From f1d74df9f73a1d15d30db784a539a73fca3ffee2 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 10 Oct 2025 15:19:20 -0700 Subject: [PATCH] Rewrite OPUS driver, no extra libs, update (#780) Move to Opus 1.5.1 Remove OpusFile and OGG libraries because we parse the OGG file in the object directly with way less memory and overhead. Update example for LittleFS and RP2040 Fixes #372 --- .github/workflows/pr-or-master-push.yml | 2 +- .gitmodules | 3 + README.md | 2 +- .../PlayOpusFromLittleFS.ino | 66 + .../data/gs-16b-2c-44100hz.opus | Bin .../PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino | 47 - lib/install-opus.sh | 83 + lib/opus | 1 + lib/opus.config.h | 247 ++ src/AudioGeneratorOpus.cpp | 223 +- src/AudioGeneratorOpus.h | 54 +- src/libogg/AUTHORS | 7 - src/libogg/CHANGES | 104 - src/libogg/COPYING | 28 - src/libogg/README.esp8266.md | 3 - src/libogg/README.md | 133 - src/libogg/bitwise.c | 1215 ------ src/libogg/config.h | 104 - src/libogg/crctable.h | 296 -- src/libogg/framing.c | 2330 ---------- src/libogg/ogg.pc | 14 - src/libogg/ogg/config_types.h | 26 - src/libogg/ogg/ogg.h | 209 - src/libogg/ogg/os_types.h | 158 - src/libopus/COPYING | 4 +- src/libopus/ChangeLog | 0 src/libopus/INSTALL | 368 -- src/libopus/LICENSE_PLEASE_READ.txt | 22 + src/libopus/NEWS | 0 src/libopus/README | 34 +- src/libopus/analysis.h | 103 - src/libopus/celt/_kiss_fft_guts.h | 58 +- src/libopus/celt/arch.h | 90 +- src/libopus/celt/bands.c | 2843 +++++++------ src/libopus/celt/bands.h | 142 +- src/libopus/celt/celt.c | 454 +- src/libopus/celt/celt.h | 178 +- src/libopus/celt/celt_decoder.c | 2580 +++++++----- src/libopus/celt/celt_encoder.c | 2535 ----------- src/libopus/celt/celt_lpc.c | 572 +-- src/libopus/celt/celt_lpc.h | 70 +- src/libopus/celt/config.h | 1 + src/libopus/celt/cpu_support.h | 85 +- src/libopus/celt/cwrs.c | 1149 +++-- src/libopus/celt/cwrs.h | 46 +- src/libopus/celt/ecintrin.h | 88 +- src/libopus/celt/entcode.c | 255 +- src/libopus/celt/entcode.h | 183 +- src/libopus/celt/entdec.c | 422 +- src/libopus/celt/entdec.h | 134 +- src/libopus/celt/entenc.c | 523 ++- src/libopus/celt/entenc.h | 155 +- src/libopus/celt/fixed_debug.h | 1027 +++-- src/libopus/celt/fixed_generic.h | 73 +- src/libopus/celt/float_cast.h | 128 +- src/libopus/celt/kiss_fft.c | 816 ++-- src/libopus/celt/kiss_fft.h | 158 +- src/libopus/celt/laplace.c | 315 +- src/libopus/celt/laplace.h | 71 +- src/libopus/celt/mathops.c | 329 +- src/libopus/celt/mathops.h | 310 +- src/libopus/celt/mdct.c | 545 +-- src/libopus/celt/mdct.h | 96 +- src/libopus/celt/mfrngcod.h | 42 +- src/libopus/celt/modes.c | 689 ++- src/libopus/celt/modes.h | 90 +- src/libopus/celt/opus.h | 1 + src/libopus/celt/opus_custom.h | 1 + src/libopus/celt/opus_defines.h | 1 + src/libopus/celt/opus_multistream.h | 1 + src/libopus/celt/opus_projection.h | 1 + src/libopus/celt/opus_types.h | 1 + src/libopus/celt/os_support.h | 90 +- src/libopus/celt/pitch.c | 856 ++-- src/libopus/celt/pitch.h | 236 +- src/libopus/celt/quant_bands.c | 908 ++-- src/libopus/celt/quant_bands.h | 56 +- src/libopus/celt/rate.c | 1131 ++--- src/libopus/celt/rate.h | 120 +- src/libopus/celt/stack_alloc.h | 124 +- src/libopus/celt/static_modes_fixed.h | 1577 ++++--- .../celt/static_modes_fixed_arm_ne10.h | 388 ++ src/libopus/celt/static_modes_float.h | 1569 ++++--- .../celt/static_modes_float_arm_ne10.h | 404 ++ src/libopus/celt/vq.c | 657 +-- src/libopus/celt/vq.h | 80 +- src/libopus/{ => include}/config.h | 95 +- src/libopus/include/opus.h | 1099 +++++ src/libopus/include/opus_custom.h | 343 ++ src/libopus/include/opus_defines.h | 830 ++++ src/libopus/include/opus_multistream.h | 660 +++ src/libopus/include/opus_projection.h | 568 +++ src/libopus/include/opus_types.h | 166 + src/libopus/mapping_matrix.c | 364 -- src/libopus/mapping_matrix.h | 132 - src/libopus/mlp.h | 60 - src/libopus/opus.c | 356 -- src/libopus/opus.h | 981 ----- src/libopus/opus.pc | 16 - src/libopus/opus_custom.h | 342 -- src/libopus/opus_decoder.c | 992 ----- src/libopus/opus_defines.h | 799 ---- src/libopus/opus_encoder.c | 2656 ------------ src/libopus/opus_multistream.c | 89 - src/libopus/opus_multistream.h | 660 --- src/libopus/opus_multistream_decoder.c | 522 --- src/libopus/opus_multistream_encoder.c | 1291 ------ src/libopus/opus_private.h | 207 - src/libopus/opus_projection.h | 568 --- src/libopus/opus_projection_decoder.c | 248 -- src/libopus/opus_projection_encoder.c | 442 -- src/libopus/opus_types.h | 166 - src/libopus/repacketizer.c | 366 -- src/libopus/silk/A2NLSF.c | 187 +- src/libopus/silk/API.h | 75 +- src/libopus/silk/CNG.c | 187 +- src/libopus/silk/HP_variable_cutoff.c | 115 +- src/libopus/silk/Inlines.h | 107 +- src/libopus/silk/LPC_analysis_filter.c | 115 +- src/libopus/silk/LPC_fit.c | 92 +- src/libopus/silk/LPC_inv_pred_gain.c | 130 +- src/libopus/silk/LP_variable_cutoff.c | 140 +- src/libopus/silk/MacroCount.h | 325 +- src/libopus/silk/MacroDebug.h | 694 +-- src/libopus/silk/NLSF2A.c | 135 +- src/libopus/silk/NLSF_VQ.c | 77 +- src/libopus/silk/NLSF_VQ_weights_laroia.c | 105 +- src/libopus/silk/NLSF_decode.c | 94 +- src/libopus/silk/NLSF_del_dec_quant.c | 174 +- src/libopus/silk/NLSF_encode.c | 119 +- src/libopus/silk/NLSF_stabilize.c | 118 +- src/libopus/silk/NLSF_unpack.c | 71 +- src/libopus/silk/NSQ.c | 434 -- src/libopus/silk/NSQ.h | 97 +- src/libopus/silk/NSQ_del_dec.c | 736 ---- src/libopus/silk/PLC.c | 395 +- src/libopus/silk/PLC.h | 51 +- src/libopus/silk/SigProc_FIX.h | 137 +- src/libopus/silk/VAD.c | 358 -- src/libopus/silk/VQ_WMat_EC.c | 135 +- src/libopus/silk/ana_filt_bank_1.c | 85 +- src/libopus/silk/arch.h | 1 + src/libopus/silk/biquad_alt.c | 134 +- src/libopus/silk/bwexpander.c | 65 +- src/libopus/silk/bwexpander_32.c | 68 +- src/libopus/silk/celt_lpc.h | 1 + src/libopus/silk/check_control_input.c | 141 +- src/libopus/silk/code_signs.c | 94 +- src/libopus/silk/config.h | 1 + src/libopus/silk/control.h | 59 +- src/libopus/silk/control_SNR.c | 147 +- src/libopus/silk/control_audio_bandwidth.c | 157 +- src/libopus/silk/control_codec.c | 252 +- src/libopus/silk/cpu_support.h | 1 + src/libopus/silk/debug.c | 100 +- src/libopus/silk/debug.h | 73 +- src/libopus/silk/dec_API.c | 405 +- src/libopus/silk/decode_core.c | 218 +- src/libopus/silk/decode_frame.c | 153 +- src/libopus/silk/decode_indices.c | 134 +- src/libopus/silk/decode_parameters.c | 101 +- src/libopus/silk/decode_pitch.c | 79 +- src/libopus/silk/decode_pulses.c | 101 +- src/libopus/silk/decoder_set_fs.c | 97 +- src/libopus/silk/define.h | 49 +- src/libopus/silk/ecintrin.h | 1 + src/libopus/silk/enc_API.c | 573 --- src/libopus/silk/encode_indices.c | 178 +- src/libopus/silk/encode_pulses.c | 168 +- src/libopus/silk/entdec.h | 1 + src/libopus/silk/entenc.h | 1 + src/libopus/silk/errors.h | 48 +- .../silk/fixed/LTP_analysis_filter_FIX.c | 77 +- .../silk/fixed/LTP_analysis_filter_FIX.lo | 12 - .../silk/fixed/LTP_analysis_filter_FIX.o | Bin 13896 -> 0 bytes src/libopus/silk/fixed/LTP_scale_ctrl_FIX.c | 70 +- src/libopus/silk/fixed/LTP_scale_ctrl_FIX.lo | 12 - src/libopus/silk/fixed/LTP_scale_ctrl_FIX.o | Bin 20696 -> 0 bytes src/libopus/silk/fixed/PLC.h | 1 + src/libopus/silk/fixed/SigProc_FIX.h | 1 + .../silk/fixed/apply_sine_window_FIX.c | 105 +- .../silk/fixed/apply_sine_window_FIX.lo | 12 - .../silk/fixed/apply_sine_window_FIX.o | Bin 10688 -> 0 bytes src/libopus/silk/fixed/autocorr_FIX.c | 65 +- src/libopus/silk/fixed/autocorr_FIX.lo | 12 - src/libopus/silk/fixed/autocorr_FIX.o | Bin 8024 -> 0 bytes src/libopus/silk/fixed/burg_modified_FIX.c | 298 +- src/libopus/silk/fixed/burg_modified_FIX.lo | 12 - src/libopus/silk/fixed/burg_modified_FIX.o | Bin 30592 -> 0 bytes src/libopus/silk/fixed/celt_lpc.h | 1 + src/libopus/silk/fixed/config.h | 1 + src/libopus/silk/fixed/control.h | 1 + src/libopus/silk/fixed/corrMatrix_FIX.c | 136 +- src/libopus/silk/fixed/corrMatrix_FIX.lo | 12 - src/libopus/silk/fixed/corrMatrix_FIX.o | Bin 17184 -> 0 bytes src/libopus/silk/fixed/debug.h | 1 + src/libopus/silk/fixed/define.h | 1 + src/libopus/silk/fixed/encode_frame_FIX.c | 446 -- src/libopus/silk/fixed/encode_frame_FIX.lo | 12 - src/libopus/silk/fixed/encode_frame_FIX.o | Bin 51152 -> 0 bytes src/libopus/silk/fixed/entdec.h | 1 + src/libopus/silk/fixed/entenc.h | 1 + src/libopus/silk/fixed/find_LPC_FIX.c | 119 +- src/libopus/silk/fixed/find_LPC_FIX.lo | 12 - src/libopus/silk/fixed/find_LPC_FIX.o | Bin 25216 -> 0 bytes src/libopus/silk/fixed/find_LTP_FIX.c | 105 +- src/libopus/silk/fixed/find_LTP_FIX.lo | 12 - src/libopus/silk/fixed/find_LTP_FIX.o | Bin 15008 -> 0 bytes src/libopus/silk/fixed/find_pitch_lags_FIX.c | 141 - src/libopus/silk/fixed/find_pitch_lags_FIX.lo | 12 - src/libopus/silk/fixed/find_pitch_lags_FIX.o | Bin 30744 -> 0 bytes src/libopus/silk/fixed/find_pred_coefs_FIX.c | 142 +- src/libopus/silk/fixed/find_pred_coefs_FIX.lo | 12 - src/libopus/silk/fixed/find_pred_coefs_FIX.o | Bin 33464 -> 0 bytes src/libopus/silk/fixed/k2a_FIX.c | 69 +- src/libopus/silk/fixed/k2a_FIX.lo | 12 - src/libopus/silk/fixed/k2a_FIX.o | Bin 7632 -> 0 bytes src/libopus/silk/fixed/k2a_Q16_FIX.c | 69 +- src/libopus/silk/fixed/k2a_Q16_FIX.lo | 12 - src/libopus/silk/fixed/k2a_Q16_FIX.o | Bin 7592 -> 0 bytes src/libopus/silk/fixed/main.h | 1 + src/libopus/silk/fixed/main_FIX.h | 70 +- .../silk/fixed/noise_shape_analysis_FIX.c | 406 -- .../silk/fixed/noise_shape_analysis_FIX.lo | 12 - .../silk/fixed/noise_shape_analysis_FIX.o | Bin 57392 -> 0 bytes src/libopus/silk/fixed/pitch.h | 1 + .../silk/fixed/pitch_analysis_core_FIX.c | 718 ---- .../silk/fixed/pitch_analysis_core_FIX.lo | 12 - .../silk/fixed/pitch_analysis_core_FIX.o | Bin 59144 -> 0 bytes src/libopus/silk/fixed/pitch_est_defines.h | 1 + src/libopus/silk/fixed/process_gains_FIX.c | 129 +- src/libopus/silk/fixed/process_gains_FIX.lo | 12 - src/libopus/silk/fixed/process_gains_FIX.o | Bin 28664 -> 0 bytes .../silk/fixed/regularize_correlations_FIX.c | 61 +- .../silk/fixed/regularize_correlations_FIX.lo | 12 - .../silk/fixed/regularize_correlations_FIX.o | Bin 11384 -> 0 bytes .../silk/fixed/residual_energy16_FIX.c | 107 +- .../silk/fixed/residual_energy16_FIX.lo | 12 - .../silk/fixed/residual_energy16_FIX.o | Bin 18976 -> 0 bytes src/libopus/silk/fixed/residual_energy_FIX.c | 97 +- src/libopus/silk/fixed/residual_energy_FIX.lo | 12 - src/libopus/silk/fixed/residual_energy_FIX.o | Bin 16904 -> 0 bytes src/libopus/silk/fixed/schur64_FIX.c | 99 +- src/libopus/silk/fixed/schur64_FIX.lo | 12 - src/libopus/silk/fixed/schur64_FIX.o | Bin 13272 -> 0 bytes src/libopus/silk/fixed/schur_FIX.c | 109 +- src/libopus/silk/fixed/schur_FIX.lo | 12 - src/libopus/silk/fixed/schur_FIX.o | Bin 10528 -> 0 bytes src/libopus/silk/fixed/stack_alloc.h | 1 + src/libopus/silk/fixed/structs.h | 1 + src/libopus/silk/fixed/structs_FIX.h | 54 +- src/libopus/silk/fixed/tuning_parameters.h | 1 + src/libopus/silk/fixed/typedef.h | 1 + src/libopus/silk/fixed/vector_ops_FIX.c | 92 +- src/libopus/silk/fixed/vector_ops_FIX.lo | 12 - src/libopus/silk/fixed/vector_ops_FIX.o | Bin 10680 -> 0 bytes .../silk/fixed/warped_autocorrelation_FIX.c | 107 +- .../silk/fixed/warped_autocorrelation_FIX.lo | 12 - .../silk/fixed/warped_autocorrelation_FIX.o | Bin 15936 -> 0 bytes src/libopus/silk/gain_quant.c | 107 +- src/libopus/silk/init_decoder.c | 96 +- src/libopus/silk/init_encoder.c | 63 - src/libopus/silk/inner_prod_aligned.c | 61 +- src/libopus/silk/interpolate.c | 65 +- src/libopus/silk/lin2log.c | 61 +- src/libopus/silk/log2lin.c | 69 +- src/libopus/silk/macros.h | 70 +- src/libopus/silk/main.h | 138 +- src/libopus/silk/main_FIX.h | 1 + src/libopus/silk/opus.h | 1 + src/libopus/silk/opus_custom.h | 1 + src/libopus/silk/opus_defines.h | 1 + src/libopus/silk/opus_multistream.h | 1 + src/libopus/silk/opus_projection.h | 1 + src/libopus/silk/opus_types.h | 1 + src/libopus/silk/os_support.h | 1 + src/libopus/silk/pitch_est_defines.h | 48 +- src/libopus/silk/pitch_est_tables.c | 115 +- src/libopus/silk/process_NLSFs.c | 113 +- src/libopus/silk/quant_LTP_gains.c | 99 +- src/libopus/silk/resampler.c | 202 +- src/libopus/silk/resampler_down2.c | 89 +- src/libopus/silk/resampler_down2_3.c | 103 +- src/libopus/silk/resampler_private.h | 48 +- src/libopus/silk/resampler_private_AR2.c | 67 +- src/libopus/silk/resampler_private_IIR_FIR.c | 106 +- src/libopus/silk/resampler_private_down_FIR.c | 250 +- src/libopus/silk/resampler_private_up2_HQ.c | 130 +- src/libopus/silk/resampler_rom.c | 92 +- src/libopus/silk/resampler_rom.h | 48 +- src/libopus/silk/resampler_structs.h | 52 +- src/libopus/silk/shell_coder.c | 151 +- src/libopus/silk/sigm_Q15.c | 78 +- src/libopus/silk/sort.c | 109 +- src/libopus/silk/stack_alloc.h | 1 + src/libopus/silk/stereo_LR_to_MS.c | 215 +- src/libopus/silk/stereo_MS_to_LR.c | 97 +- src/libopus/silk/stereo_decode_pred.c | 80 +- src/libopus/silk/stereo_encode_pred.c | 76 +- src/libopus/silk/stereo_find_predictor.c | 101 +- src/libopus/silk/stereo_quant_pred.c | 77 +- src/libopus/silk/structs.h | 80 +- src/libopus/silk/structs_FIX.h | 1 + src/libopus/silk/sum_sqr_shift.c | 97 +- src/libopus/silk/table_LSF_cos.c | 120 +- src/libopus/silk/tables.h | 50 +- src/libopus/silk/tables_LTP.c | 391 +- src/libopus/silk/tables_NLSF_CB_NB_MB.c | 307 +- src/libopus/silk/tables_NLSF_CB_WB.c | 383 +- src/libopus/silk/tables_gain.c | 87 +- src/libopus/silk/tables_other.c | 92 +- src/libopus/silk/tables_pitch_lag.c | 90 +- src/libopus/silk/tables_pulses_per_block.c | 428 +- src/libopus/silk/tuning_parameters.h | 48 +- src/libopus/silk/typedef.h | 62 +- src/libopus/src/API.h | 1 + src/libopus/src/arch.h | 1 + src/libopus/src/celt.h | 1 + src/libopus/src/config.h | 1 + src/libopus/src/cpu_support.h | 1 + src/libopus/src/define.h | 1 + src/libopus/src/entdec.h | 1 + src/libopus/src/float_cast.h | 1 + src/libopus/src/mathops.h | 1 + src/libopus/src/modes.h | 1 + src/libopus/src/opus.c | 362 ++ src/libopus/src/opus.h | 1 + src/libopus/src/opus_custom.h | 1 + src/libopus/src/opus_decoder.c | 1508 +++++++ src/libopus/src/opus_defines.h | 1 + src/libopus/src/opus_multistream.h | 1 + src/libopus/src/opus_private.h | 223 + src/libopus/src/opus_projection.h | 1 + src/libopus/src/opus_types.h | 1 + src/libopus/src/os_support.h | 1 + src/libopus/src/stack_alloc.h | 1 + src/libopus/src/structs.h | 1 + src/libopus/tansig_table.h | 45 - src/opusfile/AUTHORS | 5 - src/opusfile/COPYING | 28 - src/opusfile/README.esp8266.md | 3 - src/opusfile/README.md | 18 - src/opusfile/config.h | 128 - src/opusfile/info.c | 958 ----- src/opusfile/internal.c | 48 - src/opusfile/internal.h | 259 -- src/opusfile/opusfile.c | 3750 ----------------- src/opusfile/opusfile.h | 2164 ---------- src/opusfile/opusfile.pc | 15 - src/opusfile/stream.c | 447 -- tests/host/Makefile | 51 +- tests/host/opus.cpp | 2 +- tests/restyle.sh | 2 +- 353 files changed, 26352 insertions(+), 48834 deletions(-) create mode 100644 .gitmodules create mode 100644 examples/PlayOpusFromLittleFS/PlayOpusFromLittleFS.ino rename examples/{PlayOpusFromSPIFFS => PlayOpusFromLittleFS}/data/gs-16b-2c-44100hz.opus (100%) delete mode 100644 examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino create mode 100755 lib/install-opus.sh create mode 160000 lib/opus create mode 100644 lib/opus.config.h delete mode 100644 src/libogg/AUTHORS delete mode 100644 src/libogg/CHANGES delete mode 100644 src/libogg/COPYING delete mode 100644 src/libogg/README.esp8266.md delete mode 100644 src/libogg/README.md delete mode 100644 src/libogg/bitwise.c delete mode 100644 src/libogg/config.h delete mode 100644 src/libogg/crctable.h delete mode 100644 src/libogg/framing.c delete mode 100644 src/libogg/ogg.pc delete mode 100644 src/libogg/ogg/config_types.h delete mode 100644 src/libogg/ogg/ogg.h delete mode 100644 src/libogg/ogg/os_types.h delete mode 100644 src/libopus/ChangeLog delete mode 100644 src/libopus/INSTALL create mode 100644 src/libopus/LICENSE_PLEASE_READ.txt delete mode 100644 src/libopus/NEWS delete mode 100644 src/libopus/analysis.h delete mode 100644 src/libopus/celt/celt_encoder.c create mode 100644 src/libopus/celt/config.h create mode 100644 src/libopus/celt/opus.h create mode 100644 src/libopus/celt/opus_custom.h create mode 100644 src/libopus/celt/opus_defines.h create mode 100644 src/libopus/celt/opus_multistream.h create mode 100644 src/libopus/celt/opus_projection.h create mode 100644 src/libopus/celt/opus_types.h create mode 100644 src/libopus/celt/static_modes_fixed_arm_ne10.h create mode 100644 src/libopus/celt/static_modes_float_arm_ne10.h rename src/libopus/{ => include}/config.h (66%) create mode 100644 src/libopus/include/opus.h create mode 100644 src/libopus/include/opus_custom.h create mode 100644 src/libopus/include/opus_defines.h create mode 100644 src/libopus/include/opus_multistream.h create mode 100644 src/libopus/include/opus_projection.h create mode 100644 src/libopus/include/opus_types.h delete mode 100644 src/libopus/mapping_matrix.c delete mode 100644 src/libopus/mapping_matrix.h delete mode 100644 src/libopus/mlp.h delete mode 100644 src/libopus/opus.c delete mode 100644 src/libopus/opus.h delete mode 100644 src/libopus/opus.pc delete mode 100644 src/libopus/opus_custom.h delete mode 100644 src/libopus/opus_decoder.c delete mode 100644 src/libopus/opus_defines.h delete mode 100644 src/libopus/opus_encoder.c delete mode 100644 src/libopus/opus_multistream.c delete mode 100644 src/libopus/opus_multistream.h delete mode 100644 src/libopus/opus_multistream_decoder.c delete mode 100644 src/libopus/opus_multistream_encoder.c delete mode 100644 src/libopus/opus_private.h delete mode 100644 src/libopus/opus_projection.h delete mode 100644 src/libopus/opus_projection_decoder.c delete mode 100644 src/libopus/opus_projection_encoder.c delete mode 100644 src/libopus/opus_types.h delete mode 100644 src/libopus/repacketizer.c delete mode 100644 src/libopus/silk/NSQ.c delete mode 100644 src/libopus/silk/NSQ_del_dec.c delete mode 100644 src/libopus/silk/VAD.c create mode 100644 src/libopus/silk/arch.h create mode 100644 src/libopus/silk/celt_lpc.h create mode 100644 src/libopus/silk/config.h create mode 100644 src/libopus/silk/cpu_support.h create mode 100644 src/libopus/silk/ecintrin.h delete mode 100644 src/libopus/silk/enc_API.c create mode 100644 src/libopus/silk/entdec.h create mode 100644 src/libopus/silk/entenc.h delete mode 100644 src/libopus/silk/fixed/LTP_analysis_filter_FIX.lo delete mode 100644 src/libopus/silk/fixed/LTP_analysis_filter_FIX.o delete mode 100644 src/libopus/silk/fixed/LTP_scale_ctrl_FIX.lo delete mode 100644 src/libopus/silk/fixed/LTP_scale_ctrl_FIX.o create mode 100644 src/libopus/silk/fixed/PLC.h create mode 100644 src/libopus/silk/fixed/SigProc_FIX.h delete mode 100644 src/libopus/silk/fixed/apply_sine_window_FIX.lo delete mode 100644 src/libopus/silk/fixed/apply_sine_window_FIX.o delete mode 100644 src/libopus/silk/fixed/autocorr_FIX.lo delete mode 100644 src/libopus/silk/fixed/autocorr_FIX.o delete mode 100644 src/libopus/silk/fixed/burg_modified_FIX.lo delete mode 100644 src/libopus/silk/fixed/burg_modified_FIX.o create mode 100644 src/libopus/silk/fixed/celt_lpc.h create mode 100644 src/libopus/silk/fixed/config.h create mode 100644 src/libopus/silk/fixed/control.h delete mode 100644 src/libopus/silk/fixed/corrMatrix_FIX.lo delete mode 100644 src/libopus/silk/fixed/corrMatrix_FIX.o create mode 100644 src/libopus/silk/fixed/debug.h create mode 100644 src/libopus/silk/fixed/define.h delete mode 100644 src/libopus/silk/fixed/encode_frame_FIX.c delete mode 100644 src/libopus/silk/fixed/encode_frame_FIX.lo delete mode 100644 src/libopus/silk/fixed/encode_frame_FIX.o create mode 100644 src/libopus/silk/fixed/entdec.h create mode 100644 src/libopus/silk/fixed/entenc.h delete mode 100644 src/libopus/silk/fixed/find_LPC_FIX.lo delete mode 100644 src/libopus/silk/fixed/find_LPC_FIX.o delete mode 100644 src/libopus/silk/fixed/find_LTP_FIX.lo delete mode 100644 src/libopus/silk/fixed/find_LTP_FIX.o delete mode 100644 src/libopus/silk/fixed/find_pitch_lags_FIX.c delete mode 100644 src/libopus/silk/fixed/find_pitch_lags_FIX.lo delete mode 100644 src/libopus/silk/fixed/find_pitch_lags_FIX.o delete mode 100644 src/libopus/silk/fixed/find_pred_coefs_FIX.lo delete mode 100644 src/libopus/silk/fixed/find_pred_coefs_FIX.o delete mode 100644 src/libopus/silk/fixed/k2a_FIX.lo delete mode 100644 src/libopus/silk/fixed/k2a_FIX.o delete mode 100644 src/libopus/silk/fixed/k2a_Q16_FIX.lo delete mode 100644 src/libopus/silk/fixed/k2a_Q16_FIX.o create mode 100644 src/libopus/silk/fixed/main.h delete mode 100644 src/libopus/silk/fixed/noise_shape_analysis_FIX.c delete mode 100644 src/libopus/silk/fixed/noise_shape_analysis_FIX.lo delete mode 100644 src/libopus/silk/fixed/noise_shape_analysis_FIX.o create mode 100644 src/libopus/silk/fixed/pitch.h delete mode 100644 src/libopus/silk/fixed/pitch_analysis_core_FIX.c delete mode 100644 src/libopus/silk/fixed/pitch_analysis_core_FIX.lo delete mode 100644 src/libopus/silk/fixed/pitch_analysis_core_FIX.o create mode 100644 src/libopus/silk/fixed/pitch_est_defines.h delete mode 100644 src/libopus/silk/fixed/process_gains_FIX.lo delete mode 100644 src/libopus/silk/fixed/process_gains_FIX.o delete mode 100644 src/libopus/silk/fixed/regularize_correlations_FIX.lo delete mode 100644 src/libopus/silk/fixed/regularize_correlations_FIX.o delete mode 100644 src/libopus/silk/fixed/residual_energy16_FIX.lo delete mode 100644 src/libopus/silk/fixed/residual_energy16_FIX.o delete mode 100644 src/libopus/silk/fixed/residual_energy_FIX.lo delete mode 100644 src/libopus/silk/fixed/residual_energy_FIX.o delete mode 100644 src/libopus/silk/fixed/schur64_FIX.lo delete mode 100644 src/libopus/silk/fixed/schur64_FIX.o delete mode 100644 src/libopus/silk/fixed/schur_FIX.lo delete mode 100644 src/libopus/silk/fixed/schur_FIX.o create mode 100644 src/libopus/silk/fixed/stack_alloc.h create mode 100644 src/libopus/silk/fixed/structs.h create mode 100644 src/libopus/silk/fixed/tuning_parameters.h create mode 100644 src/libopus/silk/fixed/typedef.h delete mode 100644 src/libopus/silk/fixed/vector_ops_FIX.lo delete mode 100644 src/libopus/silk/fixed/vector_ops_FIX.o delete mode 100644 src/libopus/silk/fixed/warped_autocorrelation_FIX.lo delete mode 100644 src/libopus/silk/fixed/warped_autocorrelation_FIX.o delete mode 100644 src/libopus/silk/init_encoder.c create mode 100644 src/libopus/silk/main_FIX.h create mode 100644 src/libopus/silk/opus.h create mode 100644 src/libopus/silk/opus_custom.h create mode 100644 src/libopus/silk/opus_defines.h create mode 100644 src/libopus/silk/opus_multistream.h create mode 100644 src/libopus/silk/opus_projection.h create mode 100644 src/libopus/silk/opus_types.h create mode 100644 src/libopus/silk/os_support.h create mode 100644 src/libopus/silk/stack_alloc.h create mode 100644 src/libopus/silk/structs_FIX.h create mode 100644 src/libopus/src/API.h create mode 100644 src/libopus/src/arch.h create mode 100644 src/libopus/src/celt.h create mode 100644 src/libopus/src/config.h create mode 100644 src/libopus/src/cpu_support.h create mode 100644 src/libopus/src/define.h create mode 100644 src/libopus/src/entdec.h create mode 100644 src/libopus/src/float_cast.h create mode 100644 src/libopus/src/mathops.h create mode 100644 src/libopus/src/modes.h create mode 100644 src/libopus/src/opus.c create mode 100644 src/libopus/src/opus.h create mode 100644 src/libopus/src/opus_custom.h create mode 100644 src/libopus/src/opus_decoder.c create mode 100644 src/libopus/src/opus_defines.h create mode 100644 src/libopus/src/opus_multistream.h create mode 100644 src/libopus/src/opus_private.h create mode 100644 src/libopus/src/opus_projection.h create mode 100644 src/libopus/src/opus_types.h create mode 100644 src/libopus/src/os_support.h create mode 100644 src/libopus/src/stack_alloc.h create mode 100644 src/libopus/src/structs.h delete mode 100644 src/libopus/tansig_table.h delete mode 100644 src/opusfile/AUTHORS delete mode 100644 src/opusfile/COPYING delete mode 100644 src/opusfile/README.esp8266.md delete mode 100644 src/opusfile/README.md delete mode 100644 src/opusfile/config.h delete mode 100644 src/opusfile/info.c delete mode 100644 src/opusfile/internal.c delete mode 100644 src/opusfile/internal.h delete mode 100644 src/opusfile/opusfile.c delete mode 100644 src/opusfile/opusfile.h delete mode 100644 src/opusfile/opusfile.pc delete mode 100644 src/opusfile/stream.c diff --git a/.github/workflows/pr-or-master-push.yml b/.github/workflows/pr-or-master-push.yml index 6cf58d3..fe31c42 100644 --- a/.github/workflows/pr-or-master-push.yml +++ b/.github/workflows/pr-or-master-push.yml @@ -155,7 +155,7 @@ jobs: - name: Run codespell uses: codespell-project/actions-codespell@406322ec52dd7b488e48c1c4b82e2a8b3a1bf630 # v2.1 with: - skip: ./src/libmad,./src/libhelix-aac,./src/libopus,./src/libflac + skip: ./src/libmad,./src/libhelix-aac,./src/libopus,./src/libflac,./lib/opus ignore_words_list: ESP8266,esp8266,esp,dout,DOUT,ser,ans,inout,numer,hist - name: Run astyle on all code/examples run: | diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2108e90 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/opus"] + path = lib/opus + url = https://gitlab.xiph.org/xiph/opus.git diff --git a/README.md b/README.md index d564554..5c52fda 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ All this code is released under the GPL, and all of it is to be used at your own * The software I2S delta-sigma 32x oversampling DAC was my own creation, and sounds quite good if I do say so myself. * The AAC decode code is from the Helix project and licensed under RealNetwork's RSPL license. For commercial use you're still going to need the usual AAC licensing from [Via Licensing](http://www.via-corp.com/us/en/licensing/aac/overview.html). On the ESP32, AAC-SBR is supported (many webradio stations use this to reduce bandwidth even further). The ESP8266, however, does not support it due to a lack of onboard RAM. * MIDI decoding comes from a highly ported [MIDITONES](https://github.com/LenShustek/miditones) combined with a massively memory-optimized [TinySoundFont](https://github.com/schellingb/TinySoundFont), see the respective source files for more information. -* Opus, OGG, and OpusFile are from [Xiph.org](https://xiph.org) with the Xiph license and patent described in src/{opusfile,libggg,libopus}/COPYING.. **NOTE** Opus decoding currently only works on the ESP32 due to the large memory requirements of opusfile. PRs to rewrite it to be less memory intensive would be much appreciated. +* Opusis from [Xiph.org](https://xiph.org) with the Xiph license and patent described in src/{opusfile,libggg,libopus}/COPYING. ## Neat Things People Have Done With ESP8266Audio If you have a neat use for this library, [I'd love to hear about it](mailto:earlephilhower@yahoo.com)! diff --git a/examples/PlayOpusFromLittleFS/PlayOpusFromLittleFS.ino b/examples/PlayOpusFromLittleFS/PlayOpusFromLittleFS.ino new file mode 100644 index 0000000..8361b03 --- /dev/null +++ b/examples/PlayOpusFromLittleFS/PlayOpusFromLittleFS.ino @@ -0,0 +1,66 @@ +#include + +#ifdef ESP8266 + +void setup() { + Serial.begin(115200); +} + +void loop() { + Serial.println("OPUS not supported on the ESP8266, sorry!"); + delay(1000); +} + +#else + +#include +#include + +#include "AudioFileSourceLittleFS.h" +#include "AudioGeneratorOpus.h" +#include "AudioOutputI2S.h" + +// The includes OPUS file is from Kevin MacLeod (incompetech.com), Licensed under Creative Commons: By Attribution 3.0, http://creativecommons.org/licenses/by/3.0/ + +AudioGeneratorOpus *opus; +AudioFileSourceLittleFS *file; +AudioOutputI2S *out; + +#ifdef ESP32 +// We need more than the 8K default with other things running, so just double to avoid issues. +// Opus codes uses *lots* of stack variables in the internal decoder instead of a global working chunk +SET_LOOP_TASK_STACK_SIZE(16 * 1024); // 16KB +// On the Pico this is already taken care of using the built-in NONTHREADSAFE_PSEUDOSTACK in the config file. +#endif + +void setup() { + WiFi.mode(WIFI_OFF); + Serial.begin(115200); + delay(1000); + LittleFS.begin(); + Serial.printf("Sample Opus playback begins...\n"); + + audioLogger = &Serial; + file = new AudioFileSourceLittleFS("/gs-16b-2c-44100hz.opus"); +#ifdef ARDUINO_ARCH_RP2040 + out = new AudioOutputI2S(48000, 26, 22); +#else + out = new AudioOutputI2S(); + // out->SetPinout(0, 1, 2); // Set the pinout if needed +#endif + opus = new AudioGeneratorOpus(); + opus->begin(file, out); +} + +void loop() { + if (opus->isRunning()) { + if (!opus->loop()) { + opus->stop(); + } + } else { + Serial.printf("Opus done\n"); + delay(1000); + } +} + +#endif diff --git a/examples/PlayOpusFromSPIFFS/data/gs-16b-2c-44100hz.opus b/examples/PlayOpusFromLittleFS/data/gs-16b-2c-44100hz.opus similarity index 100% rename from examples/PlayOpusFromSPIFFS/data/gs-16b-2c-44100hz.opus rename to examples/PlayOpusFromLittleFS/data/gs-16b-2c-44100hz.opus diff --git a/examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino b/examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino deleted file mode 100644 index 272f154..0000000 --- a/examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino +++ /dev/null @@ -1,47 +0,0 @@ -#include -#ifdef ARDUINO_ARCH_RP2040 -void setup() {} -void loop() {} -#else -#ifdef ESP32 -#include -#include "SPIFFS.h" -#else -#include -#endif -#include "AudioFileSourceSPIFFS.h" -#include "AudioGeneratorOpus.h" -#include "AudioOutputI2S.h" - -// The includes OPUS file is from Kevin MacLeod (incompetech.com), Licensed under Creative Commons: By Attribution 3.0, http://creativecommons.org/licenses/by/3.0/ - -AudioGeneratorOpus *opus; -AudioFileSourceSPIFFS *file; -AudioOutputI2S *out; - -void setup() { - WiFi.mode(WIFI_OFF); - Serial.begin(115200); - delay(1000); - SPIFFS.begin(); - Serial.printf("Sample Opus playback begins...\n"); - - audioLogger = &Serial; - file = new AudioFileSourceSPIFFS("/gs-16b-2c-44100hz.opus"); - out = new AudioOutputI2S(); - opus = new AudioGeneratorOpus(); - opus->begin(file, out); -} - -void loop() { - if (opus->isRunning()) { - if (!opus->loop()) { - opus->stop(); - } - } else { - Serial.printf("Opus done\n"); - delay(1000); - } -} - -#endif diff --git a/lib/install-opus.sh b/lib/install-opus.sh new file mode 100755 index 0000000..ccd4753 --- /dev/null +++ b/lib/install-opus.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +rm -rf libopus +mkdir libopus libopus/include libopus/src libopus/celt libopus/silk libopus/silk/fixed +cp opus/include/*.h libopus/include/. +cp opus.config.h libopus/include/config.h + +celt="arch.h bands.c bands.h celt.c celt_decoder.c celt.h celt_lpc.c celt_lpc.h cpu_support.h cwrs.c cwrs.h ecintrin.h entcode.c entcode.h entdec.c entdec.h entenc.c entenc.h fixed_debug.h fixed_generic.h float_cast.h kiss_fft.c _kiss_fft_guts.h kiss_fft.h laplace.c laplace.h mathops.c mathops.h mdct.c mdct.h mfrngcod.h modes.c modes.h os_support.h pitch.c pitch.h quant_bands.c quant_bands.h rate.c rate.h stack_alloc.h static_modes_fixed_arm_ne10.h static_modes_fixed.h static_modes_float_arm_ne10.h static_modes_float.h vq.c vq.h" +cd opus/celt +for i in $celt; do + cp -i $i ../../libopus/celt/. +done +incs="config.h opus_custom.h opus_defines.h opus.h opus_multistream.h opus_projection.h opus_types.h" +for i in $incs; do + echo '#include "../include/'$i'"' > ../../libopus/celt/$i +done +sed -i s/HAVE_CONFIG_H/__STDC__/g ../../libopus/celt/*.[ch] + +cd ../silk +silk="A2NLSF.c ana_filt_bank_1.c API.h biquad_alt.c bwexpander_32.c bwexpander.c check_control_input.c CNG.c code_signs.c control_audio_bandwidth.c control_codec.c control.h control_SNR.c debug.c debug.h dec_API.c decode_core.c decode_frame.c decode_indices.c decode_parameters.c decode_pitch.c decode_pulses.c decoder_set_fs.c define.h encode_indices.c encode_pulses.c errors.h gain_quant.c HP_variable_cutoff.c init_decoder.c Inlines.h inner_prod_aligned.c interpolate.c lin2log.c log2lin.c LPC_analysis_filter.c LPC_fit.c LPC_inv_pred_gain.c LP_variable_cutoff.c MacroCount.h MacroDebug.h macros.h main.h NLSF2A.c NLSF_decode.c NLSF_del_dec_quant.c NLSF_encode.c NLSF_stabilize.c NLSF_unpack.c NLSF_VQ.c NLSF_VQ_weights_laroia.c NSQ.h pitch_est_defines.h pitch_est_tables.c PLC.c PLC.h process_NLSFs.c quant_LTP_gains.c resampler.c resampler_down2_3.c resampler_down2.c resampler_private_AR2.c resampler_private_down_FIR.c resampler_private.h resampler_private_IIR_FIR.c resampler_private_up2_HQ.c resampler_rom.c resampler_rom.h resampler_structs.h shell_coder.c sigm_Q15.c SigProc_FIX.h sort.c stereo_decode_pred.c stereo_encode_pred.c stereo_find_predictor.c stereo_LR_to_MS.c stereo_MS_to_LR.c stereo_quant_pred.c structs.h sum_sqr_shift.c table_LSF_cos.c tables_gain.c tables.h tables_LTP.c tables_NLSF_CB_NB_MB.c tables_NLSF_CB_WB.c tables_other.c tables_pitch_lag.c tables_pulses_per_block.c tuning_parameters.h typedef.h VQ_WMat_EC.c" +for i in $silk; do + cp -i $i ../../libopus/silk/. +done +for i in $incs; do + echo '#include "../include/'$i'"' > ../../libopus/silk/$i +done +silkcelt="arch.h celt_lpc.h cpu_support.h ecintrin.h entdec.h entenc.h os_support.h stack_alloc.h" +for i in $silkcelt; do + echo '#include "../celt/'$i'"' > ../../libopus/silk/$i +done +silkfix="main_FIX.h structs_FIX.h" +for i in $silkfix; do + echo '#include "fixed/'$i'"' > ../../libopus/silk/$i +done +sed -i s/HAVE_CONFIG_H/__STDC__/g ../../libopus/silk/*.[ch] + +cd fixed +fixed="apply_sine_window_FIX.c autocorr_FIX.c burg_modified_FIX.c corrMatrix_FIX.c find_LPC_FIX.c find_LTP_FIX.c find_pred_coefs_FIX.c k2a_FIX.c k2a_Q16_FIX.c LTP_analysis_filter_FIX.c LTP_scale_ctrl_FIX.c main_FIX.h process_gains_FIX.c regularize_correlations_FIX.c residual_energy16_FIX.c residual_energy_FIX.c schur64_FIX.c schur_FIX.c structs_FIX.h vector_ops_FIX.c warped_autocorrelation_FIX.c" +for i in $fixed; do + cp -i $i ../../../libopus/silk/fixed/$i +done +incs="config.h" +for i in $incs; do + echo '#include "../../include/'$i'"' > ../../../libopus/silk/fixed/$i +done +fixedcelt="celt_lpc.h entdec.h entenc.h pitch.h stack_alloc.h" +for i in $fixedcelt; do + echo '#include "../../celt/'$i'"' > ../../../libopus/silk/fixed/$i +done +fixedsilk="control.h debug.h define.h main.h pitch_est_defines.h PLC.h SigProc_FIX.h structs.h tuning_parameters.h typedef.h" +for i in $fixedsilk; do + echo '#include "../'$i'"' > ../../../libopus/silk/fixed/$i +done +sed -i s/HAVE_CONFIG_H/__STDC__/g ../../../libopus/silk/fixed/*.[ch] + +cd ../../src +src="opus.c opus_decoder.c opus_private.h" +for i in $src; do + cp -i $i ../../libopus/src/$i +done +incs="config.h opus_custom.h opus_defines.h opus.h opus_multistream.h opus_projection.h opus_types.h" +for i in $incs; do + echo '#include "../include/'$i'"' > ../../libopus/src/$i +done +srccelt="arch.h celt.h cpu_support.h entdec.h float_cast.h mathops.h modes.h os_support.h stack_alloc.h" +for i in $srccelt; do + echo '#include "../celt/'$i'"' > ../../libopus/src/$i +done +srcsilk="API.h define.h structs.h" +for i in $srcsilk; do + echo '#include "../silk/'$i'"' > ../../libopus/src/$i +done +sed -i s/HAVE_CONFIG_H/__STDC__/g ../../libopus/src/*.[ch] + +cd ../ +root="AUTHORS COPYING LICENSE_PLEASE_READ.txt README" +for i in $root; do + cp -i $i ../libopus/. +done + +cd .. +rm -r ../src/libopus +mv libopus ../src/libopus diff --git a/lib/opus b/lib/opus new file mode 160000 index 0000000..ab4e835 --- /dev/null +++ b/lib/opus @@ -0,0 +1 @@ +Subproject commit ab4e83598e7fc8b2ce82dc633a0fc0c452b629aa diff --git a/lib/opus.config.h b/lib/opus.config.h new file mode 100644 index 0000000..636dca0 --- /dev/null +++ b/lib/opus.config.h @@ -0,0 +1,247 @@ + +// CFLAGS="-m32 -g -O2 -fstack-usage -Wstack-usage=512" CPPFLAGS="-m32 -g -O2 -fstack-usage -Wstack-usage=512" ./configure --prefix=/tmp/opus --disable-float-api --enable-fixed-point --disable-hardening --disable-asm --disable-intrinsics + +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Get CPU Info by asm method */ +/* #undef CPU_INFO_BY_ASM */ + +/* Get CPU Info by c method */ +/* #undef CPU_INFO_BY_C */ + +/* Custom modes */ +/* #undef CUSTOM_MODES */ + +/* Disable DNN debug float */ +#define DISABLE_DEBUG_FLOAT 1 + +/* Disable dot product instructions */ +/* #undef DISABLE_DOT_PROD */ + +/* Do not build the float API */ +#define DISABLE_FLOAT_API 1 + +/* Disable bitstream fixes from RFC 8251 */ +/* #undef DISABLE_UPDATE_DRAFT */ + +/* Assertions */ +/* #undef ENABLE_ASSERTIONS */ + +/* Deep PLC */ +/* #undef ENABLE_DEEP_PLC */ + +/* DRED */ +/* #undef ENABLE_DRED */ + +/* Hardening */ +/* #undef ENABLE_HARDENING */ + +/* LOSSGEN */ +/* #undef ENABLE_LOSSGEN */ + +/* Enable Opus Speech Coding Enhancement */ +/* #undef ENABLE_OSCE */ + +/* Enable dumping of OSCE training data */ +/* #undef ENABLE_OSCE_TRAINING_DATA */ + +/* Debug fixed-point implementation */ +/* #undef FIXED_DEBUG */ + +/* Compile as fixed-point (for machines without a fast enough FPU) */ +#define FIXED_POINT 1 + +/* Float approximations */ +#define FLOAT_APPROX 1 + +/* Fuzzing */ +/* #undef FUZZING */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_ALLOCA_H */ + + +/* NE10 library is installed on host. Make sure it is on target! */ +/* #undef HAVE_ARM_NE10 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `lrint' function. */ +#define HAVE_LRINT 1 + +/* Define to 1 if you have the `lrintf' function. */ +#define HAVE_LRINTF 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `__malloc_hook' function. */ +/* #undef HAVE___MALLOC_HOOK */ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Make use of ARM asm optimization */ +/* #undef OPUS_ARM_ASM */ + +/* Use generic ARMv4 inline asm optimizations */ +/* #undef OPUS_ARM_INLINE_ASM */ + +/* Use ARMv5E inline asm optimizations */ +/* #undef OPUS_ARM_INLINE_EDSP */ + +/* Use ARMv6 inline asm optimizations */ +/* #undef OPUS_ARM_INLINE_MEDIA */ + +/* Use ARM NEON inline asm optimizations */ +/* #undef OPUS_ARM_INLINE_NEON */ + +/* Compiler supports Aarch64 DOTPROD Intrinsics */ +/* #undef OPUS_ARM_MAY_HAVE_DOTPROD */ + +/* Define if assembler supports EDSP instructions */ +/* #undef OPUS_ARM_MAY_HAVE_EDSP */ + +/* Define if assembler supports ARMv6 media instructions */ +/* #undef OPUS_ARM_MAY_HAVE_MEDIA */ + +/* Define if compiler supports NEON instructions */ +/* #undef OPUS_ARM_MAY_HAVE_NEON */ + +/* Compiler supports ARMv7/Aarch64 Neon Intrinsics */ +/* #undef OPUS_ARM_MAY_HAVE_NEON_INTR */ + +/* Define if binary requires Aarch64 Neon Intrinsics */ +/* #undef OPUS_ARM_PRESUME_AARCH64_NEON_INTR */ + +/* Define if binary requires Aarch64 dotprod Intrinsics */ +/* #undef OPUS_ARM_PRESUME_DOTPROD */ + +/* Define if binary requires EDSP instruction support */ +/* #undef OPUS_ARM_PRESUME_EDSP */ + +/* Define if binary requires ARMv6 media instruction support */ +/* #undef OPUS_ARM_PRESUME_MEDIA */ + +/* Define if binary requires NEON instruction support */ +/* #undef OPUS_ARM_PRESUME_NEON */ + +/* Define if binary requires NEON intrinsics support */ +/* #undef OPUS_ARM_PRESUME_NEON_INTR */ + +/* This is a build of OPUS */ +#define OPUS_BUILD /**/ + +/* Run bit-exactness checks between optimized and c implementations */ +/* #undef OPUS_CHECK_ASM */ + +/* Use run-time CPU capabilities detection */ +/* #undef OPUS_HAVE_RTCD */ + +/* Compiler supports X86 AVX2 Intrinsics */ +/* #undef OPUS_X86_MAY_HAVE_AVX2 */ + +/* Compiler supports X86 SSE Intrinsics */ +/* #undef OPUS_X86_MAY_HAVE_SSE */ + +/* Compiler supports X86 SSE2 Intrinsics */ +/* #undef OPUS_X86_MAY_HAVE_SSE2 */ + +/* Compiler supports X86 SSE4.1 Intrinsics */ +/* #undef OPUS_X86_MAY_HAVE_SSE4_1 */ + +/* Define if binary requires AVX2 intrinsics support */ +/* #undef OPUS_X86_PRESUME_AVX2 */ + +/* Define if binary requires SSE intrinsics support */ +/* #undef OPUS_X86_PRESUME_SSE */ + +/* Define if binary requires SSE2 intrinsics support */ +/* #undef OPUS_X86_PRESUME_SSE2 */ + +/* Define if binary requires SSE4.1 intrinsics support */ +/* #undef OPUS_X86_PRESUME_SSE4_1 */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "opus@xiph.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "opus" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "opus 1.5.2" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "opus" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.5.2" + +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ +#define STDC_HEADERS 1 + +/* Make use of alloca */ +#undef USE_ALLOCA + +/* Use C99 variable-size arrays */ +#define VAR_ARRAYS 1 + +// Enable heap-based stack on Pico. ESP32 should use larger task stack in the sketch +#ifdef ARDUINO_ARCH_RP2040 +#undef VAR_ARRAYS +#define NONTHREADSAFE_PSEUDOSTACK 1 +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to the equivalent of the C99 'restrict' keyword, or to + nothing if this is not supported. Do not define if restrict is + supported directly. */ +#define restrict __restrict +/* Work around a bug in Sun C++: it does not support _Restrict or + __restrict__, even though the corresponding Sun C compiler ends up with + "#define restrict _Restrict" or "#define restrict __restrict__" in the + previous line. Perhaps some future version of Sun C++ will work with + restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ +#if defined __SUNPRO_CC && !defined __RESTRICT +# define _Restrict +# define __restrict__ +#endif diff --git a/src/AudioGeneratorOpus.cpp b/src/AudioGeneratorOpus.cpp index 3f31a59..91ed283 100644 --- a/src/AudioGeneratorOpus.cpp +++ b/src/AudioGeneratorOpus.cpp @@ -2,7 +2,7 @@ AudioGeneratorOpus Audio output generator that plays Opus audio files - Copyright (C) 2020 Earle F. Philhower, III + Copyright (C) 2025 Earle F. Philhower, III This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,54 +21,74 @@ #include AudioGeneratorOpus::AudioGeneratorOpus() { - of = nullptr; + od = nullptr; buff = nullptr; buffPtr = 0; + packet = nullptr; buffLen = 0; running = false; } AudioGeneratorOpus::~AudioGeneratorOpus() { - if (of) { - op_free(of); + if (od) { + free(od); } - of = nullptr; + od = nullptr; free(buff); buff = nullptr; + free(packet); + packet = nullptr; } -#define OPUS_BUFF 1024 - bool AudioGeneratorOpus::begin(AudioFileSource *source, AudioOutput *output) { - buff = (int16_t*)malloc(OPUS_BUFF * sizeof(int16_t)); + buff = (opus_int16*)malloc(4096 * sizeof(opus_int16)); if (!buff) { return false; } + packet = (uint8_t *)malloc(1024); + if (!packet) { + free(buff); + buff = nullptr; + return false; + } + packetOff = 0; + + od = (OpusDecoder *) malloc(opus_decoder_get_size(2)); + if (!od) { + free(buff); + buff = nullptr; + free(packet); + packet = nullptr; + return false; + } + opus_decoder_init(od, 48000, 2); + if (!source) { return false; } file = source; + if (!output) { return false; } this->output = output; + if (!file->isOpen()) { return false; // Error } - of = op_open_callbacks((void*)this, &cb, nullptr, 0, nullptr); - if (!of) { - return false; - } - - prev_li = -1; lastSample[0] = 0; lastSample[1] = 0; buffPtr = 0; buffLen = 0; + bzero(hdr, sizeof(hdr)); + packetOff = 0; + state = WaitHeader; + preskip = 0; + output->begin(); // These are fixed by Opus @@ -80,8 +100,135 @@ bool AudioGeneratorOpus::begin(AudioFileSource *source, AudioOutput *output) { return true; } -bool AudioGeneratorOpus::loop() { +bool AudioGeneratorOpus::demux() { + int r; + uint8_t b; + //static int pktno = 0; + while (true) { + switch (state) { + case WaitHeader: + //audioLogger->printf("STATE: WaitHeader\n"); + if (!file->read(&b, 1)) { + return false; // No data + } + memmove(hdr, hdr + 1, 26); + hdr[26] = b; + if ((hdr[0] == 'O') && (hdr[1] == 'g') && (hdr[2] == 'g') && (hdr[3] == 'S') && (hdr[4] == 0)) { + // We have a header! + type = hdr[5]; + agp = hdr[13]; + for (int i = 1; i < 7; i++) { + agp <<= 8; + agp |= hdr[13 - i]; + } + ssn = hdr[14] | (hdr[15] << 8) | (hdr[16] << 16) | (hdr[17] << 24); + psn = hdr[18] | (hdr[19] << 8) | (hdr[20] << 16) | (hdr[21] << 24); + pcs = hdr[22] | (hdr[23] << 8) | (hdr[24] << 16) | (hdr[25] << 24); + ps = hdr[26]; + readPS = 0; + //audioLogger->printf("HEADER: typ: %d, agp: %llu, ssn: %08x, psn: %08x, pcs: %08x, ps: %d\n", type, agp, ssn, psn, pcs, ps); + state = WaitSegment; + } + break; + case WaitSegment: + //audioLogger->printf("STATE: WaitSegment\n"); + r = file->read(seg + readPS, ps - readPS); + readPS += r; // Keep track of what we read + if (readPS < ps) { + // Not enough data avail to finish, loop + return false; + } + //audioLogger->printf("SEGMENTS (%d): ", ps); + for (int i = 0; i < ps; i++) { + //audioLogger->printf(" %02x", seg[i]); + } + //audioLogger->printf("\n"); + curSeg = 0; + lacingBytesToRead = seg[0]; + state = ReadPacket; + break; + case ReadPacket: + //audioLogger->printf("STATE: ReadPacket\n"); + //audioLogger->printf("readpacket seg %d len %d\n", curSeg, seg[curSeg]); + r = file->read(packet + packetOff, lacingBytesToRead); + packetOff += r; + lacingBytesToRead -= r; + if (lacingBytesToRead) { + //audioLogger->printf("short read\n"); + return false; // Not enough avail + } + // Read lacing bit, see if there's more + if (seg[curSeg] != 0xff) { + //audioLogger->printf("PACKET %d (%d): ", pktno++, packetOff); + for (uint32_t i = 0; i < packetOff; i++) { + //audioLogger->printf(" %02X", packet[i]); + } + //audioLogger->printf("\n"); + // We have a full packet in the buffer, decode it + // First, is it a header? + if ((packetOff >= 17) && !memcmp(packet, "OpusHead", 8) && (packet[8] == 1)) { + channels = packet[9]; + preskip = packet[10] | (packet[11] << 8); + samplerate = packet[12] | (packet[13] << 8) | (packet[14] << 16) | (packet[15] << 24); + gain = packet[16] | (packet[17]++); + //audioLogger->printf("HEADER: chan: %d, sr: %d, skip %d\n", channels, samplerate, preskip); + packetOff = 0; // For better or worse, we've processed this pkt + } else if ((packetOff >= 9) && !memcmp(packet, "OpusTags", 8)) { + // This is an unparsed TAG. TODO find metadata format + packetOff = 0; // For better or worse, we've processed this pkt + } else { + // This should be a regular packet + int ret = opus_decode(od, packet, packetOff, buff, 2048, 0); + packetOff = 0; // For better or worse, we've processed this pkt + if (ret > 0) { + buffLen = ret * 2; + if (preskip) { + if (buffLen >= preskip) { + buffPtr = preskip; + preskip = 0; + //audioLogger->printf("donepreskip\n"); + } else { + buffPtr = buffLen; + preskip -= buffLen; + } + } else { + buffPtr = 0; + } + curSeg++; + if (curSeg >= ps) { + state = WaitHeader; + lacingBytesToRead = 0; + } else { + lacingBytesToRead = seg[curSeg]; + } + return true; // We have filled a buffer + } else { + //audioLogger->printf("nodecode\n"); + // Could be header pkt, we ignore them here + // That means we ignore the preskip value, for now + } + packetOff = 0; // For better or worse, we've processed this pkt + } + } + // Only have partial pkt, need next segment + curSeg++; + if (curSeg >= ps) { + state = WaitHeader; + lacingBytesToRead = 0; + } else { + lacingBytesToRead = seg[curSeg]; + } + break; + default: + state = WaitHeader; + break; + } + } +} + + +bool AudioGeneratorOpus::loop() { if (!running) { goto done; } @@ -92,16 +239,15 @@ bool AudioGeneratorOpus::loop() { do { if (buffPtr == buffLen) { - int ret = op_read_stereo(of, (opus_int16 *)buff, OPUS_BUFF); - if (ret == OP_HOLE) { - // fprintf(stderr,"\nHole detected! Corrupt file segment?\n"); - continue; - } else if (ret <= 0) { + // Will run until we either run out of data, would block, or decode something + if (!demux()) { running = false; goto done; } - buffPtr = 0; - buffLen = ret * 2; + } + if (buffPtr == buffLen) { + // Still nothing + goto done; } lastSample[AudioOutput::LEFTCHANNEL] = buff[buffPtr] & 0xffff; @@ -117,10 +263,10 @@ done: } bool AudioGeneratorOpus::stop() { - if (of) { - op_free(of); + if (od) { + free(od); } - of = nullptr; + od = nullptr; free(buff); buff = nullptr; running = false; @@ -131,30 +277,3 @@ bool AudioGeneratorOpus::stop() { bool AudioGeneratorOpus::isRunning() { return running; } - -int AudioGeneratorOpus::read_cb(unsigned char *_ptr, int _nbytes) { - if (_nbytes == 0) { - return 0; - } - _nbytes = file->read(_ptr, _nbytes); - if (_nbytes == 0) { - return -1; - } - return _nbytes; -} - -int AudioGeneratorOpus::seek_cb(opus_int64 _offset, int _whence) { - if (!file->seek((int32_t)_offset, _whence)) { - return -1; - } - return 0; -} - -opus_int64 AudioGeneratorOpus::tell_cb() { - return file->getPos(); -} - -int AudioGeneratorOpus::close_cb() { - // NO OP, we close in main loop - return 0; -} diff --git a/src/AudioGeneratorOpus.h b/src/AudioGeneratorOpus.h index ff9fb47..624de81 100644 --- a/src/AudioGeneratorOpus.h +++ b/src/AudioGeneratorOpus.h @@ -2,7 +2,7 @@ AudioGeneratorOpus Audio output generator that plays Opus audio files - Copyright (C) 2020 Earle F. Philhower, III + Copyright (C) 2025 Earle F. Philhower, III This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,8 +22,7 @@ #define _AUDIOGENERATOROPUS_H #include -//#include "libopus/opus.h" -#include "opusfile/opusfile.h" +#include "libopus/include/opus.h" class AudioGeneratorOpus : public AudioGenerator { public: @@ -34,35 +33,34 @@ public: virtual bool stop() override; virtual bool isRunning() override; -protected: - // Opus callbacks, need static functions to bounce into C++ from C - static int OPUS_read(void *_stream, unsigned char *_ptr, int _nbytes) { - return static_cast(_stream)->read_cb(_ptr, _nbytes); - } - static int OPUS_seek(void *_stream, opus_int64 _offset, int _whence) { - return static_cast(_stream)->seek_cb(_offset, _whence); - } - static opus_int64 OPUS_tell(void *_stream) { - return static_cast(_stream)->tell_cb(); - } - static int OPUS_close(void *_stream) { - return static_cast(_stream)->close_cb(); - } - - // Actual Opus callbacks - int read_cb(unsigned char *_ptr, int _nbytes); - int seek_cb(opus_int64 _offset, int _whence); - opus_int64 tell_cb(); - int close_cb(); - private: - OpusFileCallbacks cb = {OPUS_read, OPUS_seek, OPUS_tell, OPUS_close}; - OggOpusFile *of; - int prev_li; // To detect changes in streams + OpusDecoder *od = nullptr; - int16_t *buff; + uint8_t *packet; // Raw compressed, demuxed packet + uint32_t packetOff; + opus_int16 *buff; // Decoded PCM uint32_t buffPtr; uint32_t buffLen; + + bool demux(); + uint8_t hdr[27]; // Page header + enum {WaitHeader, WaitSegment, ReadPacket} state; + uint8_t type; + uint64_t agp; + uint32_t ssn; + uint32_t psn; + uint32_t pcs; + uint16_t ps; // packet lacing segments + uint16_t readPS; + uint8_t seg[256]; // Packet lacing in the current page + uint16_t curSeg; + uint32_t lacingBytesToRead; + void processPacket(); + // From the OpusHead + uint16_t preskip; + uint8_t channels; + uint32_t samplerate; + uint16_t gain; }; #endif diff --git a/src/libogg/AUTHORS b/src/libogg/AUTHORS deleted file mode 100644 index a0023f2..0000000 --- a/src/libogg/AUTHORS +++ /dev/null @@ -1,7 +0,0 @@ -Monty -Greg Maxwell -Ralph Giles -Cristian Adam -Tim Terriberry - -and the rest of the Xiph.Org Foundation. diff --git a/src/libogg/CHANGES b/src/libogg/CHANGES deleted file mode 100644 index 855b0b1..0000000 --- a/src/libogg/CHANGES +++ /dev/null @@ -1,104 +0,0 @@ -Version 1.3.4 (2019 August 30) - -* Faster slice-by-8 CRC32 implementation. - see https://lwn.net/Articles/453931/ for motivation. -* Add CMake build. -* Deprecate Visual Studio project files in favor of CMake. -* configure --disable-crc option for fuzzing. -* Various build fixes. -* Documentation and example code fixes. - -Version 1.3.3 (2017 November 7) - - * Fix an issue with corrupt continued packet handling. - * Update Windows projects and build settings. - * Remove Mac OS 9 build support. - -Version 1.3.2 (2014 May 27) - - * Fix an bug in oggpack_writecopy(). - -Version 1.3.1 (2013 May 12) - -* Guard against very large packets. -* Respect the configure --docdir override. -* Documentation fixes. -* More Windows build fixes. - -Version 1.3.0 (2011 August 4) - -* Add ogg_stream_flush_fill() call - This produces longer packets on flush, similar to - what ogg_stream_pageout_fill() does for single pages. -* Windows build fixes - -Version 1.2.2 (2010 December 07) - -* Build fix (types correction) for Mac OS X -* Update win32 project files to Visual Studio 2008 -* ogg_stream_pageout_fill documentation fix - -Version 1.2.1 (2010 November 01) - -* Various build updates (see SVN) -* Add ogg_stream_pageout_fill() to API to allow applications - greater explicit flexibility in page sizing. -* Documentation updates including multiplexing description, - terminology and API (incl. ogg_packet_clear(), - ogg_stream_pageout_fill()) -* Correct possible buffer overwrite in stream encoding on 32 bit - when a single packet exceed 250MB. -* Correct read-buffer overrun [without side effects] under - similar circumstances. -* Update unit testing to work properly with new page spill - heuristic. - -Version 1.2.0 (2010 March 25) - -* Alter default flushing behavior to span less often and use larger page - sizes when packet sizes are large. -* Build fixes for additional compilers -* Documentation updates - -Version 1.1.4 (2009 June 24) - -* New async error reporting mechanism. Calls made after a fatal error are - now safely handled in the event an error code is ignored -* Added allocation checks useful to some embedded applications -* fix possible read past end of buffer when reading 0 bits -* Updates to API documentation -* Build fixes - -Version 1.1.3 (2005 November 27) - - * Correct a bug in the granulepos field of pages where no packet ends - * New VS2003 and XCode builds, minor fixes to other builds - * documentation fixes and cleanup - -Version 1.1.2 (2004 September 23) - - * fix a bug with multipage packet assembly after seek - -Version 1.1.1 (2004 September 12) - - * various bugfixes - * important bugfix for 64-bit platforms - * various portability fixes - * autotools cleanup from Thomas Vander Stichele - * Symbian OS build support from Colin Ward at CSIRO - * new multiplexed Ogg stream documentation - -Version 1.1 (2003 November 17) - - * big-endian bitpacker routines for Theora - * various portability fixes - * improved API documentation - * RFC 3533 documentation of the format by Silvia Pfeiffer at CSIRO - * RFC 3534 documentation of the application/ogg mime-type by Linus Walleij - -Version 1.0 (2002 July 19) - - * First stable release - * little-endian bitpacker routines for Vorbis - * basic Ogg bitstream sync and coding support - diff --git a/src/libogg/COPYING b/src/libogg/COPYING deleted file mode 100644 index 6111c6c..0000000 --- a/src/libogg/COPYING +++ /dev/null @@ -1,28 +0,0 @@ -Copyright (c) 2002, Xiph.org Foundation - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -- Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -- Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -- Neither the name of the Xiph.org Foundation nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/libogg/README.esp8266.md b/src/libogg/README.esp8266.md deleted file mode 100644 index f63d68f..0000000 --- a/src/libogg/README.esp8266.md +++ /dev/null @@ -1,3 +0,0 @@ -This is libogg from Xiph, modified to build under Arduino by . - -OGG license/etc. unchanged. diff --git a/src/libogg/README.md b/src/libogg/README.md deleted file mode 100644 index c3be014..0000000 --- a/src/libogg/README.md +++ /dev/null @@ -1,133 +0,0 @@ -# Ogg - -[![Travis Build Status](https://travis-ci.org/xiph/ogg.svg?branch=master)](https://travis-ci.org/xiph/ogg) -[![Jenkins Build Status](https://mf4.xiph.org/jenkins/job/libogg/badge/icon)](https://mf4.xiph.org/jenkins/job/libogg/) -[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/xiph/ogg?branch=master&svg=true)](https://ci.appveyor.com/project/rillian/ogg) - -Ogg project codecs use the Ogg bitstream format to arrange the raw, -compressed bitstream into a more robust, useful form. For example, -the Ogg bitstream makes seeking, time stamping and error recovery -possible, as well as mixing several separate, concurrent media -streams into a single physical bitstream. - -## What's here ## -This source distribution includes libogg and nothing else. Other modules -(eg, the modules libvorbis, vorbis-tools for the Vorbis music codec, -libtheora for the Theora video codec) contain the codec libraries for -use with Ogg bitstreams. - -Directory: - -- `src` The source for libogg, a BSD-license implementation of the public domain Ogg bitstream format - -- `include` Library API headers - -- `doc` Ogg specification and libogg API documents - -- `win32` Win32 projects and build automation - -- `macosx` Mac OS X project and build files - -## Contact ## - -The Ogg homepage is located at https://www.xiph.org/ogg/ . -Up to date technical documents, contact information, source code and -pre-built utilities may be found there. - -## Building ## - -#### Building from tarball distributions #### - - ./configure - make - -and optionally (as root): - - make install - -This will install the Ogg libraries (static and shared) into -/usr/local/lib, includes into /usr/local/include and API -documentation into /usr/local/share/doc. - -#### Building from repository source #### - -A standard svn build should consist of nothing more than: - - ./autogen.sh - ./configure - make - -and as root if desired : - - make install - -#### Building on Windows #### - -Use the project file in the win32 directory. It should compile out of the box. - -#### Cross-compiling from Linux to Windows #### - -It is also possible to cross compile from Linux to windows using the MinGW -cross tools and even to run the test suite under Wine, the Linux/*nix -windows emulator. - -On Debian and Ubuntu systems, these cross compiler tools can be installed -by doing: - - sudo apt-get mingw32 mingw32-binutils mingw32-runtime wine - -Once these tools are installed its possible to compile and test by -executing the following commands, or something similar depending on -your system: - - ./configure --host=i586-mingw32msvc --target=i586-mingw32msvc --build=i586-linux - make - make check - -(Build instructions for Ogg codecs such as vorbis are similar and may -be found in those source modules' README files) - -## Building with CMake ## - -Ogg supports building using [CMake](http://www.cmake.org/). CMake is a meta build system that generates native projects for each platform. -To generate projects just run cmake replacing `YOUR-PROJECT-GENERATOR` with a proper generator from a list [here](http://www.cmake.org/cmake/help/v3.2/manual/cmake-generators.7.html): - - mkdir build - cd build - cmake -G YOUR-PROJECT-GENERATOR .. - -Note that by default cmake generates projects that will build static libraries. -To generate projects that will build dynamic library use `BUILD_SHARED_LIBS` option like this: - - cmake -G YOUR-PROJECT-GENERATOR -DBUILD_SHARED_LIBS=1 .. - -After projects are generated use them as usual - -#### Building on Windows #### - -Use proper generator for your Visual Studio version like: - - cmake -G "Visual Studio 12 2013" .. - -#### Building on Mac OS X #### - -Use Xcode generator. To build framework run: - - cmake -G Xcode -DBUILD_FRAMEWORK=1 .. - -#### Building on Linux #### - -Use Makefile generator which is default one. - - cmake .. - make - -## License ## - -THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. -USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS -GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE -IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - -THE OggVorbis SOURCE CODE IS COPYRIGHT (C) 1994-2019 -by the Xiph.Org Foundation https://www.xiph.org/ diff --git a/src/libogg/bitwise.c b/src/libogg/bitwise.c deleted file mode 100644 index 3ca9ecd..0000000 --- a/src/libogg/bitwise.c +++ /dev/null @@ -1,1215 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE Ogg CONTAINER SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2014 - by the Xiph.Org Foundation http://www.xiph.org/ - * * - ******************************************************************** - - function: packing variable sized words into an octet stream - - ********************************************************************/ - -/* We're 'LSb' endian; if we write a word but read individual bits, - then we'll read the lsb first */ - -#include -#include -#include -#include "ogg/ogg.h" - -#define BUFFER_INCREMENT 256 - -static const unsigned long mask[] = { - 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, - 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, - 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, - 0x00007fff, 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff, - 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff, - 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff, 0x1fffffff, - 0x3fffffff, 0x7fffffff, 0xffffffff -}; - -static const unsigned int mask8B[] = -{0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; - -void oggpack_writeinit(oggpack_buffer *b) { - memset(b, 0, sizeof(*b)); - b->ptr = b->buffer = _ogg_malloc(BUFFER_INCREMENT); - b->buffer[0] = '\0'; - b->storage = BUFFER_INCREMENT; -} - -void oggpackB_writeinit(oggpack_buffer *b) { - oggpack_writeinit(b); -} - -int oggpack_writecheck(oggpack_buffer *b) { - if (!b->ptr || !b->storage) { - return -1; - } - return 0; -} - -int oggpackB_writecheck(oggpack_buffer *b) { - return oggpack_writecheck(b); -} - -void oggpack_writetrunc(oggpack_buffer *b, long bits) { - long bytes = bits >> 3; - if (b->ptr) { - bits -= bytes * 8; - b->ptr = b->buffer + bytes; - b->endbit = bits; - b->endbyte = bytes; - *b->ptr &= mask[bits]; - } -} - -void oggpackB_writetrunc(oggpack_buffer *b, long bits) { - long bytes = bits >> 3; - if (b->ptr) { - bits -= bytes * 8; - b->ptr = b->buffer + bytes; - b->endbit = bits; - b->endbyte = bytes; - *b->ptr &= mask8B[bits]; - } -} - -/* Takes only up to 32 bits. */ -void oggpack_write(oggpack_buffer *b, unsigned long value, int bits) { - if (bits < 0 || bits > 32) { - goto err; - } - if (b->endbyte >= b->storage - 4) { - void *ret; - if (!b->ptr) { - return; - } - if (b->storage > LONG_MAX - BUFFER_INCREMENT) { - goto err; - } - ret = _ogg_realloc(b->buffer, b->storage + BUFFER_INCREMENT); - if (!ret) { - goto err; - } - b->buffer = ret; - b->storage += BUFFER_INCREMENT; - b->ptr = b->buffer + b->endbyte; - } - - value &= mask[bits]; - bits += b->endbit; - - b->ptr[0] |= value << b->endbit; - - if (bits >= 8) { - b->ptr[1] = (unsigned char)(value >> (8 - b->endbit)); - if (bits >= 16) { - b->ptr[2] = (unsigned char)(value >> (16 - b->endbit)); - if (bits >= 24) { - b->ptr[3] = (unsigned char)(value >> (24 - b->endbit)); - if (bits >= 32) { - if (b->endbit) { - b->ptr[4] = (unsigned char)(value >> (32 - b->endbit)); - } else { - b->ptr[4] = 0; - } - } - } - } - } - - b->endbyte += bits / 8; - b->ptr += bits / 8; - b->endbit = bits & 7; - return; -err: - oggpack_writeclear(b); -} - -/* Takes only up to 32 bits. */ -void oggpackB_write(oggpack_buffer *b, unsigned long value, int bits) { - if (bits < 0 || bits > 32) { - goto err; - } - if (b->endbyte >= b->storage - 4) { - void *ret; - if (!b->ptr) { - return; - } - if (b->storage > LONG_MAX - BUFFER_INCREMENT) { - goto err; - } - ret = _ogg_realloc(b->buffer, b->storage + BUFFER_INCREMENT); - if (!ret) { - goto err; - } - b->buffer = ret; - b->storage += BUFFER_INCREMENT; - b->ptr = b->buffer + b->endbyte; - } - - value = (value & mask[bits]) << (32 - bits); - bits += b->endbit; - - b->ptr[0] |= value >> (24 + b->endbit); - - if (bits >= 8) { - b->ptr[1] = (unsigned char)(value >> (16 + b->endbit)); - if (bits >= 16) { - b->ptr[2] = (unsigned char)(value >> (8 + b->endbit)); - if (bits >= 24) { - b->ptr[3] = (unsigned char)(value >> (b->endbit)); - if (bits >= 32) { - if (b->endbit) { - b->ptr[4] = (unsigned char)(value << (8 - b->endbit)); - } else { - b->ptr[4] = 0; - } - } - } - } - } - - b->endbyte += bits / 8; - b->ptr += bits / 8; - b->endbit = bits & 7; - return; -err: - oggpack_writeclear(b); -} - -void oggpack_writealign(oggpack_buffer *b) { - int bits = 8 - b->endbit; - if (bits < 8) { - oggpack_write(b, 0, bits); - } -} - -void oggpackB_writealign(oggpack_buffer *b) { - int bits = 8 - b->endbit; - if (bits < 8) { - oggpackB_write(b, 0, bits); - } -} - -static void oggpack_writecopy_helper(oggpack_buffer *b, - void *source, - long bits, - void (*w)(oggpack_buffer *, - unsigned long, - int), - int msb) { - unsigned char *ptr = (unsigned char *)source; - - long bytes = bits / 8; - long pbytes = (b->endbit + bits) / 8; - bits -= bytes * 8; - - /* expand storage up-front */ - if (b->endbyte + pbytes >= b->storage) { - void *ret; - if (!b->ptr) { - goto err; - } - if (b->storage > b->endbyte + pbytes + BUFFER_INCREMENT) { - goto err; - } - b->storage = b->endbyte + pbytes + BUFFER_INCREMENT; - ret = _ogg_realloc(b->buffer, b->storage); - if (!ret) { - goto err; - } - b->buffer = ret; - b->ptr = b->buffer + b->endbyte; - } - - /* copy whole octets */ - if (b->endbit) { - int i; - /* unaligned copy. Do it the hard way. */ - for (i = 0; i < bytes; i++) { - w(b, (unsigned long)(ptr[i]), 8); - } - } else { - /* aligned block copy */ - memmove(b->ptr, source, bytes); - b->ptr += bytes; - b->endbyte += bytes; - *b->ptr = 0; - } - - /* copy trailing bits */ - if (bits) { - if (msb) { - w(b, (unsigned long)(ptr[bytes] >> (8 - bits)), bits); - } else { - w(b, (unsigned long)(ptr[bytes]), bits); - } - } - return; -err: - oggpack_writeclear(b); -} - -void oggpack_writecopy(oggpack_buffer *b, void *source, long bits) { - oggpack_writecopy_helper(b, source, bits, oggpack_write, 0); -} - -void oggpackB_writecopy(oggpack_buffer *b, void *source, long bits) { - oggpack_writecopy_helper(b, source, bits, oggpackB_write, 1); -} - -void oggpack_reset(oggpack_buffer *b) { - if (!b->ptr) { - return; - } - b->ptr = b->buffer; - b->buffer[0] = 0; - b->endbit = b->endbyte = 0; -} - -void oggpackB_reset(oggpack_buffer *b) { - oggpack_reset(b); -} - -void oggpack_writeclear(oggpack_buffer *b) { - if (b->buffer) { - _ogg_free(b->buffer); - } - memset(b, 0, sizeof(*b)); -} - -void oggpackB_writeclear(oggpack_buffer *b) { - oggpack_writeclear(b); -} - -void oggpack_readinit(oggpack_buffer *b, unsigned char *buf, int bytes) { - memset(b, 0, sizeof(*b)); - b->buffer = b->ptr = buf; - b->storage = bytes; -} - -void oggpackB_readinit(oggpack_buffer *b, unsigned char *buf, int bytes) { - oggpack_readinit(b, buf, bytes); -} - -/* Read in bits without advancing the bitptr; bits <= 32 */ -long oggpack_look(oggpack_buffer *b, int bits) { - unsigned long ret; - unsigned long m; - - if (bits < 0 || bits > 32) { - return -1; - } - m = mask[bits]; - bits += b->endbit; - - if (b->endbyte >= b->storage - 4) { - /* not the main path */ - if (b->endbyte > b->storage - ((bits + 7) >> 3)) { - return -1; - } - /* special case to avoid reading b->ptr[0], which might be past the end of - the buffer; also skips some useless accounting */ - else if (!bits) { - return (0L); - } - } - - ret = b->ptr[0] >> b->endbit; - if (bits > 8) { - ret |= b->ptr[1] << (8 - b->endbit); - if (bits > 16) { - ret |= b->ptr[2] << (16 - b->endbit); - if (bits > 24) { - ret |= b->ptr[3] << (24 - b->endbit); - if (bits > 32 && b->endbit) { - ret |= b->ptr[4] << (32 - b->endbit); - } - } - } - } - return (m & ret); -} - -/* Read in bits without advancing the bitptr; bits <= 32 */ -long oggpackB_look(oggpack_buffer *b, int bits) { - unsigned long ret; - int m = 32 - bits; - - if (m < 0 || m > 32) { - return -1; - } - bits += b->endbit; - - if (b->endbyte >= b->storage - 4) { - /* not the main path */ - if (b->endbyte > b->storage - ((bits + 7) >> 3)) { - return -1; - } - /* special case to avoid reading b->ptr[0], which might be past the end of - the buffer; also skips some useless accounting */ - else if (!bits) { - return (0L); - } - } - - ret = b->ptr[0] << (24 + b->endbit); - if (bits > 8) { - ret |= b->ptr[1] << (16 + b->endbit); - if (bits > 16) { - ret |= b->ptr[2] << (8 + b->endbit); - if (bits > 24) { - ret |= b->ptr[3] << (b->endbit); - if (bits > 32 && b->endbit) { - ret |= b->ptr[4] >> (8 - b->endbit); - } - } - } - } - return ((ret & 0xffffffff) >> (m >> 1)) >> ((m + 1) >> 1); -} - -long oggpack_look1(oggpack_buffer *b) { - if (b->endbyte >= b->storage) { - return (-1); - } - return ((b->ptr[0] >> b->endbit) & 1); -} - -long oggpackB_look1(oggpack_buffer *b) { - if (b->endbyte >= b->storage) { - return (-1); - } - return ((b->ptr[0] >> (7 - b->endbit)) & 1); -} - -void oggpack_adv(oggpack_buffer *b, int bits) { - bits += b->endbit; - - if (b->endbyte > b->storage - ((bits + 7) >> 3)) { - goto overflow; - } - - b->ptr += bits / 8; - b->endbyte += bits / 8; - b->endbit = bits & 7; - return; - -overflow: - b->ptr = NULL; - b->endbyte = b->storage; - b->endbit = 1; -} - -void oggpackB_adv(oggpack_buffer *b, int bits) { - oggpack_adv(b, bits); -} - -void oggpack_adv1(oggpack_buffer *b) { - if (++(b->endbit) > 7) { - b->endbit = 0; - b->ptr++; - b->endbyte++; - } -} - -void oggpackB_adv1(oggpack_buffer *b) { - oggpack_adv1(b); -} - -/* bits <= 32 */ -long oggpack_read(oggpack_buffer *b, int bits) { - long ret; - unsigned long m; - - if (bits < 0 || bits > 32) { - goto err; - } - m = mask[bits]; - bits += b->endbit; - - if (b->endbyte >= b->storage - 4) { - /* not the main path */ - if (b->endbyte > b->storage - ((bits + 7) >> 3)) { - goto overflow; - } - /* special case to avoid reading b->ptr[0], which might be past the end of - the buffer; also skips some useless accounting */ - else if (!bits) { - return (0L); - } - } - - ret = b->ptr[0] >> b->endbit; - if (bits > 8) { - ret |= b->ptr[1] << (8 - b->endbit); - if (bits > 16) { - ret |= b->ptr[2] << (16 - b->endbit); - if (bits > 24) { - ret |= b->ptr[3] << (24 - b->endbit); - if (bits > 32 && b->endbit) { - ret |= b->ptr[4] << (32 - b->endbit); - } - } - } - } - ret &= m; - b->ptr += bits / 8; - b->endbyte += bits / 8; - b->endbit = bits & 7; - return ret; - -overflow: -err: - b->ptr = NULL; - b->endbyte = b->storage; - b->endbit = 1; - return -1L; -} - -/* bits <= 32 */ -long oggpackB_read(oggpack_buffer *b, int bits) { - long ret; - long m = 32 - bits; - - if (m < 0 || m > 32) { - goto err; - } - bits += b->endbit; - - if (b->endbyte + 4 >= b->storage) { - /* not the main path */ - if (b->endbyte > b->storage - ((bits + 7) >> 3)) { - goto overflow; - } - /* special case to avoid reading b->ptr[0], which might be past the end of - the buffer; also skips some useless accounting */ - else if (!bits) { - return (0L); - } - } - - ret = b->ptr[0] << (24 + b->endbit); - if (bits > 8) { - ret |= b->ptr[1] << (16 + b->endbit); - if (bits > 16) { - ret |= b->ptr[2] << (8 + b->endbit); - if (bits > 24) { - ret |= b->ptr[3] << (b->endbit); - if (bits > 32 && b->endbit) { - ret |= b->ptr[4] >> (8 - b->endbit); - } - } - } - } - ret = ((ret & 0xffffffffUL) >> (m >> 1)) >> ((m + 1) >> 1); - - b->ptr += bits / 8; - b->endbyte += bits / 8; - b->endbit = bits & 7; - return ret; - -overflow: -err: - b->ptr = NULL; - b->endbyte = b->storage; - b->endbit = 1; - return -1L; -} - -long oggpack_read1(oggpack_buffer *b) { - long ret; - - if (b->endbyte >= b->storage) { - goto overflow; - } - ret = (b->ptr[0] >> b->endbit) & 1; - - b->endbit++; - if (b->endbit > 7) { - b->endbit = 0; - b->ptr++; - b->endbyte++; - } - return ret; - -overflow: - b->ptr = NULL; - b->endbyte = b->storage; - b->endbit = 1; - return -1L; -} - -long oggpackB_read1(oggpack_buffer *b) { - long ret; - - if (b->endbyte >= b->storage) { - goto overflow; - } - ret = (b->ptr[0] >> (7 - b->endbit)) & 1; - - b->endbit++; - if (b->endbit > 7) { - b->endbit = 0; - b->ptr++; - b->endbyte++; - } - return ret; - -overflow: - b->ptr = NULL; - b->endbyte = b->storage; - b->endbit = 1; - return -1L; -} - -long oggpack_bytes(oggpack_buffer *b) { - return (b->endbyte + (b->endbit + 7) / 8); -} - -long oggpack_bits(oggpack_buffer *b) { - return (b->endbyte * 8 + b->endbit); -} - -long oggpackB_bytes(oggpack_buffer *b) { - return oggpack_bytes(b); -} - -long oggpackB_bits(oggpack_buffer *b) { - return oggpack_bits(b); -} - -unsigned char *oggpack_get_buffer(oggpack_buffer *b) { - return (b->buffer); -} - -unsigned char *oggpackB_get_buffer(oggpack_buffer *b) { - return oggpack_get_buffer(b); -} - -/* Self test of the bitwise routines; everything else is based on - them, so they damned well better be solid. */ - -#ifdef _V_SELFTEST -#include - -static int ilog(unsigned int v) { - int ret = 0; - while (v) { - ret++; - v >>= 1; - } - return (ret); -} - -oggpack_buffer o; -oggpack_buffer r; - -void report(char *in) { - fprintf(stderr, "%s", in); - exit(1); -} - -void cliptest(unsigned long *b, int vals, int bits, int *comp, int compsize) { - long bytes, i; - unsigned char *buffer; - - oggpack_reset(&o); - for (i = 0; i < vals; i++) { - oggpack_write(&o, b[i], bits ? bits : ilog(b[i])); - } - buffer = oggpack_get_buffer(&o); - bytes = oggpack_bytes(&o); - if (bytes != compsize) { - report("wrong number of bytes!\n"); - } - for (i = 0; i < bytes; i++)if (buffer[i] != comp[i]) { - for (i = 0; i < bytes; i++) { - fprintf(stderr, "%x %x\n", (int)buffer[i], (int)comp[i]); - } - report("wrote incorrect value!\n"); - } - oggpack_readinit(&r, buffer, bytes); - for (i = 0; i < vals; i++) { - int tbit = bits ? bits : ilog(b[i]); - if (oggpack_look(&r, tbit) == -1) { - report("out of data!\n"); - } - if (oggpack_look(&r, tbit) != (b[i]&mask[tbit])) { - report("looked at incorrect value!\n"); - } - if (tbit == 1) - if (oggpack_look1(&r) != (b[i]&mask[tbit])) { - report("looked at single bit incorrect value!\n"); - } - if (tbit == 1) { - if (oggpack_read1(&r) != (b[i]&mask[tbit])) { - report("read incorrect single bit value!\n"); - } - } else { - if (oggpack_read(&r, tbit) != (b[i]&mask[tbit])) { - report("read incorrect value!\n"); - } - } - } - if (oggpack_bytes(&r) != bytes) { - report("leftover bytes after read!\n"); - } -} - -void cliptestB(unsigned long *b, int vals, int bits, int *comp, int compsize) { - long bytes, i; - unsigned char *buffer; - - oggpackB_reset(&o); - for (i = 0; i < vals; i++) { - oggpackB_write(&o, b[i], bits ? bits : ilog(b[i])); - } - buffer = oggpackB_get_buffer(&o); - bytes = oggpackB_bytes(&o); - if (bytes != compsize) { - report("wrong number of bytes!\n"); - } - for (i = 0; i < bytes; i++)if (buffer[i] != comp[i]) { - for (i = 0; i < bytes; i++) { - fprintf(stderr, "%x %x\n", (int)buffer[i], (int)comp[i]); - } - report("wrote incorrect value!\n"); - } - oggpackB_readinit(&r, buffer, bytes); - for (i = 0; i < vals; i++) { - int tbit = bits ? bits : ilog(b[i]); - if (oggpackB_look(&r, tbit) == -1) { - report("out of data!\n"); - } - if (oggpackB_look(&r, tbit) != (b[i]&mask[tbit])) { - report("looked at incorrect value!\n"); - } - if (tbit == 1) - if (oggpackB_look1(&r) != (b[i]&mask[tbit])) { - report("looked at single bit incorrect value!\n"); - } - if (tbit == 1) { - if (oggpackB_read1(&r) != (b[i]&mask[tbit])) { - report("read incorrect single bit value!\n"); - } - } else { - if (oggpackB_read(&r, tbit) != (b[i]&mask[tbit])) { - report("read incorrect value!\n"); - } - } - } - if (oggpackB_bytes(&r) != bytes) { - report("leftover bytes after read!\n"); - } -} - -void copytest(int prefill, int copy) { - oggpack_buffer source_write; - oggpack_buffer dest_write; - oggpack_buffer source_read; - oggpack_buffer dest_read; - unsigned char *source; - unsigned char *dest; - long source_bytes, dest_bytes; - int i; - - oggpack_writeinit(&source_write); - oggpack_writeinit(&dest_write); - - for (i = 0; i < (prefill + copy + 7) / 8; i++) { - oggpack_write(&source_write, (i ^ 0x5a) & 0xff, 8); - } - source = oggpack_get_buffer(&source_write); - source_bytes = oggpack_bytes(&source_write); - - /* prefill */ - oggpack_writecopy(&dest_write, source, prefill); - - /* check buffers; verify end byte masking */ - dest = oggpack_get_buffer(&dest_write); - dest_bytes = oggpack_bytes(&dest_write); - if (dest_bytes != (prefill + 7) / 8) { - fprintf(stderr, "wrong number of bytes after prefill! %ld!=%d\n", dest_bytes, (prefill + 7) / 8); - exit(1); - } - oggpack_readinit(&source_read, source, source_bytes); - oggpack_readinit(&dest_read, dest, dest_bytes); - - for (i = 0; i < prefill; i += 8) { - int s = oggpack_read(&source_read, prefill - i < 8 ? prefill - i : 8); - int d = oggpack_read(&dest_read, prefill - i < 8 ? prefill - i : 8); - if (s != d) { - fprintf(stderr, "prefill=%d mismatch! byte %d, %x!=%x\n", prefill, i / 8, s, d); - exit(1); - } - } - if (prefill < dest_bytes) { - if (oggpack_read(&dest_read, dest_bytes - prefill) != 0) { - fprintf(stderr, "prefill=%d mismatch! trailing bits not zero\n", prefill); - exit(1); - } - } - - /* second copy */ - oggpack_writecopy(&dest_write, source, copy); - - /* check buffers; verify end byte masking */ - dest = oggpack_get_buffer(&dest_write); - dest_bytes = oggpack_bytes(&dest_write); - if (dest_bytes != (copy + prefill + 7) / 8) { - fprintf(stderr, "wrong number of bytes after prefill+copy! %ld!=%d\n", dest_bytes, (copy + prefill + 7) / 8); - exit(1); - } - oggpack_readinit(&source_read, source, source_bytes); - oggpack_readinit(&dest_read, dest, dest_bytes); - - for (i = 0; i < prefill; i += 8) { - int s = oggpack_read(&source_read, prefill - i < 8 ? prefill - i : 8); - int d = oggpack_read(&dest_read, prefill - i < 8 ? prefill - i : 8); - if (s != d) { - fprintf(stderr, "prefill=%d mismatch! byte %d, %x!=%x\n", prefill, i / 8, s, d); - exit(1); - } - } - - oggpack_readinit(&source_read, source, source_bytes); - for (i = 0; i < copy; i += 8) { - int s = oggpack_read(&source_read, copy - i < 8 ? copy - i : 8); - int d = oggpack_read(&dest_read, copy - i < 8 ? copy - i : 8); - if (s != d) { - fprintf(stderr, "prefill=%d copy=%d mismatch! byte %d, %x!=%x\n", prefill, copy, i / 8, s, d); - exit(1); - } - } - - if (copy + prefill < dest_bytes) { - if (oggpack_read(&dest_read, dest_bytes - copy - prefill) != 0) { - fprintf(stderr, "prefill=%d copy=%d mismatch! trailing bits not zero\n", prefill, copy); - exit(1); - } - } - - oggpack_writeclear(&source_write); - oggpack_writeclear(&dest_write); - - -} - -void copytestB(int prefill, int copy) { - oggpack_buffer source_write; - oggpack_buffer dest_write; - oggpack_buffer source_read; - oggpack_buffer dest_read; - unsigned char *source; - unsigned char *dest; - long source_bytes, dest_bytes; - int i; - - oggpackB_writeinit(&source_write); - oggpackB_writeinit(&dest_write); - - for (i = 0; i < (prefill + copy + 7) / 8; i++) { - oggpackB_write(&source_write, (i ^ 0x5a) & 0xff, 8); - } - source = oggpackB_get_buffer(&source_write); - source_bytes = oggpackB_bytes(&source_write); - - /* prefill */ - oggpackB_writecopy(&dest_write, source, prefill); - - /* check buffers; verify end byte masking */ - dest = oggpackB_get_buffer(&dest_write); - dest_bytes = oggpackB_bytes(&dest_write); - if (dest_bytes != (prefill + 7) / 8) { - fprintf(stderr, "wrong number of bytes after prefill! %ld!=%d\n", dest_bytes, (prefill + 7) / 8); - exit(1); - } - oggpackB_readinit(&source_read, source, source_bytes); - oggpackB_readinit(&dest_read, dest, dest_bytes); - - for (i = 0; i < prefill; i += 8) { - int s = oggpackB_read(&source_read, prefill - i < 8 ? prefill - i : 8); - int d = oggpackB_read(&dest_read, prefill - i < 8 ? prefill - i : 8); - if (s != d) { - fprintf(stderr, "prefill=%d mismatch! byte %d, %x!=%x\n", prefill, i / 8, s, d); - exit(1); - } - } - if (prefill < dest_bytes) { - if (oggpackB_read(&dest_read, dest_bytes - prefill) != 0) { - fprintf(stderr, "prefill=%d mismatch! trailing bits not zero\n", prefill); - exit(1); - } - } - - /* second copy */ - oggpackB_writecopy(&dest_write, source, copy); - - /* check buffers; verify end byte masking */ - dest = oggpackB_get_buffer(&dest_write); - dest_bytes = oggpackB_bytes(&dest_write); - if (dest_bytes != (copy + prefill + 7) / 8) { - fprintf(stderr, "wrong number of bytes after prefill+copy! %ld!=%d\n", dest_bytes, (copy + prefill + 7) / 8); - exit(1); - } - oggpackB_readinit(&source_read, source, source_bytes); - oggpackB_readinit(&dest_read, dest, dest_bytes); - - for (i = 0; i < prefill; i += 8) { - int s = oggpackB_read(&source_read, prefill - i < 8 ? prefill - i : 8); - int d = oggpackB_read(&dest_read, prefill - i < 8 ? prefill - i : 8); - if (s != d) { - fprintf(stderr, "prefill=%d mismatch! byte %d, %x!=%x\n", prefill, i / 8, s, d); - exit(1); - } - } - - oggpackB_readinit(&source_read, source, source_bytes); - for (i = 0; i < copy; i += 8) { - int s = oggpackB_read(&source_read, copy - i < 8 ? copy - i : 8); - int d = oggpackB_read(&dest_read, copy - i < 8 ? copy - i : 8); - if (s != d) { - fprintf(stderr, "prefill=%d copy=%d mismatch! byte %d, %x!=%x\n", prefill, copy, i / 8, s, d); - exit(1); - } - } - - if (copy + prefill < dest_bytes) { - if (oggpackB_read(&dest_read, dest_bytes - copy - prefill) != 0) { - fprintf(stderr, "prefill=%d copy=%d mismatch! trailing bits not zero\n", prefill, copy); - exit(1); - } - } - - oggpackB_writeclear(&source_write); - oggpackB_writeclear(&dest_write); - -} - -int main(void) { - unsigned char *buffer; - long bytes, i, j; - static unsigned long testbuffer1[] = { - 18, 12, 103948, 4325, 543, 76, 432, 52, 3, 65, 4, 56, 32, 42, 34, 21, 1, 23, 32, 546, 456, 7, - 567, 56, 8, 8, 55, 3, 52, 342, 341, 4, 265, 7, 67, 86, 2199, 21, 7, 1, 5, 1, 4 - }; - int test1size = 43; - - static unsigned long testbuffer2[] = { - 216531625L, 1237861823, 56732452, 131, 3212421, 12325343, 34547562, 12313212, - 1233432, 534, 5, 346435231, 14436467, 7869299, 76326614, 167548585, - 85525151, 0, 12321, 1, 349528352 - }; - int test2size = 21; - - static unsigned long testbuffer3[] = { - 1, 0, 14, 0, 1, 0, 12, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, - 0, 1, 30, 1, 1, 1, 0, 0, 1, 0, 0, 0, 12, 0, 11, 0, 1, 0, 0, 1 - }; - int test3size = 56; - - static unsigned long large[] = { - 2136531625L, 2137861823, 56732452, 131, 3212421, 12325343, 34547562, 12313212, - 1233432, 534, 5, 2146435231, 14436467, 7869299, 76326614, 167548585, - 85525151, 0, 12321, 1, 2146528352 - }; - - int onesize = 33; - static int one[33] = {146, 25, 44, 151, 195, 15, 153, 176, 233, 131, 196, 65, 85, 172, 47, 40, - 34, 242, 223, 136, 35, 222, 211, 86, 171, 50, 225, 135, 214, 75, 172, - 223, 4 - }; - static int oneB[33] = {150, 101, 131, 33, 203, 15, 204, 216, 105, 193, 156, 65, 84, 85, 222, - 8, 139, 145, 227, 126, 34, 55, 244, 171, 85, 100, 39, 195, 173, 18, - 245, 251, 128 - }; - - int twosize = 6; - static int two[6] = {61, 255, 255, 251, 231, 29}; - static int twoB[6] = {247, 63, 255, 253, 249, 120}; - - int threesize = 54; - static int three[54] = {169, 2, 232, 252, 91, 132, 156, 36, 89, 13, 123, 176, 144, 32, 254, - 142, 224, 85, 59, 121, 144, 79, 124, 23, 67, 90, 90, 216, 79, 23, 83, - 58, 135, 196, 61, 55, 129, 183, 54, 101, 100, 170, 37, 127, 126, 10, - 100, 52, 4, 14, 18, 86, 77, 1 - }; - static int threeB[54] = {206, 128, 42, 153, 57, 8, 183, 251, 13, 89, 36, 30, 32, 144, 183, - 130, 59, 240, 121, 59, 85, 223, 19, 228, 180, 134, 33, 107, 74, 98, - 233, 253, 196, 135, 63, 2, 110, 114, 50, 155, 90, 127, 37, 170, 104, - 200, 20, 254, 4, 58, 106, 176, 144, 0 - }; - - int foursize = 38; - static int four[38] = {18, 6, 163, 252, 97, 194, 104, 131, 32, 1, 7, 82, 137, 42, 129, 11, 72, - 132, 60, 220, 112, 8, 196, 109, 64, 179, 86, 9, 137, 195, 208, 122, 169, - 28, 2, 133, 0, 1 - }; - static int fourB[38] = {36, 48, 102, 83, 243, 24, 52, 7, 4, 35, 132, 10, 145, 21, 2, 93, 2, 41, - 1, 219, 184, 16, 33, 184, 54, 149, 170, 132, 18, 30, 29, 98, 229, 67, - 129, 10, 4, 32 - }; - - int fivesize = 45; - static int five[45] = {169, 2, 126, 139, 144, 172, 30, 4, 80, 72, 240, 59, 130, 218, 73, 62, - 241, 24, 210, 44, 4, 20, 0, 248, 116, 49, 135, 100, 110, 130, 181, 169, - 84, 75, 159, 2, 1, 0, 132, 192, 8, 0, 0, 18, 22 - }; - static int fiveB[45] = {1, 84, 145, 111, 245, 100, 128, 8, 56, 36, 40, 71, 126, 78, 213, 226, - 124, 105, 12, 0, 133, 128, 0, 162, 233, 242, 67, 152, 77, 205, 77, - 172, 150, 169, 129, 79, 128, 0, 6, 4, 32, 0, 27, 9, 0 - }; - - int sixsize = 7; - static int six[7] = {17, 177, 170, 242, 169, 19, 148}; - static int sixB[7] = {136, 141, 85, 79, 149, 200, 41}; - - /* Test read/write together */ - /* Later we test against pregenerated bitstreams */ - oggpack_writeinit(&o); - - fprintf(stderr, "\nSmall preclipped packing (LSb): "); - cliptest(testbuffer1, test1size, 0, one, onesize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nNull bit call (LSb): "); - cliptest(testbuffer3, test3size, 0, two, twosize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nLarge preclipped packing (LSb): "); - cliptest(testbuffer2, test2size, 0, three, threesize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\n32 bit preclipped packing (LSb): "); - oggpack_reset(&o); - for (i = 0; i < test2size; i++) { - oggpack_write(&o, large[i], 32); - } - buffer = oggpack_get_buffer(&o); - bytes = oggpack_bytes(&o); - oggpack_readinit(&r, buffer, bytes); - for (i = 0; i < test2size; i++) { - if (oggpack_look(&r, 32) == -1) { - report("out of data. failed!"); - } - if (oggpack_look(&r, 32) != large[i]) { - fprintf(stderr, "%ld != %lu (%lx!=%lx):", oggpack_look(&r, 32), large[i], - oggpack_look(&r, 32), large[i]); - report("read incorrect value!\n"); - } - oggpack_adv(&r, 32); - } - if (oggpack_bytes(&r) != bytes) { - report("leftover bytes after read!\n"); - } - fprintf(stderr, "ok."); - - fprintf(stderr, "\nSmall unclipped packing (LSb): "); - cliptest(testbuffer1, test1size, 7, four, foursize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nLarge unclipped packing (LSb): "); - cliptest(testbuffer2, test2size, 17, five, fivesize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nSingle bit unclipped packing (LSb): "); - cliptest(testbuffer3, test3size, 1, six, sixsize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nTesting read past end (LSb): "); - oggpack_readinit(&r, (unsigned char *)"\0\0\0\0\0\0\0\0", 8); - for (i = 0; i < 64; i++) { - if (oggpack_read(&r, 1) != 0) { - fprintf(stderr, "failed; got -1 prematurely.\n"); - exit(1); - } - } - if (oggpack_look(&r, 1) != -1 || - oggpack_read(&r, 1) != -1) { - fprintf(stderr, "failed; read past end without -1.\n"); - exit(1); - } - oggpack_readinit(&r, (unsigned char *)"\0\0\0\0\0\0\0\0", 8); - if (oggpack_read(&r, 30) != 0 || oggpack_read(&r, 16) != 0) { - fprintf(stderr, "failed 2; got -1 prematurely.\n"); - exit(1); - } - - if (oggpack_look(&r, 18) != 0 || - oggpack_look(&r, 18) != 0) { - fprintf(stderr, "failed 3; got -1 prematurely.\n"); - exit(1); - } - if (oggpack_look(&r, 19) != -1 || - oggpack_look(&r, 19) != -1) { - fprintf(stderr, "failed; read past end without -1.\n"); - exit(1); - } - if (oggpack_look(&r, 32) != -1 || - oggpack_look(&r, 32) != -1) { - fprintf(stderr, "failed; read past end without -1.\n"); - exit(1); - } - oggpack_writeclear(&o); - fprintf(stderr, "ok."); - - /* this is partly glassbox; we're mostly concerned about the allocation boundaries */ - - fprintf(stderr, "\nTesting aligned writecopies (LSb): "); - for (i = 0; i < 71; i++) - for (j = 0; j < 5; j++) { - copytest(j * 8, i); - } - for (i = BUFFER_INCREMENT * 8 - 71; i < BUFFER_INCREMENT * 8 + 71; i++) - for (j = 0; j < 5; j++) { - copytest(j * 8, i); - } - fprintf(stderr, "ok. "); - - fprintf(stderr, "\nTesting unaligned writecopies (LSb): "); - for (i = 0; i < 71; i++) - for (j = 1; j < 40; j++) - if (j & 0x7) { - copytest(j, i); - } - for (i = BUFFER_INCREMENT * 8 - 71; i < BUFFER_INCREMENT * 8 + 71; i++) - for (j = 1; j < 40; j++) - if (j & 0x7) { - copytest(j, i); - } - - fprintf(stderr, "ok. \n"); - - - /********** lazy, cut-n-paste retest with MSb packing ***********/ - - /* Test read/write together */ - /* Later we test against pregenerated bitstreams */ - oggpackB_writeinit(&o); - - fprintf(stderr, "\nSmall preclipped packing (MSb): "); - cliptestB(testbuffer1, test1size, 0, oneB, onesize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nNull bit call (MSb): "); - cliptestB(testbuffer3, test3size, 0, twoB, twosize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nLarge preclipped packing (MSb): "); - cliptestB(testbuffer2, test2size, 0, threeB, threesize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\n32 bit preclipped packing (MSb): "); - oggpackB_reset(&o); - for (i = 0; i < test2size; i++) { - oggpackB_write(&o, large[i], 32); - } - buffer = oggpackB_get_buffer(&o); - bytes = oggpackB_bytes(&o); - oggpackB_readinit(&r, buffer, bytes); - for (i = 0; i < test2size; i++) { - if (oggpackB_look(&r, 32) == -1) { - report("out of data. failed!"); - } - if (oggpackB_look(&r, 32) != large[i]) { - fprintf(stderr, "%ld != %lu (%lx!=%lx):", oggpackB_look(&r, 32), large[i], - oggpackB_look(&r, 32), large[i]); - report("read incorrect value!\n"); - } - oggpackB_adv(&r, 32); - } - if (oggpackB_bytes(&r) != bytes) { - report("leftover bytes after read!\n"); - } - fprintf(stderr, "ok."); - - fprintf(stderr, "\nSmall unclipped packing (MSb): "); - cliptestB(testbuffer1, test1size, 7, fourB, foursize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nLarge unclipped packing (MSb): "); - cliptestB(testbuffer2, test2size, 17, fiveB, fivesize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nSingle bit unclipped packing (MSb): "); - cliptestB(testbuffer3, test3size, 1, sixB, sixsize); - fprintf(stderr, "ok."); - - fprintf(stderr, "\nTesting read past end (MSb): "); - oggpackB_readinit(&r, (unsigned char *)"\0\0\0\0\0\0\0\0", 8); - for (i = 0; i < 64; i++) { - if (oggpackB_read(&r, 1) != 0) { - fprintf(stderr, "failed; got -1 prematurely.\n"); - exit(1); - } - } - if (oggpackB_look(&r, 1) != -1 || - oggpackB_read(&r, 1) != -1) { - fprintf(stderr, "failed; read past end without -1.\n"); - exit(1); - } - oggpackB_readinit(&r, (unsigned char *)"\0\0\0\0\0\0\0\0", 8); - if (oggpackB_read(&r, 30) != 0 || oggpackB_read(&r, 16) != 0) { - fprintf(stderr, "failed 2; got -1 prematurely.\n"); - exit(1); - } - - if (oggpackB_look(&r, 18) != 0 || - oggpackB_look(&r, 18) != 0) { - fprintf(stderr, "failed 3; got -1 prematurely.\n"); - exit(1); - } - if (oggpackB_look(&r, 19) != -1 || - oggpackB_look(&r, 19) != -1) { - fprintf(stderr, "failed; read past end without -1.\n"); - exit(1); - } - if (oggpackB_look(&r, 32) != -1 || - oggpackB_look(&r, 32) != -1) { - fprintf(stderr, "failed; read past end without -1.\n"); - exit(1); - } - fprintf(stderr, "ok."); - oggpackB_writeclear(&o); - - /* this is partly glassbox; we're mostly concerned about the allocation boundaries */ - - fprintf(stderr, "\nTesting aligned writecopies (MSb): "); - for (i = 0; i < 71; i++) - for (j = 0; j < 5; j++) { - copytestB(j * 8, i); - } - for (i = BUFFER_INCREMENT * 8 - 71; i < BUFFER_INCREMENT * 8 + 71; i++) - for (j = 0; j < 5; j++) { - copytestB(j * 8, i); - } - fprintf(stderr, "ok. "); - - fprintf(stderr, "\nTesting unaligned writecopies (MSb): "); - for (i = 0; i < 71; i++) - for (j = 1; j < 40; j++) - if (j & 0x7) { - copytestB(j, i); - } - for (i = BUFFER_INCREMENT * 8 - 71; i < BUFFER_INCREMENT * 8 + 71; i++) - for (j = 1; j < 40; j++) - if (j & 0x7) { - copytestB(j, i); - } - - fprintf(stderr, "ok. \n\n"); - - return (0); -} -#endif /* _V_SELFTEST */ - -#undef BUFFER_INCREMENT diff --git a/src/libogg/config.h b/src/libogg/config.h deleted file mode 100644 index 7c71893..0000000 --- a/src/libogg/config.h +++ /dev/null @@ -1,104 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Do not build with CRC */ -/* #undef DISABLE_CRC */ - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 0 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 0 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 0 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 0 - -/* Define to the sub-directory where libtool stores uninstalled libraries. */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "libogg" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "ogg-dev@xiph.org" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "libogg" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "libogg 1.3.4" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "libogg" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "1.3.4" - -/* The size of `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of `int16_t', as computed by sizeof. */ -#define SIZEOF_INT16_T 2 - -/* The size of `int32_t', as computed by sizeof. */ -#define SIZEOF_INT32_T 4 - -/* The size of `int64_t', as computed by sizeof. */ -#define SIZEOF_INT64_T 8 - -/* The size of `long', as computed by sizeof. */ -#define SIZEOF_LONG 4 - -/* The size of `long long', as computed by sizeof. */ -#define SIZEOF_LONG_LONG 8 - -/* The size of `short', as computed by sizeof. */ -#define SIZEOF_SHORT 2 - -/* The size of `uint16_t', as computed by sizeof. */ -#define SIZEOF_UINT16_T 2 - -/* The size of `uint32_t', as computed by sizeof. */ -#define SIZEOF_UINT32_T 4 - -/* The size of `uint64_t', as computed by sizeof. */ -#define SIZEOF_UINT64_T 8 - -/* The size of `u_int16_t', as computed by sizeof. */ -#define SIZEOF_U_INT16_T 2 - -/* The size of `u_int32_t', as computed by sizeof. */ -#define SIZEOF_U_INT32_T 4 - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "1.3.4" - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ diff --git a/src/libogg/crctable.h b/src/libogg/crctable.h deleted file mode 100644 index c924114..0000000 --- a/src/libogg/crctable.h +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE Ogg CONTAINER SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2018 - by the Xiph.Org Foundation http://www.xiph.org/ - * * - ********************************************************************/ - -#include "ogg/os_types.h" -#include - -static const ogg_uint32_t crc_lookup[8][256] PROGMEM = { - { - 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, - 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, - 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, - 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, - 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, - 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, - 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, - 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, - 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, - 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, - 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, - 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, - 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, - 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, - 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, - 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, - 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, - 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, - 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, - 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, - 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, - 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, - 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, - 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, - 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 - }, - - { - 0x00000000, 0xd219c1dc, 0xa0f29e0f, 0x72eb5fd3, 0x452421a9, 0x973de075, 0xe5d6bfa6, 0x37cf7e7a, - 0x8a484352, 0x5851828e, 0x2abadd5d, 0xf8a31c81, 0xcf6c62fb, 0x1d75a327, 0x6f9efcf4, 0xbd873d28, - 0x10519b13, 0xc2485acf, 0xb0a3051c, 0x62bac4c0, 0x5575baba, 0x876c7b66, 0xf58724b5, 0x279ee569, - 0x9a19d841, 0x4800199d, 0x3aeb464e, 0xe8f28792, 0xdf3df9e8, 0x0d243834, 0x7fcf67e7, 0xadd6a63b, - 0x20a33626, 0xf2baf7fa, 0x8051a829, 0x524869f5, 0x6587178f, 0xb79ed653, 0xc5758980, 0x176c485c, - 0xaaeb7574, 0x78f2b4a8, 0x0a19eb7b, 0xd8002aa7, 0xefcf54dd, 0x3dd69501, 0x4f3dcad2, 0x9d240b0e, - 0x30f2ad35, 0xe2eb6ce9, 0x9000333a, 0x4219f2e6, 0x75d68c9c, 0xa7cf4d40, 0xd5241293, 0x073dd34f, - 0xbabaee67, 0x68a32fbb, 0x1a487068, 0xc851b1b4, 0xff9ecfce, 0x2d870e12, 0x5f6c51c1, 0x8d75901d, - 0x41466c4c, 0x935fad90, 0xe1b4f243, 0x33ad339f, 0x04624de5, 0xd67b8c39, 0xa490d3ea, 0x76891236, - 0xcb0e2f1e, 0x1917eec2, 0x6bfcb111, 0xb9e570cd, 0x8e2a0eb7, 0x5c33cf6b, 0x2ed890b8, 0xfcc15164, - 0x5117f75f, 0x830e3683, 0xf1e56950, 0x23fca88c, 0x1433d6f6, 0xc62a172a, 0xb4c148f9, 0x66d88925, - 0xdb5fb40d, 0x094675d1, 0x7bad2a02, 0xa9b4ebde, 0x9e7b95a4, 0x4c625478, 0x3e890bab, 0xec90ca77, - 0x61e55a6a, 0xb3fc9bb6, 0xc117c465, 0x130e05b9, 0x24c17bc3, 0xf6d8ba1f, 0x8433e5cc, 0x562a2410, - 0xebad1938, 0x39b4d8e4, 0x4b5f8737, 0x994646eb, 0xae893891, 0x7c90f94d, 0x0e7ba69e, 0xdc626742, - 0x71b4c179, 0xa3ad00a5, 0xd1465f76, 0x035f9eaa, 0x3490e0d0, 0xe689210c, 0x94627edf, 0x467bbf03, - 0xfbfc822b, 0x29e543f7, 0x5b0e1c24, 0x8917ddf8, 0xbed8a382, 0x6cc1625e, 0x1e2a3d8d, 0xcc33fc51, - 0x828cd898, 0x50951944, 0x227e4697, 0xf067874b, 0xc7a8f931, 0x15b138ed, 0x675a673e, 0xb543a6e2, - 0x08c49bca, 0xdadd5a16, 0xa83605c5, 0x7a2fc419, 0x4de0ba63, 0x9ff97bbf, 0xed12246c, 0x3f0be5b0, - 0x92dd438b, 0x40c48257, 0x322fdd84, 0xe0361c58, 0xd7f96222, 0x05e0a3fe, 0x770bfc2d, 0xa5123df1, - 0x189500d9, 0xca8cc105, 0xb8679ed6, 0x6a7e5f0a, 0x5db12170, 0x8fa8e0ac, 0xfd43bf7f, 0x2f5a7ea3, - 0xa22feebe, 0x70362f62, 0x02dd70b1, 0xd0c4b16d, 0xe70bcf17, 0x35120ecb, 0x47f95118, 0x95e090c4, - 0x2867adec, 0xfa7e6c30, 0x889533e3, 0x5a8cf23f, 0x6d438c45, 0xbf5a4d99, 0xcdb1124a, 0x1fa8d396, - 0xb27e75ad, 0x6067b471, 0x128ceba2, 0xc0952a7e, 0xf75a5404, 0x254395d8, 0x57a8ca0b, 0x85b10bd7, - 0x383636ff, 0xea2ff723, 0x98c4a8f0, 0x4add692c, 0x7d121756, 0xaf0bd68a, 0xdde08959, 0x0ff94885, - 0xc3cab4d4, 0x11d37508, 0x63382adb, 0xb121eb07, 0x86ee957d, 0x54f754a1, 0x261c0b72, 0xf405caae, - 0x4982f786, 0x9b9b365a, 0xe9706989, 0x3b69a855, 0x0ca6d62f, 0xdebf17f3, 0xac544820, 0x7e4d89fc, - 0xd39b2fc7, 0x0182ee1b, 0x7369b1c8, 0xa1707014, 0x96bf0e6e, 0x44a6cfb2, 0x364d9061, 0xe45451bd, - 0x59d36c95, 0x8bcaad49, 0xf921f29a, 0x2b383346, 0x1cf74d3c, 0xceee8ce0, 0xbc05d333, 0x6e1c12ef, - 0xe36982f2, 0x3170432e, 0x439b1cfd, 0x9182dd21, 0xa64da35b, 0x74546287, 0x06bf3d54, 0xd4a6fc88, - 0x6921c1a0, 0xbb38007c, 0xc9d35faf, 0x1bca9e73, 0x2c05e009, 0xfe1c21d5, 0x8cf77e06, 0x5eeebfda, - 0xf33819e1, 0x2121d83d, 0x53ca87ee, 0x81d34632, 0xb61c3848, 0x6405f994, 0x16eea647, 0xc4f7679b, - 0x79705ab3, 0xab699b6f, 0xd982c4bc, 0x0b9b0560, 0x3c547b1a, 0xee4dbac6, 0x9ca6e515, 0x4ebf24c9 - }, - - { - 0x00000000, 0x01d8ac87, 0x03b1590e, 0x0269f589, 0x0762b21c, 0x06ba1e9b, 0x04d3eb12, 0x050b4795, - 0x0ec56438, 0x0f1dc8bf, 0x0d743d36, 0x0cac91b1, 0x09a7d624, 0x087f7aa3, 0x0a168f2a, 0x0bce23ad, - 0x1d8ac870, 0x1c5264f7, 0x1e3b917e, 0x1fe33df9, 0x1ae87a6c, 0x1b30d6eb, 0x19592362, 0x18818fe5, - 0x134fac48, 0x129700cf, 0x10fef546, 0x112659c1, 0x142d1e54, 0x15f5b2d3, 0x179c475a, 0x1644ebdd, - 0x3b1590e0, 0x3acd3c67, 0x38a4c9ee, 0x397c6569, 0x3c7722fc, 0x3daf8e7b, 0x3fc67bf2, 0x3e1ed775, - 0x35d0f4d8, 0x3408585f, 0x3661add6, 0x37b90151, 0x32b246c4, 0x336aea43, 0x31031fca, 0x30dbb34d, - 0x269f5890, 0x2747f417, 0x252e019e, 0x24f6ad19, 0x21fdea8c, 0x2025460b, 0x224cb382, 0x23941f05, - 0x285a3ca8, 0x2982902f, 0x2beb65a6, 0x2a33c921, 0x2f388eb4, 0x2ee02233, 0x2c89d7ba, 0x2d517b3d, - 0x762b21c0, 0x77f38d47, 0x759a78ce, 0x7442d449, 0x714993dc, 0x70913f5b, 0x72f8cad2, 0x73206655, - 0x78ee45f8, 0x7936e97f, 0x7b5f1cf6, 0x7a87b071, 0x7f8cf7e4, 0x7e545b63, 0x7c3daeea, 0x7de5026d, - 0x6ba1e9b0, 0x6a794537, 0x6810b0be, 0x69c81c39, 0x6cc35bac, 0x6d1bf72b, 0x6f7202a2, 0x6eaaae25, - 0x65648d88, 0x64bc210f, 0x66d5d486, 0x670d7801, 0x62063f94, 0x63de9313, 0x61b7669a, 0x606fca1d, - 0x4d3eb120, 0x4ce61da7, 0x4e8fe82e, 0x4f5744a9, 0x4a5c033c, 0x4b84afbb, 0x49ed5a32, 0x4835f6b5, - 0x43fbd518, 0x4223799f, 0x404a8c16, 0x41922091, 0x44996704, 0x4541cb83, 0x47283e0a, 0x46f0928d, - 0x50b47950, 0x516cd5d7, 0x5305205e, 0x52dd8cd9, 0x57d6cb4c, 0x560e67cb, 0x54679242, 0x55bf3ec5, - 0x5e711d68, 0x5fa9b1ef, 0x5dc04466, 0x5c18e8e1, 0x5913af74, 0x58cb03f3, 0x5aa2f67a, 0x5b7a5afd, - 0xec564380, 0xed8eef07, 0xefe71a8e, 0xee3fb609, 0xeb34f19c, 0xeaec5d1b, 0xe885a892, 0xe95d0415, - 0xe29327b8, 0xe34b8b3f, 0xe1227eb6, 0xe0fad231, 0xe5f195a4, 0xe4293923, 0xe640ccaa, 0xe798602d, - 0xf1dc8bf0, 0xf0042777, 0xf26dd2fe, 0xf3b57e79, 0xf6be39ec, 0xf766956b, 0xf50f60e2, 0xf4d7cc65, - 0xff19efc8, 0xfec1434f, 0xfca8b6c6, 0xfd701a41, 0xf87b5dd4, 0xf9a3f153, 0xfbca04da, 0xfa12a85d, - 0xd743d360, 0xd69b7fe7, 0xd4f28a6e, 0xd52a26e9, 0xd021617c, 0xd1f9cdfb, 0xd3903872, 0xd24894f5, - 0xd986b758, 0xd85e1bdf, 0xda37ee56, 0xdbef42d1, 0xdee40544, 0xdf3ca9c3, 0xdd555c4a, 0xdc8df0cd, - 0xcac91b10, 0xcb11b797, 0xc978421e, 0xc8a0ee99, 0xcdaba90c, 0xcc73058b, 0xce1af002, 0xcfc25c85, - 0xc40c7f28, 0xc5d4d3af, 0xc7bd2626, 0xc6658aa1, 0xc36ecd34, 0xc2b661b3, 0xc0df943a, 0xc10738bd, - 0x9a7d6240, 0x9ba5cec7, 0x99cc3b4e, 0x981497c9, 0x9d1fd05c, 0x9cc77cdb, 0x9eae8952, 0x9f7625d5, - 0x94b80678, 0x9560aaff, 0x97095f76, 0x96d1f3f1, 0x93dab464, 0x920218e3, 0x906bed6a, 0x91b341ed, - 0x87f7aa30, 0x862f06b7, 0x8446f33e, 0x859e5fb9, 0x8095182c, 0x814db4ab, 0x83244122, 0x82fceda5, - 0x8932ce08, 0x88ea628f, 0x8a839706, 0x8b5b3b81, 0x8e507c14, 0x8f88d093, 0x8de1251a, 0x8c39899d, - 0xa168f2a0, 0xa0b05e27, 0xa2d9abae, 0xa3010729, 0xa60a40bc, 0xa7d2ec3b, 0xa5bb19b2, 0xa463b535, - 0xafad9698, 0xae753a1f, 0xac1ccf96, 0xadc46311, 0xa8cf2484, 0xa9178803, 0xab7e7d8a, 0xaaa6d10d, - 0xbce23ad0, 0xbd3a9657, 0xbf5363de, 0xbe8bcf59, 0xbb8088cc, 0xba58244b, 0xb831d1c2, 0xb9e97d45, - 0xb2275ee8, 0xb3fff26f, 0xb19607e6, 0xb04eab61, 0xb545ecf4, 0xb49d4073, 0xb6f4b5fa, 0xb72c197d - }, - - { - 0x00000000, 0xdc6d9ab7, 0xbc1a28d9, 0x6077b26e, 0x7cf54c05, 0xa098d6b2, 0xc0ef64dc, 0x1c82fe6b, - 0xf9ea980a, 0x258702bd, 0x45f0b0d3, 0x999d2a64, 0x851fd40f, 0x59724eb8, 0x3905fcd6, 0xe5686661, - 0xf7142da3, 0x2b79b714, 0x4b0e057a, 0x97639fcd, 0x8be161a6, 0x578cfb11, 0x37fb497f, 0xeb96d3c8, - 0x0efeb5a9, 0xd2932f1e, 0xb2e49d70, 0x6e8907c7, 0x720bf9ac, 0xae66631b, 0xce11d175, 0x127c4bc2, - 0xeae946f1, 0x3684dc46, 0x56f36e28, 0x8a9ef49f, 0x961c0af4, 0x4a719043, 0x2a06222d, 0xf66bb89a, - 0x1303defb, 0xcf6e444c, 0xaf19f622, 0x73746c95, 0x6ff692fe, 0xb39b0849, 0xd3ecba27, 0x0f812090, - 0x1dfd6b52, 0xc190f1e5, 0xa1e7438b, 0x7d8ad93c, 0x61082757, 0xbd65bde0, 0xdd120f8e, 0x017f9539, - 0xe417f358, 0x387a69ef, 0x580ddb81, 0x84604136, 0x98e2bf5d, 0x448f25ea, 0x24f89784, 0xf8950d33, - 0xd1139055, 0x0d7e0ae2, 0x6d09b88c, 0xb164223b, 0xade6dc50, 0x718b46e7, 0x11fcf489, 0xcd916e3e, - 0x28f9085f, 0xf49492e8, 0x94e32086, 0x488eba31, 0x540c445a, 0x8861deed, 0xe8166c83, 0x347bf634, - 0x2607bdf6, 0xfa6a2741, 0x9a1d952f, 0x46700f98, 0x5af2f1f3, 0x869f6b44, 0xe6e8d92a, 0x3a85439d, - 0xdfed25fc, 0x0380bf4b, 0x63f70d25, 0xbf9a9792, 0xa31869f9, 0x7f75f34e, 0x1f024120, 0xc36fdb97, - 0x3bfad6a4, 0xe7974c13, 0x87e0fe7d, 0x5b8d64ca, 0x470f9aa1, 0x9b620016, 0xfb15b278, 0x277828cf, - 0xc2104eae, 0x1e7dd419, 0x7e0a6677, 0xa267fcc0, 0xbee502ab, 0x6288981c, 0x02ff2a72, 0xde92b0c5, - 0xcceefb07, 0x108361b0, 0x70f4d3de, 0xac994969, 0xb01bb702, 0x6c762db5, 0x0c019fdb, 0xd06c056c, - 0x3504630d, 0xe969f9ba, 0x891e4bd4, 0x5573d163, 0x49f12f08, 0x959cb5bf, 0xf5eb07d1, 0x29869d66, - 0xa6e63d1d, 0x7a8ba7aa, 0x1afc15c4, 0xc6918f73, 0xda137118, 0x067eebaf, 0x660959c1, 0xba64c376, - 0x5f0ca517, 0x83613fa0, 0xe3168dce, 0x3f7b1779, 0x23f9e912, 0xff9473a5, 0x9fe3c1cb, 0x438e5b7c, - 0x51f210be, 0x8d9f8a09, 0xede83867, 0x3185a2d0, 0x2d075cbb, 0xf16ac60c, 0x911d7462, 0x4d70eed5, - 0xa81888b4, 0x74751203, 0x1402a06d, 0xc86f3ada, 0xd4edc4b1, 0x08805e06, 0x68f7ec68, 0xb49a76df, - 0x4c0f7bec, 0x9062e15b, 0xf0155335, 0x2c78c982, 0x30fa37e9, 0xec97ad5e, 0x8ce01f30, 0x508d8587, - 0xb5e5e3e6, 0x69887951, 0x09ffcb3f, 0xd5925188, 0xc910afe3, 0x157d3554, 0x750a873a, 0xa9671d8d, - 0xbb1b564f, 0x6776ccf8, 0x07017e96, 0xdb6ce421, 0xc7ee1a4a, 0x1b8380fd, 0x7bf43293, 0xa799a824, - 0x42f1ce45, 0x9e9c54f2, 0xfeebe69c, 0x22867c2b, 0x3e048240, 0xe26918f7, 0x821eaa99, 0x5e73302e, - 0x77f5ad48, 0xab9837ff, 0xcbef8591, 0x17821f26, 0x0b00e14d, 0xd76d7bfa, 0xb71ac994, 0x6b775323, - 0x8e1f3542, 0x5272aff5, 0x32051d9b, 0xee68872c, 0xf2ea7947, 0x2e87e3f0, 0x4ef0519e, 0x929dcb29, - 0x80e180eb, 0x5c8c1a5c, 0x3cfba832, 0xe0963285, 0xfc14ccee, 0x20795659, 0x400ee437, 0x9c637e80, - 0x790b18e1, 0xa5668256, 0xc5113038, 0x197caa8f, 0x05fe54e4, 0xd993ce53, 0xb9e47c3d, 0x6589e68a, - 0x9d1cebb9, 0x4171710e, 0x2106c360, 0xfd6b59d7, 0xe1e9a7bc, 0x3d843d0b, 0x5df38f65, 0x819e15d2, - 0x64f673b3, 0xb89be904, 0xd8ec5b6a, 0x0481c1dd, 0x18033fb6, 0xc46ea501, 0xa419176f, 0x78748dd8, - 0x6a08c61a, 0xb6655cad, 0xd612eec3, 0x0a7f7474, 0x16fd8a1f, 0xca9010a8, 0xaae7a2c6, 0x768a3871, - 0x93e25e10, 0x4f8fc4a7, 0x2ff876c9, 0xf395ec7e, 0xef171215, 0x337a88a2, 0x530d3acc, 0x8f60a07b - }, - - { - 0x00000000, 0x490d678d, 0x921acf1a, 0xdb17a897, 0x20f48383, 0x69f9e40e, 0xb2ee4c99, 0xfbe32b14, - 0x41e90706, 0x08e4608b, 0xd3f3c81c, 0x9afeaf91, 0x611d8485, 0x2810e308, 0xf3074b9f, 0xba0a2c12, - 0x83d20e0c, 0xcadf6981, 0x11c8c116, 0x58c5a69b, 0xa3268d8f, 0xea2bea02, 0x313c4295, 0x78312518, - 0xc23b090a, 0x8b366e87, 0x5021c610, 0x192ca19d, 0xe2cf8a89, 0xabc2ed04, 0x70d54593, 0x39d8221e, - 0x036501af, 0x4a686622, 0x917fceb5, 0xd872a938, 0x2391822c, 0x6a9ce5a1, 0xb18b4d36, 0xf8862abb, - 0x428c06a9, 0x0b816124, 0xd096c9b3, 0x999bae3e, 0x6278852a, 0x2b75e2a7, 0xf0624a30, 0xb96f2dbd, - 0x80b70fa3, 0xc9ba682e, 0x12adc0b9, 0x5ba0a734, 0xa0438c20, 0xe94eebad, 0x3259433a, 0x7b5424b7, - 0xc15e08a5, 0x88536f28, 0x5344c7bf, 0x1a49a032, 0xe1aa8b26, 0xa8a7ecab, 0x73b0443c, 0x3abd23b1, - 0x06ca035e, 0x4fc764d3, 0x94d0cc44, 0xddddabc9, 0x263e80dd, 0x6f33e750, 0xb4244fc7, 0xfd29284a, - 0x47230458, 0x0e2e63d5, 0xd539cb42, 0x9c34accf, 0x67d787db, 0x2edae056, 0xf5cd48c1, 0xbcc02f4c, - 0x85180d52, 0xcc156adf, 0x1702c248, 0x5e0fa5c5, 0xa5ec8ed1, 0xece1e95c, 0x37f641cb, 0x7efb2646, - 0xc4f10a54, 0x8dfc6dd9, 0x56ebc54e, 0x1fe6a2c3, 0xe40589d7, 0xad08ee5a, 0x761f46cd, 0x3f122140, - 0x05af02f1, 0x4ca2657c, 0x97b5cdeb, 0xdeb8aa66, 0x255b8172, 0x6c56e6ff, 0xb7414e68, 0xfe4c29e5, - 0x444605f7, 0x0d4b627a, 0xd65ccaed, 0x9f51ad60, 0x64b28674, 0x2dbfe1f9, 0xf6a8496e, 0xbfa52ee3, - 0x867d0cfd, 0xcf706b70, 0x1467c3e7, 0x5d6aa46a, 0xa6898f7e, 0xef84e8f3, 0x34934064, 0x7d9e27e9, - 0xc7940bfb, 0x8e996c76, 0x558ec4e1, 0x1c83a36c, 0xe7608878, 0xae6deff5, 0x757a4762, 0x3c7720ef, - 0x0d9406bc, 0x44996131, 0x9f8ec9a6, 0xd683ae2b, 0x2d60853f, 0x646de2b2, 0xbf7a4a25, 0xf6772da8, - 0x4c7d01ba, 0x05706637, 0xde67cea0, 0x976aa92d, 0x6c898239, 0x2584e5b4, 0xfe934d23, 0xb79e2aae, - 0x8e4608b0, 0xc74b6f3d, 0x1c5cc7aa, 0x5551a027, 0xaeb28b33, 0xe7bfecbe, 0x3ca84429, 0x75a523a4, - 0xcfaf0fb6, 0x86a2683b, 0x5db5c0ac, 0x14b8a721, 0xef5b8c35, 0xa656ebb8, 0x7d41432f, 0x344c24a2, - 0x0ef10713, 0x47fc609e, 0x9cebc809, 0xd5e6af84, 0x2e058490, 0x6708e31d, 0xbc1f4b8a, 0xf5122c07, - 0x4f180015, 0x06156798, 0xdd02cf0f, 0x940fa882, 0x6fec8396, 0x26e1e41b, 0xfdf64c8c, 0xb4fb2b01, - 0x8d23091f, 0xc42e6e92, 0x1f39c605, 0x5634a188, 0xadd78a9c, 0xe4daed11, 0x3fcd4586, 0x76c0220b, - 0xccca0e19, 0x85c76994, 0x5ed0c103, 0x17dda68e, 0xec3e8d9a, 0xa533ea17, 0x7e244280, 0x3729250d, - 0x0b5e05e2, 0x4253626f, 0x9944caf8, 0xd049ad75, 0x2baa8661, 0x62a7e1ec, 0xb9b0497b, 0xf0bd2ef6, - 0x4ab702e4, 0x03ba6569, 0xd8adcdfe, 0x91a0aa73, 0x6a438167, 0x234ee6ea, 0xf8594e7d, 0xb15429f0, - 0x888c0bee, 0xc1816c63, 0x1a96c4f4, 0x539ba379, 0xa878886d, 0xe175efe0, 0x3a624777, 0x736f20fa, - 0xc9650ce8, 0x80686b65, 0x5b7fc3f2, 0x1272a47f, 0xe9918f6b, 0xa09ce8e6, 0x7b8b4071, 0x328627fc, - 0x083b044d, 0x413663c0, 0x9a21cb57, 0xd32cacda, 0x28cf87ce, 0x61c2e043, 0xbad548d4, 0xf3d82f59, - 0x49d2034b, 0x00df64c6, 0xdbc8cc51, 0x92c5abdc, 0x692680c8, 0x202be745, 0xfb3c4fd2, 0xb231285f, - 0x8be90a41, 0xc2e46dcc, 0x19f3c55b, 0x50fea2d6, 0xab1d89c2, 0xe210ee4f, 0x390746d8, 0x700a2155, - 0xca000d47, 0x830d6aca, 0x581ac25d, 0x1117a5d0, 0xeaf48ec4, 0xa3f9e949, 0x78ee41de, 0x31e32653 - }, - - { - 0x00000000, 0x1b280d78, 0x36501af0, 0x2d781788, 0x6ca035e0, 0x77883898, 0x5af02f10, 0x41d82268, - 0xd9406bc0, 0xc26866b8, 0xef107130, 0xf4387c48, 0xb5e05e20, 0xaec85358, 0x83b044d0, 0x989849a8, - 0xb641ca37, 0xad69c74f, 0x8011d0c7, 0x9b39ddbf, 0xdae1ffd7, 0xc1c9f2af, 0xecb1e527, 0xf799e85f, - 0x6f01a1f7, 0x7429ac8f, 0x5951bb07, 0x4279b67f, 0x03a19417, 0x1889996f, 0x35f18ee7, 0x2ed9839f, - 0x684289d9, 0x736a84a1, 0x5e129329, 0x453a9e51, 0x04e2bc39, 0x1fcab141, 0x32b2a6c9, 0x299aabb1, - 0xb102e219, 0xaa2aef61, 0x8752f8e9, 0x9c7af591, 0xdda2d7f9, 0xc68ada81, 0xebf2cd09, 0xf0dac071, - 0xde0343ee, 0xc52b4e96, 0xe853591e, 0xf37b5466, 0xb2a3760e, 0xa98b7b76, 0x84f36cfe, 0x9fdb6186, - 0x0743282e, 0x1c6b2556, 0x311332de, 0x2a3b3fa6, 0x6be31dce, 0x70cb10b6, 0x5db3073e, 0x469b0a46, - 0xd08513b2, 0xcbad1eca, 0xe6d50942, 0xfdfd043a, 0xbc252652, 0xa70d2b2a, 0x8a753ca2, 0x915d31da, - 0x09c57872, 0x12ed750a, 0x3f956282, 0x24bd6ffa, 0x65654d92, 0x7e4d40ea, 0x53355762, 0x481d5a1a, - 0x66c4d985, 0x7decd4fd, 0x5094c375, 0x4bbcce0d, 0x0a64ec65, 0x114ce11d, 0x3c34f695, 0x271cfbed, - 0xbf84b245, 0xa4acbf3d, 0x89d4a8b5, 0x92fca5cd, 0xd32487a5, 0xc80c8add, 0xe5749d55, 0xfe5c902d, - 0xb8c79a6b, 0xa3ef9713, 0x8e97809b, 0x95bf8de3, 0xd467af8b, 0xcf4fa2f3, 0xe237b57b, 0xf91fb803, - 0x6187f1ab, 0x7aaffcd3, 0x57d7eb5b, 0x4cffe623, 0x0d27c44b, 0x160fc933, 0x3b77debb, 0x205fd3c3, - 0x0e86505c, 0x15ae5d24, 0x38d64aac, 0x23fe47d4, 0x622665bc, 0x790e68c4, 0x54767f4c, 0x4f5e7234, - 0xd7c63b9c, 0xccee36e4, 0xe196216c, 0xfabe2c14, 0xbb660e7c, 0xa04e0304, 0x8d36148c, 0x961e19f4, - 0xa5cb3ad3, 0xbee337ab, 0x939b2023, 0x88b32d5b, 0xc96b0f33, 0xd243024b, 0xff3b15c3, 0xe41318bb, - 0x7c8b5113, 0x67a35c6b, 0x4adb4be3, 0x51f3469b, 0x102b64f3, 0x0b03698b, 0x267b7e03, 0x3d53737b, - 0x138af0e4, 0x08a2fd9c, 0x25daea14, 0x3ef2e76c, 0x7f2ac504, 0x6402c87c, 0x497adff4, 0x5252d28c, - 0xcaca9b24, 0xd1e2965c, 0xfc9a81d4, 0xe7b28cac, 0xa66aaec4, 0xbd42a3bc, 0x903ab434, 0x8b12b94c, - 0xcd89b30a, 0xd6a1be72, 0xfbd9a9fa, 0xe0f1a482, 0xa12986ea, 0xba018b92, 0x97799c1a, 0x8c519162, - 0x14c9d8ca, 0x0fe1d5b2, 0x2299c23a, 0x39b1cf42, 0x7869ed2a, 0x6341e052, 0x4e39f7da, 0x5511faa2, - 0x7bc8793d, 0x60e07445, 0x4d9863cd, 0x56b06eb5, 0x17684cdd, 0x0c4041a5, 0x2138562d, 0x3a105b55, - 0xa28812fd, 0xb9a01f85, 0x94d8080d, 0x8ff00575, 0xce28271d, 0xd5002a65, 0xf8783ded, 0xe3503095, - 0x754e2961, 0x6e662419, 0x431e3391, 0x58363ee9, 0x19ee1c81, 0x02c611f9, 0x2fbe0671, 0x34960b09, - 0xac0e42a1, 0xb7264fd9, 0x9a5e5851, 0x81765529, 0xc0ae7741, 0xdb867a39, 0xf6fe6db1, 0xedd660c9, - 0xc30fe356, 0xd827ee2e, 0xf55ff9a6, 0xee77f4de, 0xafafd6b6, 0xb487dbce, 0x99ffcc46, 0x82d7c13e, - 0x1a4f8896, 0x016785ee, 0x2c1f9266, 0x37379f1e, 0x76efbd76, 0x6dc7b00e, 0x40bfa786, 0x5b97aafe, - 0x1d0ca0b8, 0x0624adc0, 0x2b5cba48, 0x3074b730, 0x71ac9558, 0x6a849820, 0x47fc8fa8, 0x5cd482d0, - 0xc44ccb78, 0xdf64c600, 0xf21cd188, 0xe934dcf0, 0xa8ecfe98, 0xb3c4f3e0, 0x9ebce468, 0x8594e910, - 0xab4d6a8f, 0xb06567f7, 0x9d1d707f, 0x86357d07, 0xc7ed5f6f, 0xdcc55217, 0xf1bd459f, 0xea9548e7, - 0x720d014f, 0x69250c37, 0x445d1bbf, 0x5f7516c7, 0x1ead34af, 0x058539d7, 0x28fd2e5f, 0x33d52327 - }, - - { - 0x00000000, 0x4f576811, 0x9eaed022, 0xd1f9b833, 0x399cbdf3, 0x76cbd5e2, 0xa7326dd1, 0xe86505c0, - 0x73397be6, 0x3c6e13f7, 0xed97abc4, 0xa2c0c3d5, 0x4aa5c615, 0x05f2ae04, 0xd40b1637, 0x9b5c7e26, - 0xe672f7cc, 0xa9259fdd, 0x78dc27ee, 0x378b4fff, 0xdfee4a3f, 0x90b9222e, 0x41409a1d, 0x0e17f20c, - 0x954b8c2a, 0xda1ce43b, 0x0be55c08, 0x44b23419, 0xacd731d9, 0xe38059c8, 0x3279e1fb, 0x7d2e89ea, - 0xc824f22f, 0x87739a3e, 0x568a220d, 0x19dd4a1c, 0xf1b84fdc, 0xbeef27cd, 0x6f169ffe, 0x2041f7ef, - 0xbb1d89c9, 0xf44ae1d8, 0x25b359eb, 0x6ae431fa, 0x8281343a, 0xcdd65c2b, 0x1c2fe418, 0x53788c09, - 0x2e5605e3, 0x61016df2, 0xb0f8d5c1, 0xffafbdd0, 0x17cab810, 0x589dd001, 0x89646832, 0xc6330023, - 0x5d6f7e05, 0x12381614, 0xc3c1ae27, 0x8c96c636, 0x64f3c3f6, 0x2ba4abe7, 0xfa5d13d4, 0xb50a7bc5, - 0x9488f9e9, 0xdbdf91f8, 0x0a2629cb, 0x457141da, 0xad14441a, 0xe2432c0b, 0x33ba9438, 0x7cedfc29, - 0xe7b1820f, 0xa8e6ea1e, 0x791f522d, 0x36483a3c, 0xde2d3ffc, 0x917a57ed, 0x4083efde, 0x0fd487cf, - 0x72fa0e25, 0x3dad6634, 0xec54de07, 0xa303b616, 0x4b66b3d6, 0x0431dbc7, 0xd5c863f4, 0x9a9f0be5, - 0x01c375c3, 0x4e941dd2, 0x9f6da5e1, 0xd03acdf0, 0x385fc830, 0x7708a021, 0xa6f11812, 0xe9a67003, - 0x5cac0bc6, 0x13fb63d7, 0xc202dbe4, 0x8d55b3f5, 0x6530b635, 0x2a67de24, 0xfb9e6617, 0xb4c90e06, - 0x2f957020, 0x60c21831, 0xb13ba002, 0xfe6cc813, 0x1609cdd3, 0x595ea5c2, 0x88a71df1, 0xc7f075e0, - 0xbadefc0a, 0xf589941b, 0x24702c28, 0x6b274439, 0x834241f9, 0xcc1529e8, 0x1dec91db, 0x52bbf9ca, - 0xc9e787ec, 0x86b0effd, 0x574957ce, 0x181e3fdf, 0xf07b3a1f, 0xbf2c520e, 0x6ed5ea3d, 0x2182822c, - 0x2dd0ee65, 0x62878674, 0xb37e3e47, 0xfc295656, 0x144c5396, 0x5b1b3b87, 0x8ae283b4, 0xc5b5eba5, - 0x5ee99583, 0x11befd92, 0xc04745a1, 0x8f102db0, 0x67752870, 0x28224061, 0xf9dbf852, 0xb68c9043, - 0xcba219a9, 0x84f571b8, 0x550cc98b, 0x1a5ba19a, 0xf23ea45a, 0xbd69cc4b, 0x6c907478, 0x23c71c69, - 0xb89b624f, 0xf7cc0a5e, 0x2635b26d, 0x6962da7c, 0x8107dfbc, 0xce50b7ad, 0x1fa90f9e, 0x50fe678f, - 0xe5f41c4a, 0xaaa3745b, 0x7b5acc68, 0x340da479, 0xdc68a1b9, 0x933fc9a8, 0x42c6719b, 0x0d91198a, - 0x96cd67ac, 0xd99a0fbd, 0x0863b78e, 0x4734df9f, 0xaf51da5f, 0xe006b24e, 0x31ff0a7d, 0x7ea8626c, - 0x0386eb86, 0x4cd18397, 0x9d283ba4, 0xd27f53b5, 0x3a1a5675, 0x754d3e64, 0xa4b48657, 0xebe3ee46, - 0x70bf9060, 0x3fe8f871, 0xee114042, 0xa1462853, 0x49232d93, 0x06744582, 0xd78dfdb1, 0x98da95a0, - 0xb958178c, 0xf60f7f9d, 0x27f6c7ae, 0x68a1afbf, 0x80c4aa7f, 0xcf93c26e, 0x1e6a7a5d, 0x513d124c, - 0xca616c6a, 0x8536047b, 0x54cfbc48, 0x1b98d459, 0xf3fdd199, 0xbcaab988, 0x6d5301bb, 0x220469aa, - 0x5f2ae040, 0x107d8851, 0xc1843062, 0x8ed35873, 0x66b65db3, 0x29e135a2, 0xf8188d91, 0xb74fe580, - 0x2c139ba6, 0x6344f3b7, 0xb2bd4b84, 0xfdea2395, 0x158f2655, 0x5ad84e44, 0x8b21f677, 0xc4769e66, - 0x717ce5a3, 0x3e2b8db2, 0xefd23581, 0xa0855d90, 0x48e05850, 0x07b73041, 0xd64e8872, 0x9919e063, - 0x02459e45, 0x4d12f654, 0x9ceb4e67, 0xd3bc2676, 0x3bd923b6, 0x748e4ba7, 0xa577f394, 0xea209b85, - 0x970e126f, 0xd8597a7e, 0x09a0c24d, 0x46f7aa5c, 0xae92af9c, 0xe1c5c78d, 0x303c7fbe, 0x7f6b17af, - 0xe4376989, 0xab600198, 0x7a99b9ab, 0x35ced1ba, 0xddabd47a, 0x92fcbc6b, 0x43050458, 0x0c526c49 - }, - - { - 0x00000000, 0x5ba1dcca, 0xb743b994, 0xece2655e, 0x6a466e9f, 0x31e7b255, 0xdd05d70b, 0x86a40bc1, - 0xd48cdd3e, 0x8f2d01f4, 0x63cf64aa, 0x386eb860, 0xbecab3a1, 0xe56b6f6b, 0x09890a35, 0x5228d6ff, - 0xadd8a7cb, 0xf6797b01, 0x1a9b1e5f, 0x413ac295, 0xc79ec954, 0x9c3f159e, 0x70dd70c0, 0x2b7cac0a, - 0x79547af5, 0x22f5a63f, 0xce17c361, 0x95b61fab, 0x1312146a, 0x48b3c8a0, 0xa451adfe, 0xfff07134, - 0x5f705221, 0x04d18eeb, 0xe833ebb5, 0xb392377f, 0x35363cbe, 0x6e97e074, 0x8275852a, 0xd9d459e0, - 0x8bfc8f1f, 0xd05d53d5, 0x3cbf368b, 0x671eea41, 0xe1bae180, 0xba1b3d4a, 0x56f95814, 0x0d5884de, - 0xf2a8f5ea, 0xa9092920, 0x45eb4c7e, 0x1e4a90b4, 0x98ee9b75, 0xc34f47bf, 0x2fad22e1, 0x740cfe2b, - 0x262428d4, 0x7d85f41e, 0x91679140, 0xcac64d8a, 0x4c62464b, 0x17c39a81, 0xfb21ffdf, 0xa0802315, - 0xbee0a442, 0xe5417888, 0x09a31dd6, 0x5202c11c, 0xd4a6cadd, 0x8f071617, 0x63e57349, 0x3844af83, - 0x6a6c797c, 0x31cda5b6, 0xdd2fc0e8, 0x868e1c22, 0x002a17e3, 0x5b8bcb29, 0xb769ae77, 0xecc872bd, - 0x13380389, 0x4899df43, 0xa47bba1d, 0xffda66d7, 0x797e6d16, 0x22dfb1dc, 0xce3dd482, 0x959c0848, - 0xc7b4deb7, 0x9c15027d, 0x70f76723, 0x2b56bbe9, 0xadf2b028, 0xf6536ce2, 0x1ab109bc, 0x4110d576, - 0xe190f663, 0xba312aa9, 0x56d34ff7, 0x0d72933d, 0x8bd698fc, 0xd0774436, 0x3c952168, 0x6734fda2, - 0x351c2b5d, 0x6ebdf797, 0x825f92c9, 0xd9fe4e03, 0x5f5a45c2, 0x04fb9908, 0xe819fc56, 0xb3b8209c, - 0x4c4851a8, 0x17e98d62, 0xfb0be83c, 0xa0aa34f6, 0x260e3f37, 0x7dafe3fd, 0x914d86a3, 0xcaec5a69, - 0x98c48c96, 0xc365505c, 0x2f873502, 0x7426e9c8, 0xf282e209, 0xa9233ec3, 0x45c15b9d, 0x1e608757, - 0x79005533, 0x22a189f9, 0xce43eca7, 0x95e2306d, 0x13463bac, 0x48e7e766, 0xa4058238, 0xffa45ef2, - 0xad8c880d, 0xf62d54c7, 0x1acf3199, 0x416eed53, 0xc7cae692, 0x9c6b3a58, 0x70895f06, 0x2b2883cc, - 0xd4d8f2f8, 0x8f792e32, 0x639b4b6c, 0x383a97a6, 0xbe9e9c67, 0xe53f40ad, 0x09dd25f3, 0x527cf939, - 0x00542fc6, 0x5bf5f30c, 0xb7179652, 0xecb64a98, 0x6a124159, 0x31b39d93, 0xdd51f8cd, 0x86f02407, - 0x26700712, 0x7dd1dbd8, 0x9133be86, 0xca92624c, 0x4c36698d, 0x1797b547, 0xfb75d019, 0xa0d40cd3, - 0xf2fcda2c, 0xa95d06e6, 0x45bf63b8, 0x1e1ebf72, 0x98bab4b3, 0xc31b6879, 0x2ff90d27, 0x7458d1ed, - 0x8ba8a0d9, 0xd0097c13, 0x3ceb194d, 0x674ac587, 0xe1eece46, 0xba4f128c, 0x56ad77d2, 0x0d0cab18, - 0x5f247de7, 0x0485a12d, 0xe867c473, 0xb3c618b9, 0x35621378, 0x6ec3cfb2, 0x8221aaec, 0xd9807626, - 0xc7e0f171, 0x9c412dbb, 0x70a348e5, 0x2b02942f, 0xada69fee, 0xf6074324, 0x1ae5267a, 0x4144fab0, - 0x136c2c4f, 0x48cdf085, 0xa42f95db, 0xff8e4911, 0x792a42d0, 0x228b9e1a, 0xce69fb44, 0x95c8278e, - 0x6a3856ba, 0x31998a70, 0xdd7bef2e, 0x86da33e4, 0x007e3825, 0x5bdfe4ef, 0xb73d81b1, 0xec9c5d7b, - 0xbeb48b84, 0xe515574e, 0x09f73210, 0x5256eeda, 0xd4f2e51b, 0x8f5339d1, 0x63b15c8f, 0x38108045, - 0x9890a350, 0xc3317f9a, 0x2fd31ac4, 0x7472c60e, 0xf2d6cdcf, 0xa9771105, 0x4595745b, 0x1e34a891, - 0x4c1c7e6e, 0x17bda2a4, 0xfb5fc7fa, 0xa0fe1b30, 0x265a10f1, 0x7dfbcc3b, 0x9119a965, 0xcab875af, - 0x3548049b, 0x6ee9d851, 0x820bbd0f, 0xd9aa61c5, 0x5f0e6a04, 0x04afb6ce, 0xe84dd390, 0xb3ec0f5a, - 0xe1c4d9a5, 0xba65056f, 0x56876031, 0x0d26bcfb, 0x8b82b73a, 0xd0236bf0, 0x3cc10eae, 0x6760d264 - } -}; diff --git a/src/libogg/framing.c b/src/libogg/framing.c deleted file mode 100644 index 61242b6..0000000 --- a/src/libogg/framing.c +++ /dev/null @@ -1,2330 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE Ogg CONTAINER SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2018 - by the Xiph.Org Foundation http://www.xiph.org/ - * * - ******************************************************************** - - function: code raw packets into framed OggSquish stream and - decode Ogg streams back into raw packets - - note: The CRC code is directly derived from public domain code by - Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html - for details. - - ********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include -#include -#include -#include "ogg/ogg.h" - -#include - -/* A complete description of Ogg framing exists in docs/framing.html */ - -int ogg_page_version(const ogg_page *og) { - return ((int)(og->header[4])); -} - -int ogg_page_continued(const ogg_page *og) { - return ((int)(og->header[5] & 0x01)); -} - -int ogg_page_bos(const ogg_page *og) { - return ((int)(og->header[5] & 0x02)); -} - -int ogg_page_eos(const ogg_page *og) { - return ((int)(og->header[5] & 0x04)); -} - -ogg_int64_t ogg_page_granulepos(const ogg_page *og) { - unsigned char *page = og->header; - ogg_uint64_t granulepos = page[13] & (0xff); - granulepos = (granulepos << 8) | (page[12] & 0xff); - granulepos = (granulepos << 8) | (page[11] & 0xff); - granulepos = (granulepos << 8) | (page[10] & 0xff); - granulepos = (granulepos << 8) | (page[9] & 0xff); - granulepos = (granulepos << 8) | (page[8] & 0xff); - granulepos = (granulepos << 8) | (page[7] & 0xff); - granulepos = (granulepos << 8) | (page[6] & 0xff); - return ((ogg_int64_t)granulepos); -} - -int ogg_page_serialno(const ogg_page *og) { - return ((int)((ogg_uint32_t)og->header[14]) | - ((ogg_uint32_t)og->header[15] << 8) | - ((ogg_uint32_t)og->header[16] << 16) | - ((ogg_uint32_t)og->header[17] << 24)); -} - -long ogg_page_pageno(const ogg_page *og) { - return ((long)((ogg_uint32_t)og->header[18]) | - ((ogg_uint32_t)og->header[19] << 8) | - ((ogg_uint32_t)og->header[20] << 16) | - ((ogg_uint32_t)og->header[21] << 24)); -} - - - -/* returns the number of packets that are completed on this page (if - the leading packet is begun on a previous page, but ends on this - page, it's counted */ - -/* NOTE: - If a page consists of a packet begun on a previous page, and a new - packet begun (but not completed) on this page, the return will be: - ogg_page_packets(page) ==1, - ogg_page_continued(page) !=0 - - If a page happens to be a single packet that was begun on a - previous page, and spans to the next page (in the case of a three or - more page packet), the return will be: - ogg_page_packets(page) ==0, - ogg_page_continued(page) !=0 -*/ - -int ogg_page_packets(const ogg_page *og) { - int i, n = og->header[26], count = 0; - for (i = 0; i < n; i++) - if (og->header[27 + i] < 255) { - count++; - } - return (count); -} - - -#if 0 -/* helper to initialize lookup for direct-table CRC (illustrative; we - use the static init in crctable.h) */ - -static void _ogg_crc_init() { - int i, j; - ogg_uint32_t polynomial, crc; - polynomial = 0x04c11db7; /* The same as the ethernet generator - polynomial, although we use an - unreflected alg and an init/final - of 0, not 0xffffffff */ - for (i = 0; i <= 0xFF; i++) { - crc = i << 24; - - for (j = 0; j < 8; j++) { - crc = (crc << 1) ^ (crc & (1 << 31) ? polynomial : 0); - } - - crc_lookup[0][i] = crc; - } - - for (i = 0; i <= 0xFF; i++) - for (j = 1; j < 8; j++) { - crc_lookup[j][i] = crc_lookup[0][(crc_lookup[j - 1][i] >> 24) & 0xFF] ^ (crc_lookup[j - 1][i] << 8); - } -} -#endif - -#include "crctable.h" - -/* init the encode/decode logical stream state */ - -int ogg_stream_init(ogg_stream_state *os, int serialno) { - if (os) { - memset(os, 0, sizeof(*os)); - os->body_storage = 16 * 1024; - os->lacing_storage = 1024; - - os->body_data = _ogg_malloc(os->body_storage * sizeof(*os->body_data)); - os->lacing_vals = _ogg_malloc(os->lacing_storage * sizeof(*os->lacing_vals)); - os->granule_vals = _ogg_malloc(os->lacing_storage * sizeof(*os->granule_vals)); - - if (!os->body_data || !os->lacing_vals || !os->granule_vals) { - ogg_stream_clear(os); - return -1; - } - - os->serialno = serialno; - - return (0); - } - return (-1); -} - -/* async/delayed error detection for the ogg_stream_state */ -int ogg_stream_check(ogg_stream_state *os) { - if (!os || !os->body_data) { - return -1; - } - return 0; -} - -/* _clear does not free os, only the non-flat storage within */ -int ogg_stream_clear(ogg_stream_state *os) { - if (os) { - if (os->body_data) { - _ogg_free(os->body_data); - } - if (os->lacing_vals) { - _ogg_free(os->lacing_vals); - } - if (os->granule_vals) { - _ogg_free(os->granule_vals); - } - - memset(os, 0, sizeof(*os)); - } - return (0); -} - -int ogg_stream_destroy(ogg_stream_state *os) { - if (os) { - ogg_stream_clear(os); - _ogg_free(os); - } - return (0); -} - -/* Helpers for ogg_stream_encode; this keeps the structure and - what's happening fairly clear */ - -static int _os_body_expand(ogg_stream_state *os, long needed) { - if (os->body_storage - needed <= os->body_fill) { - long body_storage; - void *ret; - if (os->body_storage > LONG_MAX - needed) { - ogg_stream_clear(os); - return -1; - } - body_storage = os->body_storage + needed; - if (body_storage < LONG_MAX - 1024) { - body_storage += 1024; - } - ret = _ogg_realloc(os->body_data, body_storage * sizeof(*os->body_data)); - if (!ret) { - ogg_stream_clear(os); - return -1; - } - os->body_storage = body_storage; - os->body_data = ret; - } - return 0; -} - -static int _os_lacing_expand(ogg_stream_state *os, long needed) { - if (os->lacing_storage - needed <= os->lacing_fill) { - long lacing_storage; - void *ret; - if (os->lacing_storage > LONG_MAX - needed) { - ogg_stream_clear(os); - return -1; - } - lacing_storage = os->lacing_storage + needed; - if (lacing_storage < LONG_MAX - 32) { - lacing_storage += 32; - } - ret = _ogg_realloc(os->lacing_vals, lacing_storage * sizeof(*os->lacing_vals)); - if (!ret) { - ogg_stream_clear(os); - return -1; - } - os->lacing_vals = ret; - ret = _ogg_realloc(os->granule_vals, lacing_storage * - sizeof(*os->granule_vals)); - if (!ret) { - ogg_stream_clear(os); - return -1; - } - os->granule_vals = ret; - os->lacing_storage = lacing_storage; - } - return 0; -} - -/* checksum the page */ -/* Direct table CRC; note that this will be faster in the future if we - perform the checksum simultaneously with other copies */ - -static ogg_uint32_t _os_update_crc(ogg_uint32_t crc, unsigned char *buffer, int size) { - while (size >= 8) { - crc ^= ((ogg_uint32_t)buffer[0] << 24) | ((ogg_uint32_t)buffer[1] << 16) | ((ogg_uint32_t)buffer[2] << 8) | ((ogg_uint32_t)buffer[3]); - - crc = crc_lookup[7][ crc >> 24 ] ^ crc_lookup[6][(crc >> 16) & 0xFF] ^ - crc_lookup[5][(crc >> 8) & 0xFF] ^ crc_lookup[4][ crc & 0xFF] ^ - crc_lookup[3][buffer[4] ] ^ crc_lookup[2][buffer[5] ] ^ - crc_lookup[1][buffer[6] ] ^ crc_lookup[0][buffer[7] ]; - - buffer += 8; - size -= 8; - } - - while (size--) { - crc = (crc << 8)^crc_lookup[0][((crc >> 24) & 0xff)^*buffer++]; - } - return crc; -} - -void ogg_page_checksum_set(ogg_page *og) { - if (og) { - ogg_uint32_t crc_reg = 0; - - /* safety; needed for API behavior, but not framing code */ - og->header[22] = 0; - og->header[23] = 0; - og->header[24] = 0; - og->header[25] = 0; - - crc_reg = _os_update_crc(crc_reg, og->header, og->header_len); - crc_reg = _os_update_crc(crc_reg, og->body, og->body_len); - - og->header[22] = (unsigned char)(crc_reg & 0xff); - og->header[23] = (unsigned char)((crc_reg >> 8) & 0xff); - og->header[24] = (unsigned char)((crc_reg >> 16) & 0xff); - og->header[25] = (unsigned char)((crc_reg >> 24) & 0xff); - } -} - -/* submit data to the internal buffer of the framing engine */ -int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count, - long e_o_s, ogg_int64_t granulepos) { - - long bytes = 0, lacing_vals; - int i; - - if (ogg_stream_check(os)) { - return -1; - } - if (!iov) { - return 0; - } - - for (i = 0; i < count; ++i) { - if (iov[i].iov_len > LONG_MAX) { - return -1; - } - if (bytes > LONG_MAX - (long)iov[i].iov_len) { - return -1; - } - bytes += (long)iov[i].iov_len; - } - lacing_vals = bytes / 255 + 1; - - if (os->body_returned) { - /* advance packet data according to the body_returned pointer. We - had to keep it around to return a pointer into the buffer last - call */ - - os->body_fill -= os->body_returned; - if (os->body_fill) - memmove(os->body_data, os->body_data + os->body_returned, - os->body_fill); - os->body_returned = 0; - } - - /* make sure we have the buffer storage */ - if (_os_body_expand(os, bytes) || _os_lacing_expand(os, lacing_vals)) { - return -1; - } - - /* Copy in the submitted packet. Yes, the copy is a waste; this is - the liability of overly clean abstraction for the time being. It - will actually be fairly easy to eliminate the extra copy in the - future */ - - for (i = 0; i < count; ++i) { - memcpy(os->body_data + os->body_fill, iov[i].iov_base, iov[i].iov_len); - os->body_fill += (int)iov[i].iov_len; - } - - /* Store lacing vals for this packet */ - for (i = 0; i < lacing_vals - 1; i++) { - os->lacing_vals[os->lacing_fill + i] = 255; - os->granule_vals[os->lacing_fill + i] = os->granulepos; - } - os->lacing_vals[os->lacing_fill + i] = bytes % 255; - os->granulepos = os->granule_vals[os->lacing_fill + i] = granulepos; - - /* flag the first segment as the beginning of the packet */ - os->lacing_vals[os->lacing_fill] |= 0x100; - - os->lacing_fill += lacing_vals; - - /* for the sake of completeness */ - os->packetno++; - - if (e_o_s) { - os->e_o_s = 1; - } - - return (0); -} - -int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op) { - ogg_iovec_t iov; - iov.iov_base = op->packet; - iov.iov_len = op->bytes; - return ogg_stream_iovecin(os, &iov, 1, op->e_o_s, op->granulepos); -} - -/* Conditionally flush a page; force==0 will only flush nominal-size - pages, force==1 forces us to flush a page regardless of page size - so long as there's any data available at all. */ -static int ogg_stream_flush_i(ogg_stream_state *os, ogg_page *og, int force, int nfill) { - int i; - int vals = 0; - int maxvals = (os->lacing_fill > 255 ? 255 : os->lacing_fill); - int bytes = 0; - long acc = 0; - ogg_int64_t granule_pos = -1; - - if (ogg_stream_check(os)) { - return (0); - } - if (maxvals == 0) { - return (0); - } - - /* construct a page */ - /* decide how many segments to include */ - - /* If this is the initial header case, the first page must only include - the initial header packet */ - if (os->b_o_s == 0) { /* 'initial header page' case */ - granule_pos = 0; - for (vals = 0; vals < maxvals; vals++) { - if ((os->lacing_vals[vals] & 0x0ff) < 255) { - vals++; - break; - } - } - } else { - - /* The extra packets_done, packet_just_done logic here attempts to do two things: - 1) Don't unnecessarily span pages. - 2) Unless necessary, don't flush pages if there are less than four packets on - them; this expands page size to reduce unnecessary overhead if incoming packets - are large. - These are not necessary behaviors, just 'always better than naive flushing' - without requiring an application to explicitly request a specific optimized - behavior. We'll want an explicit behavior setup pathway eventually as well. */ - - int packets_done = 0; - int packet_just_done = 0; - for (vals = 0; vals < maxvals; vals++) { - if (acc > nfill && packet_just_done >= 4) { - force = 1; - break; - } - acc += os->lacing_vals[vals] & 0x0ff; - if ((os->lacing_vals[vals] & 0xff) < 255) { - granule_pos = os->granule_vals[vals]; - packet_just_done = ++packets_done; - } else { - packet_just_done = 0; - } - } - if (vals == 255) { - force = 1; - } - } - - if (!force) { - return (0); - } - - /* construct the header in temp storage */ - memcpy(os->header, "OggS", 4); - - /* stream structure version */ - os->header[4] = 0x00; - - /* continued packet flag? */ - os->header[5] = 0x00; - if ((os->lacing_vals[0] & 0x100) == 0) { - os->header[5] |= 0x01; - } - /* first page flag? */ - if (os->b_o_s == 0) { - os->header[5] |= 0x02; - } - /* last page flag? */ - if (os->e_o_s && os->lacing_fill == vals) { - os->header[5] |= 0x04; - } - os->b_o_s = 1; - - /* 64 bits of PCM position */ - for (i = 6; i < 14; i++) { - os->header[i] = (unsigned char)(granule_pos & 0xff); - granule_pos >>= 8; - } - - /* 32 bits of stream serial number */ - { - long serialno = os->serialno; - for (i = 14; i < 18; i++) { - os->header[i] = (unsigned char)(serialno & 0xff); - serialno >>= 8; - } - } - - /* 32 bits of page counter (we have both counter and page header - because this val can roll over) */ - if (os->pageno == -1) { - os->pageno = 0; - } /* because someone called - stream_reset; this would be a - strange thing to do in an - encode stream, but it has - plausible uses */ - { - long pageno = os->pageno++; - for (i = 18; i < 22; i++) { - os->header[i] = (unsigned char)(pageno & 0xff); - pageno >>= 8; - } - } - - /* zero for computation; filled in later */ - os->header[22] = 0; - os->header[23] = 0; - os->header[24] = 0; - os->header[25] = 0; - - /* segment table */ - os->header[26] = (unsigned char)(vals & 0xff); - for (i = 0; i < vals; i++) { - bytes += os->header[i + 27] = (unsigned char)(os->lacing_vals[i] & 0xff); - } - - /* set pointers in the ogg_page struct */ - og->header = os->header; - og->header_len = os->header_fill = vals + 27; - og->body = os->body_data + os->body_returned; - og->body_len = bytes; - - /* advance the lacing data and set the body_returned pointer */ - - os->lacing_fill -= vals; - memmove(os->lacing_vals, os->lacing_vals + vals, os->lacing_fill * sizeof(*os->lacing_vals)); - memmove(os->granule_vals, os->granule_vals + vals, os->lacing_fill * sizeof(*os->granule_vals)); - os->body_returned += bytes; - - /* calculate the checksum */ - - ogg_page_checksum_set(og); - - /* done */ - return (1); -} - -/* This will flush remaining packets into a page (returning nonzero), - even if there is not enough data to trigger a flush normally - (undersized page). If there are no packets or partial packets to - flush, ogg_stream_flush returns 0. Note that ogg_stream_flush will - try to flush a normal sized page like ogg_stream_pageout; a call to - ogg_stream_flush does not guarantee that all packets have flushed. - Only a return value of 0 from ogg_stream_flush indicates all packet - data is flushed into pages. - - since ogg_stream_flush will flush the last page in a stream even if - it's undersized, you almost certainly want to use ogg_stream_pageout - (and *not* ogg_stream_flush) unless you specifically need to flush - a page regardless of size in the middle of a stream. */ - -int ogg_stream_flush(ogg_stream_state *os, ogg_page *og) { - return ogg_stream_flush_i(os, og, 1, 4096); -} - -/* Like the above, but an argument is provided to adjust the nominal - page size for applications which are smart enough to provide their - own delay based flushing */ - -int ogg_stream_flush_fill(ogg_stream_state *os, ogg_page *og, int nfill) { - return ogg_stream_flush_i(os, og, 1, nfill); -} - -/* This constructs pages from buffered packet segments. The pointers - returned are to static buffers; do not free. The returned buffers are - good only until the next call (using the same ogg_stream_state) */ - -int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og) { - int force = 0; - if (ogg_stream_check(os)) { - return 0; - } - - if ((os->e_o_s && os->lacing_fill) || /* 'were done, now flush' case */ - (os->lacing_fill && !os->b_o_s)) { /* 'initial header page' case */ - force = 1; - } - - return (ogg_stream_flush_i(os, og, force, 4096)); -} - -/* Like the above, but an argument is provided to adjust the nominal - page size for applications which are smart enough to provide their - own delay based flushing */ - -int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill) { - int force = 0; - if (ogg_stream_check(os)) { - return 0; - } - - if ((os->e_o_s && os->lacing_fill) || /* 'were done, now flush' case */ - (os->lacing_fill && !os->b_o_s)) { /* 'initial header page' case */ - force = 1; - } - - return (ogg_stream_flush_i(os, og, force, nfill)); -} - -int ogg_stream_eos(ogg_stream_state *os) { - if (ogg_stream_check(os)) { - return 1; - } - return os->e_o_s; -} - -/* DECODING PRIMITIVES: packet streaming layer **********************/ - -/* This has two layers to place more of the multi-serialno and paging - control in the application's hands. First, we expose a data buffer - using ogg_sync_buffer(). The app either copies into the - buffer, or passes it directly to read(), etc. We then call - ogg_sync_wrote() to tell how many bytes we just added. - - Pages are returned (pointers into the buffer in ogg_sync_state) - by ogg_sync_pageout(). The page is then submitted to - ogg_stream_pagein() along with the appropriate - ogg_stream_state* (ie, matching serialno). We then get raw - packets out calling ogg_stream_packetout() with a - ogg_stream_state. */ - -/* initialize the struct to a known state */ -int ogg_sync_init(ogg_sync_state *oy) { - if (oy) { - oy->storage = -1; /* used as a readiness flag */ - memset(oy, 0, sizeof(*oy)); - } - return (0); -} - -/* clear non-flat storage within */ -int ogg_sync_clear(ogg_sync_state *oy) { - if (oy) { - if (oy->data) { - _ogg_free(oy->data); - } - memset(oy, 0, sizeof(*oy)); - } - return (0); -} - -int ogg_sync_destroy(ogg_sync_state *oy) { - if (oy) { - ogg_sync_clear(oy); - _ogg_free(oy); - } - return (0); -} - -int ogg_sync_check(ogg_sync_state *oy) { - if (oy->storage < 0) { - return -1; - } - return 0; -} - -char *ogg_sync_buffer(ogg_sync_state *oy, long size) { - if (ogg_sync_check(oy)) { - return NULL; - } - - /* first, clear out any space that has been previously returned */ - if (oy->returned) { - oy->fill -= oy->returned; - if (oy->fill > 0) { - memmove(oy->data, oy->data + oy->returned, oy->fill); - } - oy->returned = 0; - } - - if (size > oy->storage - oy->fill) { - /* We need to extend the internal buffer */ - long newsize = size + oy->fill + 4096; /* an extra page to be nice */ - void *ret; - - if (oy->data) { - ret = _ogg_realloc(oy->data, newsize); - } else { - ret = _ogg_malloc(newsize); - } - if (!ret) { - ogg_sync_clear(oy); - return NULL; - } - oy->data = ret; - oy->storage = newsize; - } - - /* expose a segment at least as large as requested at the fill mark */ - return ((char *)oy->data + oy->fill); -} - -int ogg_sync_wrote(ogg_sync_state *oy, long bytes) { - if (ogg_sync_check(oy)) { - return -1; - } - if (oy->fill + bytes > oy->storage) { - return -1; - } - oy->fill += bytes; - return (0); -} - -/* sync the stream. This is meant to be useful for finding page - boundaries. - - return values for this: - -n) skipped n bytes - 0) page not ready; more data (no bytes skipped) - n) page synced at current location; page length n bytes - -*/ - -long ogg_sync_pageseek(ogg_sync_state *oy, ogg_page *og) { - unsigned char *page = oy->data + oy->returned; - unsigned char *next; - long bytes = oy->fill - oy->returned; - - if (ogg_sync_check(oy)) { - return 0; - } - - if (oy->headerbytes == 0) { - int headerbytes, i; - if (bytes < 27) { - return (0); /* not enough for a header */ - } - - /* verify capture pattern */ - if (memcmp(page, "OggS", 4)) { - goto sync_fail; - } - - headerbytes = page[26] + 27; - if (bytes < headerbytes) { - return (0); /* not enough for header + seg table */ - } - - /* count up body length in the segment table */ - - for (i = 0; i < page[26]; i++) { - oy->bodybytes += page[27 + i]; - } - oy->headerbytes = headerbytes; - } - - if (oy->bodybytes + oy->headerbytes > bytes) { - return (0); - } - - /* The whole test page is buffered. Verify the checksum */ - { - /* Grab the checksum bytes, set the header field to zero */ - char chksum[4]; - ogg_page log; - - memcpy(chksum, page + 22, 4); - memset(page + 22, 0, 4); - - /* set up a temp page struct and recompute the checksum */ - log.header = page; - log.header_len = oy->headerbytes; - log.body = page + oy->headerbytes; - log.body_len = oy->bodybytes; - ogg_page_checksum_set(&log); - - /* Compare */ - if (memcmp(chksum, page + 22, 4)) { - /* D'oh. Mismatch! Corrupt page (or miscapture and not a page - at all) */ - /* replace the computed checksum with the one actually read in */ - memcpy(page + 22, chksum, 4); - -#ifndef DISABLE_CRC - /* Bad checksum. Lose sync */ - goto sync_fail; -#endif - } - } - - /* yes, have a whole page all ready to go */ - { - if (og) { - og->header = page; - og->header_len = oy->headerbytes; - og->body = page + oy->headerbytes; - og->body_len = oy->bodybytes; - } - - oy->unsynced = 0; - oy->returned += (bytes = oy->headerbytes + oy->bodybytes); - oy->headerbytes = 0; - oy->bodybytes = 0; - return (bytes); - } - -sync_fail: - - oy->headerbytes = 0; - oy->bodybytes = 0; - - /* search for possible capture */ - next = memchr(page + 1, 'O', bytes - 1); - if (!next) { - next = oy->data + oy->fill; - } - - oy->returned = (int)(next - oy->data); - return ((long) - (next - page)); -} - -/* sync the stream and get a page. Keep trying until we find a page. - Suppress 'sync errors' after reporting the first. - - return values: - -1) recapture (hole in data) - 0) need more data - 1) page returned - - Returns pointers into buffered data; invalidated by next call to - _stream, _clear, _init, or _buffer */ - -int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og) { - - if (ogg_sync_check(oy)) { - return 0; - } - - /* all we need to do is verify a page at the head of the stream - buffer. If it doesn't verify, we look for the next potential - frame */ - - for (;;) { - long ret = ogg_sync_pageseek(oy, og); - if (ret > 0) { - /* have a page */ - return (1); - } - if (ret == 0) { - /* need more data */ - return (0); - } - - /* head did not start a synced page... skipped some bytes */ - if (!oy->unsynced) { - oy->unsynced = 1; - return (-1); - } - - /* loop. keep looking */ - - } -} - -/* add the incoming page to the stream state; we decompose the page - into packet segments here as well. */ - -int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og) { - unsigned char *header = og->header; - unsigned char *body = og->body; - long bodysize = og->body_len; - int segptr = 0; - - int version = ogg_page_version(og); - int continued = ogg_page_continued(og); - int bos = ogg_page_bos(og); - int eos = ogg_page_eos(og); - ogg_int64_t granulepos = ogg_page_granulepos(og); - int serialno = ogg_page_serialno(og); - long pageno = ogg_page_pageno(og); - int segments = header[26]; - - if (ogg_stream_check(os)) { - return -1; - } - - /* clean up 'returned data' */ - { - long lr = os->lacing_returned; - long br = os->body_returned; - - /* body data */ - if (br) { - os->body_fill -= br; - if (os->body_fill) { - memmove(os->body_data, os->body_data + br, os->body_fill); - } - os->body_returned = 0; - } - - if (lr) { - /* segment table */ - if (os->lacing_fill - lr) { - memmove(os->lacing_vals, os->lacing_vals + lr, - (os->lacing_fill - lr)*sizeof(*os->lacing_vals)); - memmove(os->granule_vals, os->granule_vals + lr, - (os->lacing_fill - lr)*sizeof(*os->granule_vals)); - } - os->lacing_fill -= lr; - os->lacing_packet -= lr; - os->lacing_returned = 0; - } - } - - /* check the serial number */ - if (serialno != os->serialno) { - return (-1); - } - if (version > 0) { - return (-1); - } - - if (_os_lacing_expand(os, segments + 1)) { - return -1; - } - - /* are we in sequence? */ - if (pageno != os->pageno) { - int i; - - /* unroll previous partial packet (if any) */ - for (i = os->lacing_packet; i < os->lacing_fill; i++) { - os->body_fill -= os->lacing_vals[i] & 0xff; - } - os->lacing_fill = os->lacing_packet; - - /* make a note of dropped data in segment table */ - if (os->pageno != -1) { - os->lacing_vals[os->lacing_fill++] = 0x400; - os->lacing_packet++; - } - } - - /* are we a 'continued packet' page? If so, we may need to skip - some segments */ - if (continued) { - if (os->lacing_fill < 1 || - (os->lacing_vals[os->lacing_fill - 1] & 0xff) < 255 || - os->lacing_vals[os->lacing_fill - 1] == 0x400) { - bos = 0; - for (; segptr < segments; segptr++) { - int val = header[27 + segptr]; - body += val; - bodysize -= val; - if (val < 255) { - segptr++; - break; - } - } - } - } - - if (bodysize) { - if (_os_body_expand(os, bodysize)) { - return -1; - } - memcpy(os->body_data + os->body_fill, body, bodysize); - os->body_fill += bodysize; - } - - { - int saved = -1; - while (segptr < segments) { - int val = header[27 + segptr]; - os->lacing_vals[os->lacing_fill] = val; - os->granule_vals[os->lacing_fill] = -1; - - if (bos) { - os->lacing_vals[os->lacing_fill] |= 0x100; - bos = 0; - } - - if (val < 255) { - saved = os->lacing_fill; - } - - os->lacing_fill++; - segptr++; - - if (val < 255) { - os->lacing_packet = os->lacing_fill; - } - } - - /* set the granulepos on the last granuleval of the last full packet */ - if (saved != -1) { - os->granule_vals[saved] = granulepos; - } - - } - - if (eos) { - os->e_o_s = 1; - if (os->lacing_fill > 0) { - os->lacing_vals[os->lacing_fill - 1] |= 0x200; - } - } - - os->pageno = pageno + 1; - - return (0); -} - -/* clear things to an initial state. Good to call, eg, before seeking */ -int ogg_sync_reset(ogg_sync_state *oy) { - if (ogg_sync_check(oy)) { - return -1; - } - - oy->fill = 0; - oy->returned = 0; - oy->unsynced = 0; - oy->headerbytes = 0; - oy->bodybytes = 0; - return (0); -} - -int ogg_stream_reset(ogg_stream_state *os) { - if (ogg_stream_check(os)) { - return -1; - } - - os->body_fill = 0; - os->body_returned = 0; - - os->lacing_fill = 0; - os->lacing_packet = 0; - os->lacing_returned = 0; - - os->header_fill = 0; - - os->e_o_s = 0; - os->b_o_s = 0; - os->pageno = -1; - os->packetno = 0; - os->granulepos = 0; - - return (0); -} - -int ogg_stream_reset_serialno(ogg_stream_state *os, int serialno) { - if (ogg_stream_check(os)) { - return -1; - } - ogg_stream_reset(os); - os->serialno = serialno; - return (0); -} - -static int _packetout(ogg_stream_state *os, ogg_packet *op, int adv) { - - /* The last part of decode. We have the stream broken into packet - segments. Now we need to group them into packets (or return the - out of sync markers) */ - - int ptr = os->lacing_returned; - - if (os->lacing_packet <= ptr) { - return (0); - } - - if (os->lacing_vals[ptr] & 0x400) { - /* we need to tell the codec there's a gap; it might need to - handle previous packet dependencies. */ - os->lacing_returned++; - os->packetno++; - return (-1); - } - - if (!op && !adv) { - return (1); - } /* just using peek as an inexpensive way - to ask if there's a whole packet - waiting */ - - /* Gather the whole packet. We'll have no holes or a partial packet */ - { - int size = os->lacing_vals[ptr] & 0xff; - long bytes = size; - int eos = os->lacing_vals[ptr] & 0x200; /* last packet of the stream? */ - int bos = os->lacing_vals[ptr] & 0x100; /* first packet of the stream? */ - - while (size == 255) { - int val = os->lacing_vals[++ptr]; - size = val & 0xff; - if (val & 0x200) { - eos = 0x200; - } - bytes += size; - } - - if (op) { - op->e_o_s = eos; - op->b_o_s = bos; - op->packet = os->body_data + os->body_returned; - op->packetno = os->packetno; - op->granulepos = os->granule_vals[ptr]; - op->bytes = bytes; - } - - if (adv) { - os->body_returned += bytes; - os->lacing_returned = ptr + 1; - os->packetno++; - } - } - return (1); -} - -int ogg_stream_packetout(ogg_stream_state *os, ogg_packet *op) { - if (ogg_stream_check(os)) { - return 0; - } - return _packetout(os, op, 1); -} - -int ogg_stream_packetpeek(ogg_stream_state *os, ogg_packet *op) { - if (ogg_stream_check(os)) { - return 0; - } - return _packetout(os, op, 0); -} - -void ogg_packet_clear(ogg_packet *op) { - _ogg_free(op->packet); - memset(op, 0, sizeof(*op)); -} - -#ifdef _V_SELFTEST -#include - -ogg_stream_state os_en, os_de; -ogg_sync_state oy; - -void checkpacket(ogg_packet *op, long len, int no, long pos) { - long j; - static int sequence = 0; - static int lastno = 0; - - if (op->bytes != len) { - fprintf(stderr, "incorrect packet length (%ld != %ld)!\n", op->bytes, len); - exit(1); - } - if (op->granulepos != pos) { - fprintf(stderr, "incorrect packet granpos (%ld != %ld)!\n", (long)op->granulepos, pos); - exit(1); - } - - /* packet number just follows sequence/gap; adjust the input number - for that */ - if (no == 0) { - sequence = 0; - } else { - sequence++; - if (no > lastno + 1) { - sequence++; - } - } - lastno = no; - if (op->packetno != sequence) { - fprintf(stderr, "incorrect packet sequence %ld != %d\n", - (long)(op->packetno), sequence); - exit(1); - } - - /* Test data */ - for (j = 0; j < op->bytes; j++) - if (op->packet[j] != ((j + no) & 0xff)) { - fprintf(stderr, "body data mismatch (1) at pos %ld: %x!=%lx!\n\n", - j, op->packet[j], (j + no) & 0xff); - exit(1); - } -} - -void check_page(unsigned char *data, const int *header, ogg_page *og) { - long j; - /* Test data */ - for (j = 0; j < og->body_len; j++) - if (og->body[j] != data[j]) { - fprintf(stderr, "body data mismatch (2) at pos %ld: %x!=%x!\n\n", - j, data[j], og->body[j]); - exit(1); - } - - /* Test header */ - for (j = 0; j < og->header_len; j++) { - if (og->header[j] != header[j]) { - fprintf(stderr, "header content mismatch at pos %ld:\n", j); - for (j = 0; j < header[26] + 27; j++) { - fprintf(stderr, " (%ld)%02x:%02x", j, header[j], og->header[j]); - } - fprintf(stderr, "\n"); - exit(1); - } - } - if (og->header_len != header[26] + 27) { - fprintf(stderr, "header length incorrect! (%ld!=%d)\n", - og->header_len, header[26] + 27); - exit(1); - } -} - -void print_header(ogg_page *og) { - int j; - fprintf(stderr, "\nHEADER:\n"); - fprintf(stderr, " capture: %c %c %c %c version: %d flags: %x\n", - og->header[0], og->header[1], og->header[2], og->header[3], - (int)og->header[4], (int)og->header[5]); - - fprintf(stderr, " granulepos: %d serialno: %d pageno: %ld\n", - (og->header[9] << 24) | (og->header[8] << 16) | - (og->header[7] << 8) | og->header[6], - (og->header[17] << 24) | (og->header[16] << 16) | - (og->header[15] << 8) | og->header[14], - ((long)(og->header[21]) << 24) | (og->header[20] << 16) | - (og->header[19] << 8) | og->header[18]); - - fprintf(stderr, " checksum: %02x:%02x:%02x:%02x\n segments: %d (", - (int)og->header[22], (int)og->header[23], - (int)og->header[24], (int)og->header[25], - (int)og->header[26]); - - for (j = 27; j < og->header_len; j++) { - fprintf(stderr, "%d ", (int)og->header[j]); - } - fprintf(stderr, ")\n\n"); -} - -void copy_page(ogg_page *og) { - unsigned char *temp = _ogg_malloc(og->header_len); - memcpy(temp, og->header, og->header_len); - og->header = temp; - - temp = _ogg_malloc(og->body_len); - memcpy(temp, og->body, og->body_len); - og->body = temp; -} - -void free_page(ogg_page *og) { - _ogg_free(og->header); - _ogg_free(og->body); -} - -void error(void) { - fprintf(stderr, "error!\n"); - exit(1); -} - -/* 17 only */ -const int head1_0[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x06, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0x15, 0xed, 0xec, 0x91, - 1, - 17 - }; - -/* 17, 254, 255, 256, 500, 510, 600 byte, pad */ -const int head1_1[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0x59, 0x10, 0x6c, 0x2c, - 1, - 17 - }; -const int head2_1[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x04, - 0x07, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0x89, 0x33, 0x85, 0xce, - 13, - 254, 255, 0, 255, 1, 255, 245, 255, 255, 0, - 255, 255, 90 - }; - -/* nil packets; beginning,middle,end */ -const int head1_2[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0xff, 0x7b, 0x23, 0x17, - 1, - 0 - }; -const int head2_2[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x04, - 0x07, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0x5c, 0x3f, 0x66, 0xcb, - 17, - 17, 254, 255, 0, 0, 255, 1, 0, 255, 245, 255, 255, 0, - 255, 255, 90, 0 - }; - -/* large initial packet */ -const int head1_3[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0x01, 0x27, 0x31, 0xaa, - 18, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 10 - }; - -const int head2_3[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x04, - 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0x7f, 0x4e, 0x8a, 0xd2, - 4, - 255, 4, 255, 0 - }; - - -/* continuing packet test */ -const int head1_4[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0xff, 0x7b, 0x23, 0x17, - 1, - 0 - }; - -const int head2_4[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0xf8, 0x3c, 0x19, 0x79, - 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255 - }; - -const int head3_4[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x05, - 0x07, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 2, 0, 0, 0, - 0x38, 0xe6, 0xb6, 0x28, - 6, - 255, 220, 255, 4, 255, 0 - }; - - -/* spill expansion test */ -const int head1_4b[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0xff, 0x7b, 0x23, 0x17, - 1, - 0 - }; - -const int head2_4b[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x00, - 0x07, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0xce, 0x8f, 0x17, 0x1a, - 23, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 10, 255, 4, 255, 0, 0 - }; - - -const int head3_4b[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x04, - 0x07, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 2, 0, 0, 0, - 0x9b, 0xb2, 0x50, 0xa1, - 1, - 0 - }; - -/* page with the 255 segment limit */ -const int head1_5[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0xff, 0x7b, 0x23, 0x17, - 1, - 0 - }; - -const int head2_5[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x00, - 0x07, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0xed, 0x2a, 0x2e, 0xa7, - 255, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10 - }; - -const int head3_5[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x04, - 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 2, 0, 0, 0, - 0x6c, 0x3b, 0x82, 0x3d, - 1, - 50 - }; - - -/* packet that overspans over an entire page */ -const int head1_6[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0xff, 0x7b, 0x23, 0x17, - 1, - 0 - }; - -const int head2_6[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x00, - 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0x68, 0x22, 0x7c, 0x3d, - 255, - 100, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255 - }; - -const int head3_6[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x01, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x01, 0x02, 0x03, 0x04, 2, 0, 0, 0, - 0xf4, 0x87, 0xba, 0xf3, - 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255 - }; - -const int head4_6[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x05, - 0x07, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 3, 0, 0, 0, - 0xf7, 0x2f, 0x6c, 0x60, - 5, - 254, 255, 4, 255, 0 - }; - -/* packet that overspans over an entire page */ -const int head1_7[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, - 0xff, 0x7b, 0x23, 0x17, - 1, - 0 - }; - -const int head2_7[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x00, - 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 1, 0, 0, 0, - 0x68, 0x22, 0x7c, 0x3d, - 255, - 100, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255 - }; - -const int head3_7[] PROGMEM = {0x4f, 0x67, 0x67, 0x53, 0, 0x05, - 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 2, 0, 0, 0, - 0xd4, 0xe0, 0x60, 0xe5, - 1, - 0 - }; - -int compare_packet(const ogg_packet *op1, const ogg_packet *op2) { - if (op1->packet != op2->packet) { - fprintf(stderr, "op1->packet != op2->packet\n"); - return (1); - } - if (op1->bytes != op2->bytes) { - fprintf(stderr, "op1->bytes != op2->bytes\n"); - return (1); - } - if (op1->b_o_s != op2->b_o_s) { - fprintf(stderr, "op1->b_o_s != op2->b_o_s\n"); - return (1); - } - if (op1->e_o_s != op2->e_o_s) { - fprintf(stderr, "op1->e_o_s != op2->e_o_s\n"); - return (1); - } - if (op1->granulepos != op2->granulepos) { - fprintf(stderr, "op1->granulepos != op2->granulepos\n"); - return (1); - } - if (op1->packetno != op2->packetno) { - fprintf(stderr, "op1->packetno != op2->packetno\n"); - return (1); - } - return (0); -} - -void test_pack(const int *pl, const int **headers, int byteskip, - int pageskip, int packetskip) { - unsigned char *data = _ogg_malloc(1024 * 1024); /* for scripted test cases only */ - long inptr = 0; - long outptr = 0; - long deptr = 0; - long depacket = 0; - long granule_pos = 7, pageno = 0; - int i, j, packets, pageout = pageskip; - int eosflag = 0; - int bosflag = 0; - - int byteskipcount = 0; - - ogg_stream_reset(&os_en); - ogg_stream_reset(&os_de); - ogg_sync_reset(&oy); - - for (packets = 0; packets < packetskip; packets++) { - depacket += pl[packets]; - } - - for (packets = 0;; packets++)if (pl[packets] == -1) { - break; - } - - for (i = 0; i < packets; i++) { - /* construct a test packet */ - ogg_packet op; - int len = pl[i]; - - op.packet = data + inptr; - op.bytes = len; - op.e_o_s = (pl[i + 1] < 0 ? 1 : 0); - op.granulepos = granule_pos; - - granule_pos += 1024; - - for (j = 0; j < len; j++) { - data[inptr++] = i + j; - } - - /* submit the test packet */ - ogg_stream_packetin(&os_en, &op); - - /* retrieve any finished pages */ - { - ogg_page og; - - while (ogg_stream_pageout(&os_en, &og)) { - /* We have a page. Check it carefully */ - - fprintf(stderr, "%ld, ", pageno); - - if (headers[pageno] == NULL) { - fprintf(stderr, "coded too many pages!\n"); - exit(1); - } - - check_page(data + outptr, headers[pageno], &og); - - outptr += og.body_len; - pageno++; - if (pageskip) { - bosflag = 1; - pageskip--; - deptr += og.body_len; - } - - /* have a complete page; submit it to sync/decode */ - - { - ogg_page og_de; - ogg_packet op_de, op_de2; - char *buf = ogg_sync_buffer(&oy, og.header_len + og.body_len); - char *next = buf; - byteskipcount += og.header_len; - if (byteskipcount > byteskip) { - memcpy(next, og.header, byteskipcount - byteskip); - next += byteskipcount - byteskip; - byteskipcount = byteskip; - } - - byteskipcount += og.body_len; - if (byteskipcount > byteskip) { - memcpy(next, og.body, byteskipcount - byteskip); - next += byteskipcount - byteskip; - byteskipcount = byteskip; - } - - ogg_sync_wrote(&oy, next - buf); - - while (1) { - int ret = ogg_sync_pageout(&oy, &og_de); - if (ret == 0) { - break; - } - if (ret < 0) { - continue; - } - /* got a page. Happy happy. Verify that it's good. */ - - fprintf(stderr, "(%d), ", pageout); - - check_page(data + deptr, headers[pageout], &og_de); - deptr += og_de.body_len; - pageout++; - - /* submit it to deconstitution */ - ogg_stream_pagein(&os_de, &og_de); - - /* packets out? */ - while (ogg_stream_packetpeek(&os_de, &op_de2) > 0) { - ogg_stream_packetpeek(&os_de, NULL); - ogg_stream_packetout(&os_de, &op_de); /* just catching them all */ - - /* verify peek and out match */ - if (compare_packet(&op_de, &op_de2)) { - fprintf(stderr, "packetout != packetpeek! pos=%ld\n", - depacket); - exit(1); - } - - /* verify the packet! */ - /* check data */ - if (memcmp(data + depacket, op_de.packet, op_de.bytes)) { - fprintf(stderr, "packet data mismatch in decode! pos=%ld\n", - depacket); - exit(1); - } - /* check bos flag */ - if (bosflag == 0 && op_de.b_o_s == 0) { - fprintf(stderr, "b_o_s flag not set on packet!\n"); - exit(1); - } - if (bosflag && op_de.b_o_s) { - fprintf(stderr, "b_o_s flag incorrectly set on packet!\n"); - exit(1); - } - bosflag = 1; - depacket += op_de.bytes; - - /* check eos flag */ - if (eosflag) { - fprintf(stderr, "Multiple decoded packets with eos flag!\n"); - exit(1); - } - - if (op_de.e_o_s) { - eosflag = 1; - } - - /* check granulepos flag */ - if (op_de.granulepos != -1) { - fprintf(stderr, " granule:%ld ", (long)op_de.granulepos); - } - } - } - } - } - } - } - _ogg_free(data); - if (headers[pageno] != NULL) { - fprintf(stderr, "did not write last page!\n"); - exit(1); - } - if (headers[pageout] != NULL) { - fprintf(stderr, "did not decode last page!\n"); - exit(1); - } - if (inptr != outptr) { - fprintf(stderr, "encoded page data incomplete!\n"); - exit(1); - } - if (inptr != deptr) { - fprintf(stderr, "decoded page data incomplete!\n"); - exit(1); - } - if (inptr != depacket) { - fprintf(stderr, "decoded packet data incomplete!\n"); - exit(1); - } - if (!eosflag) { - fprintf(stderr, "Never got a packet with EOS set!\n"); - exit(1); - } - fprintf(stderr, "ok.\n"); -} - -int main(void) { - - ogg_stream_init(&os_en, 0x04030201); - ogg_stream_init(&os_de, 0x04030201); - ogg_sync_init(&oy); - - /* Exercise each code path in the framing code. Also verify that - the checksums are working. */ - - { - /* 17 only */ - const int packets[] = {17, -1}; - const int *headret[] = {head1_0, NULL}; - - fprintf(stderr, "testing single page encoding... "); - test_pack(packets, headret, 0, 0, 0); - } - - { - /* 17, 254, 255, 256, 500, 510, 600 byte, pad */ - const int packets[] = {17, 254, 255, 256, 500, 510, 600, -1}; - const int *headret[] = {head1_1, head2_1, NULL}; - - fprintf(stderr, "testing basic page encoding... "); - test_pack(packets, headret, 0, 0, 0); - } - - { - /* nil packets; beginning,middle,end */ - const int packets[] = {0, 17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1}; - const int *headret[] = {head1_2, head2_2, NULL}; - - fprintf(stderr, "testing basic nil packets... "); - test_pack(packets, headret, 0, 0, 0); - } - - { - /* large initial packet */ - const int packets[] = {4345, 259, 255, -1}; - const int *headret[] = {head1_3, head2_3, NULL}; - - fprintf(stderr, "testing initial-packet lacing > 4k... "); - test_pack(packets, headret, 0, 0, 0); - } - - { - /* continuing packet test; with page spill expansion, we have to - overflow the lacing table. */ - const int packets[] = {0, 65500, 259, 255, -1}; - const int *headret[] = {head1_4, head2_4, head3_4, NULL}; - - fprintf(stderr, "testing single packet page span... "); - test_pack(packets, headret, 0, 0, 0); - } - - { - /* spill expand packet test */ - const int packets[] = {0, 4345, 259, 255, 0, 0, -1}; - const int *headret[] = {head1_4b, head2_4b, head3_4b, NULL}; - - fprintf(stderr, "testing page spill expansion... "); - test_pack(packets, headret, 0, 0, 0); - } - - /* page with the 255 segment limit */ - { - - const int packets[] PROGMEM = {0, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 50, -1 - }; - const int *headret[] PROGMEM = {head1_5, head2_5, head3_5, NULL}; - - fprintf(stderr, "testing max packet segments... "); - test_pack(packets, headret, 0, 0, 0); - } - - { - /* packet that overspans over an entire page */ - const int packets[] = {0, 100, 130049, 259, 255, -1}; - const int *headret[] = {head1_6, head2_6, head3_6, head4_6, NULL}; - - fprintf(stderr, "testing very large packets... "); - test_pack(packets, headret, 0, 0, 0); - } - -#ifndef DISABLE_CRC - { - /* test for the libogg 1.1.1 resync in large continuation bug - found by Josh Coalson) */ - const int packets[] = {0, 100, 130049, 259, 255, -1}; - const int *headret[] = {head1_6, head2_6, head3_6, head4_6, NULL}; - - fprintf(stderr, "testing continuation resync in very large packets... "); - test_pack(packets, headret, 100, 2, 3); - } -#else - fprintf(stderr, "Skipping continuation resync test due to --disable-crc\n"); -#endif - - { - /* term only page. why not? */ - const int packets[] = {0, 100, 64770, -1}; - const int *headret[] = {head1_7, head2_7, head3_7, NULL}; - - fprintf(stderr, "testing zero data page (1 nil packet)... "); - test_pack(packets, headret, 0, 0, 0); - } - - - - { - /* build a bunch of pages for testing */ - unsigned char *data = _ogg_malloc(1024 * 1024); - int pl[] = {0, 1, 1, 98, 4079, 1, 1, 2954, 2057, 76, 34, 912, 0, 234, 1000, 1000, 1000, 300, -1}; - int inptr = 0, i, j; - ogg_page og[5]; - - ogg_stream_reset(&os_en); - - for (i = 0; pl[i] != -1; i++) { - ogg_packet op; - int len = pl[i]; - - op.packet = data + inptr; - op.bytes = len; - op.e_o_s = (pl[i + 1] < 0 ? 1 : 0); - op.granulepos = (i + 1) * 1000; - - for (j = 0; j < len; j++) { - data[inptr++] = i + j; - } - ogg_stream_packetin(&os_en, &op); - } - - _ogg_free(data); - - /* retrieve finished pages */ - for (i = 0; i < 5; i++) { - if (ogg_stream_pageout(&os_en, &og[i]) == 0) { - fprintf(stderr, "Too few pages output building sync tests!\n"); - exit(1); - } - copy_page(&og[i]); - } - - /* Test lost pages on pagein/packetout: no rollback */ - { - ogg_page temp; - ogg_packet test; - - fprintf(stderr, "Testing loss of pages... "); - - ogg_sync_reset(&oy); - ogg_stream_reset(&os_de); - for (i = 0; i < 5; i++) { - memcpy(ogg_sync_buffer(&oy, og[i].header_len), og[i].header, - og[i].header_len); - ogg_sync_wrote(&oy, og[i].header_len); - memcpy(ogg_sync_buffer(&oy, og[i].body_len), og[i].body, og[i].body_len); - ogg_sync_wrote(&oy, og[i].body_len); - } - - ogg_sync_pageout(&oy, &temp); - ogg_stream_pagein(&os_de, &temp); - ogg_sync_pageout(&oy, &temp); - ogg_stream_pagein(&os_de, &temp); - ogg_sync_pageout(&oy, &temp); - /* skip */ - ogg_sync_pageout(&oy, &temp); - ogg_stream_pagein(&os_de, &temp); - - /* do we get the expected results/packets? */ - - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 0, 0, 0); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 1, 1, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 1, 2, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 98, 3, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 4079, 4, 5000); - if (ogg_stream_packetout(&os_de, &test) != -1) { - fprintf(stderr, "Error: loss of page did not return error\n"); - exit(1); - } - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 76, 9, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 34, 10, -1); - fprintf(stderr, "ok.\n"); - } - - /* Test lost pages on pagein/packetout: rollback with continuation */ - { - ogg_page temp; - ogg_packet test; - - fprintf(stderr, "Testing loss of pages (rollback required)... "); - - ogg_sync_reset(&oy); - ogg_stream_reset(&os_de); - for (i = 0; i < 5; i++) { - memcpy(ogg_sync_buffer(&oy, og[i].header_len), og[i].header, - og[i].header_len); - ogg_sync_wrote(&oy, og[i].header_len); - memcpy(ogg_sync_buffer(&oy, og[i].body_len), og[i].body, og[i].body_len); - ogg_sync_wrote(&oy, og[i].body_len); - } - - ogg_sync_pageout(&oy, &temp); - ogg_stream_pagein(&os_de, &temp); - ogg_sync_pageout(&oy, &temp); - ogg_stream_pagein(&os_de, &temp); - ogg_sync_pageout(&oy, &temp); - ogg_stream_pagein(&os_de, &temp); - ogg_sync_pageout(&oy, &temp); - /* skip */ - ogg_sync_pageout(&oy, &temp); - ogg_stream_pagein(&os_de, &temp); - - /* do we get the expected results/packets? */ - - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 0, 0, 0); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 1, 1, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 1, 2, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 98, 3, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 4079, 4, 5000); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 1, 5, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 1, 6, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 2954, 7, -1); - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 2057, 8, 9000); - if (ogg_stream_packetout(&os_de, &test) != -1) { - fprintf(stderr, "Error: loss of page did not return error\n"); - exit(1); - } - if (ogg_stream_packetout(&os_de, &test) != 1) { - error(); - } - checkpacket(&test, 300, 17, 18000); - fprintf(stderr, "ok.\n"); - } - - /* the rest only test sync */ - { - ogg_page og_de; - /* Test fractional page inputs: incomplete capture */ - fprintf(stderr, "Testing sync on partial inputs... "); - ogg_sync_reset(&oy); - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header, - 3); - ogg_sync_wrote(&oy, 3); - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - - /* Test fractional page inputs: incomplete fixed header */ - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header + 3, - 20); - ogg_sync_wrote(&oy, 20); - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - - /* Test fractional page inputs: incomplete header */ - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header + 23, - 5); - ogg_sync_wrote(&oy, 5); - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - - /* Test fractional page inputs: incomplete body */ - - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header + 28, - og[1].header_len - 28); - ogg_sync_wrote(&oy, og[1].header_len - 28); - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - - memcpy(ogg_sync_buffer(&oy, og[1].body_len), og[1].body, 1000); - ogg_sync_wrote(&oy, 1000); - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - - memcpy(ogg_sync_buffer(&oy, og[1].body_len), og[1].body + 1000, - og[1].body_len - 1000); - ogg_sync_wrote(&oy, og[1].body_len - 1000); - if (ogg_sync_pageout(&oy, &og_de) <= 0) { - error(); - } - - fprintf(stderr, "ok.\n"); - } - - /* Test fractional page inputs: page + incomplete capture */ - { - ogg_page og_de; - fprintf(stderr, "Testing sync on 1+partial inputs... "); - ogg_sync_reset(&oy); - - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy, og[1].header_len); - - memcpy(ogg_sync_buffer(&oy, og[1].body_len), og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy, og[1].body_len); - - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header, - 20); - ogg_sync_wrote(&oy, 20); - if (ogg_sync_pageout(&oy, &og_de) <= 0) { - error(); - } - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header + 20, - og[1].header_len - 20); - ogg_sync_wrote(&oy, og[1].header_len - 20); - memcpy(ogg_sync_buffer(&oy, og[1].body_len), og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy, og[1].body_len); - if (ogg_sync_pageout(&oy, &og_de) <= 0) { - error(); - } - - fprintf(stderr, "ok.\n"); - } - - /* Test recapture: garbage + page */ - { - ogg_page og_de; - fprintf(stderr, "Testing search for capture... "); - ogg_sync_reset(&oy); - - /* 'garbage' */ - memcpy(ogg_sync_buffer(&oy, og[1].body_len), og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy, og[1].body_len); - - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy, og[1].header_len); - - memcpy(ogg_sync_buffer(&oy, og[1].body_len), og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy, og[1].body_len); - - memcpy(ogg_sync_buffer(&oy, og[2].header_len), og[2].header, - 20); - ogg_sync_wrote(&oy, 20); - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - if (ogg_sync_pageout(&oy, &og_de) <= 0) { - error(); - } - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - - memcpy(ogg_sync_buffer(&oy, og[2].header_len), og[2].header + 20, - og[2].header_len - 20); - ogg_sync_wrote(&oy, og[2].header_len - 20); - memcpy(ogg_sync_buffer(&oy, og[2].body_len), og[2].body, - og[2].body_len); - ogg_sync_wrote(&oy, og[2].body_len); - if (ogg_sync_pageout(&oy, &og_de) <= 0) { - error(); - } - - fprintf(stderr, "ok.\n"); - } - -#ifndef DISABLE_CRC - /* Test recapture: page + garbage + page */ - { - ogg_page og_de; - fprintf(stderr, "Testing recapture... "); - ogg_sync_reset(&oy); - - memcpy(ogg_sync_buffer(&oy, og[1].header_len), og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy, og[1].header_len); - - memcpy(ogg_sync_buffer(&oy, og[1].body_len), og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy, og[1].body_len); - - memcpy(ogg_sync_buffer(&oy, og[2].header_len), og[2].header, - og[2].header_len); - ogg_sync_wrote(&oy, og[2].header_len); - - memcpy(ogg_sync_buffer(&oy, og[2].header_len), og[2].header, - og[2].header_len); - ogg_sync_wrote(&oy, og[2].header_len); - - if (ogg_sync_pageout(&oy, &og_de) <= 0) { - error(); - } - - memcpy(ogg_sync_buffer(&oy, og[2].body_len), og[2].body, - og[2].body_len - 5); - ogg_sync_wrote(&oy, og[2].body_len - 5); - - memcpy(ogg_sync_buffer(&oy, og[3].header_len), og[3].header, - og[3].header_len); - ogg_sync_wrote(&oy, og[3].header_len); - - memcpy(ogg_sync_buffer(&oy, og[3].body_len), og[3].body, - og[3].body_len); - ogg_sync_wrote(&oy, og[3].body_len); - - if (ogg_sync_pageout(&oy, &og_de) > 0) { - error(); - } - if (ogg_sync_pageout(&oy, &og_de) <= 0) { - error(); - } - - fprintf(stderr, "ok.\n"); - } -#else - fprintf(stderr, "Skipping recapture test due to --disable-crc\n"); -#endif - - /* Free page data that was previously copied */ - { - for (i = 0; i < 5; i++) { - free_page(&og[i]); - } - } - } - ogg_sync_clear(&oy); - ogg_stream_clear(&os_en); - ogg_stream_clear(&os_de); - - return (0); -} - -#endif diff --git a/src/libogg/ogg.pc b/src/libogg/ogg.pc deleted file mode 100644 index 78755ce..0000000 --- a/src/libogg/ogg.pc +++ /dev/null @@ -1,14 +0,0 @@ -# ogg pkg-config file - -prefix=/usr/local -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: ogg -Description: ogg is a library for manipulating ogg bitstreams -Version: 1.3.4 -Requires: -Conflicts: -Libs: -L${libdir} -logg -Cflags: -I${includedir} diff --git a/src/libogg/ogg/config_types.h b/src/libogg/ogg/config_types.h deleted file mode 100644 index 1a87df6..0000000 --- a/src/libogg/ogg/config_types.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __CONFIG_TYPES_H__ -#define __CONFIG_TYPES_H__ - -/* these are filled in by configure or cmake*/ -#define INCLUDE_INTTYPES_H 1 -#define INCLUDE_STDINT_H 1 -#define INCLUDE_SYS_TYPES_H 1 - -#if INCLUDE_INTTYPES_H -# include -#endif -#if INCLUDE_STDINT_H -# include -#endif -#if INCLUDE_SYS_TYPES_H -# include -#endif - -typedef int16_t ogg_int16_t; -typedef uint16_t ogg_uint16_t; -typedef int32_t ogg_int32_t; -typedef uint32_t ogg_uint32_t; -typedef int64_t ogg_int64_t; -typedef uint64_t ogg_uint64_t; - -#endif diff --git a/src/libogg/ogg/ogg.h b/src/libogg/ogg/ogg.h deleted file mode 100644 index b1025d5..0000000 --- a/src/libogg/ogg/ogg.h +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 - by the Xiph.Org Foundation http://www.xiph.org/ - * * - ******************************************************************** - - function: toplevel libogg include - - ********************************************************************/ -#ifndef _OGG_H -#define _OGG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "os_types.h" - -typedef struct { - void *iov_base; - size_t iov_len; -} ogg_iovec_t; - -typedef struct { - long endbyte; - int endbit; - - unsigned char *buffer; - unsigned char *ptr; - long storage; -} oggpack_buffer; - -/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/ - -typedef struct { - unsigned char *header; - long header_len; - unsigned char *body; - long body_len; -} ogg_page; - -/* ogg_stream_state contains the current encode/decode state of a logical - Ogg bitstream **********************************************************/ - -typedef struct { - unsigned char *body_data; /* bytes from packet bodies */ - long body_storage; /* storage elements allocated */ - long body_fill; /* elements stored; fill mark */ - long body_returned; /* elements of fill returned */ - - - int *lacing_vals; /* The values that will go to the segment table */ - ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact - this way, but it is simple coupled to the - lacing fifo */ - long lacing_storage; - long lacing_fill; - long lacing_packet; - long lacing_returned; - - unsigned char header[282]; /* working space for header encode */ - int header_fill; - - int e_o_s; /* set when we have buffered the last packet in the - logical bitstream */ - int b_o_s; /* set after we've written the initial page - of a logical bitstream */ - long serialno; - long pageno; - ogg_int64_t packetno; /* sequence number for decode; the framing - knows where there's a hole in the data, - but we need coupling so that the codec - (which is in a separate abstraction - layer) also knows about the gap */ - ogg_int64_t granulepos; - -} ogg_stream_state; - -/* ogg_packet is used to encapsulate the data and metadata belonging - to a single raw Ogg/Vorbis packet *************************************/ - -typedef struct { - unsigned char *packet; - long bytes; - long b_o_s; - long e_o_s; - - ogg_int64_t granulepos; - - ogg_int64_t packetno; /* sequence number for decode; the framing - knows where there's a hole in the data, - but we need coupling so that the codec - (which is in a separate abstraction - layer) also knows about the gap */ -} ogg_packet; - -typedef struct { - unsigned char *data; - int storage; - int fill; - int returned; - - int unsynced; - int headerbytes; - int bodybytes; -} ogg_sync_state; - -/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ - -extern void oggpack_writeinit(oggpack_buffer *b); -extern int oggpack_writecheck(oggpack_buffer *b); -extern void oggpack_writetrunc(oggpack_buffer *b, long bits); -extern void oggpack_writealign(oggpack_buffer *b); -extern void oggpack_writecopy(oggpack_buffer *b, void *source, long bits); -extern void oggpack_reset(oggpack_buffer *b); -extern void oggpack_writeclear(oggpack_buffer *b); -extern void oggpack_readinit(oggpack_buffer *b, unsigned char *buf, int bytes); -extern void oggpack_write(oggpack_buffer *b, unsigned long value, int bits); -extern long oggpack_look(oggpack_buffer *b, int bits); -extern long oggpack_look1(oggpack_buffer *b); -extern void oggpack_adv(oggpack_buffer *b, int bits); -extern void oggpack_adv1(oggpack_buffer *b); -extern long oggpack_read(oggpack_buffer *b, int bits); -extern long oggpack_read1(oggpack_buffer *b); -extern long oggpack_bytes(oggpack_buffer *b); -extern long oggpack_bits(oggpack_buffer *b); -extern unsigned char *oggpack_get_buffer(oggpack_buffer *b); - -extern void oggpackB_writeinit(oggpack_buffer *b); -extern int oggpackB_writecheck(oggpack_buffer *b); -extern void oggpackB_writetrunc(oggpack_buffer *b, long bits); -extern void oggpackB_writealign(oggpack_buffer *b); -extern void oggpackB_writecopy(oggpack_buffer *b, void *source, long bits); -extern void oggpackB_reset(oggpack_buffer *b); -extern void oggpackB_writeclear(oggpack_buffer *b); -extern void oggpackB_readinit(oggpack_buffer *b, unsigned char *buf, int bytes); -extern void oggpackB_write(oggpack_buffer *b, unsigned long value, int bits); -extern long oggpackB_look(oggpack_buffer *b, int bits); -extern long oggpackB_look1(oggpack_buffer *b); -extern void oggpackB_adv(oggpack_buffer *b, int bits); -extern void oggpackB_adv1(oggpack_buffer *b); -extern long oggpackB_read(oggpack_buffer *b, int bits); -extern long oggpackB_read1(oggpack_buffer *b); -extern long oggpackB_bytes(oggpack_buffer *b); -extern long oggpackB_bits(oggpack_buffer *b); -extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b); - -/* Ogg BITSTREAM PRIMITIVES: encoding **************************/ - -extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op); -extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, - int count, long e_o_s, ogg_int64_t granulepos); -extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og); -extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill); -extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og); -extern int ogg_stream_flush_fill(ogg_stream_state *os, ogg_page *og, int nfill); - -/* Ogg BITSTREAM PRIMITIVES: decoding **************************/ - -extern int ogg_sync_init(ogg_sync_state *oy); -extern int ogg_sync_clear(ogg_sync_state *oy); -extern int ogg_sync_reset(ogg_sync_state *oy); -extern int ogg_sync_destroy(ogg_sync_state *oy); -extern int ogg_sync_check(ogg_sync_state *oy); - -extern char *ogg_sync_buffer(ogg_sync_state *oy, long size); -extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); -extern long ogg_sync_pageseek(ogg_sync_state *oy, ogg_page *og); -extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og); -extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); -extern int ogg_stream_packetout(ogg_stream_state *os, ogg_packet *op); -extern int ogg_stream_packetpeek(ogg_stream_state *os, ogg_packet *op); - -/* Ogg BITSTREAM PRIMITIVES: general ***************************/ - -extern int ogg_stream_init(ogg_stream_state *os, int serialno); -extern int ogg_stream_clear(ogg_stream_state *os); -extern int ogg_stream_reset(ogg_stream_state *os); -extern int ogg_stream_reset_serialno(ogg_stream_state *os, int serialno); -extern int ogg_stream_destroy(ogg_stream_state *os); -extern int ogg_stream_check(ogg_stream_state *os); -extern int ogg_stream_eos(ogg_stream_state *os); - -extern void ogg_page_checksum_set(ogg_page *og); - -extern int ogg_page_version(const ogg_page *og); -extern int ogg_page_continued(const ogg_page *og); -extern int ogg_page_bos(const ogg_page *og); -extern int ogg_page_eos(const ogg_page *og); -extern ogg_int64_t ogg_page_granulepos(const ogg_page *og); -extern int ogg_page_serialno(const ogg_page *og); -extern long ogg_page_pageno(const ogg_page *og); -extern int ogg_page_packets(const ogg_page *og); - -extern void ogg_packet_clear(ogg_packet *op); - - -#ifdef __cplusplus -} -#endif - -#endif /* _OGG_H */ diff --git a/src/libogg/ogg/os_types.h b/src/libogg/ogg/os_types.h deleted file mode 100644 index 108de09..0000000 --- a/src/libogg/ogg/os_types.h +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 - by the Xiph.Org Foundation http://www.xiph.org/ - * * - ******************************************************************** - - function: Define a consistent set of types on each platform. - - ********************************************************************/ -#ifndef _OS_TYPES_H -#define _OS_TYPES_H - -/* make it easy on the folks that want to compile the libs with a - different malloc than stdlib */ -#define _ogg_malloc malloc -#define _ogg_calloc calloc -#define _ogg_realloc realloc -#define _ogg_free free - -#if defined(_WIN32) - -# if defined(__CYGWIN__) -# include -typedef int16_t ogg_int16_t; -typedef uint16_t ogg_uint16_t; -typedef int32_t ogg_int32_t; -typedef uint32_t ogg_uint32_t; -typedef int64_t ogg_int64_t; -typedef uint64_t ogg_uint64_t; -# elif defined(__MINGW32__) -# include -typedef short ogg_int16_t; -typedef unsigned short ogg_uint16_t; -typedef int ogg_int32_t; -typedef unsigned int ogg_uint32_t; -typedef long long ogg_int64_t; -typedef unsigned long long ogg_uint64_t; -# elif defined(__MWERKS__) -typedef long long ogg_int64_t; -typedef unsigned long long ogg_uint64_t; -typedef int ogg_int32_t; -typedef unsigned int ogg_uint32_t; -typedef short ogg_int16_t; -typedef unsigned short ogg_uint16_t; -# else -# if defined(_MSC_VER) && (_MSC_VER >= 1800) /* MSVC 2013 and newer */ -# include -typedef int16_t ogg_int16_t; -typedef uint16_t ogg_uint16_t; -typedef int32_t ogg_int32_t; -typedef uint32_t ogg_uint32_t; -typedef int64_t ogg_int64_t; -typedef uint64_t ogg_uint64_t; -# else -/* MSVC/Borland */ -typedef __int64 ogg_int64_t; -typedef __int32 ogg_int32_t; -typedef unsigned __int32 ogg_uint32_t; -typedef unsigned __int64 ogg_uint64_t; -typedef __int16 ogg_int16_t; -typedef unsigned __int16 ogg_uint16_t; -# endif -# endif - -#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ - -# include -typedef int16_t ogg_int16_t; -typedef uint16_t ogg_uint16_t; -typedef int32_t ogg_int32_t; -typedef uint32_t ogg_uint32_t; -typedef int64_t ogg_int64_t; -typedef uint64_t ogg_uint64_t; - -#elif defined(__HAIKU__) - -/* Haiku */ -# include -typedef short ogg_int16_t; -typedef unsigned short ogg_uint16_t; -typedef int ogg_int32_t; -typedef unsigned int ogg_uint32_t; -typedef long long ogg_int64_t; -typedef unsigned long long ogg_uint64_t; - -#elif defined(__BEOS__) - -/* Be */ -# include -typedef int16_t ogg_int16_t; -typedef uint16_t ogg_uint16_t; -typedef int32_t ogg_int32_t; -typedef uint32_t ogg_uint32_t; -typedef int64_t ogg_int64_t; -typedef uint64_t ogg_uint64_t; - -#elif defined (__EMX__) - -/* OS/2 GCC */ -typedef short ogg_int16_t; -typedef unsigned short ogg_uint16_t; -typedef int ogg_int32_t; -typedef unsigned int ogg_uint32_t; -typedef long long ogg_int64_t; -typedef unsigned long long ogg_uint64_t; - - -#elif defined (DJGPP) - -/* DJGPP */ -typedef short ogg_int16_t; -typedef int ogg_int32_t; -typedef unsigned int ogg_uint32_t; -typedef long long ogg_int64_t; -typedef unsigned long long ogg_uint64_t; - -#elif defined(R5900) - -/* PS2 EE */ -typedef long ogg_int64_t; -typedef unsigned long ogg_uint64_t; -typedef int ogg_int32_t; -typedef unsigned ogg_uint32_t; -typedef short ogg_int16_t; - -#elif defined(__SYMBIAN32__) - -/* Symbian GCC */ -typedef signed short ogg_int16_t; -typedef unsigned short ogg_uint16_t; -typedef signed int ogg_int32_t; -typedef unsigned int ogg_uint32_t; -typedef long long int ogg_int64_t; -typedef unsigned long long int ogg_uint64_t; - -#elif defined(__TMS320C6X__) - -/* TI C64x compiler */ -typedef signed short ogg_int16_t; -typedef unsigned short ogg_uint16_t; -typedef signed int ogg_int32_t; -typedef unsigned int ogg_uint32_t; -typedef long long int ogg_int64_t; -typedef unsigned long long int ogg_uint64_t; - -#else - -# include "config_types.h" - -#endif - -#endif /* _OS_TYPES_H */ diff --git a/src/libopus/COPYING b/src/libopus/COPYING index 9c739c3..7571146 100644 --- a/src/libopus/COPYING +++ b/src/libopus/COPYING @@ -1,7 +1,7 @@ -Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic, +Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic, Jean-Marc Valin, Timothy B. Terriberry, CSIRO, Gregory Maxwell, Mark Borgerding, - Erik de Castro Lopo + Erik de Castro Lopo, Mozilla, Amazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff --git a/src/libopus/ChangeLog b/src/libopus/ChangeLog deleted file mode 100644 index e69de29..0000000 diff --git a/src/libopus/INSTALL b/src/libopus/INSTALL deleted file mode 100644 index 8865734..0000000 --- a/src/libopus/INSTALL +++ /dev/null @@ -1,368 +0,0 @@ -Installation Instructions -************************* - - Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software -Foundation, Inc. - - Copying and distribution of this file, with or without modification, -are permitted in any medium without royalty provided the copyright -notice and this notice are preserved. This file is offered as-is, -without warranty of any kind. - -Basic Installation -================== - - Briefly, the shell command './configure && make && make install' -should configure, build, and install this package. The following -more-detailed instructions are generic; see the 'README' file for -instructions specific to this package. Some packages provide this -'INSTALL' file but do not implement all of the features documented -below. The lack of an optional feature in a given package is not -necessarily a bug. More recommendations for GNU packages can be found -in *note Makefile Conventions: (standards)Makefile Conventions. - - The 'configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a 'Makefile' in each directory of the package. -It may also create one or more '.h' files containing system-dependent -definitions. Finally, it creates a shell script 'config.status' that -you can run in the future to recreate the current configuration, and a -file 'config.log' containing compiler output (useful mainly for -debugging 'configure'). - - It can also use an optional file (typically called 'config.cache' and -enabled with '--cache-file=config.cache' or simply '-C') that saves the -results of its tests to speed up reconfiguring. Caching is disabled by -default to prevent problems with accidental use of stale cache files. - - If you need to do unusual things to compile the package, please try -to figure out how 'configure' could check whether to do them, and mail -diffs or instructions to the address given in the 'README' so they can -be considered for the next release. If you are using the cache, and at -some point 'config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file 'configure.ac' (or 'configure.in') is used to create -'configure' by a program called 'autoconf'. You need 'configure.ac' if -you want to change it or regenerate 'configure' using a newer version of -'autoconf'. - - The simplest way to compile this package is: - - 1. 'cd' to the directory containing the package's source code and type - './configure' to configure the package for your system. - - Running 'configure' might take a while. While running, it prints - some messages telling which features it is checking for. - - 2. Type 'make' to compile the package. - - 3. Optionally, type 'make check' to run any self-tests that come with - the package, generally using the just-built uninstalled binaries. - - 4. Type 'make install' to install the programs and any data files and - documentation. When installing into a prefix owned by root, it is - recommended that the package be configured and built as a regular - user, and only the 'make install' phase executed with root - privileges. - - 5. Optionally, type 'make installcheck' to repeat any self-tests, but - this time using the binaries in their final installed location. - This target does not install anything. Running this target as a - regular user, particularly if the prior 'make install' required - root privileges, verifies that the installation completed - correctly. - - 6. You can remove the program binaries and object files from the - source code directory by typing 'make clean'. To also remove the - files that 'configure' created (so you can compile the package for - a different kind of computer), type 'make distclean'. There is - also a 'make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - - 7. Often, you can also type 'make uninstall' to remove the installed - files again. In practice, not all packages have tested that - uninstallation works correctly, even though it is required by the - GNU Coding Standards. - - 8. Some packages, particularly those that use Automake, provide 'make - distcheck', which can by used by developers to test that all other - targets like 'make install' and 'make uninstall' work correctly. - This target is generally not run by end users. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the 'configure' script does not know about. Run './configure --help' -for details on some of the pertinent environment variables. - - You can give 'configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here is -an example: - - ./configure CC=c99 CFLAGS=-g LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU 'make'. 'cd' to the -directory where you want the object files and executables to go and run -the 'configure' script. 'configure' automatically checks for the source -code in the directory that 'configure' is in and in '..'. This is known -as a "VPATH" build. - - With a non-GNU 'make', it is safer to compile the package for one -architecture at a time in the source code directory. After you have -installed the package for one architecture, use 'make distclean' before -reconfiguring for another architecture. - - On MacOS X 10.5 and later systems, you can create libraries and -executables that work on multiple system types--known as "fat" or -"universal" binaries--by specifying multiple '-arch' options to the -compiler but only a single '-arch' option to the preprocessor. Like -this: - - ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CPP="gcc -E" CXXCPP="g++ -E" - - This is not guaranteed to produce working output in all cases, you -may have to build one architecture at a time and combine the results -using the 'lipo' tool if you have problems. - -Installation Names -================== - - By default, 'make install' installs the package's commands under -'/usr/local/bin', include files under '/usr/local/include', etc. You -can specify an installation prefix other than '/usr/local' by giving -'configure' the option '--prefix=PREFIX', where PREFIX must be an -absolute file name. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -pass the option '--exec-prefix=PREFIX' to 'configure', the package uses -PREFIX as the prefix for installing programs and libraries. -Documentation and other data files still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like '--bindir=DIR' to specify different values for particular -kinds of files. Run 'configure --help' for a list of the directories -you can set and what kinds of files go in them. In general, the default -for these options is expressed in terms of '${prefix}', so that -specifying just '--prefix' will affect all of the other directory -specifications that were not explicitly provided. - - The most portable way to affect installation locations is to pass the -correct locations to 'configure'; however, many packages provide one or -both of the following shortcuts of passing variable assignments to the -'make install' command line to change installation locations without -having to reconfigure or recompile. - - The first method involves providing an override variable for each -affected directory. For example, 'make install -prefix=/alternate/directory' will choose an alternate location for all -directory configuration variables that were expressed in terms of -'${prefix}'. Any directories that were specified during 'configure', -but not in terms of '${prefix}', must each be overridden at install time -for the entire installation to be relocated. The approach of makefile -variable overrides for each directory variable is required by the GNU -Coding Standards, and ideally causes no recompilation. However, some -platforms have known limitations with the semantics of shared libraries -that end up requiring recompilation when using this method, particularly -noticeable in packages that use GNU Libtool. - - The second method involves providing the 'DESTDIR' variable. For -example, 'make install DESTDIR=/alternate/directory' will prepend -'/alternate/directory' before all installation names. The approach of -'DESTDIR' overrides is not required by the GNU Coding Standards, and -does not work on platforms that have drive letters. On the other hand, -it does better at avoiding recompilation issues, and works well even -when some directory options were not specified in terms of '${prefix}' -at 'configure' time. - -Optional Features -================= - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving 'configure' the -option '--program-prefix=PREFIX' or '--program-suffix=SUFFIX'. - - Some packages pay attention to '--enable-FEATURE' options to -'configure', where FEATURE indicates an optional part of the package. -They may also pay attention to '--with-PACKAGE' options, where PACKAGE -is something like 'gnu-as' or 'x' (for the X Window System). The -'README' should mention any '--enable-' and '--with-' options that the -package recognizes. - - For packages that use the X Window System, 'configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the 'configure' options '--x-includes=DIR' and -'--x-libraries=DIR' to specify their locations. - - Some packages offer the ability to configure how verbose the -execution of 'make' will be. For these packages, running './configure ---enable-silent-rules' sets the default to minimal output, which can be -overridden with 'make V=1'; while running './configure ---disable-silent-rules' sets the default to verbose, which can be -overridden with 'make V=0'. - -Particular systems -================== - - On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC -is not installed, it is recommended to use the following options in -order to use an ANSI C compiler: - - ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" - -and if that doesn't work, install pre-built binaries of GCC for HP-UX. - - HP-UX 'make' updates targets which have the same time stamps as their -prerequisites, which makes it generally unusable when shipped generated -files such as 'configure' are involved. Use GNU 'make' instead. - - On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot -parse its '' header file. The option '-nodtk' can be used as a -workaround. If GNU CC is not installed, it is therefore recommended to -try - - ./configure CC="cc" - -and if that doesn't work, try - - ./configure CC="cc -nodtk" - - On Solaris, don't put '/usr/ucb' early in your 'PATH'. This -directory contains several dysfunctional programs; working variants of -these programs are available in '/usr/bin'. So, if you need '/usr/ucb' -in your 'PATH', put it _after_ '/usr/bin'. - - On Haiku, software installed for all users goes in '/boot/common', -not '/usr/local'. It is recommended to use the following options: - - ./configure --prefix=/boot/common - -Specifying the System Type -========================== - - There may be some features 'configure' cannot figure out -automatically, but needs to determine by the type of machine the package -will run on. Usually, assuming the package is built to be run on the -_same_ architectures, 'configure' can figure that out, but if it prints -a message saying it cannot guess the machine type, give it the -'--build=TYPE' option. TYPE can either be a short name for the system -type, such as 'sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS - KERNEL-OS - - See the file 'config.sub' for the possible values of each field. If -'config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the option '--target=TYPE' to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with '--host=TYPE'. - -Sharing Defaults -================ - - If you want to set default values for 'configure' scripts to share, -you can create a site shell script called 'config.site' that gives -default values for variables like 'CC', 'cache_file', and 'prefix'. -'configure' looks for 'PREFIX/share/config.site' if it exists, then -'PREFIX/etc/config.site' if it exists. Or, you can set the -'CONFIG_SITE' environment variable to the location of the site script. -A warning: not all 'configure' scripts look for a site script. - -Defining Variables -================== - - Variables not defined in a site shell script can be set in the -environment passed to 'configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the 'configure' command line, using 'VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -causes the specified 'gcc' to be used as the C compiler (unless it is -overridden in the site shell script). - -Unfortunately, this technique does not work for 'CONFIG_SHELL' due to an -Autoconf limitation. Until the limitation is lifted, you can use this -workaround: - - CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash - -'configure' Invocation -====================== - - 'configure' recognizes the following options to control how it -operates. - -'--help' -'-h' - Print a summary of all of the options to 'configure', and exit. - -'--help=short' -'--help=recursive' - Print a summary of the options unique to this package's - 'configure', and exit. The 'short' variant lists options used only - in the top level, while the 'recursive' variant lists options also - present in any nested packages. - -'--version' -'-V' - Print the version of Autoconf used to generate the 'configure' - script, and exit. - -'--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally 'config.cache'. FILE defaults to '/dev/null' to - disable caching. - -'--config-cache' -'-C' - Alias for '--cache-file=config.cache'. - -'--quiet' -'--silent' -'-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to '/dev/null' (any error - messages will still be shown). - -'--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - 'configure' can determine that directory automatically. - -'--prefix=DIR' - Use DIR as the installation prefix. *note Installation Names:: for - more details, including other options available for fine-tuning the - installation locations. - -'--no-create' -'-n' - Run the configure checks, but stop before creating any output - files. - -'configure' also accepts some other, not widely useful, options. Run -'configure --help' for more details. diff --git a/src/libopus/LICENSE_PLEASE_READ.txt b/src/libopus/LICENSE_PLEASE_READ.txt new file mode 100644 index 0000000..bc88efa --- /dev/null +++ b/src/libopus/LICENSE_PLEASE_READ.txt @@ -0,0 +1,22 @@ +Contributions to the collaboration shall not be considered confidential. + +Each contributor represents and warrants that it has the right and +authority to license copyright in its contributions to the collaboration. + +Each contributor agrees to license the copyright in the contributions +under the Modified (2-clause or 3-clause) BSD License or the Clear BSD License. + +Please see the IPR statements submitted to the IETF for the complete +patent licensing details: + +Xiph.Org Foundation: +https://datatracker.ietf.org/ipr/1524/ + +Microsoft Corporation: +https://datatracker.ietf.org/ipr/1914/ + +Skype Limited: +https://datatracker.ietf.org/ipr/1602/ + +Broadcom Corporation: +https://datatracker.ietf.org/ipr/1526/ diff --git a/src/libopus/NEWS b/src/libopus/NEWS deleted file mode 100644 index e69de29..0000000 diff --git a/src/libopus/README b/src/libopus/README index 27fddf9..bcf2376 100644 --- a/src/libopus/README +++ b/src/libopus/README @@ -22,7 +22,7 @@ This package implements a shared library for encoding and decoding raw Opus bitstreams. Raw Opus bitstreams should be used over RTP according to https://tools.ietf.org/html/rfc7587 -The package also includes a number of test tools used for testing the +The package also includes a number of test tools used for testing the correct operation of the library. The bitstreams read/written by these tools should not be used for Opus file distribution: They include additional debugging data and cannot support seeking. @@ -35,10 +35,32 @@ An opus-tools package is available which provides encoding and decoding of Ogg encapsulated Opus files and includes a number of useful features. Opus-tools can be found at: - https://git.xiph.org/?p=opus-tools.git + https://gitlab.xiph.org/xiph/opus-tools.git or on the main Opus website: https://opus-codec.org/ +== Deep Learning and Opus == + +Lossy networks continue to be a challenge for real-time communications. +While the original implementation of Opus provides an excellent packet loss +concealment mechanism, the team has continued to advance the methodology used +to improve audio quality in challenge network environments. + +In Opus 1.5, we added a deep learning based redundancy encoder that enhances +audio in lossy networks by embedding one second of recovery data in the padding +data of each packet. The underlying algorithm behind encoding and decoding the +recovery data is called the deep redundancy (DRED) algorithm. By leveraging +the padding data within the packet, Opus 1.5 is fully backward compatible with +prior revisions of Opus. Please see the README under the "dnn" subdirectory to +understand DRED. + +DRED was developed by a team that Amazon Web Services initially sponsored, +who open-sourced the implementation as well as began the +standardization process at the IETF: + https://datatracker.ietf.org/doc/draft-ietf-mlcodec-opus-extension/ +The license behind Opus or the intellectual property position of Opus does +not change with Opus 1.5. + == Compiling libopus == To build from a distribution tarball, you only need to do the following: @@ -68,7 +90,7 @@ On Apple macOS, install Xcode and brew.sh, then in the Terminal enter: 1) Clone the repository: - % git clone https://git.xiph.org/opus.git + % git clone https://gitlab.xiph.org/xiph/opus.git % cd opus 2) Compiling the source @@ -77,6 +99,8 @@ On Apple macOS, install Xcode and brew.sh, then in the Terminal enter: % ./configure % make +On x86, it's a good idea to use a -march= option that allows the use of AVX2. + 3) Install the codec libraries (optional) % sudo make install @@ -133,6 +157,10 @@ To run compare the code to these test vectors: % tar -zxf opus_testvectors-rfc8251.tar.gz % ./tests/run_vectors.sh ./ opus_newvectors 48000 +== Compiling libopus for Windows and alternative build systems == + +See cmake/README.md or meson/README.md. + == Portability notes == This implementation uses floating-point by default but can be compiled to diff --git a/src/libopus/analysis.h b/src/libopus/analysis.h deleted file mode 100644 index 9f940ca..0000000 --- a/src/libopus/analysis.h +++ /dev/null @@ -1,103 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef ANALYSIS_H -#define ANALYSIS_H - -#include "celt/celt.h" -#include "opus_private.h" -#include "mlp.h" - -#define NB_FRAMES 8 -#define NB_TBANDS 18 -#define ANALYSIS_BUF_SIZE 720 /* 30 ms at 24 kHz */ - -/* At that point we can stop counting frames because it no longer matters. */ -#define ANALYSIS_COUNT_MAX 10000 - -#define DETECT_SIZE 100 - -/* Uncomment this to print the MLP features on stdout. */ -/*#define MLP_TRAINING*/ - -typedef struct { - int arch; - int application; - opus_int32 Fs; -#define TONALITY_ANALYSIS_RESET_START angle - float angle[240]; - float d_angle[240]; - float d2_angle[240]; - opus_val32 inmem[ANALYSIS_BUF_SIZE]; - int mem_fill; /* number of usable samples in the buffer */ - float prev_band_tonality[NB_TBANDS]; - float prev_tonality; - int prev_bandwidth; - float E[NB_FRAMES][NB_TBANDS]; - float logE[NB_FRAMES][NB_TBANDS]; - float lowE[NB_TBANDS]; - float highE[NB_TBANDS]; - float meanE[NB_TBANDS + 1]; - float mem[32]; - float cmean[8]; - float std[9]; - float Etracker; - float lowECount; - int E_count; - int count; - int analysis_offset; - int write_pos; - int read_pos; - int read_subframe; - float hp_ener_accum; - int initialized; - float rnn_state[MAX_NEURONS]; - opus_val32 downmix_state[3]; - AnalysisInfo info[DETECT_SIZE]; -} TonalityAnalysisState; - -/** Initialize a TonalityAnalysisState struct. - - This performs some possibly slow initialization steps which should - not be repeated every analysis step. No allocated memory is retained - by the state struct, so no cleanup call is required. -*/ -void tonality_analysis_init(TonalityAnalysisState *analysis, opus_int32 Fs); - -/** Reset a TonalityAnalysisState stuct. - - Call this when there's a discontinuity in the data. -*/ -void tonality_analysis_reset(TonalityAnalysisState *analysis); - -void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len); - -void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, const void *analysis_pcm, - int analysis_frame_size, int frame_size, int c1, int c2, int C, opus_int32 Fs, - int lsb_depth, downmix_func downmix, AnalysisInfo *analysis_info); - -#endif diff --git a/src/libopus/celt/_kiss_fft_guts.h b/src/libopus/celt/_kiss_fft_guts.h index 351bcd1..17392b3 100644 --- a/src/libopus/celt/_kiss_fft_guts.h +++ b/src/libopus/celt/_kiss_fft_guts.h @@ -1,27 +1,27 @@ -/* Copyright (c) 2003-2004, Mark Borgerding +/*Copyright (c) 2003-2004, Mark Borgerding - All rights reserved. + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE.*/ + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE.*/ #ifndef KISS_FFT_GUTS_H #define KISS_FFT_GUTS_H @@ -29,20 +29,20 @@ #define MIN(a,b) ((a)<(b) ? (a):(b)) #define MAX(a,b) ((a)>(b) ? (a):(b)) -/* kiss_fft.h - defines kiss_fft_scalar as either short or a float type - and defines - typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ +/* kiss_fft.h + defines kiss_fft_scalar as either short or a float type + and defines + typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ #include "kiss_fft.h" /* - Explanation of macros dealing with complex math: + Explanation of macros dealing with complex math: - C_MUL(m,a,b) : m = a*b - C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise - C_SUB( res, a,b) : res = a - b - C_SUBFROM( res , a) : res -= a - C_ADDTO( res , a) : res += a + C_MUL(m,a,b) : m = a*b + C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise + C_SUB( res, a,b) : res = a - b + C_SUBFROM( res , a) : res -= a + C_ADDTO( res , a) : res += a * */ #ifdef FIXED_POINT #include "arch.h" @@ -152,8 +152,8 @@ #endif /* C_ADD defined */ #ifdef FIXED_POINT -/* # define KISS_FFT_COS(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase)))) - # define KISS_FFT_SIN(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase))))*/ +/*# define KISS_FFT_COS(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase)))) +# define KISS_FFT_SIN(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase))))*/ # define KISS_FFT_COS(phase) floor(.5+TWID_MAX*cos (phase)) # define KISS_FFT_SIN(phase) floor(.5+TWID_MAX*sin (phase)) # define HALF_OF(x) ((x)>>1) diff --git a/src/libopus/celt/arch.h b/src/libopus/celt/arch.h index 324aa94..3845c3a 100644 --- a/src/libopus/celt/arch.h +++ b/src/libopus/celt/arch.h @@ -1,41 +1,41 @@ -/* Copyright (c) 2003-2008 Jean-Marc Valin - Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2003-2008 Jean-Marc Valin + Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /** - @file arch.h - @brief Various architecture definitions for CELT + @file arch.h + @brief Various architecture definitions for CELT */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef ARCH_H #define ARCH_H -#include "../opus_types.h" -#include "../opus_defines.h" +#include "opus_types.h" +#include "opus_defines.h" # if !defined(__GNUC_PREREQ) # if defined(__GNUC__)&&defined(__GNUC_MINOR__) @@ -70,9 +70,13 @@ void celt_fatal(const char *str, const char *file, int line); #ifdef __GNUC__ __attribute__((noreturn)) #endif -void celt_fatal(const char *str, const char *file, int line) { - fprintf(stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); - abort(); +void celt_fatal(const char *str, const char *file, int line) +{ + fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); +#if defined(_MSC_VER) + _set_abort_behavior( 0, _WRITE_ABORT_MSG); +#endif + abort(); } #endif @@ -103,8 +107,8 @@ void celt_fatal(const char *str, const char *file, int line) { #define USUB32(a,b) ((a)-(b)) /* Set this if opus_int64 is a native type of the CPU. */ -/* Assume that all LP64 architectures have fast 64-bit types; also x86_64 - (which can be ILP32 for x32) and Win64 (which is LLP64). */ +/* Assume that all LP64 architectures have fast 64-bit types; also x86_64 + (which can be ILP32 for x32) and Win64 (which is LLP64). */ #if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64) #define OPUS_FAST_INT64 1 #else @@ -128,8 +132,8 @@ typedef opus_val32 celt_ener; #define Q15ONE 32767 #define SIG_SHIFT 12 -/* Safe saturation value for 32-bit signals. Should be less than - 2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/ +/* Safe saturation value for 32-bit signals. Should be less than + 2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/ #define SIG_SAT (300000000) #define NORM_SCALING 16384 @@ -148,7 +152,7 @@ typedef opus_val32 celt_ener; #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) static OPUS_INLINE opus_int16 SAT16(opus_int32 x) { - return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x; + return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x; } #ifdef FIXED_DEBUG @@ -184,15 +188,13 @@ typedef float celt_norm; typedef float celt_ener; #ifdef FLOAT_APPROX -/* This code should reliably detect NaN/inf even when -ffast-math is used. - Assumes IEEE 754 format. */ -static OPUS_INLINE int celt_isnan(float x) { - union { - float f; - opus_uint32 i; - } in; - in.f = x; - return ((in.i >> 23) & 0xFF) == 0xFF && (in.i & 0x007FFFFF) != 0; +/* This code should reliably detect NaN/inf even when -ffast-math is used. + Assumes IEEE 754 format. */ +static OPUS_INLINE int celt_isnan(float x) +{ + union {float f; opus_uint32 i;} in; + in.f = x; + return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0; } #else #ifdef __FAST_MATH__ diff --git a/src/libopus/celt/bands.c b/src/libopus/celt/bands.c index e240aa5..979a13b 100644 --- a/src/libopus/celt/bands.c +++ b/src/libopus/celt/bands.c @@ -1,35 +1,35 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2008-2009 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2008-2009 Gregory Maxwell + Written by Jean-Marc Valin and Gregory Maxwell */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include #include "bands.h" @@ -43,1590 +43,1631 @@ #include "quant_bands.h" #include "pitch.h" -int hysteresis_decision(opus_val16 val, const opus_val16 *thresholds, const opus_val16 *hysteresis, int N, int prev) { - int i; - for (i = 0; i < N; i++) { - if (val < thresholds[i]) { - break; - } - } - if (i > prev && val < thresholds[prev] + hysteresis[prev]) { - i = prev; - } - if (i < prev && val > thresholds[prev - 1] - hysteresis[prev - 1]) { - i = prev; - } - return i; +int hysteresis_decision(opus_val16 val, const opus_val16 *thresholds, const opus_val16 *hysteresis, int N, int prev) +{ + int i; + for (i=0;iprev && val < thresholds[prev]+hysteresis[prev]) + i=prev; + if (i thresholds[prev-1]-hysteresis[prev-1]) + i=prev; + return i; } -opus_uint32 celt_lcg_rand(opus_uint32 seed) { - return 1664525 * seed + 1013904223; +opus_uint32 celt_lcg_rand(opus_uint32 seed) +{ + return 1664525 * seed + 1013904223; } -/* This is a cos() approximation designed to be bit-exact on any platform. Bit exactness - with this approximation is important because it has an impact on the bit allocation */ -opus_int16 bitexact_cos(opus_int16 x) { - opus_int32 tmp; - opus_int16 x2; - tmp = (4096 + ((opus_int32)(x) * (x))) >> 13; - celt_sig_assert(tmp <= 32767); - x2 = tmp; - x2 = (32767 - x2) + FRAC_MUL16(x2, (-7651 + FRAC_MUL16(x2, (8277 + FRAC_MUL16(-626, x2))))); - celt_sig_assert(x2 <= 32766); - return 1 + x2; +/* This is a cos() approximation designed to be bit-exact on any platform. Bit exactness + with this approximation is important because it has an impact on the bit allocation */ +opus_int16 bitexact_cos(opus_int16 x) +{ + opus_int32 tmp; + opus_int16 x2; + tmp = (4096+((opus_int32)(x)*(x)))>>13; + celt_sig_assert(tmp<=32767); + x2 = tmp; + x2 = (32767-x2) + FRAC_MUL16(x2, (-7651 + FRAC_MUL16(x2, (8277 + FRAC_MUL16(-626, x2))))); + celt_sig_assert(x2<=32766); + return 1+x2; } -int bitexact_log2tan(int isin, int icos) { - int lc; - int ls; - lc = EC_ILOG(icos); - ls = EC_ILOG(isin); - icos <<= 15 - lc; - isin <<= 15 - ls; - return (ls - lc) * (1 << 11) - + FRAC_MUL16(isin, FRAC_MUL16(isin, -2597) + 7932) - - FRAC_MUL16(icos, FRAC_MUL16(icos, -2597) + 7932); +int bitexact_log2tan(int isin,int icos) +{ + int lc; + int ls; + lc=EC_ILOG(icos); + ls=EC_ILOG(isin); + icos<<=15-lc; + isin<<=15-ls; + return (ls-lc)*(1<<11) + +FRAC_MUL16(isin, FRAC_MUL16(isin, -2597) + 7932) + -FRAC_MUL16(icos, FRAC_MUL16(icos, -2597) + 7932); } #ifdef FIXED_POINT /* Compute the amplitude (sqrt energy) in each of the bands */ -void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch) { - int i, c, N; - const opus_int16 *eBands = m->eBands; - (void)arch; - N = m->shortMdctSize << LM; - c = 0; do { - for (i = 0; i < end; i++) { - int j; - opus_val32 maxval = 0; - opus_val32 sum = 0; +void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch) +{ + int i, c, N; + const opus_int16 *eBands = m->eBands; + (void)arch; + N = m->shortMdctSize< 0) { - int shift = celt_ilog2(maxval) - 14 + (((m->logN[i] >> BITRES) + LM + 1) >> 1); - j = eBands[i] << LM; - if (shift > 0) { - do { - sum = MAC16_16(sum, EXTRACT16(SHR32(X[j + c * N], shift)), - EXTRACT16(SHR32(X[j + c * N], shift))); - } while (++j < eBands[i + 1] << LM); - } else { - do { - sum = MAC16_16(sum, EXTRACT16(SHL32(X[j + c * N], -shift)), - EXTRACT16(SHL32(X[j + c * N], -shift))); - } while (++j < eBands[i + 1] << LM); - } - /* We're adding one here to ensure the normalized band isn't larger than unity norm */ - bandE[i + c * m->nbEBands] = EPSILON + VSHR32(EXTEND32(celt_sqrt(sum)), -shift); + maxval = celt_maxabs32(&X[c*N+(eBands[i]< 0) + { + int shift = celt_ilog2(maxval) - 14 + (((m->logN[i]>>BITRES)+LM+1)>>1); + j=eBands[i]<0) + { + do { + sum = MAC16_16(sum, EXTRACT16(SHR32(X[j+c*N],shift)), + EXTRACT16(SHR32(X[j+c*N],shift))); + } while (++jnbEBands] = EPSILON; + do { + sum = MAC16_16(sum, EXTRACT16(SHL32(X[j+c*N],-shift)), + EXTRACT16(SHL32(X[j+c*N],-shift))); + } while (++jnbEBands]);*/ - } - } while (++c < C); - /*printf ("\n");*/ + /* We're adding one here to ensure the normalized band isn't larger than unity norm */ + bandE[i+c*m->nbEBands] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-shift); + } else { + bandE[i+c*m->nbEBands] = EPSILON; + } + /*printf ("%f ", bandE[i+c*m->nbEBands]);*/ + } + } while (++ceBands; - N = M * m->shortMdctSize; - c = 0; do { - i = 0; do { - opus_val16 g; - int j, shift; - opus_val16 E; - shift = celt_zlog2(bandE[i + c * m->nbEBands]) - 13; - E = VSHR32(bandE[i + c * m->nbEBands], shift); - g = EXTRACT16(celt_rcp(SHL32(E, 3))); - j = M * eBands[i]; do { - X[j + c * N] = MULT16_16_Q15(VSHR32(freq[j + c * N], shift - 1), g); - } while (++j < M * eBands[i + 1]); - } while (++i < end); - } while (++c < C); +void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, celt_norm * OPUS_RESTRICT X, const celt_ener *bandE, int end, int C, int M) +{ + int i, c, N; + const opus_int16 *eBands = m->eBands; + N = M*m->shortMdctSize; + c=0; do { + i=0; do { + opus_val16 g; + int j,shift; + opus_val16 E; + shift = celt_zlog2(bandE[i+c*m->nbEBands])-13; + E = VSHR32(bandE[i+c*m->nbEBands], shift); + g = EXTRACT16(celt_rcp(SHL32(E,3))); + j=M*eBands[i]; do { + X[j+c*N] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g); + } while (++jeBands; - N = m->shortMdctSize << LM; - c = 0; do { - for (i = 0; i < end; i++) { - opus_val32 sum; - sum = 1e-27f + celt_inner_prod(&X[c * N + (eBands[i] << LM)], &X[c * N + (eBands[i] << LM)], (eBands[i + 1] - eBands[i]) << LM, arch); - bandE[i + c * m->nbEBands] = celt_sqrt(sum); - /*printf ("%f ", bandE[i+c*m->nbEBands]);*/ - } - } while (++c < C); - /*printf ("\n");*/ +void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch) +{ + int i, c, N; + const opus_int16 *eBands = m->eBands; + N = m->shortMdctSize<nbEBands] = celt_sqrt(sum); + /*printf ("%f ", bandE[i+c*m->nbEBands]);*/ + } + } while (++ceBands; - N = M * m->shortMdctSize; - c = 0; do { - for (i = 0; i < end; i++) { - int j; - opus_val16 g = 1.f / (1e-27f + bandE[i + c * m->nbEBands]); - for (j = M * eBands[i]; j < M * eBands[i + 1]; j++) { - X[j + c * N] = freq[j + c * N] * g; - } - } - } while (++c < C); +void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, celt_norm * OPUS_RESTRICT X, const celt_ener *bandE, int end, int C, int M) +{ + int i, c, N; + const opus_int16 *eBands = m->eBands; + N = M*m->shortMdctSize; + c=0; do { + for (i=0;inbEBands]); + for (j=M*eBands[i];jeBands; - N = M * m->shortMdctSize; - bound = M * eBands[end]; - if (downsample != 1) { - bound = IMIN(bound, N / downsample); - } - if (silence) { - bound = 0; - start = end = 0; - } - f = freq; - x = X + M * eBands[start]; - for (i = 0; i < M * eBands[start]; i++) { - *f++ = 0; - } - for (i = start; i < end; i++) { - int j, band_end; - opus_val16 g; - opus_val16 lg; + celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandLogE, int start, + int end, int M, int downsample, int silence) +{ + int i, N; + int bound; + celt_sig * OPUS_RESTRICT f; + const celt_norm * OPUS_RESTRICT x; + const opus_int16 *eBands = m->eBands; + N = M*m->shortMdctSize; + bound = M*eBands[end]; + if (downsample!=1) + bound = IMIN(bound, N/downsample); + if (silence) + { + bound = 0; + start = end = 0; + } + f = freq; + x = X+M*eBands[start]; + for (i=0;i> DB_SHIFT); - if (shift > 31) { - shift = 0; - g = 0; - } else { - /* Handle the fractional part. */ - g = celt_exp2_frac(lg & ((1 << DB_SHIFT) - 1)); - } - /* Handle extreme gains with negative shift. */ - if (shift < 0) { - /* For shift <= -2 and g > 16384 we'd be likely to overflow, so we're - capping the gain here, which is equivalent to a cap of 18 on lg. - This shouldn't trigger unless the bitstream is already corrupted. */ - if (shift <= -2) { - g = 16384; - shift = -2; - } - do { - *f++ = SHL32(MULT16_16(*x++, g), -shift); - } while (++j < band_end); - } else + /* Handle the integer part of the log energy */ + shift = 16-(lg>>DB_SHIFT); + if (shift>31) + { + shift=0; + g=0; + } else { + /* Handle the fractional part. */ + g = celt_exp2_frac(lg&((1< 16384 we'd be likely to overflow, so we're + capping the gain here, which is equivalent to a cap of 18 on lg. + This shouldn't trigger unless the bitstream is already corrupted. */ + if (shift <= -2) + { + g = 16384; + shift = -2; + } + do { + *f++ = SHL32(MULT16_16(*x++, g), -shift); + } while (++jeBands[i + 1] - m->eBands[i]; - /* depth in 1/8 bits */ - celt_sig_assert(pulses[i] >= 0); - depth = celt_udiv(1 + pulses[i], (m->eBands[i + 1] - m->eBands[i])) >> LM; + N0 = m->eBands[i+1]-m->eBands[i]; + /* depth in 1/8 bits */ + celt_sig_assert(pulses[i]>=0); + depth = celt_udiv(1+pulses[i], (m->eBands[i+1]-m->eBands[i]))>>LM; #ifdef FIXED_POINT - thresh32 = SHR32(celt_exp2(-SHL16(depth, 10 - BITRES)), 1); - thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767, thresh32)); - { - opus_val32 t; - t = N0 << LM; - shift = celt_ilog2(t) >> 1; - t = SHL32(t, (7 - shift) << 1); - sqrt_1 = celt_rsqrt_norm(t); - } + thresh32 = SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1); + thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,thresh32)); + { + opus_val32 t; + t = N0<>1; + t = SHL32(t, (7-shift)<<1); + sqrt_1 = celt_rsqrt_norm(t); + } #else - thresh = .5f * celt_exp2(-.125f * depth); - sqrt_1 = celt_rsqrt(N0 << LM); + thresh = .5f*celt_exp2(-.125f*depth); + sqrt_1 = celt_rsqrt(N0<nbEBands + i]; - prev2 = prev2logE[c * m->nbEBands + i]; - if (C == 1) { - prev1 = MAX16(prev1, prev1logE[m->nbEBands + i]); - prev2 = MAX16(prev2, prev2logE[m->nbEBands + i]); - } - Ediff = EXTEND32(logE[c * m->nbEBands + i]) - EXTEND32(MIN16(prev1, prev2)); - Ediff = MAX32(0, Ediff); + c=0; do + { + celt_norm *X; + opus_val16 prev1; + opus_val16 prev2; + opus_val32 Ediff; + opus_val16 r; + int renormalize=0; + prev1 = prev1logE[c*m->nbEBands+i]; + prev2 = prev2logE[c*m->nbEBands+i]; + if (C==1) + { + prev1 = MAX16(prev1,prev1logE[m->nbEBands+i]); + prev2 = MAX16(prev2,prev2logE[m->nbEBands+i]); + } + Ediff = EXTEND32(logE[c*m->nbEBands+i])-EXTEND32(MIN16(prev1,prev2)); + Ediff = MAX32(0, Ediff); #ifdef FIXED_POINT - if (Ediff < 16384) { - opus_val32 r32 = SHR32(celt_exp2(-EXTRACT16(Ediff)), 1); - r = 2 * MIN16(16383, r32); - } else { - r = 0; - } - if (LM == 3) { - r = MULT16_16_Q14(23170, MIN32(23169, r)); - } - r = SHR16(MIN16(thresh, r), 1); - r = SHR32(MULT16_16_Q15(sqrt_1, r), shift); + if (Ediff < 16384) + { + opus_val32 r32 = SHR32(celt_exp2(-EXTRACT16(Ediff)),1); + r = 2*MIN16(16383,r32); + } else { + r = 0; + } + if (LM==3) + r = MULT16_16_Q14(23170, MIN32(23169, r)); + r = SHR16(MIN16(thresh, r),1); + r = SHR32(MULT16_16_Q15(sqrt_1, r),shift); #else - /* r needs to be multiplied by 2 or 2*sqrt(2) depending on LM because - short blocks don't have the same energy as long */ - r = 2.f * celt_exp2(-Ediff); - if (LM == 3) { - r *= 1.41421356f; + /* r needs to be multiplied by 2 or 2*sqrt(2) depending on LM because + short blocks don't have the same energy as long */ + r = 2.f*celt_exp2(-Ediff); + if (LM==3) + r *= 1.41421356f; + r = MIN16(thresh, r); + r = r*sqrt_1; +#endif + X = X_+c*size+(m->eBands[i]<eBands[i] << LM); - for (k = 0; k < 1 << LM; k++) { - /* Detect collapse */ - if (!(collapse_masks[i * C + c] & 1 << k)) { - /* Fill with noise */ - for (j = 0; j < N0; j++) { - seed = celt_lcg_rand(seed); - X[(j << LM) + k] = (seed & 0x8000 ? r : -r); - } - renormalize = 1; - } - } - /* We just added some energy, so we need to renormalise */ - if (renormalize) { - renormalise_vector(X, N0 << LM, Q15ONE, arch); - } - } while (++c < C); - } + } + /* We just added some energy, so we need to renormalise */ + if (renormalize) + renormalise_vector(X, N0<nbEBands])) - 13; + int shift = celt_zlog2(MAX32(bandE[i], bandE[i+m->nbEBands]))-13; #endif - left = VSHR32(bandE[i], shift); - right = VSHR32(bandE[i + m->nbEBands], shift); - norm = EPSILON + celt_sqrt(EPSILON + MULT16_16(left, left) + MULT16_16(right, right)); - a1 = DIV32_16(SHL32(EXTEND32(left), 14), norm); - a2 = DIV32_16(SHL32(EXTEND32(right), 14), norm); - for (j = 0; j < N; j++) { - celt_norm r, l; - l = X[j]; - r = Y[j]; - X[j] = EXTRACT16(SHR32(MAC16_16(MULT16_16(a1, l), a2, r), 14)); - /* Side is not encoded, no need to calculate */ - } + left = VSHR32(bandE[i],shift); + right = VSHR32(bandE[i+m->nbEBands],shift); + norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right)); + a1 = DIV32_16(SHL32(EXTEND32(left),14),norm); + a2 = DIV32_16(SHL32(EXTEND32(right),14),norm); + for (j=0;j> 1; - kr = celt_ilog2(Er) >> 1; + kl = celt_ilog2(El)>>1; + kr = celt_ilog2(Er)>>1; #endif - t = VSHR32(El, (kl - 7) << 1); - lgain = celt_rsqrt_norm(t); - t = VSHR32(Er, (kr - 7) << 1); - rgain = celt_rsqrt_norm(t); + t = VSHR32(El, (kl-7)<<1); + lgain = celt_rsqrt_norm(t); + t = VSHR32(Er, (kr-7)<<1); + rgain = celt_rsqrt_norm(t); #ifdef FIXED_POINT - if (kl < 7) { - kl = 7; - } - if (kr < 7) { - kr = 7; - } + if (kl < 7) + kl = 7; + if (kr < 7) + kr = 7; #endif - for (j = 0; j < N; j++) { - celt_norm r, l; - /* Apply mid scaling (side is already scaled) */ - l = MULT16_16_P15(mid, X[j]); - r = Y[j]; - X[j] = EXTRACT16(PSHR32(MULT16_16(lgain, SUB16(l, r)), kl + 1)); - Y[j] = EXTRACT16(PSHR32(MULT16_16(rgain, ADD16(l, r)), kr + 1)); - } + for (j=0;jeBands; - int decision; - int hf_sum = 0; + int last_decision, int *hf_average, int *tapset_decision, int update_hf, + int end, int C, int M, const int *spread_weight) +{ + int i, c, N0; + int sum = 0, nbBands=0; + const opus_int16 * OPUS_RESTRICT eBands = m->eBands; + int decision; + int hf_sum=0; - celt_assert(end > 0); + celt_assert(end>0); - N0 = M * m->shortMdctSize; + N0 = M*m->shortMdctSize; - if (M * (eBands[end] - eBands[end - 1]) <= 8) { - return SPREAD_NONE; - } - c = 0; do { - for (i = 0; i < end; i++) { - int j, N, tmp = 0; - int tcount[3] = {0, 0, 0}; - const celt_norm * OPUS_RESTRICT x = X + M * eBands[i] + c * N0; - N = M * (eBands[i + 1] - eBands[i]); - if (N <= 8) { - continue; - } - /* Compute rough CDF of |x[j]| */ - for (j = 0; j < N; j++) { - opus_val32 x2N; /* Q13 */ + if (M*(eBands[end]-eBands[end-1]) <= 8) + return SPREAD_NONE; + c=0; do { + for (i=0;i m->nbEBands - 4) { - hf_sum += celt_udiv(32 * (tcount[1] + tcount[0]), N); - } - tmp = (2 * tcount[2] >= N) + (2 * tcount[1] >= N) + (2 * tcount[0] >= N); - sum += tmp * spread_weight[i]; - nbBands += spread_weight[i]; - } - } while (++c < C); + /* Only include four last bands (8 kHz and up) */ + if (i>m->nbEBands-4) + hf_sum += celt_udiv(32*(tcount[1]+tcount[0]), N); + tmp = (2*tcount[2] >= N) + (2*tcount[1] >= N) + (2*tcount[0] >= N); + sum += tmp*spread_weight[i]; + nbBands+=spread_weight[i]; + } + } while (++cnbEBands + end)); - } - *hf_average = (*hf_average + hf_sum) >> 1; - hf_sum = *hf_average; - if (*tapset_decision == 2) { - hf_sum += 4; - } else if (*tapset_decision == 0) { - hf_sum -= 4; - } - if (hf_sum > 22) { - *tapset_decision = 2; - } else if (hf_sum > 18) { - *tapset_decision = 1; - } else { - *tapset_decision = 0; - } - } - /*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/ - celt_assert(nbBands > 0); /* end has to be non-zero */ - celt_assert(sum >= 0); - sum = celt_udiv((opus_int32)sum << 8, nbBands); - /* Recursive averaging */ - sum = (sum + *average) >> 1; - *average = sum; - /* Hysteresis */ - sum = (3 * sum + (((3 - last_decision) << 7) + 64) + 2) >> 2; - if (sum < 80) { - decision = SPREAD_AGGRESSIVE; - } else if (sum < 256) { - decision = SPREAD_NORMAL; - } else if (sum < 384) { - decision = SPREAD_LIGHT; - } else { - decision = SPREAD_NONE; - } + if (update_hf) + { + if (hf_sum) + hf_sum = celt_udiv(hf_sum, C*(4-m->nbEBands+end)); + *hf_average = (*hf_average+hf_sum)>>1; + hf_sum = *hf_average; + if (*tapset_decision==2) + hf_sum += 4; + else if (*tapset_decision==0) + hf_sum -= 4; + if (hf_sum > 22) + *tapset_decision=2; + else if (hf_sum > 18) + *tapset_decision=1; + else + *tapset_decision=0; + } + /*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/ + celt_assert(nbBands>0); /* end has to be non-zero */ + celt_assert(sum>=0); + sum = celt_udiv((opus_int32)sum<<8, nbBands); + /* Recursive averaging */ + sum = (sum+*average)>>1; + *average = sum; + /* Hysteresis */ + sum = (3*sum + (((3-last_decision)<<7) + 64) + 2)>>2; + if (sum < 80) + { + decision = SPREAD_AGGRESSIVE; + } else if (sum < 256) + { + decision = SPREAD_NORMAL; + } else if (sum < 384) + { + decision = SPREAD_LIGHT; + } else { + decision = SPREAD_NONE; + } #ifdef FUZZING - decision = rand() & 0x3; - *tapset_decision = rand() % 3; + decision = rand()&0x3; + *tapset_decision=rand()%3; #endif - return decision; + return decision; } -/* Indexing table for converting from natural Hadamard to ordery Hadamard - This is essentially a bit-reversed Gray, on top of which we've added - an inversion of the order because we want the DC at the end rather than - the beginning. The lines are for N=2, 4, 8, 16 */ +/* Indexing table for converting from natural Hadamard to ordery Hadamard + This is essentially a bit-reversed Gray, on top of which we've added + an inversion of the order because we want the DC at the end rather than + the beginning. The lines are for N=2, 4, 8, 16 */ static const int ordery_table[] = { - 1, 0, - 3, 0, 2, 1, - 7, 0, 4, 3, 6, 1, 5, 2, - 15, 0, 8, 7, 12, 3, 11, 4, 14, 1, 9, 6, 13, 2, 10, 5, + 1, 0, + 3, 0, 2, 1, + 7, 0, 4, 3, 6, 1, 5, 2, + 15, 0, 8, 7, 12, 3, 11, 4, 14, 1, 9, 6, 13, 2, 10, 5, }; -static void deinterleave_hadamard(celt_norm *X, int N0, int stride, int hadamard) { - int i, j; - VARDECL(celt_norm, tmp); - int N; - SAVE_STACK; - N = N0 * stride; - ALLOC(tmp, N, celt_norm); - celt_assert(stride > 0); - if (hadamard) { - const int *ordery = ordery_table + stride - 2; - for (i = 0; i < stride; i++) { - for (j = 0; j < N0; j++) { - tmp[ordery[i]*N0 + j] = X[j * stride + i]; - } - } - } else { - for (i = 0; i < stride; i++) - for (j = 0; j < N0; j++) { - tmp[i * N0 + j] = X[j * stride + i]; - } - } - OPUS_COPY(X, tmp, N); - RESTORE_STACK; +static void deinterleave_hadamard(celt_norm *X, int N0, int stride, int hadamard) +{ + int i,j; + VARDECL(celt_norm, tmp); + int N; + SAVE_STACK; + N = N0*stride; + ALLOC(tmp, N, celt_norm); + celt_assert(stride>0); + if (hadamard) + { + const int *ordery = ordery_table+stride-2; + for (i=0;i>= 1; - for (i = 0; i < stride; i++) - for (j = 0; j < N0; j++) { - opus_val32 tmp1, tmp2; - tmp1 = MULT16_16(QCONST16(.70710678f, 15), X[stride * 2 * j + i]); - tmp2 = MULT16_16(QCONST16(.70710678f, 15), X[stride * (2 * j + 1) + i]); - X[stride * 2 * j + i] = EXTRACT16(PSHR32(ADD32(tmp1, tmp2), 15)); - X[stride * (2 * j + 1) + i] = EXTRACT16(PSHR32(SUB32(tmp1, tmp2), 15)); - } +void haar1(celt_norm *X, int N0, int stride) +{ + int i, j; + N0 >>= 1; + for (i=0;i>1)) { - qn = 1; - } else { - qn = exp2_table8[qb & 0x7] >> (14 - (qb >> BITRES)); - qn = (qn + 1) >> 1 << 1; - } - celt_assert(qn <= 256); - return qn; + if (qb<(1<>1)) { + qn = 1; + } else { + qn = exp2_table8[qb&0x7]>>(14-(qb>>BITRES)); + qn = (qn+1)>>1<<1; + } + celt_assert(qn <= 256); + return qn; } struct band_ctx { - int encode; - int resynth; - const CELTMode *m; - int i; - int intensity; - int spread; - int tf_change; - ec_ctx *ec; - opus_int32 remaining_bits; - const celt_ener *bandE; - opus_uint32 seed; - int arch; - int theta_round; - int disable_inv; - int avoid_split_noise; + int encode; + int resynth; + const CELTMode *m; + int i; + int intensity; + int spread; + int tf_change; + ec_ctx *ec; + opus_int32 remaining_bits; + const celt_ener *bandE; + opus_uint32 seed; + int arch; + int theta_round; + int disable_inv; + int avoid_split_noise; }; struct split_ctx { - int inv; - int imid; - int iside; - int delta; - int itheta; - int qalloc; + int inv; + int imid; + int iside; + int delta; + int itheta; + int qalloc; }; static void compute_theta(struct band_ctx *ctx, struct split_ctx *sctx, - celt_norm *X, celt_norm *Y, int N, int *b, int B, int B0, - int LM, - int stereo, int *fill) { - int qn; - int itheta = 0; - int delta; - int imid, iside; - int qalloc; - int pulse_cap; - int offset; - opus_int32 tell; - int inv = 0; - int encode; - const CELTMode *m; - int i; - int intensity; - ec_ctx *ec; - const celt_ener *bandE; + celt_norm *X, celt_norm *Y, int N, int *b, int B, int B0, + int LM, + int stereo, int *fill) +{ + int qn; + int itheta=0; + int delta; + int imid, iside; + int qalloc; + int pulse_cap; + int offset; + opus_int32 tell; + int inv=0; + int encode; + const CELTMode *m; + int i; + int intensity; + ec_ctx *ec; + const celt_ener *bandE; - encode = ctx->encode; - m = ctx->m; - i = ctx->i; - intensity = ctx->intensity; - ec = ctx->ec; - bandE = ctx->bandE; + encode = ctx->encode; + m = ctx->m; + i = ctx->i; + intensity = ctx->intensity; + ec = ctx->ec; + bandE = ctx->bandE; - /* Decide on the resolution to give to the split parameter theta */ - pulse_cap = m->logN[i] + LM * (1 << BITRES); - offset = (pulse_cap >> 1) - (stereo && N == 2 ? QTHETA_OFFSET_TWOPHASE : QTHETA_OFFSET); - qn = compute_qn(N, *b, offset, pulse_cap, stereo); - if (stereo && i >= intensity) { - qn = 1; - } - if (encode) { - /* theta is the atan() of the ratio between the (normalized) - side and mid. With just that parameter, we can re-scale both - mid and side because we know that 1) they have unit norm and - 2) they are orthogonal. */ - itheta = stereo_itheta(X, Y, stereo, N, ctx->arch); - } - tell = ec_tell_frac(ec); - if (qn != 1) { - if (encode) { - if (!stereo || ctx->theta_round == 0) { - itheta = (itheta * (opus_int32)qn + 8192) >> 14; - if (!stereo && ctx->avoid_split_noise && itheta > 0 && itheta < qn) { - /* Check if the selected value of theta will cause the bit allocation - to inject noise on one side. If so, make sure the energy of that side - is zero. */ - int unquantized = celt_udiv((opus_int32)itheta * 16384, qn); - imid = bitexact_cos((opus_int16)unquantized); - iside = bitexact_cos((opus_int16)(16384 - unquantized)); - delta = FRAC_MUL16((N - 1) << 7, bitexact_log2tan(iside, imid)); - if (delta > *b) { - itheta = qn; - } else if (delta < -*b) { - itheta = 0; - } - } - } else { - int down; - /* Bias quantization towards itheta=0 and itheta=16384. */ - int bias = itheta > 8192 ? 32767 / qn : -32767 / qn; - down = IMIN(qn - 1, IMAX(0, (itheta * (opus_int32)qn + bias) >> 14)); - if (ctx->theta_round < 0) { - itheta = down; - } else { - itheta = down + 1; - } + /* Decide on the resolution to give to the split parameter theta */ + pulse_cap = m->logN[i]+LM*(1<>1) - (stereo&&N==2 ? QTHETA_OFFSET_TWOPHASE : QTHETA_OFFSET); + qn = compute_qn(N, *b, offset, pulse_cap, stereo); + if (stereo && i>=intensity) + qn = 1; + if (encode) + { + /* theta is the atan() of the ratio between the (normalized) + side and mid. With just that parameter, we can re-scale both + mid and side because we know that 1) they have unit norm and + 2) they are orthogonal. */ + itheta = stereo_itheta(X, Y, stereo, N, ctx->arch); + } + tell = ec_tell_frac(ec); + if (qn!=1) + { + if (encode) + { + if (!stereo || ctx->theta_round == 0) + { + itheta = (itheta*(opus_int32)qn+8192)>>14; + if (!stereo && ctx->avoid_split_noise && itheta > 0 && itheta < qn) + { + /* Check if the selected value of theta will cause the bit allocation + to inject noise on one side. If so, make sure the energy of that side + is zero. */ + int unquantized = celt_udiv((opus_int32)itheta*16384, qn); + imid = bitexact_cos((opus_int16)unquantized); + iside = bitexact_cos((opus_int16)(16384-unquantized)); + delta = FRAC_MUL16((N-1)<<7,bitexact_log2tan(iside,imid)); + if (delta > *b) + itheta = qn; + else if (delta < -*b) + itheta = 0; } - } - /* Entropy coding of the angle. We use a uniform pdf for the - time split, a step for stereo, and a triangular one for the rest. */ - if (stereo && N > 2) { - int p0 = 3; - int x = itheta; - int x0 = qn / 2; - int ft = p0 * (x0 + 1) + x0; - /* Use a probability of p0 up to itheta=8192 and then use 1 after */ - if (encode) { - ec_encode(ec, x <= x0 ? p0*x : (x - 1 - x0) + (x0 + 1)*p0, x <= x0 ? p0 * (x + 1) : (x - x0) + (x0 + 1)*p0, ft); - } else { - int fs; - fs = ec_decode(ec, ft); - if (fs < (x0 + 1)*p0) { - x = fs / p0; - } else { - x = x0 + 1 + (fs - (x0 + 1) * p0); - } - ec_dec_update(ec, x <= x0 ? p0*x : (x - 1 - x0) + (x0 + 1)*p0, x <= x0 ? p0 * (x + 1) : (x - x0) + (x0 + 1)*p0, ft); - itheta = x; - } - } else if (B0 > 1 || stereo) { - /* Uniform pdf */ - if (encode) { - ec_enc_uint(ec, itheta, qn + 1); - } else { - itheta = ec_dec_uint(ec, qn + 1); - } - } else { - int fs = 1, ft; - ft = ((qn >> 1) + 1) * ((qn >> 1) + 1); - if (encode) { - int fl; + } else { + int down; + /* Bias quantization towards itheta=0 and itheta=16384. */ + int bias = itheta > 8192 ? 32767/qn : -32767/qn; + down = IMIN(qn-1, IMAX(0, (itheta*(opus_int32)qn + bias)>>14)); + if (ctx->theta_round < 0) + itheta = down; + else + itheta = down+1; + } + } + /* Entropy coding of the angle. We use a uniform pdf for the + time split, a step for stereo, and a triangular one for the rest. */ + if (stereo && N>2) + { + int p0 = 3; + int x = itheta; + int x0 = qn/2; + int ft = p0*(x0+1) + x0; + /* Use a probability of p0 up to itheta=8192 and then use 1 after */ + if (encode) + { + ec_encode(ec,x<=x0?p0*x:(x-1-x0)+(x0+1)*p0,x<=x0?p0*(x+1):(x-x0)+(x0+1)*p0,ft); + } else { + int fs; + fs=ec_decode(ec,ft); + if (fs<(x0+1)*p0) + x=fs/p0; + else + x=x0+1+(fs-(x0+1)*p0); + ec_dec_update(ec,x<=x0?p0*x:(x-1-x0)+(x0+1)*p0,x<=x0?p0*(x+1):(x-x0)+(x0+1)*p0,ft); + itheta = x; + } + } else if (B0>1 || stereo) { + /* Uniform pdf */ + if (encode) + ec_enc_uint(ec, itheta, qn+1); + else + itheta = ec_dec_uint(ec, qn+1); + } else { + int fs=1, ft; + ft = ((qn>>1)+1)*((qn>>1)+1); + if (encode) + { + int fl; - fs = itheta <= (qn >> 1) ? itheta + 1 : qn + 1 - itheta; - fl = itheta <= (qn >> 1) ? itheta * (itheta + 1) >> 1 : - ft - ((qn + 1 - itheta) * (qn + 2 - itheta) >> 1); + fs = itheta <= (qn>>1) ? itheta + 1 : qn + 1 - itheta; + fl = itheta <= (qn>>1) ? itheta*(itheta + 1)>>1 : + ft - ((qn + 1 - itheta)*(qn + 2 - itheta)>>1); - ec_encode(ec, fl, fl + fs, ft); - } else { - /* Triangular pdf */ - int fl = 0; - int fm; - fm = ec_decode(ec, ft); + ec_encode(ec, fl, fl+fs, ft); + } else { + /* Triangular pdf */ + int fl=0; + int fm; + fm = ec_decode(ec, ft); - if (fm < ((qn >> 1) * ((qn >> 1) + 1) >> 1)) { - itheta = (isqrt32(8 * (opus_uint32)fm + 1) - 1) >> 1; - fs = itheta + 1; - fl = itheta * (itheta + 1) >> 1; - } else { - itheta = (2 * (qn + 1) - - isqrt32(8 * (opus_uint32)(ft - fm - 1) + 1)) >> 1; - fs = qn + 1 - itheta; - fl = ft - ((qn + 1 - itheta) * (qn + 2 - itheta) >> 1); - } + if (fm < ((qn>>1)*((qn>>1) + 1)>>1)) + { + itheta = (isqrt32(8*(opus_uint32)fm + 1) - 1)>>1; + fs = itheta + 1; + fl = itheta*(itheta + 1)>>1; + } + else + { + itheta = (2*(qn + 1) + - isqrt32(8*(opus_uint32)(ft - fm - 1) + 1))>>1; + fs = qn + 1 - itheta; + fl = ft - ((qn + 1 - itheta)*(qn + 2 - itheta)>>1); + } - ec_dec_update(ec, fl, fl + fs, ft); - } - } - celt_assert(itheta >= 0); - itheta = celt_udiv((opus_int32)itheta * 16384, qn); - if (encode && stereo) { - if (itheta == 0) { - intensity_stereo(m, X, Y, bandE, i, N); - } else { - stereo_split(X, Y, N); - } - } - /* NOTE: Renormalising X and Y *may* help fixed-point a bit at very high rate. - Let's do that at higher complexity */ - } else if (stereo) { - if (encode) { - inv = itheta > 8192 && !ctx->disable_inv; - if (inv) { - int j; - for (j = 0; j < N; j++) { - Y[j] = -Y[j]; - } - } + ec_dec_update(ec, fl, fl+fs, ft); + } + } + celt_assert(itheta>=0); + itheta = celt_udiv((opus_int32)itheta*16384, qn); + if (encode && stereo) + { + if (itheta==0) intensity_stereo(m, X, Y, bandE, i, N); - } - if (*b > 2 << BITRES && ctx->remaining_bits > 2 << BITRES) { - if (encode) { - ec_enc_bit_logp(ec, inv, 2); - } else { - inv = ec_dec_bit_logp(ec, 2); - } - } else { - inv = 0; - } - /* inv flag override to avoid problems with downmixing. */ - if (ctx->disable_inv) { - inv = 0; - } - itheta = 0; - } - qalloc = ec_tell_frac(ec) - tell; - *b -= qalloc; + else + stereo_split(X, Y, N); + } + /* NOTE: Renormalising X and Y *may* help fixed-point a bit at very high rate. + Let's do that at higher complexity */ + } else if (stereo) { + if (encode) + { + inv = itheta > 8192 && !ctx->disable_inv; + if (inv) + { + int j; + for (j=0;j2<remaining_bits > 2<disable_inv) + inv = 0; + itheta = 0; + } + qalloc = ec_tell_frac(ec) - tell; + *b -= qalloc; - if (itheta == 0) { - imid = 32767; - iside = 0; - *fill &= (1 << B) - 1; - delta = -16384; - } else if (itheta == 16384) { - imid = 0; - iside = 32767; - *fill &= ((1 << B) - 1) << B; - delta = 16384; - } else { - imid = bitexact_cos((opus_int16)itheta); - iside = bitexact_cos((opus_int16)(16384 - itheta)); - /* This is the mid vs side allocation that minimizes squared error - in that band. */ - delta = FRAC_MUL16((N - 1) << 7, bitexact_log2tan(iside, imid)); - } + if (itheta == 0) + { + imid = 32767; + iside = 0; + *fill &= (1<inv = inv; - sctx->imid = imid; - sctx->iside = iside; - sctx->delta = delta; - sctx->itheta = itheta; - sctx->qalloc = qalloc; + sctx->inv = inv; + sctx->imid = imid; + sctx->iside = iside; + sctx->delta = delta; + sctx->itheta = itheta; + sctx->qalloc = qalloc; } -static unsigned quant_band_n1(struct band_ctx *ctx, celt_norm *X, celt_norm *Y, int b, - celt_norm *lowband_out) { - int c; - int stereo; - celt_norm *x = X; - int encode; - ec_ctx *ec; +static unsigned quant_band_n1(struct band_ctx *ctx, celt_norm *X, celt_norm *Y, + celt_norm *lowband_out) +{ + int c; + int stereo; + celt_norm *x = X; + int encode; + ec_ctx *ec; - encode = ctx->encode; - ec = ctx->ec; + encode = ctx->encode; + ec = ctx->ec; - stereo = Y != NULL; - c = 0; do { - int sign = 0; - if (ctx->remaining_bits >= 1 << BITRES) { - if (encode) { - sign = x[0] < 0; - ec_enc_bits(ec, sign, 1); - } else { - sign = ec_dec_bits(ec, 1); - } - ctx->remaining_bits -= 1 << BITRES; - b -= 1 << BITRES; - } - if (ctx->resynth) { - x[0] = sign ? -NORM_SCALING : NORM_SCALING; - } - x = Y; - } while (++c < 1 + stereo); - if (lowband_out) { - lowband_out[0] = SHR16(X[0], 4); - } - return 1; + stereo = Y != NULL; + c=0; do { + int sign=0; + if (ctx->remaining_bits>=1<remaining_bits -= 1<resynth) + x[0] = sign ? -NORM_SCALING : NORM_SCALING; + x = Y; + } while (++c<1+stereo); + if (lowband_out) + lowband_out[0] = SHR16(X[0],4); + return 1; } -/* This function is responsible for encoding and decoding a mono partition. - It can split the band in two and transmit the energy difference with - the two half-bands. It can be called recursively so bands can end up being - split in 8 parts. */ +/* This function is responsible for encoding and decoding a mono partition. + It can split the band in two and transmit the energy difference with + the two half-bands. It can be called recursively so bands can end up being + split in 8 parts. */ static unsigned quant_partition(struct band_ctx *ctx, celt_norm *X, - int N, int b, int B, celt_norm *lowband, - int LM, - opus_val16 gain, int fill) { - const unsigned char *cache; - int q; - int curr_bits; - int imid = 0, iside = 0; - int B0 = B; - opus_val16 mid = 0, side = 0; - unsigned cm = 0; - celt_norm *Y = NULL; - int encode; - const CELTMode *m; - int i; - int spread; - ec_ctx *ec; + int N, int b, int B, celt_norm *lowband, + int LM, + opus_val16 gain, int fill) +{ + const unsigned char *cache; + int q; + int curr_bits; + int imid=0, iside=0; + int B0=B; + opus_val16 mid=0, side=0; + unsigned cm=0; + celt_norm *Y=NULL; + int encode; + const CELTMode *m; + int i; + int spread; + ec_ctx *ec; - encode = ctx->encode; - m = ctx->m; - i = ctx->i; - spread = ctx->spread; - ec = ctx->ec; + encode = ctx->encode; + m = ctx->m; + i = ctx->i; + spread = ctx->spread; + ec = ctx->ec; - /* If we need 1.5 more bit than we can produce, split the band in two. */ - cache = m->cache.bits + m->cache.index[(LM + 1) * m->nbEBands + i]; - if (LM != -1 && b > cache[cache[0]] + 12 && N > 2) { - int mbits, sbits, delta; - int itheta; - int qalloc; - struct split_ctx sctx; - celt_norm *next_lowband2 = NULL; - opus_int32 rebalance; + /* If we need 1.5 more bit than we can produce, split the band in two. */ + cache = m->cache.bits + m->cache.index[(LM+1)*m->nbEBands+i]; + if (LM != -1 && b > cache[cache[0]]+12 && N>2) + { + int mbits, sbits, delta; + int itheta; + int qalloc; + struct split_ctx sctx; + celt_norm *next_lowband2=NULL; + opus_int32 rebalance; - N >>= 1; - Y = X + N; - LM -= 1; - if (B == 1) { - fill = (fill & 1) | (fill << 1); - } - B = (B + 1) >> 1; + N >>= 1; + Y = X+N; + LM -= 1; + if (B==1) + fill = (fill&1)|(fill<<1); + B = (B+1)>>1; - compute_theta(ctx, &sctx, X, Y, N, &b, B, B0, LM, 0, &fill); - imid = sctx.imid; - iside = sctx.iside; - delta = sctx.delta; - itheta = sctx.itheta; - qalloc = sctx.qalloc; + compute_theta(ctx, &sctx, X, Y, N, &b, B, B0, LM, 0, &fill); + imid = sctx.imid; + iside = sctx.iside; + delta = sctx.delta; + itheta = sctx.itheta; + qalloc = sctx.qalloc; #ifdef FIXED_POINT - mid = imid; - side = iside; + mid = imid; + side = iside; #else - mid = (1.f / 32768) * imid; - side = (1.f / 32768) * iside; + mid = (1.f/32768)*imid; + side = (1.f/32768)*iside; #endif - /* Give more bits to low-energy MDCTs than they would otherwise deserve */ - if (B0 > 1 && (itheta & 0x3fff)) { - if (itheta > 8192) - /* Rough approximation for pre-echo masking */ + /* Give more bits to low-energy MDCTs than they would otherwise deserve */ + if (B0>1 && (itheta&0x3fff)) + { + if (itheta > 8192) + /* Rough approximation for pre-echo masking */ + delta -= delta>>(4-LM); + else + /* Corresponds to a forward-masking slope of 1.5 dB per 10 ms */ + delta = IMIN(0, delta + (N<>(5-LM))); + } + mbits = IMAX(0, IMIN(b, (b-delta)/2)); + sbits = b-mbits; + ctx->remaining_bits -= qalloc; + + if (lowband) + next_lowband2 = lowband+N; /* >32-bit split case */ + + rebalance = ctx->remaining_bits; + if (mbits >= sbits) + { + cm = quant_partition(ctx, X, N, mbits, B, lowband, LM, + MULT16_16_P15(gain,mid), fill); + rebalance = mbits - (rebalance-ctx->remaining_bits); + if (rebalance > 3<>B)<<(B0>>1); + } else { + cm = quant_partition(ctx, Y, N, sbits, B, next_lowband2, LM, + MULT16_16_P15(gain,side), fill>>B)<<(B0>>1); + rebalance = sbits - (rebalance-ctx->remaining_bits); + if (rebalance > 3<remaining_bits -= curr_bits; + + /* Ensures we can never bust the budget */ + while (ctx->remaining_bits < 0 && q > 0) + { + ctx->remaining_bits += curr_bits; + q--; + curr_bits = pulses2bits(m, i, LM, q); + ctx->remaining_bits -= curr_bits; + } + + if (q!=0) + { + int K = get_pulses(q); + + /* Finally do the actual quantization */ + if (encode) + { + cm = alg_quant(X, N, K, spread, B, ec, gain, ctx->resynth, ctx->arch); + } else { + cm = alg_unquant(X, N, K, spread, B, ec, gain); + } + } else { + /* If there's no pulse, fill the band anyway */ + int j; + if (ctx->resynth) + { + unsigned cm_mask; + /* B can be as large as 16, so this shift might overflow an int on a + 16-bit platform; use a long to get defined behavior.*/ + cm_mask = (unsigned)(1UL<> (4 - LM); - } else - /* Corresponds to a forward-masking slope of 1.5 dB per 10 ms */ - { - delta = IMIN(0, delta + (N << BITRES>>(5 - LM))); - } - } - mbits = IMAX(0, IMIN(b, (b - delta) / 2)); - sbits = b - mbits; - ctx->remaining_bits -= qalloc; - - if (lowband) { - next_lowband2 = lowband + N; /* >32-bit split case */ - } - - rebalance = ctx->remaining_bits; - if (mbits >= sbits) { - cm = quant_partition(ctx, X, N, mbits, B, lowband, LM, - MULT16_16_P15(gain, mid), fill); - rebalance = mbits - (rebalance - ctx->remaining_bits); - if (rebalance > 3 << BITRES && itheta != 0) { - sbits += rebalance - (3 << BITRES); - } - cm |= quant_partition(ctx, Y, N, sbits, B, next_lowband2, LM, - MULT16_16_P15(gain, side), fill >> B) << (B0 >> 1); - } else { - cm = quant_partition(ctx, Y, N, sbits, B, next_lowband2, LM, - MULT16_16_P15(gain, side), fill >> B) << (B0 >> 1); - rebalance = sbits - (rebalance - ctx->remaining_bits); - if (rebalance > 3 << BITRES && itheta != 16384) { - mbits += rebalance - (3 << BITRES); - } - cm |= quant_partition(ctx, X, N, mbits, B, lowband, LM, - MULT16_16_P15(gain, mid), fill); - } - } else { - /* This is the basic no-split case */ - q = bits2pulses(m, i, LM, b); - curr_bits = pulses2bits(m, i, LM, q); - ctx->remaining_bits -= curr_bits; - - /* Ensures we can never bust the budget */ - while (ctx->remaining_bits < 0 && q > 0) { - ctx->remaining_bits += curr_bits; - q--; - curr_bits = pulses2bits(m, i, LM, q); - ctx->remaining_bits -= curr_bits; - } - - if (q != 0) { - int K = get_pulses(q); - - /* Finally do the actual quantization */ - if (encode) { - cm = alg_quant(X, N, K, spread, B, ec, gain, ctx->resynth, ctx->arch); + OPUS_CLEAR(X, N); } else { - cm = alg_unquant(X, N, K, spread, B, ec, gain); + if (lowband == NULL) + { + /* Noise */ + for (j=0;jseed = celt_lcg_rand(ctx->seed); + X[j] = (celt_norm)((opus_int32)ctx->seed>>20); + } + cm = cm_mask; + } else { + /* Folded spectrum */ + for (j=0;jseed = celt_lcg_rand(ctx->seed); + /* About 48 dB below the "normal" folding level */ + tmp = QCONST16(1.0f/256, 10); + tmp = (ctx->seed)&0x8000 ? tmp : -tmp; + X[j] = lowband[j]+tmp; + } + cm = fill; + } + renormalise_vector(X, N, gain, ctx->arch); } - } else { - /* If there's no pulse, fill the band anyway */ - int j; - if (ctx->resynth) { - unsigned cm_mask; - /* B can be as large as 16, so this shift might overflow an int on a - 16-bit platform; use a long to get defined behavior.*/ - cm_mask = (unsigned)(1UL << B) - 1; - fill &= cm_mask; - if (!fill) { - OPUS_CLEAR(X, N); - } else { - if (lowband == NULL) { - /* Noise */ - for (j = 0; j < N; j++) { - ctx->seed = celt_lcg_rand(ctx->seed); - X[j] = (celt_norm)((opus_int32)ctx->seed >> 20); - } - cm = cm_mask; - } else { - /* Folded spectrum */ - for (j = 0; j < N; j++) { - opus_val16 tmp; - ctx->seed = celt_lcg_rand(ctx->seed); - /* About 48 dB below the "normal" folding level */ - tmp = QCONST16(1.0f / 256, 10); - tmp = (ctx->seed) & 0x8000 ? tmp : -tmp; - X[j] = lowband[j] + tmp; - } - cm = fill; - } - renormalise_vector(X, N, gain, ctx->arch); - } - } - } - } + } + } + } - return cm; + return cm; } /* This function is responsible for encoding and decoding a band for the mono case. */ static unsigned quant_band(struct band_ctx *ctx, celt_norm *X, - int N, int b, int B, celt_norm *lowband, - int LM, celt_norm *lowband_out, - opus_val16 gain, celt_norm *lowband_scratch, int fill) { - int N0 = N; - int N_B = N; - int N_B0; - int B0 = B; - int time_divide = 0; - int recombine = 0; - int longBlocks; - unsigned cm = 0; - int k; - int encode; - int tf_change; + int N, int b, int B, celt_norm *lowband, + int LM, celt_norm *lowband_out, + opus_val16 gain, celt_norm *lowband_scratch, int fill) +{ + int N0=N; + int N_B=N; + int N_B0; + int B0=B; + int time_divide=0; + int recombine=0; + int longBlocks; + unsigned cm=0; + int k; + int encode; + int tf_change; - encode = ctx->encode; - tf_change = ctx->tf_change; + encode = ctx->encode; + tf_change = ctx->tf_change; - longBlocks = B0 == 1; + longBlocks = B0==1; - N_B = celt_udiv(N_B, B); + N_B = celt_udiv(N_B, B); - /* Special case for one sample */ - if (N == 1) { - return quant_band_n1(ctx, X, NULL, b, lowband_out); - } + /* Special case for one sample */ + if (N==1) + { + return quant_band_n1(ctx, X, NULL, lowband_out); + } - if (tf_change > 0) { - recombine = tf_change; - } - /* Band recombining to increase frequency resolution */ + if (tf_change>0) + recombine = tf_change; + /* Band recombining to increase frequency resolution */ - if (lowband_scratch && lowband && (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) { - OPUS_COPY(lowband_scratch, lowband, N); - lowband = lowband_scratch; - } + if (lowband_scratch && lowband && (recombine || ((N_B&1) == 0 && tf_change<0) || B0>1)) + { + OPUS_COPY(lowband_scratch, lowband, N); + lowband = lowband_scratch; + } - for (k = 0; k < recombine; k++) { - static const unsigned char bit_interleave_table[16] = { - 0, 1, 1, 1, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3 - }; - if (encode) { - haar1(X, N >> k, 1 << k); - } - if (lowband) { - haar1(lowband, N >> k, 1 << k); - } - fill = bit_interleave_table[fill & 0xF] | bit_interleave_table[fill >> 4] << 2; - } - B >>= recombine; - N_B <<= recombine; + for (k=0;k>k, 1<>k, 1<>4]<<2; + } + B>>=recombine; + N_B<<=recombine; - /* Increasing the time resolution */ - while ((N_B & 1) == 0 && tf_change < 0) { - if (encode) { - haar1(X, N_B, B); - } - if (lowband) { - haar1(lowband, N_B, B); - } - fill |= fill << B; - B <<= 1; - N_B >>= 1; - time_divide++; - tf_change++; - } - B0 = B; - N_B0 = N_B; + /* Increasing the time resolution */ + while ((N_B&1) == 0 && tf_change<0) + { + if (encode) + haar1(X, N_B, B); + if (lowband) + haar1(lowband, N_B, B); + fill |= fill<>= 1; + time_divide++; + tf_change++; + } + B0=B; + N_B0 = N_B; - /* Reorganize the samples in time order instead of frequency order */ - if (B0 > 1) { - if (encode) { - deinterleave_hadamard(X, N_B >> recombine, B0 << recombine, longBlocks); - } - if (lowband) { - deinterleave_hadamard(lowband, N_B >> recombine, B0 << recombine, longBlocks); - } - } + /* Reorganize the samples in time order instead of frequency order */ + if (B0>1) + { + if (encode) + deinterleave_hadamard(X, N_B>>recombine, B0<>recombine, B0<resynth) { - /* Undo the sample reorganization going from time order to frequency order */ - if (B0 > 1) { - interleave_hadamard(X, N_B >> recombine, B0 << recombine, longBlocks); - } + /* This code is used by the decoder and by the resynthesis-enabled encoder */ + if (ctx->resynth) + { + /* Undo the sample reorganization going from time order to frequency order */ + if (B0>1) + interleave_hadamard(X, N_B>>recombine, B0<>= 1; - N_B <<= 1; - cm |= cm >> B; - haar1(X, N_B, B); - } + /* Undo time-freq changes that we did earlier */ + N_B = N_B0; + B = B0; + for (k=0;k>= 1; + N_B <<= 1; + cm |= cm>>B; + haar1(X, N_B, B); + } - for (k = 0; k < recombine; k++) { - static const unsigned char bit_deinterleave_table[16] = { - 0x00, 0x03, 0x0C, 0x0F, 0x30, 0x33, 0x3C, 0x3F, - 0xC0, 0xC3, 0xCC, 0xCF, 0xF0, 0xF3, 0xFC, 0xFF - }; - cm = bit_deinterleave_table[cm]; - haar1(X, N0 >> k, 1 << k); - } - B <<= recombine; + for (k=0;k>k, 1<encode; - ec = ctx->ec; + encode = ctx->encode; + ec = ctx->ec; - /* Special case for one sample */ - if (N == 1) { - return quant_band_n1(ctx, X, Y, b, lowband_out); - } + /* Special case for one sample */ + if (N==1) + { + return quant_band_n1(ctx, X, Y, lowband_out); + } - orig_fill = fill; + orig_fill = fill; - compute_theta(ctx, &sctx, X, Y, N, &b, B, B, LM, 1, &fill); - inv = sctx.inv; - imid = sctx.imid; - iside = sctx.iside; - delta = sctx.delta; - itheta = sctx.itheta; - qalloc = sctx.qalloc; + compute_theta(ctx, &sctx, X, Y, N, &b, B, B, LM, 1, &fill); + inv = sctx.inv; + imid = sctx.imid; + iside = sctx.iside; + delta = sctx.delta; + itheta = sctx.itheta; + qalloc = sctx.qalloc; #ifdef FIXED_POINT - mid = imid; - side = iside; + mid = imid; + side = iside; #else - mid = (1.f / 32768) * imid; - side = (1.f / 32768) * iside; + mid = (1.f/32768)*imid; + side = (1.f/32768)*iside; #endif - /* This is a special case for N=2 that only works for stereo and takes - advantage of the fact that mid and side are orthogonal to encode - the side with just one bit. */ - if (N == 2) { - int c; - int sign = 0; - celt_norm *x2, *y2; - mbits = b; - sbits = 0; - /* Only need one bit for the side. */ - if (itheta != 0 && itheta != 16384) { - sbits = 1 << BITRES; - } - mbits -= sbits; - c = itheta > 8192; - ctx->remaining_bits -= qalloc + sbits; + /* This is a special case for N=2 that only works for stereo and takes + advantage of the fact that mid and side are orthogonal to encode + the side with just one bit. */ + if (N==2) + { + int c; + int sign=0; + celt_norm *x2, *y2; + mbits = b; + sbits = 0; + /* Only need one bit for the side. */ + if (itheta != 0 && itheta != 16384) + sbits = 1< 8192; + ctx->remaining_bits -= qalloc+sbits; - x2 = c ? Y : X; - y2 = c ? X : Y; - if (sbits) { - if (encode) { - /* Here we only need to encode a sign for the side. */ - sign = x2[0] * y2[1] - x2[1] * y2[0] < 0; - ec_enc_bits(ec, sign, 1); - } else { - sign = ec_dec_bits(ec, 1); - } - } - sign = 1 - 2 * sign; - /* We use orig_fill here because we want to fold the side, but if - itheta==16384, we'll have cleared the low bits of fill. */ - cm = quant_band(ctx, x2, N, mbits, B, lowband, LM, lowband_out, Q15ONE, - lowband_scratch, orig_fill); - /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse), - and there's no need to worry about mixing with the other channel. */ - y2[0] = -sign * x2[1]; - y2[1] = sign * x2[0]; - if (ctx->resynth) { - celt_norm tmp; - X[0] = MULT16_16_Q15(mid, X[0]); - X[1] = MULT16_16_Q15(mid, X[1]); - Y[0] = MULT16_16_Q15(side, Y[0]); - Y[1] = MULT16_16_Q15(side, Y[1]); - tmp = X[0]; - X[0] = SUB16(tmp, Y[0]); - Y[0] = ADD16(tmp, Y[0]); - tmp = X[1]; - X[1] = SUB16(tmp, Y[1]); - Y[1] = ADD16(tmp, Y[1]); - } - } else { - /* "Normal" split code */ - opus_int32 rebalance; + x2 = c ? Y : X; + y2 = c ? X : Y; + if (sbits) + { + if (encode) + { + /* Here we only need to encode a sign for the side. */ + sign = x2[0]*y2[1] - x2[1]*y2[0] < 0; + ec_enc_bits(ec, sign, 1); + } else { + sign = ec_dec_bits(ec, 1); + } + } + sign = 1-2*sign; + /* We use orig_fill here because we want to fold the side, but if + itheta==16384, we'll have cleared the low bits of fill. */ + cm = quant_band(ctx, x2, N, mbits, B, lowband, LM, lowband_out, Q15ONE, + lowband_scratch, orig_fill); + /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse), + and there's no need to worry about mixing with the other channel. */ + y2[0] = -sign*x2[1]; + y2[1] = sign*x2[0]; + if (ctx->resynth) + { + celt_norm tmp; + X[0] = MULT16_16_Q15(mid, X[0]); + X[1] = MULT16_16_Q15(mid, X[1]); + Y[0] = MULT16_16_Q15(side, Y[0]); + Y[1] = MULT16_16_Q15(side, Y[1]); + tmp = X[0]; + X[0] = SUB16(tmp,Y[0]); + Y[0] = ADD16(tmp,Y[0]); + tmp = X[1]; + X[1] = SUB16(tmp,Y[1]); + Y[1] = ADD16(tmp,Y[1]); + } + } else { + /* "Normal" split code */ + opus_int32 rebalance; - mbits = IMAX(0, IMIN(b, (b - delta) / 2)); - sbits = b - mbits; - ctx->remaining_bits -= qalloc; + mbits = IMAX(0, IMIN(b, (b-delta)/2)); + sbits = b-mbits; + ctx->remaining_bits -= qalloc; - rebalance = ctx->remaining_bits; - if (mbits >= sbits) { - /* In stereo mode, we do not apply a scaling to the mid because we need the normalized - mid for folding later. */ - cm = quant_band(ctx, X, N, mbits, B, lowband, LM, lowband_out, Q15ONE, - lowband_scratch, fill); - rebalance = mbits - (rebalance - ctx->remaining_bits); - if (rebalance > 3 << BITRES && itheta != 0) { - sbits += rebalance - (3 << BITRES); - } + rebalance = ctx->remaining_bits; + if (mbits >= sbits) + { + /* In stereo mode, we do not apply a scaling to the mid because we need the normalized + mid for folding later. */ + cm = quant_band(ctx, X, N, mbits, B, lowband, LM, lowband_out, Q15ONE, + lowband_scratch, fill); + rebalance = mbits - (rebalance-ctx->remaining_bits); + if (rebalance > 3<> B); - } else { - /* For a stereo split, the high bits of fill are always zero, so no - folding will be done to the side. */ - cm = quant_band(ctx, Y, N, sbits, B, NULL, LM, NULL, side, NULL, fill >> B); - rebalance = sbits - (rebalance - ctx->remaining_bits); - if (rebalance > 3 << BITRES && itheta != 16384) { - mbits += rebalance - (3 << BITRES); - } - /* In stereo mode, we do not apply a scaling to the mid because we need the normalized - mid for folding later. */ - cm |= quant_band(ctx, X, N, mbits, B, lowband, LM, lowband_out, Q15ONE, - lowband_scratch, fill); - } - } + /* For a stereo split, the high bits of fill are always zero, so no + folding will be done to the side. */ + cm |= quant_band(ctx, Y, N, sbits, B, NULL, LM, NULL, side, NULL, fill>>B); + } else { + /* For a stereo split, the high bits of fill are always zero, so no + folding will be done to the side. */ + cm = quant_band(ctx, Y, N, sbits, B, NULL, LM, NULL, side, NULL, fill>>B); + rebalance = sbits - (rebalance-ctx->remaining_bits); + if (rebalance > 3<resynth) { - if (N != 2) { - stereo_merge(X, Y, mid, N, ctx->arch); - } - if (inv) { - int j; - for (j = 0; j < N; j++) { - Y[j] = -Y[j]; - } - } - } - return cm; + /* This code is used by the decoder and by the resynthesis-enabled encoder */ + if (ctx->resynth) + { + if (N!=2) + stereo_merge(X, Y, mid, N, ctx->arch); + if (inv) + { + int j; + for (j=0;jeBands; - n1 = M * (eBands[start + 1] - eBands[start]); - n2 = M * (eBands[start + 2] - eBands[start + 1]); - /* Duplicate enough of the first band folding data to be able to fold the second band. - Copies no data for CELT-only mode. */ - OPUS_COPY(&norm[n1], &norm[2 * n1 - n2], n2 - n1); - if (dual_stereo) { - OPUS_COPY(&norm2[n1], &norm2[2 * n1 - n2], n2 - n1); - } +#ifndef DISABLE_UPDATE_DRAFT +static void special_hybrid_folding(const CELTMode *m, celt_norm *norm, celt_norm *norm2, int start, int M, int dual_stereo) +{ + int n1, n2; + const opus_int16 * OPUS_RESTRICT eBands = m->eBands; + n1 = M*(eBands[start+1]-eBands[start]); + n2 = M*(eBands[start+2]-eBands[start+1]); + /* Duplicate enough of the first band folding data to be able to fold the second band. + Copies no data for CELT-only mode. */ + OPUS_COPY(&norm[n1], &norm[2*n1 - n2], n2-n1); + if (dual_stereo) + OPUS_COPY(&norm2[n1], &norm2[2*n1 - n2], n2-n1); } +#endif void quant_all_bands(int encode, const CELTMode *m, int start, int end, - celt_norm *X_, celt_norm *Y_, unsigned char *collapse_masks, - const celt_ener *bandE, int *pulses, int shortBlocks, int spread, - int dual_stereo, int intensity, int *tf_res, opus_int32 total_bits, - opus_int32 balance, ec_ctx *ec, int LM, int codedBands, - opus_uint32 *seed, int complexity, int arch, int disable_inv) { - int i; - opus_int32 remaining_bits; - const opus_int16 * OPUS_RESTRICT eBands = m->eBands; - celt_norm * OPUS_RESTRICT norm, * OPUS_RESTRICT norm2; - VARDECL(celt_norm, _norm); - VARDECL(celt_norm, _lowband_scratch); - VARDECL(celt_norm, X_save); - VARDECL(celt_norm, Y_save); - VARDECL(celt_norm, X_save2); - VARDECL(celt_norm, Y_save2); - VARDECL(celt_norm, norm_save2); - int resynth_alloc; - celt_norm *lowband_scratch; - int B; - int M; - int lowband_offset; - int update_lowband = 1; - int C = Y_ != NULL ? 2 : 1; - int norm_offset; - int theta_rdo = encode && Y_ != NULL && !dual_stereo && complexity >= 8; + celt_norm *X_, celt_norm *Y_, unsigned char *collapse_masks, + const celt_ener *bandE, int *pulses, int shortBlocks, int spread, + int dual_stereo, int intensity, int *tf_res, opus_int32 total_bits, + opus_int32 balance, ec_ctx *ec, int LM, int codedBands, + opus_uint32 *seed, int complexity, int arch, int disable_inv) +{ + int i; + opus_int32 remaining_bits; + const opus_int16 * OPUS_RESTRICT eBands = m->eBands; + celt_norm * OPUS_RESTRICT norm, * OPUS_RESTRICT norm2; + VARDECL(celt_norm, _norm); + VARDECL(celt_norm, _lowband_scratch); + VARDECL(celt_norm, X_save); + VARDECL(celt_norm, Y_save); + VARDECL(celt_norm, X_save2); + VARDECL(celt_norm, Y_save2); + VARDECL(celt_norm, norm_save2); + int resynth_alloc; + celt_norm *lowband_scratch; + int B; + int M; + int lowband_offset; + int update_lowband = 1; + int C = Y_ != NULL ? 2 : 1; + int norm_offset; + int theta_rdo = encode && Y_!=NULL && !dual_stereo && complexity>=8; #ifdef RESYNTH - int resynth = 1; + int resynth = 1; #else - int resynth = !encode || theta_rdo; + int resynth = !encode || theta_rdo; #endif - struct band_ctx ctx; - SAVE_STACK; + struct band_ctx ctx; + SAVE_STACK; - M = 1 << LM; - B = shortBlocks ? M : 1; - norm_offset = M * eBands[start]; - /* No need to allocate norm for the last band because we don't need an - output in that band. */ - ALLOC(_norm, C * (M * eBands[m->nbEBands - 1] - norm_offset), celt_norm); - norm = _norm; - norm2 = norm + M * eBands[m->nbEBands - 1] - norm_offset; + M = 1<nbEBands-1]-norm_offset), celt_norm); + norm = _norm; + norm2 = norm + M*eBands[m->nbEBands-1]-norm_offset; - /* For decoding, we can use the last band as scratch space because we don't need that - scratch space for the last band and we don't care about the data there until we're - decoding the last band. */ - if (encode && resynth) { - resynth_alloc = M * (eBands[m->nbEBands] - eBands[m->nbEBands - 1]); - } else { - resynth_alloc = ALLOC_NONE; - } - ALLOC(_lowband_scratch, resynth_alloc, celt_norm); - if (encode && resynth) { - lowband_scratch = _lowband_scratch; - } else { - lowband_scratch = X_ + M * eBands[m->nbEBands - 1]; - } - ALLOC(X_save, resynth_alloc, celt_norm); - ALLOC(Y_save, resynth_alloc, celt_norm); - ALLOC(X_save2, resynth_alloc, celt_norm); - ALLOC(Y_save2, resynth_alloc, celt_norm); - ALLOC(norm_save2, resynth_alloc, celt_norm); + /* For decoding, we can use the last band as scratch space because we don't need that + scratch space for the last band and we don't care about the data there until we're + decoding the last band. */ + if (encode && resynth) + resynth_alloc = M*(eBands[m->nbEBands]-eBands[m->nbEBands-1]); + else + resynth_alloc = ALLOC_NONE; + ALLOC(_lowband_scratch, resynth_alloc, celt_norm); + if (encode && resynth) + lowband_scratch = _lowband_scratch; + else + lowband_scratch = X_+M*eBands[m->effEBands-1]; + ALLOC(X_save, resynth_alloc, celt_norm); + ALLOC(Y_save, resynth_alloc, celt_norm); + ALLOC(X_save2, resynth_alloc, celt_norm); + ALLOC(Y_save2, resynth_alloc, celt_norm); + ALLOC(norm_save2, resynth_alloc, celt_norm); - lowband_offset = 0; - ctx.bandE = bandE; - ctx.ec = ec; - ctx.encode = encode; - ctx.intensity = intensity; - ctx.m = m; - ctx.seed = *seed; - ctx.spread = spread; - ctx.arch = arch; - ctx.disable_inv = disable_inv; - ctx.resynth = resynth; - ctx.theta_round = 0; - /* Avoid injecting noise in the first band on transients. */ - ctx.avoid_split_noise = B > 1; - for (i = start; i < end; i++) { - opus_int32 tell; - int b; - int N; - opus_int32 curr_balance; - int effective_lowband = -1; - celt_norm * OPUS_RESTRICT X, * OPUS_RESTRICT Y; - int tf_change = 0; - unsigned x_cm; - unsigned y_cm; - int last; + lowband_offset = 0; + ctx.bandE = bandE; + ctx.ec = ec; + ctx.encode = encode; + ctx.intensity = intensity; + ctx.m = m; + ctx.seed = *seed; + ctx.spread = spread; + ctx.arch = arch; + ctx.disable_inv = disable_inv; + ctx.resynth = resynth; + ctx.theta_round = 0; + /* Avoid injecting noise in the first band on transients. */ + ctx.avoid_split_noise = B > 1; + for (i=start;i 0); - tell = ec_tell_frac(ec); + X = X_+M*eBands[i]; + if (Y_!=NULL) + Y = Y_+M*eBands[i]; + else + Y = NULL; + N = M*eBands[i+1]-M*eBands[i]; + celt_assert(N > 0); + tell = ec_tell_frac(ec); - /* Compute how many bits we want to allocate to this band */ - if (i != start) { - balance -= tell; - } - remaining_bits = total_bits - tell - 1; - ctx.remaining_bits = remaining_bits; - if (i <= codedBands - 1) { - curr_balance = celt_sudiv(balance, IMIN(3, codedBands - i)); - b = IMAX(0, IMIN(16383, IMIN(remaining_bits + 1, pulses[i] + curr_balance))); - } else { - b = 0; - } + /* Compute how many bits we want to allocate to this band */ + if (i != start) + balance -= tell; + remaining_bits = total_bits-tell-1; + ctx.remaining_bits = remaining_bits; + if (i <= codedBands-1) + { + curr_balance = celt_sudiv(balance, IMIN(3, codedBands-i)); + b = IMAX(0, IMIN(16383, IMIN(remaining_bits+1,pulses[i]+curr_balance))); + } else { + b = 0; + } #ifndef DISABLE_UPDATE_DRAFT - if (resynth && (M * eBands[i] - N >= M * eBands[start] || i == start + 1) && (update_lowband || lowband_offset == 0)) { + if (resynth && (M*eBands[i]-N >= M*eBands[start] || i==start+1) && (update_lowband || lowband_offset==0)) lowband_offset = i; - } - if (i == start + 1) { - special_hybrid_folding(m, norm, norm2, start, M, dual_stereo); - } + if (i == start+1) + special_hybrid_folding(m, norm, norm2, start, M, dual_stereo); #else - if (resynth && M * eBands[i] - N >= M * eBands[start] && (update_lowband || lowband_offset == 0)) { + if (resynth && M*eBands[i]-N >= M*eBands[start] && (update_lowband || lowband_offset==0)) lowband_offset = i; - } #endif - tf_change = tf_res[i]; - ctx.tf_change = tf_change; - if (i >= m->effEBands) { - X = norm; - if (Y_ != NULL) { - Y = norm; - } - lowband_scratch = NULL; - } - if (last && !theta_rdo) { - lowband_scratch = NULL; - } + tf_change = tf_res[i]; + ctx.tf_change = tf_change; + if (i>=m->effEBands) + { + X=norm; + if (Y_!=NULL) + Y = norm; + lowband_scratch = NULL; + } + if (last && !theta_rdo) + lowband_scratch = NULL; - /* Get a conservative estimate of the collapse_mask's for the bands we're - going to be folding from. */ - if (lowband_offset != 0 && (spread != SPREAD_AGGRESSIVE || B > 1 || tf_change < 0)) { - int fold_start; - int fold_end; - int fold_i; - /* This ensures we never repeat spectral content within one band */ - effective_lowband = IMAX(0, M * eBands[lowband_offset] - norm_offset - N); - fold_start = lowband_offset; - while (M * eBands[--fold_start] > effective_lowband + norm_offset); - fold_end = lowband_offset - 1; + /* Get a conservative estimate of the collapse_mask's for the bands we're + going to be folding from. */ + if (lowband_offset != 0 && (spread!=SPREAD_AGGRESSIVE || B>1 || tf_change<0)) + { + int fold_start; + int fold_end; + int fold_i; + /* This ensures we never repeat spectral content within one band */ + effective_lowband = IMAX(0, M*eBands[lowband_offset]-norm_offset-N); + fold_start = lowband_offset; + while(M*eBands[--fold_start] > effective_lowband+norm_offset); + fold_end = lowband_offset-1; #ifndef DISABLE_UPDATE_DRAFT - while (++fold_end < i && M * eBands[fold_end] < effective_lowband + norm_offset + N); + while(++fold_end < i && M*eBands[fold_end] < effective_lowband+norm_offset+N); #else - while (M * eBands[++fold_end] < effective_lowband + norm_offset + N); + while(M*eBands[++fold_end] < effective_lowband+norm_offset+N); #endif - x_cm = y_cm = 0; - fold_i = fold_start; do { - x_cm |= collapse_masks[fold_i * C + 0]; - y_cm |= collapse_masks[fold_i * C + C - 1]; - } while (++fold_i < fold_end); - } - /* Otherwise, we'll be using the LCG to fold, so all blocks will (almost - always) be non-zero. */ - else { - x_cm = y_cm = (1 << B) - 1; - } + x_cm = y_cm = 0; + fold_i = fold_start; do { + x_cm |= collapse_masks[fold_i*C+0]; + y_cm |= collapse_masks[fold_i*C+C-1]; + } while (++fold_inbEBands], w); - /* Make a copy. */ - cm = x_cm | y_cm; - ec_save = *ec; - ctx_save = ctx; - OPUS_COPY(X_save, X, N); - OPUS_COPY(Y_save, Y, N); - /* Encode and round down. */ - ctx.theta_round = -1; - x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, - effective_lowband != -1 ? norm + effective_lowband : NULL, LM, - last ? NULL : norm + M * eBands[i] - norm_offset, lowband_scratch, cm); - dist0 = MULT16_32_Q15(w[0], celt_inner_prod(X_save, X, N, arch)) + MULT16_32_Q15(w[1], celt_inner_prod(Y_save, Y, N, arch)); + /* Switch off dual stereo to do intensity. */ + dual_stereo = 0; + if (resynth) + for (j=0;jnbEBands], w); + /* Make a copy. */ + cm = x_cm|y_cm; + ec_save = *ec; + ctx_save = ctx; + OPUS_COPY(X_save, X, N); + OPUS_COPY(Y_save, Y, N); + /* Encode and round down. */ + ctx.theta_round = -1; + x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, + effective_lowband != -1 ? norm+effective_lowband : NULL, LM, + last?NULL:norm+M*eBands[i]-norm_offset, lowband_scratch, cm); + dist0 = MULT16_32_Q15(w[0], celt_inner_prod(X_save, X, N, arch)) + MULT16_32_Q15(w[1], celt_inner_prod(Y_save, Y, N, arch)); - /* Save first result. */ - cm2 = x_cm; - ec_save2 = *ec; - ctx_save2 = ctx; - OPUS_COPY(X_save2, X, N); - OPUS_COPY(Y_save2, Y, N); - if (!last) { - OPUS_COPY(norm_save2, norm + M * eBands[i] - norm_offset, N); - } - nstart_bytes = ec_save.offs; - nend_bytes = ec_save.storage; - bytes_buf = ec_save.buf + nstart_bytes; - save_bytes = nend_bytes - nstart_bytes; - OPUS_COPY(bytes_save, bytes_buf, save_bytes); + /* Save first result. */ + cm2 = x_cm; + ec_save2 = *ec; + ctx_save2 = ctx; + OPUS_COPY(X_save2, X, N); + OPUS_COPY(Y_save2, Y, N); + if (!last) + OPUS_COPY(norm_save2, norm+M*eBands[i]-norm_offset, N); + nstart_bytes = ec_save.offs; + nend_bytes = ec_save.storage; + bytes_buf = ec_save.buf+nstart_bytes; + save_bytes = nend_bytes-nstart_bytes; + OPUS_COPY(bytes_save, bytes_buf, save_bytes); - /* Restore */ - *ec = ec_save; - ctx = ctx_save; - OPUS_COPY(X, X_save, N); - OPUS_COPY(Y, Y_save, N); + /* Restore */ + *ec = ec_save; + ctx = ctx_save; + OPUS_COPY(X, X_save, N); + OPUS_COPY(Y, Y_save, N); #ifndef DISABLE_UPDATE_DRAFT - if (i == start + 1) { - special_hybrid_folding(m, norm, norm2, start, M, dual_stereo); - } + if (i == start+1) + special_hybrid_folding(m, norm, norm2, start, M, dual_stereo); #endif - /* Encode and round up. */ - ctx.theta_round = 1; - x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, - effective_lowband != -1 ? norm + effective_lowband : NULL, LM, - last ? NULL : norm + M * eBands[i] - norm_offset, lowband_scratch, cm); - dist1 = MULT16_32_Q15(w[0], celt_inner_prod(X_save, X, N, arch)) + MULT16_32_Q15(w[1], celt_inner_prod(Y_save, Y, N, arch)); - if (dist0 >= dist1) { - x_cm = cm2; - *ec = ec_save2; - ctx = ctx_save2; - OPUS_COPY(X, X_save2, N); - OPUS_COPY(Y, Y_save2, N); - if (!last) { - OPUS_COPY(norm + M * eBands[i] - norm_offset, norm_save2, N); - } - OPUS_COPY(bytes_buf, bytes_save, save_bytes); - } - } else { - ctx.theta_round = 0; - x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, - effective_lowband != -1 ? norm + effective_lowband : NULL, LM, - last ? NULL : norm + M * eBands[i] - norm_offset, lowband_scratch, x_cm | y_cm); - } + /* Encode and round up. */ + ctx.theta_round = 1; + x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, + effective_lowband != -1 ? norm+effective_lowband : NULL, LM, + last?NULL:norm+M*eBands[i]-norm_offset, lowband_scratch, cm); + dist1 = MULT16_32_Q15(w[0], celt_inner_prod(X_save, X, N, arch)) + MULT16_32_Q15(w[1], celt_inner_prod(Y_save, Y, N, arch)); + if (dist0 >= dist1) { + x_cm = cm2; + *ec = ec_save2; + ctx = ctx_save2; + OPUS_COPY(X, X_save2, N); + OPUS_COPY(Y, Y_save2, N); + if (!last) + OPUS_COPY(norm+M*eBands[i]-norm_offset, norm_save2, N); + OPUS_COPY(bytes_buf, bytes_save, save_bytes); + } } else { - x_cm = quant_band(&ctx, X, N, b, B, - effective_lowband != -1 ? norm + effective_lowband : NULL, LM, - last ? NULL : norm + M * eBands[i] - norm_offset, Q15ONE, lowband_scratch, x_cm | y_cm); + ctx.theta_round = 0; + x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, + effective_lowband != -1 ? norm+effective_lowband : NULL, LM, + last?NULL:norm+M*eBands[i]-norm_offset, lowband_scratch, x_cm|y_cm); } - y_cm = x_cm; - } - collapse_masks[i * C + 0] = (unsigned char)x_cm; - collapse_masks[i * C + C - 1] = (unsigned char)y_cm; - balance += pulses[i] + tell; + } else { + x_cm = quant_band(&ctx, X, N, b, B, + effective_lowband != -1 ? norm+effective_lowband : NULL, LM, + last?NULL:norm+M*eBands[i]-norm_offset, Q15ONE, lowband_scratch, x_cm|y_cm); + } + y_cm = x_cm; + } + collapse_masks[i*C+0] = (unsigned char)x_cm; + collapse_masks[i*C+C-1] = (unsigned char)y_cm; + balance += pulses[i] + tell; - /* Update the folding position only as long as we have 1 bit/sample depth. */ - update_lowband = b > (N << BITRES); - /* We only need to avoid noise on a split for the first band. After that, we - have folding. */ - ctx.avoid_split_noise = 0; - } - *seed = ctx.seed; + /* Update the folding position only as long as we have 1 bit/sample depth. */ + update_lowband = b>(N<nbEBands; i++) { - int N; - N = (m->eBands[i + 1] - m->eBands[i]) << LM; - cap[i] = (m->cache.caps[m->nbEBands * (2 * LM + C - 1) + i] + 64) * C * N >> 2; - } +void init_caps(const CELTMode *m,int *cap,int LM,int C) +{ + int i; + for (i=0;inbEBands;i++) + { + int N; + N=(m->eBands[i+1]-m->eBands[i])<cache.caps[m->nbEBands*(2*LM+C-1)+i]+64)*C*N>>2; + } } -const char *opus_strerror(int error) { - static const char * const error_strings[8] = { - "success", - "invalid argument", - "buffer too small", - "internal error", - "corrupted stream", - "request not implemented", - "invalid state", - "memory allocation failed" - }; - if (error > 0 || error < -7) { - return "unknown error"; - } else { - return error_strings[-error]; - } +const char *opus_strerror(int error) +{ + static const char * const error_strings[8] = { + "success", + "invalid argument", + "buffer too small", + "internal error", + "corrupted stream", + "request not implemented", + "invalid state", + "memory allocation failed" + }; + if (error > 0 || error < -7) + return "unknown error"; + else + return error_strings[-error]; } -const char *opus_get_version_string(void) { +const char *opus_get_version_string(void) +{ return "libopus " PACKAGE_VERSION - /* Applications may rely on the presence of this substring in the version - string to determine if they have a fixed-point or floating-point build - at runtime. */ + /* Applications may rely on the presence of this substring in the version + string to determine if they have a fixed-point or floating-point build + at runtime. */ #ifdef FIXED_POINT - "-fixed" + "-fixed" #endif #ifdef FUZZING - "-fuzzing" + "-fuzzing" #endif - ; + ; } diff --git a/src/libopus/celt/celt.h b/src/libopus/celt/celt.h index 5693453..2f50195 100644 --- a/src/libopus/celt/celt.h +++ b/src/libopus/celt/celt.h @@ -1,47 +1,51 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2008 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2008 Gregory Maxwell + Written by Jean-Marc Valin and Gregory Maxwell */ /** - @file celt.h - @brief Contains all the functions for encoding and decoding audio -*/ + @file celt.h + @brief Contains all the functions for encoding and decoding audio + */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef CELT_H #define CELT_H -#include "../opus_types.h" -#include "../opus_defines.h" -#include "../opus_custom.h" +#include "opus_types.h" +#include "opus_defines.h" +#include "opus_custom.h" #include "entenc.h" #include "entdec.h" #include "arch.h" +#ifdef ENABLE_DEEP_PLC +#include "lpcnet.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -53,24 +57,24 @@ extern "C" { #define LEAK_BANDS 19 typedef struct { - int valid; - float tonality; - float tonality_slope; - float noisiness; - float activity; - float music_prob; - float music_prob_min; - float music_prob_max; - int bandwidth; - float activity_probability; - float max_pitch_ratio; - /* Store as Q6 char to save space. */ - unsigned char leak_boost[LEAK_BANDS]; + int valid; + float tonality; + float tonality_slope; + float noisiness; + float activity; + float music_prob; + float music_prob_min; + float music_prob_max; + int bandwidth; + float activity_probability; + float max_pitch_ratio; + /* Store as Q6 char to save space. */ + unsigned char leak_boost[LEAK_BANDS]; } AnalysisInfo; typedef struct { - int signalType; - int offset; + int signalType; + int offset; } SILKInfo; #define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr))) @@ -87,7 +91,7 @@ typedef struct { 0=Independent frames 1=Short term interframe prediction allowed 2=Long term prediction allowed -*/ + */ #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x) #define CELT_SET_INPUT_CLIPPING_REQUEST 10004 @@ -149,8 +153,15 @@ int celt_decoder_get_size(int channels); int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels); +int celt_decode_with_ec_dred(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, + int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum +#ifdef ENABLE_DEEP_PLC + ,LPCNetPLCState *lpcnet +#endif + ); + int celt_decode_with_ec(OpusCustomDecoder * OPUS_RESTRICT st, const unsigned char *data, - int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum); + int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum); #define celt_encoder_ctl opus_custom_encoder_ctl #define celt_decoder_ctl opus_custom_decoder_ctl @@ -166,42 +177,41 @@ static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4 /* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */ static const unsigned char spread_icdf[4] = {25, 23, 2, 0}; -static const unsigned char tapset_icdf[3] = {2, 1, 0}; +static const unsigned char tapset_icdf[3]={2,1,0}; #ifdef CUSTOM_MODES static const unsigned char toOpusTable[20] = { - 0xE0, 0xE8, 0xF0, 0xF8, - 0xC0, 0xC8, 0xD0, 0xD8, - 0xA0, 0xA8, 0xB0, 0xB8, - 0x00, 0x00, 0x00, 0x00, - 0x80, 0x88, 0x90, 0x98, + 0xE0, 0xE8, 0xF0, 0xF8, + 0xC0, 0xC8, 0xD0, 0xD8, + 0xA0, 0xA8, 0xB0, 0xB8, + 0x00, 0x00, 0x00, 0x00, + 0x80, 0x88, 0x90, 0x98, }; static const unsigned char fromOpusTable[16] = { - 0x80, 0x88, 0x90, 0x98, - 0x40, 0x48, 0x50, 0x58, - 0x20, 0x28, 0x30, 0x38, - 0x00, 0x08, 0x10, 0x18 + 0x80, 0x88, 0x90, 0x98, + 0x40, 0x48, 0x50, 0x58, + 0x20, 0x28, 0x30, 0x38, + 0x00, 0x08, 0x10, 0x18 }; -static OPUS_INLINE int toOpus(unsigned char c) { - int ret = 0; - if (c < 0xA0) { - ret = toOpusTable[c >> 3]; - } - if (ret == 0) { - return -1; - } else { - return ret | (c & 0x7); - } +static OPUS_INLINE int toOpus(unsigned char c) +{ + int ret=0; + if (c<0xA0) + ret = toOpusTable[c>>3]; + if (ret == 0) + return -1; + else + return ret|(c&0x7); } -static OPUS_INLINE int fromOpus(unsigned char c) { - if (c < 0x80) { - return -1; - } else { - return fromOpusTable[(c >> 3) - 16] | (c & 0x7); - } +static OPUS_INLINE int fromOpus(unsigned char c) +{ + if (c<0x80) + return -1; + else + return fromOpusTable[(c>>3)-16] | (c&0x7); } #endif /* CUSTOM_MODES */ @@ -220,29 +230,19 @@ void validate_celt_decoder(CELTDecoder *st); int resampling_factor(opus_int32 rate); void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp, - int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip); + int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip); void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, - opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, - const opus_val16 *window, int overlap, int arch); + opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, + const opus_val16 *window, int overlap, int arch); -#ifdef NON_STATIC_COMB_FILTER_CONST_C -void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N, - opus_val16 g10, opus_val16 g11, opus_val16 g12); -#endif - -#ifndef OVERRIDE_COMB_FILTER_CONST -# define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \ - ((void)(arch),comb_filter_const_c(y, x, T, N, g10, g11, g12)) -#endif - -void init_caps(const CELTMode *m, int *cap, int LM, int C); +void init_caps(const CELTMode *m,int *cap,int LM,int C); #ifdef RESYNTH -void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem); +void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem, int accum); void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[], - opus_val16 *oldBandE, int start, int effEnd, int C, int CC, int isTransient, - int LM, int downsample, int silence); + opus_val16 *oldBandE, int start, int effEnd, int C, int CC, int isTransient, + int LM, int downsample, int silence, int arch); #endif #ifdef __cplusplus diff --git a/src/libopus/celt/celt_decoder.c b/src/libopus/celt/celt_decoder.c index 6800572..3e50eb2 100644 --- a/src/libopus/celt/celt_decoder.c +++ b/src/libopus/celt/celt_decoder.c @@ -1,35 +1,35 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2010 Xiph.Org Foundation - Copyright (c) 2008 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2010 Xiph.Org Foundation + Copyright (c) 2008 Gregory Maxwell + Written by Jean-Marc Valin and Gregory Maxwell */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #define CELT_DECODER_C @@ -51,17 +51,19 @@ #include "celt_lpc.h" #include "vq.h" -/* The maximum pitch lag to allow in the pitch-based PLC. It's possible to save - CPU time in the PLC pitch search by making this smaller than MAX_PERIOD. The - current value corresponds to a pitch of 66.67 Hz. */ +#ifdef ENABLE_DEEP_PLC +#include "lpcnet.h" +#include "lpcnet_private.h" +#endif + +/* The maximum pitch lag to allow in the pitch-based PLC. It's possible to save + CPU time in the PLC pitch search by making this smaller than MAX_PERIOD. The + current value corresponds to a pitch of 66.67 Hz. */ #define PLC_PITCH_LAG_MAX (720) -/* The minimum pitch lag to allow in the pitch-based PLC. This corresponds to a - pitch of 480 Hz. */ +/* The minimum pitch lag to allow in the pitch-based PLC. This corresponds to a + pitch of 480 Hz. */ #define PLC_PITCH_LAG_MIN (100) -#if defined(SMALL_FOOTPRINT) && defined(FIXED_POINT) -#define NORM_ALIASING_HACK -#endif /**********************************************************************/ /* */ /* DECODER */ @@ -69,183 +71,205 @@ /**********************************************************************/ #define DECODE_BUFFER_SIZE 2048 +#define PLC_UPDATE_FRAMES 4 +#define PLC_UPDATE_SAMPLES (PLC_UPDATE_FRAMES*FRAME_SIZE) + /** Decoder state - @brief Decoder state -*/ + @brief Decoder state + */ struct OpusCustomDecoder { - const OpusCustomMode *mode; - int overlap; - int channels; - int stream_channels; + const OpusCustomMode *mode; + int overlap; + int channels; + int stream_channels; - int downsample; - int start, end; - int signalling; - int disable_inv; - int arch; + int downsample; + int start, end; + int signalling; + int disable_inv; + int complexity; + int arch; - /* Everything beyond this point gets cleared on a reset */ + /* Everything beyond this point gets cleared on a reset */ #define DECODER_RESET_START rng - opus_uint32 rng; - int error; - int last_pitch_index; - int loss_count; - int skip_plc; - int postfilter_period; - int postfilter_period_old; - opus_val16 postfilter_gain; - opus_val16 postfilter_gain_old; - int postfilter_tapset; - int postfilter_tapset_old; + opus_uint32 rng; + int error; + int last_pitch_index; + int loss_duration; + int skip_plc; + int postfilter_period; + int postfilter_period_old; + opus_val16 postfilter_gain; + opus_val16 postfilter_gain_old; + int postfilter_tapset; + int postfilter_tapset_old; + int prefilter_and_fold; - celt_sig preemph_memD[2]; + celt_sig preemph_memD[2]; - celt_sig _decode_mem[1]; /* Size = channels*(DECODE_BUFFER_SIZE+mode->overlap) */ - /* opus_val16 lpc[], Size = channels*LPC_ORDER */ - /* opus_val16 oldEBands[], Size = 2*mode->nbEBands */ - /* opus_val16 oldLogE[], Size = 2*mode->nbEBands */ - /* opus_val16 oldLogE2[], Size = 2*mode->nbEBands */ - /* opus_val16 backgroundLogE[], Size = 2*mode->nbEBands */ +#ifdef ENABLE_DEEP_PLC + opus_int16 plc_pcm[PLC_UPDATE_SAMPLES]; + int plc_fill; + float plc_preemphasis_mem; +#endif + + celt_sig _decode_mem[1]; /* Size = channels*(DECODE_BUFFER_SIZE+mode->overlap) */ + /* opus_val16 lpc[], Size = channels*CELT_LPC_ORDER */ + /* opus_val16 oldEBands[], Size = 2*mode->nbEBands */ + /* opus_val16 oldLogE[], Size = 2*mode->nbEBands */ + /* opus_val16 oldLogE2[], Size = 2*mode->nbEBands */ + /* opus_val16 backgroundLogE[], Size = 2*mode->nbEBands */ }; #if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS) -/* Make basic checks on the CELT state to ensure we don't end - up writing all over memory. */ -void validate_celt_decoder(CELTDecoder *st) { +/* Make basic checks on the CELT state to ensure we don't end + up writing all over memory. */ +void validate_celt_decoder(CELTDecoder *st) +{ #ifndef CUSTOM_MODES - celt_assert(st->mode == opus_custom_mode_create(48000, 960, NULL)); - celt_assert(st->overlap == 120); -#endif - celt_assert(st->channels == 1 || st->channels == 2); - celt_assert(st->stream_channels == 1 || st->stream_channels == 2); - celt_assert(st->downsample > 0); - celt_assert(st->start == 0 || st->start == 17); - celt_assert(st->start < st->end); - celt_assert(st->end <= 21); -#ifdef OPUS_ARCHMASK - celt_assert(st->arch >= 0); - celt_assert(st->arch <= OPUS_ARCHMASK); -#endif - celt_assert(st->last_pitch_index <= PLC_PITCH_LAG_MAX); - celt_assert(st->last_pitch_index >= PLC_PITCH_LAG_MIN || st->last_pitch_index == 0); - celt_assert(st->postfilter_period < MAX_PERIOD); - celt_assert(st->postfilter_period >= COMBFILTER_MINPERIOD || st->postfilter_period == 0); - celt_assert(st->postfilter_period_old < MAX_PERIOD); - celt_assert(st->postfilter_period_old >= COMBFILTER_MINPERIOD || st->postfilter_period_old == 0); - celt_assert(st->postfilter_tapset <= 2); - celt_assert(st->postfilter_tapset >= 0); - celt_assert(st->postfilter_tapset_old <= 2); - celt_assert(st->postfilter_tapset_old >= 0); -} -#endif - -int celt_decoder_get_size(int channels) { - const CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); - return opus_custom_decoder_get_size(mode, channels); -} - -OPUS_CUSTOM_NOSTATIC int opus_custom_decoder_get_size(const CELTMode *mode, int channels) { - int size = sizeof(struct CELTDecoder) - + (channels * (DECODE_BUFFER_SIZE + mode->overlap) - 1) * sizeof(celt_sig) - + channels * LPC_ORDER * sizeof(opus_val16) - + 4 * 2 * mode->nbEBands * sizeof(opus_val16); - return size; -} - -#ifdef CUSTOM_MODES -CELTDecoder *opus_custom_decoder_create(const CELTMode *mode, int channels, int *error) { - int ret; - CELTDecoder *st = (CELTDecoder *)opus_alloc(opus_custom_decoder_get_size(mode, channels)); - ret = opus_custom_decoder_init(st, mode, channels); - if (ret != OPUS_OK) { - opus_custom_decoder_destroy(st); - st = NULL; - } - if (error) { - *error = ret; - } - return st; -} -#endif /* CUSTOM_MODES */ - -int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels) { - int ret; - ret = opus_custom_decoder_init(st, opus_custom_mode_create(48000, 960, NULL), channels); - if (ret != OPUS_OK) { - return ret; - } - st->downsample = resampling_factor(sampling_rate); - if (st->downsample == 0) { - return OPUS_BAD_ARG; - } else { - return OPUS_OK; - } -} - -OPUS_CUSTOM_NOSTATIC int opus_custom_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels) { - if (channels < 0 || channels > 2) { - return OPUS_BAD_ARG; - } - - if (st == NULL) { - return OPUS_ALLOC_FAIL; - } - - OPUS_CLEAR((char*)st, opus_custom_decoder_get_size(mode, channels)); - - st->mode = mode; - st->overlap = mode->overlap; - st->stream_channels = st->channels = channels; - - st->downsample = 1; - st->start = 0; - st->end = st->mode->effEBands; - st->signalling = 1; -#ifndef DISABLE_UPDATE_DRAFT - st->disable_inv = channels == 1; + celt_assert(st->mode == opus_custom_mode_create(48000, 960, NULL)); + celt_assert(st->overlap == 120); + celt_assert(st->end <= 21); #else - st->disable_inv = 0; +/* From Section 4.3 in the spec: "The normal CELT layer uses 21 of those bands, + though Opus Custom (see Section 6.2) may use a different number of bands" + + Check if it's within the maximum number of Bark frequency bands instead */ + celt_assert(st->end <= 25); +#endif + celt_assert(st->channels == 1 || st->channels == 2); + celt_assert(st->stream_channels == 1 || st->stream_channels == 2); + celt_assert(st->downsample > 0); + celt_assert(st->start == 0 || st->start == 17); + celt_assert(st->start < st->end); +#ifdef OPUS_ARCHMASK + celt_assert(st->arch >= 0); + celt_assert(st->arch <= OPUS_ARCHMASK); +#endif + celt_assert(st->last_pitch_index <= PLC_PITCH_LAG_MAX); + celt_assert(st->last_pitch_index >= PLC_PITCH_LAG_MIN || st->last_pitch_index == 0); + celt_assert(st->postfilter_period < MAX_PERIOD); + celt_assert(st->postfilter_period >= COMBFILTER_MINPERIOD || st->postfilter_period == 0); + celt_assert(st->postfilter_period_old < MAX_PERIOD); + celt_assert(st->postfilter_period_old >= COMBFILTER_MINPERIOD || st->postfilter_period_old == 0); + celt_assert(st->postfilter_tapset <= 2); + celt_assert(st->postfilter_tapset >= 0); + celt_assert(st->postfilter_tapset_old <= 2); + celt_assert(st->postfilter_tapset_old >= 0); +} #endif - st->arch = opus_select_arch(); - opus_custom_decoder_ctl(st, OPUS_RESET_STATE); +int celt_decoder_get_size(int channels) +{ + const CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); + return opus_custom_decoder_get_size(mode, channels); +} - return OPUS_OK; +OPUS_CUSTOM_NOSTATIC int opus_custom_decoder_get_size(const CELTMode *mode, int channels) +{ + int size = sizeof(struct CELTDecoder) + + (channels*(DECODE_BUFFER_SIZE+mode->overlap)-1)*sizeof(celt_sig) + + channels*CELT_LPC_ORDER*sizeof(opus_val16) + + 4*2*mode->nbEBands*sizeof(opus_val16); + return size; } #ifdef CUSTOM_MODES -void opus_custom_decoder_destroy(CELTDecoder *st) { - opus_free(st); +CELTDecoder *opus_custom_decoder_create(const CELTMode *mode, int channels, int *error) +{ + int ret; + CELTDecoder *st = (CELTDecoder *)opus_alloc(opus_custom_decoder_get_size(mode, channels)); + ret = opus_custom_decoder_init(st, mode, channels); + if (ret != OPUS_OK) + { + opus_custom_decoder_destroy(st); + st = NULL; + } + if (error) + *error = ret; + return st; +} +#endif /* CUSTOM_MODES */ + +int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels) +{ + int ret; + ret = opus_custom_decoder_init(st, opus_custom_mode_create(48000, 960, NULL), channels); + if (ret != OPUS_OK) + return ret; + st->downsample = resampling_factor(sampling_rate); + if (st->downsample==0) + return OPUS_BAD_ARG; + else + return OPUS_OK; +} + +OPUS_CUSTOM_NOSTATIC int opus_custom_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels) +{ + if (channels < 0 || channels > 2) + return OPUS_BAD_ARG; + + if (st==NULL) + return OPUS_ALLOC_FAIL; + + OPUS_CLEAR((char*)st, opus_custom_decoder_get_size(mode, channels)); + + st->mode = mode; + st->overlap = mode->overlap; + st->stream_channels = st->channels = channels; + + st->downsample = 1; + st->start = 0; + st->end = st->mode->effEBands; + st->signalling = 1; +#ifndef DISABLE_UPDATE_DRAFT + st->disable_inv = channels == 1; +#else + st->disable_inv = 0; +#endif + st->arch = opus_select_arch(); + + opus_custom_decoder_ctl(st, OPUS_RESET_STATE); + + return OPUS_OK; +} + +#ifdef CUSTOM_MODES +void opus_custom_decoder_destroy(CELTDecoder *st) +{ + opus_free(st); } #endif /* CUSTOM_MODES */ #ifndef CUSTOM_MODES -/* Special case for stereo with no downsampling and no accumulation. This is - quite common and we can make it faster by processing both channels in the - same loop, reducing overhead due to the dependency loop in the IIR filter. */ +/* Special case for stereo with no downsampling and no accumulation. This is + quite common and we can make it faster by processing both channels in the + same loop, reducing overhead due to the dependency loop in the IIR filter. */ static void deemphasis_stereo_simple(celt_sig *in[], opus_val16 *pcm, int N, const opus_val16 coef0, - celt_sig *mem) { - celt_sig * OPUS_RESTRICT x0; - celt_sig * OPUS_RESTRICT x1; - celt_sig m0, m1; - int j; - x0 = in[0]; - x1 = in[1]; - m0 = mem[0]; - m1 = mem[1]; - for (j = 0; j < N; j++) { - celt_sig tmp0, tmp1; - /* Add VERY_SMALL to x[] first to reduce dependency chain. */ - tmp0 = x0[j] + VERY_SMALL + m0; - tmp1 = x1[j] + VERY_SMALL + m1; - m0 = MULT16_32_Q15(coef0, tmp0); - m1 = MULT16_32_Q15(coef0, tmp1); - pcm[2 * j ] = SCALEOUT(SIG2WORD16(tmp0)); - pcm[2 * j + 1] = SCALEOUT(SIG2WORD16(tmp1)); - } - mem[0] = m0; - mem[1] = m1; + celt_sig *mem) +{ + celt_sig * OPUS_RESTRICT x0; + celt_sig * OPUS_RESTRICT x1; + celt_sig m0, m1; + int j; + x0=in[0]; + x1=in[1]; + m0 = mem[0]; + m1 = mem[1]; + for (j=0;j 1) { - /* Shortcut for the standard (non-custom modes) case */ - for (j = 0; j < N; j++) { - celt_sig tmp = x[j] + VERY_SMALL + m; - m = MULT16_32_Q15(coef0, tmp); - scratch[j] = tmp; - } - apply_downsampling = 1; - } else { - /* Shortcut for the standard (non-custom modes) case */ + if (downsample>1) + { + /* Shortcut for the standard (non-custom modes) case */ + for (j=0;joverlap; - nbEBands = mode->nbEBands; - N = mode->shortMdctSize << LM; - ALLOC(freq, N, celt_sig); /**< Interleaved signal MDCTs */ - M = 1 << LM; + overlap = mode->overlap; + nbEBands = mode->nbEBands; + N = mode->shortMdctSize<shortMdctSize; - shift = mode->maxLM; - } else { - B = 1; - NB = mode->shortMdctSize << LM; - shift = mode->maxLM - LM; - } + if (isTransient) + { + B = M; + NB = mode->shortMdctSize; + shift = mode->maxLM; + } else { + B = 1; + NB = mode->shortMdctSize<maxLM-LM; + } - if (CC == 2 && C == 1) { - /* Copying a mono streams to two channels */ - celt_sig *freq2; - denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M, - downsample, silence); - /* Store a temporary copy in the output buffer because the IMDCT destroys its input. */ - freq2 = out_syn[1] + overlap / 2; - OPUS_COPY(freq2, freq, N); - for (b = 0; b < B; b++) { - clt_mdct_backward(&mode->mdct, &freq2[b], out_syn[0] + NB * b, mode->window, overlap, shift, B, arch); - } - for (b = 0; b < B; b++) { - clt_mdct_backward(&mode->mdct, &freq[b], out_syn[1] + NB * b, mode->window, overlap, shift, B, arch); - } - } else if (CC == 1 && C == 2) { - /* Downmixing a stereo stream to mono */ - celt_sig *freq2; - freq2 = out_syn[0] + overlap / 2; - denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M, - downsample, silence); - /* Use the output buffer as temp array before downmixing. */ - denormalise_bands(mode, X + N, freq2, oldBandE + nbEBands, start, effEnd, M, - downsample, silence); - for (i = 0; i < N; i++) { - freq[i] = ADD32(HALF32(freq[i]), HALF32(freq2[i])); - } - for (b = 0; b < B; b++) { - clt_mdct_backward(&mode->mdct, &freq[b], out_syn[0] + NB * b, mode->window, overlap, shift, B, arch); - } - } else { - /* Normal case (mono or stereo) */ - c = 0; do { - denormalise_bands(mode, X + c * N, freq, oldBandE + c * nbEBands, start, effEnd, M, - downsample, silence); - for (b = 0; b < B; b++) { - clt_mdct_backward(&mode->mdct, &freq[b], out_syn[c] + NB * b, mode->window, overlap, shift, B, arch); - } - } while (++c < CC); - } - /* Saturate IMDCT output so that we can't overflow in the pitch postfilter - or in the */ - c = 0; do { - for (i = 0; i < N; i++) { - out_syn[c][i] = SATURATE(out_syn[c][i], SIG_SAT); - } - } while (++c < CC); - RESTORE_STACK; + if (CC==2&&C==1) + { + /* Copying a mono streams to two channels */ + celt_sig *freq2; + denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M, + downsample, silence); + /* Store a temporary copy in the output buffer because the IMDCT destroys its input. */ + freq2 = out_syn[1]+overlap/2; + OPUS_COPY(freq2, freq, N); + for (b=0;bmdct, &freq2[b], out_syn[0]+NB*b, mode->window, overlap, shift, B, arch); + for (b=0;bmdct, &freq[b], out_syn[1]+NB*b, mode->window, overlap, shift, B, arch); + } else if (CC==1&&C==2) + { + /* Downmixing a stereo stream to mono */ + celt_sig *freq2; + freq2 = out_syn[0]+overlap/2; + denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M, + downsample, silence); + /* Use the output buffer as temp array before downmixing. */ + denormalise_bands(mode, X+N, freq2, oldBandE+nbEBands, start, effEnd, M, + downsample, silence); + for (i=0;imdct, &freq[b], out_syn[0]+NB*b, mode->window, overlap, shift, B, arch); + } else { + /* Normal case (mono or stereo) */ + c=0; do { + denormalise_bands(mode, X+c*N, freq, oldBandE+c*nbEBands, start, effEnd, M, + downsample, silence); + for (b=0;bmdct, &freq[b], out_syn[c]+NB*b, mode->window, overlap, shift, B, arch); + } while (++cstorage * 8; - tell = ec_tell(dec); - logp = isTransient ? 2 : 4; - tf_select_rsv = LM > 0 && tell + logp + 1 <= budget; - budget -= tf_select_rsv; - tf_changed = curr = 0; - for (i = start; i < end; i++) { - if (tell + logp <= budget) { - curr ^= ec_dec_bit_logp(dec, logp); - tell = ec_tell(dec); - tf_changed |= curr; - } - tf_res[i] = curr; - logp = isTransient ? 4 : 5; - } - tf_select = 0; - if (tf_select_rsv && - tf_select_table[LM][4 * isTransient + 0 + tf_changed] != - tf_select_table[LM][4 * isTransient + 2 + tf_changed]) { - tf_select = ec_dec_bit_logp(dec, 1); - } - for (i = start; i < end; i++) { - tf_res[i] = tf_select_table[LM][4 * isTransient + 2 * tf_select + tf_res[i]]; - } + budget = dec->storage*8; + tell = ec_tell(dec); + logp = isTransient ? 2 : 4; + tf_select_rsv = LM>0 && tell+logp+1<=budget; + budget -= tf_select_rsv; + tf_changed = curr = 0; + for (i=start;i> 1) * sizeof(opus_val16)); //ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 ); - pitch_downsample(decode_mem, lp_pitch_buf, - DECODE_BUFFER_SIZE, C, arch); - pitch_search(lp_pitch_buf + (PLC_PITCH_LAG_MAX >> 1), lp_pitch_buf, - DECODE_BUFFER_SIZE - PLC_PITCH_LAG_MAX, - PLC_PITCH_LAG_MAX - PLC_PITCH_LAG_MIN, &pitch_index, arch); - pitch_index = PLC_PITCH_LAG_MAX - pitch_index; - RESTORE_STACK; - free(lp_pitch_buf); - return pitch_index; +static int celt_plc_pitch_search(celt_sig *decode_mem[2], int C, int arch) +{ + int pitch_index; + VARDECL( opus_val16, lp_pitch_buf ); + SAVE_STACK; + ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 ); + pitch_downsample(decode_mem, lp_pitch_buf, + DECODE_BUFFER_SIZE, C, arch); + pitch_search(lp_pitch_buf+(PLC_PITCH_LAG_MAX>>1), lp_pitch_buf, + DECODE_BUFFER_SIZE-PLC_PITCH_LAG_MAX, + PLC_PITCH_LAG_MAX-PLC_PITCH_LAG_MIN, &pitch_index, arch); + pitch_index = PLC_PITCH_LAG_MAX-pitch_index; + RESTORE_STACK; + return pitch_index; } -static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) { - int c; - int i; - const int C = st->channels; - celt_sig *decode_mem[2]; - celt_sig *out_syn[2]; - opus_val16 *lpc; - opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE; - const OpusCustomMode *mode; - int nbEBands; - int overlap; - int start; - int loss_count; - int noise_based; - const opus_int16 *eBands; - SAVE_STACK; +static void prefilter_and_fold(CELTDecoder * OPUS_RESTRICT st, int N) +{ + int c; + int CC; + int i; + int overlap; + celt_sig *decode_mem[2]; + const OpusCustomMode *mode; + VARDECL(opus_val32, etmp); + mode = st->mode; + overlap = st->overlap; + CC = st->channels; + ALLOC(etmp, overlap, opus_val32); + c=0; do { + decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+overlap); + } while (++cmode; - nbEBands = mode->nbEBands; - overlap = mode->overlap; - eBands = mode->eBands; + c=0; do { + /* Apply the pre-filter to the MDCT overlap for the next frame because + the post-filter will be re-applied in the decoder after the MDCT + overlap. */ + comb_filter(etmp, decode_mem[c]+DECODE_BUFFER_SIZE-N, + st->postfilter_period_old, st->postfilter_period, overlap, + -st->postfilter_gain_old, -st->postfilter_gain, + st->postfilter_tapset_old, st->postfilter_tapset, NULL, 0, st->arch); - c = 0; do { - decode_mem[c] = st->_decode_mem + c * (DECODE_BUFFER_SIZE + overlap); - out_syn[c] = decode_mem[c] + DECODE_BUFFER_SIZE - N; - } while (++c < C); - lpc = (opus_val16*)(st->_decode_mem + (DECODE_BUFFER_SIZE + overlap) * C); - oldBandE = lpc + C * LPC_ORDER; - oldLogE = oldBandE + 2 * nbEBands; - oldLogE2 = oldLogE + 2 * nbEBands; - backgroundLogE = oldLogE2 + 2 * nbEBands; + /* Simulate TDAC on the concealed audio so that it blends with the + MDCT of the next frame. */ + for (i=0;iwindow[i], etmp[overlap-1-i]) + + MULT16_32_Q15(mode->window[overlap-i-1], etmp[i]); + } + } while (++closs_count; - start = st->start; - noise_based = loss_count >= 5 || start != 0 || st->skip_plc; - if (noise_based) { - /* Noise-based PLC/CNG */ -#ifdef NORM_ALIASING_HACK - celt_norm *X; -#else - VARDECL(celt_norm, X); -#endif - opus_uint32 seed; - int end; - int effEnd; - opus_val16 decay; - end = st->end; - effEnd = IMAX(start, IMIN(end, mode->effEBands)); +#ifdef ENABLE_DEEP_PLC -#ifdef NORM_ALIASING_HACK - /* This is an ugly hack that breaks aliasing rules and would be easily broken, - but it saves almost 4kB of stack. */ - X = (celt_norm*)(out_syn[C - 1] + overlap / 2); -#else - ALLOC(X, C * N, celt_norm); /**< Interleaved normalised MDCTs */ +#define SINC_ORDER 48 +/* h=cos(pi/2*abs(sin([-24:24]/48*pi*23./24)).^2); + b=sinc([-24:24]/3*1.02).*h; + b=b/sum(b); */ +static const float sinc_filter[SINC_ORDER+1] = { + 4.2931e-05f, -0.000190293f, -0.000816132f, -0.000637162f, 0.00141662f, 0.00354764f, 0.00184368f, -0.00428274f, + -0.00856105f, -0.0034003f, 0.00930201f, 0.0159616f, 0.00489785f, -0.0169649f, -0.0259484f, -0.00596856f, + 0.0286551f, 0.0405872f, 0.00649994f, -0.0509284f, -0.0716655f, -0.00665212f, 0.134336f, 0.278927f, + 0.339995f, 0.278927f, 0.134336f, -0.00665212f, -0.0716655f, -0.0509284f, 0.00649994f, 0.0405872f, + 0.0286551f, -0.00596856f, -0.0259484f, -0.0169649f, 0.00489785f, 0.0159616f, 0.00930201f, -0.0034003f, + -0.00856105f, -0.00428274f, 0.00184368f, 0.00354764f, 0.00141662f, -0.000637162f, -0.000816132f, -0.000190293f, + 4.2931e-05f +}; + +void update_plc_state(LPCNetPLCState *lpcnet, celt_sig *decode_mem[2], float *plc_preemphasis_mem, int CC) +{ + int i; + int tmp_read_post, tmp_fec_skip; + int offset; + celt_sig buf48k[DECODE_BUFFER_SIZE]; + opus_int16 buf16k[PLC_UPDATE_SAMPLES]; + if (CC == 1) OPUS_COPY(buf48k, decode_mem[0], DECODE_BUFFER_SIZE); + else { + for (i=0;ifec_read_pos; + tmp_fec_skip = lpcnet->fec_skip; + for (i=0;ifec_read_pos = tmp_read_post; + lpcnet->fec_skip = tmp_fec_skip; +} #endif - /* Energy decay */ - decay = loss_count == 0 ? QCONST16(1.5f, DB_SHIFT) : QCONST16(.5f, DB_SHIFT); - c = 0; do { - for (i = start; i < end; i++) { - oldBandE[c * nbEBands + i] = MAX16(backgroundLogE[c * nbEBands + i], oldBandE[c * nbEBands + i] - decay); - } - } while (++c < C); - seed = st->rng; - for (c = 0; c < C; c++) { - for (i = start; i < effEnd; i++) { - int j; - int boffs; - int blen; - boffs = N * c + (eBands[i] << LM); - blen = (eBands[i + 1] - eBands[i]) << LM; - for (j = 0; j < blen; j++) { - seed = celt_lcg_rand(seed); - X[boffs + j] = (celt_norm)((opus_int32)seed >> 20); - } - renormalise_vector(X + boffs, blen, Q15ONE, st->arch); - } - } - st->rng = seed; +static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM +#ifdef ENABLE_DEEP_PLC + ,LPCNetPLCState *lpcnet +#endif + ) +{ + int c; + int i; + const int C = st->channels; + celt_sig *decode_mem[2]; + celt_sig *out_syn[2]; + opus_val16 *lpc; + opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE; + const OpusCustomMode *mode; + int nbEBands; + int overlap; + int start; + int loss_duration; + int noise_based; + const opus_int16 *eBands; + SAVE_STACK; - c = 0; do { - OPUS_MOVE(decode_mem[c], decode_mem[c] + N, - DECODE_BUFFER_SIZE - N + (overlap >> 1)); - } while (++c < C); + mode = st->mode; + nbEBands = mode->nbEBands; + overlap = mode->overlap; + eBands = mode->eBands; - celt_synthesis(mode, X, out_syn, oldBandE, start, effEnd, C, C, 0, LM, st->downsample, 0, st->arch); - } else { - int exc_length; - /* Pitch-based PLC */ - const opus_val16 *window; - opus_val16 *exc; - opus_val16 fade = Q15ONE; - int pitch_index; - VARDECL(opus_val32, etmp); - VARDECL(opus_val16, _exc); - VARDECL(opus_val16, fir_tmp); + c=0; do { + decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+overlap); + out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N; + } while (++c_decode_mem+(DECODE_BUFFER_SIZE+overlap)*C); + oldBandE = lpc+C*CELT_LPC_ORDER; + oldLogE = oldBandE + 2*nbEBands; + oldLogE2 = oldLogE + 2*nbEBands; + backgroundLogE = oldLogE2 + 2*nbEBands; - if (loss_count == 0) { - st->last_pitch_index = pitch_index = celt_plc_pitch_search(decode_mem, C, st->arch); - } else { - pitch_index = st->last_pitch_index; - fade = QCONST16(.8f, 15); - } + loss_duration = st->loss_duration; + start = st->start; +#ifdef ENABLE_DEEP_PLC + noise_based = start != 0 || (lpcnet->fec_fill_pos == 0 && (st->skip_plc || loss_duration >= 80)); +#else + noise_based = loss_duration >= 40 || start != 0 || st->skip_plc; +#endif + if (noise_based) + { + /* Noise-based PLC/CNG */ + VARDECL(celt_norm, X); + opus_uint32 seed; + int end; + int effEnd; + opus_val16 decay; + end = st->end; + effEnd = IMAX(start, IMIN(end, mode->effEBands)); - /* We want the excitation for 2 pitch periods in order to look for a - decaying signal, but we can't get more than MAX_PERIOD. */ - exc_length = IMIN(2 * pitch_index, MAX_PERIOD); + ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ + c=0; do { + OPUS_MOVE(decode_mem[c], decode_mem[c]+N, + DECODE_BUFFER_SIZE-N+overlap); + } while (++cwindow; - c = 0; do { - opus_val16 decay; - opus_val16 attenuation; - opus_val32 S1 = 0; - celt_sig *buf; - int extrapolation_offset; - int extrapolation_len; + if (st->prefilter_and_fold) { + prefilter_and_fold(st, N); + } + + /* Energy decay */ + decay = loss_duration==0 ? QCONST16(1.5f, DB_SHIFT) : QCONST16(.5f, DB_SHIFT); + c=0; do + { + for (i=start;irng; + for (c=0;c>20); } + renormalise_vector(X+boffs, blen, Q15ONE, st->arch); + } + } + st->rng = seed; - if (loss_count == 0) { - opus_val32 ac[LPC_ORDER + 1]; - /* Compute LPC coefficients for the last MAX_PERIOD samples before - the first loss so we can work in the excitation-filter domain. */ - _celt_autocorr(exc, ac, window, overlap, - LPC_ORDER, MAX_PERIOD, st->arch); - /* Add a noise floor of -40 dB. */ + celt_synthesis(mode, X, out_syn, oldBandE, start, effEnd, C, C, 0, LM, st->downsample, 0, st->arch); + st->prefilter_and_fold = 0; + /* Skip regular PLC until we get two consecutive packets. */ + st->skip_plc = 1; + } else { + int exc_length; + /* Pitch-based PLC */ + const opus_val16 *window; + opus_val16 *exc; + opus_val16 fade = Q15ONE; + int pitch_index; + VARDECL(opus_val16, _exc); + VARDECL(opus_val16, fir_tmp); + + if (loss_duration == 0) + { +#ifdef ENABLE_DEEP_PLC + if (lpcnet->loaded) update_plc_state(lpcnet, decode_mem, &st->plc_preemphasis_mem, C); +#endif + st->last_pitch_index = pitch_index = celt_plc_pitch_search(decode_mem, C, st->arch); + } else { + pitch_index = st->last_pitch_index; + fade = QCONST16(.8f,15); + } + + /* We want the excitation for 2 pitch periods in order to look for a + decaying signal, but we can't get more than MAX_PERIOD. */ + exc_length = IMIN(2*pitch_index, MAX_PERIOD); + + ALLOC(_exc, MAX_PERIOD+CELT_LPC_ORDER, opus_val16); + ALLOC(fir_tmp, exc_length, opus_val16); + exc = _exc+CELT_LPC_ORDER; + window = mode->window; + c=0; do { + opus_val16 decay; + opus_val16 attenuation; + opus_val32 S1=0; + celt_sig *buf; + int extrapolation_offset; + int extrapolation_len; + int j; + + buf = decode_mem[c]; + for (i=0;iarch); + /* Add a noise floor of -40 dB. */ #ifdef FIXED_POINT - ac[0] += SHR32(ac[0], 13); + ac[0] += SHR32(ac[0],13); #else - ac[0] *= 1.0001f; + ac[0] *= 1.0001f; #endif - /* Use lag windowing to stabilize the Levinson-Durbin recursion. */ - for (i = 1; i <= LPC_ORDER; i++) { - /*ac[i] *= exp(-.5*(2*M_PI*.002*i)*(2*M_PI*.002*i));*/ + /* Use lag windowing to stabilize the Levinson-Durbin recursion. */ + for (i=1;i<=CELT_LPC_ORDER;i++) + { + /*ac[i] *= exp(-.5*(2*M_PI*.002*i)*(2*M_PI*.002*i));*/ #ifdef FIXED_POINT - ac[i] -= MULT16_32_Q15(2 * i * i, ac[i]); + ac[i] -= MULT16_32_Q15(2*i*i, ac[i]); #else - ac[i] -= ac[i] * (0.008f * 0.008f) * i * i; -#endif - } - _celt_lpc(lpc + c * LPC_ORDER, ac, LPC_ORDER); -#ifdef FIXED_POINT - /* For fixed-point, apply bandwidth expansion until we can guarantee that - no overflow can happen in the IIR filter. This means: - 32768*sum(abs(filter)) < 2^31 */ - while (1) { - opus_val16 tmp = Q15ONE; - opus_val32 sum = QCONST16(1., SIG_SHIFT); - for (i = 0; i < LPC_ORDER; i++) { - sum += ABS16(lpc[c * LPC_ORDER + i]); - } - if (sum < 65535) { - break; - } - for (i = 0; i < LPC_ORDER; i++) { - tmp = MULT16_16_Q15(QCONST16(.99f, 15), tmp); - lpc[c * LPC_ORDER + i] = MULT16_16_Q15(lpc[c * LPC_ORDER + i], tmp); - } - } + ac[i] -= ac[i]*(0.008f*0.008f)*i*i; #endif } - /* Initialize the LPC history with the samples just before the start - of the region for which we're computing the excitation. */ - { - /* Compute the excitation for exc_length samples before the loss. We need the copy - because celt_fir() cannot filter in-place. */ - celt_fir(exc + MAX_PERIOD - exc_length, lpc + c * LPC_ORDER, - fir_tmp, exc_length, LPC_ORDER, st->arch); - OPUS_COPY(exc + MAX_PERIOD - exc_length, fir_tmp, exc_length); - } - - /* Check if the waveform is decaying, and if so how fast. - We do this to avoid adding energy when concealing in a segment - with decaying energy. */ - { - opus_val32 E1 = 1, E2 = 1; - int decay_length; + _celt_lpc(lpc+c*CELT_LPC_ORDER, ac, CELT_LPC_ORDER); #ifdef FIXED_POINT - int shift = IMAX(0, 2 * celt_zlog2(celt_maxabs16(&exc[MAX_PERIOD - exc_length], exc_length)) - 20); + /* For fixed-point, apply bandwidth expansion until we can guarantee that + no overflow can happen in the IIR filter. This means: + 32768*sum(abs(filter)) < 2^31 */ + while (1) { + opus_val16 tmp=Q15ONE; + opus_val32 sum=QCONST16(1., SIG_SHIFT); + for (i=0;i> 1; - for (i = 0; i < decay_length; i++) { - opus_val16 e; - e = exc[MAX_PERIOD - decay_length + i]; - E1 += SHR32(MULT16_16(e, e), shift); - e = exc[MAX_PERIOD - 2 * decay_length + i]; - E2 += SHR32(MULT16_16(e, e), shift); - } - E1 = MIN32(E1, E2); - decay = celt_sqrt(frac_div32(SHR32(E1, 1), E2)); - } + } + /* Initialize the LPC history with the samples just before the start + of the region for which we're computing the excitation. */ + { + /* Compute the excitation for exc_length samples before the loss. We need the copy + because celt_fir() cannot filter in-place. */ + celt_fir(exc+MAX_PERIOD-exc_length, lpc+c*CELT_LPC_ORDER, + fir_tmp, exc_length, CELT_LPC_ORDER, st->arch); + OPUS_COPY(exc+MAX_PERIOD-exc_length, fir_tmp, exc_length); + } - /* Move the decoder memory one frame to the left to give us room to - add the data for the new frame. We ignore the overlap that extends - past the end of the buffer, because we aren't going to use it. */ - OPUS_MOVE(buf, buf + N, DECODE_BUFFER_SIZE - N); - - /* Extrapolate from the end of the excitation with a period of - "pitch_index", scaling down each period by an additional factor of - "decay". */ - extrapolation_offset = MAX_PERIOD - pitch_index; - /* We need to extrapolate enough samples to cover a complete MDCT - window (including overlap/2 samples on both sides). */ - extrapolation_len = N + overlap; - /* We also apply fading if this is not the first loss. */ - attenuation = MULT16_16_Q15(fade, decay); - for (i = j = 0; i < extrapolation_len; i++, j++) { - opus_val16 tmp; - if (j >= pitch_index) { - j -= pitch_index; - attenuation = MULT16_16_Q15(attenuation, decay); - } - buf[DECODE_BUFFER_SIZE - N + i] = - SHL32(EXTEND32(MULT16_16_Q15(attenuation, - exc[extrapolation_offset + j])), SIG_SHIFT); - /* Compute the energy of the previously decoded signal whose - excitation we're copying. */ - tmp = ROUND16( - buf[DECODE_BUFFER_SIZE - MAX_PERIOD - N + extrapolation_offset + j], - SIG_SHIFT); - S1 += SHR32(MULT16_16(tmp, tmp), 10); - } - { - opus_val16 lpc_mem[LPC_ORDER]; - /* Copy the last decoded samples (prior to the overlap region) to - synthesis filter memory so we can have a continuous signal. */ - for (i = 0; i < LPC_ORDER; i++) { - lpc_mem[i] = ROUND16(buf[DECODE_BUFFER_SIZE - N - 1 - i], SIG_SHIFT); - } - /* Apply the synthesis filter to convert the excitation back into - the signal domain. */ - celt_iir(buf + DECODE_BUFFER_SIZE - N, lpc + c * LPC_ORDER, - buf + DECODE_BUFFER_SIZE - N, extrapolation_len, LPC_ORDER, - lpc_mem, st->arch); + /* Check if the waveform is decaying, and if so how fast. + We do this to avoid adding energy when concealing in a segment + with decaying energy. */ + { + opus_val32 E1=1, E2=1; + int decay_length; #ifdef FIXED_POINT - for (i = 0; i < extrapolation_len; i++) { - buf[DECODE_BUFFER_SIZE - N + i] = SATURATE(buf[DECODE_BUFFER_SIZE - N + i], SIG_SAT); - } + int shift = IMAX(0,2*celt_zlog2(celt_maxabs16(&exc[MAX_PERIOD-exc_length], exc_length))-20); #endif - } - - /* Check if the synthesis energy is higher than expected, which can - happen with the signal changes during our window. If so, - attenuate. */ + decay_length = exc_length>>1; + for (i=0;i= pitch_index) { + j -= pitch_index; + attenuation = MULT16_16_Q15(attenuation, decay); + } + buf[DECODE_BUFFER_SIZE-N+i] = + SHL32(EXTEND32(MULT16_16_Q15(attenuation, + exc[extrapolation_offset+j])), SIG_SHIFT); + /* Compute the energy of the previously decoded signal whose + excitation we're copying. */ + tmp = SROUND16( + buf[DECODE_BUFFER_SIZE-MAX_PERIOD-N+extrapolation_offset+j], + SIG_SHIFT); + S1 += SHR32(MULT16_16(tmp, tmp), 10); + } + { + opus_val16 lpc_mem[CELT_LPC_ORDER]; + /* Copy the last decoded samples (prior to the overlap region) to + synthesis filter memory so we can have a continuous signal. */ + for (i=0;iarch); #ifdef FIXED_POINT - if (!(S1 > SHR32(S2, 2))) + for (i=0; i < extrapolation_len; i++) + buf[DECODE_BUFFER_SIZE-N+i] = SATURATE(buf[DECODE_BUFFER_SIZE-N+i], SIG_SAT); +#endif + } + + /* Check if the synthesis energy is higher than expected, which can + happen with the signal changes during our window. If so, + attenuate. */ + { + opus_val32 S2=0; + for (i=0;i SHR32(S2,2))) #else - /* The float test is written this way to catch NaNs in the output - of the IIR filter at the same time. */ - if (!(S1 > 0.2f * S2)) + /* The float test is written this way to catch NaNs in the output + of the IIR filter at the same time. */ + if (!(S1 > 0.2f*S2)) #endif - { - for (i = 0; i < extrapolation_len; i++) { - buf[DECODE_BUFFER_SIZE - N + i] = 0; - } - } else if (S1 < S2) { - opus_val16 ratio = celt_sqrt(frac_div32(SHR32(S1, 1) + 1, S2 + 1)); - for (i = 0; i < overlap; i++) { - opus_val16 tmp_g = Q15ONE - - MULT16_16_Q15(window[i], Q15ONE - ratio); - buf[DECODE_BUFFER_SIZE - N + i] = - MULT16_32_Q15(tmp_g, buf[DECODE_BUFFER_SIZE - N + i]); - } - for (i = overlap; i < extrapolation_len; i++) { - buf[DECODE_BUFFER_SIZE - N + i] = - MULT16_32_Q15(ratio, buf[DECODE_BUFFER_SIZE - N + i]); - } - } + { + for (i=0;ipostfilter_period, st->postfilter_period, overlap, - -st->postfilter_gain, -st->postfilter_gain, - st->postfilter_tapset, st->postfilter_tapset, NULL, 0, st->arch); + } while (++cloaded && (st->complexity >= 5 || lpcnet->fec_fill_pos > 0)) { + float overlap_mem; + int samples_needed16k; + celt_sig *buf; + VARDECL(float, buf_copy); + buf = decode_mem[0]; + ALLOC(buf_copy, C*overlap, float); + c=0; do { + OPUS_COPY(buf_copy+c*overlap, &decode_mem[c][DECODE_BUFFER_SIZE-N], overlap); + } while (++cplc_fill = 0; + } + while (st->plc_fill < samples_needed16k) { + lpcnet_plc_conceal(lpcnet, &st->plc_pcm[st->plc_fill]); + st->plc_fill += FRAME_SIZE; + } + /* Resample to 48 kHz. */ + for (i=0;i<(N+overlap)/3;i++) { + int j; + float sum; + for (sum=0, j=0;j<17;j++) sum += 3*st->plc_pcm[i+j]*sinc_filter[3*j]; + buf[DECODE_BUFFER_SIZE-N+3*i] = sum; + for (sum=0, j=0;j<16;j++) sum += 3*st->plc_pcm[i+j+1]*sinc_filter[3*j+2]; + buf[DECODE_BUFFER_SIZE-N+3*i+1] = sum; + for (sum=0, j=0;j<16;j++) sum += 3*st->plc_pcm[i+j+1]*sinc_filter[3*j+1]; + buf[DECODE_BUFFER_SIZE-N+3*i+2] = sum; + } + OPUS_MOVE(st->plc_pcm, &st->plc_pcm[N/3], st->plc_fill-N/3); + st->plc_fill -= N/3; + for (i=0;iplc_preemphasis_mem; + st->plc_preemphasis_mem = tmp; + } + overlap_mem = st->plc_preemphasis_mem; + for (i=0;iprefilter_and_fold = 1; + } - st->loss_count = loss_count + 1; + /* Saturate to soemthing large to avoid wrap-around. */ + st->loss_duration = IMIN(10000, loss_duration+(1<channels; + int LM, M; + int start; + int end; + int effEnd; + int codedBands; + int alloc_trim; + int postfilter_pitch; + opus_val16 postfilter_gain; + int intensity=0; + int dual_stereo=0; + opus_int32 total_bits; + opus_int32 balance; + opus_int32 tell; + int dynalloc_logp; + int postfilter_tapset; + int anti_collapse_rsv; + int anti_collapse_on=0; + int silence; + int C = st->stream_channels; + const OpusCustomMode *mode; + int nbEBands; + int overlap; + const opus_int16 *eBands; + opus_val16 max_background_increase; + ALLOC_STACK; + + VALIDATE_CELT_DECODER(st); + mode = st->mode; + nbEBands = mode->nbEBands; + overlap = mode->overlap; + eBands = mode->eBands; + start = st->start; + end = st->end; + frame_size *= st->downsample; + + lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+overlap)*CC); + oldBandE = lpc+CC*CELT_LPC_ORDER; + oldLogE = oldBandE + 2*nbEBands; + oldLogE2 = oldLogE + 2*nbEBands; + backgroundLogE = oldLogE2 + 2*nbEBands; + +#ifdef CUSTOM_MODES + if (st->signalling && data!=NULL) + { + int data0=data[0]; + /* Convert "standard mode" to Opus header */ + if (mode->Fs==48000 && mode->shortMdctSize==120) + { + data0 = fromOpus(data0); + if (data0<0) + return OPUS_INVALID_PACKET; + } + st->end = end = IMAX(1, mode->effEBands-2*(data0>>5)); + LM = (data0>>3)&0x3; + C = 1 + ((data0>>2)&0x1); + data++; + len--; + if (LM>mode->maxLM) + return OPUS_INVALID_PACKET; + if (frame_size < mode->shortMdctSize<shortMdctSize<maxLM;LM++) + if (mode->shortMdctSize<mode->maxLM) + return OPUS_BAD_ARG; + } + M=1<1275 || pcm==NULL) + return OPUS_BAD_ARG; + + N = M*mode->shortMdctSize; + c=0; do { + decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+overlap); + out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N; + } while (++c mode->effEBands) + effEnd = mode->effEBands; + + if (data == NULL || len<=1) + { + celt_decode_lost(st, N, LM +#ifdef ENABLE_DEEP_PLC + , lpcnet +#endif + ); + deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_memD, accum); + RESTORE_STACK; + return frame_size/st->downsample; + } +#ifdef ENABLE_DEEP_PLC + else { + /* FIXME: This is a bit of a hack just to make sure opus_decode_native() knows we're no longer in PLC. */ + if (lpcnet) lpcnet->blend = 0; + } +#endif + + /* Check if there are at least two packets received consecutively before + * turning on the pitch-based PLC */ + if (st->loss_duration == 0) st->skip_plc = 0; + + if (dec == NULL) + { + ec_dec_init(&_dec,(unsigned char*)data,len); + dec = &_dec; + } + + if (C==1) + { + for (i=0;i= total_bits) + silence = 1; + else if (tell==1) + silence = ec_dec_bit_logp(dec, 15); + else + silence = 0; + if (silence) + { + /* Pretend we've read all the remaining bits */ + tell = len*8; + dec->nbits_total+=tell-ec_tell(dec); + } + + postfilter_gain = 0; + postfilter_pitch = 0; + postfilter_tapset = 0; + if (start==0 && tell+16 <= total_bits) + { + if(ec_dec_bit_logp(dec, 1)) + { + int qg, octave; + octave = ec_dec_uint(dec, 6); + postfilter_pitch = (16< 0 && tell+3 <= total_bits) + { + isTransient = ec_dec_bit_logp(dec, 3); + tell = ec_tell(dec); + } + else + isTransient = 0; + + if (isTransient) + shortBlocks = M; + else + shortBlocks = 0; + + /* Decode the global flags (first symbols in the stream) */ + intra_ener = tell+3<=total_bits ? ec_dec_bit_logp(dec, 3) : 0; + /* If recovering from packet loss, make sure we make the energy prediction safe to reduce the + risk of getting loud artifacts. */ + if (!intra_ener && st->loss_duration != 0) { + c=0; do + { + opus_val16 safety = 0; + int missing = IMIN(10, st->loss_duration>>LM); + if (LM==0) safety = QCONST16(1.5f,DB_SHIFT); + else if (LM==1) safety = QCONST16(.5f,DB_SHIFT); + for (i=start;i0) + dynalloc_logp = IMAX(2, dynalloc_logp-1); + } + + ALLOC(fine_quant, nbEBands, int); + alloc_trim = tell+(6<=2&&bits>=((LM+2)<rng, 0, + st->arch, st->disable_inv); + + if (anti_collapse_rsv > 0) + { + anti_collapse_on = ec_dec_bits(dec, 1); + } + + unquant_energy_finalise(mode, start, end, oldBandE, + fine_quant, fine_priority, len*8-ec_tell(dec), dec, C); + + if (anti_collapse_on) + anti_collapse(mode, X, collapse_masks, LM, C, N, + start, end, oldBandE, oldLogE, oldLogE2, pulses, st->rng, st->arch); + + if (silence) + { + for (i=0;iprefilter_and_fold) { + prefilter_and_fold(st, N); + } + celt_synthesis(mode, X, out_syn, oldBandE, start, effEnd, + C, CC, isTransient, LM, st->downsample, silence, st->arch); + + c=0; do { + st->postfilter_period=IMAX(st->postfilter_period, COMBFILTER_MINPERIOD); + st->postfilter_period_old=IMAX(st->postfilter_period_old, COMBFILTER_MINPERIOD); + comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfilter_period, mode->shortMdctSize, + st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_old, st->postfilter_tapset, + mode->window, overlap, st->arch); + if (LM!=0) + comb_filter(out_syn[c]+mode->shortMdctSize, out_syn[c]+mode->shortMdctSize, st->postfilter_period, postfilter_pitch, N-mode->shortMdctSize, + st->postfilter_gain, postfilter_gain, st->postfilter_tapset, postfilter_tapset, + mode->window, overlap, st->arch); + + } while (++cpostfilter_period_old = st->postfilter_period; + st->postfilter_gain_old = st->postfilter_gain; + st->postfilter_tapset_old = st->postfilter_tapset; + st->postfilter_period = postfilter_pitch; + st->postfilter_gain = postfilter_gain; + st->postfilter_tapset = postfilter_tapset; + if (LM!=0) + { + st->postfilter_period_old = st->postfilter_period; + st->postfilter_gain_old = st->postfilter_gain; + st->postfilter_tapset_old = st->postfilter_tapset; + } + + if (C==1) + OPUS_COPY(&oldBandE[nbEBands], oldBandE, nbEBands); + + if (!isTransient) + { + OPUS_COPY(oldLogE2, oldLogE, 2*nbEBands); + OPUS_COPY(oldLogE, oldBandE, 2*nbEBands); + } else { + for (i=0;i<2*nbEBands;i++) + oldLogE[i] = MIN16(oldLogE[i], oldBandE[i]); + } + /* In normal circumstances, we only allow the noise floor to increase by + up to 2.4 dB/second, but when we're in DTX we give the weight of + all missing packets to the update packet. */ + max_background_increase = IMIN(160, st->loss_duration+M)*QCONST16(0.001f,DB_SHIFT); + for (i=0;i<2*nbEBands;i++) + backgroundLogE[i] = MIN16(backgroundLogE[i] + max_background_increase, oldBandE[i]); + /* In case start or end were to change */ + c=0; do + { + for (i=0;irng = dec->rng; + + deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_memD, accum); + st->loss_duration = 0; + st->prefilter_and_fold = 0; + RESTORE_STACK; + if (ec_tell(dec) > 8*len) + return OPUS_INTERNAL_ERROR; + if(ec_get_error(dec)) + st->error = 1; + return frame_size/st->downsample; } int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, - int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum) { - int c, i, N; - int spread_decision; - opus_int32 bits; - ec_dec _dec; -#ifdef NORM_ALIASING_HACK - celt_norm *X; -#else - VARDECL(celt_norm, X); + int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum) +{ + return celt_decode_with_ec_dred(st, data, len, pcm, frame_size, dec, accum +#ifdef ENABLE_DEEP_PLC + , NULL #endif - VARDECL(int, fine_quant); - VARDECL(int, pulses); - VARDECL(int, cap); - VARDECL(int, offsets); - VARDECL(int, fine_priority); - VARDECL(int, tf_res); - VARDECL(unsigned char, collapse_masks); - celt_sig *decode_mem[2]; - celt_sig *out_syn[2]; - opus_val16 *lpc; - opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE; - - int shortBlocks; - int isTransient; - int intra_ener; - const int CC = st->channels; - int LM, M; - int start; - int end; - int effEnd; - int codedBands; - int alloc_trim; - int postfilter_pitch; - opus_val16 postfilter_gain; - int intensity = 0; - int dual_stereo = 0; - opus_int32 total_bits; - opus_int32 balance; - opus_int32 tell; - int dynalloc_logp; - int postfilter_tapset; - int anti_collapse_rsv; - int anti_collapse_on = 0; - int silence; - int C = st->stream_channels; - const OpusCustomMode *mode; - int nbEBands; - int overlap; - const opus_int16 *eBands; - ALLOC_STACK; - - VALIDATE_CELT_DECODER(st); - mode = st->mode; - nbEBands = mode->nbEBands; - overlap = mode->overlap; - eBands = mode->eBands; - start = st->start; - end = st->end; - frame_size *= st->downsample; - - lpc = (opus_val16*)(st->_decode_mem + (DECODE_BUFFER_SIZE + overlap) * CC); - oldBandE = lpc + CC * LPC_ORDER; - oldLogE = oldBandE + 2 * nbEBands; - oldLogE2 = oldLogE + 2 * nbEBands; - backgroundLogE = oldLogE2 + 2 * nbEBands; - -#ifdef CUSTOM_MODES - if (st->signalling && data != NULL) { - int data0 = data[0]; - /* Convert "standard mode" to Opus header */ - if (mode->Fs == 48000 && mode->shortMdctSize == 120) { - data0 = fromOpus(data0); - if (data0 < 0) { - return OPUS_INVALID_PACKET; - } - } - st->end = end = IMAX(1, mode->effEBands - 2 * (data0 >> 5)); - LM = (data0 >> 3) & 0x3; - C = 1 + ((data0 >> 2) & 0x1); - data++; - len--; - if (LM > mode->maxLM) { - return OPUS_INVALID_PACKET; - } - if (frame_size < mode->shortMdctSize << LM) { - return OPUS_BUFFER_TOO_SMALL; - } else { - frame_size = mode->shortMdctSize << LM; - } - } else { -#else - { -#endif - for (LM = 0; LM <= mode->maxLM; LM++) - if (mode->shortMdctSize << LM == frame_size) { - break; - } - if (LM > mode->maxLM) { - return OPUS_BAD_ARG; - } - } - M = 1 << LM; - - if (len < 0 || len > 1275 || pcm == NULL) { - return OPUS_BAD_ARG; - } - - N = M * mode->shortMdctSize; - c = 0; do { - decode_mem[c] = st->_decode_mem + c * (DECODE_BUFFER_SIZE + overlap); - out_syn[c] = decode_mem[c] + DECODE_BUFFER_SIZE - N; - } while (++c < CC); - - effEnd = end; - if (effEnd > mode->effEBands) { - effEnd = mode->effEBands; - } - - if (data == NULL || len <= 1) { - celt_decode_lost(st, N, LM); - deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_memD, accum); - RESTORE_STACK; - return frame_size / st->downsample; - } - - /* Check if there are at least two packets received consecutively before - turning on the pitch-based PLC */ - st->skip_plc = st->loss_count != 0; - - if (dec == NULL) { - ec_dec_init(&_dec, (unsigned char*)data, len); - dec = &_dec; - } - - if (C == 1) { - for (i = 0; i < nbEBands; i++) { - oldBandE[i] = MAX16(oldBandE[i], oldBandE[nbEBands + i]); - } - } - - total_bits = len * 8; - tell = ec_tell(dec); - - if (tell >= total_bits) { - silence = 1; - } else if (tell == 1) { - silence = ec_dec_bit_logp(dec, 15); - } else { - silence = 0; - } - if (silence) { - /* Pretend we've read all the remaining bits */ - tell = len * 8; - dec->nbits_total += tell - ec_tell(dec); - } - - postfilter_gain = 0; - postfilter_pitch = 0; - postfilter_tapset = 0; - if (start == 0 && tell + 16 <= total_bits) { - if (ec_dec_bit_logp(dec, 1)) { - int qg, octave; - octave = ec_dec_uint(dec, 6); - postfilter_pitch = (16 << octave) + ec_dec_bits(dec, 4 + octave) - 1; - qg = ec_dec_bits(dec, 3); - if (ec_tell(dec) + 2 <= total_bits) { - postfilter_tapset = ec_dec_icdf(dec, tapset_icdf, 2); - } - postfilter_gain = QCONST16(.09375f, 15) * (qg + 1); - } - tell = ec_tell(dec); - } - - if (LM > 0 && tell + 3 <= total_bits) { - isTransient = ec_dec_bit_logp(dec, 3); - tell = ec_tell(dec); - } else { - isTransient = 0; - } - - if (isTransient) { - shortBlocks = M; - } else { - shortBlocks = 0; - } - - /* Decode the global flags (first symbols in the stream) */ - intra_ener = tell + 3 <= total_bits ? ec_dec_bit_logp(dec, 3) : 0; - /* Get band energies */ - unquant_coarse_energy(mode, start, end, oldBandE, - intra_ener, dec, C, LM); - - ALLOC(tf_res, nbEBands, int); - tf_decode(start, end, isTransient, tf_res, LM, dec); - - tell = ec_tell(dec); - spread_decision = SPREAD_NORMAL; - if (tell + 4 <= total_bits) { - spread_decision = ec_dec_icdf(dec, spread_icdf, 5); - } - - ALLOC(cap, nbEBands, int); - - init_caps(mode, cap, LM, C); - - ALLOC(offsets, nbEBands, int); - - dynalloc_logp = 6; - total_bits <<= BITRES; - tell = ec_tell_frac(dec); - for (i = start; i < end; i++) { - int width, quanta; - int dynalloc_loop_logp; - int boost; - width = C * (eBands[i + 1] - eBands[i]) << LM; - /* quanta is 6 bits, but no more than 1 bit/sample - and no less than 1/8 bit/sample */ - quanta = IMIN(width << BITRES, IMAX(6 << BITRES, width)); - dynalloc_loop_logp = dynalloc_logp; - boost = 0; - while (tell + (dynalloc_loop_logp << BITRES) < total_bits && boost < cap[i]) { - int flag; - flag = ec_dec_bit_logp(dec, dynalloc_loop_logp); - tell = ec_tell_frac(dec); - if (!flag) { - break; - } - boost += quanta; - total_bits -= quanta; - dynalloc_loop_logp = 1; - } - offsets[i] = boost; - /* Making dynalloc more likely */ - if (boost > 0) { - dynalloc_logp = IMAX(2, dynalloc_logp - 1); - } - } - - ALLOC(fine_quant, nbEBands, int); - alloc_trim = tell + (6 << BITRES) <= total_bits ? - ec_dec_icdf(dec, trim_icdf, 7) : 5; - - bits = (((opus_int32)len * 8) << BITRES) - ec_tell_frac(dec) - 1; - anti_collapse_rsv = isTransient && LM >= 2 && bits >= ((LM + 2) << BITRES) ? (1 << BITRES) : 0; - bits -= anti_collapse_rsv; - - ALLOC(pulses, nbEBands, int); - ALLOC(fine_priority, nbEBands, int); - - codedBands = clt_compute_allocation(mode, start, end, offsets, cap, - alloc_trim, &intensity, &dual_stereo, bits, &balance, pulses, - fine_quant, fine_priority, C, LM, dec, 0, 0, 0); - - unquant_fine_energy(mode, start, end, oldBandE, fine_quant, dec, C); - - c = 0; do { - OPUS_MOVE(decode_mem[c], decode_mem[c] + N, DECODE_BUFFER_SIZE - N + overlap / 2); - } while (++c < CC); - - /* Decode fixed codebook */ - ALLOC(collapse_masks, C * nbEBands, unsigned char); - -#ifdef NORM_ALIASING_HACK - /* This is an ugly hack that breaks aliasing rules and would be easily broken, - but it saves almost 4kB of stack. */ - X = (celt_norm*)(out_syn[CC - 1] + overlap / 2); -#else - ALLOC(X, C * N, celt_norm); /**< Interleaved normalised MDCTs */ -#endif - - quant_all_bands(0, mode, start, end, X, C == 2 ? X + N : NULL, collapse_masks, - NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res, - len * (8 << BITRES) - anti_collapse_rsv, balance, dec, LM, codedBands, &st->rng, 0, - st->arch, st->disable_inv); - - if (anti_collapse_rsv > 0) { - anti_collapse_on = ec_dec_bits(dec, 1); - } - - unquant_energy_finalise(mode, start, end, oldBandE, - fine_quant, fine_priority, len * 8 - ec_tell(dec), dec, C); - - if (anti_collapse_on) - anti_collapse(mode, X, collapse_masks, LM, C, N, - start, end, oldBandE, oldLogE, oldLogE2, pulses, st->rng, st->arch); - - if (silence) { - for (i = 0; i < C * nbEBands; i++) { - oldBandE[i] = -QCONST16(28.f, DB_SHIFT); - } - } - - celt_synthesis(mode, X, out_syn, oldBandE, start, effEnd, - C, CC, isTransient, LM, st->downsample, silence, st->arch); - - c = 0; do { - st->postfilter_period = IMAX(st->postfilter_period, COMBFILTER_MINPERIOD); - st->postfilter_period_old = IMAX(st->postfilter_period_old, COMBFILTER_MINPERIOD); - comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfilter_period, mode->shortMdctSize, - st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_old, st->postfilter_tapset, - mode->window, overlap, st->arch); - if (LM != 0) - comb_filter(out_syn[c] + mode->shortMdctSize, out_syn[c] + mode->shortMdctSize, st->postfilter_period, postfilter_pitch, N - mode->shortMdctSize, - st->postfilter_gain, postfilter_gain, st->postfilter_tapset, postfilter_tapset, - mode->window, overlap, st->arch); - - } while (++c < CC); - st->postfilter_period_old = st->postfilter_period; - st->postfilter_gain_old = st->postfilter_gain; - st->postfilter_tapset_old = st->postfilter_tapset; - st->postfilter_period = postfilter_pitch; - st->postfilter_gain = postfilter_gain; - st->postfilter_tapset = postfilter_tapset; - if (LM != 0) { - st->postfilter_period_old = st->postfilter_period; - st->postfilter_gain_old = st->postfilter_gain; - st->postfilter_tapset_old = st->postfilter_tapset; - } - - if (C == 1) { - OPUS_COPY(&oldBandE[nbEBands], oldBandE, nbEBands); - } - - /* In case start or end were to change */ - if (!isTransient) { - opus_val16 max_background_increase; - OPUS_COPY(oldLogE2, oldLogE, 2 * nbEBands); - OPUS_COPY(oldLogE, oldBandE, 2 * nbEBands); - /* In normal circumstances, we only allow the noise floor to increase by - up to 2.4 dB/second, but when we're in DTX, we allow up to 6 dB - increase for each update.*/ - if (st->loss_count < 10) { - max_background_increase = M * QCONST16(0.001f, DB_SHIFT); - } else { - max_background_increase = QCONST16(1.f, DB_SHIFT); - } - for (i = 0; i < 2 * nbEBands; i++) { - backgroundLogE[i] = MIN16(backgroundLogE[i] + max_background_increase, oldBandE[i]); - } - } else { - for (i = 0; i < 2 * nbEBands; i++) { - oldLogE[i] = MIN16(oldLogE[i], oldBandE[i]); - } - } - c = 0; do { - for (i = 0; i < start; i++) { - oldBandE[c * nbEBands + i] = 0; - oldLogE[c * nbEBands + i] = oldLogE2[c * nbEBands + i] = -QCONST16(28.f, DB_SHIFT); - } - for (i = end; i < nbEBands; i++) { - oldBandE[c * nbEBands + i] = 0; - oldLogE[c * nbEBands + i] = oldLogE2[c * nbEBands + i] = -QCONST16(28.f, DB_SHIFT); - } - } while (++c < 2); - st->rng = dec->rng; - - deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_memD, accum); - st->loss_count = 0; - RESTORE_STACK; - if (ec_tell(dec) > 8 * len) { - return OPUS_INTERNAL_ERROR; - } - if (ec_get_error(dec)) { - st->error = 1; - } - return frame_size / st->downsample; + ); } - #ifdef CUSTOM_MODES #ifdef FIXED_POINT -int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size) { - return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0); +int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size) +{ + return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0); } #ifndef DISABLE_FLOAT_API -int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size) { - int j, ret, C, N; - VARDECL(opus_int16, out); - ALLOC_STACK; +int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size) +{ + int j, ret, C, N; + VARDECL(opus_int16, out); + ALLOC_STACK; - if (pcm == NULL) { - return OPUS_BAD_ARG; - } + if (pcm==NULL) + return OPUS_BAD_ARG; - C = st->channels; - N = frame_size; + C = st->channels; + N = frame_size; - ALLOC(out, C * N, opus_int16); - ret = celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0); - if (ret > 0) - for (j = 0; j < C * ret; j++) { - pcm[j] = out[j] * (1.f / 32768.f); - } + ALLOC(out, C*N, opus_int16); + ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0); + if (ret>0) + for (j=0;jchannels; - N = frame_size; - ALLOC(out, C * N, celt_sig); + C = st->channels; + N = frame_size; + ALLOC(out, C*N, celt_sig); - ret = celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0); + ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0); - if (ret > 0) - for (j = 0; j < C * ret; j++) { - pcm[j] = FLOAT2INT16(out[j]); - } + if (ret>0) + for (j=0;j= st->mode->nbEBands) { + va_start(ap, request); + switch (request) + { + case OPUS_SET_COMPLEXITY_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if(value<0 || value>10) + { + goto bad_arg; + } + st->complexity = value; + } + break; + case OPUS_GET_COMPLEXITY_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->complexity; + } + break; + case CELT_SET_START_BAND_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if (value<0 || value>=st->mode->nbEBands) goto bad_arg; - } - st->start = value; - } - break; - case CELT_SET_END_BAND_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 1 || value > st->mode->nbEBands) { + st->start = value; + } + break; + case CELT_SET_END_BAND_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if (value<1 || value>st->mode->nbEBands) goto bad_arg; - } - st->end = value; - } - break; - case CELT_SET_CHANNELS_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 1 || value > 2) { + st->end = value; + } + break; + case CELT_SET_CHANNELS_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if (value<1 || value>2) goto bad_arg; - } - st->stream_channels = value; - } - break; - case CELT_GET_AND_CLEAR_ERROR_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (value == NULL) { + st->stream_channels = value; + } + break; + case CELT_GET_AND_CLEAR_ERROR_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (value==NULL) goto bad_arg; - } - *value = st->error; - st->error = 0; - } - break; - case OPUS_GET_LOOKAHEAD_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (value == NULL) { + *value=st->error; + st->error = 0; + } + break; + case OPUS_GET_LOOKAHEAD_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (value==NULL) goto bad_arg; - } - *value = st->overlap / st->downsample; - } - break; - case OPUS_RESET_STATE: { - int i; - opus_val16 *lpc, *oldBandE, *oldLogE, *oldLogE2; - lpc = (opus_val16*)(st->_decode_mem + (DECODE_BUFFER_SIZE + st->overlap) * st->channels); - oldBandE = lpc + st->channels * LPC_ORDER; - oldLogE = oldBandE + 2 * st->mode->nbEBands; - oldLogE2 = oldLogE + 2 * st->mode->nbEBands; - OPUS_CLEAR((char*)&st->DECODER_RESET_START, - opus_custom_decoder_get_size(st->mode, st->channels) - - ((char*)&st->DECODER_RESET_START - (char*)st)); - for (i = 0; i < 2 * st->mode->nbEBands; i++) { - oldLogE[i] = oldLogE2[i] = -QCONST16(28.f, DB_SHIFT); - } - st->skip_plc = 1; - } - break; - case OPUS_GET_PITCH_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (value == NULL) { + *value = st->overlap/st->downsample; + } + break; + case OPUS_RESET_STATE: + { + int i; + opus_val16 *lpc, *oldBandE, *oldLogE, *oldLogE2; + lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+st->overlap)*st->channels); + oldBandE = lpc+st->channels*CELT_LPC_ORDER; + oldLogE = oldBandE + 2*st->mode->nbEBands; + oldLogE2 = oldLogE + 2*st->mode->nbEBands; + OPUS_CLEAR((char*)&st->DECODER_RESET_START, + opus_custom_decoder_get_size(st->mode, st->channels)- + ((char*)&st->DECODER_RESET_START - (char*)st)); + for (i=0;i<2*st->mode->nbEBands;i++) + oldLogE[i]=oldLogE2[i]=-QCONST16(28.f,DB_SHIFT); + st->skip_plc = 1; + } + break; + case OPUS_GET_PITCH_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (value==NULL) goto bad_arg; - } - *value = st->postfilter_period; - } - break; - case CELT_GET_MODE_REQUEST: { - const CELTMode ** value = va_arg(ap, const CELTMode**); - if (value == 0) { + *value = st->postfilter_period; + } + break; + case CELT_GET_MODE_REQUEST: + { + const CELTMode ** value = va_arg(ap, const CELTMode**); + if (value==0) goto bad_arg; - } - *value = st->mode; - } - break; - case CELT_SET_SIGNALLING_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->signalling = value; - } - break; - case OPUS_GET_FINAL_RANGE_REQUEST: { - opus_uint32 * value = va_arg(ap, opus_uint32 *); - if (value == 0) { + *value=st->mode; + } + break; + case CELT_SET_SIGNALLING_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + st->signalling = value; + } + break; + case OPUS_GET_FINAL_RANGE_REQUEST: + { + opus_uint32 * value = va_arg(ap, opus_uint32 *); + if (value==0) goto bad_arg; - } - *value = st->rng; - } - break; - case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - st->disable_inv = value; - } - break; - case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->disable_inv; - } - break; - default: - goto bad_request; - } - va_end(ap); - return OPUS_OK; + *value=st->rng; + } + break; + case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if(value<0 || value>1) + { + goto bad_arg; + } + st->disable_inv = value; + } + break; + case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->disable_inv; + } + break; + default: + goto bad_request; + } + va_end(ap); + return OPUS_OK; bad_arg: - va_end(ap); - return OPUS_BAD_ARG; + va_end(ap); + return OPUS_BAD_ARG; bad_request: - va_end(ap); - return OPUS_UNIMPLEMENTED; + va_end(ap); + return OPUS_UNIMPLEMENTED; } diff --git a/src/libopus/celt/celt_encoder.c b/src/libopus/celt/celt_encoder.c deleted file mode 100644 index d0901d1..0000000 --- a/src/libopus/celt/celt_encoder.c +++ /dev/null @@ -1,2535 +0,0 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2010 Xiph.Org Foundation - Copyright (c) 2008 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif - -#define CELT_ENCODER_C - -#include "cpu_support.h" -#include "os_support.h" -#include "mdct.h" -#include -#include "celt.h" -#include "pitch.h" -#include "bands.h" -#include "modes.h" -#include "entcode.h" -#include "quant_bands.h" -#include "rate.h" -#include "stack_alloc.h" -#include "mathops.h" -#include "float_cast.h" -#include -#include "celt_lpc.h" -#include "vq.h" - - -/** Encoder state - @brief Encoder state -*/ -struct OpusCustomEncoder { - const OpusCustomMode *mode; /**< Mode used by the encoder */ - int channels; - int stream_channels; - - int force_intra; - int clip; - int disable_pf; - int complexity; - int upsample; - int start, end; - - opus_int32 bitrate; - int vbr; - int signalling; - int constrained_vbr; /* If zero, VBR can do whatever it likes with the rate */ - int loss_rate; - int lsb_depth; - int lfe; - int disable_inv; - int arch; - - /* Everything beyond this point gets cleared on a reset */ -#define ENCODER_RESET_START rng - - opus_uint32 rng; - int spread_decision; - opus_val32 delayedIntra; - int tonal_average; - int lastCodedBands; - int hf_average; - int tapset_decision; - - int prefilter_period; - opus_val16 prefilter_gain; - int prefilter_tapset; -#ifdef RESYNTH - int prefilter_period_old; - opus_val16 prefilter_gain_old; - int prefilter_tapset_old; -#endif - int consec_transient; - AnalysisInfo analysis; - SILKInfo silk_info; - - opus_val32 preemph_memE[2]; - opus_val32 preemph_memD[2]; - - /* VBR-related parameters */ - opus_int32 vbr_reservoir; - opus_int32 vbr_drift; - opus_int32 vbr_offset; - opus_int32 vbr_count; - opus_val32 overlap_max; - opus_val16 stereo_saving; - int intensity; - opus_val16 *energy_mask; - opus_val16 spec_avg; - -#ifdef RESYNTH - /* +MAX_PERIOD/2 to make space for overlap */ - celt_sig syn_mem[2][2 * MAX_PERIOD + MAX_PERIOD / 2]; -#endif - - celt_sig in_mem[1]; /* Size = channels*mode->overlap */ - /* celt_sig prefilter_mem[], Size = channels*COMBFILTER_MAXPERIOD */ - /* opus_val16 oldBandE[], Size = channels*mode->nbEBands */ - /* opus_val16 oldLogE[], Size = channels*mode->nbEBands */ - /* opus_val16 oldLogE2[], Size = channels*mode->nbEBands */ - /* opus_val16 energyError[], Size = channels*mode->nbEBands */ -}; - -int celt_encoder_get_size(int channels) { - CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); - return opus_custom_encoder_get_size(mode, channels); -} - -OPUS_CUSTOM_NOSTATIC int opus_custom_encoder_get_size(const CELTMode *mode, int channels) { - int size = sizeof(struct CELTEncoder) - + (channels * mode->overlap - 1) * sizeof(celt_sig) /* celt_sig in_mem[channels*mode->overlap]; */ - + channels * COMBFILTER_MAXPERIOD * sizeof(celt_sig) /* celt_sig prefilter_mem[channels*COMBFILTER_MAXPERIOD]; */ - + 4 * channels * mode->nbEBands * sizeof(opus_val16); /* opus_val16 oldBandE[channels*mode->nbEBands]; */ - /* opus_val16 oldLogE[channels*mode->nbEBands]; */ - /* opus_val16 oldLogE2[channels*mode->nbEBands]; */ - /* opus_val16 energyError[channels*mode->nbEBands]; */ - return size; -} - -#ifdef CUSTOM_MODES -CELTEncoder *opus_custom_encoder_create(const CELTMode *mode, int channels, int *error) { - int ret; - CELTEncoder *st = (CELTEncoder *)opus_alloc(opus_custom_encoder_get_size(mode, channels)); - /* init will handle the NULL case */ - ret = opus_custom_encoder_init(st, mode, channels); - if (ret != OPUS_OK) { - opus_custom_encoder_destroy(st); - st = NULL; - } - if (error) { - *error = ret; - } - return st; -} -#endif /* CUSTOM_MODES */ - -static int opus_custom_encoder_init_arch(CELTEncoder *st, const CELTMode *mode, - int channels, int arch) { - if (channels < 0 || channels > 2) { - return OPUS_BAD_ARG; - } - - if (st == NULL || mode == NULL) { - return OPUS_ALLOC_FAIL; - } - - OPUS_CLEAR((char*)st, opus_custom_encoder_get_size(mode, channels)); - - st->mode = mode; - st->stream_channels = st->channels = channels; - - st->upsample = 1; - st->start = 0; - st->end = st->mode->effEBands; - st->signalling = 1; - st->arch = arch; - - st->constrained_vbr = 1; - st->clip = 1; - - st->bitrate = OPUS_BITRATE_MAX; - st->vbr = 0; - st->force_intra = 0; - st->complexity = 5; - st->lsb_depth = 24; - - opus_custom_encoder_ctl(st, OPUS_RESET_STATE); - - return OPUS_OK; -} - -#ifdef CUSTOM_MODES -int opus_custom_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels) { - return opus_custom_encoder_init_arch(st, mode, channels, opus_select_arch()); -} -#endif - -int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels, - int arch) { - int ret; - ret = opus_custom_encoder_init_arch(st, - opus_custom_mode_create(48000, 960, NULL), channels, arch); - if (ret != OPUS_OK) { - return ret; - } - st->upsample = resampling_factor(sampling_rate); - return OPUS_OK; -} - -#ifdef CUSTOM_MODES -void opus_custom_encoder_destroy(CELTEncoder *st) { - opus_free(st); -} -#endif /* CUSTOM_MODES */ - - -static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int C, - opus_val16 *tf_estimate, int *tf_chan, int allow_weak_transients, - int *weak_transient) { - int i; - VARDECL(opus_val16, tmp); - opus_val32 mem0, mem1; - int is_transient = 0; - opus_int32 mask_metric = 0; - int c; - opus_val16 tf_max; - int len2; - /* Forward masking: 6.7 dB/ms. */ -#ifdef FIXED_POINT - int forward_shift = 4; -#else - opus_val16 forward_decay = QCONST16(.0625f, 15); -#endif - /* Table of 6*64/x, trained on real data to minimize the average error */ - static const unsigned char inv_table[128] = { - 255, 255, 156, 110, 86, 70, 59, 51, 45, 40, 37, 33, 31, 28, 26, 25, - 23, 22, 21, 20, 19, 18, 17, 16, 16, 15, 15, 14, 13, 13, 12, 12, - 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8, - 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, - }; - SAVE_STACK; - ALLOC(tmp, len, opus_val16); - - *weak_transient = 0; - /* For lower bitrates, let's be more conservative and have a forward masking - decay of 3.3 dB/ms. This avoids having to code transients at very low - bitrate (mostly for hybrid), which can result in unstable energy and/or - partial collapse. */ - if (allow_weak_transients) { -#ifdef FIXED_POINT - forward_shift = 5; -#else - forward_decay = QCONST16(.03125f, 15); -#endif - } - len2 = len / 2; - for (c = 0; c < C; c++) { - opus_val32 mean; - opus_int32 unmask = 0; - opus_val32 norm; - opus_val16 maxE; - mem0 = 0; - mem1 = 0; - /* High-pass filter: (1 - 2*z^-1 + z^-2) / (1 - z^-1 + .5*z^-2) */ - for (i = 0; i < len; i++) { - opus_val32 x, y; - x = SHR32(in[i + c * len], SIG_SHIFT); - y = ADD32(mem0, x); -#ifdef FIXED_POINT - mem0 = mem1 + y - SHL32(x, 1); - mem1 = x - SHR32(y, 1); -#else - mem0 = mem1 + y - 2 * x; - mem1 = x - .5f * y; -#endif - tmp[i] = SROUND16(y, 2); - /*printf("%f ", tmp[i]);*/ - } - /*printf("\n");*/ - /* First few samples are bad because we don't propagate the memory */ - OPUS_CLEAR(tmp, 12); - -#ifdef FIXED_POINT - /* Normalize tmp to max range */ - { - int shift = 0; - shift = 14 - celt_ilog2(MAX16(1, celt_maxabs16(tmp, len))); - if (shift != 0) { - for (i = 0; i < len; i++) { - tmp[i] = SHL16(tmp[i], shift); - } - } - } -#endif - - mean = 0; - mem0 = 0; - /* Grouping by two to reduce complexity */ - /* Forward pass to compute the post-echo threshold*/ - for (i = 0; i < len2; i++) { - opus_val16 x2 = PSHR32(MULT16_16(tmp[2 * i], tmp[2 * i]) + MULT16_16(tmp[2 * i + 1], tmp[2 * i + 1]), 16); - mean += x2; -#ifdef FIXED_POINT - /* FIXME: Use PSHR16() instead */ - tmp[i] = mem0 + PSHR32(x2 - mem0, forward_shift); -#else - tmp[i] = mem0 + MULT16_16_P15(forward_decay, x2 - mem0); -#endif - mem0 = tmp[i]; - } - - mem0 = 0; - maxE = 0; - /* Backward pass to compute the pre-echo threshold */ - for (i = len2 - 1; i >= 0; i--) { - /* Backward masking: 13.9 dB/ms. */ -#ifdef FIXED_POINT - /* FIXME: Use PSHR16() instead */ - tmp[i] = mem0 + PSHR32(tmp[i] - mem0, 3); -#else - tmp[i] = mem0 + MULT16_16_P15(QCONST16(0.125f, 15), tmp[i] - mem0); -#endif - mem0 = tmp[i]; - maxE = MAX16(maxE, mem0); - } - /*for (i=0;i> 1))); -#else - mean = celt_sqrt(mean * maxE * .5 * len2); -#endif - /* Inverse of the mean energy in Q15+6 */ - norm = SHL32(EXTEND32(len2), 6 + 14) / ADD32(EPSILON, SHR32(mean, 1)); - /* Compute harmonic mean discarding the unreliable boundaries - The data is smooth, so we only take 1/4th of the samples */ - unmask = 0; - /* We should never see NaNs here. If we find any, then something really bad happened and we better abort - before it does any damage later on. If these asserts are disabled (no hardening), then the table - lookup a few lines below (id = ...) is likely to crash dur to an out-of-bounds read. DO NOT FIX - that crash on NaN since it could result in a worse issue later on. */ - celt_assert(!celt_isnan(tmp[0])); - celt_assert(!celt_isnan(norm)); - for (i = 12; i < len2 - 5; i += 4) { - int id; -#ifdef FIXED_POINT - id = MAX32(0, MIN32(127, MULT16_32_Q15(tmp[i] + EPSILON, norm))); /* Do not round to nearest */ -#else - id = (int)MAX32(0, MIN32(127, floor(64 * norm * (tmp[i] + EPSILON)))); /* Do not round to nearest */ -#endif - unmask += inv_table[id]; - } - /*printf("%d\n", unmask);*/ - /* Normalize, compensate for the 1/4th of the sample and the factor of 6 in the inverse table */ - unmask = 64 * unmask * 4 / (6 * (len2 - 17)); - if (unmask > mask_metric) { - *tf_chan = c; - mask_metric = unmask; - } - } - is_transient = mask_metric > 200; - /* For low bitrates, define "weak transients" that need to be - handled differently to avoid partial collapse. */ - if (allow_weak_transients && is_transient && mask_metric < 600) { - is_transient = 0; - *weak_transient = 1; - } - /* Arbitrary metric for VBR boost */ - tf_max = MAX16(0, celt_sqrt(27 * mask_metric) - 42); - /* *tf_estimate = 1 + MIN16(1, sqrt(MAX16(0, tf_max-30))/20); */ - *tf_estimate = celt_sqrt(MAX32(0, SHL32(MULT16_16(QCONST16(0.0069, 14), MIN16(163, tf_max)), 14) - QCONST32(0.139, 28))); - /*printf("%d %f\n", tf_max, mask_metric);*/ - RESTORE_STACK; -#ifdef FUZZING - is_transient = rand() & 0x1; -#endif - /*printf("%d %f %d\n", is_transient, (float)*tf_estimate, tf_max);*/ - return is_transient; -} - -/* Looks for sudden increases of energy to decide whether we need to patch - the transient decision */ -static int patch_transient_decision(opus_val16 *newE, opus_val16 *oldE, int nbEBands, - int start, int end, int C) { - int i, c; - opus_val32 mean_diff = 0; - opus_val16 spread_old[26]; - /* Apply an aggressive (-6 dB/Bark) spreading function to the old frame to - avoid false detection caused by irrelevant bands */ - if (C == 1) { - spread_old[start] = oldE[start]; - for (i = start + 1; i < end; i++) { - spread_old[i] = MAX16(spread_old[i - 1] - QCONST16(1.0f, DB_SHIFT), oldE[i]); - } - } else { - spread_old[start] = MAX16(oldE[start], oldE[start + nbEBands]); - for (i = start + 1; i < end; i++) - spread_old[i] = MAX16(spread_old[i - 1] - QCONST16(1.0f, DB_SHIFT), - MAX16(oldE[i], oldE[i + nbEBands])); - } - for (i = end - 2; i >= start; i--) { - spread_old[i] = MAX16(spread_old[i], spread_old[i + 1] - QCONST16(1.0f, DB_SHIFT)); - } - /* Compute mean increase */ - c = 0; do { - for (i = IMAX(2, start); i < end - 1; i++) { - opus_val16 x1, x2; - x1 = MAX16(0, newE[i + c * nbEBands]); - x2 = MAX16(0, spread_old[i]); - mean_diff = ADD32(mean_diff, EXTEND32(MAX16(0, SUB16(x1, x2)))); - } - } while (++c < C); - mean_diff = DIV32(mean_diff, C * (end - 1 - IMAX(2, start))); - /*printf("%f %f %d\n", mean_diff, max_diff, count);*/ - return mean_diff > QCONST16(1.f, DB_SHIFT); -} - -/** Apply window and compute the MDCT for all sub-frames and - all channels in a frame */ -static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * OPUS_RESTRICT in, - celt_sig * OPUS_RESTRICT out, int C, int CC, int LM, int upsample, - int arch) { - const int overlap = mode->overlap; - int N; - int B; - int shift; - int i, b, c; - if (shortBlocks) { - B = shortBlocks; - N = mode->shortMdctSize; - shift = mode->maxLM; - } else { - B = 1; - N = mode->shortMdctSize << LM; - shift = mode->maxLM - LM; - } - c = 0; do { - for (b = 0; b < B; b++) { - /* Interleaving the sub-frames while doing the MDCTs */ - clt_mdct_forward(&mode->mdct, in + c * (B * N + overlap) + b * N, - &out[b + c * N * B], mode->window, overlap, shift, B, - arch); - } - } while (++c < CC); - if (CC == 2 && C == 1) { - for (i = 0; i < B * N; i++) { - out[i] = ADD32(HALF32(out[i]), HALF32(out[B * N + i])); - } - } - if (upsample != 1) { - c = 0; do { - int bound = B * N / upsample; - for (i = 0; i < bound; i++) { - out[c * B * N + i] *= upsample; - } - OPUS_CLEAR(&out[c * B * N + bound], B * N - bound); - } while (++c < C); - } -} - - -void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp, - int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip) { - int i; - opus_val16 coef0; - celt_sig m; - int Nu; - - coef0 = coef[0]; - m = *mem; - - /* Fast path for the normal 48kHz case and no clipping */ - if (coef[1] == 0 && upsample == 1 && !clip) { - for (i = 0; i < N; i++) { - opus_val16 x; - x = SCALEIN(pcmp[CC * i]); - /* Apply pre-emphasis */ - inp[i] = SHL32(x, SIG_SHIFT) - m; - m = SHR32(MULT16_16(coef0, x), 15 - SIG_SHIFT); - } - *mem = m; - return; - } - - Nu = N / upsample; - if (upsample != 1) { - OPUS_CLEAR(inp, N); - } - for (i = 0; i < Nu; i++) { - inp[i * upsample] = SCALEIN(pcmp[CC * i]); - } - -#ifndef FIXED_POINT - if (clip) { - /* Clip input to avoid encoding non-portable files */ - for (i = 0; i < Nu; i++) { - inp[i * upsample] = MAX32(-65536.f, MIN32(65536.f, inp[i * upsample])); - } - } -#else - (void)clip; /* Avoids a warning about clip being unused. */ -#endif -#ifdef CUSTOM_MODES - if (coef[1] != 0) { - opus_val16 coef1 = coef[1]; - opus_val16 coef2 = coef[2]; - for (i = 0; i < N; i++) { - celt_sig x, tmp; - x = inp[i]; - /* Apply pre-emphasis */ - tmp = MULT16_16(coef2, x); - inp[i] = tmp + m; - m = MULT16_32_Q15(coef1, inp[i]) - MULT16_32_Q15(coef0, tmp); - } - } else -#endif - { - for (i = 0; i < N; i++) { - opus_val16 x; - x = inp[i]; - /* Apply pre-emphasis */ - inp[i] = SHL32(x, SIG_SHIFT) - m; - m = SHR32(MULT16_16(coef0, x), 15 - SIG_SHIFT); - } - } - *mem = m; -} - - - -static opus_val32 l1_metric(const celt_norm *tmp, int N, int LM, opus_val16 bias) { - int i; - opus_val32 L1; - L1 = 0; - for (i = 0; i < N; i++) { - L1 += EXTEND32(ABS16(tmp[i])); - } - /* When in doubt, prefer good freq resolution */ - L1 = MAC16_32_Q15(L1, LM * bias, L1); - return L1; - -} - -static int tf_analysis(const CELTMode *m, int len, int isTransient, - int *tf_res, int lambda, celt_norm *X, int N0, int LM, - opus_val16 tf_estimate, int tf_chan, int *importance) { - int i; - VARDECL(int, metric); - int cost0; - int cost1; - VARDECL(int, path0); - VARDECL(int, path1); - VARDECL(celt_norm, tmp); - VARDECL(celt_norm, tmp_1); - int sel; - int selcost[2]; - int tf_select = 0; - opus_val16 bias; - - SAVE_STACK; - bias = MULT16_16_Q14(QCONST16(.04f, 15), MAX16(-QCONST16(.25f, 14), QCONST16(.5f, 14) - tf_estimate)); - /*printf("%f ", bias);*/ - - ALLOC(metric, len, int); - ALLOC(tmp, (m->eBands[len] - m->eBands[len - 1]) << LM, celt_norm); - ALLOC(tmp_1, (m->eBands[len] - m->eBands[len - 1]) << LM, celt_norm); - ALLOC(path0, len, int); - ALLOC(path1, len, int); - - for (i = 0; i < len; i++) { - int k, N; - int narrow; - opus_val32 L1, best_L1; - int best_level = 0; - N = (m->eBands[i + 1] - m->eBands[i]) << LM; - /* band is too narrow to be split down to LM=-1 */ - narrow = (m->eBands[i + 1] - m->eBands[i]) == 1; - OPUS_COPY(tmp, &X[tf_chan * N0 + (m->eBands[i] << LM)], N); - /* Just add the right channel if we're in stereo */ - /* if (C==2) - for (j=0;jeBands[i]<> LM, 1 << LM); - L1 = l1_metric(tmp_1, N, LM + 1, bias); - if (L1 < best_L1) { - best_L1 = L1; - best_level = -1; - } - } - /*printf ("%f ", L1);*/ - for (k = 0; k < LM + !(isTransient || narrow); k++) { - int B; - - if (isTransient) { - B = (LM - k - 1); - } else { - B = k + 1; - } - - haar1(tmp, N >> k, 1 << k); - - L1 = l1_metric(tmp, N, B, bias); - - if (L1 < best_L1) { - best_L1 = L1; - best_level = k + 1; - } - } - /*printf ("%d ", isTransient ? LM-best_level : best_level);*/ - /* metric is in Q1 to be able to select the mid-point (-0.5) for narrower bands */ - if (isTransient) { - metric[i] = 2 * best_level; - } else { - metric[i] = -2 * best_level; - } - /* For bands that can't be split to -1, set the metric to the half-way point to avoid - biasing the decision */ - if (narrow && (metric[i] == 0 || metric[i] == -2 * LM)) { - metric[i] -= 1; - } - /*printf("%d ", metric[i]/2 + (!isTransient)*LM);*/ - } - /*printf("\n");*/ - /* Search for the optimal tf resolution, including tf_select */ - tf_select = 0; - for (sel = 0; sel < 2; sel++) { - cost0 = importance[0] * abs(metric[0] - 2 * tf_select_table[LM][4 * isTransient + 2 * sel + 0]); - cost1 = importance[0] * abs(metric[0] - 2 * tf_select_table[LM][4 * isTransient + 2 * sel + 1]) + (isTransient ? 0 : lambda); - for (i = 1; i < len; i++) { - int curr0, curr1; - curr0 = IMIN(cost0, cost1 + lambda); - curr1 = IMIN(cost0 + lambda, cost1); - cost0 = curr0 + importance[i] * abs(metric[i] - 2 * tf_select_table[LM][4 * isTransient + 2 * sel + 0]); - cost1 = curr1 + importance[i] * abs(metric[i] - 2 * tf_select_table[LM][4 * isTransient + 2 * sel + 1]); - } - cost0 = IMIN(cost0, cost1); - selcost[sel] = cost0; - } - /* For now, we're conservative and only allow tf_select=1 for transients. - If tests confirm it's useful for non-transients, we could allow it. */ - if (selcost[1] < selcost[0] && isTransient) { - tf_select = 1; - } - cost0 = importance[0] * abs(metric[0] - 2 * tf_select_table[LM][4 * isTransient + 2 * tf_select + 0]); - cost1 = importance[0] * abs(metric[0] - 2 * tf_select_table[LM][4 * isTransient + 2 * tf_select + 1]) + (isTransient ? 0 : lambda); - /* Viterbi forward pass */ - for (i = 1; i < len; i++) { - int curr0, curr1; - int from0, from1; - - from0 = cost0; - from1 = cost1 + lambda; - if (from0 < from1) { - curr0 = from0; - path0[i] = 0; - } else { - curr0 = from1; - path0[i] = 1; - } - - from0 = cost0 + lambda; - from1 = cost1; - if (from0 < from1) { - curr1 = from0; - path1[i] = 0; - } else { - curr1 = from1; - path1[i] = 1; - } - cost0 = curr0 + importance[i] * abs(metric[i] - 2 * tf_select_table[LM][4 * isTransient + 2 * tf_select + 0]); - cost1 = curr1 + importance[i] * abs(metric[i] - 2 * tf_select_table[LM][4 * isTransient + 2 * tf_select + 1]); - } - tf_res[len - 1] = cost0 < cost1 ? 0 : 1; - /* Viterbi backward pass to check the decisions */ - for (i = len - 2; i >= 0; i--) { - if (tf_res[i + 1] == 1) { - tf_res[i] = path1[i + 1]; - } else { - tf_res[i] = path0[i + 1]; - } - } - /*printf("%d %f\n", *tf_sum, tf_estimate);*/ - RESTORE_STACK; -#ifdef FUZZING - tf_select = rand() & 0x1; - tf_res[0] = rand() & 0x1; - for (i = 1; i < len; i++) { - tf_res[i] = tf_res[i - 1] ^ ((rand() & 0xF) == 0); - } -#endif - return tf_select; -} - -static void tf_encode(int start, int end, int isTransient, int *tf_res, int LM, int tf_select, ec_enc *enc) { - int curr, i; - int tf_select_rsv; - int tf_changed; - int logp; - opus_uint32 budget; - opus_uint32 tell; - budget = enc->storage * 8; - tell = ec_tell(enc); - logp = isTransient ? 2 : 4; - /* Reserve space to code the tf_select decision. */ - tf_select_rsv = LM > 0 && tell + logp + 1 <= budget; - budget -= tf_select_rsv; - curr = tf_changed = 0; - for (i = start; i < end; i++) { - if (tell + logp <= budget) { - ec_enc_bit_logp(enc, tf_res[i] ^ curr, logp); - tell = ec_tell(enc); - curr = tf_res[i]; - tf_changed |= curr; - } else { - tf_res[i] = curr; - } - logp = isTransient ? 4 : 5; - } - /* Only code tf_select if it would actually make a difference. */ - if (tf_select_rsv && - tf_select_table[LM][4 * isTransient + 0 + tf_changed] != - tf_select_table[LM][4 * isTransient + 2 + tf_changed]) { - ec_enc_bit_logp(enc, tf_select, 1); - } else { - tf_select = 0; - } - for (i = start; i < end; i++) { - tf_res[i] = tf_select_table[LM][4 * isTransient + 2 * tf_select + tf_res[i]]; - } - /*for(i=0;i> 10; - trim = QCONST16(4.f, 8) + QCONST16(1.f / 16.f, 8) * frac; - } - if (C == 2) { - opus_val16 sum = 0; /* Q10 */ - opus_val16 minXC; /* Q10 */ - /* Compute inter-channel correlation for low frequencies */ - for (i = 0; i < 8; i++) { - opus_val32 partial; - partial = celt_inner_prod(&X[m->eBands[i] << LM], &X[N0 + (m->eBands[i] << LM)], - (m->eBands[i + 1] - m->eBands[i]) << LM, arch); - sum = ADD16(sum, EXTRACT16(SHR32(partial, 18))); - } - sum = MULT16_16_Q15(QCONST16(1.f / 8, 15), sum); - sum = MIN16(QCONST16(1.f, 10), ABS16(sum)); - minXC = sum; - for (i = 8; i < intensity; i++) { - opus_val32 partial; - partial = celt_inner_prod(&X[m->eBands[i] << LM], &X[N0 + (m->eBands[i] << LM)], - (m->eBands[i + 1] - m->eBands[i]) << LM, arch); - minXC = MIN16(minXC, ABS16(EXTRACT16(SHR32(partial, 18)))); - } - minXC = MIN16(QCONST16(1.f, 10), ABS16(minXC)); - /*printf ("%f\n", sum);*/ - /* mid-side savings estimations based on the LF average*/ - logXC = celt_log2(QCONST32(1.001f, 20) - MULT16_16(sum, sum)); - /* mid-side savings estimations based on min correlation */ - logXC2 = MAX16(HALF16(logXC), celt_log2(QCONST32(1.001f, 20) - MULT16_16(minXC, minXC))); -#ifdef FIXED_POINT - /* Compensate for Q20 vs Q14 input and convert output to Q8 */ - logXC = PSHR32(logXC - QCONST16(6.f, DB_SHIFT), DB_SHIFT - 8); - logXC2 = PSHR32(logXC2 - QCONST16(6.f, DB_SHIFT), DB_SHIFT - 8); -#endif - - trim += MAX16(-QCONST16(4.f, 8), MULT16_16_Q15(QCONST16(.75f, 15), logXC)); - *stereo_saving = MIN16(*stereo_saving + QCONST16(0.25f, 8), -HALF16(logXC2)); - } - - /* Estimate spectral tilt */ - c = 0; do { - for (i = 0; i < end - 1; i++) { - diff += bandLogE[i + c * m->nbEBands] * (opus_int32)(2 + 2 * i - end); - } - } while (++c < C); - diff /= C * (end - 1); - /*printf("%f\n", diff);*/ - trim -= MAX32(-QCONST16(2.f, 8), MIN32(QCONST16(2.f, 8), SHR32(diff + QCONST16(1.f, DB_SHIFT), DB_SHIFT - 8) / 6)); - trim -= SHR16(surround_trim, DB_SHIFT - 8); - trim -= 2 * SHR16(tf_estimate, 14 - 8); -#ifndef DISABLE_FLOAT_API - if (analysis->valid) { - trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), - (opus_val16)(QCONST16(2.f, 8) * (analysis->tonality_slope + .05f)))); - } -#else - (void)analysis; -#endif - -#ifdef FIXED_POINT - trim_index = PSHR32(trim, 8); -#else - trim_index = (int)floor(.5f + trim); -#endif - trim_index = IMAX(0, IMIN(10, trim_index)); - /*printf("%d\n", trim_index);*/ -#ifdef FUZZING - trim_index = rand() % 11; -#endif - return trim_index; -} - -static int stereo_analysis(const CELTMode *m, const celt_norm *X, - int LM, int N0) { - int i; - int thetas; - opus_val32 sumLR = EPSILON, sumMS = EPSILON; - - /* Use the L1 norm to model the entropy of the L/R signal vs the M/S signal */ - for (i = 0; i < 13; i++) { - int j; - for (j = m->eBands[i] << LM; j < m->eBands[i + 1] << LM; j++) { - opus_val32 L, R, M, S; - /* We cast to 32-bit first because of the -32768 case */ - L = EXTEND32(X[j]); - R = EXTEND32(X[N0 + j]); - M = ADD32(L, R); - S = SUB32(L, R); - sumLR = ADD32(sumLR, ADD32(ABS32(L), ABS32(R))); - sumMS = ADD32(sumMS, ADD32(ABS32(M), ABS32(S))); - } - } - sumMS = MULT16_32_Q15(QCONST16(0.707107f, 15), sumMS); - thetas = 13; - /* We don't need thetas for lower bands with LM<=1 */ - if (LM <= 1) { - thetas -= 8; - } - return MULT16_32_Q15((m->eBands[13] << (LM + 1)) + thetas, sumMS) - > MULT16_32_Q15(m->eBands[13] << (LM + 1), sumLR); -} - -#define MSWAP(a,b) do {opus_val16 tmp = a;a=b;b=tmp;} while(0) -static opus_val16 median_of_5(const opus_val16 *x) { - opus_val16 t0, t1, t2, t3, t4; - t2 = x[2]; - if (x[0] > x[1]) { - t0 = x[1]; - t1 = x[0]; - } else { - t0 = x[0]; - t1 = x[1]; - } - if (x[3] > x[4]) { - t3 = x[4]; - t4 = x[3]; - } else { - t3 = x[3]; - t4 = x[4]; - } - if (t0 > t3) { - MSWAP(t0, t3); - MSWAP(t1, t4); - } - if (t2 > t1) { - if (t1 < t3) { - return MIN16(t2, t3); - } else { - return MIN16(t4, t1); - } - } else { - if (t2 < t3) { - return MIN16(t1, t3); - } else { - return MIN16(t2, t4); - } - } -} - -static opus_val16 median_of_3(const opus_val16 *x) { - opus_val16 t0, t1, t2; - if (x[0] > x[1]) { - t0 = x[1]; - t1 = x[0]; - } else { - t0 = x[0]; - t1 = x[1]; - } - t2 = x[2]; - if (t1 < t2) { - return t1; - } else if (t0 < t2) { - return t2; - } else { - return t0; - } -} - -static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2, - int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN, - int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM, - int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc, - AnalysisInfo *analysis, int *importance, int *spread_weight) { - int i, c; - opus_int32 tot_boost = 0; - opus_val16 maxDepth; - VARDECL(opus_val16, follower); - VARDECL(opus_val16, noise_floor); - SAVE_STACK; - ALLOC(follower, C * nbEBands, opus_val16); - ALLOC(noise_floor, C * nbEBands, opus_val16); - OPUS_CLEAR(offsets, nbEBands); - /* Dynamic allocation code */ - maxDepth = -QCONST16(31.9f, DB_SHIFT); - for (i = 0; i < end; i++) { - /* Noise floor must take into account eMeans, the depth, the width of the bands - and the preemphasis filter (approx. square of bark band ID) */ - noise_floor[i] = MULT16_16(QCONST16(0.0625f, DB_SHIFT), logN[i]) - + QCONST16(.5f, DB_SHIFT) + SHL16(9 - lsb_depth, DB_SHIFT) - SHL16(eMeans[i], 6) - + MULT16_16(QCONST16(.0062, DB_SHIFT), (i + 5) * (i + 5)); - } - c = 0; do { - for (i = 0; i < end; i++) { - maxDepth = MAX16(maxDepth, bandLogE[c * nbEBands + i] - noise_floor[i]); - } - } while (++c < C); - { - /* Compute a really simple masking model to avoid taking into account completely masked - bands when computing the spreading decision. */ - VARDECL(opus_val16, mask); - VARDECL(opus_val16, sig); - ALLOC(mask, nbEBands, opus_val16); - ALLOC(sig, nbEBands, opus_val16); - for (i = 0; i < end; i++) { - mask[i] = bandLogE[i] - noise_floor[i]; - } - if (C == 2) { - for (i = 0; i < end; i++) { - mask[i] = MAX16(mask[i], bandLogE[nbEBands + i] - noise_floor[i]); - } - } - OPUS_COPY(sig, mask, end); - for (i = 1; i < end; i++) { - mask[i] = MAX16(mask[i], mask[i - 1] - QCONST16(2.f, DB_SHIFT)); - } - for (i = end - 2; i >= 0; i--) { - mask[i] = MAX16(mask[i], mask[i + 1] - QCONST16(3.f, DB_SHIFT)); - } - for (i = 0; i < end; i++) { - /* Compute SMR: Mask is never more than 72 dB below the peak and never below the noise floor.*/ - opus_val16 smr = sig[i] - MAX16(MAX16(0, maxDepth - QCONST16(12.f, DB_SHIFT)), mask[i]); - /* Clamp SMR to make sure we're not shifting by something negative or too large. */ -#ifdef FIXED_POINT - /* FIXME: Use PSHR16() instead */ - int shift = -PSHR32(MAX16(-QCONST16(5.f, DB_SHIFT), MIN16(0, smr)), DB_SHIFT); -#else - int shift = IMIN(5, IMAX(0, -(int)floor(.5f + smr))); -#endif - spread_weight[i] = 32 >> shift; - } - /* for (i=0;i 50 && LM >= 1 && !lfe) { - int last = 0; - c = 0; do { - opus_val16 offset; - opus_val16 tmp; - opus_val16 *f; - f = &follower[c * nbEBands]; - f[0] = bandLogE2[c * nbEBands]; - for (i = 1; i < end; i++) { - /* The last band to be at least 3 dB higher than the previous one - is the last we'll consider. Otherwise, we run into problems on - bandlimited signals. */ - if (bandLogE2[c * nbEBands + i] > bandLogE2[c * nbEBands + i - 1] + QCONST16(.5f, DB_SHIFT)) { - last = i; - } - f[i] = MIN16(f[i - 1] + QCONST16(1.5f, DB_SHIFT), bandLogE2[c * nbEBands + i]); - } - for (i = last - 1; i >= 0; i--) { - f[i] = MIN16(f[i], MIN16(f[i + 1] + QCONST16(2.f, DB_SHIFT), bandLogE2[c * nbEBands + i])); - } - - /* Combine with a median filter to avoid dynalloc triggering unnecessarily. - The "offset" value controls how conservative we are -- a higher offset - reduces the impact of the median filter and makes dynalloc use more bits. */ - offset = QCONST16(1.f, DB_SHIFT); - for (i = 2; i < end - 2; i++) { - f[i] = MAX16(f[i], median_of_5(&bandLogE2[c * nbEBands + i - 2]) - offset); - } - tmp = median_of_3(&bandLogE2[c * nbEBands]) - offset; - f[0] = MAX16(f[0], tmp); - f[1] = MAX16(f[1], tmp); - tmp = median_of_3(&bandLogE2[c * nbEBands + end - 3]) - offset; - f[end - 2] = MAX16(f[end - 2], tmp); - f[end - 1] = MAX16(f[end - 1], tmp); - - for (i = 0; i < end; i++) { - f[i] = MAX16(f[i], noise_floor[i]); - } - } while (++c < C); - if (C == 2) { - for (i = start; i < end; i++) { - /* Consider 24 dB "cross-talk" */ - follower[nbEBands + i] = MAX16(follower[nbEBands + i], follower[ i] - QCONST16(4.f, DB_SHIFT)); - follower[ i] = MAX16(follower[ i], follower[nbEBands + i] - QCONST16(4.f, DB_SHIFT)); - follower[i] = HALF16(MAX16(0, bandLogE[i] - follower[i]) + MAX16(0, bandLogE[nbEBands + i] - follower[nbEBands + i])); - } - } else { - for (i = start; i < end; i++) { - follower[i] = MAX16(0, bandLogE[i] - follower[i]); - } - } - for (i = start; i < end; i++) { - follower[i] = MAX16(follower[i], surround_dynalloc[i]); - } - for (i = start; i < end; i++) { -#ifdef FIXED_POINT - importance[i] = PSHR32(13 * celt_exp2(MIN16(follower[i], QCONST16(4.f, DB_SHIFT))), 16); -#else - importance[i] = (int)floor(.5f + 13 * celt_exp2(MIN16(follower[i], QCONST16(4.f, DB_SHIFT)))); -#endif - } - /* For non-transient CBR/CVBR frames, halve the dynalloc contribution */ - if ((!vbr || constrained_vbr) && !isTransient) { - for (i = start; i < end; i++) { - follower[i] = HALF16(follower[i]); - } - } - for (i = start; i < end; i++) { - if (i < 8) { - follower[i] *= 2; - } - if (i >= 12) { - follower[i] = HALF16(follower[i]); - } - } -#ifdef DISABLE_FLOAT_API - (void)analysis; -#else - if (analysis->valid) { - for (i = start; i < IMIN(LEAK_BANDS, end); i++) { - follower[i] = follower[i] + QCONST16(1.f / 64.f, DB_SHIFT) * analysis->leak_boost[i]; - } - } -#endif - for (i = start; i < end; i++) { - int width; - int boost; - int boost_bits; - - follower[i] = MIN16(follower[i], QCONST16(4, DB_SHIFT)); - - width = C * (eBands[i + 1] - eBands[i]) << LM; - if (width < 6) { - boost = (int)SHR32(EXTEND32(follower[i]), DB_SHIFT); - boost_bits = boost * width << BITRES; - } else if (width > 48) { - boost = (int)SHR32(EXTEND32(follower[i]) * 8, DB_SHIFT); - boost_bits = (boost * width << BITRES) / 8; - } else { - boost = (int)SHR32(EXTEND32(follower[i]) * width / 6, DB_SHIFT); - boost_bits = boost * 6 << BITRES; - } - /* For CBR and non-transient CVBR frames, limit dynalloc to 2/3 of the bits */ - if ((!vbr || (constrained_vbr && !isTransient)) - && (tot_boost + boost_bits) >> BITRES >> 3 > 2 * effectiveBytes / 3) { - opus_int32 cap = ((2 * effectiveBytes / 3) << BITRES << 3); - offsets[i] = cap - tot_boost; - tot_boost = cap; - break; - } else { - offsets[i] = boost; - tot_boost += boost_bits; - } - } - } else { - for (i = start; i < end; i++) { - importance[i] = 13; - } - } - *tot_boost_ = tot_boost; - RESTORE_STACK; - return maxDepth; -} - - -static int run_prefilter(CELTEncoder *st, celt_sig *in, celt_sig *prefilter_mem, int CC, int N, - int prefilter_tapset, int *pitch, opus_val16 *gain, int *qgain, int enabled, int nbAvailableBytes, AnalysisInfo *analysis) { - int c; - VARDECL(celt_sig, _pre); - celt_sig *pre[2]; - const CELTMode *mode; - int pitch_index; - opus_val16 gain1; - opus_val16 pf_threshold; - int pf_on; - int qg; - int overlap; - SAVE_STACK; - - mode = st->mode; - overlap = mode->overlap; - ALLOC(_pre, CC * (N + COMBFILTER_MAXPERIOD), celt_sig); - - pre[0] = _pre; - pre[1] = _pre + (N + COMBFILTER_MAXPERIOD); - - - c = 0; do { - OPUS_COPY(pre[c], prefilter_mem + c * COMBFILTER_MAXPERIOD, COMBFILTER_MAXPERIOD); - OPUS_COPY(pre[c] + COMBFILTER_MAXPERIOD, in + c * (N + overlap) + overlap, N); - } while (++c < CC); - - if (enabled) { - VARDECL(opus_val16, pitch_buf); - ALLOC(pitch_buf, (COMBFILTER_MAXPERIOD + N) >> 1, opus_val16); - - pitch_downsample(pre, pitch_buf, COMBFILTER_MAXPERIOD + N, CC, st->arch); - /* Don't search for the fir last 1.5 octave of the range because - there's too many false-positives due to short-term correlation */ - pitch_search(pitch_buf + (COMBFILTER_MAXPERIOD >> 1), pitch_buf, N, - COMBFILTER_MAXPERIOD - 3 * COMBFILTER_MINPERIOD, &pitch_index, - st->arch); - pitch_index = COMBFILTER_MAXPERIOD - pitch_index; - - gain1 = remove_doubling(pitch_buf, COMBFILTER_MAXPERIOD, COMBFILTER_MINPERIOD, - N, &pitch_index, st->prefilter_period, st->prefilter_gain, st->arch); - if (pitch_index > COMBFILTER_MAXPERIOD - 2) { - pitch_index = COMBFILTER_MAXPERIOD - 2; - } - gain1 = MULT16_16_Q15(QCONST16(.7f, 15), gain1); - /*printf("%d %d %f %f\n", pitch_change, pitch_index, gain1, st->analysis.tonality);*/ - if (st->loss_rate > 2) { - gain1 = HALF32(gain1); - } - if (st->loss_rate > 4) { - gain1 = HALF32(gain1); - } - if (st->loss_rate > 8) { - gain1 = 0; - } - } else { - gain1 = 0; - pitch_index = COMBFILTER_MINPERIOD; - } -#ifndef DISABLE_FLOAT_API - if (analysis->valid) { - gain1 = (opus_val16)(gain1 * analysis->max_pitch_ratio); - } -#else - (void)analysis; -#endif - /* Gain threshold for enabling the prefilter/postfilter */ - pf_threshold = QCONST16(.2f, 15); - - /* Adjusting the threshold based on rate and continuity */ - if (abs(pitch_index - st->prefilter_period) * 10 > pitch_index) { - pf_threshold += QCONST16(.2f, 15); - } - if (nbAvailableBytes < 25) { - pf_threshold += QCONST16(.1f, 15); - } - if (nbAvailableBytes < 35) { - pf_threshold += QCONST16(.1f, 15); - } - if (st->prefilter_gain > QCONST16(.4f, 15)) { - pf_threshold -= QCONST16(.1f, 15); - } - if (st->prefilter_gain > QCONST16(.55f, 15)) { - pf_threshold -= QCONST16(.1f, 15); - } - - /* Hard threshold at 0.2 */ - pf_threshold = MAX16(pf_threshold, QCONST16(.2f, 15)); - if (gain1 < pf_threshold) { - gain1 = 0; - pf_on = 0; - qg = 0; - } else { - /* This block is not gated by a total bits check only because - of the nbAvailableBytes check above.*/ - if (ABS16(gain1 - st->prefilter_gain) < QCONST16(.1f, 15)) { - gain1 = st->prefilter_gain; - } - -#ifdef FIXED_POINT - qg = ((gain1 + 1536) >> 10) / 3 - 1; -#else - qg = (int)floor(.5f + gain1 * 32 / 3) - 1; -#endif - qg = IMAX(0, IMIN(7, qg)); - gain1 = QCONST16(0.09375f, 15) * (qg + 1); - pf_on = 1; - } - /*printf("%d %f\n", pitch_index, gain1);*/ - - c = 0; do { - int offset = mode->shortMdctSize - overlap; - st->prefilter_period = IMAX(st->prefilter_period, COMBFILTER_MINPERIOD); - OPUS_COPY(in + c * (N + overlap), st->in_mem + c * (overlap), overlap); - if (offset) - comb_filter(in + c * (N + overlap) + overlap, pre[c] + COMBFILTER_MAXPERIOD, - st->prefilter_period, st->prefilter_period, offset, -st->prefilter_gain, -st->prefilter_gain, - st->prefilter_tapset, st->prefilter_tapset, NULL, 0, st->arch); - - comb_filter(in + c * (N + overlap) + overlap + offset, pre[c] + COMBFILTER_MAXPERIOD + offset, - st->prefilter_period, pitch_index, N - offset, -st->prefilter_gain, -gain1, - st->prefilter_tapset, prefilter_tapset, mode->window, overlap, st->arch); - OPUS_COPY(st->in_mem + c * (overlap), in + c * (N + overlap) + N, overlap); - - if (N > COMBFILTER_MAXPERIOD) { - OPUS_COPY(prefilter_mem + c * COMBFILTER_MAXPERIOD, pre[c] + N, COMBFILTER_MAXPERIOD); - } else { - OPUS_MOVE(prefilter_mem + c * COMBFILTER_MAXPERIOD, prefilter_mem + c * COMBFILTER_MAXPERIOD + N, COMBFILTER_MAXPERIOD - N); - OPUS_COPY(prefilter_mem + c * COMBFILTER_MAXPERIOD + COMBFILTER_MAXPERIOD - N, pre[c] + COMBFILTER_MAXPERIOD, N); - } - } while (++c < CC); - - RESTORE_STACK; - *gain = gain1; - *pitch = pitch_index; - *qgain = qg; - return pf_on; -} - -static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 base_target, - int LM, opus_int32 bitrate, int lastCodedBands, int C, int intensity, - int constrained_vbr, opus_val16 stereo_saving, int tot_boost, - opus_val16 tf_estimate, int pitch_change, opus_val16 maxDepth, - int lfe, int has_surround_mask, opus_val16 surround_masking, - opus_val16 temporal_vbr) { - /* The target rate in 8th bits per frame */ - opus_int32 target; - int coded_bins; - int coded_bands; - opus_val16 tf_calibration; - int nbEBands; - const opus_int16 *eBands; - - nbEBands = mode->nbEBands; - eBands = mode->eBands; - - coded_bands = lastCodedBands ? lastCodedBands : nbEBands; - coded_bins = eBands[coded_bands] << LM; - if (C == 2) { - coded_bins += eBands[IMIN(intensity, coded_bands)] << LM; - } - - target = base_target; - - /*printf("%f %f %f %f %d %d ", st->analysis.activity, st->analysis.tonality, tf_estimate, st->stereo_saving, tot_boost, coded_bands);*/ -#ifndef DISABLE_FLOAT_API - if (analysis->valid && analysis->activity < .4) { - target -= (opus_int32)((coded_bins << BITRES) * (.4f - analysis->activity)); - } -#endif - /* Stereo savings */ - if (C == 2) { - int coded_stereo_bands; - int coded_stereo_dof; - opus_val16 max_frac; - coded_stereo_bands = IMIN(intensity, coded_bands); - coded_stereo_dof = (eBands[coded_stereo_bands] << LM) - coded_stereo_bands; - /* Maximum fraction of the bits we can save if the signal is mono. */ - max_frac = DIV32_16(MULT16_16(QCONST16(0.8f, 15), coded_stereo_dof), coded_bins); - stereo_saving = MIN16(stereo_saving, QCONST16(1.f, 8)); - /*printf("%d %d %d ", coded_stereo_dof, coded_bins, tot_boost);*/ - target -= (opus_int32)MIN32(MULT16_32_Q15(max_frac, target), - SHR32(MULT16_16(stereo_saving - QCONST16(0.1f, 8), (coded_stereo_dof << BITRES)), 8)); - } - /* Boost the rate according to dynalloc (minus the dynalloc average for calibration). */ - target += tot_boost - (19 << LM); - /* Apply transient boost, compensating for average boost. */ - tf_calibration = QCONST16(0.044f, 14); - target += (opus_int32)SHL32(MULT16_32_Q15(tf_estimate - tf_calibration, target), 1); - -#ifndef DISABLE_FLOAT_API - /* Apply tonality boost */ - if (analysis->valid && !lfe) { - opus_int32 tonal_target; - float tonal; - - /* Tonality boost (compensating for the average). */ - tonal = MAX16(0.f, analysis->tonality - .15f) - 0.12f; - tonal_target = target + (opus_int32)((coded_bins << BITRES) * 1.2f * tonal); - if (pitch_change) { - tonal_target += (opus_int32)((coded_bins << BITRES) * .8f); - } - /*printf("%f %f ", analysis->tonality, tonal);*/ - target = tonal_target; - } -#else - (void)analysis; - (void)pitch_change; -#endif - - if (has_surround_mask && !lfe) { - opus_int32 surround_target = target + (opus_int32)SHR32(MULT16_16(surround_masking, coded_bins << BITRES), DB_SHIFT); - /*printf("%f %d %d %d %d %d %d ", surround_masking, coded_bins, st->end, st->intensity, surround_target, target, st->bitrate);*/ - target = IMAX(target / 4, surround_target); - } - - { - opus_int32 floor_depth; - int bins; - bins = eBands[nbEBands - 2] << LM; - /*floor_depth = SHR32(MULT16_16((C*bins<> 2); - target = IMIN(target, floor_depth); - /*printf("%f %d\n", maxDepth, floor_depth);*/ - } - - /* Make VBR less aggressive for constrained VBR because we can't keep a higher bitrate - for long. Needs tuning. */ - if ((!has_surround_mask || lfe) && constrained_vbr) { - target = base_target + (opus_int32)MULT16_32_Q15(QCONST16(0.67f, 15), target - base_target); - } - - if (!has_surround_mask && tf_estimate < QCONST16(.2f, 14)) { - opus_val16 amount; - opus_val16 tvbr_factor; - amount = MULT16_16_Q15(QCONST16(.0000031f, 30), IMAX(0, IMIN(32000, 96000 - bitrate))); - tvbr_factor = SHR32(MULT16_16(temporal_vbr, amount), DB_SHIFT); - target += (opus_int32)MULT16_32_Q15(tvbr_factor, target); - } - - /* Don't allow more than doubling the rate */ - target = IMIN(2 * base_target, target); - - return target; -} - -int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) { - int i, c, N; - opus_int32 bits; - ec_enc _enc; - VARDECL(celt_sig, in); - VARDECL(celt_sig, freq); - VARDECL(celt_norm, X); - VARDECL(celt_ener, bandE); - VARDECL(opus_val16, bandLogE); - VARDECL(opus_val16, bandLogE2); - VARDECL(int, fine_quant); - VARDECL(opus_val16, error); - VARDECL(int, pulses); - VARDECL(int, cap); - VARDECL(int, offsets); - VARDECL(int, importance); - VARDECL(int, spread_weight); - VARDECL(int, fine_priority); - VARDECL(int, tf_res); - VARDECL(unsigned char, collapse_masks); - celt_sig *prefilter_mem; - opus_val16 *oldBandE, *oldLogE, *oldLogE2, *energyError; - int shortBlocks = 0; - int isTransient = 0; - const int CC = st->channels; - const int C = st->stream_channels; - int LM, M; - int tf_select; - int nbFilledBytes, nbAvailableBytes; - int start; - int end; - int effEnd; - int codedBands; - int alloc_trim; - int pitch_index = COMBFILTER_MINPERIOD; - opus_val16 gain1 = 0; - int dual_stereo = 0; - int effectiveBytes; - int dynalloc_logp; - opus_int32 vbr_rate; - opus_int32 total_bits; - opus_int32 total_boost; - opus_int32 balance; - opus_int32 tell; - opus_int32 tell0_frac; - int prefilter_tapset = 0; - int pf_on; - int anti_collapse_rsv; - int anti_collapse_on = 0; - int silence = 0; - int tf_chan = 0; - opus_val16 tf_estimate; - int pitch_change = 0; - opus_int32 tot_boost; - opus_val32 sample_max; - opus_val16 maxDepth; - const OpusCustomMode *mode; - int nbEBands; - int overlap; - const opus_int16 *eBands; - int secondMdct; - int signalBandwidth; - int transient_got_disabled = 0; - opus_val16 surround_masking = 0; - opus_val16 temporal_vbr = 0; - opus_val16 surround_trim = 0; - opus_int32 equiv_rate; - int hybrid; - int weak_transient = 0; - int enable_tf_analysis; - VARDECL(opus_val16, surround_dynalloc); - ALLOC_STACK; - - mode = st->mode; - nbEBands = mode->nbEBands; - overlap = mode->overlap; - eBands = mode->eBands; - start = st->start; - end = st->end; - hybrid = start != 0; - tf_estimate = 0; - if (nbCompressedBytes < 2 || pcm == NULL) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - frame_size *= st->upsample; - for (LM = 0; LM <= mode->maxLM; LM++) - if (mode->shortMdctSize << LM == frame_size) { - break; - } - if (LM > mode->maxLM) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - M = 1 << LM; - N = M * mode->shortMdctSize; - - prefilter_mem = st->in_mem + CC * (overlap); - oldBandE = (opus_val16*)(st->in_mem + CC * (overlap + COMBFILTER_MAXPERIOD)); - oldLogE = oldBandE + CC * nbEBands; - oldLogE2 = oldLogE + CC * nbEBands; - energyError = oldLogE2 + CC * nbEBands; - - if (enc == NULL) { - tell0_frac = tell = 1; - nbFilledBytes = 0; - } else { - tell0_frac = ec_tell_frac(enc); - tell = ec_tell(enc); - nbFilledBytes = (tell + 4) >> 3; - } - -#ifdef CUSTOM_MODES - if (st->signalling && enc == NULL) { - int tmp = (mode->effEBands - end) >> 1; - end = st->end = IMAX(1, mode->effEBands - tmp); - compressed[0] = tmp << 5; - compressed[0] |= LM << 3; - compressed[0] |= (C == 2) << 2; - /* Convert "standard mode" to Opus header */ - if (mode->Fs == 48000 && mode->shortMdctSize == 120) { - int c0 = toOpus(compressed[0]); - if (c0 < 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - compressed[0] = c0; - } - compressed++; - nbCompressedBytes--; - } -#else - celt_assert(st->signalling == 0); -#endif - - /* Can't produce more than 1275 output bytes */ - nbCompressedBytes = IMIN(nbCompressedBytes, 1275); - nbAvailableBytes = nbCompressedBytes - nbFilledBytes; - - if (st->vbr && st->bitrate != OPUS_BITRATE_MAX) { - opus_int32 den = mode->Fs >> BITRES; - vbr_rate = (st->bitrate * frame_size + (den >> 1)) / den; -#ifdef CUSTOM_MODES - if (st->signalling) { - vbr_rate -= 8 << BITRES; - } -#endif - effectiveBytes = vbr_rate >> (3 + BITRES); - } else { - opus_int32 tmp; - vbr_rate = 0; - tmp = st->bitrate * frame_size; - if (tell > 1) { - tmp += tell; - } - if (st->bitrate != OPUS_BITRATE_MAX) - nbCompressedBytes = IMAX(2, IMIN(nbCompressedBytes, - (tmp + 4 * mode->Fs) / (8 * mode->Fs) - !!st->signalling)); - effectiveBytes = nbCompressedBytes - nbFilledBytes; - } - equiv_rate = ((opus_int32)nbCompressedBytes * 8 * 50 >> (3 - LM)) - (40 * C + 20) * ((400 >> LM) - 50); - if (st->bitrate != OPUS_BITRATE_MAX) { - equiv_rate = IMIN(equiv_rate, st->bitrate - (40 * C + 20) * ((400 >> LM) - 50)); - } - - if (enc == NULL) { - ec_enc_init(&_enc, compressed, nbCompressedBytes); - enc = &_enc; - } - - if (vbr_rate > 0) { - /* Computes the max bit-rate allowed in VBR mode to avoid violating the - target rate and buffering. - We must do this up front so that bust-prevention logic triggers - correctly if we don't have enough bits. */ - if (st->constrained_vbr) { - opus_int32 vbr_bound; - opus_int32 max_allowed; - /* We could use any multiple of vbr_rate as bound (depending on the - delay). - This is clamped to ensure we use at least two bytes if the encoder - was entirely empty, but to allow 0 in hybrid mode. */ - vbr_bound = vbr_rate; - max_allowed = IMIN(IMAX(tell == 1 ? 2 : 0, - (vbr_rate + vbr_bound - st->vbr_reservoir) >> (BITRES + 3)), - nbAvailableBytes); - if (max_allowed < nbAvailableBytes) { - nbCompressedBytes = nbFilledBytes + max_allowed; - nbAvailableBytes = max_allowed; - ec_enc_shrink(enc, nbCompressedBytes); - } - } - } - total_bits = nbCompressedBytes * 8; - - effEnd = end; - if (effEnd > mode->effEBands) { - effEnd = mode->effEBands; - } - - ALLOC(in, CC * (N + overlap), celt_sig); - - sample_max = MAX32(st->overlap_max, celt_maxabs16(pcm, C * (N - overlap) / st->upsample)); - st->overlap_max = celt_maxabs16(pcm + C * (N - overlap) / st->upsample, C * overlap / st->upsample); - sample_max = MAX32(sample_max, st->overlap_max); -#ifdef FIXED_POINT - silence = (sample_max == 0); -#else - silence = (sample_max <= (opus_val16)1 / (1 << st->lsb_depth)); -#endif -#ifdef FUZZING - if ((rand() & 0x3F) == 0) { - silence = 1; - } -#endif - if (tell == 1) { - ec_enc_bit_logp(enc, silence, 15); - } else { - silence = 0; - } - if (silence) { - /*In VBR mode there is no need to send more than the minimum. */ - if (vbr_rate > 0) { - effectiveBytes = nbCompressedBytes = IMIN(nbCompressedBytes, nbFilledBytes + 2); - total_bits = nbCompressedBytes * 8; - nbAvailableBytes = 2; - ec_enc_shrink(enc, nbCompressedBytes); - } - /* Pretend we've filled all the remaining bits with zeros - (that's what the initialiser did anyway) */ - tell = nbCompressedBytes * 8; - enc->nbits_total += tell - ec_tell(enc); - } - c = 0; do { - int need_clip = 0; -#ifndef FIXED_POINT - need_clip = st->clip && sample_max > 65536.f; -#endif - celt_preemphasis(pcm + c, in + c * (N + overlap) + overlap, N, CC, st->upsample, - mode->preemph, st->preemph_memE + c, need_clip); - } while (++c < CC); - - - - /* Find pitch period and gain */ - { - int enabled; - int qg; - enabled = ((st->lfe && nbAvailableBytes > 3) || nbAvailableBytes > 12 * C) && !hybrid && !silence && !st->disable_pf - && st->complexity >= 5; - - prefilter_tapset = st->tapset_decision; - pf_on = run_prefilter(st, in, prefilter_mem, CC, N, prefilter_tapset, &pitch_index, &gain1, &qg, enabled, nbAvailableBytes, &st->analysis); - if ((gain1 > QCONST16(.4f, 15) || st->prefilter_gain > QCONST16(.4f, 15)) && (!st->analysis.valid || st->analysis.tonality > .3) - && (pitch_index > 1.26 * st->prefilter_period || pitch_index < .79 * st->prefilter_period)) { - pitch_change = 1; - } - if (pf_on == 0) { - if (!hybrid && tell + 16 <= total_bits) { - ec_enc_bit_logp(enc, 0, 1); - } - } else { - /* This block is not gated by a total bits check only because - of the nbAvailableBytes check above.*/ - int octave; - ec_enc_bit_logp(enc, 1, 1); - pitch_index += 1; - octave = EC_ILOG(pitch_index) - 5; - ec_enc_uint(enc, octave, 6); - ec_enc_bits(enc, pitch_index - (16 << octave), 4 + octave); - pitch_index -= 1; - ec_enc_bits(enc, qg, 3); - ec_enc_icdf(enc, prefilter_tapset, tapset_icdf, 2); - } - } - - isTransient = 0; - shortBlocks = 0; - if (st->complexity >= 1 && !st->lfe) { - /* Reduces the likelihood of energy instability on fricatives at low bitrate - in hybrid mode. It seems like we still want to have real transients on vowels - though (small SILK quantization offset value). */ - int allow_weak_transients = hybrid && effectiveBytes < 15 && st->silk_info.signalType != 2; - isTransient = transient_analysis(in, N + overlap, CC, - &tf_estimate, &tf_chan, allow_weak_transients, &weak_transient); - } - if (LM > 0 && ec_tell(enc) + 3 <= total_bits) { - if (isTransient) { - shortBlocks = M; - } - } else { - isTransient = 0; - transient_got_disabled = 1; - } - - ALLOC(freq, CC * N, celt_sig); /**< Interleaved signal MDCTs */ - ALLOC(bandE, nbEBands * CC, celt_ener); - ALLOC(bandLogE, nbEBands * CC, opus_val16); - - secondMdct = shortBlocks && st->complexity >= 8; - ALLOC(bandLogE2, C * nbEBands, opus_val16); - if (secondMdct) { - compute_mdcts(mode, 0, in, freq, C, CC, LM, st->upsample, st->arch); - compute_band_energies(mode, freq, bandE, effEnd, C, LM, st->arch); - amp2Log2(mode, effEnd, end, bandE, bandLogE2, C); - for (i = 0; i < C * nbEBands; i++) { - bandLogE2[i] += HALF16(SHL16(LM, DB_SHIFT)); - } - } - - compute_mdcts(mode, shortBlocks, in, freq, C, CC, LM, st->upsample, st->arch); - /* This should catch any NaN in the CELT input. Since we're not supposed to see any (they're filtered - at the Opus layer), just abort. */ - celt_assert(!celt_isnan(freq[0]) && (C == 1 || !celt_isnan(freq[N]))); - if (CC == 2 && C == 1) { - tf_chan = 0; - } - compute_band_energies(mode, freq, bandE, effEnd, C, LM, st->arch); - - if (st->lfe) { - for (i = 2; i < end; i++) { - bandE[i] = IMIN(bandE[i], MULT16_32_Q15(QCONST16(1e-4f, 15), bandE[0])); - bandE[i] = MAX32(bandE[i], EPSILON); - } - } - amp2Log2(mode, effEnd, end, bandE, bandLogE, C); - - ALLOC(surround_dynalloc, C * nbEBands, opus_val16); - OPUS_CLEAR(surround_dynalloc, end); - /* This computes how much masking takes place between surround channels */ - if (!hybrid && st->energy_mask && !st->lfe) { - int mask_end; - int midband; - int count_dynalloc; - opus_val32 mask_avg = 0; - opus_val32 diff = 0; - int count = 0; - mask_end = IMAX(2, st->lastCodedBands); - for (c = 0; c < C; c++) { - for (i = 0; i < mask_end; i++) { - opus_val16 mask; - mask = MAX16(MIN16(st->energy_mask[nbEBands * c + i], - QCONST16(.25f, DB_SHIFT)), -QCONST16(2.0f, DB_SHIFT)); - if (mask > 0) { - mask = HALF16(mask); - } - mask_avg += MULT16_16(mask, eBands[i + 1] - eBands[i]); - count += eBands[i + 1] - eBands[i]; - diff += MULT16_16(mask, 1 + 2 * i - mask_end); - } - } - celt_assert(count > 0); - mask_avg = DIV32_16(mask_avg, count); - mask_avg += QCONST16(.2f, DB_SHIFT); - diff = diff * 6 / (C * (mask_end - 1) * (mask_end + 1) * mask_end); - /* Again, being conservative */ - diff = HALF32(diff); - diff = MAX32(MIN32(diff, QCONST32(.031f, DB_SHIFT)), -QCONST32(.031f, DB_SHIFT)); - /* Find the band that's in the middle of the coded spectrum */ - for (midband = 0; eBands[midband + 1] < eBands[mask_end] / 2; midband++); - count_dynalloc = 0; - for (i = 0; i < mask_end; i++) { - opus_val32 lin; - opus_val16 unmask; - lin = mask_avg + diff * (i - midband); - if (C == 2) { - unmask = MAX16(st->energy_mask[i], st->energy_mask[nbEBands + i]); - } else { - unmask = st->energy_mask[i]; - } - unmask = MIN16(unmask, QCONST16(.0f, DB_SHIFT)); - unmask -= lin; - if (unmask > QCONST16(.25f, DB_SHIFT)) { - surround_dynalloc[i] = unmask - QCONST16(.25f, DB_SHIFT); - count_dynalloc++; - } - } - if (count_dynalloc >= 3) { - /* If we need dynalloc in many bands, it's probably because our - initial masking rate was too low. */ - mask_avg += QCONST16(.25f, DB_SHIFT); - if (mask_avg > 0) { - /* Something went really wrong in the original calculations, - disabling masking. */ - mask_avg = 0; - diff = 0; - OPUS_CLEAR(surround_dynalloc, mask_end); - } else { - for (i = 0; i < mask_end; i++) { - surround_dynalloc[i] = MAX16(0, surround_dynalloc[i] - QCONST16(.25f, DB_SHIFT)); - } - } - } - mask_avg += QCONST16(.2f, DB_SHIFT); - /* Convert to 1/64th units used for the trim */ - surround_trim = 64 * diff; - /*printf("%d %d ", mask_avg, surround_trim);*/ - surround_masking = mask_avg; - } - /* Temporal VBR (but not for LFE) */ - if (!st->lfe) { - opus_val16 follow = -QCONST16(10.0f, DB_SHIFT); - opus_val32 frame_avg = 0; - opus_val16 offset = shortBlocks ? HALF16(SHL16(LM, DB_SHIFT)) : 0; - for (i = start; i < end; i++) { - follow = MAX16(follow - QCONST16(1.f, DB_SHIFT), bandLogE[i] - offset); - if (C == 2) { - follow = MAX16(follow, bandLogE[i + nbEBands] - offset); - } - frame_avg += follow; - } - frame_avg /= (end - start); - temporal_vbr = SUB16(frame_avg, st->spec_avg); - temporal_vbr = MIN16(QCONST16(3.f, DB_SHIFT), MAX16(-QCONST16(1.5f, DB_SHIFT), temporal_vbr)); - st->spec_avg += MULT16_16_Q15(QCONST16(.02f, 15), temporal_vbr); - } - /* for (i=0;i<21;i++) - printf("%f ", bandLogE[i]); - printf("\n");*/ - - if (!secondMdct) { - OPUS_COPY(bandLogE2, bandLogE, C * nbEBands); - } - - /* Last chance to catch any transient we might have missed in the - time-domain analysis */ - if (LM > 0 && ec_tell(enc) + 3 <= total_bits && !isTransient && st->complexity >= 5 && !st->lfe && !hybrid) { - if (patch_transient_decision(bandLogE, oldBandE, nbEBands, start, end, C)) { - isTransient = 1; - shortBlocks = M; - compute_mdcts(mode, shortBlocks, in, freq, C, CC, LM, st->upsample, st->arch); - compute_band_energies(mode, freq, bandE, effEnd, C, LM, st->arch); - amp2Log2(mode, effEnd, end, bandE, bandLogE, C); - /* Compensate for the scaling of short vs long mdcts */ - for (i = 0; i < C * nbEBands; i++) { - bandLogE2[i] += HALF16(SHL16(LM, DB_SHIFT)); - } - tf_estimate = QCONST16(.2f, 14); - } - } - - if (LM > 0 && ec_tell(enc) + 3 <= total_bits) { - ec_enc_bit_logp(enc, isTransient, 3); - } - - ALLOC(X, C * N, celt_norm); /**< Interleaved normalised MDCTs */ - - /* Band normalisation */ - normalise_bands(mode, freq, X, bandE, effEnd, C, M); - - enable_tf_analysis = effectiveBytes >= 15 * C && !hybrid && st->complexity >= 2 && !st->lfe; - - ALLOC(offsets, nbEBands, int); - ALLOC(importance, nbEBands, int); - ALLOC(spread_weight, nbEBands, int); - - maxDepth = dynalloc_analysis(bandLogE, bandLogE2, nbEBands, start, end, C, offsets, - st->lsb_depth, mode->logN, isTransient, st->vbr, st->constrained_vbr, - eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc, &st->analysis, importance, spread_weight); - - ALLOC(tf_res, nbEBands, int); - /* Disable variable tf resolution for hybrid and at very low bitrate */ - if (enable_tf_analysis) { - int lambda; - lambda = IMAX(80, 20480 / effectiveBytes + 2); - tf_select = tf_analysis(mode, effEnd, isTransient, tf_res, lambda, X, N, LM, tf_estimate, tf_chan, importance); - for (i = effEnd; i < end; i++) { - tf_res[i] = tf_res[effEnd - 1]; - } - } else if (hybrid && weak_transient) { - /* For weak transients, we rely on the fact that improving time resolution using - TF on a long window is imperfect and will not result in an energy collapse at - low bitrate. */ - for (i = 0; i < end; i++) { - tf_res[i] = 1; - } - tf_select = 0; - } else if (hybrid && effectiveBytes < 15 && st->silk_info.signalType != 2) { - /* For low bitrate hybrid, we force temporal resolution to 5 ms rather than 2.5 ms. */ - for (i = 0; i < end; i++) { - tf_res[i] = 0; - } - tf_select = isTransient; - } else { - for (i = 0; i < end; i++) { - tf_res[i] = isTransient; - } - tf_select = 0; - } - - ALLOC(error, C * nbEBands, opus_val16); - c = 0; - do { - for (i = start; i < end; i++) { - /* When the energy is stable, slightly bias energy quantization towards - the previous error to make the gain more stable (a constant offset is - better than fluctuations). */ - if (ABS32(SUB32(bandLogE[i + c * nbEBands], oldBandE[i + c * nbEBands])) < QCONST16(2.f, DB_SHIFT)) { - bandLogE[i + c * nbEBands] -= MULT16_16_Q15(energyError[i + c * nbEBands], QCONST16(0.25f, 15)); - } - } - } while (++c < C); - quant_coarse_energy(mode, start, end, effEnd, bandLogE, - oldBandE, total_bits, error, enc, - C, LM, nbAvailableBytes, st->force_intra, - &st->delayedIntra, st->complexity >= 4, st->loss_rate, st->lfe); - - tf_encode(start, end, isTransient, tf_res, LM, tf_select, enc); - - if (ec_tell(enc) + 4 <= total_bits) { - if (st->lfe) { - st->tapset_decision = 0; - st->spread_decision = SPREAD_NORMAL; - } else if (hybrid) { - if (st->complexity == 0) { - st->spread_decision = SPREAD_NONE; - } else if (isTransient) { - st->spread_decision = SPREAD_NORMAL; - } else { - st->spread_decision = SPREAD_AGGRESSIVE; - } - } else if (shortBlocks || st->complexity < 3 || nbAvailableBytes < 10 * C) { - if (st->complexity == 0) { - st->spread_decision = SPREAD_NONE; - } else { - st->spread_decision = SPREAD_NORMAL; - } - } else { - /* Disable new spreading+tapset estimator until we can show it works - better than the old one. So far it seems like spreading_decision() - works best. */ -#if 0 - if (st->analysis.valid) { - static const opus_val16 spread_thresholds[3] = {-QCONST16(.6f, 15), -QCONST16(.2f, 15), -QCONST16(.07f, 15)}; - static const opus_val16 spread_histeresis[3] = {QCONST16(.15f, 15), QCONST16(.07f, 15), QCONST16(.02f, 15)}; - static const opus_val16 tapset_thresholds[2] = {QCONST16(.0f, 15), QCONST16(.15f, 15)}; - static const opus_val16 tapset_histeresis[2] = {QCONST16(.1f, 15), QCONST16(.05f, 15)}; - st->spread_decision = hysteresis_decision(-st->analysis.tonality, spread_thresholds, spread_histeresis, 3, st->spread_decision); - st->tapset_decision = hysteresis_decision(st->analysis.tonality_slope, tapset_thresholds, tapset_histeresis, 2, st->tapset_decision); - } else -#endif - { - st->spread_decision = spreading_decision(mode, X, - &st->tonal_average, st->spread_decision, &st->hf_average, - &st->tapset_decision, pf_on && !shortBlocks, effEnd, C, M, spread_weight); - } - /*printf("%d %d\n", st->tapset_decision, st->spread_decision);*/ - /*printf("%f %d %f %d\n\n", st->analysis.tonality, st->spread_decision, st->analysis.tonality_slope, st->tapset_decision);*/ - } - ec_enc_icdf(enc, st->spread_decision, spread_icdf, 5); - } - - /* For LFE, everything interesting is in the first band */ - if (st->lfe) { - offsets[0] = IMIN(8, effectiveBytes / 3); - } - ALLOC(cap, nbEBands, int); - init_caps(mode, cap, LM, C); - - dynalloc_logp = 6; - total_bits <<= BITRES; - total_boost = 0; - tell = ec_tell_frac(enc); - for (i = start; i < end; i++) { - int width, quanta; - int dynalloc_loop_logp; - int boost; - int j; - width = C * (eBands[i + 1] - eBands[i]) << LM; - /* quanta is 6 bits, but no more than 1 bit/sample - and no less than 1/8 bit/sample */ - quanta = IMIN(width << BITRES, IMAX(6 << BITRES, width)); - dynalloc_loop_logp = dynalloc_logp; - boost = 0; - for (j = 0; tell + (dynalloc_loop_logp << BITRES) < total_bits - total_boost - && boost < cap[i]; j++) { - int flag; - flag = j < offsets[i]; - ec_enc_bit_logp(enc, flag, dynalloc_loop_logp); - tell = ec_tell_frac(enc); - if (!flag) { - break; - } - boost += quanta; - total_boost += quanta; - dynalloc_loop_logp = 1; - } - /* Making dynalloc more likely */ - if (j) { - dynalloc_logp = IMAX(2, dynalloc_logp - 1); - } - offsets[i] = boost; - } - - if (C == 2) { - static const opus_val16 intensity_thresholds[21] = - /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 off*/ - { 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 36, 44, 50, 56, 62, 67, 72, 79, 88, 106, 134}; - static const opus_val16 intensity_histeresis[21] = - { 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 5, 6, 8, 8}; - - /* Always use MS for 2.5 ms frames until we can do a better analysis */ - if (LM != 0) { - dual_stereo = stereo_analysis(mode, X, LM, N); - } - - st->intensity = hysteresis_decision((opus_val16)(equiv_rate / 1000), - intensity_thresholds, intensity_histeresis, 21, st->intensity); - st->intensity = IMIN(end, IMAX(start, st->intensity)); - } - - alloc_trim = 5; - if (tell + (6 << BITRES) <= total_bits - total_boost) { - if (start > 0 || st->lfe) { - st->stereo_saving = 0; - alloc_trim = 5; - } else { - alloc_trim = alloc_trim_analysis(mode, X, bandLogE, - end, LM, C, N, &st->analysis, &st->stereo_saving, tf_estimate, - st->intensity, surround_trim, equiv_rate, st->arch); - } - ec_enc_icdf(enc, alloc_trim, trim_icdf, 7); - tell = ec_tell_frac(enc); - } - - /* Variable bitrate */ - if (vbr_rate > 0) { - opus_val16 alpha; - opus_int32 delta; - /* The target rate in 8th bits per frame */ - opus_int32 target, base_target; - opus_int32 min_allowed; - int lm_diff = mode->maxLM - LM; - - /* Don't attempt to use more than 510 kb/s, even for frames smaller than 20 ms. - The CELT allocator will just not be able to use more than that anyway. */ - nbCompressedBytes = IMIN(nbCompressedBytes, 1275 >> (3 - LM)); - if (!hybrid) { - base_target = vbr_rate - ((40 * C + 20) << BITRES); - } else { - base_target = IMAX(0, vbr_rate - ((9 * C + 4) << BITRES)); - } - - if (st->constrained_vbr) { - base_target += (st->vbr_offset >> lm_diff); - } - - if (!hybrid) { - target = compute_vbr(mode, &st->analysis, base_target, LM, equiv_rate, - st->lastCodedBands, C, st->intensity, st->constrained_vbr, - st->stereo_saving, tot_boost, tf_estimate, pitch_change, maxDepth, - st->lfe, st->energy_mask != NULL, surround_masking, - temporal_vbr); - } else { - target = base_target; - /* Tonal frames (offset<100) need more bits than noisy (offset>100) ones. */ - if (st->silk_info.offset < 100) { - target += 12 << BITRES >> (3 - LM); - } - if (st->silk_info.offset > 100) { - target -= 18 << BITRES >> (3 - LM); - } - /* Boosting bitrate on transients and vowels with significant temporal - spikes. */ - target += (opus_int32)MULT16_16_Q14(tf_estimate - QCONST16(.25f, 14), (50 << BITRES)); - /* If we have a strong transient, let's make sure it has enough bits to code - the first two bands, so that it can use folding rather than noise. */ - if (tf_estimate > QCONST16(.7f, 14)) { - target = IMAX(target, 50 << BITRES); - } - } - /* The current offset is removed from the target and the space used - so far is added*/ - target = target + tell; - /* In VBR mode the frame size must not be reduced so much that it would - result in the encoder running out of bits. - The margin of 2 bytes ensures that none of the bust-prevention logic - in the decoder will have triggered so far. */ - min_allowed = ((tell + total_boost + (1 << (BITRES + 3)) - 1) >> (BITRES + 3)) + 2; - /* Take into account the 37 bits we need to have left in the packet to - signal a redundant frame in hybrid mode. Creating a shorter packet would - create an entropy coder desync. */ - if (hybrid) { - min_allowed = IMAX(min_allowed, (tell0_frac + (37 << BITRES) + total_boost + (1 << (BITRES + 3)) - 1) >> (BITRES + 3)); - } - - nbAvailableBytes = (target + (1 << (BITRES + 2))) >> (BITRES + 3); - nbAvailableBytes = IMAX(min_allowed, nbAvailableBytes); - nbAvailableBytes = IMIN(nbCompressedBytes, nbAvailableBytes); - - /* By how much did we "miss" the target on that frame */ - delta = target - vbr_rate; - - target = nbAvailableBytes << (BITRES + 3); - - /* If the frame is silent we don't adjust our drift, otherwise - the encoder will shoot to very high rates after hitting a - span of silence, but we do allow the bitres to refill. - This means that we'll undershoot our target in CVBR/VBR modes - on files with lots of silence. */ - if (silence) { - nbAvailableBytes = 2; - target = 2 * 8 << BITRES; - delta = 0; - } - - if (st->vbr_count < 970) { - st->vbr_count++; - alpha = celt_rcp(SHL32(EXTEND32(st->vbr_count + 20), 16)); - } else { - alpha = QCONST16(.001f, 15); - } - /* How many bits have we used in excess of what we're allowed */ - if (st->constrained_vbr) { - st->vbr_reservoir += target - vbr_rate; - } - /*printf ("%d\n", st->vbr_reservoir);*/ - - /* Compute the offset we need to apply in order to reach the target */ - if (st->constrained_vbr) { - st->vbr_drift += (opus_int32)MULT16_32_Q15(alpha, (delta * (1 << lm_diff)) - st->vbr_offset - st->vbr_drift); - st->vbr_offset = -st->vbr_drift; - } - /*printf ("%d\n", st->vbr_drift);*/ - - if (st->constrained_vbr && st->vbr_reservoir < 0) { - /* We're under the min value -- increase rate */ - int adjust = (-st->vbr_reservoir) / (8 << BITRES); - /* Unless we're just coding silence */ - nbAvailableBytes += silence ? 0 : adjust; - st->vbr_reservoir = 0; - /*printf ("+%d\n", adjust);*/ - } - nbCompressedBytes = IMIN(nbCompressedBytes, nbAvailableBytes); - /*printf("%d\n", nbCompressedBytes*50*8);*/ - /* This moves the raw bits to take into account the new compressed size */ - ec_enc_shrink(enc, nbCompressedBytes); - } - - /* Bit allocation */ - ALLOC(fine_quant, nbEBands, int); - ALLOC(pulses, nbEBands, int); - ALLOC(fine_priority, nbEBands, int); - - /* bits = packet size - where we are - safety*/ - bits = (((opus_int32)nbCompressedBytes * 8) << BITRES) - ec_tell_frac(enc) - 1; - anti_collapse_rsv = isTransient && LM >= 2 && bits >= ((LM + 2) << BITRES) ? (1 << BITRES) : 0; - bits -= anti_collapse_rsv; - signalBandwidth = end - 1; -#ifndef DISABLE_FLOAT_API - if (st->analysis.valid) { - int min_bandwidth; - if (equiv_rate < (opus_int32)32000 * C) { - min_bandwidth = 13; - } else if (equiv_rate < (opus_int32)48000 * C) { - min_bandwidth = 16; - } else if (equiv_rate < (opus_int32)60000 * C) { - min_bandwidth = 18; - } else if (equiv_rate < (opus_int32)80000 * C) { - min_bandwidth = 19; - } else { - min_bandwidth = 20; - } - signalBandwidth = IMAX(st->analysis.bandwidth, min_bandwidth); - } -#endif - if (st->lfe) { - signalBandwidth = 1; - } - codedBands = clt_compute_allocation(mode, start, end, offsets, cap, - alloc_trim, &st->intensity, &dual_stereo, bits, &balance, pulses, - fine_quant, fine_priority, C, LM, enc, 1, st->lastCodedBands, signalBandwidth); - if (st->lastCodedBands) { - st->lastCodedBands = IMIN(st->lastCodedBands + 1, IMAX(st->lastCodedBands - 1, codedBands)); - } else { - st->lastCodedBands = codedBands; - } - - quant_fine_energy(mode, start, end, oldBandE, error, fine_quant, enc, C); - - /* Residual quantisation */ - ALLOC(collapse_masks, C * nbEBands, unsigned char); - quant_all_bands(1, mode, start, end, X, C == 2 ? X + N : NULL, collapse_masks, - bandE, pulses, shortBlocks, st->spread_decision, - dual_stereo, st->intensity, tf_res, nbCompressedBytes * (8 << BITRES) - anti_collapse_rsv, - balance, enc, LM, codedBands, &st->rng, st->complexity, st->arch, st->disable_inv); - - if (anti_collapse_rsv > 0) { - anti_collapse_on = st->consec_transient < 2; -#ifdef FUZZING - anti_collapse_on = rand() & 0x1; -#endif - ec_enc_bits(enc, anti_collapse_on, 1); - } - quant_energy_finalise(mode, start, end, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes * 8 - ec_tell(enc), enc, C); - OPUS_CLEAR(energyError, nbEBands * CC); - c = 0; - do { - for (i = start; i < end; i++) { - energyError[i + c * nbEBands] = MAX16(-QCONST16(0.5f, 15), MIN16(QCONST16(0.5f, 15), error[i + c * nbEBands])); - } - } while (++c < C); - - if (silence) { - for (i = 0; i < C * nbEBands; i++) { - oldBandE[i] = -QCONST16(28.f, DB_SHIFT); - } - } - -#ifdef RESYNTH - /* Re-synthesis of the coded audio if required */ - { - celt_sig *out_mem[2]; - - if (anti_collapse_on) { - anti_collapse(mode, X, collapse_masks, LM, C, N, - start, end, oldBandE, oldLogE, oldLogE2, pulses, st->rng); - } - - c = 0; do { - OPUS_MOVE(st->syn_mem[c], st->syn_mem[c] + N, 2 * MAX_PERIOD - N + overlap / 2); - } while (++c < CC); - - c = 0; do { - out_mem[c] = st->syn_mem[c] + 2 * MAX_PERIOD - N; - } while (++c < CC); - - celt_synthesis(mode, X, out_mem, oldBandE, start, effEnd, - C, CC, isTransient, LM, st->upsample, silence, st->arch); - - c = 0; do { - st->prefilter_period = IMAX(st->prefilter_period, COMBFILTER_MINPERIOD); - st->prefilter_period_old = IMAX(st->prefilter_period_old, COMBFILTER_MINPERIOD); - comb_filter(out_mem[c], out_mem[c], st->prefilter_period_old, st->prefilter_period, mode->shortMdctSize, - st->prefilter_gain_old, st->prefilter_gain, st->prefilter_tapset_old, st->prefilter_tapset, - mode->window, overlap); - if (LM != 0) - comb_filter(out_mem[c] + mode->shortMdctSize, out_mem[c] + mode->shortMdctSize, st->prefilter_period, pitch_index, N - mode->shortMdctSize, - st->prefilter_gain, gain1, st->prefilter_tapset, prefilter_tapset, - mode->window, overlap); - } while (++c < CC); - - /* We reuse freq[] as scratch space for the de-emphasis */ - deemphasis(out_mem, (opus_val16*)pcm, N, CC, st->upsample, mode->preemph, st->preemph_memD); - st->prefilter_period_old = st->prefilter_period; - st->prefilter_gain_old = st->prefilter_gain; - st->prefilter_tapset_old = st->prefilter_tapset; - } -#endif - - st->prefilter_period = pitch_index; - st->prefilter_gain = gain1; - st->prefilter_tapset = prefilter_tapset; -#ifdef RESYNTH - if (LM != 0) { - st->prefilter_period_old = st->prefilter_period; - st->prefilter_gain_old = st->prefilter_gain; - st->prefilter_tapset_old = st->prefilter_tapset; - } -#endif - - if (CC == 2 && C == 1) { - OPUS_COPY(&oldBandE[nbEBands], oldBandE, nbEBands); - } - - if (!isTransient) { - OPUS_COPY(oldLogE2, oldLogE, CC * nbEBands); - OPUS_COPY(oldLogE, oldBandE, CC * nbEBands); - } else { - for (i = 0; i < CC * nbEBands; i++) { - oldLogE[i] = MIN16(oldLogE[i], oldBandE[i]); - } - } - /* In case start or end were to change */ - c = 0; do { - for (i = 0; i < start; i++) { - oldBandE[c * nbEBands + i] = 0; - oldLogE[c * nbEBands + i] = oldLogE2[c * nbEBands + i] = -QCONST16(28.f, DB_SHIFT); - } - for (i = end; i < nbEBands; i++) { - oldBandE[c * nbEBands + i] = 0; - oldLogE[c * nbEBands + i] = oldLogE2[c * nbEBands + i] = -QCONST16(28.f, DB_SHIFT); - } - } while (++c < CC); - - if (isTransient || transient_got_disabled) { - st->consec_transient++; - } else { - st->consec_transient = 0; - } - st->rng = enc->rng; - - /* If there's any room left (can only happen for very high rates), - it's already filled with zeros */ - ec_enc_done(enc); - -#ifdef CUSTOM_MODES - if (st->signalling) { - nbCompressedBytes++; - } -#endif - - RESTORE_STACK; - if (ec_get_error(enc)) { - return OPUS_INTERNAL_ERROR; - } else { - return nbCompressedBytes; - } -} - - -#ifdef CUSTOM_MODES - -#ifdef FIXED_POINT -int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { - return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL); -} - -#ifndef DISABLE_FLOAT_API -int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { - int j, ret, C, N; - VARDECL(opus_int16, in); - ALLOC_STACK; - - if (pcm == NULL) { - return OPUS_BAD_ARG; - } - - C = st->channels; - N = frame_size; - ALLOC(in, C * N, opus_int16); - - for (j = 0; j < C * N; j++) { - in[j] = FLOAT2INT16(pcm[j]); - } - - ret = celt_encode_with_ec(st, in, frame_size, compressed, nbCompressedBytes, NULL); -#ifdef RESYNTH - for (j = 0; j < C * N; j++) { - ((float*)pcm)[j] = in[j] * (1.f / 32768.f); - } -#endif - RESTORE_STACK; - return ret; -} -#endif /* DISABLE_FLOAT_API */ -#else - -int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { - int j, ret, C, N; - VARDECL(celt_sig, in); - ALLOC_STACK; - - if (pcm == NULL) { - return OPUS_BAD_ARG; - } - - C = st->channels; - N = frame_size; - ALLOC(in, C * N, celt_sig); - for (j = 0; j < C * N; j++) { - in[j] = SCALEOUT(pcm[j]); - } - - ret = celt_encode_with_ec(st, in, frame_size, compressed, nbCompressedBytes, NULL); -#ifdef RESYNTH - for (j = 0; j < C * N; j++) { - ((opus_int16*)pcm)[j] = FLOAT2INT16(in[j]); - } -#endif - RESTORE_STACK; - return ret; -} - -int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { - return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL); -} - -#endif - -#endif /* CUSTOM_MODES */ - -int opus_custom_encoder_ctl(CELTEncoder * OPUS_RESTRICT st, int request, ...) { - va_list ap; - - va_start(ap, request); - switch (request) { - case OPUS_SET_COMPLEXITY_REQUEST: { - int value = va_arg(ap, opus_int32); - if (value < 0 || value > 10) { - goto bad_arg; - } - st->complexity = value; - } - break; - case CELT_SET_START_BAND_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value >= st->mode->nbEBands) { - goto bad_arg; - } - st->start = value; - } - break; - case CELT_SET_END_BAND_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 1 || value > st->mode->nbEBands) { - goto bad_arg; - } - st->end = value; - } - break; - case CELT_SET_PREDICTION_REQUEST: { - int value = va_arg(ap, opus_int32); - if (value < 0 || value > 2) { - goto bad_arg; - } - st->disable_pf = value <= 1; - st->force_intra = value == 0; - } - break; - case OPUS_SET_PACKET_LOSS_PERC_REQUEST: { - int value = va_arg(ap, opus_int32); - if (value < 0 || value > 100) { - goto bad_arg; - } - st->loss_rate = value; - } - break; - case OPUS_SET_VBR_CONSTRAINT_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->constrained_vbr = value; - } - break; - case OPUS_SET_VBR_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->vbr = value; - } - break; - case OPUS_SET_BITRATE_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value <= 500 && value != OPUS_BITRATE_MAX) { - goto bad_arg; - } - value = IMIN(value, 260000 * st->channels); - st->bitrate = value; - } - break; - case CELT_SET_CHANNELS_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 1 || value > 2) { - goto bad_arg; - } - st->stream_channels = value; - } - break; - case OPUS_SET_LSB_DEPTH_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 8 || value > 24) { - goto bad_arg; - } - st->lsb_depth = value; - } - break; - case OPUS_GET_LSB_DEPTH_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - *value = st->lsb_depth; - } - break; - case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - st->disable_inv = value; - } - break; - case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->disable_inv; - } - break; - case OPUS_RESET_STATE: { - int i; - opus_val16 *oldBandE, *oldLogE, *oldLogE2; - oldBandE = (opus_val16*)(st->in_mem + st->channels * (st->mode->overlap + COMBFILTER_MAXPERIOD)); - oldLogE = oldBandE + st->channels * st->mode->nbEBands; - oldLogE2 = oldLogE + st->channels * st->mode->nbEBands; - OPUS_CLEAR((char*)&st->ENCODER_RESET_START, - opus_custom_encoder_get_size(st->mode, st->channels) - - ((char*)&st->ENCODER_RESET_START - (char*)st)); - for (i = 0; i < st->channels * st->mode->nbEBands; i++) { - oldLogE[i] = oldLogE2[i] = -QCONST16(28.f, DB_SHIFT); - } - st->vbr_offset = 0; - st->delayedIntra = 1; - st->spread_decision = SPREAD_NORMAL; - st->tonal_average = 256; - st->hf_average = 0; - st->tapset_decision = 0; - } - break; -#ifdef CUSTOM_MODES - case CELT_SET_INPUT_CLIPPING_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->clip = value; - } - break; -#endif - case CELT_SET_SIGNALLING_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->signalling = value; - } - break; - case CELT_SET_ANALYSIS_REQUEST: { - AnalysisInfo *info = va_arg(ap, AnalysisInfo *); - if (info) { - OPUS_COPY(&st->analysis, info, 1); - } - } - break; - case CELT_SET_SILK_INFO_REQUEST: { - SILKInfo *info = va_arg(ap, SILKInfo *); - if (info) { - OPUS_COPY(&st->silk_info, info, 1); - } - } - break; - case CELT_GET_MODE_REQUEST: { - const CELTMode ** value = va_arg(ap, const CELTMode**); - if (value == 0) { - goto bad_arg; - } - *value = st->mode; - } - break; - case OPUS_GET_FINAL_RANGE_REQUEST: { - opus_uint32 * value = va_arg(ap, opus_uint32 *); - if (value == 0) { - goto bad_arg; - } - *value = st->rng; - } - break; - case OPUS_SET_LFE_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->lfe = value; - } - break; - case OPUS_SET_ENERGY_MASK_REQUEST: { - opus_val16 *value = va_arg(ap, opus_val16*); - st->energy_mask = value; - } - break; - default: - goto bad_request; - } - va_end(ap); - return OPUS_OK; -bad_arg: - va_end(ap); - return OPUS_BAD_ARG; -bad_request: - va_end(ap); - return OPUS_UNIMPLEMENTED; -} diff --git a/src/libopus/celt/celt_lpc.c b/src/libopus/celt/celt_lpc.c index ca0730b..7e02294 100644 --- a/src/libopus/celt/celt_lpc.c +++ b/src/libopus/celt/celt_lpc.c @@ -1,33 +1,33 @@ -/* Copyright (c) 2009-2010 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2009-2010 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "celt_lpc.h" #include "stack_alloc.h" @@ -35,263 +35,329 @@ #include "pitch.h" void _celt_lpc( - opus_val16 *_lpc, /* out: [0...p-1] LPC coefficients */ - const opus_val32 *ac, /* in: [0...p] autocorrelation values */ - int p -) { - int i, j; - opus_val32 r; - opus_val32 error = ac[0]; + opus_val16 *_lpc, /* out: [0...p-1] LPC coefficients */ +const opus_val32 *ac, /* in: [0...p] autocorrelation values */ +int p +) +{ + int i, j; + opus_val32 r; + opus_val32 error = ac[0]; #ifdef FIXED_POINT - opus_val32 lpc[LPC_ORDER]; + opus_val32 lpc[CELT_LPC_ORDER]; #else - float *lpc = _lpc; + float *lpc = _lpc; #endif - OPUS_CLEAR(lpc, p); - if (ac[0] != 0) { - for (i = 0; i < p; i++) { - /* Sum up this iteration's reflection coefficient */ - opus_val32 rr = 0; - for (j = 0; j < i; j++) { - rr += MULT32_32_Q31(lpc[j], ac[i - j]); - } - rr += SHR32(ac[i + 1], 3); - r = -frac_div32(SHL32(rr, 3), error); - /* Update LPC coefficients and total error */ - lpc[i] = SHR32(r, 3); - for (j = 0; j < (i + 1) >> 1; j++) { - opus_val32 tmp1, tmp2; - tmp1 = lpc[j]; - tmp2 = lpc[i - 1 - j]; - lpc[j] = tmp1 + MULT32_32_Q31(r, tmp2); - lpc[i - 1 - j] = tmp2 + MULT32_32_Q31(r, tmp1); - } - - error = error - MULT32_32_Q31(MULT32_32_Q31(r, r), error); - /* Bail out once we get 30 dB gain */ + OPUS_CLEAR(lpc, p); #ifdef FIXED_POINT - if (error < SHR32(ac[0], 10)) { - break; - } + if (ac[0] != 0) #else - if (error < .001f * ac[0]) { - break; - } + if (ac[0] > 1e-10f) #endif - } - } + { + for (i = 0; i < p; i++) { + /* Sum up this iteration's reflection coefficient */ + opus_val32 rr = 0; + for (j = 0; j < i; j++) + rr += MULT32_32_Q31(lpc[j],ac[i - j]); + rr += SHR32(ac[i + 1],6); + r = -frac_div32(SHL32(rr,6), error); + /* Update LPC coefficients and total error */ + lpc[i] = SHR32(r,6); + for (j = 0; j < (i+1)>>1; j++) + { + opus_val32 tmp1, tmp2; + tmp1 = lpc[j]; + tmp2 = lpc[i-1-j]; + lpc[j] = tmp1 + MULT32_32_Q31(r,tmp2); + lpc[i-1-j] = tmp2 + MULT32_32_Q31(r,tmp1); + } + + error = error - MULT32_32_Q31(MULT32_32_Q31(r,r),error); + /* Bail out once we get 30 dB gain */ #ifdef FIXED_POINT - for (i = 0; i < p; i++) { - _lpc[i] = ROUND16(lpc[i], 16); - } + if (error<=SHR32(ac[0],10)) + break; +#else + if (error<=.001f*ac[0]) + break; +#endif + } + } +#ifdef FIXED_POINT + { + /* Convert the int32 lpcs to int16 and ensure there are no wrap-arounds. + This reuses the logic in silk_LPC_fit() and silk_bwexpander_32(). Any bug + fixes should also be applied there. */ + int iter, idx = 0; + opus_val32 maxabs, absval, chirp_Q16, chirp_minus_one_Q16; + + for (iter = 0; iter < 10; iter++) { + maxabs = 0; + for (i = 0; i < p; i++) { + absval = ABS32(lpc[i]); + if (absval > maxabs) { + maxabs = absval; + idx = i; + } + } + maxabs = PSHR32(maxabs, 13); /* Q25->Q12 */ + + if (maxabs > 32767) { + maxabs = MIN32(maxabs, 163838); + chirp_Q16 = QCONST32(0.999, 16) - DIV32(SHL32(maxabs - 32767, 14), + SHR32(MULT32_32_32(maxabs, idx + 1), 2)); + chirp_minus_one_Q16 = chirp_Q16 - 65536; + + /* Apply bandwidth expansion. */ + for (i = 0; i < p - 1; i++) { + lpc[i] = MULT32_32_Q16(chirp_Q16, lpc[i]); + chirp_Q16 += PSHR32(MULT32_32_32(chirp_Q16, chirp_minus_one_Q16), 16); + } + lpc[p - 1] = MULT32_32_Q16(chirp_Q16, lpc[p - 1]); + } else { + break; + } + } + + if (iter == 10) { + /* If the coeffs still do not fit into the 16 bit range after 10 iterations, + fall back to the A(z)=1 filter. */ + OPUS_CLEAR(lpc, p); + _lpc[0] = 4096; /* Q12 */ + } else { + for (i = 0; i < p; i++) { + _lpc[i] = EXTRACT16(PSHR32(lpc[i], 13)); /* Q25->Q12 */ + } + } + } #endif } void celt_fir_c( - const opus_val16 *x, - const opus_val16 *num, - opus_val16 *y, - int N, - int ord, - int arch) { - int i, j; - VARDECL(opus_val16, rnum); - SAVE_STACK; - celt_assert(x != y); - ALLOC(rnum, ord, opus_val16); - for (i = 0; i < ord; i++) { - rnum[i] = num[ord - i - 1]; - } - for (i = 0; i < N - 3; i += 4) { - opus_val32 sum[4]; - sum[0] = SHL32(EXTEND32(x[i ]), SIG_SHIFT); - sum[1] = SHL32(EXTEND32(x[i + 1]), SIG_SHIFT); - sum[2] = SHL32(EXTEND32(x[i + 2]), SIG_SHIFT); - sum[3] = SHL32(EXTEND32(x[i + 3]), SIG_SHIFT); - xcorr_kernel(rnum, x + i - ord, sum, ord, arch); - y[i ] = ROUND16(sum[0], SIG_SHIFT); - y[i + 1] = ROUND16(sum[1], SIG_SHIFT); - y[i + 2] = ROUND16(sum[2], SIG_SHIFT); - y[i + 3] = ROUND16(sum[3], SIG_SHIFT); - } - for (; i < N; i++) { - opus_val32 sum = SHL32(EXTEND32(x[i]), SIG_SHIFT); - for (j = 0; j < ord; j++) { - sum = MAC16_16(sum, rnum[j], x[i + j - ord]); - } - y[i] = ROUND16(sum, SIG_SHIFT); - } - RESTORE_STACK; + const opus_val16 *x, + const opus_val16 *num, + opus_val16 *y, + int N, + int ord, + int arch) +{ + int i,j; + VARDECL(opus_val16, rnum); + SAVE_STACK; + celt_assert(x != y); + ALLOC(rnum, ord, opus_val16); + for(i=0;i= 1; j--) { - mem[j] = mem[j - 1]; - } - mem[0] = SROUND16(sum, SIG_SHIFT); - _y[i] = sum; - } + int i,j; + (void)arch; + for (i=0;i=1;j--) + { + mem[j]=mem[j-1]; + } + mem[0] = SROUND16(sum, SIG_SHIFT); + _y[i] = sum; + } #else - int i, j; - VARDECL(opus_val16, rden); - VARDECL(opus_val16, y); - SAVE_STACK; + int i,j; + VARDECL(opus_val16, rden); + VARDECL(opus_val16, y); + SAVE_STACK; - celt_assert((ord & 3) == 0); - ALLOC(rden, ord, opus_val16); - ALLOC(y, N + ord, opus_val16); - for (i = 0; i < ord; i++) { - rden[i] = den[ord - i - 1]; - } - for (i = 0; i < ord; i++) { - y[i] = -mem[ord - i - 1]; - } - for (; i < N + ord; i++) { - y[i] = 0; - } - for (i = 0; i < N - 3; i += 4) { - /* Unroll by 4 as if it were an FIR filter */ - opus_val32 sum[4]; - sum[0] = _x[i]; - sum[1] = _x[i + 1]; - sum[2] = _x[i + 2]; - sum[3] = _x[i + 3]; - xcorr_kernel(rden, y + i, sum, ord, arch); + celt_assert((ord&3)==0); + ALLOC(rden, ord, opus_val16); + ALLOC(y, N+ord, opus_val16); + for(i=0;i 0); - celt_assert(overlap >= 0); - if (overlap == 0) { - xptr = x; - } else { - for (i = 0; i < n; i++) { - xx[i] = x[i]; - } - for (i = 0; i < overlap; i++) { - xx[i] = MULT16_16_Q15(x[i], window[i]); - xx[n - i - 1] = MULT16_16_Q15(x[n - i - 1], window[i]); - } - xptr = xx; - } - shift = 0; + const opus_val16 *x, /* in: [0...n-1] samples x */ + opus_val32 *ac, /* out: [0...lag-1] ac values */ + const opus_val16 *window, + int overlap, + int lag, + int n, + int arch + ) +{ + opus_val32 d; + int i, k; + int fastN=n-lag; + int shift; + const opus_val16 *xptr; + VARDECL(opus_val16, xx); + SAVE_STACK; + ALLOC(xx, n, opus_val16); + celt_assert(n>0); + celt_assert(overlap>=0); + if (overlap == 0) + { + xptr = x; + } else { + for (i=0;i 0) { - for (i = 0; i < n; i++) { - xx[i] = PSHR32(xptr[i], shift); - } - xptr = xx; - } else { - shift = 0; - } - } + shift = celt_ilog2(ac0)-30+10; + shift = (shift)/2; + if (shift>0) + { + for(i=0;i= 536870912) { - int shift2 = 1; - if (ac[0] >= 1073741824) { - shift2++; - } - for (i = 0; i <= lag; i++) { - ac[i] = SHR32(ac[i], shift2); - } - shift += shift2; - } + shift = 2*shift; + if (shift<=0) + ac[0] += SHL32((opus_int32)1, -shift); + if (ac[0] < 268435456) + { + int shift2 = 29 - EC_ILOG(ac[0]); + for (i=0;i<=lag;i++) + ac[i] = SHL32(ac[i], shift2); + shift -= shift2; + } else if (ac[0] >= 536870912) + { + int shift2=1; + if (ac[0] >= 1073741824) + shift2++; + for (i=0;i<=lag;i++) + ac[i] = SHR32(ac[i], shift2); + shift += shift2; + } #endif - RESTORE_STACK; - return shift; + RESTORE_STACK; + return shift; } diff --git a/src/libopus/celt/celt_lpc.h b/src/libopus/celt/celt_lpc.h index 536a472..97dee82 100644 --- a/src/libopus/celt/celt_lpc.h +++ b/src/libopus/celt/celt_lpc.h @@ -1,28 +1,28 @@ -/* Copyright (c) 2009-2010 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2009-2010 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PLC_H @@ -35,17 +35,17 @@ #include "x86/celt_lpc_sse.h" #endif -#define LPC_ORDER 24 +#define CELT_LPC_ORDER 24 void _celt_lpc(opus_val16 *_lpc, const opus_val32 *ac, int p); void celt_fir_c( - const opus_val16 *x, - const opus_val16 *num, - opus_val16 *y, - int N, - int ord, - int arch); + const opus_val16 *x, + const opus_val16 *num, + opus_val16 *y, + int N, + int ord, + int arch); #if !defined(OVERRIDE_CELT_FIR) #define celt_fir(x, num, y, N, ord, arch) \ @@ -53,14 +53,14 @@ void celt_fir_c( #endif void celt_iir(const opus_val32 *x, - const opus_val16 *den, - opus_val32 *y, - int N, - int ord, - opus_val16 *mem, - int arch); + const opus_val16 *den, + opus_val32 *y, + int N, + int ord, + opus_val16 *mem, + int arch); int _celt_autocorr(const opus_val16 *x, opus_val32 *ac, - const opus_val16 *window, int overlap, int lag, int n, int arch); + const opus_val16 *window, int overlap, int lag, int n, int arch); #endif /* PLC_H */ diff --git a/src/libopus/celt/config.h b/src/libopus/celt/config.h new file mode 100644 index 0000000..2989b6b --- /dev/null +++ b/src/libopus/celt/config.h @@ -0,0 +1 @@ +#include "../include/config.h" diff --git a/src/libopus/celt/cpu_support.h b/src/libopus/celt/cpu_support.h index bf0ff9a..9f13d8a 100644 --- a/src/libopus/celt/cpu_support.h +++ b/src/libopus/celt/cpu_support.h @@ -1,69 +1,72 @@ -/* Copyright (c) 2010 Xiph.Org Foundation - Copyright (c) 2013 Parrot */ +/* Copyright (c) 2010 Xiph.Org Foundation + * Copyright (c) 2013 Parrot */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef CPU_SUPPORT_H #define CPU_SUPPORT_H -#include "../opus_types.h" -#include "../opus_defines.h" +#include "opus_types.h" +#include "opus_defines.h" #if defined(OPUS_HAVE_RTCD) && \ (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) #include "arm/armcpu.h" -/* We currently support 4 ARM variants: - arch[0] -> ARMv4 - arch[1] -> ARMv5E - arch[2] -> ARMv6 - arch[3] -> NEON -*/ -#define OPUS_ARCHMASK 3 +/* We currently support 5 ARM variants: + * arch[0] -> ARMv4 + * arch[1] -> ARMv5E + * arch[2] -> ARMv6 + * arch[3] -> NEON + * arch[4] -> NEON+DOTPROD + */ +#define OPUS_ARCHMASK 7 -#elif (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(OPUS_X86_PRESUME_SSE)) || \ +#elif defined(OPUS_HAVE_RTCD) && \ + ((defined(OPUS_X86_MAY_HAVE_SSE) && !defined(OPUS_X86_PRESUME_SSE)) || \ (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2)) || \ (defined(OPUS_X86_MAY_HAVE_SSE4_1) && !defined(OPUS_X86_PRESUME_SSE4_1)) || \ - (defined(OPUS_X86_MAY_HAVE_AVX) && !defined(OPUS_X86_PRESUME_AVX)) + (defined(OPUS_X86_MAY_HAVE_AVX2) && !defined(OPUS_X86_PRESUME_AVX2))) #include "x86/x86cpu.h" -/* We currently support 5 x86 variants: - arch[0] -> non-sse - arch[1] -> sse - arch[2] -> sse2 - arch[3] -> sse4.1 - arch[4] -> avx -*/ +/* We currently support 5 x86 variants: + * arch[0] -> non-sse + * arch[1] -> sse + * arch[2] -> sse2 + * arch[3] -> sse4.1 + * arch[4] -> avx + */ #define OPUS_ARCHMASK 7 int opus_select_arch(void); #else #define OPUS_ARCHMASK 0 -static OPUS_INLINE int opus_select_arch(void) { - return 0; +static OPUS_INLINE int opus_select_arch(void) +{ + return 0; } #endif #endif diff --git a/src/libopus/celt/cwrs.c b/src/libopus/celt/cwrs.c index 60824b7..58c9262 100644 --- a/src/libopus/celt/cwrs.c +++ b/src/libopus/celt/cwrs.c @@ -1,97 +1,93 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2007-2009 Timothy B. Terriberry - Written by Timothy B. Terriberry and Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2007-2009 Timothy B. Terriberry + Written by Timothy B. Terriberry and Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "os_support.h" #include "cwrs.h" #include "mathops.h" #include "arch.h" -#include #ifdef CUSTOM_MODES -/* Guaranteed to return a conservatively large estimate of the binary logarithm - with frac bits of fractional precision. - Tested for all possible 32-bit inputs with frac=4, where the maximum - overestimation is 0.06254243 bits.*/ -int log2_frac(opus_uint32 val, int frac) { - int l; - l = EC_ILOG(val); - if (val & (val - 1)) { - /* This is (val>>l-16), but guaranteed to round up, even if adding a bias - before the shift would cause overflow (e.g., for 0xFFFFxxxx). - Doesn't work for val=0, but that case fails the test above.*/ - if (l > 16) { - val = ((val - 1) >> (l - 16)) + 1; - } else { - val <<= 16 - l; - } - l = (l - 1) << frac; - /* Note that we always need one iteration, since the rounding up above means - that we might need to adjust the integer part of the logarithm.*/ - do { - int b; - b = (int)(val >> 16); - l += b << frac; - val = (val + b) >> b; - val = (val * val + 0x7FFF) >> 15; - } while (frac-- > 0); - /*If val is not exactly 0x8000, then we have to round up the remainder.*/ - return l + (val > 0x8000); - } - /*Exact powers of two require no rounding.*/ - else { - return (l - 1) << frac; +/*Guaranteed to return a conservatively large estimate of the binary logarithm + with frac bits of fractional precision. + Tested for all possible 32-bit inputs with frac=4, where the maximum + overestimation is 0.06254243 bits.*/ +int log2_frac(opus_uint32 val, int frac) +{ + int l; + l=EC_ILOG(val); + if(val&(val-1)){ + /*This is (val>>l-16), but guaranteed to round up, even if adding a bias + before the shift would cause overflow (e.g., for 0xFFFFxxxx). + Doesn't work for val=0, but that case fails the test above.*/ + if(l>16)val=((val-1)>>(l-16))+1; + else val<<=16-l; + l=(l-1)<>16); + l+=b<>b; + val=(val*val+0x7FFF)>>15; } + while(frac-->0); + /*If val is not exactly 0x8000, then we have to round up the remainder.*/ + return l+(val>0x8000); + } + /*Exact powers of two require no rounding.*/ + else return (l-1)<0 ? sum(k=1...K,2**k*choose(N,k)*choose(K-1,k-1)) : 1, - where choose() is the binomial function. - A table of values for N<10 and K<10 looks like: - V[10][10] = { + where choose() is the binomial function. + A table of values for N<10 and K<10 looks like: + V[10][10] = { {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 2, 2, 2, 2, 2, 2, 2, 2, 2}, {1, 4, 8, 12, 16, 20, 24, 28, 32, 36}, @@ -102,22 +98,22 @@ int log2_frac(opus_uint32 val, int frac) { {1, 14, 98, 462, 1666, 4942, 12642, 28814, 59906, 115598}, {1, 16, 128, 688, 2816, 9424, 27008, 68464, 157184, 332688}, {1, 18, 162, 978, 4482, 16722, 53154, 148626, 374274, 864146} - }; + }; - U(N,K) = the number of such combinations wherein N-1 objects are taken at - most K-1 at a time. - This is given by + U(N,K) = the number of such combinations wherein N-1 objects are taken at + most K-1 at a time. + This is given by U(N,K) = sum(k=0...K-1,V(N-1,k)) = K>0 ? (V(N-1,K-1) + V(N,K-1))/2 : 0. - The latter expression also makes clear that U(N,K) is half the number of such - combinations wherein the first object is taken at least once. - Although it may not be clear from either of these definitions, U(N,K) is the - natural function to work with when enumerating the pulse vector codebooks, - not V(N,K). - U(N,K) is not well-defined for N=0, but with the extension + The latter expression also makes clear that U(N,K) is half the number of such + combinations wherein the first object is taken at least once. + Although it may not be clear from either of these definitions, U(N,K) is the + natural function to work with when enumerating the pulse vector codebooks, + not V(N,K). + U(N,K) is not well-defined for N=0, but with the extension U(0,K) = K>0 ? 0 : 1, - the function becomes symmetric: U(N,K) = U(K,N), with a similar table: - U[10][10] = { + the function becomes symmetric: U(N,K) = U(K,N), with a similar table: + U[10][10] = { {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 3, 5, 7, 9, 11, 13, 15, 17}, @@ -128,62 +124,62 @@ int log2_frac(opus_uint32 val, int frac) { {0, 1, 13, 85, 377, 1289, 3653, 8989, 19825, 40081}, {0, 1, 15, 113, 575, 2241, 7183, 19825, 48639, 108545}, {0, 1, 17, 145, 833, 3649, 13073, 40081, 108545, 265729} - }; + }; - With this extension, V(N,K) may be written in terms of U(N,K): + With this extension, V(N,K) may be written in terms of U(N,K): V(N,K) = U(N,K) + U(N,K+1) - for all N>=0, K>=0. - Thus U(N,K+1) represents the number of combinations where the first element - is positive or zero, and U(N,K) represents the number of combinations where - it is negative. - With a large enough table of U(N,K) values, we could write O(N) encoding - and O(min(N*log(K),N+K)) decoding routines, but such a table would be - prohibitively large for small embedded devices (K may be as large as 32767 - for small N, and N may be as large as 200). + for all N>=0, K>=0. + Thus U(N,K+1) represents the number of combinations where the first element + is positive or zero, and U(N,K) represents the number of combinations where + it is negative. + With a large enough table of U(N,K) values, we could write O(N) encoding + and O(min(N*log(K),N+K)) decoding routines, but such a table would be + prohibitively large for small embedded devices (K may be as large as 32767 + for small N, and N may be as large as 200). - Both functions obey the same recurrence relation: + Both functions obey the same recurrence relation: V(N,K) = V(N-1,K) + V(N,K-1) + V(N-1,K-1), U(N,K) = U(N-1,K) + U(N,K-1) + U(N-1,K-1), - for all N>0, K>0, with different initial conditions at N=0 or K=0. - This allows us to construct a row of one of the tables above given the - previous row or the next row. - Thus we can derive O(NK) encoding and decoding routines with O(K) memory - using only addition and subtraction. + for all N>0, K>0, with different initial conditions at N=0 or K=0. + This allows us to construct a row of one of the tables above given the + previous row or the next row. + Thus we can derive O(NK) encoding and decoding routines with O(K) memory + using only addition and subtraction. - When encoding, we build up from the U(2,K) row and work our way forwards. - When decoding, we need to start at the U(N,K) row and work our way backwards, - which requires a means of computing U(N,K). - U(N,K) may be computed from two previous values with the same N: + When encoding, we build up from the U(2,K) row and work our way forwards. + When decoding, we need to start at the U(N,K) row and work our way backwards, + which requires a means of computing U(N,K). + U(N,K) may be computed from two previous values with the same N: U(N,K) = ((2*N-1)*U(N,K-1) - U(N,K-2))/(K-1) + U(N,K-2) - for all N>1, and since U(N,K) is symmetric, a similar relation holds for two - previous values with the same K: + for all N>1, and since U(N,K) is symmetric, a similar relation holds for two + previous values with the same K: U(N,K>1) = ((2*K-1)*U(N-1,K) - U(N-2,K))/(N-1) + U(N-2,K) - for all K>1. - This allows us to construct an arbitrary row of the U(N,K) table by starting - with the first two values, which are constants. - This saves roughly 2/3 the work in our O(NK) decoding routine, but costs O(K) - multiplications. - Similar relations can be derived for V(N,K), but are not used here. + for all K>1. + This allows us to construct an arbitrary row of the U(N,K) table by starting + with the first two values, which are constants. + This saves roughly 2/3 the work in our O(NK) decoding routine, but costs O(K) + multiplications. + Similar relations can be derived for V(N,K), but are not used here. - For N>0 and K>0, U(N,K) and V(N,K) take on the form of an (N-1)-degree - polynomial for fixed N. - The first few are + For N>0 and K>0, U(N,K) and V(N,K) take on the form of an (N-1)-degree + polynomial for fixed N. + The first few are U(1,K) = 1, U(2,K) = 2*K-1, U(3,K) = (2*K-2)*K+1, U(4,K) = (((4*K-6)*K+8)*K-3)/3, U(5,K) = ((((2*K-4)*K+10)*K-8)*K+3)/3, - and + and V(1,K) = 2, V(2,K) = 4*K, V(3,K) = 4*K*K+2, V(4,K) = 8*(K*K+2)*K/3, V(5,K) = ((4*K*K+20)*K*K+6)/3, - for all K>0. - This allows us to derive O(N) encoding and O(N*log(K)) decoding routines for - small N (and indeed decoding is also O(N) for N<3). + for all K>0. + This allows us to derive O(N) encoding and O(N*log(K)) decoding routines for + small N (and indeed decoding is also O(N) for N<3). - @ARTICLE{Fis86, + @ARTICLE{Fis86, author="Thomas R. Fischer", title="A Pyramid Vector Quantizer", journal="IEEE Transactions on Information Theory", @@ -192,545 +188,528 @@ int log2_frac(opus_uint32 val, int frac) { pages="568--583", month=Jul, year=1986 - }*/ + }*/ #if !defined(SMALL_FOOTPRINT) /*U(N,K) = U(K,N) := N>0?K>0?U(N-1,K)+U(N,K-1)+U(N-1,K-1):0:K>0?1:0*/ # define CELT_PVQ_U(_n,_k) (CELT_PVQ_U_ROW[IMIN(_n,_k)][IMAX(_n,_k)]) -/* V(N,K) := U(N,K)+U(N,K+1) = the number of PVQ codewords for a band of size N - with K pulses allocated to it.*/ +/*V(N,K) := U(N,K)+U(N,K+1) = the number of PVQ codewords for a band of size N + with K pulses allocated to it.*/ # define CELT_PVQ_V(_n,_k) (CELT_PVQ_U(_n,_k)+CELT_PVQ_U(_n,(_k)+1)) -/* For each V(N,K) supported, we will access element U(min(N,K+1),max(N,K+1)). - Thus, the number of entries in row I is the larger of the maximum number of - pulses we will ever allocate for a given N=I (K=128, or however many fit in - 32 bits, whichever is smaller), plus one, and the maximum N for which - K=I-1 pulses fit in 32 bits. - The largest band size in an Opus Custom mode is 208. - Otherwise, we can limit things to the set of N which can be achieved by - splitting a band from a standard Opus mode: 176, 144, 96, 88, 72, 64, 48, - 44, 36, 32, 24, 22, 18, 16, 8, 4, 2).*/ +/*For each V(N,K) supported, we will access element U(min(N,K+1),max(N,K+1)). + Thus, the number of entries in row I is the larger of the maximum number of + pulses we will ever allocate for a given N=I (K=128, or however many fit in + 32 bits, whichever is smaller), plus one, and the maximum N for which + K=I-1 pulses fit in 32 bits. + The largest band size in an Opus Custom mode is 208. + Otherwise, we can limit things to the set of N which can be achieved by + splitting a band from a standard Opus mode: 176, 144, 96, 88, 72, 64, 48, + 44, 36, 32, 24, 22, 18, 16, 8, 4, 2).*/ #if defined(CUSTOM_MODES) -static const opus_uint32 CELT_PVQ_U_DATA[1488] PROGMEM = { +static const opus_uint32 CELT_PVQ_U_DATA[1488]={ #else -static const opus_uint32 CELT_PVQ_U_DATA[1272] PROGMEM = { +static const opus_uint32 CELT_PVQ_U_DATA[1272]={ #endif - /*N=0, K=0...176:*/ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /*N=0, K=0...176:*/ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #if defined(CUSTOM_MODES) - /*...208:*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, + /*...208:*/ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, #endif - /*N=1, K=1...176:*/ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + /*N=1, K=1...176:*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, #if defined(CUSTOM_MODES) - /*...208:*/ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, + /*...208:*/ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, #endif - /*N=2, K=2...176:*/ - 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, - 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, - 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, - 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, - 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, - 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, - 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, - 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, - 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 285, 287, 289, 291, 293, - 295, 297, 299, 301, 303, 305, 307, 309, 311, 313, 315, 317, 319, 321, 323, - 325, 327, 329, 331, 333, 335, 337, 339, 341, 343, 345, 347, 349, 351, + /*N=2, K=2...176:*/ + 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, + 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, + 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, + 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, + 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, + 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, + 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, + 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, + 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 285, 287, 289, 291, 293, + 295, 297, 299, 301, 303, 305, 307, 309, 311, 313, 315, 317, 319, 321, 323, + 325, 327, 329, 331, 333, 335, 337, 339, 341, 343, 345, 347, 349, 351, #if defined(CUSTOM_MODES) - /*...208:*/ - 353, 355, 357, 359, 361, 363, 365, 367, 369, 371, 373, 375, 377, 379, 381, - 383, 385, 387, 389, 391, 393, 395, 397, 399, 401, 403, 405, 407, 409, 411, - 413, 415, + /*...208:*/ + 353, 355, 357, 359, 361, 363, 365, 367, 369, 371, 373, 375, 377, 379, 381, + 383, 385, 387, 389, 391, 393, 395, 397, 399, 401, 403, 405, 407, 409, 411, + 413, 415, #endif - /*N=3, K=3...176:*/ - 13, 25, 41, 61, 85, 113, 145, 181, 221, 265, 313, 365, 421, 481, 545, 613, - 685, 761, 841, 925, 1013, 1105, 1201, 1301, 1405, 1513, 1625, 1741, 1861, - 1985, 2113, 2245, 2381, 2521, 2665, 2813, 2965, 3121, 3281, 3445, 3613, 3785, - 3961, 4141, 4325, 4513, 4705, 4901, 5101, 5305, 5513, 5725, 5941, 6161, 6385, - 6613, 6845, 7081, 7321, 7565, 7813, 8065, 8321, 8581, 8845, 9113, 9385, 9661, - 9941, 10225, 10513, 10805, 11101, 11401, 11705, 12013, 12325, 12641, 12961, - 13285, 13613, 13945, 14281, 14621, 14965, 15313, 15665, 16021, 16381, 16745, - 17113, 17485, 17861, 18241, 18625, 19013, 19405, 19801, 20201, 20605, 21013, - 21425, 21841, 22261, 22685, 23113, 23545, 23981, 24421, 24865, 25313, 25765, - 26221, 26681, 27145, 27613, 28085, 28561, 29041, 29525, 30013, 30505, 31001, - 31501, 32005, 32513, 33025, 33541, 34061, 34585, 35113, 35645, 36181, 36721, - 37265, 37813, 38365, 38921, 39481, 40045, 40613, 41185, 41761, 42341, 42925, - 43513, 44105, 44701, 45301, 45905, 46513, 47125, 47741, 48361, 48985, 49613, - 50245, 50881, 51521, 52165, 52813, 53465, 54121, 54781, 55445, 56113, 56785, - 57461, 58141, 58825, 59513, 60205, 60901, 61601, + /*N=3, K=3...176:*/ + 13, 25, 41, 61, 85, 113, 145, 181, 221, 265, 313, 365, 421, 481, 545, 613, + 685, 761, 841, 925, 1013, 1105, 1201, 1301, 1405, 1513, 1625, 1741, 1861, + 1985, 2113, 2245, 2381, 2521, 2665, 2813, 2965, 3121, 3281, 3445, 3613, 3785, + 3961, 4141, 4325, 4513, 4705, 4901, 5101, 5305, 5513, 5725, 5941, 6161, 6385, + 6613, 6845, 7081, 7321, 7565, 7813, 8065, 8321, 8581, 8845, 9113, 9385, 9661, + 9941, 10225, 10513, 10805, 11101, 11401, 11705, 12013, 12325, 12641, 12961, + 13285, 13613, 13945, 14281, 14621, 14965, 15313, 15665, 16021, 16381, 16745, + 17113, 17485, 17861, 18241, 18625, 19013, 19405, 19801, 20201, 20605, 21013, + 21425, 21841, 22261, 22685, 23113, 23545, 23981, 24421, 24865, 25313, 25765, + 26221, 26681, 27145, 27613, 28085, 28561, 29041, 29525, 30013, 30505, 31001, + 31501, 32005, 32513, 33025, 33541, 34061, 34585, 35113, 35645, 36181, 36721, + 37265, 37813, 38365, 38921, 39481, 40045, 40613, 41185, 41761, 42341, 42925, + 43513, 44105, 44701, 45301, 45905, 46513, 47125, 47741, 48361, 48985, 49613, + 50245, 50881, 51521, 52165, 52813, 53465, 54121, 54781, 55445, 56113, 56785, + 57461, 58141, 58825, 59513, 60205, 60901, 61601, #if defined(CUSTOM_MODES) - /*...208:*/ - 62305, 63013, 63725, 64441, 65161, 65885, 66613, 67345, 68081, 68821, 69565, - 70313, 71065, 71821, 72581, 73345, 74113, 74885, 75661, 76441, 77225, 78013, - 78805, 79601, 80401, 81205, 82013, 82825, 83641, 84461, 85285, 86113, + /*...208:*/ + 62305, 63013, 63725, 64441, 65161, 65885, 66613, 67345, 68081, 68821, 69565, + 70313, 71065, 71821, 72581, 73345, 74113, 74885, 75661, 76441, 77225, 78013, + 78805, 79601, 80401, 81205, 82013, 82825, 83641, 84461, 85285, 86113, #endif - /*N=4, K=4...176:*/ - 63, 129, 231, 377, 575, 833, 1159, 1561, 2047, 2625, 3303, 4089, 4991, 6017, - 7175, 8473, 9919, 11521, 13287, 15225, 17343, 19649, 22151, 24857, 27775, - 30913, 34279, 37881, 41727, 45825, 50183, 54809, 59711, 64897, 70375, 76153, - 82239, 88641, 95367, 102425, 109823, 117569, 125671, 134137, 142975, 152193, - 161799, 171801, 182207, 193025, 204263, 215929, 228031, 240577, 253575, - 267033, 280959, 295361, 310247, 325625, 341503, 357889, 374791, 392217, - 410175, 428673, 447719, 467321, 487487, 508225, 529543, 551449, 573951, - 597057, 620775, 645113, 670079, 695681, 721927, 748825, 776383, 804609, - 833511, 863097, 893375, 924353, 956039, 988441, 1021567, 1055425, 1090023, - 1125369, 1161471, 1198337, 1235975, 1274393, 1313599, 1353601, 1394407, - 1436025, 1478463, 1521729, 1565831, 1610777, 1656575, 1703233, 1750759, - 1799161, 1848447, 1898625, 1949703, 2001689, 2054591, 2108417, 2163175, - 2218873, 2275519, 2333121, 2391687, 2451225, 2511743, 2573249, 2635751, - 2699257, 2763775, 2829313, 2895879, 2963481, 3032127, 3101825, 3172583, - 3244409, 3317311, 3391297, 3466375, 3542553, 3619839, 3698241, 3777767, - 3858425, 3940223, 4023169, 4107271, 4192537, 4278975, 4366593, 4455399, - 4545401, 4636607, 4729025, 4822663, 4917529, 5013631, 5110977, 5209575, - 5309433, 5410559, 5512961, 5616647, 5721625, 5827903, 5935489, 6044391, - 6154617, 6266175, 6379073, 6493319, 6608921, 6725887, 6844225, 6963943, - 7085049, 7207551, + /*N=4, K=4...176:*/ + 63, 129, 231, 377, 575, 833, 1159, 1561, 2047, 2625, 3303, 4089, 4991, 6017, + 7175, 8473, 9919, 11521, 13287, 15225, 17343, 19649, 22151, 24857, 27775, + 30913, 34279, 37881, 41727, 45825, 50183, 54809, 59711, 64897, 70375, 76153, + 82239, 88641, 95367, 102425, 109823, 117569, 125671, 134137, 142975, 152193, + 161799, 171801, 182207, 193025, 204263, 215929, 228031, 240577, 253575, + 267033, 280959, 295361, 310247, 325625, 341503, 357889, 374791, 392217, + 410175, 428673, 447719, 467321, 487487, 508225, 529543, 551449, 573951, + 597057, 620775, 645113, 670079, 695681, 721927, 748825, 776383, 804609, + 833511, 863097, 893375, 924353, 956039, 988441, 1021567, 1055425, 1090023, + 1125369, 1161471, 1198337, 1235975, 1274393, 1313599, 1353601, 1394407, + 1436025, 1478463, 1521729, 1565831, 1610777, 1656575, 1703233, 1750759, + 1799161, 1848447, 1898625, 1949703, 2001689, 2054591, 2108417, 2163175, + 2218873, 2275519, 2333121, 2391687, 2451225, 2511743, 2573249, 2635751, + 2699257, 2763775, 2829313, 2895879, 2963481, 3032127, 3101825, 3172583, + 3244409, 3317311, 3391297, 3466375, 3542553, 3619839, 3698241, 3777767, + 3858425, 3940223, 4023169, 4107271, 4192537, 4278975, 4366593, 4455399, + 4545401, 4636607, 4729025, 4822663, 4917529, 5013631, 5110977, 5209575, + 5309433, 5410559, 5512961, 5616647, 5721625, 5827903, 5935489, 6044391, + 6154617, 6266175, 6379073, 6493319, 6608921, 6725887, 6844225, 6963943, + 7085049, 7207551, #if defined(CUSTOM_MODES) - /*...208:*/ - 7331457, 7456775, 7583513, 7711679, 7841281, 7972327, 8104825, 8238783, - 8374209, 8511111, 8649497, 8789375, 8930753, 9073639, 9218041, 9363967, - 9511425, 9660423, 9810969, 9963071, 10116737, 10271975, 10428793, 10587199, - 10747201, 10908807, 11072025, 11236863, 11403329, 11571431, 11741177, - 11912575, + /*...208:*/ + 7331457, 7456775, 7583513, 7711679, 7841281, 7972327, 8104825, 8238783, + 8374209, 8511111, 8649497, 8789375, 8930753, 9073639, 9218041, 9363967, + 9511425, 9660423, 9810969, 9963071, 10116737, 10271975, 10428793, 10587199, + 10747201, 10908807, 11072025, 11236863, 11403329, 11571431, 11741177, + 11912575, #endif - /*N=5, K=5...176:*/ - 321, 681, 1289, 2241, 3649, 5641, 8361, 11969, 16641, 22569, 29961, 39041, - 50049, 63241, 78889, 97281, 118721, 143529, 172041, 204609, 241601, 283401, - 330409, 383041, 441729, 506921, 579081, 658689, 746241, 842249, 947241, - 1061761, 1186369, 1321641, 1468169, 1626561, 1797441, 1981449, 2179241, - 2391489, 2618881, 2862121, 3121929, 3399041, 3694209, 4008201, 4341801, - 4695809, 5071041, 5468329, 5888521, 6332481, 6801089, 7295241, 7815849, - 8363841, 8940161, 9545769, 10181641, 10848769, 11548161, 12280841, 13047849, - 13850241, 14689089, 15565481, 16480521, 17435329, 18431041, 19468809, - 20549801, 21675201, 22846209, 24064041, 25329929, 26645121, 28010881, - 29428489, 30899241, 32424449, 34005441, 35643561, 37340169, 39096641, - 40914369, 42794761, 44739241, 46749249, 48826241, 50971689, 53187081, - 55473921, 57833729, 60268041, 62778409, 65366401, 68033601, 70781609, - 73612041, 76526529, 79526721, 82614281, 85790889, 89058241, 92418049, - 95872041, 99421961, 103069569, 106816641, 110664969, 114616361, 118672641, - 122835649, 127107241, 131489289, 135983681, 140592321, 145317129, 150160041, - 155123009, 160208001, 165417001, 170752009, 176215041, 181808129, 187533321, - 193392681, 199388289, 205522241, 211796649, 218213641, 224775361, 231483969, - 238341641, 245350569, 252512961, 259831041, 267307049, 274943241, 282741889, - 290705281, 298835721, 307135529, 315607041, 324252609, 333074601, 342075401, - 351257409, 360623041, 370174729, 379914921, 389846081, 399970689, 410291241, - 420810249, 431530241, 442453761, 453583369, 464921641, 476471169, 488234561, - 500214441, 512413449, 524834241, 537479489, 550351881, 563454121, 576788929, - 590359041, 604167209, 618216201, 632508801, + /*N=5, K=5...176:*/ + 321, 681, 1289, 2241, 3649, 5641, 8361, 11969, 16641, 22569, 29961, 39041, + 50049, 63241, 78889, 97281, 118721, 143529, 172041, 204609, 241601, 283401, + 330409, 383041, 441729, 506921, 579081, 658689, 746241, 842249, 947241, + 1061761, 1186369, 1321641, 1468169, 1626561, 1797441, 1981449, 2179241, + 2391489, 2618881, 2862121, 3121929, 3399041, 3694209, 4008201, 4341801, + 4695809, 5071041, 5468329, 5888521, 6332481, 6801089, 7295241, 7815849, + 8363841, 8940161, 9545769, 10181641, 10848769, 11548161, 12280841, 13047849, + 13850241, 14689089, 15565481, 16480521, 17435329, 18431041, 19468809, + 20549801, 21675201, 22846209, 24064041, 25329929, 26645121, 28010881, + 29428489, 30899241, 32424449, 34005441, 35643561, 37340169, 39096641, + 40914369, 42794761, 44739241, 46749249, 48826241, 50971689, 53187081, + 55473921, 57833729, 60268041, 62778409, 65366401, 68033601, 70781609, + 73612041, 76526529, 79526721, 82614281, 85790889, 89058241, 92418049, + 95872041, 99421961, 103069569, 106816641, 110664969, 114616361, 118672641, + 122835649, 127107241, 131489289, 135983681, 140592321, 145317129, 150160041, + 155123009, 160208001, 165417001, 170752009, 176215041, 181808129, 187533321, + 193392681, 199388289, 205522241, 211796649, 218213641, 224775361, 231483969, + 238341641, 245350569, 252512961, 259831041, 267307049, 274943241, 282741889, + 290705281, 298835721, 307135529, 315607041, 324252609, 333074601, 342075401, + 351257409, 360623041, 370174729, 379914921, 389846081, 399970689, 410291241, + 420810249, 431530241, 442453761, 453583369, 464921641, 476471169, 488234561, + 500214441, 512413449, 524834241, 537479489, 550351881, 563454121, 576788929, + 590359041, 604167209, 618216201, 632508801, #if defined(CUSTOM_MODES) - /*...208:*/ - 647047809, 661836041, 676876329, 692171521, 707724481, 723538089, 739615241, - 755958849, 772571841, 789457161, 806617769, 824056641, 841776769, 859781161, - 878072841, 896654849, 915530241, 934702089, 954173481, 973947521, 994027329, - 1014416041, 1035116809, 1056132801, 1077467201, 1099123209, 1121104041, - 1143412929, 1166053121, 1189027881, 1212340489, 1235994241, + /*...208:*/ + 647047809, 661836041, 676876329, 692171521, 707724481, 723538089, 739615241, + 755958849, 772571841, 789457161, 806617769, 824056641, 841776769, 859781161, + 878072841, 896654849, 915530241, 934702089, 954173481, 973947521, 994027329, + 1014416041, 1035116809, 1056132801, 1077467201, 1099123209, 1121104041, + 1143412929, 1166053121, 1189027881, 1212340489, 1235994241, #endif - /*N=6, K=6...96:*/ - 1683, 3653, 7183, 13073, 22363, 36365, 56695, 85305, 124515, 177045, 246047, - 335137, 448427, 590557, 766727, 982729, 1244979, 1560549, 1937199, 2383409, - 2908411, 3522221, 4235671, 5060441, 6009091, 7095093, 8332863, 9737793, - 11326283, 13115773, 15124775, 17372905, 19880915, 22670725, 25765455, - 29189457, 32968347, 37129037, 41699767, 46710137, 52191139, 58175189, - 64696159, 71789409, 79491819, 87841821, 96879431, 106646281, 117185651, - 128542501, 140763503, 153897073, 167993403, 183104493, 199284183, 216588185, - 235074115, 254801525, 275831935, 298228865, 322057867, 347386557, 374284647, - 402823977, 433078547, 465124549, 499040399, 534906769, 572806619, 612825229, - 655050231, 699571641, 746481891, 795875861, 847850911, 902506913, 959946283, - 1020274013, 1083597703, 1150027593, 1219676595, 1292660325, 1369097135, - 1449108145, 1532817275, 1620351277, 1711839767, 1807415257, 1907213187, - 2011371957, 2120032959, + /*N=6, K=6...96:*/ + 1683, 3653, 7183, 13073, 22363, 36365, 56695, 85305, 124515, 177045, 246047, + 335137, 448427, 590557, 766727, 982729, 1244979, 1560549, 1937199, 2383409, + 2908411, 3522221, 4235671, 5060441, 6009091, 7095093, 8332863, 9737793, + 11326283, 13115773, 15124775, 17372905, 19880915, 22670725, 25765455, + 29189457, 32968347, 37129037, 41699767, 46710137, 52191139, 58175189, + 64696159, 71789409, 79491819, 87841821, 96879431, 106646281, 117185651, + 128542501, 140763503, 153897073, 167993403, 183104493, 199284183, 216588185, + 235074115, 254801525, 275831935, 298228865, 322057867, 347386557, 374284647, + 402823977, 433078547, 465124549, 499040399, 534906769, 572806619, 612825229, + 655050231, 699571641, 746481891, 795875861, 847850911, 902506913, 959946283, + 1020274013, 1083597703, 1150027593, 1219676595, 1292660325, 1369097135, + 1449108145, 1532817275, 1620351277, 1711839767, 1807415257, 1907213187, + 2011371957, 2120032959, #if defined(CUSTOM_MODES) - /*...109:*/ - 2233340609U, 2351442379U, 2474488829U, 2602633639U, 2736033641U, 2874848851U, - 3019242501U, 3169381071U, 3325434321U, 3487575323U, 3655980493U, 3830829623U, - 4012305913U, + /*...109:*/ + 2233340609U, 2351442379U, 2474488829U, 2602633639U, 2736033641U, 2874848851U, + 3019242501U, 3169381071U, 3325434321U, 3487575323U, 3655980493U, 3830829623U, + 4012305913U, #endif - /*N=7, K=7...54*/ - 8989, 19825, 40081, 75517, 134245, 227305, 369305, 579125, 880685, 1303777, - 1884961, 2668525, 3707509, 5064793, 6814249, 9041957, 11847485, 15345233, - 19665841, 24957661, 31388293, 39146185, 48442297, 59511829, 72616013, - 88043969, 106114625, 127178701, 151620757, 179861305, 212358985, 249612805, - 292164445, 340600625, 395555537, 457713341, 527810725, 606639529, 695049433, - 793950709, 904317037, 1027188385, 1163673953, 1314955181, 1482288821, - 1667010073, 1870535785, 2094367717, + /*N=7, K=7...54*/ + 8989, 19825, 40081, 75517, 134245, 227305, 369305, 579125, 880685, 1303777, + 1884961, 2668525, 3707509, 5064793, 6814249, 9041957, 11847485, 15345233, + 19665841, 24957661, 31388293, 39146185, 48442297, 59511829, 72616013, + 88043969, 106114625, 127178701, 151620757, 179861305, 212358985, 249612805, + 292164445, 340600625, 395555537, 457713341, 527810725, 606639529, 695049433, + 793950709, 904317037, 1027188385, 1163673953, 1314955181, 1482288821, + 1667010073, 1870535785, 2094367717, #if defined(CUSTOM_MODES) - /*...60:*/ - 2340095869U, 2609401873U, 2904062449U, 3225952925U, 3577050821U, 3959439497U, + /*...60:*/ + 2340095869U, 2609401873U, 2904062449U, 3225952925U, 3577050821U, 3959439497U, #endif - /*N=8, K=8...37*/ - 48639, 108545, 224143, 433905, 795455, 1392065, 2340495, 3800305, 5984767, - 9173505, 13726991, 20103025, 28875327, 40754369, 56610575, 77500017, - 104692735, 139703809, 184327311, 240673265, 311207743, 398796225, 506750351, - 638878193, 799538175, 993696769, 1226990095, 1505789553, 1837271615, - 2229491905U, + /*N=8, K=8...37*/ + 48639, 108545, 224143, 433905, 795455, 1392065, 2340495, 3800305, 5984767, + 9173505, 13726991, 20103025, 28875327, 40754369, 56610575, 77500017, + 104692735, 139703809, 184327311, 240673265, 311207743, 398796225, 506750351, + 638878193, 799538175, 993696769, 1226990095, 1505789553, 1837271615, + 2229491905U, #if defined(CUSTOM_MODES) - /*...40:*/ - 2691463695U, 3233240945U, 3866006015U, + /*...40:*/ + 2691463695U, 3233240945U, 3866006015U, #endif - /*N=9, K=9...28:*/ - 265729, 598417, 1256465, 2485825, 4673345, 8405905, 14546705, 24331777, - 39490049, 62390545, 96220561, 145198913, 214828609, 312193553, 446304145, - 628496897, 872893441, 1196924561, 1621925137, 2173806145U, + /*N=9, K=9...28:*/ + 265729, 598417, 1256465, 2485825, 4673345, 8405905, 14546705, 24331777, + 39490049, 62390545, 96220561, 145198913, 214828609, 312193553, 446304145, + 628496897, 872893441, 1196924561, 1621925137, 2173806145U, #if defined(CUSTOM_MODES) - /*...29:*/ - 2883810113U, + /*...29:*/ + 2883810113U, #endif - /*N=10, K=10...24:*/ - 1462563, 3317445, 7059735, 14218905, 27298155, 50250765, 89129247, 152951073, - 254831667, 413442773, 654862247, 1014889769, 1541911931, 2300409629U, - 3375210671U, - /*N=11, K=11...19:*/ - 8097453, 18474633, 39753273, 81270333, 158819253, 298199265, 540279585, - 948062325, 1616336765, + /*N=10, K=10...24:*/ + 1462563, 3317445, 7059735, 14218905, 27298155, 50250765, 89129247, 152951073, + 254831667, 413442773, 654862247, 1014889769, 1541911931, 2300409629U, + 3375210671U, + /*N=11, K=11...19:*/ + 8097453, 18474633, 39753273, 81270333, 158819253, 298199265, 540279585, + 948062325, 1616336765, #if defined(CUSTOM_MODES) - /*...20:*/ - 2684641785U, + /*...20:*/ + 2684641785U, #endif - /*N=12, K=12...18:*/ - 45046719, 103274625, 224298231, 464387817, 921406335, 1759885185, - 3248227095U, - /*N=13, K=13...16:*/ - 251595969, 579168825, 1267854873, 2653649025U, - /*N=14, K=14:*/ - 1409933619 + /*N=12, K=12...18:*/ + 45046719, 103274625, 224298231, 464387817, 921406335, 1759885185, + 3248227095U, + /*N=13, K=13...16:*/ + 251595969, 579168825, 1267854873, 2653649025U, + /*N=14, K=14:*/ + 1409933619 }; #if defined(CUSTOM_MODES) -static const opus_uint32 *const CELT_PVQ_U_ROW[15] PROGMEM = { - CELT_PVQ_U_DATA + 0, CELT_PVQ_U_DATA + 208, CELT_PVQ_U_DATA + 415, - CELT_PVQ_U_DATA + 621, CELT_PVQ_U_DATA + 826, CELT_PVQ_U_DATA + 1030, - CELT_PVQ_U_DATA + 1233, CELT_PVQ_U_DATA + 1336, CELT_PVQ_U_DATA + 1389, - CELT_PVQ_U_DATA + 1421, CELT_PVQ_U_DATA + 1441, CELT_PVQ_U_DATA + 1455, - CELT_PVQ_U_DATA + 1464, CELT_PVQ_U_DATA + 1470, CELT_PVQ_U_DATA + 1473 +static const opus_uint32 *const CELT_PVQ_U_ROW[15]={ + CELT_PVQ_U_DATA+ 0,CELT_PVQ_U_DATA+ 208,CELT_PVQ_U_DATA+ 415, + CELT_PVQ_U_DATA+ 621,CELT_PVQ_U_DATA+ 826,CELT_PVQ_U_DATA+1030, + CELT_PVQ_U_DATA+1233,CELT_PVQ_U_DATA+1336,CELT_PVQ_U_DATA+1389, + CELT_PVQ_U_DATA+1421,CELT_PVQ_U_DATA+1441,CELT_PVQ_U_DATA+1455, + CELT_PVQ_U_DATA+1464,CELT_PVQ_U_DATA+1470,CELT_PVQ_U_DATA+1473 }; #else -static const opus_uint32 *const CELT_PVQ_U_ROW[15] PROGMEM = { - CELT_PVQ_U_DATA + 0, CELT_PVQ_U_DATA + 176, CELT_PVQ_U_DATA + 351, - CELT_PVQ_U_DATA + 525, CELT_PVQ_U_DATA + 698, CELT_PVQ_U_DATA + 870, - CELT_PVQ_U_DATA + 1041, CELT_PVQ_U_DATA + 1131, CELT_PVQ_U_DATA + 1178, - CELT_PVQ_U_DATA + 1207, CELT_PVQ_U_DATA + 1226, CELT_PVQ_U_DATA + 1240, - CELT_PVQ_U_DATA + 1248, CELT_PVQ_U_DATA + 1254, CELT_PVQ_U_DATA + 1257 +static const opus_uint32 *const CELT_PVQ_U_ROW[15]={ + CELT_PVQ_U_DATA+ 0,CELT_PVQ_U_DATA+ 176,CELT_PVQ_U_DATA+ 351, + CELT_PVQ_U_DATA+ 525,CELT_PVQ_U_DATA+ 698,CELT_PVQ_U_DATA+ 870, + CELT_PVQ_U_DATA+1041,CELT_PVQ_U_DATA+1131,CELT_PVQ_U_DATA+1178, + CELT_PVQ_U_DATA+1207,CELT_PVQ_U_DATA+1226,CELT_PVQ_U_DATA+1240, + CELT_PVQ_U_DATA+1248,CELT_PVQ_U_DATA+1254,CELT_PVQ_U_DATA+1257 }; #endif #if defined(CUSTOM_MODES) -void get_required_bits(opus_int16 *_bits, int _n, int _maxk, int _frac) { - int k; - /*_maxk==0 => there's nothing to do.*/ - celt_assert(_maxk > 0); - _bits[0] = 0; - for (k = 1; k <= _maxk; k++) { - _bits[k] = log2_frac(CELT_PVQ_V(_n, k), _frac); - } +void get_required_bits(opus_int16 *_bits,int _n,int _maxk,int _frac){ + int k; + /*_maxk==0 => there's nothing to do.*/ + celt_assert(_maxk>0); + _bits[0]=0; + for(k=1;k<=_maxk;k++)_bits[k]=log2_frac(CELT_PVQ_V(_n,k),_frac); } #endif -static opus_uint32 icwrs(int _n, const int *_y) { - opus_uint32 i; - int j; - int k; - celt_assert(_n >= 2); - j = _n - 1; - i = _y[j] < 0; - k = abs(_y[j]); - do { - j--; - i += CELT_PVQ_U(_n - j, k); - k += abs(_y[j]); - if (_y[j] < 0) { - i += CELT_PVQ_U(_n - j, k + 1); - } - } while (j > 0); - return i; +static opus_uint32 icwrs(int _n,const int *_y){ + opus_uint32 i; + int j; + int k; + celt_assert(_n>=2); + j=_n-1; + i=_y[j]<0; + k=abs(_y[j]); + do{ + j--; + i+=CELT_PVQ_U(_n-j,k); + k+=abs(_y[j]); + if(_y[j]<0)i+=CELT_PVQ_U(_n-j,k+1); + } + while(j>0); + return i; } -void encode_pulses(const int *_y, int _n, int _k, ec_enc *_enc) { - celt_assert(_k > 0); - ec_enc_uint(_enc, icwrs(_n, _y), CELT_PVQ_V(_n, _k)); +void encode_pulses(const int *_y,int _n,int _k,ec_enc *_enc){ + celt_assert(_k>0); + ec_enc_uint(_enc,icwrs(_n,_y),CELT_PVQ_V(_n,_k)); } -static opus_val32 cwrsi(int _n, int _k, opus_uint32 _i, int *_y) { - opus_uint32 p; - int s; - int k0; - opus_int16 val; - opus_val32 yy = 0; - celt_assert(_k > 0); - celt_assert(_n > 1); - while (_n > 2) { - opus_uint32 q; - /*Lots of pulses case:*/ - if (_k >= _n) { - const opus_uint32 *row; - row = CELT_PVQ_U_ROW[_n]; - /*Are the pulses in this dimension negative?*/ - p = row[_k + 1]; - s = -(_i >= p); - _i -= p & s; - /*Count how many pulses were placed in this dimension.*/ - k0 = _k; - q = row[_n]; - if (q > _i) { - celt_sig_assert(p > q); - _k = _n; - do { - p = CELT_PVQ_U_ROW[--_k][_n]; - } while (p > _i); - } else for (p = row[_k]; p > _i; p = row[_k]) { - _k--; - } - _i -= p; - val = (k0 - _k + s)^s; - *_y++ = val; - yy = MAC16_16(yy, val, val); - } - /*Lots of dimensions case:*/ - else { - /*Are there any pulses in this dimension at all?*/ - p = CELT_PVQ_U_ROW[_k][_n]; - q = CELT_PVQ_U_ROW[_k + 1][_n]; - if (p <= _i && _i < q) { - _i -= p; - *_y++ = 0; - } else { - /*Are the pulses in this dimension negative?*/ - s = -(_i >= q); - _i -= q & s; - /*Count how many pulses were placed in this dimension.*/ - k0 = _k; - do { - p = CELT_PVQ_U_ROW[--_k][_n]; - } while (p > _i); - _i -= p; - val = (k0 - _k + s)^s; - *_y++ = val; - yy = MAC16_16(yy, val, val); - } - } - _n--; +static opus_val32 cwrsi(int _n,int _k,opus_uint32 _i,int *_y){ + opus_uint32 p; + int s; + int k0; + opus_int16 val; + opus_val32 yy=0; + celt_assert(_k>0); + celt_assert(_n>1); + while(_n>2){ + opus_uint32 q; + /*Lots of pulses case:*/ + if(_k>=_n){ + const opus_uint32 *row; + row=CELT_PVQ_U_ROW[_n]; + /*Are the pulses in this dimension negative?*/ + p=row[_k+1]; + s=-(_i>=p); + _i-=p&s; + /*Count how many pulses were placed in this dimension.*/ + k0=_k; + q=row[_n]; + if(q>_i){ + celt_sig_assert(p>q); + _k=_n; + do p=CELT_PVQ_U_ROW[--_k][_n]; + while(p>_i); + } + else for(p=row[_k];p>_i;p=row[_k])_k--; + _i-=p; + val=(k0-_k+s)^s; + *_y++=val; + yy=MAC16_16(yy,val,val); } - /*_n==2*/ - p = 2 * _k + 1; - s = -(_i >= p); - _i -= p & s; - k0 = _k; - _k = (_i + 1) >> 1; - if (_k) { - _i -= 2 * _k - 1; + /*Lots of dimensions case:*/ + else{ + /*Are there any pulses in this dimension at all?*/ + p=CELT_PVQ_U_ROW[_k][_n]; + q=CELT_PVQ_U_ROW[_k+1][_n]; + if(p<=_i&&_i=q); + _i-=q&s; + /*Count how many pulses were placed in this dimension.*/ + k0=_k; + do p=CELT_PVQ_U_ROW[--_k][_n]; + while(p>_i); + _i-=p; + val=(k0-_k+s)^s; + *_y++=val; + yy=MAC16_16(yy,val,val); + } } - val = (k0 - _k + s)^s; - *_y++ = val; - yy = MAC16_16(yy, val, val); - /*_n==1*/ - s = -(int)_i; - val = (_k + s)^s; - *_y = val; - yy = MAC16_16(yy, val, val); - return yy; + _n--; + } + /*_n==2*/ + p=2*_k+1; + s=-(_i>=p); + _i-=p&s; + k0=_k; + _k=(_i+1)>>1; + if(_k)_i-=2*_k-1; + val=(k0-_k+s)^s; + *_y++=val; + yy=MAC16_16(yy,val,val); + /*_n==1*/ + s=-(int)_i; + val=(_k+s)^s; + *_y=val; + yy=MAC16_16(yy,val,val); + return yy; } -opus_val32 decode_pulses(int *_y, int _n, int _k, ec_dec *_dec) { - return cwrsi(_n, _k, ec_dec_uint(_dec, CELT_PVQ_V(_n, _k)), _y); +opus_val32 decode_pulses(int *_y,int _n,int _k,ec_dec *_dec){ + return cwrsi(_n,_k,ec_dec_uint(_dec,CELT_PVQ_V(_n,_k)),_y); } #else /* SMALL_FOOTPRINT */ -/* Computes the next row/column of any recurrence that obeys the relation - u[i][j]=u[i-1][j]+u[i][j-1]+u[i-1][j-1]. - _ui0 is the base case for the new row/column.*/ -static OPUS_INLINE void unext(opus_uint32 *_ui, unsigned _len, opus_uint32 _ui0) { - opus_uint32 ui1; - unsigned j; - /* This do-while will overrun the array if we don't have storage for at least - 2 values.*/ - j = 1; do { - ui1 = UADD32(UADD32(_ui[j], _ui[j - 1]), _ui0); - _ui[j - 1] = _ui0; - _ui0 = ui1; - } while (++j < _len); - _ui[j - 1] = _ui0; +/*Computes the next row/column of any recurrence that obeys the relation + u[i][j]=u[i-1][j]+u[i][j-1]+u[i-1][j-1]. + _ui0 is the base case for the new row/column.*/ +static OPUS_INLINE void unext(opus_uint32 *_ui,unsigned _len,opus_uint32 _ui0){ + opus_uint32 ui1; + unsigned j; + /*This do-while will overrun the array if we don't have storage for at least + 2 values.*/ + j=1; do { + ui1=UADD32(UADD32(_ui[j],_ui[j-1]),_ui0); + _ui[j-1]=_ui0; + _ui0=ui1; + } while (++j<_len); + _ui[j-1]=_ui0; } -/* Computes the previous row/column of any recurrence that obeys the relation - u[i-1][j]=u[i][j]-u[i][j-1]-u[i-1][j-1]. - _ui0 is the base case for the new row/column.*/ -static OPUS_INLINE void uprev(opus_uint32 *_ui, unsigned _n, opus_uint32 _ui0) { - opus_uint32 ui1; - unsigned j; - /* This do-while will overrun the array if we don't have storage for at least - 2 values.*/ - j = 1; do { - ui1 = USUB32(USUB32(_ui[j], _ui[j - 1]), _ui0); - _ui[j - 1] = _ui0; - _ui0 = ui1; - } while (++j < _n); - _ui[j - 1] = _ui0; +/*Computes the previous row/column of any recurrence that obeys the relation + u[i-1][j]=u[i][j]-u[i][j-1]-u[i-1][j-1]. + _ui0 is the base case for the new row/column.*/ +static OPUS_INLINE void uprev(opus_uint32 *_ui,unsigned _n,opus_uint32 _ui0){ + opus_uint32 ui1; + unsigned j; + /*This do-while will overrun the array if we don't have storage for at least + 2 values.*/ + j=1; do { + ui1=USUB32(USUB32(_ui[j],_ui[j-1]),_ui0); + _ui[j-1]=_ui0; + _ui0=ui1; + } while (++j<_n); + _ui[j-1]=_ui0; } -/* Compute V(_n,_k), as well as U(_n,0..._k+1). - _u: On exit, _u[i] contains U(_n,i) for i in [0..._k+1].*/ -static opus_uint32 ncwrs_urow(unsigned _n, unsigned _k, opus_uint32 *_u) { - opus_uint32 um2; - unsigned len; - unsigned k; - len = _k + 2; - /*We require storage at least 3 values (e.g., _k>0).*/ - celt_assert(len >= 3); - _u[0] = 0; - _u[1] = um2 = 1; - /*If _n==0, _u[0] should be 1 and the rest should be 0.*/ - /*If _n==1, _u[i] should be 1 for i>1.*/ - celt_assert(_n >= 2); - /*If _k==0, the following do-while loop will overflow the buffer.*/ - celt_assert(_k > 0); - k = 2; - do { - _u[k] = (k << 1) - 1; - } while (++k < len); - for (k = 2; k < _n; k++) { - unext(_u + 1, _k + 1, 1); - } - return _u[_k] + _u[_k + 1]; +/*Compute V(_n,_k), as well as U(_n,0..._k+1). + _u: On exit, _u[i] contains U(_n,i) for i in [0..._k+1].*/ +static opus_uint32 ncwrs_urow(unsigned _n,unsigned _k,opus_uint32 *_u){ + opus_uint32 um2; + unsigned len; + unsigned k; + len=_k+2; + /*We require storage at least 3 values (e.g., _k>0).*/ + celt_assert(len>=3); + _u[0]=0; + _u[1]=um2=1; + /*If _n==0, _u[0] should be 1 and the rest should be 0.*/ + /*If _n==1, _u[i] should be 1 for i>1.*/ + celt_assert(_n>=2); + /*If _k==0, the following do-while loop will overflow the buffer.*/ + celt_assert(_k>0); + k=2; + do _u[k]=(k<<1)-1; + while(++k 0); - j = 0; - do { - opus_uint32 p; - int s; - int yj; - p = _u[_k + 1]; - s = -(_i >= p); - _i -= p & s; - yj = _k; - p = _u[_k]; - while (p > _i) { - p = _u[--_k]; - } - _i -= p; - yj -= _k; - val = (yj + s)^s; - _y[j] = val; - yy = MAC16_16(yy, val, val); - uprev(_u, _k + 2, 0); - } while (++j < _n); - return yy; +static opus_val32 cwrsi(int _n,int _k,opus_uint32 _i,int *_y,opus_uint32 *_u){ + int j; + opus_int16 val; + opus_val32 yy=0; + celt_assert(_n>0); + j=0; + do{ + opus_uint32 p; + int s; + int yj; + p=_u[_k+1]; + s=-(_i>=p); + _i-=p&s; + yj=_k; + p=_u[_k]; + while(p>_i)p=_u[--_k]; + _i-=p; + yj-=_k; + val=(yj+s)^s; + _y[j]=val; + yy=MAC16_16(yy,val,val); + uprev(_u,_k+2,0); + } + while(++j<_n); + return yy; } -/* Returns the index of the given combination of K elements chosen from a set - of size 1 with associated sign bits. - _y: The vector of pulses, whose sum of absolute values is K. - _k: Returns K.*/ -static OPUS_INLINE opus_uint32 icwrs1(const int *_y, int *_k) { - *_k = abs(_y[0]); - return _y[0] < 0; +/*Returns the index of the given combination of K elements chosen from a set + of size 1 with associated sign bits. + _y: The vector of pulses, whose sum of absolute values is K. + _k: Returns K.*/ +static OPUS_INLINE opus_uint32 icwrs1(const int *_y,int *_k){ + *_k=abs(_y[0]); + return _y[0]<0; } -/* Returns the index of the given combination of K elements chosen from a set - of size _n with associated sign bits. - _y: The vector of pulses, whose sum of absolute values must be _k. - _nc: Returns V(_n,_k).*/ -static OPUS_INLINE opus_uint32 icwrs(int _n, int _k, opus_uint32 *_nc, const int *_y, - opus_uint32 *_u) { - opus_uint32 i; - int j; - int k; - /*We can't unroll the first two iterations of the loop unless _n>=2.*/ - celt_assert(_n >= 2); - _u[0] = 0; - for (k = 1; k <= _k + 1; k++) { - _u[k] = (k << 1) - 1; - } - i = icwrs1(_y + _n - 1, &k); - j = _n - 2; - i += _u[k]; - k += abs(_y[j]); - if (_y[j] < 0) { - i += _u[k + 1]; - } - while (j-- > 0) { - unext(_u, _k + 2, 0); - i += _u[k]; - k += abs(_y[j]); - if (_y[j] < 0) { - i += _u[k + 1]; - } - } - *_nc = _u[k] + _u[k + 1]; - return i; +/*Returns the index of the given combination of K elements chosen from a set + of size _n with associated sign bits. + _y: The vector of pulses, whose sum of absolute values must be _k. + _nc: Returns V(_n,_k).*/ +static OPUS_INLINE opus_uint32 icwrs(int _n,int _k,opus_uint32 *_nc,const int *_y, + opus_uint32 *_u){ + opus_uint32 i; + int j; + int k; + /*We can't unroll the first two iterations of the loop unless _n>=2.*/ + celt_assert(_n>=2); + _u[0]=0; + for(k=1;k<=_k+1;k++)_u[k]=(k<<1)-1; + i=icwrs1(_y+_n-1,&k); + j=_n-2; + i+=_u[k]; + k+=abs(_y[j]); + if(_y[j]<0)i+=_u[k+1]; + while(j-->0){ + unext(_u,_k+2,0); + i+=_u[k]; + k+=abs(_y[j]); + if(_y[j]<0)i+=_u[k+1]; + } + *_nc=_u[k]+_u[k+1]; + return i; } #ifdef CUSTOM_MODES -void get_required_bits(opus_int16 *_bits, int _n, int _maxk, int _frac) { - int k; - /*_maxk==0 => there's nothing to do.*/ - celt_assert(_maxk > 0); - _bits[0] = 0; - if (_n == 1) { - for (k = 1; k <= _maxk; k++) { - _bits[k] = 1 << _frac; - } - } else { - VARDECL(opus_uint32, u); - SAVE_STACK; - ALLOC(u, _maxk + 2U, opus_uint32); - ncwrs_urow(_n, _maxk, u); - for (k = 1; k <= _maxk; k++) { - _bits[k] = log2_frac(u[k] + u[k + 1], _frac); - } - RESTORE_STACK; - } +void get_required_bits(opus_int16 *_bits,int _n,int _maxk,int _frac){ + int k; + /*_maxk==0 => there's nothing to do.*/ + celt_assert(_maxk>0); + _bits[0]=0; + if (_n==1) + { + for (k=1;k<=_maxk;k++) + _bits[k] = 1<<_frac; + } + else { + VARDECL(opus_uint32,u); + SAVE_STACK; + ALLOC(u,_maxk+2U,opus_uint32); + ncwrs_urow(_n,_maxk,u); + for(k=1;k<=_maxk;k++) + _bits[k]=log2_frac(u[k]+u[k+1],_frac); + RESTORE_STACK; + } } #endif /* CUSTOM_MODES */ -void encode_pulses(const int *_y, int _n, int _k, ec_enc *_enc) { - opus_uint32 i; - VARDECL(opus_uint32, u); - opus_uint32 nc; - SAVE_STACK; - celt_assert(_k > 0); - ALLOC(u, _k + 2U, opus_uint32); - i = icwrs(_n, _k, &nc, _y, u); - ec_enc_uint(_enc, i, nc); - RESTORE_STACK; +void encode_pulses(const int *_y,int _n,int _k,ec_enc *_enc){ + opus_uint32 i; + VARDECL(opus_uint32,u); + opus_uint32 nc; + SAVE_STACK; + celt_assert(_k>0); + ALLOC(u,_k+2U,opus_uint32); + i=icwrs(_n,_k,&nc,_y,u); + ec_enc_uint(_enc,i,nc); + RESTORE_STACK; } -opus_val32 decode_pulses(int *_y, int _n, int _k, ec_dec *_dec) { - VARDECL(opus_uint32, u); - int ret; - SAVE_STACK; - celt_assert(_k > 0); - ALLOC(u, _k + 2U, opus_uint32); - ret = cwrsi(_n, _k, ec_dec_uint(_dec, ncwrs_urow(_n, _k, u)), _y, u); - RESTORE_STACK; - return ret; +opus_val32 decode_pulses(int *_y,int _n,int _k,ec_dec *_dec){ + VARDECL(opus_uint32,u); + int ret; + SAVE_STACK; + celt_assert(_k>0); + ALLOC(u,_k+2U,opus_uint32); + ret = cwrsi(_n,_k,ec_dec_uint(_dec,ncwrs_urow(_n,_k,u)),_y,u); + RESTORE_STACK; + return ret; } #endif /* SMALL_FOOTPRINT */ diff --git a/src/libopus/celt/cwrs.h b/src/libopus/celt/cwrs.h index 5536f44..7cd4717 100644 --- a/src/libopus/celt/cwrs.h +++ b/src/libopus/celt/cwrs.h @@ -1,30 +1,30 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2007-2009 Timothy B. Terriberry - Written by Timothy B. Terriberry and Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2007-2009 Timothy B. Terriberry + Written by Timothy B. Terriberry and Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef CWRS_H diff --git a/src/libopus/celt/ecintrin.h b/src/libopus/celt/ecintrin.h index d19043d..66a4c36 100644 --- a/src/libopus/celt/ecintrin.h +++ b/src/libopus/celt/ecintrin.h @@ -1,62 +1,66 @@ -/* Copyright (c) 2003-2008 Timothy B. Terriberry - Copyright (c) 2008 Xiph.Org Foundation */ +/* Copyright (c) 2003-2008 Timothy B. Terriberry + Copyright (c) 2008 Xiph.Org Foundation */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /*Some common macros for potential platform-specific optimization.*/ -#include "../opus_types.h" +#include "opus_types.h" #include #include #include "arch.h" #if !defined(_ecintrin_H) # define _ecintrin_H (1) -/* Some specific platforms may have optimized intrinsic or OPUS_INLINE assembly - versions of these functions which can substantially improve performance. - We define macros for them to allow easy incorporation of these non-ANSI - features.*/ +/*Some specific platforms may have optimized intrinsic or OPUS_INLINE assembly + versions of these functions which can substantially improve performance. + We define macros for them to allow easy incorporation of these non-ANSI + features.*/ -/* Modern gcc (4.x) can compile the naive versions of min and max with cmov if - given an appropriate architecture, but the branchless bit-twiddling versions - are just as fast, and do not require any special target architecture. - Earlier gcc versions (3.x) compiled both code to the same assembly - instructions, because of the way they represented ((_b)>(_a)) internally.*/ +/*Modern gcc (4.x) can compile the naive versions of min and max with cmov if + given an appropriate architecture, but the branchless bit-twiddling versions + are just as fast, and do not require any special target architecture. + Earlier gcc versions (3.x) compiled both code to the same assembly + instructions, because of the way they represented ((_b)>(_a)) internally.*/ # define EC_MINI(_a,_b) ((_a)+(((_b)-(_a))&-((_b)<(_a)))) -/* Count leading zeros. - This macro should only be used for implementing ec_ilog(), if it is defined. - All other code should use EC_ILOG() instead.*/ +/*Count leading zeros. + This macro should only be used for implementing ec_ilog(), if it is defined. + All other code should use EC_ILOG() instead.*/ #if defined(_MSC_VER) && (_MSC_VER >= 1400) +#if defined(_MSC_VER) && (_MSC_VER >= 1910) +# include /* Improve compiler throughput. */ +#else # include +#endif /*In _DEBUG mode this is not an intrinsic by default.*/ # pragma intrinsic(_BitScanReverse) -static __inline int ec_bsr(unsigned long _x) { - unsigned long ret; - _BitScanReverse(&ret, _x); - return (int)ret; +static __inline int ec_bsr(unsigned long _x){ + unsigned long ret; + _BitScanReverse(&ret,_x); + return (int)ret; } # define EC_CLZ0 (1) # define EC_CLZ(_x) (-ec_bsr(_x)) @@ -75,10 +79,10 @@ static __inline int ec_bsr(unsigned long _x) { #endif #if defined(EC_CLZ) -/* Note that __builtin_clz is not defined when _x==0, according to the gcc - documentation (and that of the BSR instruction that implements it on x86). - The majority of the time we can never pass it zero. - When we need to, it can be special cased.*/ +/*Note that __builtin_clz is not defined when _x==0, according to the gcc + documentation (and that of the BSR instruction that implements it on x86). + The majority of the time we can never pass it zero. + When we need to, it can be special cased.*/ # define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x)) #else int ec_ilog(opus_uint32 _v); diff --git a/src/libopus/celt/entcode.c b/src/libopus/celt/entcode.c index e53c3cf..62e0ddf 100644 --- a/src/libopus/celt/entcode.c +++ b/src/libopus/celt/entcode.c @@ -1,154 +1,153 @@ -/* Copyright (c) 2001-2011 Timothy B. Terriberry +/* Copyright (c) 2001-2011 Timothy B. Terriberry */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "entcode.h" #include "arch.h" #if !defined(EC_CLZ) -/* This is a fallback for systems where we don't know how to access - a BSR or CLZ instruction (see ecintrin.h). - If you are optimizing Opus on a new platform and it has a native CLZ or - BZR (e.g. cell, MIPS, x86, etc) then making it available to Opus will be - an easy performance win.*/ -int ec_ilog(opus_uint32 _v) { - /* On a Pentium M, this branchless version tested as the fastest on - 1,000,000,000 random 32-bit integers, edging out a similar version with - branches, and a 256-entry LUT version.*/ - int ret; - int m; - ret = !!_v; - m = !!(_v & 0xFFFF0000) << 4; - _v >>= m; - ret |= m; - m = !!(_v & 0xFF00) << 3; - _v >>= m; - ret |= m; - m = !!(_v & 0xF0) << 2; - _v >>= m; - ret |= m; - m = !!(_v & 0xC) << 1; - _v >>= m; - ret |= m; - ret += !!(_v & 0x2); - return ret; +/*This is a fallback for systems where we don't know how to access + a BSR or CLZ instruction (see ecintrin.h). + If you are optimizing Opus on a new platform and it has a native CLZ or + BZR (e.g. cell, MIPS, x86, etc) then making it available to Opus will be + an easy performance win.*/ +int ec_ilog(opus_uint32 _v){ + /*On a Pentium M, this branchless version tested as the fastest on + 1,000,000,000 random 32-bit integers, edging out a similar version with + branches, and a 256-entry LUT version.*/ + int ret; + int m; + ret=!!_v; + m=!!(_v&0xFFFF0000)<<4; + _v>>=m; + ret|=m; + m=!!(_v&0xFF00)<<3; + _v>>=m; + ret|=m; + m=!!(_v&0xF0)<<2; + _v>>=m; + ret|=m; + m=!!(_v&0xC)<<1; + _v>>=m; + ret|=m; + ret+=!!(_v&0x2); + return ret; } #endif #if 1 -/* This is a faster version of ec_tell_frac() that takes advantage - of the low (1/8 bit) resolution to use just a linear function - followed by a lookup to determine the exact transition thresholds. */ -opus_uint32 ec_tell_frac(ec_ctx *_this) { - static const unsigned correction[8] = { - 35733, 38967, 42495, 46340, - 50535, 55109, 60097, 65535 - }; - opus_uint32 nbits; - opus_uint32 r; - int l; - unsigned b; - nbits = _this->nbits_total << BITRES; - l = EC_ILOG(_this->rng); - r = _this->rng >> (l - 16); - b = (r >> 12) - 8; - b += r > correction[b]; - l = (l << 3) + b; - return nbits - l; +/* This is a faster version of ec_tell_frac() that takes advantage + of the low (1/8 bit) resolution to use just a linear function + followed by a lookup to determine the exact transition thresholds. */ +opus_uint32 ec_tell_frac(ec_ctx *_this){ + static const unsigned correction[8] = + {35733, 38967, 42495, 46340, + 50535, 55109, 60097, 65535}; + opus_uint32 nbits; + opus_uint32 r; + int l; + unsigned b; + nbits=_this->nbits_total<rng); + r=_this->rng>>(l-16); + b = (r>>12)-8; + b += r>correction[b]; + l = (l<<3)+b; + return nbits-l; } #else -opus_uint32 ec_tell_frac(ec_ctx *_this) { - opus_uint32 nbits; - opus_uint32 r; - int l; - int i; - /* To handle the non-integral number of bits still left in the encoder/decoder - state, we compute the worst-case number of bits of val that must be - encoded to ensure that the value is inside the range for any possible - subsequent bits. - The computation here is independent of val itself (the decoder does not - even track that value), even though the real number of bits used after - ec_enc_done() may be 1 smaller if rng is a power of two and the - corresponding trailing bits of val are all zeros. - If we did try to track that special case, then coding a value with a - probability of 1/(1<nbits_total << BITRES; - l = EC_ILOG(_this->rng); - r = _this->rng >> (l - 16); - for (i = BITRES; i-- > 0;) { - int b; - r = r * r >> 15; - b = (int)(r >> 16); - l = l << 1 | b; - r >>= b; - } - return nbits - l; +opus_uint32 ec_tell_frac(ec_ctx *_this){ + opus_uint32 nbits; + opus_uint32 r; + int l; + int i; + /*To handle the non-integral number of bits still left in the encoder/decoder + state, we compute the worst-case number of bits of val that must be + encoded to ensure that the value is inside the range for any possible + subsequent bits. + The computation here is independent of val itself (the decoder does not + even track that value), even though the real number of bits used after + ec_enc_done() may be 1 smaller if rng is a power of two and the + corresponding trailing bits of val are all zeros. + If we did try to track that special case, then coding a value with a + probability of 1/(1<nbits_total<rng); + r=_this->rng>>(l-16); + for(i=BITRES;i-->0;){ + int b; + r=r*r>>15; + b=(int)(r>>16); + l=l<<1|b; + r>>=b; + } + return nbits-l; } #endif #ifdef USE_SMALL_DIV_TABLE /* Result of 2^32/(2*i+1), except for i=0. */ const opus_uint32 SMALL_DIV_TABLE[129] = { - 0xFFFFFFFF, 0x55555555, 0x33333333, 0x24924924, - 0x1C71C71C, 0x1745D174, 0x13B13B13, 0x11111111, - 0x0F0F0F0F, 0x0D79435E, 0x0C30C30C, 0x0B21642C, - 0x0A3D70A3, 0x097B425E, 0x08D3DCB0, 0x08421084, - 0x07C1F07C, 0x07507507, 0x06EB3E45, 0x06906906, - 0x063E7063, 0x05F417D0, 0x05B05B05, 0x0572620A, - 0x05397829, 0x05050505, 0x04D4873E, 0x04A7904A, - 0x047DC11F, 0x0456C797, 0x04325C53, 0x04104104, - 0x03F03F03, 0x03D22635, 0x03B5CC0E, 0x039B0AD1, - 0x0381C0E0, 0x0369D036, 0x03531DEC, 0x033D91D2, - 0x0329161F, 0x03159721, 0x03030303, 0x02F14990, - 0x02E05C0B, 0x02D02D02, 0x02C0B02C, 0x02B1DA46, - 0x02A3A0FD, 0x0295FAD4, 0x0288DF0C, 0x027C4597, - 0x02702702, 0x02647C69, 0x02593F69, 0x024E6A17, - 0x0243F6F0, 0x0239E0D5, 0x02302302, 0x0226B902, - 0x021D9EAD, 0x0214D021, 0x020C49BA, 0x02040810, - 0x01FC07F0, 0x01F44659, 0x01ECC07B, 0x01E573AC, - 0x01DE5D6E, 0x01D77B65, 0x01D0CB58, 0x01CA4B30, - 0x01C3F8F0, 0x01BDD2B8, 0x01B7D6C3, 0x01B20364, - 0x01AC5701, 0x01A6D01A, 0x01A16D3F, 0x019C2D14, - 0x01970E4F, 0x01920FB4, 0x018D3018, 0x01886E5F, - 0x0183C977, 0x017F405F, 0x017AD220, 0x01767DCE, - 0x01724287, 0x016E1F76, 0x016A13CD, 0x01661EC6, - 0x01623FA7, 0x015E75BB, 0x015AC056, 0x01571ED3, - 0x01539094, 0x01501501, 0x014CAB88, 0x0149539E, - 0x01460CBC, 0x0142D662, 0x013FB013, 0x013C995A, - 0x013991C2, 0x013698DF, 0x0133AE45, 0x0130D190, - 0x012E025C, 0x012B404A, 0x01288B01, 0x0125E227, - 0x01234567, 0x0120B470, 0x011E2EF3, 0x011BB4A4, - 0x01194538, 0x0116E068, 0x011485F0, 0x0112358E, - 0x010FEF01, 0x010DB20A, 0x010B7E6E, 0x010953F3, - 0x01073260, 0x0105197F, 0x0103091B, 0x01010101 + 0xFFFFFFFF, 0x55555555, 0x33333333, 0x24924924, + 0x1C71C71C, 0x1745D174, 0x13B13B13, 0x11111111, + 0x0F0F0F0F, 0x0D79435E, 0x0C30C30C, 0x0B21642C, + 0x0A3D70A3, 0x097B425E, 0x08D3DCB0, 0x08421084, + 0x07C1F07C, 0x07507507, 0x06EB3E45, 0x06906906, + 0x063E7063, 0x05F417D0, 0x05B05B05, 0x0572620A, + 0x05397829, 0x05050505, 0x04D4873E, 0x04A7904A, + 0x047DC11F, 0x0456C797, 0x04325C53, 0x04104104, + 0x03F03F03, 0x03D22635, 0x03B5CC0E, 0x039B0AD1, + 0x0381C0E0, 0x0369D036, 0x03531DEC, 0x033D91D2, + 0x0329161F, 0x03159721, 0x03030303, 0x02F14990, + 0x02E05C0B, 0x02D02D02, 0x02C0B02C, 0x02B1DA46, + 0x02A3A0FD, 0x0295FAD4, 0x0288DF0C, 0x027C4597, + 0x02702702, 0x02647C69, 0x02593F69, 0x024E6A17, + 0x0243F6F0, 0x0239E0D5, 0x02302302, 0x0226B902, + 0x021D9EAD, 0x0214D021, 0x020C49BA, 0x02040810, + 0x01FC07F0, 0x01F44659, 0x01ECC07B, 0x01E573AC, + 0x01DE5D6E, 0x01D77B65, 0x01D0CB58, 0x01CA4B30, + 0x01C3F8F0, 0x01BDD2B8, 0x01B7D6C3, 0x01B20364, + 0x01AC5701, 0x01A6D01A, 0x01A16D3F, 0x019C2D14, + 0x01970E4F, 0x01920FB4, 0x018D3018, 0x01886E5F, + 0x0183C977, 0x017F405F, 0x017AD220, 0x01767DCE, + 0x01724287, 0x016E1F76, 0x016A13CD, 0x01661EC6, + 0x01623FA7, 0x015E75BB, 0x015AC056, 0x01571ED3, + 0x01539094, 0x01501501, 0x014CAB88, 0x0149539E, + 0x01460CBC, 0x0142D662, 0x013FB013, 0x013C995A, + 0x013991C2, 0x013698DF, 0x0133AE45, 0x0130D190, + 0x012E025C, 0x012B404A, 0x01288B01, 0x0125E227, + 0x01234567, 0x0120B470, 0x011E2EF3, 0x011BB4A4, + 0x01194538, 0x0116E068, 0x011485F0, 0x0112358E, + 0x010FEF01, 0x010DB20A, 0x010B7E6E, 0x010953F3, + 0x01073260, 0x0105197F, 0x0103091B, 0x01010101 }; #endif diff --git a/src/libopus/celt/entcode.h b/src/libopus/celt/entcode.h index 4be773c..3763e3f 100644 --- a/src/libopus/celt/entcode.h +++ b/src/libopus/celt/entcode.h @@ -1,32 +1,32 @@ -/* Copyright (c) 2001-2011 Timothy B. Terriberry - Copyright (c) 2008-2009 Xiph.Org Foundation */ +/* Copyright (c) 2001-2011 Timothy B. Terriberry + Copyright (c) 2008-2009 Xiph.Org Foundation */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "../opus_types.h" -#include "../opus_defines.h" +#include "opus_types.h" +#include "opus_defines.h" #if !defined(_entcode_H) # define _entcode_H (1) @@ -40,8 +40,8 @@ extern const opus_uint32 SMALL_DIV_TABLE[129]; #define USE_SMALL_DIV_TABLE #endif -/* OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a - larger type, you can speed up the decoder by using it here.*/ +/*OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a + larger type, you can speed up the decoder by using it here.*/ typedef opus_uint32 ec_window; typedef struct ec_ctx ec_ctx; typedef struct ec_ctx ec_enc; @@ -52,101 +52,100 @@ typedef struct ec_ctx ec_dec; /*The number of bits to use for the range-coded part of unsigned integers.*/ # define EC_UINT_BITS (8) -/* The resolution of fractional-precision bit usage measurements, i.e., - 3 => 1/8th bits.*/ +/*The resolution of fractional-precision bit usage measurements, i.e., + 3 => 1/8th bits.*/ # define BITRES 3 -/* The entropy encoder/decoder context. - We use the same structure for both, so that common functions like ec_tell() - can be used on either one.*/ -struct ec_ctx { - /*Buffered input/output.*/ - unsigned char *buf; - /*The size of the buffer.*/ - opus_uint32 storage; - /*The offset at which the last byte containing raw bits was read/written.*/ - opus_uint32 end_offs; - /*Bits that will be read from/written at the end.*/ - ec_window end_window; - /*Number of valid bits in end_window.*/ - int nend_bits; - /* The total number of whole bits read/written. - This does not include partial bits currently in the range coder.*/ - int nbits_total; - /*The offset at which the next range coder byte will be read/written.*/ - opus_uint32 offs; - /*The number of values in the current range.*/ - opus_uint32 rng; - /* In the decoder: the difference between the top of the current range and - the input value, minus one. - In the encoder: the low end of the current range.*/ - opus_uint32 val; - /* In the decoder: the saved normalization factor from ec_decode(). - In the encoder: the number of oustanding carry propagating symbols.*/ - opus_uint32 ext; - /*A buffered input/output symbol, awaiting carry propagation.*/ - int rem; - /*Nonzero if an error occurred.*/ - int error; +/*The entropy encoder/decoder context. + We use the same structure for both, so that common functions like ec_tell() + can be used on either one.*/ +struct ec_ctx{ + /*Buffered input/output.*/ + unsigned char *buf; + /*The size of the buffer.*/ + opus_uint32 storage; + /*The offset at which the last byte containing raw bits was read/written.*/ + opus_uint32 end_offs; + /*Bits that will be read from/written at the end.*/ + ec_window end_window; + /*Number of valid bits in end_window.*/ + int nend_bits; + /*The total number of whole bits read/written. + This does not include partial bits currently in the range coder.*/ + int nbits_total; + /*The offset at which the next range coder byte will be read/written.*/ + opus_uint32 offs; + /*The number of values in the current range.*/ + opus_uint32 rng; + /*In the decoder: the difference between the top of the current range and + the input value, minus one. + In the encoder: the low end of the current range.*/ + opus_uint32 val; + /*In the decoder: the saved normalization factor from ec_decode(). + In the encoder: the number of oustanding carry propagating symbols.*/ + opus_uint32 ext; + /*A buffered input/output symbol, awaiting carry propagation.*/ + int rem; + /*Nonzero if an error occurred.*/ + int error; }; -static OPUS_INLINE opus_uint32 ec_range_bytes(ec_ctx *_this) { - return _this->offs; +static OPUS_INLINE opus_uint32 ec_range_bytes(ec_ctx *_this){ + return _this->offs; } -static OPUS_INLINE unsigned char *ec_get_buffer(ec_ctx *_this) { - return _this->buf; +static OPUS_INLINE unsigned char *ec_get_buffer(ec_ctx *_this){ + return _this->buf; } -static OPUS_INLINE int ec_get_error(ec_ctx *_this) { - return _this->error; +static OPUS_INLINE int ec_get_error(ec_ctx *_this){ + return _this->error; } -/* Returns the number of bits "used" by the encoded or decoded symbols so far. - This same number can be computed in either the encoder or the decoder, and is - suitable for making coding decisions. - Return: The number of bits. +/*Returns the number of bits "used" by the encoded or decoded symbols so far. + This same number can be computed in either the encoder or the decoder, and is + suitable for making coding decisions. + Return: The number of bits. This will always be slightly larger than the exact value (e.g., all rounding error is in the positive direction).*/ -static OPUS_INLINE int ec_tell(ec_ctx *_this) { - return _this->nbits_total - EC_ILOG(_this->rng); +static OPUS_INLINE int ec_tell(ec_ctx *_this){ + return _this->nbits_total-EC_ILOG(_this->rng); } -/* Returns the number of bits "used" by the encoded or decoded symbols so far. - This same number can be computed in either the encoder or the decoder, and is - suitable for making coding decisions. - Return: The number of bits scaled by 2**BITRES. +/*Returns the number of bits "used" by the encoded or decoded symbols so far. + This same number can be computed in either the encoder or the decoder, and is + suitable for making coding decisions. + Return: The number of bits scaled by 2**BITRES. This will always be slightly larger than the exact value (e.g., all rounding error is in the positive direction).*/ opus_uint32 ec_tell_frac(ec_ctx *_this); /* Tested exhaustively for all n and for 1<=d<=256 */ static OPUS_INLINE opus_uint32 celt_udiv(opus_uint32 n, opus_uint32 d) { - celt_sig_assert(d > 0); + celt_sig_assert(d>0); #ifdef USE_SMALL_DIV_TABLE - if (d > 256) { - return n / d; - } else { - opus_uint32 t, q; - t = EC_ILOG(d & -d); - q = (opus_uint64)SMALL_DIV_TABLE[d >> t] * (n >> (t - 1)) >> 32; - return q + (n - q * d >= d); - } + if (d>256) + return n/d; + else { + opus_uint32 t, q; + t = EC_ILOG(d&-d); + q = (opus_uint64)SMALL_DIV_TABLE[d>>t]*(n>>(t-1))>>32; + return q+(n-q*d >= d); + } #else - return n / d; + return n/d; #endif } static OPUS_INLINE opus_int32 celt_sudiv(opus_int32 n, opus_int32 d) { - celt_sig_assert(d > 0); + celt_sig_assert(d>0); #ifdef USE_SMALL_DIV_TABLE - if (n < 0) { - return -(opus_int32)celt_udiv(-n, d); - } else { - return celt_udiv(n, d); - } + if (n<0) + return -(opus_int32)celt_udiv(-n, d); + else + return celt_udiv(n, d); #else - return n / d; + return n/d; #endif } diff --git a/src/libopus/celt/entdec.c b/src/libopus/celt/entdec.c index a0ba562..c27dd4e 100644 --- a/src/libopus/celt/entdec.c +++ b/src/libopus/celt/entdec.c @@ -1,33 +1,33 @@ -/* Copyright (c) 2001-2011 Timothy B. Terriberry - Copyright (c) 2008-2009 Xiph.Org Foundation */ +/* Copyright (c) 2001-2011 Timothy B. Terriberry + Copyright (c) 2008-2009 Xiph.Org Foundation */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include #include "os_support.h" @@ -35,212 +35,232 @@ #include "entdec.h" #include "mfrngcod.h" -/* A range decoder. - This is an entropy decoder based upon \cite{Mar79}, which is itself a - rediscovery of the FIFO arithmetic code introduced by \cite{Pas76}. - It is very similar to arithmetic encoding, except that encoding is done with - digits in any base, instead of with bits, and so it is faster when using - larger bases (i.e.: a byte). - The author claims an average waste of $\frac{1}{2}\log_b(2b)$ bits, where $b$ - is the base, longer than the theoretical optimum, but to my knowledge there - is no published justification for this claim. - This only seems true when using near-infinite precision arithmetic so that - the process is carried out with no rounding errors. +/*A range decoder. + This is an entropy decoder based upon \cite{Mar79}, which is itself a + rediscovery of the FIFO arithmetic code introduced by \cite{Pas76}. + It is very similar to arithmetic encoding, except that encoding is done with + digits in any base, instead of with bits, and so it is faster when using + larger bases (i.e.: a byte). + The author claims an average waste of $\frac{1}{2}\log_b(2b)$ bits, where $b$ + is the base, longer than the theoretical optimum, but to my knowledge there + is no published justification for this claim. + This only seems true when using near-infinite precision arithmetic so that + the process is carried out with no rounding errors. - An excellent description of implementation details is available at - http://www.arturocampos.com/ac_range.html - A recent work \cite{MNW98} which proposes several changes to arithmetic - encoding for efficiency actually re-discovers many of the principles - behind range encoding, and presents a good theoretical analysis of them. + An excellent description of implementation details is available at + http://www.arturocampos.com/ac_range.html + A recent work \cite{MNW98} which proposes several changes to arithmetic + encoding for efficiency actually re-discovers many of the principles + behind range encoding, and presents a good theoretical analysis of them. - End of stream is handled by writing out the smallest number of bits that - ensures that the stream will be correctly decoded regardless of the value of - any subsequent bits. - ec_tell() can be used to determine how many bits were needed to decode - all the symbols thus far; other data can be packed in the remaining bits of - the input buffer. - @PHDTHESIS{Pas76, + End of stream is handled by writing out the smallest number of bits that + ensures that the stream will be correctly decoded regardless of the value of + any subsequent bits. + ec_tell() can be used to determine how many bits were needed to decode + all the symbols thus far; other data can be packed in the remaining bits of + the input buffer. + @PHDTHESIS{Pas76, author="Richard Clark Pasco", title="Source coding algorithms for fast data compression", school="Dept. of Electrical Engineering, Stanford University", address="Stanford, CA", month=May, year=1976 - } - @INPROCEEDINGS{Mar79, - author="Martin, G.N.N.", - title="Range encoding: an algorithm for removing redundancy from a digitised + } + @INPROCEEDINGS{Mar79, + author="Martin, G.N.N.", + title="Range encoding: an algorithm for removing redundancy from a digitised message", - booktitle="Video & Data Recording Conference", - year=1979, - address="Southampton", - month=Jul - } - @ARTICLE{MNW98, - author="Alistair Moffat and Radford Neal and Ian H. Witten", - title="Arithmetic Coding Revisited", - journal="{ACM} Transactions on Information Systems", - year=1998, - volume=16, - number=3, - pages="256--294", - month=Jul, - URL="http://www.stanford.edu/class/ee398a/handouts/papers/Moffat98ArithmCoding.pdf" - }*/ + booktitle="Video & Data Recording Conference", + year=1979, + address="Southampton", + month=Jul + } + @ARTICLE{MNW98, + author="Alistair Moffat and Radford Neal and Ian H. Witten", + title="Arithmetic Coding Revisited", + journal="{ACM} Transactions on Information Systems", + year=1998, + volume=16, + number=3, + pages="256--294", + month=Jul, + URL="http://www.stanford.edu/class/ee398a/handouts/papers/Moffat98ArithmCoding.pdf" + }*/ -static int ec_read_byte(ec_dec *_this) { - return _this->offs < _this->storage ? _this->buf[_this->offs++] : 0; +static int ec_read_byte(ec_dec *_this){ + return _this->offs<_this->storage?_this->buf[_this->offs++]:0; } -static int ec_read_byte_from_end(ec_dec *_this) { - return _this->end_offs < _this->storage ? - _this->buf[_this->storage - ++(_this->end_offs)] : 0; +static int ec_read_byte_from_end(ec_dec *_this){ + return _this->end_offs<_this->storage? + _this->buf[_this->storage-++(_this->end_offs)]:0; } -/* Normalizes the contents of val and rng so that rng lies entirely in the - high-order symbol.*/ -static void ec_dec_normalize(ec_dec *_this) { - /*If the range is too small, rescale it and input some bits.*/ - while (_this->rng <= EC_CODE_BOT) { - int sym; - _this->nbits_total += EC_SYM_BITS; - _this->rng <<= EC_SYM_BITS; - /*Use up the remaining bits from our last symbol.*/ - sym = _this->rem; - /*Read the next value from the input.*/ - _this->rem = ec_read_byte(_this); - /*Take the rest of the bits we need from this new symbol.*/ - sym = (sym << EC_SYM_BITS | _this->rem) >> (EC_SYM_BITS - EC_CODE_EXTRA); - /*And subtract them from val, capped to be less than EC_CODE_TOP.*/ - _this->val = ((_this->val << EC_SYM_BITS) + (EC_SYM_MAX & ~sym)) & (EC_CODE_TOP - 1); - } +/*Normalizes the contents of val and rng so that rng lies entirely in the + high-order symbol.*/ +static void ec_dec_normalize(ec_dec *_this){ + /*If the range is too small, rescale it and input some bits.*/ + while(_this->rng<=EC_CODE_BOT){ + int sym; + _this->nbits_total+=EC_SYM_BITS; + _this->rng<<=EC_SYM_BITS; + /*Use up the remaining bits from our last symbol.*/ + sym=_this->rem; + /*Read the next value from the input.*/ + _this->rem=ec_read_byte(_this); + /*Take the rest of the bits we need from this new symbol.*/ + sym=(sym<rem)>>(EC_SYM_BITS-EC_CODE_EXTRA); + /*And subtract them from val, capped to be less than EC_CODE_TOP.*/ + _this->val=((_this->val<buf = _buf; - _this->storage = _storage; - _this->end_offs = 0; - _this->end_window = 0; - _this->nend_bits = 0; - /* This is the offset from which ec_tell() will subtract partial bits. - The final value after the ec_dec_normalize() call will be the same as in - the encoder, but we have to compensate for the bits that are added there.*/ - _this->nbits_total = EC_CODE_BITS + 1 - - ((EC_CODE_BITS - EC_CODE_EXTRA) / EC_SYM_BITS) * EC_SYM_BITS; - _this->offs = 0; - _this->rng = 1U << EC_CODE_EXTRA; - _this->rem = ec_read_byte(_this); - _this->val = _this->rng - 1 - (_this->rem >> (EC_SYM_BITS - EC_CODE_EXTRA)); - _this->error = 0; - /*Normalize the interval.*/ - ec_dec_normalize(_this); +void ec_dec_init(ec_dec *_this,unsigned char *_buf,opus_uint32 _storage){ + _this->buf=_buf; + _this->storage=_storage; + _this->end_offs=0; + _this->end_window=0; + _this->nend_bits=0; + /*This is the offset from which ec_tell() will subtract partial bits. + The final value after the ec_dec_normalize() call will be the same as in + the encoder, but we have to compensate for the bits that are added there.*/ + _this->nbits_total=EC_CODE_BITS+1 + -((EC_CODE_BITS-EC_CODE_EXTRA)/EC_SYM_BITS)*EC_SYM_BITS; + _this->offs=0; + _this->rng=1U<rem=ec_read_byte(_this); + _this->val=_this->rng-1-(_this->rem>>(EC_SYM_BITS-EC_CODE_EXTRA)); + _this->error=0; + /*Normalize the interval.*/ + ec_dec_normalize(_this); } -unsigned ec_decode(ec_dec *_this, unsigned _ft) { - unsigned s; - _this->ext = celt_udiv(_this->rng, _ft); - s = (unsigned)(_this->val / _this->ext); - return _ft - EC_MINI(s + 1, _ft); +unsigned ec_decode(ec_dec *_this,unsigned _ft){ + unsigned s; + _this->ext=celt_udiv(_this->rng,_ft); + s=(unsigned)(_this->val/_this->ext); + return _ft-EC_MINI(s+1,_ft); } -unsigned ec_decode_bin(ec_dec *_this, unsigned _bits) { - unsigned s; - _this->ext = _this->rng >> _bits; - s = (unsigned)(_this->val / _this->ext); - return (1U << _bits) - EC_MINI(s + 1U, 1U << _bits); +unsigned ec_decode_bin(ec_dec *_this,unsigned _bits){ + unsigned s; + _this->ext=_this->rng>>_bits; + s=(unsigned)(_this->val/_this->ext); + return (1U<<_bits)-EC_MINI(s+1U,1U<<_bits); } -void ec_dec_update(ec_dec *_this, unsigned _fl, unsigned _fh, unsigned _ft) { - opus_uint32 s; - s = IMUL32(_this->ext, _ft - _fh); - _this->val -= s; - _this->rng = _fl > 0 ? IMUL32(_this->ext, _fh - _fl) : _this->rng - s; - ec_dec_normalize(_this); +void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){ + opus_uint32 s; + s=IMUL32(_this->ext,_ft-_fh); + _this->val-=s; + _this->rng=_fl>0?IMUL32(_this->ext,_fh-_fl):_this->rng-s; + ec_dec_normalize(_this); } /*The probability of having a "one" is 1/(1<<_logp).*/ -int ec_dec_bit_logp(ec_dec *_this, unsigned _logp) { - opus_uint32 r; - opus_uint32 d; - opus_uint32 s; - int ret; - r = _this->rng; - d = _this->val; - s = r >> _logp; - ret = d < s; - if (!ret) { - _this->val = d - s; - } - _this->rng = ret ? s : r - s; - ec_dec_normalize(_this); - return ret; +int ec_dec_bit_logp(ec_dec *_this,unsigned _logp){ + opus_uint32 r; + opus_uint32 d; + opus_uint32 s; + int ret; + r=_this->rng; + d=_this->val; + s=r>>_logp; + ret=dval=d-s; + _this->rng=ret?s:r-s; + ec_dec_normalize(_this); + return ret; } -int ec_dec_icdf(ec_dec *_this, const unsigned char *_icdf, unsigned _ftb) { - opus_uint32 r; - opus_uint32 d; - opus_uint32 s; +int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb){ + opus_uint32 r; + opus_uint32 d; + opus_uint32 s; + opus_uint32 t; + int ret; + s=_this->rng; + d=_this->val; + r=s>>_ftb; + ret=-1; + do{ + t=s; + s=IMUL32(r,_icdf[++ret]); + } + while(dval=d-s; + _this->rng=t-s; + ec_dec_normalize(_this); + return ret; +} + +int ec_dec_icdf16(ec_dec *_this,const opus_uint16 *_icdf,unsigned _ftb){ + opus_uint32 r; + opus_uint32 d; + opus_uint32 s; + opus_uint32 t; + int ret; + s=_this->rng; + d=_this->val; + r=s>>_ftb; + ret=-1; + do{ + t=s; + s=IMUL32(r,_icdf[++ret]); + } + while(dval=d-s; + _this->rng=t-s; + ec_dec_normalize(_this); + return ret; +} + +opus_uint32 ec_dec_uint(ec_dec *_this,opus_uint32 _ft){ + unsigned ft; + unsigned s; + int ftb; + /*In order to optimize EC_ILOG(), it is undefined for the value 0.*/ + celt_assert(_ft>1); + _ft--; + ftb=EC_ILOG(_ft); + if(ftb>EC_UINT_BITS){ opus_uint32 t; - int ret; - s = _this->rng; - d = _this->val; - r = s >> _ftb; - ret = -1; - do { - t = s; - s = IMUL32(r, _icdf[++ret]); - } while (d < s); - _this->val = d - s; - _this->rng = t - s; - ec_dec_normalize(_this); - return ret; + ftb-=EC_UINT_BITS; + ft=(unsigned)(_ft>>ftb)+1; + s=ec_decode(_this,ft); + ec_dec_update(_this,s,s+1,ft); + t=(opus_uint32)s<error=1; + return _ft; + } + else{ + _ft++; + s=ec_decode(_this,(unsigned)_ft); + ec_dec_update(_this,s,s+1,(unsigned)_ft); + return s; + } } -opus_uint32 ec_dec_uint(ec_dec *_this, opus_uint32 _ft) { - unsigned ft; - unsigned s; - int ftb; - /*In order to optimize EC_ILOG(), it is undefined for the value 0.*/ - celt_assert(_ft > 1); - _ft--; - ftb = EC_ILOG(_ft); - if (ftb > EC_UINT_BITS) { - opus_uint32 t; - ftb -= EC_UINT_BITS; - ft = (unsigned)(_ft >> ftb) + 1; - s = ec_decode(_this, ft); - ec_dec_update(_this, s, s + 1, ft); - t = (opus_uint32)s << ftb | ec_dec_bits(_this, ftb); - if (t <= _ft) { - return t; - } - _this->error = 1; - return _ft; - } else { - _ft++; - s = ec_decode(_this, (unsigned)_ft); - ec_dec_update(_this, s, s + 1, (unsigned)_ft); - return s; +opus_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){ + ec_window window; + int available; + opus_uint32 ret; + window=_this->end_window; + available=_this->nend_bits; + if((unsigned)available<_bits){ + do{ + window|=(ec_window)ec_read_byte_from_end(_this)<end_window; - available = _this->nend_bits; - if ((unsigned)available < _bits) { - do { - window |= (ec_window)ec_read_byte_from_end(_this) << available; - available += EC_SYM_BITS; - } while (available <= EC_WINDOW_SIZE - EC_SYM_BITS); - } - ret = (opus_uint32)window & (((opus_uint32)1 << _bits) - 1U); - window >>= _bits; - available -= _bits; - _this->end_window = window; - _this->nend_bits = available; - _this->nbits_total += _bits; - return ret; + while(available<=EC_WINDOW_SIZE-EC_SYM_BITS); + } + ret=(opus_uint32)window&(((opus_uint32)1<<_bits)-1U); + window>>=_bits; + available-=_bits; + _this->end_window=window; + _this->nend_bits=available; + _this->nbits_total+=_bits; + return ret; } diff --git a/src/libopus/celt/entdec.h b/src/libopus/celt/entdec.h index 69416f1..c81f26f 100644 --- a/src/libopus/celt/entdec.h +++ b/src/libopus/celt/entdec.h @@ -1,28 +1,28 @@ -/* Copyright (c) 2001-2011 Timothy B. Terriberry - Copyright (c) 2008-2009 Xiph.Org Foundation */ +/* Copyright (c) 2001-2011 Timothy B. Terriberry + Copyright (c) 2008-2009 Xiph.Org Foundation */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(_entdec_H) @@ -30,71 +30,81 @@ # include # include "entcode.h" -/* Initializes the decoder. - _buf: The input buffer to use. - Return: 0 on success, or a negative value on error.*/ -void ec_dec_init(ec_dec *_this, unsigned char *_buf, opus_uint32 _storage); +/*Initializes the decoder. + _buf: The input buffer to use. + Return: 0 on success, or a negative value on error.*/ +void ec_dec_init(ec_dec *_this,unsigned char *_buf,opus_uint32 _storage); -/* Calculates the cumulative frequency for the next symbol. - This can then be fed into the probability model to determine what that - symbol is, and the additional frequency information required to advance to - the next symbol. - This function cannot be called more than once without a corresponding call to - ec_dec_update(), or decoding will not proceed correctly. - _ft: The total frequency of the symbols in the alphabet the next symbol was +/*Calculates the cumulative frequency for the next symbol. + This can then be fed into the probability model to determine what that + symbol is, and the additional frequency information required to advance to + the next symbol. + This function cannot be called more than once without a corresponding call to + ec_dec_update(), or decoding will not proceed correctly. + _ft: The total frequency of the symbols in the alphabet the next symbol was encoded with. - Return: A cumulative frequency representing the encoded symbol. + Return: A cumulative frequency representing the encoded symbol. If the cumulative frequency of all the symbols before the one that was encoded was fl, and the cumulative frequency of all the symbols up to and including the one encoded is fh, then the returned value will fall in the range [fl,fh).*/ -unsigned ec_decode(ec_dec *_this, unsigned _ft); +unsigned ec_decode(ec_dec *_this,unsigned _ft); /*Equivalent to ec_decode() with _ft==1<<_bits.*/ -unsigned ec_decode_bin(ec_dec *_this, unsigned _bits); +unsigned ec_decode_bin(ec_dec *_this,unsigned _bits); -/* Advance the decoder past the next symbol using the frequency information the - symbol was encoded with. - Exactly one call to ec_decode() must have been made so that all necessary - intermediate calculations are performed. - _fl: The cumulative frequency of all symbols that come before the symbol +/*Advance the decoder past the next symbol using the frequency information the + symbol was encoded with. + Exactly one call to ec_decode() must have been made so that all necessary + intermediate calculations are performed. + _fl: The cumulative frequency of all symbols that come before the symbol decoded. - _fh: The cumulative frequency of all symbols up to and including the symbol + _fh: The cumulative frequency of all symbols up to and including the symbol decoded. Together with _fl, this defines the range [_fl,_fh) in which the value returned above must fall. - _ft: The total frequency of the symbols in the alphabet the symbol decoded + _ft: The total frequency of the symbols in the alphabet the symbol decoded was encoded in. This must be the same as passed to the preceding call to ec_decode().*/ -void ec_dec_update(ec_dec *_this, unsigned _fl, unsigned _fh, unsigned _ft); +void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft); /* Decode a bit that has a 1/(1<<_logp) probability of being a one */ -int ec_dec_bit_logp(ec_dec *_this, unsigned _logp); +int ec_dec_bit_logp(ec_dec *_this,unsigned _logp); -/* Decodes a symbol given an "inverse" CDF table. - No call to ec_dec_update() is necessary after this call. - _icdf: The "inverse" CDF, such that symbol s falls in the range +/*Decodes a symbol given an "inverse" CDF table. + No call to ec_dec_update() is necessary after this call. + _icdf: The "inverse" CDF, such that symbol s falls in the range [s>0?ft-_icdf[s-1]:0,ft-_icdf[s]), where ft=1<<_ftb. The values must be monotonically non-increasing, and the last value must be 0. - _ftb: The number of bits of precision in the cumulative distribution. - Return: The decoded symbol s.*/ -int ec_dec_icdf(ec_dec *_this, const unsigned char *_icdf, unsigned _ftb); + _ftb: The number of bits of precision in the cumulative distribution. + Return: The decoded symbol s.*/ +int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb); -/* Extracts a raw unsigned integer with a non-power-of-2 range from the stream. - The bits must have been encoded with ec_enc_uint(). - No call to ec_dec_update() is necessary after this call. - _ft: The number of integers that can be decoded (one more than the max). +/*Decodes a symbol given an "inverse" CDF table. + No call to ec_dec_update() is necessary after this call. + _icdf: The "inverse" CDF, such that symbol s falls in the range + [s>0?ft-_icdf[s-1]:0,ft-_icdf[s]), where ft=1<<_ftb. + The values must be monotonically non-increasing, and the last value + must be 0. + _ftb: The number of bits of precision in the cumulative distribution. + Return: The decoded symbol s.*/ +int ec_dec_icdf16(ec_dec *_this,const opus_uint16 *_icdf,unsigned _ftb); + +/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream. + The bits must have been encoded with ec_enc_uint(). + No call to ec_dec_update() is necessary after this call. + _ft: The number of integers that can be decoded (one more than the max). This must be at least 2, and no more than 2**32-1. - Return: The decoded bits.*/ -opus_uint32 ec_dec_uint(ec_dec *_this, opus_uint32 _ft); + Return: The decoded bits.*/ +opus_uint32 ec_dec_uint(ec_dec *_this,opus_uint32 _ft); -/* Extracts a sequence of raw bits from the stream. - The bits must have been encoded with ec_enc_bits(). - No call to ec_dec_update() is necessary after this call. - _ftb: The number of bits to extract. +/*Extracts a sequence of raw bits from the stream. + The bits must have been encoded with ec_enc_bits(). + No call to ec_dec_update() is necessary after this call. + _ftb: The number of bits to extract. This must be between 0 and 25, inclusive. - Return: The decoded bits.*/ -opus_uint32 ec_dec_bits(ec_dec *_this, unsigned _ftb); + Return: The decoded bits.*/ +opus_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb); #endif diff --git a/src/libopus/celt/entenc.c b/src/libopus/celt/entenc.c index 773cc92..b297ad7 100644 --- a/src/libopus/celt/entenc.c +++ b/src/libopus/celt/entenc.c @@ -1,310 +1,305 @@ -/* Copyright (c) 2001-2011 Timothy B. Terriberry - Copyright (c) 2008-2009 Xiph.Org Foundation */ +/* Copyright (c) 2001-2011 Timothy B. Terriberry + Copyright (c) 2008-2009 Xiph.Org Foundation */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#if defined(HAVE_CONFIG_H) -# include "../config.h" -//#endif +#if defined(__STDC__) +# include "config.h" +#endif #include "os_support.h" #include "arch.h" #include "entenc.h" #include "mfrngcod.h" -/* A range encoder. - See entdec.c and the references for implementation details \cite{Mar79,MNW98}. +/*A range encoder. + See entdec.c and the references for implementation details \cite{Mar79,MNW98}. - @INPROCEEDINGS{Mar79, - author="Martin, G.N.N.", - title="Range encoding: an algorithm for removing redundancy from a digitised + @INPROCEEDINGS{Mar79, + author="Martin, G.N.N.", + title="Range encoding: an algorithm for removing redundancy from a digitised message", - booktitle="Video \& Data Recording Conference", - year=1979, - address="Southampton", - month=Jul - } - @ARTICLE{MNW98, - author="Alistair Moffat and Radford Neal and Ian H. Witten", - title="Arithmetic Coding Revisited", - journal="{ACM} Transactions on Information Systems", - year=1998, - volume=16, - number=3, - pages="256--294", - month=Jul, - URL="http://www.stanford.edu/class/ee398/handouts/papers/Moffat98ArithmCoding.pdf" - }*/ + booktitle="Video \& Data Recording Conference", + year=1979, + address="Southampton", + month=Jul + } + @ARTICLE{MNW98, + author="Alistair Moffat and Radford Neal and Ian H. Witten", + title="Arithmetic Coding Revisited", + journal="{ACM} Transactions on Information Systems", + year=1998, + volume=16, + number=3, + pages="256--294", + month=Jul, + URL="http://www.stanford.edu/class/ee398/handouts/papers/Moffat98ArithmCoding.pdf" + }*/ -static int ec_write_byte(ec_enc *_this, unsigned _value) { - if (_this->offs + _this->end_offs >= _this->storage) { - return -1; - } - _this->buf[_this->offs++] = (unsigned char)_value; - return 0; +static int ec_write_byte(ec_enc *_this,unsigned _value){ + if(_this->offs+_this->end_offs>=_this->storage)return -1; + _this->buf[_this->offs++]=(unsigned char)_value; + return 0; } -static int ec_write_byte_at_end(ec_enc *_this, unsigned _value) { - if (_this->offs + _this->end_offs >= _this->storage) { - return -1; - } - _this->buf[_this->storage - ++(_this->end_offs)] = (unsigned char)_value; - return 0; +static int ec_write_byte_at_end(ec_enc *_this,unsigned _value){ + if(_this->offs+_this->end_offs>=_this->storage)return -1; + _this->buf[_this->storage-++(_this->end_offs)]=(unsigned char)_value; + return 0; } -/* Outputs a symbol, with a carry bit. - If there is a potential to propagate a carry over several symbols, they are - buffered until it can be determined whether or not an actual carry will - occur. - If the counter for the buffered symbols overflows, then the stream becomes - undecodable. - This gives a theoretical limit of a few billion symbols in a single packet on - 32-bit systems. - The alternative is to truncate the range in order to force a carry, but - requires similar carry tracking in the decoder, needlessly slowing it down.*/ -static void ec_enc_carry_out(ec_enc *_this, int _c) { - if (_c != EC_SYM_MAX) { - /*No further carry propagation possible, flush buffer.*/ - int carry; - carry = _c >> EC_SYM_BITS; - /* Don't output a byte on the first write. - This compare should be taken care of by branch-prediction thereafter.*/ - if (_this->rem >= 0) { - _this->error |= ec_write_byte(_this, _this->rem + carry); - } - if (_this->ext > 0) { - unsigned sym; - sym = (EC_SYM_MAX + carry)&EC_SYM_MAX; - do { - _this->error |= ec_write_byte(_this, sym); - } while (--(_this->ext) > 0); - } - _this->rem = _c & EC_SYM_MAX; - } else { - _this->ext++; +/*Outputs a symbol, with a carry bit. + If there is a potential to propagate a carry over several symbols, they are + buffered until it can be determined whether or not an actual carry will + occur. + If the counter for the buffered symbols overflows, then the stream becomes + undecodable. + This gives a theoretical limit of a few billion symbols in a single packet on + 32-bit systems. + The alternative is to truncate the range in order to force a carry, but + requires similar carry tracking in the decoder, needlessly slowing it down.*/ +static void ec_enc_carry_out(ec_enc *_this,int _c){ + if(_c!=EC_SYM_MAX){ + /*No further carry propagation possible, flush buffer.*/ + int carry; + carry=_c>>EC_SYM_BITS; + /*Don't output a byte on the first write. + This compare should be taken care of by branch-prediction thereafter.*/ + if(_this->rem>=0)_this->error|=ec_write_byte(_this,_this->rem+carry); + if(_this->ext>0){ + unsigned sym; + sym=(EC_SYM_MAX+carry)&EC_SYM_MAX; + do _this->error|=ec_write_byte(_this,sym); + while(--(_this->ext)>0); } + _this->rem=_c&EC_SYM_MAX; + } + else _this->ext++; } -static OPUS_INLINE void ec_enc_normalize(ec_enc *_this) { - /*If the range is too small, output some bits and rescale it.*/ - while (_this->rng <= EC_CODE_BOT) { - ec_enc_carry_out(_this, (int)(_this->val >> EC_CODE_SHIFT)); - /*Move the next-to-high-order symbol into the high-order position.*/ - _this->val = (_this->val << EC_SYM_BITS) & (EC_CODE_TOP - 1); - _this->rng <<= EC_SYM_BITS; - _this->nbits_total += EC_SYM_BITS; - } +static OPUS_INLINE void ec_enc_normalize(ec_enc *_this){ + /*If the range is too small, output some bits and rescale it.*/ + while(_this->rng<=EC_CODE_BOT){ + ec_enc_carry_out(_this,(int)(_this->val>>EC_CODE_SHIFT)); + /*Move the next-to-high-order symbol into the high-order position.*/ + _this->val=(_this->val<rng<<=EC_SYM_BITS; + _this->nbits_total+=EC_SYM_BITS; + } } -void ec_enc_init(ec_enc *_this, unsigned char *_buf, opus_uint32 _size) { - _this->buf = _buf; - _this->end_offs = 0; - _this->end_window = 0; - _this->nend_bits = 0; - /*This is the offset from which ec_tell() will subtract partial bits.*/ - _this->nbits_total = EC_CODE_BITS + 1; - _this->offs = 0; - _this->rng = EC_CODE_TOP; - _this->rem = -1; - _this->val = 0; - _this->ext = 0; - _this->storage = _size; - _this->error = 0; +void ec_enc_init(ec_enc *_this,unsigned char *_buf,opus_uint32 _size){ + _this->buf=_buf; + _this->end_offs=0; + _this->end_window=0; + _this->nend_bits=0; + /*This is the offset from which ec_tell() will subtract partial bits.*/ + _this->nbits_total=EC_CODE_BITS+1; + _this->offs=0; + _this->rng=EC_CODE_TOP; + _this->rem=-1; + _this->val=0; + _this->ext=0; + _this->storage=_size; + _this->error=0; } -void ec_encode(ec_enc *_this, unsigned _fl, unsigned _fh, unsigned _ft) { - opus_uint32 r; - r = celt_udiv(_this->rng, _ft); - if (_fl > 0) { - _this->val += _this->rng - IMUL32(r, (_ft - _fl)); - _this->rng = IMUL32(r, (_fh - _fl)); - } else { - _this->rng -= IMUL32(r, (_ft - _fh)); - } - ec_enc_normalize(_this); +void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft){ + opus_uint32 r; + r=celt_udiv(_this->rng,_ft); + if(_fl>0){ + _this->val+=_this->rng-IMUL32(r,(_ft-_fl)); + _this->rng=IMUL32(r,(_fh-_fl)); + } + else _this->rng-=IMUL32(r,(_ft-_fh)); + ec_enc_normalize(_this); } -void ec_encode_bin(ec_enc *_this, unsigned _fl, unsigned _fh, unsigned _bits) { - opus_uint32 r; - r = _this->rng >> _bits; - if (_fl > 0) { - _this->val += _this->rng - IMUL32(r, ((1U << _bits) - _fl)); - _this->rng = IMUL32(r, (_fh - _fl)); - } else { - _this->rng -= IMUL32(r, ((1U << _bits) - _fh)); - } - ec_enc_normalize(_this); +void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){ + opus_uint32 r; + r=_this->rng>>_bits; + if(_fl>0){ + _this->val+=_this->rng-IMUL32(r,((1U<<_bits)-_fl)); + _this->rng=IMUL32(r,(_fh-_fl)); + } + else _this->rng-=IMUL32(r,((1U<<_bits)-_fh)); + ec_enc_normalize(_this); } /*The probability of having a "one" is 1/(1<<_logp).*/ -void ec_enc_bit_logp(ec_enc *_this, int _val, unsigned _logp) { - opus_uint32 r; - opus_uint32 s; - opus_uint32 l; - r = _this->rng; - l = _this->val; - s = r >> _logp; - r -= s; - if (_val) { - _this->val = l + r; - } - _this->rng = _val ? s : r; - ec_enc_normalize(_this); +void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp){ + opus_uint32 r; + opus_uint32 s; + opus_uint32 l; + r=_this->rng; + l=_this->val; + s=r>>_logp; + r-=s; + if(_val)_this->val=l+r; + _this->rng=_val?s:r; + ec_enc_normalize(_this); } -void ec_enc_icdf(ec_enc *_this, int _s, const unsigned char *_icdf, unsigned _ftb) { - opus_uint32 r; - r = _this->rng >> _ftb; - if (_s > 0) { - _this->val += _this->rng - IMUL32(r, _icdf[_s - 1]); - _this->rng = IMUL32(r, _icdf[_s - 1] - _icdf[_s]); - } else { - _this->rng -= IMUL32(r, _icdf[_s]); - } - ec_enc_normalize(_this); +void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb){ + opus_uint32 r; + r=_this->rng>>_ftb; + if(_s>0){ + _this->val+=_this->rng-IMUL32(r,_icdf[_s-1]); + _this->rng=IMUL32(r,_icdf[_s-1]-_icdf[_s]); + } + else _this->rng-=IMUL32(r,_icdf[_s]); + ec_enc_normalize(_this); } -void ec_enc_uint(ec_enc *_this, opus_uint32 _fl, opus_uint32 _ft) { - unsigned ft; - unsigned fl; - int ftb; - /*In order to optimize EC_ILOG(), it is undefined for the value 0.*/ - celt_assert(_ft > 1); - _ft--; - ftb = EC_ILOG(_ft); - if (ftb > EC_UINT_BITS) { - ftb -= EC_UINT_BITS; - ft = (_ft >> ftb) + 1; - fl = (unsigned)(_fl >> ftb); - ec_encode(_this, fl, fl + 1, ft); - ec_enc_bits(_this, _fl & (((opus_uint32)1 << ftb) - 1U), ftb); - } else { - ec_encode(_this, _fl, _fl + 1, _ft + 1); - } +void ec_enc_icdf16(ec_enc *_this,int _s,const opus_uint16 *_icdf,unsigned _ftb){ + opus_uint32 r; + r=_this->rng>>_ftb; + if(_s>0){ + _this->val+=_this->rng-IMUL32(r,_icdf[_s-1]); + _this->rng=IMUL32(r,_icdf[_s-1]-_icdf[_s]); + } + else _this->rng-=IMUL32(r,_icdf[_s]); + ec_enc_normalize(_this); } -void ec_enc_bits(ec_enc *_this, opus_uint32 _fl, unsigned _bits) { - ec_window window; - int used; - window = _this->end_window; - used = _this->nend_bits; - celt_assert(_bits > 0); - if (used + _bits > EC_WINDOW_SIZE) { - do { - _this->error |= ec_write_byte_at_end(_this, (unsigned)window & EC_SYM_MAX); - window >>= EC_SYM_BITS; - used -= EC_SYM_BITS; - } while (used >= EC_SYM_BITS); - } - window |= (ec_window)_fl << used; - used += _bits; - _this->end_window = window; - _this->nend_bits = used; - _this->nbits_total += _bits; +void ec_enc_uint(ec_enc *_this,opus_uint32 _fl,opus_uint32 _ft){ + unsigned ft; + unsigned fl; + int ftb; + /*In order to optimize EC_ILOG(), it is undefined for the value 0.*/ + celt_assert(_ft>1); + _ft--; + ftb=EC_ILOG(_ft); + if(ftb>EC_UINT_BITS){ + ftb-=EC_UINT_BITS; + ft=(_ft>>ftb)+1; + fl=(unsigned)(_fl>>ftb); + ec_encode(_this,fl,fl+1,ft); + ec_enc_bits(_this,_fl&(((opus_uint32)1<offs > 0) { - /*The first byte has been finalized.*/ - _this->buf[0] = (unsigned char)((_this->buf[0] & ~mask) | _val << shift); - } else if (_this->rem >= 0) { - /*The first byte is still awaiting carry propagation.*/ - _this->rem = (_this->rem & ~mask) | _val << shift; - } else if (_this->rng <= (EC_CODE_TOP >> _nbits)) { - /*The renormalization loop has never been run.*/ - _this->val = (_this->val & ~((opus_uint32)mask << EC_CODE_SHIFT)) | - (opus_uint32)_val << (EC_CODE_SHIFT + shift); - } - /*The encoder hasn't even encoded _nbits of data yet.*/ - else { - _this->error = -1; +void ec_enc_bits(ec_enc *_this,opus_uint32 _fl,unsigned _bits){ + ec_window window; + int used; + window=_this->end_window; + used=_this->nend_bits; + celt_assert(_bits>0); + if(used+_bits>EC_WINDOW_SIZE){ + do{ + _this->error|=ec_write_byte_at_end(_this,(unsigned)window&EC_SYM_MAX); + window>>=EC_SYM_BITS; + used-=EC_SYM_BITS; } + while(used>=EC_SYM_BITS); + } + window|=(ec_window)_fl<end_window=window; + _this->nend_bits=used; + _this->nbits_total+=_bits; } -void ec_enc_shrink(ec_enc *_this, opus_uint32 _size) { - celt_assert(_this->offs + _this->end_offs <= _size); - OPUS_MOVE(_this->buf + _size - _this->end_offs, - _this->buf + _this->storage - _this->end_offs, _this->end_offs); - _this->storage = _size; +void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits){ + int shift; + unsigned mask; + celt_assert(_nbits<=EC_SYM_BITS); + shift=EC_SYM_BITS-_nbits; + mask=((1<<_nbits)-1)<offs>0){ + /*The first byte has been finalized.*/ + _this->buf[0]=(unsigned char)((_this->buf[0]&~mask)|_val<rem>=0){ + /*The first byte is still awaiting carry propagation.*/ + _this->rem=(_this->rem&~mask)|_val<rng<=(EC_CODE_TOP>>_nbits)){ + /*The renormalization loop has never been run.*/ + _this->val=(_this->val&~((opus_uint32)mask<error=-1; } -void ec_enc_done(ec_enc *_this) { - ec_window window; - int used; - opus_uint32 msk; - opus_uint32 end; - int l; - /* We output the minimum number of bits that ensures that the symbols encoded - thus far will be decoded correctly regardless of the bits that follow.*/ - l = EC_CODE_BITS - EC_ILOG(_this->rng); - msk = (EC_CODE_TOP - 1) >> l; - end = (_this->val + msk) & ~msk; - if ((end | msk) >= _this->val + _this->rng) { - l++; - msk >>= 1; - end = (_this->val + msk) & ~msk; - } - while (l > 0) { - ec_enc_carry_out(_this, (int)(end >> EC_CODE_SHIFT)); - end = (end << EC_SYM_BITS) & (EC_CODE_TOP - 1); - l -= EC_SYM_BITS; - } - /*If we have a buffered byte flush it into the output buffer.*/ - if (_this->rem >= 0 || _this->ext > 0) { - ec_enc_carry_out(_this, 0); - } - /*If we have buffered extra bits, flush them as well.*/ - window = _this->end_window; - used = _this->nend_bits; - while (used >= EC_SYM_BITS) { - _this->error |= ec_write_byte_at_end(_this, (unsigned)window & EC_SYM_MAX); - window >>= EC_SYM_BITS; - used -= EC_SYM_BITS; - } - /*Clear any excess space and add any remaining extra bits to the last byte.*/ - if (!_this->error) { - OPUS_CLEAR(_this->buf + _this->offs, - _this->storage - _this->offs - _this->end_offs); - if (used > 0) { - /*If there's no range coder data at all, give up.*/ - if (_this->end_offs >= _this->storage) { - _this->error = -1; - } else { - l = -l; - /* If we've busted, don't add too many extra bits to the last byte; it - would corrupt the range coder data, and that's more important.*/ - if (_this->offs + _this->end_offs >= _this->storage && l < used) { - window &= (1 << l) - 1; - _this->error = -1; - } - _this->buf[_this->storage - _this->end_offs - 1] |= (unsigned char)window; - } +void ec_enc_shrink(ec_enc *_this,opus_uint32 _size){ + celt_assert(_this->offs+_this->end_offs<=_size); + OPUS_MOVE(_this->buf+_size-_this->end_offs, + _this->buf+_this->storage-_this->end_offs,_this->end_offs); + _this->storage=_size; +} + +void ec_enc_done(ec_enc *_this){ + ec_window window; + int used; + opus_uint32 msk; + opus_uint32 end; + int l; + /*We output the minimum number of bits that ensures that the symbols encoded + thus far will be decoded correctly regardless of the bits that follow.*/ + l=EC_CODE_BITS-EC_ILOG(_this->rng); + msk=(EC_CODE_TOP-1)>>l; + end=(_this->val+msk)&~msk; + if((end|msk)>=_this->val+_this->rng){ + l++; + msk>>=1; + end=(_this->val+msk)&~msk; + } + while(l>0){ + ec_enc_carry_out(_this,(int)(end>>EC_CODE_SHIFT)); + end=(end<rem>=0||_this->ext>0)ec_enc_carry_out(_this,0); + /*If we have buffered extra bits, flush them as well.*/ + window=_this->end_window; + used=_this->nend_bits; + while(used>=EC_SYM_BITS){ + _this->error|=ec_write_byte_at_end(_this,(unsigned)window&EC_SYM_MAX); + window>>=EC_SYM_BITS; + used-=EC_SYM_BITS; + } + /*Clear any excess space and add any remaining extra bits to the last byte.*/ + if(!_this->error){ + OPUS_CLEAR(_this->buf+_this->offs, + _this->storage-_this->offs-_this->end_offs); + if(used>0){ + /*If there's no range coder data at all, give up.*/ + if(_this->end_offs>=_this->storage)_this->error=-1; + else{ + l=-l; + /*If we've busted, don't add too many extra bits to the last byte; it + would corrupt the range coder data, and that's more important.*/ + if(_this->offs+_this->end_offs>=_this->storage&&lerror=-1; } + _this->buf[_this->storage-_this->end_offs-1]|=(unsigned char)window; + } } + } } diff --git a/src/libopus/celt/entenc.h b/src/libopus/celt/entenc.h index 3df4f9c..010874b 100644 --- a/src/libopus/celt/entenc.h +++ b/src/libopus/celt/entenc.h @@ -1,28 +1,28 @@ -/* Copyright (c) 2001-2011 Timothy B. Terriberry - Copyright (c) 2008-2009 Xiph.Org Foundation */ +/* Copyright (c) 2001-2011 Timothy B. Terriberry + Copyright (c) 2008-2009 Xiph.Org Foundation */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(_entenc_H) @@ -30,81 +30,90 @@ # include # include "entcode.h" -/* Initializes the encoder. - _buf: The buffer to store output bytes in. - _size: The size of the buffer, in chars.*/ -void ec_enc_init(ec_enc *_this, unsigned char *_buf, opus_uint32 _size); -/* Encodes a symbol given its frequency information. - The frequency information must be discernable by the decoder, assuming it - has read only the previous symbols from the stream. - It is allowable to change the frequency information, or even the entire - source alphabet, so long as the decoder can tell from the context of the - previously encoded information that it is supposed to do so as well. - _fl: The cumulative frequency of all symbols that come before the one to be +/*Initializes the encoder. + _buf: The buffer to store output bytes in. + _size: The size of the buffer, in chars.*/ +void ec_enc_init(ec_enc *_this,unsigned char *_buf,opus_uint32 _size); +/*Encodes a symbol given its frequency information. + The frequency information must be discernable by the decoder, assuming it + has read only the previous symbols from the stream. + It is allowable to change the frequency information, or even the entire + source alphabet, so long as the decoder can tell from the context of the + previously encoded information that it is supposed to do so as well. + _fl: The cumulative frequency of all symbols that come before the one to be encoded. - _fh: The cumulative frequency of all symbols up to and including the one to + _fh: The cumulative frequency of all symbols up to and including the one to be encoded. Together with _fl, this defines the range [_fl,_fh) in which the decoded value will fall. - _ft: The sum of the frequencies of all the symbols*/ -void ec_encode(ec_enc *_this, unsigned _fl, unsigned _fh, unsigned _ft); + _ft: The sum of the frequencies of all the symbols*/ +void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft); /*Equivalent to ec_encode() with _ft==1<<_bits.*/ -void ec_encode_bin(ec_enc *_this, unsigned _fl, unsigned _fh, unsigned _bits); +void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits); /* Encode a bit that has a 1/(1<<_logp) probability of being a one */ -void ec_enc_bit_logp(ec_enc *_this, int _val, unsigned _logp); +void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp); -/* Encodes a symbol given an "inverse" CDF table. - _s: The index of the symbol to encode. - _icdf: The "inverse" CDF, such that symbol _s falls in the range +/*Encodes a symbol given an "inverse" CDF table. + _s: The index of the symbol to encode. + _icdf: The "inverse" CDF, such that symbol _s falls in the range [_s>0?ft-_icdf[_s-1]:0,ft-_icdf[_s]), where ft=1<<_ftb. The values must be monotonically non-increasing, and the last value must be 0. - _ftb: The number of bits of precision in the cumulative distribution.*/ -void ec_enc_icdf(ec_enc *_this, int _s, const unsigned char *_icdf, unsigned _ftb); + _ftb: The number of bits of precision in the cumulative distribution.*/ +void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb); -/* Encodes a raw unsigned integer in the stream. - _fl: The integer to encode. - _ft: The number of integers that can be encoded (one more than the max). +/*Encodes a symbol given an "inverse" CDF table. + _s: The index of the symbol to encode. + _icdf: The "inverse" CDF, such that symbol _s falls in the range + [_s>0?ft-_icdf[_s-1]:0,ft-_icdf[_s]), where ft=1<<_ftb. + The values must be monotonically non-increasing, and the last value + must be 0. + _ftb: The number of bits of precision in the cumulative distribution.*/ +void ec_enc_icdf16(ec_enc *_this,int _s,const opus_uint16 *_icdf,unsigned _ftb); + +/*Encodes a raw unsigned integer in the stream. + _fl: The integer to encode. + _ft: The number of integers that can be encoded (one more than the max). This must be at least 2, and no more than 2**32-1.*/ -void ec_enc_uint(ec_enc *_this, opus_uint32 _fl, opus_uint32 _ft); +void ec_enc_uint(ec_enc *_this,opus_uint32 _fl,opus_uint32 _ft); -/* Encodes a sequence of raw bits in the stream. - _fl: The bits to encode. - _ftb: The number of bits to encode. +/*Encodes a sequence of raw bits in the stream. + _fl: The bits to encode. + _ftb: The number of bits to encode. This must be between 1 and 25, inclusive.*/ -void ec_enc_bits(ec_enc *_this, opus_uint32 _fl, unsigned _ftb); +void ec_enc_bits(ec_enc *_this,opus_uint32 _fl,unsigned _ftb); -/* Overwrites a few bits at the very start of an existing stream, after they - have already been encoded. - This makes it possible to have a few flags up front, where it is easy for - decoders to access them without parsing the whole stream, even if their - values are not determined until late in the encoding process, without having - to buffer all the intermediate symbols in the encoder. - In order for this to work, at least _nbits bits must have already been - encoded using probabilities that are an exact power of two. - The encoder can verify the number of encoded bits is sufficient, but cannot - check this latter condition. - _val: The bits to encode (in the least _nbits significant bits). +/*Overwrites a few bits at the very start of an existing stream, after they + have already been encoded. + This makes it possible to have a few flags up front, where it is easy for + decoders to access them without parsing the whole stream, even if their + values are not determined until late in the encoding process, without having + to buffer all the intermediate symbols in the encoder. + In order for this to work, at least _nbits bits must have already been + encoded using probabilities that are an exact power of two. + The encoder can verify the number of encoded bits is sufficient, but cannot + check this latter condition. + _val: The bits to encode (in the least _nbits significant bits). They will be decoded in order from most-significant to least. - _nbits: The number of bits to overwrite. + _nbits: The number of bits to overwrite. This must be no more than 8.*/ -void ec_enc_patch_initial_bits(ec_enc *_this, unsigned _val, unsigned _nbits); +void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits); -/* Compacts the data to fit in the target size. - This moves up the raw bits at the end of the current buffer so they are at - the end of the new buffer size. - The caller must ensure that the amount of data that's already been written - will fit in the new size. - _size: The number of bytes in the new buffer. +/*Compacts the data to fit in the target size. + This moves up the raw bits at the end of the current buffer so they are at + the end of the new buffer size. + The caller must ensure that the amount of data that's already been written + will fit in the new size. + _size: The number of bytes in the new buffer. This must be large enough to contain the bits already written, and must be no larger than the existing size.*/ -void ec_enc_shrink(ec_enc *_this, opus_uint32 _size); +void ec_enc_shrink(ec_enc *_this,opus_uint32 _size); -/* Indicates that there are no more symbols to encode. - All reamining output bytes are flushed to the output buffer. - ec_enc_init() must be called before the encoder can be used again.*/ +/*Indicates that there are no more symbols to encode. + All reamining output bytes are flushed to the output buffer. + ec_enc_init() must be called before the encoder can be used again.*/ void ec_enc_done(ec_enc *_this); #endif diff --git a/src/libopus/celt/fixed_debug.h b/src/libopus/celt/fixed_debug.h index 07437b9..ef2e5d0 100644 --- a/src/libopus/celt/fixed_debug.h +++ b/src/libopus/celt/fixed_debug.h @@ -1,42 +1,42 @@ -/* Copyright (C) 2003-2008 Jean-Marc Valin - Copyright (C) 2007-2012 Xiph.Org Foundation */ +/* Copyright (C) 2003-2008 Jean-Marc Valin + Copyright (C) 2007-2012 Xiph.Org Foundation */ /** - @file fixed_debug.h - @brief Fixed-point operations with debugging + @file fixed_debug.h + @brief Fixed-point operations with debugging */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FIXED_DEBUG_H #define FIXED_DEBUG_H #include -#include "../opus_defines.h" +#include "opus_defines.h" #ifdef CELT_C -OPUS_EXPORT opus_int64 celt_mips = 0; +OPUS_EXPORT opus_int64 celt_mips=0; #else extern opus_int64 celt_mips; #endif @@ -67,146 +67,168 @@ extern opus_int64 celt_mips; /** Negate 32-bit value, ignore any overflows */ #define NEG32_ovflw(a) (celt_mips+=2,(opus_val32)(0-(opus_uint32)(a))) -static OPUS_INLINE short NEG16(int x) { - int res; - if (!VERIFY_SHORT(x)) { - fprintf(stderr, "NEG16: input is not short: %d\n", (int)x); +static OPUS_INLINE short NEG16(int x) +{ + int res; + if (!VERIFY_SHORT(x)) + { + fprintf (stderr, "NEG16: input is not short: %d\n", (int)x); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = -x; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "NEG16: output is not short: %d\n", (int)res); + } + res = -x; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "NEG16: output is not short: %d\n", (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips++; - return res; + } + celt_mips++; + return res; } -static OPUS_INLINE int NEG32(opus_int64 x) { - opus_int64 res; - if (!VERIFY_INT(x)) { - fprintf(stderr, "NEG16: input is not int: %d\n", (int)x); +static OPUS_INLINE int NEG32(opus_int64 x) +{ + opus_int64 res; + if (!VERIFY_INT(x)) + { + fprintf (stderr, "NEG16: input is not int: %d\n", (int)x); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = -x; - if (!VERIFY_INT(res)) { - fprintf(stderr, "NEG16: output is not int: %d\n", (int)res); + } + res = -x; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "NEG16: output is not int: %d\n", (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 2; - return res; + } + celt_mips+=2; + return res; } #define EXTRACT16(x) EXTRACT16_(x, __FILE__, __LINE__) -static OPUS_INLINE short EXTRACT16_(int x, char *file, int line) { - int res; - if (!VERIFY_SHORT(x)) { - fprintf(stderr, "EXTRACT16: input is not short: %d in %s: line %d\n", x, file, line); +static OPUS_INLINE short EXTRACT16_(int x, char *file, int line) +{ + int res; + if (!VERIFY_SHORT(x)) + { + fprintf (stderr, "EXTRACT16: input is not short: %d in %s: line %d\n", x, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = x; - celt_mips++; - return res; + } + res = x; + celt_mips++; + return res; } #define EXTEND32(x) EXTEND32_(x, __FILE__, __LINE__) -static OPUS_INLINE int EXTEND32_(int x, char *file, int line) { - int res; - if (!VERIFY_SHORT(x)) { - fprintf(stderr, "EXTEND32: input is not short: %d in %s: line %d\n", x, file, line); +static OPUS_INLINE int EXTEND32_(int x, char *file, int line) +{ + int res; + if (!VERIFY_SHORT(x)) + { + fprintf (stderr, "EXTEND32: input is not short: %d in %s: line %d\n", x, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = x; - celt_mips++; - return res; + } + res = x; + celt_mips++; + return res; } #define SHR16(a, shift) SHR16_(a, shift, __FILE__, __LINE__) -static OPUS_INLINE short SHR16_(int a, int shift, char *file, int line) { - int res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) { - fprintf(stderr, "SHR16: inputs are not short: %d >> %d in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE short SHR16_(int a, int shift, char *file, int line) +{ + int res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) + { + fprintf (stderr, "SHR16: inputs are not short: %d >> %d in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a >> shift; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "SHR16: output is not short: %d in %s: line %d\n", res, file, line); + } + res = a>>shift; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "SHR16: output is not short: %d in %s: line %d\n", res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips++; - return res; + } + celt_mips++; + return res; } #define SHL16(a, shift) SHL16_(a, shift, __FILE__, __LINE__) -static OPUS_INLINE short SHL16_(int a, int shift, char *file, int line) { - int res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) { - fprintf(stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE short SHL16_(int a, int shift, char *file, int line) +{ + opus_int32 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) + { + fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a << shift; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "SHL16: output is not short: %d in %s: line %d\n", res, file, line); + } + res = (opus_int32)((opus_uint32)a<> shift; - if (!VERIFY_INT(res)) { - fprintf(stderr, "SHR32: output is not int: %d\n", (int)res); + } + res = a>>shift; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "SHR32: output is not int: %d\n", (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 2; - return res; + } + celt_mips+=2; + return res; } #define SHL32(a, shift) SHL32_(a, shift, __FILE__, __LINE__) -static OPUS_INLINE int SHL32_(opus_int64 a, int shift, char *file, int line) { - opus_int64 res; - if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) { - fprintf(stderr, "SHL32: inputs are not int: %lld %d in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE int SHL32_(opus_int64 a, int shift, char *file, int line) +{ + opus_int64 res; + if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) + { + fprintf (stderr, "SHL32: inputs are not int: %lld %d in %s: line %d\n", (long long)a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a << shift; - if (!VERIFY_INT(res)) { - fprintf(stderr, "SHL32: output is not int: %lld<<%d = %lld in %s: line %d\n", a, shift, res, file, line); + } + res = (opus_int64)((opus_uint64)a<>1))),shift)) @@ -219,491 +241,596 @@ static OPUS_INLINE int SHL32_(opus_int64 a, int shift, char *file, int line) { #define HALF32(x) (SHR32(x,1)) #define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__) -static OPUS_INLINE short ADD16_(int a, int b, char *file, int line) { - int res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); +static OPUS_INLINE short ADD16_(int a, int b, char *file, int line) +{ + int res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a + b; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "ADD16: output is not short: %d+%d=%d in %s: line %d\n", a, b, res, file, line); + } + res = a+b; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "ADD16: output is not short: %d+%d=%d in %s: line %d\n", a,b,res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips++; - return res; + } + celt_mips++; + return res; } #define SUB16(a, b) SUB16_(a, b, __FILE__, __LINE__) -static OPUS_INLINE short SUB16_(int a, int b, char *file, int line) { - int res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "SUB16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); +static OPUS_INLINE short SUB16_(int a, int b, char *file, int line) +{ + int res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "SUB16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a - b; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "SUB16: output is not short: %d in %s: line %d\n", res, file, line); + } + res = a-b; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "SUB16: output is not short: %d in %s: line %d\n", res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips++; - return res; + } + celt_mips++; + return res; } #define ADD32(a, b) ADD32_(a, b, __FILE__, __LINE__) -static OPUS_INLINE int ADD32_(opus_int64 a, opus_int64 b, char *file, int line) { - opus_int64 res; - if (!VERIFY_INT(a) || !VERIFY_INT(b)) { - fprintf(stderr, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line); +static OPUS_INLINE int ADD32_(opus_int64 a, opus_int64 b, char *file, int line) +{ + opus_int64 res; + if (!VERIFY_INT(a) || !VERIFY_INT(b)) + { + fprintf (stderr, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a + b; - if (!VERIFY_INT(res)) { - fprintf(stderr, "ADD32: output is not int: %d in %s: line %d\n", (int)res, file, line); + } + res = a+b; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "ADD32: output is not int: %d in %s: line %d\n", (int)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 2; - return res; + } + celt_mips+=2; + return res; } #define SUB32(a, b) SUB32_(a, b, __FILE__, __LINE__) -static OPUS_INLINE int SUB32_(opus_int64 a, opus_int64 b, char *file, int line) { - opus_int64 res; - if (!VERIFY_INT(a) || !VERIFY_INT(b)) { - fprintf(stderr, "SUB32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line); +static OPUS_INLINE int SUB32_(opus_int64 a, opus_int64 b, char *file, int line) +{ + opus_int64 res; + if (!VERIFY_INT(a) || !VERIFY_INT(b)) + { + fprintf (stderr, "SUB32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a - b; - if (!VERIFY_INT(res)) { - fprintf(stderr, "SUB32: output is not int: %d in %s: line %d\n", (int)res, file, line); + } + res = a-b; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "SUB32: output is not int: %d in %s: line %d\n", (int)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 2; - return res; + } + celt_mips+=2; + return res; } #undef UADD32 #define UADD32(a, b) UADD32_(a, b, __FILE__, __LINE__) -static OPUS_INLINE unsigned int UADD32_(opus_uint64 a, opus_uint64 b, char *file, int line) { - opus_uint64 res; - if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) { - fprintf(stderr, "UADD32: inputs are not uint32: %llu %llu in %s: line %d\n", a, b, file, line); +static OPUS_INLINE unsigned int UADD32_(opus_uint64 a, opus_uint64 b, char *file, int line) +{ + opus_uint64 res; + if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) + { + fprintf (stderr, "UADD32: inputs are not uint32: %llu %llu in %s: line %d\n", (unsigned long long)a, (unsigned long long)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a + b; - if (!VERIFY_UINT(res)) { - fprintf(stderr, "UADD32: output is not uint32: %llu in %s: line %d\n", res, file, line); + } + res = a+b; + if (!VERIFY_UINT(res)) + { + fprintf (stderr, "UADD32: output is not uint32: %llu in %s: line %d\n", (unsigned long long)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 2; - return res; + } + celt_mips+=2; + return res; } #undef USUB32 #define USUB32(a, b) USUB32_(a, b, __FILE__, __LINE__) -static OPUS_INLINE unsigned int USUB32_(opus_uint64 a, opus_uint64 b, char *file, int line) { - opus_uint64 res; - if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) { - fprintf(stderr, "USUB32: inputs are not uint32: %llu %llu in %s: line %d\n", a, b, file, line); +static OPUS_INLINE unsigned int USUB32_(opus_uint64 a, opus_uint64 b, char *file, int line) +{ + opus_uint64 res; + if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) + { + fprintf (stderr, "USUB32: inputs are not uint32: %llu %llu in %s: line %d\n", (unsigned long long)a, (unsigned long long)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - if (a < b) { - fprintf(stderr, "USUB32: inputs underflow: %llu < %llu in %s: line %d\n", a, b, file, line); + } + if (a> 16; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT32_32_Q16: output is not int: %lld*%lld=%lld\n", (long long)a, (long long)b, (long long)res); +#ifdef FIXED_DEBUG_ASSERT + celt_assert(0); +#endif + } + celt_mips+=5; + return res; } #define MULT16_16(a, b) MULT16_16_(a, b, __FILE__, __LINE__) -static OPUS_INLINE int MULT16_16_(int a, int b, char *file, int line) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); +static OPUS_INLINE int MULT16_16_(int a, int b, char *file, int line) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - if (!VERIFY_INT(res)) { - fprintf(stderr, "MULT16_16: output is not int: %d in %s: line %d\n", (int)res, file, line); + } + res = ((opus_int64)a)*b; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT16_16: output is not int: %d in %s: line %d\n", (int)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips++; - return res; + } + celt_mips++; + return res; } #define MAC16_16(c,a,b) (celt_mips-=2,ADD32((c),MULT16_16((a),(b)))) #define MULT16_32_QX(a, b, Q) MULT16_32_QX_(a, b, Q, __FILE__, __LINE__) -static OPUS_INLINE int MULT16_32_QX_(int a, opus_int64 b, int Q, char *file, int line) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) { - fprintf(stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line); +static OPUS_INLINE int MULT16_32_QX_(int a, opus_int64 b, int Q, char *file, int line) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) + { + fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - if (ABS32(b) >= ((opus_val32)(1) << (15 + Q))) { - fprintf(stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line); + } + if (ABS32(b)>=((opus_int64)(1)<<(16+Q))) + { + fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = (((opus_int64)a) * (opus_int64)b) >> Q; - if (!VERIFY_INT(res)) { - fprintf(stderr, "MULT16_32_Q%d: output is not int: %d*%d=%d in %s: line %d\n", Q, (int)a, (int)b, (int)res, file, line); + } + res = (((opus_int64)a)*(opus_int64)b) >> Q; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT16_32_Q%d: output is not int: %d*%d=%d in %s: line %d\n", Q, (int)a, (int)b,(int)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - if (Q == 15) { - celt_mips += 3; - } else { - celt_mips += 4; - } - return res; + } + if (Q==15) + celt_mips+=3; + else + celt_mips+=4; + return res; } #define MULT16_32_PX(a, b, Q) MULT16_32_PX_(a, b, Q, __FILE__, __LINE__) -static OPUS_INLINE int MULT16_32_PX_(int a, opus_int64 b, int Q, char *file, int line) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) { - fprintf(stderr, "MULT16_32_P%d: inputs are not short+int: %d %d in %s: line %d\n\n", Q, (int)a, (int)b, file, line); +static OPUS_INLINE int MULT16_32_PX_(int a, opus_int64 b, int Q, char *file, int line) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) + { + fprintf (stderr, "MULT16_32_P%d: inputs are not short+int: %d %d in %s: line %d\n\n", Q, (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - if (ABS32(b) >= ((opus_int64)(1) << (15 + Q))) { - fprintf(stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n\n", Q, (int)a, (int)b, file, line); + } + if (ABS32(b)>=((opus_int64)(1)<<(16+Q))) + { + fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n\n", Q, (int)a, (int)b,file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((((opus_int64)a) * (opus_int64)b) + (((opus_val32)(1) << Q) >> 1)) >> Q; - if (!VERIFY_INT(res)) { - fprintf(stderr, "MULT16_32_P%d: output is not int: %d*%d=%d in %s: line %d\n\n", Q, (int)a, (int)b, (int)res, file, line); + } + res = ((((opus_int64)a)*(opus_int64)b) + (((opus_val32)(1)<>1))>> Q; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT16_32_P%d: output is not int: %d*%d=%d in %s: line %d\n\n", Q, (int)a, (int)b,(int)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - if (Q == 15) { - celt_mips += 4; - } else { - celt_mips += 5; - } - return res; + } + if (Q==15) + celt_mips+=4; + else + celt_mips+=5; + return res; } #define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15) #define MAC16_32_Q15(c,a,b) (celt_mips-=2,ADD32((c),MULT16_32_Q15((a),(b)))) #define MAC16_32_Q16(c,a,b) (celt_mips-=2,ADD32((c),MULT16_32_Q16((a),(b)))) -static OPUS_INLINE int SATURATE(int a, int b) { - if (a > b) { - a = b; - } - if (a < -b) { - a = -b; - } - celt_mips += 3; - return a; +static OPUS_INLINE int SATURATE(int a, int b) +{ + if (a>b) + a=b; + if (a<-b) + a = -b; + celt_mips+=3; + return a; } -static OPUS_INLINE opus_int16 SATURATE16(opus_int32 a) { - celt_mips += 3; - if (a > 32767) { - return 32767; - } else if (a < -32768) { - return -32768; - } else { - return a; - } +static OPUS_INLINE opus_int16 SATURATE16(opus_int32 a) +{ + celt_mips+=3; + if (a>32767) + return 32767; + else if (a<-32768) + return -32768; + else return a; } -static OPUS_INLINE int MULT16_16_Q11_32(int a, int b) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16_Q11: inputs are not short: %d %d\n", a, b); +static OPUS_INLINE int MULT16_16_Q11_32(int a, int b) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16_Q11: inputs are not short: %d %d\n", a, b); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - res >>= 11; - if (!VERIFY_INT(res)) { - fprintf(stderr, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a, (int)b, (int)res); + } + res = ((opus_int64)a)*b; + res >>= 11; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a, (int)b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 3; - return res; + } + celt_mips+=3; + return res; } -static OPUS_INLINE short MULT16_16_Q13(int a, int b) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16_Q13: inputs are not short: %d %d\n", a, b); +static OPUS_INLINE short MULT16_16_Q13(int a, int b) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16_Q13: inputs are not short: %d %d\n", a, b); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - res >>= 13; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a, b, (int)res); + } + res = ((opus_int64)a)*b; + res >>= 13; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a, b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 3; - return res; + } + celt_mips+=3; + return res; } -static OPUS_INLINE short MULT16_16_Q14(int a, int b) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16_Q14: inputs are not short: %d %d\n", a, b); +static OPUS_INLINE short MULT16_16_Q14(int a, int b) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16_Q14: inputs are not short: %d %d\n", a, b); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - res >>= 14; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res); + } + res = ((opus_int64)a)*b; + res >>= 14; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 3; - return res; + } + celt_mips+=3; + return res; } #define MULT16_16_Q15(a, b) MULT16_16_Q15_(a, b, __FILE__, __LINE__) -static OPUS_INLINE short MULT16_16_Q15_(int a, int b, char *file, int line) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); +static OPUS_INLINE short MULT16_16_Q15_(int a, int b, char *file, int line) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - res >>= 15; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n", (int)res, file, line); + } + res = ((opus_int64)a)*b; + res >>= 15; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n", (int)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 1; - return res; + } + celt_mips+=1; + return res; } -static OPUS_INLINE short MULT16_16_P13(int a, int b) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16_P13: inputs are not short: %d %d\n", a, b); +static OPUS_INLINE short MULT16_16_P13(int a, int b) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16_P13: inputs are not short: %d %d\n", a, b); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - res += 4096; - if (!VERIFY_INT(res)) { - fprintf(stderr, "MULT16_16_P13: overflow: %d*%d=%d\n", a, b, (int)res); + } + res = ((opus_int64)a)*b; + res += 4096; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT16_16_P13: overflow: %d*%d=%d\n", a, b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res >>= 13; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (int)res); + } + res >>= 13; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 4; - return res; + } + celt_mips+=4; + return res; } -static OPUS_INLINE short MULT16_16_P14(int a, int b) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16_P14: inputs are not short: %d %d\n", a, b); +static OPUS_INLINE short MULT16_16_P14(int a, int b) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16_P14: inputs are not short: %d %d\n", a, b); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - res += 8192; - if (!VERIFY_INT(res)) { - fprintf(stderr, "MULT16_16_P14: overflow: %d*%d=%d\n", a, b, (int)res); + } + res = ((opus_int64)a)*b; + res += 8192; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT16_16_P14: overflow: %d*%d=%d\n", a, b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res >>= 14; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res); + } + res >>= 14; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 4; - return res; + } + celt_mips+=4; + return res; } -static OPUS_INLINE short MULT16_16_P15(int a, int b) { - opus_int64 res; - if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "MULT16_16_P15: inputs are not short: %d %d\n", a, b); +static OPUS_INLINE short MULT16_16_P15(int a, int b) +{ + opus_int64 res; + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "MULT16_16_P15: inputs are not short: %d %d\n", a, b); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = ((opus_int64)a) * b; - res += 16384; - if (!VERIFY_INT(res)) { - fprintf(stderr, "MULT16_16_P15: overflow: %d*%d=%d\n", a, b, (int)res); + } + res = ((opus_int64)a)*b; + res += 16384; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "MULT16_16_P15: overflow: %d*%d=%d\n", a, b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res >>= 15; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "MULT16_16_P15: output is not short: %d*%d=%d\n", a, b, (int)res); + } + res >>= 15; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "MULT16_16_P15: output is not short: %d*%d=%d\n", a, b, (int)res); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 2; - return res; + } + celt_mips+=2; + return res; } #define DIV32_16(a, b) DIV32_16_(a, b, __FILE__, __LINE__) -static OPUS_INLINE int DIV32_16_(opus_int64 a, opus_int64 b, char *file, int line) { - opus_int64 res; - if (b == 0) { - fprintf(stderr, "DIV32_16: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line); +static OPUS_INLINE int DIV32_16_(opus_int64 a, opus_int64 b, char *file, int line) +{ + opus_int64 res; + if (b==0) + { + fprintf(stderr, "DIV32_16: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - return 0; - } - if (!VERIFY_INT(a) || !VERIFY_SHORT(b)) { - fprintf(stderr, "DIV32_16: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line); + return 0; + } + if (!VERIFY_INT(a) || !VERIFY_SHORT(b)) + { + fprintf (stderr, "DIV32_16: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a / b; - if (!VERIFY_SHORT(res)) { - fprintf(stderr, "DIV32_16: output is not short: %d / %d = %d in %s: line %d\n", (int)a, (int)b, (int)res, file, line); - if (res > 32767) { - res = 32767; - } - if (res < -32768) { - res = -32768; - } + } + res = a/b; + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "DIV32_16: output is not short: %d / %d = %d in %s: line %d\n", (int)a,(int)b,(int)res, file, line); + if (res>32767) + res = 32767; + if (res<-32768) + res = -32768; #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 35; - return res; + } + celt_mips+=35; + return res; } #define DIV32(a, b) DIV32_(a, b, __FILE__, __LINE__) -static OPUS_INLINE int DIV32_(opus_int64 a, opus_int64 b, char *file, int line) { - opus_int64 res; - if (b == 0) { - fprintf(stderr, "DIV32: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line); +static OPUS_INLINE int DIV32_(opus_int64 a, opus_int64 b, char *file, int line) +{ + opus_int64 res; + if (b==0) + { + fprintf(stderr, "DIV32: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - return 0; - } + return 0; + } - if (!VERIFY_INT(a) || !VERIFY_INT(b)) { - fprintf(stderr, "DIV32: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line); + if (!VERIFY_INT(a) || !VERIFY_INT(b)) + { + fprintf (stderr, "DIV32: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - res = a / b; - if (!VERIFY_INT(res)) { - fprintf(stderr, "DIV32: output is not int: %d in %s: line %d\n", (int)res, file, line); + } + res = a/b; + if (!VERIFY_INT(res)) + { + fprintf (stderr, "DIV32: output is not int: %d in %s: line %d\n", (int)res, file, line); #ifdef FIXED_DEBUG_ASSERT - celt_assert(0); + celt_assert(0); #endif - } - celt_mips += 70; - return res; + } + celt_mips+=70; + return res; } -static OPUS_INLINE opus_val16 SIG2WORD16_generic(celt_sig x) { - x = PSHR32(x, SIG_SHIFT); - x = MAX32(x, -32768); - x = MIN32(x, 32767); - return EXTRACT16(x); +static OPUS_INLINE opus_val16 SIG2WORD16_generic(celt_sig x) +{ + x = PSHR32(x, SIG_SHIFT); + x = MAX32(x, -32768); + x = MIN32(x, 32767); + return EXTRACT16(x); } #define SIG2WORD16(x) (SIG2WORD16_generic(x)) #undef PRINT_MIPS -#define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", celt_mips);} while (0); +#define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", (unsigned long long)celt_mips);} while (0); #endif diff --git a/src/libopus/celt/fixed_generic.h b/src/libopus/celt/fixed_generic.h index e425c4e..8f29d46 100644 --- a/src/libopus/celt/fixed_generic.h +++ b/src/libopus/celt/fixed_generic.h @@ -1,33 +1,33 @@ -/* Copyright (C) 2007-2009 Xiph.Org Foundation - Copyright (C) 2003-2008 Jean-Marc Valin - Copyright (C) 2007-2008 CSIRO */ +/* Copyright (C) 2007-2009 Xiph.Org Foundation + Copyright (C) 2003-2008 Jean-Marc Valin + Copyright (C) 2007-2008 CSIRO */ /** - @file fixed_generic.h - @brief Generic fixed-point operations + @file fixed_generic.h + @brief Generic fixed-point operations */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FIXED_GENERIC_H @@ -57,6 +57,13 @@ #define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),((b)&0x0000ffff)),15)) #endif +/** 32x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */ +#if OPUS_FAST_INT64 +#define MULT32_32_Q16(a,b) ((opus_val32)SHR((opus_int64)(a)*(opus_int64)(b),16)) +#else +#define MULT32_32_Q16(a,b) (ADD32(ADD32(ADD32((opus_val32)(SHR32(((opus_uint32)((a)&0x0000ffff)*(opus_uint32)((b)&0x0000ffff)),16)), MULT16_16SU(SHR32(a,16),((b)&0x0000ffff))), MULT16_16SU(SHR32(b,16),((a)&0x0000ffff))), SHL32(MULT16_16(SHR32(a,16),SHR32(b,16)),16))) +#endif + /** 32x32 multiplication, followed by a 31-bit shift right. Results fits in 32 bits */ #if OPUS_FAST_INT64 #define MULT32_32_Q31(a,b) ((opus_val32)SHR((opus_int64)(a)*(opus_int64)(b),31)) @@ -102,9 +109,9 @@ #define SATURATE16(x) (EXTRACT16((x)>32767 ? 32767 : (x)<-32768 ? -32768 : (x))) -/** Shift by a and round-to-neareast 32-bit value. Result is a 16-bit value */ +/** Shift by a and round-to-nearest 32-bit value. Result is a 16-bit value */ #define ROUND16(x,a) (EXTRACT16(PSHR32((x),(a)))) -/** Shift by a and round-to-neareast 32-bit value. Result is a saturated 16-bit value */ +/** Shift by a and round-to-nearest 32-bit value. Result is a saturated 16-bit value */ #define SROUND16(x,a) EXTRACT16(SATURATE(PSHR32(x,a), 32767)); /** Divide by two */ @@ -131,6 +138,9 @@ /** 16x16 multiplication where the result fits in 16 bits */ #define MULT16_16_16(a,b) ((((opus_val16)(a))*((opus_val16)(b)))) +/** 32x32 multiplication where the result fits in 32 bits */ +#define MULT32_32_32(a,b) ((((opus_val32)(a))*((opus_val32)(b)))) + /* (opus_val32)(opus_val16) gives TI compiler a hint that it's 16x16->32 multiply */ /** 16x16 multiplication where the result fits in 32 bits */ #define MULT16_16(a,b) (((opus_val32)(opus_val16)(a))*((opus_val32)(opus_val16)(b))) @@ -166,11 +176,12 @@ #include "mips/fixed_generic_mipsr1.h" #endif -static OPUS_INLINE opus_val16 SIG2WORD16_generic(celt_sig x) { - x = PSHR32(x, SIG_SHIFT); - x = MAX32(x, -32768); - x = MIN32(x, 32767); - return EXTRACT16(x); +static OPUS_INLINE opus_val16 SIG2WORD16_generic(celt_sig x) +{ + x = PSHR32(x, SIG_SHIFT); + x = MAX32(x, -32768); + x = MIN32(x, 32767); + return EXTRACT16(x); } #define SIG2WORD16(x) (SIG2WORD16_generic(x)) diff --git a/src/libopus/celt/float_cast.h b/src/libopus/celt/float_cast.h index e1ca639..8915a5f 100644 --- a/src/libopus/celt/float_cast.h +++ b/src/libopus/celt/float_cast.h @@ -1,27 +1,27 @@ /* Copyright (C) 2001 Erik de Castro Lopo */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Version 1.1 */ @@ -32,7 +32,7 @@ #include "arch.h" -/* ============================================================================ +/*============================================================================ ** On Intel Pentium processors (especially PIII and probably P4), converting ** from float to int is very slow. To meet the C specs, the code produced by ** most C compilers targeting Pentium needs to change the FPU rounding mode @@ -58,18 +58,48 @@ /* The presence of the required functions are detected during the configure ** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in -** the ../config.h file. +** the config.h file. */ /* With GCC, when SSE is available, the fastest conversion is cvtss2si. */ #if defined(__GNUC__) && defined(__SSE__) #include -static OPUS_INLINE opus_int32 float2int(float x) { - return _mm_cvt_ss2si(_mm_set_ss(x)); -} +static OPUS_INLINE opus_int32 float2int(float x) {return _mm_cvt_ss2si(_mm_set_ss(x));} -#elif defined(HAVE_LRINTF) +#elif (defined(_MSC_VER) && _MSC_VER >= 1400) && (defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 1)) + + #include + static OPUS_INLINE opus_int32 float2int(float value) + { + /* _mm_load_ss will generate same code as _mm_set_ss + ** in _MSC_VER >= 1914 /02 so keep __mm_load__ss + ** for backward compatibility. + */ + return _mm_cvtss_si32(_mm_load_ss(&value)); + } + +#elif (defined(_MSC_VER) && _MSC_VER >= 1400) && defined (_M_IX86) + + #include + + /* Win32 doesn't seem to have these functions. + ** Therefore implement OPUS_INLINE versions of these functions here. + */ + + static OPUS_INLINE opus_int32 + float2int (float flt) + { int intgr; + + _asm + { fld flt + fistp intgr + } ; + + return intgr ; + } + +#elif defined(HAVE_LRINTF) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* These defines enable functionality introduced with the 1999 ISO C ** standard. They must be defined before the inclusion of math.h to @@ -87,7 +117,7 @@ static OPUS_INLINE opus_int32 float2int(float x) { #include #define float2int(x) lrintf(x) -#elif (defined(HAVE_LRINT)) +#elif defined(HAVE_LRINT) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define _ISOC9X_SOURCE 1 #define _ISOC99_SOURCE 1 @@ -98,48 +128,24 @@ static OPUS_INLINE opus_int32 float2int(float x) { #include #define float2int(x) lrint(x) -#elif (defined(_MSC_VER) && _MSC_VER >= 1400) && (defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 1)) -#include - -static __inline long int float2int(float value) { - return _mm_cvtss_si32(_mm_load_ss(&value)); -} -#elif (defined(_MSC_VER) && _MSC_VER >= 1400) && defined (_M_IX86) -#include - -/* Win32 doesn't seem to have these functions. -** Therefore implement OPUS_INLINE versions of these functions here. -*/ - -static __inline long int -float2int(float flt) { - int intgr; - - _asm { - fld flt - fistp intgr - } ; - - return intgr ; -} - #else #if (defined(__GNUC__) && defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) -/* supported by gcc in C99 mode, but not by all other compilers */ -#warning "Don't have the functions lrint() and lrintf ()." -#warning "Replacing these functions with a standard C cast." + /* supported by gcc in C99 mode, but not by all other compilers */ + #warning "Don't have the functions lrint() and lrintf ()." + #warning "Replacing these functions with a standard C cast." #endif /* __STDC_VERSION__ >= 199901L */ -#include -#define float2int(flt) ((int)(floor(.5+flt))) + #include + #define float2int(flt) ((int)(floor(.5+flt))) #endif #ifndef DISABLE_FLOAT_API -static OPUS_INLINE opus_int16 FLOAT2INT16(float x) { - x = x * CELT_SIG_SCALE; - x = MAX32(x, -32768); - x = MIN32(x, 32767); - return (opus_int16)float2int(x); +static OPUS_INLINE opus_int16 FLOAT2INT16(float x) +{ + x = x*CELT_SIG_SCALE; + x = MAX32(x, -32768); + x = MIN32(x, 32767); + return (opus_int16)float2int(x); } #endif /* DISABLE_FLOAT_API */ diff --git a/src/libopus/celt/kiss_fft.c b/src/libopus/celt/kiss_fft.c index 2d9ea99..2df0314 100644 --- a/src/libopus/celt/kiss_fft.c +++ b/src/libopus/celt/kiss_fft.c @@ -1,38 +1,38 @@ -/* Copyright (c) 2003-2004, Mark Borgerding - Lots of modifications by Jean-Marc Valin - Copyright (c) 2005-2007, Xiph.Org Foundation - Copyright (c) 2008, Xiph.Org Foundation, CSIRO +/*Copyright (c) 2003-2004, Mark Borgerding + Lots of modifications by Jean-Marc Valin + Copyright (c) 2005-2007, Xiph.Org Foundation + Copyright (c) 2008, Xiph.Org Foundation, CSIRO - All rights reserved. + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE.*/ + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE.*/ -/* This code is originally from Mark Borgerding's KISS-FFT but has been - heavily modified to better suit Opus */ +/* This code is originally from Mark Borgerding's KISS-FFT but has been + heavily modified to better suit Opus */ #ifndef SKIP_CONFIG_H -//# ifdef HAVE_CONFIG_H -# include "../config.h" -//# endif +# ifdef __STDC__ +# include "config.h" +# endif #endif #include "_kiss_fft_guts.h" @@ -41,257 +41,270 @@ #include "mathops.h" #include "stack_alloc.h" -/* The guts header contains all the multiplication and addition macros that are defined for - complex numbers. It also delares the kf_ internal functions. +/* The guts header contains all the multiplication and addition macros that are defined for + complex numbers. It also delares the kf_ internal functions. */ static void kf_bfly2( - kiss_fft_cpx * Fout, - int m, - int N -) { - kiss_fft_cpx * Fout2; - int i; - (void)m; + kiss_fft_cpx * Fout, + int m, + int N + ) +{ + kiss_fft_cpx * Fout2; + int i; + (void)m; #ifdef CUSTOM_MODES - if (m == 1) { - celt_assert(m == 1); - for (i = 0; i < N; i++) { - kiss_fft_cpx t; - Fout2 = Fout + 1; - t = *Fout2; - C_SUB(*Fout2, *Fout, t); - C_ADDTO(*Fout, t); - Fout += 2; - } - } else + if (m==1) + { + celt_assert(m==1); + for (i=0;itwiddles; - /* m is guaranteed to be a multiple of 4. */ - for (j = 0; j < m; j++) { - C_MUL(scratch[0], Fout[m], *tw1); - C_MUL(scratch[1], Fout[m2], *tw2); - C_MUL(scratch[2], Fout[m3], *tw3); + Fout[1].r = ADD32_ovflw(scratch0.r, scratch1.i); + Fout[1].i = SUB32_ovflw(scratch0.i, scratch1.r); + Fout[3].r = SUB32_ovflw(scratch0.r, scratch1.i); + Fout[3].i = ADD32_ovflw(scratch0.i, scratch1.r); + Fout+=4; + } + } else { + int j; + kiss_fft_cpx scratch[6]; + const kiss_twiddle_cpx *tw1,*tw2,*tw3; + const int m2=2*m; + const int m3=3*m; + kiss_fft_cpx * Fout_beg = Fout; + for (i=0;itwiddles; + /* m is guaranteed to be a multiple of 4. */ + for (j=0;jtwiddles[fstride * m]; + epi3 = st->twiddles[fstride*m]; #endif - for (i = 0; i < N; i++) { - Fout = Fout_beg + i * mm; - tw1 = tw2 = st->twiddles; - /* For non-custom modes, m is guaranteed to be a multiple of 4. */ - k = m; - do { + for (i=0;itwiddles; + /* For non-custom modes, m is guaranteed to be a multiple of 4. */ + k=m; + do { - C_MUL(scratch[1], Fout[m], *tw1); - C_MUL(scratch[2], Fout[m2], *tw2); + C_MUL(scratch[1],Fout[m] , *tw1); + C_MUL(scratch[2],Fout[m2] , *tw2); - C_ADD(scratch[3], scratch[1], scratch[2]); - C_SUB(scratch[0], scratch[1], scratch[2]); - tw1 += fstride; - tw2 += fstride * 2; + C_ADD(scratch[3],scratch[1],scratch[2]); + C_SUB(scratch[0],scratch[1],scratch[2]); + tw1 += fstride; + tw2 += fstride*2; - Fout[m].r = SUB32_ovflw(Fout->r, HALF_OF(scratch[3].r)); - Fout[m].i = SUB32_ovflw(Fout->i, HALF_OF(scratch[3].i)); + Fout[m].r = SUB32_ovflw(Fout->r, HALF_OF(scratch[3].r)); + Fout[m].i = SUB32_ovflw(Fout->i, HALF_OF(scratch[3].i)); - C_MULBYSCALAR(scratch[0], epi3.i); + C_MULBYSCALAR( scratch[0] , epi3.i ); - C_ADDTO(*Fout, scratch[3]); + C_ADDTO(*Fout,scratch[3]); - Fout[m2].r = ADD32_ovflw(Fout[m].r, scratch[0].i); - Fout[m2].i = SUB32_ovflw(Fout[m].i, scratch[0].r); + Fout[m2].r = ADD32_ovflw(Fout[m].r, scratch[0].i); + Fout[m2].i = SUB32_ovflw(Fout[m].i, scratch[0].r); - Fout[m].r = SUB32_ovflw(Fout[m].r, scratch[0].i); - Fout[m].i = ADD32_ovflw(Fout[m].i, scratch[0].r); + Fout[m].r = SUB32_ovflw(Fout[m].r, scratch[0].i); + Fout[m].i = ADD32_ovflw(Fout[m].i, scratch[0].r); - ++Fout; - } while (--k); - } + ++Fout; + } while(--k); + } } #ifndef OVERRIDE_kf_bfly5 static void kf_bfly5( - kiss_fft_cpx * Fout, - const size_t fstride, - const kiss_fft_state *st, - int m, - int N, - int mm -) { - kiss_fft_cpx *Fout0, *Fout1, *Fout2, *Fout3, *Fout4; - int i, u; - kiss_fft_cpx scratch[13]; - const kiss_twiddle_cpx *tw; - kiss_twiddle_cpx ya, yb; - kiss_fft_cpx * Fout_beg = Fout; + kiss_fft_cpx * Fout, + const size_t fstride, + const kiss_fft_state *st, + int m, + int N, + int mm + ) +{ + kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4; + int i, u; + kiss_fft_cpx scratch[13]; + const kiss_twiddle_cpx *tw; + kiss_twiddle_cpx ya,yb; + kiss_fft_cpx * Fout_beg = Fout; #ifdef FIXED_POINT - ya.r = 10126; - ya.i = -31164; - yb.r = -26510; - yb.i = -19261; + ya.r = 10126; + ya.i = -31164; + yb.r = -26510; + yb.i = -19261; #else - ya = st->twiddles[fstride * m]; - yb = st->twiddles[fstride * 2 * m]; + ya = st->twiddles[fstride*m]; + yb = st->twiddles[fstride*2*m]; #endif - tw = st->twiddles; + tw=st->twiddles; - for (i = 0; i < N; i++) { - Fout = Fout_beg + i * mm; - Fout0 = Fout; - Fout1 = Fout0 + m; - Fout2 = Fout0 + 2 * m; - Fout3 = Fout0 + 3 * m; - Fout4 = Fout0 + 4 * m; + for (i=0;ir = ADD32_ovflw(Fout0->r, ADD32_ovflw(scratch[7].r, scratch[8].r)); - Fout0->i = ADD32_ovflw(Fout0->i, ADD32_ovflw(scratch[7].i, scratch[8].i)); + Fout0->r = ADD32_ovflw(Fout0->r, ADD32_ovflw(scratch[7].r, scratch[8].r)); + Fout0->i = ADD32_ovflw(Fout0->i, ADD32_ovflw(scratch[7].i, scratch[8].i)); - scratch[5].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r, ya.r), S_MUL(scratch[8].r, yb.r))); - scratch[5].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i, ya.r), S_MUL(scratch[8].i, yb.r))); + scratch[5].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,ya.r), S_MUL(scratch[8].r,yb.r))); + scratch[5].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,ya.r), S_MUL(scratch[8].i,yb.r))); - scratch[6].r = ADD32_ovflw(S_MUL(scratch[10].i, ya.i), S_MUL(scratch[9].i, yb.i)); - scratch[6].i = NEG32_ovflw(ADD32_ovflw(S_MUL(scratch[10].r, ya.i), S_MUL(scratch[9].r, yb.i))); + scratch[6].r = ADD32_ovflw(S_MUL(scratch[10].i,ya.i), S_MUL(scratch[9].i,yb.i)); + scratch[6].i = NEG32_ovflw(ADD32_ovflw(S_MUL(scratch[10].r,ya.i), S_MUL(scratch[9].r,yb.i))); - C_SUB(*Fout1, scratch[5], scratch[6]); - C_ADD(*Fout4, scratch[5], scratch[6]); + C_SUB(*Fout1,scratch[5],scratch[6]); + C_ADD(*Fout4,scratch[5],scratch[6]); - scratch[11].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r, yb.r), S_MUL(scratch[8].r, ya.r))); - scratch[11].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i, yb.r), S_MUL(scratch[8].i, ya.r))); - scratch[12].r = SUB32_ovflw(S_MUL(scratch[9].i, ya.i), S_MUL(scratch[10].i, yb.i)); - scratch[12].i = SUB32_ovflw(S_MUL(scratch[10].r, yb.i), S_MUL(scratch[9].r, ya.i)); + scratch[11].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,yb.r), S_MUL(scratch[8].r,ya.r))); + scratch[11].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,yb.r), S_MUL(scratch[8].i,ya.r))); + scratch[12].r = SUB32_ovflw(S_MUL(scratch[9].i,ya.i), S_MUL(scratch[10].i,yb.i)); + scratch[12].i = SUB32_ovflw(S_MUL(scratch[10].r,yb.i), S_MUL(scratch[9].r,ya.i)); - C_ADD(*Fout2, scratch[11], scratch[12]); - C_SUB(*Fout3, scratch[11], scratch[12]); + C_ADD(*Fout2,scratch[11],scratch[12]); + C_SUB(*Fout3,scratch[11],scratch[12]); - ++Fout0; ++Fout1; ++Fout2; ++Fout3; ++Fout4; - } - } + ++Fout0;++Fout1;++Fout2;++Fout3;++Fout4; + } + } } #endif /* OVERRIDE_kf_bfly5 */ @@ -303,31 +316,35 @@ static void kf_bfly5( static void compute_bitrev_table( - int Fout, - opus_int16 *f, - const size_t fstride, - int in_stride, - opus_int16 * factors, - const kiss_fft_state *st -) { - const int p = *factors++; /* the radix */ - const int m = *factors++; /* stage's fft length/p */ + int Fout, + opus_int16 *f, + const size_t fstride, + int in_stride, + opus_int16 * factors, + const kiss_fft_state *st + ) +{ + const int p=*factors++; /* the radix */ + const int m=*factors++; /* stage's fft length/p */ /*printf ("fft %d %d %d %d %d %d\n", p*m, m, p, s2, fstride*in_stride, N);*/ - if (m == 1) { - int j; - for (j = 0; j < p; j++) { - *f = Fout + j; - f += fstride * in_stride; - } - } else { - int j; - for (j = 0; j < p; j++) { - compute_bitrev_table(Fout, f, fstride * p, in_stride, factors, st); - f += fstride * in_stride; - Fout += m; - } - } + if (m==1) + { + int j; + for (j=0;j 32000 || (opus_int32)p * (opus_int32)p > n) { - p = n; /* no more factors, skip to end */ + case 4: p = 2; break; + case 2: p = 3; break; + default: p += 2; break; } + if (p>32000 || (opus_int32)p*(opus_int32)p > n) + p = n; /* no more factors, skip to end */ } n /= p; #ifdef RADIX_TWO_ONLY - if (p != 2 && p != 4) + if (p!=2 && p != 4) #else - if (p > 5) + if (p>5) #endif { - return 0; + return 0; } - facbuf[2 * stages] = p; - if (p == 2 && stages > 1) { - facbuf[2 * stages] = 4; - facbuf[2] = 2; + facbuf[2*stages] = p; + if (p==2 && stages > 1) + { + facbuf[2*stages] = 4; + facbuf[2] = 2; } stages++; } while (n > 1); n = nbak; - /* Reverse the order to get the radix 4 at the end, so we can use the - fast degenerate case. It turns out that reversing the order also - improves the noise behaviour. */ - for (i = 0; i < stages / 2; i++) { - int tmp; - tmp = facbuf[2 * i]; - facbuf[2 * i] = facbuf[2 * (stages - i - 1)]; - facbuf[2 * (stages - i - 1)] = tmp; + /* Reverse the order to get the radix 4 at the end, so we can use the + fast degenerate case. It turns out that reversing the order also + improves the noise behaviour. */ + for (i=0;i= memneeded) { + if ( lenmem==NULL ) { + st = ( kiss_fft_state*)KISS_FFT_MALLOC( memneeded ); + }else{ + if (mem != NULL && *lenmem >= memneeded) st = (kiss_fft_state*)mem; - } *lenmem = memneeded; } if (st) { opus_int16 *bitrev; kiss_twiddle_cpx *twiddles; - st->nfft = nfft; + st->nfft=nfft; #ifdef FIXED_POINT st->scale_shift = celt_ilog2(st->nfft); - if (st->nfft == 1 << st->scale_shift) { - st->scale = Q15ONE; - } else { - st->scale = (1073741824 + st->nfft / 2) / st->nfft >> (15 - st->scale_shift); - } + if (st->nfft == 1<scale_shift) + st->scale = Q15ONE; + else + st->scale = (1073741824+st->nfft/2)/st->nfft>>(15-st->scale_shift); #else - st->scale = 1.f / nfft; + st->scale = 1.f/nfft; #endif - if (base != NULL) { - st->twiddles = base->twiddles; - st->shift = 0; - while (st->shift < 32 && nfft << st->shift != base->nfft) { - st->shift++; - } - if (st->shift >= 32) { - goto fail; - } + if (base != NULL) + { + st->twiddles = base->twiddles; + st->shift = 0; + while (st->shift < 32 && nfft<shift != base->nfft) + st->shift++; + if (st->shift>=32) + goto fail; } else { - st->twiddles = twiddles = (kiss_twiddle_cpx*)KISS_FFT_MALLOC(sizeof(kiss_twiddle_cpx) * nfft); - compute_twiddles(twiddles, nfft); - st->shift = -1; + st->twiddles = twiddles = (kiss_twiddle_cpx*)KISS_FFT_MALLOC(sizeof(kiss_twiddle_cpx)*nfft); + compute_twiddles(twiddles, nfft); + st->shift = -1; } - if (!kf_factor(nfft, st->factors)) { - goto fail; + if (!kf_factor(nfft,st->factors)) + { + goto fail; } /* bitrev */ - st->bitrev = bitrev = (opus_int16*)KISS_FFT_MALLOC(sizeof(opus_int16) * nfft); - if (st->bitrev == NULL) { + st->bitrev = bitrev = (opus_int16*)KISS_FFT_MALLOC(sizeof(opus_int16)*nfft); + if (st->bitrev==NULL) goto fail; - } - compute_bitrev_table(0, bitrev, 1, 1, st->factors, st); + compute_bitrev_table(0, bitrev, 1,1, st->factors,st); /* Initialize architecture specific fft parameters */ - if (opus_fft_alloc_arch(st, arch)) { + if (opus_fft_alloc_arch(st, arch)) goto fail; - } } return st; fail: @@ -477,28 +495,31 @@ fail: return NULL; } -kiss_fft_state *opus_fft_alloc(int nfft, void * mem, size_t * lenmem, int arch) { - return opus_fft_alloc_twiddles(nfft, mem, lenmem, NULL, arch); +kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem, int arch) +{ + return opus_fft_alloc_twiddles(nfft, mem, lenmem, NULL, arch); } void opus_fft_free_arch_c(kiss_fft_state *st) { - (void)st; + (void)st; } -void opus_fft_free(const kiss_fft_state *cfg, int arch) { - if (cfg) { - opus_fft_free_arch((kiss_fft_state *)cfg, arch); - opus_free((opus_int16*)cfg->bitrev); - if (cfg->shift < 0) { - opus_free((kiss_twiddle_cpx*)cfg->twiddles); - } - opus_free((kiss_fft_state*)cfg); - } +void opus_fft_free(const kiss_fft_state *cfg, int arch) +{ + if (cfg) + { + opus_fft_free_arch((kiss_fft_state *)cfg, arch); + opus_free((opus_int16*)cfg->bitrev); + if (cfg->shift < 0) + opus_free((kiss_twiddle_cpx*)cfg->twiddles); + opus_free((kiss_fft_state*)cfg); + } } #endif /* CUSTOM_MODES */ -void opus_fft_impl(const kiss_fft_state *st, kiss_fft_cpx *fout) { +void opus_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout) +{ int m2, m; int p; int L; @@ -507,76 +528,77 @@ void opus_fft_impl(const kiss_fft_state *st, kiss_fft_cpx *fout) { int shift; /* st->shift can be -1 */ - shift = st->shift > 0 ? st->shift : 0; + shift = st->shift>0 ? st->shift : 0; fstride[0] = 1; - L = 0; + L=0; do { - p = st->factors[2 * L]; - m = st->factors[2 * L + 1]; - fstride[L + 1] = fstride[L] * p; - L++; - } while (m != 1); - m = st->factors[2 * L - 1]; - for (i = L - 1; i >= 0; i--) { - if (i != 0) { - m2 = st->factors[2 * i - 1]; - } else { - m2 = 1; - } - switch (st->factors[2 * i]) { - case 2: - kf_bfly2(fout, m, fstride[i]); - break; - case 4: - kf_bfly4(fout, fstride[i] << shift, st, m, fstride[i], m2); - break; -#ifndef RADIX_TWO_ONLY - case 3: - kf_bfly3(fout, fstride[i] << shift, st, m, fstride[i], m2); - break; - case 5: - kf_bfly5(fout, fstride[i] << shift, st, m, fstride[i], m2); - break; -#endif - } - m = m2; + p = st->factors[2*L]; + m = st->factors[2*L+1]; + fstride[L+1] = fstride[L]*p; + L++; + } while(m!=1); + m = st->factors[2*L-1]; + for (i=L-1;i>=0;i--) + { + if (i!=0) + m2 = st->factors[2*i-1]; + else + m2 = 1; + switch (st->factors[2*i]) + { + case 2: + kf_bfly2(fout, m, fstride[i]); + break; + case 4: + kf_bfly4(fout,fstride[i]<scale_shift - 1; + /* Allows us to scale with MULT16_32_Q16(), which is faster than + MULT16_32_Q15() on ARM. */ + int scale_shift = st->scale_shift-1; #endif - scale = st->scale; + scale = st->scale; - celt_assert2(fin != fout, "In-place FFT not supported"); - /* Bit-reverse the input */ - for (i = 0; i < st->nfft; i++) { - kiss_fft_cpx x = fin[i]; - fout[st->bitrev[i]].r = SHR32(MULT16_32_Q16(scale, x.r), scale_shift); - fout[st->bitrev[i]].i = SHR32(MULT16_32_Q16(scale, x.i), scale_shift); - } - opus_fft_impl(st, fout); + celt_assert2 (fin != fout, "In-place FFT not supported"); + /* Bit-reverse the input */ + for (i=0;infft;i++) + { + kiss_fft_cpx x = fin[i]; + fout[st->bitrev[i]].r = SHR32(MULT16_32_Q16(scale, x.r), scale_shift); + fout[st->bitrev[i]].i = SHR32(MULT16_32_Q16(scale, x.i), scale_shift); + } + opus_fft_impl(st, fout); } -void opus_ifft_c(const kiss_fft_state *st, const kiss_fft_cpx *fin, kiss_fft_cpx *fout) { - int i; - celt_assert2(fin != fout, "In-place FFT not supported"); - /* Bit-reverse the input */ - for (i = 0; i < st->nfft; i++) { - fout[st->bitrev[i]] = fin[i]; - } - for (i = 0; i < st->nfft; i++) { - fout[i].i = -fout[i].i; - } - opus_fft_impl(st, fout); - for (i = 0; i < st->nfft; i++) { - fout[i].i = -fout[i].i; - } +void opus_ifft_c(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout) +{ + int i; + celt_assert2 (fin != fout, "In-place FFT not supported"); + /* Bit-reverse the input */ + for (i=0;infft;i++) + fout[st->bitrev[i]] = fin[i]; + for (i=0;infft;i++) + fout[i].i = -fout[i].i; + opus_fft_impl(st, fout); + for (i=0;infft;i++) + fout[i].i = -fout[i].i; } diff --git a/src/libopus/celt/kiss_fft.h b/src/libopus/celt/kiss_fft.h index fac6d73..267f72f 100644 --- a/src/libopus/celt/kiss_fft.h +++ b/src/libopus/celt/kiss_fft.h @@ -1,30 +1,30 @@ -/* Copyright (c) 2003-2004, Mark Borgerding - Lots of modifications by Jean-Marc Valin - Copyright (c) 2005-2007, Xiph.Org Foundation - Copyright (c) 2008, Xiph.Org Foundation, CSIRO +/*Copyright (c) 2003-2004, Mark Borgerding + Lots of modifications by Jean-Marc Valin + Copyright (c) 2005-2007, Xiph.Org Foundation + Copyright (c) 2008, Xiph.Org Foundation, CSIRO - All rights reserved. + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE.*/ + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE.*/ #ifndef KISS_FFT_H #define KISS_FFT_H @@ -52,6 +52,10 @@ extern "C" { # define kiss_fft_scalar opus_int32 # define kiss_twiddle_scalar opus_int16 +/* Some 32-bit CPUs would load/store a kiss_twiddle_cpx with a single memory + * access, and could benefit from additional alignment. + */ +# define KISS_TWIDDLE_CPX_ALIGNMENT (sizeof(opus_int32)) #else # ifndef kiss_fft_scalar @@ -62,35 +66,41 @@ extern "C" { # endif #endif +#if defined(__GNUC__) && defined(KISS_TWIDDLE_CPX_ALIGNMENT) +#define KISS_TWIDDLE_CPX_ALIGNED __attribute__((aligned(KISS_TWIDDLE_CPX_ALIGNMENT))) +#else +#define KISS_TWIDDLE_CPX_ALIGNED +#endif + typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; -} kiss_fft_cpx; +}kiss_fft_cpx; typedef struct { - kiss_twiddle_scalar r; - kiss_twiddle_scalar i; -} kiss_twiddle_cpx; + kiss_twiddle_scalar r; + kiss_twiddle_scalar i; +} KISS_TWIDDLE_CPX_ALIGNED kiss_twiddle_cpx; #define MAXFACTORS 8 -/* e.g. an fft of length 128 has 4 factors - as far as kissfft is concerned - 4*4*4*2 -*/ +/* e.g. an fft of length 128 has 4 factors + as far as kissfft is concerned + 4*4*4*2 + */ -typedef struct arch_fft_state { - int is_supported; - void *priv; +typedef struct arch_fft_state{ + int is_supported; + void *priv; } arch_fft_state; -typedef struct kiss_fft_state { +typedef struct kiss_fft_state{ int nfft; opus_val16 scale; #ifdef FIXED_POINT int scale_shift; #endif int shift; - opus_int16 factors[2 * MAXFACTORS]; + opus_int16 factors[2*MAXFACTORS]; const opus_int16 *bitrev; const kiss_twiddle_cpx *twiddles; arch_fft_state *arch_fft; @@ -103,47 +113,47 @@ typedef struct kiss_fft_state { /*typedef struct kiss_fft_state* kiss_fft_cfg;*/ /** - opus_fft_alloc - - Initialize a FFT (or IFFT) algorithm's cfg/state buffer. - - typical usage: kiss_fft_cfg mycfg=opus_fft_alloc(1024,0,NULL,NULL); - - The return value from fft_alloc is a cfg buffer used internally - by the fft routine or NULL. - - If lenmem is NULL, then opus_fft_alloc will allocate a cfg buffer using malloc. - The returned value should be free()d when done to avoid memory leaks. - - The state can be placed in a user supplied buffer 'mem': - If lenmem is not NULL and mem is not NULL and *lenmem is large enough, - then the function places the cfg in mem and the size used in *lenmem - and returns mem. - - If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), - then the function returns NULL and places the minimum cfg - buffer size in *lenmem. + * opus_fft_alloc + * + * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. + * + * typical usage: kiss_fft_cfg mycfg=opus_fft_alloc(1024,0,NULL,NULL); + * + * The return value from fft_alloc is a cfg buffer used internally + * by the fft routine or NULL. + * + * If lenmem is NULL, then opus_fft_alloc will allocate a cfg buffer using malloc. + * The returned value should be free()d when done to avoid memory leaks. + * + * The state can be placed in a user supplied buffer 'mem': + * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, + * then the function places the cfg in mem and the size used in *lenmem + * and returns mem. + * + * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), + * then the function returns NULL and places the minimum cfg + * buffer size in *lenmem. * */ -kiss_fft_state *opus_fft_alloc_twiddles(int nfft, void * mem, size_t * lenmem, const kiss_fft_state *base, int arch); +kiss_fft_state *opus_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base, int arch); -kiss_fft_state *opus_fft_alloc(int nfft, void * mem, size_t * lenmem, int arch); +kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem, int arch); /** - opus_fft(cfg,in_out_buf) - - Perform an FFT on a complex input buffer. - for a forward FFT, - fin should be f[0] , f[1] , ... ,f[nfft-1] - fout will be F[0] , F[1] , ... ,F[nfft-1] - Note that each element is complex and can be accessed like + * opus_fft(cfg,in_out_buf) + * + * Perform an FFT on a complex input buffer. + * for a forward FFT, + * fin should be f[0] , f[1] , ... ,f[nfft-1] + * fout will be F[0] , F[1] , ... ,F[nfft-1] + * Note that each element is complex and can be accessed like f[k].r and f[k].i * */ -void opus_fft_c(const kiss_fft_state *cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout); -void opus_ifft_c(const kiss_fft_state *cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout); +void opus_fft_c(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); +void opus_ifft_c(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); -void opus_fft_impl(const kiss_fft_state *st, kiss_fft_cpx *fout); -void opus_ifft_impl(const kiss_fft_state *st, kiss_fft_cpx *fout); +void opus_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout); +void opus_ifft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout); void opus_fft_free(const kiss_fft_state *cfg, int arch); @@ -155,24 +165,24 @@ int opus_fft_alloc_arch_c(kiss_fft_state *st); /* Is run-time CPU detection enabled on this platform? */ #if defined(OPUS_HAVE_RTCD) && (defined(HAVE_ARM_NE10)) -extern int (*const OPUS_FFT_ALLOC_ARCH_IMPL[OPUS_ARCHMASK + 1])( - kiss_fft_state *st); +extern int (*const OPUS_FFT_ALLOC_ARCH_IMPL[OPUS_ARCHMASK+1])( + kiss_fft_state *st); #define opus_fft_alloc_arch(_st, arch) \ ((*OPUS_FFT_ALLOC_ARCH_IMPL[(arch)&OPUS_ARCHMASK])(_st)) -extern void (*const OPUS_FFT_FREE_ARCH_IMPL[OPUS_ARCHMASK + 1])( - kiss_fft_state *st); +extern void (*const OPUS_FFT_FREE_ARCH_IMPL[OPUS_ARCHMASK+1])( + kiss_fft_state *st); #define opus_fft_free_arch(_st, arch) \ ((*OPUS_FFT_FREE_ARCH_IMPL[(arch)&OPUS_ARCHMASK])(_st)) -extern void (*const OPUS_FFT[OPUS_ARCHMASK + 1])(const kiss_fft_state *cfg, - const kiss_fft_cpx *fin, kiss_fft_cpx *fout); +extern void (*const OPUS_FFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg, + const kiss_fft_cpx *fin, kiss_fft_cpx *fout); #define opus_fft(_cfg, _fin, _fout, arch) \ ((*OPUS_FFT[(arch)&OPUS_ARCHMASK])(_cfg, _fin, _fout)) -extern void (*const OPUS_IFFT[OPUS_ARCHMASK + 1])(const kiss_fft_state *cfg, - const kiss_fft_cpx *fin, kiss_fft_cpx *fout); +extern void (*const OPUS_IFFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg, + const kiss_fft_cpx *fin, kiss_fft_cpx *fout); #define opus_ifft(_cfg, _fin, _fout, arch) \ ((*OPUS_IFFT[(arch)&OPUS_ARCHMASK])(_cfg, _fin, _fout)) diff --git a/src/libopus/celt/laplace.c b/src/libopus/celt/laplace.c index 9c9c2b4..8c719a9 100644 --- a/src/libopus/celt/laplace.c +++ b/src/libopus/celt/laplace.c @@ -1,34 +1,34 @@ -/* Copyright (c) 2007 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "laplace.h" #include "mathops.h" @@ -36,89 +36,200 @@ /* The minimum probability of an energy delta (out of 32768). */ #define LAPLACE_LOG_MINP (0) #define LAPLACE_MINP (1<> 15; +static unsigned ec_laplace_get_freq1(unsigned fs0, int decay) +{ + unsigned ft; + ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN) - fs0; + return ft*(opus_int32)(16384-decay)>>15; } -void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay) { - unsigned fl; - int val = *value; - fl = 0; - if (val) { - int s; - int i; - s = -(val < 0); - val = (val + s)^s; - fl = fs; - fs = ec_laplace_get_freq1(fs, decay); - /* Search the decaying part of the PDF.*/ - for (i = 1; fs > 0 && i < val; i++) { - fs *= 2; - fl += fs + 2 * LAPLACE_MINP; - fs = (fs * (opus_int32)decay) >> 15; - } - /* Everything beyond that has probability LAPLACE_MINP. */ - if (!fs) { - int di; - int ndi_max; - ndi_max = (32768 - fl + LAPLACE_MINP - 1) >> LAPLACE_LOG_MINP; - ndi_max = (ndi_max - s) >> 1; - di = IMIN(val - i, ndi_max - 1); - fl += (2 * di + 1 + s) * LAPLACE_MINP; - fs = IMIN(LAPLACE_MINP, 32768 - fl); - *value = (i + di + s)^s; - } else { - fs += LAPLACE_MINP; - fl += fs & ~s; - } - celt_assert(fl + fs <= 32768); - celt_assert(fs > 0); - } - ec_encode_bin(enc, fl, fl + fs, 15); +void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay) +{ + unsigned fl; + int val = *value; + fl = 0; + if (val) + { + int s; + int i; + s = -(val<0); + val = (val+s)^s; + fl = fs; + fs = ec_laplace_get_freq1(fs, decay); + /* Search the decaying part of the PDF.*/ + for (i=1; fs > 0 && i < val; i++) + { + fs *= 2; + fl += fs+2*LAPLACE_MINP; + fs = (fs*(opus_int32)decay)>>15; + } + /* Everything beyond that has probability LAPLACE_MINP. */ + if (!fs) + { + int di; + int ndi_max; + ndi_max = (32768-fl+LAPLACE_MINP-1)>>LAPLACE_LOG_MINP; + ndi_max = (ndi_max-s)>>1; + di = IMIN(val - i, ndi_max - 1); + fl += (2*di+1+s)*LAPLACE_MINP; + fs = IMIN(LAPLACE_MINP, 32768-fl); + *value = (i+di+s)^s; + } + else + { + fs += LAPLACE_MINP; + fl += fs&~s; + } + celt_assert(fl+fs<=32768); + celt_assert(fs>0); + } + ec_encode_bin(enc, fl, fl+fs, 15); } -int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay) { - int val = 0; - unsigned fl; - unsigned fm; - fm = ec_decode_bin(dec, 15); - fl = 0; - if (fm >= fs) { - val++; - fl = fs; - fs = ec_laplace_get_freq1(fs, decay) + LAPLACE_MINP; - /* Search the decaying part of the PDF.*/ - while (fs > LAPLACE_MINP && fm >= fl + 2 * fs) { - fs *= 2; - fl += fs; - fs = ((fs - 2 * LAPLACE_MINP) * (opus_int32)decay) >> 15; - fs += LAPLACE_MINP; - val++; - } - /* Everything beyond that has probability LAPLACE_MINP. */ - if (fs <= LAPLACE_MINP) { - int di; - di = (fm - fl) >> (LAPLACE_LOG_MINP + 1); - val += di; - fl += 2 * di * LAPLACE_MINP; - } - if (fm < fl + fs) { - val = -val; - } else { - fl += fs; - } - } - celt_assert(fl < 32768); - celt_assert(fs > 0); - celt_assert(fl <= fm); - celt_assert(fm < IMIN(fl + fs, 32768)); - ec_dec_update(dec, fl, IMIN(fl + fs, 32768), 32768); - return val; +int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay) +{ + int val=0; + unsigned fl; + unsigned fm; + fm = ec_decode_bin(dec, 15); + fl = 0; + if (fm >= fs) + { + val++; + fl = fs; + fs = ec_laplace_get_freq1(fs, decay)+LAPLACE_MINP; + /* Search the decaying part of the PDF.*/ + while(fs > LAPLACE_MINP && fm >= fl+2*fs) + { + fs *= 2; + fl += fs; + fs = ((fs-2*LAPLACE_MINP)*(opus_int32)decay)>>15; + fs += LAPLACE_MINP; + val++; + } + /* Everything beyond that has probability LAPLACE_MINP. */ + if (fs <= LAPLACE_MINP) + { + int di; + di = (fm-fl)>>(LAPLACE_LOG_MINP+1); + val += di; + fl += 2*di*LAPLACE_MINP; + } + if (fm < fl+fs) + val = -val; + else + fl += fs; + } + celt_assert(fl<32768); + celt_assert(fs>0); + celt_assert(fl<=fm); + celt_assert(fm 0 ? 1 : 2); + ec_enc_icdf16(enc, s, sign_icdf, 15); + value = abs(value); + if (value) + { + int i; + opus_uint16 icdf[8]; + icdf[0] = IMAX(7, decay); + for (i=1;i<7;i++) + { + icdf[i] = IMAX(7-i, (icdf[i-1] * (opus_int32)decay) >> 15); + } + icdf[7] = 0; + value--; + do { + ec_enc_icdf16(enc, IMIN(value, 7), icdf, 15); + value -= 7; + } while (value >= 0); + } +} + +int ec_laplace_decode_p0(ec_dec *dec, opus_uint16 p0, opus_uint16 decay) +{ + int s; + int value; + opus_uint16 sign_icdf[3]; + sign_icdf[0] = 32768-p0; + sign_icdf[1] = sign_icdf[0]/2; + sign_icdf[2] = 0; + s = ec_dec_icdf16(dec, sign_icdf, 15); + if (s==2) s = -1; + if (s != 0) + { + int i; + int v; + opus_uint16 icdf[8]; + icdf[0] = IMAX(7, decay); + for (i=1;i<7;i++) + { + icdf[i] = IMAX(7-i, (icdf[i-1] * (opus_int32)decay) >> 15); + } + icdf[7] = 0; + value = 1; + do { + v = ec_dec_icdf16(dec, icdf, 15); + value += v; + } while (v == 7); + return s*value; + } else return 0; +} + +#if 0 + +#include +#define NB_VALS 10 +#define DATA_SIZE 10000 +int main() { + ec_enc enc; + ec_dec dec; + unsigned char *ptr; + int i; + int decay, p0; + int val[NB_VALS] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + /*for (i=0;i> 1; - b = 1U << bshift; - do { - opus_uint32 t; - t = (((opus_uint32)g << 1) + b) << bshift; - if (t <= _val) { - g += b; - _val -= t; - } - b >>= 1; - bshift--; - } while (bshift >= 0); - return g; +/*Compute floor(sqrt(_val)) with exact arithmetic. + _val must be greater than 0. + This has been tested on all possible 32-bit inputs greater than 0.*/ +unsigned isqrt32(opus_uint32 _val){ + unsigned b; + unsigned g; + int bshift; + /*Uses the second method from + http://www.azillionmonkeys.com/qed/sqroot.html + The main idea is to search for the largest binary digit b such that + (g+b)*(g+b) <= _val, and add it to the solution g.*/ + g=0; + bshift=(EC_ILOG(_val)-1)>>1; + b=1U<>=1; + bshift--; + } + while(bshift>=0); + return g; } #ifdef FIXED_POINT -opus_val32 frac_div32(opus_val32 a, opus_val32 b) { - opus_val16 rcp; - opus_val32 result, rem; - int shift = celt_ilog2(b) - 29; - a = VSHR32(a, shift); - b = VSHR32(b, shift); - /* 16-bit reciprocal */ - rcp = ROUND16(celt_rcp(ROUND16(b, 16)), 3); - result = MULT16_32_Q15(rcp, a); - rem = PSHR32(a, 2) - MULT32_32_Q31(result, b); - result = ADD32(result, SHL32(MULT16_32_Q15(rcp, rem), 2)); - if (result >= 536870912) { /* 2^29 */ - return 2147483647; /* 2^31 - 1 */ - } else if (result <= -536870912) { /* -2^29 */ - return -2147483647; /* -2^31 */ - } else { - return SHL32(result, 2); - } +opus_val32 frac_div32(opus_val32 a, opus_val32 b) +{ + opus_val16 rcp; + opus_val32 result, rem; + int shift = celt_ilog2(b)-29; + a = VSHR32(a,shift); + b = VSHR32(b,shift); + /* 16-bit reciprocal */ + rcp = ROUND16(celt_rcp(ROUND16(b,16)),3); + result = MULT16_32_Q15(rcp, a); + rem = PSHR32(a,2)-MULT32_32_Q31(result, b); + result = ADD32(result, SHL32(MULT16_32_Q15(rcp, rem),2)); + if (result >= 536870912) /* 2^29 */ + return 2147483647; /* 2^31 - 1 */ + else if (result <= -536870912) /* -2^29 */ + return -2147483647; /* -2^31 */ + else + return SHL32(result, 2); } /** Reciprocal sqrt approximation in the range [0.25,1) (Q16 in, Q14 out) */ -opus_val16 celt_rsqrt_norm(opus_val32 x) { - opus_val16 n; - opus_val16 r; - opus_val16 r2; - opus_val16 y; - /* Range of n is [-16384,32767] ([-0.5,1) in Q15). */ - n = x - 32768; - /* Get a rough initial guess for the root. - The optimal minimax quadratic approximation (using relative error) is - r = 1.437799046117536+n*(-0.823394375837328+n*0.4096419668459485). - Coefficients here, and the final result r, are Q14.*/ - r = ADD16(23557, MULT16_16_Q15(n, ADD16(-13490, MULT16_16_Q15(n, 6713)))); - /* We want y = x*r*r-1 in Q15, but x is 32-bit Q16 and r is Q14. - We can compute the result from n and r using Q15 multiplies with some - adjustment, carefully done to avoid overflow. - Range of y is [-1564,1594]. */ - r2 = MULT16_16_Q15(r, r); - y = SHL16(SUB16(ADD16(MULT16_16_Q15(r2, n), r2), 16384), 1); - /* Apply a 2nd-order Householder iteration: r += r*y*(y*0.375-0.5). - This yields the Q14 reciprocal square root of the Q16 x, with a maximum - relative error of 1.04956E-4, a (relative) RMSE of 2.80979E-5, and a - peak absolute error of 2.26591/16384. */ - return ADD16(r, MULT16_16_Q15(r, MULT16_16_Q15(y, - SUB16(MULT16_16_Q15(y, 12288), 16384)))); +opus_val16 celt_rsqrt_norm(opus_val32 x) +{ + opus_val16 n; + opus_val16 r; + opus_val16 r2; + opus_val16 y; + /* Range of n is [-16384,32767] ([-0.5,1) in Q15). */ + n = x-32768; + /* Get a rough initial guess for the root. + The optimal minimax quadratic approximation (using relative error) is + r = 1.437799046117536+n*(-0.823394375837328+n*0.4096419668459485). + Coefficients here, and the final result r, are Q14.*/ + r = ADD16(23557, MULT16_16_Q15(n, ADD16(-13490, MULT16_16_Q15(n, 6713)))); + /* We want y = x*r*r-1 in Q15, but x is 32-bit Q16 and r is Q14. + We can compute the result from n and r using Q15 multiplies with some + adjustment, carefully done to avoid overflow. + Range of y is [-1564,1594]. */ + r2 = MULT16_16_Q15(r, r); + y = SHL16(SUB16(ADD16(MULT16_16_Q15(r2, n), r2), 16384), 1); + /* Apply a 2nd-order Householder iteration: r += r*y*(y*0.375-0.5). + This yields the Q14 reciprocal square root of the Q16 x, with a maximum + relative error of 1.04956E-4, a (relative) RMSE of 2.80979E-5, and a + peak absolute error of 2.26591/16384. */ + return ADD16(r, MULT16_16_Q15(r, MULT16_16_Q15(y, + SUB16(MULT16_16_Q15(y, 12288), 16384)))); } /** Sqrt approximation (QX input, QX/2 output) */ -opus_val32 celt_sqrt(opus_val32 x) { - int k; - opus_val16 n; - opus_val32 rt; - static const opus_val16 C[5] = {23175, 11561, -3011, 1699, -664}; - if (x == 0) { - return 0; - } else if (x >= 1073741824) { - return 32767; - } - k = (celt_ilog2(x) >> 1) - 7; - x = VSHR32(x, 2 * k); - n = x - 32768; - rt = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], - MULT16_16_Q15(n, ADD16(C[3], MULT16_16_Q15(n, (C[4]))))))))); - rt = VSHR32(rt, 7 - k); - return rt; +opus_val32 celt_sqrt(opus_val32 x) +{ + int k; + opus_val16 n; + opus_val32 rt; + static const opus_val16 C[5] = {23175, 11561, -3011, 1699, -664}; + if (x==0) + return 0; + else if (x>=1073741824) + return 32767; + k = (celt_ilog2(x)>>1)-7; + x = VSHR32(x, 2*k); + n = x-32768; + rt = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], + MULT16_16_Q15(n, ADD16(C[3], MULT16_16_Q15(n, (C[4]))))))))); + rt = VSHR32(rt,7-k); + return rt; } #define L1 32767 @@ -138,12 +140,13 @@ opus_val32 celt_sqrt(opus_val32 x) { #define L3 8277 #define L4 -626 -static OPUS_INLINE opus_val16 _celt_cos_pi_2(opus_val16 x) { - opus_val16 x2; +static OPUS_INLINE opus_val16 _celt_cos_pi_2(opus_val16 x) +{ + opus_val16 x2; - x2 = MULT16_16_P15(x, x); - return ADD16(1, MIN16(32766, ADD32(SUB16(L1, x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2 - )))))))); + x2 = MULT16_16_P15(x,x); + return ADD16(1,MIN16(32766,ADD32(SUB16(L1,x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2 + )))))))); } #undef L1 @@ -151,54 +154,56 @@ static OPUS_INLINE opus_val16 _celt_cos_pi_2(opus_val16 x) { #undef L3 #undef L4 -opus_val16 celt_cos_norm(opus_val32 x) { - x = x & 0x0001ffff; - if (x > SHL32(EXTEND32(1), 16)) { - x = SUB32(SHL32(EXTEND32(1), 17), x); - } - if (x & 0x00007fff) { - if (x < SHL32(EXTEND32(1), 15)) { - return _celt_cos_pi_2(EXTRACT16(x)); - } else { - return NEG16(_celt_cos_pi_2(EXTRACT16(65536 - x))); - } - } else { - if (x & 0x0000ffff) { - return 0; - } else if (x & 0x0001ffff) { - return -32767; - } else { - return 32767; - } - } +opus_val16 celt_cos_norm(opus_val32 x) +{ + x = x&0x0001ffff; + if (x>SHL32(EXTEND32(1), 16)) + x = SUB32(SHL32(EXTEND32(1), 17),x); + if (x&0x00007fff) + { + if (x 0); - i = celt_ilog2(x); - /* n is Q15 with range [0,1). */ - n = VSHR32(x, i - 15) - 32768; - /* Start with a linear approximation: - r = 1.8823529411764706-0.9411764705882353*n. - The coefficients and the result are Q14 in the range [15420,30840].*/ - r = ADD16(30840, MULT16_16_Q15(-15420, n)); - /* Perform two Newton iterations: - r -= r*((r*n)-1.Q15) - = r*((r*n)+(r-1.Q15)). */ - r = SUB16(r, MULT16_16_Q15(r, - ADD16(MULT16_16_Q15(r, n), ADD16(r, -32768)))); - /* We subtract an extra 1 in the second iteration to avoid overflow; it also - neatly compensates for truncation error in the rest of the process. */ - r = SUB16(r, ADD16(1, MULT16_16_Q15(r, - ADD16(MULT16_16_Q15(r, n), ADD16(r, -32768))))); - /* r is now the Q15 solution to 2/(n+1), with a maximum relative error - of 7.05346E-5, a (relative) RMSE of 2.14418E-5, and a peak absolute - error of 1.24665/32768. */ - return VSHR32(EXTEND32(r), i - 16); +opus_val32 celt_rcp(opus_val32 x) +{ + int i; + opus_val16 n; + opus_val16 r; + celt_sig_assert(x>0); + i = celt_ilog2(x); + /* n is Q15 with range [0,1). */ + n = VSHR32(x,i-15)-32768; + /* Start with a linear approximation: + r = 1.8823529411764706-0.9411764705882353*n. + The coefficients and the result are Q14 in the range [15420,30840].*/ + r = ADD16(30840, MULT16_16_Q15(-15420, n)); + /* Perform two Newton iterations: + r -= r*((r*n)-1.Q15) + = r*((r*n)+(r-1.Q15)). */ + r = SUB16(r, MULT16_16_Q15(r, + ADD16(MULT16_16_Q15(r, n), ADD16(r, -32768)))); + /* We subtract an extra 1 in the second iteration to avoid overflow; it also + neatly compensates for truncation error in the rest of the process. */ + r = SUB16(r, ADD16(1, MULT16_16_Q15(r, + ADD16(MULT16_16_Q15(r, n), ADD16(r, -32768))))); + /* r is now the Q15 solution to 2/(n+1), with a maximum relative error + of 7.05346E-5, a (relative) RMSE of 2.14418E-5, and a peak absolute + error of 1.24665/32768. */ + return VSHR32(EXTEND32(r),i-16); } #endif diff --git a/src/libopus/celt/mathops.h b/src/libopus/celt/mathops.h index a9d6a66..e2eece2 100644 --- a/src/libopus/celt/mathops.h +++ b/src/libopus/celt/mathops.h @@ -1,34 +1,34 @@ -/* Copyright (c) 2002-2008 Jean-Marc Valin - Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2002-2008 Jean-Marc Valin + Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /** - @file mathops.h - @brief Various math functions + @file mathops.h + @brief Various math functions */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef MATHOPS_H @@ -52,21 +52,22 @@ unsigned isqrt32(opus_uint32 _val); #define cC 0.08595542f #define cE ((float)PI/2) static OPUS_INLINE float fast_atan2f(float y, float x) { - float x2, y2; - x2 = x * x; - y2 = y * y; - /* For very small values, we don't care about the answer, so - we can just return 0. */ - if (x2 + y2 < 1e-18f) { - return 0; - } - if (x2 < y2) { - float den = (y2 + cB * x2) * (y2 + cC * x2); - return -x * y * (y2 + cA * x2) / den + (y < 0 ? -cE : cE); - } else { - float den = (x2 + cB * y2) * (x2 + cC * y2); - return x * y * (x2 + cA * y2) / den + (y < 0 ? -cE : cE) - (x * y < 0 ? -cE : cE); - } + float x2, y2; + x2 = x*x; + y2 = y*y; + /* For very small values, we don't care about the answer, so + we can just return 0. */ + if (x2 + y2 < 1e-18f) + { + return 0; + } + if(x2> 23) - 127; - in.i -= integer << 23; - frac = in.f - 1.5f; - frac = -0.41445418f + frac * (0.95909232f - + frac * (-0.33951290f + frac * 0.16541097f)); - return 1 + integer + frac; +static OPUS_INLINE float celt_log2(float x) +{ + int integer; + float frac; + union { + float f; + opus_uint32 i; + } in; + in.f = x; + integer = (in.i>>23)-127; + in.i -= (opus_uint32)integer<<23; + frac = in.f - 1.5f; + frac = -0.41445418f + frac*(0.95909232f + + frac*(-0.33951290f + frac*0.16541097f)); + return 1+integer+frac; } /** Base-2 exponential approximation (2^x). */ -static OPUS_INLINE float celt_exp2(float x) { - int integer; - float frac; - union { - float f; - opus_uint32 i; - } res; - integer = floor(x); - if (integer < -50) { - return 0; - } - frac = x - integer; - /* K0 = 1, K1 = log(2), K2 = 3-4*log(2), K3 = 3*log(2) - 2 */ - res.f = 0.99992522f + frac * (0.69583354f - + frac * (0.22606716f + 0.078024523f * frac)); - res.i = (res.i + (integer << 23)) & 0x7fffffff; - return res.f; +static OPUS_INLINE float celt_exp2(float x) +{ + int integer; + float frac; + union { + float f; + opus_uint32 i; + } res; + integer = (int)floor(x); + if (integer < -50) + return 0; + frac = x-integer; + /* K0 = 1, K1 = log(2), K2 = 3-4*log(2), K3 = 3*log(2) - 2 */ + res.f = 0.99992522f + frac * (0.69583354f + + frac * (0.22606716f + 0.078024523f*frac)); + res.i = (res.i + ((opus_uint32)integer<<23)) & 0x7fffffff; + return res.f; } #else @@ -171,16 +177,18 @@ static OPUS_INLINE float celt_exp2(float x) { #ifndef OVERRIDE_CELT_ILOG2 /** Integer log in base2. Undefined for zero and negative numbers */ -static OPUS_INLINE opus_int16 celt_ilog2(opus_int32 x) { - celt_sig_assert(x > 0); - return EC_ILOG(x) - 1; +static OPUS_INLINE opus_int16 celt_ilog2(opus_int32 x) +{ + celt_sig_assert(x>0); + return EC_ILOG(x)-1; } #endif /** Integer log in base2. Defined for zero, but not for negative numbers */ -static OPUS_INLINE opus_int16 celt_zlog2(opus_val32 x) { - return x <= 0 ? 0 : celt_ilog2(x); +static OPUS_INLINE opus_int16 celt_zlog2(opus_val32 x) +{ + return x <= 0 ? 0 : celt_ilog2(x); } opus_val16 celt_rsqrt_norm(opus_val32 x); @@ -190,49 +198,56 @@ opus_val32 celt_sqrt(opus_val32 x); opus_val16 celt_cos_norm(opus_val32 x); /** Base-2 logarithm approximation (log2(x)). (Q14 input, Q10 output) */ -static OPUS_INLINE opus_val16 celt_log2(opus_val32 x) { - int i; - opus_val16 n, frac; - /* -0.41509302963303146, 0.9609890551383969, -0.31836011537636605, - 0.15530808010959576, -0.08556153059057618 */ - static const opus_val16 C[5] = {-6801 + (1 << (13 - DB_SHIFT)), 15746, -5217, 2545, -1401}; - if (x == 0) { - return -32767; - } - i = celt_ilog2(x); - n = VSHR32(x, i - 15) - 32768 - 16384; - frac = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], MULT16_16_Q15(n, ADD16(C[3], MULT16_16_Q15(n, C[4])))))))); - return SHL16(i - 13, DB_SHIFT) + SHR16(frac, 14 - DB_SHIFT); +static OPUS_INLINE opus_val16 celt_log2(opus_val32 x) +{ + int i; + opus_val16 n, frac; + /* -0.41509302963303146, 0.9609890551383969, -0.31836011537636605, + 0.15530808010959576, -0.08556153059057618 */ + static const opus_val16 C[5] = {-6801+(1<<(13-DB_SHIFT)), 15746, -5217, 2545, -1401}; + if (x==0) + return -32767; + i = celt_ilog2(x); + n = VSHR32(x,i-15)-32768-16384; + frac = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], MULT16_16_Q15(n, ADD16(C[3], MULT16_16_Q15(n, C[4])))))))); + return SHL16(i-13,DB_SHIFT)+SHR16(frac,14-DB_SHIFT); } /* - K0 = 1 - K1 = log(2) - K2 = 3-4*log(2) - K3 = 3*log(2) - 2 + K0 = 1 + K1 = log(2) + K2 = 3-4*log(2) + K3 = 3*log(2) - 2 */ #define D0 16383 #define D1 22804 #define D2 14819 #define D3 10204 -static OPUS_INLINE opus_val32 celt_exp2_frac(opus_val16 x) { - opus_val16 frac; - frac = SHL16(x, 4); - return ADD16(D0, MULT16_16_Q15(frac, ADD16(D1, MULT16_16_Q15(frac, ADD16(D2, MULT16_16_Q15(D3, frac)))))); +static OPUS_INLINE opus_val32 celt_exp2_frac(opus_val16 x) +{ + opus_val16 frac; + frac = SHL16(x, 4); + return ADD16(D0, MULT16_16_Q15(frac, ADD16(D1, MULT16_16_Q15(frac, ADD16(D2 , MULT16_16_Q15(D3,frac)))))); } + +#undef D0 +#undef D1 +#undef D2 +#undef D3 + /** Base-2 exponential approximation (2^x). (Q10 input, Q16 output) */ -static OPUS_INLINE opus_val32 celt_exp2(opus_val16 x) { - int integer; - opus_val16 frac; - integer = SHR16(x, 10); - if (integer > 14) { - return 0x7f000000; - } else if (integer < -15) { - return 0; - } - frac = celt_exp2_frac(x - SHL16(integer, 10)); - return VSHR32(EXTEND32(frac), -integer - 2); +static OPUS_INLINE opus_val32 celt_exp2(opus_val16 x) +{ + int integer; + opus_val16 frac; + integer = SHR16(x,10); + if (integer>14) + return 0x7f000000; + else if (integer < -15) + return 0; + frac = celt_exp2_frac(x-SHL16(integer,10)); + return VSHR32(EXTEND32(frac), -integer-2); } opus_val32 celt_rcp(opus_val32 x); @@ -246,10 +261,11 @@ opus_val32 frac_div32(opus_val32 a, opus_val32 b); #define M3 -11943 #define M4 4936 -/* Atan approximation using a 4th order polynomial. Input is in Q15 format - and normalized by pi/4. Output is in Q15 format */ -static OPUS_INLINE opus_val16 celt_atan01(opus_val16 x) { - return MULT16_16_P15(x, ADD32(M1, MULT16_16_P15(x, ADD32(M2, MULT16_16_P15(x, ADD32(M3, MULT16_16_P15(M4, x))))))); +/* Atan approximation using a 4th order polynomial. Input is in Q15 format + and normalized by pi/4. Output is in Q15 format */ +static OPUS_INLINE opus_val16 celt_atan01(opus_val16 x) +{ + return MULT16_16_P15(x, ADD32(M1, MULT16_16_P15(x, ADD32(M2, MULT16_16_P15(x, ADD32(M3, MULT16_16_P15(M4, x))))))); } #undef M1 @@ -258,22 +274,22 @@ static OPUS_INLINE opus_val16 celt_atan01(opus_val16 x) { #undef M4 /* atan2() approximation valid for positive input values */ -static OPUS_INLINE opus_val16 celt_atan2p(opus_val16 y, opus_val16 x) { - if (y < x) { - opus_val32 arg; - arg = celt_div(SHL32(EXTEND32(y), 15), x); - if (arg >= 32767) { - arg = 32767; - } - return SHR16(celt_atan01(EXTRACT16(arg)), 1); - } else { - opus_val32 arg; - arg = celt_div(SHL32(EXTEND32(x), 15), y); - if (arg >= 32767) { - arg = 32767; - } - return 25736 - SHR16(celt_atan01(EXTRACT16(arg)), 1); - } +static OPUS_INLINE opus_val16 celt_atan2p(opus_val16 y, opus_val16 x) +{ + if (y < x) + { + opus_val32 arg; + arg = celt_div(SHL32(EXTEND32(y),15),x); + if (arg >= 32767) + arg = 32767; + return SHR16(celt_atan01(EXTRACT16(arg)),1); + } else { + opus_val32 arg; + arg = celt_div(SHL32(EXTEND32(x),15),y); + if (arg >= 32767) + arg = 32767; + return 25736-SHR16(celt_atan01(EXTRACT16(arg)),1); + } } #endif /* FIXED_POINT */ diff --git a/src/libopus/celt/mdct.c b/src/libopus/celt/mdct.c index 70d5aca..b67f3c8 100644 --- a/src/libopus/celt/mdct.c +++ b/src/libopus/celt/mdct.c @@ -1,48 +1,48 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2008 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2008 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* This is a simple MDCT implementation that uses a N/4 complex FFT - to do most of the work. It should be relatively straightforward to - plug in pretty much and FFT here. +/* This is a simple MDCT implementation that uses a N/4 complex FFT + to do most of the work. It should be relatively straightforward to + plug in pretty much and FFT here. - This replaces the Vorbis FFT (and uses the exact same API), which - was a bit too messy and that was ending up duplicating code - (might as well use the same FFT everywhere). + This replaces the Vorbis FFT (and uses the exact same API), which + was a bit too messy and that was ending up duplicating code + (might as well use the same FFT everywhere). - The algorithm is similar to (and inspired from) Fabrice Bellard's - MDCT implementation in FFMPEG, but has differences in signs, ordering - and scaling in many places. + The algorithm is similar to (and inspired from) Fabrice Bellard's + MDCT implementation in FFMPEG, but has differences in signs, ordering + and scaling in many places. */ #ifndef SKIP_CONFIG_H -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #endif #include "mdct.h" @@ -60,59 +60,56 @@ #ifdef CUSTOM_MODES -int clt_mdct_init(mdct_lookup *l, int N, int maxshift, int arch) { - int i; - kiss_twiddle_scalar *trig; - int shift; - int N2 = N >> 1; - l->n = N; - l->maxshift = maxshift; - for (i = 0; i <= maxshift; i++) { - if (i == 0) { - l->kfft[i] = opus_fft_alloc(N >> 2 >> i, 0, 0, arch); - } else { - l->kfft[i] = opus_fft_alloc_twiddles(N >> 2 >> i, 0, 0, l->kfft[0], arch); - } +int clt_mdct_init(mdct_lookup *l,int N, int maxshift, int arch) +{ + int i; + kiss_twiddle_scalar *trig; + int shift; + int N2=N>>1; + l->n = N; + l->maxshift = maxshift; + for (i=0;i<=maxshift;i++) + { + if (i==0) + l->kfft[i] = opus_fft_alloc(N>>2>>i, 0, 0, arch); + else + l->kfft[i] = opus_fft_alloc_twiddles(N>>2>>i, 0, 0, l->kfft[0], arch); #ifndef ENABLE_TI_DSPLIB55 - if (l->kfft[i] == NULL) { - return 0; - } + if (l->kfft[i]==NULL) + return 0; #endif - } - l->trig = trig = (kiss_twiddle_scalar*)opus_alloc((N - (N2 >> maxshift)) * sizeof(kiss_twiddle_scalar)); - if (l->trig == NULL) { - return 0; - } - for (shift = 0; shift <= maxshift; shift++) { - /* We have enough points that sine isn't necessary */ + } + l->trig = trig = (kiss_twiddle_scalar*)opus_alloc((N-(N2>>maxshift))*sizeof(kiss_twiddle_scalar)); + if (l->trig==NULL) + return 0; + for (shift=0;shift<=maxshift;shift++) + { + /* We have enough points that sine isn't necessary */ #if defined(FIXED_POINT) #if 1 - for (i = 0; i < N2; i++) { - trig[i] = TRIG_UPSCALE * celt_cos_norm(DIV32(ADD32(SHL32(EXTEND32(i), 17), N2 + 16384), N)); - } + for (i=0;i>= 1; - N >>= 1; - } - return 1; + trig += N2; + N2 >>= 1; + N >>= 1; + } + return 1; } -void clt_mdct_clear(mdct_lookup *l, int arch) { - int i; - for (i = 0; i <= l->maxshift; i++) { - opus_fft_free(l->kfft[i], arch); - } - opus_free((kiss_twiddle_scalar*)l->trig); +void clt_mdct_clear(mdct_lookup *l, int arch) +{ + int i; + for (i=0;i<=l->maxshift;i++) + opus_fft_free(l->kfft[i], arch); + opus_free((kiss_twiddle_scalar*)l->trig); } #endif /* CUSTOM_MODES */ @@ -120,215 +117,227 @@ void clt_mdct_clear(mdct_lookup *l, int arch) { /* Forward MDCT trashes the input array */ #ifndef OVERRIDE_clt_mdct_forward void clt_mdct_forward_c(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * OPUS_RESTRICT out, - const opus_val16 *window, int overlap, int shift, int stride, int arch) { - int i; - int N, N2, N4; - VARDECL(kiss_fft_scalar, f); - VARDECL(kiss_fft_cpx, f2); - const kiss_fft_state *st = l->kfft[shift]; - const kiss_twiddle_scalar *trig; - opus_val16 scale; + const opus_val16 *window, int overlap, int shift, int stride, int arch) +{ + int i; + int N, N2, N4; + VARDECL(kiss_fft_scalar, f); + VARDECL(kiss_fft_cpx, f2); + const kiss_fft_state *st = l->kfft[shift]; + const kiss_twiddle_scalar *trig; + opus_val16 scale; #ifdef FIXED_POINT - /* Allows us to scale with MULT16_32_Q16(), which is faster than - MULT16_32_Q15() on ARM. */ - int scale_shift = st->scale_shift - 1; + /* Allows us to scale with MULT16_32_Q16(), which is faster than + MULT16_32_Q15() on ARM. */ + int scale_shift = st->scale_shift-1; #endif - SAVE_STACK; - (void)arch; - scale = st->scale; + SAVE_STACK; + (void)arch; + scale = st->scale; - N = l->n; - trig = l->trig; - for (i = 0; i < shift; i++) { - N >>= 1; - trig += N; - } - N2 = N >> 1; - N4 = N >> 2; + N = l->n; + trig = l->trig; + for (i=0;i>= 1; + trig += N; + } + N2 = N>>1; + N4 = N>>2; - ALLOC(f, N2, kiss_fft_scalar); - ALLOC(f2, N4, kiss_fft_cpx); + ALLOC(f, N2, kiss_fft_scalar); + ALLOC(f2, N4, kiss_fft_cpx); - /* Consider the input to be composed of four blocks: [a, b, c, d] */ - /* Window, shuffle, fold */ - { - /* Temp pointers to make it really clear to the compiler what we're doing */ - const kiss_fft_scalar * OPUS_RESTRICT xp1 = in + (overlap >> 1); - const kiss_fft_scalar * OPUS_RESTRICT xp2 = in + N2 - 1 + (overlap >> 1); - kiss_fft_scalar * OPUS_RESTRICT yp = f; - const opus_val16 * OPUS_RESTRICT wp1 = window + (overlap >> 1); - const opus_val16 * OPUS_RESTRICT wp2 = window + (overlap >> 1) - 1; - for (i = 0; i < ((overlap + 3) >> 2); i++) { - /* Real part arranged as -d-cR, Imag part arranged as -b+aR*/ - *yp++ = MULT16_32_Q15(*wp2, xp1[N2]) + MULT16_32_Q15(*wp1, *xp2); - *yp++ = MULT16_32_Q15(*wp1, *xp1) - MULT16_32_Q15(*wp2, xp2[-N2]); - xp1 += 2; - xp2 -= 2; - wp1 += 2; - wp2 -= 2; - } - wp1 = window; - wp2 = window + overlap - 1; - for (; i < N4 - ((overlap + 3) >> 2); i++) { - /* Real part arranged as a-bR, Imag part arranged as -c-dR */ - *yp++ = *xp2; - *yp++ = *xp1; - xp1 += 2; - xp2 -= 2; - } - for (; i < N4; i++) { - /* Real part arranged as a-bR, Imag part arranged as -c-dR */ - *yp++ = -MULT16_32_Q15(*wp1, xp1[-N2]) + MULT16_32_Q15(*wp2, *xp2); - *yp++ = MULT16_32_Q15(*wp2, *xp1) + MULT16_32_Q15(*wp1, xp2[N2]); - xp1 += 2; - xp2 -= 2; - wp1 += 2; - wp2 -= 2; - } - } - /* Pre-rotation */ - { - kiss_fft_scalar * OPUS_RESTRICT yp = f; - const kiss_twiddle_scalar *t = &trig[0]; - for (i = 0; i < N4; i++) { - kiss_fft_cpx yc; - kiss_twiddle_scalar t0, t1; - kiss_fft_scalar re, im, yr, yi; - t0 = t[i]; - t1 = t[N4 + i]; - re = *yp++; - im = *yp++; - yr = S_MUL(re, t0) - S_MUL(im, t1); - yi = S_MUL(im, t0) + S_MUL(re, t1); - yc.r = yr; - yc.i = yi; - yc.r = PSHR32(MULT16_32_Q16(scale, yc.r), scale_shift); - yc.i = PSHR32(MULT16_32_Q16(scale, yc.i), scale_shift); - f2[st->bitrev[i]] = yc; - } - } + /* Consider the input to be composed of four blocks: [a, b, c, d] */ + /* Window, shuffle, fold */ + { + /* Temp pointers to make it really clear to the compiler what we're doing */ + const kiss_fft_scalar * OPUS_RESTRICT xp1 = in+(overlap>>1); + const kiss_fft_scalar * OPUS_RESTRICT xp2 = in+N2-1+(overlap>>1); + kiss_fft_scalar * OPUS_RESTRICT yp = f; + const opus_val16 * OPUS_RESTRICT wp1 = window+(overlap>>1); + const opus_val16 * OPUS_RESTRICT wp2 = window+(overlap>>1)-1; + for(i=0;i<((overlap+3)>>2);i++) + { + /* Real part arranged as -d-cR, Imag part arranged as -b+aR*/ + *yp++ = MULT16_32_Q15(*wp2, xp1[N2]) + MULT16_32_Q15(*wp1,*xp2); + *yp++ = MULT16_32_Q15(*wp1, *xp1) - MULT16_32_Q15(*wp2, xp2[-N2]); + xp1+=2; + xp2-=2; + wp1+=2; + wp2-=2; + } + wp1 = window; + wp2 = window+overlap-1; + for(;i>2);i++) + { + /* Real part arranged as a-bR, Imag part arranged as -c-dR */ + *yp++ = *xp2; + *yp++ = *xp1; + xp1+=2; + xp2-=2; + } + for(;ibitrev[i]] = yc; + } + } - /* N/4 complex FFT, does not downscale anymore */ - opus_fft_impl(st, f2); + /* N/4 complex FFT, does not downscale anymore */ + opus_fft_impl(st, f2); - /* Post-rotate */ - { - /* Temp pointers to make it really clear to the compiler what we're doing */ - const kiss_fft_cpx * OPUS_RESTRICT fp = f2; - kiss_fft_scalar * OPUS_RESTRICT yp1 = out; - kiss_fft_scalar * OPUS_RESTRICT yp2 = out + stride * (N2 - 1); - const kiss_twiddle_scalar *t = &trig[0]; - /* Temp pointers to make it really clear to the compiler what we're doing */ - for (i = 0; i < N4; i++) { - kiss_fft_scalar yr, yi; - yr = S_MUL(fp->i, t[N4 + i]) - S_MUL(fp->r, t[i]); - yi = S_MUL(fp->r, t[N4 + i]) + S_MUL(fp->i, t[i]); - *yp1 = yr; - *yp2 = yi; - fp++; - yp1 += 2 * stride; - yp2 -= 2 * stride; - } - } - RESTORE_STACK; + /* Post-rotate */ + { + /* Temp pointers to make it really clear to the compiler what we're doing */ + const kiss_fft_cpx * OPUS_RESTRICT fp = f2; + kiss_fft_scalar * OPUS_RESTRICT yp1 = out; + kiss_fft_scalar * OPUS_RESTRICT yp2 = out+stride*(N2-1); + const kiss_twiddle_scalar *t = &trig[0]; + /* Temp pointers to make it really clear to the compiler what we're doing */ + for(i=0;ii,t[N4+i]) - S_MUL(fp->r,t[i]); + yi = S_MUL(fp->r,t[N4+i]) + S_MUL(fp->i,t[i]); + *yp1 = yr; + *yp2 = yi; + fp++; + yp1 += 2*stride; + yp2 -= 2*stride; + } + } + RESTORE_STACK; } #endif /* OVERRIDE_clt_mdct_forward */ #ifndef OVERRIDE_clt_mdct_backward void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * OPUS_RESTRICT out, - const opus_val16 * OPUS_RESTRICT window, int overlap, int shift, int stride, int arch) { - int i; - int N, N2, N4; - const kiss_twiddle_scalar *trig; - (void) arch; + const opus_val16 * OPUS_RESTRICT window, int overlap, int shift, int stride, int arch) +{ + int i; + int N, N2, N4; + const kiss_twiddle_scalar *trig; + (void) arch; - N = l->n; - trig = l->trig; - for (i = 0; i < shift; i++) { - N >>= 1; - trig += N; - } - N2 = N >> 1; - N4 = N >> 2; + N = l->n; + trig = l->trig; + for (i=0;i>= 1; + trig += N; + } + N2 = N>>1; + N4 = N>>2; - /* Pre-rotate */ - { - /* Temp pointers to make it really clear to the compiler what we're doing */ - const kiss_fft_scalar * OPUS_RESTRICT xp1 = in; - const kiss_fft_scalar * OPUS_RESTRICT xp2 = in + stride * (N2 - 1); - kiss_fft_scalar * OPUS_RESTRICT yp = out + (overlap >> 1); - const kiss_twiddle_scalar * OPUS_RESTRICT t = &trig[0]; - const opus_int16 * OPUS_RESTRICT bitrev = l->kfft[shift]->bitrev; - for (i = 0; i < N4; i++) { - int rev; - kiss_fft_scalar yr, yi; - rev = *bitrev++; - yr = ADD32_ovflw(S_MUL(*xp2, t[i]), S_MUL(*xp1, t[N4 + i])); - yi = SUB32_ovflw(S_MUL(*xp1, t[i]), S_MUL(*xp2, t[N4 + i])); - /* We swap real and imag because we use an FFT instead of an IFFT. */ - yp[2 * rev + 1] = yr; - yp[2 * rev] = yi; - /* Storing the pre-rotation directly in the bitrev order. */ - xp1 += 2 * stride; - xp2 -= 2 * stride; - } - } + /* Pre-rotate */ + { + /* Temp pointers to make it really clear to the compiler what we're doing */ + const kiss_fft_scalar * OPUS_RESTRICT xp1 = in; + const kiss_fft_scalar * OPUS_RESTRICT xp2 = in+stride*(N2-1); + kiss_fft_scalar * OPUS_RESTRICT yp = out+(overlap>>1); + const kiss_twiddle_scalar * OPUS_RESTRICT t = &trig[0]; + const opus_int16 * OPUS_RESTRICT bitrev = l->kfft[shift]->bitrev; + for(i=0;ikfft[shift], (kiss_fft_cpx*)(out + (overlap >> 1))); + opus_fft_impl(l->kfft[shift], (kiss_fft_cpx*)(out+(overlap>>1))); - /* Post-rotate and de-shuffle from both ends of the buffer at once to make - it in-place. */ - { - kiss_fft_scalar * yp0 = out + (overlap >> 1); - kiss_fft_scalar * yp1 = out + (overlap >> 1) + N2 - 2; - const kiss_twiddle_scalar *t = &trig[0]; - /* Loop to (N4+1)>>1 to handle odd N4. When N4 is odd, the - middle pair will be computed twice. */ - for (i = 0; i < (N4 + 1) >> 1; i++) { - kiss_fft_scalar re, im, yr, yi; - kiss_twiddle_scalar t0, t1; - /* We swap real and imag because we're using an FFT instead of an IFFT. */ - re = yp0[1]; - im = yp0[0]; - t0 = t[i]; - t1 = t[N4 + i]; - /* We'd scale up by 2 here, but instead it's done when mixing the windows */ - yr = ADD32_ovflw(S_MUL(re, t0), S_MUL(im, t1)); - yi = SUB32_ovflw(S_MUL(re, t1), S_MUL(im, t0)); - /* We swap real and imag because we're using an FFT instead of an IFFT. */ - re = yp1[1]; - im = yp1[0]; - yp0[0] = yr; - yp1[1] = yi; + /* Post-rotate and de-shuffle from both ends of the buffer at once to make + it in-place. */ + { + kiss_fft_scalar * yp0 = out+(overlap>>1); + kiss_fft_scalar * yp1 = out+(overlap>>1)+N2-2; + const kiss_twiddle_scalar *t = &trig[0]; + /* Loop to (N4+1)>>1 to handle odd N4. When N4 is odd, the + middle pair will be computed twice. */ + for(i=0;i<(N4+1)>>1;i++) + { + kiss_fft_scalar re, im, yr, yi; + kiss_twiddle_scalar t0, t1; + /* We swap real and imag because we're using an FFT instead of an IFFT. */ + re = yp0[1]; + im = yp0[0]; + t0 = t[i]; + t1 = t[N4+i]; + /* We'd scale up by 2 here, but instead it's done when mixing the windows */ + yr = ADD32_ovflw(S_MUL(re,t0), S_MUL(im,t1)); + yi = SUB32_ovflw(S_MUL(re,t1), S_MUL(im,t0)); + /* We swap real and imag because we're using an FFT instead of an IFFT. */ + re = yp1[1]; + im = yp1[0]; + yp0[0] = yr; + yp1[1] = yi; - t0 = t[(N4 - i - 1)]; - t1 = t[(N2 - i - 1)]; - /* We'd scale up by 2 here, but instead it's done when mixing the windows */ - yr = ADD32_ovflw(S_MUL(re, t0), S_MUL(im, t1)); - yi = SUB32_ovflw(S_MUL(re, t1), S_MUL(im, t0)); - yp1[0] = yr; - yp0[1] = yi; - yp0 += 2; - yp1 -= 2; - } - } + t0 = t[(N4-i-1)]; + t1 = t[(N2-i-1)]; + /* We'd scale up by 2 here, but instead it's done when mixing the windows */ + yr = ADD32_ovflw(S_MUL(re,t0), S_MUL(im,t1)); + yi = SUB32_ovflw(S_MUL(re,t1), S_MUL(im,t0)); + yp1[0] = yr; + yp0[1] = yi; + yp0 += 2; + yp1 -= 2; + } + } - /* Mirror on both sides for TDAC */ - { - kiss_fft_scalar * OPUS_RESTRICT xp1 = out + overlap - 1; - kiss_fft_scalar * OPUS_RESTRICT yp1 = out; - const opus_val16 * OPUS_RESTRICT wp1 = window; - const opus_val16 * OPUS_RESTRICT wp2 = window + overlap - 1; + /* Mirror on both sides for TDAC */ + { + kiss_fft_scalar * OPUS_RESTRICT xp1 = out+overlap-1; + kiss_fft_scalar * OPUS_RESTRICT yp1 = out; + const opus_val16 * OPUS_RESTRICT wp1 = window; + const opus_val16 * OPUS_RESTRICT wp2 = window+overlap-1; - for (i = 0; i < overlap / 2; i++) { - kiss_fft_scalar x1, x2; - x1 = *xp1; - x2 = *yp1; - *yp1++ = SUB32_ovflw(MULT16_32_Q15(*wp2, x2), MULT16_32_Q15(*wp1, x1)); - *xp1-- = ADD32_ovflw(MULT16_32_Q15(*wp1, x2), MULT16_32_Q15(*wp2, x1)); - wp1++; - wp2--; - } - } + for(i = 0; i < overlap/2; i++) + { + kiss_fft_scalar x1, x2; + x1 = *xp1; + x2 = *yp1; + *yp1++ = SUB32_ovflw(MULT16_32_Q15(*wp2, x2), MULT16_32_Q15(*wp1, x1)); + *xp1-- = ADD32_ovflw(MULT16_32_Q15(*wp1, x2), MULT16_32_Q15(*wp2, x1)); + wp1++; + wp2--; + } + } } #endif /* OVERRIDE_clt_mdct_backward */ diff --git a/src/libopus/celt/mdct.h b/src/libopus/celt/mdct.h index c8a17d9..160ae4e 100644 --- a/src/libopus/celt/mdct.h +++ b/src/libopus/celt/mdct.h @@ -1,56 +1,56 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2008 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2008 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* This is a simple MDCT implementation that uses a N/4 complex FFT - to do most of the work. It should be relatively straightforward to - plug in pretty much and FFT here. +/* This is a simple MDCT implementation that uses a N/4 complex FFT + to do most of the work. It should be relatively straightforward to + plug in pretty much and FFT here. - This replaces the Vorbis FFT (and uses the exact same API), which - was a bit too messy and that was ending up duplicating code - (might as well use the same FFT everywhere). + This replaces the Vorbis FFT (and uses the exact same API), which + was a bit too messy and that was ending up duplicating code + (might as well use the same FFT everywhere). - The algorithm is similar to (and inspired from) Fabrice Bellard's - MDCT implementation in FFMPEG, but has differences in signs, ordering - and scaling in many places. + The algorithm is similar to (and inspired from) Fabrice Bellard's + MDCT implementation in FFMPEG, but has differences in signs, ordering + and scaling in many places. */ #ifndef MDCT_H #define MDCT_H -#include "../opus_defines.h" +#include "opus_defines.h" #include "kiss_fft.h" #include "arch.h" typedef struct { - int n; - int maxshift; - const kiss_fft_state *kfft[4]; - const kiss_twiddle_scalar * OPUS_RESTRICT trig; + int n; + int maxshift; + const kiss_fft_state *kfft[4]; + const kiss_twiddle_scalar * OPUS_RESTRICT trig; } mdct_lookup; #if defined(HAVE_ARM_NE10) @@ -58,7 +58,7 @@ typedef struct { #endif -int clt_mdct_init(mdct_lookup *l, int N, int maxshift, int arch); +int clt_mdct_init(mdct_lookup *l,int N, int maxshift, int arch); void clt_mdct_clear(mdct_lookup *l, int arch); /** Compute a forward MDCT and scale by 4/N, trashes the input array */ @@ -70,28 +70,28 @@ void clt_mdct_forward_c(const mdct_lookup *l, kiss_fft_scalar *in, /** Compute a backward MDCT (no scaling) and performs weighted overlap-add (scales implicitly by 1/2) */ void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in, - kiss_fft_scalar * OPUS_RESTRICT out, - const opus_val16 * OPUS_RESTRICT window, - int overlap, int shift, int stride, int arch); + kiss_fft_scalar * OPUS_RESTRICT out, + const opus_val16 * OPUS_RESTRICT window, + int overlap, int shift, int stride, int arch); #if !defined(OVERRIDE_OPUS_MDCT) /* Is run-time CPU detection enabled on this platform? */ #if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) -extern void (*const CLT_MDCT_FORWARD_IMPL[OPUS_ARCHMASK + 1])( - const mdct_lookup *l, kiss_fft_scalar *in, - kiss_fft_scalar * OPUS_RESTRICT out, const opus_val16 *window, - int overlap, int shift, int stride, int arch); +extern void (*const CLT_MDCT_FORWARD_IMPL[OPUS_ARCHMASK+1])( + const mdct_lookup *l, kiss_fft_scalar *in, + kiss_fft_scalar * OPUS_RESTRICT out, const opus_val16 *window, + int overlap, int shift, int stride, int arch); #define clt_mdct_forward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \ ((*CLT_MDCT_FORWARD_IMPL[(arch)&OPUS_ARCHMASK])(_l, _in, _out, \ _window, _overlap, _shift, \ _stride, _arch)) -extern void (*const CLT_MDCT_BACKWARD_IMPL[OPUS_ARCHMASK + 1])( - const mdct_lookup *l, kiss_fft_scalar *in, - kiss_fft_scalar * OPUS_RESTRICT out, const opus_val16 *window, - int overlap, int shift, int stride, int arch); +extern void (*const CLT_MDCT_BACKWARD_IMPL[OPUS_ARCHMASK+1])( + const mdct_lookup *l, kiss_fft_scalar *in, + kiss_fft_scalar * OPUS_RESTRICT out, const opus_val16 *window, + int overlap, int shift, int stride, int arch); #define clt_mdct_backward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \ (*CLT_MDCT_BACKWARD_IMPL[(arch)&OPUS_ARCHMASK])(_l, _in, _out, \ diff --git a/src/libopus/celt/mfrngcod.h b/src/libopus/celt/mfrngcod.h index 9d96aae..809152a 100644 --- a/src/libopus/celt/mfrngcod.h +++ b/src/libopus/celt/mfrngcod.h @@ -1,28 +1,28 @@ -/* Copyright (c) 2001-2008 Timothy B. Terriberry - Copyright (c) 2008-2009 Xiph.Org Foundation */ +/* Copyright (c) 2001-2008 Timothy B. Terriberry + Copyright (c) 2008-2009 Xiph.Org Foundation */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(_mfrngcode_H) diff --git a/src/libopus/celt/modes.c b/src/libopus/celt/modes.c index 665c810..4c3ffcf 100644 --- a/src/libopus/celt/modes.c +++ b/src/libopus/celt/modes.c @@ -1,35 +1,35 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2008 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2008 Gregory Maxwell + Written by Jean-Marc Valin and Gregory Maxwell */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "celt.h" #include "modes.h" @@ -40,34 +40,34 @@ #include "cpu_support.h" static const opus_int16 eband5ms[] = { - /*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100 +/*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100 }; /* Alternate tuning (partially derived from Vorbis) */ #define BITALLOC_SIZE 11 /* Bit allocation table in units of 1/32 bit/sample (0.1875 dB SNR) */ static const unsigned char band_allocation[] = { - /*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 90, 80, 75, 69, 63, 56, 49, 40, 34, 29, 20, 18, 10, 0, 0, 0, 0, 0, 0, 0, 0, - 110, 100, 90, 84, 78, 71, 65, 58, 51, 45, 39, 32, 26, 20, 12, 0, 0, 0, 0, 0, 0, - 118, 110, 103, 93, 86, 80, 75, 70, 65, 59, 53, 47, 40, 31, 23, 15, 4, 0, 0, 0, 0, - 126, 119, 112, 104, 95, 89, 83, 78, 72, 66, 60, 54, 47, 39, 32, 25, 17, 12, 1, 0, 0, - 134, 127, 120, 114, 103, 97, 91, 85, 78, 72, 66, 60, 54, 47, 41, 35, 29, 23, 16, 10, 1, - 144, 137, 130, 124, 113, 107, 101, 95, 88, 82, 76, 70, 64, 57, 51, 45, 39, 33, 26, 15, 1, - 152, 145, 138, 132, 123, 117, 111, 105, 98, 92, 86, 80, 74, 67, 61, 55, 49, 43, 36, 20, 1, - 162, 155, 148, 142, 133, 127, 121, 115, 108, 102, 96, 90, 84, 77, 71, 65, 59, 53, 46, 30, 1, - 172, 165, 158, 152, 143, 137, 131, 125, 118, 112, 106, 100, 94, 87, 81, 75, 69, 63, 56, 45, 20, - 200, 200, 200, 200, 200, 200, 200, 200, 198, 193, 188, 183, 178, 173, 168, 163, 158, 153, 148, 129, 104, +/*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 90, 80, 75, 69, 63, 56, 49, 40, 34, 29, 20, 18, 10, 0, 0, 0, 0, 0, 0, 0, 0, +110,100, 90, 84, 78, 71, 65, 58, 51, 45, 39, 32, 26, 20, 12, 0, 0, 0, 0, 0, 0, +118,110,103, 93, 86, 80, 75, 70, 65, 59, 53, 47, 40, 31, 23, 15, 4, 0, 0, 0, 0, +126,119,112,104, 95, 89, 83, 78, 72, 66, 60, 54, 47, 39, 32, 25, 17, 12, 1, 0, 0, +134,127,120,114,103, 97, 91, 85, 78, 72, 66, 60, 54, 47, 41, 35, 29, 23, 16, 10, 1, +144,137,130,124,113,107,101, 95, 88, 82, 76, 70, 64, 57, 51, 45, 39, 33, 26, 15, 1, +152,145,138,132,123,117,111,105, 98, 92, 86, 80, 74, 67, 61, 55, 49, 43, 36, 20, 1, +162,155,148,142,133,127,121,115,108,102, 96, 90, 84, 77, 71, 65, 59, 53, 46, 30, 1, +172,165,158,152,143,137,131,125,118,112,106,100, 94, 87, 81, 75, 69, 63, 56, 45, 20, +200,200,200,200,200,200,200,200,198,193,188,183,178,173,168,163,158,153,148,129,104, }; #ifndef CUSTOM_MODES_ONLY -#ifdef FIXED_POINT -#include "static_modes_fixed.h" -#else -#include "static_modes_float.h" -#endif + #ifdef FIXED_POINT + #include "static_modes_fixed.h" + #else + #include "static_modes_float.h" + #endif #endif /* CUSTOM_MODES_ONLY */ #ifndef M_PI @@ -76,371 +76,370 @@ static const unsigned char band_allocation[] = { #ifdef CUSTOM_MODES -/* Defining 25 critical bands for the full 0-20 kHz audio bandwidth - Taken from http://ccrma.stanford.edu/~jos/bbt/Bark_Frequency_Scale.html */ +/* Defining 25 critical bands for the full 0-20 kHz audio bandwidth + Taken from http://ccrma.stanford.edu/~jos/bbt/Bark_Frequency_Scale.html */ #define BARK_BANDS 25 -static const opus_int16 bark_freq[BARK_BANDS + 1] = { - 0, 100, 200, 300, 400, +static const opus_int16 bark_freq[BARK_BANDS+1] = { + 0, 100, 200, 300, 400, 510, 630, 770, 920, 1080, - 1270, 1480, 1720, 2000, 2320, - 2700, 3150, 3700, 4400, 5300, - 6400, 7700, 9500, 12000, 15500, - 20000 -}; + 1270, 1480, 1720, 2000, 2320, + 2700, 3150, 3700, 4400, 5300, + 6400, 7700, 9500, 12000, 15500, + 20000}; -static opus_int16 *compute_ebands(opus_int32 Fs, int frame_size, int res, int *nbEBands) { - opus_int16 *eBands; - int i, j, lin, low, high, nBark, offset = 0; +static opus_int16 *compute_ebands(opus_int32 Fs, int frame_size, int res, int *nbEBands) +{ + opus_int16 *eBands; + int i, j, lin, low, high, nBark, offset=0; - /* All modes that have 2.5 ms short blocks use the same definition */ - if (Fs == 400 * (opus_int32)frame_size) { - *nbEBands = sizeof(eband5ms) / sizeof(eband5ms[0]) - 1; - eBands = opus_alloc(sizeof(opus_int16) * (*nbEBands + 1)); - for (i = 0; i < *nbEBands + 1; i++) { - eBands[i] = eband5ms[i]; - } - return eBands; - } - /* Find the number of critical bands supported by our sampling rate */ - for (nBark = 1; nBark < BARK_BANDS; nBark++) - if (bark_freq[nBark + 1] * 2 >= Fs) { - break; - } + /* All modes that have 2.5 ms short blocks use the same definition */ + if (Fs == 400*(opus_int32)frame_size) + { + *nbEBands = sizeof(eband5ms)/sizeof(eband5ms[0])-1; + eBands = opus_alloc(sizeof(opus_int16)*(*nbEBands+1)); + for (i=0;i<*nbEBands+1;i++) + eBands[i] = eband5ms[i]; + return eBands; + } + /* Find the number of critical bands supported by our sampling rate */ + for (nBark=1;nBark= Fs) + break; - /* Find where the linear part ends (i.e. where the spacing is more than min_width */ - for (lin = 0; lin < nBark; lin++) - if (bark_freq[lin + 1] - bark_freq[lin] >= res) { - break; - } + /* Find where the linear part ends (i.e. where the spacing is more than min_width */ + for (lin=0;lin= res) + break; - low = (bark_freq[lin] + res / 2) / res; - high = nBark - lin; - *nbEBands = low + high; - eBands = opus_alloc(sizeof(opus_int16) * (*nbEBands + 2)); + low = (bark_freq[lin]+res/2)/res; + high = nBark-lin; + *nbEBands = low+high; + eBands = opus_alloc(sizeof(opus_int16)*(*nbEBands+2)); - if (eBands == NULL) { - return NULL; - } + if (eBands==NULL) + return NULL; - /* Linear spacing (min_width) */ - for (i = 0; i < low; i++) { - eBands[i] = i; - } - if (low > 0) { - offset = eBands[low - 1] * res - bark_freq[lin - 1]; - } - /* Spacing follows critical bands */ - for (i = 0; i < high; i++) { - int target = bark_freq[lin + i]; - /* Round to an even value */ - eBands[i + low] = (target + offset / 2 + res) / (2 * res) * 2; - offset = eBands[i + low] * res - target; - } - /* Enforce the minimum spacing at the boundary */ - for (i = 0; i < *nbEBands; i++) - if (eBands[i] < i) { - eBands[i] = i; - } - /* Round to an even value */ - eBands[*nbEBands] = (bark_freq[nBark] + res) / (2 * res) * 2; - if (eBands[*nbEBands] > frame_size) { - eBands[*nbEBands] = frame_size; - } - for (i = 1; i < *nbEBands - 1; i++) { - if (eBands[i + 1] - eBands[i] < eBands[i] - eBands[i - 1]) { - eBands[i] -= (2 * eBands[i] - eBands[i - 1] - eBands[i + 1]) / 2; - } - } - /* Remove any empty bands. */ - for (i = j = 0; i < *nbEBands; i++) - if (eBands[i + 1] > eBands[j]) { - eBands[++j] = eBands[i + 1]; - } - *nbEBands = j; + /* Linear spacing (min_width) */ + for (i=0;i0) + offset = eBands[low-1]*res - bark_freq[lin-1]; + /* Spacing follows critical bands */ + for (i=0;i frame_size) + eBands[*nbEBands] = frame_size; + for (i=1;i<*nbEBands-1;i++) + { + if (eBands[i+1]-eBands[i] < eBands[i]-eBands[i-1]) + { + eBands[i] -= (2*eBands[i]-eBands[i-1]-eBands[i+1])/2; + } + } + /* Remove any empty bands. */ + for (i=j=0;i<*nbEBands;i++) + if(eBands[i+1]>eBands[j]) + eBands[++j]=eBands[i+1]; + *nbEBands=j; - for (i = 1; i < *nbEBands; i++) { - /* Every band must be smaller than the last band. */ - celt_assert(eBands[i] - eBands[i - 1] <= eBands[*nbEBands] - eBands[*nbEBands - 1]); - /* Each band must be no larger than twice the size of the previous one. */ - celt_assert(eBands[i + 1] - eBands[i] <= 2 * (eBands[i] - eBands[i - 1])); - } + for (i=1;i<*nbEBands;i++) + { + /* Every band must be smaller than the last band. */ + celt_assert(eBands[i]-eBands[i-1]<=eBands[*nbEBands]-eBands[*nbEBands-1]); + /* Each band must be no larger than twice the size of the previous one. */ + celt_assert(eBands[i+1]-eBands[i]<=2*(eBands[i]-eBands[i-1])); + } - return eBands; + return eBands; } -static void compute_allocation_table(CELTMode *mode) { - int i, j; - unsigned char *allocVectors; - int maxBands = sizeof(eband5ms) / sizeof(eband5ms[0]) - 1; +static void compute_allocation_table(CELTMode *mode) +{ + int i, j; + unsigned char *allocVectors; + int maxBands = sizeof(eband5ms)/sizeof(eband5ms[0])-1; - mode->nbAllocVectors = BITALLOC_SIZE; - allocVectors = opus_alloc(sizeof(unsigned char) * (BITALLOC_SIZE * mode->nbEBands)); - if (allocVectors == NULL) { - return; - } + mode->nbAllocVectors = BITALLOC_SIZE; + allocVectors = opus_alloc(sizeof(unsigned char)*(BITALLOC_SIZE*mode->nbEBands)); + if (allocVectors==NULL) + { + mode->allocVectors = NULL; + return; + } - /* Check for standard mode */ - if (mode->Fs == 400 * (opus_int32)mode->shortMdctSize) { - for (i = 0; i < BITALLOC_SIZE * mode->nbEBands; i++) { - allocVectors[i] = band_allocation[i]; - } - mode->allocVectors = allocVectors; - return; - } - /* If not the standard mode, interpolate */ - /* Compute per-codec-band allocation from per-critical-band matrix */ - for (i = 0; i < BITALLOC_SIZE; i++) { - for (j = 0; j < mode->nbEBands; j++) { - int k; - for (k = 0; k < maxBands; k++) { - if (400 * (opus_int32)eband5ms[k] > mode->eBands[j] * (opus_int32)mode->Fs / mode->shortMdctSize) { - break; - } - } - if (k > maxBands - 1) { - allocVectors[i * mode->nbEBands + j] = band_allocation[i * maxBands + maxBands - 1]; - } else { - opus_int32 a0, a1; - a1 = mode->eBands[j] * (opus_int32)mode->Fs / mode->shortMdctSize - 400 * (opus_int32)eband5ms[k - 1]; - a0 = 400 * (opus_int32)eband5ms[k] - mode->eBands[j] * (opus_int32)mode->Fs / mode->shortMdctSize; - allocVectors[i * mode->nbEBands + j] = (a0 * band_allocation[i * maxBands + k - 1] - + a1 * band_allocation[i * maxBands + k]) / (a0 + a1); - } - } - } + /* Check for standard mode */ + if (mode->Fs == 400*(opus_int32)mode->shortMdctSize) + { + for (i=0;inbEBands;i++) + allocVectors[i] = band_allocation[i]; + mode->allocVectors = allocVectors; + return; + } + /* If not the standard mode, interpolate */ + /* Compute per-codec-band allocation from per-critical-band matrix */ + for (i=0;inbEBands;j++) + { + int k; + for (k=0;k mode->eBands[j]*(opus_int32)mode->Fs/mode->shortMdctSize) + break; + } + if (k>maxBands-1) + allocVectors[i*mode->nbEBands+j] = band_allocation[i*maxBands + maxBands-1]; + else { + opus_int32 a0, a1; + a1 = mode->eBands[j]*(opus_int32)mode->Fs/mode->shortMdctSize - 400*(opus_int32)eband5ms[k-1]; + a0 = 400*(opus_int32)eband5ms[k] - mode->eBands[j]*(opus_int32)mode->Fs/mode->shortMdctSize; + allocVectors[i*mode->nbEBands+j] = (a0*band_allocation[i*maxBands+k-1] + + a1*band_allocation[i*maxBands+k])/(a0+a1); + } + } + } - /* printf ("\n"); - for (i=0;inbEBands;j++) - printf ("%d ", allocVectors[i*mode->nbEBands+j]); - printf ("\n"); - } - exit(0);*/ + /*printf ("\n"); + for (i=0;inbEBands;j++) + printf ("%d ", allocVectors[i*mode->nbEBands+j]); + printf ("\n"); + } + exit(0);*/ - mode->allocVectors = allocVectors; + mode->allocVectors = allocVectors; } #endif /* CUSTOM_MODES */ -CELTMode *opus_custom_mode_create(opus_int32 Fs, int frame_size, int *error) { - int i; +CELTMode *opus_custom_mode_create(opus_int32 Fs, int frame_size, int *error) +{ + int i; #ifdef CUSTOM_MODES - CELTMode *mode = NULL; - int res; - opus_val16 *window; - opus_int16 *logN; - int LM; - int arch = opus_select_arch(); - ALLOC_STACK; + CELTMode *mode=NULL; + int res; + opus_val16 *window; + opus_int16 *logN; + int LM; + int arch = opus_select_arch(); + ALLOC_STACK; #if !defined(VAR_ARRAYS) && !defined(USE_ALLOCA) - if (global_stack == NULL) { - goto failure; - } + if (global_stack==NULL) + goto failure; #endif #endif #ifndef CUSTOM_MODES_ONLY - for (i = 0; i < TOTAL_MODES; i++) { - int j; - for (j = 0; j < 4; j++) { - if (Fs == static_mode_list[i]->Fs && - (frame_size << j) == static_mode_list[i]->shortMdctSize * static_mode_list[i]->nbShortMdcts) { - if (error) { - *error = OPUS_OK; - } - return (CELTMode*)static_mode_list[i]; - } - } - } + for (i=0;iFs && + (frame_size<shortMdctSize*static_mode_list[i]->nbShortMdcts) + { + if (error) + *error = OPUS_OK; + return (CELTMode*)static_mode_list[i]; + } + } + } #endif /* CUSTOM_MODES_ONLY */ #ifndef CUSTOM_MODES - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; + if (error) + *error = OPUS_BAD_ARG; + return NULL; #else - /* The good thing here is that permutation of the arguments will automatically be invalid */ + /* The good thing here is that permutation of the arguments will automatically be invalid */ - if (Fs < 8000 || Fs > 96000) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } - if (frame_size < 40 || frame_size > 1024 || frame_size % 2 != 0) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } - /* Frames of less than 1ms are not supported. */ - if ((opus_int32)frame_size * 1000 < Fs) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } + if (Fs < 8000 || Fs > 96000) + { + if (error) + *error = OPUS_BAD_ARG; + return NULL; + } + if (frame_size < 40 || frame_size > 1024 || frame_size%2!=0) + { + if (error) + *error = OPUS_BAD_ARG; + return NULL; + } + /* Frames of less than 1ms are not supported. */ + if ((opus_int32)frame_size*1000 < Fs) + { + if (error) + *error = OPUS_BAD_ARG; + return NULL; + } - if ((opus_int32)frame_size * 75 >= Fs && (frame_size % 16) == 0) { - LM = 3; - } else if ((opus_int32)frame_size * 150 >= Fs && (frame_size % 8) == 0) { - LM = 2; - } else if ((opus_int32)frame_size * 300 >= Fs && (frame_size % 4) == 0) { - LM = 1; - } else { - LM = 0; - } + if ((opus_int32)frame_size*75 >= Fs && (frame_size%16)==0) + { + LM = 3; + } else if ((opus_int32)frame_size*150 >= Fs && (frame_size%8)==0) + { + LM = 2; + } else if ((opus_int32)frame_size*300 >= Fs && (frame_size%4)==0) + { + LM = 1; + } else + { + LM = 0; + } - /* Shorts longer than 3.3ms are not supported. */ - if ((opus_int32)(frame_size >> LM) * 300 > Fs) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } + /* Shorts longer than 3.3ms are not supported. */ + if ((opus_int32)(frame_size>>LM)*300 > Fs) + { + if (error) + *error = OPUS_BAD_ARG; + return NULL; + } - mode = opus_alloc(sizeof(CELTMode)); - if (mode == NULL) { - goto failure; - } - mode->Fs = Fs; + mode = opus_alloc(sizeof(CELTMode)); + if (mode==NULL) + goto failure; + mode->Fs = Fs; - /* Pre/de-emphasis depends on sampling rate. The "standard" pre-emphasis - is defined as A(z) = 1 - 0.85*z^-1 at 48 kHz. Other rates should - approximate that. */ - if (Fs < 12000) { /* 8 kHz */ - mode->preemph[0] = QCONST16(0.3500061035f, 15); - mode->preemph[1] = -QCONST16(0.1799926758f, 15); - mode->preemph[2] = QCONST16(0.2719968125f, SIG_SHIFT); /* exact 1/preemph[3] */ - mode->preemph[3] = QCONST16(3.6765136719f, 13); - } else if (Fs < 24000) { /* 16 kHz */ - mode->preemph[0] = QCONST16(0.6000061035f, 15); - mode->preemph[1] = -QCONST16(0.1799926758f, 15); - mode->preemph[2] = QCONST16(0.4424998650f, SIG_SHIFT); /* exact 1/preemph[3] */ - mode->preemph[3] = QCONST16(2.2598876953f, 13); - } else if (Fs < 40000) { /* 32 kHz */ - mode->preemph[0] = QCONST16(0.7799987793f, 15); - mode->preemph[1] = -QCONST16(0.1000061035f, 15); - mode->preemph[2] = QCONST16(0.7499771125f, SIG_SHIFT); /* exact 1/preemph[3] */ - mode->preemph[3] = QCONST16(1.3333740234f, 13); - } else { /* 48 kHz */ - mode->preemph[0] = QCONST16(0.8500061035f, 15); - mode->preemph[1] = QCONST16(0.0f, 15); - mode->preemph[2] = QCONST16(1.f, SIG_SHIFT); - mode->preemph[3] = QCONST16(1.f, 13); - } + /* Pre/de-emphasis depends on sampling rate. The "standard" pre-emphasis + is defined as A(z) = 1 - 0.85*z^-1 at 48 kHz. Other rates should + approximate that. */ + if(Fs < 12000) /* 8 kHz */ + { + mode->preemph[0] = QCONST16(0.3500061035f, 15); + mode->preemph[1] = -QCONST16(0.1799926758f, 15); + mode->preemph[2] = QCONST16(0.2719968125f, SIG_SHIFT); /* exact 1/preemph[3] */ + mode->preemph[3] = QCONST16(3.6765136719f, 13); + } else if(Fs < 24000) /* 16 kHz */ + { + mode->preemph[0] = QCONST16(0.6000061035f, 15); + mode->preemph[1] = -QCONST16(0.1799926758f, 15); + mode->preemph[2] = QCONST16(0.4424998650f, SIG_SHIFT); /* exact 1/preemph[3] */ + mode->preemph[3] = QCONST16(2.2598876953f, 13); + } else if(Fs < 40000) /* 32 kHz */ + { + mode->preemph[0] = QCONST16(0.7799987793f, 15); + mode->preemph[1] = -QCONST16(0.1000061035f, 15); + mode->preemph[2] = QCONST16(0.7499771125f, SIG_SHIFT); /* exact 1/preemph[3] */ + mode->preemph[3] = QCONST16(1.3333740234f, 13); + } else /* 48 kHz */ + { + mode->preemph[0] = QCONST16(0.8500061035f, 15); + mode->preemph[1] = QCONST16(0.0f, 15); + mode->preemph[2] = QCONST16(1.f, SIG_SHIFT); + mode->preemph[3] = QCONST16(1.f, 13); + } - mode->maxLM = LM; - mode->nbShortMdcts = 1 << LM; - mode->shortMdctSize = frame_size / mode->nbShortMdcts; - res = (mode->Fs + mode->shortMdctSize) / (2 * mode->shortMdctSize); + mode->maxLM = LM; + mode->nbShortMdcts = 1<shortMdctSize = frame_size/mode->nbShortMdcts; + res = (mode->Fs+mode->shortMdctSize)/(2*mode->shortMdctSize); - mode->eBands = compute_ebands(Fs, mode->shortMdctSize, res, &mode->nbEBands); - if (mode->eBands == NULL) { - goto failure; - } + mode->eBands = compute_ebands(Fs, mode->shortMdctSize, res, &mode->nbEBands); + if (mode->eBands==NULL) + goto failure; #if !defined(SMALL_FOOTPRINT) - /* Make sure we don't allocate a band larger than our PVQ table. - 208 should be enough, but let's be paranoid. */ - if ((mode->eBands[mode->nbEBands] - mode->eBands[mode->nbEBands - 1]) << LM > - 208) { - goto failure; - } + /* Make sure we don't allocate a band larger than our PVQ table. + 208 should be enough, but let's be paranoid. */ + if ((mode->eBands[mode->nbEBands] - mode->eBands[mode->nbEBands-1])< + 208) { + goto failure; + } #endif - mode->effEBands = mode->nbEBands; - while (mode->eBands[mode->effEBands] > mode->shortMdctSize) { - mode->effEBands--; - } + mode->effEBands = mode->nbEBands; + while (mode->eBands[mode->effEBands] > mode->shortMdctSize) + mode->effEBands--; - /* Overlap must be divisible by 4 */ - mode->overlap = ((mode->shortMdctSize >> 2) << 2); + /* Overlap must be divisible by 4 */ + mode->overlap = ((mode->shortMdctSize>>2)<<2); - compute_allocation_table(mode); - if (mode->allocVectors == NULL) { - goto failure; - } + compute_allocation_table(mode); + if (mode->allocVectors==NULL) + goto failure; - window = (opus_val16*)opus_alloc(mode->overlap * sizeof(opus_val16)); - if (window == NULL) { - goto failure; - } + window = (opus_val16*)opus_alloc(mode->overlap*sizeof(opus_val16)); + if (window==NULL) + goto failure; #ifndef FIXED_POINT - for (i = 0; i < mode->overlap; i++) { - window[i] = Q15ONE * sin(.5 * M_PI * sin(.5 * M_PI * (i + .5) / mode->overlap) * sin(.5 * M_PI * (i + .5) / mode->overlap)); - } + for (i=0;ioverlap;i++) + window[i] = Q15ONE*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap)); #else - for (i = 0; i < mode->overlap; i++) { - window[i] = MIN32(32767, floor(.5 + 32768.*sin(.5 * M_PI * sin(.5 * M_PI * (i + .5) / mode->overlap) * sin(.5 * M_PI * (i + .5) / mode->overlap)))); - } + for (i=0;ioverlap;i++) + window[i] = MIN32(32767,floor(.5+32768.*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap)))); #endif - mode->window = window; + mode->window = window; - logN = (opus_int16*)opus_alloc(mode->nbEBands * sizeof(opus_int16)); - if (logN == NULL) { - goto failure; - } + logN = (opus_int16*)opus_alloc(mode->nbEBands*sizeof(opus_int16)); + if (logN==NULL) + goto failure; - for (i = 0; i < mode->nbEBands; i++) { - logN[i] = log2_frac(mode->eBands[i + 1] - mode->eBands[i], BITRES); - } - mode->logN = logN; + for (i=0;inbEBands;i++) + logN[i] = log2_frac(mode->eBands[i+1]-mode->eBands[i], BITRES); + mode->logN = logN; - compute_pulse_cache(mode, mode->maxLM); + compute_pulse_cache(mode, mode->maxLM); - if (clt_mdct_init(&mode->mdct, 2 * mode->shortMdctSize * mode->nbShortMdcts, - mode->maxLM, arch) == 0) { - goto failure; - } + if (clt_mdct_init(&mode->mdct, 2*mode->shortMdctSize*mode->nbShortMdcts, + mode->maxLM, arch) == 0) + goto failure; - if (error) { - *error = OPUS_OK; - } + if (error) + *error = OPUS_OK; - return mode; + return mode; failure: - if (error) { - *error = OPUS_ALLOC_FAIL; - } - if (mode != NULL) { - opus_custom_mode_destroy(mode); - } - return NULL; + if (error) + *error = OPUS_ALLOC_FAIL; + if (mode!=NULL) + opus_custom_mode_destroy(mode); + return NULL; #endif /* !CUSTOM_MODES */ } #ifdef CUSTOM_MODES -void opus_custom_mode_destroy(CELTMode *mode) { - int arch = opus_select_arch(); +void opus_custom_mode_destroy(CELTMode *mode) +{ + int arch = opus_select_arch(); - if (mode == NULL) { - return; - } + if (mode == NULL) + return; #ifndef CUSTOM_MODES_ONLY - { - int i; - for (i = 0; i < TOTAL_MODES; i++) { - if (mode == static_mode_list[i]) { - return; - } + { + int i; + for (i=0;ieBands); - opus_free((unsigned char*)mode->allocVectors); + opus_free((opus_int16*)mode->eBands); + opus_free((unsigned char*)mode->allocVectors); - opus_free((opus_val16*)mode->window); - opus_free((opus_int16*)mode->logN); + opus_free((opus_val16*)mode->window); + opus_free((opus_int16*)mode->logN); - opus_free((opus_int16*)mode->cache.index); - opus_free((unsigned char*)mode->cache.bits); - opus_free((unsigned char*)mode->cache.caps); - clt_mdct_clear(&mode->mdct, arch); + opus_free((opus_int16*)mode->cache.index); + opus_free((unsigned char*)mode->cache.bits); + opus_free((unsigned char*)mode->cache.caps); + clt_mdct_clear(&mode->mdct, arch); - opus_free((CELTMode *)mode); + opus_free((CELTMode *)mode); } #endif diff --git a/src/libopus/celt/modes.h b/src/libopus/celt/modes.h index dc6d023..be813cc 100644 --- a/src/libopus/celt/modes.h +++ b/src/libopus/celt/modes.h @@ -1,36 +1,36 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2008 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2008 Gregory Maxwell + Written by Jean-Marc Valin and Gregory Maxwell */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef MODES_H #define MODES_H -#include "../opus_types.h" +#include "opus_types.h" #include "celt.h" #include "arch.h" #include "mdct.h" @@ -40,35 +40,35 @@ #define MAX_PERIOD 1024 typedef struct { - int size; - const opus_int16 *index; - const unsigned char *bits; - const unsigned char *caps; + int size; + const opus_int16 *index; + const unsigned char *bits; + const unsigned char *caps; } PulseCache; /** Mode definition (opaque) - @brief Mode definition -*/ + @brief Mode definition + */ struct OpusCustomMode { - opus_int32 Fs; - int overlap; + opus_int32 Fs; + int overlap; - int nbEBands; - int effEBands; - opus_val16 preemph[4]; - const opus_int16 *eBands; /**< Definition for each "pseudo-critical band" */ + int nbEBands; + int effEBands; + opus_val16 preemph[4]; + const opus_int16 *eBands; /**< Definition for each "pseudo-critical band" */ - int maxLM; - int nbShortMdcts; - int shortMdctSize; + int maxLM; + int nbShortMdcts; + int shortMdctSize; - int nbAllocVectors; /**< Number of lines in the matrix below */ - const unsigned char *allocVectors; /**< Number of bits in each band for several rates */ - const opus_int16 *logN; + int nbAllocVectors; /**< Number of lines in the matrix below */ + const unsigned char *allocVectors; /**< Number of bits in each band for several rates */ + const opus_int16 *logN; - const opus_val16 *window; - mdct_lookup mdct; - PulseCache cache; + const opus_val16 *window; + mdct_lookup mdct; + PulseCache cache; }; diff --git a/src/libopus/celt/opus.h b/src/libopus/celt/opus.h new file mode 100644 index 0000000..0a1b59c --- /dev/null +++ b/src/libopus/celt/opus.h @@ -0,0 +1 @@ +#include "../include/opus.h" diff --git a/src/libopus/celt/opus_custom.h b/src/libopus/celt/opus_custom.h new file mode 100644 index 0000000..f54a103 --- /dev/null +++ b/src/libopus/celt/opus_custom.h @@ -0,0 +1 @@ +#include "../include/opus_custom.h" diff --git a/src/libopus/celt/opus_defines.h b/src/libopus/celt/opus_defines.h new file mode 100644 index 0000000..dcc2443 --- /dev/null +++ b/src/libopus/celt/opus_defines.h @@ -0,0 +1 @@ +#include "../include/opus_defines.h" diff --git a/src/libopus/celt/opus_multistream.h b/src/libopus/celt/opus_multistream.h new file mode 100644 index 0000000..89f6229 --- /dev/null +++ b/src/libopus/celt/opus_multistream.h @@ -0,0 +1 @@ +#include "../include/opus_multistream.h" diff --git a/src/libopus/celt/opus_projection.h b/src/libopus/celt/opus_projection.h new file mode 100644 index 0000000..72f59cc --- /dev/null +++ b/src/libopus/celt/opus_projection.h @@ -0,0 +1 @@ +#include "../include/opus_projection.h" diff --git a/src/libopus/celt/opus_types.h b/src/libopus/celt/opus_types.h new file mode 100644 index 0000000..a7958a5 --- /dev/null +++ b/src/libopus/celt/opus_types.h @@ -0,0 +1 @@ +#include "../include/opus_types.h" diff --git a/src/libopus/celt/os_support.h b/src/libopus/celt/os_support.h index 32eedb9..7d2d378 100644 --- a/src/libopus/celt/os_support.h +++ b/src/libopus/celt/os_support.h @@ -1,31 +1,31 @@ -/* Copyright (C) 2007 Jean-Marc Valin +/* Copyright (C) 2007 Jean-Marc Valin - File: os_support.h - This is the (tiny) OS abstraction layer. Aside from math.h, this is the - only place where system headers are allowed. + File: os_support.h + This is the (tiny) OS abstraction layer. Aside from math.h, this is the + only place where system headers are allowed. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. */ #ifndef OS_SUPPORT_H @@ -35,32 +35,42 @@ # include "custom_support.h" #endif -#include "../opus_types.h" -#include "../opus_defines.h" +#include "opus_types.h" +#include "opus_defines.h" #include -#include #include -/** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */ +/** Opus wrapper for malloc(). To do your own dynamic allocation replace this function, opus_realloc, and opus_free */ #ifndef OVERRIDE_OPUS_ALLOC -static OPUS_INLINE void *opus_alloc(size_t size) { - return malloc(size); +static OPUS_INLINE void *opus_alloc (size_t size) +{ + return malloc(size); } #endif -/** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */ +#ifndef OVERRIDE_OPUS_REALLOC +static OPUS_INLINE void *opus_realloc (void *ptr, size_t size) +{ + return realloc(ptr, size); +} +#endif + +/** Used only for non-threadsafe pseudostack. + If desired, this can always return the same area of memory rather than allocating a new one every time. */ #ifndef OVERRIDE_OPUS_ALLOC_SCRATCH -static OPUS_INLINE void *opus_alloc_scratch(size_t size) { - /* Scratch space doesn't need to be cleared */ - return opus_alloc(size); +static OPUS_INLINE void *opus_alloc_scratch (size_t size) +{ + /* Scratch space doesn't need to be cleared */ + return opus_alloc(size); } #endif -/** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */ +/** Opus wrapper for free(). To do your own dynamic allocation replace this function, opus_realloc, and opus_free */ #ifndef OVERRIDE_OPUS_FREE -static OPUS_INLINE void opus_free(void *ptr) { - free(ptr); +static OPUS_INLINE void opus_free (void *ptr) +{ + free(ptr); } #endif @@ -80,10 +90,10 @@ static OPUS_INLINE void opus_free(void *ptr) { #define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst)))) #endif -/* #ifdef __GNUC__ - #pragma GCC poison printf sprintf - #pragma GCC poison malloc free realloc calloc - #endif*/ +/*#ifdef __GNUC__ +#pragma GCC poison printf sprintf +#pragma GCC poison malloc free realloc calloc +#endif*/ #endif /* OS_SUPPORT_H */ diff --git a/src/libopus/celt/pitch.c b/src/libopus/celt/pitch.c index ec435a5..9bc9916 100644 --- a/src/libopus/celt/pitch.c +++ b/src/libopus/celt/pitch.c @@ -1,39 +1,39 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /** - @file pitch.c - @brief Pitch analysis -*/ + @file pitch.c + @brief Pitch analysis + */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "pitch.h" #include "os_support.h" @@ -47,158 +47,173 @@ static void find_best_pitch(opus_val32 *xcorr, opus_val16 *y, int len, #ifdef FIXED_POINT , int yshift, opus_val32 maxcorr #endif - ) { - int i, j; - opus_val32 Syy = 1; - opus_val16 best_num[2]; - opus_val32 best_den[2]; + ) +{ + int i, j; + opus_val32 Syy=1; + opus_val16 best_num[2]; + opus_val32 best_den[2]; #ifdef FIXED_POINT - int xshift; + int xshift; - xshift = celt_ilog2(maxcorr) - 14; + xshift = celt_ilog2(maxcorr)-14; #endif - best_num[0] = -1; - best_num[1] = -1; - best_den[0] = 0; - best_den[1] = 0; - best_pitch[0] = 0; - best_pitch[1] = 1; - for (j = 0; j < len; j++) { - Syy = ADD32(Syy, SHR32(MULT16_16(y[j], y[j]), yshift)); - } - for (i = 0; i < max_pitch; i++) { - if (xcorr[i] > 0) { - opus_val16 num; - opus_val32 xcorr16; - xcorr16 = EXTRACT16(VSHR32(xcorr[i], xshift)); + best_num[0] = -1; + best_num[1] = -1; + best_den[0] = 0; + best_den[1] = 0; + best_pitch[0] = 0; + best_pitch[1] = 1; + for (j=0;j0) + { + opus_val16 num; + opus_val32 xcorr16; + xcorr16 = EXTRACT16(VSHR32(xcorr[i], xshift)); #ifndef FIXED_POINT - /* Considering the range of xcorr16, this should avoid both underflows - and overflows (inf) when squaring xcorr16 */ - xcorr16 *= 1e-12f; + /* Considering the range of xcorr16, this should avoid both underflows + and overflows (inf) when squaring xcorr16 */ + xcorr16 *= 1e-12f; #endif - num = MULT16_16_Q15(xcorr16, xcorr16); - if (MULT16_32_Q15(num, best_den[1]) > MULT16_32_Q15(best_num[1], Syy)) { - if (MULT16_32_Q15(num, best_den[0]) > MULT16_32_Q15(best_num[0], Syy)) { - best_num[1] = best_num[0]; - best_den[1] = best_den[0]; - best_pitch[1] = best_pitch[0]; - best_num[0] = num; - best_den[0] = Syy; - best_pitch[0] = i; - } else { - best_num[1] = num; - best_den[1] = Syy; - best_pitch[1] = i; - } + num = MULT16_16_Q15(xcorr16,xcorr16); + if (MULT16_32_Q15(num,best_den[1]) > MULT16_32_Q15(best_num[1],Syy)) + { + if (MULT16_32_Q15(num,best_den[0]) > MULT16_32_Q15(best_num[0],Syy)) + { + best_num[1] = best_num[0]; + best_den[1] = best_den[0]; + best_pitch[1] = best_pitch[0]; + best_num[0] = num; + best_den[0] = Syy; + best_pitch[0] = i; + } else { + best_num[1] = num; + best_den[1] = Syy; + best_pitch[1] = i; } - } - Syy += SHR32(MULT16_16(y[i + len], y[i + len]), yshift) - SHR32(MULT16_16(y[i], y[i]), yshift); - Syy = MAX32(1, Syy); - } + } + } + Syy += SHR32(MULT16_16(y[i+len],y[i+len]),yshift) - SHR32(MULT16_16(y[i],y[i]),yshift); + Syy = MAX32(1, Syy); + } } static void celt_fir5(opus_val16 *x, - const opus_val16 *num, - int N) { - int i; - opus_val16 num0, num1, num2, num3, num4; - opus_val32 mem0, mem1, mem2, mem3, mem4; - num0 = num[0]; - num1 = num[1]; - num2 = num[2]; - num3 = num[3]; - num4 = num[4]; - mem0 = 0; - mem1 = 0; - mem2 = 0; - mem3 = 0; - mem4 = 0; - for (i = 0; i < N; i++) { - opus_val32 sum = SHL32(EXTEND32(x[i]), SIG_SHIFT); - sum = MAC16_16(sum, num0, mem0); - sum = MAC16_16(sum, num1, mem1); - sum = MAC16_16(sum, num2, mem2); - sum = MAC16_16(sum, num3, mem3); - sum = MAC16_16(sum, num4, mem4); - mem4 = mem3; - mem3 = mem2; - mem2 = mem1; - mem1 = mem0; - mem0 = x[i]; - x[i] = ROUND16(sum, SIG_SHIFT); - } + const opus_val16 *num, + int N) +{ + int i; + opus_val16 num0, num1, num2, num3, num4; + opus_val32 mem0, mem1, mem2, mem3, mem4; + num0=num[0]; + num1=num[1]; + num2=num[2]; + num3=num[3]; + num4=num[4]; + mem0=0; + mem1=0; + mem2=0; + mem3=0; + mem4=0; + for (i=0;i> 1; i++) { - x_lp[i] = SHR32(HALF32(HALF32(x[0][(2 * i - 1)] + x[0][(2 * i + 1)]) + x[0][2 * i]), shift); - } - x_lp[0] = SHR32(HALF32(HALF32(x[0][1]) + x[0][0]), shift); - if (C == 2) { - for (i = 1; i> 1; i++) { - x_lp[i] += SHR32(HALF32(HALF32(x[1][(2 * i - 1)] + x[1][(2 * i + 1)]) + x[1][2 * i]), shift); - } - x_lp[0] += SHR32(HALF32(HALF32(x[1][1]) + x[1][0]), shift); - } - - _celt_autocorr(x_lp, ac, NULL, 0, - 4, len >> 1, arch); - - /* Noise floor -40 dB */ -#ifdef FIXED_POINT - ac[0] += SHR32(ac[0], 13); + int shift; + opus_val32 maxabs = celt_maxabs32(x[0], len); + if (C==2) + { + opus_val32 maxabs_1 = celt_maxabs32(x[1], len); + maxabs = MAX32(maxabs, maxabs_1); + } + if (maxabs<1) + maxabs=1; + shift = celt_ilog2(maxabs)-10; + if (shift<0) + shift=0; + if (C==2) + shift++; + for (i=1;i>1;i++) + x_lp[i] = SHR32(x[0][(2*i-1)], shift+2) + SHR32(x[0][(2*i+1)], shift+2) + SHR32(x[0][2*i], shift+1); + x_lp[0] = SHR32(x[0][1], shift+2) + SHR32(x[0][0], shift+1); + if (C==2) + { + for (i=1;i>1;i++) + x_lp[i] += SHR32(x[1][(2*i-1)], shift+2) + SHR32(x[1][(2*i+1)], shift+2) + SHR32(x[1][2*i], shift+1); + x_lp[0] += SHR32(x[1][1], shift+2) + SHR32(x[1][0], shift+1); + } #else - ac[0] *= 1.0001f; + for (i=1;i>1;i++) + x_lp[i] = .25f*x[0][(2*i-1)] + .25f*x[0][(2*i+1)] + .5f*x[0][2*i]; + x_lp[0] = .25f*x[0][1] + .5f*x[0][0]; + if (C==2) + { + for (i=1;i>1;i++) + x_lp[i] += .25f*x[1][(2*i-1)] + .25f*x[1][(2*i+1)] + .5f*x[1][2*i]; + x_lp[0] += .25f*x[1][1] + .5f*x[1][0]; + } #endif - /* Lag windowing */ - for (i = 1; i <= 4; i++) { - /*ac[i] *= exp(-.5*(2*M_PI*.002*i)*(2*M_PI*.002*i));*/ -#ifdef FIXED_POINT - ac[i] -= MULT16_32_Q15(2 * i * i, ac[i]); -#else - ac[i] -= ac[i] * (.008f * i) * (.008f * i); -#endif - } + _celt_autocorr(x_lp, ac, NULL, 0, + 4, len>>1, arch); - _celt_lpc(lpc, ac, 4); - for (i = 0; i < 4; i++) { - tmp = MULT16_16_Q15(QCONST16(.9f, 15), tmp); - lpc[i] = MULT16_16_Q15(lpc[i], tmp); - } - /* Add a zero */ - lpc2[0] = lpc[0] + QCONST16(.8f, SIG_SHIFT); - lpc2[1] = lpc[1] + MULT16_16_Q15(c1, lpc[0]); - lpc2[2] = lpc[2] + MULT16_16_Q15(c1, lpc[1]); - lpc2[3] = lpc[3] + MULT16_16_Q15(c1, lpc[2]); - lpc2[4] = MULT16_16_Q15(c1, lpc[3]); - celt_fir5(x_lp, lpc2, len >> 1); + /* Noise floor -40 dB */ +#ifdef FIXED_POINT + ac[0] += SHR32(ac[0],13); +#else + ac[0] *= 1.0001f; +#endif + /* Lag windowing */ + for (i=1;i<=4;i++) + { + /*ac[i] *= exp(-.5*(2*M_PI*.002*i)*(2*M_PI*.002*i));*/ +#ifdef FIXED_POINT + ac[i] -= MULT16_32_Q15(2*i*i, ac[i]); +#else + ac[i] -= ac[i]*(.008f*i)*(.008f*i); +#endif + } + + _celt_lpc(lpc, ac, 4); + for (i=0;i<4;i++) + { + tmp = MULT16_16_Q15(QCONST16(.9f,15), tmp); + lpc[i] = MULT16_16_Q15(lpc[i], tmp); + } + /* Add a zero */ + lpc2[0] = lpc[0] + QCONST16(.8f,SIG_SHIFT); + lpc2[1] = lpc[1] + MULT16_16_Q15(c1,lpc[0]); + lpc2[2] = lpc[2] + MULT16_16_Q15(c1,lpc[1]); + lpc2[3] = lpc[3] + MULT16_16_Q15(c1,lpc[2]); + lpc2[4] = MULT16_16_Q15(c1,lpc[3]); + celt_fir5(x_lp, lpc2, len>>1); } /* Pure C implementation. */ @@ -208,326 +223,333 @@ opus_val32 void #endif celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, - opus_val32 *xcorr, int len, int max_pitch, int arch) { + opus_val32 *xcorr, int len, int max_pitch, int arch) +{ #if 0 /* This is a simple version of the pitch correlation that should work well on DSPs like Blackfin and TI C5x/C6x */ - int i, j; + int i, j; #ifdef FIXED_POINT - opus_val32 maxcorr = 1; + opus_val32 maxcorr=1; #endif #if !defined(OVERRIDE_PITCH_XCORR) - (void)arch; + (void)arch; #endif - for (i = 0; i < max_pitch; i++) { - opus_val32 sum = 0; - for (j = 0; j < len; j++) { - sum = MAC16_16(sum, _x[j], _y[i + j]); - } - xcorr[i] = sum; + for (i=0;i 0); - celt_sig_assert((((unsigned char *)_x - (unsigned char *)NULL) & 3) == 0); - for (i = 0; i < max_pitch - 3; i += 4) { - opus_val32 sum[4] = {0, 0, 0, 0}; - xcorr_kernel(_x, _y + i, sum, len, arch); - xcorr[i] = sum[0]; - xcorr[i + 1] = sum[1]; - xcorr[i + 2] = sum[2]; - xcorr[i + 3] = sum[3]; -#ifdef FIXED_POINT - sum[0] = MAX32(sum[0], sum[1]); - sum[2] = MAX32(sum[2], sum[3]); - sum[0] = MAX32(sum[0], sum[2]); - maxcorr = MAX32(maxcorr, sum[0]); + celt_assert(max_pitch>0); + celt_sig_assert(((size_t)_x&3)==0); + for (i=0;i 0); - celt_assert(max_pitch > 0); - lag = len + max_pitch; + celt_assert(len>0); + celt_assert(max_pitch>0); + lag = len+max_pitch; - ALLOC(x_lp4, len >> 2, opus_val16); - ALLOC(y_lp4, lag >> 2, opus_val16); - ALLOC(xcorr, max_pitch >> 1, opus_val32); + ALLOC(x_lp4, len>>2, opus_val16); + ALLOC(y_lp4, lag>>2, opus_val16); + ALLOC(xcorr, max_pitch>>1, opus_val32); - /* Downsample by 2 again */ - for (j = 0; j> 2; j++) { - x_lp4[j] = x_lp[2 * j]; - } - for (j = 0; j> 2; j++) { - y_lp4[j] = y[2 * j]; - } + /* Downsample by 2 again */ + for (j=0;j>2;j++) + x_lp4[j] = x_lp[2*j]; + for (j=0;j>2;j++) + y_lp4[j] = y[2*j]; #ifdef FIXED_POINT - xmax = celt_maxabs16(x_lp4, len >> 2); - ymax = celt_maxabs16(y_lp4, lag >> 2); - shift = celt_ilog2(MAX32(1, MAX32(xmax, ymax))) - 11; - if (shift > 0) { - for (j = 0; j> 2; j++) { - x_lp4[j] = SHR16(x_lp4[j], shift); - } - for (j = 0; j> 2; j++) { - y_lp4[j] = SHR16(y_lp4[j], shift); - } - /* Use double the shift for a MAC */ - shift *= 2; - } else { - shift = 0; - } + xmax = celt_maxabs16(x_lp4, len>>2); + ymax = celt_maxabs16(y_lp4, lag>>2); + shift = celt_ilog2(MAX32(1, MAX32(xmax, ymax)))-11; + if (shift>0) + { + for (j=0;j>2;j++) + x_lp4[j] = SHR16(x_lp4[j], shift); + for (j=0;j>2;j++) + y_lp4[j] = SHR16(y_lp4[j], shift); + /* Use double the shift for a MAC */ + shift *= 2; + } else { + shift = 0; + } #endif - /* Coarse search with 4x decimation */ + /* Coarse search with 4x decimation */ #ifdef FIXED_POINT - maxcorr = + maxcorr = #endif - celt_pitch_xcorr(x_lp4, y_lp4, xcorr, len >> 2, max_pitch >> 2, arch); + celt_pitch_xcorr(x_lp4, y_lp4, xcorr, len>>2, max_pitch>>2, arch); - find_best_pitch(xcorr, y_lp4, len >> 2, max_pitch >> 2, best_pitch + find_best_pitch(xcorr, y_lp4, len>>2, max_pitch>>2, best_pitch #ifdef FIXED_POINT - , 0, maxcorr + , 0, maxcorr #endif ); - /* Finer search with 2x decimation */ + /* Finer search with 2x decimation */ #ifdef FIXED_POINT - maxcorr = 1; + maxcorr=1; #endif - for (i = 0; i> 1; i++) { - opus_val32 sum; - xcorr[i] = 0; - if (abs(i - 2 * best_pitch[0]) > 2 && abs(i - 2 * best_pitch[1]) > 2) { - continue; - } + for (i=0;i>1;i++) + { + opus_val32 sum; + xcorr[i] = 0; + if (abs(i-2*best_pitch[0])>2 && abs(i-2*best_pitch[1])>2) + continue; #ifdef FIXED_POINT - sum = 0; - for (j = 0; j> 1; j++) { - sum += SHR32(MULT16_16(x_lp[j], y[i + j]), shift); - } + sum = 0; + for (j=0;j>1;j++) + sum += SHR32(MULT16_16(x_lp[j],y[i+j]), shift); #else - sum = celt_inner_prod(x_lp, y + i, len >> 1, arch); + sum = celt_inner_prod(x_lp, y+i, len>>1, arch); #endif - xcorr[i] = MAX32(-1, sum); + xcorr[i] = MAX32(-1, sum); #ifdef FIXED_POINT - maxcorr = MAX32(maxcorr, sum); + maxcorr = MAX32(maxcorr, sum); #endif - } - find_best_pitch(xcorr, y, len >> 1, max_pitch >> 1, best_pitch + } + find_best_pitch(xcorr, y, len>>1, max_pitch>>1, best_pitch #ifdef FIXED_POINT - , shift + 1, maxcorr + , shift+1, maxcorr #endif ); - /* Refine by pseudo-interpolation */ - if (best_pitch[0] > 0 && best_pitch[0] < (max_pitch >> 1) - 1) { - opus_val32 a, b, c; - a = xcorr[best_pitch[0] - 1]; - b = xcorr[best_pitch[0]]; - c = xcorr[best_pitch[0] + 1]; - if ((c - a) > MULT16_32_Q15(QCONST16(.7f, 15), b - a)) { - offset = 1; - } else if ((a - c) > MULT16_32_Q15(QCONST16(.7f, 15), b - c)) { - offset = -1; - } else { - offset = 0; - } - } else { - offset = 0; - } - *pitch = 2 * best_pitch[0] - offset; + /* Refine by pseudo-interpolation */ + if (best_pitch[0]>0 && best_pitch[0]<(max_pitch>>1)-1) + { + opus_val32 a, b, c; + a = xcorr[best_pitch[0]-1]; + b = xcorr[best_pitch[0]]; + c = xcorr[best_pitch[0]+1]; + if ((c-a) > MULT16_32_Q15(QCONST16(.7f,15),b-a)) + offset = 1; + else if ((a-c) > MULT16_32_Q15(QCONST16(.7f,15),b-c)) + offset = -1; + else + offset = 0; + } else { + offset = 0; + } + *pitch = 2*best_pitch[0]-offset; - RESTORE_STACK; + RESTORE_STACK; } #ifdef FIXED_POINT -static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy) { - opus_val32 x2y2; - int sx, sy, shift; - opus_val32 g; - opus_val16 den; - if (xy == 0 || xx == 0 || yy == 0) { - return 0; - } - sx = celt_ilog2(xx) - 14; - sy = celt_ilog2(yy) - 14; - shift = sx + sy; - x2y2 = SHR32(MULT16_16(VSHR32(xx, sx), VSHR32(yy, sy)), 14); - if (shift & 1) { - if (x2y2 < 32768) { - x2y2 <<= 1; - shift--; - } else { - x2y2 >>= 1; - shift++; - } - } - den = celt_rsqrt_norm(x2y2); - g = MULT16_32_Q15(den, xy); - g = VSHR32(g, (shift >> 1) - 1); - return EXTRACT16(MIN32(g, Q15ONE)); +static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy) +{ + opus_val32 x2y2; + int sx, sy, shift; + opus_val32 g; + opus_val16 den; + if (xy == 0 || xx == 0 || yy == 0) + return 0; + sx = celt_ilog2(xx)-14; + sy = celt_ilog2(yy)-14; + shift = sx + sy; + x2y2 = SHR32(MULT16_16(VSHR32(xx, sx), VSHR32(yy, sy)), 14); + if (shift & 1) { + if (x2y2 < 32768) + { + x2y2 <<= 1; + shift--; + } else { + x2y2 >>= 1; + shift++; + } + } + den = celt_rsqrt_norm(x2y2); + g = MULT16_32_Q15(den, xy); + g = VSHR32(g, (shift>>1)-1); + return EXTRACT16(MIN32(g, Q15ONE)); } #else -static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy) { - return xy / celt_sqrt(1 + xx * yy); +static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy) +{ + return xy/celt_sqrt(1+xx*yy); } #endif static const int second_check[16] = {0, 0, 3, 2, 3, 2, 5, 2, 3, 2, 3, 2, 5, 2, 3, 2}; opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, - int N, int *T0_, int prev_period, opus_val16 prev_gain, int arch) { - int k, i, T, T0; - opus_val16 g, g0; - opus_val16 pg; - opus_val32 xy, xx, yy, xy2; - opus_val32 xcorr[3]; - opus_val32 best_xy, best_yy; - int offset; - int minperiod0; - VARDECL(opus_val32, yy_lookup); - SAVE_STACK; + int N, int *T0_, int prev_period, opus_val16 prev_gain, int arch) +{ + int k, i, T, T0; + opus_val16 g, g0; + opus_val16 pg; + opus_val32 xy,xx,yy,xy2; + opus_val32 xcorr[3]; + opus_val32 best_xy, best_yy; + int offset; + int minperiod0; + VARDECL(opus_val32, yy_lookup); + SAVE_STACK; - minperiod0 = minperiod; - maxperiod /= 2; - minperiod /= 2; - *T0_ /= 2; - prev_period /= 2; - N /= 2; - x += maxperiod; - if (*T0_ >= maxperiod) { - *T0_ = maxperiod - 1; - } + minperiod0 = minperiod; + maxperiod /= 2; + minperiod /= 2; + *T0_ /= 2; + prev_period /= 2; + N /= 2; + x += maxperiod; + if (*T0_>=maxperiod) + *T0_=maxperiod-1; - T = T0 = *T0_; - ALLOC(yy_lookup, maxperiod + 1, opus_val32); - dual_inner_prod(x, x, x - T0, N, &xx, &xy, arch); - yy_lookup[0] = xx; - yy = xx; - for (i = 1; i <= maxperiod; i++) { - yy = yy + MULT16_16(x[-i], x[-i]) - MULT16_16(x[N - i], x[N - i]); - yy_lookup[i] = MAX32(0, yy); - } - yy = yy_lookup[T0]; - best_xy = xy; - best_yy = yy; - g = g0 = compute_pitch_gain(xy, xx, yy); - /* Look for any pitch at T/k */ - for (k = 2; k <= 15; k++) { - int T1, T1b; - opus_val16 g1; - opus_val16 cont = 0; - opus_val16 thresh; - T1 = celt_udiv(2 * T0 + k, 2 * k); - if (T1 < minperiod) { - break; - } - /* Look for another strong correlation at T1b */ - if (k == 2) { - if (T1 + T0 > maxperiod) { - T1b = T0; - } else { - T1b = T0 + T1; - } - } else { - T1b = celt_udiv(2 * second_check[k] * T0 + k, 2 * k); - } - dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2, arch); - xy = HALF32(xy + xy2); - yy = HALF32(yy_lookup[T1] + yy_lookup[T1b]); - g1 = compute_pitch_gain(xy, xx, yy); - if (abs(T1 - prev_period) <= 1) { - cont = prev_gain; - } else if (abs(T1 - prev_period) <= 2 && 5 * k * k < T0) { - cont = HALF16(prev_gain); - } else { - cont = 0; - } - thresh = MAX16(QCONST16(.3f, 15), MULT16_16_Q15(QCONST16(.7f, 15), g0) - cont); - /* Bias against very high pitch (very short period) to avoid false-positives - due to short-term correlation */ - if (T1 < 3 * minperiod) { - thresh = MAX16(QCONST16(.4f, 15), MULT16_16_Q15(QCONST16(.85f, 15), g0) - cont); - } else if (T1 < 2 * minperiod) { - thresh = MAX16(QCONST16(.5f, 15), MULT16_16_Q15(QCONST16(.9f, 15), g0) - cont); - } - if (g1 > thresh) { - best_xy = xy; - best_yy = yy; - T = T1; - g = g1; - } - } - best_xy = MAX32(0, best_xy); - if (best_yy <= best_xy) { - pg = Q15ONE; - } else { - pg = SHR32(frac_div32(best_xy, best_yy + 1), 16); - } + T = T0 = *T0_; + ALLOC(yy_lookup, maxperiod+1, opus_val32); + dual_inner_prod(x, x, x-T0, N, &xx, &xy, arch); + yy_lookup[0] = xx; + yy=xx; + for (i=1;i<=maxperiod;i++) + { + yy = yy+MULT16_16(x[-i],x[-i])-MULT16_16(x[N-i],x[N-i]); + yy_lookup[i] = MAX32(0, yy); + } + yy = yy_lookup[T0]; + best_xy = xy; + best_yy = yy; + g = g0 = compute_pitch_gain(xy, xx, yy); + /* Look for any pitch at T/k */ + for (k=2;k<=15;k++) + { + int T1, T1b; + opus_val16 g1; + opus_val16 cont=0; + opus_val16 thresh; + T1 = celt_udiv(2*T0+k, 2*k); + if (T1 < minperiod) + break; + /* Look for another strong correlation at T1b */ + if (k==2) + { + if (T1+T0>maxperiod) + T1b = T0; + else + T1b = T0+T1; + } else + { + T1b = celt_udiv(2*second_check[k]*T0+k, 2*k); + } + dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2, arch); + xy = HALF32(xy + xy2); + yy = HALF32(yy_lookup[T1] + yy_lookup[T1b]); + g1 = compute_pitch_gain(xy, xx, yy); + if (abs(T1-prev_period)<=1) + cont = prev_gain; + else if (abs(T1-prev_period)<=2 && 5*k*k < T0) + cont = HALF16(prev_gain); + else + cont = 0; + thresh = MAX16(QCONST16(.3f,15), MULT16_16_Q15(QCONST16(.7f,15),g0)-cont); + /* Bias against very high pitch (very short period) to avoid false-positives + due to short-term correlation */ + if (T1<3*minperiod) + thresh = MAX16(QCONST16(.4f,15), MULT16_16_Q15(QCONST16(.85f,15),g0)-cont); + else if (T1<2*minperiod) + thresh = MAX16(QCONST16(.5f,15), MULT16_16_Q15(QCONST16(.9f,15),g0)-cont); + if (g1 > thresh) + { + best_xy = xy; + best_yy = yy; + T = T1; + g = g1; + } + } + best_xy = MAX32(0, best_xy); + if (best_yy <= best_xy) + pg = Q15ONE; + else + pg = SHR32(frac_div32(best_xy,best_yy+1),16); - for (k = 0; k < 3; k++) { - xcorr[k] = celt_inner_prod(x, x - (T + k - 1), N, arch); - } - if ((xcorr[2] - xcorr[0]) > MULT16_32_Q15(QCONST16(.7f, 15), xcorr[1] - xcorr[0])) { - offset = 1; - } else if ((xcorr[0] - xcorr[2]) > MULT16_32_Q15(QCONST16(.7f, 15), xcorr[1] - xcorr[2])) { - offset = -1; - } else { - offset = 0; - } - if (pg > g) { - pg = g; - } - *T0_ = 2 * T + offset; + for (k=0;k<3;k++) + xcorr[k] = celt_inner_prod(x, x-(T+k-1), N, arch); + if ((xcorr[2]-xcorr[0]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[0])) + offset = 1; + else if ((xcorr[0]-xcorr[2]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[2])) + offset = -1; + else + offset = 0; + if (pg > g) + pg = g; + *T0_ = 2*T+offset; - if (*T0_ < minperiod0) { - *T0_ = minperiod0; - } - RESTORE_STACK; - return pg; + if (*T0_= 3); - y_3 = 0; /* gcc doesn't realize that y_3 can't be used uninitialized */ - y_0 = *y++; - y_1 = *y++; - y_2 = *y++; - for (j = 0; j < len - 3; j += 4) { - opus_val16 tmp; - tmp = *x++; - y_3 = *y++; - sum[0] = MAC16_16(sum[0], tmp, y_0); - sum[1] = MAC16_16(sum[1], tmp, y_1); - sum[2] = MAC16_16(sum[2], tmp, y_2); - sum[3] = MAC16_16(sum[3], tmp, y_3); - tmp = *x++; - y_0 = *y++; - sum[0] = MAC16_16(sum[0], tmp, y_1); - sum[1] = MAC16_16(sum[1], tmp, y_2); - sum[2] = MAC16_16(sum[2], tmp, y_3); - sum[3] = MAC16_16(sum[3], tmp, y_0); - tmp = *x++; - y_1 = *y++; - sum[0] = MAC16_16(sum[0], tmp, y_2); - sum[1] = MAC16_16(sum[1], tmp, y_3); - sum[2] = MAC16_16(sum[2], tmp, y_0); - sum[3] = MAC16_16(sum[3], tmp, y_1); - tmp = *x++; - y_2 = *y++; - sum[0] = MAC16_16(sum[0], tmp, y_3); - sum[1] = MAC16_16(sum[1], tmp, y_0); - sum[2] = MAC16_16(sum[2], tmp, y_1); - sum[3] = MAC16_16(sum[3], tmp, y_2); - } - if (j++ < len) { - opus_val16 tmp = *x++; - y_3 = *y++; - sum[0] = MAC16_16(sum[0], tmp, y_0); - sum[1] = MAC16_16(sum[1], tmp, y_1); - sum[2] = MAC16_16(sum[2], tmp, y_2); - sum[3] = MAC16_16(sum[3], tmp, y_3); - } - if (j++ < len) { - opus_val16 tmp = *x++; - y_0 = *y++; - sum[0] = MAC16_16(sum[0], tmp, y_1); - sum[1] = MAC16_16(sum[1], tmp, y_2); - sum[2] = MAC16_16(sum[2], tmp, y_3); - sum[3] = MAC16_16(sum[3], tmp, y_0); - } - if (j < len) { - opus_val16 tmp = *x++; - y_1 = *y++; - sum[0] = MAC16_16(sum[0], tmp, y_2); - sum[1] = MAC16_16(sum[1], tmp, y_3); - sum[2] = MAC16_16(sum[2], tmp, y_0); - sum[3] = MAC16_16(sum[3], tmp, y_1); - } +/* OPT: This is the kernel you really want to optimize. It gets used a lot + by the prefilter and by the PLC. */ +static OPUS_INLINE void xcorr_kernel_c(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len) +{ + int j; + opus_val16 y_0, y_1, y_2, y_3; + celt_assert(len>=3); + y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */ + y_0=*y++; + y_1=*y++; + y_2=*y++; + for (j=0;jnbEBands]; - oldE = MAX16(-QCONST16(9.f, DB_SHIFT), oldEBands[i + c * m->nbEBands]); + /* Encode at a fixed coarse resolution */ + for (i=start;inbEBands]; + oldE = MAX16(-QCONST16(9.f,DB_SHIFT), oldEBands[i+c*m->nbEBands]); #ifdef FIXED_POINT - f = SHL32(EXTEND32(x), 7) - PSHR32(MULT16_16(coef, oldE), 8) - prev[c]; - /* Rounding to nearest integer here is really important! */ - qi = (f + QCONST32(.5f, DB_SHIFT + 7)) >> (DB_SHIFT + 7); - decay_bound = EXTRACT16(MAX32(-QCONST16(28.f, DB_SHIFT), - SUB32((opus_val32)oldEBands[i + c * m->nbEBands], max_decay))); + f = SHL32(EXTEND32(x),7) - PSHR32(MULT16_16(coef,oldE), 8) - prev[c]; + /* Rounding to nearest integer here is really important! */ + qi = (f+QCONST32(.5f,DB_SHIFT+7))>>(DB_SHIFT+7); + decay_bound = EXTRACT16(MAX32(-QCONST16(28.f,DB_SHIFT), + SUB32((opus_val32)oldEBands[i+c*m->nbEBands],max_decay))); #else - f = x - coef * oldE - prev[c]; - /* Rounding to nearest integer here is really important! */ - qi = (int)floor(.5f + f); - decay_bound = MAX16(-QCONST16(28.f, DB_SHIFT), oldEBands[i + c * m->nbEBands]) - max_decay; + f = x-coef*oldE-prev[c]; + /* Rounding to nearest integer here is really important! */ + qi = (int)floor(.5f+f); + decay_bound = MAX16(-QCONST16(28.f,DB_SHIFT), oldEBands[i+c*m->nbEBands]) - max_decay; #endif - /* Prevent the energy from going down too quickly (e.g. for bands - that have just one bin) */ - if (qi < 0 && x < decay_bound) { - qi += (int)SHR16(SUB16(decay_bound, x), DB_SHIFT); - if (qi > 0) { - qi = 0; - } - } - qi0 = qi; - /* If we don't have enough bits to encode all the energy, just assume - something safe. */ - tell = ec_tell(enc); - bits_left = budget - tell - 3 * C * (end - i); - if (i != start && bits_left < 30) { - if (bits_left < 24) { - qi = IMIN(1, qi); - } - if (bits_left < 16) { - qi = IMAX(-1, qi); - } - } - if (lfe && i >= 2) { - qi = IMIN(qi, 0); - } - if (budget - tell >= 15) { - int pi; - pi = 2 * IMIN(i, 20); - ec_laplace_encode(enc, &qi, - prob_model[pi] << 7, prob_model[pi + 1] << 6); - } else if (budget - tell >= 2) { - qi = IMAX(-1, IMIN(qi, 1)); - ec_enc_icdf(enc, 2 * qi ^ -(qi < 0), small_energy_icdf, 2); - } else if (budget - tell >= 1) { - qi = IMIN(0, qi); - ec_enc_bit_logp(enc, -qi, 1); - } else { - qi = -1; - } - error[i + c * m->nbEBands] = PSHR32(f, 7) - SHL16(qi, DB_SHIFT); - badness += abs(qi0 - qi); - q = (opus_val32)SHL32(EXTEND32(qi), DB_SHIFT); + /* Prevent the energy from going down too quickly (e.g. for bands + that have just one bin) */ + if (qi < 0 && x < decay_bound) + { + qi += (int)SHR16(SUB16(decay_bound,x), DB_SHIFT); + if (qi > 0) + qi = 0; + } + qi0 = qi; + /* If we don't have enough bits to encode all the energy, just assume + something safe. */ + tell = ec_tell(enc); + bits_left = budget-tell-3*C*(end-i); + if (i!=start && bits_left < 30) + { + if (bits_left < 24) + qi = IMIN(1, qi); + if (bits_left < 16) + qi = IMAX(-1, qi); + } + if (lfe && i>=2) + qi = IMIN(qi, 0); + if (budget-tell >= 15) + { + int pi; + pi = 2*IMIN(i,20); + ec_laplace_encode(enc, &qi, + prob_model[pi]<<7, prob_model[pi+1]<<6); + } + else if(budget-tell >= 2) + { + qi = IMAX(-1, IMIN(qi, 1)); + ec_enc_icdf(enc, 2*qi^-(qi<0), small_energy_icdf, 2); + } + else if(budget-tell >= 1) + { + qi = IMIN(0, qi); + ec_enc_bit_logp(enc, -qi, 1); + } + else + qi = -1; + error[i+c*m->nbEBands] = PSHR32(f,7) - SHL16(qi,DB_SHIFT); + badness += abs(qi0-qi); + q = (opus_val32)SHL32(EXTEND32(qi),DB_SHIFT); - tmp = PSHR32(MULT16_16(coef, oldE), 8) + prev[c] + SHL32(q, 7); + tmp = PSHR32(MULT16_16(coef,oldE),8) + prev[c] + SHL32(q,7); #ifdef FIXED_POINT - tmp = MAX32(-QCONST32(28.f, DB_SHIFT + 7), tmp); + tmp = MAX32(-QCONST32(28.f, DB_SHIFT+7), tmp); #endif - oldEBands[i + c * m->nbEBands] = PSHR32(tmp, 7); - prev[c] = prev[c] + SHL32(q, 7) - MULT16_16(beta, PSHR32(q, 8)); - } while (++c < C); - } - return lfe ? 0 : badness; + oldEBands[i+c*m->nbEBands] = PSHR32(tmp, 7); + prev[c] = prev[c] + SHL32(q,7) - MULT16_16(beta,PSHR32(q,8)); + } while (++c < C); + } + return lfe ? 0 : badness; } void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, - const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget, - opus_val16 *error, ec_enc *enc, int C, int LM, int nbAvailableBytes, - int force_intra, opus_val32 *delayedIntra, int two_pass, int loss_rate, int lfe) { - int intra; - opus_val16 max_decay; - VARDECL(opus_val16, oldEBands_intra); - VARDECL(opus_val16, error_intra); - ec_enc enc_start_state; - opus_uint32 tell; - int badness1 = 0; - opus_int32 intra_bias; - opus_val32 new_distortion; - SAVE_STACK; + const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget, + opus_val16 *error, ec_enc *enc, int C, int LM, int nbAvailableBytes, + int force_intra, opus_val32 *delayedIntra, int two_pass, int loss_rate, int lfe) +{ + int intra; + opus_val16 max_decay; + VARDECL(opus_val16, oldEBands_intra); + VARDECL(opus_val16, error_intra); + ec_enc enc_start_state; + opus_uint32 tell; + int badness1=0; + opus_int32 intra_bias; + opus_val32 new_distortion; + SAVE_STACK; - intra = force_intra || (!two_pass && *delayedIntra > 2 * C * (end - start) && nbAvailableBytes > (end - start) * C); - intra_bias = (opus_int32)((budget**delayedIntra * loss_rate) / (C * 512)); - new_distortion = loss_distortion(eBands, oldEBands, start, effEnd, m->nbEBands, C); + intra = force_intra || (!two_pass && *delayedIntra>2*C*(end-start) && nbAvailableBytes > (end-start)*C); + intra_bias = (opus_int32)((budget**delayedIntra*loss_rate)/(C*512)); + new_distortion = loss_distortion(eBands, oldEBands, start, effEnd, m->nbEBands, C); - tell = ec_tell(enc); - if (tell + 3 > budget) { - two_pass = intra = 0; - } + tell = ec_tell(enc); + if (tell+3 > budget) + two_pass = intra = 0; - max_decay = QCONST16(16.f, DB_SHIFT); - if (end - start > 10) { + max_decay = QCONST16(16.f,DB_SHIFT); + if (end-start>10) + { #ifdef FIXED_POINT - max_decay = MIN32(max_decay, SHL32(EXTEND32(nbAvailableBytes), DB_SHIFT - 3)); + max_decay = MIN32(max_decay, SHL32(EXTEND32(nbAvailableBytes),DB_SHIFT-3)); #else - max_decay = MIN32(max_decay, .125f * nbAvailableBytes); + max_decay = MIN32(max_decay, .125f*nbAvailableBytes); #endif - } - if (lfe) { - max_decay = QCONST16(3.f, DB_SHIFT); - } - enc_start_state = *enc; + } + if (lfe) + max_decay = QCONST16(3.f,DB_SHIFT); + enc_start_state = *enc; - ALLOC(oldEBands_intra, C * m->nbEBands, opus_val16); - ALLOC(error_intra, C * m->nbEBands, opus_val16); - OPUS_COPY(oldEBands_intra, oldEBands, C * m->nbEBands); + ALLOC(oldEBands_intra, C*m->nbEBands, opus_val16); + ALLOC(error_intra, C*m->nbEBands, opus_val16); + OPUS_COPY(oldEBands_intra, oldEBands, C*m->nbEBands); - if (two_pass || intra) { - badness1 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands_intra, budget, - tell, e_prob_model[LM][1], error_intra, enc, C, LM, 1, max_decay, lfe); - } + if (two_pass || intra) + { + badness1 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands_intra, budget, + tell, e_prob_model[LM][1], error_intra, enc, C, LM, 1, max_decay, lfe); + } - if (!intra) { - unsigned char *intra_buf; - ec_enc enc_intra_state; - opus_int32 tell_intra; - opus_uint32 nstart_bytes; - opus_uint32 nintra_bytes; - opus_uint32 save_bytes; - int badness2; - VARDECL(unsigned char, intra_bits); + if (!intra) + { + unsigned char *intra_buf; + ec_enc enc_intra_state; + opus_int32 tell_intra; + opus_uint32 nstart_bytes; + opus_uint32 nintra_bytes; + opus_uint32 save_bytes; + int badness2; + VARDECL(unsigned char, intra_bits); - tell_intra = ec_tell_frac(enc); + tell_intra = ec_tell_frac(enc); - enc_intra_state = *enc; + enc_intra_state = *enc; - nstart_bytes = ec_range_bytes(&enc_start_state); - nintra_bytes = ec_range_bytes(&enc_intra_state); - intra_buf = ec_get_buffer(&enc_intra_state) + nstart_bytes; - save_bytes = nintra_bytes - nstart_bytes; - if (save_bytes == 0) { - save_bytes = ALLOC_NONE; - } - ALLOC(intra_bits, save_bytes, unsigned char); - /* Copy bits from intra bit-stream */ - OPUS_COPY(intra_bits, intra_buf, nintra_bytes - nstart_bytes); + nstart_bytes = ec_range_bytes(&enc_start_state); + nintra_bytes = ec_range_bytes(&enc_intra_state); + intra_buf = ec_get_buffer(&enc_intra_state) + nstart_bytes; + save_bytes = nintra_bytes-nstart_bytes; + if (save_bytes == 0) + save_bytes = ALLOC_NONE; + ALLOC(intra_bits, save_bytes, unsigned char); + /* Copy bits from intra bit-stream */ + OPUS_COPY(intra_bits, intra_buf, nintra_bytes - nstart_bytes); - *enc = enc_start_state; + *enc = enc_start_state; - badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget, - tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay, lfe); + badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget, + tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay, lfe); - if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ((opus_int32)ec_tell_frac(enc)) + intra_bias > tell_intra))) { - *enc = enc_intra_state; - /* Copy intra bits to bit-stream */ - OPUS_COPY(intra_buf, intra_bits, nintra_bytes - nstart_bytes); - OPUS_COPY(oldEBands, oldEBands_intra, C * m->nbEBands); - OPUS_COPY(error, error_intra, C * m->nbEBands); - intra = 1; - } - } else { - OPUS_COPY(oldEBands, oldEBands_intra, C * m->nbEBands); - OPUS_COPY(error, error_intra, C * m->nbEBands); - } + if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ((opus_int32)ec_tell_frac(enc))+intra_bias > tell_intra))) + { + *enc = enc_intra_state; + /* Copy intra bits to bit-stream */ + OPUS_COPY(intra_buf, intra_bits, nintra_bytes - nstart_bytes); + OPUS_COPY(oldEBands, oldEBands_intra, C*m->nbEBands); + OPUS_COPY(error, error_intra, C*m->nbEBands); + intra = 1; + } + } else { + OPUS_COPY(oldEBands, oldEBands_intra, C*m->nbEBands); + OPUS_COPY(error, error_intra, C*m->nbEBands); + } - if (intra) { - *delayedIntra = new_distortion; - } else - *delayedIntra = ADD32(MULT16_32_Q15(MULT16_16_Q15(pred_coef[LM], pred_coef[LM]), *delayedIntra), - new_distortion); + if (intra) + *delayedIntra = new_distortion; + else + *delayedIntra = ADD32(MULT16_32_Q15(MULT16_16_Q15(pred_coef[LM], pred_coef[LM]),*delayedIntra), + new_distortion); - RESTORE_STACK; + RESTORE_STACK; } -void quant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, ec_enc *enc, int C) { - int i, c; +void quant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, ec_enc *enc, int C) +{ + int i, c; - /* Encode finer resolution */ - for (i = start; i < end; i++) { - opus_int16 frac = 1 << fine_quant[i]; - if (fine_quant[i] <= 0) { + /* Encode finer resolution */ + for (i=start;inbEBands]+QCONST16(.5f,DB_SHIFT))>>(DB_SHIFT-fine_quant[i]); +#else + q2 = (int)floor((error[i+c*m->nbEBands]+.5f)*frac); +#endif + if (q2 > frac-1) + q2 = frac-1; + if (q2<0) + q2 = 0; + ec_enc_bits(enc, q2, fine_quant[i]); +#ifdef FIXED_POINT + offset = SUB16(SHR32(SHL32(EXTEND32(q2),DB_SHIFT)+QCONST16(.5f,DB_SHIFT),fine_quant[i]),QCONST16(.5f,DB_SHIFT)); +#else + offset = (q2+.5f)*(1<<(14-fine_quant[i]))*(1.f/16384) - .5f; +#endif + oldEBands[i+c*m->nbEBands] += offset; + error[i+c*m->nbEBands] -= offset; + /*printf ("%f ", error[i] - offset);*/ + } while (++c < C); + } +} + +void quant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc, int C) +{ + int i, prio, c; + + /* Use up the remaining bits */ + for (prio=0;prio<2;prio++) + { + for (i=start;i=C ;i++) + { + if (fine_quant[i] >= MAX_FINE_BITS || fine_priority[i]!=prio) continue; - } - c = 0; - do { + c=0; + do { int q2; opus_val16 offset; + q2 = error[i+c*m->nbEBands]<0 ? 0 : 1; + ec_enc_bits(enc, q2, 1); #ifdef FIXED_POINT - /* Has to be without rounding */ - q2 = (error[i + c * m->nbEBands] + QCONST16(.5f, DB_SHIFT)) >> (DB_SHIFT - fine_quant[i]); + offset = SHR16(SHL16(q2,DB_SHIFT)-QCONST16(.5f,DB_SHIFT),fine_quant[i]+1); #else - q2 = (int)floor((error[i + c * m->nbEBands] + .5f) * frac); + offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384); #endif - if (q2 > frac - 1) { - q2 = frac - 1; - } - if (q2 < 0) { - q2 = 0; - } - ec_enc_bits(enc, q2, fine_quant[i]); -#ifdef FIXED_POINT - offset = SUB16(SHR32(SHL32(EXTEND32(q2), DB_SHIFT) + QCONST16(.5f, DB_SHIFT), fine_quant[i]), QCONST16(.5f, DB_SHIFT)); -#else - offset = (q2 + .5f) * (1 << (14 - fine_quant[i])) * (1.f / 16384) - .5f; -#endif - oldEBands[i + c * m->nbEBands] += offset; - error[i + c * m->nbEBands] -= offset; - /*printf ("%f ", error[i] - offset);*/ - } while (++c < C); - } + oldEBands[i+c*m->nbEBands] += offset; + error[i+c*m->nbEBands] -= offset; + bits_left--; + } while (++c < C); + } + } } -void quant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc, int C) { - int i, prio, c; +void unquant_coarse_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int intra, ec_dec *dec, int C, int LM) +{ + const unsigned char *prob_model = e_prob_model[LM][intra]; + int i, c; + opus_val32 prev[2] = {0, 0}; + opus_val16 coef; + opus_val16 beta; + opus_int32 budget; + opus_int32 tell; - /* Use up the remaining bits */ - for (prio = 0; prio < 2; prio++) { - for (i = start; i < end && bits_left >= C ; i++) { - if (fine_quant[i] >= MAX_FINE_BITS || fine_priority[i] != prio) { - continue; - } - c = 0; - do { - int q2; - opus_val16 offset; - q2 = error[i + c * m->nbEBands] < 0 ? 0 : 1; - ec_enc_bits(enc, q2, 1); + if (intra) + { + coef = 0; + beta = beta_intra; + } else { + beta = beta_coef[LM]; + coef = pred_coef[LM]; + } + + budget = dec->storage*8; + + /* Decode at a fixed coarse resolution */ + for (i=start;i=15) + { + int pi; + pi = 2*IMIN(i,20); + qi = ec_laplace_decode(dec, + prob_model[pi]<<7, prob_model[pi+1]<<6); + } + else if(budget-tell>=2) + { + qi = ec_dec_icdf(dec, small_energy_icdf, 2); + qi = (qi>>1)^-(qi&1); + } + else if(budget-tell>=1) + { + qi = -ec_dec_bit_logp(dec, 1); + } + else + qi = -1; + q = (opus_val32)SHL32(EXTEND32(qi),DB_SHIFT); + + oldEBands[i+c*m->nbEBands] = MAX16(-QCONST16(9.f,DB_SHIFT), oldEBands[i+c*m->nbEBands]); + tmp = PSHR32(MULT16_16(coef,oldEBands[i+c*m->nbEBands]),8) + prev[c] + SHL32(q,7); #ifdef FIXED_POINT - offset = SHR16(SHL16(q2, DB_SHIFT) - QCONST16(.5f, DB_SHIFT), fine_quant[i] + 1); + tmp = MAX32(-QCONST32(28.f, DB_SHIFT+7), tmp); +#endif + oldEBands[i+c*m->nbEBands] = PSHR32(tmp, 7); + prev[c] = prev[c] + SHL32(q,7) - MULT16_16(beta,PSHR32(q,8)); + } while (++c < C); + } +} + +void unquant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, ec_dec *dec, int C) +{ + int i, c; + /* Decode finer resolution */ + for (i=start;inbEBands] += offset; - error[i + c * m->nbEBands] -= offset; - bits_left--; - } while (++c < C); - } - } + oldEBands[i+c*m->nbEBands] += offset; + } while (++c < C); + } } -void unquant_coarse_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int intra, ec_dec *dec, int C, int LM) { - const unsigned char *prob_model = e_prob_model[LM][intra]; - int i, c; - opus_val32 prev[2] = {0, 0}; - opus_val16 coef; - opus_val16 beta; - opus_int32 budget; - opus_int32 tell; +void unquant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, int *fine_priority, int bits_left, ec_dec *dec, int C) +{ + int i, prio, c; - if (intra) { - coef = 0; - beta = beta_intra; - } else { - beta = beta_coef[LM]; - coef = pred_coef[LM]; - } - - budget = dec->storage * 8; - - /* Decode at a fixed coarse resolution */ - for (i = start; i < end; i++) { - c = 0; - do { - int qi; - opus_val32 q; - opus_val32 tmp; - /* It would be better to express this invariant as a - test on C at function entry, but that isn't enough - to make the static analyzer happy. */ - celt_sig_assert(c < 2); - tell = ec_tell(dec); - if (budget - tell >= 15) { - int pi; - pi = 2 * IMIN(i, 20); - qi = ec_laplace_decode(dec, - prob_model[pi] << 7, prob_model[pi + 1] << 6); - } else if (budget - tell >= 2) { - qi = ec_dec_icdf(dec, small_energy_icdf, 2); - qi = (qi >> 1) ^ -(qi & 1); - } else if (budget - tell >= 1) { - qi = -ec_dec_bit_logp(dec, 1); - } else { - qi = -1; - } - q = (opus_val32)SHL32(EXTEND32(qi), DB_SHIFT); - - oldEBands[i + c * m->nbEBands] = MAX16(-QCONST16(9.f, DB_SHIFT), oldEBands[i + c * m->nbEBands]); - tmp = PSHR32(MULT16_16(coef, oldEBands[i + c * m->nbEBands]), 8) + prev[c] + SHL32(q, 7); -#ifdef FIXED_POINT - tmp = MAX32(-QCONST32(28.f, DB_SHIFT + 7), tmp); -#endif - oldEBands[i + c * m->nbEBands] = PSHR32(tmp, 7); - prev[c] = prev[c] + SHL32(q, 7) - MULT16_16(beta, PSHR32(q, 8)); - } while (++c < C); - } -} - -void unquant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, ec_dec *dec, int C) { - int i, c; - /* Decode finer resolution */ - for (i = start; i < end; i++) { - if (fine_quant[i] <= 0) { + /* Use up the remaining bits */ + for (prio=0;prio<2;prio++) + { + for (i=start;i=C ;i++) + { + if (fine_quant[i] >= MAX_FINE_BITS || fine_priority[i]!=prio) continue; - } - c = 0; - do { + c=0; + do { int q2; opus_val16 offset; - q2 = ec_dec_bits(dec, fine_quant[i]); + q2 = ec_dec_bits(dec, 1); #ifdef FIXED_POINT - offset = SUB16(SHR32(SHL32(EXTEND32(q2), DB_SHIFT) + QCONST16(.5f, DB_SHIFT), fine_quant[i]), QCONST16(.5f, DB_SHIFT)); + offset = SHR16(SHL16(q2,DB_SHIFT)-QCONST16(.5f,DB_SHIFT),fine_quant[i]+1); #else - offset = (q2 + .5f) * (1 << (14 - fine_quant[i])) * (1.f / 16384) - .5f; + offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384); #endif - oldEBands[i + c * m->nbEBands] += offset; - } while (++c < C); - } -} - -void unquant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *oldEBands, int *fine_quant, int *fine_priority, int bits_left, ec_dec *dec, int C) { - int i, prio, c; - - /* Use up the remaining bits */ - for (prio = 0; prio < 2; prio++) { - for (i = start; i < end && bits_left >= C ; i++) { - if (fine_quant[i] >= MAX_FINE_BITS || fine_priority[i] != prio) { - continue; - } - c = 0; - do { - int q2; - opus_val16 offset; - q2 = ec_dec_bits(dec, 1); -#ifdef FIXED_POINT - offset = SHR16(SHL16(q2, DB_SHIFT) - QCONST16(.5f, DB_SHIFT), fine_quant[i] + 1); -#else - offset = (q2 - .5f) * (1 << (14 - fine_quant[i] - 1)) * (1.f / 16384); -#endif - oldEBands[i + c * m->nbEBands] += offset; - bits_left--; - } while (++c < C); - } - } + oldEBands[i+c*m->nbEBands] += offset; + bits_left--; + } while (++c < C); + } + } } void amp2Log2(const CELTMode *m, int effEnd, int end, - celt_ener *bandE, opus_val16 *bandLogE, int C) { - int c, i; - c = 0; - do { - for (i = 0; i < effEnd; i++) { - bandLogE[i + c * m->nbEBands] = - celt_log2(bandE[i + c * m->nbEBands]) - - SHL16((opus_val16)eMeans[i], 6); + celt_ener *bandE, opus_val16 *bandLogE, int C) +{ + int c, i; + c=0; + do { + for (i=0;inbEBands] = + celt_log2(bandE[i+c*m->nbEBands]) + - SHL16((opus_val16)eMeans[i],6); #ifdef FIXED_POINT - /* Compensate for bandE[] being Q12 but celt_log2() taking a Q14 input. */ - bandLogE[i + c * m->nbEBands] += QCONST16(2.f, DB_SHIFT); + /* Compensate for bandE[] being Q12 but celt_log2() taking a Q14 input. */ + bandLogE[i+c*m->nbEBands] += QCONST16(2.f, DB_SHIFT); #endif - } - for (i = effEnd; i < end; i++) { - bandLogE[c * m->nbEBands + i] = -QCONST16(14.f, DB_SHIFT); - } - } while (++c < C); + } + for (i=effEnd;inbEBands+i] = -QCONST16(14.f,DB_SHIFT); + } while (++c < C); } diff --git a/src/libopus/celt/quant_bands.h b/src/libopus/celt/quant_bands.h index 20820a2..0490bca 100644 --- a/src/libopus/celt/quant_bands.h +++ b/src/libopus/celt/quant_bands.h @@ -1,29 +1,29 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef QUANT_BANDS @@ -42,16 +42,16 @@ extern const opus_val16 eMeans[25]; #endif void amp2Log2(const CELTMode *m, int effEnd, int end, - celt_ener *bandE, opus_val16 *bandLogE, int C); + celt_ener *bandE, opus_val16 *bandLogE, int C); void log2Amp(const CELTMode *m, int start, int end, - celt_ener *eBands, const opus_val16 *oldEBands, int C); + celt_ener *eBands, const opus_val16 *oldEBands, int C); void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, - const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget, - opus_val16 *error, ec_enc *enc, int C, int LM, - int nbAvailableBytes, int force_intra, opus_val32 *delayedIntra, - int two_pass, int loss_rate, int lfe); + const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget, + opus_val16 *error, ec_enc *enc, int C, int LM, + int nbAvailableBytes, int force_intra, opus_val32 *delayedIntra, + int two_pass, int loss_rate, int lfe); void quant_fine_energy(const CELTMode *m, int start, int end, opus_val16 *oldEBands, opus_val16 *error, int *fine_quant, ec_enc *enc, int C); diff --git a/src/libopus/celt/rate.c b/src/libopus/celt/rate.c index ec7b8a2..d6fe1dd 100644 --- a/src/libopus/celt/rate.c +++ b/src/libopus/celt/rate.c @@ -1,34 +1,34 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include #include "modes.h" @@ -39,195 +39,206 @@ #include "entcode.h" #include "rate.h" -static const unsigned char LOG2_FRAC_TABLE[24] = { - 0, - 8, 13, - 16, 19, 21, 23, - 24, 26, 27, 28, 29, 30, 31, 32, - 32, 33, 34, 34, 35, 36, 36, 37, 37 +static const unsigned char LOG2_FRAC_TABLE[24]={ + 0, + 8,13, + 16,19,21,23, + 24,26,27,28,29,30,31,32, + 32,33,34,34,35,36,36,37,37 }; #ifdef CUSTOM_MODES -/* Determines if V(N,K) fits in a 32-bit unsigned integer. - N and K are themselves limited to 15 bits.*/ -static int fits_in32(int _n, int _k) { - static const opus_int16 maxN[15] = { - 32767, 32767, 32767, 1476, 283, 109, 60, 40, - 29, 24, 20, 18, 16, 14, 13 - }; - static const opus_int16 maxK[15] = { - 32767, 32767, 32767, 32767, 1172, 238, 95, 53, - 36, 27, 22, 18, 16, 15, 13 - }; - if (_n >= 14) { - if (_k >= 14) { - return 0; - } else { - return _n <= maxN[_k]; - } - } else { - return _k <= maxK[_n]; - } +/*Determines if V(N,K) fits in a 32-bit unsigned integer. + N and K are themselves limited to 15 bits.*/ +static int fits_in32(int _n, int _k) +{ + static const opus_int16 maxN[15] = { + 32767, 32767, 32767, 1476, 283, 109, 60, 40, + 29, 24, 20, 18, 16, 14, 13}; + static const opus_int16 maxK[15] = { + 32767, 32767, 32767, 32767, 1172, 238, 95, 53, + 36, 27, 22, 18, 16, 15, 13}; + if (_n>=14) + { + if (_k>=14) + return 0; + else + return _n <= maxN[_k]; + } else { + return _k <= maxK[_n]; + } } -void compute_pulse_cache(CELTMode *m, int LM) { - int C; - int i; - int j; - int curr = 0; - int nbEntries = 0; - int entryN[100], entryK[100], entryI[100]; - const opus_int16 *eBands = m->eBands; - PulseCache *cache = &m->cache; - opus_int16 *cindex; - unsigned char *bits; - unsigned char *cap; +void compute_pulse_cache(CELTMode *m, int LM) +{ + int C; + int i; + int j; + int curr=0; + int nbEntries=0; + int entryN[100], entryK[100], entryI[100]; + const opus_int16 *eBands = m->eBands; + PulseCache *cache = &m->cache; + opus_int16 *cindex; + unsigned char *bits; + unsigned char *cap; - cindex = (opus_int16 *)opus_alloc(sizeof(cache->index[0]) * m->nbEBands * (LM + 2)); - cache->index = cindex; + cindex = (opus_int16 *)opus_alloc(sizeof(cache->index[0])*m->nbEBands*(LM+2)); + cache->index = cindex; - /* Scan for all unique band sizes */ - for (i = 0; i <= LM + 1; i++) { - for (j = 0; j < m->nbEBands; j++) { - int k; - int N = (eBands[j + 1] - eBands[j]) << i>>1; - cindex[i * m->nbEBands + j] = -1; - /* Find other bands that have the same size */ - for (k = 0; k <= i; k++) { - int n; - for (n = 0; n < m->nbEBands && (k != i || n < j); n++) { - if (N == (eBands[n + 1] - eBands[n]) << k>>1) { - cindex[i * m->nbEBands + j] = cindex[k * m->nbEBands + n]; - break; - } - } + /* Scan for all unique band sizes */ + for (i=0;i<=LM+1;i++) + { + for (j=0;jnbEBands;j++) + { + int k; + int N = (eBands[j+1]-eBands[j])<>1; + cindex[i*m->nbEBands+j] = -1; + /* Find other bands that have the same size */ + for (k=0;k<=i;k++) + { + int n; + for (n=0;nnbEBands && (k!=i || n>1) + { + cindex[i*m->nbEBands+j] = cindex[k*m->nbEBands+n]; + break; + } } - if (cache->index[i * m->nbEBands + j] == -1 && N != 0) { - int K; - entryN[nbEntries] = N; - K = 0; - while (fits_in32(N, get_pulses(K + 1)) && K < MAX_PSEUDO) { - K++; - } - entryK[nbEntries] = K; - cindex[i * m->nbEBands + j] = curr; - entryI[nbEntries] = curr; + } + if (cache->index[i*m->nbEBands+j] == -1 && N!=0) + { + int K; + entryN[nbEntries] = N; + K = 0; + while (fits_in32(N,get_pulses(K+1)) && KnbEBands+j] = curr; + entryI[nbEntries] = curr; - curr += K + 1; - nbEntries++; - } - } - } - bits = (unsigned char *)opus_alloc(sizeof(unsigned char) * curr); - cache->bits = bits; - cache->size = curr; - /* Compute the cache for all unique sizes */ - for (i = 0; i < nbEntries; i++) { - unsigned char *ptr = bits + entryI[i]; - opus_int16 tmp[CELT_MAX_PULSES + 1]; - get_required_bits(tmp, entryN[i], get_pulses(entryK[i]), BITRES); - for (j = 1; j <= entryK[i]; j++) { - ptr[j] = tmp[get_pulses(j)] - 1; - } - ptr[0] = entryK[i]; - } + curr += K+1; + nbEntries++; + } + } + } + bits = (unsigned char *)opus_alloc(sizeof(unsigned char)*curr); + cache->bits = bits; + cache->size = curr; + /* Compute the cache for all unique sizes */ + for (i=0;icaps = cap = (unsigned char *)opus_alloc(sizeof(cache->caps[0]) * (LM + 1) * 2 * m->nbEBands); - for (i = 0; i <= LM; i++) { - for (C = 1; C <= 2; C++) { - for (j = 0; j < m->nbEBands; j++) { - int N0; - int max_bits; - N0 = m->eBands[j + 1] - m->eBands[j]; - /* N=1 bands only have a sign bit and fine bits. */ - if (N0 << i == 1) { - max_bits = C * (1 + MAX_FINE_BITS) << BITRES; - } else { - const unsigned char *pcache; - opus_int32 num; - opus_int32 den; - int LM0; - int N; - int offset; - int ndof; - int qb; - int k; - LM0 = 0; - /* Even-sized bands bigger than N=2 can be split one more time. - As of commit 44203907 all bands >1 are even, including custom modes.*/ - if (N0 > 2) { - N0 >>= 1; - LM0--; - } - /* N0=1 bands can't be split down to N<2. */ - else if (N0 <= 1) { - LM0 = IMIN(i, 1); - N0 <<= LM0; - } - /* Compute the cost for the lowest-level PVQ of a fully split - band. */ - pcache = bits + cindex[(LM0 + 1) * m->nbEBands + j]; - max_bits = pcache[pcache[0]] + 1; - /* Add in the cost of coding regular splits. */ - N = N0; - for (k = 0; k < i - LM0; k++) { - max_bits <<= 1; - /* Offset the number of qtheta bits by log2(N)/2 - + QTHETA_OFFSET compared to their "fair share" of - total/N */ - offset = ((m->logN[j] + ((LM0 + k) << BITRES)) >> 1) - QTHETA_OFFSET; - /* The number of qtheta bits we'll allocate if the remainder - is to be max_bits. - The average measured cost for theta is 0.89701 times qb, - approximated here as 459/512. */ - num = 459 * (opus_int32)((2 * N - 1) * offset + max_bits); - den = ((opus_int32)(2 * N - 1) << 9) - 459; - qb = IMIN((num + (den >> 1)) / den, 57); - celt_assert(qb >= 0); - max_bits += qb; - N <<= 1; - } - /* Add in the cost of a stereo split, if necessary. */ - if (C == 2) { - max_bits <<= 1; - offset = ((m->logN[j] + (i << BITRES)) >> 1) - (N == 2 ? QTHETA_OFFSET_TWOPHASE : QTHETA_OFFSET); - ndof = 2 * N - 1 - (N == 2); - /* The average measured cost for theta with the step PDF is - 0.95164 times qb, approximated here as 487/512. */ - num = (N == 2 ? 512 : 487) * (opus_int32)(max_bits + ndof * offset); - den = ((opus_int32)ndof << 9) - (N == 2 ? 512 : 487); - qb = IMIN((num + (den >> 1)) / den, (N == 2 ? 64 : 61)); - celt_assert(qb >= 0); - max_bits += qb; - } - /* Add the fine bits we'll use. */ - /* Compensate for the extra DoF in stereo */ - ndof = C * N + ((C == 2 && N > 2) ? 1 : 0); - /* Offset the number of fine bits by log2(N)/2 + FINE_OFFSET - compared to their "fair share" of total/N */ - offset = ((m->logN[j] + (i << BITRES)) >> 1) - FINE_OFFSET; - /* N=2 is the only point that doesn't match the curve */ - if (N == 2) { - offset += 1 << BITRES>>2; - } - /* The number of fine bits we'll allocate if the remainder is - to be max_bits. */ - num = max_bits + ndof * offset; - den = (ndof - 1) << BITRES; - qb = IMIN((num + (den >> 1)) / den, MAX_FINE_BITS); - celt_assert(qb >= 0); - max_bits += C * qb << BITRES; - } - max_bits = (4 * max_bits / (C * ((m->eBands[j + 1] - m->eBands[j]) << i))) - 64; - celt_assert(max_bits >= 0); - celt_assert(max_bits < 256); - *cap++ = (unsigned char)max_bits; + /* Compute the maximum rate for each band at which we'll reliably use as + many bits as we ask for. */ + cache->caps = cap = (unsigned char *)opus_alloc(sizeof(cache->caps[0])*(LM+1)*2*m->nbEBands); + for (i=0;i<=LM;i++) + { + for (C=1;C<=2;C++) + { + for (j=0;jnbEBands;j++) + { + int N0; + int max_bits; + N0 = m->eBands[j+1]-m->eBands[j]; + /* N=1 bands only have a sign bit and fine bits. */ + if (N0<1 are even, including custom modes.*/ + if (N0 > 2) + { + N0>>=1; + LM0--; + } + /* N0=1 bands can't be split down to N<2. */ + else if (N0 <= 1) + { + LM0=IMIN(i,1); + N0<<=LM0; + } + /* Compute the cost for the lowest-level PVQ of a fully split + band. */ + pcache = bits + cindex[(LM0+1)*m->nbEBands+j]; + max_bits = pcache[pcache[0]]+1; + /* Add in the cost of coding regular splits. */ + N = N0; + for(k=0;klogN[j]+((LM0+k)<>1)-QTHETA_OFFSET; + /* The number of qtheta bits we'll allocate if the remainder + is to be max_bits. + The average measured cost for theta is 0.89701 times qb, + approximated here as 459/512. */ + num=459*(opus_int32)((2*N-1)*offset+max_bits); + den=((opus_int32)(2*N-1)<<9)-459; + qb = IMIN((num+(den>>1))/den, 57); + celt_assert(qb >= 0); + max_bits += qb; + N <<= 1; + } + /* Add in the cost of a stereo split, if necessary. */ + if (C==2) + { + max_bits <<= 1; + offset = ((m->logN[j]+(i<>1)-(N==2?QTHETA_OFFSET_TWOPHASE:QTHETA_OFFSET); + ndof = 2*N-1-(N==2); + /* The average measured cost for theta with the step PDF is + 0.95164 times qb, approximated here as 487/512. */ + num = (N==2?512:487)*(opus_int32)(max_bits+ndof*offset); + den = ((opus_int32)ndof<<9)-(N==2?512:487); + qb = IMIN((num+(den>>1))/den, (N==2?64:61)); + celt_assert(qb >= 0); + max_bits += qb; + } + /* Add the fine bits we'll use. */ + /* Compensate for the extra DoF in stereo */ + ndof = C*N + ((C==2 && N>2) ? 1 : 0); + /* Offset the number of fine bits by log2(N)/2 + FINE_OFFSET + compared to their "fair share" of total/N */ + offset = ((m->logN[j] + (i<>1)-FINE_OFFSET; + /* N=2 is the only point that doesn't match the curve */ + if (N==2) + offset += 1<>2; + /* The number of fine bits we'll allocate if the remainder is + to be max_bits. */ + num = max_bits+ndof*offset; + den = (ndof-1)<>1))/den, MAX_FINE_BITS); + celt_assert(qb >= 0); + max_bits += C*qb<eBands[j+1]-m->eBands[j])<= 0); + celt_assert(max_bits < 256); + *cap++ = (unsigned char)max_bits; + } + } + } } #endif /* CUSTOM_MODES */ @@ -235,389 +246,401 @@ void compute_pulse_cache(CELTMode *m, int LM) { #define ALLOC_STEPS 6 static OPUS_INLINE int interp_bits2pulses(const CELTMode *m, int start, int end, int skip_start, - const int *bits1, const int *bits2, const int *thresh, const int *cap, opus_int32 total, opus_int32 *_balance, - int skip_rsv, int *intensity, int intensity_rsv, int *dual_stereo, int dual_stereo_rsv, int *bits, - int *ebits, int *fine_priority, int C, int LM, ec_ctx *ec, int encode, int prev, int signalBandwidth) { - opus_int32 psum; - int lo, hi; - int i, j; - int logM; - int stereo; - int codedBands = -1; - int alloc_floor; - opus_int32 left, percoeff; - int done; - opus_int32 balance; - SAVE_STACK; + const int *bits1, const int *bits2, const int *thresh, const int *cap, opus_int32 total, opus_int32 *_balance, + int skip_rsv, int *intensity, int intensity_rsv, int *dual_stereo, int dual_stereo_rsv, int *bits, + int *ebits, int *fine_priority, int C, int LM, ec_ctx *ec, int encode, int prev, int signalBandwidth) +{ + opus_int32 psum; + int lo, hi; + int i, j; + int logM; + int stereo; + int codedBands=-1; + int alloc_floor; + opus_int32 left, percoeff; + int done; + opus_int32 balance; + SAVE_STACK; - alloc_floor = C << BITRES; - stereo = C > 1; + alloc_floor = C<1; - logM = LM << BITRES; - lo = 0; - hi = 1 << ALLOC_STEPS; - for (i = 0; i < ALLOC_STEPS; i++) { - int mid = (lo + hi) >> 1; - psum = 0; - done = 0; - for (j = end; j-- > start;) { - int tmp = bits1[j] + (mid * (opus_int32)bits2[j] >> ALLOC_STEPS); - if (tmp >= thresh[j] || done) { - done = 1; - /* Don't allocate more than we can actually use */ - psum += IMIN(tmp, cap[j]); - } else { - if (tmp >= alloc_floor) { - psum += alloc_floor; - } - } - } - if (psum > total) { - hi = mid; - } else { - lo = mid; - } - } - psum = 0; - /*printf ("interp bisection gave %d\n", lo);*/ - done = 0; - for (j = end; j-- > start;) { - int tmp = bits1[j] + ((opus_int32)lo * bits2[j] >> ALLOC_STEPS); - if (tmp < thresh[j] && !done) { - if (tmp >= alloc_floor) { - tmp = alloc_floor; - } else { - tmp = 0; - } - } else { + logM = LM<>1; + psum = 0; + done = 0; + for (j=end;j-->start;) + { + int tmp = bits1[j] + (mid*(opus_int32)bits2[j]>>ALLOC_STEPS); + if (tmp >= thresh[j] || done) + { done = 1; - } - /* Don't allocate more than we can actually use */ - tmp = IMIN(tmp, cap[j]); - bits[j] = tmp; - psum += tmp; - } + /* Don't allocate more than we can actually use */ + psum += IMIN(tmp, cap[j]); + } else { + if (tmp >= alloc_floor) + psum += alloc_floor; + } + } + if (psum > total) + hi = mid; + else + lo = mid; + } + psum = 0; + /*printf ("interp bisection gave %d\n", lo);*/ + done = 0; + for (j=end;j-->start;) + { + int tmp = bits1[j] + ((opus_int32)lo*bits2[j]>>ALLOC_STEPS); + if (tmp < thresh[j] && !done) + { + if (tmp >= alloc_floor) + tmp = alloc_floor; + else + tmp = 0; + } else + done = 1; + /* Don't allocate more than we can actually use */ + tmp = IMIN(tmp, cap[j]); + bits[j] = tmp; + psum += tmp; + } - /* Decide which bands to skip, working backwards from the end. */ - for (codedBands = end;; codedBands--) { - int band_width; - int band_bits; - int rem; - j = codedBands - 1; - /* Never skip the first band, nor a band that has been boosted by - dynalloc. - In the first case, we'd be coding a bit to signal we're going to waste - all the other bits. - In the second case, we'd be coding a bit to redistribute all the bits - we just signaled should be cocentrated in this band. */ - if (j <= skip_start) { - /* Give the bit we reserved to end skipping back. */ - total += skip_rsv; - break; - } - /* Figure out how many left-over bits we would be adding to this band. - This can include bits we've stolen back from higher, skipped bands.*/ - left = total - psum; - percoeff = celt_udiv(left, m->eBands[codedBands] - m->eBands[start]); - left -= (m->eBands[codedBands] - m->eBands[start]) * percoeff; - rem = IMAX(left - (m->eBands[j] - m->eBands[start]), 0); - band_width = m->eBands[codedBands] - m->eBands[j]; - band_bits = (int)(bits[j] + percoeff * band_width + rem); - /* Only code a skip decision if we're above the threshold for this band. - Otherwise it is force-skipped. - This ensures that we have enough bits to code the skip flag.*/ - if (band_bits >= IMAX(thresh[j], alloc_floor + (1 << BITRES))) { - if (encode) { - /* This if() block is the only part of the allocation function that - is not a mandatory part of the bitstream: any bands we choose to - skip here must be explicitly signaled.*/ - int depth_threshold; - /* We choose a threshold with some hysteresis to keep bands from - fluctuating in and out, but we try not to fold below a certain point. */ - if (codedBands > 17) { - depth_threshold = j < prev ? 7 : 9; - } else { - depth_threshold = 0; - } + /* Decide which bands to skip, working backwards from the end. */ + for (codedBands=end;;codedBands--) + { + int band_width; + int band_bits; + int rem; + j = codedBands-1; + /* Never skip the first band, nor a band that has been boosted by + dynalloc. + In the first case, we'd be coding a bit to signal we're going to waste + all the other bits. + In the second case, we'd be coding a bit to redistribute all the bits + we just signaled should be cocentrated in this band. */ + if (j<=skip_start) + { + /* Give the bit we reserved to end skipping back. */ + total += skip_rsv; + break; + } + /*Figure out how many left-over bits we would be adding to this band. + This can include bits we've stolen back from higher, skipped bands.*/ + left = total-psum; + percoeff = celt_udiv(left, m->eBands[codedBands]-m->eBands[start]); + left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; + rem = IMAX(left-(m->eBands[j]-m->eBands[start]),0); + band_width = m->eBands[codedBands]-m->eBands[j]; + band_bits = (int)(bits[j] + percoeff*band_width + rem); + /*Only code a skip decision if we're above the threshold for this band. + Otherwise it is force-skipped. + This ensures that we have enough bits to code the skip flag.*/ + if (band_bits >= IMAX(thresh[j], alloc_floor+(1< 17) + depth_threshold = j (depth_threshold * band_width << LM << BITRES) >> 4 && j <= signalBandwidth)) + if (codedBands<=start+2 || (band_bits > (depth_threshold*band_width<>4 && j<=signalBandwidth)) #endif - { - ec_enc_bit_logp(ec, 1, 1); - break; - } - ec_enc_bit_logp(ec, 0, 1); - } else if (ec_dec_bit_logp(ec, 1)) { - break; + { + ec_enc_bit_logp(ec, 1, 1); + break; } - /*We used a bit to skip this band.*/ - psum += 1 << BITRES; - band_bits -= 1 << BITRES; - } - /*Reclaim the bits originally allocated to this band.*/ - psum -= bits[j] + intensity_rsv; - if (intensity_rsv > 0) { - intensity_rsv = LOG2_FRAC_TABLE[j - start]; - } - psum += intensity_rsv; - if (band_bits >= alloc_floor) { - /*If we have enough for a fine energy bit per channel, use it.*/ - psum += alloc_floor; - bits[j] = alloc_floor; - } else { - /*Otherwise this band gets nothing at all.*/ - bits[j] = 0; - } - } + ec_enc_bit_logp(ec, 0, 1); + } else if (ec_dec_bit_logp(ec, 1)) { + break; + } + /*We used a bit to skip this band.*/ + psum += 1< 0) + intensity_rsv = LOG2_FRAC_TABLE[j-start]; + psum += intensity_rsv; + if (band_bits >= alloc_floor) + { + /*If we have enough for a fine energy bit per channel, use it.*/ + psum += alloc_floor; + bits[j] = alloc_floor; + } else { + /*Otherwise this band gets nothing at all.*/ + bits[j] = 0; + } + } - celt_assert(codedBands > start); - /* Code the intensity and dual stereo parameters. */ - if (intensity_rsv > 0) { - if (encode) { - *intensity = IMIN(*intensity, codedBands); - ec_enc_uint(ec, *intensity - start, codedBands + 1 - start); - } else { - *intensity = start + ec_dec_uint(ec, codedBands + 1 - start); - } - } else { - *intensity = 0; - } - if (*intensity <= start) { - total += dual_stereo_rsv; - dual_stereo_rsv = 0; - } - if (dual_stereo_rsv > 0) { - if (encode) { - ec_enc_bit_logp(ec, *dual_stereo, 1); - } else { - *dual_stereo = ec_dec_bit_logp(ec, 1); - } - } else { - *dual_stereo = 0; - } + celt_assert(codedBands > start); + /* Code the intensity and dual stereo parameters. */ + if (intensity_rsv > 0) + { + if (encode) + { + *intensity = IMIN(*intensity, codedBands); + ec_enc_uint(ec, *intensity-start, codedBands+1-start); + } + else + *intensity = start+ec_dec_uint(ec, codedBands+1-start); + } + else + *intensity = 0; + if (*intensity <= start) + { + total += dual_stereo_rsv; + dual_stereo_rsv = 0; + } + if (dual_stereo_rsv > 0) + { + if (encode) + ec_enc_bit_logp(ec, *dual_stereo, 1); + else + *dual_stereo = ec_dec_bit_logp(ec, 1); + } + else + *dual_stereo = 0; - /* Allocate the remaining bits */ - left = total - psum; - percoeff = celt_udiv(left, m->eBands[codedBands] - m->eBands[start]); - left -= (m->eBands[codedBands] - m->eBands[start]) * percoeff; - for (j = start; j < codedBands; j++) { - bits[j] += ((int)percoeff * (m->eBands[j + 1] - m->eBands[j])); - } - for (j = start; j < codedBands; j++) { - int tmp = (int)IMIN(left, m->eBands[j + 1] - m->eBands[j]); - bits[j] += tmp; - left -= tmp; - } - /*for (j=0;jeBands[codedBands]-m->eBands[start]); + left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; + for (j=start;jeBands[j+1]-m->eBands[j])); + for (j=start;jeBands[j+1]-m->eBands[j]); + bits[j] += tmp; + left -= tmp; + } + /*for (j=0;j= 0); - N0 = m->eBands[j + 1] - m->eBands[j]; - N = N0 << LM; - bit = (opus_int32)bits[j] + balance; + celt_assert(bits[j] >= 0); + N0 = m->eBands[j+1]-m->eBands[j]; + N=N0< 1) { - excess = MAX32(bit - cap[j], 0); - bits[j] = bit - excess; + if (N>1) + { + excess = MAX32(bit-cap[j],0); + bits[j] = bit-excess; - /* Compensate for the extra DoF in stereo */ - den = (C * N + ((C == 2 && N > 2 && !*dual_stereo && j < *intensity) ? 1 : 0)); + /* Compensate for the extra DoF in stereo */ + den=(C*N+ ((C==2 && N>2 && !*dual_stereo && j<*intensity) ? 1 : 0)); - NClogN = den * (m->logN[j] + logM); + NClogN = den*(m->logN[j] + logM); - /* Offset for the number of fine bits by log2(N)/2 + FINE_OFFSET - compared to their "fair share" of total/N */ - offset = (NClogN >> 1) - den * FINE_OFFSET; + /* Offset for the number of fine bits by log2(N)/2 + FINE_OFFSET + compared to their "fair share" of total/N */ + offset = (NClogN>>1)-den*FINE_OFFSET; - /* N=2 is the only point that doesn't match the curve */ - if (N == 2) { - offset += den << BITRES>>2; - } + /* N=2 is the only point that doesn't match the curve */ + if (N==2) + offset += den<>2; - /* Changing the offset for allocating the second and third - fine energy bit */ - if (bits[j] + offset < den * 2 << BITRES) { - offset += NClogN >> 2; - } else if (bits[j] + offset < den * 3 << BITRES) { - offset += NClogN >> 3; - } + /* Changing the offset for allocating the second and third + fine energy bit */ + if (bits[j] + offset < den*2<>2; + else if (bits[j] + offset < den*3<>3; - /* Divide with rounding */ - ebits[j] = IMAX(0, (bits[j] + offset + (den << (BITRES - 1)))); - ebits[j] = celt_udiv(ebits[j], den) >> BITRES; + /* Divide with rounding */ + ebits[j] = IMAX(0, (bits[j] + offset + (den<<(BITRES-1)))); + ebits[j] = celt_udiv(ebits[j], den)>>BITRES; - /* Make sure not to bust */ - if (C * ebits[j] > (bits[j] >> BITRES)) { - ebits[j] = bits[j] >> stereo >> BITRES; - } + /* Make sure not to bust */ + if (C*ebits[j] > (bits[j]>>BITRES)) + ebits[j] = bits[j] >> stereo >> BITRES; - /* More than that is useless because that's about as far as PVQ can go */ - ebits[j] = IMIN(ebits[j], MAX_FINE_BITS); + /* More than that is useless because that's about as far as PVQ can go */ + ebits[j] = IMIN(ebits[j], MAX_FINE_BITS); - /* If we rounded down or capped this band, make it a candidate for the - final fine energy pass */ - fine_priority[j] = ebits[j] * (den << BITRES) >= bits[j] + offset; + /* If we rounded down or capped this band, make it a candidate for the + final fine energy pass */ + fine_priority[j] = ebits[j]*(den<= bits[j]+offset; - /* Remove the allocated fine bits; the rest are assigned to PVQ */ - bits[j] -= C * ebits[j] << BITRES; + /* Remove the allocated fine bits; the rest are assigned to PVQ */ + bits[j] -= C*ebits[j]< 0) { - int extra_fine; - int extra_bits; - extra_fine = IMIN(excess >> (stereo + BITRES), MAX_FINE_BITS - ebits[j]); - ebits[j] += extra_fine; - extra_bits = extra_fine * C << BITRES; - fine_priority[j] = extra_bits >= excess - balance; - excess -= extra_bits; - } - balance = excess; + /* Fine energy can't take advantage of the re-balancing in + quant_all_bands(). + Instead, do the re-balancing here.*/ + if(excess > 0) + { + int extra_fine; + int extra_bits; + extra_fine = IMIN(excess>>(stereo+BITRES),MAX_FINE_BITS-ebits[j]); + ebits[j] += extra_fine; + extra_bits = extra_fine*C<= excess-balance; + excess -= extra_bits; + } + balance = excess; - celt_assert(bits[j] >= 0); - celt_assert(ebits[j] >= 0); - } - /* Save any remaining bits over the cap for the rebalancing in - quant_all_bands(). */ - *_balance = balance; + celt_assert(bits[j] >= 0); + celt_assert(ebits[j] >= 0); + } + /* Save any remaining bits over the cap for the rebalancing in + quant_all_bands(). */ + *_balance = balance; - /* The skipped bands use all their bits for fine energy. */ - for (; j < end; j++) { - ebits[j] = bits[j] >> stereo >> BITRES; - celt_assert(C * ebits[j] << BITRES == bits[j]); - bits[j] = 0; - fine_priority[j] = ebits[j] < 1; - } - RESTORE_STACK; - return codedBands; + /* The skipped bands use all their bits for fine energy. */ + for (;j> stereo >> BITRES; + celt_assert(C*ebits[j]<nbEBands; - skip_start = start; - /* Reserve a bit to signal the end of manually skipped bands. */ - skip_rsv = total >= 1 << BITRES ? 1 << BITRES : 0; - total -= skip_rsv; - /* Reserve bits for the intensity and dual stereo parameters. */ - intensity_rsv = dual_stereo_rsv = 0; - if (C == 2) { - intensity_rsv = LOG2_FRAC_TABLE[end - start]; - if (intensity_rsv > total) { - intensity_rsv = 0; - } else { - total -= intensity_rsv; - dual_stereo_rsv = total >= 1 << BITRES ? 1 << BITRES : 0; - total -= dual_stereo_rsv; - } - } - ALLOC(bits1, len, int); - ALLOC(bits2, len, int); - ALLOC(thresh, len, int); - ALLOC(trim_offset, len, int); + total = IMAX(total, 0); + len = m->nbEBands; + skip_start = start; + /* Reserve a bit to signal the end of manually skipped bands. */ + skip_rsv = total >= 1<total) + intensity_rsv = 0; + else + { + total -= intensity_rsv; + dual_stereo_rsv = total>=1<eBands[j + 1] - m->eBands[j]) << LM << BITRES) >> 4); - /* Tilt of the allocation curve */ - trim_offset[j] = C * (m->eBands[j + 1] - m->eBands[j]) * (alloc_trim - 5 - LM) * (end - j - 1) - * (1 << (LM + BITRES)) >> 6; - /* Giving less resolution to single-coefficient bands because they get - more benefit from having one coarse value per coefficient*/ - if ((m->eBands[j + 1] - m->eBands[j]) << LM == 1) { - trim_offset[j] -= C << BITRES; - } - } - lo = 1; - hi = m->nbAllocVectors - 1; - do { - int done = 0; - int psum = 0; - int mid = (lo + hi) >> 1; - for (j = end; j-- > start;) { - int bitsj; - int N = m->eBands[j + 1] - m->eBands[j]; - bitsj = C * N * m->allocVectors[mid * len + j] << LM>>2; - if (bitsj > 0) { - bitsj = IMAX(0, bitsj + trim_offset[j]); - } - bitsj += offsets[j]; - if (bitsj >= thresh[j] || done) { - done = 1; - /* Don't allocate more than we can actually use */ - psum += IMIN(bitsj, cap[j]); - } else { - if (bitsj >= C << BITRES) { - psum += C << BITRES; - } - } - } - if (psum > total) { - hi = mid - 1; - } else { - lo = mid + 1; - } - /*printf ("lo = %d, hi = %d\n", lo, hi);*/ - } while (lo <= hi); - hi = lo--; - /*printf ("interp between %d and %d\n", lo, hi);*/ - for (j = start; j < end; j++) { - int bits1j, bits2j; - int N = m->eBands[j + 1] - m->eBands[j]; - bits1j = C * N * m->allocVectors[lo * len + j] << LM>>2; - bits2j = hi >= m->nbAllocVectors ? - cap[j] : C * N * m->allocVectors[hi * len + j] << LM>>2; - if (bits1j > 0) { - bits1j = IMAX(0, bits1j + trim_offset[j]); - } - if (bits2j > 0) { - bits2j = IMAX(0, bits2j + trim_offset[j]); - } - if (lo > 0) { - bits1j += offsets[j]; - } - bits2j += offsets[j]; - if (offsets[j] > 0) { - skip_start = j; - } - bits2j = IMAX(0, bits2j - bits1j); - bits1[j] = bits1j; - bits2[j] = bits2j; - } - codedBands = interp_bits2pulses(m, start, end, skip_start, bits1, bits2, thresh, cap, - total, balance, skip_rsv, intensity, intensity_rsv, dual_stereo, dual_stereo_rsv, - pulses, ebits, fine_priority, C, LM, ec, encode, prev, signalBandwidth); - RESTORE_STACK; - return codedBands; + for (j=start;jeBands[j+1]-m->eBands[j])<>4); + /* Tilt of the allocation curve */ + trim_offset[j] = C*(m->eBands[j+1]-m->eBands[j])*(alloc_trim-5-LM)*(end-j-1) + *(1<<(LM+BITRES))>>6; + /* Giving less resolution to single-coefficient bands because they get + more benefit from having one coarse value per coefficient*/ + if ((m->eBands[j+1]-m->eBands[j])<nbAllocVectors - 1; + do + { + int done = 0; + int psum = 0; + int mid = (lo+hi) >> 1; + for (j=end;j-->start;) + { + int bitsj; + int N = m->eBands[j+1]-m->eBands[j]; + bitsj = C*N*m->allocVectors[mid*len+j]<>2; + if (bitsj > 0) + bitsj = IMAX(0, bitsj + trim_offset[j]); + bitsj += offsets[j]; + if (bitsj >= thresh[j] || done) + { + done = 1; + /* Don't allocate more than we can actually use */ + psum += IMIN(bitsj, cap[j]); + } else { + if (bitsj >= C< total) + hi = mid - 1; + else + lo = mid + 1; + /*printf ("lo = %d, hi = %d\n", lo, hi);*/ + } + while (lo <= hi); + hi = lo--; + /*printf ("interp between %d and %d\n", lo, hi);*/ + for (j=start;jeBands[j+1]-m->eBands[j]; + bits1j = C*N*m->allocVectors[lo*len+j]<>2; + bits2j = hi>=m->nbAllocVectors ? + cap[j] : C*N*m->allocVectors[hi*len+j]<>2; + if (bits1j > 0) + bits1j = IMAX(0, bits1j + trim_offset[j]); + if (bits2j > 0) + bits2j = IMAX(0, bits2j + trim_offset[j]); + if (lo > 0) + bits1j += offsets[j]; + bits2j += offsets[j]; + if (offsets[j]>0) + skip_start = j; + bits2j = IMAX(0,bits2j-bits1j); + bits1[j] = bits1j; + bits2[j] = bits2j; + } + codedBands = interp_bits2pulses(m, start, end, skip_start, bits1, bits2, thresh, cap, + total, balance, skip_rsv, intensity, intensity_rsv, dual_stereo, dual_stereo_rsv, + pulses, ebits, fine_priority, C, LM, ec, encode, prev, signalBandwidth); + RESTORE_STACK; + return codedBands; } diff --git a/src/libopus/celt/rate.h b/src/libopus/celt/rate.h index 6dc699d..fad5e41 100644 --- a/src/libopus/celt/rate.h +++ b/src/libopus/celt/rate.h @@ -1,29 +1,29 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RATE_H @@ -45,55 +45,57 @@ void compute_pulse_cache(CELTMode *m, int LM); -static OPUS_INLINE int get_pulses(int i) { - return i < 8 ? i : (8 + (i & 7)) << ((i >> 3) - 1); +static OPUS_INLINE int get_pulses(int i) +{ + return i<8 ? i : (8 + (i&7)) << ((i>>3)-1); } -static OPUS_INLINE int bits2pulses(const CELTMode *m, int band, int LM, int bits) { - int i; - int lo, hi; - const unsigned char *cache; +static OPUS_INLINE int bits2pulses(const CELTMode *m, int band, int LM, int bits) +{ + int i; + int lo, hi; + const unsigned char *cache; - LM++; - cache = m->cache.bits + m->cache.index[LM * m->nbEBands + band]; + LM++; + cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; - lo = 0; - hi = cache[0]; - bits--; - for (i = 0; i < LOG_MAX_PSEUDO; i++) { - int mid = (lo + hi + 1) >> 1; - /* OPT: Make sure this is implemented with a conditional move */ - if ((int)cache[mid] >= bits) { - hi = mid; - } else { - lo = mid; - } - } - if (bits - (lo == 0 ? -1 : (int)cache[lo]) <= (int)cache[hi] - bits) { - return lo; - } else { - return hi; - } + lo = 0; + hi = cache[0]; + bits--; + for (i=0;i>1; + /* OPT: Make sure this is implemented with a conditional move */ + if ((int)cache[mid] >= bits) + hi = mid; + else + lo = mid; + } + if (bits- (lo == 0 ? -1 : (int)cache[lo]) <= (int)cache[hi]-bits) + return lo; + else + return hi; } -static OPUS_INLINE int pulses2bits(const CELTMode *m, int band, int LM, int pulses) { - const unsigned char *cache; +static OPUS_INLINE int pulses2bits(const CELTMode *m, int band, int LM, int pulses) +{ + const unsigned char *cache; - LM++; - cache = m->cache.bits + m->cache.index[LM * m->nbEBands + band]; - return pulses == 0 ? 0 : cache[pulses] + 1; + LM++; + cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; + return pulses == 0 ? 0 : cache[pulses]+1; } /** Compute the pulse allocation, i.e. how many pulses will go in each - band. - @param m mode - @param offsets Requested increase or decrease in the number of bits for + * band. + @param m mode + @param offsets Requested increase or decrease in the number of bits for each band - @param total Number of bands - @param pulses Number of pulses per band (returned) - @return Total number of bits allocated + @param total Number of bands + @param pulses Number of pulses per band (returned) + @return Total number of bits allocated */ int clt_compute_allocation(const CELTMode *m, int start, int end, const int *offsets, const int *cap, int alloc_trim, int *intensity, int *dual_stereo, - opus_int32 total, opus_int32 *balance, int *pulses, int *ebits, int *fine_priority, int C, int LM, ec_ctx *ec, int encode, int prev, int signalBandwidth); + opus_int32 total, opus_int32 *balance, int *pulses, int *ebits, int *fine_priority, int C, int LM, ec_ctx *ec, int encode, int prev, int signalBandwidth); #endif diff --git a/src/libopus/celt/stack_alloc.h b/src/libopus/celt/stack_alloc.h index 433b016..e2739bd 100644 --- a/src/libopus/celt/stack_alloc.h +++ b/src/libopus/celt/stack_alloc.h @@ -1,46 +1,46 @@ -/* Copyright (C) 2002-2003 Jean-Marc Valin - Copyright (C) 2007-2009 Xiph.Org Foundation */ +/* Copyright (C) 2002-2003 Jean-Marc Valin + Copyright (C) 2007-2009 Xiph.Org Foundation */ /** - @file stack_alloc.h - @brief Temporary memory allocation on stack + @file stack_alloc.h + @brief Temporary memory allocation on stack */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef STACK_ALLOC_H #define STACK_ALLOC_H -#include "../opus_types.h" -#include "../opus_defines.h" +#include "opus_types.h" +#include "opus_defines.h" #if (!defined (VAR_ARRAYS) && !defined (USE_ALLOCA) && !defined (NONTHREADSAFE_PSEUDOSTACK)) #error "Opus requires one of VAR_ARRAYS, USE_ALLOCA, or NONTHREADSAFE_PSEUDOSTACK be defined to select the temporary allocation mode." #endif #ifdef USE_ALLOCA -# ifdef WIN32 +# ifdef _WIN32 # include # else # ifdef HAVE_ALLOCA_H @@ -52,41 +52,41 @@ #endif /** - @def ALIGN(stack, size) - - Aligns the stack to a 'size' boundary - - @param stack Stack - @param size New size boundary -*/ + * @def ALIGN(stack, size) + * + * Aligns the stack to a 'size' boundary + * + * @param stack Stack + * @param size New size boundary + */ /** - @def PUSH(stack, size, type) - - Allocates 'size' elements of type 'type' on the stack - - @param stack Stack - @param size Number of elements - @param type Type of element -*/ + * @def PUSH(stack, size, type) + * + * Allocates 'size' elements of type 'type' on the stack + * + * @param stack Stack + * @param size Number of elements + * @param type Type of element + */ /** - @def VARDECL(var) - - Declare variable on stack - - @param var Variable to declare -*/ + * @def VARDECL(var) + * + * Declare variable on stack + * + * @param var Variable to declare + */ /** - @def ALLOC(var, size, type) - - Allocate 'size' elements of 'type' on stack - - @param var Name of variable to allocate - @param size Number of elements - @param type Type of element -*/ + * @def ALLOC(var, size, type) + * + * Allocate 'size' elements of 'type' on stack + * + * @param var Name of variable to allocate + * @param size Number of elements + * @param type Type of element + */ #if defined(VAR_ARRAYS) @@ -102,7 +102,7 @@ #define VARDECL(type, var) type *var -# ifdef WIN32 +# ifdef _WIN32 # define ALLOC(var, size, type) var = ((type*)_alloca(sizeof(type)*(size))) # else # define ALLOC(var, size, type) var = ((type*)alloca(sizeof(type)*(size))) @@ -116,8 +116,8 @@ #else #ifdef CELT_C -char *scratch_ptr = 0; -char *global_stack = 0; +char *scratch_ptr=0; +char *global_stack=0; #else extern char *global_stack; extern char *scratch_ptr; @@ -128,7 +128,7 @@ extern char *scratch_ptr; #include #ifdef CELT_C -char *global_stack_top = 0; +char *global_stack_top=0; #else extern char *global_stack_top; #endif /* CELT_C */ @@ -141,7 +141,7 @@ extern char *global_stack_top; #else #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) -#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/sizeof(char)),(stack)+=(size)*(sizeof(type)/sizeof(char)),(type*)((stack)-(size)*(sizeof(type)/sizeof(char)))) +#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/(sizeof(char))),(stack)+=(size)*(sizeof(type)/(sizeof(char))),(type*)((stack)-(size)*(sizeof(type)/(sizeof(char))))) #if 0 /* Set this to 1 to instrument pseudostack usage */ #define RESTORE_STACK (printf("%ld %s:%d\n", global_stack-scratch_ptr, __FILE__, __LINE__),global_stack = _saved_stack) #else @@ -172,9 +172,7 @@ extern char *global_stack_top; #else -static OPUS_INLINE int _opus_false(void) { - return 0; -} +static OPUS_INLINE int _opus_false(void) {return 0;} #define OPUS_CHECK_ARRAY(ptr, len) _opus_false() #define OPUS_CHECK_VALUE(value) _opus_false() #define OPUS_PRINT_INT(value) do{}while(0) diff --git a/src/libopus/celt/static_modes_fixed.h b/src/libopus/celt/static_modes_fixed.h index 5624981..8717d62 100644 --- a/src/libopus/celt/static_modes_fixed.h +++ b/src/libopus/celt/static_modes_fixed.h @@ -1,6 +1,6 @@ -/* The contents of this file was automatically generated by dump_modes.c - with arguments: 48000 960 - It contains static definitions for some pre-defined modes. */ +/* The contents of this file was automatically generated by dump_modes.c + with arguments: 48000 960 + It contains static definitions for some pre-defined modes. */ #include "modes.h" #include "rate.h" @@ -12,438 +12,435 @@ #ifndef DEF_WINDOW120 #define DEF_WINDOW120 static const opus_val16 window120[120] = { - 2, 20, 55, 108, 178, - 266, 372, 494, 635, 792, - 966, 1157, 1365, 1590, 1831, - 2089, 2362, 2651, 2956, 3276, - 3611, 3961, 4325, 4703, 5094, - 5499, 5916, 6346, 6788, 7241, - 7705, 8179, 8663, 9156, 9657, - 10167, 10684, 11207, 11736, 12271, - 12810, 13353, 13899, 14447, 14997, - 15547, 16098, 16648, 17197, 17744, - 18287, 18827, 19363, 19893, 20418, - 20936, 21447, 21950, 22445, 22931, - 23407, 23874, 24330, 24774, 25208, - 25629, 26039, 26435, 26819, 27190, - 27548, 27893, 28224, 28541, 28845, - 29135, 29411, 29674, 29924, 30160, - 30384, 30594, 30792, 30977, 31151, - 31313, 31463, 31602, 31731, 31849, - 31958, 32057, 32148, 32229, 32303, - 32370, 32429, 32481, 32528, 32568, - 32604, 32634, 32661, 32683, 32701, - 32717, 32729, 32740, 32748, 32754, - 32758, 32762, 32764, 32766, 32767, - 32767, 32767, 32767, 32767, 32767, +2, 20, 55, 108, 178, +266, 372, 494, 635, 792, +966, 1157, 1365, 1590, 1831, +2089, 2362, 2651, 2956, 3276, +3611, 3961, 4325, 4703, 5094, +5499, 5916, 6346, 6788, 7241, +7705, 8179, 8663, 9156, 9657, +10167, 10684, 11207, 11736, 12271, +12810, 13353, 13899, 14447, 14997, +15547, 16098, 16648, 17197, 17744, +18287, 18827, 19363, 19893, 20418, +20936, 21447, 21950, 22445, 22931, +23407, 23874, 24330, 24774, 25208, +25629, 26039, 26435, 26819, 27190, +27548, 27893, 28224, 28541, 28845, +29135, 29411, 29674, 29924, 30160, +30384, 30594, 30792, 30977, 31151, +31313, 31463, 31602, 31731, 31849, +31958, 32057, 32148, 32229, 32303, +32370, 32429, 32481, 32528, 32568, +32604, 32634, 32661, 32683, 32701, +32717, 32729, 32740, 32748, 32754, +32758, 32762, 32764, 32766, 32767, +32767, 32767, 32767, 32767, 32767, }; #endif #ifndef DEF_LOGN400 #define DEF_LOGN400 static const opus_int16 logN400[21] = { - 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 16, 16, 16, 21, 21, 24, 29, 34, 36, -}; +0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 16, 16, 16, 21, 21, 24, 29, 34, 36, }; #endif #ifndef DEF_PULSE_CACHE50 #define DEF_PULSE_CACHE50 static const opus_int16 cache_index50[105] = { - -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 41, 41, 41, - 82, 82, 123, 164, 200, 222, 0, 0, 0, 0, 0, 0, 0, 0, 41, - 41, 41, 41, 123, 123, 123, 164, 164, 240, 266, 283, 295, 41, 41, 41, - 41, 41, 41, 41, 41, 123, 123, 123, 123, 240, 240, 240, 266, 266, 305, - 318, 328, 336, 123, 123, 123, 123, 123, 123, 123, 123, 240, 240, 240, 240, - 305, 305, 305, 318, 318, 343, 351, 358, 364, 240, 240, 240, 240, 240, 240, - 240, 240, 305, 305, 305, 305, 343, 343, 343, 351, 351, 370, 376, 382, 387, - }; +-1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 41, 41, 41, +82, 82, 123, 164, 200, 222, 0, 0, 0, 0, 0, 0, 0, 0, 41, +41, 41, 41, 123, 123, 123, 164, 164, 240, 266, 283, 295, 41, 41, 41, +41, 41, 41, 41, 41, 123, 123, 123, 123, 240, 240, 240, 266, 266, 305, +318, 328, 336, 123, 123, 123, 123, 123, 123, 123, 123, 240, 240, 240, 240, +305, 305, 305, 318, 318, 343, 351, 358, 364, 240, 240, 240, 240, 240, 240, +240, 240, 305, 305, 305, 305, 343, 343, 343, 351, 351, 370, 376, 382, 387, +}; static const unsigned char cache_bits50[392] = { - 40, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 40, 15, 23, 28, - 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, 47, 49, 50, - 51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 63, 63, 65, - 66, 67, 68, 69, 70, 71, 71, 40, 20, 33, 41, 48, 53, 57, 61, - 64, 66, 69, 71, 73, 75, 76, 78, 80, 82, 85, 87, 89, 91, 92, - 94, 96, 98, 101, 103, 105, 107, 108, 110, 112, 114, 117, 119, 121, 123, - 124, 126, 128, 40, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, - 97, 100, 102, 105, 107, 111, 115, 118, 121, 124, 126, 129, 131, 135, 139, - 142, 145, 148, 150, 153, 155, 159, 163, 166, 169, 172, 174, 177, 179, 35, - 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, - 153, 159, 165, 171, 176, 180, 185, 189, 192, 199, 205, 211, 216, 220, 225, - 229, 232, 239, 245, 251, 21, 33, 58, 79, 97, 112, 125, 137, 148, 157, - 166, 174, 182, 189, 195, 201, 207, 217, 227, 235, 243, 251, 17, 35, 63, - 86, 106, 123, 139, 152, 165, 177, 187, 197, 206, 214, 222, 230, 237, 250, - 25, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, - 185, 190, 200, 208, 215, 222, 229, 235, 240, 245, 255, 16, 36, 65, 89, - 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250, 11, 41, - 74, 103, 128, 151, 172, 191, 209, 225, 241, 255, 9, 43, 79, 110, 138, - 163, 186, 207, 227, 246, 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, - 228, 241, 253, 9, 44, 81, 113, 142, 168, 192, 214, 235, 255, 7, 49, - 90, 127, 160, 191, 220, 247, 6, 51, 95, 134, 170, 203, 234, 7, 47, - 87, 123, 155, 184, 212, 237, 6, 52, 97, 137, 174, 208, 240, 5, 57, - 106, 151, 192, 231, 5, 59, 111, 158, 202, 243, 5, 55, 103, 147, 187, - 224, 5, 60, 113, 161, 206, 248, 4, 65, 122, 175, 224, 4, 67, 127, - 182, 234, -}; +40, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, +7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, +7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 40, 15, 23, 28, +31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, 47, 49, 50, +51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 63, 63, 65, +66, 67, 68, 69, 70, 71, 71, 40, 20, 33, 41, 48, 53, 57, 61, +64, 66, 69, 71, 73, 75, 76, 78, 80, 82, 85, 87, 89, 91, 92, +94, 96, 98, 101, 103, 105, 107, 108, 110, 112, 114, 117, 119, 121, 123, +124, 126, 128, 40, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, +97, 100, 102, 105, 107, 111, 115, 118, 121, 124, 126, 129, 131, 135, 139, +142, 145, 148, 150, 153, 155, 159, 163, 166, 169, 172, 174, 177, 179, 35, +28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, +153, 159, 165, 171, 176, 180, 185, 189, 192, 199, 205, 211, 216, 220, 225, +229, 232, 239, 245, 251, 21, 33, 58, 79, 97, 112, 125, 137, 148, 157, +166, 174, 182, 189, 195, 201, 207, 217, 227, 235, 243, 251, 17, 35, 63, +86, 106, 123, 139, 152, 165, 177, 187, 197, 206, 214, 222, 230, 237, 250, +25, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, +185, 190, 200, 208, 215, 222, 229, 235, 240, 245, 255, 16, 36, 65, 89, +110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250, 11, 41, +74, 103, 128, 151, 172, 191, 209, 225, 241, 255, 9, 43, 79, 110, 138, +163, 186, 207, 227, 246, 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, +228, 241, 253, 9, 44, 81, 113, 142, 168, 192, 214, 235, 255, 7, 49, +90, 127, 160, 191, 220, 247, 6, 51, 95, 134, 170, 203, 234, 7, 47, +87, 123, 155, 184, 212, 237, 6, 52, 97, 137, 174, 208, 240, 5, 57, +106, 151, 192, 231, 5, 59, 111, 158, 202, 243, 5, 55, 103, 147, 187, +224, 5, 60, 113, 161, 206, 248, 4, 65, 122, 175, 224, 4, 67, 127, +182, 234, }; static const unsigned char cache_caps50[168] = { - 224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, - 178, 178, 168, 134, 61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, - 240, 240, 240, 207, 207, 207, 198, 198, 183, 144, 66, 40, 160, 160, 160, - 160, 160, 160, 160, 160, 185, 185, 185, 185, 193, 193, 193, 183, 183, 172, - 138, 64, 38, 240, 240, 240, 240, 240, 240, 240, 240, 207, 207, 207, 207, - 204, 204, 204, 193, 193, 180, 143, 66, 40, 185, 185, 185, 185, 185, 185, - 185, 185, 193, 193, 193, 193, 193, 193, 193, 183, 183, 172, 138, 65, 39, - 207, 207, 207, 207, 207, 207, 207, 207, 204, 204, 204, 204, 201, 201, 201, - 188, 188, 176, 141, 66, 40, 193, 193, 193, 193, 193, 193, 193, 193, 193, - 193, 193, 193, 194, 194, 194, 184, 184, 173, 139, 65, 39, 204, 204, 204, - 204, 204, 204, 204, 204, 201, 201, 201, 201, 198, 198, 198, 187, 187, 175, - 140, 66, 40, -}; +224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, +178, 178, 168, 134, 61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, +240, 240, 240, 207, 207, 207, 198, 198, 183, 144, 66, 40, 160, 160, 160, +160, 160, 160, 160, 160, 185, 185, 185, 185, 193, 193, 193, 183, 183, 172, +138, 64, 38, 240, 240, 240, 240, 240, 240, 240, 240, 207, 207, 207, 207, +204, 204, 204, 193, 193, 180, 143, 66, 40, 185, 185, 185, 185, 185, 185, +185, 185, 193, 193, 193, 193, 193, 193, 193, 183, 183, 172, 138, 65, 39, +207, 207, 207, 207, 207, 207, 207, 207, 204, 204, 204, 204, 201, 201, 201, +188, 188, 176, 141, 66, 40, 193, 193, 193, 193, 193, 193, 193, 193, 193, +193, 193, 193, 194, 194, 194, 184, 184, 173, 139, 65, 39, 204, 204, 204, +204, 204, 204, 204, 204, 201, 201, 201, 201, 198, 198, 198, 187, 187, 175, +140, 66, 40, }; #endif #ifndef FFT_TWIDDLES48000_960 #define FFT_TWIDDLES48000_960 static const kiss_twiddle_cpx fft_twiddles48000_960[480] = { - {32767, 0}, {32766, -429}, - {32757, -858}, {32743, -1287}, - {32724, -1715}, {32698, -2143}, - {32667, -2570}, {32631, -2998}, - {32588, -3425}, {32541, -3851}, - {32488, -4277}, {32429, -4701}, - {32364, -5125}, {32295, -5548}, - {32219, -5971}, {32138, -6393}, - {32051, -6813}, {31960, -7231}, - {31863, -7650}, {31760, -8067}, - {31652, -8481}, {31539, -8895}, - {31419, -9306}, {31294, -9716}, - {31165, -10126}, {31030, -10532}, - {30889, -10937}, {30743, -11340}, - {30592, -11741}, {30436, -12141}, - {30274, -12540}, {30107, -12935}, - {29936, -13328}, {29758, -13718}, - {29577, -14107}, {29390, -14493}, - {29197, -14875}, {29000, -15257}, - {28797, -15635}, {28590, -16010}, - {28379, -16384}, {28162, -16753}, - {27940, -17119}, {27714, -17484}, - {27482, -17845}, {27246, -18205}, - {27006, -18560}, {26760, -18911}, - {26510, -19260}, {26257, -19606}, - {25997, -19947}, {25734, -20286}, - {25466, -20621}, {25194, -20952}, - {24918, -21281}, {24637, -21605}, - {24353, -21926}, {24063, -22242}, - {23770, -22555}, {23473, -22865}, - {23171, -23171}, {22866, -23472}, - {22557, -23769}, {22244, -24063}, - {21927, -24352}, {21606, -24636}, - {21282, -24917}, {20954, -25194}, - {20622, -25465}, {20288, -25733}, - {19949, -25997}, {19607, -26255}, - {19261, -26509}, {18914, -26760}, - {18561, -27004}, {18205, -27246}, - {17846, -27481}, {17485, -27713}, - {17122, -27940}, {16755, -28162}, - {16385, -28378}, {16012, -28590}, - {15636, -28797}, {15258, -28999}, - {14878, -29197}, {14494, -29389}, - {14108, -29576}, {13720, -29757}, - {13329, -29934}, {12937, -30107}, - {12540, -30274}, {12142, -30435}, - {11744, -30592}, {11342, -30743}, - {10939, -30889}, {10534, -31030}, - {10127, -31164}, {9718, -31294}, - {9307, -31418}, {8895, -31537}, - {8482, -31652}, {8067, -31759}, - {7650, -31862}, {7233, -31960}, - {6815, -32051}, {6393, -32138}, - {5973, -32219}, {5549, -32294}, - {5127, -32364}, {4703, -32429}, - {4278, -32487}, {3852, -32541}, - {3426, -32588}, {2999, -32630}, - {2572, -32667}, {2144, -32698}, - {1716, -32724}, {1287, -32742}, - {860, -32757}, {430, -32766}, - {0, -32767}, {-429, -32766}, - {-858, -32757}, {-1287, -32743}, - {-1715, -32724}, {-2143, -32698}, - {-2570, -32667}, {-2998, -32631}, - {-3425, -32588}, {-3851, -32541}, - {-4277, -32488}, {-4701, -32429}, - {-5125, -32364}, {-5548, -32295}, - {-5971, -32219}, {-6393, -32138}, - {-6813, -32051}, {-7231, -31960}, - {-7650, -31863}, {-8067, -31760}, - {-8481, -31652}, {-8895, -31539}, - {-9306, -31419}, {-9716, -31294}, - {-10126, -31165}, {-10532, -31030}, - {-10937, -30889}, {-11340, -30743}, - {-11741, -30592}, {-12141, -30436}, - {-12540, -30274}, {-12935, -30107}, - {-13328, -29936}, {-13718, -29758}, - {-14107, -29577}, {-14493, -29390}, - {-14875, -29197}, {-15257, -29000}, - {-15635, -28797}, {-16010, -28590}, - {-16384, -28379}, {-16753, -28162}, - {-17119, -27940}, {-17484, -27714}, - {-17845, -27482}, {-18205, -27246}, - {-18560, -27006}, {-18911, -26760}, - {-19260, -26510}, {-19606, -26257}, - {-19947, -25997}, {-20286, -25734}, - {-20621, -25466}, {-20952, -25194}, - {-21281, -24918}, {-21605, -24637}, - {-21926, -24353}, {-22242, -24063}, - {-22555, -23770}, {-22865, -23473}, - {-23171, -23171}, {-23472, -22866}, - {-23769, -22557}, {-24063, -22244}, - {-24352, -21927}, {-24636, -21606}, - {-24917, -21282}, {-25194, -20954}, - {-25465, -20622}, {-25733, -20288}, - {-25997, -19949}, {-26255, -19607}, - {-26509, -19261}, {-26760, -18914}, - {-27004, -18561}, {-27246, -18205}, - {-27481, -17846}, {-27713, -17485}, - {-27940, -17122}, {-28162, -16755}, - {-28378, -16385}, {-28590, -16012}, - {-28797, -15636}, {-28999, -15258}, - {-29197, -14878}, {-29389, -14494}, - {-29576, -14108}, {-29757, -13720}, - {-29934, -13329}, {-30107, -12937}, - {-30274, -12540}, {-30435, -12142}, - {-30592, -11744}, {-30743, -11342}, - {-30889, -10939}, {-31030, -10534}, - {-31164, -10127}, {-31294, -9718}, - {-31418, -9307}, {-31537, -8895}, - {-31652, -8482}, {-31759, -8067}, - {-31862, -7650}, {-31960, -7233}, - {-32051, -6815}, {-32138, -6393}, - {-32219, -5973}, {-32294, -5549}, - {-32364, -5127}, {-32429, -4703}, - {-32487, -4278}, {-32541, -3852}, - {-32588, -3426}, {-32630, -2999}, - {-32667, -2572}, {-32698, -2144}, - {-32724, -1716}, {-32742, -1287}, - {-32757, -860}, {-32766, -430}, - {-32767, 0}, {-32766, 429}, - {-32757, 858}, {-32743, 1287}, - {-32724, 1715}, {-32698, 2143}, - {-32667, 2570}, {-32631, 2998}, - {-32588, 3425}, {-32541, 3851}, - {-32488, 4277}, {-32429, 4701}, - {-32364, 5125}, {-32295, 5548}, - {-32219, 5971}, {-32138, 6393}, - {-32051, 6813}, {-31960, 7231}, - {-31863, 7650}, {-31760, 8067}, - {-31652, 8481}, {-31539, 8895}, - {-31419, 9306}, {-31294, 9716}, - {-31165, 10126}, {-31030, 10532}, - {-30889, 10937}, {-30743, 11340}, - {-30592, 11741}, {-30436, 12141}, - {-30274, 12540}, {-30107, 12935}, - {-29936, 13328}, {-29758, 13718}, - {-29577, 14107}, {-29390, 14493}, - {-29197, 14875}, {-29000, 15257}, - {-28797, 15635}, {-28590, 16010}, - {-28379, 16384}, {-28162, 16753}, - {-27940, 17119}, {-27714, 17484}, - {-27482, 17845}, {-27246, 18205}, - {-27006, 18560}, {-26760, 18911}, - {-26510, 19260}, {-26257, 19606}, - {-25997, 19947}, {-25734, 20286}, - {-25466, 20621}, {-25194, 20952}, - {-24918, 21281}, {-24637, 21605}, - {-24353, 21926}, {-24063, 22242}, - {-23770, 22555}, {-23473, 22865}, - {-23171, 23171}, {-22866, 23472}, - {-22557, 23769}, {-22244, 24063}, - {-21927, 24352}, {-21606, 24636}, - {-21282, 24917}, {-20954, 25194}, - {-20622, 25465}, {-20288, 25733}, - {-19949, 25997}, {-19607, 26255}, - {-19261, 26509}, {-18914, 26760}, - {-18561, 27004}, {-18205, 27246}, - {-17846, 27481}, {-17485, 27713}, - {-17122, 27940}, {-16755, 28162}, - {-16385, 28378}, {-16012, 28590}, - {-15636, 28797}, {-15258, 28999}, - {-14878, 29197}, {-14494, 29389}, - {-14108, 29576}, {-13720, 29757}, - {-13329, 29934}, {-12937, 30107}, - {-12540, 30274}, {-12142, 30435}, - {-11744, 30592}, {-11342, 30743}, - {-10939, 30889}, {-10534, 31030}, - {-10127, 31164}, {-9718, 31294}, - {-9307, 31418}, {-8895, 31537}, - {-8482, 31652}, {-8067, 31759}, - {-7650, 31862}, {-7233, 31960}, - {-6815, 32051}, {-6393, 32138}, - {-5973, 32219}, {-5549, 32294}, - {-5127, 32364}, {-4703, 32429}, - {-4278, 32487}, {-3852, 32541}, - {-3426, 32588}, {-2999, 32630}, - {-2572, 32667}, {-2144, 32698}, - {-1716, 32724}, {-1287, 32742}, - {-860, 32757}, {-430, 32766}, - {0, 32767}, {429, 32766}, - {858, 32757}, {1287, 32743}, - {1715, 32724}, {2143, 32698}, - {2570, 32667}, {2998, 32631}, - {3425, 32588}, {3851, 32541}, - {4277, 32488}, {4701, 32429}, - {5125, 32364}, {5548, 32295}, - {5971, 32219}, {6393, 32138}, - {6813, 32051}, {7231, 31960}, - {7650, 31863}, {8067, 31760}, - {8481, 31652}, {8895, 31539}, - {9306, 31419}, {9716, 31294}, - {10126, 31165}, {10532, 31030}, - {10937, 30889}, {11340, 30743}, - {11741, 30592}, {12141, 30436}, - {12540, 30274}, {12935, 30107}, - {13328, 29936}, {13718, 29758}, - {14107, 29577}, {14493, 29390}, - {14875, 29197}, {15257, 29000}, - {15635, 28797}, {16010, 28590}, - {16384, 28379}, {16753, 28162}, - {17119, 27940}, {17484, 27714}, - {17845, 27482}, {18205, 27246}, - {18560, 27006}, {18911, 26760}, - {19260, 26510}, {19606, 26257}, - {19947, 25997}, {20286, 25734}, - {20621, 25466}, {20952, 25194}, - {21281, 24918}, {21605, 24637}, - {21926, 24353}, {22242, 24063}, - {22555, 23770}, {22865, 23473}, - {23171, 23171}, {23472, 22866}, - {23769, 22557}, {24063, 22244}, - {24352, 21927}, {24636, 21606}, - {24917, 21282}, {25194, 20954}, - {25465, 20622}, {25733, 20288}, - {25997, 19949}, {26255, 19607}, - {26509, 19261}, {26760, 18914}, - {27004, 18561}, {27246, 18205}, - {27481, 17846}, {27713, 17485}, - {27940, 17122}, {28162, 16755}, - {28378, 16385}, {28590, 16012}, - {28797, 15636}, {28999, 15258}, - {29197, 14878}, {29389, 14494}, - {29576, 14108}, {29757, 13720}, - {29934, 13329}, {30107, 12937}, - {30274, 12540}, {30435, 12142}, - {30592, 11744}, {30743, 11342}, - {30889, 10939}, {31030, 10534}, - {31164, 10127}, {31294, 9718}, - {31418, 9307}, {31537, 8895}, - {31652, 8482}, {31759, 8067}, - {31862, 7650}, {31960, 7233}, - {32051, 6815}, {32138, 6393}, - {32219, 5973}, {32294, 5549}, - {32364, 5127}, {32429, 4703}, - {32487, 4278}, {32541, 3852}, - {32588, 3426}, {32630, 2999}, - {32667, 2572}, {32698, 2144}, - {32724, 1716}, {32742, 1287}, - {32757, 860}, {32766, 430}, +{32767, 0}, {32766, -429}, +{32757, -858}, {32743, -1287}, +{32724, -1715}, {32698, -2143}, +{32667, -2570}, {32631, -2998}, +{32588, -3425}, {32541, -3851}, +{32488, -4277}, {32429, -4701}, +{32364, -5125}, {32295, -5548}, +{32219, -5971}, {32138, -6393}, +{32051, -6813}, {31960, -7231}, +{31863, -7650}, {31760, -8067}, +{31652, -8481}, {31539, -8895}, +{31419, -9306}, {31294, -9716}, +{31165, -10126}, {31030, -10532}, +{30889, -10937}, {30743, -11340}, +{30592, -11741}, {30436, -12141}, +{30274, -12540}, {30107, -12935}, +{29936, -13328}, {29758, -13718}, +{29577, -14107}, {29390, -14493}, +{29197, -14875}, {29000, -15257}, +{28797, -15635}, {28590, -16010}, +{28379, -16384}, {28162, -16753}, +{27940, -17119}, {27714, -17484}, +{27482, -17845}, {27246, -18205}, +{27006, -18560}, {26760, -18911}, +{26510, -19260}, {26257, -19606}, +{25997, -19947}, {25734, -20286}, +{25466, -20621}, {25194, -20952}, +{24918, -21281}, {24637, -21605}, +{24353, -21926}, {24063, -22242}, +{23770, -22555}, {23473, -22865}, +{23171, -23171}, {22866, -23472}, +{22557, -23769}, {22244, -24063}, +{21927, -24352}, {21606, -24636}, +{21282, -24917}, {20954, -25194}, +{20622, -25465}, {20288, -25733}, +{19949, -25997}, {19607, -26255}, +{19261, -26509}, {18914, -26760}, +{18561, -27004}, {18205, -27246}, +{17846, -27481}, {17485, -27713}, +{17122, -27940}, {16755, -28162}, +{16385, -28378}, {16012, -28590}, +{15636, -28797}, {15258, -28999}, +{14878, -29197}, {14494, -29389}, +{14108, -29576}, {13720, -29757}, +{13329, -29934}, {12937, -30107}, +{12540, -30274}, {12142, -30435}, +{11744, -30592}, {11342, -30743}, +{10939, -30889}, {10534, -31030}, +{10127, -31164}, {9718, -31294}, +{9307, -31418}, {8895, -31537}, +{8482, -31652}, {8067, -31759}, +{7650, -31862}, {7233, -31960}, +{6815, -32051}, {6393, -32138}, +{5973, -32219}, {5549, -32294}, +{5127, -32364}, {4703, -32429}, +{4278, -32487}, {3852, -32541}, +{3426, -32588}, {2999, -32630}, +{2572, -32667}, {2144, -32698}, +{1716, -32724}, {1287, -32742}, +{860, -32757}, {430, -32766}, +{0, -32767}, {-429, -32766}, +{-858, -32757}, {-1287, -32743}, +{-1715, -32724}, {-2143, -32698}, +{-2570, -32667}, {-2998, -32631}, +{-3425, -32588}, {-3851, -32541}, +{-4277, -32488}, {-4701, -32429}, +{-5125, -32364}, {-5548, -32295}, +{-5971, -32219}, {-6393, -32138}, +{-6813, -32051}, {-7231, -31960}, +{-7650, -31863}, {-8067, -31760}, +{-8481, -31652}, {-8895, -31539}, +{-9306, -31419}, {-9716, -31294}, +{-10126, -31165}, {-10532, -31030}, +{-10937, -30889}, {-11340, -30743}, +{-11741, -30592}, {-12141, -30436}, +{-12540, -30274}, {-12935, -30107}, +{-13328, -29936}, {-13718, -29758}, +{-14107, -29577}, {-14493, -29390}, +{-14875, -29197}, {-15257, -29000}, +{-15635, -28797}, {-16010, -28590}, +{-16384, -28379}, {-16753, -28162}, +{-17119, -27940}, {-17484, -27714}, +{-17845, -27482}, {-18205, -27246}, +{-18560, -27006}, {-18911, -26760}, +{-19260, -26510}, {-19606, -26257}, +{-19947, -25997}, {-20286, -25734}, +{-20621, -25466}, {-20952, -25194}, +{-21281, -24918}, {-21605, -24637}, +{-21926, -24353}, {-22242, -24063}, +{-22555, -23770}, {-22865, -23473}, +{-23171, -23171}, {-23472, -22866}, +{-23769, -22557}, {-24063, -22244}, +{-24352, -21927}, {-24636, -21606}, +{-24917, -21282}, {-25194, -20954}, +{-25465, -20622}, {-25733, -20288}, +{-25997, -19949}, {-26255, -19607}, +{-26509, -19261}, {-26760, -18914}, +{-27004, -18561}, {-27246, -18205}, +{-27481, -17846}, {-27713, -17485}, +{-27940, -17122}, {-28162, -16755}, +{-28378, -16385}, {-28590, -16012}, +{-28797, -15636}, {-28999, -15258}, +{-29197, -14878}, {-29389, -14494}, +{-29576, -14108}, {-29757, -13720}, +{-29934, -13329}, {-30107, -12937}, +{-30274, -12540}, {-30435, -12142}, +{-30592, -11744}, {-30743, -11342}, +{-30889, -10939}, {-31030, -10534}, +{-31164, -10127}, {-31294, -9718}, +{-31418, -9307}, {-31537, -8895}, +{-31652, -8482}, {-31759, -8067}, +{-31862, -7650}, {-31960, -7233}, +{-32051, -6815}, {-32138, -6393}, +{-32219, -5973}, {-32294, -5549}, +{-32364, -5127}, {-32429, -4703}, +{-32487, -4278}, {-32541, -3852}, +{-32588, -3426}, {-32630, -2999}, +{-32667, -2572}, {-32698, -2144}, +{-32724, -1716}, {-32742, -1287}, +{-32757, -860}, {-32766, -430}, +{-32767, 0}, {-32766, 429}, +{-32757, 858}, {-32743, 1287}, +{-32724, 1715}, {-32698, 2143}, +{-32667, 2570}, {-32631, 2998}, +{-32588, 3425}, {-32541, 3851}, +{-32488, 4277}, {-32429, 4701}, +{-32364, 5125}, {-32295, 5548}, +{-32219, 5971}, {-32138, 6393}, +{-32051, 6813}, {-31960, 7231}, +{-31863, 7650}, {-31760, 8067}, +{-31652, 8481}, {-31539, 8895}, +{-31419, 9306}, {-31294, 9716}, +{-31165, 10126}, {-31030, 10532}, +{-30889, 10937}, {-30743, 11340}, +{-30592, 11741}, {-30436, 12141}, +{-30274, 12540}, {-30107, 12935}, +{-29936, 13328}, {-29758, 13718}, +{-29577, 14107}, {-29390, 14493}, +{-29197, 14875}, {-29000, 15257}, +{-28797, 15635}, {-28590, 16010}, +{-28379, 16384}, {-28162, 16753}, +{-27940, 17119}, {-27714, 17484}, +{-27482, 17845}, {-27246, 18205}, +{-27006, 18560}, {-26760, 18911}, +{-26510, 19260}, {-26257, 19606}, +{-25997, 19947}, {-25734, 20286}, +{-25466, 20621}, {-25194, 20952}, +{-24918, 21281}, {-24637, 21605}, +{-24353, 21926}, {-24063, 22242}, +{-23770, 22555}, {-23473, 22865}, +{-23171, 23171}, {-22866, 23472}, +{-22557, 23769}, {-22244, 24063}, +{-21927, 24352}, {-21606, 24636}, +{-21282, 24917}, {-20954, 25194}, +{-20622, 25465}, {-20288, 25733}, +{-19949, 25997}, {-19607, 26255}, +{-19261, 26509}, {-18914, 26760}, +{-18561, 27004}, {-18205, 27246}, +{-17846, 27481}, {-17485, 27713}, +{-17122, 27940}, {-16755, 28162}, +{-16385, 28378}, {-16012, 28590}, +{-15636, 28797}, {-15258, 28999}, +{-14878, 29197}, {-14494, 29389}, +{-14108, 29576}, {-13720, 29757}, +{-13329, 29934}, {-12937, 30107}, +{-12540, 30274}, {-12142, 30435}, +{-11744, 30592}, {-11342, 30743}, +{-10939, 30889}, {-10534, 31030}, +{-10127, 31164}, {-9718, 31294}, +{-9307, 31418}, {-8895, 31537}, +{-8482, 31652}, {-8067, 31759}, +{-7650, 31862}, {-7233, 31960}, +{-6815, 32051}, {-6393, 32138}, +{-5973, 32219}, {-5549, 32294}, +{-5127, 32364}, {-4703, 32429}, +{-4278, 32487}, {-3852, 32541}, +{-3426, 32588}, {-2999, 32630}, +{-2572, 32667}, {-2144, 32698}, +{-1716, 32724}, {-1287, 32742}, +{-860, 32757}, {-430, 32766}, +{0, 32767}, {429, 32766}, +{858, 32757}, {1287, 32743}, +{1715, 32724}, {2143, 32698}, +{2570, 32667}, {2998, 32631}, +{3425, 32588}, {3851, 32541}, +{4277, 32488}, {4701, 32429}, +{5125, 32364}, {5548, 32295}, +{5971, 32219}, {6393, 32138}, +{6813, 32051}, {7231, 31960}, +{7650, 31863}, {8067, 31760}, +{8481, 31652}, {8895, 31539}, +{9306, 31419}, {9716, 31294}, +{10126, 31165}, {10532, 31030}, +{10937, 30889}, {11340, 30743}, +{11741, 30592}, {12141, 30436}, +{12540, 30274}, {12935, 30107}, +{13328, 29936}, {13718, 29758}, +{14107, 29577}, {14493, 29390}, +{14875, 29197}, {15257, 29000}, +{15635, 28797}, {16010, 28590}, +{16384, 28379}, {16753, 28162}, +{17119, 27940}, {17484, 27714}, +{17845, 27482}, {18205, 27246}, +{18560, 27006}, {18911, 26760}, +{19260, 26510}, {19606, 26257}, +{19947, 25997}, {20286, 25734}, +{20621, 25466}, {20952, 25194}, +{21281, 24918}, {21605, 24637}, +{21926, 24353}, {22242, 24063}, +{22555, 23770}, {22865, 23473}, +{23171, 23171}, {23472, 22866}, +{23769, 22557}, {24063, 22244}, +{24352, 21927}, {24636, 21606}, +{24917, 21282}, {25194, 20954}, +{25465, 20622}, {25733, 20288}, +{25997, 19949}, {26255, 19607}, +{26509, 19261}, {26760, 18914}, +{27004, 18561}, {27246, 18205}, +{27481, 17846}, {27713, 17485}, +{27940, 17122}, {28162, 16755}, +{28378, 16385}, {28590, 16012}, +{28797, 15636}, {28999, 15258}, +{29197, 14878}, {29389, 14494}, +{29576, 14108}, {29757, 13720}, +{29934, 13329}, {30107, 12937}, +{30274, 12540}, {30435, 12142}, +{30592, 11744}, {30743, 11342}, +{30889, 10939}, {31030, 10534}, +{31164, 10127}, {31294, 9718}, +{31418, 9307}, {31537, 8895}, +{31652, 8482}, {31759, 8067}, +{31862, 7650}, {31960, 7233}, +{32051, 6815}, {32138, 6393}, +{32219, 5973}, {32294, 5549}, +{32364, 5127}, {32429, 4703}, +{32487, 4278}, {32541, 3852}, +{32588, 3426}, {32630, 2999}, +{32667, 2572}, {32698, 2144}, +{32724, 1716}, {32742, 1287}, +{32757, 860}, {32766, 430}, }; #ifndef FFT_BITREV480 #define FFT_BITREV480 static const opus_int16 fft_bitrev480[480] = { - 0, 96, 192, 288, 384, 32, 128, 224, 320, 416, 64, 160, 256, 352, 448, - 8, 104, 200, 296, 392, 40, 136, 232, 328, 424, 72, 168, 264, 360, 456, - 16, 112, 208, 304, 400, 48, 144, 240, 336, 432, 80, 176, 272, 368, 464, - 24, 120, 216, 312, 408, 56, 152, 248, 344, 440, 88, 184, 280, 376, 472, - 4, 100, 196, 292, 388, 36, 132, 228, 324, 420, 68, 164, 260, 356, 452, - 12, 108, 204, 300, 396, 44, 140, 236, 332, 428, 76, 172, 268, 364, 460, - 20, 116, 212, 308, 404, 52, 148, 244, 340, 436, 84, 180, 276, 372, 468, - 28, 124, 220, 316, 412, 60, 156, 252, 348, 444, 92, 188, 284, 380, 476, - 1, 97, 193, 289, 385, 33, 129, 225, 321, 417, 65, 161, 257, 353, 449, - 9, 105, 201, 297, 393, 41, 137, 233, 329, 425, 73, 169, 265, 361, 457, - 17, 113, 209, 305, 401, 49, 145, 241, 337, 433, 81, 177, 273, 369, 465, - 25, 121, 217, 313, 409, 57, 153, 249, 345, 441, 89, 185, 281, 377, 473, - 5, 101, 197, 293, 389, 37, 133, 229, 325, 421, 69, 165, 261, 357, 453, - 13, 109, 205, 301, 397, 45, 141, 237, 333, 429, 77, 173, 269, 365, 461, - 21, 117, 213, 309, 405, 53, 149, 245, 341, 437, 85, 181, 277, 373, 469, - 29, 125, 221, 317, 413, 61, 157, 253, 349, 445, 93, 189, 285, 381, 477, - 2, 98, 194, 290, 386, 34, 130, 226, 322, 418, 66, 162, 258, 354, 450, - 10, 106, 202, 298, 394, 42, 138, 234, 330, 426, 74, 170, 266, 362, 458, - 18, 114, 210, 306, 402, 50, 146, 242, 338, 434, 82, 178, 274, 370, 466, - 26, 122, 218, 314, 410, 58, 154, 250, 346, 442, 90, 186, 282, 378, 474, - 6, 102, 198, 294, 390, 38, 134, 230, 326, 422, 70, 166, 262, 358, 454, - 14, 110, 206, 302, 398, 46, 142, 238, 334, 430, 78, 174, 270, 366, 462, - 22, 118, 214, 310, 406, 54, 150, 246, 342, 438, 86, 182, 278, 374, 470, - 30, 126, 222, 318, 414, 62, 158, 254, 350, 446, 94, 190, 286, 382, 478, - 3, 99, 195, 291, 387, 35, 131, 227, 323, 419, 67, 163, 259, 355, 451, - 11, 107, 203, 299, 395, 43, 139, 235, 331, 427, 75, 171, 267, 363, 459, - 19, 115, 211, 307, 403, 51, 147, 243, 339, 435, 83, 179, 275, 371, 467, - 27, 123, 219, 315, 411, 59, 155, 251, 347, 443, 91, 187, 283, 379, 475, - 7, 103, 199, 295, 391, 39, 135, 231, 327, 423, 71, 167, 263, 359, 455, - 15, 111, 207, 303, 399, 47, 143, 239, 335, 431, 79, 175, 271, 367, 463, - 23, 119, 215, 311, 407, 55, 151, 247, 343, 439, 87, 183, 279, 375, 471, - 31, 127, 223, 319, 415, 63, 159, 255, 351, 447, 95, 191, 287, 383, 479, +0, 96, 192, 288, 384, 32, 128, 224, 320, 416, 64, 160, 256, 352, 448, +8, 104, 200, 296, 392, 40, 136, 232, 328, 424, 72, 168, 264, 360, 456, +16, 112, 208, 304, 400, 48, 144, 240, 336, 432, 80, 176, 272, 368, 464, +24, 120, 216, 312, 408, 56, 152, 248, 344, 440, 88, 184, 280, 376, 472, +4, 100, 196, 292, 388, 36, 132, 228, 324, 420, 68, 164, 260, 356, 452, +12, 108, 204, 300, 396, 44, 140, 236, 332, 428, 76, 172, 268, 364, 460, +20, 116, 212, 308, 404, 52, 148, 244, 340, 436, 84, 180, 276, 372, 468, +28, 124, 220, 316, 412, 60, 156, 252, 348, 444, 92, 188, 284, 380, 476, +1, 97, 193, 289, 385, 33, 129, 225, 321, 417, 65, 161, 257, 353, 449, +9, 105, 201, 297, 393, 41, 137, 233, 329, 425, 73, 169, 265, 361, 457, +17, 113, 209, 305, 401, 49, 145, 241, 337, 433, 81, 177, 273, 369, 465, +25, 121, 217, 313, 409, 57, 153, 249, 345, 441, 89, 185, 281, 377, 473, +5, 101, 197, 293, 389, 37, 133, 229, 325, 421, 69, 165, 261, 357, 453, +13, 109, 205, 301, 397, 45, 141, 237, 333, 429, 77, 173, 269, 365, 461, +21, 117, 213, 309, 405, 53, 149, 245, 341, 437, 85, 181, 277, 373, 469, +29, 125, 221, 317, 413, 61, 157, 253, 349, 445, 93, 189, 285, 381, 477, +2, 98, 194, 290, 386, 34, 130, 226, 322, 418, 66, 162, 258, 354, 450, +10, 106, 202, 298, 394, 42, 138, 234, 330, 426, 74, 170, 266, 362, 458, +18, 114, 210, 306, 402, 50, 146, 242, 338, 434, 82, 178, 274, 370, 466, +26, 122, 218, 314, 410, 58, 154, 250, 346, 442, 90, 186, 282, 378, 474, +6, 102, 198, 294, 390, 38, 134, 230, 326, 422, 70, 166, 262, 358, 454, +14, 110, 206, 302, 398, 46, 142, 238, 334, 430, 78, 174, 270, 366, 462, +22, 118, 214, 310, 406, 54, 150, 246, 342, 438, 86, 182, 278, 374, 470, +30, 126, 222, 318, 414, 62, 158, 254, 350, 446, 94, 190, 286, 382, 478, +3, 99, 195, 291, 387, 35, 131, 227, 323, 419, 67, 163, 259, 355, 451, +11, 107, 203, 299, 395, 43, 139, 235, 331, 427, 75, 171, 267, 363, 459, +19, 115, 211, 307, 403, 51, 147, 243, 339, 435, 83, 179, 275, 371, 467, +27, 123, 219, 315, 411, 59, 155, 251, 347, 443, 91, 187, 283, 379, 475, +7, 103, 199, 295, 391, 39, 135, 231, 327, 423, 71, 167, 263, 359, 455, +15, 111, 207, 303, 399, 47, 143, 239, 335, 431, 79, 175, 271, 367, 463, +23, 119, 215, 311, 407, 55, 151, 247, 343, 439, 87, 183, 279, 375, 471, +31, 127, 223, 319, 415, 63, 159, 255, 351, 447, 95, 191, 287, 383, 479, }; #endif #ifndef FFT_BITREV240 #define FFT_BITREV240 static const opus_int16 fft_bitrev240[240] = { - 0, 48, 96, 144, 192, 16, 64, 112, 160, 208, 32, 80, 128, 176, 224, - 4, 52, 100, 148, 196, 20, 68, 116, 164, 212, 36, 84, 132, 180, 228, - 8, 56, 104, 152, 200, 24, 72, 120, 168, 216, 40, 88, 136, 184, 232, - 12, 60, 108, 156, 204, 28, 76, 124, 172, 220, 44, 92, 140, 188, 236, - 1, 49, 97, 145, 193, 17, 65, 113, 161, 209, 33, 81, 129, 177, 225, - 5, 53, 101, 149, 197, 21, 69, 117, 165, 213, 37, 85, 133, 181, 229, - 9, 57, 105, 153, 201, 25, 73, 121, 169, 217, 41, 89, 137, 185, 233, - 13, 61, 109, 157, 205, 29, 77, 125, 173, 221, 45, 93, 141, 189, 237, - 2, 50, 98, 146, 194, 18, 66, 114, 162, 210, 34, 82, 130, 178, 226, - 6, 54, 102, 150, 198, 22, 70, 118, 166, 214, 38, 86, 134, 182, 230, - 10, 58, 106, 154, 202, 26, 74, 122, 170, 218, 42, 90, 138, 186, 234, - 14, 62, 110, 158, 206, 30, 78, 126, 174, 222, 46, 94, 142, 190, 238, - 3, 51, 99, 147, 195, 19, 67, 115, 163, 211, 35, 83, 131, 179, 227, - 7, 55, 103, 151, 199, 23, 71, 119, 167, 215, 39, 87, 135, 183, 231, - 11, 59, 107, 155, 203, 27, 75, 123, 171, 219, 43, 91, 139, 187, 235, - 15, 63, 111, 159, 207, 31, 79, 127, 175, 223, 47, 95, 143, 191, 239, +0, 48, 96, 144, 192, 16, 64, 112, 160, 208, 32, 80, 128, 176, 224, +4, 52, 100, 148, 196, 20, 68, 116, 164, 212, 36, 84, 132, 180, 228, +8, 56, 104, 152, 200, 24, 72, 120, 168, 216, 40, 88, 136, 184, 232, +12, 60, 108, 156, 204, 28, 76, 124, 172, 220, 44, 92, 140, 188, 236, +1, 49, 97, 145, 193, 17, 65, 113, 161, 209, 33, 81, 129, 177, 225, +5, 53, 101, 149, 197, 21, 69, 117, 165, 213, 37, 85, 133, 181, 229, +9, 57, 105, 153, 201, 25, 73, 121, 169, 217, 41, 89, 137, 185, 233, +13, 61, 109, 157, 205, 29, 77, 125, 173, 221, 45, 93, 141, 189, 237, +2, 50, 98, 146, 194, 18, 66, 114, 162, 210, 34, 82, 130, 178, 226, +6, 54, 102, 150, 198, 22, 70, 118, 166, 214, 38, 86, 134, 182, 230, +10, 58, 106, 154, 202, 26, 74, 122, 170, 218, 42, 90, 138, 186, 234, +14, 62, 110, 158, 206, 30, 78, 126, 174, 222, 46, 94, 142, 190, 238, +3, 51, 99, 147, 195, 19, 67, 115, 163, 211, 35, 83, 131, 179, 227, +7, 55, 103, 151, 199, 23, 71, 119, 167, 215, 39, 87, 135, 183, 231, +11, 59, 107, 155, 203, 27, 75, 123, 171, 219, 43, 91, 139, 187, 235, +15, 63, 111, 159, 207, 31, 79, 127, 175, 223, 47, 95, 143, 191, 239, }; #endif #ifndef FFT_BITREV120 #define FFT_BITREV120 static const opus_int16 fft_bitrev120[120] = { - 0, 24, 48, 72, 96, 8, 32, 56, 80, 104, 16, 40, 64, 88, 112, - 4, 28, 52, 76, 100, 12, 36, 60, 84, 108, 20, 44, 68, 92, 116, - 1, 25, 49, 73, 97, 9, 33, 57, 81, 105, 17, 41, 65, 89, 113, - 5, 29, 53, 77, 101, 13, 37, 61, 85, 109, 21, 45, 69, 93, 117, - 2, 26, 50, 74, 98, 10, 34, 58, 82, 106, 18, 42, 66, 90, 114, - 6, 30, 54, 78, 102, 14, 38, 62, 86, 110, 22, 46, 70, 94, 118, - 3, 27, 51, 75, 99, 11, 35, 59, 83, 107, 19, 43, 67, 91, 115, - 7, 31, 55, 79, 103, 15, 39, 63, 87, 111, 23, 47, 71, 95, 119, +0, 24, 48, 72, 96, 8, 32, 56, 80, 104, 16, 40, 64, 88, 112, +4, 28, 52, 76, 100, 12, 36, 60, 84, 108, 20, 44, 68, 92, 116, +1, 25, 49, 73, 97, 9, 33, 57, 81, 105, 17, 41, 65, 89, 113, +5, 29, 53, 77, 101, 13, 37, 61, 85, 109, 21, 45, 69, 93, 117, +2, 26, 50, 74, 98, 10, 34, 58, 82, 106, 18, 42, 66, 90, 114, +6, 30, 54, 78, 102, 14, 38, 62, 86, 110, 22, 46, 70, 94, 118, +3, 27, 51, 75, 99, 11, 35, 59, 83, 107, 19, 43, 67, 91, 115, +7, 31, 55, 79, 103, 15, 39, 63, 87, 111, 23, 47, 71, 95, 119, }; #endif #ifndef FFT_BITREV60 #define FFT_BITREV60 static const opus_int16 fft_bitrev60[60] = { - 0, 12, 24, 36, 48, 4, 16, 28, 40, 52, 8, 20, 32, 44, 56, - 1, 13, 25, 37, 49, 5, 17, 29, 41, 53, 9, 21, 33, 45, 57, - 2, 14, 26, 38, 50, 6, 18, 30, 42, 54, 10, 22, 34, 46, 58, - 3, 15, 27, 39, 51, 7, 19, 31, 43, 55, 11, 23, 35, 47, 59, +0, 12, 24, 36, 48, 4, 16, 28, 40, 52, 8, 20, 32, 44, 56, +1, 13, 25, 37, 49, 5, 17, 29, 41, 53, 9, 21, 33, 45, 57, +2, 14, 26, 38, 50, 6, 18, 30, 42, 54, 10, 22, 34, 46, 58, +3, 15, 27, 39, 51, 7, 19, 31, 43, 55, 11, 23, 35, 47, 59, }; #endif #ifndef FFT_STATE48000_960_0 #define FFT_STATE48000_960_0 static const kiss_fft_state fft_state48000_960_0 = { - 480, /* nfft */ - 17476, /* scale */ - 8, /* scale_shift */ - -1, /* shift */ - {5, 96, 3, 32, 4, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev480, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +480, /* nfft */ +17476, /* scale */ +8, /* scale_shift */ +-1, /* shift */ +{5, 96, 3, 32, 4, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev480, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_480, +(arch_fft_state *)&cfg_arch_480, #else - NULL, +NULL, #endif }; #endif @@ -451,17 +448,17 @@ static const kiss_fft_state fft_state48000_960_0 = { #ifndef FFT_STATE48000_960_1 #define FFT_STATE48000_960_1 static const kiss_fft_state fft_state48000_960_1 = { - 240, /* nfft */ - 17476, /* scale */ - 7, /* scale_shift */ - 1, /* shift */ - {5, 48, 3, 16, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev240, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +240, /* nfft */ +17476, /* scale */ +7, /* scale_shift */ +1, /* shift */ +{5, 48, 3, 16, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev240, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_240, +(arch_fft_state *)&cfg_arch_240, #else - NULL, +NULL, #endif }; #endif @@ -469,17 +466,17 @@ static const kiss_fft_state fft_state48000_960_1 = { #ifndef FFT_STATE48000_960_2 #define FFT_STATE48000_960_2 static const kiss_fft_state fft_state48000_960_2 = { - 120, /* nfft */ - 17476, /* scale */ - 6, /* scale_shift */ - 2, /* shift */ - {5, 24, 3, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev120, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +120, /* nfft */ +17476, /* scale */ +6, /* scale_shift */ +2, /* shift */ +{5, 24, 3, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev120, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_120, +(arch_fft_state *)&cfg_arch_120, #else - NULL, +NULL, #endif }; #endif @@ -487,17 +484,17 @@ static const kiss_fft_state fft_state48000_960_2 = { #ifndef FFT_STATE48000_960_3 #define FFT_STATE48000_960_3 static const kiss_fft_state fft_state48000_960_3 = { - 60, /* nfft */ - 17476, /* scale */ - 5, /* scale_shift */ - 3, /* shift */ - {5, 12, 3, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev60, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +60, /* nfft */ +17476, /* scale */ +5, /* scale_shift */ +3, /* shift */ +{5, 12, 3, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev60, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_60, +(arch_fft_state *)&cfg_arch_60, #else - NULL, +NULL, #endif }; #endif @@ -507,389 +504,389 @@ static const kiss_fft_state fft_state48000_960_3 = { #ifndef MDCT_TWIDDLES960 #define MDCT_TWIDDLES960 static const opus_val16 mdct_twiddles960[1800] = { - 32767, 32767, 32767, 32766, 32765, - 32763, 32761, 32759, 32756, 32753, - 32750, 32746, 32742, 32738, 32733, - 32728, 32722, 32717, 32710, 32704, - 32697, 32690, 32682, 32674, 32666, - 32657, 32648, 32639, 32629, 32619, - 32609, 32598, 32587, 32576, 32564, - 32552, 32539, 32526, 32513, 32500, - 32486, 32472, 32457, 32442, 32427, - 32411, 32395, 32379, 32362, 32345, - 32328, 32310, 32292, 32274, 32255, - 32236, 32217, 32197, 32177, 32157, - 32136, 32115, 32093, 32071, 32049, - 32027, 32004, 31981, 31957, 31933, - 31909, 31884, 31859, 31834, 31809, - 31783, 31756, 31730, 31703, 31676, - 31648, 31620, 31592, 31563, 31534, - 31505, 31475, 31445, 31415, 31384, - 31353, 31322, 31290, 31258, 31226, - 31193, 31160, 31127, 31093, 31059, - 31025, 30990, 30955, 30920, 30884, - 30848, 30812, 30775, 30738, 30701, - 30663, 30625, 30587, 30548, 30509, - 30470, 30430, 30390, 30350, 30309, - 30269, 30227, 30186, 30144, 30102, - 30059, 30016, 29973, 29930, 29886, - 29842, 29797, 29752, 29707, 29662, - 29616, 29570, 29524, 29477, 29430, - 29383, 29335, 29287, 29239, 29190, - 29142, 29092, 29043, 28993, 28943, - 28892, 28842, 28791, 28739, 28688, - 28636, 28583, 28531, 28478, 28425, - 28371, 28317, 28263, 28209, 28154, - 28099, 28044, 27988, 27932, 27876, - 27820, 27763, 27706, 27648, 27591, - 27533, 27474, 27416, 27357, 27298, - 27238, 27178, 27118, 27058, 26997, - 26936, 26875, 26814, 26752, 26690, - 26628, 26565, 26502, 26439, 26375, - 26312, 26247, 26183, 26119, 26054, - 25988, 25923, 25857, 25791, 25725, - 25658, 25592, 25524, 25457, 25389, - 25322, 25253, 25185, 25116, 25047, - 24978, 24908, 24838, 24768, 24698, - 24627, 24557, 24485, 24414, 24342, - 24270, 24198, 24126, 24053, 23980, - 23907, 23834, 23760, 23686, 23612, - 23537, 23462, 23387, 23312, 23237, - 23161, 23085, 23009, 22932, 22856, - 22779, 22701, 22624, 22546, 22468, - 22390, 22312, 22233, 22154, 22075, - 21996, 21916, 21836, 21756, 21676, - 21595, 21515, 21434, 21352, 21271, - 21189, 21107, 21025, 20943, 20860, - 20777, 20694, 20611, 20528, 20444, - 20360, 20276, 20192, 20107, 20022, - 19937, 19852, 19767, 19681, 19595, - 19509, 19423, 19336, 19250, 19163, - 19076, 18988, 18901, 18813, 18725, - 18637, 18549, 18460, 18372, 18283, - 18194, 18104, 18015, 17925, 17835, - 17745, 17655, 17565, 17474, 17383, - 17292, 17201, 17110, 17018, 16927, - 16835, 16743, 16650, 16558, 16465, - 16372, 16279, 16186, 16093, 15999, - 15906, 15812, 15718, 15624, 15529, - 15435, 15340, 15245, 15150, 15055, - 14960, 14864, 14769, 14673, 14577, - 14481, 14385, 14288, 14192, 14095, - 13998, 13901, 13804, 13706, 13609, - 13511, 13414, 13316, 13218, 13119, - 13021, 12923, 12824, 12725, 12626, - 12527, 12428, 12329, 12230, 12130, - 12030, 11930, 11831, 11730, 11630, - 11530, 11430, 11329, 11228, 11128, - 11027, 10926, 10824, 10723, 10622, - 10520, 10419, 10317, 10215, 10113, - 10011, 9909, 9807, 9704, 9602, - 9499, 9397, 9294, 9191, 9088, - 8985, 8882, 8778, 8675, 8572, - 8468, 8364, 8261, 8157, 8053, - 7949, 7845, 7741, 7637, 7532, - 7428, 7323, 7219, 7114, 7009, - 6905, 6800, 6695, 6590, 6485, - 6380, 6274, 6169, 6064, 5958, - 5853, 5747, 5642, 5536, 5430, - 5325, 5219, 5113, 5007, 4901, - 4795, 4689, 4583, 4476, 4370, - 4264, 4157, 4051, 3945, 3838, - 3732, 3625, 3518, 3412, 3305, - 3198, 3092, 2985, 2878, 2771, - 2664, 2558, 2451, 2344, 2237, - 2130, 2023, 1916, 1809, 1702, - 1594, 1487, 1380, 1273, 1166, - 1059, 952, 844, 737, 630, - 523, 416, 308, 201, 94, - -13, -121, -228, -335, -442, - -550, -657, -764, -871, -978, - -1086, -1193, -1300, -1407, -1514, - -1621, -1728, -1835, -1942, -2049, - -2157, -2263, -2370, -2477, -2584, - -2691, -2798, -2905, -3012, -3118, - -3225, -3332, -3439, -3545, -3652, - -3758, -3865, -3971, -4078, -4184, - -4290, -4397, -4503, -4609, -4715, - -4821, -4927, -5033, -5139, -5245, - -5351, -5457, -5562, -5668, -5774, - -5879, -5985, -6090, -6195, -6301, - -6406, -6511, -6616, -6721, -6826, - -6931, -7036, -7140, -7245, -7349, - -7454, -7558, -7663, -7767, -7871, - -7975, -8079, -8183, -8287, -8390, - -8494, -8597, -8701, -8804, -8907, - -9011, -9114, -9217, -9319, -9422, - -9525, -9627, -9730, -9832, -9934, - -10037, -10139, -10241, -10342, -10444, - -10546, -10647, -10748, -10850, -10951, - -11052, -11153, -11253, -11354, -11455, - -11555, -11655, -11756, -11856, -11955, - -12055, -12155, -12254, -12354, -12453, - -12552, -12651, -12750, -12849, -12947, - -13046, -13144, -13242, -13340, -13438, - -13536, -13633, -13731, -13828, -13925, - -14022, -14119, -14216, -14312, -14409, - -14505, -14601, -14697, -14793, -14888, - -14984, -15079, -15174, -15269, -15364, - -15459, -15553, -15647, -15741, -15835, - -15929, -16023, -16116, -16210, -16303, - -16396, -16488, -16581, -16673, -16766, - -16858, -16949, -17041, -17133, -17224, - -17315, -17406, -17497, -17587, -17678, - -17768, -17858, -17948, -18037, -18127, - -18216, -18305, -18394, -18483, -18571, - -18659, -18747, -18835, -18923, -19010, - -19098, -19185, -19271, -19358, -19444, - -19531, -19617, -19702, -19788, -19873, - -19959, -20043, -20128, -20213, -20297, - -20381, -20465, -20549, -20632, -20715, - -20798, -20881, -20963, -21046, -21128, - -21210, -21291, -21373, -21454, -21535, - -21616, -21696, -21776, -21856, -21936, - -22016, -22095, -22174, -22253, -22331, - -22410, -22488, -22566, -22643, -22721, - -22798, -22875, -22951, -23028, -23104, - -23180, -23256, -23331, -23406, -23481, - -23556, -23630, -23704, -23778, -23852, - -23925, -23998, -24071, -24144, -24216, - -24288, -24360, -24432, -24503, -24574, - -24645, -24716, -24786, -24856, -24926, - -24995, -25064, -25133, -25202, -25270, - -25339, -25406, -25474, -25541, -25608, - -25675, -25742, -25808, -25874, -25939, - -26005, -26070, -26135, -26199, -26264, - -26327, -26391, -26455, -26518, -26581, - -26643, -26705, -26767, -26829, -26891, - -26952, -27013, -27073, -27133, -27193, - -27253, -27312, -27372, -27430, -27489, - -27547, -27605, -27663, -27720, -27777, - -27834, -27890, -27946, -28002, -28058, - -28113, -28168, -28223, -28277, -28331, - -28385, -28438, -28491, -28544, -28596, - -28649, -28701, -28752, -28803, -28854, - -28905, -28955, -29006, -29055, -29105, - -29154, -29203, -29251, -29299, -29347, - -29395, -29442, -29489, -29535, -29582, - -29628, -29673, -29719, -29764, -29808, - -29853, -29897, -29941, -29984, -30027, - -30070, -30112, -30154, -30196, -30238, - -30279, -30320, -30360, -30400, -30440, - -30480, -30519, -30558, -30596, -30635, - -30672, -30710, -30747, -30784, -30821, - -30857, -30893, -30929, -30964, -30999, - -31033, -31068, -31102, -31135, -31168, - -31201, -31234, -31266, -31298, -31330, - -31361, -31392, -31422, -31453, -31483, - -31512, -31541, -31570, -31599, -31627, - -31655, -31682, -31710, -31737, -31763, - -31789, -31815, -31841, -31866, -31891, - -31915, -31939, -31963, -31986, -32010, - -32032, -32055, -32077, -32099, -32120, - -32141, -32162, -32182, -32202, -32222, - -32241, -32260, -32279, -32297, -32315, - -32333, -32350, -32367, -32383, -32399, - -32415, -32431, -32446, -32461, -32475, - -32489, -32503, -32517, -32530, -32542, - -32555, -32567, -32579, -32590, -32601, - -32612, -32622, -32632, -32641, -32651, - -32659, -32668, -32676, -32684, -32692, - -32699, -32706, -32712, -32718, -32724, - -32729, -32734, -32739, -32743, -32747, - -32751, -32754, -32757, -32760, -32762, - -32764, -32765, -32767, -32767, -32767, - 32767, 32767, 32765, 32761, 32756, - 32750, 32742, 32732, 32722, 32710, - 32696, 32681, 32665, 32647, 32628, - 32608, 32586, 32562, 32538, 32512, - 32484, 32455, 32425, 32393, 32360, - 32326, 32290, 32253, 32214, 32174, - 32133, 32090, 32046, 32001, 31954, - 31906, 31856, 31805, 31753, 31700, - 31645, 31588, 31530, 31471, 31411, - 31349, 31286, 31222, 31156, 31089, - 31020, 30951, 30880, 30807, 30733, - 30658, 30582, 30504, 30425, 30345, - 30263, 30181, 30096, 30011, 29924, - 29836, 29747, 29656, 29564, 29471, - 29377, 29281, 29184, 29086, 28987, - 28886, 28784, 28681, 28577, 28471, - 28365, 28257, 28147, 28037, 27925, - 27812, 27698, 27583, 27467, 27349, - 27231, 27111, 26990, 26868, 26744, - 26620, 26494, 26367, 26239, 26110, - 25980, 25849, 25717, 25583, 25449, - 25313, 25176, 25038, 24900, 24760, - 24619, 24477, 24333, 24189, 24044, - 23898, 23751, 23602, 23453, 23303, - 23152, 22999, 22846, 22692, 22537, - 22380, 22223, 22065, 21906, 21746, - 21585, 21423, 21261, 21097, 20933, - 20767, 20601, 20434, 20265, 20096, - 19927, 19756, 19584, 19412, 19239, - 19065, 18890, 18714, 18538, 18361, - 18183, 18004, 17824, 17644, 17463, - 17281, 17098, 16915, 16731, 16546, - 16361, 16175, 15988, 15800, 15612, - 15423, 15234, 15043, 14852, 14661, - 14469, 14276, 14083, 13889, 13694, - 13499, 13303, 13107, 12910, 12713, - 12515, 12317, 12118, 11918, 11718, - 11517, 11316, 11115, 10913, 10710, - 10508, 10304, 10100, 9896, 9691, - 9486, 9281, 9075, 8869, 8662, - 8455, 8248, 8040, 7832, 7623, - 7415, 7206, 6996, 6787, 6577, - 6366, 6156, 5945, 5734, 5523, - 5311, 5100, 4888, 4675, 4463, - 4251, 4038, 3825, 3612, 3399, - 3185, 2972, 2758, 2544, 2330, - 2116, 1902, 1688, 1474, 1260, - 1045, 831, 617, 402, 188, - -27, -241, -456, -670, -885, - -1099, -1313, -1528, -1742, -1956, - -2170, -2384, -2598, -2811, -3025, - -3239, -3452, -3665, -3878, -4091, - -4304, -4516, -4728, -4941, -5153, - -5364, -5576, -5787, -5998, -6209, - -6419, -6629, -6839, -7049, -7258, - -7467, -7676, -7884, -8092, -8300, - -8507, -8714, -8920, -9127, -9332, - -9538, -9743, -9947, -10151, -10355, - -10558, -10761, -10963, -11165, -11367, - -11568, -11768, -11968, -12167, -12366, - -12565, -12762, -12960, -13156, -13352, - -13548, -13743, -13937, -14131, -14324, - -14517, -14709, -14900, -15091, -15281, - -15470, -15659, -15847, -16035, -16221, - -16407, -16593, -16777, -16961, -17144, - -17326, -17508, -17689, -17869, -18049, - -18227, -18405, -18582, -18758, -18934, - -19108, -19282, -19455, -19627, -19799, - -19969, -20139, -20308, -20475, -20642, - -20809, -20974, -21138, -21301, -21464, - -21626, -21786, -21946, -22105, -22263, - -22420, -22575, -22730, -22884, -23037, - -23189, -23340, -23490, -23640, -23788, - -23935, -24080, -24225, -24369, -24512, - -24654, -24795, -24934, -25073, -25211, - -25347, -25482, -25617, -25750, -25882, - -26013, -26143, -26272, -26399, -26526, - -26651, -26775, -26898, -27020, -27141, - -27260, -27379, -27496, -27612, -27727, - -27841, -27953, -28065, -28175, -28284, - -28391, -28498, -28603, -28707, -28810, - -28911, -29012, -29111, -29209, -29305, - -29401, -29495, -29587, -29679, -29769, - -29858, -29946, -30032, -30118, -30201, - -30284, -30365, -30445, -30524, -30601, - -30677, -30752, -30825, -30897, -30968, - -31038, -31106, -31172, -31238, -31302, - -31365, -31426, -31486, -31545, -31602, - -31658, -31713, -31766, -31818, -31869, - -31918, -31966, -32012, -32058, -32101, - -32144, -32185, -32224, -32262, -32299, - -32335, -32369, -32401, -32433, -32463, - -32491, -32518, -32544, -32568, -32591, - -32613, -32633, -32652, -32669, -32685, - -32700, -32713, -32724, -32735, -32744, - -32751, -32757, -32762, -32766, -32767, - 32767, 32764, 32755, 32741, 32720, - 32694, 32663, 32626, 32583, 32535, - 32481, 32421, 32356, 32286, 32209, - 32128, 32041, 31948, 31850, 31747, - 31638, 31523, 31403, 31278, 31148, - 31012, 30871, 30724, 30572, 30415, - 30253, 30086, 29913, 29736, 29553, - 29365, 29172, 28974, 28771, 28564, - 28351, 28134, 27911, 27684, 27452, - 27216, 26975, 26729, 26478, 26223, - 25964, 25700, 25432, 25159, 24882, - 24601, 24315, 24026, 23732, 23434, - 23133, 22827, 22517, 22204, 21886, - 21565, 21240, 20912, 20580, 20244, - 19905, 19563, 19217, 18868, 18516, - 18160, 17802, 17440, 17075, 16708, - 16338, 15964, 15588, 15210, 14829, - 14445, 14059, 13670, 13279, 12886, - 12490, 12093, 11693, 11291, 10888, - 10482, 10075, 9666, 9255, 8843, - 8429, 8014, 7597, 7180, 6760, - 6340, 5919, 5496, 5073, 4649, - 4224, 3798, 3372, 2945, 2517, - 2090, 1661, 1233, 804, 375, - -54, -483, -911, -1340, -1768, - -2197, -2624, -3052, -3479, -3905, - -4330, -4755, -5179, -5602, -6024, - -6445, -6865, -7284, -7702, -8118, - -8533, -8946, -9358, -9768, -10177, - -10584, -10989, -11392, -11793, -12192, - -12589, -12984, -13377, -13767, -14155, - -14541, -14924, -15305, -15683, -16058, - -16430, -16800, -17167, -17531, -17892, - -18249, -18604, -18956, -19304, -19649, - -19990, -20329, -20663, -20994, -21322, - -21646, -21966, -22282, -22595, -22904, - -23208, -23509, -23806, -24099, -24387, - -24672, -24952, -25228, -25499, -25766, - -26029, -26288, -26541, -26791, -27035, - -27275, -27511, -27741, -27967, -28188, - -28405, -28616, -28823, -29024, -29221, - -29412, -29599, -29780, -29957, -30128, - -30294, -30455, -30611, -30761, -30906, - -31046, -31181, -31310, -31434, -31552, - -31665, -31773, -31875, -31972, -32063, - -32149, -32229, -32304, -32373, -32437, - -32495, -32547, -32594, -32635, -32671, - -32701, -32726, -32745, -32758, -32766, - 32767, 32754, 32717, 32658, 32577, - 32473, 32348, 32200, 32029, 31837, - 31624, 31388, 31131, 30853, 30553, - 30232, 29891, 29530, 29148, 28746, - 28324, 27883, 27423, 26944, 26447, - 25931, 25398, 24847, 24279, 23695, - 23095, 22478, 21846, 21199, 20538, - 19863, 19174, 18472, 17757, 17030, - 16291, 15541, 14781, 14010, 13230, - 12441, 11643, 10837, 10024, 9204, - 8377, 7545, 6708, 5866, 5020, - 4171, 3319, 2464, 1608, 751, - -107, -965, -1822, -2678, -3532, - -4383, -5232, -6077, -6918, -7754, - -8585, -9409, -10228, -11039, -11843, - -12639, -13426, -14204, -14972, -15730, - -16477, -17213, -17937, -18648, -19347, - -20033, -20705, -21363, -22006, -22634, - -23246, -23843, -24423, -24986, -25533, - -26062, -26573, -27066, -27540, -27995, - -28431, -28848, -29245, -29622, -29979, - -30315, -30630, -30924, -31197, -31449, - -31679, -31887, -32074, -32239, -32381, - -32501, -32600, -32675, -32729, -32759, +32767, 32767, 32767, 32766, 32765, +32763, 32761, 32759, 32756, 32753, +32750, 32746, 32742, 32738, 32733, +32728, 32722, 32717, 32710, 32704, +32697, 32690, 32682, 32674, 32666, +32657, 32648, 32639, 32629, 32619, +32609, 32598, 32587, 32576, 32564, +32552, 32539, 32526, 32513, 32500, +32486, 32472, 32457, 32442, 32427, +32411, 32395, 32379, 32362, 32345, +32328, 32310, 32292, 32274, 32255, +32236, 32217, 32197, 32177, 32157, +32136, 32115, 32093, 32071, 32049, +32027, 32004, 31981, 31957, 31933, +31909, 31884, 31859, 31834, 31809, +31783, 31756, 31730, 31703, 31676, +31648, 31620, 31592, 31563, 31534, +31505, 31475, 31445, 31415, 31384, +31353, 31322, 31290, 31258, 31226, +31193, 31160, 31127, 31093, 31059, +31025, 30990, 30955, 30920, 30884, +30848, 30812, 30775, 30738, 30701, +30663, 30625, 30587, 30548, 30509, +30470, 30430, 30390, 30350, 30309, +30269, 30227, 30186, 30144, 30102, +30059, 30016, 29973, 29930, 29886, +29842, 29797, 29752, 29707, 29662, +29616, 29570, 29524, 29477, 29430, +29383, 29335, 29287, 29239, 29190, +29142, 29092, 29043, 28993, 28943, +28892, 28842, 28791, 28739, 28688, +28636, 28583, 28531, 28478, 28425, +28371, 28317, 28263, 28209, 28154, +28099, 28044, 27988, 27932, 27876, +27820, 27763, 27706, 27648, 27591, +27533, 27474, 27416, 27357, 27298, +27238, 27178, 27118, 27058, 26997, +26936, 26875, 26814, 26752, 26690, +26628, 26565, 26502, 26439, 26375, +26312, 26247, 26183, 26119, 26054, +25988, 25923, 25857, 25791, 25725, +25658, 25592, 25524, 25457, 25389, +25322, 25253, 25185, 25116, 25047, +24978, 24908, 24838, 24768, 24698, +24627, 24557, 24485, 24414, 24342, +24270, 24198, 24126, 24053, 23980, +23907, 23834, 23760, 23686, 23612, +23537, 23462, 23387, 23312, 23237, +23161, 23085, 23009, 22932, 22856, +22779, 22701, 22624, 22546, 22468, +22390, 22312, 22233, 22154, 22075, +21996, 21916, 21836, 21756, 21676, +21595, 21515, 21434, 21352, 21271, +21189, 21107, 21025, 20943, 20860, +20777, 20694, 20611, 20528, 20444, +20360, 20276, 20192, 20107, 20022, +19937, 19852, 19767, 19681, 19595, +19509, 19423, 19336, 19250, 19163, +19076, 18988, 18901, 18813, 18725, +18637, 18549, 18460, 18372, 18283, +18194, 18104, 18015, 17925, 17835, +17745, 17655, 17565, 17474, 17383, +17292, 17201, 17110, 17018, 16927, +16835, 16743, 16650, 16558, 16465, +16372, 16279, 16186, 16093, 15999, +15906, 15812, 15718, 15624, 15529, +15435, 15340, 15245, 15150, 15055, +14960, 14864, 14769, 14673, 14577, +14481, 14385, 14288, 14192, 14095, +13998, 13901, 13804, 13706, 13609, +13511, 13414, 13316, 13218, 13119, +13021, 12923, 12824, 12725, 12626, +12527, 12428, 12329, 12230, 12130, +12030, 11930, 11831, 11730, 11630, +11530, 11430, 11329, 11228, 11128, +11027, 10926, 10824, 10723, 10622, +10520, 10419, 10317, 10215, 10113, +10011, 9909, 9807, 9704, 9602, +9499, 9397, 9294, 9191, 9088, +8985, 8882, 8778, 8675, 8572, +8468, 8364, 8261, 8157, 8053, +7949, 7845, 7741, 7637, 7532, +7428, 7323, 7219, 7114, 7009, +6905, 6800, 6695, 6590, 6485, +6380, 6274, 6169, 6064, 5958, +5853, 5747, 5642, 5536, 5430, +5325, 5219, 5113, 5007, 4901, +4795, 4689, 4583, 4476, 4370, +4264, 4157, 4051, 3945, 3838, +3732, 3625, 3518, 3412, 3305, +3198, 3092, 2985, 2878, 2771, +2664, 2558, 2451, 2344, 2237, +2130, 2023, 1916, 1809, 1702, +1594, 1487, 1380, 1273, 1166, +1059, 952, 844, 737, 630, +523, 416, 308, 201, 94, +-13, -121, -228, -335, -442, +-550, -657, -764, -871, -978, +-1086, -1193, -1300, -1407, -1514, +-1621, -1728, -1835, -1942, -2049, +-2157, -2263, -2370, -2477, -2584, +-2691, -2798, -2905, -3012, -3118, +-3225, -3332, -3439, -3545, -3652, +-3758, -3865, -3971, -4078, -4184, +-4290, -4397, -4503, -4609, -4715, +-4821, -4927, -5033, -5139, -5245, +-5351, -5457, -5562, -5668, -5774, +-5879, -5985, -6090, -6195, -6301, +-6406, -6511, -6616, -6721, -6826, +-6931, -7036, -7140, -7245, -7349, +-7454, -7558, -7663, -7767, -7871, +-7975, -8079, -8183, -8287, -8390, +-8494, -8597, -8701, -8804, -8907, +-9011, -9114, -9217, -9319, -9422, +-9525, -9627, -9730, -9832, -9934, +-10037, -10139, -10241, -10342, -10444, +-10546, -10647, -10748, -10850, -10951, +-11052, -11153, -11253, -11354, -11455, +-11555, -11655, -11756, -11856, -11955, +-12055, -12155, -12254, -12354, -12453, +-12552, -12651, -12750, -12849, -12947, +-13046, -13144, -13242, -13340, -13438, +-13536, -13633, -13731, -13828, -13925, +-14022, -14119, -14216, -14312, -14409, +-14505, -14601, -14697, -14793, -14888, +-14984, -15079, -15174, -15269, -15364, +-15459, -15553, -15647, -15741, -15835, +-15929, -16023, -16116, -16210, -16303, +-16396, -16488, -16581, -16673, -16766, +-16858, -16949, -17041, -17133, -17224, +-17315, -17406, -17497, -17587, -17678, +-17768, -17858, -17948, -18037, -18127, +-18216, -18305, -18394, -18483, -18571, +-18659, -18747, -18835, -18923, -19010, +-19098, -19185, -19271, -19358, -19444, +-19531, -19617, -19702, -19788, -19873, +-19959, -20043, -20128, -20213, -20297, +-20381, -20465, -20549, -20632, -20715, +-20798, -20881, -20963, -21046, -21128, +-21210, -21291, -21373, -21454, -21535, +-21616, -21696, -21776, -21856, -21936, +-22016, -22095, -22174, -22253, -22331, +-22410, -22488, -22566, -22643, -22721, +-22798, -22875, -22951, -23028, -23104, +-23180, -23256, -23331, -23406, -23481, +-23556, -23630, -23704, -23778, -23852, +-23925, -23998, -24071, -24144, -24216, +-24288, -24360, -24432, -24503, -24574, +-24645, -24716, -24786, -24856, -24926, +-24995, -25064, -25133, -25202, -25270, +-25339, -25406, -25474, -25541, -25608, +-25675, -25742, -25808, -25874, -25939, +-26005, -26070, -26135, -26199, -26264, +-26327, -26391, -26455, -26518, -26581, +-26643, -26705, -26767, -26829, -26891, +-26952, -27013, -27073, -27133, -27193, +-27253, -27312, -27372, -27430, -27489, +-27547, -27605, -27663, -27720, -27777, +-27834, -27890, -27946, -28002, -28058, +-28113, -28168, -28223, -28277, -28331, +-28385, -28438, -28491, -28544, -28596, +-28649, -28701, -28752, -28803, -28854, +-28905, -28955, -29006, -29055, -29105, +-29154, -29203, -29251, -29299, -29347, +-29395, -29442, -29489, -29535, -29582, +-29628, -29673, -29719, -29764, -29808, +-29853, -29897, -29941, -29984, -30027, +-30070, -30112, -30154, -30196, -30238, +-30279, -30320, -30360, -30400, -30440, +-30480, -30519, -30558, -30596, -30635, +-30672, -30710, -30747, -30784, -30821, +-30857, -30893, -30929, -30964, -30999, +-31033, -31068, -31102, -31135, -31168, +-31201, -31234, -31266, -31298, -31330, +-31361, -31392, -31422, -31453, -31483, +-31512, -31541, -31570, -31599, -31627, +-31655, -31682, -31710, -31737, -31763, +-31789, -31815, -31841, -31866, -31891, +-31915, -31939, -31963, -31986, -32010, +-32032, -32055, -32077, -32099, -32120, +-32141, -32162, -32182, -32202, -32222, +-32241, -32260, -32279, -32297, -32315, +-32333, -32350, -32367, -32383, -32399, +-32415, -32431, -32446, -32461, -32475, +-32489, -32503, -32517, -32530, -32542, +-32555, -32567, -32579, -32590, -32601, +-32612, -32622, -32632, -32641, -32651, +-32659, -32668, -32676, -32684, -32692, +-32699, -32706, -32712, -32718, -32724, +-32729, -32734, -32739, -32743, -32747, +-32751, -32754, -32757, -32760, -32762, +-32764, -32765, -32767, -32767, -32767, +32767, 32767, 32765, 32761, 32756, +32750, 32742, 32732, 32722, 32710, +32696, 32681, 32665, 32647, 32628, +32608, 32586, 32562, 32538, 32512, +32484, 32455, 32425, 32393, 32360, +32326, 32290, 32253, 32214, 32174, +32133, 32090, 32046, 32001, 31954, +31906, 31856, 31805, 31753, 31700, +31645, 31588, 31530, 31471, 31411, +31349, 31286, 31222, 31156, 31089, +31020, 30951, 30880, 30807, 30733, +30658, 30582, 30504, 30425, 30345, +30263, 30181, 30096, 30011, 29924, +29836, 29747, 29656, 29564, 29471, +29377, 29281, 29184, 29086, 28987, +28886, 28784, 28681, 28577, 28471, +28365, 28257, 28147, 28037, 27925, +27812, 27698, 27583, 27467, 27349, +27231, 27111, 26990, 26868, 26744, +26620, 26494, 26367, 26239, 26110, +25980, 25849, 25717, 25583, 25449, +25313, 25176, 25038, 24900, 24760, +24619, 24477, 24333, 24189, 24044, +23898, 23751, 23602, 23453, 23303, +23152, 22999, 22846, 22692, 22537, +22380, 22223, 22065, 21906, 21746, +21585, 21423, 21261, 21097, 20933, +20767, 20601, 20434, 20265, 20096, +19927, 19756, 19584, 19412, 19239, +19065, 18890, 18714, 18538, 18361, +18183, 18004, 17824, 17644, 17463, +17281, 17098, 16915, 16731, 16546, +16361, 16175, 15988, 15800, 15612, +15423, 15234, 15043, 14852, 14661, +14469, 14276, 14083, 13889, 13694, +13499, 13303, 13107, 12910, 12713, +12515, 12317, 12118, 11918, 11718, +11517, 11316, 11115, 10913, 10710, +10508, 10304, 10100, 9896, 9691, +9486, 9281, 9075, 8869, 8662, +8455, 8248, 8040, 7832, 7623, +7415, 7206, 6996, 6787, 6577, +6366, 6156, 5945, 5734, 5523, +5311, 5100, 4888, 4675, 4463, +4251, 4038, 3825, 3612, 3399, +3185, 2972, 2758, 2544, 2330, +2116, 1902, 1688, 1474, 1260, +1045, 831, 617, 402, 188, +-27, -241, -456, -670, -885, +-1099, -1313, -1528, -1742, -1956, +-2170, -2384, -2598, -2811, -3025, +-3239, -3452, -3665, -3878, -4091, +-4304, -4516, -4728, -4941, -5153, +-5364, -5576, -5787, -5998, -6209, +-6419, -6629, -6839, -7049, -7258, +-7467, -7676, -7884, -8092, -8300, +-8507, -8714, -8920, -9127, -9332, +-9538, -9743, -9947, -10151, -10355, +-10558, -10761, -10963, -11165, -11367, +-11568, -11768, -11968, -12167, -12366, +-12565, -12762, -12960, -13156, -13352, +-13548, -13743, -13937, -14131, -14324, +-14517, -14709, -14900, -15091, -15281, +-15470, -15659, -15847, -16035, -16221, +-16407, -16593, -16777, -16961, -17144, +-17326, -17508, -17689, -17869, -18049, +-18227, -18405, -18582, -18758, -18934, +-19108, -19282, -19455, -19627, -19799, +-19969, -20139, -20308, -20475, -20642, +-20809, -20974, -21138, -21301, -21464, +-21626, -21786, -21946, -22105, -22263, +-22420, -22575, -22730, -22884, -23037, +-23189, -23340, -23490, -23640, -23788, +-23935, -24080, -24225, -24369, -24512, +-24654, -24795, -24934, -25073, -25211, +-25347, -25482, -25617, -25750, -25882, +-26013, -26143, -26272, -26399, -26526, +-26651, -26775, -26898, -27020, -27141, +-27260, -27379, -27496, -27612, -27727, +-27841, -27953, -28065, -28175, -28284, +-28391, -28498, -28603, -28707, -28810, +-28911, -29012, -29111, -29209, -29305, +-29401, -29495, -29587, -29679, -29769, +-29858, -29946, -30032, -30118, -30201, +-30284, -30365, -30445, -30524, -30601, +-30677, -30752, -30825, -30897, -30968, +-31038, -31106, -31172, -31238, -31302, +-31365, -31426, -31486, -31545, -31602, +-31658, -31713, -31766, -31818, -31869, +-31918, -31966, -32012, -32058, -32101, +-32144, -32185, -32224, -32262, -32299, +-32335, -32369, -32401, -32433, -32463, +-32491, -32518, -32544, -32568, -32591, +-32613, -32633, -32652, -32669, -32685, +-32700, -32713, -32724, -32735, -32744, +-32751, -32757, -32762, -32766, -32767, +32767, 32764, 32755, 32741, 32720, +32694, 32663, 32626, 32583, 32535, +32481, 32421, 32356, 32286, 32209, +32128, 32041, 31948, 31850, 31747, +31638, 31523, 31403, 31278, 31148, +31012, 30871, 30724, 30572, 30415, +30253, 30086, 29913, 29736, 29553, +29365, 29172, 28974, 28771, 28564, +28351, 28134, 27911, 27684, 27452, +27216, 26975, 26729, 26478, 26223, +25964, 25700, 25432, 25159, 24882, +24601, 24315, 24026, 23732, 23434, +23133, 22827, 22517, 22204, 21886, +21565, 21240, 20912, 20580, 20244, +19905, 19563, 19217, 18868, 18516, +18160, 17802, 17440, 17075, 16708, +16338, 15964, 15588, 15210, 14829, +14445, 14059, 13670, 13279, 12886, +12490, 12093, 11693, 11291, 10888, +10482, 10075, 9666, 9255, 8843, +8429, 8014, 7597, 7180, 6760, +6340, 5919, 5496, 5073, 4649, +4224, 3798, 3372, 2945, 2517, +2090, 1661, 1233, 804, 375, +-54, -483, -911, -1340, -1768, +-2197, -2624, -3052, -3479, -3905, +-4330, -4755, -5179, -5602, -6024, +-6445, -6865, -7284, -7702, -8118, +-8533, -8946, -9358, -9768, -10177, +-10584, -10989, -11392, -11793, -12192, +-12589, -12984, -13377, -13767, -14155, +-14541, -14924, -15305, -15683, -16058, +-16430, -16800, -17167, -17531, -17892, +-18249, -18604, -18956, -19304, -19649, +-19990, -20329, -20663, -20994, -21322, +-21646, -21966, -22282, -22595, -22904, +-23208, -23509, -23806, -24099, -24387, +-24672, -24952, -25228, -25499, -25766, +-26029, -26288, -26541, -26791, -27035, +-27275, -27511, -27741, -27967, -28188, +-28405, -28616, -28823, -29024, -29221, +-29412, -29599, -29780, -29957, -30128, +-30294, -30455, -30611, -30761, -30906, +-31046, -31181, -31310, -31434, -31552, +-31665, -31773, -31875, -31972, -32063, +-32149, -32229, -32304, -32373, -32437, +-32495, -32547, -32594, -32635, -32671, +-32701, -32726, -32745, -32758, -32766, +32767, 32754, 32717, 32658, 32577, +32473, 32348, 32200, 32029, 31837, +31624, 31388, 31131, 30853, 30553, +30232, 29891, 29530, 29148, 28746, +28324, 27883, 27423, 26944, 26447, +25931, 25398, 24847, 24279, 23695, +23095, 22478, 21846, 21199, 20538, +19863, 19174, 18472, 17757, 17030, +16291, 15541, 14781, 14010, 13230, +12441, 11643, 10837, 10024, 9204, +8377, 7545, 6708, 5866, 5020, +4171, 3319, 2464, 1608, 751, +-107, -965, -1822, -2678, -3532, +-4383, -5232, -6077, -6918, -7754, +-8585, -9409, -10228, -11039, -11843, +-12639, -13426, -14204, -14972, -15730, +-16477, -17213, -17937, -18648, -19347, +-20033, -20705, -21363, -22006, -22634, +-23246, -23843, -24423, -24986, -25533, +-26062, -26573, -27066, -27540, -27995, +-28431, -28848, -29245, -29622, -29979, +-30315, -30630, -30924, -31197, -31449, +-31679, -31887, -32074, -32239, -32381, +-32501, -32600, -32675, -32729, -32759, }; #endif static const CELTMode mode48000_960_120 = { - 48000, /* Fs */ - 120, /* overlap */ - 21, /* nbEBands */ - 21, /* effEBands */ - {27853, 0, 4096, 8192, }, /* preemph */ - eband5ms, /* eBands */ - 3, /* maxLM */ - 8, /* nbShortMdcts */ - 120, /* shortMdctSize */ - 11, /* nbAllocVectors */ - band_allocation, /* allocVectors */ - logN400, /* logN */ - window120, /* window */ - {1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960}, /* mdct */ - {392, cache_index50, cache_bits50, cache_caps50}, /* cache */ +48000, /* Fs */ +120, /* overlap */ +21, /* nbEBands */ +21, /* effEBands */ +{27853, 0, 4096, 8192, }, /* preemph */ +eband5ms, /* eBands */ +3, /* maxLM */ +8, /* nbShortMdcts */ +120, /* shortMdctSize */ +11, /* nbAllocVectors */ +band_allocation, /* allocVectors */ +logN400, /* logN */ +window120, /* window */ +{1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960}, /* mdct */ +{392, cache_index50, cache_bits50, cache_caps50}, /* cache */ }; /* List of all the available modes */ #define TOTAL_MODES 1 static const CELTMode * const static_mode_list[TOTAL_MODES] = { - &mode48000_960_120, +&mode48000_960_120, }; diff --git a/src/libopus/celt/static_modes_fixed_arm_ne10.h b/src/libopus/celt/static_modes_fixed_arm_ne10.h new file mode 100644 index 0000000..7623092 --- /dev/null +++ b/src/libopus/celt/static_modes_fixed_arm_ne10.h @@ -0,0 +1,388 @@ +/* The contents of this file was automatically generated by + * dump_mode_arm_ne10.c with arguments: 48000 960 + * It contains static definitions for some pre-defined modes. */ +#include + +#ifndef NE10_FFT_PARAMS48000_960 +#define NE10_FFT_PARAMS48000_960 +static const ne10_int32_t ne10_factors_480[64] = { +4, 40, 4, 30, 2, 15, 5, 3, 3, 1, 1, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_int32_t ne10_factors_240[64] = { +3, 20, 4, 15, 5, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_int32_t ne10_factors_120[64] = { +3, 10, 2, 15, 5, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_int32_t ne10_factors_60[64] = { +2, 5, 5, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_fft_cpx_int32_t ne10_twiddles_480[480] = { +{0,0}, {2147483647,0}, {2147483647,0}, +{2147483647,0}, {1961823921,-873460313}, {1436946998,-1595891394}, +{2147483647,0}, {1436946998,-1595891394}, {-224473265,-2135719496}, +{2147483647,0}, {663608871,-2042378339}, {-1737350854,-1262259096}, +{2147483647,0}, {-224473265,-2135719496}, {-2100555935,446487152}, +{2147483647,0}, {2100555974,-446486968}, {1961823921,-873460313}, +{1737350743,-1262259248}, {1436946998,-1595891394}, {1073741769,-1859775424}, +{663608871,-2042378339}, {224473078,-2135719516}, {-224473265,-2135719496}, +{-663609049,-2042378281}, {-1073741932,-1859775330}, {-1436947137,-1595891268}, +{-1737350854,-1262259096}, {-1961823997,-873460141}, {-2100556013,-446486785}, +{2147483647,0}, {2144540595,-112390613}, {2135719506,-224473172}, +{2121044558,-335940465}, {2100555974,-446486968}, {2074309912,-555809682}, +{2042378310,-663608960}, {2004848691,-769589332}, {1961823921,-873460313}, +{1913421927,-974937199}, {1859775377,-1073741851}, {1801031311,-1169603450}, +{1737350743,-1262259248}, {1668908218,-1351455280}, {1595891331,-1436947067}, +{1518500216,-1518500282}, {1436946998,-1595891394}, {1351455207,-1668908277}, +{1262259172,-1737350799}, {1169603371,-1801031362}, {1073741769,-1859775424}, +{974937230,-1913421912}, {873460227,-1961823959}, {769589125,-2004848771}, +{663608871,-2042378339}, {555809715,-2074309903}, {446486876,-2100555994}, +{335940246,-2121044593}, {224473078,-2135719516}, {112390647,-2144540593}, +{2147483647,0}, {2135719506,-224473172}, {2100555974,-446486968}, +{2042378310,-663608960}, {1961823921,-873460313}, {1859775377,-1073741851}, +{1737350743,-1262259248}, {1595891331,-1436947067}, {1436946998,-1595891394}, +{1262259172,-1737350799}, {1073741769,-1859775424}, {873460227,-1961823959}, +{663608871,-2042378339}, {446486876,-2100555994}, {224473078,-2135719516}, +{-94,-2147483647}, {-224473265,-2135719496}, {-446487060,-2100555955}, +{-663609049,-2042378281}, {-873460398,-1961823883}, {-1073741932,-1859775330}, +{-1262259116,-1737350839}, {-1436947137,-1595891268}, {-1595891628,-1436946738}, +{-1737350854,-1262259096}, {-1859775343,-1073741910}, {-1961823997,-873460141}, +{-2042378447,-663608538}, {-2100556013,-446486785}, {-2135719499,-224473240}, +{2147483647,0}, {2121044558,-335940465}, {2042378310,-663608960}, +{1913421927,-974937199}, {1737350743,-1262259248}, {1518500216,-1518500282}, +{1262259172,-1737350799}, {974937230,-1913421912}, {663608871,-2042378339}, +{335940246,-2121044593}, {-94,-2147483647}, {-335940431,-2121044564}, +{-663609049,-2042378281}, {-974937397,-1913421827}, {-1262259116,-1737350839}, +{-1518500258,-1518500240}, {-1737350854,-1262259096}, {-1913422071,-974936918}, +{-2042378447,-663608538}, {-2121044568,-335940406}, {-2147483647,188}, +{-2121044509,335940777}, {-2042378331,663608895}, {-1913421900,974937252}, +{-1737350633,1262259400}, {-1518499993,1518500506}, {-1262258813,1737351059}, +{-974936606,1913422229}, {-663609179,2042378239}, {-335940566,2121044542}, +{2147483647,0}, {2147299667,-28109693}, {2146747758,-56214570}, +{2145828015,-84309815}, {2144540595,-112390613}, {2142885719,-140452154}, +{2140863671,-168489630}, {2138474797,-196498235}, {2135719506,-224473172}, +{2132598271,-252409646}, {2129111626,-280302871}, {2125260168,-308148068}, +{2121044558,-335940465}, {2116465518,-363675300}, {2111523833,-391347822}, +{2106220349,-418953288}, {2100555974,-446486968}, {2094531681,-473944146}, +{2088148500,-501320115}, {2081407525,-528610186}, {2074309912,-555809682}, +{2066856885,-582913912}, {2059049696,-609918325}, {2050889698,-636818231}, +{2042378310,-663608960}, {2033516972,-690285983}, {2024307180,-716844791}, +{2014750533,-743280770}, {2004848691,-769589332}, {1994603329,-795766029}, +{1984016179,-821806435}, {1973089077,-847706028}, {1961823921,-873460313}, +{1950222618,-899064934}, {1938287127,-924515564}, {1926019520,-949807783}, +{1913421927,-974937199}, {1900496481,-999899565}, {1887245364,-1024690661}, +{1873670877,-1049306180}, {1859775377,-1073741851}, {1845561215,-1097993541}, +{1831030826,-1122057097}, {1816186632,-1145928502}, {1801031311,-1169603450}, +{1785567394,-1193077993}, {1769797456,-1216348214}, {1753724345,-1239409914}, +{1737350743,-1262259248}, {1720679456,-1284892300}, {1703713340,-1307305194}, +{1686455222,-1329494189}, {1668908218,-1351455280}, {1651075255,-1373184807}, +{1632959307,-1394679144}, {1614563642,-1415934412}, {1595891331,-1436947067}, +{1576945572,-1457713510}, {1557729613,-1478230181}, {1538246655,-1498493658}, +{1518500216,-1518500282}, {1498493590,-1538246721}, {1478230113,-1557729677}, +{1457713441,-1576945636}, {1436946998,-1595891394}, {1415934341,-1614563704}, +{1394679073,-1632959368}, {1373184735,-1651075315}, {1351455207,-1668908277}, +{1329494115,-1686455280}, {1307305120,-1703713397}, {1284892225,-1720679512}, +{1262259172,-1737350799}, {1239409837,-1753724400}, {1216348136,-1769797510}, +{1193077915,-1785567446}, {1169603371,-1801031362}, {1145928423,-1816186682}, +{1122057017,-1831030875}, {1097993571,-1845561197}, {1073741769,-1859775424}, +{1049305987,-1873670985}, {1024690635,-1887245378}, {999899482,-1900496524}, +{974937230,-1913421912}, {949807699,-1926019561}, {924515422,-1938287195}, +{899064965,-1950222603}, {873460227,-1961823959}, {847705824,-1973089164}, +{821806407,-1984016190}, {795765941,-1994603364}, {769589125,-2004848771}, +{743280682,-2014750566}, {716844642,-2024307233}, {690286016,-2033516961}, +{663608871,-2042378339}, {636818019,-2050889764}, {609918296,-2059049705}, +{582913822,-2066856911}, {555809715,-2074309903}, {528610126,-2081407540}, +{501319962,-2088148536}, {473944148,-2094531680}, {446486876,-2100555994}, +{418953102,-2106220386}, {391347792,-2111523838}, {363675176,-2116465540}, +{335940246,-2121044593}, {308148006,-2125260177}, {280302715,-2129111646}, +{252409648,-2132598271}, {224473078,-2135719516}, {196498046,-2138474814}, +{168489600,-2140863674}, {140452029,-2142885728}, {112390647,-2144540593}, +{84309753,-2145828017}, {56214412,-2146747762}, {28109695,-2147299667}, +{2147483647,0}, {2146747758,-56214570}, {2144540595,-112390613}, +{2140863671,-168489630}, {2135719506,-224473172}, {2129111626,-280302871}, +{2121044558,-335940465}, {2111523833,-391347822}, {2100555974,-446486968}, +{2088148500,-501320115}, {2074309912,-555809682}, {2059049696,-609918325}, +{2042378310,-663608960}, {2024307180,-716844791}, {2004848691,-769589332}, +{1984016179,-821806435}, {1961823921,-873460313}, {1938287127,-924515564}, +{1913421927,-974937199}, {1887245364,-1024690661}, {1859775377,-1073741851}, +{1831030826,-1122057097}, {1801031311,-1169603450}, {1769797456,-1216348214}, +{1737350743,-1262259248}, {1703713340,-1307305194}, {1668908218,-1351455280}, +{1632959307,-1394679144}, {1595891331,-1436947067}, {1557729613,-1478230181}, +{1518500216,-1518500282}, {1478230113,-1557729677}, {1436946998,-1595891394}, +{1394679073,-1632959368}, {1351455207,-1668908277}, {1307305120,-1703713397}, +{1262259172,-1737350799}, {1216348136,-1769797510}, {1169603371,-1801031362}, +{1122057017,-1831030875}, {1073741769,-1859775424}, {1024690635,-1887245378}, +{974937230,-1913421912}, {924515422,-1938287195}, {873460227,-1961823959}, +{821806407,-1984016190}, {769589125,-2004848771}, {716844642,-2024307233}, +{663608871,-2042378339}, {609918296,-2059049705}, {555809715,-2074309903}, +{501319962,-2088148536}, {446486876,-2100555994}, {391347792,-2111523838}, +{335940246,-2121044593}, {280302715,-2129111646}, {224473078,-2135719516}, +{168489600,-2140863674}, {112390647,-2144540593}, {56214412,-2146747762}, +{-94,-2147483647}, {-56214600,-2146747757}, {-112390835,-2144540584}, +{-168489787,-2140863659}, {-224473265,-2135719496}, {-280302901,-2129111622}, +{-335940431,-2121044564}, {-391347977,-2111523804}, {-446487060,-2100555955}, +{-501320144,-2088148493}, {-555809896,-2074309855}, {-609918476,-2059049651}, +{-663609049,-2042378281}, {-716844819,-2024307170}, {-769589300,-2004848703}, +{-821806581,-1984016118}, {-873460398,-1961823883}, {-924515591,-1938287114}, +{-974937397,-1913421827}, {-1024690575,-1887245411}, {-1073741932,-1859775330}, +{-1122057395,-1831030643}, {-1169603421,-1801031330}, {-1216348291,-1769797403}, +{-1262259116,-1737350839}, {-1307305268,-1703713283}, {-1351455453,-1668908078}, +{-1394679021,-1632959413}, {-1436947137,-1595891268}, {-1478230435,-1557729372}, +{-1518500258,-1518500240}, {-1557729742,-1478230045}, {-1595891628,-1436946738}, +{-1632959429,-1394679001}, {-1668908417,-1351455035}, {-1703713298,-1307305248}, +{-1737350854,-1262259096}, {-1769797708,-1216347848}, {-1801031344,-1169603400}, +{-1831030924,-1122056937}, {-1859775343,-1073741910}, {-1887245423,-1024690552}, +{-1913422071,-974936918}, {-1938287125,-924515568}, {-1961823997,-873460141}, +{-1984016324,-821806084}, {-2004848713,-769589276}, {-2024307264,-716844553}, +{-2042378447,-663608538}, {-2059049731,-609918206}, {-2074309994,-555809377}, +{-2088148499,-501320119}, {-2100556013,-446486785}, {-2111523902,-391347448}, +{-2121044568,-335940406}, {-2129111659,-280302621}, {-2135719499,-224473240}, +{-2140863681,-168489506}, {-2144540612,-112390298}, {-2146747758,-56214574}, +{2147483647,0}, {2145828015,-84309815}, {2140863671,-168489630}, +{2132598271,-252409646}, {2121044558,-335940465}, {2106220349,-418953288}, +{2088148500,-501320115}, {2066856885,-582913912}, {2042378310,-663608960}, +{2014750533,-743280770}, {1984016179,-821806435}, {1950222618,-899064934}, +{1913421927,-974937199}, {1873670877,-1049306180}, {1831030826,-1122057097}, +{1785567394,-1193077993}, {1737350743,-1262259248}, {1686455222,-1329494189}, +{1632959307,-1394679144}, {1576945572,-1457713510}, {1518500216,-1518500282}, +{1457713441,-1576945636}, {1394679073,-1632959368}, {1329494115,-1686455280}, +{1262259172,-1737350799}, {1193077915,-1785567446}, {1122057017,-1831030875}, +{1049305987,-1873670985}, {974937230,-1913421912}, {899064965,-1950222603}, +{821806407,-1984016190}, {743280682,-2014750566}, {663608871,-2042378339}, +{582913822,-2066856911}, {501319962,-2088148536}, {418953102,-2106220386}, +{335940246,-2121044593}, {252409648,-2132598271}, {168489600,-2140863674}, +{84309753,-2145828017}, {-94,-2147483647}, {-84309940,-2145828010}, +{-168489787,-2140863659}, {-252409834,-2132598249}, {-335940431,-2121044564}, +{-418953286,-2106220349}, {-501320144,-2088148493}, {-582914003,-2066856860}, +{-663609049,-2042378281}, {-743280858,-2014750501}, {-821806581,-1984016118}, +{-899065136,-1950222525}, {-974937397,-1913421827}, {-1049306374,-1873670768}, +{-1122057395,-1831030643}, {-1193078284,-1785567199}, {-1262259116,-1737350839}, +{-1329494061,-1686455323}, {-1394679021,-1632959413}, {-1457713485,-1576945595}, +{-1518500258,-1518500240}, {-1576945613,-1457713466}, {-1632959429,-1394679001}, +{-1686455338,-1329494041}, {-1737350854,-1262259096}, {-1785567498,-1193077837}, +{-1831030924,-1122056937}, {-1873671031,-1049305905}, {-1913422071,-974936918}, +{-1950222750,-899064648}, {-1984016324,-821806084}, {-2014750687,-743280354}, +{-2042378447,-663608538}, {-2066856867,-582913978}, {-2088148499,-501320119}, +{-2106220354,-418953261}, {-2121044568,-335940406}, {-2132598282,-252409555}, +{-2140863681,-168489506}, {-2145828021,-84309659}, {-2147483647,188}, +{-2145828006,84310034}, {-2140863651,168489881}, {-2132598237,252409928}, +{-2121044509,335940777}, {-2106220281,418953629}, {-2088148411,501320484}, +{-2066856765,582914339}, {-2042378331,663608895}, {-2014750557,743280706}, +{-1984016181,821806431}, {-1950222593,899064989}, {-1913421900,974937252}, +{-1873670848,1049306232}, {-1831030728,1122057257}, {-1785567289,1193078149}, +{-1737350633,1262259400}, {-1686455106,1329494336}, {-1632959185,1394679287}, +{-1576945358,1457713742}, {-1518499993,1518500506}, {-1457713209,1576945850}, +{-1394678735,1632959656}, {-1329493766,1686455555}, {-1262258813,1737351059}, +{-1193077546,1785567692}, {-1122056638,1831031107}, {-1049305599,1873671202}, +{-974936606,1913422229}, {-899064330,1950222896}, {-821805761,1984016458}, +{-743280025,2014750808}, {-663609179,2042378239}, {-582914134,2066856823}, +{-501320277,2088148461}, {-418953420,2106220322}, {-335940566,2121044542}, +{-252409716,2132598263}, {-168489668,2140863668}, {-84309821,2145828015}, +}; +static const ne10_fft_cpx_int32_t ne10_twiddles_240[240] = { +{0,0}, {2147483647,0}, {2147483647,0}, +{2147483647,0}, {1961823921,-873460313}, {1436946998,-1595891394}, +{2147483647,0}, {1436946998,-1595891394}, {-224473265,-2135719496}, +{2147483647,0}, {663608871,-2042378339}, {-1737350854,-1262259096}, +{2147483647,0}, {-224473265,-2135719496}, {-2100555935,446487152}, +{2147483647,0}, {2135719506,-224473172}, {2100555974,-446486968}, +{2042378310,-663608960}, {1961823921,-873460313}, {1859775377,-1073741851}, +{1737350743,-1262259248}, {1595891331,-1436947067}, {1436946998,-1595891394}, +{1262259172,-1737350799}, {1073741769,-1859775424}, {873460227,-1961823959}, +{663608871,-2042378339}, {446486876,-2100555994}, {224473078,-2135719516}, +{2147483647,0}, {2100555974,-446486968}, {1961823921,-873460313}, +{1737350743,-1262259248}, {1436946998,-1595891394}, {1073741769,-1859775424}, +{663608871,-2042378339}, {224473078,-2135719516}, {-224473265,-2135719496}, +{-663609049,-2042378281}, {-1073741932,-1859775330}, {-1436947137,-1595891268}, +{-1737350854,-1262259096}, {-1961823997,-873460141}, {-2100556013,-446486785}, +{2147483647,0}, {2042378310,-663608960}, {1737350743,-1262259248}, +{1262259172,-1737350799}, {663608871,-2042378339}, {-94,-2147483647}, +{-663609049,-2042378281}, {-1262259116,-1737350839}, {-1737350854,-1262259096}, +{-2042378447,-663608538}, {-2147483647,188}, {-2042378331,663608895}, +{-1737350633,1262259400}, {-1262258813,1737351059}, {-663609179,2042378239}, +{2147483647,0}, {2146747758,-56214570}, {2144540595,-112390613}, +{2140863671,-168489630}, {2135719506,-224473172}, {2129111626,-280302871}, +{2121044558,-335940465}, {2111523833,-391347822}, {2100555974,-446486968}, +{2088148500,-501320115}, {2074309912,-555809682}, {2059049696,-609918325}, +{2042378310,-663608960}, {2024307180,-716844791}, {2004848691,-769589332}, +{1984016179,-821806435}, {1961823921,-873460313}, {1938287127,-924515564}, +{1913421927,-974937199}, {1887245364,-1024690661}, {1859775377,-1073741851}, +{1831030826,-1122057097}, {1801031311,-1169603450}, {1769797456,-1216348214}, +{1737350743,-1262259248}, {1703713340,-1307305194}, {1668908218,-1351455280}, +{1632959307,-1394679144}, {1595891331,-1436947067}, {1557729613,-1478230181}, +{1518500216,-1518500282}, {1478230113,-1557729677}, {1436946998,-1595891394}, +{1394679073,-1632959368}, {1351455207,-1668908277}, {1307305120,-1703713397}, +{1262259172,-1737350799}, {1216348136,-1769797510}, {1169603371,-1801031362}, +{1122057017,-1831030875}, {1073741769,-1859775424}, {1024690635,-1887245378}, +{974937230,-1913421912}, {924515422,-1938287195}, {873460227,-1961823959}, +{821806407,-1984016190}, {769589125,-2004848771}, {716844642,-2024307233}, +{663608871,-2042378339}, {609918296,-2059049705}, {555809715,-2074309903}, +{501319962,-2088148536}, {446486876,-2100555994}, {391347792,-2111523838}, +{335940246,-2121044593}, {280302715,-2129111646}, {224473078,-2135719516}, +{168489600,-2140863674}, {112390647,-2144540593}, {56214412,-2146747762}, +{2147483647,0}, {2144540595,-112390613}, {2135719506,-224473172}, +{2121044558,-335940465}, {2100555974,-446486968}, {2074309912,-555809682}, +{2042378310,-663608960}, {2004848691,-769589332}, {1961823921,-873460313}, +{1913421927,-974937199}, {1859775377,-1073741851}, {1801031311,-1169603450}, +{1737350743,-1262259248}, {1668908218,-1351455280}, {1595891331,-1436947067}, +{1518500216,-1518500282}, {1436946998,-1595891394}, {1351455207,-1668908277}, +{1262259172,-1737350799}, {1169603371,-1801031362}, {1073741769,-1859775424}, +{974937230,-1913421912}, {873460227,-1961823959}, {769589125,-2004848771}, +{663608871,-2042378339}, {555809715,-2074309903}, {446486876,-2100555994}, +{335940246,-2121044593}, {224473078,-2135719516}, {112390647,-2144540593}, +{-94,-2147483647}, {-112390835,-2144540584}, {-224473265,-2135719496}, +{-335940431,-2121044564}, {-446487060,-2100555955}, {-555809896,-2074309855}, +{-663609049,-2042378281}, {-769589300,-2004848703}, {-873460398,-1961823883}, +{-974937397,-1913421827}, {-1073741932,-1859775330}, {-1169603421,-1801031330}, +{-1262259116,-1737350839}, {-1351455453,-1668908078}, {-1436947137,-1595891268}, +{-1518500258,-1518500240}, {-1595891628,-1436946738}, {-1668908417,-1351455035}, +{-1737350854,-1262259096}, {-1801031344,-1169603400}, {-1859775343,-1073741910}, +{-1913422071,-974936918}, {-1961823997,-873460141}, {-2004848713,-769589276}, +{-2042378447,-663608538}, {-2074309994,-555809377}, {-2100556013,-446486785}, +{-2121044568,-335940406}, {-2135719499,-224473240}, {-2144540612,-112390298}, +{2147483647,0}, {2140863671,-168489630}, {2121044558,-335940465}, +{2088148500,-501320115}, {2042378310,-663608960}, {1984016179,-821806435}, +{1913421927,-974937199}, {1831030826,-1122057097}, {1737350743,-1262259248}, +{1632959307,-1394679144}, {1518500216,-1518500282}, {1394679073,-1632959368}, +{1262259172,-1737350799}, {1122057017,-1831030875}, {974937230,-1913421912}, +{821806407,-1984016190}, {663608871,-2042378339}, {501319962,-2088148536}, +{335940246,-2121044593}, {168489600,-2140863674}, {-94,-2147483647}, +{-168489787,-2140863659}, {-335940431,-2121044564}, {-501320144,-2088148493}, +{-663609049,-2042378281}, {-821806581,-1984016118}, {-974937397,-1913421827}, +{-1122057395,-1831030643}, {-1262259116,-1737350839}, {-1394679021,-1632959413}, +{-1518500258,-1518500240}, {-1632959429,-1394679001}, {-1737350854,-1262259096}, +{-1831030924,-1122056937}, {-1913422071,-974936918}, {-1984016324,-821806084}, +{-2042378447,-663608538}, {-2088148499,-501320119}, {-2121044568,-335940406}, +{-2140863681,-168489506}, {-2147483647,188}, {-2140863651,168489881}, +{-2121044509,335940777}, {-2088148411,501320484}, {-2042378331,663608895}, +{-1984016181,821806431}, {-1913421900,974937252}, {-1831030728,1122057257}, +{-1737350633,1262259400}, {-1632959185,1394679287}, {-1518499993,1518500506}, +{-1394678735,1632959656}, {-1262258813,1737351059}, {-1122056638,1831031107}, +{-974936606,1913422229}, {-821805761,1984016458}, {-663609179,2042378239}, +{-501320277,2088148461}, {-335940566,2121044542}, {-168489668,2140863668}, +}; +static const ne10_fft_cpx_int32_t ne10_twiddles_120[120] = { +{0,0}, {2147483647,0}, {2147483647,0}, +{2147483647,0}, {1961823921,-873460313}, {1436946998,-1595891394}, +{2147483647,0}, {1436946998,-1595891394}, {-224473265,-2135719496}, +{2147483647,0}, {663608871,-2042378339}, {-1737350854,-1262259096}, +{2147483647,0}, {-224473265,-2135719496}, {-2100555935,446487152}, +{2147483647,0}, {2100555974,-446486968}, {1961823921,-873460313}, +{1737350743,-1262259248}, {1436946998,-1595891394}, {1073741769,-1859775424}, +{663608871,-2042378339}, {224473078,-2135719516}, {-224473265,-2135719496}, +{-663609049,-2042378281}, {-1073741932,-1859775330}, {-1436947137,-1595891268}, +{-1737350854,-1262259096}, {-1961823997,-873460141}, {-2100556013,-446486785}, +{2147483647,0}, {2144540595,-112390613}, {2135719506,-224473172}, +{2121044558,-335940465}, {2100555974,-446486968}, {2074309912,-555809682}, +{2042378310,-663608960}, {2004848691,-769589332}, {1961823921,-873460313}, +{1913421927,-974937199}, {1859775377,-1073741851}, {1801031311,-1169603450}, +{1737350743,-1262259248}, {1668908218,-1351455280}, {1595891331,-1436947067}, +{1518500216,-1518500282}, {1436946998,-1595891394}, {1351455207,-1668908277}, +{1262259172,-1737350799}, {1169603371,-1801031362}, {1073741769,-1859775424}, +{974937230,-1913421912}, {873460227,-1961823959}, {769589125,-2004848771}, +{663608871,-2042378339}, {555809715,-2074309903}, {446486876,-2100555994}, +{335940246,-2121044593}, {224473078,-2135719516}, {112390647,-2144540593}, +{2147483647,0}, {2135719506,-224473172}, {2100555974,-446486968}, +{2042378310,-663608960}, {1961823921,-873460313}, {1859775377,-1073741851}, +{1737350743,-1262259248}, {1595891331,-1436947067}, {1436946998,-1595891394}, +{1262259172,-1737350799}, {1073741769,-1859775424}, {873460227,-1961823959}, +{663608871,-2042378339}, {446486876,-2100555994}, {224473078,-2135719516}, +{-94,-2147483647}, {-224473265,-2135719496}, {-446487060,-2100555955}, +{-663609049,-2042378281}, {-873460398,-1961823883}, {-1073741932,-1859775330}, +{-1262259116,-1737350839}, {-1436947137,-1595891268}, {-1595891628,-1436946738}, +{-1737350854,-1262259096}, {-1859775343,-1073741910}, {-1961823997,-873460141}, +{-2042378447,-663608538}, {-2100556013,-446486785}, {-2135719499,-224473240}, +{2147483647,0}, {2121044558,-335940465}, {2042378310,-663608960}, +{1913421927,-974937199}, {1737350743,-1262259248}, {1518500216,-1518500282}, +{1262259172,-1737350799}, {974937230,-1913421912}, {663608871,-2042378339}, +{335940246,-2121044593}, {-94,-2147483647}, {-335940431,-2121044564}, +{-663609049,-2042378281}, {-974937397,-1913421827}, {-1262259116,-1737350839}, +{-1518500258,-1518500240}, {-1737350854,-1262259096}, {-1913422071,-974936918}, +{-2042378447,-663608538}, {-2121044568,-335940406}, {-2147483647,188}, +{-2121044509,335940777}, {-2042378331,663608895}, {-1913421900,974937252}, +{-1737350633,1262259400}, {-1518499993,1518500506}, {-1262258813,1737351059}, +{-974936606,1913422229}, {-663609179,2042378239}, {-335940566,2121044542}, +}; +static const ne10_fft_cpx_int32_t ne10_twiddles_60[60] = { +{0,0}, {2147483647,0}, {2147483647,0}, +{2147483647,0}, {1961823921,-873460313}, {1436946998,-1595891394}, +{2147483647,0}, {1436946998,-1595891394}, {-224473265,-2135719496}, +{2147483647,0}, {663608871,-2042378339}, {-1737350854,-1262259096}, +{2147483647,0}, {-224473265,-2135719496}, {-2100555935,446487152}, +{2147483647,0}, {2135719506,-224473172}, {2100555974,-446486968}, +{2042378310,-663608960}, {1961823921,-873460313}, {1859775377,-1073741851}, +{1737350743,-1262259248}, {1595891331,-1436947067}, {1436946998,-1595891394}, +{1262259172,-1737350799}, {1073741769,-1859775424}, {873460227,-1961823959}, +{663608871,-2042378339}, {446486876,-2100555994}, {224473078,-2135719516}, +{2147483647,0}, {2100555974,-446486968}, {1961823921,-873460313}, +{1737350743,-1262259248}, {1436946998,-1595891394}, {1073741769,-1859775424}, +{663608871,-2042378339}, {224473078,-2135719516}, {-224473265,-2135719496}, +{-663609049,-2042378281}, {-1073741932,-1859775330}, {-1436947137,-1595891268}, +{-1737350854,-1262259096}, {-1961823997,-873460141}, {-2100556013,-446486785}, +{2147483647,0}, {2042378310,-663608960}, {1737350743,-1262259248}, +{1262259172,-1737350799}, {663608871,-2042378339}, {-94,-2147483647}, +{-663609049,-2042378281}, {-1262259116,-1737350839}, {-1737350854,-1262259096}, +{-2042378447,-663608538}, {-2147483647,188}, {-2042378331,663608895}, +{-1737350633,1262259400}, {-1262258813,1737351059}, {-663609179,2042378239}, +}; +static const ne10_fft_state_int32_t ne10_fft_state_int32_t_480 = { +120, +(ne10_int32_t *)ne10_factors_480, +(ne10_fft_cpx_int32_t *)ne10_twiddles_480, +NULL, +(ne10_fft_cpx_int32_t *)&ne10_twiddles_480[120], +}; +static const arch_fft_state cfg_arch_480 = { +1, +(void *)&ne10_fft_state_int32_t_480, +}; + +static const ne10_fft_state_int32_t ne10_fft_state_int32_t_240 = { +60, +(ne10_int32_t *)ne10_factors_240, +(ne10_fft_cpx_int32_t *)ne10_twiddles_240, +NULL, +(ne10_fft_cpx_int32_t *)&ne10_twiddles_240[60], +}; +static const arch_fft_state cfg_arch_240 = { +1, +(void *)&ne10_fft_state_int32_t_240, +}; + +static const ne10_fft_state_int32_t ne10_fft_state_int32_t_120 = { +30, +(ne10_int32_t *)ne10_factors_120, +(ne10_fft_cpx_int32_t *)ne10_twiddles_120, +NULL, +(ne10_fft_cpx_int32_t *)&ne10_twiddles_120[30], +}; +static const arch_fft_state cfg_arch_120 = { +1, +(void *)&ne10_fft_state_int32_t_120, +}; + +static const ne10_fft_state_int32_t ne10_fft_state_int32_t_60 = { +15, +(ne10_int32_t *)ne10_factors_60, +(ne10_fft_cpx_int32_t *)ne10_twiddles_60, +NULL, +(ne10_fft_cpx_int32_t *)&ne10_twiddles_60[15], +}; +static const arch_fft_state cfg_arch_60 = { +1, +(void *)&ne10_fft_state_int32_t_60, +}; + +#endif /* end NE10_FFT_PARAMS48000_960 */ diff --git a/src/libopus/celt/static_modes_float.h b/src/libopus/celt/static_modes_float.h index 58922bd..e102a38 100644 --- a/src/libopus/celt/static_modes_float.h +++ b/src/libopus/celt/static_modes_float.h @@ -1,6 +1,6 @@ -/* The contents of this file was automatically generated by dump_modes.c - with arguments: 48000 960 - It contains static definitions for some pre-defined modes. */ +/* The contents of this file was automatically generated by dump_modes.c + with arguments: 48000 960 + It contains static definitions for some pre-defined modes. */ #include "modes.h" #include "rate.h" @@ -12,437 +12,434 @@ #ifndef DEF_WINDOW120 #define DEF_WINDOW120 static const opus_val16 window120[120] = { - 6.7286966e-05f, 0.00060551348f, 0.0016815970f, 0.0032947962f, 0.0054439943f, - 0.0081276923f, 0.011344001f, 0.015090633f, 0.019364886f, 0.024163635f, - 0.029483315f, 0.035319905f, 0.041668911f, 0.048525347f, 0.055883718f, - 0.063737999f, 0.072081616f, 0.080907428f, 0.090207705f, 0.099974111f, - 0.11019769f, 0.12086883f, 0.13197729f, 0.14351214f, 0.15546177f, - 0.16781389f, 0.18055550f, 0.19367290f, 0.20715171f, 0.22097682f, - 0.23513243f, 0.24960208f, 0.26436860f, 0.27941419f, 0.29472040f, - 0.31026818f, 0.32603788f, 0.34200931f, 0.35816177f, 0.37447407f, - 0.39092462f, 0.40749142f, 0.42415215f, 0.44088423f, 0.45766484f, - 0.47447104f, 0.49127978f, 0.50806798f, 0.52481261f, 0.54149077f, - 0.55807973f, 0.57455701f, 0.59090049f, 0.60708841f, 0.62309951f, - 0.63891306f, 0.65450896f, 0.66986776f, 0.68497077f, 0.69980010f, - 0.71433873f, 0.72857055f, 0.74248043f, 0.75605424f, 0.76927895f, - 0.78214257f, 0.79463430f, 0.80674445f, 0.81846456f, 0.82978733f, - 0.84070669f, 0.85121779f, 0.86131698f, 0.87100183f, 0.88027111f, - 0.88912479f, 0.89756398f, 0.90559094f, 0.91320904f, 0.92042270f, - 0.92723738f, 0.93365955f, 0.93969656f, 0.94535671f, 0.95064907f, - 0.95558353f, 0.96017067f, 0.96442171f, 0.96834849f, 0.97196334f, - 0.97527906f, 0.97830883f, 0.98106616f, 0.98356480f, 0.98581869f, - 0.98784191f, 0.98964856f, 0.99125274f, 0.99266849f, 0.99390969f, - 0.99499004f, 0.99592297f, 0.99672162f, 0.99739874f, 0.99796667f, - 0.99843728f, 0.99882195f, 0.99913147f, 0.99937606f, 0.99956527f, - 0.99970802f, 0.99981248f, 0.99988613f, 0.99993565f, 0.99996697f, - 0.99998518f, 0.99999457f, 0.99999859f, 0.99999982f, 1.0000000f, +6.7286966e-05f, 0.00060551348f, 0.0016815970f, 0.0032947962f, 0.0054439943f, +0.0081276923f, 0.011344001f, 0.015090633f, 0.019364886f, 0.024163635f, +0.029483315f, 0.035319905f, 0.041668911f, 0.048525347f, 0.055883718f, +0.063737999f, 0.072081616f, 0.080907428f, 0.090207705f, 0.099974111f, +0.11019769f, 0.12086883f, 0.13197729f, 0.14351214f, 0.15546177f, +0.16781389f, 0.18055550f, 0.19367290f, 0.20715171f, 0.22097682f, +0.23513243f, 0.24960208f, 0.26436860f, 0.27941419f, 0.29472040f, +0.31026818f, 0.32603788f, 0.34200931f, 0.35816177f, 0.37447407f, +0.39092462f, 0.40749142f, 0.42415215f, 0.44088423f, 0.45766484f, +0.47447104f, 0.49127978f, 0.50806798f, 0.52481261f, 0.54149077f, +0.55807973f, 0.57455701f, 0.59090049f, 0.60708841f, 0.62309951f, +0.63891306f, 0.65450896f, 0.66986776f, 0.68497077f, 0.69980010f, +0.71433873f, 0.72857055f, 0.74248043f, 0.75605424f, 0.76927895f, +0.78214257f, 0.79463430f, 0.80674445f, 0.81846456f, 0.82978733f, +0.84070669f, 0.85121779f, 0.86131698f, 0.87100183f, 0.88027111f, +0.88912479f, 0.89756398f, 0.90559094f, 0.91320904f, 0.92042270f, +0.92723738f, 0.93365955f, 0.93969656f, 0.94535671f, 0.95064907f, +0.95558353f, 0.96017067f, 0.96442171f, 0.96834849f, 0.97196334f, +0.97527906f, 0.97830883f, 0.98106616f, 0.98356480f, 0.98581869f, +0.98784191f, 0.98964856f, 0.99125274f, 0.99266849f, 0.99390969f, +0.99499004f, 0.99592297f, 0.99672162f, 0.99739874f, 0.99796667f, +0.99843728f, 0.99882195f, 0.99913147f, 0.99937606f, 0.99956527f, +0.99970802f, 0.99981248f, 0.99988613f, 0.99993565f, 0.99996697f, +0.99998518f, 0.99999457f, 0.99999859f, 0.99999982f, 1.0000000f, }; #endif #ifndef DEF_LOGN400 #define DEF_LOGN400 static const opus_int16 logN400[21] = { - 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 16, 16, 16, 21, 21, 24, 29, 34, 36, -}; +0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 16, 16, 16, 21, 21, 24, 29, 34, 36, }; #endif #ifndef DEF_PULSE_CACHE50 #define DEF_PULSE_CACHE50 static const opus_int16 cache_index50[105] = { - -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 41, 41, 41, - 82, 82, 123, 164, 200, 222, 0, 0, 0, 0, 0, 0, 0, 0, 41, - 41, 41, 41, 123, 123, 123, 164, 164, 240, 266, 283, 295, 41, 41, 41, - 41, 41, 41, 41, 41, 123, 123, 123, 123, 240, 240, 240, 266, 266, 305, - 318, 328, 336, 123, 123, 123, 123, 123, 123, 123, 123, 240, 240, 240, 240, - 305, 305, 305, 318, 318, 343, 351, 358, 364, 240, 240, 240, 240, 240, 240, - 240, 240, 305, 305, 305, 305, 343, 343, 343, 351, 351, 370, 376, 382, 387, - }; +-1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 41, 41, 41, +82, 82, 123, 164, 200, 222, 0, 0, 0, 0, 0, 0, 0, 0, 41, +41, 41, 41, 123, 123, 123, 164, 164, 240, 266, 283, 295, 41, 41, 41, +41, 41, 41, 41, 41, 123, 123, 123, 123, 240, 240, 240, 266, 266, 305, +318, 328, 336, 123, 123, 123, 123, 123, 123, 123, 123, 240, 240, 240, 240, +305, 305, 305, 318, 318, 343, 351, 358, 364, 240, 240, 240, 240, 240, 240, +240, 240, 305, 305, 305, 305, 343, 343, 343, 351, 351, 370, 376, 382, 387, +}; static const unsigned char cache_bits50[392] = { - 40, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 40, 15, 23, 28, - 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, 47, 49, 50, - 51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 63, 63, 65, - 66, 67, 68, 69, 70, 71, 71, 40, 20, 33, 41, 48, 53, 57, 61, - 64, 66, 69, 71, 73, 75, 76, 78, 80, 82, 85, 87, 89, 91, 92, - 94, 96, 98, 101, 103, 105, 107, 108, 110, 112, 114, 117, 119, 121, 123, - 124, 126, 128, 40, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, - 97, 100, 102, 105, 107, 111, 115, 118, 121, 124, 126, 129, 131, 135, 139, - 142, 145, 148, 150, 153, 155, 159, 163, 166, 169, 172, 174, 177, 179, 35, - 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, - 153, 159, 165, 171, 176, 180, 185, 189, 192, 199, 205, 211, 216, 220, 225, - 229, 232, 239, 245, 251, 21, 33, 58, 79, 97, 112, 125, 137, 148, 157, - 166, 174, 182, 189, 195, 201, 207, 217, 227, 235, 243, 251, 17, 35, 63, - 86, 106, 123, 139, 152, 165, 177, 187, 197, 206, 214, 222, 230, 237, 250, - 25, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, - 185, 190, 200, 208, 215, 222, 229, 235, 240, 245, 255, 16, 36, 65, 89, - 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250, 11, 41, - 74, 103, 128, 151, 172, 191, 209, 225, 241, 255, 9, 43, 79, 110, 138, - 163, 186, 207, 227, 246, 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, - 228, 241, 253, 9, 44, 81, 113, 142, 168, 192, 214, 235, 255, 7, 49, - 90, 127, 160, 191, 220, 247, 6, 51, 95, 134, 170, 203, 234, 7, 47, - 87, 123, 155, 184, 212, 237, 6, 52, 97, 137, 174, 208, 240, 5, 57, - 106, 151, 192, 231, 5, 59, 111, 158, 202, 243, 5, 55, 103, 147, 187, - 224, 5, 60, 113, 161, 206, 248, 4, 65, 122, 175, 224, 4, 67, 127, - 182, 234, -}; +40, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, +7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, +7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 40, 15, 23, 28, +31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, 47, 49, 50, +51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 63, 63, 65, +66, 67, 68, 69, 70, 71, 71, 40, 20, 33, 41, 48, 53, 57, 61, +64, 66, 69, 71, 73, 75, 76, 78, 80, 82, 85, 87, 89, 91, 92, +94, 96, 98, 101, 103, 105, 107, 108, 110, 112, 114, 117, 119, 121, 123, +124, 126, 128, 40, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, +97, 100, 102, 105, 107, 111, 115, 118, 121, 124, 126, 129, 131, 135, 139, +142, 145, 148, 150, 153, 155, 159, 163, 166, 169, 172, 174, 177, 179, 35, +28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, +153, 159, 165, 171, 176, 180, 185, 189, 192, 199, 205, 211, 216, 220, 225, +229, 232, 239, 245, 251, 21, 33, 58, 79, 97, 112, 125, 137, 148, 157, +166, 174, 182, 189, 195, 201, 207, 217, 227, 235, 243, 251, 17, 35, 63, +86, 106, 123, 139, 152, 165, 177, 187, 197, 206, 214, 222, 230, 237, 250, +25, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, +185, 190, 200, 208, 215, 222, 229, 235, 240, 245, 255, 16, 36, 65, 89, +110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250, 11, 41, +74, 103, 128, 151, 172, 191, 209, 225, 241, 255, 9, 43, 79, 110, 138, +163, 186, 207, 227, 246, 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, +228, 241, 253, 9, 44, 81, 113, 142, 168, 192, 214, 235, 255, 7, 49, +90, 127, 160, 191, 220, 247, 6, 51, 95, 134, 170, 203, 234, 7, 47, +87, 123, 155, 184, 212, 237, 6, 52, 97, 137, 174, 208, 240, 5, 57, +106, 151, 192, 231, 5, 59, 111, 158, 202, 243, 5, 55, 103, 147, 187, +224, 5, 60, 113, 161, 206, 248, 4, 65, 122, 175, 224, 4, 67, 127, +182, 234, }; static const unsigned char cache_caps50[168] = { - 224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, - 178, 178, 168, 134, 61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, - 240, 240, 240, 207, 207, 207, 198, 198, 183, 144, 66, 40, 160, 160, 160, - 160, 160, 160, 160, 160, 185, 185, 185, 185, 193, 193, 193, 183, 183, 172, - 138, 64, 38, 240, 240, 240, 240, 240, 240, 240, 240, 207, 207, 207, 207, - 204, 204, 204, 193, 193, 180, 143, 66, 40, 185, 185, 185, 185, 185, 185, - 185, 185, 193, 193, 193, 193, 193, 193, 193, 183, 183, 172, 138, 65, 39, - 207, 207, 207, 207, 207, 207, 207, 207, 204, 204, 204, 204, 201, 201, 201, - 188, 188, 176, 141, 66, 40, 193, 193, 193, 193, 193, 193, 193, 193, 193, - 193, 193, 193, 194, 194, 194, 184, 184, 173, 139, 65, 39, 204, 204, 204, - 204, 204, 204, 204, 204, 201, 201, 201, 201, 198, 198, 198, 187, 187, 175, - 140, 66, 40, -}; +224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, +178, 178, 168, 134, 61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, +240, 240, 240, 207, 207, 207, 198, 198, 183, 144, 66, 40, 160, 160, 160, +160, 160, 160, 160, 160, 185, 185, 185, 185, 193, 193, 193, 183, 183, 172, +138, 64, 38, 240, 240, 240, 240, 240, 240, 240, 240, 207, 207, 207, 207, +204, 204, 204, 193, 193, 180, 143, 66, 40, 185, 185, 185, 185, 185, 185, +185, 185, 193, 193, 193, 193, 193, 193, 193, 183, 183, 172, 138, 65, 39, +207, 207, 207, 207, 207, 207, 207, 207, 204, 204, 204, 204, 201, 201, 201, +188, 188, 176, 141, 66, 40, 193, 193, 193, 193, 193, 193, 193, 193, 193, +193, 193, 193, 194, 194, 194, 184, 184, 173, 139, 65, 39, 204, 204, 204, +204, 204, 204, 204, 204, 201, 201, 201, 201, 198, 198, 198, 187, 187, 175, +140, 66, 40, }; #endif #ifndef FFT_TWIDDLES48000_960 #define FFT_TWIDDLES48000_960 static const kiss_twiddle_cpx fft_twiddles48000_960[480] = { - {1.0000000f, -0.0000000f}, {0.99991433f, -0.013089596f}, - {0.99965732f, -0.026176948f}, {0.99922904f, -0.039259816f}, - {0.99862953f, -0.052335956f}, {0.99785892f, -0.065403129f}, - {0.99691733f, -0.078459096f}, {0.99580493f, -0.091501619f}, - {0.99452190f, -0.10452846f}, {0.99306846f, -0.11753740f}, - {0.99144486f, -0.13052619f}, {0.98965139f, -0.14349262f}, - {0.98768834f, -0.15643447f}, {0.98555606f, -0.16934950f}, - {0.98325491f, -0.18223553f}, {0.98078528f, -0.19509032f}, - {0.97814760f, -0.20791169f}, {0.97534232f, -0.22069744f}, - {0.97236992f, -0.23344536f}, {0.96923091f, -0.24615329f}, - {0.96592583f, -0.25881905f}, {0.96245524f, -0.27144045f}, - {0.95881973f, -0.28401534f}, {0.95501994f, -0.29654157f}, - {0.95105652f, -0.30901699f}, {0.94693013f, -0.32143947f}, - {0.94264149f, -0.33380686f}, {0.93819134f, -0.34611706f}, - {0.93358043f, -0.35836795f}, {0.92880955f, -0.37055744f}, - {0.92387953f, -0.38268343f}, {0.91879121f, -0.39474386f}, - {0.91354546f, -0.40673664f}, {0.90814317f, -0.41865974f}, - {0.90258528f, -0.43051110f}, {0.89687274f, -0.44228869f}, - {0.89100652f, -0.45399050f}, {0.88498764f, -0.46561452f}, - {0.87881711f, -0.47715876f}, {0.87249601f, -0.48862124f}, - {0.86602540f, -0.50000000f}, {0.85940641f, -0.51129309f}, - {0.85264016f, -0.52249856f}, {0.84572782f, -0.53361452f}, - {0.83867057f, -0.54463904f}, {0.83146961f, -0.55557023f}, - {0.82412619f, -0.56640624f}, {0.81664156f, -0.57714519f}, - {0.80901699f, -0.58778525f}, {0.80125381f, -0.59832460f}, - {0.79335334f, -0.60876143f}, {0.78531693f, -0.61909395f}, - {0.77714596f, -0.62932039f}, {0.76884183f, -0.63943900f}, - {0.76040597f, -0.64944805f}, {0.75183981f, -0.65934582f}, - {0.74314483f, -0.66913061f}, {0.73432251f, -0.67880075f}, - {0.72537437f, -0.68835458f}, {0.71630194f, -0.69779046f}, - {0.70710678f, -0.70710678f}, {0.69779046f, -0.71630194f}, - {0.68835458f, -0.72537437f}, {0.67880075f, -0.73432251f}, - {0.66913061f, -0.74314483f}, {0.65934582f, -0.75183981f}, - {0.64944805f, -0.76040597f}, {0.63943900f, -0.76884183f}, - {0.62932039f, -0.77714596f}, {0.61909395f, -0.78531693f}, - {0.60876143f, -0.79335334f}, {0.59832460f, -0.80125381f}, - {0.58778525f, -0.80901699f}, {0.57714519f, -0.81664156f}, - {0.56640624f, -0.82412619f}, {0.55557023f, -0.83146961f}, - {0.54463904f, -0.83867057f}, {0.53361452f, -0.84572782f}, - {0.52249856f, -0.85264016f}, {0.51129309f, -0.85940641f}, - {0.50000000f, -0.86602540f}, {0.48862124f, -0.87249601f}, - {0.47715876f, -0.87881711f}, {0.46561452f, -0.88498764f}, - {0.45399050f, -0.89100652f}, {0.44228869f, -0.89687274f}, - {0.43051110f, -0.90258528f}, {0.41865974f, -0.90814317f}, - {0.40673664f, -0.91354546f}, {0.39474386f, -0.91879121f}, - {0.38268343f, -0.92387953f}, {0.37055744f, -0.92880955f}, - {0.35836795f, -0.93358043f}, {0.34611706f, -0.93819134f}, - {0.33380686f, -0.94264149f}, {0.32143947f, -0.94693013f}, - {0.30901699f, -0.95105652f}, {0.29654157f, -0.95501994f}, - {0.28401534f, -0.95881973f}, {0.27144045f, -0.96245524f}, - {0.25881905f, -0.96592583f}, {0.24615329f, -0.96923091f}, - {0.23344536f, -0.97236992f}, {0.22069744f, -0.97534232f}, - {0.20791169f, -0.97814760f}, {0.19509032f, -0.98078528f}, - {0.18223553f, -0.98325491f}, {0.16934950f, -0.98555606f}, - {0.15643447f, -0.98768834f}, {0.14349262f, -0.98965139f}, - {0.13052619f, -0.99144486f}, {0.11753740f, -0.99306846f}, - {0.10452846f, -0.99452190f}, {0.091501619f, -0.99580493f}, - {0.078459096f, -0.99691733f}, {0.065403129f, -0.99785892f}, - {0.052335956f, -0.99862953f}, {0.039259816f, -0.99922904f}, - {0.026176948f, -0.99965732f}, {0.013089596f, -0.99991433f}, - {6.1230318e-17f, -1.0000000f}, {-0.013089596f, -0.99991433f}, - {-0.026176948f, -0.99965732f}, {-0.039259816f, -0.99922904f}, - {-0.052335956f, -0.99862953f}, {-0.065403129f, -0.99785892f}, - {-0.078459096f, -0.99691733f}, {-0.091501619f, -0.99580493f}, - {-0.10452846f, -0.99452190f}, {-0.11753740f, -0.99306846f}, - {-0.13052619f, -0.99144486f}, {-0.14349262f, -0.98965139f}, - {-0.15643447f, -0.98768834f}, {-0.16934950f, -0.98555606f}, - {-0.18223553f, -0.98325491f}, {-0.19509032f, -0.98078528f}, - {-0.20791169f, -0.97814760f}, {-0.22069744f, -0.97534232f}, - {-0.23344536f, -0.97236992f}, {-0.24615329f, -0.96923091f}, - {-0.25881905f, -0.96592583f}, {-0.27144045f, -0.96245524f}, - {-0.28401534f, -0.95881973f}, {-0.29654157f, -0.95501994f}, - {-0.30901699f, -0.95105652f}, {-0.32143947f, -0.94693013f}, - {-0.33380686f, -0.94264149f}, {-0.34611706f, -0.93819134f}, - {-0.35836795f, -0.93358043f}, {-0.37055744f, -0.92880955f}, - {-0.38268343f, -0.92387953f}, {-0.39474386f, -0.91879121f}, - {-0.40673664f, -0.91354546f}, {-0.41865974f, -0.90814317f}, - {-0.43051110f, -0.90258528f}, {-0.44228869f, -0.89687274f}, - {-0.45399050f, -0.89100652f}, {-0.46561452f, -0.88498764f}, - {-0.47715876f, -0.87881711f}, {-0.48862124f, -0.87249601f}, - {-0.50000000f, -0.86602540f}, {-0.51129309f, -0.85940641f}, - {-0.52249856f, -0.85264016f}, {-0.53361452f, -0.84572782f}, - {-0.54463904f, -0.83867057f}, {-0.55557023f, -0.83146961f}, - {-0.56640624f, -0.82412619f}, {-0.57714519f, -0.81664156f}, - {-0.58778525f, -0.80901699f}, {-0.59832460f, -0.80125381f}, - {-0.60876143f, -0.79335334f}, {-0.61909395f, -0.78531693f}, - {-0.62932039f, -0.77714596f}, {-0.63943900f, -0.76884183f}, - {-0.64944805f, -0.76040597f}, {-0.65934582f, -0.75183981f}, - {-0.66913061f, -0.74314483f}, {-0.67880075f, -0.73432251f}, - {-0.68835458f, -0.72537437f}, {-0.69779046f, -0.71630194f}, - {-0.70710678f, -0.70710678f}, {-0.71630194f, -0.69779046f}, - {-0.72537437f, -0.68835458f}, {-0.73432251f, -0.67880075f}, - {-0.74314483f, -0.66913061f}, {-0.75183981f, -0.65934582f}, - {-0.76040597f, -0.64944805f}, {-0.76884183f, -0.63943900f}, - {-0.77714596f, -0.62932039f}, {-0.78531693f, -0.61909395f}, - {-0.79335334f, -0.60876143f}, {-0.80125381f, -0.59832460f}, - {-0.80901699f, -0.58778525f}, {-0.81664156f, -0.57714519f}, - {-0.82412619f, -0.56640624f}, {-0.83146961f, -0.55557023f}, - {-0.83867057f, -0.54463904f}, {-0.84572782f, -0.53361452f}, - {-0.85264016f, -0.52249856f}, {-0.85940641f, -0.51129309f}, - {-0.86602540f, -0.50000000f}, {-0.87249601f, -0.48862124f}, - {-0.87881711f, -0.47715876f}, {-0.88498764f, -0.46561452f}, - {-0.89100652f, -0.45399050f}, {-0.89687274f, -0.44228869f}, - {-0.90258528f, -0.43051110f}, {-0.90814317f, -0.41865974f}, - {-0.91354546f, -0.40673664f}, {-0.91879121f, -0.39474386f}, - {-0.92387953f, -0.38268343f}, {-0.92880955f, -0.37055744f}, - {-0.93358043f, -0.35836795f}, {-0.93819134f, -0.34611706f}, - {-0.94264149f, -0.33380686f}, {-0.94693013f, -0.32143947f}, - {-0.95105652f, -0.30901699f}, {-0.95501994f, -0.29654157f}, - {-0.95881973f, -0.28401534f}, {-0.96245524f, -0.27144045f}, - {-0.96592583f, -0.25881905f}, {-0.96923091f, -0.24615329f}, - {-0.97236992f, -0.23344536f}, {-0.97534232f, -0.22069744f}, - {-0.97814760f, -0.20791169f}, {-0.98078528f, -0.19509032f}, - {-0.98325491f, -0.18223553f}, {-0.98555606f, -0.16934950f}, - {-0.98768834f, -0.15643447f}, {-0.98965139f, -0.14349262f}, - {-0.99144486f, -0.13052619f}, {-0.99306846f, -0.11753740f}, - {-0.99452190f, -0.10452846f}, {-0.99580493f, -0.091501619f}, - {-0.99691733f, -0.078459096f}, {-0.99785892f, -0.065403129f}, - {-0.99862953f, -0.052335956f}, {-0.99922904f, -0.039259816f}, - {-0.99965732f, -0.026176948f}, {-0.99991433f, -0.013089596f}, - {-1.0000000f, -1.2246064e-16f}, {-0.99991433f, 0.013089596f}, - {-0.99965732f, 0.026176948f}, {-0.99922904f, 0.039259816f}, - {-0.99862953f, 0.052335956f}, {-0.99785892f, 0.065403129f}, - {-0.99691733f, 0.078459096f}, {-0.99580493f, 0.091501619f}, - {-0.99452190f, 0.10452846f}, {-0.99306846f, 0.11753740f}, - {-0.99144486f, 0.13052619f}, {-0.98965139f, 0.14349262f}, - {-0.98768834f, 0.15643447f}, {-0.98555606f, 0.16934950f}, - {-0.98325491f, 0.18223553f}, {-0.98078528f, 0.19509032f}, - {-0.97814760f, 0.20791169f}, {-0.97534232f, 0.22069744f}, - {-0.97236992f, 0.23344536f}, {-0.96923091f, 0.24615329f}, - {-0.96592583f, 0.25881905f}, {-0.96245524f, 0.27144045f}, - {-0.95881973f, 0.28401534f}, {-0.95501994f, 0.29654157f}, - {-0.95105652f, 0.30901699f}, {-0.94693013f, 0.32143947f}, - {-0.94264149f, 0.33380686f}, {-0.93819134f, 0.34611706f}, - {-0.93358043f, 0.35836795f}, {-0.92880955f, 0.37055744f}, - {-0.92387953f, 0.38268343f}, {-0.91879121f, 0.39474386f}, - {-0.91354546f, 0.40673664f}, {-0.90814317f, 0.41865974f}, - {-0.90258528f, 0.43051110f}, {-0.89687274f, 0.44228869f}, - {-0.89100652f, 0.45399050f}, {-0.88498764f, 0.46561452f}, - {-0.87881711f, 0.47715876f}, {-0.87249601f, 0.48862124f}, - {-0.86602540f, 0.50000000f}, {-0.85940641f, 0.51129309f}, - {-0.85264016f, 0.52249856f}, {-0.84572782f, 0.53361452f}, - {-0.83867057f, 0.54463904f}, {-0.83146961f, 0.55557023f}, - {-0.82412619f, 0.56640624f}, {-0.81664156f, 0.57714519f}, - {-0.80901699f, 0.58778525f}, {-0.80125381f, 0.59832460f}, - {-0.79335334f, 0.60876143f}, {-0.78531693f, 0.61909395f}, - {-0.77714596f, 0.62932039f}, {-0.76884183f, 0.63943900f}, - {-0.76040597f, 0.64944805f}, {-0.75183981f, 0.65934582f}, - {-0.74314483f, 0.66913061f}, {-0.73432251f, 0.67880075f}, - {-0.72537437f, 0.68835458f}, {-0.71630194f, 0.69779046f}, - {-0.70710678f, 0.70710678f}, {-0.69779046f, 0.71630194f}, - {-0.68835458f, 0.72537437f}, {-0.67880075f, 0.73432251f}, - {-0.66913061f, 0.74314483f}, {-0.65934582f, 0.75183981f}, - {-0.64944805f, 0.76040597f}, {-0.63943900f, 0.76884183f}, - {-0.62932039f, 0.77714596f}, {-0.61909395f, 0.78531693f}, - {-0.60876143f, 0.79335334f}, {-0.59832460f, 0.80125381f}, - {-0.58778525f, 0.80901699f}, {-0.57714519f, 0.81664156f}, - {-0.56640624f, 0.82412619f}, {-0.55557023f, 0.83146961f}, - {-0.54463904f, 0.83867057f}, {-0.53361452f, 0.84572782f}, - {-0.52249856f, 0.85264016f}, {-0.51129309f, 0.85940641f}, - {-0.50000000f, 0.86602540f}, {-0.48862124f, 0.87249601f}, - {-0.47715876f, 0.87881711f}, {-0.46561452f, 0.88498764f}, - {-0.45399050f, 0.89100652f}, {-0.44228869f, 0.89687274f}, - {-0.43051110f, 0.90258528f}, {-0.41865974f, 0.90814317f}, - {-0.40673664f, 0.91354546f}, {-0.39474386f, 0.91879121f}, - {-0.38268343f, 0.92387953f}, {-0.37055744f, 0.92880955f}, - {-0.35836795f, 0.93358043f}, {-0.34611706f, 0.93819134f}, - {-0.33380686f, 0.94264149f}, {-0.32143947f, 0.94693013f}, - {-0.30901699f, 0.95105652f}, {-0.29654157f, 0.95501994f}, - {-0.28401534f, 0.95881973f}, {-0.27144045f, 0.96245524f}, - {-0.25881905f, 0.96592583f}, {-0.24615329f, 0.96923091f}, - {-0.23344536f, 0.97236992f}, {-0.22069744f, 0.97534232f}, - {-0.20791169f, 0.97814760f}, {-0.19509032f, 0.98078528f}, - {-0.18223553f, 0.98325491f}, {-0.16934950f, 0.98555606f}, - {-0.15643447f, 0.98768834f}, {-0.14349262f, 0.98965139f}, - {-0.13052619f, 0.99144486f}, {-0.11753740f, 0.99306846f}, - {-0.10452846f, 0.99452190f}, {-0.091501619f, 0.99580493f}, - {-0.078459096f, 0.99691733f}, {-0.065403129f, 0.99785892f}, - {-0.052335956f, 0.99862953f}, {-0.039259816f, 0.99922904f}, - {-0.026176948f, 0.99965732f}, {-0.013089596f, 0.99991433f}, - {-1.8369095e-16f, 1.0000000f}, {0.013089596f, 0.99991433f}, - {0.026176948f, 0.99965732f}, {0.039259816f, 0.99922904f}, - {0.052335956f, 0.99862953f}, {0.065403129f, 0.99785892f}, - {0.078459096f, 0.99691733f}, {0.091501619f, 0.99580493f}, - {0.10452846f, 0.99452190f}, {0.11753740f, 0.99306846f}, - {0.13052619f, 0.99144486f}, {0.14349262f, 0.98965139f}, - {0.15643447f, 0.98768834f}, {0.16934950f, 0.98555606f}, - {0.18223553f, 0.98325491f}, {0.19509032f, 0.98078528f}, - {0.20791169f, 0.97814760f}, {0.22069744f, 0.97534232f}, - {0.23344536f, 0.97236992f}, {0.24615329f, 0.96923091f}, - {0.25881905f, 0.96592583f}, {0.27144045f, 0.96245524f}, - {0.28401534f, 0.95881973f}, {0.29654157f, 0.95501994f}, - {0.30901699f, 0.95105652f}, {0.32143947f, 0.94693013f}, - {0.33380686f, 0.94264149f}, {0.34611706f, 0.93819134f}, - {0.35836795f, 0.93358043f}, {0.37055744f, 0.92880955f}, - {0.38268343f, 0.92387953f}, {0.39474386f, 0.91879121f}, - {0.40673664f, 0.91354546f}, {0.41865974f, 0.90814317f}, - {0.43051110f, 0.90258528f}, {0.44228869f, 0.89687274f}, - {0.45399050f, 0.89100652f}, {0.46561452f, 0.88498764f}, - {0.47715876f, 0.87881711f}, {0.48862124f, 0.87249601f}, - {0.50000000f, 0.86602540f}, {0.51129309f, 0.85940641f}, - {0.52249856f, 0.85264016f}, {0.53361452f, 0.84572782f}, - {0.54463904f, 0.83867057f}, {0.55557023f, 0.83146961f}, - {0.56640624f, 0.82412619f}, {0.57714519f, 0.81664156f}, - {0.58778525f, 0.80901699f}, {0.59832460f, 0.80125381f}, - {0.60876143f, 0.79335334f}, {0.61909395f, 0.78531693f}, - {0.62932039f, 0.77714596f}, {0.63943900f, 0.76884183f}, - {0.64944805f, 0.76040597f}, {0.65934582f, 0.75183981f}, - {0.66913061f, 0.74314483f}, {0.67880075f, 0.73432251f}, - {0.68835458f, 0.72537437f}, {0.69779046f, 0.71630194f}, - {0.70710678f, 0.70710678f}, {0.71630194f, 0.69779046f}, - {0.72537437f, 0.68835458f}, {0.73432251f, 0.67880075f}, - {0.74314483f, 0.66913061f}, {0.75183981f, 0.65934582f}, - {0.76040597f, 0.64944805f}, {0.76884183f, 0.63943900f}, - {0.77714596f, 0.62932039f}, {0.78531693f, 0.61909395f}, - {0.79335334f, 0.60876143f}, {0.80125381f, 0.59832460f}, - {0.80901699f, 0.58778525f}, {0.81664156f, 0.57714519f}, - {0.82412619f, 0.56640624f}, {0.83146961f, 0.55557023f}, - {0.83867057f, 0.54463904f}, {0.84572782f, 0.53361452f}, - {0.85264016f, 0.52249856f}, {0.85940641f, 0.51129309f}, - {0.86602540f, 0.50000000f}, {0.87249601f, 0.48862124f}, - {0.87881711f, 0.47715876f}, {0.88498764f, 0.46561452f}, - {0.89100652f, 0.45399050f}, {0.89687274f, 0.44228869f}, - {0.90258528f, 0.43051110f}, {0.90814317f, 0.41865974f}, - {0.91354546f, 0.40673664f}, {0.91879121f, 0.39474386f}, - {0.92387953f, 0.38268343f}, {0.92880955f, 0.37055744f}, - {0.93358043f, 0.35836795f}, {0.93819134f, 0.34611706f}, - {0.94264149f, 0.33380686f}, {0.94693013f, 0.32143947f}, - {0.95105652f, 0.30901699f}, {0.95501994f, 0.29654157f}, - {0.95881973f, 0.28401534f}, {0.96245524f, 0.27144045f}, - {0.96592583f, 0.25881905f}, {0.96923091f, 0.24615329f}, - {0.97236992f, 0.23344536f}, {0.97534232f, 0.22069744f}, - {0.97814760f, 0.20791169f}, {0.98078528f, 0.19509032f}, - {0.98325491f, 0.18223553f}, {0.98555606f, 0.16934950f}, - {0.98768834f, 0.15643447f}, {0.98965139f, 0.14349262f}, - {0.99144486f, 0.13052619f}, {0.99306846f, 0.11753740f}, - {0.99452190f, 0.10452846f}, {0.99580493f, 0.091501619f}, - {0.99691733f, 0.078459096f}, {0.99785892f, 0.065403129f}, - {0.99862953f, 0.052335956f}, {0.99922904f, 0.039259816f}, - {0.99965732f, 0.026176948f}, {0.99991433f, 0.013089596f}, +{1.0000000f, -0.0000000f}, {0.99991433f, -0.013089596f}, +{0.99965732f, -0.026176948f}, {0.99922904f, -0.039259816f}, +{0.99862953f, -0.052335956f}, {0.99785892f, -0.065403129f}, +{0.99691733f, -0.078459096f}, {0.99580493f, -0.091501619f}, +{0.99452190f, -0.10452846f}, {0.99306846f, -0.11753740f}, +{0.99144486f, -0.13052619f}, {0.98965139f, -0.14349262f}, +{0.98768834f, -0.15643447f}, {0.98555606f, -0.16934950f}, +{0.98325491f, -0.18223553f}, {0.98078528f, -0.19509032f}, +{0.97814760f, -0.20791169f}, {0.97534232f, -0.22069744f}, +{0.97236992f, -0.23344536f}, {0.96923091f, -0.24615329f}, +{0.96592583f, -0.25881905f}, {0.96245524f, -0.27144045f}, +{0.95881973f, -0.28401534f}, {0.95501994f, -0.29654157f}, +{0.95105652f, -0.30901699f}, {0.94693013f, -0.32143947f}, +{0.94264149f, -0.33380686f}, {0.93819134f, -0.34611706f}, +{0.93358043f, -0.35836795f}, {0.92880955f, -0.37055744f}, +{0.92387953f, -0.38268343f}, {0.91879121f, -0.39474386f}, +{0.91354546f, -0.40673664f}, {0.90814317f, -0.41865974f}, +{0.90258528f, -0.43051110f}, {0.89687274f, -0.44228869f}, +{0.89100652f, -0.45399050f}, {0.88498764f, -0.46561452f}, +{0.87881711f, -0.47715876f}, {0.87249601f, -0.48862124f}, +{0.86602540f, -0.50000000f}, {0.85940641f, -0.51129309f}, +{0.85264016f, -0.52249856f}, {0.84572782f, -0.53361452f}, +{0.83867057f, -0.54463904f}, {0.83146961f, -0.55557023f}, +{0.82412619f, -0.56640624f}, {0.81664156f, -0.57714519f}, +{0.80901699f, -0.58778525f}, {0.80125381f, -0.59832460f}, +{0.79335334f, -0.60876143f}, {0.78531693f, -0.61909395f}, +{0.77714596f, -0.62932039f}, {0.76884183f, -0.63943900f}, +{0.76040597f, -0.64944805f}, {0.75183981f, -0.65934582f}, +{0.74314483f, -0.66913061f}, {0.73432251f, -0.67880075f}, +{0.72537437f, -0.68835458f}, {0.71630194f, -0.69779046f}, +{0.70710678f, -0.70710678f}, {0.69779046f, -0.71630194f}, +{0.68835458f, -0.72537437f}, {0.67880075f, -0.73432251f}, +{0.66913061f, -0.74314483f}, {0.65934582f, -0.75183981f}, +{0.64944805f, -0.76040597f}, {0.63943900f, -0.76884183f}, +{0.62932039f, -0.77714596f}, {0.61909395f, -0.78531693f}, +{0.60876143f, -0.79335334f}, {0.59832460f, -0.80125381f}, +{0.58778525f, -0.80901699f}, {0.57714519f, -0.81664156f}, +{0.56640624f, -0.82412619f}, {0.55557023f, -0.83146961f}, +{0.54463904f, -0.83867057f}, {0.53361452f, -0.84572782f}, +{0.52249856f, -0.85264016f}, {0.51129309f, -0.85940641f}, +{0.50000000f, -0.86602540f}, {0.48862124f, -0.87249601f}, +{0.47715876f, -0.87881711f}, {0.46561452f, -0.88498764f}, +{0.45399050f, -0.89100652f}, {0.44228869f, -0.89687274f}, +{0.43051110f, -0.90258528f}, {0.41865974f, -0.90814317f}, +{0.40673664f, -0.91354546f}, {0.39474386f, -0.91879121f}, +{0.38268343f, -0.92387953f}, {0.37055744f, -0.92880955f}, +{0.35836795f, -0.93358043f}, {0.34611706f, -0.93819134f}, +{0.33380686f, -0.94264149f}, {0.32143947f, -0.94693013f}, +{0.30901699f, -0.95105652f}, {0.29654157f, -0.95501994f}, +{0.28401534f, -0.95881973f}, {0.27144045f, -0.96245524f}, +{0.25881905f, -0.96592583f}, {0.24615329f, -0.96923091f}, +{0.23344536f, -0.97236992f}, {0.22069744f, -0.97534232f}, +{0.20791169f, -0.97814760f}, {0.19509032f, -0.98078528f}, +{0.18223553f, -0.98325491f}, {0.16934950f, -0.98555606f}, +{0.15643447f, -0.98768834f}, {0.14349262f, -0.98965139f}, +{0.13052619f, -0.99144486f}, {0.11753740f, -0.99306846f}, +{0.10452846f, -0.99452190f}, {0.091501619f, -0.99580493f}, +{0.078459096f, -0.99691733f}, {0.065403129f, -0.99785892f}, +{0.052335956f, -0.99862953f}, {0.039259816f, -0.99922904f}, +{0.026176948f, -0.99965732f}, {0.013089596f, -0.99991433f}, +{6.1230318e-17f, -1.0000000f}, {-0.013089596f, -0.99991433f}, +{-0.026176948f, -0.99965732f}, {-0.039259816f, -0.99922904f}, +{-0.052335956f, -0.99862953f}, {-0.065403129f, -0.99785892f}, +{-0.078459096f, -0.99691733f}, {-0.091501619f, -0.99580493f}, +{-0.10452846f, -0.99452190f}, {-0.11753740f, -0.99306846f}, +{-0.13052619f, -0.99144486f}, {-0.14349262f, -0.98965139f}, +{-0.15643447f, -0.98768834f}, {-0.16934950f, -0.98555606f}, +{-0.18223553f, -0.98325491f}, {-0.19509032f, -0.98078528f}, +{-0.20791169f, -0.97814760f}, {-0.22069744f, -0.97534232f}, +{-0.23344536f, -0.97236992f}, {-0.24615329f, -0.96923091f}, +{-0.25881905f, -0.96592583f}, {-0.27144045f, -0.96245524f}, +{-0.28401534f, -0.95881973f}, {-0.29654157f, -0.95501994f}, +{-0.30901699f, -0.95105652f}, {-0.32143947f, -0.94693013f}, +{-0.33380686f, -0.94264149f}, {-0.34611706f, -0.93819134f}, +{-0.35836795f, -0.93358043f}, {-0.37055744f, -0.92880955f}, +{-0.38268343f, -0.92387953f}, {-0.39474386f, -0.91879121f}, +{-0.40673664f, -0.91354546f}, {-0.41865974f, -0.90814317f}, +{-0.43051110f, -0.90258528f}, {-0.44228869f, -0.89687274f}, +{-0.45399050f, -0.89100652f}, {-0.46561452f, -0.88498764f}, +{-0.47715876f, -0.87881711f}, {-0.48862124f, -0.87249601f}, +{-0.50000000f, -0.86602540f}, {-0.51129309f, -0.85940641f}, +{-0.52249856f, -0.85264016f}, {-0.53361452f, -0.84572782f}, +{-0.54463904f, -0.83867057f}, {-0.55557023f, -0.83146961f}, +{-0.56640624f, -0.82412619f}, {-0.57714519f, -0.81664156f}, +{-0.58778525f, -0.80901699f}, {-0.59832460f, -0.80125381f}, +{-0.60876143f, -0.79335334f}, {-0.61909395f, -0.78531693f}, +{-0.62932039f, -0.77714596f}, {-0.63943900f, -0.76884183f}, +{-0.64944805f, -0.76040597f}, {-0.65934582f, -0.75183981f}, +{-0.66913061f, -0.74314483f}, {-0.67880075f, -0.73432251f}, +{-0.68835458f, -0.72537437f}, {-0.69779046f, -0.71630194f}, +{-0.70710678f, -0.70710678f}, {-0.71630194f, -0.69779046f}, +{-0.72537437f, -0.68835458f}, {-0.73432251f, -0.67880075f}, +{-0.74314483f, -0.66913061f}, {-0.75183981f, -0.65934582f}, +{-0.76040597f, -0.64944805f}, {-0.76884183f, -0.63943900f}, +{-0.77714596f, -0.62932039f}, {-0.78531693f, -0.61909395f}, +{-0.79335334f, -0.60876143f}, {-0.80125381f, -0.59832460f}, +{-0.80901699f, -0.58778525f}, {-0.81664156f, -0.57714519f}, +{-0.82412619f, -0.56640624f}, {-0.83146961f, -0.55557023f}, +{-0.83867057f, -0.54463904f}, {-0.84572782f, -0.53361452f}, +{-0.85264016f, -0.52249856f}, {-0.85940641f, -0.51129309f}, +{-0.86602540f, -0.50000000f}, {-0.87249601f, -0.48862124f}, +{-0.87881711f, -0.47715876f}, {-0.88498764f, -0.46561452f}, +{-0.89100652f, -0.45399050f}, {-0.89687274f, -0.44228869f}, +{-0.90258528f, -0.43051110f}, {-0.90814317f, -0.41865974f}, +{-0.91354546f, -0.40673664f}, {-0.91879121f, -0.39474386f}, +{-0.92387953f, -0.38268343f}, {-0.92880955f, -0.37055744f}, +{-0.93358043f, -0.35836795f}, {-0.93819134f, -0.34611706f}, +{-0.94264149f, -0.33380686f}, {-0.94693013f, -0.32143947f}, +{-0.95105652f, -0.30901699f}, {-0.95501994f, -0.29654157f}, +{-0.95881973f, -0.28401534f}, {-0.96245524f, -0.27144045f}, +{-0.96592583f, -0.25881905f}, {-0.96923091f, -0.24615329f}, +{-0.97236992f, -0.23344536f}, {-0.97534232f, -0.22069744f}, +{-0.97814760f, -0.20791169f}, {-0.98078528f, -0.19509032f}, +{-0.98325491f, -0.18223553f}, {-0.98555606f, -0.16934950f}, +{-0.98768834f, -0.15643447f}, {-0.98965139f, -0.14349262f}, +{-0.99144486f, -0.13052619f}, {-0.99306846f, -0.11753740f}, +{-0.99452190f, -0.10452846f}, {-0.99580493f, -0.091501619f}, +{-0.99691733f, -0.078459096f}, {-0.99785892f, -0.065403129f}, +{-0.99862953f, -0.052335956f}, {-0.99922904f, -0.039259816f}, +{-0.99965732f, -0.026176948f}, {-0.99991433f, -0.013089596f}, +{-1.0000000f, -1.2246064e-16f}, {-0.99991433f, 0.013089596f}, +{-0.99965732f, 0.026176948f}, {-0.99922904f, 0.039259816f}, +{-0.99862953f, 0.052335956f}, {-0.99785892f, 0.065403129f}, +{-0.99691733f, 0.078459096f}, {-0.99580493f, 0.091501619f}, +{-0.99452190f, 0.10452846f}, {-0.99306846f, 0.11753740f}, +{-0.99144486f, 0.13052619f}, {-0.98965139f, 0.14349262f}, +{-0.98768834f, 0.15643447f}, {-0.98555606f, 0.16934950f}, +{-0.98325491f, 0.18223553f}, {-0.98078528f, 0.19509032f}, +{-0.97814760f, 0.20791169f}, {-0.97534232f, 0.22069744f}, +{-0.97236992f, 0.23344536f}, {-0.96923091f, 0.24615329f}, +{-0.96592583f, 0.25881905f}, {-0.96245524f, 0.27144045f}, +{-0.95881973f, 0.28401534f}, {-0.95501994f, 0.29654157f}, +{-0.95105652f, 0.30901699f}, {-0.94693013f, 0.32143947f}, +{-0.94264149f, 0.33380686f}, {-0.93819134f, 0.34611706f}, +{-0.93358043f, 0.35836795f}, {-0.92880955f, 0.37055744f}, +{-0.92387953f, 0.38268343f}, {-0.91879121f, 0.39474386f}, +{-0.91354546f, 0.40673664f}, {-0.90814317f, 0.41865974f}, +{-0.90258528f, 0.43051110f}, {-0.89687274f, 0.44228869f}, +{-0.89100652f, 0.45399050f}, {-0.88498764f, 0.46561452f}, +{-0.87881711f, 0.47715876f}, {-0.87249601f, 0.48862124f}, +{-0.86602540f, 0.50000000f}, {-0.85940641f, 0.51129309f}, +{-0.85264016f, 0.52249856f}, {-0.84572782f, 0.53361452f}, +{-0.83867057f, 0.54463904f}, {-0.83146961f, 0.55557023f}, +{-0.82412619f, 0.56640624f}, {-0.81664156f, 0.57714519f}, +{-0.80901699f, 0.58778525f}, {-0.80125381f, 0.59832460f}, +{-0.79335334f, 0.60876143f}, {-0.78531693f, 0.61909395f}, +{-0.77714596f, 0.62932039f}, {-0.76884183f, 0.63943900f}, +{-0.76040597f, 0.64944805f}, {-0.75183981f, 0.65934582f}, +{-0.74314483f, 0.66913061f}, {-0.73432251f, 0.67880075f}, +{-0.72537437f, 0.68835458f}, {-0.71630194f, 0.69779046f}, +{-0.70710678f, 0.70710678f}, {-0.69779046f, 0.71630194f}, +{-0.68835458f, 0.72537437f}, {-0.67880075f, 0.73432251f}, +{-0.66913061f, 0.74314483f}, {-0.65934582f, 0.75183981f}, +{-0.64944805f, 0.76040597f}, {-0.63943900f, 0.76884183f}, +{-0.62932039f, 0.77714596f}, {-0.61909395f, 0.78531693f}, +{-0.60876143f, 0.79335334f}, {-0.59832460f, 0.80125381f}, +{-0.58778525f, 0.80901699f}, {-0.57714519f, 0.81664156f}, +{-0.56640624f, 0.82412619f}, {-0.55557023f, 0.83146961f}, +{-0.54463904f, 0.83867057f}, {-0.53361452f, 0.84572782f}, +{-0.52249856f, 0.85264016f}, {-0.51129309f, 0.85940641f}, +{-0.50000000f, 0.86602540f}, {-0.48862124f, 0.87249601f}, +{-0.47715876f, 0.87881711f}, {-0.46561452f, 0.88498764f}, +{-0.45399050f, 0.89100652f}, {-0.44228869f, 0.89687274f}, +{-0.43051110f, 0.90258528f}, {-0.41865974f, 0.90814317f}, +{-0.40673664f, 0.91354546f}, {-0.39474386f, 0.91879121f}, +{-0.38268343f, 0.92387953f}, {-0.37055744f, 0.92880955f}, +{-0.35836795f, 0.93358043f}, {-0.34611706f, 0.93819134f}, +{-0.33380686f, 0.94264149f}, {-0.32143947f, 0.94693013f}, +{-0.30901699f, 0.95105652f}, {-0.29654157f, 0.95501994f}, +{-0.28401534f, 0.95881973f}, {-0.27144045f, 0.96245524f}, +{-0.25881905f, 0.96592583f}, {-0.24615329f, 0.96923091f}, +{-0.23344536f, 0.97236992f}, {-0.22069744f, 0.97534232f}, +{-0.20791169f, 0.97814760f}, {-0.19509032f, 0.98078528f}, +{-0.18223553f, 0.98325491f}, {-0.16934950f, 0.98555606f}, +{-0.15643447f, 0.98768834f}, {-0.14349262f, 0.98965139f}, +{-0.13052619f, 0.99144486f}, {-0.11753740f, 0.99306846f}, +{-0.10452846f, 0.99452190f}, {-0.091501619f, 0.99580493f}, +{-0.078459096f, 0.99691733f}, {-0.065403129f, 0.99785892f}, +{-0.052335956f, 0.99862953f}, {-0.039259816f, 0.99922904f}, +{-0.026176948f, 0.99965732f}, {-0.013089596f, 0.99991433f}, +{-1.8369095e-16f, 1.0000000f}, {0.013089596f, 0.99991433f}, +{0.026176948f, 0.99965732f}, {0.039259816f, 0.99922904f}, +{0.052335956f, 0.99862953f}, {0.065403129f, 0.99785892f}, +{0.078459096f, 0.99691733f}, {0.091501619f, 0.99580493f}, +{0.10452846f, 0.99452190f}, {0.11753740f, 0.99306846f}, +{0.13052619f, 0.99144486f}, {0.14349262f, 0.98965139f}, +{0.15643447f, 0.98768834f}, {0.16934950f, 0.98555606f}, +{0.18223553f, 0.98325491f}, {0.19509032f, 0.98078528f}, +{0.20791169f, 0.97814760f}, {0.22069744f, 0.97534232f}, +{0.23344536f, 0.97236992f}, {0.24615329f, 0.96923091f}, +{0.25881905f, 0.96592583f}, {0.27144045f, 0.96245524f}, +{0.28401534f, 0.95881973f}, {0.29654157f, 0.95501994f}, +{0.30901699f, 0.95105652f}, {0.32143947f, 0.94693013f}, +{0.33380686f, 0.94264149f}, {0.34611706f, 0.93819134f}, +{0.35836795f, 0.93358043f}, {0.37055744f, 0.92880955f}, +{0.38268343f, 0.92387953f}, {0.39474386f, 0.91879121f}, +{0.40673664f, 0.91354546f}, {0.41865974f, 0.90814317f}, +{0.43051110f, 0.90258528f}, {0.44228869f, 0.89687274f}, +{0.45399050f, 0.89100652f}, {0.46561452f, 0.88498764f}, +{0.47715876f, 0.87881711f}, {0.48862124f, 0.87249601f}, +{0.50000000f, 0.86602540f}, {0.51129309f, 0.85940641f}, +{0.52249856f, 0.85264016f}, {0.53361452f, 0.84572782f}, +{0.54463904f, 0.83867057f}, {0.55557023f, 0.83146961f}, +{0.56640624f, 0.82412619f}, {0.57714519f, 0.81664156f}, +{0.58778525f, 0.80901699f}, {0.59832460f, 0.80125381f}, +{0.60876143f, 0.79335334f}, {0.61909395f, 0.78531693f}, +{0.62932039f, 0.77714596f}, {0.63943900f, 0.76884183f}, +{0.64944805f, 0.76040597f}, {0.65934582f, 0.75183981f}, +{0.66913061f, 0.74314483f}, {0.67880075f, 0.73432251f}, +{0.68835458f, 0.72537437f}, {0.69779046f, 0.71630194f}, +{0.70710678f, 0.70710678f}, {0.71630194f, 0.69779046f}, +{0.72537437f, 0.68835458f}, {0.73432251f, 0.67880075f}, +{0.74314483f, 0.66913061f}, {0.75183981f, 0.65934582f}, +{0.76040597f, 0.64944805f}, {0.76884183f, 0.63943900f}, +{0.77714596f, 0.62932039f}, {0.78531693f, 0.61909395f}, +{0.79335334f, 0.60876143f}, {0.80125381f, 0.59832460f}, +{0.80901699f, 0.58778525f}, {0.81664156f, 0.57714519f}, +{0.82412619f, 0.56640624f}, {0.83146961f, 0.55557023f}, +{0.83867057f, 0.54463904f}, {0.84572782f, 0.53361452f}, +{0.85264016f, 0.52249856f}, {0.85940641f, 0.51129309f}, +{0.86602540f, 0.50000000f}, {0.87249601f, 0.48862124f}, +{0.87881711f, 0.47715876f}, {0.88498764f, 0.46561452f}, +{0.89100652f, 0.45399050f}, {0.89687274f, 0.44228869f}, +{0.90258528f, 0.43051110f}, {0.90814317f, 0.41865974f}, +{0.91354546f, 0.40673664f}, {0.91879121f, 0.39474386f}, +{0.92387953f, 0.38268343f}, {0.92880955f, 0.37055744f}, +{0.93358043f, 0.35836795f}, {0.93819134f, 0.34611706f}, +{0.94264149f, 0.33380686f}, {0.94693013f, 0.32143947f}, +{0.95105652f, 0.30901699f}, {0.95501994f, 0.29654157f}, +{0.95881973f, 0.28401534f}, {0.96245524f, 0.27144045f}, +{0.96592583f, 0.25881905f}, {0.96923091f, 0.24615329f}, +{0.97236992f, 0.23344536f}, {0.97534232f, 0.22069744f}, +{0.97814760f, 0.20791169f}, {0.98078528f, 0.19509032f}, +{0.98325491f, 0.18223553f}, {0.98555606f, 0.16934950f}, +{0.98768834f, 0.15643447f}, {0.98965139f, 0.14349262f}, +{0.99144486f, 0.13052619f}, {0.99306846f, 0.11753740f}, +{0.99452190f, 0.10452846f}, {0.99580493f, 0.091501619f}, +{0.99691733f, 0.078459096f}, {0.99785892f, 0.065403129f}, +{0.99862953f, 0.052335956f}, {0.99922904f, 0.039259816f}, +{0.99965732f, 0.026176948f}, {0.99991433f, 0.013089596f}, }; #ifndef FFT_BITREV480 #define FFT_BITREV480 static const opus_int16 fft_bitrev480[480] = { - 0, 96, 192, 288, 384, 32, 128, 224, 320, 416, 64, 160, 256, 352, 448, - 8, 104, 200, 296, 392, 40, 136, 232, 328, 424, 72, 168, 264, 360, 456, - 16, 112, 208, 304, 400, 48, 144, 240, 336, 432, 80, 176, 272, 368, 464, - 24, 120, 216, 312, 408, 56, 152, 248, 344, 440, 88, 184, 280, 376, 472, - 4, 100, 196, 292, 388, 36, 132, 228, 324, 420, 68, 164, 260, 356, 452, - 12, 108, 204, 300, 396, 44, 140, 236, 332, 428, 76, 172, 268, 364, 460, - 20, 116, 212, 308, 404, 52, 148, 244, 340, 436, 84, 180, 276, 372, 468, - 28, 124, 220, 316, 412, 60, 156, 252, 348, 444, 92, 188, 284, 380, 476, - 1, 97, 193, 289, 385, 33, 129, 225, 321, 417, 65, 161, 257, 353, 449, - 9, 105, 201, 297, 393, 41, 137, 233, 329, 425, 73, 169, 265, 361, 457, - 17, 113, 209, 305, 401, 49, 145, 241, 337, 433, 81, 177, 273, 369, 465, - 25, 121, 217, 313, 409, 57, 153, 249, 345, 441, 89, 185, 281, 377, 473, - 5, 101, 197, 293, 389, 37, 133, 229, 325, 421, 69, 165, 261, 357, 453, - 13, 109, 205, 301, 397, 45, 141, 237, 333, 429, 77, 173, 269, 365, 461, - 21, 117, 213, 309, 405, 53, 149, 245, 341, 437, 85, 181, 277, 373, 469, - 29, 125, 221, 317, 413, 61, 157, 253, 349, 445, 93, 189, 285, 381, 477, - 2, 98, 194, 290, 386, 34, 130, 226, 322, 418, 66, 162, 258, 354, 450, - 10, 106, 202, 298, 394, 42, 138, 234, 330, 426, 74, 170, 266, 362, 458, - 18, 114, 210, 306, 402, 50, 146, 242, 338, 434, 82, 178, 274, 370, 466, - 26, 122, 218, 314, 410, 58, 154, 250, 346, 442, 90, 186, 282, 378, 474, - 6, 102, 198, 294, 390, 38, 134, 230, 326, 422, 70, 166, 262, 358, 454, - 14, 110, 206, 302, 398, 46, 142, 238, 334, 430, 78, 174, 270, 366, 462, - 22, 118, 214, 310, 406, 54, 150, 246, 342, 438, 86, 182, 278, 374, 470, - 30, 126, 222, 318, 414, 62, 158, 254, 350, 446, 94, 190, 286, 382, 478, - 3, 99, 195, 291, 387, 35, 131, 227, 323, 419, 67, 163, 259, 355, 451, - 11, 107, 203, 299, 395, 43, 139, 235, 331, 427, 75, 171, 267, 363, 459, - 19, 115, 211, 307, 403, 51, 147, 243, 339, 435, 83, 179, 275, 371, 467, - 27, 123, 219, 315, 411, 59, 155, 251, 347, 443, 91, 187, 283, 379, 475, - 7, 103, 199, 295, 391, 39, 135, 231, 327, 423, 71, 167, 263, 359, 455, - 15, 111, 207, 303, 399, 47, 143, 239, 335, 431, 79, 175, 271, 367, 463, - 23, 119, 215, 311, 407, 55, 151, 247, 343, 439, 87, 183, 279, 375, 471, - 31, 127, 223, 319, 415, 63, 159, 255, 351, 447, 95, 191, 287, 383, 479, +0, 96, 192, 288, 384, 32, 128, 224, 320, 416, 64, 160, 256, 352, 448, +8, 104, 200, 296, 392, 40, 136, 232, 328, 424, 72, 168, 264, 360, 456, +16, 112, 208, 304, 400, 48, 144, 240, 336, 432, 80, 176, 272, 368, 464, +24, 120, 216, 312, 408, 56, 152, 248, 344, 440, 88, 184, 280, 376, 472, +4, 100, 196, 292, 388, 36, 132, 228, 324, 420, 68, 164, 260, 356, 452, +12, 108, 204, 300, 396, 44, 140, 236, 332, 428, 76, 172, 268, 364, 460, +20, 116, 212, 308, 404, 52, 148, 244, 340, 436, 84, 180, 276, 372, 468, +28, 124, 220, 316, 412, 60, 156, 252, 348, 444, 92, 188, 284, 380, 476, +1, 97, 193, 289, 385, 33, 129, 225, 321, 417, 65, 161, 257, 353, 449, +9, 105, 201, 297, 393, 41, 137, 233, 329, 425, 73, 169, 265, 361, 457, +17, 113, 209, 305, 401, 49, 145, 241, 337, 433, 81, 177, 273, 369, 465, +25, 121, 217, 313, 409, 57, 153, 249, 345, 441, 89, 185, 281, 377, 473, +5, 101, 197, 293, 389, 37, 133, 229, 325, 421, 69, 165, 261, 357, 453, +13, 109, 205, 301, 397, 45, 141, 237, 333, 429, 77, 173, 269, 365, 461, +21, 117, 213, 309, 405, 53, 149, 245, 341, 437, 85, 181, 277, 373, 469, +29, 125, 221, 317, 413, 61, 157, 253, 349, 445, 93, 189, 285, 381, 477, +2, 98, 194, 290, 386, 34, 130, 226, 322, 418, 66, 162, 258, 354, 450, +10, 106, 202, 298, 394, 42, 138, 234, 330, 426, 74, 170, 266, 362, 458, +18, 114, 210, 306, 402, 50, 146, 242, 338, 434, 82, 178, 274, 370, 466, +26, 122, 218, 314, 410, 58, 154, 250, 346, 442, 90, 186, 282, 378, 474, +6, 102, 198, 294, 390, 38, 134, 230, 326, 422, 70, 166, 262, 358, 454, +14, 110, 206, 302, 398, 46, 142, 238, 334, 430, 78, 174, 270, 366, 462, +22, 118, 214, 310, 406, 54, 150, 246, 342, 438, 86, 182, 278, 374, 470, +30, 126, 222, 318, 414, 62, 158, 254, 350, 446, 94, 190, 286, 382, 478, +3, 99, 195, 291, 387, 35, 131, 227, 323, 419, 67, 163, 259, 355, 451, +11, 107, 203, 299, 395, 43, 139, 235, 331, 427, 75, 171, 267, 363, 459, +19, 115, 211, 307, 403, 51, 147, 243, 339, 435, 83, 179, 275, 371, 467, +27, 123, 219, 315, 411, 59, 155, 251, 347, 443, 91, 187, 283, 379, 475, +7, 103, 199, 295, 391, 39, 135, 231, 327, 423, 71, 167, 263, 359, 455, +15, 111, 207, 303, 399, 47, 143, 239, 335, 431, 79, 175, 271, 367, 463, +23, 119, 215, 311, 407, 55, 151, 247, 343, 439, 87, 183, 279, 375, 471, +31, 127, 223, 319, 415, 63, 159, 255, 351, 447, 95, 191, 287, 383, 479, }; #endif #ifndef FFT_BITREV240 #define FFT_BITREV240 static const opus_int16 fft_bitrev240[240] = { - 0, 48, 96, 144, 192, 16, 64, 112, 160, 208, 32, 80, 128, 176, 224, - 4, 52, 100, 148, 196, 20, 68, 116, 164, 212, 36, 84, 132, 180, 228, - 8, 56, 104, 152, 200, 24, 72, 120, 168, 216, 40, 88, 136, 184, 232, - 12, 60, 108, 156, 204, 28, 76, 124, 172, 220, 44, 92, 140, 188, 236, - 1, 49, 97, 145, 193, 17, 65, 113, 161, 209, 33, 81, 129, 177, 225, - 5, 53, 101, 149, 197, 21, 69, 117, 165, 213, 37, 85, 133, 181, 229, - 9, 57, 105, 153, 201, 25, 73, 121, 169, 217, 41, 89, 137, 185, 233, - 13, 61, 109, 157, 205, 29, 77, 125, 173, 221, 45, 93, 141, 189, 237, - 2, 50, 98, 146, 194, 18, 66, 114, 162, 210, 34, 82, 130, 178, 226, - 6, 54, 102, 150, 198, 22, 70, 118, 166, 214, 38, 86, 134, 182, 230, - 10, 58, 106, 154, 202, 26, 74, 122, 170, 218, 42, 90, 138, 186, 234, - 14, 62, 110, 158, 206, 30, 78, 126, 174, 222, 46, 94, 142, 190, 238, - 3, 51, 99, 147, 195, 19, 67, 115, 163, 211, 35, 83, 131, 179, 227, - 7, 55, 103, 151, 199, 23, 71, 119, 167, 215, 39, 87, 135, 183, 231, - 11, 59, 107, 155, 203, 27, 75, 123, 171, 219, 43, 91, 139, 187, 235, - 15, 63, 111, 159, 207, 31, 79, 127, 175, 223, 47, 95, 143, 191, 239, +0, 48, 96, 144, 192, 16, 64, 112, 160, 208, 32, 80, 128, 176, 224, +4, 52, 100, 148, 196, 20, 68, 116, 164, 212, 36, 84, 132, 180, 228, +8, 56, 104, 152, 200, 24, 72, 120, 168, 216, 40, 88, 136, 184, 232, +12, 60, 108, 156, 204, 28, 76, 124, 172, 220, 44, 92, 140, 188, 236, +1, 49, 97, 145, 193, 17, 65, 113, 161, 209, 33, 81, 129, 177, 225, +5, 53, 101, 149, 197, 21, 69, 117, 165, 213, 37, 85, 133, 181, 229, +9, 57, 105, 153, 201, 25, 73, 121, 169, 217, 41, 89, 137, 185, 233, +13, 61, 109, 157, 205, 29, 77, 125, 173, 221, 45, 93, 141, 189, 237, +2, 50, 98, 146, 194, 18, 66, 114, 162, 210, 34, 82, 130, 178, 226, +6, 54, 102, 150, 198, 22, 70, 118, 166, 214, 38, 86, 134, 182, 230, +10, 58, 106, 154, 202, 26, 74, 122, 170, 218, 42, 90, 138, 186, 234, +14, 62, 110, 158, 206, 30, 78, 126, 174, 222, 46, 94, 142, 190, 238, +3, 51, 99, 147, 195, 19, 67, 115, 163, 211, 35, 83, 131, 179, 227, +7, 55, 103, 151, 199, 23, 71, 119, 167, 215, 39, 87, 135, 183, 231, +11, 59, 107, 155, 203, 27, 75, 123, 171, 219, 43, 91, 139, 187, 235, +15, 63, 111, 159, 207, 31, 79, 127, 175, 223, 47, 95, 143, 191, 239, }; #endif #ifndef FFT_BITREV120 #define FFT_BITREV120 static const opus_int16 fft_bitrev120[120] = { - 0, 24, 48, 72, 96, 8, 32, 56, 80, 104, 16, 40, 64, 88, 112, - 4, 28, 52, 76, 100, 12, 36, 60, 84, 108, 20, 44, 68, 92, 116, - 1, 25, 49, 73, 97, 9, 33, 57, 81, 105, 17, 41, 65, 89, 113, - 5, 29, 53, 77, 101, 13, 37, 61, 85, 109, 21, 45, 69, 93, 117, - 2, 26, 50, 74, 98, 10, 34, 58, 82, 106, 18, 42, 66, 90, 114, - 6, 30, 54, 78, 102, 14, 38, 62, 86, 110, 22, 46, 70, 94, 118, - 3, 27, 51, 75, 99, 11, 35, 59, 83, 107, 19, 43, 67, 91, 115, - 7, 31, 55, 79, 103, 15, 39, 63, 87, 111, 23, 47, 71, 95, 119, +0, 24, 48, 72, 96, 8, 32, 56, 80, 104, 16, 40, 64, 88, 112, +4, 28, 52, 76, 100, 12, 36, 60, 84, 108, 20, 44, 68, 92, 116, +1, 25, 49, 73, 97, 9, 33, 57, 81, 105, 17, 41, 65, 89, 113, +5, 29, 53, 77, 101, 13, 37, 61, 85, 109, 21, 45, 69, 93, 117, +2, 26, 50, 74, 98, 10, 34, 58, 82, 106, 18, 42, 66, 90, 114, +6, 30, 54, 78, 102, 14, 38, 62, 86, 110, 22, 46, 70, 94, 118, +3, 27, 51, 75, 99, 11, 35, 59, 83, 107, 19, 43, 67, 91, 115, +7, 31, 55, 79, 103, 15, 39, 63, 87, 111, 23, 47, 71, 95, 119, }; #endif #ifndef FFT_BITREV60 #define FFT_BITREV60 static const opus_int16 fft_bitrev60[60] = { - 0, 12, 24, 36, 48, 4, 16, 28, 40, 52, 8, 20, 32, 44, 56, - 1, 13, 25, 37, 49, 5, 17, 29, 41, 53, 9, 21, 33, 45, 57, - 2, 14, 26, 38, 50, 6, 18, 30, 42, 54, 10, 22, 34, 46, 58, - 3, 15, 27, 39, 51, 7, 19, 31, 43, 55, 11, 23, 35, 47, 59, +0, 12, 24, 36, 48, 4, 16, 28, 40, 52, 8, 20, 32, 44, 56, +1, 13, 25, 37, 49, 5, 17, 29, 41, 53, 9, 21, 33, 45, 57, +2, 14, 26, 38, 50, 6, 18, 30, 42, 54, 10, 22, 34, 46, 58, +3, 15, 27, 39, 51, 7, 19, 31, 43, 55, 11, 23, 35, 47, 59, }; #endif #ifndef FFT_STATE48000_960_0 #define FFT_STATE48000_960_0 static const kiss_fft_state fft_state48000_960_0 = { - 480, /* nfft */ - 0.002083333f, /* scale */ - -1, /* shift */ - {5, 96, 3, 32, 4, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev480, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +480, /* nfft */ +0.002083333f, /* scale */ +-1, /* shift */ +{5, 96, 3, 32, 4, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev480, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_480, +(arch_fft_state *)&cfg_arch_480, #else - NULL, +NULL, #endif }; #endif @@ -450,16 +447,16 @@ static const kiss_fft_state fft_state48000_960_0 = { #ifndef FFT_STATE48000_960_1 #define FFT_STATE48000_960_1 static const kiss_fft_state fft_state48000_960_1 = { - 240, /* nfft */ - 0.004166667f, /* scale */ - 1, /* shift */ - {5, 48, 3, 16, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev240, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +240, /* nfft */ +0.004166667f, /* scale */ +1, /* shift */ +{5, 48, 3, 16, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev240, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_240, +(arch_fft_state *)&cfg_arch_240, #else - NULL, +NULL, #endif }; #endif @@ -467,16 +464,16 @@ static const kiss_fft_state fft_state48000_960_1 = { #ifndef FFT_STATE48000_960_2 #define FFT_STATE48000_960_2 static const kiss_fft_state fft_state48000_960_2 = { - 120, /* nfft */ - 0.008333333f, /* scale */ - 2, /* shift */ - {5, 24, 3, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev120, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +120, /* nfft */ +0.008333333f, /* scale */ +2, /* shift */ +{5, 24, 3, 8, 2, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev120, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_120, +(arch_fft_state *)&cfg_arch_120, #else - NULL, +NULL, #endif }; #endif @@ -484,16 +481,16 @@ static const kiss_fft_state fft_state48000_960_2 = { #ifndef FFT_STATE48000_960_3 #define FFT_STATE48000_960_3 static const kiss_fft_state fft_state48000_960_3 = { - 60, /* nfft */ - 0.016666667f, /* scale */ - 3, /* shift */ - {5, 12, 3, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ - fft_bitrev60, /* bitrev */ - fft_twiddles48000_960, /* bitrev */ +60, /* nfft */ +0.016666667f, /* scale */ +3, /* shift */ +{5, 12, 3, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* factors */ +fft_bitrev60, /* bitrev */ +fft_twiddles48000_960, /* bitrev */ #ifdef OVERRIDE_FFT - (arch_fft_state *)&cfg_arch_60, +(arch_fft_state *)&cfg_arch_60, #else - NULL, +NULL, #endif }; #endif @@ -503,389 +500,389 @@ static const kiss_fft_state fft_state48000_960_3 = { #ifndef MDCT_TWIDDLES960 #define MDCT_TWIDDLES960 static const opus_val16 mdct_twiddles960[1800] = { - 0.99999994f, 0.99999321f, 0.99997580f, 0.99994773f, 0.99990886f, - 0.99985933f, 0.99979913f, 0.99972820f, 0.99964654f, 0.99955416f, - 0.99945110f, 0.99933738f, 0.99921292f, 0.99907774f, 0.99893188f, - 0.99877530f, 0.99860805f, 0.99843007f, 0.99824142f, 0.99804211f, - 0.99783206f, 0.99761140f, 0.99737996f, 0.99713790f, 0.99688518f, - 0.99662173f, 0.99634761f, 0.99606287f, 0.99576741f, 0.99546129f, - 0.99514455f, 0.99481714f, 0.99447906f, 0.99413031f, 0.99377096f, - 0.99340093f, 0.99302030f, 0.99262899f, 0.99222708f, 0.99181455f, - 0.99139136f, 0.99095762f, 0.99051321f, 0.99005818f, 0.98959261f, - 0.98911643f, 0.98862964f, 0.98813224f, 0.98762429f, 0.98710573f, - 0.98657662f, 0.98603696f, 0.98548669f, 0.98492593f, 0.98435456f, - 0.98377270f, 0.98318028f, 0.98257732f, 0.98196387f, 0.98133987f, - 0.98070538f, 0.98006040f, 0.97940493f, 0.97873890f, 0.97806245f, - 0.97737551f, 0.97667813f, 0.97597027f, 0.97525197f, 0.97452319f, - 0.97378403f, 0.97303438f, 0.97227436f, 0.97150391f, 0.97072303f, - 0.96993178f, 0.96913016f, 0.96831810f, 0.96749574f, 0.96666300f, - 0.96581990f, 0.96496642f, 0.96410263f, 0.96322852f, 0.96234411f, - 0.96144938f, 0.96054435f, 0.95962906f, 0.95870346f, 0.95776761f, - 0.95682150f, 0.95586514f, 0.95489854f, 0.95392174f, 0.95293468f, - 0.95193744f, 0.95093000f, 0.94991243f, 0.94888461f, 0.94784665f, - 0.94679856f, 0.94574034f, 0.94467193f, 0.94359344f, 0.94250488f, - 0.94140619f, 0.94029742f, 0.93917859f, 0.93804967f, 0.93691075f, - 0.93576175f, 0.93460274f, 0.93343377f, 0.93225473f, 0.93106574f, - 0.92986679f, 0.92865789f, 0.92743903f, 0.92621022f, 0.92497152f, - 0.92372292f, 0.92246443f, 0.92119598f, 0.91991776f, 0.91862965f, - 0.91733170f, 0.91602397f, 0.91470635f, 0.91337901f, 0.91204184f, - 0.91069490f, 0.90933824f, 0.90797186f, 0.90659571f, 0.90520984f, - 0.90381432f, 0.90240908f, 0.90099424f, 0.89956969f, 0.89813554f, - 0.89669174f, 0.89523834f, 0.89377540f, 0.89230281f, 0.89082074f, - 0.88932908f, 0.88782793f, 0.88631725f, 0.88479710f, 0.88326746f, - 0.88172835f, 0.88017982f, 0.87862182f, 0.87705445f, 0.87547767f, - 0.87389153f, 0.87229604f, 0.87069118f, 0.86907703f, 0.86745358f, - 0.86582077f, 0.86417878f, 0.86252749f, 0.86086690f, 0.85919720f, - 0.85751826f, 0.85583007f, 0.85413277f, 0.85242635f, 0.85071075f, - 0.84898609f, 0.84725231f, 0.84550947f, 0.84375757f, 0.84199661f, - 0.84022665f, 0.83844769f, 0.83665979f, 0.83486289f, 0.83305705f, - 0.83124226f, 0.82941860f, 0.82758605f, 0.82574469f, 0.82389444f, - 0.82203537f, 0.82016748f, 0.81829083f, 0.81640542f, 0.81451124f, - 0.81260836f, 0.81069672f, 0.80877650f, 0.80684757f, 0.80490994f, - 0.80296379f, 0.80100900f, 0.79904562f, 0.79707366f, 0.79509324f, - 0.79310423f, 0.79110676f, 0.78910083f, 0.78708643f, 0.78506362f, - 0.78303236f, 0.78099275f, 0.77894479f, 0.77688843f, 0.77482378f, - 0.77275085f, 0.77066964f, 0.76858020f, 0.76648247f, 0.76437658f, - 0.76226246f, 0.76014024f, 0.75800985f, 0.75587130f, 0.75372469f, - 0.75157005f, 0.74940729f, 0.74723655f, 0.74505776f, 0.74287105f, - 0.74067634f, 0.73847371f, 0.73626316f, 0.73404479f, 0.73181850f, - 0.72958434f, 0.72734243f, 0.72509271f, 0.72283524f, 0.72057003f, - 0.71829706f, 0.71601641f, 0.71372813f, 0.71143216f, 0.70912862f, - 0.70681745f, 0.70449871f, 0.70217246f, 0.69983864f, 0.69749737f, - 0.69514859f, 0.69279242f, 0.69042879f, 0.68805778f, 0.68567938f, - 0.68329364f, 0.68090063f, 0.67850029f, 0.67609268f, 0.67367786f, - 0.67125577f, 0.66882652f, 0.66639012f, 0.66394657f, 0.66149592f, - 0.65903819f, 0.65657341f, 0.65410155f, 0.65162271f, 0.64913690f, - 0.64664418f, 0.64414448f, 0.64163786f, 0.63912445f, 0.63660413f, - 0.63407701f, 0.63154310f, 0.62900239f, 0.62645501f, 0.62390089f, - 0.62134010f, 0.61877263f, 0.61619854f, 0.61361790f, 0.61103064f, - 0.60843682f, 0.60583651f, 0.60322970f, 0.60061646f, 0.59799677f, - 0.59537065f, 0.59273821f, 0.59009939f, 0.58745426f, 0.58480281f, - 0.58214509f, 0.57948118f, 0.57681108f, 0.57413477f, 0.57145232f, - 0.56876373f, 0.56606907f, 0.56336832f, 0.56066155f, 0.55794877f, - 0.55523002f, 0.55250537f, 0.54977477f, 0.54703826f, 0.54429591f, - 0.54154772f, 0.53879374f, 0.53603399f, 0.53326851f, 0.53049731f, - 0.52772039f, 0.52493787f, 0.52214974f, 0.51935595f, 0.51655668f, - 0.51375180f, 0.51094145f, 0.50812566f, 0.50530440f, 0.50247771f, - 0.49964568f, 0.49680826f, 0.49396557f, 0.49111754f, 0.48826426f, - 0.48540577f, 0.48254207f, 0.47967321f, 0.47679919f, 0.47392011f, - 0.47103590f, 0.46814668f, 0.46525243f, 0.46235323f, 0.45944905f, - 0.45653993f, 0.45362595f, 0.45070711f, 0.44778344f, 0.44485497f, - 0.44192174f, 0.43898380f, 0.43604112f, 0.43309379f, 0.43014181f, - 0.42718524f, 0.42422408f, 0.42125839f, 0.41828820f, 0.41531351f, - 0.41233435f, 0.40935081f, 0.40636289f, 0.40337059f, 0.40037400f, - 0.39737311f, 0.39436796f, 0.39135858f, 0.38834500f, 0.38532731f, - 0.38230544f, 0.37927949f, 0.37624949f, 0.37321547f, 0.37017745f, - 0.36713544f, 0.36408952f, 0.36103970f, 0.35798600f, 0.35492846f, - 0.35186714f, 0.34880206f, 0.34573323f, 0.34266070f, 0.33958447f, - 0.33650464f, 0.33342120f, 0.33033419f, 0.32724363f, 0.32414958f, - 0.32105204f, 0.31795108f, 0.31484672f, 0.31173897f, 0.30862790f, - 0.30551350f, 0.30239585f, 0.29927495f, 0.29615086f, 0.29302359f, - 0.28989318f, 0.28675964f, 0.28362307f, 0.28048345f, 0.27734083f, - 0.27419522f, 0.27104670f, 0.26789525f, 0.26474094f, 0.26158381f, - 0.25842386f, 0.25526115f, 0.25209570f, 0.24892756f, 0.24575676f, - 0.24258332f, 0.23940729f, 0.23622867f, 0.23304754f, 0.22986393f, - 0.22667783f, 0.22348931f, 0.22029841f, 0.21710514f, 0.21390954f, - 0.21071166f, 0.20751151f, 0.20430915f, 0.20110460f, 0.19789790f, - 0.19468907f, 0.19147816f, 0.18826519f, 0.18505022f, 0.18183327f, - 0.17861435f, 0.17539354f, 0.17217083f, 0.16894630f, 0.16571994f, - 0.16249183f, 0.15926196f, 0.15603039f, 0.15279715f, 0.14956227f, - 0.14632578f, 0.14308774f, 0.13984816f, 0.13660708f, 0.13336454f, - 0.13012058f, 0.12687522f, 0.12362850f, 0.12038045f, 0.11713112f, - 0.11388054f, 0.11062872f, 0.10737573f, 0.10412160f, 0.10086634f, - 0.097609997f, 0.094352618f, 0.091094226f, 0.087834857f, 0.084574550f, - 0.081313334f, 0.078051247f, 0.074788325f, 0.071524605f, 0.068260118f, - 0.064994894f, 0.061728980f, 0.058462404f, 0.055195201f, 0.051927410f, - 0.048659060f, 0.045390189f, 0.042120833f, 0.038851023f, 0.035580799f, - 0.032310195f, 0.029039243f, 0.025767982f, 0.022496443f, 0.019224664f, - 0.015952680f, 0.012680525f, 0.0094082337f, 0.0061358409f, 0.0028633832f, - -0.00040910527f, -0.0036815894f, -0.0069540343f, -0.010226404f, -0.013498665f, - -0.016770782f, -0.020042717f, -0.023314439f, -0.026585912f, -0.029857099f, - -0.033127967f, -0.036398482f, -0.039668605f, -0.042938303f, -0.046207540f, - -0.049476285f, -0.052744497f, -0.056012146f, -0.059279196f, -0.062545612f, - -0.065811358f, -0.069076397f, -0.072340697f, -0.075604223f, -0.078866936f, - -0.082128808f, -0.085389800f, -0.088649876f, -0.091909006f, -0.095167145f, - -0.098424271f, -0.10168034f, -0.10493532f, -0.10818918f, -0.11144188f, - -0.11469338f, -0.11794366f, -0.12119267f, -0.12444039f, -0.12768677f, - -0.13093179f, -0.13417540f, -0.13741758f, -0.14065829f, -0.14389749f, - -0.14713514f, -0.15037122f, -0.15360570f, -0.15683852f, -0.16006967f, - -0.16329910f, -0.16652679f, -0.16975269f, -0.17297678f, -0.17619900f, - -0.17941935f, -0.18263777f, -0.18585424f, -0.18906870f, -0.19228116f, - -0.19549155f, -0.19869985f, -0.20190603f, -0.20511003f, -0.20831184f, - -0.21151142f, -0.21470875f, -0.21790376f, -0.22109644f, -0.22428675f, - -0.22747467f, -0.23066014f, -0.23384315f, -0.23702365f, -0.24020162f, - -0.24337701f, -0.24654980f, -0.24971995f, -0.25288740f, -0.25605217f, - -0.25921419f, -0.26237345f, -0.26552987f, -0.26868346f, -0.27183419f, - -0.27498198f, -0.27812684f, -0.28126872f, -0.28440759f, -0.28754342f, - -0.29067615f, -0.29380578f, -0.29693225f, -0.30005556f, -0.30317566f, - -0.30629250f, -0.30940607f, -0.31251630f, -0.31562322f, -0.31872672f, - -0.32182685f, -0.32492352f, -0.32801670f, -0.33110636f, -0.33419248f, - -0.33727503f, -0.34035397f, -0.34342924f, -0.34650084f, -0.34956875f, - -0.35263291f, -0.35569328f, -0.35874987f, -0.36180258f, -0.36485144f, - -0.36789638f, -0.37093741f, -0.37397444f, -0.37700745f, -0.38003644f, - -0.38306138f, -0.38608220f, -0.38909888f, -0.39211139f, -0.39511973f, - -0.39812380f, -0.40112361f, -0.40411916f, -0.40711036f, -0.41009718f, - -0.41307965f, -0.41605768f, -0.41903123f, -0.42200032f, -0.42496487f, - -0.42792490f, -0.43088034f, -0.43383113f, -0.43677729f, -0.43971881f, - -0.44265559f, -0.44558764f, -0.44851488f, -0.45143735f, -0.45435500f, - -0.45726776f, -0.46017563f, -0.46307856f, -0.46597654f, -0.46886954f, - -0.47175750f, -0.47464043f, -0.47751826f, -0.48039100f, -0.48325855f, - -0.48612097f, -0.48897815f, -0.49183011f, -0.49467680f, -0.49751821f, - -0.50035429f, -0.50318497f, -0.50601029f, -0.50883019f, -0.51164466f, - -0.51445359f, -0.51725709f, -0.52005500f, -0.52284735f, -0.52563411f, - -0.52841520f, -0.53119069f, -0.53396046f, -0.53672451f, -0.53948283f, - -0.54223537f, -0.54498214f, -0.54772300f, -0.55045801f, -0.55318713f, - -0.55591035f, -0.55862761f, -0.56133890f, -0.56404412f, -0.56674337f, - -0.56943649f, -0.57212353f, -0.57480448f, -0.57747924f, -0.58014780f, - -0.58281022f, -0.58546633f, -0.58811617f, -0.59075975f, -0.59339696f, - -0.59602785f, -0.59865236f, -0.60127044f, -0.60388207f, -0.60648727f, - -0.60908598f, -0.61167812f, -0.61426371f, -0.61684275f, -0.61941516f, - -0.62198097f, -0.62454009f, -0.62709254f, -0.62963831f, -0.63217729f, - -0.63470948f, -0.63723493f, -0.63975352f, -0.64226526f, -0.64477009f, - -0.64726806f, -0.64975911f, -0.65224314f, -0.65472025f, -0.65719032f, - -0.65965337f, -0.66210932f, -0.66455823f, -0.66700000f, -0.66943461f, - -0.67186207f, -0.67428231f, -0.67669535f, -0.67910111f, -0.68149966f, - -0.68389088f, -0.68627477f, -0.68865126f, -0.69102043f, -0.69338220f, - -0.69573659f, -0.69808346f, -0.70042288f, -0.70275480f, -0.70507920f, - -0.70739603f, -0.70970529f, -0.71200693f, -0.71430099f, -0.71658736f, - -0.71886611f, -0.72113711f, -0.72340041f, -0.72565591f, -0.72790372f, - -0.73014367f, -0.73237586f, -0.73460019f, -0.73681659f, -0.73902518f, - -0.74122584f, -0.74341851f, -0.74560326f, -0.74778003f, -0.74994880f, - -0.75210953f, -0.75426215f, -0.75640678f, -0.75854325f, -0.76067162f, - -0.76279181f, -0.76490390f, -0.76700771f, -0.76910341f, -0.77119076f, - -0.77326995f, -0.77534080f, -0.77740335f, -0.77945763f, -0.78150350f, - -0.78354102f, -0.78557014f, -0.78759086f, -0.78960317f, -0.79160696f, - -0.79360235f, -0.79558921f, -0.79756755f, -0.79953730f, -0.80149853f, - -0.80345118f, -0.80539525f, -0.80733067f, -0.80925739f, -0.81117553f, - -0.81308490f, -0.81498563f, -0.81687760f, -0.81876087f, -0.82063532f, - -0.82250100f, -0.82435787f, -0.82620591f, -0.82804507f, -0.82987541f, - -0.83169687f, -0.83350939f, -0.83531296f, -0.83710766f, -0.83889335f, - -0.84067005f, -0.84243774f, -0.84419644f, -0.84594607f, -0.84768665f, - -0.84941816f, -0.85114056f, -0.85285389f, -0.85455805f, -0.85625303f, - -0.85793889f, -0.85961550f, -0.86128294f, -0.86294121f, -0.86459017f, - -0.86622989f, -0.86786032f, -0.86948150f, -0.87109333f, -0.87269586f, - -0.87428904f, -0.87587279f, -0.87744725f, -0.87901229f, -0.88056785f, - -0.88211405f, -0.88365078f, -0.88517809f, -0.88669586f, -0.88820416f, - -0.88970292f, -0.89119220f, -0.89267188f, -0.89414203f, -0.89560264f, - -0.89705360f, -0.89849502f, -0.89992678f, -0.90134889f, -0.90276134f, - -0.90416414f, -0.90555727f, -0.90694070f, -0.90831441f, -0.90967834f, - -0.91103262f, -0.91237706f, -0.91371179f, -0.91503674f, -0.91635185f, - -0.91765714f, -0.91895264f, -0.92023826f, -0.92151409f, -0.92277998f, - -0.92403603f, -0.92528218f, -0.92651838f, -0.92774469f, -0.92896110f, - -0.93016750f, -0.93136400f, -0.93255049f, -0.93372697f, -0.93489349f, - -0.93604994f, -0.93719643f, -0.93833286f, -0.93945926f, -0.94057560f, - -0.94168180f, -0.94277799f, -0.94386405f, -0.94494003f, -0.94600588f, - -0.94706154f, -0.94810712f, -0.94914252f, -0.95016778f, -0.95118284f, - -0.95218778f, -0.95318246f, -0.95416695f, -0.95514119f, -0.95610523f, - -0.95705903f, -0.95800257f, -0.95893586f, -0.95985889f, -0.96077162f, - -0.96167403f, -0.96256620f, -0.96344805f, -0.96431959f, -0.96518075f, - -0.96603161f, -0.96687216f, -0.96770233f, -0.96852213f, -0.96933156f, - -0.97013056f, -0.97091925f, -0.97169751f, -0.97246534f, -0.97322279f, - -0.97396982f, -0.97470641f, -0.97543252f, -0.97614825f, -0.97685349f, - -0.97754824f, -0.97823256f, -0.97890645f, -0.97956979f, -0.98022264f, - -0.98086500f, -0.98149687f, -0.98211825f, -0.98272908f, -0.98332942f, - -0.98391914f, -0.98449844f, -0.98506713f, -0.98562527f, -0.98617285f, - -0.98670989f, -0.98723638f, -0.98775226f, -0.98825759f, -0.98875231f, - -0.98923647f, -0.98971003f, -0.99017298f, -0.99062532f, -0.99106705f, - -0.99149817f, -0.99191868f, -0.99232858f, -0.99272782f, -0.99311644f, - -0.99349445f, -0.99386179f, -0.99421853f, -0.99456459f, -0.99489999f, - -0.99522477f, -0.99553883f, -0.99584228f, -0.99613506f, -0.99641716f, - -0.99668860f, -0.99694937f, -0.99719942f, -0.99743885f, -0.99766755f, - -0.99788558f, -0.99809295f, -0.99828959f, -0.99847561f, -0.99865085f, - -0.99881548f, -0.99896932f, -0.99911255f, -0.99924499f, -0.99936682f, - -0.99947786f, -0.99957830f, -0.99966794f, -0.99974692f, -0.99981517f, - -0.99987274f, -0.99991959f, -0.99995571f, -0.99998116f, -0.99999589f, - 0.99999964f, 0.99997288f, 0.99990326f, 0.99979085f, 0.99963558f, - 0.99943751f, 0.99919659f, 0.99891287f, 0.99858636f, 0.99821711f, - 0.99780506f, 0.99735034f, 0.99685282f, 0.99631262f, 0.99572974f, - 0.99510419f, 0.99443603f, 0.99372530f, 0.99297196f, 0.99217612f, - 0.99133772f, 0.99045694f, 0.98953366f, 0.98856801f, 0.98756003f, - 0.98650974f, 0.98541719f, 0.98428243f, 0.98310548f, 0.98188645f, - 0.98062533f, 0.97932225f, 0.97797716f, 0.97659022f, 0.97516143f, - 0.97369087f, 0.97217858f, 0.97062469f, 0.96902919f, 0.96739221f, - 0.96571374f, 0.96399397f, 0.96223283f, 0.96043050f, 0.95858705f, - 0.95670253f, 0.95477700f, 0.95281059f, 0.95080340f, 0.94875544f, - 0.94666684f, 0.94453770f, 0.94236809f, 0.94015813f, 0.93790787f, - 0.93561745f, 0.93328691f, 0.93091643f, 0.92850608f, 0.92605597f, - 0.92356616f, 0.92103678f, 0.91846794f, 0.91585976f, 0.91321236f, - 0.91052586f, 0.90780038f, 0.90503591f, 0.90223277f, 0.89939094f, - 0.89651060f, 0.89359182f, 0.89063478f, 0.88763964f, 0.88460642f, - 0.88153529f, 0.87842643f, 0.87527996f, 0.87209594f, 0.86887461f, - 0.86561602f, 0.86232042f, 0.85898781f, 0.85561842f, 0.85221243f, - 0.84876984f, 0.84529096f, 0.84177583f, 0.83822471f, 0.83463764f, - 0.83101481f, 0.82735640f, 0.82366252f, 0.81993335f, 0.81616908f, - 0.81236988f, 0.80853581f, 0.80466717f, 0.80076402f, 0.79682660f, - 0.79285502f, 0.78884947f, 0.78481019f, 0.78073722f, 0.77663082f, - 0.77249116f, 0.76831841f, 0.76411277f, 0.75987434f, 0.75560343f, - 0.75130010f, 0.74696463f, 0.74259710f, 0.73819780f, 0.73376691f, - 0.72930455f, 0.72481096f, 0.72028631f, 0.71573079f, 0.71114463f, - 0.70652801f, 0.70188117f, 0.69720417f, 0.69249737f, 0.68776089f, - 0.68299496f, 0.67819971f, 0.67337549f, 0.66852236f, 0.66364062f, - 0.65873051f, 0.65379208f, 0.64882571f, 0.64383155f, 0.63880974f, - 0.63376063f, 0.62868434f, 0.62358117f, 0.61845124f, 0.61329484f, - 0.60811216f, 0.60290343f, 0.59766883f, 0.59240872f, 0.58712316f, - 0.58181250f, 0.57647687f, 0.57111657f, 0.56573176f, 0.56032276f, - 0.55488980f, 0.54943299f, 0.54395270f, 0.53844911f, 0.53292239f, - 0.52737290f, 0.52180082f, 0.51620632f, 0.51058978f, 0.50495136f, - 0.49929130f, 0.49360985f, 0.48790723f, 0.48218375f, 0.47643960f, - 0.47067502f, 0.46489030f, 0.45908567f, 0.45326138f, 0.44741765f, - 0.44155475f, 0.43567297f, 0.42977250f, 0.42385364f, 0.41791660f, - 0.41196167f, 0.40598908f, 0.39999911f, 0.39399201f, 0.38796803f, - 0.38192743f, 0.37587047f, 0.36979741f, 0.36370850f, 0.35760403f, - 0.35148421f, 0.34534934f, 0.33919969f, 0.33303553f, 0.32685706f, - 0.32066461f, 0.31445843f, 0.30823877f, 0.30200592f, 0.29576012f, - 0.28950164f, 0.28323078f, 0.27694780f, 0.27065292f, 0.26434645f, - 0.25802869f, 0.25169984f, 0.24536023f, 0.23901010f, 0.23264973f, - 0.22627939f, 0.21989937f, 0.21350993f, 0.20711134f, 0.20070387f, - 0.19428782f, 0.18786344f, 0.18143101f, 0.17499080f, 0.16854310f, - 0.16208819f, 0.15562633f, 0.14915779f, 0.14268288f, 0.13620184f, - 0.12971498f, 0.12322257f, 0.11672486f, 0.11022217f, 0.10371475f, - 0.097202882f, 0.090686858f, 0.084166944f, 0.077643424f, 0.071116582f, - 0.064586692f, 0.058054037f, 0.051518895f, 0.044981543f, 0.038442269f, - 0.031901345f, 0.025359053f, 0.018815678f, 0.012271495f, 0.0057267868f, - -0.00081816671f, -0.0073630852f, -0.013907688f, -0.020451695f, -0.026994826f, - -0.033536803f, -0.040077340f, -0.046616159f, -0.053152986f, -0.059687532f, - -0.066219524f, -0.072748676f, -0.079274714f, -0.085797355f, -0.092316322f, - -0.098831341f, -0.10534211f, -0.11184838f, -0.11834986f, -0.12484626f, - -0.13133731f, -0.13782275f, -0.14430228f, -0.15077563f, -0.15724251f, - -0.16370267f, -0.17015581f, -0.17660165f, -0.18303993f, -0.18947038f, - -0.19589271f, -0.20230664f, -0.20871192f, -0.21510825f, -0.22149536f, - -0.22787298f, -0.23424086f, -0.24059868f, -0.24694622f, -0.25328314f, - -0.25960925f, -0.26592422f, -0.27222782f, -0.27851975f, -0.28479972f, - -0.29106751f, -0.29732284f, -0.30356544f, -0.30979502f, -0.31601134f, - -0.32221413f, -0.32840309f, -0.33457801f, -0.34073856f, -0.34688455f, - -0.35301566f, -0.35913166f, -0.36523229f, -0.37131724f, -0.37738630f, - -0.38343921f, -0.38947567f, -0.39549544f, -0.40149832f, -0.40748394f, - -0.41345215f, -0.41940263f, -0.42533514f, -0.43124944f, -0.43714526f, - -0.44302234f, -0.44888046f, -0.45471936f, -0.46053877f, -0.46633846f, - -0.47211814f, -0.47787762f, -0.48361665f, -0.48933494f, -0.49503228f, - -0.50070840f, -0.50636309f, -0.51199609f, -0.51760709f, -0.52319598f, - -0.52876246f, -0.53430629f, -0.53982723f, -0.54532504f, -0.55079949f, - -0.55625033f, -0.56167740f, -0.56708032f, -0.57245898f, -0.57781315f, - -0.58314258f, -0.58844697f, -0.59372622f, -0.59897995f, -0.60420811f, - -0.60941035f, -0.61458647f, -0.61973625f, -0.62485951f, -0.62995601f, - -0.63502556f, -0.64006782f, -0.64508271f, -0.65007001f, -0.65502942f, - -0.65996075f, -0.66486382f, -0.66973841f, -0.67458433f, -0.67940134f, - -0.68418926f, -0.68894786f, -0.69367695f, -0.69837630f, -0.70304573f, - -0.70768511f, -0.71229410f, -0.71687263f, -0.72142041f, -0.72593731f, - -0.73042315f, -0.73487765f, -0.73930067f, -0.74369204f, -0.74805158f, - -0.75237900f, -0.75667429f, -0.76093709f, -0.76516730f, -0.76936477f, - -0.77352923f, -0.77766061f, -0.78175867f, -0.78582323f, -0.78985411f, - -0.79385114f, -0.79781419f, -0.80174309f, -0.80563760f, -0.80949765f, - -0.81332302f, -0.81711352f, -0.82086903f, -0.82458937f, -0.82827437f, - -0.83192390f, -0.83553779f, -0.83911592f, -0.84265804f, -0.84616417f, - -0.84963393f, -0.85306740f, -0.85646427f, -0.85982448f, -0.86314780f, - -0.86643422f, -0.86968350f, -0.87289548f, -0.87607014f, -0.87920725f, - -0.88230664f, -0.88536829f, -0.88839203f, -0.89137769f, -0.89432514f, - -0.89723432f, -0.90010506f, -0.90293723f, -0.90573072f, -0.90848541f, - -0.91120118f, -0.91387796f, -0.91651553f, -0.91911387f, -0.92167282f, - -0.92419231f, -0.92667222f, -0.92911243f, -0.93151283f, -0.93387336f, - -0.93619382f, -0.93847424f, -0.94071442f, -0.94291431f, -0.94507378f, - -0.94719279f, -0.94927126f, -0.95130903f, -0.95330608f, -0.95526224f, - -0.95717752f, -0.95905179f, -0.96088499f, -0.96267700f, -0.96442777f, - -0.96613729f, -0.96780539f, -0.96943200f, -0.97101706f, -0.97256058f, - -0.97406244f, -0.97552258f, -0.97694093f, -0.97831738f, -0.97965199f, - -0.98094457f, -0.98219514f, -0.98340368f, -0.98457009f, -0.98569429f, - -0.98677629f, -0.98781598f, -0.98881340f, -0.98976845f, -0.99068111f, - -0.99155134f, -0.99237907f, -0.99316430f, -0.99390697f, -0.99460709f, - -0.99526459f, -0.99587947f, -0.99645168f, -0.99698120f, -0.99746799f, - -0.99791211f, -0.99831343f, -0.99867201f, -0.99898779f, -0.99926084f, - -0.99949104f, -0.99967843f, -0.99982297f, -0.99992472f, -0.99998361f, - 0.99999869f, 0.99989158f, 0.99961317f, 0.99916345f, 0.99854255f, - 0.99775058f, 0.99678761f, 0.99565387f, 0.99434954f, 0.99287480f, - 0.99122995f, 0.98941529f, 0.98743105f, 0.98527765f, 0.98295540f, - 0.98046476f, 0.97780609f, 0.97497988f, 0.97198665f, 0.96882683f, - 0.96550101f, 0.96200979f, 0.95835376f, 0.95453346f, 0.95054960f, - 0.94640291f, 0.94209403f, 0.93762374f, 0.93299282f, 0.92820197f, - 0.92325211f, 0.91814411f, 0.91287869f, 0.90745693f, 0.90187967f, - 0.89614785f, 0.89026248f, 0.88422459f, 0.87803519f, 0.87169534f, - 0.86520612f, 0.85856867f, 0.85178405f, 0.84485358f, 0.83777827f, - 0.83055943f, 0.82319832f, 0.81569612f, 0.80805415f, 0.80027372f, - 0.79235619f, 0.78430289f, 0.77611518f, 0.76779449f, 0.75934225f, - 0.75075996f, 0.74204898f, 0.73321080f, 0.72424710f, 0.71515924f, - 0.70594883f, 0.69661748f, 0.68716675f, 0.67759830f, 0.66791373f, - 0.65811473f, 0.64820296f, 0.63818014f, 0.62804794f, 0.61780810f, - 0.60746247f, 0.59701276f, 0.58646071f, 0.57580817f, 0.56505698f, - 0.55420899f, 0.54326600f, 0.53222996f, 0.52110273f, 0.50988621f, - 0.49858227f, 0.48719296f, 0.47572014f, 0.46416581f, 0.45253196f, - 0.44082057f, 0.42903364f, 0.41717321f, 0.40524128f, 0.39323992f, - 0.38117120f, 0.36903715f, 0.35683987f, 0.34458145f, 0.33226398f, - 0.31988961f, 0.30746040f, 0.29497850f, 0.28244606f, 0.26986524f, - 0.25723818f, 0.24456702f, 0.23185398f, 0.21910121f, 0.20631088f, - 0.19348522f, 0.18062639f, 0.16773662f, 0.15481812f, 0.14187308f, - 0.12890373f, 0.11591230f, 0.10290100f, 0.089872077f, 0.076827750f, - 0.063770257f, 0.050701842f, 0.037624735f, 0.024541186f, 0.011453429f, - -0.0016362892f, -0.014725727f, -0.027812643f, -0.040894791f, -0.053969935f, - -0.067035832f, -0.080090240f, -0.093130924f, -0.10615565f, -0.11916219f, - -0.13214831f, -0.14511178f, -0.15805040f, -0.17096193f, -0.18384418f, - -0.19669491f, -0.20951195f, -0.22229309f, -0.23503613f, -0.24773891f, - -0.26039925f, -0.27301496f, -0.28558388f, -0.29810387f, -0.31057280f, - -0.32298848f, -0.33534884f, -0.34765175f, -0.35989508f, -0.37207675f, - -0.38419467f, -0.39624676f, -0.40823093f, -0.42014518f, -0.43198743f, - -0.44375566f, -0.45544785f, -0.46706200f, -0.47859612f, -0.49004826f, - -0.50141639f, -0.51269865f, -0.52389306f, -0.53499764f, -0.54601061f, - -0.55693001f, -0.56775403f, -0.57848072f, -0.58910829f, -0.59963489f, - -0.61005878f, -0.62037814f, -0.63059121f, -0.64069623f, -0.65069145f, - -0.66057515f, -0.67034572f, -0.68000144f, -0.68954057f, -0.69896162f, - -0.70826286f, -0.71744281f, -0.72649974f, -0.73543227f, -0.74423873f, - -0.75291771f, -0.76146764f, -0.76988715f, -0.77817470f, -0.78632891f, - -0.79434842f, -0.80223179f, -0.80997771f, -0.81758487f, -0.82505190f, - -0.83237761f, -0.83956063f, -0.84659988f, -0.85349399f, -0.86024189f, - -0.86684239f, -0.87329435f, -0.87959671f, -0.88574833f, -0.89174819f, - -0.89759529f, -0.90328854f, -0.90882701f, -0.91420978f, -0.91943592f, - -0.92450452f, -0.92941469f, -0.93416560f, -0.93875647f, -0.94318646f, - -0.94745487f, -0.95156091f, -0.95550388f, -0.95928317f, -0.96289814f, - -0.96634805f, -0.96963239f, -0.97275060f, -0.97570217f, -0.97848648f, - -0.98110318f, -0.98355180f, -0.98583186f, -0.98794299f, -0.98988485f, - -0.99165714f, -0.99325943f, -0.99469161f, -0.99595332f, -0.99704438f, - -0.99796462f, -0.99871385f, -0.99929196f, -0.99969882f, -0.99993443f, - 0.99999464f, 0.99956632f, 0.99845290f, 0.99665523f, 0.99417448f, - 0.99101239f, 0.98717111f, 0.98265326f, 0.97746199f, 0.97160077f, - 0.96507365f, 0.95788515f, 0.95004016f, 0.94154406f, 0.93240267f, - 0.92262226f, 0.91220951f, 0.90117162f, 0.88951606f, 0.87725091f, - 0.86438453f, 0.85092574f, 0.83688372f, 0.82226819f, 0.80708915f, - 0.79135692f, 0.77508235f, 0.75827658f, 0.74095112f, 0.72311783f, - 0.70478898f, 0.68597710f, 0.66669506f, 0.64695615f, 0.62677377f, - 0.60616189f, 0.58513457f, 0.56370622f, 0.54189157f, 0.51970547f, - 0.49716324f, 0.47428027f, 0.45107225f, 0.42755505f, 0.40374488f, - 0.37965798f, 0.35531086f, 0.33072025f, 0.30590299f, 0.28087607f, - 0.25565663f, 0.23026201f, 0.20470956f, 0.17901683f, 0.15320139f, - 0.12728097f, 0.10127331f, 0.075196236f, 0.049067631f, 0.022905400f, - -0.0032725304f, -0.029448219f, -0.055603724f, -0.081721120f, -0.10778251f, - -0.13377003f, -0.15966587f, -0.18545228f, -0.21111161f, -0.23662624f, - -0.26197869f, -0.28715160f, -0.31212771f, -0.33688989f, -0.36142120f, - -0.38570482f, -0.40972409f, -0.43346253f, -0.45690393f, -0.48003218f, - -0.50283146f, -0.52528608f, -0.54738069f, -0.56910020f, -0.59042966f, - -0.61135447f, -0.63186026f, -0.65193301f, -0.67155898f, -0.69072473f, - -0.70941705f, -0.72762316f, -0.74533063f, -0.76252723f, -0.77920127f, - -0.79534131f, -0.81093621f, -0.82597536f, -0.84044844f, -0.85434550f, - -0.86765707f, -0.88037395f, -0.89248747f, -0.90398932f, -0.91487163f, - -0.92512697f, -0.93474823f, -0.94372886f, -0.95206273f, -0.95974404f, - -0.96676767f, -0.97312868f, -0.97882277f, -0.98384601f, -0.98819500f, - -0.99186671f, -0.99485862f, -0.99716878f, -0.99879545f, -0.99973762f, +0.99999994f, 0.99999321f, 0.99997580f, 0.99994773f, 0.99990886f, +0.99985933f, 0.99979913f, 0.99972820f, 0.99964654f, 0.99955416f, +0.99945110f, 0.99933738f, 0.99921292f, 0.99907774f, 0.99893188f, +0.99877530f, 0.99860805f, 0.99843007f, 0.99824142f, 0.99804211f, +0.99783206f, 0.99761140f, 0.99737996f, 0.99713790f, 0.99688518f, +0.99662173f, 0.99634761f, 0.99606287f, 0.99576741f, 0.99546129f, +0.99514455f, 0.99481714f, 0.99447906f, 0.99413031f, 0.99377096f, +0.99340093f, 0.99302030f, 0.99262899f, 0.99222708f, 0.99181455f, +0.99139136f, 0.99095762f, 0.99051321f, 0.99005818f, 0.98959261f, +0.98911643f, 0.98862964f, 0.98813224f, 0.98762429f, 0.98710573f, +0.98657662f, 0.98603696f, 0.98548669f, 0.98492593f, 0.98435456f, +0.98377270f, 0.98318028f, 0.98257732f, 0.98196387f, 0.98133987f, +0.98070538f, 0.98006040f, 0.97940493f, 0.97873890f, 0.97806245f, +0.97737551f, 0.97667813f, 0.97597027f, 0.97525197f, 0.97452319f, +0.97378403f, 0.97303438f, 0.97227436f, 0.97150391f, 0.97072303f, +0.96993178f, 0.96913016f, 0.96831810f, 0.96749574f, 0.96666300f, +0.96581990f, 0.96496642f, 0.96410263f, 0.96322852f, 0.96234411f, +0.96144938f, 0.96054435f, 0.95962906f, 0.95870346f, 0.95776761f, +0.95682150f, 0.95586514f, 0.95489854f, 0.95392174f, 0.95293468f, +0.95193744f, 0.95093000f, 0.94991243f, 0.94888461f, 0.94784665f, +0.94679856f, 0.94574034f, 0.94467193f, 0.94359344f, 0.94250488f, +0.94140619f, 0.94029742f, 0.93917859f, 0.93804967f, 0.93691075f, +0.93576175f, 0.93460274f, 0.93343377f, 0.93225473f, 0.93106574f, +0.92986679f, 0.92865789f, 0.92743903f, 0.92621022f, 0.92497152f, +0.92372292f, 0.92246443f, 0.92119598f, 0.91991776f, 0.91862965f, +0.91733170f, 0.91602397f, 0.91470635f, 0.91337901f, 0.91204184f, +0.91069490f, 0.90933824f, 0.90797186f, 0.90659571f, 0.90520984f, +0.90381432f, 0.90240908f, 0.90099424f, 0.89956969f, 0.89813554f, +0.89669174f, 0.89523834f, 0.89377540f, 0.89230281f, 0.89082074f, +0.88932908f, 0.88782793f, 0.88631725f, 0.88479710f, 0.88326746f, +0.88172835f, 0.88017982f, 0.87862182f, 0.87705445f, 0.87547767f, +0.87389153f, 0.87229604f, 0.87069118f, 0.86907703f, 0.86745358f, +0.86582077f, 0.86417878f, 0.86252749f, 0.86086690f, 0.85919720f, +0.85751826f, 0.85583007f, 0.85413277f, 0.85242635f, 0.85071075f, +0.84898609f, 0.84725231f, 0.84550947f, 0.84375757f, 0.84199661f, +0.84022665f, 0.83844769f, 0.83665979f, 0.83486289f, 0.83305705f, +0.83124226f, 0.82941860f, 0.82758605f, 0.82574469f, 0.82389444f, +0.82203537f, 0.82016748f, 0.81829083f, 0.81640542f, 0.81451124f, +0.81260836f, 0.81069672f, 0.80877650f, 0.80684757f, 0.80490994f, +0.80296379f, 0.80100900f, 0.79904562f, 0.79707366f, 0.79509324f, +0.79310423f, 0.79110676f, 0.78910083f, 0.78708643f, 0.78506362f, +0.78303236f, 0.78099275f, 0.77894479f, 0.77688843f, 0.77482378f, +0.77275085f, 0.77066964f, 0.76858020f, 0.76648247f, 0.76437658f, +0.76226246f, 0.76014024f, 0.75800985f, 0.75587130f, 0.75372469f, +0.75157005f, 0.74940729f, 0.74723655f, 0.74505776f, 0.74287105f, +0.74067634f, 0.73847371f, 0.73626316f, 0.73404479f, 0.73181850f, +0.72958434f, 0.72734243f, 0.72509271f, 0.72283524f, 0.72057003f, +0.71829706f, 0.71601641f, 0.71372813f, 0.71143216f, 0.70912862f, +0.70681745f, 0.70449871f, 0.70217246f, 0.69983864f, 0.69749737f, +0.69514859f, 0.69279242f, 0.69042879f, 0.68805778f, 0.68567938f, +0.68329364f, 0.68090063f, 0.67850029f, 0.67609268f, 0.67367786f, +0.67125577f, 0.66882652f, 0.66639012f, 0.66394657f, 0.66149592f, +0.65903819f, 0.65657341f, 0.65410155f, 0.65162271f, 0.64913690f, +0.64664418f, 0.64414448f, 0.64163786f, 0.63912445f, 0.63660413f, +0.63407701f, 0.63154310f, 0.62900239f, 0.62645501f, 0.62390089f, +0.62134010f, 0.61877263f, 0.61619854f, 0.61361790f, 0.61103064f, +0.60843682f, 0.60583651f, 0.60322970f, 0.60061646f, 0.59799677f, +0.59537065f, 0.59273821f, 0.59009939f, 0.58745426f, 0.58480281f, +0.58214509f, 0.57948118f, 0.57681108f, 0.57413477f, 0.57145232f, +0.56876373f, 0.56606907f, 0.56336832f, 0.56066155f, 0.55794877f, +0.55523002f, 0.55250537f, 0.54977477f, 0.54703826f, 0.54429591f, +0.54154772f, 0.53879374f, 0.53603399f, 0.53326851f, 0.53049731f, +0.52772039f, 0.52493787f, 0.52214974f, 0.51935595f, 0.51655668f, +0.51375180f, 0.51094145f, 0.50812566f, 0.50530440f, 0.50247771f, +0.49964568f, 0.49680826f, 0.49396557f, 0.49111754f, 0.48826426f, +0.48540577f, 0.48254207f, 0.47967321f, 0.47679919f, 0.47392011f, +0.47103590f, 0.46814668f, 0.46525243f, 0.46235323f, 0.45944905f, +0.45653993f, 0.45362595f, 0.45070711f, 0.44778344f, 0.44485497f, +0.44192174f, 0.43898380f, 0.43604112f, 0.43309379f, 0.43014181f, +0.42718524f, 0.42422408f, 0.42125839f, 0.41828820f, 0.41531351f, +0.41233435f, 0.40935081f, 0.40636289f, 0.40337059f, 0.40037400f, +0.39737311f, 0.39436796f, 0.39135858f, 0.38834500f, 0.38532731f, +0.38230544f, 0.37927949f, 0.37624949f, 0.37321547f, 0.37017745f, +0.36713544f, 0.36408952f, 0.36103970f, 0.35798600f, 0.35492846f, +0.35186714f, 0.34880206f, 0.34573323f, 0.34266070f, 0.33958447f, +0.33650464f, 0.33342120f, 0.33033419f, 0.32724363f, 0.32414958f, +0.32105204f, 0.31795108f, 0.31484672f, 0.31173897f, 0.30862790f, +0.30551350f, 0.30239585f, 0.29927495f, 0.29615086f, 0.29302359f, +0.28989318f, 0.28675964f, 0.28362307f, 0.28048345f, 0.27734083f, +0.27419522f, 0.27104670f, 0.26789525f, 0.26474094f, 0.26158381f, +0.25842386f, 0.25526115f, 0.25209570f, 0.24892756f, 0.24575676f, +0.24258332f, 0.23940729f, 0.23622867f, 0.23304754f, 0.22986393f, +0.22667783f, 0.22348931f, 0.22029841f, 0.21710514f, 0.21390954f, +0.21071166f, 0.20751151f, 0.20430915f, 0.20110460f, 0.19789790f, +0.19468907f, 0.19147816f, 0.18826519f, 0.18505022f, 0.18183327f, +0.17861435f, 0.17539354f, 0.17217083f, 0.16894630f, 0.16571994f, +0.16249183f, 0.15926196f, 0.15603039f, 0.15279715f, 0.14956227f, +0.14632578f, 0.14308774f, 0.13984816f, 0.13660708f, 0.13336454f, +0.13012058f, 0.12687522f, 0.12362850f, 0.12038045f, 0.11713112f, +0.11388054f, 0.11062872f, 0.10737573f, 0.10412160f, 0.10086634f, +0.097609997f, 0.094352618f, 0.091094226f, 0.087834857f, 0.084574550f, +0.081313334f, 0.078051247f, 0.074788325f, 0.071524605f, 0.068260118f, +0.064994894f, 0.061728980f, 0.058462404f, 0.055195201f, 0.051927410f, +0.048659060f, 0.045390189f, 0.042120833f, 0.038851023f, 0.035580799f, +0.032310195f, 0.029039243f, 0.025767982f, 0.022496443f, 0.019224664f, +0.015952680f, 0.012680525f, 0.0094082337f, 0.0061358409f, 0.0028633832f, +-0.00040910527f, -0.0036815894f, -0.0069540343f, -0.010226404f, -0.013498665f, +-0.016770782f, -0.020042717f, -0.023314439f, -0.026585912f, -0.029857099f, +-0.033127967f, -0.036398482f, -0.039668605f, -0.042938303f, -0.046207540f, +-0.049476285f, -0.052744497f, -0.056012146f, -0.059279196f, -0.062545612f, +-0.065811358f, -0.069076397f, -0.072340697f, -0.075604223f, -0.078866936f, +-0.082128808f, -0.085389800f, -0.088649876f, -0.091909006f, -0.095167145f, +-0.098424271f, -0.10168034f, -0.10493532f, -0.10818918f, -0.11144188f, +-0.11469338f, -0.11794366f, -0.12119267f, -0.12444039f, -0.12768677f, +-0.13093179f, -0.13417540f, -0.13741758f, -0.14065829f, -0.14389749f, +-0.14713514f, -0.15037122f, -0.15360570f, -0.15683852f, -0.16006967f, +-0.16329910f, -0.16652679f, -0.16975269f, -0.17297678f, -0.17619900f, +-0.17941935f, -0.18263777f, -0.18585424f, -0.18906870f, -0.19228116f, +-0.19549155f, -0.19869985f, -0.20190603f, -0.20511003f, -0.20831184f, +-0.21151142f, -0.21470875f, -0.21790376f, -0.22109644f, -0.22428675f, +-0.22747467f, -0.23066014f, -0.23384315f, -0.23702365f, -0.24020162f, +-0.24337701f, -0.24654980f, -0.24971995f, -0.25288740f, -0.25605217f, +-0.25921419f, -0.26237345f, -0.26552987f, -0.26868346f, -0.27183419f, +-0.27498198f, -0.27812684f, -0.28126872f, -0.28440759f, -0.28754342f, +-0.29067615f, -0.29380578f, -0.29693225f, -0.30005556f, -0.30317566f, +-0.30629250f, -0.30940607f, -0.31251630f, -0.31562322f, -0.31872672f, +-0.32182685f, -0.32492352f, -0.32801670f, -0.33110636f, -0.33419248f, +-0.33727503f, -0.34035397f, -0.34342924f, -0.34650084f, -0.34956875f, +-0.35263291f, -0.35569328f, -0.35874987f, -0.36180258f, -0.36485144f, +-0.36789638f, -0.37093741f, -0.37397444f, -0.37700745f, -0.38003644f, +-0.38306138f, -0.38608220f, -0.38909888f, -0.39211139f, -0.39511973f, +-0.39812380f, -0.40112361f, -0.40411916f, -0.40711036f, -0.41009718f, +-0.41307965f, -0.41605768f, -0.41903123f, -0.42200032f, -0.42496487f, +-0.42792490f, -0.43088034f, -0.43383113f, -0.43677729f, -0.43971881f, +-0.44265559f, -0.44558764f, -0.44851488f, -0.45143735f, -0.45435500f, +-0.45726776f, -0.46017563f, -0.46307856f, -0.46597654f, -0.46886954f, +-0.47175750f, -0.47464043f, -0.47751826f, -0.48039100f, -0.48325855f, +-0.48612097f, -0.48897815f, -0.49183011f, -0.49467680f, -0.49751821f, +-0.50035429f, -0.50318497f, -0.50601029f, -0.50883019f, -0.51164466f, +-0.51445359f, -0.51725709f, -0.52005500f, -0.52284735f, -0.52563411f, +-0.52841520f, -0.53119069f, -0.53396046f, -0.53672451f, -0.53948283f, +-0.54223537f, -0.54498214f, -0.54772300f, -0.55045801f, -0.55318713f, +-0.55591035f, -0.55862761f, -0.56133890f, -0.56404412f, -0.56674337f, +-0.56943649f, -0.57212353f, -0.57480448f, -0.57747924f, -0.58014780f, +-0.58281022f, -0.58546633f, -0.58811617f, -0.59075975f, -0.59339696f, +-0.59602785f, -0.59865236f, -0.60127044f, -0.60388207f, -0.60648727f, +-0.60908598f, -0.61167812f, -0.61426371f, -0.61684275f, -0.61941516f, +-0.62198097f, -0.62454009f, -0.62709254f, -0.62963831f, -0.63217729f, +-0.63470948f, -0.63723493f, -0.63975352f, -0.64226526f, -0.64477009f, +-0.64726806f, -0.64975911f, -0.65224314f, -0.65472025f, -0.65719032f, +-0.65965337f, -0.66210932f, -0.66455823f, -0.66700000f, -0.66943461f, +-0.67186207f, -0.67428231f, -0.67669535f, -0.67910111f, -0.68149966f, +-0.68389088f, -0.68627477f, -0.68865126f, -0.69102043f, -0.69338220f, +-0.69573659f, -0.69808346f, -0.70042288f, -0.70275480f, -0.70507920f, +-0.70739603f, -0.70970529f, -0.71200693f, -0.71430099f, -0.71658736f, +-0.71886611f, -0.72113711f, -0.72340041f, -0.72565591f, -0.72790372f, +-0.73014367f, -0.73237586f, -0.73460019f, -0.73681659f, -0.73902518f, +-0.74122584f, -0.74341851f, -0.74560326f, -0.74778003f, -0.74994880f, +-0.75210953f, -0.75426215f, -0.75640678f, -0.75854325f, -0.76067162f, +-0.76279181f, -0.76490390f, -0.76700771f, -0.76910341f, -0.77119076f, +-0.77326995f, -0.77534080f, -0.77740335f, -0.77945763f, -0.78150350f, +-0.78354102f, -0.78557014f, -0.78759086f, -0.78960317f, -0.79160696f, +-0.79360235f, -0.79558921f, -0.79756755f, -0.79953730f, -0.80149853f, +-0.80345118f, -0.80539525f, -0.80733067f, -0.80925739f, -0.81117553f, +-0.81308490f, -0.81498563f, -0.81687760f, -0.81876087f, -0.82063532f, +-0.82250100f, -0.82435787f, -0.82620591f, -0.82804507f, -0.82987541f, +-0.83169687f, -0.83350939f, -0.83531296f, -0.83710766f, -0.83889335f, +-0.84067005f, -0.84243774f, -0.84419644f, -0.84594607f, -0.84768665f, +-0.84941816f, -0.85114056f, -0.85285389f, -0.85455805f, -0.85625303f, +-0.85793889f, -0.85961550f, -0.86128294f, -0.86294121f, -0.86459017f, +-0.86622989f, -0.86786032f, -0.86948150f, -0.87109333f, -0.87269586f, +-0.87428904f, -0.87587279f, -0.87744725f, -0.87901229f, -0.88056785f, +-0.88211405f, -0.88365078f, -0.88517809f, -0.88669586f, -0.88820416f, +-0.88970292f, -0.89119220f, -0.89267188f, -0.89414203f, -0.89560264f, +-0.89705360f, -0.89849502f, -0.89992678f, -0.90134889f, -0.90276134f, +-0.90416414f, -0.90555727f, -0.90694070f, -0.90831441f, -0.90967834f, +-0.91103262f, -0.91237706f, -0.91371179f, -0.91503674f, -0.91635185f, +-0.91765714f, -0.91895264f, -0.92023826f, -0.92151409f, -0.92277998f, +-0.92403603f, -0.92528218f, -0.92651838f, -0.92774469f, -0.92896110f, +-0.93016750f, -0.93136400f, -0.93255049f, -0.93372697f, -0.93489349f, +-0.93604994f, -0.93719643f, -0.93833286f, -0.93945926f, -0.94057560f, +-0.94168180f, -0.94277799f, -0.94386405f, -0.94494003f, -0.94600588f, +-0.94706154f, -0.94810712f, -0.94914252f, -0.95016778f, -0.95118284f, +-0.95218778f, -0.95318246f, -0.95416695f, -0.95514119f, -0.95610523f, +-0.95705903f, -0.95800257f, -0.95893586f, -0.95985889f, -0.96077162f, +-0.96167403f, -0.96256620f, -0.96344805f, -0.96431959f, -0.96518075f, +-0.96603161f, -0.96687216f, -0.96770233f, -0.96852213f, -0.96933156f, +-0.97013056f, -0.97091925f, -0.97169751f, -0.97246534f, -0.97322279f, +-0.97396982f, -0.97470641f, -0.97543252f, -0.97614825f, -0.97685349f, +-0.97754824f, -0.97823256f, -0.97890645f, -0.97956979f, -0.98022264f, +-0.98086500f, -0.98149687f, -0.98211825f, -0.98272908f, -0.98332942f, +-0.98391914f, -0.98449844f, -0.98506713f, -0.98562527f, -0.98617285f, +-0.98670989f, -0.98723638f, -0.98775226f, -0.98825759f, -0.98875231f, +-0.98923647f, -0.98971003f, -0.99017298f, -0.99062532f, -0.99106705f, +-0.99149817f, -0.99191868f, -0.99232858f, -0.99272782f, -0.99311644f, +-0.99349445f, -0.99386179f, -0.99421853f, -0.99456459f, -0.99489999f, +-0.99522477f, -0.99553883f, -0.99584228f, -0.99613506f, -0.99641716f, +-0.99668860f, -0.99694937f, -0.99719942f, -0.99743885f, -0.99766755f, +-0.99788558f, -0.99809295f, -0.99828959f, -0.99847561f, -0.99865085f, +-0.99881548f, -0.99896932f, -0.99911255f, -0.99924499f, -0.99936682f, +-0.99947786f, -0.99957830f, -0.99966794f, -0.99974692f, -0.99981517f, +-0.99987274f, -0.99991959f, -0.99995571f, -0.99998116f, -0.99999589f, +0.99999964f, 0.99997288f, 0.99990326f, 0.99979085f, 0.99963558f, +0.99943751f, 0.99919659f, 0.99891287f, 0.99858636f, 0.99821711f, +0.99780506f, 0.99735034f, 0.99685282f, 0.99631262f, 0.99572974f, +0.99510419f, 0.99443603f, 0.99372530f, 0.99297196f, 0.99217612f, +0.99133772f, 0.99045694f, 0.98953366f, 0.98856801f, 0.98756003f, +0.98650974f, 0.98541719f, 0.98428243f, 0.98310548f, 0.98188645f, +0.98062533f, 0.97932225f, 0.97797716f, 0.97659022f, 0.97516143f, +0.97369087f, 0.97217858f, 0.97062469f, 0.96902919f, 0.96739221f, +0.96571374f, 0.96399397f, 0.96223283f, 0.96043050f, 0.95858705f, +0.95670253f, 0.95477700f, 0.95281059f, 0.95080340f, 0.94875544f, +0.94666684f, 0.94453770f, 0.94236809f, 0.94015813f, 0.93790787f, +0.93561745f, 0.93328691f, 0.93091643f, 0.92850608f, 0.92605597f, +0.92356616f, 0.92103678f, 0.91846794f, 0.91585976f, 0.91321236f, +0.91052586f, 0.90780038f, 0.90503591f, 0.90223277f, 0.89939094f, +0.89651060f, 0.89359182f, 0.89063478f, 0.88763964f, 0.88460642f, +0.88153529f, 0.87842643f, 0.87527996f, 0.87209594f, 0.86887461f, +0.86561602f, 0.86232042f, 0.85898781f, 0.85561842f, 0.85221243f, +0.84876984f, 0.84529096f, 0.84177583f, 0.83822471f, 0.83463764f, +0.83101481f, 0.82735640f, 0.82366252f, 0.81993335f, 0.81616908f, +0.81236988f, 0.80853581f, 0.80466717f, 0.80076402f, 0.79682660f, +0.79285502f, 0.78884947f, 0.78481019f, 0.78073722f, 0.77663082f, +0.77249116f, 0.76831841f, 0.76411277f, 0.75987434f, 0.75560343f, +0.75130010f, 0.74696463f, 0.74259710f, 0.73819780f, 0.73376691f, +0.72930455f, 0.72481096f, 0.72028631f, 0.71573079f, 0.71114463f, +0.70652801f, 0.70188117f, 0.69720417f, 0.69249737f, 0.68776089f, +0.68299496f, 0.67819971f, 0.67337549f, 0.66852236f, 0.66364062f, +0.65873051f, 0.65379208f, 0.64882571f, 0.64383155f, 0.63880974f, +0.63376063f, 0.62868434f, 0.62358117f, 0.61845124f, 0.61329484f, +0.60811216f, 0.60290343f, 0.59766883f, 0.59240872f, 0.58712316f, +0.58181250f, 0.57647687f, 0.57111657f, 0.56573176f, 0.56032276f, +0.55488980f, 0.54943299f, 0.54395270f, 0.53844911f, 0.53292239f, +0.52737290f, 0.52180082f, 0.51620632f, 0.51058978f, 0.50495136f, +0.49929130f, 0.49360985f, 0.48790723f, 0.48218375f, 0.47643960f, +0.47067502f, 0.46489030f, 0.45908567f, 0.45326138f, 0.44741765f, +0.44155475f, 0.43567297f, 0.42977250f, 0.42385364f, 0.41791660f, +0.41196167f, 0.40598908f, 0.39999911f, 0.39399201f, 0.38796803f, +0.38192743f, 0.37587047f, 0.36979741f, 0.36370850f, 0.35760403f, +0.35148421f, 0.34534934f, 0.33919969f, 0.33303553f, 0.32685706f, +0.32066461f, 0.31445843f, 0.30823877f, 0.30200592f, 0.29576012f, +0.28950164f, 0.28323078f, 0.27694780f, 0.27065292f, 0.26434645f, +0.25802869f, 0.25169984f, 0.24536023f, 0.23901010f, 0.23264973f, +0.22627939f, 0.21989937f, 0.21350993f, 0.20711134f, 0.20070387f, +0.19428782f, 0.18786344f, 0.18143101f, 0.17499080f, 0.16854310f, +0.16208819f, 0.15562633f, 0.14915779f, 0.14268288f, 0.13620184f, +0.12971498f, 0.12322257f, 0.11672486f, 0.11022217f, 0.10371475f, +0.097202882f, 0.090686858f, 0.084166944f, 0.077643424f, 0.071116582f, +0.064586692f, 0.058054037f, 0.051518895f, 0.044981543f, 0.038442269f, +0.031901345f, 0.025359053f, 0.018815678f, 0.012271495f, 0.0057267868f, +-0.00081816671f, -0.0073630852f, -0.013907688f, -0.020451695f, -0.026994826f, +-0.033536803f, -0.040077340f, -0.046616159f, -0.053152986f, -0.059687532f, +-0.066219524f, -0.072748676f, -0.079274714f, -0.085797355f, -0.092316322f, +-0.098831341f, -0.10534211f, -0.11184838f, -0.11834986f, -0.12484626f, +-0.13133731f, -0.13782275f, -0.14430228f, -0.15077563f, -0.15724251f, +-0.16370267f, -0.17015581f, -0.17660165f, -0.18303993f, -0.18947038f, +-0.19589271f, -0.20230664f, -0.20871192f, -0.21510825f, -0.22149536f, +-0.22787298f, -0.23424086f, -0.24059868f, -0.24694622f, -0.25328314f, +-0.25960925f, -0.26592422f, -0.27222782f, -0.27851975f, -0.28479972f, +-0.29106751f, -0.29732284f, -0.30356544f, -0.30979502f, -0.31601134f, +-0.32221413f, -0.32840309f, -0.33457801f, -0.34073856f, -0.34688455f, +-0.35301566f, -0.35913166f, -0.36523229f, -0.37131724f, -0.37738630f, +-0.38343921f, -0.38947567f, -0.39549544f, -0.40149832f, -0.40748394f, +-0.41345215f, -0.41940263f, -0.42533514f, -0.43124944f, -0.43714526f, +-0.44302234f, -0.44888046f, -0.45471936f, -0.46053877f, -0.46633846f, +-0.47211814f, -0.47787762f, -0.48361665f, -0.48933494f, -0.49503228f, +-0.50070840f, -0.50636309f, -0.51199609f, -0.51760709f, -0.52319598f, +-0.52876246f, -0.53430629f, -0.53982723f, -0.54532504f, -0.55079949f, +-0.55625033f, -0.56167740f, -0.56708032f, -0.57245898f, -0.57781315f, +-0.58314258f, -0.58844697f, -0.59372622f, -0.59897995f, -0.60420811f, +-0.60941035f, -0.61458647f, -0.61973625f, -0.62485951f, -0.62995601f, +-0.63502556f, -0.64006782f, -0.64508271f, -0.65007001f, -0.65502942f, +-0.65996075f, -0.66486382f, -0.66973841f, -0.67458433f, -0.67940134f, +-0.68418926f, -0.68894786f, -0.69367695f, -0.69837630f, -0.70304573f, +-0.70768511f, -0.71229410f, -0.71687263f, -0.72142041f, -0.72593731f, +-0.73042315f, -0.73487765f, -0.73930067f, -0.74369204f, -0.74805158f, +-0.75237900f, -0.75667429f, -0.76093709f, -0.76516730f, -0.76936477f, +-0.77352923f, -0.77766061f, -0.78175867f, -0.78582323f, -0.78985411f, +-0.79385114f, -0.79781419f, -0.80174309f, -0.80563760f, -0.80949765f, +-0.81332302f, -0.81711352f, -0.82086903f, -0.82458937f, -0.82827437f, +-0.83192390f, -0.83553779f, -0.83911592f, -0.84265804f, -0.84616417f, +-0.84963393f, -0.85306740f, -0.85646427f, -0.85982448f, -0.86314780f, +-0.86643422f, -0.86968350f, -0.87289548f, -0.87607014f, -0.87920725f, +-0.88230664f, -0.88536829f, -0.88839203f, -0.89137769f, -0.89432514f, +-0.89723432f, -0.90010506f, -0.90293723f, -0.90573072f, -0.90848541f, +-0.91120118f, -0.91387796f, -0.91651553f, -0.91911387f, -0.92167282f, +-0.92419231f, -0.92667222f, -0.92911243f, -0.93151283f, -0.93387336f, +-0.93619382f, -0.93847424f, -0.94071442f, -0.94291431f, -0.94507378f, +-0.94719279f, -0.94927126f, -0.95130903f, -0.95330608f, -0.95526224f, +-0.95717752f, -0.95905179f, -0.96088499f, -0.96267700f, -0.96442777f, +-0.96613729f, -0.96780539f, -0.96943200f, -0.97101706f, -0.97256058f, +-0.97406244f, -0.97552258f, -0.97694093f, -0.97831738f, -0.97965199f, +-0.98094457f, -0.98219514f, -0.98340368f, -0.98457009f, -0.98569429f, +-0.98677629f, -0.98781598f, -0.98881340f, -0.98976845f, -0.99068111f, +-0.99155134f, -0.99237907f, -0.99316430f, -0.99390697f, -0.99460709f, +-0.99526459f, -0.99587947f, -0.99645168f, -0.99698120f, -0.99746799f, +-0.99791211f, -0.99831343f, -0.99867201f, -0.99898779f, -0.99926084f, +-0.99949104f, -0.99967843f, -0.99982297f, -0.99992472f, -0.99998361f, +0.99999869f, 0.99989158f, 0.99961317f, 0.99916345f, 0.99854255f, +0.99775058f, 0.99678761f, 0.99565387f, 0.99434954f, 0.99287480f, +0.99122995f, 0.98941529f, 0.98743105f, 0.98527765f, 0.98295540f, +0.98046476f, 0.97780609f, 0.97497988f, 0.97198665f, 0.96882683f, +0.96550101f, 0.96200979f, 0.95835376f, 0.95453346f, 0.95054960f, +0.94640291f, 0.94209403f, 0.93762374f, 0.93299282f, 0.92820197f, +0.92325211f, 0.91814411f, 0.91287869f, 0.90745693f, 0.90187967f, +0.89614785f, 0.89026248f, 0.88422459f, 0.87803519f, 0.87169534f, +0.86520612f, 0.85856867f, 0.85178405f, 0.84485358f, 0.83777827f, +0.83055943f, 0.82319832f, 0.81569612f, 0.80805415f, 0.80027372f, +0.79235619f, 0.78430289f, 0.77611518f, 0.76779449f, 0.75934225f, +0.75075996f, 0.74204898f, 0.73321080f, 0.72424710f, 0.71515924f, +0.70594883f, 0.69661748f, 0.68716675f, 0.67759830f, 0.66791373f, +0.65811473f, 0.64820296f, 0.63818014f, 0.62804794f, 0.61780810f, +0.60746247f, 0.59701276f, 0.58646071f, 0.57580817f, 0.56505698f, +0.55420899f, 0.54326600f, 0.53222996f, 0.52110273f, 0.50988621f, +0.49858227f, 0.48719296f, 0.47572014f, 0.46416581f, 0.45253196f, +0.44082057f, 0.42903364f, 0.41717321f, 0.40524128f, 0.39323992f, +0.38117120f, 0.36903715f, 0.35683987f, 0.34458145f, 0.33226398f, +0.31988961f, 0.30746040f, 0.29497850f, 0.28244606f, 0.26986524f, +0.25723818f, 0.24456702f, 0.23185398f, 0.21910121f, 0.20631088f, +0.19348522f, 0.18062639f, 0.16773662f, 0.15481812f, 0.14187308f, +0.12890373f, 0.11591230f, 0.10290100f, 0.089872077f, 0.076827750f, +0.063770257f, 0.050701842f, 0.037624735f, 0.024541186f, 0.011453429f, +-0.0016362892f, -0.014725727f, -0.027812643f, -0.040894791f, -0.053969935f, +-0.067035832f, -0.080090240f, -0.093130924f, -0.10615565f, -0.11916219f, +-0.13214831f, -0.14511178f, -0.15805040f, -0.17096193f, -0.18384418f, +-0.19669491f, -0.20951195f, -0.22229309f, -0.23503613f, -0.24773891f, +-0.26039925f, -0.27301496f, -0.28558388f, -0.29810387f, -0.31057280f, +-0.32298848f, -0.33534884f, -0.34765175f, -0.35989508f, -0.37207675f, +-0.38419467f, -0.39624676f, -0.40823093f, -0.42014518f, -0.43198743f, +-0.44375566f, -0.45544785f, -0.46706200f, -0.47859612f, -0.49004826f, +-0.50141639f, -0.51269865f, -0.52389306f, -0.53499764f, -0.54601061f, +-0.55693001f, -0.56775403f, -0.57848072f, -0.58910829f, -0.59963489f, +-0.61005878f, -0.62037814f, -0.63059121f, -0.64069623f, -0.65069145f, +-0.66057515f, -0.67034572f, -0.68000144f, -0.68954057f, -0.69896162f, +-0.70826286f, -0.71744281f, -0.72649974f, -0.73543227f, -0.74423873f, +-0.75291771f, -0.76146764f, -0.76988715f, -0.77817470f, -0.78632891f, +-0.79434842f, -0.80223179f, -0.80997771f, -0.81758487f, -0.82505190f, +-0.83237761f, -0.83956063f, -0.84659988f, -0.85349399f, -0.86024189f, +-0.86684239f, -0.87329435f, -0.87959671f, -0.88574833f, -0.89174819f, +-0.89759529f, -0.90328854f, -0.90882701f, -0.91420978f, -0.91943592f, +-0.92450452f, -0.92941469f, -0.93416560f, -0.93875647f, -0.94318646f, +-0.94745487f, -0.95156091f, -0.95550388f, -0.95928317f, -0.96289814f, +-0.96634805f, -0.96963239f, -0.97275060f, -0.97570217f, -0.97848648f, +-0.98110318f, -0.98355180f, -0.98583186f, -0.98794299f, -0.98988485f, +-0.99165714f, -0.99325943f, -0.99469161f, -0.99595332f, -0.99704438f, +-0.99796462f, -0.99871385f, -0.99929196f, -0.99969882f, -0.99993443f, +0.99999464f, 0.99956632f, 0.99845290f, 0.99665523f, 0.99417448f, +0.99101239f, 0.98717111f, 0.98265326f, 0.97746199f, 0.97160077f, +0.96507365f, 0.95788515f, 0.95004016f, 0.94154406f, 0.93240267f, +0.92262226f, 0.91220951f, 0.90117162f, 0.88951606f, 0.87725091f, +0.86438453f, 0.85092574f, 0.83688372f, 0.82226819f, 0.80708915f, +0.79135692f, 0.77508235f, 0.75827658f, 0.74095112f, 0.72311783f, +0.70478898f, 0.68597710f, 0.66669506f, 0.64695615f, 0.62677377f, +0.60616189f, 0.58513457f, 0.56370622f, 0.54189157f, 0.51970547f, +0.49716324f, 0.47428027f, 0.45107225f, 0.42755505f, 0.40374488f, +0.37965798f, 0.35531086f, 0.33072025f, 0.30590299f, 0.28087607f, +0.25565663f, 0.23026201f, 0.20470956f, 0.17901683f, 0.15320139f, +0.12728097f, 0.10127331f, 0.075196236f, 0.049067631f, 0.022905400f, +-0.0032725304f, -0.029448219f, -0.055603724f, -0.081721120f, -0.10778251f, +-0.13377003f, -0.15966587f, -0.18545228f, -0.21111161f, -0.23662624f, +-0.26197869f, -0.28715160f, -0.31212771f, -0.33688989f, -0.36142120f, +-0.38570482f, -0.40972409f, -0.43346253f, -0.45690393f, -0.48003218f, +-0.50283146f, -0.52528608f, -0.54738069f, -0.56910020f, -0.59042966f, +-0.61135447f, -0.63186026f, -0.65193301f, -0.67155898f, -0.69072473f, +-0.70941705f, -0.72762316f, -0.74533063f, -0.76252723f, -0.77920127f, +-0.79534131f, -0.81093621f, -0.82597536f, -0.84044844f, -0.85434550f, +-0.86765707f, -0.88037395f, -0.89248747f, -0.90398932f, -0.91487163f, +-0.92512697f, -0.93474823f, -0.94372886f, -0.95206273f, -0.95974404f, +-0.96676767f, -0.97312868f, -0.97882277f, -0.98384601f, -0.98819500f, +-0.99186671f, -0.99485862f, -0.99716878f, -0.99879545f, -0.99973762f, }; #endif static const CELTMode mode48000_960_120 = { - 48000, /* Fs */ - 120, /* overlap */ - 21, /* nbEBands */ - 21, /* effEBands */ - {0.85000610f, 0.0000000f, 1.0000000f, 1.0000000f, }, /* preemph */ - eband5ms, /* eBands */ - 3, /* maxLM */ - 8, /* nbShortMdcts */ - 120, /* shortMdctSize */ - 11, /* nbAllocVectors */ - band_allocation, /* allocVectors */ - logN400, /* logN */ - window120, /* window */ - {1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960}, /* mdct */ - {392, cache_index50, cache_bits50, cache_caps50}, /* cache */ +48000, /* Fs */ +120, /* overlap */ +21, /* nbEBands */ +21, /* effEBands */ +{0.85000610f, 0.0000000f, 1.0000000f, 1.0000000f, }, /* preemph */ +eband5ms, /* eBands */ +3, /* maxLM */ +8, /* nbShortMdcts */ +120, /* shortMdctSize */ +11, /* nbAllocVectors */ +band_allocation, /* allocVectors */ +logN400, /* logN */ +window120, /* window */ +{1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960}, /* mdct */ +{392, cache_index50, cache_bits50, cache_caps50}, /* cache */ }; /* List of all the available modes */ #define TOTAL_MODES 1 static const CELTMode * const static_mode_list[TOTAL_MODES] = { - &mode48000_960_120, +&mode48000_960_120, }; diff --git a/src/libopus/celt/static_modes_float_arm_ne10.h b/src/libopus/celt/static_modes_float_arm_ne10.h new file mode 100644 index 0000000..66e1abb --- /dev/null +++ b/src/libopus/celt/static_modes_float_arm_ne10.h @@ -0,0 +1,404 @@ +/* The contents of this file was automatically generated by + * dump_mode_arm_ne10.c with arguments: 48000 960 + * It contains static definitions for some pre-defined modes. */ +#include + +#ifndef NE10_FFT_PARAMS48000_960 +#define NE10_FFT_PARAMS48000_960 +static const ne10_int32_t ne10_factors_480[64] = { +4, 40, 4, 30, 2, 15, 5, 3, 3, 1, 1, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_int32_t ne10_factors_240[64] = { +3, 20, 4, 15, 5, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_int32_t ne10_factors_120[64] = { +3, 10, 2, 15, 5, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_int32_t ne10_factors_60[64] = { +2, 5, 5, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, }; +static const ne10_fft_cpx_float32_t ne10_twiddles_480[480] = { +{1.0000000f,0.0000000f}, {1.0000000f,-0.0000000f}, {1.0000000f,-0.0000000f}, +{1.0000000f,-0.0000000f}, {0.91354543f,-0.40673664f}, {0.66913056f,-0.74314487f}, +{1.0000000f,-0.0000000f}, {0.66913056f,-0.74314487f}, {-0.10452851f,-0.99452192f}, +{1.0000000f,-0.0000000f}, {0.30901697f,-0.95105654f}, {-0.80901700f,-0.58778518f}, +{1.0000000f,-0.0000000f}, {-0.10452851f,-0.99452192f}, {-0.97814757f,0.20791179f}, +{1.0000000f,-0.0000000f}, {0.97814763f,-0.20791170f}, {0.91354543f,-0.40673664f}, +{0.80901700f,-0.58778524f}, {0.66913056f,-0.74314487f}, {0.49999997f,-0.86602545f}, +{0.30901697f,-0.95105654f}, {0.10452842f,-0.99452192f}, {-0.10452851f,-0.99452192f}, +{-0.30901703f,-0.95105648f}, {-0.50000006f,-0.86602533f}, {-0.66913068f,-0.74314475f}, +{-0.80901700f,-0.58778518f}, {-0.91354549f,-0.40673658f}, {-0.97814763f,-0.20791161f}, +{1.0000000f,-0.0000000f}, {0.99862951f,-0.052335959f}, {0.99452192f,-0.10452846f}, +{0.98768836f,-0.15643448f}, {0.97814763f,-0.20791170f}, {0.96592581f,-0.25881904f}, +{0.95105648f,-0.30901700f}, {0.93358040f,-0.35836795f}, {0.91354543f,-0.40673664f}, +{0.89100653f,-0.45399052f}, {0.86602545f,-0.50000000f}, {0.83867055f,-0.54463905f}, +{0.80901700f,-0.58778524f}, {0.77714598f,-0.62932038f}, {0.74314475f,-0.66913062f}, +{0.70710677f,-0.70710683f}, {0.66913056f,-0.74314487f}, {0.62932038f,-0.77714598f}, +{0.58778524f,-0.80901700f}, {0.54463899f,-0.83867055f}, {0.49999997f,-0.86602545f}, +{0.45399052f,-0.89100653f}, {0.40673661f,-0.91354549f}, {0.35836786f,-0.93358046f}, +{0.30901697f,-0.95105654f}, {0.25881907f,-0.96592581f}, {0.20791166f,-0.97814763f}, +{0.15643437f,-0.98768836f}, {0.10452842f,-0.99452192f}, {0.052335974f,-0.99862951f}, +{1.0000000f,-0.0000000f}, {0.99452192f,-0.10452846f}, {0.97814763f,-0.20791170f}, +{0.95105648f,-0.30901700f}, {0.91354543f,-0.40673664f}, {0.86602545f,-0.50000000f}, +{0.80901700f,-0.58778524f}, {0.74314475f,-0.66913062f}, {0.66913056f,-0.74314487f}, +{0.58778524f,-0.80901700f}, {0.49999997f,-0.86602545f}, {0.40673661f,-0.91354549f}, +{0.30901697f,-0.95105654f}, {0.20791166f,-0.97814763f}, {0.10452842f,-0.99452192f}, +{-4.3711388e-08f,-1.0000000f}, {-0.10452851f,-0.99452192f}, {-0.20791174f,-0.97814757f}, +{-0.30901703f,-0.95105648f}, {-0.40673670f,-0.91354543f}, {-0.50000006f,-0.86602533f}, +{-0.58778518f,-0.80901700f}, {-0.66913068f,-0.74314475f}, {-0.74314493f,-0.66913044f}, +{-0.80901700f,-0.58778518f}, {-0.86602539f,-0.50000006f}, {-0.91354549f,-0.40673658f}, +{-0.95105654f,-0.30901679f}, {-0.97814763f,-0.20791161f}, {-0.99452192f,-0.10452849f}, +{1.0000000f,-0.0000000f}, {0.98768836f,-0.15643448f}, {0.95105648f,-0.30901700f}, +{0.89100653f,-0.45399052f}, {0.80901700f,-0.58778524f}, {0.70710677f,-0.70710683f}, +{0.58778524f,-0.80901700f}, {0.45399052f,-0.89100653f}, {0.30901697f,-0.95105654f}, +{0.15643437f,-0.98768836f}, {-4.3711388e-08f,-1.0000000f}, {-0.15643445f,-0.98768836f}, +{-0.30901703f,-0.95105648f}, {-0.45399061f,-0.89100647f}, {-0.58778518f,-0.80901700f}, +{-0.70710677f,-0.70710677f}, {-0.80901700f,-0.58778518f}, {-0.89100659f,-0.45399037f}, +{-0.95105654f,-0.30901679f}, {-0.98768836f,-0.15643445f}, {-1.0000000f,8.7422777e-08f}, +{-0.98768830f,0.15643461f}, {-0.95105654f,0.30901697f}, {-0.89100653f,0.45399055f}, +{-0.80901694f,0.58778536f}, {-0.70710665f,0.70710689f}, {-0.58778507f,0.80901712f}, +{-0.45399022f,0.89100665f}, {-0.30901709f,0.95105648f}, {-0.15643452f,0.98768830f}, +{1.0000000f,-0.0000000f}, {0.99991435f,-0.013089596f}, {0.99965733f,-0.026176950f}, +{0.99922901f,-0.039259817f}, {0.99862951f,-0.052335959f}, {0.99785894f,-0.065403134f}, +{0.99691731f,-0.078459099f}, {0.99580491f,-0.091501623f}, {0.99452192f,-0.10452846f}, +{0.99306846f,-0.11753740f}, {0.99144489f,-0.13052620f}, {0.98965138f,-0.14349262f}, +{0.98768836f,-0.15643448f}, {0.98555607f,-0.16934951f}, {0.98325491f,-0.18223552f}, +{0.98078525f,-0.19509032f}, {0.97814763f,-0.20791170f}, {0.97534233f,-0.22069745f}, +{0.97236991f,-0.23344538f}, {0.96923089f,-0.24615330f}, {0.96592581f,-0.25881904f}, +{0.96245521f,-0.27144045f}, {0.95881975f,-0.28401536f}, {0.95501995f,-0.29654160f}, +{0.95105648f,-0.30901700f}, {0.94693011f,-0.32143945f}, {0.94264150f,-0.33380687f}, +{0.93819129f,-0.34611708f}, {0.93358040f,-0.35836795f}, {0.92880952f,-0.37055743f}, +{0.92387956f,-0.38268346f}, {0.91879117f,-0.39474389f}, {0.91354543f,-0.40673664f}, +{0.90814316f,-0.41865975f}, {0.90258527f,-0.43051112f}, {0.89687270f,-0.44228873f}, +{0.89100653f,-0.45399052f}, {0.88498765f,-0.46561453f}, {0.87881708f,-0.47715878f}, +{0.87249601f,-0.48862126f}, {0.86602545f,-0.50000000f}, {0.85940641f,-0.51129311f}, +{0.85264015f,-0.52249855f}, {0.84572786f,-0.53361452f}, {0.83867055f,-0.54463905f}, +{0.83146960f,-0.55557024f}, {0.82412618f,-0.56640625f}, {0.81664151f,-0.57714522f}, +{0.80901700f,-0.58778524f}, {0.80125380f,-0.59832460f}, {0.79335332f,-0.60876143f}, +{0.78531694f,-0.61909395f}, {0.77714598f,-0.62932038f}, {0.76884180f,-0.63943899f}, +{0.76040596f,-0.64944810f}, {0.75183982f,-0.65934587f}, {0.74314475f,-0.66913062f}, +{0.73432249f,-0.67880076f}, {0.72537434f,-0.68835455f}, {0.71630192f,-0.69779050f}, +{0.70710677f,-0.70710683f}, {0.69779044f,-0.71630198f}, {0.68835455f,-0.72537440f}, +{0.67880070f,-0.73432255f}, {0.66913056f,-0.74314487f}, {0.65934581f,-0.75183982f}, +{0.64944804f,-0.76040596f}, {0.63943899f,-0.76884186f}, {0.62932038f,-0.77714598f}, +{0.61909395f,-0.78531694f}, {0.60876137f,-0.79335338f}, {0.59832460f,-0.80125386f}, +{0.58778524f,-0.80901700f}, {0.57714516f,-0.81664151f}, {0.56640625f,-0.82412618f}, +{0.55557019f,-0.83146960f}, {0.54463899f,-0.83867055f}, {0.53361452f,-0.84572786f}, +{0.52249849f,-0.85264015f}, {0.51129311f,-0.85940641f}, {0.49999997f,-0.86602545f}, +{0.48862118f,-0.87249601f}, {0.47715876f,-0.87881708f}, {0.46561447f,-0.88498765f}, +{0.45399052f,-0.89100653f}, {0.44228867f,-0.89687276f}, {0.43051103f,-0.90258533f}, +{0.41865975f,-0.90814316f}, {0.40673661f,-0.91354549f}, {0.39474380f,-0.91879129f}, +{0.38268343f,-0.92387956f}, {0.37055740f,-0.92880958f}, {0.35836786f,-0.93358046f}, +{0.34611705f,-0.93819135f}, {0.33380681f,-0.94264150f}, {0.32143947f,-0.94693011f}, +{0.30901697f,-0.95105654f}, {0.29654151f,-0.95501995f}, {0.28401533f,-0.95881975f}, +{0.27144039f,-0.96245527f}, {0.25881907f,-0.96592581f}, {0.24615327f,-0.96923089f}, +{0.23344530f,-0.97236991f}, {0.22069745f,-0.97534233f}, {0.20791166f,-0.97814763f}, +{0.19509023f,-0.98078531f}, {0.18223552f,-0.98325491f}, {0.16934945f,-0.98555607f}, +{0.15643437f,-0.98768836f}, {0.14349259f,-0.98965138f}, {0.13052613f,-0.99144489f}, +{0.11753740f,-0.99306846f}, {0.10452842f,-0.99452192f}, {0.091501534f,-0.99580491f}, +{0.078459084f,-0.99691731f}, {0.065403074f,-0.99785894f}, {0.052335974f,-0.99862951f}, +{0.039259788f,-0.99922901f}, {0.026176875f,-0.99965733f}, {0.013089597f,-0.99991435f}, +{1.0000000f,-0.0000000f}, {0.99965733f,-0.026176950f}, {0.99862951f,-0.052335959f}, +{0.99691731f,-0.078459099f}, {0.99452192f,-0.10452846f}, {0.99144489f,-0.13052620f}, +{0.98768836f,-0.15643448f}, {0.98325491f,-0.18223552f}, {0.97814763f,-0.20791170f}, +{0.97236991f,-0.23344538f}, {0.96592581f,-0.25881904f}, {0.95881975f,-0.28401536f}, +{0.95105648f,-0.30901700f}, {0.94264150f,-0.33380687f}, {0.93358040f,-0.35836795f}, +{0.92387956f,-0.38268346f}, {0.91354543f,-0.40673664f}, {0.90258527f,-0.43051112f}, +{0.89100653f,-0.45399052f}, {0.87881708f,-0.47715878f}, {0.86602545f,-0.50000000f}, +{0.85264015f,-0.52249855f}, {0.83867055f,-0.54463905f}, {0.82412618f,-0.56640625f}, +{0.80901700f,-0.58778524f}, {0.79335332f,-0.60876143f}, {0.77714598f,-0.62932038f}, +{0.76040596f,-0.64944810f}, {0.74314475f,-0.66913062f}, {0.72537434f,-0.68835455f}, +{0.70710677f,-0.70710683f}, {0.68835455f,-0.72537440f}, {0.66913056f,-0.74314487f}, +{0.64944804f,-0.76040596f}, {0.62932038f,-0.77714598f}, {0.60876137f,-0.79335338f}, +{0.58778524f,-0.80901700f}, {0.56640625f,-0.82412618f}, {0.54463899f,-0.83867055f}, +{0.52249849f,-0.85264015f}, {0.49999997f,-0.86602545f}, {0.47715876f,-0.87881708f}, +{0.45399052f,-0.89100653f}, {0.43051103f,-0.90258533f}, {0.40673661f,-0.91354549f}, +{0.38268343f,-0.92387956f}, {0.35836786f,-0.93358046f}, {0.33380681f,-0.94264150f}, +{0.30901697f,-0.95105654f}, {0.28401533f,-0.95881975f}, {0.25881907f,-0.96592581f}, +{0.23344530f,-0.97236991f}, {0.20791166f,-0.97814763f}, {0.18223552f,-0.98325491f}, +{0.15643437f,-0.98768836f}, {0.13052613f,-0.99144489f}, {0.10452842f,-0.99452192f}, +{0.078459084f,-0.99691731f}, {0.052335974f,-0.99862951f}, {0.026176875f,-0.99965733f}, +{-4.3711388e-08f,-1.0000000f}, {-0.026176963f,-0.99965733f}, {-0.052336060f,-0.99862951f}, +{-0.078459173f,-0.99691731f}, {-0.10452851f,-0.99452192f}, {-0.13052621f,-0.99144489f}, +{-0.15643445f,-0.98768836f}, {-0.18223560f,-0.98325491f}, {-0.20791174f,-0.97814757f}, +{-0.23344538f,-0.97236991f}, {-0.25881916f,-0.96592581f}, {-0.28401542f,-0.95881969f}, +{-0.30901703f,-0.95105648f}, {-0.33380687f,-0.94264150f}, {-0.35836795f,-0.93358040f}, +{-0.38268352f,-0.92387950f}, {-0.40673670f,-0.91354543f}, {-0.43051112f,-0.90258527f}, +{-0.45399061f,-0.89100647f}, {-0.47715873f,-0.87881708f}, {-0.50000006f,-0.86602533f}, +{-0.52249867f,-0.85264009f}, {-0.54463905f,-0.83867055f}, {-0.56640631f,-0.82412612f}, +{-0.58778518f,-0.80901700f}, {-0.60876143f,-0.79335332f}, {-0.62932050f,-0.77714586f}, +{-0.64944804f,-0.76040596f}, {-0.66913068f,-0.74314475f}, {-0.68835467f,-0.72537428f}, +{-0.70710677f,-0.70710677f}, {-0.72537446f,-0.68835449f}, {-0.74314493f,-0.66913044f}, +{-0.76040596f,-0.64944804f}, {-0.77714604f,-0.62932026f}, {-0.79335332f,-0.60876143f}, +{-0.80901700f,-0.58778518f}, {-0.82412624f,-0.56640613f}, {-0.83867055f,-0.54463899f}, +{-0.85264021f,-0.52249849f}, {-0.86602539f,-0.50000006f}, {-0.87881714f,-0.47715873f}, +{-0.89100659f,-0.45399037f}, {-0.90258527f,-0.43051112f}, {-0.91354549f,-0.40673658f}, +{-0.92387956f,-0.38268328f}, {-0.93358040f,-0.35836792f}, {-0.94264150f,-0.33380675f}, +{-0.95105654f,-0.30901679f}, {-0.95881975f,-0.28401530f}, {-0.96592587f,-0.25881892f}, +{-0.97236991f,-0.23344538f}, {-0.97814763f,-0.20791161f}, {-0.98325491f,-0.18223536f}, +{-0.98768836f,-0.15643445f}, {-0.99144489f,-0.13052608f}, {-0.99452192f,-0.10452849f}, +{-0.99691737f,-0.078459039f}, {-0.99862957f,-0.052335810f}, {-0.99965733f,-0.026176952f}, +{1.0000000f,-0.0000000f}, {0.99922901f,-0.039259817f}, {0.99691731f,-0.078459099f}, +{0.99306846f,-0.11753740f}, {0.98768836f,-0.15643448f}, {0.98078525f,-0.19509032f}, +{0.97236991f,-0.23344538f}, {0.96245521f,-0.27144045f}, {0.95105648f,-0.30901700f}, +{0.93819129f,-0.34611708f}, {0.92387956f,-0.38268346f}, {0.90814316f,-0.41865975f}, +{0.89100653f,-0.45399052f}, {0.87249601f,-0.48862126f}, {0.85264015f,-0.52249855f}, +{0.83146960f,-0.55557024f}, {0.80901700f,-0.58778524f}, {0.78531694f,-0.61909395f}, +{0.76040596f,-0.64944810f}, {0.73432249f,-0.67880076f}, {0.70710677f,-0.70710683f}, +{0.67880070f,-0.73432255f}, {0.64944804f,-0.76040596f}, {0.61909395f,-0.78531694f}, +{0.58778524f,-0.80901700f}, {0.55557019f,-0.83146960f}, {0.52249849f,-0.85264015f}, +{0.48862118f,-0.87249601f}, {0.45399052f,-0.89100653f}, {0.41865975f,-0.90814316f}, +{0.38268343f,-0.92387956f}, {0.34611705f,-0.93819135f}, {0.30901697f,-0.95105654f}, +{0.27144039f,-0.96245527f}, {0.23344530f,-0.97236991f}, {0.19509023f,-0.98078531f}, +{0.15643437f,-0.98768836f}, {0.11753740f,-0.99306846f}, {0.078459084f,-0.99691731f}, +{0.039259788f,-0.99922901f}, {-4.3711388e-08f,-1.0000000f}, {-0.039259877f,-0.99922901f}, +{-0.078459173f,-0.99691731f}, {-0.11753749f,-0.99306846f}, {-0.15643445f,-0.98768836f}, +{-0.19509032f,-0.98078525f}, {-0.23344538f,-0.97236991f}, {-0.27144048f,-0.96245521f}, +{-0.30901703f,-0.95105648f}, {-0.34611711f,-0.93819129f}, {-0.38268352f,-0.92387950f}, +{-0.41865984f,-0.90814310f}, {-0.45399061f,-0.89100647f}, {-0.48862135f,-0.87249595f}, +{-0.52249867f,-0.85264009f}, {-0.55557036f,-0.83146954f}, {-0.58778518f,-0.80901700f}, +{-0.61909389f,-0.78531694f}, {-0.64944804f,-0.76040596f}, {-0.67880076f,-0.73432249f}, +{-0.70710677f,-0.70710677f}, {-0.73432249f,-0.67880070f}, {-0.76040596f,-0.64944804f}, +{-0.78531694f,-0.61909389f}, {-0.80901700f,-0.58778518f}, {-0.83146966f,-0.55557019f}, +{-0.85264021f,-0.52249849f}, {-0.87249607f,-0.48862115f}, {-0.89100659f,-0.45399037f}, +{-0.90814322f,-0.41865960f}, {-0.92387956f,-0.38268328f}, {-0.93819135f,-0.34611690f}, +{-0.95105654f,-0.30901679f}, {-0.96245521f,-0.27144048f}, {-0.97236991f,-0.23344538f}, +{-0.98078531f,-0.19509031f}, {-0.98768836f,-0.15643445f}, {-0.99306846f,-0.11753736f}, +{-0.99691737f,-0.078459039f}, {-0.99922901f,-0.039259743f}, {-1.0000000f,8.7422777e-08f}, +{-0.99922901f,0.039259918f}, {-0.99691731f,0.078459218f}, {-0.99306846f,0.11753753f}, +{-0.98768830f,0.15643461f}, {-0.98078525f,0.19509049f}, {-0.97236985f,0.23344554f}, +{-0.96245515f,0.27144065f}, {-0.95105654f,0.30901697f}, {-0.93819135f,0.34611705f}, +{-0.92387956f,0.38268346f}, {-0.90814316f,0.41865975f}, {-0.89100653f,0.45399055f}, +{-0.87249601f,0.48862129f}, {-0.85264015f,0.52249861f}, {-0.83146960f,0.55557030f}, +{-0.80901694f,0.58778536f}, {-0.78531688f,0.61909401f}, {-0.76040590f,0.64944816f}, +{-0.73432243f,0.67880082f}, {-0.70710665f,0.70710689f}, {-0.67880058f,0.73432261f}, +{-0.64944792f,0.76040608f}, {-0.61909378f,0.78531706f}, {-0.58778507f,0.80901712f}, +{-0.55557001f,0.83146977f}, {-0.52249837f,0.85264033f}, {-0.48862100f,0.87249613f}, +{-0.45399022f,0.89100665f}, {-0.41865945f,0.90814328f}, {-0.38268313f,0.92387968f}, +{-0.34611672f,0.93819147f}, {-0.30901709f,0.95105648f}, {-0.27144054f,0.96245521f}, +{-0.23344545f,0.97236991f}, {-0.19509038f,0.98078525f}, {-0.15643452f,0.98768830f}, +{-0.11753743f,0.99306846f}, {-0.078459114f,0.99691731f}, {-0.039259821f,0.99922901f}, +}; +static const ne10_fft_cpx_float32_t ne10_twiddles_240[240] = { +{1.0000000f,0.0000000f}, {1.0000000f,-0.0000000f}, {1.0000000f,-0.0000000f}, +{1.0000000f,-0.0000000f}, {0.91354543f,-0.40673664f}, {0.66913056f,-0.74314487f}, +{1.0000000f,-0.0000000f}, {0.66913056f,-0.74314487f}, {-0.10452851f,-0.99452192f}, +{1.0000000f,-0.0000000f}, {0.30901697f,-0.95105654f}, {-0.80901700f,-0.58778518f}, +{1.0000000f,-0.0000000f}, {-0.10452851f,-0.99452192f}, {-0.97814757f,0.20791179f}, +{1.0000000f,-0.0000000f}, {0.99452192f,-0.10452846f}, {0.97814763f,-0.20791170f}, +{0.95105648f,-0.30901700f}, {0.91354543f,-0.40673664f}, {0.86602545f,-0.50000000f}, +{0.80901700f,-0.58778524f}, {0.74314475f,-0.66913062f}, {0.66913056f,-0.74314487f}, +{0.58778524f,-0.80901700f}, {0.49999997f,-0.86602545f}, {0.40673661f,-0.91354549f}, +{0.30901697f,-0.95105654f}, {0.20791166f,-0.97814763f}, {0.10452842f,-0.99452192f}, +{1.0000000f,-0.0000000f}, {0.97814763f,-0.20791170f}, {0.91354543f,-0.40673664f}, +{0.80901700f,-0.58778524f}, {0.66913056f,-0.74314487f}, {0.49999997f,-0.86602545f}, +{0.30901697f,-0.95105654f}, {0.10452842f,-0.99452192f}, {-0.10452851f,-0.99452192f}, +{-0.30901703f,-0.95105648f}, {-0.50000006f,-0.86602533f}, {-0.66913068f,-0.74314475f}, +{-0.80901700f,-0.58778518f}, {-0.91354549f,-0.40673658f}, {-0.97814763f,-0.20791161f}, +{1.0000000f,-0.0000000f}, {0.95105648f,-0.30901700f}, {0.80901700f,-0.58778524f}, +{0.58778524f,-0.80901700f}, {0.30901697f,-0.95105654f}, {-4.3711388e-08f,-1.0000000f}, +{-0.30901703f,-0.95105648f}, {-0.58778518f,-0.80901700f}, {-0.80901700f,-0.58778518f}, +{-0.95105654f,-0.30901679f}, {-1.0000000f,8.7422777e-08f}, {-0.95105654f,0.30901697f}, +{-0.80901694f,0.58778536f}, {-0.58778507f,0.80901712f}, {-0.30901709f,0.95105648f}, +{1.0000000f,-0.0000000f}, {0.99965733f,-0.026176950f}, {0.99862951f,-0.052335959f}, +{0.99691731f,-0.078459099f}, {0.99452192f,-0.10452846f}, {0.99144489f,-0.13052620f}, +{0.98768836f,-0.15643448f}, {0.98325491f,-0.18223552f}, {0.97814763f,-0.20791170f}, +{0.97236991f,-0.23344538f}, {0.96592581f,-0.25881904f}, {0.95881975f,-0.28401536f}, +{0.95105648f,-0.30901700f}, {0.94264150f,-0.33380687f}, {0.93358040f,-0.35836795f}, +{0.92387956f,-0.38268346f}, {0.91354543f,-0.40673664f}, {0.90258527f,-0.43051112f}, +{0.89100653f,-0.45399052f}, {0.87881708f,-0.47715878f}, {0.86602545f,-0.50000000f}, +{0.85264015f,-0.52249855f}, {0.83867055f,-0.54463905f}, {0.82412618f,-0.56640625f}, +{0.80901700f,-0.58778524f}, {0.79335332f,-0.60876143f}, {0.77714598f,-0.62932038f}, +{0.76040596f,-0.64944810f}, {0.74314475f,-0.66913062f}, {0.72537434f,-0.68835455f}, +{0.70710677f,-0.70710683f}, {0.68835455f,-0.72537440f}, {0.66913056f,-0.74314487f}, +{0.64944804f,-0.76040596f}, {0.62932038f,-0.77714598f}, {0.60876137f,-0.79335338f}, +{0.58778524f,-0.80901700f}, {0.56640625f,-0.82412618f}, {0.54463899f,-0.83867055f}, +{0.52249849f,-0.85264015f}, {0.49999997f,-0.86602545f}, {0.47715876f,-0.87881708f}, +{0.45399052f,-0.89100653f}, {0.43051103f,-0.90258533f}, {0.40673661f,-0.91354549f}, +{0.38268343f,-0.92387956f}, {0.35836786f,-0.93358046f}, {0.33380681f,-0.94264150f}, +{0.30901697f,-0.95105654f}, {0.28401533f,-0.95881975f}, {0.25881907f,-0.96592581f}, +{0.23344530f,-0.97236991f}, {0.20791166f,-0.97814763f}, {0.18223552f,-0.98325491f}, +{0.15643437f,-0.98768836f}, {0.13052613f,-0.99144489f}, {0.10452842f,-0.99452192f}, +{0.078459084f,-0.99691731f}, {0.052335974f,-0.99862951f}, {0.026176875f,-0.99965733f}, +{1.0000000f,-0.0000000f}, {0.99862951f,-0.052335959f}, {0.99452192f,-0.10452846f}, +{0.98768836f,-0.15643448f}, {0.97814763f,-0.20791170f}, {0.96592581f,-0.25881904f}, +{0.95105648f,-0.30901700f}, {0.93358040f,-0.35836795f}, {0.91354543f,-0.40673664f}, +{0.89100653f,-0.45399052f}, {0.86602545f,-0.50000000f}, {0.83867055f,-0.54463905f}, +{0.80901700f,-0.58778524f}, {0.77714598f,-0.62932038f}, {0.74314475f,-0.66913062f}, +{0.70710677f,-0.70710683f}, {0.66913056f,-0.74314487f}, {0.62932038f,-0.77714598f}, +{0.58778524f,-0.80901700f}, {0.54463899f,-0.83867055f}, {0.49999997f,-0.86602545f}, +{0.45399052f,-0.89100653f}, {0.40673661f,-0.91354549f}, {0.35836786f,-0.93358046f}, +{0.30901697f,-0.95105654f}, {0.25881907f,-0.96592581f}, {0.20791166f,-0.97814763f}, +{0.15643437f,-0.98768836f}, {0.10452842f,-0.99452192f}, {0.052335974f,-0.99862951f}, +{-4.3711388e-08f,-1.0000000f}, {-0.052336060f,-0.99862951f}, {-0.10452851f,-0.99452192f}, +{-0.15643445f,-0.98768836f}, {-0.20791174f,-0.97814757f}, {-0.25881916f,-0.96592581f}, +{-0.30901703f,-0.95105648f}, {-0.35836795f,-0.93358040f}, {-0.40673670f,-0.91354543f}, +{-0.45399061f,-0.89100647f}, {-0.50000006f,-0.86602533f}, {-0.54463905f,-0.83867055f}, +{-0.58778518f,-0.80901700f}, {-0.62932050f,-0.77714586f}, {-0.66913068f,-0.74314475f}, +{-0.70710677f,-0.70710677f}, {-0.74314493f,-0.66913044f}, {-0.77714604f,-0.62932026f}, +{-0.80901700f,-0.58778518f}, {-0.83867055f,-0.54463899f}, {-0.86602539f,-0.50000006f}, +{-0.89100659f,-0.45399037f}, {-0.91354549f,-0.40673658f}, {-0.93358040f,-0.35836792f}, +{-0.95105654f,-0.30901679f}, {-0.96592587f,-0.25881892f}, {-0.97814763f,-0.20791161f}, +{-0.98768836f,-0.15643445f}, {-0.99452192f,-0.10452849f}, {-0.99862957f,-0.052335810f}, +{1.0000000f,-0.0000000f}, {0.99691731f,-0.078459099f}, {0.98768836f,-0.15643448f}, +{0.97236991f,-0.23344538f}, {0.95105648f,-0.30901700f}, {0.92387956f,-0.38268346f}, +{0.89100653f,-0.45399052f}, {0.85264015f,-0.52249855f}, {0.80901700f,-0.58778524f}, +{0.76040596f,-0.64944810f}, {0.70710677f,-0.70710683f}, {0.64944804f,-0.76040596f}, +{0.58778524f,-0.80901700f}, {0.52249849f,-0.85264015f}, {0.45399052f,-0.89100653f}, +{0.38268343f,-0.92387956f}, {0.30901697f,-0.95105654f}, {0.23344530f,-0.97236991f}, +{0.15643437f,-0.98768836f}, {0.078459084f,-0.99691731f}, {-4.3711388e-08f,-1.0000000f}, +{-0.078459173f,-0.99691731f}, {-0.15643445f,-0.98768836f}, {-0.23344538f,-0.97236991f}, +{-0.30901703f,-0.95105648f}, {-0.38268352f,-0.92387950f}, {-0.45399061f,-0.89100647f}, +{-0.52249867f,-0.85264009f}, {-0.58778518f,-0.80901700f}, {-0.64944804f,-0.76040596f}, +{-0.70710677f,-0.70710677f}, {-0.76040596f,-0.64944804f}, {-0.80901700f,-0.58778518f}, +{-0.85264021f,-0.52249849f}, {-0.89100659f,-0.45399037f}, {-0.92387956f,-0.38268328f}, +{-0.95105654f,-0.30901679f}, {-0.97236991f,-0.23344538f}, {-0.98768836f,-0.15643445f}, +{-0.99691737f,-0.078459039f}, {-1.0000000f,8.7422777e-08f}, {-0.99691731f,0.078459218f}, +{-0.98768830f,0.15643461f}, {-0.97236985f,0.23344554f}, {-0.95105654f,0.30901697f}, +{-0.92387956f,0.38268346f}, {-0.89100653f,0.45399055f}, {-0.85264015f,0.52249861f}, +{-0.80901694f,0.58778536f}, {-0.76040590f,0.64944816f}, {-0.70710665f,0.70710689f}, +{-0.64944792f,0.76040608f}, {-0.58778507f,0.80901712f}, {-0.52249837f,0.85264033f}, +{-0.45399022f,0.89100665f}, {-0.38268313f,0.92387968f}, {-0.30901709f,0.95105648f}, +{-0.23344545f,0.97236991f}, {-0.15643452f,0.98768830f}, {-0.078459114f,0.99691731f}, +}; +static const ne10_fft_cpx_float32_t ne10_twiddles_120[120] = { +{1.0000000f,0.0000000f}, {1.0000000f,-0.0000000f}, {1.0000000f,-0.0000000f}, +{1.0000000f,-0.0000000f}, {0.91354543f,-0.40673664f}, {0.66913056f,-0.74314487f}, +{1.0000000f,-0.0000000f}, {0.66913056f,-0.74314487f}, {-0.10452851f,-0.99452192f}, +{1.0000000f,-0.0000000f}, {0.30901697f,-0.95105654f}, {-0.80901700f,-0.58778518f}, +{1.0000000f,-0.0000000f}, {-0.10452851f,-0.99452192f}, {-0.97814757f,0.20791179f}, +{1.0000000f,-0.0000000f}, {0.97814763f,-0.20791170f}, {0.91354543f,-0.40673664f}, +{0.80901700f,-0.58778524f}, {0.66913056f,-0.74314487f}, {0.49999997f,-0.86602545f}, +{0.30901697f,-0.95105654f}, {0.10452842f,-0.99452192f}, {-0.10452851f,-0.99452192f}, +{-0.30901703f,-0.95105648f}, {-0.50000006f,-0.86602533f}, {-0.66913068f,-0.74314475f}, +{-0.80901700f,-0.58778518f}, {-0.91354549f,-0.40673658f}, {-0.97814763f,-0.20791161f}, +{1.0000000f,-0.0000000f}, {0.99862951f,-0.052335959f}, {0.99452192f,-0.10452846f}, +{0.98768836f,-0.15643448f}, {0.97814763f,-0.20791170f}, {0.96592581f,-0.25881904f}, +{0.95105648f,-0.30901700f}, {0.93358040f,-0.35836795f}, {0.91354543f,-0.40673664f}, +{0.89100653f,-0.45399052f}, {0.86602545f,-0.50000000f}, {0.83867055f,-0.54463905f}, +{0.80901700f,-0.58778524f}, {0.77714598f,-0.62932038f}, {0.74314475f,-0.66913062f}, +{0.70710677f,-0.70710683f}, {0.66913056f,-0.74314487f}, {0.62932038f,-0.77714598f}, +{0.58778524f,-0.80901700f}, {0.54463899f,-0.83867055f}, {0.49999997f,-0.86602545f}, +{0.45399052f,-0.89100653f}, {0.40673661f,-0.91354549f}, {0.35836786f,-0.93358046f}, +{0.30901697f,-0.95105654f}, {0.25881907f,-0.96592581f}, {0.20791166f,-0.97814763f}, +{0.15643437f,-0.98768836f}, {0.10452842f,-0.99452192f}, {0.052335974f,-0.99862951f}, +{1.0000000f,-0.0000000f}, {0.99452192f,-0.10452846f}, {0.97814763f,-0.20791170f}, +{0.95105648f,-0.30901700f}, {0.91354543f,-0.40673664f}, {0.86602545f,-0.50000000f}, +{0.80901700f,-0.58778524f}, {0.74314475f,-0.66913062f}, {0.66913056f,-0.74314487f}, +{0.58778524f,-0.80901700f}, {0.49999997f,-0.86602545f}, {0.40673661f,-0.91354549f}, +{0.30901697f,-0.95105654f}, {0.20791166f,-0.97814763f}, {0.10452842f,-0.99452192f}, +{-4.3711388e-08f,-1.0000000f}, {-0.10452851f,-0.99452192f}, {-0.20791174f,-0.97814757f}, +{-0.30901703f,-0.95105648f}, {-0.40673670f,-0.91354543f}, {-0.50000006f,-0.86602533f}, +{-0.58778518f,-0.80901700f}, {-0.66913068f,-0.74314475f}, {-0.74314493f,-0.66913044f}, +{-0.80901700f,-0.58778518f}, {-0.86602539f,-0.50000006f}, {-0.91354549f,-0.40673658f}, +{-0.95105654f,-0.30901679f}, {-0.97814763f,-0.20791161f}, {-0.99452192f,-0.10452849f}, +{1.0000000f,-0.0000000f}, {0.98768836f,-0.15643448f}, {0.95105648f,-0.30901700f}, +{0.89100653f,-0.45399052f}, {0.80901700f,-0.58778524f}, {0.70710677f,-0.70710683f}, +{0.58778524f,-0.80901700f}, {0.45399052f,-0.89100653f}, {0.30901697f,-0.95105654f}, +{0.15643437f,-0.98768836f}, {-4.3711388e-08f,-1.0000000f}, {-0.15643445f,-0.98768836f}, +{-0.30901703f,-0.95105648f}, {-0.45399061f,-0.89100647f}, {-0.58778518f,-0.80901700f}, +{-0.70710677f,-0.70710677f}, {-0.80901700f,-0.58778518f}, {-0.89100659f,-0.45399037f}, +{-0.95105654f,-0.30901679f}, {-0.98768836f,-0.15643445f}, {-1.0000000f,8.7422777e-08f}, +{-0.98768830f,0.15643461f}, {-0.95105654f,0.30901697f}, {-0.89100653f,0.45399055f}, +{-0.80901694f,0.58778536f}, {-0.70710665f,0.70710689f}, {-0.58778507f,0.80901712f}, +{-0.45399022f,0.89100665f}, {-0.30901709f,0.95105648f}, {-0.15643452f,0.98768830f}, +}; +static const ne10_fft_cpx_float32_t ne10_twiddles_60[60] = { +{1.0000000f,0.0000000f}, {1.0000000f,-0.0000000f}, {1.0000000f,-0.0000000f}, +{1.0000000f,-0.0000000f}, {0.91354543f,-0.40673664f}, {0.66913056f,-0.74314487f}, +{1.0000000f,-0.0000000f}, {0.66913056f,-0.74314487f}, {-0.10452851f,-0.99452192f}, +{1.0000000f,-0.0000000f}, {0.30901697f,-0.95105654f}, {-0.80901700f,-0.58778518f}, +{1.0000000f,-0.0000000f}, {-0.10452851f,-0.99452192f}, {-0.97814757f,0.20791179f}, +{1.0000000f,-0.0000000f}, {0.99452192f,-0.10452846f}, {0.97814763f,-0.20791170f}, +{0.95105648f,-0.30901700f}, {0.91354543f,-0.40673664f}, {0.86602545f,-0.50000000f}, +{0.80901700f,-0.58778524f}, {0.74314475f,-0.66913062f}, {0.66913056f,-0.74314487f}, +{0.58778524f,-0.80901700f}, {0.49999997f,-0.86602545f}, {0.40673661f,-0.91354549f}, +{0.30901697f,-0.95105654f}, {0.20791166f,-0.97814763f}, {0.10452842f,-0.99452192f}, +{1.0000000f,-0.0000000f}, {0.97814763f,-0.20791170f}, {0.91354543f,-0.40673664f}, +{0.80901700f,-0.58778524f}, {0.66913056f,-0.74314487f}, {0.49999997f,-0.86602545f}, +{0.30901697f,-0.95105654f}, {0.10452842f,-0.99452192f}, {-0.10452851f,-0.99452192f}, +{-0.30901703f,-0.95105648f}, {-0.50000006f,-0.86602533f}, {-0.66913068f,-0.74314475f}, +{-0.80901700f,-0.58778518f}, {-0.91354549f,-0.40673658f}, {-0.97814763f,-0.20791161f}, +{1.0000000f,-0.0000000f}, {0.95105648f,-0.30901700f}, {0.80901700f,-0.58778524f}, +{0.58778524f,-0.80901700f}, {0.30901697f,-0.95105654f}, {-4.3711388e-08f,-1.0000000f}, +{-0.30901703f,-0.95105648f}, {-0.58778518f,-0.80901700f}, {-0.80901700f,-0.58778518f}, +{-0.95105654f,-0.30901679f}, {-1.0000000f,8.7422777e-08f}, {-0.95105654f,0.30901697f}, +{-0.80901694f,0.58778536f}, {-0.58778507f,0.80901712f}, {-0.30901709f,0.95105648f}, +}; +static const ne10_fft_state_float32_t ne10_fft_state_float32_t_480 = { +120, +(ne10_int32_t *)ne10_factors_480, +(ne10_fft_cpx_float32_t *)ne10_twiddles_480, +NULL, +(ne10_fft_cpx_float32_t *)&ne10_twiddles_480[120], +/* is_forward_scaled = true */ +(ne10_int32_t) 1, +/* is_backward_scaled = false */ +(ne10_int32_t) 0, +}; +static const arch_fft_state cfg_arch_480 = { +1, +(void *)&ne10_fft_state_float32_t_480, +}; + +static const ne10_fft_state_float32_t ne10_fft_state_float32_t_240 = { +60, +(ne10_int32_t *)ne10_factors_240, +(ne10_fft_cpx_float32_t *)ne10_twiddles_240, +NULL, +(ne10_fft_cpx_float32_t *)&ne10_twiddles_240[60], +/* is_forward_scaled = true */ +(ne10_int32_t) 1, +/* is_backward_scaled = false */ +(ne10_int32_t) 0, +}; +static const arch_fft_state cfg_arch_240 = { +1, +(void *)&ne10_fft_state_float32_t_240, +}; + +static const ne10_fft_state_float32_t ne10_fft_state_float32_t_120 = { +30, +(ne10_int32_t *)ne10_factors_120, +(ne10_fft_cpx_float32_t *)ne10_twiddles_120, +NULL, +(ne10_fft_cpx_float32_t *)&ne10_twiddles_120[30], +/* is_forward_scaled = true */ +(ne10_int32_t) 1, +/* is_backward_scaled = false */ +(ne10_int32_t) 0, +}; +static const arch_fft_state cfg_arch_120 = { +1, +(void *)&ne10_fft_state_float32_t_120, +}; + +static const ne10_fft_state_float32_t ne10_fft_state_float32_t_60 = { +15, +(ne10_int32_t *)ne10_factors_60, +(ne10_fft_cpx_float32_t *)ne10_twiddles_60, +NULL, +(ne10_fft_cpx_float32_t *)&ne10_twiddles_60[15], +/* is_forward_scaled = true */ +(ne10_int32_t) 1, +/* is_backward_scaled = false */ +(ne10_int32_t) 0, +}; +static const arch_fft_state cfg_arch_60 = { +1, +(void *)&ne10_fft_state_float32_t_60, +}; + +#endif /* end NE10_FFT_PARAMS48000_960 */ diff --git a/src/libopus/celt/vq.c b/src/libopus/celt/vq.c index 78ef99b..81321d9 100644 --- a/src/libopus/celt/vq.c +++ b/src/libopus/celt/vq.c @@ -1,34 +1,34 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Written by Jean-Marc Valin */ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Written by Jean-Marc Valin */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "mathops.h" #include "cwrs.h" @@ -44,382 +44,399 @@ #endif #ifndef OVERRIDE_vq_exp_rotation1 -static void exp_rotation1(celt_norm *X, int len, int stride, opus_val16 c, opus_val16 s) { - int i; - opus_val16 ms; - celt_norm *Xptr; - Xptr = X; - ms = NEG16(s); - for (i = 0; i < len - stride; i++) { - celt_norm x1, x2; - x1 = Xptr[0]; - x2 = Xptr[stride]; - Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15)); - *Xptr++ = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15)); - } - Xptr = &X[len - 2 * stride - 1]; - for (i = len - 2 * stride - 1; i >= 0; i--) { - celt_norm x1, x2; - x1 = Xptr[0]; - x2 = Xptr[stride]; - Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15)); - *Xptr-- = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15)); - } +static void exp_rotation1(celt_norm *X, int len, int stride, opus_val16 c, opus_val16 s) +{ + int i; + opus_val16 ms; + celt_norm *Xptr; + Xptr = X; + ms = NEG16(s); + for (i=0;i=0;i--) + { + celt_norm x1, x2; + x1 = Xptr[0]; + x2 = Xptr[stride]; + Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15)); + *Xptr-- = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15)); + } } #endif /* OVERRIDE_vq_exp_rotation1 */ -void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread) { - static const int SPREAD_FACTOR[3] = {15, 10, 5}; - int i; - opus_val16 c, s; - opus_val16 gain, theta; - int stride2 = 0; - int factor; +void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread) +{ + static const int SPREAD_FACTOR[3]={15,10,5}; + int i; + opus_val16 c, s; + opus_val16 gain, theta; + int stride2=0; + int factor; - if (2 * K >= len || spread == SPREAD_NONE) { - return; - } - factor = SPREAD_FACTOR[spread - 1]; + if (2*K>=len || spread==SPREAD_NONE) + return; + factor = SPREAD_FACTOR[spread-1]; - gain = celt_div((opus_val32)MULT16_16(Q15_ONE, len), (opus_val32)(len + factor * K)); - theta = HALF16(MULT16_16_Q15(gain, gain)); + gain = celt_div((opus_val32)MULT16_16(Q15_ONE,len),(opus_val32)(len+factor*K)); + theta = HALF16(MULT16_16_Q15(gain,gain)); - c = celt_cos_norm(EXTEND32(theta)); - s = celt_cos_norm(EXTEND32(SUB16(Q15ONE, theta))); /* sin(theta) */ + c = celt_cos_norm(EXTEND32(theta)); + s = celt_cos_norm(EXTEND32(SUB16(Q15ONE,theta))); /* sin(theta) */ - if (len >= 8 * stride) { - stride2 = 1; - /* This is just a simple (equivalent) way of computing sqrt(len/stride) with rounding. - It's basically incrementing long as (stride2+0.5)^2 < len/stride. */ - while ((stride2 * stride2 + stride2)*stride + (stride >> 2) < len) { - stride2++; - } - } - /* NOTE: As a minor optimization, we could be passing around log2(B), not B, for both this and for - extract_collapse_mask().*/ - len = celt_udiv(len, stride); - for (i = 0; i < stride; i++) { - if (dir < 0) { - if (stride2) { - exp_rotation1(X + i * len, len, stride2, s, c); - } - exp_rotation1(X + i * len, len, 1, c, s); - } else { - exp_rotation1(X + i * len, len, 1, c, -s); - if (stride2) { - exp_rotation1(X + i * len, len, stride2, s, -c); - } - } - } + if (len>=8*stride) + { + stride2 = 1; + /* This is just a simple (equivalent) way of computing sqrt(len/stride) with rounding. + It's basically incrementing long as (stride2+0.5)^2 < len/stride. */ + while ((stride2*stride2+stride2)*stride + (stride>>2) < len) + stride2++; + } + /*NOTE: As a minor optimization, we could be passing around log2(B), not B, for both this and for + extract_collapse_mask().*/ + len = celt_udiv(len, stride); + for (i=0;i> 1; + k = celt_ilog2(Ryy)>>1; #endif - t = VSHR32(Ryy, 2 * (k - 7)); - g = MULT16_16_P15(celt_rsqrt_norm(t), gain); + t = VSHR32(Ryy, 2*(k-7)); + g = MULT16_16_P15(celt_rsqrt_norm(t),gain); - i = 0; - do { - X[i] = EXTRACT16(PSHR32(MULT16_16(g, iy[i]), k + 1)); - } while (++i < N); + i=0; + do + X[i] = EXTRACT16(PSHR32(MULT16_16(g, iy[i]), k+1)); + while (++i < N); } -static unsigned extract_collapse_mask(int *iy, int N, int B) { - unsigned collapse_mask; - int N0; - int i; - if (B <= 1) { - return 1; - } - /* NOTE: As a minor optimization, we could be passing around log2(B), not B, for both this and for - exp_rotation().*/ - N0 = celt_udiv(N, B); - collapse_mask = 0; - i = 0; do { - int j; - unsigned tmp = 0; - j = 0; do { - tmp |= iy[i * N0 + j]; - } while (++j < N0); - collapse_mask |= (tmp != 0) << i; - } while (++i < B); - return collapse_mask; +static unsigned extract_collapse_mask(int *iy, int N, int B) +{ + unsigned collapse_mask; + int N0; + int i; + if (B<=1) + return 1; + /*NOTE: As a minor optimization, we could be passing around log2(B), not B, for both this and for + exp_rotation().*/ + N0 = celt_udiv(N, B); + collapse_mask = 0; + i=0; do { + int j; + unsigned tmp=0; + j=0; do { + tmp |= iy[i*N0+j]; + } while (++j (N >> 1)) { - opus_val16 rcp; - j = 0; do { - sum += X[j]; - } while (++j < N); + /* Do a pre-search by projecting on the pyramid */ + if (K > (N>>1)) + { + opus_val16 rcp; + j=0; do { + sum += X[j]; + } while (++j EPSILON && sum < 64)) + /* Prevents infinities and NaNs from causing too many pulses + to be allocated. 64 is an approximation of infinity here. */ + if (!(sum > EPSILON && sum < 64)) #endif - { - X[0] = QCONST16(1.f, 14); - j = 1; do { - X[j] = 0; - } while (++j < N); - sum = QCONST16(1.f, 14); - } + { + X[0] = QCONST16(1.f,14); + j=1; do + X[j]=0; + while (++j= 0); + y[j] = (celt_norm)iy[j]; + yy = MAC16_16(yy, y[j],y[j]); + xy = MAC16_16(xy, X[j],y[j]); + y[j] *= 2; + pulsesLeft -= iy[j]; + } while (++j=0); - /* This should never happen, but just in case it does (e.g. on silence) - we fill the first bin with pulses. */ + /* This should never happen, but just in case it does (e.g. on silence) + we fill the first bin with pulses. */ #ifdef FIXED_POINT_DEBUG - celt_sig_assert(pulsesLeft <= N + 3); + celt_sig_assert(pulsesLeft<=N+3); #endif - if (pulsesLeft > N + 3) { - opus_val16 tmp = (opus_val16)pulsesLeft; - yy = MAC16_16(yy, tmp, tmp); - yy = MAC16_16(yy, tmp, y[0]); - iy[0] += pulsesLeft; - pulsesLeft = 0; - } + if (pulsesLeft > N+3) + { + opus_val16 tmp = (opus_val16)pulsesLeft; + yy = MAC16_16(yy, tmp, tmp); + yy = MAC16_16(yy, tmp, y[0]); + iy[0] += pulsesLeft; + pulsesLeft=0; + } - for (i = 0; i < pulsesLeft; i++) { - opus_val16 Rxy, Ryy; - int best_id; - opus_val32 best_num; - opus_val16 best_den; + for (i=0;i= best_num/best_den, but that way + we can do it without any division */ + /* OPT: It's not clear whether a cmov is faster than a branch here + since the condition is more often false than true and using + a cmov introduces data dependencies across iterations. The optimal + choice may be architecture-dependent. */ + if (opus_unlikely(MULT16_16(best_den, Rxy) > MULT16_16(Ryy, best_num))) + { + best_den = Ryy; + best_num = Rxy; + best_id = j; + } + } while (++j= best_num/best_den, but that way - we can do it without any division */ - /* OPT: It's not clear whether a cmov is faster than a branch here - since the condition is more often false than true and using - a cmov introduces data dependencies across iterations. The optimal - choice may be architecture-dependent. */ - if (opus_unlikely(MULT16_16(best_den, Rxy) > MULT16_16(Ryy, best_num))) { - best_den = Ryy; - best_num = Rxy; - best_id = j; - } - } while (++j < N); + /* Updating the sums of the new pulse(s) */ + xy = ADD32(xy, EXTEND32(X[best_id])); + /* We're multiplying y[j] by two so we don't have to do it here */ + yy = ADD16(yy, y[best_id]); - /* Updating the sums of the new pulse(s) */ - xy = ADD32(xy, EXTEND32(X[best_id])); - /* We're multiplying y[j] by two so we don't have to do it here */ - yy = ADD16(yy, y[best_id]); + /* Only now that we've made the final choice, update y/iy */ + /* Multiplying y[j] by 2 so we don't have to do it everywhere else */ + y[best_id] += 2; + iy[best_id]++; + } - /* Only now that we've made the final choice, update y/iy */ - /* Multiplying y[j] by 2 so we don't have to do it everywhere else */ - y[best_id] += 2; - iy[best_id]++; - } - - /* Put the original sign back */ - j = 0; - do { - /*iy[j] = signx[j] ? -iy[j] : iy[j];*/ - /* OPT: The is more likely to be compiled without a branch than the code above - but has the same performance otherwise. */ - iy[j] = (iy[j] ^ -signx[j]) + signx[j]; - } while (++j < N); - RESTORE_STACK; - return yy; + /* Put the original sign back */ + j=0; + do { + /*iy[j] = signx[j] ? -iy[j] : iy[j];*/ + /* OPT: The is more likely to be compiled without a branch than the code above + but has the same performance otherwise. */ + iy[j] = (iy[j]^-signx[j]) + signx[j]; + } while (++j 0, "alg_quant() needs at least one pulse"); - celt_assert2(N > 1, "alg_quant() needs at least two dimensions"); + celt_assert2(K>0, "alg_quant() needs at least one pulse"); + celt_assert2(N>1, "alg_quant() needs at least two dimensions"); - /* Covers vectorization by up to 4. */ - ALLOC(iy, N + 3, int); + /* Covers vectorization by up to 4. */ + ALLOC(iy, N+3, int); - exp_rotation(X, N, 1, B, K, spread); + exp_rotation(X, N, 1, B, K, spread); - yy = op_pvq_search(X, iy, K, N, arch); + yy = op_pvq_search(X, iy, K, N, arch); - encode_pulses(iy, N, K, enc); + encode_pulses(iy, N, K, enc); - if (resynth) { - normalise_residual(iy, X, N, yy, gain); - exp_rotation(X, N, -1, B, K, spread); - } + if (resynth) + { + normalise_residual(iy, X, N, yy, gain); + exp_rotation(X, N, -1, B, K, spread); + } - collapse_mask = extract_collapse_mask(iy, N, B); - RESTORE_STACK; - return collapse_mask; + collapse_mask = extract_collapse_mask(iy, N, B); + RESTORE_STACK; + return collapse_mask; } /** Decode pulse vector and combine the result with the pitch vector to produce the final normalised signal in the current band. */ unsigned alg_unquant(celt_norm *X, int N, int K, int spread, int B, - ec_dec *dec, opus_val16 gain) { - opus_val32 Ryy; - unsigned collapse_mask; - VARDECL(int, iy); - SAVE_STACK; + ec_dec *dec, opus_val16 gain) +{ + opus_val32 Ryy; + unsigned collapse_mask; + VARDECL(int, iy); + SAVE_STACK; - celt_assert2(K > 0, "alg_unquant() needs at least one pulse"); - celt_assert2(N > 1, "alg_unquant() needs at least two dimensions"); - ALLOC(iy, N, int); - Ryy = decode_pulses(iy, N, K, dec); - normalise_residual(iy, X, N, Ryy, gain); - exp_rotation(X, N, -1, B, K, spread); - collapse_mask = extract_collapse_mask(iy, N, B); - RESTORE_STACK; - return collapse_mask; + celt_assert2(K>0, "alg_unquant() needs at least one pulse"); + celt_assert2(N>1, "alg_unquant() needs at least two dimensions"); + ALLOC(iy, N, int); + Ryy = decode_pulses(iy, N, K, dec); + normalise_residual(iy, X, N, Ryy, gain); + exp_rotation(X, N, -1, B, K, spread); + collapse_mask = extract_collapse_mask(iy, N, B); + RESTORE_STACK; + return collapse_mask; } #ifndef OVERRIDE_renormalise_vector -void renormalise_vector(celt_norm *X, int N, opus_val16 gain, int arch) { - int i; +void renormalise_vector(celt_norm *X, int N, opus_val16 gain, int arch) +{ + int i; #ifdef FIXED_POINT - int k; + int k; #endif - opus_val32 E; - opus_val16 g; - opus_val32 t; - celt_norm *xptr; - E = EPSILON + celt_inner_prod(X, X, N, arch); + opus_val32 E; + opus_val16 g; + opus_val32 t; + celt_norm *xptr; + E = EPSILON + celt_inner_prod(X, X, N, arch); #ifdef FIXED_POINT - k = celt_ilog2(E) >> 1; + k = celt_ilog2(E)>>1; #endif - t = VSHR32(E, 2 * (k - 7)); - g = MULT16_16_P15(celt_rsqrt_norm(t), gain); + t = VSHR32(E, 2*(k-7)); + g = MULT16_16_P15(celt_rsqrt_norm(t),gain); - xptr = X; - for (i = 0; i < N; i++) { - *xptr = EXTRACT16(PSHR32(MULT16_16(g, *xptr), k + 1)); - xptr++; - } - /*return celt_sqrt(E);*/ + xptr = X; + for (i=0;i header file. */ /* #undef HAVE_ALLOCA_H */ + /* NE10 library is installed on host. Make sure it is on target! */ /* #undef HAVE_ARM_NE10 */ /* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 0 +#define HAVE_DLFCN_H 1 /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 /* Define to 1 if you have the `lrint' function. */ -#define HAVE_LRINT 0 +#define HAVE_LRINT 1 /* Define to 1 if you have the `lrintf' function. */ -#define HAVE_LRINTF 0 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 +#define HAVE_LRINTF 1 /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 @@ -74,10 +99,10 @@ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 0 +#define HAVE_UNISTD_H 1 /* Define to 1 if you have the `__malloc_hook' function. */ -#define HAVE___MALLOC_HOOK 1 +/* #undef HAVE___MALLOC_HOOK */ /* Define to the sub-directory where libtool stores uninstalled libraries. */ #define LT_OBJDIR ".libs/" @@ -97,6 +122,9 @@ /* Use ARM NEON inline asm optimizations */ /* #undef OPUS_ARM_INLINE_NEON */ +/* Compiler supports Aarch64 DOTPROD Intrinsics */ +/* #undef OPUS_ARM_MAY_HAVE_DOTPROD */ + /* Define if assembler supports EDSP instructions */ /* #undef OPUS_ARM_MAY_HAVE_EDSP */ @@ -112,6 +140,9 @@ /* Define if binary requires Aarch64 Neon Intrinsics */ /* #undef OPUS_ARM_PRESUME_AARCH64_NEON_INTR */ +/* Define if binary requires Aarch64 dotprod Intrinsics */ +/* #undef OPUS_ARM_PRESUME_DOTPROD */ + /* Define if binary requires EDSP instruction support */ /* #undef OPUS_ARM_PRESUME_EDSP */ @@ -133,8 +164,8 @@ /* Use run-time CPU capabilities detection */ /* #undef OPUS_HAVE_RTCD */ -/* Compiler supports X86 AVX Intrinsics */ -/* #undef OPUS_X86_MAY_HAVE_AVX */ +/* Compiler supports X86 AVX2 Intrinsics */ +/* #undef OPUS_X86_MAY_HAVE_AVX2 */ /* Compiler supports X86 SSE Intrinsics */ /* #undef OPUS_X86_MAY_HAVE_SSE */ @@ -145,8 +176,8 @@ /* Compiler supports X86 SSE4.1 Intrinsics */ /* #undef OPUS_X86_MAY_HAVE_SSE4_1 */ -/* Define if binary requires AVX intrinsics support */ -/* #undef OPUS_X86_PRESUME_AVX */ +/* Define if binary requires AVX2 intrinsics support */ +/* #undef OPUS_X86_PRESUME_AVX2 */ /* Define if binary requires SSE intrinsics support */ /* #undef OPUS_X86_PRESUME_SSE */ @@ -164,7 +195,7 @@ #define PACKAGE_NAME "opus" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "opus 1.3.1" +#define PACKAGE_STRING "opus 1.5.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "opus" @@ -173,38 +204,44 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.3.1" +#define PACKAGE_VERSION "1.5.2" -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ #define STDC_HEADERS 1 /* Make use of alloca */ -/* #undef USE_ALLOCA */ +#undef USE_ALLOCA /* Use C99 variable-size arrays */ #define VAR_ARRAYS 1 +// Enable heap-based stack on Pico. ESP32 should use larger task stack in the sketch +#ifdef ARDUINO_ARCH_RP2040 +#undef VAR_ARRAYS +#define NONTHREADSAFE_PSEUDOSTACK 1 +#endif + /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus /* #undef inline */ #endif -/* Define to the equivalent of the C99 'restrict' keyword, or to - nothing if this is not supported. Do not define if restrict is - supported directly. */ +/* Define to the equivalent of the C99 'restrict' keyword, or to + nothing if this is not supported. Do not define if restrict is + supported directly. */ #define restrict __restrict -/* Work around a bug in Sun C++: it does not support _Restrict or - __restrict__, even though the corresponding Sun C compiler ends up with - "#define restrict _Restrict" or "#define restrict __restrict__" in the - previous line. Perhaps some future version of Sun C++ will work with - restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ +/* Work around a bug in Sun C++: it does not support _Restrict or + __restrict__, even though the corresponding Sun C compiler ends up with + "#define restrict _Restrict" or "#define restrict __restrict__" in the + previous line. Perhaps some future version of Sun C++ will work with + restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ #if defined __SUNPRO_CC && !defined __RESTRICT # define _Restrict # define __restrict__ #endif - -#include diff --git a/src/libopus/include/opus.h b/src/libopus/include/opus.h new file mode 100644 index 0000000..eadeda7 --- /dev/null +++ b/src/libopus/include/opus.h @@ -0,0 +1,1099 @@ +/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited + Written by Jean-Marc Valin and Koen Vos */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus.h + * @brief Opus reference implementation API + */ + +#ifndef OPUS_H +#define OPUS_H + +#include "opus_types.h" +#include "opus_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @mainpage Opus + * + * The Opus codec is designed for interactive speech and audio transmission over the Internet. + * It is designed by the IETF Codec Working Group and incorporates technology from + * Skype's SILK codec and Xiph.Org's CELT codec. + * + * The Opus codec is designed to handle a wide range of interactive audio applications, + * including Voice over IP, videoconferencing, in-game chat, and even remote live music + * performances. It can scale from low bit-rate narrowband speech to very high quality + * stereo music. Its main features are: + + * @li Sampling rates from 8 to 48 kHz + * @li Bit-rates from 6 kb/s to 510 kb/s + * @li Support for both constant bit-rate (CBR) and variable bit-rate (VBR) + * @li Audio bandwidth from narrowband to full-band + * @li Support for speech and music + * @li Support for mono and stereo + * @li Support for multichannel (up to 255 channels) + * @li Frame sizes from 2.5 ms to 60 ms + * @li Good loss robustness and packet loss concealment (PLC) + * @li Floating point and fixed-point implementation + * + * Documentation sections: + * @li @ref opus_encoder + * @li @ref opus_decoder + * @li @ref opus_repacketizer + * @li @ref opus_multistream + * @li @ref opus_libinfo + * @li @ref opus_custom + */ + +/** @defgroup opus_encoder Opus Encoder + * @{ + * + * @brief This page describes the process and functions used to encode Opus. + * + * Since Opus is a stateful codec, the encoding process starts with creating an encoder + * state. This can be done with: + * + * @code + * int error; + * OpusEncoder *enc; + * enc = opus_encoder_create(Fs, channels, application, &error); + * @endcode + * + * From this point, @c enc can be used for encoding an audio stream. An encoder state + * @b must @b not be used for more than one stream at the same time. Similarly, the encoder + * state @b must @b not be re-initialized for each frame. + * + * While opus_encoder_create() allocates memory for the state, it's also possible + * to initialize pre-allocated memory: + * + * @code + * int size; + * int error; + * OpusEncoder *enc; + * size = opus_encoder_get_size(channels); + * enc = malloc(size); + * error = opus_encoder_init(enc, Fs, channels, application); + * @endcode + * + * where opus_encoder_get_size() returns the required size for the encoder state. Note that + * future versions of this code may change the size, so no assumptions should be made about it. + * + * The encoder state is always continuous in memory and only a shallow copy is sufficient + * to copy it (e.g. memcpy()) + * + * It is possible to change some of the encoder's settings using the opus_encoder_ctl() + * interface. All these settings already default to the recommended value, so they should + * only be changed when necessary. The most common settings one may want to change are: + * + * @code + * opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)); + * opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); + * opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type)); + * @endcode + * + * where + * + * @arg bitrate is in bits per second (b/s) + * @arg complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest + * @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC + * + * See @ref opus_encoderctls and @ref opus_genericctls for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream. + * + * To encode a frame, opus_encode() or opus_encode_float() must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data: + * @code + * len = opus_encode(enc, audio_frame, frame_size, packet, max_packet); + * @endcode + * + * where + *
    + *
  • audio_frame is the audio data in opus_int16 (or float for opus_encode_float())
  • + *
  • frame_size is the duration of the frame in samples (per channel)
  • + *
  • packet is the byte array to which the compressed data is written
  • + *
  • max_packet is the maximum number of bytes that can be written in the packet (4000 bytes is recommended). + * Do not use max_packet to control VBR target bitrate, instead use the #OPUS_SET_BITRATE CTL.
  • + *
+ * + * opus_encode() and opus_encode_float() return the number of bytes actually written to the packet. + * The return value can be negative, which indicates that an error has occurred. If the return value + * is 2 bytes or less, then the packet does not need to be transmitted (DTX). + * + * Once the encoder state if no longer needed, it can be destroyed with + * + * @code + * opus_encoder_destroy(enc); + * @endcode + * + * If the encoder was created with opus_encoder_init() rather than opus_encoder_create(), + * then no action is required aside from potentially freeing the memory that was manually + * allocated for it (calling free(enc) for the example above) + * + */ + +/** Opus encoder state. + * This contains the complete state of an Opus encoder. + * It is position independent and can be freely copied. + * @see opus_encoder_create,opus_encoder_init + */ +typedef struct OpusEncoder OpusEncoder; + +/** Gets the size of an OpusEncoder structure. + * @param[in] channels int: Number of channels. + * This must be 1 or 2. + * @returns The size in bytes. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels); + +/** + */ + +/** Allocates and initializes an encoder state. + * There are three coding modes: + * + * @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice + * signals. It enhances the input signal by high-pass filtering and + * emphasizing formants and harmonics. Optionally it includes in-band + * forward error correction to protect against packet loss. Use this + * mode for typical VoIP applications. Because of the enhancement, + * even at high bitrates the output may sound different from the input. + * + * @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most + * non-voice signals like music. Use this mode for music and mixed + * (music/voice) content, broadcast, and applications requiring less + * than 15 ms of coding delay. + * + * @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that + * disables the speech-optimized mode in exchange for slightly reduced delay. + * This mode can only be set on an newly initialized or freshly reset encoder + * because it changes the codec delay. + * + * This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution). + * @param [in] Fs opus_int32: Sampling rate of input signal (Hz) + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) in input signal + * @param [in] application int: Coding mode (one of @ref OPUS_APPLICATION_VOIP, @ref OPUS_APPLICATION_AUDIO, or @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY) + * @param [out] error int*: @ref opus_errorcodes + * @note Regardless of the sampling rate and number channels selected, the Opus encoder + * can switch to a lower audio bandwidth or number of channels if the bitrate + * selected is too low. This also means that it is safe to always use 48 kHz stereo input + * and let the encoder optimize the encoding. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create( + opus_int32 Fs, + int channels, + int application, + int *error +); + +/** Initializes a previously allocated encoder state + * The memory pointed to by st must be at least the size returned by opus_encoder_get_size(). + * This is intended for applications which use their own allocator instead of malloc. + * @see opus_encoder_create(),opus_encoder_get_size() + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @param [in] st OpusEncoder*: Encoder state + * @param [in] Fs opus_int32: Sampling rate of input signal (Hz) + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) in input signal + * @param [in] application int: Coding mode (one of OPUS_APPLICATION_VOIP, OPUS_APPLICATION_AUDIO, or OPUS_APPLICATION_RESTRICTED_LOWDELAY) + * @retval #OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_EXPORT int opus_encoder_init( + OpusEncoder *st, + opus_int32 Fs, + int channels, + int application +) OPUS_ARG_NONNULL(1); + +/** Encodes an Opus frame. + * @param [in] st OpusEncoder*: Encoder state + * @param [in] pcm opus_int16*: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16) + * @param [in] frame_size int: Number of samples per channel in the + * input signal. + * This must be an Opus frame size for + * the encoder's sampling rate. + * For example, at 48 kHz the permitted + * values are 120, 240, 480, 960, 1920, + * and 2880. + * Passing in a duration of less than + * 10 ms (480 samples at 48 kHz) will + * prevent the encoder from using the LPC + * or hybrid modes. + * @param [out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode( + OpusEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Encodes an Opus frame from floating point input. + * @param [in] st OpusEncoder*: Encoder state + * @param [in] pcm float*: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0. + * Samples with a range beyond +/-1.0 are supported but will + * be clipped by decoders using the integer API and should + * only be used if it is known that the far end supports + * extended dynamic range. + * length is frame_size*channels*sizeof(float) + * @param [in] frame_size int: Number of samples per channel in the + * input signal. + * This must be an Opus frame size for + * the encoder's sampling rate. + * For example, at 48 kHz the permitted + * values are 120, 240, 480, 960, 1920, + * and 2880. + * Passing in a duration of less than + * 10 ms (480 samples at 48 kHz) will + * prevent the encoder from using the LPC + * or hybrid modes. + * @param [out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float( + OpusEncoder *st, + const float *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Frees an OpusEncoder allocated by opus_encoder_create(). + * @param[in] st OpusEncoder*: State to be freed. + */ +OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st); + +/** Perform a CTL function on an Opus encoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @param st OpusEncoder*: Encoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls or + * @ref opus_encoderctls. + * @see opus_genericctls + * @see opus_encoderctls + */ +OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); +/**@}*/ + +/** @defgroup opus_decoder Opus Decoder + * @{ + * + * @brief This page describes the process and functions used to decode Opus. + * + * The decoding process also starts with creating a decoder + * state. This can be done with: + * @code + * int error; + * OpusDecoder *dec; + * dec = opus_decoder_create(Fs, channels, &error); + * @endcode + * where + * @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000 + * @li channels is the number of channels (1 or 2) + * @li error will hold the error code in case of failure (or #OPUS_OK on success) + * @li the return value is a newly created decoder state to be used for decoding + * + * While opus_decoder_create() allocates memory for the state, it's also possible + * to initialize pre-allocated memory: + * @code + * int size; + * int error; + * OpusDecoder *dec; + * size = opus_decoder_get_size(channels); + * dec = malloc(size); + * error = opus_decoder_init(dec, Fs, channels); + * @endcode + * where opus_decoder_get_size() returns the required size for the decoder state. Note that + * future versions of this code may change the size, so no assumptions should be made about it. + * + * The decoder state is always continuous in memory and only a shallow copy is sufficient + * to copy it (e.g. memcpy()) + * + * To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data: + * @code + * frame_size = opus_decode(dec, packet, len, decoded, max_size, 0); + * @endcode + * where + * + * @li packet is the byte array containing the compressed data + * @li len is the exact number of bytes contained in the packet + * @li decoded is the decoded audio data in opus_int16 (or float for opus_decode_float()) + * @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array + * + * opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet. + * If that value is negative, then an error has occurred. This can occur if the packet is corrupted or if the audio + * buffer is too small to hold the decoded audio. + * + * Opus is a stateful codec with overlapping blocks and as a result Opus + * packets are not coded independently of each other. Packets must be + * passed into the decoder serially and in the correct order for a correct + * decode. Lost packets can be replaced with loss concealment by calling + * the decoder with a null pointer and zero length for the missing packet. + * + * A single codec state may only be accessed from a single thread at + * a time and any required locking must be performed by the caller. Separate + * streams must be decoded with separate decoder states and can be decoded + * in parallel unless the library was compiled with NONTHREADSAFE_PSEUDOSTACK + * defined. + * + */ + +/** Opus decoder state. + * This contains the complete state of an Opus decoder. + * It is position independent and can be freely copied. + * @see opus_decoder_create,opus_decoder_init + */ +typedef struct OpusDecoder OpusDecoder; + +/** Opus DRED decoder. + * This contains the complete state of an Opus DRED decoder. + * It is position independent and can be freely copied. + * @see opus_dred_decoder_create,opus_dred_decoder_init + */ +typedef struct OpusDREDDecoder OpusDREDDecoder; + + +/** Opus DRED state. + * This contains the complete state of an Opus DRED packet. + * It is position independent and can be freely copied. + * @see opus_dred_create,opus_dred_init + */ +typedef struct OpusDRED OpusDRED; + +/** Gets the size of an OpusDecoder structure. + * @param [in] channels int: Number of channels. + * This must be 1 or 2. + * @returns The size in bytes. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels); + +/** Allocates and initializes a decoder state. + * @param [in] Fs opus_int32: Sample rate to decode at (Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) to decode + * @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes + * + * Internally Opus stores data at 48000 Hz, so that should be the default + * value for Fs. However, the decoder can efficiently decode to buffers + * at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use + * data at the full sample rate, or knows the compressed data doesn't + * use the full frequency range, it can request decoding at a reduced + * rate. Likewise, the decoder is capable of filling in either mono or + * interleaved stereo pcm buffers, at the caller's request. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create( + opus_int32 Fs, + int channels, + int *error +); + +/** Initializes a previously allocated decoder state. + * The state must be at least the size returned by opus_decoder_get_size(). + * This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @param [in] st OpusDecoder*: Decoder state. + * @param [in] Fs opus_int32: Sampling rate to decode to (Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) to decode + * @retval #OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_EXPORT int opus_decoder_init( + OpusDecoder *st, + opus_int32 Fs, + int channels +) OPUS_ARG_NONNULL(1); + +/** Decode an Opus packet. + * @param [in] st OpusDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len opus_int32: Number of bytes in payload* + * @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(opus_int16) + * @param [in] frame_size Number of samples per channel of available space in \a pcm. + * If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will + * not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), + * then frame_size needs to be exactly the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the next incoming packet. For the PLC and + * FEC cases, frame_size must be a multiple of 2.5 ms. + * @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be + * decoded. If no such data is available, the frame is decoded as if it were lost. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode( + OpusDecoder *st, + const unsigned char *data, + opus_int32 len, + opus_int16 *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Decode an Opus packet with floating point output. + * @param [in] st OpusDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len opus_int32: Number of bytes in payload + * @param [out] pcm float*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(float) + * @param [in] frame_size Number of samples per channel of available space in \a pcm. + * If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will + * not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), + * then frame_size needs to be exactly the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the next incoming packet. For the PLC and + * FEC cases, frame_size must be a multiple of 2.5 ms. + * @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be + * decoded. If no such data is available the frame is decoded as if it were lost. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float( + OpusDecoder *st, + const unsigned char *data, + opus_int32 len, + float *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on an Opus decoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @param st OpusDecoder*: Decoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls or + * @ref opus_decoderctls. + * @see opus_genericctls + * @see opus_decoderctls + */ +OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); + +/** Frees an OpusDecoder allocated by opus_decoder_create(). + * @param[in] st OpusDecoder*: State to be freed. + */ +OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st); + +/** Gets the size of an OpusDREDDecoder structure. + * @returns The size in bytes. + */ +OPUS_EXPORT int opus_dred_decoder_get_size(void); + +/** Allocates and initializes an OpusDREDDecoder state. + * @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_EXPORT OpusDREDDecoder *opus_dred_decoder_create(int *error); + +/** Initializes an OpusDREDDecoder state. + * @param[in] dec OpusDREDDecoder*: State to be initialized. + */ +OPUS_EXPORT int opus_dred_decoder_init(OpusDREDDecoder *dec); + +/** Frees an OpusDREDDecoder allocated by opus_dred_decoder_create(). + * @param[in] dec OpusDREDDecoder*: State to be freed. + */ +OPUS_EXPORT void opus_dred_decoder_destroy(OpusDREDDecoder *dec); + +/** Perform a CTL function on an Opus DRED decoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @param dred_dec OpusDREDDecoder*: DRED Decoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls or + * @ref opus_decoderctls. + * @see opus_genericctls + * @see opus_decoderctls + */ +OPUS_EXPORT int opus_dred_decoder_ctl(OpusDREDDecoder *dred_dec, int request, ...); + +/** Gets the size of an OpusDRED structure. + * @returns The size in bytes. + */ +OPUS_EXPORT int opus_dred_get_size(void); + +/** Allocates and initializes a DRED state. + * @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_EXPORT OpusDRED *opus_dred_alloc(int *error); + +/** Frees an OpusDRED allocated by opus_dred_create(). + * @param[in] dec OpusDRED*: State to be freed. + */ +OPUS_EXPORT void opus_dred_free(OpusDRED *dec); + +/** Decode an Opus DRED packet. + * @param [in] dred_dec OpusDRED*: DRED Decoder state + * @param [in] dred OpusDRED*: DRED state + * @param [in] data char*: Input payload + * @param [in] len opus_int32: Number of bytes in payload + * @param [in] max_dred_samples opus_int32: Maximum number of DRED samples that may be needed (if available in the packet). + * @param [in] sampling_rate opus_int32: Sampling rate used for max_dred_samples argument. Needs not match the actual sampling rate of the decoder. + * @param [out] dred_end opus_int32*: Number of non-encoded (silence) samples between the DRED timestamp and the last DRED sample. + * @param [in] defer_processing int: Flag (0 or 1). If set to one, the CPU-intensive part of the DRED decoding is deferred until opus_dred_process() is called. + * @returns Offset (positive) of the first decoded DRED samples, zero if no DRED is present, or @ref opus_errorcodes + */ +OPUS_EXPORT int opus_dred_parse(OpusDREDDecoder *dred_dec, OpusDRED *dred, const unsigned char *data, opus_int32 len, opus_int32 max_dred_samples, opus_int32 sampling_rate, int *dred_end, int defer_processing) OPUS_ARG_NONNULL(1); + +/** Finish decoding an Opus DRED packet. The function only needs to be called if opus_dred_parse() was called with defer_processing=1. + * The source and destination will often be the same DRED state. + * @param [in] dred_dec OpusDRED*: DRED Decoder state + * @param [in] src OpusDRED*: Source DRED state to start the processing from. + * @param [out] dst OpusDRED*: Destination DRED state to store the updated state after processing. + * @returns @ref opus_errorcodes + */ +OPUS_EXPORT int opus_dred_process(OpusDREDDecoder *dred_dec, const OpusDRED *src, OpusDRED *dst); + +/** Decode audio from an Opus DRED packet with floating point output. + * @param [in] st OpusDecoder*: Decoder state + * @param [in] dred OpusDRED*: DRED state + * @param [in] dred_offset opus_int32: position of the redundancy to decode (in samples before the beginning of the real audio data in the packet). + * @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(opus_int16) + * @param [in] frame_size Number of samples per channel to decode in \a pcm. + * frame_size must be a multiple of 2.5 ms. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_EXPORT int opus_decoder_dred_decode(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size); + +/** Decode audio from an Opus DRED packet with floating point output. + * @param [in] st OpusDecoder*: Decoder state + * @param [in] dred OpusDRED*: DRED state + * @param [in] dred_offset opus_int32: position of the redundancy to decode (in samples before the beginning of the real audio data in the packet). + * @param [out] pcm float*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(float) + * @param [in] frame_size Number of samples per channel to decode in \a pcm. + * frame_size must be a multiple of 2.5 ms. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_EXPORT int opus_decoder_dred_decode_float(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size); + + +/** Parse an opus packet into one or more frames. + * Opus_decode will perform this operation internally so most applications do + * not need to use this function. + * This function does not copy the frames, the returned pointers are pointers into + * the input packet. + * @param [in] data char*: Opus packet to be parsed + * @param [in] len opus_int32: size of data + * @param [out] out_toc char*: TOC pointer + * @param [out] frames char*[48] encapsulated frames + * @param [out] size opus_int16[48] sizes of the encapsulated frames + * @param [out] payload_offset int*: returns the position of the payload within the packet (in bytes) + * @returns number of frames + */ +OPUS_EXPORT int opus_packet_parse( + const unsigned char *data, + opus_int32 len, + unsigned char *out_toc, + const unsigned char *frames[48], + opus_int16 size[48], + int *payload_offset +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5); + +/** Gets the bandwidth of an Opus packet. + * @param [in] data char*: Opus packet + * @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) + * @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) + * @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) + * @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) + * @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1); + +/** Gets the number of samples per frame from an Opus packet. + * @param [in] data char*: Opus packet. + * This must contain at least one byte of + * data. + * @param [in] Fs opus_int32: Sampling rate in Hz. + * This must be a multiple of 400, or + * inaccurate results will be returned. + * @returns Number of samples per frame. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1); + +/** Gets the number of channels from an Opus packet. + * @param [in] data char*: Opus packet + * @returns Number of channels + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1); + +/** Gets the number of frames in an Opus packet. + * @param [in] packet char*: Opus packet + * @param [in] len opus_int32: Length of packet + * @returns Number of frames + * @retval OPUS_BAD_ARG Insufficient data was passed to the function + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1); + +/** Gets the number of samples of an Opus packet. + * @param [in] packet char*: Opus packet + * @param [in] len opus_int32: Length of packet + * @param [in] Fs opus_int32: Sampling rate in Hz. + * This must be a multiple of 400, or + * inaccurate results will be returned. + * @returns Number of samples + * @retval OPUS_BAD_ARG Insufficient data was passed to the function + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1); + +/** Checks whether an Opus packet has LBRR. + * @param [in] packet char*: Opus packet + * @param [in] len opus_int32: Length of packet + * @returns 1 is LBRR is present, 0 otherwise + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_has_lbrr(const unsigned char packet[], opus_int32 len); + +/** Gets the number of samples of an Opus packet. + * @param [in] dec OpusDecoder*: Decoder state + * @param [in] packet char*: Opus packet + * @param [in] len opus_int32: Length of packet + * @returns Number of samples + * @retval OPUS_BAD_ARG Insufficient data was passed to the function + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); + +/** Applies soft-clipping to bring a float signal within the [-1,1] range. If + * the signal is already in that range, nothing is done. If there are values + * outside of [-1,1], then the signal is clipped as smoothly as possible to + * both fit in the range and avoid creating excessive distortion in the + * process. + * @param [in,out] pcm float*: Input PCM and modified PCM + * @param [in] frame_size int Number of samples per channel to process + * @param [in] channels int: Number of channels + * @param [in,out] softclip_mem float*: State memory for the soft clipping process (one float per channel, initialized to zero) + */ +OPUS_EXPORT void opus_pcm_soft_clip(float *pcm, int frame_size, int channels, float *softclip_mem); + + +/**@}*/ + +/** @defgroup opus_repacketizer Repacketizer + * @{ + * + * The repacketizer can be used to merge multiple Opus packets into a single + * packet or alternatively to split Opus packets that have previously been + * merged. Splitting valid Opus packets is always guaranteed to succeed, + * whereas merging valid packets only succeeds if all frames have the same + * mode, bandwidth, and frame size, and when the total duration of the merged + * packet is no more than 120 ms. The 120 ms limit comes from the + * specification and limits decoder memory requirements at a point where + * framing overhead becomes negligible. + * + * The repacketizer currently only operates on elementary Opus + * streams. It will not manipualte multistream packets successfully, except in + * the degenerate case where they consist of data from a single stream. + * + * The repacketizing process starts with creating a repacketizer state, either + * by calling opus_repacketizer_create() or by allocating the memory yourself, + * e.g., + * @code + * OpusRepacketizer *rp; + * rp = (OpusRepacketizer*)malloc(opus_repacketizer_get_size()); + * if (rp != NULL) + * opus_repacketizer_init(rp); + * @endcode + * + * Then the application should submit packets with opus_repacketizer_cat(), + * extract new packets with opus_repacketizer_out() or + * opus_repacketizer_out_range(), and then reset the state for the next set of + * input packets via opus_repacketizer_init(). + * + * For example, to split a sequence of packets into individual frames: + * @code + * unsigned char *data; + * int len; + * while (get_next_packet(&data, &len)) + * { + * unsigned char out[1276]; + * opus_int32 out_len; + * int nb_frames; + * int err; + * int i; + * err = opus_repacketizer_cat(rp, data, len); + * if (err != OPUS_OK) + * { + * release_packet(data); + * return err; + * } + * nb_frames = opus_repacketizer_get_nb_frames(rp); + * for (i = 0; i < nb_frames; i++) + * { + * out_len = opus_repacketizer_out_range(rp, i, i+1, out, sizeof(out)); + * if (out_len < 0) + * { + * release_packet(data); + * return (int)out_len; + * } + * output_next_packet(out, out_len); + * } + * opus_repacketizer_init(rp); + * release_packet(data); + * } + * @endcode + * + * Alternatively, to combine a sequence of frames into packets that each + * contain up to TARGET_DURATION_MS milliseconds of data: + * @code + * // The maximum number of packets with duration TARGET_DURATION_MS occurs + * // when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/5) + * // packets. + * unsigned char *data[(TARGET_DURATION_MS*2/5)+1]; + * opus_int32 len[(TARGET_DURATION_MS*2/5)+1]; + * int nb_packets; + * unsigned char out[1277*(TARGET_DURATION_MS*2/2)]; + * opus_int32 out_len; + * int prev_toc; + * nb_packets = 0; + * while (get_next_packet(data+nb_packets, len+nb_packets)) + * { + * int nb_frames; + * int err; + * nb_frames = opus_packet_get_nb_frames(data[nb_packets], len[nb_packets]); + * if (nb_frames < 1) + * { + * release_packets(data, nb_packets+1); + * return nb_frames; + * } + * nb_frames += opus_repacketizer_get_nb_frames(rp); + * // If adding the next packet would exceed our target, or it has an + * // incompatible TOC sequence, output the packets we already have before + * // submitting it. + * // N.B., The nb_packets > 0 check ensures we've submitted at least one + * // packet since the last call to opus_repacketizer_init(). Otherwise a + * // single packet longer than TARGET_DURATION_MS would cause us to try to + * // output an (invalid) empty packet. It also ensures that prev_toc has + * // been set to a valid value. Additionally, len[nb_packets] > 0 is + * // guaranteed by the call to opus_packet_get_nb_frames() above, so the + * // reference to data[nb_packets][0] should be valid. + * if (nb_packets > 0 && ( + * ((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) || + * opus_packet_get_samples_per_frame(data[nb_packets], 48000)*nb_frames > + * TARGET_DURATION_MS*48)) + * { + * out_len = opus_repacketizer_out(rp, out, sizeof(out)); + * if (out_len < 0) + * { + * release_packets(data, nb_packets+1); + * return (int)out_len; + * } + * output_next_packet(out, out_len); + * opus_repacketizer_init(rp); + * release_packets(data, nb_packets); + * data[0] = data[nb_packets]; + * len[0] = len[nb_packets]; + * nb_packets = 0; + * } + * err = opus_repacketizer_cat(rp, data[nb_packets], len[nb_packets]); + * if (err != OPUS_OK) + * { + * release_packets(data, nb_packets+1); + * return err; + * } + * prev_toc = data[nb_packets][0]; + * nb_packets++; + * } + * // Output the final, partial packet. + * if (nb_packets > 0) + * { + * out_len = opus_repacketizer_out(rp, out, sizeof(out)); + * release_packets(data, nb_packets); + * if (out_len < 0) + * return (int)out_len; + * output_next_packet(out, out_len); + * } + * @endcode + * + * An alternate way of merging packets is to simply call opus_repacketizer_cat() + * unconditionally until it fails. At that point, the merged packet can be + * obtained with opus_repacketizer_out() and the input packet for which + * opus_repacketizer_cat() needs to be re-added to a newly reinitialized + * repacketizer state. + */ + +typedef struct OpusRepacketizer OpusRepacketizer; + +/** Gets the size of an OpusRepacketizer structure. + * @returns The size in bytes. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void); + +/** (Re)initializes a previously allocated repacketizer state. + * The state must be at least the size returned by opus_repacketizer_get_size(). + * This can be used for applications which use their own allocator instead of + * malloc(). + * It must also be called to reset the queue of packets waiting to be + * repacketized, which is necessary if the maximum packet duration of 120 ms + * is reached or if you wish to submit packets with a different Opus + * configuration (coding mode, audio bandwidth, frame size, or channel count). + * Failure to do so will prevent a new packet from being added with + * opus_repacketizer_cat(). + * @see opus_repacketizer_create + * @see opus_repacketizer_get_size + * @see opus_repacketizer_cat + * @param rp OpusRepacketizer*: The repacketizer state to + * (re)initialize. + * @returns A pointer to the same repacketizer state that was passed in. + */ +OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); + +/** Allocates memory and initializes the new repacketizer with + * opus_repacketizer_init(). + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void); + +/** Frees an OpusRepacketizer allocated by + * opus_repacketizer_create(). + * @param[in] rp OpusRepacketizer*: State to be freed. + */ +OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp); + +/** Add a packet to the current repacketizer state. + * This packet must match the configuration of any packets already submitted + * for repacketization since the last call to opus_repacketizer_init(). + * This means that it must have the same coding mode, audio bandwidth, frame + * size, and channel count. + * This can be checked in advance by examining the top 6 bits of the first + * byte of the packet, and ensuring they match the top 6 bits of the first + * byte of any previously submitted packet. + * The total duration of audio in the repacketizer state also must not exceed + * 120 ms, the maximum duration of a single packet, after adding this packet. + * + * The contents of the current repacketizer state can be extracted into new + * packets using opus_repacketizer_out() or opus_repacketizer_out_range(). + * + * In order to add a packet with a different configuration or to add more + * audio beyond 120 ms, you must clear the repacketizer state by calling + * opus_repacketizer_init(). + * If a packet is too large to add to the current repacketizer state, no part + * of it is added, even if it contains multiple frames, some of which might + * fit. + * If you wish to be able to add parts of such packets, you should first use + * another repacketizer to split the packet into pieces and add them + * individually. + * @see opus_repacketizer_out_range + * @see opus_repacketizer_out + * @see opus_repacketizer_init + * @param rp OpusRepacketizer*: The repacketizer state to which to + * add the packet. + * @param[in] data const unsigned char*: The packet data. + * The application must ensure + * this pointer remains valid + * until the next call to + * opus_repacketizer_init() or + * opus_repacketizer_destroy(). + * @param len opus_int32: The number of bytes in the packet data. + * @returns An error code indicating whether or not the operation succeeded. + * @retval #OPUS_OK The packet's contents have been added to the repacketizer + * state. + * @retval #OPUS_INVALID_PACKET The packet did not have a valid TOC sequence, + * the packet's TOC sequence was not compatible + * with previously submitted packets (because + * the coding mode, audio bandwidth, frame size, + * or channel count did not match), or adding + * this packet would increase the total amount of + * audio stored in the repacketizer state to more + * than 120 ms. + */ +OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); + + +/** Construct a new packet from data previously submitted to the repacketizer + * state via opus_repacketizer_cat(). + * @param rp OpusRepacketizer*: The repacketizer state from which to + * construct the new packet. + * @param begin int: The index of the first frame in the current + * repacketizer state to include in the output. + * @param end int: One past the index of the last frame in the + * current repacketizer state to include in the + * output. + * @param[out] data const unsigned char*: The buffer in which to + * store the output packet. + * @param maxlen opus_int32: The maximum number of bytes to store in + * the output buffer. In order to guarantee + * success, this should be at least + * 1276 for a single frame, + * or for multiple frames, + * 1277*(end-begin). + * However, 1*(end-begin) plus + * the size of all packet data submitted to + * the repacketizer since the last call to + * opus_repacketizer_init() or + * opus_repacketizer_create() is also + * sufficient, and possibly much smaller. + * @returns The total size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BAD_ARG [begin,end) was an invalid range of + * frames (begin < 0, begin >= end, or end > + * opus_repacketizer_get_nb_frames()). + * @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the + * complete output packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Return the total number of frames contained in packet data submitted to + * the repacketizer state so far via opus_repacketizer_cat() since the last + * call to opus_repacketizer_init() or opus_repacketizer_create(). + * This defines the valid range of packets that can be extracted with + * opus_repacketizer_out_range() or opus_repacketizer_out(). + * @param rp OpusRepacketizer*: The repacketizer state containing the + * frames. + * @returns The total number of frames contained in the packet data submitted + * to the repacketizer state. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); + +/** Construct a new packet from data previously submitted to the repacketizer + * state via opus_repacketizer_cat(). + * This is a convenience routine that returns all the data submitted so far + * in a single packet. + * It is equivalent to calling + * @code + * opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp), + * data, maxlen) + * @endcode + * @param rp OpusRepacketizer*: The repacketizer state from which to + * construct the new packet. + * @param[out] data const unsigned char*: The buffer in which to + * store the output packet. + * @param maxlen opus_int32: The maximum number of bytes to store in + * the output buffer. In order to guarantee + * success, this should be at least + * 1277*opus_repacketizer_get_nb_frames(rp). + * However, + * 1*opus_repacketizer_get_nb_frames(rp) + * plus the size of all packet data + * submitted to the repacketizer since the + * last call to opus_repacketizer_init() or + * opus_repacketizer_create() is also + * sufficient, and possibly much smaller. + * @returns The total size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the + * complete output packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1); + +/** Pads a given Opus packet to a larger size (possibly changing the TOC sequence). + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to pad. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @param new_len opus_int32: The desired size of the packet after padding. + * This must be at least as large as len. + * @returns an error code + * @retval #OPUS_OK \a on success. + * @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len); + +/** Remove all padding from a given Opus packet and rewrite the TOC sequence to + * minimize space usage. + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to strip. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @returns The new size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BAD_ARG \a len was less than 1. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len); + +/** Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence). + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to pad. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @param new_len opus_int32: The desired size of the packet after padding. + * This must be at least 1. + * @param nb_streams opus_int32: The number of streams (not channels) in the packet. + * This must be at least as large as len. + * @returns an error code + * @retval #OPUS_OK \a on success. + * @retval #OPUS_BAD_ARG \a len was less than 1. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams); + +/** Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to + * minimize space usage. + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to strip. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @param nb_streams opus_int32: The number of streams (not channels) in the packet. + * This must be at least 1. + * @returns The new size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, int nb_streams); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_H */ diff --git a/src/libopus/include/opus_custom.h b/src/libopus/include/opus_custom.h new file mode 100644 index 0000000..2f22d4b --- /dev/null +++ b/src/libopus/include/opus_custom.h @@ -0,0 +1,343 @@ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2008-2012 Gregory Maxwell + Written by Jean-Marc Valin and Gregory Maxwell */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + @file opus_custom.h + @brief Opus-Custom reference implementation API + */ + +#ifndef OPUS_CUSTOM_H +#define OPUS_CUSTOM_H + +#include "opus_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef CUSTOM_MODES +# define OPUS_CUSTOM_EXPORT OPUS_EXPORT +# define OPUS_CUSTOM_EXPORT_STATIC OPUS_EXPORT +#else +# define OPUS_CUSTOM_EXPORT +# ifdef OPUS_BUILD +# define OPUS_CUSTOM_EXPORT_STATIC static OPUS_INLINE +# else +# define OPUS_CUSTOM_EXPORT_STATIC +# endif +#endif + +/** @defgroup opus_custom Opus Custom + * @{ + * Opus Custom is an optional part of the Opus specification and + * reference implementation which uses a distinct API from the regular + * API and supports frame sizes that are not normally supported.\ Use + * of Opus Custom is discouraged for all but very special applications + * for which a frame size different from 2.5, 5, 10, or 20 ms is needed + * (for either complexity or latency reasons) and where interoperability + * is less important. + * + * In addition to the interoperability limitations the use of Opus custom + * disables a substantial chunk of the codec and generally lowers the + * quality available at a given bitrate. Normally when an application needs + * a different frame size from the codec it should buffer to match the + * sizes but this adds a small amount of delay which may be important + * in some very low latency applications. Some transports (especially + * constant rate RF transports) may also work best with frames of + * particular durations. + * + * Libopus only supports custom modes if they are enabled at compile time. + * + * The Opus Custom API is similar to the regular API but the + * @ref opus_encoder_create and @ref opus_decoder_create calls take + * an additional mode parameter which is a structure produced by + * a call to @ref opus_custom_mode_create. Both the encoder and decoder + * must create a mode using the same sample rate (fs) and frame size + * (frame size) so these parameters must either be signaled out of band + * or fixed in a particular implementation. + * + * Similar to regular Opus the custom modes support on the fly frame size + * switching, but the sizes available depend on the particular frame size in + * use. For some initial frame sizes on a single on the fly size is available. + */ + +/** Contains the state of an encoder. One encoder state is needed + for each stream. It is initialized once at the beginning of the + stream. Do *not* re-initialize the state for every frame. + @brief Encoder state + */ +typedef struct OpusCustomEncoder OpusCustomEncoder; + +/** State of the decoder. One decoder state is needed for each stream. + It is initialized once at the beginning of the stream. Do *not* + re-initialize the state for every frame. + @brief Decoder state + */ +typedef struct OpusCustomDecoder OpusCustomDecoder; + +/** The mode contains all the information necessary to create an + encoder. Both the encoder and decoder need to be initialized + with exactly the same mode, otherwise the output will be + corrupted. The mode MUST NOT BE DESTROYED until the encoders and + decoders that use it are destroyed as well. + @brief Mode configuration + */ +typedef struct OpusCustomMode OpusCustomMode; + +/** Creates a new mode struct. This will be passed to an encoder or + * decoder. The mode MUST NOT BE DESTROYED until the encoders and + * decoders that use it are destroyed as well. + * @param [in] Fs int: Sampling rate (8000 to 96000 Hz) + * @param [in] frame_size int: Number of samples (per channel) to encode in each + * packet (64 - 1024, prime factorization must contain zero or more 2s, 3s, or 5s and no other primes) + * @param [out] error int*: Returned error code (if NULL, no error will be returned) + * @return A newly created mode + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomMode *opus_custom_mode_create(opus_int32 Fs, int frame_size, int *error); + +/** Destroys a mode struct. Only call this after all encoders and + * decoders using this mode are destroyed as well. + * @param [in] mode OpusCustomMode*: Mode to be freed. + */ +OPUS_CUSTOM_EXPORT void opus_custom_mode_destroy(OpusCustomMode *mode); + + +#if !defined(OPUS_BUILD) || defined(CELT_ENCODER_C) + +/* Encoder */ +/** Gets the size of an OpusCustomEncoder structure. + * @param [in] mode OpusCustomMode *: Mode configuration + * @param [in] channels int: Number of channels + * @returns size + */ +OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_encoder_get_size( + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1); + +# ifdef CUSTOM_MODES +/** Initializes a previously allocated encoder state + * The memory pointed to by st must be the size returned by opus_custom_encoder_get_size. + * This is intended for applications which use their own allocator instead of malloc. + * @see opus_custom_encoder_create(),opus_custom_encoder_get_size() + * To reset a previously initialized state use the OPUS_RESET_STATE CTL. + * @param [in] st OpusCustomEncoder*: Encoder state + * @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of + * the stream (must be the same characteristics as used for the + * decoder) + * @param [in] channels int: Number of channels + * @return OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT int opus_custom_encoder_init( + OpusCustomEncoder *st, + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); +# endif +#endif + + +/** Creates a new encoder state. Each stream needs its own encoder + * state (can't be shared across simultaneous streams). + * @param [in] mode OpusCustomMode*: Contains all the information about the characteristics of + * the stream (must be the same characteristics as used for the + * decoder) + * @param [in] channels int: Number of channels + * @param [out] error int*: Returns an error code + * @return Newly created encoder state. +*/ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomEncoder *opus_custom_encoder_create( + const OpusCustomMode *mode, + int channels, + int *error +) OPUS_ARG_NONNULL(1); + + +/** Destroys an encoder state. + * @param[in] st OpusCustomEncoder*: State to be freed. + */ +OPUS_CUSTOM_EXPORT void opus_custom_encoder_destroy(OpusCustomEncoder *st); + +/** Encodes a frame of audio. + * @param [in] st OpusCustomEncoder*: Encoder state + * @param [in] pcm float*: PCM audio in float format, with a normal range of +/-1.0. + * Samples with a range beyond +/-1.0 are supported but will + * be clipped by decoders using the integer API and should + * only be used if it is known that the far end supports + * extended dynamic range. There must be exactly + * frame_size samples per channel. + * @param [in] frame_size int: Number of samples per frame of input signal + * @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. + * @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame + * (can change from one frame to another) + * @return Number of bytes written to "compressed". + * If negative, an error has occurred (see error codes). It is IMPORTANT that + * the length returned be somehow transmitted to the decoder. Otherwise, no + * decoding is possible. + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode_float( + OpusCustomEncoder *st, + const float *pcm, + int frame_size, + unsigned char *compressed, + int maxCompressedBytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Encodes a frame of audio. + * @param [in] st OpusCustomEncoder*: Encoder state + * @param [in] pcm opus_int16*: PCM audio in signed 16-bit format (native endian). + * There must be exactly frame_size samples per channel. + * @param [in] frame_size int: Number of samples per frame of input signal + * @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. + * @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame + * (can change from one frame to another) + * @return Number of bytes written to "compressed". + * If negative, an error has occurred (see error codes). It is IMPORTANT that + * the length returned be somehow transmitted to the decoder. Otherwise, no + * decoding is possible. + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode( + OpusCustomEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *compressed, + int maxCompressedBytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on an Opus custom encoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @see opus_encoderctls + */ +OPUS_CUSTOM_EXPORT int opus_custom_encoder_ctl(OpusCustomEncoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); + + +#if !defined(OPUS_BUILD) || defined(CELT_DECODER_C) +/* Decoder */ + +/** Gets the size of an OpusCustomDecoder structure. + * @param [in] mode OpusCustomMode *: Mode configuration + * @param [in] channels int: Number of channels + * @returns size + */ +OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_decoder_get_size( + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1); + +/** Initializes a previously allocated decoder state + * The memory pointed to by st must be the size returned by opus_custom_decoder_get_size. + * This is intended for applications which use their own allocator instead of malloc. + * @see opus_custom_decoder_create(),opus_custom_decoder_get_size() + * To reset a previously initialized state use the OPUS_RESET_STATE CTL. + * @param [in] st OpusCustomDecoder*: Decoder state + * @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of + * the stream (must be the same characteristics as used for the + * encoder) + * @param [in] channels int: Number of channels + * @return OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT_STATIC int opus_custom_decoder_init( + OpusCustomDecoder *st, + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); + +#endif + + +/** Creates a new decoder state. Each stream needs its own decoder state (can't + * be shared across simultaneous streams). + * @param [in] mode OpusCustomMode: Contains all the information about the characteristics of the + * stream (must be the same characteristics as used for the encoder) + * @param [in] channels int: Number of channels + * @param [out] error int*: Returns an error code + * @return Newly created decoder state. + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomDecoder *opus_custom_decoder_create( + const OpusCustomMode *mode, + int channels, + int *error +) OPUS_ARG_NONNULL(1); + +/** Destroys a decoder state. + * @param[in] st OpusCustomDecoder*: State to be freed. + */ +OPUS_CUSTOM_EXPORT void opus_custom_decoder_destroy(OpusCustomDecoder *st); + +/** Decode an opus custom frame with floating point output + * @param [in] st OpusCustomDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len int: Number of bytes in payload + * @param [out] pcm float*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(float) + * @param [in] frame_size Number of samples per channel of available space in *pcm. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode_float( + OpusCustomDecoder *st, + const unsigned char *data, + int len, + float *pcm, + int frame_size +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Decode an opus custom frame + * @param [in] st OpusCustomDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len int: Number of bytes in payload + * @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(opus_int16) + * @param [in] frame_size Number of samples per channel of available space in *pcm. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode( + OpusCustomDecoder *st, + const unsigned char *data, + int len, + opus_int16 *pcm, + int frame_size +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on an Opus custom decoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @see opus_genericctls + */ +OPUS_CUSTOM_EXPORT int opus_custom_decoder_ctl(OpusCustomDecoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_CUSTOM_H */ diff --git a/src/libopus/include/opus_defines.h b/src/libopus/include/opus_defines.h new file mode 100644 index 0000000..cd8f4dd --- /dev/null +++ b/src/libopus/include/opus_defines.h @@ -0,0 +1,830 @@ +/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited + Written by Jean-Marc Valin and Koen Vos */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus_defines.h + * @brief Opus reference implementation constants + */ + +#ifndef OPUS_DEFINES_H +#define OPUS_DEFINES_H + +#include "opus_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @defgroup opus_errorcodes Error codes + * @{ + */ +/** No error @hideinitializer*/ +#define OPUS_OK 0 +/** One or more invalid/out of range arguments @hideinitializer*/ +#define OPUS_BAD_ARG -1 +/** Not enough bytes allocated in the buffer @hideinitializer*/ +#define OPUS_BUFFER_TOO_SMALL -2 +/** An internal error was detected @hideinitializer*/ +#define OPUS_INTERNAL_ERROR -3 +/** The compressed data passed is corrupted @hideinitializer*/ +#define OPUS_INVALID_PACKET -4 +/** Invalid/unsupported request number @hideinitializer*/ +#define OPUS_UNIMPLEMENTED -5 +/** An encoder or decoder structure is invalid or already freed @hideinitializer*/ +#define OPUS_INVALID_STATE -6 +/** Memory allocation has failed @hideinitializer*/ +#define OPUS_ALLOC_FAIL -7 +/**@}*/ + +/** @cond OPUS_INTERNAL_DOC */ +/**Export control for opus functions */ + +#ifndef OPUS_EXPORT +# if defined(_WIN32) +# if defined(OPUS_BUILD) && defined(DLL_EXPORT) +# define OPUS_EXPORT __declspec(dllexport) +# else +# define OPUS_EXPORT +# endif +# elif defined(__GNUC__) && defined(OPUS_BUILD) +# define OPUS_EXPORT __attribute__ ((visibility ("default"))) +# else +# define OPUS_EXPORT +# endif +#endif + +# if !defined(OPUS_GNUC_PREREQ) +# if defined(__GNUC__)&&defined(__GNUC_MINOR__) +# define OPUS_GNUC_PREREQ(_maj,_min) \ + ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) +# else +# define OPUS_GNUC_PREREQ(_maj,_min) 0 +# endif +# endif + +#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) +# if OPUS_GNUC_PREREQ(3,0) +# define OPUS_RESTRICT __restrict__ +# elif (defined(_MSC_VER) && _MSC_VER >= 1400) +# define OPUS_RESTRICT __restrict +# else +# define OPUS_RESTRICT +# endif +#else +# define OPUS_RESTRICT restrict +#endif + +#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) +# if OPUS_GNUC_PREREQ(2,7) +# define OPUS_INLINE __inline__ +# elif (defined(_MSC_VER)) +# define OPUS_INLINE __inline +# else +# define OPUS_INLINE +# endif +#else +# define OPUS_INLINE inline +#endif + +/**Warning attributes for opus functions + * NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out + * some paranoid null checks. */ +#if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) +# define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) +#else +# define OPUS_WARN_UNUSED_RESULT +#endif +#if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) +# define OPUS_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x))) +#else +# define OPUS_ARG_NONNULL(_x) +#endif + +/** These are the actual Encoder CTL ID numbers. + * They should not be used directly by applications. + * In general, SETs should be even and GETs should be odd.*/ +#define OPUS_SET_APPLICATION_REQUEST 4000 +#define OPUS_GET_APPLICATION_REQUEST 4001 +#define OPUS_SET_BITRATE_REQUEST 4002 +#define OPUS_GET_BITRATE_REQUEST 4003 +#define OPUS_SET_MAX_BANDWIDTH_REQUEST 4004 +#define OPUS_GET_MAX_BANDWIDTH_REQUEST 4005 +#define OPUS_SET_VBR_REQUEST 4006 +#define OPUS_GET_VBR_REQUEST 4007 +#define OPUS_SET_BANDWIDTH_REQUEST 4008 +#define OPUS_GET_BANDWIDTH_REQUEST 4009 +#define OPUS_SET_COMPLEXITY_REQUEST 4010 +#define OPUS_GET_COMPLEXITY_REQUEST 4011 +#define OPUS_SET_INBAND_FEC_REQUEST 4012 +#define OPUS_GET_INBAND_FEC_REQUEST 4013 +#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014 +#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015 +#define OPUS_SET_DTX_REQUEST 4016 +#define OPUS_GET_DTX_REQUEST 4017 +#define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020 +#define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021 +#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022 +#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023 +#define OPUS_SET_SIGNAL_REQUEST 4024 +#define OPUS_GET_SIGNAL_REQUEST 4025 +#define OPUS_GET_LOOKAHEAD_REQUEST 4027 +/* #define OPUS_RESET_STATE 4028 */ +#define OPUS_GET_SAMPLE_RATE_REQUEST 4029 +#define OPUS_GET_FINAL_RANGE_REQUEST 4031 +#define OPUS_GET_PITCH_REQUEST 4033 +#define OPUS_SET_GAIN_REQUEST 4034 +#define OPUS_GET_GAIN_REQUEST 4045 /* Should have been 4035 */ +#define OPUS_SET_LSB_DEPTH_REQUEST 4036 +#define OPUS_GET_LSB_DEPTH_REQUEST 4037 +#define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039 +#define OPUS_SET_EXPERT_FRAME_DURATION_REQUEST 4040 +#define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041 +#define OPUS_SET_PREDICTION_DISABLED_REQUEST 4042 +#define OPUS_GET_PREDICTION_DISABLED_REQUEST 4043 +/* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */ +#define OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST 4046 +#define OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST 4047 +#define OPUS_GET_IN_DTX_REQUEST 4049 +#define OPUS_SET_DRED_DURATION_REQUEST 4050 +#define OPUS_GET_DRED_DURATION_REQUEST 4051 +#define OPUS_SET_DNN_BLOB_REQUEST 4052 +/*#define OPUS_GET_DNN_BLOB_REQUEST 4053 */ + +/** Defines for the presence of extended APIs. */ +#define OPUS_HAVE_OPUS_PROJECTION_H + +/* Macros to trigger compilation errors when the wrong types are provided to a CTL */ +#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x)) + +#ifdef DISABLE_PTR_CHECK +/* Disable checks to prevent ubsan from complaining about NULL checks + in test_opus_api. */ +#define __opus_check_int_ptr(ptr) (ptr) +#define __opus_check_uint_ptr(ptr) (ptr) +#define __opus_check_uint8_ptr(ptr) (ptr) +#define __opus_check_val16_ptr(ptr) (ptr) +#define __opus_check_void_ptr(ptr) (ptr) +#else +#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr))) +#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr))) +#define __opus_check_uint8_ptr(ptr) ((ptr) + ((ptr) - (opus_uint8*)(ptr))) +#define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr))) +#define __opus_check_void_ptr(x) ((void)((void *)0 == (x)), (x)) +#endif +/** @endcond */ + +/** @defgroup opus_ctlvalues Pre-defined values for CTL interface + * @see opus_genericctls, opus_encoderctls + * @{ + */ +/* Values for the various encoder CTLs */ +#define OPUS_AUTO -1000 /**opus_int32: Allowed values: 0-10, inclusive. + * + * @hideinitializer */ +#define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x) +/** Gets the encoder's complexity configuration. + * @see OPUS_SET_COMPLEXITY + * @param[out] x opus_int32 *: Returns a value in the range 0-10, + * inclusive. + * @hideinitializer */ +#define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x) + +/** Configures the bitrate in the encoder. + * Rates from 500 to 512000 bits per second are meaningful, as well as the + * special values #OPUS_AUTO and #OPUS_BITRATE_MAX. + * The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much + * rate as it can, which is useful for controlling the rate by adjusting the + * output buffer size. + * @see OPUS_GET_BITRATE + * @param[in] x opus_int32: Bitrate in bits per second. The default + * is determined based on the number of + * channels and the input sampling rate. + * @hideinitializer */ +#define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x) +/** Gets the encoder's bitrate configuration. + * @see OPUS_SET_BITRATE + * @param[out] x opus_int32 *: Returns the bitrate in bits per second. + * The default is determined based on the + * number of channels and the input + * sampling rate. + * @hideinitializer */ +#define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x) + +/** Enables or disables variable bitrate (VBR) in the encoder. + * The configured bitrate may not be met exactly because frames must + * be an integer number of bytes in length. + * @see OPUS_GET_VBR + * @see OPUS_SET_VBR_CONSTRAINT + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Hard CBR. For LPC/hybrid modes at very low bit-rate, this can + * cause noticeable quality degradation.
+ *
1
VBR (default). The exact type of VBR is controlled by + * #OPUS_SET_VBR_CONSTRAINT.
+ *
+ * @hideinitializer */ +#define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x) +/** Determine if variable bitrate (VBR) is enabled in the encoder. + * @see OPUS_SET_VBR + * @see OPUS_GET_VBR_CONSTRAINT + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Hard CBR.
+ *
1
VBR (default). The exact type of VBR may be retrieved via + * #OPUS_GET_VBR_CONSTRAINT.
+ *
+ * @hideinitializer */ +#define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x) + +/** Enables or disables constrained VBR in the encoder. + * This setting is ignored when the encoder is in CBR mode. + * @warning Only the MDCT mode of Opus currently heeds the constraint. + * Speech mode ignores it completely, hybrid mode may fail to obey it + * if the LPC layer uses more bitrate than the constraint would have + * permitted. + * @see OPUS_GET_VBR_CONSTRAINT + * @see OPUS_SET_VBR + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Unconstrained VBR.
+ *
1
Constrained VBR (default). This creates a maximum of one + * frame of buffering delay assuming a transport with a + * serialization speed of the nominal bitrate.
+ *
+ * @hideinitializer */ +#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x) +/** Determine if constrained VBR is enabled in the encoder. + * @see OPUS_SET_VBR_CONSTRAINT + * @see OPUS_GET_VBR + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Unconstrained VBR.
+ *
1
Constrained VBR (default).
+ *
+ * @hideinitializer */ +#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x) + +/** Configures mono/stereo forcing in the encoder. + * This can force the encoder to produce packets encoded as either mono or + * stereo, regardless of the format of the input audio. This is useful when + * the caller knows that the input signal is currently a mono source embedded + * in a stereo stream. + * @see OPUS_GET_FORCE_CHANNELS + * @param[in] x opus_int32: Allowed values: + *
+ *
#OPUS_AUTO
Not forced (default)
+ *
1
Forced mono
+ *
2
Forced stereo
+ *
+ * @hideinitializer */ +#define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x) +/** Gets the encoder's forced channel configuration. + * @see OPUS_SET_FORCE_CHANNELS + * @param[out] x opus_int32 *: + *
+ *
#OPUS_AUTO
Not forced (default)
+ *
1
Forced mono
+ *
2
Forced stereo
+ *
+ * @hideinitializer */ +#define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x) + +/** Configures the maximum bandpass that the encoder will select automatically. + * Applications should normally use this instead of #OPUS_SET_BANDWIDTH + * (leaving that set to the default, #OPUS_AUTO). This allows the + * application to set an upper bound based on the type of input it is + * providing, but still gives the encoder the freedom to reduce the bandpass + * when the bitrate becomes too low, for better overall quality. + * @see OPUS_GET_MAX_BANDWIDTH + * @param[in] x opus_int32: Allowed values: + *
+ *
OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
+ *
+ * @hideinitializer */ +#define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x) + +/** Gets the encoder's configured maximum allowed bandpass. + * @see OPUS_SET_MAX_BANDWIDTH + * @param[out] x opus_int32 *: Allowed values: + *
+ *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
+ *
+ * @hideinitializer */ +#define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) + +/** Sets the encoder's bandpass to a specific value. + * This prevents the encoder from automatically selecting the bandpass based + * on the available bitrate. If an application knows the bandpass of the input + * audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH + * instead, which still gives the encoder the freedom to reduce the bandpass + * when the bitrate becomes too low, for better overall quality. + * @see OPUS_GET_BANDWIDTH + * @param[in] x opus_int32: Allowed values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
+ *
+ * @hideinitializer */ +#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x) + +/** Configures the type of signal being encoded. + * This is a hint which helps the encoder's mode selection. + * @see OPUS_GET_SIGNAL + * @param[in] x opus_int32: Allowed values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
+ *
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
+ *
+ * @hideinitializer */ +#define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured signal type. + * @see OPUS_SET_SIGNAL + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
+ *
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
+ *
+ * @hideinitializer */ +#define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x) + + +/** Configures the encoder's intended application. + * The initial value is a mandatory argument to the encoder_create function. + * @see OPUS_GET_APPLICATION + * @param[in] x opus_int32: Returns one of the following values: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @hideinitializer */ +#define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured application. + * @see OPUS_SET_APPLICATION + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @hideinitializer */ +#define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x) + +/** Gets the total samples of delay added by the entire codec. + * This can be queried by the encoder and then the provided number of samples can be + * skipped on from the start of the decoder's output to provide time aligned input + * and output. From the perspective of a decoding application the real data begins this many + * samples late. + * + * The decoder contribution to this delay is identical for all decoders, but the + * encoder portion of the delay may vary from implementation to implementation, + * version to version, or even depend on the encoder's initial configuration. + * Applications needing delay compensation should call this CTL rather than + * hard-coding a value. + * @param[out] x opus_int32 *: Number of lookahead samples + * @hideinitializer */ +#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's use of inband forward error correction (FEC). + * @note This is only applicable to the LPC layer + * @see OPUS_GET_INBAND_FEC + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Disable inband FEC (default).
+ *
1
Inband FEC enabled. If the packet loss rate is sufficiently high, Opus will automatically switch to SILK even at high rates to enable use of that FEC.
+ *
2
Inband FEC enabled, but does not necessarily switch to SILK if we have music.
+ *
+ * @hideinitializer */ +#define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x) +/** Gets encoder's configured use of inband forward error correction. + * @see OPUS_SET_INBAND_FEC + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Inband FEC disabled (default).
+ *
1
Inband FEC enabled. If the packet loss rate is sufficiently high, Opus will automatically switch to SILK even at high rates to enable use of that FEC.
+ *
2
Inband FEC enabled, but does not necessarily switch to SILK if we have music.
+ *
+ * @hideinitializer */ +#define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's expected packet loss percentage. + * Higher values trigger progressively more loss resistant behavior in the encoder + * at the expense of quality at a given bitrate in the absence of packet loss, but + * greater quality under loss. + * @see OPUS_GET_PACKET_LOSS_PERC + * @param[in] x opus_int32: Loss percentage in the range 0-100, inclusive (default: 0). + * @hideinitializer */ +#define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured packet loss percentage. + * @see OPUS_SET_PACKET_LOSS_PERC + * @param[out] x opus_int32 *: Returns the configured loss percentage + * in the range 0-100, inclusive (default: 0). + * @hideinitializer */ +#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's use of discontinuous transmission (DTX). + * @note This is only applicable to the LPC layer + * @see OPUS_GET_DTX + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Disable DTX (default).
+ *
1
Enabled DTX.
+ *
+ * @hideinitializer */ +#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x) +/** Gets encoder's configured use of discontinuous transmission. + * @see OPUS_SET_DTX + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
DTX disabled (default).
+ *
1
DTX enabled.
+ *
+ * @hideinitializer */ +#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x) +/** Configures the depth of signal being encoded. + * + * This is a hint which helps the encoder identify silence and near-silence. + * It represents the number of significant bits of linear intensity below + * which the signal contains ignorable quantization or other noise. + * + * For example, OPUS_SET_LSB_DEPTH(14) would be an appropriate setting + * for G.711 u-law input. OPUS_SET_LSB_DEPTH(16) would be appropriate + * for 16-bit linear pcm input with opus_encode_float(). + * + * When using opus_encode() instead of opus_encode_float(), or when libopus + * is compiled for fixed-point, the encoder uses the minimum of the value + * set here and the value 16. + * + * @see OPUS_GET_LSB_DEPTH + * @param[in] x opus_int32: Input precision in bits, between 8 and 24 + * (default: 24). + * @hideinitializer */ +#define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured signal depth. + * @see OPUS_SET_LSB_DEPTH + * @param[out] x opus_int32 *: Input precision in bits, between 8 and + * 24 (default: 24). + * @hideinitializer */ +#define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's use of variable duration frames. + * When variable duration is enabled, the encoder is free to use a shorter frame + * size than the one requested in the opus_encode*() call. + * It is then the user's responsibility + * to verify how much audio was encoded by checking the ToC byte of the encoded + * packet. The part of the audio that was not encoded needs to be resent to the + * encoder for the next call. Do not use this option unless you really + * know what you are doing. + * @see OPUS_GET_EXPERT_FRAME_DURATION + * @param[in] x opus_int32: Allowed values: + *
+ *
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
+ *
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
+ *
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
+ *
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
+ *
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
+ *
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
+ *
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
+ *
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
+ *
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
+ *
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
+ *
+ * @hideinitializer */ +#define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured use of variable duration frames. + * @see OPUS_SET_EXPERT_FRAME_DURATION + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
+ *
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
+ *
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
+ *
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
+ *
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
+ *
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
+ *
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
+ *
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
+ *
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
+ *
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
+ *
+ * @hideinitializer */ +#define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x) + +/** If set to 1, disables almost all use of prediction, making frames almost + * completely independent. This reduces quality. + * @see OPUS_GET_PREDICTION_DISABLED + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Enable prediction (default).
+ *
1
Disable prediction.
+ *
+ * @hideinitializer */ +#define OPUS_SET_PREDICTION_DISABLED(x) OPUS_SET_PREDICTION_DISABLED_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured prediction status. + * @see OPUS_SET_PREDICTION_DISABLED + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Prediction enabled (default).
+ *
1
Prediction disabled.
+ *
+ * @hideinitializer */ +#define OPUS_GET_PREDICTION_DISABLED(x) OPUS_GET_PREDICTION_DISABLED_REQUEST, __opus_check_int_ptr(x) + +/** If non-zero, enables Deep Redundancy (DRED) and use the specified maximum number of 10-ms redundant frames + * @hideinitializer */ +#define OPUS_SET_DRED_DURATION(x) OPUS_SET_DRED_DURATION_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured Deep Redundancy (DRED) maximum number of frames. + * @hideinitializer */ +#define OPUS_GET_DRED_DURATION(x) OPUS_GET_DRED_DURATION_REQUEST, __opus_check_int_ptr(x) + +/** Provide external DNN weights from binary object (only when explicitly built without the weights) + * @hideinitializer */ +#define OPUS_SET_DNN_BLOB(data, len) OPUS_SET_DNN_BLOB_REQUEST, __opus_check_void_ptr(data), __opus_check_int(len) + + +/**@}*/ + +/** @defgroup opus_genericctls Generic CTLs + * + * These macros are used with the \c opus_decoder_ctl and + * \c opus_encoder_ctl calls to generate a particular + * request. + * + * When called on an \c OpusDecoder they apply to that + * particular decoder instance. When called on an + * \c OpusEncoder they apply to the corresponding setting + * on that encoder instance, if present. + * + * Some usage examples: + * + * @code + * int ret; + * opus_int32 pitch; + * ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch)); + * if (ret == OPUS_OK) return ret; + * + * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); + * opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE); + * + * opus_int32 enc_bw, dec_bw; + * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw)); + * opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw)); + * if (enc_bw != dec_bw) { + * printf("packet bandwidth mismatch!\n"); + * } + * @endcode + * + * @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls + * @{ + */ + +/** Resets the codec state to be equivalent to a freshly initialized state. + * This should be called when switching streams in order to prevent + * the back to back decoding from giving different results from + * one at a time decoding. + * @hideinitializer */ +#define OPUS_RESET_STATE 4028 + +/** Gets the final state of the codec's entropy coder. + * This is used for testing purposes, + * The encoder and decoder state should be identical after coding a payload + * (assuming no data corruption or software bugs) + * + * @param[out] x opus_uint32 *: Entropy coder state + * + * @hideinitializer */ +#define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x) + +/** Gets the encoder's configured bandpass or the decoder's last bandpass. + * @see OPUS_SET_BANDWIDTH + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
+ *
+ * @hideinitializer */ +#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) + +/** Gets the sampling rate the encoder or decoder was initialized with. + * This simply returns the Fs value passed to opus_encoder_init() + * or opus_decoder_init(). + * @param[out] x opus_int32 *: Sampling rate of encoder or decoder. + * @hideinitializer + */ +#define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x) + +/** If set to 1, disables the use of phase inversion for intensity stereo, + * improving the quality of mono downmixes, but slightly reducing normal + * stereo quality. Disabling phase inversion in the decoder does not comply + * with RFC 6716, although it does not cause any interoperability issue and + * is expected to become part of the Opus standard once RFC 6716 is updated + * by draft-ietf-codec-opus-update. + * @see OPUS_GET_PHASE_INVERSION_DISABLED + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Enable phase inversion (default).
+ *
1
Disable phase inversion.
+ *
+ * @hideinitializer */ +#define OPUS_SET_PHASE_INVERSION_DISABLED(x) OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured phase inversion status. + * @see OPUS_SET_PHASE_INVERSION_DISABLED + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Stereo phase inversion enabled (default).
+ *
1
Stereo phase inversion disabled.
+ *
+ * @hideinitializer */ +#define OPUS_GET_PHASE_INVERSION_DISABLED(x) OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int_ptr(x) +/** Gets the DTX state of the encoder. + * Returns whether the last encoded frame was either a comfort noise update + * during DTX or not encoded because of DTX. + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
The encoder is not in DTX.
+ *
1
The encoder is in DTX.
+ *
+ * @hideinitializer */ +#define OPUS_GET_IN_DTX(x) OPUS_GET_IN_DTX_REQUEST, __opus_check_int_ptr(x) + +/**@}*/ + +/** @defgroup opus_decoderctls Decoder related CTLs + * @see opus_genericctls, opus_encoderctls, opus_decoder + * @{ + */ + +/** Configures decoder gain adjustment. + * Scales the decoded output by a factor specified in Q8 dB units. + * This has a maximum range of -32768 to 32767 inclusive, and returns + * OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment. + * This setting survives decoder reset. + * + * gain = pow(10, x/(20.0*256)) + * + * @param[in] x opus_int32: Amount to scale PCM signal by in Q8 dB units. + * @hideinitializer */ +#define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x) +/** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN + * + * @param[out] x opus_int32 *: Amount to scale PCM signal by in Q8 dB units. + * @hideinitializer */ +#define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x) + +/** Gets the duration (in samples) of the last packet successfully decoded or concealed. + * @param[out] x opus_int32 *: Number of samples (at current sampling rate). + * @hideinitializer */ +#define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x) + +/** Gets the pitch of the last decoded frame, if available. + * This can be used for any post-processing algorithm requiring the use of pitch, + * e.g. time stretching/shortening. If the last frame was not voiced, or if the + * pitch was not coded in the frame, then zero is returned. + * + * This CTL is only implemented for decoder instances. + * + * @param[out] x opus_int32 *: pitch period at 48 kHz (or 0 if not available) + * + * @hideinitializer */ +#define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x) + +/**@}*/ + +/** @defgroup opus_libinfo Opus library information functions + * @{ + */ + +/** Converts an opus error code into a human readable string. + * + * @param[in] error int: Error number + * @returns Error string + */ +OPUS_EXPORT const char *opus_strerror(int error); + +/** Gets the libopus version string. + * + * Applications may look for the substring "-fixed" in the version string to + * determine whether they have a fixed-point or floating-point build at + * runtime. + * + * @returns Version string + */ +OPUS_EXPORT const char *opus_get_version_string(void); +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_DEFINES_H */ diff --git a/src/libopus/include/opus_multistream.h b/src/libopus/include/opus_multistream.h new file mode 100644 index 0000000..824cc55 --- /dev/null +++ b/src/libopus/include/opus_multistream.h @@ -0,0 +1,660 @@ +/* Copyright (c) 2011 Xiph.Org Foundation + Written by Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus_multistream.h + * @brief Opus reference implementation multistream API + */ + +#ifndef OPUS_MULTISTREAM_H +#define OPUS_MULTISTREAM_H + +#include "opus.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @cond OPUS_INTERNAL_DOC */ + +/** Macros to trigger compilation errors when the wrong types are provided to a + * CTL. */ +/**@{*/ +#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) +#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) +/**@}*/ + +/** These are the actual encoder and decoder CTL ID numbers. + * They should not be used directly by applications. + * In general, SETs should be even and GETs should be odd.*/ +/**@{*/ +#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 +#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 +/**@}*/ + +/** @endcond */ + +/** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs + * + * These are convenience macros that are specific to the + * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl() + * interface. + * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and + * @ref opus_decoderctls may be applied to a multistream encoder or decoder as + * well. + * In addition, you may retrieve the encoder or decoder state for an specific + * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or + * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually. + */ +/**@{*/ + +/** Gets the encoder state for an individual stream of a multistream encoder. + * @param[in] x opus_int32: The index of the stream whose encoder you + * wish to retrieve. + * This must be non-negative and less than + * the streams parameter used + * to initialize the encoder. + * @param[out] y OpusEncoder**: Returns a pointer to the given + * encoder state. + * @retval OPUS_BAD_ARG The index of the requested stream was out of range. + * @hideinitializer + */ +#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) + +/** Gets the decoder state for an individual stream of a multistream decoder. + * @param[in] x opus_int32: The index of the stream whose decoder you + * wish to retrieve. + * This must be non-negative and less than + * the streams parameter used + * to initialize the decoder. + * @param[out] y OpusDecoder**: Returns a pointer to the given + * decoder state. + * @retval OPUS_BAD_ARG The index of the requested stream was out of range. + * @hideinitializer + */ +#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) + +/**@}*/ + +/** @defgroup opus_multistream Opus Multistream API + * @{ + * + * The multistream API allows individual Opus streams to be combined into a + * single packet, enabling support for up to 255 channels. Unlike an + * elementary Opus stream, the encoder and decoder must negotiate the channel + * configuration before the decoder can successfully interpret the data in the + * packets produced by the encoder. Some basic information, such as packet + * duration, can be computed without any special negotiation. + * + * The format for multistream Opus packets is defined in + * RFC 7845 + * and is based on the self-delimited Opus framing described in Appendix B of + * RFC 6716. + * Normal Opus packets are just a degenerate case of multistream Opus packets, + * and can be encoded or decoded with the multistream API by setting + * streams to 1 when initializing the encoder or + * decoder. + * + * Multistream Opus streams can contain up to 255 elementary Opus streams. + * These may be either "uncoupled" or "coupled", indicating that the decoder + * is configured to decode them to either 1 or 2 channels, respectively. + * The streams are ordered so that all coupled streams appear at the + * beginning. + * + * A mapping table defines which decoded channel i + * should be used for each input/output (I/O) channel j. This table is + * typically provided as an unsigned char array. + * Let i = mapping[j] be the index for I/O channel j. + * If i < 2*coupled_streams, then I/O channel j is + * encoded as the left channel of stream (i/2) if i + * is even, or as the right channel of stream (i/2) if + * i is odd. Otherwise, I/O channel j is encoded as + * mono in stream (i - coupled_streams), unless it has the special + * value 255, in which case it is omitted from the encoding entirely (the + * decoder will reproduce it as silence). Each value i must either + * be the special value 255 or be less than streams + coupled_streams. + * + * The output channels specified by the encoder + * should use the + * Vorbis + * channel ordering. A decoder may wish to apply an additional permutation + * to the mapping the encoder used to achieve a different output channel + * order (e.g. for outputting in WAV order). + * + * Each multistream packet contains an Opus packet for each stream, and all of + * the Opus packets in a single multistream packet must have the same + * duration. Therefore the duration of a multistream packet can be extracted + * from the TOC sequence of the first stream, which is located at the + * beginning of the packet, just like an elementary Opus stream: + * + * @code + * int nb_samples; + * int nb_frames; + * nb_frames = opus_packet_get_nb_frames(data, len); + * if (nb_frames < 1) + * return nb_frames; + * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames; + * @endcode + * + * The general encoding and decoding process proceeds exactly the same as in + * the normal @ref opus_encoder and @ref opus_decoder APIs. + * See their documentation for an overview of how to use the corresponding + * multistream functions. + */ + +/** Opus multistream encoder state. + * This contains the complete state of a multistream Opus encoder. + * It is position independent and can be freely copied. + * @see opus_multistream_encoder_create + * @see opus_multistream_encoder_init + */ +typedef struct OpusMSEncoder OpusMSEncoder; + +/** Opus multistream decoder state. + * This contains the complete state of a multistream Opus decoder. + * It is position independent and can be freely copied. + * @see opus_multistream_decoder_create + * @see opus_multistream_decoder_init + */ +typedef struct OpusMSDecoder OpusMSDecoder; + +/**\name Multistream encoder functions */ +/**@{*/ + +/** Gets the size of an OpusMSEncoder structure. + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than 255. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size( + int streams, + int coupled_streams +); + +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_surround_encoder_get_size( + int channels, + int mapping_family +); + + +/** Allocates and initializes a multistream encoder state. + * Call opus_multistream_encoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than the number of channels. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than the number of input channels. + * @param[in] mapping const unsigned char[channels]: Mapping from + * encoded channels to input channels, as described in + * @ref opus_multistream. As an extra constraint, the + * multistream encoder does not allow encoding coupled + * streams for which one channel is unused since this + * is never a good idea. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create( + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping, + int application, + int *error +) OPUS_ARG_NONNULL(5); + +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_surround_encoder_create( + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + unsigned char *mapping, + int application, + int *error +) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); + +/** Initialize a previously allocated multistream encoder state. + * The memory pointed to by \a st must be at least the size returned by + * opus_multistream_encoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_multistream_encoder_create + * @see opus_multistream_encoder_get_size + * @param st OpusMSEncoder*: Multistream encoder state to initialize. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than the number of channels. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than the number of input channels. + * @param[in] mapping const unsigned char[channels]: Mapping from + * encoded channels to input channels, as described in + * @ref opus_multistream. As an extra constraint, the + * multistream encoder does not allow encoding coupled + * streams for which one channel is unused since this + * is never a good idea. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_multistream_encoder_init( + OpusMSEncoder *st, + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping, + int application +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); + +OPUS_EXPORT int opus_multistream_surround_encoder_init( + OpusMSEncoder *st, + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + unsigned char *mapping, + int application +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6) OPUS_ARG_NONNULL(7); + +/** Encodes a multistream Opus frame. + * @param st OpusMSEncoder*: Multistream encoder state. + * @param[in] pcm const opus_int16*: The input signal as interleaved + * samples. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( + OpusMSEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Encodes a multistream Opus frame from floating point input. + * @param st OpusMSEncoder*: Multistream encoder state. + * @param[in] pcm const float*: The input signal as interleaved + * samples with a normal range of + * +/-1.0. + * Samples with a range beyond +/-1.0 + * are supported but will be clipped by + * decoders using the integer API and + * should only be used if it is known + * that the far end supports extended + * dynamic range. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( + OpusMSEncoder *st, + const float *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Frees an OpusMSEncoder allocated by + * opus_multistream_encoder_create(). + * @param st OpusMSEncoder*: Multistream encoder state to be freed. + */ +OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); + +/** Perform a CTL function on a multistream Opus encoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusMSEncoder*: Multistream encoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_encoderctls, or @ref opus_multistream_ctls. + * @see opus_genericctls + * @see opus_encoderctls + * @see opus_multistream_ctls + */ +OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); + +/**@}*/ + +/**\name Multistream decoder functions */ +/**@{*/ + +/** Gets the size of an OpusMSDecoder structure. + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size( + int streams, + int coupled_streams +); + +/** Allocates and initializes a multistream decoder state. + * Call opus_multistream_decoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] mapping const unsigned char[channels]: Mapping from + * coded channels to output channels, as described in + * @ref opus_multistream. + * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create( + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping, + int *error +) OPUS_ARG_NONNULL(5); + +/** Intialize a previously allocated decoder state object. + * The memory pointed to by \a st must be at least the size returned by + * opus_multistream_encoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_multistream_decoder_create + * @see opus_multistream_deocder_get_size + * @param st OpusMSEncoder*: Multistream encoder state to initialize. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] mapping const unsigned char[channels]: Mapping from + * coded channels to output channels, as described in + * @ref opus_multistream. + * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_multistream_decoder_init( + OpusMSDecoder *st, + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); + +/** Decode a multistream Opus packet. + * @param st OpusMSDecoder*: Multistream decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( + OpusMSDecoder *st, + const unsigned char *data, + opus_int32 len, + opus_int16 *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Decode a multistream Opus packet with floating point output. + * @param st OpusMSDecoder*: Multistream decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( + OpusMSDecoder *st, + const unsigned char *data, + opus_int32 len, + float *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on a multistream Opus decoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusMSDecoder*: Multistream decoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_decoderctls, or @ref opus_multistream_ctls. + * @see opus_genericctls + * @see opus_decoderctls + * @see opus_multistream_ctls + */ +OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); + +/** Frees an OpusMSDecoder allocated by + * opus_multistream_decoder_create(). + * @param st OpusMSDecoder: Multistream decoder state to be freed. + */ +OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); + +/**@}*/ + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_MULTISTREAM_H */ diff --git a/src/libopus/include/opus_projection.h b/src/libopus/include/opus_projection.h new file mode 100644 index 0000000..9dabf4e --- /dev/null +++ b/src/libopus/include/opus_projection.h @@ -0,0 +1,568 @@ +/* Copyright (c) 2017 Google Inc. + Written by Andrew Allen */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus_projection.h + * @brief Opus projection reference API + */ + +#ifndef OPUS_PROJECTION_H +#define OPUS_PROJECTION_H + +#include "opus_multistream.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @cond OPUS_INTERNAL_DOC */ + +/** These are the actual encoder and decoder CTL ID numbers. + * They should not be used directly by applications.c + * In general, SETs should be even and GETs should be odd.*/ +/**@{*/ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST 6001 +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST 6003 +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST 6005 +/**@}*/ + + +/** @endcond */ + +/** @defgroup opus_projection_ctls Projection specific encoder and decoder CTLs + * + * These are convenience macros that are specific to the + * opus_projection_encoder_ctl() and opus_projection_decoder_ctl() + * interface. + * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, + * @ref opus_decoderctls, and @ref opus_multistream_ctls may be applied to a + * projection encoder or decoder as well. + */ +/**@{*/ + +/** Gets the gain (in dB. S7.8-format) of the demixing matrix from the encoder. + * @param[out] x opus_int32 *: Returns the gain (in dB. S7.8-format) + * of the demixing matrix. + * @hideinitializer + */ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST, __opus_check_int_ptr(x) + + +/** Gets the size in bytes of the demixing matrix from the encoder. + * @param[out] x opus_int32 *: Returns the size in bytes of the + * demixing matrix. + * @hideinitializer + */ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST, __opus_check_int_ptr(x) + + +/** Copies the demixing matrix to the supplied pointer location. + * @param[out] x unsigned char *: Returns the demixing matrix to the + * supplied pointer location. + * @param y opus_int32: The size in bytes of the reserved memory at the + * pointer location. + * @hideinitializer + */ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX(x,y) OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST, x, __opus_check_int(y) + + +/**@}*/ + +/** Opus projection encoder state. + * This contains the complete state of a projection Opus encoder. + * It is position independent and can be freely copied. + * @see opus_projection_ambisonics_encoder_create + */ +typedef struct OpusProjectionEncoder OpusProjectionEncoder; + + +/** Opus projection decoder state. + * This contains the complete state of a projection Opus decoder. + * It is position independent and can be freely copied. + * @see opus_projection_decoder_create + * @see opus_projection_decoder_init + */ +typedef struct OpusProjectionDecoder OpusProjectionDecoder; + + +/**\name Projection encoder functions */ +/**@{*/ + +/** Gets the size of an OpusProjectionEncoder structure. + * @param channels int: The total number of input channels to encode. + * This must be no more than 255. + * @param mapping_family int: The mapping family to use for selecting + * the appropriate projection. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_ambisonics_encoder_get_size( + int channels, + int mapping_family +); + + +/** Allocates and initializes a projection encoder state. + * Call opus_projection_encoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param mapping_family int: The mapping family to use for selecting + * the appropriate projection. + * @param[out] streams int *: The total number of streams that will + * be encoded from the input. + * @param[out] coupled_streams int *: Number of coupled (2 channel) + * streams that will be encoded from the input. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionEncoder *opus_projection_ambisonics_encoder_create( + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + int application, + int *error +) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5); + + +/** Initialize a previously allocated projection encoder state. + * The memory pointed to by \a st must be at least the size returned by + * opus_projection_ambisonics_encoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_projection_ambisonics_encoder_create + * @see opus_projection_ambisonics_encoder_get_size + * @param st OpusProjectionEncoder*: Projection encoder state to initialize. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than the number of channels. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than the number of input channels. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_projection_ambisonics_encoder_init( + OpusProjectionEncoder *st, + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + int application +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); + + +/** Encodes a projection Opus frame. + * @param st OpusProjectionEncoder*: Projection encoder state. + * @param[in] pcm const opus_int16*: The input signal as interleaved + * samples. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode( + OpusProjectionEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + + +/** Encodes a projection Opus frame from floating point input. + * @param st OpusProjectionEncoder*: Projection encoder state. + * @param[in] pcm const float*: The input signal as interleaved + * samples with a normal range of + * +/-1.0. + * Samples with a range beyond +/-1.0 + * are supported but will be clipped by + * decoders using the integer API and + * should only be used if it is known + * that the far end supports extended + * dynamic range. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode_float( + OpusProjectionEncoder *st, + const float *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + + +/** Frees an OpusProjectionEncoder allocated by + * opus_projection_ambisonics_encoder_create(). + * @param st OpusProjectionEncoder*: Projection encoder state to be freed. + */ +OPUS_EXPORT void opus_projection_encoder_destroy(OpusProjectionEncoder *st); + + +/** Perform a CTL function on a projection Opus encoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusProjectionEncoder*: Projection encoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_encoderctls, @ref opus_multistream_ctls, or + * @ref opus_projection_ctls + * @see opus_genericctls + * @see opus_encoderctls + * @see opus_multistream_ctls + * @see opus_projection_ctls + */ +OPUS_EXPORT int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); + + +/**@}*/ + +/**\name Projection decoder functions */ +/**@{*/ + +/** Gets the size of an OpusProjectionDecoder structure. + * @param channels int: The total number of output channels. + * This must be no more than 255. + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_decoder_get_size( + int channels, + int streams, + int coupled_streams +); + + +/** Allocates and initializes a projection decoder state. + * Call opus_projection_decoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix + * that mapping from coded channels to output channels, + * as described in @ref opus_projection and + * @ref opus_projection_ctls. + * @param demixing_matrix_size opus_int32: The size in bytes of the + * demixing matrix, as + * described in @ref + * opus_projection_ctls. + * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionDecoder *opus_projection_decoder_create( + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + unsigned char *demixing_matrix, + opus_int32 demixing_matrix_size, + int *error +) OPUS_ARG_NONNULL(5); + + +/** Intialize a previously allocated projection decoder state object. + * The memory pointed to by \a st must be at least the size returned by + * opus_projection_decoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_projection_decoder_create + * @see opus_projection_deocder_get_size + * @param st OpusProjectionDecoder*: Projection encoder state to initialize. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix + * that mapping from coded channels to output channels, + * as described in @ref opus_projection and + * @ref opus_projection_ctls. + * @param demixing_matrix_size opus_int32: The size in bytes of the + * demixing matrix, as + * described in @ref + * opus_projection_ctls. + * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_projection_decoder_init( + OpusProjectionDecoder *st, + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + unsigned char *demixing_matrix, + opus_int32 demixing_matrix_size +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); + + +/** Decode a projection Opus packet. + * @param st OpusProjectionDecoder*: Projection decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode( + OpusProjectionDecoder *st, + const unsigned char *data, + opus_int32 len, + opus_int16 *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + + +/** Decode a projection Opus packet with floating point output. + * @param st OpusProjectionDecoder*: Projection decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode_float( + OpusProjectionDecoder *st, + const unsigned char *data, + opus_int32 len, + float *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + + +/** Perform a CTL function on a projection Opus decoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusProjectionDecoder*: Projection decoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_decoderctls, @ref opus_multistream_ctls, or + * @ref opus_projection_ctls. + * @see opus_genericctls + * @see opus_decoderctls + * @see opus_multistream_ctls + * @see opus_projection_ctls + */ +OPUS_EXPORT int opus_projection_decoder_ctl(OpusProjectionDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); + + +/** Frees an OpusProjectionDecoder allocated by + * opus_projection_decoder_create(). + * @param st OpusProjectionDecoder: Projection decoder state to be freed. + */ +OPUS_EXPORT void opus_projection_decoder_destroy(OpusProjectionDecoder *st); + + +/**@}*/ + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_PROJECTION_H */ diff --git a/src/libopus/include/opus_types.h b/src/libopus/include/opus_types.h new file mode 100644 index 0000000..7cf6755 --- /dev/null +++ b/src/libopus/include/opus_types.h @@ -0,0 +1,166 @@ +/* (C) COPYRIGHT 1994-2002 Xiph.Org Foundation */ +/* Modified by Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/* opus_types.h based on ogg_types.h from libogg */ + +/** + @file opus_types.h + @brief Opus reference implementation types +*/ +#ifndef OPUS_TYPES_H +#define OPUS_TYPES_H + +#define opus_int int /* used for counters etc; at least 16 bits */ +#define opus_int64 long long +#define opus_int8 signed char + +#define opus_uint unsigned int /* used for counters etc; at least 16 bits */ +#define opus_uint64 unsigned long long +#define opus_uint8 unsigned char + +/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */ +#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H)) +#include +# undef opus_int64 +# undef opus_int8 +# undef opus_uint64 +# undef opus_uint8 + typedef int8_t opus_int8; + typedef uint8_t opus_uint8; + typedef int16_t opus_int16; + typedef uint16_t opus_uint16; + typedef int32_t opus_int32; + typedef uint32_t opus_uint32; + typedef int64_t opus_int64; + typedef uint64_t opus_uint64; +#elif defined(_WIN32) + +# if defined(__CYGWIN__) +# include <_G_config.h> + typedef _G_int32_t opus_int32; + typedef _G_uint32_t opus_uint32; + typedef _G_int16 opus_int16; + typedef _G_uint16 opus_uint16; +# elif defined(__MINGW32__) + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; +# elif defined(__MWERKS__) + typedef int opus_int32; + typedef unsigned int opus_uint32; + typedef short opus_int16; + typedef unsigned short opus_uint16; +# else + /* MSVC/Borland */ + typedef __int32 opus_int32; + typedef unsigned __int32 opus_uint32; + typedef __int16 opus_int16; + typedef unsigned __int16 opus_uint16; +# endif + +#elif defined(__MACOS__) + +# include + typedef SInt16 opus_int16; + typedef UInt16 opus_uint16; + typedef SInt32 opus_int32; + typedef UInt32 opus_uint32; + +#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ + +# include + typedef int16_t opus_int16; + typedef u_int16_t opus_uint16; + typedef int32_t opus_int32; + typedef u_int32_t opus_uint32; + +#elif defined(__BEOS__) + + /* Be */ +# include + typedef int16 opus_int16; + typedef u_int16 opus_uint16; + typedef int32_t opus_int32; + typedef u_int32_t opus_uint32; + +#elif defined (__EMX__) + + /* OS/2 GCC */ + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#elif defined (DJGPP) + + /* DJGPP */ + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#elif defined(R5900) + + /* PS2 EE */ + typedef int opus_int32; + typedef unsigned opus_uint32; + typedef short opus_int16; + typedef unsigned short opus_uint16; + +#elif defined(__SYMBIAN32__) + + /* Symbian GCC */ + typedef signed short opus_int16; + typedef unsigned short opus_uint16; + typedef signed int opus_int32; + typedef unsigned int opus_uint32; + +#elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) + + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef long opus_int32; + typedef unsigned long opus_uint32; + +#elif defined(CONFIG_TI_C6X) + + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#else + + /* Give up, take a reasonable guess */ + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#endif + +#endif /* OPUS_TYPES_H */ diff --git a/src/libopus/mapping_matrix.c b/src/libopus/mapping_matrix.c deleted file mode 100644 index 352fc7f..0000000 --- a/src/libopus/mapping_matrix.c +++ /dev/null @@ -1,364 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "celt/arch.h" -#include "celt/float_cast.h" -#include "opus_private.h" -#include "opus_defines.h" -#include "mapping_matrix.h" - -#define MATRIX_INDEX(nb_rows, row, col) (nb_rows * col + row) - -opus_int32 mapping_matrix_get_size(int rows, int cols) { - opus_int32 size; - - /* Mapping Matrix must only support up to 255 channels in or out. - Additionally, the total cell count must be <= 65004 octets in order - for the matrix to be stored in an OGG header. - */ - if (rows > 255 || cols > 255) { - return 0; - } - size = rows * (opus_int32)cols * sizeof(opus_int16); - if (size > 65004) { - return 0; - } - - return align(sizeof(MappingMatrix)) + align(size); -} - -opus_int16 *mapping_matrix_get_data(const MappingMatrix *matrix) { - /* void* cast avoids clang -Wcast-align warning */ - return (opus_int16*)(void*)((char*)matrix + align(sizeof(MappingMatrix))); -} - -void mapping_matrix_init(MappingMatrix * const matrix, - int rows, int cols, int gain, const opus_int16 *data, opus_int32 data_size) { - int i; - opus_int16 *ptr; - -#if !defined(ENABLE_ASSERTIONS) - (void)data_size; -#endif - celt_assert(align(data_size) == align(rows * cols * sizeof(opus_int16))); - - matrix->rows = rows; - matrix->cols = cols; - matrix->gain = gain; - ptr = mapping_matrix_get_data(matrix); - for (i = 0; i < rows * cols; i++) { - ptr[i] = data[i]; - } -} - -#ifndef DISABLE_FLOAT_API -void mapping_matrix_multiply_channel_in_float( - const MappingMatrix *matrix, - const float *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size) { - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, col; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) { - float tmp = 0; - for (col = 0; col < input_rows; col++) { - tmp += - matrix_data[MATRIX_INDEX(matrix->rows, output_row, col)] * - input[MATRIX_INDEX(input_rows, col, i)]; - } -#if defined(FIXED_POINT) - output[output_rows * i] = FLOAT2INT16((1 / 32768.f) * tmp); -#else - output[output_rows * i] = (1 / 32768.f) * tmp; -#endif - } -} - -void mapping_matrix_multiply_channel_out_float( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - float *output, - int output_rows, - int frame_size -) { - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, row; - float input_sample; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) { -#if defined(FIXED_POINT) - input_sample = (1 / 32768.f) * input[input_rows * i]; -#else - input_sample = input[input_rows * i]; -#endif - for (row = 0; row < output_rows; row++) { - float tmp = - (1 / 32768.f) * matrix_data[MATRIX_INDEX(matrix->rows, row, input_row)] * - input_sample; - output[MATRIX_INDEX(output_rows, row, i)] += tmp; - } - } -} -#endif /* DISABLE_FLOAT_API */ - -void mapping_matrix_multiply_channel_in_short( - const MappingMatrix *matrix, - const opus_int16 *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size) { - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, col; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) { - opus_val32 tmp = 0; - for (col = 0; col < input_rows; col++) { -#if defined(FIXED_POINT) - tmp += - ((opus_int32)matrix_data[MATRIX_INDEX(matrix->rows, output_row, col)] * - (opus_int32)input[MATRIX_INDEX(input_rows, col, i)]) >> 8; -#else - tmp += - matrix_data[MATRIX_INDEX(matrix->rows, output_row, col)] * - input[MATRIX_INDEX(input_rows, col, i)]; -#endif - } -#if defined(FIXED_POINT) - output[output_rows * i] = (opus_int16)((tmp + 64) >> 7); -#else - output[output_rows * i] = (1 / (32768.f * 32768.f)) * tmp; -#endif - } -} - -void mapping_matrix_multiply_channel_out_short( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - opus_int16 *output, - int output_rows, - int frame_size) { - /* Matrix data is ordered col-wise. */ - opus_int16* matrix_data; - int i, row; - opus_int32 input_sample; - - celt_assert(input_rows <= matrix->cols && output_rows <= matrix->rows); - - matrix_data = mapping_matrix_get_data(matrix); - - for (i = 0; i < frame_size; i++) { -#if defined(FIXED_POINT) - input_sample = (opus_int32)input[input_rows * i]; -#else - input_sample = (opus_int32)FLOAT2INT16(input[input_rows * i]); -#endif - for (row = 0; row < output_rows; row++) { - opus_int32 tmp = - (opus_int32)matrix_data[MATRIX_INDEX(matrix->rows, row, input_row)] * - input_sample; - output[MATRIX_INDEX(output_rows, row, i)] += (tmp + 16384) >> 15; - } - } -} - -const MappingMatrix mapping_matrix_foa_mixing = { 6, 6, 0 }; -const opus_int16 mapping_matrix_foa_mixing_data[36] = { - 16384, 0, -16384, 23170, 0, 0, 16384, 23170, - 16384, 0, 0, 0, 16384, 0, -16384, -23170, - 0, 0, 16384, -23170, 16384, 0, 0, 0, - 0, 0, 0, 0, 32767, 0, 0, 0, - 0, 0, 0, 32767 -}; - -const MappingMatrix mapping_matrix_soa_mixing = { 11, 11, 0 }; -const opus_int16 mapping_matrix_soa_mixing_data[121] = { - 10923, 7723, 13377, -13377, 11585, 9459, 7723, -16384, - -6689, 0, 0, 10923, 7723, 13377, 13377, -11585, - 9459, 7723, 16384, -6689, 0, 0, 10923, -15447, - 13377, 0, 0, -18919, 7723, 0, 13377, 0, - 0, 10923, 7723, -13377, -13377, 11585, -9459, 7723, - 16384, -6689, 0, 0, 10923, -7723, 0, 13377, - -16384, 0, -15447, 0, 9459, 0, 0, 10923, - -7723, 0, -13377, 16384, 0, -15447, 0, 9459, - 0, 0, 10923, 15447, 0, 0, 0, 0, - -15447, 0, -18919, 0, 0, 10923, 7723, -13377, - 13377, -11585, -9459, 7723, -16384, -6689, 0, 0, - 10923, -15447, -13377, 0, 0, 18919, 7723, 0, - 13377, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 32767, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32767 -}; - -const MappingMatrix mapping_matrix_toa_mixing = { 18, 18, 0 }; -const opus_int16 mapping_matrix_toa_mixing_data[324] = { - 8208, 0, -881, 14369, 0, 0, -8192, -4163, - 13218, 0, 0, 0, 11095, -8836, -6218, 14833, - 0, 0, 8208, -10161, 881, 10161, -13218, -2944, - -8192, 2944, 0, -10488, -6218, 6248, -11095, -6248, - 0, -10488, 0, 0, 8208, 10161, 881, -10161, - -13218, 2944, -8192, -2944, 0, 10488, -6218, -6248, - -11095, 6248, 0, 10488, 0, 0, 8176, 5566, - -11552, 5566, 9681, -11205, 8192, -11205, 0, 4920, - -15158, 9756, -3334, 9756, 0, -4920, 0, 0, - 8176, 7871, 11552, 0, 0, 15846, 8192, 0, - -9681, -6958, 0, 13797, 3334, 0, -15158, 0, - 0, 0, 8176, 0, 11552, 7871, 0, 0, - 8192, 15846, 9681, 0, 0, 0, 3334, 13797, - 15158, 6958, 0, 0, 8176, 5566, -11552, -5566, - -9681, -11205, 8192, 11205, 0, 4920, 15158, 9756, - -3334, -9756, 0, 4920, 0, 0, 8208, 14369, - -881, 0, 0, -4163, -8192, 0, -13218, -14833, - 0, -8836, 11095, 0, 6218, 0, 0, 0, - 8208, 10161, 881, 10161, 13218, 2944, -8192, 2944, - 0, 10488, 6218, -6248, -11095, -6248, 0, -10488, - 0, 0, 8208, -14369, -881, 0, 0, 4163, - -8192, 0, -13218, 14833, 0, 8836, 11095, 0, - 6218, 0, 0, 0, 8208, 0, -881, -14369, - 0, 0, -8192, 4163, 13218, 0, 0, 0, - 11095, 8836, -6218, -14833, 0, 0, 8176, -5566, - -11552, 5566, -9681, 11205, 8192, -11205, 0, -4920, - 15158, -9756, -3334, 9756, 0, -4920, 0, 0, - 8176, 0, 11552, -7871, 0, 0, 8192, -15846, - 9681, 0, 0, 0, 3334, -13797, 15158, -6958, - 0, 0, 8176, -7871, 11552, 0, 0, -15846, - 8192, 0, -9681, 6958, 0, -13797, 3334, 0, - -15158, 0, 0, 0, 8176, -5566, -11552, -5566, - 9681, 11205, 8192, 11205, 0, -4920, -15158, -9756, - -3334, -9756, 0, 4920, 0, 0, 8208, -10161, - 881, -10161, 13218, -2944, -8192, -2944, 0, -10488, - 6218, 6248, -11095, 6248, 0, 10488, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32767, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 32767 -}; - -const MappingMatrix mapping_matrix_foa_demixing = { 6, 6, 0 }; -const opus_int16 mapping_matrix_foa_demixing_data[36] = { - 16384, 16384, 16384, 16384, 0, 0, 0, 23170, - 0, -23170, 0, 0, -16384, 16384, -16384, 16384, - 0, 0, 23170, 0, -23170, 0, 0, 0, - 0, 0, 0, 0, 32767, 0, 0, 0, - 0, 0, 0, 32767 -}; - -const MappingMatrix mapping_matrix_soa_demixing = { 11, 11, 3050 }; -const opus_int16 mapping_matrix_soa_demixing_data[121] = { - 2771, 2771, 2771, 2771, 2771, 2771, 2771, 2771, - 2771, 0, 0, 10033, 10033, -20066, 10033, 14189, - 14189, -28378, 10033, -20066, 0, 0, 3393, 3393, - 3393, -3393, 0, 0, 0, -3393, -3393, 0, - 0, -17378, 17378, 0, -17378, -24576, 24576, 0, - 17378, 0, 0, 0, -14189, 14189, 0, -14189, - -28378, 28378, 0, 14189, 0, 0, 0, 2399, - 2399, -4799, -2399, 0, 0, 0, -2399, 4799, - 0, 0, 1959, 1959, 1959, 1959, -3918, -3918, - -3918, 1959, 1959, 0, 0, -4156, 4156, 0, - 4156, 0, 0, 0, -4156, 0, 0, 0, - 8192, 8192, -16384, 8192, 16384, 16384, -32768, 8192, - -16384, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 8312, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 8312 -}; - -const MappingMatrix mapping_matrix_toa_demixing = { 18, 18, 0 }; -const opus_int16 mapping_matrix_toa_demixing_data[324] = { - 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, - 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, - 0, 0, 0, -9779, 9779, 6263, 8857, 0, - 6263, 13829, 9779, -13829, 0, -6263, 0, -8857, - -6263, -9779, 0, 0, -3413, 3413, 3413, -11359, - 11359, 11359, -11359, -3413, 3413, -3413, -3413, -11359, - 11359, 11359, -11359, 3413, 0, 0, 13829, 9779, - -9779, 6263, 0, 8857, -6263, 0, 9779, 0, - -13829, 6263, -8857, 0, -6263, -9779, 0, 0, - 0, -15617, -15617, 6406, 0, 0, -6406, 0, - 15617, 0, 0, -6406, 0, 0, 6406, 15617, - 0, 0, 0, -5003, 5003, -10664, 15081, 0, - -10664, -7075, 5003, 7075, 0, 10664, 0, -15081, - 10664, -5003, 0, 0, -8176, -8176, -8176, 8208, - 8208, 8208, 8208, -8176, -8176, -8176, -8176, 8208, - 8208, 8208, 8208, -8176, 0, 0, -7075, 5003, - -5003, -10664, 0, 15081, 10664, 0, 5003, 0, - 7075, -10664, -15081, 0, 10664, -5003, 0, 0, - 15617, 0, 0, 0, -6406, 6406, 0, -15617, - 0, -15617, 15617, 0, 6406, -6406, 0, 0, - 0, 0, 0, -11393, 11393, 2993, -4233, 0, - 2993, -16112, 11393, 16112, 0, -2993, 0, 4233, - -2993, -11393, 0, 0, 0, -9974, -9974, -13617, - 0, 0, 13617, 0, 9974, 0, 0, 13617, - 0, 0, -13617, 9974, 0, 0, 0, 5579, - -5579, 10185, 14403, 0, 10185, -7890, -5579, 7890, - 0, -10185, 0, -14403, -10185, 5579, 0, 0, - 11826, -11826, -11826, -901, 901, 901, -901, 11826, - -11826, 11826, 11826, -901, 901, 901, -901, -11826, - 0, 0, -7890, -5579, 5579, 10185, 0, 14403, - -10185, 0, -5579, 0, 7890, 10185, -14403, 0, - -10185, 5579, 0, 0, -9974, 0, 0, 0, - -13617, 13617, 0, 9974, 0, 9974, -9974, 0, - 13617, -13617, 0, 0, 0, 0, 16112, -11393, - 11393, -2993, 0, 4233, 2993, 0, -11393, 0, - -16112, -2993, -4233, 0, 2993, 11393, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32767, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 32767 -}; - diff --git a/src/libopus/mapping_matrix.h b/src/libopus/mapping_matrix.h deleted file mode 100644 index 498e137..0000000 --- a/src/libopus/mapping_matrix.h +++ /dev/null @@ -1,132 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - @file mapping_matrix.h - @brief Opus reference implementation mapping matrix API -*/ - -#ifndef MAPPING_MATRIX_H -#define MAPPING_MATRIX_H - -#include "opus_types.h" -#include "opus_projection.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct MappingMatrix { - int rows; /* number of channels outputted from matrix. */ - int cols; /* number of channels inputted to matrix. */ - int gain; /* in dB. S7.8-format. */ - /* Matrix cell data goes here using col-wise ordering. */ -} MappingMatrix; - -opus_int32 mapping_matrix_get_size(int rows, int cols); - -opus_int16 *mapping_matrix_get_data(const MappingMatrix *matrix); - -void mapping_matrix_init( - MappingMatrix * const matrix, - int rows, - int cols, - int gain, - const opus_int16 *data, - opus_int32 data_size -); - -#ifndef DISABLE_FLOAT_API -void mapping_matrix_multiply_channel_in_float( - const MappingMatrix *matrix, - const float *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size -); - -void mapping_matrix_multiply_channel_out_float( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - float *output, - int output_rows, - int frame_size -); -#endif /* DISABLE_FLOAT_API */ - -void mapping_matrix_multiply_channel_in_short( - const MappingMatrix *matrix, - const opus_int16 *input, - int input_rows, - opus_val16 *output, - int output_row, - int output_rows, - int frame_size -); - -void mapping_matrix_multiply_channel_out_short( - const MappingMatrix *matrix, - const opus_val16 *input, - int input_row, - int input_rows, - opus_int16 *output, - int output_rows, - int frame_size -); - -/* Pre-computed mixing and demixing matrices for 1st to 3rd-order ambisonics. - foa: first-order ambisonics - soa: second-order ambisonics - toa: third-order ambisonics -*/ -extern const MappingMatrix mapping_matrix_foa_mixing; -extern const opus_int16 mapping_matrix_foa_mixing_data[36]; - -extern const MappingMatrix mapping_matrix_soa_mixing; -extern const opus_int16 mapping_matrix_soa_mixing_data[121]; - -extern const MappingMatrix mapping_matrix_toa_mixing; -extern const opus_int16 mapping_matrix_toa_mixing_data[324]; - -extern const MappingMatrix mapping_matrix_foa_demixing; -extern const opus_int16 mapping_matrix_foa_demixing_data[36]; - -extern const MappingMatrix mapping_matrix_soa_demixing; -extern const opus_int16 mapping_matrix_soa_demixing_data[121]; - -extern const MappingMatrix mapping_matrix_toa_demixing; -extern const opus_int16 mapping_matrix_toa_demixing_data[324]; - -#ifdef __cplusplus -} -#endif - -#endif /* MAPPING_MATRIX_H */ diff --git a/src/libopus/mlp.h b/src/libopus/mlp.h deleted file mode 100644 index bfcfffd..0000000 --- a/src/libopus/mlp.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (c) 2017 Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef _MLP_H_ -#define _MLP_H_ - -#include "opus_types.h" - -#define WEIGHTS_SCALE (1.f/128) - -#define MAX_NEURONS 32 - -typedef struct { - const opus_int8 *bias; - const opus_int8 *input_weights; - int nb_inputs; - int nb_neurons; - int sigmoid; -} DenseLayer; - -typedef struct { - const opus_int8 *bias; - const opus_int8 *input_weights; - const opus_int8 *recurrent_weights; - int nb_inputs; - int nb_neurons; -} GRULayer; - -extern const DenseLayer layer0; -extern const GRULayer layer1; -extern const DenseLayer layer2; - -void compute_dense(const DenseLayer *layer, float *output, const float *input); - -void compute_gru(const GRULayer *gru, float *state, const float *input); - -#endif /* _MLP_H_ */ diff --git a/src/libopus/opus.c b/src/libopus/opus.c deleted file mode 100644 index a80a28a..0000000 --- a/src/libopus/opus.c +++ /dev/null @@ -1,356 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation, Skype Limited - Written by Jean-Marc Valin and Koen Vos */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "opus.h" -#include "opus_private.h" - -#ifndef DISABLE_FLOAT_API -OPUS_EXPORT void opus_pcm_soft_clip(float *_x, int N, int C, float *declip_mem) { - int c; - int i; - float *x; - - if (C < 1 || N < 1 || !_x || !declip_mem) { - return; - } - - /* First thing: saturate everything to +/- 2 which is the highest level our - non-linearity can handle. At the point where the signal reaches +/-2, - the derivative will be zero anyway, so this doesn't introduce any - discontinuity in the derivative. */ - for (i = 0; i < N * C; i++) { - _x[i] = MAX16(-2.f, MIN16(2.f, _x[i])); - } - for (c = 0; c < C; c++) { - float a; - float x0; - int curr; - - x = _x + c; - a = declip_mem[c]; - /* Continue applying the non-linearity from the previous frame to avoid - any discontinuity. */ - for (i = 0; i < N; i++) { - if (x[i * C]*a >= 0) { - break; - } - x[i * C] = x[i * C] + a * x[i * C] * x[i * C]; - } - - curr = 0; - x0 = x[0]; - while (1) { - int start, end; - float maxval; - int special = 0; - int peak_pos; - for (i = curr; i < N; i++) { - if (x[i * C] > 1 || x[i * C] < -1) { - break; - } - } - if (i == N) { - a = 0; - break; - } - peak_pos = i; - start = end = i; - maxval = ABS16(x[i * C]); - /* Look for first zero crossing before clipping */ - while (start > 0 && x[i * C]*x[(start - 1)*C] >= 0) { - start--; - } - /* Look for first zero crossing after clipping */ - while (end < N && x[i * C]*x[end * C] >= 0) { - /* Look for other peaks until the next zero-crossing. */ - if (ABS16(x[end * C]) > maxval) { - maxval = ABS16(x[end * C]); - peak_pos = end; - } - end++; - } - /* Detect the special case where we clip before the first zero crossing */ - special = (start == 0 && x[i * C] * x[0] >= 0); - - /* Compute a such that maxval + a*maxval^2 = 1 */ - a = (maxval - 1) / (maxval * maxval); - /* Slightly boost "a" by 2^-22. This is just enough to ensure -ffast-math - does not cause output values larger than +/-1, but small enough not - to matter even for 24-bit output. */ - a += a * 2.4e-7f; - if (x[i * C] > 0) { - a = -a; - } - /* Apply soft clipping */ - for (i = start; i < end; i++) { - x[i * C] = x[i * C] + a * x[i * C] * x[i * C]; - } - - if (special && peak_pos >= 2) { - /* Add a linear ramp from the first sample to the signal peak. - This avoids a discontinuity at the beginning of the frame. */ - float delta; - float offset = x0 - x[0]; - delta = offset / peak_pos; - for (i = curr; i < peak_pos; i++) { - offset -= delta; - x[i * C] += offset; - x[i * C] = MAX16(-1.f, MIN16(1.f, x[i * C])); - } - } - curr = end; - if (curr == N) { - break; - } - } - declip_mem[c] = a; - } -} -#endif - -int encode_size(int size, unsigned char *data) { - if (size < 252) { - data[0] = size; - return 1; - } else { - data[0] = 252 + (size & 0x3); - data[1] = (size - (int)data[0]) >> 2; - return 2; - } -} - -static int parse_size(const unsigned char *data, opus_int32 len, opus_int16 *size) { - if (len < 1) { - *size = -1; - return -1; - } else if (data[0] < 252) { - *size = data[0]; - return 1; - } else if (len < 2) { - *size = -1; - return -1; - } else { - *size = 4 * data[1] + data[0]; - return 2; - } -} - -int opus_packet_get_samples_per_frame(const unsigned char *data, - opus_int32 Fs) { - int audiosize; - if (data[0] & 0x80) { - audiosize = ((data[0] >> 3) & 0x3); - audiosize = (Fs << audiosize) / 400; - } else if ((data[0] & 0x60) == 0x60) { - audiosize = (data[0] & 0x08) ? Fs / 50 : Fs / 100; - } else { - audiosize = ((data[0] >> 3) & 0x3); - if (audiosize == 3) { - audiosize = Fs * 60 / 1000; - } else { - audiosize = (Fs << audiosize) / 100; - } - } - return audiosize; -} - -int opus_packet_parse_impl(const unsigned char *data, opus_int32 len, - int self_delimited, unsigned char *out_toc, - const unsigned char *frames[48], opus_int16 size[48], - int *payload_offset, opus_int32 *packet_offset) { - int i, bytes; - int count; - int cbr; - unsigned char ch, toc; - int framesize; - opus_int32 last_size; - opus_int32 pad = 0; - const unsigned char *data0 = data; - - if (size == NULL || len < 0) { - return OPUS_BAD_ARG; - } - if (len == 0) { - return OPUS_INVALID_PACKET; - } - - framesize = opus_packet_get_samples_per_frame(data, 48000); - - cbr = 0; - toc = *data++; - len--; - last_size = len; - switch (toc & 0x3) { - /* One frame */ - case 0: - count = 1; - break; - /* Two CBR frames */ - case 1: - count = 2; - cbr = 1; - if (!self_delimited) { - if (len & 0x1) { - return OPUS_INVALID_PACKET; - } - last_size = len / 2; - /* If last_size doesn't fit in size[0], we'll catch it later */ - size[0] = (opus_int16)last_size; - } - break; - /* Two VBR frames */ - case 2: - count = 2; - bytes = parse_size(data, len, size); - len -= bytes; - if (size[0] < 0 || size[0] > len) { - return OPUS_INVALID_PACKET; - } - data += bytes; - last_size = len - size[0]; - break; - /* Multiple CBR/VBR frames (from 0 to 120 ms) */ - default: /*case 3:*/ - if (len < 1) { - return OPUS_INVALID_PACKET; - } - /* Number of frames encoded in bits 0 to 5 */ - ch = *data++; - count = ch & 0x3F; - if (count <= 0 || framesize * (opus_int32)count > 5760) { - return OPUS_INVALID_PACKET; - } - len--; - /* Padding flag is bit 6 */ - if (ch & 0x40) { - int p; - do { - int tmp; - if (len <= 0) { - return OPUS_INVALID_PACKET; - } - p = *data++; - len--; - tmp = p == 255 ? 254 : p; - len -= tmp; - pad += tmp; - } while (p == 255); - } - if (len < 0) { - return OPUS_INVALID_PACKET; - } - /* VBR flag is bit 7 */ - cbr = !(ch & 0x80); - if (!cbr) { - /* VBR case */ - last_size = len; - for (i = 0; i < count - 1; i++) { - bytes = parse_size(data, len, size + i); - len -= bytes; - if (size[i] < 0 || size[i] > len) { - return OPUS_INVALID_PACKET; - } - data += bytes; - last_size -= bytes + size[i]; - } - if (last_size < 0) { - return OPUS_INVALID_PACKET; - } - } else if (!self_delimited) { - /* CBR case */ - last_size = len / count; - if (last_size * count != len) { - return OPUS_INVALID_PACKET; - } - for (i = 0; i < count - 1; i++) { - size[i] = (opus_int16)last_size; - } - } - break; - } - /* Self-delimited framing has an extra size for the last frame. */ - if (self_delimited) { - bytes = parse_size(data, len, size + count - 1); - len -= bytes; - if (size[count - 1] < 0 || size[count - 1] > len) { - return OPUS_INVALID_PACKET; - } - data += bytes; - /* For CBR packets, apply the size to all the frames. */ - if (cbr) { - if (size[count - 1]*count > len) { - return OPUS_INVALID_PACKET; - } - for (i = 0; i < count - 1; i++) { - size[i] = size[count - 1]; - } - } else if (bytes + size[count - 1] > last_size) { - return OPUS_INVALID_PACKET; - } - } else { - /* Because it's not encoded explicitly, it's possible the size of the - last packet (or all the packets, for the CBR case) is larger than - 1275. Reject them here.*/ - if (last_size > 1275) { - return OPUS_INVALID_PACKET; - } - size[count - 1] = (opus_int16)last_size; - } - - if (payload_offset) { - *payload_offset = (int)(data - data0); - } - - for (i = 0; i < count; i++) { - if (frames) { - frames[i] = data; - } - data += size[i]; - } - - if (packet_offset) { - *packet_offset = pad + (opus_int32)(data - data0); - } - - if (out_toc) { - *out_toc = toc; - } - - return count; -} - -int opus_packet_parse(const unsigned char *data, opus_int32 len, - unsigned char *out_toc, const unsigned char *frames[48], - opus_int16 size[48], int *payload_offset) { - return opus_packet_parse_impl(data, len, 0, out_toc, - frames, size, payload_offset, NULL); -} - diff --git a/src/libopus/opus.h b/src/libopus/opus.h deleted file mode 100644 index 9ffd125..0000000 --- a/src/libopus/opus.h +++ /dev/null @@ -1,981 +0,0 @@ -/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited - Written by Jean-Marc Valin and Koen Vos */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - @file opus.h - @brief Opus reference implementation API -*/ - -#ifndef OPUS_H -#define OPUS_H - -#include "opus_types.h" -#include "opus_defines.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - @mainpage Opus - - The Opus codec is designed for interactive speech and audio transmission over the Internet. - It is designed by the IETF Codec Working Group and incorporates technology from - Skype's SILK codec and Xiph.Org's CELT codec. - - The Opus codec is designed to handle a wide range of interactive audio applications, - including Voice over IP, videoconferencing, in-game chat, and even remote live music - performances. It can scale from low bit-rate narrowband speech to very high quality - stereo music. Its main features are: - - @li Sampling rates from 8 to 48 kHz - @li Bit-rates from 6 kb/s to 510 kb/s - @li Support for both constant bit-rate (CBR) and variable bit-rate (VBR) - @li Audio bandwidth from narrowband to full-band - @li Support for speech and music - @li Support for mono and stereo - @li Support for multichannel (up to 255 channels) - @li Frame sizes from 2.5 ms to 60 ms - @li Good loss robustness and packet loss concealment (PLC) - @li Floating point and fixed-point implementation - - Documentation sections: - @li @ref opus_encoder - @li @ref opus_decoder - @li @ref opus_repacketizer - @li @ref opus_multistream - @li @ref opus_libinfo - @li @ref opus_custom -*/ - -/** @defgroup opus_encoder Opus Encoder - @{ - - @brief This page describes the process and functions used to encode Opus. - - Since Opus is a stateful codec, the encoding process starts with creating an encoder - state. This can be done with: - - @code - int error; - OpusEncoder *enc; - enc = opus_encoder_create(Fs, channels, application, &error); - @endcode - - From this point, @c enc can be used for encoding an audio stream. An encoder state - @b must @b not be used for more than one stream at the same time. Similarly, the encoder - state @b must @b not be re-initialized for each frame. - - While opus_encoder_create() allocates memory for the state, it's also possible - to initialize pre-allocated memory: - - @code - int size; - int error; - OpusEncoder *enc; - size = opus_encoder_get_size(channels); - enc = malloc(size); - error = opus_encoder_init(enc, Fs, channels, application); - @endcode - - where opus_encoder_get_size() returns the required size for the encoder state. Note that - future versions of this code may change the size, so no assuptions should be made about it. - - The encoder state is always continuous in memory and only a shallow copy is sufficient - to copy it (e.g. memcpy()) - - It is possible to change some of the encoder's settings using the opus_encoder_ctl() - interface. All these settings already default to the recommended value, so they should - only be changed when necessary. The most common settings one may want to change are: - - @code - opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)); - opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); - opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type)); - @endcode - - where - - @arg bitrate is in bits per second (b/s) - @arg complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest - @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC - - See @ref opus_encoderctls and @ref opus_genericctls for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream. - - To encode a frame, opus_encode() or opus_encode_float() must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data: - @code - len = opus_encode(enc, audio_frame, frame_size, packet, max_packet); - @endcode - - where -
    -
  • audio_frame is the audio data in opus_int16 (or float for opus_encode_float())
  • -
  • frame_size is the duration of the frame in samples (per channel)
  • -
  • packet is the byte array to which the compressed data is written
  • -
  • max_packet is the maximum number of bytes that can be written in the packet (4000 bytes is recommended). - Do not use max_packet to control VBR target bitrate, instead use the #OPUS_SET_BITRATE CTL.
  • -
- - opus_encode() and opus_encode_float() return the number of bytes actually written to the packet. - The return value can be negative, which indicates that an error has occurred. If the return value - is 2 bytes or less, then the packet does not need to be transmitted (DTX). - - Once the encoder state if no longer needed, it can be destroyed with - - @code - opus_encoder_destroy(enc); - @endcode - - If the encoder was created with opus_encoder_init() rather than opus_encoder_create(), - then no action is required aside from potentially freeing the memory that was manually - allocated for it (calling free(enc) for the example above) - -*/ - -/** Opus encoder state. - This contains the complete state of an Opus encoder. - It is position independent and can be freely copied. - @see opus_encoder_create,opus_encoder_init -*/ -typedef struct OpusEncoder OpusEncoder; - -/** Gets the size of an OpusEncoder structure. - @param[in] channels int: Number of channels. - This must be 1 or 2. - @returns The size in bytes. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels); - -/** -*/ - -/** Allocates and initializes an encoder state. - There are three coding modes: - - @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice - signals. It enhances the input signal by high-pass filtering and - emphasizing formants and harmonics. Optionally it includes in-band - forward error correction to protect against packet loss. Use this - mode for typical VoIP applications. Because of the enhancement, - even at high bitrates the output may sound different from the input. - - @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most - non-voice signals like music. Use this mode for music and mixed - (music/voice) content, broadcast, and applications requiring less - than 15 ms of coding delay. - - @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that - disables the speech-optimized mode in exchange for slightly reduced delay. - This mode can only be set on an newly initialized or freshly reset encoder - because it changes the codec delay. - - This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution). - @param [in] Fs opus_int32: Sampling rate of input signal (Hz) - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param [in] channels int: Number of channels (1 or 2) in input signal - @param [in] application int: Coding mode (@ref OPUS_APPLICATION_VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY) - @param [out] error int*: @ref opus_errorcodes - @note Regardless of the sampling rate and number channels selected, the Opus encoder - can switch to a lower audio bandwidth or number of channels if the bitrate - selected is too low. This also means that it is safe to always use 48 kHz stereo input - and let the encoder optimize the encoding. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create( - opus_int32 Fs, - int channels, - int application, - int *error -); - -/** Initializes a previously allocated encoder state - The memory pointed to by st must be at least the size returned by opus_encoder_get_size(). - This is intended for applications which use their own allocator instead of malloc. - @see opus_encoder_create(),opus_encoder_get_size() - To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - @param [in] st OpusEncoder*: Encoder state - @param [in] Fs opus_int32: Sampling rate of input signal (Hz) - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param [in] channels int: Number of channels (1 or 2) in input signal - @param [in] application int: Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY) - @retval #OPUS_OK Success or @ref opus_errorcodes -*/ -OPUS_EXPORT int opus_encoder_init( - OpusEncoder *st, - opus_int32 Fs, - int channels, - int application -) OPUS_ARG_NONNULL(1); - -/** Encodes an Opus frame. - @param [in] st OpusEncoder*: Encoder state - @param [in] pcm opus_int16*: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16) - @param [in] frame_size int: Number of samples per channel in the - input signal. - This must be an Opus frame size for - the encoder's sampling rate. - For example, at 48 kHz the permitted - values are 120, 240, 480, 960, 1920, - and 2880. - Passing in a duration of less than - 10 ms (480 samples at 48 kHz) will - prevent the encoder from using the LPC - or hybrid modes. - @param [out] data unsigned char*: Output payload. - This must contain storage for at - least \a max_data_bytes. - @param [in] max_data_bytes opus_int32: Size of the allocated - memory for the output - payload. This may be - used to impose an upper limit on - the instant bitrate, but should - not be used as the only bitrate - control. Use #OPUS_SET_BITRATE to - control the bitrate. - @returns The length of the encoded packet (in bytes) on success or a - negative error code (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode( - OpusEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Encodes an Opus frame from floating point input. - @param [in] st OpusEncoder*: Encoder state - @param [in] pcm float*: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0. - Samples with a range beyond +/-1.0 are supported but will - be clipped by decoders using the integer API and should - only be used if it is known that the far end supports - extended dynamic range. - length is frame_size*channels*sizeof(float) - @param [in] frame_size int: Number of samples per channel in the - input signal. - This must be an Opus frame size for - the encoder's sampling rate. - For example, at 48 kHz the permitted - values are 120, 240, 480, 960, 1920, - and 2880. - Passing in a duration of less than - 10 ms (480 samples at 48 kHz) will - prevent the encoder from using the LPC - or hybrid modes. - @param [out] data unsigned char*: Output payload. - This must contain storage for at - least \a max_data_bytes. - @param [in] max_data_bytes opus_int32: Size of the allocated - memory for the output - payload. This may be - used to impose an upper limit on - the instant bitrate, but should - not be used as the only bitrate - control. Use #OPUS_SET_BITRATE to - control the bitrate. - @returns The length of the encoded packet (in bytes) on success or a - negative error code (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float( - OpusEncoder *st, - const float *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Frees an OpusEncoder allocated by opus_encoder_create(). - @param[in] st OpusEncoder*: State to be freed. -*/ -OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st); - -/** Perform a CTL function on an Opus encoder. - - Generally the request and subsequent arguments are generated - by a convenience macro. - @param st OpusEncoder*: Encoder state. - @param request This and all remaining parameters should be replaced by one - of the convenience macros in @ref opus_genericctls or - @ref opus_encoderctls. - @see opus_genericctls - @see opus_encoderctls -*/ -OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); -/**@}*/ - -/** @defgroup opus_decoder Opus Decoder - @{ - - @brief This page describes the process and functions used to decode Opus. - - The decoding process also starts with creating a decoder - state. This can be done with: - @code - int error; - OpusDecoder *dec; - dec = opus_decoder_create(Fs, channels, &error); - @endcode - where - @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000 - @li channels is the number of channels (1 or 2) - @li error will hold the error code in case of failure (or #OPUS_OK on success) - @li the return value is a newly created decoder state to be used for decoding - - While opus_decoder_create() allocates memory for the state, it's also possible - to initialize pre-allocated memory: - @code - int size; - int error; - OpusDecoder *dec; - size = opus_decoder_get_size(channels); - dec = malloc(size); - error = opus_decoder_init(dec, Fs, channels); - @endcode - where opus_decoder_get_size() returns the required size for the decoder state. Note that - future versions of this code may change the size, so no assuptions should be made about it. - - The decoder state is always continuous in memory and only a shallow copy is sufficient - to copy it (e.g. memcpy()) - - To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data: - @code - frame_size = opus_decode(dec, packet, len, decoded, max_size, 0); - @endcode - where - - @li packet is the byte array containing the compressed data - @li len is the exact number of bytes contained in the packet - @li decoded is the decoded audio data in opus_int16 (or float for opus_decode_float()) - @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array - - opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet. - If that value is negative, then an error has occurred. This can occur if the packet is corrupted or if the audio - buffer is too small to hold the decoded audio. - - Opus is a stateful codec with overlapping blocks and as a result Opus - packets are not coded independently of each other. Packets must be - passed into the decoder serially and in the correct order for a correct - decode. Lost packets can be replaced with loss concealment by calling - the decoder with a null pointer and zero length for the missing packet. - - A single codec state may only be accessed from a single thread at - a time and any required locking must be performed by the caller. Separate - streams must be decoded with separate decoder states and can be decoded - in parallel unless the library was compiled with NONTHREADSAFE_PSEUDOSTACK - defined. - -*/ - -/** Opus decoder state. - This contains the complete state of an Opus decoder. - It is position independent and can be freely copied. - @see opus_decoder_create,opus_decoder_init -*/ -typedef struct OpusDecoder OpusDecoder; - -/** Gets the size of an OpusDecoder structure. - @param [in] channels int: Number of channels. - This must be 1 or 2. - @returns The size in bytes. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels); - -/** Allocates and initializes a decoder state. - @param [in] Fs opus_int32: Sample rate to decode at (Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param [in] channels int: Number of channels (1 or 2) to decode - @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes - - Internally Opus stores data at 48000 Hz, so that should be the default - value for Fs. However, the decoder can efficiently decode to buffers - at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use - data at the full sample rate, or knows the compressed data doesn't - use the full frequency range, it can request decoding at a reduced - rate. Likewise, the decoder is capable of filling in either mono or - interleaved stereo pcm buffers, at the caller's request. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create( - opus_int32 Fs, - int channels, - int *error -); - -/** Initializes a previously allocated decoder state. - The state must be at least the size returned by opus_decoder_get_size(). - This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size - To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - @param [in] st OpusDecoder*: Decoder state. - @param [in] Fs opus_int32: Sampling rate to decode to (Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param [in] channels int: Number of channels (1 or 2) to decode - @retval #OPUS_OK Success or @ref opus_errorcodes -*/ -OPUS_EXPORT int opus_decoder_init( - OpusDecoder *st, - opus_int32 Fs, - int channels -) OPUS_ARG_NONNULL(1); - -/** Decode an Opus packet. - @param [in] st OpusDecoder*: Decoder state - @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - @param [in] len opus_int32: Number of bytes in payload - @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length - is frame_size*channels*sizeof(opus_int16) - @param [in] frame_size Number of samples per channel of available space in \a pcm. - If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will - not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), - then frame_size needs to be exactly the duration of audio that is missing, otherwise the - decoder will not be in the optimal state to decode the next incoming packet. For the PLC and - FEC cases, frame_size must be a multiple of 2.5 ms. - @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be - decoded. If no such data is available, the frame is decoded as if it were lost. - @returns Number of decoded samples or @ref opus_errorcodes -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode( - OpusDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_int16 *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Decode an Opus packet with floating point output. - @param [in] st OpusDecoder*: Decoder state - @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - @param [in] len opus_int32: Number of bytes in payload - @param [out] pcm float*: Output signal (interleaved if 2 channels). length - is frame_size*channels*sizeof(float) - @param [in] frame_size Number of samples per channel of available space in \a pcm. - If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will - not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), - then frame_size needs to be exactly the duration of audio that is missing, otherwise the - decoder will not be in the optimal state to decode the next incoming packet. For the PLC and - FEC cases, frame_size must be a multiple of 2.5 ms. - @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be - decoded. If no such data is available the frame is decoded as if it were lost. - @returns Number of decoded samples or @ref opus_errorcodes -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float( - OpusDecoder *st, - const unsigned char *data, - opus_int32 len, - float *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on an Opus decoder. - - Generally the request and subsequent arguments are generated - by a convenience macro. - @param st OpusDecoder*: Decoder state. - @param request This and all remaining parameters should be replaced by one - of the convenience macros in @ref opus_genericctls or - @ref opus_decoderctls. - @see opus_genericctls - @see opus_decoderctls -*/ -OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); - -/** Frees an OpusDecoder allocated by opus_decoder_create(). - @param[in] st OpusDecoder*: State to be freed. -*/ -OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st); - -/** Parse an opus packet into one or more frames. - Opus_decode will perform this operation internally so most applications do - not need to use this function. - This function does not copy the frames, the returned pointers are pointers into - the input packet. - @param [in] data char*: Opus packet to be parsed - @param [in] len opus_int32: size of data - @param [out] out_toc char*: TOC pointer - @param [out] frames char*[48] encapsulated frames - @param [out] size opus_int16[48] sizes of the encapsulated frames - @param [out] payload_offset int*: returns the position of the payload within the packet (in bytes) - @returns number of frames -*/ -OPUS_EXPORT int opus_packet_parse( - const unsigned char *data, - opus_int32 len, - unsigned char *out_toc, - const unsigned char *frames[48], - opus_int16 size[48], - int *payload_offset -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5); - -/** Gets the bandwidth of an Opus packet. - @param [in] data char*: Opus packet - @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) - @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) - @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) - @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) - @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) - @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1); - -/** Gets the number of samples per frame from an Opus packet. - @param [in] data char*: Opus packet. - This must contain at least one byte of - data. - @param [in] Fs opus_int32: Sampling rate in Hz. - This must be a multiple of 400, or - inaccurate results will be returned. - @returns Number of samples per frame. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1); - -/** Gets the number of channels from an Opus packet. - @param [in] data char*: Opus packet - @returns Number of channels - @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1); - -/** Gets the number of frames in an Opus packet. - @param [in] packet char*: Opus packet - @param [in] len opus_int32: Length of packet - @returns Number of frames - @retval OPUS_BAD_ARG Insufficient data was passed to the function - @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1); - -/** Gets the number of samples of an Opus packet. - @param [in] packet char*: Opus packet - @param [in] len opus_int32: Length of packet - @param [in] Fs opus_int32: Sampling rate in Hz. - This must be a multiple of 400, or - inaccurate results will be returned. - @returns Number of samples - @retval OPUS_BAD_ARG Insufficient data was passed to the function - @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1); - -/** Gets the number of samples of an Opus packet. - @param [in] dec OpusDecoder*: Decoder state - @param [in] packet char*: Opus packet - @param [in] len opus_int32: Length of packet - @returns Number of samples - @retval OPUS_BAD_ARG Insufficient data was passed to the function - @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); - -/** Applies soft-clipping to bring a float signal within the [-1,1] range. If - the signal is already in that range, nothing is done. If there are values - outside of [-1,1], then the signal is clipped as smoothly as possible to - both fit in the range and avoid creating excessive distortion in the - process. - @param [in,out] pcm float*: Input PCM and modified PCM - @param [in] frame_size int Number of samples per channel to process - @param [in] channels int: Number of channels - @param [in,out] softclip_mem float*: State memory for the soft clipping process (one float per channel, initialized to zero) -*/ -OPUS_EXPORT void opus_pcm_soft_clip(float *pcm, int frame_size, int channels, float *softclip_mem); - - -/**@}*/ - -/** @defgroup opus_repacketizer Repacketizer - @{ - - The repacketizer can be used to merge multiple Opus packets into a single - packet or alternatively to split Opus packets that have previously been - merged. Splitting valid Opus packets is always guaranteed to succeed, - whereas merging valid packets only succeeds if all frames have the same - mode, bandwidth, and frame size, and when the total duration of the merged - packet is no more than 120 ms. The 120 ms limit comes from the - specification and limits decoder memory requirements at a point where - framing overhead becomes negligible. - - The repacketizer currently only operates on elementary Opus - streams. It will not manipualte multistream packets successfully, except in - the degenerate case where they consist of data from a single stream. - - The repacketizing process starts with creating a repacketizer state, either - by calling opus_repacketizer_create() or by allocating the memory yourself, - e.g., - @code - OpusRepacketizer *rp; - rp = (OpusRepacketizer*)malloc(opus_repacketizer_get_size()); - if (rp != NULL) - opus_repacketizer_init(rp); - @endcode - - Then the application should submit packets with opus_repacketizer_cat(), - extract new packets with opus_repacketizer_out() or - opus_repacketizer_out_range(), and then reset the state for the next set of - input packets via opus_repacketizer_init(). - - For example, to split a sequence of packets into individual frames: - @code - unsigned char *data; - int len; - while (get_next_packet(&data, &len)) - { - unsigned char out[1276]; - opus_int32 out_len; - int nb_frames; - int err; - int i; - err = opus_repacketizer_cat(rp, data, len); - if (err != OPUS_OK) - { - release_packet(data); - return err; - } - nb_frames = opus_repacketizer_get_nb_frames(rp); - for (i = 0; i < nb_frames; i++) - { - out_len = opus_repacketizer_out_range(rp, i, i+1, out, sizeof(out)); - if (out_len < 0) - { - release_packet(data); - return (int)out_len; - } - output_next_packet(out, out_len); - } - opus_repacketizer_init(rp); - release_packet(data); - } - @endcode - - Alternatively, to combine a sequence of frames into packets that each - contain up to TARGET_DURATION_MS milliseconds of data: - @code - // The maximum number of packets with duration TARGET_DURATION_MS occurs - // when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/5) - // packets. - unsigned char *data[(TARGET_DURATION_MS*2/5)+1]; - opus_int32 len[(TARGET_DURATION_MS*2/5)+1]; - int nb_packets; - unsigned char out[1277*(TARGET_DURATION_MS*2/2)]; - opus_int32 out_len; - int prev_toc; - nb_packets = 0; - while (get_next_packet(data+nb_packets, len+nb_packets)) - { - int nb_frames; - int err; - nb_frames = opus_packet_get_nb_frames(data[nb_packets], len[nb_packets]); - if (nb_frames < 1) - { - release_packets(data, nb_packets+1); - return nb_frames; - } - nb_frames += opus_repacketizer_get_nb_frames(rp); - // If adding the next packet would exceed our target, or it has an - // incompatible TOC sequence, output the packets we already have before - // submitting it. - // N.B., The nb_packets > 0 check ensures we've submitted at least one - // packet since the last call to opus_repacketizer_init(). Otherwise a - // single packet longer than TARGET_DURATION_MS would cause us to try to - // output an (invalid) empty packet. It also ensures that prev_toc has - // been set to a valid value. Additionally, len[nb_packets] > 0 is - // guaranteed by the call to opus_packet_get_nb_frames() above, so the - // reference to data[nb_packets][0] should be valid. - if (nb_packets > 0 && ( - ((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) || - opus_packet_get_samples_per_frame(data[nb_packets], 48000)*nb_frames > - TARGET_DURATION_MS*48)) - { - out_len = opus_repacketizer_out(rp, out, sizeof(out)); - if (out_len < 0) - { - release_packets(data, nb_packets+1); - return (int)out_len; - } - output_next_packet(out, out_len); - opus_repacketizer_init(rp); - release_packets(data, nb_packets); - data[0] = data[nb_packets]; - len[0] = len[nb_packets]; - nb_packets = 0; - } - err = opus_repacketizer_cat(rp, data[nb_packets], len[nb_packets]); - if (err != OPUS_OK) - { - release_packets(data, nb_packets+1); - return err; - } - prev_toc = data[nb_packets][0]; - nb_packets++; - } - // Output the final, partial packet. - if (nb_packets > 0) - { - out_len = opus_repacketizer_out(rp, out, sizeof(out)); - release_packets(data, nb_packets); - if (out_len < 0) - return (int)out_len; - output_next_packet(out, out_len); - } - @endcode - - An alternate way of merging packets is to simply call opus_repacketizer_cat() - unconditionally until it fails. At that point, the merged packet can be - obtained with opus_repacketizer_out() and the input packet for which - opus_repacketizer_cat() needs to be re-added to a newly reinitialized - repacketizer state. -*/ - -typedef struct OpusRepacketizer OpusRepacketizer; - -/** Gets the size of an OpusRepacketizer structure. - @returns The size in bytes. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void); - -/** (Re)initializes a previously allocated repacketizer state. - The state must be at least the size returned by opus_repacketizer_get_size(). - This can be used for applications which use their own allocator instead of - malloc(). - It must also be called to reset the queue of packets waiting to be - repacketized, which is necessary if the maximum packet duration of 120 ms - is reached or if you wish to submit packets with a different Opus - configuration (coding mode, audio bandwidth, frame size, or channel count). - Failure to do so will prevent a new packet from being added with - opus_repacketizer_cat(). - @see opus_repacketizer_create - @see opus_repacketizer_get_size - @see opus_repacketizer_cat - @param rp OpusRepacketizer*: The repacketizer state to - (re)initialize. - @returns A pointer to the same repacketizer state that was passed in. -*/ -OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); - -/** Allocates memory and initializes the new repacketizer with - opus_repacketizer_init(). -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void); - -/** Frees an OpusRepacketizer allocated by - opus_repacketizer_create(). - @param[in] rp OpusRepacketizer*: State to be freed. -*/ -OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp); - -/** Add a packet to the current repacketizer state. - This packet must match the configuration of any packets already submitted - for repacketization since the last call to opus_repacketizer_init(). - This means that it must have the same coding mode, audio bandwidth, frame - size, and channel count. - This can be checked in advance by examining the top 6 bits of the first - byte of the packet, and ensuring they match the top 6 bits of the first - byte of any previously submitted packet. - The total duration of audio in the repacketizer state also must not exceed - 120 ms, the maximum duration of a single packet, after adding this packet. - - The contents of the current repacketizer state can be extracted into new - packets using opus_repacketizer_out() or opus_repacketizer_out_range(). - - In order to add a packet with a different configuration or to add more - audio beyond 120 ms, you must clear the repacketizer state by calling - opus_repacketizer_init(). - If a packet is too large to add to the current repacketizer state, no part - of it is added, even if it contains multiple frames, some of which might - fit. - If you wish to be able to add parts of such packets, you should first use - another repacketizer to split the packet into pieces and add them - individually. - @see opus_repacketizer_out_range - @see opus_repacketizer_out - @see opus_repacketizer_init - @param rp OpusRepacketizer*: The repacketizer state to which to - add the packet. - @param[in] data const unsigned char*: The packet data. - The application must ensure - this pointer remains valid - until the next call to - opus_repacketizer_init() or - opus_repacketizer_destroy(). - @param len opus_int32: The number of bytes in the packet data. - @returns An error code indicating whether or not the operation succeeded. - @retval #OPUS_OK The packet's contents have been added to the repacketizer - state. - @retval #OPUS_INVALID_PACKET The packet did not have a valid TOC sequence, - the packet's TOC sequence was not compatible - with previously submitted packets (because - the coding mode, audio bandwidth, frame size, - or channel count did not match), or adding - this packet would increase the total amount of - audio stored in the repacketizer state to more - than 120 ms. -*/ -OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); - - -/** Construct a new packet from data previously submitted to the repacketizer - state via opus_repacketizer_cat(). - @param rp OpusRepacketizer*: The repacketizer state from which to - construct the new packet. - @param begin int: The index of the first frame in the current - repacketizer state to include in the output. - @param end int: One past the index of the last frame in the - current repacketizer state to include in the - output. - @param[out] data const unsigned char*: The buffer in which to - store the output packet. - @param maxlen opus_int32: The maximum number of bytes to store in - the output buffer. In order to guarantee - success, this should be at least - 1276 for a single frame, - or for multiple frames, - 1277*(end-begin). - However, 1*(end-begin) plus - the size of all packet data submitted to - the repacketizer since the last call to - opus_repacketizer_init() or - opus_repacketizer_create() is also - sufficient, and possibly much smaller. - @returns The total size of the output packet on success, or an error code - on failure. - @retval #OPUS_BAD_ARG [begin,end) was an invalid range of - frames (begin < 0, begin >= end, or end > - opus_repacketizer_get_nb_frames()). - @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the - complete output packet. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Return the total number of frames contained in packet data submitted to - the repacketizer state so far via opus_repacketizer_cat() since the last - call to opus_repacketizer_init() or opus_repacketizer_create(). - This defines the valid range of packets that can be extracted with - opus_repacketizer_out_range() or opus_repacketizer_out(). - @param rp OpusRepacketizer*: The repacketizer state containing the - frames. - @returns The total number of frames contained in the packet data submitted - to the repacketizer state. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); - -/** Construct a new packet from data previously submitted to the repacketizer - state via opus_repacketizer_cat(). - This is a convenience routine that returns all the data submitted so far - in a single packet. - It is equivalent to calling - @code - opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp), - data, maxlen) - @endcode - @param rp OpusRepacketizer*: The repacketizer state from which to - construct the new packet. - @param[out] data const unsigned char*: The buffer in which to - store the output packet. - @param maxlen opus_int32: The maximum number of bytes to store in - the output buffer. In order to guarantee - success, this should be at least - 1277*opus_repacketizer_get_nb_frames(rp). - However, - 1*opus_repacketizer_get_nb_frames(rp) - plus the size of all packet data - submitted to the repacketizer since the - last call to opus_repacketizer_init() or - opus_repacketizer_create() is also - sufficient, and possibly much smaller. - @returns The total size of the output packet on success, or an error code - on failure. - @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the - complete output packet. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1); - -/** Pads a given Opus packet to a larger size (possibly changing the TOC sequence). - @param[in,out] data const unsigned char*: The buffer containing the - packet to pad. - @param len opus_int32: The size of the packet. - This must be at least 1. - @param new_len opus_int32: The desired size of the packet after padding. - This must be at least as large as len. - @returns an error code - @retval #OPUS_OK \a on success. - @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. - @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. -*/ -OPUS_EXPORT int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len); - -/** Remove all padding from a given Opus packet and rewrite the TOC sequence to - minimize space usage. - @param[in,out] data const unsigned char*: The buffer containing the - packet to strip. - @param len opus_int32: The size of the packet. - This must be at least 1. - @returns The new size of the output packet on success, or an error code - on failure. - @retval #OPUS_BAD_ARG \a len was less than 1. - @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len); - -/** Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence). - @param[in,out] data const unsigned char*: The buffer containing the - packet to pad. - @param len opus_int32: The size of the packet. - This must be at least 1. - @param new_len opus_int32: The desired size of the packet after padding. - This must be at least 1. - @param nb_streams opus_int32: The number of streams (not channels) in the packet. - This must be at least as large as len. - @returns an error code - @retval #OPUS_OK \a on success. - @retval #OPUS_BAD_ARG \a len was less than 1. - @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. -*/ -OPUS_EXPORT int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams); - -/** Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to - minimize space usage. - @param[in,out] data const unsigned char*: The buffer containing the - packet to strip. - @param len opus_int32: The size of the packet. - This must be at least 1. - @param nb_streams opus_int32: The number of streams (not channels) in the packet. - This must be at least 1. - @returns The new size of the output packet on success, or an error code - on failure. - @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. - @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, int nb_streams); - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_H */ diff --git a/src/libopus/opus.pc b/src/libopus/opus.pc deleted file mode 100644 index da284cf..0000000 --- a/src/libopus/opus.pc +++ /dev/null @@ -1,16 +0,0 @@ -# Opus codec reference implementation pkg-config file - -prefix=/usr/local -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: Opus -Description: Opus IETF audio codec (fixed-point build) -URL: https://opus-codec.org/ -Version: 1.3.1 -Requires: -Conflicts: -Libs: -L${libdir} -lopus -Libs.private: -lm -Cflags: -I${includedir}/opus diff --git a/src/libopus/opus_custom.h b/src/libopus/opus_custom.h deleted file mode 100644 index 12cec92..0000000 --- a/src/libopus/opus_custom.h +++ /dev/null @@ -1,342 +0,0 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2008-2012 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - @file opus_custom.h - @brief Opus-Custom reference implementation API -*/ - -#ifndef OPUS_CUSTOM_H -#define OPUS_CUSTOM_H - -#include "opus_defines.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef CUSTOM_MODES -# define OPUS_CUSTOM_EXPORT OPUS_EXPORT -# define OPUS_CUSTOM_EXPORT_STATIC OPUS_EXPORT -#else -# define OPUS_CUSTOM_EXPORT -# ifdef OPUS_BUILD -# define OPUS_CUSTOM_EXPORT_STATIC static OPUS_INLINE -# else -# define OPUS_CUSTOM_EXPORT_STATIC -# endif -#endif - -/** @defgroup opus_custom Opus Custom - @{ - Opus Custom is an optional part of the Opus specification and - reference implementation which uses a distinct API from the regular - API and supports frame sizes that are not normally supported.\ Use - of Opus Custom is discouraged for all but very special applications - for which a frame size different from 2.5, 5, 10, or 20 ms is needed - (for either complexity or latency reasons) and where interoperability - is less important. - - In addition to the interoperability limitations the use of Opus custom - disables a substantial chunk of the codec and generally lowers the - quality available at a given bitrate. Normally when an application needs - a different frame size from the codec it should buffer to match the - sizes but this adds a small amount of delay which may be important - in some very low latency applications. Some transports (especially - constant rate RF transports) may also work best with frames of - particular durations. - - Libopus only supports custom modes if they are enabled at compile time. - - The Opus Custom API is similar to the regular API but the - @ref opus_encoder_create and @ref opus_decoder_create calls take - an additional mode parameter which is a structure produced by - a call to @ref opus_custom_mode_create. Both the encoder and decoder - must create a mode using the same sample rate (fs) and frame size - (frame size) so these parameters must either be signaled out of band - or fixed in a particular implementation. - - Similar to regular Opus the custom modes support on the fly frame size - switching, but the sizes available depend on the particular frame size in - use. For some initial frame sizes on a single on the fly size is available. -*/ - -/** Contains the state of an encoder. One encoder state is needed - for each stream. It is initialized once at the beginning of the - stream. Do *not* re-initialize the state for every frame. - @brief Encoder state -*/ -typedef struct OpusCustomEncoder OpusCustomEncoder; - -/** State of the decoder. One decoder state is needed for each stream. - It is initialized once at the beginning of the stream. Do *not* - re-initialize the state for every frame. - @brief Decoder state -*/ -typedef struct OpusCustomDecoder OpusCustomDecoder; - -/** The mode contains all the information necessary to create an - encoder. Both the encoder and decoder need to be initialized - with exactly the same mode, otherwise the output will be - corrupted. - @brief Mode configuration -*/ -typedef struct OpusCustomMode OpusCustomMode; - -/** Creates a new mode struct. This will be passed to an encoder or - decoder. The mode MUST NOT BE DESTROYED until the encoders and - decoders that use it are destroyed as well. - @param [in] Fs int: Sampling rate (8000 to 96000 Hz) - @param [in] frame_size int: Number of samples (per channel) to encode in each - packet (64 - 1024, prime factorization must contain zero or more 2s, 3s, or 5s and no other primes) - @param [out] error int*: Returned error code (if NULL, no error will be returned) - @return A newly created mode -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomMode *opus_custom_mode_create(opus_int32 Fs, int frame_size, int *error); - -/** Destroys a mode struct. Only call this after all encoders and - decoders using this mode are destroyed as well. - @param [in] mode OpusCustomMode*: Mode to be freed. -*/ -OPUS_CUSTOM_EXPORT void opus_custom_mode_destroy(OpusCustomMode *mode); - - -#if !defined(OPUS_BUILD) || defined(CELT_ENCODER_C) - -/* Encoder */ -/** Gets the size of an OpusCustomEncoder structure. - @param [in] mode OpusCustomMode *: Mode configuration - @param [in] channels int: Number of channels - @returns size -*/ -OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_encoder_get_size( - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1); - -# ifdef CUSTOM_MODES -/** Initializes a previously allocated encoder state - The memory pointed to by st must be the size returned by opus_custom_encoder_get_size. - This is intended for applications which use their own allocator instead of malloc. - @see opus_custom_encoder_create(),opus_custom_encoder_get_size() - To reset a previously initialized state use the OPUS_RESET_STATE CTL. - @param [in] st OpusCustomEncoder*: Encoder state - @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of - the stream (must be the same characteristics as used for the - decoder) - @param [in] channels int: Number of channels - @return OPUS_OK Success or @ref opus_errorcodes -*/ -OPUS_CUSTOM_EXPORT int opus_custom_encoder_init( - OpusCustomEncoder *st, - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); -# endif -#endif - - -/** Creates a new encoder state. Each stream needs its own encoder - state (can't be shared across simultaneous streams). - @param [in] mode OpusCustomMode*: Contains all the information about the characteristics of - the stream (must be the same characteristics as used for the - decoder) - @param [in] channels int: Number of channels - @param [out] error int*: Returns an error code - @return Newly created encoder state. -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomEncoder *opus_custom_encoder_create( - const OpusCustomMode *mode, - int channels, - int *error -) OPUS_ARG_NONNULL(1); - - -/** Destroys a an encoder state. - @param[in] st OpusCustomEncoder*: State to be freed. -*/ -OPUS_CUSTOM_EXPORT void opus_custom_encoder_destroy(OpusCustomEncoder *st); - -/** Encodes a frame of audio. - @param [in] st OpusCustomEncoder*: Encoder state - @param [in] pcm float*: PCM audio in float format, with a normal range of +/-1.0. - Samples with a range beyond +/-1.0 are supported but will - be clipped by decoders using the integer API and should - only be used if it is known that the far end supports - extended dynamic range. There must be exactly - frame_size samples per channel. - @param [in] frame_size int: Number of samples per frame of input signal - @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. - @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame - (can change from one frame to another) - @return Number of bytes written to "compressed". - If negative, an error has occurred (see error codes). It is IMPORTANT that - the length returned be somehow transmitted to the decoder. Otherwise, no - decoding is possible. -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode_float( - OpusCustomEncoder *st, - const float *pcm, - int frame_size, - unsigned char *compressed, - int maxCompressedBytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Encodes a frame of audio. - @param [in] st OpusCustomEncoder*: Encoder state - @param [in] pcm opus_int16*: PCM audio in signed 16-bit format (native endian). - There must be exactly frame_size samples per channel. - @param [in] frame_size int: Number of samples per frame of input signal - @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. - @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame - (can change from one frame to another) - @return Number of bytes written to "compressed". - If negative, an error has occurred (see error codes). It is IMPORTANT that - the length returned be somehow transmitted to the decoder. Otherwise, no - decoding is possible. -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode( - OpusCustomEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *compressed, - int maxCompressedBytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on an Opus custom encoder. - - Generally the request and subsequent arguments are generated - by a convenience macro. - @see opus_encoderctls -*/ -OPUS_CUSTOM_EXPORT int opus_custom_encoder_ctl(OpusCustomEncoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); - - -#if !defined(OPUS_BUILD) || defined(CELT_DECODER_C) -/* Decoder */ - -/** Gets the size of an OpusCustomDecoder structure. - @param [in] mode OpusCustomMode *: Mode configuration - @param [in] channels int: Number of channels - @returns size -*/ -OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_decoder_get_size( - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1); - -/** Initializes a previously allocated decoder state - The memory pointed to by st must be the size returned by opus_custom_decoder_get_size. - This is intended for applications which use their own allocator instead of malloc. - @see opus_custom_decoder_create(),opus_custom_decoder_get_size() - To reset a previously initialized state use the OPUS_RESET_STATE CTL. - @param [in] st OpusCustomDecoder*: Decoder state - @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of - the stream (must be the same characteristics as used for the - encoder) - @param [in] channels int: Number of channels - @return OPUS_OK Success or @ref opus_errorcodes -*/ -OPUS_CUSTOM_EXPORT_STATIC int opus_custom_decoder_init( - OpusCustomDecoder *st, - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); - -#endif - - -/** Creates a new decoder state. Each stream needs its own decoder state (can't - be shared across simultaneous streams). - @param [in] mode OpusCustomMode: Contains all the information about the characteristics of the - stream (must be the same characteristics as used for the encoder) - @param [in] channels int: Number of channels - @param [out] error int*: Returns an error code - @return Newly created decoder state. -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomDecoder *opus_custom_decoder_create( - const OpusCustomMode *mode, - int channels, - int *error -) OPUS_ARG_NONNULL(1); - -/** Destroys a an decoder state. - @param[in] st OpusCustomDecoder*: State to be freed. -*/ -OPUS_CUSTOM_EXPORT void opus_custom_decoder_destroy(OpusCustomDecoder *st); - -/** Decode an opus custom frame with floating point output - @param [in] st OpusCustomDecoder*: Decoder state - @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - @param [in] len int: Number of bytes in payload - @param [out] pcm float*: Output signal (interleaved if 2 channels). length - is frame_size*channels*sizeof(float) - @param [in] frame_size Number of samples per channel of available space in *pcm. - @returns Number of decoded samples or @ref opus_errorcodes -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode_float( - OpusCustomDecoder *st, - const unsigned char *data, - int len, - float *pcm, - int frame_size -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Decode an opus custom frame - @param [in] st OpusCustomDecoder*: Decoder state - @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - @param [in] len int: Number of bytes in payload - @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length - is frame_size*channels*sizeof(opus_int16) - @param [in] frame_size Number of samples per channel of available space in *pcm. - @returns Number of decoded samples or @ref opus_errorcodes -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode( - OpusCustomDecoder *st, - const unsigned char *data, - int len, - opus_int16 *pcm, - int frame_size -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on an Opus custom decoder. - - Generally the request and subsequent arguments are generated - by a convenience macro. - @see opus_genericctls -*/ -OPUS_CUSTOM_EXPORT int opus_custom_decoder_ctl(OpusCustomDecoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_CUSTOM_H */ diff --git a/src/libopus/opus_decoder.c b/src/libopus/opus_decoder.c deleted file mode 100644 index 0b2ba33..0000000 --- a/src/libopus/opus_decoder.c +++ /dev/null @@ -1,992 +0,0 @@ -/* Copyright (c) 2010 Xiph.Org Foundation, Skype Limited - Written by Jean-Marc Valin and Koen Vos */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -# include "config.h" -//#endif - -#ifndef OPUS_BUILD -# error "OPUS_BUILD _MUST_ be defined to build Opus. This probably means you need other defines as well, as in a config.h. See the included build files for details." -#endif - -#if defined(__GNUC__) && (__GNUC__ >= 2) && !defined(__OPTIMIZE__) && !defined(OPUS_WILL_BE_SLOW) -// Yes, I know... -// # pragma message "You appear to be compiling without optimization, if so opus will be very slow." -#endif - -#include -#include "celt/celt.h" -#include "opus.h" -#include "celt/entdec.h" -#include "celt/modes.h" -#include "silk/API.h" -#include "celt/stack_alloc.h" -#include "celt/float_cast.h" -#include "opus_private.h" -#include "celt/os_support.h" -#include "silk/structs.h" -#include "silk/define.h" -#include "celt/mathops.h" -#include "celt/cpu_support.h" - -struct OpusDecoder { - int celt_dec_offset; - int silk_dec_offset; - int channels; - opus_int32 Fs; /** Sampling rate (at the API level) */ - silk_DecControlStruct DecControl; - int decode_gain; - int arch; - - /* Everything beyond this point gets cleared on a reset */ -#define OPUS_DECODER_RESET_START stream_channels - int stream_channels; - - int bandwidth; - int mode; - int prev_mode; - int frame_size; - int prev_redundancy; - int last_packet_duration; -#ifndef FIXED_POINT - opus_val16 softclip_mem[2]; -#endif - - opus_uint32 rangeFinal; -}; - -#if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS) -static void validate_opus_decoder(OpusDecoder *st) { - celt_assert(st->channels == 1 || st->channels == 2); - celt_assert(st->Fs == 48000 || st->Fs == 24000 || st->Fs == 16000 || st->Fs == 12000 || st->Fs == 8000); - celt_assert(st->DecControl.API_sampleRate == st->Fs); - celt_assert(st->DecControl.internalSampleRate == 0 || st->DecControl.internalSampleRate == 16000 || st->DecControl.internalSampleRate == 12000 || st->DecControl.internalSampleRate == 8000); - celt_assert(st->DecControl.nChannelsAPI == st->channels); - celt_assert(st->DecControl.nChannelsInternal == 0 || st->DecControl.nChannelsInternal == 1 || st->DecControl.nChannelsInternal == 2); - celt_assert(st->DecControl.payloadSize_ms == 0 || st->DecControl.payloadSize_ms == 10 || st->DecControl.payloadSize_ms == 20 || st->DecControl.payloadSize_ms == 40 || st->DecControl.payloadSize_ms == 60); -#ifdef OPUS_ARCHMASK - celt_assert(st->arch >= 0); - celt_assert(st->arch <= OPUS_ARCHMASK); -#endif - celt_assert(st->stream_channels == 1 || st->stream_channels == 2); -} -#define VALIDATE_OPUS_DECODER(st) validate_opus_decoder(st) -#else -#define VALIDATE_OPUS_DECODER(st) -#endif - -int opus_decoder_get_size(int channels) { - int silkDecSizeBytes, celtDecSizeBytes; - int ret; - if (channels < 1 || channels > 2) { - return 0; - } - ret = silk_Get_Decoder_Size(&silkDecSizeBytes); - if (ret) { - return 0; - } - silkDecSizeBytes = align(silkDecSizeBytes); - celtDecSizeBytes = celt_decoder_get_size(channels); - return align(sizeof(OpusDecoder)) + silkDecSizeBytes + celtDecSizeBytes; -} - -int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) { - void *silk_dec; - CELTDecoder *celt_dec; - int ret, silkDecSizeBytes; - - if ((Fs != 48000 && Fs != 24000 && Fs != 16000 && Fs != 12000 && Fs != 8000) - || (channels != 1 && channels != 2)) { - return OPUS_BAD_ARG; - } - - OPUS_CLEAR((char*)st, opus_decoder_get_size(channels)); - /* Initialize SILK decoder */ - ret = silk_Get_Decoder_Size(&silkDecSizeBytes); - if (ret) { - return OPUS_INTERNAL_ERROR; - } - - silkDecSizeBytes = align(silkDecSizeBytes); - st->silk_dec_offset = align(sizeof(OpusDecoder)); - st->celt_dec_offset = st->silk_dec_offset + silkDecSizeBytes; - silk_dec = (char*)st + st->silk_dec_offset; - celt_dec = (CELTDecoder*)((char*)st + st->celt_dec_offset); - st->stream_channels = st->channels = channels; - - st->Fs = Fs; - st->DecControl.API_sampleRate = st->Fs; - st->DecControl.nChannelsAPI = st->channels; - - /* Reset decoder */ - ret = silk_InitDecoder(silk_dec); - if (ret) { - return OPUS_INTERNAL_ERROR; - } - - /* Initialize CELT decoder */ - ret = celt_decoder_init(celt_dec, Fs, channels); - if (ret != OPUS_OK) { - return OPUS_INTERNAL_ERROR; - } - - celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0)); - - st->prev_mode = 0; - st->frame_size = Fs / 400; - st->arch = opus_select_arch(); - return OPUS_OK; -} - -OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error) { - int ret; - OpusDecoder *st; - if ((Fs != 48000 && Fs != 24000 && Fs != 16000 && Fs != 12000 && Fs != 8000) - || (channels != 1 && channels != 2)) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } - st = (OpusDecoder *)opus_alloc(opus_decoder_get_size(channels)); - if (st == NULL) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - ret = opus_decoder_init(st, Fs, channels); - if (error) { - *error = ret; - } - if (ret != OPUS_OK) { - opus_free(st); - st = NULL; - } - return st; -} - -static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2, - opus_val16 *out, int overlap, int channels, - const opus_val16 *window, opus_int32 Fs) { - int i, c; - int inc = 48000 / Fs; - for (c = 0; c < channels; c++) { - for (i = 0; i < overlap; i++) { - opus_val16 w = MULT16_16_Q15(window[i * inc], window[i * inc]); - out[i * channels + c] = SHR32(MAC16_16(MULT16_16(w, in2[i * channels + c]), - Q15ONE - w, in1[i * channels + c]), 15); - } - } -} - -static int opus_packet_get_mode(const unsigned char *data) { - int mode; - if (data[0] & 0x80) { - mode = MODE_CELT_ONLY; - } else if ((data[0] & 0x60) == 0x60) { - mode = MODE_HYBRID; - } else { - mode = MODE_SILK_ONLY; - } - return mode; -} - -static int opus_decode_frame(OpusDecoder *st, const unsigned char *data, - opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec) { - void *silk_dec; - CELTDecoder *celt_dec; - int i, silk_ret = 0, celt_ret = 0; - ec_dec dec; - opus_int32 silk_frame_size; - int pcm_silk_size; - VARDECL(opus_int16, pcm_silk); - int pcm_transition_silk_size; - VARDECL(opus_val16, pcm_transition_silk); - int pcm_transition_celt_size; - VARDECL(opus_val16, pcm_transition_celt); - opus_val16 *pcm_transition = NULL; - int redundant_audio_size; - VARDECL(opus_val16, redundant_audio); - - int audiosize; - int mode; - int bandwidth; - int transition = 0; - int start_band; - int redundancy = 0; - int redundancy_bytes = 0; - int celt_to_silk = 0; - int c; - int F2_5, F5, F10, F20; - const opus_val16 *window; - opus_uint32 redundant_rng = 0; - int celt_accum; - ALLOC_STACK; - - silk_dec = (char*)st + st->silk_dec_offset; - celt_dec = (CELTDecoder*)((char*)st + st->celt_dec_offset); - F20 = st->Fs / 50; - F10 = F20 >> 1; - F5 = F10 >> 1; - F2_5 = F5 >> 1; - if (frame_size < F2_5) { - RESTORE_STACK; - return OPUS_BUFFER_TOO_SMALL; - } - /* Limit frame_size to avoid excessive stack allocations. */ - frame_size = IMIN(frame_size, st->Fs / 25 * 3); - /* Payloads of 1 (2 including ToC) or 0 trigger the PLC/DTX */ - if (len <= 1) { - data = NULL; - /* In that case, don't conceal more than what the ToC says */ - frame_size = IMIN(frame_size, st->frame_size); - } - if (data != NULL) { - audiosize = st->frame_size; - mode = st->mode; - bandwidth = st->bandwidth; - ec_dec_init(&dec, (unsigned char*)data, len); - } else { - audiosize = frame_size; - mode = st->prev_mode; - bandwidth = 0; - - if (mode == 0) { - /* If we haven't got any packet yet, all we can do is return zeros */ - for (i = 0; i < audiosize * st->channels; i++) { - pcm[i] = 0; - } - RESTORE_STACK; - return audiosize; - } - - /* Avoids trying to run the PLC on sizes other than 2.5 (CELT), 5 (CELT), - 10, or 20 (e.g. 12.5 or 30 ms). */ - if (audiosize > F20) { - do { - int ret = opus_decode_frame(st, NULL, 0, pcm, IMIN(audiosize, F20), 0); - if (ret < 0) { - RESTORE_STACK; - return ret; - } - pcm += ret * st->channels; - audiosize -= ret; - } while (audiosize > 0); - RESTORE_STACK; - return frame_size; - } else if (audiosize < F20) { - if (audiosize > F10) { - audiosize = F10; - } else if (mode != MODE_SILK_ONLY && audiosize > F5 && audiosize < F10) { - audiosize = F5; - } - } - } - - /* In fixed-point, we can tell CELT to do the accumulation on top of the - SILK PCM buffer. This saves some stack space. */ -#ifdef FIXED_POINT - celt_accum = (mode != MODE_CELT_ONLY) && (frame_size >= F10); -#else - celt_accum = 0; -#endif - - pcm_transition_silk_size = ALLOC_NONE; - pcm_transition_celt_size = ALLOC_NONE; - if (data != NULL && st->prev_mode > 0 && ( - (mode == MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY && !st->prev_redundancy) - || (mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY)) - ) { - transition = 1; - /* Decide where to allocate the stack memory for pcm_transition */ - if (mode == MODE_CELT_ONLY) { - pcm_transition_celt_size = F5 * st->channels; - } else { - pcm_transition_silk_size = F5 * st->channels; - } - } - ALLOC(pcm_transition_celt, pcm_transition_celt_size, opus_val16); - if (transition && mode == MODE_CELT_ONLY) { - pcm_transition = pcm_transition_celt; - opus_decode_frame(st, NULL, 0, pcm_transition, IMIN(F5, audiosize), 0); - } - if (audiosize > frame_size) { - /*fprintf(stderr, "PCM buffer too small: %d vs %d (mode = %d)\n", audiosize, frame_size, mode);*/ - RESTORE_STACK; - return OPUS_BAD_ARG; - } else { - frame_size = audiosize; - } - - /* Don't allocate any memory when in CELT-only mode */ - pcm_silk_size = (mode != MODE_CELT_ONLY && !celt_accum) ? IMAX(F10, frame_size) * st->channels : ALLOC_NONE; - ALLOC(pcm_silk, pcm_silk_size, opus_int16); - - /* SILK processing */ - if (mode != MODE_CELT_ONLY) { - int lost_flag, decoded_samples; - opus_int16 *pcm_ptr; -#ifdef FIXED_POINT - if (celt_accum) { - pcm_ptr = pcm; - } else -#endif - pcm_ptr = pcm_silk; - - if (st->prev_mode == MODE_CELT_ONLY) { - silk_InitDecoder(silk_dec); - } - - /* The SILK PLC cannot produce frames of less than 10 ms */ - st->DecControl.payloadSize_ms = IMAX(10, 1000 * audiosize / st->Fs); - - if (data != NULL) { - st->DecControl.nChannelsInternal = st->stream_channels; - if (mode == MODE_SILK_ONLY) { - if (bandwidth == OPUS_BANDWIDTH_NARROWBAND) { - st->DecControl.internalSampleRate = 8000; - } else if (bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - st->DecControl.internalSampleRate = 12000; - } else if (bandwidth == OPUS_BANDWIDTH_WIDEBAND) { - st->DecControl.internalSampleRate = 16000; - } else { - st->DecControl.internalSampleRate = 16000; - celt_assert(0); - } - } else { - /* Hybrid mode */ - st->DecControl.internalSampleRate = 16000; - } - } - - lost_flag = data == NULL ? 1 : 2 * decode_fec; - decoded_samples = 0; - do { - /* Call SILK decoder */ - int first_frame = decoded_samples == 0; - silk_ret = silk_Decode(silk_dec, &st->DecControl, - lost_flag, first_frame, &dec, pcm_ptr, &silk_frame_size, st->arch); - if (silk_ret) { - if (lost_flag) { - /* PLC failure should not be fatal */ - silk_frame_size = frame_size; - for (i = 0; i < frame_size * st->channels; i++) { - pcm_ptr[i] = 0; - } - } else { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - } - pcm_ptr += silk_frame_size * st->channels; - decoded_samples += silk_frame_size; - } while (decoded_samples < frame_size); - } - - start_band = 0; - if (!decode_fec && mode != MODE_CELT_ONLY && data != NULL - && ec_tell(&dec) + 17 + 20 * (st->mode == MODE_HYBRID) <= 8 * len) { - /* Check if we have a redundant 0-8 kHz band */ - if (mode == MODE_HYBRID) { - redundancy = ec_dec_bit_logp(&dec, 12); - } else { - redundancy = 1; - } - if (redundancy) { - celt_to_silk = ec_dec_bit_logp(&dec, 1); - /* redundancy_bytes will be at least two, in the non-hybrid - case due to the ec_tell() check above */ - redundancy_bytes = mode == MODE_HYBRID ? - (opus_int32)ec_dec_uint(&dec, 256) + 2 : - len - ((ec_tell(&dec) + 7) >> 3); - len -= redundancy_bytes; - /* This is a sanity check. It should never happen for a valid - packet, so the exact behaviour is not normative. */ - if (len * 8 < ec_tell(&dec)) { - len = 0; - redundancy_bytes = 0; - redundancy = 0; - } - /* Shrink decoder because of raw bits */ - dec.storage -= redundancy_bytes; - } - } - if (mode != MODE_CELT_ONLY) { - start_band = 17; - } - - if (redundancy) { - transition = 0; - pcm_transition_silk_size = ALLOC_NONE; - } - - ALLOC(pcm_transition_silk, pcm_transition_silk_size, opus_val16); - - if (transition && mode != MODE_CELT_ONLY) { - pcm_transition = pcm_transition_silk; - opus_decode_frame(st, NULL, 0, pcm_transition, IMIN(F5, audiosize), 0); - } - - - if (bandwidth) { - int endband = 21; - - switch (bandwidth) { - case OPUS_BANDWIDTH_NARROWBAND: - endband = 13; - break; - case OPUS_BANDWIDTH_MEDIUMBAND: - case OPUS_BANDWIDTH_WIDEBAND: - endband = 17; - break; - case OPUS_BANDWIDTH_SUPERWIDEBAND: - endband = 19; - break; - case OPUS_BANDWIDTH_FULLBAND: - endband = 21; - break; - default: - celt_assert(0); - break; - } - MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_END_BAND(endband))); - } - MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_CHANNELS(st->stream_channels))); - - /* Only allocation memory for redundancy if/when needed */ - redundant_audio_size = redundancy ? F5 * st->channels : ALLOC_NONE; - ALLOC(redundant_audio, redundant_audio_size, opus_val16); - - /* 5 ms redundant frame for CELT->SILK*/ - if (redundancy && celt_to_silk) { - MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0))); - celt_decode_with_ec(celt_dec, data + len, redundancy_bytes, - redundant_audio, F5, NULL, 0); - MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng))); - } - - /* MUST be after PLC */ - MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(start_band))); - - if (mode != MODE_SILK_ONLY) { - int celt_frame_size = IMIN(F20, frame_size); - /* Make sure to discard any previous CELT state */ - if (mode != st->prev_mode && st->prev_mode > 0 && !st->prev_redundancy) { - MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_RESET_STATE)); - } - /* Decode CELT */ - celt_ret = celt_decode_with_ec(celt_dec, decode_fec ? NULL : data, - len, pcm, celt_frame_size, &dec, celt_accum); - } else { - unsigned char silence[2] = {0xFF, 0xFF}; - if (!celt_accum) { - for (i = 0; i < frame_size * st->channels; i++) { - pcm[i] = 0; - } - } - /* For hybrid -> SILK transitions, we let the CELT MDCT - do a fade-out by decoding a silence frame */ - if (st->prev_mode == MODE_HYBRID && !(redundancy && celt_to_silk && st->prev_redundancy)) { - MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0))); - celt_decode_with_ec(celt_dec, silence, 2, pcm, F2_5, NULL, celt_accum); - } - } - - if (mode != MODE_CELT_ONLY && !celt_accum) { -#ifdef FIXED_POINT - for (i = 0; i < frame_size * st->channels; i++) { - pcm[i] = SAT16(ADD32(pcm[i], pcm_silk[i])); - } -#else - for (i = 0; i < frame_size * st->channels; i++) { - pcm[i] = pcm[i] + (opus_val16)((1.f / 32768.f) * pcm_silk[i]); - } -#endif - } - - { - const CELTMode *celt_mode; - MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_GET_MODE(&celt_mode))); - window = celt_mode->window; - } - - /* 5 ms redundant frame for SILK->CELT */ - if (redundancy && !celt_to_silk) { - MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_RESET_STATE)); - MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0))); - - celt_decode_with_ec(celt_dec, data + len, redundancy_bytes, redundant_audio, F5, NULL, 0); - MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng))); - smooth_fade(pcm + st->channels * (frame_size - F2_5), redundant_audio + st->channels * F2_5, - pcm + st->channels * (frame_size - F2_5), F2_5, st->channels, window, st->Fs); - } - if (redundancy && celt_to_silk) { - for (c = 0; c < st->channels; c++) { - for (i = 0; i < F2_5; i++) { - pcm[st->channels * i + c] = redundant_audio[st->channels * i + c]; - } - } - smooth_fade(redundant_audio + st->channels * F2_5, pcm + st->channels * F2_5, - pcm + st->channels * F2_5, F2_5, st->channels, window, st->Fs); - } - if (transition) { - if (audiosize >= F5) { - for (i = 0; i < st->channels * F2_5; i++) { - pcm[i] = pcm_transition[i]; - } - smooth_fade(pcm_transition + st->channels * F2_5, pcm + st->channels * F2_5, - pcm + st->channels * F2_5, F2_5, - st->channels, window, st->Fs); - } else { - /* Not enough time to do a clean transition, but we do it anyway - This will not preserve amplitude perfectly and may introduce - a bit of temporal aliasing, but it shouldn't be too bad and - that's pretty much the best we can do. In any case, generating this - transition it pretty silly in the first place */ - smooth_fade(pcm_transition, pcm, - pcm, F2_5, - st->channels, window, st->Fs); - } - } - - if (st->decode_gain) { - opus_val32 gain; - gain = celt_exp2(MULT16_16_P15(QCONST16(6.48814081e-4f, 25), st->decode_gain)); - for (i = 0; i < frame_size * st->channels; i++) { - opus_val32 x; - x = MULT16_32_P16(pcm[i], gain); - pcm[i] = SATURATE(x, 32767); - } - } - - if (len <= 1) { - st->rangeFinal = 0; - } else { - st->rangeFinal = dec.rng ^ redundant_rng; - } - - st->prev_mode = mode; - st->prev_redundancy = redundancy && !celt_to_silk; - - if (celt_ret >= 0) { - if (OPUS_CHECK_ARRAY(pcm, audiosize * st->channels)) { - OPUS_PRINT_INT(audiosize); - } - } - - RESTORE_STACK; - return celt_ret < 0 ? celt_ret : audiosize; - -} - -int opus_decode_native(OpusDecoder *st, const unsigned char *data, - opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec, - int self_delimited, opus_int32 *packet_offset, int soft_clip) { - int i, nb_samples; - int count, offset; - unsigned char toc; - int packet_frame_size, packet_bandwidth, packet_mode, packet_stream_channels; - /* 48 x 2.5 ms = 120 ms */ - opus_int16 size[48]; - VALIDATE_OPUS_DECODER(st); - if (decode_fec < 0 || decode_fec > 1) { - return OPUS_BAD_ARG; - } - /* For FEC/PLC, frame_size has to be to have a multiple of 2.5 ms */ - if ((decode_fec || len == 0 || data == NULL) && frame_size % (st->Fs / 400) != 0) { - return OPUS_BAD_ARG; - } - if (len == 0 || data == NULL) { - int pcm_count = 0; - do { - int ret; - ret = opus_decode_frame(st, NULL, 0, pcm + pcm_count * st->channels, frame_size - pcm_count, 0); - if (ret < 0) { - return ret; - } - pcm_count += ret; - } while (pcm_count < frame_size); - celt_assert(pcm_count == frame_size); - if (OPUS_CHECK_ARRAY(pcm, pcm_count * st->channels)) { - OPUS_PRINT_INT(pcm_count); - } - st->last_packet_duration = pcm_count; - return pcm_count; - } else if (len < 0) { - return OPUS_BAD_ARG; - } - - packet_mode = opus_packet_get_mode(data); - packet_bandwidth = opus_packet_get_bandwidth(data); - packet_frame_size = opus_packet_get_samples_per_frame(data, st->Fs); - packet_stream_channels = opus_packet_get_nb_channels(data); - - count = opus_packet_parse_impl(data, len, self_delimited, &toc, NULL, - size, &offset, packet_offset); - if (count < 0) { - return count; - } - - data += offset; - - if (decode_fec) { - int duration_copy; - int ret; - /* If no FEC can be present, run the PLC (recursive call) */ - if (frame_size < packet_frame_size || packet_mode == MODE_CELT_ONLY || st->mode == MODE_CELT_ONLY) { - return opus_decode_native(st, NULL, 0, pcm, frame_size, 0, 0, NULL, soft_clip); - } - /* Otherwise, run the PLC on everything except the size for which we might have FEC */ - duration_copy = st->last_packet_duration; - if (frame_size - packet_frame_size != 0) { - ret = opus_decode_native(st, NULL, 0, pcm, frame_size - packet_frame_size, 0, 0, NULL, soft_clip); - if (ret < 0) { - st->last_packet_duration = duration_copy; - return ret; - } - celt_assert(ret == frame_size - packet_frame_size); - } - /* Complete with FEC */ - st->mode = packet_mode; - st->bandwidth = packet_bandwidth; - st->frame_size = packet_frame_size; - st->stream_channels = packet_stream_channels; - ret = opus_decode_frame(st, data, size[0], pcm + st->channels * (frame_size - packet_frame_size), - packet_frame_size, 1); - if (ret < 0) { - return ret; - } else { - if (OPUS_CHECK_ARRAY(pcm, frame_size * st->channels)) { - OPUS_PRINT_INT(frame_size); - } - st->last_packet_duration = frame_size; - return frame_size; - } - } - - if (count * packet_frame_size > frame_size) { - return OPUS_BUFFER_TOO_SMALL; - } - - /* Update the state as the last step to avoid updating it on an invalid packet */ - st->mode = packet_mode; - st->bandwidth = packet_bandwidth; - st->frame_size = packet_frame_size; - st->stream_channels = packet_stream_channels; - - nb_samples = 0; - for (i = 0; i < count; i++) { - int ret; - ret = opus_decode_frame(st, data, size[i], pcm + nb_samples * st->channels, frame_size - nb_samples, 0); - if (ret < 0) { - return ret; - } - celt_assert(ret == packet_frame_size); - data += size[i]; - nb_samples += ret; - } - st->last_packet_duration = nb_samples; - if (OPUS_CHECK_ARRAY(pcm, nb_samples * st->channels)) { - OPUS_PRINT_INT(nb_samples); - } -#ifndef FIXED_POINT - if (soft_clip) { - opus_pcm_soft_clip(pcm, nb_samples, st->channels, st->softclip_mem); - } else { - st->softclip_mem[0] = st->softclip_mem[1] = 0; - } -#endif - return nb_samples; -} - -#ifdef FIXED_POINT - -int opus_decode(OpusDecoder *st, const unsigned char *data, - opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec) { - if (frame_size <= 0) { - return OPUS_BAD_ARG; - } - return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0); -} - -#ifndef DISABLE_FLOAT_API -int opus_decode_float(OpusDecoder *st, const unsigned char *data, - opus_int32 len, float *pcm, int frame_size, int decode_fec) { - VARDECL(opus_int16, out); - int ret, i; - int nb_samples; - ALLOC_STACK; - - if (frame_size <= 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - if (data != NULL && len > 0 && !decode_fec) { - nb_samples = opus_decoder_get_nb_samples(st, data, len); - if (nb_samples > 0) { - frame_size = IMIN(frame_size, nb_samples); - } else { - return OPUS_INVALID_PACKET; - } - } - celt_assert(st->channels == 1 || st->channels == 2); - ALLOC(out, frame_size * st->channels, opus_int16); - - ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 0); - if (ret > 0) { - for (i = 0; i < ret * st->channels; i++) { - pcm[i] = (1.f / 32768.f) * (out[i]); - } - } - RESTORE_STACK; - return ret; -} -#endif - - -#else -int opus_decode(OpusDecoder *st, const unsigned char *data, - opus_int32 len, opus_int16 *pcm, int frame_size, int decode_fec) { - VARDECL(float, out); - int ret, i; - int nb_samples; - ALLOC_STACK; - - if (frame_size <= 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - if (data != NULL && len > 0 && !decode_fec) { - nb_samples = opus_decoder_get_nb_samples(st, data, len); - if (nb_samples > 0) { - frame_size = IMIN(frame_size, nb_samples); - } else { - return OPUS_INVALID_PACKET; - } - } - celt_assert(st->channels == 1 || st->channels == 2); - ALLOC(out, frame_size * st->channels, float); - - ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 1); - if (ret > 0) { - for (i = 0; i < ret * st->channels; i++) { - pcm[i] = FLOAT2INT16(out[i]); - } - } - RESTORE_STACK; - return ret; -} - -int opus_decode_float(OpusDecoder *st, const unsigned char *data, - opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec) { - if (frame_size <= 0) { - return OPUS_BAD_ARG; - } - return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0); -} - -#endif - -int opus_decoder_ctl(OpusDecoder *st, int request, ...) { - int ret = OPUS_OK; - va_list ap; - void *silk_dec; - CELTDecoder *celt_dec; - - silk_dec = (char*)st + st->silk_dec_offset; - celt_dec = (CELTDecoder*)((char*)st + st->celt_dec_offset); - - - va_start(ap, request); - - switch (request) { - case OPUS_GET_BANDWIDTH_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->bandwidth; - } - break; - case OPUS_GET_FINAL_RANGE_REQUEST: { - opus_uint32 *value = va_arg(ap, opus_uint32*); - if (!value) { - goto bad_arg; - } - *value = st->rangeFinal; - } - break; - case OPUS_RESET_STATE: { - OPUS_CLEAR((char*)&st->OPUS_DECODER_RESET_START, - sizeof(OpusDecoder) - - ((char*)&st->OPUS_DECODER_RESET_START - (char*)st)); - - celt_decoder_ctl(celt_dec, OPUS_RESET_STATE); - silk_InitDecoder(silk_dec); - st->stream_channels = st->channels; - st->frame_size = st->Fs / 400; - } - break; - case OPUS_GET_SAMPLE_RATE_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->Fs; - } - break; - case OPUS_GET_PITCH_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - if (st->prev_mode == MODE_CELT_ONLY) { - ret = celt_decoder_ctl(celt_dec, OPUS_GET_PITCH(value)); - } else { - *value = st->DecControl.prevPitchLag; - } - } - break; - case OPUS_GET_GAIN_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->decode_gain; - } - break; - case OPUS_SET_GAIN_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < -32768 || value > 32767) { - goto bad_arg; - } - st->decode_gain = value; - } - break; - case OPUS_GET_LAST_PACKET_DURATION_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->last_packet_duration; - } - break; - case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - ret = celt_decoder_ctl(celt_dec, OPUS_SET_PHASE_INVERSION_DISABLED(value)); - } - break; - case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - ret = celt_decoder_ctl(celt_dec, OPUS_GET_PHASE_INVERSION_DISABLED(value)); - } - break; - default: - /*fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);*/ - ret = OPUS_UNIMPLEMENTED; - break; - } - - va_end(ap); - return ret; -bad_arg: - va_end(ap); - return OPUS_BAD_ARG; -} - -void opus_decoder_destroy(OpusDecoder *st) { - opus_free(st); -} - - -int opus_packet_get_bandwidth(const unsigned char *data) { - int bandwidth; - if (data[0] & 0x80) { - bandwidth = OPUS_BANDWIDTH_MEDIUMBAND + ((data[0] >> 5) & 0x3); - if (bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - bandwidth = OPUS_BANDWIDTH_NARROWBAND; - } - } else if ((data[0] & 0x60) == 0x60) { - bandwidth = (data[0] & 0x10) ? OPUS_BANDWIDTH_FULLBAND : - OPUS_BANDWIDTH_SUPERWIDEBAND; - } else { - bandwidth = OPUS_BANDWIDTH_NARROWBAND + ((data[0] >> 5) & 0x3); - } - return bandwidth; -} - -int opus_packet_get_nb_channels(const unsigned char *data) { - return (data[0] & 0x4) ? 2 : 1; -} - -int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) { - int count; - if (len < 1) { - return OPUS_BAD_ARG; - } - count = packet[0] & 0x3; - if (count == 0) { - return 1; - } else if (count != 3) { - return 2; - } else if (len < 2) { - return OPUS_INVALID_PACKET; - } else { - return packet[1] & 0x3F; - } -} - -int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, - opus_int32 Fs) { - int samples; - int count = opus_packet_get_nb_frames(packet, len); - - if (count < 0) { - return count; - } - - samples = count * opus_packet_get_samples_per_frame(packet, Fs); - /* Can't have more than 120 ms */ - if (samples * 25 > Fs * 3) { - return OPUS_INVALID_PACKET; - } else { - return samples; - } -} - -int opus_decoder_get_nb_samples(const OpusDecoder *dec, - const unsigned char packet[], opus_int32 len) { - return opus_packet_get_nb_samples(packet, len, dec->Fs); -} diff --git a/src/libopus/opus_defines.h b/src/libopus/opus_defines.h deleted file mode 100644 index 97f0ba8..0000000 --- a/src/libopus/opus_defines.h +++ /dev/null @@ -1,799 +0,0 @@ -/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited - Written by Jean-Marc Valin and Koen Vos */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - @file opus_defines.h - @brief Opus reference implementation constants -*/ - -#ifndef OPUS_DEFINES_H -#define OPUS_DEFINES_H - -#include "opus_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup opus_errorcodes Error codes - @{ -*/ -/** No error @hideinitializer*/ -#define OPUS_OK 0 -/** One or more invalid/out of range arguments @hideinitializer*/ -#define OPUS_BAD_ARG -1 -/** Not enough bytes allocated in the buffer @hideinitializer*/ -#define OPUS_BUFFER_TOO_SMALL -2 -/** An internal error was detected @hideinitializer*/ -#define OPUS_INTERNAL_ERROR -3 -/** The compressed data passed is corrupted @hideinitializer*/ -#define OPUS_INVALID_PACKET -4 -/** Invalid/unsupported request number @hideinitializer*/ -#define OPUS_UNIMPLEMENTED -5 -/** An encoder or decoder structure is invalid or already freed @hideinitializer*/ -#define OPUS_INVALID_STATE -6 -/** Memory allocation has failed @hideinitializer*/ -#define OPUS_ALLOC_FAIL -7 -/**@}*/ - -/** @cond OPUS_INTERNAL_DOC */ -/**Export control for opus functions */ - -#ifndef OPUS_EXPORT -# if defined(WIN32) -# if defined(OPUS_BUILD) && defined(DLL_EXPORT) -# define OPUS_EXPORT __declspec(dllexport) -# else -# define OPUS_EXPORT -# endif -# elif defined(__GNUC__) && defined(OPUS_BUILD) -# define OPUS_EXPORT __attribute__ ((visibility ("default"))) -# else -# define OPUS_EXPORT -# endif -#endif - -# if !defined(OPUS_GNUC_PREREQ) -# if defined(__GNUC__)&&defined(__GNUC_MINOR__) -# define OPUS_GNUC_PREREQ(_maj,_min) \ - ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) -# else -# define OPUS_GNUC_PREREQ(_maj,_min) 0 -# endif -# endif - -#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) -# if OPUS_GNUC_PREREQ(3,0) -# define OPUS_RESTRICT __restrict__ -# elif (defined(_MSC_VER) && _MSC_VER >= 1400) -# define OPUS_RESTRICT __restrict -# else -# define OPUS_RESTRICT -# endif -#else -# define OPUS_RESTRICT restrict -#endif - -#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) -# if OPUS_GNUC_PREREQ(2,7) -# define OPUS_INLINE __inline__ -# elif (defined(_MSC_VER)) -# define OPUS_INLINE __inline -# else -# define OPUS_INLINE -# endif -#else -# define OPUS_INLINE inline -#endif - -/** Warning attributes for opus functions - NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out - some paranoid null checks. */ -#if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) -# define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) -#else -# define OPUS_WARN_UNUSED_RESULT -#endif -#if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) -# define OPUS_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x))) -#else -# define OPUS_ARG_NONNULL(_x) -#endif - -/** These are the actual Encoder CTL ID numbers. - They should not be used directly by applications. - In general, SETs should be even and GETs should be odd.*/ -#define OPUS_SET_APPLICATION_REQUEST 4000 -#define OPUS_GET_APPLICATION_REQUEST 4001 -#define OPUS_SET_BITRATE_REQUEST 4002 -#define OPUS_GET_BITRATE_REQUEST 4003 -#define OPUS_SET_MAX_BANDWIDTH_REQUEST 4004 -#define OPUS_GET_MAX_BANDWIDTH_REQUEST 4005 -#define OPUS_SET_VBR_REQUEST 4006 -#define OPUS_GET_VBR_REQUEST 4007 -#define OPUS_SET_BANDWIDTH_REQUEST 4008 -#define OPUS_GET_BANDWIDTH_REQUEST 4009 -#define OPUS_SET_COMPLEXITY_REQUEST 4010 -#define OPUS_GET_COMPLEXITY_REQUEST 4011 -#define OPUS_SET_INBAND_FEC_REQUEST 4012 -#define OPUS_GET_INBAND_FEC_REQUEST 4013 -#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014 -#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015 -#define OPUS_SET_DTX_REQUEST 4016 -#define OPUS_GET_DTX_REQUEST 4017 -#define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020 -#define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021 -#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022 -#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023 -#define OPUS_SET_SIGNAL_REQUEST 4024 -#define OPUS_GET_SIGNAL_REQUEST 4025 -#define OPUS_GET_LOOKAHEAD_REQUEST 4027 -/* #define OPUS_RESET_STATE 4028 */ -#define OPUS_GET_SAMPLE_RATE_REQUEST 4029 -#define OPUS_GET_FINAL_RANGE_REQUEST 4031 -#define OPUS_GET_PITCH_REQUEST 4033 -#define OPUS_SET_GAIN_REQUEST 4034 -#define OPUS_GET_GAIN_REQUEST 4045 /* Should have been 4035 */ -#define OPUS_SET_LSB_DEPTH_REQUEST 4036 -#define OPUS_GET_LSB_DEPTH_REQUEST 4037 -#define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039 -#define OPUS_SET_EXPERT_FRAME_DURATION_REQUEST 4040 -#define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041 -#define OPUS_SET_PREDICTION_DISABLED_REQUEST 4042 -#define OPUS_GET_PREDICTION_DISABLED_REQUEST 4043 -/* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */ -#define OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST 4046 -#define OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST 4047 -#define OPUS_GET_IN_DTX_REQUEST 4049 - -/** Defines for the presence of extended APIs. */ -#define OPUS_HAVE_OPUS_PROJECTION_H - -/* Macros to trigger compilation errors when the wrong types are provided to a CTL */ -#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x)) -#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr))) -#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr))) -#define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr))) -/** @endcond */ - -/** @defgroup opus_ctlvalues Pre-defined values for CTL interface - @see opus_genericctls, opus_encoderctls - @{ -*/ -/* Values for the various encoder CTLs */ -#define OPUS_AUTO -1000 /**opus_int32: Allowed values: 0-10, inclusive. - - @hideinitializer */ -#define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x) -/** Gets the encoder's complexity configuration. - @see OPUS_SET_COMPLEXITY - @param[out] x opus_int32 *: Returns a value in the range 0-10, - inclusive. - @hideinitializer */ -#define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x) - -/** Configures the bitrate in the encoder. - Rates from 500 to 512000 bits per second are meaningful, as well as the - special values #OPUS_AUTO and #OPUS_BITRATE_MAX. - The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much - rate as it can, which is useful for controlling the rate by adjusting the - output buffer size. - @see OPUS_GET_BITRATE - @param[in] x opus_int32: Bitrate in bits per second. The default - is determined based on the number of - channels and the input sampling rate. - @hideinitializer */ -#define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x) -/** Gets the encoder's bitrate configuration. - @see OPUS_SET_BITRATE - @param[out] x opus_int32 *: Returns the bitrate in bits per second. - The default is determined based on the - number of channels and the input - sampling rate. - @hideinitializer */ -#define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x) - -/** Enables or disables variable bitrate (VBR) in the encoder. - The configured bitrate may not be met exactly because frames must - be an integer number of bytes in length. - @see OPUS_GET_VBR - @see OPUS_SET_VBR_CONSTRAINT - @param[in] x opus_int32: Allowed values: -
-
0
Hard CBR. For LPC/hybrid modes at very low bit-rate, this can - cause noticeable quality degradation.
-
1
VBR (default). The exact type of VBR is controlled by - #OPUS_SET_VBR_CONSTRAINT.
-
- @hideinitializer */ -#define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x) -/** Determine if variable bitrate (VBR) is enabled in the encoder. - @see OPUS_SET_VBR - @see OPUS_GET_VBR_CONSTRAINT - @param[out] x opus_int32 *: Returns one of the following values: -
-
0
Hard CBR.
-
1
VBR (default). The exact type of VBR may be retrieved via - #OPUS_GET_VBR_CONSTRAINT.
-
- @hideinitializer */ -#define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x) - -/** Enables or disables constrained VBR in the encoder. - This setting is ignored when the encoder is in CBR mode. - @warning Only the MDCT mode of Opus currently heeds the constraint. - Speech mode ignores it completely, hybrid mode may fail to obey it - if the LPC layer uses more bitrate than the constraint would have - permitted. - @see OPUS_GET_VBR_CONSTRAINT - @see OPUS_SET_VBR - @param[in] x opus_int32: Allowed values: -
-
0
Unconstrained VBR.
-
1
Constrained VBR (default). This creates a maximum of one - frame of buffering delay assuming a transport with a - serialization speed of the nominal bitrate.
-
- @hideinitializer */ -#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x) -/** Determine if constrained VBR is enabled in the encoder. - @see OPUS_SET_VBR_CONSTRAINT - @see OPUS_GET_VBR - @param[out] x opus_int32 *: Returns one of the following values: -
-
0
Unconstrained VBR.
-
1
Constrained VBR (default).
-
- @hideinitializer */ -#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x) - -/** Configures mono/stereo forcing in the encoder. - This can force the encoder to produce packets encoded as either mono or - stereo, regardless of the format of the input audio. This is useful when - the caller knows that the input signal is currently a mono source embedded - in a stereo stream. - @see OPUS_GET_FORCE_CHANNELS - @param[in] x opus_int32: Allowed values: -
-
#OPUS_AUTO
Not forced (default)
-
1
Forced mono
-
2
Forced stereo
-
- @hideinitializer */ -#define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x) -/** Gets the encoder's forced channel configuration. - @see OPUS_SET_FORCE_CHANNELS - @param[out] x opus_int32 *: -
-
#OPUS_AUTO
Not forced (default)
-
1
Forced mono
-
2
Forced stereo
-
- @hideinitializer */ -#define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x) - -/** Configures the maximum bandpass that the encoder will select automatically. - Applications should normally use this instead of #OPUS_SET_BANDWIDTH - (leaving that set to the default, #OPUS_AUTO). This allows the - application to set an upper bound based on the type of input it is - providing, but still gives the encoder the freedom to reduce the bandpass - when the bitrate becomes too low, for better overall quality. - @see OPUS_GET_MAX_BANDWIDTH - @param[in] x opus_int32: Allowed values: -
-
OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
-
OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
-
OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
-
OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
-
OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
-
- @hideinitializer */ -#define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x) - -/** Gets the encoder's configured maximum allowed bandpass. - @see OPUS_SET_MAX_BANDWIDTH - @param[out] x opus_int32 *: Allowed values: -
-
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
-
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
-
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
-
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
-
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
-
- @hideinitializer */ -#define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) - -/** Sets the encoder's bandpass to a specific value. - This prevents the encoder from automatically selecting the bandpass based - on the available bitrate. If an application knows the bandpass of the input - audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH - instead, which still gives the encoder the freedom to reduce the bandpass - when the bitrate becomes too low, for better overall quality. - @see OPUS_GET_BANDWIDTH - @param[in] x opus_int32: Allowed values: -
-
#OPUS_AUTO
(default)
-
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
-
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
-
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
-
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
-
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
-
- @hideinitializer */ -#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x) - -/** Configures the type of signal being encoded. - This is a hint which helps the encoder's mode selection. - @see OPUS_GET_SIGNAL - @param[in] x opus_int32: Allowed values: -
-
#OPUS_AUTO
(default)
-
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
-
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
-
- @hideinitializer */ -#define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured signal type. - @see OPUS_SET_SIGNAL - @param[out] x opus_int32 *: Returns one of the following values: -
-
#OPUS_AUTO
(default)
-
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
-
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
-
- @hideinitializer */ -#define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x) - - -/** Configures the encoder's intended application. - The initial value is a mandatory argument to the encoder_create function. - @see OPUS_GET_APPLICATION - @param[in] x opus_int32: Returns one of the following values: -
-
#OPUS_APPLICATION_VOIP
-
Process signal for improved speech intelligibility.
-
#OPUS_APPLICATION_AUDIO
-
Favor faithfulness to the original input.
-
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
-
Configure the minimum possible coding delay by disabling certain modes - of operation.
-
- @hideinitializer */ -#define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured application. - @see OPUS_SET_APPLICATION - @param[out] x opus_int32 *: Returns one of the following values: -
-
#OPUS_APPLICATION_VOIP
-
Process signal for improved speech intelligibility.
-
#OPUS_APPLICATION_AUDIO
-
Favor faithfulness to the original input.
-
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
-
Configure the minimum possible coding delay by disabling certain modes - of operation.
-
- @hideinitializer */ -#define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x) - -/** Gets the total samples of delay added by the entire codec. - This can be queried by the encoder and then the provided number of samples can be - skipped on from the start of the decoder's output to provide time aligned input - and output. From the perspective of a decoding application the real data begins this many - samples late. - - The decoder contribution to this delay is identical for all decoders, but the - encoder portion of the delay may vary from implementation to implementation, - version to version, or even depend on the encoder's initial configuration. - Applications needing delay compensation should call this CTL rather than - hard-coding a value. - @param[out] x opus_int32 *: Number of lookahead samples - @hideinitializer */ -#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's use of inband forward error correction (FEC). - @note This is only applicable to the LPC layer - @see OPUS_GET_INBAND_FEC - @param[in] x opus_int32: Allowed values: -
-
0
Disable inband FEC (default).
-
1
Enable inband FEC.
-
- @hideinitializer */ -#define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x) -/** Gets encoder's configured use of inband forward error correction. - @see OPUS_SET_INBAND_FEC - @param[out] x opus_int32 *: Returns one of the following values: -
-
0
Inband FEC disabled (default).
-
1
Inband FEC enabled.
-
- @hideinitializer */ -#define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's expected packet loss percentage. - Higher values trigger progressively more loss resistant behavior in the encoder - at the expense of quality at a given bitrate in the absence of packet loss, but - greater quality under loss. - @see OPUS_GET_PACKET_LOSS_PERC - @param[in] x opus_int32: Loss percentage in the range 0-100, inclusive (default: 0). - @hideinitializer */ -#define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured packet loss percentage. - @see OPUS_SET_PACKET_LOSS_PERC - @param[out] x opus_int32 *: Returns the configured loss percentage - in the range 0-100, inclusive (default: 0). - @hideinitializer */ -#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's use of discontinuous transmission (DTX). - @note This is only applicable to the LPC layer - @see OPUS_GET_DTX - @param[in] x opus_int32: Allowed values: -
-
0
Disable DTX (default).
-
1
Enabled DTX.
-
- @hideinitializer */ -#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x) -/** Gets encoder's configured use of discontinuous transmission. - @see OPUS_SET_DTX - @param[out] x opus_int32 *: Returns one of the following values: -
-
0
DTX disabled (default).
-
1
DTX enabled.
-
- @hideinitializer */ -#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x) -/** Configures the depth of signal being encoded. - - This is a hint which helps the encoder identify silence and near-silence. - It represents the number of significant bits of linear intensity below - which the signal contains ignorable quantization or other noise. - - For example, OPUS_SET_LSB_DEPTH(14) would be an appropriate setting - for G.711 u-law input. OPUS_SET_LSB_DEPTH(16) would be appropriate - for 16-bit linear pcm input with opus_encode_float(). - - When using opus_encode() instead of opus_encode_float(), or when libopus - is compiled for fixed-point, the encoder uses the minimum of the value - set here and the value 16. - - @see OPUS_GET_LSB_DEPTH - @param[in] x opus_int32: Input precision in bits, between 8 and 24 - (default: 24). - @hideinitializer */ -#define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured signal depth. - @see OPUS_SET_LSB_DEPTH - @param[out] x opus_int32 *: Input precision in bits, between 8 and - 24 (default: 24). - @hideinitializer */ -#define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's use of variable duration frames. - When variable duration is enabled, the encoder is free to use a shorter frame - size than the one requested in the opus_encode*() call. - It is then the user's responsibility - to verify how much audio was encoded by checking the ToC byte of the encoded - packet. The part of the audio that was not encoded needs to be resent to the - encoder for the next call. Do not use this option unless you really - know what you are doing. - @see OPUS_GET_EXPERT_FRAME_DURATION - @param[in] x opus_int32: Allowed values: -
-
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
-
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
-
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
-
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
-
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
-
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
-
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
-
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
-
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
-
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
-
- @hideinitializer */ -#define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured use of variable duration frames. - @see OPUS_SET_EXPERT_FRAME_DURATION - @param[out] x opus_int32 *: Returns one of the following values: -
-
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
-
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
-
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
-
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
-
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
-
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
-
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
-
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
-
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
-
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
-
- @hideinitializer */ -#define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x) - -/** If set to 1, disables almost all use of prediction, making frames almost - completely independent. This reduces quality. - @see OPUS_GET_PREDICTION_DISABLED - @param[in] x opus_int32: Allowed values: -
-
0
Enable prediction (default).
-
1
Disable prediction.
-
- @hideinitializer */ -#define OPUS_SET_PREDICTION_DISABLED(x) OPUS_SET_PREDICTION_DISABLED_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured prediction status. - @see OPUS_SET_PREDICTION_DISABLED - @param[out] x opus_int32 *: Returns one of the following values: -
-
0
Prediction enabled (default).
-
1
Prediction disabled.
-
- @hideinitializer */ -#define OPUS_GET_PREDICTION_DISABLED(x) OPUS_GET_PREDICTION_DISABLED_REQUEST, __opus_check_int_ptr(x) - -/**@}*/ - -/** @defgroup opus_genericctls Generic CTLs - - These macros are used with the \c opus_decoder_ctl and - \c opus_encoder_ctl calls to generate a particular - request. - - When called on an \c OpusDecoder they apply to that - particular decoder instance. When called on an - \c OpusEncoder they apply to the corresponding setting - on that encoder instance, if present. - - Some usage examples: - - @code - int ret; - opus_int32 pitch; - ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch)); - if (ret == OPUS_OK) return ret; - - opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); - opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE); - - opus_int32 enc_bw, dec_bw; - opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw)); - opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw)); - if (enc_bw != dec_bw) { - printf("packet bandwidth mismatch!\n"); - } - @endcode - - @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls - @{ -*/ - -/** Resets the codec state to be equivalent to a freshly initialized state. - This should be called when switching streams in order to prevent - the back to back decoding from giving different results from - one at a time decoding. - @hideinitializer */ -#define OPUS_RESET_STATE 4028 - -/** Gets the final state of the codec's entropy coder. - This is used for testing purposes, - The encoder and decoder state should be identical after coding a payload - (assuming no data corruption or software bugs) - - @param[out] x opus_uint32 *: Entropy coder state - - @hideinitializer */ -#define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x) - -/** Gets the encoder's configured bandpass or the decoder's last bandpass. - @see OPUS_SET_BANDWIDTH - @param[out] x opus_int32 *: Returns one of the following values: -
-
#OPUS_AUTO
(default)
-
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
-
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
-
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
-
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
-
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
-
- @hideinitializer */ -#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) - -/** Gets the sampling rate the encoder or decoder was initialized with. - This simply returns the Fs value passed to opus_encoder_init() - or opus_decoder_init(). - @param[out] x opus_int32 *: Sampling rate of encoder or decoder. - @hideinitializer -*/ -#define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x) - -/** If set to 1, disables the use of phase inversion for intensity stereo, - improving the quality of mono downmixes, but slightly reducing normal - stereo quality. Disabling phase inversion in the decoder does not comply - with RFC 6716, although it does not cause any interoperability issue and - is expected to become part of the Opus standard once RFC 6716 is updated - by draft-ietf-codec-opus-update. - @see OPUS_GET_PHASE_INVERSION_DISABLED - @param[in] x opus_int32: Allowed values: -
-
0
Enable phase inversion (default).
-
1
Disable phase inversion.
-
- @hideinitializer */ -#define OPUS_SET_PHASE_INVERSION_DISABLED(x) OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured phase inversion status. - @see OPUS_SET_PHASE_INVERSION_DISABLED - @param[out] x opus_int32 *: Returns one of the following values: -
-
0
Stereo phase inversion enabled (default).
-
1
Stereo phase inversion disabled.
-
- @hideinitializer */ -#define OPUS_GET_PHASE_INVERSION_DISABLED(x) OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int_ptr(x) -/** Gets the DTX state of the encoder. - Returns whether the last encoded frame was either a comfort noise update - during DTX or not encoded because of DTX. - @param[out] x opus_int32 *: Returns one of the following values: -
-
0
The encoder is not in DTX.
-
1
The encoder is in DTX.
-
- @hideinitializer */ -#define OPUS_GET_IN_DTX(x) OPUS_GET_IN_DTX_REQUEST, __opus_check_int_ptr(x) - -/**@}*/ - -/** @defgroup opus_decoderctls Decoder related CTLs - @see opus_genericctls, opus_encoderctls, opus_decoder - @{ -*/ - -/** Configures decoder gain adjustment. - Scales the decoded output by a factor specified in Q8 dB units. - This has a maximum range of -32768 to 32767 inclusive, and returns - OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment. - This setting survives decoder reset. - - gain = pow(10, x/(20.0*256)) - - @param[in] x opus_int32: Amount to scale PCM signal by in Q8 dB units. - @hideinitializer */ -#define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x) -/** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN - - @param[out] x opus_int32 *: Amount to scale PCM signal by in Q8 dB units. - @hideinitializer */ -#define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x) - -/** Gets the duration (in samples) of the last packet successfully decoded or concealed. - @param[out] x opus_int32 *: Number of samples (at current sampling rate). - @hideinitializer */ -#define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x) - -/** Gets the pitch of the last decoded frame, if available. - This can be used for any post-processing algorithm requiring the use of pitch, - e.g. time stretching/shortening. If the last frame was not voiced, or if the - pitch was not coded in the frame, then zero is returned. - - This CTL is only implemented for decoder instances. - - @param[out] x opus_int32 *: pitch period at 48 kHz (or 0 if not available) - - @hideinitializer */ -#define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x) - -/**@}*/ - -/** @defgroup opus_libinfo Opus library information functions - @{ -*/ - -/** Converts an opus error code into a human readable string. - - @param[in] error int: Error number - @returns Error string -*/ -OPUS_EXPORT const char *opus_strerror(int error); - -/** Gets the libopus version string. - - Applications may look for the substring "-fixed" in the version string to - determine whether they have a fixed-point or floating-point build at - runtime. - - @returns Version string -*/ -OPUS_EXPORT const char *opus_get_version_string(void); -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_DEFINES_H */ diff --git a/src/libopus/opus_encoder.c b/src/libopus/opus_encoder.c deleted file mode 100644 index 96ff8d1..0000000 --- a/src/libopus/opus_encoder.c +++ /dev/null @@ -1,2656 +0,0 @@ -/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited - Written by Jean-Marc Valin and Koen Vos */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#if 0 -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include -#include "celt/celt.h" -#include "celt/entenc.h" -#include "celt/modes.h" -#include "silk/API.h" -#include "celt/stack_alloc.h" -#include "celt/float_cast.h" -#include "opus.h" -#include "celt/arch.h" -#include "celt/pitch.h" -#include "opus_private.h" -#include "celt/os_support.h" -#include "celt/cpu_support.h" -#include "analysis.h" -#include "celt/mathops.h" -#include "silk/tuning_parameters.h" -#ifdef FIXED_POINT -#include "silk/fixed/structs_FIX.h" -#else -#include "silk/float/structs_FLP.h" -#endif - -#define MAX_ENCODER_BUFFER 480 - -#ifndef DISABLE_FLOAT_API -#define PSEUDO_SNR_THRESHOLD 316.23f /* 10^(25/10) */ -#endif - -typedef struct { - opus_val32 XX, XY, YY; - opus_val16 smoothed_width; - opus_val16 max_follower; -} StereoWidthState; - -struct OpusEncoder { - int celt_enc_offset; - int silk_enc_offset; - silk_EncControlStruct silk_mode; - int application; - int channels; - int delay_compensation; - int force_channels; - int signal_type; - int user_bandwidth; - int max_bandwidth; - int user_forced_mode; - int voice_ratio; - opus_int32 Fs; - int use_vbr; - int vbr_constraint; - int variable_duration; - opus_int32 bitrate_bps; - opus_int32 user_bitrate_bps; - int lsb_depth; - int encoder_buffer; - int lfe; - int arch; - int use_dtx; /* general DTX for both SILK and CELT */ -#ifndef DISABLE_FLOAT_API - TonalityAnalysisState analysis; -#endif - -#define OPUS_ENCODER_RESET_START stream_channels - int stream_channels; - opus_int16 hybrid_stereo_width_Q14; - opus_int32 variable_HP_smth2_Q15; - opus_val16 prev_HB_gain; - opus_val32 hp_mem[4]; - int mode; - int prev_mode; - int prev_channels; - int prev_framesize; - int bandwidth; - /* Bandwidth determined automatically from the rate (before any other adjustment) */ - int auto_bandwidth; - int silk_bw_switch; - /* Sampling rate (at the API level) */ - int first; - opus_val16 * energy_masking; - StereoWidthState width_mem; - opus_val16 delay_buffer[MAX_ENCODER_BUFFER * 2]; -#ifndef DISABLE_FLOAT_API - int detected_bandwidth; - int nb_no_activity_frames; - opus_val32 peak_signal_energy; -#endif - int nonfinal_frame; /* current frame is not the final in a packet */ - opus_uint32 rangeFinal; -}; - -/* Transition tables for the voice and music. First column is the - middle (memoriless) threshold. The second column is the hysteresis - (difference with the middle) */ -static const opus_int32 mono_voice_bandwidth_thresholds[8] = { - 9000, 700, /* NB<->MB */ - 9000, 700, /* MB<->WB */ - 13500, 1000, /* WB<->SWB */ - 14000, 2000, /* SWB<->FB */ -}; -static const opus_int32 mono_music_bandwidth_thresholds[8] = { - 9000, 700, /* NB<->MB */ - 9000, 700, /* MB<->WB */ - 11000, 1000, /* WB<->SWB */ - 12000, 2000, /* SWB<->FB */ -}; -static const opus_int32 stereo_voice_bandwidth_thresholds[8] = { - 9000, 700, /* NB<->MB */ - 9000, 700, /* MB<->WB */ - 13500, 1000, /* WB<->SWB */ - 14000, 2000, /* SWB<->FB */ -}; -static const opus_int32 stereo_music_bandwidth_thresholds[8] = { - 9000, 700, /* NB<->MB */ - 9000, 700, /* MB<->WB */ - 11000, 1000, /* WB<->SWB */ - 12000, 2000, /* SWB<->FB */ -}; -/* Threshold bit-rates for switching between mono and stereo */ -static const opus_int32 stereo_voice_threshold = 19000; -static const opus_int32 stereo_music_threshold = 17000; - -/* Threshold bit-rate for switching between SILK/hybrid and CELT-only */ -static const opus_int32 mode_thresholds[2][2] = { - /* voice */ /* music */ - { 64000, 10000}, /* mono */ - { 44000, 10000}, /* stereo */ -}; - -static const opus_int32 fec_thresholds[] = { - 12000, 1000, /* NB */ - 14000, 1000, /* MB */ - 16000, 1000, /* WB */ - 20000, 1000, /* SWB */ - 22000, 1000, /* FB */ -}; - -int opus_encoder_get_size(int channels) { - int silkEncSizeBytes, celtEncSizeBytes; - int ret; - if (channels < 1 || channels > 2) { - return 0; - } - ret = silk_Get_Encoder_Size(&silkEncSizeBytes); - if (ret) { - return 0; - } - silkEncSizeBytes = align(silkEncSizeBytes); - celtEncSizeBytes = celt_encoder_get_size(channels); - return align(sizeof(OpusEncoder)) + silkEncSizeBytes + celtEncSizeBytes; -} - -int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int application) { - void *silk_enc; - CELTEncoder *celt_enc; - int err; - int ret, silkEncSizeBytes; - - if ((Fs != 48000 && Fs != 24000 && Fs != 16000 && Fs != 12000 && Fs != 8000) || (channels != 1 && channels != 2) || - (application != OPUS_APPLICATION_VOIP && application != OPUS_APPLICATION_AUDIO - && application != OPUS_APPLICATION_RESTRICTED_LOWDELAY)) { - return OPUS_BAD_ARG; - } - - OPUS_CLEAR((char*)st, opus_encoder_get_size(channels)); - /* Create SILK encoder */ - ret = silk_Get_Encoder_Size(&silkEncSizeBytes); - if (ret) { - return OPUS_BAD_ARG; - } - silkEncSizeBytes = align(silkEncSizeBytes); - st->silk_enc_offset = align(sizeof(OpusEncoder)); - st->celt_enc_offset = st->silk_enc_offset + silkEncSizeBytes; - silk_enc = (char*)st + st->silk_enc_offset; - celt_enc = (CELTEncoder*)((char*)st + st->celt_enc_offset); - - st->stream_channels = st->channels = channels; - - st->Fs = Fs; - - st->arch = opus_select_arch(); - - ret = silk_InitEncoder(silk_enc, st->arch, &st->silk_mode); - if (ret) { - return OPUS_INTERNAL_ERROR; - } - - /* default SILK parameters */ - st->silk_mode.nChannelsAPI = channels; - st->silk_mode.nChannelsInternal = channels; - st->silk_mode.API_sampleRate = st->Fs; - st->silk_mode.maxInternalSampleRate = 16000; - st->silk_mode.minInternalSampleRate = 8000; - st->silk_mode.desiredInternalSampleRate = 16000; - st->silk_mode.payloadSize_ms = 20; - st->silk_mode.bitRate = 25000; - st->silk_mode.packetLossPercentage = 0; - st->silk_mode.complexity = 9; - st->silk_mode.useInBandFEC = 0; - st->silk_mode.useDTX = 0; - st->silk_mode.useCBR = 0; - st->silk_mode.reducedDependency = 0; - - /* Create CELT encoder */ - /* Initialize CELT encoder */ - err = celt_encoder_init(celt_enc, Fs, channels, st->arch); - if (err != OPUS_OK) { - return OPUS_INTERNAL_ERROR; - } - - celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0)); - celt_encoder_ctl(celt_enc, OPUS_SET_COMPLEXITY(st->silk_mode.complexity)); - - st->use_vbr = 1; - /* Makes constrained VBR the default (safer for real-time use) */ - st->vbr_constraint = 1; - st->user_bitrate_bps = OPUS_AUTO; - st->bitrate_bps = 3000 + Fs * channels; - st->application = application; - st->signal_type = OPUS_AUTO; - st->user_bandwidth = OPUS_AUTO; - st->max_bandwidth = OPUS_BANDWIDTH_FULLBAND; - st->force_channels = OPUS_AUTO; - st->user_forced_mode = OPUS_AUTO; - st->voice_ratio = -1; - st->encoder_buffer = st->Fs / 100; - st->lsb_depth = 24; - st->variable_duration = OPUS_FRAMESIZE_ARG; - - /* Delay compensation of 4 ms (2.5 ms for SILK's extra look-ahead - + 1.5 ms for SILK resamplers and stereo prediction) */ - st->delay_compensation = st->Fs / 250; - - st->hybrid_stereo_width_Q14 = 1 << 14; - st->prev_HB_gain = Q15ONE; - st->variable_HP_smth2_Q15 = silk_LSHIFT(silk_lin2log(VARIABLE_HP_MIN_CUTOFF_HZ), 8); - st->first = 1; - st->mode = MODE_HYBRID; - st->bandwidth = OPUS_BANDWIDTH_FULLBAND; - -#ifndef DISABLE_FLOAT_API - tonality_analysis_init(&st->analysis, st->Fs); - st->analysis.application = st->application; -#endif - - return OPUS_OK; -} - -static unsigned char gen_toc(int mode, int framerate, int bandwidth, int channels) { - int period; - unsigned char toc; - period = 0; - while (framerate < 400) { - framerate <<= 1; - period++; - } - if (mode == MODE_SILK_ONLY) { - toc = (bandwidth - OPUS_BANDWIDTH_NARROWBAND) << 5; - toc |= (period - 2) << 3; - } else if (mode == MODE_CELT_ONLY) { - int tmp = bandwidth - OPUS_BANDWIDTH_MEDIUMBAND; - if (tmp < 0) { - tmp = 0; - } - toc = 0x80; - toc |= tmp << 5; - toc |= period << 3; - } else { /* Hybrid */ - toc = 0x60; - toc |= (bandwidth - OPUS_BANDWIDTH_SUPERWIDEBAND) << 4; - toc |= (period - 2) << 3; - } - toc |= (channels == 2) << 2; - return toc; -} - -#ifndef FIXED_POINT -static void silk_biquad_float( - const opus_val16 *in, /* I: Input signal */ - const opus_int32 *B_Q28, /* I: MA coefficients [3] */ - const opus_int32 *A_Q28, /* I: AR coefficients [2] */ - opus_val32 *S, /* I/O: State vector [2] */ - opus_val16 *out, /* O: Output signal */ - const opus_int32 len, /* I: Signal length (must be even) */ - int stride -) { - /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ - opus_int k; - opus_val32 vout; - opus_val32 inval; - opus_val32 A[2], B[3]; - - A[0] = (opus_val32)(A_Q28[0] * (1.f / ((opus_int32)1 << 28))); - A[1] = (opus_val32)(A_Q28[1] * (1.f / ((opus_int32)1 << 28))); - B[0] = (opus_val32)(B_Q28[0] * (1.f / ((opus_int32)1 << 28))); - B[1] = (opus_val32)(B_Q28[1] * (1.f / ((opus_int32)1 << 28))); - B[2] = (opus_val32)(B_Q28[2] * (1.f / ((opus_int32)1 << 28))); - - /* Negate A_Q28 values and split in two parts */ - - for (k = 0; k < len; k++) { - /* S[ 0 ], S[ 1 ]: Q12 */ - inval = in[ k * stride ]; - vout = S[ 0 ] + B[0] * inval; - - S[ 0 ] = S[1] - vout * A[0] + B[1] * inval; - - S[ 1 ] = - vout * A[1] + B[2] * inval + VERY_SMALL; - - /* Scale back to Q0 and saturate */ - out[ k * stride ] = vout; - } -} -#endif - -static void hp_cutoff(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *out, opus_val32 *hp_mem, int len, int channels, opus_int32 Fs, int arch) { - opus_int32 B_Q28[ 3 ], A_Q28[ 2 ]; - opus_int32 Fc_Q19, r_Q28, r_Q22; - (void)arch; - - silk_assert(cutoff_Hz <= silk_int32_MAX / SILK_FIX_CONST(1.5 * 3.14159 / 1000, 19)); - Fc_Q19 = silk_DIV32_16(silk_SMULBB(SILK_FIX_CONST(1.5 * 3.14159 / 1000, 19), cutoff_Hz), Fs / 1000); - silk_assert(Fc_Q19 > 0 && Fc_Q19 < 32768); - - r_Q28 = SILK_FIX_CONST(1.0, 28) - silk_MUL(SILK_FIX_CONST(0.92, 9), Fc_Q19); - - /* b = r * [ 1; -2; 1 ]; */ - /* a = [ 1; -2 * r * ( 1 - 0.5 * Fc^2 ); r^2 ]; */ - B_Q28[ 0 ] = r_Q28; - B_Q28[ 1 ] = silk_LSHIFT(-r_Q28, 1); - B_Q28[ 2 ] = r_Q28; - - /* -r * ( 2 - Fc * Fc ); */ - r_Q22 = silk_RSHIFT(r_Q28, 6); - A_Q28[ 0 ] = silk_SMULWW(r_Q22, silk_SMULWW(Fc_Q19, Fc_Q19) - SILK_FIX_CONST(2.0, 22)); - A_Q28[ 1 ] = silk_SMULWW(r_Q22, r_Q22); - -#ifdef FIXED_POINT - if (channels == 1) { - silk_biquad_alt_stride1(in, B_Q28, A_Q28, hp_mem, out, len); - } else { - silk_biquad_alt_stride2(in, B_Q28, A_Q28, hp_mem, out, len, arch); - } -#else - silk_biquad_float(in, B_Q28, A_Q28, hp_mem, out, len, channels); - if (channels == 2) { - silk_biquad_float(in + 1, B_Q28, A_Q28, hp_mem + 2, out + 1, len, channels); - } -#endif -} - -#ifdef FIXED_POINT -static void dc_reject(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *out, opus_val32 *hp_mem, int len, int channels, opus_int32 Fs) { - int c, i; - int shift; - - /* Approximates -round(log2(6.3*cutoff_Hz/Fs)) */ - shift = celt_ilog2(Fs / (cutoff_Hz * 4)); - for (c = 0; c < channels; c++) { - for (i = 0; i < len; i++) { - opus_val32 x, y; - x = SHL32(EXTEND32(in[channels * i + c]), 14); - y = x - hp_mem[2 * c]; - hp_mem[2 * c] = hp_mem[2 * c] + PSHR32(x - hp_mem[2 * c], shift); - out[channels * i + c] = EXTRACT16(SATURATE(PSHR32(y, 14), 32767)); - } - } -} - -#else -static void dc_reject(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *out, opus_val32 *hp_mem, int len, int channels, opus_int32 Fs) { - int i; - float coef, coef2; - coef = 6.3f * cutoff_Hz / Fs; - coef2 = 1 - coef; - if (channels == 2) { - float m0, m2; - m0 = hp_mem[0]; - m2 = hp_mem[2]; - for (i = 0; i < len; i++) { - opus_val32 x0, x1, out0, out1; - x0 = in[2 * i + 0]; - x1 = in[2 * i + 1]; - out0 = x0 - m0; - out1 = x1 - m2; - m0 = coef * x0 + VERY_SMALL + coef2 * m0; - m2 = coef * x1 + VERY_SMALL + coef2 * m2; - out[2 * i + 0] = out0; - out[2 * i + 1] = out1; - } - hp_mem[0] = m0; - hp_mem[2] = m2; - } else { - float m0; - m0 = hp_mem[0]; - for (i = 0; i < len; i++) { - opus_val32 x, y; - x = in[i]; - y = x - m0; - m0 = coef * x + VERY_SMALL + coef2 * m0; - out[i] = y; - } - hp_mem[0] = m0; - } -} -#endif - -static void stereo_fade(const opus_val16 *in, opus_val16 *out, opus_val16 g1, opus_val16 g2, - int overlap48, int frame_size, int channels, const opus_val16 *window, opus_int32 Fs) { - int i; - int overlap; - int inc; - inc = 48000 / Fs; - overlap = overlap48 / inc; - g1 = Q15ONE - g1; - g2 = Q15ONE - g2; - for (i = 0; i < overlap; i++) { - opus_val32 diff; - opus_val16 g, w; - w = MULT16_16_Q15(window[i * inc], window[i * inc]); - g = SHR32(MAC16_16(MULT16_16(w, g2), - Q15ONE - w, g1), 15); - diff = EXTRACT16(HALF32((opus_val32)in[i * channels] - (opus_val32)in[i * channels + 1])); - diff = MULT16_16_Q15(g, diff); - out[i * channels] = out[i * channels] - diff; - out[i * channels + 1] = out[i * channels + 1] + diff; - } - for (; i < frame_size; i++) { - opus_val32 diff; - diff = EXTRACT16(HALF32((opus_val32)in[i * channels] - (opus_val32)in[i * channels + 1])); - diff = MULT16_16_Q15(g2, diff); - out[i * channels] = out[i * channels] - diff; - out[i * channels + 1] = out[i * channels + 1] + diff; - } -} - -static void gain_fade(const opus_val16 *in, opus_val16 *out, opus_val16 g1, opus_val16 g2, - int overlap48, int frame_size, int channels, const opus_val16 *window, opus_int32 Fs) { - int i; - int inc; - int overlap; - int c; - inc = 48000 / Fs; - overlap = overlap48 / inc; - if (channels == 1) { - for (i = 0; i < overlap; i++) { - opus_val16 g, w; - w = MULT16_16_Q15(window[i * inc], window[i * inc]); - g = SHR32(MAC16_16(MULT16_16(w, g2), - Q15ONE - w, g1), 15); - out[i] = MULT16_16_Q15(g, in[i]); - } - } else { - for (i = 0; i < overlap; i++) { - opus_val16 g, w; - w = MULT16_16_Q15(window[i * inc], window[i * inc]); - g = SHR32(MAC16_16(MULT16_16(w, g2), - Q15ONE - w, g1), 15); - out[i * 2] = MULT16_16_Q15(g, in[i * 2]); - out[i * 2 + 1] = MULT16_16_Q15(g, in[i * 2 + 1]); - } - } - c = 0; do { - for (i = overlap; i < frame_size; i++) { - out[i * channels + c] = MULT16_16_Q15(g2, in[i * channels + c]); - } - } while (++c < channels); -} - -OpusEncoder *opus_encoder_create(opus_int32 Fs, int channels, int application, int *error) { - int ret; - OpusEncoder *st; - if ((Fs != 48000 && Fs != 24000 && Fs != 16000 && Fs != 12000 && Fs != 8000) || (channels != 1 && channels != 2) || - (application != OPUS_APPLICATION_VOIP && application != OPUS_APPLICATION_AUDIO - && application != OPUS_APPLICATION_RESTRICTED_LOWDELAY)) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } - st = (OpusEncoder *)opus_alloc(opus_encoder_get_size(channels)); - if (st == NULL) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - ret = opus_encoder_init(st, Fs, channels, application); - if (error) { - *error = ret; - } - if (ret != OPUS_OK) { - opus_free(st); - st = NULL; - } - return st; -} - -static opus_int32 user_bitrate_to_bitrate(OpusEncoder *st, int frame_size, int max_data_bytes) { - if (!frame_size) { - frame_size = st->Fs / 400; - } - if (st->user_bitrate_bps == OPUS_AUTO) { - return 60 * st->Fs / frame_size + st->Fs * st->channels; - } else if (st->user_bitrate_bps == OPUS_BITRATE_MAX) { - return max_data_bytes * 8 * st->Fs / frame_size; - } else { - return st->user_bitrate_bps; - } -} - -#ifndef DISABLE_FLOAT_API -#ifdef FIXED_POINT -#define PCM2VAL(x) FLOAT2INT16(x) -#else -#define PCM2VAL(x) SCALEIN(x) -#endif - -void downmix_float(const void *_x, opus_val32 *y, int subframe, int offset, int c1, int c2, int C) { - const float *x; - int j; - - x = (const float *)_x; - for (j = 0; j < subframe; j++) { - y[j] = PCM2VAL(x[(j + offset) * C + c1]); - } - if (c2 > -1) { - for (j = 0; j < subframe; j++) { - y[j] += PCM2VAL(x[(j + offset) * C + c2]); - } - } else if (c2 == -2) { - int c; - for (c = 1; c < C; c++) { - for (j = 0; j < subframe; j++) { - y[j] += PCM2VAL(x[(j + offset) * C + c]); - } - } - } -} -#endif - -void downmix_int(const void *_x, opus_val32 *y, int subframe, int offset, int c1, int c2, int C) { - const opus_int16 *x; - int j; - - x = (const opus_int16 *)_x; - for (j = 0; j < subframe; j++) { - y[j] = x[(j + offset) * C + c1]; - } - if (c2 > -1) { - for (j = 0; j < subframe; j++) { - y[j] += x[(j + offset) * C + c2]; - } - } else if (c2 == -2) { - int c; - for (c = 1; c < C; c++) { - for (j = 0; j < subframe; j++) { - y[j] += x[(j + offset) * C + c]; - } - } - } -} - -opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs) { - int new_size; - if (frame_size < Fs / 400) { - return -1; - } - if (variable_duration == OPUS_FRAMESIZE_ARG) { - new_size = frame_size; - } else if (variable_duration >= OPUS_FRAMESIZE_2_5_MS && variable_duration <= OPUS_FRAMESIZE_120_MS) { - if (variable_duration <= OPUS_FRAMESIZE_40_MS) { - new_size = (Fs / 400) << (variable_duration - OPUS_FRAMESIZE_2_5_MS); - } else { - new_size = (variable_duration - OPUS_FRAMESIZE_2_5_MS - 2) * Fs / 50; - } - } else { - return -1; - } - if (new_size > frame_size) { - return -1; - } - if (400 * new_size != Fs && 200 * new_size != Fs && 100 * new_size != Fs && - 50 * new_size != Fs && 25 * new_size != Fs && 50 * new_size != 3 * Fs && - 50 * new_size != 4 * Fs && 50 * new_size != 5 * Fs && 50 * new_size != 6 * Fs) { - return -1; - } - return new_size; -} - -opus_val16 compute_stereo_width(const opus_val16 *pcm, int frame_size, opus_int32 Fs, StereoWidthState *mem) { - opus_val32 xx, xy, yy; - opus_val16 sqrt_xx, sqrt_yy; - opus_val16 qrrt_xx, qrrt_yy; - int frame_rate; - int i; - opus_val16 short_alpha; - - frame_rate = Fs / frame_size; - short_alpha = Q15ONE - MULT16_16(25, Q15ONE) / IMAX(50, frame_rate); - xx = xy = yy = 0; - /* Unroll by 4. The frame size is always a multiple of 4 *except* for - 2.5 ms frames at 12 kHz. Since this setting is very rare (and very - stupid), we just discard the last two samples. */ - for (i = 0; i < frame_size - 3; i += 4) { - opus_val32 pxx = 0; - opus_val32 pxy = 0; - opus_val32 pyy = 0; - opus_val16 x, y; - x = pcm[2 * i]; - y = pcm[2 * i + 1]; - pxx = SHR32(MULT16_16(x, x), 2); - pxy = SHR32(MULT16_16(x, y), 2); - pyy = SHR32(MULT16_16(y, y), 2); - x = pcm[2 * i + 2]; - y = pcm[2 * i + 3]; - pxx += SHR32(MULT16_16(x, x), 2); - pxy += SHR32(MULT16_16(x, y), 2); - pyy += SHR32(MULT16_16(y, y), 2); - x = pcm[2 * i + 4]; - y = pcm[2 * i + 5]; - pxx += SHR32(MULT16_16(x, x), 2); - pxy += SHR32(MULT16_16(x, y), 2); - pyy += SHR32(MULT16_16(y, y), 2); - x = pcm[2 * i + 6]; - y = pcm[2 * i + 7]; - pxx += SHR32(MULT16_16(x, x), 2); - pxy += SHR32(MULT16_16(x, y), 2); - pyy += SHR32(MULT16_16(y, y), 2); - - xx += SHR32(pxx, 10); - xy += SHR32(pxy, 10); - yy += SHR32(pyy, 10); - } -#ifndef FIXED_POINT - if (!(xx < 1e9f) || celt_isnan(xx) || !(yy < 1e9f) || celt_isnan(yy)) { - xy = xx = yy = 0; - } -#endif - mem->XX += MULT16_32_Q15(short_alpha, xx - mem->XX); - mem->XY += MULT16_32_Q15(short_alpha, xy - mem->XY); - mem->YY += MULT16_32_Q15(short_alpha, yy - mem->YY); - mem->XX = MAX32(0, mem->XX); - mem->XY = MAX32(0, mem->XY); - mem->YY = MAX32(0, mem->YY); - if (MAX32(mem->XX, mem->YY) > QCONST16(8e-4f, 18)) { - opus_val16 corr; - opus_val16 ldiff; - opus_val16 width; - sqrt_xx = celt_sqrt(mem->XX); - sqrt_yy = celt_sqrt(mem->YY); - qrrt_xx = celt_sqrt(sqrt_xx); - qrrt_yy = celt_sqrt(sqrt_yy); - /* Inter-channel correlation */ - mem->XY = MIN32(mem->XY, sqrt_xx * sqrt_yy); - corr = SHR32(frac_div32(mem->XY, EPSILON + MULT16_16(sqrt_xx, sqrt_yy)), 16); - /* Approximate loudness difference */ - ldiff = MULT16_16(Q15ONE, ABS16(qrrt_xx - qrrt_yy)) / (EPSILON + qrrt_xx + qrrt_yy); - width = MULT16_16_Q15(celt_sqrt(QCONST32(1.f, 30) - MULT16_16(corr, corr)), ldiff); - /* Smoothing over one second */ - mem->smoothed_width += (width - mem->smoothed_width) / frame_rate; - /* Peak follower */ - mem->max_follower = MAX16(mem->max_follower - QCONST16(.02f, 15) / frame_rate, mem->smoothed_width); - } - /*printf("%f %f %f %f %f ", corr/(float)Q15ONE, ldiff/(float)Q15ONE, width/(float)Q15ONE, mem->smoothed_width/(float)Q15ONE, mem->max_follower/(float)Q15ONE);*/ - return EXTRACT16(MIN32(Q15ONE, MULT16_16(20, mem->max_follower))); -} - -static int decide_fec(int useInBandFEC, int PacketLoss_perc, int last_fec, int mode, int *bandwidth, opus_int32 rate) { - int orig_bandwidth; - if (!useInBandFEC || PacketLoss_perc == 0 || mode == MODE_CELT_ONLY) { - return 0; - } - orig_bandwidth = *bandwidth; - for (;;) { - opus_int32 hysteresis; - opus_int32 LBRR_rate_thres_bps; - /* Compute threshold for using FEC at the current bandwidth setting */ - LBRR_rate_thres_bps = fec_thresholds[2 * (*bandwidth - OPUS_BANDWIDTH_NARROWBAND)]; - hysteresis = fec_thresholds[2 * (*bandwidth - OPUS_BANDWIDTH_NARROWBAND) + 1]; - if (last_fec == 1) { - LBRR_rate_thres_bps -= hysteresis; - } - if (last_fec == 0) { - LBRR_rate_thres_bps += hysteresis; - } - LBRR_rate_thres_bps = silk_SMULWB(silk_MUL(LBRR_rate_thres_bps, - 125 - silk_min(PacketLoss_perc, 25)), SILK_FIX_CONST(0.01, 16)); - /* If loss <= 5%, we look at whether we have enough rate to enable FEC. - If loss > 5%, we decrease the bandwidth until we can enable FEC. */ - if (rate > LBRR_rate_thres_bps) { - return 1; - } else if (PacketLoss_perc <= 5) { - return 0; - } else if (*bandwidth > OPUS_BANDWIDTH_NARROWBAND) { - (*bandwidth)--; - } else { - break; - } - } - /* Couldn't find any bandwidth to enable FEC, keep original bandwidth. */ - *bandwidth = orig_bandwidth; - return 0; -} - -static int compute_silk_rate_for_hybrid(int rate, int bandwidth, int frame20ms, int vbr, int fec, int channels) { - int entry; - int i; - int N; - int silk_rate; - static int rate_table[][5] = { - /* |total| |-------- SILK------------| - |-- No FEC -| |--- FEC ---| - 10ms 20ms 10ms 20ms */ - { 0, 0, 0, 0, 0}, - {12000, 10000, 10000, 11000, 11000}, - {16000, 13500, 13500, 15000, 15000}, - {20000, 16000, 16000, 18000, 18000}, - {24000, 18000, 18000, 21000, 21000}, - {32000, 22000, 22000, 28000, 28000}, - {64000, 38000, 38000, 50000, 50000} - }; - /* Do the allocation per-channel. */ - rate /= channels; - entry = 1 + frame20ms + 2 * fec; - N = sizeof(rate_table) / sizeof(rate_table[0]); - for (i = 1; i < N; i++) { - if (rate_table[i][0] > rate) { - break; - } - } - if (i == N) { - silk_rate = rate_table[i - 1][entry]; - /* For now, just give 50% of the extra bits to SILK. */ - silk_rate += (rate - rate_table[i - 1][0]) / 2; - } else { - opus_int32 lo, hi, x0, x1; - lo = rate_table[i - 1][entry]; - hi = rate_table[i][entry]; - x0 = rate_table[i - 1][0]; - x1 = rate_table[i][0]; - silk_rate = (lo * (x1 - rate) + hi * (rate - x0)) / (x1 - x0); - } - if (!vbr) { - /* Tiny boost to SILK for CBR. We should probably tune this better. */ - silk_rate += 100; - } - if (bandwidth == OPUS_BANDWIDTH_SUPERWIDEBAND) { - silk_rate += 300; - } - silk_rate *= channels; - /* Small adjustment for stereo (calibrated for 32 kb/s, haven't tried other bitrates). */ - if (channels == 2 && rate >= 12000) { - silk_rate -= 1000; - } - return silk_rate; -} - -/* Returns the equivalent bitrate corresponding to 20 ms frames, - complexity 10 VBR operation. */ -static opus_int32 compute_equiv_rate(opus_int32 bitrate, int channels, - int frame_rate, int vbr, int mode, int complexity, int loss) { - opus_int32 equiv; - equiv = bitrate; - /* Take into account overhead from smaller frames. */ - if (frame_rate > 50) { - equiv -= (40 * channels + 20) * (frame_rate - 50); - } - /* CBR is about a 8% penalty for both SILK and CELT. */ - if (!vbr) { - equiv -= equiv / 12; - } - /* Complexity makes about 10% difference (from 0 to 10) in general. */ - equiv = equiv * (90 + complexity) / 100; - if (mode == MODE_SILK_ONLY || mode == MODE_HYBRID) { - /* SILK complexity 0-1 uses the non-delayed-decision NSQ, which - costs about 20%. */ - if (complexity < 2) { - equiv = equiv * 4 / 5; - } - equiv -= equiv * loss / (6 * loss + 10); - } else if (mode == MODE_CELT_ONLY) { - /* CELT complexity 0-4 doesn't have the pitch filter, which costs - about 10%. */ - if (complexity < 5) { - equiv = equiv * 9 / 10; - } - } else { - /* Mode not known yet */ - /* Half the SILK loss*/ - equiv -= equiv * loss / (12 * loss + 20); - } - return equiv; -} - -#ifndef DISABLE_FLOAT_API - -int is_digital_silence(const opus_val16* pcm, int frame_size, int channels, int lsb_depth) { - int silence = 0; - opus_val32 sample_max = 0; -#ifdef MLP_TRAINING - return 0; -#endif - sample_max = celt_maxabs16(pcm, frame_size * channels); - -#ifdef FIXED_POINT - silence = (sample_max == 0); - (void)lsb_depth; -#else - silence = (sample_max <= (opus_val16) 1 / (1 << lsb_depth)); -#endif - - return silence; -} - -#ifdef FIXED_POINT -static opus_val32 compute_frame_energy(const opus_val16 *pcm, int frame_size, int channels, int arch) { - int i; - opus_val32 sample_max; - int max_shift; - int shift; - opus_val32 energy = 0; - int len = frame_size * channels; - (void)arch; - /* Max amplitude in the signal */ - sample_max = celt_maxabs16(pcm, len); - - /* Compute the right shift required in the MAC to avoid an overflow */ - max_shift = celt_ilog2(len); - shift = IMAX(0, (celt_ilog2(sample_max) << 1) + max_shift - 28); - - /* Compute the energy */ - for (i = 0; i < len; i++) { - energy += SHR32(MULT16_16(pcm[i], pcm[i]), shift); - } - - /* Normalize energy by the frame size and left-shift back to the original position */ - energy /= len; - energy = SHL32(energy, shift); - - return energy; -} -#else -static opus_val32 compute_frame_energy(const opus_val16 *pcm, int frame_size, int channels, int arch) { - int len = frame_size * channels; - return celt_inner_prod(pcm, pcm, len, arch) / len; -} -#endif - -/* Decides if DTX should be turned on (=1) or off (=0) */ -static int decide_dtx_mode(float activity_probability, /* probability that current frame contains speech/music */ - int *nb_no_activity_frames, /* number of consecutive frames with no activity */ - opus_val32 peak_signal_energy, /* peak energy of desired signal detected so far */ - const opus_val16 *pcm, /* input pcm signal */ - int frame_size, /* frame size */ - int channels, - int is_silence, /* only digital silence detected in this frame */ - int arch - ) { - opus_val32 noise_energy; - - if (!is_silence) { - if (activity_probability < DTX_ACTIVITY_THRESHOLD) { /* is noise */ - noise_energy = compute_frame_energy(pcm, frame_size, channels, arch); - - /* but is sufficiently quiet */ - is_silence = peak_signal_energy >= (PSEUDO_SNR_THRESHOLD * noise_energy); - } - } - - if (is_silence) { - /* The number of consecutive DTX frames should be within the allowed bounds */ - (*nb_no_activity_frames)++; - - if (*nb_no_activity_frames > NB_SPEECH_FRAMES_BEFORE_DTX) { - if (*nb_no_activity_frames <= (NB_SPEECH_FRAMES_BEFORE_DTX + MAX_CONSECUTIVE_DTX)) - /* Valid frame for DTX! */ - { - return 1; - } else { - (*nb_no_activity_frames) = NB_SPEECH_FRAMES_BEFORE_DTX; - } - } - } else { - (*nb_no_activity_frames) = 0; - } - - return 0; -} - -#endif - -static opus_int32 encode_multiframe_packet(OpusEncoder *st, - const opus_val16 *pcm, - int nb_frames, - int frame_size, - unsigned char *data, - opus_int32 out_data_bytes, - int to_celt, - int lsb_depth, - int float_api) { - int i; - int ret = 0; - VARDECL(unsigned char, tmp_data); - int bak_mode, bak_bandwidth, bak_channels, bak_to_mono; - VARDECL(OpusRepacketizer, rp); - int max_header_bytes; - opus_int32 bytes_per_frame; - opus_int32 cbr_bytes; - opus_int32 repacketize_len; - int tmp_len; - ALLOC_STACK; - - /* Worst cases: - 2 frames: Code 2 with different compressed sizes - >2 frames: Code 3 VBR */ - max_header_bytes = nb_frames == 2 ? 3 : (2 + (nb_frames - 1) * 2); - - if (st->use_vbr || st->user_bitrate_bps == OPUS_BITRATE_MAX) { - repacketize_len = out_data_bytes; - } else { - cbr_bytes = 3 * st->bitrate_bps / (3 * 8 * st->Fs / (frame_size * nb_frames)); - repacketize_len = IMIN(cbr_bytes, out_data_bytes); - } - bytes_per_frame = IMIN(1276, 1 + (repacketize_len - max_header_bytes) / nb_frames); - - ALLOC(tmp_data, nb_frames * bytes_per_frame, unsigned char); - ALLOC(rp, 1, OpusRepacketizer); - opus_repacketizer_init(rp); - - bak_mode = st->user_forced_mode; - bak_bandwidth = st->user_bandwidth; - bak_channels = st->force_channels; - - st->user_forced_mode = st->mode; - st->user_bandwidth = st->bandwidth; - st->force_channels = st->stream_channels; - - bak_to_mono = st->silk_mode.toMono; - if (bak_to_mono) { - st->force_channels = 1; - } else { - st->prev_channels = st->stream_channels; - } - - for (i = 0; i < nb_frames; i++) { - st->silk_mode.toMono = 0; - st->nonfinal_frame = i < (nb_frames - 1); - - /* When switching from SILK/Hybrid to CELT, only ask for a switch at the last frame */ - if (to_celt && i == nb_frames - 1) { - st->user_forced_mode = MODE_CELT_ONLY; - } - - tmp_len = opus_encode_native(st, pcm + i * (st->channels * frame_size), frame_size, - tmp_data + i * bytes_per_frame, bytes_per_frame, lsb_depth, NULL, 0, 0, 0, 0, - NULL, float_api); - - if (tmp_len < 0) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - - ret = opus_repacketizer_cat(rp, tmp_data + i * bytes_per_frame, tmp_len); - - if (ret < 0) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - } - - ret = opus_repacketizer_out_range_impl(rp, 0, nb_frames, data, repacketize_len, 0, !st->use_vbr); - - if (ret < 0) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - - /* Discard configs that were forced locally for the purpose of repacketization */ - st->user_forced_mode = bak_mode; - st->user_bandwidth = bak_bandwidth; - st->force_channels = bak_channels; - st->silk_mode.toMono = bak_to_mono; - - RESTORE_STACK; - return ret; -} - -static int compute_redundancy_bytes(opus_int32 max_data_bytes, opus_int32 bitrate_bps, int frame_rate, int channels) { - int redundancy_bytes_cap; - int redundancy_bytes; - opus_int32 redundancy_rate; - int base_bits; - opus_int32 available_bits; - base_bits = (40 * channels + 20); - - /* Equivalent rate for 5 ms frames. */ - redundancy_rate = bitrate_bps + base_bits * (200 - frame_rate); - /* For VBR, further increase the bitrate if we can afford it. It's pretty short - and we'll avoid artefacts. */ - redundancy_rate = 3 * redundancy_rate / 2; - redundancy_bytes = redundancy_rate / 1600; - - /* Compute the max rate we can use given CBR or VBR with cap. */ - available_bits = max_data_bytes * 8 - 2 * base_bits; - redundancy_bytes_cap = (available_bits * 240 / (240 + 48000 / frame_rate) + base_bits) / 8; - redundancy_bytes = IMIN(redundancy_bytes, redundancy_bytes_cap); - /* It we can't get enough bits for redundancy to be worth it, rely on the decoder PLC. */ - if (redundancy_bytes > 4 + 8 * channels) { - redundancy_bytes = IMIN(257, redundancy_bytes); - } else { - redundancy_bytes = 0; - } - return redundancy_bytes; -} - -opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, - unsigned char *data, opus_int32 out_data_bytes, int lsb_depth, - const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, - int analysis_channels, downmix_func downmix, int float_api) { - void *silk_enc; - CELTEncoder *celt_enc; - int i; - int ret = 0; - opus_int32 nBytes; - ec_enc enc; - int bytes_target; - int prefill = 0; - int start_band = 0; - int redundancy = 0; - int redundancy_bytes = 0; /* Number of bytes to use for redundancy frame */ - int celt_to_silk = 0; - VARDECL(opus_val16, pcm_buf); - int nb_compr_bytes; - int to_celt = 0; - opus_uint32 redundant_rng = 0; - int cutoff_Hz, hp_freq_smth1; - int voice_est; /* Probability of voice in Q7 */ - opus_int32 equiv_rate; - int delay_compensation; - int frame_rate; - opus_int32 max_rate; /* Max bitrate we're allowed to use */ - int curr_bandwidth; - opus_val16 HB_gain; - opus_int32 max_data_bytes; /* Max number of bytes we're allowed to use */ - int total_buffer; - opus_val16 stereo_width; - const CELTMode *celt_mode; -#ifndef DISABLE_FLOAT_API - AnalysisInfo analysis_info; - int analysis_read_pos_bak = -1; - int analysis_read_subframe_bak = -1; - int is_silence = 0; -#endif - VARDECL(opus_val16, tmp_prefill); - - ALLOC_STACK; - - max_data_bytes = IMIN(1276, out_data_bytes); - - st->rangeFinal = 0; - if (frame_size <= 0 || max_data_bytes <= 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - /* Cannot encode 100 ms in 1 byte */ - if (max_data_bytes == 1 && st->Fs == (frame_size * 10)) { - RESTORE_STACK; - return OPUS_BUFFER_TOO_SMALL; - } - - silk_enc = (char*)st + st->silk_enc_offset; - celt_enc = (CELTEncoder*)((char*)st + st->celt_enc_offset); - if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) { - delay_compensation = 0; - } else { - delay_compensation = st->delay_compensation; - } - - lsb_depth = IMIN(lsb_depth, st->lsb_depth); - - celt_encoder_ctl(celt_enc, CELT_GET_MODE(&celt_mode)); -#ifndef DISABLE_FLOAT_API - analysis_info.valid = 0; -#ifdef FIXED_POINT - if (st->silk_mode.complexity >= 10 && st->Fs >= 16000) -#else - if (st->silk_mode.complexity >= 7 && st->Fs >= 16000) -#endif - { - is_silence = is_digital_silence(pcm, frame_size, st->channels, lsb_depth); - analysis_read_pos_bak = st->analysis.read_pos; - analysis_read_subframe_bak = st->analysis.read_subframe; - run_analysis(&st->analysis, celt_mode, analysis_pcm, analysis_size, frame_size, - c1, c2, analysis_channels, st->Fs, - lsb_depth, downmix, &analysis_info); - - /* Track the peak signal energy */ - if (!is_silence && analysis_info.activity_probability > DTX_ACTIVITY_THRESHOLD) - st->peak_signal_energy = MAX32(MULT16_32_Q15(QCONST16(0.999f, 15), st->peak_signal_energy), - compute_frame_energy(pcm, frame_size, st->channels, st->arch)); - } else if (st->analysis.initialized) { - tonality_analysis_reset(&st->analysis); - } -#else - (void)analysis_pcm; - (void)analysis_size; - (void)c1; - (void)c2; - (void)analysis_channels; - (void)downmix; -#endif - -#ifndef DISABLE_FLOAT_API - /* Reset voice_ratio if this frame is not silent or if analysis is disabled. - Otherwise, preserve voice_ratio from the last non-silent frame */ - if (!is_silence) { - st->voice_ratio = -1; - } - - st->detected_bandwidth = 0; - if (analysis_info.valid) { - int analysis_bandwidth; - if (st->signal_type == OPUS_AUTO) { - float prob; - if (st->prev_mode == 0) { - prob = analysis_info.music_prob; - } else if (st->prev_mode == MODE_CELT_ONLY) { - prob = analysis_info.music_prob_max; - } else { - prob = analysis_info.music_prob_min; - } - st->voice_ratio = (int)floor(.5 + 100 * (1 - prob)); - } - - analysis_bandwidth = analysis_info.bandwidth; - if (analysis_bandwidth <= 12) { - st->detected_bandwidth = OPUS_BANDWIDTH_NARROWBAND; - } else if (analysis_bandwidth <= 14) { - st->detected_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND; - } else if (analysis_bandwidth <= 16) { - st->detected_bandwidth = OPUS_BANDWIDTH_WIDEBAND; - } else if (analysis_bandwidth <= 18) { - st->detected_bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND; - } else { - st->detected_bandwidth = OPUS_BANDWIDTH_FULLBAND; - } - } -#else - st->voice_ratio = -1; -#endif - - if (st->channels == 2 && st->force_channels != 1) { - stereo_width = compute_stereo_width(pcm, frame_size, st->Fs, &st->width_mem); - } else { - stereo_width = 0; - } - total_buffer = delay_compensation; - st->bitrate_bps = user_bitrate_to_bitrate(st, frame_size, max_data_bytes); - - frame_rate = st->Fs / frame_size; - if (!st->use_vbr) { - int cbrBytes; - /* Multiply by 12 to make sure the division is exact. */ - int frame_rate12 = 12 * st->Fs / frame_size; - /* We need to make sure that "int" values always fit in 16 bits. */ - cbrBytes = IMIN((12 * st->bitrate_bps / 8 + frame_rate12 / 2) / frame_rate12, max_data_bytes); - st->bitrate_bps = cbrBytes * (opus_int32)frame_rate12 * 8 / 12; - /* Make sure we provide at least one byte to avoid failing. */ - max_data_bytes = IMAX(1, cbrBytes); - } - if (max_data_bytes < 3 || st->bitrate_bps < 3 * frame_rate * 8 - || (frame_rate < 50 && (max_data_bytes * frame_rate < 300 || st->bitrate_bps < 2400))) { - /*If the space is too low to do something useful, emit 'PLC' frames.*/ - int tocmode = st->mode; - int bw = st->bandwidth == 0 ? OPUS_BANDWIDTH_NARROWBAND : st->bandwidth; - int packet_code = 0; - int num_multiframes = 0; - - if (tocmode == 0) { - tocmode = MODE_SILK_ONLY; - } - if (frame_rate > 100) { - tocmode = MODE_CELT_ONLY; - } - /* 40 ms -> 2 x 20 ms if in CELT_ONLY or HYBRID mode */ - if (frame_rate == 25 && tocmode != MODE_SILK_ONLY) { - frame_rate = 50; - packet_code = 1; - } - - /* >= 60 ms frames */ - if (frame_rate <= 16) { - /* 1 x 60 ms, 2 x 40 ms, 2 x 60 ms */ - if (out_data_bytes == 1 || (tocmode == MODE_SILK_ONLY && frame_rate != 10)) { - tocmode = MODE_SILK_ONLY; - - packet_code = frame_rate <= 12; - frame_rate = frame_rate == 12 ? 25 : 16; - } else { - num_multiframes = 50 / frame_rate; - frame_rate = 50; - packet_code = 3; - } - } - - if (tocmode == MODE_SILK_ONLY && bw > OPUS_BANDWIDTH_WIDEBAND) { - bw = OPUS_BANDWIDTH_WIDEBAND; - } else if (tocmode == MODE_CELT_ONLY && bw == OPUS_BANDWIDTH_MEDIUMBAND) { - bw = OPUS_BANDWIDTH_NARROWBAND; - } else if (tocmode == MODE_HYBRID && bw <= OPUS_BANDWIDTH_SUPERWIDEBAND) { - bw = OPUS_BANDWIDTH_SUPERWIDEBAND; - } - - data[0] = gen_toc(tocmode, frame_rate, bw, st->stream_channels); - data[0] |= packet_code; - - ret = packet_code <= 1 ? 1 : 2; - - max_data_bytes = IMAX(max_data_bytes, ret); - - if (packet_code == 3) { - data[1] = num_multiframes; - } - - if (!st->use_vbr) { - ret = opus_packet_pad(data, ret, max_data_bytes); - if (ret == OPUS_OK) { - ret = max_data_bytes; - } else { - ret = OPUS_INTERNAL_ERROR; - } - } - RESTORE_STACK; - return ret; - } - max_rate = frame_rate * max_data_bytes * 8; - - /* Equivalent 20-ms rate for mode/channel/bandwidth decisions */ - equiv_rate = compute_equiv_rate(st->bitrate_bps, st->channels, st->Fs / frame_size, - st->use_vbr, 0, st->silk_mode.complexity, st->silk_mode.packetLossPercentage); - - if (st->signal_type == OPUS_SIGNAL_VOICE) { - voice_est = 127; - } else if (st->signal_type == OPUS_SIGNAL_MUSIC) { - voice_est = 0; - } else if (st->voice_ratio >= 0) { - voice_est = st->voice_ratio * 327 >> 8; - /* For AUDIO, never be more than 90% confident of having speech */ - if (st->application == OPUS_APPLICATION_AUDIO) { - voice_est = IMIN(voice_est, 115); - } - } else if (st->application == OPUS_APPLICATION_VOIP) { - voice_est = 115; - } else { - voice_est = 48; - } - - if (st->force_channels != OPUS_AUTO && st->channels == 2) { - st->stream_channels = st->force_channels; - } else { -#ifdef FUZZING - /* Random mono/stereo decision */ - if (st->channels == 2 && (rand() & 0x1F) == 0) { - st->stream_channels = 3 - st->stream_channels; - } -#else - /* Rate-dependent mono-stereo decision */ - if (st->channels == 2) { - opus_int32 stereo_threshold; - stereo_threshold = stereo_music_threshold + ((voice_est * voice_est * (stereo_voice_threshold - stereo_music_threshold)) >> 14); - if (st->stream_channels == 2) { - stereo_threshold -= 1000; - } else { - stereo_threshold += 1000; - } - st->stream_channels = (equiv_rate > stereo_threshold) ? 2 : 1; - } else { - st->stream_channels = st->channels; - } -#endif - } - /* Update equivalent rate for channels decision. */ - equiv_rate = compute_equiv_rate(st->bitrate_bps, st->stream_channels, st->Fs / frame_size, - st->use_vbr, 0, st->silk_mode.complexity, st->silk_mode.packetLossPercentage); - - /* Allow SILK DTX if DTX is enabled but the generalized DTX cannot be used, - e.g. because of the complexity setting or sample rate. */ -#ifndef DISABLE_FLOAT_API - st->silk_mode.useDTX = st->use_dtx && !(analysis_info.valid || is_silence); -#else - st->silk_mode.useDTX = st->use_dtx; -#endif - - /* Mode selection depending on application and signal type */ - if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) { - st->mode = MODE_CELT_ONLY; - } else if (st->user_forced_mode == OPUS_AUTO) { -#ifdef FUZZING - /* Random mode switching */ - if ((rand() & 0xF) == 0) { - if ((rand() & 0x1) == 0) { - st->mode = MODE_CELT_ONLY; - } else { - st->mode = MODE_SILK_ONLY; - } - } else { - if (st->prev_mode == MODE_CELT_ONLY) { - st->mode = MODE_CELT_ONLY; - } else { - st->mode = MODE_SILK_ONLY; - } - } -#else - opus_int32 mode_voice, mode_music; - opus_int32 threshold; - - /* Interpolate based on stereo width */ - mode_voice = (opus_int32)(MULT16_32_Q15(Q15ONE - stereo_width, mode_thresholds[0][0]) - + MULT16_32_Q15(stereo_width, mode_thresholds[1][0])); - mode_music = (opus_int32)(MULT16_32_Q15(Q15ONE - stereo_width, mode_thresholds[1][1]) - + MULT16_32_Q15(stereo_width, mode_thresholds[1][1])); - /* Interpolate based on speech/music probability */ - threshold = mode_music + ((voice_est * voice_est * (mode_voice - mode_music)) >> 14); - /* Bias towards SILK for VoIP because of some useful features */ - if (st->application == OPUS_APPLICATION_VOIP) { - threshold += 8000; - } - - /*printf("%f %d\n", stereo_width/(float)Q15ONE, threshold);*/ - /* Hysteresis */ - if (st->prev_mode == MODE_CELT_ONLY) { - threshold -= 4000; - } else if (st->prev_mode > 0) { - threshold += 4000; - } - - st->mode = (equiv_rate >= threshold) ? MODE_CELT_ONLY : MODE_SILK_ONLY; - - /* When FEC is enabled and there's enough packet loss, use SILK */ - if (st->silk_mode.useInBandFEC && st->silk_mode.packetLossPercentage > (128 - voice_est) >> 4) { - st->mode = MODE_SILK_ONLY; - } - /* When encoding voice and DTX is enabled but the generalized DTX cannot be used, - use SILK in order to make use of its DTX. */ - if (st->silk_mode.useDTX && voice_est > 100) { - st->mode = MODE_SILK_ONLY; - } -#endif - - /* If max_data_bytes represents less than 6 kb/s, switch to CELT-only mode */ - if (max_data_bytes < (frame_rate > 50 ? 9000 : 6000)*frame_size / (st->Fs * 8)) { - st->mode = MODE_CELT_ONLY; - } - } else { - st->mode = st->user_forced_mode; - } - - /* Override the chosen mode to make sure we meet the requested frame size */ - if (st->mode != MODE_CELT_ONLY && frame_size < st->Fs / 100) { - st->mode = MODE_CELT_ONLY; - } - if (st->lfe) { - st->mode = MODE_CELT_ONLY; - } - - if (st->prev_mode > 0 && - ((st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY) || - (st->mode == MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY))) { - redundancy = 1; - celt_to_silk = (st->mode != MODE_CELT_ONLY); - if (!celt_to_silk) { - /* Switch to SILK/hybrid if frame size is 10 ms or more*/ - if (frame_size >= st->Fs / 100) { - st->mode = st->prev_mode; - to_celt = 1; - } else { - redundancy = 0; - } - } - } - - /* When encoding multiframes, we can ask for a switch to CELT only in the last frame. This switch - is processed above as the requested mode shouldn't interrupt stereo->mono transition. */ - if (st->stream_channels == 1 && st->prev_channels == 2 && st->silk_mode.toMono == 0 - && st->mode != MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY) { - /* Delay stereo->mono transition by two frames so that SILK can do a smooth downmix */ - st->silk_mode.toMono = 1; - st->stream_channels = 2; - } else { - st->silk_mode.toMono = 0; - } - - /* Update equivalent rate with mode decision. */ - equiv_rate = compute_equiv_rate(st->bitrate_bps, st->stream_channels, st->Fs / frame_size, - st->use_vbr, st->mode, st->silk_mode.complexity, st->silk_mode.packetLossPercentage); - - if (st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY) { - silk_EncControlStruct dummy; - silk_InitEncoder(silk_enc, st->arch, &dummy); - prefill = 1; - } - - /* Automatic (rate-dependent) bandwidth selection */ - if (st->mode == MODE_CELT_ONLY || st->first || st->silk_mode.allowBandwidthSwitch) { - const opus_int32 *voice_bandwidth_thresholds, *music_bandwidth_thresholds; - opus_int32 bandwidth_thresholds[8]; - int bandwidth = OPUS_BANDWIDTH_FULLBAND; - - if (st->channels == 2 && st->force_channels != 1) { - voice_bandwidth_thresholds = stereo_voice_bandwidth_thresholds; - music_bandwidth_thresholds = stereo_music_bandwidth_thresholds; - } else { - voice_bandwidth_thresholds = mono_voice_bandwidth_thresholds; - music_bandwidth_thresholds = mono_music_bandwidth_thresholds; - } - /* Interpolate bandwidth thresholds depending on voice estimation */ - for (i = 0; i < 8; i++) { - bandwidth_thresholds[i] = music_bandwidth_thresholds[i] - + ((voice_est * voice_est * (voice_bandwidth_thresholds[i] - music_bandwidth_thresholds[i])) >> 14); - } - do { - int threshold, hysteresis; - threshold = bandwidth_thresholds[2 * (bandwidth - OPUS_BANDWIDTH_MEDIUMBAND)]; - hysteresis = bandwidth_thresholds[2 * (bandwidth - OPUS_BANDWIDTH_MEDIUMBAND) + 1]; - if (!st->first) { - if (st->auto_bandwidth >= bandwidth) { - threshold -= hysteresis; - } else { - threshold += hysteresis; - } - } - if (equiv_rate >= threshold) { - break; - } - } while (--bandwidth > OPUS_BANDWIDTH_NARROWBAND); - /* We don't use mediumband anymore, except when explicitly requested or during - mode transitions. */ - if (bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - bandwidth = OPUS_BANDWIDTH_WIDEBAND; - } - st->bandwidth = st->auto_bandwidth = bandwidth; - /* Prevents any transition to SWB/FB until the SILK layer has fully - switched to WB mode and turned the variable LP filter off */ - if (!st->first && st->mode != MODE_CELT_ONLY && !st->silk_mode.inWBmodeWithoutVariableLP && st->bandwidth > OPUS_BANDWIDTH_WIDEBAND) { - st->bandwidth = OPUS_BANDWIDTH_WIDEBAND; - } - } - - if (st->bandwidth > st->max_bandwidth) { - st->bandwidth = st->max_bandwidth; - } - - if (st->user_bandwidth != OPUS_AUTO) { - st->bandwidth = st->user_bandwidth; - } - - /* This prevents us from using hybrid at unsafe CBR/max rates */ - if (st->mode != MODE_CELT_ONLY && max_rate < 15000) { - st->bandwidth = IMIN(st->bandwidth, OPUS_BANDWIDTH_WIDEBAND); - } - - /* Prevents Opus from wasting bits on frequencies that are above - the Nyquist rate of the input signal */ - if (st->Fs <= 24000 && st->bandwidth > OPUS_BANDWIDTH_SUPERWIDEBAND) { - st->bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND; - } - if (st->Fs <= 16000 && st->bandwidth > OPUS_BANDWIDTH_WIDEBAND) { - st->bandwidth = OPUS_BANDWIDTH_WIDEBAND; - } - if (st->Fs <= 12000 && st->bandwidth > OPUS_BANDWIDTH_MEDIUMBAND) { - st->bandwidth = OPUS_BANDWIDTH_MEDIUMBAND; - } - if (st->Fs <= 8000 && st->bandwidth > OPUS_BANDWIDTH_NARROWBAND) { - st->bandwidth = OPUS_BANDWIDTH_NARROWBAND; - } -#ifndef DISABLE_FLOAT_API - /* Use detected bandwidth to reduce the encoded bandwidth. */ - if (st->detected_bandwidth && st->user_bandwidth == OPUS_AUTO) { - int min_detected_bandwidth; - /* Makes bandwidth detection more conservative just in case the detector - gets it wrong when we could have coded a high bandwidth transparently. - When operating in SILK/hybrid mode, we don't go below wideband to avoid - more complicated switches that require redundancy. */ - if (equiv_rate <= 18000 * st->stream_channels && st->mode == MODE_CELT_ONLY) { - min_detected_bandwidth = OPUS_BANDWIDTH_NARROWBAND; - } else if (equiv_rate <= 24000 * st->stream_channels && st->mode == MODE_CELT_ONLY) { - min_detected_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND; - } else if (equiv_rate <= 30000 * st->stream_channels) { - min_detected_bandwidth = OPUS_BANDWIDTH_WIDEBAND; - } else if (equiv_rate <= 44000 * st->stream_channels) { - min_detected_bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND; - } else { - min_detected_bandwidth = OPUS_BANDWIDTH_FULLBAND; - } - - st->detected_bandwidth = IMAX(st->detected_bandwidth, min_detected_bandwidth); - st->bandwidth = IMIN(st->bandwidth, st->detected_bandwidth); - } -#endif - st->silk_mode.LBRR_coded = decide_fec(st->silk_mode.useInBandFEC, st->silk_mode.packetLossPercentage, - st->silk_mode.LBRR_coded, st->mode, &st->bandwidth, equiv_rate); - celt_encoder_ctl(celt_enc, OPUS_SET_LSB_DEPTH(lsb_depth)); - - /* CELT mode doesn't support mediumband, use wideband instead */ - if (st->mode == MODE_CELT_ONLY && st->bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - st->bandwidth = OPUS_BANDWIDTH_WIDEBAND; - } - if (st->lfe) { - st->bandwidth = OPUS_BANDWIDTH_NARROWBAND; - } - - curr_bandwidth = st->bandwidth; - - /* Chooses the appropriate mode for speech - NEVER* switch to/from CELT-only mode here as this will invalidate some assumptions */ - if (st->mode == MODE_SILK_ONLY && curr_bandwidth > OPUS_BANDWIDTH_WIDEBAND) { - st->mode = MODE_HYBRID; - } - if (st->mode == MODE_HYBRID && curr_bandwidth <= OPUS_BANDWIDTH_WIDEBAND) { - st->mode = MODE_SILK_ONLY; - } - - /* Can't support higher than >60 ms frames, and >20 ms when in Hybrid or CELT-only modes */ - if ((frame_size > st->Fs / 50 && (st->mode != MODE_SILK_ONLY)) || frame_size > 3 * st->Fs / 50) { - int enc_frame_size; - int nb_frames; - - if (st->mode == MODE_SILK_ONLY) { - if (frame_size == 2 * st->Fs / 25) { /* 80 ms -> 2x 40 ms */ - enc_frame_size = st->Fs / 25; - } else if (frame_size == 3 * st->Fs / 25) { /* 120 ms -> 2x 60 ms */ - enc_frame_size = 3 * st->Fs / 50; - } else { /* 100 ms -> 5x 20 ms */ - enc_frame_size = st->Fs / 50; - } - } else { - enc_frame_size = st->Fs / 50; - } - - nb_frames = frame_size / enc_frame_size; - -#ifndef DISABLE_FLOAT_API - if (analysis_read_pos_bak != -1) { - st->analysis.read_pos = analysis_read_pos_bak; - st->analysis.read_subframe = analysis_read_subframe_bak; - } -#endif - - ret = encode_multiframe_packet(st, pcm, nb_frames, enc_frame_size, data, - out_data_bytes, to_celt, lsb_depth, float_api); - - RESTORE_STACK; - return ret; - } - - /* For the first frame at a new SILK bandwidth */ - if (st->silk_bw_switch) { - redundancy = 1; - celt_to_silk = 1; - st->silk_bw_switch = 0; - /* Do a prefill without reseting the sampling rate control. */ - prefill = 2; - } - - /* If we decided to go with CELT, make sure redundancy is off, no matter what - we decided earlier. */ - if (st->mode == MODE_CELT_ONLY) { - redundancy = 0; - } - - if (redundancy) { - redundancy_bytes = compute_redundancy_bytes(max_data_bytes, st->bitrate_bps, frame_rate, st->stream_channels); - if (redundancy_bytes == 0) { - redundancy = 0; - } - } - - /* printf("%d %d %d %d\n", st->bitrate_bps, st->stream_channels, st->mode, curr_bandwidth); */ - bytes_target = IMIN(max_data_bytes - redundancy_bytes, st->bitrate_bps * frame_size / (st->Fs * 8)) - 1; - - data += 1; - - ec_enc_init(&enc, data, max_data_bytes - 1); - - ALLOC(pcm_buf, (total_buffer + frame_size)*st->channels, opus_val16); - OPUS_COPY(pcm_buf, &st->delay_buffer[(st->encoder_buffer - total_buffer)*st->channels], total_buffer * st->channels); - - if (st->mode == MODE_CELT_ONLY) { - hp_freq_smth1 = silk_LSHIFT(silk_lin2log(VARIABLE_HP_MIN_CUTOFF_HZ), 8); - } else { - hp_freq_smth1 = ((silk_encoder*)silk_enc)->state_Fxx[0].sCmn.variable_HP_smth1_Q15; - } - - st->variable_HP_smth2_Q15 = silk_SMLAWB(st->variable_HP_smth2_Q15, - hp_freq_smth1 - st->variable_HP_smth2_Q15, SILK_FIX_CONST(VARIABLE_HP_SMTH_COEF2, 16)); - - /* convert from log scale to Hertz */ - cutoff_Hz = silk_log2lin(silk_RSHIFT(st->variable_HP_smth2_Q15, 8)); - - if (st->application == OPUS_APPLICATION_VOIP) { - hp_cutoff(pcm, cutoff_Hz, &pcm_buf[total_buffer * st->channels], st->hp_mem, frame_size, st->channels, st->Fs, st->arch); - } else { - dc_reject(pcm, 3, &pcm_buf[total_buffer * st->channels], st->hp_mem, frame_size, st->channels, st->Fs); - } -#ifndef FIXED_POINT - if (float_api) { - opus_val32 sum; - sum = celt_inner_prod(&pcm_buf[total_buffer * st->channels], &pcm_buf[total_buffer * st->channels], frame_size * st->channels, st->arch); - /* This should filter out both NaNs and ridiculous signals that could - cause NaNs further down. */ - if (!(sum < 1e9f) || celt_isnan(sum)) { - OPUS_CLEAR(&pcm_buf[total_buffer * st->channels], frame_size * st->channels); - st->hp_mem[0] = st->hp_mem[1] = st->hp_mem[2] = st->hp_mem[3] = 0; - } - } -#endif - - - /* SILK processing */ - HB_gain = Q15ONE; - if (st->mode != MODE_CELT_ONLY) { - opus_int32 total_bitRate, celt_rate; - opus_int activity; -#ifdef FIXED_POINT - const opus_int16 *pcm_silk; -#else - VARDECL(opus_int16, pcm_silk); - ALLOC(pcm_silk, st->channels * frame_size, opus_int16); -#endif - - activity = VAD_NO_DECISION; -#ifndef DISABLE_FLOAT_API - if (analysis_info.valid) { - /* Inform SILK about the Opus VAD decision */ - activity = (analysis_info.activity_probability >= DTX_ACTIVITY_THRESHOLD); - } -#endif - - /* Distribute bits between SILK and CELT */ - total_bitRate = 8 * bytes_target * frame_rate; - if (st->mode == MODE_HYBRID) { - /* Base rate for SILK */ - st->silk_mode.bitRate = compute_silk_rate_for_hybrid(total_bitRate, - curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr, st->silk_mode.LBRR_coded, - st->stream_channels); - if (!st->energy_masking) { - /* Increasingly attenuate high band when it gets allocated fewer bits */ - celt_rate = total_bitRate - st->silk_mode.bitRate; - HB_gain = Q15ONE - SHR32(celt_exp2(-celt_rate * QCONST16(1.f / 1024, 10)), 1); - } - } else { - /* SILK gets all bits */ - st->silk_mode.bitRate = total_bitRate; - } - - /* Surround masking for SILK */ - if (st->energy_masking && st->use_vbr && !st->lfe) { - opus_val32 mask_sum = 0; - opus_val16 masking_depth; - opus_int32 rate_offset; - int c; - int end = 17; - opus_int16 srate = 16000; - if (st->bandwidth == OPUS_BANDWIDTH_NARROWBAND) { - end = 13; - srate = 8000; - } else if (st->bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - end = 15; - srate = 12000; - } - for (c = 0; c < st->channels; c++) { - for (i = 0; i < end; i++) { - opus_val16 mask; - mask = MAX16(MIN16(st->energy_masking[21 * c + i], - QCONST16(.5f, DB_SHIFT)), -QCONST16(2.0f, DB_SHIFT)); - if (mask > 0) { - mask = HALF16(mask); - } - mask_sum += mask; - } - } - /* Conservative rate reduction, we cut the masking in half */ - masking_depth = mask_sum / end * st->channels; - masking_depth += QCONST16(.2f, DB_SHIFT); - rate_offset = (opus_int32)PSHR32(MULT16_16(srate, masking_depth), DB_SHIFT); - rate_offset = MAX32(rate_offset, -2 * st->silk_mode.bitRate / 3); - /* Split the rate change between the SILK and CELT part for hybrid. */ - if (st->bandwidth == OPUS_BANDWIDTH_SUPERWIDEBAND || st->bandwidth == OPUS_BANDWIDTH_FULLBAND) { - st->silk_mode.bitRate += 3 * rate_offset / 5; - } else { - st->silk_mode.bitRate += rate_offset; - } - } - - st->silk_mode.payloadSize_ms = 1000 * frame_size / st->Fs; - st->silk_mode.nChannelsAPI = st->channels; - st->silk_mode.nChannelsInternal = st->stream_channels; - if (curr_bandwidth == OPUS_BANDWIDTH_NARROWBAND) { - st->silk_mode.desiredInternalSampleRate = 8000; - } else if (curr_bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - st->silk_mode.desiredInternalSampleRate = 12000; - } else { - celt_assert(st->mode == MODE_HYBRID || curr_bandwidth == OPUS_BANDWIDTH_WIDEBAND); - st->silk_mode.desiredInternalSampleRate = 16000; - } - if (st->mode == MODE_HYBRID) { - /* Don't allow bandwidth reduction at lowest bitrates in hybrid mode */ - st->silk_mode.minInternalSampleRate = 16000; - } else { - st->silk_mode.minInternalSampleRate = 8000; - } - - st->silk_mode.maxInternalSampleRate = 16000; - if (st->mode == MODE_SILK_ONLY) { - opus_int32 effective_max_rate = max_rate; - if (frame_rate > 50) { - effective_max_rate = effective_max_rate * 2 / 3; - } - if (effective_max_rate < 8000) { - st->silk_mode.maxInternalSampleRate = 12000; - st->silk_mode.desiredInternalSampleRate = IMIN(12000, st->silk_mode.desiredInternalSampleRate); - } - if (effective_max_rate < 7000) { - st->silk_mode.maxInternalSampleRate = 8000; - st->silk_mode.desiredInternalSampleRate = IMIN(8000, st->silk_mode.desiredInternalSampleRate); - } - } - - st->silk_mode.useCBR = !st->use_vbr; - - /* Call SILK encoder for the low band */ - - /* Max bits for SILK, counting ToC, redundancy bytes, and optionally redundancy. */ - st->silk_mode.maxBits = (max_data_bytes - 1) * 8; - if (redundancy && redundancy_bytes >= 2) { - /* Counting 1 bit for redundancy position and 20 bits for flag+size (only for hybrid). */ - st->silk_mode.maxBits -= redundancy_bytes * 8 + 1; - if (st->mode == MODE_HYBRID) { - st->silk_mode.maxBits -= 20; - } - } - if (st->silk_mode.useCBR) { - if (st->mode == MODE_HYBRID) { - st->silk_mode.maxBits = IMIN(st->silk_mode.maxBits, st->silk_mode.bitRate * frame_size / st->Fs); - } - } else { - /* Constrained VBR. */ - if (st->mode == MODE_HYBRID) { - /* Compute SILK bitrate corresponding to the max total bits available */ - opus_int32 maxBitRate = compute_silk_rate_for_hybrid(st->silk_mode.maxBits * st->Fs / frame_size, - curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr, st->silk_mode.LBRR_coded, - st->stream_channels); - st->silk_mode.maxBits = maxBitRate * frame_size / st->Fs; - } - } - - if (prefill) { - opus_int32 zero = 0; - int prefill_offset; - /* Use a smooth onset for the SILK prefill to avoid the encoder trying to encode - a discontinuity. The exact location is what we need to avoid leaving any "gap" - in the audio when mixing with the redundant CELT frame. Here we can afford to - overwrite st->delay_buffer because the only thing that uses it before it gets - rewritten is tmp_prefill[] and even then only the part after the ramp really - gets used (rather than sent to the encoder and discarded) */ - prefill_offset = st->channels * (st->encoder_buffer - st->delay_compensation - st->Fs / 400); - gain_fade(st->delay_buffer + prefill_offset, st->delay_buffer + prefill_offset, - 0, Q15ONE, celt_mode->overlap, st->Fs / 400, st->channels, celt_mode->window, st->Fs); - OPUS_CLEAR(st->delay_buffer, prefill_offset); -#ifdef FIXED_POINT - pcm_silk = st->delay_buffer; -#else - for (i = 0; i < st->encoder_buffer * st->channels; i++) { - pcm_silk[i] = FLOAT2INT16(st->delay_buffer[i]); - } -#endif - silk_Encode(silk_enc, &st->silk_mode, pcm_silk, st->encoder_buffer, NULL, &zero, prefill, activity); - /* Prevent a second switch in the real encode call. */ - st->silk_mode.opusCanSwitch = 0; - } - -#ifdef FIXED_POINT - pcm_silk = pcm_buf + total_buffer * st->channels; -#else - for (i = 0; i < frame_size * st->channels; i++) { - pcm_silk[i] = FLOAT2INT16(pcm_buf[total_buffer * st->channels + i]); - } -#endif - ret = silk_Encode(silk_enc, &st->silk_mode, pcm_silk, frame_size, &enc, &nBytes, 0, activity); - if (ret) { - /*fprintf (stderr, "SILK encode error: %d\n", ret);*/ - /* Handle error */ - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - - /* Extract SILK internal bandwidth for signaling in first byte */ - if (st->mode == MODE_SILK_ONLY) { - if (st->silk_mode.internalSampleRate == 8000) { - curr_bandwidth = OPUS_BANDWIDTH_NARROWBAND; - } else if (st->silk_mode.internalSampleRate == 12000) { - curr_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND; - } else if (st->silk_mode.internalSampleRate == 16000) { - curr_bandwidth = OPUS_BANDWIDTH_WIDEBAND; - } - } else { - celt_assert(st->silk_mode.internalSampleRate == 16000); - } - - st->silk_mode.opusCanSwitch = st->silk_mode.switchReady && !st->nonfinal_frame; - - if (nBytes == 0) { - st->rangeFinal = 0; - data[-1] = gen_toc(st->mode, st->Fs / frame_size, curr_bandwidth, st->stream_channels); - RESTORE_STACK; - return 1; - } - - /* FIXME: How do we allocate the redundancy for CBR? */ - if (st->silk_mode.opusCanSwitch) { - redundancy_bytes = compute_redundancy_bytes(max_data_bytes, st->bitrate_bps, frame_rate, st->stream_channels); - redundancy = (redundancy_bytes != 0); - celt_to_silk = 0; - st->silk_bw_switch = 1; - } - } - - /* CELT processing */ - { - int endband = 21; - - switch (curr_bandwidth) { - case OPUS_BANDWIDTH_NARROWBAND: - endband = 13; - break; - case OPUS_BANDWIDTH_MEDIUMBAND: - case OPUS_BANDWIDTH_WIDEBAND: - endband = 17; - break; - case OPUS_BANDWIDTH_SUPERWIDEBAND: - endband = 19; - break; - case OPUS_BANDWIDTH_FULLBAND: - endband = 21; - break; - } - celt_encoder_ctl(celt_enc, CELT_SET_END_BAND(endband)); - celt_encoder_ctl(celt_enc, CELT_SET_CHANNELS(st->stream_channels)); - } - celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(OPUS_BITRATE_MAX)); - if (st->mode != MODE_SILK_ONLY) { - opus_val32 celt_pred = 2; - celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0)); - /* We may still decide to disable prediction later */ - if (st->silk_mode.reducedDependency) { - celt_pred = 0; - } - celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(celt_pred)); - - if (st->mode == MODE_HYBRID) { - if (st->use_vbr) { - celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps - st->silk_mode.bitRate)); - celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(0)); - } - } else { - if (st->use_vbr) { - celt_encoder_ctl(celt_enc, OPUS_SET_VBR(1)); - celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(st->vbr_constraint)); - celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps)); - } - } - } - - ALLOC(tmp_prefill, st->channels * st->Fs / 400, opus_val16); - if (st->mode != MODE_SILK_ONLY && st->mode != st->prev_mode && st->prev_mode > 0) { - OPUS_COPY(tmp_prefill, &st->delay_buffer[(st->encoder_buffer - total_buffer - st->Fs / 400)*st->channels], st->channels * st->Fs / 400); - } - - if (st->channels * (st->encoder_buffer - (frame_size + total_buffer)) > 0) { - OPUS_MOVE(st->delay_buffer, &st->delay_buffer[st->channels * frame_size], st->channels * (st->encoder_buffer - frame_size - total_buffer)); - OPUS_COPY(&st->delay_buffer[st->channels * (st->encoder_buffer - frame_size - total_buffer)], - &pcm_buf[0], - (frame_size + total_buffer)*st->channels); - } else { - OPUS_COPY(st->delay_buffer, &pcm_buf[(frame_size + total_buffer - st->encoder_buffer)*st->channels], st->encoder_buffer * st->channels); - } - /* gain_fade() and stereo_fade() need to be after the buffer copying - because we don't want any of this to affect the SILK part */ - if (st->prev_HB_gain < Q15ONE || HB_gain < Q15ONE) { - gain_fade(pcm_buf, pcm_buf, - st->prev_HB_gain, HB_gain, celt_mode->overlap, frame_size, st->channels, celt_mode->window, st->Fs); - } - st->prev_HB_gain = HB_gain; - if (st->mode != MODE_HYBRID || st->stream_channels == 1) { - if (equiv_rate > 32000) { - st->silk_mode.stereoWidth_Q14 = 16384; - } else if (equiv_rate < 16000) { - st->silk_mode.stereoWidth_Q14 = 0; - } else { - st->silk_mode.stereoWidth_Q14 = 16384 - 2048 * (opus_int32)(32000 - equiv_rate) / (equiv_rate - 14000); - } - } - if (!st->energy_masking && st->channels == 2) { - /* Apply stereo width reduction (at low bitrates) */ - if (st->hybrid_stereo_width_Q14 < (1 << 14) || st->silk_mode.stereoWidth_Q14 < (1 << 14)) { - opus_val16 g1, g2; - g1 = st->hybrid_stereo_width_Q14; - g2 = (opus_val16)(st->silk_mode.stereoWidth_Q14); -#ifdef FIXED_POINT - g1 = g1 == 16384 ? Q15ONE : SHL16(g1, 1); - g2 = g2 == 16384 ? Q15ONE : SHL16(g2, 1); -#else - g1 *= (1.f / 16384); - g2 *= (1.f / 16384); -#endif - stereo_fade(pcm_buf, pcm_buf, g1, g2, celt_mode->overlap, - frame_size, st->channels, celt_mode->window, st->Fs); - st->hybrid_stereo_width_Q14 = st->silk_mode.stereoWidth_Q14; - } - } - - if (st->mode != MODE_CELT_ONLY && ec_tell(&enc) + 17 + 20 * (st->mode == MODE_HYBRID) <= 8 * (max_data_bytes - 1)) { - /* For SILK mode, the redundancy is inferred from the length */ - if (st->mode == MODE_HYBRID) { - ec_enc_bit_logp(&enc, redundancy, 12); - } - if (redundancy) { - int max_redundancy; - ec_enc_bit_logp(&enc, celt_to_silk, 1); - if (st->mode == MODE_HYBRID) { - /* Reserve the 8 bits needed for the redundancy length, - and at least a few bits for CELT if possible */ - max_redundancy = (max_data_bytes - 1) - ((ec_tell(&enc) + 8 + 3 + 7) >> 3); - } else { - max_redundancy = (max_data_bytes - 1) - ((ec_tell(&enc) + 7) >> 3); - } - /* Target the same bit-rate for redundancy as for the rest, - up to a max of 257 bytes */ - redundancy_bytes = IMIN(max_redundancy, redundancy_bytes); - redundancy_bytes = IMIN(257, IMAX(2, redundancy_bytes)); - if (st->mode == MODE_HYBRID) { - ec_enc_uint(&enc, redundancy_bytes - 2, 256); - } - } - } else { - redundancy = 0; - } - - if (!redundancy) { - st->silk_bw_switch = 0; - redundancy_bytes = 0; - } - if (st->mode != MODE_CELT_ONLY) { - start_band = 17; - } - - if (st->mode == MODE_SILK_ONLY) { - ret = (ec_tell(&enc) + 7) >> 3; - ec_enc_done(&enc); - nb_compr_bytes = ret; - } else { - nb_compr_bytes = (max_data_bytes - 1) - redundancy_bytes; - ec_enc_shrink(&enc, nb_compr_bytes); - } - -#ifndef DISABLE_FLOAT_API - if (redundancy || st->mode != MODE_SILK_ONLY) { - celt_encoder_ctl(celt_enc, CELT_SET_ANALYSIS(&analysis_info)); - } -#endif - if (st->mode == MODE_HYBRID) { - SILKInfo info; - info.signalType = st->silk_mode.signalType; - info.offset = st->silk_mode.offset; - celt_encoder_ctl(celt_enc, CELT_SET_SILK_INFO(&info)); - } - - /* 5 ms redundant frame for CELT->SILK */ - if (redundancy && celt_to_silk) { - int err; - celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0)); - celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0)); - celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(OPUS_BITRATE_MAX)); - err = celt_encode_with_ec(celt_enc, pcm_buf, st->Fs / 200, data + nb_compr_bytes, redundancy_bytes, NULL); - if (err < 0) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - celt_encoder_ctl(celt_enc, OPUS_GET_FINAL_RANGE(&redundant_rng)); - celt_encoder_ctl(celt_enc, OPUS_RESET_STATE); - } - - celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(start_band)); - - if (st->mode != MODE_SILK_ONLY) { - if (st->mode != st->prev_mode && st->prev_mode > 0) { - unsigned char dummy[2]; - celt_encoder_ctl(celt_enc, OPUS_RESET_STATE); - - /* Prefilling */ - celt_encode_with_ec(celt_enc, tmp_prefill, st->Fs / 400, dummy, 2, NULL); - celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0)); - } - /* If false, we already busted the budget and we'll end up with a "PLC frame" */ - if (ec_tell(&enc) <= 8 * nb_compr_bytes) { - /* Set the bitrate again if it was overridden in the redundancy code above*/ - if (redundancy && celt_to_silk && st->mode == MODE_HYBRID && st->use_vbr) { - celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps - st->silk_mode.bitRate)); - } - celt_encoder_ctl(celt_enc, OPUS_SET_VBR(st->use_vbr)); - ret = celt_encode_with_ec(celt_enc, pcm_buf, frame_size, NULL, nb_compr_bytes, &enc); - if (ret < 0) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - /* Put CELT->SILK redundancy data in the right place. */ - if (redundancy && celt_to_silk && st->mode == MODE_HYBRID && st->use_vbr) { - OPUS_MOVE(data + ret, data + nb_compr_bytes, redundancy_bytes); - nb_compr_bytes = nb_compr_bytes + redundancy_bytes; - } - } - } - - /* 5 ms redundant frame for SILK->CELT */ - if (redundancy && !celt_to_silk) { - int err; - unsigned char dummy[2]; - int N2, N4; - N2 = st->Fs / 200; - N4 = st->Fs / 400; - - celt_encoder_ctl(celt_enc, OPUS_RESET_STATE); - celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0)); - celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0)); - celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0)); - celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(OPUS_BITRATE_MAX)); - - if (st->mode == MODE_HYBRID) { - /* Shrink packet to what the encoder actually used. */ - nb_compr_bytes = ret; - ec_enc_shrink(&enc, nb_compr_bytes); - } - /* NOTE: We could speed this up slightly (at the expense of code size) by just adding a function that prefills the buffer */ - celt_encode_with_ec(celt_enc, pcm_buf + st->channels * (frame_size - N2 - N4), N4, dummy, 2, NULL); - - err = celt_encode_with_ec(celt_enc, pcm_buf + st->channels * (frame_size - N2), N2, data + nb_compr_bytes, redundancy_bytes, NULL); - if (err < 0) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - celt_encoder_ctl(celt_enc, OPUS_GET_FINAL_RANGE(&redundant_rng)); - } - - - - /* Signalling the mode in the first byte */ - data--; - data[0] = gen_toc(st->mode, st->Fs / frame_size, curr_bandwidth, st->stream_channels); - - st->rangeFinal = enc.rng ^ redundant_rng; - - if (to_celt) { - st->prev_mode = MODE_CELT_ONLY; - } else { - st->prev_mode = st->mode; - } - st->prev_channels = st->stream_channels; - st->prev_framesize = frame_size; - - st->first = 0; - - /* DTX decision */ -#ifndef DISABLE_FLOAT_API - if (st->use_dtx && (analysis_info.valid || is_silence)) { - if (decide_dtx_mode(analysis_info.activity_probability, &st->nb_no_activity_frames, - st->peak_signal_energy, pcm, frame_size, st->channels, is_silence, st->arch)) { - st->rangeFinal = 0; - data[0] = gen_toc(st->mode, st->Fs / frame_size, curr_bandwidth, st->stream_channels); - RESTORE_STACK; - return 1; - } - } else { - st->nb_no_activity_frames = 0; - } -#endif - - /* In the unlikely case that the SILK encoder busted its target, tell - the decoder to call the PLC */ - if (ec_tell(&enc) > (max_data_bytes - 1) * 8) { - if (max_data_bytes < 2) { - RESTORE_STACK; - return OPUS_BUFFER_TOO_SMALL; - } - data[1] = 0; - ret = 1; - st->rangeFinal = 0; - } else if (st->mode == MODE_SILK_ONLY && !redundancy) { - /* When in LPC only mode it's perfectly - reasonable to strip off trailing zero bytes as - the required range decoder behavior is to - fill these in. This can't be done when the MDCT - modes are used because the decoder needs to know - the actual length for allocation purposes.*/ - while (ret > 2 && data[ret] == 0) { - ret--; - } - } - /* Count ToC and redundancy */ - ret += 1 + redundancy_bytes; - if (!st->use_vbr) { - if (opus_packet_pad(data, ret, max_data_bytes) != OPUS_OK) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - ret = max_data_bytes; - } - RESTORE_STACK; - return ret; -} - -#ifdef FIXED_POINT - -#ifndef DISABLE_FLOAT_API -opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int analysis_frame_size, - unsigned char *data, opus_int32 max_data_bytes) { - int i, ret; - int frame_size; - VARDECL(opus_int16, in); - ALLOC_STACK; - - frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); - if (frame_size <= 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - ALLOC(in, frame_size * st->channels, opus_int16); - - for (i = 0; i < frame_size * st->channels; i++) { - in[i] = FLOAT2INT16(pcm[i]); - } - ret = opus_encode_native(st, in, frame_size, data, max_data_bytes, 16, - pcm, analysis_frame_size, 0, -2, st->channels, downmix_float, 1); - RESTORE_STACK; - return ret; -} -#endif - -opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int analysis_frame_size, - unsigned char *data, opus_int32 out_data_bytes) { - int frame_size; - frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); - return opus_encode_native(st, pcm, frame_size, data, out_data_bytes, 16, - pcm, analysis_frame_size, 0, -2, st->channels, downmix_int, 0); -} - -#else -opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int analysis_frame_size, - unsigned char *data, opus_int32 max_data_bytes) { - int i, ret; - int frame_size; - VARDECL(float, in); - ALLOC_STACK; - - frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); - if (frame_size <= 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - ALLOC(in, frame_size * st->channels, float); - - for (i = 0; i < frame_size * st->channels; i++) { - in[i] = (1.0f / 32768) * pcm[i]; - } - ret = opus_encode_native(st, in, frame_size, data, max_data_bytes, 16, - pcm, analysis_frame_size, 0, -2, st->channels, downmix_int, 0); - RESTORE_STACK; - return ret; -} -opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int analysis_frame_size, - unsigned char *data, opus_int32 out_data_bytes) { - int frame_size; - frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); - return opus_encode_native(st, pcm, frame_size, data, out_data_bytes, 24, - pcm, analysis_frame_size, 0, -2, st->channels, downmix_float, 1); -} -#endif - - -int opus_encoder_ctl(OpusEncoder *st, int request, ...) { - int ret; - CELTEncoder *celt_enc; - va_list ap; - - ret = OPUS_OK; - va_start(ap, request); - - celt_enc = (CELTEncoder*)((char*)st + st->celt_enc_offset); - - switch (request) { - case OPUS_SET_APPLICATION_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if ((value != OPUS_APPLICATION_VOIP && value != OPUS_APPLICATION_AUDIO - && value != OPUS_APPLICATION_RESTRICTED_LOWDELAY) - || (!st->first && st->application != value)) { - ret = OPUS_BAD_ARG; - break; - } - st->application = value; -#ifndef DISABLE_FLOAT_API - st->analysis.application = value; -#endif - } - break; - case OPUS_GET_APPLICATION_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->application; - } - break; - case OPUS_SET_BITRATE_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value != OPUS_AUTO && value != OPUS_BITRATE_MAX) { - if (value <= 0) { - goto bad_arg; - } else if (value <= 500) { - value = 500; - } else if (value > (opus_int32)300000 * st->channels) { - value = (opus_int32)300000 * st->channels; - } - } - st->user_bitrate_bps = value; - } - break; - case OPUS_GET_BITRATE_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = user_bitrate_to_bitrate(st, st->prev_framesize, 1276); - } - break; - case OPUS_SET_FORCE_CHANNELS_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if ((value < 1 || value > st->channels) && value != OPUS_AUTO) { - goto bad_arg; - } - st->force_channels = value; - } - break; - case OPUS_GET_FORCE_CHANNELS_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->force_channels; - } - break; - case OPUS_SET_MAX_BANDWIDTH_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < OPUS_BANDWIDTH_NARROWBAND || value > OPUS_BANDWIDTH_FULLBAND) { - goto bad_arg; - } - st->max_bandwidth = value; - if (st->max_bandwidth == OPUS_BANDWIDTH_NARROWBAND) { - st->silk_mode.maxInternalSampleRate = 8000; - } else if (st->max_bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - st->silk_mode.maxInternalSampleRate = 12000; - } else { - st->silk_mode.maxInternalSampleRate = 16000; - } - } - break; - case OPUS_GET_MAX_BANDWIDTH_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->max_bandwidth; - } - break; - case OPUS_SET_BANDWIDTH_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if ((value < OPUS_BANDWIDTH_NARROWBAND || value > OPUS_BANDWIDTH_FULLBAND) && value != OPUS_AUTO) { - goto bad_arg; - } - st->user_bandwidth = value; - if (st->user_bandwidth == OPUS_BANDWIDTH_NARROWBAND) { - st->silk_mode.maxInternalSampleRate = 8000; - } else if (st->user_bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) { - st->silk_mode.maxInternalSampleRate = 12000; - } else { - st->silk_mode.maxInternalSampleRate = 16000; - } - } - break; - case OPUS_GET_BANDWIDTH_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->bandwidth; - } - break; - case OPUS_SET_DTX_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - st->use_dtx = value; - } - break; - case OPUS_GET_DTX_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->use_dtx; - } - break; - case OPUS_SET_COMPLEXITY_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 10) { - goto bad_arg; - } - st->silk_mode.complexity = value; - celt_encoder_ctl(celt_enc, OPUS_SET_COMPLEXITY(value)); - } - break; - case OPUS_GET_COMPLEXITY_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->silk_mode.complexity; - } - break; - case OPUS_SET_INBAND_FEC_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - st->silk_mode.useInBandFEC = value; - } - break; - case OPUS_GET_INBAND_FEC_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->silk_mode.useInBandFEC; - } - break; - case OPUS_SET_PACKET_LOSS_PERC_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 100) { - goto bad_arg; - } - st->silk_mode.packetLossPercentage = value; - celt_encoder_ctl(celt_enc, OPUS_SET_PACKET_LOSS_PERC(value)); - } - break; - case OPUS_GET_PACKET_LOSS_PERC_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->silk_mode.packetLossPercentage; - } - break; - case OPUS_SET_VBR_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - st->use_vbr = value; - st->silk_mode.useCBR = 1 - value; - } - break; - case OPUS_GET_VBR_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->use_vbr; - } - break; - case OPUS_SET_VOICE_RATIO_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < -1 || value > 100) { - goto bad_arg; - } - st->voice_ratio = value; - } - break; - case OPUS_GET_VOICE_RATIO_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->voice_ratio; - } - break; - case OPUS_SET_VBR_CONSTRAINT_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - st->vbr_constraint = value; - } - break; - case OPUS_GET_VBR_CONSTRAINT_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->vbr_constraint; - } - break; - case OPUS_SET_SIGNAL_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value != OPUS_AUTO && value != OPUS_SIGNAL_VOICE && value != OPUS_SIGNAL_MUSIC) { - goto bad_arg; - } - st->signal_type = value; - } - break; - case OPUS_GET_SIGNAL_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->signal_type; - } - break; - case OPUS_GET_LOOKAHEAD_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->Fs / 400; - if (st->application != OPUS_APPLICATION_RESTRICTED_LOWDELAY) { - *value += st->delay_compensation; - } - } - break; - case OPUS_GET_SAMPLE_RATE_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->Fs; - } - break; - case OPUS_GET_FINAL_RANGE_REQUEST: { - opus_uint32 *value = va_arg(ap, opus_uint32*); - if (!value) { - goto bad_arg; - } - *value = st->rangeFinal; - } - break; - case OPUS_SET_LSB_DEPTH_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 8 || value > 24) { - goto bad_arg; - } - st->lsb_depth = value; - } - break; - case OPUS_GET_LSB_DEPTH_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->lsb_depth; - } - break; - case OPUS_SET_EXPERT_FRAME_DURATION_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value != OPUS_FRAMESIZE_ARG && value != OPUS_FRAMESIZE_2_5_MS && - value != OPUS_FRAMESIZE_5_MS && value != OPUS_FRAMESIZE_10_MS && - value != OPUS_FRAMESIZE_20_MS && value != OPUS_FRAMESIZE_40_MS && - value != OPUS_FRAMESIZE_60_MS && value != OPUS_FRAMESIZE_80_MS && - value != OPUS_FRAMESIZE_100_MS && value != OPUS_FRAMESIZE_120_MS) { - goto bad_arg; - } - st->variable_duration = value; - } - break; - case OPUS_GET_EXPERT_FRAME_DURATION_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->variable_duration; - } - break; - case OPUS_SET_PREDICTION_DISABLED_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value > 1 || value < 0) { - goto bad_arg; - } - st->silk_mode.reducedDependency = value; - } - break; - case OPUS_GET_PREDICTION_DISABLED_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->silk_mode.reducedDependency; - } - break; - case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value < 0 || value > 1) { - goto bad_arg; - } - celt_encoder_ctl(celt_enc, OPUS_SET_PHASE_INVERSION_DISABLED(value)); - } - break; - case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - celt_encoder_ctl(celt_enc, OPUS_GET_PHASE_INVERSION_DISABLED(value)); - } - break; - case OPUS_RESET_STATE: { - void *silk_enc; - silk_EncControlStruct dummy; - char *start; - silk_enc = (char*)st + st->silk_enc_offset; -#ifndef DISABLE_FLOAT_API - tonality_analysis_reset(&st->analysis); -#endif - - start = (char*)&st->OPUS_ENCODER_RESET_START; - OPUS_CLEAR(start, sizeof(OpusEncoder) - (start - (char*)st)); - - celt_encoder_ctl(celt_enc, OPUS_RESET_STATE); - silk_InitEncoder(silk_enc, st->arch, &dummy); - st->stream_channels = st->channels; - st->hybrid_stereo_width_Q14 = 1 << 14; - st->prev_HB_gain = Q15ONE; - st->first = 1; - st->mode = MODE_HYBRID; - st->bandwidth = OPUS_BANDWIDTH_FULLBAND; - st->variable_HP_smth2_Q15 = silk_LSHIFT(silk_lin2log(VARIABLE_HP_MIN_CUTOFF_HZ), 8); - } - break; - case OPUS_SET_FORCE_MODE_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if ((value < MODE_SILK_ONLY || value > MODE_CELT_ONLY) && value != OPUS_AUTO) { - goto bad_arg; - } - st->user_forced_mode = value; - } - break; - case OPUS_SET_LFE_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->lfe = value; - ret = celt_encoder_ctl(celt_enc, OPUS_SET_LFE(value)); - } - break; - case OPUS_SET_ENERGY_MASK_REQUEST: { - opus_val16 *value = va_arg(ap, opus_val16*); - st->energy_masking = value; - ret = celt_encoder_ctl(celt_enc, OPUS_SET_ENERGY_MASK(value)); - } - break; - case OPUS_GET_IN_DTX_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - if (st->silk_mode.useDTX && (st->prev_mode == MODE_SILK_ONLY || st->prev_mode == MODE_HYBRID)) { - /* DTX determined by Silk. */ - int n; - void *silk_enc = (char*)st + st->silk_enc_offset; - *value = 1; - for (n = 0; n < st->silk_mode.nChannelsInternal; n++) { - *value = *value && ((silk_encoder*)silk_enc)->state_Fxx[n].sCmn.noSpeechCounter >= NB_SPEECH_FRAMES_BEFORE_DTX; - } - } -#ifndef DISABLE_FLOAT_API - else if (st->use_dtx) { - /* DTX determined by Opus. */ - *value = st->nb_no_activity_frames >= NB_SPEECH_FRAMES_BEFORE_DTX; - } -#endif - else { - *value = 0; - } - } - break; - - case CELT_GET_MODE_REQUEST: { - const CELTMode ** value = va_arg(ap, const CELTMode**); - if (!value) { - goto bad_arg; - } - ret = celt_encoder_ctl(celt_enc, CELT_GET_MODE(value)); - } - break; - default: - /* fprintf(stderr, "unknown opus_encoder_ctl() request: %d", request);*/ - ret = OPUS_UNIMPLEMENTED; - break; - } - va_end(ap); - return ret; -bad_arg: - va_end(ap); - return OPUS_BAD_ARG; -} - -void opus_encoder_destroy(OpusEncoder *st) { - opus_free(st); -} -#endif diff --git a/src/libopus/opus_multistream.c b/src/libopus/opus_multistream.c deleted file mode 100644 index 0363ea2..0000000 --- a/src/libopus/opus_multistream.c +++ /dev/null @@ -1,89 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "opus_multistream.h" -#include "opus.h" -#include "opus_private.h" -#include "celt/stack_alloc.h" -#include -#include "celt/float_cast.h" -#include "celt/os_support.h" - - -int validate_layout(const ChannelLayout *layout) { - int i, max_channel; - - max_channel = layout->nb_streams + layout->nb_coupled_streams; - if (max_channel > 255) { - return 0; - } - for (i = 0; i < layout->nb_channels; i++) { - if (layout->mapping[i] >= max_channel && layout->mapping[i] != 255) { - return 0; - } - } - return 1; -} - - -int get_left_channel(const ChannelLayout *layout, int stream_id, int prev) { - int i; - i = (prev < 0) ? 0 : prev + 1; - for (; i < layout->nb_channels; i++) { - if (layout->mapping[i] == stream_id * 2) { - return i; - } - } - return -1; -} - -int get_right_channel(const ChannelLayout *layout, int stream_id, int prev) { - int i; - i = (prev < 0) ? 0 : prev + 1; - for (; i < layout->nb_channels; i++) { - if (layout->mapping[i] == stream_id * 2 + 1) { - return i; - } - } - return -1; -} - -int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev) { - int i; - i = (prev < 0) ? 0 : prev + 1; - for (; i < layout->nb_channels; i++) { - if (layout->mapping[i] == stream_id + layout->nb_coupled_streams) { - return i; - } - } - return -1; -} - diff --git a/src/libopus/opus_multistream.h b/src/libopus/opus_multistream.h deleted file mode 100644 index 004f89c..0000000 --- a/src/libopus/opus_multistream.h +++ /dev/null @@ -1,660 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - @file opus_multistream.h - @brief Opus reference implementation multistream API -*/ - -#ifndef OPUS_MULTISTREAM_H -#define OPUS_MULTISTREAM_H - -#include "opus.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @cond OPUS_INTERNAL_DOC */ - -/** Macros to trigger compilation errors when the wrong types are provided to a - CTL. */ -/**@{*/ -#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) -#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) -/**@}*/ - -/** These are the actual encoder and decoder CTL ID numbers. - They should not be used directly by applications. - In general, SETs should be even and GETs should be odd.*/ -/**@{*/ -#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 -#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 -/**@}*/ - -/** @endcond */ - -/** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs - - These are convenience macros that are specific to the - opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl() - interface. - The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and - @ref opus_decoderctls may be applied to a multistream encoder or decoder as - well. - In addition, you may retrieve the encoder or decoder state for an specific - stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or - #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually. -*/ -/**@{*/ - -/** Gets the encoder state for an individual stream of a multistream encoder. - @param[in] x opus_int32: The index of the stream whose encoder you - wish to retrieve. - This must be non-negative and less than - the streams parameter used - to initialize the encoder. - @param[out] y OpusEncoder**: Returns a pointer to the given - encoder state. - @retval OPUS_BAD_ARG The index of the requested stream was out of range. - @hideinitializer -*/ -#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) - -/** Gets the decoder state for an individual stream of a multistream decoder. - @param[in] x opus_int32: The index of the stream whose decoder you - wish to retrieve. - This must be non-negative and less than - the streams parameter used - to initialize the decoder. - @param[out] y OpusDecoder**: Returns a pointer to the given - decoder state. - @retval OPUS_BAD_ARG The index of the requested stream was out of range. - @hideinitializer -*/ -#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) - -/**@}*/ - -/** @defgroup opus_multistream Opus Multistream API - @{ - - The multistream API allows individual Opus streams to be combined into a - single packet, enabling support for up to 255 channels. Unlike an - elementary Opus stream, the encoder and decoder must negotiate the channel - configuration before the decoder can successfully interpret the data in the - packets produced by the encoder. Some basic information, such as packet - duration, can be computed without any special negotiation. - - The format for multistream Opus packets is defined in - RFC 7845 - and is based on the self-delimited Opus framing described in Appendix B of - RFC 6716. - Normal Opus packets are just a degenerate case of multistream Opus packets, - and can be encoded or decoded with the multistream API by setting - streams to 1 when initializing the encoder or - decoder. - - Multistream Opus streams can contain up to 255 elementary Opus streams. - These may be either "uncoupled" or "coupled", indicating that the decoder - is configured to decode them to either 1 or 2 channels, respectively. - The streams are ordered so that all coupled streams appear at the - beginning. - - A mapping table defines which decoded channel i - should be used for each input/output (I/O) channel j. This table is - typically provided as an unsigned char array. - Let i = mapping[j] be the index for I/O channel j. - If i < 2*coupled_streams, then I/O channel j is - encoded as the left channel of stream (i/2) if i - is even, or as the right channel of stream (i/2) if - i is odd. Otherwise, I/O channel j is encoded as - mono in stream (i - coupled_streams), unless it has the special - value 255, in which case it is omitted from the encoding entirely (the - decoder will reproduce it as silence). Each value i must either - be the special value 255 or be less than streams + coupled_streams. - - The output channels specified by the encoder - should use the - Vorbis - channel ordering. A decoder may wish to apply an additional permutation - to the mapping the encoder used to achieve a different output channel - order (e.g. for outputing in WAV order). - - Each multistream packet contains an Opus packet for each stream, and all of - the Opus packets in a single multistream packet must have the same - duration. Therefore the duration of a multistream packet can be extracted - from the TOC sequence of the first stream, which is located at the - beginning of the packet, just like an elementary Opus stream: - - @code - int nb_samples; - int nb_frames; - nb_frames = opus_packet_get_nb_frames(data, len); - if (nb_frames < 1) - return nb_frames; - nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames; - @endcode - - The general encoding and decoding process proceeds exactly the same as in - the normal @ref opus_encoder and @ref opus_decoder APIs. - See their documentation for an overview of how to use the corresponding - multistream functions. -*/ - -/** Opus multistream encoder state. - This contains the complete state of a multistream Opus encoder. - It is position independent and can be freely copied. - @see opus_multistream_encoder_create - @see opus_multistream_encoder_init -*/ -typedef struct OpusMSEncoder OpusMSEncoder; - -/** Opus multistream decoder state. - This contains the complete state of a multistream Opus decoder. - It is position independent and can be freely copied. - @see opus_multistream_decoder_create - @see opus_multistream_decoder_init -*/ -typedef struct OpusMSDecoder OpusMSDecoder; - -/**\name Multistream encoder functions */ -/**@{*/ - -/** Gets the size of an OpusMSEncoder structure. - @param streams int: The total number of streams to encode from the - input. - This must be no more than 255. - @param coupled_streams int: Number of coupled (2 channel) streams - to encode. - This must be no larger than the total - number of streams. - Additionally, The total number of - encoded channels (streams + - coupled_streams) must be no - more than 255. - @returns The size in bytes on success, or a negative error code - (see @ref opus_errorcodes) on error. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size( - int streams, - int coupled_streams -); - -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_surround_encoder_get_size( - int channels, - int mapping_family -); - - -/** Allocates and initializes a multistream encoder state. - Call opus_multistream_encoder_destroy() to release - this object when finished. - @param Fs opus_int32: Sampling rate of the input signal (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels in the input signal. - This must be at most 255. - It may be greater than the number of - coded channels (streams + - coupled_streams). - @param streams int: The total number of streams to encode from the - input. - This must be no more than the number of channels. - @param coupled_streams int: Number of coupled (2 channel) streams - to encode. - This must be no larger than the total - number of streams. - Additionally, The total number of - encoded channels (streams + - coupled_streams) must be no - more than the number of input channels. - @param[in] mapping const unsigned char[channels]: Mapping from - encoded channels to input channels, as described in - @ref opus_multistream. As an extra constraint, the - multistream encoder does not allow encoding coupled - streams for which one channel is unused since this - is never a good idea. - @param application int: The target encoder application. - This must be one of the following: -
-
#OPUS_APPLICATION_VOIP
-
Process signal for improved speech intelligibility.
-
#OPUS_APPLICATION_AUDIO
-
Favor faithfulness to the original input.
-
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
-
Configure the minimum possible coding delay by disabling certain modes - of operation.
-
- @param[out] error int *: Returns #OPUS_OK on success, or an error - code (see @ref opus_errorcodes) on - failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int application, - int *error -) OPUS_ARG_NONNULL(5); - -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_surround_encoder_create( - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - unsigned char *mapping, - int application, - int *error -) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); - -/** Initialize a previously allocated multistream encoder state. - The memory pointed to by \a st must be at least the size returned by - opus_multistream_encoder_get_size(). - This is intended for applications which use their own allocator instead of - malloc. - To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - @see opus_multistream_encoder_create - @see opus_multistream_encoder_get_size - @param st OpusMSEncoder*: Multistream encoder state to initialize. - @param Fs opus_int32: Sampling rate of the input signal (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels in the input signal. - This must be at most 255. - It may be greater than the number of - coded channels (streams + - coupled_streams). - @param streams int: The total number of streams to encode from the - input. - This must be no more than the number of channels. - @param coupled_streams int: Number of coupled (2 channel) streams - to encode. - This must be no larger than the total - number of streams. - Additionally, The total number of - encoded channels (streams + - coupled_streams) must be no - more than the number of input channels. - @param[in] mapping const unsigned char[channels]: Mapping from - encoded channels to input channels, as described in - @ref opus_multistream. As an extra constraint, the - multistream encoder does not allow encoding coupled - streams for which one channel is unused since this - is never a good idea. - @param application int: The target encoder application. - This must be one of the following: -
-
#OPUS_APPLICATION_VOIP
-
Process signal for improved speech intelligibility.
-
#OPUS_APPLICATION_AUDIO
-
Favor faithfulness to the original input.
-
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
-
Configure the minimum possible coding delay by disabling certain modes - of operation.
-
- @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - on failure. -*/ -OPUS_EXPORT int opus_multistream_encoder_init( - OpusMSEncoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int application -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); - -OPUS_EXPORT int opus_multistream_surround_encoder_init( - OpusMSEncoder *st, - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - unsigned char *mapping, - int application -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6) OPUS_ARG_NONNULL(7); - -/** Encodes a multistream Opus frame. - @param st OpusMSEncoder*: Multistream encoder state. - @param[in] pcm const opus_int16*: The input signal as interleaved - samples. - This must contain - frame_size*channels - samples. - @param frame_size int: Number of samples per channel in the input - signal. - This must be an Opus frame size for the - encoder's sampling rate. - For example, at 48 kHz the permitted values - are 120, 240, 480, 960, 1920, and 2880. - Passing in a duration of less than 10 ms - (480 samples at 48 kHz) will prevent the - encoder from using the LPC or hybrid modes. - @param[out] data unsigned char*: Output payload. - This must contain storage for at - least \a max_data_bytes. - @param [in] max_data_bytes opus_int32: Size of the allocated - memory for the output - payload. This may be - used to impose an upper limit on - the instant bitrate, but should - not be used as the only bitrate - control. Use #OPUS_SET_BITRATE to - control the bitrate. - @returns The length of the encoded packet (in bytes) on success or a - negative error code (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( - OpusMSEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Encodes a multistream Opus frame from floating point input. - @param st OpusMSEncoder*: Multistream encoder state. - @param[in] pcm const float*: The input signal as interleaved - samples with a normal range of - +/-1.0. - Samples with a range beyond +/-1.0 - are supported but will be clipped by - decoders using the integer API and - should only be used if it is known - that the far end supports extended - dynamic range. - This must contain - frame_size*channels - samples. - @param frame_size int: Number of samples per channel in the input - signal. - This must be an Opus frame size for the - encoder's sampling rate. - For example, at 48 kHz the permitted values - are 120, 240, 480, 960, 1920, and 2880. - Passing in a duration of less than 10 ms - (480 samples at 48 kHz) will prevent the - encoder from using the LPC or hybrid modes. - @param[out] data unsigned char*: Output payload. - This must contain storage for at - least \a max_data_bytes. - @param [in] max_data_bytes opus_int32: Size of the allocated - memory for the output - payload. This may be - used to impose an upper limit on - the instant bitrate, but should - not be used as the only bitrate - control. Use #OPUS_SET_BITRATE to - control the bitrate. - @returns The length of the encoded packet (in bytes) on success or a - negative error code (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( - OpusMSEncoder *st, - const float *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Frees an OpusMSEncoder allocated by - opus_multistream_encoder_create(). - @param st OpusMSEncoder*: Multistream encoder state to be freed. -*/ -OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); - -/** Perform a CTL function on a multistream Opus encoder. - - Generally the request and subsequent arguments are generated by a - convenience macro. - @param st OpusMSEncoder*: Multistream encoder state. - @param request This and all remaining parameters should be replaced by one - of the convenience macros in @ref opus_genericctls, - @ref opus_encoderctls, or @ref opus_multistream_ctls. - @see opus_genericctls - @see opus_encoderctls - @see opus_multistream_ctls -*/ -OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); - -/**@}*/ - -/**\name Multistream decoder functions */ -/**@{*/ - -/** Gets the size of an OpusMSDecoder structure. - @param streams int: The total number of streams coded in the - input. - This must be no more than 255. - @param coupled_streams int: Number streams to decode as coupled - (2 channel) streams. - This must be no larger than the total - number of streams. - Additionally, The total number of - coded channels (streams + - coupled_streams) must be no - more than 255. - @returns The size in bytes on success, or a negative error code - (see @ref opus_errorcodes) on error. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size( - int streams, - int coupled_streams -); - -/** Allocates and initializes a multistream decoder state. - Call opus_multistream_decoder_destroy() to release - this object when finished. - @param Fs opus_int32: Sampling rate to decode at (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels to output. - This must be at most 255. - It may be different from the number of coded - channels (streams + - coupled_streams). - @param streams int: The total number of streams coded in the - input. - This must be no more than 255. - @param coupled_streams int: Number of streams to decode as coupled - (2 channel) streams. - This must be no larger than the total - number of streams. - Additionally, The total number of - coded channels (streams + - coupled_streams) must be no - more than 255. - @param[in] mapping const unsigned char[channels]: Mapping from - coded channels to output channels, as described in - @ref opus_multistream. - @param[out] error int *: Returns #OPUS_OK on success, or an error - code (see @ref opus_errorcodes) on - failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int *error -) OPUS_ARG_NONNULL(5); - -/** Intialize a previously allocated decoder state object. - The memory pointed to by \a st must be at least the size returned by - opus_multistream_encoder_get_size(). - This is intended for applications which use their own allocator instead of - malloc. - To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - @see opus_multistream_decoder_create - @see opus_multistream_deocder_get_size - @param st OpusMSEncoder*: Multistream encoder state to initialize. - @param Fs opus_int32: Sampling rate to decode at (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels to output. - This must be at most 255. - It may be different from the number of coded - channels (streams + - coupled_streams). - @param streams int: The total number of streams coded in the - input. - This must be no more than 255. - @param coupled_streams int: Number of streams to decode as coupled - (2 channel) streams. - This must be no larger than the total - number of streams. - Additionally, The total number of - coded channels (streams + - coupled_streams) must be no - more than 255. - @param[in] mapping const unsigned char[channels]: Mapping from - coded channels to output channels, as described in - @ref opus_multistream. - @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - on failure. -*/ -OPUS_EXPORT int opus_multistream_decoder_init( - OpusMSDecoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); - -/** Decode a multistream Opus packet. - @param st OpusMSDecoder*: Multistream decoder state. - @param[in] data const unsigned char*: Input payload. - Use a NULL - pointer to indicate packet - loss. - @param len opus_int32: Number of bytes in payload. - @param[out] pcm opus_int16*: Output signal, with interleaved - samples. - This must contain room for - frame_size*channels - samples. - @param frame_size int: The number of samples per channel of - available space in \a pcm. - If this is less than the maximum packet duration - (120 ms; 5760 for 48kHz), this function will not be capable - of decoding some packets. In the case of PLC (data==NULL) - or FEC (decode_fec=1), then frame_size needs to be exactly - the duration of audio that is missing, otherwise the - decoder will not be in the optimal state to decode the - next incoming packet. For the PLC and FEC cases, frame_size - must be a multiple of 2.5 ms. - @param decode_fec int: Flag (0 or 1) to request that any in-band - forward error correction data be decoded. - If no such data is available, the frame is - decoded as if it were lost. - @returns Number of samples decoded on success or a negative error code - (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( - OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_int16 *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Decode a multistream Opus packet with floating point output. - @param st OpusMSDecoder*: Multistream decoder state. - @param[in] data const unsigned char*: Input payload. - Use a NULL - pointer to indicate packet - loss. - @param len opus_int32: Number of bytes in payload. - @param[out] pcm opus_int16*: Output signal, with interleaved - samples. - This must contain room for - frame_size*channels - samples. - @param frame_size int: The number of samples per channel of - available space in \a pcm. - If this is less than the maximum packet duration - (120 ms; 5760 for 48kHz), this function will not be capable - of decoding some packets. In the case of PLC (data==NULL) - or FEC (decode_fec=1), then frame_size needs to be exactly - the duration of audio that is missing, otherwise the - decoder will not be in the optimal state to decode the - next incoming packet. For the PLC and FEC cases, frame_size - must be a multiple of 2.5 ms. - @param decode_fec int: Flag (0 or 1) to request that any in-band - forward error correction data be decoded. - If no such data is available, the frame is - decoded as if it were lost. - @returns Number of samples decoded on success or a negative error code - (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( - OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - float *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on a multistream Opus decoder. - - Generally the request and subsequent arguments are generated by a - convenience macro. - @param st OpusMSDecoder*: Multistream decoder state. - @param request This and all remaining parameters should be replaced by one - of the convenience macros in @ref opus_genericctls, - @ref opus_decoderctls, or @ref opus_multistream_ctls. - @see opus_genericctls - @see opus_decoderctls - @see opus_multistream_ctls -*/ -OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); - -/** Frees an OpusMSDecoder allocated by - opus_multistream_decoder_create(). - @param st OpusMSDecoder: Multistream decoder state to be freed. -*/ -OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); - -/**@}*/ - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_MULTISTREAM_H */ diff --git a/src/libopus/opus_multistream_decoder.c b/src/libopus/opus_multistream_decoder.c deleted file mode 100644 index 9880e44..0000000 --- a/src/libopus/opus_multistream_decoder.c +++ /dev/null @@ -1,522 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "opus_multistream.h" -#include "opus.h" -#include "opus_private.h" -#include "celt/stack_alloc.h" -#include -#include "celt/float_cast.h" -#include "celt/os_support.h" - -/* DECODER */ - -#if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS) -static void validate_ms_decoder(OpusMSDecoder *st) { - validate_layout(&st->layout); -} -#define VALIDATE_MS_DECODER(st) validate_ms_decoder(st) -#else -#define VALIDATE_MS_DECODER(st) -#endif - - -opus_int32 opus_multistream_decoder_get_size(int nb_streams, int nb_coupled_streams) { - int coupled_size; - int mono_size; - - if (nb_streams < 1 || nb_coupled_streams > nb_streams || nb_coupled_streams < 0) { - return 0; - } - coupled_size = opus_decoder_get_size(2); - mono_size = opus_decoder_get_size(1); - return align(sizeof(OpusMSDecoder)) - + nb_coupled_streams * align(coupled_size) - + (nb_streams - nb_coupled_streams) * align(mono_size); -} - -int opus_multistream_decoder_init( - OpusMSDecoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping -) { - int coupled_size; - int mono_size; - int i, ret; - char *ptr; - - if ((channels > 255) || (channels < 1) || (coupled_streams > streams) || - (streams < 1) || (coupled_streams < 0) || (streams > 255 - coupled_streams)) { - return OPUS_BAD_ARG; - } - - st->layout.nb_channels = channels; - st->layout.nb_streams = streams; - st->layout.nb_coupled_streams = coupled_streams; - - for (i = 0; i < st->layout.nb_channels; i++) { - st->layout.mapping[i] = mapping[i]; - } - if (!validate_layout(&st->layout)) { - return OPUS_BAD_ARG; - } - - ptr = (char*)st + align(sizeof(OpusMSDecoder)); - coupled_size = opus_decoder_get_size(2); - mono_size = opus_decoder_get_size(1); - - for (i = 0; i < st->layout.nb_coupled_streams; i++) { - ret = opus_decoder_init((OpusDecoder*)ptr, Fs, 2); - if (ret != OPUS_OK) { - return ret; - } - ptr += align(coupled_size); - } - for (; i < st->layout.nb_streams; i++) { - ret = opus_decoder_init((OpusDecoder*)ptr, Fs, 1); - if (ret != OPUS_OK) { - return ret; - } - ptr += align(mono_size); - } - return OPUS_OK; -} - - -OpusMSDecoder *opus_multistream_decoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int *error -) { - int ret; - OpusMSDecoder *st; - if ((channels > 255) || (channels < 1) || (coupled_streams > streams) || - (streams < 1) || (coupled_streams < 0) || (streams > 255 - coupled_streams)) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } - st = (OpusMSDecoder *)opus_alloc(opus_multistream_decoder_get_size(streams, coupled_streams)); - if (st == NULL) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - ret = opus_multistream_decoder_init(st, Fs, channels, streams, coupled_streams, mapping); - if (error) { - *error = ret; - } - if (ret != OPUS_OK) { - opus_free(st); - st = NULL; - } - return st; -} - -static int opus_multistream_packet_validate(const unsigned char *data, - opus_int32 len, int nb_streams, opus_int32 Fs) { - int s; - int count; - unsigned char toc; - opus_int16 size[48]; - int samples = 0; - opus_int32 packet_offset; - - for (s = 0; s < nb_streams; s++) { - int tmp_samples; - if (len <= 0) { - return OPUS_INVALID_PACKET; - } - count = opus_packet_parse_impl(data, len, s != nb_streams - 1, &toc, NULL, - size, NULL, &packet_offset); - if (count < 0) { - return count; - } - tmp_samples = opus_packet_get_nb_samples(data, packet_offset, Fs); - if (s != 0 && samples != tmp_samples) { - return OPUS_INVALID_PACKET; - } - samples = tmp_samples; - data += packet_offset; - len -= packet_offset; - } - return samples; -} - -int opus_multistream_decode_native( - OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - void *pcm, - opus_copy_channel_out_func copy_channel_out, - int frame_size, - int decode_fec, - int soft_clip, - void *user_data -) { - opus_int32 Fs; - int coupled_size; - int mono_size; - int s, c; - char *ptr; - int do_plc = 0; - VARDECL(opus_val16, buf); - ALLOC_STACK; - - VALIDATE_MS_DECODER(st); - if (frame_size <= 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - /* Limit frame_size to avoid excessive stack allocations. */ - MUST_SUCCEED(opus_multistream_decoder_ctl(st, OPUS_GET_SAMPLE_RATE(&Fs))); - frame_size = IMIN(frame_size, Fs / 25 * 3); - ALLOC(buf, 2 * frame_size, opus_val16); - ptr = (char*)st + align(sizeof(OpusMSDecoder)); - coupled_size = opus_decoder_get_size(2); - mono_size = opus_decoder_get_size(1); - - if (len == 0) { - do_plc = 1; - } - if (len < 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - if (!do_plc && len < 2 * st->layout.nb_streams - 1) { - RESTORE_STACK; - return OPUS_INVALID_PACKET; - } - if (!do_plc) { - int ret = opus_multistream_packet_validate(data, len, st->layout.nb_streams, Fs); - if (ret < 0) { - RESTORE_STACK; - return ret; - } else if (ret > frame_size) { - RESTORE_STACK; - return OPUS_BUFFER_TOO_SMALL; - } - } - for (s = 0; s < st->layout.nb_streams; s++) { - OpusDecoder *dec; - opus_int32 packet_offset; - int ret; - - dec = (OpusDecoder*)ptr; - ptr += (s < st->layout.nb_coupled_streams) ? align(coupled_size) : align(mono_size); - - if (!do_plc && len <= 0) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - packet_offset = 0; - ret = opus_decode_native(dec, data, len, buf, frame_size, decode_fec, s != st->layout.nb_streams - 1, &packet_offset, soft_clip); - data += packet_offset; - len -= packet_offset; - if (ret <= 0) { - RESTORE_STACK; - return ret; - } - frame_size = ret; - if (s < st->layout.nb_coupled_streams) { - int chan, prev; - prev = -1; - /* Copy "left" audio to the channel(s) where it belongs */ - while ((chan = get_left_channel(&st->layout, s, prev)) != -1) { - (*copy_channel_out)(pcm, st->layout.nb_channels, chan, - buf, 2, frame_size, user_data); - prev = chan; - } - prev = -1; - /* Copy "right" audio to the channel(s) where it belongs */ - while ((chan = get_right_channel(&st->layout, s, prev)) != -1) { - (*copy_channel_out)(pcm, st->layout.nb_channels, chan, - buf + 1, 2, frame_size, user_data); - prev = chan; - } - } else { - int chan, prev; - prev = -1; - /* Copy audio to the channel(s) where it belongs */ - while ((chan = get_mono_channel(&st->layout, s, prev)) != -1) { - (*copy_channel_out)(pcm, st->layout.nb_channels, chan, - buf, 1, frame_size, user_data); - prev = chan; - } - } - } - /* Handle muted channels */ - for (c = 0; c < st->layout.nb_channels; c++) { - if (st->layout.mapping[c] == 255) { - (*copy_channel_out)(pcm, st->layout.nb_channels, c, - NULL, 0, frame_size, user_data); - } - } - RESTORE_STACK; - return frame_size; -} - -#if !defined(DISABLE_FLOAT_API) -static void opus_copy_channel_out_float( - void *dst, - int dst_stride, - int dst_channel, - const opus_val16 *src, - int src_stride, - int frame_size, - void *user_data -) { - float *float_dst; - opus_int32 i; - (void)user_data; - float_dst = (float*)dst; - if (src != NULL) { - for (i = 0; i < frame_size; i++) -#if defined(FIXED_POINT) - float_dst[i * dst_stride + dst_channel] = (1 / 32768.f) * src[i * src_stride]; -#else - float_dst[i * dst_stride + dst_channel] = src[i * src_stride]; -#endif - } else { - for (i = 0; i < frame_size; i++) { - float_dst[i * dst_stride + dst_channel] = 0; - } - } -} -#endif - -static void opus_copy_channel_out_short( - void *dst, - int dst_stride, - int dst_channel, - const opus_val16 *src, - int src_stride, - int frame_size, - void *user_data -) { - opus_int16 *short_dst; - opus_int32 i; - (void)user_data; - short_dst = (opus_int16*)dst; - if (src != NULL) { - for (i = 0; i < frame_size; i++) -#if defined(FIXED_POINT) - short_dst[i * dst_stride + dst_channel] = src[i * src_stride]; -#else - short_dst[i * dst_stride + dst_channel] = FLOAT2INT16(src[i * src_stride]); -#endif - } else { - for (i = 0; i < frame_size; i++) { - short_dst[i * dst_stride + dst_channel] = 0; - } - } -} - - - -#ifdef FIXED_POINT -int opus_multistream_decode( - OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_int16 *pcm, - int frame_size, - int decode_fec -) { - return opus_multistream_decode_native(st, data, len, - pcm, opus_copy_channel_out_short, frame_size, decode_fec, 0, NULL); -} - -#ifndef DISABLE_FLOAT_API -int opus_multistream_decode_float(OpusMSDecoder *st, const unsigned char *data, - opus_int32 len, float *pcm, int frame_size, int decode_fec) { - return opus_multistream_decode_native(st, data, len, - pcm, opus_copy_channel_out_float, frame_size, decode_fec, 0, NULL); -} -#endif - -#else - -int opus_multistream_decode(OpusMSDecoder *st, const unsigned char *data, - opus_int32 len, opus_int16 *pcm, int frame_size, int decode_fec) { - return opus_multistream_decode_native(st, data, len, - pcm, opus_copy_channel_out_short, frame_size, decode_fec, 1, NULL); -} - -int opus_multistream_decode_float( - OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_val16 *pcm, - int frame_size, - int decode_fec -) { - return opus_multistream_decode_native(st, data, len, - pcm, opus_copy_channel_out_float, frame_size, decode_fec, 0, NULL); -} -#endif - -int opus_multistream_decoder_ctl_va_list(OpusMSDecoder *st, int request, - va_list ap) { - int coupled_size, mono_size; - char *ptr; - int ret = OPUS_OK; - - coupled_size = opus_decoder_get_size(2); - mono_size = opus_decoder_get_size(1); - ptr = (char*)st + align(sizeof(OpusMSDecoder)); - switch (request) { - case OPUS_GET_BANDWIDTH_REQUEST: - case OPUS_GET_SAMPLE_RATE_REQUEST: - case OPUS_GET_GAIN_REQUEST: - case OPUS_GET_LAST_PACKET_DURATION_REQUEST: - case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: { - OpusDecoder *dec; - /* For int32* GET params, just query the first stream */ - opus_int32 *value = va_arg(ap, opus_int32*); - dec = (OpusDecoder*)ptr; - ret = opus_decoder_ctl(dec, request, value); - } - break; - case OPUS_GET_FINAL_RANGE_REQUEST: { - int s; - opus_uint32 *value = va_arg(ap, opus_uint32*); - opus_uint32 tmp; - if (!value) { - goto bad_arg; - } - *value = 0; - for (s = 0; s < st->layout.nb_streams; s++) { - OpusDecoder *dec; - dec = (OpusDecoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - ret = opus_decoder_ctl(dec, request, &tmp); - if (ret != OPUS_OK) { - break; - } - *value ^= tmp; - } - } - break; - case OPUS_RESET_STATE: { - int s; - for (s = 0; s < st->layout.nb_streams; s++) { - OpusDecoder *dec; - - dec = (OpusDecoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - ret = opus_decoder_ctl(dec, OPUS_RESET_STATE); - if (ret != OPUS_OK) { - break; - } - } - } - break; - case OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST: { - int s; - opus_int32 stream_id; - OpusDecoder **value; - stream_id = va_arg(ap, opus_int32); - if (stream_id < 0 || stream_id >= st->layout.nb_streams) { - goto bad_arg; - } - value = va_arg(ap, OpusDecoder**); - if (!value) { - goto bad_arg; - } - for (s = 0; s < stream_id; s++) { - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - } - *value = (OpusDecoder*)ptr; - } - break; - case OPUS_SET_GAIN_REQUEST: - case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: { - int s; - /* This works for int32 params */ - opus_int32 value = va_arg(ap, opus_int32); - for (s = 0; s < st->layout.nb_streams; s++) { - OpusDecoder *dec; - - dec = (OpusDecoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - ret = opus_decoder_ctl(dec, request, value); - if (ret != OPUS_OK) { - break; - } - } - } - break; - default: - ret = OPUS_UNIMPLEMENTED; - break; - } - return ret; -bad_arg: - return OPUS_BAD_ARG; -} - -int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) { - int ret; - va_list ap; - va_start(ap, request); - ret = opus_multistream_decoder_ctl_va_list(st, request, ap); - va_end(ap); - return ret; -} - -void opus_multistream_decoder_destroy(OpusMSDecoder *st) { - opus_free(st); -} diff --git a/src/libopus/opus_multistream_encoder.c b/src/libopus/opus_multistream_encoder.c deleted file mode 100644 index ed17826..0000000 --- a/src/libopus/opus_multistream_encoder.c +++ /dev/null @@ -1,1291 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#if 0 -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "opus_multistream.h" -#include "opus.h" -#include "opus_private.h" -#include "celt/stack_alloc.h" -#include -#include "celt/float_cast.h" -#include "celt/os_support.h" -#include "celt/mathops.h" -#include "celt/mdct.h" -#include "celt/modes.h" -#include "celt/bands.h" -#include "celt/quant_bands.h" -#include "celt/pitch.h" - -typedef struct { - int nb_streams; - int nb_coupled_streams; - unsigned char mapping[8]; -} VorbisLayout; - -/* Index is nb_channel-1*/ -static const VorbisLayout vorbis_mappings[8] = { - {1, 0, {0}}, /* 1: mono */ - {1, 1, {0, 1}}, /* 2: stereo */ - {2, 1, {0, 2, 1}}, /* 3: 1-d surround */ - {2, 2, {0, 1, 2, 3}}, /* 4: quadraphonic surround */ - {3, 2, {0, 4, 1, 2, 3}}, /* 5: 5-channel surround */ - {4, 2, {0, 4, 1, 2, 3, 5}}, /* 6: 5.1 surround */ - {4, 3, {0, 4, 1, 2, 3, 5, 6}}, /* 7: 6.1 surround */ - {5, 3, {0, 6, 1, 2, 3, 4, 5, 7}}, /* 8: 7.1 surround */ -}; - -static opus_val32 *ms_get_preemph_mem(OpusMSEncoder *st) { - int s; - char *ptr; - int coupled_size, mono_size; - - coupled_size = opus_encoder_get_size(2); - mono_size = opus_encoder_get_size(1); - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - for (s = 0; s < st->layout.nb_streams; s++) { - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - } - /* void* cast avoids clang -Wcast-align warning */ - return (opus_val32*)(void*)(ptr + st->layout.nb_channels * 120 * sizeof(opus_val32)); -} - -static opus_val32 *ms_get_window_mem(OpusMSEncoder *st) { - int s; - char *ptr; - int coupled_size, mono_size; - - coupled_size = opus_encoder_get_size(2); - mono_size = opus_encoder_get_size(1); - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - for (s = 0; s < st->layout.nb_streams; s++) { - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - } - /* void* cast avoids clang -Wcast-align warning */ - return (opus_val32*)(void*)ptr; -} - -static int validate_ambisonics(int nb_channels, int *nb_streams, int *nb_coupled_streams) { - int order_plus_one; - int acn_channels; - int nondiegetic_channels; - - if (nb_channels < 1 || nb_channels > 227) { - return 0; - } - - order_plus_one = isqrt32(nb_channels); - acn_channels = order_plus_one * order_plus_one; - nondiegetic_channels = nb_channels - acn_channels; - - if (nondiegetic_channels != 0 && nondiegetic_channels != 2) { - return 0; - } - - if (nb_streams) { - *nb_streams = acn_channels + (nondiegetic_channels != 0); - } - if (nb_coupled_streams) { - *nb_coupled_streams = nondiegetic_channels != 0; - } - return 1; -} - -static int validate_encoder_layout(const ChannelLayout *layout) { - int s; - for (s = 0; s < layout->nb_streams; s++) { - if (s < layout->nb_coupled_streams) { - if (get_left_channel(layout, s, -1) == -1) { - return 0; - } - if (get_right_channel(layout, s, -1) == -1) { - return 0; - } - } else { - if (get_mono_channel(layout, s, -1) == -1) { - return 0; - } - } - } - return 1; -} - -static void channel_pos(int channels, int pos[8]) { - /* Position in the mix: 0 don't mix, 1: left, 2: center, 3:right */ - if (channels == 4) { - pos[0] = 1; - pos[1] = 3; - pos[2] = 1; - pos[3] = 3; - } else if (channels == 3 || channels == 5 || channels == 6) { - pos[0] = 1; - pos[1] = 2; - pos[2] = 3; - pos[3] = 1; - pos[4] = 3; - pos[5] = 0; - } else if (channels == 7) { - pos[0] = 1; - pos[1] = 2; - pos[2] = 3; - pos[3] = 1; - pos[4] = 3; - pos[5] = 2; - pos[6] = 0; - } else if (channels == 8) { - pos[0] = 1; - pos[1] = 2; - pos[2] = 3; - pos[3] = 1; - pos[4] = 3; - pos[5] = 1; - pos[6] = 3; - pos[7] = 0; - } -} - -#if 1 -/* Computes a rough approximation of log2(2^a + 2^b) */ -static opus_val16 logSum(opus_val16 a, opus_val16 b) { - opus_val16 max; - opus_val32 diff; - opus_val16 frac; - static const opus_val16 diff_table[17] = { - QCONST16(0.5000000f, DB_SHIFT), QCONST16(0.2924813f, DB_SHIFT), QCONST16(0.1609640f, DB_SHIFT), QCONST16(0.0849625f, DB_SHIFT), - QCONST16(0.0437314f, DB_SHIFT), QCONST16(0.0221971f, DB_SHIFT), QCONST16(0.0111839f, DB_SHIFT), QCONST16(0.0056136f, DB_SHIFT), - QCONST16(0.0028123f, DB_SHIFT) - }; - int low; - if (a > b) { - max = a; - diff = SUB32(EXTEND32(a), EXTEND32(b)); - } else { - max = b; - diff = SUB32(EXTEND32(b), EXTEND32(a)); - } - if (!(diff < QCONST16(8.f, DB_SHIFT))) { /* inverted to catch NaNs */ - return max; - } -#ifdef FIXED_POINT - low = SHR32(diff, DB_SHIFT - 1); - frac = SHL16(diff - SHL16(low, DB_SHIFT - 1), 16 - DB_SHIFT); -#else - low = (int)floor(2 * diff); - frac = 2 * diff - low; -#endif - return max + diff_table[low] + MULT16_16_Q15(frac, SUB16(diff_table[low + 1], diff_table[low])); -} -#else -opus_val16 logSum(opus_val16 a, opus_val16 b) { - return log2(pow(4, a) + pow(4, b)) / 2; -} -#endif - -void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *bandLogE, opus_val32 *mem, opus_val32 *preemph_mem, - int len, int overlap, int channels, int rate, opus_copy_channel_in_func copy_channel_in, int arch - ) { - int c; - int i; - int LM; - int pos[8] = {0}; - int upsample; - int frame_size; - int freq_size; - opus_val16 channel_offset; - opus_val32 bandE[21]; - opus_val16 maskLogE[3][21]; - VARDECL(opus_val32, in); - VARDECL(opus_val16, x); - VARDECL(opus_val32, freq); - SAVE_STACK; - - upsample = resampling_factor(rate); - frame_size = len * upsample; - freq_size = IMIN(960, frame_size); - - /* LM = log2(frame_size / 120) */ - for (LM = 0; LM < celt_mode->maxLM; LM++) - if (celt_mode->shortMdctSize << LM == frame_size) { - break; - } - - ALLOC(in, frame_size + overlap, opus_val32); - ALLOC(x, len, opus_val16); - ALLOC(freq, freq_size, opus_val32); - - channel_pos(channels, pos); - - for (c = 0; c < 3; c++) - for (i = 0; i < 21; i++) { - maskLogE[c][i] = -QCONST16(28.f, DB_SHIFT); - } - - for (c = 0; c < channels; c++) { - int frame; - int nb_frames = frame_size / freq_size; - celt_assert(nb_frames * freq_size == frame_size); - OPUS_COPY(in, mem + c * overlap, overlap); - (*copy_channel_in)(x, 1, pcm, channels, c, len, NULL); - celt_preemphasis(x, in + overlap, frame_size, 1, upsample, celt_mode->preemph, preemph_mem + c, 0); -#ifndef FIXED_POINT - { - opus_val32 sum; - sum = celt_inner_prod(in, in, frame_size + overlap, 0); - /* This should filter out both NaNs and ridiculous signals that could - cause NaNs further down. */ - if (!(sum < 1e18f) || celt_isnan(sum)) { - OPUS_CLEAR(in, frame_size + overlap); - preemph_mem[c] = 0; - } - } -#endif - OPUS_CLEAR(bandE, 21); - for (frame = 0; frame < nb_frames; frame++) { - opus_val32 tmpE[21]; - clt_mdct_forward(&celt_mode->mdct, in + 960 * frame, freq, celt_mode->window, - overlap, celt_mode->maxLM - LM, 1, arch); - if (upsample != 1) { - int bound = freq_size / upsample; - for (i = 0; i < bound; i++) { - freq[i] *= upsample; - } - for (; i < freq_size; i++) { - freq[i] = 0; - } - } - - compute_band_energies(celt_mode, freq, tmpE, 21, 1, LM, arch); - /* If we have multiple frames, take the max energy. */ - for (i = 0; i < 21; i++) { - bandE[i] = MAX32(bandE[i], tmpE[i]); - } - } - amp2Log2(celt_mode, 21, 21, bandE, bandLogE + 21 * c, 1); - /* Apply spreading function with -6 dB/band going up and -12 dB/band going down. */ - for (i = 1; i < 21; i++) { - bandLogE[21 * c + i] = MAX16(bandLogE[21 * c + i], bandLogE[21 * c + i - 1] - QCONST16(1.f, DB_SHIFT)); - } - for (i = 19; i >= 0; i--) { - bandLogE[21 * c + i] = MAX16(bandLogE[21 * c + i], bandLogE[21 * c + i + 1] - QCONST16(2.f, DB_SHIFT)); - } - if (pos[c] == 1) { - for (i = 0; i < 21; i++) { - maskLogE[0][i] = logSum(maskLogE[0][i], bandLogE[21 * c + i]); - } - } else if (pos[c] == 3) { - for (i = 0; i < 21; i++) { - maskLogE[2][i] = logSum(maskLogE[2][i], bandLogE[21 * c + i]); - } - } else if (pos[c] == 2) { - for (i = 0; i < 21; i++) { - maskLogE[0][i] = logSum(maskLogE[0][i], bandLogE[21 * c + i] - QCONST16(.5f, DB_SHIFT)); - maskLogE[2][i] = logSum(maskLogE[2][i], bandLogE[21 * c + i] - QCONST16(.5f, DB_SHIFT)); - } - } -#if 0 - for (i = 0; i < 21; i++) { - printf("%f ", bandLogE[21 * c + i]); - } - float sum = 0; - for (i = 0; i < 21; i++) { - sum += bandLogE[21 * c + i]; - } - printf("%f ", sum / 21); -#endif - OPUS_COPY(mem + c * overlap, in + frame_size, overlap); - } - for (i = 0; i < 21; i++) { - maskLogE[1][i] = MIN32(maskLogE[0][i], maskLogE[2][i]); - } - channel_offset = HALF16(celt_log2(QCONST32(2.f, 14) / (channels - 1))); - for (c = 0; c < 3; c++) - for (i = 0; i < 21; i++) { - maskLogE[c][i] += channel_offset; - } -#if 0 - for (c = 0; c < 3; c++) { - for (i = 0; i < 21; i++) { - printf("%f ", maskLogE[c][i]); - } - } -#endif - for (c = 0; c < channels; c++) { - opus_val16 *mask; - if (pos[c] != 0) { - mask = &maskLogE[pos[c] - 1][0]; - for (i = 0; i < 21; i++) { - bandLogE[21 * c + i] = bandLogE[21 * c + i] - mask[i]; - } - } else { - for (i = 0; i < 21; i++) { - bandLogE[21 * c + i] = 0; - } - } -#if 0 - for (i = 0; i < 21; i++) { - printf("%f ", bandLogE[21 * c + i]); - } - printf("\n"); -#endif -#if 0 - float sum = 0; - for (i = 0; i < 21; i++) { - sum += bandLogE[21 * c + i]; - } - printf("%f ", sum / (float)QCONST32(21.f, DB_SHIFT)); - printf("\n"); -#endif - } - RESTORE_STACK; -} - -opus_int32 opus_multistream_encoder_get_size(int nb_streams, int nb_coupled_streams) { - int coupled_size; - int mono_size; - - if (nb_streams < 1 || nb_coupled_streams > nb_streams || nb_coupled_streams < 0) { - return 0; - } - coupled_size = opus_encoder_get_size(2); - mono_size = opus_encoder_get_size(1); - return align(sizeof(OpusMSEncoder)) - + nb_coupled_streams * align(coupled_size) - + (nb_streams - nb_coupled_streams) * align(mono_size); -} - -opus_int32 opus_multistream_surround_encoder_get_size(int channels, int mapping_family) { - int nb_streams; - int nb_coupled_streams; - opus_int32 size; - - if (mapping_family == 0) { - if (channels == 1) { - nb_streams = 1; - nb_coupled_streams = 0; - } else if (channels == 2) { - nb_streams = 1; - nb_coupled_streams = 1; - } else { - return 0; - } - } else if (mapping_family == 1 && channels <= 8 && channels >= 1) { - nb_streams = vorbis_mappings[channels - 1].nb_streams; - nb_coupled_streams = vorbis_mappings[channels - 1].nb_coupled_streams; - } else if (mapping_family == 255) { - nb_streams = channels; - nb_coupled_streams = 0; - } else if (mapping_family == 2) { - if (!validate_ambisonics(channels, &nb_streams, &nb_coupled_streams)) { - return 0; - } - } else { - return 0; - } - size = opus_multistream_encoder_get_size(nb_streams, nb_coupled_streams); - if (channels > 2) { - size += channels * (120 * sizeof(opus_val32) + sizeof(opus_val32)); - } - return size; -} - -static int opus_multistream_encoder_init_impl( - OpusMSEncoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int application, - MappingType mapping_type -) { - int coupled_size; - int mono_size; - int i, ret; - char *ptr; - - if ((channels > 255) || (channels < 1) || (coupled_streams > streams) || - (streams < 1) || (coupled_streams < 0) || (streams > 255 - coupled_streams)) { - return OPUS_BAD_ARG; - } - - st->arch = opus_select_arch(); - st->layout.nb_channels = channels; - st->layout.nb_streams = streams; - st->layout.nb_coupled_streams = coupled_streams; - if (mapping_type != MAPPING_TYPE_SURROUND) { - st->lfe_stream = -1; - } - st->bitrate_bps = OPUS_AUTO; - st->application = application; - st->variable_duration = OPUS_FRAMESIZE_ARG; - for (i = 0; i < st->layout.nb_channels; i++) { - st->layout.mapping[i] = mapping[i]; - } - if (!validate_layout(&st->layout)) { - return OPUS_BAD_ARG; - } - if (mapping_type == MAPPING_TYPE_SURROUND && - !validate_encoder_layout(&st->layout)) { - return OPUS_BAD_ARG; - } - if (mapping_type == MAPPING_TYPE_AMBISONICS && - !validate_ambisonics(st->layout.nb_channels, NULL, NULL)) { - return OPUS_BAD_ARG; - } - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - coupled_size = opus_encoder_get_size(2); - mono_size = opus_encoder_get_size(1); - - for (i = 0; i < st->layout.nb_coupled_streams; i++) { - ret = opus_encoder_init((OpusEncoder*)ptr, Fs, 2, application); - if (ret != OPUS_OK) { - return ret; - } - if (i == st->lfe_stream) { - opus_encoder_ctl((OpusEncoder*)ptr, OPUS_SET_LFE(1)); - } - ptr += align(coupled_size); - } - for (; i < st->layout.nb_streams; i++) { - ret = opus_encoder_init((OpusEncoder*)ptr, Fs, 1, application); - if (i == st->lfe_stream) { - opus_encoder_ctl((OpusEncoder*)ptr, OPUS_SET_LFE(1)); - } - if (ret != OPUS_OK) { - return ret; - } - ptr += align(mono_size); - } - if (mapping_type == MAPPING_TYPE_SURROUND) { - OPUS_CLEAR(ms_get_preemph_mem(st), channels); - OPUS_CLEAR(ms_get_window_mem(st), channels * 120); - } - st->mapping_type = mapping_type; - return OPUS_OK; -} - -int opus_multistream_encoder_init( - OpusMSEncoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int application -) { - return opus_multistream_encoder_init_impl(st, Fs, channels, streams, - coupled_streams, mapping, - application, MAPPING_TYPE_NONE); -} - -int opus_multistream_surround_encoder_init( - OpusMSEncoder *st, - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - unsigned char *mapping, - int application -) { - MappingType mapping_type; - - if ((channels > 255) || (channels < 1)) { - return OPUS_BAD_ARG; - } - st->lfe_stream = -1; - if (mapping_family == 0) { - if (channels == 1) { - *streams = 1; - *coupled_streams = 0; - mapping[0] = 0; - } else if (channels == 2) { - *streams = 1; - *coupled_streams = 1; - mapping[0] = 0; - mapping[1] = 1; - } else { - return OPUS_UNIMPLEMENTED; - } - } else if (mapping_family == 1 && channels <= 8 && channels >= 1) { - int i; - *streams = vorbis_mappings[channels - 1].nb_streams; - *coupled_streams = vorbis_mappings[channels - 1].nb_coupled_streams; - for (i = 0; i < channels; i++) { - mapping[i] = vorbis_mappings[channels - 1].mapping[i]; - } - if (channels >= 6) { - st->lfe_stream = *streams - 1; - } - } else if (mapping_family == 255) { - int i; - *streams = channels; - *coupled_streams = 0; - for (i = 0; i < channels; i++) { - mapping[i] = i; - } - } else if (mapping_family == 2) { - int i; - if (!validate_ambisonics(channels, streams, coupled_streams)) { - return OPUS_BAD_ARG; - } - for (i = 0; i < (*streams - *coupled_streams); i++) { - mapping[i] = i + (*coupled_streams * 2); - } - for (i = 0; i < *coupled_streams * 2; i++) { - mapping[i + (*streams - *coupled_streams)] = i; - } - } else { - return OPUS_UNIMPLEMENTED; - } - - if (channels > 2 && mapping_family == 1) { - mapping_type = MAPPING_TYPE_SURROUND; - } else if (mapping_family == 2) { - mapping_type = MAPPING_TYPE_AMBISONICS; - } else { - mapping_type = MAPPING_TYPE_NONE; - } - return opus_multistream_encoder_init_impl(st, Fs, channels, *streams, - *coupled_streams, mapping, - application, mapping_type); -} - -OpusMSEncoder *opus_multistream_encoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int application, - int *error -) { - int ret; - OpusMSEncoder *st; - if ((channels > 255) || (channels < 1) || (coupled_streams > streams) || - (streams < 1) || (coupled_streams < 0) || (streams > 255 - coupled_streams)) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } - st = (OpusMSEncoder *)opus_alloc(opus_multistream_encoder_get_size(streams, coupled_streams)); - if (st == NULL) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - ret = opus_multistream_encoder_init(st, Fs, channels, streams, coupled_streams, mapping, application); - if (ret != OPUS_OK) { - opus_free(st); - st = NULL; - } - if (error) { - *error = ret; - } - return st; -} - -OpusMSEncoder *opus_multistream_surround_encoder_create( - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - unsigned char *mapping, - int application, - int *error -) { - int ret; - opus_int32 size; - OpusMSEncoder *st; - if ((channels > 255) || (channels < 1)) { - if (error) { - *error = OPUS_BAD_ARG; - } - return NULL; - } - size = opus_multistream_surround_encoder_get_size(channels, mapping_family); - if (!size) { - if (error) { - *error = OPUS_UNIMPLEMENTED; - } - return NULL; - } - st = (OpusMSEncoder *)opus_alloc(size); - if (st == NULL) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - ret = opus_multistream_surround_encoder_init(st, Fs, channels, mapping_family, streams, coupled_streams, mapping, application); - if (ret != OPUS_OK) { - opus_free(st); - st = NULL; - } - if (error) { - *error = ret; - } - return st; -} - -static void surround_rate_allocation( - OpusMSEncoder *st, - opus_int32 *rate, - int frame_size, - opus_int32 Fs -) { - int i; - opus_int32 channel_rate; - int stream_offset; - int lfe_offset; - int coupled_ratio; /* Q8 */ - int lfe_ratio; /* Q8 */ - int nb_lfe; - int nb_uncoupled; - int nb_coupled; - int nb_normal; - opus_int32 channel_offset; - opus_int32 bitrate; - int total; - - nb_lfe = (st->lfe_stream != -1); - nb_coupled = st->layout.nb_coupled_streams; - nb_uncoupled = st->layout.nb_streams - nb_coupled - nb_lfe; - nb_normal = 2 * nb_coupled + nb_uncoupled; - - /* Give each non-LFE channel enough bits per channel for coding band energy. */ - channel_offset = 40 * IMAX(50, Fs / frame_size); - - if (st->bitrate_bps == OPUS_AUTO) { - bitrate = nb_normal * (channel_offset + Fs + 10000) + 8000 * nb_lfe; - } else if (st->bitrate_bps == OPUS_BITRATE_MAX) { - bitrate = nb_normal * 300000 + nb_lfe * 128000; - } else { - bitrate = st->bitrate_bps; - } - - /* Give LFE some basic stream_channel allocation but never exceed 1/20 of the - total rate for the non-energy part to avoid problems at really low rate. */ - lfe_offset = IMIN(bitrate / 20, 3000) + 15 * IMAX(50, Fs / frame_size); - - /* We give each stream (coupled or uncoupled) a starting bitrate. - This models the main saving of coupled channels over uncoupled. */ - stream_offset = (bitrate - channel_offset * nb_normal - lfe_offset * nb_lfe) / nb_normal / 2; - stream_offset = IMAX(0, IMIN(20000, stream_offset)); - - /* Coupled streams get twice the mono rate after the offset is allocated. */ - coupled_ratio = 512; - /* Should depend on the bitrate, for now we assume LFE gets 1/8 the bits of mono */ - lfe_ratio = 32; - - total = (nb_uncoupled << 8) /* mono */ - + coupled_ratio * nb_coupled /* stereo */ - + nb_lfe * lfe_ratio; - channel_rate = 256 * (opus_int64)(bitrate - lfe_offset * nb_lfe - stream_offset * (nb_coupled + nb_uncoupled) - channel_offset * nb_normal) / total; - - for (i = 0; i < st->layout.nb_streams; i++) { - if (i < st->layout.nb_coupled_streams) { - rate[i] = 2 * channel_offset + IMAX(0, stream_offset + (channel_rate * coupled_ratio >> 8)); - } else if (i != st->lfe_stream) { - rate[i] = channel_offset + IMAX(0, stream_offset + channel_rate); - } else { - rate[i] = IMAX(0, lfe_offset + (channel_rate * lfe_ratio >> 8)); - } - } -} - -static void ambisonics_rate_allocation( - OpusMSEncoder *st, - opus_int32 *rate, - int frame_size, - opus_int32 Fs -) { - int i; - opus_int32 total_rate; - opus_int32 per_stream_rate; - - const int nb_channels = st->layout.nb_streams + st->layout.nb_coupled_streams; - - if (st->bitrate_bps == OPUS_AUTO) { - total_rate = (st->layout.nb_coupled_streams + st->layout.nb_streams) * - (Fs + 60 * Fs / frame_size) + st->layout.nb_streams * (opus_int32)15000; - } else if (st->bitrate_bps == OPUS_BITRATE_MAX) { - total_rate = nb_channels * 320000; - } else { - total_rate = st->bitrate_bps; - } - - /* Allocate equal number of bits to Ambisonic (uncoupled) and non-diegetic - (coupled) streams */ - per_stream_rate = total_rate / st->layout.nb_streams; - for (i = 0; i < st->layout.nb_streams; i++) { - rate[i] = per_stream_rate; - } -} - -static opus_int32 rate_allocation( - OpusMSEncoder *st, - opus_int32 *rate, - int frame_size -) { - int i; - opus_int32 rate_sum = 0; - opus_int32 Fs; - char *ptr; - - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_SAMPLE_RATE(&Fs)); - - if (st->mapping_type == MAPPING_TYPE_AMBISONICS) { - ambisonics_rate_allocation(st, rate, frame_size, Fs); - } else { - surround_rate_allocation(st, rate, frame_size, Fs); - } - - for (i = 0; i < st->layout.nb_streams; i++) { - rate[i] = IMAX(rate[i], 500); - rate_sum += rate[i]; - } - return rate_sum; -} - -/* Max size in case the encoder decides to return six frames (6 x 20 ms = 120 ms) */ -#define MS_FRAME_TMP (6*1275+12) -int opus_multistream_encode_native -( - OpusMSEncoder *st, - opus_copy_channel_in_func copy_channel_in, - const void *pcm, - int analysis_frame_size, - unsigned char *data, - opus_int32 max_data_bytes, - int lsb_depth, - downmix_func downmix, - int float_api, - void *user_data -) { - opus_int32 Fs; - int coupled_size; - int mono_size; - int s; - char *ptr; - int tot_size; - VARDECL(opus_val16, buf); - VARDECL(opus_val16, bandSMR); - unsigned char tmp_data[MS_FRAME_TMP]; - OpusRepacketizer rp; - opus_int32 vbr; - const CELTMode *celt_mode; - opus_int32 bitrates[256]; - opus_val16 bandLogE[42]; - opus_val32 *mem = NULL; - opus_val32 *preemph_mem = NULL; - int frame_size; - opus_int32 rate_sum; - opus_int32 smallest_packet; - ALLOC_STACK; - - if (st->mapping_type == MAPPING_TYPE_SURROUND) { - preemph_mem = ms_get_preemph_mem(st); - mem = ms_get_window_mem(st); - } - - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_SAMPLE_RATE(&Fs)); - opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_VBR(&vbr)); - opus_encoder_ctl((OpusEncoder*)ptr, CELT_GET_MODE(&celt_mode)); - - frame_size = frame_size_select(analysis_frame_size, st->variable_duration, Fs); - if (frame_size <= 0) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - /* Smallest packet the encoder can produce. */ - smallest_packet = st->layout.nb_streams * 2 - 1; - /* 100 ms needs an extra byte per stream for the ToC. */ - if (Fs / frame_size == 10) { - smallest_packet += st->layout.nb_streams; - } - if (max_data_bytes < smallest_packet) { - RESTORE_STACK; - return OPUS_BUFFER_TOO_SMALL; - } - ALLOC(buf, 2 * frame_size, opus_val16); - coupled_size = opus_encoder_get_size(2); - mono_size = opus_encoder_get_size(1); - - ALLOC(bandSMR, 21 * st->layout.nb_channels, opus_val16); - if (st->mapping_type == MAPPING_TYPE_SURROUND) { - surround_analysis(celt_mode, pcm, bandSMR, mem, preemph_mem, frame_size, 120, st->layout.nb_channels, Fs, copy_channel_in, st->arch); - } - - /* Compute bitrate allocation between streams (this could be a lot better) */ - rate_sum = rate_allocation(st, bitrates, frame_size); - - if (!vbr) { - if (st->bitrate_bps == OPUS_AUTO) { - max_data_bytes = IMIN(max_data_bytes, 3 * rate_sum / (3 * 8 * Fs / frame_size)); - } else if (st->bitrate_bps != OPUS_BITRATE_MAX) { - max_data_bytes = IMIN(max_data_bytes, IMAX(smallest_packet, - 3 * st->bitrate_bps / (3 * 8 * Fs / frame_size))); - } - } - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - for (s = 0; s < st->layout.nb_streams; s++) { - OpusEncoder *enc; - enc = (OpusEncoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrates[s])); - if (st->mapping_type == MAPPING_TYPE_SURROUND) { - opus_int32 equiv_rate; - equiv_rate = st->bitrate_bps; - if (frame_size * 50 < Fs) { - equiv_rate -= 60 * (Fs / frame_size - 50) * st->layout.nb_channels; - } - if (equiv_rate > 10000 * st->layout.nb_channels) { - opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); - } else if (equiv_rate > 7000 * st->layout.nb_channels) { - opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_SUPERWIDEBAND)); - } else if (equiv_rate > 5000 * st->layout.nb_channels) { - opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_WIDEBAND)); - } else { - opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); - } - if (s < st->layout.nb_coupled_streams) { - /* To preserve the spatial image, force stereo CELT on coupled streams */ - opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_CELT_ONLY)); - opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(2)); - } - } else if (st->mapping_type == MAPPING_TYPE_AMBISONICS) { - opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_CELT_ONLY)); - } - } - - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - /* Counting ToC */ - tot_size = 0; - for (s = 0; s < st->layout.nb_streams; s++) { - OpusEncoder *enc; - int len; - int curr_max; - int c1, c2; - int ret; - - opus_repacketizer_init(&rp); - enc = (OpusEncoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - int i; - int left, right; - left = get_left_channel(&st->layout, s, -1); - right = get_right_channel(&st->layout, s, -1); - (*copy_channel_in)(buf, 2, - pcm, st->layout.nb_channels, left, frame_size, user_data); - (*copy_channel_in)(buf + 1, 2, - pcm, st->layout.nb_channels, right, frame_size, user_data); - ptr += align(coupled_size); - if (st->mapping_type == MAPPING_TYPE_SURROUND) { - for (i = 0; i < 21; i++) { - bandLogE[i] = bandSMR[21 * left + i]; - bandLogE[21 + i] = bandSMR[21 * right + i]; - } - } - c1 = left; - c2 = right; - } else { - int i; - int chan = get_mono_channel(&st->layout, s, -1); - (*copy_channel_in)(buf, 1, - pcm, st->layout.nb_channels, chan, frame_size, user_data); - ptr += align(mono_size); - if (st->mapping_type == MAPPING_TYPE_SURROUND) { - for (i = 0; i < 21; i++) { - bandLogE[i] = bandSMR[21 * chan + i]; - } - } - c1 = chan; - c2 = -1; - } - if (st->mapping_type == MAPPING_TYPE_SURROUND) { - opus_encoder_ctl(enc, OPUS_SET_ENERGY_MASK(bandLogE)); - } - /* number of bytes left (+Toc) */ - curr_max = max_data_bytes - tot_size; - /* Reserve one byte for the last stream and two for the others */ - curr_max -= IMAX(0, 2 * (st->layout.nb_streams - s - 1) - 1); - /* For 100 ms, reserve an extra byte per stream for the ToC */ - if (Fs / frame_size == 10) { - curr_max -= st->layout.nb_streams - s - 1; - } - curr_max = IMIN(curr_max, MS_FRAME_TMP); - /* Repacketizer will add one or two bytes for self-delimited frames */ - if (s != st->layout.nb_streams - 1) { - curr_max -= curr_max > 253 ? 2 : 1; - } - if (!vbr && s == st->layout.nb_streams - 1) { - opus_encoder_ctl(enc, OPUS_SET_BITRATE(curr_max * (8 * Fs / frame_size))); - } - len = opus_encode_native(enc, buf, frame_size, tmp_data, curr_max, lsb_depth, - pcm, analysis_frame_size, c1, c2, st->layout.nb_channels, downmix, float_api); - if (len < 0) { - RESTORE_STACK; - return len; - } - /* We need to use the repacketizer to add the self-delimiting lengths - while taking into account the fact that the encoder can now return - more than one frame at a time (e.g. 60 ms CELT-only) */ - ret = opus_repacketizer_cat(&rp, tmp_data, len); - /* If the opus_repacketizer_cat() fails, then something's seriously wrong - with the encoder. */ - if (ret != OPUS_OK) { - RESTORE_STACK; - return OPUS_INTERNAL_ERROR; - } - len = opus_repacketizer_out_range_impl(&rp, 0, opus_repacketizer_get_nb_frames(&rp), - data, max_data_bytes - tot_size, s != st->layout.nb_streams - 1, !vbr && s == st->layout.nb_streams - 1); - data += len; - tot_size += len; - } - /*printf("\n");*/ - RESTORE_STACK; - return tot_size; -} - -#if !defined(DISABLE_FLOAT_API) -static void opus_copy_channel_in_float( - opus_val16 *dst, - int dst_stride, - const void *src, - int src_stride, - int src_channel, - int frame_size, - void *user_data -) { - const float *float_src; - opus_int32 i; - (void)user_data; - float_src = (const float *)src; - for (i = 0; i < frame_size; i++) -#if defined(FIXED_POINT) - dst[i * dst_stride] = FLOAT2INT16(float_src[i * src_stride + src_channel]); -#else - dst[i * dst_stride] = float_src[i * src_stride + src_channel]; -#endif -} -#endif - -static void opus_copy_channel_in_short( - opus_val16 *dst, - int dst_stride, - const void *src, - int src_stride, - int src_channel, - int frame_size, - void *user_data -) { - const opus_int16 *short_src; - opus_int32 i; - (void)user_data; - short_src = (const opus_int16 *)src; - for (i = 0; i < frame_size; i++) -#if defined(FIXED_POINT) - dst[i * dst_stride] = short_src[i * src_stride + src_channel]; -#else - dst[i * dst_stride] = (1 / 32768.f) * short_src[i * src_stride + src_channel]; -#endif -} - - -#ifdef FIXED_POINT -int opus_multistream_encode( - OpusMSEncoder *st, - const opus_val16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) { - return opus_multistream_encode_native(st, opus_copy_channel_in_short, - pcm, frame_size, data, max_data_bytes, 16, downmix_int, 0, NULL); -} - -#ifndef DISABLE_FLOAT_API -int opus_multistream_encode_float( - OpusMSEncoder *st, - const float *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) { - return opus_multistream_encode_native(st, opus_copy_channel_in_float, - pcm, frame_size, data, max_data_bytes, 16, downmix_float, 1, NULL); -} -#endif - -#else - -int opus_multistream_encode_float -( - OpusMSEncoder *st, - const opus_val16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) { - return opus_multistream_encode_native(st, opus_copy_channel_in_float, - pcm, frame_size, data, max_data_bytes, 24, downmix_float, 1, NULL); -} - -int opus_multistream_encode( - OpusMSEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) { - return opus_multistream_encode_native(st, opus_copy_channel_in_short, - pcm, frame_size, data, max_data_bytes, 16, downmix_int, 0, NULL); -} -#endif - -int opus_multistream_encoder_ctl_va_list(OpusMSEncoder *st, int request, - va_list ap) { - int coupled_size, mono_size; - char *ptr; - int ret = OPUS_OK; - - coupled_size = opus_encoder_get_size(2); - mono_size = opus_encoder_get_size(1); - ptr = (char*)st + align(sizeof(OpusMSEncoder)); - switch (request) { - case OPUS_SET_BITRATE_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - if (value != OPUS_AUTO && value != OPUS_BITRATE_MAX) { - if (value <= 0) { - goto bad_arg; - } - value = IMIN(300000 * st->layout.nb_channels, IMAX(500 * st->layout.nb_channels, value)); - } - st->bitrate_bps = value; - } - break; - case OPUS_GET_BITRATE_REQUEST: { - int s; - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = 0; - for (s = 0; s < st->layout.nb_streams; s++) { - opus_int32 rate; - OpusEncoder *enc; - enc = (OpusEncoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - opus_encoder_ctl(enc, request, &rate); - *value += rate; - } - } - break; - case OPUS_GET_LSB_DEPTH_REQUEST: - case OPUS_GET_VBR_REQUEST: - case OPUS_GET_APPLICATION_REQUEST: - case OPUS_GET_BANDWIDTH_REQUEST: - case OPUS_GET_COMPLEXITY_REQUEST: - case OPUS_GET_PACKET_LOSS_PERC_REQUEST: - case OPUS_GET_DTX_REQUEST: - case OPUS_GET_VOICE_RATIO_REQUEST: - case OPUS_GET_VBR_CONSTRAINT_REQUEST: - case OPUS_GET_SIGNAL_REQUEST: - case OPUS_GET_LOOKAHEAD_REQUEST: - case OPUS_GET_SAMPLE_RATE_REQUEST: - case OPUS_GET_INBAND_FEC_REQUEST: - case OPUS_GET_FORCE_CHANNELS_REQUEST: - case OPUS_GET_PREDICTION_DISABLED_REQUEST: - case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: { - OpusEncoder *enc; - /* For int32* GET params, just query the first stream */ - opus_int32 *value = va_arg(ap, opus_int32*); - enc = (OpusEncoder*)ptr; - ret = opus_encoder_ctl(enc, request, value); - } - break; - case OPUS_GET_FINAL_RANGE_REQUEST: { - int s; - opus_uint32 *value = va_arg(ap, opus_uint32*); - opus_uint32 tmp; - if (!value) { - goto bad_arg; - } - *value = 0; - for (s = 0; s < st->layout.nb_streams; s++) { - OpusEncoder *enc; - enc = (OpusEncoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - ret = opus_encoder_ctl(enc, request, &tmp); - if (ret != OPUS_OK) { - break; - } - *value ^= tmp; - } - } - break; - case OPUS_SET_LSB_DEPTH_REQUEST: - case OPUS_SET_COMPLEXITY_REQUEST: - case OPUS_SET_VBR_REQUEST: - case OPUS_SET_VBR_CONSTRAINT_REQUEST: - case OPUS_SET_MAX_BANDWIDTH_REQUEST: - case OPUS_SET_BANDWIDTH_REQUEST: - case OPUS_SET_SIGNAL_REQUEST: - case OPUS_SET_APPLICATION_REQUEST: - case OPUS_SET_INBAND_FEC_REQUEST: - case OPUS_SET_PACKET_LOSS_PERC_REQUEST: - case OPUS_SET_DTX_REQUEST: - case OPUS_SET_FORCE_MODE_REQUEST: - case OPUS_SET_FORCE_CHANNELS_REQUEST: - case OPUS_SET_PREDICTION_DISABLED_REQUEST: - case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: { - int s; - /* This works for int32 params */ - opus_int32 value = va_arg(ap, opus_int32); - for (s = 0; s < st->layout.nb_streams; s++) { - OpusEncoder *enc; - - enc = (OpusEncoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - ret = opus_encoder_ctl(enc, request, value); - if (ret != OPUS_OK) { - break; - } - } - } - break; - case OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST: { - int s; - opus_int32 stream_id; - OpusEncoder **value; - stream_id = va_arg(ap, opus_int32); - if (stream_id < 0 || stream_id >= st->layout.nb_streams) { - goto bad_arg; - } - value = va_arg(ap, OpusEncoder**); - if (!value) { - goto bad_arg; - } - for (s = 0; s < stream_id; s++) { - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - } - *value = (OpusEncoder*)ptr; - } - break; - case OPUS_SET_EXPERT_FRAME_DURATION_REQUEST: { - opus_int32 value = va_arg(ap, opus_int32); - st->variable_duration = value; - } - break; - case OPUS_GET_EXPERT_FRAME_DURATION_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = st->variable_duration; - } - break; - case OPUS_RESET_STATE: { - int s; - if (st->mapping_type == MAPPING_TYPE_SURROUND) { - OPUS_CLEAR(ms_get_preemph_mem(st), st->layout.nb_channels); - OPUS_CLEAR(ms_get_window_mem(st), st->layout.nb_channels * 120); - } - for (s = 0; s < st->layout.nb_streams; s++) { - OpusEncoder *enc; - enc = (OpusEncoder*)ptr; - if (s < st->layout.nb_coupled_streams) { - ptr += align(coupled_size); - } else { - ptr += align(mono_size); - } - ret = opus_encoder_ctl(enc, OPUS_RESET_STATE); - if (ret != OPUS_OK) { - break; - } - } - } - break; - default: - ret = OPUS_UNIMPLEMENTED; - break; - } - return ret; -bad_arg: - return OPUS_BAD_ARG; -} - -int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) { - int ret; - va_list ap; - va_start(ap, request); - ret = opus_multistream_encoder_ctl_va_list(st, request, ap); - va_end(ap); - return ret; -} - -void opus_multistream_encoder_destroy(OpusMSEncoder *st) { - opus_free(st); -} -#endif diff --git a/src/libopus/opus_private.h b/src/libopus/opus_private.h deleted file mode 100644 index 955a4f0..0000000 --- a/src/libopus/opus_private.h +++ /dev/null @@ -1,207 +0,0 @@ -/* Copyright (c) 2012 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#ifndef OPUS_PRIVATE_H -#define OPUS_PRIVATE_H - -#include "celt/arch.h" -#include "opus.h" -#include "celt/celt.h" - -#include /* va_list */ -#include /* offsetof */ - -struct OpusRepacketizer { - unsigned char toc; - int nb_frames; - const unsigned char *frames[48]; - opus_int16 len[48]; - int framesize; -}; - -typedef struct ChannelLayout { - int nb_channels; - int nb_streams; - int nb_coupled_streams; - unsigned char mapping[256]; -} ChannelLayout; - -typedef enum { - MAPPING_TYPE_NONE, - MAPPING_TYPE_SURROUND, - MAPPING_TYPE_AMBISONICS -} MappingType; - -struct OpusMSEncoder { - ChannelLayout layout; - int arch; - int lfe_stream; - int application; - int variable_duration; - MappingType mapping_type; - opus_int32 bitrate_bps; - /* Encoder states go here */ - /* then opus_val32 window_mem[channels*120]; */ - /* then opus_val32 preemph_mem[channels]; */ -}; - -struct OpusMSDecoder { - ChannelLayout layout; - /* Decoder states go here */ -}; - -int opus_multistream_encoder_ctl_va_list(struct OpusMSEncoder *st, int request, - va_list ap); -int opus_multistream_decoder_ctl_va_list(struct OpusMSDecoder *st, int request, - va_list ap); - -int validate_layout(const ChannelLayout *layout); -int get_left_channel(const ChannelLayout *layout, int stream_id, int prev); -int get_right_channel(const ChannelLayout *layout, int stream_id, int prev); -int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev); - -typedef void (*opus_copy_channel_in_func)( - opus_val16 *dst, - int dst_stride, - const void *src, - int src_stride, - int src_channel, - int frame_size, - void *user_data -); - -typedef void (*opus_copy_channel_out_func)( - void *dst, - int dst_stride, - int dst_channel, - const opus_val16 *src, - int src_stride, - int frame_size, - void *user_data -); - -#define MODE_SILK_ONLY 1000 -#define MODE_HYBRID 1001 -#define MODE_CELT_ONLY 1002 - -#define OPUS_SET_VOICE_RATIO_REQUEST 11018 -#define OPUS_GET_VOICE_RATIO_REQUEST 11019 - -/** Configures the encoder's expected percentage of voice - opposed to music or other signals. - - @note This interface is currently more aspiration than actuality. It's - ultimately expected to bias an automatic signal classifier, but it currently - just shifts the static bitrate to mode mapping around a little bit. - - @param[in] x int: Voice percentage in the range 0-100, inclusive. - @hideinitializer */ -#define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO - - @param[out] x int*: Voice percentage in the range 0-100, inclusive. - @hideinitializer */ -#define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x) - - -#define OPUS_SET_FORCE_MODE_REQUEST 11002 -#define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x) - -typedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int); -void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C); -void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C); -int is_digital_silence(const opus_val16* pcm, int frame_size, int channels, int lsb_depth); - -int encode_size(int size, unsigned char *data); - -opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs); - -opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, - unsigned char *data, opus_int32 out_data_bytes, int lsb_depth, - const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, - int analysis_channels, downmix_func downmix, int float_api); - -int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len, - opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited, - opus_int32 *packet_offset, int soft_clip); - -/* Make sure everything is properly aligned. */ -static OPUS_INLINE int align(int i) { - struct foo { - char c; - union { - void* p; - opus_int32 i; - opus_val32 v; - } u; - }; - - unsigned int alignment = offsetof(struct foo, u); - - /* Optimizing compilers should optimize div and multiply into and - for all sensible alignment values. */ - return ((i + alignment - 1) / alignment) * alignment; -} - -int opus_packet_parse_impl(const unsigned char *data, opus_int32 len, - int self_delimited, unsigned char *out_toc, - const unsigned char *frames[48], opus_int16 size[48], - int *payload_offset, opus_int32 *packet_offset); - -opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end, - unsigned char *data, opus_int32 maxlen, int self_delimited, int pad); - -int pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len); - -int opus_multistream_encode_native -( - struct OpusMSEncoder *st, - opus_copy_channel_in_func copy_channel_in, - const void *pcm, - int analysis_frame_size, - unsigned char *data, - opus_int32 max_data_bytes, - int lsb_depth, - downmix_func downmix, - int float_api, - void *user_data -); - -int opus_multistream_decode_native( - struct OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - void *pcm, - opus_copy_channel_out_func copy_channel_out, - int frame_size, - int decode_fec, - int soft_clip, - void *user_data -); - -#endif /* OPUS_PRIVATE_H */ diff --git a/src/libopus/opus_projection.h b/src/libopus/opus_projection.h deleted file mode 100644 index eb763aa..0000000 --- a/src/libopus/opus_projection.h +++ /dev/null @@ -1,568 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - @file opus_projection.h - @brief Opus projection reference API -*/ - -#ifndef OPUS_PROJECTION_H -#define OPUS_PROJECTION_H - -#include "opus_multistream.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @cond OPUS_INTERNAL_DOC */ - -/** These are the actual encoder and decoder CTL ID numbers. - They should not be used directly by applications.c - In general, SETs should be even and GETs should be odd.*/ -/**@{*/ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST 6001 -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST 6003 -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST 6005 -/**@}*/ - - -/** @endcond */ - -/** @defgroup opus_projection_ctls Projection specific encoder and decoder CTLs - - These are convenience macros that are specific to the - opus_projection_encoder_ctl() and opus_projection_decoder_ctl() - interface. - The CTLs from @ref opus_genericctls, @ref opus_encoderctls, - @ref opus_decoderctls, and @ref opus_multistream_ctls may be applied to a - projection encoder or decoder as well. -*/ -/**@{*/ - -/** Gets the gain (in dB. S7.8-format) of the demixing matrix from the encoder. - @param[out] x opus_int32 *: Returns the gain (in dB. S7.8-format) - of the demixing matrix. - @hideinitializer -*/ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST, __opus_check_int_ptr(x) - - -/** Gets the size in bytes of the demixing matrix from the encoder. - @param[out] x opus_int32 *: Returns the size in bytes of the - demixing matrix. - @hideinitializer -*/ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST, __opus_check_int_ptr(x) - - -/** Copies the demixing matrix to the supplied pointer location. - @param[out] x unsigned char *: Returns the demixing matrix to the - supplied pointer location. - @param y opus_int32: The size in bytes of the reserved memory at the - pointer location. - @hideinitializer -*/ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX(x,y) OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST, x, __opus_check_int(y) - - -/**@}*/ - -/** Opus projection encoder state. - This contains the complete state of a projection Opus encoder. - It is position independent and can be freely copied. - @see opus_projection_ambisonics_encoder_create -*/ -typedef struct OpusProjectionEncoder OpusProjectionEncoder; - - -/** Opus projection decoder state. - This contains the complete state of a projection Opus decoder. - It is position independent and can be freely copied. - @see opus_projection_decoder_create - @see opus_projection_decoder_init -*/ -typedef struct OpusProjectionDecoder OpusProjectionDecoder; - - -/**\name Projection encoder functions */ -/**@{*/ - -/** Gets the size of an OpusProjectionEncoder structure. - @param channels int: The total number of input channels to encode. - This must be no more than 255. - @param mapping_family int: The mapping family to use for selecting - the appropriate projection. - @returns The size in bytes on success, or a negative error code - (see @ref opus_errorcodes) on error. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_ambisonics_encoder_get_size( - int channels, - int mapping_family -); - - -/** Allocates and initializes a projection encoder state. - Call opus_projection_encoder_destroy() to release - this object when finished. - @param Fs opus_int32: Sampling rate of the input signal (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels in the input signal. - This must be at most 255. - It may be greater than the number of - coded channels (streams + - coupled_streams). - @param mapping_family int: The mapping family to use for selecting - the appropriate projection. - @param[out] streams int *: The total number of streams that will - be encoded from the input. - @param[out] coupled_streams int *: Number of coupled (2 channel) - streams that will be encoded from the input. - @param application int: The target encoder application. - This must be one of the following: -
-
#OPUS_APPLICATION_VOIP
-
Process signal for improved speech intelligibility.
-
#OPUS_APPLICATION_AUDIO
-
Favor faithfulness to the original input.
-
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
-
Configure the minimum possible coding delay by disabling certain modes - of operation.
-
- @param[out] error int *: Returns #OPUS_OK on success, or an error - code (see @ref opus_errorcodes) on - failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionEncoder *opus_projection_ambisonics_encoder_create( - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - int application, - int *error -) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5); - - -/** Initialize a previously allocated projection encoder state. - The memory pointed to by \a st must be at least the size returned by - opus_projection_ambisonics_encoder_get_size(). - This is intended for applications which use their own allocator instead of - malloc. - To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - @see opus_projection_ambisonics_encoder_create - @see opus_projection_ambisonics_encoder_get_size - @param st OpusProjectionEncoder*: Projection encoder state to initialize. - @param Fs opus_int32: Sampling rate of the input signal (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels in the input signal. - This must be at most 255. - It may be greater than the number of - coded channels (streams + - coupled_streams). - @param streams int: The total number of streams to encode from the - input. - This must be no more than the number of channels. - @param coupled_streams int: Number of coupled (2 channel) streams - to encode. - This must be no larger than the total - number of streams. - Additionally, The total number of - encoded channels (streams + - coupled_streams) must be no - more than the number of input channels. - @param application int: The target encoder application. - This must be one of the following: -
-
#OPUS_APPLICATION_VOIP
-
Process signal for improved speech intelligibility.
-
#OPUS_APPLICATION_AUDIO
-
Favor faithfulness to the original input.
-
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
-
Configure the minimum possible coding delay by disabling certain modes - of operation.
-
- @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - on failure. -*/ -OPUS_EXPORT int opus_projection_ambisonics_encoder_init( - OpusProjectionEncoder *st, - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - int application -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); - - -/** Encodes a projection Opus frame. - @param st OpusProjectionEncoder*: Projection encoder state. - @param[in] pcm const opus_int16*: The input signal as interleaved - samples. - This must contain - frame_size*channels - samples. - @param frame_size int: Number of samples per channel in the input - signal. - This must be an Opus frame size for the - encoder's sampling rate. - For example, at 48 kHz the permitted values - are 120, 240, 480, 960, 1920, and 2880. - Passing in a duration of less than 10 ms - (480 samples at 48 kHz) will prevent the - encoder from using the LPC or hybrid modes. - @param[out] data unsigned char*: Output payload. - This must contain storage for at - least \a max_data_bytes. - @param [in] max_data_bytes opus_int32: Size of the allocated - memory for the output - payload. This may be - used to impose an upper limit on - the instant bitrate, but should - not be used as the only bitrate - control. Use #OPUS_SET_BITRATE to - control the bitrate. - @returns The length of the encoded packet (in bytes) on success or a - negative error code (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode( - OpusProjectionEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - - -/** Encodes a projection Opus frame from floating point input. - @param st OpusProjectionEncoder*: Projection encoder state. - @param[in] pcm const float*: The input signal as interleaved - samples with a normal range of - +/-1.0. - Samples with a range beyond +/-1.0 - are supported but will be clipped by - decoders using the integer API and - should only be used if it is known - that the far end supports extended - dynamic range. - This must contain - frame_size*channels - samples. - @param frame_size int: Number of samples per channel in the input - signal. - This must be an Opus frame size for the - encoder's sampling rate. - For example, at 48 kHz the permitted values - are 120, 240, 480, 960, 1920, and 2880. - Passing in a duration of less than 10 ms - (480 samples at 48 kHz) will prevent the - encoder from using the LPC or hybrid modes. - @param[out] data unsigned char*: Output payload. - This must contain storage for at - least \a max_data_bytes. - @param [in] max_data_bytes opus_int32: Size of the allocated - memory for the output - payload. This may be - used to impose an upper limit on - the instant bitrate, but should - not be used as the only bitrate - control. Use #OPUS_SET_BITRATE to - control the bitrate. - @returns The length of the encoded packet (in bytes) on success or a - negative error code (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode_float( - OpusProjectionEncoder *st, - const float *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - - -/** Frees an OpusProjectionEncoder allocated by - opus_projection_ambisonics_encoder_create(). - @param st OpusProjectionEncoder*: Projection encoder state to be freed. -*/ -OPUS_EXPORT void opus_projection_encoder_destroy(OpusProjectionEncoder *st); - - -/** Perform a CTL function on a projection Opus encoder. - - Generally the request and subsequent arguments are generated by a - convenience macro. - @param st OpusProjectionEncoder*: Projection encoder state. - @param request This and all remaining parameters should be replaced by one - of the convenience macros in @ref opus_genericctls, - @ref opus_encoderctls, @ref opus_multistream_ctls, or - @ref opus_projection_ctls - @see opus_genericctls - @see opus_encoderctls - @see opus_multistream_ctls - @see opus_projection_ctls -*/ -OPUS_EXPORT int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); - - -/**@}*/ - -/**\name Projection decoder functions */ -/**@{*/ - -/** Gets the size of an OpusProjectionDecoder structure. - @param channels int: The total number of output channels. - This must be no more than 255. - @param streams int: The total number of streams coded in the - input. - This must be no more than 255. - @param coupled_streams int: Number streams to decode as coupled - (2 channel) streams. - This must be no larger than the total - number of streams. - Additionally, The total number of - coded channels (streams + - coupled_streams) must be no - more than 255. - @returns The size in bytes on success, or a negative error code - (see @ref opus_errorcodes) on error. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_decoder_get_size( - int channels, - int streams, - int coupled_streams -); - - -/** Allocates and initializes a projection decoder state. - Call opus_projection_decoder_destroy() to release - this object when finished. - @param Fs opus_int32: Sampling rate to decode at (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels to output. - This must be at most 255. - It may be different from the number of coded - channels (streams + - coupled_streams). - @param streams int: The total number of streams coded in the - input. - This must be no more than 255. - @param coupled_streams int: Number of streams to decode as coupled - (2 channel) streams. - This must be no larger than the total - number of streams. - Additionally, The total number of - coded channels (streams + - coupled_streams) must be no - more than 255. - @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix - that mapping from coded channels to output channels, - as described in @ref opus_projection and - @ref opus_projection_ctls. - @param demixing_matrix_size opus_int32: The size in bytes of the - demixing matrix, as - described in @ref - opus_projection_ctls. - @param[out] error int *: Returns #OPUS_OK on success, or an error - code (see @ref opus_errorcodes) on - failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionDecoder *opus_projection_decoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - unsigned char *demixing_matrix, - opus_int32 demixing_matrix_size, - int *error -) OPUS_ARG_NONNULL(5); - - -/** Intialize a previously allocated projection decoder state object. - The memory pointed to by \a st must be at least the size returned by - opus_projection_decoder_get_size(). - This is intended for applications which use their own allocator instead of - malloc. - To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - @see opus_projection_decoder_create - @see opus_projection_deocder_get_size - @param st OpusProjectionDecoder*: Projection encoder state to initialize. - @param Fs opus_int32: Sampling rate to decode at (in Hz). - This must be one of 8000, 12000, 16000, - 24000, or 48000. - @param channels int: Number of channels to output. - This must be at most 255. - It may be different from the number of coded - channels (streams + - coupled_streams). - @param streams int: The total number of streams coded in the - input. - This must be no more than 255. - @param coupled_streams int: Number of streams to decode as coupled - (2 channel) streams. - This must be no larger than the total - number of streams. - Additionally, The total number of - coded channels (streams + - coupled_streams) must be no - more than 255. - @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix - that mapping from coded channels to output channels, - as described in @ref opus_projection and - @ref opus_projection_ctls. - @param demixing_matrix_size opus_int32: The size in bytes of the - demixing matrix, as - described in @ref - opus_projection_ctls. - @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - on failure. -*/ -OPUS_EXPORT int opus_projection_decoder_init( - OpusProjectionDecoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - unsigned char *demixing_matrix, - opus_int32 demixing_matrix_size -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); - - -/** Decode a projection Opus packet. - @param st OpusProjectionDecoder*: Projection decoder state. - @param[in] data const unsigned char*: Input payload. - Use a NULL - pointer to indicate packet - loss. - @param len opus_int32: Number of bytes in payload. - @param[out] pcm opus_int16*: Output signal, with interleaved - samples. - This must contain room for - frame_size*channels - samples. - @param frame_size int: The number of samples per channel of - available space in \a pcm. - If this is less than the maximum packet duration - (120 ms; 5760 for 48kHz), this function will not be capable - of decoding some packets. In the case of PLC (data==NULL) - or FEC (decode_fec=1), then frame_size needs to be exactly - the duration of audio that is missing, otherwise the - decoder will not be in the optimal state to decode the - next incoming packet. For the PLC and FEC cases, frame_size - must be a multiple of 2.5 ms. - @param decode_fec int: Flag (0 or 1) to request that any in-band - forward error correction data be decoded. - If no such data is available, the frame is - decoded as if it were lost. - @returns Number of samples decoded on success or a negative error code - (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode( - OpusProjectionDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_int16 *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - - -/** Decode a projection Opus packet with floating point output. - @param st OpusProjectionDecoder*: Projection decoder state. - @param[in] data const unsigned char*: Input payload. - Use a NULL - pointer to indicate packet - loss. - @param len opus_int32: Number of bytes in payload. - @param[out] pcm opus_int16*: Output signal, with interleaved - samples. - This must contain room for - frame_size*channels - samples. - @param frame_size int: The number of samples per channel of - available space in \a pcm. - If this is less than the maximum packet duration - (120 ms; 5760 for 48kHz), this function will not be capable - of decoding some packets. In the case of PLC (data==NULL) - or FEC (decode_fec=1), then frame_size needs to be exactly - the duration of audio that is missing, otherwise the - decoder will not be in the optimal state to decode the - next incoming packet. For the PLC and FEC cases, frame_size - must be a multiple of 2.5 ms. - @param decode_fec int: Flag (0 or 1) to request that any in-band - forward error correction data be decoded. - If no such data is available, the frame is - decoded as if it were lost. - @returns Number of samples decoded on success or a negative error code - (see @ref opus_errorcodes) on failure. -*/ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode_float( - OpusProjectionDecoder *st, - const unsigned char *data, - opus_int32 len, - float *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - - -/** Perform a CTL function on a projection Opus decoder. - - Generally the request and subsequent arguments are generated by a - convenience macro. - @param st OpusProjectionDecoder*: Projection decoder state. - @param request This and all remaining parameters should be replaced by one - of the convenience macros in @ref opus_genericctls, - @ref opus_decoderctls, @ref opus_multistream_ctls, or - @ref opus_projection_ctls. - @see opus_genericctls - @see opus_decoderctls - @see opus_multistream_ctls - @see opus_projection_ctls -*/ -OPUS_EXPORT int opus_projection_decoder_ctl(OpusProjectionDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); - - -/** Frees an OpusProjectionDecoder allocated by - opus_projection_decoder_create(). - @param st OpusProjectionDecoder: Projection decoder state to be freed. -*/ -OPUS_EXPORT void opus_projection_decoder_destroy(OpusProjectionDecoder *st); - - -/**@}*/ - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_PROJECTION_H */ diff --git a/src/libopus/opus_projection_decoder.c b/src/libopus/opus_projection_decoder.c deleted file mode 100644 index 4420a2a..0000000 --- a/src/libopus/opus_projection_decoder.c +++ /dev/null @@ -1,248 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "celt/mathops.h" -#include "celt/os_support.h" -#include "opus_private.h" -#include "opus_defines.h" -#include "opus_projection.h" -#include "opus_multistream.h" -#include "mapping_matrix.h" -#include "celt/stack_alloc.h" - -struct OpusProjectionDecoder { - opus_int32 demixing_matrix_size_in_bytes; - /* Encoder states go here */ -}; - -#if !defined(DISABLE_FLOAT_API) -static void opus_projection_copy_channel_out_float( - void *dst, - int dst_stride, - int dst_channel, - const opus_val16 *src, - int src_stride, - int frame_size, - void *user_data) { - float *float_dst; - const MappingMatrix *matrix; - float_dst = (float *)dst; - matrix = (const MappingMatrix *)user_data; - - if (dst_channel == 0) { - OPUS_CLEAR(float_dst, frame_size * dst_stride); - } - - if (src != NULL) - mapping_matrix_multiply_channel_out_float(matrix, src, dst_channel, - src_stride, float_dst, dst_stride, frame_size); -} -#endif - -static void opus_projection_copy_channel_out_short( - void *dst, - int dst_stride, - int dst_channel, - const opus_val16 *src, - int src_stride, - int frame_size, - void *user_data) { - opus_int16 *short_dst; - const MappingMatrix *matrix; - short_dst = (opus_int16 *)dst; - matrix = (const MappingMatrix *)user_data; - if (dst_channel == 0) { - OPUS_CLEAR(short_dst, frame_size * dst_stride); - } - - if (src != NULL) - mapping_matrix_multiply_channel_out_short(matrix, src, dst_channel, - src_stride, short_dst, dst_stride, frame_size); -} - -static MappingMatrix *get_dec_demixing_matrix(OpusProjectionDecoder *st) { - /* void* cast avoids clang -Wcast-align warning */ - return (MappingMatrix*)(void*)((char*)st + - align(sizeof(OpusProjectionDecoder))); -} - -static OpusMSDecoder *get_multistream_decoder(OpusProjectionDecoder *st) { - /* void* cast avoids clang -Wcast-align warning */ - return (OpusMSDecoder*)(void*)((char*)st + - align(sizeof(OpusProjectionDecoder) + - st->demixing_matrix_size_in_bytes)); -} - -opus_int32 opus_projection_decoder_get_size(int channels, int streams, - int coupled_streams) { - opus_int32 matrix_size; - opus_int32 decoder_size; - - matrix_size = - mapping_matrix_get_size(streams + coupled_streams, channels); - if (!matrix_size) { - return 0; - } - - decoder_size = opus_multistream_decoder_get_size(streams, coupled_streams); - if (!decoder_size) { - return 0; - } - - return align(sizeof(OpusProjectionDecoder)) + matrix_size + decoder_size; -} - -int opus_projection_decoder_init(OpusProjectionDecoder *st, opus_int32 Fs, - int channels, int streams, int coupled_streams, - unsigned char *demixing_matrix, opus_int32 demixing_matrix_size) { - int nb_input_streams; - opus_int32 expected_matrix_size; - int i, ret; - unsigned char mapping[255]; - VARDECL(opus_int16, buf); - ALLOC_STACK; - - /* Verify supplied matrix size. */ - nb_input_streams = streams + coupled_streams; - expected_matrix_size = nb_input_streams * channels * sizeof(opus_int16); - if (expected_matrix_size != demixing_matrix_size) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - /* Convert demixing matrix input into internal format. */ - ALLOC(buf, nb_input_streams * channels, opus_int16); - for (i = 0; i < nb_input_streams * channels; i++) { - int s = demixing_matrix[2 * i + 1] << 8 | demixing_matrix[2 * i]; - s = ((s & 0xFFFF) ^ 0x8000) - 0x8000; - buf[i] = (opus_int16)s; - } - - /* Assign demixing matrix. */ - st->demixing_matrix_size_in_bytes = - mapping_matrix_get_size(channels, nb_input_streams); - if (!st->demixing_matrix_size_in_bytes) { - RESTORE_STACK; - return OPUS_BAD_ARG; - } - - mapping_matrix_init(get_dec_demixing_matrix(st), channels, nb_input_streams, 0, - buf, demixing_matrix_size); - - /* Set trivial mapping so each input channel pairs with a matrix column. */ - for (i = 0; i < channels; i++) { - mapping[i] = i; - } - - ret = opus_multistream_decoder_init( - get_multistream_decoder(st), Fs, channels, streams, coupled_streams, mapping); - RESTORE_STACK; - return ret; -} - -OpusProjectionDecoder *opus_projection_decoder_create( - opus_int32 Fs, int channels, int streams, int coupled_streams, - unsigned char *demixing_matrix, opus_int32 demixing_matrix_size, int *error) { - int size; - int ret; - OpusProjectionDecoder *st; - - /* Allocate space for the projection decoder. */ - size = opus_projection_decoder_get_size(channels, streams, coupled_streams); - if (!size) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - st = (OpusProjectionDecoder *)opus_alloc(size); - if (!st) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - - /* Initialize projection decoder with provided settings. */ - ret = opus_projection_decoder_init(st, Fs, channels, streams, coupled_streams, - demixing_matrix, demixing_matrix_size); - if (ret != OPUS_OK) { - opus_free(st); - st = NULL; - } - if (error) { - *error = ret; - } - return st; -} - -#ifdef FIXED_POINT -int opus_projection_decode(OpusProjectionDecoder *st, const unsigned char *data, - opus_int32 len, opus_int16 *pcm, int frame_size, - int decode_fec) { - return opus_multistream_decode_native(get_multistream_decoder(st), data, len, - pcm, opus_projection_copy_channel_out_short, frame_size, decode_fec, 0, - get_dec_demixing_matrix(st)); -} -#else -int opus_projection_decode(OpusProjectionDecoder *st, const unsigned char *data, - opus_int32 len, opus_int16 *pcm, int frame_size, - int decode_fec) { - return opus_multistream_decode_native(get_multistream_decoder(st), data, len, - pcm, opus_projection_copy_channel_out_short, frame_size, decode_fec, 1, - get_dec_demixing_matrix(st)); -} -#endif - -#ifndef DISABLE_FLOAT_API -int opus_projection_decode_float(OpusProjectionDecoder *st, const unsigned char *data, - opus_int32 len, float *pcm, int frame_size, int decode_fec) { - return opus_multistream_decode_native(get_multistream_decoder(st), data, len, - pcm, opus_projection_copy_channel_out_float, frame_size, decode_fec, 0, - get_dec_demixing_matrix(st)); -} -#endif - -int opus_projection_decoder_ctl(OpusProjectionDecoder *st, int request, ...) { - va_list ap; - int ret = OPUS_OK; - - va_start(ap, request); - ret = opus_multistream_decoder_ctl_va_list(get_multistream_decoder(st), - request, ap); - va_end(ap); - return ret; -} - -void opus_projection_decoder_destroy(OpusProjectionDecoder *st) { - opus_free(st); -} - diff --git a/src/libopus/opus_projection_encoder.c b/src/libopus/opus_projection_encoder.c deleted file mode 100644 index 738e038..0000000 --- a/src/libopus/opus_projection_encoder.c +++ /dev/null @@ -1,442 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#if 0 -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "celt/mathops.h" -#include "celt/os_support.h" -#include "opus_private.h" -#include "opus_defines.h" -#include "opus_projection.h" -#include "opus_multistream.h" -#include "celt/stack_alloc.h" -#include "mapping_matrix.h" - -struct OpusProjectionEncoder { - opus_int32 mixing_matrix_size_in_bytes; - opus_int32 demixing_matrix_size_in_bytes; - /* Encoder states go here */ -}; - -#if !defined(DISABLE_FLOAT_API) -static void opus_projection_copy_channel_in_float( - opus_val16 *dst, - int dst_stride, - const void *src, - int src_stride, - int src_channel, - int frame_size, - void *user_data -) { - mapping_matrix_multiply_channel_in_float((const MappingMatrix*)user_data, - (const float*)src, src_stride, dst, src_channel, dst_stride, frame_size); -} -#endif - -static void opus_projection_copy_channel_in_short( - opus_val16 *dst, - int dst_stride, - const void *src, - int src_stride, - int src_channel, - int frame_size, - void *user_data -) { - mapping_matrix_multiply_channel_in_short((const MappingMatrix*)user_data, - (const opus_int16*)src, src_stride, dst, src_channel, dst_stride, frame_size); -} - -static int get_order_plus_one_from_channels(int channels, int *order_plus_one) { - int order_plus_one_; - int acn_channels; - int nondiegetic_channels; - - /* Allowed numbers of channels: - (1 + n)^2 + 2j, for n = 0...14 and j = 0 or 1. - */ - if (channels < 1 || channels > 227) { - return OPUS_BAD_ARG; - } - - order_plus_one_ = isqrt32(channels); - acn_channels = order_plus_one_ * order_plus_one_; - nondiegetic_channels = channels - acn_channels; - if (nondiegetic_channels != 0 && nondiegetic_channels != 2) { - return OPUS_BAD_ARG; - } - - if (order_plus_one) { - *order_plus_one = order_plus_one_; - } - return OPUS_OK; -} - -static int get_streams_from_channels(int channels, int mapping_family, - int *streams, int *coupled_streams, - int *order_plus_one) { - if (mapping_family == 3) { - if (get_order_plus_one_from_channels(channels, order_plus_one) != OPUS_OK) { - return OPUS_BAD_ARG; - } - if (streams) { - *streams = (channels + 1) / 2; - } - if (coupled_streams) { - *coupled_streams = channels / 2; - } - return OPUS_OK; - } - return OPUS_BAD_ARG; -} - -static MappingMatrix *get_mixing_matrix(OpusProjectionEncoder *st) { - /* void* cast avoids clang -Wcast-align warning */ - return (MappingMatrix *)(void*)((char*)st + - align(sizeof(OpusProjectionEncoder))); -} - -static MappingMatrix *get_enc_demixing_matrix(OpusProjectionEncoder *st) { - /* void* cast avoids clang -Wcast-align warning */ - return (MappingMatrix *)(void*)((char*)st + - align(sizeof(OpusProjectionEncoder) + - st->mixing_matrix_size_in_bytes)); -} - -static OpusMSEncoder *get_multistream_encoder(OpusProjectionEncoder *st) { - /* void* cast avoids clang -Wcast-align warning */ - return (OpusMSEncoder *)(void*)((char*)st + - align(sizeof(OpusProjectionEncoder) + - st->mixing_matrix_size_in_bytes + - st->demixing_matrix_size_in_bytes)); -} - -opus_int32 opus_projection_ambisonics_encoder_get_size(int channels, - int mapping_family) { - int nb_streams; - int nb_coupled_streams; - int order_plus_one; - int mixing_matrix_rows, mixing_matrix_cols; - int demixing_matrix_rows, demixing_matrix_cols; - opus_int32 mixing_matrix_size, demixing_matrix_size; - opus_int32 encoder_size; - int ret; - - ret = get_streams_from_channels(channels, mapping_family, &nb_streams, - &nb_coupled_streams, &order_plus_one); - if (ret != OPUS_OK) { - return 0; - } - - if (order_plus_one == 2) { - mixing_matrix_rows = mapping_matrix_foa_mixing.rows; - mixing_matrix_cols = mapping_matrix_foa_mixing.cols; - demixing_matrix_rows = mapping_matrix_foa_demixing.rows; - demixing_matrix_cols = mapping_matrix_foa_demixing.cols; - } else if (order_plus_one == 3) { - mixing_matrix_rows = mapping_matrix_soa_mixing.rows; - mixing_matrix_cols = mapping_matrix_soa_mixing.cols; - demixing_matrix_rows = mapping_matrix_soa_demixing.rows; - demixing_matrix_cols = mapping_matrix_soa_demixing.cols; - } else if (order_plus_one == 4) { - mixing_matrix_rows = mapping_matrix_toa_mixing.rows; - mixing_matrix_cols = mapping_matrix_toa_mixing.cols; - demixing_matrix_rows = mapping_matrix_toa_demixing.rows; - demixing_matrix_cols = mapping_matrix_toa_demixing.cols; - } else { - return 0; - } - - mixing_matrix_size = - mapping_matrix_get_size(mixing_matrix_rows, mixing_matrix_cols); - if (!mixing_matrix_size) { - return 0; - } - - demixing_matrix_size = - mapping_matrix_get_size(demixing_matrix_rows, demixing_matrix_cols); - if (!demixing_matrix_size) { - return 0; - } - - encoder_size = - opus_multistream_encoder_get_size(nb_streams, nb_coupled_streams); - if (!encoder_size) { - return 0; - } - - return align(sizeof(OpusProjectionEncoder)) + - mixing_matrix_size + demixing_matrix_size + encoder_size; -} - -int opus_projection_ambisonics_encoder_init(OpusProjectionEncoder *st, opus_int32 Fs, - int channels, int mapping_family, - int *streams, int *coupled_streams, - int application) { - MappingMatrix *mixing_matrix; - MappingMatrix *demixing_matrix; - OpusMSEncoder *ms_encoder; - int i; - int ret; - int order_plus_one; - unsigned char mapping[255]; - - if (streams == NULL || coupled_streams == NULL) { - return OPUS_BAD_ARG; - } - - if (get_streams_from_channels(channels, mapping_family, streams, - coupled_streams, &order_plus_one) != OPUS_OK) { - return OPUS_BAD_ARG; - } - - if (mapping_family == 3) { - /* Assign mixing matrix based on available pre-computed matrices. */ - mixing_matrix = get_mixing_matrix(st); - if (order_plus_one == 2) { - mapping_matrix_init(mixing_matrix, mapping_matrix_foa_mixing.rows, - mapping_matrix_foa_mixing.cols, mapping_matrix_foa_mixing.gain, - mapping_matrix_foa_mixing_data, - sizeof(mapping_matrix_foa_mixing_data)); - } else if (order_plus_one == 3) { - mapping_matrix_init(mixing_matrix, mapping_matrix_soa_mixing.rows, - mapping_matrix_soa_mixing.cols, mapping_matrix_soa_mixing.gain, - mapping_matrix_soa_mixing_data, - sizeof(mapping_matrix_soa_mixing_data)); - } else if (order_plus_one == 4) { - mapping_matrix_init(mixing_matrix, mapping_matrix_toa_mixing.rows, - mapping_matrix_toa_mixing.cols, mapping_matrix_toa_mixing.gain, - mapping_matrix_toa_mixing_data, - sizeof(mapping_matrix_toa_mixing_data)); - } else { - return OPUS_BAD_ARG; - } - - st->mixing_matrix_size_in_bytes = mapping_matrix_get_size( - mixing_matrix->rows, mixing_matrix->cols); - if (!st->mixing_matrix_size_in_bytes) { - return OPUS_BAD_ARG; - } - - /* Assign demixing matrix based on available pre-computed matrices. */ - demixing_matrix = get_enc_demixing_matrix(st); - if (order_plus_one == 2) { - mapping_matrix_init(demixing_matrix, mapping_matrix_foa_demixing.rows, - mapping_matrix_foa_demixing.cols, mapping_matrix_foa_demixing.gain, - mapping_matrix_foa_demixing_data, - sizeof(mapping_matrix_foa_demixing_data)); - } else if (order_plus_one == 3) { - mapping_matrix_init(demixing_matrix, mapping_matrix_soa_demixing.rows, - mapping_matrix_soa_demixing.cols, mapping_matrix_soa_demixing.gain, - mapping_matrix_soa_demixing_data, - sizeof(mapping_matrix_soa_demixing_data)); - } else if (order_plus_one == 4) { - mapping_matrix_init(demixing_matrix, mapping_matrix_toa_demixing.rows, - mapping_matrix_toa_demixing.cols, mapping_matrix_toa_demixing.gain, - mapping_matrix_toa_demixing_data, - sizeof(mapping_matrix_toa_demixing_data)); - } else { - return OPUS_BAD_ARG; - } - - st->demixing_matrix_size_in_bytes = mapping_matrix_get_size( - demixing_matrix->rows, demixing_matrix->cols); - if (!st->demixing_matrix_size_in_bytes) { - return OPUS_BAD_ARG; - } - } else { - return OPUS_UNIMPLEMENTED; - } - - /* Ensure matrices are large enough for desired coding scheme. */ - if (*streams + *coupled_streams > mixing_matrix->rows || - channels > mixing_matrix->cols || - channels > demixing_matrix->rows || - *streams + *coupled_streams > demixing_matrix->cols) { - return OPUS_BAD_ARG; - } - - /* Set trivial mapping so each input channel pairs with a matrix column. */ - for (i = 0; i < channels; i++) { - mapping[i] = i; - } - - /* Initialize multistream encoder with provided settings. */ - ms_encoder = get_multistream_encoder(st); - ret = opus_multistream_encoder_init(ms_encoder, Fs, channels, *streams, - *coupled_streams, mapping, application); - return ret; -} - -OpusProjectionEncoder *opus_projection_ambisonics_encoder_create( - opus_int32 Fs, int channels, int mapping_family, int *streams, - int *coupled_streams, int application, int *error) { - int size; - int ret; - OpusProjectionEncoder *st; - - /* Allocate space for the projection encoder. */ - size = opus_projection_ambisonics_encoder_get_size(channels, mapping_family); - if (!size) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - st = (OpusProjectionEncoder *)opus_alloc(size); - if (!st) { - if (error) { - *error = OPUS_ALLOC_FAIL; - } - return NULL; - } - - /* Initialize projection encoder with provided settings. */ - ret = opus_projection_ambisonics_encoder_init(st, Fs, channels, - mapping_family, streams, coupled_streams, application); - if (ret != OPUS_OK) { - opus_free(st); - st = NULL; - } - if (error) { - *error = ret; - } - return st; -} - -int opus_projection_encode(OpusProjectionEncoder *st, const opus_int16 *pcm, - int frame_size, unsigned char *data, - opus_int32 max_data_bytes) { - return opus_multistream_encode_native(get_multistream_encoder(st), - opus_projection_copy_channel_in_short, pcm, frame_size, data, - max_data_bytes, 16, downmix_int, 0, get_mixing_matrix(st)); -} - -#ifndef DISABLE_FLOAT_API -#ifdef FIXED_POINT -int opus_projection_encode_float(OpusProjectionEncoder *st, const float *pcm, - int frame_size, unsigned char *data, - opus_int32 max_data_bytes) { - return opus_multistream_encode_native(get_multistream_encoder(st), - opus_projection_copy_channel_in_float, pcm, frame_size, data, - max_data_bytes, 16, downmix_float, 1, get_mixing_matrix(st)); -} -#else -int opus_projection_encode_float(OpusProjectionEncoder *st, const float *pcm, - int frame_size, unsigned char *data, - opus_int32 max_data_bytes) { - return opus_multistream_encode_native(get_multistream_encoder(st), - opus_projection_copy_channel_in_float, pcm, frame_size, data, - max_data_bytes, 24, downmix_float, 1, get_mixing_matrix(st)); -} -#endif -#endif - -void opus_projection_encoder_destroy(OpusProjectionEncoder *st) { - opus_free(st); -} - -int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...) { - va_list ap; - MappingMatrix *demixing_matrix; - OpusMSEncoder *ms_encoder; - int ret = OPUS_OK; - - ms_encoder = get_multistream_encoder(st); - demixing_matrix = get_enc_demixing_matrix(st); - - va_start(ap, request); - switch (request) { - case OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = - ms_encoder->layout.nb_channels * (ms_encoder->layout.nb_streams - + ms_encoder->layout.nb_coupled_streams) * sizeof(opus_int16); - } - break; - case OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST: { - opus_int32 *value = va_arg(ap, opus_int32*); - if (!value) { - goto bad_arg; - } - *value = demixing_matrix->gain; - } - break; - case OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST: { - int i, j, k, l; - int nb_input_streams; - int nb_output_streams; - unsigned char *external_char; - opus_int16 *internal_short; - opus_int32 external_size; - opus_int32 internal_size; - - /* (I/O is in relation to the decoder's perspective). */ - nb_input_streams = ms_encoder->layout.nb_streams + - ms_encoder->layout.nb_coupled_streams; - nb_output_streams = ms_encoder->layout.nb_channels; - - external_char = va_arg(ap, unsigned char *); - external_size = va_arg(ap, opus_int32); - if (!external_char) { - goto bad_arg; - } - internal_short = mapping_matrix_get_data(demixing_matrix); - internal_size = nb_input_streams * nb_output_streams * sizeof(opus_int16); - if (external_size != internal_size) { - goto bad_arg; - } - - /* Copy demixing matrix subset to output destination. */ - l = 0; - for (i = 0; i < nb_input_streams; i++) { - for (j = 0; j < nb_output_streams; j++) { - k = demixing_matrix->rows * i + j; - external_char[2 * l] = (unsigned char)internal_short[k]; - external_char[2 * l + 1] = (unsigned char)(internal_short[k] >> 8); - l++; - } - } - } - break; - default: { - ret = opus_multistream_encoder_ctl_va_list(ms_encoder, request, ap); - } - break; - } - va_end(ap); - return ret; - -bad_arg: - va_end(ap); - return OPUS_BAD_ARG; -} -#endif diff --git a/src/libopus/opus_types.h b/src/libopus/opus_types.h deleted file mode 100644 index 9a8f54e..0000000 --- a/src/libopus/opus_types.h +++ /dev/null @@ -1,166 +0,0 @@ -/* (C) COPYRIGHT 1994-2002 Xiph.Org Foundation */ -/* Modified by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -/* opus_types.h based on ogg_types.h from libogg */ - -/** - @file opus_types.h - @brief Opus reference implementation types -*/ -#ifndef OPUS_TYPES_H -#define OPUS_TYPES_H - -#define opus_int int /* used for counters etc; at least 16 bits */ -#define opus_int64 long long -#define opus_int8 signed char - -#define opus_uint unsigned int /* used for counters etc; at least 16 bits */ -#define opus_uint64 unsigned long long -#define opus_uint8 unsigned char - -/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */ -#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H)) -#include -# undef opus_int64 -# undef opus_int8 -# undef opus_uint64 -# undef opus_uint8 -typedef int8_t opus_int8; -typedef uint8_t opus_uint8; -typedef int16_t opus_int16; -typedef uint16_t opus_uint16; -typedef int32_t opus_int32; -typedef uint32_t opus_uint32; -typedef int64_t opus_int64; -typedef uint64_t opus_uint64; -#elif defined(_WIN32) - -# if defined(__CYGWIN__) -# include <_G_config.h> -typedef _G_int32_t opus_int32; -typedef _G_uint32_t opus_uint32; -typedef _G_int16 opus_int16; -typedef _G_uint16 opus_uint16; -# elif defined(__MINGW32__) -typedef short opus_int16; -typedef unsigned short opus_uint16; -typedef int opus_int32; -typedef unsigned int opus_uint32; -# elif defined(__MWERKS__) -typedef int opus_int32; -typedef unsigned int opus_uint32; -typedef short opus_int16; -typedef unsigned short opus_uint16; -# else -/* MSVC/Borland */ -typedef __int32 opus_int32; -typedef unsigned __int32 opus_uint32; -typedef __int16 opus_int16; -typedef unsigned __int16 opus_uint16; -# endif - -#elif defined(__MACOS__) - -# include -typedef SInt16 opus_int16; -typedef UInt16 opus_uint16; -typedef SInt32 opus_int32; -typedef UInt32 opus_uint32; - -#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ - -# include -typedef int16_t opus_int16; -typedef u_int16_t opus_uint16; -typedef int32_t opus_int32; -typedef u_int32_t opus_uint32; - -#elif defined(__BEOS__) - -/* Be */ -# include -typedef int16 opus_int16; -typedef u_int16 opus_uint16; -typedef int32_t opus_int32; -typedef u_int32_t opus_uint32; - -#elif defined (__EMX__) - -/* OS/2 GCC */ -typedef short opus_int16; -typedef unsigned short opus_uint16; -typedef int opus_int32; -typedef unsigned int opus_uint32; - -#elif defined (DJGPP) - -/* DJGPP */ -typedef short opus_int16; -typedef unsigned short opus_uint16; -typedef int opus_int32; -typedef unsigned int opus_uint32; - -#elif defined(R5900) - -/* PS2 EE */ -typedef int opus_int32; -typedef unsigned opus_uint32; -typedef short opus_int16; -typedef unsigned short opus_uint16; - -#elif defined(__SYMBIAN32__) - -/* Symbian GCC */ -typedef signed short opus_int16; -typedef unsigned short opus_uint16; -typedef signed int opus_int32; -typedef unsigned int opus_uint32; - -#elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) - -typedef short opus_int16; -typedef unsigned short opus_uint16; -typedef long opus_int32; -typedef unsigned long opus_uint32; - -#elif defined(CONFIG_TI_C6X) - -typedef short opus_int16; -typedef unsigned short opus_uint16; -typedef int opus_int32; -typedef unsigned int opus_uint32; - -#else - -/* Give up, take a reasonable guess */ -typedef short opus_int16; -typedef unsigned short opus_uint16; -typedef int opus_int32; -typedef unsigned int opus_uint32; - -#endif - -#endif /* OPUS_TYPES_H */ diff --git a/src/libopus/repacketizer.c b/src/libopus/repacketizer.c deleted file mode 100644 index 98ae89a..0000000 --- a/src/libopus/repacketizer.c +++ /dev/null @@ -1,366 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "opus.h" -#include "opus_private.h" -#include "celt/os_support.h" - - -int opus_repacketizer_get_size(void) { - return sizeof(OpusRepacketizer); -} - -OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) { - rp->nb_frames = 0; - return rp; -} - -OpusRepacketizer *opus_repacketizer_create(void) { - OpusRepacketizer *rp; - rp = (OpusRepacketizer *)opus_alloc(opus_repacketizer_get_size()); - if (rp == NULL) { - return NULL; - } - return opus_repacketizer_init(rp); -} - -void opus_repacketizer_destroy(OpusRepacketizer *rp) { - opus_free(rp); -} - -static int opus_repacketizer_cat_impl(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len, int self_delimited) { - unsigned char tmp_toc; - int curr_nb_frames, ret; - /* Set of check ToC */ - if (len < 1) { - return OPUS_INVALID_PACKET; - } - if (rp->nb_frames == 0) { - rp->toc = data[0]; - rp->framesize = opus_packet_get_samples_per_frame(data, 8000); - } else if ((rp->toc & 0xFC) != (data[0] & 0xFC)) { - /*fprintf(stderr, "toc mismatch: 0x%x vs 0x%x\n", rp->toc, data[0]);*/ - return OPUS_INVALID_PACKET; - } - curr_nb_frames = opus_packet_get_nb_frames(data, len); - if (curr_nb_frames < 1) { - return OPUS_INVALID_PACKET; - } - - /* Check the 120 ms maximum packet size */ - if ((curr_nb_frames + rp->nb_frames)*rp->framesize > 960) { - return OPUS_INVALID_PACKET; - } - - ret = opus_packet_parse_impl(data, len, self_delimited, &tmp_toc, &rp->frames[rp->nb_frames], &rp->len[rp->nb_frames], NULL, NULL); - if (ret < 1) { - return ret; - } - - rp->nb_frames += curr_nb_frames; - return OPUS_OK; -} - -int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) { - return opus_repacketizer_cat_impl(rp, data, len, 0); -} - -int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) { - return rp->nb_frames; -} - -opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end, - unsigned char *data, opus_int32 maxlen, int self_delimited, int pad) { - int i, count; - opus_int32 tot_size; - opus_int16 *len; - const unsigned char **frames; - unsigned char * ptr; - - if (begin < 0 || begin >= end || end > rp->nb_frames) { - /*fprintf(stderr, "%d %d %d\n", begin, end, rp->nb_frames);*/ - return OPUS_BAD_ARG; - } - count = end - begin; - - len = rp->len + begin; - frames = rp->frames + begin; - if (self_delimited) { - tot_size = 1 + (len[count - 1] >= 252); - } else { - tot_size = 0; - } - - ptr = data; - if (count == 1) { - /* Code 0 */ - tot_size += len[0] + 1; - if (tot_size > maxlen) { - return OPUS_BUFFER_TOO_SMALL; - } - *ptr++ = rp->toc & 0xFC; - } else if (count == 2) { - if (len[1] == len[0]) { - /* Code 1 */ - tot_size += 2 * len[0] + 1; - if (tot_size > maxlen) { - return OPUS_BUFFER_TOO_SMALL; - } - *ptr++ = (rp->toc & 0xFC) | 0x1; - } else { - /* Code 2 */ - tot_size += len[0] + len[1] + 2 + (len[0] >= 252); - if (tot_size > maxlen) { - return OPUS_BUFFER_TOO_SMALL; - } - *ptr++ = (rp->toc & 0xFC) | 0x2; - ptr += encode_size(len[0], ptr); - } - } - if (count > 2 || (pad && tot_size < maxlen)) { - /* Code 3 */ - int vbr; - int pad_amount = 0; - - /* Restart the process for the padding case */ - ptr = data; - if (self_delimited) { - tot_size = 1 + (len[count - 1] >= 252); - } else { - tot_size = 0; - } - vbr = 0; - for (i = 1; i < count; i++) { - if (len[i] != len[0]) { - vbr = 1; - break; - } - } - if (vbr) { - tot_size += 2; - for (i = 0; i < count - 1; i++) { - tot_size += 1 + (len[i] >= 252) + len[i]; - } - tot_size += len[count - 1]; - - if (tot_size > maxlen) { - return OPUS_BUFFER_TOO_SMALL; - } - *ptr++ = (rp->toc & 0xFC) | 0x3; - *ptr++ = count | 0x80; - } else { - tot_size += count * len[0] + 2; - if (tot_size > maxlen) { - return OPUS_BUFFER_TOO_SMALL; - } - *ptr++ = (rp->toc & 0xFC) | 0x3; - *ptr++ = count; - } - pad_amount = pad ? (maxlen - tot_size) : 0; - if (pad_amount != 0) { - int nb_255s; - data[1] |= 0x40; - nb_255s = (pad_amount - 1) / 255; - for (i = 0; i < nb_255s; i++) { - *ptr++ = 255; - } - *ptr++ = pad_amount - 255 * nb_255s - 1; - tot_size += pad_amount; - } - if (vbr) { - for (i = 0; i < count - 1; i++) { - ptr += encode_size(len[i], ptr); - } - } - } - if (self_delimited) { - int sdlen = encode_size(len[count - 1], ptr); - ptr += sdlen; - } - /* Copy the actual data */ - for (i = 0; i < count; i++) { - /* Using OPUS_MOVE() instead of OPUS_COPY() in case we're doing in-place - padding from opus_packet_pad or opus_packet_unpad(). */ - /* assert disabled because it's not valid in C. */ - /* celt_assert(frames[i] + len[i] <= data || ptr <= frames[i]); */ - OPUS_MOVE(ptr, frames[i], len[i]); - ptr += len[i]; - } - if (pad) { - /* Fill padding with zeros. */ - while (ptr < data + maxlen) { - *ptr++ = 0; - } - } - return tot_size; -} - -opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) { - return opus_repacketizer_out_range_impl(rp, begin, end, data, maxlen, 0, 0); -} - -opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) { - return opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, maxlen, 0, 0); -} - -int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len) { - OpusRepacketizer *rp = (OpusRepacketizer*)malloc(sizeof(OpusRepacketizer)); - opus_int32 ret; - if (len < 1) { - free(rp); - return OPUS_BAD_ARG; - } - if (len == new_len) { - free(rp); - return OPUS_OK; - } else if (len > new_len) { - free(rp); - return OPUS_BAD_ARG; - } - opus_repacketizer_init(rp); - /* Moving payload to the end of the packet so we can do in-place padding */ - OPUS_MOVE(data + new_len - len, data, len); - ret = opus_repacketizer_cat(rp, data + new_len - len, len); - if (ret != OPUS_OK) { - free(rp); - return ret; - } - ret = opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, new_len, 0, 1); - free(rp); - if (ret > 0) { - return OPUS_OK; - } else { - return ret; - } -} - -opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len) { - OpusRepacketizer *rp = (OpusRepacketizer*)malloc(sizeof(OpusRepacketizer)); - opus_int32 ret; - if (len < 1) { - free(rp); - return OPUS_BAD_ARG; - } - opus_repacketizer_init(rp); - ret = opus_repacketizer_cat(rp, data, len); - if (ret < 0) { - free(rp); - return ret; - } - ret = opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, len, 0, 0); - free(rp); - celt_assert(ret > 0 && ret <= len); - return ret; -} - -int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams) { - int s; - int count; - unsigned char toc; - opus_int16 size[48]; - opus_int32 packet_offset; - opus_int32 amount; - - if (len < 1) { - return OPUS_BAD_ARG; - } - if (len == new_len) { - return OPUS_OK; - } else if (len > new_len) { - return OPUS_BAD_ARG; - } - amount = new_len - len; - /* Seek to last stream */ - for (s = 0; s < nb_streams - 1; s++) { - if (len <= 0) { - return OPUS_INVALID_PACKET; - } - count = opus_packet_parse_impl(data, len, 1, &toc, NULL, - size, NULL, &packet_offset); - if (count < 0) { - return count; - } - data += packet_offset; - len -= packet_offset; - } - return opus_packet_pad(data, len, len + amount); -} - -opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, int nb_streams) { - int s; - unsigned char toc; - opus_int16 size[48]; - opus_int32 packet_offset; - OpusRepacketizer *rp = (OpusRepacketizer*)malloc(sizeof(OpusRepacketizer)); - unsigned char *dst; - opus_int32 dst_len; - - if (len < 1) { - free(rp); - return OPUS_BAD_ARG; - } - dst = data; - dst_len = 0; - /* Unpad all frames */ - for (s = 0; s < nb_streams; s++) { - opus_int32 ret; - int self_delimited = s != nb_streams - 1; - if (len <= 0) { - free(rp); - return OPUS_INVALID_PACKET; - } - opus_repacketizer_init(rp); - ret = opus_packet_parse_impl(data, len, self_delimited, &toc, NULL, - size, NULL, &packet_offset); - if (ret < 0) { - free(rp); - return ret; - } - ret = opus_repacketizer_cat_impl(rp, data, packet_offset, self_delimited); - if (ret < 0) { - free(rp); - return ret; - } - ret = opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, dst, len, self_delimited, 0); - if (ret < 0) { - free(rp); - return ret; - } else { - dst_len += ret; - } - dst += ret; - data += packet_offset; - len -= packet_offset; - } - free(rp); - return dst_len; -} - diff --git a/src/libopus/silk/A2NLSF.c b/src/libopus/silk/A2NLSF.c index bb3b88b..911315d 100644 --- a/src/libopus/silk/A2NLSF.c +++ b/src/libopus/silk/A2NLSF.c @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* Conversion between prediction filter coefficients and NLSFs */ @@ -31,9 +31,9 @@ /* Therefore the result is not accurate NLSFs, but the two */ /* functions are accurate inverses of each other */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "tables.h" @@ -47,14 +47,15 @@ static OPUS_INLINE void silk_A2NLSF_trans_poly( opus_int32 *p, /* I/O Polynomial */ const opus_int dd /* I Polynomial order (= filter order / 2 ) */ -) { +) +{ opus_int k, n; - for (k = 2; k <= dd; k++) { - for (n = dd; n > k; n--) { + for( k = 2; k <= dd; k++ ) { + for( n = dd; n > k; n-- ) { p[ n - 2 ] -= p[ n ]; } - p[ k - 2 ] -= silk_LSHIFT(p[ k ], 1); + p[ k - 2 ] -= silk_LSHIFT( p[ k ], 1 ); } } /* Helper function for A2NLSF(..) */ @@ -63,42 +64,47 @@ static OPUS_INLINE opus_int32 silk_A2NLSF_eval_poly( /* return the polynomial ev opus_int32 *p, /* I Polynomial, Q16 */ const opus_int32 x, /* I Evaluation point, Q12 */ const opus_int dd /* I Order */ -) { +) +{ opus_int n; opus_int32 x_Q16, y32; y32 = p[ dd ]; /* Q16 */ - x_Q16 = silk_LSHIFT(x, 4); + x_Q16 = silk_LSHIFT( x, 4 ); - if (opus_likely(8 == dd)) { - y32 = silk_SMLAWW(p[ 7 ], y32, x_Q16); - y32 = silk_SMLAWW(p[ 6 ], y32, x_Q16); - y32 = silk_SMLAWW(p[ 5 ], y32, x_Q16); - y32 = silk_SMLAWW(p[ 4 ], y32, x_Q16); - y32 = silk_SMLAWW(p[ 3 ], y32, x_Q16); - y32 = silk_SMLAWW(p[ 2 ], y32, x_Q16); - y32 = silk_SMLAWW(p[ 1 ], y32, x_Q16); - y32 = silk_SMLAWW(p[ 0 ], y32, x_Q16); - } else { - for (n = dd - 1; n >= 0; n--) { - y32 = silk_SMLAWW(p[ n ], y32, x_Q16); /* Q16 */ + if ( opus_likely( 8 == dd ) ) + { + y32 = silk_SMLAWW( p[ 7 ], y32, x_Q16 ); + y32 = silk_SMLAWW( p[ 6 ], y32, x_Q16 ); + y32 = silk_SMLAWW( p[ 5 ], y32, x_Q16 ); + y32 = silk_SMLAWW( p[ 4 ], y32, x_Q16 ); + y32 = silk_SMLAWW( p[ 3 ], y32, x_Q16 ); + y32 = silk_SMLAWW( p[ 2 ], y32, x_Q16 ); + y32 = silk_SMLAWW( p[ 1 ], y32, x_Q16 ); + y32 = silk_SMLAWW( p[ 0 ], y32, x_Q16 ); + } + else + { + for( n = dd - 1; n >= 0; n-- ) { + y32 = silk_SMLAWW( p[ n ], y32, x_Q16 ); /* Q16 */ } } return y32; } static OPUS_INLINE void silk_A2NLSF_init( - const opus_int32 *a_Q16, - opus_int32 *P, - opus_int32 *Q, - const opus_int dd -) { + const opus_int32 *a_Q16, + opus_int32 *P, + opus_int32 *Q, + const opus_int dd +) +{ opus_int k; /* Convert filter coefs to even and odd polynomials */ - P[dd] = silk_LSHIFT(1, 16); - Q[dd] = silk_LSHIFT(1, 16); - for (k = 0; k < dd; k++) { + P[dd] = silk_LSHIFT( 1, 16 ); + Q[dd] = silk_LSHIFT( 1, 16 ); + for( k = 0; k < dd; k++ ) { P[ k ] = -a_Q16[ dd - k - 1 ] - a_Q16[ dd + k ]; /* Q16 */ Q[ k ] = -a_Q16[ dd - k - 1 ] + a_Q16[ dd + k ]; /* Q16 */ } @@ -106,14 +112,14 @@ static OPUS_INLINE void silk_A2NLSF_init( /* Divide out zeros as we have that for even filter orders, */ /* z = 1 is always a root in Q, and */ /* z = -1 is always a root in P */ - for (k = dd; k > 0; k--) { + for( k = dd; k > 0; k-- ) { P[ k - 1 ] -= P[ k ]; Q[ k - 1 ] += Q[ k ]; } /* Transform polynomials from cos(n*f) to cos(f)^n */ - silk_A2NLSF_trans_poly(P, dd); - silk_A2NLSF_trans_poly(Q, dd); + silk_A2NLSF_trans_poly( P, dd ); + silk_A2NLSF_trans_poly( Q, dd ); } /* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */ @@ -122,7 +128,8 @@ void silk_A2NLSF( opus_int16 *NLSF, /* O Normalized Line Spectral Frequencies in Q15 (0..2^15-1) [d] */ opus_int32 *a_Q16, /* I/O Monic whitening filter coefficients in Q16 [d] */ const opus_int d /* I Filter order (must be even) */ -) { +) +{ opus_int i, k, m, dd, root_ix, ffrac; opus_int32 xlo, xhi, xmid; opus_int32 ylo, yhi, ymid, thr; @@ -136,21 +143,21 @@ void silk_A2NLSF( PQ[ 0 ] = P; PQ[ 1 ] = Q; - dd = silk_RSHIFT(d, 1); + dd = silk_RSHIFT( d, 1 ); - silk_A2NLSF_init(a_Q16, P, Q, dd); + silk_A2NLSF_init( a_Q16, P, Q, dd ); /* Find roots, alternating between P and Q */ p = P; /* Pointer to polynomial */ xlo = silk_LSFCosTab_FIX_Q12[ 0 ]; /* Q12*/ - ylo = silk_A2NLSF_eval_poly(p, xlo, dd); + ylo = silk_A2NLSF_eval_poly( p, xlo, dd ); - if (ylo < 0) { + if( ylo < 0 ) { /* Set the first NLSF to zero and move on to the next */ NLSF[ 0 ] = 0; p = Q; /* Pointer to polynomial */ - ylo = silk_A2NLSF_eval_poly(p, xlo, dd); + ylo = silk_A2NLSF_eval_poly( p, xlo, dd ); root_ix = 1; /* Index of current root */ } else { root_ix = 0; /* Index of current root */ @@ -158,14 +165,14 @@ void silk_A2NLSF( k = 1; /* Loop counter */ i = 0; /* Counter for bandwidth expansions applied */ thr = 0; - while (1) { + while( 1 ) { /* Evaluate polynomial */ xhi = silk_LSFCosTab_FIX_Q12[ k ]; /* Q12 */ - yhi = silk_A2NLSF_eval_poly(p, xhi, dd); + yhi = silk_A2NLSF_eval_poly( p, xhi, dd ); /* Detect zero crossing */ - if ((ylo <= 0 && yhi >= thr) || (ylo >= 0 && yhi <= -thr)) { - if (yhi == 0) { + if( ( ylo <= 0 && yhi >= thr ) || ( ylo >= 0 && yhi <= -thr ) ) { + if( yhi == 0 ) { /* If the root lies exactly at the end of the current */ /* interval, look for the next root in the next interval */ thr = 1; @@ -174,13 +181,13 @@ void silk_A2NLSF( } /* Binary division */ ffrac = -256; - for (m = 0; m < BIN_DIV_STEPS_A2NLSF_FIX; m++) { + for( m = 0; m < BIN_DIV_STEPS_A2NLSF_FIX; m++ ) { /* Evaluate polynomial */ - xmid = silk_RSHIFT_ROUND(xlo + xhi, 1); - ymid = silk_A2NLSF_eval_poly(p, xmid, dd); + xmid = silk_RSHIFT_ROUND( xlo + xhi, 1 ); + ymid = silk_A2NLSF_eval_poly( p, xmid, dd ); /* Detect zero crossing */ - if ((ylo <= 0 && ymid >= 0) || (ylo >= 0 && ymid <= 0)) { + if( ( ylo <= 0 && ymid >= 0 ) || ( ylo >= 0 && ymid <= 0 ) ) { /* Reduce frequency */ xhi = xmid; yhi = ymid; @@ -188,28 +195,28 @@ void silk_A2NLSF( /* Increase frequency */ xlo = xmid; ylo = ymid; - ffrac = silk_ADD_RSHIFT(ffrac, 128, m); + ffrac = silk_ADD_RSHIFT( ffrac, 128, m ); } } /* Interpolate */ - if (silk_abs(ylo) < 65536) { + if( silk_abs( ylo ) < 65536 ) { /* Avoid dividing by zero */ den = ylo - yhi; - nom = silk_LSHIFT(ylo, 8 - BIN_DIV_STEPS_A2NLSF_FIX) + silk_RSHIFT(den, 1); - if (den != 0) { - ffrac += silk_DIV32(nom, den); + nom = silk_LSHIFT( ylo, 8 - BIN_DIV_STEPS_A2NLSF_FIX ) + silk_RSHIFT( den, 1 ); + if( den != 0 ) { + ffrac += silk_DIV32( nom, den ); } } else { /* No risk of dividing by zero because abs(ylo - yhi) >= abs(ylo) >= 65536 */ - ffrac += silk_DIV32(ylo, silk_RSHIFT(ylo - yhi, 8 - BIN_DIV_STEPS_A2NLSF_FIX)); + ffrac += silk_DIV32( ylo, silk_RSHIFT( ylo - yhi, 8 - BIN_DIV_STEPS_A2NLSF_FIX ) ); } - NLSF[ root_ix ] = (opus_int16)silk_min_32(silk_LSHIFT((opus_int32)k, 8) + ffrac, silk_int16_MAX); + NLSF[ root_ix ] = (opus_int16)silk_min_32( silk_LSHIFT( (opus_int32)k, 8 ) + ffrac, silk_int16_MAX ); - silk_assert(NLSF[ root_ix ] >= 0); + silk_assert( NLSF[ root_ix ] >= 0 ); root_ix++; /* Next root */ - if (root_ix >= d) { + if( root_ix >= d ) { /* Found all roots */ break; } @@ -218,7 +225,7 @@ void silk_A2NLSF( /* Evaluate polynomial */ xlo = silk_LSFCosTab_FIX_Q12[ k - 1 ]; /* Q12*/ - ylo = silk_LSHIFT(1 - (root_ix & 2), 12); + ylo = silk_LSHIFT( 1 - ( root_ix & 2 ), 12 ); } else { /* Increment loop counter */ k++; @@ -226,29 +233,29 @@ void silk_A2NLSF( ylo = yhi; thr = 0; - if (k > LSF_COS_TAB_SZ_FIX) { + if( k > LSF_COS_TAB_SZ_FIX ) { i++; - if (i > MAX_ITERATIONS_A2NLSF_FIX) { + if( i > MAX_ITERATIONS_A2NLSF_FIX ) { /* Set NLSFs to white spectrum and exit */ - NLSF[ 0 ] = (opus_int16)silk_DIV32_16(1 << 15, d + 1); - for (k = 1; k < d; k++) { - NLSF[ k ] = (opus_int16)silk_ADD16(NLSF[ k - 1 ], NLSF[ 0 ]); + NLSF[ 0 ] = (opus_int16)silk_DIV32_16( 1 << 15, d + 1 ); + for( k = 1; k < d; k++ ) { + NLSF[ k ] = (opus_int16)silk_ADD16( NLSF[ k-1 ], NLSF[ 0 ] ); } return; } /* Error: Apply progressively more bandwidth expansion and run again */ - silk_bwexpander_32(a_Q16, d, 65536 - silk_LSHIFT(1, i)); + silk_bwexpander_32( a_Q16, d, 65536 - silk_LSHIFT( 1, i ) ); - silk_A2NLSF_init(a_Q16, P, Q, dd); + silk_A2NLSF_init( a_Q16, P, Q, dd ); p = P; /* Pointer to polynomial */ xlo = silk_LSFCosTab_FIX_Q12[ 0 ]; /* Q12*/ - ylo = silk_A2NLSF_eval_poly(p, xlo, dd); - if (ylo < 0) { + ylo = silk_A2NLSF_eval_poly( p, xlo, dd ); + if( ylo < 0 ) { /* Set the first NLSF to zero and move on to the next */ NLSF[ 0 ] = 0; p = Q; /* Pointer to polynomial */ - ylo = silk_A2NLSF_eval_poly(p, xlo, dd); + ylo = silk_A2NLSF_eval_poly( p, xlo, dd ); root_ix = 1; /* Index of current root */ } else { root_ix = 0; /* Index of current root */ diff --git a/src/libopus/silk/API.h b/src/libopus/silk/API.h index 6f48097..878965c 100644 --- a/src/libopus/silk/API.h +++ b/src/libopus/silk/API.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_API_H @@ -31,8 +31,12 @@ #include "control.h" #include "typedef.h" #include "errors.h" -#include "../celt/entenc.h" -#include "../celt/entdec.h" +#include "entenc.h" +#include "entdec.h" + +#ifdef ENABLE_DEEP_PLC +#include "lpcnet_private.h" +#endif #ifdef __cplusplus extern "C" @@ -88,6 +92,16 @@ opus_int silk_Encode( /* O Returns error co /* Decoder functions */ /****************************************/ + +/***********************************************/ +/* Load OSCE models from external data pointer */ +/***********************************************/ +opus_int silk_LoadOSCEModels( + void *decState, /* O I/O State */ + const unsigned char *data, /* I pointer to binary blob */ + int len /* I length of binary blob data */ +); + /***********************************************/ /* Get size in bytes of the Silk decoder state */ /***********************************************/ @@ -96,8 +110,12 @@ opus_int silk_Get_Decoder_Size( /* O Returns error co ); /*************************/ -/* Init or Reset decoder */ +/* Init and Reset decoder */ /*************************/ +opus_int silk_ResetDecoder( /* O Returns error code */ + void *decState /* I/O State */ +); + opus_int silk_InitDecoder( /* O Returns error code */ void *decState /* I/O State */ ); @@ -113,6 +131,9 @@ opus_int silk_Decode( /* O Returns error co ec_dec *psRangeDec, /* I/O Compressor data structure */ opus_int16 *samplesOut, /* O Decoded output speech vector */ opus_int32 *nSamplesOut, /* O Number of samples decoded */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif int arch /* I Run-time architecture */ ); diff --git a/src/libopus/silk/CNG.c b/src/libopus/silk/CNG.c index 6a101fb..d23f322 100644 --- a/src/libopus/silk/CNG.c +++ b/src/libopus/silk/CNG.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" /* Generates excitation for CNG LPC synthesis */ static OPUS_INLINE void silk_CNG_exc( @@ -38,21 +38,22 @@ static OPUS_INLINE void silk_CNG_exc( opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */ opus_int length, /* I Length */ opus_int32 *rand_seed /* I/O Seed to random index generator */ -) { +) +{ opus_int32 seed; opus_int i, idx, exc_mask; exc_mask = CNG_BUF_MASK_MAX; - while (exc_mask > length) { - exc_mask = silk_RSHIFT(exc_mask, 1); + while( exc_mask > length ) { + exc_mask = silk_RSHIFT( exc_mask, 1 ); } seed = *rand_seed; - for (i = 0; i < length; i++) { - seed = silk_RAND(seed); - idx = (opus_int)(silk_RSHIFT(seed, 24) & exc_mask); - silk_assert(idx >= 0); - silk_assert(idx <= CNG_BUF_MASK_MAX); + for( i = 0; i < length; i++ ) { + seed = silk_RAND( seed ); + idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask ); + silk_assert( idx >= 0 ); + silk_assert( idx <= CNG_BUF_MASK_MAX ); exc_Q14[ i ] = exc_buf_Q14[ idx ]; } *rand_seed = seed; @@ -60,12 +61,13 @@ static OPUS_INLINE void silk_CNG_exc( void silk_CNG_Reset( silk_decoder_state *psDec /* I/O Decoder state */ -) { +) +{ opus_int i, NLSF_step_Q15, NLSF_acc_Q15; - NLSF_step_Q15 = silk_DIV32_16(silk_int16_MAX, psDec->LPC_order + 1); + NLSF_step_Q15 = silk_DIV32_16( silk_int16_MAX, psDec->LPC_order + 1 ); NLSF_acc_Q15 = 0; - for (i = 0; i < psDec->LPC_order; i++) { + for( i = 0; i < psDec->LPC_order; i++ ) { NLSF_acc_Q15 += NLSF_step_Q15; psDec->sCNG.CNG_smth_NLSF_Q15[ i ] = NLSF_acc_Q15; } @@ -79,103 +81,108 @@ void silk_CNG( silk_decoder_control *psDecCtrl, /* I/O Decoder control */ opus_int16 frame[], /* I/O Signal */ opus_int length /* I Length of residual */ -) { +) +{ opus_int i, subfr; opus_int32 LPC_pred_Q10, max_Gain_Q16, gain_Q16, gain_Q10; opus_int16 A_Q12[ MAX_LPC_ORDER ]; silk_CNG_struct *psCNG = &psDec->sCNG; SAVE_STACK; - if (psDec->fs_kHz != psCNG->fs_kHz) { + if( psDec->fs_kHz != psCNG->fs_kHz ) { /* Reset state */ - silk_CNG_Reset(psDec); + silk_CNG_Reset( psDec ); psCNG->fs_kHz = psDec->fs_kHz; } - if (psDec->lossCnt == 0 && psDec->prevSignalType == TYPE_NO_VOICE_ACTIVITY) { + if( psDec->lossCnt == 0 && psDec->prevSignalType == TYPE_NO_VOICE_ACTIVITY ) { /* Update CNG parameters */ /* Smoothing of LSF's */ - for (i = 0; i < psDec->LPC_order; i++) { - psCNG->CNG_smth_NLSF_Q15[ i ] += silk_SMULWB((opus_int32)psDec->prevNLSF_Q15[ i ] - (opus_int32)psCNG->CNG_smth_NLSF_Q15[ i ], CNG_NLSF_SMTH_Q16); + for( i = 0; i < psDec->LPC_order; i++ ) { + psCNG->CNG_smth_NLSF_Q15[ i ] += silk_SMULWB( (opus_int32)psDec->prevNLSF_Q15[ i ] - (opus_int32)psCNG->CNG_smth_NLSF_Q15[ i ], CNG_NLSF_SMTH_Q16 ); } /* Find the subframe with the highest gain */ max_Gain_Q16 = 0; subfr = 0; - for (i = 0; i < psDec->nb_subfr; i++) { - if (psDecCtrl->Gains_Q16[ i ] > max_Gain_Q16) { + for( i = 0; i < psDec->nb_subfr; i++ ) { + if( psDecCtrl->Gains_Q16[ i ] > max_Gain_Q16 ) { max_Gain_Q16 = psDecCtrl->Gains_Q16[ i ]; subfr = i; } } /* Update CNG excitation buffer with excitation from this subframe */ - silk_memmove(&psCNG->CNG_exc_buf_Q14[ psDec->subfr_length ], psCNG->CNG_exc_buf_Q14, (psDec->nb_subfr - 1) * psDec->subfr_length * sizeof(opus_int32)); - silk_memcpy(psCNG->CNG_exc_buf_Q14, &psDec->exc_Q14[ subfr * psDec->subfr_length ], psDec->subfr_length * sizeof(opus_int32)); + silk_memmove( &psCNG->CNG_exc_buf_Q14[ psDec->subfr_length ], psCNG->CNG_exc_buf_Q14, ( psDec->nb_subfr - 1 ) * psDec->subfr_length * sizeof( opus_int32 ) ); + silk_memcpy( psCNG->CNG_exc_buf_Q14, &psDec->exc_Q14[ subfr * psDec->subfr_length ], psDec->subfr_length * sizeof( opus_int32 ) ); /* Smooth gains */ - for (i = 0; i < psDec->nb_subfr; i++) { - psCNG->CNG_smth_Gain_Q16 += silk_SMULWB(psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16); + for( i = 0; i < psDec->nb_subfr; i++ ) { + psCNG->CNG_smth_Gain_Q16 += silk_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 ); + /* If the smoothed gain is 3 dB greater than this subframe's gain, use this subframe's gain to adapt faster. */ + if( silk_SMULWW( psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_THRESHOLD_Q16 ) > psDecCtrl->Gains_Q16[ i ] ) { + psCNG->CNG_smth_Gain_Q16 = psDecCtrl->Gains_Q16[ i ]; + } } } /* Add CNG when packet is lost or during DTX */ - if (psDec->lossCnt) { - VARDECL(opus_int32, CNG_sig_Q14); - ALLOC(CNG_sig_Q14, length + MAX_LPC_ORDER, opus_int32); + if( psDec->lossCnt ) { + VARDECL( opus_int32, CNG_sig_Q14 ); + ALLOC( CNG_sig_Q14, length + MAX_LPC_ORDER, opus_int32 ); /* Generate CNG excitation */ - gain_Q16 = silk_SMULWW(psDec->sPLC.randScale_Q14, psDec->sPLC.prevGain_Q16[1]); - if (gain_Q16 >= (1 << 21) || psCNG->CNG_smth_Gain_Q16 > (1 << 23)) { - gain_Q16 = silk_SMULTT(gain_Q16, gain_Q16); - gain_Q16 = silk_SUB_LSHIFT32(silk_SMULTT(psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16), gain_Q16, 5); - gain_Q16 = silk_LSHIFT32(silk_SQRT_APPROX(gain_Q16), 16); + gain_Q16 = silk_SMULWW( psDec->sPLC.randScale_Q14, psDec->sPLC.prevGain_Q16[1] ); + if( gain_Q16 >= (1 << 21) || psCNG->CNG_smth_Gain_Q16 > (1 << 23) ) { + gain_Q16 = silk_SMULTT( gain_Q16, gain_Q16 ); + gain_Q16 = silk_SUB_LSHIFT32(silk_SMULTT( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 ); + gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 16 ); } else { - gain_Q16 = silk_SMULWW(gain_Q16, gain_Q16); - gain_Q16 = silk_SUB_LSHIFT32(silk_SMULWW(psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16), gain_Q16, 5); - gain_Q16 = silk_LSHIFT32(silk_SQRT_APPROX(gain_Q16), 8); + gain_Q16 = silk_SMULWW( gain_Q16, gain_Q16 ); + gain_Q16 = silk_SUB_LSHIFT32(silk_SMULWW( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 ); + gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 8 ); } - gain_Q10 = silk_RSHIFT(gain_Q16, 6); + gain_Q10 = silk_RSHIFT( gain_Q16, 6 ); - silk_CNG_exc(CNG_sig_Q14 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, length, &psCNG->rand_seed); + silk_CNG_exc( CNG_sig_Q14 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, length, &psCNG->rand_seed ); /* Convert CNG NLSF to filter representation */ - silk_NLSF2A(A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order, psDec->arch); + silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order, psDec->arch ); /* Generate CNG signal, by synthesis filtering */ - silk_memcpy(CNG_sig_Q14, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof(opus_int32)); - celt_assert(psDec->LPC_order == 10 || psDec->LPC_order == 16); - for (i = 0; i < length; i++) { + silk_memcpy( CNG_sig_Q14, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof( opus_int32 ) ); + celt_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 ); + for( i = 0; i < length; i++ ) { /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ - LPC_pred_Q10 = silk_RSHIFT(psDec->LPC_order, 1); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ]); - if (psDec->LPC_order == 16) { - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 11 ], A_Q12[ 10 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 12 ], A_Q12[ 11 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 13 ], A_Q12[ 12 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 14 ], A_Q12[ 13 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 15 ], A_Q12[ 14 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 16 ], A_Q12[ 15 ]); + LPC_pred_Q10 = silk_RSHIFT( psDec->LPC_order, 1 ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ] ); + if( psDec->LPC_order == 16 ) { + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 11 ], A_Q12[ 10 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 12 ], A_Q12[ 11 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 13 ], A_Q12[ 12 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 14 ], A_Q12[ 13 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 15 ], A_Q12[ 14 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 16 ], A_Q12[ 15 ] ); } /* Update states */ - CNG_sig_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32(CNG_sig_Q14[ MAX_LPC_ORDER + i ], silk_LSHIFT_SAT32(LPC_pred_Q10, 4)); + CNG_sig_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( CNG_sig_Q14[ MAX_LPC_ORDER + i ], silk_LSHIFT_SAT32( LPC_pred_Q10, 4 ) ); /* Scale with Gain and add to input signal */ - frame[ i ] = (opus_int16)silk_ADD_SAT16(frame[ i ], silk_SAT16(silk_RSHIFT_ROUND(silk_SMULWW(CNG_sig_Q14[ MAX_LPC_ORDER + i ], gain_Q10), 8))); + frame[ i ] = (opus_int16)silk_ADD_SAT16( frame[ i ], silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( CNG_sig_Q14[ MAX_LPC_ORDER + i ], gain_Q10 ), 8 ) ) ); } - silk_memcpy(psCNG->CNG_synth_state, &CNG_sig_Q14[ length ], MAX_LPC_ORDER * sizeof(opus_int32)); + silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q14[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) ); } else { - silk_memset(psCNG->CNG_synth_state, 0, psDec->LPC_order * sizeof(opus_int32)); + silk_memset( psCNG->CNG_synth_state, 0, psDec->LPC_order * sizeof( opus_int32 ) ); } RESTORE_STACK; } diff --git a/src/libopus/silk/HP_variable_cutoff.c b/src/libopus/silk/HP_variable_cutoff.c index 58a2a2b..31352e6 100644 --- a/src/libopus/silk/HP_variable_cutoff.c +++ b/src/libopus/silk/HP_variable_cutoff.c @@ -1,35 +1,35 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #ifdef FIXED_POINT -#include "fixed/main_FIX.h" +#include "main_FIX.h" #else #include "main_FLP.h" #endif @@ -38,39 +38,40 @@ /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */ void silk_HP_variable_cutoff( silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */ -) { - opus_int quality_Q15; - opus_int32 pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7; - silk_encoder_state *psEncC1 = &state_Fxx[ 0 ].sCmn; +) +{ + opus_int quality_Q15; + opus_int32 pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7; + silk_encoder_state *psEncC1 = &state_Fxx[ 0 ].sCmn; - /* Adaptive cutoff frequency: estimate low end of pitch frequency range */ - if (psEncC1->prevSignalType == TYPE_VOICED) { - /* difference, in log domain */ - pitch_freq_Hz_Q16 = silk_DIV32_16(silk_LSHIFT(silk_MUL(psEncC1->fs_kHz, 1000), 16), psEncC1->prevLag); - pitch_freq_log_Q7 = silk_lin2log(pitch_freq_Hz_Q16) - (16 << 7); + /* Adaptive cutoff frequency: estimate low end of pitch frequency range */ + if( psEncC1->prevSignalType == TYPE_VOICED ) { + /* difference, in log domain */ + pitch_freq_Hz_Q16 = silk_DIV32_16( silk_LSHIFT( silk_MUL( psEncC1->fs_kHz, 1000 ), 16 ), psEncC1->prevLag ); + pitch_freq_log_Q7 = silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 ); - /* adjustment based on quality */ - quality_Q15 = psEncC1->input_quality_bands_Q15[ 0 ]; - pitch_freq_log_Q7 = silk_SMLAWB(pitch_freq_log_Q7, silk_SMULWB(silk_LSHIFT(-quality_Q15, 2), quality_Q15), - pitch_freq_log_Q7 - (silk_lin2log(SILK_FIX_CONST(VARIABLE_HP_MIN_CUTOFF_HZ, 16)) - (16 << 7))); + /* adjustment based on quality */ + quality_Q15 = psEncC1->input_quality_bands_Q15[ 0 ]; + pitch_freq_log_Q7 = silk_SMLAWB( pitch_freq_log_Q7, silk_SMULWB( silk_LSHIFT( -quality_Q15, 2 ), quality_Q15 ), + pitch_freq_log_Q7 - ( silk_lin2log( SILK_FIX_CONST( VARIABLE_HP_MIN_CUTOFF_HZ, 16 ) ) - ( 16 << 7 ) ) ); - /* delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; */ - delta_freq_Q7 = pitch_freq_log_Q7 - silk_RSHIFT(psEncC1->variable_HP_smth1_Q15, 8); - if (delta_freq_Q7 < 0) { - /* less smoothing for decreasing pitch frequency, to track something close to the minimum */ - delta_freq_Q7 = silk_MUL(delta_freq_Q7, 3); - } + /* delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; */ + delta_freq_Q7 = pitch_freq_log_Q7 - silk_RSHIFT( psEncC1->variable_HP_smth1_Q15, 8 ); + if( delta_freq_Q7 < 0 ) { + /* less smoothing for decreasing pitch frequency, to track something close to the minimum */ + delta_freq_Q7 = silk_MUL( delta_freq_Q7, 3 ); + } - /* limit delta, to reduce impact of outliers in pitch estimation */ - delta_freq_Q7 = silk_LIMIT_32(delta_freq_Q7, -SILK_FIX_CONST(VARIABLE_HP_MAX_DELTA_FREQ, 7), SILK_FIX_CONST(VARIABLE_HP_MAX_DELTA_FREQ, 7)); + /* limit delta, to reduce impact of outliers in pitch estimation */ + delta_freq_Q7 = silk_LIMIT_32( delta_freq_Q7, -SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) ); - /* update smoother */ - psEncC1->variable_HP_smth1_Q15 = silk_SMLAWB(psEncC1->variable_HP_smth1_Q15, - silk_SMULBB(psEncC1->speech_activity_Q8, delta_freq_Q7), SILK_FIX_CONST(VARIABLE_HP_SMTH_COEF1, 16)); + /* update smoother */ + psEncC1->variable_HP_smth1_Q15 = silk_SMLAWB( psEncC1->variable_HP_smth1_Q15, + silk_SMULBB( psEncC1->speech_activity_Q8, delta_freq_Q7 ), SILK_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) ); - /* limit frequency range */ - psEncC1->variable_HP_smth1_Q15 = silk_LIMIT_32(psEncC1->variable_HP_smth1_Q15, - silk_LSHIFT(silk_lin2log(VARIABLE_HP_MIN_CUTOFF_HZ), 8), - silk_LSHIFT(silk_lin2log(VARIABLE_HP_MAX_CUTOFF_HZ), 8)); - } + /* limit frequency range */ + psEncC1->variable_HP_smth1_Q15 = silk_LIMIT_32( psEncC1->variable_HP_smth1_Q15, + silk_LSHIFT( silk_lin2log( VARIABLE_HP_MIN_CUTOFF_HZ ), 8 ), + silk_LSHIFT( silk_lin2log( VARIABLE_HP_MAX_CUTOFF_HZ ), 8 ) ); + } } diff --git a/src/libopus/silk/Inlines.h b/src/libopus/silk/Inlines.h index 6abba13..ec986cd 100644 --- a/src/libopus/silk/Inlines.h +++ b/src/libopus/silk/Inlines.h @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /*! \file silk_Inlines.h - \brief silk_Inlines.h defines OPUS_INLINE signal processing functions. -*/ + * \brief silk_Inlines.h defines OPUS_INLINE signal processing functions. + */ #ifndef SILK_FIX_INLINES_H #define SILK_FIX_INLINES_H @@ -38,16 +38,17 @@ extern "C" #endif /* count leading zeros of opus_int64 */ -static OPUS_INLINE opus_int32 silk_CLZ64(opus_int64 in) { +static OPUS_INLINE opus_int32 silk_CLZ64( opus_int64 in ) +{ opus_int32 in_upper; in_upper = (opus_int32)silk_RSHIFT64(in, 32); if (in_upper == 0) { /* Search in the lower 32 bits */ - return 32 + silk_CLZ32((opus_int32) in); + return 32 + silk_CLZ32( (opus_int32) in ); } else { /* Search in the upper 32 bits */ - return silk_CLZ32(in_upper); + return silk_CLZ32( in_upper ); } } @@ -56,7 +57,8 @@ static OPUS_INLINE void silk_CLZ_FRAC( opus_int32 in, /* I input */ opus_int32 *lz, /* O number of leading zeros */ opus_int32 *frac_Q7 /* O the 7 bits right after the leading one */ -) { +) +{ opus_int32 lzeros = silk_CLZ32(in); * lz = lzeros; @@ -66,16 +68,17 @@ static OPUS_INLINE void silk_CLZ_FRAC( /* Approximation of square root */ /* Accuracy: < +/- 10% for output values > 15 */ /* < +/- 2.5% for output values > 120 */ -static OPUS_INLINE opus_int32 silk_SQRT_APPROX(opus_int32 x) { +static OPUS_INLINE opus_int32 silk_SQRT_APPROX( opus_int32 x ) +{ opus_int32 y, lz, frac_Q7; - if (x <= 0) { + if( x <= 0 ) { return 0; } silk_CLZ_FRAC(x, &lz, &frac_Q7); - if (lz & 1) { + if( lz & 1 ) { y = 32768; } else { y = 46214; /* 46214 = sqrt(2) * 32768 */ @@ -95,38 +98,39 @@ static OPUS_INLINE opus_int32 silk_DIV32_varQ( /* O returns a good approxim const opus_int32 a32, /* I numerator (Q0) */ const opus_int32 b32, /* I denominator (Q0) */ const opus_int Qres /* I Q-domain of result (>= 0) */ -) { +) +{ opus_int a_headrm, b_headrm, lshift; opus_int32 b32_inv, a32_nrm, b32_nrm, result; - silk_assert(b32 != 0); - silk_assert(Qres >= 0); + silk_assert( b32 != 0 ); + silk_assert( Qres >= 0 ); /* Compute number of bits head room and normalize inputs */ - a_headrm = silk_CLZ32(silk_abs(a32)) - 1; + a_headrm = silk_CLZ32( silk_abs(a32) ) - 1; a32_nrm = silk_LSHIFT(a32, a_headrm); /* Q: a_headrm */ - b_headrm = silk_CLZ32(silk_abs(b32)) - 1; + b_headrm = silk_CLZ32( silk_abs(b32) ) - 1; b32_nrm = silk_LSHIFT(b32, b_headrm); /* Q: b_headrm */ /* Inverse of b32, with 14 bits of precision */ - b32_inv = silk_DIV32_16(silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16)); /* Q: 29 + 16 - b_headrm */ + b32_inv = silk_DIV32_16( silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16) ); /* Q: 29 + 16 - b_headrm */ /* First approximation */ result = silk_SMULWB(a32_nrm, b32_inv); /* Q: 29 + a_headrm - b_headrm */ /* Compute residual by subtracting product of denominator and first approximation */ /* It's OK to overflow because the final value of a32_nrm should always be small */ - a32_nrm = silk_SUB32_ovflw(a32_nrm, silk_LSHIFT_ovflw(silk_SMMUL(b32_nrm, result), 3)); /* Q: a_headrm */ + a32_nrm = silk_SUB32_ovflw(a32_nrm, silk_LSHIFT_ovflw( silk_SMMUL(b32_nrm, result), 3 )); /* Q: a_headrm */ /* Refinement */ result = silk_SMLAWB(result, a32_nrm, b32_inv); /* Q: 29 + a_headrm - b_headrm */ /* Convert to Qres domain */ lshift = 29 + a_headrm - b_headrm - Qres; - if (lshift < 0) { + if( lshift < 0 ) { return silk_LSHIFT_SAT32(result, -lshift); } else { - if (lshift < 32) { + if( lshift < 32){ return silk_RSHIFT(result, lshift); } else { /* Avoid undefined result */ @@ -139,37 +143,38 @@ static OPUS_INLINE opus_int32 silk_DIV32_varQ( /* O returns a good approxim static OPUS_INLINE opus_int32 silk_INVERSE32_varQ( /* O returns a good approximation of "(1 << Qres) / b32" */ const opus_int32 b32, /* I denominator (Q0) */ const opus_int Qres /* I Q-domain of result (> 0) */ -) { +) +{ opus_int b_headrm, lshift; opus_int32 b32_inv, b32_nrm, err_Q32, result; - silk_assert(b32 != 0); - silk_assert(Qres > 0); + silk_assert( b32 != 0 ); + silk_assert( Qres > 0 ); /* Compute number of bits head room and normalize input */ - b_headrm = silk_CLZ32(silk_abs(b32)) - 1; + b_headrm = silk_CLZ32( silk_abs(b32) ) - 1; b32_nrm = silk_LSHIFT(b32, b_headrm); /* Q: b_headrm */ /* Inverse of b32, with 14 bits of precision */ - b32_inv = silk_DIV32_16(silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16)); /* Q: 29 + 16 - b_headrm */ + b32_inv = silk_DIV32_16( silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16) ); /* Q: 29 + 16 - b_headrm */ /* First approximation */ result = silk_LSHIFT(b32_inv, 16); /* Q: 61 - b_headrm */ /* Compute residual by subtracting product of denominator and first approximation from one */ - err_Q32 = silk_LSHIFT(((opus_int32)1 << 29) - silk_SMULWB(b32_nrm, b32_inv), 3); /* Q32 */ + err_Q32 = silk_LSHIFT( ((opus_int32)1<<29) - silk_SMULWB(b32_nrm, b32_inv), 3 ); /* Q32 */ /* Refinement */ result = silk_SMLAWW(result, err_Q32, b32_inv); /* Q: 61 - b_headrm */ /* Convert to Qres domain */ lshift = 61 - b_headrm - Qres; - if (lshift <= 0) { + if( lshift <= 0 ) { return silk_LSHIFT_SAT32(result, -lshift); } else { - if (lshift < 32) { + if( lshift < 32){ return silk_RSHIFT(result, lshift); - } else { + }else{ /* Avoid undefined result */ return 0; } diff --git a/src/libopus/silk/LPC_analysis_filter.c b/src/libopus/silk/LPC_analysis_filter.c index 0c9da4b..494c93c 100644 --- a/src/libopus/silk/LPC_analysis_filter.c +++ b/src/libopus/silk/LPC_analysis_filter.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" -#include "../celt/celt_lpc.h" +#include "celt_lpc.h" /*******************************************/ /* LPC analysis filter */ @@ -39,11 +39,11 @@ /* first d output samples are set to zero */ /*******************************************/ -/* OPT: Using celt_fir() for this function should be faster, but it may cause - integer overflows in intermediate values (not final results), which the - current implementation silences by casting to unsigned. Enabling - this should be safe in pretty much all cases, even though it is not technically - C89-compliant. */ +/* OPT: Using celt_fir() for this function should be faster, but it may cause + integer overflows in intermediate values (not final results), which the + current implementation silences by casting to unsigned. Enabling + this should be safe in pretty much all cases, even though it is not technically + C89-compliant. */ #define USE_CELT_FIR 0 void silk_LPC_analysis_filter( @@ -53,7 +53,8 @@ void silk_LPC_analysis_filter( const opus_int32 len, /* I Signal length */ const opus_int32 d, /* I Filter order */ int arch /* I Run-time architecture */ -) { +) +{ opus_int j; #if defined(FIXED_POINT) && USE_CELT_FIR opus_int16 num[SILK_MAX_ORDER_LPC]; @@ -63,48 +64,48 @@ void silk_LPC_analysis_filter( const opus_int16 *in_ptr; #endif - celt_assert(d >= 6); - celt_assert((d & 1) == 0); - celt_assert(d <= len); + celt_assert( d >= 6 ); + celt_assert( (d & 1) == 0 ); + celt_assert( d <= len ); #if defined(FIXED_POINT) && USE_CELT_FIR - celt_assert(d <= SILK_MAX_ORDER_LPC); - for (j = 0; j < d; j++) { + celt_assert( d <= SILK_MAX_ORDER_LPC ); + for ( j = 0; j < d; j++ ) { num[ j ] = -B[ j ]; } - celt_fir(in + d, num, out + d, len - d, d, arch); - for (j = 0; j < d; j++) { + celt_fir( in + d, num, out + d, len - d, d, arch ); + for ( j = 0; j < d; j++ ) { out[ j ] = 0; } #else (void)arch; - for (ix = d; ix < len; ix++) { + for( ix = d; ix < len; ix++ ) { in_ptr = &in[ ix - 1 ]; - out32_Q12 = silk_SMULBB(in_ptr[ 0 ], B[ 0 ]); - /* Allowing wrap around so that two wraps can cancel each other. The rare - cases where the result wraps around can only be triggered by invalid streams*/ - out32_Q12 = silk_SMLABB_ovflw(out32_Q12, in_ptr[ -1 ], B[ 1 ]); - out32_Q12 = silk_SMLABB_ovflw(out32_Q12, in_ptr[ -2 ], B[ 2 ]); - out32_Q12 = silk_SMLABB_ovflw(out32_Q12, in_ptr[ -3 ], B[ 3 ]); - out32_Q12 = silk_SMLABB_ovflw(out32_Q12, in_ptr[ -4 ], B[ 4 ]); - out32_Q12 = silk_SMLABB_ovflw(out32_Q12, in_ptr[ -5 ], B[ 5 ]); - for (j = 6; j < d; j += 2) { - out32_Q12 = silk_SMLABB_ovflw(out32_Q12, in_ptr[ -j ], B[ j ]); - out32_Q12 = silk_SMLABB_ovflw(out32_Q12, in_ptr[ -j - 1 ], B[ j + 1 ]); + out32_Q12 = silk_SMULBB( in_ptr[ 0 ], B[ 0 ] ); + /* Allowing wrap around so that two wraps can cancel each other. The rare + cases where the result wraps around can only be triggered by invalid streams*/ + out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -1 ], B[ 1 ] ); + out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -2 ], B[ 2 ] ); + out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -3 ], B[ 3 ] ); + out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -4 ], B[ 4 ] ); + out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -5 ], B[ 5 ] ); + for( j = 6; j < d; j += 2 ) { + out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -j ], B[ j ] ); + out32_Q12 = silk_SMLABB_ovflw( out32_Q12, in_ptr[ -j - 1 ], B[ j + 1 ] ); } /* Subtract prediction */ - out32_Q12 = silk_SUB32_ovflw(silk_LSHIFT((opus_int32)in_ptr[ 1 ], 12), out32_Q12); + out32_Q12 = silk_SUB32_ovflw( silk_LSHIFT( (opus_int32)in_ptr[ 1 ], 12 ), out32_Q12 ); /* Scale to Q0 */ - out32 = silk_RSHIFT_ROUND(out32_Q12, 12); + out32 = silk_RSHIFT_ROUND( out32_Q12, 12 ); /* Saturate output */ - out[ ix ] = (opus_int16)silk_SAT16(out32); + out[ ix ] = (opus_int16)silk_SAT16( out32 ); } /* Set first d output samples to zero */ - silk_memset(out, 0, d * sizeof(opus_int16)); + silk_memset( out, 0, d * sizeof( opus_int16 ) ); #endif } diff --git a/src/libopus/silk/LPC_fit.c b/src/libopus/silk/LPC_fit.c index d59aaf7..c63dbc4 100644 --- a/src/libopus/silk/LPC_fit.c +++ b/src/libopus/silk/LPC_fit.c @@ -1,80 +1,82 @@ /*********************************************************************** - Copyright (c) 2013, Koen Vos. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2013, Koen Vos. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" -/* Convert int32 coefficients to int16 coefs and make sure there's no wrap-around */ +/* Convert int32 coefficients to int16 coefs and make sure there's no wrap-around. + This logic is reused in _celt_lpc(). Any bug fixes should also be applied there. */ void silk_LPC_fit( opus_int16 *a_QOUT, /* O Output signal */ opus_int32 *a_QIN, /* I/O Input signal */ const opus_int QOUT, /* I Input Q domain */ const opus_int QIN, /* I Input Q domain */ const opus_int d /* I Filter order */ -) { +) +{ opus_int i, k, idx = 0; opus_int32 maxabs, absval, chirp_Q16; /* Limit the maximum absolute value of the prediction coefficients, so that they'll fit in int16 */ - for (i = 0; i < 10; i++) { + for( i = 0; i < 10; i++ ) { /* Find maximum absolute value and its index */ maxabs = 0; - for (k = 0; k < d; k++) { - absval = silk_abs(a_QIN[k]); - if (absval > maxabs) { + for( k = 0; k < d; k++ ) { + absval = silk_abs( a_QIN[k] ); + if( absval > maxabs ) { maxabs = absval; idx = k; } } - maxabs = silk_RSHIFT_ROUND(maxabs, QIN - QOUT); + maxabs = silk_RSHIFT_ROUND( maxabs, QIN - QOUT ); - if (maxabs > silk_int16_MAX) { + if( maxabs > silk_int16_MAX ) { /* Reduce magnitude of prediction coefficients */ - maxabs = silk_min(maxabs, 163838); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */ - chirp_Q16 = SILK_FIX_CONST(0.999, 16) - silk_DIV32(silk_LSHIFT(maxabs - silk_int16_MAX, 14), - silk_RSHIFT32(silk_MUL(maxabs, idx + 1), 2)); - silk_bwexpander_32(a_QIN, d, chirp_Q16); + maxabs = silk_min( maxabs, 163838 ); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */ + chirp_Q16 = SILK_FIX_CONST( 0.999, 16 ) - silk_DIV32( silk_LSHIFT( maxabs - silk_int16_MAX, 14 ), + silk_RSHIFT32( silk_MUL( maxabs, idx + 1), 2 ) ); + silk_bwexpander_32( a_QIN, d, chirp_Q16 ); } else { break; } } - if (i == 10) { + if( i == 10 ) { /* Reached the last iteration, clip the coefficients */ - for (k = 0; k < d; k++) { - a_QOUT[ k ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(a_QIN[ k ], QIN - QOUT)); - a_QIN[ k ] = silk_LSHIFT((opus_int32)a_QOUT[ k ], QIN - QOUT); + for( k = 0; k < d; k++ ) { + a_QOUT[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( a_QIN[ k ], QIN - QOUT ) ); + a_QIN[ k ] = silk_LSHIFT( (opus_int32)a_QOUT[ k ], QIN - QOUT ); } } else { - for (k = 0; k < d; k++) { - a_QOUT[ k ] = (opus_int16)silk_RSHIFT_ROUND(a_QIN[ k ], QIN - QOUT); + for( k = 0; k < d; k++ ) { + a_QOUT[ k ] = (opus_int16)silk_RSHIFT_ROUND( a_QIN[ k ], QIN - QOUT ); } } } diff --git a/src/libopus/silk/LPC_inv_pred_gain.c b/src/libopus/silk/LPC_inv_pred_gain.c index 58f4cac..4cc91b2 100644 --- a/src/libopus/silk/LPC_inv_pred_gain.c +++ b/src/libopus/silk/LPC_inv_pred_gain.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "define.h" @@ -42,75 +42,76 @@ static opus_int32 LPC_inverse_pred_gain_QA_c( /* O Returns inverse prediction gain in energy domain, Q30 */ opus_int32 A_QA[ SILK_MAX_ORDER_LPC ], /* I Prediction coefficients */ const opus_int order /* I Prediction order */ -) { +) +{ opus_int k, n, mult2Q; opus_int32 invGain_Q30, rc_Q31, rc_mult1_Q30, rc_mult2, tmp1, tmp2; - invGain_Q30 = SILK_FIX_CONST(1, 30); - for (k = order - 1; k > 0; k--) { + invGain_Q30 = SILK_FIX_CONST( 1, 30 ); + for( k = order - 1; k > 0; k-- ) { /* Check for stability */ - if ((A_QA[ k ] > A_LIMIT) || (A_QA[ k ] < -A_LIMIT)) { + if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) { return 0; } /* Set RC equal to negated AR coef */ - rc_Q31 = -silk_LSHIFT(A_QA[ k ], 31 - QA); + rc_Q31 = -silk_LSHIFT( A_QA[ k ], 31 - QA ); /* rc_mult1_Q30 range: [ 1 : 2^30 ] */ - rc_mult1_Q30 = silk_SUB32(SILK_FIX_CONST(1, 30), silk_SMMUL(rc_Q31, rc_Q31)); - silk_assert(rc_mult1_Q30 > (1 << 15)); /* reduce A_LIMIT if fails */ - silk_assert(rc_mult1_Q30 <= (1 << 30)); + rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) ); + silk_assert( rc_mult1_Q30 > ( 1 << 15 ) ); /* reduce A_LIMIT if fails */ + silk_assert( rc_mult1_Q30 <= ( 1 << 30 ) ); /* Update inverse gain */ /* invGain_Q30 range: [ 0 : 2^30 ] */ - invGain_Q30 = silk_LSHIFT(silk_SMMUL(invGain_Q30, rc_mult1_Q30), 2); - silk_assert(invGain_Q30 >= 0); - silk_assert(invGain_Q30 <= (1 << 30)); - if (invGain_Q30 < SILK_FIX_CONST(1.0f / MAX_PREDICTION_POWER_GAIN, 30)) { + invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 ); + silk_assert( invGain_Q30 >= 0 ); + silk_assert( invGain_Q30 <= ( 1 << 30 ) ); + if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) { return 0; } /* rc_mult2 range: [ 2^30 : silk_int32_MAX ] */ - mult2Q = 32 - silk_CLZ32(silk_abs(rc_mult1_Q30)); - rc_mult2 = silk_INVERSE32_varQ(rc_mult1_Q30, mult2Q + 30); + mult2Q = 32 - silk_CLZ32( silk_abs( rc_mult1_Q30 ) ); + rc_mult2 = silk_INVERSE32_varQ( rc_mult1_Q30, mult2Q + 30 ); /* Update AR coefficient */ - for (n = 0; n < (k + 1) >> 1; n++) { + for( n = 0; n < (k + 1) >> 1; n++ ) { opus_int64 tmp64; tmp1 = A_QA[ n ]; tmp2 = A_QA[ k - n - 1 ]; - tmp64 = silk_RSHIFT_ROUND64(silk_SMULL(silk_SUB_SAT32(tmp1, - MUL32_FRAC_Q(tmp2, rc_Q31, 31)), rc_mult2), mult2Q); - if (tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN) { - return 0; + tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp1, + MUL32_FRAC_Q( tmp2, rc_Q31, 31 ) ), rc_mult2 ), mult2Q); + if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { + return 0; } - A_QA[ n ] = (opus_int32)tmp64; - tmp64 = silk_RSHIFT_ROUND64(silk_SMULL(silk_SUB_SAT32(tmp2, - MUL32_FRAC_Q(tmp1, rc_Q31, 31)), rc_mult2), mult2Q); - if (tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN) { - return 0; + A_QA[ n ] = ( opus_int32 )tmp64; + tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp2, + MUL32_FRAC_Q( tmp1, rc_Q31, 31 ) ), rc_mult2), mult2Q); + if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { + return 0; } - A_QA[ k - n - 1 ] = (opus_int32)tmp64; + A_QA[ k - n - 1 ] = ( opus_int32 )tmp64; } } /* Check for stability */ - if ((A_QA[ k ] > A_LIMIT) || (A_QA[ k ] < -A_LIMIT)) { + if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) { return 0; } /* Set RC equal to negated AR coef */ - rc_Q31 = -silk_LSHIFT(A_QA[ 0 ], 31 - QA); + rc_Q31 = -silk_LSHIFT( A_QA[ 0 ], 31 - QA ); /* Range: [ 1 : 2^30 ] */ - rc_mult1_Q30 = silk_SUB32(SILK_FIX_CONST(1, 30), silk_SMMUL(rc_Q31, rc_Q31)); + rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) ); /* Update inverse gain */ /* Range: [ 0 : 2^30 ] */ - invGain_Q30 = silk_LSHIFT(silk_SMMUL(invGain_Q30, rc_mult1_Q30), 2); - silk_assert(invGain_Q30 >= 0); - silk_assert(invGain_Q30 <= (1 << 30)); - if (invGain_Q30 < SILK_FIX_CONST(1.0f / MAX_PREDICTION_POWER_GAIN, 30)) { + invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 ); + silk_assert( invGain_Q30 >= 0 ); + silk_assert( invGain_Q30 <= ( 1 << 30 ) ); + if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) { return 0; } @@ -121,19 +122,20 @@ static opus_int32 LPC_inverse_pred_gain_QA_c( /* O Returns inver opus_int32 silk_LPC_inverse_pred_gain_c( /* O Returns inverse prediction gain in energy domain, Q30 */ const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */ const opus_int order /* I Prediction order */ -) { +) +{ opus_int k; opus_int32 Atmp_QA[ SILK_MAX_ORDER_LPC ]; opus_int32 DC_resp = 0; /* Increase Q domain of the AR coefficients */ - for (k = 0; k < order; k++) { + for( k = 0; k < order; k++ ) { DC_resp += (opus_int32)A_Q12[ k ]; - Atmp_QA[ k ] = silk_LSHIFT32((opus_int32)A_Q12[ k ], QA - 12); + Atmp_QA[ k ] = silk_LSHIFT32( (opus_int32)A_Q12[ k ], QA - 12 ); } /* If the DC is unstable, we don't even need to do the full calculations */ - if (DC_resp >= 4096) { + if( DC_resp >= 4096 ) { return 0; } - return LPC_inverse_pred_gain_QA_c(Atmp_QA, order); + return LPC_inverse_pred_gain_QA_c( Atmp_QA, order ); } diff --git a/src/libopus/silk/LP_variable_cutoff.c b/src/libopus/silk/LP_variable_cutoff.c index aef2b0a..1f39324 100644 --- a/src/libopus/silk/LP_variable_cutoff.c +++ b/src/libopus/silk/LP_variable_cutoff.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif /* Elliptic/Cauer filters designed with 0.1 dB passband ripple, @@ -43,52 +43,53 @@ static OPUS_INLINE void silk_LP_interpolate_filter_taps( opus_int32 A_Q28[ TRANSITION_NA ], const opus_int ind, const opus_int32 fac_Q16 -) { +) +{ opus_int nb, na; - if (ind < TRANSITION_INT_NUM - 1) { - if (fac_Q16 > 0) { - if (fac_Q16 < 32768) { /* fac_Q16 is in range of a 16-bit int */ + if( ind < TRANSITION_INT_NUM - 1 ) { + if( fac_Q16 > 0 ) { + if( fac_Q16 < 32768 ) { /* fac_Q16 is in range of a 16-bit int */ /* Piece-wise linear interpolation of B and A */ - for (nb = 0; nb < TRANSITION_NB; nb++) { + for( nb = 0; nb < TRANSITION_NB; nb++ ) { B_Q28[ nb ] = silk_SMLAWB( - silk_Transition_LP_B_Q28[ ind ][ nb ], - silk_Transition_LP_B_Q28[ ind + 1 ][ nb ] - - silk_Transition_LP_B_Q28[ ind ][ nb ], - fac_Q16); + silk_Transition_LP_B_Q28[ ind ][ nb ], + silk_Transition_LP_B_Q28[ ind + 1 ][ nb ] - + silk_Transition_LP_B_Q28[ ind ][ nb ], + fac_Q16 ); } - for (na = 0; na < TRANSITION_NA; na++) { + for( na = 0; na < TRANSITION_NA; na++ ) { A_Q28[ na ] = silk_SMLAWB( - silk_Transition_LP_A_Q28[ ind ][ na ], - silk_Transition_LP_A_Q28[ ind + 1 ][ na ] - - silk_Transition_LP_A_Q28[ ind ][ na ], - fac_Q16); + silk_Transition_LP_A_Q28[ ind ][ na ], + silk_Transition_LP_A_Q28[ ind + 1 ][ na ] - + silk_Transition_LP_A_Q28[ ind ][ na ], + fac_Q16 ); } } else { /* ( fac_Q16 - ( 1 << 16 ) ) is in range of a 16-bit int */ - silk_assert(fac_Q16 - (1 << 16) == silk_SAT16(fac_Q16 - (1 << 16))); + silk_assert( fac_Q16 - ( 1 << 16 ) == silk_SAT16( fac_Q16 - ( 1 << 16 ) ) ); /* Piece-wise linear interpolation of B and A */ - for (nb = 0; nb < TRANSITION_NB; nb++) { + for( nb = 0; nb < TRANSITION_NB; nb++ ) { B_Q28[ nb ] = silk_SMLAWB( - silk_Transition_LP_B_Q28[ ind + 1 ][ nb ], - silk_Transition_LP_B_Q28[ ind + 1 ][ nb ] - - silk_Transition_LP_B_Q28[ ind ][ nb ], - fac_Q16 - ((opus_int32)1 << 16)); + silk_Transition_LP_B_Q28[ ind + 1 ][ nb ], + silk_Transition_LP_B_Q28[ ind + 1 ][ nb ] - + silk_Transition_LP_B_Q28[ ind ][ nb ], + fac_Q16 - ( (opus_int32)1 << 16 ) ); } - for (na = 0; na < TRANSITION_NA; na++) { + for( na = 0; na < TRANSITION_NA; na++ ) { A_Q28[ na ] = silk_SMLAWB( - silk_Transition_LP_A_Q28[ ind + 1 ][ na ], - silk_Transition_LP_A_Q28[ ind + 1 ][ na ] - - silk_Transition_LP_A_Q28[ ind ][ na ], - fac_Q16 - ((opus_int32)1 << 16)); + silk_Transition_LP_A_Q28[ ind + 1 ][ na ], + silk_Transition_LP_A_Q28[ ind + 1 ][ na ] - + silk_Transition_LP_A_Q28[ ind ][ na ], + fac_Q16 - ( (opus_int32)1 << 16 ) ); } } } else { - silk_memcpy(B_Q28, silk_Transition_LP_B_Q28[ ind ], TRANSITION_NB * sizeof(opus_int32)); - silk_memcpy(A_Q28, silk_Transition_LP_A_Q28[ ind ], TRANSITION_NA * sizeof(opus_int32)); + silk_memcpy( B_Q28, silk_Transition_LP_B_Q28[ ind ], TRANSITION_NB * sizeof( opus_int32 ) ); + silk_memcpy( A_Q28, silk_Transition_LP_A_Q28[ ind ], TRANSITION_NA * sizeof( opus_int32 ) ); } } else { - silk_memcpy(B_Q28, silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NB * sizeof(opus_int32)); - silk_memcpy(A_Q28, silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NA * sizeof(opus_int32)); + silk_memcpy( B_Q28, silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NB * sizeof( opus_int32 ) ); + silk_memcpy( A_Q28, silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM - 1 ], TRANSITION_NA * sizeof( opus_int32 ) ); } } @@ -100,34 +101,35 @@ void silk_LP_variable_cutoff( silk_LP_state *psLP, /* I/O LP filter state */ opus_int16 *frame, /* I/O Low-pass filtered output signal */ const opus_int frame_length /* I Frame length */ -) { +) +{ opus_int32 B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ], fac_Q16 = 0; opus_int ind = 0; - silk_assert(psLP->transition_frame_no >= 0 && psLP->transition_frame_no <= TRANSITION_FRAMES); + silk_assert( psLP->transition_frame_no >= 0 && psLP->transition_frame_no <= TRANSITION_FRAMES ); /* Run filter if needed */ - if (psLP->mode != 0) { + if( psLP->mode != 0 ) { /* Calculate index and interpolation factor for interpolation */ #if( TRANSITION_INT_STEPS == 64 ) - fac_Q16 = silk_LSHIFT(TRANSITION_FRAMES - psLP->transition_frame_no, 16 - 6); + fac_Q16 = silk_LSHIFT( TRANSITION_FRAMES - psLP->transition_frame_no, 16 - 6 ); #else - fac_Q16 = silk_DIV32_16(silk_LSHIFT(TRANSITION_FRAMES - psLP->transition_frame_no, 16), TRANSITION_FRAMES); + fac_Q16 = silk_DIV32_16( silk_LSHIFT( TRANSITION_FRAMES - psLP->transition_frame_no, 16 ), TRANSITION_FRAMES ); #endif - ind = silk_RSHIFT(fac_Q16, 16); - fac_Q16 -= silk_LSHIFT(ind, 16); + ind = silk_RSHIFT( fac_Q16, 16 ); + fac_Q16 -= silk_LSHIFT( ind, 16 ); - silk_assert(ind >= 0); - silk_assert(ind < TRANSITION_INT_NUM); + silk_assert( ind >= 0 ); + silk_assert( ind < TRANSITION_INT_NUM ); /* Interpolate filter coefficients */ - silk_LP_interpolate_filter_taps(B_Q28, A_Q28, ind, fac_Q16); + silk_LP_interpolate_filter_taps( B_Q28, A_Q28, ind, fac_Q16 ); /* Update transition frame number for next frame */ - psLP->transition_frame_no = silk_LIMIT(psLP->transition_frame_no + psLP->mode, 0, TRANSITION_FRAMES); + psLP->transition_frame_no = silk_LIMIT( psLP->transition_frame_no + psLP->mode, 0, TRANSITION_FRAMES ); /* ARMA low-pass filtering */ - silk_assert(TRANSITION_NB == 3 && TRANSITION_NA == 2); - silk_biquad_alt_stride1(frame, B_Q28, A_Q28, psLP->In_LP_State, frame, frame_length); + silk_assert( TRANSITION_NB == 3 && TRANSITION_NA == 2 ); + silk_biquad_alt_stride1( frame, B_Q28, A_Q28, psLP->In_LP_State, frame, frame_length); } } diff --git a/src/libopus/silk/MacroCount.h b/src/libopus/silk/MacroCount.h index 56070fd..dab2f57 100644 --- a/src/libopus/silk/MacroCount.h +++ b/src/libopus/silk/MacroCount.h @@ -1,57 +1,57 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SIGPROCFIX_API_MACROCOUNT_H #define SIGPROCFIX_API_MACROCOUNT_H -#include #ifdef silk_MACRO_COUNT +#include #define varDefine opus_int64 ops_count = 0; extern opus_int64 ops_count; -static OPUS_INLINE opus_int64 silk_SaveCount() { - return (ops_count); +static OPUS_INLINE opus_int64 silk_SaveCount(){ + return(ops_count); } -static OPUS_INLINE opus_int64 silk_SaveResetCount() { +static OPUS_INLINE opus_int64 silk_SaveResetCount(){ opus_int64 ret; ret = ops_count; ops_count = 0; - return (ret); + return(ret); } -static OPUS_INLINE silk_PrintCount() { +static OPUS_INLINE silk_PrintCount(){ printf("ops_count = %d \n ", (opus_int32)ops_count); } #undef silk_MUL -static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){ opus_int32 ret; ops_count += 4; ret = a32 * b32; @@ -59,14 +59,14 @@ static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32) { } #undef silk_MUL_uint -static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32) { +static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){ opus_uint32 ret; ops_count += 4; ret = a32 * b32; return ret; } #undef silk_MLA -static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){ opus_int32 ret; ops_count += 4; ret = a32 + b32 * c32; @@ -74,7 +74,7 @@ static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int3 } #undef silk_MLA_uint -static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32) { +static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){ opus_uint32 ret; ops_count += 4; ret = a32 + b32 * c32; @@ -82,14 +82,14 @@ static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, op } #undef silk_SMULWB -static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){ opus_int32 ret; ops_count += 5; ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16); return ret; } #undef silk_SMLAWB -static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){ opus_int32 ret; ops_count += 5; ret = ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16))); @@ -97,14 +97,14 @@ static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_i } #undef silk_SMULWT -static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){ opus_int32 ret; ops_count += 4; ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16); return ret; } #undef silk_SMLAWT -static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ opus_int32 ret; ops_count += 4; ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16)); @@ -112,14 +112,14 @@ static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_i } #undef silk_SMULBB -static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){ opus_int32 ret; ops_count += 1; ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32); return ret; } #undef silk_SMLABB -static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){ opus_int32 ret; ops_count += 1; ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32); @@ -127,7 +127,7 @@ static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_i } #undef silk_SMULBT -static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){ opus_int32 ret; ops_count += 4; ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16); @@ -135,7 +135,7 @@ static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32) { } #undef silk_SMLABT -static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ opus_int32 ret; ops_count += 1; ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16); @@ -143,7 +143,7 @@ static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_i } #undef silk_SMULTT -static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){ opus_int32 ret; ops_count += 1; ret = (a32 >> 16) * (b32 >> 16); @@ -151,7 +151,7 @@ static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32) { } #undef silk_SMLATT -static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ opus_int32 ret; ops_count += 1; ret = a32 + (b32 >> 16) * (c32 >> 16); @@ -179,7 +179,7 @@ static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_i #define silk_SMLAWT_ovflw silk_SMLAWT #undef silk_SMULL -static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){ opus_int64 ret; ops_count += 8; ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32)); @@ -187,14 +187,14 @@ static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32) { } #undef silk_SMLAL -static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){ opus_int64 ret; ops_count += 8; ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32)); return ret; } #undef silk_SMLALBB -static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16) { +static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){ opus_int64 ret; ops_count += 4; ret = a64 + ((opus_int64)(b16) * /*(opus_int64)*/(c16)); @@ -202,22 +202,23 @@ static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_ } #undef SigProcFIX_CLZ16 -static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16) { +static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16) +{ opus_int32 out32 = 0; ops_count += 10; - if (in16 == 0) { + if( in16 == 0 ) { return 16; } /* test nibbles */ - if (in16 & 0xFF00) { - if (in16 & 0xF000) { + if( in16 & 0xFF00 ) { + if( in16 & 0xF000 ) { in16 >>= 12; } else { out32 += 4; in16 >>= 8; } } else { - if (in16 & 0xFFF0) { + if( in16 & 0xFFF0 ) { out32 += 8; in16 >>= 4; } else { @@ -225,26 +226,25 @@ static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16) { } } /* test bits and return */ - if (in16 & 0xC) { - if (in16 & 0x8) { + if( in16 & 0xC ) { + if( in16 & 0x8 ) return out32 + 0; - } else { + else return out32 + 1; - } } else { - if (in16 & 0xE) { + if( in16 & 0xE ) return out32 + 2; - } else { + else return out32 + 3; - } } } #undef SigProcFIX_CLZ32 -static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32) { +static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32) +{ /* test highest 16 bits and convert to opus_int16 */ ops_count += 2; - if (in32 & 0xFFFF0000) { + if( in32 & 0xFFFF0000 ) { return SigProcFIX_CLZ16((opus_int16)(in32 >> 16)); } else { return SigProcFIX_CLZ16((opus_int16)in32) + 16; @@ -252,108 +252,108 @@ static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32) { } #undef silk_DIV32 -static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){ ops_count += 64; return a32 / b32; } #undef silk_DIV32_16 -static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){ ops_count += 32; return a32 / b32; } #undef silk_SAT8 -static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a) { +static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a){ opus_int8 tmp; ops_count += 1; tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX : \ - ((a) < silk_int8_MIN ? silk_int8_MIN : (a))); - return (tmp); + ((a) < silk_int8_MIN ? silk_int8_MIN : (a))); + return(tmp); } #undef silk_SAT16 -static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a) { +static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a){ opus_int16 tmp; ops_count += 1; tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX : \ - ((a) < silk_int16_MIN ? silk_int16_MIN : (a))); - return (tmp); + ((a) < silk_int16_MIN ? silk_int16_MIN : (a))); + return(tmp); } #undef silk_SAT32 -static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a) { +static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a){ opus_int32 tmp; ops_count += 1; tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : \ - ((a) < silk_int32_MIN ? silk_int32_MIN : (a))); - return (tmp); + ((a) < silk_int32_MIN ? silk_int32_MIN : (a))); + return(tmp); } #undef silk_POS_SAT32 -static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a) { +static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a){ opus_int32 tmp; ops_count += 1; tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a)); - return (tmp); + return(tmp); } #undef silk_ADD_POS_SAT8 -static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){ opus_int8 tmp; ops_count += 1; - tmp = (opus_int8)((((a) + (b)) & 0x80) ? silk_int8_MAX : ((a) + (b))); - return (tmp); + tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b))); + return(tmp); } #undef silk_ADD_POS_SAT16 -static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){ opus_int16 tmp; ops_count += 1; - tmp = (opus_int16)((((a) + (b)) & 0x8000) ? silk_int16_MAX : ((a) + (b))); - return (tmp); + tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b))); + return(tmp); } #undef silk_ADD_POS_SAT32 -static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){ opus_int32 tmp; ops_count += 1; - tmp = (opus_int32)((((a) + (b)) & 0x80000000) ? silk_int32_MAX : ((a) + (b))); - return (tmp); + tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b))); + return(tmp); } #undef silk_LSHIFT8 -static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift) { +static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){ opus_int8 ret; ops_count += 1; ret = a << shift; return ret; } #undef silk_LSHIFT16 -static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift) { +static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){ opus_int16 ret; ops_count += 1; ret = a << shift; return ret; } #undef silk_LSHIFT32 -static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){ opus_int32 ret; ops_count += 1; ret = a << shift; return ret; } #undef silk_LSHIFT64 -static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift) { +static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){ ops_count += 1; return a << shift; } #undef silk_LSHIFT_ovflw -static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){ ops_count += 1; return a << shift; } #undef silk_LSHIFT_uint -static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift) { +static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){ opus_uint32 ret; ops_count += 1; ret = a << shift; @@ -361,83 +361,83 @@ static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift) } #undef silk_RSHIFT8 -static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift) { +static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){ ops_count += 1; return a >> shift; } #undef silk_RSHIFT16 -static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift) { +static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){ ops_count += 1; return a >> shift; } #undef silk_RSHIFT32 -static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){ ops_count += 1; return a >> shift; } #undef silk_RSHIFT64 -static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift) { +static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){ ops_count += 1; return a >> shift; } #undef silk_RSHIFT_uint -static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift) { +static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){ ops_count += 1; return a >> shift; } #undef silk_ADD_LSHIFT -static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){ opus_int32 ret; ops_count += 1; ret = a + (b << shift); return ret; /* shift >= 0*/ } #undef silk_ADD_LSHIFT32 -static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ opus_int32 ret; ops_count += 1; ret = a + (b << shift); return ret; /* shift >= 0*/ } #undef silk_ADD_LSHIFT_uint -static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift) { +static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){ opus_uint32 ret; ops_count += 1; ret = a + (b << shift); return ret; /* shift >= 0*/ } #undef silk_ADD_RSHIFT -static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){ opus_int32 ret; ops_count += 1; ret = a + (b >> shift); return ret; /* shift > 0*/ } #undef silk_ADD_RSHIFT32 -static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ opus_int32 ret; ops_count += 1; ret = a + (b >> shift); return ret; /* shift > 0*/ } #undef silk_ADD_RSHIFT_uint -static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift) { +static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){ opus_uint32 ret; ops_count += 1; ret = a + (b >> shift); return ret; /* shift > 0*/ } #undef silk_SUB_LSHIFT32 -static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ opus_int32 ret; ops_count += 1; ret = a - (b << shift); return ret; /* shift >= 0*/ } #undef silk_SUB_RSHIFT32 -static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ opus_int32 ret; ops_count += 1; ret = a - (b >> shift); @@ -445,7 +445,7 @@ static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus } #undef silk_RSHIFT_ROUND -static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift) { +static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){ opus_int32 ret; ops_count += 3; ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; @@ -453,7 +453,7 @@ static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift) } #undef silk_RSHIFT_ROUND64 -static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift) { +static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){ opus_int64 ret; ops_count += 6; ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; @@ -461,36 +461,36 @@ static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift } #undef silk_abs_int64 -static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a) { +static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){ ops_count += 1; return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/ } #undef silk_abs_int32 -static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a) { +static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){ ops_count += 1; return silk_abs(a); } #undef silk_min -static silk_min(a, b) { +static silk_min(a, b){ ops_count += 1; - return (((a) < (b)) ? (a) : (b)); + return (((a) < (b)) ? (a) : (b)); } #undef silk_max -static silk_max(a, b) { +static silk_max(a, b){ ops_count += 1; - return (((a) > (b)) ? (a) : (b)); + return (((a) > (b)) ? (a) : (b)); } #undef silk_sign -static silk_sign(a) { +static silk_sign(a){ ops_count += 1; - return ((a) > 0 ? 1 : ((a) < 0 ? -1 : 0)); + return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 )); } #undef silk_ADD16 -static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b) { +static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){ opus_int16 ret; ops_count += 1; ret = a + b; @@ -498,7 +498,7 @@ static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b) { } #undef silk_ADD32 -static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b) { +static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){ opus_int32 ret; ops_count += 1; ret = a + b; @@ -506,7 +506,7 @@ static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b) { } #undef silk_ADD64 -static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){ opus_int64 ret; ops_count += 2; ret = a + b; @@ -514,7 +514,7 @@ static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b) { } #undef silk_SUB16 -static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b) { +static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){ opus_int16 ret; ops_count += 1; ret = a - b; @@ -522,7 +522,7 @@ static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b) { } #undef silk_SUB32 -static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b) { +static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){ opus_int32 ret; ops_count += 1; ret = a - b; @@ -530,7 +530,7 @@ static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b) { } #undef silk_SUB64 -static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){ opus_int64 ret; ops_count += 2; ret = a - b; @@ -538,65 +538,65 @@ static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b) { } #undef silk_ADD_SAT16 -static OPUS_INLINE opus_int16 silk_ADD_SAT16(opus_int16 a16, opus_int16 b16) { +static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) { opus_int16 res; /* Nb will be counted in AKP_add32 and silk_SAT16*/ - res = (opus_int16)silk_SAT16(silk_ADD32((opus_int32)(a16), (b16))); + res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) ); return res; } #undef silk_ADD_SAT32 -static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){ opus_int32 res; ops_count += 1; - res = ((((a32) + (b32)) & 0x80000000) == 0 ? \ - ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32) + (b32)) : \ - ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32) + (b32))); + res = ((((a32) + (b32)) & 0x80000000) == 0 ? \ + ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \ + ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) ); return res; } #undef silk_ADD_SAT64 -static OPUS_INLINE opus_int64 silk_ADD_SAT64(opus_int64 a64, opus_int64 b64) { +static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) { opus_int64 res; ops_count += 1; - res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ - ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64) + (b64)) : \ - ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64) + (b64))); + res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ + ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \ + ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) ); return res; } #undef silk_SUB_SAT16 -static OPUS_INLINE opus_int16 silk_SUB_SAT16(opus_int16 a16, opus_int16 b16) { +static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) { opus_int16 res; silk_assert(0); /* Nb will be counted in sub-macros*/ - res = (opus_int16)silk_SAT16(silk_SUB32((opus_int32)(a16), (b16))); + res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) ); return res; } #undef silk_SUB_SAT32 -static OPUS_INLINE opus_int32 silk_SUB_SAT32(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) { opus_int32 res; ops_count += 1; - res = ((((a32) - (b32)) & 0x80000000) == 0 ? \ - (((a32) & ((b32) ^ 0x80000000) & 0x80000000) ? silk_int32_MIN : (a32) - (b32)) : \ - ((((a32) ^ 0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32) - (b32))); + res = ((((a32)-(b32)) & 0x80000000) == 0 ? \ + (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \ + ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) ); return res; } #undef silk_SUB_SAT64 -static OPUS_INLINE opus_int64 silk_SUB_SAT64(opus_int64 a64, opus_int64 b64) { +static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) { opus_int64 res; ops_count += 1; - res = ((((a64) - (b64)) & 0x8000000000000000LL) == 0 ? \ - (((a64) & ((b64) ^ 0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64) - (b64)) : \ - ((((a64) ^ 0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64) - (b64))); + res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \ + (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \ + ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) ); return res; } #undef silk_SMULWW -static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32) { +static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){ opus_int32 ret; /* Nb will be counted in sub-macros*/ ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)); @@ -604,7 +604,7 @@ static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32) { } #undef silk_SMLAWW -static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32) { +static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){ opus_int32 ret; /* Nb will be counted in sub-macros*/ ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16)); @@ -612,82 +612,93 @@ static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_i } #undef silk_min_int -static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) { +static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) +{ ops_count += 1; return (((a) < (b)) ? (a) : (b)); } #undef silk_min_16 -static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b) { +static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b) +{ ops_count += 1; return (((a) < (b)) ? (a) : (b)); } #undef silk_min_32 -static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b) { +static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b) +{ ops_count += 1; return (((a) < (b)) ? (a) : (b)); } #undef silk_min_64 -static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b) +{ ops_count += 1; return (((a) < (b)) ? (a) : (b)); } /* silk_min() versions with typecast in the function call */ #undef silk_max_int -static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b) { +static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b) +{ ops_count += 1; return (((a) > (b)) ? (a) : (b)); } #undef silk_max_16 -static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b) { +static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b) +{ ops_count += 1; return (((a) > (b)) ? (a) : (b)); } #undef silk_max_32 -static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b) { +static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b) +{ ops_count += 1; return (((a) > (b)) ? (a) : (b)); } #undef silk_max_64 -static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) +{ ops_count += 1; return (((a) > (b)) ? (a) : (b)); } #undef silk_LIMIT_int -static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2) { +static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2) +{ opus_int ret; ops_count += 6; ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ - : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); - return (ret); + return(ret); } #undef silk_LIMIT_16 -static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2) { +static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2) +{ opus_int16 ret; ops_count += 6; ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ - : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); - return (ret); +return(ret); } #undef silk_LIMIT_32 -static OPUS_INLINE opus_int32 silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2) { +static OPUS_INLINE opus_int32 silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2) +{ opus_int32 ret; ops_count += 6; ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ - : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); - return (ret); + : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); + return(ret); } #else diff --git a/src/libopus/silk/MacroDebug.h b/src/libopus/silk/MacroDebug.h index 7794eed..3110da9 100644 --- a/src/libopus/silk/MacroDebug.h +++ b/src/libopus/silk/MacroDebug.h @@ -1,49 +1,50 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Copyright (C) 2012 Xiph.Org Foundation - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Copyright (C) 2012 Xiph.Org Foundation +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef MACRO_DEBUG_H #define MACRO_DEBUG_H -/* Redefine macro functions with extensive assertion in DEBUG mode. - As functions can't be undefined, this file can't work with SigProcFIX_MacroCount.h */ +/* Redefine macro functions with extensive assertion in DEBUG mode. + As functions can't be undefined, this file can't work with SigProcFIX_MacroCount.h */ #if ( defined (FIXED_DEBUG) || ( 0 && defined (_DEBUG) ) ) && !defined (silk_MACRO_COUNT) #undef silk_ADD16 #define silk_ADD16(a,b) silk_ADD16_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int16 silk_ADD16_(opus_int16 a, opus_int16 b, char *file, int line) { +static OPUS_INLINE opus_int16 silk_ADD16_(opus_int16 a, opus_int16 b, char *file, int line){ opus_int16 ret; ret = a + b; - if (ret != silk_ADD_SAT16(a, b)) { - fprintf(stderr, "silk_ADD16(%d, %d) in %s: line %d\n", a, b, file, line); + if ( ret != silk_ADD_SAT16( a, b ) ) + { + fprintf (stderr, "silk_ADD16(%d, %d) in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -51,14 +52,15 @@ static OPUS_INLINE opus_int16 silk_ADD16_(opus_int16 a, opus_int16 b, char *file #undef silk_ADD32 #define silk_ADD32(a,b) silk_ADD32_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_ADD32_(opus_int32 a, opus_int32 b, char *file, int line) { +static OPUS_INLINE opus_int32 silk_ADD32_(opus_int32 a, opus_int32 b, char *file, int line){ opus_int32 ret; - ret = a + b; - if (ret != silk_ADD_SAT32(a, b)) { - fprintf(stderr, "silk_ADD32(%d, %d) in %s: line %d\n", a, b, file, line); + ret = (opus_int32)((opus_uint32)a + (opus_uint32)b); + if ( ret != silk_ADD_SAT32( a, b ) ) + { + fprintf (stderr, "silk_ADD32(%d, %d) in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -66,14 +68,15 @@ static OPUS_INLINE opus_int32 silk_ADD32_(opus_int32 a, opus_int32 b, char *file #undef silk_ADD64 #define silk_ADD64(a,b) silk_ADD64_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_ADD64_(opus_int64 a, opus_int64 b, char *file, int line) { +static OPUS_INLINE opus_int64 silk_ADD64_(opus_int64 a, opus_int64 b, char *file, int line){ opus_int64 ret; ret = a + b; - if (ret != silk_ADD_SAT64(a, b)) { - fprintf(stderr, "silk_ADD64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line); + if ( ret != silk_ADD_SAT64( a, b ) ) + { + fprintf (stderr, "silk_ADD64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -81,14 +84,15 @@ static OPUS_INLINE opus_int64 silk_ADD64_(opus_int64 a, opus_int64 b, char *file #undef silk_SUB16 #define silk_SUB16(a,b) silk_SUB16_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int16 silk_SUB16_(opus_int16 a, opus_int16 b, char *file, int line) { +static OPUS_INLINE opus_int16 silk_SUB16_(opus_int16 a, opus_int16 b, char *file, int line){ opus_int16 ret; ret = a - b; - if (ret != silk_SUB_SAT16(a, b)) { - fprintf(stderr, "silk_SUB16(%d, %d) in %s: line %d\n", a, b, file, line); + if ( ret != silk_SUB_SAT16( a, b ) ) + { + fprintf (stderr, "silk_SUB16(%d, %d) in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -96,14 +100,15 @@ static OPUS_INLINE opus_int16 silk_SUB16_(opus_int16 a, opus_int16 b, char *file #undef silk_SUB32 #define silk_SUB32(a,b) silk_SUB32_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SUB32_(opus_int32 a, opus_int32 b, char *file, int line) { - opus_int32 ret; +static OPUS_INLINE opus_int32 silk_SUB32_(opus_int32 a, opus_int32 b, char *file, int line){ + opus_int64 ret; - ret = a - b; - if (ret != silk_SUB_SAT32(a, b)) { - fprintf(stderr, "silk_SUB32(%d, %d) in %s: line %d\n", a, b, file, line); + ret = a - (opus_int64)b; + if ( ret != silk_SUB_SAT32( a, b ) ) + { + fprintf (stderr, "silk_SUB32(%d, %d) in %s: line %d\n", a, b, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -111,14 +116,15 @@ static OPUS_INLINE opus_int32 silk_SUB32_(opus_int32 a, opus_int32 b, char *file #undef silk_SUB64 #define silk_SUB64(a,b) silk_SUB64_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_SUB64_(opus_int64 a, opus_int64 b, char *file, int line) { +static OPUS_INLINE opus_int64 silk_SUB64_(opus_int64 a, opus_int64 b, char *file, int line){ opus_int64 ret; ret = a - b; - if (ret != silk_SUB_SAT64(a, b)) { - fprintf(stderr, "silk_SUB64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line); + if ( ret != silk_SUB_SAT64( a, b ) ) + { + fprintf (stderr, "silk_SUB64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -126,13 +132,14 @@ static OPUS_INLINE opus_int64 silk_SUB64_(opus_int64 a, opus_int64 b, char *file #undef silk_ADD_SAT16 #define silk_ADD_SAT16(a,b) silk_ADD_SAT16_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int16 silk_ADD_SAT16_(opus_int16 a16, opus_int16 b16, char *file, int line) { +static OPUS_INLINE opus_int16 silk_ADD_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line) { opus_int16 res; - res = (opus_int16)silk_SAT16(silk_ADD32((opus_int32)(a16), (b16))); - if (res != silk_SAT16((opus_int32)a16 + (opus_int32)b16)) { - fprintf(stderr, "silk_ADD_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line); + res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) ); + if ( res != silk_SAT16( (opus_int32)a16 + (opus_int32)b16 ) ) + { + fprintf (stderr, "silk_ADD_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return res; @@ -140,15 +147,16 @@ static OPUS_INLINE opus_int16 silk_ADD_SAT16_(opus_int16 a16, opus_int16 b16, ch #undef silk_ADD_SAT32 #define silk_ADD_SAT32(a,b) silk_ADD_SAT32_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_ADD_SAT32_(opus_int32 a32, opus_int32 b32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_ADD_SAT32_(opus_int32 a32, opus_int32 b32, char *file, int line){ opus_int32 res; - res = ((((opus_uint32)(a32) + (opus_uint32)(b32)) & 0x80000000) == 0 ? \ - ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32) + (b32)) : \ - ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32) + (b32))); - if (res != silk_SAT32((opus_int64)a32 + (opus_int64)b32)) { - fprintf(stderr, "silk_ADD_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line); + res = ((((opus_uint32)(a32) + (opus_uint32)(b32)) & 0x80000000) == 0 ? \ + ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \ + ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) ); + if ( res != silk_SAT32( (opus_int64)a32 + (opus_int64)b32 ) ) + { + fprintf (stderr, "silk_ADD_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return res; @@ -156,26 +164,28 @@ static OPUS_INLINE opus_int32 silk_ADD_SAT32_(opus_int32 a32, opus_int32 b32, ch #undef silk_ADD_SAT64 #define silk_ADD_SAT64(a,b) silk_ADD_SAT64_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_ADD_SAT64_(opus_int64 a64, opus_int64 b64, char *file, int line) { +static OPUS_INLINE opus_int64 silk_ADD_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line) { opus_int64 res; int fail = 0; - res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ - ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64) + (b64)) : \ - ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64) + (b64))); - if (res != a64 + b64) { + res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ + ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \ + ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) ); + if( res != a64 + b64 ) { /* Check that we saturated to the correct extreme value */ - if (!((res == silk_int64_MAX && ((a64 >> 1) + (b64 >> 1) > (silk_int64_MAX >> 3))) || - (res == silk_int64_MIN && ((a64 >> 1) + (b64 >> 1) < (silk_int64_MIN >> 3))))) { + if ( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) || + ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) ) ) + { fail = 1; } } else { /* Saturation not necessary */ fail = res != a64 + b64; } - if (fail) { - fprintf(stderr, "silk_ADD_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line); + if ( fail ) + { + fprintf (stderr, "silk_ADD_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return res; @@ -183,13 +193,14 @@ static OPUS_INLINE opus_int64 silk_ADD_SAT64_(opus_int64 a64, opus_int64 b64, ch #undef silk_SUB_SAT16 #define silk_SUB_SAT16(a,b) silk_SUB_SAT16_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int16 silk_SUB_SAT16_(opus_int16 a16, opus_int16 b16, char *file, int line) { +static OPUS_INLINE opus_int16 silk_SUB_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line ) { opus_int16 res; - res = (opus_int16)silk_SAT16(silk_SUB32((opus_int32)(a16), (b16))); - if (res != silk_SAT16((opus_int32)a16 - (opus_int32)b16)) { - fprintf(stderr, "silk_SUB_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line); + res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) ); + if ( res != silk_SAT16( (opus_int32)a16 - (opus_int32)b16 ) ) + { + fprintf (stderr, "silk_SUB_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return res; @@ -197,15 +208,16 @@ static OPUS_INLINE opus_int16 silk_SUB_SAT16_(opus_int16 a16, opus_int16 b16, ch #undef silk_SUB_SAT32 #define silk_SUB_SAT32(a,b) silk_SUB_SAT32_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SUB_SAT32_(opus_int32 a32, opus_int32 b32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SUB_SAT32_( opus_int32 a32, opus_int32 b32, char *file, int line ) { opus_int32 res; - res = ((((opus_uint32)(a32) - (opus_uint32)(b32)) & 0x80000000) == 0 ? \ - (((a32) & ((b32) ^ 0x80000000) & 0x80000000) ? silk_int32_MIN : (a32) - (b32)) : \ - ((((a32) ^ 0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32) - (b32))); - if (res != silk_SAT32((opus_int64)a32 - (opus_int64)b32)) { - fprintf(stderr, "silk_SUB_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line); + res = ((((opus_uint32)(a32)-(opus_uint32)(b32)) & 0x80000000) == 0 ? \ + (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \ + ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) ); + if ( res != silk_SAT32( (opus_int64)a32 - (opus_int64)b32 ) ) + { + fprintf (stderr, "silk_SUB_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return res; @@ -213,26 +225,28 @@ static OPUS_INLINE opus_int32 silk_SUB_SAT32_(opus_int32 a32, opus_int32 b32, ch #undef silk_SUB_SAT64 #define silk_SUB_SAT64(a,b) silk_SUB_SAT64_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_SUB_SAT64_(opus_int64 a64, opus_int64 b64, char *file, int line) { +static OPUS_INLINE opus_int64 silk_SUB_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line ) { opus_int64 res; int fail = 0; - res = ((((a64) - (b64)) & 0x8000000000000000LL) == 0 ? \ - (((a64) & ((b64) ^ 0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64) - (b64)) : \ - ((((a64) ^ 0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64) - (b64))); - if (res != a64 - b64) { + res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \ + (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \ + ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) ); + if( res != a64 - b64 ) { /* Check that we saturated to the correct extreme value */ - if (!((res == silk_int64_MAX && ((a64 >> 1) + (b64 >> 1) > (silk_int64_MAX >> 3))) || - (res == silk_int64_MIN && ((a64 >> 1) + (b64 >> 1) < (silk_int64_MIN >> 3))))) { + if( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) || + ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) )) + { fail = 1; } } else { /* Saturation not necessary */ fail = res != a64 - b64; } - if (fail) { - fprintf(stderr, "silk_SUB_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line); + if ( fail ) + { + fprintf (stderr, "silk_SUB_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return res; @@ -240,15 +254,16 @@ static OPUS_INLINE opus_int64 silk_SUB_SAT64_(opus_int64 a64, opus_int64 b64, ch #undef silk_MUL #define silk_MUL(a,b) silk_MUL_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_MUL_(opus_int32 a32, opus_int32 b32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_MUL_(opus_int32 a32, opus_int32 b32, char *file, int line){ opus_int32 ret; opus_int64 ret64; - ret = a32 * b32; + ret = (opus_int32)((opus_uint32)a32 * (opus_uint32)b32); ret64 = (opus_int64)a32 * (opus_int64)b32; - if ((opus_int64)ret != ret64) { - fprintf(stderr, "silk_MUL(%d, %d) in %s: line %d\n", a32, b32, file, line); + if ( (opus_int64)ret != ret64 ) + { + fprintf (stderr, "silk_MUL(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -256,13 +271,14 @@ static OPUS_INLINE opus_int32 silk_MUL_(opus_int32 a32, opus_int32 b32, char *fi #undef silk_MUL_uint #define silk_MUL_uint(a,b) silk_MUL_uint_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_uint32 silk_MUL_uint_(opus_uint32 a32, opus_uint32 b32, char *file, int line) { +static OPUS_INLINE opus_uint32 silk_MUL_uint_(opus_uint32 a32, opus_uint32 b32, char *file, int line){ opus_uint32 ret; ret = a32 * b32; - if ((opus_uint64)ret != (opus_uint64)a32 * (opus_uint64)b32) { - fprintf(stderr, "silk_MUL_uint(%u, %u) in %s: line %d\n", a32, b32, file, line); + if ( (opus_uint64)ret != (opus_uint64)a32 * (opus_uint64)b32 ) + { + fprintf (stderr, "silk_MUL_uint(%u, %u) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -270,13 +286,14 @@ static OPUS_INLINE opus_uint32 silk_MUL_uint_(opus_uint32 a32, opus_uint32 b32, #undef silk_MLA #define silk_MLA(a,b,c) silk_MLA_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_MLA_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_MLA_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){ opus_int32 ret; ret = a32 + b32 * c32; - if ((opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32) { - fprintf(stderr, "silk_MLA(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 ) + { + fprintf (stderr, "silk_MLA(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -284,13 +301,14 @@ static OPUS_INLINE opus_int32 silk_MLA_(opus_int32 a32, opus_int32 b32, opus_int #undef silk_MLA_uint #define silk_MLA_uint(a,b,c) silk_MLA_uint_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_MLA_uint_(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_MLA_uint_(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32, char *file, int line){ opus_uint32 ret; ret = a32 + b32 * c32; - if ((opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32) { - fprintf(stderr, "silk_MLA_uint(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 ) + { + fprintf (stderr, "silk_MLA_uint(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -298,13 +316,14 @@ static OPUS_INLINE opus_int32 silk_MLA_uint_(opus_uint32 a32, opus_uint32 b32, o #undef silk_SMULWB #define silk_SMULWB(a,b) silk_SMULWB_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMULWB_(opus_int32 a32, opus_int32 b32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMULWB_(opus_int32 a32, opus_int32 b32, char *file, int line){ opus_int32 ret; ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16); - if ((opus_int64)ret != ((opus_int64)a32 * (opus_int16)b32) >> 16) { - fprintf(stderr, "silk_SMULWB(%d, %d) in %s: line %d\n", a32, b32, file, line); + if ( (opus_int64)ret != ((opus_int64)a32 * (opus_int16)b32) >> 16 ) + { + fprintf (stderr, "silk_SMULWB(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -312,13 +331,14 @@ static OPUS_INLINE opus_int32 silk_SMULWB_(opus_int32 a32, opus_int32 b32, char #undef silk_SMLAWB #define silk_SMLAWB(a,b,c) silk_SMLAWB_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMLAWB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMLAWB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){ opus_int32 ret; - ret = silk_ADD32(a32, silk_SMULWB(b32, c32)); - if (silk_ADD32(a32, silk_SMULWB(b32, c32)) != silk_ADD_SAT32(a32, silk_SMULWB(b32, c32))) { - fprintf(stderr, "silk_SMLAWB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + ret = silk_ADD32_ovflw( a32, silk_SMULWB( b32, c32 ) ); + if ( ret != silk_ADD_SAT32( a32, silk_SMULWB( b32, c32 ) ) ) + { + fprintf (stderr, "silk_SMLAWB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -326,13 +346,14 @@ static OPUS_INLINE opus_int32 silk_SMLAWB_(opus_int32 a32, opus_int32 b32, opus_ #undef silk_SMULWT #define silk_SMULWT(a,b) silk_SMULWT_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMULWT_(opus_int32 a32, opus_int32 b32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMULWT_(opus_int32 a32, opus_int32 b32, char *file, int line){ opus_int32 ret; ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16); - if ((opus_int64)ret != ((opus_int64)a32 * (b32 >> 16)) >> 16) { - fprintf(stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line); + if ( (opus_int64)ret != ((opus_int64)a32 * (b32 >> 16)) >> 16 ) + { + fprintf (stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -340,13 +361,14 @@ static OPUS_INLINE opus_int32 silk_SMULWT_(opus_int32 a32, opus_int32 b32, char #undef silk_SMLAWT #define silk_SMLAWT(a,b,c) silk_SMLAWT_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMLAWT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMLAWT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){ opus_int32 ret; ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16)); - if ((opus_int64)ret != (opus_int64)a32 + (((opus_int64)b32 * (c32 >> 16)) >> 16)) { - fprintf(stderr, "silk_SMLAWT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + if ( (opus_int64)ret != (opus_int64)a32 + (((opus_int64)b32 * (c32 >> 16)) >> 16) ) + { + fprintf (stderr, "silk_SMLAWT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -354,19 +376,20 @@ static OPUS_INLINE opus_int32 silk_SMLAWT_(opus_int32 a32, opus_int32 b32, opus_ #undef silk_SMULL #define silk_SMULL(a,b) silk_SMULL_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_SMULL_(opus_int64 a64, opus_int64 b64, char *file, int line) { +static OPUS_INLINE opus_int64 silk_SMULL_(opus_int64 a64, opus_int64 b64, char *file, int line){ opus_int64 ret64; int fail = 0; ret64 = a64 * b64; - if (b64 != 0) { + if( b64 != 0 ) { fail = a64 != (ret64 / b64); - } else if (a64 != 0) { + } else if( a64 != 0 ) { fail = b64 != (ret64 / a64); } - if (fail) { - fprintf(stderr, "silk_SMULL(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line); + if ( fail ) + { + fprintf (stderr, "silk_SMULL(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret64; @@ -375,13 +398,14 @@ static OPUS_INLINE opus_int64 silk_SMULL_(opus_int64 a64, opus_int64 b64, char * /* no checking needed for silk_SMULBB */ #undef silk_SMLABB #define silk_SMLABB(a,b,c) silk_SMLABB_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMLABB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMLABB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){ opus_int32 ret; ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32); - if ((opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int16)c32) { - fprintf(stderr, "silk_SMLABB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int16)c32 ) + { + fprintf (stderr, "silk_SMLABB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -390,13 +414,14 @@ static OPUS_INLINE opus_int32 silk_SMLABB_(opus_int32 a32, opus_int32 b32, opus_ /* no checking needed for silk_SMULBT */ #undef silk_SMLABT #define silk_SMLABT(a,b,c) silk_SMLABT_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMLABT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMLABT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){ opus_int32 ret; ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16); - if ((opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (c32 >> 16)) { - fprintf(stderr, "silk_SMLABT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (c32 >> 16) ) + { + fprintf (stderr, "silk_SMLABT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -405,13 +430,14 @@ static OPUS_INLINE opus_int32 silk_SMLABT_(opus_int32 a32, opus_int32 b32, opus_ /* no checking needed for silk_SMULTT */ #undef silk_SMLATT #define silk_SMLATT(a,b,c) silk_SMLATT_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMLATT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMLATT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){ opus_int32 ret; ret = a32 + (b32 >> 16) * (c32 >> 16); - if ((opus_int64)ret != (opus_int64)a32 + (b32 >> 16) * (c32 >> 16)) { - fprintf(stderr, "silk_SMLATT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + if ( (opus_int64)ret != (opus_int64)a32 + (b32 >> 16) * (c32 >> 16) ) + { + fprintf (stderr, "silk_SMLATT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -419,28 +445,29 @@ static OPUS_INLINE opus_int32 silk_SMLATT_(opus_int32 a32, opus_int32 b32, opus_ #undef silk_SMULWW #define silk_SMULWW(a,b) silk_SMULWW_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMULWW_(opus_int32 a32, opus_int32 b32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMULWW_(opus_int32 a32, opus_int32 b32, char *file, int line){ opus_int32 ret, tmp1, tmp2; opus_int64 ret64; int fail = 0; - ret = silk_SMULWB(a32, b32); - tmp1 = silk_RSHIFT_ROUND(b32, 16); - tmp2 = silk_MUL(a32, tmp1); + ret = silk_SMULWB( a32, b32 ); + tmp1 = silk_RSHIFT_ROUND( b32, 16 ); + tmp2 = silk_MUL( a32, tmp1 ); fail |= (opus_int64)tmp2 != (opus_int64) a32 * (opus_int64) tmp1; tmp1 = ret; - ret = silk_ADD32(tmp1, tmp2); - fail |= silk_ADD32(tmp1, tmp2) != silk_ADD_SAT32(tmp1, tmp2); + ret = silk_ADD32( tmp1, tmp2 ); + fail |= silk_ADD32( tmp1, tmp2 ) != silk_ADD_SAT32( tmp1, tmp2 ); - ret64 = silk_RSHIFT64(silk_SMULL(a32, b32), 16); + ret64 = silk_RSHIFT64( silk_SMULL( a32, b32 ), 16 ); fail |= (opus_int64)ret != ret64; - if (fail) { - fprintf(stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line); + if ( fail ) + { + fprintf (stderr, "silk_SMULWW(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } @@ -449,39 +476,35 @@ static OPUS_INLINE opus_int32 silk_SMULWW_(opus_int32 a32, opus_int32 b32, char #undef silk_SMLAWW #define silk_SMLAWW(a,b,c) silk_SMLAWW_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SMLAWW_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SMLAWW_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){ opus_int32 ret, tmp; - tmp = silk_SMULWW(b32, c32); - ret = silk_ADD32(a32, tmp); - if (ret != silk_ADD_SAT32(a32, tmp)) { - fprintf(stderr, "silk_SMLAWW(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); + tmp = silk_SMULWW( b32, c32 ); + ret = silk_ADD32( a32, tmp ); + if ( ret != silk_ADD_SAT32( a32, tmp ) ) + { + fprintf (stderr, "silk_SMLAWW(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; } -/* Multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) */ -#undef silk_MLA_ovflw -#define silk_MLA_ovflw(a32, b32, c32) ((a32) + ((b32) * (c32))) -#undef silk_SMLABB_ovflw -#define silk_SMLABB_ovflw(a32, b32, c32) ((a32) + ((opus_int32)((opus_int16)(b32))) * (opus_int32)((opus_int16)(c32))) - -/* no checking needed for silk_SMULL - no checking needed for silk_SMLAL - no checking needed for silk_SMLALBB - no checking needed for SigProcFIX_CLZ16 - no checking needed for SigProcFIX_CLZ32*/ +/* no checking needed for silk_SMULL + no checking needed for silk_SMLAL + no checking needed for silk_SMLALBB + no checking needed for SigProcFIX_CLZ16 + no checking needed for SigProcFIX_CLZ32*/ #undef silk_DIV32 #define silk_DIV32(a,b) silk_DIV32_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_DIV32_(opus_int32 a32, opus_int32 b32, char *file, int line) { - if (b32 == 0) { - fprintf(stderr, "silk_DIV32(%d, %d) in %s: line %d\n", a32, b32, file, line); +static OPUS_INLINE opus_int32 silk_DIV32_(opus_int32 a32, opus_int32 b32, char *file, int line){ + if ( b32 == 0 ) + { + fprintf (stderr, "silk_DIV32(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a32 / b32; @@ -489,41 +512,43 @@ static OPUS_INLINE opus_int32 silk_DIV32_(opus_int32 a32, opus_int32 b32, char * #undef silk_DIV32_16 #define silk_DIV32_16(a,b) silk_DIV32_16_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_DIV32_16_(opus_int32 a32, opus_int32 b32, char *file, int line) { +static OPUS_INLINE opus_int32 silk_DIV32_16_(opus_int32 a32, opus_int32 b32, char *file, int line){ int fail = 0; fail |= b32 == 0; fail |= b32 > silk_int16_MAX; fail |= b32 < silk_int16_MIN; - if (fail) { - fprintf(stderr, "silk_DIV32_16(%d, %d) in %s: line %d\n", a32, b32, file, line); + if ( fail ) + { + fprintf (stderr, "silk_DIV32_16(%d, %d) in %s: line %d\n", a32, b32, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a32 / b32; } -/* no checking needed for silk_SAT8 - no checking needed for silk_SAT16 - no checking needed for silk_SAT32 - no checking needed for silk_POS_SAT32 - no checking needed for silk_ADD_POS_SAT8 - no checking needed for silk_ADD_POS_SAT16 - no checking needed for silk_ADD_POS_SAT32 */ +/* no checking needed for silk_SAT8 + no checking needed for silk_SAT16 + no checking needed for silk_SAT32 + no checking needed for silk_POS_SAT32 + no checking needed for silk_ADD_POS_SAT8 + no checking needed for silk_ADD_POS_SAT16 + no checking needed for silk_ADD_POS_SAT32 */ #undef silk_LSHIFT8 #define silk_LSHIFT8(a,b) silk_LSHIFT8_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int8 silk_LSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int8 silk_LSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){ opus_int8 ret; int fail = 0; - ret = a << shift; + ret = (opus_int8)((opus_uint8)a << shift); fail |= shift < 0; fail |= shift >= 8; - fail |= (opus_int64)ret != ((opus_int64)a) << shift; - if (fail) { - fprintf(stderr, "silk_LSHIFT8(%d, %d) in %s: line %d\n", a, shift, file, line); + fail |= (opus_int64)ret != (opus_int64)(((opus_uint64)a) << shift); + if ( fail ) + { + fprintf (stderr, "silk_LSHIFT8(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -531,17 +556,18 @@ static OPUS_INLINE opus_int8 silk_LSHIFT8_(opus_int8 a, opus_int32 shift, char * #undef silk_LSHIFT16 #define silk_LSHIFT16(a,b) silk_LSHIFT16_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int16 silk_LSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int16 silk_LSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){ opus_int16 ret; int fail = 0; - ret = a << shift; + ret = (opus_int16)((opus_uint16)a << shift); fail |= shift < 0; fail |= shift >= 16; - fail |= (opus_int64)ret != ((opus_int64)a) << shift; - if (fail) { - fprintf(stderr, "silk_LSHIFT16(%d, %d) in %s: line %d\n", a, shift, file, line); + fail |= (opus_int64)ret != (opus_int64)(((opus_uint64)a) << shift); + if ( fail ) + { + fprintf (stderr, "silk_LSHIFT16(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -549,17 +575,18 @@ static OPUS_INLINE opus_int16 silk_LSHIFT16_(opus_int16 a, opus_int32 shift, cha #undef silk_LSHIFT32 #define silk_LSHIFT32(a,b) silk_LSHIFT32_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_LSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int32 silk_LSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){ opus_int32 ret; int fail = 0; - ret = a << shift; + ret = (opus_int32)((opus_uint32)a << shift); fail |= shift < 0; fail |= shift >= 32; - fail |= (opus_int64)ret != ((opus_int64)a) << shift; - if (fail) { - fprintf(stderr, "silk_LSHIFT32(%d, %d) in %s: line %d\n", a, shift, file, line); + fail |= (opus_int64)ret != (opus_int64)(((opus_uint64)a) << shift); + if ( fail ) + { + fprintf (stderr, "silk_LSHIFT32(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -567,17 +594,18 @@ static OPUS_INLINE opus_int32 silk_LSHIFT32_(opus_int32 a, opus_int32 shift, cha #undef silk_LSHIFT64 #define silk_LSHIFT64(a,b) silk_LSHIFT64_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_LSHIFT64_(opus_int64 a, opus_int shift, char *file, int line) { +static OPUS_INLINE opus_int64 silk_LSHIFT64_(opus_int64 a, opus_int shift, char *file, int line){ opus_int64 ret; int fail = 0; - ret = a << shift; + ret = (opus_int64)((opus_uint64)a << shift); fail |= shift < 0; fail |= shift >= 64; - fail |= (ret >> shift) != ((opus_int64)a); - if (fail) { - fprintf(stderr, "silk_LSHIFT64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line); + fail |= (ret>>shift) != ((opus_int64)a); + if ( fail ) + { + fprintf (stderr, "silk_LSHIFT64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -585,11 +613,12 @@ static OPUS_INLINE opus_int64 silk_LSHIFT64_(opus_int64 a, opus_int shift, char #undef silk_LSHIFT_ovflw #define silk_LSHIFT_ovflw(a,b) silk_LSHIFT_ovflw_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw_(opus_int32 a, opus_int32 shift, char *file, int line) { - if ((shift < 0) || (shift >= 32)) { /* no check for overflow */ - fprintf(stderr, "silk_LSHIFT_ovflw(%d, %d) in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw_(opus_int32 a, opus_int32 shift, char *file, int line){ + if ( (shift < 0) || (shift >= 32) ) /* no check for overflow */ + { + fprintf (stderr, "silk_LSHIFT_ovflw(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a << shift; @@ -597,13 +626,14 @@ static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw_(opus_int32 a, opus_int32 shift, #undef silk_LSHIFT_uint #define silk_LSHIFT_uint(a,b) silk_LSHIFT_uint_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_uint32 silk_LSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_uint32 silk_LSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){ opus_uint32 ret; ret = a << shift; - if ((shift < 0) || ((opus_int64)ret != ((opus_int64)a) << shift)) { - fprintf(stderr, "silk_LSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line); + if ( (shift < 0) || ((opus_int64)ret != ((opus_int64)a) << shift)) + { + fprintf (stderr, "silk_LSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -611,11 +641,12 @@ static OPUS_INLINE opus_uint32 silk_LSHIFT_uint_(opus_uint32 a, opus_int32 shift #undef silk_RSHIFT8 #define silk_RSHITF8(a,b) silk_RSHIFT8_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int8 silk_RSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line) { - if ((shift < 0) || (shift >= 8)) { - fprintf(stderr, "silk_RSHITF8(%d, %d) in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE opus_int8 silk_RSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){ + if ( (shift < 0) || (shift>=8) ) + { + fprintf (stderr, "silk_RSHITF8(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a >> shift; @@ -623,11 +654,12 @@ static OPUS_INLINE opus_int8 silk_RSHIFT8_(opus_int8 a, opus_int32 shift, char * #undef silk_RSHIFT16 #define silk_RSHITF16(a,b) silk_RSHIFT16_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int16 silk_RSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line) { - if ((shift < 0) || (shift >= 16)) { - fprintf(stderr, "silk_RSHITF16(%d, %d) in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE opus_int16 silk_RSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){ + if ( (shift < 0) || (shift>=16) ) + { + fprintf (stderr, "silk_RSHITF16(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a >> shift; @@ -635,11 +667,12 @@ static OPUS_INLINE opus_int16 silk_RSHIFT16_(opus_int16 a, opus_int32 shift, cha #undef silk_RSHIFT32 #define silk_RSHIFT32(a,b) silk_RSHIFT32_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_RSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line) { - if ((shift < 0) || (shift >= 32)) { - fprintf(stderr, "silk_RSHITF32(%d, %d) in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE opus_int32 silk_RSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){ + if ( (shift < 0) || (shift>=32) ) + { + fprintf (stderr, "silk_RSHITF32(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a >> shift; @@ -647,11 +680,12 @@ static OPUS_INLINE opus_int32 silk_RSHIFT32_(opus_int32 a, opus_int32 shift, cha #undef silk_RSHIFT64 #define silk_RSHIFT64(a,b) silk_RSHIFT64_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_RSHIFT64_(opus_int64 a, opus_int64 shift, char *file, int line) { - if ((shift < 0) || (shift >= 64)) { - fprintf(stderr, "silk_RSHITF64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)shift, file, line); +static OPUS_INLINE opus_int64 silk_RSHIFT64_(opus_int64 a, opus_int64 shift, char *file, int line){ + if ( (shift < 0) || (shift>=64) ) + { + fprintf (stderr, "silk_RSHITF64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a >> shift; @@ -659,11 +693,12 @@ static OPUS_INLINE opus_int64 silk_RSHIFT64_(opus_int64 a, opus_int64 shift, cha #undef silk_RSHIFT_uint #define silk_RSHIFT_uint(a,b) silk_RSHIFT_uint_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_uint32 silk_RSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line) { - if ((shift < 0) || (shift > 32)) { - fprintf(stderr, "silk_RSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line); +static OPUS_INLINE opus_uint32 silk_RSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){ + if ( (shift < 0) || (shift>32) ) + { + fprintf (stderr, "silk_RSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return a >> shift; @@ -671,13 +706,14 @@ static OPUS_INLINE opus_uint32 silk_RSHIFT_uint_(opus_uint32 a, opus_int32 shift #undef silk_ADD_LSHIFT #define silk_ADD_LSHIFT(a,b,c) silk_ADD_LSHIFT_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE int silk_ADD_LSHIFT_(int a, int b, int shift, char *file, int line) { +static OPUS_INLINE int silk_ADD_LSHIFT_(int a, int b, int shift, char *file, int line){ opus_int16 ret; - ret = a + (b << shift); - if ((shift < 0) || (shift > 15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift))) { - fprintf(stderr, "silk_ADD_LSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); + ret = a + (opus_int16)((opus_uint16)b << shift); + if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (opus_int64)(((opus_uint64)b) << shift)) ) + { + fprintf (stderr, "silk_ADD_LSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift >= 0 */ @@ -685,13 +721,14 @@ static OPUS_INLINE int silk_ADD_LSHIFT_(int a, int b, int shift, char *file, int #undef silk_ADD_LSHIFT32 #define silk_ADD_LSHIFT32(a,b,c) silk_ADD_LSHIFT32_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){ opus_int32 ret; - ret = a + (b << shift); - if ((shift < 0) || (shift > 31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift))) { - fprintf(stderr, "silk_ADD_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); + ret = silk_ADD32_ovflw(a, (opus_int32)((opus_uint32)b << shift)); + if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (opus_int64)(((opus_uint64)b) << shift)) ) + { + fprintf (stderr, "silk_ADD_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift >= 0 */ @@ -699,13 +736,14 @@ static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32_(opus_int32 a, opus_int32 b, opu #undef silk_ADD_LSHIFT_uint #define silk_ADD_LSHIFT_uint(a,b,c) silk_ADD_LSHIFT_uint_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){ opus_uint32 ret; ret = a + (b << shift); - if ((shift < 0) || (shift > 32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift))) { - fprintf(stderr, "silk_ADD_LSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line); + if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) ) + { + fprintf (stderr, "silk_ADD_LSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift >= 0 */ @@ -713,13 +751,14 @@ static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint_(opus_uint32 a, opus_uint32 #undef silk_ADD_RSHIFT #define silk_ADD_RSHIFT(a,b,c) silk_ADD_RSHIFT_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE int silk_ADD_RSHIFT_(int a, int b, int shift, char *file, int line) { +static OPUS_INLINE int silk_ADD_RSHIFT_(int a, int b, int shift, char *file, int line){ opus_int16 ret; ret = a + (b >> shift); - if ((shift < 0) || (shift > 15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift))) { - fprintf(stderr, "silk_ADD_RSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); + if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) ) + { + fprintf (stderr, "silk_ADD_RSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift > 0 */ @@ -727,13 +766,14 @@ static OPUS_INLINE int silk_ADD_RSHIFT_(int a, int b, int shift, char *file, int #undef silk_ADD_RSHIFT32 #define silk_ADD_RSHIFT32(a,b,c) silk_ADD_RSHIFT32_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){ opus_int32 ret; - ret = a + (b >> shift); - if ((shift < 0) || (shift > 31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift))) { - fprintf(stderr, "silk_ADD_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); + ret = silk_ADD32_ovflw(a, (b >> shift)); + if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) ) + { + fprintf (stderr, "silk_ADD_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift > 0 */ @@ -741,13 +781,14 @@ static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32_(opus_int32 a, opus_int32 b, opu #undef silk_ADD_RSHIFT_uint #define silk_ADD_RSHIFT_uint(a,b,c) silk_ADD_RSHIFT_uint_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){ opus_uint32 ret; ret = a + (b >> shift); - if ((shift < 0) || (shift > 32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift))) { - fprintf(stderr, "silk_ADD_RSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line); + if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) ) + { + fprintf (stderr, "silk_ADD_RSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift > 0 */ @@ -755,13 +796,14 @@ static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint_(opus_uint32 a, opus_uint32 #undef silk_SUB_LSHIFT32 #define silk_SUB_LSHIFT32(a,b,c) silk_SUB_LSHIFT32_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){ opus_int32 ret; - ret = a - (b << shift); - if ((shift < 0) || (shift > 31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) << shift))) { - fprintf(stderr, "silk_SUB_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); + ret = silk_SUB32_ovflw(a, (opus_int32)((opus_uint32)b << shift)); + if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (opus_int64)(((opus_uint64)b) << shift)) ) + { + fprintf (stderr, "silk_SUB_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift >= 0 */ @@ -769,13 +811,14 @@ static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32_(opus_int32 a, opus_int32 b, opu #undef silk_SUB_RSHIFT32 #define silk_SUB_RSHIFT32(a,b,c) silk_SUB_RSHIFT32_((a), (b), (c), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){ opus_int32 ret; - ret = a - (b >> shift); - if ((shift < 0) || (shift > 31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) >> shift))) { - fprintf(stderr, "silk_SUB_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); + ret = silk_SUB32_ovflw(a, (b >> shift)); + if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) >> shift)) ) + { + fprintf (stderr, "silk_SUB_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; /* shift > 0 */ @@ -783,14 +826,15 @@ static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32_(opus_int32 a, opus_int32 b, opu #undef silk_RSHIFT_ROUND #define silk_RSHIFT_ROUND(a,b) silk_RSHIFT_ROUND_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND_(opus_int32 a, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND_(opus_int32 a, opus_int32 shift, char *file, int line){ opus_int32 ret; ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; - /* the marco definition can't handle a shift of zero */ - if ((shift <= 0) || (shift > 31) || ((opus_int64)ret != ((opus_int64)a + ((opus_int64)1 << (shift - 1))) >> shift)) { - fprintf(stderr, "silk_RSHIFT_ROUND(%d, %d) in %s: line %d\n", a, shift, file, line); + /* the macro definition can't handle a shift of zero */ + if ( (shift <= 0) || (shift>31) || ((opus_int64)ret != ((opus_int64)a + ((opus_int64)1 << (shift - 1))) >> shift) ) + { + fprintf (stderr, "silk_RSHIFT_ROUND(%d, %d) in %s: line %d\n", a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return ret; @@ -798,13 +842,14 @@ static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND_(opus_int32 a, opus_int32 shift, #undef silk_RSHIFT_ROUND64 #define silk_RSHIFT_ROUND64(a,b) silk_RSHIFT_ROUND64_((a), (b), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64_(opus_int64 a, opus_int32 shift, char *file, int line) { +static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64_(opus_int64 a, opus_int32 shift, char *file, int line){ opus_int64 ret; - /* the marco definition can't handle a shift of zero */ - if ((shift <= 0) || (shift >= 64)) { - fprintf(stderr, "silk_RSHIFT_ROUND64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line); + /* the macro definition can't handle a shift of zero */ + if ( (shift <= 0) || (shift>=64) ) + { + fprintf (stderr, "silk_RSHIFT_ROUND64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; @@ -812,19 +857,20 @@ static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64_(opus_int64 a, opus_int32 shif } /* silk_abs is used on floats also, so doesn't work... */ -/* #undef silk_abs - static OPUS_INLINE opus_int32 silk_abs(opus_int32 a){ +/*#undef silk_abs +static OPUS_INLINE opus_int32 silk_abs(opus_int32 a){ silk_assert(a != 0x80000000); return (((a) > 0) ? (a) : -(a)); // Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN - }*/ +}*/ #undef silk_abs_int64 #define silk_abs_int64(a) silk_abs_int64_((a), __FILE__, __LINE__) -static OPUS_INLINE opus_int64 silk_abs_int64_(opus_int64 a, char *file, int line) { - if (a == silk_int64_MIN) { - fprintf(stderr, "silk_abs_int64(%lld) in %s: line %d\n", (long long)a, file, line); +static OPUS_INLINE opus_int64 silk_abs_int64_(opus_int64 a, char *file, int line){ + if ( a == silk_int64_MIN ) + { + fprintf (stderr, "silk_abs_int64(%lld) in %s: line %d\n", (long long)a, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */ @@ -832,11 +878,12 @@ static OPUS_INLINE opus_int64 silk_abs_int64_(opus_int64 a, char *file, int line #undef silk_abs_int32 #define silk_abs_int32(a) silk_abs_int32_((a), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_abs_int32_(opus_int32 a, char *file, int line) { - if (a == silk_int32_MIN) { - fprintf(stderr, "silk_abs_int32(%d) in %s: line %d\n", a, file, line); +static OPUS_INLINE opus_int32 silk_abs_int32_(opus_int32 a, char *file, int line){ + if ( a == silk_int32_MIN ) + { + fprintf (stderr, "silk_abs_int32(%d) in %s: line %d\n", a, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } return silk_abs(a); @@ -844,51 +891,54 @@ static OPUS_INLINE opus_int32 silk_abs_int32_(opus_int32 a, char *file, int line #undef silk_CHECK_FIT8 #define silk_CHECK_FIT8(a) silk_CHECK_FIT8_((a), __FILE__, __LINE__) -static OPUS_INLINE opus_int8 silk_CHECK_FIT8_(opus_int64 a, char *file, int line) { +static OPUS_INLINE opus_int8 silk_CHECK_FIT8_( opus_int64 a, char *file, int line ){ opus_int8 ret; ret = (opus_int8)a; - if ((opus_int64)ret != a) { - fprintf(stderr, "silk_CHECK_FIT8(%lld) in %s: line %d\n", (long long)a, file, line); + if ( (opus_int64)ret != a ) + { + fprintf (stderr, "silk_CHECK_FIT8(%lld) in %s: line %d\n", (long long)a, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } - return (ret); + return( ret ); } #undef silk_CHECK_FIT16 #define silk_CHECK_FIT16(a) silk_CHECK_FIT16_((a), __FILE__, __LINE__) -static OPUS_INLINE opus_int16 silk_CHECK_FIT16_(opus_int64 a, char *file, int line) { +static OPUS_INLINE opus_int16 silk_CHECK_FIT16_( opus_int64 a, char *file, int line ){ opus_int16 ret; ret = (opus_int16)a; - if ((opus_int64)ret != a) { - fprintf(stderr, "silk_CHECK_FIT16(%lld) in %s: line %d\n", (long long)a, file, line); + if ( (opus_int64)ret != a ) + { + fprintf (stderr, "silk_CHECK_FIT16(%lld) in %s: line %d\n", (long long)a, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } - return (ret); + return( ret ); } #undef silk_CHECK_FIT32 #define silk_CHECK_FIT32(a) silk_CHECK_FIT32_((a), __FILE__, __LINE__) -static OPUS_INLINE opus_int32 silk_CHECK_FIT32_(opus_int64 a, char *file, int line) { +static OPUS_INLINE opus_int32 silk_CHECK_FIT32_( opus_int64 a, char *file, int line ){ opus_int32 ret; ret = (opus_int32)a; - if ((opus_int64)ret != a) { - fprintf(stderr, "silk_CHECK_FIT32(%lld) in %s: line %d\n", (long long)a, file, line); + if ( (opus_int64)ret != a ) + { + fprintf (stderr, "silk_CHECK_FIT32(%lld) in %s: line %d\n", (long long)a, file, line); #ifdef FIXED_DEBUG_ASSERT - silk_assert(0); + silk_assert( 0 ); #endif } - return (ret); + return( ret ); } -/* no checking for silk_NSHIFT_MUL_32_32 - no checking for silk_NSHIFT_MUL_16_16 - no checking needed for silk_min - no checking needed for silk_max - no checking needed for silk_sign +/* no checking for silk_NSHIFT_MUL_32_32 + no checking for silk_NSHIFT_MUL_16_16 + no checking needed for silk_min + no checking needed for silk_max + no checking needed for silk_sign */ #endif diff --git a/src/libopus/silk/NLSF2A.c b/src/libopus/silk/NLSF2A.c index fc981f0..a2c15b9 100644 --- a/src/libopus/silk/NLSF2A.c +++ b/src/libopus/silk/NLSF2A.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif /* conversion between prediction filter coefficients and LSFs */ /* order should be even */ @@ -45,102 +45,97 @@ static OPUS_INLINE void silk_NLSF2A_find_poly( opus_int32 *out, /* O intermediate polynomial, QA [dd+1] */ const opus_int32 *cLSF, /* I vector of interleaved 2*cos(LSFs), QA [d] */ opus_int dd /* I polynomial order (= 1/2 * filter order) */ -) { +) +{ opus_int k, n; opus_int32 ftmp; - out[0] = silk_LSHIFT(1, QA); + out[0] = silk_LSHIFT( 1, QA ); out[1] = -cLSF[0]; - for (k = 1; k < dd; k++) { - ftmp = cLSF[2 * k]; /* QA*/ - out[k + 1] = silk_LSHIFT(out[k - 1], 1) - (opus_int32)silk_RSHIFT_ROUND64(silk_SMULL(ftmp, out[k]), QA); - for (n = k; n > 1; n--) { - out[n] += out[n - 2] - (opus_int32)silk_RSHIFT_ROUND64(silk_SMULL(ftmp, out[n - 1]), QA); + for( k = 1; k < dd; k++ ) { + ftmp = cLSF[2*k]; /* QA*/ + out[k+1] = silk_LSHIFT( out[k-1], 1 ) - (opus_int32)silk_RSHIFT_ROUND64( silk_SMULL( ftmp, out[k] ), QA ); + for( n = k; n > 1; n-- ) { + out[n] += out[n-2] - (opus_int32)silk_RSHIFT_ROUND64( silk_SMULL( ftmp, out[n-1] ), QA ); } out[1] -= ftmp; } } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" /* compute whitening filter coefficients from normalized line spectral frequencies */ void silk_NLSF2A( opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */ const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */ const opus_int d, /* I filter order (should be even) */ int arch /* I Run-time architecture */ -) { - /* This ordering was found to maximize quality. It improves numerical accuracy of - silk_NLSF2A_find_poly() compared to "standard" ordering. */ +) +{ + /* This ordering was found to maximize quality. It improves numerical accuracy of + silk_NLSF2A_find_poly() compared to "standard" ordering. */ static const unsigned char ordering16[16] = { - 0, 15, 8, 7, 4, 11, 12, 3, 2, 13, 10, 5, 6, 9, 14, 1 + 0, 15, 8, 7, 4, 11, 12, 3, 2, 13, 10, 5, 6, 9, 14, 1 }; static const unsigned char ordering10[10] = { - 0, 9, 6, 3, 4, 5, 8, 1, 2, 7 + 0, 9, 6, 3, 4, 5, 8, 1, 2, 7 }; const unsigned char *ordering; opus_int k, i, dd; - opus_int32 *cos_LSF_QA = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC); - opus_int32 *P = (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC / 2 + 1)); - opus_int32 *Q = (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC / 2 + 1)); + opus_int32 cos_LSF_QA[ SILK_MAX_ORDER_LPC ]; + opus_int32 P[ SILK_MAX_ORDER_LPC / 2 + 1 ], Q[ SILK_MAX_ORDER_LPC / 2 + 1 ]; opus_int32 Ptmp, Qtmp, f_int, f_frac, cos_val, delta; - opus_int32 *a32_QA1 = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC); + opus_int32 a32_QA1[ SILK_MAX_ORDER_LPC ]; - silk_assert(LSF_COS_TAB_SZ_FIX == 128); - celt_assert(d == 10 || d == 16); + silk_assert( LSF_COS_TAB_SZ_FIX == 128 ); + celt_assert( d==10 || d==16 ); /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */ ordering = d == 16 ? ordering16 : ordering10; - for (k = 0; k < d; k++) { - silk_assert(NLSF[k] >= 0); + for( k = 0; k < d; k++ ) { + silk_assert( NLSF[k] >= 0 ); /* f_int on a scale 0-127 (rounded down) */ - f_int = silk_RSHIFT(NLSF[k], 15 - 7); + f_int = silk_RSHIFT( NLSF[k], 15 - 7 ); /* f_frac, range: 0..255 */ - f_frac = NLSF[k] - silk_LSHIFT(f_int, 15 - 7); + f_frac = NLSF[k] - silk_LSHIFT( f_int, 15 - 7 ); silk_assert(f_int >= 0); - silk_assert(f_int < LSF_COS_TAB_SZ_FIX); + silk_assert(f_int < LSF_COS_TAB_SZ_FIX ); /* Read start and end value from table */ cos_val = silk_LSFCosTab_FIX_Q12[ f_int ]; /* Q12 */ delta = silk_LSFCosTab_FIX_Q12[ f_int + 1 ] - cos_val; /* Q12, with a range of 0..200 */ /* Linear interpolation */ - cos_LSF_QA[ordering[k]] = silk_RSHIFT_ROUND(silk_LSHIFT(cos_val, 8) + silk_MUL(delta, f_frac), 20 - QA); /* QA */ + cos_LSF_QA[ordering[k]] = silk_RSHIFT_ROUND( silk_LSHIFT( cos_val, 8 ) + silk_MUL( delta, f_frac ), 20 - QA ); /* QA */ } - dd = silk_RSHIFT(d, 1); + dd = silk_RSHIFT( d, 1 ); /* generate even and odd polynomials using convolution */ - silk_NLSF2A_find_poly(P, &cos_LSF_QA[ 0 ], dd); - silk_NLSF2A_find_poly(Q, &cos_LSF_QA[ 1 ], dd); + silk_NLSF2A_find_poly( P, &cos_LSF_QA[ 0 ], dd ); + silk_NLSF2A_find_poly( Q, &cos_LSF_QA[ 1 ], dd ); /* convert even and odd polynomials to opus_int32 Q12 filter coefs */ - for (k = 0; k < dd; k++) { - Ptmp = P[ k + 1 ] + P[ k ]; - Qtmp = Q[ k + 1 ] - Q[ k ]; + for( k = 0; k < dd; k++ ) { + Ptmp = P[ k+1 ] + P[ k ]; + Qtmp = Q[ k+1 ] - Q[ k ]; /* the Ptmp and Qtmp values at this stage need to fit in int32 */ a32_QA1[ k ] = -Qtmp - Ptmp; /* QA+1 */ - a32_QA1[ d - k - 1 ] = Qtmp - Ptmp; /* QA+1 */ + a32_QA1[ d-k-1 ] = Qtmp - Ptmp; /* QA+1 */ } /* Convert int32 coefficients to Q12 int16 coefs */ - silk_LPC_fit(a_Q12, a32_QA1, 12, QA + 1, d); + silk_LPC_fit( a_Q12, a32_QA1, 12, QA + 1, d ); - for (i = 0; silk_LPC_inverse_pred_gain(a_Q12, d, arch) == 0 && i < MAX_LPC_STABILIZE_ITERATIONS; i++) { + for( i = 0; silk_LPC_inverse_pred_gain( a_Q12, d, arch ) == 0 && i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) { /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */ /* on the unscaled coefficients, convert to Q12 and measure again */ - silk_bwexpander_32(a32_QA1, d, 65536 - silk_LSHIFT(2, i)); - for (k = 0; k < d; k++) { - a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND(a32_QA1[ k ], QA + 1 - 12); /* QA+1 -> Q12 */ + silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) ); + for( k = 0; k < d; k++ ) { + a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */ } } - free(cos_LSF_QA); - free(P); - free(Q); - free(a32_QA1); } -#pragma GCC diagnostic pop + diff --git a/src/libopus/silk/NLSF_VQ.c b/src/libopus/silk/NLSF_VQ.c index cb54050..81f30e7 100644 --- a/src/libopus/silk/NLSF_VQ.c +++ b/src/libopus/silk/NLSF_VQ.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -39,34 +39,35 @@ void silk_NLSF_VQ( const opus_int16 pWght_Q9[], /* I Codebook weights [K*LPC_order] */ const opus_int K, /* I Number of codebook vectors */ const opus_int LPC_order /* I Number of LPCs */ -) { +) +{ opus_int i, m; opus_int32 diff_Q15, diffw_Q24, sum_error_Q24, pred_Q24; const opus_int16 *w_Q9_ptr; const opus_uint8 *cb_Q8_ptr; - celt_assert((LPC_order & 1) == 0); + celt_assert( ( LPC_order & 1 ) == 0 ); /* Loop over codebook */ cb_Q8_ptr = pCB_Q8; w_Q9_ptr = pWght_Q9; - for (i = 0; i < K; i++) { + for( i = 0; i < K; i++ ) { sum_error_Q24 = 0; pred_Q24 = 0; - for (m = LPC_order - 2; m >= 0; m -= 2) { + for( m = LPC_order-2; m >= 0; m -= 2 ) { /* Compute weighted absolute predictive quantization error for index m + 1 */ - diff_Q15 = silk_SUB_LSHIFT32(in_Q15[ m + 1 ], (opus_int32)cb_Q8_ptr[ m + 1 ], 7); /* range: [ -32767 : 32767 ]*/ - diffw_Q24 = silk_SMULBB(diff_Q15, w_Q9_ptr[ m + 1 ]); - sum_error_Q24 = silk_ADD32(sum_error_Q24, silk_abs(silk_SUB_RSHIFT32(diffw_Q24, pred_Q24, 1))); + diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m + 1 ], (opus_int32)cb_Q8_ptr[ m + 1 ], 7 ); /* range: [ -32767 : 32767 ]*/ + diffw_Q24 = silk_SMULBB( diff_Q15, w_Q9_ptr[ m + 1 ] ); + sum_error_Q24 = silk_ADD32( sum_error_Q24, silk_abs( silk_SUB_RSHIFT32( diffw_Q24, pred_Q24, 1 ) ) ); pred_Q24 = diffw_Q24; /* Compute weighted absolute predictive quantization error for index m */ - diff_Q15 = silk_SUB_LSHIFT32(in_Q15[ m ], (opus_int32)cb_Q8_ptr[ m ], 7); /* range: [ -32767 : 32767 ]*/ - diffw_Q24 = silk_SMULBB(diff_Q15, w_Q9_ptr[ m ]); - sum_error_Q24 = silk_ADD32(sum_error_Q24, silk_abs(silk_SUB_RSHIFT32(diffw_Q24, pred_Q24, 1))); + diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m ], (opus_int32)cb_Q8_ptr[ m ], 7 ); /* range: [ -32767 : 32767 ]*/ + diffw_Q24 = silk_SMULBB( diff_Q15, w_Q9_ptr[ m ] ); + sum_error_Q24 = silk_ADD32( sum_error_Q24, silk_abs( silk_SUB_RSHIFT32( diffw_Q24, pred_Q24, 1 ) ) ); pred_Q24 = diffw_Q24; - silk_assert(sum_error_Q24 >= 0); + silk_assert( sum_error_Q24 >= 0 ); } err_Q24[ i ] = sum_error_Q24; cb_Q8_ptr += LPC_order; diff --git a/src/libopus/silk/NLSF_VQ_weights_laroia.c b/src/libopus/silk/NLSF_VQ_weights_laroia.c index f99d400..86cdc5c 100644 --- a/src/libopus/silk/NLSF_VQ_weights_laroia.c +++ b/src/libopus/silk/NLSF_VQ_weights_laroia.c @@ -1,41 +1,41 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "define.h" #include "SigProc_FIX.h" /* - R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP - Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech, - Signal Processing, pp. 641-644, 1991. +R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP +Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech, +Signal Processing, pp. 641-644, 1991. */ /* Laroia low complexity NLSF weights */ @@ -43,37 +43,38 @@ void silk_NLSF_VQ_weights_laroia( opus_int16 *pNLSFW_Q_OUT, /* O Pointer to input vector weights [D] */ const opus_int16 *pNLSF_Q15, /* I Pointer to input vector [D] */ const opus_int D /* I Input vector dimension (even) */ -) { +) +{ opus_int k; opus_int32 tmp1_int, tmp2_int; - celt_assert(D > 0); - celt_assert((D & 1) == 0); + celt_assert( D > 0 ); + celt_assert( ( D & 1 ) == 0 ); /* First value */ - tmp1_int = silk_max_int(pNLSF_Q15[ 0 ], 1); - tmp1_int = silk_DIV32_16((opus_int32)1 << (15 + NLSF_W_Q), tmp1_int); - tmp2_int = silk_max_int(pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], 1); - tmp2_int = silk_DIV32_16((opus_int32)1 << (15 + NLSF_W_Q), tmp2_int); - pNLSFW_Q_OUT[ 0 ] = (opus_int16)silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX); - silk_assert(pNLSFW_Q_OUT[ 0 ] > 0); + tmp1_int = silk_max_int( pNLSF_Q15[ 0 ], 1 ); + tmp1_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp1_int ); + tmp2_int = silk_max_int( pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], 1 ); + tmp2_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp2_int ); + pNLSFW_Q_OUT[ 0 ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX ); + silk_assert( pNLSFW_Q_OUT[ 0 ] > 0 ); /* Main loop */ - for (k = 1; k < D - 1; k += 2) { - tmp1_int = silk_max_int(pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], 1); - tmp1_int = silk_DIV32_16((opus_int32)1 << (15 + NLSF_W_Q), tmp1_int); - pNLSFW_Q_OUT[ k ] = (opus_int16)silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX); - silk_assert(pNLSFW_Q_OUT[ k ] > 0); + for( k = 1; k < D - 1; k += 2 ) { + tmp1_int = silk_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], 1 ); + tmp1_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp1_int ); + pNLSFW_Q_OUT[ k ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX ); + silk_assert( pNLSFW_Q_OUT[ k ] > 0 ); - tmp2_int = silk_max_int(pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], 1); - tmp2_int = silk_DIV32_16((opus_int32)1 << (15 + NLSF_W_Q), tmp2_int); - pNLSFW_Q_OUT[ k + 1 ] = (opus_int16)silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX); - silk_assert(pNLSFW_Q_OUT[ k + 1 ] > 0); + tmp2_int = silk_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], 1 ); + tmp2_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp2_int ); + pNLSFW_Q_OUT[ k + 1 ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX ); + silk_assert( pNLSFW_Q_OUT[ k + 1 ] > 0 ); } /* Last value */ - tmp1_int = silk_max_int((1 << 15) - pNLSF_Q15[ D - 1 ], 1); - tmp1_int = silk_DIV32_16((opus_int32)1 << (15 + NLSF_W_Q), tmp1_int); - pNLSFW_Q_OUT[ D - 1 ] = (opus_int16)silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX); - silk_assert(pNLSFW_Q_OUT[ D - 1 ] > 0); + tmp1_int = silk_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], 1 ); + tmp1_int = silk_DIV32_16( (opus_int32)1 << ( 15 + NLSF_W_Q ), tmp1_int ); + pNLSFW_Q_OUT[ D - 1 ] = (opus_int16)silk_min_int( tmp1_int + tmp2_int, silk_int16_MAX ); + silk_assert( pNLSFW_Q_OUT[ D - 1 ] > 0 ); } diff --git a/src/libopus/silk/NLSF_decode.c b/src/libopus/silk/NLSF_decode.c index 3c5cc18..f4d10fc 100644 --- a/src/libopus/silk/NLSF_decode.c +++ b/src/libopus/silk/NLSF_decode.c @@ -1,56 +1,57 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" /* Predictive dequantizer for NLSF residuals */ static OPUS_INLINE void silk_NLSF_residual_dequant( /* O Returns RD value in Q30 */ - opus_int16 x_Q10[], /* O Output [ order ] */ + opus_int16 x_Q10[], /* O Output [ order ] */ const opus_int8 indices[], /* I Quantization indices [ order ] */ const opus_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */ const opus_int quant_step_size_Q16, /* I Quantization step size */ const opus_int16 order /* I Number of input values */ -) { +) +{ opus_int i, out_Q10, pred_Q10; out_Q10 = 0; - for (i = order - 1; i >= 0; i--) { - pred_Q10 = silk_RSHIFT(silk_SMULBB(out_Q10, (opus_int16)pred_coef_Q8[ i ]), 8); - out_Q10 = silk_LSHIFT(indices[ i ], 10); - if (out_Q10 > 0) { - out_Q10 = silk_SUB16(out_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); - } else if (out_Q10 < 0) { - out_Q10 = silk_ADD16(out_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); + for( i = order-1; i >= 0; i-- ) { + pred_Q10 = silk_RSHIFT( silk_SMULBB( out_Q10, (opus_int16)pred_coef_Q8[ i ] ), 8 ); + out_Q10 = silk_LSHIFT( indices[ i ], 10 ); + if( out_Q10 > 0 ) { + out_Q10 = silk_SUB16( out_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); + } else if( out_Q10 < 0 ) { + out_Q10 = silk_ADD16( out_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); } - out_Q10 = silk_SMLAWB(pred_Q10, (opus_int32)out_Q10, quant_step_size_Q16); + out_Q10 = silk_SMLAWB( pred_Q10, (opus_int32)out_Q10, quant_step_size_Q16 ); x_Q10[ i ] = out_Q10; } } @@ -60,10 +61,11 @@ static OPUS_INLINE void silk_NLSF_residual_dequant( /* O Returns RD /* NLSF vector decoder */ /***********************/ void silk_NLSF_decode( - opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */ - opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ + opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */ + opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */ -) { +) +{ opus_int i; opus_uint8 pred_Q8[ MAX_LPC_ORDER ]; opus_int16 ec_ix[ MAX_LPC_ORDER ]; @@ -73,19 +75,19 @@ void silk_NLSF_decode( const opus_int16 *pCB_Wght_Q9; /* Unpack entropy table indices and predictor for current CB1 index */ - silk_NLSF_unpack(ec_ix, pred_Q8, psNLSF_CB, NLSFIndices[ 0 ]); + silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, NLSFIndices[ 0 ] ); /* Predictive residual dequantizer */ - silk_NLSF_residual_dequant(res_Q10, &NLSFIndices[ 1 ], pred_Q8, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->order); + silk_NLSF_residual_dequant( res_Q10, &NLSFIndices[ 1 ], pred_Q8, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->order ); /* Apply inverse square-rooted weights to first stage and add to output */ pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ]; pCB_Wght_Q9 = &psNLSF_CB->CB1_Wght_Q9[ NLSFIndices[ 0 ] * psNLSF_CB->order ]; - for (i = 0; i < psNLSF_CB->order; i++) { - NLSF_Q15_tmp = silk_ADD_LSHIFT32(silk_DIV32_16(silk_LSHIFT((opus_int32)res_Q10[ i ], 14), pCB_Wght_Q9[ i ]), (opus_int16)pCB_element[ i ], 7); - pNLSF_Q15[ i ] = (opus_int16)silk_LIMIT(NLSF_Q15_tmp, 0, 32767); + for( i = 0; i < psNLSF_CB->order; i++ ) { + NLSF_Q15_tmp = silk_ADD_LSHIFT32( silk_DIV32_16( silk_LSHIFT( (opus_int32)res_Q10[ i ], 14 ), pCB_Wght_Q9[ i ] ), (opus_int16)pCB_element[ i ], 7 ); + pNLSF_Q15[ i ] = (opus_int16)silk_LIMIT( NLSF_Q15_tmp, 0, 32767 ); } /* NLSF stabilization */ - silk_NLSF_stabilize(pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order); + silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order ); } diff --git a/src/libopus/silk/NLSF_del_dec_quant.c b/src/libopus/silk/NLSF_del_dec_quant.c index f5a5cf4..728aa81 100644 --- a/src/libopus/silk/NLSF_del_dec_quant.c +++ b/src/libopus/silk/NLSF_del_dec_quant.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -43,7 +43,8 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns const opus_int16 inv_quant_step_size_Q6, /* I Inverse quantization step size */ const opus_int32 mu_Q20, /* I R/D tradeoff */ const opus_int16 order /* I Number of input values */ -) { +) +{ opus_int i, j, nStates, ind_tmp, ind_min_max, ind_max_min, in_Q10, res_Q10; opus_int pred_Q10, diff_Q10, rate0_Q5, rate1_Q5; opus_int16 out0_Q10, out1_Q10; @@ -59,89 +60,90 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns opus_int out0_Q10_table[2 * NLSF_QUANT_MAX_AMPLITUDE_EXT]; opus_int out1_Q10_table[2 * NLSF_QUANT_MAX_AMPLITUDE_EXT]; - for (i = -NLSF_QUANT_MAX_AMPLITUDE_EXT; i <= NLSF_QUANT_MAX_AMPLITUDE_EXT - 1; i++) { - out0_Q10 = silk_LSHIFT(i, 10); - out1_Q10 = silk_ADD16(out0_Q10, 1024); - if (i > 0) { - out0_Q10 = silk_SUB16(out0_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); - out1_Q10 = silk_SUB16(out1_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); - } else if (i == 0) { - out1_Q10 = silk_SUB16(out1_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); - } else if (i == -1) { - out0_Q10 = silk_ADD16(out0_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); + for (i = -NLSF_QUANT_MAX_AMPLITUDE_EXT; i <= NLSF_QUANT_MAX_AMPLITUDE_EXT-1; i++) + { + out0_Q10 = silk_LSHIFT( i, 10 ); + out1_Q10 = silk_ADD16( out0_Q10, 1024 ); + if( i > 0 ) { + out0_Q10 = silk_SUB16( out0_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); + out1_Q10 = silk_SUB16( out1_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); + } else if( i == 0 ) { + out1_Q10 = silk_SUB16( out1_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); + } else if( i == -1 ) { + out0_Q10 = silk_ADD16( out0_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); } else { - out0_Q10 = silk_ADD16(out0_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); - out1_Q10 = silk_ADD16(out1_Q10, SILK_FIX_CONST(NLSF_QUANT_LEVEL_ADJ, 10)); + out0_Q10 = silk_ADD16( out0_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); + out1_Q10 = silk_ADD16( out1_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) ); } - out0_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_RSHIFT(silk_SMULBB(out0_Q10, quant_step_size_Q16), 16); - out1_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_RSHIFT(silk_SMULBB(out1_Q10, quant_step_size_Q16), 16); + out0_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_RSHIFT( silk_SMULBB( out0_Q10, quant_step_size_Q16 ), 16 ); + out1_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_RSHIFT( silk_SMULBB( out1_Q10, quant_step_size_Q16 ), 16 ); } - silk_assert((NLSF_QUANT_DEL_DEC_STATES & (NLSF_QUANT_DEL_DEC_STATES - 1)) == 0); /* must be power of two */ + silk_assert( (NLSF_QUANT_DEL_DEC_STATES & (NLSF_QUANT_DEL_DEC_STATES-1)) == 0 ); /* must be power of two */ nStates = 1; RD_Q25[ 0 ] = 0; prev_out_Q10[ 0 ] = 0; - for (i = order - 1; i >= 0; i--) { + for( i = order - 1; i >= 0; i-- ) { rates_Q5 = &ec_rates_Q5[ ec_ix[ i ] ]; in_Q10 = x_Q10[ i ]; - for (j = 0; j < nStates; j++) { - pred_Q10 = silk_RSHIFT(silk_SMULBB((opus_int16)pred_coef_Q8[ i ], prev_out_Q10[ j ]), 8); - res_Q10 = silk_SUB16(in_Q10, pred_Q10); - ind_tmp = silk_RSHIFT(silk_SMULBB(inv_quant_step_size_Q6, res_Q10), 16); - ind_tmp = silk_LIMIT(ind_tmp, -NLSF_QUANT_MAX_AMPLITUDE_EXT, NLSF_QUANT_MAX_AMPLITUDE_EXT - 1); + for( j = 0; j < nStates; j++ ) { + pred_Q10 = silk_RSHIFT( silk_SMULBB( (opus_int16)pred_coef_Q8[ i ], prev_out_Q10[ j ] ), 8 ); + res_Q10 = silk_SUB16( in_Q10, pred_Q10 ); + ind_tmp = silk_RSHIFT( silk_SMULBB( inv_quant_step_size_Q6, res_Q10 ), 16 ); + ind_tmp = silk_LIMIT( ind_tmp, -NLSF_QUANT_MAX_AMPLITUDE_EXT, NLSF_QUANT_MAX_AMPLITUDE_EXT-1 ); ind[ j ][ i ] = (opus_int8)ind_tmp; /* compute outputs for ind_tmp and ind_tmp + 1 */ out0_Q10 = out0_Q10_table[ ind_tmp + NLSF_QUANT_MAX_AMPLITUDE_EXT ]; out1_Q10 = out1_Q10_table[ ind_tmp + NLSF_QUANT_MAX_AMPLITUDE_EXT ]; - out0_Q10 = silk_ADD16(out0_Q10, pred_Q10); - out1_Q10 = silk_ADD16(out1_Q10, pred_Q10); + out0_Q10 = silk_ADD16( out0_Q10, pred_Q10 ); + out1_Q10 = silk_ADD16( out1_Q10, pred_Q10 ); prev_out_Q10[ j ] = out0_Q10; prev_out_Q10[ j + nStates ] = out1_Q10; /* compute RD for ind_tmp and ind_tmp + 1 */ - if (ind_tmp + 1 >= NLSF_QUANT_MAX_AMPLITUDE) { - if (ind_tmp + 1 == NLSF_QUANT_MAX_AMPLITUDE) { + if( ind_tmp + 1 >= NLSF_QUANT_MAX_AMPLITUDE ) { + if( ind_tmp + 1 == NLSF_QUANT_MAX_AMPLITUDE ) { rate0_Q5 = rates_Q5[ ind_tmp + NLSF_QUANT_MAX_AMPLITUDE ]; rate1_Q5 = 280; } else { - rate0_Q5 = silk_SMLABB(280 - 43 * NLSF_QUANT_MAX_AMPLITUDE, 43, ind_tmp); - rate1_Q5 = silk_ADD16(rate0_Q5, 43); + rate0_Q5 = silk_SMLABB( 280 - 43 * NLSF_QUANT_MAX_AMPLITUDE, 43, ind_tmp ); + rate1_Q5 = silk_ADD16( rate0_Q5, 43 ); } - } else if (ind_tmp <= -NLSF_QUANT_MAX_AMPLITUDE) { - if (ind_tmp == -NLSF_QUANT_MAX_AMPLITUDE) { + } else if( ind_tmp <= -NLSF_QUANT_MAX_AMPLITUDE ) { + if( ind_tmp == -NLSF_QUANT_MAX_AMPLITUDE ) { rate0_Q5 = 280; rate1_Q5 = rates_Q5[ ind_tmp + 1 + NLSF_QUANT_MAX_AMPLITUDE ]; } else { - rate0_Q5 = silk_SMLABB(280 - 43 * NLSF_QUANT_MAX_AMPLITUDE, -43, ind_tmp); - rate1_Q5 = silk_SUB16(rate0_Q5, 43); + rate0_Q5 = silk_SMLABB( 280 - 43 * NLSF_QUANT_MAX_AMPLITUDE, -43, ind_tmp ); + rate1_Q5 = silk_SUB16( rate0_Q5, 43 ); } } else { rate0_Q5 = rates_Q5[ ind_tmp + NLSF_QUANT_MAX_AMPLITUDE ]; rate1_Q5 = rates_Q5[ ind_tmp + 1 + NLSF_QUANT_MAX_AMPLITUDE ]; } RD_tmp_Q25 = RD_Q25[ j ]; - diff_Q10 = silk_SUB16(in_Q10, out0_Q10); - RD_Q25[ j ] = silk_SMLABB(silk_MLA(RD_tmp_Q25, silk_SMULBB(diff_Q10, diff_Q10), w_Q5[ i ]), mu_Q20, rate0_Q5); - diff_Q10 = silk_SUB16(in_Q10, out1_Q10); - RD_Q25[ j + nStates ] = silk_SMLABB(silk_MLA(RD_tmp_Q25, silk_SMULBB(diff_Q10, diff_Q10), w_Q5[ i ]), mu_Q20, rate1_Q5); + diff_Q10 = silk_SUB16( in_Q10, out0_Q10 ); + RD_Q25[ j ] = silk_SMLABB( silk_MLA( RD_tmp_Q25, silk_SMULBB( diff_Q10, diff_Q10 ), w_Q5[ i ] ), mu_Q20, rate0_Q5 ); + diff_Q10 = silk_SUB16( in_Q10, out1_Q10 ); + RD_Q25[ j + nStates ] = silk_SMLABB( silk_MLA( RD_tmp_Q25, silk_SMULBB( diff_Q10, diff_Q10 ), w_Q5[ i ] ), mu_Q20, rate1_Q5 ); } - if (nStates <= NLSF_QUANT_DEL_DEC_STATES / 2) { + if( nStates <= NLSF_QUANT_DEL_DEC_STATES/2 ) { /* double number of states and copy */ - for (j = 0; j < nStates; j++) { + for( j = 0; j < nStates; j++ ) { ind[ j + nStates ][ i ] = ind[ j ][ i ] + 1; } - nStates = silk_LSHIFT(nStates, 1); - for (j = nStates; j < NLSF_QUANT_DEL_DEC_STATES; j++) { + nStates = silk_LSHIFT( nStates, 1 ); + for( j = nStates; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) { ind[ j ][ i ] = ind[ j - nStates ][ i ]; } } else { /* sort lower and upper half of RD_Q25, pairwise */ - for (j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++) { - if (RD_Q25[ j ] > RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ]) { + for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) { + if( RD_Q25[ j ] > RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ] ) { RD_max_Q25[ j ] = RD_Q25[ j ]; RD_min_Q25[ j ] = RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ]; RD_Q25[ j ] = RD_min_Q25[ j ]; @@ -159,22 +161,22 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns } /* compare the highest RD values of the winning half with the lowest one in the losing half, and copy if necessary */ /* afterwards ind_sort[] will contain the indices of the NLSF_QUANT_DEL_DEC_STATES winning RD values */ - while (1) { + while( 1 ) { min_max_Q25 = silk_int32_MAX; max_min_Q25 = 0; ind_min_max = 0; ind_max_min = 0; - for (j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++) { - if (min_max_Q25 > RD_max_Q25[ j ]) { + for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) { + if( min_max_Q25 > RD_max_Q25[ j ] ) { min_max_Q25 = RD_max_Q25[ j ]; ind_min_max = j; } - if (max_min_Q25 < RD_min_Q25[ j ]) { + if( max_min_Q25 < RD_min_Q25[ j ] ) { max_min_Q25 = RD_min_Q25[ j ]; ind_max_min = j; } } - if (min_max_Q25 >= max_min_Q25) { + if( min_max_Q25 >= max_min_Q25 ) { break; } /* copy ind_min_max to ind_max_min */ @@ -183,11 +185,11 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns prev_out_Q10[ ind_max_min ] = prev_out_Q10[ ind_min_max + NLSF_QUANT_DEL_DEC_STATES ]; RD_min_Q25[ ind_max_min ] = 0; RD_max_Q25[ ind_min_max ] = silk_int32_MAX; - silk_memcpy(ind[ ind_max_min ], ind[ ind_min_max ], MAX_LPC_ORDER * sizeof(opus_int8)); + silk_memcpy( ind[ ind_max_min ], ind[ ind_min_max ], MAX_LPC_ORDER * sizeof( opus_int8 ) ); } /* increment index if it comes from the upper half */ - for (j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++) { - ind[ j ][ i ] += silk_RSHIFT(ind_sort[ j ], NLSF_QUANT_DEL_DEC_STATES_LOG2); + for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) { + ind[ j ][ i ] += silk_RSHIFT( ind_sort[ j ], NLSF_QUANT_DEL_DEC_STATES_LOG2 ); } } } @@ -195,19 +197,19 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns /* last sample: find winner, copy indices and return RD value */ ind_tmp = 0; min_Q25 = silk_int32_MAX; - for (j = 0; j < 2 * NLSF_QUANT_DEL_DEC_STATES; j++) { - if (min_Q25 > RD_Q25[ j ]) { + for( j = 0; j < 2 * NLSF_QUANT_DEL_DEC_STATES; j++ ) { + if( min_Q25 > RD_Q25[ j ] ) { min_Q25 = RD_Q25[ j ]; ind_tmp = j; } } - for (j = 0; j < order; j++) { - indices[ j ] = ind[ ind_tmp & (NLSF_QUANT_DEL_DEC_STATES - 1) ][ j ]; - silk_assert(indices[ j ] >= -NLSF_QUANT_MAX_AMPLITUDE_EXT); - silk_assert(indices[ j ] <= NLSF_QUANT_MAX_AMPLITUDE_EXT); + for( j = 0; j < order; j++ ) { + indices[ j ] = ind[ ind_tmp & ( NLSF_QUANT_DEL_DEC_STATES - 1 ) ][ j ]; + silk_assert( indices[ j ] >= -NLSF_QUANT_MAX_AMPLITUDE_EXT ); + silk_assert( indices[ j ] <= NLSF_QUANT_MAX_AMPLITUDE_EXT ); } - indices[ 0 ] += silk_RSHIFT(ind_tmp, NLSF_QUANT_DEL_DEC_STATES_LOG2); - silk_assert(indices[ 0 ] <= NLSF_QUANT_MAX_AMPLITUDE_EXT); - silk_assert(min_Q25 >= 0); + indices[ 0 ] += silk_RSHIFT( ind_tmp, NLSF_QUANT_DEL_DEC_STATES_LOG2 ); + silk_assert( indices[ 0 ] <= NLSF_QUANT_MAX_AMPLITUDE_EXT ); + silk_assert( min_Q25 >= 0 ); return min_Q25; } diff --git a/src/libopus/silk/NLSF_encode.c b/src/libopus/silk/NLSF_encode.c index f98468f..01aadd0 100644 --- a/src/libopus/silk/NLSF_encode.c +++ b/src/libopus/silk/NLSF_encode.c @@ -1,55 +1,56 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" /***********************/ /* NLSF vector encoder */ /***********************/ opus_int32 silk_NLSF_encode( /* O Returns RD value in Q25 */ - opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ - opus_int16 *pNLSF_Q15, /* I/O (Un)quantized NLSF vector [ LPC_ORDER ] */ + opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ + opus_int16 *pNLSF_Q15, /* I/O (Un)quantized NLSF vector [ LPC_ORDER ] */ const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const opus_int16 *pW_Q2, /* I NLSF weight vector [ LPC_ORDER ] */ const opus_int NLSF_mu_Q20, /* I Rate weight for the RD optimization */ const opus_int nSurvivors, /* I Max survivors after first stage */ const opus_int signalType /* I Signal type: 0/1/2 */ -) { +) +{ opus_int i, s, ind1, bestIndex, prob_Q8, bits_q7; opus_int32 W_tmp_Q9, ret; - VARDECL(opus_int32, err_Q24); - VARDECL(opus_int32, RD_Q25); - VARDECL(opus_int, tempIndices1); - VARDECL(opus_int8, tempIndices2); + VARDECL( opus_int32, err_Q24 ); + VARDECL( opus_int32, RD_Q25 ); + VARDECL( opus_int, tempIndices1 ); + VARDECL( opus_int8, tempIndices2 ); opus_int16 res_Q10[ MAX_LPC_ORDER ]; opus_int16 NLSF_tmp_Q15[ MAX_LPC_ORDER ]; opus_int16 W_adj_Q5[ MAX_LPC_ORDER ]; @@ -59,63 +60,63 @@ opus_int32 silk_NLSF_encode( /* O Returns const opus_int16 *pCB_Wght_Q9; SAVE_STACK; - celt_assert(signalType >= 0 && signalType <= 2); - silk_assert(NLSF_mu_Q20 <= 32767 && NLSF_mu_Q20 >= 0); + celt_assert( signalType >= 0 && signalType <= 2 ); + silk_assert( NLSF_mu_Q20 <= 32767 && NLSF_mu_Q20 >= 0 ); /* NLSF stabilization */ - silk_NLSF_stabilize(pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order); + silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order ); /* First stage: VQ */ - ALLOC(err_Q24, psNLSF_CB->nVectors, opus_int32); - silk_NLSF_VQ(err_Q24, pNLSF_Q15, psNLSF_CB->CB1_NLSF_Q8, psNLSF_CB->CB1_Wght_Q9, psNLSF_CB->nVectors, psNLSF_CB->order); + ALLOC( err_Q24, psNLSF_CB->nVectors, opus_int32 ); + silk_NLSF_VQ( err_Q24, pNLSF_Q15, psNLSF_CB->CB1_NLSF_Q8, psNLSF_CB->CB1_Wght_Q9, psNLSF_CB->nVectors, psNLSF_CB->order ); /* Sort the quantization errors */ - ALLOC(tempIndices1, nSurvivors, opus_int); - silk_insertion_sort_increasing(err_Q24, tempIndices1, psNLSF_CB->nVectors, nSurvivors); + ALLOC( tempIndices1, nSurvivors, opus_int ); + silk_insertion_sort_increasing( err_Q24, tempIndices1, psNLSF_CB->nVectors, nSurvivors ); - ALLOC(RD_Q25, nSurvivors, opus_int32); - ALLOC(tempIndices2, nSurvivors * MAX_LPC_ORDER, opus_int8); + ALLOC( RD_Q25, nSurvivors, opus_int32 ); + ALLOC( tempIndices2, nSurvivors * MAX_LPC_ORDER, opus_int8 ); /* Loop over survivors */ - for (s = 0; s < nSurvivors; s++) { + for( s = 0; s < nSurvivors; s++ ) { ind1 = tempIndices1[ s ]; /* Residual after first stage */ pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ ind1 * psNLSF_CB->order ]; pCB_Wght_Q9 = &psNLSF_CB->CB1_Wght_Q9[ ind1 * psNLSF_CB->order ]; - for (i = 0; i < psNLSF_CB->order; i++) { - NLSF_tmp_Q15[ i ] = silk_LSHIFT16((opus_int16)pCB_element[ i ], 7); + for( i = 0; i < psNLSF_CB->order; i++ ) { + NLSF_tmp_Q15[ i ] = silk_LSHIFT16( (opus_int16)pCB_element[ i ], 7 ); W_tmp_Q9 = pCB_Wght_Q9[ i ]; - res_Q10[ i ] = (opus_int16)silk_RSHIFT(silk_SMULBB(pNLSF_Q15[ i ] - NLSF_tmp_Q15[ i ], W_tmp_Q9), 14); - W_adj_Q5[ i ] = silk_DIV32_varQ((opus_int32)pW_Q2[ i ], silk_SMULBB(W_tmp_Q9, W_tmp_Q9), 21); + res_Q10[ i ] = (opus_int16)silk_RSHIFT( silk_SMULBB( pNLSF_Q15[ i ] - NLSF_tmp_Q15[ i ], W_tmp_Q9 ), 14 ); + W_adj_Q5[ i ] = silk_DIV32_varQ( (opus_int32)pW_Q2[ i ], silk_SMULBB( W_tmp_Q9, W_tmp_Q9 ), 21 ); } /* Unpack entropy table indices and predictor for current CB1 index */ - silk_NLSF_unpack(ec_ix, pred_Q8, psNLSF_CB, ind1); + silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, ind1 ); /* Trellis quantizer */ - RD_Q25[ s ] = silk_NLSF_del_dec_quant(&tempIndices2[ s * MAX_LPC_ORDER ], res_Q10, W_adj_Q5, pred_Q8, ec_ix, - psNLSF_CB->ec_Rates_Q5, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->invQuantStepSize_Q6, NLSF_mu_Q20, psNLSF_CB->order); + RD_Q25[ s ] = silk_NLSF_del_dec_quant( &tempIndices2[ s * MAX_LPC_ORDER ], res_Q10, W_adj_Q5, pred_Q8, ec_ix, + psNLSF_CB->ec_Rates_Q5, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->invQuantStepSize_Q6, NLSF_mu_Q20, psNLSF_CB->order ); /* Add rate for first stage */ - iCDF_ptr = &psNLSF_CB->CB1_iCDF[(signalType >> 1) * psNLSF_CB->nVectors ]; - if (ind1 == 0) { + iCDF_ptr = &psNLSF_CB->CB1_iCDF[ ( signalType >> 1 ) * psNLSF_CB->nVectors ]; + if( ind1 == 0 ) { prob_Q8 = 256 - iCDF_ptr[ ind1 ]; } else { prob_Q8 = iCDF_ptr[ ind1 - 1 ] - iCDF_ptr[ ind1 ]; } - bits_q7 = (8 << 7) - silk_lin2log(prob_Q8); - RD_Q25[ s ] = silk_SMLABB(RD_Q25[ s ], bits_q7, silk_RSHIFT(NLSF_mu_Q20, 2)); + bits_q7 = ( 8 << 7 ) - silk_lin2log( prob_Q8 ); + RD_Q25[ s ] = silk_SMLABB( RD_Q25[ s ], bits_q7, silk_RSHIFT( NLSF_mu_Q20, 2 ) ); } /* Find the lowest rate-distortion error */ - silk_insertion_sort_increasing(RD_Q25, &bestIndex, nSurvivors, 1); + silk_insertion_sort_increasing( RD_Q25, &bestIndex, nSurvivors, 1 ); NLSFIndices[ 0 ] = (opus_int8)tempIndices1[ bestIndex ]; - silk_memcpy(&NLSFIndices[ 1 ], &tempIndices2[ bestIndex * MAX_LPC_ORDER ], psNLSF_CB->order * sizeof(opus_int8)); + silk_memcpy( &NLSFIndices[ 1 ], &tempIndices2[ bestIndex * MAX_LPC_ORDER ], psNLSF_CB->order * sizeof( opus_int8 ) ); /* Decode */ - silk_NLSF_decode(pNLSF_Q15, NLSFIndices, psNLSF_CB); + silk_NLSF_decode( pNLSF_Q15, NLSFIndices, psNLSF_CB ); ret = RD_Q25[ 0 ]; RESTORE_STACK; diff --git a/src/libopus/silk/NLSF_stabilize.c b/src/libopus/silk/NLSF_stabilize.c index b4e22b4..ab389cc 100644 --- a/src/libopus/silk/NLSF_stabilize.c +++ b/src/libopus/silk/NLSF_stabilize.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif /* NLSF stabilizer: */ /* */ @@ -45,18 +45,19 @@ /* NLSF stabilizer, for a single input data vector */ void silk_NLSF_stabilize( - opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */ + opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */ const opus_int16 *NDeltaMin_Q15, /* I Min distance vector, NDeltaMin_Q15[L] must be >= 1 [L+1] */ const opus_int L /* I Number of NLSF parameters in the input vector */ -) { - opus_int i, I = 0, k, loops; +) +{ + opus_int i, I=0, k, loops; opus_int16 center_freq_Q15; opus_int32 diff_Q15, min_diff_Q15, min_center_Q15, max_center_Q15; /* This is necessary to ensure an output within range of a opus_int16 */ - silk_assert(NDeltaMin_Q15[L] >= 1); + silk_assert( NDeltaMin_Q15[L] >= 1 ); - for (loops = 0; loops < MAX_LOOPS; loops++) { + for( loops = 0; loops < MAX_LOOPS; loops++ ) { /**************************/ /* Find smallest distance */ /**************************/ @@ -64,16 +65,16 @@ void silk_NLSF_stabilize( min_diff_Q15 = NLSF_Q15[0] - NDeltaMin_Q15[0]; I = 0; /* Middle elements */ - for (i = 1; i <= L - 1; i++) { - diff_Q15 = NLSF_Q15[i] - (NLSF_Q15[i - 1] + NDeltaMin_Q15[i]); - if (diff_Q15 < min_diff_Q15) { + for( i = 1; i <= L-1; i++ ) { + diff_Q15 = NLSF_Q15[i] - ( NLSF_Q15[i-1] + NDeltaMin_Q15[i] ); + if( diff_Q15 < min_diff_Q15 ) { min_diff_Q15 = diff_Q15; I = i; } } /* Last element */ - diff_Q15 = (1 << 15) - (NLSF_Q15[L - 1] + NDeltaMin_Q15[L]); - if (diff_Q15 < min_diff_Q15) { + diff_Q15 = ( 1 << 15 ) - ( NLSF_Q15[L-1] + NDeltaMin_Q15[L] ); + if( diff_Q15 < min_diff_Q15 ) { min_diff_Q15 = diff_Q15; I = L; } @@ -81,62 +82,61 @@ void silk_NLSF_stabilize( /***************************************************/ /* Now check if the smallest distance non-negative */ /***************************************************/ - if (min_diff_Q15 >= 0) { + if( min_diff_Q15 >= 0 ) { return; } - if (I == 0) { + if( I == 0 ) { /* Move away from lower limit */ NLSF_Q15[0] = NDeltaMin_Q15[0]; - } else if (I == L) { + } else if( I == L) { /* Move away from higher limit */ - NLSF_Q15[L - 1] = (1 << 15) - NDeltaMin_Q15[L]; + NLSF_Q15[L-1] = ( 1 << 15 ) - NDeltaMin_Q15[L]; } else { /* Find the lower extreme for the location of the current center frequency */ min_center_Q15 = 0; - for (k = 0; k < I; k++) { + for( k = 0; k < I; k++ ) { min_center_Q15 += NDeltaMin_Q15[k]; } - min_center_Q15 += silk_RSHIFT(NDeltaMin_Q15[I], 1); + min_center_Q15 += silk_RSHIFT( NDeltaMin_Q15[I], 1 ); /* Find the upper extreme for the location of the current center frequency */ max_center_Q15 = 1 << 15; - for (k = L; k > I; k--) { + for( k = L; k > I; k-- ) { max_center_Q15 -= NDeltaMin_Q15[k]; } - max_center_Q15 -= silk_RSHIFT(NDeltaMin_Q15[I], 1); + max_center_Q15 -= silk_RSHIFT( NDeltaMin_Q15[I], 1 ); /* Move apart, sorted by value, keeping the same center frequency */ - center_freq_Q15 = (opus_int16)silk_LIMIT_32(silk_RSHIFT_ROUND((opus_int32)NLSF_Q15[I - 1] + (opus_int32)NLSF_Q15[I], 1), - min_center_Q15, max_center_Q15); - NLSF_Q15[I - 1] = center_freq_Q15 - silk_RSHIFT(NDeltaMin_Q15[I], 1); - NLSF_Q15[I] = NLSF_Q15[I - 1] + NDeltaMin_Q15[I]; + center_freq_Q15 = (opus_int16)silk_LIMIT_32( silk_RSHIFT_ROUND( (opus_int32)NLSF_Q15[I-1] + (opus_int32)NLSF_Q15[I], 1 ), + min_center_Q15, max_center_Q15 ); + NLSF_Q15[I-1] = center_freq_Q15 - silk_RSHIFT( NDeltaMin_Q15[I], 1 ); + NLSF_Q15[I] = NLSF_Q15[I-1] + NDeltaMin_Q15[I]; } } /* Safe and simple fall back method, which is less ideal than the above */ - if (loops == MAX_LOOPS) { + if( loops == MAX_LOOPS ) + { /* Insertion sort (fast for already almost sorted arrays): */ /* Best case: O(n) for an already sorted array */ /* Worst case: O(n^2) for an inversely sorted array */ - silk_insertion_sort_increasing_all_values_int16(&NLSF_Q15[0], L); + silk_insertion_sort_increasing_all_values_int16( &NLSF_Q15[0], L ); /* First NLSF should be no less than NDeltaMin[0] */ - NLSF_Q15[0] = silk_max_int(NLSF_Q15[0], NDeltaMin_Q15[0]); + NLSF_Q15[0] = silk_max_int( NLSF_Q15[0], NDeltaMin_Q15[0] ); /* Keep delta_min distance between the NLSFs */ - for (i = 1; i < L; i++) { - NLSF_Q15[i] = silk_max_int(NLSF_Q15[i], silk_ADD_SAT16(NLSF_Q15[i - 1], NDeltaMin_Q15[i])); - } + for( i = 1; i < L; i++ ) + NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], silk_ADD_SAT16( NLSF_Q15[i-1], NDeltaMin_Q15[i] ) ); /* Last NLSF should be no higher than 1 - NDeltaMin[L] */ - NLSF_Q15[L - 1] = silk_min_int(NLSF_Q15[L - 1], (1 << 15) - NDeltaMin_Q15[L]); + NLSF_Q15[L-1] = silk_min_int( NLSF_Q15[L-1], (1<<15) - NDeltaMin_Q15[L] ); /* Keep NDeltaMin distance between the NLSFs */ - for (i = L - 2; i >= 0; i--) { - NLSF_Q15[i] = silk_min_int(NLSF_Q15[i], NLSF_Q15[i + 1] - NDeltaMin_Q15[i + 1]); - } + for( i = L-2; i >= 0; i-- ) + NLSF_Q15[i] = silk_min_int( NLSF_Q15[i], NLSF_Q15[i+1] - NDeltaMin_Q15[i+1] ); } } diff --git a/src/libopus/silk/NLSF_unpack.c b/src/libopus/silk/NLSF_unpack.c index 842ddbb..ed0d9c3 100644 --- a/src/libopus/silk/NLSF_unpack.c +++ b/src/libopus/silk/NLSF_unpack.c @@ -1,54 +1,55 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" /* Unpack predictor values and indices for entropy coding tables */ void silk_NLSF_unpack( - opus_int16 ec_ix[], /* O Indices to entropy tables [ LPC_ORDER ] */ - opus_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */ + opus_int16 ec_ix[], /* O Indices to entropy tables [ LPC_ORDER ] */ + opus_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */ const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const opus_int CB1_index /* I Index of vector in first LSF codebook */ -) { +) +{ opus_int i; opus_uint8 entry; const opus_uint8 *ec_sel_ptr; ec_sel_ptr = &psNLSF_CB->ec_sel[ CB1_index * psNLSF_CB->order / 2 ]; - for (i = 0; i < psNLSF_CB->order; i += 2) { + for( i = 0; i < psNLSF_CB->order; i += 2 ) { entry = *ec_sel_ptr++; - ec_ix [ i ] = silk_SMULBB(silk_RSHIFT(entry, 1) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1); - pred_Q8[ i ] = psNLSF_CB->pred_Q8[ i + (entry & 1) * (psNLSF_CB->order - 1) ]; - ec_ix [ i + 1 ] = silk_SMULBB(silk_RSHIFT(entry, 5) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1); - pred_Q8[ i + 1 ] = psNLSF_CB->pred_Q8[ i + (silk_RSHIFT(entry, 4) & 1) * (psNLSF_CB->order - 1) + 1 ]; + ec_ix [ i ] = silk_SMULBB( silk_RSHIFT( entry, 1 ) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1 ); + pred_Q8[ i ] = psNLSF_CB->pred_Q8[ i + ( entry & 1 ) * ( psNLSF_CB->order - 1 ) ]; + ec_ix [ i + 1 ] = silk_SMULBB( silk_RSHIFT( entry, 5 ) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1 ); + pred_Q8[ i + 1 ] = psNLSF_CB->pred_Q8[ i + ( silk_RSHIFT( entry, 4 ) & 1 ) * ( psNLSF_CB->order - 1 ) + 1 ]; } } diff --git a/src/libopus/silk/NSQ.c b/src/libopus/silk/NSQ.c deleted file mode 100644 index cde253f..0000000 --- a/src/libopus/silk/NSQ.c +++ /dev/null @@ -1,434 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif - -#include "main.h" -#include "../celt/stack_alloc.h" -#include "NSQ.h" - - -static OPUS_INLINE void silk_nsq_scale_states( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - const opus_int16 x16[], /* I input */ - opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ - const opus_int16 sLTP[], /* I re-whitened LTP state in Q0 */ - opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ - opus_int subfr, /* I subframe number */ - const opus_int LTP_scale_Q14, /* I */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag */ - const opus_int signal_type /* I Signal type */ -); - -#if !defined(OPUS_X86_MAY_HAVE_SSE4_1) -static OPUS_INLINE void silk_noise_shape_quantizer( - silk_nsq_state *NSQ, /* I/O NSQ state */ - opus_int signalType, /* I Signal type */ - const opus_int32 x_sc_Q10[], /* I */ - opus_int8 pulses[], /* O */ - opus_int16 xq[], /* O */ - opus_int32 sLTP_Q15[], /* I/O LTP state */ - const opus_int16 a_Q12[], /* I Short term prediction coefs */ - const opus_int16 b_Q14[], /* I Long term prediction coefs */ - const opus_int16 AR_shp_Q13[], /* I Noise shaping AR coefs */ - opus_int lag, /* I Pitch lag */ - opus_int32 HarmShapeFIRPacked_Q14, /* I */ - opus_int Tilt_Q14, /* I Spectral tilt */ - opus_int32 LF_shp_Q14, /* I */ - opus_int32 Gain_Q16, /* I */ - opus_int Lambda_Q10, /* I */ - opus_int offset_Q10, /* I */ - opus_int length, /* I Input length */ - opus_int shapingLPCOrder, /* I Noise shaping AR filter order */ - opus_int predictLPCOrder, /* I Prediction filter order */ - int arch /* I Architecture */ -); -#endif - -void silk_NSQ_c -( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - SideInfoIndices *psIndices, /* I/O Quantization Indices */ - const opus_int16 x16[], /* I Input */ - opus_int8 pulses[], /* O Quantized pulse signal */ - const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ - const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ - const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ - const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ - const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ - const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ - const opus_int LTP_scale_Q14 /* I LTP state scaling */ -) { - opus_int k, lag, start_idx, LSF_interpolation_flag; - const opus_int16 *A_Q12, *B_Q14, *AR_shp_Q13; - opus_int16 *pxq; - VARDECL(opus_int32, sLTP_Q15); - VARDECL(opus_int16, sLTP); - opus_int32 HarmShapeFIRPacked_Q14; - opus_int offset_Q10; - VARDECL(opus_int32, x_sc_Q10); - SAVE_STACK; - - NSQ->rand_seed = psIndices->Seed; - - /* Set unvoiced lag to the previous one, overwrite later for voiced */ - lag = NSQ->lagPrev; - - silk_assert(NSQ->prev_gain_Q16 != 0); - - offset_Q10 = silk_Quantization_Offsets_Q10[ psIndices->signalType >> 1 ][ psIndices->quantOffsetType ]; - - if (psIndices->NLSFInterpCoef_Q2 == 4) { - LSF_interpolation_flag = 0; - } else { - LSF_interpolation_flag = 1; - } - - ALLOC(sLTP_Q15, psEncC->ltp_mem_length + psEncC->frame_length, opus_int32); - ALLOC(sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16); - ALLOC(x_sc_Q10, psEncC->subfr_length, opus_int32); - /* Set up pointers to start of sub frame */ - NSQ->sLTP_shp_buf_idx = psEncC->ltp_mem_length; - NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; - pxq = &NSQ->xq[ psEncC->ltp_mem_length ]; - for (k = 0; k < psEncC->nb_subfr; k++) { - A_Q12 = &PredCoef_Q12[((k >> 1) | (1 - LSF_interpolation_flag)) * MAX_LPC_ORDER ]; - B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; - AR_shp_Q13 = &AR_Q13[ k * MAX_SHAPE_LPC_ORDER ]; - - /* Noise shape parameters */ - silk_assert(HarmShapeGain_Q14[ k ] >= 0); - HarmShapeFIRPacked_Q14 = silk_RSHIFT(HarmShapeGain_Q14[ k ], 2); - HarmShapeFIRPacked_Q14 |= silk_LSHIFT((opus_int32)silk_RSHIFT(HarmShapeGain_Q14[ k ], 1), 16); - - NSQ->rewhite_flag = 0; - if (psIndices->signalType == TYPE_VOICED) { - /* Voiced */ - lag = pitchL[ k ]; - - /* Re-whitening */ - if ((k & (3 - silk_LSHIFT(LSF_interpolation_flag, 1))) == 0) { - /* Rewhiten with new A coefs */ - start_idx = psEncC->ltp_mem_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; - celt_assert(start_idx > 0); - - silk_LPC_analysis_filter(&sLTP[ start_idx ], &NSQ->xq[ start_idx + k * psEncC->subfr_length ], - A_Q12, psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder, psEncC->arch); - - NSQ->rewhite_flag = 1; - NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; - } - } - - silk_nsq_scale_states(psEncC, NSQ, x16, x_sc_Q10, sLTP, sLTP_Q15, k, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType); - - silk_noise_shape_quantizer(NSQ, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, A_Q12, B_Q14, - AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10, - offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, psEncC->arch); - - x16 += psEncC->subfr_length; - pulses += psEncC->subfr_length; - pxq += psEncC->subfr_length; - } - - /* Update lagPrev for next frame */ - NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; - - /* Save quantized speech and noise shaping signals */ - silk_memmove(NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof(opus_int16)); - silk_memmove(NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof(opus_int32)); - RESTORE_STACK; -} - -/***********************************/ -/* silk_noise_shape_quantizer */ -/***********************************/ - -#if !defined(OPUS_X86_MAY_HAVE_SSE4_1) -static OPUS_INLINE -#endif -void silk_noise_shape_quantizer( - silk_nsq_state *NSQ, /* I/O NSQ state */ - opus_int signalType, /* I Signal type */ - const opus_int32 x_sc_Q10[], /* I */ - opus_int8 pulses[], /* O */ - opus_int16 xq[], /* O */ - opus_int32 sLTP_Q15[], /* I/O LTP state */ - const opus_int16 a_Q12[], /* I Short term prediction coefs */ - const opus_int16 b_Q14[], /* I Long term prediction coefs */ - const opus_int16 AR_shp_Q13[], /* I Noise shaping AR coefs */ - opus_int lag, /* I Pitch lag */ - opus_int32 HarmShapeFIRPacked_Q14, /* I */ - opus_int Tilt_Q14, /* I Spectral tilt */ - opus_int32 LF_shp_Q14, /* I */ - opus_int32 Gain_Q16, /* I */ - opus_int Lambda_Q10, /* I */ - opus_int offset_Q10, /* I */ - opus_int length, /* I Input length */ - opus_int shapingLPCOrder, /* I Noise shaping AR filter order */ - opus_int predictLPCOrder, /* I Prediction filter order */ - int arch /* I Architecture */ -) { - opus_int i; - opus_int32 LTP_pred_Q13, LPC_pred_Q10, n_AR_Q12, n_LTP_Q13; - opus_int32 n_LF_Q12, r_Q10, rr_Q10, q1_Q0, q1_Q10, q2_Q10, rd1_Q20, rd2_Q20; - opus_int32 exc_Q14, LPC_exc_Q14, xq_Q14, Gain_Q10; - opus_int32 tmp1, tmp2, sLF_AR_shp_Q14; - opus_int32 *psLPC_Q14, *shp_lag_ptr, *pred_lag_ptr; -#ifdef silk_short_prediction_create_arch_coef - opus_int32 a_Q12_arch[MAX_LPC_ORDER]; -#endif - - shp_lag_ptr = &NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ]; - pred_lag_ptr = &sLTP_Q15[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ]; - Gain_Q10 = silk_RSHIFT(Gain_Q16, 6); - - /* Set up short term AR state */ - psLPC_Q14 = &NSQ->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 ]; - -#ifdef silk_short_prediction_create_arch_coef - silk_short_prediction_create_arch_coef(a_Q12_arch, a_Q12, predictLPCOrder); -#endif - - for (i = 0; i < length; i++) { - /* Generate dither */ - NSQ->rand_seed = silk_RAND(NSQ->rand_seed); - - /* Short-term prediction */ - LPC_pred_Q10 = silk_noise_shape_quantizer_short_prediction(psLPC_Q14, a_Q12, a_Q12_arch, predictLPCOrder, arch); - - /* Long-term prediction */ - if (signalType == TYPE_VOICED) { - /* Unrolled loop */ - /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ - LTP_pred_Q13 = 2; - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ 0 ], b_Q14[ 0 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -1 ], b_Q14[ 1 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -2 ], b_Q14[ 2 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -3 ], b_Q14[ 3 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -4 ], b_Q14[ 4 ]); - pred_lag_ptr++; - } else { - LTP_pred_Q13 = 0; - } - - /* Noise shape feedback */ - celt_assert((shapingLPCOrder & 1) == 0); /* check that order is even */ - n_AR_Q12 = silk_NSQ_noise_shape_feedback_loop(&NSQ->sDiff_shp_Q14, NSQ->sAR2_Q14, AR_shp_Q13, shapingLPCOrder, arch); - - n_AR_Q12 = silk_SMLAWB(n_AR_Q12, NSQ->sLF_AR_shp_Q14, Tilt_Q14); - - n_LF_Q12 = silk_SMULWB(NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14); - n_LF_Q12 = silk_SMLAWT(n_LF_Q12, NSQ->sLF_AR_shp_Q14, LF_shp_Q14); - - celt_assert(lag > 0 || signalType != TYPE_VOICED); - - /* Combine prediction and noise shaping signals */ - tmp1 = silk_SUB32(silk_LSHIFT32(LPC_pred_Q10, 2), n_AR_Q12); /* Q12 */ - tmp1 = silk_SUB32(tmp1, n_LF_Q12); /* Q12 */ - if (lag > 0) { - /* Symmetric, packed FIR coefficients */ - n_LTP_Q13 = silk_SMULWB(silk_ADD32(shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ]), HarmShapeFIRPacked_Q14); - n_LTP_Q13 = silk_SMLAWT(n_LTP_Q13, shp_lag_ptr[ -1 ], HarmShapeFIRPacked_Q14); - n_LTP_Q13 = silk_LSHIFT(n_LTP_Q13, 1); - shp_lag_ptr++; - - tmp2 = silk_SUB32(LTP_pred_Q13, n_LTP_Q13); /* Q13 */ - tmp1 = silk_ADD_LSHIFT32(tmp2, tmp1, 1); /* Q13 */ - tmp1 = silk_RSHIFT_ROUND(tmp1, 3); /* Q10 */ - } else { - tmp1 = silk_RSHIFT_ROUND(tmp1, 2); /* Q10 */ - } - - r_Q10 = silk_SUB32(x_sc_Q10[ i ], tmp1); /* residual error Q10 */ - - /* Flip sign depending on dither */ - if (NSQ->rand_seed < 0) { - r_Q10 = -r_Q10; - } - r_Q10 = silk_LIMIT_32(r_Q10, -(31 << 10), 30 << 10); - - /* Find two quantization level candidates and measure their rate-distortion */ - q1_Q10 = silk_SUB32(r_Q10, offset_Q10); - q1_Q0 = silk_RSHIFT(q1_Q10, 10); - if (Lambda_Q10 > 2048) { - /* For aggressive RDO, the bias becomes more than one pulse. */ - int rdo_offset = Lambda_Q10 / 2 - 512; - if (q1_Q10 > rdo_offset) { - q1_Q0 = silk_RSHIFT(q1_Q10 - rdo_offset, 10); - } else if (q1_Q10 < -rdo_offset) { - q1_Q0 = silk_RSHIFT(q1_Q10 + rdo_offset, 10); - } else if (q1_Q10 < 0) { - q1_Q0 = -1; - } else { - q1_Q0 = 0; - } - } - if (q1_Q0 > 0) { - q1_Q10 = silk_SUB32(silk_LSHIFT(q1_Q0, 10), QUANT_LEVEL_ADJUST_Q10); - q1_Q10 = silk_ADD32(q1_Q10, offset_Q10); - q2_Q10 = silk_ADD32(q1_Q10, 1024); - rd1_Q20 = silk_SMULBB(q1_Q10, Lambda_Q10); - rd2_Q20 = silk_SMULBB(q2_Q10, Lambda_Q10); - } else if (q1_Q0 == 0) { - q1_Q10 = offset_Q10; - q2_Q10 = silk_ADD32(q1_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10); - rd1_Q20 = silk_SMULBB(q1_Q10, Lambda_Q10); - rd2_Q20 = silk_SMULBB(q2_Q10, Lambda_Q10); - } else if (q1_Q0 == -1) { - q2_Q10 = offset_Q10; - q1_Q10 = silk_SUB32(q2_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10); - rd1_Q20 = silk_SMULBB(-q1_Q10, Lambda_Q10); - rd2_Q20 = silk_SMULBB(q2_Q10, Lambda_Q10); - } else { /* Q1_Q0 < -1 */ - q1_Q10 = silk_ADD32(silk_LSHIFT(q1_Q0, 10), QUANT_LEVEL_ADJUST_Q10); - q1_Q10 = silk_ADD32(q1_Q10, offset_Q10); - q2_Q10 = silk_ADD32(q1_Q10, 1024); - rd1_Q20 = silk_SMULBB(-q1_Q10, Lambda_Q10); - rd2_Q20 = silk_SMULBB(-q2_Q10, Lambda_Q10); - } - rr_Q10 = silk_SUB32(r_Q10, q1_Q10); - rd1_Q20 = silk_SMLABB(rd1_Q20, rr_Q10, rr_Q10); - rr_Q10 = silk_SUB32(r_Q10, q2_Q10); - rd2_Q20 = silk_SMLABB(rd2_Q20, rr_Q10, rr_Q10); - - if (rd2_Q20 < rd1_Q20) { - q1_Q10 = q2_Q10; - } - - pulses[ i ] = (opus_int8)silk_RSHIFT_ROUND(q1_Q10, 10); - - /* Excitation */ - exc_Q14 = silk_LSHIFT(q1_Q10, 4); - if (NSQ->rand_seed < 0) { - exc_Q14 = -exc_Q14; - } - - /* Add predictions */ - LPC_exc_Q14 = silk_ADD_LSHIFT32(exc_Q14, LTP_pred_Q13, 1); - xq_Q14 = silk_ADD_LSHIFT32(LPC_exc_Q14, LPC_pred_Q10, 4); - - /* Scale XQ back to normal level before saving */ - xq[ i ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(silk_SMULWW(xq_Q14, Gain_Q10), 8)); - - /* Update states */ - psLPC_Q14++; - *psLPC_Q14 = xq_Q14; - NSQ->sDiff_shp_Q14 = silk_SUB_LSHIFT32(xq_Q14, x_sc_Q10[ i ], 4); - sLF_AR_shp_Q14 = silk_SUB_LSHIFT32(NSQ->sDiff_shp_Q14, n_AR_Q12, 2); - NSQ->sLF_AR_shp_Q14 = sLF_AR_shp_Q14; - - NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx ] = silk_SUB_LSHIFT32(sLF_AR_shp_Q14, n_LF_Q12, 2); - sLTP_Q15[ NSQ->sLTP_buf_idx ] = silk_LSHIFT(LPC_exc_Q14, 1); - NSQ->sLTP_shp_buf_idx++; - NSQ->sLTP_buf_idx++; - - /* Make dither dependent on quantized signal */ - NSQ->rand_seed = silk_ADD32_ovflw(NSQ->rand_seed, pulses[ i ]); - } - - /* Update LPC synth buffer */ - silk_memcpy(NSQ->sLPC_Q14, &NSQ->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof(opus_int32)); -} - -static OPUS_INLINE void silk_nsq_scale_states( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - const opus_int16 x16[], /* I input */ - opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ - const opus_int16 sLTP[], /* I re-whitened LTP state in Q0 */ - opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ - opus_int subfr, /* I subframe number */ - const opus_int LTP_scale_Q14, /* I */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag */ - const opus_int signal_type /* I Signal type */ -) { - opus_int i, lag; - opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q26; - - lag = pitchL[ subfr ]; - inv_gain_Q31 = silk_INVERSE32_varQ(silk_max(Gains_Q16[ subfr ], 1), 47); - silk_assert(inv_gain_Q31 != 0); - - /* Scale input */ - inv_gain_Q26 = silk_RSHIFT_ROUND(inv_gain_Q31, 5); - for (i = 0; i < psEncC->subfr_length; i++) { - x_sc_Q10[ i ] = silk_SMULWW(x16[ i ], inv_gain_Q26); - } - - /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */ - if (NSQ->rewhite_flag) { - if (subfr == 0) { - /* Do LTP downscaling */ - inv_gain_Q31 = silk_LSHIFT(silk_SMULWB(inv_gain_Q31, LTP_scale_Q14), 2); - } - for (i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++) { - silk_assert(i < MAX_FRAME_LENGTH); - sLTP_Q15[ i ] = silk_SMULWB(inv_gain_Q31, sLTP[ i ]); - } - } - - /* Adjust for changing gain */ - if (Gains_Q16[ subfr ] != NSQ->prev_gain_Q16) { - gain_adj_Q16 = silk_DIV32_varQ(NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16); - - /* Scale long-term shaping state */ - for (i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx; i++) { - NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW(gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ]); - } - - /* Scale long-term prediction state */ - if (signal_type == TYPE_VOICED && NSQ->rewhite_flag == 0) { - for (i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++) { - sLTP_Q15[ i ] = silk_SMULWW(gain_adj_Q16, sLTP_Q15[ i ]); - } - } - - NSQ->sLF_AR_shp_Q14 = silk_SMULWW(gain_adj_Q16, NSQ->sLF_AR_shp_Q14); - NSQ->sDiff_shp_Q14 = silk_SMULWW(gain_adj_Q16, NSQ->sDiff_shp_Q14); - - /* Scale short-term prediction and shaping states */ - for (i = 0; i < NSQ_LPC_BUF_LENGTH; i++) { - NSQ->sLPC_Q14[ i ] = silk_SMULWW(gain_adj_Q16, NSQ->sLPC_Q14[ i ]); - } - for (i = 0; i < MAX_SHAPE_LPC_ORDER; i++) { - NSQ->sAR2_Q14[ i ] = silk_SMULWW(gain_adj_Q16, NSQ->sAR2_Q14[ i ]); - } - - /* Save inverse gain */ - NSQ->prev_gain_Q16 = Gains_Q16[ subfr ]; - } -} diff --git a/src/libopus/silk/NSQ.h b/src/libopus/silk/NSQ.h index f182607..971832f 100644 --- a/src/libopus/silk/NSQ.h +++ b/src/libopus/silk/NSQ.h @@ -1,29 +1,29 @@ /*********************************************************************** - Copyright (c) 2014 Vidyo. - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2014 Vidyo. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_NSQ_H #define SILK_NSQ_H @@ -32,37 +32,40 @@ #undef silk_short_prediction_create_arch_coef -static OPUS_INLINE opus_int32 silk_noise_shape_quantizer_short_prediction_c(const opus_int32 *buf32, const opus_int16 *coef16, opus_int order) { +static OPUS_INLINE opus_int32 silk_noise_shape_quantizer_short_prediction_c(const opus_int32 *buf32, const opus_int16 *coef16, opus_int order) +{ opus_int32 out; - silk_assert(order == 10 || order == 16); + silk_assert( order == 10 || order == 16 ); /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ - out = silk_RSHIFT(order, 1); - out = silk_SMLAWB(out, buf32[ 0 ], coef16[ 0 ]); - out = silk_SMLAWB(out, buf32[ -1 ], coef16[ 1 ]); - out = silk_SMLAWB(out, buf32[ -2 ], coef16[ 2 ]); - out = silk_SMLAWB(out, buf32[ -3 ], coef16[ 3 ]); - out = silk_SMLAWB(out, buf32[ -4 ], coef16[ 4 ]); - out = silk_SMLAWB(out, buf32[ -5 ], coef16[ 5 ]); - out = silk_SMLAWB(out, buf32[ -6 ], coef16[ 6 ]); - out = silk_SMLAWB(out, buf32[ -7 ], coef16[ 7 ]); - out = silk_SMLAWB(out, buf32[ -8 ], coef16[ 8 ]); - out = silk_SMLAWB(out, buf32[ -9 ], coef16[ 9 ]); + out = silk_RSHIFT( order, 1 ); + out = silk_SMLAWB( out, buf32[ 0 ], coef16[ 0 ] ); + out = silk_SMLAWB( out, buf32[ -1 ], coef16[ 1 ] ); + out = silk_SMLAWB( out, buf32[ -2 ], coef16[ 2 ] ); + out = silk_SMLAWB( out, buf32[ -3 ], coef16[ 3 ] ); + out = silk_SMLAWB( out, buf32[ -4 ], coef16[ 4 ] ); + out = silk_SMLAWB( out, buf32[ -5 ], coef16[ 5 ] ); + out = silk_SMLAWB( out, buf32[ -6 ], coef16[ 6 ] ); + out = silk_SMLAWB( out, buf32[ -7 ], coef16[ 7 ] ); + out = silk_SMLAWB( out, buf32[ -8 ], coef16[ 8 ] ); + out = silk_SMLAWB( out, buf32[ -9 ], coef16[ 9 ] ); - if (order == 16) { - out = silk_SMLAWB(out, buf32[ -10 ], coef16[ 10 ]); - out = silk_SMLAWB(out, buf32[ -11 ], coef16[ 11 ]); - out = silk_SMLAWB(out, buf32[ -12 ], coef16[ 12 ]); - out = silk_SMLAWB(out, buf32[ -13 ], coef16[ 13 ]); - out = silk_SMLAWB(out, buf32[ -14 ], coef16[ 14 ]); - out = silk_SMLAWB(out, buf32[ -15 ], coef16[ 15 ]); + if( order == 16 ) + { + out = silk_SMLAWB( out, buf32[ -10 ], coef16[ 10 ] ); + out = silk_SMLAWB( out, buf32[ -11 ], coef16[ 11 ] ); + out = silk_SMLAWB( out, buf32[ -12 ], coef16[ 12 ] ); + out = silk_SMLAWB( out, buf32[ -13 ], coef16[ 13 ] ); + out = silk_SMLAWB( out, buf32[ -14 ], coef16[ 14 ] ); + out = silk_SMLAWB( out, buf32[ -15 ], coef16[ 15 ] ); } return out; } #define silk_noise_shape_quantizer_short_prediction(in, coef, coefRev, order, arch) ((void)arch,silk_noise_shape_quantizer_short_prediction_c(in, coef, order)) -static OPUS_INLINE opus_int32 silk_NSQ_noise_shape_feedback_loop_c(const opus_int32 *data0, opus_int32 *data1, const opus_int16 *coef, opus_int order) { +static OPUS_INLINE opus_int32 silk_NSQ_noise_shape_feedback_loop_c(const opus_int32 *data0, opus_int32 *data1, const opus_int16 *coef, opus_int order) +{ opus_int32 out; opus_int32 tmp1, tmp2; opus_int j; @@ -85,7 +88,7 @@ static OPUS_INLINE opus_int32 silk_NSQ_noise_shape_feedback_loop_c(const opus_in data1[order - 1] = tmp1; out = silk_SMLAWB(out, tmp1, coef[order - 1]); /* Q11 -> Q12 */ - out = silk_LSHIFT32(out, 1); + out = silk_LSHIFT32( out, 1 ); return out; } diff --git a/src/libopus/silk/NSQ_del_dec.c b/src/libopus/silk/NSQ_del_dec.c deleted file mode 100644 index 7268582..0000000 --- a/src/libopus/silk/NSQ_del_dec.c +++ /dev/null @@ -1,736 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif - -#include "main.h" -#include "../celt/stack_alloc.h" -#include "NSQ.h" - - -typedef struct { - opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ]; - opus_int32 RandState[ DECISION_DELAY ]; - opus_int32 Q_Q10[ DECISION_DELAY ]; - opus_int32 Xq_Q14[ DECISION_DELAY ]; - opus_int32 Pred_Q15[ DECISION_DELAY ]; - opus_int32 Shape_Q14[ DECISION_DELAY ]; - opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; - opus_int32 LF_AR_Q14; - opus_int32 Diff_Q14; - opus_int32 Seed; - opus_int32 SeedInit; - opus_int32 RD_Q10; -} NSQ_del_dec_struct; - -typedef struct { - opus_int32 Q_Q10; - opus_int32 RD_Q10; - opus_int32 xq_Q14; - opus_int32 LF_AR_Q14; - opus_int32 Diff_Q14; - opus_int32 sLTP_shp_Q14; - opus_int32 LPC_exc_Q14; -} NSQ_sample_struct; - -typedef NSQ_sample_struct NSQ_sample_pair[ 2 ]; - -#if defined(MIPSr1_ASM) -#include "mips/NSQ_del_dec_mipsr1.h" -#endif -static OPUS_INLINE void silk_nsq_del_dec_scale_states( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ - const opus_int16 x16[], /* I Input */ - opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ - const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ - opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ - opus_int subfr, /* I Subframe number */ - opus_int nStatesDelayedDecision, /* I Number of del dec states */ - const opus_int LTP_scale_Q14, /* I LTP state scaling */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag */ - const opus_int signal_type, /* I Signal type */ - const opus_int decisionDelay /* I Decision delay */ -); - -/******************************************/ -/* Noise shape quantizer for one subframe */ -/******************************************/ -static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( - silk_nsq_state *NSQ, /* I/O NSQ state */ - NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ - opus_int signalType, /* I Signal type */ - const opus_int32 x_Q10[], /* I */ - opus_int8 pulses[], /* O */ - opus_int16 xq[], /* O */ - opus_int32 sLTP_Q15[], /* I/O LTP filter state */ - opus_int32 delayedGain_Q10[], /* I/O Gain delay buffer */ - const opus_int16 a_Q12[], /* I Short term prediction coefs */ - const opus_int16 b_Q14[], /* I Long term prediction coefs */ - const opus_int16 AR_shp_Q13[], /* I Noise shaping coefs */ - opus_int lag, /* I Pitch lag */ - opus_int32 HarmShapeFIRPacked_Q14, /* I */ - opus_int Tilt_Q14, /* I Spectral tilt */ - opus_int32 LF_shp_Q14, /* I */ - opus_int32 Gain_Q16, /* I */ - opus_int Lambda_Q10, /* I */ - opus_int offset_Q10, /* I */ - opus_int length, /* I Input length */ - opus_int subfr, /* I Subframe number */ - opus_int shapingLPCOrder, /* I Shaping LPC filter order */ - opus_int predictLPCOrder, /* I Prediction filter order */ - opus_int warping_Q16, /* I */ - opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ - opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ - opus_int decisionDelay, /* I */ - int arch /* I */ -); - -void silk_NSQ_del_dec_c( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - SideInfoIndices *psIndices, /* I/O Quantization Indices */ - const opus_int16 x16[], /* I Input */ - opus_int8 pulses[], /* O Quantized pulse signal */ - const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ - const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ - const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ - const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ - const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ - const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ - const opus_int LTP_scale_Q14 /* I LTP state scaling */ -) { - opus_int i, k, lag, start_idx, LSF_interpolation_flag, Winner_ind, subfr; - opus_int last_smple_idx, smpl_buf_idx, decisionDelay; - const opus_int16 *A_Q12, *B_Q14, *AR_shp_Q13; - opus_int16 *pxq; - VARDECL(opus_int32, sLTP_Q15); - VARDECL(opus_int16, sLTP); - opus_int32 HarmShapeFIRPacked_Q14; - opus_int offset_Q10; - opus_int32 RDmin_Q10, Gain_Q10; - VARDECL(opus_int32, x_sc_Q10); - VARDECL(opus_int32, delayedGain_Q10); - VARDECL(NSQ_del_dec_struct, psDelDec); - NSQ_del_dec_struct *psDD; - SAVE_STACK; - - /* Set unvoiced lag to the previous one, overwrite later for voiced */ - lag = NSQ->lagPrev; - - silk_assert(NSQ->prev_gain_Q16 != 0); - - /* Initialize delayed decision states */ - ALLOC(psDelDec, psEncC->nStatesDelayedDecision, NSQ_del_dec_struct); - silk_memset(psDelDec, 0, psEncC->nStatesDelayedDecision * sizeof(NSQ_del_dec_struct)); - for (k = 0; k < psEncC->nStatesDelayedDecision; k++) { - psDD = &psDelDec[ k ]; - psDD->Seed = (k + psIndices->Seed) & 3; - psDD->SeedInit = psDD->Seed; - psDD->RD_Q10 = 0; - psDD->LF_AR_Q14 = NSQ->sLF_AR_shp_Q14; - psDD->Diff_Q14 = NSQ->sDiff_shp_Q14; - psDD->Shape_Q14[ 0 ] = NSQ->sLTP_shp_Q14[ psEncC->ltp_mem_length - 1 ]; - silk_memcpy(psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof(opus_int32)); - silk_memcpy(psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof(NSQ->sAR2_Q14)); - } - - offset_Q10 = silk_Quantization_Offsets_Q10[ psIndices->signalType >> 1 ][ psIndices->quantOffsetType ]; - smpl_buf_idx = 0; /* index of oldest samples */ - - decisionDelay = silk_min_int(DECISION_DELAY, psEncC->subfr_length); - - /* For voiced frames limit the decision delay to lower than the pitch lag */ - if (psIndices->signalType == TYPE_VOICED) { - for (k = 0; k < psEncC->nb_subfr; k++) { - decisionDelay = silk_min_int(decisionDelay, pitchL[ k ] - LTP_ORDER / 2 - 1); - } - } else { - if (lag > 0) { - decisionDelay = silk_min_int(decisionDelay, lag - LTP_ORDER / 2 - 1); - } - } - - if (psIndices->NLSFInterpCoef_Q2 == 4) { - LSF_interpolation_flag = 0; - } else { - LSF_interpolation_flag = 1; - } - - ALLOC(sLTP_Q15, psEncC->ltp_mem_length + psEncC->frame_length, opus_int32); - ALLOC(sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16); - ALLOC(x_sc_Q10, psEncC->subfr_length, opus_int32); - ALLOC(delayedGain_Q10, DECISION_DELAY, opus_int32); - /* Set up pointers to start of sub frame */ - pxq = &NSQ->xq[ psEncC->ltp_mem_length ]; - NSQ->sLTP_shp_buf_idx = psEncC->ltp_mem_length; - NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; - subfr = 0; - for (k = 0; k < psEncC->nb_subfr; k++) { - A_Q12 = &PredCoef_Q12[((k >> 1) | (1 - LSF_interpolation_flag)) * MAX_LPC_ORDER ]; - B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; - AR_shp_Q13 = &AR_Q13[ k * MAX_SHAPE_LPC_ORDER ]; - - /* Noise shape parameters */ - silk_assert(HarmShapeGain_Q14[ k ] >= 0); - HarmShapeFIRPacked_Q14 = silk_RSHIFT(HarmShapeGain_Q14[ k ], 2); - HarmShapeFIRPacked_Q14 |= silk_LSHIFT((opus_int32)silk_RSHIFT(HarmShapeGain_Q14[ k ], 1), 16); - - NSQ->rewhite_flag = 0; - if (psIndices->signalType == TYPE_VOICED) { - /* Voiced */ - lag = pitchL[ k ]; - - /* Re-whitening */ - if ((k & (3 - silk_LSHIFT(LSF_interpolation_flag, 1))) == 0) { - if (k == 2) { - /* RESET DELAYED DECISIONS */ - /* Find winner */ - RDmin_Q10 = psDelDec[ 0 ].RD_Q10; - Winner_ind = 0; - for (i = 1; i < psEncC->nStatesDelayedDecision; i++) { - if (psDelDec[ i ].RD_Q10 < RDmin_Q10) { - RDmin_Q10 = psDelDec[ i ].RD_Q10; - Winner_ind = i; - } - } - for (i = 0; i < psEncC->nStatesDelayedDecision; i++) { - if (i != Winner_ind) { - psDelDec[ i ].RD_Q10 += (silk_int32_MAX >> 4); - silk_assert(psDelDec[ i ].RD_Q10 >= 0); - } - } - - /* Copy final part of signals from winner state to output and long-term filter states */ - psDD = &psDelDec[ Winner_ind ]; - last_smple_idx = smpl_buf_idx + decisionDelay; - for (i = 0; i < decisionDelay; i++) { - last_smple_idx = (last_smple_idx - 1) % DECISION_DELAY; - if (last_smple_idx < 0) { - last_smple_idx += DECISION_DELAY; - } - pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND(psDD->Q_Q10[ last_smple_idx ], 10); - pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND( - silk_SMULWW(psDD->Xq_Q14[ last_smple_idx ], Gains_Q16[ 1 ]), 14)); - NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q14[ last_smple_idx ]; - } - - subfr = 0; - } - - /* Rewhiten with new A coefs */ - start_idx = psEncC->ltp_mem_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; - celt_assert(start_idx > 0); - - silk_LPC_analysis_filter(&sLTP[ start_idx ], &NSQ->xq[ start_idx + k * psEncC->subfr_length ], - A_Q12, psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder, psEncC->arch); - - NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; - NSQ->rewhite_flag = 1; - } - } - - silk_nsq_del_dec_scale_states(psEncC, NSQ, psDelDec, x16, x_sc_Q10, sLTP, sLTP_Q15, k, - psEncC->nStatesDelayedDecision, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType, decisionDelay); - - silk_noise_shape_quantizer_del_dec(NSQ, psDelDec, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, - delayedGain_Q10, A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], - Gains_Q16[ k ], Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, - psEncC->predictLPCOrder, psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay, psEncC->arch); - - x16 += psEncC->subfr_length; - pulses += psEncC->subfr_length; - pxq += psEncC->subfr_length; - } - - /* Find winner */ - RDmin_Q10 = psDelDec[ 0 ].RD_Q10; - Winner_ind = 0; - for (k = 1; k < psEncC->nStatesDelayedDecision; k++) { - if (psDelDec[ k ].RD_Q10 < RDmin_Q10) { - RDmin_Q10 = psDelDec[ k ].RD_Q10; - Winner_ind = k; - } - } - - /* Copy final part of signals from winner state to output and long-term filter states */ - psDD = &psDelDec[ Winner_ind ]; - psIndices->Seed = psDD->SeedInit; - last_smple_idx = smpl_buf_idx + decisionDelay; - Gain_Q10 = silk_RSHIFT32(Gains_Q16[ psEncC->nb_subfr - 1 ], 6); - for (i = 0; i < decisionDelay; i++) { - last_smple_idx = (last_smple_idx - 1) % DECISION_DELAY; - if (last_smple_idx < 0) { - last_smple_idx += DECISION_DELAY; - } - - pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND(psDD->Q_Q10[ last_smple_idx ], 10); - pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND( - silk_SMULWW(psDD->Xq_Q14[ last_smple_idx ], Gain_Q10), 8)); - NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q14[ last_smple_idx ]; - } - silk_memcpy(NSQ->sLPC_Q14, &psDD->sLPC_Q14[ psEncC->subfr_length ], NSQ_LPC_BUF_LENGTH * sizeof(opus_int32)); - silk_memcpy(NSQ->sAR2_Q14, psDD->sAR2_Q14, sizeof(psDD->sAR2_Q14)); - - /* Update states */ - NSQ->sLF_AR_shp_Q14 = psDD->LF_AR_Q14; - NSQ->sDiff_shp_Q14 = psDD->Diff_Q14; - NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; - - /* Save quantized speech signal */ - silk_memmove(NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof(opus_int16)); - silk_memmove(NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof(opus_int32)); - RESTORE_STACK; -} - -/******************************************/ -/* Noise shape quantizer for one subframe */ -/******************************************/ -#ifndef OVERRIDE_silk_noise_shape_quantizer_del_dec -static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( - silk_nsq_state *NSQ, /* I/O NSQ state */ - NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ - opus_int signalType, /* I Signal type */ - const opus_int32 x_Q10[], /* I */ - opus_int8 pulses[], /* O */ - opus_int16 xq[], /* O */ - opus_int32 sLTP_Q15[], /* I/O LTP filter state */ - opus_int32 delayedGain_Q10[], /* I/O Gain delay buffer */ - const opus_int16 a_Q12[], /* I Short term prediction coefs */ - const opus_int16 b_Q14[], /* I Long term prediction coefs */ - const opus_int16 AR_shp_Q13[], /* I Noise shaping coefs */ - opus_int lag, /* I Pitch lag */ - opus_int32 HarmShapeFIRPacked_Q14, /* I */ - opus_int Tilt_Q14, /* I Spectral tilt */ - opus_int32 LF_shp_Q14, /* I */ - opus_int32 Gain_Q16, /* I */ - opus_int Lambda_Q10, /* I */ - opus_int offset_Q10, /* I */ - opus_int length, /* I Input length */ - opus_int subfr, /* I Subframe number */ - opus_int shapingLPCOrder, /* I Shaping LPC filter order */ - opus_int predictLPCOrder, /* I Prediction filter order */ - opus_int warping_Q16, /* I */ - opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ - opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ - opus_int decisionDelay, /* I */ - int arch /* I */ -) { - opus_int i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx; - opus_int32 Winner_rand_state; - opus_int32 LTP_pred_Q14, LPC_pred_Q14, n_AR_Q14, n_LTP_Q14; - opus_int32 n_LF_Q14, r_Q10, rr_Q10, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10; - opus_int32 q1_Q0, q1_Q10, q2_Q10, exc_Q14, LPC_exc_Q14, xq_Q14, Gain_Q10; - opus_int32 tmp1, tmp2, sLF_AR_shp_Q14; - opus_int32 *pred_lag_ptr, *shp_lag_ptr, *psLPC_Q14; -#ifdef silk_short_prediction_create_arch_coef - opus_int32 a_Q12_arch[MAX_LPC_ORDER]; -#endif - - VARDECL(NSQ_sample_pair, psSampleState); - NSQ_del_dec_struct *psDD; - NSQ_sample_struct *psSS; - SAVE_STACK; - - celt_assert(nStatesDelayedDecision > 0); - ALLOC(psSampleState, nStatesDelayedDecision, NSQ_sample_pair); - - shp_lag_ptr = &NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ]; - pred_lag_ptr = &sLTP_Q15[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ]; - Gain_Q10 = silk_RSHIFT(Gain_Q16, 6); - -#ifdef silk_short_prediction_create_arch_coef - silk_short_prediction_create_arch_coef(a_Q12_arch, a_Q12, predictLPCOrder); -#endif - - for (i = 0; i < length; i++) { - /* Perform common calculations used in all states */ - - /* Long-term prediction */ - if (signalType == TYPE_VOICED) { - /* Unrolled loop */ - /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ - LTP_pred_Q14 = 2; - LTP_pred_Q14 = silk_SMLAWB(LTP_pred_Q14, pred_lag_ptr[ 0 ], b_Q14[ 0 ]); - LTP_pred_Q14 = silk_SMLAWB(LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ]); - LTP_pred_Q14 = silk_SMLAWB(LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ]); - LTP_pred_Q14 = silk_SMLAWB(LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ]); - LTP_pred_Q14 = silk_SMLAWB(LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ]); - LTP_pred_Q14 = silk_LSHIFT(LTP_pred_Q14, 1); /* Q13 -> Q14 */ - pred_lag_ptr++; - } else { - LTP_pred_Q14 = 0; - } - - /* Long-term shaping */ - if (lag > 0) { - /* Symmetric, packed FIR coefficients */ - n_LTP_Q14 = silk_SMULWB(silk_ADD32(shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ]), HarmShapeFIRPacked_Q14); - n_LTP_Q14 = silk_SMLAWT(n_LTP_Q14, shp_lag_ptr[ -1 ], HarmShapeFIRPacked_Q14); - n_LTP_Q14 = silk_SUB_LSHIFT32(LTP_pred_Q14, n_LTP_Q14, 2); /* Q12 -> Q14 */ - shp_lag_ptr++; - } else { - n_LTP_Q14 = 0; - } - - for (k = 0; k < nStatesDelayedDecision; k++) { - /* Delayed decision state */ - psDD = &psDelDec[ k ]; - - /* Sample state */ - psSS = psSampleState[ k ]; - - /* Generate dither */ - psDD->Seed = silk_RAND(psDD->Seed); - - /* Pointer used in short term prediction and shaping */ - psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ]; - /* Short-term prediction */ - LPC_pred_Q14 = silk_noise_shape_quantizer_short_prediction(psLPC_Q14, a_Q12, a_Q12_arch, predictLPCOrder, arch); - LPC_pred_Q14 = silk_LSHIFT(LPC_pred_Q14, 4); /* Q10 -> Q14 */ - - /* Noise shape feedback */ - celt_assert((shapingLPCOrder & 1) == 0); /* check that order is even */ - /* Output of lowpass section */ - tmp2 = silk_SMLAWB(psDD->Diff_Q14, psDD->sAR2_Q14[ 0 ], warping_Q16); - /* Output of allpass section */ - tmp1 = silk_SMLAWB(psDD->sAR2_Q14[ 0 ], psDD->sAR2_Q14[ 1 ] - tmp2, warping_Q16); - psDD->sAR2_Q14[ 0 ] = tmp2; - n_AR_Q14 = silk_RSHIFT(shapingLPCOrder, 1); - n_AR_Q14 = silk_SMLAWB(n_AR_Q14, tmp2, AR_shp_Q13[ 0 ]); - /* Loop over allpass sections */ - for (j = 2; j < shapingLPCOrder; j += 2) { - /* Output of allpass section */ - tmp2 = silk_SMLAWB(psDD->sAR2_Q14[ j - 1 ], psDD->sAR2_Q14[ j + 0 ] - tmp1, warping_Q16); - psDD->sAR2_Q14[ j - 1 ] = tmp1; - n_AR_Q14 = silk_SMLAWB(n_AR_Q14, tmp1, AR_shp_Q13[ j - 1 ]); - /* Output of allpass section */ - tmp1 = silk_SMLAWB(psDD->sAR2_Q14[ j + 0 ], psDD->sAR2_Q14[ j + 1 ] - tmp2, warping_Q16); - psDD->sAR2_Q14[ j + 0 ] = tmp2; - n_AR_Q14 = silk_SMLAWB(n_AR_Q14, tmp2, AR_shp_Q13[ j ]); - } - psDD->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1; - n_AR_Q14 = silk_SMLAWB(n_AR_Q14, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ]); - - n_AR_Q14 = silk_LSHIFT(n_AR_Q14, 1); /* Q11 -> Q12 */ - n_AR_Q14 = silk_SMLAWB(n_AR_Q14, psDD->LF_AR_Q14, Tilt_Q14); /* Q12 */ - n_AR_Q14 = silk_LSHIFT(n_AR_Q14, 2); /* Q12 -> Q14 */ - - n_LF_Q14 = silk_SMULWB(psDD->Shape_Q14[ *smpl_buf_idx ], LF_shp_Q14); /* Q12 */ - n_LF_Q14 = silk_SMLAWT(n_LF_Q14, psDD->LF_AR_Q14, LF_shp_Q14); /* Q12 */ - n_LF_Q14 = silk_LSHIFT(n_LF_Q14, 2); /* Q12 -> Q14 */ - - /* Input minus prediction plus noise feedback */ - /* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP */ - tmp1 = silk_ADD32(n_AR_Q14, n_LF_Q14); /* Q14 */ - tmp2 = silk_ADD32(n_LTP_Q14, LPC_pred_Q14); /* Q13 */ - tmp1 = silk_SUB32(tmp2, tmp1); /* Q13 */ - tmp1 = silk_RSHIFT_ROUND(tmp1, 4); /* Q10 */ - - r_Q10 = silk_SUB32(x_Q10[ i ], tmp1); /* residual error Q10 */ - - /* Flip sign depending on dither */ - if (psDD->Seed < 0) { - r_Q10 = -r_Q10; - } - r_Q10 = silk_LIMIT_32(r_Q10, -(31 << 10), 30 << 10); - - /* Find two quantization level candidates and measure their rate-distortion */ - q1_Q10 = silk_SUB32(r_Q10, offset_Q10); - q1_Q0 = silk_RSHIFT(q1_Q10, 10); - if (Lambda_Q10 > 2048) { - /* For aggressive RDO, the bias becomes more than one pulse. */ - int rdo_offset = Lambda_Q10 / 2 - 512; - if (q1_Q10 > rdo_offset) { - q1_Q0 = silk_RSHIFT(q1_Q10 - rdo_offset, 10); - } else if (q1_Q10 < -rdo_offset) { - q1_Q0 = silk_RSHIFT(q1_Q10 + rdo_offset, 10); - } else if (q1_Q10 < 0) { - q1_Q0 = -1; - } else { - q1_Q0 = 0; - } - } - if (q1_Q0 > 0) { - q1_Q10 = silk_SUB32(silk_LSHIFT(q1_Q0, 10), QUANT_LEVEL_ADJUST_Q10); - q1_Q10 = silk_ADD32(q1_Q10, offset_Q10); - q2_Q10 = silk_ADD32(q1_Q10, 1024); - rd1_Q10 = silk_SMULBB(q1_Q10, Lambda_Q10); - rd2_Q10 = silk_SMULBB(q2_Q10, Lambda_Q10); - } else if (q1_Q0 == 0) { - q1_Q10 = offset_Q10; - q2_Q10 = silk_ADD32(q1_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10); - rd1_Q10 = silk_SMULBB(q1_Q10, Lambda_Q10); - rd2_Q10 = silk_SMULBB(q2_Q10, Lambda_Q10); - } else if (q1_Q0 == -1) { - q2_Q10 = offset_Q10; - q1_Q10 = silk_SUB32(q2_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10); - rd1_Q10 = silk_SMULBB(-q1_Q10, Lambda_Q10); - rd2_Q10 = silk_SMULBB(q2_Q10, Lambda_Q10); - } else { /* q1_Q0 < -1 */ - q1_Q10 = silk_ADD32(silk_LSHIFT(q1_Q0, 10), QUANT_LEVEL_ADJUST_Q10); - q1_Q10 = silk_ADD32(q1_Q10, offset_Q10); - q2_Q10 = silk_ADD32(q1_Q10, 1024); - rd1_Q10 = silk_SMULBB(-q1_Q10, Lambda_Q10); - rd2_Q10 = silk_SMULBB(-q2_Q10, Lambda_Q10); - } - rr_Q10 = silk_SUB32(r_Q10, q1_Q10); - rd1_Q10 = silk_RSHIFT(silk_SMLABB(rd1_Q10, rr_Q10, rr_Q10), 10); - rr_Q10 = silk_SUB32(r_Q10, q2_Q10); - rd2_Q10 = silk_RSHIFT(silk_SMLABB(rd2_Q10, rr_Q10, rr_Q10), 10); - - if (rd1_Q10 < rd2_Q10) { - psSS[ 0 ].RD_Q10 = silk_ADD32(psDD->RD_Q10, rd1_Q10); - psSS[ 1 ].RD_Q10 = silk_ADD32(psDD->RD_Q10, rd2_Q10); - psSS[ 0 ].Q_Q10 = q1_Q10; - psSS[ 1 ].Q_Q10 = q2_Q10; - } else { - psSS[ 0 ].RD_Q10 = silk_ADD32(psDD->RD_Q10, rd2_Q10); - psSS[ 1 ].RD_Q10 = silk_ADD32(psDD->RD_Q10, rd1_Q10); - psSS[ 0 ].Q_Q10 = q2_Q10; - psSS[ 1 ].Q_Q10 = q1_Q10; - } - - /* Update states for best quantization */ - - /* Quantized excitation */ - exc_Q14 = silk_LSHIFT32(psSS[ 0 ].Q_Q10, 4); - if (psDD->Seed < 0) { - exc_Q14 = -exc_Q14; - } - - /* Add predictions */ - LPC_exc_Q14 = silk_ADD32(exc_Q14, LTP_pred_Q14); - xq_Q14 = silk_ADD32(LPC_exc_Q14, LPC_pred_Q14); - - /* Update states */ - psSS[ 0 ].Diff_Q14 = silk_SUB_LSHIFT32(xq_Q14, x_Q10[ i ], 4); - sLF_AR_shp_Q14 = silk_SUB32(psSS[ 0 ].Diff_Q14, n_AR_Q14); - psSS[ 0 ].sLTP_shp_Q14 = silk_SUB32(sLF_AR_shp_Q14, n_LF_Q14); - psSS[ 0 ].LF_AR_Q14 = sLF_AR_shp_Q14; - psSS[ 0 ].LPC_exc_Q14 = LPC_exc_Q14; - psSS[ 0 ].xq_Q14 = xq_Q14; - - /* Update states for second best quantization */ - - /* Quantized excitation */ - exc_Q14 = silk_LSHIFT32(psSS[ 1 ].Q_Q10, 4); - if (psDD->Seed < 0) { - exc_Q14 = -exc_Q14; - } - - /* Add predictions */ - LPC_exc_Q14 = silk_ADD32(exc_Q14, LTP_pred_Q14); - xq_Q14 = silk_ADD32(LPC_exc_Q14, LPC_pred_Q14); - - /* Update states */ - psSS[ 1 ].Diff_Q14 = silk_SUB_LSHIFT32(xq_Q14, x_Q10[ i ], 4); - sLF_AR_shp_Q14 = silk_SUB32(psSS[ 1 ].Diff_Q14, n_AR_Q14); - psSS[ 1 ].sLTP_shp_Q14 = silk_SUB32(sLF_AR_shp_Q14, n_LF_Q14); - psSS[ 1 ].LF_AR_Q14 = sLF_AR_shp_Q14; - psSS[ 1 ].LPC_exc_Q14 = LPC_exc_Q14; - psSS[ 1 ].xq_Q14 = xq_Q14; - } - - *smpl_buf_idx = (*smpl_buf_idx - 1) % DECISION_DELAY; - if (*smpl_buf_idx < 0) { - *smpl_buf_idx += DECISION_DELAY; - } - last_smple_idx = (*smpl_buf_idx + decisionDelay) % DECISION_DELAY; - - /* Find winner */ - RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10; - Winner_ind = 0; - for (k = 1; k < nStatesDelayedDecision; k++) { - if (psSampleState[ k ][ 0 ].RD_Q10 < RDmin_Q10) { - RDmin_Q10 = psSampleState[ k ][ 0 ].RD_Q10; - Winner_ind = k; - } - } - - /* Increase RD values of expired states */ - Winner_rand_state = psDelDec[ Winner_ind ].RandState[ last_smple_idx ]; - for (k = 0; k < nStatesDelayedDecision; k++) { - if (psDelDec[ k ].RandState[ last_smple_idx ] != Winner_rand_state) { - psSampleState[ k ][ 0 ].RD_Q10 = silk_ADD32(psSampleState[ k ][ 0 ].RD_Q10, silk_int32_MAX >> 4); - psSampleState[ k ][ 1 ].RD_Q10 = silk_ADD32(psSampleState[ k ][ 1 ].RD_Q10, silk_int32_MAX >> 4); - silk_assert(psSampleState[ k ][ 0 ].RD_Q10 >= 0); - } - } - - /* Find worst in first set and best in second set */ - RDmax_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10; - RDmin_Q10 = psSampleState[ 0 ][ 1 ].RD_Q10; - RDmax_ind = 0; - RDmin_ind = 0; - for (k = 1; k < nStatesDelayedDecision; k++) { - /* find worst in first set */ - if (psSampleState[ k ][ 0 ].RD_Q10 > RDmax_Q10) { - RDmax_Q10 = psSampleState[ k ][ 0 ].RD_Q10; - RDmax_ind = k; - } - /* find best in second set */ - if (psSampleState[ k ][ 1 ].RD_Q10 < RDmin_Q10) { - RDmin_Q10 = psSampleState[ k ][ 1 ].RD_Q10; - RDmin_ind = k; - } - } - - /* Replace a state if best from second set outperforms worst in first set */ - if (RDmin_Q10 < RDmax_Q10) { - silk_memcpy(((opus_int32 *)&psDelDec[ RDmax_ind ]) + i, - ((opus_int32 *)&psDelDec[ RDmin_ind ]) + i, sizeof(NSQ_del_dec_struct) - i * sizeof(opus_int32)); - silk_memcpy(&psSampleState[ RDmax_ind ][ 0 ], &psSampleState[ RDmin_ind ][ 1 ], sizeof(NSQ_sample_struct)); - } - - /* Write samples from winner to output and long-term filter states */ - psDD = &psDelDec[ Winner_ind ]; - if (subfr > 0 || i >= decisionDelay) { - pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND(psDD->Q_Q10[ last_smple_idx ], 10); - xq[ i - decisionDelay ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND( - silk_SMULWW(psDD->Xq_Q14[ last_smple_idx ], delayedGain_Q10[ last_smple_idx ]), 8)); - NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q14[ last_smple_idx ]; - sLTP_Q15[ NSQ->sLTP_buf_idx - decisionDelay ] = psDD->Pred_Q15[ last_smple_idx ]; - } - NSQ->sLTP_shp_buf_idx++; - NSQ->sLTP_buf_idx++; - - /* Update states */ - for (k = 0; k < nStatesDelayedDecision; k++) { - psDD = &psDelDec[ k ]; - psSS = &psSampleState[ k ][ 0 ]; - psDD->LF_AR_Q14 = psSS->LF_AR_Q14; - psDD->Diff_Q14 = psSS->Diff_Q14; - psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ] = psSS->xq_Q14; - psDD->Xq_Q14[ *smpl_buf_idx ] = psSS->xq_Q14; - psDD->Q_Q10[ *smpl_buf_idx ] = psSS->Q_Q10; - psDD->Pred_Q15[ *smpl_buf_idx ] = silk_LSHIFT32(psSS->LPC_exc_Q14, 1); - psDD->Shape_Q14[ *smpl_buf_idx ] = psSS->sLTP_shp_Q14; - psDD->Seed = silk_ADD32_ovflw(psDD->Seed, silk_RSHIFT_ROUND(psSS->Q_Q10, 10)); - psDD->RandState[ *smpl_buf_idx ] = psDD->Seed; - psDD->RD_Q10 = psSS->RD_Q10; - } - delayedGain_Q10[ *smpl_buf_idx ] = Gain_Q10; - } - /* Update LPC states */ - for (k = 0; k < nStatesDelayedDecision; k++) { - psDD = &psDelDec[ k ]; - silk_memcpy(psDD->sLPC_Q14, &psDD->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof(opus_int32)); - } - RESTORE_STACK; -} -#endif /* OVERRIDE_silk_noise_shape_quantizer_del_dec */ - -static OPUS_INLINE void silk_nsq_del_dec_scale_states( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ - const opus_int16 x16[], /* I Input */ - opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ - const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ - opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ - opus_int subfr, /* I Subframe number */ - opus_int nStatesDelayedDecision, /* I Number of del dec states */ - const opus_int LTP_scale_Q14, /* I LTP state scaling */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag */ - const opus_int signal_type, /* I Signal type */ - const opus_int decisionDelay /* I Decision delay */ -) { - opus_int i, k, lag; - opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q26; - NSQ_del_dec_struct *psDD; - - lag = pitchL[ subfr ]; - inv_gain_Q31 = silk_INVERSE32_varQ(silk_max(Gains_Q16[ subfr ], 1), 47); - silk_assert(inv_gain_Q31 != 0); - - /* Scale input */ - inv_gain_Q26 = silk_RSHIFT_ROUND(inv_gain_Q31, 5); - for (i = 0; i < psEncC->subfr_length; i++) { - x_sc_Q10[ i ] = silk_SMULWW(x16[ i ], inv_gain_Q26); - } - - /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */ - if (NSQ->rewhite_flag) { - if (subfr == 0) { - /* Do LTP downscaling */ - inv_gain_Q31 = silk_LSHIFT(silk_SMULWB(inv_gain_Q31, LTP_scale_Q14), 2); - } - for (i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++) { - silk_assert(i < MAX_FRAME_LENGTH); - sLTP_Q15[ i ] = silk_SMULWB(inv_gain_Q31, sLTP[ i ]); - } - } - - /* Adjust for changing gain */ - if (Gains_Q16[ subfr ] != NSQ->prev_gain_Q16) { - gain_adj_Q16 = silk_DIV32_varQ(NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16); - - /* Scale long-term shaping state */ - for (i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx; i++) { - NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW(gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ]); - } - - /* Scale long-term prediction state */ - if (signal_type == TYPE_VOICED && NSQ->rewhite_flag == 0) { - for (i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx - decisionDelay; i++) { - sLTP_Q15[ i ] = silk_SMULWW(gain_adj_Q16, sLTP_Q15[ i ]); - } - } - - for (k = 0; k < nStatesDelayedDecision; k++) { - psDD = &psDelDec[ k ]; - - /* Scale scalar states */ - psDD->LF_AR_Q14 = silk_SMULWW(gain_adj_Q16, psDD->LF_AR_Q14); - psDD->Diff_Q14 = silk_SMULWW(gain_adj_Q16, psDD->Diff_Q14); - - /* Scale short-term prediction and shaping states */ - for (i = 0; i < NSQ_LPC_BUF_LENGTH; i++) { - psDD->sLPC_Q14[ i ] = silk_SMULWW(gain_adj_Q16, psDD->sLPC_Q14[ i ]); - } - for (i = 0; i < MAX_SHAPE_LPC_ORDER; i++) { - psDD->sAR2_Q14[ i ] = silk_SMULWW(gain_adj_Q16, psDD->sAR2_Q14[ i ]); - } - for (i = 0; i < DECISION_DELAY; i++) { - psDD->Pred_Q15[ i ] = silk_SMULWW(gain_adj_Q16, psDD->Pred_Q15[ i ]); - psDD->Shape_Q14[ i ] = silk_SMULWW(gain_adj_Q16, psDD->Shape_Q14[ i ]); - } - } - - /* Save inverse gain */ - NSQ->prev_gain_Q16 = Gains_Q16[ subfr ]; - } -} diff --git a/src/libopus/silk/PLC.c b/src/libopus/silk/PLC.c index 7d6f57f..d9c6c40 100644 --- a/src/libopus/silk/PLC.c +++ b/src/libopus/silk/PLC.c @@ -1,38 +1,42 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" #include "PLC.h" +#ifdef ENABLE_DEEP_PLC +#include "lpcnet.h" +#endif + #define NB_ATT 2 static const opus_int16 HARM_ATT_Q15[NB_ATT] = { 32440, 31130 }; /* 0.99, 0.95 */ static const opus_int16 PLC_RAND_ATTENUATE_V_Q15[NB_ATT] = { 31130, 26214 }; /* 0.95, 0.8 */ @@ -47,16 +51,20 @@ static OPUS_INLINE void silk_PLC_conceal( silk_decoder_state *psDec, /* I/O Decoder state */ silk_decoder_control *psDecCtrl, /* I/O Decoder control */ opus_int16 frame[], /* O LPC residual signal */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif int arch /* I Run-time architecture */ ); void silk_PLC_Reset( silk_decoder_state *psDec /* I/O Decoder state */ -) { - psDec->sPLC.pitchL_Q8 = silk_LSHIFT(psDec->frame_length, 8 - 1); - psDec->sPLC.prevGain_Q16[ 0 ] = SILK_FIX_CONST(1, 16); - psDec->sPLC.prevGain_Q16[ 1 ] = SILK_FIX_CONST(1, 16); +) +{ + psDec->sPLC.pitchL_Q8 = silk_LSHIFT( psDec->frame_length, 8 - 1 ); + psDec->sPLC.prevGain_Q16[ 0 ] = SILK_FIX_CONST( 1, 16 ); + psDec->sPLC.prevGain_Q16[ 1 ] = SILK_FIX_CONST( 1, 16 ); psDec->sPLC.subfr_length = 20; psDec->sPLC.nb_subfr = 2; } @@ -66,26 +74,42 @@ void silk_PLC( silk_decoder_control *psDecCtrl, /* I/O Decoder control */ opus_int16 frame[], /* I/O signal */ opus_int lost, /* I Loss flag */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif int arch /* I Run-time architecture */ -) { +) +{ /* PLC control function */ - if (psDec->fs_kHz != psDec->sPLC.fs_kHz) { - silk_PLC_Reset(psDec); + if( psDec->fs_kHz != psDec->sPLC.fs_kHz ) { + silk_PLC_Reset( psDec ); psDec->sPLC.fs_kHz = psDec->fs_kHz; } - if (lost) { + if( lost ) { /****************************/ /* Generate Signal */ /****************************/ - silk_PLC_conceal(psDec, psDecCtrl, frame, arch); + silk_PLC_conceal( psDec, psDecCtrl, frame, +#ifdef ENABLE_DEEP_PLC + lpcnet, +#endif + arch ); psDec->lossCnt++; } else { /****************************/ /* Update state */ /****************************/ - silk_PLC_update(psDec, psDecCtrl); + silk_PLC_update( psDec, psDecCtrl ); +#ifdef ENABLE_DEEP_PLC + if ( lpcnet != NULL && psDec->sPLC.fs_kHz == 16 ) { + int k; + for( k = 0; k < psDec->nb_subfr; k += 2 ) { + lpcnet_plc_update( lpcnet, frame + k * psDec->subfr_length ); + } + } +#endif } } @@ -95,7 +119,8 @@ void silk_PLC( static OPUS_INLINE void silk_PLC_update( silk_decoder_state *psDec, /* I/O Decoder state */ silk_decoder_control *psDecCtrl /* I/O Decoder control */ -) { +) +{ opus_int32 LTP_Gain_Q14, temp_LTP_Gain_Q14; opus_int i, j; silk_PLC_struct *psPLC; @@ -105,85 +130,86 @@ static OPUS_INLINE void silk_PLC_update( /* Update parameters used in case of packet loss */ psDec->prevSignalType = psDec->indices.signalType; LTP_Gain_Q14 = 0; - if (psDec->indices.signalType == TYPE_VOICED) { + if( psDec->indices.signalType == TYPE_VOICED ) { /* Find the parameters for the last subframe which contains a pitch pulse */ - for (j = 0; j * psDec->subfr_length < psDecCtrl->pitchL[ psDec->nb_subfr - 1 ]; j++) { - if (j == psDec->nb_subfr) { + for( j = 0; j * psDec->subfr_length < psDecCtrl->pitchL[ psDec->nb_subfr - 1 ]; j++ ) { + if( j == psDec->nb_subfr ) { break; } temp_LTP_Gain_Q14 = 0; - for (i = 0; i < LTP_ORDER; i++) { - temp_LTP_Gain_Q14 += psDecCtrl->LTPCoef_Q14[(psDec->nb_subfr - 1 - j) * LTP_ORDER + i ]; + for( i = 0; i < LTP_ORDER; i++ ) { + temp_LTP_Gain_Q14 += psDecCtrl->LTPCoef_Q14[ ( psDec->nb_subfr - 1 - j ) * LTP_ORDER + i ]; } - if (temp_LTP_Gain_Q14 > LTP_Gain_Q14) { + if( temp_LTP_Gain_Q14 > LTP_Gain_Q14 ) { LTP_Gain_Q14 = temp_LTP_Gain_Q14; - silk_memcpy(psPLC->LTPCoef_Q14, - &psDecCtrl->LTPCoef_Q14[ silk_SMULBB(psDec->nb_subfr - 1 - j, LTP_ORDER) ], - LTP_ORDER * sizeof(opus_int16)); + silk_memcpy( psPLC->LTPCoef_Q14, + &psDecCtrl->LTPCoef_Q14[ silk_SMULBB( psDec->nb_subfr - 1 - j, LTP_ORDER ) ], + LTP_ORDER * sizeof( opus_int16 ) ); - psPLC->pitchL_Q8 = silk_LSHIFT(psDecCtrl->pitchL[ psDec->nb_subfr - 1 - j ], 8); + psPLC->pitchL_Q8 = silk_LSHIFT( psDecCtrl->pitchL[ psDec->nb_subfr - 1 - j ], 8 ); } } - silk_memset(psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof(opus_int16)); + silk_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( opus_int16 ) ); psPLC->LTPCoef_Q14[ LTP_ORDER / 2 ] = LTP_Gain_Q14; /* Limit LT coefs */ - if (LTP_Gain_Q14 < V_PITCH_GAIN_START_MIN_Q14) { + if( LTP_Gain_Q14 < V_PITCH_GAIN_START_MIN_Q14 ) { opus_int scale_Q10; opus_int32 tmp; - tmp = silk_LSHIFT(V_PITCH_GAIN_START_MIN_Q14, 10); - scale_Q10 = silk_DIV32(tmp, silk_max(LTP_Gain_Q14, 1)); - for (i = 0; i < LTP_ORDER; i++) { - psPLC->LTPCoef_Q14[ i ] = silk_RSHIFT(silk_SMULBB(psPLC->LTPCoef_Q14[ i ], scale_Q10), 10); + tmp = silk_LSHIFT( V_PITCH_GAIN_START_MIN_Q14, 10 ); + scale_Q10 = silk_DIV32( tmp, silk_max( LTP_Gain_Q14, 1 ) ); + for( i = 0; i < LTP_ORDER; i++ ) { + psPLC->LTPCoef_Q14[ i ] = silk_RSHIFT( silk_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q10 ), 10 ); } - } else if (LTP_Gain_Q14 > V_PITCH_GAIN_START_MAX_Q14) { + } else if( LTP_Gain_Q14 > V_PITCH_GAIN_START_MAX_Q14 ) { opus_int scale_Q14; opus_int32 tmp; - tmp = silk_LSHIFT(V_PITCH_GAIN_START_MAX_Q14, 14); - scale_Q14 = silk_DIV32(tmp, silk_max(LTP_Gain_Q14, 1)); - for (i = 0; i < LTP_ORDER; i++) { - psPLC->LTPCoef_Q14[ i ] = silk_RSHIFT(silk_SMULBB(psPLC->LTPCoef_Q14[ i ], scale_Q14), 14); + tmp = silk_LSHIFT( V_PITCH_GAIN_START_MAX_Q14, 14 ); + scale_Q14 = silk_DIV32( tmp, silk_max( LTP_Gain_Q14, 1 ) ); + for( i = 0; i < LTP_ORDER; i++ ) { + psPLC->LTPCoef_Q14[ i ] = silk_RSHIFT( silk_SMULBB( psPLC->LTPCoef_Q14[ i ], scale_Q14 ), 14 ); } } } else { - psPLC->pitchL_Q8 = silk_LSHIFT(silk_SMULBB(psDec->fs_kHz, 18), 8); - silk_memset(psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof(opus_int16)); + psPLC->pitchL_Q8 = silk_LSHIFT( silk_SMULBB( psDec->fs_kHz, 18 ), 8 ); + silk_memset( psPLC->LTPCoef_Q14, 0, LTP_ORDER * sizeof( opus_int16 )); } /* Save LPC coeficients */ - silk_memcpy(psPLC->prevLPC_Q12, psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof(opus_int16)); + silk_memcpy( psPLC->prevLPC_Q12, psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) ); psPLC->prevLTP_scale_Q14 = psDecCtrl->LTP_scale_Q14; /* Save last two gains */ - silk_memcpy(psPLC->prevGain_Q16, &psDecCtrl->Gains_Q16[ psDec->nb_subfr - 2 ], 2 * sizeof(opus_int32)); + silk_memcpy( psPLC->prevGain_Q16, &psDecCtrl->Gains_Q16[ psDec->nb_subfr - 2 ], 2 * sizeof( opus_int32 ) ); psPLC->subfr_length = psDec->subfr_length; psPLC->nb_subfr = psDec->nb_subfr; } static OPUS_INLINE void silk_PLC_energy(opus_int32 *energy1, opus_int *shift1, opus_int32 *energy2, opus_int *shift2, - const opus_int32 *exc_Q14, const opus_int32 *prevGain_Q10, int subfr_length, int nb_subfr) { + const opus_int32 *exc_Q14, const opus_int32 *prevGain_Q10, int subfr_length, int nb_subfr) +{ int i, k; - VARDECL(opus_int16, exc_buf); + VARDECL( opus_int16, exc_buf ); opus_int16 *exc_buf_ptr; SAVE_STACK; - ALLOC(exc_buf, 2 * subfr_length, opus_int16); + ALLOC( exc_buf, 2*subfr_length, opus_int16 ); /* Find random noise component */ /* Scale previous excitation signal */ exc_buf_ptr = exc_buf; - for (k = 0; k < 2; k++) { - for (i = 0; i < subfr_length; i++) { - exc_buf_ptr[ i ] = (opus_int16)silk_SAT16(silk_RSHIFT( - silk_SMULWW(exc_Q14[ i + (k + nb_subfr - 2) * subfr_length ], prevGain_Q10[ k ]), 8)); + for( k = 0; k < 2; k++ ) { + for( i = 0; i < subfr_length; i++ ) { + exc_buf_ptr[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT( + silk_SMULWW( exc_Q14[ i + ( k + nb_subfr - 2 ) * subfr_length ], prevGain_Q10[ k ] ), 8 ) ); } exc_buf_ptr += subfr_length; } /* Find the subframe with lowest energy of the last two and use that as random noise generator */ - silk_sum_sqr_shift(energy1, shift1, exc_buf, subfr_length); - silk_sum_sqr_shift(energy2, shift2, &exc_buf[ subfr_length ], subfr_length); + silk_sum_sqr_shift( energy1, shift1, exc_buf, subfr_length ); + silk_sum_sqr_shift( energy2, shift2, &exc_buf[ subfr_length ], subfr_length ); RESTORE_STACK; } @@ -191,8 +217,12 @@ static OPUS_INLINE void silk_PLC_conceal( silk_decoder_state *psDec, /* I/O Decoder state */ silk_decoder_control *psDecCtrl, /* I/O Decoder control */ opus_int16 frame[], /* O LPC residual signal */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif int arch /* I Run-time architecture */ -) { +) +{ opus_int i, j, k; opus_int lag, idx, sLTP_buf_idx, shift1, shift2; opus_int32 rand_seed, harm_Gain_Q15, rand_Gain_Q15, inv_gain_Q30; @@ -205,36 +235,36 @@ static OPUS_INLINE void silk_PLC_conceal( #ifdef SMALL_FOOTPRINT opus_int16 *sLTP; #else - VARDECL(opus_int16, sLTP); + VARDECL( opus_int16, sLTP ); #endif - VARDECL(opus_int32, sLTP_Q14); + VARDECL( opus_int32, sLTP_Q14 ); silk_PLC_struct *psPLC = &psDec->sPLC; opus_int32 prevGain_Q10[2]; SAVE_STACK; - ALLOC(sLTP_Q14, psDec->ltp_mem_length + psDec->frame_length, opus_int32); + ALLOC( sLTP_Q14, psDec->ltp_mem_length + psDec->frame_length, opus_int32 ); #ifdef SMALL_FOOTPRINT /* Ugly hack that breaks aliasing rules to save stack: put sLTP at the very end of sLTP_Q14. */ - sLTP = ((opus_int16*)&sLTP_Q14[psDec->ltp_mem_length + psDec->frame_length]) - psDec->ltp_mem_length; + sLTP = ((opus_int16*)&sLTP_Q14[psDec->ltp_mem_length + psDec->frame_length])-psDec->ltp_mem_length; #else - ALLOC(sLTP, psDec->ltp_mem_length, opus_int16); + ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 ); #endif - prevGain_Q10[0] = silk_RSHIFT(psPLC->prevGain_Q16[ 0 ], 6); - prevGain_Q10[1] = silk_RSHIFT(psPLC->prevGain_Q16[ 1 ], 6); + prevGain_Q10[0] = silk_RSHIFT( psPLC->prevGain_Q16[ 0 ], 6); + prevGain_Q10[1] = silk_RSHIFT( psPLC->prevGain_Q16[ 1 ], 6); - if (psDec->first_frame_after_reset) { - silk_memset(psPLC->prevLPC_Q12, 0, sizeof(psPLC->prevLPC_Q12)); + if( psDec->first_frame_after_reset ) { + silk_memset( psPLC->prevLPC_Q12, 0, sizeof( psPLC->prevLPC_Q12 ) ); } silk_PLC_energy(&energy1, &shift1, &energy2, &shift2, psDec->exc_Q14, prevGain_Q10, psDec->subfr_length, psDec->nb_subfr); - if (silk_RSHIFT(energy1, shift2) < silk_RSHIFT(energy2, shift1)) { + if( silk_RSHIFT( energy1, shift2 ) < silk_RSHIFT( energy2, shift1 ) ) { /* First sub-frame has lowest energy */ - rand_ptr = &psDec->exc_Q14[ silk_max_int(0, (psPLC->nb_subfr - 1) * psPLC->subfr_length - RAND_BUF_SIZE) ]; + rand_ptr = &psDec->exc_Q14[ silk_max_int( 0, ( psPLC->nb_subfr - 1 ) * psPLC->subfr_length - RAND_BUF_SIZE ) ]; } else { /* Second sub-frame has lowest energy */ - rand_ptr = &psDec->exc_Q14[ silk_max_int(0, psPLC->nb_subfr * psPLC->subfr_length - RAND_BUF_SIZE) ]; + rand_ptr = &psDec->exc_Q14[ silk_max_int( 0, psPLC->nb_subfr * psPLC->subfr_length - RAND_BUF_SIZE ) ]; } /* Set up Gain to random noise component */ @@ -242,96 +272,94 @@ static OPUS_INLINE void silk_PLC_conceal( rand_scale_Q14 = psPLC->randScale_Q14; /* Set up attenuation gains */ - harm_Gain_Q15 = HARM_ATT_Q15[ silk_min_int(NB_ATT - 1, psDec->lossCnt) ]; - if (psDec->prevSignalType == TYPE_VOICED) { - rand_Gain_Q15 = PLC_RAND_ATTENUATE_V_Q15[ silk_min_int(NB_ATT - 1, psDec->lossCnt) ]; + harm_Gain_Q15 = HARM_ATT_Q15[ silk_min_int( NB_ATT - 1, psDec->lossCnt ) ]; + if( psDec->prevSignalType == TYPE_VOICED ) { + rand_Gain_Q15 = PLC_RAND_ATTENUATE_V_Q15[ silk_min_int( NB_ATT - 1, psDec->lossCnt ) ]; } else { - rand_Gain_Q15 = PLC_RAND_ATTENUATE_UV_Q15[ silk_min_int(NB_ATT - 1, psDec->lossCnt) ]; + rand_Gain_Q15 = PLC_RAND_ATTENUATE_UV_Q15[ silk_min_int( NB_ATT - 1, psDec->lossCnt ) ]; } /* LPC concealment. Apply BWE to previous LPC */ - silk_bwexpander(psPLC->prevLPC_Q12, psDec->LPC_order, SILK_FIX_CONST(BWE_COEF, 16)); + silk_bwexpander( psPLC->prevLPC_Q12, psDec->LPC_order, SILK_FIX_CONST( BWE_COEF, 16 ) ); /* Preload LPC coeficients to array on stack. Gives small performance gain */ - silk_memcpy(A_Q12, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof(opus_int16)); + silk_memcpy( A_Q12, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof( opus_int16 ) ); /* First Lost frame */ - if (psDec->lossCnt == 0) { + if( psDec->lossCnt == 0 ) { rand_scale_Q14 = 1 << 14; /* Reduce random noise Gain for voiced frames */ - if (psDec->prevSignalType == TYPE_VOICED) { - for (i = 0; i < LTP_ORDER; i++) { + if( psDec->prevSignalType == TYPE_VOICED ) { + for( i = 0; i < LTP_ORDER; i++ ) { rand_scale_Q14 -= B_Q14[ i ]; } - rand_scale_Q14 = silk_max_16(3277, rand_scale_Q14); /* 0.2 */ - rand_scale_Q14 = (opus_int16)silk_RSHIFT(silk_SMULBB(rand_scale_Q14, psPLC->prevLTP_scale_Q14), 14); + rand_scale_Q14 = silk_max_16( 3277, rand_scale_Q14 ); /* 0.2 */ + rand_scale_Q14 = (opus_int16)silk_RSHIFT( silk_SMULBB( rand_scale_Q14, psPLC->prevLTP_scale_Q14 ), 14 ); } else { /* Reduce random noise for unvoiced frames with high LPC gain */ opus_int32 invGain_Q30, down_scale_Q30; - invGain_Q30 = silk_LPC_inverse_pred_gain(psPLC->prevLPC_Q12, psDec->LPC_order, arch); + invGain_Q30 = silk_LPC_inverse_pred_gain( psPLC->prevLPC_Q12, psDec->LPC_order, arch ); - down_scale_Q30 = silk_min_32(silk_RSHIFT((opus_int32)1 << 30, LOG2_INV_LPC_GAIN_HIGH_THRES), invGain_Q30); - down_scale_Q30 = silk_max_32(silk_RSHIFT((opus_int32)1 << 30, LOG2_INV_LPC_GAIN_LOW_THRES), down_scale_Q30); - down_scale_Q30 = silk_LSHIFT(down_scale_Q30, LOG2_INV_LPC_GAIN_HIGH_THRES); + down_scale_Q30 = silk_min_32( silk_RSHIFT( (opus_int32)1 << 30, LOG2_INV_LPC_GAIN_HIGH_THRES ), invGain_Q30 ); + down_scale_Q30 = silk_max_32( silk_RSHIFT( (opus_int32)1 << 30, LOG2_INV_LPC_GAIN_LOW_THRES ), down_scale_Q30 ); + down_scale_Q30 = silk_LSHIFT( down_scale_Q30, LOG2_INV_LPC_GAIN_HIGH_THRES ); - rand_Gain_Q15 = silk_RSHIFT(silk_SMULWB(down_scale_Q30, rand_Gain_Q15), 14); + rand_Gain_Q15 = silk_RSHIFT( silk_SMULWB( down_scale_Q30, rand_Gain_Q15 ), 14 ); } } rand_seed = psPLC->rand_seed; - lag = silk_RSHIFT_ROUND(psPLC->pitchL_Q8, 8); + lag = silk_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 ); sLTP_buf_idx = psDec->ltp_mem_length; /* Rewhiten LTP state */ idx = psDec->ltp_mem_length - lag - psDec->LPC_order - LTP_ORDER / 2; - celt_assert(idx > 0); - silk_LPC_analysis_filter(&sLTP[ idx ], &psDec->outBuf[ idx ], A_Q12, psDec->ltp_mem_length - idx, psDec->LPC_order, arch); + celt_assert( idx > 0 ); + silk_LPC_analysis_filter( &sLTP[ idx ], &psDec->outBuf[ idx ], A_Q12, psDec->ltp_mem_length - idx, psDec->LPC_order, arch ); /* Scale LTP state */ - inv_gain_Q30 = silk_INVERSE32_varQ(psPLC->prevGain_Q16[ 1 ], 46); - inv_gain_Q30 = silk_min(inv_gain_Q30, silk_int32_MAX >> 1); - for (i = idx + psDec->LPC_order; i < psDec->ltp_mem_length; i++) { - sLTP_Q14[ i ] = silk_SMULWB(inv_gain_Q30, sLTP[ i ]); + inv_gain_Q30 = silk_INVERSE32_varQ( psPLC->prevGain_Q16[ 1 ], 46 ); + inv_gain_Q30 = silk_min( inv_gain_Q30, silk_int32_MAX >> 1 ); + for( i = idx + psDec->LPC_order; i < psDec->ltp_mem_length; i++ ) { + sLTP_Q14[ i ] = silk_SMULWB( inv_gain_Q30, sLTP[ i ] ); } /***************************/ /* LTP synthesis filtering */ /***************************/ - for (k = 0; k < psDec->nb_subfr; k++) { + for( k = 0; k < psDec->nb_subfr; k++ ) { /* Set up pointer */ pred_lag_ptr = &sLTP_Q14[ sLTP_buf_idx - lag + LTP_ORDER / 2 ]; - for (i = 0; i < psDec->subfr_length; i++) { + for( i = 0; i < psDec->subfr_length; i++ ) { /* Unrolled loop */ /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ LTP_pred_Q12 = 2; - LTP_pred_Q12 = silk_SMLAWB(LTP_pred_Q12, pred_lag_ptr[ 0 ], B_Q14[ 0 ]); - LTP_pred_Q12 = silk_SMLAWB(LTP_pred_Q12, pred_lag_ptr[ -1 ], B_Q14[ 1 ]); - LTP_pred_Q12 = silk_SMLAWB(LTP_pred_Q12, pred_lag_ptr[ -2 ], B_Q14[ 2 ]); - LTP_pred_Q12 = silk_SMLAWB(LTP_pred_Q12, pred_lag_ptr[ -3 ], B_Q14[ 3 ]); - LTP_pred_Q12 = silk_SMLAWB(LTP_pred_Q12, pred_lag_ptr[ -4 ], B_Q14[ 4 ]); + LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ 0 ], B_Q14[ 0 ] ); + LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -1 ], B_Q14[ 1 ] ); + LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -2 ], B_Q14[ 2 ] ); + LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -3 ], B_Q14[ 3 ] ); + LTP_pred_Q12 = silk_SMLAWB( LTP_pred_Q12, pred_lag_ptr[ -4 ], B_Q14[ 4 ] ); pred_lag_ptr++; /* Generate LPC excitation */ - rand_seed = silk_RAND(rand_seed); - idx = silk_RSHIFT(rand_seed, 25) & RAND_BUF_MASK; - sLTP_Q14[ sLTP_buf_idx ] = silk_LSHIFT32(silk_SMLAWB(LTP_pred_Q12, rand_ptr[ idx ], rand_scale_Q14), 2); + rand_seed = silk_RAND( rand_seed ); + idx = silk_RSHIFT( rand_seed, 25 ) & RAND_BUF_MASK; + sLTP_Q14[ sLTP_buf_idx ] = silk_LSHIFT32( silk_SMLAWB( LTP_pred_Q12, rand_ptr[ idx ], rand_scale_Q14 ), 2 ); sLTP_buf_idx++; } /* Gradually reduce LTP gain */ - for (j = 0; j < LTP_ORDER; j++) { - B_Q14[ j ] = silk_RSHIFT(silk_SMULBB(harm_Gain_Q15, B_Q14[ j ]), 15); - } - if (psDec->indices.signalType != TYPE_NO_VOICE_ACTIVITY) { - /* Gradually reduce excitation gain */ - rand_scale_Q14 = silk_RSHIFT(silk_SMULBB(rand_scale_Q14, rand_Gain_Q15), 15); + for( j = 0; j < LTP_ORDER; j++ ) { + B_Q14[ j ] = silk_RSHIFT( silk_SMULBB( harm_Gain_Q15, B_Q14[ j ] ), 15 ); } + /* Gradually reduce excitation gain */ + rand_scale_Q14 = silk_RSHIFT( silk_SMULBB( rand_scale_Q14, rand_Gain_Q15 ), 15 ); /* Slowly increase pitch lag */ - psPLC->pitchL_Q8 = silk_SMLAWB(psPLC->pitchL_Q8, psPLC->pitchL_Q8, PITCH_DRIFT_FAC_Q16); - psPLC->pitchL_Q8 = silk_min_32(psPLC->pitchL_Q8, silk_LSHIFT(silk_SMULBB(MAX_PITCH_LAG_MS, psDec->fs_kHz), 8)); - lag = silk_RSHIFT_ROUND(psPLC->pitchL_Q8, 8); + psPLC->pitchL_Q8 = silk_SMLAWB( psPLC->pitchL_Q8, psPLC->pitchL_Q8, PITCH_DRIFT_FAC_Q16 ); + psPLC->pitchL_Q8 = silk_min_32( psPLC->pitchL_Q8, silk_LSHIFT( silk_SMULBB( MAX_PITCH_LAG_MS, psDec->fs_kHz ), 8 ) ); + lag = silk_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 ); } /***************************/ @@ -340,44 +368,62 @@ static OPUS_INLINE void silk_PLC_conceal( sLPC_Q14_ptr = &sLTP_Q14[ psDec->ltp_mem_length - MAX_LPC_ORDER ]; /* Copy LPC state */ - silk_memcpy(sLPC_Q14_ptr, psDec->sLPC_Q14_buf, MAX_LPC_ORDER * sizeof(opus_int32)); + silk_memcpy( sLPC_Q14_ptr, psDec->sLPC_Q14_buf, MAX_LPC_ORDER * sizeof( opus_int32 ) ); - celt_assert(psDec->LPC_order >= 10); /* check that unrolling works */ - for (i = 0; i < psDec->frame_length; i++) { + celt_assert( psDec->LPC_order >= 10 ); /* check that unrolling works */ + for( i = 0; i < psDec->frame_length; i++ ) { /* partly unrolled */ /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ - LPC_pred_Q10 = silk_RSHIFT(psDec->LPC_order, 1); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ]); - for (j = 10; j < psDec->LPC_order; j++) { - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - j - 1 ], A_Q12[ j ]); + LPC_pred_Q10 = silk_RSHIFT( psDec->LPC_order, 1 ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ] ); + for( j = 10; j < psDec->LPC_order; j++ ) { + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14_ptr[ MAX_LPC_ORDER + i - j - 1 ], A_Q12[ j ] ); } /* Add prediction to LPC excitation */ - sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32(sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], - silk_LSHIFT_SAT32(LPC_pred_Q10, 4)); + sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], + silk_LSHIFT_SAT32( LPC_pred_Q10, 4 )); /* Scale with Gain */ - frame[ i ] = (opus_int16)silk_SAT16(silk_SAT16(silk_RSHIFT_ROUND(silk_SMULWW(sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], prevGain_Q10[ 1 ]), 8))); + frame[ i ] = (opus_int16)silk_SAT16( silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], prevGain_Q10[ 1 ] ), 8 ) ) ); } +#ifdef ENABLE_DEEP_PLC + if ( lpcnet != NULL && lpcnet->loaded && psDec->sPLC.fs_kHz == 16 ) { + int run_deep_plc = psDec->sPLC.enable_deep_plc || lpcnet->fec_fill_pos != 0; + if( run_deep_plc ) { + for( k = 0; k < psDec->nb_subfr; k += 2 ) { + lpcnet_plc_conceal( lpcnet, frame + k * psDec->subfr_length ); + } + /* We *should* be able to copy only from psDec->frame_length-MAX_LPC_ORDER, i.e. the last MAX_LPC_ORDER samples. */ + for( i = 0; i < psDec->frame_length; i++ ) { + sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = (int)floor(.5 + frame[ i ] * (float)(1 << 24) / prevGain_Q10[ 1 ] ); + } + } else { + for( k = 0; k < psDec->nb_subfr; k += 2 ) { + lpcnet_plc_update( lpcnet, frame + k * psDec->subfr_length ); + } + } + } +#endif /* Save LPC state */ - silk_memcpy(psDec->sLPC_Q14_buf, &sLPC_Q14_ptr[ psDec->frame_length ], MAX_LPC_ORDER * sizeof(opus_int32)); + silk_memcpy( psDec->sLPC_Q14_buf, &sLPC_Q14_ptr[ psDec->frame_length ], MAX_LPC_ORDER * sizeof( opus_int32 ) ); /**************************************/ /* Update states */ /**************************************/ psPLC->rand_seed = rand_seed; psPLC->randScale_Q14 = rand_scale_Q14; - for (i = 0; i < MAX_NB_SUBFR; i++) { + for( i = 0; i < MAX_NB_SUBFR; i++ ) { psDecCtrl->pitchL[ i ] = lag; } RESTORE_STACK; @@ -388,51 +434,56 @@ void silk_PLC_glue_frames( silk_decoder_state *psDec, /* I/O decoder state */ opus_int16 frame[], /* I/O signal */ opus_int length /* I length of signal */ -) { +) +{ opus_int i, energy_shift; opus_int32 energy; silk_PLC_struct *psPLC; psPLC = &psDec->sPLC; - if (psDec->lossCnt) { + if( psDec->lossCnt ) { /* Calculate energy in concealed residual */ - silk_sum_sqr_shift(&psPLC->conc_energy, &psPLC->conc_energy_shift, frame, length); + silk_sum_sqr_shift( &psPLC->conc_energy, &psPLC->conc_energy_shift, frame, length ); psPLC->last_frame_lost = 1; } else { - if (psDec->sPLC.last_frame_lost) { + if( psDec->sPLC.last_frame_lost ) { /* Calculate residual in decoded signal if last frame was lost */ - silk_sum_sqr_shift(&energy, &energy_shift, frame, length); + silk_sum_sqr_shift( &energy, &energy_shift, frame, length ); /* Normalize energies */ - if (energy_shift > psPLC->conc_energy_shift) { - psPLC->conc_energy = silk_RSHIFT(psPLC->conc_energy, energy_shift - psPLC->conc_energy_shift); - } else if (energy_shift < psPLC->conc_energy_shift) { - energy = silk_RSHIFT(energy, psPLC->conc_energy_shift - energy_shift); + if( energy_shift > psPLC->conc_energy_shift ) { + psPLC->conc_energy = silk_RSHIFT( psPLC->conc_energy, energy_shift - psPLC->conc_energy_shift ); + } else if( energy_shift < psPLC->conc_energy_shift ) { + energy = silk_RSHIFT( energy, psPLC->conc_energy_shift - energy_shift ); } /* Fade in the energy difference */ - if (energy > psPLC->conc_energy) { + if( energy > psPLC->conc_energy ) { opus_int32 frac_Q24, LZ; opus_int32 gain_Q16, slope_Q16; - LZ = silk_CLZ32(psPLC->conc_energy); + LZ = silk_CLZ32( psPLC->conc_energy ); LZ = LZ - 1; - psPLC->conc_energy = silk_LSHIFT(psPLC->conc_energy, LZ); - energy = silk_RSHIFT(energy, silk_max_32(24 - LZ, 0)); + psPLC->conc_energy = silk_LSHIFT( psPLC->conc_energy, LZ ); + energy = silk_RSHIFT( energy, silk_max_32( 24 - LZ, 0 ) ); - frac_Q24 = silk_DIV32(psPLC->conc_energy, silk_max(energy, 1)); + frac_Q24 = silk_DIV32( psPLC->conc_energy, silk_max( energy, 1 ) ); - gain_Q16 = silk_LSHIFT(silk_SQRT_APPROX(frac_Q24), 4); - slope_Q16 = silk_DIV32_16(((opus_int32)1 << 16) - gain_Q16, length); + gain_Q16 = silk_LSHIFT( silk_SQRT_APPROX( frac_Q24 ), 4 ); + slope_Q16 = silk_DIV32_16( ( (opus_int32)1 << 16 ) - gain_Q16, length ); /* Make slope 4x steeper to avoid missing onsets after DTX */ - slope_Q16 = silk_LSHIFT(slope_Q16, 2); - - for (i = 0; i < length; i++) { - frame[ i ] = silk_SMULWB(gain_Q16, frame[ i ]); - gain_Q16 += slope_Q16; - if (gain_Q16 > (opus_int32)1 << 16) { - break; + slope_Q16 = silk_LSHIFT( slope_Q16, 2 ); +#ifdef ENABLE_DEEP_PLC + if ( psDec->sPLC.fs_kHz != 16 ) +#endif + { + for( i = 0; i < length; i++ ) { + frame[ i ] = silk_SMULWB( gain_Q16, frame[ i ] ); + gain_Q16 += slope_Q16; + if( gain_Q16 > (opus_int32)1 << 16 ) { + break; + } } } } diff --git a/src/libopus/silk/PLC.h b/src/libopus/silk/PLC.h index 12e125f..1bebb78 100644 --- a/src/libopus/silk/PLC.h +++ b/src/libopus/silk/PLC.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_PLC_H @@ -49,6 +49,9 @@ void silk_PLC( silk_decoder_control *psDecCtrl, /* I/O Decoder control */ opus_int16 frame[], /* I/O signal */ opus_int lost, /* I Loss flag */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif int arch /* I Run-time architecture */ ); diff --git a/src/libopus/silk/SigProc_FIX.h b/src/libopus/silk/SigProc_FIX.h index 7aa706a..fbdfa82 100644 --- a/src/libopus/silk/SigProc_FIX.h +++ b/src/libopus/silk/SigProc_FIX.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_SIGPROC_FIX_H @@ -41,7 +41,7 @@ extern "C" #include "typedef.h" #include "resampler_structs.h" #include "macros.h" -#include "../celt/cpu_support.h" +#include "cpu_support.h" #if defined(OPUS_X86_MAY_HAVE_SSE4_1) #include "x86/SigProc_FIX_sse.h" @@ -57,7 +57,7 @@ extern "C" /********************************************************************/ /*! - Initialize/reset the resampler state for a given pair of input/output sampling rates + * Initialize/reset the resampler state for a given pair of input/output sampling rates */ opus_int silk_resampler_init( silk_resampler_state_struct *S, /* I/O Resampler state */ @@ -67,8 +67,8 @@ opus_int silk_resampler_init( ); /*! - Resampler: convert from one sampling rate to another -*/ + * Resampler: convert from one sampling rate to another + */ opus_int silk_resampler( silk_resampler_state_struct *S, /* I/O Resampler state */ opus_int16 out[], /* O Output signal */ @@ -77,7 +77,7 @@ opus_int silk_resampler( ); /*! - Downsample 2x, mediocre quality +* Downsample 2x, mediocre quality */ void silk_resampler_down2( opus_int32 *S, /* I/O State vector [ 2 ] */ @@ -87,7 +87,7 @@ void silk_resampler_down2( ); /*! - Downsample by a factor 2/3, low quality + * Downsample by a factor 2/3, low quality */ void silk_resampler_down2_3( opus_int32 *S, /* I/O State vector [ 6 ] */ @@ -97,10 +97,10 @@ void silk_resampler_down2_3( ); /*! - second order ARMA filter; - slower than biquad() but uses more precise coefficients - can handle (slowly) varying coefficients -*/ + * second order ARMA filter; + * slower than biquad() but uses more precise coefficients + * can handle (slowly) varying coefficients + */ void silk_biquad_alt_stride1( const opus_int16 *in, /* I input signal */ const opus_int32 *B_Q28, /* I MA coefficients [3] */ @@ -314,13 +314,13 @@ void silk_insertion_sort_decreasing_int16( ); void silk_insertion_sort_increasing_all_values_int16( - opus_int16 *a, /* I/O Unsorted / Sorted vector */ - const opus_int L /* I Vector length */ + opus_int16 *a, /* I/O Unsorted / Sorted vector */ + const opus_int L /* I Vector length */ ); /* NLSF stabilizer, for a single input data vector */ void silk_NLSF_stabilize( - opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */ + opus_int16 *NLSF_Q15, /* I/O Unstable/stabilized normalized LSF vector in Q15 [L] */ const opus_int16 *NDeltaMin_Q15, /* I Min distance vector, NDeltaMin_Q15[L] must be >= 1 [L+1] */ const opus_int L /* I Number of NLSF parameters in the input vector */ ); @@ -381,7 +381,7 @@ opus_int32 silk_inner_prod_aligned_scale( const opus_int len /* I vector lengths */ ); -opus_int64 silk_inner_prod16_aligned_64_c( +opus_int64 silk_inner_prod16_c( const opus_int16 *inVec1, /* I input vector 1 */ const opus_int16 *inVec2, /* I input vector 2 */ const opus_int len /* I vector lengths */ @@ -391,20 +391,21 @@ opus_int64 silk_inner_prod16_aligned_64_c( /* MACROS */ /********************************************************************/ -/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating - left. Output is 32bit int. - Note: contemporary compilers recognize the C expression below and - compile it into a 'ror' instruction if available. No need for OPUS_INLINE ASM! */ -static OPUS_INLINE opus_int32 silk_ROR32(opus_int32 a32, opus_int rot) { +/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating + left. Output is 32bit int. + Note: contemporary compilers recognize the C expression below and + compile it into a 'ror' instruction if available. No need for OPUS_INLINE ASM! */ +static OPUS_INLINE opus_int32 silk_ROR32( opus_int32 a32, opus_int rot ) +{ opus_uint32 x = (opus_uint32) a32; opus_uint32 r = (opus_uint32) rot; - opus_uint32 m = (opus_uint32) - rot; - if (rot == 0) { + opus_uint32 m = (opus_uint32) -rot; + if( rot == 0 ) { return a32; - } else if (rot < 0) { - return (opus_int32)((x << m) | (x >> (32 - m))); + } else if( rot < 0 ) { + return (opus_int32) ((x << m) | (x >> (32 - m))); } else { - return (opus_int32)((x << (32 - r)) | (x >> r)); + return (opus_int32) ((x << (32 - r)) | (x >> r)); } } @@ -445,11 +446,11 @@ static OPUS_INLINE opus_int32 silk_ROR32(opus_int32 a32, opus_int rot) { /* (a32 * b32) */ #define silk_SMULL(a32, b32) ((opus_int64)(a32) * /*(opus_int64)*/(b32)) -/* Adds two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour - (just standard two's complement implementation-specific behaviour) */ +/* Adds two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour + (just standard two's complement implementation-specific behaviour) */ #define silk_ADD32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) + (opus_uint32)(b))) -/* Subtractss two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour - (just standard two's complement implementation-specific behaviour) */ +/* Subtractss two signed 32-bit values in a way that can overflow, while not relying on undefined behaviour + (just standard two's complement implementation-specific behaviour) */ #define silk_SUB32_ovflw(a, b) ((opus_int32)((opus_uint32)(a) - (opus_uint32)(b))) /* Multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) */ @@ -542,30 +543,38 @@ static OPUS_INLINE opus_int32 silk_ROR32(opus_int32 a32, opus_int rot) { #define SILK_FIX_CONST( C, Q ) ((opus_int32)((C) * ((opus_int64)1 << (Q)) + 0.5)) /* silk_min() versions with typecast in the function call */ -static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) { +static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) +{ return (((a) < (b)) ? (a) : (b)); } -static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b) { +static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b) +{ return (((a) < (b)) ? (a) : (b)); } -static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b) { +static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b) +{ return (((a) < (b)) ? (a) : (b)); } -static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b) +{ return (((a) < (b)) ? (a) : (b)); } /* silk_min() versions with typecast in the function call */ -static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b) { +static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b) +{ return (((a) > (b)) ? (a) : (b)); } -static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b) { +static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b) +{ return (((a) > (b)) ? (a) : (b)); } -static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b) { +static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b) +{ return (((a) > (b)) ? (a) : (b)); } -static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) { +static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) +{ return (((a) > (b)) ? (a) : (b)); } @@ -600,12 +609,14 @@ static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) { /* the following seems faster on x86 */ #define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT64(silk_SMULL((a32), (b32)), 32) -#if !defined(OPUS_X86_MAY_HAVE_SSE4_1) +#if !defined(OVERRIDE_silk_burg_modified) #define silk_burg_modified(res_nrg, res_nrg_Q, A_Q16, x, minInvGain_Q30, subfr_length, nb_subfr, D, arch) \ ((void)(arch), silk_burg_modified_c(res_nrg, res_nrg_Q, A_Q16, x, minInvGain_Q30, subfr_length, nb_subfr, D, arch)) +#endif -#define silk_inner_prod16_aligned_64(inVec1, inVec2, len, arch) \ - ((void)(arch),silk_inner_prod16_aligned_64_c(inVec1, inVec2, len)) +#if !defined(OVERRIDE_silk_inner_prod16) +#define silk_inner_prod16(inVec1, inVec2, len, arch) \ + ((void)(arch),silk_inner_prod16_c(inVec1, inVec2, len)) #endif #include "Inlines.h" diff --git a/src/libopus/silk/VAD.c b/src/libopus/silk/VAD.c deleted file mode 100644 index 31fa97d..0000000 --- a/src/libopus/silk/VAD.c +++ /dev/null @@ -1,358 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif -#include - -#include "main.h" -#include "../celt/stack_alloc.h" - -/* Silk VAD noise level estimation */ -# if !defined(OPUS_X86_MAY_HAVE_SSE4_1) -static OPUS_INLINE void silk_VAD_GetNoiseLevels( - const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies */ - silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */ -); -#endif - -/**********************************/ -/* Initialization of the Silk VAD */ -/**********************************/ -opus_int silk_VAD_Init( /* O Return value, 0 if success */ - silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */ -) { - opus_int b, ret = 0; - - /* reset state memory */ - silk_memset(psSilk_VAD, 0, sizeof(silk_VAD_state)); - - /* init noise levels */ - /* Initialize array with approx pink noise levels (psd proportional to inverse of frequency) */ - for (b = 0; b < VAD_N_BANDS; b++) { - psSilk_VAD->NoiseLevelBias[ b ] = silk_max_32(silk_DIV32_16(VAD_NOISE_LEVELS_BIAS, b + 1), 1); - } - - /* Initialize state */ - for (b = 0; b < VAD_N_BANDS; b++) { - psSilk_VAD->NL[ b ] = silk_MUL(100, psSilk_VAD->NoiseLevelBias[ b ]); - psSilk_VAD->inv_NL[ b ] = silk_DIV32(silk_int32_MAX, psSilk_VAD->NL[ b ]); - } - psSilk_VAD->counter = 15; - - /* init smoothed energy-to-noise ratio*/ - for (b = 0; b < VAD_N_BANDS; b++) { - psSilk_VAD->NrgRatioSmth_Q8[ b ] = 100 * 256; /* 100 * 256 --> 20 dB SNR */ - } - - return (ret); -} - -/* Weighting factors for tilt measure */ -static const opus_int32 tiltWeights[ VAD_N_BANDS ] PROGMEM = { 30000, 6000, -12000, -12000 }; - -/***************************************/ -/* Get the speech activity level in Q8 */ -/***************************************/ -opus_int silk_VAD_GetSA_Q8_c( /* O Return value, 0 if success */ - silk_encoder_state *psEncC, /* I/O Encoder state */ - const opus_int16 pIn[] /* I PCM input */ -) { - opus_int SA_Q15, pSNR_dB_Q7, input_tilt; - opus_int decimated_framelength1, decimated_framelength2; - opus_int decimated_framelength; - opus_int dec_subframe_length, dec_subframe_offset, SNR_Q7, i, b, s; - opus_int32 sumSquared, smooth_coef_Q16; - opus_int16 HPstateTmp; - VARDECL(opus_int16, X); - opus_int32 Xnrg[ VAD_N_BANDS ]; - opus_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ]; - opus_int32 speech_nrg, x_tmp; - opus_int X_offset[ VAD_N_BANDS ]; - opus_int ret = 0; - silk_VAD_state *psSilk_VAD = &psEncC->sVAD; - SAVE_STACK; - - /* Safety checks */ - silk_assert(VAD_N_BANDS == 4); - celt_assert(MAX_FRAME_LENGTH >= psEncC->frame_length); - celt_assert(psEncC->frame_length <= 512); - celt_assert(psEncC->frame_length == 8 * silk_RSHIFT(psEncC->frame_length, 3)); - - /***********************/ - /* Filter and Decimate */ - /***********************/ - decimated_framelength1 = silk_RSHIFT(psEncC->frame_length, 1); - decimated_framelength2 = silk_RSHIFT(psEncC->frame_length, 2); - decimated_framelength = silk_RSHIFT(psEncC->frame_length, 3); - /* Decimate into 4 bands: - 0 L 3L L 3L 5L - - -- - -- -- - 8 8 2 4 4 - - [0-1 kHz| temp. |1-2 kHz| 2-4 kHz | 4-8 kHz | - - They're arranged to allow the minimal ( frame_length / 4 ) extra - scratch space during the downsampling process */ - X_offset[ 0 ] = 0; - X_offset[ 1 ] = decimated_framelength + decimated_framelength2; - X_offset[ 2 ] = X_offset[ 1 ] + decimated_framelength; - X_offset[ 3 ] = X_offset[ 2 ] + decimated_framelength2; - ALLOC(X, X_offset[ 3 ] + decimated_framelength1, opus_int16); - - /* 0-8 kHz to 0-4 kHz and 4-8 kHz */ - silk_ana_filt_bank_1(pIn, &psSilk_VAD->AnaState[ 0 ], - X, &X[ X_offset[ 3 ] ], psEncC->frame_length); - - /* 0-4 kHz to 0-2 kHz and 2-4 kHz */ - silk_ana_filt_bank_1(X, &psSilk_VAD->AnaState1[ 0 ], - X, &X[ X_offset[ 2 ] ], decimated_framelength1); - - /* 0-2 kHz to 0-1 kHz and 1-2 kHz */ - silk_ana_filt_bank_1(X, &psSilk_VAD->AnaState2[ 0 ], - X, &X[ X_offset[ 1 ] ], decimated_framelength2); - - /*********************************************/ - /* HP filter on lowest band (differentiator) */ - /*********************************************/ - X[ decimated_framelength - 1 ] = silk_RSHIFT(X[ decimated_framelength - 1 ], 1); - HPstateTmp = X[ decimated_framelength - 1 ]; - for (i = decimated_framelength - 1; i > 0; i--) { - X[ i - 1 ] = silk_RSHIFT(X[ i - 1 ], 1); - X[ i ] -= X[ i - 1 ]; - } - X[ 0 ] -= psSilk_VAD->HPstate; - psSilk_VAD->HPstate = HPstateTmp; - - /*************************************/ - /* Calculate the energy in each band */ - /*************************************/ - for (b = 0; b < VAD_N_BANDS; b++) { - /* Find the decimated framelength in the non-uniformly divided bands */ - decimated_framelength = silk_RSHIFT(psEncC->frame_length, silk_min_int(VAD_N_BANDS - b, VAD_N_BANDS - 1)); - - /* Split length into subframe lengths */ - dec_subframe_length = silk_RSHIFT(decimated_framelength, VAD_INTERNAL_SUBFRAMES_LOG2); - dec_subframe_offset = 0; - - /* Compute energy per sub-frame */ - /* initialize with summed energy of last subframe */ - Xnrg[ b ] = psSilk_VAD->XnrgSubfr[ b ]; - for (s = 0; s < VAD_INTERNAL_SUBFRAMES; s++) { - sumSquared = 0; - for (i = 0; i < dec_subframe_length; i++) { - /* The energy will be less than dec_subframe_length * ( silk_int16_MIN / 8 ) ^ 2. */ - /* Therefore we can accumulate with no risk of overflow (unless dec_subframe_length > 128) */ - x_tmp = silk_RSHIFT( - X[ X_offset[ b ] + i + dec_subframe_offset ], 3); - sumSquared = silk_SMLABB(sumSquared, x_tmp, x_tmp); - - /* Safety check */ - silk_assert(sumSquared >= 0); - } - - /* Add/saturate summed energy of current subframe */ - if (s < VAD_INTERNAL_SUBFRAMES - 1) { - Xnrg[ b ] = silk_ADD_POS_SAT32(Xnrg[ b ], sumSquared); - } else { - /* Look-ahead subframe */ - Xnrg[ b ] = silk_ADD_POS_SAT32(Xnrg[ b ], silk_RSHIFT(sumSquared, 1)); - } - - dec_subframe_offset += dec_subframe_length; - } - psSilk_VAD->XnrgSubfr[ b ] = sumSquared; - } - - /********************/ - /* Noise estimation */ - /********************/ - silk_VAD_GetNoiseLevels(&Xnrg[ 0 ], psSilk_VAD); - - /***********************************************/ - /* Signal-plus-noise to noise ratio estimation */ - /***********************************************/ - sumSquared = 0; - input_tilt = 0; - for (b = 0; b < VAD_N_BANDS; b++) { - speech_nrg = Xnrg[ b ] - psSilk_VAD->NL[ b ]; - if (speech_nrg > 0) { - /* Divide, with sufficient resolution */ - if ((Xnrg[ b ] & 0xFF800000) == 0) { - NrgToNoiseRatio_Q8[ b ] = silk_DIV32(silk_LSHIFT(Xnrg[ b ], 8), psSilk_VAD->NL[ b ] + 1); - } else { - NrgToNoiseRatio_Q8[ b ] = silk_DIV32(Xnrg[ b ], silk_RSHIFT(psSilk_VAD->NL[ b ], 8) + 1); - } - - /* Convert to log domain */ - SNR_Q7 = silk_lin2log(NrgToNoiseRatio_Q8[ b ]) - 8 * 128; - - /* Sum-of-squares */ - sumSquared = silk_SMLABB(sumSquared, SNR_Q7, SNR_Q7); /* Q14 */ - - /* Tilt measure */ - if (speech_nrg < ((opus_int32)1 << 20)) { - /* Scale down SNR value for small subband speech energies */ - SNR_Q7 = silk_SMULWB(silk_LSHIFT(silk_SQRT_APPROX(speech_nrg), 6), SNR_Q7); - } - input_tilt = silk_SMLAWB(input_tilt, tiltWeights[ b ], SNR_Q7); - } else { - NrgToNoiseRatio_Q8[ b ] = 256; - } - } - - /* Mean-of-squares */ - sumSquared = silk_DIV32_16(sumSquared, VAD_N_BANDS); /* Q14 */ - - /* Root-mean-square approximation, scale to dBs, and write to output pointer */ - pSNR_dB_Q7 = (opus_int16)(3 * silk_SQRT_APPROX(sumSquared)); /* Q7 */ - - /*********************************/ - /* Speech Probability Estimation */ - /*********************************/ - SA_Q15 = silk_sigm_Q15(silk_SMULWB(VAD_SNR_FACTOR_Q16, pSNR_dB_Q7) - VAD_NEGATIVE_OFFSET_Q5); - - /**************************/ - /* Frequency Tilt Measure */ - /**************************/ - psEncC->input_tilt_Q15 = silk_LSHIFT(silk_sigm_Q15(input_tilt) - 16384, 1); - - /**************************************************/ - /* Scale the sigmoid output based on power levels */ - /**************************************************/ - speech_nrg = 0; - for (b = 0; b < VAD_N_BANDS; b++) { - /* Accumulate signal-without-noise energies, higher frequency bands have more weight */ - speech_nrg += (b + 1) * silk_RSHIFT(Xnrg[ b ] - psSilk_VAD->NL[ b ], 4); - } - - if (psEncC->frame_length == 20 * psEncC->fs_kHz) { - speech_nrg = silk_RSHIFT32(speech_nrg, 1); - } - /* Power scaling */ - if (speech_nrg <= 0) { - SA_Q15 = silk_RSHIFT(SA_Q15, 1); - } else if (speech_nrg < 16384) { - speech_nrg = silk_LSHIFT32(speech_nrg, 16); - - /* square-root */ - speech_nrg = silk_SQRT_APPROX(speech_nrg); - SA_Q15 = silk_SMULWB(32768 + speech_nrg, SA_Q15); - } - - /* Copy the resulting speech activity in Q8 */ - psEncC->speech_activity_Q8 = silk_min_int(silk_RSHIFT(SA_Q15, 7), silk_uint8_MAX); - - /***********************************/ - /* Energy Level and SNR estimation */ - /***********************************/ - /* Smoothing coefficient */ - smooth_coef_Q16 = silk_SMULWB(VAD_SNR_SMOOTH_COEF_Q18, silk_SMULWB((opus_int32)SA_Q15, SA_Q15)); - - if (psEncC->frame_length == 10 * psEncC->fs_kHz) { - smooth_coef_Q16 >>= 1; - } - - for (b = 0; b < VAD_N_BANDS; b++) { - /* compute smoothed energy-to-noise ratio per band */ - psSilk_VAD->NrgRatioSmth_Q8[ b ] = silk_SMLAWB(psSilk_VAD->NrgRatioSmth_Q8[ b ], - NrgToNoiseRatio_Q8[ b ] - psSilk_VAD->NrgRatioSmth_Q8[ b ], smooth_coef_Q16); - - /* signal to noise ratio in dB per band */ - SNR_Q7 = 3 * (silk_lin2log(psSilk_VAD->NrgRatioSmth_Q8[b]) - 8 * 128); - /* quality = sigmoid( 0.25 * ( SNR_dB - 16 ) ); */ - psEncC->input_quality_bands_Q15[ b ] = silk_sigm_Q15(silk_RSHIFT(SNR_Q7 - 16 * 128, 4)); - } - - RESTORE_STACK; - return (ret); -} - -/**************************/ -/* Noise level estimation */ -/**************************/ -# if !defined(OPUS_X86_MAY_HAVE_SSE4_1) -static OPUS_INLINE -#endif -void silk_VAD_GetNoiseLevels( - const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies */ - silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */ -) { - opus_int k; - opus_int32 nl, nrg, inv_nrg; - opus_int coef, min_coef; - - /* Initially faster smoothing */ - if (psSilk_VAD->counter < 1000) { /* 1000 = 20 sec */ - min_coef = silk_DIV32_16(silk_int16_MAX, silk_RSHIFT(psSilk_VAD->counter, 4) + 1); - /* Increment frame counter */ - psSilk_VAD->counter++; - } else { - min_coef = 0; - } - - for (k = 0; k < VAD_N_BANDS; k++) { - /* Get old noise level estimate for current band */ - nl = psSilk_VAD->NL[ k ]; - silk_assert(nl >= 0); - - /* Add bias */ - nrg = silk_ADD_POS_SAT32(pX[ k ], psSilk_VAD->NoiseLevelBias[ k ]); - silk_assert(nrg > 0); - - /* Invert energies */ - inv_nrg = silk_DIV32(silk_int32_MAX, nrg); - silk_assert(inv_nrg >= 0); - - /* Less update when subband energy is high */ - if (nrg > silk_LSHIFT(nl, 3)) { - coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 >> 3; - } else if (nrg < nl) { - coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16; - } else { - coef = silk_SMULWB(silk_SMULWW(inv_nrg, nl), VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 << 1); - } - - /* Initially faster smoothing */ - coef = silk_max_int(coef, min_coef); - - /* Smooth inverse energies */ - psSilk_VAD->inv_NL[ k ] = silk_SMLAWB(psSilk_VAD->inv_NL[ k ], inv_nrg - psSilk_VAD->inv_NL[ k ], coef); - silk_assert(psSilk_VAD->inv_NL[ k ] >= 0); - - /* Compute noise level by inverting again */ - nl = silk_DIV32(silk_int32_MAX, psSilk_VAD->inv_NL[ k ]); - silk_assert(nl >= 0); - - /* Limit noise levels (guarantee 7 bits of head room) */ - nl = silk_min(nl, 0x00FFFFFF); - - /* Store as part of state */ - psSilk_VAD->NL[ k ] = nl; - } -} diff --git a/src/libopus/silk/VQ_WMat_EC.c b/src/libopus/silk/VQ_WMat_EC.c index 8715c3d..bf9ef7b 100644 --- a/src/libopus/silk/VQ_WMat_EC.c +++ b/src/libopus/silk/VQ_WMat_EC.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -45,7 +45,8 @@ void silk_VQ_WMat_EC_c( const opus_int subfr_len, /* I number of samples per subframe */ const opus_int32 max_gain_Q7, /* I maximum sum of absolute LTP coefficients */ const opus_int L /* I number of vectors in codebook */ -) { +) +{ opus_int k, gain_tmp_Q7; const opus_int8 *cb_row_Q7; opus_int32 neg_xX_Q24[ 5 ]; @@ -53,70 +54,70 @@ void silk_VQ_WMat_EC_c( opus_int32 bits_res_Q8, bits_tot_Q8; /* Negate and convert to new Q domain */ - neg_xX_Q24[ 0 ] = -silk_LSHIFT32(xX_Q17[ 0 ], 7); - neg_xX_Q24[ 1 ] = -silk_LSHIFT32(xX_Q17[ 1 ], 7); - neg_xX_Q24[ 2 ] = -silk_LSHIFT32(xX_Q17[ 2 ], 7); - neg_xX_Q24[ 3 ] = -silk_LSHIFT32(xX_Q17[ 3 ], 7); - neg_xX_Q24[ 4 ] = -silk_LSHIFT32(xX_Q17[ 4 ], 7); + neg_xX_Q24[ 0 ] = -silk_LSHIFT32( xX_Q17[ 0 ], 7 ); + neg_xX_Q24[ 1 ] = -silk_LSHIFT32( xX_Q17[ 1 ], 7 ); + neg_xX_Q24[ 2 ] = -silk_LSHIFT32( xX_Q17[ 2 ], 7 ); + neg_xX_Q24[ 3 ] = -silk_LSHIFT32( xX_Q17[ 3 ], 7 ); + neg_xX_Q24[ 4 ] = -silk_LSHIFT32( xX_Q17[ 4 ], 7 ); /* Loop over codebook */ *rate_dist_Q8 = silk_int32_MAX; *res_nrg_Q15 = silk_int32_MAX; cb_row_Q7 = cb_Q7; - /* In things go really bad, at least *ind is set to something safe. */ + /* If things go really bad, at least *ind is set to something safe. */ *ind = 0; - for (k = 0; k < L; k++) { + for( k = 0; k < L; k++ ) { opus_int32 penalty; gain_tmp_Q7 = cb_gain_Q7[k]; /* Weighted rate */ /* Quantization error: 1 - 2 * xX * cb + cb' * XX * cb */ - sum1_Q15 = SILK_FIX_CONST(1.001, 15); + sum1_Q15 = SILK_FIX_CONST( 1.001, 15 ); /* Penalty for too large gain */ - penalty = silk_LSHIFT32(silk_max(silk_SUB32(gain_tmp_Q7, max_gain_Q7), 0), 11); + penalty = silk_LSHIFT32( silk_max( silk_SUB32( gain_tmp_Q7, max_gain_Q7 ), 0 ), 11 ); /* first row of XX_Q17 */ - sum2_Q24 = silk_MLA(neg_xX_Q24[ 0 ], XX_Q17[ 1 ], cb_row_Q7[ 1 ]); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 2 ], cb_row_Q7[ 2 ]); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 3 ], cb_row_Q7[ 3 ]); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 4 ], cb_row_Q7[ 4 ]); - sum2_Q24 = silk_LSHIFT32(sum2_Q24, 1); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 0 ], cb_row_Q7[ 0 ]); - sum1_Q15 = silk_SMLAWB(sum1_Q15, sum2_Q24, cb_row_Q7[ 0 ]); + sum2_Q24 = silk_MLA( neg_xX_Q24[ 0 ], XX_Q17[ 1 ], cb_row_Q7[ 1 ] ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 2 ], cb_row_Q7[ 2 ] ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 3 ], cb_row_Q7[ 3 ] ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 4 ], cb_row_Q7[ 4 ] ); + sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 0 ], cb_row_Q7[ 0 ] ); + sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 0 ] ); /* second row of XX_Q17 */ - sum2_Q24 = silk_MLA(neg_xX_Q24[ 1 ], XX_Q17[ 7 ], cb_row_Q7[ 2 ]); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 8 ], cb_row_Q7[ 3 ]); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 9 ], cb_row_Q7[ 4 ]); - sum2_Q24 = silk_LSHIFT32(sum2_Q24, 1); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 6 ], cb_row_Q7[ 1 ]); - sum1_Q15 = silk_SMLAWB(sum1_Q15, sum2_Q24, cb_row_Q7[ 1 ]); + sum2_Q24 = silk_MLA( neg_xX_Q24[ 1 ], XX_Q17[ 7 ], cb_row_Q7[ 2 ] ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 8 ], cb_row_Q7[ 3 ] ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 9 ], cb_row_Q7[ 4 ] ); + sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 6 ], cb_row_Q7[ 1 ] ); + sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 1 ] ); /* third row of XX_Q17 */ - sum2_Q24 = silk_MLA(neg_xX_Q24[ 2 ], XX_Q17[ 13 ], cb_row_Q7[ 3 ]); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 14 ], cb_row_Q7[ 4 ]); - sum2_Q24 = silk_LSHIFT32(sum2_Q24, 1); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 12 ], cb_row_Q7[ 2 ]); - sum1_Q15 = silk_SMLAWB(sum1_Q15, sum2_Q24, cb_row_Q7[ 2 ]); + sum2_Q24 = silk_MLA( neg_xX_Q24[ 2 ], XX_Q17[ 13 ], cb_row_Q7[ 3 ] ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 14 ], cb_row_Q7[ 4 ] ); + sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 12 ], cb_row_Q7[ 2 ] ); + sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 2 ] ); /* fourth row of XX_Q17 */ - sum2_Q24 = silk_MLA(neg_xX_Q24[ 3 ], XX_Q17[ 19 ], cb_row_Q7[ 4 ]); - sum2_Q24 = silk_LSHIFT32(sum2_Q24, 1); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 18 ], cb_row_Q7[ 3 ]); - sum1_Q15 = silk_SMLAWB(sum1_Q15, sum2_Q24, cb_row_Q7[ 3 ]); + sum2_Q24 = silk_MLA( neg_xX_Q24[ 3 ], XX_Q17[ 19 ], cb_row_Q7[ 4 ] ); + sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 18 ], cb_row_Q7[ 3 ] ); + sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 3 ] ); /* last row of XX_Q17 */ - sum2_Q24 = silk_LSHIFT32(neg_xX_Q24[ 4 ], 1); - sum2_Q24 = silk_MLA(sum2_Q24, XX_Q17[ 24 ], cb_row_Q7[ 4 ]); - sum1_Q15 = silk_SMLAWB(sum1_Q15, sum2_Q24, cb_row_Q7[ 4 ]); + sum2_Q24 = silk_LSHIFT32( neg_xX_Q24[ 4 ], 1 ); + sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 24 ], cb_row_Q7[ 4 ] ); + sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 4 ] ); /* find best */ - if (sum1_Q15 >= 0) { + if( sum1_Q15 >= 0 ) { /* Translate residual energy to bits using high-rate assumption (6 dB ==> 1 bit/sample) */ - bits_res_Q8 = silk_SMULBB(subfr_len, silk_lin2log(sum1_Q15 + penalty) - (15 << 7)); - /* In the following line we reduce the codelength component by half ("-1"); seems to slghtly improve quality */ - bits_tot_Q8 = silk_ADD_LSHIFT32(bits_res_Q8, cl_Q5[ k ], 3 - 1); - if (bits_tot_Q8 <= *rate_dist_Q8) { + bits_res_Q8 = silk_SMULBB( subfr_len, silk_lin2log( sum1_Q15 + penalty) - (15 << 7) ); + /* In the following line we reduce the codelength component by half ("-1"); seems to slightly improve quality */ + bits_tot_Q8 = silk_ADD_LSHIFT32( bits_res_Q8, cl_Q5[ k ], 3-1 ); + if( bits_tot_Q8 <= *rate_dist_Q8 ) { *rate_dist_Q8 = bits_tot_Q8; *res_nrg_Q15 = sum1_Q15 + penalty; *ind = (opus_int8)k; diff --git a/src/libopus/silk/ana_filt_bank_1.c b/src/libopus/silk/ana_filt_bank_1.c index 51dd961..1211ffa 100644 --- a/src/libopus/silk/ana_filt_bank_1.c +++ b/src/libopus/silk/ana_filt_bank_1.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" @@ -42,32 +42,33 @@ void silk_ana_filt_bank_1( opus_int16 *outL, /* O Low band [N/2] */ opus_int16 *outH, /* O High band [N/2] */ const opus_int32 N /* I Number of input samples */ -) { - opus_int k, N2 = silk_RSHIFT(N, 1); +) +{ + opus_int k, N2 = silk_RSHIFT( N, 1 ); opus_int32 in32, X, Y, out_1, out_2; /* Internal variables and state are in Q10 format */ - for (k = 0; k < N2; k++) { + for( k = 0; k < N2; k++ ) { /* Convert to Q10 */ - in32 = silk_LSHIFT((opus_int32)in[ 2 * k ], 10); + in32 = silk_LSHIFT( (opus_int32)in[ 2 * k ], 10 ); /* All-pass section for even input sample */ - Y = silk_SUB32(in32, S[ 0 ]); - X = silk_SMLAWB(Y, Y, A_fb1_21); - out_1 = silk_ADD32(S[ 0 ], X); - S[ 0 ] = silk_ADD32(in32, X); + Y = silk_SUB32( in32, S[ 0 ] ); + X = silk_SMLAWB( Y, Y, A_fb1_21 ); + out_1 = silk_ADD32( S[ 0 ], X ); + S[ 0 ] = silk_ADD32( in32, X ); /* Convert to Q10 */ - in32 = silk_LSHIFT((opus_int32)in[ 2 * k + 1 ], 10); + in32 = silk_LSHIFT( (opus_int32)in[ 2 * k + 1 ], 10 ); /* All-pass section for odd input sample, and add to output of previous section */ - Y = silk_SUB32(in32, S[ 1 ]); - X = silk_SMULWB(Y, A_fb1_20); - out_2 = silk_ADD32(S[ 1 ], X); - S[ 1 ] = silk_ADD32(in32, X); + Y = silk_SUB32( in32, S[ 1 ] ); + X = silk_SMULWB( Y, A_fb1_20 ); + out_2 = silk_ADD32( S[ 1 ], X ); + S[ 1 ] = silk_ADD32( in32, X ); /* Add/subtract, convert back to int16 and store to output */ - outL[ k ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(silk_ADD32(out_2, out_1), 11)); - outH[ k ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(silk_SUB32(out_2, out_1), 11)); + outL[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_ADD32( out_2, out_1 ), 11 ) ); + outH[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SUB32( out_2, out_1 ), 11 ) ); } } diff --git a/src/libopus/silk/arch.h b/src/libopus/silk/arch.h new file mode 100644 index 0000000..0530293 --- /dev/null +++ b/src/libopus/silk/arch.h @@ -0,0 +1 @@ +#include "../celt/arch.h" diff --git a/src/libopus/silk/biquad_alt.c b/src/libopus/silk/biquad_alt.c index 74b5340..f3844f3 100644 --- a/src/libopus/silk/biquad_alt.c +++ b/src/libopus/silk/biquad_alt.c @@ -1,40 +1,40 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ /* * - silk_biquad_alt.c + * silk_biquad_alt.c * * * - Second order ARMA filter - Can handle slowly varying filter coefficients + * Second order ARMA filter * + * Can handle slowly varying filter coefficients * * */ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" @@ -46,32 +46,33 @@ void silk_biquad_alt_stride1( opus_int32 *S, /* I/O State vector [2] */ opus_int16 *out, /* O output signal */ const opus_int32 len /* I signal length (must be even) */ -) { +) +{ /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ opus_int k; opus_int32 inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14; /* Negate A_Q28 values and split in two parts */ - A0_L_Q28 = (-A_Q28[ 0 ]) & 0x00003FFF; /* lower part */ - A0_U_Q28 = silk_RSHIFT(-A_Q28[ 0 ], 14); /* upper part */ - A1_L_Q28 = (-A_Q28[ 1 ]) & 0x00003FFF; /* lower part */ - A1_U_Q28 = silk_RSHIFT(-A_Q28[ 1 ], 14); /* upper part */ + A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF; /* lower part */ + A0_U_Q28 = silk_RSHIFT( -A_Q28[ 0 ], 14 ); /* upper part */ + A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF; /* lower part */ + A1_U_Q28 = silk_RSHIFT( -A_Q28[ 1 ], 14 ); /* upper part */ - for (k = 0; k < len; k++) { + for( k = 0; k < len; k++ ) { /* S[ 0 ], S[ 1 ]: Q12 */ inval = in[ k ]; - out32_Q14 = silk_LSHIFT(silk_SMLAWB(S[ 0 ], B_Q28[ 0 ], inval), 2); + out32_Q14 = silk_LSHIFT( silk_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 ); - S[ 0 ] = S[1] + silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14, A0_L_Q28), 14); - S[ 0 ] = silk_SMLAWB(S[ 0 ], out32_Q14, A0_U_Q28); - S[ 0 ] = silk_SMLAWB(S[ 0 ], B_Q28[ 1 ], inval); + S[ 0 ] = S[1] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14, A0_L_Q28 ), 14 ); + S[ 0 ] = silk_SMLAWB( S[ 0 ], out32_Q14, A0_U_Q28 ); + S[ 0 ] = silk_SMLAWB( S[ 0 ], B_Q28[ 1 ], inval); - S[ 1 ] = silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14, A1_L_Q28), 14); - S[ 1 ] = silk_SMLAWB(S[ 1 ], out32_Q14, A1_U_Q28); - S[ 1 ] = silk_SMLAWB(S[ 1 ], B_Q28[ 2 ], inval); + S[ 1 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14, A1_L_Q28 ), 14 ); + S[ 1 ] = silk_SMLAWB( S[ 1 ], out32_Q14, A1_U_Q28 ); + S[ 1 ] = silk_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval ); /* Scale back to Q0 and saturate */ - out[ k ] = (opus_int16)silk_SAT16(silk_RSHIFT(out32_Q14 + (1 << 14) - 1, 14)); + out[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) ); } } @@ -82,38 +83,39 @@ void silk_biquad_alt_stride2_c( opus_int32 *S, /* I/O State vector [4] */ opus_int16 *out, /* O output signal */ const opus_int32 len /* I signal length (must be even) */ -) { +) +{ /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ opus_int k; opus_int32 A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14[ 2 ]; /* Negate A_Q28 values and split in two parts */ - A0_L_Q28 = (-A_Q28[ 0 ]) & 0x00003FFF; /* lower part */ - A0_U_Q28 = silk_RSHIFT(-A_Q28[ 0 ], 14); /* upper part */ - A1_L_Q28 = (-A_Q28[ 1 ]) & 0x00003FFF; /* lower part */ - A1_U_Q28 = silk_RSHIFT(-A_Q28[ 1 ], 14); /* upper part */ + A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF; /* lower part */ + A0_U_Q28 = silk_RSHIFT( -A_Q28[ 0 ], 14 ); /* upper part */ + A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF; /* lower part */ + A1_U_Q28 = silk_RSHIFT( -A_Q28[ 1 ], 14 ); /* upper part */ - for (k = 0; k < len; k++) { + for( k = 0; k < len; k++ ) { /* S[ 0 ], S[ 1 ], S[ 2 ], S[ 3 ]: Q12 */ - out32_Q14[ 0 ] = silk_LSHIFT(silk_SMLAWB(S[ 0 ], B_Q28[ 0 ], in[ 2 * k + 0 ]), 2); - out32_Q14[ 1 ] = silk_LSHIFT(silk_SMLAWB(S[ 2 ], B_Q28[ 0 ], in[ 2 * k + 1 ]), 2); + out32_Q14[ 0 ] = silk_LSHIFT( silk_SMLAWB( S[ 0 ], B_Q28[ 0 ], in[ 2 * k + 0 ] ), 2 ); + out32_Q14[ 1 ] = silk_LSHIFT( silk_SMLAWB( S[ 2 ], B_Q28[ 0 ], in[ 2 * k + 1 ] ), 2 ); - S[ 0 ] = S[ 1 ] + silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14[ 0 ], A0_L_Q28), 14); - S[ 2 ] = S[ 3 ] + silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14[ 1 ], A0_L_Q28), 14); - S[ 0 ] = silk_SMLAWB(S[ 0 ], out32_Q14[ 0 ], A0_U_Q28); - S[ 2 ] = silk_SMLAWB(S[ 2 ], out32_Q14[ 1 ], A0_U_Q28); - S[ 0 ] = silk_SMLAWB(S[ 0 ], B_Q28[ 1 ], in[ 2 * k + 0 ]); - S[ 2 ] = silk_SMLAWB(S[ 2 ], B_Q28[ 1 ], in[ 2 * k + 1 ]); + S[ 0 ] = S[ 1 ] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 0 ], A0_L_Q28 ), 14 ); + S[ 2 ] = S[ 3 ] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 1 ], A0_L_Q28 ), 14 ); + S[ 0 ] = silk_SMLAWB( S[ 0 ], out32_Q14[ 0 ], A0_U_Q28 ); + S[ 2 ] = silk_SMLAWB( S[ 2 ], out32_Q14[ 1 ], A0_U_Q28 ); + S[ 0 ] = silk_SMLAWB( S[ 0 ], B_Q28[ 1 ], in[ 2 * k + 0 ] ); + S[ 2 ] = silk_SMLAWB( S[ 2 ], B_Q28[ 1 ], in[ 2 * k + 1 ] ); - S[ 1 ] = silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14[ 0 ], A1_L_Q28), 14); - S[ 3 ] = silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14[ 1 ], A1_L_Q28), 14); - S[ 1 ] = silk_SMLAWB(S[ 1 ], out32_Q14[ 0 ], A1_U_Q28); - S[ 3 ] = silk_SMLAWB(S[ 3 ], out32_Q14[ 1 ], A1_U_Q28); - S[ 1 ] = silk_SMLAWB(S[ 1 ], B_Q28[ 2 ], in[ 2 * k + 0 ]); - S[ 3 ] = silk_SMLAWB(S[ 3 ], B_Q28[ 2 ], in[ 2 * k + 1 ]); + S[ 1 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 0 ], A1_L_Q28 ), 14 ); + S[ 3 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 1 ], A1_L_Q28 ), 14 ); + S[ 1 ] = silk_SMLAWB( S[ 1 ], out32_Q14[ 0 ], A1_U_Q28 ); + S[ 3 ] = silk_SMLAWB( S[ 3 ], out32_Q14[ 1 ], A1_U_Q28 ); + S[ 1 ] = silk_SMLAWB( S[ 1 ], B_Q28[ 2 ], in[ 2 * k + 0 ] ); + S[ 3 ] = silk_SMLAWB( S[ 3 ], B_Q28[ 2 ], in[ 2 * k + 1 ] ); /* Scale back to Q0 and saturate */ - out[ 2 * k + 0 ] = (opus_int16)silk_SAT16(silk_RSHIFT(out32_Q14[ 0 ] + (1 << 14) - 1, 14)); - out[ 2 * k + 1 ] = (opus_int16)silk_SAT16(silk_RSHIFT(out32_Q14[ 1 ] + (1 << 14) - 1, 14)); + out[ 2 * k + 0 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14[ 0 ] + (1<<14) - 1, 14 ) ); + out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14[ 1 ] + (1<<14) - 1, 14 ) ); } } diff --git a/src/libopus/silk/bwexpander.c b/src/libopus/silk/bwexpander.c index 2da7ce5..a70eb08 100644 --- a/src/libopus/silk/bwexpander.c +++ b/src/libopus/silk/bwexpander.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" @@ -36,15 +36,16 @@ void silk_bwexpander( opus_int16 *ar, /* I/O AR filter to be expanded (without leading 1) */ const opus_int d, /* I Length of ar */ opus_int32 chirp_Q16 /* I Chirp factor (typically in the range 0 to 1) */ -) { +) +{ opus_int i; opus_int32 chirp_minus_one_Q16 = chirp_Q16 - 65536; /* NB: Dont use silk_SMULWB, instead of silk_RSHIFT_ROUND( silk_MUL(), 16 ), below. */ /* Bias in silk_SMULWB can lead to unstable filters */ - for (i = 0; i < d - 1; i++) { - ar[ i ] = (opus_int16)silk_RSHIFT_ROUND(silk_MUL(chirp_Q16, ar[ i ]), 16); - chirp_Q16 += silk_RSHIFT_ROUND(silk_MUL(chirp_Q16, chirp_minus_one_Q16), 16); + for( i = 0; i < d - 1; i++ ) { + ar[ i ] = (opus_int16)silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, ar[ i ] ), 16 ); + chirp_Q16 += silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 ); } - ar[ d - 1 ] = (opus_int16)silk_RSHIFT_ROUND(silk_MUL(chirp_Q16, ar[ d - 1 ]), 16); + ar[ d - 1 ] = (opus_int16)silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, ar[ d - 1 ] ), 16 ); } diff --git a/src/libopus/silk/bwexpander_32.c b/src/libopus/silk/bwexpander_32.c index fc46801..d6cd874 100644 --- a/src/libopus/silk/bwexpander_32.c +++ b/src/libopus/silk/bwexpander_32.c @@ -1,49 +1,51 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" -/* Chirp (bandwidth expand) LP AR filter */ +/* Chirp (bandwidth expand) LP AR filter. + This logic is reused in _celt_lpc(). Any bug fixes should also be applied there. */ void silk_bwexpander_32( opus_int32 *ar, /* I/O AR filter to be expanded (without leading 1) */ const opus_int d, /* I Length of ar */ opus_int32 chirp_Q16 /* I Chirp factor in Q16 */ -) { +) +{ opus_int i; opus_int32 chirp_minus_one_Q16 = chirp_Q16 - 65536; - for (i = 0; i < d - 1; i++) { - ar[ i ] = silk_SMULWW(chirp_Q16, ar[ i ]); - chirp_Q16 += silk_RSHIFT_ROUND(silk_MUL(chirp_Q16, chirp_minus_one_Q16), 16); + for( i = 0; i < d - 1; i++ ) { + ar[ i ] = silk_SMULWW( chirp_Q16, ar[ i ] ); + chirp_Q16 += silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 ); } - ar[ d - 1 ] = silk_SMULWW(chirp_Q16, ar[ d - 1 ]); + ar[ d - 1 ] = silk_SMULWW( chirp_Q16, ar[ d - 1 ] ); } diff --git a/src/libopus/silk/celt_lpc.h b/src/libopus/silk/celt_lpc.h new file mode 100644 index 0000000..6975665 --- /dev/null +++ b/src/libopus/silk/celt_lpc.h @@ -0,0 +1 @@ +#include "../celt/celt_lpc.h" diff --git a/src/libopus/silk/check_control_input.c b/src/libopus/silk/check_control_input.c index 904b49b..016fee2 100644 --- a/src/libopus/silk/check_control_input.c +++ b/src/libopus/silk/check_control_input.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" #include "control.h" @@ -36,68 +36,69 @@ /* Check encoder control struct */ opus_int check_control_input( silk_EncControlStruct *encControl /* I Control structure */ -) { - celt_assert(encControl != NULL); +) +{ + celt_assert( encControl != NULL ); - if (((encControl->API_sampleRate != 8000) && - (encControl->API_sampleRate != 12000) && - (encControl->API_sampleRate != 16000) && - (encControl->API_sampleRate != 24000) && - (encControl->API_sampleRate != 32000) && - (encControl->API_sampleRate != 44100) && - (encControl->API_sampleRate != 48000)) || - ((encControl->desiredInternalSampleRate != 8000) && - (encControl->desiredInternalSampleRate != 12000) && - (encControl->desiredInternalSampleRate != 16000)) || - ((encControl->maxInternalSampleRate != 8000) && - (encControl->maxInternalSampleRate != 12000) && - (encControl->maxInternalSampleRate != 16000)) || - ((encControl->minInternalSampleRate != 8000) && - (encControl->minInternalSampleRate != 12000) && - (encControl->minInternalSampleRate != 16000)) || - (encControl->minInternalSampleRate > encControl->desiredInternalSampleRate) || - (encControl->maxInternalSampleRate < encControl->desiredInternalSampleRate) || - (encControl->minInternalSampleRate > encControl->maxInternalSampleRate)) { - celt_assert(0); + if( ( ( encControl->API_sampleRate != 8000 ) && + ( encControl->API_sampleRate != 12000 ) && + ( encControl->API_sampleRate != 16000 ) && + ( encControl->API_sampleRate != 24000 ) && + ( encControl->API_sampleRate != 32000 ) && + ( encControl->API_sampleRate != 44100 ) && + ( encControl->API_sampleRate != 48000 ) ) || + ( ( encControl->desiredInternalSampleRate != 8000 ) && + ( encControl->desiredInternalSampleRate != 12000 ) && + ( encControl->desiredInternalSampleRate != 16000 ) ) || + ( ( encControl->maxInternalSampleRate != 8000 ) && + ( encControl->maxInternalSampleRate != 12000 ) && + ( encControl->maxInternalSampleRate != 16000 ) ) || + ( ( encControl->minInternalSampleRate != 8000 ) && + ( encControl->minInternalSampleRate != 12000 ) && + ( encControl->minInternalSampleRate != 16000 ) ) || + ( encControl->minInternalSampleRate > encControl->desiredInternalSampleRate ) || + ( encControl->maxInternalSampleRate < encControl->desiredInternalSampleRate ) || + ( encControl->minInternalSampleRate > encControl->maxInternalSampleRate ) ) { + celt_assert( 0 ); return SILK_ENC_FS_NOT_SUPPORTED; } - if (encControl->payloadSize_ms != 10 && - encControl->payloadSize_ms != 20 && - encControl->payloadSize_ms != 40 && - encControl->payloadSize_ms != 60) { - celt_assert(0); + if( encControl->payloadSize_ms != 10 && + encControl->payloadSize_ms != 20 && + encControl->payloadSize_ms != 40 && + encControl->payloadSize_ms != 60 ) { + celt_assert( 0 ); return SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; } - if (encControl->packetLossPercentage < 0 || encControl->packetLossPercentage > 100) { - celt_assert(0); + if( encControl->packetLossPercentage < 0 || encControl->packetLossPercentage > 100 ) { + celt_assert( 0 ); return SILK_ENC_INVALID_LOSS_RATE; } - if (encControl->useDTX < 0 || encControl->useDTX > 1) { - celt_assert(0); + if( encControl->useDTX < 0 || encControl->useDTX > 1 ) { + celt_assert( 0 ); return SILK_ENC_INVALID_DTX_SETTING; } - if (encControl->useCBR < 0 || encControl->useCBR > 1) { - celt_assert(0); + if( encControl->useCBR < 0 || encControl->useCBR > 1 ) { + celt_assert( 0 ); return SILK_ENC_INVALID_CBR_SETTING; } - if (encControl->useInBandFEC < 0 || encControl->useInBandFEC > 1) { - celt_assert(0); + if( encControl->useInBandFEC < 0 || encControl->useInBandFEC > 1 ) { + celt_assert( 0 ); return SILK_ENC_INVALID_INBAND_FEC_SETTING; } - if (encControl->nChannelsAPI < 1 || encControl->nChannelsAPI > ENCODER_NUM_CHANNELS) { - celt_assert(0); + if( encControl->nChannelsAPI < 1 || encControl->nChannelsAPI > ENCODER_NUM_CHANNELS ) { + celt_assert( 0 ); return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; } - if (encControl->nChannelsInternal < 1 || encControl->nChannelsInternal > ENCODER_NUM_CHANNELS) { - celt_assert(0); + if( encControl->nChannelsInternal < 1 || encControl->nChannelsInternal > ENCODER_NUM_CHANNELS ) { + celt_assert( 0 ); return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; } - if (encControl->nChannelsInternal > encControl->nChannelsAPI) { - celt_assert(0); + if( encControl->nChannelsInternal > encControl->nChannelsAPI ) { + celt_assert( 0 ); return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; } - if (encControl->complexity < 0 || encControl->complexity > 10) { - celt_assert(0); + if( encControl->complexity < 0 || encControl->complexity > 10 ) { + celt_assert( 0 ); return SILK_ENC_INVALID_COMPLEXITY_SETTING; } diff --git a/src/libopus/silk/code_signs.c b/src/libopus/silk/code_signs.c index ccfaa53..b9eae24 100644 --- a/src/libopus/silk/code_signs.c +++ b/src/libopus/silk/code_signs.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -45,7 +45,8 @@ void silk_encode_signs( const opus_int signalType, /* I Signal type */ const opus_int quantOffsetType, /* I Quantization offset type */ const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */ -) { +) +{ opus_int i, j, p; opus_uint8 icdf[ 2 ]; const opus_int8 *q_ptr; @@ -53,16 +54,16 @@ void silk_encode_signs( icdf[ 1 ] = 0; q_ptr = pulses; - i = silk_SMULBB(7, silk_ADD_LSHIFT(quantOffsetType, signalType, 1)); + i = silk_SMULBB( 7, silk_ADD_LSHIFT( quantOffsetType, signalType, 1 ) ); icdf_ptr = &silk_sign_iCDF[ i ]; - length = silk_RSHIFT(length + SHELL_CODEC_FRAME_LENGTH / 2, LOG2_SHELL_CODEC_FRAME_LENGTH); - for (i = 0; i < length; i++) { + length = silk_RSHIFT( length + SHELL_CODEC_FRAME_LENGTH/2, LOG2_SHELL_CODEC_FRAME_LENGTH ); + for( i = 0; i < length; i++ ) { p = sum_pulses[ i ]; - if (p > 0) { - icdf[ 0 ] = icdf_ptr[ silk_min(p & 0x1F, 6) ]; - for (j = 0; j < SHELL_CODEC_FRAME_LENGTH; j++) { - if (q_ptr[ j ] != 0) { - ec_enc_icdf(psRangeEnc, silk_enc_map(q_ptr[ j ]), icdf, 8); + if( p > 0 ) { + icdf[ 0 ] = icdf_ptr[ silk_min( p & 0x1F, 6 ) ]; + for( j = 0; j < SHELL_CODEC_FRAME_LENGTH; j++ ) { + if( q_ptr[ j ] != 0 ) { + ec_enc_icdf( psRangeEnc, silk_enc_map( q_ptr[ j ]), icdf, 8 ); } } } @@ -78,7 +79,8 @@ void silk_decode_signs( const opus_int signalType, /* I Signal type */ const opus_int quantOffsetType, /* I Quantization offset type */ const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */ -) { +) +{ opus_int i, j, p; opus_uint8 icdf[ 2 ]; opus_int16 *q_ptr; @@ -86,24 +88,24 @@ void silk_decode_signs( icdf[ 1 ] = 0; q_ptr = pulses; - i = silk_SMULBB(7, silk_ADD_LSHIFT(quantOffsetType, signalType, 1)); + i = silk_SMULBB( 7, silk_ADD_LSHIFT( quantOffsetType, signalType, 1 ) ); icdf_ptr = &silk_sign_iCDF[ i ]; - length = silk_RSHIFT(length + SHELL_CODEC_FRAME_LENGTH / 2, LOG2_SHELL_CODEC_FRAME_LENGTH); - for (i = 0; i < length; i++) { + length = silk_RSHIFT( length + SHELL_CODEC_FRAME_LENGTH/2, LOG2_SHELL_CODEC_FRAME_LENGTH ); + for( i = 0; i < length; i++ ) { p = sum_pulses[ i ]; - if (p > 0) { - icdf[ 0 ] = icdf_ptr[ silk_min(p & 0x1F, 6) ]; - for (j = 0; j < SHELL_CODEC_FRAME_LENGTH; j++) { - if (q_ptr[ j ] > 0) { + if( p > 0 ) { + icdf[ 0 ] = icdf_ptr[ silk_min( p & 0x1F, 6 ) ]; + for( j = 0; j < SHELL_CODEC_FRAME_LENGTH; j++ ) { + if( q_ptr[ j ] > 0 ) { /* attach sign */ #if 0 /* conditional implementation */ - if (ec_dec_icdf(psRangeDec, icdf, 8) == 0) { + if( ec_dec_icdf( psRangeDec, icdf, 8 ) == 0 ) { q_ptr[ j ] = -q_ptr[ j ]; } #else /* implementation with shift, subtraction, multiplication */ - q_ptr[ j ] *= silk_dec_map(ec_dec_icdf(psRangeDec, icdf, 8)); + q_ptr[ j ] *= silk_dec_map( ec_dec_icdf( psRangeDec, icdf, 8 ) ); #endif } } diff --git a/src/libopus/silk/config.h b/src/libopus/silk/config.h new file mode 100644 index 0000000..2989b6b --- /dev/null +++ b/src/libopus/silk/config.h @@ -0,0 +1 @@ +#include "../include/config.h" diff --git a/src/libopus/silk/control.h b/src/libopus/silk/control.h index 0579f47..f5633e6 100644 --- a/src/libopus/silk/control.h +++ b/src/libopus/silk/control.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_CONTROL_H @@ -77,6 +77,9 @@ typedef struct { /* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */ opus_int useInBandFEC; + /* I: Flag to enable in-band Deep REDundancy (DRED); 0/1 */ + opus_int useDRED; + /* I: Flag to actually code in-band Forward Error Correction (FEC) in the current packet; 0/1 */ opus_int LBRR_coded; @@ -141,6 +144,14 @@ typedef struct { /* O: Pitch lag of previous frame (0 if unvoiced), measured in samples at 48 kHz */ opus_int prevPitchLag; + + /* I: Enable Deep PLC */ + opus_int enable_deep_plc; + +#ifdef ENABLE_OSCE + /* I: OSCE method */ + opus_int osce_method; +#endif } silk_DecControlStruct; #ifdef __cplusplus diff --git a/src/libopus/silk/control_SNR.c b/src/libopus/silk/control_SNR.c index f2c4c36..cb26f26 100644 --- a/src/libopus/silk/control_SNR.c +++ b/src/libopus/silk/control_SNR.c @@ -1,112 +1,113 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" #include "tuning_parameters.h" -/* These tables hold SNR values divided by 21 (so they fit in 8 bits) - for different target bitrates spaced at 400 bps interval. The first - 10 values are omitted (0-4 kb/s) because they're all zeros. - These tables were obtained by running different SNRs through the - encoder and measuring the active bitrate. */ +/* These tables hold SNR values divided by 21 (so they fit in 8 bits) + for different target bitrates spaced at 400 bps interval. The first + 10 values are omitted (0-4 kb/s) because they're all zeros. + These tables were obtained by running different SNRs through the + encoder and measuring the active bitrate. */ static const unsigned char silk_TargetRate_NB_21[117 - 10] = { - 0, 15, 39, 52, 61, 68, - 74, 79, 84, 88, 92, 95, 99, 102, 105, 108, 111, 114, 117, 119, 122, 124, - 126, 129, 131, 133, 135, 137, 139, 142, 143, 145, 147, 149, 151, 153, 155, 157, - 158, 160, 162, 163, 165, 167, 168, 170, 171, 173, 174, 176, 177, 179, 180, 182, - 183, 185, 186, 187, 189, 190, 192, 193, 194, 196, 197, 199, 200, 201, 203, 204, - 205, 207, 208, 209, 211, 212, 213, 215, 216, 217, 219, 220, 221, 223, 224, 225, - 227, 228, 230, 231, 232, 234, 235, 236, 238, 239, 241, 242, 243, 245, 246, 248, - 249, 250, 252, 253, 255 + 0, 15, 39, 52, 61, 68, + 74, 79, 84, 88, 92, 95, 99,102,105,108,111,114,117,119,122,124, + 126,129,131,133,135,137,139,142,143,145,147,149,151,153,155,157, + 158,160,162,163,165,167,168,170,171,173,174,176,177,179,180,182, + 183,185,186,187,189,190,192,193,194,196,197,199,200,201,203,204, + 205,207,208,209,211,212,213,215,216,217,219,220,221,223,224,225, + 227,228,230,231,232,234,235,236,238,239,241,242,243,245,246,248, + 249,250,252,253,255 }; static const unsigned char silk_TargetRate_MB_21[165 - 10] = { - 0, 0, 28, 43, 52, 59, - 65, 70, 74, 78, 81, 85, 87, 90, 93, 95, 98, 100, 102, 105, 107, 109, - 111, 113, 115, 116, 118, 120, 122, 123, 125, 127, 128, 130, 131, 133, 134, 136, - 137, 138, 140, 141, 143, 144, 145, 147, 148, 149, 151, 152, 153, 154, 156, 157, - 158, 159, 160, 162, 163, 164, 165, 166, 167, 168, 169, 171, 172, 173, 174, 175, - 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 188, 189, 190, - 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 203, 204, 205, - 206, 207, 208, 209, 210, 211, 212, 213, 214, 214, 215, 216, 217, 218, 219, 220, - 221, 222, 223, 224, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, - 236, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 255 + 0, 0, 28, 43, 52, 59, + 65, 70, 74, 78, 81, 85, 87, 90, 93, 95, 98,100,102,105,107,109, + 111,113,115,116,118,120,122,123,125,127,128,130,131,133,134,136, + 137,138,140,141,143,144,145,147,148,149,151,152,153,154,156,157, + 158,159,160,162,163,164,165,166,167,168,169,171,172,173,174,175, + 176,177,178,179,180,181,182,183,184,185,186,187,188,188,189,190, + 191,192,193,194,195,196,197,198,199,200,201,202,203,203,204,205, + 206,207,208,209,210,211,212,213,214,214,215,216,217,218,219,220, + 221,222,223,224,224,225,226,227,228,229,230,231,232,233,234,235, + 236,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250, + 251,252,253,254,255 }; static const unsigned char silk_TargetRate_WB_21[201 - 10] = { - 0, 0, 0, 8, 29, 41, - 49, 56, 62, 66, 70, 74, 77, 80, 83, 86, 88, 91, 93, 95, 97, 99, - 101, 103, 105, 107, 108, 110, 112, 113, 115, 116, 118, 119, 121, 122, 123, 125, - 126, 127, 129, 130, 131, 132, 134, 135, 136, 137, 138, 140, 141, 142, 143, 144, - 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 156, 157, 158, 159, 159, 160, - 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, - 176, 177, 177, 178, 179, 180, 181, 181, 182, 183, 184, 185, 185, 186, 187, 188, - 189, 189, 190, 191, 192, 192, 193, 194, 195, 195, 196, 197, 198, 198, 199, 200, - 200, 201, 202, 203, 203, 204, 205, 206, 206, 207, 208, 209, 209, 210, 211, 211, - 212, 213, 214, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 221, 222, 223, - 224, 224, 225, 226, 226, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, - 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 246, 246, - 247, 248, 249, 249, 250, 251, 252, 253, 255 + 0, 0, 0, 8, 29, 41, + 49, 56, 62, 66, 70, 74, 77, 80, 83, 86, 88, 91, 93, 95, 97, 99, + 101,103,105,107,108,110,112,113,115,116,118,119,121,122,123,125, + 126,127,129,130,131,132,134,135,136,137,138,140,141,142,143,144, + 145,146,147,148,149,150,151,152,153,154,156,157,158,159,159,160, + 161,162,163,164,165,166,167,168,169,170,171,171,172,173,174,175, + 176,177,177,178,179,180,181,181,182,183,184,185,185,186,187,188, + 189,189,190,191,192,192,193,194,195,195,196,197,198,198,199,200, + 200,201,202,203,203,204,205,206,206,207,208,209,209,210,211,211, + 212,213,214,214,215,216,216,217,218,219,219,220,221,221,222,223, + 224,224,225,226,226,227,228,229,229,230,231,232,232,233,234,234, + 235,236,237,237,238,239,240,240,241,242,243,243,244,245,246,246, + 247,248,249,249,250,251,252,253,255 }; /* Control SNR of redidual quantizer */ opus_int silk_control_SNR( silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */ opus_int32 TargetRate_bps /* I Target max bitrate (bps) */ -) { +) +{ int id; int bound; const unsigned char *snr_table; psEncC->TargetRate_bps = TargetRate_bps; - if (psEncC->nb_subfr == 2) { - TargetRate_bps -= 2000 + psEncC->fs_kHz / 16; + if( psEncC->nb_subfr == 2 ) { + TargetRate_bps -= 2000 + psEncC->fs_kHz/16; } - if (psEncC->fs_kHz == 8) { + if( psEncC->fs_kHz == 8 ) { bound = sizeof(silk_TargetRate_NB_21); snr_table = silk_TargetRate_NB_21; - } else if (psEncC->fs_kHz == 12) { + } else if( psEncC->fs_kHz == 12 ) { bound = sizeof(silk_TargetRate_MB_21); snr_table = silk_TargetRate_MB_21; } else { bound = sizeof(silk_TargetRate_WB_21); snr_table = silk_TargetRate_WB_21; } - id = (TargetRate_bps + 200) / 400; - id = silk_min(id - 10, bound - 1); - if (id <= 0) { + id = (TargetRate_bps+200)/400; + id = silk_min(id - 10, bound-1); + if( id <= 0 ) { psEncC->SNR_dB_Q7 = 0; } else { - psEncC->SNR_dB_Q7 = snr_table[id] * 21; + psEncC->SNR_dB_Q7 = snr_table[id]*21; } return SILK_NO_ERROR; } diff --git a/src/libopus/silk/control_audio_bandwidth.c b/src/libopus/silk/control_audio_bandwidth.c index a738d22..3a05cc0 100644 --- a/src/libopus/silk/control_audio_bandwidth.c +++ b/src/libopus/silk/control_audio_bandwidth.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" #include "tuning_parameters.h" @@ -36,92 +36,95 @@ opus_int silk_control_audio_bandwidth( silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */ silk_EncControlStruct *encControl /* I Control structure */ -) { +) +{ opus_int fs_kHz; opus_int orig_kHz; opus_int32 fs_Hz; orig_kHz = psEncC->fs_kHz; /* Handle a bandwidth-switching reset where we need to be aware what the last sampling rate was. */ - if (orig_kHz == 0) { + if( orig_kHz == 0 ) { orig_kHz = psEncC->sLP.saved_fs_kHz; } fs_kHz = orig_kHz; - fs_Hz = silk_SMULBB(fs_kHz, 1000); - if (fs_Hz == 0) { + fs_Hz = silk_SMULBB( fs_kHz, 1000 ); + if( fs_Hz == 0 ) { /* Encoder has just been initialized */ - fs_Hz = silk_min(psEncC->desiredInternal_fs_Hz, psEncC->API_fs_Hz); - fs_kHz = silk_DIV32_16(fs_Hz, 1000); - } else if (fs_Hz > psEncC->API_fs_Hz || fs_Hz > psEncC->maxInternal_fs_Hz || fs_Hz < psEncC->minInternal_fs_Hz) { + fs_Hz = silk_min( psEncC->desiredInternal_fs_Hz, psEncC->API_fs_Hz ); + fs_kHz = silk_DIV32_16( fs_Hz, 1000 ); + } else if( fs_Hz > psEncC->API_fs_Hz || fs_Hz > psEncC->maxInternal_fs_Hz || fs_Hz < psEncC->minInternal_fs_Hz ) { /* Make sure internal rate is not higher than external rate or maximum allowed, or lower than minimum allowed */ fs_Hz = psEncC->API_fs_Hz; - fs_Hz = silk_min(fs_Hz, psEncC->maxInternal_fs_Hz); - fs_Hz = silk_max(fs_Hz, psEncC->minInternal_fs_Hz); - fs_kHz = silk_DIV32_16(fs_Hz, 1000); + fs_Hz = silk_min( fs_Hz, psEncC->maxInternal_fs_Hz ); + fs_Hz = silk_max( fs_Hz, psEncC->minInternal_fs_Hz ); + fs_kHz = silk_DIV32_16( fs_Hz, 1000 ); } else { /* State machine for the internal sampling rate switching */ - if (psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES) { + if( psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES ) { /* Stop transition phase */ psEncC->sLP.mode = 0; } - if (psEncC->allow_bandwidth_switch || encControl->opusCanSwitch) { + if( psEncC->allow_bandwidth_switch || encControl->opusCanSwitch ) { /* Check if we should switch down */ - if (silk_SMULBB(orig_kHz, 1000) > psEncC->desiredInternal_fs_Hz) { + if( silk_SMULBB( orig_kHz, 1000 ) > psEncC->desiredInternal_fs_Hz ) + { /* Switch down */ - if (psEncC->sLP.mode == 0) { + if( psEncC->sLP.mode == 0 ) { /* New transition */ psEncC->sLP.transition_frame_no = TRANSITION_FRAMES; /* Reset transition filter state */ - silk_memset(psEncC->sLP.In_LP_State, 0, sizeof(psEncC->sLP.In_LP_State)); + silk_memset( psEncC->sLP.In_LP_State, 0, sizeof( psEncC->sLP.In_LP_State ) ); } - if (encControl->opusCanSwitch) { + if( encControl->opusCanSwitch ) { /* Stop transition phase */ psEncC->sLP.mode = 0; /* Switch to a lower sample frequency */ fs_kHz = orig_kHz == 16 ? 12 : 8; } else { - if (psEncC->sLP.transition_frame_no <= 0) { - encControl->switchReady = 1; - /* Make room for redundancy */ - encControl->maxBits -= encControl->maxBits * 5 / (encControl->payloadSize_ms + 5); - } else { - /* Direction: down (at double speed) */ - psEncC->sLP.mode = -2; - } + if( psEncC->sLP.transition_frame_no <= 0 ) { + encControl->switchReady = 1; + /* Make room for redundancy */ + encControl->maxBits -= encControl->maxBits * 5 / ( encControl->payloadSize_ms + 5 ); + } else { + /* Direction: down (at double speed) */ + psEncC->sLP.mode = -2; + } } - } else - /* Check if we should switch up */ - if (silk_SMULBB(orig_kHz, 1000) < psEncC->desiredInternal_fs_Hz) { - /* Switch up */ - if (encControl->opusCanSwitch) { - /* Switch to a higher sample frequency */ - fs_kHz = orig_kHz == 8 ? 12 : 16; + } + else + /* Check if we should switch up */ + if( silk_SMULBB( orig_kHz, 1000 ) < psEncC->desiredInternal_fs_Hz ) + { + /* Switch up */ + if( encControl->opusCanSwitch ) { + /* Switch to a higher sample frequency */ + fs_kHz = orig_kHz == 8 ? 12 : 16; - /* New transition */ - psEncC->sLP.transition_frame_no = 0; + /* New transition */ + psEncC->sLP.transition_frame_no = 0; - /* Reset transition filter state */ - silk_memset(psEncC->sLP.In_LP_State, 0, sizeof(psEncC->sLP.In_LP_State)); + /* Reset transition filter state */ + silk_memset( psEncC->sLP.In_LP_State, 0, sizeof( psEncC->sLP.In_LP_State ) ); - /* Direction: up */ - psEncC->sLP.mode = 1; - } else { - if (psEncC->sLP.mode == 0) { - encControl->switchReady = 1; - /* Make room for redundancy */ - encControl->maxBits -= encControl->maxBits * 5 / (encControl->payloadSize_ms + 5); - } else { - /* Direction: up */ - psEncC->sLP.mode = 1; - } - } + /* Direction: up */ + psEncC->sLP.mode = 1; } else { - if (psEncC->sLP.mode < 0) { - psEncC->sLP.mode = 1; - } + if( psEncC->sLP.mode == 0 ) { + encControl->switchReady = 1; + /* Make room for redundancy */ + encControl->maxBits -= encControl->maxBits * 5 / ( encControl->payloadSize_ms + 5 ); + } else { + /* Direction: up */ + psEncC->sLP.mode = 1; + } } + } else { + if (psEncC->sLP.mode<0) + psEncC->sLP.mode = 1; + } } } diff --git a/src/libopus/silk/control_codec.c b/src/libopus/silk/control_codec.c index 9d540c4..2eac36b 100644 --- a/src/libopus/silk/control_codec.c +++ b/src/libopus/silk/control_codec.c @@ -1,41 +1,41 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #ifdef FIXED_POINT -#include "fixed/main_FIX.h" +#include "main_FIX.h" #define silk_encoder_state_Fxx silk_encoder_state_FIX #else #include "main_FLP.h" #define silk_encoder_state_Fxx silk_encoder_state_FLP #endif -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" #include "tuning_parameters.h" #include "pitch_est_defines.h" @@ -68,7 +68,8 @@ opus_int silk_control_encoder( const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ const opus_int channelNb, /* I Channel number */ const opus_int force_fs_kHz -) { +) +{ opus_int fs_kHz, ret = 0; psEnc->sCmn.useDTX = encControl->useDTX; @@ -83,10 +84,10 @@ opus_int silk_control_encoder( psEnc->sCmn.allow_bandwidth_switch = allow_bw_switch; psEnc->sCmn.channelNb = channelNb; - if (psEnc->sCmn.controlled_since_last_payload != 0 && psEnc->sCmn.prefillFlag == 0) { - if (psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0) { + if( psEnc->sCmn.controlled_since_last_payload != 0 && psEnc->sCmn.prefillFlag == 0 ) { + if( psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0 ) { /* Change in API sampling rate in the middle of encoding a packet */ - ret += silk_setup_resamplers(psEnc, psEnc->sCmn.fs_kHz); + ret += silk_setup_resamplers( psEnc, psEnc->sCmn.fs_kHz ); } return ret; } @@ -96,24 +97,24 @@ opus_int silk_control_encoder( /********************************************/ /* Determine internal sampling rate */ /********************************************/ - fs_kHz = silk_control_audio_bandwidth(&psEnc->sCmn, encControl); - if (force_fs_kHz) { - fs_kHz = force_fs_kHz; + fs_kHz = silk_control_audio_bandwidth( &psEnc->sCmn, encControl ); + if( force_fs_kHz ) { + fs_kHz = force_fs_kHz; } /********************************************/ /* Prepare resampler and buffered data */ /********************************************/ - ret += silk_setup_resamplers(psEnc, fs_kHz); + ret += silk_setup_resamplers( psEnc, fs_kHz ); /********************************************/ /* Set internal sampling frequency */ /********************************************/ - ret += silk_setup_fs(psEnc, fs_kHz, encControl->payloadSize_ms); + ret += silk_setup_fs( psEnc, fs_kHz, encControl->payloadSize_ms ); /********************************************/ /* Set encoding complexity */ /********************************************/ - ret += silk_setup_complexity(&psEnc->sCmn, encControl->complexity); + ret += silk_setup_complexity( &psEnc->sCmn, encControl->complexity ); /********************************************/ /* Set packet loss rate measured by farend */ @@ -123,7 +124,7 @@ opus_int silk_control_encoder( /********************************************/ /* Set LBRR usage */ /********************************************/ - ret += silk_setup_LBRR(&psEnc->sCmn, encControl); + ret += silk_setup_LBRR( &psEnc->sCmn, encControl ); psEnc->sCmn.controlled_since_last_payload = 1; @@ -133,56 +134,58 @@ opus_int silk_control_encoder( static opus_int silk_setup_resamplers( silk_encoder_state_Fxx *psEnc, /* I/O */ opus_int fs_kHz /* I */ -) { +) +{ opus_int ret = SILK_NO_ERROR; SAVE_STACK; - if (psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz) { - if (psEnc->sCmn.fs_kHz == 0) { + if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz ) + { + if( psEnc->sCmn.fs_kHz == 0 ) { /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */ - ret += silk_resampler_init(&psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000, 1); + ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000, 1 ); } else { - VARDECL(opus_int16, x_buf_API_fs_Hz); - VARDECL(silk_resampler_state_struct, temp_resampler_state); + VARDECL( opus_int16, x_buf_API_fs_Hz ); + VARDECL( silk_resampler_state_struct, temp_resampler_state ); #ifdef FIXED_POINT opus_int16 *x_bufFIX = psEnc->x_buf; #else - VARDECL(opus_int16, x_bufFIX); + VARDECL( opus_int16, x_bufFIX ); opus_int32 new_buf_samples; #endif opus_int32 api_buf_samples; opus_int32 old_buf_samples; opus_int32 buf_length_ms; - buf_length_ms = silk_LSHIFT(psEnc->sCmn.nb_subfr * 5, 1) + LA_SHAPE_MS; + buf_length_ms = silk_LSHIFT( psEnc->sCmn.nb_subfr * 5, 1 ) + LA_SHAPE_MS; old_buf_samples = buf_length_ms * psEnc->sCmn.fs_kHz; #ifndef FIXED_POINT new_buf_samples = buf_length_ms * fs_kHz; - ALLOC(x_bufFIX, silk_max(old_buf_samples, new_buf_samples), - opus_int16); - silk_float2short_array(x_bufFIX, psEnc->x_buf, old_buf_samples); + ALLOC( x_bufFIX, silk_max( old_buf_samples, new_buf_samples ), + opus_int16 ); + silk_float2short_array( x_bufFIX, psEnc->x_buf, old_buf_samples ); #endif /* Initialize resampler for temporary resampling of x_buf data to API_fs_Hz */ - ALLOC(temp_resampler_state, 1, silk_resampler_state_struct); - ret += silk_resampler_init(temp_resampler_state, silk_SMULBB(psEnc->sCmn.fs_kHz, 1000), psEnc->sCmn.API_fs_Hz, 0); + ALLOC( temp_resampler_state, 1, silk_resampler_state_struct ); + ret += silk_resampler_init( temp_resampler_state, silk_SMULBB( psEnc->sCmn.fs_kHz, 1000 ), psEnc->sCmn.API_fs_Hz, 0 ); /* Calculate number of samples to temporarily upsample */ - api_buf_samples = buf_length_ms * silk_DIV32_16(psEnc->sCmn.API_fs_Hz, 1000); + api_buf_samples = buf_length_ms * silk_DIV32_16( psEnc->sCmn.API_fs_Hz, 1000 ); /* Temporary resampling of x_buf data to API_fs_Hz */ - ALLOC(x_buf_API_fs_Hz, api_buf_samples, opus_int16); - ret += silk_resampler(temp_resampler_state, x_buf_API_fs_Hz, x_bufFIX, old_buf_samples); + ALLOC( x_buf_API_fs_Hz, api_buf_samples, opus_int16 ); + ret += silk_resampler( temp_resampler_state, x_buf_API_fs_Hz, x_bufFIX, old_buf_samples ); /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */ - ret += silk_resampler_init(&psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, silk_SMULBB(fs_kHz, 1000), 1); + ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, silk_SMULBB( fs_kHz, 1000 ), 1 ); /* Correct resampler state by resampling buffered data from API_fs_Hz to fs_kHz */ - ret += silk_resampler(&psEnc->sCmn.resampler_state, x_bufFIX, x_buf_API_fs_Hz, api_buf_samples); + ret += silk_resampler( &psEnc->sCmn.resampler_state, x_bufFIX, x_buf_API_fs_Hz, api_buf_samples ); #ifndef FIXED_POINT - silk_short2float_array(psEnc->x_buf, x_bufFIX, new_buf_samples); + silk_short2float_array( psEnc->x_buf, x_bufFIX, new_buf_samples); #endif } } @@ -197,33 +200,34 @@ static opus_int silk_setup_fs( silk_encoder_state_Fxx *psEnc, /* I/O */ opus_int fs_kHz, /* I */ opus_int PacketSize_ms /* I */ -) { +) +{ opus_int ret = SILK_NO_ERROR; /* Set packet size */ - if (PacketSize_ms != psEnc->sCmn.PacketSize_ms) { - if ((PacketSize_ms != 10) && - (PacketSize_ms != 20) && - (PacketSize_ms != 40) && - (PacketSize_ms != 60)) { + if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) { + if( ( PacketSize_ms != 10 ) && + ( PacketSize_ms != 20 ) && + ( PacketSize_ms != 40 ) && + ( PacketSize_ms != 60 ) ) { ret = SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; } - if (PacketSize_ms <= 10) { + if( PacketSize_ms <= 10 ) { psEnc->sCmn.nFramesPerPacket = 1; psEnc->sCmn.nb_subfr = PacketSize_ms == 10 ? 2 : 1; - psEnc->sCmn.frame_length = silk_SMULBB(PacketSize_ms, fs_kHz); - psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB(FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz); - if (psEnc->sCmn.fs_kHz == 8) { + psEnc->sCmn.frame_length = silk_SMULBB( PacketSize_ms, fs_kHz ); + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); + if( psEnc->sCmn.fs_kHz == 8 ) { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_NB_iCDF; } else { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_iCDF; } } else { - psEnc->sCmn.nFramesPerPacket = silk_DIV32_16(PacketSize_ms, MAX_FRAME_LENGTH_MS); + psEnc->sCmn.nFramesPerPacket = silk_DIV32_16( PacketSize_ms, MAX_FRAME_LENGTH_MS ); psEnc->sCmn.nb_subfr = MAX_NB_SUBFR; - psEnc->sCmn.frame_length = silk_SMULBB(20, fs_kHz); - psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB(FIND_PITCH_LPC_WIN_MS, fs_kHz); - if (psEnc->sCmn.fs_kHz == 8) { + psEnc->sCmn.frame_length = silk_SMULBB( 20, fs_kHz ); + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); + if( psEnc->sCmn.fs_kHz == 8 ) { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_NB_iCDF; } else { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_iCDF; @@ -234,14 +238,14 @@ static opus_int silk_setup_fs( } /* Set internal sampling frequency */ - celt_assert(fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16); - celt_assert(psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4); - if (psEnc->sCmn.fs_kHz != fs_kHz) { + celt_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 ); + celt_assert( psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4 ); + if( psEnc->sCmn.fs_kHz != fs_kHz ) { /* reset part of the state */ - silk_memset(&psEnc->sShape, 0, sizeof(psEnc->sShape)); - silk_memset(&psEnc->sCmn.sNSQ, 0, sizeof(psEnc->sCmn.sNSQ)); - silk_memset(psEnc->sCmn.prev_NLSFq_Q15, 0, sizeof(psEnc->sCmn.prev_NLSFq_Q15)); - silk_memset(&psEnc->sCmn.sLP.In_LP_State, 0, sizeof(psEnc->sCmn.sLP.In_LP_State)); + silk_memset( &psEnc->sShape, 0, sizeof( psEnc->sShape ) ); + silk_memset( &psEnc->sCmn.sNSQ, 0, sizeof( psEnc->sCmn.sNSQ ) ); + silk_memset( psEnc->sCmn.prev_NLSFq_Q15, 0, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) ); + silk_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) ); psEnc->sCmn.inputBufIx = 0; psEnc->sCmn.nFramesEncoded = 0; psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR computation */ @@ -255,20 +259,20 @@ static opus_int silk_setup_fs( psEnc->sCmn.prevSignalType = TYPE_NO_VOICE_ACTIVITY; psEnc->sCmn.fs_kHz = fs_kHz; - if (psEnc->sCmn.fs_kHz == 8) { - if (psEnc->sCmn.nb_subfr == MAX_NB_SUBFR) { + if( psEnc->sCmn.fs_kHz == 8 ) { + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_NB_iCDF; } else { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_NB_iCDF; } } else { - if (psEnc->sCmn.nb_subfr == MAX_NB_SUBFR) { + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_iCDF; } else { psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_iCDF; } } - if (psEnc->sCmn.fs_kHz == 8 || psEnc->sCmn.fs_kHz == 12) { + if( psEnc->sCmn.fs_kHz == 8 || psEnc->sCmn.fs_kHz == 12 ) { psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER; psEnc->sCmn.psNLSF_CB = &silk_NLSF_CB_NB_MB; } else { @@ -276,18 +280,18 @@ static opus_int silk_setup_fs( psEnc->sCmn.psNLSF_CB = &silk_NLSF_CB_WB; } psEnc->sCmn.subfr_length = SUB_FRAME_LENGTH_MS * fs_kHz; - psEnc->sCmn.frame_length = silk_SMULBB(psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr); - psEnc->sCmn.ltp_mem_length = silk_SMULBB(LTP_MEM_LENGTH_MS, fs_kHz); - psEnc->sCmn.la_pitch = silk_SMULBB(LA_PITCH_MS, fs_kHz); - psEnc->sCmn.max_pitch_lag = silk_SMULBB(18, fs_kHz); - if (psEnc->sCmn.nb_subfr == MAX_NB_SUBFR) { - psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB(FIND_PITCH_LPC_WIN_MS, fs_kHz); + psEnc->sCmn.frame_length = silk_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); + psEnc->sCmn.ltp_mem_length = silk_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); + psEnc->sCmn.la_pitch = silk_SMULBB( LA_PITCH_MS, fs_kHz ); + psEnc->sCmn.max_pitch_lag = silk_SMULBB( 18, fs_kHz ); + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); } else { - psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB(FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz); + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); } - if (psEnc->sCmn.fs_kHz == 16) { + if( psEnc->sCmn.fs_kHz == 16 ) { psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform8_iCDF; - } else if (psEnc->sCmn.fs_kHz == 12) { + } else if( psEnc->sCmn.fs_kHz == 12 ) { psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform6_iCDF; } else { psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform4_iCDF; @@ -295,7 +299,7 @@ static opus_int silk_setup_fs( } /* Check that settings are valid */ - celt_assert((psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr) == psEnc->sCmn.frame_length); + celt_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->sCmn.frame_length ); return ret; } @@ -303,14 +307,15 @@ static opus_int silk_setup_fs( static opus_int silk_setup_complexity( silk_encoder_state *psEncC, /* I/O */ opus_int Complexity /* I */ -) { +) +{ opus_int ret = 0; /* Set encoding complexity */ - celt_assert(Complexity >= 0 && Complexity <= 10); - if (Complexity < 1) { + celt_assert( Complexity >= 0 && Complexity <= 10 ); + if( Complexity < 1 ) { psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; - psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST(0.8, 16); + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); psEncC->pitchEstimationLPCOrder = 6; psEncC->shapingLPCOrder = 12; psEncC->la_shape = 3 * psEncC->fs_kHz; @@ -318,9 +323,9 @@ static opus_int silk_setup_complexity( psEncC->useInterpolatedNLSFs = 0; psEncC->NLSF_MSVQ_Survivors = 2; psEncC->warping_Q16 = 0; - } else if (Complexity < 2) { + } else if( Complexity < 2 ) { psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; - psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST(0.76, 16); + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); psEncC->pitchEstimationLPCOrder = 8; psEncC->shapingLPCOrder = 14; psEncC->la_shape = 5 * psEncC->fs_kHz; @@ -328,9 +333,9 @@ static opus_int silk_setup_complexity( psEncC->useInterpolatedNLSFs = 0; psEncC->NLSF_MSVQ_Survivors = 3; psEncC->warping_Q16 = 0; - } else if (Complexity < 3) { + } else if( Complexity < 3 ) { psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; - psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST(0.8, 16); + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); psEncC->pitchEstimationLPCOrder = 6; psEncC->shapingLPCOrder = 12; psEncC->la_shape = 3 * psEncC->fs_kHz; @@ -338,9 +343,9 @@ static opus_int silk_setup_complexity( psEncC->useInterpolatedNLSFs = 0; psEncC->NLSF_MSVQ_Survivors = 2; psEncC->warping_Q16 = 0; - } else if (Complexity < 4) { + } else if( Complexity < 4 ) { psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; - psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST(0.76, 16); + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); psEncC->pitchEstimationLPCOrder = 8; psEncC->shapingLPCOrder = 14; psEncC->la_shape = 5 * psEncC->fs_kHz; @@ -348,49 +353,49 @@ static opus_int silk_setup_complexity( psEncC->useInterpolatedNLSFs = 0; psEncC->NLSF_MSVQ_Survivors = 4; psEncC->warping_Q16 = 0; - } else if (Complexity < 6) { + } else if( Complexity < 6 ) { psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; - psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST(0.74, 16); + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.74, 16 ); psEncC->pitchEstimationLPCOrder = 10; psEncC->shapingLPCOrder = 16; psEncC->la_shape = 5 * psEncC->fs_kHz; psEncC->nStatesDelayedDecision = 2; psEncC->useInterpolatedNLSFs = 1; psEncC->NLSF_MSVQ_Survivors = 6; - psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST(WARPING_MULTIPLIER, 16); - } else if (Complexity < 8) { + psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); + } else if( Complexity < 8 ) { psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; - psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST(0.72, 16); + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.72, 16 ); psEncC->pitchEstimationLPCOrder = 12; psEncC->shapingLPCOrder = 20; psEncC->la_shape = 5 * psEncC->fs_kHz; psEncC->nStatesDelayedDecision = 3; psEncC->useInterpolatedNLSFs = 1; psEncC->NLSF_MSVQ_Survivors = 8; - psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST(WARPING_MULTIPLIER, 16); + psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); } else { psEncC->pitchEstimationComplexity = SILK_PE_MAX_COMPLEX; - psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST(0.7, 16); + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.7, 16 ); psEncC->pitchEstimationLPCOrder = 16; psEncC->shapingLPCOrder = 24; psEncC->la_shape = 5 * psEncC->fs_kHz; psEncC->nStatesDelayedDecision = MAX_DEL_DEC_STATES; psEncC->useInterpolatedNLSFs = 1; psEncC->NLSF_MSVQ_Survivors = 16; - psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST(WARPING_MULTIPLIER, 16); + psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); } /* Do not allow higher pitch estimation LPC order than predict LPC order */ - psEncC->pitchEstimationLPCOrder = silk_min_int(psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder); + psEncC->pitchEstimationLPCOrder = silk_min_int( psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder ); psEncC->shapeWinLength = SUB_FRAME_LENGTH_MS * psEncC->fs_kHz + 2 * psEncC->la_shape; psEncC->Complexity = Complexity; - celt_assert(psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER); - celt_assert(psEncC->shapingLPCOrder <= MAX_SHAPE_LPC_ORDER); - celt_assert(psEncC->nStatesDelayedDecision <= MAX_DEL_DEC_STATES); - celt_assert(psEncC->warping_Q16 <= 32767); - celt_assert(psEncC->la_shape <= LA_SHAPE_MAX); - celt_assert(psEncC->shapeWinLength <= SHAPE_LPC_WIN_MAX); + celt_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER ); + celt_assert( psEncC->shapingLPCOrder <= MAX_SHAPE_LPC_ORDER ); + celt_assert( psEncC->nStatesDelayedDecision <= MAX_DEL_DEC_STATES ); + celt_assert( psEncC->warping_Q16 <= 32767 ); + celt_assert( psEncC->la_shape <= LA_SHAPE_MAX ); + celt_assert( psEncC->shapeWinLength <= SHAPE_LPC_WIN_MAX ); return ret; } @@ -398,18 +403,19 @@ static opus_int silk_setup_complexity( static OPUS_INLINE opus_int silk_setup_LBRR( silk_encoder_state *psEncC, /* I/O */ const silk_EncControlStruct *encControl /* I */ -) { +) +{ opus_int LBRR_in_previous_packet, ret = SILK_NO_ERROR; LBRR_in_previous_packet = psEncC->LBRR_enabled; psEncC->LBRR_enabled = encControl->LBRR_coded; - if (psEncC->LBRR_enabled) { + if( psEncC->LBRR_enabled ) { /* Set gain increase for coding LBRR excitation */ - if (LBRR_in_previous_packet == 0) { + if( LBRR_in_previous_packet == 0 ) { /* Previous packet did not have LBRR, and was therefore coded at a higher bitrate */ psEncC->LBRR_GainIncreases = 7; } else { - psEncC->LBRR_GainIncreases = silk_max_int(7 - silk_SMULWB((opus_int32)psEncC->PacketLoss_perc, SILK_FIX_CONST(0.4, 16)), 2); + psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opus_int32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.2, 16 ) ), 3 ); } } diff --git a/src/libopus/silk/cpu_support.h b/src/libopus/silk/cpu_support.h new file mode 100644 index 0000000..32e7df2 --- /dev/null +++ b/src/libopus/silk/cpu_support.h @@ -0,0 +1 @@ +#include "../celt/cpu_support.h" diff --git a/src/libopus/silk/debug.c b/src/libopus/silk/debug.c index 771dbbf..ec8c525 100644 --- a/src/libopus/silk/debug.c +++ b/src/libopus/silk/debug.c @@ -1,48 +1,53 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif + +typedef int prevent_empty_translation_unit_warning; #include "debug.h" + +#if SILK_DEBUG || SILK_TIC_TOC #include "SigProc_FIX.h" +#endif #if SILK_TIC_TOC -#ifdef _WIN32 - #if (defined(_WIN32) || defined(_WINCE)) #include /* timer */ #else /* Linux or Mac*/ #include #endif -unsigned long silk_GetHighResolutionTime(void) { /* O time in usec*/ +#ifdef _WIN32 +unsigned long silk_GetHighResolutionTime(void) /* O time in usec*/ +{ /* Returns a time counter in microsec */ /* the resolution is platform dependent */ /* but is typically 1.62 us resolution */ @@ -50,20 +55,21 @@ unsigned long silk_GetHighResolutionTime(void) { /* O time in usec*/ LARGE_INTEGER lpFrequency; QueryPerformanceCounter(&lpPerformanceCount); QueryPerformanceFrequency(&lpFrequency); - return (unsigned long)((1000000 * (lpPerformanceCount.QuadPart)) / lpFrequency.QuadPart); + return (unsigned long)((1000000*(lpPerformanceCount.QuadPart)) / lpFrequency.QuadPart); } #else /* Linux or Mac*/ -unsigned long GetHighResolutionTime(void) { /* O time in usec*/ +unsigned long GetHighResolutionTime(void) /* O time in usec*/ +{ struct timeval tv; gettimeofday(&tv, 0); - return ((tv.tv_sec * 1000000) + (tv.tv_usec)); + return((tv.tv_sec*1000000)+(tv.tv_usec)); } #endif int silk_Timer_nTimers = 0; int silk_Timer_depth_ctr = 0; char silk_Timer_tags[silk_NUM_TIMERS_MAX][silk_NUM_TIMERS_MAX_TAG_LEN]; -#ifdef WIN32 +#ifdef _WIN32 LARGE_INTEGER silk_Timer_start[silk_NUM_TIMERS_MAX]; #else unsigned long silk_Timer_start[silk_NUM_TIMERS_MAX]; @@ -74,9 +80,11 @@ opus_int64 silk_Timer_sum[silk_NUM_TIMERS_MAX]; opus_int64 silk_Timer_max[silk_NUM_TIMERS_MAX]; opus_int64 silk_Timer_depth[silk_NUM_TIMERS_MAX]; -#ifdef WIN32 -void silk_TimerSave(char *file_name) { - if (silk_Timer_nTimers > 0) { +#ifdef _WIN32 +void silk_TimerSave(char *file_name) +{ + if( silk_Timer_nTimers > 0 ) + { int k; FILE *fp; LARGE_INTEGER lpFrequency; @@ -84,25 +92,24 @@ void silk_TimerSave(char *file_name) { int del = 0x7FFFFFFF; double avg, sum_avg; /* estimate overhead of calling performance counters */ - for (k = 0; k < 1000; k++) { + for( k = 0; k < 1000; k++ ) { QueryPerformanceCounter(&lpPerformanceCount1); QueryPerformanceCounter(&lpPerformanceCount2); lpPerformanceCount2.QuadPart -= lpPerformanceCount1.QuadPart; - if ((int)lpPerformanceCount2.LowPart < del) { + if( (int)lpPerformanceCount2.LowPart < del ) del = lpPerformanceCount2.LowPart; - } } QueryPerformanceFrequency(&lpFrequency); /* print results to file */ sum_avg = 0.0f; - for (k = 0; k < silk_Timer_nTimers; k++) { + for( k = 0; k < silk_Timer_nTimers; k++ ) { if (silk_Timer_depth[k] == 0) { sum_avg += (1e6 * silk_Timer_sum[k] / silk_Timer_cnt[k] - del) / lpFrequency.QuadPart * silk_Timer_cnt[k]; } } fp = fopen(file_name, "w"); fprintf(fp, " min avg %% max count\n"); - for (k = 0; k < silk_Timer_nTimers; k++) { + for( k = 0; k < silk_Timer_nTimers; k++ ) { if (silk_Timer_depth[k] == 0) { fprintf(fp, "%-28s", silk_Timer_tags[k]); } else if (silk_Timer_depth[k] == 1) { @@ -125,14 +132,17 @@ void silk_TimerSave(char *file_name) { } } #else -void silk_TimerSave(char *file_name) { - if (silk_Timer_nTimers > 0) { +void silk_TimerSave(char *file_name) +{ + if( silk_Timer_nTimers > 0 ) + { int k; FILE *fp; /* print results to file */ fp = fopen(file_name, "w"); fprintf(fp, " min avg max count\n"); - for (k = 0; k < silk_Timer_nTimers; k++) { + for( k = 0; k < silk_Timer_nTimers; k++ ) + { if (silk_Timer_depth[k] == 0) { fprintf(fp, "%-28s", silk_Timer_tags[k]); } else if (silk_Timer_depth[k] == 1) { diff --git a/src/libopus/silk/debug.h b/src/libopus/silk/debug.h index 767cb51..36163e4 100644 --- a/src/libopus/silk/debug.h +++ b/src/libopus/silk/debug.h @@ -1,55 +1,56 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_DEBUG_H #define SILK_DEBUG_H +/* Set to 1 to enable DEBUG_STORE_DATA() macros for dumping + * intermediate signals from the codec. + */ +#define SILK_DEBUG 0 + +/* Flag for using timers */ +#define SILK_TIC_TOC 0 + +#if SILK_DEBUG || SILK_TIC_TOC #include "typedef.h" -#include /* file writing */ #include /* strcpy, strcmp */ +#include /* file writing */ +#endif #ifdef __cplusplus extern "C" { #endif -unsigned long GetHighResolutionTime(void); /* O time in usec*/ - -/* Set to 1 to enable DEBUG_STORE_DATA() macros for dumping - intermediate signals from the codec. -*/ -#define SILK_DEBUG 0 - -/* Flag for using timers */ -#define SILK_TIC_TOC 0 - - #if SILK_TIC_TOC +unsigned long GetHighResolutionTime(void); /* O time in usec*/ + #if (defined(_WIN32) || defined(_WINCE)) #include /* timer */ #else /* Linux or Mac*/ diff --git a/src/libopus/silk/dec_API.c b/src/libopus/silk/dec_API.c index c205136..ebe80e5 100644 --- a/src/libopus/silk/dec_API.c +++ b/src/libopus/silk/dec_API.c @@ -1,37 +1,42 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "API.h" #include "main.h" -#include "../celt/stack_alloc.h" -#include "../celt/os_support.h" +#include "stack_alloc.h" +#include "os_support.h" + +#ifdef ENABLE_OSCE +#include "osce.h" +#include "osce_structs.h" +#endif /************************/ /* Decoder Super Struct */ @@ -42,31 +47,79 @@ typedef struct { opus_int nChannelsAPI; opus_int nChannelsInternal; opus_int prev_decode_only_middle; +#ifdef ENABLE_OSCE + OSCEModel osce_model; +#endif } silk_decoder; /*********************/ /* Decoder functions */ /*********************/ -opus_int silk_Get_Decoder_Size( /* O Returns error code */ - opus_int *decSizeBytes /* O Number of bytes in SILK decoder state */ -) { + + +opus_int silk_LoadOSCEModels(void *decState, const unsigned char *data, int len) +{ +#ifdef ENABLE_OSCE opus_int ret = SILK_NO_ERROR; - *decSizeBytes = sizeof(silk_decoder); + ret = osce_load_models(&((silk_decoder *)decState)->osce_model, data, len); + ((silk_decoder *)decState)->osce_model.loaded = (ret == 0); + return ret; +#else + (void) decState; + (void) data; + (void) len; + return SILK_NO_ERROR; +#endif +} + +opus_int silk_Get_Decoder_Size( /* O Returns error code */ + opus_int *decSizeBytes /* O Number of bytes in SILK decoder state */ +) +{ + opus_int ret = SILK_NO_ERROR; + + *decSizeBytes = sizeof( silk_decoder ); return ret; } /* Reset decoder state */ -opus_int silk_InitDecoder( /* O Returns error code */ +opus_int silk_ResetDecoder( /* O Returns error code */ void *decState /* I/O State */ -) { +) +{ opus_int n, ret = SILK_NO_ERROR; silk_decoder_state *channel_state = ((silk_decoder *)decState)->channel_state; - for (n = 0; n < DECODER_NUM_CHANNELS; n++) { - ret = silk_init_decoder(&channel_state[ n ]); + for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) { + ret = silk_reset_decoder( &channel_state[ n ] ); + } + silk_memset(&((silk_decoder *)decState)->sStereo, 0, sizeof(((silk_decoder *)decState)->sStereo)); + /* Not strictly needed, but it's cleaner that way */ + ((silk_decoder *)decState)->prev_decode_only_middle = 0; + + return ret; +} + + +opus_int silk_InitDecoder( /* O Returns error code */ + void *decState /* I/O State */ +) +{ + opus_int n, ret = SILK_NO_ERROR; + silk_decoder_state *channel_state = ((silk_decoder *)decState)->channel_state; +#ifdef ENABLE_OSCE + ((silk_decoder *)decState)->osce_model.loaded = 0; +#endif +#ifndef USE_WEIGHTS_FILE + /* load osce models */ + silk_LoadOSCEModels(decState, NULL, 0); +#endif + + for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) { + ret = silk_init_decoder( &channel_state[ n ] ); } silk_memset(&((silk_decoder *)decState)->sStereo, 0, sizeof(((silk_decoder *)decState)->sStereo)); /* Not strictly needed, but it's cleaner that way */ @@ -84,137 +137,141 @@ opus_int silk_Decode( /* O Returns error co ec_dec *psRangeDec, /* I/O Compressor data structure */ opus_int16 *samplesOut, /* O Decoded output speech vector */ opus_int32 *nSamplesOut, /* O Number of samples decoded */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif int arch /* I Run-time architecture */ -) { +) +{ opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR; opus_int32 nSamplesOutDec, LBRR_symbol; opus_int16 *samplesOut1_tmp[ 2 ]; - VARDECL(opus_int16, samplesOut1_tmp_storage1); - VARDECL(opus_int16, samplesOut1_tmp_storage2); - VARDECL(opus_int16, samplesOut2_tmp); + VARDECL( opus_int16, samplesOut1_tmp_storage1 ); + VARDECL( opus_int16, samplesOut1_tmp_storage2 ); + VARDECL( opus_int16, samplesOut2_tmp ); opus_int32 MS_pred_Q13[ 2 ] = { 0 }; opus_int16 *resample_out_ptr; - silk_decoder *psDec = (silk_decoder *)decState; + silk_decoder *psDec = ( silk_decoder * )decState; silk_decoder_state *channel_state = psDec->channel_state; opus_int has_side; opus_int stereo_to_mono; int delay_stack_alloc; SAVE_STACK; - celt_assert(decControl->nChannelsInternal == 1 || decControl->nChannelsInternal == 2); + celt_assert( decControl->nChannelsInternal == 1 || decControl->nChannelsInternal == 2 ); /**********************************/ /* Test if first frame in payload */ /**********************************/ - if (newPacketFlag) { - for (n = 0; n < decControl->nChannelsInternal; n++) { + if( newPacketFlag ) { + for( n = 0; n < decControl->nChannelsInternal; n++ ) { channel_state[ n ].nFramesDecoded = 0; /* Used to count frames in packet */ } } /* If Mono -> Stereo transition in bitstream: init state of second channel */ - if (decControl->nChannelsInternal > psDec->nChannelsInternal) { - ret += silk_init_decoder(&channel_state[ 1 ]); + if( decControl->nChannelsInternal > psDec->nChannelsInternal ) { + ret += silk_init_decoder( &channel_state[ 1 ] ); } stereo_to_mono = decControl->nChannelsInternal == 1 && psDec->nChannelsInternal == 2 && - (decControl->internalSampleRate == 1000 * channel_state[ 0 ].fs_kHz); + ( decControl->internalSampleRate == 1000*channel_state[ 0 ].fs_kHz ); - if (channel_state[ 0 ].nFramesDecoded == 0) { - for (n = 0; n < decControl->nChannelsInternal; n++) { + if( channel_state[ 0 ].nFramesDecoded == 0 ) { + for( n = 0; n < decControl->nChannelsInternal; n++ ) { opus_int fs_kHz_dec; - if (decControl->payloadSize_ms == 0) { + if( decControl->payloadSize_ms == 0 ) { /* Assuming packet loss, use 10 ms */ channel_state[ n ].nFramesPerPacket = 1; channel_state[ n ].nb_subfr = 2; - } else if (decControl->payloadSize_ms == 10) { + } else if( decControl->payloadSize_ms == 10 ) { channel_state[ n ].nFramesPerPacket = 1; channel_state[ n ].nb_subfr = 2; - } else if (decControl->payloadSize_ms == 20) { + } else if( decControl->payloadSize_ms == 20 ) { channel_state[ n ].nFramesPerPacket = 1; channel_state[ n ].nb_subfr = 4; - } else if (decControl->payloadSize_ms == 40) { + } else if( decControl->payloadSize_ms == 40 ) { channel_state[ n ].nFramesPerPacket = 2; channel_state[ n ].nb_subfr = 4; - } else if (decControl->payloadSize_ms == 60) { + } else if( decControl->payloadSize_ms == 60 ) { channel_state[ n ].nFramesPerPacket = 3; channel_state[ n ].nb_subfr = 4; } else { - celt_assert(0); + celt_assert( 0 ); RESTORE_STACK; return SILK_DEC_INVALID_FRAME_SIZE; } - fs_kHz_dec = (decControl->internalSampleRate >> 10) + 1; - if (fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16) { - celt_assert(0); + fs_kHz_dec = ( decControl->internalSampleRate >> 10 ) + 1; + if( fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16 ) { + celt_assert( 0 ); RESTORE_STACK; return SILK_DEC_INVALID_SAMPLING_FREQUENCY; } - ret += silk_decoder_set_fs(&channel_state[ n ], fs_kHz_dec, decControl->API_sampleRate); + ret += silk_decoder_set_fs( &channel_state[ n ], fs_kHz_dec, decControl->API_sampleRate ); } } - if (decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 && (psDec->nChannelsAPI == 1 || psDec->nChannelsInternal == 1)) { - silk_memset(psDec->sStereo.pred_prev_Q13, 0, sizeof(psDec->sStereo.pred_prev_Q13)); - silk_memset(psDec->sStereo.sSide, 0, sizeof(psDec->sStereo.sSide)); - silk_memcpy(&channel_state[ 1 ].resampler_state, &channel_state[ 0 ].resampler_state, sizeof(silk_resampler_state_struct)); + if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 && ( psDec->nChannelsAPI == 1 || psDec->nChannelsInternal == 1 ) ) { + silk_memset( psDec->sStereo.pred_prev_Q13, 0, sizeof( psDec->sStereo.pred_prev_Q13 ) ); + silk_memset( psDec->sStereo.sSide, 0, sizeof( psDec->sStereo.sSide ) ); + silk_memcpy( &channel_state[ 1 ].resampler_state, &channel_state[ 0 ].resampler_state, sizeof( silk_resampler_state_struct ) ); } psDec->nChannelsAPI = decControl->nChannelsAPI; psDec->nChannelsInternal = decControl->nChannelsInternal; - if (decControl->API_sampleRate > (opus_int32)MAX_API_FS_KHZ * 1000 || decControl->API_sampleRate < 8000) { + if( decControl->API_sampleRate > (opus_int32)MAX_API_FS_KHZ * 1000 || decControl->API_sampleRate < 8000 ) { ret = SILK_DEC_INVALID_SAMPLING_FREQUENCY; RESTORE_STACK; - return (ret); + return( ret ); } - if (lostFlag != FLAG_PACKET_LOST && channel_state[ 0 ].nFramesDecoded == 0) { + if( lostFlag != FLAG_PACKET_LOST && channel_state[ 0 ].nFramesDecoded == 0 ) { /* First decoder call for this payload */ /* Decode VAD flags and LBRR flag */ - for (n = 0; n < decControl->nChannelsInternal; n++) { - for (i = 0; i < channel_state[ n ].nFramesPerPacket; i++) { + for( n = 0; n < decControl->nChannelsInternal; n++ ) { + for( i = 0; i < channel_state[ n ].nFramesPerPacket; i++ ) { channel_state[ n ].VAD_flags[ i ] = ec_dec_bit_logp(psRangeDec, 1); } channel_state[ n ].LBRR_flag = ec_dec_bit_logp(psRangeDec, 1); } /* Decode LBRR flags */ - for (n = 0; n < decControl->nChannelsInternal; n++) { - silk_memset(channel_state[ n ].LBRR_flags, 0, sizeof(channel_state[ n ].LBRR_flags)); - if (channel_state[ n ].LBRR_flag) { - if (channel_state[ n ].nFramesPerPacket == 1) { + for( n = 0; n < decControl->nChannelsInternal; n++ ) { + silk_memset( channel_state[ n ].LBRR_flags, 0, sizeof( channel_state[ n ].LBRR_flags ) ); + if( channel_state[ n ].LBRR_flag ) { + if( channel_state[ n ].nFramesPerPacket == 1 ) { channel_state[ n ].LBRR_flags[ 0 ] = 1; } else { - LBRR_symbol = ec_dec_icdf(psRangeDec, silk_LBRR_flags_iCDF_ptr[ channel_state[ n ].nFramesPerPacket - 2 ], 8) + 1; - for (i = 0; i < channel_state[ n ].nFramesPerPacket; i++) { - channel_state[ n ].LBRR_flags[ i ] = silk_RSHIFT(LBRR_symbol, i) & 1; + LBRR_symbol = ec_dec_icdf( psRangeDec, silk_LBRR_flags_iCDF_ptr[ channel_state[ n ].nFramesPerPacket - 2 ], 8 ) + 1; + for( i = 0; i < channel_state[ n ].nFramesPerPacket; i++ ) { + channel_state[ n ].LBRR_flags[ i ] = silk_RSHIFT( LBRR_symbol, i ) & 1; } } } } - if (lostFlag == FLAG_DECODE_NORMAL) { + if( lostFlag == FLAG_DECODE_NORMAL ) { /* Regular decoding: skip all LBRR data */ - for (i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++) { - for (n = 0; n < decControl->nChannelsInternal; n++) { - if (channel_state[ n ].LBRR_flags[ i ]) { + for( i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++ ) { + for( n = 0; n < decControl->nChannelsInternal; n++ ) { + if( channel_state[ n ].LBRR_flags[ i ] ) { opus_int16 pulses[ MAX_FRAME_LENGTH ]; opus_int condCoding; - if (decControl->nChannelsInternal == 2 && n == 0) { - silk_stereo_decode_pred(psRangeDec, MS_pred_Q13); - if (channel_state[ 1 ].LBRR_flags[ i ] == 0) { - silk_stereo_decode_mid_only(psRangeDec, &decode_only_middle); + if( decControl->nChannelsInternal == 2 && n == 0 ) { + silk_stereo_decode_pred( psRangeDec, MS_pred_Q13 ); + if( channel_state[ 1 ].LBRR_flags[ i ] == 0 ) { + silk_stereo_decode_mid_only( psRangeDec, &decode_only_middle ); } } /* Use conditional coding if previous frame available */ - if (i > 0 && channel_state[ n ].LBRR_flags[ i - 1 ]) { + if( i > 0 && channel_state[ n ].LBRR_flags[ i - 1 ] ) { condCoding = CODE_CONDITIONALLY; } else { condCoding = CODE_INDEPENDENTLY; } - silk_decode_indices(&channel_state[ n ], psRangeDec, i, 1, condCoding); - silk_decode_pulses(psRangeDec, pulses, channel_state[ n ].indices.signalType, - channel_state[ n ].indices.quantOffsetType, channel_state[ n ].frame_length); + silk_decode_indices( &channel_state[ n ], psRangeDec, i, 1, condCoding ); + silk_decode_pulses( psRangeDec, pulses, channel_state[ n ].indices.signalType, + channel_state[ n ].indices.quantOffsetType, channel_state[ n ].frame_length ); } } } @@ -222,158 +279,173 @@ opus_int silk_Decode( /* O Returns error co } /* Get MS predictor index */ - if (decControl->nChannelsInternal == 2) { - if (lostFlag == FLAG_DECODE_NORMAL || - (lostFlag == FLAG_DECODE_LBRR && channel_state[ 0 ].LBRR_flags[ channel_state[ 0 ].nFramesDecoded ] == 1)) { - silk_stereo_decode_pred(psRangeDec, MS_pred_Q13); + if( decControl->nChannelsInternal == 2 ) { + if( lostFlag == FLAG_DECODE_NORMAL || + ( lostFlag == FLAG_DECODE_LBRR && channel_state[ 0 ].LBRR_flags[ channel_state[ 0 ].nFramesDecoded ] == 1 ) ) + { + silk_stereo_decode_pred( psRangeDec, MS_pred_Q13 ); /* For LBRR data, decode mid-only flag only if side-channel's LBRR flag is false */ - if ((lostFlag == FLAG_DECODE_NORMAL && channel_state[ 1 ].VAD_flags[ channel_state[ 0 ].nFramesDecoded ] == 0) || - (lostFlag == FLAG_DECODE_LBRR && channel_state[ 1 ].LBRR_flags[ channel_state[ 0 ].nFramesDecoded ] == 0)) { - silk_stereo_decode_mid_only(psRangeDec, &decode_only_middle); + if( ( lostFlag == FLAG_DECODE_NORMAL && channel_state[ 1 ].VAD_flags[ channel_state[ 0 ].nFramesDecoded ] == 0 ) || + ( lostFlag == FLAG_DECODE_LBRR && channel_state[ 1 ].LBRR_flags[ channel_state[ 0 ].nFramesDecoded ] == 0 ) ) + { + silk_stereo_decode_mid_only( psRangeDec, &decode_only_middle ); } else { decode_only_middle = 0; } } else { - for (n = 0; n < 2; n++) { + for( n = 0; n < 2; n++ ) { MS_pred_Q13[ n ] = psDec->sStereo.pred_prev_Q13[ n ]; } } } /* Reset side channel decoder prediction memory for first frame with side coding */ - if (decControl->nChannelsInternal == 2 && decode_only_middle == 0 && psDec->prev_decode_only_middle == 1) { - silk_memset(psDec->channel_state[ 1 ].outBuf, 0, sizeof(psDec->channel_state[ 1 ].outBuf)); - silk_memset(psDec->channel_state[ 1 ].sLPC_Q14_buf, 0, sizeof(psDec->channel_state[ 1 ].sLPC_Q14_buf)); + if( decControl->nChannelsInternal == 2 && decode_only_middle == 0 && psDec->prev_decode_only_middle == 1 ) { + silk_memset( psDec->channel_state[ 1 ].outBuf, 0, sizeof(psDec->channel_state[ 1 ].outBuf) ); + silk_memset( psDec->channel_state[ 1 ].sLPC_Q14_buf, 0, sizeof(psDec->channel_state[ 1 ].sLPC_Q14_buf) ); psDec->channel_state[ 1 ].lagPrev = 100; psDec->channel_state[ 1 ].LastGainIndex = 10; psDec->channel_state[ 1 ].prevSignalType = TYPE_NO_VOICE_ACTIVITY; psDec->channel_state[ 1 ].first_frame_after_reset = 1; } - /* Check if the temp buffer fits into the output PCM buffer. If it fits, - we can delay allocating the temp buffer until after the SILK peak stack - usage. We need to use a < and not a <= because of the two extra samples. */ - delay_stack_alloc = decControl->internalSampleRate * decControl->nChannelsInternal - < decControl->API_sampleRate * decControl->nChannelsAPI; - ALLOC(samplesOut1_tmp_storage1, delay_stack_alloc ? ALLOC_NONE - : decControl->nChannelsInternal * (channel_state[ 0 ].frame_length + 2), - opus_int16); - if (delay_stack_alloc) { - samplesOut1_tmp[ 0 ] = samplesOut; - samplesOut1_tmp[ 1 ] = samplesOut + channel_state[ 0 ].frame_length + 2; + /* Check if the temp buffer fits into the output PCM buffer. If it fits, + we can delay allocating the temp buffer until after the SILK peak stack + usage. We need to use a < and not a <= because of the two extra samples. */ + delay_stack_alloc = decControl->internalSampleRate*decControl->nChannelsInternal + < decControl->API_sampleRate*decControl->nChannelsAPI; + ALLOC( samplesOut1_tmp_storage1, delay_stack_alloc ? ALLOC_NONE + : decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2 ), + opus_int16 ); + if ( delay_stack_alloc ) + { + samplesOut1_tmp[ 0 ] = samplesOut; + samplesOut1_tmp[ 1 ] = samplesOut + channel_state[ 0 ].frame_length + 2; } else { - samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage1; - samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage1 + channel_state[ 0 ].frame_length + 2; + samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage1; + samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage1 + channel_state[ 0 ].frame_length + 2; } - if (lostFlag == FLAG_DECODE_NORMAL) { + if( lostFlag == FLAG_DECODE_NORMAL ) { has_side = !decode_only_middle; } else { has_side = !psDec->prev_decode_only_middle - || (decControl->nChannelsInternal == 2 && lostFlag == FLAG_DECODE_LBRR && channel_state[1].LBRR_flags[ channel_state[1].nFramesDecoded ] == 1); + || (decControl->nChannelsInternal == 2 && lostFlag == FLAG_DECODE_LBRR && channel_state[1].LBRR_flags[ channel_state[1].nFramesDecoded ] == 1 ); } + channel_state[ 0 ].sPLC.enable_deep_plc = decControl->enable_deep_plc; /* Call decoder for one frame */ - for (n = 0; n < decControl->nChannelsInternal; n++) { - if (n == 0 || has_side) { + for( n = 0; n < decControl->nChannelsInternal; n++ ) { + if( n == 0 || has_side ) { opus_int FrameIndex; opus_int condCoding; FrameIndex = channel_state[ 0 ].nFramesDecoded - n; /* Use independent coding if no previous frame available */ - if (FrameIndex <= 0) { + if( FrameIndex <= 0 ) { condCoding = CODE_INDEPENDENTLY; - } else if (lostFlag == FLAG_DECODE_LBRR) { + } else if( lostFlag == FLAG_DECODE_LBRR ) { condCoding = channel_state[ n ].LBRR_flags[ FrameIndex - 1 ] ? CODE_CONDITIONALLY : CODE_INDEPENDENTLY; - } else if (n > 0 && psDec->prev_decode_only_middle) { - /* If we skipped a side frame in this packet, we don't - need LTP scaling; the LTP state is well-defined. */ + } else if( n > 0 && psDec->prev_decode_only_middle ) { + /* If we skipped a side frame in this packet, we don't + need LTP scaling; the LTP state is well-defined. */ condCoding = CODE_INDEPENDENTLY_NO_LTP_SCALING; } else { condCoding = CODE_CONDITIONALLY; } - ret += silk_decode_frame(&channel_state[ n ], psRangeDec, &samplesOut1_tmp[ n ][ 2 ], &nSamplesOutDec, lostFlag, condCoding, arch); +#ifdef ENABLE_OSCE + if ( channel_state[n].osce.method != decControl->osce_method ) { + osce_reset( &channel_state[n].osce, decControl->osce_method ); + } +#endif + ret += silk_decode_frame( &channel_state[ n ], psRangeDec, &samplesOut1_tmp[ n ][ 2 ], &nSamplesOutDec, lostFlag, condCoding, +#ifdef ENABLE_DEEP_PLC + n == 0 ? lpcnet : NULL, +#endif +#ifdef ENABLE_OSCE + &psDec->osce_model, +#endif + arch); } else { - silk_memset(&samplesOut1_tmp[ n ][ 2 ], 0, nSamplesOutDec * sizeof(opus_int16)); + silk_memset( &samplesOut1_tmp[ n ][ 2 ], 0, nSamplesOutDec * sizeof( opus_int16 ) ); } channel_state[ n ].nFramesDecoded++; } - if (decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2) { + if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 ) { /* Convert Mid/Side to Left/Right */ - silk_stereo_MS_to_LR(&psDec->sStereo, samplesOut1_tmp[ 0 ], samplesOut1_tmp[ 1 ], MS_pred_Q13, channel_state[ 0 ].fs_kHz, nSamplesOutDec); + silk_stereo_MS_to_LR( &psDec->sStereo, samplesOut1_tmp[ 0 ], samplesOut1_tmp[ 1 ], MS_pred_Q13, channel_state[ 0 ].fs_kHz, nSamplesOutDec ); } else { /* Buffering */ - silk_memcpy(samplesOut1_tmp[ 0 ], psDec->sStereo.sMid, 2 * sizeof(opus_int16)); - silk_memcpy(psDec->sStereo.sMid, &samplesOut1_tmp[ 0 ][ nSamplesOutDec ], 2 * sizeof(opus_int16)); + silk_memcpy( samplesOut1_tmp[ 0 ], psDec->sStereo.sMid, 2 * sizeof( opus_int16 ) ); + silk_memcpy( psDec->sStereo.sMid, &samplesOut1_tmp[ 0 ][ nSamplesOutDec ], 2 * sizeof( opus_int16 ) ); } /* Number of output samples */ - *nSamplesOut = silk_DIV32(nSamplesOutDec * decControl->API_sampleRate, silk_SMULBB(channel_state[ 0 ].fs_kHz, 1000)); + *nSamplesOut = silk_DIV32( nSamplesOutDec * decControl->API_sampleRate, silk_SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) ); /* Set up pointers to temp buffers */ - ALLOC(samplesOut2_tmp, - decControl->nChannelsAPI == 2 ? *nSamplesOut : ALLOC_NONE, opus_int16); - if (decControl->nChannelsAPI == 2) { + ALLOC( samplesOut2_tmp, + decControl->nChannelsAPI == 2 ? *nSamplesOut : ALLOC_NONE, opus_int16 ); + if( decControl->nChannelsAPI == 2 ) { resample_out_ptr = samplesOut2_tmp; } else { resample_out_ptr = samplesOut; } - ALLOC(samplesOut1_tmp_storage2, delay_stack_alloc - ? decControl->nChannelsInternal * (channel_state[ 0 ].frame_length + 2) - : ALLOC_NONE, - opus_int16); - if (delay_stack_alloc) { - OPUS_COPY(samplesOut1_tmp_storage2, samplesOut, decControl->nChannelsInternal * (channel_state[ 0 ].frame_length + 2)); - samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage2; - samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage2 + channel_state[ 0 ].frame_length + 2; + ALLOC( samplesOut1_tmp_storage2, delay_stack_alloc + ? decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2 ) + : ALLOC_NONE, + opus_int16 ); + if ( delay_stack_alloc ) { + OPUS_COPY(samplesOut1_tmp_storage2, samplesOut, decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2)); + samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage2; + samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage2 + channel_state[ 0 ].frame_length + 2; } - for (n = 0; n < silk_min(decControl->nChannelsAPI, decControl->nChannelsInternal); n++) { + for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInternal ); n++ ) { /* Resample decoded signal to API_sampleRate */ - ret += silk_resampler(&channel_state[ n ].resampler_state, resample_out_ptr, &samplesOut1_tmp[ n ][ 1 ], nSamplesOutDec); + ret += silk_resampler( &channel_state[ n ].resampler_state, resample_out_ptr, &samplesOut1_tmp[ n ][ 1 ], nSamplesOutDec ); /* Interleave if stereo output and stereo stream */ - if (decControl->nChannelsAPI == 2) { - for (i = 0; i < *nSamplesOut; i++) { + if( decControl->nChannelsAPI == 2 ) { + for( i = 0; i < *nSamplesOut; i++ ) { samplesOut[ n + 2 * i ] = resample_out_ptr[ i ]; } } } /* Create two channel output from mono stream */ - if (decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 1) { - if (stereo_to_mono) { - /* Resample right channel for newly collapsed stereo just in case - we weren't doing collapsing when switching to mono */ - ret += silk_resampler(&channel_state[ 1 ].resampler_state, resample_out_ptr, &samplesOut1_tmp[ 0 ][ 1 ], nSamplesOutDec); + if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 1 ) { + if ( stereo_to_mono ){ + /* Resample right channel for newly collapsed stereo just in case + we weren't doing collapsing when switching to mono */ + ret += silk_resampler( &channel_state[ 1 ].resampler_state, resample_out_ptr, &samplesOut1_tmp[ 0 ][ 1 ], nSamplesOutDec ); - for (i = 0; i < *nSamplesOut; i++) { + for( i = 0; i < *nSamplesOut; i++ ) { samplesOut[ 1 + 2 * i ] = resample_out_ptr[ i ]; } } else { - for (i = 0; i < *nSamplesOut; i++) { + for( i = 0; i < *nSamplesOut; i++ ) { samplesOut[ 1 + 2 * i ] = samplesOut[ 0 + 2 * i ]; } } } /* Export pitch lag, measured at 48 kHz sampling rate */ - if (channel_state[ 0 ].prevSignalType == TYPE_VOICED) { + if( channel_state[ 0 ].prevSignalType == TYPE_VOICED ) { int mult_tab[ 3 ] = { 6, 4, 3 }; - decControl->prevPitchLag = channel_state[ 0 ].lagPrev * mult_tab[(channel_state[ 0 ].fs_kHz - 8) >> 2 ]; + decControl->prevPitchLag = channel_state[ 0 ].lagPrev * mult_tab[ ( channel_state[ 0 ].fs_kHz - 8 ) >> 2 ]; } else { decControl->prevPitchLag = 0; } - if (lostFlag == FLAG_PACKET_LOST) { - /* On packet loss, remove the gain clamping to prevent having the energy "bounce back" - if we lose packets when the energy is going down */ - for (i = 0; i < psDec->nChannelsInternal; i++) { - psDec->channel_state[ i ].LastGainIndex = 10; - } + if( lostFlag == FLAG_PACKET_LOST ) { + /* On packet loss, remove the gain clamping to prevent having the energy "bounce back" + if we lose packets when the energy is going down */ + for ( i = 0; i < psDec->nChannelsInternal; i++ ) + psDec->channel_state[ i ].LastGainIndex = 10; } else { - psDec->prev_decode_only_middle = decode_only_middle; + psDec->prev_decode_only_middle = decode_only_middle; } RESTORE_STACK; return ret; @@ -386,24 +458,25 @@ opus_int silk_get_TOC( const opus_int nBytesIn, /* I Number of input bytes */ const opus_int nFramesPerPayload, /* I Number of SILK frames per payload */ silk_TOC_struct *Silk_TOC /* O Type of content */ -) { +) +{ opus_int i, flags, ret = SILK_NO_ERROR; - if (nBytesIn < 1) { + if( nBytesIn < 1 ) { return -1; } - if (nFramesPerPayload < 0 || nFramesPerPayload > 3) { + if( nFramesPerPayload < 0 || nFramesPerPayload > 3 ) { return -1; } - silk_memset(Silk_TOC, 0, sizeof(*Silk_TOC)); + silk_memset( Silk_TOC, 0, sizeof( *Silk_TOC ) ); /* For stereo, extract the flags for the mid channel */ - flags = silk_RSHIFT(payload[ 0 ], 7 - nFramesPerPayload) & (silk_LSHIFT(1, nFramesPerPayload + 1) - 1); + flags = silk_RSHIFT( payload[ 0 ], 7 - nFramesPerPayload ) & ( silk_LSHIFT( 1, nFramesPerPayload + 1 ) - 1 ); Silk_TOC->inbandFECFlag = flags & 1; - for (i = nFramesPerPayload - 1; i >= 0 ; i--) { - flags = silk_RSHIFT(flags, 1); + for( i = nFramesPerPayload - 1; i >= 0 ; i-- ) { + flags = silk_RSHIFT( flags, 1 ); Silk_TOC->VADFlags[ i ] = flags & 1; Silk_TOC->VADFlag |= flags & 1; } diff --git a/src/libopus/silk/decode_core.c b/src/libopus/silk/decode_core.c index e05a800..ffe752c 100644 --- a/src/libopus/silk/decode_core.c +++ b/src/libopus/silk/decode_core.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" /**********************************************************/ /* Core decoder. Performs inverse NSQ operation LTP + LPC */ @@ -41,27 +41,28 @@ void silk_decode_core( opus_int16 xq[], /* O Decoded speech */ const opus_int16 pulses[ MAX_FRAME_LENGTH ], /* I Pulse signal */ int arch /* I Run-time architecture */ -) { +) +{ opus_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType; opus_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ]; - VARDECL(opus_int16, sLTP); - VARDECL(opus_int32, sLTP_Q15); + VARDECL( opus_int16, sLTP ); + VARDECL( opus_int32, sLTP_Q15 ); opus_int32 LTP_pred_Q13, LPC_pred_Q10, Gain_Q10, inv_gain_Q31, gain_adj_Q16, rand_seed, offset_Q10; opus_int32 *pred_lag_ptr, *pexc_Q14, *pres_Q14; - VARDECL(opus_int32, res_Q14); - VARDECL(opus_int32, sLPC_Q14); + VARDECL( opus_int32, res_Q14 ); + VARDECL( opus_int32, sLPC_Q14 ); SAVE_STACK; - silk_assert(psDec->prev_gain_Q16 != 0); + silk_assert( psDec->prev_gain_Q16 != 0 ); - ALLOC(sLTP, psDec->ltp_mem_length, opus_int16); - ALLOC(sLTP_Q15, psDec->ltp_mem_length + psDec->frame_length, opus_int32); - ALLOC(res_Q14, psDec->subfr_length, opus_int32); - ALLOC(sLPC_Q14, psDec->subfr_length + MAX_LPC_ORDER, opus_int32); + ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 ); + ALLOC( sLTP_Q15, psDec->ltp_mem_length + psDec->frame_length, opus_int32 ); + ALLOC( res_Q14, psDec->subfr_length, opus_int32 ); + ALLOC( sLPC_Q14, psDec->subfr_length + MAX_LPC_ORDER, opus_int32 ); offset_Q10 = silk_Quantization_Offsets_Q10[ psDec->indices.signalType >> 1 ][ psDec->indices.quantOffsetType ]; - if (psDec->indices.NLSFInterpCoef_Q2 < 1 << 2) { + if( psDec->indices.NLSFInterpCoef_Q2 < 1 << 2 ) { NLSF_interpolation_flag = 1; } else { NLSF_interpolation_flag = 0; @@ -69,167 +70,168 @@ void silk_decode_core( /* Decode excitation */ rand_seed = psDec->indices.Seed; - for (i = 0; i < psDec->frame_length; i++) { - rand_seed = silk_RAND(rand_seed); - psDec->exc_Q14[ i ] = silk_LSHIFT((opus_int32)pulses[ i ], 14); - if (psDec->exc_Q14[ i ] > 0) { + for( i = 0; i < psDec->frame_length; i++ ) { + rand_seed = silk_RAND( rand_seed ); + psDec->exc_Q14[ i ] = silk_LSHIFT( (opus_int32)pulses[ i ], 14 ); + if( psDec->exc_Q14[ i ] > 0 ) { psDec->exc_Q14[ i ] -= QUANT_LEVEL_ADJUST_Q10 << 4; - } else if (psDec->exc_Q14[ i ] < 0) { + } else + if( psDec->exc_Q14[ i ] < 0 ) { psDec->exc_Q14[ i ] += QUANT_LEVEL_ADJUST_Q10 << 4; } psDec->exc_Q14[ i ] += offset_Q10 << 4; - if (rand_seed < 0) { - psDec->exc_Q14[ i ] = -psDec->exc_Q14[ i ]; + if( rand_seed < 0 ) { + psDec->exc_Q14[ i ] = -psDec->exc_Q14[ i ]; } - rand_seed = silk_ADD32_ovflw(rand_seed, pulses[ i ]); + rand_seed = silk_ADD32_ovflw( rand_seed, pulses[ i ] ); } /* Copy LPC state */ - silk_memcpy(sLPC_Q14, psDec->sLPC_Q14_buf, MAX_LPC_ORDER * sizeof(opus_int32)); + silk_memcpy( sLPC_Q14, psDec->sLPC_Q14_buf, MAX_LPC_ORDER * sizeof( opus_int32 ) ); pexc_Q14 = psDec->exc_Q14; pxq = xq; sLTP_buf_idx = psDec->ltp_mem_length; /* Loop over subframes */ - for (k = 0; k < psDec->nb_subfr; k++) { + for( k = 0; k < psDec->nb_subfr; k++ ) { pres_Q14 = res_Q14; A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ]; /* Preload LPC coeficients to array on stack. Gives small performance gain */ - silk_memcpy(A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof(opus_int16)); + silk_memcpy( A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof( opus_int16 ) ); B_Q14 = &psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER ]; signalType = psDec->indices.signalType; - Gain_Q10 = silk_RSHIFT(psDecCtrl->Gains_Q16[ k ], 6); - inv_gain_Q31 = silk_INVERSE32_varQ(psDecCtrl->Gains_Q16[ k ], 47); + Gain_Q10 = silk_RSHIFT( psDecCtrl->Gains_Q16[ k ], 6 ); + inv_gain_Q31 = silk_INVERSE32_varQ( psDecCtrl->Gains_Q16[ k ], 47 ); /* Calculate gain adjustment factor */ - if (psDecCtrl->Gains_Q16[ k ] != psDec->prev_gain_Q16) { - gain_adj_Q16 = silk_DIV32_varQ(psDec->prev_gain_Q16, psDecCtrl->Gains_Q16[ k ], 16); + if( psDecCtrl->Gains_Q16[ k ] != psDec->prev_gain_Q16 ) { + gain_adj_Q16 = silk_DIV32_varQ( psDec->prev_gain_Q16, psDecCtrl->Gains_Q16[ k ], 16 ); /* Scale short term state */ - for (i = 0; i < MAX_LPC_ORDER; i++) { - sLPC_Q14[ i ] = silk_SMULWW(gain_adj_Q16, sLPC_Q14[ i ]); + for( i = 0; i < MAX_LPC_ORDER; i++ ) { + sLPC_Q14[ i ] = silk_SMULWW( gain_adj_Q16, sLPC_Q14[ i ] ); } } else { gain_adj_Q16 = (opus_int32)1 << 16; } /* Save inv_gain */ - silk_assert(inv_gain_Q31 != 0); + silk_assert( inv_gain_Q31 != 0 ); psDec->prev_gain_Q16 = psDecCtrl->Gains_Q16[ k ]; /* Avoid abrupt transition from voiced PLC to unvoiced normal decoding */ - if (psDec->lossCnt && psDec->prevSignalType == TYPE_VOICED && - psDec->indices.signalType != TYPE_VOICED && k < MAX_NB_SUBFR / 2) { + if( psDec->lossCnt && psDec->prevSignalType == TYPE_VOICED && + psDec->indices.signalType != TYPE_VOICED && k < MAX_NB_SUBFR/2 ) { - silk_memset(B_Q14, 0, LTP_ORDER * sizeof(opus_int16)); - B_Q14[ LTP_ORDER / 2 ] = SILK_FIX_CONST(0.25, 14); + silk_memset( B_Q14, 0, LTP_ORDER * sizeof( opus_int16 ) ); + B_Q14[ LTP_ORDER/2 ] = SILK_FIX_CONST( 0.25, 14 ); signalType = TYPE_VOICED; psDecCtrl->pitchL[ k ] = psDec->lagPrev; } - if (signalType == TYPE_VOICED) { + if( signalType == TYPE_VOICED ) { /* Voiced */ lag = psDecCtrl->pitchL[ k ]; /* Re-whitening */ - if (k == 0 || (k == 2 && NLSF_interpolation_flag)) { + if( k == 0 || ( k == 2 && NLSF_interpolation_flag ) ) { /* Rewhiten with new A coefs */ start_idx = psDec->ltp_mem_length - lag - psDec->LPC_order - LTP_ORDER / 2; - celt_assert(start_idx > 0); + celt_assert( start_idx > 0 ); - if (k == 2) { - silk_memcpy(&psDec->outBuf[ psDec->ltp_mem_length ], xq, 2 * psDec->subfr_length * sizeof(opus_int16)); + if( k == 2 ) { + silk_memcpy( &psDec->outBuf[ psDec->ltp_mem_length ], xq, 2 * psDec->subfr_length * sizeof( opus_int16 ) ); } - silk_LPC_analysis_filter(&sLTP[ start_idx ], &psDec->outBuf[ start_idx + k * psDec->subfr_length ], - A_Q12, psDec->ltp_mem_length - start_idx, psDec->LPC_order, arch); + silk_LPC_analysis_filter( &sLTP[ start_idx ], &psDec->outBuf[ start_idx + k * psDec->subfr_length ], + A_Q12, psDec->ltp_mem_length - start_idx, psDec->LPC_order, arch ); /* After rewhitening the LTP state is unscaled */ - if (k == 0) { + if( k == 0 ) { /* Do LTP downscaling to reduce inter-packet dependency */ - inv_gain_Q31 = silk_LSHIFT(silk_SMULWB(inv_gain_Q31, psDecCtrl->LTP_scale_Q14), 2); + inv_gain_Q31 = silk_LSHIFT( silk_SMULWB( inv_gain_Q31, psDecCtrl->LTP_scale_Q14 ), 2 ); } - for (i = 0; i < lag + LTP_ORDER / 2; i++) { - sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWB(inv_gain_Q31, sLTP[ psDec->ltp_mem_length - i - 1 ]); + for( i = 0; i < lag + LTP_ORDER/2; i++ ) { + sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWB( inv_gain_Q31, sLTP[ psDec->ltp_mem_length - i - 1 ] ); } } else { /* Update LTP state when Gain changes */ - if (gain_adj_Q16 != (opus_int32)1 << 16) { - for (i = 0; i < lag + LTP_ORDER / 2; i++) { - sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWW(gain_adj_Q16, sLTP_Q15[ sLTP_buf_idx - i - 1 ]); + if( gain_adj_Q16 != (opus_int32)1 << 16 ) { + for( i = 0; i < lag + LTP_ORDER/2; i++ ) { + sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWW( gain_adj_Q16, sLTP_Q15[ sLTP_buf_idx - i - 1 ] ); } } } } /* Long-term prediction */ - if (signalType == TYPE_VOICED) { + if( signalType == TYPE_VOICED ) { /* Set up pointer */ pred_lag_ptr = &sLTP_Q15[ sLTP_buf_idx - lag + LTP_ORDER / 2 ]; - for (i = 0; i < psDec->subfr_length; i++) { + for( i = 0; i < psDec->subfr_length; i++ ) { /* Unrolled loop */ /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ LTP_pred_Q13 = 2; - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ 0 ], B_Q14[ 0 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -1 ], B_Q14[ 1 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -2 ], B_Q14[ 2 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -3 ], B_Q14[ 3 ]); - LTP_pred_Q13 = silk_SMLAWB(LTP_pred_Q13, pred_lag_ptr[ -4 ], B_Q14[ 4 ]); + LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ 0 ], B_Q14[ 0 ] ); + LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -1 ], B_Q14[ 1 ] ); + LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -2 ], B_Q14[ 2 ] ); + LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -3 ], B_Q14[ 3 ] ); + LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -4 ], B_Q14[ 4 ] ); pred_lag_ptr++; /* Generate LPC excitation */ - pres_Q14[ i ] = silk_ADD_LSHIFT32(pexc_Q14[ i ], LTP_pred_Q13, 1); + pres_Q14[ i ] = silk_ADD_LSHIFT32( pexc_Q14[ i ], LTP_pred_Q13, 1 ); /* Update states */ - sLTP_Q15[ sLTP_buf_idx ] = silk_LSHIFT(pres_Q14[ i ], 1); + sLTP_Q15[ sLTP_buf_idx ] = silk_LSHIFT( pres_Q14[ i ], 1 ); sLTP_buf_idx++; } } else { pres_Q14 = pexc_Q14; } - for (i = 0; i < psDec->subfr_length; i++) { + for( i = 0; i < psDec->subfr_length; i++ ) { /* Short-term prediction */ - celt_assert(psDec->LPC_order == 10 || psDec->LPC_order == 16); + celt_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 ); /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ - LPC_pred_Q10 = silk_RSHIFT(psDec->LPC_order, 1); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp[ 0 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp[ 1 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp[ 2 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp[ 3 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp[ 4 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp[ 5 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp[ 6 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp[ 7 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp[ 8 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ]); - if (psDec->LPC_order == 16) { - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 11 ], A_Q12_tmp[ 10 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 12 ], A_Q12_tmp[ 11 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 13 ], A_Q12_tmp[ 12 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 14 ], A_Q12_tmp[ 13 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 15 ], A_Q12_tmp[ 14 ]); - LPC_pred_Q10 = silk_SMLAWB(LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 16 ], A_Q12_tmp[ 15 ]); + LPC_pred_Q10 = silk_RSHIFT( psDec->LPC_order, 1 ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp[ 0 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp[ 1 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp[ 2 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp[ 3 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp[ 4 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp[ 5 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp[ 6 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp[ 7 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp[ 8 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] ); + if( psDec->LPC_order == 16 ) { + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 11 ], A_Q12_tmp[ 10 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 12 ], A_Q12_tmp[ 11 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 13 ], A_Q12_tmp[ 12 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 14 ], A_Q12_tmp[ 13 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 15 ], A_Q12_tmp[ 14 ] ); + LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 16 ], A_Q12_tmp[ 15 ] ); } /* Add prediction to LPC excitation */ - sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32(pres_Q14[ i ], silk_LSHIFT_SAT32(LPC_pred_Q10, 4)); + sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( pres_Q14[ i ], silk_LSHIFT_SAT32( LPC_pred_Q10, 4 ) ); /* Scale with gain */ - pxq[ i ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(silk_SMULWW(sLPC_Q14[ MAX_LPC_ORDER + i ], Gain_Q10), 8)); + pxq[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14[ MAX_LPC_ORDER + i ], Gain_Q10 ), 8 ) ); } /* Update LPC filter state */ - silk_memcpy(sLPC_Q14, &sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof(opus_int32)); + silk_memcpy( sLPC_Q14, &sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( opus_int32 ) ); pexc_Q14 += psDec->subfr_length; pxq += psDec->subfr_length; } /* Save LPC state */ - silk_memcpy(psDec->sLPC_Q14_buf, sLPC_Q14, MAX_LPC_ORDER * sizeof(opus_int32)); + silk_memcpy( psDec->sLPC_Q14_buf, sLPC_Q14, MAX_LPC_ORDER * sizeof( opus_int32 ) ); RESTORE_STACK; } diff --git a/src/libopus/silk/decode_frame.c b/src/libopus/silk/decode_frame.c index 226ff13..fcb5189 100644 --- a/src/libopus/silk/decode_frame.c +++ b/src/libopus/silk/decode_frame.c @@ -1,38 +1,42 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" #include "PLC.h" +#ifdef ENABLE_OSCE +#include "osce.h" +#endif + /****************/ /* Decode frame */ /****************/ @@ -43,79 +47,116 @@ opus_int silk_decode_frame( opus_int32 *pN, /* O Pointer to size of output frame */ opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */ opus_int condCoding, /* I The type of conditional coding to use */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif +#ifdef ENABLE_OSCE + OSCEModel *osce_model, +#endif int arch /* I Run-time architecture */ -) { - VARDECL(silk_decoder_control, psDecCtrl); +) +{ + VARDECL( silk_decoder_control, psDecCtrl ); opus_int L, mv_len, ret = 0; SAVE_STACK; L = psDec->frame_length; - ALLOC(psDecCtrl, 1, silk_decoder_control); + ALLOC( psDecCtrl, 1, silk_decoder_control ); psDecCtrl->LTP_scale_Q14 = 0; /* Safety checks */ - celt_assert(L > 0 && L <= MAX_FRAME_LENGTH); + celt_assert( L > 0 && L <= MAX_FRAME_LENGTH ); - if (lostFlag == FLAG_DECODE_NORMAL || - (lostFlag == FLAG_DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 1)) { - VARDECL(opus_int16, pulses); - ALLOC(pulses, (L + SHELL_CODEC_FRAME_LENGTH - 1) & - ~(SHELL_CODEC_FRAME_LENGTH - 1), opus_int16); + if( lostFlag == FLAG_DECODE_NORMAL || + ( lostFlag == FLAG_DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 1 ) ) + { + VARDECL( opus_int16, pulses ); +#ifdef ENABLE_OSCE + opus_int32 ec_start; + ec_start = ec_tell(psRangeDec); +#endif + ALLOC( pulses, (L + SHELL_CODEC_FRAME_LENGTH - 1) & + ~(SHELL_CODEC_FRAME_LENGTH - 1), opus_int16 ); /*********************************************/ /* Decode quantization indices of side info */ /*********************************************/ - silk_decode_indices(psDec, psRangeDec, psDec->nFramesDecoded, lostFlag, condCoding); + silk_decode_indices( psDec, psRangeDec, psDec->nFramesDecoded, lostFlag, condCoding ); /*********************************************/ /* Decode quantization indices of excitation */ /*********************************************/ - silk_decode_pulses(psRangeDec, pulses, psDec->indices.signalType, - psDec->indices.quantOffsetType, psDec->frame_length); + silk_decode_pulses( psRangeDec, pulses, psDec->indices.signalType, + psDec->indices.quantOffsetType, psDec->frame_length ); /********************************************/ /* Decode parameters and pulse signal */ /********************************************/ - silk_decode_parameters(psDec, psDecCtrl, condCoding); + silk_decode_parameters( psDec, psDecCtrl, condCoding ); /********************************************************/ /* Run inverse NSQ */ /********************************************************/ - silk_decode_core(psDec, psDecCtrl, pOut, pulses, arch); + silk_decode_core( psDec, psDecCtrl, pOut, pulses, arch ); + + /*************************/ + /* Update output buffer. */ + /*************************/ + celt_assert( psDec->ltp_mem_length >= psDec->frame_length ); + mv_len = psDec->ltp_mem_length - psDec->frame_length; + silk_memmove( psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16) ); + silk_memcpy( &psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof( opus_int16 ) ); + +#ifdef ENABLE_OSCE + /********************************************************/ + /* Run SILK enhancer */ + /********************************************************/ + osce_enhance_frame( osce_model, psDec, psDecCtrl, pOut, ec_tell(psRangeDec) - ec_start, arch ); +#endif /********************************************************/ /* Update PLC state */ /********************************************************/ - silk_PLC(psDec, psDecCtrl, pOut, 0, arch); + silk_PLC( psDec, psDecCtrl, pOut, 0, +#ifdef ENABLE_DEEP_PLC + lpcnet, +#endif + arch ); psDec->lossCnt = 0; psDec->prevSignalType = psDec->indices.signalType; - celt_assert(psDec->prevSignalType >= 0 && psDec->prevSignalType <= 2); + celt_assert( psDec->prevSignalType >= 0 && psDec->prevSignalType <= 2 ); /* A frame has been decoded without errors */ psDec->first_frame_after_reset = 0; } else { /* Handle packet loss by extrapolation */ - psDec->indices.signalType = psDec->prevSignalType; - silk_PLC(psDec, psDecCtrl, pOut, 1, arch); - } + silk_PLC( psDec, psDecCtrl, pOut, 1, +#ifdef ENABLE_DEEP_PLC + lpcnet, +#endif + arch ); - /*************************/ - /* Update output buffer. */ - /*************************/ - celt_assert(psDec->ltp_mem_length >= psDec->frame_length); - mv_len = psDec->ltp_mem_length - psDec->frame_length; - silk_memmove(psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16)); - silk_memcpy(&psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof(opus_int16)); +#ifdef ENABLE_OSCE + osce_reset( &psDec->osce, psDec->osce.method ); +#endif + /*************************/ + /* Update output buffer. */ + /*************************/ + celt_assert( psDec->ltp_mem_length >= psDec->frame_length ); + mv_len = psDec->ltp_mem_length - psDec->frame_length; + silk_memmove( psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16) ); + silk_memcpy( &psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof( opus_int16 ) ); + } /************************************************/ /* Comfort noise generation / estimation */ /************************************************/ - silk_CNG(psDec, psDecCtrl, pOut, L); + silk_CNG( psDec, psDecCtrl, pOut, L ); /****************************************************************/ /* Ensure smooth connection of extrapolated and good frames */ /****************************************************************/ - silk_PLC_glue_frames(psDec, pOut, L); + silk_PLC_glue_frames( psDec, pOut, L ); /* Update some decoder state variables */ psDec->lagPrev = psDecCtrl->pitchL[ psDec->nb_subfr - 1 ]; diff --git a/src/libopus/silk/decode_indices.c b/src/libopus/silk/decode_indices.c index 957cb8d..227235c 100644 --- a/src/libopus/silk/decode_indices.c +++ b/src/libopus/silk/decode_indices.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -38,7 +38,8 @@ void silk_decode_indices( opus_int FrameIndex, /* I Frame number */ opus_int decode_LBRR, /* I Flag indicating LBRR data is being decoded */ opus_int condCoding /* I The type of conditional coding to use */ -) { +) +{ opus_int i, k, Ix; opus_int decode_absolute_lagIndex, delta_lagIndex; opus_int16 ec_ix[ MAX_LPC_ORDER ]; @@ -47,95 +48,96 @@ void silk_decode_indices( /*******************************************/ /* Decode signal type and quantizer offset */ /*******************************************/ - if (decode_LBRR || psDec->VAD_flags[ FrameIndex ]) { - Ix = ec_dec_icdf(psRangeDec, silk_type_offset_VAD_iCDF, 8) + 2; + if( decode_LBRR || psDec->VAD_flags[ FrameIndex ] ) { + Ix = ec_dec_icdf( psRangeDec, silk_type_offset_VAD_iCDF, 8 ) + 2; } else { - Ix = ec_dec_icdf(psRangeDec, silk_type_offset_no_VAD_iCDF, 8); + Ix = ec_dec_icdf( psRangeDec, silk_type_offset_no_VAD_iCDF, 8 ); } - psDec->indices.signalType = (opus_int8)silk_RSHIFT(Ix, 1); - psDec->indices.quantOffsetType = (opus_int8)(Ix & 1); + psDec->indices.signalType = (opus_int8)silk_RSHIFT( Ix, 1 ); + psDec->indices.quantOffsetType = (opus_int8)( Ix & 1 ); /****************/ /* Decode gains */ /****************/ /* First subframe */ - if (condCoding == CODE_CONDITIONALLY) { + if( condCoding == CODE_CONDITIONALLY ) { /* Conditional coding */ - psDec->indices.GainsIndices[ 0 ] = (opus_int8)ec_dec_icdf(psRangeDec, silk_delta_gain_iCDF, 8); + psDec->indices.GainsIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 ); } else { /* Independent coding, in two stages: MSB bits followed by 3 LSBs */ - psDec->indices.GainsIndices[ 0 ] = (opus_int8)silk_LSHIFT(ec_dec_icdf(psRangeDec, silk_gain_iCDF[ psDec->indices.signalType ], 8), 3); - psDec->indices.GainsIndices[ 0 ] += (opus_int8)ec_dec_icdf(psRangeDec, silk_uniform8_iCDF, 8); + psDec->indices.GainsIndices[ 0 ] = (opus_int8)silk_LSHIFT( ec_dec_icdf( psRangeDec, silk_gain_iCDF[ psDec->indices.signalType ], 8 ), 3 ); + psDec->indices.GainsIndices[ 0 ] += (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform8_iCDF, 8 ); } /* Remaining subframes */ - for (i = 1; i < psDec->nb_subfr; i++) { - psDec->indices.GainsIndices[ i ] = (opus_int8)ec_dec_icdf(psRangeDec, silk_delta_gain_iCDF, 8); + for( i = 1; i < psDec->nb_subfr; i++ ) { + psDec->indices.GainsIndices[ i ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_delta_gain_iCDF, 8 ); } /**********************/ /* Decode LSF Indices */ /**********************/ - psDec->indices.NLSFIndices[ 0 ] = (opus_int8)ec_dec_icdf(psRangeDec, &psDec->psNLSF_CB->CB1_iCDF[(psDec->indices.signalType >> 1) * psDec->psNLSF_CB->nVectors ], 8); - silk_NLSF_unpack(ec_ix, pred_Q8, psDec->psNLSF_CB, psDec->indices.NLSFIndices[ 0 ]); - celt_assert(psDec->psNLSF_CB->order == psDec->LPC_order); - for (i = 0; i < psDec->psNLSF_CB->order; i++) { - Ix = ec_dec_icdf(psRangeDec, &psDec->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8); - if (Ix == 0) { - Ix -= ec_dec_icdf(psRangeDec, silk_NLSF_EXT_iCDF, 8); - } else if (Ix == 2 * NLSF_QUANT_MAX_AMPLITUDE) { - Ix += ec_dec_icdf(psRangeDec, silk_NLSF_EXT_iCDF, 8); + psDec->indices.NLSFIndices[ 0 ] = (opus_int8)ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->CB1_iCDF[ ( psDec->indices.signalType >> 1 ) * psDec->psNLSF_CB->nVectors ], 8 ); + silk_NLSF_unpack( ec_ix, pred_Q8, psDec->psNLSF_CB, psDec->indices.NLSFIndices[ 0 ] ); + celt_assert( psDec->psNLSF_CB->order == psDec->LPC_order ); + for( i = 0; i < psDec->psNLSF_CB->order; i++ ) { + Ix = ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 ); + if( Ix == 0 ) { + Ix -= ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 ); + } else if( Ix == 2 * NLSF_QUANT_MAX_AMPLITUDE ) { + Ix += ec_dec_icdf( psRangeDec, silk_NLSF_EXT_iCDF, 8 ); } - psDec->indices.NLSFIndices[ i + 1 ] = (opus_int8)(Ix - NLSF_QUANT_MAX_AMPLITUDE); + psDec->indices.NLSFIndices[ i+1 ] = (opus_int8)( Ix - NLSF_QUANT_MAX_AMPLITUDE ); } /* Decode LSF interpolation factor */ - if (psDec->nb_subfr == MAX_NB_SUBFR) { - psDec->indices.NLSFInterpCoef_Q2 = (opus_int8)ec_dec_icdf(psRangeDec, silk_NLSF_interpolation_factor_iCDF, 8); + if( psDec->nb_subfr == MAX_NB_SUBFR ) { + psDec->indices.NLSFInterpCoef_Q2 = (opus_int8)ec_dec_icdf( psRangeDec, silk_NLSF_interpolation_factor_iCDF, 8 ); } else { psDec->indices.NLSFInterpCoef_Q2 = 4; } - if (psDec->indices.signalType == TYPE_VOICED) { + if( psDec->indices.signalType == TYPE_VOICED ) + { /*********************/ /* Decode pitch lags */ /*********************/ /* Get lag index */ decode_absolute_lagIndex = 1; - if (condCoding == CODE_CONDITIONALLY && psDec->ec_prevSignalType == TYPE_VOICED) { + if( condCoding == CODE_CONDITIONALLY && psDec->ec_prevSignalType == TYPE_VOICED ) { /* Decode Delta index */ - delta_lagIndex = (opus_int16)ec_dec_icdf(psRangeDec, silk_pitch_delta_iCDF, 8); - if (delta_lagIndex > 0) { + delta_lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_delta_iCDF, 8 ); + if( delta_lagIndex > 0 ) { delta_lagIndex = delta_lagIndex - 9; - psDec->indices.lagIndex = (opus_int16)(psDec->ec_prevLagIndex + delta_lagIndex); + psDec->indices.lagIndex = (opus_int16)( psDec->ec_prevLagIndex + delta_lagIndex ); decode_absolute_lagIndex = 0; } } - if (decode_absolute_lagIndex) { + if( decode_absolute_lagIndex ) { /* Absolute decoding */ - psDec->indices.lagIndex = (opus_int16)ec_dec_icdf(psRangeDec, silk_pitch_lag_iCDF, 8) * silk_RSHIFT(psDec->fs_kHz, 1); - psDec->indices.lagIndex += (opus_int16)ec_dec_icdf(psRangeDec, psDec->pitch_lag_low_bits_iCDF, 8); + psDec->indices.lagIndex = (opus_int16)ec_dec_icdf( psRangeDec, silk_pitch_lag_iCDF, 8 ) * silk_RSHIFT( psDec->fs_kHz, 1 ); + psDec->indices.lagIndex += (opus_int16)ec_dec_icdf( psRangeDec, psDec->pitch_lag_low_bits_iCDF, 8 ); } psDec->ec_prevLagIndex = psDec->indices.lagIndex; /* Get countour index */ - psDec->indices.contourIndex = (opus_int8)ec_dec_icdf(psRangeDec, psDec->pitch_contour_iCDF, 8); + psDec->indices.contourIndex = (opus_int8)ec_dec_icdf( psRangeDec, psDec->pitch_contour_iCDF, 8 ); /********************/ /* Decode LTP gains */ /********************/ /* Decode PERIndex value */ - psDec->indices.PERIndex = (opus_int8)ec_dec_icdf(psRangeDec, silk_LTP_per_index_iCDF, 8); + psDec->indices.PERIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_per_index_iCDF, 8 ); - for (k = 0; k < psDec->nb_subfr; k++) { - psDec->indices.LTPIndex[ k ] = (opus_int8)ec_dec_icdf(psRangeDec, silk_LTP_gain_iCDF_ptrs[ psDec->indices.PERIndex ], 8); + for( k = 0; k < psDec->nb_subfr; k++ ) { + psDec->indices.LTPIndex[ k ] = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTP_gain_iCDF_ptrs[ psDec->indices.PERIndex ], 8 ); } /**********************/ /* Decode LTP scaling */ /**********************/ - if (condCoding == CODE_INDEPENDENTLY) { - psDec->indices.LTP_scaleIndex = (opus_int8)ec_dec_icdf(psRangeDec, silk_LTPscale_iCDF, 8); + if( condCoding == CODE_INDEPENDENTLY ) { + psDec->indices.LTP_scaleIndex = (opus_int8)ec_dec_icdf( psRangeDec, silk_LTPscale_iCDF, 8 ); } else { psDec->indices.LTP_scaleIndex = 0; } @@ -145,5 +147,5 @@ void silk_decode_indices( /***************/ /* Decode seed */ /***************/ - psDec->indices.Seed = (opus_int8)ec_dec_icdf(psRangeDec, silk_uniform4_iCDF, 8); + psDec->indices.Seed = (opus_int8)ec_dec_icdf( psRangeDec, silk_uniform4_iCDF, 8 ); } diff --git a/src/libopus/silk/decode_parameters.c b/src/libopus/silk/decode_parameters.c index ca59c33..80f1497 100644 --- a/src/libopus/silk/decode_parameters.c +++ b/src/libopus/silk/decode_parameters.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -36,67 +36,68 @@ void silk_decode_parameters( silk_decoder_state *psDec, /* I/O State */ silk_decoder_control *psDecCtrl, /* I/O Decoder control */ opus_int condCoding /* I The type of conditional coding to use */ -) { +) +{ opus_int i, k, Ix; opus_int16 pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ]; const opus_int8 *cbk_ptr_Q7; /* Dequant Gains */ - silk_gains_dequant(psDecCtrl->Gains_Q16, psDec->indices.GainsIndices, - &psDec->LastGainIndex, condCoding == CODE_CONDITIONALLY, psDec->nb_subfr); + silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->indices.GainsIndices, + &psDec->LastGainIndex, condCoding == CODE_CONDITIONALLY, psDec->nb_subfr ); /****************/ /* Decode NLSFs */ /****************/ - silk_NLSF_decode(pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB); + silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB ); /* Convert NLSF parameters to AR prediction filter coefficients */ - silk_NLSF2A(psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order, psDec->arch); + silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order, psDec->arch ); /* If just reset, e.g., because internal Fs changed, do not allow interpolation */ /* improves the case of packet loss in the first frame after a switch */ - if (psDec->first_frame_after_reset == 1) { + if( psDec->first_frame_after_reset == 1 ) { psDec->indices.NLSFInterpCoef_Q2 = 4; } - if (psDec->indices.NLSFInterpCoef_Q2 < 4) { + if( psDec->indices.NLSFInterpCoef_Q2 < 4 ) { /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */ /* the previous NLSF1, and the current NLSF1 */ - for (i = 0; i < psDec->LPC_order; i++) { - pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + silk_RSHIFT(silk_MUL(psDec->indices.NLSFInterpCoef_Q2, - pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ]), 2); + for( i = 0; i < psDec->LPC_order; i++ ) { + pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + silk_RSHIFT( silk_MUL( psDec->indices.NLSFInterpCoef_Q2, + pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ), 2 ); } /* Convert NLSF parameters to AR prediction filter coefficients */ - silk_NLSF2A(psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order, psDec->arch); + silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order, psDec->arch ); } else { /* Copy LPC coefficients for first half from second half */ - silk_memcpy(psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof(opus_int16)); + silk_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) ); } - silk_memcpy(psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof(opus_int16)); + silk_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( opus_int16 ) ); /* After a packet loss do BWE of LPC coefs */ - if (psDec->lossCnt) { - silk_bwexpander(psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16); - silk_bwexpander(psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16); + if( psDec->lossCnt ) { + silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 ); + silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 ); } - if (psDec->indices.signalType == TYPE_VOICED) { + if( psDec->indices.signalType == TYPE_VOICED ) { /*********************/ /* Decode pitch lags */ /*********************/ /* Decode pitch values */ - silk_decode_pitch(psDec->indices.lagIndex, psDec->indices.contourIndex, psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr); + silk_decode_pitch( psDec->indices.lagIndex, psDec->indices.contourIndex, psDecCtrl->pitchL, psDec->fs_kHz, psDec->nb_subfr ); /* Decode Codebook Index */ cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ psDec->indices.PERIndex ]; /* set pointer to start of codebook */ - for (k = 0; k < psDec->nb_subfr; k++) { + for( k = 0; k < psDec->nb_subfr; k++ ) { Ix = psDec->indices.LTPIndex[ k ]; - for (i = 0; i < LTP_ORDER; i++) { - psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = silk_LSHIFT(cbk_ptr_Q7[ Ix * LTP_ORDER + i ], 7); + for( i = 0; i < LTP_ORDER; i++ ) { + psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = silk_LSHIFT( cbk_ptr_Q7[ Ix * LTP_ORDER + i ], 7 ); } } @@ -106,8 +107,8 @@ void silk_decode_parameters( Ix = psDec->indices.LTP_scaleIndex; psDecCtrl->LTP_scale_Q14 = silk_LTPScales_table_Q14[ Ix ]; } else { - silk_memset(psDecCtrl->pitchL, 0, psDec->nb_subfr * sizeof(opus_int)); - silk_memset(psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * psDec->nb_subfr * sizeof(opus_int16)); + silk_memset( psDecCtrl->pitchL, 0, psDec->nb_subfr * sizeof( opus_int ) ); + silk_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * psDec->nb_subfr * sizeof( opus_int16 ) ); psDec->indices.PERIndex = 0; psDecCtrl->LTP_scale_Q14 = 0; } diff --git a/src/libopus/silk/decode_pitch.c b/src/libopus/silk/decode_pitch.c index 1d64828..49f5905 100644 --- a/src/libopus/silk/decode_pitch.c +++ b/src/libopus/silk/decode_pitch.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif /*********************************************************** - Pitch analyser function +* Pitch analyser function ********************************************************** */ #include "SigProc_FIX.h" #include "pitch_est_defines.h" @@ -41,36 +41,37 @@ void silk_decode_pitch( opus_int pitch_lags[], /* O 4 pitch values */ const opus_int Fs_kHz, /* I sampling frequency (kHz) */ const opus_int nb_subfr /* I number of sub frames */ -) { +) +{ opus_int lag, k, min_lag, max_lag, cbk_size; const opus_int8 *Lag_CB_ptr; - if (Fs_kHz == 8) { - if (nb_subfr == PE_MAX_NB_SUBFR) { + if( Fs_kHz == 8 ) { + if( nb_subfr == PE_MAX_NB_SUBFR ) { Lag_CB_ptr = &silk_CB_lags_stage2[ 0 ][ 0 ]; cbk_size = PE_NB_CBKS_STAGE2_EXT; } else { - celt_assert(nb_subfr == PE_MAX_NB_SUBFR >> 1); + celt_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1 ); Lag_CB_ptr = &silk_CB_lags_stage2_10_ms[ 0 ][ 0 ]; cbk_size = PE_NB_CBKS_STAGE2_10MS; } } else { - if (nb_subfr == PE_MAX_NB_SUBFR) { + if( nb_subfr == PE_MAX_NB_SUBFR ) { Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; cbk_size = PE_NB_CBKS_STAGE3_MAX; } else { - celt_assert(nb_subfr == PE_MAX_NB_SUBFR >> 1); + celt_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1 ); Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; cbk_size = PE_NB_CBKS_STAGE3_10MS; } } - min_lag = silk_SMULBB(PE_MIN_LAG_MS, Fs_kHz); - max_lag = silk_SMULBB(PE_MAX_LAG_MS, Fs_kHz); + min_lag = silk_SMULBB( PE_MIN_LAG_MS, Fs_kHz ); + max_lag = silk_SMULBB( PE_MAX_LAG_MS, Fs_kHz ); lag = min_lag + lagIndex; - for (k = 0; k < nb_subfr; k++) { - pitch_lags[ k ] = lag + matrix_ptr(Lag_CB_ptr, k, contourIndex, cbk_size); - pitch_lags[ k ] = silk_LIMIT(pitch_lags[ k ], min_lag, max_lag); + for( k = 0; k < nb_subfr; k++ ) { + pitch_lags[ k ] = lag + matrix_ptr( Lag_CB_ptr, k, contourIndex, cbk_size ); + pitch_lags[ k ] = silk_LIMIT( pitch_lags[ k ], min_lag, max_lag ); } } diff --git a/src/libopus/silk/decode_pulses.c b/src/libopus/silk/decode_pulses.c index 2760e26..d279820 100644 --- a/src/libopus/silk/decode_pulses.c +++ b/src/libopus/silk/decode_pulses.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -40,7 +40,8 @@ void silk_decode_pulses( const opus_int signalType, /* I Sigtype */ const opus_int quantOffsetType, /* I quantOffsetType */ const opus_int frame_length /* I Frame length */ -) { +) +{ opus_int i, j, k, iter, abs_q, nLS, RateLevelIndex; opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ]; opus_int16 *pulses_ptr; @@ -49,13 +50,13 @@ void silk_decode_pulses( /*********************/ /* Decode rate level */ /*********************/ - RateLevelIndex = ec_dec_icdf(psRangeDec, silk_rate_levels_iCDF[ signalType >> 1 ], 8); + RateLevelIndex = ec_dec_icdf( psRangeDec, silk_rate_levels_iCDF[ signalType >> 1 ], 8 ); /* Calculate number of shell blocks */ - silk_assert(1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH); - iter = silk_RSHIFT(frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH); - if (iter * SHELL_CODEC_FRAME_LENGTH < frame_length) { - celt_assert(frame_length == 12 * 10); /* Make sure only happens for 10 ms @ 12 kHz */ + silk_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH ); + iter = silk_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH ); + if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ) { + celt_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10 ms @ 12 kHz */ iter++; } @@ -63,42 +64,42 @@ void silk_decode_pulses( /* Sum-Weighted-Pulses Decoding */ /***************************************************/ cdf_ptr = silk_pulses_per_block_iCDF[ RateLevelIndex ]; - for (i = 0; i < iter; i++) { + for( i = 0; i < iter; i++ ) { nLshifts[ i ] = 0; - sum_pulses[ i ] = ec_dec_icdf(psRangeDec, cdf_ptr, 8); + sum_pulses[ i ] = ec_dec_icdf( psRangeDec, cdf_ptr, 8 ); /* LSB indication */ - while (sum_pulses[ i ] == SILK_MAX_PULSES + 1) { + while( sum_pulses[ i ] == SILK_MAX_PULSES + 1 ) { nLshifts[ i ]++; /* When we've already got 10 LSBs, we shift the table to not allow (SILK_MAX_PULSES + 1) */ - sum_pulses[ i ] = ec_dec_icdf(psRangeDec, - silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1] + (nLshifts[ i ] == 10), 8); + sum_pulses[ i ] = ec_dec_icdf( psRangeDec, + silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1] + ( nLshifts[ i ] == 10 ), 8 ); } } /***************************************************/ /* Shell decoding */ /***************************************************/ - for (i = 0; i < iter; i++) { - if (sum_pulses[ i ] > 0) { - silk_shell_decoder(&pulses[ silk_SMULBB(i, SHELL_CODEC_FRAME_LENGTH) ], psRangeDec, sum_pulses[ i ]); + for( i = 0; i < iter; i++ ) { + if( sum_pulses[ i ] > 0 ) { + silk_shell_decoder( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] ); } else { - silk_memset(&pulses[ silk_SMULBB(i, SHELL_CODEC_FRAME_LENGTH) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof(pulses[0])); + silk_memset( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( pulses[0] ) ); } } /***************************************************/ /* LSB Decoding */ /***************************************************/ - for (i = 0; i < iter; i++) { - if (nLshifts[ i ] > 0) { + for( i = 0; i < iter; i++ ) { + if( nLshifts[ i ] > 0 ) { nLS = nLshifts[ i ]; - pulses_ptr = &pulses[ silk_SMULBB(i, SHELL_CODEC_FRAME_LENGTH) ]; - for (k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++) { + pulses_ptr = &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ]; + for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { abs_q = pulses_ptr[ k ]; - for (j = 0; j < nLS; j++) { - abs_q = silk_LSHIFT(abs_q, 1); - abs_q += ec_dec_icdf(psRangeDec, silk_lsb_iCDF, 8); + for( j = 0; j < nLS; j++ ) { + abs_q = silk_LSHIFT( abs_q, 1 ); + abs_q += ec_dec_icdf( psRangeDec, silk_lsb_iCDF, 8 ); } pulses_ptr[ k ] = abs_q; } @@ -110,5 +111,5 @@ void silk_decode_pulses( /****************************************/ /* Decode and add signs to pulse signal */ /****************************************/ - silk_decode_signs(psRangeDec, pulses, frame_length, signalType, quantOffsetType, sum_pulses); + silk_decode_signs( psRangeDec, pulses, frame_length, signalType, quantOffsetType, sum_pulses ); } diff --git a/src/libopus/silk/decoder_set_fs.c b/src/libopus/silk/decoder_set_fs.c index cc08cad..3a6a47c 100644 --- a/src/libopus/silk/decoder_set_fs.c +++ b/src/libopus/silk/decoder_set_fs.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -36,63 +36,64 @@ opus_int silk_decoder_set_fs( silk_decoder_state *psDec, /* I/O Decoder state pointer */ opus_int fs_kHz, /* I Sampling frequency (kHz) */ opus_int32 fs_API_Hz /* I API Sampling frequency (Hz) */ -) { +) +{ opus_int frame_length, ret = 0; - celt_assert(fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16); - celt_assert(psDec->nb_subfr == MAX_NB_SUBFR || psDec->nb_subfr == MAX_NB_SUBFR / 2); + celt_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 ); + celt_assert( psDec->nb_subfr == MAX_NB_SUBFR || psDec->nb_subfr == MAX_NB_SUBFR/2 ); /* New (sub)frame length */ - psDec->subfr_length = silk_SMULBB(SUB_FRAME_LENGTH_MS, fs_kHz); - frame_length = silk_SMULBB(psDec->nb_subfr, psDec->subfr_length); + psDec->subfr_length = silk_SMULBB( SUB_FRAME_LENGTH_MS, fs_kHz ); + frame_length = silk_SMULBB( psDec->nb_subfr, psDec->subfr_length ); /* Initialize resampler when switching internal or external sampling frequency */ - if (psDec->fs_kHz != fs_kHz || psDec->fs_API_hz != fs_API_Hz) { + if( psDec->fs_kHz != fs_kHz || psDec->fs_API_hz != fs_API_Hz ) { /* Initialize the resampler for dec_API.c preparing resampling from fs_kHz to API_fs_Hz */ - ret += silk_resampler_init(&psDec->resampler_state, silk_SMULBB(fs_kHz, 1000), fs_API_Hz, 0); + ret += silk_resampler_init( &psDec->resampler_state, silk_SMULBB( fs_kHz, 1000 ), fs_API_Hz, 0 ); psDec->fs_API_hz = fs_API_Hz; } - if (psDec->fs_kHz != fs_kHz || frame_length != psDec->frame_length) { - if (fs_kHz == 8) { - if (psDec->nb_subfr == MAX_NB_SUBFR) { + if( psDec->fs_kHz != fs_kHz || frame_length != psDec->frame_length ) { + if( fs_kHz == 8 ) { + if( psDec->nb_subfr == MAX_NB_SUBFR ) { psDec->pitch_contour_iCDF = silk_pitch_contour_NB_iCDF; } else { psDec->pitch_contour_iCDF = silk_pitch_contour_10_ms_NB_iCDF; } } else { - if (psDec->nb_subfr == MAX_NB_SUBFR) { + if( psDec->nb_subfr == MAX_NB_SUBFR ) { psDec->pitch_contour_iCDF = silk_pitch_contour_iCDF; } else { psDec->pitch_contour_iCDF = silk_pitch_contour_10_ms_iCDF; } } - if (psDec->fs_kHz != fs_kHz) { - psDec->ltp_mem_length = silk_SMULBB(LTP_MEM_LENGTH_MS, fs_kHz); - if (fs_kHz == 8 || fs_kHz == 12) { + if( psDec->fs_kHz != fs_kHz ) { + psDec->ltp_mem_length = silk_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); + if( fs_kHz == 8 || fs_kHz == 12 ) { psDec->LPC_order = MIN_LPC_ORDER; psDec->psNLSF_CB = &silk_NLSF_CB_NB_MB; } else { psDec->LPC_order = MAX_LPC_ORDER; psDec->psNLSF_CB = &silk_NLSF_CB_WB; } - if (fs_kHz == 16) { + if( fs_kHz == 16 ) { psDec->pitch_lag_low_bits_iCDF = silk_uniform8_iCDF; - } else if (fs_kHz == 12) { + } else if( fs_kHz == 12 ) { psDec->pitch_lag_low_bits_iCDF = silk_uniform6_iCDF; - } else if (fs_kHz == 8) { + } else if( fs_kHz == 8 ) { psDec->pitch_lag_low_bits_iCDF = silk_uniform4_iCDF; } else { /* unsupported sampling rate */ - celt_assert(0); + celt_assert( 0 ); } psDec->first_frame_after_reset = 1; psDec->lagPrev = 100; psDec->LastGainIndex = 10; psDec->prevSignalType = TYPE_NO_VOICE_ACTIVITY; - silk_memset(psDec->outBuf, 0, sizeof(psDec->outBuf)); - silk_memset(psDec->sLPC_Q14_buf, 0, sizeof(psDec->sLPC_Q14_buf)); + silk_memset( psDec->outBuf, 0, sizeof(psDec->outBuf)); + silk_memset( psDec->sLPC_Q14_buf, 0, sizeof(psDec->sLPC_Q14_buf) ); } psDec->fs_kHz = fs_kHz; @@ -100,7 +101,7 @@ opus_int silk_decoder_set_fs( } /* Check that settings are valid */ - celt_assert(psDec->frame_length > 0 && psDec->frame_length <= MAX_FRAME_LENGTH); + celt_assert( psDec->frame_length > 0 && psDec->frame_length <= MAX_FRAME_LENGTH ); return ret; } diff --git a/src/libopus/silk/define.h b/src/libopus/silk/define.h index 13fcfd3..491c86f 100644 --- a/src/libopus/silk/define.h +++ b/src/libopus/silk/define.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_DEFINE_H @@ -225,6 +225,7 @@ extern "C" /* Defines for CN generation */ #define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH))-1 */ #define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */ +#define CNG_GAIN_SMTH_THRESHOLD_Q16 46396 /* -3 dB */ #define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */ #ifdef __cplusplus diff --git a/src/libopus/silk/ecintrin.h b/src/libopus/silk/ecintrin.h new file mode 100644 index 0000000..c6cc9b2 --- /dev/null +++ b/src/libopus/silk/ecintrin.h @@ -0,0 +1 @@ +#include "../celt/ecintrin.h" diff --git a/src/libopus/silk/enc_API.c b/src/libopus/silk/enc_API.c deleted file mode 100644 index 1ad1aa2..0000000 --- a/src/libopus/silk/enc_API.c +++ /dev/null @@ -1,573 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ -#if 0 - -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif -#include "define.h" -#include "API.h" -#include "control.h" -#include "typedef.h" -#include "../celt/stack_alloc.h" -#include "structs.h" -#include "tuning_parameters.h" -#ifdef FIXED_POINT -#include "fixed/main_FIX.h" -#else -#include "main_FLP.h" -#endif - -/***************************************/ -/* Read control structure from encoder */ -/***************************************/ -static opus_int silk_QueryEncoder( /* O Returns error code */ - const void *encState, /* I State */ - silk_EncControlStruct *encStatus /* O Encoder Status */ -); - -/****************************************/ -/* Encoder functions */ -/****************************************/ - -opus_int silk_Get_Encoder_Size( /* O Returns error code */ - opus_int *encSizeBytes /* O Number of bytes in SILK encoder state */ -) { - opus_int ret = SILK_NO_ERROR; - - *encSizeBytes = sizeof(silk_encoder); - - return ret; -} - -/*************************/ -/* Init or Reset encoder */ -/*************************/ -opus_int silk_InitEncoder( /* O Returns error code */ - void *encState, /* I/O State */ - int arch, /* I Run-time architecture */ - silk_EncControlStruct *encStatus /* O Encoder Status */ -) { - silk_encoder *psEnc; - opus_int n, ret = SILK_NO_ERROR; - - psEnc = (silk_encoder *)encState; - - /* Reset encoder */ - silk_memset(psEnc, 0, sizeof(silk_encoder)); - for (n = 0; n < ENCODER_NUM_CHANNELS; n++) { - if (ret += silk_init_encoder(&psEnc->state_Fxx[ n ], arch)) { - celt_assert(0); - } - } - - psEnc->nChannelsAPI = 1; - psEnc->nChannelsInternal = 1; - - /* Read control structure */ - if (ret += silk_QueryEncoder(encState, encStatus)) { - celt_assert(0); - } - - return ret; -} - -/***************************************/ -/* Read control structure from encoder */ -/***************************************/ -static opus_int silk_QueryEncoder( /* O Returns error code */ - const void *encState, /* I State */ - silk_EncControlStruct *encStatus /* O Encoder Status */ -) { - opus_int ret = SILK_NO_ERROR; - silk_encoder_state_Fxx *state_Fxx; - silk_encoder *psEnc = (silk_encoder *)encState; - - state_Fxx = psEnc->state_Fxx; - - encStatus->nChannelsAPI = psEnc->nChannelsAPI; - encStatus->nChannelsInternal = psEnc->nChannelsInternal; - encStatus->API_sampleRate = state_Fxx[ 0 ].sCmn.API_fs_Hz; - encStatus->maxInternalSampleRate = state_Fxx[ 0 ].sCmn.maxInternal_fs_Hz; - encStatus->minInternalSampleRate = state_Fxx[ 0 ].sCmn.minInternal_fs_Hz; - encStatus->desiredInternalSampleRate = state_Fxx[ 0 ].sCmn.desiredInternal_fs_Hz; - encStatus->payloadSize_ms = state_Fxx[ 0 ].sCmn.PacketSize_ms; - encStatus->bitRate = state_Fxx[ 0 ].sCmn.TargetRate_bps; - encStatus->packetLossPercentage = state_Fxx[ 0 ].sCmn.PacketLoss_perc; - encStatus->complexity = state_Fxx[ 0 ].sCmn.Complexity; - encStatus->useInBandFEC = state_Fxx[ 0 ].sCmn.useInBandFEC; - encStatus->useDTX = state_Fxx[ 0 ].sCmn.useDTX; - encStatus->useCBR = state_Fxx[ 0 ].sCmn.useCBR; - encStatus->internalSampleRate = silk_SMULBB(state_Fxx[ 0 ].sCmn.fs_kHz, 1000); - encStatus->allowBandwidthSwitch = state_Fxx[ 0 ].sCmn.allow_bandwidth_switch; - encStatus->inWBmodeWithoutVariableLP = state_Fxx[ 0 ].sCmn.fs_kHz == 16 && state_Fxx[ 0 ].sCmn.sLP.mode == 0; - - return ret; -} - - -/**************************/ -/* Encode frame with Silk */ -/**************************/ -/* Note: if prefillFlag is set, the input must contain 10 ms of audio, irrespective of what */ -/* encControl->payloadSize_ms is set to */ -opus_int silk_Encode( /* O Returns error code */ - void *encState, /* I/O State */ - silk_EncControlStruct *encControl, /* I Control status */ - const opus_int16 *samplesIn, /* I Speech sample input vector */ - opus_int nSamplesIn, /* I Number of samples in input vector */ - ec_enc *psRangeEnc, /* I/O Compressor data structure */ - opus_int32 *nBytesOut, /* I/O Number of bytes in payload (input: Max bytes) */ - const opus_int prefillFlag, /* I Flag to indicate prefilling buffers no coding */ - opus_int activity /* I Decision of Opus voice activity detector */ -) { - opus_int n, i, nBits, flags, tmp_payloadSize_ms = 0, tmp_complexity = 0, ret = 0; - opus_int nSamplesToBuffer, nSamplesToBufferMax, nBlocksOf10ms; - opus_int nSamplesFromInput = 0, nSamplesFromInputMax; - opus_int speech_act_thr_for_switch_Q8; - opus_int32 TargetRate_bps, MStargetRates_bps[ 2 ], channelRate_bps, LBRR_symbol, sum; - silk_encoder *psEnc = (silk_encoder *)encState; - VARDECL(opus_int16, buf); - opus_int transition, curr_block, tot_blocks; - SAVE_STACK; - - if (encControl->reducedDependency) { - psEnc->state_Fxx[0].sCmn.first_frame_after_reset = 1; - psEnc->state_Fxx[1].sCmn.first_frame_after_reset = 1; - } - psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded = psEnc->state_Fxx[ 1 ].sCmn.nFramesEncoded = 0; - - /* Check values in encoder control structure */ - if ((ret = check_control_input(encControl)) != 0) { - celt_assert(0); - RESTORE_STACK; - return ret; - } - - encControl->switchReady = 0; - - if (encControl->nChannelsInternal > psEnc->nChannelsInternal) { - /* Mono -> Stereo transition: init state of second channel and stereo state */ - ret += silk_init_encoder(&psEnc->state_Fxx[ 1 ], psEnc->state_Fxx[ 0 ].sCmn.arch); - silk_memset(psEnc->sStereo.pred_prev_Q13, 0, sizeof(psEnc->sStereo.pred_prev_Q13)); - silk_memset(psEnc->sStereo.sSide, 0, sizeof(psEnc->sStereo.sSide)); - psEnc->sStereo.mid_side_amp_Q0[ 0 ] = 0; - psEnc->sStereo.mid_side_amp_Q0[ 1 ] = 1; - psEnc->sStereo.mid_side_amp_Q0[ 2 ] = 0; - psEnc->sStereo.mid_side_amp_Q0[ 3 ] = 1; - psEnc->sStereo.width_prev_Q14 = 0; - psEnc->sStereo.smth_width_Q14 = SILK_FIX_CONST(1, 14); - if (psEnc->nChannelsAPI == 2) { - silk_memcpy(&psEnc->state_Fxx[ 1 ].sCmn.resampler_state, &psEnc->state_Fxx[ 0 ].sCmn.resampler_state, sizeof(silk_resampler_state_struct)); - silk_memcpy(&psEnc->state_Fxx[ 1 ].sCmn.In_HP_State, &psEnc->state_Fxx[ 0 ].sCmn.In_HP_State, sizeof(psEnc->state_Fxx[ 1 ].sCmn.In_HP_State)); - } - } - - transition = (encControl->payloadSize_ms != psEnc->state_Fxx[ 0 ].sCmn.PacketSize_ms) || (psEnc->nChannelsInternal != encControl->nChannelsInternal); - - psEnc->nChannelsAPI = encControl->nChannelsAPI; - psEnc->nChannelsInternal = encControl->nChannelsInternal; - - nBlocksOf10ms = silk_DIV32(100 * nSamplesIn, encControl->API_sampleRate); - tot_blocks = (nBlocksOf10ms > 1) ? nBlocksOf10ms >> 1 : 1; - curr_block = 0; - if (prefillFlag) { - silk_LP_state save_LP; - /* Only accept input length of 10 ms */ - if (nBlocksOf10ms != 1) { - celt_assert(0); - RESTORE_STACK; - return SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES; - } - if (prefillFlag == 2) { - save_LP = psEnc->state_Fxx[ 0 ].sCmn.sLP; - /* Save the sampling rate so the bandwidth switching code can keep handling transitions. */ - save_LP.saved_fs_kHz = psEnc->state_Fxx[ 0 ].sCmn.fs_kHz; - } - /* Reset Encoder */ - for (n = 0; n < encControl->nChannelsInternal; n++) { - ret = silk_init_encoder(&psEnc->state_Fxx[ n ], psEnc->state_Fxx[ n ].sCmn.arch); - /* Restore the variable LP state. */ - if (prefillFlag == 2) { - psEnc->state_Fxx[ n ].sCmn.sLP = save_LP; - } - celt_assert(!ret); - } - tmp_payloadSize_ms = encControl->payloadSize_ms; - encControl->payloadSize_ms = 10; - tmp_complexity = encControl->complexity; - encControl->complexity = 0; - for (n = 0; n < encControl->nChannelsInternal; n++) { - psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0; - psEnc->state_Fxx[ n ].sCmn.prefillFlag = 1; - } - } else { - /* Only accept input lengths that are a multiple of 10 ms */ - if (nBlocksOf10ms * encControl->API_sampleRate != 100 * nSamplesIn || nSamplesIn < 0) { - celt_assert(0); - RESTORE_STACK; - return SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES; - } - /* Make sure no more than one packet can be produced */ - if (1000 * (opus_int32)nSamplesIn > encControl->payloadSize_ms * encControl->API_sampleRate) { - celt_assert(0); - RESTORE_STACK; - return SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES; - } - } - - for (n = 0; n < encControl->nChannelsInternal; n++) { - /* Force the side channel to the same rate as the mid */ - opus_int force_fs_kHz = (n == 1) ? psEnc->state_Fxx[0].sCmn.fs_kHz : 0; - if ((ret = silk_control_encoder(&psEnc->state_Fxx[ n ], encControl, psEnc->allowBandwidthSwitch, n, force_fs_kHz)) != 0) { - silk_assert(0); - RESTORE_STACK; - return ret; - } - if (psEnc->state_Fxx[n].sCmn.first_frame_after_reset || transition) { - for (i = 0; i < psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket; i++) { - psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i ] = 0; - } - } - psEnc->state_Fxx[ n ].sCmn.inDTX = psEnc->state_Fxx[ n ].sCmn.useDTX; - } - celt_assert(encControl->nChannelsInternal == 1 || psEnc->state_Fxx[ 0 ].sCmn.fs_kHz == psEnc->state_Fxx[ 1 ].sCmn.fs_kHz); - - /* Input buffering/resampling and encoding */ - nSamplesToBufferMax = - 10 * nBlocksOf10ms * psEnc->state_Fxx[ 0 ].sCmn.fs_kHz; - nSamplesFromInputMax = - silk_DIV32_16(nSamplesToBufferMax * - psEnc->state_Fxx[ 0 ].sCmn.API_fs_Hz, - psEnc->state_Fxx[ 0 ].sCmn.fs_kHz * 1000); - ALLOC(buf, nSamplesFromInputMax, opus_int16); - while (1) { - nSamplesToBuffer = psEnc->state_Fxx[ 0 ].sCmn.frame_length - psEnc->state_Fxx[ 0 ].sCmn.inputBufIx; - nSamplesToBuffer = silk_min(nSamplesToBuffer, nSamplesToBufferMax); - nSamplesFromInput = silk_DIV32_16(nSamplesToBuffer * psEnc->state_Fxx[ 0 ].sCmn.API_fs_Hz, psEnc->state_Fxx[ 0 ].sCmn.fs_kHz * 1000); - /* Resample and write to buffer */ - if (encControl->nChannelsAPI == 2 && encControl->nChannelsInternal == 2) { - opus_int id = psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded; - for (n = 0; n < nSamplesFromInput; n++) { - buf[ n ] = samplesIn[ 2 * n ]; - } - /* Making sure to start both resamplers from the same state when switching from mono to stereo */ - if (psEnc->nPrevChannelsInternal == 1 && id == 0) { - silk_memcpy(&psEnc->state_Fxx[ 1 ].sCmn.resampler_state, &psEnc->state_Fxx[ 0 ].sCmn.resampler_state, sizeof(psEnc->state_Fxx[ 1 ].sCmn.resampler_state)); - } - - ret += silk_resampler(&psEnc->state_Fxx[ 0 ].sCmn.resampler_state, - &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx + 2 ], buf, nSamplesFromInput); - psEnc->state_Fxx[ 0 ].sCmn.inputBufIx += nSamplesToBuffer; - - nSamplesToBuffer = psEnc->state_Fxx[ 1 ].sCmn.frame_length - psEnc->state_Fxx[ 1 ].sCmn.inputBufIx; - nSamplesToBuffer = silk_min(nSamplesToBuffer, 10 * nBlocksOf10ms * psEnc->state_Fxx[ 1 ].sCmn.fs_kHz); - for (n = 0; n < nSamplesFromInput; n++) { - buf[ n ] = samplesIn[ 2 * n + 1 ]; - } - ret += silk_resampler(&psEnc->state_Fxx[ 1 ].sCmn.resampler_state, - &psEnc->state_Fxx[ 1 ].sCmn.inputBuf[ psEnc->state_Fxx[ 1 ].sCmn.inputBufIx + 2 ], buf, nSamplesFromInput); - - psEnc->state_Fxx[ 1 ].sCmn.inputBufIx += nSamplesToBuffer; - } else if (encControl->nChannelsAPI == 2 && encControl->nChannelsInternal == 1) { - /* Combine left and right channels before resampling */ - for (n = 0; n < nSamplesFromInput; n++) { - sum = samplesIn[ 2 * n ] + samplesIn[ 2 * n + 1 ]; - buf[ n ] = (opus_int16)silk_RSHIFT_ROUND(sum, 1); - } - ret += silk_resampler(&psEnc->state_Fxx[ 0 ].sCmn.resampler_state, - &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx + 2 ], buf, nSamplesFromInput); - /* On the first mono frame, average the results for the two resampler states */ - if (psEnc->nPrevChannelsInternal == 2 && psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded == 0) { - ret += silk_resampler(&psEnc->state_Fxx[ 1 ].sCmn.resampler_state, - &psEnc->state_Fxx[ 1 ].sCmn.inputBuf[ psEnc->state_Fxx[ 1 ].sCmn.inputBufIx + 2 ], buf, nSamplesFromInput); - for (n = 0; n < psEnc->state_Fxx[ 0 ].sCmn.frame_length; n++) { - psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx + n + 2 ] = - silk_RSHIFT(psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx + n + 2 ] - + psEnc->state_Fxx[ 1 ].sCmn.inputBuf[ psEnc->state_Fxx[ 1 ].sCmn.inputBufIx + n + 2 ], 1); - } - } - psEnc->state_Fxx[ 0 ].sCmn.inputBufIx += nSamplesToBuffer; - } else { - celt_assert(encControl->nChannelsAPI == 1 && encControl->nChannelsInternal == 1); - silk_memcpy(buf, samplesIn, nSamplesFromInput * sizeof(opus_int16)); - ret += silk_resampler(&psEnc->state_Fxx[ 0 ].sCmn.resampler_state, - &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx + 2 ], buf, nSamplesFromInput); - psEnc->state_Fxx[ 0 ].sCmn.inputBufIx += nSamplesToBuffer; - } - - samplesIn += nSamplesFromInput * encControl->nChannelsAPI; - nSamplesIn -= nSamplesFromInput; - - /* Default */ - psEnc->allowBandwidthSwitch = 0; - - /* Silk encoder */ - if (psEnc->state_Fxx[ 0 ].sCmn.inputBufIx >= psEnc->state_Fxx[ 0 ].sCmn.frame_length) { - /* Enough data in input buffer, so encode */ - celt_assert(psEnc->state_Fxx[ 0 ].sCmn.inputBufIx == psEnc->state_Fxx[ 0 ].sCmn.frame_length); - celt_assert(encControl->nChannelsInternal == 1 || psEnc->state_Fxx[ 1 ].sCmn.inputBufIx == psEnc->state_Fxx[ 1 ].sCmn.frame_length); - - /* Deal with LBRR data */ - if (psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded == 0 && !prefillFlag) { - /* Create space at start of payload for VAD and FEC flags */ - opus_uint8 iCDF[ 2 ] = { 0, 0 }; - iCDF[ 0 ] = 256 - silk_RSHIFT(256, (psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket + 1) * encControl->nChannelsInternal); - ec_enc_icdf(psRangeEnc, 0, iCDF, 8); - - /* Encode any LBRR data from previous packet */ - /* Encode LBRR flags */ - for (n = 0; n < encControl->nChannelsInternal; n++) { - LBRR_symbol = 0; - for (i = 0; i < psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket; i++) { - LBRR_symbol |= silk_LSHIFT(psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i ], i); - } - psEnc->state_Fxx[ n ].sCmn.LBRR_flag = LBRR_symbol > 0 ? 1 : 0; - if (LBRR_symbol && psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket > 1) { - ec_enc_icdf(psRangeEnc, LBRR_symbol - 1, silk_LBRR_flags_iCDF_ptr[ psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket - 2 ], 8); - } - } - - /* Code LBRR indices and excitation signals */ - for (i = 0; i < psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket; i++) { - for (n = 0; n < encControl->nChannelsInternal; n++) { - if (psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i ]) { - opus_int condCoding; - - if (encControl->nChannelsInternal == 2 && n == 0) { - silk_stereo_encode_pred(psRangeEnc, psEnc->sStereo.predIx[ i ]); - /* For LBRR data there's no need to code the mid-only flag if the side-channel LBRR flag is set */ - if (psEnc->state_Fxx[ 1 ].sCmn.LBRR_flags[ i ] == 0) { - silk_stereo_encode_mid_only(psRangeEnc, psEnc->sStereo.mid_only_flags[ i ]); - } - } - /* Use conditional coding if previous frame available */ - if (i > 0 && psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i - 1 ]) { - condCoding = CODE_CONDITIONALLY; - } else { - condCoding = CODE_INDEPENDENTLY; - } - silk_encode_indices(&psEnc->state_Fxx[ n ].sCmn, psRangeEnc, i, 1, condCoding); - silk_encode_pulses(psRangeEnc, psEnc->state_Fxx[ n ].sCmn.indices_LBRR[i].signalType, psEnc->state_Fxx[ n ].sCmn.indices_LBRR[i].quantOffsetType, - psEnc->state_Fxx[ n ].sCmn.pulses_LBRR[ i ], psEnc->state_Fxx[ n ].sCmn.frame_length); - } - } - } - - /* Reset LBRR flags */ - for (n = 0; n < encControl->nChannelsInternal; n++) { - silk_memset(psEnc->state_Fxx[ n ].sCmn.LBRR_flags, 0, sizeof(psEnc->state_Fxx[ n ].sCmn.LBRR_flags)); - } - - psEnc->nBitsUsedLBRR = ec_tell(psRangeEnc); - } - - silk_HP_variable_cutoff(psEnc->state_Fxx); - - /* Total target bits for packet */ - nBits = silk_DIV32_16(silk_MUL(encControl->bitRate, encControl->payloadSize_ms), 1000); - /* Subtract bits used for LBRR */ - if (!prefillFlag) { - nBits -= psEnc->nBitsUsedLBRR; - } - /* Divide by number of uncoded frames left in packet */ - nBits = silk_DIV32_16(nBits, psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket); - /* Convert to bits/second */ - if (encControl->payloadSize_ms == 10) { - TargetRate_bps = silk_SMULBB(nBits, 100); - } else { - TargetRate_bps = silk_SMULBB(nBits, 50); - } - /* Subtract fraction of bits in excess of target in previous frames and packets */ - TargetRate_bps -= silk_DIV32_16(silk_MUL(psEnc->nBitsExceeded, 1000), BITRESERVOIR_DECAY_TIME_MS); - if (!prefillFlag && psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded > 0) { - /* Compare actual vs target bits so far in this packet */ - opus_int32 bitsBalance = ec_tell(psRangeEnc) - psEnc->nBitsUsedLBRR - nBits * psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded; - TargetRate_bps -= silk_DIV32_16(silk_MUL(bitsBalance, 1000), BITRESERVOIR_DECAY_TIME_MS); - } - /* Never exceed input bitrate */ - TargetRate_bps = silk_LIMIT(TargetRate_bps, encControl->bitRate, 5000); - - /* Convert Left/Right to Mid/Side */ - if (encControl->nChannelsInternal == 2) { - silk_stereo_LR_to_MS(&psEnc->sStereo, &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ 2 ], &psEnc->state_Fxx[ 1 ].sCmn.inputBuf[ 2 ], - psEnc->sStereo.predIx[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ], &psEnc->sStereo.mid_only_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ], - MStargetRates_bps, TargetRate_bps, psEnc->state_Fxx[ 0 ].sCmn.speech_activity_Q8, encControl->toMono, - psEnc->state_Fxx[ 0 ].sCmn.fs_kHz, psEnc->state_Fxx[ 0 ].sCmn.frame_length); - if (psEnc->sStereo.mid_only_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ] == 0) { - /* Reset side channel encoder memory for first frame with side coding */ - if (psEnc->prev_decode_only_middle == 1) { - silk_memset(&psEnc->state_Fxx[ 1 ].sShape, 0, sizeof(psEnc->state_Fxx[ 1 ].sShape)); - silk_memset(&psEnc->state_Fxx[ 1 ].sCmn.sNSQ, 0, sizeof(psEnc->state_Fxx[ 1 ].sCmn.sNSQ)); - silk_memset(psEnc->state_Fxx[ 1 ].sCmn.prev_NLSFq_Q15, 0, sizeof(psEnc->state_Fxx[ 1 ].sCmn.prev_NLSFq_Q15)); - silk_memset(&psEnc->state_Fxx[ 1 ].sCmn.sLP.In_LP_State, 0, sizeof(psEnc->state_Fxx[ 1 ].sCmn.sLP.In_LP_State)); - psEnc->state_Fxx[ 1 ].sCmn.prevLag = 100; - psEnc->state_Fxx[ 1 ].sCmn.sNSQ.lagPrev = 100; - psEnc->state_Fxx[ 1 ].sShape.LastGainIndex = 10; - psEnc->state_Fxx[ 1 ].sCmn.prevSignalType = TYPE_NO_VOICE_ACTIVITY; - psEnc->state_Fxx[ 1 ].sCmn.sNSQ.prev_gain_Q16 = 65536; - psEnc->state_Fxx[ 1 ].sCmn.first_frame_after_reset = 1; - } - silk_encode_do_VAD_Fxx(&psEnc->state_Fxx[ 1 ], activity); - } else { - psEnc->state_Fxx[ 1 ].sCmn.VAD_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ] = 0; - } - if (!prefillFlag) { - silk_stereo_encode_pred(psRangeEnc, psEnc->sStereo.predIx[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ]); - if (psEnc->state_Fxx[ 1 ].sCmn.VAD_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ] == 0) { - silk_stereo_encode_mid_only(psRangeEnc, psEnc->sStereo.mid_only_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ]); - } - } - } else { - /* Buffering */ - silk_memcpy(psEnc->state_Fxx[ 0 ].sCmn.inputBuf, psEnc->sStereo.sMid, 2 * sizeof(opus_int16)); - silk_memcpy(psEnc->sStereo.sMid, &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.frame_length ], 2 * sizeof(opus_int16)); - } - silk_encode_do_VAD_Fxx(&psEnc->state_Fxx[ 0 ], activity); - - /* Encode */ - for (n = 0; n < encControl->nChannelsInternal; n++) { - opus_int maxBits, useCBR; - - /* Handling rate constraints */ - maxBits = encControl->maxBits; - if (tot_blocks == 2 && curr_block == 0) { - maxBits = maxBits * 3 / 5; - } else if (tot_blocks == 3) { - if (curr_block == 0) { - maxBits = maxBits * 2 / 5; - } else if (curr_block == 1) { - maxBits = maxBits * 3 / 4; - } - } - useCBR = encControl->useCBR && curr_block == tot_blocks - 1; - - if (encControl->nChannelsInternal == 1) { - channelRate_bps = TargetRate_bps; - } else { - channelRate_bps = MStargetRates_bps[ n ]; - if (n == 0 && MStargetRates_bps[ 1 ] > 0) { - useCBR = 0; - /* Give mid up to 1/2 of the max bits for that frame */ - maxBits -= encControl->maxBits / (tot_blocks * 2); - } - } - - if (channelRate_bps > 0) { - opus_int condCoding; - - silk_control_SNR(&psEnc->state_Fxx[ n ].sCmn, channelRate_bps); - - /* Use independent coding if no previous frame available */ - if (psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded - n <= 0) { - condCoding = CODE_INDEPENDENTLY; - } else if (n > 0 && psEnc->prev_decode_only_middle) { - /* If we skipped a side frame in this packet, we don't - need LTP scaling; the LTP state is well-defined. */ - condCoding = CODE_INDEPENDENTLY_NO_LTP_SCALING; - } else { - condCoding = CODE_CONDITIONALLY; - } - if ((ret = silk_encode_frame_Fxx(&psEnc->state_Fxx[ n ], nBytesOut, psRangeEnc, condCoding, maxBits, useCBR)) != 0) { - silk_assert(0); - } - } - psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0; - psEnc->state_Fxx[ n ].sCmn.inputBufIx = 0; - psEnc->state_Fxx[ n ].sCmn.nFramesEncoded++; - } - psEnc->prev_decode_only_middle = psEnc->sStereo.mid_only_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded - 1 ]; - - /* Insert VAD and FEC flags at beginning of bitstream */ - if (*nBytesOut > 0 && psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded == psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket) { - flags = 0; - for (n = 0; n < encControl->nChannelsInternal; n++) { - for (i = 0; i < psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket; i++) { - flags = silk_LSHIFT(flags, 1); - flags |= psEnc->state_Fxx[ n ].sCmn.VAD_flags[ i ]; - } - flags = silk_LSHIFT(flags, 1); - flags |= psEnc->state_Fxx[ n ].sCmn.LBRR_flag; - } - if (!prefillFlag) { - ec_enc_patch_initial_bits(psRangeEnc, flags, (psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket + 1) * encControl->nChannelsInternal); - } - - /* Return zero bytes if all channels DTXed */ - if (psEnc->state_Fxx[ 0 ].sCmn.inDTX && (encControl->nChannelsInternal == 1 || psEnc->state_Fxx[ 1 ].sCmn.inDTX)) { - *nBytesOut = 0; - } - - psEnc->nBitsExceeded += *nBytesOut * 8; - psEnc->nBitsExceeded -= silk_DIV32_16(silk_MUL(encControl->bitRate, encControl->payloadSize_ms), 1000); - psEnc->nBitsExceeded = silk_LIMIT(psEnc->nBitsExceeded, 0, 10000); - - /* Update flag indicating if bandwidth switching is allowed */ - speech_act_thr_for_switch_Q8 = silk_SMLAWB(SILK_FIX_CONST(SPEECH_ACTIVITY_DTX_THRES, 8), - SILK_FIX_CONST((1 - SPEECH_ACTIVITY_DTX_THRES) / MAX_BANDWIDTH_SWITCH_DELAY_MS, 16 + 8), psEnc->timeSinceSwitchAllowed_ms); - if (psEnc->state_Fxx[ 0 ].sCmn.speech_activity_Q8 < speech_act_thr_for_switch_Q8) { - psEnc->allowBandwidthSwitch = 1; - psEnc->timeSinceSwitchAllowed_ms = 0; - } else { - psEnc->allowBandwidthSwitch = 0; - psEnc->timeSinceSwitchAllowed_ms += encControl->payloadSize_ms; - } - } - - if (nSamplesIn == 0) { - break; - } - } else { - break; - } - curr_block++; - } - - psEnc->nPrevChannelsInternal = encControl->nChannelsInternal; - - encControl->allowBandwidthSwitch = psEnc->allowBandwidthSwitch; - encControl->inWBmodeWithoutVariableLP = psEnc->state_Fxx[ 0 ].sCmn.fs_kHz == 16 && psEnc->state_Fxx[ 0 ].sCmn.sLP.mode == 0; - encControl->internalSampleRate = silk_SMULBB(psEnc->state_Fxx[ 0 ].sCmn.fs_kHz, 1000); - encControl->stereoWidth_Q14 = encControl->toMono ? 0 : psEnc->sStereo.smth_width_Q14; - if (prefillFlag) { - encControl->payloadSize_ms = tmp_payloadSize_ms; - encControl->complexity = tmp_complexity; - for (n = 0; n < encControl->nChannelsInternal; n++) { - psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0; - psEnc->state_Fxx[ n ].sCmn.prefillFlag = 0; - } - } - - encControl->signalType = psEnc->state_Fxx[0].sCmn.indices.signalType; - encControl->offset = silk_Quantization_Offsets_Q10 - [ psEnc->state_Fxx[0].sCmn.indices.signalType >> 1 ] - [ psEnc->state_Fxx[0].sCmn.indices.quantOffsetType ]; - RESTORE_STACK; - return ret; -} - -#endif diff --git a/src/libopus/silk/encode_indices.c b/src/libopus/silk/encode_indices.c index c342d51..1ef2442 100644 --- a/src/libopus/silk/encode_indices.c +++ b/src/libopus/silk/encode_indices.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -38,135 +38,137 @@ void silk_encode_indices( opus_int FrameIndex, /* I Frame number */ opus_int encode_LBRR, /* I Flag indicating LBRR data is being encoded */ opus_int condCoding /* I The type of conditional coding to use */ -) { +) +{ opus_int i, k, typeOffset; opus_int encode_absolute_lagIndex, delta_lagIndex; opus_int16 ec_ix[ MAX_LPC_ORDER ]; opus_uint8 pred_Q8[ MAX_LPC_ORDER ]; const SideInfoIndices *psIndices; - if (encode_LBRR) { - psIndices = &psEncC->indices_LBRR[ FrameIndex ]; + if( encode_LBRR ) { + psIndices = &psEncC->indices_LBRR[ FrameIndex ]; } else { - psIndices = &psEncC->indices; + psIndices = &psEncC->indices; } /*******************************************/ /* Encode signal type and quantizer offset */ /*******************************************/ typeOffset = 2 * psIndices->signalType + psIndices->quantOffsetType; - celt_assert(typeOffset >= 0 && typeOffset < 6); - celt_assert(encode_LBRR == 0 || typeOffset >= 2); - if (encode_LBRR || typeOffset >= 2) { - ec_enc_icdf(psRangeEnc, typeOffset - 2, silk_type_offset_VAD_iCDF, 8); + celt_assert( typeOffset >= 0 && typeOffset < 6 ); + celt_assert( encode_LBRR == 0 || typeOffset >= 2 ); + if( encode_LBRR || typeOffset >= 2 ) { + ec_enc_icdf( psRangeEnc, typeOffset - 2, silk_type_offset_VAD_iCDF, 8 ); } else { - ec_enc_icdf(psRangeEnc, typeOffset, silk_type_offset_no_VAD_iCDF, 8); + ec_enc_icdf( psRangeEnc, typeOffset, silk_type_offset_no_VAD_iCDF, 8 ); } /****************/ /* Encode gains */ /****************/ /* first subframe */ - if (condCoding == CODE_CONDITIONALLY) { + if( condCoding == CODE_CONDITIONALLY ) { /* conditional coding */ - silk_assert(psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1); - ec_enc_icdf(psRangeEnc, psIndices->GainsIndices[ 0 ], silk_delta_gain_iCDF, 8); + silk_assert( psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ); + ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ 0 ], silk_delta_gain_iCDF, 8 ); } else { /* independent coding, in two stages: MSB bits followed by 3 LSBs */ - silk_assert(psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < N_LEVELS_QGAIN); - ec_enc_icdf(psRangeEnc, silk_RSHIFT(psIndices->GainsIndices[ 0 ], 3), silk_gain_iCDF[ psIndices->signalType ], 8); - ec_enc_icdf(psRangeEnc, psIndices->GainsIndices[ 0 ] & 7, silk_uniform8_iCDF, 8); + silk_assert( psIndices->GainsIndices[ 0 ] >= 0 && psIndices->GainsIndices[ 0 ] < N_LEVELS_QGAIN ); + ec_enc_icdf( psRangeEnc, silk_RSHIFT( psIndices->GainsIndices[ 0 ], 3 ), silk_gain_iCDF[ psIndices->signalType ], 8 ); + ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ 0 ] & 7, silk_uniform8_iCDF, 8 ); } /* remaining subframes */ - for (i = 1; i < psEncC->nb_subfr; i++) { - silk_assert(psIndices->GainsIndices[ i ] >= 0 && psIndices->GainsIndices[ i ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1); - ec_enc_icdf(psRangeEnc, psIndices->GainsIndices[ i ], silk_delta_gain_iCDF, 8); + for( i = 1; i < psEncC->nb_subfr; i++ ) { + silk_assert( psIndices->GainsIndices[ i ] >= 0 && psIndices->GainsIndices[ i ] < MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ); + ec_enc_icdf( psRangeEnc, psIndices->GainsIndices[ i ], silk_delta_gain_iCDF, 8 ); } /****************/ /* Encode NLSFs */ /****************/ - ec_enc_icdf(psRangeEnc, psIndices->NLSFIndices[ 0 ], &psEncC->psNLSF_CB->CB1_iCDF[(psIndices->signalType >> 1) * psEncC->psNLSF_CB->nVectors ], 8); - silk_NLSF_unpack(ec_ix, pred_Q8, psEncC->psNLSF_CB, psIndices->NLSFIndices[ 0 ]); - celt_assert(psEncC->psNLSF_CB->order == psEncC->predictLPCOrder); - for (i = 0; i < psEncC->psNLSF_CB->order; i++) { - if (psIndices->NLSFIndices[ i + 1 ] >= NLSF_QUANT_MAX_AMPLITUDE) { - ec_enc_icdf(psRangeEnc, 2 * NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8); - ec_enc_icdf(psRangeEnc, psIndices->NLSFIndices[ i + 1 ] - NLSF_QUANT_MAX_AMPLITUDE, silk_NLSF_EXT_iCDF, 8); - } else if (psIndices->NLSFIndices[ i + 1 ] <= -NLSF_QUANT_MAX_AMPLITUDE) { - ec_enc_icdf(psRangeEnc, 0, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8); - ec_enc_icdf(psRangeEnc, -psIndices->NLSFIndices[ i + 1 ] - NLSF_QUANT_MAX_AMPLITUDE, silk_NLSF_EXT_iCDF, 8); + ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ 0 ], &psEncC->psNLSF_CB->CB1_iCDF[ ( psIndices->signalType >> 1 ) * psEncC->psNLSF_CB->nVectors ], 8 ); + silk_NLSF_unpack( ec_ix, pred_Q8, psEncC->psNLSF_CB, psIndices->NLSFIndices[ 0 ] ); + celt_assert( psEncC->psNLSF_CB->order == psEncC->predictLPCOrder ); + for( i = 0; i < psEncC->psNLSF_CB->order; i++ ) { + if( psIndices->NLSFIndices[ i+1 ] >= NLSF_QUANT_MAX_AMPLITUDE ) { + ec_enc_icdf( psRangeEnc, 2 * NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 ); + ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i+1 ] - NLSF_QUANT_MAX_AMPLITUDE, silk_NLSF_EXT_iCDF, 8 ); + } else if( psIndices->NLSFIndices[ i+1 ] <= -NLSF_QUANT_MAX_AMPLITUDE ) { + ec_enc_icdf( psRangeEnc, 0, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 ); + ec_enc_icdf( psRangeEnc, -psIndices->NLSFIndices[ i+1 ] - NLSF_QUANT_MAX_AMPLITUDE, silk_NLSF_EXT_iCDF, 8 ); } else { - ec_enc_icdf(psRangeEnc, psIndices->NLSFIndices[ i + 1 ] + NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8); + ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i+1 ] + NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 ); } } /* Encode NLSF interpolation factor */ - if (psEncC->nb_subfr == MAX_NB_SUBFR) { - silk_assert(psIndices->NLSFInterpCoef_Q2 >= 0 && psIndices->NLSFInterpCoef_Q2 < 5); - ec_enc_icdf(psRangeEnc, psIndices->NLSFInterpCoef_Q2, silk_NLSF_interpolation_factor_iCDF, 8); + if( psEncC->nb_subfr == MAX_NB_SUBFR ) { + silk_assert( psIndices->NLSFInterpCoef_Q2 >= 0 && psIndices->NLSFInterpCoef_Q2 < 5 ); + ec_enc_icdf( psRangeEnc, psIndices->NLSFInterpCoef_Q2, silk_NLSF_interpolation_factor_iCDF, 8 ); } - if (psIndices->signalType == TYPE_VOICED) { + if( psIndices->signalType == TYPE_VOICED ) + { /*********************/ /* Encode pitch lags */ /*********************/ /* lag index */ encode_absolute_lagIndex = 1; - if (condCoding == CODE_CONDITIONALLY && psEncC->ec_prevSignalType == TYPE_VOICED) { + if( condCoding == CODE_CONDITIONALLY && psEncC->ec_prevSignalType == TYPE_VOICED ) { /* Delta Encoding */ delta_lagIndex = psIndices->lagIndex - psEncC->ec_prevLagIndex; - if (delta_lagIndex < -8 || delta_lagIndex > 11) { + if( delta_lagIndex < -8 || delta_lagIndex > 11 ) { delta_lagIndex = 0; } else { delta_lagIndex = delta_lagIndex + 9; encode_absolute_lagIndex = 0; /* Only use delta */ } - silk_assert(delta_lagIndex >= 0 && delta_lagIndex < 21); - ec_enc_icdf(psRangeEnc, delta_lagIndex, silk_pitch_delta_iCDF, 8); + silk_assert( delta_lagIndex >= 0 && delta_lagIndex < 21 ); + ec_enc_icdf( psRangeEnc, delta_lagIndex, silk_pitch_delta_iCDF, 8 ); } - if (encode_absolute_lagIndex) { + if( encode_absolute_lagIndex ) { /* Absolute encoding */ opus_int32 pitch_high_bits, pitch_low_bits; - pitch_high_bits = silk_DIV32_16(psIndices->lagIndex, silk_RSHIFT(psEncC->fs_kHz, 1)); - pitch_low_bits = psIndices->lagIndex - silk_SMULBB(pitch_high_bits, silk_RSHIFT(psEncC->fs_kHz, 1)); - silk_assert(pitch_low_bits < psEncC->fs_kHz / 2); - silk_assert(pitch_high_bits < 32); - ec_enc_icdf(psRangeEnc, pitch_high_bits, silk_pitch_lag_iCDF, 8); - ec_enc_icdf(psRangeEnc, pitch_low_bits, psEncC->pitch_lag_low_bits_iCDF, 8); + pitch_high_bits = silk_DIV32_16( psIndices->lagIndex, silk_RSHIFT( psEncC->fs_kHz, 1 ) ); + pitch_low_bits = psIndices->lagIndex - silk_SMULBB( pitch_high_bits, silk_RSHIFT( psEncC->fs_kHz, 1 ) ); + silk_assert( pitch_low_bits < psEncC->fs_kHz / 2 ); + silk_assert( pitch_high_bits < 32 ); + ec_enc_icdf( psRangeEnc, pitch_high_bits, silk_pitch_lag_iCDF, 8 ); + ec_enc_icdf( psRangeEnc, pitch_low_bits, psEncC->pitch_lag_low_bits_iCDF, 8 ); } psEncC->ec_prevLagIndex = psIndices->lagIndex; /* Countour index */ - silk_assert(psIndices->contourIndex >= 0); - silk_assert((psIndices->contourIndex < 34 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 4) || - (psIndices->contourIndex < 11 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 4) || - (psIndices->contourIndex < 12 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 2) || - (psIndices->contourIndex < 3 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 2)); - ec_enc_icdf(psRangeEnc, psIndices->contourIndex, psEncC->pitch_contour_iCDF, 8); + silk_assert( psIndices->contourIndex >= 0 ); + silk_assert( ( psIndices->contourIndex < 34 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 4 ) || + ( psIndices->contourIndex < 11 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 4 ) || + ( psIndices->contourIndex < 12 && psEncC->fs_kHz > 8 && psEncC->nb_subfr == 2 ) || + ( psIndices->contourIndex < 3 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 2 ) ); + ec_enc_icdf( psRangeEnc, psIndices->contourIndex, psEncC->pitch_contour_iCDF, 8 ); /********************/ /* Encode LTP gains */ /********************/ /* PERIndex value */ - silk_assert(psIndices->PERIndex >= 0 && psIndices->PERIndex < 3); - ec_enc_icdf(psRangeEnc, psIndices->PERIndex, silk_LTP_per_index_iCDF, 8); + silk_assert( psIndices->PERIndex >= 0 && psIndices->PERIndex < 3 ); + ec_enc_icdf( psRangeEnc, psIndices->PERIndex, silk_LTP_per_index_iCDF, 8 ); /* Codebook Indices */ - for (k = 0; k < psEncC->nb_subfr; k++) { - silk_assert(psIndices->LTPIndex[ k ] >= 0 && psIndices->LTPIndex[ k ] < (8 << psIndices->PERIndex)); - ec_enc_icdf(psRangeEnc, psIndices->LTPIndex[ k ], silk_LTP_gain_iCDF_ptrs[ psIndices->PERIndex ], 8); + for( k = 0; k < psEncC->nb_subfr; k++ ) { + silk_assert( psIndices->LTPIndex[ k ] >= 0 && psIndices->LTPIndex[ k ] < ( 8 << psIndices->PERIndex ) ); + ec_enc_icdf( psRangeEnc, psIndices->LTPIndex[ k ], silk_LTP_gain_iCDF_ptrs[ psIndices->PERIndex ], 8 ); } /**********************/ /* Encode LTP scaling */ /**********************/ - if (condCoding == CODE_INDEPENDENTLY) { - silk_assert(psIndices->LTP_scaleIndex >= 0 && psIndices->LTP_scaleIndex < 3); - ec_enc_icdf(psRangeEnc, psIndices->LTP_scaleIndex, silk_LTPscale_iCDF, 8); + if( condCoding == CODE_INDEPENDENTLY ) { + silk_assert( psIndices->LTP_scaleIndex >= 0 && psIndices->LTP_scaleIndex < 3 ); + ec_enc_icdf( psRangeEnc, psIndices->LTP_scaleIndex, silk_LTPscale_iCDF, 8 ); } - silk_assert(!condCoding || psIndices->LTP_scaleIndex == 0); + silk_assert( !condCoding || psIndices->LTP_scaleIndex == 0 ); } psEncC->ec_prevSignalType = psIndices->signalType; @@ -174,6 +176,6 @@ void silk_encode_indices( /***************/ /* Encode seed */ /***************/ - silk_assert(psIndices->Seed >= 0 && psIndices->Seed < 4); - ec_enc_icdf(psRangeEnc, psIndices->Seed, silk_uniform4_iCDF, 8); + silk_assert( psIndices->Seed >= 0 && psIndices->Seed < 4 ); + ec_enc_icdf( psRangeEnc, psIndices->Seed, silk_uniform4_iCDF, 8 ); } diff --git a/src/libopus/silk/encode_pulses.c b/src/libopus/silk/encode_pulses.c index f918e34..a753e86 100644 --- a/src/libopus/silk/encode_pulses.c +++ b/src/libopus/silk/encode_pulses.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" /*********************************************/ /* Encode quantization indices of excitation */ @@ -41,12 +41,13 @@ static OPUS_INLINE opus_int combine_and_check( /* return ok const opus_int *pulses_in, /* I */ opus_int max_pulses, /* I max value for sum of pulses */ opus_int len /* I number of output values */ -) { +) +{ opus_int k, sum; - for (k = 0; k < len; k++) { + for( k = 0; k < len; k++ ) { sum = pulses_in[ 2 * k ] + pulses_in[ 2 * k + 1 ]; - if (sum > max_pulses) { + if( sum > max_pulses ) { return 1; } pulses_comb[ k ] = sum; @@ -62,12 +63,13 @@ void silk_encode_pulses( const opus_int quantOffsetType, /* I quantOffsetType */ opus_int8 pulses[], /* I quantization indices */ const opus_int frame_length /* I Frame length */ -) { +) +{ opus_int i, k, j, iter, bit, nLS, scale_down, RateLevelIndex = 0; opus_int32 abs_q, minSumBits_Q5, sumBits_Q5; - VARDECL(opus_int, abs_pulses); - VARDECL(opus_int, sum_pulses); - VARDECL(opus_int, nRshifts); + VARDECL( opus_int, abs_pulses ); + VARDECL( opus_int, sum_pulses ); + VARDECL( opus_int, nRshifts ); opus_int pulses_comb[ 8 ]; opus_int *abs_pulses_ptr; const opus_int8 *pulses_ptr; @@ -75,52 +77,52 @@ void silk_encode_pulses( const opus_uint8 *nBits_ptr; SAVE_STACK; - silk_memset(pulses_comb, 0, 8 * sizeof(opus_int)); /* Fixing Valgrind reported problem*/ + silk_memset( pulses_comb, 0, 8 * sizeof( opus_int ) ); /* Fixing Valgrind reported problem*/ /****************************/ /* Prepare for shell coding */ /****************************/ /* Calculate number of shell blocks */ - silk_assert(1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH); - iter = silk_RSHIFT(frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH); - if (iter * SHELL_CODEC_FRAME_LENGTH < frame_length) { - celt_assert(frame_length == 12 * 10); /* Make sure only happens for 10 ms @ 12 kHz */ + silk_assert( 1 << LOG2_SHELL_CODEC_FRAME_LENGTH == SHELL_CODEC_FRAME_LENGTH ); + iter = silk_RSHIFT( frame_length, LOG2_SHELL_CODEC_FRAME_LENGTH ); + if( iter * SHELL_CODEC_FRAME_LENGTH < frame_length ) { + celt_assert( frame_length == 12 * 10 ); /* Make sure only happens for 10 ms @ 12 kHz */ iter++; - silk_memset(&pulses[ frame_length ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof(opus_int8)); + silk_memset( &pulses[ frame_length ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof(opus_int8)); } /* Take the absolute value of the pulses */ - ALLOC(abs_pulses, iter * SHELL_CODEC_FRAME_LENGTH, opus_int); - silk_assert(!(SHELL_CODEC_FRAME_LENGTH & 3)); - for (i = 0; i < iter * SHELL_CODEC_FRAME_LENGTH; i += 4) { - abs_pulses[i + 0] = (opus_int)silk_abs(pulses[ i + 0 ]); - abs_pulses[i + 1] = (opus_int)silk_abs(pulses[ i + 1 ]); - abs_pulses[i + 2] = (opus_int)silk_abs(pulses[ i + 2 ]); - abs_pulses[i + 3] = (opus_int)silk_abs(pulses[ i + 3 ]); + ALLOC( abs_pulses, iter * SHELL_CODEC_FRAME_LENGTH, opus_int ); + silk_assert( !( SHELL_CODEC_FRAME_LENGTH & 3 ) ); + for( i = 0; i < iter * SHELL_CODEC_FRAME_LENGTH; i+=4 ) { + abs_pulses[i+0] = ( opus_int )silk_abs( pulses[ i + 0 ] ); + abs_pulses[i+1] = ( opus_int )silk_abs( pulses[ i + 1 ] ); + abs_pulses[i+2] = ( opus_int )silk_abs( pulses[ i + 2 ] ); + abs_pulses[i+3] = ( opus_int )silk_abs( pulses[ i + 3 ] ); } /* Calc sum pulses per shell code frame */ - ALLOC(sum_pulses, iter, opus_int); - ALLOC(nRshifts, iter, opus_int); + ALLOC( sum_pulses, iter, opus_int ); + ALLOC( nRshifts, iter, opus_int ); abs_pulses_ptr = abs_pulses; - for (i = 0; i < iter; i++) { + for( i = 0; i < iter; i++ ) { nRshifts[ i ] = 0; - while (1) { + while( 1 ) { /* 1+1 -> 2 */ - scale_down = combine_and_check(pulses_comb, abs_pulses_ptr, silk_max_pulses_table[ 0 ], 8); + scale_down = combine_and_check( pulses_comb, abs_pulses_ptr, silk_max_pulses_table[ 0 ], 8 ); /* 2+2 -> 4 */ - scale_down += combine_and_check(pulses_comb, pulses_comb, silk_max_pulses_table[ 1 ], 4); + scale_down += combine_and_check( pulses_comb, pulses_comb, silk_max_pulses_table[ 1 ], 4 ); /* 4+4 -> 8 */ - scale_down += combine_and_check(pulses_comb, pulses_comb, silk_max_pulses_table[ 2 ], 2); + scale_down += combine_and_check( pulses_comb, pulses_comb, silk_max_pulses_table[ 2 ], 2 ); /* 8+8 -> 16 */ - scale_down += combine_and_check(&sum_pulses[ i ], pulses_comb, silk_max_pulses_table[ 3 ], 1); + scale_down += combine_and_check( &sum_pulses[ i ], pulses_comb, silk_max_pulses_table[ 3 ], 1 ); - if (scale_down) { + if( scale_down ) { /* We need to downscale the quantization signal */ nRshifts[ i ]++; - for (k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++) { - abs_pulses_ptr[ k ] = silk_RSHIFT(abs_pulses_ptr[ k ], 1); + for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { + abs_pulses_ptr[ k ] = silk_RSHIFT( abs_pulses_ptr[ k ], 1 ); } } else { /* Jump out of while(1) loop and go to next shell coding frame */ @@ -135,63 +137,63 @@ void silk_encode_pulses( /**************/ /* find rate level that leads to fewest bits for coding of pulses per block info */ minSumBits_Q5 = silk_int32_MAX; - for (k = 0; k < N_RATE_LEVELS - 1; k++) { + for( k = 0; k < N_RATE_LEVELS - 1; k++ ) { nBits_ptr = silk_pulses_per_block_BITS_Q5[ k ]; sumBits_Q5 = silk_rate_levels_BITS_Q5[ signalType >> 1 ][ k ]; - for (i = 0; i < iter; i++) { - if (nRshifts[ i ] > 0) { + for( i = 0; i < iter; i++ ) { + if( nRshifts[ i ] > 0 ) { sumBits_Q5 += nBits_ptr[ SILK_MAX_PULSES + 1 ]; } else { sumBits_Q5 += nBits_ptr[ sum_pulses[ i ] ]; } } - if (sumBits_Q5 < minSumBits_Q5) { + if( sumBits_Q5 < minSumBits_Q5 ) { minSumBits_Q5 = sumBits_Q5; RateLevelIndex = k; } } - ec_enc_icdf(psRangeEnc, RateLevelIndex, silk_rate_levels_iCDF[ signalType >> 1 ], 8); + ec_enc_icdf( psRangeEnc, RateLevelIndex, silk_rate_levels_iCDF[ signalType >> 1 ], 8 ); /***************************************************/ /* Sum-Weighted-Pulses Encoding */ /***************************************************/ cdf_ptr = silk_pulses_per_block_iCDF[ RateLevelIndex ]; - for (i = 0; i < iter; i++) { - if (nRshifts[ i ] == 0) { - ec_enc_icdf(psRangeEnc, sum_pulses[ i ], cdf_ptr, 8); + for( i = 0; i < iter; i++ ) { + if( nRshifts[ i ] == 0 ) { + ec_enc_icdf( psRangeEnc, sum_pulses[ i ], cdf_ptr, 8 ); } else { - ec_enc_icdf(psRangeEnc, SILK_MAX_PULSES + 1, cdf_ptr, 8); - for (k = 0; k < nRshifts[ i ] - 1; k++) { - ec_enc_icdf(psRangeEnc, SILK_MAX_PULSES + 1, silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1 ], 8); + ec_enc_icdf( psRangeEnc, SILK_MAX_PULSES + 1, cdf_ptr, 8 ); + for( k = 0; k < nRshifts[ i ] - 1; k++ ) { + ec_enc_icdf( psRangeEnc, SILK_MAX_PULSES + 1, silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1 ], 8 ); } - ec_enc_icdf(psRangeEnc, sum_pulses[ i ], silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1 ], 8); + ec_enc_icdf( psRangeEnc, sum_pulses[ i ], silk_pulses_per_block_iCDF[ N_RATE_LEVELS - 1 ], 8 ); } } /******************/ /* Shell Encoding */ /******************/ - for (i = 0; i < iter; i++) { - if (sum_pulses[ i ] > 0) { - silk_shell_encoder(psRangeEnc, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ]); + for( i = 0; i < iter; i++ ) { + if( sum_pulses[ i ] > 0 ) { + silk_shell_encoder( psRangeEnc, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ] ); } } /****************/ /* LSB Encoding */ /****************/ - for (i = 0; i < iter; i++) { - if (nRshifts[ i ] > 0) { + for( i = 0; i < iter; i++ ) { + if( nRshifts[ i ] > 0 ) { pulses_ptr = &pulses[ i * SHELL_CODEC_FRAME_LENGTH ]; nLS = nRshifts[ i ] - 1; - for (k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++) { - abs_q = (opus_int8)silk_abs(pulses_ptr[ k ]); - for (j = nLS; j > 0; j--) { - bit = silk_RSHIFT(abs_q, j) & 1; - ec_enc_icdf(psRangeEnc, bit, silk_lsb_iCDF, 8); + for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) { + abs_q = (opus_int8)silk_abs( pulses_ptr[ k ] ); + for( j = nLS; j > 0; j-- ) { + bit = silk_RSHIFT( abs_q, j ) & 1; + ec_enc_icdf( psRangeEnc, bit, silk_lsb_iCDF, 8 ); } bit = abs_q & 1; - ec_enc_icdf(psRangeEnc, bit, silk_lsb_iCDF, 8); + ec_enc_icdf( psRangeEnc, bit, silk_lsb_iCDF, 8 ); } } } @@ -199,6 +201,6 @@ void silk_encode_pulses( /****************/ /* Encode signs */ /****************/ - silk_encode_signs(psRangeEnc, pulses, frame_length, signalType, quantOffsetType, sum_pulses); + silk_encode_signs( psRangeEnc, pulses, frame_length, signalType, quantOffsetType, sum_pulses ); RESTORE_STACK; } diff --git a/src/libopus/silk/entdec.h b/src/libopus/silk/entdec.h new file mode 100644 index 0000000..07f6c03 --- /dev/null +++ b/src/libopus/silk/entdec.h @@ -0,0 +1 @@ +#include "../celt/entdec.h" diff --git a/src/libopus/silk/entenc.h b/src/libopus/silk/entenc.h new file mode 100644 index 0000000..0ee730b --- /dev/null +++ b/src/libopus/silk/entenc.h @@ -0,0 +1 @@ +#include "../celt/entenc.h" diff --git a/src/libopus/silk/errors.h b/src/libopus/silk/errors.h index 3b0158b..4507080 100644 --- a/src/libopus/silk/errors.h +++ b/src/libopus/silk/errors.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_ERRORS_H diff --git a/src/libopus/silk/fixed/LTP_analysis_filter_FIX.c b/src/libopus/silk/fixed/LTP_analysis_filter_FIX.c index 9936a2c..e7eaabd 100644 --- a/src/libopus/silk/fixed/LTP_analysis_filter_FIX.c +++ b/src/libopus/silk/fixed/LTP_analysis_filter_FIX.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" @@ -40,7 +40,8 @@ void silk_LTP_analysis_filter_FIX( const opus_int subfr_length, /* I Length of each subframe */ const opus_int nb_subfr, /* I Number of subframes */ const opus_int pre_length /* I Length of the preceding samples starting at &x[0] for each subframe */ -) { +) +{ const opus_int16 *x_ptr, *x_lag_ptr; opus_int16 Btmp_Q14[ LTP_ORDER ]; opus_int16 *LTP_res_ptr; @@ -49,7 +50,7 @@ void silk_LTP_analysis_filter_FIX( x_ptr = x; LTP_res_ptr = LTP_res; - for (k = 0; k < nb_subfr; k++) { + for( k = 0; k < nb_subfr; k++ ) { x_lag_ptr = x_ptr - pitchL[ k ]; @@ -60,23 +61,23 @@ void silk_LTP_analysis_filter_FIX( Btmp_Q14[ 4 ] = LTPCoef_Q14[ k * LTP_ORDER + 4 ]; /* LTP analysis FIR filter */ - for (i = 0; i < subfr_length + pre_length; i++) { + for( i = 0; i < subfr_length + pre_length; i++ ) { LTP_res_ptr[ i ] = x_ptr[ i ]; /* Long-term prediction */ - LTP_est = silk_SMULBB(x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ]); - LTP_est = silk_SMLABB_ovflw(LTP_est, x_lag_ptr[ 1 ], Btmp_Q14[ 1 ]); - LTP_est = silk_SMLABB_ovflw(LTP_est, x_lag_ptr[ 0 ], Btmp_Q14[ 2 ]); - LTP_est = silk_SMLABB_ovflw(LTP_est, x_lag_ptr[ -1 ], Btmp_Q14[ 3 ]); - LTP_est = silk_SMLABB_ovflw(LTP_est, x_lag_ptr[ -2 ], Btmp_Q14[ 4 ]); + LTP_est = silk_SMULBB( x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ] ); + LTP_est = silk_SMLABB_ovflw( LTP_est, x_lag_ptr[ 1 ], Btmp_Q14[ 1 ] ); + LTP_est = silk_SMLABB_ovflw( LTP_est, x_lag_ptr[ 0 ], Btmp_Q14[ 2 ] ); + LTP_est = silk_SMLABB_ovflw( LTP_est, x_lag_ptr[ -1 ], Btmp_Q14[ 3 ] ); + LTP_est = silk_SMLABB_ovflw( LTP_est, x_lag_ptr[ -2 ], Btmp_Q14[ 4 ] ); - LTP_est = silk_RSHIFT_ROUND(LTP_est, 14); /* round and -> Q0*/ + LTP_est = silk_RSHIFT_ROUND( LTP_est, 14 ); /* round and -> Q0*/ /* Subtract long-term prediction */ - LTP_res_ptr[ i ] = (opus_int16)silk_SAT16((opus_int32)x_ptr[ i ] - LTP_est); + LTP_res_ptr[ i ] = (opus_int16)silk_SAT16( (opus_int32)x_ptr[ i ] - LTP_est ); /* Scale residual */ - LTP_res_ptr[ i ] = silk_SMULWB(invGains_Q16[ k ], LTP_res_ptr[ i ]); + LTP_res_ptr[ i ] = silk_SMULWB( invGains_Q16[ k ], LTP_res_ptr[ i ] ); x_lag_ptr++; } diff --git a/src/libopus/silk/fixed/LTP_analysis_filter_FIX.lo b/src/libopus/silk/fixed/LTP_analysis_filter_FIX.lo deleted file mode 100644 index 762ccd9..0000000 --- a/src/libopus/silk/fixed/LTP_analysis_filter_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/LTP_analysis_filter_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/LTP_analysis_filter_FIX.o' - -# Name of the non-PIC object -non_pic_object='LTP_analysis_filter_FIX.o' - diff --git a/src/libopus/silk/fixed/LTP_analysis_filter_FIX.o b/src/libopus/silk/fixed/LTP_analysis_filter_FIX.o deleted file mode 100644 index 714ff662821a8dfc539895e6d6d2fb7888ceb4eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13896 zcmbtb4|G)JmH*znVKR_E69|8Ts014RshLSa2vI;XNx%sNAtVG4^f{S%Nd_h}K^N|f865PuBTmXSGTLuwUWK}`|kJV zv?RO6E-TS+LzI*TY@6CH*&x*E{9!+DiY3zEI=OoHlq$W={aZK$R4;{zuG_r<{Fp{n`%tjW0?#@IG zwN)OA9D?pz0>`g{f8CzI@onBn%KW#~*e@ce7=@6(pyqUyl$8!iN% ze>3p>sqk>!_~9ZS0KW?dj#q=isqoMz+L<4W>|yNW`QrU2w71VMc>T@`$nTkY=LNQR zWF&I>B;IxvgcqD_4IKYbYvB2xwC+FQiR?e^Y2E*-Cvx()r4YfY3u~@@J#Zj70v1rZ zw<7yroeFTuC5v(trqZ?o%lAjDss7^U=K!E*NmgtKS4t_q+7&MMUTgBU#}0`Y{9! zdCR}*kkcP=$jhE_$QiFna$NaghrH}%N%|K47m&U>C=d7OtGg0NUyH*p`V!@x4!;-+ z?29{m!vf@OhrhNANUz_3tM27PqWk%cSIqxQ4f7rk|Jd1rPeVFmFmjO9X9yGh#YaH; z1^zpvO9lNU(&d7_fOLhRN06Rh2p3ksG-Rp;qj9D|Fdoh{3dYNsh+xKXW}RSsoY^E8 zzt#&8-YS?0T0by-f+^y8WCT;n8Cx)uw09taLBUMbmIJd_Fw-=gBKrhWu36x1zhExc z_5*WJFmtq@f!YzlRB8VK%)^2Sa^`WtggEoGV5&Luf?#U3DzG^wn1wvH6M|W!4M9Jz zu_BPOf=Bo;lovdXNs3Z_3rV8Cjp@=be5VcIQW)2Iz`XwFVRVaQ0AbiAxR4OV(d6jY zC0fP;DB?q3uv|l2(2XuS%;{289Dfh?DaeC)a>yYkT!w)Z-vXE4g62f#`?WNfFar@< zJ9;UfbH#fg(0M@e822*YG@!Zr!Z`>}iWF^l3+_DmqAr}YL~lgeBk)Z~dj-82X`i5P zLQ_$oqAiC37xT1eE8=3F7Tt_=h0wnR>G^^-kggW=tw=WrI*NW8p_ps29~AIqS=7B4 zNZ&uhr5M-Z7eMfwysQ{CC&G@wc@Mu9Fdu60OpE8EkZaXQt@+G13uqxm#VNdukvc02M0gt`1VDSwFh9(Cl`AuL=i$&*X-Ua(#D7PU6{@vOH~;DbB=rs z!b0^%B#Y<57Bd6>@mhdtA<$m`a$HXpKnm5hs3FL8+zRFGE~~I3Z%0_DcJNqm3)tmS zO*-;UgoSDsR#1=|`4FJhi_$8Jt6H*$ldoEXG(`VD}f(MNXO^Ai~x}VR0I?wn;6oEN7>q)rUf^b!4;_ zgtXJqN}!PU_=42h%Y2VJ@+87#u<W3s^yp_bT$G$aEo-_EpZ zJg2agCtQqBtih)z-n@R?%)NfBG}9((b4tnz^^zGS6SYYNrJ(GY%Jh=!3YQeNLV@&3 zR#)AW+ULUg8q+Js`qa|5Us z5)10c7Ri2LgPZuf7n~qsE zmOs=q9o*50_S@|X*sYiWl>AGb`qtr4U)78(%Jn7_ee%g zFE9Izw&5|yTp^^k#yTbGHthTZ4BN*tY`>(ToHH6*FG<-W#D8Ru5}?D%UNp8zk}kVr ze}LU))ecLu`JzB+9WfXZ-XN;;yQS$qn$;Y1Vk6>vbRQ-q7@|w5BuFK|Za(VSdeqZ( z)YEa)v*oBq3Z##cyaJc24rR13+jtu_2eSES5B{G8^04ZQY9TZF33(q&=Pb$Iqk99( zc^>fit1JE0b9b>Tb4)S=?8@1>-IBAA^Gfckz&$2C{DwSLvmNaJ=RsP2{wK#GJ>V}x zY}LOns|*_>8)-R(2H}sdi}Y}XGq2W3ayCILS#FoCzrPDHy|dWtJU}n?1okOw`_yF)bkBhZn%`)}#vlrA7g{ zJd)1jEJK>W(FrLf(n7gEYWD#J&!6ZAK_qurhMCPK6P7Ks%#eZQl}o+fse%D*tBvR)56@t2eJ) zyP`?oxk(@2qnG|rzs-N-?u~6rtkrF;%a*KOwsytZ#RCVJ$E*1sg{%H^xcGgy5qOt_JFcnTj*+%<40fNdxmYc(w}#oJ%Eo(%JrcBhlQl5}@8xZ?vCV z-=0m_Cb!R}5I5r$(3h~vG&Mtd!m zNDZ{-qA9z>HZvWGou<)V&kO_nF06%wnwx5jjlF%g(S9v6`lH$HX4VoelUBEk5DJ46 zY~VJdH=0Np89Qqk?Tdw4ThsdWq9?A6!b=3q(;YM*D6WLljE8{bgh-&E>732$U_}Q+ z8F(2p2|LyYWlY)WTvmkClT1gcE*4C6Gi_wDX5848246x0h?;uzila&uZxA9mhV^xn z0i=dyO{C)HpipsJEfkO$Gb}U7n(Y3J(O%;+ zvJ>f)(YDSA8|}3)W3d#M*eKktae!!Q!fdf&0@?L-Sjt>?PZlOws@Lx0d1cLLTx12s z5f-?mFbH*Gbj3p;AuLM6RW{fhZ)`Hw!2SsK ze4%o0uBkb?Yf$DX8=15v_MQB?#FK^AfRRcYUEvm?i<=T3Bbg~*WBJOd8!HW~3e#Fp z;aZ-JIH^OISPyV;@@+zFQetVr4v#Brp}5tF8_f{09P?qOx(&Wum@&YIMy_-m(B#kt=NLSoVIFr9i1X#52huClCM;LF5#KR z4;5#q`N+9<(cAE}fUfDd;sdc_Q)hk>t!!;uVPujy98WnhaW>%Lcd5xBr-8ExIkggd zCO=@sB)s_Sqy4*%LP#g$PCcPp313`SHuwCt0Y{PnrGi}eq=jQPXPNO@7V1m)n;|or zO`4%_HV&ms>GWk(6~TLI72>>(57c8cUHMTXRdn&mM6%9Z7oV9NUJ^Qk zH&|mdU3@IMNTRdii?A7hO!DOGFSCj5mzf`EdgD0s(VIs ztLTkoR>40ZKRXnBnE2faZc>pBDY!-b9#QZ*^8e=w9;doJt>FJo{-0IwkBC2};6>E$ zDFxq0e%?}W{Ahyhr{d;}*LL!APQe$`;K-LKaz5;!DR@EA|1sg?=`QvEhUzd`!Kc&s z&Q$Pk(s*5^;2Gi`L>Bu-TD>nZ*#6+BGwU#;NPv@RMHyo>l13Vsj8w_d^J7HKH>yA*#?!GA#f4h8>$ z^zT;i?^0ez6?_J*m&X;ni|YTZg7eQ#P>UZb_-^ulTEQ*i-%;?B#J{iLms7vLR`9P7 z{)K{HMYx~lg&f}+!lx+sGMXo|6+BFJs8;aHXxtYo_#X1ptl+DNU#sBLXk4}^xIy#h z5e1)1^?XdhKc;@aui(Yx=Vb+-M|qu6@D}2Ktl)cTe*U9^ho}xeSMWz@JVq3J72!n` zuN;>V;>#5LVHz)a?n(VOsSb^b{&K2kn}R6v#AE5d3vZBA5;`s*!KSgnWuHe@be+9)Q{jVnf%?gfxQ->{~;9cb3 zR&e=T@_>RrOZtDQ;NPKmjw|>pg#Vp_zeD&>6?}~dlYOe-@6r63LUoe)7E->86g)!u zjS5~w<09)V{X9r|+ZFvJ<$FlM;}qxj6&yc=V0%Ns%ZPth!T+1|KU44?;x)=c#u=jc zuTk)g#4lFx>EvI^rJpCMzTJv`Gv&Ka!M{oTu!6rtejZlv6pimO1wT*vXBGTKiu2zT z{0_=j?oTrQTGB6}eM{mW(Ec!8!NsUBR;l1uP@MAjjr4Pd{A3jUS17&*75ogv`I3T9 zrFx!JaCxquCLGft7d+H|RrFI-w_mt$nj&2PQw6_~68;|-j=9}Se#Bn^ir<3h=N{4@ zk4n&F9bTtS%3L@?Cr}BR`0K#D{s`&MR`kycbvDn1BRPxeT;sygMKz6Yy$eSY|8@;q zi-Oluo!2Y)6v}_A3rGL*6MWQ#BiTd!Zg=6R{{-O~7mnmy8nm4*9Q9u({XH%m$pMOg z$c3Z+H1hMHg0~a?go5V?f7*p3`4;(q(S@V`uaiEB`S{Y*2Pyrz6x=avQbm|;raV-< zf=h+2Tb~839sTeg4(@hV-1{VD1cO% z)*O%=eAOGJ8HH~+z3__HZ4DohO{ovPv0yCS-wz*ISuh3PM}qLp1-_5K_YyKP`;4A! zwBMv0{*)WOzrotbx=LS-M9ANf5|_UZBtHuXw5MetVRjb5F`5d`10CFw{#bkb?;)yB z>{j;w8qFibu&KKEhXT0t8sVS2l~)L^f)d8}OsGfOr}Kw5%K%e-qUAT}h1GS6P+{5X zOW40luiA!aUqGMORQoMsV5nzI!Ylqs$mpipcY%1U{2Rzn+GGBhyPAI*Fx4kO>@fBJ zPl`}s**4G}tN%XgxE!59!~St7)&B1Q41LNtf#fYQS={fU{gYrPRvE|LAQ;R3S62v& ztE3^_rJcMVCVNGVO}kP>1TXER^hqEP8?^@kUrzS70_|=xe~IB=Lyc9xy<^lb0J_p% z)^)7D(f1(r-$w!CaN^ry)gH^Mu3doGxtVx{zor*A=c?w9<2si8!xaB>j-?<}`~L;? CuRlNl diff --git a/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.c b/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.c index 68ace87..9b10879 100644 --- a/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.c +++ b/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" @@ -36,14 +36,20 @@ void silk_LTP_scale_ctrl_FIX( silk_encoder_state_FIX *psEnc, /* I/O encoder state */ silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ opus_int condCoding /* I The type of conditional coding to use */ -) { +) +{ opus_int round_loss; - if (condCoding == CODE_INDEPENDENTLY) { + if( condCoding == CODE_INDEPENDENTLY ) { /* Only scale if first frame in packet */ - round_loss = psEnc->sCmn.PacketLoss_perc + psEnc->sCmn.nFramesPerPacket; - psEnc->sCmn.indices.LTP_scaleIndex = (opus_int8)silk_LIMIT( - silk_SMULWB(silk_SMULBB(round_loss, psEncCtrl->LTPredCodGain_Q7), SILK_FIX_CONST(0.1, 9)), 0, 2); + round_loss = psEnc->sCmn.PacketLoss_perc * psEnc->sCmn.nFramesPerPacket; + if ( psEnc->sCmn.LBRR_flag ) { + /* LBRR reduces the effective loss. In practice, it does not square the loss because + losses aren't independent, but that still seems to work best. We also never go below 2%. */ + round_loss = 2 + silk_SMULBB( round_loss, round_loss ) / 100; + } + psEnc->sCmn.indices.LTP_scaleIndex = silk_SMULBB( psEncCtrl->LTPredCodGain_Q7, round_loss ) > silk_log2lin( 128*7 + 2900-psEnc->sCmn.SNR_dB_Q7 ); + psEnc->sCmn.indices.LTP_scaleIndex += silk_SMULBB( psEncCtrl->LTPredCodGain_Q7, round_loss ) > silk_log2lin( 128*7 + 3900-psEnc->sCmn.SNR_dB_Q7 ); } else { /* Default is minimum scaling */ psEnc->sCmn.indices.LTP_scaleIndex = 0; diff --git a/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.lo b/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.lo deleted file mode 100644 index 24d93f5..0000000 --- a/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/LTP_scale_ctrl_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/LTP_scale_ctrl_FIX.o' - -# Name of the non-PIC object -non_pic_object='LTP_scale_ctrl_FIX.o' - diff --git a/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.o b/src/libopus/silk/fixed/LTP_scale_ctrl_FIX.o deleted file mode 100644 index 06f6521da96a0384f653ae181ec30732ec46b4fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20696 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⪻d|lrX2Ixy`WDAHaEV^R9O|%&r+Q+Ea7v+jv*t7W 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 IBgppu3+1p46951J diff --git a/src/libopus/silk/fixed/PLC.h b/src/libopus/silk/fixed/PLC.h new file mode 100644 index 0000000..7b74107 --- /dev/null +++ b/src/libopus/silk/fixed/PLC.h @@ -0,0 +1 @@ +#include "../PLC.h" diff --git a/src/libopus/silk/fixed/SigProc_FIX.h b/src/libopus/silk/fixed/SigProc_FIX.h new file mode 100644 index 0000000..54611bd --- /dev/null +++ b/src/libopus/silk/fixed/SigProc_FIX.h @@ -0,0 +1 @@ +#include "../SigProc_FIX.h" diff --git a/src/libopus/silk/fixed/apply_sine_window_FIX.c b/src/libopus/silk/fixed/apply_sine_window_FIX.c index ac19642..3349213 100644 --- a/src/libopus/silk/fixed/apply_sine_window_FIX.c +++ b/src/libopus/silk/fixed/apply_sine_window_FIX.c @@ -1,35 +1,35 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif -#include "../SigProc_FIX.h" +#include "SigProc_FIX.h" /* Apply sine window to signal vector. */ /* Window types: */ @@ -38,11 +38,11 @@ /* Every other sample is linearly interpolated, for speed. */ /* Window length must be between 16 and 120 (incl) and a multiple of 4. */ -/* Matlab code for table: - for k=16:9*4:16+2*9*4, fprintf(' %7.d,', -round(65536*pi ./ (k:4:k+8*4))); fprintf('\n'); end +/* Matlab code for table: + for k=16:9*4:16+2*9*4, fprintf(' %7.d,', -round(65536*pi ./ (k:4:k+8*4))); fprintf('\n'); end */ static const opus_int16 freq_table_Q16[ 27 ] = { - 12111, 9804, 8235, 7100, 6239, 5565, 5022, 4575, 4202, + 12111, 9804, 8235, 7100, 6239, 5565, 5022, 4575, 4202, 3885, 3612, 3375, 3167, 2984, 2820, 2674, 2542, 2422, 2313, 2214, 2123, 2038, 1961, 1889, 1822, 1760, 1702, }; @@ -52,49 +52,50 @@ void silk_apply_sine_window( const opus_int16 px[], /* I Pointer to input signal */ const opus_int win_type, /* I Selects a window type */ const opus_int length /* I Window length, multiple of 4 */ -) { +) +{ opus_int k, f_Q16, c_Q16; opus_int32 S0_Q16, S1_Q16; - celt_assert(win_type == 1 || win_type == 2); + celt_assert( win_type == 1 || win_type == 2 ); /* Length must be in a range from 16 to 120 and a multiple of 4 */ - celt_assert(length >= 16 && length <= 120); - celt_assert((length & 3) == 0); + celt_assert( length >= 16 && length <= 120 ); + celt_assert( ( length & 3 ) == 0 ); /* Frequency */ - k = (length >> 2) - 4; - celt_assert(k >= 0 && k <= 26); + k = ( length >> 2 ) - 4; + celt_assert( k >= 0 && k <= 26 ); f_Q16 = (opus_int)freq_table_Q16[ k ]; /* Factor used for cosine approximation */ - c_Q16 = silk_SMULWB((opus_int32)f_Q16, -f_Q16); - silk_assert(c_Q16 >= -32768); + c_Q16 = silk_SMULWB( (opus_int32)f_Q16, -f_Q16 ); + silk_assert( c_Q16 >= -32768 ); /* initialize state */ - if (win_type == 1) { + if( win_type == 1 ) { /* start from 0 */ S0_Q16 = 0; /* approximation of sin(f) */ - S1_Q16 = f_Q16 + silk_RSHIFT(length, 3); + S1_Q16 = f_Q16 + silk_RSHIFT( length, 3 ); } else { /* start from 1 */ - S0_Q16 = ((opus_int32)1 << 16); + S0_Q16 = ( (opus_int32)1 << 16 ); /* approximation of cos(f) */ - S1_Q16 = ((opus_int32)1 << 16) + silk_RSHIFT(c_Q16, 1) + silk_RSHIFT(length, 4); + S1_Q16 = ( (opus_int32)1 << 16 ) + silk_RSHIFT( c_Q16, 1 ) + silk_RSHIFT( length, 4 ); } /* Uses the recursive equation: sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f) */ /* 4 samples at a time */ - for (k = 0; k < length; k += 4) { - px_win[ k ] = (opus_int16)silk_SMULWB(silk_RSHIFT(S0_Q16 + S1_Q16, 1), px[ k ]); - px_win[ k + 1 ] = (opus_int16)silk_SMULWB(S1_Q16, px[ k + 1]); - S0_Q16 = silk_SMULWB(S1_Q16, c_Q16) + silk_LSHIFT(S1_Q16, 1) - S0_Q16 + 1; - S0_Q16 = silk_min(S0_Q16, ((opus_int32)1 << 16)); + for( k = 0; k < length; k += 4 ) { + px_win[ k ] = (opus_int16)silk_SMULWB( silk_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k ] ); + px_win[ k + 1 ] = (opus_int16)silk_SMULWB( S1_Q16, px[ k + 1] ); + S0_Q16 = silk_SMULWB( S1_Q16, c_Q16 ) + silk_LSHIFT( S1_Q16, 1 ) - S0_Q16 + 1; + S0_Q16 = silk_min( S0_Q16, ( (opus_int32)1 << 16 ) ); - px_win[ k + 2 ] = (opus_int16)silk_SMULWB(silk_RSHIFT(S0_Q16 + S1_Q16, 1), px[ k + 2]); - px_win[ k + 3 ] = (opus_int16)silk_SMULWB(S0_Q16, px[ k + 3 ]); - S1_Q16 = silk_SMULWB(S0_Q16, c_Q16) + silk_LSHIFT(S0_Q16, 1) - S1_Q16; - S1_Q16 = silk_min(S1_Q16, ((opus_int32)1 << 16)); + px_win[ k + 2 ] = (opus_int16)silk_SMULWB( silk_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k + 2] ); + px_win[ k + 3 ] = (opus_int16)silk_SMULWB( S0_Q16, px[ k + 3 ] ); + S1_Q16 = silk_SMULWB( S0_Q16, c_Q16 ) + silk_LSHIFT( S0_Q16, 1 ) - S1_Q16; + S1_Q16 = silk_min( S1_Q16, ( (opus_int32)1 << 16 ) ); } } diff --git a/src/libopus/silk/fixed/apply_sine_window_FIX.lo b/src/libopus/silk/fixed/apply_sine_window_FIX.lo deleted file mode 100644 index 0228ba8..0000000 --- a/src/libopus/silk/fixed/apply_sine_window_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/apply_sine_window_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/apply_sine_window_FIX.o' - -# Name of the non-PIC object -non_pic_object='apply_sine_window_FIX.o' - diff --git a/src/libopus/silk/fixed/apply_sine_window_FIX.o b/src/libopus/silk/fixed/apply_sine_window_FIX.o deleted file mode 100644 index fdbd8fc619fb8f5bbeb26105776781ddf659d4d3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10688 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 B?{okF diff --git a/src/libopus/silk/fixed/autocorr_FIX.c b/src/libopus/silk/fixed/autocorr_FIX.c index ce4f6ad..fe7a800 100644 --- a/src/libopus/silk/fixed/autocorr_FIX.c +++ b/src/libopus/silk/fixed/autocorr_FIX.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif -#include "../SigProc_FIX.h" -#include "../../celt/celt_lpc.h" +#include "SigProc_FIX.h" +#include "celt_lpc.h" /* Compute autocorrelation */ void silk_autocorr( @@ -40,8 +40,9 @@ void silk_autocorr( const opus_int inputDataSize, /* I Length of input */ const opus_int correlationCount, /* I Number of correlation taps to compute */ int arch /* I Run-time architecture */ -) { +) +{ opus_int corrCount; - corrCount = silk_min_int(inputDataSize, correlationCount); - *scale = _celt_autocorr(inputData, results, NULL, 0, corrCount - 1, inputDataSize, arch); + corrCount = silk_min_int( inputDataSize, correlationCount ); + *scale = _celt_autocorr(inputData, results, NULL, 0, corrCount-1, inputDataSize, arch); } diff --git a/src/libopus/silk/fixed/autocorr_FIX.lo b/src/libopus/silk/fixed/autocorr_FIX.lo deleted file mode 100644 index b0ef65d..0000000 --- a/src/libopus/silk/fixed/autocorr_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/autocorr_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/autocorr_FIX.o' - -# Name of the non-PIC object -non_pic_object='autocorr_FIX.o' - diff --git a/src/libopus/silk/fixed/autocorr_FIX.o b/src/libopus/silk/fixed/autocorr_FIX.o deleted file mode 100644 index 9d4cbba4e76e75fb2d0feb93dfcb97f5269d7e9f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8024 zcmbtY4Qw366`r~E+2=SpJ252ZB%p&P!J*up&vuLpg!qS;xC)8mB$7i4oAurLZtL@{ zwR@L1v_O75dSR+X8X*y-IA{^b&~Cp9c8KAAr~x`!zg` z1~F(OCMpqG?2jCKZH9k#w&|Vw!1EH6oBoM3$?tyy#F*qiK)FrI|3Wz-<$t4`l=6ot zcecQTH8GB$O9C!HzXTBh1|(<@V4DO{0mdX~6ktMv7(WdW9*|%Oe+@uUf~8^{vl6rk zP?2B-KM4`cNwAV{0dPcuRs0ZuqY@Q zCP7AkrzGeS;28kV2lOlZSbhnNWks5A>5x%h)`0^VNIW>y zfgakUL7x#A+yx8fFi{urZ2LIhyK16kp9pYelx4wY)%;Noi9s=O=TXigiTj2Ukli$l z2F4P-tYfr2DGXMF_ZU)`g*9o0A(i7Y5K1yu%Sq;JuM#%~)R+?0Qf*+c4j!fU^QvTE zxJQYZfZDCZu&+If`cmtVvt3G5!9b`=4Ex%(sIT=w5aUWz4mjJV#IUdNMSa19i^AE2 z62pcQiyD3;Fx;m^)pLX$VoDA>+jpL`E5HeCLQuq3B_w<(tAHRue9=M1Hyexi^g^vd z7i8%12{4E-c#j$9@5h(HQ=CK)`%Y;(Gv&p4>WyUGzO4YnA^$47=H|bP-@K{e7=$u`uFlJRNZqD^Qb7XWPox|hMZl^Hj zxj8`;F(rN_pSP#dMF#t9XNZ-^N08p#H39RKt+LcT`GA9rGpMj9ZS zrs+;inHA>etdh;l(VeDeTX}P~;xRKo_T*%-YMG+MzC{o<4C;@JZr^IomZ~zSL!MKyMGkSY%8&|38YV1LbZ6|0 zZFwa-Gw9{3PT9rv>RFy+`D!>R9|m0RY<0Gb|+I)2OS^QWyz@=-duEGVV8mPD^_kgHS4(*J6CbNlwa|1h8AlO z^F^xzRsl>IE?hMYqE#kN%qJujM*vGi<(EyBTnpf=>xW+g7@L?ZAJtihSoO%NS5}*tSuIz68(QTHB;JmKH6vF#B)d8*C)>0A zY6*5J^e=NJx?|T54_}q++&c-cX;n^ds;4SY_O@()x~q4iWW@$6PGKPNTgDlmYvXH{ zHpT9RoopR&YlQ}F-~7_Z&zNtr5e0UO=hAJ(!G8Fg=tuv6hK zS*IAmhoZL8VB#WHO9C>24@zy5p?#iIt06B}3I?^Y$Op-gmw`Y}2?m2hU!7ve)Ao5S zMsUojZ8GE)poVM%v?798l|_A8F9wKhdg%qC9mD4gyRYAgAZkaZ<8o^H&QYZ>i&*Ae&+u{Ls6$Y#s3wRpVLb@^i7qf1UhXuJP)P?bCR5#vRglygOsr zq4D1#{zi@8MR-c%@1!_=jlWsCXGb*tTg2b3@!ur;u*N?@@jR*VHxvIgjenWqIi>OH z>Z|5W0|9ga6HNJ=R*J}LF$nQptSL?4&NB>=vw=*Fg^-mN3ix7|c4)MPY z@u;u9yMHHM<&)Iedm;U1&{w4m4-Qb2{^b&~BJpax)5PDS@t>keyMGa0ojuS`_>`#5 zM5@K`cSlT~419u0gE1s;2O7h@3oUY&nA)Uu-LweGO-x36yw=I@ZTORL3V!teF=5&02>VWMhli7idDC*9?ct)^?}x^E<9~)G zSlQ$FasSZA?*ga$1d848U-o}=5&K)o{($COgX~tYuNVKXD1Nn0G5)3Sug8B6^{>VW zP?Vq3X8A*HVXFRB{SauQtlNKine?OfRf!gIrR-0Vy=qtW8M0Sc)yhuc7eGKRq6n(b zlKp_jtMM!PIS}gQ@7+52!@HugS9z`1H~LP{!TuQv7=Pzztz(aA)=~@%W3Qkxlwnx~ VPksCtQ$71Ox~QHCETy2^{|Ed$R!jf@ diff --git a/src/libopus/silk/fixed/burg_modified_FIX.c b/src/libopus/silk/fixed/burg_modified_FIX.c index 17e2e82..745e3f9 100644 --- a/src/libopus/silk/fixed/burg_modified_FIX.c +++ b/src/libopus/silk/fixed/burg_modified_FIX.c @@ -1,38 +1,38 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif -#include "../SigProc_FIX.h" -#include "../define.h" -#include "../tuning_parameters.h" -#include "../../celt/pitch.h" +#include "SigProc_FIX.h" +#include "define.h" +#include "tuning_parameters.h" +#include "pitch.h" #define MAX_FRAME_SIZE 384 /* subfr_length * nb_subfr = ( 0.005 * 16000 + 16 ) * 4 = 384 */ @@ -52,121 +52,117 @@ void silk_burg_modified_c( const opus_int nb_subfr, /* I Number of subframes stacked in x */ const opus_int D, /* I Order */ int arch /* I Run-time architecture */ -) { +) +{ opus_int k, n, s, lz, rshifts, reached_max_gain; opus_int32 C0, num, nrg, rc_Q31, invGain_Q30, Atmp_QA, Atmp1, tmp1, tmp2, x1, x2; const opus_int16 *x_ptr; - opus_int32 *C_first_row = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC); - opus_int32 *C_last_row = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC); - opus_int32 *Af_QA = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC); - opus_int32 *CAf = (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC + 1)); - opus_int32 *CAb = (opus_int32*)malloc(sizeof(opus_int32) * (SILK_MAX_ORDER_LPC + 1)); - opus_int32 *xcorr = (opus_int32*)malloc(sizeof(opus_int32) * SILK_MAX_ORDER_LPC); + opus_int32 C_first_row[ SILK_MAX_ORDER_LPC ]; + opus_int32 C_last_row[ SILK_MAX_ORDER_LPC ]; + opus_int32 Af_QA[ SILK_MAX_ORDER_LPC ]; + opus_int32 CAf[ SILK_MAX_ORDER_LPC + 1 ]; + opus_int32 CAb[ SILK_MAX_ORDER_LPC + 1 ]; + opus_int32 xcorr[ SILK_MAX_ORDER_LPC ]; opus_int64 C0_64; - celt_assert(subfr_length * nb_subfr <= MAX_FRAME_SIZE); + celt_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE ); /* Compute autocorrelations, added over subframes */ - C0_64 = silk_inner_prod16_aligned_64(x, x, subfr_length * nb_subfr, arch); + C0_64 = silk_inner_prod16( x, x, subfr_length*nb_subfr, arch ); lz = silk_CLZ64(C0_64); rshifts = 32 + 1 + N_BITS_HEAD_ROOM - lz; - if (rshifts > MAX_RSHIFTS) { - rshifts = MAX_RSHIFTS; - } - if (rshifts < MIN_RSHIFTS) { - rshifts = MIN_RSHIFTS; - } + if (rshifts > MAX_RSHIFTS) rshifts = MAX_RSHIFTS; + if (rshifts < MIN_RSHIFTS) rshifts = MIN_RSHIFTS; if (rshifts > 0) { - C0 = (opus_int32)silk_RSHIFT64(C0_64, rshifts); + C0 = (opus_int32)silk_RSHIFT64(C0_64, rshifts ); } else { - C0 = silk_LSHIFT32((opus_int32)C0_64, -rshifts); + C0 = silk_LSHIFT32((opus_int32)C0_64, -rshifts ); } - CAb[ 0 ] = CAf[ 0 ] = C0 + silk_SMMUL(SILK_FIX_CONST(FIND_LPC_COND_FAC, 32), C0) + 1; /* Q(-rshifts) */ - silk_memset(C_first_row, 0, SILK_MAX_ORDER_LPC * sizeof(opus_int32)); - if (rshifts > 0) { - for (s = 0; s < nb_subfr; s++) { + CAb[ 0 ] = CAf[ 0 ] = C0 + silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_FAC, 32 ), C0 ) + 1; /* Q(-rshifts) */ + silk_memset( C_first_row, 0, SILK_MAX_ORDER_LPC * sizeof( opus_int32 ) ); + if( rshifts > 0 ) { + for( s = 0; s < nb_subfr; s++ ) { x_ptr = x + s * subfr_length; - for (n = 1; n < D + 1; n++) { + for( n = 1; n < D + 1; n++ ) { C_first_row[ n - 1 ] += (opus_int32)silk_RSHIFT64( - silk_inner_prod16_aligned_64(x_ptr, x_ptr + n, subfr_length - n, arch), rshifts); + silk_inner_prod16( x_ptr, x_ptr + n, subfr_length - n, arch ), rshifts ); } } } else { - for (s = 0; s < nb_subfr; s++) { + for( s = 0; s < nb_subfr; s++ ) { int i; opus_int32 d; x_ptr = x + s * subfr_length; - celt_pitch_xcorr(x_ptr, x_ptr + 1, xcorr, subfr_length - D, D, arch); - for (n = 1; n < D + 1; n++) { - for (i = n + subfr_length - D, d = 0; i < subfr_length; i++) { - d = MAC16_16(d, x_ptr[ i ], x_ptr[ i - n ]); - } - xcorr[ n - 1 ] += d; + celt_pitch_xcorr(x_ptr, x_ptr + 1, xcorr, subfr_length - D, D, arch ); + for( n = 1; n < D + 1; n++ ) { + for ( i = n + subfr_length - D, d = 0; i < subfr_length; i++ ) + d = MAC16_16( d, x_ptr[ i ], x_ptr[ i - n ] ); + xcorr[ n - 1 ] += d; } - for (n = 1; n < D + 1; n++) { - C_first_row[ n - 1 ] += silk_LSHIFT32(xcorr[ n - 1 ], -rshifts); + for( n = 1; n < D + 1; n++ ) { + C_first_row[ n - 1 ] += silk_LSHIFT32( xcorr[ n - 1 ], -rshifts ); } } } - silk_memcpy(C_last_row, C_first_row, SILK_MAX_ORDER_LPC * sizeof(opus_int32)); + silk_memcpy( C_last_row, C_first_row, SILK_MAX_ORDER_LPC * sizeof( opus_int32 ) ); /* Initialize */ - CAb[ 0 ] = CAf[ 0 ] = C0 + silk_SMMUL(SILK_FIX_CONST(FIND_LPC_COND_FAC, 32), C0) + 1; /* Q(-rshifts) */ + CAb[ 0 ] = CAf[ 0 ] = C0 + silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_FAC, 32 ), C0 ) + 1; /* Q(-rshifts) */ invGain_Q30 = (opus_int32)1 << 30; reached_max_gain = 0; - for (n = 0; n < D; n++) { + for( n = 0; n < D; n++ ) { /* Update first row of correlation matrix (without first element) */ /* Update last row of correlation matrix (without last element, stored in reversed order) */ /* Update C * Af */ /* Update C * flipud(Af) (stored in reversed order) */ - if (rshifts > -2) { - for (s = 0; s < nb_subfr; s++) { + if( rshifts > -2 ) { + for( s = 0; s < nb_subfr; s++ ) { x_ptr = x + s * subfr_length; - x1 = -silk_LSHIFT32((opus_int32)x_ptr[ n ], 16 - rshifts); /* Q(16-rshifts) */ - x2 = -silk_LSHIFT32((opus_int32)x_ptr[ subfr_length - n - 1 ], 16 - rshifts); /* Q(16-rshifts) */ - tmp1 = silk_LSHIFT32((opus_int32)x_ptr[ n ], QA - 16); /* Q(QA-16) */ - tmp2 = silk_LSHIFT32((opus_int32)x_ptr[ subfr_length - n - 1 ], QA - 16); /* Q(QA-16) */ - for (k = 0; k < n; k++) { - C_first_row[ k ] = silk_SMLAWB(C_first_row[ k ], x1, x_ptr[ n - k - 1 ]); /* Q( -rshifts ) */ - C_last_row[ k ] = silk_SMLAWB(C_last_row[ k ], x2, x_ptr[ subfr_length - n + k ]); /* Q( -rshifts ) */ + x1 = -silk_LSHIFT32( (opus_int32)x_ptr[ n ], 16 - rshifts ); /* Q(16-rshifts) */ + x2 = -silk_LSHIFT32( (opus_int32)x_ptr[ subfr_length - n - 1 ], 16 - rshifts ); /* Q(16-rshifts) */ + tmp1 = silk_LSHIFT32( (opus_int32)x_ptr[ n ], QA - 16 ); /* Q(QA-16) */ + tmp2 = silk_LSHIFT32( (opus_int32)x_ptr[ subfr_length - n - 1 ], QA - 16 ); /* Q(QA-16) */ + for( k = 0; k < n; k++ ) { + C_first_row[ k ] = silk_SMLAWB( C_first_row[ k ], x1, x_ptr[ n - k - 1 ] ); /* Q( -rshifts ) */ + C_last_row[ k ] = silk_SMLAWB( C_last_row[ k ], x2, x_ptr[ subfr_length - n + k ] ); /* Q( -rshifts ) */ Atmp_QA = Af_QA[ k ]; - tmp1 = silk_SMLAWB(tmp1, Atmp_QA, x_ptr[ n - k - 1 ]); /* Q(QA-16) */ - tmp2 = silk_SMLAWB(tmp2, Atmp_QA, x_ptr[ subfr_length - n + k ]); /* Q(QA-16) */ + tmp1 = silk_SMLAWB( tmp1, Atmp_QA, x_ptr[ n - k - 1 ] ); /* Q(QA-16) */ + tmp2 = silk_SMLAWB( tmp2, Atmp_QA, x_ptr[ subfr_length - n + k ] ); /* Q(QA-16) */ } - tmp1 = silk_LSHIFT32(-tmp1, 32 - QA - rshifts); /* Q(16-rshifts) */ - tmp2 = silk_LSHIFT32(-tmp2, 32 - QA - rshifts); /* Q(16-rshifts) */ - for (k = 0; k <= n; k++) { - CAf[ k ] = silk_SMLAWB(CAf[ k ], tmp1, x_ptr[ n - k ]); /* Q( -rshift ) */ - CAb[ k ] = silk_SMLAWB(CAb[ k ], tmp2, x_ptr[ subfr_length - n + k - 1 ]); /* Q( -rshift ) */ + tmp1 = silk_LSHIFT32( -tmp1, 32 - QA - rshifts ); /* Q(16-rshifts) */ + tmp2 = silk_LSHIFT32( -tmp2, 32 - QA - rshifts ); /* Q(16-rshifts) */ + for( k = 0; k <= n; k++ ) { + CAf[ k ] = silk_SMLAWB( CAf[ k ], tmp1, x_ptr[ n - k ] ); /* Q( -rshift ) */ + CAb[ k ] = silk_SMLAWB( CAb[ k ], tmp2, x_ptr[ subfr_length - n + k - 1 ] ); /* Q( -rshift ) */ } } } else { - for (s = 0; s < nb_subfr; s++) { + for( s = 0; s < nb_subfr; s++ ) { x_ptr = x + s * subfr_length; - x1 = -silk_LSHIFT32((opus_int32)x_ptr[ n ], -rshifts); /* Q( -rshifts ) */ - x2 = -silk_LSHIFT32((opus_int32)x_ptr[ subfr_length - n - 1 ], -rshifts); /* Q( -rshifts ) */ - tmp1 = silk_LSHIFT32((opus_int32)x_ptr[ n ], 17); /* Q17 */ - tmp2 = silk_LSHIFT32((opus_int32)x_ptr[ subfr_length - n - 1 ], 17); /* Q17 */ - for (k = 0; k < n; k++) { - C_first_row[ k ] = silk_MLA(C_first_row[ k ], x1, x_ptr[ n - k - 1 ]); /* Q( -rshifts ) */ - C_last_row[ k ] = silk_MLA(C_last_row[ k ], x2, x_ptr[ subfr_length - n + k ]); /* Q( -rshifts ) */ - Atmp1 = silk_RSHIFT_ROUND(Af_QA[ k ], QA - 17); /* Q17 */ - /* We sometimes have get overflows in the multiplications (even beyond +/- 2^32), - but they cancel each other and the real result seems to always fit in a 32-bit - signed integer. This was determined experimentally, not theoretically (unfortunately). */ - tmp1 = silk_MLA_ovflw(tmp1, x_ptr[ n - k - 1 ], Atmp1); /* Q17 */ - tmp2 = silk_MLA_ovflw(tmp2, x_ptr[ subfr_length - n + k ], Atmp1); /* Q17 */ + x1 = -silk_LSHIFT32( (opus_int32)x_ptr[ n ], -rshifts ); /* Q( -rshifts ) */ + x2 = -silk_LSHIFT32( (opus_int32)x_ptr[ subfr_length - n - 1 ], -rshifts ); /* Q( -rshifts ) */ + tmp1 = silk_LSHIFT32( (opus_int32)x_ptr[ n ], 17 ); /* Q17 */ + tmp2 = silk_LSHIFT32( (opus_int32)x_ptr[ subfr_length - n - 1 ], 17 ); /* Q17 */ + for( k = 0; k < n; k++ ) { + C_first_row[ k ] = silk_MLA( C_first_row[ k ], x1, x_ptr[ n - k - 1 ] ); /* Q( -rshifts ) */ + C_last_row[ k ] = silk_MLA( C_last_row[ k ], x2, x_ptr[ subfr_length - n + k ] ); /* Q( -rshifts ) */ + Atmp1 = silk_RSHIFT_ROUND( Af_QA[ k ], QA - 17 ); /* Q17 */ + /* We sometimes get overflows in the multiplications (even beyond +/- 2^32), + but they cancel each other and the real result seems to always fit in a 32-bit + signed integer. This was determined experimentally, not theoretically (unfortunately). */ + tmp1 = silk_MLA_ovflw( tmp1, x_ptr[ n - k - 1 ], Atmp1 ); /* Q17 */ + tmp2 = silk_MLA_ovflw( tmp2, x_ptr[ subfr_length - n + k ], Atmp1 ); /* Q17 */ } tmp1 = -tmp1; /* Q17 */ tmp2 = -tmp2; /* Q17 */ - for (k = 0; k <= n; k++) { - CAf[ k ] = silk_SMLAWW(CAf[ k ], tmp1, - silk_LSHIFT32((opus_int32)x_ptr[ n - k ], -rshifts - 1)); /* Q( -rshift ) */ - CAb[ k ] = silk_SMLAWW(CAb[ k ], tmp2, - silk_LSHIFT32((opus_int32)x_ptr[ subfr_length - n + k - 1 ], -rshifts - 1)); /* Q( -rshift ) */ + for( k = 0; k <= n; k++ ) { + CAf[ k ] = silk_SMLAWW( CAf[ k ], tmp1, + silk_LSHIFT32( (opus_int32)x_ptr[ n - k ], -rshifts - 1 ) ); /* Q( -rshift ) */ + CAb[ k ] = silk_SMLAWW( CAb[ k ], tmp2, + silk_LSHIFT32( (opus_int32)x_ptr[ subfr_length - n + k - 1 ], -rshifts - 1 ) ); /* Q( -rshift ) */ } } } @@ -175,43 +171,43 @@ void silk_burg_modified_c( tmp1 = C_first_row[ n ]; /* Q( -rshifts ) */ tmp2 = C_last_row[ n ]; /* Q( -rshifts ) */ num = 0; /* Q( -rshifts ) */ - nrg = silk_ADD32(CAb[ 0 ], CAf[ 0 ]); /* Q( 1-rshifts ) */ - for (k = 0; k < n; k++) { + nrg = silk_ADD32( CAb[ 0 ], CAf[ 0 ] ); /* Q( 1-rshifts ) */ + for( k = 0; k < n; k++ ) { Atmp_QA = Af_QA[ k ]; - lz = silk_CLZ32(silk_abs(Atmp_QA)) - 1; - lz = silk_min(32 - QA, lz); - Atmp1 = silk_LSHIFT32(Atmp_QA, lz); /* Q( QA + lz ) */ + lz = silk_CLZ32( silk_abs( Atmp_QA ) ) - 1; + lz = silk_min( 32 - QA, lz ); + Atmp1 = silk_LSHIFT32( Atmp_QA, lz ); /* Q( QA + lz ) */ - tmp1 = silk_ADD_LSHIFT32(tmp1, silk_SMMUL(C_last_row[ n - k - 1 ], Atmp1), 32 - QA - lz); /* Q( -rshifts ) */ - tmp2 = silk_ADD_LSHIFT32(tmp2, silk_SMMUL(C_first_row[ n - k - 1 ], Atmp1), 32 - QA - lz); /* Q( -rshifts ) */ - num = silk_ADD_LSHIFT32(num, silk_SMMUL(CAb[ n - k ], Atmp1), 32 - QA - lz); /* Q( -rshifts ) */ - nrg = silk_ADD_LSHIFT32(nrg, silk_SMMUL(silk_ADD32(CAb[ k + 1 ], CAf[ k + 1 ]), - Atmp1), 32 - QA - lz); /* Q( 1-rshifts ) */ + tmp1 = silk_ADD_LSHIFT32( tmp1, silk_SMMUL( C_last_row[ n - k - 1 ], Atmp1 ), 32 - QA - lz ); /* Q( -rshifts ) */ + tmp2 = silk_ADD_LSHIFT32( tmp2, silk_SMMUL( C_first_row[ n - k - 1 ], Atmp1 ), 32 - QA - lz ); /* Q( -rshifts ) */ + num = silk_ADD_LSHIFT32( num, silk_SMMUL( CAb[ n - k ], Atmp1 ), 32 - QA - lz ); /* Q( -rshifts ) */ + nrg = silk_ADD_LSHIFT32( nrg, silk_SMMUL( silk_ADD32( CAb[ k + 1 ], CAf[ k + 1 ] ), + Atmp1 ), 32 - QA - lz ); /* Q( 1-rshifts ) */ } CAf[ n + 1 ] = tmp1; /* Q( -rshifts ) */ CAb[ n + 1 ] = tmp2; /* Q( -rshifts ) */ - num = silk_ADD32(num, tmp2); /* Q( -rshifts ) */ - num = silk_LSHIFT32(-num, 1); /* Q( 1-rshifts ) */ + num = silk_ADD32( num, tmp2 ); /* Q( -rshifts ) */ + num = silk_LSHIFT32( -num, 1 ); /* Q( 1-rshifts ) */ /* Calculate the next order reflection (parcor) coefficient */ - if (silk_abs(num) < nrg) { - rc_Q31 = silk_DIV32_varQ(num, nrg, 31); + if( silk_abs( num ) < nrg ) { + rc_Q31 = silk_DIV32_varQ( num, nrg, 31 ); } else { - rc_Q31 = (num > 0) ? silk_int32_MAX : silk_int32_MIN; + rc_Q31 = ( num > 0 ) ? silk_int32_MAX : silk_int32_MIN; } /* Update inverse prediction gain */ - tmp1 = ((opus_int32)1 << 30) - silk_SMMUL(rc_Q31, rc_Q31); - tmp1 = silk_LSHIFT(silk_SMMUL(invGain_Q30, tmp1), 2); - if (tmp1 <= minInvGain_Q30) { + tmp1 = ( (opus_int32)1 << 30 ) - silk_SMMUL( rc_Q31, rc_Q31 ); + tmp1 = silk_LSHIFT( silk_SMMUL( invGain_Q30, tmp1 ), 2 ); + if( tmp1 <= minInvGain_Q30 ) { /* Max prediction gain exceeded; set reflection coefficient such that max prediction gain is exactly hit */ - tmp2 = ((opus_int32)1 << 30) - silk_DIV32_varQ(minInvGain_Q30, invGain_Q30, 30); /* Q30 */ - rc_Q31 = silk_SQRT_APPROX(tmp2); /* Q15 */ - if (rc_Q31 > 0) { + tmp2 = ( (opus_int32)1 << 30 ) - silk_DIV32_varQ( minInvGain_Q30, invGain_Q30, 30 ); /* Q30 */ + rc_Q31 = silk_SQRT_APPROX( tmp2 ); /* Q15 */ + if( rc_Q31 > 0 ) { /* Newton-Raphson iteration */ - rc_Q31 = silk_RSHIFT32(rc_Q31 + silk_DIV32(tmp2, rc_Q31), 1); /* Q15 */ - rc_Q31 = silk_LSHIFT32(rc_Q31, 16); /* Q31 */ - if (num < 0) { + rc_Q31 = silk_RSHIFT32( rc_Q31 + silk_DIV32( tmp2, rc_Q31 ), 1 ); /* Q15 */ + rc_Q31 = silk_LSHIFT32( rc_Q31, 16 ); /* Q31 */ + if( num < 0 ) { /* Ensure adjusted reflection coefficients has the original sign */ rc_Q31 = -rc_Q31; } @@ -223,68 +219,62 @@ void silk_burg_modified_c( } /* Update the AR coefficients */ - for (k = 0; k < (n + 1) >> 1; k++) { + for( k = 0; k < (n + 1) >> 1; k++ ) { tmp1 = Af_QA[ k ]; /* QA */ tmp2 = Af_QA[ n - k - 1 ]; /* QA */ - Af_QA[ k ] = silk_ADD_LSHIFT32(tmp1, silk_SMMUL(tmp2, rc_Q31), 1); /* QA */ - Af_QA[ n - k - 1 ] = silk_ADD_LSHIFT32(tmp2, silk_SMMUL(tmp1, rc_Q31), 1); /* QA */ + Af_QA[ k ] = silk_ADD_LSHIFT32( tmp1, silk_SMMUL( tmp2, rc_Q31 ), 1 ); /* QA */ + Af_QA[ n - k - 1 ] = silk_ADD_LSHIFT32( tmp2, silk_SMMUL( tmp1, rc_Q31 ), 1 ); /* QA */ } - Af_QA[ n ] = silk_RSHIFT32(rc_Q31, 31 - QA); /* QA */ + Af_QA[ n ] = silk_RSHIFT32( rc_Q31, 31 - QA ); /* QA */ - if (reached_max_gain) { + if( reached_max_gain ) { /* Reached max prediction gain; set remaining coefficients to zero and exit loop */ - for (k = n + 1; k < D; k++) { + for( k = n + 1; k < D; k++ ) { Af_QA[ k ] = 0; } break; } /* Update C * Af and C * Ab */ - for (k = 0; k <= n + 1; k++) { + for( k = 0; k <= n + 1; k++ ) { tmp1 = CAf[ k ]; /* Q( -rshifts ) */ tmp2 = CAb[ n - k + 1 ]; /* Q( -rshifts ) */ - CAf[ k ] = silk_ADD_LSHIFT32(tmp1, silk_SMMUL(tmp2, rc_Q31), 1); /* Q( -rshifts ) */ - CAb[ n - k + 1 ] = silk_ADD_LSHIFT32(tmp2, silk_SMMUL(tmp1, rc_Q31), 1); /* Q( -rshifts ) */ + CAf[ k ] = silk_ADD_LSHIFT32( tmp1, silk_SMMUL( tmp2, rc_Q31 ), 1 ); /* Q( -rshifts ) */ + CAb[ n - k + 1 ] = silk_ADD_LSHIFT32( tmp2, silk_SMMUL( tmp1, rc_Q31 ), 1 ); /* Q( -rshifts ) */ } } - if (reached_max_gain) { - for (k = 0; k < D; k++) { + if( reached_max_gain ) { + for( k = 0; k < D; k++ ) { /* Scale coefficients */ - A_Q16[ k ] = -silk_RSHIFT_ROUND(Af_QA[ k ], QA - 16); + A_Q16[ k ] = -silk_RSHIFT_ROUND( Af_QA[ k ], QA - 16 ); } /* Subtract energy of preceding samples from C0 */ - if (rshifts > 0) { - for (s = 0; s < nb_subfr; s++) { + if( rshifts > 0 ) { + for( s = 0; s < nb_subfr; s++ ) { x_ptr = x + s * subfr_length; - C0 -= (opus_int32)silk_RSHIFT64(silk_inner_prod16_aligned_64(x_ptr, x_ptr, D, arch), rshifts); + C0 -= (opus_int32)silk_RSHIFT64( silk_inner_prod16( x_ptr, x_ptr, D, arch ), rshifts ); } } else { - for (s = 0; s < nb_subfr; s++) { + for( s = 0; s < nb_subfr; s++ ) { x_ptr = x + s * subfr_length; - C0 -= silk_LSHIFT32(silk_inner_prod_aligned(x_ptr, x_ptr, D, arch), -rshifts); + C0 -= silk_LSHIFT32( silk_inner_prod_aligned( x_ptr, x_ptr, D, arch), -rshifts); } } /* Approximate residual energy */ - *res_nrg = silk_LSHIFT(silk_SMMUL(invGain_Q30, C0), 2); + *res_nrg = silk_LSHIFT( silk_SMMUL( invGain_Q30, C0 ), 2 ); *res_nrg_Q = -rshifts; } else { /* Return residual energy */ nrg = CAf[ 0 ]; /* Q( -rshifts ) */ tmp1 = (opus_int32)1 << 16; /* Q16 */ - for (k = 0; k < D; k++) { - Atmp1 = silk_RSHIFT_ROUND(Af_QA[ k ], QA - 16); /* Q16 */ - nrg = silk_SMLAWW(nrg, CAf[ k + 1 ], Atmp1); /* Q( -rshifts ) */ - tmp1 = silk_SMLAWW(tmp1, Atmp1, Atmp1); /* Q16 */ + for( k = 0; k < D; k++ ) { + Atmp1 = silk_RSHIFT_ROUND( Af_QA[ k ], QA - 16 ); /* Q16 */ + nrg = silk_SMLAWW( nrg, CAf[ k + 1 ], Atmp1 ); /* Q( -rshifts ) */ + tmp1 = silk_SMLAWW( tmp1, Atmp1, Atmp1 ); /* Q16 */ A_Q16[ k ] = -Atmp1; } - *res_nrg = silk_SMLAWW(nrg, silk_SMMUL(SILK_FIX_CONST(FIND_LPC_COND_FAC, 32), C0), -tmp1); /* Q( -rshifts ) */ + *res_nrg = silk_SMLAWW( nrg, silk_SMMUL( SILK_FIX_CONST( FIND_LPC_COND_FAC, 32 ), C0 ), -tmp1 );/* Q( -rshifts ) */ *res_nrg_Q = -rshifts; } - free(C_first_row); - free(C_last_row); - free(Af_QA); - free(CAf); - free(CAb); - free(xcorr); } diff --git a/src/libopus/silk/fixed/burg_modified_FIX.lo b/src/libopus/silk/fixed/burg_modified_FIX.lo deleted file mode 100644 index 05cdcd5..0000000 --- a/src/libopus/silk/fixed/burg_modified_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/burg_modified_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/burg_modified_FIX.o' - -# Name of the non-PIC object -non_pic_object='burg_modified_FIX.o' - diff --git a/src/libopus/silk/fixed/burg_modified_FIX.o b/src/libopus/silk/fixed/burg_modified_FIX.o deleted file mode 100644 index aa1a769e763d661fce6949def202bc9e8c5d4555..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30592 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 v9p_cfq{kREq|Nda(?*B@QR?v 0) { + if( rshifts > 0 ) { /* Right shifting used */ - for (lag = 0; lag < order; lag++) { + for( lag = 0; lag < order; lag++ ) { inner_prod = 0; - for (i = 0; i < L; i++) { - inner_prod = silk_ADD_RSHIFT32(inner_prod, silk_SMULBB(ptr1[ i ], ptr2[i]), rshifts); + for( i = 0; i < L; i++ ) { + inner_prod = silk_ADD_RSHIFT32( inner_prod, silk_SMULBB( ptr1[ i ], ptr2[i] ), rshifts ); } Xt[ lag ] = inner_prod; /* X[:,lag]'*t */ ptr1--; /* Go to next column of X */ } } else { - silk_assert(rshifts == 0); - for (lag = 0; lag < order; lag++) { - Xt[ lag ] = silk_inner_prod_aligned(ptr1, ptr2, L, arch); /* X[:,lag]'*t */ + silk_assert( rshifts == 0 ); + for( lag = 0; lag < order; lag++ ) { + Xt[ lag ] = silk_inner_prod_aligned( ptr1, ptr2, L, arch ); /* X[:,lag]'*t */ ptr1--; /* Go to next column of X */ } } @@ -80,66 +81,67 @@ void silk_corrMatrix_FIX( opus_int32 *nrg, /* O Energy of x vector */ opus_int *rshifts, /* O Right shifts of correlations and energy */ int arch /* I Run-time architecture */ -) { +) +{ opus_int i, j, lag; opus_int32 energy; const opus_int16 *ptr1, *ptr2; /* Calculate energy to find shift used to fit in 32 bits */ - silk_sum_sqr_shift(nrg, rshifts, x, L + order - 1); + silk_sum_sqr_shift( nrg, rshifts, x, L + order - 1 ); energy = *nrg; /* Calculate energy of first column (0) of X: X[:,0]'*X[:,0] */ /* Remove contribution of first order - 1 samples */ - for (i = 0; i < order - 1; i++) { - energy -= silk_RSHIFT32(silk_SMULBB(x[ i ], x[ i ]), *rshifts); + for( i = 0; i < order - 1; i++ ) { + energy -= silk_RSHIFT32( silk_SMULBB( x[ i ], x[ i ] ), *rshifts ); } /* Calculate energy of remaining columns of X: X[:,j]'*X[:,j] */ /* Fill out the diagonal of the correlation matrix */ - matrix_ptr(XX, 0, 0, order) = energy; - silk_assert(energy >= 0); + matrix_ptr( XX, 0, 0, order ) = energy; + silk_assert( energy >= 0 ); ptr1 = &x[ order - 1 ]; /* First sample of column 0 of X */ - for (j = 1; j < order; j++) { - energy = silk_SUB32(energy, silk_RSHIFT32(silk_SMULBB(ptr1[ L - j ], ptr1[ L - j ]), *rshifts)); - energy = silk_ADD32(energy, silk_RSHIFT32(silk_SMULBB(ptr1[ -j ], ptr1[ -j ]), *rshifts)); - matrix_ptr(XX, j, j, order) = energy; - silk_assert(energy >= 0); + for( j = 1; j < order; j++ ) { + energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr1[ L - j ] ), *rshifts ) ); + energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr1[ -j ] ), *rshifts ) ); + matrix_ptr( XX, j, j, order ) = energy; + silk_assert( energy >= 0 ); } ptr2 = &x[ order - 2 ]; /* First sample of column 1 of X */ /* Calculate the remaining elements of the correlation matrix */ - if (*rshifts > 0) { + if( *rshifts > 0 ) { /* Right shifting used */ - for (lag = 1; lag < order; lag++) { + for( lag = 1; lag < order; lag++ ) { /* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */ energy = 0; - for (i = 0; i < L; i++) { - energy += silk_RSHIFT32(silk_SMULBB(ptr1[ i ], ptr2[i]), *rshifts); + for( i = 0; i < L; i++ ) { + energy += silk_RSHIFT32( silk_SMULBB( ptr1[ i ], ptr2[i] ), *rshifts ); } /* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */ - matrix_ptr(XX, lag, 0, order) = energy; - matrix_ptr(XX, 0, lag, order) = energy; - for (j = 1; j < (order - lag); j++) { - energy = silk_SUB32(energy, silk_RSHIFT32(silk_SMULBB(ptr1[ L - j ], ptr2[ L - j ]), *rshifts)); - energy = silk_ADD32(energy, silk_RSHIFT32(silk_SMULBB(ptr1[ -j ], ptr2[ -j ]), *rshifts)); - matrix_ptr(XX, lag + j, j, order) = energy; - matrix_ptr(XX, j, lag + j, order) = energy; + matrix_ptr( XX, lag, 0, order ) = energy; + matrix_ptr( XX, 0, lag, order ) = energy; + for( j = 1; j < ( order - lag ); j++ ) { + energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ), *rshifts ) ); + energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr2[ -j ] ), *rshifts ) ); + matrix_ptr( XX, lag + j, j, order ) = energy; + matrix_ptr( XX, j, lag + j, order ) = energy; } ptr2--; /* Update pointer to first sample of next column (lag) in X */ } } else { - for (lag = 1; lag < order; lag++) { + for( lag = 1; lag < order; lag++ ) { /* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */ - energy = silk_inner_prod_aligned(ptr1, ptr2, L, arch); - matrix_ptr(XX, lag, 0, order) = energy; - matrix_ptr(XX, 0, lag, order) = energy; + energy = silk_inner_prod_aligned( ptr1, ptr2, L, arch ); + matrix_ptr( XX, lag, 0, order ) = energy; + matrix_ptr( XX, 0, lag, order ) = energy; /* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */ - for (j = 1; j < (order - lag); j++) { - energy = silk_SUB32(energy, silk_SMULBB(ptr1[ L - j ], ptr2[ L - j ])); - energy = silk_SMLABB(energy, ptr1[ -j ], ptr2[ -j ]); - matrix_ptr(XX, lag + j, j, order) = energy; - matrix_ptr(XX, j, lag + j, order) = energy; + for( j = 1; j < ( order - lag ); j++ ) { + energy = silk_SUB32( energy, silk_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ) ); + energy = silk_SMLABB( energy, ptr1[ -j ], ptr2[ -j ] ); + matrix_ptr( XX, lag + j, j, order ) = energy; + matrix_ptr( XX, j, lag + j, order ) = energy; } ptr2--;/* Update pointer to first sample of next column (lag) in X */ } diff --git a/src/libopus/silk/fixed/corrMatrix_FIX.lo b/src/libopus/silk/fixed/corrMatrix_FIX.lo deleted file mode 100644 index be8b343..0000000 --- a/src/libopus/silk/fixed/corrMatrix_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/corrMatrix_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/corrMatrix_FIX.o' - -# Name of the non-PIC object -non_pic_object='corrMatrix_FIX.o' - diff --git a/src/libopus/silk/fixed/corrMatrix_FIX.o b/src/libopus/silk/fixed/corrMatrix_FIX.o deleted file mode 100644 index 9bdb7b931bf4ec50dde97675fcce84d2dfc3b736..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17184 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 diff --git a/src/libopus/silk/fixed/debug.h b/src/libopus/silk/fixed/debug.h new file mode 100644 index 0000000..4b4c44e --- /dev/null +++ b/src/libopus/silk/fixed/debug.h @@ -0,0 +1 @@ +#include "../debug.h" diff --git a/src/libopus/silk/fixed/define.h b/src/libopus/silk/fixed/define.h new file mode 100644 index 0000000..ce1ede2 --- /dev/null +++ b/src/libopus/silk/fixed/define.h @@ -0,0 +1 @@ +#include "../define.h" diff --git a/src/libopus/silk/fixed/encode_frame_FIX.c b/src/libopus/silk/fixed/encode_frame_FIX.c deleted file mode 100644 index c771839..0000000 --- a/src/libopus/silk/fixed/encode_frame_FIX.c +++ /dev/null @@ -1,446 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif - -#include -#include "main_FIX.h" -#include "../../celt/stack_alloc.h" -#include "../tuning_parameters.h" - -#if 0 -/* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate */ -static OPUS_INLINE void silk_LBRR_encode_FIX( - silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ - silk_encoder_control_FIX *psEncCtrl, /* I/O Pointer to Silk FIX encoder control struct */ - const opus_int16 x16[], /* I Input signal */ - opus_int condCoding /* I The type of conditional coding used so far for this frame */ -); - -void silk_encode_do_VAD_FIX( - silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ - opus_int activity /* I Decision of Opus voice activity detector */ -) { - const opus_int activity_threshold = SILK_FIX_CONST(SPEECH_ACTIVITY_DTX_THRES, 8); - - /****************************/ - /* Voice Activity Detection */ - /****************************/ - silk_VAD_GetSA_Q8(&psEnc->sCmn, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.arch); - /* If Opus VAD is inactive and Silk VAD is active: lower Silk VAD to just under the threshold */ - if (activity == VAD_NO_ACTIVITY && psEnc->sCmn.speech_activity_Q8 >= activity_threshold) { - psEnc->sCmn.speech_activity_Q8 = activity_threshold - 1; - } - - /**************************************************/ - /* Convert speech activity into VAD and DTX flags */ - /**************************************************/ - if (psEnc->sCmn.speech_activity_Q8 < activity_threshold) { - psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY; - psEnc->sCmn.noSpeechCounter++; - if (psEnc->sCmn.noSpeechCounter <= NB_SPEECH_FRAMES_BEFORE_DTX) { - psEnc->sCmn.inDTX = 0; - } else if (psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX + NB_SPEECH_FRAMES_BEFORE_DTX) { - psEnc->sCmn.noSpeechCounter = NB_SPEECH_FRAMES_BEFORE_DTX; - psEnc->sCmn.inDTX = 0; - } - psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesEncoded ] = 0; - } else { - psEnc->sCmn.noSpeechCounter = 0; - psEnc->sCmn.inDTX = 0; - psEnc->sCmn.indices.signalType = TYPE_UNVOICED; - psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesEncoded ] = 1; - } -} - -/****************/ -/* Encode frame */ -/****************/ -opus_int silk_encode_frame_FIX( - silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ - opus_int32 *pnBytesOut, /* O Pointer to number of payload bytes; */ - ec_enc *psRangeEnc, /* I/O compressor data structure */ - opus_int condCoding, /* I The type of conditional coding to use */ - opus_int maxBits, /* I If > 0: maximum number of output bits */ - opus_int useCBR /* I Flag to force constant-bitrate operation */ -) { - silk_encoder_control_FIX sEncCtrl; - opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; - opus_int16 *x_frame; - ec_enc sRangeEnc_copy, sRangeEnc_copy2; - silk_nsq_state sNSQ_copy, sNSQ_copy2; - opus_int32 seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gainMult_upper; - opus_int32 gainsID, gainsID_lower, gainsID_upper; - opus_int16 gainMult_Q8; - opus_int16 ec_prevLagIndex_copy; - opus_int ec_prevSignalType_copy; - opus_int8 LastGainIndex_copy2; - opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; - opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; - opus_int best_sum[ MAX_NB_SUBFR ]; - SAVE_STACK; - - /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */ - LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_upper = 0; - - psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; - - /**************************************************************/ - /* Set up Input Pointers, and insert frame in input buffer */ - /*************************************************************/ - /* start of frame to encode */ - x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; - - /***************************************/ - /* Ensure smooth bandwidth transitions */ - /***************************************/ - silk_LP_variable_cutoff(&psEnc->sCmn.sLP, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length); - - /*******************************************/ - /* Copy new frame to front of input buffer */ - /*******************************************/ - silk_memcpy(x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length * sizeof(opus_int16)); - - if (!psEnc->sCmn.prefillFlag) { - VARDECL(opus_int16, res_pitch); - VARDECL(opus_uint8, ec_buf_copy); - opus_int16 *res_pitch_frame; - - ALLOC(res_pitch, - psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length - + psEnc->sCmn.ltp_mem_length, opus_int16); - /* start of pitch LPC residual frame */ - res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; - - /*****************************************/ - /* Find pitch lags, initial LPC analysis */ - /*****************************************/ - silk_find_pitch_lags_FIX(psEnc, &sEncCtrl, res_pitch, x_frame - psEnc->sCmn.ltp_mem_length, psEnc->sCmn.arch); - - /************************/ - /* Noise shape analysis */ - /************************/ - silk_noise_shape_analysis_FIX(psEnc, &sEncCtrl, res_pitch_frame, x_frame, psEnc->sCmn.arch); - - /***************************************************/ - /* Find linear prediction coefficients (LPC + LTP) */ - /***************************************************/ - silk_find_pred_coefs_FIX(psEnc, &sEncCtrl, res_pitch_frame, x_frame, condCoding); - - /****************************************/ - /* Process gains */ - /****************************************/ - silk_process_gains_FIX(psEnc, &sEncCtrl, condCoding); - - /****************************************/ - /* Low Bitrate Redundant Encoding */ - /****************************************/ - silk_LBRR_encode_FIX(psEnc, &sEncCtrl, x_frame, condCoding); - - /* Loop over quantizer and entropy coding to control bitrate */ - maxIter = 6; - gainMult_Q8 = SILK_FIX_CONST(1, 8); - found_lower = 0; - found_upper = 0; - gainsID = silk_gains_ID(psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr); - gainsID_lower = -1; - gainsID_upper = -1; - /* Copy part of the input state */ - silk_memcpy(&sRangeEnc_copy, psRangeEnc, sizeof(ec_enc)); - silk_memcpy(&sNSQ_copy, &psEnc->sCmn.sNSQ, sizeof(silk_nsq_state)); - seed_copy = psEnc->sCmn.indices.Seed; - ec_prevLagIndex_copy = psEnc->sCmn.ec_prevLagIndex; - ec_prevSignalType_copy = psEnc->sCmn.ec_prevSignalType; - ALLOC(ec_buf_copy, 1275, opus_uint8); - for (iter = 0; ; iter++) { - if (gainsID == gainsID_lower) { - nBits = nBits_lower; - } else if (gainsID == gainsID_upper) { - nBits = nBits_upper; - } else { - /* Restore part of the input state */ - if (iter > 0) { - silk_memcpy(psRangeEnc, &sRangeEnc_copy, sizeof(ec_enc)); - silk_memcpy(&psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof(silk_nsq_state)); - psEnc->sCmn.indices.Seed = seed_copy; - psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; - psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; - } - - /*****************************************/ - /* Noise shaping quantization */ - /*****************************************/ - if (psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0) { - silk_NSQ_del_dec(&psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, x_frame, psEnc->sCmn.pulses, - sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR_Q13, sEncCtrl.HarmShapeGain_Q14, - sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, - psEnc->sCmn.arch); - } else { - silk_NSQ(&psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, x_frame, psEnc->sCmn.pulses, - sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR_Q13, sEncCtrl.HarmShapeGain_Q14, - sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, - psEnc->sCmn.arch); - } - - if (iter == maxIter && !found_lower) { - silk_memcpy(&sRangeEnc_copy2, psRangeEnc, sizeof(ec_enc)); - } - - /****************************************/ - /* Encode Parameters */ - /****************************************/ - silk_encode_indices(&psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding); - - /****************************************/ - /* Encode Excitation Signal */ - /****************************************/ - silk_encode_pulses(psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, - psEnc->sCmn.pulses, psEnc->sCmn.frame_length); - - nBits = ec_tell(psRangeEnc); - - /* If we still bust after the last iteration, do some damage control. */ - if (iter == maxIter && !found_lower && nBits > maxBits) { - silk_memcpy(psRangeEnc, &sRangeEnc_copy2, sizeof(ec_enc)); - - /* Keep gains the same as the last frame. */ - psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; - for (i = 0; i < psEnc->sCmn.nb_subfr; i++) { - psEnc->sCmn.indices.GainsIndices[ i ] = 4; - } - if (condCoding != CODE_CONDITIONALLY) { - psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGainIndexPrev; - } - psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; - psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; - /* Clear all pulses. */ - for (i = 0; i < psEnc->sCmn.frame_length; i++) { - psEnc->sCmn.pulses[ i ] = 0; - } - - silk_encode_indices(&psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding); - - silk_encode_pulses(psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, - psEnc->sCmn.pulses, psEnc->sCmn.frame_length); - - nBits = ec_tell(psRangeEnc); - } - - if (useCBR == 0 && iter == 0 && nBits <= maxBits) { - break; - } - } - - if (iter == maxIter) { - if (found_lower && (gainsID == gainsID_lower || nBits > maxBits)) { - /* Restore output state from earlier iteration that did meet the bitrate budget */ - silk_memcpy(psRangeEnc, &sRangeEnc_copy2, sizeof(ec_enc)); - celt_assert(sRangeEnc_copy2.offs <= 1275); - silk_memcpy(psRangeEnc->buf, ec_buf_copy, sRangeEnc_copy2.offs); - silk_memcpy(&psEnc->sCmn.sNSQ, &sNSQ_copy2, sizeof(silk_nsq_state)); - psEnc->sShape.LastGainIndex = LastGainIndex_copy2; - } - break; - } - - if (nBits > maxBits) { - if (found_lower == 0 && iter >= 2) { - /* Adjust the quantizer's rate/distortion tradeoff and discard previous "upper" results */ - sEncCtrl.Lambda_Q10 = silk_ADD_RSHIFT32(sEncCtrl.Lambda_Q10, sEncCtrl.Lambda_Q10, 1); - found_upper = 0; - gainsID_upper = -1; - } else { - found_upper = 1; - nBits_upper = nBits; - gainMult_upper = gainMult_Q8; - gainsID_upper = gainsID; - } - } else if (nBits < maxBits - 5) { - found_lower = 1; - nBits_lower = nBits; - gainMult_lower = gainMult_Q8; - if (gainsID != gainsID_lower) { - gainsID_lower = gainsID; - /* Copy part of the output state */ - silk_memcpy(&sRangeEnc_copy2, psRangeEnc, sizeof(ec_enc)); - celt_assert(psRangeEnc->offs <= 1275); - silk_memcpy(ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs); - silk_memcpy(&sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof(silk_nsq_state)); - LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; - } - } else { - /* Within 5 bits of budget: close enough */ - break; - } - - if (!found_lower && nBits > maxBits) { - int j; - for (i = 0; i < psEnc->sCmn.nb_subfr; i++) { - int sum = 0; - for (j = i * psEnc->sCmn.subfr_length; j < (i + 1)*psEnc->sCmn.subfr_length; j++) { - sum += abs(psEnc->sCmn.pulses[j]); - } - if (iter == 0 || (sum < best_sum[i] && !gain_lock[i])) { - best_sum[i] = sum; - best_gain_mult[i] = gainMult_Q8; - } else { - gain_lock[i] = 1; - } - } - } - if ((found_lower & found_upper) == 0) { - /* Adjust gain according to high-rate rate/distortion curve */ - if (nBits > maxBits) { - if (gainMult_Q8 < 16384) { - gainMult_Q8 *= 2; - } else { - gainMult_Q8 = 32767; - } - } else { - opus_int32 gain_factor_Q16; - gain_factor_Q16 = silk_log2lin(silk_LSHIFT(nBits - maxBits, 7) / psEnc->sCmn.frame_length + SILK_FIX_CONST(16, 7)); - gainMult_Q8 = silk_SMULWB(gain_factor_Q16, gainMult_Q8); - } - - } else { - /* Adjust gain by interpolating */ - gainMult_Q8 = gainMult_lower + silk_DIV32_16(silk_MUL(gainMult_upper - gainMult_lower, maxBits - nBits_lower), nBits_upper - nBits_lower); - /* New gain multplier must be between 25% and 75% of old range (note that gainMult_upper < gainMult_lower) */ - if (gainMult_Q8 > silk_ADD_RSHIFT32(gainMult_lower, gainMult_upper - gainMult_lower, 2)) { - gainMult_Q8 = silk_ADD_RSHIFT32(gainMult_lower, gainMult_upper - gainMult_lower, 2); - } else if (gainMult_Q8 < silk_SUB_RSHIFT32(gainMult_upper, gainMult_upper - gainMult_lower, 2)) { - gainMult_Q8 = silk_SUB_RSHIFT32(gainMult_upper, gainMult_upper - gainMult_lower, 2); - } - } - - for (i = 0; i < psEnc->sCmn.nb_subfr; i++) { - opus_int16 tmp; - if (gain_lock[i]) { - tmp = best_gain_mult[i]; - } else { - tmp = gainMult_Q8; - } - sEncCtrl.Gains_Q16[ i ] = silk_LSHIFT_SAT32(silk_SMULWB(sEncCtrl.GainsUnq_Q16[ i ], tmp), 8); - } - - /* Quantize gains */ - psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; - silk_gains_quant(psEnc->sCmn.indices.GainsIndices, sEncCtrl.Gains_Q16, - &psEnc->sShape.LastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr); - - /* Unique identifier of gains vector */ - gainsID = silk_gains_ID(psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr); - } - } - - /* Update input buffer */ - silk_memmove(psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], - (psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz) * sizeof(opus_int16)); - - /* Exit without entropy coding */ - if (psEnc->sCmn.prefillFlag) { - /* No payload */ - *pnBytesOut = 0; - RESTORE_STACK; - return ret; - } - - /* Parameters needed for next frame */ - psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; - psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType; - - /****************************************/ - /* Finalize payload */ - /****************************************/ - psEnc->sCmn.first_frame_after_reset = 0; - /* Payload size */ - *pnBytesOut = silk_RSHIFT(ec_tell(psRangeEnc) + 7, 3); - - RESTORE_STACK; - return ret; -} - -/* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate */ -static OPUS_INLINE void silk_LBRR_encode_FIX( - silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ - silk_encoder_control_FIX *psEncCtrl, /* I/O Pointer to Silk FIX encoder control struct */ - const opus_int16 x16[], /* I Input signal */ - opus_int condCoding /* I The type of conditional coding used so far for this frame */ -) { - opus_int32 TempGains_Q16[ MAX_NB_SUBFR ]; - SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFramesEncoded ]; - silk_nsq_state sNSQ_LBRR; - - /*******************************************/ - /* Control use of inband LBRR */ - /*******************************************/ - if (psEnc->sCmn.LBRR_enabled && psEnc->sCmn.speech_activity_Q8 > SILK_FIX_CONST(LBRR_SPEECH_ACTIVITY_THRES, 8)) { - psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesEncoded ] = 1; - - /* Copy noise shaping quantizer state and quantization indices from regular encoding */ - silk_memcpy(&sNSQ_LBRR, &psEnc->sCmn.sNSQ, sizeof(silk_nsq_state)); - silk_memcpy(psIndices_LBRR, &psEnc->sCmn.indices, sizeof(SideInfoIndices)); - - /* Save original gains */ - silk_memcpy(TempGains_Q16, psEncCtrl->Gains_Q16, psEnc->sCmn.nb_subfr * sizeof(opus_int32)); - - if (psEnc->sCmn.nFramesEncoded == 0 || psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesEncoded - 1 ] == 0) { - /* First frame in packet or previous frame not LBRR coded */ - psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex; - - /* Increase Gains to get target LBRR rate */ - psIndices_LBRR->GainsIndices[ 0 ] = psIndices_LBRR->GainsIndices[ 0 ] + psEnc->sCmn.LBRR_GainIncreases; - psIndices_LBRR->GainsIndices[ 0 ] = silk_min_int(psIndices_LBRR->GainsIndices[ 0 ], N_LEVELS_QGAIN - 1); - } - - /* Decode to get gains in sync with decoder */ - /* Overwrite unquantized gains with quantized gains */ - silk_gains_dequant(psEncCtrl->Gains_Q16, psIndices_LBRR->GainsIndices, - &psEnc->sCmn.LBRRprevLastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr); - - /*****************************************/ - /* Noise shaping quantization */ - /*****************************************/ - if (psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0) { - silk_NSQ_del_dec(&psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, x16, - psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, - psEncCtrl->AR_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, - psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch); - } else { - silk_NSQ(&psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, x16, - psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, - psEncCtrl->AR_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, - psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch); - } - - /* Restore original gains */ - silk_memcpy(psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr * sizeof(opus_int32)); - } -} -#endif diff --git a/src/libopus/silk/fixed/encode_frame_FIX.lo b/src/libopus/silk/fixed/encode_frame_FIX.lo deleted file mode 100644 index 1c4a00a..0000000 --- a/src/libopus/silk/fixed/encode_frame_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/encode_frame_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/encode_frame_FIX.o' - -# Name of the non-PIC object -non_pic_object='encode_frame_FIX.o' - diff --git a/src/libopus/silk/fixed/encode_frame_FIX.o b/src/libopus/silk/fixed/encode_frame_FIX.o deleted file mode 100644 index d9ef799f3c70aa28a6f42284a50be189b5dd0c06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 51152 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 diff --git a/src/libopus/silk/fixed/entdec.h b/src/libopus/silk/fixed/entdec.h new file mode 100644 index 0000000..d3c6484 --- /dev/null +++ b/src/libopus/silk/fixed/entdec.h @@ -0,0 +1 @@ +#include "../../celt/entdec.h" diff --git a/src/libopus/silk/fixed/entenc.h b/src/libopus/silk/fixed/entenc.h new file mode 100644 index 0000000..13312cd --- /dev/null +++ b/src/libopus/silk/fixed/entenc.h @@ -0,0 +1 @@ +#include "../../celt/entenc.h" diff --git a/src/libopus/silk/fixed/find_LPC_FIX.c b/src/libopus/silk/fixed/find_LPC_FIX.c index 168b9ae..e54940d 100644 --- a/src/libopus/silk/fixed/find_LPC_FIX.c +++ b/src/libopus/silk/fixed/find_LPC_FIX.c @@ -1,37 +1,37 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" -#include "../../celt/stack_alloc.h" -#include "../tuning_parameters.h" +#include "stack_alloc.h" +#include "tuning_parameters.h" /* Finds LPC vector from correlations, and converts to NLSF */ void silk_find_LPC_FIX( @@ -39,7 +39,8 @@ void silk_find_LPC_FIX( opus_int16 NLSF_Q15[], /* O NLSFs */ const opus_int16 x[], /* I Input signal */ const opus_int32 minInvGain_Q30 /* I Inverse of max prediction gain */ -) { +) +{ opus_int k, subfr_length; opus_int32 a_Q16[ MAX_LPC_ORDER ]; opus_int isInterpLower, shift; @@ -59,68 +60,68 @@ void silk_find_LPC_FIX( psEncC->indices.NLSFInterpCoef_Q2 = 4; /* Burg AR analysis for the full frame */ - silk_burg_modified(&res_nrg, &res_nrg_Q, a_Q16, x, minInvGain_Q30, subfr_length, psEncC->nb_subfr, psEncC->predictLPCOrder, psEncC->arch); + silk_burg_modified( &res_nrg, &res_nrg_Q, a_Q16, x, minInvGain_Q30, subfr_length, psEncC->nb_subfr, psEncC->predictLPCOrder, psEncC->arch ); - if (psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR) { - VARDECL(opus_int16, LPC_res); + if( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) { + VARDECL( opus_int16, LPC_res ); /* Optimal solution for last 10 ms */ - silk_burg_modified(&res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + 2 * subfr_length, minInvGain_Q30, subfr_length, 2, psEncC->predictLPCOrder, psEncC->arch); + silk_burg_modified( &res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + 2 * subfr_length, minInvGain_Q30, subfr_length, 2, psEncC->predictLPCOrder, psEncC->arch ); /* subtract residual energy here, as that's easier than adding it to the */ /* residual energy of the first 10 ms in each iteration of the search below */ shift = res_tmp_nrg_Q - res_nrg_Q; - if (shift >= 0) { - if (shift < 32) { - res_nrg = res_nrg - silk_RSHIFT(res_tmp_nrg, shift); + if( shift >= 0 ) { + if( shift < 32 ) { + res_nrg = res_nrg - silk_RSHIFT( res_tmp_nrg, shift ); } } else { - silk_assert(shift > -32); - res_nrg = silk_RSHIFT(res_nrg, -shift) - res_tmp_nrg; + silk_assert( shift > -32 ); + res_nrg = silk_RSHIFT( res_nrg, -shift ) - res_tmp_nrg; res_nrg_Q = res_tmp_nrg_Q; } /* Convert to NLSFs */ - silk_A2NLSF(NLSF_Q15, a_tmp_Q16, psEncC->predictLPCOrder); + silk_A2NLSF( NLSF_Q15, a_tmp_Q16, psEncC->predictLPCOrder ); - ALLOC(LPC_res, 2 * subfr_length, opus_int16); + ALLOC( LPC_res, 2 * subfr_length, opus_int16 ); /* Search over interpolation indices to find the one with lowest residual energy */ - for (k = 3; k >= 0; k--) { + for( k = 3; k >= 0; k-- ) { /* Interpolate NLSFs for first half */ - silk_interpolate(NLSF0_Q15, psEncC->prev_NLSFq_Q15, NLSF_Q15, k, psEncC->predictLPCOrder); + silk_interpolate( NLSF0_Q15, psEncC->prev_NLSFq_Q15, NLSF_Q15, k, psEncC->predictLPCOrder ); /* Convert to LPC for residual energy evaluation */ - silk_NLSF2A(a_tmp_Q12, NLSF0_Q15, psEncC->predictLPCOrder, psEncC->arch); + silk_NLSF2A( a_tmp_Q12, NLSF0_Q15, psEncC->predictLPCOrder, psEncC->arch ); /* Calculate residual energy with NLSF interpolation */ - silk_LPC_analysis_filter(LPC_res, x, a_tmp_Q12, 2 * subfr_length, psEncC->predictLPCOrder, psEncC->arch); + silk_LPC_analysis_filter( LPC_res, x, a_tmp_Q12, 2 * subfr_length, psEncC->predictLPCOrder, psEncC->arch ); - silk_sum_sqr_shift(&res_nrg0, &rshift0, LPC_res + psEncC->predictLPCOrder, subfr_length - psEncC->predictLPCOrder); - silk_sum_sqr_shift(&res_nrg1, &rshift1, LPC_res + psEncC->predictLPCOrder + subfr_length, subfr_length - psEncC->predictLPCOrder); + silk_sum_sqr_shift( &res_nrg0, &rshift0, LPC_res + psEncC->predictLPCOrder, subfr_length - psEncC->predictLPCOrder ); + silk_sum_sqr_shift( &res_nrg1, &rshift1, LPC_res + psEncC->predictLPCOrder + subfr_length, subfr_length - psEncC->predictLPCOrder ); /* Add subframe energies from first half frame */ shift = rshift0 - rshift1; - if (shift >= 0) { - res_nrg1 = silk_RSHIFT(res_nrg1, shift); + if( shift >= 0 ) { + res_nrg1 = silk_RSHIFT( res_nrg1, shift ); res_nrg_interp_Q = -rshift0; } else { - res_nrg0 = silk_RSHIFT(res_nrg0, -shift); + res_nrg0 = silk_RSHIFT( res_nrg0, -shift ); res_nrg_interp_Q = -rshift1; } - res_nrg_interp = silk_ADD32(res_nrg0, res_nrg1); + res_nrg_interp = silk_ADD32( res_nrg0, res_nrg1 ); /* Compare with first half energy without NLSF interpolation, or best interpolated value so far */ shift = res_nrg_interp_Q - res_nrg_Q; - if (shift >= 0) { - if (silk_RSHIFT(res_nrg_interp, shift) < res_nrg) { + if( shift >= 0 ) { + if( silk_RSHIFT( res_nrg_interp, shift ) < res_nrg ) { isInterpLower = silk_TRUE; } else { isInterpLower = silk_FALSE; } } else { - if (-shift < 32) { - if (res_nrg_interp < silk_RSHIFT(res_nrg, -shift)) { + if( -shift < 32 ) { + if( res_nrg_interp < silk_RSHIFT( res_nrg, -shift ) ) { isInterpLower = silk_TRUE; } else { isInterpLower = silk_FALSE; @@ -131,7 +132,7 @@ void silk_find_LPC_FIX( } /* Determine whether current interpolated NLSFs are best so far */ - if (isInterpLower == silk_TRUE) { + if( isInterpLower == silk_TRUE ) { /* Interpolation has lower residual energy */ res_nrg = res_nrg_interp; res_nrg_Q = res_nrg_interp_Q; @@ -140,11 +141,11 @@ void silk_find_LPC_FIX( } } - if (psEncC->indices.NLSFInterpCoef_Q2 == 4) { + if( psEncC->indices.NLSFInterpCoef_Q2 == 4 ) { /* NLSF interpolation is currently inactive, calculate NLSFs from full frame AR coefficients */ - silk_A2NLSF(NLSF_Q15, a_Q16, psEncC->predictLPCOrder); + silk_A2NLSF( NLSF_Q15, a_Q16, psEncC->predictLPCOrder ); } - celt_assert(psEncC->indices.NLSFInterpCoef_Q2 == 4 || (psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR)); + celt_assert( psEncC->indices.NLSFInterpCoef_Q2 == 4 || ( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) ); RESTORE_STACK; } diff --git a/src/libopus/silk/fixed/find_LPC_FIX.lo b/src/libopus/silk/fixed/find_LPC_FIX.lo deleted file mode 100644 index f668a4f..0000000 --- a/src/libopus/silk/fixed/find_LPC_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/find_LPC_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/find_LPC_FIX.o' - -# Name of the non-PIC object -non_pic_object='find_LPC_FIX.o' - diff --git a/src/libopus/silk/fixed/find_LPC_FIX.o b/src/libopus/silk/fixed/find_LPC_FIX.o deleted file mode 100644 index d55f49ef3e851e6fd89f01f1d5091559eb070ff0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25216 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 diff --git a/src/libopus/silk/fixed/find_LTP_FIX.c b/src/libopus/silk/fixed/find_LTP_FIX.c index 740c730..70961b0 100644 --- a/src/libopus/silk/fixed/find_LTP_FIX.c +++ b/src/libopus/silk/fixed/find_LTP_FIX.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" -#include "../tuning_parameters.h" +#include "tuning_parameters.h" void silk_find_LTP_FIX( opus_int32 XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Correlation matrix */ @@ -40,7 +40,8 @@ void silk_find_LTP_FIX( const opus_int subfr_length, /* I Subframe length */ const opus_int nb_subfr, /* I Number of subframes */ int arch /* I Run-time architecture */ -) { +) +{ opus_int i, k, extra_shifts; opus_int xx_shifts, xX_shifts, XX_shifts; const opus_int16 *lag_ptr; @@ -49,48 +50,48 @@ void silk_find_LTP_FIX( xXLTP_Q17_ptr = xXLTP_Q17; XXLTP_Q17_ptr = XXLTP_Q17; - for (k = 0; k < nb_subfr; k++) { - lag_ptr = r_ptr - (lag[ k ] + LTP_ORDER / 2); + for( k = 0; k < nb_subfr; k++ ) { + lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); - silk_sum_sqr_shift(&xx, &xx_shifts, r_ptr, subfr_length + LTP_ORDER); /* xx in Q( -xx_shifts ) */ - silk_corrMatrix_FIX(lag_ptr, subfr_length, LTP_ORDER, XXLTP_Q17_ptr, &nrg, &XX_shifts, arch); /* XXLTP_Q17_ptr and nrg in Q( -XX_shifts ) */ + silk_sum_sqr_shift( &xx, &xx_shifts, r_ptr, subfr_length + LTP_ORDER ); /* xx in Q( -xx_shifts ) */ + silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, XXLTP_Q17_ptr, &nrg, &XX_shifts, arch ); /* XXLTP_Q17_ptr and nrg in Q( -XX_shifts ) */ extra_shifts = xx_shifts - XX_shifts; - if (extra_shifts > 0) { + if( extra_shifts > 0 ) { /* Shift XX */ xX_shifts = xx_shifts; - for (i = 0; i < LTP_ORDER * LTP_ORDER; i++) { - XXLTP_Q17_ptr[ i ] = silk_RSHIFT32(XXLTP_Q17_ptr[ i ], extra_shifts); /* Q( -xX_shifts ) */ + for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { + XXLTP_Q17_ptr[ i ] = silk_RSHIFT32( XXLTP_Q17_ptr[ i ], extra_shifts ); /* Q( -xX_shifts ) */ } - nrg = silk_RSHIFT32(nrg, extra_shifts); /* Q( -xX_shifts ) */ - } else if (extra_shifts < 0) { + nrg = silk_RSHIFT32( nrg, extra_shifts ); /* Q( -xX_shifts ) */ + } else if( extra_shifts < 0 ) { /* Shift xx */ xX_shifts = XX_shifts; - xx = silk_RSHIFT32(xx, -extra_shifts); /* Q( -xX_shifts ) */ + xx = silk_RSHIFT32( xx, -extra_shifts ); /* Q( -xX_shifts ) */ } else { xX_shifts = xx_shifts; } - silk_corrVector_FIX(lag_ptr, r_ptr, subfr_length, LTP_ORDER, xXLTP_Q17_ptr, xX_shifts, arch); /* xXLTP_Q17_ptr in Q( -xX_shifts ) */ + silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, xXLTP_Q17_ptr, xX_shifts, arch ); /* xXLTP_Q17_ptr in Q( -xX_shifts ) */ /* At this point all correlations are in Q(-xX_shifts) */ - temp = silk_SMLAWB(1, nrg, SILK_FIX_CONST(LTP_CORR_INV_MAX, 16)); - temp = silk_max(temp, xx); - TIC(div) + temp = silk_SMLAWB( 1, nrg, SILK_FIX_CONST( LTP_CORR_INV_MAX, 16 ) ); + temp = silk_max( temp, xx ); +TIC(div) #if 0 - for (i = 0; i < LTP_ORDER * LTP_ORDER; i++) { - XXLTP_Q17_ptr[ i ] = silk_DIV32_varQ(XXLTP_Q17_ptr[ i ], temp, 17); + for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { + XXLTP_Q17_ptr[ i ] = silk_DIV32_varQ( XXLTP_Q17_ptr[ i ], temp, 17 ); } - for (i = 0; i < LTP_ORDER; i++) { - xXLTP_Q17_ptr[ i ] = silk_DIV32_varQ(xXLTP_Q17_ptr[ i ], temp, 17); + for( i = 0; i < LTP_ORDER; i++ ) { + xXLTP_Q17_ptr[ i ] = silk_DIV32_varQ( xXLTP_Q17_ptr[ i ], temp, 17 ); } #else - for (i = 0; i < LTP_ORDER * LTP_ORDER; i++) { - XXLTP_Q17_ptr[ i ] = (opus_int32)(silk_LSHIFT64((opus_int64)XXLTP_Q17_ptr[ i ], 17) / temp); + for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { + XXLTP_Q17_ptr[ i ] = (opus_int32)( silk_LSHIFT64( (opus_int64)XXLTP_Q17_ptr[ i ], 17 ) / temp ); } - for (i = 0; i < LTP_ORDER; i++) { - xXLTP_Q17_ptr[ i ] = (opus_int32)(silk_LSHIFT64((opus_int64)xXLTP_Q17_ptr[ i ], 17) / temp); + for( i = 0; i < LTP_ORDER; i++ ) { + xXLTP_Q17_ptr[ i ] = (opus_int32)( silk_LSHIFT64( (opus_int64)xXLTP_Q17_ptr[ i ], 17 ) / temp ); } #endif - TOC(div) +TOC(div) r_ptr += subfr_length; XXLTP_Q17_ptr += LTP_ORDER * LTP_ORDER; xXLTP_Q17_ptr += LTP_ORDER; diff --git a/src/libopus/silk/fixed/find_LTP_FIX.lo b/src/libopus/silk/fixed/find_LTP_FIX.lo deleted file mode 100644 index 9bf636a..0000000 --- a/src/libopus/silk/fixed/find_LTP_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/find_LTP_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/find_LTP_FIX.o' - -# Name of the non-PIC object -non_pic_object='find_LTP_FIX.o' - diff --git a/src/libopus/silk/fixed/find_LTP_FIX.o b/src/libopus/silk/fixed/find_LTP_FIX.o deleted file mode 100644 index c81c0f688228bdf22ba75a90c07d22a7402d57d5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15008 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 diff --git a/src/libopus/silk/fixed/find_pitch_lags_FIX.c b/src/libopus/silk/fixed/find_pitch_lags_FIX.c deleted file mode 100644 index 146a26c..0000000 --- a/src/libopus/silk/fixed/find_pitch_lags_FIX.c +++ /dev/null @@ -1,141 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif - -#include "main_FIX.h" -#include "../../celt/stack_alloc.h" -#include "../tuning_parameters.h" - -/* Find pitch lags */ -void silk_find_pitch_lags_FIX( - silk_encoder_state_FIX *psEnc, /* I/O encoder state */ - silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ - opus_int16 res[], /* O residual */ - const opus_int16 x[], /* I Speech signal */ - int arch /* I Run-time architecture */ -) { - opus_int buf_len, i, scale; - opus_int32 thrhld_Q13, res_nrg; - const opus_int16 *x_ptr; - VARDECL(opus_int16, Wsig); - opus_int16 *Wsig_ptr; - opus_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ]; - opus_int16 rc_Q15[ MAX_FIND_PITCH_LPC_ORDER ]; - opus_int32 A_Q24[ MAX_FIND_PITCH_LPC_ORDER ]; - opus_int16 A_Q12[ MAX_FIND_PITCH_LPC_ORDER ]; - SAVE_STACK; - - /******************************************/ - /* Set up buffer lengths etc based on Fs */ - /******************************************/ - buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length; - - /* Safety check */ - celt_assert(buf_len >= psEnc->sCmn.pitch_LPC_win_length); - - /*************************************/ - /* Estimate LPC AR coefficients */ - /*************************************/ - - /* Calculate windowed signal */ - - ALLOC(Wsig, psEnc->sCmn.pitch_LPC_win_length, opus_int16); - - /* First LA_LTP samples */ - x_ptr = x + buf_len - psEnc->sCmn.pitch_LPC_win_length; - Wsig_ptr = Wsig; - silk_apply_sine_window(Wsig_ptr, x_ptr, 1, psEnc->sCmn.la_pitch); - - /* Middle un - windowed samples */ - Wsig_ptr += psEnc->sCmn.la_pitch; - x_ptr += psEnc->sCmn.la_pitch; - silk_memcpy(Wsig_ptr, x_ptr, (psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT(psEnc->sCmn.la_pitch, 1)) * sizeof(opus_int16)); - - /* Last LA_LTP samples */ - Wsig_ptr += psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT(psEnc->sCmn.la_pitch, 1); - x_ptr += psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT(psEnc->sCmn.la_pitch, 1); - silk_apply_sine_window(Wsig_ptr, x_ptr, 2, psEnc->sCmn.la_pitch); - - /* Calculate autocorrelation sequence */ - silk_autocorr(auto_corr, &scale, Wsig, psEnc->sCmn.pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1, arch); - - /* Add white noise, as fraction of energy */ - auto_corr[ 0 ] = silk_SMLAWB(auto_corr[ 0 ], auto_corr[ 0 ], SILK_FIX_CONST(FIND_PITCH_WHITE_NOISE_FRACTION, 16)) + 1; - - /* Calculate the reflection coefficients using schur */ - res_nrg = silk_schur(rc_Q15, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder); - - /* Prediction gain */ - psEncCtrl->predGain_Q16 = silk_DIV32_varQ(auto_corr[ 0 ], silk_max_int(res_nrg, 1), 16); - - /* Convert reflection coefficients to prediction coefficients */ - silk_k2a(A_Q24, rc_Q15, psEnc->sCmn.pitchEstimationLPCOrder); - - /* Convert From 32 bit Q24 to 16 bit Q12 coefs */ - for (i = 0; i < psEnc->sCmn.pitchEstimationLPCOrder; i++) { - A_Q12[ i ] = (opus_int16)silk_SAT16(silk_RSHIFT(A_Q24[ i ], 12)); - } - - /* Do BWE */ - silk_bwexpander(A_Q12, psEnc->sCmn.pitchEstimationLPCOrder, SILK_FIX_CONST(FIND_PITCH_BANDWIDTH_EXPANSION, 16)); - - /*****************************************/ - /* LPC analysis filtering */ - /*****************************************/ - silk_LPC_analysis_filter(res, x, A_Q12, buf_len, psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.arch); - - if (psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY && psEnc->sCmn.first_frame_after_reset == 0) { - /* Threshold for pitch estimator */ - thrhld_Q13 = SILK_FIX_CONST(0.6, 13); - thrhld_Q13 = silk_SMLABB(thrhld_Q13, SILK_FIX_CONST(-0.004, 13), psEnc->sCmn.pitchEstimationLPCOrder); - thrhld_Q13 = silk_SMLAWB(thrhld_Q13, SILK_FIX_CONST(-0.1, 21), psEnc->sCmn.speech_activity_Q8); - thrhld_Q13 = silk_SMLABB(thrhld_Q13, SILK_FIX_CONST(-0.15, 13), silk_RSHIFT(psEnc->sCmn.prevSignalType, 1)); - thrhld_Q13 = silk_SMLAWB(thrhld_Q13, SILK_FIX_CONST(-0.1, 14), psEnc->sCmn.input_tilt_Q15); - thrhld_Q13 = silk_SAT16(thrhld_Q13); - - /*****************************************/ - /* Call pitch estimator */ - /*****************************************/ - if (silk_pitch_analysis_core(res, psEncCtrl->pitchL, &psEnc->sCmn.indices.lagIndex, &psEnc->sCmn.indices.contourIndex, - &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16, - (opus_int)thrhld_Q13, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr, - psEnc->sCmn.arch) == 0) { - psEnc->sCmn.indices.signalType = TYPE_VOICED; - } else { - psEnc->sCmn.indices.signalType = TYPE_UNVOICED; - } - } else { - silk_memset(psEncCtrl->pitchL, 0, sizeof(psEncCtrl->pitchL)); - psEnc->sCmn.indices.lagIndex = 0; - psEnc->sCmn.indices.contourIndex = 0; - psEnc->LTPCorr_Q15 = 0; - } - RESTORE_STACK; -} diff --git a/src/libopus/silk/fixed/find_pitch_lags_FIX.lo b/src/libopus/silk/fixed/find_pitch_lags_FIX.lo deleted file mode 100644 index 227482c..0000000 --- a/src/libopus/silk/fixed/find_pitch_lags_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/find_pitch_lags_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/find_pitch_lags_FIX.o' - -# Name of the non-PIC object -non_pic_object='find_pitch_lags_FIX.o' - diff --git a/src/libopus/silk/fixed/find_pitch_lags_FIX.o b/src/libopus/silk/fixed/find_pitch_lags_FIX.o deleted file mode 100644 index 9d37442e0e23060415612f51ff9e4bad7710560c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30744 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 z 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 6; - for (i = 0; i < psEnc->sCmn.nb_subfr; i++) { - min_gain_Q16 = silk_min(min_gain_Q16, psEncCtrl->Gains_Q16[ i ]); + for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + min_gain_Q16 = silk_min( min_gain_Q16, psEncCtrl->Gains_Q16[ i ] ); } - for (i = 0; i < psEnc->sCmn.nb_subfr; i++) { + for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { /* Divide to Q16 */ - silk_assert(psEncCtrl->Gains_Q16[ i ] > 0); + silk_assert( psEncCtrl->Gains_Q16[ i ] > 0 ); /* Invert and normalize gains, and ensure that maximum invGains_Q16 is within range of a 16 bit int */ - invGains_Q16[ i ] = silk_DIV32_varQ(min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2); + invGains_Q16[ i ] = silk_DIV32_varQ( min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2 ); /* Limit inverse */ - invGains_Q16[ i ] = silk_max(invGains_Q16[ i ], 100); + invGains_Q16[ i ] = silk_max( invGains_Q16[ i ], 100 ); /* Square the inverted gains */ - silk_assert(invGains_Q16[ i ] == silk_SAT16(invGains_Q16[ i ])); + silk_assert( invGains_Q16[ i ] == silk_SAT16( invGains_Q16[ i ] ) ); /* Invert the inverted and normalized gains */ - local_gains[ i ] = silk_DIV32(((opus_int32)1 << 16), invGains_Q16[ i ]); + local_gains[ i ] = silk_DIV32( ( (opus_int32)1 << 16 ), invGains_Q16[ i ] ); } - ALLOC(LPC_in_pre, - psEnc->sCmn.nb_subfr * psEnc->sCmn.predictLPCOrder - + psEnc->sCmn.frame_length, opus_int16); - if (psEnc->sCmn.indices.signalType == TYPE_VOICED) { - VARDECL(opus_int32, xXLTP_Q17); - VARDECL(opus_int32, XXLTP_Q17); + ALLOC( LPC_in_pre, + psEnc->sCmn.nb_subfr * psEnc->sCmn.predictLPCOrder + + psEnc->sCmn.frame_length, opus_int16 ); + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { + VARDECL( opus_int32, xXLTP_Q17 ); + VARDECL( opus_int32, XXLTP_Q17 ); /**********/ /* VOICED */ /**********/ - celt_assert(psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2); + celt_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 ); - ALLOC(xXLTP_Q17, psEnc->sCmn.nb_subfr * LTP_ORDER, opus_int32); - ALLOC(XXLTP_Q17, psEnc->sCmn.nb_subfr * LTP_ORDER * LTP_ORDER, opus_int32); + ALLOC( xXLTP_Q17, psEnc->sCmn.nb_subfr * LTP_ORDER, opus_int32 ); + ALLOC( XXLTP_Q17, psEnc->sCmn.nb_subfr * LTP_ORDER * LTP_ORDER, opus_int32 ); /* LTP analysis */ - silk_find_LTP_FIX(XXLTP_Q17, xXLTP_Q17, res_pitch, - psEncCtrl->pitchL, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch); + silk_find_LTP_FIX( XXLTP_Q17, xXLTP_Q17, res_pitch, + psEncCtrl->pitchL, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch ); /* Quantize LTP gain parameters */ - silk_quant_LTP_gains(psEncCtrl->LTPCoef_Q14, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex, - &psEnc->sCmn.sum_log_gain_Q7, &psEncCtrl->LTPredCodGain_Q7, XXLTP_Q17, xXLTP_Q17, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch); + silk_quant_LTP_gains( psEncCtrl->LTPCoef_Q14, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex, + &psEnc->sCmn.sum_log_gain_Q7, &psEncCtrl->LTPredCodGain_Q7, XXLTP_Q17, xXLTP_Q17, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch ); /* Control LTP scaling */ - silk_LTP_scale_ctrl_FIX(psEnc, psEncCtrl, condCoding); + silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl, condCoding ); /* Create LTP residual */ - silk_LTP_analysis_filter_FIX(LPC_in_pre, x - psEnc->sCmn.predictLPCOrder, psEncCtrl->LTPCoef_Q14, - psEncCtrl->pitchL, invGains_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder); + silk_LTP_analysis_filter_FIX( LPC_in_pre, x - psEnc->sCmn.predictLPCOrder, psEncCtrl->LTPCoef_Q14, + psEncCtrl->pitchL, invGains_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); } else { /************/ @@ -106,39 +108,39 @@ void silk_find_pred_coefs_FIX( /* Create signal with prepended subframes, scaled by inverse gains */ x_ptr = x - psEnc->sCmn.predictLPCOrder; x_pre_ptr = LPC_in_pre; - for (i = 0; i < psEnc->sCmn.nb_subfr; i++) { - silk_scale_copy_vector16(x_pre_ptr, x_ptr, invGains_Q16[ i ], - psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder); + for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + silk_scale_copy_vector16( x_pre_ptr, x_ptr, invGains_Q16[ i ], + psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder ); x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder; x_ptr += psEnc->sCmn.subfr_length; } - silk_memset(psEncCtrl->LTPCoef_Q14, 0, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof(opus_int16)); + silk_memset( psEncCtrl->LTPCoef_Q14, 0, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( opus_int16 ) ); psEncCtrl->LTPredCodGain_Q7 = 0; psEnc->sCmn.sum_log_gain_Q7 = 0; } /* Limit on total predictive coding gain */ - if (psEnc->sCmn.first_frame_after_reset) { - minInvGain_Q30 = SILK_FIX_CONST(1.0f / MAX_PREDICTION_POWER_GAIN_AFTER_RESET, 30); + if( psEnc->sCmn.first_frame_after_reset ) { + minInvGain_Q30 = SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN_AFTER_RESET, 30 ); } else { - minInvGain_Q30 = silk_log2lin(silk_SMLAWB(16 << 7, (opus_int32)psEncCtrl->LTPredCodGain_Q7, SILK_FIX_CONST(1.0 / 3, 16))); /* Q16 */ - minInvGain_Q30 = silk_DIV32_varQ(minInvGain_Q30, - silk_SMULWW(SILK_FIX_CONST(MAX_PREDICTION_POWER_GAIN, 0), - silk_SMLAWB(SILK_FIX_CONST(0.25, 18), SILK_FIX_CONST(0.75, 18), psEncCtrl->coding_quality_Q14)), 14); + minInvGain_Q30 = silk_log2lin( silk_SMLAWB( 16 << 7, (opus_int32)psEncCtrl->LTPredCodGain_Q7, SILK_FIX_CONST( 1.0 / 3, 16 ) ) ); /* Q16 */ + minInvGain_Q30 = silk_DIV32_varQ( minInvGain_Q30, + silk_SMULWW( SILK_FIX_CONST( MAX_PREDICTION_POWER_GAIN, 0 ), + silk_SMLAWB( SILK_FIX_CONST( 0.25, 18 ), SILK_FIX_CONST( 0.75, 18 ), psEncCtrl->coding_quality_Q14 ) ), 14 ); } /* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */ - silk_find_LPC_FIX(&psEnc->sCmn, NLSF_Q15, LPC_in_pre, minInvGain_Q30); + silk_find_LPC_FIX( &psEnc->sCmn, NLSF_Q15, LPC_in_pre, minInvGain_Q30 ); /* Quantize LSFs */ - silk_process_NLSFs(&psEnc->sCmn, psEncCtrl->PredCoef_Q12, NLSF_Q15, psEnc->sCmn.prev_NLSFq_Q15); + silk_process_NLSFs( &psEnc->sCmn, psEncCtrl->PredCoef_Q12, NLSF_Q15, psEnc->sCmn.prev_NLSFq_Q15 ); /* Calculate residual energy using quantized LPC coefficients */ - silk_residual_energy_FIX(psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains, - psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder, psEnc->sCmn.arch); + silk_residual_energy_FIX( psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains, + psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder, psEnc->sCmn.arch ); /* Copy to prediction struct for use in next frame for interpolation */ - silk_memcpy(psEnc->sCmn.prev_NLSFq_Q15, NLSF_Q15, sizeof(psEnc->sCmn.prev_NLSFq_Q15)); + silk_memcpy( psEnc->sCmn.prev_NLSFq_Q15, NLSF_Q15, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) ); RESTORE_STACK; } diff --git a/src/libopus/silk/fixed/find_pred_coefs_FIX.lo b/src/libopus/silk/fixed/find_pred_coefs_FIX.lo deleted file mode 100644 index 330842e..0000000 --- a/src/libopus/silk/fixed/find_pred_coefs_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/find_pred_coefs_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/find_pred_coefs_FIX.o' - -# Name of the non-PIC object -non_pic_object='find_pred_coefs_FIX.o' - diff --git a/src/libopus/silk/fixed/find_pred_coefs_FIX.o b/src/libopus/silk/fixed/find_pred_coefs_FIX.o deleted file mode 100644 index e3e2d06151ba8da0048af7e17431e2a3c84ace08..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 33464 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 1; n++) { + for( n = 0; n < (k + 1) >> 1; n++ ) { tmp1 = A_Q24[ n ]; tmp2 = A_Q24[ k - n - 1 ]; - A_Q24[ n ] = silk_SMLAWB(tmp1, silk_LSHIFT(tmp2, 1), rc); - A_Q24[ k - n - 1 ] = silk_SMLAWB(tmp2, silk_LSHIFT(tmp1, 1), rc); + A_Q24[ n ] = silk_SMLAWB( tmp1, silk_LSHIFT( tmp2, 1 ), rc ); + A_Q24[ k - n - 1 ] = silk_SMLAWB( tmp2, silk_LSHIFT( tmp1, 1 ), rc ); } - A_Q24[ k ] = -silk_LSHIFT((opus_int32)rc_Q15[ k ], 9); + A_Q24[ k ] = -silk_LSHIFT( (opus_int32)rc_Q15[ k ], 9 ); } } diff --git a/src/libopus/silk/fixed/k2a_FIX.lo b/src/libopus/silk/fixed/k2a_FIX.lo deleted file mode 100644 index 7a39cd6..0000000 --- a/src/libopus/silk/fixed/k2a_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/k2a_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/k2a_FIX.o' - -# Name of the non-PIC object -non_pic_object='k2a_FIX.o' - diff --git a/src/libopus/silk/fixed/k2a_FIX.o b/src/libopus/silk/fixed/k2a_FIX.o deleted file mode 100644 index b3c43fc3fb910a72a09bdab684f635b35db5d93e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7632 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 Jy>C9r{y)ggOmzSN diff --git a/src/libopus/silk/fixed/k2a_Q16_FIX.c b/src/libopus/silk/fixed/k2a_Q16_FIX.c index 60e1fb8..dbb6f0e 100644 --- a/src/libopus/silk/fixed/k2a_Q16_FIX.c +++ b/src/libopus/silk/fixed/k2a_Q16_FIX.c @@ -1,53 +1,54 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif -#include "../SigProc_FIX.h" +#include "SigProc_FIX.h" /* Step up function, converts reflection coefficients to prediction coefficients */ void silk_k2a_Q16( opus_int32 *A_Q24, /* O Prediction coefficients [order] Q24 */ const opus_int32 *rc_Q16, /* I Reflection coefficients [order] Q16 */ const opus_int32 order /* I Prediction order */ -) { +) +{ opus_int k, n; opus_int32 rc, tmp1, tmp2; - for (k = 0; k < order; k++) { + for( k = 0; k < order; k++ ) { rc = rc_Q16[ k ]; - for (n = 0; n < (k + 1) >> 1; n++) { + for( n = 0; n < (k + 1) >> 1; n++ ) { tmp1 = A_Q24[ n ]; tmp2 = A_Q24[ k - n - 1 ]; - A_Q24[ n ] = silk_SMLAWW(tmp1, tmp2, rc); - A_Q24[ k - n - 1 ] = silk_SMLAWW(tmp2, tmp1, rc); + A_Q24[ n ] = silk_SMLAWW( tmp1, tmp2, rc ); + A_Q24[ k - n - 1 ] = silk_SMLAWW( tmp2, tmp1, rc ); } - A_Q24[ k ] = -silk_LSHIFT(rc, 8); + A_Q24[ k ] = -silk_LSHIFT( rc, 8 ); } } diff --git a/src/libopus/silk/fixed/k2a_Q16_FIX.lo b/src/libopus/silk/fixed/k2a_Q16_FIX.lo deleted file mode 100644 index 59a6439..0000000 --- a/src/libopus/silk/fixed/k2a_Q16_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/k2a_Q16_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/k2a_Q16_FIX.o' - -# Name of the non-PIC object -non_pic_object='k2a_Q16_FIX.o' - diff --git a/src/libopus/silk/fixed/k2a_Q16_FIX.o b/src/libopus/silk/fixed/k2a_Q16_FIX.o deleted file mode 100644 index 23dfe4e01b963fc9dccdbdd96584f9da01f06c56..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7592 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 U^zq}o&S!sy`u~zLq*}NC5AtwEhX4Qo diff --git a/src/libopus/silk/fixed/main.h b/src/libopus/silk/fixed/main.h new file mode 100644 index 0000000..44f40ec --- /dev/null +++ b/src/libopus/silk/fixed/main.h @@ -0,0 +1 @@ +#include "../main.h" diff --git a/src/libopus/silk/fixed/main_FIX.h b/src/libopus/silk/fixed/main_FIX.h index 2318445..6d2112e 100644 --- a/src/libopus/silk/fixed/main_FIX.h +++ b/src/libopus/silk/fixed/main_FIX.h @@ -1,40 +1,40 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_MAIN_FIX_H #define SILK_MAIN_FIX_H -#include "../SigProc_FIX.h" +#include "SigProc_FIX.h" #include "structs_FIX.h" -#include "../control.h" -#include "../main.h" -#include "../PLC.h" -#include "../debug.h" -#include "../../celt/entenc.h" +#include "control.h" +#include "main.h" +#include "PLC.h" +#include "debug.h" +#include "entenc.h" #if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \ || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) @@ -109,8 +109,8 @@ void silk_noise_shape_analysis_FIX( /* Autocorrelations for a warped frequency axis */ void silk_warped_autocorrelation_FIX_c( - opus_int32 *corr, /* O Result [order + 1] */ - opus_int *scale, /* O Scaling of the correlation vector */ + opus_int32 *corr, /* O Result [order + 1] */ + opus_int *scale, /* O Scaling of the correlation vector */ const opus_int16 *input, /* I Input data to correlate */ const opus_int warping_Q16, /* I Warping coefficient */ const opus_int length, /* I Length of input */ @@ -183,10 +183,10 @@ void silk_LTP_analysis_filter_FIX( /* Calculates residual energies of input subframes where all subframes have LPC_order */ /* of preceding samples */ void silk_residual_energy_FIX( - opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ - opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ + opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ + opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ const opus_int16 x[], /* I Input signal */ - opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ + opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ const opus_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */ const opus_int subfr_length, /* I Subframe length */ const opus_int nb_subfr, /* I Number of subframes */ diff --git a/src/libopus/silk/fixed/noise_shape_analysis_FIX.c b/src/libopus/silk/fixed/noise_shape_analysis_FIX.c deleted file mode 100644 index 79131f3..0000000 --- a/src/libopus/silk/fixed/noise_shape_analysis_FIX.c +++ /dev/null @@ -1,406 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif - -#include "main_FIX.h" -#include "../../celt/stack_alloc.h" -#include "../tuning_parameters.h" - -/* Compute gain to make warped filter coefficients have a zero mean log frequency response on a */ -/* non-warped frequency scale. (So that it can be implemented with a minimum-phase monic filter.) */ -/* Note: A monic filter is one with the first coefficient equal to 1.0. In Silk we omit the first */ -/* coefficient in an array of coefficients, for monic filters. */ -static OPUS_INLINE opus_int32 warped_gain( /* gain in Q16*/ - const opus_int32 *coefs_Q24, - opus_int lambda_Q16, - opus_int order -) { - opus_int i; - opus_int32 gain_Q24; - - lambda_Q16 = -lambda_Q16; - gain_Q24 = coefs_Q24[ order - 1 ]; - for (i = order - 2; i >= 0; i--) { - gain_Q24 = silk_SMLAWB(coefs_Q24[ i ], gain_Q24, lambda_Q16); - } - gain_Q24 = silk_SMLAWB(SILK_FIX_CONST(1.0, 24), gain_Q24, -lambda_Q16); - return silk_INVERSE32_varQ(gain_Q24, 40); -} - -/* Convert warped filter coefficients to monic pseudo-warped coefficients and limit maximum */ -/* amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */ -static OPUS_INLINE void limit_warped_coefs( - opus_int32 *coefs_Q24, - opus_int lambda_Q16, - opus_int32 limit_Q24, - opus_int order -) { - opus_int i, iter, ind = 0; - opus_int32 tmp, maxabs_Q24, chirp_Q16, gain_Q16; - opus_int32 nom_Q16, den_Q24; - opus_int32 limit_Q20, maxabs_Q20; - - /* Convert to monic coefficients */ - lambda_Q16 = -lambda_Q16; - for (i = order - 1; i > 0; i--) { - coefs_Q24[ i - 1 ] = silk_SMLAWB(coefs_Q24[ i - 1 ], coefs_Q24[ i ], lambda_Q16); - } - lambda_Q16 = -lambda_Q16; - nom_Q16 = silk_SMLAWB(SILK_FIX_CONST(1.0, 16), -(opus_int32)lambda_Q16, lambda_Q16); - den_Q24 = silk_SMLAWB(SILK_FIX_CONST(1.0, 24), coefs_Q24[ 0 ], lambda_Q16); - gain_Q16 = silk_DIV32_varQ(nom_Q16, den_Q24, 24); - for (i = 0; i < order; i++) { - coefs_Q24[ i ] = silk_SMULWW(gain_Q16, coefs_Q24[ i ]); - } - limit_Q20 = silk_RSHIFT(limit_Q24, 4); - for (iter = 0; iter < 10; iter++) { - /* Find maximum absolute value */ - maxabs_Q24 = -1; - for (i = 0; i < order; i++) { - tmp = silk_abs_int32(coefs_Q24[ i ]); - if (tmp > maxabs_Q24) { - maxabs_Q24 = tmp; - ind = i; - } - } - /* Use Q20 to avoid any overflow when multiplying by (ind + 1) later. */ - maxabs_Q20 = silk_RSHIFT(maxabs_Q24, 4); - if (maxabs_Q20 <= limit_Q20) { - /* Coefficients are within range - done */ - return; - } - - /* Convert back to true warped coefficients */ - for (i = 1; i < order; i++) { - coefs_Q24[ i - 1 ] = silk_SMLAWB(coefs_Q24[ i - 1 ], coefs_Q24[ i ], lambda_Q16); - } - gain_Q16 = silk_INVERSE32_varQ(gain_Q16, 32); - for (i = 0; i < order; i++) { - coefs_Q24[ i ] = silk_SMULWW(gain_Q16, coefs_Q24[ i ]); - } - - /* Apply bandwidth expansion */ - chirp_Q16 = SILK_FIX_CONST(0.99, 16) - silk_DIV32_varQ( - silk_SMULWB(maxabs_Q20 - limit_Q20, silk_SMLABB(SILK_FIX_CONST(0.8, 10), SILK_FIX_CONST(0.1, 10), iter)), - silk_MUL(maxabs_Q20, ind + 1), 22); - silk_bwexpander_32(coefs_Q24, order, chirp_Q16); - - /* Convert to monic warped coefficients */ - lambda_Q16 = -lambda_Q16; - for (i = order - 1; i > 0; i--) { - coefs_Q24[ i - 1 ] = silk_SMLAWB(coefs_Q24[ i - 1 ], coefs_Q24[ i ], lambda_Q16); - } - lambda_Q16 = -lambda_Q16; - nom_Q16 = silk_SMLAWB(SILK_FIX_CONST(1.0, 16), -(opus_int32)lambda_Q16, lambda_Q16); - den_Q24 = silk_SMLAWB(SILK_FIX_CONST(1.0, 24), coefs_Q24[ 0 ], lambda_Q16); - gain_Q16 = silk_DIV32_varQ(nom_Q16, den_Q24, 24); - for (i = 0; i < order; i++) { - coefs_Q24[ i ] = silk_SMULWW(gain_Q16, coefs_Q24[ i ]); - } - } - silk_assert(0); -} - -/* Disable MIPS version until it's updated. */ -#if 0 && defined(MIPSr1_ASM) -#include "mips/noise_shape_analysis_FIX_mipsr1.h" -#endif - -/**************************************************************/ -/* Compute noise shaping coefficients and initial gain values */ -/**************************************************************/ -#ifndef OVERRIDE_silk_noise_shape_analysis_FIX -void silk_noise_shape_analysis_FIX( - silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ - silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */ - const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */ - const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */ - int arch /* I Run-time architecture */ -) { - silk_shape_state_FIX *psShapeSt = &psEnc->sShape; - opus_int k, i, nSamples, nSegs, Qnrg, b_Q14, warping_Q16, scale = 0; - opus_int32 SNR_adj_dB_Q7, HarmShapeGain_Q16, Tilt_Q16, tmp32; - opus_int32 nrg, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7; - opus_int32 BWExp_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8; - opus_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; - opus_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ]; - opus_int32 AR_Q24[ MAX_SHAPE_LPC_ORDER ]; - VARDECL(opus_int16, x_windowed); - const opus_int16 *x_ptr, *pitch_res_ptr; - SAVE_STACK; - - /* Point to start of first LPC analysis block */ - x_ptr = x - psEnc->sCmn.la_shape; - - /****************/ - /* GAIN CONTROL */ - /****************/ - SNR_adj_dB_Q7 = psEnc->sCmn.SNR_dB_Q7; - - /* Input quality is the average of the quality in the lowest two VAD bands */ - psEncCtrl->input_quality_Q14 = (opus_int)silk_RSHIFT((opus_int32)psEnc->sCmn.input_quality_bands_Q15[ 0 ] - + psEnc->sCmn.input_quality_bands_Q15[ 1 ], 2); - - /* Coding quality level, between 0.0_Q0 and 1.0_Q0, but in Q14 */ - psEncCtrl->coding_quality_Q14 = silk_RSHIFT(silk_sigm_Q15(silk_RSHIFT_ROUND(SNR_adj_dB_Q7 - - SILK_FIX_CONST(20.0, 7), 4)), 1); - - /* Reduce coding SNR during low speech activity */ - if (psEnc->sCmn.useCBR == 0) { - b_Q8 = SILK_FIX_CONST(1.0, 8) - psEnc->sCmn.speech_activity_Q8; - b_Q8 = silk_SMULWB(silk_LSHIFT(b_Q8, 8), b_Q8); - SNR_adj_dB_Q7 = silk_SMLAWB(SNR_adj_dB_Q7, - silk_SMULBB(SILK_FIX_CONST(-BG_SNR_DECR_dB, 7) >> (4 + 1), b_Q8), /* Q11*/ - silk_SMULWB(SILK_FIX_CONST(1.0, 14) + psEncCtrl->input_quality_Q14, psEncCtrl->coding_quality_Q14)); /* Q12*/ - } - - if (psEnc->sCmn.indices.signalType == TYPE_VOICED) { - /* Reduce gains for periodic signals */ - SNR_adj_dB_Q7 = silk_SMLAWB(SNR_adj_dB_Q7, SILK_FIX_CONST(HARM_SNR_INCR_dB, 8), psEnc->LTPCorr_Q15); - } else { - /* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */ - SNR_adj_dB_Q7 = silk_SMLAWB(SNR_adj_dB_Q7, - silk_SMLAWB(SILK_FIX_CONST(6.0, 9), -SILK_FIX_CONST(0.4, 18), psEnc->sCmn.SNR_dB_Q7), - SILK_FIX_CONST(1.0, 14) - psEncCtrl->input_quality_Q14); - } - - /*************************/ - /* SPARSENESS PROCESSING */ - /*************************/ - /* Set quantizer offset */ - if (psEnc->sCmn.indices.signalType == TYPE_VOICED) { - /* Initially set to 0; may be overruled in process_gains(..) */ - psEnc->sCmn.indices.quantOffsetType = 0; - } else { - /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ - nSamples = silk_LSHIFT(psEnc->sCmn.fs_kHz, 1); - energy_variation_Q7 = 0; - log_energy_prev_Q7 = 0; - pitch_res_ptr = pitch_res; - nSegs = silk_SMULBB(SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr) / 2; - for (k = 0; k < nSegs; k++) { - silk_sum_sqr_shift(&nrg, &scale, pitch_res_ptr, nSamples); - nrg += silk_RSHIFT(nSamples, scale); /* Q(-scale)*/ - - log_energy_Q7 = silk_lin2log(nrg); - if (k > 0) { - energy_variation_Q7 += silk_abs(log_energy_Q7 - log_energy_prev_Q7); - } - log_energy_prev_Q7 = log_energy_Q7; - pitch_res_ptr += nSamples; - } - - /* Set quantization offset depending on sparseness measure */ - if (energy_variation_Q7 > SILK_FIX_CONST(ENERGY_VARIATION_THRESHOLD_QNT_OFFSET, 7) * (nSegs - 1)) { - psEnc->sCmn.indices.quantOffsetType = 0; - } else { - psEnc->sCmn.indices.quantOffsetType = 1; - } - } - - /*******************************/ - /* Control bandwidth expansion */ - /*******************************/ - /* More BWE for signals with high prediction gain */ - strength_Q16 = silk_SMULWB(psEncCtrl->predGain_Q16, SILK_FIX_CONST(FIND_PITCH_WHITE_NOISE_FRACTION, 16)); - BWExp_Q16 = silk_DIV32_varQ(SILK_FIX_CONST(BANDWIDTH_EXPANSION, 16), - silk_SMLAWW(SILK_FIX_CONST(1.0, 16), strength_Q16, strength_Q16), 16); - - if (psEnc->sCmn.warping_Q16 > 0) { - /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */ - warping_Q16 = silk_SMLAWB(psEnc->sCmn.warping_Q16, (opus_int32)psEncCtrl->coding_quality_Q14, SILK_FIX_CONST(0.01, 18)); - } else { - warping_Q16 = 0; - } - - /********************************************/ - /* Compute noise shaping AR coefs and gains */ - /********************************************/ - ALLOC(x_windowed, psEnc->sCmn.shapeWinLength, opus_int16); - for (k = 0; k < psEnc->sCmn.nb_subfr; k++) { - /* Apply window: sine slope followed by flat part followed by cosine slope */ - opus_int shift, slope_part, flat_part; - flat_part = psEnc->sCmn.fs_kHz * 3; - slope_part = silk_RSHIFT(psEnc->sCmn.shapeWinLength - flat_part, 1); - - silk_apply_sine_window(x_windowed, x_ptr, 1, slope_part); - shift = slope_part; - silk_memcpy(x_windowed + shift, x_ptr + shift, flat_part * sizeof(opus_int16)); - shift += flat_part; - silk_apply_sine_window(x_windowed + shift, x_ptr + shift, 2, slope_part); - - /* Update pointer: next LPC analysis block */ - x_ptr += psEnc->sCmn.subfr_length; - - if (psEnc->sCmn.warping_Q16 > 0) { - /* Calculate warped auto correlation */ - silk_warped_autocorrelation_FIX(auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder, arch); - } else { - /* Calculate regular auto correlation */ - silk_autocorr(auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1, arch); - } - - /* Add white noise, as a fraction of energy */ - auto_corr[0] = silk_ADD32(auto_corr[0], silk_max_32(silk_SMULWB(silk_RSHIFT(auto_corr[ 0 ], 4), - SILK_FIX_CONST(SHAPE_WHITE_NOISE_FRACTION, 20)), 1)); - - /* Calculate the reflection coefficients using schur */ - nrg = silk_schur64(refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrder); - silk_assert(nrg >= 0); - - /* Convert reflection coefficients to prediction coefficients */ - silk_k2a_Q16(AR_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder); - - Qnrg = -scale; /* range: -12...30*/ - silk_assert(Qnrg >= -12); - silk_assert(Qnrg <= 30); - - /* Make sure that Qnrg is an even number */ - if (Qnrg & 1) { - Qnrg -= 1; - nrg >>= 1; - } - - tmp32 = silk_SQRT_APPROX(nrg); - Qnrg >>= 1; /* range: -6...15*/ - - psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32(tmp32, 16 - Qnrg); - - if (psEnc->sCmn.warping_Q16 > 0) { - /* Adjust gain for warping */ - gain_mult_Q16 = warped_gain(AR_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder); - silk_assert(psEncCtrl->Gains_Q16[ k ] > 0); - if (psEncCtrl->Gains_Q16[ k ] < SILK_FIX_CONST(0.25, 16)) { - psEncCtrl->Gains_Q16[ k ] = silk_SMULWW(psEncCtrl->Gains_Q16[ k ], gain_mult_Q16); - } else { - psEncCtrl->Gains_Q16[ k ] = silk_SMULWW(silk_RSHIFT_ROUND(psEncCtrl->Gains_Q16[ k ], 1), gain_mult_Q16); - if (psEncCtrl->Gains_Q16[ k ] >= (silk_int32_MAX >> 1)) { - psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX; - } else { - psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT32(psEncCtrl->Gains_Q16[ k ], 1); - } - } - silk_assert(psEncCtrl->Gains_Q16[ k ] > 0); - } - - /* Bandwidth expansion */ - silk_bwexpander_32(AR_Q24, psEnc->sCmn.shapingLPCOrder, BWExp_Q16); - - if (psEnc->sCmn.warping_Q16 > 0) { - /* Convert to monic warped prediction coefficients and limit absolute values */ - limit_warped_coefs(AR_Q24, warping_Q16, SILK_FIX_CONST(3.999, 24), psEnc->sCmn.shapingLPCOrder); - - /* Convert from Q24 to Q13 and store in int16 */ - for (i = 0; i < psEnc->sCmn.shapingLPCOrder; i++) { - psEncCtrl->AR_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(AR_Q24[ i ], 11)); - } - } else { - silk_LPC_fit(&psEncCtrl->AR_Q13[ k * MAX_SHAPE_LPC_ORDER ], AR_Q24, 13, 24, psEnc->sCmn.shapingLPCOrder); - } - } - - /*****************/ - /* Gain tweaking */ - /*****************/ - /* Increase gains during low speech activity and put lower limit on gains */ - gain_mult_Q16 = silk_log2lin(-silk_SMLAWB(-SILK_FIX_CONST(16.0, 7), SNR_adj_dB_Q7, SILK_FIX_CONST(0.16, 16))); - gain_add_Q16 = silk_log2lin(silk_SMLAWB(SILK_FIX_CONST(16.0, 7), SILK_FIX_CONST(MIN_QGAIN_DB, 7), SILK_FIX_CONST(0.16, 16))); - silk_assert(gain_mult_Q16 > 0); - for (k = 0; k < psEnc->sCmn.nb_subfr; k++) { - psEncCtrl->Gains_Q16[ k ] = silk_SMULWW(psEncCtrl->Gains_Q16[ k ], gain_mult_Q16); - silk_assert(psEncCtrl->Gains_Q16[ k ] >= 0); - psEncCtrl->Gains_Q16[ k ] = silk_ADD_POS_SAT32(psEncCtrl->Gains_Q16[ k ], gain_add_Q16); - } - - - /************************************************/ - /* Control low-frequency shaping and noise tilt */ - /************************************************/ - /* Less low frequency shaping for noisy inputs */ - strength_Q16 = silk_MUL(SILK_FIX_CONST(LOW_FREQ_SHAPING, 4), silk_SMLAWB(SILK_FIX_CONST(1.0, 12), - SILK_FIX_CONST(LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 13), psEnc->sCmn.input_quality_bands_Q15[ 0 ] - SILK_FIX_CONST(1.0, 15))); - strength_Q16 = silk_RSHIFT(silk_MUL(strength_Q16, psEnc->sCmn.speech_activity_Q8), 8); - if (psEnc->sCmn.indices.signalType == TYPE_VOICED) { - /* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */ - /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/ - opus_int fs_kHz_inv = silk_DIV32_16(SILK_FIX_CONST(0.2, 14), psEnc->sCmn.fs_kHz); - for (k = 0; k < psEnc->sCmn.nb_subfr; k++) { - b_Q14 = fs_kHz_inv + silk_DIV32_16(SILK_FIX_CONST(3.0, 14), psEncCtrl->pitchL[ k ]); - /* Pack two coefficients in one int32 */ - psEncCtrl->LF_shp_Q14[ k ] = silk_LSHIFT(SILK_FIX_CONST(1.0, 14) - b_Q14 - silk_SMULWB(strength_Q16, b_Q14), 16); - psEncCtrl->LF_shp_Q14[ k ] |= (opus_uint16)(b_Q14 - SILK_FIX_CONST(1.0, 14)); - } - silk_assert(SILK_FIX_CONST(HARM_HP_NOISE_COEF, 24) < SILK_FIX_CONST(0.5, 24)); /* Guarantees that second argument to SMULWB() is within range of an opus_int16*/ - Tilt_Q16 = - SILK_FIX_CONST(HP_NOISE_COEF, 16) - - silk_SMULWB(SILK_FIX_CONST(1.0, 16) - SILK_FIX_CONST(HP_NOISE_COEF, 16), - silk_SMULWB(SILK_FIX_CONST(HARM_HP_NOISE_COEF, 24), psEnc->sCmn.speech_activity_Q8)); - } else { - b_Q14 = silk_DIV32_16(21299, psEnc->sCmn.fs_kHz); /* 1.3_Q0 = 21299_Q14*/ - /* Pack two coefficients in one int32 */ - psEncCtrl->LF_shp_Q14[ 0 ] = silk_LSHIFT(SILK_FIX_CONST(1.0, 14) - b_Q14 - - silk_SMULWB(strength_Q16, silk_SMULWB(SILK_FIX_CONST(0.6, 16), b_Q14)), 16); - psEncCtrl->LF_shp_Q14[ 0 ] |= (opus_uint16)(b_Q14 - SILK_FIX_CONST(1.0, 14)); - for (k = 1; k < psEnc->sCmn.nb_subfr; k++) { - psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ 0 ]; - } - Tilt_Q16 = -SILK_FIX_CONST(HP_NOISE_COEF, 16); - } - - /****************************/ - /* HARMONIC SHAPING CONTROL */ - /****************************/ - if (USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED) { - /* More harmonic noise shaping for high bitrates or noisy input */ - HarmShapeGain_Q16 = silk_SMLAWB(SILK_FIX_CONST(HARMONIC_SHAPING, 16), - SILK_FIX_CONST(1.0, 16) - silk_SMULWB(SILK_FIX_CONST(1.0, 18) - silk_LSHIFT(psEncCtrl->coding_quality_Q14, 4), - psEncCtrl->input_quality_Q14), SILK_FIX_CONST(HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING, 16)); - - /* Less harmonic noise shaping for less periodic signals */ - HarmShapeGain_Q16 = silk_SMULWB(silk_LSHIFT(HarmShapeGain_Q16, 1), - silk_SQRT_APPROX(silk_LSHIFT(psEnc->LTPCorr_Q15, 15))); - } else { - HarmShapeGain_Q16 = 0; - } - - /*************************/ - /* Smooth over subframes */ - /*************************/ - for (k = 0; k < MAX_NB_SUBFR; k++) { - psShapeSt->HarmShapeGain_smth_Q16 = - silk_SMLAWB(psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST(SUBFR_SMTH_COEF, 16)); - psShapeSt->Tilt_smth_Q16 = - silk_SMLAWB(psShapeSt->Tilt_smth_Q16, Tilt_Q16 - psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST(SUBFR_SMTH_COEF, 16)); - - psEncCtrl->HarmShapeGain_Q14[ k ] = (opus_int)silk_RSHIFT_ROUND(psShapeSt->HarmShapeGain_smth_Q16, 2); - psEncCtrl->Tilt_Q14[ k ] = (opus_int)silk_RSHIFT_ROUND(psShapeSt->Tilt_smth_Q16, 2); - } - RESTORE_STACK; -} -#endif /* OVERRIDE_silk_noise_shape_analysis_FIX */ diff --git a/src/libopus/silk/fixed/noise_shape_analysis_FIX.lo b/src/libopus/silk/fixed/noise_shape_analysis_FIX.lo deleted file mode 100644 index 9c74371..0000000 --- a/src/libopus/silk/fixed/noise_shape_analysis_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/noise_shape_analysis_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/noise_shape_analysis_FIX.o' - -# Name of the non-PIC object -non_pic_object='noise_shape_analysis_FIX.o' - diff --git a/src/libopus/silk/fixed/noise_shape_analysis_FIX.o b/src/libopus/silk/fixed/noise_shape_analysis_FIX.o deleted file mode 100644 index 423d350d0793a98496a5c85e92f892b7cb8f4234..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 57392 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 diff --git a/src/libopus/silk/fixed/pitch.h b/src/libopus/silk/fixed/pitch.h new file mode 100644 index 0000000..f2cf322 --- /dev/null +++ b/src/libopus/silk/fixed/pitch.h @@ -0,0 +1 @@ +#include "../../celt/pitch.h" diff --git a/src/libopus/silk/fixed/pitch_analysis_core_FIX.c b/src/libopus/silk/fixed/pitch_analysis_core_FIX.c deleted file mode 100644 index 9b384da..0000000 --- a/src/libopus/silk/fixed/pitch_analysis_core_FIX.c +++ /dev/null @@ -1,718 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif - -/*********************************************************** - Pitch analyser function -********************************************************** */ -#include "../SigProc_FIX.h" -#include "../pitch_est_defines.h" -#include "../../celt/stack_alloc.h" -#include "../debug.h" -#include "../../celt/pitch.h" - -#define SCRATCH_SIZE 22 -#define SF_LENGTH_4KHZ ( PE_SUBFR_LENGTH_MS * 4 ) -#define SF_LENGTH_8KHZ ( PE_SUBFR_LENGTH_MS * 8 ) -#define MIN_LAG_4KHZ ( PE_MIN_LAG_MS * 4 ) -#define MIN_LAG_8KHZ ( PE_MIN_LAG_MS * 8 ) -#define MAX_LAG_4KHZ ( PE_MAX_LAG_MS * 4 ) -#define MAX_LAG_8KHZ ( PE_MAX_LAG_MS * 8 - 1 ) -#define CSTRIDE_4KHZ ( MAX_LAG_4KHZ + 1 - MIN_LAG_4KHZ ) -#define CSTRIDE_8KHZ ( MAX_LAG_8KHZ + 3 - ( MIN_LAG_8KHZ - 2 ) ) -#define D_COMP_MIN ( MIN_LAG_8KHZ - 3 ) -#define D_COMP_MAX ( MAX_LAG_8KHZ + 4 ) -#define D_COMP_STRIDE ( D_COMP_MAX - D_COMP_MIN ) - -typedef opus_int32 silk_pe_stage3_vals[ PE_NB_STAGE3_LAGS ]; - -/************************************************************/ -/* Internally used functions */ -/************************************************************/ -static void silk_P_Ana_calc_corr_st3( - silk_pe_stage3_vals cross_corr_st3[], /* O 3 DIM correlation array */ - const opus_int16 frame[], /* I vector to correlate */ - opus_int start_lag, /* I lag offset to search around */ - opus_int sf_length, /* I length of a 5 ms subframe */ - opus_int nb_subfr, /* I number of subframes */ - opus_int complexity, /* I Complexity setting */ - int arch /* I Run-time architecture */ -); - -static void silk_P_Ana_calc_energy_st3( - silk_pe_stage3_vals energies_st3[], /* O 3 DIM energy array */ - const opus_int16 frame[], /* I vector to calc energy in */ - opus_int start_lag, /* I lag offset to search around */ - opus_int sf_length, /* I length of one 5 ms subframe */ - opus_int nb_subfr, /* I number of subframes */ - opus_int complexity, /* I Complexity setting */ - int arch /* I Run-time architecture */ -); - -/*************************************************************/ -/* FIXED POINT CORE PITCH ANALYSIS FUNCTION */ -/*************************************************************/ -opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ - const opus_int16 *frame_unscaled, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ - opus_int *pitch_out, /* O 4 pitch lag values */ - opus_int16 *lagIndex, /* O Lag Index */ - opus_int8 *contourIndex, /* O Pitch contour Index */ - opus_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */ - opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ - const opus_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */ - const opus_int search_thres2_Q13, /* I Final threshold for lag candidates 0 - 1 */ - const opus_int Fs_kHz, /* I Sample frequency (kHz) */ - const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ - const opus_int nb_subfr, /* I number of 5 ms subframes */ - int arch /* I Run-time architecture */ -) { - VARDECL(opus_int16, frame_8kHz_buf); - VARDECL(opus_int16, frame_4kHz); - VARDECL(opus_int16, frame_scaled); - opus_int32 filt_state[ 6 ]; - const opus_int16 *frame, *frame_8kHz; - opus_int i, k, d, j; - VARDECL(opus_int16, C); - VARDECL(opus_int32, xcorr32); - const opus_int16 *target_ptr, *basis_ptr; - opus_int32 cross_corr, normalizer, energy, energy_basis, energy_target; - opus_int d_srch[ PE_D_SRCH_LENGTH ], Cmax, length_d_srch, length_d_comp, shift; - VARDECL(opus_int16, d_comp); - opus_int32 sum, threshold, lag_counter; - opus_int CBimax, CBimax_new, CBimax_old, lag, start_lag, end_lag, lag_new; - opus_int32 CC[ PE_NB_CBKS_STAGE2_EXT ], CCmax, CCmax_b, CCmax_new_b, CCmax_new; - VARDECL(silk_pe_stage3_vals, energies_st3); - VARDECL(silk_pe_stage3_vals, cross_corr_st3); - opus_int frame_length, frame_length_8kHz, frame_length_4kHz; - opus_int sf_length; - opus_int min_lag; - opus_int max_lag; - opus_int32 contour_bias_Q15, diff; - opus_int nb_cbk_search, cbk_size; - opus_int32 delta_lag_log2_sqr_Q7, lag_log2_Q7, prevLag_log2_Q7, prev_lag_bias_Q13; - const opus_int8 *Lag_CB_ptr; - SAVE_STACK; - - /* Check for valid sampling frequency */ - celt_assert(Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16); - - /* Check for valid complexity setting */ - celt_assert(complexity >= SILK_PE_MIN_COMPLEX); - celt_assert(complexity <= SILK_PE_MAX_COMPLEX); - - silk_assert(search_thres1_Q16 >= 0 && search_thres1_Q16 <= (1 << 16)); - silk_assert(search_thres2_Q13 >= 0 && search_thres2_Q13 <= (1 << 13)); - - /* Set up frame lengths max / min lag for the sampling frequency */ - frame_length = (PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS) * Fs_kHz; - frame_length_4kHz = (PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS) * 4; - frame_length_8kHz = (PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS) * 8; - sf_length = PE_SUBFR_LENGTH_MS * Fs_kHz; - min_lag = PE_MIN_LAG_MS * Fs_kHz; - max_lag = PE_MAX_LAG_MS * Fs_kHz - 1; - - /* Downscale input if necessary */ - silk_sum_sqr_shift(&energy, &shift, frame_unscaled, frame_length); - shift += 3 - silk_CLZ32(energy); /* at least two bits headroom */ - ALLOC(frame_scaled, frame_length, opus_int16); - if (shift > 0) { - shift = silk_RSHIFT(shift + 1, 1); - for (i = 0; i < frame_length; i++) { - frame_scaled[ i ] = silk_RSHIFT(frame_unscaled[ i ], shift); - } - frame = frame_scaled; - } else { - frame = frame_unscaled; - } - - ALLOC(frame_8kHz_buf, (Fs_kHz == 8) ? 1 : frame_length_8kHz, opus_int16); - /* Resample from input sampled at Fs_kHz to 8 kHz */ - if (Fs_kHz == 16) { - silk_memset(filt_state, 0, 2 * sizeof(opus_int32)); - silk_resampler_down2(filt_state, frame_8kHz_buf, frame, frame_length); - frame_8kHz = frame_8kHz_buf; - } else if (Fs_kHz == 12) { - silk_memset(filt_state, 0, 6 * sizeof(opus_int32)); - silk_resampler_down2_3(filt_state, frame_8kHz_buf, frame, frame_length); - frame_8kHz = frame_8kHz_buf; - } else { - celt_assert(Fs_kHz == 8); - frame_8kHz = frame; - } - - /* Decimate again to 4 kHz */ - silk_memset(filt_state, 0, 2 * sizeof(opus_int32)); /* Set state to zero */ - ALLOC(frame_4kHz, frame_length_4kHz, opus_int16); - silk_resampler_down2(filt_state, frame_4kHz, frame_8kHz, frame_length_8kHz); - - /* Low-pass filter */ - for (i = frame_length_4kHz - 1; i > 0; i--) { - frame_4kHz[ i ] = silk_ADD_SAT16(frame_4kHz[ i ], frame_4kHz[ i - 1 ]); - } - - - /****************************************************************************** - FIRST STAGE, operating in 4 khz - ******************************************************************************/ - ALLOC(C, nb_subfr * CSTRIDE_8KHZ, opus_int16); - ALLOC(xcorr32, MAX_LAG_4KHZ - MIN_LAG_4KHZ + 1, opus_int32); - silk_memset(C, 0, (nb_subfr >> 1) * CSTRIDE_4KHZ * sizeof(opus_int16)); - target_ptr = &frame_4kHz[ silk_LSHIFT(SF_LENGTH_4KHZ, 2) ]; - for (k = 0; k < nb_subfr >> 1; k++) { - /* Check that we are within range of the array */ - celt_assert(target_ptr >= frame_4kHz); - celt_assert(target_ptr + SF_LENGTH_8KHZ <= frame_4kHz + frame_length_4kHz); - - basis_ptr = target_ptr - MIN_LAG_4KHZ; - - /* Check that we are within range of the array */ - celt_assert(basis_ptr >= frame_4kHz); - celt_assert(basis_ptr + SF_LENGTH_8KHZ <= frame_4kHz + frame_length_4kHz); - - celt_pitch_xcorr(target_ptr, target_ptr - MAX_LAG_4KHZ, xcorr32, SF_LENGTH_8KHZ, MAX_LAG_4KHZ - MIN_LAG_4KHZ + 1, arch); - - /* Calculate first vector products before loop */ - cross_corr = xcorr32[ MAX_LAG_4KHZ - MIN_LAG_4KHZ ]; - normalizer = silk_inner_prod_aligned(target_ptr, target_ptr, SF_LENGTH_8KHZ, arch); - normalizer = silk_ADD32(normalizer, silk_inner_prod_aligned(basis_ptr, basis_ptr, SF_LENGTH_8KHZ, arch)); - normalizer = silk_ADD32(normalizer, silk_SMULBB(SF_LENGTH_8KHZ, 4000)); - - matrix_ptr(C, k, 0, CSTRIDE_4KHZ) = - (opus_int16)silk_DIV32_varQ(cross_corr, normalizer, 13 + 1); /* Q13 */ - - /* From now on normalizer is computed recursively */ - for (d = MIN_LAG_4KHZ + 1; d <= MAX_LAG_4KHZ; d++) { - basis_ptr--; - - /* Check that we are within range of the array */ - silk_assert(basis_ptr >= frame_4kHz); - silk_assert(basis_ptr + SF_LENGTH_8KHZ <= frame_4kHz + frame_length_4kHz); - - cross_corr = xcorr32[ MAX_LAG_4KHZ - d ]; - - /* Add contribution of new sample and remove contribution from oldest sample */ - normalizer = silk_ADD32(normalizer, - silk_SMULBB(basis_ptr[ 0 ], basis_ptr[ 0 ]) - - silk_SMULBB(basis_ptr[ SF_LENGTH_8KHZ ], basis_ptr[ SF_LENGTH_8KHZ ])); - - matrix_ptr(C, k, d - MIN_LAG_4KHZ, CSTRIDE_4KHZ) = - (opus_int16)silk_DIV32_varQ(cross_corr, normalizer, 13 + 1); /* Q13 */ - } - /* Update target pointer */ - target_ptr += SF_LENGTH_8KHZ; - } - - /* Combine two subframes into single correlation measure and apply short-lag bias */ - if (nb_subfr == PE_MAX_NB_SUBFR) { - for (i = MAX_LAG_4KHZ; i >= MIN_LAG_4KHZ; i--) { - sum = (opus_int32)matrix_ptr(C, 0, i - MIN_LAG_4KHZ, CSTRIDE_4KHZ) - + (opus_int32)matrix_ptr(C, 1, i - MIN_LAG_4KHZ, CSTRIDE_4KHZ); /* Q14 */ - sum = silk_SMLAWB(sum, sum, silk_LSHIFT(-i, 4)); /* Q14 */ - C[ i - MIN_LAG_4KHZ ] = (opus_int16)sum; /* Q14 */ - } - } else { - /* Only short-lag bias */ - for (i = MAX_LAG_4KHZ; i >= MIN_LAG_4KHZ; i--) { - sum = silk_LSHIFT((opus_int32)C[ i - MIN_LAG_4KHZ ], 1); /* Q14 */ - sum = silk_SMLAWB(sum, sum, silk_LSHIFT(-i, 4)); /* Q14 */ - C[ i - MIN_LAG_4KHZ ] = (opus_int16)sum; /* Q14 */ - } - } - - /* Sort */ - length_d_srch = silk_ADD_LSHIFT32(4, complexity, 1); - celt_assert(3 * length_d_srch <= PE_D_SRCH_LENGTH); - silk_insertion_sort_decreasing_int16(C, d_srch, CSTRIDE_4KHZ, - length_d_srch); - - /* Escape if correlation is very low already here */ - Cmax = (opus_int)C[ 0 ]; /* Q14 */ - if (Cmax < SILK_FIX_CONST(0.2, 14)) { - silk_memset(pitch_out, 0, nb_subfr * sizeof(opus_int)); - *LTPCorr_Q15 = 0; - *lagIndex = 0; - *contourIndex = 0; - RESTORE_STACK; - return 1; - } - - threshold = silk_SMULWB(search_thres1_Q16, Cmax); - for (i = 0; i < length_d_srch; i++) { - /* Convert to 8 kHz indices for the sorted correlation that exceeds the threshold */ - if (C[ i ] > threshold) { - d_srch[ i ] = silk_LSHIFT(d_srch[ i ] + MIN_LAG_4KHZ, 1); - } else { - length_d_srch = i; - break; - } - } - celt_assert(length_d_srch > 0); - - ALLOC(d_comp, D_COMP_STRIDE, opus_int16); - for (i = D_COMP_MIN; i < D_COMP_MAX; i++) { - d_comp[ i - D_COMP_MIN ] = 0; - } - for (i = 0; i < length_d_srch; i++) { - d_comp[ d_srch[ i ] - D_COMP_MIN ] = 1; - } - - /* Convolution */ - for (i = D_COMP_MAX - 1; i >= MIN_LAG_8KHZ; i--) { - d_comp[ i - D_COMP_MIN ] += - d_comp[ i - 1 - D_COMP_MIN ] + d_comp[ i - 2 - D_COMP_MIN ]; - } - - length_d_srch = 0; - for (i = MIN_LAG_8KHZ; i < MAX_LAG_8KHZ + 1; i++) { - if (d_comp[ i + 1 - D_COMP_MIN ] > 0) { - d_srch[ length_d_srch ] = i; - length_d_srch++; - } - } - - /* Convolution */ - for (i = D_COMP_MAX - 1; i >= MIN_LAG_8KHZ; i--) { - d_comp[ i - D_COMP_MIN ] += d_comp[ i - 1 - D_COMP_MIN ] - + d_comp[ i - 2 - D_COMP_MIN ] + d_comp[ i - 3 - D_COMP_MIN ]; - } - - length_d_comp = 0; - for (i = MIN_LAG_8KHZ; i < D_COMP_MAX; i++) { - if (d_comp[ i - D_COMP_MIN ] > 0) { - d_comp[ length_d_comp ] = i - 2; - length_d_comp++; - } - } - - /********************************************************************************** - ** SECOND STAGE, operating at 8 kHz, on lag sections with high correlation - *************************************************************************************/ - - /********************************************************************************* - Find energy of each subframe projected onto its history, for a range of delays - *********************************************************************************/ - silk_memset(C, 0, nb_subfr * CSTRIDE_8KHZ * sizeof(opus_int16)); - - target_ptr = &frame_8kHz[ PE_LTP_MEM_LENGTH_MS * 8 ]; - for (k = 0; k < nb_subfr; k++) { - - /* Check that we are within range of the array */ - celt_assert(target_ptr >= frame_8kHz); - celt_assert(target_ptr + SF_LENGTH_8KHZ <= frame_8kHz + frame_length_8kHz); - - energy_target = silk_ADD32(silk_inner_prod_aligned(target_ptr, target_ptr, SF_LENGTH_8KHZ, arch), 1); - for (j = 0; j < length_d_comp; j++) { - d = d_comp[ j ]; - basis_ptr = target_ptr - d; - - /* Check that we are within range of the array */ - silk_assert(basis_ptr >= frame_8kHz); - silk_assert(basis_ptr + SF_LENGTH_8KHZ <= frame_8kHz + frame_length_8kHz); - - cross_corr = silk_inner_prod_aligned(target_ptr, basis_ptr, SF_LENGTH_8KHZ, arch); - if (cross_corr > 0) { - energy_basis = silk_inner_prod_aligned(basis_ptr, basis_ptr, SF_LENGTH_8KHZ, arch); - matrix_ptr(C, k, d - (MIN_LAG_8KHZ - 2), CSTRIDE_8KHZ) = - (opus_int16)silk_DIV32_varQ(cross_corr, - silk_ADD32(energy_target, - energy_basis), - 13 + 1); /* Q13 */ - } else { - matrix_ptr(C, k, d - (MIN_LAG_8KHZ - 2), CSTRIDE_8KHZ) = 0; - } - } - target_ptr += SF_LENGTH_8KHZ; - } - - /* search over lag range and lags codebook */ - /* scale factor for lag codebook, as a function of center lag */ - - CCmax = silk_int32_MIN; - CCmax_b = silk_int32_MIN; - - CBimax = 0; /* To avoid returning undefined lag values */ - lag = -1; /* To check if lag with strong enough correlation has been found */ - - if (prevLag > 0) { - if (Fs_kHz == 12) { - prevLag = silk_DIV32_16(silk_LSHIFT(prevLag, 1), 3); - } else if (Fs_kHz == 16) { - prevLag = silk_RSHIFT(prevLag, 1); - } - prevLag_log2_Q7 = silk_lin2log((opus_int32)prevLag); - } else { - prevLag_log2_Q7 = 0; - } - silk_assert(search_thres2_Q13 == silk_SAT16(search_thres2_Q13)); - /* Set up stage 2 codebook based on number of subframes */ - if (nb_subfr == PE_MAX_NB_SUBFR) { - cbk_size = PE_NB_CBKS_STAGE2_EXT; - Lag_CB_ptr = &silk_CB_lags_stage2[ 0 ][ 0 ]; - if (Fs_kHz == 8 && complexity > SILK_PE_MIN_COMPLEX) { - /* If input is 8 khz use a larger codebook here because it is last stage */ - nb_cbk_search = PE_NB_CBKS_STAGE2_EXT; - } else { - nb_cbk_search = PE_NB_CBKS_STAGE2; - } - } else { - cbk_size = PE_NB_CBKS_STAGE2_10MS; - Lag_CB_ptr = &silk_CB_lags_stage2_10_ms[ 0 ][ 0 ]; - nb_cbk_search = PE_NB_CBKS_STAGE2_10MS; - } - - for (k = 0; k < length_d_srch; k++) { - d = d_srch[ k ]; - for (j = 0; j < nb_cbk_search; j++) { - CC[ j ] = 0; - for (i = 0; i < nb_subfr; i++) { - opus_int d_subfr; - /* Try all codebooks */ - d_subfr = d + matrix_ptr(Lag_CB_ptr, i, j, cbk_size); - CC[ j ] = CC[ j ] - + (opus_int32)matrix_ptr(C, i, - d_subfr - (MIN_LAG_8KHZ - 2), - CSTRIDE_8KHZ); - } - } - /* Find best codebook */ - CCmax_new = silk_int32_MIN; - CBimax_new = 0; - for (i = 0; i < nb_cbk_search; i++) { - if (CC[ i ] > CCmax_new) { - CCmax_new = CC[ i ]; - CBimax_new = i; - } - } - - /* Bias towards shorter lags */ - lag_log2_Q7 = silk_lin2log(d); /* Q7 */ - silk_assert(lag_log2_Q7 == silk_SAT16(lag_log2_Q7)); - silk_assert(nb_subfr * SILK_FIX_CONST(PE_SHORTLAG_BIAS, 13) == silk_SAT16(nb_subfr * SILK_FIX_CONST(PE_SHORTLAG_BIAS, 13))); - CCmax_new_b = CCmax_new - silk_RSHIFT(silk_SMULBB(nb_subfr * SILK_FIX_CONST(PE_SHORTLAG_BIAS, 13), lag_log2_Q7), 7); /* Q13 */ - - /* Bias towards previous lag */ - silk_assert(nb_subfr * SILK_FIX_CONST(PE_PREVLAG_BIAS, 13) == silk_SAT16(nb_subfr * SILK_FIX_CONST(PE_PREVLAG_BIAS, 13))); - if (prevLag > 0) { - delta_lag_log2_sqr_Q7 = lag_log2_Q7 - prevLag_log2_Q7; - silk_assert(delta_lag_log2_sqr_Q7 == silk_SAT16(delta_lag_log2_sqr_Q7)); - delta_lag_log2_sqr_Q7 = silk_RSHIFT(silk_SMULBB(delta_lag_log2_sqr_Q7, delta_lag_log2_sqr_Q7), 7); - prev_lag_bias_Q13 = silk_RSHIFT(silk_SMULBB(nb_subfr * SILK_FIX_CONST(PE_PREVLAG_BIAS, 13), *LTPCorr_Q15), 15); /* Q13 */ - prev_lag_bias_Q13 = silk_DIV32(silk_MUL(prev_lag_bias_Q13, delta_lag_log2_sqr_Q7), delta_lag_log2_sqr_Q7 + SILK_FIX_CONST(0.5, 7)); - CCmax_new_b -= prev_lag_bias_Q13; /* Q13 */ - } - - if (CCmax_new_b > CCmax_b && /* Find maximum biased correlation */ - CCmax_new > silk_SMULBB(nb_subfr, search_thres2_Q13) && /* Correlation needs to be high enough to be voiced */ - silk_CB_lags_stage2[ 0 ][ CBimax_new ] <= MIN_LAG_8KHZ /* Lag must be in range */ - ) { - CCmax_b = CCmax_new_b; - CCmax = CCmax_new; - lag = d; - CBimax = CBimax_new; - } - } - - if (lag == -1) { - /* No suitable candidate found */ - silk_memset(pitch_out, 0, nb_subfr * sizeof(opus_int)); - *LTPCorr_Q15 = 0; - *lagIndex = 0; - *contourIndex = 0; - RESTORE_STACK; - return 1; - } - - /* Output normalized correlation */ - *LTPCorr_Q15 = (opus_int)silk_LSHIFT(silk_DIV32_16(CCmax, nb_subfr), 2); - silk_assert(*LTPCorr_Q15 >= 0); - - if (Fs_kHz > 8) { - /* Search in original signal */ - - CBimax_old = CBimax; - /* Compensate for decimation */ - silk_assert(lag == silk_SAT16(lag)); - if (Fs_kHz == 12) { - lag = silk_RSHIFT(silk_SMULBB(lag, 3), 1); - } else if (Fs_kHz == 16) { - lag = silk_LSHIFT(lag, 1); - } else { - lag = silk_SMULBB(lag, 3); - } - - lag = silk_LIMIT_int(lag, min_lag, max_lag); - start_lag = silk_max_int(lag - 2, min_lag); - end_lag = silk_min_int(lag + 2, max_lag); - lag_new = lag; /* to avoid undefined lag */ - CBimax = 0; /* to avoid undefined lag */ - - CCmax = silk_int32_MIN; - /* pitch lags according to second stage */ - for (k = 0; k < nb_subfr; k++) { - pitch_out[ k ] = lag + 2 * silk_CB_lags_stage2[ k ][ CBimax_old ]; - } - - /* Set up codebook parameters according to complexity setting and frame length */ - if (nb_subfr == PE_MAX_NB_SUBFR) { - nb_cbk_search = (opus_int)silk_nb_cbk_searchs_stage3[ complexity ]; - cbk_size = PE_NB_CBKS_STAGE3_MAX; - Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; - } else { - nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; - cbk_size = PE_NB_CBKS_STAGE3_10MS; - Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; - } - - /* Calculate the correlations and energies needed in stage 3 */ - ALLOC(energies_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals); - ALLOC(cross_corr_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals); - silk_P_Ana_calc_corr_st3(cross_corr_st3, frame, start_lag, sf_length, nb_subfr, complexity, arch); - silk_P_Ana_calc_energy_st3(energies_st3, frame, start_lag, sf_length, nb_subfr, complexity, arch); - - lag_counter = 0; - silk_assert(lag == silk_SAT16(lag)); - contour_bias_Q15 = silk_DIV32_16(SILK_FIX_CONST(PE_FLATCONTOUR_BIAS, 15), lag); - - target_ptr = &frame[ PE_LTP_MEM_LENGTH_MS * Fs_kHz ]; - energy_target = silk_ADD32(silk_inner_prod_aligned(target_ptr, target_ptr, nb_subfr * sf_length, arch), 1); - for (d = start_lag; d <= end_lag; d++) { - for (j = 0; j < nb_cbk_search; j++) { - cross_corr = 0; - energy = energy_target; - for (k = 0; k < nb_subfr; k++) { - cross_corr = silk_ADD32(cross_corr, - matrix_ptr(cross_corr_st3, k, j, - nb_cbk_search)[ lag_counter ]); - energy = silk_ADD32(energy, - matrix_ptr(energies_st3, k, j, - nb_cbk_search)[ lag_counter ]); - silk_assert(energy >= 0); - } - if (cross_corr > 0) { - CCmax_new = silk_DIV32_varQ(cross_corr, energy, 13 + 1); /* Q13 */ - /* Reduce depending on flatness of contour */ - diff = silk_int16_MAX - silk_MUL(contour_bias_Q15, j); /* Q15 */ - silk_assert(diff == silk_SAT16(diff)); - CCmax_new = silk_SMULWB(CCmax_new, diff); /* Q14 */ - } else { - CCmax_new = 0; - } - - if (CCmax_new > CCmax && (d + silk_CB_lags_stage3[ 0 ][ j ]) <= max_lag) { - CCmax = CCmax_new; - lag_new = d; - CBimax = j; - } - } - lag_counter++; - } - - for (k = 0; k < nb_subfr; k++) { - pitch_out[ k ] = lag_new + matrix_ptr(Lag_CB_ptr, k, CBimax, cbk_size); - pitch_out[ k ] = silk_LIMIT(pitch_out[ k ], min_lag, PE_MAX_LAG_MS * Fs_kHz); - } - *lagIndex = (opus_int16)(lag_new - min_lag); - *contourIndex = (opus_int8)CBimax; - } else { /* Fs_kHz == 8 */ - /* Save Lags */ - for (k = 0; k < nb_subfr; k++) { - pitch_out[ k ] = lag + matrix_ptr(Lag_CB_ptr, k, CBimax, cbk_size); - pitch_out[ k ] = silk_LIMIT(pitch_out[ k ], MIN_LAG_8KHZ, PE_MAX_LAG_MS * 8); - } - *lagIndex = (opus_int16)(lag - MIN_LAG_8KHZ); - *contourIndex = (opus_int8)CBimax; - } - celt_assert(*lagIndex >= 0); - /* return as voiced */ - RESTORE_STACK; - return 0; -} - -/*********************************************************************** - Calculates the correlations used in stage 3 search. In order to cover - the whole lag codebook for all the searched offset lags (lag +- 2), - the following correlations are needed in each sub frame: - - sf1: lag range [-8,...,7] total 16 correlations - sf2: lag range [-4,...,4] total 9 correlations - sf3: lag range [-3,....4] total 8 correltions - sf4: lag range [-6,....8] total 15 correlations - - In total 48 correlations. The direct implementation computed in worst - case 4*12*5 = 240 correlations, but more likely around 120. - ***********************************************************************/ -static void silk_P_Ana_calc_corr_st3( - silk_pe_stage3_vals cross_corr_st3[], /* O 3 DIM correlation array */ - const opus_int16 frame[], /* I vector to correlate */ - opus_int start_lag, /* I lag offset to search around */ - opus_int sf_length, /* I length of a 5 ms subframe */ - opus_int nb_subfr, /* I number of subframes */ - opus_int complexity, /* I Complexity setting */ - int arch /* I Run-time architecture */ -) { - const opus_int16 *target_ptr; - opus_int i, j, k, lag_counter, lag_low, lag_high; - opus_int nb_cbk_search, delta, idx, cbk_size; - VARDECL(opus_int32, scratch_mem); - VARDECL(opus_int32, xcorr32); - const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; - SAVE_STACK; - - celt_assert(complexity >= SILK_PE_MIN_COMPLEX); - celt_assert(complexity <= SILK_PE_MAX_COMPLEX); - - if (nb_subfr == PE_MAX_NB_SUBFR) { - Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; - Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; - nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ]; - cbk_size = PE_NB_CBKS_STAGE3_MAX; - } else { - celt_assert(nb_subfr == PE_MAX_NB_SUBFR >> 1); - Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; - Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; - nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; - cbk_size = PE_NB_CBKS_STAGE3_10MS; - } - ALLOC(scratch_mem, SCRATCH_SIZE, opus_int32); - ALLOC(xcorr32, SCRATCH_SIZE, opus_int32); - - target_ptr = &frame[ silk_LSHIFT(sf_length, 2) ]; /* Pointer to middle of frame */ - for (k = 0; k < nb_subfr; k++) { - lag_counter = 0; - - /* Calculate the correlations for each subframe */ - lag_low = matrix_ptr(Lag_range_ptr, k, 0, 2); - lag_high = matrix_ptr(Lag_range_ptr, k, 1, 2); - celt_assert(lag_high - lag_low + 1 <= SCRATCH_SIZE); - celt_pitch_xcorr(target_ptr, target_ptr - start_lag - lag_high, xcorr32, sf_length, lag_high - lag_low + 1, arch); - for (j = lag_low; j <= lag_high; j++) { - silk_assert(lag_counter < SCRATCH_SIZE); - scratch_mem[ lag_counter ] = xcorr32[ lag_high - j ]; - lag_counter++; - } - - delta = matrix_ptr(Lag_range_ptr, k, 0, 2); - for (i = 0; i < nb_cbk_search; i++) { - /* Fill out the 3 dim array that stores the correlations for */ - /* each code_book vector for each start lag */ - idx = matrix_ptr(Lag_CB_ptr, k, i, cbk_size) - delta; - for (j = 0; j < PE_NB_STAGE3_LAGS; j++) { - silk_assert(idx + j < SCRATCH_SIZE); - silk_assert(idx + j < lag_counter); - matrix_ptr(cross_corr_st3, k, i, nb_cbk_search)[ j ] = - scratch_mem[ idx + j ]; - } - } - target_ptr += sf_length; - } - RESTORE_STACK; -} - -/********************************************************************/ -/* Calculate the energies for first two subframes. The energies are */ -/* calculated recursively. */ -/********************************************************************/ -static void silk_P_Ana_calc_energy_st3( - silk_pe_stage3_vals energies_st3[], /* O 3 DIM energy array */ - const opus_int16 frame[], /* I vector to calc energy in */ - opus_int start_lag, /* I lag offset to search around */ - opus_int sf_length, /* I length of one 5 ms subframe */ - opus_int nb_subfr, /* I number of subframes */ - opus_int complexity, /* I Complexity setting */ - int arch /* I Run-time architecture */ -) { - const opus_int16 *target_ptr, *basis_ptr; - opus_int32 energy; - opus_int k, i, j, lag_counter; - opus_int nb_cbk_search, delta, idx, cbk_size, lag_diff; - VARDECL(opus_int32, scratch_mem); - const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; - SAVE_STACK; - - celt_assert(complexity >= SILK_PE_MIN_COMPLEX); - celt_assert(complexity <= SILK_PE_MAX_COMPLEX); - - if (nb_subfr == PE_MAX_NB_SUBFR) { - Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; - Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; - nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ]; - cbk_size = PE_NB_CBKS_STAGE3_MAX; - } else { - celt_assert(nb_subfr == PE_MAX_NB_SUBFR >> 1); - Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; - Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; - nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; - cbk_size = PE_NB_CBKS_STAGE3_10MS; - } - ALLOC(scratch_mem, SCRATCH_SIZE, opus_int32); - - target_ptr = &frame[ silk_LSHIFT(sf_length, 2) ]; - for (k = 0; k < nb_subfr; k++) { - lag_counter = 0; - - /* Calculate the energy for first lag */ - basis_ptr = target_ptr - (start_lag + matrix_ptr(Lag_range_ptr, k, 0, 2)); - energy = silk_inner_prod_aligned(basis_ptr, basis_ptr, sf_length, arch); - silk_assert(energy >= 0); - scratch_mem[ lag_counter ] = energy; - lag_counter++; - - lag_diff = (matrix_ptr(Lag_range_ptr, k, 1, 2) - matrix_ptr(Lag_range_ptr, k, 0, 2) + 1); - for (i = 1; i < lag_diff; i++) { - /* remove part outside new window */ - energy -= silk_SMULBB(basis_ptr[ sf_length - i ], basis_ptr[ sf_length - i ]); - silk_assert(energy >= 0); - - /* add part that comes into window */ - energy = silk_ADD_SAT32(energy, silk_SMULBB(basis_ptr[ -i ], basis_ptr[ -i ])); - silk_assert(energy >= 0); - silk_assert(lag_counter < SCRATCH_SIZE); - scratch_mem[ lag_counter ] = energy; - lag_counter++; - } - - delta = matrix_ptr(Lag_range_ptr, k, 0, 2); - for (i = 0; i < nb_cbk_search; i++) { - /* Fill out the 3 dim array that stores the correlations for */ - /* each code_book vector for each start lag */ - idx = matrix_ptr(Lag_CB_ptr, k, i, cbk_size) - delta; - for (j = 0; j < PE_NB_STAGE3_LAGS; j++) { - silk_assert(idx + j < SCRATCH_SIZE); - silk_assert(idx + j < lag_counter); - matrix_ptr(energies_st3, k, i, nb_cbk_search)[ j ] = - scratch_mem[ idx + j ]; - silk_assert( - matrix_ptr(energies_st3, k, i, nb_cbk_search)[ j ] >= 0); - } - } - target_ptr += sf_length; - } - RESTORE_STACK; -} diff --git a/src/libopus/silk/fixed/pitch_analysis_core_FIX.lo b/src/libopus/silk/fixed/pitch_analysis_core_FIX.lo deleted file mode 100644 index 46ccdff..0000000 --- a/src/libopus/silk/fixed/pitch_analysis_core_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/pitch_analysis_core_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/pitch_analysis_core_FIX.o' - -# Name of the non-PIC object -non_pic_object='pitch_analysis_core_FIX.o' - diff --git a/src/libopus/silk/fixed/pitch_analysis_core_FIX.o b/src/libopus/silk/fixed/pitch_analysis_core_FIX.o deleted file mode 100644 index 351cae6a3810007fa7d7b14546341829f45633e3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 59144 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 diff --git a/src/libopus/silk/fixed/pitch_est_defines.h b/src/libopus/silk/fixed/pitch_est_defines.h new file mode 100644 index 0000000..77b7e3d --- /dev/null +++ b/src/libopus/silk/fixed/pitch_est_defines.h @@ -0,0 +1 @@ +#include "../pitch_est_defines.h" diff --git a/src/libopus/silk/fixed/process_gains_FIX.c b/src/libopus/silk/fixed/process_gains_FIX.c index 1d09b0e..fb3a4fe 100644 --- a/src/libopus/silk/fixed/process_gains_FIX.c +++ b/src/libopus/silk/fixed/process_gains_FIX.c @@ -1,101 +1,102 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" -#include "../tuning_parameters.h" +#include "tuning_parameters.h" /* Processing of gains */ void silk_process_gains_FIX( silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */ opus_int condCoding /* I The type of conditional coding to use */ -) { +) +{ silk_shape_state_FIX *psShapeSt = &psEnc->sShape; opus_int k; opus_int32 s_Q16, InvMaxSqrVal_Q16, gain, gain_squared, ResNrg, ResNrgPart, quant_offset_Q10; /* Gain reduction when LTP coding gain is high */ - if (psEnc->sCmn.indices.signalType == TYPE_VOICED) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { /*s = -0.5f * silk_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); */ - s_Q16 = -silk_sigm_Q15(silk_RSHIFT_ROUND(psEncCtrl->LTPredCodGain_Q7 - SILK_FIX_CONST(12.0, 7), 4)); - for (k = 0; k < psEnc->sCmn.nb_subfr; k++) { - psEncCtrl->Gains_Q16[ k ] = silk_SMLAWB(psEncCtrl->Gains_Q16[ k ], psEncCtrl->Gains_Q16[ k ], s_Q16); + s_Q16 = -silk_sigm_Q15( silk_RSHIFT_ROUND( psEncCtrl->LTPredCodGain_Q7 - SILK_FIX_CONST( 12.0, 7 ), 4 ) ); + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { + psEncCtrl->Gains_Q16[ k ] = silk_SMLAWB( psEncCtrl->Gains_Q16[ k ], psEncCtrl->Gains_Q16[ k ], s_Q16 ); } } /* Limit the quantized signal */ /* InvMaxSqrVal = pow( 2.0f, 0.33f * ( 21.0f - SNR_dB ) ) / subfr_length; */ - InvMaxSqrVal_Q16 = silk_DIV32_16(silk_log2lin( - silk_SMULWB(SILK_FIX_CONST(21 + 16 / 0.33, 7) - psEnc->sCmn.SNR_dB_Q7, SILK_FIX_CONST(0.33, 16))), psEnc->sCmn.subfr_length); + InvMaxSqrVal_Q16 = silk_DIV32_16( silk_log2lin( + silk_SMULWB( SILK_FIX_CONST( 21 + 16 / 0.33, 7 ) - psEnc->sCmn.SNR_dB_Q7, SILK_FIX_CONST( 0.33, 16 ) ) ), psEnc->sCmn.subfr_length ); - for (k = 0; k < psEnc->sCmn.nb_subfr; k++) { + for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { /* Soft limit on ratio residual energy and squared gains */ ResNrg = psEncCtrl->ResNrg[ k ]; - ResNrgPart = silk_SMULWW(ResNrg, InvMaxSqrVal_Q16); - if (psEncCtrl->ResNrgQ[ k ] > 0) { - ResNrgPart = silk_RSHIFT_ROUND(ResNrgPart, psEncCtrl->ResNrgQ[ k ]); + ResNrgPart = silk_SMULWW( ResNrg, InvMaxSqrVal_Q16 ); + if( psEncCtrl->ResNrgQ[ k ] > 0 ) { + ResNrgPart = silk_RSHIFT_ROUND( ResNrgPart, psEncCtrl->ResNrgQ[ k ] ); } else { - if (ResNrgPart >= silk_RSHIFT(silk_int32_MAX, -psEncCtrl->ResNrgQ[ k ])) { + if( ResNrgPart >= silk_RSHIFT( silk_int32_MAX, -psEncCtrl->ResNrgQ[ k ] ) ) { ResNrgPart = silk_int32_MAX; } else { - ResNrgPart = silk_LSHIFT(ResNrgPart, -psEncCtrl->ResNrgQ[ k ]); + ResNrgPart = silk_LSHIFT( ResNrgPart, -psEncCtrl->ResNrgQ[ k ] ); } } gain = psEncCtrl->Gains_Q16[ k ]; - gain_squared = silk_ADD_SAT32(ResNrgPart, silk_SMMUL(gain, gain)); - if (gain_squared < silk_int16_MAX) { + gain_squared = silk_ADD_SAT32( ResNrgPart, silk_SMMUL( gain, gain ) ); + if( gain_squared < silk_int16_MAX ) { /* recalculate with higher precision */ - gain_squared = silk_SMLAWW(silk_LSHIFT(ResNrgPart, 16), gain, gain); - silk_assert(gain_squared > 0); - gain = silk_SQRT_APPROX(gain_squared); /* Q8 */ - gain = silk_min(gain, silk_int32_MAX >> 8); - psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32(gain, 8); /* Q16 */ + gain_squared = silk_SMLAWW( silk_LSHIFT( ResNrgPart, 16 ), gain, gain ); + silk_assert( gain_squared > 0 ); + gain = silk_SQRT_APPROX( gain_squared ); /* Q8 */ + gain = silk_min( gain, silk_int32_MAX >> 8 ); + psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32( gain, 8 ); /* Q16 */ } else { - gain = silk_SQRT_APPROX(gain_squared); /* Q0 */ - gain = silk_min(gain, silk_int32_MAX >> 16); - psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32(gain, 16); /* Q16 */ + gain = silk_SQRT_APPROX( gain_squared ); /* Q0 */ + gain = silk_min( gain, silk_int32_MAX >> 16 ); + psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32( gain, 16 ); /* Q16 */ } } /* Save unquantized gains and gain Index */ - silk_memcpy(psEncCtrl->GainsUnq_Q16, psEncCtrl->Gains_Q16, psEnc->sCmn.nb_subfr * sizeof(opus_int32)); + silk_memcpy( psEncCtrl->GainsUnq_Q16, psEncCtrl->Gains_Q16, psEnc->sCmn.nb_subfr * sizeof( opus_int32 ) ); psEncCtrl->lastGainIndexPrev = psShapeSt->LastGainIndex; /* Quantize gains */ - silk_gains_quant(psEnc->sCmn.indices.GainsIndices, psEncCtrl->Gains_Q16, - &psShapeSt->LastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr); + silk_gains_quant( psEnc->sCmn.indices.GainsIndices, psEncCtrl->Gains_Q16, + &psShapeSt->LastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr ); /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */ - if (psEnc->sCmn.indices.signalType == TYPE_VOICED) { - if (psEncCtrl->LTPredCodGain_Q7 + silk_RSHIFT(psEnc->sCmn.input_tilt_Q15, 8) > SILK_FIX_CONST(1.0, 7)) { + if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { + if( psEncCtrl->LTPredCodGain_Q7 + silk_RSHIFT( psEnc->sCmn.input_tilt_Q15, 8 ) > SILK_FIX_CONST( 1.0, 7 ) ) { psEnc->sCmn.indices.quantOffsetType = 0; } else { psEnc->sCmn.indices.quantOffsetType = 1; @@ -104,13 +105,13 @@ void silk_process_gains_FIX( /* Quantizer boundary adjustment */ quant_offset_Q10 = silk_Quantization_Offsets_Q10[ psEnc->sCmn.indices.signalType >> 1 ][ psEnc->sCmn.indices.quantOffsetType ]; - psEncCtrl->Lambda_Q10 = SILK_FIX_CONST(LAMBDA_OFFSET, 10) - + silk_SMULBB(SILK_FIX_CONST(LAMBDA_DELAYED_DECISIONS, 10), psEnc->sCmn.nStatesDelayedDecision) - + silk_SMULWB(SILK_FIX_CONST(LAMBDA_SPEECH_ACT, 18), psEnc->sCmn.speech_activity_Q8) - + silk_SMULWB(SILK_FIX_CONST(LAMBDA_INPUT_QUALITY, 12), psEncCtrl->input_quality_Q14) - + silk_SMULWB(SILK_FIX_CONST(LAMBDA_CODING_QUALITY, 12), psEncCtrl->coding_quality_Q14) - + silk_SMULWB(SILK_FIX_CONST(LAMBDA_QUANT_OFFSET, 16), quant_offset_Q10); + psEncCtrl->Lambda_Q10 = SILK_FIX_CONST( LAMBDA_OFFSET, 10 ) + + silk_SMULBB( SILK_FIX_CONST( LAMBDA_DELAYED_DECISIONS, 10 ), psEnc->sCmn.nStatesDelayedDecision ) + + silk_SMULWB( SILK_FIX_CONST( LAMBDA_SPEECH_ACT, 18 ), psEnc->sCmn.speech_activity_Q8 ) + + silk_SMULWB( SILK_FIX_CONST( LAMBDA_INPUT_QUALITY, 12 ), psEncCtrl->input_quality_Q14 ) + + silk_SMULWB( SILK_FIX_CONST( LAMBDA_CODING_QUALITY, 12 ), psEncCtrl->coding_quality_Q14 ) + + silk_SMULWB( SILK_FIX_CONST( LAMBDA_QUANT_OFFSET, 16 ), quant_offset_Q10 ); - silk_assert(psEncCtrl->Lambda_Q10 > 0); - silk_assert(psEncCtrl->Lambda_Q10 < SILK_FIX_CONST(2, 10)); + silk_assert( psEncCtrl->Lambda_Q10 > 0 ); + silk_assert( psEncCtrl->Lambda_Q10 < SILK_FIX_CONST( 2, 10 ) ); } diff --git a/src/libopus/silk/fixed/process_gains_FIX.lo b/src/libopus/silk/fixed/process_gains_FIX.lo deleted file mode 100644 index 80571cc..0000000 --- a/src/libopus/silk/fixed/process_gains_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/process_gains_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/process_gains_FIX.o' - -# Name of the non-PIC object -non_pic_object='process_gains_FIX.o' - diff --git a/src/libopus/silk/fixed/process_gains_FIX.o b/src/libopus/silk/fixed/process_gains_FIX.o deleted file mode 100644 index d443070f37d72065b94f47aa77b6fa630fe8b9bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28664 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 diff --git a/src/libopus/silk/fixed/regularize_correlations_FIX.c b/src/libopus/silk/fixed/regularize_correlations_FIX.c index a09645c..0d799ec 100644 --- a/src/libopus/silk/fixed/regularize_correlations_FIX.c +++ b/src/libopus/silk/fixed/regularize_correlations_FIX.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" @@ -37,10 +37,11 @@ void silk_regularize_correlations_FIX( opus_int32 *xx, /* I/O Correlation values */ opus_int32 noise, /* I Noise to add */ opus_int D /* I Dimension of XX */ -) { +) +{ opus_int i; - for (i = 0; i < D; i++) { - matrix_ptr(&XX[ 0 ], i, i, D) = silk_ADD32(matrix_ptr(&XX[ 0 ], i, i, D), noise); + for( i = 0; i < D; i++ ) { + matrix_ptr( &XX[ 0 ], i, i, D ) = silk_ADD32( matrix_ptr( &XX[ 0 ], i, i, D ), noise ); } xx[ 0 ] += noise; } diff --git a/src/libopus/silk/fixed/regularize_correlations_FIX.lo b/src/libopus/silk/fixed/regularize_correlations_FIX.lo deleted file mode 100644 index 5e873c6..0000000 --- a/src/libopus/silk/fixed/regularize_correlations_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/regularize_correlations_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/regularize_correlations_FIX.o' - -# Name of the non-PIC object -non_pic_object='regularize_correlations_FIX.o' - diff --git a/src/libopus/silk/fixed/regularize_correlations_FIX.o b/src/libopus/silk/fixed/regularize_correlations_FIX.o deleted file mode 100644 index da672465f75156b35180e7181c1aa9de133fcf74..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11384 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 0); - celt_assert(D <= 16); - celt_assert(cQ > 0); - celt_assert(cQ < 16); + celt_assert( D >= 0 ); + celt_assert( D <= 16 ); + celt_assert( cQ > 0 ); + celt_assert( cQ < 16 ); lshifts = 16 - cQ; Qxtra = lshifts; c_max = 0; - for (i = 0; i < D; i++) { - c_max = silk_max_32(c_max, silk_abs((opus_int32)c[ i ])); + for( i = 0; i < D; i++ ) { + c_max = silk_max_32( c_max, silk_abs( (opus_int32)c[ i ] ) ); } - Qxtra = silk_min_int(Qxtra, silk_CLZ32(c_max) - 17); + Qxtra = silk_min_int( Qxtra, silk_CLZ32( c_max ) - 17 ); - w_max = silk_max_32(wXX[ 0 ], wXX[ D * D - 1 ]); - Qxtra = silk_min_int(Qxtra, silk_CLZ32(silk_MUL(D, silk_RSHIFT(silk_SMULWB(w_max, c_max), 4))) - 5); - Qxtra = silk_max_int(Qxtra, 0); - for (i = 0; i < D; i++) { - cn[ i ] = silk_LSHIFT((opus_int)c[ i ], Qxtra); - silk_assert(silk_abs(cn[i]) <= (silk_int16_MAX + 1)); /* Check that silk_SMLAWB can be used */ + w_max = silk_max_32( wXX[ 0 ], wXX[ D * D - 1 ] ); + Qxtra = silk_min_int( Qxtra, silk_CLZ32( silk_MUL( D, silk_RSHIFT( silk_SMULWB( w_max, c_max ), 4 ) ) ) - 5 ); + Qxtra = silk_max_int( Qxtra, 0 ); + for( i = 0; i < D; i++ ) { + cn[ i ] = silk_LSHIFT( ( opus_int )c[ i ], Qxtra ); + silk_assert( silk_abs(cn[i]) <= ( silk_int16_MAX + 1 ) ); /* Check that silk_SMLAWB can be used */ } lshifts -= Qxtra; /* Compute wxx - 2 * wXx * c */ tmp = 0; - for (i = 0; i < D; i++) { - tmp = silk_SMLAWB(tmp, wXx[ i ], cn[ i ]); + for( i = 0; i < D; i++ ) { + tmp = silk_SMLAWB( tmp, wXx[ i ], cn[ i ] ); } - nrg = silk_RSHIFT(wxx, 1 + lshifts) - tmp; /* Q: -lshifts - 1 */ + nrg = silk_RSHIFT( wxx, 1 + lshifts ) - tmp; /* Q: -lshifts - 1 */ /* Add c' * wXX * c, assuming wXX is symmetric */ tmp2 = 0; - for (i = 0; i < D; i++) { + for( i = 0; i < D; i++ ) { tmp = 0; pRow = &wXX[ i * D ]; - for (j = i + 1; j < D; j++) { - tmp = silk_SMLAWB(tmp, pRow[ j ], cn[ j ]); + for( j = i + 1; j < D; j++ ) { + tmp = silk_SMLAWB( tmp, pRow[ j ], cn[ j ] ); } - tmp = silk_SMLAWB(tmp, silk_RSHIFT(pRow[ i ], 1), cn[ i ]); - tmp2 = silk_SMLAWB(tmp2, tmp, cn[ i ]); + tmp = silk_SMLAWB( tmp, silk_RSHIFT( pRow[ i ], 1 ), cn[ i ] ); + tmp2 = silk_SMLAWB( tmp2, tmp, cn[ i ] ); } - nrg = silk_ADD_LSHIFT32(nrg, tmp2, lshifts); /* Q: -lshifts - 1 */ + nrg = silk_ADD_LSHIFT32( nrg, tmp2, lshifts ); /* Q: -lshifts - 1 */ /* Keep one bit free always, because we add them for LSF interpolation */ - if (nrg < 1) { + if( nrg < 1 ) { nrg = 1; - } else if (nrg > silk_RSHIFT(silk_int32_MAX, lshifts + 2)) { + } else if( nrg > silk_RSHIFT( silk_int32_MAX, lshifts + 2 ) ) { nrg = silk_int32_MAX >> 1; } else { - nrg = silk_LSHIFT(nrg, lshifts + 1); /* Q0 */ + nrg = silk_LSHIFT( nrg, lshifts + 1 ); /* Q0 */ } return nrg; diff --git a/src/libopus/silk/fixed/residual_energy16_FIX.lo b/src/libopus/silk/fixed/residual_energy16_FIX.lo deleted file mode 100644 index 1bcfabe..0000000 --- a/src/libopus/silk/fixed/residual_energy16_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/residual_energy16_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/residual_energy16_FIX.o' - -# Name of the non-PIC object -non_pic_object='residual_energy16_FIX.o' - diff --git a/src/libopus/silk/fixed/residual_energy16_FIX.o b/src/libopus/silk/fixed/residual_energy16_FIX.o deleted file mode 100644 index 4524d65e9f111ecc8cbf0c000b97ef35be9bdb1a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18976 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 wU4UmH1}HH6w^;ns%VTn+a diff --git a/src/libopus/silk/fixed/residual_energy_FIX.c b/src/libopus/silk/fixed/residual_energy_FIX.c index fc279a4..14a5a31 100644 --- a/src/libopus/silk/fixed/residual_energy_FIX.c +++ b/src/libopus/silk/fixed/residual_energy_FIX.c @@ -1,53 +1,54 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" -#include "../../celt/stack_alloc.h" +#include "stack_alloc.h" /* Calculates residual energies of input subframes where all subframes have LPC_order */ /* of preceding samples */ void silk_residual_energy_FIX( - opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ - opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ + opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ + opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ const opus_int16 x[], /* I Input signal */ - opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ + opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ const opus_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */ const opus_int subfr_length, /* I Subframe length */ const opus_int nb_subfr, /* I Number of subframes */ const opus_int LPC_order, /* I LPC order */ - int arch /* I Run-time architecture */ -) { + int arch /* I Run-time architecture */ +) +{ opus_int offset, i, j, rshift, lz1, lz2; opus_int16 *LPC_res_ptr; - VARDECL(opus_int16, LPC_res); + VARDECL( opus_int16, LPC_res ); const opus_int16 *x_ptr; opus_int32 tmp32; SAVE_STACK; @@ -56,41 +57,41 @@ void silk_residual_energy_FIX( offset = LPC_order + subfr_length; /* Filter input to create the LPC residual for each frame half, and measure subframe energies */ - ALLOC(LPC_res, (MAX_NB_SUBFR >> 1) * offset, opus_int16); - celt_assert((nb_subfr >> 1) * (MAX_NB_SUBFR >> 1) == nb_subfr); - for (i = 0; i < nb_subfr >> 1; i++) { + ALLOC( LPC_res, ( MAX_NB_SUBFR >> 1 ) * offset, opus_int16 ); + celt_assert( ( nb_subfr >> 1 ) * ( MAX_NB_SUBFR >> 1 ) == nb_subfr ); + for( i = 0; i < nb_subfr >> 1; i++ ) { /* Calculate half frame LPC residual signal including preceding samples */ - silk_LPC_analysis_filter(LPC_res, x_ptr, a_Q12[ i ], (MAX_NB_SUBFR >> 1) * offset, LPC_order, arch); + silk_LPC_analysis_filter( LPC_res, x_ptr, a_Q12[ i ], ( MAX_NB_SUBFR >> 1 ) * offset, LPC_order, arch ); /* Point to first subframe of the just calculated LPC residual signal */ LPC_res_ptr = LPC_res + LPC_order; - for (j = 0; j < (MAX_NB_SUBFR >> 1); j++) { + for( j = 0; j < ( MAX_NB_SUBFR >> 1 ); j++ ) { /* Measure subframe energy */ - silk_sum_sqr_shift(&nrgs[ i * (MAX_NB_SUBFR >> 1) + j ], &rshift, LPC_res_ptr, subfr_length); + silk_sum_sqr_shift( &nrgs[ i * ( MAX_NB_SUBFR >> 1 ) + j ], &rshift, LPC_res_ptr, subfr_length ); /* Set Q values for the measured energy */ - nrgsQ[ i * (MAX_NB_SUBFR >> 1) + j ] = -rshift; + nrgsQ[ i * ( MAX_NB_SUBFR >> 1 ) + j ] = -rshift; /* Move to next subframe */ LPC_res_ptr += offset; } /* Move to next frame half */ - x_ptr += (MAX_NB_SUBFR >> 1) * offset; + x_ptr += ( MAX_NB_SUBFR >> 1 ) * offset; } /* Apply the squared subframe gains */ - for (i = 0; i < nb_subfr; i++) { + for( i = 0; i < nb_subfr; i++ ) { /* Fully upscale gains and energies */ - lz1 = silk_CLZ32(nrgs[ i ]) - 1; - lz2 = silk_CLZ32(gains[ i ]) - 1; + lz1 = silk_CLZ32( nrgs[ i ] ) - 1; + lz2 = silk_CLZ32( gains[ i ] ) - 1; - tmp32 = silk_LSHIFT32(gains[ i ], lz2); + tmp32 = silk_LSHIFT32( gains[ i ], lz2 ); /* Find squared gains */ - tmp32 = silk_SMMUL(tmp32, tmp32); /* Q( 2 * lz2 - 32 )*/ + tmp32 = silk_SMMUL( tmp32, tmp32 ); /* Q( 2 * lz2 - 32 )*/ /* Scale energies */ - nrgs[ i ] = silk_SMMUL(tmp32, silk_LSHIFT32(nrgs[ i ], lz1)); /* Q( nrgsQ[ i ] + lz1 + 2 * lz2 - 32 - 32 )*/ + nrgs[ i ] = silk_SMMUL( tmp32, silk_LSHIFT32( nrgs[ i ], lz1 ) ); /* Q( nrgsQ[ i ] + lz1 + 2 * lz2 - 32 - 32 )*/ nrgsQ[ i ] += lz1 + 2 * lz2 - 32 - 32; } RESTORE_STACK; diff --git a/src/libopus/silk/fixed/residual_energy_FIX.lo b/src/libopus/silk/fixed/residual_energy_FIX.lo deleted file mode 100644 index e84657c..0000000 --- a/src/libopus/silk/fixed/residual_energy_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/residual_energy_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/residual_energy_FIX.o' - -# Name of the non-PIC object -non_pic_object='residual_energy_FIX.o' - diff --git a/src/libopus/silk/fixed/residual_energy_FIX.o b/src/libopus/silk/fixed/residual_energy_FIX.o deleted file mode 100644 index 1fa2cc6253320804ef5c80f25870fbc62a400a55..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16904 zcmbVT33Qyrk?wyEd1P6KEim!{9uuD!9V5%~fv=G*GXlxhX>5c2do=S)8hbP&&tYT& zHqUzAcp?OLLK4EVF-bN+60!l3-Q@_09gby59wG49N61^kk^>U5OANt*N5EUvUG>ke z)+otKzo+@DzN)USs;=(-=l@4Xnp?NH3`1};#CnnE7!@M4HcxMqgTF0gx^T1GVtv^xz_%kDC=Z*Z<7+YKX;%m8| zhVBTy_Jc^$ZM^2<;@%^=Zv0*D( zo3hfeXf_--t%Q~8KV)uc*-;abO7Ia*r>#^bmQ48j!m+p&UE^QkPxPAUY;Rx6zka>ugn#ohAgPP6(eYTVThx5?7v=r2FMnfVh2A5O=%e z#pChD5*gv$0#K1J3ZLFilp00wDZINS?L*q_ksYKZ&w`^;Ae9udFb0Ss7o9?(%L|`` zEJ5>1xOB)Sm;DEjZl6Q%7DSZZ7?M+bMLu*vLf)$DZF1J_HaYtqo1F7KCX1?aHaYu2 zCZ{a_J&@iS$d|M@rJ)K)?|PeG@h6mTwfU7Ul<%?mRi8jUVe_j?fh_Xvgip6ePKMhj zFEV4rzcn!KV)zp;``%mX7Gf&WzH3@kxK}Y#jecMT6f;f6F{GFZ$z&8W z!*~un7*@KLfQBim5h!1%eTu1*%ma$4H>#n}!-`oheLJm~6~+jR^Q4dq!*{2ghAQ9P7^F(&mysm;D;O?K z!#!I7u7G*11FXpRb(q~!tU`3V43`k1IGYmvETfg897S^KeH#qK6}{0x2PIvBic>#@ zV=D4^p3K=~$!v6_bO(IA3!2k~_f76lG6xY_JMIcubESvC(fL41A8!`k=|D^K(-tB; zBUIY+EL>&qrQ5M+iM|GDm%?`-?NRhjq>B{23%jZWm0p_zT-9mmb%?7vE!~Z@U+M2b zdWoV3XBbJv4?_;*S7GWuWi{&oi{kbi#Ls-hE7f}|9Wfq`1 zKD4#!Q7E-mvX+mv<^!T~u^fd`Yd32dQp+d2SK3-DP^daIA}Ko@=MHY+9k%7G5SH@$ zSpEg!y~CETL0Fl(B2TW(lk1R_27b#1DunlEcCYmaOL;LIM$%V9ct5b^8xfZBr7T}6 zyt9B-qc$O|$jz8YMK&L2t0wpI2=6vqbqm7M>JgTEg*R!-uS8hNPq7?o@-|x@LRiXw z!15yD{kAQ?3Ss3+tDN5Fp`3rmsxbYp*zz`nmFiX`OZ~9LTnK+M7oh3|y2!U0*VAku zmFhOsP-MI8h4QN%y{@q39SAGcF6j$y0S6tbeYU(CVWqkqGpNXG

19`?*)S@ZM#s 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 0 && order <= SILK_MAX_ORDER_LPC); + celt_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC ); /* Check for invalid input */ - if (c[ 0 ] <= 0) { - silk_memset(rc_Q16, 0, order * sizeof(opus_int32)); + if( c[ 0 ] <= 0 ) { + silk_memset( rc_Q16, 0, order * sizeof( opus_int32 ) ); return 0; } k = 0; do { C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ]; - } while (++k <= order); + } while( ++k <= order ); - for (k = 0; k < order; k++) { + for( k = 0; k < order; k++ ) { /* Check that we won't be getting an unstable rc, otherwise stop here. */ if (silk_abs_int32(C[ k + 1 ][ 0 ]) >= C[ 0 ][ 1 ]) { - if (C[ k + 1 ][ 0 ] > 0) { - rc_Q16[ k ] = -SILK_FIX_CONST(.99f, 16); - } else { - rc_Q16[ k ] = SILK_FIX_CONST(.99f, 16); - } - k++; - break; + if ( C[ k + 1 ][ 0 ] > 0 ) { + rc_Q16[ k ] = -SILK_FIX_CONST( .99f, 16 ); + } else { + rc_Q16[ k ] = SILK_FIX_CONST( .99f, 16 ); + } + k++; + break; } /* Get reflection coefficient: divide two Q30 values and get result in Q31 */ - rc_tmp_Q31 = silk_DIV32_varQ(-C[ k + 1 ][ 0 ], C[ 0 ][ 1 ], 31); + rc_tmp_Q31 = silk_DIV32_varQ( -C[ k + 1 ][ 0 ], C[ 0 ][ 1 ], 31 ); /* Save the output */ - rc_Q16[ k ] = silk_RSHIFT_ROUND(rc_tmp_Q31, 15); + rc_Q16[ k ] = silk_RSHIFT_ROUND( rc_tmp_Q31, 15 ); /* Update correlations */ - for (n = 0; n < order - k; n++) { + for( n = 0; n < order - k; n++ ) { Ctmp1_Q30 = C[ n + k + 1 ][ 0 ]; Ctmp2_Q30 = C[ n ][ 1 ]; /* Multiply and add the highest int32 */ - C[ n + k + 1 ][ 0 ] = Ctmp1_Q30 + silk_SMMUL(silk_LSHIFT(Ctmp2_Q30, 1), rc_tmp_Q31); - C[ n ][ 1 ] = Ctmp2_Q30 + silk_SMMUL(silk_LSHIFT(Ctmp1_Q30, 1), rc_tmp_Q31); + C[ n + k + 1 ][ 0 ] = Ctmp1_Q30 + silk_SMMUL( silk_LSHIFT( Ctmp2_Q30, 1 ), rc_tmp_Q31 ); + C[ n ][ 1 ] = Ctmp2_Q30 + silk_SMMUL( silk_LSHIFT( Ctmp1_Q30, 1 ), rc_tmp_Q31 ); } } - for (; k < order; k++) { - rc_Q16[ k ] = 0; + for(; k < order; k++ ) { + rc_Q16[ k ] = 0; } - return silk_max_32(1, C[ 0 ][ 1 ]); + return silk_max_32( 1, C[ 0 ][ 1 ] ); } diff --git a/src/libopus/silk/fixed/schur64_FIX.lo b/src/libopus/silk/fixed/schur64_FIX.lo deleted file mode 100644 index 644480e..0000000 --- a/src/libopus/silk/fixed/schur64_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/schur64_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/schur64_FIX.o' - -# Name of the non-PIC object -non_pic_object='schur64_FIX.o' - diff --git a/src/libopus/silk/fixed/schur64_FIX.o b/src/libopus/silk/fixed/schur64_FIX.o deleted file mode 100644 index 94d69ae9b4a4d53e85820df76dbe035716cc6b8e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13272 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 0 && order <= SILK_MAX_ORDER_LPC); + celt_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC ); /* Get number of leading zeros */ - lz = silk_CLZ32(c[ 0 ]); + lz = silk_CLZ32( c[ 0 ] ); /* Copy correlations and adjust level to Q30 */ k = 0; - if (lz < 2) { + if( lz < 2 ) { /* lz must be 1, so shift one to the right */ do { - C[ k ][ 0 ] = C[ k ][ 1 ] = silk_RSHIFT(c[ k ], 1); - } while (++k <= order); - } else if (lz > 2) { + C[ k ][ 0 ] = C[ k ][ 1 ] = silk_RSHIFT( c[ k ], 1 ); + } while( ++k <= order ); + } else if( lz > 2 ) { /* Shift to the left */ lz -= 2; do { - C[ k ][ 0 ] = C[ k ][ 1 ] = silk_LSHIFT(c[ k ], lz); - } while (++k <= order); + C[ k ][ 0 ] = C[ k ][ 1 ] = silk_LSHIFT( c[ k ], lz ); + } while( ++k <= order ); } else { /* No need to shift */ do { C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ]; - } while (++k <= order); + } while( ++k <= order ); } - for (k = 0; k < order; k++) { + for( k = 0; k < order; k++ ) { /* Check that we won't be getting an unstable rc, otherwise stop here. */ if (silk_abs_int32(C[ k + 1 ][ 0 ]) >= C[ 0 ][ 1 ]) { - if (C[ k + 1 ][ 0 ] > 0) { - rc_Q15[ k ] = -SILK_FIX_CONST(.99f, 15); - } else { - rc_Q15[ k ] = SILK_FIX_CONST(.99f, 15); - } - k++; - break; + if ( C[ k + 1 ][ 0 ] > 0 ) { + rc_Q15[ k ] = -SILK_FIX_CONST( .99f, 15 ); + } else { + rc_Q15[ k ] = SILK_FIX_CONST( .99f, 15 ); + } + k++; + break; } /* Get reflection coefficient */ - rc_tmp_Q15 = -silk_DIV32_16(C[ k + 1 ][ 0 ], silk_max_32(silk_RSHIFT(C[ 0 ][ 1 ], 15), 1)); + rc_tmp_Q15 = -silk_DIV32_16( C[ k + 1 ][ 0 ], silk_max_32( silk_RSHIFT( C[ 0 ][ 1 ], 15 ), 1 ) ); /* Clip (shouldn't happen for properly conditioned inputs) */ - rc_tmp_Q15 = silk_SAT16(rc_tmp_Q15); + rc_tmp_Q15 = silk_SAT16( rc_tmp_Q15 ); /* Store */ rc_Q15[ k ] = (opus_int16)rc_tmp_Q15; /* Update correlations */ - for (n = 0; n < order - k; n++) { + for( n = 0; n < order - k; n++ ) { Ctmp1 = C[ n + k + 1 ][ 0 ]; Ctmp2 = C[ n ][ 1 ]; - C[ n + k + 1 ][ 0 ] = silk_SMLAWB(Ctmp1, silk_LSHIFT(Ctmp2, 1), rc_tmp_Q15); - C[ n ][ 1 ] = silk_SMLAWB(Ctmp2, silk_LSHIFT(Ctmp1, 1), rc_tmp_Q15); + C[ n + k + 1 ][ 0 ] = silk_SMLAWB( Ctmp1, silk_LSHIFT( Ctmp2, 1 ), rc_tmp_Q15 ); + C[ n ][ 1 ] = silk_SMLAWB( Ctmp2, silk_LSHIFT( Ctmp1, 1 ), rc_tmp_Q15 ); } } - for (; k < order; k++) { - rc_Q15[ k ] = 0; + for(; k < order; k++ ) { + rc_Q15[ k ] = 0; } /* return residual energy */ - return silk_max_32(1, C[ 0 ][ 1 ]); + return silk_max_32( 1, C[ 0 ][ 1 ] ); } diff --git a/src/libopus/silk/fixed/schur_FIX.lo b/src/libopus/silk/fixed/schur_FIX.lo deleted file mode 100644 index f98ce3d..0000000 --- a/src/libopus/silk/fixed/schur_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/schur_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/schur_FIX.o' - -# Name of the non-PIC object -non_pic_object='schur_FIX.o' - diff --git a/src/libopus/silk/fixed/schur_FIX.o b/src/libopus/silk/fixed/schur_FIX.o deleted file mode 100644 index 36c8f8b045637687e81d7360398059e091a2fc84..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10528 zcmbtadw5jGb)UO;C00o63dBP^5-lJwIA~WZ0Tu)qRu5Pa5gw9aO6*)#`;gYGc9ne) z#Ajo$EaRJ|pfmO3P%zuaf zGyWcbcTZQ~(0^Y9K{zmKU$P8{K<-Un9k9dKY_5^zpp$#OBln+ye8rdS*!T6zWl>j68+5hL_UGDm*!?;Cj==Ca zdtl9L*~_DuTKmWwxht**+Q7tUTdm_Ue{Rfo&VTlunl|m+n)hA#^B~CY8Q+pmRrqsn z_`eG*^M4=f!0->W=rMopy)B`){AaJa+DFFPU7!BJWBw1Wo*BQ7v1aYy`1n1p4=$cz zKs00J+VX1q$Q#j?T=&)+2YPcC1Fq-Z_vc<|TYkPHzr(&IZ-4RfR9DSGFwWXW*S6*> z*0+qdy>vYgx)5-E>*c`NYn9sBmR#pc*Yg$N{+vS!a_0kQuU7i=6;pDXuXe0?HG6in zv(}z_xpU2rG6St(!qJ`|()`1hwT|JlnmWcKP2=O^oAVWYBV%U*hsMWGpFRNT-FmKV z&4b4i$K2n4x6jy0SuG*E(C_hY|&icMgaU?8TrF$%#Ca7 zi-FO9;?oxnG_K?G=^FVaNCJmmz*+w6UH&`$clkf(H=Y;s^WBdFn)?OJU1#1d=dL7r z4Cd{}Z%&vw9N(o&{u|@t>QtAyYH*%kyE;K1XZq5m>7XCTUGqPO;a!>mBObnFyL>c| zUj;l1Uh4y1Lv=prQCR>@MFIo$?9 zFeZ>?8%=Wg9+UjU(?IGDi{24LM3+30Qye7@bjG35xkDy7Z`35`pOWO1d0&>KW7TUW zdD}06EX7Q4GmfVBP0^aSfz<6hSGt2Yd{k2}X&7-C{IQE=zdsKhry^bU2ZV|K@P|M; z1b!XqNN)dwf@#p|pwDT+H1gQS1hYz81b$u+ z>$dDGd>X3DPU0X%Do-Iv^brEbsulpcZ8x zvug0k15msB+Y`0$+0081^!XLYYP6m*NRucvTDO(iZgY5;TMBohmlDTEyvCGF!*QWk zKH=58*4RSS*VoxlsN=8}1tq(vS5j;-YT5R2B@Csuz_TStW0~e(DhQ~x>Dm%!Rk`k* z@0_m9m{K_hy3c01b8Y!2%R6A6^jcP4emltFflMTTcJU~I6m zstc~M=iCCz*u0NvzN#Hs&zzm*f5yi;zl8a!P;CJcu#QjxC^xseh{A`YF}9fGQ8^tZK!lH4 z>BT{&7gMY1{{sPI)V@S59{Y-w`C!M!)q}(4w|QfUP&^xs2t8sZ>-EMmX|PyK8Q@SPo?*;-?1xwe zf}vD0?diwVb;bI&rII0jC*VLj6AnkBAcPlVW@s>idhn_Q7>?<6@RyhXWD7`gFq<}H z7kI6~&|*oUJP^$E163;QAc*8p+K8l5@mM+|w1TM+YVo6fnK>i+GR-l=(Rkc$(=V{i zc1{1@eLwpWvjI_NTMW-*yLRFDNxQE9UbijR0R8ekXMlTGf1J~q(O=kymf%u96!hU>tOR=^_^hznR_0GP+T@I zI0K2Mw>cii_P_MKjwlkR1XsyXJ>u}_&5jJ*Q#8#mlF_J|a$6k&S2{mFrdHxf+6BVK?%O=8JoWCnflM|LY3_?ah_Mi`xR{$^SJ$mx>8|T@*KKWZ*G2cn(y%GwvCL3& ze+>3n0%&qX3(IB}_vvE8?dgE$JD z7)mcJlcJvlqVZ%9v<8!D>*j=E^C?W@D&rGu=8ms3G-kAR?rLnH)Z*M4dow{;D(30{ z&$O5!cLomt%h(9Lj2s_U@+{1zR;j^Xc|ScQZ$gVY$BVEfK==~5iNg+@(tD(9N?+! zg{ZTGV$HNdWIl#<1E$FgN=yfjifw9bUF%-f)0<6XvSQiPHD)>IJK$^b)URAFPNqfK=-0p@ou10B$XJ}pkiCOEL)w16vk>R%Zzrl7-lqgc`Tb$PNx$M;8( zqBD3&6e&8s9EucOycs4*bnykH2rh4e6Gb{JK60H+o2W>f&fs2Er0C*qK1rgBdv_5W zE(1yt9w+C4-`sDShv|wHxC8+*!&aCVc>r1jIRAp6^k}*X-g*;!!V$vL*;>z_f=4NC zeX%i&O`Tg?{GGGQ7|fFnyGpc-4wYoRZF zA%tIMu}C{|FMm?NChj8pEeif1;h$CTdN{3N=@X4<2fspLNr=Y8OGqIe!raQsM$@9 z!N(~6cNF|>vh!O7zlHD{3ci>4GMXP5=QoL;tKi+_w^qTkWZ$RYCrQ6a!OxQ4W(9wq z>~tvjL9)}M;7^d9pn}UiGoavyNPkGdcah%_1^-{dA69TL@n2W)-4y3vD>(ms1AITL z;D1H&yrAHZ5&xQk|B&MOcLnb!{IY^SOYvM)aQR#)A-SA)x!-0exV*8~DEN7be}#ho zBjIZl{4((y6?`%2cPaRHC~lco8Rt((e?ZY6p*+Y>9#a1Z;fEFd;spQa_o8g{0r4;O(T} zrr>`hTt1(q9sF$q%bkk;bpf+J1%HwJrWE|!#NVsn^11M+g8vQ0^9=<*P5d*|qB~OM z5xt=3CrJ3R1?NAcQ2cKwcrW2^T5x>-ZYKO)3yyaFhwu*+{CUcQ_)$%~Pf`DK6px#Z zoHEZcj$17_>dW(o*Meg_Z;`*X3cjB3HVck+o*}w13_^$<6zN6reko|wL;PQ-w`aiMY)>G-PEjXHx=S%ob&x_3S zRGBvg{~7t+tl$Sp|1%0M&keh7f(I3RHra{X1easPIQjP_5w>|Ymh(k0ljl1Xcas7R zhlV5&PkLwoZoJF`*LTtOODYwK2R#|QuX@7pk%f7B)9}SEl|%;Beeg|U0^0;E_6bLN zvwd*;jV7Tdr-Qw{smNZ*!L5FRW-t{@^hLn7P?ns<7JOceNHKV3o=|dNAOhEQPXaza zc;J%;e13piEt!q<8_`s7AVP!we>86Bi@B8ZAWdx`Larx?t9O?9AiyQKK`KzY4=+AY zcJo@?3DA!`xA31DfnN%Lh|@9wN)-8iki2YB*IHHpgEs%v{`ed~n+@=1Ez&;?!xTyX zvfTiZV*RhuB3x(o6oeeV?B7lO6*ab!26Q*=8!4ClB)=7iV)?&Ffs0?pMgDPrN&hnc zy8%;e0>mCC#g7!B!t(oziedk+;)aHTKfPOvs(S#0Du(*c;=>+_e2xlkvhENFijDux zg`$V-kLN*rF013u16Iuc+vI;Y$gM@yJqbb;L;X!otl^jJ2@j*mx?csIV)0il;@#nY z*hInj(WDyx(}1CWIZhyXiPA>Bag+SZn4bmhV*SH2g`HbPW7e{tY{x(%X;TS^qtxGu zA+75ElrSYt>=^a$R}9GUOZZhFisf%vk^JFT9@$^!72{ETqwTBYe;En!+eNYdcs5W{ fjNO@=_Fp&W3Y9v3{H{@~{|1WxKMGwrrS|_n+9?Po diff --git a/src/libopus/silk/fixed/stack_alloc.h b/src/libopus/silk/fixed/stack_alloc.h new file mode 100644 index 0000000..7b53013 --- /dev/null +++ b/src/libopus/silk/fixed/stack_alloc.h @@ -0,0 +1 @@ +#include "../../celt/stack_alloc.h" diff --git a/src/libopus/silk/fixed/structs.h b/src/libopus/silk/fixed/structs.h new file mode 100644 index 0000000..e564d5d --- /dev/null +++ b/src/libopus/silk/fixed/structs.h @@ -0,0 +1 @@ +#include "../structs.h" diff --git a/src/libopus/silk/fixed/structs_FIX.h b/src/libopus/silk/fixed/structs_FIX.h index bcd6b20..2774a97 100644 --- a/src/libopus/silk/fixed/structs_FIX.h +++ b/src/libopus/silk/fixed/structs_FIX.h @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_STRUCTS_FIX_H #define SILK_STRUCTS_FIX_H -#include "../typedef.h" -#include "../main.h" -#include "../structs.h" +#include "typedef.h" +#include "main.h" +#include "structs.h" #ifdef __cplusplus extern "C" diff --git a/src/libopus/silk/fixed/tuning_parameters.h b/src/libopus/silk/fixed/tuning_parameters.h new file mode 100644 index 0000000..b2cb638 --- /dev/null +++ b/src/libopus/silk/fixed/tuning_parameters.h @@ -0,0 +1 @@ +#include "../tuning_parameters.h" diff --git a/src/libopus/silk/fixed/typedef.h b/src/libopus/silk/fixed/typedef.h new file mode 100644 index 0000000..95a45fd --- /dev/null +++ b/src/libopus/silk/fixed/typedef.h @@ -0,0 +1 @@ +#include "../typedef.h" diff --git a/src/libopus/silk/fixed/vector_ops_FIX.c b/src/libopus/silk/fixed/vector_ops_FIX.c index 24b3f94..dee2225 100644 --- a/src/libopus/silk/fixed/vector_ops_FIX.c +++ b/src/libopus/silk/fixed/vector_ops_FIX.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif -#include "../SigProc_FIX.h" -#include "../../celt/pitch.h" +#include "SigProc_FIX.h" +#include "pitch.h" /* Copy and multiply a vector by a constant */ void silk_scale_copy_vector16( @@ -38,13 +38,14 @@ void silk_scale_copy_vector16( const opus_int16 *data_in, opus_int32 gain_Q16, /* I Gain in Q16 */ const opus_int dataSize /* I Length */ -) { +) +{ opus_int i; opus_int32 tmp32; - for (i = 0; i < dataSize; i++) { - tmp32 = silk_SMULWB(gain_Q16, data_in[ i ]); - data_out[ i ] = (opus_int16)silk_CHECK_FIT16(tmp32); + for( i = 0; i < dataSize; i++ ) { + tmp32 = silk_SMULWB( gain_Q16, data_in[ i ] ); + data_out[ i ] = (opus_int16)silk_CHECK_FIT16( tmp32 ); } } @@ -53,11 +54,12 @@ void silk_scale_vector32_Q26_lshift_18( opus_int32 *data1, /* I/O Q0/Q18 */ opus_int32 gain_Q26, /* I Q26 */ opus_int dataSize /* I length */ -) { +) +{ opus_int i; - for (i = 0; i < dataSize; i++) { - data1[ i ] = (opus_int32)silk_CHECK_FIT32(silk_RSHIFT64(silk_SMULL(data1[ i ], gain_Q26), 8)); /* OUTPUT: Q18 */ + for( i = 0; i < dataSize; i++ ) { + data1[ i ] = (opus_int32)silk_CHECK_FIT32( silk_RSHIFT64( silk_SMULL( data1[ i ], gain_Q26 ), 8 ) ); /* OUTPUT: Q18 */ } } @@ -71,28 +73,30 @@ opus_int32 silk_inner_prod_aligned( const opus_int16 *const inVec2, /* I input vector 2 */ const opus_int len, /* I vector lengths */ int arch /* I Run-time architecture */ -) { +) +{ #ifdef FIXED_POINT - return celt_inner_prod(inVec1, inVec2, len, arch); + return celt_inner_prod(inVec1, inVec2, len, arch); #else opus_int i; opus_int32 sum = 0; - for (i = 0; i < len; i++) { - sum = silk_SMLABB(sum, inVec1[ i ], inVec2[ i ]); + for( i = 0; i < len; i++ ) { + sum = silk_SMLABB( sum, inVec1[ i ], inVec2[ i ] ); } return sum; #endif } -opus_int64 silk_inner_prod16_aligned_64_c( +opus_int64 silk_inner_prod16_c( const opus_int16 *inVec1, /* I input vector 1 */ const opus_int16 *inVec2, /* I input vector 2 */ const opus_int len /* I vector lengths */ -) { +) +{ opus_int i; opus_int64 sum = 0; - for (i = 0; i < len; i++) { - sum = silk_SMLALBB(sum, inVec1[ i ], inVec2[ i ]); + for( i = 0; i < len; i++ ) { + sum = silk_SMLALBB( sum, inVec1[ i ], inVec2[ i ] ); } return sum; } diff --git a/src/libopus/silk/fixed/vector_ops_FIX.lo b/src/libopus/silk/fixed/vector_ops_FIX.lo deleted file mode 100644 index 1e7ba8f..0000000 --- a/src/libopus/silk/fixed/vector_ops_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/vector_ops_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/vector_ops_FIX.o' - -# Name of the non-PIC object -non_pic_object='vector_ops_FIX.o' - diff --git a/src/libopus/silk/fixed/vector_ops_FIX.o b/src/libopus/silk/fixed/vector_ops_FIX.o deleted file mode 100644 index bc0f42d662f6092fcc1b02fa25a998aea832e9c1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10680 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 RDrE1QqD+2~vs8j^|6lADqrU(E diff --git a/src/libopus/silk/fixed/warped_autocorrelation_FIX.c b/src/libopus/silk/fixed/warped_autocorrelation_FIX.c index ed51507..473e28e 100644 --- a/src/libopus/silk/fixed/warped_autocorrelation_FIX.c +++ b/src/libopus/silk/fixed/warped_autocorrelation_FIX.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main_FIX.h" @@ -39,55 +39,54 @@ /* Autocorrelations for a warped frequency axis */ #ifndef OVERRIDE_silk_warped_autocorrelation_FIX_c void silk_warped_autocorrelation_FIX_c( - opus_int32 *corr, /* O Result [order + 1] */ - opus_int *scale, /* O Scaling of the correlation vector */ + opus_int32 *corr, /* O Result [order + 1] */ + opus_int *scale, /* O Scaling of the correlation vector */ const opus_int16 *input, /* I Input data to correlate */ const opus_int warping_Q16, /* I Warping coefficient */ const opus_int length, /* I Length of input */ const opus_int order /* I Correlation order (even) */ -) { +) +{ opus_int n, i, lsh; opus_int32 tmp1_QS, tmp2_QS; - opus_int32 *state_QS = (opus_int32*)calloc(MAX_SHAPE_LPC_ORDER + 1, sizeof(opus_int32)); - opus_int64 *corr_QC = (opus_int64*)calloc(MAX_SHAPE_LPC_ORDER + 1, sizeof(opus_int64)); + opus_int32 state_QS[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; + opus_int64 corr_QC[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; /* Order must be even */ - celt_assert((order & 1) == 0); - silk_assert(2 * QS - QC >= 0); + celt_assert( ( order & 1 ) == 0 ); + silk_assert( 2 * QS - QC >= 0 ); /* Loop over samples */ - for (n = 0; n < length; n++) { - tmp1_QS = silk_LSHIFT32((opus_int32)input[ n ], QS); + for( n = 0; n < length; n++ ) { + tmp1_QS = silk_LSHIFT32( (opus_int32)input[ n ], QS ); /* Loop over allpass sections */ - for (i = 0; i < order; i += 2) { + for( i = 0; i < order; i += 2 ) { /* Output of allpass section */ - tmp2_QS = silk_SMLAWB(state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16); + tmp2_QS = silk_SMLAWB( state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16 ); state_QS[ i ] = tmp1_QS; - corr_QC[ i ] += silk_RSHIFT64(silk_SMULL(tmp1_QS, state_QS[ 0 ]), 2 * QS - QC); + corr_QC[ i ] += silk_RSHIFT64( silk_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC ); /* Output of allpass section */ - tmp1_QS = silk_SMLAWB(state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16); + tmp1_QS = silk_SMLAWB( state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16 ); state_QS[ i + 1 ] = tmp2_QS; - corr_QC[ i + 1 ] += silk_RSHIFT64(silk_SMULL(tmp2_QS, state_QS[ 0 ]), 2 * QS - QC); + corr_QC[ i + 1 ] += silk_RSHIFT64( silk_SMULL( tmp2_QS, state_QS[ 0 ] ), 2 * QS - QC ); } state_QS[ order ] = tmp1_QS; - corr_QC[ order ] += silk_RSHIFT64(silk_SMULL(tmp1_QS, state_QS[ 0 ]), 2 * QS - QC); + corr_QC[ order ] += silk_RSHIFT64( silk_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC ); } - lsh = silk_CLZ64(corr_QC[ 0 ]) - 35; - lsh = silk_LIMIT(lsh, -12 - QC, 30 - QC); - *scale = -(QC + lsh); - silk_assert(*scale >= -30 && *scale <= 12); - if (lsh >= 0) { - for (i = 0; i < order + 1; i++) { - corr[ i ] = (opus_int32)silk_CHECK_FIT32(silk_LSHIFT64(corr_QC[ i ], lsh)); + lsh = silk_CLZ64( corr_QC[ 0 ] ) - 35; + lsh = silk_LIMIT( lsh, -12 - QC, 30 - QC ); + *scale = -( QC + lsh ); + silk_assert( *scale >= -30 && *scale <= 12 ); + if( lsh >= 0 ) { + for( i = 0; i < order + 1; i++ ) { + corr[ i ] = (opus_int32)silk_CHECK_FIT32( silk_LSHIFT64( corr_QC[ i ], lsh ) ); } } else { - for (i = 0; i < order + 1; i++) { - corr[ i ] = (opus_int32)silk_CHECK_FIT32(silk_RSHIFT64(corr_QC[ i ], -lsh)); + for( i = 0; i < order + 1; i++ ) { + corr[ i ] = (opus_int32)silk_CHECK_FIT32( silk_RSHIFT64( corr_QC[ i ], -lsh ) ); } } - silk_assert(corr_QC[ 0 ] >= 0); /* If breaking, decrease QC*/ - free(state_QS); - free(corr_QC); + silk_assert( corr_QC[ 0 ] >= 0 ); /* If breaking, decrease QC*/ } #endif /* OVERRIDE_silk_warped_autocorrelation_FIX_c */ diff --git a/src/libopus/silk/fixed/warped_autocorrelation_FIX.lo b/src/libopus/silk/fixed/warped_autocorrelation_FIX.lo deleted file mode 100644 index 2e03296..0000000 --- a/src/libopus/silk/fixed/warped_autocorrelation_FIX.lo +++ /dev/null @@ -1,12 +0,0 @@ -# silk/fixed/warped_autocorrelation_FIX.lo - a libtool object file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# Name of the PIC object. -pic_object='.libs/warped_autocorrelation_FIX.o' - -# Name of the non-PIC object -non_pic_object='warped_autocorrelation_FIX.o' - diff --git a/src/libopus/silk/fixed/warped_autocorrelation_FIX.o b/src/libopus/silk/fixed/warped_autocorrelation_FIX.o deleted file mode 100644 index 500bd7e1e785c68daa27d3ec6035dc987c4821d8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15936 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 double_step_size_threshold) { - ind[ k ] = double_step_size_threshold + silk_RSHIFT(ind[ k ] - double_step_size_threshold + 1, 1); + if( ind[ k ] > double_step_size_threshold ) { + ind[ k ] = double_step_size_threshold + silk_RSHIFT( ind[ k ] - double_step_size_threshold + 1, 1 ); } - ind[ k ] = silk_LIMIT_int(ind[ k ], MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT); + ind[ k ] = silk_LIMIT_int( ind[ k ], MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT ); /* Accumulate deltas */ - if (ind[ k ] > double_step_size_threshold) { - *prev_ind += silk_LSHIFT(ind[ k ], 1) - double_step_size_threshold; - *prev_ind = silk_min_int(*prev_ind, N_LEVELS_QGAIN - 1); + if( ind[ k ] > double_step_size_threshold ) { + *prev_ind += silk_LSHIFT( ind[ k ], 1 ) - double_step_size_threshold; + *prev_ind = silk_min_int( *prev_ind, N_LEVELS_QGAIN - 1 ); } else { *prev_ind += ind[ k ]; } @@ -85,7 +86,7 @@ void silk_gains_quant( } /* Scale and convert to linear scale */ - gain_Q16[ k ] = silk_log2lin(silk_min_32(silk_SMULWB(INV_SCALE_Q16, *prev_ind) + OFFSET, 3967)); /* 3967 = 31 in Q7 */ + gain_Q16[ k ] = silk_log2lin( silk_min_32( silk_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */ } } @@ -96,29 +97,30 @@ void silk_gains_dequant( opus_int8 *prev_ind, /* I/O last index in previous frame */ const opus_int conditional, /* I first gain is delta coded if 1 */ const opus_int nb_subfr /* I number of subframes */ -) { +) +{ opus_int k, ind_tmp, double_step_size_threshold; - for (k = 0; k < nb_subfr; k++) { - if (k == 0 && conditional == 0) { + for( k = 0; k < nb_subfr; k++ ) { + if( k == 0 && conditional == 0 ) { /* Gain index is not allowed to go down more than 16 steps (~21.8 dB) */ - *prev_ind = silk_max_int(ind[ k ], *prev_ind - 16); + *prev_ind = silk_max_int( ind[ k ], *prev_ind - 16 ); } else { /* Delta index */ ind_tmp = ind[ k ] + MIN_DELTA_GAIN_QUANT; /* Accumulate deltas */ double_step_size_threshold = 2 * MAX_DELTA_GAIN_QUANT - N_LEVELS_QGAIN + *prev_ind; - if (ind_tmp > double_step_size_threshold) { - *prev_ind += silk_LSHIFT(ind_tmp, 1) - double_step_size_threshold; + if( ind_tmp > double_step_size_threshold ) { + *prev_ind += silk_LSHIFT( ind_tmp, 1 ) - double_step_size_threshold; } else { *prev_ind += ind_tmp; } } - *prev_ind = silk_LIMIT_int(*prev_ind, 0, N_LEVELS_QGAIN - 1); + *prev_ind = silk_LIMIT_int( *prev_ind, 0, N_LEVELS_QGAIN - 1 ); /* Scale and convert to linear scale */ - gain_Q16[ k ] = silk_log2lin(silk_min_32(silk_SMULWB(INV_SCALE_Q16, *prev_ind) + OFFSET, 3967)); /* 3967 = 31 in Q7 */ + gain_Q16[ k ] = silk_log2lin( silk_min_32( silk_SMULWB( INV_SCALE_Q16, *prev_ind ) + OFFSET, 3967 ) ); /* 3967 = 31 in Q7 */ } } @@ -126,13 +128,14 @@ void silk_gains_dequant( opus_int32 silk_gains_ID( /* O returns unique identifier of gains */ const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */ const opus_int nb_subfr /* I number of subframes */ -) { +) +{ opus_int k; opus_int32 gainsID; gainsID = 0; - for (k = 0; k < nb_subfr; k++) { - gainsID = silk_ADD_LSHIFT32(ind[ k ], gainsID, 8); + for( k = 0; k < nb_subfr; k++ ) { + gainsID = silk_ADD_LSHIFT32( ind[ k ], gainsID, 8 ); } return gainsID; diff --git a/src/libopus/silk/init_decoder.c b/src/libopus/silk/init_decoder.c index bfc5642..21c8d01 100644 --- a/src/libopus/silk/init_decoder.c +++ b/src/libopus/silk/init_decoder.c @@ -1,44 +1,51 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" +#ifdef ENABLE_OSCE +#include "osce.h" +#endif + +#include "structs.h" + /************************/ -/* Init Decoder State */ +/* Reset Decoder State */ /************************/ -opus_int silk_init_decoder( +opus_int silk_reset_decoder( silk_decoder_state *psDec /* I/O Decoder state pointer */ -) { +) +{ /* Clear the entire encoder state, except anything copied */ - silk_memset(psDec, 0, sizeof(silk_decoder_state)); + silk_memset( &psDec->SILK_DECODER_STATE_RESET_START, 0, sizeof( silk_decoder_state ) - ((char*) &psDec->SILK_DECODER_STATE_RESET_START - (char*)psDec) ); /* Used to deactivate LSF interpolation */ psDec->first_frame_after_reset = 1; @@ -46,11 +53,32 @@ opus_int silk_init_decoder( psDec->arch = opus_select_arch(); /* Reset CNG state */ - silk_CNG_Reset(psDec); + silk_CNG_Reset( psDec ); /* Reset PLC state */ - silk_PLC_Reset(psDec); + silk_PLC_Reset( psDec ); - return (0); +#ifdef ENABLE_OSCE + /* Reset OSCE state and method */ + osce_reset(&psDec->osce, OSCE_DEFAULT_METHOD); +#endif + + return 0; +} + + +/************************/ +/* Init Decoder State */ +/************************/ +opus_int silk_init_decoder( + silk_decoder_state *psDec /* I/O Decoder state pointer */ +) +{ + /* Clear the entire encoder state, except anything copied */ + silk_memset( psDec, 0, sizeof( silk_decoder_state ) ); + + silk_reset_decoder( psDec ); + + return(0); } diff --git a/src/libopus/silk/init_encoder.c b/src/libopus/silk/init_encoder.c deleted file mode 100644 index eaa72ef..0000000 --- a/src/libopus/silk/init_encoder.c +++ /dev/null @@ -1,63 +0,0 @@ -/*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif -#ifdef FIXED_POINT -#include "fixed/main_FIX.h" -#else -#include "main_FLP.h" -#endif -#include "tuning_parameters.h" -#include "../celt/cpu_support.h" - -/*********************************/ -/* Initialize Silk Encoder state */ -/*********************************/ -opus_int silk_init_encoder( - silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk FIX encoder state */ - int arch /* I Run-time architecture */ -) { - opus_int ret = 0; - - /* Clear the entire encoder state */ - silk_memset(psEnc, 0, sizeof(silk_encoder_state_Fxx)); - - psEnc->sCmn.arch = arch; - - psEnc->sCmn.variable_HP_smth1_Q15 = silk_LSHIFT(silk_lin2log(SILK_FIX_CONST(VARIABLE_HP_MIN_CUTOFF_HZ, 16)) - (16 << 7), 8); - psEnc->sCmn.variable_HP_smth2_Q15 = psEnc->sCmn.variable_HP_smth1_Q15; - - /* Used to deactivate LSF interpolation, pitch prediction */ - psEnc->sCmn.first_frame_after_reset = 1; - - /* Initialize Silk VAD */ - ret += silk_VAD_Init(&psEnc->sCmn.sVAD); - - return ret; -} diff --git a/src/libopus/silk/inner_prod_aligned.c b/src/libopus/silk/inner_prod_aligned.c index e9aabd0..69eee89 100644 --- a/src/libopus/silk/inner_prod_aligned.c +++ b/src/libopus/silk/inner_prod_aligned.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" @@ -36,11 +36,12 @@ opus_int32 silk_inner_prod_aligned_scale( const opus_int16 *const inVec2, /* I input vector 2 */ const opus_int scale, /* I number of bits to shift */ const opus_int len /* I vector lengths */ -) { +) +{ opus_int i; opus_int32 sum = 0; - for (i = 0; i < len; i++) { - sum = silk_ADD_RSHIFT32(sum, silk_SMULBB(inVec1[ i ], inVec2[ i ]), scale); + for( i = 0; i < len; i++ ) { + sum = silk_ADD_RSHIFT32( sum, silk_SMULBB( inVec1[ i ], inVec2[ i ] ), scale ); } return sum; } diff --git a/src/libopus/silk/interpolate.c b/src/libopus/silk/interpolate.c index 77479a2..b2856f8 100644 --- a/src/libopus/silk/interpolate.c +++ b/src/libopus/silk/interpolate.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -38,13 +38,14 @@ void silk_interpolate( const opus_int16 x1[ MAX_LPC_ORDER ], /* I second vector */ const opus_int ifact_Q2, /* I interp. factor, weight on 2nd vector */ const opus_int d /* I number of parameters */ -) { +) +{ opus_int i; - celt_assert(ifact_Q2 >= 0); - celt_assert(ifact_Q2 <= 4); + celt_assert( ifact_Q2 >= 0 ); + celt_assert( ifact_Q2 <= 4 ); - for (i = 0; i < d; i++) { - xi[ i ] = (opus_int16)silk_ADD_RSHIFT(x0[ i ], silk_SMULBB(x1[ i ] - x0[ i ], ifact_Q2), 2); + for( i = 0; i < d; i++ ) { + xi[ i ] = (opus_int16)silk_ADD_RSHIFT( x0[ i ], silk_SMULBB( x1[ i ] - x0[ i ], ifact_Q2 ), 2 ); } } diff --git a/src/libopus/silk/lin2log.c b/src/libopus/silk/lin2log.c index 61998cd..0826ccd 100644 --- a/src/libopus/silk/lin2log.c +++ b/src/libopus/silk/lin2log.c @@ -1,45 +1,46 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" /* Approximation of 128 * log2() (very close inverse of silk_log2lin()) */ /* Convert input to a log scale */ opus_int32 silk_lin2log( const opus_int32 inLin /* I input in linear scale */ -) { +) +{ opus_int32 lz, frac_Q7; - silk_CLZ_FRAC(inLin, &lz, &frac_Q7); + silk_CLZ_FRAC( inLin, &lz, &frac_Q7 ); /* Piece-wise parabolic approximation */ - return silk_ADD_LSHIFT32(silk_SMLAWB(frac_Q7, silk_MUL(frac_Q7, 128 - frac_Q7), 179), 31 - lz, 7); + return silk_ADD_LSHIFT32( silk_SMLAWB( frac_Q7, silk_MUL( frac_Q7, 128 - frac_Q7 ), 179 ), 31 - lz, 7 ); } diff --git a/src/libopus/silk/log2lin.c b/src/libopus/silk/log2lin.c index 83d5d2d..860c3dc 100644 --- a/src/libopus/silk/log2lin.c +++ b/src/libopus/silk/log2lin.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" @@ -35,23 +35,24 @@ /* Convert input to a linear scale */ opus_int32 silk_log2lin( const opus_int32 inLog_Q7 /* I input on log scale */ -) { +) +{ opus_int32 out, frac_Q7; - if (inLog_Q7 < 0) { + if( inLog_Q7 < 0 ) { return 0; - } else if (inLog_Q7 >= 3967) { + } else if ( inLog_Q7 >= 3967 ) { return silk_int32_MAX; } - out = silk_LSHIFT(1, silk_RSHIFT(inLog_Q7, 7)); + out = silk_LSHIFT( 1, silk_RSHIFT( inLog_Q7, 7 ) ); frac_Q7 = inLog_Q7 & 0x7F; - if (inLog_Q7 < 2048) { + if( inLog_Q7 < 2048 ) { /* Piece-wise parabolic approximation */ - out = silk_ADD_RSHIFT32(out, silk_MUL(out, silk_SMLAWB(frac_Q7, silk_SMULBB(frac_Q7, 128 - frac_Q7), -174)), 7); + out = silk_ADD_RSHIFT32( out, silk_MUL( out, silk_SMLAWB( frac_Q7, silk_SMULBB( frac_Q7, 128 - frac_Q7 ), -174 ) ), 7 ); } else { /* Piece-wise parabolic approximation */ - out = silk_MLA(out, silk_RSHIFT(out, 7), silk_SMLAWB(frac_Q7, silk_SMULBB(frac_Q7, 128 - frac_Q7), -174)); + out = silk_MLA( out, silk_RSHIFT( out, 7 ), silk_SMLAWB( frac_Q7, silk_SMULBB( frac_Q7, 128 - frac_Q7 ), -174 ) ); } return out; } diff --git a/src/libopus/silk/macros.h b/src/libopus/silk/macros.h index 585e292..d5ac409 100644 --- a/src/libopus/silk/macros.h +++ b/src/libopus/silk/macros.h @@ -1,40 +1,40 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_MACROS_H #define SILK_MACROS_H -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif -#include "../opus_types.h" -#include "../opus_defines.h" -#include "../celt/arch.h" +#include "opus_types.h" +#include "opus_defines.h" +#include "arch.h" /* This is an OPUS_INLINE header file for general platform. */ @@ -108,15 +108,17 @@ #include "mips/macros_mipsr1.h" #endif -#include "../celt/ecintrin.h" +#include "ecintrin.h" #ifndef OVERRIDE_silk_CLZ16 -static OPUS_INLINE opus_int32 silk_CLZ16(opus_int16 in16) { - return 32 - EC_ILOG(in16 << 16 | 0x8000); +static OPUS_INLINE opus_int32 silk_CLZ16(opus_int16 in16) +{ + return 32 - EC_ILOG(in16<<16|0x8000); } #endif #ifndef OVERRIDE_silk_CLZ32 -static OPUS_INLINE opus_int32 silk_CLZ32(opus_int32 in32) { +static OPUS_INLINE opus_int32 silk_CLZ32(opus_int32 in32) +{ return in32 ? 32 - EC_ILOG(in32) : 32; } #endif diff --git a/src/libopus/silk/main.h b/src/libopus/silk/main.h index 79751e5..cd576d8 100644 --- a/src/libopus/silk/main.h +++ b/src/libopus/silk/main.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_MAIN_H @@ -35,8 +35,8 @@ #include "PLC.h" #include "control.h" #include "debug.h" -#include "../celt/entenc.h" -#include "../celt/entdec.h" +#include "entenc.h" +#include "entdec.h" #if defined(OPUS_X86_MAY_HAVE_SSE4_1) #include "x86/main_sse.h" @@ -214,8 +214,8 @@ void silk_quant_LTP_gains( opus_int8 *periodicity_index, /* O Periodicity Index */ opus_int32 *sum_gain_dB_Q7, /* I/O Cumulative max prediction gain */ opus_int *pred_gain_dB_Q7, /* O LTP prediction gain */ - const opus_int32 XX_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix in Q18 */ - const opus_int32 xX_Q17[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector in Q18 */ + const opus_int32 XX_Q17[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Correlation matrix in Q18 */ + const opus_int32 xX_Q17[ MAX_NB_SUBFR*LTP_ORDER ], /* I Correlation vector in Q18 */ const opus_int subfr_len, /* I Number of samples per subframe */ const opus_int nb_subfr, /* I Number of subframes */ int arch /* I Run-time architecture */ @@ -247,21 +247,21 @@ void silk_VQ_WMat_EC_c( /************************************/ void silk_NSQ_c( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - SideInfoIndices *psIndices, /* I/O Quantization Indices */ - const opus_int16 x16[], /* I Input */ - opus_int8 pulses[], /* O Quantized pulse signal */ - const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ - const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ - const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ - const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ - const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ - const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ - const opus_int LTP_scale_Q14 /* I LTP state scaling */ + const silk_encoder_state *psEncC, /* I Encoder State */ + silk_nsq_state *NSQ, /* I/O NSQ state */ + SideInfoIndices *psIndices, /* I/O Quantization Indices */ + const opus_int16 x16[], /* I Input */ + opus_int8 pulses[], /* O Quantized pulse signal */ + const opus_int16 *PredCoef_Q12, /* I Short term prediction coefs */ + const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ + const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ + const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ + const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ + const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ + const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ + const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ + const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ + const opus_int LTP_scale_Q14 /* I LTP state scaling */ ); #if !defined(OVERRIDE_silk_NSQ) @@ -273,21 +273,21 @@ void silk_NSQ_c( /* Noise shaping using delayed decision */ void silk_NSQ_del_dec_c( - const silk_encoder_state *psEncC, /* I Encoder State */ - silk_nsq_state *NSQ, /* I/O NSQ state */ - SideInfoIndices *psIndices, /* I/O Quantization Indices */ - const opus_int16 x16[], /* I Input */ - opus_int8 pulses[], /* O Quantized pulse signal */ - const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ - const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ - const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ - const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ - const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ - const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ - const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ - const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ - const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ - const opus_int LTP_scale_Q14 /* I LTP state scaling */ + const silk_encoder_state *psEncC, /* I Encoder State */ + silk_nsq_state *NSQ, /* I/O NSQ state */ + SideInfoIndices *psIndices, /* I/O Quantization Indices */ + const opus_int16 x16[], /* I Input */ + opus_int8 pulses[], /* O Quantized pulse signal */ + const opus_int16 *PredCoef_Q12, /* I Short term prediction coefs */ + const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ + const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ + const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ + const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ + const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ + const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ + const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ + const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ + const opus_int LTP_scale_Q14 /* I LTP state scaling */ ); #if !defined(OVERRIDE_silk_NSQ_del_dec) @@ -336,8 +336,8 @@ void silk_process_NLSFs( ); opus_int32 silk_NLSF_encode( /* O Returns RD value in Q25 */ - opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ - opus_int16 *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ + opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ + opus_int16 *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const opus_int16 *pW_QW, /* I NLSF weight vector [ LPC_ORDER ] */ const opus_int NLSF_mu_Q20, /* I Rate weight for the RD optimization */ @@ -371,8 +371,8 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns /* Unpack predictor values and indices for entropy coding tables */ void silk_NLSF_unpack( - opus_int16 ec_ix[], /* O Indices to entropy tables [ LPC_ORDER ] */ - opus_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */ + opus_int16 ec_ix[], /* O Indices to entropy tables [ LPC_ORDER ] */ + opus_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */ const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ const opus_int CB1_index /* I Index of vector in first LSF codebook */ ); @@ -381,14 +381,18 @@ void silk_NLSF_unpack( /* NLSF vector decoder */ /***********************/ void silk_NLSF_decode( - opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */ - opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ + opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */ + opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */ ); /****************************************************/ /* Decoder Functions */ /****************************************************/ +opus_int silk_reset_decoder( + silk_decoder_state *psDec /* I/O Decoder state pointer */ +); + opus_int silk_init_decoder( silk_decoder_state *psDec /* I/O Decoder state pointer */ ); @@ -410,6 +414,12 @@ opus_int silk_decode_frame( opus_int32 *pN, /* O Pointer to size of output frame */ opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */ opus_int condCoding, /* I The type of conditional coding to use */ +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState *lpcnet, +#endif +#ifdef ENABLE_OSCE + OSCEModel *osce_model, +#endif int arch /* I Run-time architecture */ ); diff --git a/src/libopus/silk/main_FIX.h b/src/libopus/silk/main_FIX.h new file mode 100644 index 0000000..4143f36 --- /dev/null +++ b/src/libopus/silk/main_FIX.h @@ -0,0 +1 @@ +#include "fixed/main_FIX.h" diff --git a/src/libopus/silk/opus.h b/src/libopus/silk/opus.h new file mode 100644 index 0000000..0a1b59c --- /dev/null +++ b/src/libopus/silk/opus.h @@ -0,0 +1 @@ +#include "../include/opus.h" diff --git a/src/libopus/silk/opus_custom.h b/src/libopus/silk/opus_custom.h new file mode 100644 index 0000000..f54a103 --- /dev/null +++ b/src/libopus/silk/opus_custom.h @@ -0,0 +1 @@ +#include "../include/opus_custom.h" diff --git a/src/libopus/silk/opus_defines.h b/src/libopus/silk/opus_defines.h new file mode 100644 index 0000000..dcc2443 --- /dev/null +++ b/src/libopus/silk/opus_defines.h @@ -0,0 +1 @@ +#include "../include/opus_defines.h" diff --git a/src/libopus/silk/opus_multistream.h b/src/libopus/silk/opus_multistream.h new file mode 100644 index 0000000..89f6229 --- /dev/null +++ b/src/libopus/silk/opus_multistream.h @@ -0,0 +1 @@ +#include "../include/opus_multistream.h" diff --git a/src/libopus/silk/opus_projection.h b/src/libopus/silk/opus_projection.h new file mode 100644 index 0000000..72f59cc --- /dev/null +++ b/src/libopus/silk/opus_projection.h @@ -0,0 +1 @@ +#include "../include/opus_projection.h" diff --git a/src/libopus/silk/opus_types.h b/src/libopus/silk/opus_types.h new file mode 100644 index 0000000..a7958a5 --- /dev/null +++ b/src/libopus/silk/opus_types.h @@ -0,0 +1 @@ +#include "../include/opus_types.h" diff --git a/src/libopus/silk/os_support.h b/src/libopus/silk/os_support.h new file mode 100644 index 0000000..dc47379 --- /dev/null +++ b/src/libopus/silk/os_support.h @@ -0,0 +1 @@ +#include "../celt/os_support.h" diff --git a/src/libopus/silk/pitch_est_defines.h b/src/libopus/silk/pitch_est_defines.h index b469f71..e1e4b5d 100644 --- a/src/libopus/silk/pitch_est_defines.h +++ b/src/libopus/silk/pitch_est_defines.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_PE_DEFINES_H diff --git a/src/libopus/silk/pitch_est_tables.c b/src/libopus/silk/pitch_est_tables.c index 3a58c5b..3706f21 100644 --- a/src/libopus/silk/pitch_est_tables.c +++ b/src/libopus/silk/pitch_est_tables.c @@ -1,91 +1,98 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "typedef.h" #include "pitch_est_defines.h" -const opus_int8 silk_CB_lags_stage2_10_ms[ PE_MAX_NB_SUBFR >> 1][ PE_NB_CBKS_STAGE2_10MS ] = { +const opus_int8 silk_CB_lags_stage2_10_ms[ PE_MAX_NB_SUBFR >> 1][ PE_NB_CBKS_STAGE2_10MS ] = +{ {0, 1, 0}, {0, 0, 1} }; -const opus_int8 silk_CB_lags_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ PE_NB_CBKS_STAGE3_10MS ] = { - { 0, 0, 1, -1, 1, -1, 2, -2, 2, -2, 3, -3}, - { 0, 1, 0, 1, -1, 2, -1, 2, -2, 3, -2, 3} +const opus_int8 silk_CB_lags_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ PE_NB_CBKS_STAGE3_10MS ] = +{ + { 0, 0, 1,-1, 1,-1, 2,-2, 2,-2, 3,-3}, + { 0, 1, 0, 1,-1, 2,-1, 2,-2, 3,-2, 3} }; -const opus_int8 silk_Lag_range_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 2 ] = { +const opus_int8 silk_Lag_range_stage3_10_ms[ PE_MAX_NB_SUBFR >> 1 ][ 2 ] = +{ {-3, 7}, {-2, 7} }; -const opus_int8 silk_CB_lags_stage2[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE2_EXT ] = { - {0, 2, -1, -1, -1, 0, 0, 1, 1, 0, 1}, +const opus_int8 silk_CB_lags_stage2[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE2_EXT ] = +{ + {0, 2,-1,-1,-1, 0, 0, 1, 1, 0, 1}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0}, - {0, -1, 2, 1, 0, 1, 1, 0, 0, -1, -1} + {0,-1, 2, 1, 0, 1, 1, 0, 0,-1,-1} }; -const opus_int8 silk_CB_lags_stage3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ] = { - {0, 0, 1, -1, 0, 1, -1, 0, -1, 1, -2, 2, -2, -2, 2, -3, 2, 3, -3, -4, 3, -4, 4, 4, -5, 5, -6, -5, 6, -7, 6, 5, 8, -9}, - {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 1, -1, 0, 1, -1, -1, 1, -1, 2, 1, -1, 2, -2, -2, 2, -2, 2, 2, 3, -3}, - {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, -1, 1, 0, 0, 2, 1, -1, 2, -1, -1, 2, -1, 2, 2, -1, 3, -2, -2, -2, 3}, - {0, 1, 0, 0, 1, 0, 1, -1, 2, -1, 2, -1, 2, 3, -2, 3, -2, -2, 4, 4, -3, 5, -3, -4, 6, -4, 6, 5, -5, 8, -6, -5, -7, 9} +const opus_int8 silk_CB_lags_stage3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ] = +{ + {0, 0, 1,-1, 0, 1,-1, 0,-1, 1,-2, 2,-2,-2, 2,-3, 2, 3,-3,-4, 3,-4, 4, 4,-5, 5,-6,-5, 6,-7, 6, 5, 8,-9}, + {0, 0, 1, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 1,-1, 0, 1,-1,-1, 1,-1, 2, 1,-1, 2,-2,-2, 2,-2, 2, 2, 3,-3}, + {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,-1, 1, 0, 0, 2, 1,-1, 2,-1,-1, 2,-1, 2, 2,-1, 3,-2,-2,-2, 3}, + {0, 1, 0, 0, 1, 0, 1,-1, 2,-1, 2,-1, 2, 3,-2, 3,-2,-2, 4, 4,-3, 5,-3,-4, 6,-4, 6, 5,-5, 8,-6,-5,-7, 9} }; -const opus_int8 silk_Lag_range_stage3[ SILK_PE_MAX_COMPLEX + 1 ] [ PE_MAX_NB_SUBFR ][ 2 ] = { +const opus_int8 silk_Lag_range_stage3[ SILK_PE_MAX_COMPLEX + 1 ] [ PE_MAX_NB_SUBFR ][ 2 ] = +{ /* Lags to search for low number of stage3 cbks */ { - {-5, 8}, - {-1, 6}, - {-1, 6}, - {-4, 10} + {-5,8}, + {-1,6}, + {-1,6}, + {-4,10} }, /* Lags to search for middle number of stage3 cbks */ { - {-6, 10}, - {-2, 6}, - {-1, 6}, - {-5, 10} + {-6,10}, + {-2,6}, + {-1,6}, + {-5,10} }, /* Lags to search for max number of stage3 cbks */ { - {-9, 12}, - {-3, 7}, - {-2, 7}, - {-7, 13} + {-9,12}, + {-3,7}, + {-2,7}, + {-7,13} } }; -const opus_int8 silk_nb_cbk_searchs_stage3[ SILK_PE_MAX_COMPLEX + 1 ] = { +const opus_int8 silk_nb_cbk_searchs_stage3[ SILK_PE_MAX_COMPLEX + 1 ] = +{ PE_NB_CBKS_STAGE3_MIN, PE_NB_CBKS_STAGE3_MID, PE_NB_CBKS_STAGE3_MAX diff --git a/src/libopus/silk/process_NLSFs.c b/src/libopus/silk/process_NLSFs.c index 6832a4c..b1f2314 100644 --- a/src/libopus/silk/process_NLSFs.c +++ b/src/libopus/silk/process_NLSFs.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -37,7 +37,8 @@ void silk_process_NLSFs( opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */ opus_int16 pNLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */ const opus_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */ -) { +) +{ opus_int i, doInterpolate; opus_int NLSF_mu_Q20; opus_int16 i_sqr_Q15; @@ -45,62 +46,62 @@ void silk_process_NLSFs( opus_int16 pNLSFW_QW[ MAX_LPC_ORDER ]; opus_int16 pNLSFW0_temp_QW[ MAX_LPC_ORDER ]; - silk_assert(psEncC->speech_activity_Q8 >= 0); - silk_assert(psEncC->speech_activity_Q8 <= SILK_FIX_CONST(1.0, 8)); - celt_assert(psEncC->useInterpolatedNLSFs == 1 || psEncC->indices.NLSFInterpCoef_Q2 == (1 << 2)); + silk_assert( psEncC->speech_activity_Q8 >= 0 ); + silk_assert( psEncC->speech_activity_Q8 <= SILK_FIX_CONST( 1.0, 8 ) ); + celt_assert( psEncC->useInterpolatedNLSFs == 1 || psEncC->indices.NLSFInterpCoef_Q2 == ( 1 << 2 ) ); /***********************/ /* Calculate mu values */ /***********************/ /* NLSF_mu = 0.003 - 0.0015 * psEnc->speech_activity; */ - NLSF_mu_Q20 = silk_SMLAWB(SILK_FIX_CONST(0.003, 20), SILK_FIX_CONST(-0.001, 28), psEncC->speech_activity_Q8); - if (psEncC->nb_subfr == 2) { + NLSF_mu_Q20 = silk_SMLAWB( SILK_FIX_CONST( 0.003, 20 ), SILK_FIX_CONST( -0.001, 28 ), psEncC->speech_activity_Q8 ); + if( psEncC->nb_subfr == 2 ) { /* Multiply by 1.5 for 10 ms packets */ - NLSF_mu_Q20 = silk_ADD_RSHIFT(NLSF_mu_Q20, NLSF_mu_Q20, 1); + NLSF_mu_Q20 = silk_ADD_RSHIFT( NLSF_mu_Q20, NLSF_mu_Q20, 1 ); } - celt_assert(NLSF_mu_Q20 > 0); - silk_assert(NLSF_mu_Q20 <= SILK_FIX_CONST(0.005, 20)); + celt_assert( NLSF_mu_Q20 > 0 ); + silk_assert( NLSF_mu_Q20 <= SILK_FIX_CONST( 0.005, 20 ) ); /* Calculate NLSF weights */ - silk_NLSF_VQ_weights_laroia(pNLSFW_QW, pNLSF_Q15, psEncC->predictLPCOrder); + silk_NLSF_VQ_weights_laroia( pNLSFW_QW, pNLSF_Q15, psEncC->predictLPCOrder ); /* Update NLSF weights for interpolated NLSFs */ - doInterpolate = (psEncC->useInterpolatedNLSFs == 1) && (psEncC->indices.NLSFInterpCoef_Q2 < 4); - if (doInterpolate) { + doInterpolate = ( psEncC->useInterpolatedNLSFs == 1 ) && ( psEncC->indices.NLSFInterpCoef_Q2 < 4 ); + if( doInterpolate ) { /* Calculate the interpolated NLSF vector for the first half */ - silk_interpolate(pNLSF0_temp_Q15, prev_NLSFq_Q15, pNLSF_Q15, - psEncC->indices.NLSFInterpCoef_Q2, psEncC->predictLPCOrder); + silk_interpolate( pNLSF0_temp_Q15, prev_NLSFq_Q15, pNLSF_Q15, + psEncC->indices.NLSFInterpCoef_Q2, psEncC->predictLPCOrder ); /* Calculate first half NLSF weights for the interpolated NLSFs */ - silk_NLSF_VQ_weights_laroia(pNLSFW0_temp_QW, pNLSF0_temp_Q15, psEncC->predictLPCOrder); + silk_NLSF_VQ_weights_laroia( pNLSFW0_temp_QW, pNLSF0_temp_Q15, psEncC->predictLPCOrder ); /* Update NLSF weights with contribution from first half */ - i_sqr_Q15 = silk_LSHIFT(silk_SMULBB(psEncC->indices.NLSFInterpCoef_Q2, psEncC->indices.NLSFInterpCoef_Q2), 11); - for (i = 0; i < psEncC->predictLPCOrder; i++) { - pNLSFW_QW[ i ] = silk_ADD16(silk_RSHIFT(pNLSFW_QW[ i ], 1), silk_RSHIFT( - silk_SMULBB(pNLSFW0_temp_QW[ i ], i_sqr_Q15), 16)); - silk_assert(pNLSFW_QW[ i ] >= 1); + i_sqr_Q15 = silk_LSHIFT( silk_SMULBB( psEncC->indices.NLSFInterpCoef_Q2, psEncC->indices.NLSFInterpCoef_Q2 ), 11 ); + for( i = 0; i < psEncC->predictLPCOrder; i++ ) { + pNLSFW_QW[ i ] = silk_ADD16( silk_RSHIFT( pNLSFW_QW[ i ], 1 ), silk_RSHIFT( + silk_SMULBB( pNLSFW0_temp_QW[ i ], i_sqr_Q15 ), 16) ); + silk_assert( pNLSFW_QW[ i ] >= 1 ); } } - silk_NLSF_encode(psEncC->indices.NLSFIndices, pNLSF_Q15, psEncC->psNLSF_CB, pNLSFW_QW, - NLSF_mu_Q20, psEncC->NLSF_MSVQ_Survivors, psEncC->indices.signalType); + silk_NLSF_encode( psEncC->indices.NLSFIndices, pNLSF_Q15, psEncC->psNLSF_CB, pNLSFW_QW, + NLSF_mu_Q20, psEncC->NLSF_MSVQ_Survivors, psEncC->indices.signalType ); /* Convert quantized NLSFs back to LPC coefficients */ - silk_NLSF2A(PredCoef_Q12[ 1 ], pNLSF_Q15, psEncC->predictLPCOrder, psEncC->arch); + silk_NLSF2A( PredCoef_Q12[ 1 ], pNLSF_Q15, psEncC->predictLPCOrder, psEncC->arch ); - if (doInterpolate) { + if( doInterpolate ) { /* Calculate the interpolated, quantized LSF vector for the first half */ - silk_interpolate(pNLSF0_temp_Q15, prev_NLSFq_Q15, pNLSF_Q15, - psEncC->indices.NLSFInterpCoef_Q2, psEncC->predictLPCOrder); + silk_interpolate( pNLSF0_temp_Q15, prev_NLSFq_Q15, pNLSF_Q15, + psEncC->indices.NLSFInterpCoef_Q2, psEncC->predictLPCOrder ); /* Convert back to LPC coefficients */ - silk_NLSF2A(PredCoef_Q12[ 0 ], pNLSF0_temp_Q15, psEncC->predictLPCOrder, psEncC->arch); + silk_NLSF2A( PredCoef_Q12[ 0 ], pNLSF0_temp_Q15, psEncC->predictLPCOrder, psEncC->arch ); } else { /* Copy LPC coefficients for first half from second half */ - celt_assert(psEncC->predictLPCOrder <= MAX_LPC_ORDER); - silk_memcpy(PredCoef_Q12[ 0 ], PredCoef_Q12[ 1 ], psEncC->predictLPCOrder * sizeof(opus_int16)); + celt_assert( psEncC->predictLPCOrder <= MAX_LPC_ORDER ); + silk_memcpy( PredCoef_Q12[ 0 ], PredCoef_Q12[ 1 ], psEncC->predictLPCOrder * sizeof( opus_int16 ) ); } } diff --git a/src/libopus/silk/quant_LTP_gains.c b/src/libopus/silk/quant_LTP_gains.c index 4f7cf9d..197a13c 100644 --- a/src/libopus/silk/quant_LTP_gains.c +++ b/src/libopus/silk/quant_LTP_gains.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" #include "tuning_parameters.h" @@ -38,12 +38,13 @@ void silk_quant_LTP_gains( opus_int8 *periodicity_index, /* O Periodicity Index */ opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */ opus_int *pred_gain_dB_Q7, /* O LTP prediction gain */ - const opus_int32 XX_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix in Q18 */ - const opus_int32 xX_Q17[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector in Q18 */ + const opus_int32 XX_Q17[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Correlation matrix in Q18 */ + const opus_int32 xX_Q17[ MAX_NB_SUBFR*LTP_ORDER ], /* I Correlation vector in Q18 */ const opus_int subfr_len, /* I Number of samples per subframe */ const opus_int nb_subfr, /* I Number of subframes */ int arch /* I Run-time architecture */ -) { +) +{ opus_int j, k, cbk_size; opus_int8 temp_idx[ MAX_NB_SUBFR ]; const opus_uint8 *cl_ptr_Q5; @@ -60,10 +61,10 @@ void silk_quant_LTP_gains( /***************************************************/ min_rate_dist_Q7 = silk_int32_MAX; best_sum_log_gain_Q7 = 0; - for (k = 0; k < 3; k++) { - /* Safety margin for pitch gain control, to take into account factors - such as state rescaling/rewhitening. */ - opus_int32 gain_safety = SILK_FIX_CONST(0.4, 7); + for( k = 0; k < 3; k++ ) { + /* Safety margin for pitch gain control, to take into account factors + such as state rescaling/rewhitening. */ + opus_int32 gain_safety = SILK_FIX_CONST( 0.4, 7 ); cl_ptr_Q5 = silk_LTP_gain_BITS_Q5_ptrs[ k ]; cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ k ]; @@ -77,9 +78,9 @@ void silk_quant_LTP_gains( res_nrg_Q15 = 0; rate_dist_Q7 = 0; sum_log_gain_tmp_Q7 = *sum_log_gain_Q7; - for (j = 0; j < nb_subfr; j++) { - max_gain_Q7 = silk_log2lin((SILK_FIX_CONST(MAX_SUM_LOG_GAIN_DB / 6.0, 7) - sum_log_gain_tmp_Q7) - + SILK_FIX_CONST(7, 7)) - gain_safety; + for( j = 0; j < nb_subfr; j++ ) { + max_gain_Q7 = silk_log2lin( ( SILK_FIX_CONST( MAX_SUM_LOG_GAIN_DB / 6.0, 7 ) - sum_log_gain_tmp_Q7 ) + + SILK_FIX_CONST( 7, 7 ) ) - gain_safety; silk_VQ_WMat_EC( &temp_idx[ j ], /* O index of best codebook vector */ &res_nrg_Q15_subfr, /* O residual energy */ @@ -96,36 +97,36 @@ void silk_quant_LTP_gains( arch /* I Run-time architecture */ ); - res_nrg_Q15 = silk_ADD_POS_SAT32(res_nrg_Q15, res_nrg_Q15_subfr); - rate_dist_Q7 = silk_ADD_POS_SAT32(rate_dist_Q7, rate_dist_Q7_subfr); + res_nrg_Q15 = silk_ADD_POS_SAT32( res_nrg_Q15, res_nrg_Q15_subfr ); + rate_dist_Q7 = silk_ADD_POS_SAT32( rate_dist_Q7, rate_dist_Q7_subfr ); sum_log_gain_tmp_Q7 = silk_max(0, sum_log_gain_tmp_Q7 - + silk_lin2log(gain_safety + gain_Q7) - SILK_FIX_CONST(7, 7)); + + silk_lin2log( gain_safety + gain_Q7 ) - SILK_FIX_CONST( 7, 7 )); XX_Q17_ptr += LTP_ORDER * LTP_ORDER; xX_Q17_ptr += LTP_ORDER; } - if (rate_dist_Q7 <= min_rate_dist_Q7) { + if( rate_dist_Q7 <= min_rate_dist_Q7 ) { min_rate_dist_Q7 = rate_dist_Q7; *periodicity_index = (opus_int8)k; - silk_memcpy(cbk_index, temp_idx, nb_subfr * sizeof(opus_int8)); + silk_memcpy( cbk_index, temp_idx, nb_subfr * sizeof( opus_int8 ) ); best_sum_log_gain_Q7 = sum_log_gain_tmp_Q7; } } cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ *periodicity_index ]; - for (j = 0; j < nb_subfr; j++) { - for (k = 0; k < LTP_ORDER; k++) { - B_Q14[ j * LTP_ORDER + k ] = silk_LSHIFT(cbk_ptr_Q7[ cbk_index[ j ] * LTP_ORDER + k ], 7); + for( j = 0; j < nb_subfr; j++ ) { + for( k = 0; k < LTP_ORDER; k++ ) { + B_Q14[ j * LTP_ORDER + k ] = silk_LSHIFT( cbk_ptr_Q7[ cbk_index[ j ] * LTP_ORDER + k ], 7 ); } } - if (nb_subfr == 2) { - res_nrg_Q15 = silk_RSHIFT32(res_nrg_Q15, 1); + if( nb_subfr == 2 ) { + res_nrg_Q15 = silk_RSHIFT32( res_nrg_Q15, 1 ); } else { - res_nrg_Q15 = silk_RSHIFT32(res_nrg_Q15, 2); + res_nrg_Q15 = silk_RSHIFT32( res_nrg_Q15, 2 ); } *sum_log_gain_Q7 = best_sum_log_gain_Q7; - *pred_gain_dB_Q7 = (opus_int)silk_SMULBB(-3, silk_lin2log(res_nrg_Q15) - (15 << 7)); + *pred_gain_dB_Q7 = (opus_int)silk_SMULBB( -3, silk_lin2log( res_nrg_Q15 ) - ( 15 << 7 ) ); } diff --git a/src/libopus/silk/resampler.c b/src/libopus/silk/resampler.c index cd24505..1f3e642 100644 --- a/src/libopus/silk/resampler.c +++ b/src/libopus/silk/resampler.c @@ -1,69 +1,69 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif /* - Matrix of resampling methods used: - Fs_out (kHz) - 8 12 16 24 48 - - 8 C UF U UF UF - 12 AF C UF U UF - Fs_in (kHz) 16 D AF C UF UF - 24 AF D AF C U - 48 AF AF AF D C - - C -> Copy (no resampling) - D -> Allpass-based 2x downsampling - U -> Allpass-based 2x upsampling - UF -> Allpass-based 2x upsampling followed by FIR interpolation - AF -> AR2 filter followed by FIR interpolation -*/ + * Matrix of resampling methods used: + * Fs_out (kHz) + * 8 12 16 24 48 + * + * 8 C UF U UF UF + * 12 AF C UF U UF + * Fs_in (kHz) 16 D AF C UF UF + * 24 AF D AF C U + * 48 AF AF AF D C + * + * C -> Copy (no resampling) + * D -> Allpass-based 2x downsampling + * U -> Allpass-based 2x upsampling + * UF -> Allpass-based 2x upsampling followed by FIR interpolation + * AF -> AR2 filter followed by FIR interpolation + */ #include "resampler_private.h" /* Tables with delay compensation values to equalize total delay for different modes */ static const opus_int8 delay_matrix_enc[ 5 ][ 3 ] = { - /* in \ out 8 12 16 */ - /* 8 */ { 6, 0, 3 }, - /* 12 */ { 0, 7, 3 }, - /* 16 */ { 0, 1, 10 }, - /* 24 */ { 0, 2, 6 }, - /* 48 */ { 18, 10, 12 } +/* in \ out 8 12 16 */ +/* 8 */ { 6, 0, 3 }, +/* 12 */ { 0, 7, 3 }, +/* 16 */ { 0, 1, 10 }, +/* 24 */ { 0, 2, 6 }, +/* 48 */ { 18, 10, 12 } }; static const opus_int8 delay_matrix_dec[ 3 ][ 5 ] = { - /* in \ out 8 12 16 24 48 */ - /* 8 */ { 4, 0, 2, 0, 0 }, - /* 12 */ { 0, 9, 4, 7, 4 }, - /* 16 */ { 0, 3, 12, 7, 7 } +/* in \ out 8 12 16 24 48 */ +/* 8 */ { 4, 0, 2, 0, 0 }, +/* 12 */ { 0, 9, 4, 7, 4 }, +/* 16 */ { 0, 3, 12, 7, 7 } }; /* Simple way to make [8000, 12000, 16000, 24000, 48000] to [0, 1, 2, 3, 4] */ @@ -80,40 +80,41 @@ opus_int silk_resampler_init( opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */ opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */ opus_int forEnc /* I If 1: encoder; if 0: decoder */ -) { +) +{ opus_int up2x; /* Clear state */ - silk_memset(S, 0, sizeof(silk_resampler_state_struct)); + silk_memset( S, 0, sizeof( silk_resampler_state_struct ) ); /* Input checking */ - if (forEnc) { - if ((Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 && Fs_Hz_in != 24000 && Fs_Hz_in != 48000) || - (Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000)) { - celt_assert(0); + if( forEnc ) { + if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 && Fs_Hz_in != 24000 && Fs_Hz_in != 48000 ) || + ( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 ) ) { + celt_assert( 0 ); return -1; } - S->inputDelay = delay_matrix_enc[ rateID(Fs_Hz_in) ][ rateID(Fs_Hz_out) ]; + S->inputDelay = delay_matrix_enc[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ]; } else { - if ((Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000) || - (Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 && Fs_Hz_out != 24000 && Fs_Hz_out != 48000)) { - celt_assert(0); + if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 ) || + ( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 && Fs_Hz_out != 24000 && Fs_Hz_out != 48000 ) ) { + celt_assert( 0 ); return -1; } - S->inputDelay = delay_matrix_dec[ rateID(Fs_Hz_in) ][ rateID(Fs_Hz_out) ]; + S->inputDelay = delay_matrix_dec[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ]; } - S->Fs_in_kHz = silk_DIV32_16(Fs_Hz_in, 1000); - S->Fs_out_kHz = silk_DIV32_16(Fs_Hz_out, 1000); + S->Fs_in_kHz = silk_DIV32_16( Fs_Hz_in, 1000 ); + S->Fs_out_kHz = silk_DIV32_16( Fs_Hz_out, 1000 ); /* Number of samples processed per batch */ S->batchSize = S->Fs_in_kHz * RESAMPLER_MAX_BATCH_SIZE_MS; /* Find resampler with the right sampling ratio */ up2x = 0; - if (Fs_Hz_out > Fs_Hz_in) { + if( Fs_Hz_out > Fs_Hz_in ) { /* Upsample */ - if (Fs_Hz_out == silk_MUL(Fs_Hz_in, 2)) { /* Fs_out : Fs_in = 2 : 1 */ + if( Fs_Hz_out == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 1 */ /* Special case: directly use 2x upsampler */ S->resampler_function = USE_silk_resampler_private_up2_HQ_wrapper; } else { @@ -121,36 +122,36 @@ opus_int silk_resampler_init( S->resampler_function = USE_silk_resampler_private_IIR_FIR; up2x = 1; } - } else if (Fs_Hz_out < Fs_Hz_in) { + } else if ( Fs_Hz_out < Fs_Hz_in ) { /* Downsample */ - S->resampler_function = USE_silk_resampler_private_down_FIR; - if (silk_MUL(Fs_Hz_out, 4) == silk_MUL(Fs_Hz_in, 3)) { /* Fs_out : Fs_in = 3 : 4 */ + S->resampler_function = USE_silk_resampler_private_down_FIR; + if( silk_MUL( Fs_Hz_out, 4 ) == silk_MUL( Fs_Hz_in, 3 ) ) { /* Fs_out : Fs_in = 3 : 4 */ S->FIR_Fracs = 3; S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0; S->Coefs = silk_Resampler_3_4_COEFS; - } else if (silk_MUL(Fs_Hz_out, 3) == silk_MUL(Fs_Hz_in, 2)) { /* Fs_out : Fs_in = 2 : 3 */ + } else if( silk_MUL( Fs_Hz_out, 3 ) == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 3 */ S->FIR_Fracs = 2; S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0; S->Coefs = silk_Resampler_2_3_COEFS; - } else if (silk_MUL(Fs_Hz_out, 2) == Fs_Hz_in) { /* Fs_out : Fs_in = 1 : 2 */ + } else if( silk_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 2 */ S->FIR_Fracs = 1; S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR1; S->Coefs = silk_Resampler_1_2_COEFS; - } else if (silk_MUL(Fs_Hz_out, 3) == Fs_Hz_in) { /* Fs_out : Fs_in = 1 : 3 */ + } else if( silk_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 3 */ S->FIR_Fracs = 1; S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2; S->Coefs = silk_Resampler_1_3_COEFS; - } else if (silk_MUL(Fs_Hz_out, 4) == Fs_Hz_in) { /* Fs_out : Fs_in = 1 : 4 */ + } else if( silk_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 4 */ S->FIR_Fracs = 1; S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2; S->Coefs = silk_Resampler_1_4_COEFS; - } else if (silk_MUL(Fs_Hz_out, 6) == Fs_Hz_in) { /* Fs_out : Fs_in = 1 : 6 */ + } else if( silk_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 6 */ S->FIR_Fracs = 1; S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2; S->Coefs = silk_Resampler_1_6_COEFS; } else { /* None available */ - celt_assert(0); + celt_assert( 0 ); return -1; } } else { @@ -159,9 +160,9 @@ opus_int silk_resampler_init( } /* Ratio of input/output samples */ - S->invRatio_Q16 = silk_LSHIFT32(silk_DIV32(silk_LSHIFT32(Fs_Hz_in, 14 + up2x), Fs_Hz_out), 2); + S->invRatio_Q16 = silk_LSHIFT32( silk_DIV32( silk_LSHIFT32( Fs_Hz_in, 14 + up2x ), Fs_Hz_out ), 2 ); /* Make sure the ratio is rounded up */ - while (silk_SMULWW(S->invRatio_Q16, Fs_Hz_out) < silk_LSHIFT32(Fs_Hz_in, up2x)) { + while( silk_SMULWW( S->invRatio_Q16, Fs_Hz_out ) < silk_LSHIFT32( Fs_Hz_in, up2x ) ) { S->invRatio_Q16++; } @@ -175,39 +176,40 @@ opus_int silk_resampler( opus_int16 out[], /* O Output signal */ const opus_int16 in[], /* I Input signal */ opus_int32 inLen /* I Number of input samples */ -) { +) +{ opus_int nSamples; /* Need at least 1 ms of input data */ - celt_assert(inLen >= S->Fs_in_kHz); + celt_assert( inLen >= S->Fs_in_kHz ); /* Delay can't exceed the 1 ms of buffering */ - celt_assert(S->inputDelay <= S->Fs_in_kHz); + celt_assert( S->inputDelay <= S->Fs_in_kHz ); nSamples = S->Fs_in_kHz - S->inputDelay; /* Copy to delay buffer */ - silk_memcpy(&S->delayBuf[ S->inputDelay ], in, nSamples * sizeof(opus_int16)); + silk_memcpy( &S->delayBuf[ S->inputDelay ], in, nSamples * sizeof( opus_int16 ) ); - switch (S->resampler_function) { - case USE_silk_resampler_private_up2_HQ_wrapper: - silk_resampler_private_up2_HQ_wrapper(S, out, S->delayBuf, S->Fs_in_kHz); - silk_resampler_private_up2_HQ_wrapper(S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz); - break; - case USE_silk_resampler_private_IIR_FIR: - silk_resampler_private_IIR_FIR(S, out, S->delayBuf, S->Fs_in_kHz); - silk_resampler_private_IIR_FIR(S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz); - break; - case USE_silk_resampler_private_down_FIR: - silk_resampler_private_down_FIR(S, out, S->delayBuf, S->Fs_in_kHz); - silk_resampler_private_down_FIR(S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz); - break; - default: - silk_memcpy(out, S->delayBuf, S->Fs_in_kHz * sizeof(opus_int16)); - silk_memcpy(&out[ S->Fs_out_kHz ], &in[ nSamples ], (inLen - S->Fs_in_kHz) * sizeof(opus_int16)); + switch( S->resampler_function ) { + case USE_silk_resampler_private_up2_HQ_wrapper: + silk_resampler_private_up2_HQ_wrapper( S, out, S->delayBuf, S->Fs_in_kHz ); + silk_resampler_private_up2_HQ_wrapper( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz ); + break; + case USE_silk_resampler_private_IIR_FIR: + silk_resampler_private_IIR_FIR( S, out, S->delayBuf, S->Fs_in_kHz ); + silk_resampler_private_IIR_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz ); + break; + case USE_silk_resampler_private_down_FIR: + silk_resampler_private_down_FIR( S, out, S->delayBuf, S->Fs_in_kHz ); + silk_resampler_private_down_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz ); + break; + default: + silk_memcpy( out, S->delayBuf, S->Fs_in_kHz * sizeof( opus_int16 ) ); + silk_memcpy( &out[ S->Fs_out_kHz ], &in[ nSamples ], ( inLen - S->Fs_in_kHz ) * sizeof( opus_int16 ) ); } /* Copy to delay buffer */ - silk_memcpy(S->delayBuf, &in[ inLen - S->inputDelay ], S->inputDelay * sizeof(opus_int16)); + silk_memcpy( S->delayBuf, &in[ inLen - S->inputDelay ], S->inputDelay * sizeof( opus_int16 ) ); return 0; } diff --git a/src/libopus/silk/resampler_down2.c b/src/libopus/silk/resampler_down2.c index eb9d2a2..2fcd156 100644 --- a/src/libopus/silk/resampler_down2.c +++ b/src/libopus/silk/resampler_down2.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "resampler_rom.h" @@ -38,36 +38,37 @@ void silk_resampler_down2( opus_int16 *out, /* O Output signal [ floor(len/2) ] */ const opus_int16 *in, /* I Input signal [ len ] */ opus_int32 inLen /* I Number of input samples */ -) { - opus_int32 k, len2 = silk_RSHIFT32(inLen, 1); +) +{ + opus_int32 k, len2 = silk_RSHIFT32( inLen, 1 ); opus_int32 in32, out32, Y, X; - celt_assert(silk_resampler_down2_0 > 0); - celt_assert(silk_resampler_down2_1 < 0); + celt_assert( silk_resampler_down2_0 > 0 ); + celt_assert( silk_resampler_down2_1 < 0 ); /* Internal variables and state are in Q10 format */ - for (k = 0; k < len2; k++) { + for( k = 0; k < len2; k++ ) { /* Convert to Q10 */ - in32 = silk_LSHIFT((opus_int32)in[ 2 * k ], 10); + in32 = silk_LSHIFT( (opus_int32)in[ 2 * k ], 10 ); /* All-pass section for even input sample */ - Y = silk_SUB32(in32, S[ 0 ]); - X = silk_SMLAWB(Y, Y, silk_resampler_down2_1); - out32 = silk_ADD32(S[ 0 ], X); - S[ 0 ] = silk_ADD32(in32, X); + Y = silk_SUB32( in32, S[ 0 ] ); + X = silk_SMLAWB( Y, Y, silk_resampler_down2_1 ); + out32 = silk_ADD32( S[ 0 ], X ); + S[ 0 ] = silk_ADD32( in32, X ); /* Convert to Q10 */ - in32 = silk_LSHIFT((opus_int32)in[ 2 * k + 1 ], 10); + in32 = silk_LSHIFT( (opus_int32)in[ 2 * k + 1 ], 10 ); /* All-pass section for odd input sample, and add to output of previous section */ - Y = silk_SUB32(in32, S[ 1 ]); - X = silk_SMULWB(Y, silk_resampler_down2_0); - out32 = silk_ADD32(out32, S[ 1 ]); - out32 = silk_ADD32(out32, X); - S[ 1 ] = silk_ADD32(in32, X); + Y = silk_SUB32( in32, S[ 1 ] ); + X = silk_SMULWB( Y, silk_resampler_down2_0 ); + out32 = silk_ADD32( out32, S[ 1 ] ); + out32 = silk_ADD32( out32, X ); + S[ 1 ] = silk_ADD32( in32, X ); /* Add, convert back to int16 and store to output */ - out[ k ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(out32, 11)); + out[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32, 11 ) ); } } diff --git a/src/libopus/silk/resampler_down2_3.c b/src/libopus/silk/resampler_down2_3.c index 612a261..595f00c 100644 --- a/src/libopus/silk/resampler_down2_3.c +++ b/src/libopus/silk/resampler_down2_3.c @@ -1,37 +1,37 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "resampler_private.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" #define ORDER_FIR 4 @@ -41,46 +41,46 @@ void silk_resampler_down2_3( opus_int16 *out, /* O Output signal [ floor(2*inLen/3) ] */ const opus_int16 *in, /* I Input signal [ inLen ] */ opus_int32 inLen /* I Number of input samples */ -) { +) +{ opus_int32 nSamplesIn, counter, res_Q6; - VARDECL(opus_int32, buf); + VARDECL( opus_int32, buf ); opus_int32 *buf_ptr; SAVE_STACK; - // ALLOC( buf, RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR, opus_int32 ); - opus_int32 *buf = (opus_int32*)malloc((RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR) * sizeof(opus_int32)); + ALLOC( buf, RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR, opus_int32 ); /* Copy buffered samples to start of buffer */ - silk_memcpy(buf, S, ORDER_FIR * sizeof(opus_int32)); + silk_memcpy( buf, S, ORDER_FIR * sizeof( opus_int32 ) ); /* Iterate over blocks of frameSizeIn input samples */ - while (1) { - nSamplesIn = silk_min(inLen, RESAMPLER_MAX_BATCH_SIZE_IN); + while( 1 ) { + nSamplesIn = silk_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN ); /* Second-order AR filter (output in Q8) */ - silk_resampler_private_AR2(&S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, - silk_Resampler_2_3_COEFS_LQ, nSamplesIn); + silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, + silk_Resampler_2_3_COEFS_LQ, nSamplesIn ); /* Interpolate filtered signal */ buf_ptr = buf; counter = nSamplesIn; - while (counter > 2) { + while( counter > 2 ) { /* Inner product */ - res_Q6 = silk_SMULWB(buf_ptr[ 0 ], silk_Resampler_2_3_COEFS_LQ[ 2 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 1 ], silk_Resampler_2_3_COEFS_LQ[ 3 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 2 ], silk_Resampler_2_3_COEFS_LQ[ 5 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 3 ], silk_Resampler_2_3_COEFS_LQ[ 4 ]); + res_Q6 = silk_SMULWB( buf_ptr[ 0 ], silk_Resampler_2_3_COEFS_LQ[ 2 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 1 ], silk_Resampler_2_3_COEFS_LQ[ 3 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 2 ], silk_Resampler_2_3_COEFS_LQ[ 5 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 3 ], silk_Resampler_2_3_COEFS_LQ[ 4 ] ); /* Scale down, saturate and store in output array */ - *out++ = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6)); + *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) ); - res_Q6 = silk_SMULWB(buf_ptr[ 1 ], silk_Resampler_2_3_COEFS_LQ[ 4 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 2 ], silk_Resampler_2_3_COEFS_LQ[ 5 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 3 ], silk_Resampler_2_3_COEFS_LQ[ 3 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 4 ], silk_Resampler_2_3_COEFS_LQ[ 2 ]); + res_Q6 = silk_SMULWB( buf_ptr[ 1 ], silk_Resampler_2_3_COEFS_LQ[ 4 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 2 ], silk_Resampler_2_3_COEFS_LQ[ 5 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 3 ], silk_Resampler_2_3_COEFS_LQ[ 3 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 4 ], silk_Resampler_2_3_COEFS_LQ[ 2 ] ); /* Scale down, saturate and store in output array */ - *out++ = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6)); + *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) ); buf_ptr += 3; counter -= 3; @@ -89,16 +89,15 @@ void silk_resampler_down2_3( in += nSamplesIn; inLen -= nSamplesIn; - if (inLen > 0) { + if( inLen > 0 ) { /* More iterations to do; copy last part of filtered signal to beginning of buffer */ - silk_memcpy(buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof(opus_int32)); + silk_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( opus_int32 ) ); } else { break; } } /* Copy last part of filtered signal to the state for the next call */ - silk_memcpy(S, &buf[ nSamplesIn ], ORDER_FIR * sizeof(opus_int32)); - free(buf); + silk_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( opus_int32 ) ); RESTORE_STACK; } diff --git a/src/libopus/silk/resampler_private.h b/src/libopus/silk/resampler_private.h index 382a5cd..422a7d9 100644 --- a/src/libopus/silk/resampler_private.h +++ b/src/libopus/silk/resampler_private.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_RESAMPLER_PRIVATE_H diff --git a/src/libopus/silk/resampler_private_AR2.c b/src/libopus/silk/resampler_private_AR2.c index cfc6c7f..8468578 100644 --- a/src/libopus/silk/resampler_private_AR2.c +++ b/src/libopus/silk/resampler_private_AR2.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "resampler_private.h" @@ -39,16 +39,17 @@ void silk_resampler_private_AR2( const opus_int16 in[], /* I Input signal */ const opus_int16 A_Q14[], /* I AR coefficients, Q14 */ opus_int32 len /* I Signal length */ -) { +) +{ opus_int32 k; opus_int32 out32; - for (k = 0; k < len; k++) { - out32 = silk_ADD_LSHIFT32(S[ 0 ], (opus_int32)in[ k ], 8); + for( k = 0; k < len; k++ ) { + out32 = silk_ADD_LSHIFT32( S[ 0 ], (opus_int32)in[ k ], 8 ); out_Q8[ k ] = out32; - out32 = silk_LSHIFT(out32, 2); - S[ 0 ] = silk_SMLAWB(S[ 1 ], out32, A_Q14[ 0 ]); - S[ 1 ] = silk_SMULWB(out32, A_Q14[ 1 ]); + out32 = silk_LSHIFT( out32, 2 ); + S[ 0 ] = silk_SMLAWB( S[ 1 ], out32, A_Q14[ 0 ] ); + S[ 1 ] = silk_SMULWB( out32, A_Q14[ 1 ] ); } } diff --git a/src/libopus/silk/resampler_private_IIR_FIR.c b/src/libopus/silk/resampler_private_IIR_FIR.c index f3ddd2e..5aff032 100644 --- a/src/libopus/silk/resampler_private_IIR_FIR.c +++ b/src/libopus/silk/resampler_private_IIR_FIR.c @@ -1,62 +1,63 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "resampler_private.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" static OPUS_INLINE opus_int16 *silk_resampler_private_IIR_FIR_INTERPOL( opus_int16 *out, opus_int16 *buf, opus_int32 max_index_Q16, opus_int32 index_increment_Q16 -) { +) +{ opus_int32 index_Q16, res_Q15; opus_int16 *buf_ptr; opus_int32 table_index; /* Interpolate upsampled signal and store in output array */ - for (index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16) { - table_index = silk_SMULWB(index_Q16 & 0xFFFF, 12); + for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) { + table_index = silk_SMULWB( index_Q16 & 0xFFFF, 12 ); buf_ptr = &buf[ index_Q16 >> 16 ]; - res_Q15 = silk_SMULBB(buf_ptr[ 0 ], silk_resampler_frac_FIR_12[ table_index ][ 0 ]); - res_Q15 = silk_SMLABB(res_Q15, buf_ptr[ 1 ], silk_resampler_frac_FIR_12[ table_index ][ 1 ]); - res_Q15 = silk_SMLABB(res_Q15, buf_ptr[ 2 ], silk_resampler_frac_FIR_12[ table_index ][ 2 ]); - res_Q15 = silk_SMLABB(res_Q15, buf_ptr[ 3 ], silk_resampler_frac_FIR_12[ table_index ][ 3 ]); - res_Q15 = silk_SMLABB(res_Q15, buf_ptr[ 4 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 3 ]); - res_Q15 = silk_SMLABB(res_Q15, buf_ptr[ 5 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 2 ]); - res_Q15 = silk_SMLABB(res_Q15, buf_ptr[ 6 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 1 ]); - res_Q15 = silk_SMLABB(res_Q15, buf_ptr[ 7 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 0 ]); - *out++ = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(res_Q15, 15)); + res_Q15 = silk_SMULBB( buf_ptr[ 0 ], silk_resampler_frac_FIR_12[ table_index ][ 0 ] ); + res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 1 ], silk_resampler_frac_FIR_12[ table_index ][ 1 ] ); + res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 2 ], silk_resampler_frac_FIR_12[ table_index ][ 2 ] ); + res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 3 ], silk_resampler_frac_FIR_12[ table_index ][ 3 ] ); + res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 4 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 3 ] ); + res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 5 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 2 ] ); + res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 6 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 1 ] ); + res_Q15 = silk_SMLABB( res_Q15, buf_ptr[ 7 ], silk_resampler_frac_FIR_12[ 11 - table_index ][ 0 ] ); + *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q15, 15 ) ); } return out; } @@ -66,40 +67,41 @@ void silk_resampler_private_IIR_FIR( opus_int16 out[], /* O Output signal */ const opus_int16 in[], /* I Input signal */ opus_int32 inLen /* I Number of input samples */ -) { +) +{ silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS; opus_int32 nSamplesIn; opus_int32 max_index_Q16, index_increment_Q16; - VARDECL(opus_int16, buf); + VARDECL( opus_int16, buf ); SAVE_STACK; - ALLOC(buf, 2 * S->batchSize + RESAMPLER_ORDER_FIR_12, opus_int16); + ALLOC( buf, 2 * S->batchSize + RESAMPLER_ORDER_FIR_12, opus_int16 ); /* Copy buffered samples to start of buffer */ - silk_memcpy(buf, S->sFIR.i16, RESAMPLER_ORDER_FIR_12 * sizeof(opus_int16)); + silk_memcpy( buf, S->sFIR.i16, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); /* Iterate over blocks of frameSizeIn input samples */ index_increment_Q16 = S->invRatio_Q16; - while (1) { - nSamplesIn = silk_min(inLen, S->batchSize); + while( 1 ) { + nSamplesIn = silk_min( inLen, S->batchSize ); /* Upsample 2x */ - silk_resampler_private_up2_HQ(S->sIIR, &buf[ RESAMPLER_ORDER_FIR_12 ], in, nSamplesIn); + silk_resampler_private_up2_HQ( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_12 ], in, nSamplesIn ); - max_index_Q16 = silk_LSHIFT32(nSamplesIn, 16 + 1); /* + 1 because 2x upsampling */ - out = silk_resampler_private_IIR_FIR_INTERPOL(out, buf, max_index_Q16, index_increment_Q16); + max_index_Q16 = silk_LSHIFT32( nSamplesIn, 16 + 1 ); /* + 1 because 2x upsampling */ + out = silk_resampler_private_IIR_FIR_INTERPOL( out, buf, max_index_Q16, index_increment_Q16 ); in += nSamplesIn; inLen -= nSamplesIn; - if (inLen > 0) { + if( inLen > 0 ) { /* More iterations to do; copy last part of filtered signal to beginning of buffer */ - silk_memcpy(buf, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof(opus_int16)); + silk_memcpy( buf, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); } else { break; } } /* Copy last part of filtered signal to the state for the next call */ - silk_memcpy(S->sFIR.i16, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof(opus_int16)); + silk_memcpy( S->sFIR.i16, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); RESTORE_STACK; } diff --git a/src/libopus/silk/resampler_private_down_FIR.c b/src/libopus/silk/resampler_private_down_FIR.c index e4d38eb..4ee8897 100644 --- a/src/libopus/silk/resampler_private_down_FIR.c +++ b/src/libopus/silk/resampler_private_down_FIR.c @@ -1,37 +1,37 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "resampler_private.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" static OPUS_INLINE opus_int16 *silk_resampler_private_down_FIR_INTERPOL( opus_int16 *out, @@ -41,101 +41,102 @@ static OPUS_INLINE opus_int16 *silk_resampler_private_down_FIR_INTERPOL( opus_int FIR_Fracs, opus_int32 max_index_Q16, opus_int32 index_increment_Q16 -) { +) +{ opus_int32 index_Q16, res_Q6; opus_int32 *buf_ptr; opus_int32 interpol_ind; const opus_int16 *interpol_ptr; - switch (FIR_Order) { - case RESAMPLER_DOWN_ORDER_FIR0: - for (index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16) { - /* Integer part gives pointer to buffered input */ - buf_ptr = buf + silk_RSHIFT(index_Q16, 16); + switch( FIR_Order ) { + case RESAMPLER_DOWN_ORDER_FIR0: + for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) { + /* Integer part gives pointer to buffered input */ + buf_ptr = buf + silk_RSHIFT( index_Q16, 16 ); - /* Fractional part gives interpolation coefficients */ - interpol_ind = silk_SMULWB(index_Q16 & 0xFFFF, FIR_Fracs); + /* Fractional part gives interpolation coefficients */ + interpol_ind = silk_SMULWB( index_Q16 & 0xFFFF, FIR_Fracs ); - /* Inner product */ - interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR0 / 2 * interpol_ind ]; - res_Q6 = silk_SMULWB(buf_ptr[ 0 ], interpol_ptr[ 0 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 1 ], interpol_ptr[ 1 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 2 ], interpol_ptr[ 2 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 3 ], interpol_ptr[ 3 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 4 ], interpol_ptr[ 4 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 5 ], interpol_ptr[ 5 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 6 ], interpol_ptr[ 6 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 7 ], interpol_ptr[ 7 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 8 ], interpol_ptr[ 8 ]); - interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR0 / 2 * (FIR_Fracs - 1 - interpol_ind) ]; - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 17 ], interpol_ptr[ 0 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 16 ], interpol_ptr[ 1 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 15 ], interpol_ptr[ 2 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 14 ], interpol_ptr[ 3 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 13 ], interpol_ptr[ 4 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 12 ], interpol_ptr[ 5 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 11 ], interpol_ptr[ 6 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 10 ], interpol_ptr[ 7 ]); - res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[ 9 ], interpol_ptr[ 8 ]); + /* Inner product */ + interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR0 / 2 * interpol_ind ]; + res_Q6 = silk_SMULWB( buf_ptr[ 0 ], interpol_ptr[ 0 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 1 ], interpol_ptr[ 1 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 2 ], interpol_ptr[ 2 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 3 ], interpol_ptr[ 3 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 4 ], interpol_ptr[ 4 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 5 ], interpol_ptr[ 5 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 6 ], interpol_ptr[ 6 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 7 ], interpol_ptr[ 7 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 8 ], interpol_ptr[ 8 ] ); + interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR0 / 2 * ( FIR_Fracs - 1 - interpol_ind ) ]; + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 17 ], interpol_ptr[ 0 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 16 ], interpol_ptr[ 1 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 15 ], interpol_ptr[ 2 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 14 ], interpol_ptr[ 3 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 13 ], interpol_ptr[ 4 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 12 ], interpol_ptr[ 5 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 11 ], interpol_ptr[ 6 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 10 ], interpol_ptr[ 7 ] ); + res_Q6 = silk_SMLAWB( res_Q6, buf_ptr[ 9 ], interpol_ptr[ 8 ] ); - /* Scale down, saturate and store in output array */ - *out++ = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6)); - } - break; - case RESAMPLER_DOWN_ORDER_FIR1: - for (index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16) { - /* Integer part gives pointer to buffered input */ - buf_ptr = buf + silk_RSHIFT(index_Q16, 16); + /* Scale down, saturate and store in output array */ + *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) ); + } + break; + case RESAMPLER_DOWN_ORDER_FIR1: + for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) { + /* Integer part gives pointer to buffered input */ + buf_ptr = buf + silk_RSHIFT( index_Q16, 16 ); - /* Inner product */ - res_Q6 = silk_SMULWB(silk_ADD32(buf_ptr[ 0 ], buf_ptr[ 23 ]), FIR_Coefs[ 0 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 1 ], buf_ptr[ 22 ]), FIR_Coefs[ 1 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 2 ], buf_ptr[ 21 ]), FIR_Coefs[ 2 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 3 ], buf_ptr[ 20 ]), FIR_Coefs[ 3 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 4 ], buf_ptr[ 19 ]), FIR_Coefs[ 4 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 5 ], buf_ptr[ 18 ]), FIR_Coefs[ 5 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 6 ], buf_ptr[ 17 ]), FIR_Coefs[ 6 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 7 ], buf_ptr[ 16 ]), FIR_Coefs[ 7 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 8 ], buf_ptr[ 15 ]), FIR_Coefs[ 8 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 9 ], buf_ptr[ 14 ]), FIR_Coefs[ 9 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 10 ], buf_ptr[ 13 ]), FIR_Coefs[ 10 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 11 ], buf_ptr[ 12 ]), FIR_Coefs[ 11 ]); + /* Inner product */ + res_Q6 = silk_SMULWB( silk_ADD32( buf_ptr[ 0 ], buf_ptr[ 23 ] ), FIR_Coefs[ 0 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 1 ], buf_ptr[ 22 ] ), FIR_Coefs[ 1 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 2 ], buf_ptr[ 21 ] ), FIR_Coefs[ 2 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 3 ], buf_ptr[ 20 ] ), FIR_Coefs[ 3 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 4 ], buf_ptr[ 19 ] ), FIR_Coefs[ 4 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 5 ], buf_ptr[ 18 ] ), FIR_Coefs[ 5 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 6 ], buf_ptr[ 17 ] ), FIR_Coefs[ 6 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 7 ], buf_ptr[ 16 ] ), FIR_Coefs[ 7 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 8 ], buf_ptr[ 15 ] ), FIR_Coefs[ 8 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 9 ], buf_ptr[ 14 ] ), FIR_Coefs[ 9 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 10 ], buf_ptr[ 13 ] ), FIR_Coefs[ 10 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 11 ], buf_ptr[ 12 ] ), FIR_Coefs[ 11 ] ); - /* Scale down, saturate and store in output array */ - *out++ = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6)); - } - break; - case RESAMPLER_DOWN_ORDER_FIR2: - for (index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16) { - /* Integer part gives pointer to buffered input */ - buf_ptr = buf + silk_RSHIFT(index_Q16, 16); + /* Scale down, saturate and store in output array */ + *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) ); + } + break; + case RESAMPLER_DOWN_ORDER_FIR2: + for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) { + /* Integer part gives pointer to buffered input */ + buf_ptr = buf + silk_RSHIFT( index_Q16, 16 ); - /* Inner product */ - res_Q6 = silk_SMULWB(silk_ADD32(buf_ptr[ 0 ], buf_ptr[ 35 ]), FIR_Coefs[ 0 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 1 ], buf_ptr[ 34 ]), FIR_Coefs[ 1 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 2 ], buf_ptr[ 33 ]), FIR_Coefs[ 2 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 3 ], buf_ptr[ 32 ]), FIR_Coefs[ 3 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 4 ], buf_ptr[ 31 ]), FIR_Coefs[ 4 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 5 ], buf_ptr[ 30 ]), FIR_Coefs[ 5 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 6 ], buf_ptr[ 29 ]), FIR_Coefs[ 6 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 7 ], buf_ptr[ 28 ]), FIR_Coefs[ 7 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 8 ], buf_ptr[ 27 ]), FIR_Coefs[ 8 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 9 ], buf_ptr[ 26 ]), FIR_Coefs[ 9 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 10 ], buf_ptr[ 25 ]), FIR_Coefs[ 10 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 11 ], buf_ptr[ 24 ]), FIR_Coefs[ 11 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 12 ], buf_ptr[ 23 ]), FIR_Coefs[ 12 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 13 ], buf_ptr[ 22 ]), FIR_Coefs[ 13 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 14 ], buf_ptr[ 21 ]), FIR_Coefs[ 14 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 15 ], buf_ptr[ 20 ]), FIR_Coefs[ 15 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 16 ], buf_ptr[ 19 ]), FIR_Coefs[ 16 ]); - res_Q6 = silk_SMLAWB(res_Q6, silk_ADD32(buf_ptr[ 17 ], buf_ptr[ 18 ]), FIR_Coefs[ 17 ]); + /* Inner product */ + res_Q6 = silk_SMULWB( silk_ADD32( buf_ptr[ 0 ], buf_ptr[ 35 ] ), FIR_Coefs[ 0 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 1 ], buf_ptr[ 34 ] ), FIR_Coefs[ 1 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 2 ], buf_ptr[ 33 ] ), FIR_Coefs[ 2 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 3 ], buf_ptr[ 32 ] ), FIR_Coefs[ 3 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 4 ], buf_ptr[ 31 ] ), FIR_Coefs[ 4 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 5 ], buf_ptr[ 30 ] ), FIR_Coefs[ 5 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 6 ], buf_ptr[ 29 ] ), FIR_Coefs[ 6 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 7 ], buf_ptr[ 28 ] ), FIR_Coefs[ 7 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 8 ], buf_ptr[ 27 ] ), FIR_Coefs[ 8 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 9 ], buf_ptr[ 26 ] ), FIR_Coefs[ 9 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 10 ], buf_ptr[ 25 ] ), FIR_Coefs[ 10 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 11 ], buf_ptr[ 24 ] ), FIR_Coefs[ 11 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 12 ], buf_ptr[ 23 ] ), FIR_Coefs[ 12 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 13 ], buf_ptr[ 22 ] ), FIR_Coefs[ 13 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 14 ], buf_ptr[ 21 ] ), FIR_Coefs[ 14 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 15 ], buf_ptr[ 20 ] ), FIR_Coefs[ 15 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 16 ], buf_ptr[ 19 ] ), FIR_Coefs[ 16 ] ); + res_Q6 = silk_SMLAWB( res_Q6, silk_ADD32( buf_ptr[ 17 ], buf_ptr[ 18 ] ), FIR_Coefs[ 17 ] ); - /* Scale down, saturate and store in output array */ - *out++ = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6)); - } - break; - default: - celt_assert(0); + /* Scale down, saturate and store in output array */ + *out++ = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( res_Q6, 6 ) ); + } + break; + default: + celt_assert( 0 ); } return out; } @@ -146,47 +147,48 @@ void silk_resampler_private_down_FIR( opus_int16 out[], /* O Output signal */ const opus_int16 in[], /* I Input signal */ opus_int32 inLen /* I Number of input samples */ -) { +) +{ silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS; opus_int32 nSamplesIn; opus_int32 max_index_Q16, index_increment_Q16; - VARDECL(opus_int32, buf); + VARDECL( opus_int32, buf ); const opus_int16 *FIR_Coefs; SAVE_STACK; - ALLOC(buf, S->batchSize + S->FIR_Order, opus_int32); + ALLOC( buf, S->batchSize + S->FIR_Order, opus_int32 ); /* Copy buffered samples to start of buffer */ - silk_memcpy(buf, S->sFIR.i32, S->FIR_Order * sizeof(opus_int32)); + silk_memcpy( buf, S->sFIR.i32, S->FIR_Order * sizeof( opus_int32 ) ); FIR_Coefs = &S->Coefs[ 2 ]; /* Iterate over blocks of frameSizeIn input samples */ index_increment_Q16 = S->invRatio_Q16; - while (1) { - nSamplesIn = silk_min(inLen, S->batchSize); + while( 1 ) { + nSamplesIn = silk_min( inLen, S->batchSize ); /* Second-order AR filter (output in Q8) */ - silk_resampler_private_AR2(S->sIIR, &buf[ S->FIR_Order ], in, S->Coefs, nSamplesIn); + silk_resampler_private_AR2( S->sIIR, &buf[ S->FIR_Order ], in, S->Coefs, nSamplesIn ); - max_index_Q16 = silk_LSHIFT32(nSamplesIn, 16); + max_index_Q16 = silk_LSHIFT32( nSamplesIn, 16 ); /* Interpolate filtered signal */ - out = silk_resampler_private_down_FIR_INTERPOL(out, buf, FIR_Coefs, S->FIR_Order, - S->FIR_Fracs, max_index_Q16, index_increment_Q16); + out = silk_resampler_private_down_FIR_INTERPOL( out, buf, FIR_Coefs, S->FIR_Order, + S->FIR_Fracs, max_index_Q16, index_increment_Q16 ); in += nSamplesIn; inLen -= nSamplesIn; - if (inLen > 1) { + if( inLen > 1 ) { /* More iterations to do; copy last part of filtered signal to beginning of buffer */ - silk_memcpy(buf, &buf[ nSamplesIn ], S->FIR_Order * sizeof(opus_int32)); + silk_memcpy( buf, &buf[ nSamplesIn ], S->FIR_Order * sizeof( opus_int32 ) ); } else { break; } } /* Copy last part of filtered signal to the state for the next call */ - silk_memcpy(S->sFIR.i32, &buf[ nSamplesIn ], S->FIR_Order * sizeof(opus_int32)); + silk_memcpy( S->sFIR.i32, &buf[ nSamplesIn ], S->FIR_Order * sizeof( opus_int32 ) ); RESTORE_STACK; } diff --git a/src/libopus/silk/resampler_private_up2_HQ.c b/src/libopus/silk/resampler_private_up2_HQ.c index 01ef476..db8ce7f 100644 --- a/src/libopus/silk/resampler_private_up2_HQ.c +++ b/src/libopus/silk/resampler_private_up2_HQ.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" #include "resampler_private.h" @@ -40,63 +40,64 @@ void silk_resampler_private_up2_HQ( opus_int16 *out, /* O Output signal [ 2 * len ] */ const opus_int16 *in, /* I Input signal [ len ] */ opus_int32 len /* I Number of input samples */ -) { +) +{ opus_int32 k; opus_int32 in32, out32_1, out32_2, Y, X; - silk_assert(silk_resampler_up2_hq_0[ 0 ] > 0); - silk_assert(silk_resampler_up2_hq_0[ 1 ] > 0); - silk_assert(silk_resampler_up2_hq_0[ 2 ] < 0); - silk_assert(silk_resampler_up2_hq_1[ 0 ] > 0); - silk_assert(silk_resampler_up2_hq_1[ 1 ] > 0); - silk_assert(silk_resampler_up2_hq_1[ 2 ] < 0); + silk_assert( silk_resampler_up2_hq_0[ 0 ] > 0 ); + silk_assert( silk_resampler_up2_hq_0[ 1 ] > 0 ); + silk_assert( silk_resampler_up2_hq_0[ 2 ] < 0 ); + silk_assert( silk_resampler_up2_hq_1[ 0 ] > 0 ); + silk_assert( silk_resampler_up2_hq_1[ 1 ] > 0 ); + silk_assert( silk_resampler_up2_hq_1[ 2 ] < 0 ); /* Internal variables and state are in Q10 format */ - for (k = 0; k < len; k++) { + for( k = 0; k < len; k++ ) { /* Convert to Q10 */ - in32 = silk_LSHIFT((opus_int32)in[ k ], 10); + in32 = silk_LSHIFT( (opus_int32)in[ k ], 10 ); /* First all-pass section for even output sample */ - Y = silk_SUB32(in32, S[ 0 ]); - X = silk_SMULWB(Y, silk_resampler_up2_hq_0[ 0 ]); - out32_1 = silk_ADD32(S[ 0 ], X); - S[ 0 ] = silk_ADD32(in32, X); + Y = silk_SUB32( in32, S[ 0 ] ); + X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 0 ] ); + out32_1 = silk_ADD32( S[ 0 ], X ); + S[ 0 ] = silk_ADD32( in32, X ); /* Second all-pass section for even output sample */ - Y = silk_SUB32(out32_1, S[ 1 ]); - X = silk_SMULWB(Y, silk_resampler_up2_hq_0[ 1 ]); - out32_2 = silk_ADD32(S[ 1 ], X); - S[ 1 ] = silk_ADD32(out32_1, X); + Y = silk_SUB32( out32_1, S[ 1 ] ); + X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 1 ] ); + out32_2 = silk_ADD32( S[ 1 ], X ); + S[ 1 ] = silk_ADD32( out32_1, X ); /* Third all-pass section for even output sample */ - Y = silk_SUB32(out32_2, S[ 2 ]); - X = silk_SMLAWB(Y, Y, silk_resampler_up2_hq_0[ 2 ]); - out32_1 = silk_ADD32(S[ 2 ], X); - S[ 2 ] = silk_ADD32(out32_2, X); + Y = silk_SUB32( out32_2, S[ 2 ] ); + X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_0[ 2 ] ); + out32_1 = silk_ADD32( S[ 2 ], X ); + S[ 2 ] = silk_ADD32( out32_2, X ); /* Apply gain in Q15, convert back to int16 and store to output */ - out[ 2 * k ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(out32_1, 10)); + out[ 2 * k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) ); /* First all-pass section for odd output sample */ - Y = silk_SUB32(in32, S[ 3 ]); - X = silk_SMULWB(Y, silk_resampler_up2_hq_1[ 0 ]); - out32_1 = silk_ADD32(S[ 3 ], X); - S[ 3 ] = silk_ADD32(in32, X); + Y = silk_SUB32( in32, S[ 3 ] ); + X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 0 ] ); + out32_1 = silk_ADD32( S[ 3 ], X ); + S[ 3 ] = silk_ADD32( in32, X ); /* Second all-pass section for odd output sample */ - Y = silk_SUB32(out32_1, S[ 4 ]); - X = silk_SMULWB(Y, silk_resampler_up2_hq_1[ 1 ]); - out32_2 = silk_ADD32(S[ 4 ], X); - S[ 4 ] = silk_ADD32(out32_1, X); + Y = silk_SUB32( out32_1, S[ 4 ] ); + X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 1 ] ); + out32_2 = silk_ADD32( S[ 4 ], X ); + S[ 4 ] = silk_ADD32( out32_1, X ); /* Third all-pass section for odd output sample */ - Y = silk_SUB32(out32_2, S[ 5 ]); - X = silk_SMLAWB(Y, Y, silk_resampler_up2_hq_1[ 2 ]); - out32_1 = silk_ADD32(S[ 5 ], X); - S[ 5 ] = silk_ADD32(out32_2, X); + Y = silk_SUB32( out32_2, S[ 5 ] ); + X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_1[ 2 ] ); + out32_1 = silk_ADD32( S[ 5 ], X ); + S[ 5 ] = silk_ADD32( out32_2, X ); /* Apply gain in Q15, convert back to int16 and store to output */ - out[ 2 * k + 1 ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(out32_1, 10)); + out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) ); } } @@ -105,7 +106,8 @@ void silk_resampler_private_up2_HQ_wrapper( opus_int16 *out, /* O Output signal [ 2 * len ] */ const opus_int16 *in, /* I Input signal [ len ] */ opus_int32 len /* I Number of input samples */ -) { +) +{ silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS; - silk_resampler_private_up2_HQ(S->sIIR, out, in, len); + silk_resampler_private_up2_HQ( S->sIIR, out, in, len ); } diff --git a/src/libopus/silk/resampler_rom.c b/src/libopus/silk/resampler_rom.c index 63965a8..70d9d78 100644 --- a/src/libopus/silk/resampler_rom.c +++ b/src/libopus/silk/resampler_rom.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif -/* Filter coefficients for IIR/FIR polyphase resampling * - Total size: 179 Words (358 Bytes) */ +/* Filter coefficients for IIR/FIR polyphase resampling * + * Total size: 179 Words (358 Bytes) */ #include "resampler_private.h" @@ -42,42 +42,42 @@ /* Tables with IIR and FIR coefficients for fractional downsamplers (123 Words) */ silk_DWORD_ALIGN const opus_int16 silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR0 / 2 ] = { -20694, -13867, - -49, 64, 17, -157, 353, -496, 163, 11047, 22205, - -39, 6, 91, -170, 186, 23, -896, 6336, 19928, - -19, -36, 102, -89, -24, 328, -951, 2568, 15909, - }; + -49, 64, 17, -157, 353, -496, 163, 11047, 22205, + -39, 6, 91, -170, 186, 23, -896, 6336, 19928, + -19, -36, 102, -89, -24, 328, -951, 2568, 15909, +}; silk_DWORD_ALIGN const opus_int16 silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR0 / 2 ] = { -14457, -14019, 64, 128, -122, 36, 310, -768, 584, 9267, 17733, 12, 128, 18, -142, 288, -117, -865, 4123, 14459, - }; +}; silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR1 / 2 ] = { - 616, -14323, - -10, 39, 58, -46, -84, 120, 184, -315, -541, 1284, 5380, 9024, + 616, -14323, + -10, 39, 58, -46, -84, 120, 184, -315, -541, 1284, 5380, 9024, }; silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ] = { - 16102, -15162, - -13, 0, 20, 26, 5, -31, -43, -4, 65, 90, 7, -157, -248, -44, 593, 1583, 2612, 3271, + 16102, -15162, + -13, 0, 20, 26, 5, -31, -43, -4, 65, 90, 7, -157, -248, -44, 593, 1583, 2612, 3271, }; silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_4_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ] = { - 22500, -15099, - 3, -14, -20, -15, 2, 25, 37, 25, -16, -71, -107, -79, 50, 292, 623, 982, 1288, 1464, + 22500, -15099, + 3, -14, -20, -15, 2, 25, 37, 25, -16, -71, -107, -79, 50, 292, 623, 982, 1288, 1464, }; silk_DWORD_ALIGN const opus_int16 silk_Resampler_1_6_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR2 / 2 ] = { - 27540, -15257, - 17, 12, 8, 1, -10, -22, -30, -32, -22, 3, 44, 100, 168, 243, 317, 381, 429, 455, + 27540, -15257, + 17, 12, 8, 1, -10, -22, -30, -32, -22, 3, 44, 100, 168, 243, 317, 381, 429, 455, }; silk_DWORD_ALIGN const opus_int16 silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ] = { - -2797, -6507, - 4697, 10739, - 1567, 8276, - }; + -2797, -6507, + 4697, 10739, + 1567, 8276, +}; /* Table with interplation fractions of 1/24, 3/24, 5/24, ... , 23/24 : 23/24 (46 Words) */ silk_DWORD_ALIGN const opus_int16 silk_resampler_frac_FIR_12[ 12 ][ RESAMPLER_ORDER_FIR_12 / 2 ] = { diff --git a/src/libopus/silk/resampler_rom.h b/src/libopus/silk/resampler_rom.h index fe4d964..490b338 100644 --- a/src/libopus/silk/resampler_rom.h +++ b/src/libopus/silk/resampler_rom.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_FIX_RESAMPLER_ROM_H diff --git a/src/libopus/silk/resampler_structs.h b/src/libopus/silk/resampler_structs.h index f2f652e..9e9457d 100644 --- a/src/libopus/silk/resampler_structs.h +++ b/src/libopus/silk/resampler_structs.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_RESAMPLER_STRUCTS_H @@ -35,9 +35,9 @@ extern "C" { #define SILK_RESAMPLER_MAX_FIR_ORDER 36 #define SILK_RESAMPLER_MAX_IIR_ORDER 6 -typedef struct _silk_resampler_state_struct { +typedef struct _silk_resampler_state_struct{ opus_int32 sIIR[ SILK_RESAMPLER_MAX_IIR_ORDER ]; /* this must be the first element of this struct */ - union { + union{ opus_int32 i32[ SILK_RESAMPLER_MAX_FIR_ORDER ]; opus_int16 i16[ SILK_RESAMPLER_MAX_FIR_ORDER ]; } sFIR; diff --git a/src/libopus/silk/shell_coder.c b/src/libopus/silk/shell_coder.c index 5f83307..6efa4ea 100644 --- a/src/libopus/silk/shell_coder.c +++ b/src/libopus/silk/shell_coder.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -37,9 +37,10 @@ static OPUS_INLINE void combine_pulses( opus_int *out, /* O combined pulses vector [len] */ const opus_int *in, /* I input vector [2 * len] */ const opus_int len /* I number of OUTPUT samples */ -) { +) +{ opus_int k; - for (k = 0; k < len; k++) { + for( k = 0; k < len; k++ ) { out[ k ] = in[ 2 * k ] + in[ 2 * k + 1 ]; } } @@ -49,9 +50,10 @@ static OPUS_INLINE void encode_split( const opus_int p_child1, /* I pulse amplitude of first child subframe */ const opus_int p, /* I pulse amplitude of current subframe */ const opus_uint8 *shell_table /* I table of shell cdfs */ -) { - if (p > 0) { - ec_enc_icdf(psRangeEnc, p_child1, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8); +) +{ + if( p > 0 ) { + ec_enc_icdf( psRangeEnc, p_child1, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8 ); } } @@ -61,9 +63,10 @@ static OPUS_INLINE void decode_split( ec_dec *psRangeDec, /* I/O Compressor data structure */ const opus_int p, /* I pulse amplitude of current subframe */ const opus_uint8 *shell_table /* I table of shell cdfs */ -) { - if (p > 0) { - p_child1[ 0 ] = ec_dec_icdf(psRangeDec, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8); +) +{ + if( p > 0 ) { + p_child1[ 0 ] = ec_dec_icdf( psRangeDec, &shell_table[ silk_shell_code_table_offsets[ p ] ], 8 ); p_child2[ 0 ] = p - p_child1[ 0 ]; } else { p_child1[ 0 ] = 0; @@ -75,39 +78,40 @@ static OPUS_INLINE void decode_split( void silk_shell_encoder( ec_enc *psRangeEnc, /* I/O compressor data structure */ const opus_int *pulses0 /* I data: nonnegative pulse amplitudes */ -) { +) +{ opus_int pulses1[ 8 ], pulses2[ 4 ], pulses3[ 2 ], pulses4[ 1 ]; /* this function operates on one shell code frame of 16 pulses */ - silk_assert(SHELL_CODEC_FRAME_LENGTH == 16); + silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 ); /* tree representation per pulse-subframe */ - combine_pulses(pulses1, pulses0, 8); - combine_pulses(pulses2, pulses1, 4); - combine_pulses(pulses3, pulses2, 2); - combine_pulses(pulses4, pulses3, 1); + combine_pulses( pulses1, pulses0, 8 ); + combine_pulses( pulses2, pulses1, 4 ); + combine_pulses( pulses3, pulses2, 2 ); + combine_pulses( pulses4, pulses3, 1 ); - encode_split(psRangeEnc, pulses3[ 0 ], pulses4[ 0 ], silk_shell_code_table3); + encode_split( psRangeEnc, pulses3[ 0 ], pulses4[ 0 ], silk_shell_code_table3 ); - encode_split(psRangeEnc, pulses2[ 0 ], pulses3[ 0 ], silk_shell_code_table2); + encode_split( psRangeEnc, pulses2[ 0 ], pulses3[ 0 ], silk_shell_code_table2 ); - encode_split(psRangeEnc, pulses1[ 0 ], pulses2[ 0 ], silk_shell_code_table1); - encode_split(psRangeEnc, pulses0[ 0 ], pulses1[ 0 ], silk_shell_code_table0); - encode_split(psRangeEnc, pulses0[ 2 ], pulses1[ 1 ], silk_shell_code_table0); + encode_split( psRangeEnc, pulses1[ 0 ], pulses2[ 0 ], silk_shell_code_table1 ); + encode_split( psRangeEnc, pulses0[ 0 ], pulses1[ 0 ], silk_shell_code_table0 ); + encode_split( psRangeEnc, pulses0[ 2 ], pulses1[ 1 ], silk_shell_code_table0 ); - encode_split(psRangeEnc, pulses1[ 2 ], pulses2[ 1 ], silk_shell_code_table1); - encode_split(psRangeEnc, pulses0[ 4 ], pulses1[ 2 ], silk_shell_code_table0); - encode_split(psRangeEnc, pulses0[ 6 ], pulses1[ 3 ], silk_shell_code_table0); + encode_split( psRangeEnc, pulses1[ 2 ], pulses2[ 1 ], silk_shell_code_table1 ); + encode_split( psRangeEnc, pulses0[ 4 ], pulses1[ 2 ], silk_shell_code_table0 ); + encode_split( psRangeEnc, pulses0[ 6 ], pulses1[ 3 ], silk_shell_code_table0 ); - encode_split(psRangeEnc, pulses2[ 2 ], pulses3[ 1 ], silk_shell_code_table2); + encode_split( psRangeEnc, pulses2[ 2 ], pulses3[ 1 ], silk_shell_code_table2 ); - encode_split(psRangeEnc, pulses1[ 4 ], pulses2[ 2 ], silk_shell_code_table1); - encode_split(psRangeEnc, pulses0[ 8 ], pulses1[ 4 ], silk_shell_code_table0); - encode_split(psRangeEnc, pulses0[ 10 ], pulses1[ 5 ], silk_shell_code_table0); + encode_split( psRangeEnc, pulses1[ 4 ], pulses2[ 2 ], silk_shell_code_table1 ); + encode_split( psRangeEnc, pulses0[ 8 ], pulses1[ 4 ], silk_shell_code_table0 ); + encode_split( psRangeEnc, pulses0[ 10 ], pulses1[ 5 ], silk_shell_code_table0 ); - encode_split(psRangeEnc, pulses1[ 6 ], pulses2[ 3 ], silk_shell_code_table1); - encode_split(psRangeEnc, pulses0[ 12 ], pulses1[ 6 ], silk_shell_code_table0); - encode_split(psRangeEnc, pulses0[ 14 ], pulses1[ 7 ], silk_shell_code_table0); + encode_split( psRangeEnc, pulses1[ 6 ], pulses2[ 3 ], silk_shell_code_table1 ); + encode_split( psRangeEnc, pulses0[ 12 ], pulses1[ 6 ], silk_shell_code_table0 ); + encode_split( psRangeEnc, pulses0[ 14 ], pulses1[ 7 ], silk_shell_code_table0 ); } @@ -116,31 +120,32 @@ void silk_shell_decoder( opus_int16 *pulses0, /* O data: nonnegative pulse amplitudes */ ec_dec *psRangeDec, /* I/O Compressor data structure */ const opus_int pulses4 /* I number of pulses per pulse-subframe */ -) { +) +{ opus_int16 pulses3[ 2 ], pulses2[ 4 ], pulses1[ 8 ]; /* this function operates on one shell code frame of 16 pulses */ - silk_assert(SHELL_CODEC_FRAME_LENGTH == 16); + silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 ); - decode_split(&pulses3[ 0 ], &pulses3[ 1 ], psRangeDec, pulses4, silk_shell_code_table3); + decode_split( &pulses3[ 0 ], &pulses3[ 1 ], psRangeDec, pulses4, silk_shell_code_table3 ); - decode_split(&pulses2[ 0 ], &pulses2[ 1 ], psRangeDec, pulses3[ 0 ], silk_shell_code_table2); + decode_split( &pulses2[ 0 ], &pulses2[ 1 ], psRangeDec, pulses3[ 0 ], silk_shell_code_table2 ); - decode_split(&pulses1[ 0 ], &pulses1[ 1 ], psRangeDec, pulses2[ 0 ], silk_shell_code_table1); - decode_split(&pulses0[ 0 ], &pulses0[ 1 ], psRangeDec, pulses1[ 0 ], silk_shell_code_table0); - decode_split(&pulses0[ 2 ], &pulses0[ 3 ], psRangeDec, pulses1[ 1 ], silk_shell_code_table0); + decode_split( &pulses1[ 0 ], &pulses1[ 1 ], psRangeDec, pulses2[ 0 ], silk_shell_code_table1 ); + decode_split( &pulses0[ 0 ], &pulses0[ 1 ], psRangeDec, pulses1[ 0 ], silk_shell_code_table0 ); + decode_split( &pulses0[ 2 ], &pulses0[ 3 ], psRangeDec, pulses1[ 1 ], silk_shell_code_table0 ); - decode_split(&pulses1[ 2 ], &pulses1[ 3 ], psRangeDec, pulses2[ 1 ], silk_shell_code_table1); - decode_split(&pulses0[ 4 ], &pulses0[ 5 ], psRangeDec, pulses1[ 2 ], silk_shell_code_table0); - decode_split(&pulses0[ 6 ], &pulses0[ 7 ], psRangeDec, pulses1[ 3 ], silk_shell_code_table0); + decode_split( &pulses1[ 2 ], &pulses1[ 3 ], psRangeDec, pulses2[ 1 ], silk_shell_code_table1 ); + decode_split( &pulses0[ 4 ], &pulses0[ 5 ], psRangeDec, pulses1[ 2 ], silk_shell_code_table0 ); + decode_split( &pulses0[ 6 ], &pulses0[ 7 ], psRangeDec, pulses1[ 3 ], silk_shell_code_table0 ); - decode_split(&pulses2[ 2 ], &pulses2[ 3 ], psRangeDec, pulses3[ 1 ], silk_shell_code_table2); + decode_split( &pulses2[ 2 ], &pulses2[ 3 ], psRangeDec, pulses3[ 1 ], silk_shell_code_table2 ); - decode_split(&pulses1[ 4 ], &pulses1[ 5 ], psRangeDec, pulses2[ 2 ], silk_shell_code_table1); - decode_split(&pulses0[ 8 ], &pulses0[ 9 ], psRangeDec, pulses1[ 4 ], silk_shell_code_table0); - decode_split(&pulses0[ 10 ], &pulses0[ 11 ], psRangeDec, pulses1[ 5 ], silk_shell_code_table0); + decode_split( &pulses1[ 4 ], &pulses1[ 5 ], psRangeDec, pulses2[ 2 ], silk_shell_code_table1 ); + decode_split( &pulses0[ 8 ], &pulses0[ 9 ], psRangeDec, pulses1[ 4 ], silk_shell_code_table0 ); + decode_split( &pulses0[ 10 ], &pulses0[ 11 ], psRangeDec, pulses1[ 5 ], silk_shell_code_table0 ); - decode_split(&pulses1[ 6 ], &pulses1[ 7 ], psRangeDec, pulses2[ 3 ], silk_shell_code_table1); - decode_split(&pulses0[ 12 ], &pulses0[ 13 ], psRangeDec, pulses1[ 6 ], silk_shell_code_table0); - decode_split(&pulses0[ 14 ], &pulses0[ 15 ], psRangeDec, pulses1[ 7 ], silk_shell_code_table0); + decode_split( &pulses1[ 6 ], &pulses1[ 7 ], psRangeDec, pulses2[ 3 ], silk_shell_code_table1 ); + decode_split( &pulses0[ 12 ], &pulses0[ 13 ], psRangeDec, pulses1[ 6 ], silk_shell_code_table0 ); + decode_split( &pulses0[ 14 ], &pulses0[ 15 ], psRangeDec, pulses1[ 7 ], silk_shell_code_table0 ); } diff --git a/src/libopus/silk/sigm_Q15.c b/src/libopus/silk/sigm_Q15.c index 1e5ce31..75c872e 100644 --- a/src/libopus/silk/sigm_Q15.c +++ b/src/libopus/silk/sigm_Q15.c @@ -1,75 +1,75 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif -#include +#ifdef __STDC__ +#include "config.h" +#endif /* Approximate sigmoid function */ #include "SigProc_FIX.h" /* fprintf(1, '%d, ', round(1024 * ([1 ./ (1 + exp(-(1:5))), 1] - 1 ./ (1 + exp(-(0:5)))))); */ -static const opus_int32 sigm_LUT_slope_Q10[ 6 ] PROGMEM = { +static const opus_int32 sigm_LUT_slope_Q10[ 6 ] = { 237, 153, 73, 30, 12, 7 }; /* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp(-(0:5))))); */ -static const opus_int32 sigm_LUT_pos_Q15[ 6 ] PROGMEM = { +static const opus_int32 sigm_LUT_pos_Q15[ 6 ] = { 16384, 23955, 28861, 31213, 32178, 32548 }; /* fprintf(1, '%d, ', round(32767 * 1 ./ (1 + exp((0:5))))); */ -static const opus_int32 sigm_LUT_neg_Q15[ 6 ] PROGMEM = { +static const opus_int32 sigm_LUT_neg_Q15[ 6 ] = { 16384, 8812, 3906, 1554, 589, 219 }; opus_int silk_sigm_Q15( opus_int in_Q5 /* I */ -) { +) +{ opus_int ind; - if (in_Q5 < 0) { + if( in_Q5 < 0 ) { /* Negative input */ in_Q5 = -in_Q5; - if (in_Q5 >= 6 * 32) { + if( in_Q5 >= 6 * 32 ) { return 0; /* Clip */ } else { /* Linear interpolation of look up table */ - ind = silk_RSHIFT(in_Q5, 5); - return (sigm_LUT_neg_Q15[ ind ] - silk_SMULBB(sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F)); + ind = silk_RSHIFT( in_Q5, 5 ); + return( sigm_LUT_neg_Q15[ ind ] - silk_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) ); } } else { /* Positive input */ - if (in_Q5 >= 6 * 32) { + if( in_Q5 >= 6 * 32 ) { return 32767; /* clip */ } else { /* Linear interpolation of look up table */ - ind = silk_RSHIFT(in_Q5, 5); - return (sigm_LUT_pos_Q15[ ind ] + silk_SMULBB(sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F)); + ind = silk_RSHIFT( in_Q5, 5 ); + return( sigm_LUT_pos_Q15[ ind ] + silk_SMULBB( sigm_LUT_slope_Q10[ ind ], in_Q5 & 0x1F ) ); } } } diff --git a/src/libopus/silk/sort.c b/src/libopus/silk/sort.c index f478f84..776e088 100644 --- a/src/libopus/silk/sort.c +++ b/src/libopus/silk/sort.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif /* Insertion sort (fast for already almost sorted arrays): */ /* Best case: O(n) for an already sorted array */ @@ -42,24 +42,25 @@ void silk_insertion_sort_increasing( opus_int *idx, /* O Index vector for the sorted elements */ const opus_int L, /* I Vector length */ const opus_int K /* I Number of correctly sorted positions */ -) { +) +{ opus_int32 value; opus_int i, j; /* Safety checks */ - celt_assert(K > 0); - celt_assert(L > 0); - celt_assert(L >= K); + celt_assert( K > 0 ); + celt_assert( L > 0 ); + celt_assert( L >= K ); /* Write start indices in index vector */ - for (i = 0; i < K; i++) { + for( i = 0; i < K; i++ ) { idx[ i ] = i; } /* Sort vector elements by value, increasing order */ - for (i = 1; i < K; i++) { + for( i = 1; i < K; i++ ) { value = a[ i ]; - for (j = i - 1; (j >= 0) && (value < a[ j ]); j--) { + for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) { a[ j + 1 ] = a[ j ]; /* Shift value */ idx[ j + 1 ] = idx[ j ]; /* Shift index */ } @@ -69,10 +70,10 @@ void silk_insertion_sort_increasing( /* If less than L values are asked for, check the remaining values, */ /* but only spend CPU to ensure that the K first values are correct */ - for (i = K; i < L; i++) { + for( i = K; i < L; i++ ) { value = a[ i ]; - if (value < a[ K - 1 ]) { - for (j = K - 2; (j >= 0) && (value < a[ j ]); j--) { + if( value < a[ K - 1 ] ) { + for( j = K - 2; ( j >= 0 ) && ( value < a[ j ] ); j-- ) { a[ j + 1 ] = a[ j ]; /* Shift value */ idx[ j + 1 ] = idx[ j ]; /* Shift index */ } @@ -89,24 +90,25 @@ void silk_insertion_sort_decreasing_int16( opus_int *idx, /* O Index vector for the sorted elements */ const opus_int L, /* I Vector length */ const opus_int K /* I Number of correctly sorted positions */ -) { +) +{ opus_int i, j; opus_int value; /* Safety checks */ - celt_assert(K > 0); - celt_assert(L > 0); - celt_assert(L >= K); + celt_assert( K > 0 ); + celt_assert( L > 0 ); + celt_assert( L >= K ); /* Write start indices in index vector */ - for (i = 0; i < K; i++) { + for( i = 0; i < K; i++ ) { idx[ i ] = i; } /* Sort vector elements by value, decreasing order */ - for (i = 1; i < K; i++) { + for( i = 1; i < K; i++ ) { value = a[ i ]; - for (j = i - 1; (j >= 0) && (value > a[ j ]); j--) { + for( j = i - 1; ( j >= 0 ) && ( value > a[ j ] ); j-- ) { a[ j + 1 ] = a[ j ]; /* Shift value */ idx[ j + 1 ] = idx[ j ]; /* Shift index */ } @@ -116,10 +118,10 @@ void silk_insertion_sort_decreasing_int16( /* If less than L values are asked for, check the remaining values, */ /* but only spend CPU to ensure that the K first values are correct */ - for (i = K; i < L; i++) { + for( i = K; i < L; i++ ) { value = a[ i ]; - if (value > a[ K - 1 ]) { - for (j = K - 2; (j >= 0) && (value > a[ j ]); j--) { + if( value > a[ K - 1 ] ) { + for( j = K - 2; ( j >= 0 ) && ( value > a[ j ] ); j-- ) { a[ j + 1 ] = a[ j ]; /* Shift value */ idx[ j + 1 ] = idx[ j ]; /* Shift index */ } @@ -131,19 +133,20 @@ void silk_insertion_sort_decreasing_int16( #endif void silk_insertion_sort_increasing_all_values_int16( - opus_int16 *a, /* I/O Unsorted / Sorted vector */ - const opus_int L /* I Vector length */ -) { + opus_int16 *a, /* I/O Unsorted / Sorted vector */ + const opus_int L /* I Vector length */ +) +{ opus_int value; opus_int i, j; /* Safety checks */ - celt_assert(L > 0); + celt_assert( L > 0 ); /* Sort vector elements by value, increasing order */ - for (i = 1; i < L; i++) { + for( i = 1; i < L; i++ ) { value = a[ i ]; - for (j = i - 1; (j >= 0) && (value < a[ j ]); j--) { + for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) { a[ j + 1 ] = a[ j ]; /* Shift value */ } a[ j + 1 ] = value; /* Write value */ diff --git a/src/libopus/silk/stack_alloc.h b/src/libopus/silk/stack_alloc.h new file mode 100644 index 0000000..416720b --- /dev/null +++ b/src/libopus/silk/stack_alloc.h @@ -0,0 +1 @@ +#include "../celt/stack_alloc.h" diff --git a/src/libopus/silk/stereo_LR_to_MS.c b/src/libopus/silk/stereo_LR_to_MS.c index 45c4320..70501c2 100644 --- a/src/libopus/silk/stereo_LR_to_MS.c +++ b/src/libopus/silk/stereo_LR_to_MS.c @@ -1,36 +1,36 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" -#include "../celt/stack_alloc.h" +#include "stack_alloc.h" /* Convert Left/Right stereo signal to adaptive Mid/Side representation */ void silk_stereo_LR_to_MS( @@ -45,47 +45,48 @@ void silk_stereo_LR_to_MS( opus_int toMono, /* I Last frame before a stereo->mono transition */ opus_int fs_kHz, /* I Sample rate (kHz) */ opus_int frame_length /* I Number of samples */ -) { +) +{ opus_int n, is10msFrame, denom_Q16, delta0_Q13, delta1_Q13; opus_int32 sum, diff, smooth_coef_Q16, pred_Q13[ 2 ], pred0_Q13, pred1_Q13; opus_int32 LP_ratio_Q14, HP_ratio_Q14, frac_Q16, frac_3_Q16, min_mid_rate_bps, width_Q14, w_Q24, deltaw_Q24; - VARDECL(opus_int16, side); - VARDECL(opus_int16, LP_mid); - VARDECL(opus_int16, HP_mid); - VARDECL(opus_int16, LP_side); - VARDECL(opus_int16, HP_side); + VARDECL( opus_int16, side ); + VARDECL( opus_int16, LP_mid ); + VARDECL( opus_int16, HP_mid ); + VARDECL( opus_int16, LP_side ); + VARDECL( opus_int16, HP_side ); opus_int16 *mid = &x1[ -2 ]; SAVE_STACK; - ALLOC(side, frame_length + 2, opus_int16); + ALLOC( side, frame_length + 2, opus_int16 ); /* Convert to basic mid/side signals */ - for (n = 0; n < frame_length + 2; n++) { + for( n = 0; n < frame_length + 2; n++ ) { sum = x1[ n - 2 ] + (opus_int32)x2[ n - 2 ]; diff = x1[ n - 2 ] - (opus_int32)x2[ n - 2 ]; - mid[ n ] = (opus_int16)silk_RSHIFT_ROUND(sum, 1); - side[ n ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(diff, 1)); + mid[ n ] = (opus_int16)silk_RSHIFT_ROUND( sum, 1 ); + side[ n ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( diff, 1 ) ); } /* Buffering */ - silk_memcpy(mid, state->sMid, 2 * sizeof(opus_int16)); - silk_memcpy(side, state->sSide, 2 * sizeof(opus_int16)); - silk_memcpy(state->sMid, &mid[ frame_length ], 2 * sizeof(opus_int16)); - silk_memcpy(state->sSide, &side[ frame_length ], 2 * sizeof(opus_int16)); + silk_memcpy( mid, state->sMid, 2 * sizeof( opus_int16 ) ); + silk_memcpy( side, state->sSide, 2 * sizeof( opus_int16 ) ); + silk_memcpy( state->sMid, &mid[ frame_length ], 2 * sizeof( opus_int16 ) ); + silk_memcpy( state->sSide, &side[ frame_length ], 2 * sizeof( opus_int16 ) ); /* LP and HP filter mid signal */ - ALLOC(LP_mid, frame_length, opus_int16); - ALLOC(HP_mid, frame_length, opus_int16); - for (n = 0; n < frame_length; n++) { - sum = silk_RSHIFT_ROUND(silk_ADD_LSHIFT(mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1), 2); + ALLOC( LP_mid, frame_length, opus_int16 ); + ALLOC( HP_mid, frame_length, opus_int16 ); + for( n = 0; n < frame_length; n++ ) { + sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT32( mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1 ), 2 ); LP_mid[ n ] = sum; HP_mid[ n ] = mid[ n + 1 ] - sum; } /* LP and HP filter side signal */ - ALLOC(LP_side, frame_length, opus_int16); - ALLOC(HP_side, frame_length, opus_int16); - for (n = 0; n < frame_length; n++) { - sum = silk_RSHIFT_ROUND(silk_ADD_LSHIFT(side[ n ] + (opus_int32)side[ n + 2 ], side[ n + 1 ], 1), 2); + ALLOC( LP_side, frame_length, opus_int16 ); + ALLOC( HP_side, frame_length, opus_int16 ); + for( n = 0; n < frame_length; n++ ) { + sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT32( side[ n ] + (opus_int32)side[ n + 2 ], side[ n + 1 ], 1 ), 2 ); LP_side[ n ] = sum; HP_side[ n ] = side[ n + 1 ] - sum; } @@ -93,57 +94,58 @@ void silk_stereo_LR_to_MS( /* Find energies and predictors */ is10msFrame = frame_length == 10 * fs_kHz; smooth_coef_Q16 = is10msFrame ? - SILK_FIX_CONST(STEREO_RATIO_SMOOTH_COEF / 2, 16) : - SILK_FIX_CONST(STEREO_RATIO_SMOOTH_COEF, 16); - smooth_coef_Q16 = silk_SMULWB(silk_SMULBB(prev_speech_act_Q8, prev_speech_act_Q8), smooth_coef_Q16); + SILK_FIX_CONST( STEREO_RATIO_SMOOTH_COEF / 2, 16 ) : + SILK_FIX_CONST( STEREO_RATIO_SMOOTH_COEF, 16 ); + smooth_coef_Q16 = silk_SMULWB( silk_SMULBB( prev_speech_act_Q8, prev_speech_act_Q8 ), smooth_coef_Q16 ); - pred_Q13[ 0 ] = silk_stereo_find_predictor(&LP_ratio_Q14, LP_mid, LP_side, &state->mid_side_amp_Q0[ 0 ], frame_length, smooth_coef_Q16); - pred_Q13[ 1 ] = silk_stereo_find_predictor(&HP_ratio_Q14, HP_mid, HP_side, &state->mid_side_amp_Q0[ 2 ], frame_length, smooth_coef_Q16); + pred_Q13[ 0 ] = silk_stereo_find_predictor( &LP_ratio_Q14, LP_mid, LP_side, &state->mid_side_amp_Q0[ 0 ], frame_length, smooth_coef_Q16 ); + pred_Q13[ 1 ] = silk_stereo_find_predictor( &HP_ratio_Q14, HP_mid, HP_side, &state->mid_side_amp_Q0[ 2 ], frame_length, smooth_coef_Q16 ); /* Ratio of the norms of residual and mid signals */ - frac_Q16 = silk_SMLABB(HP_ratio_Q14, LP_ratio_Q14, 3); - frac_Q16 = silk_min(frac_Q16, SILK_FIX_CONST(1, 16)); + frac_Q16 = silk_SMLABB( HP_ratio_Q14, LP_ratio_Q14, 3 ); + frac_Q16 = silk_min( frac_Q16, SILK_FIX_CONST( 1, 16 ) ); /* Determine bitrate distribution between mid and side, and possibly reduce stereo width */ total_rate_bps -= is10msFrame ? 1200 : 600; /* Subtract approximate bitrate for coding stereo parameters */ - if (total_rate_bps < 1) { + if( total_rate_bps < 1 ) { total_rate_bps = 1; } - min_mid_rate_bps = silk_SMLABB(2000, fs_kHz, 600); - silk_assert(min_mid_rate_bps < 32767); + min_mid_rate_bps = silk_SMLABB( 2000, fs_kHz, 600 ); + silk_assert( min_mid_rate_bps < 32767 ); /* Default bitrate distribution: 8 parts for Mid and (5+3*frac) parts for Side. so: mid_rate = ( 8 / ( 13 + 3 * frac ) ) * total_ rate */ - frac_3_Q16 = silk_MUL(3, frac_Q16); - mid_side_rates_bps[ 0 ] = silk_DIV32_varQ(total_rate_bps, SILK_FIX_CONST(8 + 5, 16) + frac_3_Q16, 16 + 3); + frac_3_Q16 = silk_MUL( 3, frac_Q16 ); + mid_side_rates_bps[ 0 ] = silk_DIV32_varQ( total_rate_bps, SILK_FIX_CONST( 8 + 5, 16 ) + frac_3_Q16, 16+3 ); /* If Mid bitrate below minimum, reduce stereo width */ - if (mid_side_rates_bps[ 0 ] < min_mid_rate_bps) { + if( mid_side_rates_bps[ 0 ] < min_mid_rate_bps ) { mid_side_rates_bps[ 0 ] = min_mid_rate_bps; mid_side_rates_bps[ 1 ] = total_rate_bps - mid_side_rates_bps[ 0 ]; /* width = 4 * ( 2 * side_rate - min_rate ) / ( ( 1 + 3 * frac ) * min_rate ) */ - width_Q14 = silk_DIV32_varQ(silk_LSHIFT(mid_side_rates_bps[ 1 ], 1) - min_mid_rate_bps, - silk_SMULWB(SILK_FIX_CONST(1, 16) + frac_3_Q16, min_mid_rate_bps), 14 + 2); - width_Q14 = silk_LIMIT(width_Q14, 0, SILK_FIX_CONST(1, 14)); + width_Q14 = silk_DIV32_varQ( silk_LSHIFT( mid_side_rates_bps[ 1 ], 1 ) - min_mid_rate_bps, + silk_SMULWB( SILK_FIX_CONST( 1, 16 ) + frac_3_Q16, min_mid_rate_bps ), 14+2 ); + width_Q14 = silk_LIMIT( width_Q14, 0, SILK_FIX_CONST( 1, 14 ) ); } else { mid_side_rates_bps[ 1 ] = total_rate_bps - mid_side_rates_bps[ 0 ]; - width_Q14 = SILK_FIX_CONST(1, 14); + width_Q14 = SILK_FIX_CONST( 1, 14 ); } /* Smoother */ - state->smth_width_Q14 = (opus_int16)silk_SMLAWB(state->smth_width_Q14, width_Q14 - state->smth_width_Q14, smooth_coef_Q16); + state->smth_width_Q14 = (opus_int16)silk_SMLAWB( state->smth_width_Q14, width_Q14 - state->smth_width_Q14, smooth_coef_Q16 ); /* At very low bitrates or for inputs that are nearly amplitude panned, switch to panned-mono coding */ *mid_only_flag = 0; - if (toMono) { + if( toMono ) { /* Last frame before stereo->mono transition; collapse stereo width */ width_Q14 = 0; pred_Q13[ 0 ] = 0; pred_Q13[ 1 ] = 0; - silk_stereo_quant_pred(pred_Q13, ix); - } else if (state->width_prev_Q14 == 0 && - (8 * total_rate_bps < 13 * min_mid_rate_bps || silk_SMULWB(frac_Q16, state->smth_width_Q14) < SILK_FIX_CONST(0.05, 14))) { + silk_stereo_quant_pred( pred_Q13, ix ); + } else if( state->width_prev_Q14 == 0 && + ( 8 * total_rate_bps < 13 * min_mid_rate_bps || silk_SMULWB( frac_Q16, state->smth_width_Q14 ) < SILK_FIX_CONST( 0.05, 14 ) ) ) + { /* Code as panned-mono; previous frame already had zero width */ /* Scale down and quantize predictors */ - pred_Q13[ 0 ] = silk_RSHIFT(silk_SMULBB(state->smth_width_Q14, pred_Q13[ 0 ]), 14); - pred_Q13[ 1 ] = silk_RSHIFT(silk_SMULBB(state->smth_width_Q14, pred_Q13[ 1 ]), 14); - silk_stereo_quant_pred(pred_Q13, ix); + pred_Q13[ 0 ] = silk_RSHIFT( silk_SMULBB( state->smth_width_Q14, pred_Q13[ 0 ] ), 14 ); + pred_Q13[ 1 ] = silk_RSHIFT( silk_SMULBB( state->smth_width_Q14, pred_Q13[ 1 ] ), 14 ); + silk_stereo_quant_pred( pred_Q13, ix ); /* Collapse stereo width */ width_Q14 = 0; pred_Q13[ 0 ] = 0; @@ -151,33 +153,34 @@ void silk_stereo_LR_to_MS( mid_side_rates_bps[ 0 ] = total_rate_bps; mid_side_rates_bps[ 1 ] = 0; *mid_only_flag = 1; - } else if (state->width_prev_Q14 != 0 && - (8 * total_rate_bps < 11 * min_mid_rate_bps || silk_SMULWB(frac_Q16, state->smth_width_Q14) < SILK_FIX_CONST(0.02, 14))) { + } else if( state->width_prev_Q14 != 0 && + ( 8 * total_rate_bps < 11 * min_mid_rate_bps || silk_SMULWB( frac_Q16, state->smth_width_Q14 ) < SILK_FIX_CONST( 0.02, 14 ) ) ) + { /* Transition to zero-width stereo */ /* Scale down and quantize predictors */ - pred_Q13[ 0 ] = silk_RSHIFT(silk_SMULBB(state->smth_width_Q14, pred_Q13[ 0 ]), 14); - pred_Q13[ 1 ] = silk_RSHIFT(silk_SMULBB(state->smth_width_Q14, pred_Q13[ 1 ]), 14); - silk_stereo_quant_pred(pred_Q13, ix); + pred_Q13[ 0 ] = silk_RSHIFT( silk_SMULBB( state->smth_width_Q14, pred_Q13[ 0 ] ), 14 ); + pred_Q13[ 1 ] = silk_RSHIFT( silk_SMULBB( state->smth_width_Q14, pred_Q13[ 1 ] ), 14 ); + silk_stereo_quant_pred( pred_Q13, ix ); /* Collapse stereo width */ width_Q14 = 0; pred_Q13[ 0 ] = 0; pred_Q13[ 1 ] = 0; - } else if (state->smth_width_Q14 > SILK_FIX_CONST(0.95, 14)) { + } else if( state->smth_width_Q14 > SILK_FIX_CONST( 0.95, 14 ) ) { /* Full-width stereo coding */ - silk_stereo_quant_pred(pred_Q13, ix); - width_Q14 = SILK_FIX_CONST(1, 14); + silk_stereo_quant_pred( pred_Q13, ix ); + width_Q14 = SILK_FIX_CONST( 1, 14 ); } else { /* Reduced-width stereo coding; scale down and quantize predictors */ - pred_Q13[ 0 ] = silk_RSHIFT(silk_SMULBB(state->smth_width_Q14, pred_Q13[ 0 ]), 14); - pred_Q13[ 1 ] = silk_RSHIFT(silk_SMULBB(state->smth_width_Q14, pred_Q13[ 1 ]), 14); - silk_stereo_quant_pred(pred_Q13, ix); + pred_Q13[ 0 ] = silk_RSHIFT( silk_SMULBB( state->smth_width_Q14, pred_Q13[ 0 ] ), 14 ); + pred_Q13[ 1 ] = silk_RSHIFT( silk_SMULBB( state->smth_width_Q14, pred_Q13[ 1 ] ), 14 ); + silk_stereo_quant_pred( pred_Q13, ix ); width_Q14 = state->smth_width_Q14; } /* Make sure to keep on encoding until the tapered output has been transmitted */ - if (*mid_only_flag == 1) { + if( *mid_only_flag == 1 ) { state->silent_side_len += frame_length - STEREO_INTERP_LEN_MS * fs_kHz; - if (state->silent_side_len < LA_SHAPE_MS * fs_kHz) { + if( state->silent_side_len < LA_SHAPE_MS * fs_kHz ) { *mid_only_flag = 0; } else { /* Limit to avoid wrapping around */ @@ -187,37 +190,37 @@ void silk_stereo_LR_to_MS( state->silent_side_len = 0; } - if (*mid_only_flag == 0 && mid_side_rates_bps[ 1 ] < 1) { + if( *mid_only_flag == 0 && mid_side_rates_bps[ 1 ] < 1 ) { mid_side_rates_bps[ 1 ] = 1; - mid_side_rates_bps[ 0 ] = silk_max_int(1, total_rate_bps - mid_side_rates_bps[ 1 ]); + mid_side_rates_bps[ 0 ] = silk_max_int( 1, total_rate_bps - mid_side_rates_bps[ 1 ]); } /* Interpolate predictors and subtract prediction from side channel */ pred0_Q13 = -state->pred_prev_Q13[ 0 ]; pred1_Q13 = -state->pred_prev_Q13[ 1 ]; - w_Q24 = silk_LSHIFT(state->width_prev_Q14, 10); - denom_Q16 = silk_DIV32_16((opus_int32)1 << 16, STEREO_INTERP_LEN_MS * fs_kHz); - delta0_Q13 = -silk_RSHIFT_ROUND(silk_SMULBB(pred_Q13[ 0 ] - state->pred_prev_Q13[ 0 ], denom_Q16), 16); - delta1_Q13 = -silk_RSHIFT_ROUND(silk_SMULBB(pred_Q13[ 1 ] - state->pred_prev_Q13[ 1 ], denom_Q16), 16); - deltaw_Q24 = silk_LSHIFT(silk_SMULWB(width_Q14 - state->width_prev_Q14, denom_Q16), 10); - for (n = 0; n < STEREO_INTERP_LEN_MS * fs_kHz; n++) { + w_Q24 = silk_LSHIFT( state->width_prev_Q14, 10 ); + denom_Q16 = silk_DIV32_16( (opus_int32)1 << 16, STEREO_INTERP_LEN_MS * fs_kHz ); + delta0_Q13 = -silk_RSHIFT_ROUND( silk_SMULBB( pred_Q13[ 0 ] - state->pred_prev_Q13[ 0 ], denom_Q16 ), 16 ); + delta1_Q13 = -silk_RSHIFT_ROUND( silk_SMULBB( pred_Q13[ 1 ] - state->pred_prev_Q13[ 1 ], denom_Q16 ), 16 ); + deltaw_Q24 = silk_LSHIFT( silk_SMULWB( width_Q14 - state->width_prev_Q14, denom_Q16 ), 10 ); + for( n = 0; n < STEREO_INTERP_LEN_MS * fs_kHz; n++ ) { pred0_Q13 += delta0_Q13; pred1_Q13 += delta1_Q13; w_Q24 += deltaw_Q24; - sum = silk_LSHIFT(silk_ADD_LSHIFT(mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1), 9); /* Q11 */ - sum = silk_SMLAWB(silk_SMULWB(w_Q24, side[ n + 1 ]), sum, pred0_Q13); /* Q8 */ - sum = silk_SMLAWB(sum, silk_LSHIFT((opus_int32)mid[ n + 1 ], 11), pred1_Q13); /* Q8 */ - x2[ n - 1 ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(sum, 8)); + sum = silk_LSHIFT( silk_ADD_LSHIFT32( mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1 ), 9 ); /* Q11 */ + sum = silk_SMLAWB( silk_SMULWB( w_Q24, side[ n + 1 ] ), sum, pred0_Q13 ); /* Q8 */ + sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)mid[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */ + x2[ n - 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) ); } pred0_Q13 = -pred_Q13[ 0 ]; pred1_Q13 = -pred_Q13[ 1 ]; - w_Q24 = silk_LSHIFT(width_Q14, 10); - for (n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++) { - sum = silk_LSHIFT(silk_ADD_LSHIFT(mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1), 9); /* Q11 */ - sum = silk_SMLAWB(silk_SMULWB(w_Q24, side[ n + 1 ]), sum, pred0_Q13); /* Q8 */ - sum = silk_SMLAWB(sum, silk_LSHIFT((opus_int32)mid[ n + 1 ], 11), pred1_Q13); /* Q8 */ - x2[ n - 1 ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(sum, 8)); + w_Q24 = silk_LSHIFT( width_Q14, 10 ); + for( n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++ ) { + sum = silk_LSHIFT( silk_ADD_LSHIFT32( mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1 ), 9 ); /* Q11 */ + sum = silk_SMLAWB( silk_SMULWB( w_Q24, side[ n + 1 ] ), sum, pred0_Q13 ); /* Q8 */ + sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)mid[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */ + x2[ n - 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) ); } state->pred_prev_Q13[ 0 ] = (opus_int16)pred_Q13[ 0 ]; state->pred_prev_Q13[ 1 ] = (opus_int16)pred_Q13[ 1 ]; diff --git a/src/libopus/silk/stereo_MS_to_LR.c b/src/libopus/silk/stereo_MS_to_LR.c index 20159d8..26342fb 100644 --- a/src/libopus/silk/stereo_MS_to_LR.c +++ b/src/libopus/silk/stereo_MS_to_LR.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -39,46 +39,47 @@ void silk_stereo_MS_to_LR( const opus_int32 pred_Q13[], /* I Predictors */ opus_int fs_kHz, /* I Samples rate (kHz) */ opus_int frame_length /* I Number of samples */ -) { +) +{ opus_int n, denom_Q16, delta0_Q13, delta1_Q13; opus_int32 sum, diff, pred0_Q13, pred1_Q13; /* Buffering */ - silk_memcpy(x1, state->sMid, 2 * sizeof(opus_int16)); - silk_memcpy(x2, state->sSide, 2 * sizeof(opus_int16)); - silk_memcpy(state->sMid, &x1[ frame_length ], 2 * sizeof(opus_int16)); - silk_memcpy(state->sSide, &x2[ frame_length ], 2 * sizeof(opus_int16)); + silk_memcpy( x1, state->sMid, 2 * sizeof( opus_int16 ) ); + silk_memcpy( x2, state->sSide, 2 * sizeof( opus_int16 ) ); + silk_memcpy( state->sMid, &x1[ frame_length ], 2 * sizeof( opus_int16 ) ); + silk_memcpy( state->sSide, &x2[ frame_length ], 2 * sizeof( opus_int16 ) ); /* Interpolate predictors and add prediction to side channel */ pred0_Q13 = state->pred_prev_Q13[ 0 ]; pred1_Q13 = state->pred_prev_Q13[ 1 ]; - denom_Q16 = silk_DIV32_16((opus_int32)1 << 16, STEREO_INTERP_LEN_MS * fs_kHz); - delta0_Q13 = silk_RSHIFT_ROUND(silk_SMULBB(pred_Q13[ 0 ] - state->pred_prev_Q13[ 0 ], denom_Q16), 16); - delta1_Q13 = silk_RSHIFT_ROUND(silk_SMULBB(pred_Q13[ 1 ] - state->pred_prev_Q13[ 1 ], denom_Q16), 16); - for (n = 0; n < STEREO_INTERP_LEN_MS * fs_kHz; n++) { + denom_Q16 = silk_DIV32_16( (opus_int32)1 << 16, STEREO_INTERP_LEN_MS * fs_kHz ); + delta0_Q13 = silk_RSHIFT_ROUND( silk_SMULBB( pred_Q13[ 0 ] - state->pred_prev_Q13[ 0 ], denom_Q16 ), 16 ); + delta1_Q13 = silk_RSHIFT_ROUND( silk_SMULBB( pred_Q13[ 1 ] - state->pred_prev_Q13[ 1 ], denom_Q16 ), 16 ); + for( n = 0; n < STEREO_INTERP_LEN_MS * fs_kHz; n++ ) { pred0_Q13 += delta0_Q13; pred1_Q13 += delta1_Q13; - sum = silk_LSHIFT(silk_ADD_LSHIFT(x1[ n ] + x1[ n + 2 ], x1[ n + 1 ], 1), 9); /* Q11 */ - sum = silk_SMLAWB(silk_LSHIFT((opus_int32)x2[ n + 1 ], 8), sum, pred0_Q13); /* Q8 */ - sum = silk_SMLAWB(sum, silk_LSHIFT((opus_int32)x1[ n + 1 ], 11), pred1_Q13); /* Q8 */ - x2[ n + 1 ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(sum, 8)); + sum = silk_LSHIFT( silk_ADD_LSHIFT32( x1[ n ] + (opus_int32)x1[ n + 2 ], x1[ n + 1 ], 1 ), 9 ); /* Q11 */ + sum = silk_SMLAWB( silk_LSHIFT( (opus_int32)x2[ n + 1 ], 8 ), sum, pred0_Q13 ); /* Q8 */ + sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)x1[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */ + x2[ n + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) ); } pred0_Q13 = pred_Q13[ 0 ]; pred1_Q13 = pred_Q13[ 1 ]; - for (n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++) { - sum = silk_LSHIFT(silk_ADD_LSHIFT(x1[ n ] + x1[ n + 2 ], x1[ n + 1 ], 1), 9); /* Q11 */ - sum = silk_SMLAWB(silk_LSHIFT((opus_int32)x2[ n + 1 ], 8), sum, pred0_Q13); /* Q8 */ - sum = silk_SMLAWB(sum, silk_LSHIFT((opus_int32)x1[ n + 1 ], 11), pred1_Q13); /* Q8 */ - x2[ n + 1 ] = (opus_int16)silk_SAT16(silk_RSHIFT_ROUND(sum, 8)); + for( n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++ ) { + sum = silk_LSHIFT( silk_ADD_LSHIFT32( x1[ n ] + (opus_int32)x1[ n + 2 ], x1[ n + 1 ], 1 ), 9 ); /* Q11 */ + sum = silk_SMLAWB( silk_LSHIFT( (opus_int32)x2[ n + 1 ], 8 ), sum, pred0_Q13 ); /* Q8 */ + sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)x1[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */ + x2[ n + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) ); } state->pred_prev_Q13[ 0 ] = pred_Q13[ 0 ]; state->pred_prev_Q13[ 1 ] = pred_Q13[ 1 ]; /* Convert to left/right signals */ - for (n = 0; n < frame_length; n++) { + for( n = 0; n < frame_length; n++ ) { sum = x1[ n + 1 ] + (opus_int32)x2[ n + 1 ]; diff = x1[ n + 1 ] - (opus_int32)x2[ n + 1 ]; - x1[ n + 1 ] = (opus_int16)silk_SAT16(sum); - x2[ n + 1 ] = (opus_int16)silk_SAT16(diff); + x1[ n + 1 ] = (opus_int16)silk_SAT16( sum ); + x2[ n + 1 ] = (opus_int16)silk_SAT16( diff ); } } diff --git a/src/libopus/silk/stereo_decode_pred.c b/src/libopus/silk/stereo_decode_pred.c index e56c180..b6075f9 100644 --- a/src/libopus/silk/stereo_decode_pred.c +++ b/src/libopus/silk/stereo_decode_pred.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -35,26 +35,27 @@ void silk_stereo_decode_pred( ec_dec *psRangeDec, /* I/O Compressor data structure */ opus_int32 pred_Q13[] /* O Predictors */ -) { +) +{ opus_int n, ix[ 2 ][ 3 ]; opus_int32 low_Q13, step_Q13; /* Entropy decoding */ - n = ec_dec_icdf(psRangeDec, silk_stereo_pred_joint_iCDF, 8); - ix[ 0 ][ 2 ] = silk_DIV32_16(n, 5); + n = ec_dec_icdf( psRangeDec, silk_stereo_pred_joint_iCDF, 8 ); + ix[ 0 ][ 2 ] = silk_DIV32_16( n, 5 ); ix[ 1 ][ 2 ] = n - 5 * ix[ 0 ][ 2 ]; - for (n = 0; n < 2; n++) { - ix[ n ][ 0 ] = ec_dec_icdf(psRangeDec, silk_uniform3_iCDF, 8); - ix[ n ][ 1 ] = ec_dec_icdf(psRangeDec, silk_uniform5_iCDF, 8); + for( n = 0; n < 2; n++ ) { + ix[ n ][ 0 ] = ec_dec_icdf( psRangeDec, silk_uniform3_iCDF, 8 ); + ix[ n ][ 1 ] = ec_dec_icdf( psRangeDec, silk_uniform5_iCDF, 8 ); } /* Dequantize */ - for (n = 0; n < 2; n++) { + for( n = 0; n < 2; n++ ) { ix[ n ][ 0 ] += 3 * ix[ n ][ 2 ]; low_Q13 = silk_stereo_pred_quant_Q13[ ix[ n ][ 0 ] ]; - step_Q13 = silk_SMULWB(silk_stereo_pred_quant_Q13[ ix[ n ][ 0 ] + 1 ] - low_Q13, - SILK_FIX_CONST(0.5 / STEREO_QUANT_SUB_STEPS, 16)); - pred_Q13[ n ] = silk_SMLABB(low_Q13, step_Q13, 2 * ix[ n ][ 1 ] + 1); + step_Q13 = silk_SMULWB( silk_stereo_pred_quant_Q13[ ix[ n ][ 0 ] + 1 ] - low_Q13, + SILK_FIX_CONST( 0.5 / STEREO_QUANT_SUB_STEPS, 16 ) ); + pred_Q13[ n ] = silk_SMLABB( low_Q13, step_Q13, 2 * ix[ n ][ 1 ] + 1 ); } /* Subtract second from first predictor (helps when actually applying these) */ @@ -65,7 +66,8 @@ void silk_stereo_decode_pred( void silk_stereo_decode_mid_only( ec_dec *psRangeDec, /* I/O Compressor data structure */ opus_int *decode_only_mid /* O Flag that only mid channel has been coded */ -) { +) +{ /* Decode flag that only mid channel is coded */ - *decode_only_mid = ec_dec_icdf(psRangeDec, silk_stereo_only_code_mid_iCDF, 8); + *decode_only_mid = ec_dec_icdf( psRangeDec, silk_stereo_only_code_mid_iCDF, 8 ); } diff --git a/src/libopus/silk/stereo_encode_pred.c b/src/libopus/silk/stereo_encode_pred.c index fa806d5..ef1edcd 100644 --- a/src/libopus/silk/stereo_encode_pred.c +++ b/src/libopus/silk/stereo_encode_pred.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -35,18 +35,19 @@ void silk_stereo_encode_pred( ec_enc *psRangeEnc, /* I/O Compressor data structure */ opus_int8 ix[ 2 ][ 3 ] /* I Quantization indices */ -) { +) +{ opus_int n; /* Entropy coding */ n = 5 * ix[ 0 ][ 2 ] + ix[ 1 ][ 2 ]; - celt_assert(n < 25); - ec_enc_icdf(psRangeEnc, n, silk_stereo_pred_joint_iCDF, 8); - for (n = 0; n < 2; n++) { - celt_assert(ix[ n ][ 0 ] < 3); - celt_assert(ix[ n ][ 1 ] < STEREO_QUANT_SUB_STEPS); - ec_enc_icdf(psRangeEnc, ix[ n ][ 0 ], silk_uniform3_iCDF, 8); - ec_enc_icdf(psRangeEnc, ix[ n ][ 1 ], silk_uniform5_iCDF, 8); + celt_assert( n < 25 ); + ec_enc_icdf( psRangeEnc, n, silk_stereo_pred_joint_iCDF, 8 ); + for( n = 0; n < 2; n++ ) { + celt_assert( ix[ n ][ 0 ] < 3 ); + celt_assert( ix[ n ][ 1 ] < STEREO_QUANT_SUB_STEPS ); + ec_enc_icdf( psRangeEnc, ix[ n ][ 0 ], silk_uniform3_iCDF, 8 ); + ec_enc_icdf( psRangeEnc, ix[ n ][ 1 ], silk_uniform5_iCDF, 8 ); } } @@ -54,7 +55,8 @@ void silk_stereo_encode_pred( void silk_stereo_encode_mid_only( ec_enc *psRangeEnc, /* I/O Compressor data structure */ opus_int8 mid_only_flag -) { +) +{ /* Encode flag that only mid channel is coded */ - ec_enc_icdf(psRangeEnc, mid_only_flag, silk_stereo_only_code_mid_iCDF, 8); + ec_enc_icdf( psRangeEnc, mid_only_flag, silk_stereo_only_code_mid_iCDF, 8 ); } diff --git a/src/libopus/silk/stereo_find_predictor.c b/src/libopus/silk/stereo_find_predictor.c index f8a7d86..96cd3e5 100644 --- a/src/libopus/silk/stereo_find_predictor.c +++ b/src/libopus/silk/stereo_find_predictor.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -39,40 +39,41 @@ opus_int32 silk_stereo_find_predictor( /* O Returns opus_int32 mid_res_amp_Q0[], /* I/O Smoothed mid, residual norms */ opus_int length, /* I Number of samples */ opus_int smooth_coef_Q16 /* I Smoothing coefficient */ -) { +) +{ opus_int scale, scale1, scale2; opus_int32 nrgx, nrgy, corr, pred_Q13, pred2_Q10; /* Find predictor */ - silk_sum_sqr_shift(&nrgx, &scale1, x, length); - silk_sum_sqr_shift(&nrgy, &scale2, y, length); - scale = silk_max_int(scale1, scale2); - scale = scale + (scale & 1); /* make even */ - nrgy = silk_RSHIFT32(nrgy, scale - scale2); - nrgx = silk_RSHIFT32(nrgx, scale - scale1); - nrgx = silk_max_int(nrgx, 1); - corr = silk_inner_prod_aligned_scale(x, y, scale, length); - pred_Q13 = silk_DIV32_varQ(corr, nrgx, 13); - pred_Q13 = silk_LIMIT(pred_Q13, -(1 << 14), 1 << 14); - pred2_Q10 = silk_SMULWB(pred_Q13, pred_Q13); + silk_sum_sqr_shift( &nrgx, &scale1, x, length ); + silk_sum_sqr_shift( &nrgy, &scale2, y, length ); + scale = silk_max_int( scale1, scale2 ); + scale = scale + ( scale & 1 ); /* make even */ + nrgy = silk_RSHIFT32( nrgy, scale - scale2 ); + nrgx = silk_RSHIFT32( nrgx, scale - scale1 ); + nrgx = silk_max_int( nrgx, 1 ); + corr = silk_inner_prod_aligned_scale( x, y, scale, length ); + pred_Q13 = silk_DIV32_varQ( corr, nrgx, 13 ); + pred_Q13 = silk_LIMIT( pred_Q13, -(1 << 14), 1 << 14 ); + pred2_Q10 = silk_SMULWB( pred_Q13, pred_Q13 ); /* Faster update for signals with large prediction parameters */ - smooth_coef_Q16 = (opus_int)silk_max_int(smooth_coef_Q16, silk_abs(pred2_Q10)); + smooth_coef_Q16 = (opus_int)silk_max_int( smooth_coef_Q16, silk_abs( pred2_Q10 ) ); /* Smoothed mid and residual norms */ - silk_assert(smooth_coef_Q16 < 32768); - scale = silk_RSHIFT(scale, 1); - mid_res_amp_Q0[ 0 ] = silk_SMLAWB(mid_res_amp_Q0[ 0 ], silk_LSHIFT(silk_SQRT_APPROX(nrgx), scale) - mid_res_amp_Q0[ 0 ], - smooth_coef_Q16); + silk_assert( smooth_coef_Q16 < 32768 ); + scale = silk_RSHIFT( scale, 1 ); + mid_res_amp_Q0[ 0 ] = silk_SMLAWB( mid_res_amp_Q0[ 0 ], silk_LSHIFT( silk_SQRT_APPROX( nrgx ), scale ) - mid_res_amp_Q0[ 0 ], + smooth_coef_Q16 ); /* Residual energy = nrgy - 2 * pred * corr + pred^2 * nrgx */ - nrgy = silk_SUB_LSHIFT32(nrgy, silk_SMULWB(corr, pred_Q13), 3 + 1); - nrgy = silk_ADD_LSHIFT32(nrgy, silk_SMULWB(nrgx, pred2_Q10), 6); - mid_res_amp_Q0[ 1 ] = silk_SMLAWB(mid_res_amp_Q0[ 1 ], silk_LSHIFT(silk_SQRT_APPROX(nrgy), scale) - mid_res_amp_Q0[ 1 ], - smooth_coef_Q16); + nrgy = silk_SUB_LSHIFT32( nrgy, silk_SMULWB( corr, pred_Q13 ), 3 + 1 ); + nrgy = silk_ADD_LSHIFT32( nrgy, silk_SMULWB( nrgx, pred2_Q10 ), 6 ); + mid_res_amp_Q0[ 1 ] = silk_SMLAWB( mid_res_amp_Q0[ 1 ], silk_LSHIFT( silk_SQRT_APPROX( nrgy ), scale ) - mid_res_amp_Q0[ 1 ], + smooth_coef_Q16 ); /* Ratio of smoothed residual and mid norms */ - *ratio_Q14 = silk_DIV32_varQ(mid_res_amp_Q0[ 1 ], silk_max(mid_res_amp_Q0[ 0 ], 1), 14); - *ratio_Q14 = silk_LIMIT(*ratio_Q14, 0, 32767); + *ratio_Q14 = silk_DIV32_varQ( mid_res_amp_Q0[ 1 ], silk_max( mid_res_amp_Q0[ 0 ], 1 ), 14 ); + *ratio_Q14 = silk_LIMIT( *ratio_Q14, 0, 32767 ); return pred_Q13; } diff --git a/src/libopus/silk/stereo_quant_pred.c b/src/libopus/silk/stereo_quant_pred.c index 7a68815..5f349da 100644 --- a/src/libopus/silk/stereo_quant_pred.c +++ b/src/libopus/silk/stereo_quant_pred.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "main.h" @@ -35,22 +35,23 @@ void silk_stereo_quant_pred( opus_int32 pred_Q13[], /* I/O Predictors (out: quantized) */ opus_int8 ix[ 2 ][ 3 ] /* O Quantization indices */ -) { +) +{ opus_int i, j, n; opus_int32 low_Q13, step_Q13, lvl_Q13, err_min_Q13, err_Q13, quant_pred_Q13 = 0; /* Quantize */ - for (n = 0; n < 2; n++) { + for( n = 0; n < 2; n++ ) { /* Brute-force search over quantization levels */ err_min_Q13 = silk_int32_MAX; - for (i = 0; i < STEREO_QUANT_TAB_SIZE - 1; i++) { + for( i = 0; i < STEREO_QUANT_TAB_SIZE - 1; i++ ) { low_Q13 = silk_stereo_pred_quant_Q13[ i ]; - step_Q13 = silk_SMULWB(silk_stereo_pred_quant_Q13[ i + 1 ] - low_Q13, - SILK_FIX_CONST(0.5 / STEREO_QUANT_SUB_STEPS, 16)); - for (j = 0; j < STEREO_QUANT_SUB_STEPS; j++) { - lvl_Q13 = silk_SMLABB(low_Q13, step_Q13, 2 * j + 1); - err_Q13 = silk_abs(pred_Q13[ n ] - lvl_Q13); - if (err_Q13 < err_min_Q13) { + step_Q13 = silk_SMULWB( silk_stereo_pred_quant_Q13[ i + 1 ] - low_Q13, + SILK_FIX_CONST( 0.5 / STEREO_QUANT_SUB_STEPS, 16 ) ); + for( j = 0; j < STEREO_QUANT_SUB_STEPS; j++ ) { + lvl_Q13 = silk_SMLABB( low_Q13, step_Q13, 2 * j + 1 ); + err_Q13 = silk_abs( pred_Q13[ n ] - lvl_Q13 ); + if( err_Q13 < err_min_Q13 ) { err_min_Q13 = err_Q13; quant_pred_Q13 = lvl_Q13; ix[ n ][ 0 ] = i; @@ -61,8 +62,8 @@ void silk_stereo_quant_pred( } } } -done: - ix[ n ][ 2 ] = silk_DIV32_16(ix[ n ][ 0 ], 3); + done: + ix[ n ][ 2 ] = silk_DIV32_16( ix[ n ][ 0 ], 3 ); ix[ n ][ 0 ] -= ix[ n ][ 2 ] * 3; pred_Q13[ n ] = quant_pred_Q13; } diff --git a/src/libopus/silk/structs.h b/src/libopus/silk/structs.h index 6bb7e67..38243be 100644 --- a/src/libopus/silk/structs.h +++ b/src/libopus/silk/structs.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_STRUCTS_H @@ -31,8 +31,23 @@ #include "typedef.h" #include "SigProc_FIX.h" #include "define.h" -#include "../celt/entenc.h" -#include "../celt/entdec.h" +#include "entenc.h" +#include "entdec.h" + +#ifdef ENABLE_DEEP_PLC +#include "lpcnet.h" +#include "lpcnet_private.h" +#endif + +#ifdef ENABLE_DRED +#include "dred_encoder.h" +#include "dred_decoder.h" +#endif + +#ifdef ENABLE_OSCE +#include "osce_config.h" +#include "osce_structs.h" +#endif #ifdef __cplusplus extern "C" @@ -228,6 +243,14 @@ typedef struct { } silk_encoder_state; +#ifdef ENABLE_OSCE +typedef struct { + OSCEFeatureState features; + OSCEState state; + int method; +} silk_OSCE_struct; +#endif + /* Struct for Packet Loss Concealment */ typedef struct { opus_int32 pitchL_Q8; /* Pitch lag to use for voiced concealment */ @@ -243,6 +266,7 @@ typedef struct { opus_int fs_kHz; opus_int nb_subfr; opus_int subfr_length; + opus_int enable_deep_plc; } silk_PLC_struct; /* Struct for CNG */ @@ -259,6 +283,10 @@ typedef struct { /* Decoder state */ /********************************/ typedef struct { +#ifdef ENABLE_OSCE + silk_OSCE_struct osce; +#endif +#define SILK_DECODER_STATE_RESET_START prev_gain_Q16 opus_int32 prev_gain_Q16; opus_int32 exc_Q14[ MAX_FRAME_LENGTH ]; opus_int32 sLPC_Q14_buf[ MAX_LPC_ORDER ]; diff --git a/src/libopus/silk/structs_FIX.h b/src/libopus/silk/structs_FIX.h new file mode 100644 index 0000000..e46bd47 --- /dev/null +++ b/src/libopus/silk/structs_FIX.h @@ -0,0 +1 @@ +#include "fixed/structs_FIX.h" diff --git a/src/libopus/silk/sum_sqr_shift.c b/src/libopus/silk/sum_sqr_shift.c index 3fc85b3..5b33507 100644 --- a/src/libopus/silk/sum_sqr_shift.c +++ b/src/libopus/silk/sum_sqr_shift.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "SigProc_FIX.h" @@ -38,42 +38,43 @@ void silk_sum_sqr_shift( opus_int *shift, /* O Number of bits right shift applied to energy */ const opus_int16 *x, /* I Input vector */ opus_int len /* I Length of input vector */ -) { +) +{ opus_int i, shft; opus_uint32 nrg_tmp; opus_int32 nrg; /* Do a first run with the maximum shift we could have. */ - shft = 31 - silk_CLZ32(len); + shft = 31-silk_CLZ32(len); /* Let's be conservative with rounding and start with nrg=len. */ nrg = len; - for (i = 0; i < len - 1; i += 2) { - nrg_tmp = silk_SMULBB(x[ i ], x[ i ]); - nrg_tmp = silk_SMLABB_ovflw(nrg_tmp, x[ i + 1 ], x[ i + 1 ]); - nrg = (opus_int32)silk_ADD_RSHIFT_uint(nrg, nrg_tmp, shft); + for( i = 0; i < len - 1; i += 2 ) { + nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); + nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] ); + nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); } - if (i < len) { + if( i < len ) { /* One sample left to process */ - nrg_tmp = silk_SMULBB(x[ i ], x[ i ]); - nrg = (opus_int32)silk_ADD_RSHIFT_uint(nrg, nrg_tmp, shft); + nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); + nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); } - silk_assert(nrg >= 0); - /* Make sure the result will fit in a 32-bit signed integer with two bits - of headroom. */ - shft = silk_max_32(0, shft + 3 - silk_CLZ32(nrg)); + silk_assert( nrg >= 0 ); + /* Make sure the result will fit in a 32-bit signed integer with two bits + of headroom. */ + shft = silk_max_32(0, shft+3 - silk_CLZ32(nrg)); nrg = 0; - for (i = 0 ; i < len - 1; i += 2) { - nrg_tmp = silk_SMULBB(x[ i ], x[ i ]); - nrg_tmp = silk_SMLABB_ovflw(nrg_tmp, x[ i + 1 ], x[ i + 1 ]); - nrg = (opus_int32)silk_ADD_RSHIFT_uint(nrg, nrg_tmp, shft); + for( i = 0 ; i < len - 1; i += 2 ) { + nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); + nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] ); + nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); } - if (i < len) { + if( i < len ) { /* One sample left to process */ - nrg_tmp = silk_SMULBB(x[ i ], x[ i ]); - nrg = (opus_int32)silk_ADD_RSHIFT_uint(nrg, nrg_tmp, shft); + nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); + nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); } - silk_assert(nrg >= 0); + silk_assert( nrg >= 0 ); /* Output arguments */ *shift = shft; diff --git a/src/libopus/silk/table_LSF_cos.c b/src/libopus/silk/table_LSF_cos.c index 9af6069..6608f5d 100644 --- a/src/libopus/silk/table_LSF_cos.c +++ b/src/libopus/silk/table_LSF_cos.c @@ -1,70 +1,70 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "tables.h" /* Cosine approximation table for LSF conversion */ /* Q12 values (even) */ const opus_int16 silk_LSFCosTab_FIX_Q12[ LSF_COS_TAB_SZ_FIX + 1 ] = { - 8192, 8190, 8182, 8170, - 8152, 8130, 8104, 8072, - 8034, 7994, 7946, 7896, - 7840, 7778, 7714, 7644, - 7568, 7490, 7406, 7318, - 7226, 7128, 7026, 6922, - 6812, 6698, 6580, 6458, - 6332, 6204, 6070, 5934, - 5792, 5648, 5502, 5352, - 5198, 5040, 4880, 4718, - 4552, 4382, 4212, 4038, - 3862, 3684, 3502, 3320, - 3136, 2948, 2760, 2570, - 2378, 2186, 1990, 1794, - 1598, 1400, 1202, 1002, - 802, 602, 402, 202, - 0, -202, -402, -602, - -802, -1002, -1202, -1400, - -1598, -1794, -1990, -2186, - -2378, -2570, -2760, -2948, - -3136, -3320, -3502, -3684, - -3862, -4038, -4212, -4382, - -4552, -4718, -4880, -5040, - -5198, -5352, -5502, -5648, - -5792, -5934, -6070, -6204, - -6332, -6458, -6580, -6698, - -6812, -6922, -7026, -7128, - -7226, -7318, -7406, -7490, - -7568, -7644, -7714, -7778, - -7840, -7896, -7946, -7994, - -8034, -8072, -8104, -8130, - -8152, -8170, -8182, -8190, - -8192 + 8192, 8190, 8182, 8170, + 8152, 8130, 8104, 8072, + 8034, 7994, 7946, 7896, + 7840, 7778, 7714, 7644, + 7568, 7490, 7406, 7318, + 7226, 7128, 7026, 6922, + 6812, 6698, 6580, 6458, + 6332, 6204, 6070, 5934, + 5792, 5648, 5502, 5352, + 5198, 5040, 4880, 4718, + 4552, 4382, 4212, 4038, + 3862, 3684, 3502, 3320, + 3136, 2948, 2760, 2570, + 2378, 2186, 1990, 1794, + 1598, 1400, 1202, 1002, + 802, 602, 402, 202, + 0, -202, -402, -602, + -802, -1002, -1202, -1400, + -1598, -1794, -1990, -2186, + -2378, -2570, -2760, -2948, + -3136, -3320, -3502, -3684, + -3862, -4038, -4212, -4382, + -4552, -4718, -4880, -5040, + -5198, -5352, -5502, -5648, + -5792, -5934, -6070, -6204, + -6332, -6458, -6580, -6698, + -6812, -6922, -7026, -7128, + -7226, -7318, -7406, -7490, + -7568, -7644, -7714, -7778, + -7840, -7896, -7946, -7994, + -8034, -8072, -8104, -8130, + -8152, -8170, -8182, -8190, + -8192 }; diff --git a/src/libopus/silk/tables.h b/src/libopus/silk/tables.h index 39ba9d9..95230c4 100644 --- a/src/libopus/silk/tables.h +++ b/src/libopus/silk/tables.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_TABLES_H @@ -40,7 +40,7 @@ extern "C" extern const opus_uint8 silk_gain_iCDF[ 3 ][ N_LEVELS_QGAIN / 8 ]; /* 24 */ extern const opus_uint8 silk_delta_gain_iCDF[ MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ]; /* 41 */ -extern const opus_uint8 silk_pitch_lag_iCDF[ 2 * (PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS) ]; /* 32 */ +extern const opus_uint8 silk_pitch_lag_iCDF[ 2 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) ];/* 32 */ extern const opus_uint8 silk_pitch_delta_iCDF[ 21 ]; /* 21 */ extern const opus_uint8 silk_pitch_contour_iCDF[ 34 ]; /* 34 */ extern const opus_uint8 silk_pitch_contour_NB_iCDF[ 11 ]; /* 11 */ diff --git a/src/libopus/silk/tables_LTP.c b/src/libopus/silk/tables_LTP.c index 1b51b98..e79edd9 100644 --- a/src/libopus/silk/tables_LTP.c +++ b/src/libopus/silk/tables_LTP.c @@ -1,70 +1,70 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "tables.h" const opus_uint8 silk_LTP_per_index_iCDF[3] = { - 179, 99, 0 + 179, 99, 0 }; static const opus_uint8 silk_LTP_gain_iCDF_0[8] = { - 71, 56, 43, 30, 21, 12, 6, 0 + 71, 56, 43, 30, 21, 12, 6, 0 }; static const opus_uint8 silk_LTP_gain_iCDF_1[16] = { - 199, 165, 144, 124, 109, 96, 84, 71, - 61, 51, 42, 32, 23, 15, 8, 0 + 199, 165, 144, 124, 109, 96, 84, 71, + 61, 51, 42, 32, 23, 15, 8, 0 }; static const opus_uint8 silk_LTP_gain_iCDF_2[32] = { - 241, 225, 211, 199, 187, 175, 164, 153, - 142, 132, 123, 114, 105, 96, 88, 80, - 72, 64, 57, 50, 44, 38, 33, 29, - 24, 20, 16, 12, 9, 5, 2, 0 + 241, 225, 211, 199, 187, 175, 164, 153, + 142, 132, 123, 114, 105, 96, 88, 80, + 72, 64, 57, 50, 44, 38, 33, 29, + 24, 20, 16, 12, 9, 5, 2, 0 }; static const opus_uint8 silk_LTP_gain_BITS_Q5_0[8] = { - 15, 131, 138, 138, 155, 155, 173, 173 + 15, 131, 138, 138, 155, 155, 173, 173 }; static const opus_uint8 silk_LTP_gain_BITS_Q5_1[16] = { - 69, 93, 115, 118, 131, 138, 141, 138, - 150, 150, 155, 150, 155, 160, 166, 160 + 69, 93, 115, 118, 131, 138, 141, 138, + 150, 150, 155, 150, 155, 160, 166, 160 }; static const opus_uint8 silk_LTP_gain_BITS_Q5_2[32] = { - 131, 128, 134, 141, 141, 141, 145, 145, - 145, 150, 155, 155, 155, 155, 160, 160, - 160, 160, 166, 166, 173, 173, 182, 192, - 182, 192, 192, 192, 205, 192, 205, 224 + 131, 128, 134, 141, 141, 141, 145, 145, + 145, 150, 155, 155, 155, 155, 160, 160, + 160, 160, 166, 166, 173, 173, 182, 192, + 182, 192, 192, 192, 205, 192, 205, 224 }; const opus_uint8 * const silk_LTP_gain_iCDF_ptrs[NB_LTP_CBKS] = { @@ -79,181 +79,184 @@ const opus_uint8 * const silk_LTP_gain_BITS_Q5_ptrs[NB_LTP_CBKS] = { silk_LTP_gain_BITS_Q5_2 }; -static const opus_int8 silk_LTP_gain_vq_0[8][5] = { - { - 4, 6, 24, 7, 5 - }, - { - 0, 0, 2, 0, 0 - }, - { +static const opus_int8 silk_LTP_gain_vq_0[8][5] = +{ +{ + 4, 6, 24, 7, 5 +}, +{ + 0, 0, 2, 0, 0 +}, +{ 12, 28, 41, 13, -4 - }, - { +}, +{ -9, 15, 42, 25, 14 - }, - { - 1, -2, 62, 41, -9 - }, - { - -10, 37, 65, -4, 3 - }, - { +}, +{ + 1, -2, 62, 41, -9 +}, +{ + -10, 37, 65, -4, 3 +}, +{ -6, 4, 66, 7, -8 - }, - { +}, +{ 16, 14, 38, -3, 33 - } +} }; -static const opus_int8 silk_LTP_gain_vq_1[16][5] = { - { +static const opus_int8 silk_LTP_gain_vq_1[16][5] = +{ +{ 13, 22, 39, 23, 12 - }, - { +}, +{ -1, 36, 64, 27, -6 - }, - { +}, +{ -7, 10, 55, 43, 17 - }, - { - 1, 1, 8, 1, 1 - }, - { - 6, -11, 74, 53, -9 - }, - { - -12, 55, 76, -12, 8 - }, - { +}, +{ + 1, 1, 8, 1, 1 +}, +{ + 6, -11, 74, 53, -9 +}, +{ + -12, 55, 76, -12, 8 +}, +{ -3, 3, 93, 27, -4 - }, - { +}, +{ 26, 39, 59, 3, -8 - }, - { - 2, 0, 77, 11, 9 - }, - { +}, +{ + 2, 0, 77, 11, 9 +}, +{ -8, 22, 44, -6, 7 - }, - { +}, +{ 40, 9, 26, 3, 9 - }, - { +}, +{ -7, 20, 101, -7, 4 - }, - { - 3, -8, 42, 26, 0 - }, - { - -15, 33, 68, 2, 23 - }, - { +}, +{ + 3, -8, 42, 26, 0 +}, +{ + -15, 33, 68, 2, 23 +}, +{ -2, 55, 46, -2, 15 - }, - { - 3, -1, 21, 16, 41 - } +}, +{ + 3, -1, 21, 16, 41 +} }; -static const opus_int8 silk_LTP_gain_vq_2[32][5] = { - { +static const opus_int8 silk_LTP_gain_vq_2[32][5] = +{ +{ -6, 27, 61, 39, 5 - }, - { - -11, 42, 88, 4, 1 - }, - { +}, +{ + -11, 42, 88, 4, 1 +}, +{ -2, 60, 65, 6, -4 - }, - { +}, +{ -1, -5, 73, 56, 1 - }, - { +}, +{ -9, 19, 94, 29, -9 - }, - { - 0, 12, 99, 6, 4 - }, - { - 8, -19, 102, 46, -13 - }, - { - 3, 2, 13, 3, 2 - }, - { - 9, -21, 84, 72, -18 - }, - { - -11, 46, 104, -22, 8 - }, - { +}, +{ + 0, 12, 99, 6, 4 +}, +{ + 8, -19, 102, 46, -13 +}, +{ + 3, 2, 13, 3, 2 +}, +{ + 9, -21, 84, 72, -18 +}, +{ + -11, 46, 104, -22, 8 +}, +{ 18, 38, 48, 23, 0 - }, - { - -16, 70, 83, -21, 11 - }, - { - 5, -11, 117, 22, -8 - }, - { +}, +{ + -16, 70, 83, -21, 11 +}, +{ + 5, -11, 117, 22, -8 +}, +{ -6, 23, 117, -12, 3 - }, - { - 3, -8, 95, 28, 4 - }, - { - -10, 15, 77, 60, -15 - }, - { +}, +{ + 3, -8, 95, 28, 4 +}, +{ + -10, 15, 77, 60, -15 +}, +{ -1, 4, 124, 2, -4 - }, - { - 3, 38, 84, 24, -25 - }, - { - 2, 13, 42, 13, 31 - }, - { +}, +{ + 3, 38, 84, 24, -25 +}, +{ + 2, 13, 42, 13, 31 +}, +{ 21, -4, 56, 46, -1 - }, - { +}, +{ -1, 35, 79, -13, 19 - }, - { +}, +{ -7, 65, 88, -9, -14 - }, - { +}, +{ 20, 4, 81, 49, -29 - }, - { +}, +{ 20, 0, 75, 3, -17 - }, - { - 5, -9, 44, 92, -8 - }, - { - 1, -3, 22, 69, 31 - }, - { +}, +{ + 5, -9, 44, 92, -8 +}, +{ + 1, -3, 22, 69, 31 +}, +{ -6, 95, 41, -12, 5 - }, - { +}, +{ 39, 67, 16, -4, 1 - }, - { - 0, -6, 120, 55, -36 - }, - { - -13, 44, 122, 4, -24 - }, - { +}, +{ + 0, -6, 120, 55, -36 +}, +{ + -13, 44, 122, 4, -24 +}, +{ 81, 5, 11, 3, 7 - }, - { - 2, 0, 9, 10, 88 - } +}, +{ + 2, 0, 9, 10, 88 +} }; const opus_int8 * const silk_LTP_vq_ptrs_Q7[NB_LTP_CBKS] = { @@ -262,22 +265,22 @@ const opus_int8 * const silk_LTP_vq_ptrs_Q7[NB_LTP_CBKS] = { (opus_int8 *)&silk_LTP_gain_vq_2[0][0] }; -/* Maximum frequency-dependent response of the pitch taps above, - computed as max(abs(freqz(taps))) */ +/* Maximum frequency-dependent response of the pitch taps above, + computed as max(abs(freqz(taps))) */ static const opus_uint8 silk_LTP_gain_vq_0_gain[8] = { - 46, 2, 90, 87, 93, 91, 82, 98 + 46, 2, 90, 87, 93, 91, 82, 98 }; static const opus_uint8 silk_LTP_gain_vq_1_gain[16] = { - 109, 120, 118, 12, 113, 115, 117, 119, - 99, 59, 87, 111, 63, 111, 112, 80 + 109, 120, 118, 12, 113, 115, 117, 119, + 99, 59, 87, 111, 63, 111, 112, 80 }; static const opus_uint8 silk_LTP_gain_vq_2_gain[32] = { - 126, 124, 125, 124, 129, 121, 126, 23, - 132, 127, 127, 127, 126, 127, 122, 133, - 130, 134, 101, 118, 119, 145, 126, 86, - 124, 120, 123, 119, 170, 173, 107, 109 + 126, 124, 125, 124, 129, 121, 126, 23, + 132, 127, 127, 127, 126, 127, 122, 133, + 130, 134, 101, 118, 119, 145, 126, 86, + 124, 120, 123, 119, 170, 173, 107, 109 }; const opus_uint8 * const silk_LTP_vq_gain_ptrs_Q7[NB_LTP_CBKS] = { diff --git a/src/libopus/silk/tables_NLSF_CB_NB_MB.c b/src/libopus/silk/tables_NLSF_CB_NB_MB.c index dc65459..4ef4e12 100644 --- a/src/libopus/silk/tables_NLSF_CB_NB_MB.c +++ b/src/libopus/silk/tables_NLSF_CB_NB_MB.c @@ -1,188 +1,189 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "tables.h" static const opus_uint8 silk_NLSF_CB1_NB_MB_Q8[ 320 ] = { - 12, 35, 60, 83, 108, 132, 157, 180, - 206, 228, 15, 32, 55, 77, 101, 125, - 151, 175, 201, 225, 19, 42, 66, 89, - 114, 137, 162, 184, 209, 230, 12, 25, - 50, 72, 97, 120, 147, 172, 200, 223, - 26, 44, 69, 90, 114, 135, 159, 180, - 205, 225, 13, 22, 53, 80, 106, 130, - 156, 180, 205, 228, 15, 25, 44, 64, - 90, 115, 142, 168, 196, 222, 19, 24, - 62, 82, 100, 120, 145, 168, 190, 214, - 22, 31, 50, 79, 103, 120, 151, 170, - 203, 227, 21, 29, 45, 65, 106, 124, - 150, 171, 196, 224, 30, 49, 75, 97, - 121, 142, 165, 186, 209, 229, 19, 25, - 52, 70, 93, 116, 143, 166, 192, 219, - 26, 34, 62, 75, 97, 118, 145, 167, - 194, 217, 25, 33, 56, 70, 91, 113, - 143, 165, 196, 223, 21, 34, 51, 72, - 97, 117, 145, 171, 196, 222, 20, 29, - 50, 67, 90, 117, 144, 168, 197, 221, - 22, 31, 48, 66, 95, 117, 146, 168, - 196, 222, 24, 33, 51, 77, 116, 134, - 158, 180, 200, 224, 21, 28, 70, 87, - 106, 124, 149, 170, 194, 217, 26, 33, - 53, 64, 83, 117, 152, 173, 204, 225, - 27, 34, 65, 95, 108, 129, 155, 174, - 210, 225, 20, 26, 72, 99, 113, 131, - 154, 176, 200, 219, 34, 43, 61, 78, - 93, 114, 155, 177, 205, 229, 23, 29, - 54, 97, 124, 138, 163, 179, 209, 229, - 30, 38, 56, 89, 118, 129, 158, 178, - 200, 231, 21, 29, 49, 63, 85, 111, - 142, 163, 193, 222, 27, 48, 77, 103, - 133, 158, 179, 196, 215, 232, 29, 47, - 74, 99, 124, 151, 176, 198, 220, 237, - 33, 42, 61, 76, 93, 121, 155, 174, - 207, 225, 29, 53, 87, 112, 136, 154, - 170, 188, 208, 227, 24, 30, 52, 84, - 131, 150, 166, 186, 203, 229, 37, 48, - 64, 84, 104, 118, 156, 177, 201, 230 + 12, 35, 60, 83, 108, 132, 157, 180, + 206, 228, 15, 32, 55, 77, 101, 125, + 151, 175, 201, 225, 19, 42, 66, 89, + 114, 137, 162, 184, 209, 230, 12, 25, + 50, 72, 97, 120, 147, 172, 200, 223, + 26, 44, 69, 90, 114, 135, 159, 180, + 205, 225, 13, 22, 53, 80, 106, 130, + 156, 180, 205, 228, 15, 25, 44, 64, + 90, 115, 142, 168, 196, 222, 19, 24, + 62, 82, 100, 120, 145, 168, 190, 214, + 22, 31, 50, 79, 103, 120, 151, 170, + 203, 227, 21, 29, 45, 65, 106, 124, + 150, 171, 196, 224, 30, 49, 75, 97, + 121, 142, 165, 186, 209, 229, 19, 25, + 52, 70, 93, 116, 143, 166, 192, 219, + 26, 34, 62, 75, 97, 118, 145, 167, + 194, 217, 25, 33, 56, 70, 91, 113, + 143, 165, 196, 223, 21, 34, 51, 72, + 97, 117, 145, 171, 196, 222, 20, 29, + 50, 67, 90, 117, 144, 168, 197, 221, + 22, 31, 48, 66, 95, 117, 146, 168, + 196, 222, 24, 33, 51, 77, 116, 134, + 158, 180, 200, 224, 21, 28, 70, 87, + 106, 124, 149, 170, 194, 217, 26, 33, + 53, 64, 83, 117, 152, 173, 204, 225, + 27, 34, 65, 95, 108, 129, 155, 174, + 210, 225, 20, 26, 72, 99, 113, 131, + 154, 176, 200, 219, 34, 43, 61, 78, + 93, 114, 155, 177, 205, 229, 23, 29, + 54, 97, 124, 138, 163, 179, 209, 229, + 30, 38, 56, 89, 118, 129, 158, 178, + 200, 231, 21, 29, 49, 63, 85, 111, + 142, 163, 193, 222, 27, 48, 77, 103, + 133, 158, 179, 196, 215, 232, 29, 47, + 74, 99, 124, 151, 176, 198, 220, 237, + 33, 42, 61, 76, 93, 121, 155, 174, + 207, 225, 29, 53, 87, 112, 136, 154, + 170, 188, 208, 227, 24, 30, 52, 84, + 131, 150, 166, 186, 203, 229, 37, 48, + 64, 84, 104, 118, 156, 177, 201, 230 }; static const opus_int16 silk_NLSF_CB1_Wght_Q9[ 320 ] = { - 2897, 2314, 2314, 2314, 2287, 2287, 2314, 2300, 2327, 2287, - 2888, 2580, 2394, 2367, 2314, 2274, 2274, 2274, 2274, 2194, - 2487, 2340, 2340, 2314, 2314, 2314, 2340, 2340, 2367, 2354, - 3216, 2766, 2340, 2340, 2314, 2274, 2221, 2207, 2261, 2194, - 2460, 2474, 2367, 2394, 2394, 2394, 2394, 2367, 2407, 2314, - 3479, 3056, 2127, 2207, 2274, 2274, 2274, 2287, 2314, 2261, - 3282, 3141, 2580, 2394, 2247, 2221, 2207, 2194, 2194, 2114, - 4096, 3845, 2221, 2620, 2620, 2407, 2314, 2394, 2367, 2074, - 3178, 3244, 2367, 2221, 2553, 2434, 2340, 2314, 2167, 2221, - 3338, 3488, 2726, 2194, 2261, 2460, 2354, 2367, 2207, 2101, - 2354, 2420, 2327, 2367, 2394, 2420, 2420, 2420, 2460, 2367, - 3779, 3629, 2434, 2527, 2367, 2274, 2274, 2300, 2207, 2048, - 3254, 3225, 2713, 2846, 2447, 2327, 2300, 2300, 2274, 2127, - 3263, 3300, 2753, 2806, 2447, 2261, 2261, 2247, 2127, 2101, - 2873, 2981, 2633, 2367, 2407, 2354, 2194, 2247, 2247, 2114, - 3225, 3197, 2633, 2580, 2274, 2181, 2247, 2221, 2221, 2141, - 3178, 3310, 2740, 2407, 2274, 2274, 2274, 2287, 2194, 2114, - 3141, 3272, 2460, 2061, 2287, 2500, 2367, 2487, 2434, 2181, - 3507, 3282, 2314, 2700, 2647, 2474, 2367, 2394, 2340, 2127, - 3423, 3535, 3038, 3056, 2300, 1950, 2221, 2274, 2274, 2274, - 3404, 3366, 2087, 2687, 2873, 2354, 2420, 2274, 2474, 2540, - 3760, 3488, 1950, 2660, 2897, 2527, 2394, 2367, 2460, 2261, - 3028, 3272, 2740, 2888, 2740, 2154, 2127, 2287, 2234, 2247, - 3695, 3657, 2025, 1969, 2660, 2700, 2580, 2500, 2327, 2367, - 3207, 3413, 2354, 2074, 2888, 2888, 2340, 2487, 2247, 2167, - 3338, 3366, 2846, 2780, 2327, 2154, 2274, 2287, 2114, 2061, - 2327, 2300, 2181, 2167, 2181, 2367, 2633, 2700, 2700, 2553, - 2407, 2434, 2221, 2261, 2221, 2221, 2340, 2420, 2607, 2700, - 3038, 3244, 2806, 2888, 2474, 2074, 2300, 2314, 2354, 2380, - 2221, 2154, 2127, 2287, 2500, 2793, 2793, 2620, 2580, 2367, - 3676, 3713, 2234, 1838, 2181, 2753, 2726, 2673, 2513, 2207, - 2793, 3160, 2726, 2553, 2846, 2513, 2181, 2394, 2221, 2181 + 2897, 2314, 2314, 2314, 2287, 2287, 2314, 2300, 2327, 2287, + 2888, 2580, 2394, 2367, 2314, 2274, 2274, 2274, 2274, 2194, + 2487, 2340, 2340, 2314, 2314, 2314, 2340, 2340, 2367, 2354, + 3216, 2766, 2340, 2340, 2314, 2274, 2221, 2207, 2261, 2194, + 2460, 2474, 2367, 2394, 2394, 2394, 2394, 2367, 2407, 2314, + 3479, 3056, 2127, 2207, 2274, 2274, 2274, 2287, 2314, 2261, + 3282, 3141, 2580, 2394, 2247, 2221, 2207, 2194, 2194, 2114, + 4096, 3845, 2221, 2620, 2620, 2407, 2314, 2394, 2367, 2074, + 3178, 3244, 2367, 2221, 2553, 2434, 2340, 2314, 2167, 2221, + 3338, 3488, 2726, 2194, 2261, 2460, 2354, 2367, 2207, 2101, + 2354, 2420, 2327, 2367, 2394, 2420, 2420, 2420, 2460, 2367, + 3779, 3629, 2434, 2527, 2367, 2274, 2274, 2300, 2207, 2048, + 3254, 3225, 2713, 2846, 2447, 2327, 2300, 2300, 2274, 2127, + 3263, 3300, 2753, 2806, 2447, 2261, 2261, 2247, 2127, 2101, + 2873, 2981, 2633, 2367, 2407, 2354, 2194, 2247, 2247, 2114, + 3225, 3197, 2633, 2580, 2274, 2181, 2247, 2221, 2221, 2141, + 3178, 3310, 2740, 2407, 2274, 2274, 2274, 2287, 2194, 2114, + 3141, 3272, 2460, 2061, 2287, 2500, 2367, 2487, 2434, 2181, + 3507, 3282, 2314, 2700, 2647, 2474, 2367, 2394, 2340, 2127, + 3423, 3535, 3038, 3056, 2300, 1950, 2221, 2274, 2274, 2274, + 3404, 3366, 2087, 2687, 2873, 2354, 2420, 2274, 2474, 2540, + 3760, 3488, 1950, 2660, 2897, 2527, 2394, 2367, 2460, 2261, + 3028, 3272, 2740, 2888, 2740, 2154, 2127, 2287, 2234, 2247, + 3695, 3657, 2025, 1969, 2660, 2700, 2580, 2500, 2327, 2367, + 3207, 3413, 2354, 2074, 2888, 2888, 2340, 2487, 2247, 2167, + 3338, 3366, 2846, 2780, 2327, 2154, 2274, 2287, 2114, 2061, + 2327, 2300, 2181, 2167, 2181, 2367, 2633, 2700, 2700, 2553, + 2407, 2434, 2221, 2261, 2221, 2221, 2340, 2420, 2607, 2700, + 3038, 3244, 2806, 2888, 2474, 2074, 2300, 2314, 2354, 2380, + 2221, 2154, 2127, 2287, 2500, 2793, 2793, 2620, 2580, 2367, + 3676, 3713, 2234, 1838, 2181, 2753, 2726, 2673, 2513, 2207, + 2793, 3160, 2726, 2553, 2846, 2513, 2181, 2394, 2221, 2181 }; static const opus_uint8 silk_NLSF_CB1_iCDF_NB_MB[ 64 ] = { - 212, 178, 148, 129, 108, 96, 85, 82, - 79, 77, 61, 59, 57, 56, 51, 49, - 48, 45, 42, 41, 40, 38, 36, 34, - 31, 30, 21, 12, 10, 3, 1, 0, - 255, 245, 244, 236, 233, 225, 217, 203, - 190, 176, 175, 161, 149, 136, 125, 114, - 102, 91, 81, 71, 60, 52, 43, 35, - 28, 20, 19, 18, 12, 11, 5, 0 + 212, 178, 148, 129, 108, 96, 85, 82, + 79, 77, 61, 59, 57, 56, 51, 49, + 48, 45, 42, 41, 40, 38, 36, 34, + 31, 30, 21, 12, 10, 3, 1, 0, + 255, 245, 244, 236, 233, 225, 217, 203, + 190, 176, 175, 161, 149, 136, 125, 114, + 102, 91, 81, 71, 60, 52, 43, 35, + 28, 20, 19, 18, 12, 11, 5, 0 }; static const opus_uint8 silk_NLSF_CB2_SELECT_NB_MB[ 160 ] = { - 16, 0, 0, 0, 0, 99, 66, 36, - 36, 34, 36, 34, 34, 34, 34, 83, - 69, 36, 52, 34, 116, 102, 70, 68, - 68, 176, 102, 68, 68, 34, 65, 85, - 68, 84, 36, 116, 141, 152, 139, 170, - 132, 187, 184, 216, 137, 132, 249, 168, - 185, 139, 104, 102, 100, 68, 68, 178, - 218, 185, 185, 170, 244, 216, 187, 187, - 170, 244, 187, 187, 219, 138, 103, 155, - 184, 185, 137, 116, 183, 155, 152, 136, - 132, 217, 184, 184, 170, 164, 217, 171, - 155, 139, 244, 169, 184, 185, 170, 164, - 216, 223, 218, 138, 214, 143, 188, 218, - 168, 244, 141, 136, 155, 170, 168, 138, - 220, 219, 139, 164, 219, 202, 216, 137, - 168, 186, 246, 185, 139, 116, 185, 219, - 185, 138, 100, 100, 134, 100, 102, 34, - 68, 68, 100, 68, 168, 203, 221, 218, - 168, 167, 154, 136, 104, 70, 164, 246, - 171, 137, 139, 137, 155, 218, 219, 139 + 16, 0, 0, 0, 0, 99, 66, 36, + 36, 34, 36, 34, 34, 34, 34, 83, + 69, 36, 52, 34, 116, 102, 70, 68, + 68, 176, 102, 68, 68, 34, 65, 85, + 68, 84, 36, 116, 141, 152, 139, 170, + 132, 187, 184, 216, 137, 132, 249, 168, + 185, 139, 104, 102, 100, 68, 68, 178, + 218, 185, 185, 170, 244, 216, 187, 187, + 170, 244, 187, 187, 219, 138, 103, 155, + 184, 185, 137, 116, 183, 155, 152, 136, + 132, 217, 184, 184, 170, 164, 217, 171, + 155, 139, 244, 169, 184, 185, 170, 164, + 216, 223, 218, 138, 214, 143, 188, 218, + 168, 244, 141, 136, 155, 170, 168, 138, + 220, 219, 139, 164, 219, 202, 216, 137, + 168, 186, 246, 185, 139, 116, 185, 219, + 185, 138, 100, 100, 134, 100, 102, 34, + 68, 68, 100, 68, 168, 203, 221, 218, + 168, 167, 154, 136, 104, 70, 164, 246, + 171, 137, 139, 137, 155, 218, 219, 139 }; static const opus_uint8 silk_NLSF_CB2_iCDF_NB_MB[ 72 ] = { - 255, 254, 253, 238, 14, 3, 2, 1, - 0, 255, 254, 252, 218, 35, 3, 2, - 1, 0, 255, 254, 250, 208, 59, 4, - 2, 1, 0, 255, 254, 246, 194, 71, - 10, 2, 1, 0, 255, 252, 236, 183, - 82, 8, 2, 1, 0, 255, 252, 235, - 180, 90, 17, 2, 1, 0, 255, 248, - 224, 171, 97, 30, 4, 1, 0, 255, - 254, 236, 173, 95, 37, 7, 1, 0 + 255, 254, 253, 238, 14, 3, 2, 1, + 0, 255, 254, 252, 218, 35, 3, 2, + 1, 0, 255, 254, 250, 208, 59, 4, + 2, 1, 0, 255, 254, 246, 194, 71, + 10, 2, 1, 0, 255, 252, 236, 183, + 82, 8, 2, 1, 0, 255, 252, 235, + 180, 90, 17, 2, 1, 0, 255, 248, + 224, 171, 97, 30, 4, 1, 0, 255, + 254, 236, 173, 95, 37, 7, 1, 0 }; static const opus_uint8 silk_NLSF_CB2_BITS_NB_MB_Q5[ 72 ] = { - 255, 255, 255, 131, 6, 145, 255, 255, - 255, 255, 255, 236, 93, 15, 96, 255, - 255, 255, 255, 255, 194, 83, 25, 71, - 221, 255, 255, 255, 255, 162, 73, 34, - 66, 162, 255, 255, 255, 210, 126, 73, - 43, 57, 173, 255, 255, 255, 201, 125, - 71, 48, 58, 130, 255, 255, 255, 166, - 110, 73, 57, 62, 104, 210, 255, 255, - 251, 123, 65, 55, 68, 100, 171, 255 + 255, 255, 255, 131, 6, 145, 255, 255, + 255, 255, 255, 236, 93, 15, 96, 255, + 255, 255, 255, 255, 194, 83, 25, 71, + 221, 255, 255, 255, 255, 162, 73, 34, + 66, 162, 255, 255, 255, 210, 126, 73, + 43, 57, 173, 255, 255, 255, 201, 125, + 71, 48, 58, 130, 255, 255, 255, 166, + 110, 73, 57, 62, 104, 210, 255, 255, + 251, 123, 65, 55, 68, 100, 171, 255 }; static const opus_uint8 silk_NLSF_PRED_NB_MB_Q8[ 18 ] = { - 179, 138, 140, 148, 151, 149, 153, 151, - 163, 116, 67, 82, 59, 92, 72, 100, - 89, 92 + 179, 138, 140, 148, 151, 149, 153, 151, + 163, 116, 67, 82, 59, 92, 72, 100, + 89, 92 }; static const opus_int16 silk_NLSF_DELTA_MIN_NB_MB_Q15[ 11 ] = { - 250, 3, 6, 3, 3, 3, 4, 3, - 3, 3, 461 + 250, 3, 6, 3, 3, 3, 4, 3, + 3, 3, 461 }; -const silk_NLSF_CB_struct silk_NLSF_CB_NB_MB = { +const silk_NLSF_CB_struct silk_NLSF_CB_NB_MB = +{ 32, 10, - SILK_FIX_CONST(0.18, 16), - SILK_FIX_CONST(1.0 / 0.18, 6), + SILK_FIX_CONST( 0.18, 16 ), + SILK_FIX_CONST( 1.0 / 0.18, 6 ), silk_NLSF_CB1_NB_MB_Q8, silk_NLSF_CB1_Wght_Q9, silk_NLSF_CB1_iCDF_NB_MB, diff --git a/src/libopus/silk/tables_NLSF_CB_WB.c b/src/libopus/silk/tables_NLSF_CB_WB.c index 0841a71..1baa75c 100644 --- a/src/libopus/silk/tables_NLSF_CB_WB.c +++ b/src/libopus/silk/tables_NLSF_CB_WB.c @@ -1,226 +1,227 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "tables.h" static const opus_uint8 silk_NLSF_CB1_WB_Q8[ 512 ] = { - 7, 23, 38, 54, 69, 85, 100, 116, - 131, 147, 162, 178, 193, 208, 223, 239, - 13, 25, 41, 55, 69, 83, 98, 112, - 127, 142, 157, 171, 187, 203, 220, 236, - 15, 21, 34, 51, 61, 78, 92, 106, - 126, 136, 152, 167, 185, 205, 225, 240, - 10, 21, 36, 50, 63, 79, 95, 110, - 126, 141, 157, 173, 189, 205, 221, 237, - 17, 20, 37, 51, 59, 78, 89, 107, - 123, 134, 150, 164, 184, 205, 224, 240, - 10, 15, 32, 51, 67, 81, 96, 112, - 129, 142, 158, 173, 189, 204, 220, 236, - 8, 21, 37, 51, 65, 79, 98, 113, - 126, 138, 155, 168, 179, 192, 209, 218, - 12, 15, 34, 55, 63, 78, 87, 108, - 118, 131, 148, 167, 185, 203, 219, 236, - 16, 19, 32, 36, 56, 79, 91, 108, - 118, 136, 154, 171, 186, 204, 220, 237, - 11, 28, 43, 58, 74, 89, 105, 120, - 135, 150, 165, 180, 196, 211, 226, 241, - 6, 16, 33, 46, 60, 75, 92, 107, - 123, 137, 156, 169, 185, 199, 214, 225, - 11, 19, 30, 44, 57, 74, 89, 105, - 121, 135, 152, 169, 186, 202, 218, 234, - 12, 19, 29, 46, 57, 71, 88, 100, - 120, 132, 148, 165, 182, 199, 216, 233, - 17, 23, 35, 46, 56, 77, 92, 106, - 123, 134, 152, 167, 185, 204, 222, 237, - 14, 17, 45, 53, 63, 75, 89, 107, - 115, 132, 151, 171, 188, 206, 221, 240, - 9, 16, 29, 40, 56, 71, 88, 103, - 119, 137, 154, 171, 189, 205, 222, 237, - 16, 19, 36, 48, 57, 76, 87, 105, - 118, 132, 150, 167, 185, 202, 218, 236, - 12, 17, 29, 54, 71, 81, 94, 104, - 126, 136, 149, 164, 182, 201, 221, 237, - 15, 28, 47, 62, 79, 97, 115, 129, - 142, 155, 168, 180, 194, 208, 223, 238, - 8, 14, 30, 45, 62, 78, 94, 111, - 127, 143, 159, 175, 192, 207, 223, 239, - 17, 30, 49, 62, 79, 92, 107, 119, - 132, 145, 160, 174, 190, 204, 220, 235, - 14, 19, 36, 45, 61, 76, 91, 108, - 121, 138, 154, 172, 189, 205, 222, 238, - 12, 18, 31, 45, 60, 76, 91, 107, - 123, 138, 154, 171, 187, 204, 221, 236, - 13, 17, 31, 43, 53, 70, 83, 103, - 114, 131, 149, 167, 185, 203, 220, 237, - 17, 22, 35, 42, 58, 78, 93, 110, - 125, 139, 155, 170, 188, 206, 224, 240, - 8, 15, 34, 50, 67, 83, 99, 115, - 131, 146, 162, 178, 193, 209, 224, 239, - 13, 16, 41, 66, 73, 86, 95, 111, - 128, 137, 150, 163, 183, 206, 225, 241, - 17, 25, 37, 52, 63, 75, 92, 102, - 119, 132, 144, 160, 175, 191, 212, 231, - 19, 31, 49, 65, 83, 100, 117, 133, - 147, 161, 174, 187, 200, 213, 227, 242, - 18, 31, 52, 68, 88, 103, 117, 126, - 138, 149, 163, 177, 192, 207, 223, 239, - 16, 29, 47, 61, 76, 90, 106, 119, - 133, 147, 161, 176, 193, 209, 224, 240, - 15, 21, 35, 50, 61, 73, 86, 97, - 110, 119, 129, 141, 175, 198, 218, 237 + 7, 23, 38, 54, 69, 85, 100, 116, + 131, 147, 162, 178, 193, 208, 223, 239, + 13, 25, 41, 55, 69, 83, 98, 112, + 127, 142, 157, 171, 187, 203, 220, 236, + 15, 21, 34, 51, 61, 78, 92, 106, + 126, 136, 152, 167, 185, 205, 225, 240, + 10, 21, 36, 50, 63, 79, 95, 110, + 126, 141, 157, 173, 189, 205, 221, 237, + 17, 20, 37, 51, 59, 78, 89, 107, + 123, 134, 150, 164, 184, 205, 224, 240, + 10, 15, 32, 51, 67, 81, 96, 112, + 129, 142, 158, 173, 189, 204, 220, 236, + 8, 21, 37, 51, 65, 79, 98, 113, + 126, 138, 155, 168, 179, 192, 209, 218, + 12, 15, 34, 55, 63, 78, 87, 108, + 118, 131, 148, 167, 185, 203, 219, 236, + 16, 19, 32, 36, 56, 79, 91, 108, + 118, 136, 154, 171, 186, 204, 220, 237, + 11, 28, 43, 58, 74, 89, 105, 120, + 135, 150, 165, 180, 196, 211, 226, 241, + 6, 16, 33, 46, 60, 75, 92, 107, + 123, 137, 156, 169, 185, 199, 214, 225, + 11, 19, 30, 44, 57, 74, 89, 105, + 121, 135, 152, 169, 186, 202, 218, 234, + 12, 19, 29, 46, 57, 71, 88, 100, + 120, 132, 148, 165, 182, 199, 216, 233, + 17, 23, 35, 46, 56, 77, 92, 106, + 123, 134, 152, 167, 185, 204, 222, 237, + 14, 17, 45, 53, 63, 75, 89, 107, + 115, 132, 151, 171, 188, 206, 221, 240, + 9, 16, 29, 40, 56, 71, 88, 103, + 119, 137, 154, 171, 189, 205, 222, 237, + 16, 19, 36, 48, 57, 76, 87, 105, + 118, 132, 150, 167, 185, 202, 218, 236, + 12, 17, 29, 54, 71, 81, 94, 104, + 126, 136, 149, 164, 182, 201, 221, 237, + 15, 28, 47, 62, 79, 97, 115, 129, + 142, 155, 168, 180, 194, 208, 223, 238, + 8, 14, 30, 45, 62, 78, 94, 111, + 127, 143, 159, 175, 192, 207, 223, 239, + 17, 30, 49, 62, 79, 92, 107, 119, + 132, 145, 160, 174, 190, 204, 220, 235, + 14, 19, 36, 45, 61, 76, 91, 108, + 121, 138, 154, 172, 189, 205, 222, 238, + 12, 18, 31, 45, 60, 76, 91, 107, + 123, 138, 154, 171, 187, 204, 221, 236, + 13, 17, 31, 43, 53, 70, 83, 103, + 114, 131, 149, 167, 185, 203, 220, 237, + 17, 22, 35, 42, 58, 78, 93, 110, + 125, 139, 155, 170, 188, 206, 224, 240, + 8, 15, 34, 50, 67, 83, 99, 115, + 131, 146, 162, 178, 193, 209, 224, 239, + 13, 16, 41, 66, 73, 86, 95, 111, + 128, 137, 150, 163, 183, 206, 225, 241, + 17, 25, 37, 52, 63, 75, 92, 102, + 119, 132, 144, 160, 175, 191, 212, 231, + 19, 31, 49, 65, 83, 100, 117, 133, + 147, 161, 174, 187, 200, 213, 227, 242, + 18, 31, 52, 68, 88, 103, 117, 126, + 138, 149, 163, 177, 192, 207, 223, 239, + 16, 29, 47, 61, 76, 90, 106, 119, + 133, 147, 161, 176, 193, 209, 224, 240, + 15, 21, 35, 50, 61, 73, 86, 97, + 110, 119, 129, 141, 175, 198, 218, 237 }; static const opus_int16 silk_NLSF_CB1_WB_Wght_Q9[ 512 ] = { - 3657, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2963, 2963, 2925, 2846, - 3216, 3085, 2972, 3056, 3056, 3010, 3010, 3010, 2963, 2963, 3010, 2972, 2888, 2846, 2846, 2726, - 3920, 4014, 2981, 3207, 3207, 2934, 3056, 2846, 3122, 3244, 2925, 2846, 2620, 2553, 2780, 2925, - 3516, 3197, 3010, 3103, 3019, 2888, 2925, 2925, 2925, 2925, 2888, 2888, 2888, 2888, 2888, 2753, - 5054, 5054, 2934, 3573, 3385, 3056, 3085, 2793, 3160, 3160, 2972, 2846, 2513, 2540, 2753, 2888, - 4428, 4149, 2700, 2753, 2972, 3010, 2925, 2846, 2981, 3019, 2925, 2925, 2925, 2925, 2888, 2726, - 3620, 3019, 2972, 3056, 3056, 2873, 2806, 3056, 3216, 3047, 2981, 3291, 3291, 2981, 3310, 2991, - 5227, 5014, 2540, 3338, 3526, 3385, 3197, 3094, 3376, 2981, 2700, 2647, 2687, 2793, 2846, 2673, - 5081, 5174, 4615, 4428, 2460, 2897, 3047, 3207, 3169, 2687, 2740, 2888, 2846, 2793, 2846, 2700, - 3122, 2888, 2963, 2925, 2925, 2925, 2925, 2963, 2963, 2963, 2963, 2925, 2925, 2963, 2963, 2963, - 4202, 3207, 2981, 3103, 3010, 2888, 2888, 2925, 2972, 2873, 2916, 3019, 2972, 3010, 3197, 2873, - 3760, 3760, 3244, 3103, 2981, 2888, 2925, 2888, 2972, 2934, 2793, 2793, 2846, 2888, 2888, 2660, - 3854, 4014, 3207, 3122, 3244, 2934, 3047, 2963, 2963, 3085, 2846, 2793, 2793, 2793, 2793, 2580, - 3845, 4080, 3357, 3516, 3094, 2740, 3010, 2934, 3122, 3085, 2846, 2846, 2647, 2647, 2846, 2806, - 5147, 4894, 3225, 3845, 3441, 3169, 2897, 3413, 3451, 2700, 2580, 2673, 2740, 2846, 2806, 2753, - 4109, 3789, 3291, 3160, 2925, 2888, 2888, 2925, 2793, 2740, 2793, 2740, 2793, 2846, 2888, 2806, - 5081, 5054, 3047, 3545, 3244, 3056, 3085, 2944, 3103, 2897, 2740, 2740, 2740, 2846, 2793, 2620, - 4309, 4309, 2860, 2527, 3207, 3376, 3376, 3075, 3075, 3376, 3056, 2846, 2647, 2580, 2726, 2753, - 3056, 2916, 2806, 2888, 2740, 2687, 2897, 3103, 3150, 3150, 3216, 3169, 3056, 3010, 2963, 2846, - 4375, 3882, 2925, 2888, 2846, 2888, 2846, 2846, 2888, 2888, 2888, 2846, 2888, 2925, 2888, 2846, - 2981, 2916, 2916, 2981, 2981, 3056, 3122, 3216, 3150, 3056, 3010, 2972, 2972, 2972, 2925, 2740, - 4229, 4149, 3310, 3347, 2925, 2963, 2888, 2981, 2981, 2846, 2793, 2740, 2846, 2846, 2846, 2793, - 4080, 4014, 3103, 3010, 2925, 2925, 2925, 2888, 2925, 2925, 2846, 2846, 2846, 2793, 2888, 2780, - 4615, 4575, 3169, 3441, 3207, 2981, 2897, 3038, 3122, 2740, 2687, 2687, 2687, 2740, 2793, 2700, - 4149, 4269, 3789, 3657, 2726, 2780, 2888, 2888, 3010, 2972, 2925, 2846, 2687, 2687, 2793, 2888, - 4215, 3554, 2753, 2846, 2846, 2888, 2888, 2888, 2925, 2925, 2888, 2925, 2925, 2925, 2963, 2888, - 5174, 4921, 2261, 3432, 3789, 3479, 3347, 2846, 3310, 3479, 3150, 2897, 2460, 2487, 2753, 2925, - 3451, 3685, 3122, 3197, 3357, 3047, 3207, 3207, 2981, 3216, 3085, 2925, 2925, 2687, 2540, 2434, - 2981, 3010, 2793, 2793, 2740, 2793, 2846, 2972, 3056, 3103, 3150, 3150, 3150, 3103, 3010, 3010, - 2944, 2873, 2687, 2726, 2780, 3010, 3432, 3545, 3357, 3244, 3056, 3010, 2963, 2925, 2888, 2846, - 3019, 2944, 2897, 3010, 3010, 2972, 3019, 3103, 3056, 3056, 3010, 2888, 2846, 2925, 2925, 2888, - 3920, 3967, 3010, 3197, 3357, 3216, 3291, 3291, 3479, 3704, 3441, 2726, 2181, 2460, 2580, 2607 + 3657, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2963, 2963, 2925, 2846, + 3216, 3085, 2972, 3056, 3056, 3010, 3010, 3010, 2963, 2963, 3010, 2972, 2888, 2846, 2846, 2726, + 3920, 4014, 2981, 3207, 3207, 2934, 3056, 2846, 3122, 3244, 2925, 2846, 2620, 2553, 2780, 2925, + 3516, 3197, 3010, 3103, 3019, 2888, 2925, 2925, 2925, 2925, 2888, 2888, 2888, 2888, 2888, 2753, + 5054, 5054, 2934, 3573, 3385, 3056, 3085, 2793, 3160, 3160, 2972, 2846, 2513, 2540, 2753, 2888, + 4428, 4149, 2700, 2753, 2972, 3010, 2925, 2846, 2981, 3019, 2925, 2925, 2925, 2925, 2888, 2726, + 3620, 3019, 2972, 3056, 3056, 2873, 2806, 3056, 3216, 3047, 2981, 3291, 3291, 2981, 3310, 2991, + 5227, 5014, 2540, 3338, 3526, 3385, 3197, 3094, 3376, 2981, 2700, 2647, 2687, 2793, 2846, 2673, + 5081, 5174, 4615, 4428, 2460, 2897, 3047, 3207, 3169, 2687, 2740, 2888, 2846, 2793, 2846, 2700, + 3122, 2888, 2963, 2925, 2925, 2925, 2925, 2963, 2963, 2963, 2963, 2925, 2925, 2963, 2963, 2963, + 4202, 3207, 2981, 3103, 3010, 2888, 2888, 2925, 2972, 2873, 2916, 3019, 2972, 3010, 3197, 2873, + 3760, 3760, 3244, 3103, 2981, 2888, 2925, 2888, 2972, 2934, 2793, 2793, 2846, 2888, 2888, 2660, + 3854, 4014, 3207, 3122, 3244, 2934, 3047, 2963, 2963, 3085, 2846, 2793, 2793, 2793, 2793, 2580, + 3845, 4080, 3357, 3516, 3094, 2740, 3010, 2934, 3122, 3085, 2846, 2846, 2647, 2647, 2846, 2806, + 5147, 4894, 3225, 3845, 3441, 3169, 2897, 3413, 3451, 2700, 2580, 2673, 2740, 2846, 2806, 2753, + 4109, 3789, 3291, 3160, 2925, 2888, 2888, 2925, 2793, 2740, 2793, 2740, 2793, 2846, 2888, 2806, + 5081, 5054, 3047, 3545, 3244, 3056, 3085, 2944, 3103, 2897, 2740, 2740, 2740, 2846, 2793, 2620, + 4309, 4309, 2860, 2527, 3207, 3376, 3376, 3075, 3075, 3376, 3056, 2846, 2647, 2580, 2726, 2753, + 3056, 2916, 2806, 2888, 2740, 2687, 2897, 3103, 3150, 3150, 3216, 3169, 3056, 3010, 2963, 2846, + 4375, 3882, 2925, 2888, 2846, 2888, 2846, 2846, 2888, 2888, 2888, 2846, 2888, 2925, 2888, 2846, + 2981, 2916, 2916, 2981, 2981, 3056, 3122, 3216, 3150, 3056, 3010, 2972, 2972, 2972, 2925, 2740, + 4229, 4149, 3310, 3347, 2925, 2963, 2888, 2981, 2981, 2846, 2793, 2740, 2846, 2846, 2846, 2793, + 4080, 4014, 3103, 3010, 2925, 2925, 2925, 2888, 2925, 2925, 2846, 2846, 2846, 2793, 2888, 2780, + 4615, 4575, 3169, 3441, 3207, 2981, 2897, 3038, 3122, 2740, 2687, 2687, 2687, 2740, 2793, 2700, + 4149, 4269, 3789, 3657, 2726, 2780, 2888, 2888, 3010, 2972, 2925, 2846, 2687, 2687, 2793, 2888, + 4215, 3554, 2753, 2846, 2846, 2888, 2888, 2888, 2925, 2925, 2888, 2925, 2925, 2925, 2963, 2888, + 5174, 4921, 2261, 3432, 3789, 3479, 3347, 2846, 3310, 3479, 3150, 2897, 2460, 2487, 2753, 2925, + 3451, 3685, 3122, 3197, 3357, 3047, 3207, 3207, 2981, 3216, 3085, 2925, 2925, 2687, 2540, 2434, + 2981, 3010, 2793, 2793, 2740, 2793, 2846, 2972, 3056, 3103, 3150, 3150, 3150, 3103, 3010, 3010, + 2944, 2873, 2687, 2726, 2780, 3010, 3432, 3545, 3357, 3244, 3056, 3010, 2963, 2925, 2888, 2846, + 3019, 2944, 2897, 3010, 3010, 2972, 3019, 3103, 3056, 3056, 3010, 2888, 2846, 2925, 2925, 2888, + 3920, 3967, 3010, 3197, 3357, 3216, 3291, 3291, 3479, 3704, 3441, 2726, 2181, 2460, 2580, 2607 }; static const opus_uint8 silk_NLSF_CB1_iCDF_WB[ 64 ] = { - 225, 204, 201, 184, 183, 175, 158, 154, - 153, 135, 119, 115, 113, 110, 109, 99, - 98, 95, 79, 68, 52, 50, 48, 45, - 43, 32, 31, 27, 18, 10, 3, 0, - 255, 251, 235, 230, 212, 201, 196, 182, - 167, 166, 163, 151, 138, 124, 110, 104, - 90, 78, 76, 70, 69, 57, 45, 34, - 24, 21, 11, 6, 5, 4, 3, 0 + 225, 204, 201, 184, 183, 175, 158, 154, + 153, 135, 119, 115, 113, 110, 109, 99, + 98, 95, 79, 68, 52, 50, 48, 45, + 43, 32, 31, 27, 18, 10, 3, 0, + 255, 251, 235, 230, 212, 201, 196, 182, + 167, 166, 163, 151, 138, 124, 110, 104, + 90, 78, 76, 70, 69, 57, 45, 34, + 24, 21, 11, 6, 5, 4, 3, 0 }; static const opus_uint8 silk_NLSF_CB2_SELECT_WB[ 256 ] = { - 0, 0, 0, 0, 0, 0, 0, 1, - 100, 102, 102, 68, 68, 36, 34, 96, - 164, 107, 158, 185, 180, 185, 139, 102, - 64, 66, 36, 34, 34, 0, 1, 32, - 208, 139, 141, 191, 152, 185, 155, 104, - 96, 171, 104, 166, 102, 102, 102, 132, - 1, 0, 0, 0, 0, 16, 16, 0, - 80, 109, 78, 107, 185, 139, 103, 101, - 208, 212, 141, 139, 173, 153, 123, 103, - 36, 0, 0, 0, 0, 0, 0, 1, - 48, 0, 0, 0, 0, 0, 0, 32, - 68, 135, 123, 119, 119, 103, 69, 98, - 68, 103, 120, 118, 118, 102, 71, 98, - 134, 136, 157, 184, 182, 153, 139, 134, - 208, 168, 248, 75, 189, 143, 121, 107, - 32, 49, 34, 34, 34, 0, 17, 2, - 210, 235, 139, 123, 185, 137, 105, 134, - 98, 135, 104, 182, 100, 183, 171, 134, - 100, 70, 68, 70, 66, 66, 34, 131, - 64, 166, 102, 68, 36, 2, 1, 0, - 134, 166, 102, 68, 34, 34, 66, 132, - 212, 246, 158, 139, 107, 107, 87, 102, - 100, 219, 125, 122, 137, 118, 103, 132, - 114, 135, 137, 105, 171, 106, 50, 34, - 164, 214, 141, 143, 185, 151, 121, 103, - 192, 34, 0, 0, 0, 0, 0, 1, - 208, 109, 74, 187, 134, 249, 159, 137, - 102, 110, 154, 118, 87, 101, 119, 101, - 0, 2, 0, 36, 36, 66, 68, 35, - 96, 164, 102, 100, 36, 0, 2, 33, - 167, 138, 174, 102, 100, 84, 2, 2, - 100, 107, 120, 119, 36, 197, 24, 0 + 0, 0, 0, 0, 0, 0, 0, 1, + 100, 102, 102, 68, 68, 36, 34, 96, + 164, 107, 158, 185, 180, 185, 139, 102, + 64, 66, 36, 34, 34, 0, 1, 32, + 208, 139, 141, 191, 152, 185, 155, 104, + 96, 171, 104, 166, 102, 102, 102, 132, + 1, 0, 0, 0, 0, 16, 16, 0, + 80, 109, 78, 107, 185, 139, 103, 101, + 208, 212, 141, 139, 173, 153, 123, 103, + 36, 0, 0, 0, 0, 0, 0, 1, + 48, 0, 0, 0, 0, 0, 0, 32, + 68, 135, 123, 119, 119, 103, 69, 98, + 68, 103, 120, 118, 118, 102, 71, 98, + 134, 136, 157, 184, 182, 153, 139, 134, + 208, 168, 248, 75, 189, 143, 121, 107, + 32, 49, 34, 34, 34, 0, 17, 2, + 210, 235, 139, 123, 185, 137, 105, 134, + 98, 135, 104, 182, 100, 183, 171, 134, + 100, 70, 68, 70, 66, 66, 34, 131, + 64, 166, 102, 68, 36, 2, 1, 0, + 134, 166, 102, 68, 34, 34, 66, 132, + 212, 246, 158, 139, 107, 107, 87, 102, + 100, 219, 125, 122, 137, 118, 103, 132, + 114, 135, 137, 105, 171, 106, 50, 34, + 164, 214, 141, 143, 185, 151, 121, 103, + 192, 34, 0, 0, 0, 0, 0, 1, + 208, 109, 74, 187, 134, 249, 159, 137, + 102, 110, 154, 118, 87, 101, 119, 101, + 0, 2, 0, 36, 36, 66, 68, 35, + 96, 164, 102, 100, 36, 0, 2, 33, + 167, 138, 174, 102, 100, 84, 2, 2, + 100, 107, 120, 119, 36, 197, 24, 0 }; static const opus_uint8 silk_NLSF_CB2_iCDF_WB[ 72 ] = { - 255, 254, 253, 244, 12, 3, 2, 1, - 0, 255, 254, 252, 224, 38, 3, 2, - 1, 0, 255, 254, 251, 209, 57, 4, - 2, 1, 0, 255, 254, 244, 195, 69, - 4, 2, 1, 0, 255, 251, 232, 184, - 84, 7, 2, 1, 0, 255, 254, 240, - 186, 86, 14, 2, 1, 0, 255, 254, - 239, 178, 91, 30, 5, 1, 0, 255, - 248, 227, 177, 100, 19, 2, 1, 0 + 255, 254, 253, 244, 12, 3, 2, 1, + 0, 255, 254, 252, 224, 38, 3, 2, + 1, 0, 255, 254, 251, 209, 57, 4, + 2, 1, 0, 255, 254, 244, 195, 69, + 4, 2, 1, 0, 255, 251, 232, 184, + 84, 7, 2, 1, 0, 255, 254, 240, + 186, 86, 14, 2, 1, 0, 255, 254, + 239, 178, 91, 30, 5, 1, 0, 255, + 248, 227, 177, 100, 19, 2, 1, 0 }; static const opus_uint8 silk_NLSF_CB2_BITS_WB_Q5[ 72 ] = { - 255, 255, 255, 156, 4, 154, 255, 255, - 255, 255, 255, 227, 102, 15, 92, 255, - 255, 255, 255, 255, 213, 83, 24, 72, - 236, 255, 255, 255, 255, 150, 76, 33, - 63, 214, 255, 255, 255, 190, 121, 77, - 43, 55, 185, 255, 255, 255, 245, 137, - 71, 43, 59, 139, 255, 255, 255, 255, - 131, 66, 50, 66, 107, 194, 255, 255, - 166, 116, 76, 55, 53, 125, 255, 255 + 255, 255, 255, 156, 4, 154, 255, 255, + 255, 255, 255, 227, 102, 15, 92, 255, + 255, 255, 255, 255, 213, 83, 24, 72, + 236, 255, 255, 255, 255, 150, 76, 33, + 63, 214, 255, 255, 255, 190, 121, 77, + 43, 55, 185, 255, 255, 255, 245, 137, + 71, 43, 59, 139, 255, 255, 255, 255, + 131, 66, 50, 66, 107, 194, 255, 255, + 166, 116, 76, 55, 53, 125, 255, 255 }; static const opus_uint8 silk_NLSF_PRED_WB_Q8[ 30 ] = { - 175, 148, 160, 176, 178, 173, 174, 164, - 177, 174, 196, 182, 198, 192, 182, 68, - 62, 66, 60, 72, 117, 85, 90, 118, - 136, 151, 142, 160, 142, 155 + 175, 148, 160, 176, 178, 173, 174, 164, + 177, 174, 196, 182, 198, 192, 182, 68, + 62, 66, 60, 72, 117, 85, 90, 118, + 136, 151, 142, 160, 142, 155 }; static const opus_int16 silk_NLSF_DELTA_MIN_WB_Q15[ 17 ] = { - 100, 3, 40, 3, 3, 3, 5, 14, - 14, 10, 11, 3, 8, 9, 7, 3, - 347 + 100, 3, 40, 3, 3, 3, 5, 14, + 14, 10, 11, 3, 8, 9, 7, 3, + 347 }; -const silk_NLSF_CB_struct silk_NLSF_CB_WB = { +const silk_NLSF_CB_struct silk_NLSF_CB_WB = +{ 32, 16, - SILK_FIX_CONST(0.15, 16), - SILK_FIX_CONST(1.0 / 0.15, 6), + SILK_FIX_CONST( 0.15, 16 ), + SILK_FIX_CONST( 1.0 / 0.15, 6 ), silk_NLSF_CB1_WB_Q8, silk_NLSF_CB1_WB_Wght_Q9, silk_NLSF_CB1_iCDF_WB, diff --git a/src/libopus/silk/tables_gain.c b/src/libopus/silk/tables_gain.c index ec388e9..47b659a 100644 --- a/src/libopus/silk/tables_gain.c +++ b/src/libopus/silk/tables_gain.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "tables.h" @@ -36,25 +36,26 @@ extern "C" { #endif -const opus_uint8 silk_gain_iCDF[ 3 ][ N_LEVELS_QGAIN / 8 ] = { - { - 224, 112, 44, 15, 3, 2, 1, 0 - }, - { - 254, 237, 192, 132, 70, 23, 4, 0 - }, - { - 255, 252, 226, 155, 61, 11, 2, 0 - } +const opus_uint8 silk_gain_iCDF[ 3 ][ N_LEVELS_QGAIN / 8 ] = +{ +{ + 224, 112, 44, 15, 3, 2, 1, 0 +}, +{ + 254, 237, 192, 132, 70, 23, 4, 0 +}, +{ + 255, 252, 226, 155, 61, 11, 2, 0 +} }; const opus_uint8 silk_delta_gain_iCDF[ MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ] = { - 250, 245, 234, 203, 71, 50, 42, 38, - 35, 33, 31, 29, 28, 27, 26, 25, - 24, 23, 22, 21, 20, 19, 18, 17, - 16, 15, 14, 13, 12, 11, 10, 9, - 8, 7, 6, 5, 4, 3, 2, 1, - 0 + 250, 245, 234, 203, 71, 50, 42, 38, + 35, 33, 31, 29, 28, 27, 26, 25, + 24, 23, 22, 21, 20, 19, 18, 17, + 16, 15, 14, 13, 12, 11, 10, 9, + 8, 7, 6, 5, 4, 3, 2, 1, + 0 }; #ifdef __cplusplus diff --git a/src/libopus/silk/tables_other.c b/src/libopus/silk/tables_other.c index 235e22c..045a7e4 100644 --- a/src/libopus/silk/tables_other.c +++ b/src/libopus/silk/tables_other.c @@ -1,33 +1,33 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "structs.h" #include "define.h" @@ -41,14 +41,14 @@ extern "C" /* Tables for stereo predictor coding */ const opus_int16 silk_stereo_pred_quant_Q13[ STEREO_QUANT_TAB_SIZE ] = { -13732, -10050, -8266, -7526, -6500, -5000, -2950, -820, - 820, 2950, 5000, 6500, 7526, 8266, 10050, 13732 - }; + 820, 2950, 5000, 6500, 7526, 8266, 10050, 13732 +}; const opus_uint8 silk_stereo_pred_joint_iCDF[ 25 ] = { 249, 247, 246, 245, 244, 234, 210, 202, 201, 200, 197, 174, 82, 59, 56, - 55, 54, 46, 22, 12, - 11, 10, 9, 7, 0 + 55, 54, 46, 22, 12, + 11, 10, 9, 7, 0 }; const opus_uint8 silk_stereo_only_code_mid_iCDF[ 2 ] = { 64, 0 }; @@ -68,10 +68,10 @@ const opus_uint8 silk_LTPscale_iCDF[ 3 ] = { 128, 64, 0 }; /* Tables for signal type and offset coding */ const opus_uint8 silk_type_offset_VAD_iCDF[ 4 ] = { - 232, 158, 10, 0 + 232, 158, 10, 0 }; const opus_uint8 silk_type_offset_no_VAD_iCDF[ 2 ] = { - 230, 0 + 230, 0 }; /* Tables for NLSF interpolation factor */ @@ -99,21 +99,23 @@ const opus_uint8 silk_NLSF_EXT_iCDF[ 7 ] = { 100, 40, 16, 7, 3, 1, 0 }; [0.95 : 0.15 : 0.35] normalized cut off frequencies. */ /* Interpolation points for filter coefficients used in the bandwidth transition smoother */ -const opus_int32 silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ] = { - { 250767114, 501534038, 250767114 }, - { 209867381, 419732057, 209867381 }, - { 170987846, 341967853, 170987846 }, - { 131531482, 263046905, 131531482 }, - { 89306658, 178584282, 89306658 } +const opus_int32 silk_Transition_LP_B_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NB ] = +{ +{ 250767114, 501534038, 250767114 }, +{ 209867381, 419732057, 209867381 }, +{ 170987846, 341967853, 170987846 }, +{ 131531482, 263046905, 131531482 }, +{ 89306658, 178584282, 89306658 } }; /* Interpolation points for filter coefficients used in the bandwidth transition smoother */ -const opus_int32 silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ] = { - { 506393414, 239854379 }, - { 411067935, 169683996 }, - { 306733530, 116694253 }, - { 185807084, 77959395 }, - { 35497197, 57401098 } +const opus_int32 silk_Transition_LP_A_Q28[ TRANSITION_INT_NUM ][ TRANSITION_NA ] = +{ +{ 506393414, 239854379 }, +{ 411067935, 169683996 }, +{ 306733530, 116694253 }, +{ 185807084, 77959395 }, +{ 35497197, 57401098 } }; #ifdef __cplusplus diff --git a/src/libopus/silk/tables_pitch_lag.c b/src/libopus/silk/tables_pitch_lag.c index 4de8cc6..bb27521 100644 --- a/src/libopus/silk/tables_pitch_lag.c +++ b/src/libopus/silk/tables_pitch_lag.c @@ -1,69 +1,69 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "tables.h" -const opus_uint8 silk_pitch_lag_iCDF[ 2 * (PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS) ] = { - 253, 250, 244, 233, 212, 182, 150, 131, - 120, 110, 98, 85, 72, 60, 49, 40, - 32, 25, 19, 15, 13, 11, 9, 8, - 7, 6, 5, 4, 3, 2, 1, 0 +const opus_uint8 silk_pitch_lag_iCDF[ 2 * ( PITCH_EST_MAX_LAG_MS - PITCH_EST_MIN_LAG_MS ) ] = { + 253, 250, 244, 233, 212, 182, 150, 131, + 120, 110, 98, 85, 72, 60, 49, 40, + 32, 25, 19, 15, 13, 11, 9, 8, + 7, 6, 5, 4, 3, 2, 1, 0 }; const opus_uint8 silk_pitch_delta_iCDF[21] = { - 210, 208, 206, 203, 199, 193, 183, 168, - 142, 104, 74, 52, 37, 27, 20, 14, - 10, 6, 4, 2, 0 + 210, 208, 206, 203, 199, 193, 183, 168, + 142, 104, 74, 52, 37, 27, 20, 14, + 10, 6, 4, 2, 0 }; const opus_uint8 silk_pitch_contour_iCDF[34] = { - 223, 201, 183, 167, 152, 138, 124, 111, - 98, 88, 79, 70, 62, 56, 50, 44, - 39, 35, 31, 27, 24, 21, 18, 16, - 14, 12, 10, 8, 6, 4, 3, 2, - 1, 0 + 223, 201, 183, 167, 152, 138, 124, 111, + 98, 88, 79, 70, 62, 56, 50, 44, + 39, 35, 31, 27, 24, 21, 18, 16, + 14, 12, 10, 8, 6, 4, 3, 2, + 1, 0 }; const opus_uint8 silk_pitch_contour_NB_iCDF[11] = { - 188, 176, 155, 138, 119, 97, 67, 43, - 26, 10, 0 + 188, 176, 155, 138, 119, 97, 67, 43, + 26, 10, 0 }; const opus_uint8 silk_pitch_contour_10_ms_iCDF[12] = { - 165, 119, 80, 61, 47, 35, 27, 20, - 14, 9, 4, 0 + 165, 119, 80, 61, 47, 35, 27, 20, + 14, 9, 4, 0 }; const opus_uint8 silk_pitch_contour_10_ms_NB_iCDF[3] = { - 113, 63, 0 + 113, 63, 0 }; diff --git a/src/libopus/silk/tables_pulses_per_block.c b/src/libopus/silk/tables_pulses_per_block.c index ee03e2c..83935b0 100644 --- a/src/libopus/silk/tables_pulses_per_block.c +++ b/src/libopus/silk/tables_pulses_per_block.c @@ -1,262 +1,264 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "../config.h" -//#endif +#ifdef __STDC__ +#include "config.h" +#endif #include "tables.h" const opus_uint8 silk_max_pulses_table[ 4 ] = { - 8, 10, 12, 16 + 8, 10, 12, 16 }; const opus_uint8 silk_pulses_per_block_iCDF[ 10 ][ 18 ] = { - { - 125, 51, 26, 18, 15, 12, 11, 10, - 9, 8, 7, 6, 5, 4, 3, 2, - 1, 0 - }, - { - 198, 105, 45, 22, 15, 12, 11, 10, - 9, 8, 7, 6, 5, 4, 3, 2, - 1, 0 - }, - { - 213, 162, 116, 83, 59, 43, 32, 24, +{ + 125, 51, 26, 18, 15, 12, 11, 10, + 9, 8, 7, 6, 5, 4, 3, 2, + 1, 0 +}, +{ + 198, 105, 45, 22, 15, 12, 11, 10, + 9, 8, 7, 6, 5, 4, 3, 2, + 1, 0 +}, +{ + 213, 162, 116, 83, 59, 43, 32, 24, 18, 15, 12, 9, 7, 6, 5, 3, - 2, 0 - }, - { - 239, 187, 116, 59, 28, 16, 11, 10, - 9, 8, 7, 6, 5, 4, 3, 2, - 1, 0 - }, - { - 250, 229, 188, 135, 86, 51, 30, 19, + 2, 0 +}, +{ + 239, 187, 116, 59, 28, 16, 11, 10, + 9, 8, 7, 6, 5, 4, 3, 2, + 1, 0 +}, +{ + 250, 229, 188, 135, 86, 51, 30, 19, 13, 10, 8, 6, 5, 4, 3, 2, - 1, 0 - }, - { - 249, 235, 213, 185, 156, 128, 103, 83, + 1, 0 +}, +{ + 249, 235, 213, 185, 156, 128, 103, 83, 66, 53, 42, 33, 26, 21, 17, 13, 10, 0 - }, - { - 254, 249, 235, 206, 164, 118, 77, 46, +}, +{ + 254, 249, 235, 206, 164, 118, 77, 46, 27, 16, 10, 7, 5, 4, 3, 2, - 1, 0 - }, - { - 255, 253, 249, 239, 220, 191, 156, 119, + 1, 0 +}, +{ + 255, 253, 249, 239, 220, 191, 156, 119, 85, 57, 37, 23, 15, 10, 6, 4, - 2, 0 - }, - { - 255, 253, 251, 246, 237, 223, 203, 179, - 152, 124, 98, 75, 55, 40, 29, 21, + 2, 0 +}, +{ + 255, 253, 251, 246, 237, 223, 203, 179, + 152, 124, 98, 75, 55, 40, 29, 21, 15, 0 - }, - { - 255, 254, 253, 247, 220, 162, 106, 67, +}, +{ + 255, 254, 253, 247, 220, 162, 106, 67, 42, 28, 18, 12, 9, 6, 4, 3, - 2, 0 - } + 2, 0 +} }; const opus_uint8 silk_pulses_per_block_BITS_Q5[ 9 ][ 18 ] = { - { +{ 31, 57, 107, 160, 205, 205, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255 - }, - { + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255 +}, +{ 69, 47, 67, 111, 166, 205, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255 - }, - { + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255 +}, +{ 82, 74, 79, 95, 109, 128, 145, 160, - 173, 205, 205, 205, 224, 255, 255, 224, - 255, 224 - }, - { - 125, 74, 59, 69, 97, 141, 182, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255 - }, - { - 173, 115, 85, 73, 76, 92, 115, 145, - 173, 205, 224, 224, 255, 255, 255, 255, - 255, 255 - }, - { - 166, 134, 113, 102, 101, 102, 107, 118, - 125, 138, 145, 155, 166, 182, 192, 192, - 205, 150 - }, - { - 224, 182, 134, 101, 83, 79, 85, 97, - 120, 145, 173, 205, 224, 255, 255, 255, - 255, 255 - }, - { - 255, 224, 192, 150, 120, 101, 92, 89, + 173, 205, 205, 205, 224, 255, 255, 224, + 255, 224 +}, +{ + 125, 74, 59, 69, 97, 141, 182, 255, + 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255 +}, +{ + 173, 115, 85, 73, 76, 92, 115, 145, + 173, 205, 224, 224, 255, 255, 255, 255, + 255, 255 +}, +{ + 166, 134, 113, 102, 101, 102, 107, 118, + 125, 138, 145, 155, 166, 182, 192, 192, + 205, 150 +}, +{ + 224, 182, 134, 101, 83, 79, 85, 97, + 120, 145, 173, 205, 224, 255, 255, 255, + 255, 255 +}, +{ + 255, 224, 192, 150, 120, 101, 92, 89, 93, 102, 118, 134, 160, 182, 192, 224, - 224, 224 - }, - { - 255, 224, 224, 182, 155, 134, 118, 109, - 104, 102, 106, 111, 118, 131, 145, 160, - 173, 131 - } + 224, 224 +}, +{ + 255, 224, 224, 182, 155, 134, 118, 109, + 104, 102, 106, 111, 118, 131, 145, 160, + 173, 131 +} }; -const opus_uint8 silk_rate_levels_iCDF[ 2 ][ 9 ] = { - { - 241, 190, 178, 132, 87, 74, 41, 14, - 0 - }, - { - 223, 193, 157, 140, 106, 57, 39, 18, - 0 - } +const opus_uint8 silk_rate_levels_iCDF[ 2 ][ 9 ] = +{ +{ + 241, 190, 178, 132, 87, 74, 41, 14, + 0 +}, +{ + 223, 193, 157, 140, 106, 57, 39, 18, + 0 +} }; -const opus_uint8 silk_rate_levels_BITS_Q5[ 2 ][ 9 ] = { - { - 131, 74, 141, 79, 80, 138, 95, 104, - 134 - }, - { +const opus_uint8 silk_rate_levels_BITS_Q5[ 2 ][ 9 ] = +{ +{ + 131, 74, 141, 79, 80, 138, 95, 104, + 134 +}, +{ 95, 99, 91, 125, 93, 76, 123, 115, - 123 - } + 123 +} }; const opus_uint8 silk_shell_code_table0[ 152 ] = { - 128, 0, 214, 42, 0, 235, 128, 21, - 0, 244, 184, 72, 11, 0, 248, 214, - 128, 42, 7, 0, 248, 225, 170, 80, - 25, 5, 0, 251, 236, 198, 126, 54, - 18, 3, 0, 250, 238, 211, 159, 82, - 35, 15, 5, 0, 250, 231, 203, 168, - 128, 88, 53, 25, 6, 0, 252, 238, - 216, 185, 148, 108, 71, 40, 18, 4, - 0, 253, 243, 225, 199, 166, 128, 90, - 57, 31, 13, 3, 0, 254, 246, 233, - 212, 183, 147, 109, 73, 44, 23, 10, - 2, 0, 255, 250, 240, 223, 198, 166, - 128, 90, 58, 33, 16, 6, 1, 0, - 255, 251, 244, 231, 210, 181, 146, 110, - 75, 46, 25, 12, 5, 1, 0, 255, - 253, 248, 238, 221, 196, 164, 128, 92, - 60, 35, 18, 8, 3, 1, 0, 255, - 253, 249, 242, 229, 208, 180, 146, 110, - 76, 48, 27, 14, 7, 3, 1, 0 + 128, 0, 214, 42, 0, 235, 128, 21, + 0, 244, 184, 72, 11, 0, 248, 214, + 128, 42, 7, 0, 248, 225, 170, 80, + 25, 5, 0, 251, 236, 198, 126, 54, + 18, 3, 0, 250, 238, 211, 159, 82, + 35, 15, 5, 0, 250, 231, 203, 168, + 128, 88, 53, 25, 6, 0, 252, 238, + 216, 185, 148, 108, 71, 40, 18, 4, + 0, 253, 243, 225, 199, 166, 128, 90, + 57, 31, 13, 3, 0, 254, 246, 233, + 212, 183, 147, 109, 73, 44, 23, 10, + 2, 0, 255, 250, 240, 223, 198, 166, + 128, 90, 58, 33, 16, 6, 1, 0, + 255, 251, 244, 231, 210, 181, 146, 110, + 75, 46, 25, 12, 5, 1, 0, 255, + 253, 248, 238, 221, 196, 164, 128, 92, + 60, 35, 18, 8, 3, 1, 0, 255, + 253, 249, 242, 229, 208, 180, 146, 110, + 76, 48, 27, 14, 7, 3, 1, 0 }; const opus_uint8 silk_shell_code_table1[ 152 ] = { - 129, 0, 207, 50, 0, 236, 129, 20, - 0, 245, 185, 72, 10, 0, 249, 213, - 129, 42, 6, 0, 250, 226, 169, 87, - 27, 4, 0, 251, 233, 194, 130, 62, - 20, 4, 0, 250, 236, 207, 160, 99, - 47, 17, 3, 0, 255, 240, 217, 182, - 131, 81, 41, 11, 1, 0, 255, 254, - 233, 201, 159, 107, 61, 20, 2, 1, - 0, 255, 249, 233, 206, 170, 128, 86, - 50, 23, 7, 1, 0, 255, 250, 238, - 217, 186, 148, 108, 70, 39, 18, 6, - 1, 0, 255, 252, 243, 226, 200, 166, - 128, 90, 56, 30, 13, 4, 1, 0, - 255, 252, 245, 231, 209, 180, 146, 110, - 76, 47, 25, 11, 4, 1, 0, 255, - 253, 248, 237, 219, 194, 163, 128, 93, - 62, 37, 19, 8, 3, 1, 0, 255, - 254, 250, 241, 226, 205, 177, 145, 111, - 79, 51, 30, 15, 6, 2, 1, 0 + 129, 0, 207, 50, 0, 236, 129, 20, + 0, 245, 185, 72, 10, 0, 249, 213, + 129, 42, 6, 0, 250, 226, 169, 87, + 27, 4, 0, 251, 233, 194, 130, 62, + 20, 4, 0, 250, 236, 207, 160, 99, + 47, 17, 3, 0, 255, 240, 217, 182, + 131, 81, 41, 11, 1, 0, 255, 254, + 233, 201, 159, 107, 61, 20, 2, 1, + 0, 255, 249, 233, 206, 170, 128, 86, + 50, 23, 7, 1, 0, 255, 250, 238, + 217, 186, 148, 108, 70, 39, 18, 6, + 1, 0, 255, 252, 243, 226, 200, 166, + 128, 90, 56, 30, 13, 4, 1, 0, + 255, 252, 245, 231, 209, 180, 146, 110, + 76, 47, 25, 11, 4, 1, 0, 255, + 253, 248, 237, 219, 194, 163, 128, 93, + 62, 37, 19, 8, 3, 1, 0, 255, + 254, 250, 241, 226, 205, 177, 145, 111, + 79, 51, 30, 15, 6, 2, 1, 0 }; const opus_uint8 silk_shell_code_table2[ 152 ] = { - 129, 0, 203, 54, 0, 234, 129, 23, - 0, 245, 184, 73, 10, 0, 250, 215, - 129, 41, 5, 0, 252, 232, 173, 86, - 24, 3, 0, 253, 240, 200, 129, 56, - 15, 2, 0, 253, 244, 217, 164, 94, - 38, 10, 1, 0, 253, 245, 226, 189, - 132, 71, 27, 7, 1, 0, 253, 246, - 231, 203, 159, 105, 56, 23, 6, 1, - 0, 255, 248, 235, 213, 179, 133, 85, - 47, 19, 5, 1, 0, 255, 254, 243, - 221, 194, 159, 117, 70, 37, 12, 2, - 1, 0, 255, 254, 248, 234, 208, 171, - 128, 85, 48, 22, 8, 2, 1, 0, - 255, 254, 250, 240, 220, 189, 149, 107, - 67, 36, 16, 6, 2, 1, 0, 255, - 254, 251, 243, 227, 201, 166, 128, 90, - 55, 29, 13, 5, 2, 1, 0, 255, - 254, 252, 246, 234, 213, 183, 147, 109, - 73, 43, 22, 10, 4, 2, 1, 0 + 129, 0, 203, 54, 0, 234, 129, 23, + 0, 245, 184, 73, 10, 0, 250, 215, + 129, 41, 5, 0, 252, 232, 173, 86, + 24, 3, 0, 253, 240, 200, 129, 56, + 15, 2, 0, 253, 244, 217, 164, 94, + 38, 10, 1, 0, 253, 245, 226, 189, + 132, 71, 27, 7, 1, 0, 253, 246, + 231, 203, 159, 105, 56, 23, 6, 1, + 0, 255, 248, 235, 213, 179, 133, 85, + 47, 19, 5, 1, 0, 255, 254, 243, + 221, 194, 159, 117, 70, 37, 12, 2, + 1, 0, 255, 254, 248, 234, 208, 171, + 128, 85, 48, 22, 8, 2, 1, 0, + 255, 254, 250, 240, 220, 189, 149, 107, + 67, 36, 16, 6, 2, 1, 0, 255, + 254, 251, 243, 227, 201, 166, 128, 90, + 55, 29, 13, 5, 2, 1, 0, 255, + 254, 252, 246, 234, 213, 183, 147, 109, + 73, 43, 22, 10, 4, 2, 1, 0 }; const opus_uint8 silk_shell_code_table3[ 152 ] = { - 130, 0, 200, 58, 0, 231, 130, 26, - 0, 244, 184, 76, 12, 0, 249, 214, - 130, 43, 6, 0, 252, 232, 173, 87, - 24, 3, 0, 253, 241, 203, 131, 56, - 14, 2, 0, 254, 246, 221, 167, 94, - 35, 8, 1, 0, 254, 249, 232, 193, - 130, 65, 23, 5, 1, 0, 255, 251, - 239, 211, 162, 99, 45, 15, 4, 1, - 0, 255, 251, 243, 223, 186, 131, 74, - 33, 11, 3, 1, 0, 255, 252, 245, - 230, 202, 158, 105, 57, 24, 8, 2, - 1, 0, 255, 253, 247, 235, 214, 179, - 132, 84, 44, 19, 7, 2, 1, 0, - 255, 254, 250, 240, 223, 196, 159, 112, - 69, 36, 15, 6, 2, 1, 0, 255, - 254, 253, 245, 231, 209, 176, 136, 93, - 55, 27, 11, 3, 2, 1, 0, 255, - 254, 253, 252, 239, 221, 194, 158, 117, - 76, 42, 18, 4, 3, 2, 1, 0 + 130, 0, 200, 58, 0, 231, 130, 26, + 0, 244, 184, 76, 12, 0, 249, 214, + 130, 43, 6, 0, 252, 232, 173, 87, + 24, 3, 0, 253, 241, 203, 131, 56, + 14, 2, 0, 254, 246, 221, 167, 94, + 35, 8, 1, 0, 254, 249, 232, 193, + 130, 65, 23, 5, 1, 0, 255, 251, + 239, 211, 162, 99, 45, 15, 4, 1, + 0, 255, 251, 243, 223, 186, 131, 74, + 33, 11, 3, 1, 0, 255, 252, 245, + 230, 202, 158, 105, 57, 24, 8, 2, + 1, 0, 255, 253, 247, 235, 214, 179, + 132, 84, 44, 19, 7, 2, 1, 0, + 255, 254, 250, 240, 223, 196, 159, 112, + 69, 36, 15, 6, 2, 1, 0, 255, + 254, 253, 245, 231, 209, 176, 136, 93, + 55, 27, 11, 3, 2, 1, 0, 255, + 254, 253, 252, 239, 221, 194, 158, 117, + 76, 42, 18, 4, 3, 2, 1, 0 }; const opus_uint8 silk_shell_code_table_offsets[ 17 ] = { - 0, 0, 2, 5, 9, 14, 20, 27, - 35, 44, 54, 65, 77, 90, 104, 119, - 135 + 0, 0, 2, 5, 9, 14, 20, 27, + 35, 44, 54, 65, 77, 90, 104, 119, + 135 }; const opus_uint8 silk_sign_iCDF[ 42 ] = { - 254, 49, 67, 77, 82, 93, 99, - 198, 11, 18, 24, 31, 36, 45, - 255, 46, 66, 78, 87, 94, 104, - 208, 14, 21, 32, 42, 51, 66, - 255, 94, 104, 109, 112, 115, 118, - 248, 53, 69, 80, 88, 95, 102 + 254, 49, 67, 77, 82, 93, 99, + 198, 11, 18, 24, 31, 36, 45, + 255, 46, 66, 78, 87, 94, 104, + 208, 14, 21, 32, 42, 51, 66, + 255, 94, 104, 109, 112, 115, 118, + 248, 53, 69, 80, 88, 95, 102 }; diff --git a/src/libopus/silk/tuning_parameters.h b/src/libopus/silk/tuning_parameters.h index e884478..d70275f 100644 --- a/src/libopus/silk/tuning_parameters.h +++ b/src/libopus/silk/tuning_parameters.h @@ -1,28 +1,28 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_TUNING_PARAMETERS_H diff --git a/src/libopus/silk/typedef.h b/src/libopus/silk/typedef.h index 32773d5..793d2c0 100644 --- a/src/libopus/silk/typedef.h +++ b/src/libopus/silk/typedef.h @@ -1,35 +1,35 @@ /*********************************************************************** - Copyright (c) 2006-2011, Skype Limited. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Internet Society, IETF or IETF Trust, nor the - names of specific contributors, may be used to endorse or promote - products derived from this software without specific prior written - permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2011, Skype Limited. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #ifndef SILK_TYPEDEF_H #define SILK_TYPEDEF_H -#include "../opus_types.h" -#include "../opus_defines.h" +#include "opus_types.h" +#include "opus_defines.h" #ifndef FIXED_POINT # include @@ -64,9 +64,13 @@ #ifdef __GNUC__ __attribute__((noreturn)) #endif -static OPUS_INLINE void _silk_fatal(const char *str, const char *file, int line) { - fprintf(stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); - abort(); +static OPUS_INLINE void _silk_fatal(const char *str, const char *file, int line) +{ + fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); +#if defined(_MSC_VER) + _set_abort_behavior( 0, _WRITE_ABORT_MSG); +#endif + abort(); } # define silk_assert(COND) {if (!(COND)) {silk_fatal("assertion failed: " #COND);}} # else diff --git a/src/libopus/src/API.h b/src/libopus/src/API.h new file mode 100644 index 0000000..55ab447 --- /dev/null +++ b/src/libopus/src/API.h @@ -0,0 +1 @@ +#include "../silk/API.h" diff --git a/src/libopus/src/arch.h b/src/libopus/src/arch.h new file mode 100644 index 0000000..0530293 --- /dev/null +++ b/src/libopus/src/arch.h @@ -0,0 +1 @@ +#include "../celt/arch.h" diff --git a/src/libopus/src/celt.h b/src/libopus/src/celt.h new file mode 100644 index 0000000..f66c3ba --- /dev/null +++ b/src/libopus/src/celt.h @@ -0,0 +1 @@ +#include "../celt/celt.h" diff --git a/src/libopus/src/config.h b/src/libopus/src/config.h new file mode 100644 index 0000000..2989b6b --- /dev/null +++ b/src/libopus/src/config.h @@ -0,0 +1 @@ +#include "../include/config.h" diff --git a/src/libopus/src/cpu_support.h b/src/libopus/src/cpu_support.h new file mode 100644 index 0000000..32e7df2 --- /dev/null +++ b/src/libopus/src/cpu_support.h @@ -0,0 +1 @@ +#include "../celt/cpu_support.h" diff --git a/src/libopus/src/define.h b/src/libopus/src/define.h new file mode 100644 index 0000000..3a4554e --- /dev/null +++ b/src/libopus/src/define.h @@ -0,0 +1 @@ +#include "../silk/define.h" diff --git a/src/libopus/src/entdec.h b/src/libopus/src/entdec.h new file mode 100644 index 0000000..07f6c03 --- /dev/null +++ b/src/libopus/src/entdec.h @@ -0,0 +1 @@ +#include "../celt/entdec.h" diff --git a/src/libopus/src/float_cast.h b/src/libopus/src/float_cast.h new file mode 100644 index 0000000..84ec934 --- /dev/null +++ b/src/libopus/src/float_cast.h @@ -0,0 +1 @@ +#include "../celt/float_cast.h" diff --git a/src/libopus/src/mathops.h b/src/libopus/src/mathops.h new file mode 100644 index 0000000..f4dee75 --- /dev/null +++ b/src/libopus/src/mathops.h @@ -0,0 +1 @@ +#include "../celt/mathops.h" diff --git a/src/libopus/src/modes.h b/src/libopus/src/modes.h new file mode 100644 index 0000000..5623259 --- /dev/null +++ b/src/libopus/src/modes.h @@ -0,0 +1 @@ +#include "../celt/modes.h" diff --git a/src/libopus/src/opus.c b/src/libopus/src/opus.c new file mode 100644 index 0000000..c08de75 --- /dev/null +++ b/src/libopus/src/opus.c @@ -0,0 +1,362 @@ +/* Copyright (c) 2011 Xiph.Org Foundation, Skype Limited + Written by Jean-Marc Valin and Koen Vos */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef __STDC__ +#include "config.h" +#endif + +#include "opus.h" +#include "opus_private.h" + +#ifndef DISABLE_FLOAT_API +OPUS_EXPORT void opus_pcm_soft_clip(float *_x, int N, int C, float *declip_mem) +{ + int c; + int i; + float *x; + + if (C<1 || N<1 || !_x || !declip_mem) return; + + /* First thing: saturate everything to +/- 2 which is the highest level our + non-linearity can handle. At the point where the signal reaches +/-2, + the derivative will be zero anyway, so this doesn't introduce any + discontinuity in the derivative. */ + for (i=0;i=0) + break; + x[i*C] = x[i*C]+a*x[i*C]*x[i*C]; + } + + curr=0; + x0 = x[0]; + while(1) + { + int start, end; + float maxval; + int special=0; + int peak_pos; + for (i=curr;i1 || x[i*C]<-1) + break; + } + if (i==N) + { + a=0; + break; + } + peak_pos = i; + start=end=i; + maxval=ABS16(x[i*C]); + /* Look for first zero crossing before clipping */ + while (start>0 && x[i*C]*x[(start-1)*C]>=0) + start--; + /* Look for first zero crossing after clipping */ + while (end=0) + { + /* Look for other peaks until the next zero-crossing. */ + if (ABS16(x[end*C])>maxval) + { + maxval = ABS16(x[end*C]); + peak_pos = end; + } + end++; + } + /* Detect the special case where we clip before the first zero crossing */ + special = (start==0 && x[i*C]*x[0]>=0); + + /* Compute a such that maxval + a*maxval^2 = 1 */ + a=(maxval-1)/(maxval*maxval); + /* Slightly boost "a" by 2^-22. This is just enough to ensure -ffast-math + does not cause output values larger than +/-1, but small enough not + to matter even for 24-bit output. */ + a += a*2.4e-7f; + if (x[i*C]>0) + a = -a; + /* Apply soft clipping */ + for (i=start;i=2) + { + /* Add a linear ramp from the first sample to the signal peak. + This avoids a discontinuity at the beginning of the frame. */ + float delta; + float offset = x0-x[0]; + delta = offset / peak_pos; + for (i=curr;i>2; + return 2; + } +} + +static int parse_size(const unsigned char *data, opus_int32 len, opus_int16 *size) +{ + if (len<1) + { + *size = -1; + return -1; + } else if (data[0]<252) + { + *size = data[0]; + return 1; + } else if (len<2) + { + *size = -1; + return -1; + } else { + *size = 4*data[1] + data[0]; + return 2; + } +} + +int opus_packet_get_samples_per_frame(const unsigned char *data, + opus_int32 Fs) +{ + int audiosize; + if (data[0]&0x80) + { + audiosize = ((data[0]>>3)&0x3); + audiosize = (Fs<>3)&0x3); + if (audiosize == 3) + audiosize = Fs*60/1000; + else + audiosize = (Fs< len) + return OPUS_INVALID_PACKET; + data += bytes; + last_size = len-size[0]; + break; + /* Multiple CBR/VBR frames (from 0 to 120 ms) */ + default: /*case 3:*/ + if (len<1) + return OPUS_INVALID_PACKET; + /* Number of frames encoded in bits 0 to 5 */ + ch = *data++; + count = ch&0x3F; + if (count <= 0 || framesize*(opus_int32)count > 5760) + return OPUS_INVALID_PACKET; + len--; + /* Padding flag is bit 6 */ + if (ch&0x40) + { + int p; + do { + int tmp; + if (len<=0) + return OPUS_INVALID_PACKET; + p = *data++; + len--; + tmp = p==255 ? 254: p; + len -= tmp; + pad += tmp; + } while (p==255); + } + if (len<0) + return OPUS_INVALID_PACKET; + /* VBR flag is bit 7 */ + cbr = !(ch&0x80); + if (!cbr) + { + /* VBR case */ + last_size = len; + for (i=0;i len) + return OPUS_INVALID_PACKET; + data += bytes; + last_size -= bytes+size[i]; + } + if (last_size<0) + return OPUS_INVALID_PACKET; + } else if (!self_delimited) + { + /* CBR case */ + last_size = len/count; + if (last_size*count!=len) + return OPUS_INVALID_PACKET; + for (i=0;i len) + return OPUS_INVALID_PACKET; + data += bytes; + /* For CBR packets, apply the size to all the frames. */ + if (cbr) + { + if (size[count-1]*count > len) + return OPUS_INVALID_PACKET; + for (i=0;i last_size) + return OPUS_INVALID_PACKET; + } else + { + /* Because it's not encoded explicitly, it's possible the size of the + last packet (or all the packets, for the CBR case) is larger than + 1275. Reject them here.*/ + if (last_size > 1275) + return OPUS_INVALID_PACKET; + size[count-1] = (opus_int16)last_size; + } + + if (payload_offset) + *payload_offset = (int)(data-data0); + + for (i=0;i= 2) && !defined(__OPTIMIZE__) && !defined(OPUS_WILL_BE_SLOW) +# pragma message "You appear to be compiling without optimization, if so opus will be very slow." +#endif + +#include +#include "celt.h" +#include "opus.h" +#include "entdec.h" +#include "modes.h" +#include "API.h" +#include "stack_alloc.h" +#include "float_cast.h" +#include "opus_private.h" +#include "os_support.h" +#include "structs.h" +#include "define.h" +#include "mathops.h" +#include "cpu_support.h" + +#ifdef ENABLE_DEEP_PLC +#include "dred_rdovae_dec_data.h" +#include "dred_rdovae_dec.h" +#endif + +#ifdef ENABLE_OSCE +#include "osce.h" +#endif + +struct OpusDecoder { + int celt_dec_offset; + int silk_dec_offset; + int channels; + opus_int32 Fs; /** Sampling rate (at the API level) */ + silk_DecControlStruct DecControl; + int decode_gain; + int complexity; + int arch; +#ifdef ENABLE_DEEP_PLC + LPCNetPLCState lpcnet; +#endif + + /* Everything beyond this point gets cleared on a reset */ +#define OPUS_DECODER_RESET_START stream_channels + int stream_channels; + + int bandwidth; + int mode; + int prev_mode; + int frame_size; + int prev_redundancy; + int last_packet_duration; +#ifndef FIXED_POINT + opus_val16 softclip_mem[2]; +#endif + + opus_uint32 rangeFinal; +}; + +#if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS) +static void validate_opus_decoder(OpusDecoder *st) +{ + celt_assert(st->channels == 1 || st->channels == 2); + celt_assert(st->Fs == 48000 || st->Fs == 24000 || st->Fs == 16000 || st->Fs == 12000 || st->Fs == 8000); + celt_assert(st->DecControl.API_sampleRate == st->Fs); + celt_assert(st->DecControl.internalSampleRate == 0 || st->DecControl.internalSampleRate == 16000 || st->DecControl.internalSampleRate == 12000 || st->DecControl.internalSampleRate == 8000); + celt_assert(st->DecControl.nChannelsAPI == st->channels); + celt_assert(st->DecControl.nChannelsInternal == 0 || st->DecControl.nChannelsInternal == 1 || st->DecControl.nChannelsInternal == 2); + celt_assert(st->DecControl.payloadSize_ms == 0 || st->DecControl.payloadSize_ms == 10 || st->DecControl.payloadSize_ms == 20 || st->DecControl.payloadSize_ms == 40 || st->DecControl.payloadSize_ms == 60); +#ifdef OPUS_ARCHMASK + celt_assert(st->arch >= 0); + celt_assert(st->arch <= OPUS_ARCHMASK); +#endif + celt_assert(st->stream_channels == 1 || st->stream_channels == 2); +} +#define VALIDATE_OPUS_DECODER(st) validate_opus_decoder(st) +#else +#define VALIDATE_OPUS_DECODER(st) +#endif + +int opus_decoder_get_size(int channels) +{ + int silkDecSizeBytes, celtDecSizeBytes; + int ret; + if (channels<1 || channels > 2) + return 0; + ret = silk_Get_Decoder_Size( &silkDecSizeBytes ); + if(ret) + return 0; + silkDecSizeBytes = align(silkDecSizeBytes); + celtDecSizeBytes = celt_decoder_get_size(channels); + return align(sizeof(OpusDecoder))+silkDecSizeBytes+celtDecSizeBytes; +} + +int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) +{ + void *silk_dec; + CELTDecoder *celt_dec; + int ret, silkDecSizeBytes; + + if ((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000) + || (channels!=1&&channels!=2)) + return OPUS_BAD_ARG; + + OPUS_CLEAR((char*)st, opus_decoder_get_size(channels)); + /* Initialize SILK decoder */ + ret = silk_Get_Decoder_Size(&silkDecSizeBytes); + if (ret) + return OPUS_INTERNAL_ERROR; + + silkDecSizeBytes = align(silkDecSizeBytes); + st->silk_dec_offset = align(sizeof(OpusDecoder)); + st->celt_dec_offset = st->silk_dec_offset+silkDecSizeBytes; + silk_dec = (char*)st+st->silk_dec_offset; + celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset); + st->stream_channels = st->channels = channels; + st->complexity = 0; + + st->Fs = Fs; + st->DecControl.API_sampleRate = st->Fs; + st->DecControl.nChannelsAPI = st->channels; + + /* Reset decoder */ + ret = silk_InitDecoder( silk_dec ); + if(ret)return OPUS_INTERNAL_ERROR; + + /* Initialize CELT decoder */ + ret = celt_decoder_init(celt_dec, Fs, channels); + if(ret!=OPUS_OK)return OPUS_INTERNAL_ERROR; + + celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0)); + + st->prev_mode = 0; + st->frame_size = Fs/400; +#ifdef ENABLE_DEEP_PLC + lpcnet_plc_init( &st->lpcnet); +#endif + st->arch = opus_select_arch(); + return OPUS_OK; +} + +OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error) +{ + int ret; + OpusDecoder *st; + if ((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000) + || (channels!=1&&channels!=2)) + { + if (error) + *error = OPUS_BAD_ARG; + return NULL; + } + st = (OpusDecoder *)opus_alloc(opus_decoder_get_size(channels)); + if (st == NULL) + { + if (error) + *error = OPUS_ALLOC_FAIL; + return NULL; + } + ret = opus_decoder_init(st, Fs, channels); + if (error) + *error = ret; + if (ret != OPUS_OK) + { + opus_free(st); + st = NULL; + } + return st; +} + +static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2, + opus_val16 *out, int overlap, int channels, + const opus_val16 *window, opus_int32 Fs) +{ + int i, c; + int inc = 48000/Fs; + for (c=0;csilk_dec_offset; + celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset); + F20 = st->Fs/50; + F10 = F20>>1; + F5 = F10>>1; + F2_5 = F5>>1; + if (frame_size < F2_5) + { + RESTORE_STACK; + return OPUS_BUFFER_TOO_SMALL; + } + /* Limit frame_size to avoid excessive stack allocations. */ + frame_size = IMIN(frame_size, st->Fs/25*3); + /* Payloads of 1 (2 including ToC) or 0 trigger the PLC/DTX */ + if (len<=1) + { + data = NULL; + /* In that case, don't conceal more than what the ToC says */ + frame_size = IMIN(frame_size, st->frame_size); + } + if (data != NULL) + { + audiosize = st->frame_size; + mode = st->mode; + bandwidth = st->bandwidth; + ec_dec_init(&dec,(unsigned char*)data,len); + } else { + audiosize = frame_size; + /* Run PLC using last used mode (CELT if we ended with CELT redundancy) */ + mode = st->prev_redundancy ? MODE_CELT_ONLY : st->prev_mode; + bandwidth = 0; + + if (mode == 0) + { + /* If we haven't got any packet yet, all we can do is return zeros */ + for (i=0;ichannels;i++) + pcm[i] = 0; + RESTORE_STACK; + return audiosize; + } + + /* Avoids trying to run the PLC on sizes other than 2.5 (CELT), 5 (CELT), + 10, or 20 (e.g. 12.5 or 30 ms). */ + if (audiosize > F20) + { + do { + int ret = opus_decode_frame(st, NULL, 0, pcm, IMIN(audiosize, F20), 0); + if (ret<0) + { + RESTORE_STACK; + return ret; + } + pcm += ret*st->channels; + audiosize -= ret; + } while (audiosize > 0); + RESTORE_STACK; + return frame_size; + } else if (audiosize < F20) + { + if (audiosize > F10) + audiosize = F10; + else if (mode != MODE_SILK_ONLY && audiosize > F5 && audiosize < F10) + audiosize = F5; + } + } + + /* In fixed-point, we can tell CELT to do the accumulation on top of the + SILK PCM buffer. This saves some stack space. */ +#ifdef FIXED_POINT + celt_accum = (mode != MODE_CELT_ONLY) && (frame_size >= F10); +#else + celt_accum = 0; +#endif + + pcm_transition_silk_size = ALLOC_NONE; + pcm_transition_celt_size = ALLOC_NONE; + if (data!=NULL && st->prev_mode > 0 && ( + (mode == MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY && !st->prev_redundancy) + || (mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY) ) + ) + { + transition = 1; + /* Decide where to allocate the stack memory for pcm_transition */ + if (mode == MODE_CELT_ONLY) + pcm_transition_celt_size = F5*st->channels; + else + pcm_transition_silk_size = F5*st->channels; + } + ALLOC(pcm_transition_celt, pcm_transition_celt_size, opus_val16); + if (transition && mode == MODE_CELT_ONLY) + { + pcm_transition = pcm_transition_celt; + opus_decode_frame(st, NULL, 0, pcm_transition, IMIN(F5, audiosize), 0); + } + if (audiosize > frame_size) + { + /*fprintf(stderr, "PCM buffer too small: %d vs %d (mode = %d)\n", audiosize, frame_size, mode);*/ + RESTORE_STACK; + return OPUS_BAD_ARG; + } else { + frame_size = audiosize; + } + + /* Don't allocate any memory when in CELT-only mode */ + pcm_silk_size = (mode != MODE_CELT_ONLY && !celt_accum) ? IMAX(F10, frame_size)*st->channels : ALLOC_NONE; + ALLOC(pcm_silk, pcm_silk_size, opus_int16); + + /* SILK processing */ + if (mode != MODE_CELT_ONLY) + { + int lost_flag, decoded_samples; + opus_int16 *pcm_ptr; +#ifdef FIXED_POINT + if (celt_accum) + pcm_ptr = pcm; + else +#endif + pcm_ptr = pcm_silk; + + if (st->prev_mode==MODE_CELT_ONLY) + silk_ResetDecoder( silk_dec ); + + /* The SILK PLC cannot produce frames of less than 10 ms */ + st->DecControl.payloadSize_ms = IMAX(10, 1000 * audiosize / st->Fs); + + if (data != NULL) + { + st->DecControl.nChannelsInternal = st->stream_channels; + if( mode == MODE_SILK_ONLY ) { + if( bandwidth == OPUS_BANDWIDTH_NARROWBAND ) { + st->DecControl.internalSampleRate = 8000; + } else if( bandwidth == OPUS_BANDWIDTH_MEDIUMBAND ) { + st->DecControl.internalSampleRate = 12000; + } else if( bandwidth == OPUS_BANDWIDTH_WIDEBAND ) { + st->DecControl.internalSampleRate = 16000; + } else { + st->DecControl.internalSampleRate = 16000; + celt_assert( 0 ); + } + } else { + /* Hybrid mode */ + st->DecControl.internalSampleRate = 16000; + } + } + st->DecControl.enable_deep_plc = st->complexity >= 5; +#ifdef ENABLE_OSCE + st->DecControl.osce_method = OSCE_METHOD_NONE; +#ifndef DISABLE_LACE + if (st->complexity >= 6) {st->DecControl.osce_method = OSCE_METHOD_LACE;} +#endif +#ifndef DISABLE_NOLACE + if (st->complexity >= 7) {st->DecControl.osce_method = OSCE_METHOD_NOLACE;} +#endif +#endif + + lost_flag = data == NULL ? 1 : 2 * !!decode_fec; + decoded_samples = 0; + do { + /* Call SILK decoder */ + int first_frame = decoded_samples == 0; + silk_ret = silk_Decode( silk_dec, &st->DecControl, + lost_flag, first_frame, &dec, pcm_ptr, &silk_frame_size, +#ifdef ENABLE_DEEP_PLC + &st->lpcnet, +#endif + st->arch ); + if( silk_ret ) { + if (lost_flag) { + /* PLC failure should not be fatal */ + silk_frame_size = frame_size; + for (i=0;ichannels;i++) + pcm_ptr[i] = 0; + } else { + RESTORE_STACK; + return OPUS_INTERNAL_ERROR; + } + } + pcm_ptr += silk_frame_size * st->channels; + decoded_samples += silk_frame_size; + } while( decoded_samples < frame_size ); + } + + start_band = 0; + if (!decode_fec && mode != MODE_CELT_ONLY && data != NULL + && ec_tell(&dec)+17+20*(mode == MODE_HYBRID) <= 8*len) + { + /* Check if we have a redundant 0-8 kHz band */ + if (mode == MODE_HYBRID) + redundancy = ec_dec_bit_logp(&dec, 12); + else + redundancy = 1; + if (redundancy) + { + celt_to_silk = ec_dec_bit_logp(&dec, 1); + /* redundancy_bytes will be at least two, in the non-hybrid + case due to the ec_tell() check above */ + redundancy_bytes = mode==MODE_HYBRID ? + (opus_int32)ec_dec_uint(&dec, 256)+2 : + len-((ec_tell(&dec)+7)>>3); + len -= redundancy_bytes; + /* This is a sanity check. It should never happen for a valid + packet, so the exact behaviour is not normative. */ + if (len*8 < ec_tell(&dec)) + { + len = 0; + redundancy_bytes = 0; + redundancy = 0; + } + /* Shrink decoder because of raw bits */ + dec.storage -= redundancy_bytes; + } + } + if (mode != MODE_CELT_ONLY) + start_band = 17; + + if (redundancy) + { + transition = 0; + pcm_transition_silk_size=ALLOC_NONE; + } + + ALLOC(pcm_transition_silk, pcm_transition_silk_size, opus_val16); + + if (transition && mode != MODE_CELT_ONLY) + { + pcm_transition = pcm_transition_silk; + opus_decode_frame(st, NULL, 0, pcm_transition, IMIN(F5, audiosize), 0); + } + + + if (bandwidth) + { + int endband=21; + + switch(bandwidth) + { + case OPUS_BANDWIDTH_NARROWBAND: + endband = 13; + break; + case OPUS_BANDWIDTH_MEDIUMBAND: + case OPUS_BANDWIDTH_WIDEBAND: + endband = 17; + break; + case OPUS_BANDWIDTH_SUPERWIDEBAND: + endband = 19; + break; + case OPUS_BANDWIDTH_FULLBAND: + endband = 21; + break; + default: + celt_assert(0); + break; + } + MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_END_BAND(endband))); + } + MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_CHANNELS(st->stream_channels))); + + /* Only allocation memory for redundancy if/when needed */ + redundant_audio_size = redundancy ? F5*st->channels : ALLOC_NONE; + ALLOC(redundant_audio, redundant_audio_size, opus_val16); + + /* 5 ms redundant frame for CELT->SILK*/ + if (redundancy && celt_to_silk) + { + /* If the previous frame did not use CELT (the first redundancy frame in + a transition from SILK may have been lost) then the CELT decoder is + stale at this point and the redundancy audio is not useful, however + the final range is still needed (for testing), so the redundancy is + always decoded but the decoded audio may not be used */ + MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0))); + celt_decode_with_ec(celt_dec, data+len, redundancy_bytes, + redundant_audio, F5, NULL, 0); + MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng))); + } + + /* MUST be after PLC */ + MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(start_band))); + + if (mode != MODE_SILK_ONLY) + { + int celt_frame_size = IMIN(F20, frame_size); + /* Make sure to discard any previous CELT state */ + if (mode != st->prev_mode && st->prev_mode > 0 && !st->prev_redundancy) + MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_RESET_STATE)); + /* Decode CELT */ + celt_ret = celt_decode_with_ec_dred(celt_dec, decode_fec ? NULL : data, + len, pcm, celt_frame_size, &dec, celt_accum +#ifdef ENABLE_DEEP_PLC + , &st->lpcnet +#endif + ); + } else { + unsigned char silence[2] = {0xFF, 0xFF}; + if (!celt_accum) + { + for (i=0;ichannels;i++) + pcm[i] = 0; + } + /* For hybrid -> SILK transitions, we let the CELT MDCT + do a fade-out by decoding a silence frame */ + if (st->prev_mode == MODE_HYBRID && !(redundancy && celt_to_silk && st->prev_redundancy) ) + { + MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0))); + celt_decode_with_ec(celt_dec, silence, 2, pcm, F2_5, NULL, celt_accum); + } + } + + if (mode != MODE_CELT_ONLY && !celt_accum) + { +#ifdef FIXED_POINT + for (i=0;ichannels;i++) + pcm[i] = SAT16(ADD32(pcm[i], pcm_silk[i])); +#else + for (i=0;ichannels;i++) + pcm[i] = pcm[i] + (opus_val16)((1.f/32768.f)*pcm_silk[i]); +#endif + } + + { + const CELTMode *celt_mode; + MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_GET_MODE(&celt_mode))); + window = celt_mode->window; + } + + /* 5 ms redundant frame for SILK->CELT */ + if (redundancy && !celt_to_silk) + { + MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_RESET_STATE)); + MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0))); + + celt_decode_with_ec(celt_dec, data+len, redundancy_bytes, redundant_audio, F5, NULL, 0); + MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng))); + smooth_fade(pcm+st->channels*(frame_size-F2_5), redundant_audio+st->channels*F2_5, + pcm+st->channels*(frame_size-F2_5), F2_5, st->channels, window, st->Fs); + } + /* 5ms redundant frame for CELT->SILK; ignore if the previous frame did not + use CELT (the first redundancy frame in a transition from SILK may have + been lost) */ + if (redundancy && celt_to_silk && (st->prev_mode != MODE_SILK_ONLY || st->prev_redundancy)) + { + for (c=0;cchannels;c++) + { + for (i=0;ichannels*i+c] = redundant_audio[st->channels*i+c]; + } + smooth_fade(redundant_audio+st->channels*F2_5, pcm+st->channels*F2_5, + pcm+st->channels*F2_5, F2_5, st->channels, window, st->Fs); + } + if (transition) + { + if (audiosize >= F5) + { + for (i=0;ichannels*F2_5;i++) + pcm[i] = pcm_transition[i]; + smooth_fade(pcm_transition+st->channels*F2_5, pcm+st->channels*F2_5, + pcm+st->channels*F2_5, F2_5, + st->channels, window, st->Fs); + } else { + /* Not enough time to do a clean transition, but we do it anyway + This will not preserve amplitude perfectly and may introduce + a bit of temporal aliasing, but it shouldn't be too bad and + that's pretty much the best we can do. In any case, generating this + transition it pretty silly in the first place */ + smooth_fade(pcm_transition, pcm, + pcm, F2_5, + st->channels, window, st->Fs); + } + } + + if(st->decode_gain) + { + opus_val32 gain; + gain = celt_exp2(MULT16_16_P15(QCONST16(6.48814081e-4f, 25), st->decode_gain)); + for (i=0;ichannels;i++) + { + opus_val32 x; + x = MULT16_32_P16(pcm[i],gain); + pcm[i] = SATURATE(x, 32767); + } + } + + if (len <= 1) + st->rangeFinal = 0; + else + st->rangeFinal = dec.rng ^ redundant_rng; + + st->prev_mode = mode; + st->prev_redundancy = redundancy && !celt_to_silk; + + if (celt_ret>=0) + { + if (OPUS_CHECK_ARRAY(pcm, audiosize*st->channels)) + OPUS_PRINT_INT(audiosize); + } + + RESTORE_STACK; + return celt_ret < 0 ? celt_ret : audiosize; + +} + +int opus_decode_native(OpusDecoder *st, const unsigned char *data, + opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec, + int self_delimited, opus_int32 *packet_offset, int soft_clip, const OpusDRED *dred, opus_int32 dred_offset) +{ + int i, nb_samples; + int count, offset; + unsigned char toc; + int packet_frame_size, packet_bandwidth, packet_mode, packet_stream_channels; + /* 48 x 2.5 ms = 120 ms */ + opus_int16 size[48]; + VALIDATE_OPUS_DECODER(st); + if (decode_fec<0 || decode_fec>1) + return OPUS_BAD_ARG; + /* For FEC/PLC, frame_size has to be to have a multiple of 2.5 ms */ + if ((decode_fec || len==0 || data==NULL) && frame_size%(st->Fs/400)!=0) + return OPUS_BAD_ARG; +#ifdef ENABLE_DRED + if (dred != NULL && dred->process_stage == 2) { + int F10; + int features_per_frame; + int needed_feature_frames; + int init_frames; + lpcnet_plc_fec_clear(&st->lpcnet); + F10 = st->Fs/100; + /* if blend==0, the last PLC call was "update" and we need to feed two extra 10-ms frames. */ + init_frames = (st->lpcnet.blend == 0) ? 2 : 0; + features_per_frame = IMAX(1, frame_size/F10); + needed_feature_frames = init_frames + features_per_frame; + lpcnet_plc_fec_clear(&st->lpcnet); + for (i=0;idred_offset*F10/4)/F10); + if (feature_offset <= 4*dred->nb_latents-1 && feature_offset >= 0) { + lpcnet_plc_fec_add(&st->lpcnet, dred->fec_features+feature_offset*DRED_NUM_FEATURES); + } else { + if (feature_offset >= 0) lpcnet_plc_fec_add(&st->lpcnet, NULL); + } + + } + } +#else + (void)dred; + (void)dred_offset; +#endif + if (len==0 || data==NULL) + { + int pcm_count=0; + do { + int ret; + ret = opus_decode_frame(st, NULL, 0, pcm+pcm_count*st->channels, frame_size-pcm_count, 0); + if (ret<0) + return ret; + pcm_count += ret; + } while (pcm_count < frame_size); + celt_assert(pcm_count == frame_size); + if (OPUS_CHECK_ARRAY(pcm, pcm_count*st->channels)) + OPUS_PRINT_INT(pcm_count); + st->last_packet_duration = pcm_count; + return pcm_count; + } else if (len<0) + return OPUS_BAD_ARG; + + packet_mode = opus_packet_get_mode(data); + packet_bandwidth = opus_packet_get_bandwidth(data); + packet_frame_size = opus_packet_get_samples_per_frame(data, st->Fs); + packet_stream_channels = opus_packet_get_nb_channels(data); + + count = opus_packet_parse_impl(data, len, self_delimited, &toc, NULL, + size, &offset, packet_offset, NULL, NULL); + if (count<0) + return count; + + data += offset; + + if (decode_fec) + { + int duration_copy; + int ret; + /* If no FEC can be present, run the PLC (recursive call) */ + if (frame_size < packet_frame_size || packet_mode == MODE_CELT_ONLY || st->mode == MODE_CELT_ONLY) + return opus_decode_native(st, NULL, 0, pcm, frame_size, 0, 0, NULL, soft_clip, NULL, 0); + /* Otherwise, run the PLC on everything except the size for which we might have FEC */ + duration_copy = st->last_packet_duration; + if (frame_size-packet_frame_size!=0) + { + ret = opus_decode_native(st, NULL, 0, pcm, frame_size-packet_frame_size, 0, 0, NULL, soft_clip, NULL, 0); + if (ret<0) + { + st->last_packet_duration = duration_copy; + return ret; + } + celt_assert(ret==frame_size-packet_frame_size); + } + /* Complete with FEC */ + st->mode = packet_mode; + st->bandwidth = packet_bandwidth; + st->frame_size = packet_frame_size; + st->stream_channels = packet_stream_channels; + ret = opus_decode_frame(st, data, size[0], pcm+st->channels*(frame_size-packet_frame_size), + packet_frame_size, 1); + if (ret<0) + return ret; + else { + if (OPUS_CHECK_ARRAY(pcm, frame_size*st->channels)) + OPUS_PRINT_INT(frame_size); + st->last_packet_duration = frame_size; + return frame_size; + } + } + + if (count*packet_frame_size > frame_size) + return OPUS_BUFFER_TOO_SMALL; + + /* Update the state as the last step to avoid updating it on an invalid packet */ + st->mode = packet_mode; + st->bandwidth = packet_bandwidth; + st->frame_size = packet_frame_size; + st->stream_channels = packet_stream_channels; + + nb_samples=0; + for (i=0;ichannels, frame_size-nb_samples, 0); + if (ret<0) + return ret; + celt_assert(ret==packet_frame_size); + data += size[i]; + nb_samples += ret; + } + st->last_packet_duration = nb_samples; + if (OPUS_CHECK_ARRAY(pcm, nb_samples*st->channels)) + OPUS_PRINT_INT(nb_samples); +#ifndef FIXED_POINT + if (soft_clip) + opus_pcm_soft_clip(pcm, nb_samples, st->channels, st->softclip_mem); + else + st->softclip_mem[0]=st->softclip_mem[1]=0; +#endif + return nb_samples; +} + +#ifdef FIXED_POINT + +int opus_decode(OpusDecoder *st, const unsigned char *data, + opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec) +{ + if(frame_size<=0) + return OPUS_BAD_ARG; + return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0, NULL, 0); +} + +#ifndef DISABLE_FLOAT_API +int opus_decode_float(OpusDecoder *st, const unsigned char *data, + opus_int32 len, float *pcm, int frame_size, int decode_fec) +{ + VARDECL(opus_int16, out); + int ret, i; + int nb_samples; + ALLOC_STACK; + + if(frame_size<=0) + { + RESTORE_STACK; + return OPUS_BAD_ARG; + } + if (data != NULL && len > 0 && !decode_fec) + { + nb_samples = opus_decoder_get_nb_samples(st, data, len); + if (nb_samples>0) + frame_size = IMIN(frame_size, nb_samples); + else + return OPUS_INVALID_PACKET; + } + celt_assert(st->channels == 1 || st->channels == 2); + ALLOC(out, frame_size*st->channels, opus_int16); + + ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 0, NULL, 0); + if (ret > 0) + { + for (i=0;ichannels;i++) + pcm[i] = (1.f/32768.f)*(out[i]); + } + RESTORE_STACK; + return ret; +} +#endif + + +#else +int opus_decode(OpusDecoder *st, const unsigned char *data, + opus_int32 len, opus_int16 *pcm, int frame_size, int decode_fec) +{ + VARDECL(float, out); + int ret, i; + int nb_samples; + ALLOC_STACK; + + if(frame_size<=0) + { + RESTORE_STACK; + return OPUS_BAD_ARG; + } + + if (data != NULL && len > 0 && !decode_fec) + { + nb_samples = opus_decoder_get_nb_samples(st, data, len); + if (nb_samples>0) + frame_size = IMIN(frame_size, nb_samples); + else + return OPUS_INVALID_PACKET; + } + celt_assert(st->channels == 1 || st->channels == 2); + ALLOC(out, frame_size*st->channels, float); + + ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 1, NULL, 0); + if (ret > 0) + { + for (i=0;ichannels;i++) + pcm[i] = FLOAT2INT16(out[i]); + } + RESTORE_STACK; + return ret; +} + +int opus_decode_float(OpusDecoder *st, const unsigned char *data, + opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec) +{ + if(frame_size<=0) + return OPUS_BAD_ARG; + return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0, NULL, 0); +} + +#endif + +int opus_decoder_ctl(OpusDecoder *st, int request, ...) +{ + int ret = OPUS_OK; + va_list ap; + void *silk_dec; + CELTDecoder *celt_dec; + + silk_dec = (char*)st+st->silk_dec_offset; + celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset); + + + va_start(ap, request); + + switch (request) + { + case OPUS_GET_BANDWIDTH_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->bandwidth; + } + break; + case OPUS_SET_COMPLEXITY_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if(value<0 || value>10) + { + goto bad_arg; + } + st->complexity = value; + celt_decoder_ctl(celt_dec, OPUS_SET_COMPLEXITY(value)); + } + break; + case OPUS_GET_COMPLEXITY_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->complexity; + } + break; + case OPUS_GET_FINAL_RANGE_REQUEST: + { + opus_uint32 *value = va_arg(ap, opus_uint32*); + if (!value) + { + goto bad_arg; + } + *value = st->rangeFinal; + } + break; + case OPUS_RESET_STATE: + { + OPUS_CLEAR((char*)&st->OPUS_DECODER_RESET_START, + sizeof(OpusDecoder)- + ((char*)&st->OPUS_DECODER_RESET_START - (char*)st)); + + celt_decoder_ctl(celt_dec, OPUS_RESET_STATE); + silk_ResetDecoder( silk_dec ); + st->stream_channels = st->channels; + st->frame_size = st->Fs/400; +#ifdef ENABLE_DEEP_PLC + lpcnet_plc_reset( &st->lpcnet ); +#endif + } + break; + case OPUS_GET_SAMPLE_RATE_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->Fs; + } + break; + case OPUS_GET_PITCH_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + if (st->prev_mode == MODE_CELT_ONLY) + ret = celt_decoder_ctl(celt_dec, OPUS_GET_PITCH(value)); + else + *value = st->DecControl.prevPitchLag; + } + break; + case OPUS_GET_GAIN_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->decode_gain; + } + break; + case OPUS_SET_GAIN_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if (value<-32768 || value>32767) + { + goto bad_arg; + } + st->decode_gain = value; + } + break; + case OPUS_GET_LAST_PACKET_DURATION_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + *value = st->last_packet_duration; + } + break; + case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: + { + opus_int32 value = va_arg(ap, opus_int32); + if(value<0 || value>1) + { + goto bad_arg; + } + ret = celt_decoder_ctl(celt_dec, OPUS_SET_PHASE_INVERSION_DISABLED(value)); + } + break; + case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: + { + opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) + { + goto bad_arg; + } + ret = celt_decoder_ctl(celt_dec, OPUS_GET_PHASE_INVERSION_DISABLED(value)); + } + break; +#ifdef USE_WEIGHTS_FILE + case OPUS_SET_DNN_BLOB_REQUEST: + { + const unsigned char *data = va_arg(ap, const unsigned char *); + opus_int32 len = va_arg(ap, opus_int32); + if(len<0 || data == NULL) + { + goto bad_arg; + } + ret = lpcnet_plc_load_model(&st->lpcnet, data, len); + ret = silk_LoadOSCEModels(silk_dec, data, len) || ret; + } + break; +#endif + default: + /*fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);*/ + ret = OPUS_UNIMPLEMENTED; + break; + } + + va_end(ap); + return ret; +bad_arg: + va_end(ap); + return OPUS_BAD_ARG; +} + +void opus_decoder_destroy(OpusDecoder *st) +{ + opus_free(st); +} + + +int opus_packet_get_bandwidth(const unsigned char *data) +{ + int bandwidth; + if (data[0]&0x80) + { + bandwidth = OPUS_BANDWIDTH_MEDIUMBAND + ((data[0]>>5)&0x3); + if (bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) + bandwidth = OPUS_BANDWIDTH_NARROWBAND; + } else if ((data[0]&0x60) == 0x60) + { + bandwidth = (data[0]&0x10) ? OPUS_BANDWIDTH_FULLBAND : + OPUS_BANDWIDTH_SUPERWIDEBAND; + } else { + bandwidth = OPUS_BANDWIDTH_NARROWBAND + ((data[0]>>5)&0x3); + } + return bandwidth; +} + +int opus_packet_get_nb_channels(const unsigned char *data) +{ + return (data[0]&0x4) ? 2 : 1; +} + +int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) +{ + int count; + if (len<1) + return OPUS_BAD_ARG; + count = packet[0]&0x3; + if (count==0) + return 1; + else if (count!=3) + return 2; + else if (len<2) + return OPUS_INVALID_PACKET; + else + return packet[1]&0x3F; +} + +int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, + opus_int32 Fs) +{ + int samples; + int count = opus_packet_get_nb_frames(packet, len); + + if (count<0) + return count; + + samples = count*opus_packet_get_samples_per_frame(packet, Fs); + /* Can't have more than 120 ms */ + if (samples*25 > Fs*3) + return OPUS_INVALID_PACKET; + else + return samples; +} + +int opus_packet_has_lbrr(const unsigned char packet[], opus_int32 len) +{ + int ret; + const unsigned char *frames[48]; + opus_int16 size[48]; + int packet_mode, packet_frame_size, packet_stream_channels; + int nb_frames=1; + int lbrr; + + packet_mode = opus_packet_get_mode(packet); + if (packet_mode == MODE_CELT_ONLY) + return 0; + packet_frame_size = opus_packet_get_samples_per_frame(packet, 48000); + if (packet_frame_size > 960) + nb_frames = packet_frame_size/960; + packet_stream_channels = opus_packet_get_nb_channels(packet); + ret = opus_packet_parse(packet, len, NULL, frames, size, NULL); + if (ret <= 0) + return ret; + lbrr = (frames[0][0] >> (7-nb_frames)) & 0x1; + if (packet_stream_channels == 2) + lbrr = lbrr || ((frames[0][0] >> (6-2*nb_frames)) & 0x1); + return lbrr; +} + +int opus_decoder_get_nb_samples(const OpusDecoder *dec, + const unsigned char packet[], opus_int32 len) +{ + return opus_packet_get_nb_samples(packet, len, dec->Fs); +} + +struct OpusDREDDecoder { +#ifdef ENABLE_DRED + RDOVAEDec model; +#endif + int loaded; + int arch; + opus_uint32 magic; +}; + +#if defined(ENABLE_DRED) && (defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS)) +static void validate_dred_decoder(OpusDREDDecoder *st) +{ + celt_assert(st->magic == 0xD8EDDEC0); +#ifdef OPUS_ARCHMASK + celt_assert(st->arch >= 0); + celt_assert(st->arch <= OPUS_ARCHMASK); +#endif +} +#define VALIDATE_DRED_DECODER(st) validate_dred_decoder(st) +#else +#define VALIDATE_DRED_DECODER(st) +#endif + + +int opus_dred_decoder_get_size(void) +{ + return sizeof(OpusDREDDecoder); +} + +#ifdef ENABLE_DRED +int dred_decoder_load_model(OpusDREDDecoder *dec, const unsigned char *data, int len) +{ + WeightArray *list; + int ret; + parse_weights(&list, data, len); + ret = init_rdovaedec(&dec->model, list); + opus_free(list); + if (ret == 0) dec->loaded = 1; + return (ret == 0) ? OPUS_OK : OPUS_BAD_ARG; +} +#endif + +int opus_dred_decoder_init(OpusDREDDecoder *dec) +{ + int ret = 0; + dec->loaded = 0; +#if defined(ENABLE_DRED) && !defined(USE_WEIGHTS_FILE) + ret = init_rdovaedec(&dec->model, rdovaedec_arrays); + if (ret == 0) dec->loaded = 1; +#endif + dec->arch = opus_select_arch(); + /* To make sure nobody forgets to init, use a magic number. */ + dec->magic = 0xD8EDDEC0; + return (ret == 0) ? OPUS_OK : OPUS_UNIMPLEMENTED; +} + +OpusDREDDecoder *opus_dred_decoder_create(int *error) +{ + int ret; + OpusDREDDecoder *dec; + dec = (OpusDREDDecoder *)opus_alloc(opus_dred_decoder_get_size()); + if (dec == NULL) + { + if (error) + *error = OPUS_ALLOC_FAIL; + return NULL; + } + ret = opus_dred_decoder_init(dec); + if (error) + *error = ret; + if (ret != OPUS_OK) + { + opus_free(dec); + dec = NULL; + } + return dec; +} + +void opus_dred_decoder_destroy(OpusDREDDecoder *dec) +{ + if (dec) dec->magic = 0xDE57801D; + opus_free(dec); +} + +int opus_dred_decoder_ctl(OpusDREDDecoder *dred_dec, int request, ...) +{ +#ifdef ENABLE_DRED + int ret = OPUS_OK; + va_list ap; + + va_start(ap, request); + (void)dred_dec; + switch (request) + { +# ifdef USE_WEIGHTS_FILE + case OPUS_SET_DNN_BLOB_REQUEST: + { + const unsigned char *data = va_arg(ap, const unsigned char *); + opus_int32 len = va_arg(ap, opus_int32); + if(len<0 || data == NULL) + { + goto bad_arg; + } + return dred_decoder_load_model(dred_dec, data, len); + } + break; +# endif + default: + /*fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);*/ + ret = OPUS_UNIMPLEMENTED; + break; + } + va_end(ap); + return ret; +# ifdef USE_WEIGHTS_FILE +bad_arg: + va_end(ap); + return OPUS_BAD_ARG; +# endif +#else + (void)dred_dec; + (void)request; + return OPUS_UNIMPLEMENTED; +#endif +} + +#ifdef ENABLE_DRED +static int dred_find_payload(const unsigned char *data, opus_int32 len, const unsigned char **payload, int *dred_frame_offset) +{ + const unsigned char *data0; + int len0; + int frame = 0; + int ret; + const unsigned char *frames[48]; + opus_int16 size[48]; + int frame_size; + + *payload = NULL; + /* Get the padding section of the packet. */ + ret = opus_packet_parse_impl(data, len, 0, NULL, frames, size, NULL, NULL, &data0, &len0); + if (ret < 0) + return ret; + frame_size = opus_packet_get_samples_per_frame(data, 48000); + data = data0; + len = len0; + /* Scan extensions in order until we find the earliest frame with DRED data. */ + while (len > 0) + { + opus_int32 header_size; + int id, L; + len0 = len; + data0 = data; + id = *data0 >> 1; + L = *data0 & 0x1; + len = skip_extension(&data, len, &header_size); + if (len < 0) + break; + if (id == 1) + { + if (L==0) + { + frame++; + } else { + frame += data0[1]; + } + } else if (id == DRED_EXTENSION_ID) + { + const unsigned char *curr_payload; + opus_int32 curr_payload_len; + curr_payload = data0+header_size; + curr_payload_len = (data-data0)-header_size; + /* DRED position in the packet, in units of 2.5 ms like for the signaled DRED offset. */ + *dred_frame_offset = frame*frame_size/120; +#ifdef DRED_EXPERIMENTAL_VERSION + /* Check that temporary extension type and version match. + This check will be removed once extension is finalized. */ + if (curr_payload_len > DRED_EXPERIMENTAL_BYTES && curr_payload[0] == 'D' && curr_payload[1] == DRED_EXPERIMENTAL_VERSION) { + *payload = curr_payload+2; + return curr_payload_len-2; + } +#else + if (curr_payload_len > 0) { + *payload = curr_payload; + return curr_payload_len; + } +#endif + } + } + return 0; +} +#endif + +int opus_dred_get_size(void) +{ +#ifdef ENABLE_DRED + return sizeof(OpusDRED); +#else + return 0; +#endif +} + +OpusDRED *opus_dred_alloc(int *error) +{ +#ifdef ENABLE_DRED + OpusDRED *dec; + dec = (OpusDRED *)opus_alloc(opus_dred_get_size()); + if (dec == NULL) + { + if (error) + *error = OPUS_ALLOC_FAIL; + return NULL; + } + return dec; +#else + if (error) + *error = OPUS_UNIMPLEMENTED; + return NULL; +#endif +} + +void opus_dred_free(OpusDRED *dec) +{ +#ifdef ENABLE_DRED + opus_free(dec); +#else + (void)dec; +#endif +} + +int opus_dred_parse(OpusDREDDecoder *dred_dec, OpusDRED *dred, const unsigned char *data, opus_int32 len, opus_int32 max_dred_samples, opus_int32 sampling_rate, int *dred_end, int defer_processing) +{ +#ifdef ENABLE_DRED + const unsigned char *payload; + opus_int32 payload_len; + int dred_frame_offset=0; + VALIDATE_DRED_DECODER(dred_dec); + if (!dred_dec->loaded) return OPUS_UNIMPLEMENTED; + dred->process_stage = -1; + payload_len = dred_find_payload(data, len, &payload, &dred_frame_offset); + if (payload_len < 0) + return payload_len; + if (payload != NULL) + { + int offset; + int min_feature_frames; + offset = 100*max_dred_samples/sampling_rate; + min_feature_frames = IMIN(2 + offset, 2*DRED_NUM_REDUNDANCY_FRAMES); + dred_ec_decode(dred, payload, payload_len, min_feature_frames, dred_frame_offset); + if (!defer_processing) + opus_dred_process(dred_dec, dred, dred); + if (dred_end) *dred_end = IMAX(0, -dred->dred_offset*sampling_rate/400); + return IMAX(0, dred->nb_latents*sampling_rate/25 - dred->dred_offset* sampling_rate/400); + } + if (dred_end) *dred_end = 0; + return 0; +#else + (void)dred_dec; + (void)dred; + (void)data; + (void)len; + (void)max_dred_samples; + (void)sampling_rate; + (void)defer_processing; + (void)dred_end; + return OPUS_UNIMPLEMENTED; +#endif +} + +int opus_dred_process(OpusDREDDecoder *dred_dec, const OpusDRED *src, OpusDRED *dst) +{ +#ifdef ENABLE_DRED + if (dred_dec == NULL || src == NULL || dst == NULL || (src->process_stage != 1 && src->process_stage != 2)) + return OPUS_BAD_ARG; + VALIDATE_DRED_DECODER(dred_dec); + if (!dred_dec->loaded) return OPUS_UNIMPLEMENTED; + if (src != dst) + OPUS_COPY(dst, src, 1); + if (dst->process_stage == 2) + return OPUS_OK; + DRED_rdovae_decode_all(&dred_dec->model, dst->fec_features, dst->state, dst->latents, dst->nb_latents, dred_dec->arch); + dst->process_stage = 2; + return OPUS_OK; +#else + (void)dred_dec; + (void)src; + (void)dst; + return OPUS_UNIMPLEMENTED; +#endif +} + +int opus_decoder_dred_decode(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size) +{ +#ifdef ENABLE_DRED + VARDECL(float, out); + int ret, i; + ALLOC_STACK; + + if(frame_size<=0) + { + RESTORE_STACK; + return OPUS_BAD_ARG; + } + + celt_assert(st->channels == 1 || st->channels == 2); + ALLOC(out, frame_size*st->channels, float); + + ret = opus_decode_native(st, NULL, 0, out, frame_size, 0, 0, NULL, 1, dred, dred_offset); + if (ret > 0) + { + for (i=0;ichannels;i++) + pcm[i] = FLOAT2INT16(out[i]); + } + RESTORE_STACK; + return ret; +#else + (void)st; + (void)dred; + (void)dred_offset; + (void)pcm; + (void)frame_size; + return OPUS_UNIMPLEMENTED; +#endif +} + +int opus_decoder_dred_decode_float(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size) +{ +#ifdef ENABLE_DRED + if(frame_size<=0) + return OPUS_BAD_ARG; + return opus_decode_native(st, NULL, 0, pcm, frame_size, 0, 0, NULL, 0, dred, dred_offset); +#else + (void)st; + (void)dred; + (void)dred_offset; + (void)pcm; + (void)frame_size; + return OPUS_UNIMPLEMENTED; +#endif +} diff --git a/src/libopus/src/opus_defines.h b/src/libopus/src/opus_defines.h new file mode 100644 index 0000000..dcc2443 --- /dev/null +++ b/src/libopus/src/opus_defines.h @@ -0,0 +1 @@ +#include "../include/opus_defines.h" diff --git a/src/libopus/src/opus_multistream.h b/src/libopus/src/opus_multistream.h new file mode 100644 index 0000000..89f6229 --- /dev/null +++ b/src/libopus/src/opus_multistream.h @@ -0,0 +1 @@ +#include "../include/opus_multistream.h" diff --git a/src/libopus/src/opus_private.h b/src/libopus/src/opus_private.h new file mode 100644 index 0000000..364c21c --- /dev/null +++ b/src/libopus/src/opus_private.h @@ -0,0 +1,223 @@ +/* Copyright (c) 2012 Xiph.Org Foundation + Written by Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef OPUS_PRIVATE_H +#define OPUS_PRIVATE_H + +#include "arch.h" +#include "opus.h" +#include "celt.h" + +#include /* va_list */ +#include /* offsetof */ + +struct OpusRepacketizer { + unsigned char toc; + int nb_frames; + const unsigned char *frames[48]; + opus_int16 len[48]; + int framesize; + const unsigned char *paddings[48]; + opus_int32 padding_len[48]; +}; + +typedef struct { + int id; + int frame; + const unsigned char *data; + opus_int32 len; +} opus_extension_data; + +typedef struct ChannelLayout { + int nb_channels; + int nb_streams; + int nb_coupled_streams; + unsigned char mapping[256]; +} ChannelLayout; + +typedef enum { + MAPPING_TYPE_NONE, + MAPPING_TYPE_SURROUND, + MAPPING_TYPE_AMBISONICS +} MappingType; + +struct OpusMSEncoder { + ChannelLayout layout; + int arch; + int lfe_stream; + int application; + int variable_duration; + MappingType mapping_type; + opus_int32 bitrate_bps; + /* Encoder states go here */ + /* then opus_val32 window_mem[channels*120]; */ + /* then opus_val32 preemph_mem[channels]; */ +}; + +struct OpusMSDecoder { + ChannelLayout layout; + /* Decoder states go here */ +}; + +int opus_multistream_encoder_ctl_va_list(struct OpusMSEncoder *st, int request, + va_list ap); +int opus_multistream_decoder_ctl_va_list(struct OpusMSDecoder *st, int request, + va_list ap); + +int validate_layout(const ChannelLayout *layout); +int get_left_channel(const ChannelLayout *layout, int stream_id, int prev); +int get_right_channel(const ChannelLayout *layout, int stream_id, int prev); +int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev); + +typedef void (*opus_copy_channel_in_func)( + opus_val16 *dst, + int dst_stride, + const void *src, + int src_stride, + int src_channel, + int frame_size, + void *user_data +); + +typedef void (*opus_copy_channel_out_func)( + void *dst, + int dst_stride, + int dst_channel, + const opus_val16 *src, + int src_stride, + int frame_size, + void *user_data +); + +#define MODE_SILK_ONLY 1000 +#define MODE_HYBRID 1001 +#define MODE_CELT_ONLY 1002 + +#define OPUS_SET_VOICE_RATIO_REQUEST 11018 +#define OPUS_GET_VOICE_RATIO_REQUEST 11019 + +/** Configures the encoder's expected percentage of voice + * opposed to music or other signals. + * + * @note This interface is currently more aspiration than actuality. It's + * ultimately expected to bias an automatic signal classifier, but it currently + * just shifts the static bitrate to mode mapping around a little bit. + * + * @param[in] x int: Voice percentage in the range 0-100, inclusive. + * @hideinitializer */ +#define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO + * + * @param[out] x int*: Voice percentage in the range 0-100, inclusive. + * @hideinitializer */ +#define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x) + + +#define OPUS_SET_FORCE_MODE_REQUEST 11002 +#define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x) + +typedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int); +void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C); +void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C); +int is_digital_silence(const opus_val16* pcm, int frame_size, int channels, int lsb_depth); + +int encode_size(int size, unsigned char *data); + +opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs); + +opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, + unsigned char *data, opus_int32 out_data_bytes, int lsb_depth, + const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, + int analysis_channels, downmix_func downmix, int float_api); + +int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len, + opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited, + opus_int32 *packet_offset, int soft_clip, const OpusDRED *dred, opus_int32 dred_offset); + +/* Make sure everything is properly aligned. */ +static OPUS_INLINE int align(int i) +{ + struct foo {char c; union { void* p; opus_int32 i; opus_val32 v; } u;}; + + unsigned int alignment = offsetof(struct foo, u); + + /* Optimizing compilers should optimize div and multiply into and + for all sensible alignment values. */ + return ((i + alignment - 1) / alignment) * alignment; +} + +/* More than that is ridiculous for now (3 * max frames per packet)*/ +opus_int32 skip_extension(const unsigned char **data, opus_int32 len, opus_int32 *header_size); + +int opus_packet_parse_impl(const unsigned char *data, opus_int32 len, + int self_delimited, unsigned char *out_toc, + const unsigned char *frames[48], opus_int16 size[48], + int *payload_offset, opus_int32 *packet_offset, + const unsigned char **padding, opus_int32 *padding_len); + +opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end, + unsigned char *data, opus_int32 maxlen, int self_delimited, int pad, + const opus_extension_data *extensions, int nb_extensions); + +int pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len); + +int opus_multistream_encode_native +( + struct OpusMSEncoder *st, + opus_copy_channel_in_func copy_channel_in, + const void *pcm, + int analysis_frame_size, + unsigned char *data, + opus_int32 max_data_bytes, + int lsb_depth, + downmix_func downmix, + int float_api, + void *user_data +); + +int opus_multistream_decode_native( + struct OpusMSDecoder *st, + const unsigned char *data, + opus_int32 len, + void *pcm, + opus_copy_channel_out_func copy_channel_out, + int frame_size, + int decode_fec, + int soft_clip, + void *user_data +); + +opus_int32 opus_packet_extensions_parse(const unsigned char *data, opus_int32 len, opus_extension_data *extensions, opus_int32 *nb_extensions); + +opus_int32 opus_packet_extensions_generate(unsigned char *data, opus_int32 len, const opus_extension_data *extensions, int nb_extensions, int pad); + +opus_int32 opus_packet_extensions_count(const unsigned char *data, opus_int32 len); + +opus_int32 opus_packet_pad_impl(unsigned char *data, opus_int32 len, opus_int32 new_len, int pad, const opus_extension_data *extensions, int nb_extensions); + +#endif /* OPUS_PRIVATE_H */ diff --git a/src/libopus/src/opus_projection.h b/src/libopus/src/opus_projection.h new file mode 100644 index 0000000..72f59cc --- /dev/null +++ b/src/libopus/src/opus_projection.h @@ -0,0 +1 @@ +#include "../include/opus_projection.h" diff --git a/src/libopus/src/opus_types.h b/src/libopus/src/opus_types.h new file mode 100644 index 0000000..a7958a5 --- /dev/null +++ b/src/libopus/src/opus_types.h @@ -0,0 +1 @@ +#include "../include/opus_types.h" diff --git a/src/libopus/src/os_support.h b/src/libopus/src/os_support.h new file mode 100644 index 0000000..dc47379 --- /dev/null +++ b/src/libopus/src/os_support.h @@ -0,0 +1 @@ +#include "../celt/os_support.h" diff --git a/src/libopus/src/stack_alloc.h b/src/libopus/src/stack_alloc.h new file mode 100644 index 0000000..416720b --- /dev/null +++ b/src/libopus/src/stack_alloc.h @@ -0,0 +1 @@ +#include "../celt/stack_alloc.h" diff --git a/src/libopus/src/structs.h b/src/libopus/src/structs.h new file mode 100644 index 0000000..336e73b --- /dev/null +++ b/src/libopus/src/structs.h @@ -0,0 +1 @@ +#include "../silk/structs.h" diff --git a/src/libopus/tansig_table.h b/src/libopus/tansig_table.h deleted file mode 100644 index 4261fab..0000000 --- a/src/libopus/tansig_table.h +++ /dev/null @@ -1,45 +0,0 @@ -/* This file is auto-generated by gen_tables */ - -static const float tansig_table[201] = { - 0.000000f, 0.039979f, 0.079830f, 0.119427f, 0.158649f, - 0.197375f, 0.235496f, 0.272905f, 0.309507f, 0.345214f, - 0.379949f, 0.413644f, 0.446244f, 0.477700f, 0.507977f, - 0.537050f, 0.564900f, 0.591519f, 0.616909f, 0.641077f, - 0.664037f, 0.685809f, 0.706419f, 0.725897f, 0.744277f, - 0.761594f, 0.777888f, 0.793199f, 0.807569f, 0.821040f, - 0.833655f, 0.845456f, 0.856485f, 0.866784f, 0.876393f, - 0.885352f, 0.893698f, 0.901468f, 0.908698f, 0.915420f, - 0.921669f, 0.927473f, 0.932862f, 0.937863f, 0.942503f, - 0.946806f, 0.950795f, 0.954492f, 0.957917f, 0.961090f, - 0.964028f, 0.966747f, 0.969265f, 0.971594f, 0.973749f, - 0.975743f, 0.977587f, 0.979293f, 0.980869f, 0.982327f, - 0.983675f, 0.984921f, 0.986072f, 0.987136f, 0.988119f, - 0.989027f, 0.989867f, 0.990642f, 0.991359f, 0.992020f, - 0.992631f, 0.993196f, 0.993718f, 0.994199f, 0.994644f, - 0.995055f, 0.995434f, 0.995784f, 0.996108f, 0.996407f, - 0.996682f, 0.996937f, 0.997172f, 0.997389f, 0.997590f, - 0.997775f, 0.997946f, 0.998104f, 0.998249f, 0.998384f, - 0.998508f, 0.998623f, 0.998728f, 0.998826f, 0.998916f, - 0.999000f, 0.999076f, 0.999147f, 0.999213f, 0.999273f, - 0.999329f, 0.999381f, 0.999428f, 0.999472f, 0.999513f, - 0.999550f, 0.999585f, 0.999617f, 0.999646f, 0.999673f, - 0.999699f, 0.999722f, 0.999743f, 0.999763f, 0.999781f, - 0.999798f, 0.999813f, 0.999828f, 0.999841f, 0.999853f, - 0.999865f, 0.999875f, 0.999885f, 0.999893f, 0.999902f, - 0.999909f, 0.999916f, 0.999923f, 0.999929f, 0.999934f, - 0.999939f, 0.999944f, 0.999948f, 0.999952f, 0.999956f, - 0.999959f, 0.999962f, 0.999965f, 0.999968f, 0.999970f, - 0.999973f, 0.999975f, 0.999977f, 0.999978f, 0.999980f, - 0.999982f, 0.999983f, 0.999984f, 0.999986f, 0.999987f, - 0.999988f, 0.999989f, 0.999990f, 0.999990f, 0.999991f, - 0.999992f, 0.999992f, 0.999993f, 0.999994f, 0.999994f, - 0.999994f, 0.999995f, 0.999995f, 0.999996f, 0.999996f, - 0.999996f, 0.999997f, 0.999997f, 0.999997f, 0.999997f, - 0.999997f, 0.999998f, 0.999998f, 0.999998f, 0.999998f, - 0.999998f, 0.999998f, 0.999999f, 0.999999f, 0.999999f, - 0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f, - 0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f, - 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, - 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, - 1.000000f, -}; diff --git a/src/opusfile/AUTHORS b/src/opusfile/AUTHORS deleted file mode 100644 index d0ac09d..0000000 --- a/src/opusfile/AUTHORS +++ /dev/null @@ -1,5 +0,0 @@ -Timothy B. Terriberry -Ralph Giles -Christopher "Monty" Montgomery (original libvorbisfile) -Gregory Maxwell (noise shaping dithering) -nu774 (original winsock support) diff --git a/src/opusfile/COPYING b/src/opusfile/COPYING deleted file mode 100644 index 7b53d66..0000000 --- a/src/opusfile/COPYING +++ /dev/null @@ -1,28 +0,0 @@ -Copyright (c) 1994-2013 Xiph.Org Foundation and contributors - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -- Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -- Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -- Neither the name of the Xiph.Org Foundation nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/opusfile/README.esp8266.md b/src/opusfile/README.esp8266.md deleted file mode 100644 index 267aa28..0000000 --- a/src/opusfile/README.esp8266.md +++ /dev/null @@ -1,3 +0,0 @@ -This is opusfile from Xiph, modified to build under Arduino by and adjusted to work with AudioFileSources, - -Original license/etc. unchanged. diff --git a/src/opusfile/README.md b/src/opusfile/README.md deleted file mode 100644 index 609cc6b..0000000 --- a/src/opusfile/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Opusfile - -[![GitLab Pipeline Status](https://gitlab.xiph.org/xiph/opusfile/badges/master/pipeline.svg)](https://gitlab.xiph.org/xiph/opusfile/commits/master) -[![Travis Build Status](https://travis-ci.org/xiph/opusfile.svg?branch=master)](https://travis-ci.org/xiph/opusfile) -[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/xiph/opusfile?branch=master&svg=true)](https://ci.appveyor.com/project/rillian/opusfile) - -The opusfile and opusurl libraries provide a high-level API for -decoding and seeking within .opus files on disk or over http(s). - -opusfile depends on libopus and libogg. -opusurl depends on opusfile and openssl. - -The library is functional, but there are likely issues -we didn't find in our own testing. Please give feedback -in #opus on irc.freenode.net or at opus@xiph.org. - -Programming documentation is available in tree and online at -https://opus-codec.org/docs/ diff --git a/src/opusfile/config.h b/src/opusfile/config.h deleted file mode 100644 index cbf0085..0000000 --- a/src/opusfile/config.h +++ /dev/null @@ -1,128 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 0 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 0 - -/* Define to the sub-directory where libtool stores uninstalled libraries. */ -#define LT_OBJDIR ".libs/" - -/* Disable floating-point API */ -#define OP_DISABLE_FLOAT_API 1 - -/* Enable assertions in code */ -/* #undef OP_ENABLE_ASSERTIONS */ - -/* Enable HTTP support */ -/* #undef OP_ENABLE_HTTP */ - -/* Enable fixed-point calculation */ -#define OP_FIXED_POINT 1 - -/* Enable use of clock_gettime function */ -/* #undef OP_HAVE_CLOCK_GETTIME */ - -/* Enable use of lrintf function */ -/* #undef OP_HAVE_LRINTF */ - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "opus@xiph.org" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "opusfile" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "opusfile 0.12" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "opusfile" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "0.12" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define this if the compiler supports __attribute__(( - ifelse([visibility("default")], , [visibility_default], - [visibility("default")]) )) */ -#define SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT 1 - -/* Define this if the compiler supports the -fvisibility flag */ -#define SUPPORT_FLAG_VISIBILITY 1 - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 -#endif - - -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -/* #undef _FILE_OFFSET_BITS */ - -/* Define for large files, on AIX-style hosts. */ -/* #undef _LARGE_FILES */ - -/* Define to 1 if on MINIX. */ -/* #undef _MINIX */ - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* We need at least WindowsXP for getaddrinfo/freeaddrinfo */ -/* #undef _WIN32_WINNT */ diff --git a/src/opusfile/info.c b/src/opusfile/info.c deleted file mode 100644 index 84d292f..0000000 --- a/src/opusfile/info.c +++ /dev/null @@ -1,958 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE libopusfile SOURCE CODE IS (C) COPYRIGHT 2012-2020 - by the Xiph.Org Foundation and contributors https://xiph.org/ - * * - ********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "internal.h" -#include -#include - -static unsigned op_parse_uint16le(const unsigned char *_data) { - return _data[0] | _data[1] << 8; -} - -static int op_parse_int16le(const unsigned char *_data) { - int ret; - ret = _data[0] | _data[1] << 8; - return (ret ^ 0x8000) - 0x8000; -} - -static opus_uint32 op_parse_uint32le(const unsigned char *_data) { - return _data[0] | (opus_uint32)_data[1] << 8 | - (opus_uint32)_data[2] << 16 | (opus_uint32)_data[3] << 24; -} - -static opus_uint32 op_parse_uint32be(const unsigned char *_data) { - return _data[3] | (opus_uint32)_data[2] << 8 | - (opus_uint32)_data[1] << 16 | (opus_uint32)_data[0] << 24; -} - -int opus_head_parse(OpusHead *_head, const unsigned char *_data, size_t _len) { - OpusHead head; - if (_len < 8) { - return OP_ENOTFORMAT; - } - if (memcmp(_data, "OpusHead", 8) != 0) { - return OP_ENOTFORMAT; - } - if (_len < 9) { - return OP_EBADHEADER; - } - head.version = _data[8]; - if (head.version > 15) { - return OP_EVERSION; - } - if (_len < 19) { - return OP_EBADHEADER; - } - head.channel_count = _data[9]; - head.pre_skip = op_parse_uint16le(_data + 10); - head.input_sample_rate = op_parse_uint32le(_data + 12); - head.output_gain = op_parse_int16le(_data + 16); - head.mapping_family = _data[18]; - if (head.mapping_family == 0) { - if (head.channel_count < 1 || head.channel_count > 2) { - return OP_EBADHEADER; - } - if (head.version <= 1 && _len > 19) { - return OP_EBADHEADER; - } - head.stream_count = 1; - head.coupled_count = head.channel_count - 1; - if (_head != NULL) { - _head->mapping[0] = 0; - _head->mapping[1] = 1; - } - } else if (head.mapping_family == 1) { - size_t size; - int ci; - if (head.channel_count < 1 || head.channel_count > 8) { - return OP_EBADHEADER; - } - size = 21 + head.channel_count; - if (_len < size || head.version <= 1 && _len > size) { - return OP_EBADHEADER; - } - head.stream_count = _data[19]; - if (head.stream_count < 1) { - return OP_EBADHEADER; - } - head.coupled_count = _data[20]; - if (head.coupled_count > head.stream_count) { - return OP_EBADHEADER; - } - for (ci = 0; ci < head.channel_count; ci++) { - if (_data[21 + ci] >= head.stream_count + head.coupled_count - && _data[21 + ci] != 255) { - return OP_EBADHEADER; - } - } - if (_head != NULL) { - memcpy(_head->mapping, _data + 21, head.channel_count); - } - } - /* General purpose players should not attempt to play back content with - channel mapping family 255.*/ - else if (head.mapping_family == 255) { - return OP_EIMPL; - } - /*No other channel mapping families are currently defined.*/ - else { - return OP_EBADHEADER; - } - if (_head != NULL) { - memcpy(_head, &head, head.mapping - (unsigned char *)&head); - } - return 0; -} - -void opus_tags_init(OpusTags *_tags) { - memset(_tags, 0, sizeof(*_tags)); -} - -void opus_tags_clear(OpusTags *_tags) { - int ncomments; - int ci; - ncomments = _tags->comments; - if (_tags->user_comments != NULL) { - ncomments++; - } else { - OP_ASSERT(ncomments == 0); - } - for (ci = ncomments; ci-- > 0;) { - _ogg_free(_tags->user_comments[ci]); - } - _ogg_free(_tags->user_comments); - _ogg_free(_tags->comment_lengths); - _ogg_free(_tags->vendor); -} - -/*Ensure there's room for up to _ncomments comments.*/ -static int op_tags_ensure_capacity(OpusTags *_tags, size_t _ncomments) { - char **user_comments; - int *comment_lengths; - int cur_ncomments; - size_t size; - if (OP_UNLIKELY(_ncomments >= (size_t)INT_MAX)) { - return OP_EFAULT; - } - size = sizeof(*_tags->comment_lengths) * (_ncomments + 1); - if (size / sizeof(*_tags->comment_lengths) != _ncomments + 1) { - return OP_EFAULT; - } - cur_ncomments = _tags->comments; - /* We only support growing. - Trimming requires cleaning up the allocated strings in the old space, and - is best handled separately if it's ever needed.*/ - OP_ASSERT(_ncomments >= (size_t)cur_ncomments); - comment_lengths = (int *)_ogg_realloc(_tags->comment_lengths, size); - if (OP_UNLIKELY(comment_lengths == NULL)) { - return OP_EFAULT; - } - if (_tags->comment_lengths == NULL) { - OP_ASSERT(cur_ncomments == 0); - comment_lengths[cur_ncomments] = 0; - } - comment_lengths[_ncomments] = comment_lengths[cur_ncomments]; - _tags->comment_lengths = comment_lengths; - size = sizeof(*_tags->user_comments) * (_ncomments + 1); - if (size / sizeof(*_tags->user_comments) != _ncomments + 1) { - return OP_EFAULT; - } - user_comments = (char **)_ogg_realloc(_tags->user_comments, size); - if (OP_UNLIKELY(user_comments == NULL)) { - return OP_EFAULT; - } - if (_tags->user_comments == NULL) { - OP_ASSERT(cur_ncomments == 0); - user_comments[cur_ncomments] = NULL; - } - user_comments[_ncomments] = user_comments[cur_ncomments]; - _tags->user_comments = user_comments; - return 0; -} - -/*Duplicate a (possibly non-NUL terminated) string with a known length.*/ -static char *op_strdup_with_len(const char *_s, size_t _len) { - size_t size; - char *ret; - size = sizeof(*ret) * (_len + 1); - if (OP_UNLIKELY(size < _len)) { - return NULL; - } - ret = (char *)_ogg_malloc(size); - if (OP_LIKELY(ret != NULL)) { - ret = (char *)memcpy(ret, _s, sizeof(*ret) * _len); - ret[_len] = '\0'; - } - return ret; -} - -/* The actual implementation of opus_tags_parse(). - Unlike the public API, this function requires _tags to already be - initialized, modifies its contents before success is guaranteed, and assumes - the caller will clear it on error.*/ -static int opus_tags_parse_impl(OpusTags *_tags, - const unsigned char *_data, size_t _len) { - opus_uint32 count; - size_t len; - int ncomments; - int ci; - len = _len; - if (len < 8) { - return OP_ENOTFORMAT; - } - if (memcmp(_data, "OpusTags", 8) != 0) { - return OP_ENOTFORMAT; - } - if (len < 16) { - return OP_EBADHEADER; - } - _data += 8; - len -= 8; - count = op_parse_uint32le(_data); - _data += 4; - len -= 4; - if (count > len) { - return OP_EBADHEADER; - } - if (_tags != NULL) { - _tags->vendor = op_strdup_with_len((char *)_data, count); - if (_tags->vendor == NULL) { - return OP_EFAULT; - } - } - _data += count; - len -= count; - if (len < 4) { - return OP_EBADHEADER; - } - count = op_parse_uint32le(_data); - _data += 4; - len -= 4; - /*Check to make sure there's minimally sufficient data left in the packet.*/ - if (count > len >> 2) { - return OP_EBADHEADER; - } - /*Check for overflow (the API limits this to an int).*/ - if (count > (opus_uint32)INT_MAX - 1) { - return OP_EFAULT; - } - if (_tags != NULL) { - int ret; - ret = op_tags_ensure_capacity(_tags, count); - if (ret < 0) { - return ret; - } - } - ncomments = (int)count; - for (ci = 0; ci < ncomments; ci++) { - /*Check to make sure there's minimally sufficient data left in the packet.*/ - if ((size_t)(ncomments - ci) > len >> 2) { - return OP_EBADHEADER; - } - count = op_parse_uint32le(_data); - _data += 4; - len -= 4; - if (count > len) { - return OP_EBADHEADER; - } - /*Check for overflow (the API limits this to an int).*/ - if (count > (opus_uint32)INT_MAX) { - return OP_EFAULT; - } - if (_tags != NULL) { - _tags->user_comments[ci] = op_strdup_with_len((char *)_data, count); - if (_tags->user_comments[ci] == NULL) { - return OP_EFAULT; - } - _tags->comment_lengths[ci] = (int)count; - _tags->comments = ci + 1; - /* Needed by opus_tags_clear() if we fail before parsing the (optional) - binary metadata.*/ - _tags->user_comments[ci + 1] = NULL; - } - _data += count; - len -= count; - } - if (len > 0 && (_data[0] & 1)) { - if (len > (opus_uint32)INT_MAX) { - return OP_EFAULT; - } - if (_tags != NULL) { - _tags->user_comments[ncomments] = (char *)_ogg_malloc(len); - if (OP_UNLIKELY(_tags->user_comments[ncomments] == NULL)) { - return OP_EFAULT; - } - memcpy(_tags->user_comments[ncomments], _data, len); - _tags->comment_lengths[ncomments] = (int)len; - } - } - return 0; -} - -int opus_tags_parse(OpusTags *_tags, const unsigned char *_data, size_t _len) { - if (_tags != NULL) { - OpusTags tags; - int ret; - opus_tags_init(&tags); - ret = opus_tags_parse_impl(&tags, _data, _len); - if (ret < 0) { - opus_tags_clear(&tags); - } else { - *_tags = *&tags; - } - return ret; - } else { - return opus_tags_parse_impl(NULL, _data, _len); - } -} - -/* The actual implementation of opus_tags_copy(). - Unlike the public API, this function requires _dst to already be - initialized, modifies its contents before success is guaranteed, and assumes - the caller will clear it on error.*/ -static int opus_tags_copy_impl(OpusTags *_dst, const OpusTags *_src) { - char *vendor; - int ncomments; - int ret; - int ci; - vendor = _src->vendor; - _dst->vendor = op_strdup_with_len(vendor, strlen(vendor)); - if (OP_UNLIKELY(_dst->vendor == NULL)) { - return OP_EFAULT; - } - ncomments = _src->comments; - ret = op_tags_ensure_capacity(_dst, ncomments); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - for (ci = 0; ci < ncomments; ci++) { - int len; - len = _src->comment_lengths[ci]; - OP_ASSERT(len >= 0); - _dst->user_comments[ci] = op_strdup_with_len(_src->user_comments[ci], len); - if (OP_UNLIKELY(_dst->user_comments[ci] == NULL)) { - return OP_EFAULT; - } - _dst->comment_lengths[ci] = len; - _dst->comments = ci + 1; - } - if (_src->comment_lengths != NULL) { - int len; - len = _src->comment_lengths[ncomments]; - if (len > 0) { - _dst->user_comments[ncomments] = (char *)_ogg_malloc(len); - if (OP_UNLIKELY(_dst->user_comments[ncomments] == NULL)) { - return OP_EFAULT; - } - memcpy(_dst->user_comments[ncomments], _src->user_comments[ncomments], len); - _dst->comment_lengths[ncomments] = len; - } - } - return 0; -} - -int opus_tags_copy(OpusTags *_dst, const OpusTags *_src) { - OpusTags dst; - int ret; - opus_tags_init(&dst); - ret = opus_tags_copy_impl(&dst, _src); - if (OP_UNLIKELY(ret < 0)) { - opus_tags_clear(&dst); - } else { - *_dst = *&dst; - } - return ret; -} - -int opus_tags_add(OpusTags *_tags, const char *_tag, const char *_value) { - char *comment; - size_t tag_len; - size_t value_len; - int ncomments; - int ret; - ncomments = _tags->comments; - ret = op_tags_ensure_capacity(_tags, ncomments + 1); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - tag_len = strlen(_tag); - value_len = strlen(_value); - /*+2 for '=' and '\0'.*/ - if (tag_len + value_len < tag_len) { - return OP_EFAULT; - } - if (tag_len + value_len > (size_t)INT_MAX - 2) { - return OP_EFAULT; - } - comment = (char *)_ogg_malloc(sizeof(*comment) * (tag_len + value_len + 2)); - if (OP_UNLIKELY(comment == NULL)) { - return OP_EFAULT; - } - memcpy(comment, _tag, sizeof(*comment)*tag_len); - comment[tag_len] = '='; - memcpy(comment + tag_len + 1, _value, sizeof(*comment) * (value_len + 1)); - _tags->user_comments[ncomments] = comment; - _tags->comment_lengths[ncomments] = (int)(tag_len + value_len + 1); - _tags->comments = ncomments + 1; - return 0; -} - -int opus_tags_add_comment(OpusTags *_tags, const char *_comment) { - char *comment; - int comment_len; - int ncomments; - int ret; - ncomments = _tags->comments; - ret = op_tags_ensure_capacity(_tags, ncomments + 1); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - comment_len = (int)strlen(_comment); - comment = op_strdup_with_len(_comment, comment_len); - if (OP_UNLIKELY(comment == NULL)) { - return OP_EFAULT; - } - _tags->user_comments[ncomments] = comment; - _tags->comment_lengths[ncomments] = comment_len; - _tags->comments = ncomments + 1; - return 0; -} - -int opus_tags_set_binary_suffix(OpusTags *_tags, - const unsigned char *_data, int _len) { - unsigned char *binary_suffix_data; - int ncomments; - int ret; - if (_len < 0 || _len > 0 && (_data == NULL || !(_data[0] & 1))) { - return OP_EINVAL; - } - ncomments = _tags->comments; - ret = op_tags_ensure_capacity(_tags, ncomments); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - binary_suffix_data = - (unsigned char *)_ogg_realloc(_tags->user_comments[ncomments], _len); - if (OP_UNLIKELY(binary_suffix_data == NULL)) { - return OP_EFAULT; - } - memcpy(binary_suffix_data, _data, _len); - _tags->user_comments[ncomments] = (char *)binary_suffix_data; - _tags->comment_lengths[ncomments] = _len; - return 0; -} - -int opus_tagcompare(const char *_tag_name, const char *_comment) { - size_t tag_len; - tag_len = strlen(_tag_name); - if (OP_UNLIKELY(tag_len > (size_t)INT_MAX)) { - return -1; - } - return opus_tagncompare(_tag_name, (int)tag_len, _comment); -} - -int opus_tagncompare(const char *_tag_name, int _tag_len, const char *_comment) { - int ret; - OP_ASSERT(_tag_len >= 0); - ret = op_strncasecmp(_tag_name, _comment, _tag_len); - return ret ? ret : '=' - _comment[_tag_len]; -} - -const char *opus_tags_query(const OpusTags *_tags, const char *_tag, int _count) { - char **user_comments; - size_t tag_len; - int found; - int ncomments; - int ci; - tag_len = strlen(_tag); - if (OP_UNLIKELY(tag_len > (size_t)INT_MAX)) { - return NULL; - } - ncomments = _tags->comments; - user_comments = _tags->user_comments; - found = 0; - for (ci = 0; ci < ncomments; ci++) { - if (!opus_tagncompare(_tag, (int)tag_len, user_comments[ci])) { - /*We return a pointer to the data, not a copy.*/ - if (_count == found++) { - return user_comments[ci] + tag_len + 1; - } - } - } - /*Didn't find anything.*/ - return NULL; -} - -int opus_tags_query_count(const OpusTags *_tags, const char *_tag) { - char **user_comments; - size_t tag_len; - int found; - int ncomments; - int ci; - tag_len = strlen(_tag); - if (OP_UNLIKELY(tag_len > (size_t)INT_MAX)) { - return 0; - } - ncomments = _tags->comments; - user_comments = _tags->user_comments; - found = 0; - for (ci = 0; ci < ncomments; ci++) { - if (!opus_tagncompare(_tag, (int)tag_len, user_comments[ci])) { - found++; - } - } - return found; -} - -const unsigned char *opus_tags_get_binary_suffix(const OpusTags *_tags, - int *_len) { - int ncomments; - int len; - ncomments = _tags->comments; - len = _tags->comment_lengths == NULL ? 0 : _tags->comment_lengths[ncomments]; - *_len = len; - OP_ASSERT(len == 0 || _tags->user_comments != NULL); - return len > 0 ? (const unsigned char *)_tags->user_comments[ncomments] : NULL; -} - -static int opus_tags_get_gain(const OpusTags *_tags, int *_gain_q8, - const char *_tag_name, size_t _tag_len) { - char **comments; - int ncomments; - int ci; - comments = _tags->user_comments; - ncomments = _tags->comments; - /*Look for the first valid tag with the name _tag_name and use that.*/ - for (ci = 0; ci < ncomments; ci++) { - OP_ASSERT(_tag_len <= (size_t)INT_MAX); - if (opus_tagncompare(_tag_name, (int)_tag_len, comments[ci]) == 0) { - char *p; - opus_int32 gain_q8; - int negative; - p = comments[ci] + _tag_len + 1; - negative = 0; - if (*p == '-') { - negative = -1; - p++; - } else if (*p == '+') { - p++; - } - gain_q8 = 0; - while (*p >= '0' && *p <= '9') { - gain_q8 = 10 * gain_q8 + *p - '0'; - if (gain_q8 > 32767 - negative) { - break; - } - p++; - } - /* This didn't look like a signed 16-bit decimal integer. - Not a valid gain tag.*/ - if (*p != '\0') { - continue; - } - *_gain_q8 = (int)(gain_q8 + negative ^ negative); - return 0; - } - } - return OP_FALSE; -} - -int opus_tags_get_album_gain(const OpusTags *_tags, int *_gain_q8) { - return opus_tags_get_gain(_tags, _gain_q8, "R128_ALBUM_GAIN", 15); -} - -int opus_tags_get_track_gain(const OpusTags *_tags, int *_gain_q8) { - return opus_tags_get_gain(_tags, _gain_q8, "R128_TRACK_GAIN", 15); -} - -static int op_is_jpeg(const unsigned char *_buf, size_t _buf_sz) { - return _buf_sz >= 3 && memcmp(_buf, "\xFF\xD8\xFF", 3) == 0; -} - -/* Tries to extract the width, height, bits per pixel, and palette size of a - JPEG. - On failure, simply leaves its outputs unmodified.*/ -static void op_extract_jpeg_params(const unsigned char *_buf, size_t _buf_sz, - opus_uint32 *_width, opus_uint32 *_height, - opus_uint32 *_depth, opus_uint32 *_colors, int *_has_palette) { - if (op_is_jpeg(_buf, _buf_sz)) { - size_t offs; - offs = 2; - for (;;) { - size_t segment_len; - int marker; - while (offs < _buf_sz && _buf[offs] != 0xFF) { - offs++; - } - while (offs < _buf_sz && _buf[offs] == 0xFF) { - offs++; - } - marker = _buf[offs]; - offs++; - /* If we hit EOI* (end of image), or another SOI* (start of image), - or SOS (start of scan), then stop now.*/ - if (offs >= _buf_sz || (marker >= 0xD8 && marker <= 0xDA)) { - break; - } - /*RST* (restart markers): skip (no segment length).*/ - else if (marker >= 0xD0 && marker <= 0xD7) { - continue; - } - /*Read the length of the marker segment.*/ - if (_buf_sz - offs < 2) { - break; - } - segment_len = _buf[offs] << 8 | _buf[offs + 1]; - if (segment_len < 2 || _buf_sz - offs < segment_len) { - break; - } - if (marker == 0xC0 || (marker > 0xC0 && marker < 0xD0 && (marker & 3) != 0)) { - /*Found a SOFn (start of frame) marker segment:*/ - if (segment_len >= 8) { - *_height = _buf[offs + 3] << 8 | _buf[offs + 4]; - *_width = _buf[offs + 5] << 8 | _buf[offs + 6]; - *_depth = _buf[offs + 2] * _buf[offs + 7]; - *_colors = 0; - *_has_palette = 0; - } - break; - } - /*Other markers: skip the whole marker segment.*/ - offs += segment_len; - } - } -} - -static int op_is_png(const unsigned char *_buf, size_t _buf_sz) { - return _buf_sz >= 8 && memcmp(_buf, "\x89PNG\x0D\x0A\x1A\x0A", 8) == 0; -} - -/* Tries to extract the width, height, bits per pixel, and palette size of a - PNG. - On failure, simply leaves its outputs unmodified.*/ -static void op_extract_png_params(const unsigned char *_buf, size_t _buf_sz, - opus_uint32 *_width, opus_uint32 *_height, - opus_uint32 *_depth, opus_uint32 *_colors, int *_has_palette) { - if (op_is_png(_buf, _buf_sz)) { - size_t offs; - offs = 8; - while (_buf_sz - offs >= 12) { - ogg_uint32_t chunk_len; - chunk_len = op_parse_uint32be(_buf + offs); - if (chunk_len > _buf_sz - (offs + 12)) { - break; - } else if (chunk_len == 13 && memcmp(_buf + offs + 4, "IHDR", 4) == 0) { - int color_type; - *_width = op_parse_uint32be(_buf + offs + 8); - *_height = op_parse_uint32be(_buf + offs + 12); - color_type = _buf[offs + 17]; - if (color_type == 3) { - *_depth = 24; - *_has_palette = 1; - } else { - int sample_depth; - sample_depth = _buf[offs + 16]; - if (color_type == 0) { - *_depth = sample_depth; - } else if (color_type == 2) { - *_depth = sample_depth * 3; - } else if (color_type == 4) { - *_depth = sample_depth * 2; - } else if (color_type == 6) { - *_depth = sample_depth * 4; - } - *_colors = 0; - *_has_palette = 0; - break; - } - } else if (*_has_palette > 0 && memcmp(_buf + offs + 4, "PLTE", 4) == 0) { - *_colors = chunk_len / 3; - break; - } - offs += 12 + chunk_len; - } - } -} - -static int op_is_gif(const unsigned char *_buf, size_t _buf_sz) { - return _buf_sz >= 6 && (memcmp(_buf, "GIF87a", 6) == 0 || memcmp(_buf, "GIF89a", 6) == 0); -} - -/* Tries to extract the width, height, bits per pixel, and palette size of a - GIF. - On failure, simply leaves its outputs unmodified.*/ -static void op_extract_gif_params(const unsigned char *_buf, size_t _buf_sz, - opus_uint32 *_width, opus_uint32 *_height, - opus_uint32 *_depth, opus_uint32 *_colors, int *_has_palette) { - if (op_is_gif(_buf, _buf_sz) && _buf_sz >= 14) { - *_width = _buf[6] | _buf[7] << 8; - *_height = _buf[8] | _buf[9] << 8; - /*libFLAC hard-codes the depth to 24.*/ - *_depth = 24; - *_colors = 1 << ((_buf[10] & 7) + 1); - *_has_palette = 1; - } -} - -/* The actual implementation of opus_picture_tag_parse(). - Unlike the public API, this function requires _pic to already be - initialized, modifies its contents before success is guaranteed, and assumes - the caller will clear it on error.*/ -static int opus_picture_tag_parse_impl(OpusPictureTag *_pic, const char *_tag, - unsigned char *_buf, size_t _buf_sz, size_t _base64_sz) { - opus_int32 picture_type; - opus_uint32 mime_type_length; - char *mime_type; - opus_uint32 description_length; - char *description; - opus_uint32 width; - opus_uint32 height; - opus_uint32 depth; - opus_uint32 colors; - opus_uint32 data_length; - opus_uint32 file_width; - opus_uint32 file_height; - opus_uint32 file_depth; - opus_uint32 file_colors; - int format; - int has_palette; - int colors_set; - size_t i; - /*Decode the BASE64 data.*/ - OP_ASSERT(_base64_sz >= 11); - for (i = 0; i < _base64_sz; i++) { - opus_uint32 value; - int j; - value = 0; - for (j = 0; j < 4; j++) { - unsigned c; - unsigned d; - c = (unsigned char)_tag[4 * i + j]; - if (c == '+') { - d = 62; - } else if (c == '/') { - d = 63; - } else if (c >= '0' && c <= '9') { - d = 52 + c - '0'; - } else if (c >= 'a' && c <= 'z') { - d = 26 + c - 'a'; - } else if (c >= 'A' && c <= 'Z') { - d = c - 'A'; - } else if (c == '=' && 3 * i + j > _buf_sz) { - d = 0; - } else { - return OP_ENOTFORMAT; - } - value = value << 6 | d; - } - _buf[3 * i] = (unsigned char)(value >> 16); - if (3 * i + 1 < _buf_sz) { - _buf[3 * i + 1] = (unsigned char)(value >> 8); - if (3 * i + 2 < _buf_sz) { - _buf[3 * i + 2] = (unsigned char)value; - } - } - } - i = 0; - picture_type = op_parse_uint32be(_buf + i); - i += 4; - /*Extract the MIME type.*/ - mime_type_length = op_parse_uint32be(_buf + i); - i += 4; - if (mime_type_length > _buf_sz - 32) { - return OP_ENOTFORMAT; - } - mime_type = (char *)_ogg_malloc(sizeof(*_pic->mime_type) * (mime_type_length + 1)); - if (mime_type == NULL) { - return OP_EFAULT; - } - memcpy(mime_type, _buf + i, sizeof(*mime_type)*mime_type_length); - mime_type[mime_type_length] = '\0'; - _pic->mime_type = mime_type; - i += mime_type_length; - /*Extract the description string.*/ - description_length = op_parse_uint32be(_buf + i); - i += 4; - if (description_length > _buf_sz - mime_type_length - 32) { - return OP_ENOTFORMAT; - } - description = - (char *)_ogg_malloc(sizeof(*_pic->mime_type) * (description_length + 1)); - if (description == NULL) { - return OP_EFAULT; - } - memcpy(description, _buf + i, sizeof(*description)*description_length); - description[description_length] = '\0'; - _pic->description = description; - i += description_length; - /*Extract the remaining fields.*/ - width = op_parse_uint32be(_buf + i); - i += 4; - height = op_parse_uint32be(_buf + i); - i += 4; - depth = op_parse_uint32be(_buf + i); - i += 4; - colors = op_parse_uint32be(_buf + i); - i += 4; - /*If one of these is set, they all must be, but colors==0 is a valid value.*/ - colors_set = width != 0 || height != 0 || depth != 0 || colors != 0; - if ((width == 0 || height == 0 || depth == 0) && colors_set) { - return OP_ENOTFORMAT; - } - data_length = op_parse_uint32be(_buf + i); - i += 4; - if (data_length > _buf_sz - i) { - return OP_ENOTFORMAT; - } - /*Trim extraneous data so we don't copy it below.*/ - _buf_sz = i + data_length; - /*Attempt to determine the image format.*/ - format = OP_PIC_FORMAT_UNKNOWN; - if (mime_type_length == 3 && strcmp(mime_type, "-->") == 0) { - format = OP_PIC_FORMAT_URL; - /*Picture type 1 must be a 32x32 PNG.*/ - if (picture_type == 1 && (width != 0 || height != 0) && (width != 32 || height != 32)) { - return OP_ENOTFORMAT; - } - /*Append a terminating NUL for the convenience of our callers.*/ - _buf[_buf_sz++] = '\0'; - } else { - if (mime_type_length == 10 - && op_strncasecmp(mime_type, "image/jpeg", mime_type_length) == 0) { - if (op_is_jpeg(_buf + i, data_length)) { - format = OP_PIC_FORMAT_JPEG; - } - } else if (mime_type_length == 9 - && op_strncasecmp(mime_type, "image/png", mime_type_length) == 0) { - if (op_is_png(_buf + i, data_length)) { - format = OP_PIC_FORMAT_PNG; - } - } else if (mime_type_length == 9 - && op_strncasecmp(mime_type, "image/gif", mime_type_length) == 0) { - if (op_is_gif(_buf + i, data_length)) { - format = OP_PIC_FORMAT_GIF; - } - } else if (mime_type_length == 0 || (mime_type_length == 6 - && op_strncasecmp(mime_type, "image/", mime_type_length) == 0)) { - if (op_is_jpeg(_buf + i, data_length)) { - format = OP_PIC_FORMAT_JPEG; - } else if (op_is_png(_buf + i, data_length)) { - format = OP_PIC_FORMAT_PNG; - } else if (op_is_gif(_buf + i, data_length)) { - format = OP_PIC_FORMAT_GIF; - } - } - file_width = file_height = file_depth = file_colors = 0; - has_palette = -1; - switch (format) { - case OP_PIC_FORMAT_JPEG: { - op_extract_jpeg_params(_buf + i, data_length, - &file_width, &file_height, &file_depth, &file_colors, &has_palette); - } break; - case OP_PIC_FORMAT_PNG: { - op_extract_png_params(_buf + i, data_length, - &file_width, &file_height, &file_depth, &file_colors, &has_palette); - } break; - case OP_PIC_FORMAT_GIF: { - op_extract_gif_params(_buf + i, data_length, - &file_width, &file_height, &file_depth, &file_colors, &has_palette); - } break; - } - if (has_palette >= 0) { - /* If we successfully extracted these parameters from the image, override - any declared values.*/ - width = file_width; - height = file_height; - depth = file_depth; - colors = file_colors; - } - /*Picture type 1 must be a 32x32 PNG.*/ - if (picture_type == 1 && (format != OP_PIC_FORMAT_PNG || width != 32 || height != 32)) { - return OP_ENOTFORMAT; - } - } - /* Adjust _buf_sz instead of using data_length to capture the terminating NUL - for URLs.*/ - _buf_sz -= i; - memmove(_buf, _buf + i, sizeof(*_buf)*_buf_sz); - _buf = (unsigned char *)_ogg_realloc(_buf, _buf_sz); - if (_buf_sz > 0 && _buf == NULL) { - return OP_EFAULT; - } - _pic->type = picture_type; - _pic->width = width; - _pic->height = height; - _pic->depth = depth; - _pic->colors = colors; - _pic->data_length = data_length; - _pic->data = _buf; - _pic->format = format; - return 0; -} - -int opus_picture_tag_parse(OpusPictureTag *_pic, const char *_tag) { - OpusPictureTag pic; - unsigned char *buf; - size_t base64_sz; - size_t buf_sz; - size_t tag_length; - int ret; - if (opus_tagncompare("METADATA_BLOCK_PICTURE", 22, _tag) == 0) { - _tag += 23; - } - /*Figure out how much BASE64-encoded data we have.*/ - tag_length = strlen(_tag); - if (tag_length & 3) { - return OP_ENOTFORMAT; - } - base64_sz = tag_length >> 2; - buf_sz = 3 * base64_sz; - if (buf_sz < 32) { - return OP_ENOTFORMAT; - } - if (_tag[tag_length - 1] == '=') { - buf_sz--; - } - if (_tag[tag_length - 2] == '=') { - buf_sz--; - } - if (buf_sz < 32) { - return OP_ENOTFORMAT; - } - /*Allocate an extra byte to allow appending a terminating NUL to URL data.*/ - buf = (unsigned char *)_ogg_malloc(sizeof(*buf) * (buf_sz + 1)); - if (buf == NULL) { - return OP_EFAULT; - } - opus_picture_tag_init(&pic); - ret = opus_picture_tag_parse_impl(&pic, _tag, buf, buf_sz, base64_sz); - if (ret < 0) { - opus_picture_tag_clear(&pic); - _ogg_free(buf); - } else { - *_pic = *&pic; - } - return ret; -} - -void opus_picture_tag_init(OpusPictureTag *_pic) { - memset(_pic, 0, sizeof(*_pic)); -} - -void opus_picture_tag_clear(OpusPictureTag *_pic) { - _ogg_free(_pic->description); - _ogg_free(_pic->mime_type); - _ogg_free(_pic->data); -} diff --git a/src/opusfile/internal.c b/src/opusfile/internal.c deleted file mode 100644 index 07e4824..0000000 --- a/src/opusfile/internal.c +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE libopusfile SOURCE CODE IS (C) COPYRIGHT 2012-2020 - by the Xiph.Org Foundation and contributors https://xiph.org/ - * * - ********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "internal.h" - -#if defined(OP_ENABLE_ASSERTIONS) -void op_fatal_impl(const char *_str, const char *_file, int _line) { - fprintf(stderr, "Fatal (internal) error in %s, line %i: %s\n", - _file, _line, _str); - abort(); -} -#endif - -/* A version of strncasecmp() that is guaranteed to only ignore the case of - ASCII characters.*/ -int op_strncasecmp(const char *_a, const char *_b, int _n) { - int i; - for (i = 0; i < _n; i++) { - int a; - int b; - int d; - a = _a[i]; - b = _b[i]; - if (a >= 'a' && a <= 'z') { - a -= 'a' - 'A'; - } - if (b >= 'a' && b <= 'z') { - b -= 'a' - 'A'; - } - d = a - b; - if (d) { - return d; - } - } - return 0; -} diff --git a/src/opusfile/internal.h b/src/opusfile/internal.h deleted file mode 100644 index cee9107..0000000 --- a/src/opusfile/internal.h +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE libopusfile SOURCE CODE IS (C) COPYRIGHT 2012-2020 - by the Xiph.Org Foundation and contributors https://xiph.org/ - * * - ********************************************************************/ -#if !defined(_opusfile_internal_h) -# define _opusfile_internal_h (1) - -# if !defined(_REENTRANT) -# define _REENTRANT -# endif -# if !defined(_GNU_SOURCE) -# define _GNU_SOURCE -# endif -# if !defined(_LARGEFILE_SOURCE) -# define _LARGEFILE_SOURCE -# endif -# if !defined(_LARGEFILE64_SOURCE) -# define _LARGEFILE64_SOURCE -# endif -# if !defined(_FILE_OFFSET_BITS) -# define _FILE_OFFSET_BITS 64 -# endif - -# include -# include "opusfile.h" - -typedef struct OggOpusLink OggOpusLink; - -# if defined(OP_FIXED_POINT) - -typedef opus_int16 op_sample; - -# else - -typedef float op_sample; - -/* We're using this define to test for libopus 1.1 or later until libopus - provides a better mechanism.*/ -# if defined(OPUS_GET_EXPERT_FRAME_DURATION_REQUEST) -/*Enable soft clipping prevention in 16-bit decodes.*/ -# define OP_SOFT_CLIP (1) -# endif - -# endif - -# if OP_GNUC_PREREQ(4,2) -/*Disable excessive warnings about the order of operations.*/ -# pragma GCC diagnostic ignored "-Wparentheses" -# elif defined(_MSC_VER) -/*Disable excessive warnings about the order of operations.*/ -# pragma warning(disable:4554) -/*Disable warnings about "deprecated" POSIX functions.*/ -# pragma warning(disable:4996) -# endif - -# if OP_GNUC_PREREQ(3,0) -/* Another alternative is - (__builtin_constant_p(_x)?!!(_x):__builtin_expect(!!(_x),1)) - but that evaluates _x multiple times, which may be bad.*/ -# define OP_LIKELY(_x) (__builtin_expect(!!(_x),1)) -# define OP_UNLIKELY(_x) (__builtin_expect(!!(_x),0)) -# else -# define OP_LIKELY(_x) (!!(_x)) -# define OP_UNLIKELY(_x) (!!(_x)) -# endif - -# if defined(OP_ENABLE_ASSERTIONS) -# if OP_GNUC_PREREQ(2,5)||__SUNPRO_C>=0x590 -__attribute__((noreturn)) -# endif -void op_fatal_impl(const char *_str, const char *_file, int _line); - -# define OP_FATAL(_str) (op_fatal_impl(_str,__FILE__,__LINE__)) - -# define OP_ASSERT(_cond) \ - do{ \ - if(OP_UNLIKELY(!(_cond)))OP_FATAL("assertion failed: " #_cond); \ - } \ - while(0) -# define OP_ALWAYS_TRUE(_cond) OP_ASSERT(_cond) - -# else -# define OP_FATAL(_str) abort() -# define OP_ASSERT(_cond) -# define OP_ALWAYS_TRUE(_cond) ((void)(_cond)) -# endif - -# define OP_INT64_MAX (2*(((ogg_int64_t)1<<62)-1)|1) -# define OP_INT64_MIN (-OP_INT64_MAX-1) -# define OP_INT32_MAX (2*(((ogg_int32_t)1<<30)-1)|1) -# define OP_INT32_MIN (-OP_INT32_MAX-1) - -# define OP_MIN(_a,_b) ((_a)<(_b)?(_a):(_b)) -# define OP_MAX(_a,_b) ((_a)>(_b)?(_a):(_b)) -# define OP_CLAMP(_lo,_x,_hi) (OP_MAX(_lo,OP_MIN(_x,_hi))) - -/* Advance a file offset by the given amount, clamping against OP_INT64_MAX. - This is used to advance a known offset by things like OP_CHUNK_SIZE or - OP_PAGE_SIZE_MAX, while making sure to avoid signed overflow. - It assumes that both _offset and _amount are non-negative.*/ -#define OP_ADV_OFFSET(_offset,_amount) \ - (OP_MIN(_offset,OP_INT64_MAX-(_amount))+(_amount)) - -/*The maximum channel count for any mapping we'll actually decode.*/ -# define OP_NCHANNELS_MAX (2) - -/*Initial state.*/ -# define OP_NOTOPEN (0) -/*We've found the first Opus stream in the first link.*/ -# define OP_PARTOPEN (1) -# define OP_OPENED (2) -/*We've found the first Opus stream in the current link.*/ -# define OP_STREAMSET (3) -/* We've initialized the decoder for the chosen Opus stream in the current - link.*/ -# define OP_INITSET (4) - -/* Information cached for a single link in a chained Ogg Opus file. - We choose the first Opus stream encountered in each link to play back (and - require at least one).*/ -struct OggOpusLink { - /*The byte offset of the first header page in this link.*/ - opus_int64 offset; - /* The byte offset of the first data page from the chosen Opus stream in this - link (after the headers).*/ - opus_int64 data_offset; - /* The byte offset of the last page from the chosen Opus stream in this link. - This is used when seeking to ensure we find a page before the last one, so - that end-trimming calculations work properly. - This is only valid for seekable sources.*/ - opus_int64 end_offset; - /* The total duration of all prior links. - This is always zero for non-seekable sources.*/ - ogg_int64_t pcm_file_offset; - /* The granule position of the last sample. - This is only valid for seekable sources.*/ - ogg_int64_t pcm_end; - /*The granule position before the first sample.*/ - ogg_int64_t pcm_start; - /*The serial number.*/ - ogg_uint32_t serialno; - /*The contents of the info header.*/ - OpusHead head; - /*The contents of the comment header.*/ - OpusTags tags; -}; - -struct OggOpusFile { - /*The callbacks used to access the stream.*/ - OpusFileCallbacks callbacks; - /*A FILE *, memory buffer, etc.*/ - void *stream; - /*Whether or not we can seek with this stream.*/ - int seekable; - /*The number of links in this chained Ogg Opus file.*/ - int nlinks; - /* The cached information from each link in a chained Ogg Opus file. - If stream isn't seekable (e.g., it's a pipe), only the current link - appears.*/ - OggOpusLink *links; - /*The number of serial numbers from a single link.*/ - int nserialnos; - /*The capacity of the list of serial numbers from a single link.*/ - int cserialnos; - /* Storage for the list of serial numbers from a single link. - This is a scratch buffer used when scanning the BOS pages at the start of - each link.*/ - ogg_uint32_t *serialnos; - /* This is the current offset of the data processed by the ogg_sync_state. - After a seek, this should be set to the target offset so that we can track - the byte offsets of subsequent pages. - After a call to op_get_next_page(), this will point to the first byte after - that page.*/ - opus_int64 offset; - /*The total size of this stream, or -1 if it's unseekable.*/ - opus_int64 end; - /*Used to locate pages in the stream.*/ - ogg_sync_state oy; - /*One of OP_NOTOPEN, OP_PARTOPEN, OP_OPENED, OP_STREAMSET, OP_INITSET.*/ - int ready_state; - /*The current link being played back.*/ - int cur_link; - /*The number of decoded samples to discard from the start of decoding.*/ - opus_int32 cur_discard_count; - /*The granule position of the previous packet (current packet start time).*/ - ogg_int64_t prev_packet_gp; - /* The stream offset of the most recent page with completed packets, or -1. - This is only needed to recover continued packet data in the seeking logic, - when we use the current position as one of our bounds, only to later - discover it was the correct starting point.*/ - opus_int64 prev_page_offset; - /*The number of bytes read since the last bitrate query, including framing.*/ - opus_int64 bytes_tracked; - /*The number of samples decoded since the last bitrate query.*/ - ogg_int64_t samples_tracked; - /*Takes physical pages and welds them into a logical stream of packets.*/ - ogg_stream_state os; - /* Re-timestamped packets from a single page. - Buffering these relies on the undocumented libogg behavior that ogg_packet - pointers remain valid until the next page is submitted to the - ogg_stream_state they came from.*/ - ogg_packet op[255]; - /*The index of the next packet to return.*/ - int op_pos; - /*The total number of packets available.*/ - int op_count; - /*Central working state for the packet-to-PCM decoder.*/ - OpusMSDecoder *od; - /*The application-provided packet decode callback.*/ - op_decode_cb_func decode_cb; - /*The application-provided packet decode callback context.*/ - void *decode_cb_ctx; - /*The stream count used to initialize the decoder.*/ - int od_stream_count; - /*The coupled stream count used to initialize the decoder.*/ - int od_coupled_count; - /*The channel count used to initialize the decoder.*/ - int od_channel_count; - /*The channel mapping used to initialize the decoder.*/ - unsigned char od_mapping[OP_NCHANNELS_MAX]; - /*The buffered data for one decoded packet.*/ - op_sample *od_buffer; - /*The current position in the decoded buffer.*/ - int od_buffer_pos; - /*The number of valid samples in the decoded buffer.*/ - int od_buffer_size; - /* The type of gain offset to apply. - One of OP_HEADER_GAIN, OP_ALBUM_GAIN, OP_TRACK_GAIN, or OP_ABSOLUTE_GAIN.*/ - int gain_type; - /*The offset to apply to the gain.*/ - opus_int32 gain_offset_q8; - /*Internal state for soft clipping and dithering float->short output.*/ -#if !defined(OP_FIXED_POINT) -# if defined(OP_SOFT_CLIP) - float clip_state[OP_NCHANNELS_MAX]; -# endif - float dither_a[OP_NCHANNELS_MAX * 4]; - float dither_b[OP_NCHANNELS_MAX * 4]; - opus_uint32 dither_seed; - int dither_mute; - int dither_disabled; - /* The number of channels represented by the internal state. - This gets set to 0 whenever anything that would prevent state propagation - occurs (switching between the float/short APIs, or between the - stereo/multistream APIs).*/ - int state_channel_count; -#endif -}; - -int op_strncasecmp(const char *_a, const char *_b, int _n); - -#endif diff --git a/src/opusfile/opusfile.c b/src/opusfile/opusfile.c deleted file mode 100644 index 9bb4079..0000000 --- a/src/opusfile/opusfile.c +++ /dev/null @@ -1,3750 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2020 - by the Xiph.Org Foundation and contributors https://xiph.org/ - * * - ******************************************************************** - - function: stdio-based convenience library for opening/seeking/decoding - last mod: $Id: vorbisfile.c 17573 2010-10-27 14:53:59Z xiphmont $ - - ********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "internal.h" -#include -#include -#include -#include -#include -#include - -#include "opusfile.h" - -/* This implementation is largely based off of libvorbisfile. - All of the Ogg bits work roughly the same, though I have made some - "improvements" that have not been folded back there, yet.*/ - -/* A 'chained bitstream' is an Ogg Opus bitstream that contains more than one - logical bitstream arranged end to end (the only form of Ogg multiplexing - supported by this library. - Grouping (parallel multiplexing) is not supported, except to the extent that - if there are multiple logical Ogg streams in a single link of the chain, we - will ignore all but the first Opus stream we find.*/ - -/* An Ogg Opus file can be played beginning to end (streamed) without worrying - ahead of time about chaining (see opusdec from the opus-tools package). - If we have the whole file, however, and want random access - (seeking/scrubbing) or desire to know the total length/time of a file, we - need to account for the possibility of chaining.*/ - -/* We can handle things a number of ways. - We can determine the entire bitstream structure right off the bat, or find - pieces on demand. - This library determines and caches structure for the entire bitstream, but - builds a virtual decoder on the fly when moving between links in the chain.*/ - -/* There are also different ways to implement seeking. - Enough information exists in an Ogg bitstream to seek to sample-granularity - positions in the output. - Or, one can seek by picking some portion of the stream roughly in the desired - area if we only want coarse navigation through the stream. - We implement and expose both strategies.*/ - -/*The maximum number of bytes in a page (including the page headers).*/ -#define OP_PAGE_SIZE_MAX (65307) -/* The default amount to seek backwards per step when trying to find the - previous page. - This must be at least as large as the maximum size of a page.*/ -#define OP_CHUNK_SIZE (65536) -/* The maximum amount to seek backwards per step when trying to find the - previous page.*/ -#define OP_CHUNK_SIZE_MAX (1024*(opus_int32)1024) -/*A smaller read size is needed for low-rate streaming.*/ -#define OP_READ_SIZE (2048) - -int op_test(OpusHead *_head, - const unsigned char *_initial_data, size_t _initial_bytes) { - ogg_sync_state oy; - char *data; - int err; - /* The first page of a normal Opus file will be at most 57 bytes (27 Ogg - page header bytes + 1 lacing value + 21 Opus header bytes + 8 channel - mapping bytes). - It will be at least 47 bytes (27 Ogg page header bytes + 1 lacing value + - 19 Opus header bytes using channel mapping family 0). - If we don't have at least that much data, give up now.*/ - if (_initial_bytes < 47) { - return OP_FALSE; - } - /* Only proceed if we start with the magic OggS string. - This is to prevent us spending a lot of time allocating memory and looking - for Ogg pages in non-Ogg files.*/ - if (memcmp(_initial_data, "OggS", 4) != 0) { - return OP_ENOTFORMAT; - } - if (OP_UNLIKELY(_initial_bytes > (size_t)LONG_MAX)) { - return OP_EFAULT; - } - ogg_sync_init(&oy); - data = ogg_sync_buffer(&oy, (long)_initial_bytes); - if (data != NULL) { - ogg_stream_state *os = (ogg_stream_state*)malloc(sizeof(ogg_stream_state)); - ogg_page og; - int ret; - memcpy(data, _initial_data, _initial_bytes); - ogg_sync_wrote(&oy, (long)_initial_bytes); - ogg_stream_init(os, -1); - err = OP_FALSE; - do { - ogg_packet op; - ret = ogg_sync_pageout(&oy, &og); - /*Ignore holes.*/ - if (ret < 0) { - continue; - } - /*Stop if we run out of data.*/ - if (!ret) { - break; - } - ogg_stream_reset_serialno(os, ogg_page_serialno(&og)); - ogg_stream_pagein(os, &og); - /* Only process the first packet on this page (if it's a BOS packet, - it's required to be the only one).*/ - if (ogg_stream_packetout(os, &op) == 1) { - if (op.b_o_s) { - ret = opus_head_parse(_head, op.packet, op.bytes); - /*If this didn't look like Opus, keep going.*/ - if (ret == OP_ENOTFORMAT) { - continue; - } - /*Otherwise we're done, one way or another.*/ - err = ret; - } - /* We finished parsing the headers. - There is no Opus to be found.*/ - else { - err = OP_ENOTFORMAT; - } - } - } while (err == OP_FALSE); - ogg_stream_clear(os); - free(os); - } else { - err = OP_EFAULT; - } - ogg_sync_clear(&oy); - return err; -} - -/* Many, many internal helpers. - The intention is not to be confusing. - Rampant duplication and monolithic function implementation (though we do have - some large, omnibus functions still) would be harder to understand anyway. - The high level functions are last. - Begin grokking near the end of the file if you prefer to read things - top-down.*/ - -/*The read/seek functions track absolute position within the stream.*/ - -/* Read a little more data from the file/pipe into the ogg_sync framer. - _nbytes: The maximum number of bytes to read. - Return: A positive number of bytes read on success, 0 on end-of-file, or a - negative value on failure.*/ -static int op_get_data(OggOpusFile *_of, int _nbytes) { - unsigned char *buffer; - int nbytes; - OP_ASSERT(_nbytes > 0); - buffer = (unsigned char *)ogg_sync_buffer(&_of->oy, _nbytes); - nbytes = (int)(*_of->callbacks.read)(_of->stream, buffer, _nbytes); - OP_ASSERT(nbytes <= _nbytes); - if (OP_LIKELY(nbytes > 0)) { - ogg_sync_wrote(&_of->oy, nbytes); - } - return nbytes; -} - -/*Save a tiny smidge of verbosity to make the code more readable.*/ -static int op_seek_helper(OggOpusFile *_of, opus_int64 _offset) { - if (_offset == _of->offset) { - return 0; - } - if (_of->callbacks.seek == NULL - || (*_of->callbacks.seek)(_of->stream, _offset, SEEK_SET)) { - return OP_EREAD; - } - _of->offset = _offset; - ogg_sync_reset(&_of->oy); - return 0; -} - -/* Get the current position indicator of the underlying stream. - This should be the same as the value reported by tell().*/ -static opus_int64 op_position(const OggOpusFile *_of) { - /* The current position indicator is _not_ simply offset. - We may also have unprocessed, buffered data in the sync state.*/ - return _of->offset + _of->oy.fill - _of->oy.returned; -} - -/* From the head of the stream, get the next page. - _boundary specifies if the function is allowed to fetch more data from the - stream (and how much) or only use internally buffered data. - _boundary: -1: Unbounded search. - 0: Read no additional data. - Use only cached data. - n: Search for the start of a new page up to file position n. - Return: n>=0: Found a page at absolute offset n. - OP_FALSE: Hit the _boundary limit. - OP_EREAD: An underlying read operation failed. - OP_BADLINK: We hit end-of-file before reaching _boundary.*/ -static opus_int64 op_get_next_page(OggOpusFile *_of, ogg_page *_og, - opus_int64 _boundary) { - while (_boundary <= 0 || _of->offset < _boundary) { - int more; - more = ogg_sync_pageseek(&_of->oy, _og); - /*Skipped (-more) bytes.*/ - if (OP_UNLIKELY(more < 0)) { - _of->offset -= more; - } else if (more == 0) { - int read_nbytes; - int ret; - /*Send more paramedics.*/ - if (!_boundary) { - return OP_FALSE; - } - if (_boundary < 0) { - read_nbytes = OP_READ_SIZE; - } else { - opus_int64 position; - position = op_position(_of); - if (position >= _boundary) { - return OP_FALSE; - } - read_nbytes = (int)OP_MIN(_boundary - position, OP_READ_SIZE); - } - ret = op_get_data(_of, read_nbytes); - if (OP_UNLIKELY(ret < 0)) { - return OP_EREAD; - } - if (OP_UNLIKELY(ret == 0)) { - /* Only fail cleanly on EOF if we didn't have a known boundary. - Otherwise, we should have been able to reach that boundary, and this - is a fatal error.*/ - return OP_UNLIKELY(_boundary < 0) ? OP_FALSE : OP_EBADLINK; - } - } else { - /* Got a page. - Return the page start offset and advance the internal offset past the - page end.*/ - opus_int64 page_offset; - page_offset = _of->offset; - _of->offset += more; - OP_ASSERT(page_offset >= 0); - return page_offset; - } - } - return OP_FALSE; -} - -static int op_add_serialno(const ogg_page *_og, - ogg_uint32_t **_serialnos, int *_nserialnos, int *_cserialnos) { - ogg_uint32_t *serialnos; - int nserialnos; - int cserialnos; - ogg_uint32_t s; - s = ogg_page_serialno(_og); - serialnos = *_serialnos; - nserialnos = *_nserialnos; - cserialnos = *_cserialnos; - if (OP_UNLIKELY(nserialnos >= cserialnos)) { - if (OP_UNLIKELY(cserialnos > INT_MAX / (int)sizeof(*serialnos) - 1 >> 1)) { - return OP_EFAULT; - } - cserialnos = 2 * cserialnos + 1; - OP_ASSERT(nserialnos < cserialnos); - serialnos = (ogg_uint32_t *)_ogg_realloc(serialnos, - sizeof(*serialnos) * cserialnos); - if (OP_UNLIKELY(serialnos == NULL)) { - return OP_EFAULT; - } - } - serialnos[nserialnos++] = s; - *_serialnos = serialnos; - *_nserialnos = nserialnos; - *_cserialnos = cserialnos; - return 0; -} - -/*Returns nonzero if found.*/ -static int op_lookup_serialno(ogg_uint32_t _s, - const ogg_uint32_t *_serialnos, int _nserialnos) { - int i; - for (i = 0; i < _nserialnos && _serialnos[i] != _s; i++); - return i < _nserialnos; -} - -static int op_lookup_page_serialno(const ogg_page *_og, - const ogg_uint32_t *_serialnos, int _nserialnos) { - return op_lookup_serialno(ogg_page_serialno(_og), _serialnos, _nserialnos); -} - -typedef struct OpusSeekRecord OpusSeekRecord; - -/* We use this to remember the pages we found while enumerating the links of a - chained stream. - We keep track of the starting and ending offsets, as well as the point we - started searching from, so we know where to bisect. - We also keep the serial number, so we can tell if the page belonged to the - current link or not, as well as the granule position, to aid in estimating - the start of the link.*/ -struct OpusSeekRecord { - /* The earliest byte we know of such that reading forward from it causes - capture to be regained at this page.*/ - opus_int64 search_start; - /*The offset of this page.*/ - opus_int64 offset; - /*The size of this page.*/ - opus_int32 size; - /*The serial number of this page.*/ - ogg_uint32_t serialno; - /*The granule position of this page.*/ - ogg_int64_t gp; -}; - -/* Find the last page beginning before _offset with a valid granule position. - There is no '_boundary' parameter as it will always have to read more data. - This is much dirtier than the above, as Ogg doesn't have any backward search - linkage. - This search prefers pages of the specified serial number. - If a page of the specified serial number is spotted during the - seek-back-and-read-forward, it will return the info of last page of the - matching serial number, instead of the very last page, unless the very last - page belongs to a different link than preferred serial number. - If no page of the specified serial number is seen, it will return the info of - the last page. - [out] _sr: Returns information about the page that was found on success. - _offset: The _offset before which to find a page. - Any page returned will consist of data entirely before _offset. - _serialno: The preferred serial number. - If a page with this serial number is found, it will be returned - even if another page in the same link is found closer to - _offset. - This is purely opportunistic: there is no guarantee such a page - will be found if it exists. - _serialnos: The list of serial numbers in the link that contains the - preferred serial number. - _nserialnos: The number of serial numbers in the current link. - Return: 0 on success, or a negative value on failure. - OP_EREAD: Failed to read more data (error or EOF). - OP_EBADLINK: We couldn't find a page even after seeking back to the - start of the stream.*/ -static int op_get_prev_page_serial(OggOpusFile *_of, OpusSeekRecord *_sr, - opus_int64 _offset, ogg_uint32_t _serialno, - const ogg_uint32_t *_serialnos, int _nserialnos) { - OpusSeekRecord preferred_sr; - ogg_page og; - opus_int64 begin; - opus_int64 end; - opus_int64 original_end; - opus_int32 chunk_size; - int preferred_found; - original_end = end = begin = _offset; - preferred_found = 0; - _offset = -1; - chunk_size = OP_CHUNK_SIZE; - do { - opus_int64 search_start; - int ret; - OP_ASSERT(chunk_size >= OP_PAGE_SIZE_MAX); - begin = OP_MAX(begin - chunk_size, 0); - ret = op_seek_helper(_of, begin); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - search_start = begin; - while (_of->offset < end) { - opus_int64 llret; - ogg_uint32_t serialno; - llret = op_get_next_page(_of, &og, end); - if (OP_UNLIKELY(llret < OP_FALSE)) { - return (int)llret; - } else if (llret == OP_FALSE) { - break; - } - serialno = ogg_page_serialno(&og); - /* Save the information for this page. - We're not interested in the page itself... just the serial number, byte - offset, page size, and granule position.*/ - _sr->search_start = search_start; - _sr->offset = _offset = llret; - _sr->serialno = serialno; - OP_ASSERT(_of->offset - _offset >= 0); - OP_ASSERT(_of->offset - _offset <= OP_PAGE_SIZE_MAX); - _sr->size = (opus_int32)(_of->offset - _offset); - _sr->gp = ogg_page_granulepos(&og); - /*If this page is from the stream we're looking for, remember it.*/ - if (serialno == _serialno) { - preferred_found = 1; - *&preferred_sr = *_sr; - } - if (!op_lookup_serialno(serialno, _serialnos, _nserialnos)) { - /* We fell off the end of the link, which means we seeked back too far - and shouldn't have been looking in that link to begin with. - If we found the preferred serial number, forget that we saw it.*/ - preferred_found = 0; - } - search_start = llret + 1; - } - /* We started from the beginning of the stream and found nothing. - This should be impossible unless the contents of the stream changed out - from under us after we read from it.*/ - if (OP_UNLIKELY(!begin) && OP_UNLIKELY(_offset < 0)) { - return OP_EBADLINK; - } - /* Bump up the chunk size. - This is mildly helpful when seeks are very expensive (http).*/ - chunk_size = OP_MIN(2 * chunk_size, OP_CHUNK_SIZE_MAX); - /*Avoid quadratic complexity if we hit an invalid patch of the file.*/ - end = OP_MIN(begin + OP_PAGE_SIZE_MAX - 1, original_end); - } while (_offset < 0); - if (preferred_found) { - *_sr = *&preferred_sr; - } - return 0; -} - -/* Find the last page beginning before _offset with the given serial number and - a valid granule position. - Unlike the above search, this continues until it finds such a page, but does - not stray outside the current link. - We could implement it (inefficiently) by calling op_get_prev_page_serial() - repeatedly until it returned a page that had both our preferred serial - number and a valid granule position, but doing it with a separate function - allows us to avoid repeatedly re-scanning valid pages from other streams as - we seek-back-and-read-forward. - [out] _gp: Returns the granule position of the page that was found on - success. - _offset: The _offset before which to find a page. - Any page returned will consist of data entirely before _offset. - _serialno: The target serial number. - _serialnos: The list of serial numbers in the link that contains the - preferred serial number. - _nserialnos: The number of serial numbers in the current link. - Return: The offset of the page on success, or a negative value on failure. - OP_EREAD: Failed to read more data (error or EOF). - OP_EBADLINK: We couldn't find a page even after seeking back past the - beginning of the link.*/ -static opus_int64 op_get_last_page(OggOpusFile *_of, ogg_int64_t *_gp, - opus_int64 _offset, ogg_uint32_t _serialno, - const ogg_uint32_t *_serialnos, int _nserialnos) { - ogg_page og; - ogg_int64_t gp; - opus_int64 begin; - opus_int64 end; - opus_int64 original_end; - opus_int32 chunk_size; - /*The target serial number must belong to the current link.*/ - OP_ASSERT(op_lookup_serialno(_serialno, _serialnos, _nserialnos)); - original_end = end = begin = _offset; - _offset = -1; - /* We shouldn't have to initialize gp, but gcc is too dumb to figure out that - ret>=0 implies we entered the if(page_gp!=-1) block at least once.*/ - gp = -1; - chunk_size = OP_CHUNK_SIZE; - do { - int left_link; - int ret; - OP_ASSERT(chunk_size >= OP_PAGE_SIZE_MAX); - begin = OP_MAX(begin - chunk_size, 0); - ret = op_seek_helper(_of, begin); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - left_link = 0; - while (_of->offset < end) { - opus_int64 llret; - ogg_uint32_t serialno; - llret = op_get_next_page(_of, &og, end); - if (OP_UNLIKELY(llret < OP_FALSE)) { - return llret; - } else if (llret == OP_FALSE) { - break; - } - serialno = ogg_page_serialno(&og); - if (serialno == _serialno) { - ogg_int64_t page_gp; - /*The page is from the right stream...*/ - page_gp = ogg_page_granulepos(&og); - if (page_gp != -1) { - /* And has a valid granule position. - Let's remember it.*/ - _offset = llret; - gp = page_gp; - } - } else if (OP_UNLIKELY(!op_lookup_serialno(serialno, - _serialnos, _nserialnos))) { - /* We fell off the start of the link, which means we don't need to keep - seeking any farther back.*/ - left_link = 1; - } - } - /* We started from at or before the beginning of the link and found nothing. - This should be impossible unless the contents of the stream changed out - from under us after we read from it.*/ - if ((OP_UNLIKELY(left_link) || OP_UNLIKELY(!begin)) && OP_UNLIKELY(_offset < 0)) { - return OP_EBADLINK; - } - /* Bump up the chunk size. - This is mildly helpful when seeks are very expensive (http).*/ - chunk_size = OP_MIN(2 * chunk_size, OP_CHUNK_SIZE_MAX); - /*Avoid quadratic complexity if we hit an invalid patch of the file.*/ - end = OP_MIN(begin + OP_PAGE_SIZE_MAX - 1, original_end); - } while (_offset < 0); - *_gp = gp; - return _offset; -} - -/* Uses the local ogg_stream storage in _of. - This is important for non-streaming input sources.*/ -static int op_fetch_headers_impl(OggOpusFile *_of, OpusHead *_head, - OpusTags *_tags, ogg_uint32_t **_serialnos, int *_nserialnos, - int *_cserialnos, ogg_page *_og) { - ogg_packet op; - int ret; - if (_serialnos != NULL) { - *_nserialnos = 0; - } - /* Extract the serialnos of all BOS pages plus the first set of Opus headers - we see in the link.*/ - while (ogg_page_bos(_og)) { - if (_serialnos != NULL) { - if (OP_UNLIKELY(op_lookup_page_serialno(_og, *_serialnos, *_nserialnos))) { - /*A dupe serialnumber in an initial header packet set==invalid stream.*/ - return OP_EBADHEADER; - } - ret = op_add_serialno(_og, _serialnos, _nserialnos, _cserialnos); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } - if (_of->ready_state < OP_STREAMSET) { - /* We don't have an Opus stream in this link yet, so begin prospective - stream setup. - We need a stream to get packets.*/ - ogg_stream_reset_serialno(&_of->os, ogg_page_serialno(_og)); - ogg_stream_pagein(&_of->os, _og); - if (OP_LIKELY(ogg_stream_packetout(&_of->os, &op) > 0)) { - ret = opus_head_parse(_head, op.packet, op.bytes); - /* Found a valid Opus header. - Continue setup.*/ - if (OP_LIKELY(ret >= 0)) { - _of->ready_state = OP_STREAMSET; - } - /* If it's just a stream type we don't recognize, ignore it. - Everything else is fatal.*/ - else if (ret != OP_ENOTFORMAT) { - return ret; - } - } - /*TODO: Should a BOS page with no packets be an error?*/ - } - /* Get the next page. - No need to clamp the boundary offset against _of->end, as all errors - become OP_ENOTFORMAT or OP_EBADHEADER.*/ - if (OP_UNLIKELY(op_get_next_page(_of, _og, - OP_ADV_OFFSET(_of->offset, OP_CHUNK_SIZE)) < 0)) { - return _of->ready_state < OP_STREAMSET ? OP_ENOTFORMAT : OP_EBADHEADER; - } - } - if (OP_UNLIKELY(_of->ready_state != OP_STREAMSET)) { - return OP_ENOTFORMAT; - } - /*If the first non-header page belonged to our Opus stream, submit it.*/ - if (_of->os.serialno == ogg_page_serialno(_og)) { - ogg_stream_pagein(&_of->os, _og); - } - /*Loop getting packets.*/ - for (;;) { - switch (ogg_stream_packetout(&_of->os, &op)) { - case 0: { - /*Loop getting pages.*/ - for (;;) { - /* No need to clamp the boundary offset against _of->end, as all - errors become OP_EBADHEADER.*/ - if (OP_UNLIKELY(op_get_next_page(_of, _og, - OP_ADV_OFFSET(_of->offset, OP_CHUNK_SIZE)) < 0)) { - return OP_EBADHEADER; - } - /*If this page belongs to the correct stream, go parse it.*/ - if (_of->os.serialno == ogg_page_serialno(_og)) { - ogg_stream_pagein(&_of->os, _og); - break; - } - /*If the link ends before we see the Opus comment header, abort.*/ - if (OP_UNLIKELY(ogg_page_bos(_og))) { - return OP_EBADHEADER; - } - /*Otherwise, keep looking.*/ - } - } break; - /*We shouldn't get a hole in the headers!*/ - case -1: return OP_EBADHEADER; - default: { - /* Got a packet. - It should be the comment header.*/ - ret = opus_tags_parse(_tags, op.packet, op.bytes); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - /* Make sure the page terminated at the end of the comment header. - If there is another packet on the page, or part of a packet, then - reject the stream. - Otherwise seekable sources won't be able to seek back to the start - properly.*/ - ret = ogg_stream_packetout(&_of->os, &op); - if (OP_UNLIKELY(ret != 0) - || OP_UNLIKELY(_og->header[_og->header_len - 1] == 255)) { - /*If we fail, the caller assumes our tags are uninitialized.*/ - opus_tags_clear(_tags); - return OP_EBADHEADER; - } - return 0; - } - } - } -} - -static int op_fetch_headers(OggOpusFile *_of, OpusHead *_head, - OpusTags *_tags, ogg_uint32_t **_serialnos, int *_nserialnos, - int *_cserialnos, ogg_page *_og) { - ogg_page og; - int ret; - if (!_og) { - /* No need to clamp the boundary offset against _of->end, as all errors - become OP_ENOTFORMAT.*/ - if (OP_UNLIKELY(op_get_next_page(_of, &og, - OP_ADV_OFFSET(_of->offset, OP_CHUNK_SIZE)) < 0)) { - return OP_ENOTFORMAT; - } - _og = &og; - } - _of->ready_state = OP_OPENED; - ret = op_fetch_headers_impl(_of, _head, _tags, _serialnos, _nserialnos, - _cserialnos, _og); - /* Revert back from OP_STREAMSET to OP_OPENED on failure, to prevent - double-free of the tags in an unseekable stream.*/ - if (OP_UNLIKELY(ret < 0)) { - _of->ready_state = OP_OPENED; - } - return ret; -} - -/* Granule position manipulation routines. - A granule position is defined to be an unsigned 64-bit integer, with the - special value -1 in two's complement indicating an unset or invalid granule - position. - We are not guaranteed to have an unsigned 64-bit type, so we construct the - following routines that - a) Properly order negative numbers as larger than positive numbers, and - b) Check for underflow or overflow past the special -1 value. - This lets us operate on the full, valid range of granule positions in a - consistent and safe manner. - This full range is organized into distinct regions: - [ -1 (invalid) ][ 0 ... OP_INT64_MAX ][ OP_INT64_MIN ... -2 ][-1 (invalid) ] - - No one should actually use granule positions so large that they're negative, - even if they are technically valid, as very little software handles them - correctly (including most of Xiph.Org's). - This library also refuses to support durations so large they won't fit in a - signed 64-bit integer (to avoid exposing this mess to the application, and - to simplify a good deal of internal arithmetic), so the only way to use them - successfully is if pcm_start is very large. - This means there isn't anything you can do with negative granule positions - that you couldn't have done with purely non-negative ones. - The main purpose of these routines is to allow us to think very explicitly - about the possible failure cases of all granule position manipulations.*/ - -/* Safely adds a small signed integer to a valid (not -1) granule position. - The result can use the full 64-bit range of values (both positive and - negative), but will fail on overflow (wrapping past -1; wrapping past - OP_INT64_MAX is explicitly okay). - [out] _dst_gp: The resulting granule position. - Only modified on success. - _src_gp: The granule position to add to. - This must not be -1. - _delta: The amount to add. - This is allowed to be up to 32 bits to support the maximum - duration of a single Ogg page (255 packets * 120 ms per - packet == 1,468,800 samples at 48 kHz). - Return: 0 on success, or OP_EINVAL if the result would wrap around past -1.*/ -static int op_granpos_add(ogg_int64_t *_dst_gp, ogg_int64_t _src_gp, - opus_int32 _delta) { - /* The code below handles this case correctly, but there's no reason we - should ever be called with these values, so make sure we aren't.*/ - OP_ASSERT(_src_gp != -1); - if (_delta > 0) { - /* Adding this amount to the granule position would overflow its 64-bit - range.*/ - if (OP_UNLIKELY(_src_gp < 0) && OP_UNLIKELY(_src_gp >= -1 - _delta)) { - return OP_EINVAL; - } - if (OP_UNLIKELY(_src_gp > OP_INT64_MAX - _delta)) { - /* Adding this amount to the granule position would overflow the positive - half of its 64-bit range. - Since signed overflow is undefined in C, do it in a way the compiler - isn't allowed to screw up.*/ - _delta -= (opus_int32)(OP_INT64_MAX - _src_gp) + 1; - _src_gp = OP_INT64_MIN; - } - } else if (_delta < 0) { - /* Subtracting this amount from the granule position would underflow its - 64-bit range.*/ - if (_src_gp >= 0 && OP_UNLIKELY(_src_gp < -_delta)) { - return OP_EINVAL; - } - if (OP_UNLIKELY(_src_gp < OP_INT64_MIN - _delta)) { - /* Subtracting this amount from the granule position would underflow the - negative half of its 64-bit range. - Since signed underflow is undefined in C, do it in a way the compiler - isn't allowed to screw up.*/ - _delta += (opus_int32)(_src_gp - OP_INT64_MIN) + 1; - _src_gp = OP_INT64_MAX; - } - } - *_dst_gp = _src_gp + _delta; - return 0; -} - -/* Safely computes the difference between two granule positions. - The difference must fit in a signed 64-bit integer, or the function fails. - It correctly handles the case where the granule position has wrapped around - from positive values to negative ones. - [out] _delta: The difference between the granule positions. - Only modified on success. - _gp_a: The granule position to subtract from. - This must not be -1. - _gp_b: The granule position to subtract. - This must not be -1. - Return: 0 on success, or OP_EINVAL if the result would not fit in a signed - 64-bit integer.*/ -static int op_granpos_diff(ogg_int64_t *_delta, - ogg_int64_t _gp_a, ogg_int64_t _gp_b) { - int gp_a_negative; - int gp_b_negative; - /* The code below handles these cases correctly, but there's no reason we - should ever be called with these values, so make sure we aren't.*/ - OP_ASSERT(_gp_a != -1); - OP_ASSERT(_gp_b != -1); - gp_a_negative = OP_UNLIKELY(_gp_a < 0); - gp_b_negative = OP_UNLIKELY(_gp_b < 0); - if (OP_UNLIKELY(gp_a_negative ^ gp_b_negative)) { - ogg_int64_t da; - ogg_int64_t db; - if (gp_a_negative) { - /* _gp_a has wrapped to a negative value but _gp_b hasn't: the difference - should be positive.*/ - /*Step 1: Handle wrapping.*/ - /*_gp_a < 0 => da < 0.*/ - da = (OP_INT64_MIN - _gp_a) - 1; - /*_gp_b >= 0 => db >= 0.*/ - db = OP_INT64_MAX - _gp_b; - /*Step 2: Check for overflow.*/ - if (OP_UNLIKELY(OP_INT64_MAX + da < db)) { - return OP_EINVAL; - } - *_delta = db - da; - } else { - /* _gp_b has wrapped to a negative value but _gp_a hasn't: the difference - should be negative.*/ - /*Step 1: Handle wrapping.*/ - /*_gp_a >= 0 => da <= 0*/ - da = _gp_a + OP_INT64_MIN; - /*_gp_b < 0 => db <= 0*/ - db = OP_INT64_MIN - _gp_b; - /*Step 2: Check for overflow.*/ - if (OP_UNLIKELY(da < OP_INT64_MIN - db)) { - return OP_EINVAL; - } - *_delta = da + db; - } - } else { - *_delta = _gp_a - _gp_b; - } - return 0; -} - -static int op_granpos_cmp(ogg_int64_t _gp_a, ogg_int64_t _gp_b) { - /* The invalid granule position -1 should behave like NaN: neither greater - than nor less than any other granule position, nor equal to any other - granule position, including itself. - However, that means there isn't anything we could sensibly return from this - function for it.*/ - OP_ASSERT(_gp_a != -1); - OP_ASSERT(_gp_b != -1); - /*Handle the wrapping cases.*/ - if (OP_UNLIKELY(_gp_a < 0)) { - if (_gp_b >= 0) { - return 1; - } - /*Else fall through.*/ - } else if (OP_UNLIKELY(_gp_b < 0)) { - return -1; - } - /*No wrapping case.*/ - return (_gp_a > _gp_b) - (_gp_b > _gp_a); -} - -/* Returns the duration of the packet (in samples at 48 kHz), or a negative - value on error.*/ -static int op_get_packet_duration(const unsigned char *_data, int _len) { - int nframes; - int frame_size; - int nsamples; - nframes = opus_packet_get_nb_frames(_data, _len); - if (OP_UNLIKELY(nframes < 0)) { - return OP_EBADPACKET; - } - frame_size = opus_packet_get_samples_per_frame(_data, 48000); - nsamples = nframes * frame_size; - if (OP_UNLIKELY(nsamples > 120 * 48)) { - return OP_EBADPACKET; - } - return nsamples; -} - -/* This function more properly belongs in info.c, but we define it here to allow - the static granule position manipulation functions to remain static.*/ -ogg_int64_t opus_granule_sample(const OpusHead *_head, ogg_int64_t _gp) { - opus_int32 pre_skip; - pre_skip = _head->pre_skip; - if (_gp != -1 && op_granpos_add(&_gp, _gp, -pre_skip)) { - _gp = -1; - } - return _gp; -} - -/* Grab all the packets currently in the stream state, and compute their - durations. - _of->op_count is set to the number of packets collected. - [out] _durations: Returns the durations of the individual packets. - Return: The total duration of all packets, or OP_HOLE if there was a hole.*/ -static opus_int32 op_collect_audio_packets(OggOpusFile *_of, - int _durations[255]) { - opus_int32 total_duration; - int op_count; - /*Count the durations of all packets in the page.*/ - op_count = 0; - total_duration = 0; - for (;;) { - int ret; - /* This takes advantage of undocumented libogg behavior that returned - ogg_packet buffers are valid at least until the next page is - submitted. - Relying on this is not too terrible, as _none_ of the Ogg memory - ownership/lifetime rules are well-documented. - But I can read its code and know this will work.*/ - ret = ogg_stream_packetout(&_of->os, _of->op + op_count); - if (!ret) { - break; - } - if (OP_UNLIKELY(ret < 0)) { - /*We shouldn't get holes in the middle of pages.*/ - OP_ASSERT(op_count == 0); - /* Set the return value and break out of the loop. - We want to make sure op_count gets set to 0, because we've ingested a - page, so any previously loaded packets are now invalid.*/ - total_duration = OP_HOLE; - break; - } - /* Unless libogg is broken, we can't get more than 255 packets from a - single page.*/ - OP_ASSERT(op_count < 255); - _durations[op_count] = op_get_packet_duration(_of->op[op_count].packet, - _of->op[op_count].bytes); - if (OP_LIKELY(_durations[op_count] > 0)) { - /*With at most 255 packets on a page, this can't overflow.*/ - total_duration += _durations[op_count++]; - } - /*Ignore packets with an invalid TOC sequence.*/ - else if (op_count > 0) { - /*But save the granule position, if there was one.*/ - _of->op[op_count - 1].granulepos = _of->op[op_count].granulepos; - } - } - _of->op_pos = 0; - _of->op_count = op_count; - return total_duration; -} - -/* Starting from current cursor position, get the initial PCM offset of the next - page. - This also validates the granule position on the first page with a completed - audio data packet, as required by the spec. - If this link is completely empty (no pages with completed packets), then this - function sets pcm_start=pcm_end=0 and returns the BOS page of the next link - (if any). - In the seekable case, we initialize pcm_end=-1 before calling this function, - so that later we can detect that the link was empty before calling - op_find_final_pcm_offset(). - [inout] _link: The link for which to find pcm_start. - [out] _og: Returns the BOS page of the next link if this link was empty. - In the unseekable case, we can then feed this to - op_fetch_headers() to start the next link. - The caller may pass NULL (e.g., for seekable streams), in - which case this page will be discarded. - Return: 0 on success, 1 if there is a buffered BOS page available, or a - negative value on unrecoverable error.*/ -static int op_find_initial_pcm_offset(OggOpusFile *_of, - OggOpusLink *_link, ogg_page *_og) { - ogg_page og; - opus_int64 page_offset; - ogg_int64_t pcm_start; - ogg_int64_t prev_packet_gp; - ogg_int64_t cur_page_gp; - ogg_uint32_t serialno; - opus_int32 total_duration; - int *durations = (int*)malloc(255 * sizeof(int)); - int cur_page_eos; - int op_count; - int pi; - if (_og == NULL) { - _og = &og; - } - serialno = _of->os.serialno; - op_count = 0; - /* We shouldn't have to initialize total_duration, but gcc is too dumb to - figure out that op_count>0 implies we've been through the whole loop at - least once.*/ - total_duration = 0; - do { - page_offset = op_get_next_page(_of, _og, _of->end); - /* We should get a page unless the file is truncated or mangled. - Otherwise there are no audio data packets in the whole logical stream.*/ - if (OP_UNLIKELY(page_offset < 0)) { - /*Fail if there was a read error.*/ - if (page_offset < OP_FALSE) { - free(durations); - return (int)page_offset; - } - /* Fail if the pre-skip is non-zero, since it's asking us to skip more - samples than exist.*/ - if (_link->head.pre_skip > 0) { - free(durations); - return OP_EBADTIMESTAMP; - } - _link->pcm_file_offset = 0; - /* Set pcm_end and end_offset so we can skip the call to - op_find_final_pcm_offset().*/ - _link->pcm_start = _link->pcm_end = 0; - _link->end_offset = _link->data_offset; - free(durations); - return 0; - } - /*Similarly, if we hit the next link in the chain, we've gone too far.*/ - if (OP_UNLIKELY(ogg_page_bos(_og))) { - if (_link->head.pre_skip > 0) { - free(durations); - return OP_EBADTIMESTAMP; - } - /* Set pcm_end and end_offset so we can skip the call to - op_find_final_pcm_offset().*/ - _link->pcm_file_offset = 0; - _link->pcm_start = _link->pcm_end = 0; - _link->end_offset = _link->data_offset; - /*Tell the caller we've got a buffered page for them.*/ - free(durations); - return 1; - } - /* Ignore pages from other streams (not strictly necessary, because of the - checks in ogg_stream_pagein(), but saves some work).*/ - if (serialno != (ogg_uint32_t)ogg_page_serialno(_og)) { - continue; - } - ogg_stream_pagein(&_of->os, _og); - /* Bitrate tracking: add the header's bytes here. - The body bytes are counted when we consume the packets.*/ - _of->bytes_tracked += _og->header_len; - /*Count the durations of all packets in the page.*/ - do { - total_duration = op_collect_audio_packets(_of, durations); - } - /*Ignore holes.*/ - while (OP_UNLIKELY(total_duration < 0)); - op_count = _of->op_count; - } while (op_count <= 0); - /* We found the first page with a completed audio data packet: actually look - at the granule position. - RFC 3533 says, "A special value of -1 (in two's complement) indicates that - no packets finish on this page," which does not say that a granule - position that is NOT -1 indicates that some packets DO finish on that page - (even though this was the intention, libogg itself violated this intention - for years before we fixed it). - The Ogg Opus specification only imposes its start-time requirements - on the granule position of the first page with completed packets, - so we ignore any set granule positions until then.*/ - cur_page_gp = _of->op[op_count - 1].granulepos; - /* But getting a packet without a valid granule position on the page is not - okay.*/ - if (cur_page_gp == -1) { - free(durations); - return OP_EBADTIMESTAMP; - } - cur_page_eos = _of->op[op_count - 1].e_o_s; - if (OP_LIKELY(!cur_page_eos)) { - /* The EOS flag wasn't set. - Work backwards from the provided granule position to get the starting PCM - offset.*/ - if (OP_UNLIKELY(op_granpos_add(&pcm_start, cur_page_gp, -total_duration) < 0)) { - /* The starting granule position MUST not be smaller than the amount of - audio on the first page with completed packets.*/ - free(durations); - return OP_EBADTIMESTAMP; - } - } else { - /*The first page with completed packets was also the last.*/ - if (OP_LIKELY(op_granpos_add(&pcm_start, cur_page_gp, -total_duration) < 0)) { - /* If there's less audio on the page than indicated by the granule - position, then we're doing end-trimming, and the starting PCM offset - is zero by spec mandate.*/ - pcm_start = 0; - /* However, the end-trimming MUST not ask us to trim more samples than - exist after applying the pre-skip.*/ - if (OP_UNLIKELY(op_granpos_cmp(cur_page_gp, _link->head.pre_skip) < 0)) { - free(durations); - return OP_EBADTIMESTAMP; - } - } - } - /*Timestamp the individual packets.*/ - prev_packet_gp = pcm_start; - for (pi = 0; pi < op_count; pi++) { - if (cur_page_eos) { - ogg_int64_t diff; - OP_ALWAYS_TRUE(!op_granpos_diff(&diff, cur_page_gp, prev_packet_gp)); - diff = durations[pi] - diff; - /*If we have samples to trim...*/ - if (diff > 0) { - /* If we trimmed the entire packet, stop (the spec says encoders - shouldn't do this, but we support it anyway).*/ - if (OP_UNLIKELY(diff > durations[pi])) { - break; - } - _of->op[pi].granulepos = prev_packet_gp = cur_page_gp; - /* Move the EOS flag to this packet, if necessary, so we'll trim the - samples.*/ - _of->op[pi].e_o_s = 1; - continue; - } - } - /*Update the granule position as normal.*/ - OP_ALWAYS_TRUE(!op_granpos_add(&_of->op[pi].granulepos, - prev_packet_gp, durations[pi])); - prev_packet_gp = _of->op[pi].granulepos; - } - /*Update the packet count after end-trimming.*/ - _of->op_count = pi; - _of->cur_discard_count = _link->head.pre_skip; - _link->pcm_file_offset = 0; - _of->prev_packet_gp = _link->pcm_start = pcm_start; - _of->prev_page_offset = page_offset; - free(durations); - return 0; -} - -/* Starting from current cursor position, get the final PCM offset of the - previous page. - This also validates the duration of the link, which, while not strictly - required by the spec, we need to ensure duration calculations don't - overflow. - This is only done for seekable sources. - We must validate that op_find_initial_pcm_offset() succeeded for this link - before calling this function, otherwise it will scan the entire stream - backwards until it reaches the start, and then fail.*/ -static int op_find_final_pcm_offset(OggOpusFile *_of, - const ogg_uint32_t *_serialnos, int _nserialnos, OggOpusLink *_link, - opus_int64 _offset, ogg_uint32_t _end_serialno, ogg_int64_t _end_gp, - ogg_int64_t *_total_duration) { - ogg_int64_t total_duration; - ogg_int64_t duration; - ogg_uint32_t cur_serialno; - /*For the time being, fetch end PCM offset the simple way.*/ - cur_serialno = _link->serialno; - if (_end_serialno != cur_serialno || _end_gp == -1) { - _offset = op_get_last_page(_of, &_end_gp, _offset, - cur_serialno, _serialnos, _nserialnos); - if (OP_UNLIKELY(_offset < 0)) { - return (int)_offset; - } - } - /*At worst we should have found the first page with completed packets.*/ - if (OP_UNLIKELY(_offset < _link->data_offset)) { - return OP_EBADLINK; - } - /* This implementation requires that the difference between the first and last - granule positions in each link be representable in a signed, 64-bit - number, and that each link also have at least as many samples as the - pre-skip requires.*/ - if (OP_UNLIKELY(op_granpos_diff(&duration, _end_gp, _link->pcm_start) < 0) - || OP_UNLIKELY(duration < _link->head.pre_skip)) { - return OP_EBADTIMESTAMP; - } - /* We also require that the total duration be representable in a signed, - 64-bit number.*/ - duration -= _link->head.pre_skip; - total_duration = *_total_duration; - if (OP_UNLIKELY(OP_INT64_MAX - duration < total_duration)) { - return OP_EBADTIMESTAMP; - } - *_total_duration = total_duration + duration; - _link->pcm_end = _end_gp; - _link->end_offset = _offset; - return 0; -} - -/* Rescale the number _x from the range [0,_from] to [0,_to]. - _from and _to must be positive.*/ -static opus_int64 op_rescale64(opus_int64 _x, opus_int64 _from, opus_int64 _to) { - opus_int64 frac; - opus_int64 ret; - int i; - if (_x >= _from) { - return _to; - } - if (_x <= 0) { - return 0; - } - frac = 0; - for (i = 0; i < 63; i++) { - frac <<= 1; - OP_ASSERT(_x <= _from); - if (_x >= _from >> 1) { - _x -= _from - _x; - frac |= 1; - } else { - _x <<= 1; - } - } - ret = 0; - for (i = 0; i < 63; i++) { - if (frac & 1) { - ret = (ret & _to & 1) + (ret >> 1) + (_to >> 1); - } else { - ret >>= 1; - } - frac >>= 1; - } - return ret; -} - -/* The minimum granule position spacing allowed for making predictions. - This corresponds to about 1 second of audio at 48 kHz for both Opus and - Vorbis, or one keyframe interval in Theora with the default keyframe spacing - of 256.*/ -#define OP_GP_SPACING_MIN (48000) - -/* Try to estimate the location of the next link using the current seek - records, assuming the initial granule position of any streams we've found is - 0.*/ -static opus_int64 op_predict_link_start(const OpusSeekRecord *_sr, int _nsr, - opus_int64 _searched, opus_int64 _end_searched, opus_int32 _bias) { - opus_int64 bisect; - int sri; - int srj; - /* Require that we be at least OP_CHUNK_SIZE from the end. - We don't require that we be at least OP_CHUNK_SIZE from the beginning, - because if we are we'll just scan forward without seeking.*/ - _end_searched -= OP_CHUNK_SIZE; - if (_searched >= _end_searched) { - return -1; - } - bisect = _end_searched; - for (sri = 0; sri < _nsr; sri++) { - ogg_int64_t gp1; - ogg_int64_t gp2_min; - ogg_uint32_t serialno1; - opus_int64 offset1; - /* If the granule position is negative, either it's invalid or we'd cause - overflow.*/ - gp1 = _sr[sri].gp; - if (gp1 < 0) { - continue; - } - /* We require some minimum distance between granule positions to make an - estimate. - We don't actually know what granule position scheme is being used, - because we have no idea what kind of stream these came from. - Therefore we require a minimum spacing between them, with the - expectation that while bitrates and granule position increments might - vary locally in quite complex ways, they are globally smooth.*/ - if (OP_UNLIKELY(op_granpos_add(&gp2_min, gp1, OP_GP_SPACING_MIN) < 0)) { - /*No granule position would satisfy us.*/ - continue; - } - offset1 = _sr[sri].offset; - serialno1 = _sr[sri].serialno; - for (srj = sri; srj-- > 0;) { - ogg_int64_t gp2; - opus_int64 offset2; - opus_int64 num; - ogg_int64_t den; - ogg_int64_t ipart; - gp2 = _sr[srj].gp; - if (gp2 < gp2_min) { - continue; - } - /*Oh, and also make sure these came from the same stream.*/ - if (_sr[srj].serialno != serialno1) { - continue; - } - offset2 = _sr[srj].offset; - /*For once, we can subtract with impunity.*/ - den = gp2 - gp1; - ipart = gp2 / den; - num = offset2 - offset1; - OP_ASSERT(num > 0); - if (ipart > 0 && (offset2 - _searched) / ipart < num) { - continue; - } - offset2 -= ipart * num; - gp2 -= ipart * den; - offset2 -= op_rescale64(gp2, den, num) - _bias; - if (offset2 < _searched) { - continue; - } - bisect = OP_MIN(bisect, offset2); - break; - } - } - return bisect >= _end_searched ? -1 : bisect; -} - -/* Finds each bitstream link, one at a time, using a bisection search. - This has to begin by knowing the offset of the first link's initial page.*/ -static int op_bisect_forward_serialno(OggOpusFile *_of, - opus_int64 _searched, OpusSeekRecord *_sr, int _csr, - ogg_uint32_t **_serialnos, int *_nserialnos, int *_cserialnos) { - ogg_page og; - OggOpusLink *links; - int nlinks; - int clinks; - ogg_uint32_t *serialnos; - int nserialnos; - ogg_int64_t total_duration; - int nsr; - int ret; - links = _of->links; - nlinks = clinks = _of->nlinks; - total_duration = 0; - /* We start with one seek record, for the last page in the file. - We build up a list of records for places we seek to during link - enumeration. - This list is kept sorted in reverse order. - We only care about seek locations that were _not_ in the current link, - therefore we can add them one at a time to the end of the list as we - improve the lower bound on the location where the next link starts.*/ - nsr = 1; - for (;;) { - opus_int64 end_searched; - opus_int64 bisect; - opus_int64 next; - opus_int64 last; - ogg_int64_t end_offset; - ogg_int64_t end_gp; - int sri; - serialnos = *_serialnos; - nserialnos = *_nserialnos; - if (OP_UNLIKELY(nlinks >= clinks)) { - if (OP_UNLIKELY(clinks > INT_MAX - 1 >> 1)) { - return OP_EFAULT; - } - clinks = 2 * clinks + 1; - OP_ASSERT(nlinks < clinks); - links = (OggOpusLink *)_ogg_realloc(links, sizeof(*links) * clinks); - if (OP_UNLIKELY(links == NULL)) { - return OP_EFAULT; - } - _of->links = links; - } - /* Invariants: - We have the headers and serial numbers for the link beginning at 'begin'. - We have the offset and granule position of the last page in the file - (potentially not a page we care about).*/ - /*Scan the seek records we already have to save us some bisection.*/ - for (sri = 0; sri < nsr; sri++) { - if (op_lookup_serialno(_sr[sri].serialno, serialnos, nserialnos)) { - break; - } - } - /*Is the last page in our current list of serial numbers?*/ - if (sri <= 0) { - break; - } - /* Last page wasn't found. - We have at least one more link.*/ - last = -1; - end_searched = _sr[sri - 1].search_start; - next = _sr[sri - 1].offset; - end_gp = -1; - if (sri < nsr) { - _searched = _sr[sri].offset + _sr[sri].size; - if (_sr[sri].serialno == links[nlinks - 1].serialno) { - end_gp = _sr[sri].gp; - end_offset = _sr[sri].offset; - } - } - nsr = sri; - bisect = -1; - /* If we've already found the end of at least one link, try to pick the - first bisection point at twice the average link size. - This is a good choice for files with lots of links that are all about the - same size.*/ - if (nlinks > 1) { - opus_int64 last_offset; - opus_int64 avg_link_size; - opus_int64 upper_limit; - last_offset = links[nlinks - 1].offset; - avg_link_size = last_offset / (nlinks - 1); - upper_limit = end_searched - OP_CHUNK_SIZE - avg_link_size; - if (OP_LIKELY(last_offset > _searched - avg_link_size) - && OP_LIKELY(last_offset < upper_limit)) { - bisect = last_offset + avg_link_size; - if (OP_LIKELY(bisect < upper_limit)) { - bisect += avg_link_size; - } - } - } - /* We guard against garbage separating the last and first pages of two - links below.*/ - while (_searched < end_searched) { - opus_int32 next_bias; - /*If we don't have a better estimate, use simple bisection.*/ - if (bisect == -1) { - bisect = _searched + (end_searched - _searched >> 1); - } - /*If we're within OP_CHUNK_SIZE of the start, scan forward.*/ - if (bisect - _searched < OP_CHUNK_SIZE) { - bisect = _searched; - } - /* Otherwise we're skipping data. - Forget the end page, if we saw one, as we might miss a later one.*/ - else { - end_gp = -1; - } - ret = op_seek_helper(_of, bisect); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - last = op_get_next_page(_of, &og, _sr[nsr - 1].offset); - if (OP_UNLIKELY(last < OP_FALSE)) { - return (int)last; - } - next_bias = 0; - if (last == OP_FALSE) { - end_searched = bisect; - } else { - ogg_uint32_t serialno; - ogg_int64_t gp; - serialno = ogg_page_serialno(&og); - gp = ogg_page_granulepos(&og); - if (!op_lookup_serialno(serialno, serialnos, nserialnos)) { - end_searched = bisect; - next = last; - /*In reality we should always have enough room, but be paranoid.*/ - if (OP_LIKELY(nsr < _csr)) { - _sr[nsr].search_start = bisect; - _sr[nsr].offset = last; - OP_ASSERT(_of->offset - last >= 0); - OP_ASSERT(_of->offset - last <= OP_PAGE_SIZE_MAX); - _sr[nsr].size = (opus_int32)(_of->offset - last); - _sr[nsr].serialno = serialno; - _sr[nsr].gp = gp; - nsr++; - } - } else { - _searched = _of->offset; - next_bias = OP_CHUNK_SIZE; - if (serialno == links[nlinks - 1].serialno) { - /* This page was from the stream we want, remember it. - If it's the last such page in the link, we won't have to go back - looking for it later.*/ - end_gp = gp; - end_offset = last; - } - } - } - bisect = op_predict_link_start(_sr, nsr, _searched, end_searched, next_bias); - } - /* Bisection point found. - Get the final granule position of the previous link, assuming - op_find_initial_pcm_offset() didn't already determine the link was - empty.*/ - if (OP_LIKELY(links[nlinks - 1].pcm_end == -1)) { - if (end_gp == -1) { - /* If we don't know where the end page is, we'll have to seek back and - look for it, starting from the end of the link.*/ - end_offset = next; - /* Also forget the last page we read. - It won't be available after the seek.*/ - last = -1; - } - ret = op_find_final_pcm_offset(_of, serialnos, nserialnos, - links + nlinks - 1, end_offset, links[nlinks - 1].serialno, end_gp, - &total_duration); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } - if (last != next) { - /* The last page we read was not the first page the next link. - Move the cursor position to the offset of that first page. - This only performs an actual seek if the first page of the next link - does not start at the end of the last page from the current Opus - stream with a valid granule position.*/ - ret = op_seek_helper(_of, next); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } - ret = op_fetch_headers(_of, &links[nlinks].head, &links[nlinks].tags, - _serialnos, _nserialnos, _cserialnos, last != next ? NULL : &og); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - links[nlinks].offset = next; - links[nlinks].data_offset = _of->offset; - links[nlinks].serialno = _of->os.serialno; - links[nlinks].pcm_end = -1; - /* This might consume a page from the next link, however the next bisection - always starts with a seek.*/ - ret = op_find_initial_pcm_offset(_of, links + nlinks, NULL); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - links[nlinks].pcm_file_offset = total_duration; - _searched = _of->offset; - /*Mark the current link count so it can be cleaned up on error.*/ - _of->nlinks = ++nlinks; - } - /* Last page is in the starting serialno list, so we've reached the last link. - Now find the last granule position for it (if we didn't the first time we - looked at the end of the stream, and if op_find_initial_pcm_offset() - didn't already determine the link was empty).*/ - if (OP_LIKELY(links[nlinks - 1].pcm_end == -1)) { - ret = op_find_final_pcm_offset(_of, serialnos, nserialnos, - links + nlinks - 1, _sr[0].offset, _sr[0].serialno, _sr[0].gp, &total_duration); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } - /*Trim back the links array if necessary.*/ - links = (OggOpusLink *)_ogg_realloc(links, sizeof(*links) * nlinks); - if (OP_LIKELY(links != NULL)) { - _of->links = links; - } - /*We also don't need these anymore.*/ - _ogg_free(*_serialnos); - *_serialnos = NULL; - *_cserialnos = *_nserialnos = 0; - return 0; -} - -static void op_update_gain(OggOpusFile *_of) { - OpusHead *head; - opus_int32 gain_q8; - int li; - /* If decode isn't ready, then we'll apply the gain when we initialize the - decoder.*/ - if (_of->ready_state < OP_INITSET) { - return; - } - gain_q8 = _of->gain_offset_q8; - li = _of->seekable ? _of->cur_link : 0; - head = &_of->links[li].head; - /* We don't have to worry about overflow here because the header gain and - track gain must lie in the range [-32768,32767], and the user-supplied - offset has been pre-clamped to [-98302,98303].*/ - switch (_of->gain_type) { - case OP_ALBUM_GAIN: { - int album_gain_q8; - album_gain_q8 = 0; - opus_tags_get_album_gain(&_of->links[li].tags, &album_gain_q8); - gain_q8 += album_gain_q8; - gain_q8 += head->output_gain; - } break; - case OP_TRACK_GAIN: { - int track_gain_q8; - track_gain_q8 = 0; - opus_tags_get_track_gain(&_of->links[li].tags, &track_gain_q8); - gain_q8 += track_gain_q8; - gain_q8 += head->output_gain; - } break; - case OP_HEADER_GAIN: gain_q8 += head->output_gain; break; - case OP_ABSOLUTE_GAIN: break; - default: OP_ASSERT(0); - } - gain_q8 = OP_CLAMP(-32768, gain_q8, 32767); - OP_ASSERT(_of->od != NULL); -#if defined(OPUS_SET_GAIN) - opus_multistream_decoder_ctl(_of->od, OPUS_SET_GAIN(gain_q8)); -#else - /* A fallback that works with both float and fixed-point is a bunch of work, - so just force people to use a sufficiently new version. - This is deployed well enough at this point that this shouldn't be a burden.*/ -# error "libopus 1.0.1 or later required" -#endif -} - -static int op_make_decode_ready(OggOpusFile *_of) { - const OpusHead *head; - int li; - int stream_count; - int coupled_count; - int channel_count; - if (_of->ready_state > OP_STREAMSET) { - return 0; - } - if (OP_UNLIKELY(_of->ready_state < OP_STREAMSET)) { - return OP_EFAULT; - } - li = _of->seekable ? _of->cur_link : 0; - head = &_of->links[li].head; - stream_count = head->stream_count; - coupled_count = head->coupled_count; - channel_count = head->channel_count; - /*Check to see if the current decoder is compatible with the current link.*/ - if (_of->od != NULL && _of->od_stream_count == stream_count - && _of->od_coupled_count == coupled_count && _of->od_channel_count == channel_count - && memcmp(_of->od_mapping, head->mapping, - sizeof(*head->mapping)*channel_count) == 0) { - opus_multistream_decoder_ctl(_of->od, OPUS_RESET_STATE); - } else { - int err; - opus_multistream_decoder_destroy(_of->od); - _of->od = opus_multistream_decoder_create(48000, channel_count, - stream_count, coupled_count, head->mapping, &err); - if (_of->od == NULL) { - return OP_EFAULT; - } - _of->od_stream_count = stream_count; - _of->od_coupled_count = coupled_count; - _of->od_channel_count = channel_count; - memcpy(_of->od_mapping, head->mapping, sizeof(*head->mapping)*channel_count); - } - _of->ready_state = OP_INITSET; - _of->bytes_tracked = 0; - _of->samples_tracked = 0; -#if !defined(OP_FIXED_POINT) - _of->state_channel_count = 0; - /* Use the serial number for the PRNG seed to get repeatable output for - straight play-throughs.*/ - _of->dither_seed = _of->links[li].serialno; -#endif - op_update_gain(_of); - return 0; -} - -static int op_open_seekable2_impl(OggOpusFile *_of) { - /* 64 seek records should be enough for anybody. - Actually, with a bisection search in a 63-bit range down to OP_CHUNK_SIZE - granularity, much more than enough.*/ - OpusSeekRecord *sr = (OpusSeekRecord*)malloc(64 * sizeof(OpusSeekRecord)); - opus_int64 data_offset; - int ret; - /*We can seek, so set out learning all about this file.*/ - (*_of->callbacks.seek)(_of->stream, 0, SEEK_END); - _of->offset = _of->end = (*_of->callbacks.tell)(_of->stream); - if (OP_UNLIKELY(_of->end < 0)) { - free(sr); - return OP_EREAD; - } - data_offset = _of->links[0].data_offset; - if (OP_UNLIKELY(_of->end < data_offset)) { - free(sr); - return OP_EBADLINK; - } - /* Get the offset of the last page of the physical bitstream, or, if we're - lucky, the last Opus page of the first link, as most Ogg Opus files will - contain a single logical bitstream.*/ - ret = op_get_prev_page_serial(_of, sr, _of->end, - _of->links[0].serialno, _of->serialnos, _of->nserialnos); - if (OP_UNLIKELY(ret < 0)) { - free(sr); - return ret; - } - /*If there's any trailing junk, forget about it.*/ - _of->end = sr[0].offset + sr[0].size; - if (OP_UNLIKELY(_of->end < data_offset)) { - free(sr); - return OP_EBADLINK; - } - /*Now enumerate the bitstream structure.*/ - ret = op_bisect_forward_serialno(_of, data_offset, sr, 64, - &_of->serialnos, &_of->nserialnos, &_of->cserialnos); - free(sr); - return ret; -} - -static int op_open_seekable2(OggOpusFile *_of) { - ogg_sync_state oy_start; - ogg_stream_state *os_start = (ogg_stream_state*)malloc(sizeof(ogg_stream_state)); - ogg_packet *op_start; - opus_int64 prev_page_offset; - opus_int64 start_offset; - int start_op_count; - int ret; - /* We're partially open and have a first link header state in storage in _of. - Save off that stream state so we can come back to it. - It would be simpler to just dump all this state and seek back to - links[0].data_offset when we're done. - But we do the extra work to allow us to seek back to _exactly_ the same - stream position we're at now. - This allows, e.g., the HTTP backend to continue reading from the original - connection (if it's still available), instead of opening a new one. - This means we can open and start playing a normal Opus file with a single - link and reasonable packet sizes using only two HTTP requests.*/ - start_op_count = _of->op_count; - /*This is a bit too large to put on the stack unconditionally.*/ - op_start = (ogg_packet *)_ogg_malloc(sizeof(*op_start) * start_op_count); - if (op_start == NULL) { - free(os_start); - return OP_EFAULT; - } - *&oy_start = _of->oy; - *os_start = _of->os; - prev_page_offset = _of->prev_page_offset; - start_offset = _of->offset; - memcpy(op_start, _of->op, sizeof(*op_start)*start_op_count); - OP_ASSERT((*_of->callbacks.tell)(_of->stream) == op_position(_of)); - ogg_sync_init(&_of->oy); - ogg_stream_init(&_of->os, -1); - ret = op_open_seekable2_impl(_of); - /*Restore the old stream state.*/ - ogg_stream_clear(&_of->os); - ogg_sync_clear(&_of->oy); - *&_of->oy = *&oy_start; - *&_of->os = *os_start; - _of->offset = start_offset; - _of->op_count = start_op_count; - memcpy(_of->op, op_start, sizeof(*_of->op)*start_op_count); - _ogg_free(op_start); - _of->prev_packet_gp = _of->links[0].pcm_start; - _of->prev_page_offset = prev_page_offset; - _of->cur_discard_count = _of->links[0].head.pre_skip; - if (OP_UNLIKELY(ret < 0)) { - free(os_start); - return ret; - } - /*And restore the position indicator.*/ - ret = (*_of->callbacks.seek)(_of->stream, op_position(_of), SEEK_SET); - free(os_start); - return OP_UNLIKELY(ret < 0) ? OP_EREAD : 0; -} - -/*Clear out the current logical bitstream decoder.*/ -static void op_decode_clear(OggOpusFile *_of) { - /* We don't actually free the decoder. - We might be able to reuse it for the next link.*/ - _of->op_count = 0; - _of->od_buffer_size = 0; - _of->prev_packet_gp = -1; - _of->prev_page_offset = -1; - if (!_of->seekable) { - OP_ASSERT(_of->ready_state >= OP_INITSET); - opus_tags_clear(&_of->links[0].tags); - } - _of->ready_state = OP_OPENED; -} - -static void op_clear(OggOpusFile *_of) { - OggOpusLink *links; - _ogg_free(_of->od_buffer); - if (_of->od != NULL) { - opus_multistream_decoder_destroy(_of->od); - } - links = _of->links; - if (!_of->seekable) { - if (_of->ready_state > OP_OPENED || _of->ready_state == OP_PARTOPEN) { - opus_tags_clear(&links[0].tags); - } - } else if (OP_LIKELY(links != NULL)) { - int nlinks; - int link; - nlinks = _of->nlinks; - for (link = 0; link < nlinks; link++) { - opus_tags_clear(&links[link].tags); - } - } - _ogg_free(links); - _ogg_free(_of->serialnos); - ogg_stream_clear(&_of->os); - ogg_sync_clear(&_of->oy); - if (_of->callbacks.close != NULL) { - (*_of->callbacks.close)(_of->stream); - } -} - -static int op_open1(OggOpusFile *_of, - void *_stream, const OpusFileCallbacks *_cb, - const unsigned char *_initial_data, size_t _initial_bytes) { - ogg_page og; - ogg_page *pog; - int seekable; - int ret; - memset(_of, 0, sizeof(*_of)); - if (OP_UNLIKELY(_initial_bytes > (size_t)LONG_MAX)) { - return OP_EFAULT; - } - _of->end = -1; - _of->stream = _stream; - *&_of->callbacks = *_cb; - /*At a minimum, we need to be able to read data.*/ - if (OP_UNLIKELY(_of->callbacks.read == NULL)) { - return OP_EREAD; - } - /*Initialize the framing state.*/ - ogg_sync_init(&_of->oy); - /* Perhaps some data was previously read into a buffer for testing against - other stream types. - Allow initialization from this previously read data (especially as we may - be reading from a non-seekable stream). - This requires copying it into a buffer allocated by ogg_sync_buffer() and - doesn't support seeking, so this is not a good mechanism to use for - decoding entire files from RAM.*/ - if (_initial_bytes > 0) { - char *buffer; - buffer = ogg_sync_buffer(&_of->oy, (long)_initial_bytes); - memcpy(buffer, _initial_data, _initial_bytes * sizeof(*buffer)); - ogg_sync_wrote(&_of->oy, (long)_initial_bytes); - } - /* Can we seek? - Stevens suggests the seek test is portable. - It's actually not for files on win32, but we address that by fixing it in - our callback implementation (see stream.c).*/ - seekable = _cb->seek != NULL && (*_cb->seek)(_stream, 0, SEEK_CUR) != -1; - /*If seek is implemented, tell must also be implemented.*/ - if (seekable) { - opus_int64 pos; - if (OP_UNLIKELY(_of->callbacks.tell == NULL)) { - return OP_EINVAL; - } - pos = (*_of->callbacks.tell)(_of->stream); - /* If the current position is not equal to the initial bytes consumed, - absolute seeking will not work.*/ - if (OP_UNLIKELY(pos != (opus_int64)_initial_bytes)) { - return OP_EINVAL; - } - } - _of->seekable = seekable; - /* Don't seek yet. - Set up a 'single' (current) logical bitstream entry for partial open.*/ - _of->links = (OggOpusLink *)_ogg_malloc(sizeof(*_of->links)); - /*The serialno gets filled in later by op_fetch_headers().*/ - ogg_stream_init(&_of->os, -1); - pog = NULL; - for (;;) { - /* Fetch all BOS pages, store the Opus header and all seen serial numbers, - and load subsequent Opus setup headers.*/ - ret = op_fetch_headers(_of, &_of->links[0].head, &_of->links[0].tags, - &_of->serialnos, &_of->nserialnos, &_of->cserialnos, pog); - if (OP_UNLIKELY(ret < 0)) { - break; - } - _of->nlinks = 1; - _of->links[0].offset = 0; - _of->links[0].data_offset = _of->offset; - _of->links[0].pcm_end = -1; - _of->links[0].serialno = _of->os.serialno; - /*Fetch the initial PCM offset.*/ - ret = op_find_initial_pcm_offset(_of, _of->links, &og); - if (seekable || OP_LIKELY(ret <= 0)) { - break; - } - /* This link was empty, but we already have the BOS page for the next one in - og. - We can't seek, so start processing the next link right now.*/ - opus_tags_clear(&_of->links[0].tags); - _of->nlinks = 0; - if (!seekable) { - _of->cur_link++; - } - pog = &og; - } - if (OP_LIKELY(ret >= 0)) { - _of->ready_state = OP_PARTOPEN; - } - return ret; -} - -static int op_open2(OggOpusFile *_of) { - int ret; - OP_ASSERT(_of->ready_state == OP_PARTOPEN); - if (_of->seekable) { - _of->ready_state = OP_OPENED; - ret = op_open_seekable2(_of); - } else { - ret = 0; - } - if (OP_LIKELY(ret >= 0)) { - /* We have buffered packets from op_find_initial_pcm_offset(). - Move to OP_INITSET so we can use them.*/ - _of->ready_state = OP_STREAMSET; - ret = op_make_decode_ready(_of); - if (OP_LIKELY(ret >= 0)) { - return 0; - } - } - /*Don't auto-close the stream on failure.*/ - _of->callbacks.close = NULL; - op_clear(_of); - return ret; -} - -OggOpusFile *op_test_callbacks(void *_stream, const OpusFileCallbacks *_cb, - const unsigned char *_initial_data, size_t _initial_bytes, int *_error) { - OggOpusFile *of; - int ret; - of = (OggOpusFile *)_ogg_malloc(sizeof(*of)); - ret = OP_EFAULT; - if (OP_LIKELY(of != NULL)) { - ret = op_open1(of, _stream, _cb, _initial_data, _initial_bytes); - if (OP_LIKELY(ret >= 0)) { - if (_error != NULL) { - *_error = 0; - } - return of; - } - /*Don't auto-close the stream on failure.*/ - of->callbacks.close = NULL; - op_clear(of); - _ogg_free(of); - } - if (_error != NULL) { - *_error = ret; - } - return NULL; -} - -OggOpusFile *op_open_callbacks(void *_stream, const OpusFileCallbacks *_cb, - const unsigned char *_initial_data, size_t _initial_bytes, int *_error) { - OggOpusFile *of; - of = op_test_callbacks(_stream, _cb, _initial_data, _initial_bytes, _error); - if (OP_LIKELY(of != NULL)) { - int ret; - ret = op_open2(of); - if (OP_LIKELY(ret >= 0)) { - return of; - } - if (_error != NULL) { - *_error = ret; - } - _ogg_free(of); - } - return NULL; -} - -/* Convenience routine to clean up from failure for the open functions that - create their own streams.*/ -static OggOpusFile *op_open_close_on_failure(void *_stream, - const OpusFileCallbacks *_cb, int *_error) { - OggOpusFile *of; - if (OP_UNLIKELY(_stream == NULL)) { - if (_error != NULL) { - *_error = OP_EFAULT; - } - return NULL; - } - of = op_open_callbacks(_stream, _cb, NULL, 0, _error); - if (OP_UNLIKELY(of == NULL)) { - (*_cb->close)(_stream); - } - return of; -} - -OggOpusFile *op_open_file(const char *_path, int *_error) { - OpusFileCallbacks cb; - return op_open_close_on_failure(op_fopen(&cb, _path, "rb"), &cb, _error); -} - -OggOpusFile *op_open_memory(const unsigned char *_data, size_t _size, - int *_error) { - OpusFileCallbacks cb; - return op_open_close_on_failure(op_mem_stream_create(&cb, _data, _size), &cb, - _error); -} - -/* Convenience routine to clean up from failure for the open functions that - create their own streams.*/ -static OggOpusFile *op_test_close_on_failure(void *_stream, - const OpusFileCallbacks *_cb, int *_error) { - OggOpusFile *of; - if (OP_UNLIKELY(_stream == NULL)) { - if (_error != NULL) { - *_error = OP_EFAULT; - } - return NULL; - } - of = op_test_callbacks(_stream, _cb, NULL, 0, _error); - if (OP_UNLIKELY(of == NULL)) { - (*_cb->close)(_stream); - } - return of; -} - -OggOpusFile *op_test_file(const char *_path, int *_error) { - OpusFileCallbacks cb; - return op_test_close_on_failure(op_fopen(&cb, _path, "rb"), &cb, _error); -} - -OggOpusFile *op_test_memory(const unsigned char *_data, size_t _size, - int *_error) { - OpusFileCallbacks cb; - return op_test_close_on_failure(op_mem_stream_create(&cb, _data, _size), &cb, - _error); -} - -int op_test_open(OggOpusFile *_of) { - int ret; - if (OP_UNLIKELY(_of->ready_state != OP_PARTOPEN)) { - return OP_EINVAL; - } - ret = op_open2(_of); - /* op_open2() will clear this structure on failure. - Reset its contents to prevent double-frees in op_free().*/ - if (OP_UNLIKELY(ret < 0)) { - memset(_of, 0, sizeof(*_of)); - } - return ret; -} - -void op_free(OggOpusFile *_of) { - if (OP_LIKELY(_of != NULL)) { - op_clear(_of); - _ogg_free(_of); - } -} - -int op_seekable(const OggOpusFile *_of) { - return _of->seekable; -} - -int op_link_count(const OggOpusFile *_of) { - return _of->nlinks; -} - -opus_uint32 op_serialno(const OggOpusFile *_of, int _li) { - if (OP_UNLIKELY(_li >= _of->nlinks)) { - _li = _of->nlinks - 1; - } - if (!_of->seekable) { - _li = 0; - } - return _of->links[_li < 0 ? _of->cur_link : _li].serialno; -} - -int op_channel_count(const OggOpusFile *_of, int _li) { - return op_head(_of, _li)->channel_count; -} - -opus_int64 op_raw_total(const OggOpusFile *_of, int _li) { - if (OP_UNLIKELY(_of->ready_state < OP_OPENED) - || OP_UNLIKELY(!_of->seekable) - || OP_UNLIKELY(_li >= _of->nlinks)) { - return OP_EINVAL; - } - if (_li < 0) { - return _of->end; - } - return (_li + 1 >= _of->nlinks ? _of->end : _of->links[_li + 1].offset) - - (_li > 0 ? _of->links[_li].offset : 0); -} - -ogg_int64_t op_pcm_total(const OggOpusFile *_of, int _li) { - OggOpusLink *links; - ogg_int64_t pcm_total; - ogg_int64_t diff = 0; - int nlinks; - nlinks = _of->nlinks; - if (OP_UNLIKELY(_of->ready_state < OP_OPENED) - || OP_UNLIKELY(!_of->seekable) - || OP_UNLIKELY(_li >= nlinks)) { - return OP_EINVAL; - } - links = _of->links; - /* We verify that the granule position differences are larger than the - pre-skip and that the total duration does not overflow during link - enumeration, so we don't have to check here.*/ - pcm_total = 0; - if (_li < 0) { - pcm_total = links[nlinks - 1].pcm_file_offset; - _li = nlinks - 1; - } - OP_ALWAYS_TRUE(!op_granpos_diff(&diff, - links[_li].pcm_end, links[_li].pcm_start)); - return pcm_total + diff - links[_li].head.pre_skip; -} - -const OpusHead *op_head(const OggOpusFile *_of, int _li) { - if (OP_UNLIKELY(_li >= _of->nlinks)) { - _li = _of->nlinks - 1; - } - if (!_of->seekable) { - _li = 0; - } - return &_of->links[_li < 0 ? _of->cur_link : _li].head; -} - -const OpusTags *op_tags(const OggOpusFile *_of, int _li) { - if (OP_UNLIKELY(_li >= _of->nlinks)) { - _li = _of->nlinks - 1; - } - if (!_of->seekable) { - if (_of->ready_state < OP_STREAMSET && _of->ready_state != OP_PARTOPEN) { - return NULL; - } - _li = 0; - } else if (_li < 0) { - _li = _of->ready_state >= OP_STREAMSET ? _of->cur_link : 0; - } - return &_of->links[_li].tags; -} - -int op_current_link(const OggOpusFile *_of) { - if (OP_UNLIKELY(_of->ready_state < OP_OPENED)) { - return OP_EINVAL; - } - return _of->cur_link; -} - -/* Compute an average bitrate given a byte and sample count. - Return: The bitrate in bits per second.*/ -static opus_int32 op_calc_bitrate(opus_int64 _bytes, ogg_int64_t _samples) { - if (OP_UNLIKELY(_samples <= 0)) { - return OP_INT32_MAX; - } - /*These rates are absurd, but let's handle them anyway.*/ - if (OP_UNLIKELY(_bytes > (OP_INT64_MAX - (_samples >> 1)) / (48000 * 8))) { - ogg_int64_t den; - if (OP_UNLIKELY(_bytes / (OP_INT32_MAX / (48000 * 8)) >= _samples)) { - return OP_INT32_MAX; - } - den = _samples / (48000 * 8); - return (opus_int32)((_bytes + (den >> 1)) / den); - } - /* This can't actually overflow in normal operation: even with a pre-skip of - 545 2.5 ms frames with 8 streams running at 1282*8+1 bytes per packet - (1275 byte frames + Opus framing overhead + Ogg lacing values), that all - produce a single sample of decoded output, we still don't top 45 Mbps. - The only way to get bitrates larger than that is with excessive Opus - padding, more encoded streams than output channels, or lots and lots of - Ogg pages with no packets on them.*/ - return (opus_int32)OP_MIN((_bytes * 48000 * 8 + (_samples >> 1)) / _samples, - OP_INT32_MAX); -} - -opus_int32 op_bitrate(const OggOpusFile *_of, int _li) { - if (OP_UNLIKELY(_of->ready_state < OP_OPENED) || OP_UNLIKELY(!_of->seekable) - || OP_UNLIKELY(_li >= _of->nlinks)) { - return OP_EINVAL; - } - return op_calc_bitrate(op_raw_total(_of, _li), op_pcm_total(_of, _li)); -} - -opus_int32 op_bitrate_instant(OggOpusFile *_of) { - ogg_int64_t samples_tracked; - opus_int32 ret; - if (OP_UNLIKELY(_of->ready_state < OP_OPENED)) { - return OP_EINVAL; - } - samples_tracked = _of->samples_tracked; - if (OP_UNLIKELY(samples_tracked == 0)) { - return OP_FALSE; - } - ret = op_calc_bitrate(_of->bytes_tracked, samples_tracked); - _of->bytes_tracked = 0; - _of->samples_tracked = 0; - return ret; -} - -/* Given a serialno, find a link with a corresponding Opus stream, if it exists. - Return: The index of the link to which the page belongs, or a negative number - if it was not a desired Opus bitstream section.*/ -static int op_get_link_from_serialno(const OggOpusFile *_of, int _cur_link, - opus_int64 _page_offset, ogg_uint32_t _serialno) { - const OggOpusLink *links; - int nlinks; - int li_lo; - int li_hi; - OP_ASSERT(_of->seekable); - links = _of->links; - nlinks = _of->nlinks; - li_lo = 0; - /*Start off by guessing we're just a multiplexed page in the current link.*/ - li_hi = _cur_link + 1 < nlinks && _page_offset < links[_cur_link + 1].offset ? - _cur_link + 1 : nlinks; - do { - if (_page_offset >= links[_cur_link].offset) { - li_lo = _cur_link; - } else { - li_hi = _cur_link; - } - _cur_link = li_lo + (li_hi - li_lo >> 1); - } while (li_hi - li_lo > 1); - /* We've identified the link that should contain this page. - Make sure it's a page we care about.*/ - if (links[_cur_link].serialno != _serialno) { - return OP_FALSE; - } - return _cur_link; -} - -/* Fetch and process a page. - This handles the case where we're at a bitstream boundary and dumps the - decoding machine. - If the decoding machine is unloaded, it loads it. - It also keeps prev_packet_gp up to date (seek and read both use this). - Return: <0) Error, OP_HOLE (lost packet), or OP_EOF. - 0) Got at least one audio data packet.*/ -static int op_fetch_and_process_page(OggOpusFile *_of, - ogg_page *_og, opus_int64 _page_offset, int _spanp, int _ignore_holes) { - OggOpusLink *links; - ogg_uint32_t cur_serialno; - int seekable; - int cur_link; - int ret; - /*We shouldn't get here if we have unprocessed packets.*/ - OP_ASSERT(_of->ready_state < OP_INITSET || _of->op_pos >= _of->op_count); - seekable = _of->seekable; - links = _of->links; - cur_link = seekable ? _of->cur_link : 0; - cur_serialno = links[cur_link].serialno; - /*Handle one page.*/ - for (;;) { - ogg_page og; - OP_ASSERT(_of->ready_state >= OP_OPENED); - /*If we were given a page to use, use it.*/ - if (_og != NULL) { - *&og = *_og; - _og = NULL; - } - /*Keep reading until we get a page with the correct serialno.*/ - else { - _page_offset = op_get_next_page(_of, &og, _of->end); - } - /*EOF: Leave uninitialized.*/ - if (_page_offset < 0) { - return _page_offset < OP_FALSE ? (int)_page_offset : OP_EOF; - } - if (OP_LIKELY(_of->ready_state >= OP_STREAMSET) - && cur_serialno != (ogg_uint32_t)ogg_page_serialno(&og)) { - /* Two possibilities: - 1) Another stream is multiplexed into this logical section, or*/ - if (OP_LIKELY(!ogg_page_bos(&og))) { - continue; - } - /* 2) Our decoding just traversed a bitstream boundary.*/ - if (!_spanp) { - return OP_EOF; - } - if (OP_LIKELY(_of->ready_state >= OP_INITSET)) { - op_decode_clear(_of); - } - } - /* Bitrate tracking: add the header's bytes here. - The body bytes are counted when we consume the packets.*/ - else { - _of->bytes_tracked += og.header_len; - } - /* Do we need to load a new machine before submitting the page? - This is different in the seekable and non-seekable cases. - In the seekable case, we already have all the header information loaded - and cached. - We just initialize the machine with it and continue on our merry way. - In the non-seekable (streaming) case, we'll only be at a boundary if we - just left the previous logical bitstream, and we're now nominally at the - header of the next bitstream.*/ - if (OP_UNLIKELY(_of->ready_state < OP_STREAMSET)) { - if (seekable) { - ogg_uint32_t serialno; - serialno = ogg_page_serialno(&og); - /*Match the serialno to bitstream section.*/ - OP_ASSERT(cur_link >= 0 && cur_link < _of->nlinks); - if (links[cur_link].serialno != serialno) { - /* It wasn't a page from the current link. - Is it from the next one?*/ - if (OP_LIKELY(cur_link + 1 < _of->nlinks && links[cur_link + 1].serialno == - serialno)) { - cur_link++; - } else { - int new_link; - new_link = - op_get_link_from_serialno(_of, cur_link, _page_offset, serialno); - /* Not a desired Opus bitstream section. - Keep trying.*/ - if (new_link < 0) { - continue; - } - cur_link = new_link; - } - } - cur_serialno = serialno; - _of->cur_link = cur_link; - ogg_stream_reset_serialno(&_of->os, serialno); - _of->ready_state = OP_STREAMSET; - /* If we're at the start of this link, initialize the granule position - and pre-skip tracking.*/ - if (_page_offset <= links[cur_link].data_offset) { - _of->prev_packet_gp = links[cur_link].pcm_start; - _of->prev_page_offset = -1; - _of->cur_discard_count = links[cur_link].head.pre_skip; - /* Ignore a hole at the start of a new link (this is common for - streams joined in the middle) or after seeking.*/ - _ignore_holes = 1; - } - } else { - do { - /* We're streaming. - Fetch the two header packets, build the info struct.*/ - ret = op_fetch_headers(_of, &links[0].head, &links[0].tags, - NULL, NULL, NULL, &og); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - /* op_find_initial_pcm_offset() will suppress any initial hole for us, - so no need to set _ignore_holes.*/ - ret = op_find_initial_pcm_offset(_of, links, &og); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - _of->links[0].serialno = cur_serialno = _of->os.serialno; - _of->cur_link++; - } - /* If the link was empty, keep going, because we already have the - BOS page of the next one in og.*/ - while (OP_UNLIKELY(ret > 0)); - /* If we didn't get any packets out of op_find_initial_pcm_offset(), - keep going (this is possible if end-trimming trimmed them all).*/ - if (_of->op_count <= 0) { - continue; - } - /* Otherwise, we're done. - TODO: This resets bytes_tracked, which misses the header bytes - already processed by op_find_initial_pcm_offset().*/ - ret = op_make_decode_ready(_of); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - return 0; - } - } - /* The buffered page is the data we want, and we're ready for it. - Add it to the stream state.*/ - if (OP_UNLIKELY(_of->ready_state == OP_STREAMSET)) { - ret = op_make_decode_ready(_of); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } - /*Extract all the packets from the current page.*/ - ogg_stream_pagein(&_of->os, &og); - if (OP_LIKELY(_of->ready_state >= OP_INITSET)) { - opus_int32 total_duration; - int *durations = (int*)malloc(255 * sizeof(int)); - int op_count; - int report_hole; - report_hole = 0; - total_duration = op_collect_audio_packets(_of, durations); - if (OP_UNLIKELY(total_duration < 0)) { - /* libogg reported a hole (a gap in the page sequence numbers). - Drain the packets from the page anyway. - If we don't, they'll still be there when we fetch the next page. - Then, when we go to pull out packets, we might get more than 255, - which would overrun our packet buffer. - We repeat this call until we get any actual packets, since we might - have buffered multiple out-of-sequence pages with no packets on - them.*/ - do { - total_duration = op_collect_audio_packets(_of, durations); - } while (total_duration < 0); - if (!_ignore_holes) { - /* Report the hole to the caller after we finish timestamping the - packets.*/ - report_hole = 1; - /* We had lost or damaged pages, so reset our granule position - tracking. - This makes holes behave the same as a small raw seek. - If the next page is the EOS page, we'll discard it (because we - can't perform end trimming properly), and we'll always discard at - least 80 ms of audio (to allow decoder state to re-converge). - We could try to fill in the gap with PLC by looking at timestamps - in the non-EOS case, but that's complicated and error prone and we - can't rely on the timestamps being valid.*/ - _of->prev_packet_gp = -1; - } - } - op_count = _of->op_count; - /* If we found at least one audio data packet, compute per-packet granule - positions for them.*/ - if (op_count > 0) { - ogg_int64_t diff; - ogg_int64_t prev_packet_gp; - ogg_int64_t cur_packet_gp; - ogg_int64_t cur_page_gp; - int cur_page_eos; - int pi; - cur_page_gp = _of->op[op_count - 1].granulepos; - cur_page_eos = _of->op[op_count - 1].e_o_s; - prev_packet_gp = _of->prev_packet_gp; - if (OP_UNLIKELY(prev_packet_gp == -1)) { - opus_int32 cur_discard_count; - /* This is the first call after a raw seek. - Try to reconstruct prev_packet_gp from scratch.*/ - OP_ASSERT(seekable); - if (OP_UNLIKELY(cur_page_eos)) { - /* If the first page we hit after our seek was the EOS page, and - we didn't start from data_offset or before, we don't have - enough information to do end-trimming. - Proceed to the next link, rather than risk playing back some - samples that shouldn't have been played.*/ - _of->op_count = 0; - if (report_hole) { - free(durations); - return OP_HOLE; - } - continue; - } - /* By default discard 80 ms of data after a seek, unless we seek - into the pre-skip region.*/ - cur_discard_count = 80 * 48; - cur_page_gp = _of->op[op_count - 1].granulepos; - /* Try to initialize prev_packet_gp. - If the current page had packets but didn't have a granule - position, or the granule position it had was too small (both - illegal), just use the starting granule position for the link.*/ - prev_packet_gp = links[cur_link].pcm_start; - if (OP_LIKELY(cur_page_gp != -1)) { - op_granpos_add(&prev_packet_gp, cur_page_gp, -total_duration); - } - if (OP_LIKELY(!op_granpos_diff(&diff, - prev_packet_gp, links[cur_link].pcm_start))) { - opus_int32 pre_skip; - /* If we start at the beginning of the pre-skip region, or we're - at least 80 ms from the end of the pre-skip region, we discard - to the end of the pre-skip region. - Otherwise, we still use the 80 ms default, which will discard - past the end of the pre-skip region.*/ - pre_skip = links[cur_link].head.pre_skip; - if (diff >= 0 && diff <= OP_MAX(0, pre_skip - 80 * 48)) { - cur_discard_count = pre_skip - (int)diff; - } - } - _of->cur_discard_count = cur_discard_count; - } - if (OP_UNLIKELY(cur_page_gp == -1)) { - /* This page had completed packets but didn't have a valid granule - position. - This is illegal, but we'll try to handle it by continuing to count - forwards from the previous page.*/ - if (op_granpos_add(&cur_page_gp, prev_packet_gp, total_duration) < 0) { - /*The timestamp for this page overflowed.*/ - cur_page_gp = links[cur_link].pcm_end; - } - } - /*If we hit the last page, handle end-trimming.*/ - if (OP_UNLIKELY(cur_page_eos) - && OP_LIKELY(!op_granpos_diff(&diff, cur_page_gp, prev_packet_gp)) - && OP_LIKELY(diff < total_duration)) { - cur_packet_gp = prev_packet_gp; - for (pi = 0; pi < op_count; pi++) { - /*Check for overflow.*/ - if (diff < 0 && OP_UNLIKELY(OP_INT64_MAX + diff < durations[pi])) { - diff = durations[pi] + 1; - } else { - diff = durations[pi] - diff; - } - /*If we have samples to trim...*/ - if (diff > 0) { - /* If we trimmed the entire packet, stop (the spec says encoders - shouldn't do this, but we support it anyway).*/ - if (OP_UNLIKELY(diff > durations[pi])) { - break; - } - cur_packet_gp = cur_page_gp; - /* Move the EOS flag to this packet, if necessary, so we'll trim - the samples during decode.*/ - _of->op[pi].e_o_s = 1; - } else { - /*Update the granule position as normal.*/ - OP_ALWAYS_TRUE(!op_granpos_add(&cur_packet_gp, - cur_packet_gp, durations[pi])); - } - _of->op[pi].granulepos = cur_packet_gp; - OP_ALWAYS_TRUE(!op_granpos_diff(&diff, cur_page_gp, cur_packet_gp)); - } - } else { - /* Propagate timestamps to earlier packets. - op_granpos_add(&prev_packet_gp,prev_packet_gp,total_duration) - should succeed and give prev_packet_gp==cur_page_gp. - But we don't bother to check that, as there isn't much we can do - if it's not true, and it actually will not be true on the first - page after a seek, if there was a continued packet. - The only thing we guarantee is that the start and end granule - positions of the packets are valid, and that they are monotonic - within a page. - They might be completely out of range for this link (we'll check - that elsewhere), or non-monotonic between pages.*/ - if (OP_UNLIKELY(op_granpos_add(&prev_packet_gp, - cur_page_gp, -total_duration) < 0)) { - /* The starting timestamp for the first packet on this page - underflowed. - This is illegal, but we ignore it.*/ - prev_packet_gp = 0; - } - for (pi = 0; pi < op_count; pi++) { - if (OP_UNLIKELY(op_granpos_add(&cur_packet_gp, - cur_page_gp, -total_duration) < 0)) { - /* The start timestamp for this packet underflowed. - This is illegal, but we ignore it.*/ - cur_packet_gp = 0; - } - total_duration -= durations[pi]; - OP_ASSERT(total_duration >= 0); - OP_ALWAYS_TRUE(!op_granpos_add(&cur_packet_gp, - cur_packet_gp, durations[pi])); - _of->op[pi].granulepos = cur_packet_gp; - } - OP_ASSERT(total_duration == 0); - } - _of->prev_packet_gp = prev_packet_gp; - _of->prev_page_offset = _page_offset; - _of->op_count = op_count = pi; - } - if (report_hole) { - free(durations); - return OP_HOLE; - } - /*If end-trimming didn't trim all the packets, we're done.*/ - if (op_count > 0) { - free(durations); - return 0; - } - } - } -} - -int op_raw_seek(OggOpusFile *_of, opus_int64 _pos) { - int ret; - if (OP_UNLIKELY(_of->ready_state < OP_OPENED)) { - return OP_EINVAL; - } - /*Don't dump the decoder state if we can't seek.*/ - if (OP_UNLIKELY(!_of->seekable)) { - return OP_ENOSEEK; - } - if (OP_UNLIKELY(_pos < 0) || OP_UNLIKELY(_pos > _of->end)) { - return OP_EINVAL; - } - /*Clear out any buffered, decoded data.*/ - op_decode_clear(_of); - _of->bytes_tracked = 0; - _of->samples_tracked = 0; - ret = op_seek_helper(_of, _pos); - if (OP_UNLIKELY(ret < 0)) { - return OP_EREAD; - } - ret = op_fetch_and_process_page(_of, NULL, -1, 1, 1); - /* If we hit EOF, op_fetch_and_process_page() leaves us uninitialized. - Instead, jump to the end.*/ - if (ret == OP_EOF) { - int cur_link; - op_decode_clear(_of); - cur_link = _of->nlinks - 1; - _of->cur_link = cur_link; - _of->prev_packet_gp = _of->links[cur_link].pcm_end; - _of->cur_discard_count = 0; - ret = 0; - } - return ret; -} - -/* Convert a PCM offset relative to the start of the whole stream to a granule - position in an individual link.*/ -static ogg_int64_t op_get_granulepos(const OggOpusFile *_of, - ogg_int64_t _pcm_offset, int *_li) { - const OggOpusLink *links; - ogg_int64_t duration; - ogg_int64_t pcm_start; - opus_int32 pre_skip; - int nlinks; - int li_lo; - int li_hi; - OP_ASSERT(_pcm_offset >= 0); - nlinks = _of->nlinks; - links = _of->links; - li_lo = 0; - li_hi = nlinks; - do { - int li; - li = li_lo + (li_hi - li_lo >> 1); - if (links[li].pcm_file_offset <= _pcm_offset) { - li_lo = li; - } else { - li_hi = li; - } - } while (li_hi - li_lo > 1); - _pcm_offset -= links[li_lo].pcm_file_offset; - pcm_start = links[li_lo].pcm_start; - pre_skip = links[li_lo].head.pre_skip; - OP_ALWAYS_TRUE(!op_granpos_diff(&duration, links[li_lo].pcm_end, pcm_start)); - duration -= pre_skip; - if (_pcm_offset >= duration) { - return -1; - } - _pcm_offset += pre_skip; - if (OP_UNLIKELY(pcm_start > OP_INT64_MAX - _pcm_offset)) { - /* Adding this amount to the granule position would overflow the positive - half of its 64-bit range. - Since signed overflow is undefined in C, do it in a way the compiler - isn't allowed to screw up.*/ - _pcm_offset -= OP_INT64_MAX - pcm_start + 1; - pcm_start = OP_INT64_MIN; - } - pcm_start += _pcm_offset; - *_li = li_lo; - return pcm_start; -} - -/* A small helper to determine if an Ogg page contains data that continues onto - a subsequent page.*/ -static int op_page_continues(const ogg_page *_og) { - int nlacing; - OP_ASSERT(_og->header_len >= 27); - nlacing = _og->header[26]; - OP_ASSERT(_og->header_len >= 27 + nlacing); - /* This also correctly handles the (unlikely) case of nlacing==0, because - 0!=255.*/ - return _og->header[27 + nlacing - 1] == 255; -} - -/*A small helper to buffer the continued packet data from a page.*/ -static void op_buffer_continued_data(OggOpusFile *_of, ogg_page *_og) { - ogg_packet op; - ogg_stream_pagein(&_of->os, _og); - /* Drain any packets that did end on this page (and ignore holes). - We only care about the continued packet data.*/ - while (ogg_stream_packetout(&_of->os, &op)); -} - -/* This controls how close the target has to be to use the current stream - position to subdivide the initial range. - Two minutes seems to be a good default.*/ -#define OP_CUR_TIME_THRESH (120*48*(opus_int32)1000) - -/* Note: The OP_SMALL_FOOTPRINT #define doesn't (currently) save much code size, - but it's meant to serve as documentation for portions of the seeking - algorithm that are purely optional, to aid others learning from/porting this - code to other contexts.*/ -/*#define OP_SMALL_FOOTPRINT (1)*/ - -/* Search within link _li for the page with the highest granule position - preceding (or equal to) _target_gp. - There is a danger here: missing pages or incorrect frame number information - in the bitstream could make our task impossible. - Account for that (and report it as an error condition).*/ -static int op_pcm_seek_page(OggOpusFile *_of, - ogg_int64_t _target_gp, int _li) { - const OggOpusLink *link; - ogg_page og; - ogg_int64_t pcm_pre_skip; - ogg_int64_t pcm_start; - ogg_int64_t pcm_end; - ogg_int64_t best_gp; - ogg_int64_t diff; - ogg_uint32_t serialno; - opus_int32 pre_skip; - opus_int64 begin; - opus_int64 end; - opus_int64 boundary; - opus_int64 best; - opus_int64 best_start; - opus_int64 page_offset; - opus_int64 d0; - opus_int64 d1; - opus_int64 d2; - int force_bisect; - int buffering; - int ret; - _of->bytes_tracked = 0; - _of->samples_tracked = 0; - link = _of->links + _li; - best_gp = pcm_start = link->pcm_start; - pcm_end = link->pcm_end; - serialno = link->serialno; - best = best_start = begin = link->data_offset; - page_offset = -1; - buffering = 0; - /* We discard the first 80 ms of data after a seek, so seek back that much - farther. - If we can't, simply seek to the beginning of the link.*/ - if (OP_UNLIKELY(op_granpos_add(&_target_gp, _target_gp, -80 * 48) < 0) - || OP_UNLIKELY(op_granpos_cmp(_target_gp, pcm_start) < 0)) { - _target_gp = pcm_start; - } - /*Special case seeking to the start of the link.*/ - pre_skip = link->head.pre_skip; - OP_ALWAYS_TRUE(!op_granpos_add(&pcm_pre_skip, pcm_start, pre_skip)); - if (op_granpos_cmp(_target_gp, pcm_pre_skip) < 0) { - end = boundary = begin; - } else { - end = boundary = link->end_offset; -#if !defined(OP_SMALL_FOOTPRINT) - /*If we were decoding from this link, we can narrow the range a bit.*/ - if (_li == _of->cur_link && _of->ready_state >= OP_INITSET) { - opus_int64 offset; - int op_count; - op_count = _of->op_count; - /* The only way the offset can be invalid _and_ we can fail the granule - position checks below is if someone changed the contents of the last - page since we read it. - We'd be within our rights to just return OP_EBADLINK in that case, but - we'll simply ignore the current position instead.*/ - offset = _of->offset; - if (op_count > 0 && OP_LIKELY(offset <= end)) { - ogg_int64_t gp; - /* Make sure the timestamp is valid. - The granule position might be -1 if we collected the packets from a - page without a granule position after reporting a hole.*/ - gp = _of->op[op_count - 1].granulepos; - if (OP_LIKELY(gp != -1) && OP_LIKELY(op_granpos_cmp(pcm_start, gp) < 0) - && OP_LIKELY(op_granpos_cmp(pcm_end, gp) > 0)) { - OP_ALWAYS_TRUE(!op_granpos_diff(&diff, gp, _target_gp)); - /* We only actually use the current time if either - a) We can cut off at least half the range, or - b) We're seeking sufficiently close to the current position that - it's likely to be informative. - Otherwise it appears using the whole link range to estimate the - first seek location gives better results, on average.*/ - if (diff < 0) { - OP_ASSERT(offset >= begin); - if (offset - begin >= end - begin >> 1 || diff > -OP_CUR_TIME_THRESH) { - best = begin = offset; - best_gp = pcm_start = gp; - /* If we have buffered data from a continued packet, remember the - offset of the previous page's start, so that if we do wind up - having to seek back here later, we can prime the stream with - the continued packet data. - With no continued packet, we remember the end of the page.*/ - best_start = _of->os.body_returned < _of->os.body_fill ? - _of->prev_page_offset : best; - /* If there's completed packets and data in the stream state, - prev_page_offset should always be set.*/ - OP_ASSERT(best_start >= 0); - /*Buffer any continued packet data starting from here.*/ - buffering = 1; - } - } else { - ogg_int64_t prev_page_gp; - /* We might get lucky and already have the packet with the target - buffered. - Worth checking. - For very small files (with all of the data in a single page, - generally 1 second or less), we can loop them continuously - without seeking at all.*/ - OP_ALWAYS_TRUE(!op_granpos_add(&prev_page_gp, _of->op[0].granulepos, - -op_get_packet_duration(_of->op[0].packet, _of->op[0].bytes))); - if (op_granpos_cmp(prev_page_gp, _target_gp) <= 0) { - /* Don't call op_decode_clear(), because it will dump our - packets.*/ - _of->op_pos = 0; - _of->od_buffer_size = 0; - _of->prev_packet_gp = prev_page_gp; - /*_of->prev_page_offset already points to the right place.*/ - _of->ready_state = OP_STREAMSET; - return op_make_decode_ready(_of); - } - /* No such luck. - Check if we can cut off at least half the range, though.*/ - if (offset - begin <= end - begin >> 1 || diff < OP_CUR_TIME_THRESH) { - /*We really want the page start here, but this will do.*/ - end = boundary = offset; - pcm_end = gp; - } - } - } - } - } -#endif - } - /* This code was originally based on the "new search algorithm by HB (Nicholas - Vinen)" from libvorbisfile. - It has been modified substantially since.*/ - op_decode_clear(_of); - if (!buffering) { - ogg_stream_reset_serialno(&_of->os, serialno); - } - _of->cur_link = _li; - _of->ready_state = OP_STREAMSET; - /*Initialize the interval size history.*/ - d2 = d1 = d0 = end - begin; - force_bisect = 0; - while (begin < end) { - opus_int64 bisect; - opus_int64 next_boundary; - opus_int32 chunk_size; - if (end - begin < OP_CHUNK_SIZE) { - bisect = begin; - } else { - /*Update the interval size history.*/ - d0 = d1 >> 1; - d1 = d2 >> 1; - d2 = end - begin >> 1; - if (force_bisect) { - bisect = begin + (end - begin >> 1); - } else { - ogg_int64_t diff2; - OP_ALWAYS_TRUE(!op_granpos_diff(&diff, _target_gp, pcm_start)); - OP_ALWAYS_TRUE(!op_granpos_diff(&diff2, pcm_end, pcm_start)); - /*Take a (pretty decent) guess.*/ - bisect = begin + op_rescale64(diff, diff2, end - begin) - OP_CHUNK_SIZE; - } - if (bisect - OP_CHUNK_SIZE < begin) { - bisect = begin; - } - force_bisect = 0; - } - if (bisect != _of->offset) { - /*Discard any buffered continued packet data.*/ - if (buffering) { - ogg_stream_reset(&_of->os); - } - buffering = 0; - page_offset = -1; - ret = op_seek_helper(_of, bisect); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } - chunk_size = OP_CHUNK_SIZE; - next_boundary = boundary; - /* Now scan forward and figure out where we landed. - In the ideal case, we will see a page with a granule position at or - before our target, followed by a page with a granule position after our - target (or the end of the search interval). - Then we can just drop out and will have all of the data we need with no - additional seeking. - If we landed too far before, or after, we'll break out and do another - bisection.*/ - while (begin < end) { - page_offset = op_get_next_page(_of, &og, boundary); - if (page_offset < 0) { - if (page_offset < OP_FALSE) { - return (int)page_offset; - } - /* There are no more pages in our interval from our stream with a valid - timestamp that start at position bisect or later.*/ - /*If we scanned the whole interval, we're done.*/ - if (bisect <= begin + 1) { - end = begin; - } else { - /* Otherwise, back up one chunk. - First, discard any data from a continued packet.*/ - if (buffering) { - ogg_stream_reset(&_of->os); - } - buffering = 0; - bisect = OP_MAX(bisect - chunk_size, begin); - ret = op_seek_helper(_of, bisect); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - /*Bump up the chunk size.*/ - chunk_size = OP_MIN(2 * chunk_size, OP_CHUNK_SIZE_MAX); - /* If we did find a page from another stream or without a timestamp, - don't read past it.*/ - boundary = next_boundary; - } - } else { - ogg_int64_t gp; - int has_packets; - /* Save the offset of the first page we found after the seek, regardless - of the stream it came from or whether or not it has a timestamp.*/ - next_boundary = OP_MIN(page_offset, next_boundary); - if (serialno != (ogg_uint32_t)ogg_page_serialno(&og)) { - continue; - } - has_packets = ogg_page_packets(&og) > 0; - /* Force the gp to -1 (as it should be per spec) if no packets end on - this page. - Otherwise we might get confused when we try to pull out a packet - with that timestamp and can't find it.*/ - gp = has_packets ? ogg_page_granulepos(&og) : -1; - if (gp == -1) { - if (buffering) { - if (OP_LIKELY(!has_packets)) { - ogg_stream_pagein(&_of->os, &og); - } else { - /* If packets did end on this page, but we still didn't have a - valid granule position (in violation of the spec!), stop - buffering continued packet data. - Otherwise we might continue past the packet we actually - wanted.*/ - ogg_stream_reset(&_of->os); - buffering = 0; - } - } - continue; - } - if (op_granpos_cmp(gp, _target_gp) < 0) { - /* We found a page that ends before our target. - Advance to the raw offset of the next page.*/ - begin = _of->offset; - if (OP_UNLIKELY(op_granpos_cmp(pcm_start, gp) > 0) - || OP_UNLIKELY(op_granpos_cmp(pcm_end, gp) < 0)) { - /* Don't let pcm_start get out of range! - That could happen with an invalid timestamp.*/ - break; - } - /* Save the byte offset of the end of the page with this granule - position.*/ - best = best_start = begin; - /* Buffer any data from a continued packet, if necessary. - This avoids the need to seek back here if the next timestamp we - encounter while scanning forward lies after our target.*/ - if (buffering) { - ogg_stream_reset(&_of->os); - } - if (op_page_continues(&og)) { - op_buffer_continued_data(_of, &og); - /* If we have a continued packet, remember the offset of this - page's start, so that if we do wind up having to seek back here - later, we can prime the stream with the continued packet data. - With no continued packet, we remember the end of the page.*/ - best_start = page_offset; - } - /* Then force buffering on, so that if a packet starts (but does not - end) on the next page, we still avoid the extra seek back.*/ - buffering = 1; - best_gp = pcm_start = gp; - OP_ALWAYS_TRUE(!op_granpos_diff(&diff, _target_gp, pcm_start)); - /* If we're more than a second away from our target, break out and - do another bisection.*/ - if (diff > 48000) { - break; - } - /*Otherwise, keep scanning forward (do NOT use begin+1).*/ - bisect = begin; - } else { - /*We found a page that ends after our target.*/ - /*If we scanned the whole interval before we found it, we're done.*/ - if (bisect <= begin + 1) { - end = begin; - } else { - end = bisect; - /*In later iterations, don't read past the first page we found.*/ - boundary = next_boundary; - /* If we're not making much progress shrinking the interval size, - start forcing straight bisection to limit the worst case.*/ - force_bisect = end - begin > d0 * 2; - /* Don't let pcm_end get out of range! - That could happen with an invalid timestamp.*/ - if (OP_LIKELY(op_granpos_cmp(pcm_end, gp) > 0) - && OP_LIKELY(op_granpos_cmp(pcm_start, gp) <= 0)) { - pcm_end = gp; - } - break; - } - } - } - } - } - /*Found our page.*/ - OP_ASSERT(op_granpos_cmp(best_gp, pcm_start) >= 0); - /* Seek, if necessary. - If we were buffering data from a continued packet, we should be able to - continue to scan forward to get the rest of the data (even if - page_offset==-1). - Otherwise, we need to seek back to best_start.*/ - if (!buffering) { - if (best_start != page_offset) { - page_offset = -1; - ret = op_seek_helper(_of, best_start); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } - if (best_start < best) { - /*Retrieve the page at best_start, if we do not already have it.*/ - if (page_offset < 0) { - page_offset = op_get_next_page(_of, &og, link->end_offset); - if (OP_UNLIKELY(page_offset < OP_FALSE)) { - return (int)page_offset; - } - if (OP_UNLIKELY(page_offset != best_start)) { - return OP_EBADLINK; - } - } - op_buffer_continued_data(_of, &og); - page_offset = -1; - } - } - /*Update prev_packet_gp to allow per-packet granule position assignment.*/ - _of->prev_packet_gp = best_gp; - _of->prev_page_offset = best_start; - ret = op_fetch_and_process_page(_of, page_offset < 0 ? NULL : &og, page_offset, 0, 1); - if (OP_UNLIKELY(ret < 0)) { - return OP_EBADLINK; - } - /*Verify result.*/ - if (OP_UNLIKELY(op_granpos_cmp(_of->prev_packet_gp, _target_gp) > 0)) { - return OP_EBADLINK; - } - /*Our caller will set cur_discard_count to handle pre-roll.*/ - return 0; -} - -int op_pcm_seek(OggOpusFile *_of, ogg_int64_t _pcm_offset) { - const OggOpusLink *link; - ogg_int64_t pcm_start; - ogg_int64_t target_gp; - ogg_int64_t prev_packet_gp; - ogg_int64_t skip; - ogg_int64_t diff; - int op_count; - int op_pos; - int ret; - int li; - if (OP_UNLIKELY(_of->ready_state < OP_OPENED)) { - return OP_EINVAL; - } - if (OP_UNLIKELY(!_of->seekable)) { - return OP_ENOSEEK; - } - if (OP_UNLIKELY(_pcm_offset < 0)) { - return OP_EINVAL; - } - target_gp = op_get_granulepos(_of, _pcm_offset, &li); - if (OP_UNLIKELY(target_gp == -1)) { - return OP_EINVAL; - } - link = _of->links + li; - pcm_start = link->pcm_start; - OP_ALWAYS_TRUE(!op_granpos_diff(&_pcm_offset, target_gp, pcm_start)); -#if !defined(OP_SMALL_FOOTPRINT) - /* For small (90 ms or less) forward seeks within the same link, just decode - forward. - This also optimizes the case of seeking to the current position.*/ - if (li == _of->cur_link && _of->ready_state >= OP_INITSET) { - ogg_int64_t gp; - gp = _of->prev_packet_gp; - if (OP_LIKELY(gp != -1)) { - ogg_int64_t discard_count; - int nbuffered; - nbuffered = OP_MAX(_of->od_buffer_size - _of->od_buffer_pos, 0); - OP_ALWAYS_TRUE(!op_granpos_add(&gp, gp, -nbuffered)); - /* We do _not_ add cur_discard_count to gp. - Otherwise the total amount to discard could grow without bound, and it - would be better just to do a full seek.*/ - if (OP_LIKELY(!op_granpos_diff(&discard_count, target_gp, gp))) { - /* We use a threshold of 90 ms instead of 80, since 80 ms is the - _minimum_ we would have discarded after a full seek. - Assuming 20 ms frames (the default), we'd discard 90 ms on average.*/ - if (discard_count >= 0 && OP_UNLIKELY(discard_count < 90 * 48)) { - _of->cur_discard_count = (opus_int32)discard_count; - return 0; - } - } - } - } -#endif - ret = op_pcm_seek_page(_of, target_gp, li); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - /*Now skip samples until we actually get to our target.*/ - /*Figure out where we should skip to.*/ - if (_pcm_offset <= link->head.pre_skip) { - skip = 0; - } else { - skip = OP_MAX(_pcm_offset - 80 * 48, 0); - } - OP_ASSERT(_pcm_offset - skip >= 0); - OP_ASSERT(_pcm_offset - skip < OP_INT32_MAX - 120 * 48); - /*Skip packets until we find one with samples past our skip target.*/ - for (;;) { - op_count = _of->op_count; - prev_packet_gp = _of->prev_packet_gp; - for (op_pos = _of->op_pos; op_pos < op_count; op_pos++) { - ogg_int64_t cur_packet_gp; - cur_packet_gp = _of->op[op_pos].granulepos; - if (OP_LIKELY(!op_granpos_diff(&diff, cur_packet_gp, pcm_start)) - && diff > skip) { - break; - } - prev_packet_gp = cur_packet_gp; - } - _of->prev_packet_gp = prev_packet_gp; - _of->op_pos = op_pos; - if (op_pos < op_count) { - break; - } - /* We skipped all the packets on this page. - Fetch another.*/ - ret = op_fetch_and_process_page(_of, NULL, -1, 0, 1); - if (OP_UNLIKELY(ret < 0)) { - return OP_EBADLINK; - } - } - /* We skipped too far, or couldn't get within 2 billion samples of the target. - Either the timestamps were illegal or there was a hole in the data.*/ - if (op_granpos_diff(&diff, prev_packet_gp, pcm_start) || diff > skip - || _pcm_offset - diff >= OP_INT32_MAX) { - return OP_EBADLINK; - } - /* TODO: If there are further holes/illegal timestamps, we still won't decode - to the correct sample. - However, at least op_pcm_tell() will report the correct value immediately - after returning.*/ - _of->cur_discard_count = (opus_int32)(_pcm_offset - diff); - return 0; -} - -opus_int64 op_raw_tell(const OggOpusFile *_of) { - if (OP_UNLIKELY(_of->ready_state < OP_OPENED)) { - return OP_EINVAL; - } - return _of->offset; -} - -/* Convert a granule position from a given link to a PCM offset relative to the - start of the whole stream. - For unseekable sources, this gets reset to 0 at the beginning of each link.*/ -static ogg_int64_t op_get_pcm_offset(const OggOpusFile *_of, - ogg_int64_t _gp, int _li) { - const OggOpusLink *links; - ogg_int64_t pcm_offset; - links = _of->links; - OP_ASSERT(_li >= 0 && _li < _of->nlinks); - pcm_offset = links[_li].pcm_file_offset; - if (_of->seekable && OP_UNLIKELY(op_granpos_cmp(_gp, links[_li].pcm_end) > 0)) { - _gp = links[_li].pcm_end; - } - if (OP_LIKELY(op_granpos_cmp(_gp, links[_li].pcm_start) > 0)) { - ogg_int64_t delta; - if (OP_UNLIKELY(op_granpos_diff(&delta, _gp, links[_li].pcm_start) < 0)) { - /* This means an unseekable stream claimed to have a page from more than - 2 billion days after we joined.*/ - OP_ASSERT(!_of->seekable); - return OP_INT64_MAX; - } - if (delta < links[_li].head.pre_skip) { - delta = 0; - } else { - delta -= links[_li].head.pre_skip; - } - /* In the seekable case, _gp was limited by pcm_end. - In the unseekable case, pcm_offset should be 0.*/ - OP_ASSERT(pcm_offset <= OP_INT64_MAX - delta); - pcm_offset += delta; - } - return pcm_offset; -} - -ogg_int64_t op_pcm_tell(const OggOpusFile *_of) { - ogg_int64_t gp; - int nbuffered; - int li; - if (OP_UNLIKELY(_of->ready_state < OP_OPENED)) { - return OP_EINVAL; - } - gp = _of->prev_packet_gp; - if (gp == -1) { - return 0; - } - nbuffered = OP_MAX(_of->od_buffer_size - _of->od_buffer_pos, 0); - OP_ALWAYS_TRUE(!op_granpos_add(&gp, gp, -nbuffered)); - li = _of->seekable ? _of->cur_link : 0; - if (op_granpos_add(&gp, gp, _of->cur_discard_count) < 0) { - gp = _of->links[li].pcm_end; - } - return op_get_pcm_offset(_of, gp, li); -} - -void op_set_decode_callback(OggOpusFile *_of, - op_decode_cb_func _decode_cb, void *_ctx) { - _of->decode_cb = _decode_cb; - _of->decode_cb_ctx = _ctx; -} - -int op_set_gain_offset(OggOpusFile *_of, - int _gain_type, opus_int32 _gain_offset_q8) { - if (_gain_type != OP_HEADER_GAIN && _gain_type != OP_ALBUM_GAIN - && _gain_type != OP_TRACK_GAIN && _gain_type != OP_ABSOLUTE_GAIN) { - return OP_EINVAL; - } - _of->gain_type = _gain_type; - /* The sum of header gain and track gain lies in the range [-65536,65534]. - These bounds allow the offset to set the final value to anywhere in the - range [-32768,32767], which is what we'll clamp it to before applying.*/ - _of->gain_offset_q8 = OP_CLAMP(-98302, _gain_offset_q8, 98303); - op_update_gain(_of); - return 0; -} - -void op_set_dither_enabled(OggOpusFile *_of, int _enabled) { -#if !defined(OP_FIXED_POINT) - _of->dither_disabled = !_enabled; - if (!_enabled) { - _of->dither_mute = 65; - } -#else - (void) _of; - (void) _enabled; -#endif -} - -/* Allocate the decoder scratch buffer. - This is done lazily, since if the user provides large enough buffers, we'll - never need it.*/ -static int op_init_buffer(OggOpusFile *_of) { - int nchannels_max; - if (_of->seekable) { - const OggOpusLink *links; - int nlinks; - int li; - links = _of->links; - nlinks = _of->nlinks; - nchannels_max = 1; - for (li = 0; li < nlinks; li++) { - nchannels_max = OP_MAX(nchannels_max, links[li].head.channel_count); - } - } else { - nchannels_max = OP_NCHANNELS_MAX; - } - _of->od_buffer = (op_sample *)_ogg_malloc( - sizeof(*_of->od_buffer) * nchannels_max * 120 * 48); - if (_of->od_buffer == NULL) { - return OP_EFAULT; - } - return 0; -} - -/*Decode a single packet into the target buffer.*/ -static int op_decode(OggOpusFile *_of, op_sample *_pcm, - const ogg_packet *_op, int _nsamples, int _nchannels) { - int ret; - /*First we try using the application-provided decode callback.*/ - if (_of->decode_cb != NULL) { -#if defined(OP_FIXED_POINT) - ret = (*_of->decode_cb)(_of->decode_cb_ctx, _of->od, _pcm, _op, - _nsamples, _nchannels, OP_DEC_FORMAT_SHORT, _of->cur_link); -#else - ret = (*_of->decode_cb)(_of->decode_cb_ctx, _of->od, _pcm, _op, - _nsamples, _nchannels, OP_DEC_FORMAT_FLOAT, _of->cur_link); -#endif - } else { - ret = OP_DEC_USE_DEFAULT; - } - /*If the application didn't want to handle decoding, do it ourselves.*/ - if (ret == OP_DEC_USE_DEFAULT) { -#if defined(OP_FIXED_POINT) - ret = opus_multistream_decode(_of->od, - _op->packet, _op->bytes, _pcm, _nsamples, 0); -#else - ret = opus_multistream_decode_float(_of->od, - _op->packet, _op->bytes, _pcm, _nsamples, 0); -#endif - OP_ASSERT(ret < 0 || ret == _nsamples); - } - /* If the application returned a positive value other than 0 or - OP_DEC_USE_DEFAULT, fail.*/ - else if (OP_UNLIKELY(ret > 0)) { - return OP_EBADPACKET; - } - if (OP_UNLIKELY(ret < 0)) { - return OP_EBADPACKET; - } - return ret; -} - -/* Read more samples from the stream, using the same API as op_read() or - op_read_float().*/ -static int op_read_native(OggOpusFile *_of, - op_sample *_pcm, int _buf_size, int *_li) { - if (OP_UNLIKELY(_of->ready_state < OP_OPENED)) { - return OP_EINVAL; - } - for (;;) { - int ret; - if (OP_LIKELY(_of->ready_state >= OP_INITSET)) { - int nchannels; - int od_buffer_pos; - int nsamples; - int op_pos; - nchannels = _of->links[_of->seekable ? _of->cur_link : 0].head.channel_count; - od_buffer_pos = _of->od_buffer_pos; - nsamples = _of->od_buffer_size - od_buffer_pos; - /*If we have buffered samples, return them.*/ - if (nsamples > 0) { - if (nsamples * nchannels > _buf_size) { - nsamples = _buf_size / nchannels; - } - OP_ASSERT(_pcm != NULL || nsamples <= 0); - /* Check nsamples again so we don't pass NULL to memcpy() if _buf_size - is zero. - That would technically be undefined behavior, even if the number of - bytes to copy were zero.*/ - if (nsamples > 0) { - memcpy(_pcm, _of->od_buffer + nchannels * od_buffer_pos, - sizeof(*_pcm)*nchannels * nsamples); - od_buffer_pos += nsamples; - _of->od_buffer_pos = od_buffer_pos; - } - if (_li != NULL) { - *_li = _of->cur_link; - } - return nsamples; - } - /*If we have buffered packets, decode one.*/ - op_pos = _of->op_pos; - if (OP_LIKELY(op_pos < _of->op_count)) { - const ogg_packet *pop; - ogg_int64_t diff; - opus_int32 cur_discard_count; - int duration; - int trimmed_duration; - pop = _of->op + op_pos++; - _of->op_pos = op_pos; - cur_discard_count = _of->cur_discard_count; - duration = op_get_packet_duration(pop->packet, pop->bytes); - /*We don't buffer packets with an invalid TOC sequence.*/ - OP_ASSERT(duration > 0); - trimmed_duration = duration; - /*Perform end-trimming.*/ - if (OP_UNLIKELY(pop->e_o_s)) { - if (OP_UNLIKELY(op_granpos_cmp(pop->granulepos, - _of->prev_packet_gp) <= 0)) { - trimmed_duration = 0; - } else if (OP_LIKELY(!op_granpos_diff(&diff, - pop->granulepos, _of->prev_packet_gp))) { - trimmed_duration = (int)OP_MIN(diff, trimmed_duration); - } - } - _of->prev_packet_gp = pop->granulepos; - if (OP_UNLIKELY(duration * nchannels > _buf_size)) { - op_sample *buf; - /*If the user's buffer is too small, decode into a scratch buffer.*/ - buf = _of->od_buffer; - if (OP_UNLIKELY(buf == NULL)) { - ret = op_init_buffer(_of); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - buf = _of->od_buffer; - } - ret = op_decode(_of, buf, pop, duration, nchannels); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - /*Perform pre-skip/pre-roll.*/ - od_buffer_pos = (int)OP_MIN(trimmed_duration, cur_discard_count); - cur_discard_count -= od_buffer_pos; - _of->cur_discard_count = cur_discard_count; - _of->od_buffer_pos = od_buffer_pos; - _of->od_buffer_size = trimmed_duration; - /* Update bitrate tracking based on the actual samples we used from - what was decoded.*/ - _of->bytes_tracked += pop->bytes; - _of->samples_tracked += trimmed_duration - od_buffer_pos; - } else { - OP_ASSERT(_pcm != NULL); - /*Otherwise decode directly into the user's buffer.*/ - ret = op_decode(_of, _pcm, pop, duration, nchannels); - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - if (OP_LIKELY(trimmed_duration > 0)) { - /*Perform pre-skip/pre-roll.*/ - od_buffer_pos = (int)OP_MIN(trimmed_duration, cur_discard_count); - cur_discard_count -= od_buffer_pos; - _of->cur_discard_count = cur_discard_count; - trimmed_duration -= od_buffer_pos; - if (OP_LIKELY(trimmed_duration > 0) - && OP_UNLIKELY(od_buffer_pos > 0)) { - memmove(_pcm, _pcm + od_buffer_pos * nchannels, - sizeof(*_pcm)*trimmed_duration * nchannels); - } - /* Update bitrate tracking based on the actual samples we used from - what was decoded.*/ - _of->bytes_tracked += pop->bytes; - _of->samples_tracked += trimmed_duration; - if (OP_LIKELY(trimmed_duration > 0)) { - if (_li != NULL) { - *_li = _of->cur_link; - } - return trimmed_duration; - } - } - } - /* Don't grab another page yet. - This one might have more packets, or might have buffered data now.*/ - continue; - } - } - /*Suck in another page.*/ - ret = op_fetch_and_process_page(_of, NULL, -1, 1, 0); - if (OP_UNLIKELY(ret == OP_EOF)) { - if (_li != NULL) { - *_li = _of->cur_link; - } - return 0; - } - if (OP_UNLIKELY(ret < 0)) { - return ret; - } - } -} - -/* A generic filter to apply to the decoded audio data. - _src is non-const because we will destructively modify the contents of the - source buffer that we consume in some cases.*/ -typedef int (*op_read_filter_func)(OggOpusFile *_of, void *_dst, int _dst_sz, - op_sample *_src, int _nsamples, int _nchannels); - -/* Decode some samples and then apply a custom filter to them. - This is used to convert to different output formats.*/ -static int op_filter_read_native(OggOpusFile *_of, void *_dst, int _dst_sz, - op_read_filter_func _filter, int *_li) { - int ret; - /*Ensure we have some decoded samples in our buffer.*/ - ret = op_read_native(_of, NULL, 0, _li); - /*Now apply the filter to them.*/ - if (OP_LIKELY(ret >= 0) && OP_LIKELY(_of->ready_state >= OP_INITSET)) { - int od_buffer_pos; - od_buffer_pos = _of->od_buffer_pos; - ret = _of->od_buffer_size - od_buffer_pos; - if (OP_LIKELY(ret > 0)) { - int nchannels; - nchannels = _of->links[_of->seekable ? _of->cur_link : 0].head.channel_count; - ret = (*_filter)(_of, _dst, _dst_sz, - _of->od_buffer + nchannels * od_buffer_pos, ret, nchannels); - OP_ASSERT(ret >= 0); - OP_ASSERT(ret <= _of->od_buffer_size - od_buffer_pos); - od_buffer_pos += ret; - _of->od_buffer_pos = od_buffer_pos; - } - } - return ret; -} - -#if !defined(OP_FIXED_POINT)||!defined(OP_DISABLE_FLOAT_API) - -/* Matrices for downmixing from the supported channel counts to stereo. - The matrices with 5 or more channels are normalized to a total volume of 2.0, - since most mixes sound too quiet if normalized to 1.0 (as there is generally - little volume in the side/rear channels).*/ -static const float OP_STEREO_DOWNMIX[OP_NCHANNELS_MAX - 2][OP_NCHANNELS_MAX][2] = { - /*3.0*/ - { - {0.5858F, 0.0F}, {0.4142F, 0.4142F}, {0.0F, 0.5858F} - }, - /*quadrophonic*/ - { - {0.4226F, 0.0F}, {0.0F, 0.4226F}, {0.366F, 0.2114F}, {0.2114F, 0.336F} - }, - /*5.0*/ - { - {0.651F, 0.0F}, {0.46F, 0.46F}, {0.0F, 0.651F}, {0.5636F, 0.3254F}, - {0.3254F, 0.5636F} - }, - /*5.1*/ - { - {0.529F, 0.0F}, {0.3741F, 0.3741F}, {0.0F, 0.529F}, {0.4582F, 0.2645F}, - {0.2645F, 0.4582F}, {0.3741F, 0.3741F} - }, - /*6.1*/ - { - {0.4553F, 0.0F}, {0.322F, 0.322F}, {0.0F, 0.4553F}, {0.3943F, 0.2277F}, - {0.2277F, 0.3943F}, {0.2788F, 0.2788F}, {0.322F, 0.322F} - }, - /*7.1*/ - { - {0.3886F, 0.0F}, {0.2748F, 0.2748F}, {0.0F, 0.3886F}, {0.3366F, 0.1943F}, - {0.1943F, 0.3366F}, {0.3366F, 0.1943F}, {0.1943F, 0.3366F}, {0.2748F, 0.2748F} - } -}; - -#endif - -#if defined(OP_FIXED_POINT) -#if 0 -/* Matrices for downmixing from the supported channel counts to stereo. - The matrices with 5 or more channels are normalized to a total volume of 2.0, - since most mixes sound too quiet if normalized to 1.0 (as there is generally - little volume in the side/rear channels). - Hence we keep the coefficients in Q14, so the downmix values won't overflow a - 32-bit number.*/ -static const opus_int16 OP_STEREO_DOWNMIX_Q14 -[OP_NCHANNELS_MAX - 2][OP_NCHANNELS_MAX][2] = { - /*3.0*/ - { - {9598, 0}, {6786, 6786}, {0, 9598} - }, - /*quadrophonic*/ - { - {6924, 0}, {0, 6924}, {5996, 3464}, {3464, 5996} - }, - /*5.0*/ - { - {10666, 0}, {7537, 7537}, {0, 10666}, {9234, 5331}, {5331, 9234} - }, - /*5.1*/ - { - {8668, 0}, {6129, 6129}, {0, 8668}, {7507, 4335}, {4335, 7507}, {6129, 6129} - }, - /*6.1*/ - { - {7459, 0}, {5275, 5275}, {0, 7459}, {6460, 3731}, {3731, 6460}, {4568, 4568}, - {5275, 5275} - }, - /*7.1*/ - { - {6368, 0}, {4502, 4502}, {0, 6368}, {5515, 3183}, {3183, 5515}, {5515, 3183}, - {3183, 5515}, {4502, 4502} - } -}; -#endif -int op_read(OggOpusFile *_of, opus_int16 *_pcm, int _buf_size, int *_li) { - return op_read_native(_of, _pcm, _buf_size, _li); -} - -static int op_stereo_filter(OggOpusFile *_of, void *_dst, int _dst_sz, - op_sample *_src, int _nsamples, int _nchannels) { - (void)_of; - _nsamples = OP_MIN(_nsamples, _dst_sz >> 1); - if (_nchannels == 2) { - memcpy(_dst, _src, _nsamples * 2 * sizeof(*_src)); - } else { - opus_int16 *dst; - int i; - dst = (opus_int16 *)_dst; - if (_nchannels == 1) { - for (i = 0; i < _nsamples; i++) { - dst[2 * i + 0] = dst[2 * i + 1] = _src[i]; - } - } else { -#if 0 - for (i = 0; i < _nsamples; i++) { - opus_int32 l; - opus_int32 r; - int ci; - l = r = 0; - for (ci = 0; ci < _nchannels; ci++) { - opus_int32 s; - s = _src[_nchannels * i + ci]; - l += OP_STEREO_DOWNMIX_Q14[_nchannels - 3][ci][0] * s; - r += OP_STEREO_DOWNMIX_Q14[_nchannels - 3][ci][1] * s; - } - /*TODO: For 5 or more channels, we should do soft clipping here.*/ - dst[2 * i + 0] = (opus_int16)OP_CLAMP(-32768, l + 8192 >> 14, 32767); - dst[2 * i + 1] = (opus_int16)OP_CLAMP(-32768, r + 8192 >> 14, 32767); - } -#endif - // noop, removed for RAM savings - } - } - return _nsamples; -} - -int op_read_stereo(OggOpusFile *_of, opus_int16 *_pcm, int _buf_size) { - return op_filter_read_native(_of, _pcm, _buf_size, op_stereo_filter, NULL); -} - -# if !defined(OP_DISABLE_FLOAT_API) - -static int op_short2float_filter(OggOpusFile *_of, void *_dst, int _dst_sz, - op_sample *_src, int _nsamples, int _nchannels) { - float *dst; - int i; - (void)_of; - dst = (float *)_dst; - if (OP_UNLIKELY(_nsamples * _nchannels > _dst_sz)) { - _nsamples = _dst_sz / _nchannels; - } - _dst_sz = _nsamples * _nchannels; - for (i = 0; i < _dst_sz; i++) { - dst[i] = (1.0F / 32768) * _src[i]; - } - return _nsamples; -} - -int op_read_float(OggOpusFile *_of, float *_pcm, int _buf_size, int *_li) { - return op_filter_read_native(_of, _pcm, _buf_size, op_short2float_filter, _li); -} - -static int op_short2float_stereo_filter(OggOpusFile *_of, - void *_dst, int _dst_sz, op_sample *_src, int _nsamples, int _nchannels) { - float *dst; - int i; - dst = (float *)_dst; - _nsamples = OP_MIN(_nsamples, _dst_sz >> 1); - if (_nchannels == 1) { - _nsamples = op_short2float_filter(_of, dst, _nsamples, _src, _nsamples, 1); - for (i = _nsamples; i-- > 0;) { - dst[2 * i + 0] = dst[2 * i + 1] = dst[i]; - } - } else if (_nchannels < 5) { - /* For 3 or 4 channels, we can downmix in fixed point without risk of - clipping.*/ - if (_nchannels > 2) { - _nsamples = op_stereo_filter(_of, _src, _nsamples * 2, - _src, _nsamples, _nchannels); - } - return op_short2float_filter(_of, dst, _dst_sz, _src, _nsamples, 2); - } else { - /* For 5 or more channels, we convert to floats and then downmix (so that we - don't risk clipping).*/ - for (i = 0; i < _nsamples; i++) { - float l; - float r; - int ci; - l = r = 0; - for (ci = 0; ci < _nchannels; ci++) { - float s; - s = (1.0F / 32768) * _src[_nchannels * i + ci]; - l += OP_STEREO_DOWNMIX[_nchannels - 3][ci][0] * s; - r += OP_STEREO_DOWNMIX[_nchannels - 3][ci][1] * s; - } - dst[2 * i + 0] = l; - dst[2 * i + 1] = r; - } - } - return _nsamples; -} - -int op_read_float_stereo(OggOpusFile *_of, float *_pcm, int _buf_size) { - return op_filter_read_native(_of, _pcm, _buf_size, - op_short2float_stereo_filter, NULL); -} - -# endif - -#else - -# if defined(OP_HAVE_LRINTF) -# include -# define op_float2int(_x) (lrintf(_x)) -# else -# define op_float2int(_x) ((int)((_x)+((_x)<0?-0.5F:0.5F))) -# endif - -/* The dithering code here is adapted from opusdec, part of opus-tools. - It was originally written by Greg Maxwell.*/ - -static opus_uint32 op_rand(opus_uint32 _seed) { - return _seed * 96314165 + 907633515 & 0xFFFFFFFFU; -} - -/* This implements 16-bit quantization with full triangular dither and IIR noise - shaping. - The noise shaping filters were designed by Sebastian Gesemann, and are based - on the LAME ATH curves with flattening to limit their peak gain to 20 dB. - Everyone else's noise shaping filters are mildly crazy. - The 48 kHz version of this filter is just a warped version of the 44.1 kHz - filter and probably could be improved by shifting the HF shelf up in - frequency a little bit, since 48 kHz has a bit more room and being more - conservative against bat-ears is probably more important than more noise - suppression. - This process can increase the peak level of the signal (in theory by the peak - error of 1.5 +20 dB, though that is unobservably rare). - To avoid clipping, the signal is attenuated by a couple thousandths of a dB. - Initially, the approach taken here was to only attenuate by the 99.9th - percentile, making clipping rare but not impossible (like SoX), but the - limited gain of the filter means that the worst case was only two - thousandths of a dB more, so this just uses the worst case. - The attenuation is probably also helpful to prevent clipping in the DAC - reconstruction filters or downstream resampling, in any case.*/ - -# define OP_GAIN (32753.0F) - -# define OP_PRNG_GAIN (1.0F/(float)0xFFFFFFFF) - -/*48 kHz noise shaping filter, sd=2.34.*/ - -static const float OP_FCOEF_B[4] = { - 2.2374F, -0.7339F, -0.1251F, -0.6033F -}; - -static const float OP_FCOEF_A[4] = { - 0.9030F, 0.0116F, -0.5853F, -0.2571F -}; - -static int op_float2short_filter(OggOpusFile *_of, void *_dst, int _dst_sz, - float *_src, int _nsamples, int _nchannels) { - opus_int16 *dst; - int ci; - int i; - dst = (opus_int16 *)_dst; - if (OP_UNLIKELY(_nsamples * _nchannels > _dst_sz)) { - _nsamples = _dst_sz / _nchannels; - } -# if defined(OP_SOFT_CLIP) - if (_of->state_channel_count != _nchannels) { - for (ci = 0; ci < _nchannels; ci++) { - _of->clip_state[ci] = 0; - } - } - opus_pcm_soft_clip(_src, _nsamples, _nchannels, _of->clip_state); -# endif - if (_of->dither_disabled) { - for (i = 0; i < _nchannels * _nsamples; i++) { - dst[i] = op_float2int(OP_CLAMP(-32768, 32768.0F * _src[i], 32767)); - } - } else { - opus_uint32 seed; - int mute; - seed = _of->dither_seed; - mute = _of->dither_mute; - if (_of->state_channel_count != _nchannels) { - mute = 65; - } - /* In order to avoid replacing digital silence with quiet dither noise, we - mute if the output has been silent for a while.*/ - if (mute > 64) { - memset(_of->dither_a, 0, sizeof(*_of->dither_a) * 4 * _nchannels); - } - for (i = 0; i < _nsamples; i++) { - int silent; - silent = 1; - for (ci = 0; ci < _nchannels; ci++) { - float r; - float s; - float err; - int si; - int j; - s = _src[_nchannels * i + ci]; - silent &= s == 0; - s *= OP_GAIN; - err = 0; - for (j = 0; j < 4; j++) { - err += OP_FCOEF_B[j] * _of->dither_b[ci * 4 + j] - - OP_FCOEF_A[j] * _of->dither_a[ci * 4 + j]; - } - for (j = 3; j-- > 0;) { - _of->dither_a[ci * 4 + j + 1] = _of->dither_a[ci * 4 + j]; - } - for (j = 3; j-- > 0;) { - _of->dither_b[ci * 4 + j + 1] = _of->dither_b[ci * 4 + j]; - } - _of->dither_a[ci * 4] = err; - s -= err; - if (mute > 16) { - r = 0; - } else { - seed = op_rand(seed); - r = seed * OP_PRNG_GAIN; - seed = op_rand(seed); - r -= seed * OP_PRNG_GAIN; - } - /* Clamp in float out of paranoia that the input will be > 96 dBFS and - wrap if the integer is clamped.*/ - si = op_float2int(OP_CLAMP(-32768, s + r, 32767)); - dst[_nchannels * i + ci] = (opus_int16)si; - /* Including clipping in the noise shaping is generally disastrous: the - futile effort to restore the clipped energy results in more clipping. - However, small amounts---at the level which could normally be created - by dither and rounding---are harmless and can even reduce clipping - somewhat due to the clipping sometimes reducing the dither + rounding - error.*/ - _of->dither_b[ci * 4] = mute > 16 ? 0 : OP_CLAMP(-1.5F, si - s, 1.5F); - } - mute++; - if (!silent) { - mute = 0; - } - } - _of->dither_mute = OP_MIN(mute, 65); - _of->dither_seed = seed; - } - _of->state_channel_count = _nchannels; - return _nsamples; -} - -int op_read(OggOpusFile *_of, opus_int16 *_pcm, int _buf_size, int *_li) { - return op_filter_read_native(_of, _pcm, _buf_size, op_float2short_filter, _li); -} - -int op_read_float(OggOpusFile *_of, float *_pcm, int _buf_size, int *_li) { - _of->state_channel_count = 0; - return op_read_native(_of, _pcm, _buf_size, _li); -} - -static int op_stereo_filter(OggOpusFile *_of, void *_dst, int _dst_sz, - op_sample *_src, int _nsamples, int _nchannels) { - (void)_of; - _nsamples = OP_MIN(_nsamples, _dst_sz >> 1); - if (_nchannels == 2) { - memcpy(_dst, _src, _nsamples * 2 * sizeof(*_src)); - } else { - float *dst; - int i; - dst = (float *)_dst; - if (_nchannels == 1) { - for (i = 0; i < _nsamples; i++) { - dst[2 * i + 0] = dst[2 * i + 1] = _src[i]; - } - } else { - for (i = 0; i < _nsamples; i++) { - float l; - float r; - int ci; - l = r = 0; - for (ci = 0; ci < _nchannels; ci++) { - l += OP_STEREO_DOWNMIX[_nchannels - 3][ci][0] * _src[_nchannels * i + ci]; - r += OP_STEREO_DOWNMIX[_nchannels - 3][ci][1] * _src[_nchannels * i + ci]; - } - dst[2 * i + 0] = l; - dst[2 * i + 1] = r; - } - } - } - return _nsamples; -} - -static int op_float2short_stereo_filter(OggOpusFile *_of, - void *_dst, int _dst_sz, op_sample *_src, int _nsamples, int _nchannels) { - opus_int16 *dst; - dst = (opus_int16 *)_dst; - if (_nchannels == 1) { - int i; - _nsamples = op_float2short_filter(_of, dst, _dst_sz >> 1, _src, _nsamples, 1); - for (i = _nsamples; i-- > 0;) { - dst[2 * i + 0] = dst[2 * i + 1] = dst[i]; - } - } else { - if (_nchannels > 2) { - _nsamples = OP_MIN(_nsamples, _dst_sz >> 1); - _nsamples = op_stereo_filter(_of, _src, _nsamples * 2, - _src, _nsamples, _nchannels); - } - _nsamples = op_float2short_filter(_of, dst, _dst_sz, _src, _nsamples, 2); - } - return _nsamples; -} - -int op_read_stereo(OggOpusFile *_of, opus_int16 *_pcm, int _buf_size) { - return op_filter_read_native(_of, _pcm, _buf_size, - op_float2short_stereo_filter, NULL); -} - -int op_read_float_stereo(OggOpusFile *_of, float *_pcm, int _buf_size) { - _of->state_channel_count = 0; - return op_filter_read_native(_of, _pcm, _buf_size, op_stereo_filter, NULL); -} - -#endif diff --git a/src/opusfile/opusfile.h b/src/opusfile/opusfile.h deleted file mode 100644 index c5e1292..0000000 --- a/src/opusfile/opusfile.h +++ /dev/null @@ -1,2164 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2012 - by the Xiph.Org Foundation and contributors https://xiph.org/ - * * - ******************************************************************** - - function: stdio-based convenience library for opening/seeking/decoding - last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $ - - ********************************************************************/ -#if !defined(_opusfile_h) -# define _opusfile_h (1) - -/** \mainpage - \section Introduction - - This is the documentation for the libopusfile C API. - - The libopusfile package provides a convenient high-level API for - decoding and basic manipulation of all Ogg Opus audio streams. - libopusfile is implemented as a layer on top of Xiph.Org's - reference - libogg - and - libopus - libraries. - - libopusfile provides several sets of built-in routines for - file/stream access, and may also use custom stream I/O routines provided by - the embedded environment. - There are built-in I/O routines provided for ANSI-compliant - stdio (FILE *), memory buffers, and URLs - (including URLs, plus optionally and URLs). - - \section Organization - - The main API is divided into several sections: - - \ref stream_open_close - - \ref stream_info - - \ref stream_decoding - - \ref stream_seeking - - Several additional sections are not tied to the main API. - - \ref stream_callbacks - - \ref header_info - - \ref error_codes - - \section Overview - - The libopusfile API always decodes files to 48 kHz. - The original sample rate is not preserved by the lossy compression, though - it is stored in the header to allow you to resample to it after decoding - (the libopusfile API does not currently provide a resampler, - but the - the - Speex resampler is a good choice if you need one). - In general, if you are playing back the audio, you should leave it at - 48 kHz, provided your audio hardware supports it. - When decoding to a file, it may be worth resampling back to the original - sample rate, so as not to surprise users who might not expect the sample - rate to change after encoding to Opus and decoding. - - Opus files can contain anywhere from 1 to 255 channels of audio. - The channel mappings for up to 8 channels are the same as the - Vorbis - mappings. - A special stereo API can convert everything to 2 channels, making it simple - to support multichannel files in an application which only has stereo - output. - Although the libopusfile ABI provides support for the theoretical - maximum number of channels, the current implementation does not support - files with more than 8 channels, as they do not have well-defined channel - mappings. - - Like all Ogg files, Opus files may be "chained". - That is, multiple Opus files may be combined into a single, longer file just - by concatenating the original files. - This is commonly done in internet radio streaming, as it allows the title - and artist to be updated each time the song changes, since each link in the - chain includes its own set of metadata. - - libopusfile fully supports chained files. - It will decode the first Opus stream found in each link of a chained file - (ignoring any other streams that might be concurrently multiplexed with it, - such as a video stream). - - The channel count can also change between links. - If your application is not prepared to deal with this, it can use the stereo - API to ensure the audio from all links will always get decoded into a - common format. - Since libopusfile always decodes to 48 kHz, you do not have to - worry about the sample rate changing between links (as was possible with - Vorbis). - This makes application support for chained files with libopusfile - very easy.*/ - -# if defined(__cplusplus) -extern "C" { -# endif - -# include -# include -# include "../libogg/ogg/ogg.h" -# include "../libopus/opus_multistream.h" - -/**@cond PRIVATE*/ - -/*Enable special features for gcc and gcc-compatible compilers.*/ -# if !defined(OP_GNUC_PREREQ) -# if defined(__GNUC__)&&defined(__GNUC_MINOR__) -# define OP_GNUC_PREREQ(_maj,_min) \ - ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) -# else -# define OP_GNUC_PREREQ(_maj,_min) 0 -# endif -# endif - -# if OP_GNUC_PREREQ(4,0) -# pragma GCC visibility push(default) -# endif - -typedef struct OpusHead OpusHead; -typedef struct OpusTags OpusTags; -typedef struct OpusPictureTag OpusPictureTag; -typedef struct OpusServerInfo OpusServerInfo; -typedef struct OpusFileCallbacks OpusFileCallbacks; -typedef struct OggOpusFile OggOpusFile; - -/*Warning attributes for libopusfile functions.*/ -# if OP_GNUC_PREREQ(3,4) -# define OP_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) -# else -# define OP_WARN_UNUSED_RESULT -# endif -# if OP_GNUC_PREREQ(3,4) -# define OP_ARG_NONNULL(_x) __attribute__((__nonnull__(_x))) -# else -# define OP_ARG_NONNULL(_x) -# endif - -/**@endcond*/ - -/**\defgroup error_codes Error Codes*/ -/*@{*/ -/** \name List of possible error codes - Many of the functions in this library return a negative error code when a - function fails. - This list provides a brief explanation of the common errors. - See each individual function for more details on what a specific error code - means in that context.*/ -/*@{*/ - -/**A request did not succeed.*/ -#define OP_FALSE (-1) -/*Currently not used externally.*/ -#define OP_EOF (-2) -/** There was a hole in the page sequence numbers (e.g., a page was corrupt or - missing).*/ -#define OP_HOLE (-3) -/** An underlying read, seek, or tell operation failed when it should have - succeeded.*/ -#define OP_EREAD (-128) -/** A NULL pointer was passed where one was unexpected, or an - internal memory allocation failed, or an internal library error was - encountered.*/ -#define OP_EFAULT (-129) -/** The stream used a feature that is not implemented, such as an unsupported - channel family.*/ -#define OP_EIMPL (-130) -/**One or more parameters to a function were invalid.*/ -#define OP_EINVAL (-131) -/** A purported Ogg Opus stream did not begin with an Ogg page, a purported - header packet did not start with one of the required strings, "OpusHead" or - "OpusTags", or a link in a chained file was encountered that did not - contain any logical Opus streams.*/ -#define OP_ENOTFORMAT (-132) -/** A required header packet was not properly formatted, contained illegal - values, or was missing altogether.*/ -#define OP_EBADHEADER (-133) -/**The ID header contained an unrecognized version number.*/ -#define OP_EVERSION (-134) -/*Currently not used at all.*/ -#define OP_ENOTAUDIO (-135) -/** An audio packet failed to decode properly. - This is usually caused by a multistream Ogg packet where the durations of - the individual Opus packets contained in it are not all the same.*/ -#define OP_EBADPACKET (-136) -/** We failed to find data we had seen before, or the bitstream structure was - sufficiently malformed that seeking to the target destination was - impossible.*/ -#define OP_EBADLINK (-137) -/**An operation that requires seeking was requested on an unseekable stream.*/ -#define OP_ENOSEEK (-138) -/**The first or last granule position of a link failed basic validity checks.*/ -#define OP_EBADTIMESTAMP (-139) - -/*@}*/ -/*@}*/ - -/**\defgroup header_info Header Information*/ -/*@{*/ - -/**The maximum number of channels in an Ogg Opus stream.*/ -#define OPUS_CHANNEL_COUNT_MAX (255) - -/** Ogg Opus bitstream information. - This contains the basic playback parameters for a stream, and corresponds to - the initial ID header packet of an Ogg Opus stream.*/ -struct OpusHead { - /** The Ogg Opus format version, in the range 0...255. - The top 4 bits represent a "major" version, and the bottom four bits - represent backwards-compatible "minor" revisions. - The current specification describes version 1. - This library will recognize versions up through 15 as backwards compatible - with the current specification. - An earlier draft of the specification described a version 0, but the only - difference between version 1 and version 0 is that version 0 did - not specify the semantics for handling the version field.*/ - int version; - /**The number of channels, in the range 1...255.*/ - int channel_count; - /** The number of samples that should be discarded from the beginning of the - stream.*/ - unsigned pre_skip; - /** The sampling rate of the original input. - All Opus audio is coded at 48 kHz, and should also be decoded at 48 kHz - for playback (unless the target hardware does not support this sampling - rate). - However, this field may be used to resample the audio back to the original - sampling rate, for example, when saving the output to a file.*/ - opus_uint32 input_sample_rate; - /** The gain to apply to the decoded output, in dB, as a Q8 value in the range - -32768...32767. - The libopusfile API will automatically apply this gain to the - decoded output before returning it, scaling it by - pow(10,output_gain/(20.0*256)). - You can adjust this behavior with op_set_gain_offset().*/ - int output_gain; - /** The channel mapping family, in the range 0...255. - Channel mapping family 0 covers mono or stereo in a single stream. - Channel mapping family 1 covers 1 to 8 channels in one or more streams, - using the Vorbis speaker assignments. - Channel mapping family 255 covers 1 to 255 channels in one or more - streams, but without any defined speaker assignment.*/ - int mapping_family; - /**The number of Opus streams in each Ogg packet, in the range 1...255.*/ - int stream_count; - /** The number of coupled Opus streams in each Ogg packet, in the range - 0...127. - This must satisfy 0 <= coupled_count <= stream_count and - coupled_count + stream_count <= 255. - The coupled streams appear first, before all uncoupled streams, in an Ogg - Opus packet.*/ - int coupled_count; - /** The mapping from coded stream channels to output channels. - Let index=mapping[k] be the value for channel k. - If index<2*coupled_count, then it refers to the left channel - from stream (index/2) if even, and the right channel from - stream (index/2) if odd. - Otherwise, it refers to the output of the uncoupled stream - (index-coupled_count).*/ - unsigned char mapping[OPUS_CHANNEL_COUNT_MAX]; -}; - -/** The metadata from an Ogg Opus stream. - - This structure holds the in-stream metadata corresponding to the 'comment' - header packet of an Ogg Opus stream. - The comment header is meant to be used much like someone jotting a quick - note on the label of a CD. - It should be a short, to the point text note that can be more than a couple - words, but not more than a short paragraph. - - The metadata is stored as a series of (tag, value) pairs, in length-encoded - string vectors, using the same format as Vorbis (without the final "framing - bit"), Theora, and Speex, except for the packet header. - The first occurrence of the '=' character delimits the tag and value. - A particular tag may occur more than once, and order is significant. - The character set encoding for the strings is always UTF-8, but the tag - names are limited to ASCII, and treated as case-insensitive. - See the Vorbis - comment header specification for details. - - In filling in this structure, libopusfile will null-terminate the - #user_comments strings for safety. - However, the bitstream format itself treats them as 8-bit clean vectors, - possibly containing NUL characters, so the #comment_lengths array should be - treated as their authoritative length. - - This structure is binary and source-compatible with a - vorbis_comment, and pointers to it may be freely cast to - vorbis_comment pointers, and vice versa. - It is provided as a separate type to avoid introducing a compile-time - dependency on the libvorbis headers.*/ -struct OpusTags { - /**The array of comment string vectors.*/ - char **user_comments; - /**An array of the corresponding length of each vector, in bytes.*/ - int *comment_lengths; - /**The total number of comment streams.*/ - int comments; - /** The null-terminated vendor string. - This identifies the software used to encode the stream.*/ - char *vendor; -}; - -/**\name Picture tag image formats*/ -/*@{*/ - -/** The MIME type was not recognized, or the image data did not match the - declared MIME type.*/ -#define OP_PIC_FORMAT_UNKNOWN (-1) -/**The MIME type indicates the image data is really a URL.*/ -#define OP_PIC_FORMAT_URL (0) -/**The image is a JPEG.*/ -#define OP_PIC_FORMAT_JPEG (1) -/**The image is a PNG.*/ -#define OP_PIC_FORMAT_PNG (2) -/**The image is a GIF.*/ -#define OP_PIC_FORMAT_GIF (3) - -/*@}*/ - -/**The contents of a METADATA_BLOCK_PICTURE tag.*/ -struct OpusPictureTag { - /** The picture type according to the ID3v2 APIC frame: -

    -
  1. Other
  2. -
  3. 32x32 pixels 'file icon' (PNG only)
  4. -
  5. Other file icon
  6. -
  7. Cover (front)
  8. -
  9. Cover (back)
  10. -
  11. Leaflet page
  12. -
  13. Media (e.g. label side of CD)
  14. -
  15. Lead artist/lead performer/soloist
  16. -
  17. Artist/performer
  18. -
  19. Conductor
  20. -
  21. Band/Orchestra
  22. -
  23. Composer
  24. -
  25. Lyricist/text writer
  26. -
  27. Recording Location
  28. -
  29. During recording
  30. -
  31. During performance
  32. -
  33. Movie/video screen capture
  34. -
  35. A bright colored fish
  36. -
  37. Illustration
  38. -
  39. Band/artist logotype
  40. -
  41. Publisher/Studio logotype
  42. -
- Others are reserved and should not be used. - There may only be one each of picture type 1 and 2 in a file.*/ - opus_int32 type; - /** The MIME type of the picture, in printable ASCII characters 0x20-0x7E. - The MIME type may also be "-->" to signify that the data part - is a URL pointing to the picture instead of the picture data itself. - In this case, a terminating NUL is appended to the URL string in #data, - but #data_length is set to the length of the string excluding that - terminating NUL.*/ - char *mime_type; - /**The description of the picture, in UTF-8.*/ - char *description; - /**The width of the picture in pixels.*/ - opus_uint32 width; - /**The height of the picture in pixels.*/ - opus_uint32 height; - /** The color depth of the picture in bits-per-pixel (not - bits-per-channel).*/ - opus_uint32 depth; - /** For indexed-color pictures (e.g., GIF), the number of colors used, or 0 - for non-indexed pictures.*/ - opus_uint32 colors; - /**The length of the picture data in bytes.*/ - opus_uint32 data_length; - /**The binary picture data.*/ - unsigned char *data; - /** The format of the picture data, if known. - One of -
    -
  • #OP_PIC_FORMAT_UNKNOWN,
  • -
  • #OP_PIC_FORMAT_URL,
  • -
  • #OP_PIC_FORMAT_JPEG,
  • -
  • #OP_PIC_FORMAT_PNG, or
  • -
  • #OP_PIC_FORMAT_GIF.
  • -
*/ - int format; -}; - -/** \name Functions for manipulating header data - - These functions manipulate the #OpusHead and #OpusTags structures, - which describe the audio parameters and tag-value metadata, respectively. - These can be used to query the headers returned by libopusfile, or - to parse Opus headers from sources other than an Ogg Opus stream, provided - they use the same format.*/ -/*@{*/ - -/** Parses the contents of the ID header packet of an Ogg Opus stream. - \param[out] _head Returns the contents of the parsed packet. - The contents of this structure are untouched on error. - This may be NULL to merely test the header - for validity. - \param[in] _data The contents of the ID header packet. - \param _len The number of bytes of data in the ID header packet. - \return 0 on success or a negative value on error. - \retval #OP_ENOTFORMAT If the data does not start with the "OpusHead" - string. - \retval #OP_EVERSION If the version field signaled a version this library - does not know how to parse. - \retval #OP_EIMPL If the channel mapping family was 255, which general - purpose players should not attempt to play. - \retval #OP_EBADHEADER If the contents of the packet otherwise violate the - Ogg Opus specification: -
    -
  • Insufficient data,
  • -
  • Too much data for the known minor versions,
  • -
  • An unrecognized channel mapping family,
  • -
  • Zero channels or too many channels,
  • -
  • Zero coded streams,
  • -
  • Too many coupled streams, or
  • -
  • An invalid channel mapping index.
  • -
*/ -OP_WARN_UNUSED_RESULT int opus_head_parse(OpusHead *_head, - const unsigned char *_data, size_t _len) OP_ARG_NONNULL(2); - -/** Converts a granule position to a sample offset for a given Ogg Opus stream. - The sample offset is simply _gp-_head->pre_skip. - Granule position values smaller than OpusHead#pre_skip correspond to audio - that should never be played, and thus have no associated sample offset. - This function returns -1 for such values. - This function also correctly handles extremely large granule positions, - which may have wrapped around to a negative number when stored in a signed - ogg_int64_t value. - \param _head The #OpusHead information from the ID header of the stream. - \param _gp The granule position to convert. - \return The sample offset associated with the given granule position - (counting at a 48 kHz sampling rate), or the special value -1 on - error (i.e., the granule position was smaller than the pre-skip - amount).*/ -ogg_int64_t opus_granule_sample(const OpusHead *_head, ogg_int64_t _gp) -OP_ARG_NONNULL(1); - -/** Parses the contents of the 'comment' header packet of an Ogg Opus stream. - \param[out] _tags An uninitialized #OpusTags structure. - This returns the contents of the parsed packet. - The contents of this structure are untouched on error. - This may be NULL to merely test the header - for validity. - \param[in] _data The contents of the 'comment' header packet. - \param _len The number of bytes of data in the 'info' header packet. - \retval 0 Success. - \retval #OP_ENOTFORMAT If the data does not start with the "OpusTags" - string. - \retval #OP_EBADHEADER If the contents of the packet otherwise violate the - Ogg Opus specification. - \retval #OP_EFAULT If there wasn't enough memory to store the tags.*/ -OP_WARN_UNUSED_RESULT int opus_tags_parse(OpusTags *_tags, - const unsigned char *_data, size_t _len) OP_ARG_NONNULL(2); - -/** Performs a deep copy of an #OpusTags structure. - \param _dst The #OpusTags structure to copy into. - If this function fails, the contents of this structure remain - untouched. - \param _src The #OpusTags structure to copy from. - \retval 0 Success. - \retval #OP_EFAULT If there wasn't enough memory to copy the tags.*/ -int opus_tags_copy(OpusTags *_dst, const OpusTags *_src) OP_ARG_NONNULL(1); - -/** Initializes an #OpusTags structure. - This should be called on a freshly allocated #OpusTags structure before - attempting to use it. - \param _tags The #OpusTags structure to initialize.*/ -void opus_tags_init(OpusTags *_tags) OP_ARG_NONNULL(1); - -/** Add a (tag, value) pair to an initialized #OpusTags structure. - \note Neither opus_tags_add() nor opus_tags_add_comment() support values - containing embedded NULs, although the bitstream format does support them. - To add such tags, you will need to manipulate the #OpusTags structure - directly. - \param _tags The #OpusTags structure to add the (tag, value) pair to. - \param _tag A NUL-terminated, case-insensitive, ASCII string containing - the tag to add (without an '=' character). - \param _value A NUL-terminated UTF-8 containing the corresponding value. - \return 0 on success, or a negative value on failure. - \retval #OP_EFAULT An internal memory allocation failed.*/ -int opus_tags_add(OpusTags *_tags, const char *_tag, const char *_value) -OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) OP_ARG_NONNULL(3); - -/** Add a comment to an initialized #OpusTags structure. - \note Neither opus_tags_add_comment() nor opus_tags_add() support comments - containing embedded NULs, although the bitstream format does support them. - To add such tags, you will need to manipulate the #OpusTags structure - directly. - \param _tags The #OpusTags structure to add the comment to. - \param _comment A NUL-terminated UTF-8 string containing the comment in - "TAG=value" form. - \return 0 on success, or a negative value on failure. - \retval #OP_EFAULT An internal memory allocation failed.*/ -int opus_tags_add_comment(OpusTags *_tags, const char *_comment) -OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Replace the binary suffix data at the end of the packet (if any). - \param _tags An initialized #OpusTags structure. - \param _data A buffer of binary data to append after the encoded user - comments. - The least significant bit of the first byte of this data must - be set (to ensure the data is preserved by other editors). - \param _len The number of bytes of binary data to append. - This may be zero to remove any existing binary suffix data. - \return 0 on success, or a negative value on error. - \retval #OP_EINVAL \a _len was negative, or \a _len was positive but - \a _data was NULL or the least significant - bit of the first byte was not set. - \retval #OP_EFAULT An internal memory allocation failed.*/ -int opus_tags_set_binary_suffix(OpusTags *_tags, - const unsigned char *_data, int _len) OP_ARG_NONNULL(1); - -/** Look up a comment value by its tag. - \param _tags An initialized #OpusTags structure. - \param _tag The tag to look up. - \param _count The instance of the tag. - The same tag can appear multiple times, each with a distinct - value, so an index is required to retrieve them all. - The order in which these values appear is significant and - should be preserved. - Use opus_tags_query_count() to get the legal range for the - \a _count parameter. - \return A pointer to the queried tag's value. - This points directly to data in the #OpusTags structure. - It should not be modified or freed by the application, and - modifications to the structure may invalidate the pointer. - \retval NULL If no matching tag is found.*/ -const char *opus_tags_query(const OpusTags *_tags, const char *_tag, int _count) -OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Look up the number of instances of a tag. - Call this first when querying for a specific tag and then iterate over the - number of instances with separate calls to opus_tags_query() to retrieve - all the values for that tag in order. - \param _tags An initialized #OpusTags structure. - \param _tag The tag to look up. - \return The number of instances of this particular tag.*/ -int opus_tags_query_count(const OpusTags *_tags, const char *_tag) -OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Retrieve the binary suffix data at the end of the packet (if any). - \param _tags An initialized #OpusTags structure. - \param[out] _len Returns the number of bytes of binary suffix data returned. - \return A pointer to the binary suffix data, or NULL if none - was present.*/ -const unsigned char *opus_tags_get_binary_suffix(const OpusTags *_tags, - int *_len) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Get the album gain from an R128_ALBUM_GAIN tag, if one was specified. - This searches for the first R128_ALBUM_GAIN tag with a valid signed, - 16-bit decimal integer value and returns the value. - This routine is exposed merely for convenience for applications which wish - to do something special with the album gain (i.e., display it). - If you simply wish to apply the album gain instead of the header gain, you - can use op_set_gain_offset() with an #OP_ALBUM_GAIN type and no offset. - \param _tags An initialized #OpusTags structure. - \param[out] _gain_q8 The album gain, in 1/256ths of a dB. - This will lie in the range [-32768,32767], and should - be applied in addition to the header gain. - On error, no value is returned, and the previous - contents remain unchanged. - \return 0 on success, or a negative value on error. - \retval #OP_FALSE There was no album gain available in the given tags.*/ -int opus_tags_get_album_gain(const OpusTags *_tags, int *_gain_q8) -OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Get the track gain from an R128_TRACK_GAIN tag, if one was specified. - This searches for the first R128_TRACK_GAIN tag with a valid signed, - 16-bit decimal integer value and returns the value. - This routine is exposed merely for convenience for applications which wish - to do something special with the track gain (i.e., display it). - If you simply wish to apply the track gain instead of the header gain, you - can use op_set_gain_offset() with an #OP_TRACK_GAIN type and no offset. - \param _tags An initialized #OpusTags structure. - \param[out] _gain_q8 The track gain, in 1/256ths of a dB. - This will lie in the range [-32768,32767], and should - be applied in addition to the header gain. - On error, no value is returned, and the previous - contents remain unchanged. - \return 0 on success, or a negative value on error. - \retval #OP_FALSE There was no track gain available in the given tags.*/ -int opus_tags_get_track_gain(const OpusTags *_tags, int *_gain_q8) -OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Clears the #OpusTags structure. - This should be called on an #OpusTags structure after it is no longer - needed. - It will free all memory used by the structure members. - \param _tags The #OpusTags structure to clear.*/ -void opus_tags_clear(OpusTags *_tags) OP_ARG_NONNULL(1); - -/** Check if \a _comment is an instance of a \a _tag_name tag. - \see opus_tagncompare - \param _tag_name A NUL-terminated, case-insensitive, ASCII string containing - the name of the tag to check for (without the terminating - '=' character). - \param _comment The comment string to check. - \return An integer less than, equal to, or greater than zero if \a _comment - is found respectively, to be less than, to match, or be greater - than a "tag=value" string whose tag matches \a _tag_name.*/ -int opus_tagcompare(const char *_tag_name, const char *_comment); - -/** Check if \a _comment is an instance of a \a _tag_name tag. - This version is slightly more efficient than opus_tagcompare() if the length - of the tag name is already known (e.g., because it is a constant). - \see opus_tagcompare - \param _tag_name A case-insensitive ASCII string containing the name of the - tag to check for (without the terminating '=' character). - \param _tag_len The number of characters in the tag name. - This must be non-negative. - \param _comment The comment string to check. - \return An integer less than, equal to, or greater than zero if \a _comment - is found respectively, to be less than, to match, or be greater - than a "tag=value" string whose tag matches the first \a _tag_len - characters of \a _tag_name.*/ -int opus_tagncompare(const char *_tag_name, int _tag_len, const char *_comment); - -/** Parse a single METADATA_BLOCK_PICTURE tag. - This decodes the BASE64-encoded content of the tag and returns a structure - with the MIME type, description, image parameters (if known), and the - compressed image data. - If the MIME type indicates the presence of an image format we recognize - (JPEG, PNG, or GIF) and the actual image data contains the magic signature - associated with that format, then the OpusPictureTag::format field will be - set to the corresponding format. - This is provided as a convenience to avoid requiring applications to parse - the MIME type and/or do their own format detection for the commonly used - formats. - In this case, we also attempt to extract the image parameters directly from - the image data (overriding any that were present in the tag, which the - specification says applications are not meant to rely on). - The application must still provide its own support for actually decoding the - image data and, if applicable, retrieving that data from URLs. - \param[out] _pic Returns the parsed picture data. - No sanitation is done on the type, MIME type, or - description fields, so these might return invalid values. - The contents of this structure are left unmodified on - failure. - \param _tag The METADATA_BLOCK_PICTURE tag contents. - The leading "METADATA_BLOCK_PICTURE=" portion is optional, - to allow the function to be used on either directly on the - values in OpusTags::user_comments or on the return value - of opus_tags_query(). - \return 0 on success or a negative value on error. - \retval #OP_ENOTFORMAT The METADATA_BLOCK_PICTURE contents were not valid. - \retval #OP_EFAULT There was not enough memory to store the picture tag - contents.*/ -OP_WARN_UNUSED_RESULT int opus_picture_tag_parse(OpusPictureTag *_pic, - const char *_tag) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Initializes an #OpusPictureTag structure. - This should be called on a freshly allocated #OpusPictureTag structure - before attempting to use it. - \param _pic The #OpusPictureTag structure to initialize.*/ -void opus_picture_tag_init(OpusPictureTag *_pic) OP_ARG_NONNULL(1); - -/** Clears the #OpusPictureTag structure. - This should be called on an #OpusPictureTag structure after it is no longer - needed. - It will free all memory used by the structure members. - \param _pic The #OpusPictureTag structure to clear.*/ -void opus_picture_tag_clear(OpusPictureTag *_pic) OP_ARG_NONNULL(1); - -/*@}*/ - -/*@}*/ - -/**\defgroup url_options URL Reading Options*/ -/*@{*/ -/** \name URL reading options - Options for op_url_stream_create() and associated functions. - These allow you to provide proxy configuration parameters, skip SSL - certificate checks, etc. - Options are processed in order, and if the same option is passed multiple - times, only the value specified by the last occurrence has an effect - (unless otherwise specified). - They may be expanded in the future.*/ -/*@{*/ - -/**@cond PRIVATE*/ - -/* These are the raw numbers used to define the request codes. - They should not be used directly.*/ -#define OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST (6464) -#define OP_HTTP_PROXY_HOST_REQUEST (6528) -#define OP_HTTP_PROXY_PORT_REQUEST (6592) -#define OP_HTTP_PROXY_USER_REQUEST (6656) -#define OP_HTTP_PROXY_PASS_REQUEST (6720) -#define OP_GET_SERVER_INFO_REQUEST (6784) - -#define OP_URL_OPT(_request) ((char *)(_request)) - -/* These macros trigger compilation errors or warnings if the wrong types are - provided to one of the URL options.*/ -#define OP_CHECK_INT(_x) ((void)((_x)==(opus_int32)0),(opus_int32)(_x)) -#define OP_CHECK_CONST_CHAR_PTR(_x) ((_x)+((_x)-(const char *)(_x))) -#define OP_CHECK_SERVER_INFO_PTR(_x) ((_x)+((_x)-(OpusServerInfo *)(_x))) - -/**@endcond*/ - -/**HTTP/Shoutcast/Icecast server information associated with a URL.*/ -struct OpusServerInfo { - /** The name of the server (icy-name/ice-name). - This is NULL if there was no icy-name or - ice-name header.*/ - char *name; - /** A short description of the server (icy-description/ice-description). - This is NULL if there was no icy-description or - ice-description header.*/ - char *description; - /** The genre the server falls under (icy-genre/ice-genre). - This is NULL if there was no icy-genre or - ice-genre header.*/ - char *genre; - /** The homepage for the server (icy-url/ice-url). - This is NULL if there was no icy-url or - ice-url header.*/ - char *url; - /** The software used by the origin server (Server). - This is NULL if there was no Server header.*/ - char *server; - /** The media type of the entity sent to the recipient (Content-Type). - This is NULL if there was no Content-Type - header.*/ - char *content_type; - /** The nominal stream bitrate in kbps (icy-br/ice-bitrate). - This is -1 if there was no icy-br or - ice-bitrate header.*/ - opus_int32 bitrate_kbps; - /** Flag indicating whether the server is public (1) or not - (0) (icy-pub/ice-public). - This is -1 if there was no icy-pub or - ice-public header.*/ - int is_public; - /** Flag indicating whether the server is using HTTPS instead of HTTP. - This is 0 unless HTTPS is being used. - This may not match the protocol used in the original URL if there were - redirections.*/ - int is_ssl; -}; - -/** Initializes an #OpusServerInfo structure. - All fields are set as if the corresponding header was not available. - \param _info The #OpusServerInfo structure to initialize. - \note If you use this function, you must link against libopusurl.*/ -void opus_server_info_init(OpusServerInfo *_info) OP_ARG_NONNULL(1); - -/** Clears the #OpusServerInfo structure. - This should be called on an #OpusServerInfo structure after it is no longer - needed. - It will free all memory used by the structure members. - \param _info The #OpusServerInfo structure to clear. - \note If you use this function, you must link against libopusurl.*/ -void opus_server_info_clear(OpusServerInfo *_info) OP_ARG_NONNULL(1); - -/** Skip the certificate check when connecting via TLS/SSL (https). - \param _b opus_int32: Whether or not to skip the certificate - check. - The check will be skipped if \a _b is non-zero, and will not be - skipped if \a _b is zero. - \hideinitializer*/ -#define OP_SSL_SKIP_CERTIFICATE_CHECK(_b) \ - OP_URL_OPT(OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST),OP_CHECK_INT(_b) - -/** Proxy connections through the given host. - If no port is specified via #OP_HTTP_PROXY_PORT, the port number defaults - to 8080 (http-alt). - All proxy parameters are ignored for non-http and non-https URLs. - \param _host const char *: The proxy server hostname. - This may be NULL to disable the use of a proxy - server. - \hideinitializer*/ -#define OP_HTTP_PROXY_HOST(_host) \ - OP_URL_OPT(OP_HTTP_PROXY_HOST_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host) - -/** Use the given port when proxying connections. - This option only has an effect if #OP_HTTP_PROXY_HOST is specified with a - non-NULL \a _host. - If this option is not provided, the proxy port number defaults to 8080 - (http-alt). - All proxy parameters are ignored for non-http and non-https URLs. - \param _port opus_int32: The proxy server port. - This must be in the range 0...65535 (inclusive), or the - URL function this is passed to will fail. - \hideinitializer*/ -#define OP_HTTP_PROXY_PORT(_port) \ - OP_URL_OPT(OP_HTTP_PROXY_PORT_REQUEST),OP_CHECK_INT(_port) - -/** Use the given user name for authentication when proxying connections. - All proxy parameters are ignored for non-http and non-https URLs. - \param _user const char *: The proxy server user name. - This may be NULL to disable proxy - authentication. - A non-NULL value only has an effect - if #OP_HTTP_PROXY_HOST and #OP_HTTP_PROXY_PASS - are also specified with non-NULL - arguments. - \hideinitializer*/ -#define OP_HTTP_PROXY_USER(_user) \ - OP_URL_OPT(OP_HTTP_PROXY_USER_REQUEST),OP_CHECK_CONST_CHAR_PTR(_user) - -/** Use the given password for authentication when proxying connections. - All proxy parameters are ignored for non-http and non-https URLs. - \param _pass const char *: The proxy server password. - This may be NULL to disable proxy - authentication. - A non-NULL value only has an effect - if #OP_HTTP_PROXY_HOST and #OP_HTTP_PROXY_USER - are also specified with non-NULL - arguments. - \hideinitializer*/ -#define OP_HTTP_PROXY_PASS(_pass) \ - OP_URL_OPT(OP_HTTP_PROXY_PASS_REQUEST),OP_CHECK_CONST_CHAR_PTR(_pass) - -/** Parse information about the streaming server (if any) and return it. - Very little validation is done. - In particular, OpusServerInfo::url may not be a valid URL, - OpusServerInfo::bitrate_kbps may not really be in kbps, and - OpusServerInfo::content_type may not be a valid MIME type. - The character set of the string fields is not specified anywhere, and should - not be assumed to be valid UTF-8. - \param _info OpusServerInfo *: Returns information about the server. - If there is any error opening the stream, the - contents of this structure remain - unmodified. - On success, fills in the structure with the - server information that was available, if - any. - After a successful return, the contents of - this structure should be freed by calling - opus_server_info_clear(). - \hideinitializer*/ -#define OP_GET_SERVER_INFO(_info) \ - OP_URL_OPT(OP_GET_SERVER_INFO_REQUEST),OP_CHECK_SERVER_INFO_PTR(_info) - -/*@}*/ -/*@}*/ - -/**\defgroup stream_callbacks Abstract Stream Reading Interface*/ -/*@{*/ -/** \name Functions for reading from streams - These functions define the interface used to read from and seek in a stream - of data. - A stream does not need to implement seeking, but the decoder will not be - able to seek if it does not do so. - These functions also include some convenience routines for working with - standard FILE pointers, complete streams stored in a single - block of memory, or URLs.*/ -/*@{*/ - -/** Reads up to \a _nbytes bytes of data from \a _stream. - \param _stream The stream to read from. - \param[out] _ptr The buffer to store the data in. - \param _nbytes The maximum number of bytes to read. - This function may return fewer, though it will not - return zero unless it reaches end-of-file. - \return The number of bytes successfully read, or a negative value on - error.*/ -typedef int (*op_read_func)(void *_stream, unsigned char *_ptr, int _nbytes); - -/** Sets the position indicator for \a _stream. - The new position, measured in bytes, is obtained by adding \a _offset - bytes to the position specified by \a _whence. - If \a _whence is set to SEEK_SET, SEEK_CUR, or - SEEK_END, the offset is relative to the start of the stream, - the current position indicator, or end-of-file, respectively. - \retval 0 Success. - \retval -1 Seeking is not supported or an error occurred. - errno need not be set.*/ -typedef int (*op_seek_func)(void *_stream, opus_int64 _offset, int _whence); - -/** Obtains the current value of the position indicator for \a _stream. - \return The current position indicator.*/ -typedef opus_int64(*op_tell_func)(void *_stream); - -/** Closes the underlying stream. - \retval 0 Success. - \retval EOF An error occurred. - errno need not be set.*/ -typedef int (*op_close_func)(void *_stream); - -/** The callbacks used to access non-FILE stream resources. - The function prototypes are basically the same as for the stdio functions - fread(), fseek(), ftell(), and - fclose(). - The differences are that the FILE * arguments have been - replaced with a void *, which is to be used as a pointer to - whatever internal data these functions might need, that #seek and #tell - take and return 64-bit offsets, and that #seek must return -1 if - the stream is unseekable.*/ -struct OpusFileCallbacks { - /** Used to read data from the stream. - This must not be NULL.*/ - op_read_func read; - /** Used to seek in the stream. - This may be NULL if seeking is not implemented.*/ - op_seek_func seek; - /** Used to return the current read position in the stream. - This may be NULL if seeking is not implemented.*/ - op_tell_func tell; - /** Used to close the stream when the decoder is freed. - This may be NULL to leave the stream open.*/ - op_close_func close; -}; - -/** Opens a stream with fopen() and fills in a set of callbacks - that can be used to access it. - This is useful to avoid writing your own portable 64-bit seeking wrappers, - and also avoids cross-module linking issues on Windows, where a - FILE * must be accessed by routines defined in the same module - that opened it. - \param[out] _cb The callbacks to use for this file. - If there is an error opening the file, nothing will be - filled in here. - \param _path The path to the file to open. - On Windows, this string must be UTF-8 (to allow access to - files whose names cannot be represented in the current - MBCS code page). - All other systems use the native character encoding. - \param _mode The mode to open the file in. - \return A stream handle to use with the callbacks, or NULL on - error.*/ -OP_WARN_UNUSED_RESULT void *op_fopen(OpusFileCallbacks *_cb, - const char *_path, const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) -OP_ARG_NONNULL(3); - -/** Opens a stream with fdopen() and fills in a set of callbacks - that can be used to access it. - This is useful to avoid writing your own portable 64-bit seeking wrappers, - and also avoids cross-module linking issues on Windows, where a - FILE * must be accessed by routines defined in the same module - that opened it. - \param[out] _cb The callbacks to use for this file. - If there is an error opening the file, nothing will be - filled in here. - \param _fd The file descriptor to open. - \param _mode The mode to open the file in. - \return A stream handle to use with the callbacks, or NULL on - error.*/ -OP_WARN_UNUSED_RESULT void *op_fdopen(OpusFileCallbacks *_cb, - int _fd, const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(3); - -/** Opens a stream with freopen() and fills in a set of callbacks - that can be used to access it. - This is useful to avoid writing your own portable 64-bit seeking wrappers, - and also avoids cross-module linking issues on Windows, where a - FILE * must be accessed by routines defined in the same module - that opened it. - \param[out] _cb The callbacks to use for this file. - If there is an error opening the file, nothing will be - filled in here. - \param _path The path to the file to open. - On Windows, this string must be UTF-8 (to allow access - to files whose names cannot be represented in the - current MBCS code page). - All other systems use the native character encoding. - \param _mode The mode to open the file in. - \param _stream A stream previously returned by op_fopen(), op_fdopen(), - or op_freopen(). - \return A stream handle to use with the callbacks, or NULL on - error.*/ -OP_WARN_UNUSED_RESULT void *op_freopen(OpusFileCallbacks *_cb, - const char *_path, const char *_mode, void *_stream) OP_ARG_NONNULL(1) -OP_ARG_NONNULL(2) OP_ARG_NONNULL(3) OP_ARG_NONNULL(4); - -/** Creates a stream that reads from the given block of memory. - This block of memory must contain the complete stream to decode. - This is useful for caching small streams (e.g., sound effects) in RAM. - \param[out] _cb The callbacks to use for this stream. - If there is an error creating the stream, nothing will be - filled in here. - \param _data The block of memory to read from. - \param _size The size of the block of memory. - \return A stream handle to use with the callbacks, or NULL on - error.*/ -OP_WARN_UNUSED_RESULT void *op_mem_stream_create(OpusFileCallbacks *_cb, - const unsigned char *_data, size_t _size) OP_ARG_NONNULL(1); - -/** Creates a stream that reads from the given URL. - This function behaves identically to op_url_stream_create(), except that it - takes a va_list instead of a variable number of arguments. - It does not call the va_end macro, and because it invokes the - va_arg macro, the value of \a _ap is undefined after the call. - \note If you use this function, you must link against libopusurl. - \param[out] _cb The callbacks to use for this stream. - If there is an error creating the stream, nothing will - be filled in here. - \param _url The URL to read from. - Currently only the , , and - schemes are supported. - Both and may be disabled at compile - time, in which case opening such URLs will always fail. - Currently this only supports URIs. - IRIs should be converted to UTF-8 and URL-escaped, with - internationalized domain names encoded in punycode, - before passing them to this function. - \param[in,out] _ap A list of the \ref url_options "optional flags" to use. - This is a variable-length list of options terminated - with NULL. - \return A stream handle to use with the callbacks, or NULL on - error.*/ -OP_WARN_UNUSED_RESULT void *op_url_stream_vcreate(OpusFileCallbacks *_cb, - const char *_url, va_list _ap) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/** Creates a stream that reads from the given URL. - \note If you use this function, you must link against libopusurl. - \param[out] _cb The callbacks to use for this stream. - If there is an error creating the stream, nothing will be - filled in here. - \param _url The URL to read from. - Currently only the , , and schemes - are supported. - Both and may be disabled at compile time, - in which case opening such URLs will always fail. - Currently this only supports URIs. - IRIs should be converted to UTF-8 and URL-escaped, with - internationalized domain names encoded in punycode, before - passing them to this function. - \param ... The \ref url_options "optional flags" to use. - This is a variable-length list of options terminated with - NULL. - \return A stream handle to use with the callbacks, or NULL on - error.*/ -OP_WARN_UNUSED_RESULT void *op_url_stream_create(OpusFileCallbacks *_cb, - const char *_url, ...) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); - -/*@}*/ -/*@}*/ - -/**\defgroup stream_open_close Opening and Closing*/ -/*@{*/ -/** \name Functions for opening and closing streams - - These functions allow you to test a stream to see if it is Opus, open it, - and close it. - Several flavors are provided for each of the built-in stream types, plus a - more general version which takes a set of application-provided callbacks.*/ -/*@{*/ - -/** Test to see if this is an Opus stream. - For good results, you will need at least 57 bytes (for a pure Opus-only - stream). - Something like 512 bytes will give more reliable results for multiplexed - streams. - This function is meant to be a quick-rejection filter. - Its purpose is not to guarantee that a stream is a valid Opus stream, but to - ensure that it looks enough like Opus that it isn't going to be recognized - as some other format (except possibly an Opus stream that is also - multiplexed with other codecs, such as video). - \param[out] _head The parsed ID header contents. - You may pass NULL if you do not need - this information. - If the function fails, the contents of this structure - remain untouched. - \param _initial_data An initial buffer of data from the start of the - stream. - \param _initial_bytes The number of bytes in \a _initial_data. - \return 0 if the data appears to be Opus, or a negative value on error. - \retval #OP_FALSE There was not enough data to tell if this was an Opus - stream or not. - \retval #OP_EFAULT An internal memory allocation failed. - \retval #OP_EIMPL The stream used a feature that is not implemented, - such as an unsupported channel family. - \retval #OP_ENOTFORMAT If the data did not contain a recognizable ID - header for an Opus stream. - \retval #OP_EVERSION If the version field signaled a version this library - does not know how to parse. - \retval #OP_EBADHEADER The ID header was not properly formatted or contained - illegal values.*/ -int op_test(OpusHead *_head, - const unsigned char *_initial_data, size_t _initial_bytes); - -/** Open a stream from the given file path. - \param _path The path to the file to open. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want the - failure code. - The failure code will be #OP_EFAULT if the file could not - be opened, or one of the other failure codes from - op_open_callbacks() otherwise. - \return A freshly opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_open_file(const char *_path, int *_error) -OP_ARG_NONNULL(1); - -/** Open a stream from a memory buffer. - \param _data The memory buffer to open. - \param _size The number of bytes in the buffer. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want the - failure code. - See op_open_callbacks() for a full list of failure codes. - \return A freshly opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_open_memory(const unsigned char *_data, - size_t _size, int *_error); - -/** Open a stream from a URL. - This function behaves identically to op_open_url(), except that it - takes a va_list instead of a variable number of arguments. - It does not call the va_end macro, and because it invokes the - va_arg macro, the value of \a _ap is undefined after the call. - \note If you use this function, you must link against libopusurl. - \param _url The URL to open. - Currently only the , , and - schemes are supported. - Both and may be disabled at compile - time, in which case opening such URLs will always - fail. - Currently this only supports URIs. - IRIs should be converted to UTF-8 and URL-escaped, - with internationalized domain names encoded in - punycode, before passing them to this function. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want - the failure code. - See op_open_callbacks() for a full list of failure - codes. - \param[in,out] _ap A list of the \ref url_options "optional flags" to - use. - This is a variable-length list of options terminated - with NULL. - \return A freshly opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_vopen_url(const char *_url, - int *_error, va_list _ap) OP_ARG_NONNULL(1); - -/** Open a stream from a URL. - \note If you use this function, you must link against libopusurl. - \param _url The URL to open. - Currently only the , , and schemes - are supported. - Both and may be disabled at compile - time, in which case opening such URLs will always fail. - Currently this only supports URIs. - IRIs should be converted to UTF-8 and URL-escaped, with - internationalized domain names encoded in punycode, - before passing them to this function. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want the - failure code. - See op_open_callbacks() for a full list of failure codes. - \param ... The \ref url_options "optional flags" to use. - This is a variable-length list of options terminated with - NULL. - \return A freshly opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_open_url(const char *_url, - int *_error, ...) OP_ARG_NONNULL(1); - -/** Open a stream using the given set of callbacks to access it. - \param _stream The stream to read from (e.g., a FILE *). - This value will be passed verbatim as the first - argument to all of the callbacks. - \param _cb The callbacks with which to access the stream. - read() must - be implemented. - seek() and - tell() may - be NULL, or may always return -1 to - indicate a stream is unseekable, but if - seek() is - implemented and succeeds on a particular stream, then - tell() must - also. - close() may - be NULL, but if it is not, it will be - called when the \c OggOpusFile is destroyed by - op_free(). - It will not be called if op_open_callbacks() fails - with an error. - \param _initial_data An initial buffer of data from the start of the - stream. - Applications can read some number of bytes from the - start of the stream to help identify this as an Opus - stream, and then provide them here to allow the - stream to be opened, even if it is unseekable. - \param _initial_bytes The number of bytes in \a _initial_data. - If the stream is seekable, its current position (as - reported by - tell() - at the start of this function) must be equal to - \a _initial_bytes. - Otherwise, seeking to absolute positions will - generate inconsistent results. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want - the failure code. - The failure code will be one of -
-
#OP_EREAD
-
An underlying read, seek, or tell operation - failed when it should have succeeded, or we failed - to find data in the stream we had seen before.
-
#OP_EFAULT
-
There was a memory allocation failure, or an - internal library error.
-
#OP_EIMPL
-
The stream used a feature that is not - implemented, such as an unsupported channel - family.
-
#OP_EINVAL
-
seek() - was implemented and succeeded on this source, but - tell() - did not, or the starting position indicator was - not equal to \a _initial_bytes.
-
#OP_ENOTFORMAT
-
The stream contained a link that did not have - any logical Opus streams in it.
-
#OP_EBADHEADER
-
A required header packet was not properly - formatted, contained illegal values, or was missing - altogether.
-
#OP_EVERSION
-
An ID header contained an unrecognized version - number.
-
#OP_EBADLINK
-
We failed to find data we had seen before after - seeking.
-
#OP_EBADTIMESTAMP
-
The first or last timestamp in a link failed - basic validity checks.
-
- \return A freshly opened \c OggOpusFile, or NULL on error. - libopusfile does not take ownership of the stream - if the call fails. - The calling application is responsible for closing the stream if - this call returns an error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_open_callbacks(void *_stream, - const OpusFileCallbacks *_cb, const unsigned char *_initial_data, - size_t _initial_bytes, int *_error) OP_ARG_NONNULL(2); - -/** Partially open a stream from the given file path. - \see op_test_callbacks - \param _path The path to the file to open. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want the - failure code. - The failure code will be #OP_EFAULT if the file could not - be opened, or one of the other failure codes from - op_open_callbacks() otherwise. - \return A partially opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_test_file(const char *_path, int *_error) -OP_ARG_NONNULL(1); - -/** Partially open a stream from a memory buffer. - \see op_test_callbacks - \param _data The memory buffer to open. - \param _size The number of bytes in the buffer. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want the - failure code. - See op_open_callbacks() for a full list of failure codes. - \return A partially opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_test_memory(const unsigned char *_data, - size_t _size, int *_error); - -/** Partially open a stream from a URL. - This function behaves identically to op_test_url(), except that it - takes a va_list instead of a variable number of arguments. - It does not call the va_end macro, and because it invokes the - va_arg macro, the value of \a _ap is undefined after the call. - \note If you use this function, you must link against libopusurl. - \see op_test_url - \see op_test_callbacks - \param _url The URL to open. - Currently only the , , and - schemes are supported. - Both and may be disabled at compile - time, in which case opening such URLs will always - fail. - Currently this only supports URIs. - IRIs should be converted to UTF-8 and URL-escaped, - with internationalized domain names encoded in - punycode, before passing them to this function. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want - the failure code. - See op_open_callbacks() for a full list of failure - codes. - \param[in,out] _ap A list of the \ref url_options "optional flags" to - use. - This is a variable-length list of options terminated - with NULL. - \return A partially opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_vtest_url(const char *_url, - int *_error, va_list _ap) OP_ARG_NONNULL(1); - -/** Partially open a stream from a URL. - \note If you use this function, you must link against libopusurl. - \see op_test_callbacks - \param _url The URL to open. - Currently only the , , and - schemes are supported. - Both and may be disabled at compile - time, in which case opening such URLs will always fail. - Currently this only supports URIs. - IRIs should be converted to UTF-8 and URL-escaped, with - internationalized domain names encoded in punycode, - before passing them to this function. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want the - failure code. - See op_open_callbacks() for a full list of failure - codes. - \param ... The \ref url_options "optional flags" to use. - This is a variable-length list of options terminated - with NULL. - \return A partially opened \c OggOpusFile, or NULL on error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_test_url(const char *_url, - int *_error, ...) OP_ARG_NONNULL(1); - -/** Partially open a stream using the given set of callbacks to access it. - This tests for Opusness and loads the headers for the first link. - It does not seek (although it tests for seekability). - You can query a partially open stream for the few pieces of basic - information returned by op_serialno(), op_channel_count(), op_head(), and - op_tags() (but only for the first link). - You may also determine if it is seekable via a call to op_seekable(). - You cannot read audio from the stream, seek, get the size or duration, - get information from links other than the first one, or even get the total - number of links until you finish opening the stream with op_test_open(). - If you do not need to do any of these things, you can dispose of it with - op_free() instead. - - This function is provided mostly to simplify porting existing code that used - libvorbisfile. - For new code, you are likely better off using op_test() instead, which - is less resource-intensive, requires less data to succeed, and imposes a - hard limit on the amount of data it examines (important for unseekable - streams, where all such data must be buffered until you are sure of the - stream type). - \param _stream The stream to read from (e.g., a FILE *). - This value will be passed verbatim as the first - argument to all of the callbacks. - \param _cb The callbacks with which to access the stream. - read() must - be implemented. - seek() and - tell() may - be NULL, or may always return -1 to - indicate a stream is unseekable, but if - seek() is - implemented and succeeds on a particular stream, then - tell() must - also. - close() may - be NULL, but if it is not, it will be - called when the \c OggOpusFile is destroyed by - op_free(). - It will not be called if op_open_callbacks() fails - with an error. - \param _initial_data An initial buffer of data from the start of the - stream. - Applications can read some number of bytes from the - start of the stream to help identify this as an Opus - stream, and then provide them here to allow the - stream to be tested more thoroughly, even if it is - unseekable. - \param _initial_bytes The number of bytes in \a _initial_data. - If the stream is seekable, its current position (as - reported by - tell() - at the start of this function) must be equal to - \a _initial_bytes. - Otherwise, seeking to absolute positions will - generate inconsistent results. - \param[out] _error Returns 0 on success, or a failure code on error. - You may pass in NULL if you don't want - the failure code. - See op_open_callbacks() for a full list of failure - codes. - \return A partially opened \c OggOpusFile, or NULL on error. - libopusfile does not take ownership of the stream - if the call fails. - The calling application is responsible for closing the stream if - this call returns an error.*/ -OP_WARN_UNUSED_RESULT OggOpusFile *op_test_callbacks(void *_stream, - const OpusFileCallbacks *_cb, const unsigned char *_initial_data, - size_t _initial_bytes, int *_error) OP_ARG_NONNULL(2); - -/** Finish opening a stream partially opened with op_test_callbacks() or one of - the associated convenience functions. - If this function fails, you are still responsible for freeing the - \c OggOpusFile with op_free(). - \param _of The \c OggOpusFile to finish opening. - \return 0 on success, or a negative value on error. - \retval #OP_EREAD An underlying read, seek, or tell operation failed - when it should have succeeded. - \retval #OP_EFAULT There was a memory allocation failure, or an - internal library error. - \retval #OP_EIMPL The stream used a feature that is not implemented, - such as an unsupported channel family. - \retval #OP_EINVAL The stream was not partially opened with - op_test_callbacks() or one of the associated - convenience functions. - \retval #OP_ENOTFORMAT The stream contained a link that did not have any - logical Opus streams in it. - \retval #OP_EBADHEADER A required header packet was not properly - formatted, contained illegal values, or was - missing altogether. - \retval #OP_EVERSION An ID header contained an unrecognized version - number. - \retval #OP_EBADLINK We failed to find data we had seen before after - seeking. - \retval #OP_EBADTIMESTAMP The first or last timestamp in a link failed basic - validity checks.*/ -int op_test_open(OggOpusFile *_of) OP_ARG_NONNULL(1); - -/** Release all memory used by an \c OggOpusFile. - \param _of The \c OggOpusFile to free.*/ -void op_free(OggOpusFile *_of); - -/*@}*/ -/*@}*/ - -/**\defgroup stream_info Stream Information*/ -/*@{*/ -/** \name Functions for obtaining information about streams - - These functions allow you to get basic information about a stream, including - seekability, the number of links (for chained streams), plus the size, - duration, bitrate, header parameters, and meta information for each link - (or, where available, the stream as a whole). - Some of these (size, duration) are only available for seekable streams. - You can also query the current stream position, link, and playback time, - and instantaneous bitrate during playback. - - Some of these functions may be used successfully on the partially open - streams returned by op_test_callbacks() or one of the associated - convenience functions. - Their documentation will indicate so explicitly.*/ -/*@{*/ - -/** Returns whether or not the stream being read is seekable. - This is true if -
    -
  1. The seek() and - tell() callbacks are both - non-NULL,
  2. -
  3. The seek() callback was - successfully executed at least once, and
  4. -
  5. The tell() callback was - successfully able to report the position indicator afterwards.
  6. -
- This function may be called on partially-opened streams. - \param _of The \c OggOpusFile whose seekable status is to be returned. - \return A non-zero value if seekable, and 0 if unseekable.*/ -int op_seekable(const OggOpusFile *_of) OP_ARG_NONNULL(1); - -/** Returns the number of links in this chained stream. - This function may be called on partially-opened streams, but it will always - return 1. - The actual number of links is not known until the stream is fully opened. - \param _of The \c OggOpusFile from which to retrieve the link count. - \return For fully-open seekable streams, this returns the total number of - links in the whole stream, which will be at least 1. - For partially-open or unseekable streams, this always returns 1.*/ -int op_link_count(const OggOpusFile *_of) OP_ARG_NONNULL(1); - -/** Get the serial number of the given link in a (possibly-chained) Ogg Opus - stream. - This function may be called on partially-opened streams, but it will always - return the serial number of the Opus stream in the first link. - \param _of The \c OggOpusFile from which to retrieve the serial number. - \param _li The index of the link whose serial number should be retrieved. - Use a negative number to get the serial number of the current - link. - \return The serial number of the given link. - If \a _li is greater than the total number of links, this returns - the serial number of the last link. - If the stream is not seekable, this always returns the serial number - of the current link.*/ -opus_uint32 op_serialno(const OggOpusFile *_of, int _li) OP_ARG_NONNULL(1); - -/** Get the channel count of the given link in a (possibly-chained) Ogg Opus - stream. - This is equivalent to op_head(_of,_li)->channel_count, but - is provided for convenience. - This function may be called on partially-opened streams, but it will always - return the channel count of the Opus stream in the first link. - \param _of The \c OggOpusFile from which to retrieve the channel count. - \param _li The index of the link whose channel count should be retrieved. - Use a negative number to get the channel count of the current - link. - \return The channel count of the given link. - If \a _li is greater than the total number of links, this returns - the channel count of the last link. - If the stream is not seekable, this always returns the channel count - of the current link.*/ -int op_channel_count(const OggOpusFile *_of, int _li) OP_ARG_NONNULL(1); - -/** Get the total (compressed) size of the stream, or of an individual link in - a (possibly-chained) Ogg Opus stream, including all headers and Ogg muxing - overhead. - \warning If the Opus stream (or link) is concurrently multiplexed with other - logical streams (e.g., video), this returns the size of the entire stream - (or link), not just the number of bytes in the first logical Opus stream. - Returning the latter would require scanning the entire file. - \param _of The \c OggOpusFile from which to retrieve the compressed size. - \param _li The index of the link whose compressed size should be computed. - Use a negative number to get the compressed size of the entire - stream. - \return The compressed size of the entire stream if \a _li is negative, the - compressed size of link \a _li if it is non-negative, or a negative - value on error. - The compressed size of the entire stream may be smaller than that - of the underlying stream if trailing garbage was detected in the - file. - \retval #OP_EINVAL The stream is not seekable (so we can't know the length), - \a _li wasn't less than the total number of links in - the stream, or the stream was only partially open.*/ -opus_int64 op_raw_total(const OggOpusFile *_of, int _li) OP_ARG_NONNULL(1); - -/** Get the total PCM length (number of samples at 48 kHz) of the stream, or of - an individual link in a (possibly-chained) Ogg Opus stream. - Users looking for op_time_total() should use op_pcm_total() - instead. - Because timestamps in Opus are fixed at 48 kHz, there is no need for a - separate function to convert this to seconds (and leaving it out avoids - introducing floating point to the API, for those that wish to avoid it). - \param _of The \c OggOpusFile from which to retrieve the PCM offset. - \param _li The index of the link whose PCM length should be computed. - Use a negative number to get the PCM length of the entire stream. - \return The PCM length of the entire stream if \a _li is negative, the PCM - length of link \a _li if it is non-negative, or a negative value on - error. - \retval #OP_EINVAL The stream is not seekable (so we can't know the length), - \a _li wasn't less than the total number of links in - the stream, or the stream was only partially open.*/ -ogg_int64_t op_pcm_total(const OggOpusFile *_of, int _li) OP_ARG_NONNULL(1); - -/** Get the ID header information for the given link in a (possibly chained) Ogg - Opus stream. - This function may be called on partially-opened streams, but it will always - return the ID header information of the Opus stream in the first link. - \param _of The \c OggOpusFile from which to retrieve the ID header - information. - \param _li The index of the link whose ID header information should be - retrieved. - Use a negative number to get the ID header information of the - current link. - For an unseekable stream, \a _li is ignored, and the ID header - information for the current link is always returned, if - available. - \return The contents of the ID header for the given link.*/ -const OpusHead *op_head(const OggOpusFile *_of, int _li) OP_ARG_NONNULL(1); - -/** Get the comment header information for the given link in a (possibly - chained) Ogg Opus stream. - This function may be called on partially-opened streams, but it will always - return the tags from the Opus stream in the first link. - \param _of The \c OggOpusFile from which to retrieve the comment header - information. - \param _li The index of the link whose comment header information should be - retrieved. - Use a negative number to get the comment header information of - the current link. - For an unseekable stream, \a _li is ignored, and the comment - header information for the current link is always returned, if - available. - \return The contents of the comment header for the given link, or - NULL if this is an unseekable stream that encountered - an invalid link.*/ -const OpusTags *op_tags(const OggOpusFile *_of, int _li) OP_ARG_NONNULL(1); - -/** Retrieve the index of the current link. - This is the link that produced the data most recently read by - op_read_float() or its associated functions, or, after a seek, the link - that the seek target landed in. - Reading more data may advance the link index (even on the first read after a - seek). - \param _of The \c OggOpusFile from which to retrieve the current link index. - \return The index of the current link on success, or a negative value on - failure. - For seekable streams, this is a number between 0 (inclusive) and the - value returned by op_link_count() (exclusive). - For unseekable streams, this value starts at 0 and increments by one - each time a new link is encountered (even though op_link_count() - always returns 1). - \retval #OP_EINVAL The stream was only partially open.*/ -int op_current_link(const OggOpusFile *_of) OP_ARG_NONNULL(1); - -/** Computes the bitrate of the stream, or of an individual link in a - (possibly-chained) Ogg Opus stream. - The stream must be seekable to compute the bitrate. - For unseekable streams, use op_bitrate_instant() to get periodic estimates. - \warning If the Opus stream (or link) is concurrently multiplexed with other - logical streams (e.g., video), this uses the size of the entire stream (or - link) to compute the bitrate, not just the number of bytes in the first - logical Opus stream. - Returning the latter requires scanning the entire file, but this may be done - by decoding the whole file and calling op_bitrate_instant() once at the - end. - Install a trivial decoding callback with op_set_decode_callback() if you - wish to skip actual decoding during this process. - \param _of The \c OggOpusFile from which to retrieve the bitrate. - \param _li The index of the link whose bitrate should be computed. - Use a negative number to get the bitrate of the whole stream. - \return The bitrate on success, or a negative value on error. - \retval #OP_EINVAL The stream was only partially open, the stream was not - seekable, or \a _li was larger than the number of - links.*/ -opus_int32 op_bitrate(const OggOpusFile *_of, int _li) OP_ARG_NONNULL(1); - -/** Compute the instantaneous bitrate, measured as the ratio of bits to playable - samples decoded since a) the last call to op_bitrate_instant(), b) the last - seek, or c) the start of playback, whichever was most recent. - This will spike somewhat after a seek or at the start/end of a chain - boundary, as pre-skip, pre-roll, and end-trimming causes samples to be - decoded but not played. - \param _of The \c OggOpusFile from which to retrieve the bitrate. - \return The bitrate, in bits per second, or a negative value on error. - \retval #OP_FALSE No data has been decoded since any of the events - described above. - \retval #OP_EINVAL The stream was only partially open.*/ -opus_int32 op_bitrate_instant(OggOpusFile *_of) OP_ARG_NONNULL(1); - -/** Obtain the current value of the position indicator for \a _of. - \param _of The \c OggOpusFile from which to retrieve the position indicator. - \return The byte position that is currently being read from. - \retval #OP_EINVAL The stream was only partially open.*/ -opus_int64 op_raw_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1); - -/** Obtain the PCM offset of the next sample to be read. - If the stream is not properly timestamped, this might not increment by the - proper amount between reads, or even return monotonically increasing - values. - \param _of The \c OggOpusFile from which to retrieve the PCM offset. - \return The PCM offset of the next sample to be read. - \retval #OP_EINVAL The stream was only partially open.*/ -ogg_int64_t op_pcm_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1); - -/*@}*/ -/*@}*/ - -/**\defgroup stream_seeking Seeking*/ -/*@{*/ -/** \name Functions for seeking in Opus streams - - These functions let you seek in Opus streams, if the underlying stream - support it. - Seeking is implemented for all built-in stream I/O routines, though some - individual streams may not be seekable (pipes, live HTTP streams, or HTTP - streams from a server that does not support Range requests). - - op_raw_seek() is the fastest: it is guaranteed to perform at most one - physical seek, but, since the target is a byte position, makes no guarantee - how close to a given time it will come. - op_pcm_seek() provides sample-accurate seeking. - The number of physical seeks it requires is still quite small (often 1 or - 2, even in highly variable bitrate streams). - - Seeking in Opus requires decoding some pre-roll amount before playback to - allow the internal state to converge (as if recovering from packet loss). - This is handled internally by libopusfile, but means there is - little extra overhead for decoding up to the exact position requested - (since it must decode some amount of audio anyway). - It also means that decoding after seeking may not return exactly the same - values as would be obtained by decoding the stream straight through. - However, such differences are expected to be smaller than the loss - introduced by Opus's lossy compression.*/ -/*@{*/ - -/** Seek to a byte offset relative to the compressed data. - This also scans packets to update the PCM cursor. - It will cross a logical bitstream boundary, but only if it can't get any - packets out of the tail of the link to which it seeks. - \param _of The \c OggOpusFile in which to seek. - \param _byte_offset The byte position to seek to. - This must be between 0 and #op_raw_total(\a _of,\c -1) - (inclusive). - \return 0 on success, or a negative error code on failure. - \retval #OP_EREAD The underlying seek operation failed. - \retval #OP_EINVAL The stream was only partially open, or the target was - outside the valid range for the stream. - \retval #OP_ENOSEEK This stream is not seekable. - \retval #OP_EBADLINK Failed to initialize a decoder for a stream for an - unknown reason.*/ -int op_raw_seek(OggOpusFile *_of, opus_int64 _byte_offset) OP_ARG_NONNULL(1); - -/** Seek to the specified PCM offset, such that decoding will begin at exactly - the requested position. - \param _of The \c OggOpusFile in which to seek. - \param _pcm_offset The PCM offset to seek to. - This is in samples at 48 kHz relative to the start of the - stream. - \return 0 on success, or a negative value on error. - \retval #OP_EREAD An underlying read or seek operation failed. - \retval #OP_EINVAL The stream was only partially open, or the target was - outside the valid range for the stream. - \retval #OP_ENOSEEK This stream is not seekable. - \retval #OP_EBADLINK We failed to find data we had seen before, or the - bitstream structure was sufficiently malformed that - seeking to the target destination was impossible.*/ -int op_pcm_seek(OggOpusFile *_of, ogg_int64_t _pcm_offset) OP_ARG_NONNULL(1); - -/*@}*/ -/*@}*/ - -/**\defgroup stream_decoding Decoding*/ -/*@{*/ -/** \name Functions for decoding audio data - - These functions retrieve actual decoded audio data from the stream. - The general functions, op_read() and op_read_float() return 16-bit or - floating-point output, both using native endian ordering. - The number of channels returned can change from link to link in a chained - stream. - There are special functions, op_read_stereo() and op_read_float_stereo(), - which always output two channels, to simplify applications which do not - wish to handle multichannel audio. - These downmix multichannel files to two channels, so they can always return - samples in the same format for every link in a chained file. - - If the rest of your audio processing chain can handle floating point, the - floating-point routines should be preferred, as they prevent clipping and - other issues which might be avoided entirely if, e.g., you scale down the - volume at some other stage. - However, if you intend to consume 16-bit samples directly, the conversion in - libopusfile provides noise-shaping dithering and, if compiled - against libopus 1.1 or later, soft-clipping prevention. - - libopusfile can also be configured at compile time to use the - fixed-point libopus API. - If so, libopusfile's floating-point API may also be disabled. - In that configuration, nothing in libopusfile will use any - floating-point operations, to simplify support on devices without an - adequate FPU. - - \warning HTTPS streams may be be vulnerable to truncation attacks if you do - not check the error return code from op_read_float() or its associated - functions. - If the remote peer does not close the connection gracefully (with a TLS - "close notify" message), these functions will return #OP_EREAD instead of 0 - when they reach the end of the file. - If you are reading from an URL (particularly if seeking is not - supported), you should make sure to check for this error and warn the user - appropriately.*/ -/*@{*/ - -/** Indicates that the decoding callback should produce signed 16-bit - native-endian output samples.*/ -#define OP_DEC_FORMAT_SHORT (7008) -/** Indicates that the decoding callback should produce 32-bit native-endian - float samples.*/ -#define OP_DEC_FORMAT_FLOAT (7040) - -/** Indicates that the decoding callback did not decode anything, and that - libopusfile should decode normally instead.*/ -#define OP_DEC_USE_DEFAULT (6720) - -/** Called to decode an Opus packet. - This should invoke the functional equivalent of opus_multistream_decode() or - opus_multistream_decode_float(), except that it returns 0 on success - instead of the number of decoded samples (which is known a priori). - \param _ctx The application-provided callback context. - \param _decoder The decoder to use to decode the packet. - \param[out] _pcm The buffer to decode into. - This will always have enough room for \a _nchannels of - \a _nsamples samples, which should be placed into this - buffer interleaved. - \param _op The packet to decode. - This will always have its granule position set to a valid - value. - \param _nsamples The number of samples expected from the packet. - \param _nchannels The number of channels expected from the packet. - \param _format The desired sample output format. - This is either #OP_DEC_FORMAT_SHORT or - #OP_DEC_FORMAT_FLOAT. - \param _li The index of the link from which this packet was decoded. - \return A non-negative value on success, or a negative value on error. - Any error codes should be the same as those returned by - opus_multistream_decode() or opus_multistream_decode_float(). - Success codes are as follows: - \retval 0 Decoding was successful. - The application has filled the buffer with - exactly \a _nsamples*\a - _nchannels samples in the requested - format. - \retval #OP_DEC_USE_DEFAULT No decoding was done. - libopusfile should do the decoding - by itself instead.*/ -typedef int (*op_decode_cb_func)(void *_ctx, OpusMSDecoder *_decoder, void *_pcm, - const ogg_packet *_op, int _nsamples, int _nchannels, int _format, int _li); - -/** Sets the packet decode callback function. - If set, this is called once for each packet that needs to be decoded. - This can be used by advanced applications to do additional processing on the - compressed or uncompressed data. - For example, an application might save the final entropy coder state for - debugging and testing purposes, or it might apply additional filters - before the downmixing, dithering, or soft-clipping performed by - libopusfile, so long as these filters do not introduce any - latency. - - A call to this function is no guarantee that the audio will eventually be - delivered to the application. - libopusfile may discard some or all of the decoded audio data - (i.e., at the beginning or end of a link, or after a seek), however the - callback is still required to provide all of it. - \param _of The \c OggOpusFile on which to set the decode callback. - \param _decode_cb The callback function to call. - This may be NULL to disable calling the - callback. - \param _ctx The application-provided context pointer to pass to the - callback on each call.*/ -void op_set_decode_callback(OggOpusFile *_of, - op_decode_cb_func _decode_cb, void *_ctx) OP_ARG_NONNULL(1); - -/** Gain offset type that indicates that the provided offset is relative to the - header gain. - This is the default.*/ -#define OP_HEADER_GAIN (0) - -/** Gain offset type that indicates that the provided offset is relative to the - R128_ALBUM_GAIN value (if any), in addition to the header gain.*/ -#define OP_ALBUM_GAIN (3007) - -/** Gain offset type that indicates that the provided offset is relative to the - R128_TRACK_GAIN value (if any), in addition to the header gain.*/ -#define OP_TRACK_GAIN (3008) - -/** Gain offset type that indicates that the provided offset should be used as - the gain directly, without applying any the header or track gains.*/ -#define OP_ABSOLUTE_GAIN (3009) - -/** Sets the gain to be used for decoded output. - By default, the gain in the header is applied with no additional offset. - The total gain (including header gain and/or track gain, if applicable, and - this offset), will be clamped to [-32768,32767]/256 dB. - This is more than enough to saturate or underflow 16-bit PCM. - \note The new gain will not be applied to any already buffered, decoded - output. - This means you cannot change it sample-by-sample, as at best it will be - updated packet-by-packet. - It is meant for setting a target volume level, rather than applying smooth - fades, etc. - \param _of The \c OggOpusFile on which to set the gain offset. - \param _gain_type One of #OP_HEADER_GAIN, #OP_ALBUM_GAIN, - #OP_TRACK_GAIN, or #OP_ABSOLUTE_GAIN. - \param _gain_offset_q8 The gain offset to apply, in 1/256ths of a dB. - \return 0 on success or a negative value on error. - \retval #OP_EINVAL The \a _gain_type was unrecognized.*/ -int op_set_gain_offset(OggOpusFile *_of, - int _gain_type, opus_int32 _gain_offset_q8) OP_ARG_NONNULL(1); - -/** Sets whether or not dithering is enabled for 16-bit decoding. - By default, when libopusfile is compiled to use floating-point - internally, calling op_read() or op_read_stereo() will first decode to - float, and then convert to fixed-point using noise-shaping dithering. - This flag can be used to disable that dithering. - When the application uses op_read_float() or op_read_float_stereo(), or when - the library has been compiled to decode directly to fixed point, this flag - has no effect. - \param _of The \c OggOpusFile on which to enable or disable dithering. - \param _enabled A non-zero value to enable dithering, or 0 to disable it.*/ -void op_set_dither_enabled(OggOpusFile *_of, int _enabled) OP_ARG_NONNULL(1); - -/** Reads more samples from the stream. - \note Although \a _buf_size must indicate the total number of values that - can be stored in \a _pcm, the return value is the number of samples - per channel. - This is done because -
    -
  1. The channel count cannot be known a priori (reading more samples might - advance us into the next link, with a different channel count), so - \a _buf_size cannot also be in units of samples per channel,
  2. -
  3. Returning the samples per channel matches the libopus API - as closely as we're able,
  4. -
  5. Returning the total number of values instead of samples per channel - would mean the caller would need a division to compute the samples per - channel, and might worry about the possibility of getting back samples - for some channels and not others, and
  6. -
  7. This approach is relatively fool-proof: if an application passes too - small a value to \a _buf_size, they will simply get fewer samples back, - and if they assume the return value is the total number of values, then - they will simply read too few (rather than reading too many and going - off the end of the buffer).
  8. -
- \param _of The \c OggOpusFile from which to read. - \param[out] _pcm A buffer in which to store the output PCM samples, as - signed native-endian 16-bit values at 48 kHz - with a nominal range of [-32768,32767). - Multiple channels are interleaved using the - Vorbis - channel ordering. - This must have room for at least \a _buf_size values. - \param _buf_size The number of values that can be stored in \a _pcm. - It is recommended that this be large enough for at - least 120 ms of data at 48 kHz per channel (5760 - values per channel). - Smaller buffers will simply return less data, possibly - consuming more memory to buffer the data internally. - libopusfile may return less data than - requested. - If so, there is no guarantee that the remaining data - in \a _pcm will be unmodified. - \param[out] _li The index of the link this data was decoded from. - You may pass NULL if you do not need this - information. - If this function fails (returning a negative value), - this parameter is left unset. - \return The number of samples read per channel on success, or a negative - value on failure. - The channel count can be retrieved on success by calling - op_head(_of,*_li). - The number of samples returned may be 0 if the buffer was too small - to store even a single sample for all channels, or if end-of-file - was reached. - The list of possible failure codes follows. - Most of them can only be returned by unseekable, chained streams - that encounter a new link. - \retval #OP_HOLE There was a hole in the data, and some samples - may have been skipped. - Call this function again to continue decoding - past the hole. - \retval #OP_EREAD An underlying read operation failed. - This may signal a truncation attack from an - source. - \retval #OP_EFAULT An internal memory allocation failed. - \retval #OP_EIMPL An unseekable stream encountered a new link that - used a feature that is not implemented, such as - an unsupported channel family. - \retval #OP_EINVAL The stream was only partially open. - \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that - did not have any logical Opus streams in it. - \retval #OP_EBADHEADER An unseekable stream encountered a new link with a - required header packet that was not properly - formatted, contained illegal values, or was - missing altogether. - \retval #OP_EVERSION An unseekable stream encountered a new link with - an ID header that contained an unrecognized - version number. - \retval #OP_EBADPACKET Failed to properly decode the next packet. - \retval #OP_EBADLINK We failed to find data we had seen before. - \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with - a starting timestamp that failed basic validity - checks.*/ -OP_WARN_UNUSED_RESULT int op_read(OggOpusFile *_of, - opus_int16 *_pcm, int _buf_size, int *_li) OP_ARG_NONNULL(1); - -/** Reads more samples from the stream. - \note Although \a _buf_size must indicate the total number of values that - can be stored in \a _pcm, the return value is the number of samples - per channel. -
    -
  1. The channel count cannot be known a priori (reading more samples might - advance us into the next link, with a different channel count), so - \a _buf_size cannot also be in units of samples per channel,
  2. -
  3. Returning the samples per channel matches the libopus API - as closely as we're able,
  4. -
  5. Returning the total number of values instead of samples per channel - would mean the caller would need a division to compute the samples per - channel, and might worry about the possibility of getting back samples - for some channels and not others, and
  6. -
  7. This approach is relatively fool-proof: if an application passes too - small a value to \a _buf_size, they will simply get fewer samples back, - and if they assume the return value is the total number of values, then - they will simply read too few (rather than reading too many and going - off the end of the buffer).
  8. -
- \param _of The \c OggOpusFile from which to read. - \param[out] _pcm A buffer in which to store the output PCM samples as - signed floats at 48 kHz with a nominal range of - [-1.0,1.0]. - Multiple channels are interleaved using the - Vorbis - channel ordering. - This must have room for at least \a _buf_size floats. - \param _buf_size The number of floats that can be stored in \a _pcm. - It is recommended that this be large enough for at - least 120 ms of data at 48 kHz per channel (5760 - samples per channel). - Smaller buffers will simply return less data, possibly - consuming more memory to buffer the data internally. - If less than \a _buf_size values are returned, - libopusfile makes no guarantee that the - remaining data in \a _pcm will be unmodified. - \param[out] _li The index of the link this data was decoded from. - You may pass NULL if you do not need this - information. - If this function fails (returning a negative value), - this parameter is left unset. - \return The number of samples read per channel on success, or a negative - value on failure. - The channel count can be retrieved on success by calling - op_head(_of,*_li). - The number of samples returned may be 0 if the buffer was too small - to store even a single sample for all channels, or if end-of-file - was reached. - The list of possible failure codes follows. - Most of them can only be returned by unseekable, chained streams - that encounter a new link. - \retval #OP_HOLE There was a hole in the data, and some samples - may have been skipped. - Call this function again to continue decoding - past the hole. - \retval #OP_EREAD An underlying read operation failed. - This may signal a truncation attack from an - source. - \retval #OP_EFAULT An internal memory allocation failed. - \retval #OP_EIMPL An unseekable stream encountered a new link that - used a feature that is not implemented, such as - an unsupported channel family. - \retval #OP_EINVAL The stream was only partially open. - \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that - did not have any logical Opus streams in it. - \retval #OP_EBADHEADER An unseekable stream encountered a new link with a - required header packet that was not properly - formatted, contained illegal values, or was - missing altogether. - \retval #OP_EVERSION An unseekable stream encountered a new link with - an ID header that contained an unrecognized - version number. - \retval #OP_EBADPACKET Failed to properly decode the next packet. - \retval #OP_EBADLINK We failed to find data we had seen before. - \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with - a starting timestamp that failed basic validity - checks.*/ -OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of, - float *_pcm, int _buf_size, int *_li) OP_ARG_NONNULL(1); - -/** Reads more samples from the stream and downmixes to stereo, if necessary. - This function is intended for simple players that want a uniform output - format, even if the channel count changes between links in a chained - stream. - \note \a _buf_size indicates the total number of values that can be stored - in \a _pcm, while the return value is the number of samples per - channel, even though the channel count is known, for consistency with - op_read(). - \param _of The \c OggOpusFile from which to read. - \param[out] _pcm A buffer in which to store the output PCM samples, as - signed native-endian 16-bit values at 48 kHz - with a nominal range of [-32768,32767). - The left and right channels are interleaved in the - buffer. - This must have room for at least \a _buf_size values. - \param _buf_size The number of values that can be stored in \a _pcm. - It is recommended that this be large enough for at - least 120 ms of data at 48 kHz per channel (11520 - values total). - Smaller buffers will simply return less data, possibly - consuming more memory to buffer the data internally. - If less than \a _buf_size values are returned, - libopusfile makes no guarantee that the - remaining data in \a _pcm will be unmodified. - \return The number of samples read per channel on success, or a negative - value on failure. - The number of samples returned may be 0 if the buffer was too small - to store even a single sample for both channels, or if end-of-file - was reached. - The list of possible failure codes follows. - Most of them can only be returned by unseekable, chained streams - that encounter a new link. - \retval #OP_HOLE There was a hole in the data, and some samples - may have been skipped. - Call this function again to continue decoding - past the hole. - \retval #OP_EREAD An underlying read operation failed. - This may signal a truncation attack from an - source. - \retval #OP_EFAULT An internal memory allocation failed. - \retval #OP_EIMPL An unseekable stream encountered a new link that - used a feature that is not implemented, such as - an unsupported channel family. - \retval #OP_EINVAL The stream was only partially open. - \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that - did not have any logical Opus streams in it. - \retval #OP_EBADHEADER An unseekable stream encountered a new link with a - required header packet that was not properly - formatted, contained illegal values, or was - missing altogether. - \retval #OP_EVERSION An unseekable stream encountered a new link with - an ID header that contained an unrecognized - version number. - \retval #OP_EBADPACKET Failed to properly decode the next packet. - \retval #OP_EBADLINK We failed to find data we had seen before. - \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with - a starting timestamp that failed basic validity - checks.*/ -OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of, - opus_int16 *_pcm, int _buf_size) OP_ARG_NONNULL(1); - -/** Reads more samples from the stream and downmixes to stereo, if necessary. - This function is intended for simple players that want a uniform output - format, even if the channel count changes between links in a chained - stream. - \note \a _buf_size indicates the total number of values that can be stored - in \a _pcm, while the return value is the number of samples per - channel, even though the channel count is known, for consistency with - op_read_float(). - \param _of The \c OggOpusFile from which to read. - \param[out] _pcm A buffer in which to store the output PCM samples, as - signed floats at 48 kHz with a nominal range of - [-1.0,1.0]. - The left and right channels are interleaved in the - buffer. - This must have room for at least \a _buf_size values. - \param _buf_size The number of values that can be stored in \a _pcm. - It is recommended that this be large enough for at - least 120 ms of data at 48 kHz per channel (11520 - values total). - Smaller buffers will simply return less data, possibly - consuming more memory to buffer the data internally. - If less than \a _buf_size values are returned, - libopusfile makes no guarantee that the - remaining data in \a _pcm will be unmodified. - \return The number of samples read per channel on success, or a negative - value on failure. - The number of samples returned may be 0 if the buffer was too small - to store even a single sample for both channels, or if end-of-file - was reached. - The list of possible failure codes follows. - Most of them can only be returned by unseekable, chained streams - that encounter a new link. - \retval #OP_HOLE There was a hole in the data, and some samples - may have been skipped. - Call this function again to continue decoding - past the hole. - \retval #OP_EREAD An underlying read operation failed. - This may signal a truncation attack from an - source. - \retval #OP_EFAULT An internal memory allocation failed. - \retval #OP_EIMPL An unseekable stream encountered a new link that - used a feature that is not implemented, such as - an unsupported channel family. - \retval #OP_EINVAL The stream was only partially open. - \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that - that did not have any logical Opus streams in it. - \retval #OP_EBADHEADER An unseekable stream encountered a new link with a - required header packet that was not properly - formatted, contained illegal values, or was - missing altogether. - \retval #OP_EVERSION An unseekable stream encountered a new link with - an ID header that contained an unrecognized - version number. - \retval #OP_EBADPACKET Failed to properly decode the next packet. - \retval #OP_EBADLINK We failed to find data we had seen before. - \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with - a starting timestamp that failed basic validity - checks.*/ -OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of, - float *_pcm, int _buf_size) OP_ARG_NONNULL(1); - -/*@}*/ -/*@}*/ - -# if OP_GNUC_PREREQ(4,0) -# pragma GCC visibility pop -# endif - -# if defined(__cplusplus) -} -# endif - -#endif diff --git a/src/opusfile/opusfile.pc b/src/opusfile/opusfile.pc deleted file mode 100644 index 398f8c4..0000000 --- a/src/opusfile/opusfile.pc +++ /dev/null @@ -1,15 +0,0 @@ -# opusfile installed pkg-config file - -prefix=/usr/local -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: opusfile -Description: High-level Opus decoding library -Version: 0.12 -Requires.private: ogg >= 1.3 opus >= 1.0.1 -Conflicts: -Libs: -L${libdir} -lopusfile -Libs.private: -Cflags: -I${includedir}/opus diff --git a/src/opusfile/stream.c b/src/opusfile/stream.c deleted file mode 100644 index 7751413..0000000 --- a/src/opusfile/stream.c +++ /dev/null @@ -1,447 +0,0 @@ -/******************************************************************** - * * - THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. - USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS - GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE - IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. - * * - THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2018 - by the Xiph.Org Foundation and contributors https://xiph.org/ - * * - ******************************************************************** - - function: stdio-based convenience library for opening/seeking/decoding - last mod: $Id: vorbisfile.c 17573 2010-10-27 14:53:59Z xiphmont $ - - ********************************************************************/ -//#ifdef HAVE_CONFIG_H -#include "config.h" -//#endif - -#include "internal.h" -#include -#include -#include -#include -#include -#if defined(_WIN32) -# include -#endif - -typedef struct OpusMemStream OpusMemStream; - -#define OP_MEM_SIZE_MAX (~(size_t)0>>1) -#define OP_MEM_DIFF_MAX ((ptrdiff_t)OP_MEM_SIZE_MAX) - -/* The context information needed to read from a block of memory as if it were a - file.*/ -struct OpusMemStream { - /*The block of memory to read from.*/ - const unsigned char *data; - /* The total size of the block. - This must be at most OP_MEM_SIZE_MAX to prevent signed overflow while - seeking.*/ - ptrdiff_t size; - /* The current file position. - This is allowed to be set arbitrarily greater than size (i.e., past the end - of the block, though we will not read data past the end of the block), but - is not allowed to be negative (i.e., before the beginning of the block).*/ - ptrdiff_t pos; -}; - -static int op_fread(void *_stream, unsigned char *_ptr, int _buf_size) { - FILE *stream; - size_t ret; - /*Check for empty read.*/ - if (_buf_size <= 0) { - return 0; - } - stream = (FILE *)_stream; - ret = fread(_ptr, 1, _buf_size, stream); - OP_ASSERT(ret <= (size_t)_buf_size); - /*If ret==0 and !feof(stream), there was a read error.*/ - return ret > 0 || feof(stream) ? (int)ret : OP_EREAD; -} - -static int op_fseek(void *_stream, opus_int64 _offset, int _whence) { -#if defined(_WIN32) - /* _fseeki64() is not exposed until MSVCRT80. - This is the default starting with MSVC 2005 (_MSC_VER>=1400), but we want - to allow linking against older MSVCRT versions for compatibility back to - XP without installing extra runtime libraries. - i686-pc-mingw32 does not have fseeko() and requires - __MSVCRT_VERSION__>=0x800 for _fseeki64(), which screws up linking with - other libraries (that don't use MSVCRT80 from MSVC 2005 by default). - i686-w64-mingw32 does have fseeko() and respects _FILE_OFFSET_BITS, but I - don't know how to detect that at compile time. - We could just use fseeko64() (which is available in both), but it's - implemented using fgetpos()/fsetpos() just like this code, except without - the overflow checking, so we prefer our version.*/ - opus_int64 pos; - /* We don't use fpos_t directly because it might be a struct if __STDC__ is - non-zero or _INTEGRAL_MAX_BITS < 64. - I'm not certain when the latter is true, but someone could in theory set - the former. - Either way, it should be binary compatible with a normal 64-bit int (this - assumption is not portable, but I believe it is true for MSVCRT).*/ - OP_ASSERT(sizeof(pos) == sizeof(fpos_t)); - /*Translate the seek to an absolute one.*/ - if (_whence == SEEK_CUR) { - int ret; - ret = fgetpos((FILE *)_stream, (fpos_t *)&pos); - if (ret) { - return ret; - } - } else if (_whence == SEEK_END) { - pos = _filelengthi64(_fileno((FILE *)_stream)); - } else if (_whence == SEEK_SET) { - pos = 0; - } else { - return -1; - } - /*Check for errors or overflow.*/ - if (pos < 0 || _offset < -pos || _offset > OP_INT64_MAX - pos) { - return -1; - } - pos += _offset; - return fsetpos((FILE *)_stream, (fpos_t *)&pos); -#else - /* This function actually conforms to the SUSv2 and POSIX.1-2001, so we prefer - it except on Windows.*/ - return fseeko((FILE *)_stream, (off_t)_offset, _whence); -#endif -} - -static opus_int64 op_ftell(void *_stream) { -#if defined(_WIN32) - /* _ftelli64() is not exposed until MSVCRT80, and ftello()/ftello64() have - the same problems as fseeko()/fseeko64() in MingW. - See above for a more detailed explanation.*/ - opus_int64 pos; - OP_ASSERT(sizeof(pos) == sizeof(fpos_t)); - return fgetpos((FILE *)_stream, (fpos_t *)&pos) ? -1 : pos; -#else - /* This function actually conforms to the SUSv2 and POSIX.1-2001, so we prefer - it except on Windows.*/ - return ftello((FILE *)_stream); -#endif -} - -static const OpusFileCallbacks OP_FILE_CALLBACKS = { - op_fread, - op_fseek, - op_ftell, - (op_close_func)fclose -}; - -#if defined(_WIN32) -# include -# include - -/* Windows doesn't accept UTF-8 by default, and we don't have a wchar_t API, - so if we just pass the path to fopen(), then there'd be no way for a user - of our API to open a Unicode filename. - Instead, we translate from UTF-8 to UTF-16 and use Windows' wchar_t API. - This makes this API more consistent with platforms where the character set - used by fopen is the same as used on disk, which is generally UTF-8, and - with our metadata API, which always uses UTF-8.*/ -static wchar_t *op_utf8_to_utf16(const char *_src) { - wchar_t *dst; - size_t len; - len = strlen(_src); - /*Worst-case output is 1 wide character per 1 input character.*/ - dst = (wchar_t *)_ogg_malloc(sizeof(*dst) * (len + 1)); - if (dst != NULL) { - size_t si; - size_t di; - for (di = si = 0; si < len; si++) { - int c0; - c0 = (unsigned char)_src[si]; - if (!(c0 & 0x80)) { - /*Start byte says this is a 1-byte sequence.*/ - dst[di++] = (wchar_t)c0; - continue; - } else { - int c1; - /*This is safe, because c0 was not 0 and _src is NUL-terminated.*/ - c1 = (unsigned char)_src[si + 1]; - if ((c1 & 0xC0) == 0x80) { - /*Found at least one continuation byte.*/ - if ((c0 & 0xE0) == 0xC0) { - wchar_t w; - /*Start byte says this is a 2-byte sequence.*/ - w = (c0 & 0x1F) << 6 | c1 & 0x3F; - if (w >= 0x80U) { - /*This is a 2-byte sequence that is not overlong.*/ - dst[di++] = w; - si++; - continue; - } - } else { - int c2; - /*This is safe, because c1 was not 0 and _src is NUL-terminated.*/ - c2 = (unsigned char)_src[si + 2]; - if ((c2 & 0xC0) == 0x80) { - /*Found at least two continuation bytes.*/ - if ((c0 & 0xF0) == 0xE0) { - wchar_t w; - /*Start byte says this is a 3-byte sequence.*/ - w = (c0 & 0xF) << 12 | (c1 & 0x3F) << 6 | c2 & 0x3F; - if (w >= 0x800U && (w < 0xD800 || w >= 0xE000) && w < 0xFFFE) { - /* This is a 3-byte sequence that is not overlong, not a - UTF-16 surrogate pair value, and not a 'not a character' - value.*/ - dst[di++] = w; - si += 2; - continue; - } - } else { - int c3; - /* This is safe, because c2 was not 0 and _src is - NUL-terminated.*/ - c3 = (unsigned char)_src[si + 3]; - if ((c3 & 0xC0) == 0x80) { - /*Found at least three continuation bytes.*/ - if ((c0 & 0xF8) == 0xF0) { - opus_uint32 w; - /*Start byte says this is a 4-byte sequence.*/ - w = (c0 & 7) << 18 | (c1 & 0x3F) << 12 | (c2 & 0x3F) << 6 & (c3 & 0x3F); - if (w >= 0x10000U && w < 0x110000U) { - /* This is a 4-byte sequence that is not overlong and not - greater than the largest valid Unicode code point. - Convert it to a surrogate pair.*/ - w -= 0x10000; - dst[di++] = (wchar_t)(0xD800 + (w >> 10)); - dst[di++] = (wchar_t)(0xDC00 + (w & 0x3FF)); - si += 3; - continue; - } - } - } - } - } - } - } - } - /*If we got here, we encountered an illegal UTF-8 sequence.*/ - _ogg_free(dst); - return NULL; - } - OP_ASSERT(di <= len); - dst[di] = '\0'; - } - return dst; -} - -/* fsetpos() internally dispatches to the win32 API call SetFilePointer(). - According to SetFilePointer()'s documentation [0], the behavior is - undefined if you do not call it on "a file stored on a seeking device". - However, none of the MSVCRT seeking functions verify what kind of file is - being used before calling it (which I believe is a bug, since they are - supposed to fail and return an error, but it is a bug that has been there - for multiple decades now). - In practice, SetFilePointer() appears to succeed for things like stdin, - even when you are not just piping in a regular file, which prevents the use - of this API to determine whether it is possible to seek in a file at all. - Therefore, we take the approach recommended by the SetFilePointer() - documentation and confirm the type of file using GetFileType() first. - We do this once, when the file is opened, and return the corresponding - callback in order to avoid an extra win32 API call on every seek in the - common case. - Hopefully the return value of GetFileType() cannot actually change for the - lifetime of a file handle. - [0] https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfilepointer -*/ -static int op_fseek_fail(void *_stream, opus_int64 _offset, int _whence) { - (void)_stream; - (void)_offset; - (void)_whence; - return -1; -} - -static const OpusFileCallbacks OP_UNSEEKABLE_FILE_CALLBACKS = { - op_fread, - op_fseek_fail, - op_ftell, - (op_close_func)fclose -}; - -# define WIN32_LEAN_AND_MEAN -# define WIN32_EXTRA_LEAN -# include - -static const OpusFileCallbacks *op_get_file_callbacks(FILE *_fp) { - intptr_t h_file; - h_file = _get_osfhandle(_fileno(_fp)); - if (h_file != -1 - && (GetFileType((HANDLE)h_file) & ~FILE_TYPE_REMOTE) == FILE_TYPE_DISK) { - return &OP_FILE_CALLBACKS; - } - return &OP_UNSEEKABLE_FILE_CALLBACKS; -} -#else -static const OpusFileCallbacks *op_get_file_callbacks(FILE *_fp) { - (void)_fp; - return &OP_FILE_CALLBACKS; -} -#endif - -void *op_fopen(OpusFileCallbacks *_cb, const char *_path, const char *_mode) { - FILE *fp; -#if !defined(_WIN32) - fp = fopen(_path, _mode); -#else - fp = NULL; - { - wchar_t *wpath; - wchar_t *wmode; - wpath = op_utf8_to_utf16(_path); - wmode = op_utf8_to_utf16(_mode); - if (wmode == NULL) { - errno = EINVAL; - } else if (wpath == NULL) { - errno = ENOENT; - } else { - fp = _wfopen(wpath, wmode); - } - _ogg_free(wmode); - _ogg_free(wpath); - } -#endif - if (fp != NULL) { - *_cb = *op_get_file_callbacks(fp); - } - return fp; -} - -void *op_fdopen(OpusFileCallbacks *_cb, int _fd, const char *_mode) { - FILE *fp; - fp = fdopen(_fd, _mode); - if (fp != NULL) { - *_cb = *op_get_file_callbacks(fp); - } - return fp; -} - -void *op_freopen(OpusFileCallbacks *_cb, const char *_path, const char *_mode, - void *_stream) { - FILE *fp; -#if !defined(_WIN32) - fp = freopen(_path, _mode, (FILE *)_stream); -#else - fp = NULL; - { - wchar_t *wpath; - wchar_t *wmode; - wpath = op_utf8_to_utf16(_path); - wmode = op_utf8_to_utf16(_mode); - if (wmode == NULL) { - errno = EINVAL; - } else if (wpath == NULL) { - errno = ENOENT; - } else { - fp = _wfreopen(wpath, wmode, (FILE *)_stream); - } - _ogg_free(wmode); - _ogg_free(wpath); - } -#endif - if (fp != NULL) { - *_cb = *op_get_file_callbacks(fp); - } - return fp; -} - -static int op_mem_read(void *_stream, unsigned char *_ptr, int _buf_size) { - OpusMemStream *stream; - ptrdiff_t size; - ptrdiff_t pos; - stream = (OpusMemStream *)_stream; - /*Check for empty read.*/ - if (_buf_size <= 0) { - return 0; - } - size = stream->size; - pos = stream->pos; - /*Check for EOF.*/ - if (pos >= size) { - return 0; - } - /*Check for a short read.*/ - _buf_size = (int)OP_MIN(size - pos, _buf_size); - memcpy(_ptr, stream->data + pos, _buf_size); - pos += _buf_size; - stream->pos = pos; - return _buf_size; -} - -static int op_mem_seek(void *_stream, opus_int64 _offset, int _whence) { - OpusMemStream *stream; - ptrdiff_t pos; - stream = (OpusMemStream *)_stream; - pos = stream->pos; - OP_ASSERT(pos >= 0); - switch (_whence) { - case SEEK_SET: { - /*Check for overflow:*/ - if (_offset < 0 || _offset > OP_MEM_DIFF_MAX) { - return -1; - } - pos = (ptrdiff_t)_offset; - } break; - case SEEK_CUR: { - /*Check for overflow:*/ - if (_offset < -pos || _offset > OP_MEM_DIFF_MAX - pos) { - return -1; - } - pos = (ptrdiff_t)(pos + _offset); - } break; - case SEEK_END: { - ptrdiff_t size; - size = stream->size; - OP_ASSERT(size >= 0); - /*Check for overflow:*/ - if (_offset < -size || _offset > OP_MEM_DIFF_MAX - size) { - return -1; - } - pos = (ptrdiff_t)(size + _offset); - } break; - default: return -1; - } - stream->pos = pos; - return 0; -} - -static opus_int64 op_mem_tell(void *_stream) { - OpusMemStream *stream; - stream = (OpusMemStream *)_stream; - return (ogg_int64_t)stream->pos; -} - -static int op_mem_close(void *_stream) { - _ogg_free(_stream); - return 0; -} - -static const OpusFileCallbacks OP_MEM_CALLBACKS = { - op_mem_read, - op_mem_seek, - op_mem_tell, - op_mem_close -}; - -void *op_mem_stream_create(OpusFileCallbacks *_cb, - const unsigned char *_data, size_t _size) { - OpusMemStream *stream; - if (_size > OP_MEM_SIZE_MAX) { - return NULL; - } - stream = (OpusMemStream *)_ogg_malloc(sizeof(*stream)); - if (stream != NULL) { - *_cb = *&OP_MEM_CALLBACKS; - stream->data = _data; - stream->size = _size; - stream->pos = 0; - } - return stream; -} diff --git a/tests/host/Makefile b/tests/host/Makefile index 7994ff2..c25430c 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -26,53 +26,6 @@ libflac=../../src/libflac/md5.c ../../src/libflac/window.c ../../src/libflac/mem ../../src/libflac/format.c ../../src/libflac/lpc.c ../../src/libflac/crc.c ../../src/libflac/bitreader.c ../../src/libflac/bitmath.c \ ../../src/libflac/stream_decoder.c ../../src/libflac/float.c -libogg=../../src/libogg/framing.c ../../src/libogg/bitwise.c - -libopus=../../src/libopus/opus_decoder.c ../../src/libopus/opus_projection_decoder.c ../../src/libopus/opus.c ../../src/libopus/opus_multistream.c \ -../../src/libopus/opus_multistream_encoder.c ../../src/libopus/repacketizer.c ../../src/libopus/opus_multistream_decoder.c \ -../../src/libopus/mapping_matrix.c ../../src/libopus/opus_projection_encoder.c ../../src/libopus/silk/NLSF_VQ_weights_laroia.c \ -../../src/libopus/silk/decode_core.c ../../src/libopus/silk/resampler_down2_3.c ../../src/libopus/silk/resampler_private_down_FIR.c \ -../../src/libopus/silk/tables_other.c ../../src/libopus/silk/resampler_private_up2_HQ.c ../../src/libopus/silk/init_encoder.c \ -../../src/libopus/silk/tables_NLSF_CB_WB.c ../../src/libopus/silk/control_codec.c ../../src/libopus/silk/decode_frame.c \ -../../src/libopus/silk/table_LSF_cos.c ../../src/libopus/silk/resampler_private_AR2.c ../../src/libopus/silk/NLSF_del_dec_quant.c \ -../../src/libopus/silk/VQ_WMat_EC.c ../../src/libopus/silk/encode_indices.c ../../src/libopus/silk/sort.c ../../src/libopus/silk/NSQ.c \ -../../src/libopus/silk/NLSF_unpack.c ../../src/libopus/silk/bwexpander_32.c ../../src/libopus/silk/tables_NLSF_CB_NB_MB.c \ -../../src/libopus/silk/ana_filt_bank_1.c ../../src/libopus/silk/resampler_down2.c ../../src/libopus/silk/stereo_encode_pred.c \ -../../src/libopus/silk/bwexpander.c ../../src/libopus/silk/PLC.c ../../src/libopus/silk/pitch_est_tables.c ../../src/libopus/silk/NLSF2A.c \ -../../src/libopus/silk/stereo_quant_pred.c ../../src/libopus/silk/debug.c ../../src/libopus/silk/LPC_analysis_filter.c \ -../../src/libopus/silk/control_audio_bandwidth.c ../../src/libopus/silk/decode_indices.c ../../src/libopus/silk/sigm_Q15.c \ -../../src/libopus/silk/resampler_private_IIR_FIR.c ../../src/libopus/silk/log2lin.c ../../src/libopus/silk/A2NLSF.c \ -../../src/libopus/silk/quant_LTP_gains.c ../../src/libopus/silk/NLSF_stabilize.c ../../src/libopus/silk/fixed/find_pred_coefs_FIX.c \ -../../src/libopus/silk/fixed/autocorr_FIX.c ../../src/libopus/silk/fixed/burg_modified_FIX.c ../../src/libopus/silk/fixed/vector_ops_FIX.c \ -../../src/libopus/silk/fixed/find_LTP_FIX.c ../../src/libopus/silk/fixed/find_pitch_lags_FIX.c ../../src/libopus/silk/fixed/schur64_FIX.c \ -../../src/libopus/silk/fixed/noise_shape_analysis_FIX.c ../../src/libopus/silk/fixed/find_LPC_FIX.c \ -../../src/libopus/silk/fixed/residual_energy16_FIX.c ../../src/libopus/silk/fixed/apply_sine_window_FIX.c \ -../../src/libopus/silk/fixed/regularize_correlations_FIX.c ../../src/libopus/silk/fixed/k2a_Q16_FIX.c \ -../../src/libopus/silk/fixed/encode_frame_FIX.c ../../src/libopus/silk/fixed/k2a_FIX.c ../../src/libopus/silk/fixed/pitch_analysis_core_FIX.c \ -../../src/libopus/silk/fixed/process_gains_FIX.c ../../src/libopus/silk/fixed/LTP_scale_ctrl_FIX.c \ -../../src/libopus/silk/fixed/warped_autocorrelation_FIX.c ../../src/libopus/silk/fixed/schur_FIX.c \ -../../src/libopus/silk/fixed/LTP_analysis_filter_FIX.c ../../src/libopus/silk/fixed/corrMatrix_FIX.c \ -../../src/libopus/silk/fixed/residual_energy_FIX.c ../../src/libopus/silk/LPC_fit.c ../../src/libopus/silk/tables_gain.c \ -../../src/libopus/silk/decode_parameters.c ../../src/libopus/silk/tables_pitch_lag.c ../../src/libopus/silk/stereo_MS_to_LR.c \ -../../src/libopus/silk/dec_API.c ../../src/libopus/silk/code_signs.c ../../src/libopus/silk/shell_coder.c \ -../../src/libopus/silk/stereo_find_predictor.c ../../src/libopus/silk/init_decoder.c ../../src/libopus/silk/decode_pulses.c \ -../../src/libopus/silk/gain_quant.c ../../src/libopus/silk/check_control_input.c ../../src/libopus/silk/tables_LTP.c \ -../../src/libopus/silk/resampler_rom.c ../../src/libopus/silk/NSQ_del_dec.c ../../src/libopus/silk/decode_pitch.c ../../src/libopus/silk/VAD.c \ -../../src/libopus/silk/NLSF_decode.c ../../src/libopus/silk/sum_sqr_shift.c ../../src/libopus/silk/stereo_LR_to_MS.c \ -../../src/libopus/silk/encode_pulses.c ../../src/libopus/silk/control_SNR.c ../../src/libopus/silk/tables_pulses_per_block.c \ -../../src/libopus/silk/LP_variable_cutoff.c ../../src/libopus/silk/enc_API.c ../../src/libopus/silk/interpolate.c \ -../../src/libopus/silk/LPC_inv_pred_gain.c ../../src/libopus/silk/NLSF_VQ.c ../../src/libopus/silk/lin2log.c \ -../../src/libopus/silk/resampler.c ../../src/libopus/silk/NLSF_encode.c ../../src/libopus/silk/CNG.c ../../src/libopus/silk/stereo_decode_pred.c \ -../../src/libopus/silk/process_NLSFs.c ../../src/libopus/silk/HP_variable_cutoff.c ../../src/libopus/silk/biquad_alt.c \ -../../src/libopus/silk/inner_prod_aligned.c ../../src/libopus/silk/decoder_set_fs.c ../../src/libopus/celt/celt.c \ -../../src/libopus/celt/mdct.c ../../src/libopus/celt/cwrs.c ../../src/libopus/celt/rate.c ../../src/libopus/celt/vq.c \ -../../src/libopus/celt/quant_bands.c ../../src/libopus/celt/celt_decoder.c ../../src/libopus/celt/celt_lpc.c \ -../../src/libopus/celt/celt_encoder.c ../../src/libopus/celt/entenc.c ../../src/libopus/celt/bands.c ../../src/libopus/celt/kiss_fft.c \ -../../src/libopus/celt/pitch.c ../../src/libopus/celt/entdec.c ../../src/libopus/celt/laplace.c ../../src/libopus/celt/entcode.c \ -../../src/libopus/celt/modes.c ../../src/libopus/celt/mathops.c ../../src/libopus/opus_encoder.c - -opusfile=../../src/opusfile/opusfile.c ../../src/opusfile/stream.c ../../src/opusfile/internal.c ../../src/opusfile/info.c - libflac=../../src/libflac/md5.c ../../src/libflac/window.c ../../src/libflac/memory.c ../../src/libflac/cpu.c \ ../../src/libflac/fixed.c ../../src/libflac/format.c ../../src/libflac/lpc.c ../../src/libflac/crc.c \ ../../src/libflac/bitreader.c ../../src/libflac/bitmath.c ../../src/libflac/stream_decoder.c ../../src/libflac/float.c @@ -126,9 +79,7 @@ midi: FORCE opus: FORCE rm -f *.o - gcc $(CCOPTS) -DUSE_DEFAULT_STDLIB -c $(libogg) -I ../../src/ -I. - gcc $(CCOPTS) -DUSE_DEFAULT_STDLIB -c $(libopus) -I ../../src/ -I. - gcc $(CCOPTS) -DUSE_DEFAULT_STDLIB -c $(opusfile) -I ../../src/ -I. + find ../../src/libopus -name *.c -exec gcc $(CCOPTS) -DUSE_DEFAULT_STDLIB -c \{\} -I ../../src/ -I. \; g++ $(CPPOPTS) -o opus opus.cpp Serial.cpp *.o ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioGeneratorOpus.cpp ../../src/AudioLogger.cpp -I ../../src/ -I. rm -f *.o echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./opus diff --git a/tests/host/opus.cpp b/tests/host/opus.cpp index 45e8d71..861e833 100644 --- a/tests/host/opus.cpp +++ b/tests/host/opus.cpp @@ -3,7 +3,7 @@ #include "AudioOutputSTDIO.h" #include "AudioGeneratorOpus.h" -#define OPUS "../../examples/PlayOpusFromSPIFFS/data/gs-16b-2c-44100hz.opus" +#define OPUS "../../examples/PlayOpusFromLittleFS/data/gs-16b-2c-44100hz.opus" int main(int argc, char **argv) { diff --git a/tests/restyle.sh b/tests/restyle.sh index 6a3641e..6c331b4 100755 --- a/tests/restyle.sh +++ b/tests/restyle.sh @@ -1,4 +1,4 @@ #!/bin/bash -find ./src -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" \) -a \! -path '*api*' -a \! -path '*libespeak-ng*' -exec astyle --suffix=none --options=./tests/astyle_core.conf \{\} \; +find ./src -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" \) -a \! -path '*api*' -a \! -path '*libespeak-ng*' -a \! -path '*libopus*' -exec astyle --suffix=none --options=./tests/astyle_core.conf \{\} \; find ./examples -type f -name "*.ino" -exec astyle --suffix=none --options=./tests/astyle_examples.conf \{\} \;