From 833d665b6c580b1671348cb1d56c30e53133c777 Mon Sep 17 00:00:00 2001 From: Auto Commit Date: Thu, 31 Aug 2023 16:46:27 -0400 Subject: [PATCH] pushing all modifications done to EVS 26.452 to make it closer to the new EVS structure from IVAS --- Workspace_msvc/common.vcxproj | 6 + Workspace_msvc/evs_dec.vcxproj | 4 +- Workspace_msvc/evs_enc.vcxproj | 4 +- lib_com/ACcontextMapping.c | 6 +- lib_com/ari.c | 4 +- lib_com/ari_hm.c | 12 +- lib_com/arith_coder.c | 62 +- lib_com/bitalloc_fx.c | 33 +- lib_com/bitallocsum_fx.c | 13 +- lib_com/bits_alloc.c | 1268 +++- lib_com/bitstream_fx.c | 151 +- lib_com/cb_shape_fx.c | 32 +- lib_com/cldfb.c | 61 +- lib_com/cng_exc_fx.c | 245 +- lib_com/cnst_fx.h | 180 +- lib_com/codec_tcx_common.c | 200 +- lib_com/core_com_config_fx.c | 698 +- lib_com/deemph_fx.c | 3 +- lib_com/delay_comp.c | 79 +- lib_com/dlpc_bfi.c | 32 +- lib_com/edct_fx.c | 15 +- lib_com/enhancer_fx.c | 4 +- lib_com/enr_1_az_fx.c | 3 +- lib_com/env_adj_fx.c | 4 +- lib_com/env_stab_fx.c | 89 +- lib_com/env_stab_trans_fx.c | 21 +- lib_com/est_tilt_fx.c | 21 +- lib_com/fd_cng_com.c | 754 +- lib_com/fill_spectrum_fx.c | 98 +- lib_com/findpulse_fx.c | 2 +- lib_com/fine_gain_bits_fx.c | 15 +- lib_com/frame_ener_fx.c | 7 +- lib_com/gain_inov.c | 7 +- lib_com/get_gain.c | 19 +- lib_com/gs_bitallocation_fx.c | 1033 ++- lib_com/gs_gains_fx.c | 30 +- lib_com/gs_inact_switching_fx.c | 6 +- lib_com/gs_noisefill_fx.c | 238 +- lib_com/gs_preech_fx.c | 44 +- lib_com/guided_plc_util.c | 124 +- lib_com/hp50.c | 25 +- lib_com/hq2_bit_alloc_fx.c | 10 +- lib_com/hq2_core_com_fx.c | 73 +- lib_com/hq2_noise_inject_fx.c | 2 +- lib_com/hq_conf_fx.c | 183 +- lib_com/hq_tools_fx.c | 241 +- lib_com/hvq_pvq_bitalloc_fx.c | 26 +- lib_com/igf_base.c | 674 +- lib_com/index_pvq_opt_fx.c | 8 +- lib_com/interleave_spectrum_fx.c | 31 +- lib_com/interpol_fx.c | 3 +- lib_com/isf_dec_amr_wb_fx.c | 12 +- lib_com/ivas_avq_pos_reorder_com.c | 68 + lib_com/ivas_cnst.h | 1603 ++++ lib_com/ivas_error.h | 167 + lib_com/ivas_error_utils.h | 96 + lib_com/ivas_rom_com.c | 10568 +++++++++++++++++++++++++++ lib_com/ivas_rom_com.h | 420 ++ lib_com/ivas_stat_com.h | 793 ++ lib_com/lag_wind.c | 11 +- lib_com/lerp.c | 22 +- lib_com/limit_t0_fx.c | 11 +- lib_com/logqnorm_fx.c | 29 +- lib_com/longarith.c | 19 +- lib_com/low_rate_band_att_fx.c | 43 +- lib_com/lpc_tools_fx.c | 8 +- lib_com/lsf_dec_bfi_fx.c | 44 +- lib_com/lsf_msvq_ma.c | 34 +- lib_com/lsf_tools_fx.c | 501 +- lib_com/lsp_conv_poly_fx.c | 56 +- lib_com/modif_fs_fx.c | 170 +- lib_com/mslvq_com_fx.c | 16 +- lib_com/nelp_fx.c | 17 +- lib_com/options.h | 93 +- lib_com/parameter_bitmaping.c | 69 +- lib_com/phase_dispersion.c | 4 +- lib_com/ppp_fx.c | 13 +- lib_com/pred_lt4_fx.c | 16 +- lib_com/preemph_fx.c | 7 +- lib_com/prot_fx.h | 6169 ++++++++-------- lib_com/pvq_com_fx.c | 192 +- lib_com/range_com_fx.c | 15 +- lib_com/re8_ppv_fx.c | 8 +- lib_com/re8_util_fx.c | 4 +- lib_com/recovernorm_fx.c | 7 +- lib_com/reordvct_fx.c | 4 +- lib_com/residu_fx.c | 62 +- lib_com/rom_com_fx.c | 1254 +++- lib_com/rom_com_fx.h | 38 +- lib_com/scale_mem_fx.c | 8 +- lib_com/stab_est_fx.c | 5 +- lib_com/stat_com.h | 37 +- lib_com/stat_noise_uv_mod_fx.c | 22 +- lib_com/swb_bwe_com_fx.c | 164 +- lib_com/swb_bwe_com_hr_fx.c | 26 +- lib_com/swb_bwe_com_lr_fx.c | 225 +- lib_com/swb_tbe_com_fx.c | 1116 ++- lib_com/syn_12k8_fx.c | 11 +- lib_com/syn_filt_fx.c | 39 +- lib_com/tcq_position_arith_fx.c | 236 +- lib_com/tcx_ltp.c | 389 +- lib_com/tcx_mdct.c | 61 +- lib_com/tcx_mdct_window.c | 63 +- lib_com/tcx_utils.c | 709 +- lib_com/tec_com.c | 462 +- lib_com/tns_base.c | 472 +- lib_com/tools_fx.c | 86 +- lib_com/trans_direct_fx.c | 27 +- lib_com/trans_inv_fx.c | 33 +- lib_com/vlpc_2st_com.c | 8 +- lib_com/weight_a_fx.c | 21 +- lib_com/weight_fx.c | 16 +- lib_com/wi_fx.c | 1321 +--- lib_com/window.c | 12 +- lib_com/window_ola_fx.c | 161 +- lib_com/wtda_fx.c | 199 +- lib_dec/ACcontextMapping_dec.c | 389 +- lib_dec/EvsRXlib.c | 4 +- lib_dec/FEC_HQ_core_fx.c | 361 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 921 ++- lib_dec/FEC_adapt_codebook_fx.c | 3 +- lib_dec/FEC_clas_estim_fx.c | 105 +- lib_dec/FEC_fx.c | 47 +- lib_dec/FEC_lsf_estim_fx.c | 4 +- lib_dec/FEC_pitch_estim_fx.c | 8 +- lib_dec/FEC_scale_syn_fx.c | 55 +- lib_dec/LD_music_post_filter_fx.c | 138 +- lib_dec/TonalComponentDetection.c | 336 +- lib_dec/acelp_core_dec_fx.c | 1258 +++- lib_dec/acelp_core_switch_dec_fx.c | 164 +- lib_dec/amr_wb_dec_fx.c | 354 +- lib_dec/ari_dec.c | 51 +- lib_dec/ari_hm_dec.c | 36 +- lib_dec/arith_coder_dec.c | 64 +- lib_dec/avq_dec_fx.c | 64 +- lib_dec/bass_psfilter_fx.c | 300 +- lib_dec/cng_dec_fx.c | 410 +- lib_dec/core_dec_init.c | 595 +- lib_dec/core_dec_reconf.c | 108 +- lib_dec/core_dec_switch.c | 153 +- lib_dec/core_switching_dec_fx.c | 733 +- lib_dec/d_gain2p.c | 11 +- lib_dec/dec2t32_fx.c | 27 +- lib_dec/dec4t64_fx.c | 244 +- lib_dec/dec_LPD.c | 267 +- lib_dec/dec_ace.c | 206 +- lib_dec/dec_acelp.c | 6 +- lib_dec/dec_acelp_tcx_main.c | 157 +- lib_dec/dec_amr_wb_fx.c | 39 +- lib_dec/dec_gen_voic_fx.c | 83 +- lib_dec/dec_higher_acelp_fx.c | 112 +- lib_dec/dec_nelp_fx.c | 26 +- lib_dec/dec_pit_exc_fx.c | 205 +- lib_dec/dec_post.c | 126 +- lib_dec/dec_ppp_fx.c | 32 +- lib_dec/dec_prm.c | 178 +- lib_dec/dec_tcx.c | 524 +- lib_dec/dec_tran_fx.c | 63 +- lib_dec/dec_uv.c | 26 +- lib_dec/decision_matrix_dec_fx.c | 55 +- lib_dec/decoder.c | 13 +- lib_dec/dlpc_avq.c | 226 +- lib_dec/dlpc_stoch.c | 82 +- lib_dec/er_dec_acelp.c | 85 +- lib_dec/er_dec_tcx.c | 274 +- lib_dec/er_scale_syn.c | 19 +- lib_dec/er_sync_exc.c | 13 +- lib_dec/er_util.c | 82 +- lib_dec/evs_dec_fx.c | 412 +- lib_dec/fd_cng_dec.c | 1862 +++-- lib_dec/gain_dec_fx.c | 145 +- lib_dec/gaus_dec_fx.c | 24 +- lib_dec/gs_dec_amr_wb_fx.c | 117 +- lib_dec/gs_dec_fx.c | 419 +- lib_dec/hdecnrm_fx.c | 9 +- lib_dec/hf_synth_fx.c | 309 +- lib_dec/hq_classifier_dec_fx.c | 71 +- lib_dec/hq_conf_fec_fx.c | 15 +- lib_dec/hq_core_dec_fx.c | 423 +- lib_dec/hq_env_dec_fx.c | 17 +- lib_dec/hq_hr_dec_fx.c | 104 +- lib_dec/hq_lr_dec_fx.c | 44 +- lib_dec/igf_dec.c | 89 +- lib_dec/igf_scf_dec.c | 58 +- lib_dec/init_dec_fx.c | 847 +-- lib_dec/inov_dec_fx.c | 95 +- lib_dec/io_dec_fx.c | 10 +- lib_dec/jbm_pcmdsp_window.c | 1 - lib_dec/lead_deindexing_fx.c | 48 +- lib_dec/lp_exc_d_fx.c | 48 +- lib_dec/lsf_dec_fx.c | 450 +- lib_dec/lsf_msvq_ma_dec.c | 65 +- lib_dec/nelp_dec_fx.c | 48 +- lib_dec/peak_vq_dec_fx.c | 69 +- lib_dec/pit_dec.c | 87 +- lib_dec/pitch_extr.c | 12 +- lib_dec/post_dec.c | 56 +- lib_dec/ppp_dec_fx.c | 221 +- lib_dec/pvq_core_dec_fx.c | 134 +- lib_dec/pvq_decode_fx.c | 46 +- lib_dec/range_dec_fx.c | 115 +- lib_dec/re8_dec_fx.c | 2 +- lib_dec/rom_dec_fx.c | 8 +- lib_dec/rom_dec_fx.h | 4 +- lib_dec/rst_dec_fx.c | 2 +- lib_dec/stat_dec_fx.h | 1357 ++-- lib_dec/stat_noise_uv_dec_fx.c | 16 +- lib_dec/swb_bwe_dec_fx.c | 265 +- lib_dec/swb_bwe_dec_hr_fx.c | 128 +- lib_dec/swb_bwe_dec_lr_fx.c | 63 +- lib_dec/swb_tbe_dec_fx.c | 693 +- lib_dec/syn_outp_fx.c | 14 +- lib_dec/tcq_core_dec_fx.c | 15 +- lib_dec/tcx_utils_dec.c | 82 +- lib_dec/tns_base_dec.c | 89 +- lib_dec/tonalMDCTconcealment.c | 1173 ++- lib_dec/transition_dec_fx.c | 110 +- lib_dec/updt_dec_fx.c | 537 +- lib_dec/vlpc_1st_dec.c | 5 +- lib_dec/vlpc_2st_dec.c | 15 +- lib_dec/voiced_dec_fx.c | 149 +- lib_dec/voip_client.c | 6 +- lib_dec/waveadjust_fec_dec.c | 12 +- lib_enc/ACcontextMapping_enc.c | 902 ++- lib_enc/FEC_enc_fx.c | 30 +- lib_enc/SNR_calc.c | 160 +- lib_enc/acelp_core_enc_fx.c | 626 +- lib_enc/acelp_core_switch_enc_fx.c | 144 +- lib_enc/acelp_enc_util.c | 14 +- lib_enc/amr_wb_enc_fx.c | 238 +- lib_enc/analy_lp_fx.c | 42 +- lib_enc/analy_sp.c | 315 +- lib_enc/ari_enc.c | 71 +- lib_enc/ari_hm_enc.c | 163 +- lib_enc/arith_coder_enc.c | 278 +- lib_enc/avq_cod_fx.c | 329 +- lib_enc/bass_psfilter_enc.c | 30 +- lib_enc/bw_detect_fx.c | 315 +- lib_enc/cng_enc_fx.c | 674 +- lib_enc/cod2t32_fx.c | 44 +- lib_enc/cod4t64_fx.c | 145 +- lib_enc/cod_ace.c | 332 +- lib_enc/cod_tcx.c | 1140 ++- lib_enc/cod_uv.c | 8 +- lib_enc/comvad_decision.c | 229 +- lib_enc/cor_shif_fx.c | 5 +- lib_enc/core_enc_2div.c | 100 +- lib_enc/core_enc_init.c | 259 +- lib_enc/core_enc_ol.c | 442 +- lib_enc/core_enc_reconf.c | 239 +- lib_enc/core_enc_switch.c | 128 +- lib_enc/core_enc_updt.c | 185 +- lib_enc/core_switching_enc_fx.c | 443 +- lib_enc/corr_xh_fx.c | 13 +- lib_enc/decision_matrix_enc_fx.c | 234 +- lib_enc/detect_transient_fx.c | 16 +- lib_enc/diffcod_fx.c | 23 +- lib_enc/dtx_fx.c | 634 +- lib_enc/enc_acelp.c | 99 +- lib_enc/enc_acelp_tcx_main.c | 82 +- lib_enc/enc_acelpx.c | 78 +- lib_enc/enc_amr_wb_fx.c | 79 +- lib_enc/enc_gain.c | 7 +- lib_enc/enc_gen_voic_fx.c | 150 +- lib_enc/enc_gen_voic_rf_fx.c | 325 +- lib_enc/enc_higher_acelp_fx.c | 144 +- lib_enc/enc_nelp_fx.c | 43 +- lib_enc/enc_pit_exc_fx.c | 273 +- lib_enc/enc_ppp_fx.c | 100 +- lib_enc/enc_prm.c | 256 +- lib_enc/enc_tran_fx.c | 145 +- lib_enc/enc_uv_fx.c | 192 +- lib_enc/encoder.c | 18 +- lib_enc/energy.c | 212 +- lib_enc/eval_pit_contr_fx.c | 98 +- lib_enc/evs_enc_fx.c | 391 +- lib_enc/ext_sig_ana.c | 607 +- lib_enc/fd_cng_enc.c | 308 +- lib_enc/find_tar_fx.c | 30 +- lib_enc/find_tilt_fx.c | 7 +- lib_enc/find_uv.c | 132 +- lib_enc/find_wsp_fx.c | 29 +- lib_enc/frame_spec_dif_cor_rate.c | 29 +- lib_enc/gain_enc_fx.c | 356 +- lib_enc/gaus_enc_fx.c | 99 +- lib_enc/gp_clip_fx.c | 52 +- lib_enc/gs_enc_fx.c | 416 +- lib_enc/gs_enc_fx.test.c | 0 lib_enc/guided_plc_enc.c | 102 +- lib_enc/hf_cod_amrwb_fx.c | 42 +- lib_enc/hq_classifier_enc_fx.c | 275 +- lib_enc/hq_core_enc_fx.c | 293 +- lib_enc/hq_env_enc_fx.c | 57 +- lib_enc/hq_hr_enc_fx.c | 74 +- lib_enc/hq_lr_enc_fx.c | 243 +- lib_enc/hvq_enc_fx.c | 34 +- lib_enc/igf_enc.c | 267 +- lib_enc/igf_scf_enc.c | 102 +- lib_enc/init_enc_fx.c | 1036 ++- lib_enc/inov_enc_fx.c | 224 +- lib_enc/isf_enc_amr_wb_fx.c | 91 +- lib_enc/ivas_rom_enc.h | 133 + lib_enc/ivas_stat_enc.h | 1141 +++ lib_enc/lead_indexing_fx.c | 7 +- lib_enc/long_enr.c | 123 +- lib_enc/lp_exc_e_fx.c | 102 +- lib_enc/lsf_enc_fx.c | 580 +- lib_enc/lsf_msvq_ma_enc.c | 200 +- lib_enc/ltd_stable.c | 29 +- lib_enc/mdct_classifier_fx.c | 153 +- lib_enc/mdct_selector.c | 88 +- lib_enc/mslvq_enc_fx.c | 16 +- lib_enc/multi_harm_fx.c | 21 +- lib_enc/nelp_enc_fx.c | 138 +- lib_enc/nois_est_fx.c | 683 +- lib_enc/noise_adjust_fx.c | 4 +- lib_enc/normalizecoefs_fx.c | 15 +- lib_enc/peak_vq_enc_fx.c | 131 +- lib_enc/pit_enc_fx.c | 167 +- lib_enc/pitch_ol.c | 98 +- lib_enc/pitch_ol2_fx.c | 23 +- lib_enc/plc_enc_ext.c | 64 +- lib_enc/ppp_enc_fx.c | 758 +- lib_enc/pre_proc_fx.c | 504 +- lib_enc/pvq_core_enc_fx.c | 189 +- lib_enc/pvq_encode_fx.c | 52 +- lib_enc/q_gain2p.c | 74 +- lib_enc/qlpc_avq.c | 283 +- lib_enc/qlpc_stoch.c | 105 +- lib_enc/range_enc_fx.c | 147 +- lib_enc/re8_cod_fx.c | 3 +- lib_enc/reordernorm_fx.c | 13 +- lib_enc/rst_enc_fx.c | 31 +- lib_enc/set_impulse_fx.c | 16 +- lib_enc/setmodeindex.c | 42 +- lib_enc/sig_clas.c | 299 +- lib_enc/spec_center.c | 26 +- lib_enc/spec_flatness.c | 18 +- lib_enc/speech_music_classif_fx.c | 2232 ++++-- lib_enc/stat_enc_fx.h | 1641 +++-- lib_enc/stat_noise_uv_enc_fx.c | 32 +- lib_enc/subband_fft.c | 111 +- lib_enc/swb_bwe_enc_fx.c | 167 +- lib_enc/swb_bwe_enc_hr_fx.c | 60 +- lib_enc/swb_bwe_enc_lr_fx.c | 258 +- lib_enc/swb_pre_proc_fx.c | 71 +- lib_enc/swb_tbe_enc_fx.c | 564 +- lib_enc/tcq_core_enc_fx.c | 16 +- lib_enc/tcx_utils_enc.c | 86 +- lib_enc/tfa_enc.c | 39 +- lib_enc/tns_base_enc.c | 6 +- lib_enc/transient_detection.c | 199 +- lib_enc/transition_enc_fx.c | 438 +- lib_enc/update_decision.c | 154 +- lib_enc/updt_enc_fx.c | 389 +- lib_enc/updt_tar_fx.c | 9 +- lib_enc/vad_basop.c | 6 +- lib_enc/vad_basop.h | 9 +- lib_enc/vad_fx.c | 521 +- lib_enc/vad_param_updt_fx.c | 254 +- lib_enc/vad_proc.c | 392 +- lib_enc/vbr_average_rate_fx.c | 122 +- lib_enc/vlpc_1st_cod.c | 32 +- lib_enc/vlpc_2st_cod.c | 22 +- lib_enc/voiced_enc_fx.c | 769 +- lib_enc/waveadjust_fec_cod.c | 12 +- 366 files changed, 61101 insertions(+), 27085 deletions(-) create mode 100644 lib_com/ivas_avq_pos_reorder_com.c create mode 100644 lib_com/ivas_cnst.h create mode 100644 lib_com/ivas_error.h create mode 100644 lib_com/ivas_error_utils.h create mode 100644 lib_com/ivas_rom_com.c create mode 100644 lib_com/ivas_rom_com.h create mode 100644 lib_com/ivas_stat_com.h create mode 100644 lib_enc/gs_enc_fx.test.c create mode 100644 lib_enc/ivas_rom_enc.h create mode 100644 lib_enc/ivas_stat_enc.h diff --git a/Workspace_msvc/common.vcxproj b/Workspace_msvc/common.vcxproj index 946a2e0..277f0d4 100644 --- a/Workspace_msvc/common.vcxproj +++ b/Workspace_msvc/common.vcxproj @@ -169,6 +169,8 @@ + + @@ -231,6 +233,10 @@ + + + + diff --git a/Workspace_msvc/evs_dec.vcxproj b/Workspace_msvc/evs_dec.vcxproj index 410ecd8..43baef8 100644 --- a/Workspace_msvc/evs_dec.vcxproj +++ b/Workspace_msvc/evs_dec.vcxproj @@ -48,7 +48,7 @@ .\Debug_Dec\ false false - EVS_dec + IVAS_dec ..\ @@ -88,7 +88,7 @@ - ..\EVS_dec.exe + ..\IVAS_dec.exe true true diff --git a/Workspace_msvc/evs_enc.vcxproj b/Workspace_msvc/evs_enc.vcxproj index 7da2473..656b52d 100644 --- a/Workspace_msvc/evs_enc.vcxproj +++ b/Workspace_msvc/evs_enc.vcxproj @@ -55,7 +55,7 @@ .\Debug_Enc\ false false - EVS_cod + IVAS_cod @@ -140,7 +140,7 @@ - ..\EVS_cod.exe + ..\IVAS_cod.exe true false diff --git a/lib_com/ACcontextMapping.c b/lib_com/ACcontextMapping.c index 154618f..9195b02 100644 --- a/lib_com/ACcontextMapping.c +++ b/lib_com/ACcontextMapping.c @@ -2,16 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include -#include +#include #include "options.h" #include "basop_util.h" #include "cnst_fx.h" #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( diff --git a/lib_com/ari.c b/lib_com/ari.c index edf6e47..4d0eb66 100644 --- a/lib_com/ari.c +++ b/lib_com/ari.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "assert.h" +#include "options.h" #include "prot_fx.h" #include "basop_mpy.h" #include "cnst_fx.h" -#include "stl.h" /** * \brief 31x16 Bit multiply (x*y) diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c index 80f2d70..b2b464b 100644 --- a/lib_com/ari_hm.c +++ b/lib_com/ari_hm.c @@ -3,11 +3,9 @@ ====================================================================================*/ -#include -#include -#include +#include #include -#include "stl.h" +#include "options.h" #include "cnst_fx.h" #include "basop_util.h" #include "rom_com_fx.h" @@ -19,7 +17,8 @@ void UnmapIndex( Word16 LtpPitchLag, Word8 SmallerLags, Word16 *FractionalResolution, - Word32 *Lag) + Word32 *Lag +) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; @@ -166,7 +165,8 @@ void ConfigureContextHm( Word16 CountIndexBits( Word16 Bandwidth, - Word16 PeriodicityIndex) + Word16 PeriodicityIndex +) { Word16 result; Word16 PeriodicityIndexS; diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c index 6c4739d..97a945b 100644 --- a/lib_com/arith_coder.c +++ b/lib_com/arith_coder.c @@ -2,21 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include #include - +#include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "options.h" #include "cnst_fx.h" -#include "stl.h" /* Fixed point implementation of exp(negate()) */ Word32 expfp( /* o: Q31 */ - Word16 x, /* i: mantissa Q-e */ - Word16 x_e) /* i: exponent Q0 */ + const Word16 x, /* i: mantissa Q-e */ + const Word16 x_e) /* i: exponent Q0 */ { Word16 xi, xf, tmp; Word16 b0, b1, b2, b3; @@ -55,10 +51,22 @@ Word32 expfp( /* o: Q31 */ b2 = s_and(xi, 4); b3 = s_and(xi, 8); - if (b0 != 0) y = Mpy_32_16_1(y, 24109); /* exp(-1) in -1Q16 */ - if (b1 != 0) y = Mpy_32_16_1(y, 17739); /* exp(-2) in -2Q17 */ - if (b2 != 0) y = Mpy_32_16_1(y, 19205); /* exp(-4) in -5Q20 */ - if (b3 != 0) y = Mpy_32_16_1(y, 22513); /* exp(-8) in -11Q26 */ + if (b0 != 0) + { + y = Mpy_32_16_1(y, 24109); /* exp(-1) in -1Q16 */ + } + if (b1 != 0) + { + y = Mpy_32_16_1(y, 17739); /* exp(-2) in -2Q17 */ + } + if (b2 != 0) + { + y = Mpy_32_16_1(y, 19205); /* exp(-4) in -5Q20 */ + } + if (b3 != 0) + { + y = Mpy_32_16_1(y, 22513); /* exp(-8) in -11Q26 */ + } /* scaling: -1*b0 - 2*b1 -5*b2 -11*b3 */ y = L_shr(y, add(add(xi, shr(xi, 2)), shr(b3, 3))); @@ -79,10 +87,12 @@ Word32 expfp( /* o: Q31 */ * *pout2 = ( (base/65536)^(2*exp + 1) ) * 65536 * * NOTE: This function must be in sync with ari_decode_14bits_pow() */ -void powfp_odd2(Word16 base, /* Q15 */ - Word16 exp, /* Q0 */ - Word16 *pout1, /* Q15 */ - Word16 *pout2) /* Q15 */ +void powfp_odd2( + const Word16 base, /* Q15 */ + const Word16 exp, /* Q0 */ + Word16 *pout1, /* Q15 */ + Word16 *pout2 /* Q15 */ +) { /* this version is in sync with ari_enc_14bits_pow() * that is, we have to start multiplication from the largest power-of-two, in order to @@ -168,11 +178,11 @@ void powfp_odd2(Word16 base, /* Q15 */ * and decoder remain synchronized. *-------------------------------------------------------------------------*/ void tcx_arith_scale_envelope( - Word16 L_spec_core, /* i: number of lines to scale Q0 */ + const Word16 L_spec_core, /* i: number of lines to scale Q0 */ Word16 L_frame, /* i: number of lines Q0 */ - Word32 env[], /* i: unscaled envelope Q16 */ + const Word32 env[], /* i: unscaled envelope Q16 */ Word16 target_bits, /* i: number of available bits Q0 */ - Word16 low_complexity, /* i: low-complexity flag Q0 */ + const Word16 low_complexity,/* i: low-complexity flag Q0 */ Word16 s_env[], /* o: scaled envelope Q15-e */ Word16 *s_env_e /* o: scaled envelope exponent Q0 */ ) @@ -417,11 +427,11 @@ void tcx_arith_scale_envelope( *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope( const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - Word16 L_frame, /* i: number of spectral lines */ - Word16 L_spec, - Word16 preemph_fac, /* i: pre-emphasis factor */ - Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ + const Word16 L_frame, /* i: number of spectral lines */ + const Word16 L_spec, + const Word16 preemph_fac, /* i: pre-emphasis factor */ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ Word32 env[] /* o: shaped signal envelope */ ) { @@ -434,12 +444,12 @@ void tcx_arith_render_envelope( /* Compute perceptual LPC envelope, transform it into freq.-domain gains */ weight_a_fx( A_ind, tmpA, gamma_w, M ); - lpc2mdct( tmpA, M, NULL, NULL, gainlpc, gainlpc_e ); + lpc2mdct( tmpA, M, NULL, NULL, gainlpc, gainlpc_e, FDNS_NPTS, 0); /* Add pre-emphasis tilt to LPC envelope, transform LPC into MDCT gains */ E_LPC_a_weight_inv(A_ind, signal_env, gamma_uw, M); E_LPC_a_add_tilt(signal_env, tmpA, preemph_fac, M); - lpc2mdct(tmpA, M+1, signal_env, signal_env_e, NULL, NULL); + lpc2mdct(tmpA, M+1, signal_env, signal_env_e, NULL, NULL, FDNS_NPTS, 0); /* Compute weighted signal envelope in perceptual domain */ FOR (k = 0; k < FDNS_NPTS; k++) diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index e875265..42c6dd3 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ void bitalloc_fx ( Word16 *y, /* i : reordered norm of sub-vectors Q0 */ @@ -16,8 +15,8 @@ void bitalloc_fx ( Word16 N, /* i : number of norms Q0 */ Word16 K, /* i : maximum number of bits per dimension Q0 */ Word16 *r, /* o : bit-allacation vector Q0 */ - const Word16 *sfmsize, /* i : band length Q0 */ - const Word16 hqswb_clas /* i : signal classification flag Q0 */ + const Word16 *sfmsize, /* i : band length Q0 */ + const Word16 hqswb_clas /* i : signal classification flag Q0 */ ) { Word16 i, j, k, n, m, v, im; @@ -101,7 +100,7 @@ void bitalloc_fx ( } test(); - IF ( (LT_16(sum, WID_G1))||(EQ_16(diff,sum))) + IF ( (LT_16(sum, sfmsize[SFM_G1 - 1]))||(EQ_16(diff,sum))) /* sfmsize[SFM_G1-1] matches WID_G1, but also allows for extended BWs used in ACELP->HQ switching. */ { BREAK; } @@ -127,7 +126,7 @@ void bitalloc_fx ( } - IF ( GE_16(sum, WID_G2)) + IF ( GE_16(sum, sfmsize[SFM_G1])) /* sfmsize[SFM_G1] matches WID_G2, but also allows for extended BWs used in ACELP->HQ switching. */ { FOR (i=0; i<=N; i++) { @@ -139,8 +138,8 @@ void bitalloc_fx ( { r[j] = 1; move16(); - sum = sub(sum, WID_G2); - IF (LT_16(sum, WID_G2)) + sum = sub(sum, sfmsize[j]); + IF (LT_16(sum, sfmsize[SFM_G1])) { BREAK; } @@ -148,7 +147,7 @@ void bitalloc_fx ( } } - IF ( GE_16(sum, WID_G2)) + IF ( GE_16(sum, sfmsize[SFM_G1])) { FOR (i=0; i<=N; i++) { @@ -160,8 +159,8 @@ void bitalloc_fx ( { r[j] = 2; move16(); - sum = sub(sum, WID_G2); - IF ( LT_16(sum, WID_G2)) + sum = sub(sum, sfmsize[j]); + IF ( LT_16(sum, sfmsize[SFM_G1])) { BREAK; } @@ -169,7 +168,7 @@ void bitalloc_fx ( } } - IF ( GE_16(sum, WID_G1)) + IF ( GE_16(sum, sfmsize[SFM_G1-1])) { FOR (i=0; i<=N; i++) { @@ -180,8 +179,8 @@ void bitalloc_fx ( { r[j] = 1; move16(); - sum = sub(sum, WID_G1); - IF ( LT_16(sum, WID_G1)) + sum = sub(sum, sfmsize[j]); + IF ( LT_16(sum, sfmsize[SFM_G1-1])) { BREAK; } @@ -189,7 +188,7 @@ void bitalloc_fx ( } } - IF ( GE_16(sum, WID_G1)) + IF ( GE_16(sum, sfmsize[SFM_G1-1])) { FOR (i=0; i<=N; i++) { @@ -200,8 +199,8 @@ void bitalloc_fx ( { r[j] = 2; move16(); - sum = sub(sum, WID_G1); - IF ( LT_16(sum, WID_G1)) + sum = sub(sum, sfmsize[j]); + IF ( LT_16(sum, sfmsize[SFM_G1-1])) { BREAK; } diff --git a/lib_com/bitallocsum_fx.c b/lib_com/bitallocsum_fx.c index cb8cf09..9860058 100644 --- a/lib_com/bitallocsum_fx.c +++ b/lib_com/bitallocsum_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* Common constants */ /*-------------------------------------------------------------------------- * bitallocsum_fx() @@ -14,12 +13,12 @@ *--------------------------------------------------------------------------*/ void bitallocsum_fx( Word16 *R, /* i : bit-allocation vector Q0 */ - const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ + const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ Word16 *sum, /* o : total number of bits allocated Q0 */ Word16 *Rsubband, /* o : rate per subband Q3 */ - const Word16 v, /* i : bit rate Q0 */ - const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ - const Word16 *sfmsize /* i : band length Q0 */ + const Word16 num_bits,/* i : number of bits Q0 */ + const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ + const Word16 *sfmsize /* i : band length Q0 */ ) { Word16 i; @@ -39,7 +38,7 @@ void bitallocsum_fx( IF ( LE_16(length, L_FRAME32k)) { - diff = sub(v, *sum); + diff = sub(num_bits, *sum); i = (Word16)0; move16(); WHILE ( diff > 0 ) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 69b71c6..02eb0f9 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -1,16 +1,31 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include #include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "stl.h" -#include "options.h" #include "rom_com_fx.h" +#include "ivas_cnst.h" +#include "ivas_rom_com.h" + + /*-------------------------------------------------------------------* + * Local function prototypes + *--------------------------------------------------------------------*/ +static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk(const Word16 bits_frame, Word16* fixed_cdk_index, const Word16 nb_subfr ); +static Word16 BITS_ALLOC_adjust_generic(const Word16 bits_frame, Word16* fixed_cdk_index, const Word16 nb_subfr, const Word16* pulseconfigbits, const Word16 pulseconfig_size); +static Word16 allocate_unused(const Word32 core_brate, const Word16 coder_type, const Word16 unused_bits, const Word16 nb_prm, const Word16 subfr, const Word16 prm_type, Word16* prm_bit_mode); + +typedef enum +{ + GAINSPRM = 0x0, + PITCHPRM = 0x1, + MID_LSFSPRM = 0x3, + LSFPRM = 0x4 +} PRM_TYPES; /* * function BITS_ALLOC_init_config_acelp() @@ -97,16 +112,16 @@ void BITS_ALLOC_init_config_acelp( /* * function BITS_ALLOC_config_acelp() * - * description: configure all acelp modes and allocate the bits + * description: configure all Mode 2 ACELP coder types and allocate the bits * * return: bit demand */ Word16 BITS_ALLOC_config_acelp( - const Word16 bits_frame, /*i: remaining bit budget for the frame*/ - const Word16 coder_type, /*i: acelp coder type*/ - ACELP_config *pConfigAcelp, /*i/o: configuration structure of ACELP*/ - const Word16 narrowBand, - const Word16 nb_subfr + const Word16 bits_frame, /* i: remaining bit budget for the frame*/ + const Word16 coder_type, /* i: acelp coder type*/ + ACELP_config *pConfigAcelp, /* i/o: configuration structure of ACELP*/ + const Word16 narrowBand, /* i : narrowband flag */ + const Word16 nb_subfr /* i : number of subframes */ ) { Word16 mode_index; @@ -288,8 +303,7 @@ Word16 BITS_ALLOC_config_acelp( } -static -Word16 BITS_ALLOC_adjust_generic( +static Word16 BITS_ALLOC_adjust_generic( const Word16 bits_frame, /*i: bit budget*/ Word16 *fixed_cdk_index, const Word16 nb_subfr, @@ -367,7 +381,7 @@ Word16 BITS_ALLOC_adjust_generic( return mult_r(bitsused, inb_subfr); } -Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( +static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( const Word16 bits_frame, /*i: bit budget*/ Word16 *fixed_cdk_index, const Word16 nb_subfr @@ -382,3 +396,1233 @@ Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( return bitsused; } +/*#ifdef IVAS_CODE Below basop operators are missing */ +/*-------------------------------------------------------------------* + * fcb_table() + * + * Selection of fixed innovation codebook bitbudget table + *--------------------------------------------------------------------*/ + +static Word16 fcb_table( + const Word16 n, + const Word16 L_subfr) +{ + Word16 out; + PMT("Not floating point computation, but fixed point operator are still missing ") + + out = PulseConfTable[n].bits; + if (L_subfr > L_SUBFR) + { + out = fast_FCB_bits_2sfr[n]; + } + + return (out); +} + +/*-------------------------------------------------------------------* + * acelp_FCB_allocator() + * + * Routine to allocate fixed innovation codebook bit-budget + *--------------------------------------------------------------------*/ + +static ivas_error acelp_FCB_allocator( + Word16* nBits, /* i/o: available bit-budget */ + Word16 fixed_cdk_index[], /* o : codebook index */ + Word16 nb_subfr, /* i : number of subframes */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 coder_type, /* i : coder type */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 fix_first /* i : flag to indicate whether the first subframe bit-budget was fixed */ +) +{ + Word16 cdbk, sfr, step; + Word16 nBits_tmp; + Word16* p_fixed_cdk_index; + Word16 max_n; + ivas_error error; + PMT("Not floating point computation, but fixed point operator are still missing ") + + error = IVAS_ERR_OK; + + cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */ + + p_fixed_cdk_index = fixed_cdk_index; + + /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ + if (tc_subfr >= L_SUBFR && fix_first) + { + Word16 i; + + for (i = 0; i < nb_subfr; i++) + { + *nBits -= ACELP_FIXED_CDK_BITS(fixed_cdk_index[i]); + } + return error; + } + + /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */ + sfr = 0; + if (fix_first) + { + *nBits -= ACELP_FIXED_CDK_BITS(fixed_cdk_index[0]); + sfr = 1; + p_fixed_cdk_index++; + nb_subfr = 3; + } + + /* distribute the bit-budget equally between subframes */ + if (L_subfr > L_SUBFR) /* access fast_FCB_bits_2sfr */ + { + max_n = 6; + } + else + { + max_n = ACELP_FIXED_CDK_NB; + } + for (cdbk = 0; cdbk < max_n; cdbk++) + { + if (fcb_table(cdbk, L_subfr) * nb_subfr > *nBits) + { + break; + } + } + cdbk--; + +#if defined DEBUGGING + if (cdbk < 0 && coder_type != TRANSITION) + { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too low bit-budget for fixed innovation codebook (frame = %d). Exiting! \n", frame); + } + if ((L_subfr == L_SUBFR && cdbk >= ACELP_FIXED_CDK_NB) || (L_subfr == 2 * L_SUBFR && fcb_table(cdbk, L_subfr) == 128 /*stop value*/)) + { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too high bit-budget for fixed innovation codebook (frame = %d). Exiting! \n", frame); + } +#endif + + set16_fx(p_fixed_cdk_index, cdbk, nb_subfr); + nBits_tmp = 0; + if (cdbk >= 0) + { + nBits_tmp = fcb_table(cdbk, L_subfr); + } + else + { + nBits_tmp = 0; + } + *nBits -= nBits_tmp * nb_subfr; + + /* try to increase the FCB bit-budget of the first subframe(s) */ + if (cdbk < ACELP_FIXED_CDK_NB - 1) + { + step = fcb_table(cdbk + 1, L_subfr) - nBits_tmp; + while (*nBits >= step) + { + (*p_fixed_cdk_index)++; + *nBits -= step; + p_fixed_cdk_index++; + } + + /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ + step = fcb_table(fixed_cdk_index[sfr] + 1, L_subfr) - fcb_table(fixed_cdk_index[sfr], L_subfr); + if (*nBits >= step && cdbk >= 0) + { + fixed_cdk_index[sfr]++; + *nBits -= step; + + if (*nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1) + { + sfr++; + fixed_cdk_index[sfr]++; + *nBits -= step; + } + } + } + /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ + if (tc_subfr >= L_SUBFR) + { + Word16 tempr; + + SWAP(fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR]); + + /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ + if (tc_subfr / L_SUBFR < nb_subfr - 1) + { + SWAP(fixed_cdk_index[(tc_subfr - L_SUBFR) / L_SUBFR], fixed_cdk_index[nb_subfr - 1]); + } + } + + /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */ + if (L_subfr > L_SUBFR) + { + Word16 i, j; + for (i = 0; i < nb_subfr; i++) + { + j = fixed_cdk_index[i]; + fixed_cdk_index[i] = fast_FCB_bits_2sfr[j]; + } + } + + return error; +} + + +/*-------------------------------------------------------------------* + * config_acelp1() + * + * Configure ACELP bit allocation + * - should be in range of <6700; 24350> for ACELP@12.8kHz + * - per channel bitrate minimum is 13250 kbps for ACELP@16kHz + *--------------------------------------------------------------------*/ + +ivas_error config_acelp1( + const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word32 total_brate, /* i : total bitrate */ + const Word32 core_brate_inp, /* i : core bitrate */ + const Word16 core, /* i : core */ + const Word16 extl, /* i : extension layer */ + const Word32 extl_brate, /* i : extension layer bitrate */ + const Word16 L_frame, /* i : frame length at internal Fs */ + const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ + ACELP_config* acelp_cfg, /* i : ACELP bit-allocation */ + const Word16 signalling_bits, /* i : number of signalling bits */ + const Word16 coder_type, /* i : coder type */ + const Word16 tc_subfr, /* i : TC subfr ID */ + const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ + Word16* nBits_es_Pred, /* o : number of bits for Es_pred Q */ + Word16* unbits, /* o : number of unused bits */ + const Word16 element_mode, /* i : element mode */ + Word16* uc_two_stage_flag, /* o : flag undicating two-stage UC */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 idchan, /* i : stereo channel ID */ + const Word16 active_cnt, /* i : Active frame counter */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ +) +{ + Word16 i, bits, nb_subfr; + Word16 flag_hardcoded, coder_type_sw, fix_first; + Word32 core_brate; +#ifdef DEBUGGING + Word32 core_brate_inpI = core_brate_inp; +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(active_cnt) +#endif +#endif + ivas_error error; + + error = IVAS_ERR_OK; + PMT("Not floating point computation, but fixed point operator are still missing ") + /*-----------------------------------------------------------------* + * Set the flag indicating two-stage Unvoiced (UC) frame + *-----------------------------------------------------------------*/ + + *uc_two_stage_flag = 0; + if (coder_type == UNVOICED) + { + if (total_brate >= MIN_UNVOICED_TWO_STAGE_BRATE && element_mode > EVS_MONO && (idchan == 0 || ((total_brate >= 8500 || extl_brate == 0) && tdm_LRTD_flag == 1))) + { + *uc_two_stage_flag = 1; + } + } + + /*-----------------------------------------------------------------* + * Set the number of subframes + *-----------------------------------------------------------------*/ + + if (L_frame == L_FRAME) + { + nb_subfr = NB_SUBFR; + +#if defined DEBUGGING + if (((core_brate_inp < 5900 && coder_type > UNVOICED) && !(core_brate_inp < MIN_TC_BRATE && coder_type == TRANSITION)) && !(idchan > 0 && element_mode == IVAS_CPE_TD) && !(element_mode == IVAS_SCE && tdm_low_rate_mode)) + { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inpI, frame); + } + + if (core_brate_inp > ACELP_12k8_HIGH_LIMIT && core == ACELP_CORE) + { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too high bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inpI, frame); + } +#endif + } + else /* L_frame == L_FRAME16k */ + { + nb_subfr = NB_SUBFR16k; + +#if defined DEBUGGING + if (core_brate_inp < ACELP_16k_LOW_LIMIT && core == ACELP_CORE) + { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@16k in frame %d. Exiting!\n", core_brate_inpI, frame); + } +#endif + } + + coder_type_sw = coder_type; + if (core != ACELP_CORE) + { + /* used in acelp_core_switch_enc() */ + nb_subfr = 1; + if (L_frame == L_FRAME) + { + coder_type_sw = TRANSITION; + } + } + + /*-----------------------------------------------------------------* + * Check if the core_brate is hard coded (to keep BE for mono core) or not + *-----------------------------------------------------------------*/ + + flag_hardcoded = 0; + i = 0; + + while (i < SIZE_BRATE_INTERMED_TBL) + { + if (core_brate_inp == brate_intermed_tbl[i]) + { + flag_hardcoded = 1; + break; + } + + if (core_brate_inp < brate_intermed_tbl[i]) + { + flag_hardcoded = 0; + break; + } + + i++; + } + + if (element_mode == IVAS_CPE_TD && coder_type == AUDIO && + core_brate_inp <= STEREO_GSC_BIT_RATE_ALLOC && brate_intermed_tbl[i] == ACELP_9k60) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + { + i--; + } + + core_brate = brate_intermed_tbl[i]; + + if (element_mode > EVS_MONO) + { + flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */ + } + + if (core != ACELP_CORE && element_mode == EVS_MONO) /* needed for mode1 core switching in EVS mono */ + { + flag_hardcoded = 1; + } + + /*-----------------------------------------------------------------* + * ACELP bit allocation + *-----------------------------------------------------------------*/ + + if (!(coder_type == TRANSITION && tc_subfr != -1) || enc_dec == DEC) + { + /* Set the bit-budget */ + bits = (Word16)(core_brate_inp / FRAMES_PER_SEC); + + if (coder_type == TRANSITION && enc_dec == DEC && tc_call == 1) + { + bits += *nBits_es_Pred; /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ + } + + /* Subtract signalling bits */ + if (enc_dec == DEC && idchan == 1 && element_mode > EVS_MONO) + { + bits -= TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS; + + if (tdm_LRTD_flag == 1) + { + bits += STEREO_BITS_TCA; + } + + /* subtract TBE/BWE flag */ + if (extl_brate > 0 && (extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE)) + { + bits--; + } + } + else + { + /* Subtract signalling bits */ + bits -= signalling_bits; + } + + if (extl_brate > 0 && (extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE)) + { + /* extension layer signalling bit is counted in the extension layer bitbudget */ + bits++; + } + + /*-----------------------------------------------------------------* + * LSF Q bit-budget + *-----------------------------------------------------------------*/ + + if (!tdm_lp_reuse_flag || idchan == 0) + { + /* LSF Q bit-budget */ + acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + + if (!flag_hardcoded) + { + if (L_frame == L_FRAME) + { + if (element_mode == IVAS_SCE && tdm_low_rate_mode) + { + acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + } + else if ((total_brate < 7200 || coder_type == INACTIVE || coder_type == AUDIO) && idchan == 1) + { + /* TD stereo, secondary channel: do nothing */ + acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + } + else if (element_mode > EVS_MONO && coder_type == AUDIO && brate_intermed_tbl[i] < ACELP_9k60) + { + /* primary channel: do nothing */ + } + else if (element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] >= ACELP_9k60*/) + { + acelp_cfg->lsf_bits = 42; + } + else if (total_brate <= 9600 || coder_type == UNVOICED) + { + acelp_cfg->lsf_bits = 31; + } + else if (total_brate <= 20000) + { + acelp_cfg->lsf_bits = 36; + } + else + { + acelp_cfg->lsf_bits = 41; + } + } + else /* L_frame == L_FRAME16k */ + { + acelp_cfg->lsf_bits = 41; + } + } + + bits -= acelp_cfg->lsf_bits; + + /* mid-LSF Q bit-budget */ + acelp_cfg->mid_lsf_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + + if (element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] < ACELP_9k60*/) + { + acelp_cfg->mid_lsf_bits = 5; + /* primary channel: do nothing */ + } + + bits -= acelp_cfg->mid_lsf_bits; + } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + else if (tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) + { + bits -= TDM_IC_LSF_PRED_BITS; + } +#endif + /* gain Q bit-budget - part 1 */ + if ((coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !(core_brate <= ACELP_8k00 && coder_type != TRANSITION)) || (coder_type == INACTIVE && total_brate > MAX_GSC_INACTIVE_BRATE)) + { + *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, -1, -1)]; + bits -= *nBits_es_Pred; + } + else if (*uc_two_stage_flag) + { + *nBits_es_Pred = 4; + bits -= *nBits_es_Pred; + } + } + else + { + bits = *unbits; + } + + if (coder_type == TRANSITION && tc_call == 0) + { + *unbits = bits; + return error; + } + + /*-----------------------------------------------------------------* + * Low-rate mode - bits are allocated in tdm_low_rate_enc() + *-----------------------------------------------------------------*/ + + if (element_mode == IVAS_SCE && tdm_low_rate_mode) + { + acelp_cfg->FEC_mode = 0; + acelp_cfg->ltf_mode = FULL_BAND; + *nBits_es_Pred = 0; + *unbits = 0; + acelp_cfg->ubits = 0; + + return error; + } + + /*-----------------------------------------------------------------* + * Supplementary information for FEC + *-----------------------------------------------------------------*/ + + acelp_cfg->FEC_mode = 0; + if (core_brate >= ACELP_11k60 && (idchan == 0 || element_mode == EVS_MONO)) + { + acelp_cfg->FEC_mode = 1; + + if (coder_type > UNVOICED && coder_type < AUDIO && coder_type != VOICED) + { + bits -= FEC_BITS_CLS; + } + + if (coder_type != TRANSITION) + { + if (total_brate >= ACELP_16k40) + { + acelp_cfg->FEC_mode = 2; + + if (coder_type > UNVOICED && coder_type < AUDIO) + { + bits -= FEC_BITS_ENR; + } + } + + if (total_brate >= ACELP_32k) + { + acelp_cfg->FEC_mode = 3; + + if (coder_type > UNVOICED && coder_type < AUDIO) + { + bits -= FEC_BITS_POS; + } + } + } + } + + /*-----------------------------------------------------------------* + * LP filtering of the adaptive excitation + *-----------------------------------------------------------------*/ + + if (idchan > 0 && element_mode > EVS_MONO) + { + acelp_cfg->ltf_mode = FULL_BAND; + } + else if (coder_type == UNVOICED) + { + acelp_cfg->ltf_mode = FULL_BAND; + } + else if ((coder_type == GENERIC || coder_type == TRANSITION) && core_brate < ACELP_11k60) + { + acelp_cfg->ltf_mode = LOW_PASS; + } + else if (core_brate >= ACELP_11k60 && (coder_type != AUDIO && !(coder_type == INACTIVE && L_frame == L_FRAME))) + { + if (coder_type == INACTIVE && L_frame == L_FRAME16k && total_brate <= MAX_GSC_INACTIVE_BRATE) /* GSC Inactive @16kHz */ + { + acelp_cfg->ltf_mode = FULL_BAND; + } + else + { + acelp_cfg->ltf_mode = NORMAL_OPERATION; + if (coder_type != TRANSITION) + { + bits -= nb_subfr; + } + } + } + else + { + acelp_cfg->ltf_mode = FULL_BAND; + } + + /*-----------------------------------------------------------------* + * UC bit-budget + *-----------------------------------------------------------------*/ + + if (((coder_type == UNVOICED && !(*uc_two_stage_flag)) || (coder_type == INACTIVE && core_brate <= ACELP_9k60)) && (idchan == 0 || element_mode == EVS_MONO)) + { + bits -= NBITS_NOISENESS; /* noiseness */ + } + if (coder_type == UNVOICED && !(*uc_two_stage_flag)) + { + bits -= (3 * NB_SUBFR); /* tilt factor */ + } + + /*-----------------------------------------------------------------* + * TC bit-budget + *-----------------------------------------------------------------*/ + + fix_first = 0; + if (coder_type == TRANSITION) + { + if (tc_call == 2) + { + fix_first = 1; + } + + /* TC signalling */ + if (L_frame == L_FRAME) + { + if (tc_subfr == TC_0_0) + { + if (enc_dec == ENC) + { + bits -= 1; /* TC signalling */ + } + + if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + { + bits -= 3; /* LP filtering flag */ + } + } + else if (tc_subfr == TC_0_64) + { + if (enc_dec == ENC) + { + bits -= 4; /* TC signalling */ + } + + if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + { + bits -= 3; /* LP filtering flag */ + } + } + else if (tc_subfr == TC_0_128) + { + if (enc_dec == ENC) + { + bits -= 4; /* TC signalling */ + } + + if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + { + bits -= 2; /* LP filtering flag */ + } + } + else if (tc_subfr == TC_0_192) + { + if (enc_dec == ENC) + { + bits -= 3; /* TC signalling */ + } + + if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + { + bits -= 1; /* LP filtering flag */ + } + } + else if (tc_subfr == L_SUBFR) + { + if (enc_dec == ENC) + { + bits -= 3; /* TC signalling */ + } + + if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + { + bits -= (L_FRAME - tc_subfr - L_SUBFR) / L_SUBFR; /* LP filtering flag */ + } + } + else + { + if (enc_dec == ENC) + { + bits -= 4; /* TC signalling */ + } + + if (acelp_cfg->ltf_mode == NORMAL_OPERATION) + { + bits -= (L_FRAME - tc_subfr - L_SUBFR) / L_SUBFR; /* LP filtering flag */ + } + } + } + else /* L_frame == L_FRAME16k */ + { + if (enc_dec == ENC) + { + if (tc_subfr <= 2 * L_SUBFR) + { + bits -= 2; /* TC signalling */ + } + else + { + bits -= 3; /* TC signalling */ + } + } + + bits -= (L_FRAME16k - tc_subfr - L_SUBFR) / L_SUBFR; /* LP filtering flag */ + } + + /* glottal-shape codebook bits */ + bits -= (3 + 6 + 1 + 3); + } + + /*-----------------------------------------------------------------* + * pitch, innovation, gains bit-budget + *-----------------------------------------------------------------*/ + + acelp_cfg->fcb_mode = 0; + + if (element_mode == IVAS_CPE_TD && tdm_low_rate_mode == 1 && coder_type != INACTIVE && coder_type != UNVOICED) /* GENERIC low rate mode for secondary channel */ + { + set16_fx(acelp_cfg->pitch_bits, 0, NB_SUBFR16k); + set16_fx(acelp_cfg->gains_mode, 0, NB_SUBFR16k); + + for (i = 0; i < 2; i++) + { + acelp_cfg->pitch_bits[i] = 0; + if (tdm_Pitch_reuse_flag == 0) + { + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx(ACELP_7k20, GENERIC, 2 * i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + bits -= acelp_cfg->pitch_bits[i]; + } + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx(ACELP_7k20, GENERIC, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + bits -= acelp_cfg->gains_mode[i]; + } + acelp_cfg->fcb_mode = 1; + +#ifdef DEBUGGING + if (bits >= 55) + { + printf("too much bits -> %d, LPC = %d and pitch = %d\n", bits, tdm_lp_reuse_flag, tdm_Pitch_reuse_flag); + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0); + } + else +#endif + if (bits >= 16) + { + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0); + } + else + { + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0); + acelp_cfg->fixed_cdk_index[1] = -1; + } + acelp_cfg->fixed_cdk_index[2] = -1; + acelp_cfg->fixed_cdk_index[3] = -1; + } + else if ((coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO) || (nb_subfr == NB_SUBFR16k && (total_brate > MAX_GSC_INACTIVE_BRATE || coder_type != INACTIVE)) || core == HQ_CORE) + { + /* pitch Q & gain Q bit-budget - part 2*/ + for (i = 0; i < nb_subfr; i++) + { + if (L_frame == L_FRAME) + { + if (tdm_Pitch_reuse_flag == 1 && idchan == 1) + { + acelp_cfg->pitch_bits[i] = 0; + } + else + { + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + } + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + if (tdm_Pitch_reuse_flag == 1 && idchan == 1) + { + acelp_cfg->pitch_bits[i] = 0; + } + else + { + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + } + acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + } + + bits -= acelp_cfg->pitch_bits[i]; + + if (coder_type == INACTIVE && acelp_cfg->gains_mode[i] == 6 /* VQ vs. SQ threshold @32 kbps */) + { + bits -= 5; + } + else + { + if (*uc_two_stage_flag == 1) + { + acelp_cfg->gains_mode[i] = 7; + } + + bits -= acelp_cfg->gains_mode[i]; + } + } + + /* algebraic codebook bit-budget */ + if (flag_hardcoded || (core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE) || (total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE)) + { + for (i = 0; i < nb_subfr; i++) + { + if (L_frame == L_FRAME) + { + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx(tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + } + bits -= acelp_cfg->fixed_cdk_index[i]; + } + } + else if (!(coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD)) + { + if (coder_type == UNVOICED && !(*uc_two_stage_flag)) + { + i = bits / NB_SUBFR; + if (i % 2 == 0) + { + i--; /* must be odd */ + } + i = s_min(i, 13); +#ifdef DEBUG_MODE_TD + if (i < 0) + IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR::: UC negative index should not happen at frame %d\n", frame); +#endif + i = s_max(i, 0); /* If i == 0-> random noise generator will be used as FCB */ + set16_fx(acelp_cfg->fixed_cdk_index, i, NB_SUBFR); + bits -= (i * NB_SUBFR); + } + else + { + + acelp_cfg->fcb_mode = 1; + if (element_mode == IVAS_CPE_TD) + { + if (bits >= ACELP_FIXED_CDK_BITS(0) * (nb_subfr)) /* enough bits for all fcb */ + { + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first); + } + else if (bits >= ACELP_FIXED_CDK_BITS(0) * (nb_subfr - 1)) + { + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr - 1, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_cfg->fixed_cdk_index[3] = -1; + } + else if (bits >= ACELP_FIXED_CDK_BITS(0) * (nb_subfr - 2)) + { + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr - 2, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; + acelp_cfg->fixed_cdk_index[1] = -1; + acelp_cfg->fixed_cdk_index[3] = -1; + } + else if (bits >= ACELP_FIXED_CDK_BITS(0)) + { + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first); + acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; + acelp_cfg->fixed_cdk_index[0] = -1; + acelp_cfg->fixed_cdk_index[2] = -1; + acelp_cfg->fixed_cdk_index[3] = -1; + } + else /* No FCB */ + { +#if defined DEBUGGING + IVAS_ERROR(IVAS_ERR_INTERNAL, "WARNING!!!, No bit allocated to FCB, check frame %d\n", frame); +#endif + acelp_cfg->fixed_cdk_index[0] = -1; + acelp_cfg->fixed_cdk_index[1] = -1; + acelp_cfg->fixed_cdk_index[2] = -1; + acelp_cfg->fixed_cdk_index[3] = -1; + } + } + else if (element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && L_frame == L_FRAME16k) + { + bits = 100; /* 9 kbps for fcb */ + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first); + } + else + { + acelp_FCB_allocator(&bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first); + } + } + } + + /* AVQ codebook */ + if ((core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE) || (total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE)) + { + for (i = 0; i < nb_subfr; i++) + { + if (flag_hardcoded) + { + acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + { + bits -= acelp_cfg->AVQ_cdk_bits[i]; + } + } + + bits -= G_AVQ_BITS; + } + + if (core_brate_inp >= MIN_BRATE_AVQ_EXC && core_brate_inp <= MAX_BRATE_AVQ_EXC_TD && coder_type == GENERIC) + { + /* harm. flag ACELP AVQ */ + bits--; + } + + if (!flag_hardcoded) + { + Word16 bit_tmp; + + bit_tmp = bits / nb_subfr; + set16_fx(acelp_cfg->AVQ_cdk_bits, bit_tmp, nb_subfr); + bits -= bit_tmp * nb_subfr; + + bit_tmp = bits % nb_subfr; + acelp_cfg->AVQ_cdk_bits[0] += bit_tmp; + bits -= bit_tmp; + } + } + } + else if ((coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD) || ((coder_type == INACTIVE || coder_type == AUDIO) && nb_subfr == NB_SUBFR) || (coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE)) + { + Word32 Local_BR, Pitch_BR; + Word16 Pitch_CT; + + /* as defined at the beginning of [enc,dec]_pit_exc() */ + if (GSC_IVAS_mode > 0 && (GSC_noisy_speech || core_brate > GSC_H_RATE_STG)) + { + Local_BR = ACELP_8k00; + Pitch_CT = GENERIC; + Pitch_BR = ACELP_8k00; + if (L_frame == L_FRAME16k) + { + Local_BR = ACELP_14k80; + if (GSC_IVAS_mode > 0 && core_brate < IVAS_24k4) + { + Local_BR = ACELP_9k60; + } + Pitch_BR = core_brate; + } + } + else if (GSC_noisy_speech) + { + Local_BR = ACELP_7k20; + Pitch_CT = GENERIC; + Pitch_BR = ACELP_7k20; + if (L_frame == L_FRAME16k) + { + Pitch_BR = core_brate; + } + } + else + { + Local_BR = ACELP_7k20; + Pitch_CT = AUDIO; + Pitch_BR = core_brate; + + if (L_frame == L_FRAME16k) + { + Local_BR = ACELP_13k20; + Pitch_CT = GENERIC; + } + } + + for (i = 0; i < nb_subfr; i++) + { + if (L_frame == L_FRAME16k) + { + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(Pitch_BR, Pitch_CT, i * L_SUBFR, 0)]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx(Local_BR, LOCAL_CT, i * L_SUBFR, 0)]; + } + else + { + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx(Pitch_BR, Pitch_CT, i * L_SUBFR, 0)]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx(Local_BR, LOCAL_CT, i * L_SUBFR, 0)]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx(ACELP_7k20, LOCAL_CT, i * L_SUBFR, 0)]; + } + } + } + + if (coder_type == TRANSITION && (tc_call == 1 && tc_subfr == 0 && L_frame == L_FRAME)) + { + return error; + } + + /*-----------------------------------------------------------------* + * unused bits handling + *-----------------------------------------------------------------*/ + + acelp_cfg->ubits = 0; /* these bits could be reused for something else */ + + if (flag_hardcoded && core_brate != PPP_NELP_2k80) + { + /* unused bits */ + if (coder_type == AUDIO || (coder_type == INACTIVE && core_brate <= ACELP_24k40)) + { + acelp_cfg->ubits = 0; + } + else if (L_frame == L_FRAME) + { + acelp_cfg->ubits = reserved_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, -1, TC_SUBFR2IDX_fx(tc_subfr))]; + } + else + { + acelp_cfg->ubits = 0; + } + + bits -= acelp_cfg->ubits; + } + + /* sanity check */ + if ((coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO) || nb_subfr == NB_SUBFR16k) + { + if ((L_frame == L_FRAME16k && coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE) || (GSC_IVAS_mode > 0 && L_frame == L_FRAME16k)) /* GSC Inactive @16kHz */ + { + acelp_cfg->ubits = 0; + } + else if (flag_hardcoded && core == ACELP_CORE && bits != 0) + { +#if defined DEBUGGING + IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32)bits, frame); +#endif + } + else if (bits > 0 && !(coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD)) + { + if (idchan > 0 && element_mode == IVAS_CPE_TD) + { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if (!tdm_lp_reuse_flag) + { + acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ + bits = 0; + } + else + { + Word16 nb_prm = 4; + if (tdm_low_rate_mode == 1) + { + nb_prm = 2; + } + /* First add remaining bits on gains */ + bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode); + + /* Then, Increase pitch bit budget */ + if (tdm_Pitch_reuse_flag == 0 && bits > 0) + { + bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits); + } + + /* Increase mid-lsf bit budget */ + if (tdm_lp_reuse_flag == 0 && bits > 0) + { + bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits); + bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits); + } + } +#else + Word16 nb_prm = 4; + + if (tdm_low_rate_mode == 1) + { + nb_prm = 2; + } + + /* First add remaining bits on gains */ + if (!(*uc_two_stage_flag)) + { + bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode); + } + + /* Then, Increase pitch bit budget */ + if (tdm_Pitch_reuse_flag == 0 && bits > 0) + { + bits -= allocate_unused(core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits); + } + + /* Increase mid-lsf bit budget */ + if (tdm_lp_reuse_flag == 0 && bits > 0) + { + bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits); + bits -= allocate_unused(core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits); + } +#endif +#if defined DEBUGGING + if (idchan > 0 && bits > 0 && (coder_type > UNVOICED || tdm_low_rate_mode == 0)) + { + IVAS_ERROR(IVAS_ERR_INTERNAL, "WARNING !! Unused bits in secondary channel at frame %d\n", frame); + } +#endif + } + + else if (core == ACELP_CORE && coder_type >= UNVOICED && coder_type <= GENERIC && L_frame == L_FRAME) + { + acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ + + if (acelp_cfg->lsf_bits > 46) + { + acelp_cfg->ubits = acelp_cfg->lsf_bits - 46; + acelp_cfg->lsf_bits = 46; + } + else if (acelp_cfg->lsf_bits > 42 && L_frame == L_FRAME) + { + acelp_cfg->ubits = acelp_cfg->lsf_bits - 42; + acelp_cfg->lsf_bits = 42; + } + } + else + { + acelp_cfg->ubits = bits; + } + } + else if (bits < 0 && !(coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD)) + { +#if defined DEBUGGING + IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32)bits, frame); +#endif + } + } + + return error; +} + +/*-------------------------------------------------------------------* + * allocate_unused() + * + * Allocate unused bits + *--------------------------------------------------------------------*/ + +static Word16 allocate_unused( + const Word32 core_brate, + const Word16 coder_type, + const Word16 unused_bits, + const Word16 nb_prm, + const Word16 subfr, + const Word16 prm_type, + Word16* prm_bit_mode) +{ + Word16 max_bit_per_pos = 0, bit_added = 0; + PMT("Not floating point computation, but fixed point operator are still missing ") + + if (prm_type == GAINSPRM) + { + max_bit_per_pos = 6; + if (core_brate > ACELP_8k00) + { + max_bit_per_pos = 7; + } + else if (coder_type != UNVOICED) + { + if (subfr >= 1) + { + max_bit_per_pos = 7; + } + else if (subfr == 0) + { + max_bit_per_pos = 8; + } + } + else if (coder_type == UNVOICED) + { + max_bit_per_pos = 9; /* No real limit on UC gain bit budget of the secondary channel */ + } + } + else if (prm_type == PITCHPRM) + { + max_bit_per_pos = 6; + if (subfr == 0 || subfr == 2 || nb_prm == 2) + { + max_bit_per_pos = 10; + } + + if (coder_type == UNVOICED) + { + max_bit_per_pos = 0; /* Should not allocate bits in case of unvoiced coder type */ + } + } + else if (prm_type == MID_LSFSPRM) + { + max_bit_per_pos = 5; + } + else if (prm_type == LSFPRM) + { + max_bit_per_pos = 42; + } + else + { +#ifdef DEBUG_MODE_TD + IVAS_ERROR(IVAS_ERR_WRONG_MODE, "unknown mode in bit_alloc.c"); +#endif + } + + max_bit_per_pos = s_min(unused_bits, max_bit_per_pos - prm_bit_mode[subfr]); + if (max_bit_per_pos < 0) + { + return 0; + } + else if (max_bit_per_pos >= 0 && subfr == (nb_prm - 1)) + { + prm_bit_mode[subfr] += max_bit_per_pos; + } + else + { + prm_bit_mode[subfr] += max_bit_per_pos; + bit_added += allocate_unused(core_brate, coder_type, unused_bits - max_bit_per_pos, nb_prm, subfr + 1, prm_type, &prm_bit_mode[0]); + } + + return bit_added + max_bit_per_pos; +} + + +/*-------------------------------------------------------------------* + * set_ACELP_flag() + * + * set ACELP@16kHz flag + *--------------------------------------------------------------------*/ + + /*! r: ACELP16k flag */ +Word16 set_ACELP_flag( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate per channel */ + const Word16 idchan, /* i : Channel id */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 cng_type /* i : CNG type */ +) +{ + PMT("Not floating point computation, but fixed point operator are still missing ") + if (element_mode == IVAS_CPE_DFT && idchan == 0 && total_brate <= SID_2k40 && bwidth == WB && cng_type == LP_CNG) + { + + return 1; + } + else if (element_mode == IVAS_CPE_TD) + { + if (element_brate >= IVAS_24k4 && idchan == 0 && (tdm_LRTD_flag == 0 || element_brate > IVAS_24k4)) + { + return 1; + } + else + { + return 0; + } + } + else if (element_mode == IVAS_CPE_DFT) + { + if (element_brate >= IVAS_24k4) + { + return 1; + } + else + { + return 0; + } + } + else if (element_mode == IVAS_SCE) + { + if (element_brate >= SCE_CORE_16k_LOW_LIMIT) + { + return 1; + } + else + { + return 0; + } + } + else if (total_brate >= ACELP_16k_LOW_LIMIT) /* EVS_MONO */ + { + return 1; + } + else + { + return 0; + } +} +/*#endif IVAS_CODE*/ \ No newline at end of file diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index c734eb4..56c3c43 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -4,21 +4,24 @@ #include #include -#include "stl.h" +#include "options.h" #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "options.h" #include "basop_util.h" #include "rom_com_fx.h" #include "mime.h" +//#include "ivas_prot.h" +#include "ivas_cnst.h" +#include "ivas_rom_com.h" #ifdef DEBUGGING /*-------------------------------------------------------------------* * Global variables *--------------------------------------------------------------------*/ int16_t FEC_seed = 12558; /* Seed for random FEC generator */ -float FEC_random = 0; /* FEC rate in percent (for simulation of FEC) */ FILE* FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */ +#ifndef IVAS_CODE +float FEC_random = 0; /* FEC rate in percent (for simulation of FEC) */ /*-------------------------------------------------------------------* * file_read_FECpattern() * @@ -74,6 +77,7 @@ static int16_t file_read_FECpattern(void) return bfi; } #endif +#endif /*-------------------------------------------------------------------* * pack_bit() * @@ -131,10 +135,10 @@ static Word16 unpack_bit( * lookup AMRWB IO mode *-------------------------------------------------------------------*/ static Word16 rate2AMRWB_IOmode( - Word32 rate /* i: bit rate */ + Word32 brate /* i: bitrate */ ) { - switch ( rate ) + switch ( brate ) { /* EVS AMR-WB IO modes */ case SID_1k75 : @@ -158,8 +162,9 @@ static Word16 rate2AMRWB_IOmode( case ACELP_23k85 : return AMRWB_IO_2385; default: - return -1; + break; } + return -1; } /*-------------------------------------------------------------------* @@ -167,11 +172,16 @@ static Word16 rate2AMRWB_IOmode( * * lookup EVS mode *-------------------------------------------------------------------*/ -static Word16 rate2EVSmode( - Word32 rate /* i: bit rate */ +Word16 rate2EVSmode( + Word32 brate, /* i: bitrate */ + Word16* is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ ) { - switch ( rate ) + if (is_amr_wb != NULL) + { + *is_amr_wb = 0; + } + switch ( brate ) { /* EVS Primary modes */ case FRAME_NO_DATA : @@ -202,9 +212,14 @@ static Word16 rate2EVSmode( return PRIMARY_96000; case HQ_128k : return PRIMARY_128000; - default : - return rate2AMRWB_IOmode(rate); + default : + break; } + if (is_amr_wb != NULL) + { + *is_amr_wb = 1; + } + return rate2AMRWB_IOmode(brate); } /*-------------------------------------------------------------------* @@ -214,7 +229,7 @@ static Word16 rate2EVSmode( *-------------------------------------------------------------------*/ void push_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr , /* i/o: encoder state structure */ Word16 id, /* i : ID of the indice */ UWord16 value, /* i : value of the quantized indice */ Word16 nb_bits /* i : number of bits used to quantize the indice */ @@ -223,33 +238,33 @@ void push_indice_fx( Word16 i; - IF ( EQ_16(st_fx->last_ind_fx, id)) + IF ( EQ_16(hBstr->last_ind_fx, id)) { /* indice with the same name as the previous one */ - i = st_fx->next_ind_fx; + i = hBstr->next_ind_fx; } ELSE { /* new indice - find an empty slot in the list */ i = id; move16(); - WHILE (NE_16(st_fx->ind_list_fx[i].nb_bits, -1)) + WHILE (NE_16(hBstr->ind_list_fx[i].nb_bits, -1)) { i = add(i, 1); } } /* store the values in the list */ - st_fx->ind_list_fx[i].value = value; + hBstr->ind_list_fx[i].value = value; move16(); - st_fx->ind_list_fx[i].nb_bits = nb_bits; + hBstr->ind_list_fx[i].nb_bits = nb_bits; move16(); /* updates */ - st_fx->next_ind_fx = add(i, 1); - st_fx->last_ind_fx = id; + hBstr->next_ind_fx = add(i, 1); + hBstr->last_ind_fx = id; move16(); - st_fx->nb_bits_tot_fx = add(st_fx->nb_bits_tot_fx, nb_bits); + hBstr->nb_bits_tot_fx = add(hBstr->nb_bits_tot_fx, nb_bits); return; } @@ -260,22 +275,22 @@ void push_indice_fx( *-------------------------------------------------------------------*/ void push_next_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ UWord16 value, /* i : value of the quantized indice */ Word16 nb_bits /* i : number of bits used to quantize the indice */ ) { /* store the values in the list */ - st_fx->ind_list_fx[st_fx->next_ind_fx].value = value; + hBstr->ind_list_fx[hBstr->next_ind_fx].value = value; move16(); - st_fx->ind_list_fx[st_fx->next_ind_fx].nb_bits = nb_bits; + hBstr->ind_list_fx[hBstr->next_ind_fx].nb_bits = nb_bits; move16(); - st_fx->next_ind_fx = add(st_fx->next_ind_fx, 1); + hBstr->next_ind_fx = add(hBstr->next_ind_fx, 1); /* update the total number of bits already written */ - st_fx->nb_bits_tot_fx = add(st_fx->nb_bits_tot_fx, nb_bits); + hBstr->nb_bits_tot_fx = add(hBstr->nb_bits_tot_fx, nb_bits); return; } @@ -287,7 +302,7 @@ void push_next_indice_fx( *-------------------------------------------------------------------*/ void push_next_bits_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ Word16 nb_bits /* i : number of bits to pack */ ) @@ -296,7 +311,7 @@ void push_next_bits_fx( Word16 i, nb_bits_m15; Indice_fx *ptr; - ptr = &st_fx->ind_list_fx[st_fx->next_ind_fx]; + ptr = &hBstr->ind_list_fx[hBstr->next_ind_fx]; nb_bits_m15 = sub(nb_bits, 15); i = 0; move16(); @@ -327,8 +342,8 @@ void push_next_bits_fx( ++ptr; } } - st_fx->next_ind_fx = (Word16)(ptr - st_fx->ind_list_fx); - st_fx->nb_bits_tot_fx = add(st_fx->nb_bits_tot_fx, nb_bits); + hBstr->next_ind_fx = (Word16)(ptr - hBstr->ind_list_fx); + hBstr->nb_bits_tot_fx = add(hBstr->nb_bits_tot_fx, nb_bits); } /*-------------------------------------------------------------------* @@ -474,21 +489,21 @@ UWord16 get_indice_1_fx( /* o : value of the indice */ *-------------------------------------------------------------------*/ void reset_indices_enc_fx( - Encoder_State_fx *st_fx -) + BSTR_ENC_HANDLE hBstr /* i/o: encoder state structure */ + ) { Word16 i; - st_fx->nb_bits_tot_fx = 0; + hBstr->nb_bits_tot_fx = 0; move16(); - st_fx->next_ind_fx = 0; + hBstr->next_ind_fx = 0; move16(); - st_fx->last_ind_fx = -1; + hBstr->last_ind_fx = -1; move16(); FOR (i=0; iind_list_fx[i].nb_bits = -1; + hBstr->ind_list_fx[i].nb_bits = -1; move16(); } @@ -520,6 +535,7 @@ void reset_indices_dec_fx( void write_indices_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ FILE *file /* i : output bitstream file */ , UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ @@ -529,6 +545,7 @@ void write_indices_fx( Word16 stream[2+MAX_BITS_PER_FRAME], *pt_stream; Word32 mask; UWord8 header; + Word16 isAmrWb = 0; if( st_fx->bitstreamformat == G192 ) { @@ -541,7 +558,7 @@ void write_indices_fx( stream[i] = 0; } *pt_stream++ = (Word16)SYNC_GOOD_FRAME; - *pt_stream++ = st_fx->nb_bits_tot_fx; + *pt_stream++ = hBstr->nb_bits_tot_fx; /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) @@ -550,15 +567,15 @@ void write_indices_fx( for (i=0; iind_list_fx[i].nb_bits != -1) + if (hBstr->ind_list_fx[i].nb_bits != -1) { /* mask from MSB to LSB */ - mask = 1 << (st_fx->ind_list_fx[i].nb_bits - 1); + mask = 1 << (hBstr->ind_list_fx[i].nb_bits - 1); /* write bit by bit */ - for (k=0; k < st_fx->ind_list_fx[i].nb_bits; k++) + for (k=0; k < hBstr->ind_list_fx[i].nb_bits; k++) { - if ( st_fx->ind_list_fx[i].value & mask ) + if (hBstr->ind_list_fx[i].value & mask ) { *pt_stream++ = G192_BIN1; } @@ -577,7 +594,7 @@ void write_indices_fx( { /* Create and write ToC header */ /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8)(st_fx->Opt_AMR_WB_fx << 5 | st_fx->Opt_AMR_WB_fx << 4 | rate2EVSmode(st_fx->nb_bits_tot_fx * 50)); + header = (UWord8)(st_fx->Opt_AMR_WB_fx << 5 | st_fx->Opt_AMR_WB_fx << 4 | rate2EVSmode(hBstr->nb_bits_tot_fx * 50, &isAmrWb)); fwrite( &header, sizeof(UWord8), 1, file ); /* Write speech bits */ fwrite( pFrame, sizeof(UWord8), (pFrame_size + 7)>>3, file ); @@ -586,7 +603,7 @@ void write_indices_fx( /* Clearing of indices */ FOR (i=0; iind_list_fx[i].nb_bits = -1; + hBstr->ind_list_fx[i].nb_bits = -1; move16(); } @@ -597,9 +614,9 @@ void write_indices_fx( fwrite( stream, sizeof(unsigned short), 2+stream[1], file ); } /* reset index pointers */ - st_fx->nb_bits_tot_fx = 0; - st_fx->next_ind_fx = 0; - st_fx->last_ind_fx = -1; + hBstr->nb_bits_tot_fx = 0; + hBstr->next_ind_fx = 0; + hBstr->last_ind_fx = -1; return; } @@ -612,6 +629,7 @@ void write_indices_fx( void indices_to_serial( const Encoder_State_fx *st_fx, /* i: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ Word16 *pFrame_size /* o: size of the binary encoded access unit [bits] */ ) @@ -622,31 +640,32 @@ void indices_to_serial( Word16 amrwb_bits[(ACELP_23k85 / 50)]; UWord8 omask= 0x80; UWord8 *pt_pFrame=pFrame; + Word16 isAmrWb = 0; if ( st_fx->Opt_AMR_WB_fx ) { - cmi = rate2EVSmode(st_fx->total_brate_fx); - core_mode = rate2EVSmode(st_fx->nb_bits_tot_fx * 50); + cmi = rate2EVSmode(st_fx->total_brate_fx, &isAmrWb); + core_mode = rate2EVSmode(hBstr->nb_bits_tot_fx * 50, &isAmrWb); j=0; for (i=0; iind_list_fx[i].nb_bits != -1) + if (hBstr->ind_list_fx[i].nb_bits != -1) { /* mask from MSB to LSB */ - mask = 1 << (st_fx->ind_list_fx[i].nb_bits - 1); + mask = 1 << (hBstr->ind_list_fx[i].nb_bits - 1); /* temporarily save bit */ - for (k=0; k < st_fx->ind_list_fx[i].nb_bits; k++) + for (k=0; k < hBstr->ind_list_fx[i].nb_bits; k++) { - amrwb_bits[j++] = (st_fx->ind_list_fx[i].value & mask) > 0; + amrwb_bits[j++] = (hBstr->ind_list_fx[i].value & mask) > 0; mask >>= 1; } } } } - *pFrame_size = st_fx->nb_bits_tot_fx; + *pFrame_size = hBstr->nb_bits_tot_fx; /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) @@ -654,13 +673,13 @@ void indices_to_serial( j=0; for (i=0; iind_list_fx[i].nb_bits != -1) + if (hBstr->ind_list_fx[i].nb_bits != -1) { /* mask from MSB to LSB */ - mask = 1 << (st_fx->ind_list_fx[i].nb_bits - 1); + mask = 1 << (hBstr->ind_list_fx[i].nb_bits - 1); /* write bit by bit */ - for (k=0; k < st_fx->ind_list_fx[i].nb_bits; k++) + for (k=0; k < hBstr->ind_list_fx[i].nb_bits; k++) { if (st_fx->Opt_AMR_WB_fx ) { @@ -668,7 +687,7 @@ void indices_to_serial( } else { - pack_bit(st_fx->ind_list_fx[i].value & mask, &pt_pFrame, &omask); + pack_bit(hBstr->ind_list_fx[i].value & mask, &pt_pFrame, &omask); j++; } mask >>= 1; @@ -880,7 +899,7 @@ static void decoder_selectCodec( move16(); } } - st->last_cng_type_fx = st->cng_type_fx; /* CNG type switching at the first correctly received SID frame */ + st->hTdCngDec->last_cng_type_fx = st->cng_type_fx; /* CNG type switching at the first correctly received SID frame */ } @@ -1223,6 +1242,7 @@ static void mdct_switching_dec( Word16 BRATE2IDX_fx(Word32 brate) { + Word32 L_temp; Word32 L_idx; #define START 9 @@ -1428,7 +1448,7 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem /* verify that a valid num bits value is present in the G.192 file */ /* only AMRWB or EVS bit rates or 0(NO DATA) are allowed in G.192 file frame reading */ - if( rate2EVSmode(total_brate) < 0 ) /* negative value means that a valid rate was not found */ + if( rate2EVSmode(total_brate, NULL) < 0 ) /* negative value means that a valid rate was not found */ { fprintf(stderr, "\nError, illegal bit rate (%d) in the G.192 frame ! Exiting ! \n", total_brate); exit(-1); @@ -1577,10 +1597,11 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem /* st->total brate= total_brate ; updated in a good frame below */ } /* rew_flag */ + + /* get total bit-rate */ #ifdef DEBUGGING st->bfi_fx |= file_read_FECpattern(); #endif - /* get total bit-rate */ if ( st->bfi_fx == 0 && !rew_flag ) { /* select MODE1 or MODE2 */ @@ -1622,7 +1643,18 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem mdct_switching_dec(st); } +#ifdef DEBUGGING + else + { + bit_stream_ptr = st->bit_stream_fx; + + for (k = 0; k < num_bits+ 2 * 8; ++k) + { + *bit_stream_ptr++ = 0; + } + } +#endif return 1; } @@ -2139,7 +2171,6 @@ void getPartialCopyInfo( st->core_fx = 0; } } - /* check for bit errors */ berCheck( st, coder_type ); diff --git a/lib_com/cb_shape_fx.c b/lib_com/cb_shape_fx.c index b475136..475f9dd 100644 --- a/lib_com/cb_shape_fx.c +++ b/lib_com/cb_shape_fx.c @@ -1,14 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* */ -#include "stl.h" - /* * E_GAIN_f_pitch_sharpening * @@ -52,29 +50,31 @@ void cb_shape_fx( const Word16 g1, /* i : formant sharpening numerator weighting */ const Word16 g2, /* i : formant sharpening denominator weighting */ const Word16 *p_Aq, /* i : LP filter coefficients */ - Word16 *code, /* i/o: signal to shape */ + Word16 *code, /* i/o: signal to shape */ const Word16 tilt_code, /* i : tilt of code */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ - const Word16 shift + const Word16 shift, + const Word16 L_subfr /* i : subframe lenght */ ) { - Word16 tmp, buff[L_SUBFR+M], A_num[M+1], A_den[M+1]; + Word16 tmp, buff[2*L_SUBFR + M], A_num[M + 1], A_den[M + 1]; Word16 i; Word32 L_tmp; Word16 tilt, mu; tmp = 0; + move16(); /* Pre-emphasis */ IF( preemphFlag ) { - preemph_copy_fx(code, code, tilt_code, L_SUBFR, &tmp); + preemph_copy_fx(code, code, tilt_code, L_subfr, &tmp); } /* pitch sharpening */ IF( pitchFlag ) { - E_GAIN_f_pitch_sharpening( code, pt_pitch, L_SUBFR ); + E_GAIN_f_pitch_sharpening( code, pt_pitch, L_subfr); } /* phase scrambling filter */ @@ -82,7 +82,7 @@ void cb_shape_fx( { buff[0] = code[0]; move16(); - FOR (i = 1; i < L_SUBFR; i++) + FOR (i = 1; i < L_subfr; i++) { buff[i]=code[i]; move16(); @@ -99,32 +99,32 @@ void cb_shape_fx( { weight_a_fx( p_Aq, A_num, g1, M ); weight_a_fx( p_Aq, A_den, g2, M ); - set16_fx(buff, 0, M+L_SUBFR); + set16_fx(buff, 0, M+ L_subfr); IF( formantTiltFlag ) { Copy(A_num, buff+M, M+1); - E_UTIL_synthesis(1, A_den, buff+M, buff+M, L_SUBFR, buff, 0, M); + E_UTIL_synthesis(1, A_den, buff+M, buff+M, L_subfr, buff, 0, M); /*Compute tilt of formant enhancement*/ - tilt = extract_l(L_shr(get_gain(buff+M+1, buff+M, L_SUBFR-1),1)); + tilt = extract_l(L_shr(get_gain(buff+M+1, buff+M, L_subfr -1),1)); /*Combine tilt of code and fe*/ tmp = 0; move16(); /*mu = 0.5f*tilt_code-0.25f*tilt;*/ mu = sub(shr(tilt_code,1),shr(tilt,2)); - preemph_copy_fx(code, code, mu, L_SUBFR, &tmp); + preemph_copy_fx(code, code, mu, L_subfr, &tmp); } ELSE { - Copy( code, buff, L_SUBFR ); + Copy( code, buff, L_subfr); Overflow = 0; move16(); - Residu3_lc_fx(A_num, M, buff, code, L_SUBFR, shift); + Residu3_lc_fx(A_num, M, buff, code, L_subfr, shift); { - syn_filt_s_lc_fx(shift, A_den, code, code, L_SUBFR); + syn_filt_s_lc_fx(shift, A_den, code, code, L_subfr); } } } diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index a05236e..788c0b1 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -977,27 +977,41 @@ void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns han * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ -void openCldfb ( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ - ) +ivas_error openCldfb ( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ + const Word16 type, /*!< analysis or synthesis */ + const Word16 maxCldfbBands, /*!< number of cldfb bands */ + const Word16 frameSize /*!< FrameSize */ +#ifdef ADD_IVAS_CLDFB + ,CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ +#endif +) { HANDLE_CLDFB_FILTER_BANK hs; - hs = (HANDLE_CLDFB_FILTER_BANK) calloc(1, sizeof (struct CLDFB_FILTER_BANK)); - + hs = (HANDLE_CLDFB_FILTER_BANK)count_malloc(sizeof (struct CLDFB_FILTER_BANK)); + if (hs == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); + } hs->type = type; +#ifdef ADD_IVAS_CLDFB + hs->prototype = prototype; +#endif move16(); IF (type == CLDFB_ANALYSIS) { - hs->FilterStates = (Word16 *) calloc(STATE_BUFFER_SIZE*maxCldfbBands, sizeof (Word16)); + hs->FilterStates = (Word16 *)count_malloc(STATE_BUFFER_SIZE*maxCldfbBands* sizeof (Word16)); } ELSE { - hs->FilterStates = (Word16 *) calloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands, sizeof (Word16)); + hs->FilterStates = (Word16 *)count_malloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands* sizeof (Word16)); + } + if (hs->FilterStates == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB"); } hs->flags &= ~CLDFB_FLAG_KEEP_STATES; @@ -1037,7 +1051,7 @@ void openCldfb ( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ *h_cldfb = hs; } - return; + return IVAS_ERR_OK; } @@ -1212,7 +1226,7 @@ void analysisCldfbEncoder_fx( &st_fx->currEnergyHF_e_fx, enerBuffSum, enerBuffSum_exp, - &st_fx->tecEnc + st_fx->hTECEnc ); return; @@ -1231,7 +1245,7 @@ GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | p Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ Word16 *energyValuesSum_Exp,/*!< o: pointer to exponents of energyValuesSum, not initialized */ - HANDLE_TEC_ENC_FX hTecEnc + TEC_ENC_HANDLE_FX hTecEnc ) { Word16 j; @@ -1450,9 +1464,9 @@ deleteCldfb (HANDLE_CLDFB_FILTER_BANK * h_cldfb) /* i: cldfb handle { IF ( (*h_cldfb)->FilterStates != NULL ) { - free((*h_cldfb)->FilterStates); + count_free((*h_cldfb)->FilterStates); } - free(*h_cldfb); + count_free(*h_cldfb); } *h_cldfb = NULL; } @@ -1590,21 +1604,28 @@ cldfb_init_proto_and_twiddles(HANDLE_CLDFB_FILTER_BANK hs) /* i: cldfb handl * * Save the memory of filter; to be restored with cldfb_restore_memory() *--------------------------------------------------------------------*/ -void +ivas_error cldfb_save_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i: cldfb handle */ { + if (hs->memory != NULL || hs->memory_length != 0) + { + /* memory already stored; Free memory first */ + return IVAS_ERR_OK; + } hs->memory_length = cldfb_get_memory_length(hs); hs->memory = (Word16 *) calloc( hs->memory_length + CLDFB_MEM_EXPONENTS + 1, sizeof (Word16)); - /* save the memory */ Copy (hs->FilterStates, hs->memory, hs->memory_length); Copy (hs->FilterStates_e, hs->memory+hs->memory_length, CLDFB_MEM_EXPONENTS); hs->memory[hs->memory_length+CLDFB_MEM_EXPONENTS] = hs->FilterStates_eg; move16(); - - return; + if (hs->memory == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n"); + } + return IVAS_ERR_OK; } @@ -1628,6 +1649,7 @@ cldfb_restore_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i/o: cldfb handle */ hs->FilterStates_eg = hs->memory[hs->memory_length+CLDFB_MEM_EXPONENTS]; move16(); + /* adjust sample rate if it was changed in the meanwhile */ IF (NE_16 (hs->memory_length,size)) { @@ -1635,7 +1657,7 @@ cldfb_restore_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i/o: cldfb handle */ } hs->memory_length = 0; - free(hs->memory); + count_free(hs->memory); hs->memory = NULL; return; @@ -1657,5 +1679,6 @@ cldfb_reset_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i/o: cldfb handle */ set16_fx (hs->FilterStates_e, 0, sizeof(hs->FilterStates_e)/sizeof(hs->FilterStates_e[0])); hs->FilterStates_eg = 0; move16(); + return; } diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index b0249f6..245270c 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "rom_com_fx.h" /*---------------------------------------------------------------------* @@ -22,31 +21,32 @@ *-------------------------------------------------------*/ void CNG_exc_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - Word32 *Enew, /* i/o: decoded SID energy Q6 */ - Word16 *seed, /* i/o: random generator seed */ - Word16 exc[], /* o : current non-enhanced excitation Q_new */ - Word16 exc2[], /* o : current enhanced excitation Q_new */ - Word32 *lp_ener, /* i/o: LP filtered E */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ - Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ - const Word16 allow_cn_step, /* i : allow CN step */ - Word16 *last_allow_cn_step, /* i/o: last allow step */ - const Word16 OldQ_exc, /* i : Old excitation scaling */ - const Word16 Q_exc /* i : excitation scaling */ - , const Word16 num_ho /* i : number of selected hangover frames */ - ,Word32 q_env[] - ,Word32 *lp_env - ,Word32 *old_env - ,Word16 *exc_mem - ,Word16 *exc_mem1 - ,Word16 *sid_bw - ,Word16 *cng_ener_seed1 - ,Word16 exc3[] - ,Word16 Opt_AMR_WB + const Word32 core_brate, /* i : core bitrate */ + const Word16 L_frame, /* i : length of the frame */ + Word32 *Enew, /* i/o: decoded SID energy Q6 */ + Word16 *seed, /* i/o: random generator seed */ + Word16 exc[], /* o : current non-enhanced excitation Q_new */ + Word16 exc2[], /* o : current enhanced excitation Q_new */ + Word32 *lp_ener, /* i/o: LP filtered E */ + const Word32 last_core_brate,/* i : previous frame core bitrate */ + Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ + Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ + Word16 bwe_exc[], /* o : excitation for SWB TBE */ + const Word16 allow_cn_step, /* i : allow CN step */ + Word16 *last_allow_cn_step, /* i/o: last allow step */ + const Word16 OldQ_exc, /* i : Old excitation scaling */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 num_ho, /* i : number of selected hangover frames */ + Word32 q_env[], + Word32 *lp_env, + Word32 *old_env, + Word16 *exc_mem, + Word16 *exc_mem1, + Word16 *sid_bw, + Word16 *cng_ener_seed1, + Word16 exc3[], + Word16 Opt_AMR_WB, + const int16_t element_mode /* i : IVAS Element mode */ ) { Word16 i, tmp, tmp2, exp, exp2, Q_ener; @@ -100,8 +100,11 @@ void CNG_exc_fx( move32(); } - *lp_ener = *Enew; - move32(); + if (EQ_16(element_mode, EVS_MONO)) + { + *lp_ener = *Enew; + move32(); + } } /*---------------------------------------------------------------------* @@ -169,7 +172,11 @@ void CNG_exc_fx( *last_allow_cn_step = 1; move16(); } - + /* If not mono, skip CNG here */ + if (GT_16(element_mode, IVAS_SCE)) + { + return; + } /*---------------------------------------------------------------------* * Generate white noise vector *---------------------------------------------------------------------*/ @@ -581,11 +588,15 @@ void CNG_exc_fx( *-------------------------------------------------------*/ void cng_params_postupd_fx( const Word16 ho_circ_ptr, /* i : pointer for CNG averaging buffers Q0 */ - Word16 *cng_buf_cnt, /* i/o: counter for CNG store buffers Q0 */ + Word16 *cng_buf_cnt, /* i/o: counter for CNG store buffers Q0 */ const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ - Word32 ho_env_circ[] /* i/o: Envelope buffer */ + Word32 ho_env_circ[] /* i/o: Envelope buffer */ +#ifdef IVAS_CODE_CNG_COM + ,const Word16 element_mode, /* i : Element mode */ + const Word16 bwidth /* i : Audio bandwidth */ +#endif ) { Word16 i, j; @@ -610,9 +621,9 @@ void cng_params_postupd_fx( ptr = add(ptr, HO_HIST_SIZE); } - FOR( j = 0; j < *cng_buf_cnt; j++ ) + FOR(j = 0; j < *cng_buf_cnt; j++) { - exc2 = &cng_exc2_buf[ptr*L_FFT]; + exc2 = &cng_exc2_buf[ptr * L_FFT]; Q_exc = cng_Qexc_buf[ptr]; last_active_brate = cng_brate_buf[ptr]; @@ -622,57 +633,50 @@ void cng_params_postupd_fx( fft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); ptR = &fft_io[1]; - ptI = &fft_io[L_FFT-1]; - FOR (i=0; iTCX/HQ */ +#define INV_CLDFB_BANDWIDTH ( 1.f / 800.f ) + +#define L_FILT_2OVER3 12 +#define L_FILT_2OVER3_LP 3 +#endif + #define CLDFB_ANALYSIS 0 #define CLDFB_SYNTHESIS 1 @@ -754,6 +785,10 @@ enum #define G_CODE_MIN_TC192_FX 4915 /* Q13 */ #define G_CODE_MAX_TC192_Q0 41 + +#define BIT_SAVING_LOW_THR 10 +#define BIT_SAVING_HIGH_THR 80 + /*--------------------------------------------------------------* * ACELP constants *---------------------------------------------------------------*/ @@ -781,12 +816,16 @@ enum #define TCXLTP_LTP_ORDER 24 #define TCX_RES_Q_BITS_GAIN 3 +#define LPC_SHAPED_ARI_MAX_RATE_CPE ACELP_13k20 #define LPC_SHAPED_ARI_MAX_RATE ACELP_9k60 #define N_MAX_ARI 800 #define SPEC_EXP_DEC 20 /* initial decoder spectrum exponent */ + +#define N_TCX_STARTLINE_NOISE_WB 11 +#define N_TCX_STARTLINE_NOISE_SWB 9 /*----------------------------------------------------------------------------------* * TNS constants *----------------------------------------------------------------------------------*/ @@ -808,7 +847,8 @@ enum #define DEC_NPRM_DIV NPRM_DIV /* Total number of quantized parameter in 1 division (decoder side) */ #define NPRM_LPC_NEW 2*(4+2*NB_SPHERE) /* LPC total number of quantized parameters */ -#define BITBUFSIZE (128000/50) +#define BITBUFSIZE (IVAS_BRATE_MAX/FRAMES_PER_SEC) +#define IGF_BITBUFSIZE ( HQ_128k / FRAMES_PER_SEC ) #define TNS_COEF_RES 4 /* Bit resolution of the coefficients. */ #define INDEX_SHIFT (1 << (TNS_COEF_RES-1)) /* For shifting the index so that index 0 points to 0. */ @@ -862,6 +902,12 @@ enum #define MAX_NO_MODES_p 145 #define NO_CODING_MODES 6 #define LVQ_COD_MODES 18 + +#ifdef MSVQ_ROM +#define LIMIT_LEADER 19 +#define DELTA_LEADER 256 +#endif + /* BC-TCQ */ #define N_STAGE_VQ 8 #define N_DIM 2 @@ -1209,6 +1255,12 @@ enum /*----------------------------------------------------------------------------------* * FD CNG *----------------------------------------------------------------------------------*/ +#define SIZE_SCALE_TABLE_MONO 20 +#define SIZE_SCALE_TABLE_STEREO 27 +#define SIZE_SCALE_TABLE_CN 18 +#define SIZE_SCALE_TABLE_CN_AMRWB 3 +#define SIZE_SCALE_TABLE_TCX 13 + #define DELTA 1e-20f #define DELTA_MANTISSA_W16 0x5e73 #define DELTA_MANTISSA_W32 0x5e728433 @@ -1335,6 +1387,13 @@ enum #define N_FEATURES_2 3 /* number of features */ +#ifdef IVAS_CODE +#define TOD_NSPEC 80 /* number of spectral bins of the tonal detector */ +#define TOD_THR_MASS 0.86f /* initial value for the adaptive threshold of the tonal detector */ +#define P2A_FACT 0.9f /* long-term averaging factor for peak-to-average ratio */ +#define THR_P2A_HIGH 95.0f /* higher threshold to detect strongly peaky signals at low bitrates*/ +#define THR_P2A 80.0f /* lower threshold to detect strongly peaky signals at higher bitrates */ +#endif /*----------------------------------------------------------------------------------* * LD music post-filter constants *----------------------------------------------------------------------------------*/ @@ -1373,8 +1432,14 @@ enum #define SSF 32 /* Sub-subframe length for energy estimation in UC decision */ #define NB_SSF (L_FRAME / SSF) /* number of sub-subframes per frame */ +//IVAS_CODE +#define GSC_LRES_GAINQ_LIMIT 3000 /* Bitrate where the low resolution quantization starts for the GSC */ +#define GSC_LRES_NB_NITS 10 /* Number of bits gained by using the low resolution quantization */ -#define MBANDS_GN 16 /* Number of band for gain coding in GSC */ + +#define MBANDS_GN16k 18 /* Number of band for gain coding in GSC */ +#define MBANDS_GN 16 /* Number of band for gain coding in GSC */ +#define MBANDS_GN_BITALLOC16k 20 /* Number of band for gain coding in GSC */ #define BAND1k2 3 #define MBANDS_LOC (MBANDS_GN-1) @@ -1549,12 +1614,33 @@ enum #define HVQ_MAX_PEAKS_32k 23 #define HVQ_MAX_PEAKS_24k 17 #define HVQ_MAX_PEAKS_24k_CLAS 20 /* Limit for HVQ mode */ +#ifdef IVAS_CNST +#define HVQ_MAX_PEAKS (HVQ_MAX_PEAKS_32k + 1 + 11 ) +#else #define HVQ_MAX_PEAKS HVQ_MAX_PEAKS_32k + 1 +#endif #define HVQ_NUM_SFM_24k (SFM_N_HARMONIC - 1 - HVQ_THRES_SFM_24k) #define HVQ_NUM_SFM_32k (SFM_N_HARMONIC - 1 - HVQ_THRES_SFM_32k) #define HVQ_MAX_RATE 32000 +#ifdef IVAS_CNST +#define HQ_BWE_CROSSOVER_BRATE 26000 /* HQ crossover bitrate between 24.4 and 32 kbps BWE tunings */ +#define HVQ_PEAKS_BPS_DELTA ( HQ_32k - HQ_24k40 ) +#define HVQ_PEAKS_PER_DELTA ( HVQ_MAX_PEAKS_32k - HVQ_MAX_PEAKS_24k ) +#define HVQ_PEAKS_PER_DELTA_THR ( HVQ_MAX_PEAKS_32k - HVQ_MAX_PEAKS_24k_CLAS ) +#define HVQ_PEAKS_PER_DELTA_OFFS ( HVQ_MAX_PEAKS_24k * HVQ_PEAKS_BPS_DELTA - HQ_24k40 * HVQ_PEAKS_PER_DELTA ) +#define HVQ_PEAKS_PER_DELTA_THR_OFFS ( HVQ_MAX_PEAKS_24k_CLAS * HVQ_PEAKS_BPS_DELTA - HQ_24k40 * HVQ_PEAKS_PER_DELTA_THR ) +#define L_SPEC48k 800 /* HQ spectrum length at 48kHz */ +#define L_SPEC32k 640 /* HQ spectrum length at 32kHz */ +#define L_SPEC16k 320 /* HQ spectrum length at 16kHz */ +#define L_SPEC8k 160 /* HQ spectrum length at 8kHz */ +#define L_SPEC48k_EXT 1000 /* Extended HQ spectrum length at 48kHz, for ACELP->HQ switching */ +#define L_SPEC32k_EXT 800 /* Extended HQ spectrum length at 32kHz, for ACELP->HQ switching */ +#define L_SPEC16k_EXT 400 /* Extended HQ spectrum length at 16kHz, for ACELP->HQ switching */ +#define L_FRAME48k_EXT 1200 /* Extended MDCT frame size in samples at 48kHz */ + +#endif #define NUMNRMIBITS_SWB_HVQ_24k 35 @@ -1619,7 +1705,7 @@ enum #define MAX_SPLITS 10 /* Maximum number of PVQ band splits */ #define QUANTAQ3OFFSET 1 -enum QuantaMode { NEAREST = 0, CONS }; +enum QuantaMode { PVQ_NEAREST = 0, PVQ_CONS }; #define PYR_OFFSET 1 #define RCF_INIT_SHIFT 14 @@ -1835,6 +1921,9 @@ enum QuantaMode { NEAREST = 0, CONS }; #define kTcxSnrOffsetGc 0x08 /* 0.03125f (7Q8) */ #define kTcxSnrOffsetVc 0x20 /* 0.125f (7Q8) */ +/*IVAS_CNST_AND_ROM*/ +#define LOWRATE_TCXLPC_MAX_BR_CPE ACELP_13k20 +/*End of IVAS_CNST_AND_ROM*/ #define LOWRATE_TCXLPC_MAX_BR ACELP_9k60 /*--------------------------------------------------------------* @@ -1863,23 +1952,62 @@ enum QuantaMode { NEAREST = 0, CONS }; #define IGF_MODE_FB 3 -#define IGF_BITRATE_WB_9600 0 -#define IGF_BITRATE_RF_WB_13200 1 -#define IGF_BITRATE_SWB_9600 2 -#define IGF_BITRATE_SWB_13200 3 -#define IGF_BITRATE_RF_SWB_13200 4 -#define IGF_BITRATE_SWB_16400 5 -#define IGF_BITRATE_SWB_24400 6 -#define IGF_BITRATE_SWB_32000 7 -#define IGF_BITRATE_SWB_48000 8 -#define IGF_BITRATE_FB_16400 9 -#define IGF_BITRATE_FB_24400 10 -#define IGF_BITRATE_FB_32000 11 -#define IGF_BITRATE_FB_48000 12 -#define IGF_BITRATE_FB_96000 13 -#define IGF_BITRATE_FB_128000 14 -#define IGF_BITRATE_UNKNOWN 15 - +//#define IGF_BITRATE_WB_9600 0 +//#define IGF_BITRATE_RF_WB_13200 1 +//#define IGF_BITRATE_SWB_9600 2 +//#define IGF_BITRATE_SWB_13200 3 +//#define IGF_BITRATE_RF_SWB_13200 4 +//#define IGF_BITRATE_SWB_16400 5 +//#define IGF_BITRATE_SWB_24400 6 +//#define IGF_BITRATE_SWB_32000 7 +//#define IGF_BITRATE_SWB_48000 8 +//#define IGF_BITRATE_FB_16400 9 +//#define IGF_BITRATE_FB_24400 10 +//#define IGF_BITRATE_FB_32000 11 +//#define IGF_BITRATE_FB_48000 12 +//#define IGF_BITRATE_FB_96000 13 +//#define IGF_BITRATE_FB_128000 14 +//#define IGF_BITRATE_UNKNOWN 15 +enum +{ + IGF_BITRATE_WB_9600, + IGF_BITRATE_RF_WB_13200, + IGF_BITRATE_SWB_9600, + IGF_BITRATE_SWB_13200, + IGF_BITRATE_RF_SWB_13200, + IGF_BITRATE_SWB_16400, + IGF_BITRATE_SWB_24400, + IGF_BITRATE_SWB_32000, + IGF_BITRATE_SWB_48000, + IGF_BITRATE_SWB_64000, + IGF_BITRATE_FB_16400, + IGF_BITRATE_FB_24400, + IGF_BITRATE_FB_32000, + IGF_BITRATE_FB_48000, + IGF_BITRATE_FB_64000, + IGF_BITRATE_FB_96000, + IGF_BITRATE_FB_128000, + IGF_BITRATE_WB_13200_CPE, + IGF_BITRATE_WB_16400_CPE, + IGF_BITRATE_SWB_13200_CPE, + IGF_BITRATE_SWB_16400_CPE, + IGF_BITRATE_SWB_24400_CPE, + IGF_BITRATE_SWB_32000_CPE, + IGF_BITRATE_SWB_48000_CPE, + IGF_BITRATE_SWB_48000_CPE_TCX10, + IGF_BITRATE_SWB_64000_CPE, + IGF_BITRATE_SWB_80000_CPE, + IGF_BITRATE_SWB_96000_CPE, + IGF_BITRATE_FB_24400_CPE, + IGF_BITRATE_FB_32000_CPE, + IGF_BITRATE_FB_48000_CPE, + IGF_BITRATE_FB_48000_CPE_TCX10, + IGF_BITRATE_FB_64000_CPE, + IGF_BITRATE_FB_80000_CPE, + IGF_BITRATE_FB_96000_CPE, + IGF_BITRATE_FB_128000_CPE, + IGF_BITRATE_UNKNOWN +}; #define IGF_WHITENING_OFF 0 #define IGF_WHITENING_MID 1 diff --git a/lib_com/codec_tcx_common.c b/lib_com/codec_tcx_common.c index 5f5f1db..8fddaf6 100644 --- a/lib_com/codec_tcx_common.c +++ b/lib_com/codec_tcx_common.c @@ -2,19 +2,22 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include -#include "prot_fx.h" #include "options.h" - -#include "stl.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" -#define inv_int InvIntTable - +#define inv_int InvIntTable -Word16 tcxGetNoiseFillingTilt(Word16 A[], Word16 lpcorder, Word16 L_frame, Word16 mode, Word16 *noiseTiltFactor) +Word16 tcxGetNoiseFillingTilt( + const Word16 A[], + const Word16 lpcorder, + const Word16 L_frame, + const Word16 mode, + Word16 *noiseTiltFactor +) { Word16 firstLine; Word32 tmp; @@ -46,10 +49,12 @@ Word16 tcxGetNoiseFillingTilt(Word16 A[], Word16 lpcorder, Word16 L_frame, Word1 void tcxFormantEnhancement( Word16 xn_buf[], - Word16 gainlpc[], Word16 gainlpc_e[], - Word32 spectrum[], Word16 *spectrum_e, - Word16 L_frame, - Word16 L_frameTCX + const Word16 gainlpc[], + const Word16 gainlpc_e[], + Word32 spectrum[], + Word16 *spectrum_e, + const Word16 L_frame, + const Word16 L_frameTCX ) { Word16 i, j, k, l, n; @@ -202,43 +207,39 @@ void tcxFormantEnhancement( } -void tcxInvertWindowGrouping(TCX_config *tcx_cfg, - Word32 xn_buf[], - Word32 spectrum[], - Word16 L_frame, - Word8 fUseTns, - Word16 last_core, - Word16 index, - Word16 frame_cnt, - Word16 bfi) +void tcxInvertWindowGrouping( + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word32 xn_buf[], + Word32 spectrum[], + const Word16 L_frame, + const Word8 fUseTns, + const Word16 last_core, + const Word16 index, + const Word16 frame_cnt, + const Word16 bfi +) { Word16 i, L_win, L_spec; Word32 *p; L_win = shr(L_frame, 1); - L_spec = tcx_cfg->tnsConfig[0][0].iFilterBorders[0]; + L_spec = hTcxCfg->tnsConfig[0][0].iFilterBorders[0]; move16(); test(); test(); - if ((frame_cnt != 0) && (bfi == 0) && (last_core != ACELP_CORE)) /* fix sub-window overlap */ + if ((frame_cnt != 0) && (bfi == 0) && NE_16(last_core, ACELP_CORE)) /* fix sub-window overlap */ { - tcx_cfg->tcx_last_overlap_mode = tcx_cfg->tcx_curr_overlap_mode; + hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF (((bfi==0) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)))) + test();test();test();test();test();test();test(); + IF (((bfi==0) &&((hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) || + ((hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)))) || - ((bfi!=0) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) && - !(tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)))) + ((bfi!=0) &&((hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) && + !(hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP)))) { /* ungroup sub-windows: deinterleave MDCT bins into separate windows */ p = xn_buf; @@ -265,7 +266,7 @@ void tcxInvertWindowGrouping(TCX_config *tcx_cfg, test(); test(); - IF ((tcx_cfg->fIsTNSAllowed != 0) && (bfi == 0) && (fUseTns != 0)) + IF ((hTcxCfg->fIsTNSAllowed != 0) && (bfi == 0) && (fUseTns != 0)) { /* rearrange LF sub-window lines prior to TNS synthesis filtering */ IF (LT_16(L_spec, L_frame)) @@ -285,4 +286,135 @@ void tcxInvertWindowGrouping(TCX_config *tcx_cfg, } +#ifdef IVAS_CODE_TCX_COM + +/*-------------------------------------------------------------------* + * tcx5SpectrumInterleaving() + * + * + *-------------------------------------------------------------------*/ + +void tcx5SpectrumInterleaving( + const int16_t tcx5Size, + float* spectrum) +{ + int16_t i; + float interleaveBuf[N_TCX10_MAX]; + + set_f(interleaveBuf, 0.0f, N_TCX10_MAX); + + /* group sub-windows: interleave bins according to their frequencies */ + for (i = 0; i < tcx5Size; i++) + { + interleaveBuf[2 * i] = spectrum[i]; + interleaveBuf[2 * i + 1] = spectrum[tcx5Size + i]; + } + + mvr2r(interleaveBuf, spectrum, 2 * tcx5Size); + + return; +} + + +/*-------------------------------------------------------------------* + * tcx5SpectrumDeinterleaving() + * + * + *-------------------------------------------------------------------*/ + +void tcx5SpectrumDeinterleaving( + const int16_t tcx5Size, + float* spectrum) +{ + int16_t i; + float interleaveBuf[N_TCX10_MAX]; + + set_f(interleaveBuf, 0.0f, N_TCX10_MAX); + + /* ungroup sub-windows: interleave bins according to their frequencies */ + for (i = 0; i < tcx5Size; i++) + { + interleaveBuf[i] = spectrum[2 * i]; + interleaveBuf[tcx5Size + i] = spectrum[2 * i + 1]; + } + + mvr2r(interleaveBuf, spectrum, 2 * tcx5Size); + + return; +} + + +/*-------------------------------------------------------------------* + * tcx5TnsGrouping() + * + * + *-------------------------------------------------------------------*/ + +void tcx5TnsGrouping( + const int16_t L_frame, /* i : frame length (TCX5) */ + const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ + float* spectrum) +{ + /* rearrange LF sub-window lines prior to TNS synthesis filtering */ + if (L_spec < L_frame) + { + mvr2r(spectrum + 8, spectrum + 16, L_spec - 8); + mvr2r(spectrum + L_frame, spectrum + 8, 8); + mvr2r(spectrum + L_frame + 8, spectrum + L_spec + 8, L_spec - 8); + } + else + { + float buff[8]; /* Buffer for the rearrangement of LF TCX5 */ + mvr2r(spectrum + L_spec, buff, 8); + mvr2r(spectrum + 8, spectrum + 16, L_spec - 8); + mvr2r(buff, spectrum + 8, 8); + } + + return; +} + + +/*-------------------------------------------------------------------* + * tcx5TnsUngrouping() + * + * + *-------------------------------------------------------------------*/ + +void tcx5TnsUngrouping( + const int16_t L_frame, /* i : frame length (TCX5) */ + const int16_t L_spec, /* i : coded spec length (TCX5, derived from filter borders*/ + float* spectrum, + const int16_t enc_dec /* i : 0: encoder, else decoder */ +) +{ + /* undo rearrangement of LF sub-window lines prior to TNS analysis */ + if (L_spec < L_frame) + { + mvr2r(spectrum + L_spec + 8, spectrum + L_frame + 8, L_spec - 8); + mvr2r(spectrum + 8, spectrum + L_frame, 8); + mvr2r(spectrum + 16, spectrum + 8, L_spec - 8); + set_zero(spectrum + L_spec, L_frame - L_spec); + set_zero(spectrum + L_frame + L_spec, L_frame - L_spec); + } + else + { + float buff[8]; /* Buffer for the rearrangement of LF TCX5 */ + + mvr2r(spectrum + 8, buff, 8); + + if (enc_dec == ENC) + { + mvr2r(spectrum + 16, spectrum + 8, L_frame - 8); + mvr2r(buff, spectrum + L_frame, 8); + } + else + { + mvr2r(spectrum + 16, spectrum + 8, L_spec - 8); + mvr2r(buff, spectrum + L_spec, 8); + } + } + + return; +} +#endif diff --git a/lib_com/core_com_config_fx.c b/lib_com/core_com_config_fx.c index a287157..c5c5b02 100644 --- a/lib_com/core_com_config_fx.c +++ b/lib_com/core_com_config_fx.c @@ -2,43 +2,203 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include #include - +#include #include "options.h" -#include "stl.h" #include "basop_util.h" #include "prot_fx.h" #include "rom_com_fx.h" +#if 1//def IVAS_CODE_COM_CONFIG_P1 + + /*-------------------------------------------------------------------* + * is_EVS_bitrate() + * + * check if the bitrate is EVS supported active bitrate + *-------------------------------------------------------------------*/ -Word8 getTcxonly(const Word32 bitrate) + /*! r: flag indicating a valid bitrate */ +Word16 is_EVS_bitrate( + const Word32 ivas_total_brate, /* i : EVS total bitrate */ + Word16* Opt_AMR_WB /* i : AMR-WB IO flag */ +) { + Word16 j; - Word8 tcxonly; + j = 0; + while (j < SIZE_BRATE_TBL && ivas_total_brate != brate_tbl[j]) + { + j++; + } - tcxonly = 0; - move16(); - if( GT_32(bitrate,32000)) + /* AMR-WB IO mode/EVS primary mode determination */ + if (j >= SIZE_BRATE_TBL) { - tcxonly = 1; - move16(); + switch (ivas_total_brate) + { + case ACELP_6k60: + case ACELP_8k85: + case ACELP_12k65: + case ACELP_14k25: + case ACELP_15k85: + case ACELP_18k25: + case ACELP_19k85: + case ACELP_23k05: + case ACELP_23k85: + break; + default: + { + return 0; + } + break; + } + + *Opt_AMR_WB = 1; + } + else + { + *Opt_AMR_WB = 0; + } + + return 1; +} + + +/*-------------------------------------------------------------------* + * get_codec_mode() + * + * Get codec_mode (MODE1 or MODE2) + *-------------------------------------------------------------------*/ + + /*! r: codec mode */ +Word16 get_codec_mode( + const Word32 total_brate /* i : total bitrate */ +) +{ + Word16 codec_mode = -1; + + SWITCH (total_brate) + { + case 5900: + codec_mode = MODE1; move16(); + BREAK; + case 7200: + codec_mode = MODE1; move16(); + BREAK; + case 8000: + codec_mode = MODE1; move16(); + BREAK; + case 9600: + codec_mode = MODE2; move16(); + BREAK; + case 13200: + codec_mode = MODE1; move16(); + BREAK; + case 16400: + codec_mode = MODE2; move16(); + BREAK; + case 24400: + codec_mode = MODE2; move16(); + BREAK; + case 32000: + codec_mode = MODE1; move16(); + BREAK; + case 48000: + codec_mode = MODE2; move16(); + BREAK; + case 64000: + codec_mode = MODE1; move16(); + BREAK; + case 96000: + codec_mode = MODE2; move16(); + BREAK; + case 128000: + codec_mode = MODE2; move16(); + BREAK; } + return codec_mode; +} + +#endif + +Word16 getTcxonly( +#ifdef IVAS_CODE_SWITCHING + const Word16 element_mode, /* i : IVAS element mode */ +#endif + const Word32 total_brate /* i : total bitrate */ +#ifdef IVAS_CODE_SWITCHING + ,const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const int16_t is_ism_format /* i : flag indicating ISM format */ +#endif +) +{ + + Word16 tcxonly; + tcxonly = 0; + move16(); +#ifdef IVAS_CODE_SWITCHING + SWITCH(element_mode) + { + case EVS_MONO: +#endif + if (GT_32(total_brate, 32000)) + { + tcxonly = 1; + move16(); + } +#ifdef IVAS_CODE_SWITCHING + break; + case IVAS_SCE: + if (is_ism_format) + { + if (total_brate > MAX_ACELP_BRATE_ISM) + { + tcxonly = 1; + } + } + else + { + if (total_brate > MAX_ACELP_BRATE) + { + tcxonly = 1; + } + } + break; + + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if (total_brate > MAX_ACELP_BRATE) + { + tcxonly = 1; + } + break; + case IVAS_CPE_MDCT: + if (total_brate >= (MCT_flag ? IVAS_32k : IVAS_48k)) + { + tcxonly = 1; + } + break; +#endif return tcxonly; } -Word8 getCtxHm(const Word32 bitrate, const Word16 rf_flag) +Word8 getCtxHm( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_flag /* i : flag to signal the RF mode */ +) { Word8 ctx_hm; ctx_hm = 0; move16(); - test(); - if( (bitrate > LPC_SHAPED_ARI_MAX_RATE) && (bitrate <= 64000) && !rf_flag) + test(); test(); test(); test(); test(); test(); test(); test(); + if (((LE_16(element_mode, IVAS_SCE) && GT_32(total_brate, LPC_SHAPED_ARI_MAX_RATE)) || + (GT_16(element_mode, IVAS_SCE) && GT_32(total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE))) && !rf_flag && + ((LE_32(total_brate, IVAS_64k) && NE_16(element_mode, IVAS_CPE_DFT)) || + (LT_32(total_brate, IVAS_24k4) && EQ_16(element_mode, IVAS_CPE_DFT))) && NE_16(element_mode, IVAS_CPE_MDCT)) { ctx_hm = 1; @@ -50,14 +210,16 @@ Word8 getCtxHm(const Word32 bitrate, const Word16 rf_flag) } -Word8 getResq(const Word32 bitrate) +Word8 getResq( + const Word32 total_brate /* i : total bitrate */ +) { Word8 resq; resq = 0; move16(); - if (LE_32(bitrate,64000)) + if (LE_32(total_brate, IVAS_64k)) { resq = 1; move16(); @@ -67,17 +229,19 @@ Word8 getResq(const Word32 bitrate) } -Word8 getTnsAllowed(const Word32 bitrate - ,const Word16 igf - ) +Word16 getTnsAllowed( + const Word32 total_brate, /* i : total bitrate */ + const Word16 igf, /* i : flag indicating IGF activity*/ + const int16_t element_mode /* i : IVAS element mode */ +) { Word8 tnsAllowed; tnsAllowed = 0; move16(); - IF ( igf != 0 ) + IF(igf != 0) { - if( GT_32(bitrate, HQ_16k40)) + if (GT_32(total_brate, HQ_16k40) || (GT_32(total_brate, HQ_13k20) && EQ_16(element_mode, IVAS_CPE_DFT))) { tnsAllowed = 1; move16(); @@ -85,18 +249,21 @@ Word8 getTnsAllowed(const Word32 bitrate } ELSE { - if( GT_32(bitrate, HQ_32k)) + if (GT_32(total_brate, HQ_32k)) { tnsAllowed = 1; move16(); } } - return tnsAllowed; } -Word8 getRestrictedMode(const Word32 bitrate, const Word16 Opt_AMR_WB) +Word8 getRestrictedMode( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +) { Word8 restrictedMode; @@ -105,7 +272,12 @@ Word8 getRestrictedMode(const Word32 bitrate, const Word16 Opt_AMR_WB) move16(); test(); - IF ( (Opt_AMR_WB == 0) && (GT_32(bitrate,32000))) + IF ( (Opt_AMR_WB == 0) && (GT_32(total_brate, HQ_32k) && NE_16(element_mode, IVAS_SCE))) + { + restrictedMode = 6; + move16(); + } + ELSE IF (Opt_AMR_WB == 0 && (GT_32(total_brate, HQ_48k) && EQ_16(element_mode, IVAS_SCE))) { restrictedMode = 6; move16(); @@ -120,11 +292,13 @@ Word8 getRestrictedMode(const Word32 bitrate, const Word16 Opt_AMR_WB) } -Word16 sr2fscale(const Word32 sr) +Word16 sr2fscale( + const Word32 sr_core /* i : internal sampling rate */ +) { Word16 fscale; - SWITCH(sr) + SWITCH(sr_core) { case 8000: fscale = (FSCALE_DENOM*8000)/12800; @@ -164,45 +338,66 @@ Word16 sr2fscale(const Word32 sr) return fscale; } -Word32 getCoreSamplerateMode2(const Word32 bitrate, const Word16 bandwidth, const Word16 rf_mode) +Word32 getCoreSamplerateMode2( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ +) { Word32 sr_core; + Word16 bwd_swb_or_fb_flag; sr_core = -1; /* to suppress MSVC warning */ move32(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - - IF( EQ_32( bandwidth,NB)) + bwd_swb_or_fb_flag = s_or((Word16)EQ_16(bwidth, SWB), (Word16)EQ_16(bwidth, FB)); + test();test();test();test();test();test();test();test();test();test(); + test();test();test();test();test();test();test(); + test();test();test();test();test(); + IF( EQ_32( bwidth,NB)) { - sr_core = 12800; + sr_core = INT_FS_12k8; move32(); } + ELSE IF ( EQ_16(element_mode, EVS_MONO) && ( L_and(EQ_32(bwidth,WB),LT_32(total_brate, ACELP_13k20))|| + L_and(EQ_32(bwidth,SWB), LE_32(total_brate, ACELP_13k20)) || EQ_16(rf_mode,1) ) ) - ELSE IF ( L_and(EQ_32(bandwidth,WB),LT_32(bitrate,13200))|| - L_and(EQ_32(bandwidth,SWB), LE_32(bitrate,13200)) || EQ_16(rf_mode,1) ) - { - sr_core = 12800; + sr_core = INT_FS_12k8; + move32(); + } + ELSE IF (GT_16(element_mode, EVS_MONO) && flag_ACELP16k == 0) + { + sr_core = INT_FS_12k8; + move32(); + } + ELSE IF (EQ_32(bwidth,WB)||((LE_32(total_brate, ACELP_32k))&&((EQ_32(bwidth,SWB))||(EQ_32(bwidth,FB))))) + { + sr_core = INT_FS_16k; move32(); } - ELSE IF (EQ_32(bandwidth,WB)||((LE_32(bitrate,32000))&&((EQ_32(bandwidth,SWB))||(EQ_32(bandwidth,FB))))) + ELSE IF (bwd_swb_or_fb_flag && LE_32(total_brate, MAX_ACELP_BRATE) && EQ_16(element_mode, IVAS_SCE) && !is_ism_format) { - sr_core = 16000; + sr_core = INT_FS_16k; move32(); } - ELSE IF ( ((EQ_32(bandwidth,SWB))||(EQ_32(bandwidth,FB)))&&(LE_32(bitrate,64000))) + ELSE IF (bwd_swb_or_fb_flag && LE_32(total_brate, MAX_ACELP_BRATE_ISM) && EQ_16(element_mode, IVAS_SCE) && is_ism_format) + { + sr_core = INT_FS_16k; + } + else if (bwd_swb_or_fb_flag && LE_32(total_brate, MAX_ACELP_BRATE) && EQ_16(element_mode, IVAS_SCE) && is_ism_format) + { + sr_core = 25600; + } + ELSE IF ( (EQ_16(element_mode, EVS_MONO) && (bwd_swb_or_fb_flag && LE_32(total_brate, HQ_64k))) + || (GT_16(element_mode, IVAS_SCE) && ((EQ_16(bwidth, SWB) && LE_32(total_brate, IVAS_96k)) || (EQ_16(bwidth, FB) && LE_32(total_brate, IVAS_96k))))) { sr_core = 25600; move32(); } - ELSE IF (EQ_32(bandwidth,SWB)||EQ_32(bandwidth,FB)) + ELSE IF (bwd_swb_or_fb_flag) { sr_core = 32000; move32(); @@ -215,14 +410,16 @@ Word32 getCoreSamplerateMode2(const Word32 bitrate, const Word16 bandwidth, cons return sr_core; } -Word16 getTcxBandwidth(const Word16 bandwidth) +Word16 getTcxBandwidth( + const Word16 bwidth /* i : audio bandwidth */ +) { Word16 tcxBandwidth; tcxBandwidth = 16384/*0.5f Q15*/; move16(); - if(EQ_16(bandwidth, NB)) + if(EQ_16(bwidth, NB)) { tcxBandwidth = 10240/*0.3125f Q15*/; move16(); @@ -231,12 +428,17 @@ Word16 getTcxBandwidth(const Word16 bandwidth) return tcxBandwidth; } - - -Word8 getIgfPresent( - const Word32 bitrate, - const Word16 bandwidth - ,const Word16 rf_mode +/*-------------------------------------------------------------------* + * getIgfPresent() + * + * + *-------------------------------------------------------------------*/ + +Word16 getIgfPresent( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ) { Word8 igfPresent; @@ -244,32 +446,91 @@ Word8 getIgfPresent( igfPresent = 0; move16(); - test(); - test(); - if( (EQ_16(bandwidth, SWB))&&(GE_32(bitrate,ACELP_9k60))&&(LT_32(bitrate,HQ_64k))) + IF (EQ_16(bwidth, SWB)) { - igfPresent = 1; - move16(); + SWITCH (element_mode) + { + case EVS_MONO: + case IVAS_SCE: + if (LE_32(total_brate, HQ_64k)) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if (LE_32(total_brate, HQ_48k)) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_MDCT: + if (LE_32(total_brate, IVAS_96k)) + { + igfPresent = 1; + move16(); + } + BREAK; + } } - - test(); - if( EQ_16(bandwidth, FB)&&(GE_32(bitrate,ACELP_16k40))) + else if (bwidth == FB) { - igfPresent = 1; - move16(); + SWITCH(element_mode) + { + case EVS_MONO: + case IVAS_SCE: + if (LE_32(total_brate, IVAS_128k)) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if (LE_32(total_brate, HQ_48k)) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_MDCT: + if (LE_32(total_brate, IVAS_128k)) + { + igfPresent = 1; + move16(); + } + BREAK; + } } - - test(); - if( (EQ_16(bandwidth, WB))&&(EQ_32(bitrate,ACELP_9k60))) + else if (bwidth == WB) { - igfPresent = 1; - move16(); + SWITCH(element_mode) + { + case EVS_MONO: + case IVAS_SCE: + if (LE_32(total_brate, ACELP_9k60)) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + case IVAS_CPE_MDCT: + if (LE_32(total_brate, ACELP_13k20)) + { + igfPresent = 1; + move16(); + } + BREAK; + } } - test(); test(); test(); - if( ((EQ_16(bandwidth, WB))||(EQ_16(bandwidth,SWB)))&&(EQ_16(rf_mode,1))&&(EQ_32(bitrate,ACELP_13k20))) + if (((EQ_16(bwidth, WB)) || (EQ_16(bwidth, SWB))) && (EQ_16(rf_mode, 1)) && (EQ_32(total_brate, ACELP_13k20))) { igfPresent = 1; move16(); @@ -279,40 +540,37 @@ Word8 getIgfPresent( } -Word8 getCnaPresent( - const Word32 bitrate, - const Word16 bandwidth +Word16 getCnaPresent( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth /* i : audio bandwidth */ ) { Word8 flag_cna = 0; flag_cna = 0; - move16(); - test(); - if( EQ_16(bandwidth, NB)&&(LE_32(bitrate,ACELP_13k20))) + IF (EQ_16(element_mode, IVAS_CPE_DFT) && LE_32(element_brate, CNA_MAX_BRATE_DFT_STEREO)) { flag_cna = 1; - move16(); - } - - test(); - if( (EQ_16(bandwidth, WB))&&(LE_32(bitrate,ACELP_13k20))) - { - flag_cna = 1; - move16(); } - - test(); - if( (EQ_16(bandwidth, SWB))&&(LE_32(bitrate,ACELP_13k20))) + ELSE { - flag_cna = 1; move16(); + test(); + if (LE_16(bwidth, SWB) && (LE_32(total_brate, ACELP_13k20))) + { + flag_cna = 1; + move16(); + } } return flag_cna; } -Word8 getTcxLtp(const Word32 sr_core) +Word8 getTcxLtp( + const Word32 sr_core /* i : internal sampling rate */ +) { Word8 tcxltp = 0; @@ -342,7 +600,7 @@ Word16 initPitchLagParameters( Word16 pit_res_max; - IF (EQ_32(sr_core, 12800)) + IF (EQ_32(sr_core, INT_FS_12k8)) { *pit_min = PIT_MIN_12k8; @@ -359,7 +617,7 @@ Word16 initPitchLagParameters( move16(); } - ELSE IF (EQ_32(sr_core, 16000)) + ELSE IF (EQ_32(sr_core, INT_FS_16k)) { *pit_min = PIT_MIN_16k; @@ -413,7 +671,9 @@ Word16 initPitchLagParameters( return pit_res_max; } -Word16 getNumTcxCodedLines(const Word16 bwidth) +Word16 getNumTcxCodedLines( + const Word16 bwidth /* i : audio bandwidth */ +) { Word16 tcx_coded_lines; @@ -449,18 +709,17 @@ Word16 getNumTcxCodedLines(const Word16 bwidth) } Word16 getTcxLpcShapedAri( - const Word32 total_brate, - const Word16 bwidth - ,const Word16 rf_mode + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const Word16 element_mode /* i : IVAS element mode */ ) { Word16 tcx_lpc_shaped_ari = 0; move16(); - - (void) bwidth; - - test(); - if( (LE_32(total_brate, LPC_SHAPED_ARI_MAX_RATE))||rf_mode) + test(); test(); test(); + if (((LE_16(element_mode, IVAS_SCE) && LE_32(total_brate, LPC_SHAPED_ARI_MAX_RATE)) || + (GT_16(element_mode, IVAS_SCE) && LE_32(total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE))) || + rf_mode) { tcx_lpc_shaped_ari = 1; move16(); @@ -469,3 +728,236 @@ Word16 getTcxLpcShapedAri( return tcx_lpc_shaped_ari; } +#ifdef IVAS_CODE_COM_CONFIG_P1 +/*-----------------------------------------------------------------------* + * init_tcx_window_cfg() + * + * Initialization of TCX windows + *-----------------------------------------------------------------------*/ + +void init_tcx_window_cfg( + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ + const int32_t sr_core, /* i : SR core */ + const int32_t input_Fs, /* i : input/output SR */ + const int16_t L_frame, /* i : L_frame at sr_core */ + const int16_t L_frameTCX, /* i : L_frame at i/o SR */ + const int16_t encoderLookahead_enc, /* i : encoder LA at sr_core */ + const int16_t encoderLookahead_FB, /* i : encoder LA at i/o SR */ + const int16_t mdctWindowLength, /* i : window length at sr_core */ + const int16_t mdctWindowLengthFB, /* i : window length at i/o SR */ + const int16_t element_mode /* i : mode of CPE/SCE */ +) +{ + /* Symmetric window = sine LD window*/ + hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; + hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; + hTcxCfg->tcx_mdct_window_length = mdctWindowLength; + hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; + + mdct_window_sine(hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode); + if (hTcxCfg->tcx_mdct_window_length == hTcxCfg->tcx_mdct_window_lengthFB) + { + mvr2r(hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, hTcxCfg->tcx_mdct_window_length); + } + else + { + mdct_window_sine(hTcxCfg->tcx_mdct_windowFB, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode); + } + + /*ALDO windows for MODE2*/ + mdct_window_aldo(hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_2, L_frame); + mdct_window_aldo(hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_2_FB, NS2SA(input_Fs, FRAME_SIZE_NS)); + hTcxCfg->tcx_aldo_window_1_trunc = hTcxCfg->tcx_aldo_window_1 + NS2SA(sr_core, N_ZERO_MDCT_NS); + hTcxCfg->tcx_aldo_window_1_FB_trunc = hTcxCfg->tcx_aldo_window_1_FB + NS2SA(input_Fs, N_ZERO_MDCT_NS); + + /*1.25ms transition window for ACELP->TCX*/ + hTcxCfg->tcx_mdct_window_trans_length = NS2SA(sr_core, ACELP_TCX_TRANS_NS); + mdct_window_sine(hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA(input_Fs, ACELP_TCX_TRANS_NS); + if (hTcxCfg->tcx_mdct_window_trans_length == hTcxCfg->tcx_mdct_window_trans_lengthFB) + { + mvr2r(hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_length); + } + else + { + mdct_window_sine(hTcxCfg->tcx_mdct_window_transFB, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode); + } + + /*Mid-OLA*/ + /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ + hTcxCfg->tcx_mdct_window_half_length = 2 * ((encoderLookahead_enc - (int16_t)(0.005f * sr_core + 0.5f)) >> 1); + hTcxCfg->tcx_mdct_window_half_lengthFB = 2 * ((encoderLookahead_FB - (int16_t)(0.005f * input_Fs + 0.5f)) >> 1); + assert((hTcxCfg->tcx_mdct_window_half_length > 16) && "Half window can not be large enough!"); + + mdct_window_sine(hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode); + if (hTcxCfg->tcx_mdct_window_half_length == hTcxCfg->tcx_mdct_window_half_lengthFB) + { + mvr2r(hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_half_length); + } + else + { + mdct_window_sine(hTcxCfg->tcx_mdct_window_halfFB, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode); + } + + /* minimum overlap 1.25 ms */ + hTcxCfg->tcx_mdct_window_min_length = (int16_t)(sr_core * INV_CLDFB_BANDWIDTH); + hTcxCfg->tcx_mdct_window_min_lengthFB = (int16_t)(input_Fs * INV_CLDFB_BANDWIDTH); + /* save complexity by copying the small windows if they have the same length */ + if (hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_trans_length) + { + mvr2r(hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length); + } + else + { + mdct_window_sine(hTcxCfg->tcx_mdct_window_minimum, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode); + } + + if (hTcxCfg->tcx_mdct_window_min_lengthFB == hTcxCfg->tcx_mdct_window_trans_lengthFB) + { + mvr2r(hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB); + } + else if (hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_min_lengthFB) + { + mvr2r(hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB); + } + else + { + mdct_window_sine(hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode); + } + + /* TCX Offset */ + hTcxCfg->tcx_offset = (hTcxCfg->tcx_mdct_window_delay >> 1); + hTcxCfg->tcx_offsetFB = (hTcxCfg->tcx_mdct_window_delayFB >> 1); + /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ + hTcxCfg->lfacNext = hTcxCfg->tcx_offset - L_frame / 4; + hTcxCfg->lfacNextFB = hTcxCfg->tcx_offsetFB - L_frameTCX / 4; + + return; +} + +/*-----------------------------------------------------------------------* + * init_tcx() + * + * Initialization of TCX + *-----------------------------------------------------------------------*/ + +void init_tcx_cfg( + TCX_CONFIG_HANDLE hTcxCfg, + const int32_t total_brate, + const int32_t sr_core, + const int32_t input_Fs, + const int16_t L_frame, + const int16_t bwidth, + const int16_t L_frameTCX, + const int16_t fscale, + const int16_t encoderLookahead_enc, + const int16_t encoderLookahead_FB, + const float preemph_fac, + const int16_t tcxonly, + const int16_t rf_mode, + const int16_t igf, + const int16_t infoIGFStopFreq, + const int16_t element_mode, + const int16_t ini_frame, + const int16_t is_mct +) +{ + int16_t i; + int16_t mdctWindowLength; + int16_t mdctWindowLengthFB; + int16_t na_scale_bwidth; + + hTcxCfg->preemph_fac = preemph_fac; + hTcxCfg->tcx5Size = NS2SA(sr_core, FRAME_SIZE_NS / 4); /* Always 5 ms */ + hTcxCfg->tcx5SizeFB = NS2SA(input_Fs, FRAME_SIZE_NS / 4); /* Always 5 ms */ + + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + mdctWindowLength = getMdctWindowLength(fscale); + mdctWindowLengthFB = (int16_t)(mdctWindowLength * input_Fs / sr_core); + + init_tcx_window_cfg(hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode); + + /* SQ deadzone & memory quantization*/ + hTcxCfg->sq_rounding = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ + + /* TCX rate loop */ + hTcxCfg->tcxRateLoopOpt = (tcxonly) ? 2 : 0; + hTcxCfg->tcxRateLoopOpt = (element_mode == IVAS_CPE_MDCT) ? 3 : hTcxCfg->tcxRateLoopOpt; + + /* TCX bandwidth */ + hTcxCfg->bandwidth = getTcxBandwidth(bwidth); + + /* set number of coded lines */ + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(bwidth); + + /* TNS in TCX */ + hTcxCfg->pCurrentTnsConfig = NULL; + hTcxCfg->fIsTNSAllowed = getTnsAllowed(total_brate, igf, element_mode); + + if (hTcxCfg->fIsTNSAllowed) + { + InitTnsConfigs(bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, is_mct); + + SetAllowTnsOnWhite(hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT); + } + + if (ini_frame == 0) + { + hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + hTcxCfg->last_aldo = 1; + } + + /* Context HM*/ + hTcxCfg->ctx_hm = getCtxHm(element_mode, total_brate, rf_mode); + + /* Residual Coding*/ + hTcxCfg->resq = getResq(total_brate); + hTcxCfg->tcxRateLoopOpt = (hTcxCfg->resq && !tcxonly) ? 1 : hTcxCfg->tcxRateLoopOpt; + + /*Set bandwidth scale*/ + if (bwidth == NB) + { + na_scale_bwidth = NB; + } + else if (sr_core <= INT_FS_16k) + { + na_scale_bwidth = WB; + } + else + { + na_scale_bwidth = SWB; + } + + /* Scale TCX for non-active frames to adjust loudness with ACELP*/ + hTcxCfg->na_scale = 1.f; + + if (na_scale_bwidth < SWB && !tcxonly) + { + for (i = 0; i < SIZE_SCALE_TABLE_TCX; i++) + { + if ((na_scale_bwidth == scaleTcxTable[i].bwmode) && + (total_brate >= scaleTcxTable[i].bitrateFrom) && + (total_brate < scaleTcxTable[i].bitrateTo)) + { + if (rf_mode) + { + i--; + } + hTcxCfg->na_scale = scaleTcxTable[i].scale; + break; + } + } + } + + if (tcxonly) + { + InitPsychLPC(sr_core, L_frame, hTcxCfg); + } + else + { + hTcxCfg->psychParamsCurrent = NULL; + } + + return; +} +#endif \ No newline at end of file diff --git a/lib_com/deemph_fx.c b/lib_com/deemph_fx.c index 56e32fc..5b2f5ae 100644 --- a/lib_com/deemph_fx.c +++ b/lib_com/deemph_fx.c @@ -1,10 +1,9 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_util.h" /*========================================================================*/ diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index f67b752..52962fe 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -2,40 +2,91 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "prot_fx.h" +#include "ivas_cnst.h" /*-------------------------------------------------------------------------- * get_delay_fx() * -* Function returns various types of delays in the codec in ms. +* Function returns various types of delays in the codec in ns. *--------------------------------------------------------------------------*/ -Word32 get_delay_fx( /* o : delay value in ms */ - const Word16 what_delay, /* i : what delay? (ENC or DEC) */ - const Word32 io_fs /* i : input/output sampling frequency */ +Word32 get_delay_fx( /* o : delay value in ms */ + const Word16 what_delay, /* i : what delay? (ENC or DEC) */ + const Word32 io_fs, /* i : input/output sampling frequency */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + , + const AUDIO_CONFIG output_config /* i : decoder output config */ +#endif ) { - Word32 delay = 0; + Word32 delay = 0; IF( EQ_16(what_delay,ENC)) { - delay = (DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS); - move32(); + IF (EQ_16(ivas_format, MONO_FORMAT)) /* EVS mono */ + { + delay = (DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS); + move32(); + } + ELSE + { + delay = IVAS_ENC_DELAY_NS; + test(); + IF (EQ_16(ivas_format, MASA_FORMAT) || EQ_16(ivas_format, MASA_ISM_FORMAT) ) + { + delay = 0; /* All delay is compensated in the decoder with MASA */ + } + } + test(); + IF (EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) + { + /* compensate for DirAC/SPAR filterbank delay */ + delay += IVAS_FB_ENC_DELAY_NS; + } } ELSE { - IF( EQ_32(io_fs,8000)) + IF (EQ_16(ivas_format, MONO_FORMAT)) /* EVS mono */ { - delay = DELAY_CLDFB_NS; - move32(); + IF(EQ_32(io_fs,8000)) + { + delay = DELAY_CLDFB_NS; + move32(); + } + ELSE + { + delay = DELAY_BWE_TOTAL_NS; + move32(); + } } - ELSE + ELSE /* IVAS */ { - delay = DELAY_BWE_TOTAL_NS; - move32(); + delay = IVAS_DEC_DELAY_NS; + +#ifdef SPLIT_REND_WITH_HEAD_ROT + + IF (NE_16(output_config, AUDIO_CONFIG_BINAURAL_SPLIT_CODED)) + { +#endif + IF (hCldfb != NULL) + { + /* compensate for filterbank delay */ + delay += IVAS_FB_DEC_DELAY_NS; + } +#ifdef SPLIT_REND_WITH_HEAD_ROT + } +#endif + test(); + IF (EQ_16(ivas_format, MASA_FORMAT) || EQ_16(ivas_format, MASA_ISM_FORMAT) ) + { + delay += IVAS_ENC_DELAY_NS; /* Compensate also the encoder delay in the decoder with MASA */ + } } } diff --git a/lib_com/dlpc_bfi.c b/lib_com/dlpc_bfi.c index 4271e1c..7b79911 100644 --- a/lib_com/dlpc_bfi.c +++ b/lib_com/dlpc_bfi.c @@ -4,24 +4,22 @@ /* Header files */ -#include -#include -#include +#include +#include "options.h" #include "prot_fx.h" -#include "stl.h" #include "prot_fx.h" void dlpc_bfi( const Word16 L_frame, Word16 *lsf_q, /* o : quantized LSFs */ - const Word16 *lsfold, /* i : past quantized LSF */ - const Word16 last_good, /* i : last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ + const Word16 *lsfold, /* i : past quantized LSF */ + const Word16 last_good, /* i : last good received frame */ + const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ Word16 mem_MA[], /* i/o: quantizer memory for MA model */ Word16 mem_AR[], /* i/o: quantizer memory for AR model */ Word16 *stab_fac, /* i : LSF stability factor */ Word16 *lsf_adaptive_mean,/* i : LSF adaptive mean, updated when BFI==0 */ - Word16 numlpc, /* i : Number of division per superframe */ + Word16 numlpc, /* i : Number of division per superframe */ Word16 lsf_cng[], Word8 plcBackgroundNoiseUpdated, Word16 *lsf_q_cng, /* o : quantized LSFs */ @@ -31,24 +29,14 @@ void dlpc_bfi( ) { - lsf_dec_bfi( - MODE2, - &lsf_q[0], lsfold, lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, - 0, L_frame, last_good, nbLostCmpt, - plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly - ,0 + lsf_dec_bfi(MODE2, &lsf_q[0], lsfold, lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, + 0, L_frame, last_good, nbLostCmpt, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0); - ); IF ( EQ_16(numlpc,2)) { /* Decode the second LPC */ - lsf_dec_bfi( - MODE2, - &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, - 0, L_frame, last_good, nbLostCmpt+1, - plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly - ,0 - ); + lsf_dec_bfi(MODE2, &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, + 0, L_frame, last_good, nbLostCmpt+1, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0); } /**/ /*No local variabvles defined*/ } diff --git a/lib_com/edct_fx.c b/lib_com/edct_fx.c index f45a54f..685f62b 100644 --- a/lib_com/edct_fx.c +++ b/lib_com/edct_fx.c @@ -209,7 +209,6 @@ void edst_fx( return; } - /*========================================================================*/ /* FUNCTION : edct_fx() */ /*------------------------------------------------------------------------*/ @@ -231,10 +230,12 @@ void edst_fx( /* _ None */ /*========================================================================*/ void edct_16fx( - const Word16 *x, /* i : input signal Qx */ - Word16 *y, /* o : output transform Qx */ - Word16 length, /* i : length */ - Word16 bh /* bit-headroom */ + const Word16 *x, /* i : input signal Qx */ + Word16 *y, /* o : output transform Qx */ + Word16 length, /* i : length */ + Word16 bh, /* bit-headroom */ + const Word16 element_mode + ) { Word16 i; @@ -250,7 +251,9 @@ void edct_16fx( Word16 Len2, i2; const Word16 *px, *pt; Word16 *py; - +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(element_mode) +#endif /*COMPLETE: some eDCT sub function are missing */ IF (EQ_16(length,L_FRAME32k)) diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 81b8097..9f74f57 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" #include "basop_util.h" /*---------------------------------------------------------------------* @@ -125,6 +124,7 @@ void enhancer_fx( move16(); /* low dispersion */ } } + phase_dispersion_fx(norm_gain_code, gain_pit, code, i, dm_fx); /*------------------------------------------------------------ diff --git a/lib_com/enr_1_az_fx.c b/lib_com/enr_1_az_fx.c index 47f6c0e..6a608f6 100644 --- a/lib_com/enr_1_az_fx.c +++ b/lib_com/enr_1_az_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Enr_1_Az_fx_12Q3() diff --git a/lib_com/env_adj_fx.c b/lib_com/env_adj_fx.c index 1ad3c62..897c3e1 100644 --- a/lib_com/env_adj_fx.c +++ b/lib_com/env_adj_fx.c @@ -1,7 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ @@ -18,7 +18,7 @@ void env_adj_fx const Word16 *pulses, /* i : number of pulses per band Q0 */ const Word16 length, /* i : length of spectrum Q0 */ const Word16 last_sfm, /* i : index of the last band Q0 */ - Word16 *adj, /* o : adjustment factors for the envelope Q15 */ + Word16 *adj, /* o : adjustment factors for the envelope Q15 */ const Word16 env_stab, /* i : envelope stability Q15 */ const Word16 *sfmsize /* i : subband sizes Q0 */ ) diff --git a/lib_com/env_stab_fx.c b/lib_com/env_stab_fx.c index e3e8c63..f9ec7d4 100644 --- a/lib_com/env_stab_fx.c +++ b/lib_com/env_stab_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required by wmc_tool */ +#include +#include "options.h" /* Compilation switches */ +#include "cnst_fx.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ /*--------------------------------------------------------------------------* * Local constants @@ -20,11 +19,12 @@ /* Envelope stability measure */ /*--------------------------------------------------------------------------*/ -Word16 env_stability_fx( /* in Q15 */ - const Word16 *ynrm, /*i: Norm vector for current frame */ - const Word16 nb_sfm, /*i: Number of sub-bands */ - Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ - Word16 *mem_env_delta /*i/o: Envelope stability memory for smoothing in Q12 */ +Word16 env_stability_fx( /* in Q15 */ + const Word16* ynrm, /*i: Norm vector for current frame */ + const Word16 nb_sfm, /*i: Number of sub-bands */ + Word16* mem_norm, /*i/o: Norm vector memory from past frame */ + Word16* mem_env_delta, /*i/o: Envelope stability memory for smoothing in Q12 */ + const Word16 core_switching_flag/* i : Core switching flag */ ) { Word16 env_delta; @@ -36,43 +36,54 @@ Word16 env_stability_fx( /* in Q15 */ Word32 L_tmp, L_env_delta; Word16 inv_nb_sfm; - /* Calculate envelope stability parameter */ - L_env_delta = L_deposit_l(0); - FOR (i = 0; i < nb_sfm; i++) + IF (core_switching_flag) { - tmp = sub(mem_norm[i],ynrm[i]); - L_env_delta = L_mac0(L_env_delta, tmp, tmp); - mem_norm[i] = ynrm[i]; - move16(); + FOR (i = 0; i < nb_sfm; i++) + { + mem_norm[i] = ynrm[i]; move16(); + } + Overflow = 0; move16(); + env_delta = shl(*mem_env_delta, 1); } - - inv_nb_sfm = 19418; /* Q19 */ move16(); - if (nb_sfm == 26) + ELSE { - inv_nb_sfm = 20165; /* Q19 */ move16(); - } - exp = norm_l(L_env_delta); - L_env_delta = Mult_32_16(L_shl(L_env_delta, exp), inv_nb_sfm); /* 0+exp+19-15 */ + /* Calculate envelope stability parameter */ + L_env_delta = L_deposit_l(0); + FOR(i = 0; i < nb_sfm; i++) + { + tmp = sub(mem_norm[i], ynrm[i]); + L_env_delta = L_mac0(L_env_delta, tmp, tmp); + mem_norm[i] = ynrm[i]; + move16(); + } - L_tmp = Sqrt_l(L_env_delta, &exp2); /* exp+4+31+exp2 */ + inv_nb_sfm = 19418; /* Q19 */ move16(); + if (nb_sfm == 26) + { + inv_nb_sfm = 20165; /* Q19 */ move16(); + } + exp = norm_l(L_env_delta); + L_env_delta = Mult_32_16(L_shl(L_env_delta, exp), inv_nb_sfm); /* 0+exp+19-15 */ - exp = add(35, add(exp, exp2)); - if ( EQ_16(s_and(exp, 1), 1)) - { - L_tmp = Mult_32_16(L_tmp, 23170); /* 1/sqrt(2) in Q15 */ - } - exp = shr(exp, 1); + L_tmp = Sqrt_l(L_env_delta, &exp2); /* exp+4+31+exp2 */ - env_delta = round_fx(L_shl(L_tmp, sub(26, exp))); /* Q10 */ + exp = add(35, add(exp, exp2)); + if (EQ_16(s_and(exp, 1), 1)) + { + L_tmp = Mult_32_16(L_tmp, 23170); /* 1/sqrt(2) in Q15 */ + } + exp = shr(exp, 1); - L_tmp = L_mult0(26214, env_delta); /* 26214 is 0.1 in Q18. Q28 */ - L_tmp = L_mac(L_tmp, 29491, *mem_env_delta); /* 29491 is 0.9 in Q15. Q28 */ + env_delta = round_fx(L_shl(L_tmp, sub(26, exp))); /* Q10 */ - *mem_env_delta = round_fx(L_tmp); /* Q12 */ - Overflow = 0; - move16(); - env_delta = round_fx(L_shl(L_tmp, 1)); /* Q13 */ + L_tmp = L_mult0(26214, env_delta); /* 26214 is 0.1 in Q18. Q28 */ + L_tmp = L_mac(L_tmp, 29491, *mem_env_delta); /* 29491 is 0.9 in Q15. Q28 */ + *mem_env_delta = round_fx(L_tmp); /* Q12 */ + Overflow = 0; + move16(); + env_delta = round_fx(L_shl(L_tmp, 1)); /* Q13 */ + } IF (Overflow != 0) /* Saturated due to the above up-shifting operation. */ { return stab_trans_fx[L_STAB_TBL-1]; /* The highest quantized index. */ diff --git a/lib_com/env_stab_trans_fx.c b/lib_com/env_stab_trans_fx.c index 6e86bca..da31fc7 100644 --- a/lib_com/env_stab_trans_fx.c +++ b/lib_com/env_stab_trans_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "math_op.h" /* WMOPS macros */ -#include "stl.h" /* required by wmc_tool */ /*--------------------------------------------------------------------------* * env_stab_transient_detect() @@ -16,15 +15,15 @@ *--------------------------------------------------------------------------*/ void env_stab_transient_detect_fx( - const Word16 is_transient, /* i: Transient flag */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ - const Word16 norm[], /* i : quantization indices for norms */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ - const Word16 HQ_mode, /* i : HQ coding mode */ - const Word16 bin_th, /* i : HVQ cross-over frequency bin */ - const Word32 *L_coeff, /* i : Coded spectral coefficients */ - const Word16 Qcoeff /* i : Q of coded spectral coefficients */ + const Word16 is_transient, /* i: Transient flag */ + const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ + const Word16 norm[], /* i : quantization indices for norms */ + Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ + Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ + const Word16 HQ_mode, /* i : HQ coding mode */ + const Word16 bin_th, /* i : HVQ cross-over frequency bin */ + const Word32 *L_coeff, /* i : Coded spectral coefficients */ + const Word16 Qcoeff /* i : Q of coded spectral coefficients */ ) { Word16 i, blk, norm_ind, sqrt_exp, bin_th_1, temp, sh; diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 07a7ac0..3fcb1ac 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -34,19 +34,24 @@ /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ -Word16 est_tilt_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +Word16 est_tilt_fx( /* o : tilt of the code Q15 */ + const Word16 *exc, /* i : adaptive excitation vector Qx */ + const Word16 gain_pit, /* i : adaptive gain Q14 */ + const Word16 *code, /* i : algebraic excitation vector Q9 */ + const Word32 gain_code, /* i : algebraic code gain Q16 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +#ifdef ADD_LRTD + ,const Word16 L_subfr /* i : Sub frame length */ +#endif ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; Word32 L_tmp; Word16 tilt_code; - +#ifdef ADD_LRTD + PMT("FIX POINT NEED to be adapted for 16 kHz frame length ") +#endif ener1 = extract_h(Dot_product12(exc, exc, L_SUBFR, &exp1)); exp1 = sub(exp1, add(Q_exc, Q_exc)); L_tmp = L_mult(gain_pit, gain_pit); /* energy of pitch excitation */ diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 400a41d..7432d05 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -3,130 +3,152 @@ ====================================================================================*/ #include -#include "stl.h" +#include +#include "options.h" #include "basop_util.h" #include "options.h" -#include "stl.h" #include "rom_basop_util.h" #include "rom_com_fx.h" #include "prot_fx.h" #define DELTA_SHIFT 2 #define DELTA_SHIFT_LD64 67108864l/*DELTA_SHIFT/64.0 Q31*/ +#define CNG_HS 4 /* 4 bit headroom for dot product */ +#define CNG_S 6 /* 1 sign bit, 6 bit integer part, 9 bit frational part for input and output data */ - - -/***************************************** -* Create an instance of type FD_CNG_COM * -*****************************************/ -void createFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom) + /*------------------------------------------------------------------- + * Local function prototypes + *-------------------------------------------------------------------*/ +static void getmidbands(const Word16* part, const Word16 npart, Word16* midband, Word16* psize, + Word16* psize_norm, Word16* psize_norm_exp, Word16* psize_inv); + + + + /*------------------------------------------------------------------- + * createFdCngCom() + * + * Create an instance of type FD_CNG_COM + *-------------------------------------------------------------------*/ +ivas_error createFdCngCom( + HANDLE_FD_CNG_COM * hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +) { HANDLE_FD_CNG_COM hs; /* Allocate memory */ - hs = (HANDLE_FD_CNG_COM) calloc(1, sizeof (FD_CNG_COM)); - move16(); + hs = (HANDLE_FD_CNG_COM)count_malloc(sizeof(FD_CNG_COM)); + if (hs == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD CNG COM"); + } *hFdCngCom = hs; - move16(); - return; + + return IVAS_ERR_OK; } +/*------------------------------------------------------------------- + * initFdCngCom() + * + * + *-------------------------------------------------------------------*/ -void initFdCngCom(HANDLE_FD_CNG_COM hs, Word16 scale) +void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) { /* Calculate CLDFB scaling factor */ /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ - /*hs->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ + /*hFdCngCom->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ assert(2048/*1.0/(1<<4) Q15*/ < mult(scale, scale)); /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ - hs->invScalingFactor = shl(mult(scale,scale),1); + hFdCngCom->invScalingFactor = shl(mult(scale,scale),1); /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ - hs->scalingFactor = div_s(0x4000,hs->invScalingFactor); + hFdCngCom->scalingFactor = div_s(0x4000,hFdCngCom->invScalingFactor); /* Initialize the overlap-add */ - set16_fx( hs->timeDomainBuffer, 0, L_FRAME16k ); - hs->olapBufferAna = NULL; + set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k ); + hFdCngCom->olapBufferAna = NULL; move16(); - set16_fx( hs->olapBufferSynth, 0, FFTLEN ); - hs->olapBufferSynth2 = NULL; + set16_fx( hFdCngCom->olapBufferSynth, 0, FFTLEN ); + hFdCngCom->olapBufferSynth2 = NULL; move16(); /* Initialize the comfort noise generation */ - set32_fx( hs->fftBuffer, 0, FFTLEN ); - set32_fx( hs->cngNoiseLevel, 0, FFTCLDFBLEN ); + set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN ); + set32_fx( hFdCngCom->cngNoiseLevel, 0, FFTCLDFBLEN ); /* Initialize quantizer */ - set32_fx( hs->sidNoiseEst, 0, NPART ); - set16_fx( hs->A_cng, 0, M+1 ); - hs->A_cng[0] = 4096/*1.f Q12*/; /* 3Q12 */ move16(); + set32_fx( hFdCngCom->sidNoiseEst, 0, NPART ); + set16_fx( hFdCngCom->A_cng, 0, M+1 ); + hFdCngCom->A_cng[0] = 4096/*1.f Q12*/; /* 3Q12 */ move16(); /* Set some counters and flags */ - hs->inactive_frame_counter = 0; /* Either SID or zero frames */ move16(); - hs->active_frame_counter = 0; + hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ move16(); + hFdCngCom->active_frame_counter = 0; move16(); - hs->frame_type_previous = ACTIVE_FRAME; + hFdCngCom->frame_type_previous = ACTIVE_FRAME; move16(); - hs->flag_noisy_speech = 0; + hFdCngCom->flag_noisy_speech = 0; move16(); - hs->likelihood_noisy_speech = 0; + hFdCngCom->likelihood_noisy_speech = 0; move16(); - hs->numCoreBands = 0; + hFdCngCom->numCoreBands = 0; move16(); - hs->stopBand = 0; + hFdCngCom->stopBand = 0; move16(); - hs->startBand = 0; + hFdCngCom->startBand = 0; move16(); - hs->stopFFTbin = 0; + hFdCngCom->stopFFTbin = 0; move16(); - hs->frameSize = 0; + hFdCngCom->frameSize = 0; move16(); - hs->fftlen = 0; + hFdCngCom->fftlen = 0; move16(); /* Initialize noise estimation algorithm */ - set32_fx( hs->periodog, 0, PERIODOGLEN ); - mhvals(MSNUMSUBFR*MSSUBFRLEN, &(hs->msM_win)); - mhvals(MSSUBFRLEN, &(hs->msM_subwin)); - set32_fx( hs->msPeriodogSum, 0, 2 ); - hs->msPeriodogSum_exp[0] = 0; + set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN ); + mhvals(MSNUMSUBFR*MSSUBFRLEN, &(hFdCngCom->msM_win)); + mhvals(MSSUBFRLEN, &(hFdCngCom->msM_subwin)); + set32_fx( hFdCngCom->msPeriodogSum, 0, 2 ); + hFdCngCom->msPeriodogSum_exp[0] = 0; move16(); - hs->msPeriodogSum_exp[1] = 0; + hFdCngCom->msPeriodogSum_exp[1] = 0; move16(); - set32_fx( hs->msPsdSum, 0, 2 ); - set16_fx( hs->msSlope, 0, 2 ); - set32_fx( hs->msQeqInvAv, 0, 2 ); - hs->msQeqInvAv_exp[0] = 0; + set32_fx( hFdCngCom->msPsdSum, 0, 2 ); + set16_fx( hFdCngCom->msSlope, 0, 2 ); + set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); + hFdCngCom->msQeqInvAv_exp[0] = 0; move16(); - hs->msQeqInvAv_exp[1] = 0; + hFdCngCom->msQeqInvAv_exp[1] = 0; move16(); - hs->msFrCnt_init_counter = 0; + hFdCngCom->msFrCnt_init_counter = 0; move16(); - hs->msFrCnt_init_thresh = 1; + hFdCngCom->msFrCnt_init_thresh = 1; move16(); - hs->init_old = 0; + hFdCngCom->init_old = 0; move16(); - hs->offsetflag = 0; + hFdCngCom->offsetflag = 0; move16(); - hs->msFrCnt = MSSUBFRLEN; + hFdCngCom->msFrCnt = MSSUBFRLEN; move16(); - hs->msMinBufferPtr = 0; + hFdCngCom->msMinBufferPtr = 0; move16(); - hs->msAlphaCor[0] = 644245120l/*0.3f Q31*/; + hFdCngCom->msAlphaCor[0] = 644245120l/*0.3f Q31*/; move16(); - hs->msAlphaCor[1] = 644245120l/*0.3f Q31*/; + hFdCngCom->msAlphaCor[1] = 644245120l/*0.3f Q31*/; move16(); /* Initialize exponents */ - hs->exp_cldfb_periodog = 0; + hFdCngCom->exp_cldfb_periodog = 0; move16(); return; } -/***************************************** -* Delete an instance of type FD_CNG_COM * -*****************************************/ +/*------------------------------------------------------------------- + * deleteFdCngCom() + * + * Delete an instance of type FD_CNG_COM + *-------------------------------------------------------------------*/ void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom) /* i/o: Contains the variables related to the CLDFB-based CNG process */ { HANDLE_FD_CNG_COM hsCom; @@ -134,28 +156,31 @@ void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom) /* i/o: Contains the variable move16(); IF (hsCom != NULL) { - free(hsCom); + count_free(hsCom); *hFdCngCom = NULL; move16(); } } -/*************************************** -* Initialize the spectral partitioning * -****************************************/ -void initPartitions( const Word16* part_in, - Word16 npart_in, - Word16 startBand, - Word16 stopBand, - Word16* part_out, - Word16* npart_out, - Word16* midband, - Word16* psize, - Word16* psize_norm, - Word16* psize_norm_exp, - Word16* psize_inv, - Word16 stopBandFR - ) +/*------------------------------------------------------------------- + * initPartitions() + * + * Initialize the spectral partitioning + *-------------------------------------------------------------------*/ +void initPartitions( + const Word16* part_in, + const Word16 npart_in, + const Word16 startBand, + const Word16 stopBand, + Word16* part_out, + Word16* npart_out, + Word16* midband, + Word16* psize, + Word16* psize_norm, + Word16* psize_norm_exp, + Word16* psize_inv, + const Word16 stopBandFR +) { Word16 i, j, len_out, tmp16; @@ -204,20 +229,17 @@ void initPartitions( const Word16* part_in, } -#define CNG_HS 4 /* 4 bit headroom for dot product */ -#define CNG_S 6 /* 1 sign bit, 6 bit integer part, 9 bit frational part for input and output data */ - - - -/******************************************************** -* Apply some dynamic range compression based on the log * -********************************************************/ +/*------------------------------------------------------------------- + * compress_range() + * + * Apply some dynamic range compression based on the log + *-------------------------------------------------------------------*/ void compress_range( Word32 *in, - Word16 in_exp, + Word16 in_exp, Word16 *out, - Word16 len + const Word16 len ) { Word16 i; @@ -276,14 +298,16 @@ void compress_range( } -/************************************************************* -* Apply some dynamic range expansion to undo the compression * -*************************************************************/ +/*------------------------------------------------------------------- + * expand_range() + * + * Apply some dynamic range expansion to undo the compression + *-------------------------------------------------------------------*/ void expand_range( Word16 *in, Word32 *out, Word16 *out_exp, - Word16 len + const Word16 len ) { Word16 i; @@ -330,12 +354,15 @@ void expand_range( } -/************************************************* -* Noise estimation using Minimum Statistics (MS) * -*************************************************/ +/*------------------------------------------------------------------- + * minimum_statistics() + * + * Noise estimation using Minimum Statistics (MS) + *-------------------------------------------------------------------*/ + void minimum_statistics ( - Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ - Word16 lenFFT, /* i : Number of FFT partitions */ + const Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ + const Word16 lenFFT, /* i : Number of FFT partitions */ Word16 *psize, /* i : Partition sizes, fractional */ Word16 *msPeriodog, /* i : Periodogram (energies) */ Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ @@ -354,7 +381,11 @@ void minimum_statistics ( Word16 *msNewMinFlag, /* i : Binary flag */ Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ Word16 *msPeriodogBufPtr, /* i/o: Counter */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing buffers and variables */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +#ifdef IVAS_CODE_CNG + ,const Word16 enc_dec, /* i : encoder/decoder indicator */ + const Word16 element_mode /* i : IVAS element mode type */ +#endif ) { Word16 i,j,k,s,s1,s2,s3; @@ -391,9 +422,9 @@ void minimum_statistics ( len2 = i_mult(MSNUMSUBFR,len); - msM_win = st->msM_win; + msM_win = hFdCngCom->msM_win; move16(); - msM_subwin = st->msM_subwin; + msM_subwin = hFdCngCom->msM_subwin; move16(); msAlphaCorAlpha = MSALPHACORALPHA; @@ -401,11 +432,11 @@ void minimum_statistics ( msAlphaCorAlpha2 = MSALPHACORALPHA2; move16(); - msPsdSum = st->msPsdSum; - msPeriodogSum = st->msPeriodogSum; + msPsdSum = hFdCngCom->msPsdSum; + msPeriodogSum = hFdCngCom->msPeriodogSum; /* No minimum statistics at initialization */ - IF ( LT_16(st->msFrCnt_init_counter,st->msFrCnt_init_thresh)) + IF ( LT_16(hFdCngCom->msFrCnt_init_counter,hFdCngCom->msFrCnt_init_thresh)) { Copy(msPeriodog, msPsd, len); /* 6Q9 */ Copy(msPeriodog, msNoiseFloor, len); /* 6Q9 */ @@ -426,17 +457,17 @@ void minimum_statistics ( /* Increment frame counter at initialization */ /* Some frames are sometimes zero at initialization => ignore them */ - IF ( LT_16(msPeriodog[0],st->init_old)) + IF ( LT_16(msPeriodog[0],hFdCngCom->init_old)) { set32_fx(msCurrentMinOut, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ set32_fx(msCurrentMin, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ set32_fx(msMinBuf, 2147483647l/*1.0 Q31*/, len2); /* 16Q15 */ set32_fx(msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ - st->msFrCnt_init_counter = add(st->msFrCnt_init_counter,1); + hFdCngCom->msFrCnt_init_counter = add(hFdCngCom->msFrCnt_init_counter,1); move16(); } - st->init_old = msPeriodog[0]; /* 6Q9 */ move16(); + hFdCngCom->init_old = msPeriodog[0]; /* 6Q9 */ move16(); } ELSE { @@ -449,7 +480,7 @@ void minimum_statistics ( move16(); stop = lenFFT; move16(); - totsize = sub(st->stopFFTbin,st->startBand); + totsize = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); WHILE ( GT_16(stop,start)) { current_len = sub(stop,start); @@ -462,7 +493,7 @@ void minimum_statistics ( IF ( msPeriodogSum[cnt] == 0 ) { - st->msAlphaCor[cnt] = Mpy_32_16_1(st->msAlphaCor[cnt], msAlphaCorAlpha); + hFdCngCom->msAlphaCor[cnt] = Mpy_32_16_1(hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha); move32(); } ELSE @@ -510,7 +541,7 @@ void minimum_statistics ( scalar16 = shl(scalar16,s3); scalar16 = s_max(scalar16, MSALPHACORMAX); - st->msAlphaCor[cnt] = L_add(Mpy_32_16_1(st->msAlphaCor[cnt], msAlphaCorAlpha), + hFdCngCom->msAlphaCor[cnt] = L_add(Mpy_32_16_1(hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha), L_mult(scalar16, msAlphaCorAlpha2)); move32(); } @@ -533,7 +564,7 @@ void minimum_statistics ( msAlphaHatMin2 = MSALPHAHATMIN; move32(); } - scalar = Mpy_32_16_1(st->msAlphaCor[cnt], MSALPHAMAX); + scalar = Mpy_32_16_1(hFdCngCom->msAlphaCor[cnt], MSALPHAMAX); FOR (j=start; jmsQeqInvAv[cnt] = QeqInvAv; + hFdCngCom->msQeqInvAv[cnt] = QeqInvAv; move32(); /* New minimum? */ @@ -727,17 +758,17 @@ void minimum_statistics ( } /* This is used later to identify local minima */ - IF ( GE_16(st->msFrCnt,MSSUBFRLEN)) + IF ( GE_16(hFdCngCom->msFrCnt,MSSUBFRLEN)) { FOR ( i = 0; i < 3; i++ ) { - IF ( LT_32(st->msQeqInvAv[cnt],L_shr(L_deposit_h(msQeqInvAv_thresh[i]),CNG_S))/*0.0 Q31*/) + IF ( LT_32(hFdCngCom->msQeqInvAv[cnt],L_shr(L_deposit_h(msQeqInvAv_thresh[i]),CNG_S))/*0.0 Q31*/) { BREAK; } } /* format 1Q30 */ - st->msSlope[cnt] = msNoiseSlopeMax[i]; + hFdCngCom->msSlope[cnt] = msNoiseSlopeMax[i]; move32(); } @@ -746,13 +777,13 @@ void minimum_statistics ( move16(); stop = len; move16(); - totsize = sub(st->stopBand,st->stopFFTbin); + totsize = sub(hFdCngCom->stopBand,hFdCngCom->stopFFTbin); cnt = add(cnt,1); } /*while (stop > start)*/ /* Update minimum between sub windows */ test(); - IF ( GT_16(st->msFrCnt,1)&<_16(st->msFrCnt,MSSUBFRLEN)) + IF ( GT_16(hFdCngCom->msFrCnt,1)&<_16(hFdCngCom->msFrCnt,MSSUBFRLEN)) { FOR (j=0; jmsFrCnt,MSSUBFRLEN)) + IF ( GE_16(hFdCngCom->msFrCnt,MSSUBFRLEN)) { /* Collect buffers */ - Copy32(msCurrentMinSubWindow, msMinBuf+len*st->msMinBufferPtr, len); + Copy32(msCurrentMinSubWindow, msMinBuf+len*hFdCngCom->msMinBufferPtr, len); /* Compute minimum among all buffers */ Copy32(msMinBuf, msCurrentMinOut, len); @@ -795,13 +826,13 @@ void minimum_statistics ( } /* Take over local minima */ - slope = st->msSlope[0]; + slope = hFdCngCom->msSlope[0]; move16(); FOR (j=0; jmsSlope[1]; + slope = hFdCngCom->msSlope[1]; move16(); } test(); @@ -839,14 +870,14 @@ void minimum_statistics ( /* Detect sudden offsets based on the FFT bins (core bandwidth) */ IF ( GT_32(Mpy_32_16_1(msPsdSum[0],655/*0.02 Q15*/), msPeriodogSum[0])/*0.0 Q31*/) { - IF ( st->offsetflag > 0 ) + IF ( hFdCngCom->offsetflag > 0 ) { Copy(msPeriodog, msPsd, len); FOR (j=0; j < len; j++) { msCurrentMinOut[j] = L_deposit_h(msPeriodog[j]); } - set32_fx(st->msAlphaCor, 2147483647l/*1.0 Q31*/, cnt); + set32_fx(hFdCngCom->msAlphaCor, 2147483647l/*1.0 Q31*/, cnt); set32_fx(msAlpha, 0l/*0.0 Q31*/, len); Copy(msPeriodog, msPsdFirstMoment, len); set32_fx(msPsdSecondMoment, 0l/*0.0 Q31*/, len); @@ -859,32 +890,32 @@ void minimum_statistics ( move32(); } } - st->offsetflag = 1; + hFdCngCom->offsetflag = 1; move16(); } ELSE { - st->offsetflag = 0; + hFdCngCom->offsetflag = 0; move16(); } /* Increment frame counter */ - IF ( EQ_16(st->msFrCnt,MSSUBFRLEN)) + IF ( EQ_16(hFdCngCom->msFrCnt,MSSUBFRLEN)) { - st->msFrCnt = 1; + hFdCngCom->msFrCnt = 1; move16(); - st->msMinBufferPtr = add(st->msMinBufferPtr,1); + hFdCngCom->msMinBufferPtr = add(hFdCngCom->msMinBufferPtr,1); move16(); - if ( EQ_16(st->msMinBufferPtr,MSNUMSUBFR)) + if ( EQ_16(hFdCngCom->msMinBufferPtr,MSNUMSUBFR)) { - st->msMinBufferPtr = 0; + hFdCngCom->msMinBufferPtr = 0; move16(); } } ELSE { - st->msFrCnt = add(st->msFrCnt,1); + hFdCngCom->msFrCnt = add(hFdCngCom->msFrCnt,1); } /* Smooth noise estimate during CNG phases */ @@ -893,7 +924,12 @@ void minimum_statistics ( msNoiseEst[j] = round_fx(L_mac(L_mult(31130/*0.95 Q15*/, msNoiseEst[j]), 1638/*0.05 Q15*/, msNoiseFloor[j])); } } - +#ifdef IVAS_CODE_CNG_COM + if (enc_dec == DEC && element_mode == IVAS_CPE_TD) + { + v_multc(msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING); + } +#endif /* Collect buffers */ Copy(msPeriodog, msPeriodogBuf+len*(*msPeriodogBufPtr), len); @@ -926,17 +962,21 @@ void minimum_statistics ( } - -/*********************************** -* Apply bitrate-dependant scale * -***********************************/ -void apply_scale(Word32 *scale, Word16 bwmode, Word32 bitrate) +/*------------------------------------------------------------------- + * apply_scale() + * + * Apply bitrate-dependent scale + *-------------------------------------------------------------------*/ +void apply_scale( + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP* scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ +) { Word16 i; - Word16 scaleTableSize = sizeof (scaleTable) / sizeof (scaleTable[0]); - - - +PMT("Verifiy if the basop ued are ok for stereo too") FOR (i=0; i < scaleTableSize; i++) { cast16(); @@ -955,18 +995,21 @@ void apply_scale(Word32 *scale, Word16 bwmode, Word32 bitrate) } - -/*************************************** -* Compute the power for each partition * -***************************************/ -void bandcombinepow(Word32* bandpow, /* i : Power for each band */ - Word16 exp_bandpow, /* i : exponent of bandpow */ - Word16 nband, /* i : Number of bands */ - Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* psize_inv, /* i : Inverse partition sizes */ - Word32* partpow, /* o : Power for each partition */ - Word16* exp_partpow) +/*------------------------------------------------------------------- + * bandcombinepow() + * + * Compute the power for each partition + *-------------------------------------------------------------------*/ +void bandcombinepow( + const Word32* bandpow, /* i : Power for each band */ + const Word16 exp_bandpow, /* i : exponent of bandpow */ + const Word16 nband, /* i : Number of bands */ + Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + const Word16* psize_inv, /* i : Inverse partition sizes */ + Word32* partpow, /* o : Power for each partition */ + Word16* exp_partpow +) { Word16 i, p; @@ -1024,19 +1067,21 @@ void bandcombinepow(Word32* bandpow, /* i : Power for move16(); } - -/************************************ -* Scale partitions (with smoothing) * -************************************/ -void scalebands (Word32 *partpow, /* i : Power for each partition */ - Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16 *midband, /* i : Central band of each partition */ - Word16 nFFTpart, /* i : Number of FFT partitions */ - Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ - Word16 flag_fft_en - ) +/*------------------------------------------------------------------- + * scalebands() + * + * Scale partitions (with smoothing) + *-------------------------------------------------------------------*/ +void scalebands ( + const Word32 *partpow, /* i : Power for each partition */ + Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + Word16 *midband, /* i : Central band of each partition */ + const Word16 nFFTpart, /* i : Number of FFT partitions */ + const Word16 nband, /* i : Number of bands */ + Word32 *bandpow, /* o : Power for each band */ + const Word16 flag_fft_en +) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; Word16 startBand, startPart, stopPart, stopPartM1; @@ -1168,17 +1213,20 @@ void scalebands (Word32 *partpow, /* i : Power for each partition */ } - -/************************************** -* Get central band for each partition * -**************************************/ -void getmidbands(Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* midband, /* o : Central band of each partition */ - Word16* psize, /* o : Partition sizes */ - Word16* psize_norm, /* o : Partition sizes, fractional values */ - Word16* psize_norm_exp, /* o : Exponent for fractional partition sizes */ - Word16* psize_inv) /* o : Inverse of partition sizes */ +/*------------------------------------------------------------------- + * getmidbands() + * + * Get central band for each partition + *-------------------------------------------------------------------*/ +static void getmidbands( + const Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + Word16* midband, /* o : Central band of each partition */ + Word16* psize, /* o : Partition sizes */ + Word16* psize_norm, /* o : Partition sizes, fractional values */ + Word16* psize_norm_exp, /* o : Exponent for fractional partition sizes */ + Word16* psize_inv /* o : Inverse of partition sizes */ +) { Word16 j, max_psize, shift; @@ -1220,29 +1268,19 @@ void getmidbands(Word16* part, /* i : Partition upper boundaries ( assert(norm_s(-max_psize) >= 9 ); } - -/* - AnalysisSTFT - - Parameters: - - timeDomainInput, i : pointer to time signal - fftBuffer, o : FFT bins - fftBufferExp, i : exponent of FFT bins - st i/o: FD_CNG structure containing all buffers and variables - - Function: - STFT analysis filterbank - - Returns: - void -*/ -void AnalysisSTFT (const Word16 *timeDomainInput, /* i : pointer to time signal */ - Word16 Q, - Word32 *fftBuffer, /* o : FFT bins */ - Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - ) +/*------------------------------------------------------------------- + * AnalysisSTFT() + * + * STFT analysis filterbank + *-------------------------------------------------------------------*/ + +void AnalysisSTFT ( + const Word16 *timeDomainInput, /* i : pointer to time signal */ + Word16 Q, + Word32 *fftBuffer, /* o : FFT bins */ + Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +) { Word16 i, len; Word16 len2; @@ -1251,17 +1289,17 @@ void AnalysisSTFT (const Word16 *timeDomainInput, /* i : pointer to time signal - assert( (st->fftlen>>1) == st->frameSize); + assert( (hFdCngCom->fftlen>>1) == hFdCngCom->frameSize); /* pointer inititialization */ - assert(st->olapBufferAna != NULL); - olapBuffer = st->olapBufferAna; - olapWin = st->olapWinAna; + assert(hFdCngCom->olapBufferAna != NULL); + olapBuffer = hFdCngCom->olapBufferAna; + olapWin = hFdCngCom->olapWinAna; /* olapWin factor is scaled with one bit */ *fftBuffer_exp = 1; move16(); - len = sub(st->fftlen,st->frameSize); + len = sub(hFdCngCom->fftlen,hFdCngCom->frameSize); assert(len <= 320); /* see size of olapBuffer */ /* Window the signal */ @@ -1273,7 +1311,7 @@ void AnalysisSTFT (const Word16 *timeDomainInput, /* i : pointer to time signal fftBuffer[i] = L_mult(olapBuffer[i], mult_r(olapWin[i].v.im, 23170/*1.4142135623730950488016887242097 Q14*/)); fftBuffer[i+len2] = L_mult(olapBuffer[i+len2], mult_r(olapWin[len2-1-i].v.re, 23170/*1.4142135623730950488016887242097 Q14*/)); } - len2 = shr(st->frameSize,1); + len2 = shr(hFdCngCom->frameSize,1); FOR (i=0; i fftlen, fftBuffer_exp, -1); + BASOP_rfft(fftBuffer, hFdCngCom->fftlen, fftBuffer_exp, -1); FOR (i=0; i frameSize,len)+i], Q ); + olapBuffer[i] = shr( timeDomainInput[sub(hFdCngCom->frameSize,len)+i], Q ); move16(); } } -/* - SynthesisSTFT - - Parameters: - - fftBuffer i : pointer to FFT bins - fftBufferExp i : exponent of FFT bins - timeDomainOutput o : pointer to time domain signal - timeDomainOutputExp o : pointer to exponent of time domain output - olapBuffer i/o : pointer to overlap buffer - olapWin i : pointer to overlap window - st i/o : pointer to FD_CNG structure containing all buffers and variables - - Function: - STFT synthesis filterbank - - Returns: - void -*/ -void -SynthesisSTFT (Word32 *fftBuffer, /* i : pointer to FFT bins */ - Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ - Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ - const PWord16 *olapWin, /* i : pointer to overlap window */ - Word16 tcx_transition, - HANDLE_FD_CNG_COM st, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ - Word16 gen_exc, - Word16 *Q_new - ) +/*------------------------------------------------------------------- + * SynthesisSTFT() + * + * STFT synthesis filterbank + *-------------------------------------------------------------------*/ + +void SynthesisSTFT ( + Word32 *fftBuffer, /* i : pointer to FFT bins */ + Word16 fftBufferExp, /* i : exponent of FFT bins */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ + const PWord16 *olapWin, /* i : pointer to overlap window */ + Word16 tcx_transition, + HANDLE_FD_CNG_COM hFdCngCom, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ + Word16 gen_exc, + Word16 *Q_new, + const Word16 element_mode, /* i : element mode */ + const Word16 nchan_out /* i : number of output channels */ +) { Word16 i, len, scale, tmp; Word16 len2, len3, len4; @@ -1332,18 +1359,26 @@ SynthesisSTFT (Word32 *fftBuffer, /* i : pointer to FFT bins */ /* Perform IFFT */ scale = 0; - BASOP_rfft(fftBuffer, st->fftlen, &scale, 1); + BASOP_rfft(fftBuffer, hFdCngCom->fftlen, &scale, 1); fftBufferExp = add(fftBufferExp, scale); - fftBufferExp = add(fftBufferExp, st->fftlenShift); + fftBufferExp = add(fftBufferExp, hFdCngCom->fftlenShift); /* Perform overlap-add */ - Copy(olapBuffer+st->frameSize, olapBuffer, st->frameSize); - set16_fx(olapBuffer+st->frameSize, 0, st->frameSize); - - len2 = shr(st->fftlen,2); - len4 = shr(st->fftlen,3); + /* Handle overlap in P/S domain for stereo */ + IF ((EQ_16(element_mode, IVAS_CPE_TD) || EQ_16(element_mode, IVAS_CPE_DFT)) && EQ_16(nchan_out, 2) ) + { + Copy(olapBuffer + 3 * hFdCngCom->frameSize / 4 - (M + 1), buf, hFdCngCom->frameSize + M + 1); + set16_fx(olapBuffer, 0, hFdCngCom->fftlen); + } + ELSE + { + Copy(olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize); + set16_fx(olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize); + } + len2 = shr(hFdCngCom->fftlen,2); + len4 = shr(hFdCngCom->fftlen,3); len3 = add(len2,len4); - len = add(st->frameSize,len4); + len = add(hFdCngCom->frameSize,len4); IF ( tcx_transition ) { FOR (i=0; i < len; i++) @@ -1375,55 +1410,131 @@ SynthesisSTFT (Word32 *fftBuffer, /* i : pointer to FFT bins */ } len = add( len, len2 ); - FOR (i=len; i < st->fftlen ; i++) + FOR (i=len; i < hFdCngCom->fftlen ; i++) { olapBuffer[i] = 0; move16(); } /* Get time-domain signal */ - FOR (i=0; i < st->frameSize; i++) + FOR (i=0; i < hFdCngCom->frameSize; i++) { - timeDomainOutput[i] = mult_r( olapBuffer[i+len4], st->fftlenFac ); + timeDomainOutput[i] = mult_r( olapBuffer[i+len4], hFdCngCom->fftlenFac ); move16(); } - /* Generate excitation */ - IF ( EQ_16( gen_exc, 1 )) +#ifdef IVAS_CODE_CNG_COM + PME() + if ((element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT) && nchan_out == 2) { - FOR (i=0; i < M+1+st->frameSize; i++) + for (i = 0; i < hFdCngCom->frameSize / 2; i++) { - buf[i] = mult_r( olapBuffer[i+len4-M-1], st->fftlenFac ); - move16(); + buf[i + (M + 1)] += olapBuffer[i + hFdCngCom->frameSize / 4]; } - tmp = buf[0]; - E_UTIL_f_preemph2( *Q_new-1, buf+1, PREEMPH_FAC, M+st->frameSize, &tmp ); - Residu3_fx( st->A_cng, buf+1+M, st->exc_cng, st->frameSize, 1 ); + v_multc(buf, (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); } - IF ( EQ_16( gen_exc, 2 )) + else +#endif { - FOR (i=0; i < M+1+st->frameSize; i++) + FOR(i = 0; i < M + 1 + hFdCngCom->frameSize; i++) { - buf[i] = mult_r( olapBuffer[i+len4-M-1], st->fftlenFac ); + buf[i] = mult_r(olapBuffer[i + len4 - M - 1], hFdCngCom->fftlenFac); move16(); } tmp = buf[0]; - *Q_new = E_UTIL_f_preemph3( buf+1, PREEMPH_FAC, M+st->frameSize, &tmp, 1 ); - Residu3_fx( st->A_cng, buf+1+M, st->exc_cng, st->frameSize, 1 ); + } + IF ( EQ_16( gen_exc, 1 )) + { + + E_UTIL_f_preemph2( *Q_new-1, buf+1, PREEMPH_FAC, M+hFdCngCom->frameSize, &tmp ); + Residu3_fx( hFdCngCom->A_cng, buf+1+M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); + } + IF ( EQ_16( gen_exc, 2 )) + { + *Q_new = E_UTIL_f_preemph3( buf+1, PREEMPH_FAC, M+hFdCngCom->frameSize, &tmp, 1 ); + Residu3_fx( hFdCngCom->A_cng, buf+1+M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); } } +#ifdef IVAS_CODE_CNG_COM +/*------------------------------------------------------------------- + * SynthesisSTFT_dirac() + * + * STFT synthesis filterbank + *-------------------------------------------------------------------*/ + +void SynthesisSTFT_dirac( + float* fftBuffer, /* i : FFT bins */ + float* timeDomainOutput, + float* olapBuffer, + const float* olapWin, + const int16_t samples_out, + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +) +{ + int16_t i; + float buf[M + 1 + 320], tmp; + + /* Perform IFFT */ + RFFTN(fftBuffer, hFdCngCom->fftSineTab, hFdCngCom->fftlen, 1); + + /* Handle overlap in P/S domain for stereo */ + mvr2r(olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize); + set_f(olapBuffer + hFdCngCom->frameSize, 0.0f, hFdCngCom->frameSize); /*olapBuffer, fftBuffer, olapWin*/ + + for (i = hFdCngCom->frameSize / 4; i < 3 * hFdCngCom->frameSize / 4; i++) + { + olapBuffer[i] += fftBuffer[i] * olapWin[i - hFdCngCom->frameSize / 4]; + } + for (; i < 5 * hFdCngCom->frameSize / 4; i++) + { + olapBuffer[i] = fftBuffer[i]; + } + + for (; i < 7 * hFdCngCom->frameSize / 4; i++) + { + olapBuffer[i] = fftBuffer[i]; + } + + for (; i < hFdCngCom->fftlen; i++) + { + olapBuffer[i] = 0; + } + + /* Get time-domain signal */ + v_multc(olapBuffer + hFdCngCom->frameSize / 4, (float)(hFdCngCom->fftlen / 2), timeDomainOutput, samples_out); + + /* Get excitation */ + v_multc(olapBuffer + hFdCngCom->frameSize / 4 - (M + 1), (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); + tmp = buf[0]; + preemph(buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp); + residu(hFdCngCom->A_cng, M, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize); + + /* update and window olapBuf if we have a output frame that is shorter than the default frame size...*/ + if (samples_out < hFdCngCom->frameSize) + { + mvr2r(olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, 3 * hFdCngCom->frameSize / 4); + } + for (i = 5 * hFdCngCom->frameSize / 4; i < 7 * hFdCngCom->frameSize / 4; i++) + { + olapBuffer[i] *= olapWin[i - 3 * hFdCngCom->frameSize / 4]; + } + return; +} +#endif /************************************************************************************** * Compute some values used in the bias correction of the minimum statistics algorithm * **************************************************************************************/ -void mhvals(Word16 d, - Word16 * m /*, float * h*/ - ) +void mhvals( + const Word16 d, + Word16 * m /*, float * h*/ +) { Word16 i, j; - Word16 len = sizeof(d_array)/sizeof(Word16); + Word16 len = SIZE_SCALE_TABLE_CN; + move16(); assert( d==72 || d==12); /* function only tested for d==72 and d==12) */ @@ -1496,27 +1607,18 @@ void mhvals(Word16 d, } } - -/* - rand_gauss - - Parameters: - - seed i/o : pointer to seed - - Function: - Random generator with Gaussian distribution with mean 0 and std 1 - - Returns: - random signal format Q3.29 -*/ +/*------------------------------------------------------------------- + * rand_gauss() + * + * Random generator with Gaussian distribution with mean 0 and std 1 + * Returns: + * random signal format Q3.29 + *-------------------------------------------------------------------*/ Word32 rand_gauss (Word16 *seed) { Word32 temp; Word16 loc_seed; - - /* This unrolled version reduces the cycles from 17 to 10 */ loc_seed = extract_l(L_mac0(13849, *seed, 31821)); temp = L_deposit_l(loc_seed); @@ -1532,43 +1634,29 @@ Word32 rand_gauss (Word16 *seed) return L_shl(temp,WORD16_BITS-CNG_RAND_GAUSS_SHIFT); } - -/* - lpc_from_spectrum - - Parameters: - - powspec i : pointer to noise levels format Q5.27 - start i : start band - stop i : stop band - fftlen i : size of fft - A o : lpc coefficients format Q3.12 - s i : lpc order - preemph_fac i : preemphase factor format Q1.15 - - - Function: - calculate lpc coefficients from the spectrum - - Returns: - void -*/ -void lpc_from_spectrum (Word32 *powspec, - Word16 powspec_exp, - Word16 start, - Word16 stop, - Word16 fftlen, - Word16 *A, - Word16 lpcorder, - Word16 preemph_fac - ) +/*------------------------------------------------------------------- + * lpc_from_spectrum() + * + * + *-------------------------------------------------------------------*/ + +void lpc_from_spectrum ( + HANDLE_FD_CNG_COM hFdCngCom, + const Word16 start, /*i : start band*/ + const Word16 stop, /*i : stop band*/ + const Word16 preemph_fac /*i : preemphase factor format Q1.15*/ +) { Word16 i, s1, s2, s3, fftlen2, scale, fftlen4, fftlen8, len, step, preemph_fac2; Word32 maxVal, r[32], fftBuffer[FFTLEN], *ptr, *pti, nf; Word16 tmp, r_h[32], r_l[32]; const PWord16 *table; - + Word32* powspec = hFdCngCom->cngNoiseLevel; /*i : pointer to noise levels format Q5.27*/ + Word16 powspec_exp = hFdCngCom->cngNoiseLevelExp; + Word16 fftlen = hFdCngCom->fftlen; /*i : size of fft*/ + Word16*A = hFdCngCom->A_cng; /*o : lpc coefficients format Q3.12*/ + Word16 lpcorder = M; scale = 0; move16(); @@ -1734,17 +1822,18 @@ void lpc_from_spectrum (Word32 *powspec, Returns: void */ -void msvq_decoder (const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 maxN, /* i : Codebook vector dimension */ - Word16 Idx[], /* i : Indices */ - Word16 *uq /* o : quantized vector */ - ) +void msvq_decoder ( + const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook vector dimension */ + const Word16 Idx[], /* i : Indices */ + Word16 *uq /* o : quantized vector */ +) { Word16 s, i, offset; - +PMT("msvq_decoder Not verified") offset = i_mult(Idx[0], maxN); FOR (i=0; iA_cng, Aq+i*(M+1), M+1 ); + Copy( hFdCngCom->A_cng, Aq+i*(M+1), M+1 ); } E_LPC_a_lsp_conversion( Aq, lsp_new, lsp_old, M ); @@ -1811,16 +1905,18 @@ void FdCng_exc( { E_LPC_lsp_lsf_conversion( lsp_new, lsf_new, M ); } - Copy( hs->exc_cng, exc, L_frame ); - Copy( hs->exc_cng, exc2, L_frame ); - - IF( EQ_16(L_frame,L_FRAME)) + Copy( hFdCngCom->exc_cng, exc, L_frame ); + Copy( hFdCngCom->exc_cng, exc2, L_frame ); + IF (bwe_exc != NULL) { - interp_code_5over2_fx( exc2, bwe_exc, L_frame ); - } - ELSE - { - interp_code_4over2_fx( exc2, bwe_exc, L_frame ); + IF(EQ_16(L_frame, L_FRAME)) + { + interp_code_5over2_fx(exc2, bwe_exc, L_frame); + } + ELSE + { + interp_code_4over2_fx(exc2, bwe_exc, L_frame); + } } } diff --git a/lib_com/fill_spectrum_fx.c b/lib_com/fill_spectrum_fx.c index ae947af..fea44d9 100644 --- a/lib_com/fill_spectrum_fx.c +++ b/lib_com/fill_spectrum_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* * fill_spectrum() @@ -17,42 +16,43 @@ *--------------------------------------------------------------------------*/ void fill_spectrum_fx( - Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ - Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ - const Word16 *R, /* i : number of pulses per band Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - Word16 norm[], /* i : quantization indices for norms Q0 */ - const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ - const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ - const Word16 nf_idx, /* i : noise fill index Q0 */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ - const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ - const Word16 core_sfm, /* i : index of the end band for core Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ - const Word32 L_core_brate, /* i : target bit-rate Q0 */ - Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ - Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ - const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ - const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ - const Word16 *npulses, /* i : number of pulses per band Q0 */ - const Word16 prev_is_transient, /* i : previous transient flag Q0 */ - Word32 *prev_normq, /* i/o: previous norms Q14 */ - Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ - const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ - const Word16 *sfmsize, /* i : Length of bands Q0 */ - const Word16 *sfm_start, /* i : Start of bands Q0 */ - const Word16 *sfm_end, /* i : End of bands Q0 */ - Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ - const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ - const Word16 num_sfm /* i : Total number of bands Q0 */ - ,Word16 *prev_env_Q - ,const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ + Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ + Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ + const Word16 *R, /* i : number of pulses per band Q0 */ + const Word16 is_transient, /* i : transient flag Q0 */ + Word16 norm[], /* i : quantization indices for norms Q0 */ + const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ + const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ + const Word16 nf_idx, /* i : noise fill index Q0 */ + const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ + const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ + Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ + Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ + const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ + const Word16 core_sfm, /* i : index of the end band for core Q0 */ + const Word16 HQ_mode, /* i : HQ mode Q0 */ + Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ + const Word32 L_core_brate, /* i : target bit-rate Q0 */ + Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ + Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ + Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ + const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ + const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ + const Word16 *npulses, /* i : number of pulses per band Q0 */ + const Word16 prev_is_transient, /* i : previous transient flag Q0 */ + Word32 *prev_normq, /* i/o: previous norms Q14 */ + Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ + const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ + const Word16 *sfmsize, /* i : Length of bands Q0 */ + const Word16 *sfm_start, /* i : Start of bands Q0 */ + const Word16 *sfm_end, /* i : End of bands Q0 */ + Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ + const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ + const Word16 num_sfm, /* i : Total number of bands Q0 */ + Word16 *prev_env_Q, + const Word16 num_env_bands, /* i : Number sub bands to be encoded for HQ_GEN Q0 */ + const Word16 element_mode /* i : IVAS element mode */ ) { Word16 CodeBook[FREQ_LENGTH]; /* Q12 */ @@ -66,9 +66,8 @@ void fill_spectrum_fx( Word16 peak_pos[L_HARMONIC_EXC]; Word16 bwe_peaks[L_FRAME48k]; Word32 L_normq_v[NB_SFM]; /*Q14 */ - Word16 coeff_fine[L_FRAME48k]; /*Q15 */ - Word32 L_coeff_out1[L_FRAME48k]; /*Q12 */ - + Word16 coeff_fine[L_SPEC48k_EXT]; /*Q15 */ + Word32 L_coeff_out1[L_SPEC48k_EXT]; /*Q12 */ set16_fx( peak_pos, 0, L_HARMONIC_EXC ); set16_fx( bwe_peaks, 0, L_FRAME48k ); set16_fx(norm_adj, 32767, num_sfm); /* 1.0, Q15 */ @@ -96,9 +95,9 @@ void fill_spectrum_fx( IF ( EQ_16(HQ_mode, HQ_HARMONIC)) { - /*high_sfm = (core_brate == HQ_24k40) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */ + /*high_sfm = (core_brate == HQ_BWE_CROSSOVER_BRATE) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */ high_sfm = sub(HVQ_THRES_SFM_32k, 1); - if (EQ_32(L_core_brate, HQ_24k40)) + if (LT_32(L_core_brate, HQ_BWE_CROSSOVER_BRATE)) { high_sfm = sub(HVQ_THRES_SFM_24k, 1); } @@ -225,12 +224,11 @@ void fill_spectrum_fx( test(); IF ( EQ_16(HQ_mode, HQ_HARMONIC)) { - harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out ); + harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode ); } ELSE IF ( EQ_16(HQ_mode, HQ_HVQ)) { - hvq_bwe_fx( L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, - prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm, + hvq_bwe_fx( L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, 15, 12 ); } ELSE IF ( EQ_16(HQ_mode, HQ_GEN_SWB)||EQ_16(HQ_mode,HQ_GEN_FB)) @@ -242,7 +240,7 @@ void fill_spectrum_fx( * HQ WB BWE refinements *----------------------------------------------------------------*/ test(); - IF ( EQ_16(length, L_FRAME16k)&&EQ_32(L_core_brate,HQ_32k)) + IF ( EQ_16(length, L_FRAME16k) && LE_32(L_core_brate,HQ_32k)) { hq_wb_nf_bwe_fx( coeff, is_transient, prev_bfi, L_normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R, prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, L_coeff_out, prev_env_Q ); @@ -253,7 +251,7 @@ void fill_spectrum_fx( *----------------------------------------------------------------*/ test(); - IF ( NE_16(HQ_mode, HQ_HARMONIC)&&NE_16(HQ_mode,HQ_HVQ)) + IF ( NE_16(HQ_mode, HQ_HARMONIC) && NE_16(HQ_mode,HQ_HVQ)) { prev_noise_level[0] = 3277; move16();/* 0.1 in Q15 */ @@ -261,14 +259,14 @@ void fill_spectrum_fx( move16();/* 0.1 in Q15 */ } test(); - IF ( !(EQ_16(length, L_FRAME16k)&&EQ_32(L_core_brate,HQ_32k))) + IF ( !(EQ_16(length, L_FRAME16k) && LE_32(L_core_brate,HQ_32k))) { set32_fx( prev_env, 0, SFM_N_WB ); set32_fx( prev_normq, 0, SFM_N_WB ); } test(); - IF ( EQ_16(length, L_FRAME32k)&&LE_32(L_core_brate,HQ_32k)) + IF ( EQ_16(length, L_FRAME32k) && LE_32(L_core_brate,HQ_32k)) { *prev_R = R[SFM_N_WB-1]; Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE ); diff --git a/lib_com/findpulse_fx.c b/lib_com/findpulse_fx.c index f292b65..2afb93d 100644 --- a/lib_com/findpulse_fx.c +++ b/lib_com/findpulse_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*----------------------------------------------------------------------------------* * findpulse() diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index d6db726..ea39568 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*-------------------------------------------------------------------------- @@ -14,11 +14,11 @@ * HQ core encoder *--------------------------------------------------------------------------*/ -void subband_gain_bits_fx( - const Word16 *Rk, /* i : bit allocation per band Q3 */ - const Word16 N, /* i : number of bands */ - Word16 *bits, /* o : gain bits per band */ - const Word16 *sfmsize /* i : Size of bands */ +static void subband_gain_bits_fx( + const Word16 *Rk, /* i : bit allocation per band Q3 */ + const Word16 N, /* i : number of bands */ + Word16 *bits, /* o : gain bits per band */ + const Word16 *sfmsize /* i : Size of bands */ ) { Word16 i,b,tot; @@ -69,7 +69,6 @@ Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ) { - Word16 subband_cnt; Word16 gain_bits_tot; Word16 i; @@ -84,7 +83,6 @@ Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits } /* Re-adjust bit budget for gain quantization */ - subband_cnt = 0; move16(); gain_bits_tot = 0; move16(); @@ -94,7 +92,6 @@ Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits { IF (Rk[i] > 0) { - subband_cnt = add(subband_cnt, 1); Rk[i] = sub(Rk[i], shl(gain_bits_array[i], 3)); move16(); gain_bits_tot = add(gain_bits_tot, gain_bits_array[i]); diff --git a/lib_com/frame_ener_fx.c b/lib_com/frame_ener_fx.c index a70235e..5f6b42a 100644 --- a/lib_com/frame_ener_fx.c +++ b/lib_com/frame_ener_fx.c @@ -2,6 +2,7 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ @@ -18,10 +19,10 @@ Word16 frame_ener_fx( const Word16 clas, /* i : frame classification */ const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */ const Word16 pitch, /* i : pitch period Q0 */ - Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ + Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */ const Word16 Q_new, /* i : Scaling factor */ - Word16 shift, /* i : Shift need to obtain 12 bits vectors */ + Word16 shift, /* i : Shift need to obtain 12 bits vectors */ const Word16 enc /* i : Encoder/decoder */ ) { @@ -142,7 +143,7 @@ Word16 frame_energy_fx( /* o : Frame energy in const Word16 *pitch, /* i : pitch values for each subframe Q6 */ const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/ const Word16 lp_speech, /* i : long term active speech energy average Q8 */ - Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ + Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ const Word16 Q_syn /* i : Synthesis scaling */ ) { diff --git a/lib_com/gain_inov.c b/lib_com/gain_inov.c index 703054c..21142b5 100644 --- a/lib_com/gain_inov.c +++ b/lib_com/gain_inov.c @@ -2,16 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include +#include "options.h" #include "prot_fx.h" -#include "stl.h" #include "basop_util.h" #include "rom_com_fx.h" -Word32 calc_gain_inov( /* returns innovation gain Q16 */ +Word32 calc_gain_inov( /* returns innovation gain Q16 */ const Word16 *code, /* i : algebraic excitation Q9 */ - Word16 lcode, /* i : Subframe size Q0 */ + const Word16 lcode, /* i : Subframe size Q0 */ Word32 *dotp, /* o : intermediate result Q31-e */ Word16 *dotp_e /* o : intermediate result exponent Q0 */ ) diff --git a/lib_com/get_gain.c b/lib_com/get_gain.c index 9db8199..672e5f9 100644 --- a/lib_com/get_gain.c +++ b/lib_com/get_gain.c @@ -2,15 +2,20 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" #include "prot_fx.h" -#include "stl.h" #include "basop_util.h" +/*----------------------------------------------------------------------------------* + * get_gain() + * + * + *----------------------------------------------------------------------------------*/ Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ - Word16 x[], /* input : target signal */ - Word16 y[], /* input : filtered codebook excitation */ - Word16 n /* input : segment length */ + const Word16 x[], /* input : target signal */ + const Word16 y[], /* input : filtered codebook excitation */ + const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; @@ -36,9 +41,9 @@ Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ } Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q16 */ - Word16 x[], /* input : target signal */ - Word16 y[], /* input : filtered codebook excitation */ - Word16 n /* input : segment length */ + const Word16 x[], /* input : target signal */ + const Word16 y[], /* input : filtered codebook excitation */ + const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; diff --git a/lib_com/gs_bitallocation_fx.c b/lib_com/gs_bitallocation_fx.c index f82fb3f..f05e78f 100644 --- a/lib_com/gs_bitallocation_fx.c +++ b/lib_com/gs_bitallocation_fx.c @@ -1,7 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ @@ -45,44 +45,65 @@ void bands_and_bit_alloc_fx( const Word32 core_brate, /* i : core bit rate */ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ const Word16 bits_used, /* i : Number of bit used before frequency Q */ - Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ + Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ - Word16 *max_ener_band, /* o : Sorted order */ - Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ - Word16 *nb_subbands, /* o : Number of subband allowed */ + Word16 *max_ener_band, /* o : Sorted order */ + Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ + Word16 *nb_subbands, /* o : Number of subband allowed */ const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */ - Word16 *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */ - Word16 *pvq_len, /* o : Number of bin covered with the PVQ */ + Word16 *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */ + Word16 *pvq_len, /* o : Number of bin covered with the PVQ */ const Word16 coder_type, /* i : coding type */ const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 GSC_noisy_speech + const Word16 GSC_noisy_speech, /* i : GSC noisy speech flag */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ) { Word16 bandoffset, i, j, nb_bands_max, bit_new_bands, bit_tmp, st_band, nb_bands; - Word16 ener_vec[MBANDS_GN]; /*Q12 */ + Word16 ener_vec[MBANDS_GN_BITALLOC16k]; /*Q12 */ Word16 nb_tot_bands = 16; Word16 bit_index, bit_index_mem, imax; Word32 L_tmp; Word32 sum_bit, bit_fracf; Word16 etmp; Word16 tmp; - Word16 Ener_per_bd_iQ_tmp[MBANDS_GN]; + Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; Word16 pos, band; Word16 SWB_bit_budget; - Word32 bits_per_bands[MBANDS_GN]; + Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; Word16 w_sum_bit; +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(GSC_IVAS_mode) + MY_UNUSED_Word(element_mode) +#endif + nb_tot_bands = MBANDS_GN; + move16(); + if (EQ_16(L_frame, L_FRAME16k)) + { + nb_tot_bands = MBANDS_GN_BITALLOC16k; + move16(); + } + Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, nb_tot_bands); - Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, MBANDS_GN ); - - set32_fx( bits_per_bands, 0, MBANDS_GN ); - set16_fx( out_bits_per_bands, 0, MBANDS_GN ); + set32_fx( bits_per_bands, 0, MBANDS_GN_BITALLOC16k); + set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k); /* To adapt current energy band to PVQ freq band for sorting*/ ener_vec[0] = add(Ener_per_bd_iQ[0],Ener_per_bd_iQ[1]); /*Q12 */ - Copy( Ener_per_bd_iQ_tmp+1, ener_vec, 15 ); /*Q12 */ - ener_vec[15] = ener_vec[14]; + Copy( Ener_per_bd_iQ_tmp+1, ener_vec, MBANDS_GN-1); /*Q12 */ + ener_vec[MBANDS_GN-1] = ener_vec[MBANDS_GN-2]; move16(); + IF (EQ_16(L_frame, L_FRAME16k)) + { + ener_vec[16] = Ener_per_bd_iQ[16]; + ener_vec[17] = mac_r(L_mult(Ener_per_bd_iQ[16], 16384), Ener_per_bd_iQ[17],16384); + ener_vec[18] = Ener_per_bd_iQ[17]; + ener_vec[19] = mult_r(Ener_per_bd_iQ[17], 26214); + move16(); move16(); move16(); move16(); + } /*------------------------------------------------------------------------ * Determination of the number of bits available to the frequency domain @@ -93,8 +114,40 @@ void bands_and_bit_alloc_fx( move16(); bit_new_bands = 5; move16(); +#ifdef ADD_LRTD + if (GT_32(core_brate, ACELP_16k40) && EQ_16(L_frame, L_FRAME16k)) + { + bit_new_bands = 7; + move16(); + } + + i = 0; + move16(); + WHILE (LT_16(i, SIZE_BRATE_INTERMED_TBL)) + { + IF (LE_32(core_brate, brate_intermed_tbl[i])) + { + BREAK; + } + + IF (EQ_32(brate_intermed_tbl[i], ACELP_24k40)) + { + BREAK; + } + + i = add(i,1); + } + if (GT_16(element_mode, EVS_MONO) && EQ_16(coder_type, AUDIO) && + LE_32(core_brate, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i], ACELP_9k60)) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + { + i = sub(i,1); + } + + bit_index = i_mult2( BRATE2IDX_fx(brate_intermed_tbl[i]), 17); +#else bit_index = i_mult2(BRATE2IDX_fx(core_brate),17); +#endif bit_index_mem = bit_index; move16(); @@ -130,352 +183,762 @@ void bands_and_bit_alloc_fx( move16(); } - IF( EQ_16(GSC_noisy_speech,1)) - { - SWB_bit_budget = *bit; - move16(); - nb_bands = 5; - move16(); - st_band = nb_bands; - move16(); - - set32_fx( bits_per_bands, 0, MBANDS_GN ); - /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ - bit_fracf = L_mult(div_s(1,nb_bands),shl(SWB_bit_budget,2)); /* Q18 */ - - nb_tot_bands = sub(nb_bands_max,6); - nb_tot_bands = s_min(nb_tot_bands, 16); - - FOR(j = 0; j < 2; j++) +#ifdef ADD_LRTD + if (L_frame == L_FRAME16k) { - i = j; - move16(); - max_ener_band[j] = i; - move16(); - ener_vec[i] = 0; - move16(); - } - - FOR(; j < nb_bands; j++) - { - i = maximum_fx(ener_vec, nb_tot_bands, &etmp); - max_ener_band[j] = i; - move16(); - ener_vec[i] = 0; - move16(); + *bit -= 8; } - set32_fx(bits_per_bands, bit_fracf, nb_bands); - } - ELSE + if (coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT) /* can happen only for 2nd channel inactive */ { - bit_index++; - bit_tmp = sub(*bit,GSC_freq_bits[bit_index]); - bit_index++; - nb_bands_max = add(nb_bands_max,GSC_freq_bits[bit_index]); - bit_index++; - - *pvq_len = 112; - move16(); - st_band = 7; - move16(); + *bit += GSC_LRES_NB_NITS; + } - IF( LE_32(core_brate,ACELP_9k60)) + if (*bit > 0) + { + if (GSC_IVAS_mode > 0) { - *pvq_len = 80; - move16(); + SWB_bit_budget = *bit; st_band = 5; - move16(); - IF( Diff_len == 0 ) + set_f(bits_per_bands, 0, MBANDS_GN_BITALLOC16k); + + /* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */ + bit_fracf = (-0.125f * Diff_len + 76.0f) / 100; + bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f); + + /* Adjusment of the bitrate between LF and HF base on the content type */ + /* 1 = new GSC bit alloc + 2 = GSC bit alloc for tc frame + 3 = more music like (should not happen often given music is coded with dft) */ + + if (GSC_IVAS_mode <= 3) { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,13); + nb_bands_max -= 6; } - } - ELSE IF( Diff_len == 0 ) - { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,17); - } + if (GSC_IVAS_mode == 2) + { + bit_fracf += 0.1f; + nb_bands_max--; + } - nb_bands = shr(*pvq_len,4); - - /*------------------------------------------------------------------------ - * Ajustement of the maximum number of bands in function of the - * dynamics of the spectrum (more or less speech like) - *-----------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( EQ_16(coder_type,INACTIVE)||GE_16(noise_lev,NOISE_LEVEL_SP3)) - { - /* Probably classification error -> concentrate bits on LF */ - nb_bands_max = nb_bands; - move16(); - if( GE_32(core_brate,ACELP_8k00)) + if (GSC_IVAS_mode == 3) { - nb_bands_max = add(nb_bands,1); + bit_fracf -= 0.1f; + nb_bands_max += 3; } - } - ELSE IF( GE_16(noise_lev,NOISE_LEVEL_SP2)|| - (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0) ) /* Very low dynamic, tend to speech, do not try to code HF at all */ - { - nb_bands_max = sub(nb_bands_max,2); - } - ELSE if( GE_16(noise_lev,NOISE_LEVEL_SP1)) /* Very low dynamic, tend to speech, code less HF */ - { - nb_bands_max = sub(nb_bands_max,1); - } - test(); - if( EQ_16(bwidth,NB)&>_16(nb_bands_max,10)) - { - nb_bands_max = 10; - move16(); - } + /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/ + /* Adjust the number of band based on the content type and bitrate */ + nb_bands_adj = 1.0f; + if (GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG) + { + nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f; + } + else if (GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG) + { + nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f; + } + nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f); + nb_bands_max = check_bounds_s(nb_bands_max, 5, nb_tot_bands); - /*------------------------------------------------------------------------ - * Find extra number of band to code according to bit rate availables - *-----------------------------------------------------------------------*/ - WHILE ( GE_16(bit_tmp,bit_new_bands)&&LE_16(nb_bands,sub(nb_bands_max,1))) - { - bit_tmp = sub(bit_tmp,bit_new_bands); - nb_bands = add(nb_bands,1); - } + bit_fracf *= SWB_bit_budget; - /*------------------------------------------------------------------------ - * Fractional bits to distribute on the first x bands - *-----------------------------------------------------------------------*/ + /* Estimation of the number of bit used in HF */ + /* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */ + mb = .17f * bit_fracf; + mp = (2.0f * DSR_NB_PULSE); + if (core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3) + { + mp = 1.5f * DSR_NB_PULSE; + } + else if (core_brate < GSC_L_RATE_STG) + { + mp = DSR_NB_PULSE; + } - bit_fracf = L_mult(div_s(1,st_band),shl(bit_tmp,2)); /* Q18 */ + /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/ + /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */ + /* compute the total possible number of band to be coded */ + nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); + mp = min(mp, mb); + if (nb_tot_bands + st_band > nb_bands_max) + { + bit_adj = ((mb + mp) / 2) * (nb_tot_bands + st_band - nb_bands_max); + bit_adj = max(0, bit_adj); + nb_tot_bands = nb_bands_max - st_band; + bit_fracf += bit_adj; + } + nb_tot_bands += st_band; - /*------------------------------------------------------------------------ - * Complete the bit allocation per frequency band - *-----------------------------------------------------------------------*/ - imax = 5; - move16(); + /* Allocate bits to LF */ + etmp = 0.23f; + for (j = 0; j < st_band; j++) + { + i = j; + max_ener_band[j] = i; + ener_vec[i] = MIN16B; + bits_per_bands[j] = etmp * bit_fracf; + etmp -= 0.015f; + } - if( GT_32(core_brate,ACELP_9k60)) - { - imax = 7; - move16(); - } - FOR(i = 0; i < imax; i++) - { - bits_per_bands[i] = L_add(GSC_freq_bits_fx[bit_index],bit_fracf); - move32();/* Q18 */ - bit_index = add(bit_index,1); - } + SWB_bit_budget -= bit_fracf; - IF( Diff_len == 0 ) - { - bit_index = add(bit_index_mem,10); - FOR( i = 0; i < 7; i++ ) + /* Find low energy band in HF */ + set_s(nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k); + for (i = st_band + 2; i < nb_tot_bands - 1; i++) { - bits_per_bands[i] = L_add(bits_per_bands[i],GSC_freq_bits_fx[bit_index]); - move32();/*chk Q18 */ - bit_index = add(bit_index,1); + if (ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1]) + { + nb_pulse_per_band[i] = 1; + } } - } + for (j = st_band; j < nb_tot_bands; j++) + { + if (j > 6) + { + i = maximum(ener_vec, nb_tot_bands, &etmp); + } + else + { + i = j; + } - /*-------------------------------------------------------------------------- - * Complete the bit allocation per frequency band for 16kHz high brate mode - *--------------------------------------------------------------------------*/ + max_ener_band[j] = i; + ener_vec[i] = MIN16B; + } - FOR( j = st_band; j < nb_bands; j++ ) - { - bits_per_bands[j] = L_shl(bit_new_bands,18); - move32(); /*chk Q18 */ - } + /* Recompute the final bit distribution for HF */ + if (nb_tot_bands > st_band) + { + bit_fracf = DSR_NB_PULSE; + mb = (SWB_bit_budget * 2 / (nb_tot_bands - st_band)) - mp; + bit_fracf = (mb - mp) / (nb_tot_bands - st_band); + mb -= bit_fracf; + /* Do the distribution */ + for (j = st_band; j < nb_tot_bands; j++) + { + if (nb_pulse_per_band[max_ener_band[j]] > 1) + { + bits_per_bands[max_ener_band[j]] = mb; + } + else + { + bits_per_bands[max_ener_band[j]] = 4.5f; + } + mb -= bit_fracf; + SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; + } + } - /*-------------------------------------------------------------------------- - * Compute a maximum band (band offset) for the search on maximal energy - * This is function of the spectral dynamic and the bitrate - *--------------------------------------------------------------------------*/ + /* Series of verification in case bit allocated != the budget */ + if (SWB_bit_budget > 0) + { + i = st_band - 1; + while (SWB_bit_budget > 0) + { + bits_per_bands[i]++; + SWB_bit_budget--; + i--; + if (i == -1) + { + i = st_band - 1; + } + } + } - bandoffset = sub(nb_tot_bands,add(nb_bands,2)); + nb_bands = nb_tot_bands; - test(); - test(); - test(); - test(); - test(); - IF( LE_16(noise_lev,NOISE_LEVEL_SP1a)) - { - bandoffset = sub(bandoffset,1); - } - ELSE if ( (LE_32(core_brate,ACELP_13k20)&&(EQ_16(coder_type,INACTIVE)||GE_16(noise_lev,NOISE_LEVEL_SP3)))|| - (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0) ) - { - bandoffset = add(bandoffset,1); - } + sum_bit = 0; + j = 0; + for (i = 0; i < nb_bands; i++) + { + if (bits_per_bands[i] > 112) + { + sum_bit += bits_per_bands[i] - 112; + bits_per_bands[i] = 112; + j = i + 1; + } - bandoffset = s_max(bandoffset ,0); + /* safety check for overage bit reallocation */ + else if (bits_per_bands[i] + sum_bit / 3 > 112) + { + j = i + 1; + } + } - /*-------------------------------------------------------------------------- - * Initiazed sorted vector - * For the first x bands to be included in th final sorted vector - * Sort the remaining bands in decrease energy order - *--------------------------------------------------------------------------*/ - FOR(j = 0; j < nb_tot_bands; j++) - { - max_ener_band[j] = -10; - move16(); + if (sum_bit != 0) + { + sum_bit /= (nb_bands - j); + for (i = j; i < nb_bands; i++) + { + bits_per_bands[i] += sum_bit; + } + } } - FOR(j = 0; j < st_band; j++) + else +#endif + IF(EQ_16(GSC_noisy_speech, 1)) { - max_ener_band[j] = j; + SWB_bit_budget = *bit; move16(); - ener_vec[j] = -10; + nb_bands = 5; move16(); + +#ifdef ADD_LRTD + + fzero_val = 0.0f; + if (element_mode > EVS_MONO) + { + fzero_val = MIN16B_FLT; + } + + if (coder_type == UNVOICED && element_mode > EVS_MONO) + { + nb_bands = 3; + if (SWB_bit_budget > 20) + { + nb_bands = 5; + } + } + else if (bwidth < SWB) + { + nb_bands = 7; + } + +#endif + + st_band = nb_bands; + move16(); + + set32_fx(bits_per_bands, 0, MBANDS_GN); + /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ + bit_fracf = L_mult(div_s(1, nb_bands), shl(SWB_bit_budget, 2)); /* Q18 */ + + nb_tot_bands = sub(nb_bands_max, 6); + nb_tot_bands = s_min(nb_tot_bands, 16); + + FOR(j = 0; j < 2; j++) + { + i = j; + move16(); + max_ener_band[j] = i; + move16(); + ener_vec[i] = 0; + move16(); + } +#ifdef ADD_LRTD + if (bwidth < SWB) + { + if (coder_type == UNVOICED && element_mode > EVS_MONO) + { + nb_tot_bands = 5; + } +#endif + FOR(; j < nb_bands; j++) + { + i = maximum_fx(ener_vec, nb_tot_bands, &etmp); + max_ener_band[j] = i; + move16(); + ener_vec[i] = 0; + move16(); + } +#ifdef ADD_LRTD + } + else + { + for (; j < nb_bands; j++) + { + i = maximum(ener_vec, nb_tot_bands, &etmp); + max_ener_band[j] = i; + ener_vec[i] = fzero_val; + } + } +#endif + set32_fx(bits_per_bands, bit_fracf, nb_bands); } - pos = st_band; - move16(); - FOR(; j < nb_bands; j++) + ELSE { - i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); - pos = s_max(pos,i); - max_ener_band[j] = i; + bit_index++; + bit_tmp = sub(*bit,GSC_freq_bits[bit_index]); + bit_index++; + nb_bands_max = add(nb_bands_max,GSC_freq_bits[bit_index]); + bit_index++; + + *pvq_len = 112; move16(); - ener_vec[i] = -10; + st_band = 7; move16(); - } - - /* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */ - test(); - test(); - test(); - IF( GT_16(sub(nb_tot_bands, bandoffset),nb_bands)&&(GT_16(pos,7)&&EQ_32(core_brate,ACELP_8k00))&&EQ_16(bwidth,WB)) - { - band = sub(nb_tot_bands, add(bandoffset,nb_bands)); - FOR(j=0; j ACELP_16k40) { - i = maximum_fx( ener_vec, sub(nb_tot_bands,bandoffset), &etmp ); - max_ener_band[add(nb_bands,j)] = i; + *pvq_len = 160; + st_band = 10; + nb_bands = *pvq_len / 16; + bit_tmp -= 35; + bit_new_bands = 5; + } +#endif + IF(LE_32(core_brate,ACELP_9k60)) + { + *pvq_len = 80; move16(); - ener_vec[i] = -10; + st_band = 5; move16(); - bits_per_bands[add(nb_bands,j)] = 1310720; - move32(); /*Q18 */ + + IF(Diff_len == 0) + { + nb_bands_max = add(nb_bands_max,2); + bit_tmp = sub(bit_tmp,13); + } } - nb_bands = add(nb_bands,band); - bit_tmp = i_mult2(band,5); + ELSE IF(Diff_len == 0) + { + nb_bands_max = add(nb_bands_max,2); + bit_tmp = sub(bit_tmp,17); + } - IF( LE_16(band,2)) + nb_bands = shr(*pvq_len,4); +#ifdef ADD_LRTD + nb_bands_max = min(nb_bands_max, MBANDS_GN_BITALLOC16k); +#endif + /*------------------------------------------------------------------------ + * Ajustement of the maximum number of bands in function of the + * dynamics of the spectrum (more or less speech like) + *-----------------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + IF(EQ_16(coder_type,INACTIVE) || GE_16(noise_lev,NOISE_LEVEL_SP3)) + { + /* Probably classification error -> concentrate bits on LF */ +#ifdef ADD_LRTD + if (L_frame == L_FRAME16k && core_brate >= ACELP_24k40) + { + nb_bands_max = nb_tot_bands - 2; + } + else if (core_brate >= ACELP_16k40) + { + nb_bands_max = nb_bands + 2; + } + else +#endif + if (GE_32(core_brate,ACELP_8k00)) + { + nb_bands_max = add(nb_bands,1); + } + else + { + nb_bands_max = nb_bands; + move16(); + } + } + ELSE IF(GE_16(noise_lev,NOISE_LEVEL_SP2) || + (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0)) /* Very low dynamic, tend to speech, do not try to code HF at all */ + { + nb_bands_max = sub(nb_bands_max,2); + } + ELSE if (GE_16(noise_lev,NOISE_LEVEL_SP1)) /* Very low dynamic, tend to speech, code less HF */ + { + nb_bands_max = sub(nb_bands_max,1); + } + #ifdef ADD_LRTD + if (L_frame == L_FRAME16k) { - FOR(j = sub(st_band,1); j < nb_bands; j++) + if (core_brate < ACELP_24k40) { - bits_per_bands[j] = L_add(bits_per_bands[j],262144); /*Q18 */ move32(); + nb_bands_max -= 4; + } + else if (core_brate < ACELP_32k) + { + if (Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2) + { + nb_bands_max -= 2; + bit_new_bands *= 2; + } + } + else if (core_brate >= ACELP_32k) + { + bit_new_bands *= 2; } - bit_tmp = add(bit_tmp, add(sub(nb_bands, st_band) , 1)); } - i = 0; +#endif + test(); + if (EQ_16(bwidth,NB) && GT_16(nb_bands_max,10)) + { + nb_bands_max = 10; + move16(); + } + + /*------------------------------------------------------------------------ + * Find extra number of band to code according to bit rate availables + *-----------------------------------------------------------------------*/ + WHILE(GE_16(bit_tmp,bit_new_bands) && LE_16(nb_bands,sub(nb_bands_max,1))) + { + bit_tmp = sub(bit_tmp,bit_new_bands); + nb_bands = add(nb_bands,1); + } + + /*------------------------------------------------------------------------ + * Fractional bits to distribute on the first x bands + *-----------------------------------------------------------------------*/ +#ifdef ADD_LRTD + if (L_frame == L_FRAME16k && core_brate > ACELP_32k) + { + bit_fracf = 0; + } + else +#endif + { + bit_fracf = L_mult(div_s(1, st_band), shl(bit_tmp, 2)); /* Q18 */ + } + /*------------------------------------------------------------------------ + * Complete the bit allocation per frequency band + *-----------------------------------------------------------------------*/ + imax = 5; move16(); - j = 0; + + if (GT_32(core_brate,ACELP_9k60)) + { + imax = 7; + move16(); + } + FOR(i = 0; i < imax; i++) + { + bits_per_bands[i] = L_add(GSC_freq_bits_fx[bit_index],bit_fracf); + move32();/* Q18 */ + bit_index = add(bit_index,1); + } +#ifdef ADD_LRTD + if (L_frame == L_FRAME16k && core_brate > ACELP_16k40) + { + bit_index = 0; + i = imax - 1; + bits_per_bands[i] += Compl_GSC_freq_bits[bit_index]; + i++; + bit_index++; + + for (; i < 10; i++) + { + bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf; + bit_index++; + } + } +#endif + IF(Diff_len == 0) + { + bit_index = add(bit_index_mem,10); + FOR(i = 0; i < 7; i++) + { + bits_per_bands[i] = L_add(bits_per_bands[i],GSC_freq_bits_fx[bit_index]); + move32();/*chk Q18 */ + bit_index = add(bit_index,1); + } + } +#ifdef ADD_LRTD + if (bit_fracf < 0) + { + for (j = 0; j < nb_tot_bands; j++) + { + bits_per_bands[j] = max(bits_per_bands[j], 0); + } + } + +#endif + /*-------------------------------------------------------------------------- + * Complete the bit allocation per frequency band for 16kHz high brate mode + *--------------------------------------------------------------------------*/ +#ifdef ADD_LRTD + if (L_frame == L_FRAME16k && core_brate > ACELP_32k) + { + for (j = st_band; j < nb_bands; j++) + { + bits_per_bands[j] = bit_new_bands; + } + + bit_fracf = (1.0f / nb_bands) * (bit_tmp); + + etmp = 2.0f * bit_fracf / (nb_bands + 1); + bit_fracf = etmp; + for (j = nb_bands - 1; j >= 0; j--) + { + bits_per_bands[j] += etmp; + etmp += bit_fracf; + } + } + else +#endif + { + FOR(j = st_band; j < nb_bands; j++) + { + bits_per_bands[j] = L_shl(bit_new_bands, 18); + move32(); /*chk Q18 */ + } + } + + /*-------------------------------------------------------------------------- + * Compute a maximum band (band offset) for the search on maximal energy + * This is function of the spectral dynamic and the bitrate + *--------------------------------------------------------------------------*/ + + bandoffset = sub(nb_tot_bands,add(nb_bands,2)); + + test(); + test(); + test(); + test(); + test(); + IF(LE_16(noise_lev,NOISE_LEVEL_SP1a)) + { + bandoffset = sub(bandoffset,1); + } + ELSE if ((LE_32(core_brate,ACELP_13k20) && (EQ_16(coder_type,INACTIVE) || GE_16(noise_lev,NOISE_LEVEL_SP3))) || + (LE_32(core_brate,ACELP_13k20) && GE_32(core_brate,ACELP_9k60) && cor_strong_limit == 0)) + { + bandoffset = add(bandoffset,1); + } + + bandoffset = s_max(bandoffset ,0); + + /*-------------------------------------------------------------------------- + * Initiazed sorted vector + * For the first x bands to be included in th final sorted vector + * Sort the remaining bands in decrease energy order + *--------------------------------------------------------------------------*/ + FOR(j = 0; j < nb_tot_bands; j++) + { + max_ener_band[j] = -10; + move16(); + } + FOR(j = 0; j < st_band; j++) + { + max_ener_band[j] = j; + move16(); + ener_vec[j] = -10; + move16(); + } + pos = st_band; move16(); - FOR( ; bit_tmp > 0; bit_tmp--) + FOR(; j < nb_bands; j++) { - bits_per_bands[j] = L_sub(bits_per_bands[j],262144); /*Q18 */ - j = add(j,1); - if ( EQ_16(j,sub(st_band, i))) + i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); + pos = s_max(pos,i); + max_ener_band[j] = i; + move16(); + ener_vec[i] = -10; + move16(); + } + + /* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */ + test(); + test(); + test(); + IF(GT_16(sub(nb_tot_bands, bandoffset),nb_bands) && (GT_16(pos,7) && EQ_32(core_brate,ACELP_8k00)) && EQ_16(bwidth,WB)) + { + band = sub(nb_tot_bands, add(bandoffset,nb_bands)); + FOR(j = 0; j < band; j++) { - j = 0; + i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); + max_ener_band[add(nb_bands,j)] = i; move16(); + ener_vec[i] = -10; + move16(); + bits_per_bands[add(nb_bands,j)] = 1310720; + move32(); /*Q18 */ + } + nb_bands = add(nb_bands,band); + + bit_tmp = i_mult2(band,5); + + IF(LE_16(band,2)) + { + FOR(j = sub(st_band,1); j < nb_bands; j++) + { + bits_per_bands[j] = L_add(bits_per_bands[j],262144); /*Q18 */ move32(); + } + bit_tmp = add(bit_tmp, add(sub(nb_bands, st_band) , 1)); } - test(); - if( j == 0 && LT_16(i,sub(st_band, 1))) + + i = 0; + move16(); + j = 0; + move16(); + FOR(; bit_tmp > 0; bit_tmp--) { - i = add(i,1); + bits_per_bands[j] = L_sub(bits_per_bands[j],262144); /*Q18 */ + j = add(j,1); + if (EQ_16(j,sub(st_band, i))) + { + j = 0; + move16(); + } + test(); + if (j == 0 && LT_16(i,sub(st_band, 1))) + { + i = add(i,1); + } } } } - } - /*-------------------------------------------------------------------------- - * Bit sum verification for GSC inactive at very high rate - * The maximum number of bits per band of length 16 is 112 - * Redistribute the overage bits if needed - *--------------------------------------------------------------------------*/ - sum_bit = 0; - move16(); - j = 0; - move16(); - FOR( i = 0; i < nb_bands; i++ ) - { - L_tmp = Mult_32_16(sum_bit,10923); + /*-------------------------------------------------------------------------- + * Bit sum verification for GSC inactive at very high rate + * The maximum number of bits per band of length 16 is 112 + * Redistribute the overage bits if needed + *--------------------------------------------------------------------------*/ + sum_bit = 0; + move16(); + j = 0; + move16(); + FOR(i = 0; i < nb_bands; i++) + { + L_tmp = Mult_32_16(sum_bit, 10923); - IF( GT_32(bits_per_bands[i],29360128)) /* 112 in Q18 */ + IF(GT_32(bits_per_bands[i], 29360128)) /* 112 in Q18 */ + { + sum_bit = L_add(sum_bit, L_sub(bits_per_bands[i], 29360128)); /* Q18 */ + bits_per_bands[i] = 29360128; + move32(); + j = add(i, 1); + } + ELSE if (GT_32(L_add(bits_per_bands[i], L_tmp), 29360128)) /* Q18 */ + { + j = add(i, 1); + } + } + + IF(sum_bit != 0) { - sum_bit = L_add(sum_bit,L_sub(bits_per_bands[i],29360128)); /* Q18 */ - bits_per_bands[i] = 29360128; - move32(); - j = add(i,1); + tmp = sub(nb_bands, j); + sum_bit = Mult_32_16(sum_bit, div_s(1, tmp)); /* Q18 */ + FOR(i = j; i < nb_bands; i++) + { + bits_per_bands[i] = L_add(bits_per_bands[i], sum_bit); + move32();/* Q18 */ + } } - ELSE if( GT_32(L_add(bits_per_bands[i],L_tmp),29360128 )) /* Q18 */ + /*-------------------------------------------------------------------------- + * second step of bit sum verification, normally sum_bit == *bit + *--------------------------------------------------------------------------*/ + w_sum_bit = 0; + move16(); + FOR(i = 0; i < nb_bands; i++) { - j = add(i,1); + out_bits_per_bands[i] = shl(extract_l(L_shr(bits_per_bands[i], 18)), 3); + move16(); + w_sum_bit = add(w_sum_bit, out_bits_per_bands[i]); /* Q3 */ } - } - - IF( sum_bit != 0 ) - { - tmp = sub(nb_bands,j); - sum_bit = Mult_32_16(sum_bit,div_s(1,tmp)); /* Q18 */ - FOR( i = j; i < nb_bands; i++ ) + tmp = shl(*bit, 3); +#ifdef ADD_LRTD + if (GSC_IVAS_mode != 0 && sum_bit < *bit) /* If we need to add bits, we are doing it on the LF */ { - bits_per_bands[i] = L_add(bits_per_bands[i],sum_bit); - move32();/* Q18 */ + reajust_bits(bits_per_bands, 0, nb_bands, (int16_t)sum_bit, *bit); } - } - /*-------------------------------------------------------------------------- - * second step of bit sum verification, normally sum_bit == *bit - *--------------------------------------------------------------------------*/ - w_sum_bit = 0; - move16(); - FOR( i = 0; i < nb_bands; i++ ) - { - out_bits_per_bands[i] = shl(extract_l(L_shr(bits_per_bands[i],18)),3); + else + { + reajust_bits(bits_per_bands, nb_bands - 1, 0, (int16_t)sum_bit, *bit); + } +#else + IF(GT_16(tmp, w_sum_bit)) + { + i = sub(nb_bands, 1); + move16(); + FOR(; tmp > w_sum_bit; w_sum_bit += (1 << 3)) + { + out_bits_per_bands[i] = add(out_bits_per_bands[i], 1 << 3); + move16(); + i = sub(i, 1); + if (i == 0) + { + i = sub(nb_bands, 1); + } + } + } +#endif + /*-------------------------------------------------------------------------- + * Recompute the real number/length of frequency bands to encode + *--------------------------------------------------------------------------*/ + * nb_subbands = nb_bands; move16(); - w_sum_bit = add(w_sum_bit,out_bits_per_bands[i]); /* Q3 */ - } - tmp = shl(*bit,3); + *pvq_len = shl(*nb_subbands, 4); - IF( GT_16(tmp,w_sum_bit)) - { - i = sub(nb_bands,1); - move16(); - FOR( ; tmp > w_sum_bit; w_sum_bit += (1<<3) ) + /*-------------------------------------------------------------------------- + * Concatenate bands (encoder only) + *--------------------------------------------------------------------------*/ + IF(exc_diff != NULL) { - out_bits_per_bands[i] = add(out_bits_per_bands[i],1<<3); - move16(); - i = sub(i, 1); - if(i==0) + FOR(j = 0; j < nb_bands; j++) { - i = sub(nb_bands,1); + Copy(exc_diff + shl(max_ener_band[j], 4), concat_in + shl(j, 4), 16); } } +#ifdef ADD_LRTD + } + else /* *bit == 0 */ + { + set_s(bits_per_bands_s, 0, nb_tot_bands); + *nb_subbands = 0; + *pvq_len = 0; + } +#endif + return; +} +#ifdef ADD_LRTD +/*-------------------------------------------------------------------* + * reajust_bits() + * + * + *-------------------------------------------------------------------*/ + +static void reajust_bits( + float* bits_per_bands, + const int16_t st_band, + const int16_t end_band, + const int16_t sum_bit_in, + const int16_t bit_bdgt_in) +{ + int16_t i, amount_to_add, incr; + int16_t bit_bdgt, sum_bit; + + incr = 1; + if (end_band < st_band) + { + incr = -1; + } + + if (bit_bdgt_in < sum_bit_in) + { + amount_to_add = -1; + bit_bdgt = sum_bit_in; + sum_bit = bit_bdgt_in; + } + else + { + bit_bdgt = bit_bdgt_in; + sum_bit = sum_bit_in; + amount_to_add = 1; } - /*-------------------------------------------------------------------------- - * Recompute the real number/length of frequency bands to encode - *--------------------------------------------------------------------------*/ - *nb_subbands = nb_bands; - move16(); - *pvq_len = shl(*nb_subbands,4); - /*-------------------------------------------------------------------------- - * Concatenate bands (encoder only) - *--------------------------------------------------------------------------*/ - IF( exc_diff != NULL ) + i = st_band; + while (bit_bdgt > sum_bit) { - FOR( j = 0; j < nb_bands; j++ ) + if (amount_to_add > 0 || (amount_to_add < 0 && bits_per_bands[i] > 1)) { - Copy( exc_diff + shl(max_ener_band[j],4), concat_in+shl(j,4), 16 ); + bits_per_bands[i] += amount_to_add; + sum_bit += (int16_t)abs(amount_to_add); + } + + i += incr; + if (i == end_band) + { + i = st_band; } } return; } + +#endif \ No newline at end of file diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 438c750..43bf6c9 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -421,7 +421,7 @@ Word16 gsc_gaindec_fx( /* o : average frequency gain */ * Quantization of the energy per band *-------------------------------------------------------------------*/ Word16 gsc_gainQ_fx( /*Q12*/ - Encoder_State_fx *st_fx, /* i/o: decoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 y_gain4[], /* i : Energy per band Q12 */ Word16 y_gainQ[], /* o : quantized energy per band Q12 */ const Word32 core_brate, /* i : Core rate */ @@ -470,7 +470,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ /* Quantized mean gain without clipping */ mean_4g[0] = round_fx(L_tmp); idx_g = vquant_fx(mean_4g, Gain_meanNB_fx, mean_4g, Gain_mean_dicNB_fx, 1, 64); - push_indice_fx( st_fx, IND_MEAN_GAIN2, idx_g, 6 ); + push_indice_fx( hBstr, IND_MEAN_GAIN2, idx_g, 6 ); FOR(i = 0; i < Mbands_gn; i++) { @@ -482,21 +482,21 @@ Word16 gsc_gainQ_fx( /*Q12*/ move16(); set16_fx(y_gain_tmp+10, 0, MBANDS_GN-10); idx_g = vquant_fx(y_gain_tmp, Mean_dic_NB_fx, y_gain_tmp, Gain_dic1_NB_fx, 3, 64); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 6 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); IF(LT_32(core_brate,ACELP_9k60)) { idx_g = vquant_fx(y_gain_tmp+3, Mean_dic_NB_fx+3, y_gain_tmp+3, Gain_dic2_NB_fx, 3, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); idx_g = vquant_fx(y_gain_tmp+6, Mean_dic_NB_fx+6, y_gain_tmp+6, Gain_dic3_NB_fx, 4, 16); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 4 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); } ELSE { idx_g = vquant_fx(y_gain_tmp+3, Mean_dic_NB_fx+3, y_gain_tmp+3, Gain_dic2_NBHR_fx, 3, 64); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 6 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); idx_g = vquant_fx(y_gain_tmp+6, Mean_dic_NB_fx+6, y_gain_tmp+6, Gain_dic3_NBHR_fx, 4, 128); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 7 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 7 ); }/*add end */ test(); @@ -559,7 +559,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ /*idx_g = (short)vquant(mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64);*/ idx_g = vquant_fx(mean_4g, mean_m_fx, mean_4g, mean_gain_dic_fx, 1, 64); - push_indice_fx( st_fx, IND_MEAN_GAIN2, idx_g, 6 ); + push_indice_fx( hBstr, IND_MEAN_GAIN2, idx_g, 6 ); FOR(i = 0; i < Mbands_gn; i++) { @@ -585,13 +585,13 @@ Word16 gsc_gainQ_fx( /*Q12*/ /*idx_g = (short)vquant(y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32);*/ idx_g = vquant_fx(y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 ); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); /*idx_g = (short)vquant(y_gain_tmp2+3, YGain_mean_LR+3, y_gain_tmp2+3, YGain_dic2_LR, 4, 32);*/ idx_g = vquant_fx(y_gain_tmp2+3, YGain_mean_LR_fx+3, y_gain_tmp2+3, YGain_dic2_LR_fx, 4, 32 ); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); /*idx_g = (short)vquant(y_gain_tmp2+7, YGain_mean_LR+7, y_gain_tmp2+7, YGain_dic3_LR, 5, 32);*/ idx_g = vquant_fx(y_gain_tmp2+7, YGain_mean_LR_fx+7, y_gain_tmp2+7, YGain_dic3_LR_fx, 5, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); /*set_f(y_gain_tmp2+12, 0, MBANDS_GN-12);*/ set16_fx(y_gain_tmp2+12, 0, MBANDS_GN-12); @@ -625,13 +625,13 @@ Word16 gsc_gainQ_fx( /*Q12*/ ELSE { idx_g = vquant_fx(y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 6 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); idx_g = vquant_fx(y_gain_tmp+4, YG_mean16_fx+4, y_gain_tmp+4, YG_dicMR_2_fx, 4, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); idx_g = vquant_fx(y_gain_tmp+8, YG_mean16_fx+8, y_gain_tmp+8, YG_dicMR_3_fx, 4, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); idx_g = vquant_fx(y_gain_tmp+12, YG_mean16_fx+12, y_gain_tmp+12, YG_dicMR_4_fx, 4, 16); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 4 ); + push_indice_fx( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); } } diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index a92a719..73aa990 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -84,7 +84,7 @@ void Inac_swtch_ematch_fx( ELSE IF( EQ_16(coder_type,VOICED)||EQ_16(coder_type,GENERIC)||EQ_16(coder_type,TRANSITION)||NE_16(last_core,ACELP_CORE)||NE_16(last_codec_mode,MODE1)) { /* Find spectrum and energy per band for GC and VC frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5 ); + edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO); Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1); @@ -98,7 +98,7 @@ void Inac_swtch_ematch_fx( ELSE IF( EQ_16(coder_type,INACTIVE)&&LE_32(core_brate,ACELP_24k40)) { /* Find spectrum and energy per band for inactive frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5 ); + edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO); Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); /* More agressive smoothing in the first 50 frames */ @@ -146,7 +146,7 @@ void Inac_swtch_ematch_fx( } /* Going back to time */ - edct_16fx( dct_exc_tmp, exc2, L_frame, 5 ); + edct_16fx( dct_exc_tmp, exc2, L_frame, 5 , EVS_MONO); } return; diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 4c83b66..008970d 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" #include "rom_com_fx.h" #include "prot_fx.h" -#include "stl.h" /*-------------------------------------------------------------------* * gs_noisf() @@ -16,11 +15,11 @@ static void gs_noisf_fx( const Word16 Start_BIN, /* i : First bin for noise fill */ const Word16 NB_Qbins, /* i : Number of bin per band */ - const Word16 Noise_fac, /* i : Noise level Q15 */ - const Word16 *y_norm, /* i : Quantized pulses Qn */ - Word16 *exc_diffQ, /* o : Quantized pulses with noise added Qn */ - Word16 *seed_tcx, /* i : Random generator seed */ - const Word16 coder_type, /* i : coder type */ + const Word16 Noise_fac, /* i : Noise level Q15 */ + const Word16 *y_norm, /* i : Quantized pulses Qn */ + Word16 *exc_diffQ, /* o : Quantized pulses with noise added Qn */ + Word16 *seed_tcx, /* i : Random generator seed */ + const Word16 coder_type, /* i : coder type */ Word16 qNoise_fac ) { @@ -153,15 +152,16 @@ static void EstimateNoiseLevel_inner_fx( /* _ None */ /*==========================================================================*/ static void EstimateNoiseLevel_fx( - Word16 *noisepb, /* o : Noise per band */ - const Word32 bitrate, /* i : Bitrate of the codec */ - const Word16 Diff_len, /* i : number of bin before cut-off frequency */ - const Word16 Mbands_gn, /* i : number of bands */ - const Word16 coder_type, /* i : coder type */ - const Word16 noise_lev, /* i : pulses dynamic */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 last_bin, /* i : the last bin of bit allocation */ - Word16 bwidth + Word16 *noisepb, /* o : Noise per band */ + const Word32 bitrate, /* i : Bitrate of the codec */ + const Word16 Diff_len, /* i : number of bin before cut-off frequency */ + const Word16 Mbands_gn, /* i : number of bands */ + const Word16 coder_type, /* i : coder type */ + const Word16 noise_lev, /* i : pulses dynamic */ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + Word16 last_bin, /* i : the last bin of bit allocation */ + Word16 bwidth, + const int16_t L_frame /* i : frame length */ ) { Word16 i_band; @@ -169,7 +169,7 @@ static void EstimateNoiseLevel_fx( i_band = 0; move16(); - IF( LT_16(Diff_len,L_FRAME)) + IF( LT_16(Diff_len, L_frame)) { EstimateNoiseLevel_inner_fx(noisepb, bitrate, i_band, MBANDS_GN); IF( coder_type != INACTIVE ) @@ -195,7 +195,7 @@ static void EstimateNoiseLevel_fx( } } test(); - IF ( (EQ_16(coder_type,INACTIVE)||GE_16(noise_lev,NOISE_LEVEL_SP3))) + IF ( (EQ_16(coder_type,INACTIVE)||GE_16(noise_lev,NOISE_LEVEL_SP3)) && EQ_16(L_frame, L_FRAME)) { FOR( i_band = 9; i_band < Mbands_gn; i_band++ ) { @@ -203,6 +203,39 @@ static void EstimateNoiseLevel_fx( move16();/*noisepb[i_band]*1.15=noisepb[i_band] *(1 + 0.15) */ } } + ELSE IF(EQ_16(L_frame, L_FRAME16k)) + { + IF (EQ_32(bitrate, ACELP_13k20)) + { + set16_fx(noisepb, 14746/*0.45*/, Mbands_gn); + } + + IF (EQ_16(coder_type, INACTIVE)) + { + FOR (; i_band < Mbands_gn; i_band++) + { + noisepb[i_band] = 13107/*.4f*/; + move16(); + } + } + ELSE IF (LE_16(noise_lev, NOISE_LEVEL_SP1) && GT_32(bitrate, ACELP_16k40)) + { + FOR (; i_band < sub(Mbands_gn, 4); i_band++) + { + noisepb[i_band] = mult_r(noisepb[i_band], 19661)/*.6f*/; + move16(); + } + } + ELSE IF (LE_16(noise_lev, NOISE_LEVEL_SP2) && GT_32(bitrate, ACELP_16k40)) + { + FOR (; i_band < sub(Mbands_gn, 4); i_band++) + { + noisepb[i_band] = mult_r(noisepb[i_band], 26214)/*.8f*/; + move16(); + } + } + } + return; } @@ -289,7 +322,9 @@ void freq_dnw_scaling_fx( const Word16 noise_lev, /* i : Noise level */ const Word32 core_brate, /* i : Core bitrate */ Word16 fy_norm[], /* i/o: Frequency quantized parameter */ - Word16 Qx /* Q format of fy_norm*/ + Word16 Qx, /* Q format of fy_norm*/ + const int16_t L_frame /* i : frame length */ + ) { Word16 sc_dyn; @@ -297,7 +332,7 @@ void freq_dnw_scaling_fx( sc_dyn = 32767; move16(); /*Q15 */ - start_sc = L_FRAME; + start_sc = L_frame; move16(); test(); IF( LE_32(core_brate,ACELP_8k00)&&EQ_16(coder_type,INACTIVE)) @@ -324,7 +359,13 @@ void freq_dnw_scaling_fx( } } - FOR(i = start_sc; i < L_FRAME; i++) + IF (EQ_16(L_frame, L_FRAME16k) && LE_32(core_brate, ACELP_24k40)) + { + /*sc_dyn += 0.125f;*/ + sc_dyn = add(sc_dyn, 4096); /* Saturates to 1.0 */ + } + + FOR(i = start_sc; i < L_frame; i++) { fy_norm[i] = mult_r(fy_norm[i],sc_dyn); move16();/*Qx */ @@ -334,7 +375,7 @@ void freq_dnw_scaling_fx( test(); IF( (LT_32(core_brate,ACELP_13k20)&&cor_strong_limit==0)||LT_32(core_brate,ACELP_9k60)) { - FOR(i = 160; i < L_FRAME; i++) + FOR(i = 160; i < L_frame; i++) { fy_norm[i] = s_min(fy_norm[i],shl(1,Qx)); move16(); @@ -344,7 +385,7 @@ void freq_dnw_scaling_fx( } ELSE IF ( LT_32(core_brate,ACELP_22k60)) { - FOR(i = 160; i < L_FRAME; i++) + FOR(i = 160; i < L_frame; i++) { fy_norm[i] = s_min(fy_norm[i],shr_r(1536,sub(10,Qx))); move16(); @@ -358,7 +399,7 @@ void freq_dnw_scaling_fx( } static void Decreas_freqPeak_fx( - Word16 *lsf_new, /* i : ISFs at the end of the frame */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ Word16 *exc_diffQ, /* i/o: frequency coefficients of per band */ Word16 rat /* i : threshold of ratio between consecutive lsf_new_diff */ ) @@ -366,7 +407,7 @@ static void Decreas_freqPeak_fx( Word16 i, j, k; Word16 last_bin = 0; Word16 pos = 0; - Word16 *src, max,avrg; + Word16 *src, max_val,avrg; Word32 L_avrg,L_tmp; Word16 lsf_new_diff[M]; Word16 tmp,tmp1,exp; @@ -382,13 +423,13 @@ static void Decreas_freqPeak_fx( avrg = 0; move16(); L_avrg = L_deposit_l(0); - max = 1; + max_val = 1; move16(); FOR(i=160; i 0 && EQ_16(GSC_noisy_speech, 1))) + { + set16_fx(noisepb, 13107/*0.4f*/, MBANDS_GN16k); + } ELSE { - EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, - last_bin_tmp, bwidth ); + EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame ); } IF( exc_wo_nf != NULL ) { - Copy( exc_diffQ, exc_wo_nf, L_FRAME ); + Copy( exc_diffQ, exc_wo_nf, L_frame); } test(); - IF( GSC_noisy_speech && !bfi ) + + IF(GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16(element_mode, IVAS_SCE)) { set16_fx( noisepb, 3277, MBANDS_GN ); } - Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ ); - + IF (LT_32(core_brate, 6000) && LE_16(coder_type, UNVOICED)) + { + FOR (i = 0; i < L_frame; i++) + { + IF (exc_diffQ[i] == 0) + { + PMT("code below to be validated for IVAS use") + /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/ + tmp = mult(shl(noisepb[0],1), Random(seed_tcx));/*Q15 */ + tmp = shr(tmp, sub(15, Qexc_diffQ));/*qNoise_fac */ + exc_diffQ[i] = add(exc_diffQ[i], tmp); + move16();/*Q */ + } + } + } + ELSE + { + Apply_NoiseFill_fx(exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ); + } /*--------------------------------------------------------------------------------------* * Quantize average gain - * Substract Q averaged gain + * Subtract Q averaged gain * VQ of remaining gain per band *--------------------------------------------------------------------------------------*/ test(); @@ -722,7 +796,7 @@ void highband_exc_dct_in_fx( { Ener_per_band_comp_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 ); - IF( LT_16(nb_subfr, 4)) + IF( LT_16(nb_subfr, 4) && LT_16(L_frame, L_FRAME16k)) { FOR(i = L_FRAME-16; i < L_FRAME; i++) { @@ -777,21 +851,81 @@ void highband_exc_dct_in_fx( /*--------------------------------------------------------------------------------------* * Apply decoded gain onto the difference signal *--------------------------------------------------------------------------------------*/ +#ifdef ADD_LRTD + if (GSC_IVAS_mode >= 1) + { + float scale_factLF = 0.9f; + float scale_factHF = 0.9f; + + if (GSC_IVAS_mode == 1 && GSC_noisy_speech == 0) + { + scale_factHF = 0.8f; + } + else if (GSC_IVAS_mode == 2 || GSC_noisy_speech == 1) + { + scale_factHF = 0.71f; + } + else if (GSC_IVAS_mode == 3) + { + scale_factHF = 0.9f; + } + for (i = 0; i < pit_band_idx * 16; i++) + { + exc_diffQ[i] *= scale_factLF; + } + for (; i < L_frame; i++) + { + exc_diffQ[i] *= scale_factHF; + } + } + else if (GSC_noisy_speech) + { + float scale_fact = 0.9f; + + if (element_mode == IVAS_CPE_TD) + { + if (coder_type == INACTIVE) + { + scale_fact = 1.0f; + } + else + { + scale_fact = 0.95f; + } + } + else if (element_mode > IVAS_SCE) + { + scale_fact = 0.71f; + } + + for (i = 0; i < L_frame; i++) + { + exc_diffQ[i] *= scale_fact; + } + } + if (GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20) + { + for (i = 80; i < L_frame; i++) + { + exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); + } + } +#else IF( GSC_noisy_speech ) { - FOR( i= 0; i < L_FRAME; i++ ) + FOR( i= 0; i < L_frame; i++ ) { exc_diffQ[i] = mult_r(exc_diffQ[i], 29491); move16(); } } - +#endif Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc ); IF( exc_wo_nf != NULL ) { Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1 , Qexc_diffQ, Q_exc); - Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_FRAME ); + Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } /*--------------------------------------------------------------------------------------* * add the correction layer to the LF bins, @@ -800,7 +934,7 @@ void highband_exc_dct_in_fx( * DC is Zeroed *--------------------------------------------------------------------------------------*/ - Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_FRAME ); + Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame ); test(); IF( core_brate == ACELP_8k00 && bwidth != NB ) { @@ -913,7 +1047,7 @@ void highband_exc_dct_in_fx( } } - Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_FRAME-64 ); + Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame-64 ); Copy(&bitallocation_band[4], last_bitallocation_band, 6); *last_ener = ener; move16(); diff --git a/lib_com/gs_preech_fx.c b/lib_com/gs_preech_fx.c index 75928b7..17bf45e 100644 --- a/lib_com/gs_preech_fx.c +++ b/lib_com/gs_preech_fx.c @@ -2,21 +2,23 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ +#define ATT_LENGHT16k 80 +/*#define INV_L_FRAME16k ( 1.0f / L_FRAME16k )*/ #define ATT_LENGHT 64 #define ATT_SEG_LEN (L_FRAME/ATT_LENGHT) -#define INV_ATT_SEG_LEN (1.0f/ATT_SEG_LEN) -#define INV_L_FRAME (1.0f/L_FRAME) +/*#define INV_ATT_SEG_LEN (1.0f/ATT_SEG_LEN)*/ +/*#define INV_L_FRAME (1.0f/L_FRAME)*/ /*==========================================================================*/ /* FUNCTION : void pre_echo_att_fx(); */ @@ -39,38 +41,46 @@ /* _ None */ /*==========================================================================*/ void pre_echo_att_fx( - Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx /* i : flag signalling attack encoded by AC mode (GSC) */ - ,const Word16 Q_new - ,const Word16 last_coder_type_fx /* i : Last coding mode */ + Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ + Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 Q_new, + const Word16 last_coder_type_fx, /* i : Last coding mode */ + const Word16 L_frame /* i : Frame length*/ ) { Word32 etmp_fx; - Word32 finc_fx[ATT_LENGHT] = {0}; + Word32 finc_fx[ATT_LENGHT16k] = {0}; Word16 ratio_fx; Word16 attack_pos_fx, i; Word32 L_tmp, L_tmp1; Word16 tmp, n1, n2, exp, frac1, frac2; Word32 etmp1_fx; + Word16 att_len; + test(); - IF ( EQ_16(gsc_attack_flag_fx,1)&&EQ_16(last_coder_type_fx,AUDIO)) /*gsc_attack_flag_fx does not get set for all the test cases */ + IF ( GT_16(gsc_attack_flag_fx,0) && EQ_16(last_coder_type_fx,AUDIO)) /*gsc_attack_flag_fx does not get set for all the test cases */ { /*-------------------------------------------------------------------------* * Find where the onset (attack) occurs by computing the energy per section * The inverse weighting aims to favor the first maxima in case of * gradual onset *-------------------------------------------------------------------------*/ - FOR(i = 0; i < ATT_LENGHT; i++) + att_len = ATT_LENGHT; + if (L_frame == L_FRAME16k) + { + att_len = ATT_LENGHT16k; + } + FOR(i = 0; i < att_len; i++) { L_tmp = sum2_fx(&exc_fx[shl(i,2)], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s(sub(ATT_LENGHT,i),ATT_LENGHT); /*Q15 */ + tmp = div_s(sub(att_len,i),att_len); /*Q15 */ L_tmp = Mult_32_16(L_tmp, tmp); /*2*Q_new+1 */ finc_fx[i] = L_tmp; move32(); /*2*Q_new+1 */ } - attack_pos_fx = maximum_32_fx(finc_fx, ATT_LENGHT, &etmp_fx); + attack_pos_fx = maximum_32_fx(finc_fx, att_len, &etmp_fx); /* Scaled the maximum energy and allowed 6 dB increase*/ etmp_fx = L_shr(etmp_fx,add(2+1-4, shl(Q_new,1)));/*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */ @@ -128,9 +138,13 @@ void pre_echo_att_fx( * In normal cases, just compute the energy of the frame *-------------------------------------------------------*/ - etmp_fx = sum2_fx( exc_fx, L_FRAME ); /*2*Q_new+1 */ - + etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */ +#ifdef ADD_LRTD + PMTE() + etmp_fx = L_shr(etmp_fx, add(8 + 1 - 4, shl(Q_new, 1))); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ +#else etmp_fx = L_shr(etmp_fx,add(8+1-4, shl(Q_new,1))); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ +#endif *Last_frame_ener_fx = etmp_fx; move32(); /*2*Q_new+1*/ } diff --git a/lib_com/guided_plc_util.c b/lib_com/guided_plc_util.c index 5c1fa7d..12061e6 100644 --- a/lib_com/guided_plc_util.c +++ b/lib_com/guided_plc_util.c @@ -2,14 +2,31 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include +#include "options.h" #include "prot_fx.h" -#include "stl.h" #include "rom_com_fx.h" - #include "basop_util.h" #include "rom_basop_util.h" -void getLookAheadResSig( Word16 *speechLookAhead, Word16 *A_3Q12, Word16 *res, Word16 L_frame, Word16 numSubFrame ) + /*-------------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------------*/ +static void reorder_lsfs(Word16* lsf, const Word16 min_dist, const Word16 n, const Word32 sr_core); + + +/*-------------------------------------------------------------------* + * getLookAheadResSig() + * + * + *-------------------------------------------------------------------*/ +void getLookAheadResSig( + Word16 *speechLookAhead, + Word16 *A_3Q12, + Word16 *res, + const Word16 L_frame, + const Word16 numSubFrame +) { Word16 *p_A; Word16 i_subfr; @@ -25,12 +42,8 @@ void getLookAheadResSig( Word16 *speechLookAhead, Word16 *A_3Q12, Word16 *res, W FOR(i_subfr=0; i_subfrlsfoldbfi1_14Q1[i] ); L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); @@ -59,8 +80,19 @@ void updateLSFForConcealment( HANDLE_PLC_ENC_EVS decState, Word16 *lsf_14Q1, Wor return; } - -void getConcealedLP( HANDLE_PLC_ENC_EVS memDecState, Word16 *AqCon, const Word16 lsfBase[], Word16 last_good, Word16 L_frame) +/*-------------------------------------------------------------------* + * getConcealedLP() + * + * + *-------------------------------------------------------------------*/ + +void getConcealedLP( + PLC_ENC_EVS_HANDLE memDecState, + Word16 *AqCon, + const Word16 lsfBase[], + const Word16 last_good, + const Word16 L_frame +) { Word16 *lsf; Word16 lsp[(NB_DIV+1)*M]; @@ -72,14 +104,8 @@ void getConcealedLP( HANDLE_PLC_ENC_EVS memDecState, Word16 *AqCon, const Word16 dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold_14Q1, last_good, 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &(memDecState->stab_fac_Q15), memDecState->lsf_adaptive_mean_14Q1, - 1, - NULL, - 0, - NULL, - NULL, - lsfBase, - 0 - ); + 1, NULL, 0, NULL, NULL, lsfBase, 0); + Copy( memDecState->lspold_Q15, lsp, M ); int_fs = INT_FS_FX; @@ -95,29 +121,41 @@ void getConcealedLP( HANDLE_PLC_ENC_EVS memDecState, Word16 *AqCon, const Word16 return; } - -void getConcealedLSF( HANDLE_PLC_ENC_EVS memDecState, const Word16 lsfBase[], Word16 last_good, Word16 L_frame) +/*-------------------------------------------------------------------* + * getConcealedLSF() + * + * + *-------------------------------------------------------------------*/ +void getConcealedLSF( + PLC_ENC_EVS_HANDLE memDecState, + const Word16 lsfBase[], + const Word16 last_good, + const Word16 L_frame +) { Word16 *lsf = memDecState->lsf_con; dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold_14Q1, last_good, 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &(memDecState->stab_fac_Q15), memDecState->lsf_adaptive_mean_14Q1, - 1, - NULL, - 0, - NULL, - NULL, - lsfBase, - 0 - ); + 1, NULL, 0, NULL, NULL, lsfBase, 0); return; } -static void reorder_lsfs(Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 sr_core); - -void RecLpcSpecPowDiffuseLc( Word16 *lspq, Word16 *lsp_old, Word16 *lsfq, Decoder_State_fx *st, Word16 reset_q ) +/*-------------------------------------------------------------------* + * RecLpcSpecPowDiffuseLc() + * + * + *-------------------------------------------------------------------*/ + +void RecLpcSpecPowDiffuseLc( + Word16 *lspq, + Word16 *lsp_old, + Word16 *lsfq, + Decoder_State_fx *st, + const Word16 reset_q +) { const Word16 *means; Word16 lsf_old[M]; @@ -153,12 +191,16 @@ void RecLpcSpecPowDiffuseLc( Word16 *lspq, Word16 *lsp_old, Word16 *lsfq, Decode return; } - +/*-------------------------------------------------------------------* + * modify_lsf() + * + * + *-------------------------------------------------------------------*/ void modify_lsf( Word16 *lsf, const Word16 n, - const Word32 sr_core - , Word16 reset_q + const Word32 sr_core, + const Word16 reset_q ) { Word16 i, k, th_x1p28_Q14; @@ -167,7 +209,7 @@ void modify_lsf( th_x1p28_Q14 = 4864/*1900.0f*1.28f Q1*/; move16(); - if( EQ_32( sr_core, 16000 )) + if( EQ_32( sr_core, INT_FS_16k)) { th_x1p28_Q14 = 6080/*2375.0f*1.28f Q1*/; move16(); @@ -176,7 +218,7 @@ void modify_lsf( IF( reset_q == 0 ) { th_x1p28_Q14 = 2048; /* 800.0f*1.28f Q1*/ move16(); - if( EQ_32( sr_core, 16000 )) + if( EQ_32( sr_core, INT_FS_16k)) { th_x1p28_Q14 = 2560; /*1000.0f*1.28f Q1*/ move16(); } @@ -226,7 +268,7 @@ static void reorder_lsfs( fs2 = 16384/*6400.0 * 1.28 Q1*/; move16(); - if(EQ_32(sr_core, 16000)) + if(EQ_32(sr_core, INT_FS_16k)) { fs2 = 20480/*8000.0 * 1.28 Q1*/; move16(); @@ -235,7 +277,7 @@ static void reorder_lsfs( /*-----------------------------------------------------------------* * Verify the LSF ordering and minimum GAP *-----------------------------------------------------------------*/ - IF( EQ_32( sr_core, 16000 )) + IF( EQ_32( sr_core, INT_FS_16k)) { th1 = 3200; move16(); diff --git a/lib_com/hp50.c b/lib_com/hp50.c index 93b5219..a942ffd 100644 --- a/lib_com/hp50.c +++ b/lib_com/hp50.c @@ -3,11 +3,11 @@ ====================================================================================*/ +#include +#include "options.h" #include -#include "stl.h" #include "prot_fx.h" #include "basop_util.h" -#include "options.h" #define HP20_COEFF_SCALE (2) @@ -138,17 +138,17 @@ static void filter_2nd_order( } -void hp20(Word16 signal[], /* i/o: signal to filter any */ - const Word16 stride, /* i : stride to be applied accessing signal */ - const Word16 lg, /* i : length of signal (integer) Q0 */ - Word32 mem[5], /* i/o: static filter memory with this layout: */ +void hp20(Word16 signal[], /* i/o: signal to filter any */ + const Word16 stride, /* i : stride to be applied accessing signal */ + const Word16 lg, /* i : length of signal (integer) Q0 */ + Word32 mem[5], /* i/o: static filter memory with this layout: */ /* mem[0]: y[-2] (32-bit) */ /* mem[1]; y[-1] (32-bit) */ /* mem[2]: x[-2] << 16 */ /* mem[3]: x[-1] << 16 */ /* Note: mem[0..3] need to be scaled per frame */ /* mem[4]: states scale */ - const Word32 sFreq) /* i : input sampling rate Q0 */ + const Word32 sFreq) /* i : input sampling rate Q0 */ { Word32 a1, b1, a2, b2; Word16 prescale, prescaleOld, diff; @@ -232,15 +232,8 @@ void hp20(Word16 signal[], /* i/o: signal to filter any */ } - filter_2nd_order(signal, - stride, - prescale, - lg, - mem, - a1, - a2, - b1, - b2); + filter_2nd_order(signal, stride, prescale, lg, + mem, a1, a2, b1, b2); return; } diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 802ffc0..7f1866b 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -2,9 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" #include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ #define MIN_BITS_FIX 0 /* QRk=18 */ #define HQ_16k40_BIT (HQ_16k40/50) /* 16400/50=328 */ @@ -228,12 +228,12 @@ void Bits2indvsb_fx ( void hq2_bit_alloc_har_fx ( const Word32 *L_y, /* i : Qbe band energy of sub-vectors */ - Word16 B_fx, /* i : Q0 number of available bits */ + Word16 B_fx, /* i : Q0 number of available bits */ const Word16 N_fx, /* i : Q0 number of sub-vectors */ - Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : highfreq bands */ + Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ + Word16 p2a_bands_fx, /* i : highfreq bands */ const Word32 L_core_brate, /* i : Q0 core bit rate */ - Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ + Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ const Word16 band_width_fx[] /* i : Q0 table of band_width */ ) { diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index 8fd73d1..497c285 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" #include "cnst_fx.h" /* Audio core constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" -#include "stl.h" #include "basop_mpy.h" /*--------------------------------------------------------------------------* @@ -16,16 +15,16 @@ *--------------------------------------------------------------------------*/ void mdct_spectrum_denorm_fx( - const Word16 inp_vector[], /* i : Q0 : */ - Word32 L_y2[], /* i/o : Qs : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word32 L_band_energy[], /* i : Qbe : band energy */ - const Word16 npulses[], /* i : Q0 : number of coded spectrum */ - const Word16 bands, /* i : Q0 : number of subbands */ - const Word16 ld_slope_fx, /* i : Q15 : */ - const Word16 pd_thresh_fx /* i : Q15 : */ + const Word16 inp_vector[], /* i : Q0 : */ + Word32 L_y2[], /* i/o : Qs : decoded spectrum */ + const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ + const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ + const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ + const Word32 L_band_energy[], /* i : Qbe : band energy */ + const Word16 npulses[], /* i : Q0 : number of coded spectrum */ + const Word16 bands, /* i : Q0 : number of subbands */ + const Word16 ld_slope_fx, /* i : Q15 : */ + const Word16 pd_thresh_fx /* i : Q15 : */ ) { Word16 i, k; @@ -236,15 +235,15 @@ void hq2_core_configure_fx ( { IF( is_transient ) { - IF ( LE_16(num_bits, ACELP_7k20 / 50)) + IF ( LE_16(num_bits, ACELP_7k20 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_8kHz_007200bps_short_fx; } - ELSE IF ( LE_16(num_bits, ACELP_8k00 / 50)) + ELSE IF ( LE_16(num_bits, ACELP_8k00 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_8kHz_008000bps_short_fx; } - ELSE IF ( LE_16(num_bits, ACELP_13k20 / 50)) + ELSE IF ( LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_8kHz_013200bps_short_fx; } @@ -255,15 +254,15 @@ void hq2_core_configure_fx ( } ELSE { - IF ( LE_16(num_bits, ACELP_7k20 / 50)) + IF ( LE_16(num_bits, ACELP_7k20 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_8kHz_007200bps_long_fx; } - ELSE IF ( LE_16(num_bits, ACELP_8k00 / 50)) + ELSE IF ( LE_16(num_bits, ACELP_8k00 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_8kHz_008000bps_long_fx; } - ELSE IF ( LE_16(num_bits, ACELP_13k20 / 50)) + ELSE IF ( LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_8kHz_013200bps_long_fx; } @@ -277,12 +276,12 @@ void hq2_core_configure_fx ( { IF (is_transient) { - IF ( LE_16(num_bits, ACELP_13k20 / 50)) + IF ( LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_16kHz_013200bps_short_fx; move16(); } - ELSE if ( LE_16(num_bits, ACELP_16k40 / 50)) + ELSE if ( LE_16(num_bits, ACELP_16k40 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_16kHz_016400bps_short_fx; move16(); @@ -290,12 +289,12 @@ void hq2_core_configure_fx ( } ELSE { - IF ( LE_16(num_bits, ACELP_13k20 / 50)) + IF ( LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_16kHz_013200bps_long_fx; move16(); } - ELSE if ( LE_16(num_bits, ACELP_16k40 / 50)) + ELSE if ( LE_16(num_bits, ACELP_16k40 / FRAMES_PER_SEC)) { xcore_config_fx = &xcore_config_16kHz_016400bps_long_fx; move16(); @@ -461,14 +460,14 @@ void reverse_transient_frame_energies_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_pre_fx( - const Word16 band_start[], /* i: Starting position of sub band */ - const Word16 band_end[], /* i: End position of sub band */ - const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ - const Word16 BANDS, /* i: total number of bands */ - const Word32 L_bwe_br, /* i: bitrate information */ - Word16 new_band_start[], /* o: Starting position of new shorten sub band */ - Word16 new_band_end[], /* o: End position of new shorten sub band */ - Word16 new_band_width[] /* o: new sub band bandwidth */ + const Word16 band_start[], /* i: Starting position of sub band */ + const Word16 band_end[], /* i: End position of sub band */ + const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ + const Word16 BANDS, /* i: total number of bands */ + const Word32 L_bwe_br, /* i: bitrate information */ + Word16 new_band_start[], /* o: Starting position of new shorten sub band */ + Word16 new_band_end[], /* o: End position of new shorten sub band */ + Word16 new_band_width[] /* o: new sub band bandwidth */ ) { Word16 j; @@ -547,9 +546,9 @@ void spt_shorten_domain_band_save_fx( const Word16 band_start[], /* i: starting position of subband */ const Word16 band_end[], /* i: end position of subband */ const Word16 band_width[], /* i: band width of subband */ - Word16 org_band_start[], /* o: starting position of subband */ - Word16 org_band_end[], /* o: end position of subband */ - Word16 org_band_width[] /* o: band width of subband */ + Word16 org_band_start[], /* o: starting position of subband */ + Word16 org_band_end[], /* o: end position of subband */ + Word16 org_band_width[] /* o: band width of subband */ ) { Word16 k; @@ -579,9 +578,9 @@ void spt_shorten_domain_band_save_fx( void spt_shorten_domain_band_restore_fx( const Word16 bands, /* i: total subband */ - Word16 band_start[], /* i/o: starting position of subband */ - Word16 band_end[], /* i/o: end position of subband */ - Word16 band_width[], /* i/o: band width of subband */ + Word16 band_start[], /* i/o: starting position of subband */ + Word16 band_end[], /* i/o: end position of subband */ + Word16 band_width[], /* i/o: band width of subband */ const Word16 org_band_start[], /* o: starting position of subband */ const Word16 org_band_end[], /* o: end position of subband */ const Word16 org_band_width[] /* o: band width of subband */ @@ -617,7 +616,7 @@ void spt_swb_peakpos_tmp_save_fx( const Word16 bands, /* i: total number of bands */ const Word16 band_start[], /* i: starting position of subband */ const Word16 band_end[], /* i: end position of subband */ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ ) { diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index b6de410..e73877c 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -2,8 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" -#include "stl.h" #include "prot_fx.h" #include "math_op.h" #include "math_32.h" diff --git a/lib_com/hq_conf_fx.c b/lib_com/hq_conf_fx.c index 1cacbdc..f8f128a 100644 --- a/lib_com/hq_conf_fx.c +++ b/lib_com/hq_conf_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" #include "cnst_fx.h" /* Audio core constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* * hq_configure() @@ -16,59 +15,61 @@ *--------------------------------------------------------------------------*/ void hq_configure_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ + const Word16 length, /* i : Frame length Q0 */ + const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ + const Word32 core_brate, /* i : Codec bitrate Q0 */ Word16 *num_sfm, /* o : Total number of subbands Q0 */ Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths Q0 */ - Word16 const **sfm_start, /* o : Subband start coefficients Q0 */ - Word16 const **sfm_end /* o : Subband end coefficients Q0 */ + Word16 *sfmsize, /* o : Subband bandwidths Q0 */ + Word16 *sfm_start, /* o : Subband start coefficients Q0 */ + Word16 *sfm_end /* o : Subband end coefficients Q0 */ ) { + const Word16* p_sfmsize; + const Word16* p_sfm_start; + const Word16* p_sfm_end; + Word16 i, bw_ext; + + bw_ext = 0; + *start_norm = 0; move16(); - IF ( EQ_16(length, L_FRAME48k)) +#ifndef SOLVED_COMP_ENC_DEC + IF(EQ_16(length, L_FRAME48k)) /*tbv SOLVED_COMP_ENC_DEC*/ +#else + IF ( EQ_16(length, L_SPEC48k)) +#endif { IF ( EQ_16(hqswb_clas, HQ_GEN_FB)) { *num_sfm = NB_SFM; move16(); - *sfmsize = band_len_HQ; + p_sfmsize = band_len_HQ; move16(); - *sfm_start = band_start_HQ; + p_sfm_start = band_start_HQ; move16(); - *sfm_end = band_end_HQ; + p_sfm_end = band_end_HQ; move16(); test(); - IF ( EQ_32(core_brate, HQ_32k)) + IF ( GE_32(core_brate, HQ_32k)) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; move16(); - } - ELSE IF ( EQ_32(core_brate, HQ_16k40)||EQ_32(core_brate,HQ_24k40)) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - move16(); - } - - /* setting start frequency of FD BWE */ - test(); - IF ( EQ_32(core_brate, HQ_32k)) - { *num_env_bands = SFM_N_STA_10k; move16(); } - ELSE IF ( EQ_32(core_brate, HQ_16k40)||EQ_32(core_brate,HQ_24k40)) + ELSE /*IF(EQ_32(core_brate, HQ_16k40) || EQ_32(core_brate, HQ_24k40))*/ { + *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; *num_env_bands = SFM_N_STA_8k; move16(); + move16(); } *nb_sfm = *num_sfm; move16(); @@ -84,28 +85,22 @@ void hq_configure_fx( *num_env_bands = SFM_N_HARM_FB; move16(); - *sfmsize = band_len_harm; + p_sfmsize = band_len_harm; move16(); - *sfm_start = band_start_harm; + p_sfm_start = band_start_harm; move16(); - *sfm_end = band_end_harm; + p_sfm_end = band_end_harm; move16(); } ELSE IF ( EQ_16(hqswb_clas, HQ_HVQ)) { - IF ( EQ_32(core_brate, HQ_24k40)) + IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { *num_sfm = SFM_N_HARM_FB; move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); *num_env_bands = sub(*num_sfm, *nb_sfm); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *sfm_end = band_end_harm; move16(); *start_norm = HVQ_THRES_SFM_24k; move16(); @@ -117,16 +112,14 @@ void hq_configure_fx( *nb_sfm = HVQ_THRES_SFM_32k; move16(); *num_env_bands = sub(*num_sfm, *nb_sfm); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); - *sfm_end = band_end_harm; - move16(); } + p_sfmsize = band_len_harm; + p_sfm_start = band_start_harm; + p_sfm_end = band_end_harm; + move16();move16();move16(); } ELSE { @@ -137,16 +130,16 @@ void hq_configure_fx( *num_env_bands = NB_SFM; move16(); - *sfmsize = band_len_HQ; + p_sfmsize = band_len_HQ; move16(); - *sfm_start = band_start_HQ; + p_sfm_start = band_start_HQ; move16(); - *sfm_end = band_end_HQ; + p_sfm_end = band_end_HQ; move16(); } } } - ELSE IF( EQ_16(length, L_FRAME32k)) + ELSE IF( EQ_16(length, L_SPEC32k)) { IF ( EQ_16(hqswb_clas, HQ_HARMONIC)) { @@ -157,16 +150,16 @@ void hq_configure_fx( *num_env_bands = SFM_N_HARM; move16(); - *sfmsize = band_len_harm; + p_sfmsize = band_len_harm; move16(); - *sfm_start = band_start_harm; + p_sfm_start = band_start_harm; move16(); - *sfm_end = band_end_harm; + p_sfm_end = band_end_harm; move16(); } ELSE IF ( EQ_16(hqswb_clas, HQ_HVQ)) { - IF ( EQ_32(core_brate, HQ_24k40)) + IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { *num_sfm = SFM_N_HARM; move16(); @@ -174,12 +167,6 @@ void hq_configure_fx( move16(); *num_env_bands = sub(*num_sfm, *nb_sfm); - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *sfm_end = band_end_harm; - move16(); *start_norm = HVQ_THRES_SFM_24k; move16(); } @@ -191,46 +178,39 @@ void hq_configure_fx( move16(); *num_env_bands = sub(*num_sfm, *nb_sfm); - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); - *sfm_end = band_end_harm; - move16(); } + p_sfmsize = band_len_harm; + move16(); + p_sfm_start = band_start_harm; + move16(); + p_sfm_end = band_end_harm; + move16(); + } ELSE IF ( EQ_16(hqswb_clas, HQ_GEN_SWB)) { *num_sfm = SFM_N_SWB; move16(); - *sfmsize = band_len_HQ; + p_sfmsize = band_len_HQ; move16(); - *sfm_start = band_start_HQ; + p_sfm_start = band_start_HQ; move16(); - *sfm_end = band_end_HQ; + p_sfm_end = band_end_HQ; move16(); - IF ( EQ_32(core_brate, HQ_32k)) + IF ( GE_32(core_brate, HQ_32k)) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; move16(); - } - ELSE if ( EQ_32(core_brate, HQ_24k40)) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - move16(); - } - - /* setting start frequency of HQ Generic */ - IF ( EQ_32(core_brate, HQ_32k)) - { *num_env_bands = SFM_N_STA_10k; move16(); } - ELSE if( EQ_32(core_brate, HQ_24k40)) + ELSE /*if( EQ_32(core_brate, HQ_24k40))*/ { + *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; + move16(); *num_env_bands = SFM_N_STA_8k; move16(); } @@ -248,14 +228,32 @@ void hq_configure_fx( *num_env_bands = SFM_N_SWB; move16(); - *sfmsize = band_len_HQ; + p_sfmsize = band_len_HQ; move16(); - *sfm_start = band_start_HQ; + p_sfm_start = band_start_HQ; move16(); - *sfm_end = band_end_HQ; + p_sfm_end = band_end_HQ; move16(); } } + ELSE IF (EQ_16(length, L_SPEC48k_EXT ) ) + { + bw_ext = 1; + p_sfmsize = band_len_HQ; + p_sfm_start = band_start_HQ; + p_sfm_end = band_end_HQ; + *num_sfm = NB_SFM; + move16(); move16(); move16(); move16(); + } + ELSE IF (EQ_16(length, L_SPEC16k_EXT)) + { + bw_ext = 1; + p_sfmsize = band_len_wb; + p_sfm_start = band_start_wb; + p_sfm_end = band_end_wb; + *num_sfm = SFM_N_WB; + move16();move16();move16();move16(); + } ELSE { *num_sfm = SFM_N_WB; @@ -265,13 +263,34 @@ void hq_configure_fx( *num_env_bands = SFM_N_WB; move16(); - *sfmsize = band_len_wb; + p_sfmsize = band_len_wb; move16(); - *sfm_start = band_start_wb; + p_sfm_start = band_start_wb; move16(); - *sfm_end = band_end_wb; + p_sfm_end = band_end_wb; move16(); } + IF (bw_ext) + { + FOR (i = 0; i < *num_sfm; i++) + { + /*sfmsize[i] = (int16_t)(1.25f * p_sfmsize[i]);*/ + sfmsize[i] = mult_r(shl(p_sfmsize[i],1),20480); + /*sfm_start[i] = (int16_t)(1.25f * p_sfm_start[i]);*/ + sfm_start[i] = mult_r(shl(p_sfm_start[i], 1), 20480); + /*sfm_end[i] = (int16_t)(1.25f * p_sfm_end[i]);*/ + sfm_end[i] = mult_r(shl(p_sfm_end[i], 1), 20480); + } + *nb_sfm = *num_sfm; + *num_env_bands = *num_sfm; + move16();move16(); + } + else + { + Copy(p_sfmsize, sfmsize, *num_sfm); + Copy(p_sfm_start, sfm_start, *num_sfm); + Copy(p_sfm_end, sfm_end, *num_sfm); + } *numnrmibits = extract_l(L_mult0(sub(*num_env_bands, 1), NORMI_BITS)); diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index f20cca9..f4523ca 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -1,7 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include "options.h" /* Compilation switches */ #include "rom_com_fx.h" /* Static table prototypes FIP version */ @@ -9,7 +9,7 @@ #include "prot_fx.h" /*--------------------------------------------------------------------------* - * Local functions + * Local function prototypes *--------------------------------------------------------------------------*/ static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, Word32 *coeff_out, const Word16 n_swb_overlap_offset, @@ -22,10 +22,10 @@ static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, Word32 *coeff_o *--------------------------------------------------------------------------*/ void hq_swb_harmonic_calc_norm_envelop_fx( - Word32 *L_SWB_signal, /* i : input signal Q=12*/ - Word32 *L_envelope, /* o : output envelope Q=12*/ - Word16 L_swb_norm, /* i : length of normaliztion */ - Word16 SWB_flength /* i : length of input signal */ + const Word32 *L_SWB_signal, /* i : input signal Q=12*/ + Word32 *L_envelope, /* o : output envelope Q=12*/ + const Word16 L_swb_norm, /* i : length of normaliztion */ + const Word16 SWB_flength /* i : length of input signal */ ) { @@ -103,10 +103,10 @@ void hq_swb_harmonic_calc_norm_envelop_fx( *--------------------------------------------------------------------------*/ void limit_band_noise_level_calc_fx( - const Word16 *wnorm, /* i : reordered norm of sub-vectors */ - Word16 *limit, /* o : highest band of bit allocation */ - const Word32 core_brate, /* i : bit rate */ - Word16 *noise_level /* o : noise level Q15 */ + const Word16 *wnorm, /* i : reordered norm of sub-vectors */ + Word16 *limit, /* o : highest band of bit allocation */ + const Word32 core_brate, /* i : bit rate */ + Word16 *noise_level /* o : noise level Q15 */ ) { Word16 ener_limit, ener_sum; @@ -143,7 +143,7 @@ void limit_band_noise_level_calc_fx( fact = 2022929597; move32(); - if (EQ_32(core_brate, HQ_24k40)) + if (LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { fact = L_add(1900523029, 1); } @@ -195,16 +195,16 @@ void limit_band_noise_level_calc_fx( * NOTE: Q values preliminary *--------------------------------------------------------------------------*/ -Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook Q=0*/ - const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag Q=0*/ - const Word16 *coeff, /* i : Coded spectral coefficients Q=12*/ - const Word16 *sfm_start, /* i : Subband start indices Q=0*/ - const Word16 *sfmsize, /* i : Subband widths Q=0*/ - const Word16 *sfm_end, /* i : Subband end indices Q=0*/ - const Word16 last_sfm, /* i : Last coded band Q=0*/ - const Word16 *R, /* i : Per-band bit allocation Q=0*/ - Word16 *CodeBook, /* o : Noise-fill codebook Q=12*/ - Word16 *CodeBook_mod /* o : Densified noise-fill codebook Q=12*/ +Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook Q=0*/ + const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag Q=0*/ + const Word16 *coeff, /* i : Coded spectral coefficients Q=12*/ + const Word16 *sfm_start, /* i : Subband start indices Q=0*/ + const Word16 *sfmsize, /* i : Subband widths Q=0*/ + const Word16 *sfm_end, /* i : Subband end indices Q=0*/ + const Word16 last_sfm, /* i : Last coded band Q=0*/ + const Word16 *R, /* i : Per-band bit allocation Q=0*/ + Word16 *CodeBook, /* o : Noise-fill codebook Q=12*/ + Word16 *CodeBook_mod /* o : Densified noise-fill codebook Q=12*/ ) { Word16 sfm_base; @@ -350,7 +350,7 @@ void apply_noisefill_HQ_fx( const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ const Word16 *sfmsize, /* i : Subband band width Q0 */ - Word16 *coeff /* i/o: coded/noisefilled spectrum Q12 */ + Word16 *coeff /* i/o: coded/noisefilled spectrum Q12 */ ) { Word16 sfm; @@ -365,7 +365,7 @@ void apply_noisefill_HQ_fx( test(); test(); - IF ( (GE_16(length, L_FRAME32k))||(GT_32(L_core_brate,HQ_32k))||(LT_32(L_core_brate,HQ_24k40))) + IF ( (GE_16(length, L_FRAME32k)) || (NE_32(L_core_brate,HQ_32k))) { /* Read from codebook */ cb_pos = 0; @@ -459,10 +459,10 @@ void harm_bwe_fine_fx( const Word16 *norm, /* i : quantization indices for norms */ const Word16 *sfm_start, /* i : Subband start coefficient */ const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word32 *coeff_out /* o : coded/noisefilled spectrum */ - , Word16 *coeff_fine /* o : BWE fine structure */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum */ + Word16 *coeff_fine /* o : BWE fine structure */ ) { Word16 sfm; @@ -573,16 +573,16 @@ void harm_bwe_fine_fx( *--------------------------------------------------------------------------*/ void hvq_bwe_fine_fx( - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 num_sfm, /* i : total number of bands Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *peak_idx, /* i : Peak index Q0 */ - const Word16 Npeaks, /* i : Number of peaks Q0 */ - Word16 *peak_pos, /* o : Peak positions Q0 */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0 */ - Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ - Word16 *bwe_peaks, /* o : Positions of peaks in BWE Q0 */ - Word16 *coeff_fine /* o : HVQ BWE fine structure Q15 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 num_sfm, /* i : total number of bands Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + const Word16 *peak_idx, /* i : Peak index Q0 */ + const Word16 Npeaks, /* i : Number of peaks Q0 */ + Word16 *peak_pos, /* o : Peak positions Q0 */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0 */ + Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ + Word16 *bwe_peaks, /* o : Positions of peaks in BWE Q0 */ + Word16 *coeff_fine /* o : HVQ BWE fine structure Q15 */ ) { Word16 i, j; @@ -740,12 +740,12 @@ void hq_fold_bwe_fx( *--------------------------------------------------------------------------*/ void apply_nf_gain_fx( - const Word16 nf_idx, /* i : noise fill gain index Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *R, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ + const Word16 nf_idx, /* i : noise fill gain index Q0 */ + const Word16 last_sfm, /* i : last coded subband Q0 */ + const Word16 *R, /* i : bit allocation Q0 */ + const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ + const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ + Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ ) { Word16 sfm; @@ -775,19 +775,20 @@ void apply_nf_gain_fx( *--------------------------------------------------------------------------*/ void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out /* o : coded/noisefilled spectrum */ + const Word16 *coeff_fine, /* i : fine structure for BWE */ + const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 *sfm_start, /* i : Subband start coefficient */ + const Word16 *sfm_end, /* i : Subband end coefficient */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16 *R, /* i : bit allocation */ + const Word16 prev_hq_mode, /* i : previous hq mode */ + Word16 *norm, /* i/o: quantization indices for norms */ + Word16 *noise_level, /* i/o: noise levels for harmonic modes */ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ + Word32 *coeff_out, /* o : coded/noisefilled spectrum */ + const Word16 element_mode /* i : IVAS element mode */ ) { Word16 i, j; @@ -884,7 +885,16 @@ void harm_bwe_fx( exp1 = norm_s(alfa); tmp1 = shl(alfa, exp1); - exp1 = add(1, exp1); + if (EQ_16( element_mode, EVS_MONO)) + { + exp1 = add(1, exp1); + } +#ifdef DEBUGGING + else + { + PMT("VERIFY if this really matches IVAS float") + } +#endif tmp1 = s_max(tmp1, 16384); tmp1 = div_s(16384, tmp1); L_tmp2 = L_deposit_h(tmp1); @@ -943,13 +953,13 @@ void hvq_bwe_fx( const Word16 *bwe_peaks, /* i : HVQ bwe peaks Q0 */ const Word16 bin_th, /* i : HVQ transition bin Q0 */ const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word32 core_brate, /* i : Core bit-rate Q0 */ + const Word32 core_brate, /* i : Core bitrate Q0 */ const Word16 *R, /* i : Bit allocation */ - Word16 *norm, /* i/o: quantization indices for norms Q0 */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ + Word16 *norm, /* i/o: quantization indices for norms Q0 */ + Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ + Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ const Word16 qin, const Word16 qout ) @@ -1004,7 +1014,7 @@ void hvq_bwe_fx( } norm_ind = add(last_sfm, 1); - IF ( EQ_32(core_brate, HQ_24k40)) + IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { peak_band = 0; move16(); @@ -1276,12 +1286,12 @@ void hvq_bwe_fx( *--------------------------------------------------------------------------*/ void hvq_concat_bands_fx ( - const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ - const Word16 *sel_bnds, /* i : Array of selected high bands */ - const Word16 n_sel_bnds, /* i : Number of selected high bands */ - Word16 *hvq_band_start, /* i : Band start indices */ - Word16 *hvq_band_width, /* i : Band widths */ - Word16 *hvq_band_end /* i : Band end indices */ + const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ + const Word16 *sel_bnds, /* i : Array of selected high bands */ + const Word16 n_sel_bnds, /* i : Number of selected high bands */ + Word16 *hvq_band_start, /* i : Band start indices */ + Word16 *hvq_band_width, /* i : Band widths */ + Word16 *hvq_band_end /* i : Band end indices */ ) { Word16 k, k_1; @@ -1319,14 +1329,14 @@ void hvq_concat_bands_fx *--------------------------------------------------------------------------*/ void noise_mix_fx( - const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ - const Word32 L_E, /* i : normalization factor Q17 */ - const Word32 L_normq, /* i : quantized norm Q14 */ - Word16 *seed, /* i/o: random seed Q0 */ - const Word16 istart, /* i : start coefficient Q0 */ - const Word16 iend, /* i : end coefficient Q0 */ - const Word16 noise_level, /* i : noise_level Q0 */ - Word32 *L_coeff_out, /* o : noise mixed spectrum Qout */ + const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ + const Word32 L_E, /* i : normalization factor Q17 */ + const Word32 L_normq, /* i : quantized norm Q14 */ + Word16 *seed, /* i/o: random seed Q0 */ + const Word16 istart, /* i : start coefficient Q0 */ + const Word16 iend, /* i : end coefficient Q0 */ + const Word16 noise_level, /* i : noise_level Q0 */ + Word32 *L_coeff_out, /* o : noise mixed spectrum Qout */ const Word16 qin, const Word16 qout ) @@ -1647,26 +1657,26 @@ Word16 get_nor_delta_hf_fx( } return add_bits_denv; } - +/*-------------------------------------------------------------------* +* calc_nor_delta_hf() +* +* +*--------------------------------------------------------------------------*/ Word16 calc_nor_delta_hf_fx( - Encoder_State_fx *st, - const Word32 *t_audio, - Word16 *ynrm, - Word16 *Rsubband, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 *sfmsize, - const Word16 *sfm_start, - const Word16 core_sfm + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32* t_audio, /* i : transform-domain coefficients */ + Word16* ynrm, /* i/o: norm indices */ + Word16* Rsubband, /* i/o: sub-band bit allocation */ + const Word16 num_env_bands, /* i : Number coded envelope bands */ + const Word16 nb_sfm, /* i : Number of envelope bands */ + const Word16* sfmsize, /* i : band length */ + const Word16* sfm_start, /* i : Start index of bands */ + const Word16 core_sfm /* i : index of the end band for core */ ) { Word16 i; Word16 ynrm_t[44],normqlg2_t[44]; Word16 delta,max_delta,min_delta,bitsforDelta,add_bits_denv; - Word16 temp_num; - - temp_num=0; - move16(); max_delta=-100; move16(); @@ -1715,7 +1725,7 @@ Word16 calc_nor_delta_hf_fx( /* updating norm & storing delta norm */ add_bits_denv = 2; move16(); - push_indice_fx( st, IND_DELTA_ENV_HQ, sub(bitsforDelta,2) , 2 ); + push_indice_fx(hBstr, IND_DELTA_ENV_HQ, sub(bitsforDelta,2) , 2 ); FOR(i=num_env_bands; i #include "options.h" /* Compilation switches */ -#include "stl.h" /* required by wmc_tool */ - #include "rom_com_fx.h" #include "prot_fx.h" /* Function prototypes */ @@ -19,16 +17,16 @@ /*--------------------------------------------------------------------------*/ Word16 hvq_pvq_bitalloc_fx( - Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ - const Word32 brate, /* i : bitrate */ - const Word16 bwidth_fx, /* i : Encoded bandwidth */ - const Word16 *ynrm, /* i : Envelope coefficients */ - const Word32 manE_peak, /* i : Peak energy mantissa */ - const Word16 expE_peak, /* i : Peak energy exponent */ - Word16 *Rk, /* o : bit allocation for concatenated vector */ - Word16 *R, /* i/o: Global bit allocation */ - Word16 *sel_bands, /* o : Selected bands for encoding */ - Word16 *n_sel_bands /* o : No. of selected bands for encoding */ + Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : Encoded bandwidth */ + const Word16 *ynrm, /* i : Envelope coefficients */ + const Word32 manE_peak, /* i : Peak energy mantissa */ + const Word16 expE_peak, /* i : Peak energy exponent */ + Word16 *Rk, /* o : bit allocation for concatenated vector */ + Word16 *R, /* i/o: Global bit allocation */ + Word16 *sel_bands, /* o : Selected bands for encoding */ + Word16 *n_sel_bands /* o : No. of selected bands for encoding */ ) { Word16 num_bands, band_max_bits; @@ -52,7 +50,7 @@ Word16 hvq_pvq_bitalloc_fx( num_sfm = SFM_N_HARM; } - IF ( EQ_32(brate, HQ_24k40)) + IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { band_max_bits = HVQ_BAND_MAX_BITS_24k; move16(); diff --git a/lib_com/igf_base.c b/lib_com/igf_base.c index 3c799c5..ab8ef26 100644 --- a/lib_com/igf_base.c +++ b/lib_com/igf_base.c @@ -38,92 +38,341 @@ static Word16 IGF_ApplyTransFac( /**********************************************************************/ /* maps a given bitrate to the IGF_BITRATE index **************************************************************************/ -static Word16 IGF_MapBitRateToIndex( /**< out: Q0 | return bit rate index */ - Word32 bitRate, /**< in: | bitrate */ - Word16 mode /**< in: | bandwidth mode */ - , Word16 rf_mode /**< in: | flag to signal the RF mode */ +Word16 IGF_MapBitRateToIndex( + const Word32 brate, /* i : bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ) { - Word16 bitRateIndex; - - - bitRateIndex = IGF_BITRATE_UNKNOWN; + Word16 bitRateIndex = IGF_BITRATE_UNKNOWN; move16(); - - switch (mode) + /* Stereo/CPE modes */ + IF(GT_16(element_mode, IVAS_SCE)) { - case IGF_MODE_WB: - switch (bitRate) + switch (bwidth) { - case 13200: - if (EQ_16(rf_mode,1)) + case IGF_MODE_WB: + IF(LE_32(brate, IVAS_13k2) && EQ_16(rf_mode, 1)) { bitRateIndex = IGF_BITRATE_RF_WB_13200; + move16(); } - break; - case 9600: - bitRateIndex = IGF_BITRATE_WB_9600; - break; - default: - assert(0); + ELSE IF(LE_32(brate, ACELP_9k60)) + { + bitRateIndex = IGF_BITRATE_WB_13200_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_13k2)) + { + bitRateIndex = IGF_BITRATE_WB_16400_CPE; + move16(); + } + BREAK; + case IGF_MODE_SWB: + /* DFT and TD Stereo bitrates */ + IF(LE_32(brate, ACELP_9k60)) + { + bitRateIndex = IGF_BITRATE_SWB_13200_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_13k2)) + { + IF(EQ_16(rf_mode, 1)) + { + bitRateIndex = IGF_BITRATE_RF_SWB_13200; + move16(); + } + ELSE + { + bitRateIndex = IGF_BITRATE_SWB_16400_CPE; + move16(); + } + } + ELSE IF(LE_32(brate, IVAS_16k4)) + { + bitRateIndex = IGF_BITRATE_SWB_24400_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_24k4) ) + { + bitRateIndex = IGF_BITRATE_SWB_32000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_32k) ) + { + bitRateIndex = IGF_BITRATE_SWB_32000; + move16(); + } + /* MDCT Stereo bitrates */ + ELSE IF(LE_32(brate, IVAS_48k) ) + { + bitRateIndex = IGF_BITRATE_SWB_48000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_64k) ) + { + bitRateIndex = IGF_BITRATE_SWB_64000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_80k) ) + { + bitRateIndex = IGF_BITRATE_SWB_80000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_96k)) + { + bitRateIndex = IGF_BITRATE_SWB_96000_CPE; + move16(); + } + BREAK; + case IGF_MODE_FB: + /* DFT and TD Stereo bitrates */ + IF(LE_32(brate, IVAS_16k4) ) + { + bitRateIndex = IGF_BITRATE_FB_24400_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_24k4) ) + { + bitRateIndex = IGF_BITRATE_FB_32000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_32k)) + { + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + } + /* MDCT Stereo bitrates */ + ELSE IF(LE_32(brate, IVAS_48k)) + { + bitRateIndex = IGF_BITRATE_FB_48000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_64k) ) + { + bitRateIndex = IGF_BITRATE_FB_64000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_80k) ) + { + bitRateIndex = IGF_BITRATE_FB_80000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_96k) ) + { + bitRateIndex = IGF_BITRATE_FB_96000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_128k)) + { + bitRateIndex = IGF_BITRATE_FB_128000_CPE; + move16(); + } + BREAK; } - break; - case IGF_MODE_SWB: - switch (bitRate) + } + /* SCE modes: use tunings done for DFT stereo bitrates also for according SCE bitrates, otherwise same config as mono modes */ + ELSE IF(EQ_16(element_mode, IVAS_SCE)) + { + switch (bwidth) { - case 9600: - bitRateIndex = IGF_BITRATE_SWB_9600; - break; - case 13200: - bitRateIndex = IGF_BITRATE_SWB_13200; - if (EQ_16(rf_mode,1)) + case IGF_MODE_WB: + IF(LE_32(brate, IVAS_13k2) && EQ_16(rf_mode, 1) ) { - bitRateIndex = IGF_BITRATE_RF_SWB_13200; + bitRateIndex = IGF_BITRATE_RF_WB_13200; + move16(); } - break; - case 16400: - bitRateIndex = IGF_BITRATE_SWB_16400; - break; - case 24400: - bitRateIndex = IGF_BITRATE_SWB_24400; - break; - case 32000: - bitRateIndex = IGF_BITRATE_SWB_32000; - break; - case 48000: - bitRateIndex = IGF_BITRATE_SWB_48000; - break; - default: - assert(0); + ELSE IF(LE_32(brate, ACELP_9k60)) /* bitrates 8000 and 9600 */ + { + bitRateIndex = IGF_BITRATE_WB_9600; + move16(); + } + BREAK; + case IGF_MODE_SWB: + IF(LE_32(brate, ACELP_9k60) ) + { + bitRateIndex = IGF_BITRATE_SWB_13200_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_13k2) ) + { + IF(EQ_16(rf_mode, 1)) + { + bitRateIndex = IGF_BITRATE_RF_SWB_13200; + move16(); + } + ELSE + { + bitRateIndex = IGF_BITRATE_SWB_16400_CPE; + move16(); + } + } + ELSE IF(LE_32(brate, IVAS_16k4) ) + { + bitRateIndex = IGF_BITRATE_SWB_24400_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_24k4)) + { + move16(); + bitRateIndex = IGF_BITRATE_SWB_32000_CPE; + } + ELSE IF(LE_32(brate, IVAS_32k) ) + { + bitRateIndex = IGF_BITRATE_SWB_32000; + move16(); + } + ELSE IF(LE_32(brate, IVAS_48k)) + { + bitRateIndex = IGF_BITRATE_SWB_48000; + move16(); + } + ELSE IF(LE_32(brate, IVAS_64k)) + { + bitRateIndex = IGF_BITRATE_SWB_64000; + move16(); + } + BREAK; + case IGF_MODE_FB: + IF(LE_32(brate, IVAS_16k4) ) + { + bitRateIndex = IGF_BITRATE_FB_24400_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_24k4)) + { + bitRateIndex = IGF_BITRATE_FB_32000_CPE; + move16(); + } + ELSE IF(LE_32(brate, IVAS_32k) ) + { + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + } + ELSE IF(LE_32(brate, IVAS_48k)) + { + bitRateIndex = IGF_BITRATE_FB_48000; + move16(); + } + ELSE IF(LE_32(brate, IVAS_64k)) + { + bitRateIndex = IGF_BITRATE_FB_64000; + move16(); + } + ELSE IF(LE_32(brate, IVAS_96k)) + { + bitRateIndex = IGF_BITRATE_FB_96000; + move16(); + } + ELSE IF(LE_32(brate, IVAS_128k)) + { + bitRateIndex = IGF_BITRATE_FB_128000; + move16(); + } + BREAK; } - break; - case IGF_MODE_FB: - switch (bitRate) + } + /* EVS mono */ + else + { + switch (bwidth) { - case 16400: - bitRateIndex = IGF_BITRATE_FB_16400; - break; - case 24400: - bitRateIndex = IGF_BITRATE_FB_24400; - break; - case 32000: - bitRateIndex = IGF_BITRATE_FB_32000; - break; - case 48000: - bitRateIndex = IGF_BITRATE_FB_48000; - break; - case 96000: - bitRateIndex = IGF_BITRATE_FB_96000; - break; - case 128000: - bitRateIndex = IGF_BITRATE_FB_128000; - break; - default: - assert(0); + case IGF_MODE_WB: + IF(LE_32(brate, ACELP_13k20) && EQ_16(rf_mode, 1)) + { + bitRateIndex = IGF_BITRATE_RF_WB_13200; + move16(); + } + ELSE IF(LE_32(brate, ACELP_9k60)) /* bitrates 8000 and 9600 */ + { + bitRateIndex = IGF_BITRATE_WB_9600; + move16(); + } + BREAK; + case IGF_MODE_SWB: + IF(LE_32(brate, ACELP_9k60)) + { + move16(); + bitRateIndex = IGF_BITRATE_SWB_9600; + } + ELSE IF(LE_32(brate, ACELP_13k20) ) + { + IF(EQ_16(rf_mode, 1)) + { + bitRateIndex = IGF_BITRATE_RF_SWB_13200; + move16(); + } + ELSE + { + bitRateIndex = IGF_BITRATE_SWB_13200; + move16(); + } + } + ELSE IF(LE_32(brate, ACELP_16k40) ) + { + bitRateIndex = IGF_BITRATE_SWB_16400; + move16(); + } + ELSE IF(LE_32(brate, ACELP_24k40)) + { + bitRateIndex = IGF_BITRATE_SWB_24400; + move16(); + } + ELSE IF(LE_32(brate, ACELP_32k)) + { + bitRateIndex = IGF_BITRATE_SWB_32000; + move16(); + } + ELSE IF(LE_32(brate, ACELP_48k)) + { + bitRateIndex = IGF_BITRATE_SWB_48000; + move16(); + } + ELSE IF(LE_32(brate, ACELP_64k) ) + { + bitRateIndex = IGF_BITRATE_SWB_64000; + move16(); + } + BREAK; + case IGF_MODE_FB: + IF(LE_32(brate, ACELP_16k40) ) + { + bitRateIndex = IGF_BITRATE_FB_16400; + move16(); + } + ELSE IF(LE_32(brate, ACELP_24k40)) + { + bitRateIndex = IGF_BITRATE_FB_24400; + move16(); + } + ELSE IF(LE_32(brate, ACELP_32k) ) + { + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + } + ELSE IF(LE_32(brate, ACELP_48k) ) + { + bitRateIndex = IGF_BITRATE_FB_48000; + move16(); + } + ELSE IF(LE_32(brate, ACELP_64k)) + { + bitRateIndex = IGF_BITRATE_FB_64000; + move16(); + } + ELSE IF(LE_32(brate, HQ_96k) ) + { + bitRateIndex = IGF_BITRATE_FB_96000; + move16(); + } + ELSE IF(LE_32(brate, HQ_128k)) + { + bitRateIndex = IGF_BITRATE_FB_128000; + move16(); + } + BREAK; } - break; - default: - assert(0); } return bitRateIndex; @@ -685,15 +934,16 @@ void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, /**********************************************************************/ /* write bits to stream **************************************************************************/ -void IGFCommonFuncsWriteSerialBit(void *st, /**< in: | encoder/decoder state structure */ - Word16 *pBitOffset, /**< out: Q0 | bit offset */ - Word16 bit /**< in: Q0 | value of bit */ - ) +void IGFCommonFuncsWriteSerialBit( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< out: Q0 | bit offset */ + Word16 bit /**< in: Q0 | value of bit */ +) { - IF (st) + IF (hBstr) { - push_next_indice_fx(st, bit, 1); + push_next_indice_fx(hBstr, bit, 1); } *pBitOffset = add(*pBitOffset, 1); move16(); @@ -704,11 +954,12 @@ void IGFCommonFuncsWriteSerialBit(void *st, /**********************************************************************/ /* changes the IGF configuration **************************************************************************/ -Word16 IGFCommonFuncsIGFConfiguration( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - H_IGF_INFO hIGFInfo /**< out: | IGF info handle */ - ,Word16 rf_mode /**< in: flag to signal the RF mode */ +Word16 IGFCommonFuncsIGFConfiguration( + const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + H_IGF_INFO hIGFInfo, /* o : IGF info handle */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ) { H_IGF_GRID hGrid; @@ -721,9 +972,7 @@ Word16 IGFCommonFuncsIGFConfiguration( retValue = 0; /* bitrate index is unknown -> error! */ move16(); /* interface call for reading in settings */ - hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex(bitRate, mode - ,rf_mode - ); + hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex(total_brate, bwidth, element_mode, rf_mode); IF (NE_16(hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN)) { @@ -782,36 +1031,75 @@ Word16 IGFCommonFuncsIGFConfiguration( /**********************************************************************/ /* selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder **************************************************************************/ -Word16 IGFCommonFuncsIGFGetCFTables( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - Word16 rf_mode, /**< in: | flag to signal the RF mode */ - const Word16 **cf_se00, /**< out: | CF table for t == 0 and f == 0 */ - const Word16 **cf_se01, /**< out: | CF table for t == 0 and f == 1 */ - Word16 *cf_off_se01, /**< out: | offset for CF table above */ - const Word16 **cf_se02, /**< out: | CF tables for t == 0 and f >= 2 */ - const Word16 **cf_off_se02, /**< out: | offsets for CF tables above */ - const Word16 **cf_se10, /**< out: | CF table for t == 1 and f == 0 */ - Word16 *cf_off_se10, /**< out: | offset for CF table above */ - const Word16 **cf_se11, /**< out: | CF tables for t == 1 and f >= 1 */ - const Word16 **cf_off_se11 /**< out: | offsets for CF tables above */ +Word16 IGFCommonFuncsIGFGetCFTables( + const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const Word16** cf_se00, /* o : CF table for t == 0 and f == 0 */ + const Word16** cf_se01, /* o : CF table for t == 0 and f == 1 */ + Word16* cf_off_se01, /* o : offset for CF table above */ + const Word16** cf_se02, /* o : CF tables for t == 0 and f >= 2 */ + const Word16** cf_off_se02, /* o : offsets for CF tables above */ + const Word16** cf_se10, /* o : CF table for t == 1 and f == 0 */ + Word16* cf_off_se10, /* o : offset for CF table above */ + const Word16** cf_se11, /* o : CF tables for t == 1 and f >= 1 */ + const Word16** cf_off_se11 /* o : offsets for CF tables above */ ) { Word16 retValue; Word16 bitRateIndex; -Word16 temp_var; - - retValue = 0; /* bitrate index is unknown -> error! */ move16(); - bitRateIndex = IGF_MapBitRateToIndex(bitRate, mode - ,rf_mode - ); + retValue = 0; /* bitrate index is unknown -> error! */ + bitRateIndex = IGF_MapBitRateToIndex(total_brate, bwidth, element_mode, rf_mode); - IF (NE_16(bitRateIndex, IGF_BITRATE_UNKNOWN)) + IF (bitRateIndex != IGF_BITRATE_UNKNOWN) { - retValue = 1; /* no error */ move16(); - SWITCH(bitRateIndex) + retValue = 1; /* no error */ + + SWITCH (bitRateIndex) + { + case IGF_BITRATE_WB_13200_CPE: + bitRateIndex = IGF_BITRATE_WB_9600; + move16(); + BREAK; + case IGF_BITRATE_WB_16400_CPE: + bitRateIndex = IGF_BITRATE_WB_9600; + move16(); + BREAK; + case IGF_BITRATE_SWB_13200_CPE: + bitRateIndex = IGF_BITRATE_SWB_9600; + move16(); + BREAK; + case IGF_BITRATE_SWB_16400_CPE: + bitRateIndex = IGF_BITRATE_SWB_13200; + move16(); + BREAK; + case IGF_BITRATE_SWB_24400_CPE: + bitRateIndex = IGF_BITRATE_SWB_16400; + move16(); + BREAK; + case IGF_BITRATE_FB_24400_CPE: + bitRateIndex = IGF_BITRATE_FB_16400; + move16(); + BREAK; + case IGF_BITRATE_SWB_32000_CPE: + bitRateIndex = IGF_BITRATE_SWB_24400; + move16(); + BREAK; + case IGF_BITRATE_FB_32000_CPE: + bitRateIndex = IGF_BITRATE_FB_24400; + move16(); + BREAK; + case IGF_BITRATE_FB_48000_CPE: + case IGF_BITRATE_FB_64000_CPE: + bitRateIndex = IGF_BITRATE_FB_32000; + move16(); + BREAK; + } + + switch (bitRateIndex) { case IGF_BITRATE_WB_9600: case IGF_BITRATE_RF_WB_13200: @@ -822,115 +1110,99 @@ Word16 temp_var; case IGF_BITRATE_SWB_24400: case IGF_BITRATE_SWB_32000: case IGF_BITRATE_SWB_48000: - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - temp_var = bitRateIndex; - if ((bitRateIndex == 0) || (bitRateIndex == 1)) - { - bitRateIndex = 0; - } - else if ((bitRateIndex == 2) || (bitRateIndex == 3) || (bitRateIndex == 4) || (bitRateIndex == 5)) - { - bitRateIndex = 1; - } - else if ((bitRateIndex == 6) || (bitRateIndex == 7)) - { - bitRateIndex = 2; - } - else if (bitRateIndex == 8) - { - bitRateIndex = 3; - } - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); - bitRateIndex = temp_var; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); - *cf_se10 = &cf_se10_tab[0]; - move16(); - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); + case IGF_BITRATE_SWB_64000: + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16();move16();move16();move16();move16();move16();move16();move16();move16(); + BREAK; case IGF_BITRATE_FB_16400: case IGF_BITRATE_FB_24400: case IGF_BITRATE_FB_32000: - bitRateIndex = add(sub(bitRateIndex, IGF_BITRATE_FB_16400), IGF_BITRATE_SWB_16400); - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - temp_var = bitRateIndex; - if (bitRateIndex == 5) - { - bitRateIndex = 1; - } - else if (bitRateIndex == 6 || bitRateIndex == 7) - { - bitRateIndex = 2; - } - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); - bitRateIndex = temp_var; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); - *cf_se10 = &cf_se10_tab[0]; - move16(); - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); + bitRateIndex = bitRateIndex - IGF_BITRATE_FB_16400 + IGF_BITRATE_SWB_16400; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); BREAK; case IGF_BITRATE_FB_48000: - bitRateIndex = add(sub(bitRateIndex, IGF_BITRATE_FB_48000), IGF_BITRATE_SWB_48000); - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - temp_var = bitRateIndex; - bitRateIndex = 3; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); - bitRateIndex = temp_var; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); - *cf_se10 = &cf_se10_tab[0]; - move16(); - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); + case IGF_BITRATE_FB_64000: + bitRateIndex = bitRateIndex - IGF_BITRATE_FB_48000 + IGF_BITRATE_SWB_48000; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); BREAK; case IGF_BITRATE_FB_96000: case IGF_BITRATE_FB_128000: - bitRateIndex = IGF_BITRATE_SWB_48000; - move16(); - *cf_se00 = cf_se00_tab; - *cf_se01 = cf_se01_tab[bitRateIndex]; - *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; - temp_var = bitRateIndex; - bitRateIndex = 3; - *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); - bitRateIndex = temp_var; - *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); - *cf_se10 = &cf_se10_tab[0]; - move16(); - *cf_off_se10 = cf_off_se10_tab; - *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); - *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); + case IGF_BITRATE_FB_80000_CPE: + case IGF_BITRATE_FB_96000_CPE: + case IGF_BITRATE_FB_128000_CPE: + bitRateIndex = IGF_BITRATE_SWB_48000; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); + BREAK; + case IGF_BITRATE_SWB_48000_CPE: + bitRateIndex = IGF_BITRATE_SWB_16400; + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); + BREAK; + case IGF_BITRATE_SWB_64000_CPE: + case IGF_BITRATE_SWB_80000_CPE: + case IGF_BITRATE_SWB_96000_CPE: + bitRateIndex = IGF_BITRATE_SWB_48000; /*bitRateIndex-IGF_BITRATE_SWB_56000+IGF_BITRATE_SWB_48000;*/ + *cf_se00 = cf_se00_tab; + *cf_se01 = cf_se01_tab[bitRateIndex]; + *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; + *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; + *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; + *cf_se10 = &cf_se10_tab[0]; + *cf_off_se10 = cf_off_se10_tab; + *cf_se11 = &cf_se11_tab[0][0][0]; + *cf_off_se11 = &cf_off_se11_tab[0][0]; + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); BREAK; case IGF_BITRATE_UNKNOWN: default: assert(0); } } + return retValue; } diff --git a/lib_com/index_pvq_opt_fx.c b/lib_com/index_pvq_opt_fx.c index 68297f4..5de8567 100644 --- a/lib_com/index_pvq_opt_fx.c +++ b/lib_com/index_pvq_opt_fx.c @@ -2,13 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include +#include #include "options.h" #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ #include "basop_util.h" -#include #define N_OPT_FX 5 /* complexity setting, direct functional calculation limit & low dim recursion limit */ #define TABLE_LIM_OPT_FX 96 /* odd divisor table , N-row_recursion limit setting, due to dim */ @@ -153,9 +153,7 @@ UWord32 a_four_fx( /* o: offset for dim 4 */ /* return UDIVBY3*((k_val< #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* * interleave_spectrum_fx() @@ -30,8 +29,11 @@ void interleave_spectrum_fx( /* Common inits */ p1 = coefs; p_out = coefs_out; - +#ifdef SOLVED_COMP_ENC_DEC + IF(EQ_16(length, L_SPEC48k)) +#else IF ( EQ_16(length, L_FRAME48k)) +#endif { bw = intl_bw_48; cnt = intl_cnt_48; @@ -41,7 +43,7 @@ void interleave_spectrum_fx( p3 = p2 + sublen[0]; p4 = p3 + sublen[0]; } - ELSE IF( EQ_16(length, L_FRAME32k)) + ELSE IF( EQ_16(length, L_SPEC32k)) { bw = intl_bw_32; cnt = intl_cnt_32; @@ -51,7 +53,7 @@ void interleave_spectrum_fx( p3 = p2 + sublen[1]; p4 = p3 + sublen[1]; } - ELSE /* length == L_FRAME16k */ + ELSE /* length == L_SPEC16k */ { bw = intl_bw_16; cnt = intl_cnt_16; @@ -112,24 +114,33 @@ void de_interleave_spectrum_fx( Word32 coefs_out[L_FRAME48k]; Word16 sublen[] = {80, 160, 240, 320, 480, 720}; Word16 grps; + Word16 l_frame; const Word16 *bw; const Word16 *cnt; /* common for all groups */ p1 = coefs_out; - + l_frame = length; + move16(); +#ifdef SOLVED_COMP_ENC_DEC + IF(EQ_16(length, L_SPEC48k)) +#else IF ( EQ_16(length, L_FRAME48k)) +#endif { bw = intl_bw_48; cnt = intl_cnt_48; grps = N_INTL_GRP_48; move16(); - +#ifdef SOLVED_COMP_ENC_DEC + l_frame = L_FRAME48k; + move16(); +#endif p2 = coefs_out + sublen[2]; /* 240, length/4 */ p3 = coefs_out + sublen[4]; /* 480, 2*length/4 */ p4 = coefs_out + sublen[5]; /* 720, 3*length/4 */ } - ELSE IF( EQ_16(length, L_FRAME32k)) + ELSE IF( EQ_16(length, L_SPEC32k)) { bw = intl_bw_32; cnt = intl_cnt_32; @@ -140,7 +151,7 @@ void de_interleave_spectrum_fx( p3 = coefs_out + sublen[3]; /* 320 */ p4 = coefs_out + sublen[4]; /* 480 */ } - ELSE /* length == L_FRAME16k */ + ELSE /* length == L_SPEC16k */ { bw = intl_bw_16; cnt = intl_cnt_16; @@ -182,7 +193,7 @@ void de_interleave_spectrum_fx( } } - Copy32(coefs_out, coefs, length); + Copy32(coefs_out, coefs, l_frame); return; } diff --git a/lib_com/interpol_fx.c b/lib_com/interpol_fx.c index 3345bff..522a541 100644 --- a/lib_com/interpol_fx.c +++ b/lib_com/interpol_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* tables definition */ -#include "stl.h" Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ diff --git a/lib_com/isf_dec_amr_wb_fx.c b/lib_com/isf_dec_amr_wb_fx.c index 2343d59..ce049c7 100644 --- a/lib_com/isf_dec_amr_wb_fx.c +++ b/lib_com/isf_dec_amr_wb_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #ifdef _MSC_VER void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); @@ -260,11 +260,11 @@ void disf_2s_46b_fx( *-------------------------------------------------------------------*/ void disf_2s_36b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ + Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ + Word16 *mem_AR, /* i/o: quantizer memory for AR model */ + Word16 *mem_MA, /* i/o: quantizer memory for MA model */ + const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ ) { Word16 i; diff --git a/lib_com/ivas_avq_pos_reorder_com.c b/lib_com/ivas_avq_pos_reorder_com.c new file mode 100644 index 0000000..cd682e2 --- /dev/null +++ b/lib_com/ivas_avq_pos_reorder_com.c @@ -0,0 +1,68 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include "options.h" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "prot_fx.h" + +/*-----------------------------------------------------------------* + * ordr_esti() + * + * + *-----------------------------------------------------------------*/ + +void ordr_esti( + const Word16 svLength, /* i : sub-vector index */ + Word16*Mpos, /* i/o: dominant sub-vector position from ACV */ + Word16 svOrder[], /* i/o: AVQ sub-vecotr order */ + const Word16 Nsv /* i : total sub-vectors in a sub-frames */ +) +{ + Word16 i, tmp; + + tmp = svOrder[0]; + svOrder[0] = *Mpos; + *Mpos = sub(Nsv, 1); + move16();move16();move16(); + + FOR ( i = 1; i < svLength; i++ ) + { + svOrder[i] = tmp; + move16(); + tmp = add(tmp, 1); + } + + return; +} diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h new file mode 100644 index 0000000..ce6709c --- /dev/null +++ b/lib_com/ivas_cnst.h @@ -0,0 +1,1603 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_CNST_H +#define IVAS_CNST_H + +#include +#include "options.h" +#include "cnst_fx.h" +#include "ivas_error.h" + +/* clang-format off */ + +/*----------------------------------------------------------------------------------* + * mathematical constants + *----------------------------------------------------------------------------------*/ + +#define PI_OVER_2 ( EVS_PI / 2.0f ) +#define PI_OVER_180 ( EVS_PI / 180.0f ) +#define _180_OVER_PI ( 180.0f / EVS_PI ) + +#define SQRT2 1.414213562373095f +#define SQRT2_OVER_2 (SQRT2 / 2.0f) + +#define INV_SQRT2 7.071067811865475e-1f /* 1/sqrt(2) */ +#define INV_SQRT3 0.577350269189626f /* 1/sqrt(3) */ + +#define LOG_10 2.30258509299f + + +/*----------------------------------------------------------------------------------* + * IVAS formats + *----------------------------------------------------------------------------------*/ + +typedef enum +{ + UNDEFINED_FORMAT, + MONO_FORMAT, /* EVS mono processing */ + STEREO_FORMAT, /* IVAS stereo format */ + ISM_FORMAT, /* IVAS ISM (objects-coding) format */ + SBA_FORMAT, /* IVAS SBA (ambisonics) format */ + MASA_FORMAT, /* IVAS MASA format */ + MC_FORMAT, /* IVAS multi-channel format */ + MASA_ISM_FORMAT, /* IVAS combined MASA + objects format*/ + SBA_ISM_FORMAT /* IVAS combined SBA + objects format */ +} IVAS_FORMAT; + + +/*----------------------------------------------------------------------------------* + * IVAS format signaling + *----------------------------------------------------------------------------------*/ + +#define IVAS_FORMAT_SIGNALING_NBITS 2 /* number of bits for signaling the IVAS format */ +#define IVAS_FORMAT_SIGNALING_NBITS_SBA ( IVAS_FORMAT_SIGNALING_NBITS + 1 ) + + +/*----------------------------------------------------------------------------------* + * IVAS output audio configurations + *----------------------------------------------------------------------------------*/ + +typedef enum +{ + AUDIO_CONFIG_INVALID, + AUDIO_CONFIG_MONO, /* mono output */ + AUDIO_CONFIG_STEREO, /* stereo output */ + AUDIO_CONFIG_5_1, /* 5.1 speakers layout CICP6 */ + AUDIO_CONFIG_7_1, /* 7.1 speakers layout CICP12 */ + AUDIO_CONFIG_5_1_2, /* 5.1+2 speakers layout CICP14 */ + AUDIO_CONFIG_5_1_4, /* 5.1+4 speakers layout CICP16 */ + AUDIO_CONFIG_7_1_4, /* 7.1+4 speakers layout CICP19 */ + AUDIO_CONFIG_LS_CUSTOM, /* custom loudspeaker layout */ + AUDIO_CONFIG_FOA, /* ambisonics, order 1 */ + AUDIO_CONFIG_HOA2, /* ambisonics, order 2 */ + AUDIO_CONFIG_HOA3, /* ambisonics, order 3 */ + AUDIO_CONFIG_OBA, /* object based audio */ + AUDIO_CONFIG_BINAURAL, /* binaural with HRIR */ + AUDIO_CONFIG_BINAURAL_ROOM, /* binaural with HRIR and BRIR */ + AUDIO_CONFIG_ISM1, /* ISM1 */ + AUDIO_CONFIG_ISM2, /* ISM2 */ + AUDIO_CONFIG_ISM3, /* ISM3 */ + AUDIO_CONFIG_ISM4, /* ISM4 */ + AUDIO_CONFIG_EXTERNAL /* external renderer */ + +} AUDIO_CONFIG; + +#ifdef DEBUGGING +typedef enum +{ + RENDER_TYPE_OVERRIDE_NONE, + RENDER_TYPE_OVERRIDE_CREND, + RENDER_TYPE_OVERRIDE_FASTCONV +} ivas_renderTypeOverride; +#endif + +/*----------------------------------------------------------------------------------* + * IVAS rendering configurations + *----------------------------------------------------------------------------------*/ + +/* Rendering convention rules: + * 1) "st_ivas->renderer_type" reflects always the last rendering stage in the processing + * 2) in some configurations, more rendering stages are used + * - renderers at the last stage, like RENDERER_BINAURAL_xxx, consider uniquely "st_ivas->hOutputSetup" + * - renderers that can be followed by an additional rendering stage, e.g. RENDERER_DIRAC, consider uniquely "st_ivas->hIntSetup" + * 3) in case of a single rendering stage: "hIntSetup=hOutputSetup" + * 4) In case of no rendering stage: "hTransSetup=hIntSetup=hOutputSetup" */ + +typedef enum +{ + RENDERER_DISABLE, + RENDERER_TD_PANNING, + RENDERER_BINAURAL_FASTCONV, + RENDERER_BINAURAL_FASTCONV_ROOM, + RENDERER_BINAURAL_PARAMETRIC, + RENDERER_BINAURAL_PARAMETRIC_ROOM, + RENDERER_BINAURAL_OBJECTS_TD, + RENDERER_DIRAC, + RENDERER_MC, + RENDERER_MC_PARAMMC, + RENDERER_SBA_LINEAR_DEC, + RENDERER_SBA_LINEAR_ENC, + RENDERER_STEREO_PARAMETRIC, + RENDERER_MONO_DOWNMIX, + RENDERER_MCMASA_MONO_STEREO, + RENDERER_PARAM_ISM, + RENDERER_BINAURAL_MIXER_CONV, + RENDERER_BINAURAL_MIXER_CONV_ROOM + +} RENDERER_TYPE; + +/*----------------------------------------------------------------------------------* + * IVAS general constants + *----------------------------------------------------------------------------------*/ + +#define MAX_INPUT_CHANNELS 16 /* Maximum number of input channels */ +#define MAX_TRANSPORT_CHANNELS 12 /* Maximum number of transport channels */ +#define MAX_INTERN_CHANNELS 16 /* Maximum number of intern channels (HOA 3rd order) */ +#define HEAD_ROTATION_HOA_ORDER 3 /* HOA 3rd order */ +#define MAX_CICP_CHANNELS 16 /* max channels for loudspeaker layouts (16 for custom layouts)*/ +#define MAX_OUTPUT_CHANNELS 16 /* Maximum number of output channels (HOA 3rd order) */ +#define IVAS_MAX_NUM_CH 16 /* == MAX_OUTPUT_CHANNELS */ + +#define FOA_CHANNELS 4 /* number of FOA channels */ + +#define BINAURAL_CHANNELS 2 /* number of channels for binaural output configuration */ +#define CPE_CHANNELS 2 /* number of CPE (stereo) channels */ +#define MAX_NUM_OBJECTS 4 /* max. number of audio objects */ + +#define MAX_SCE MAX_NUM_OBJECTS /* max. number of SCEs */ +#define MAX_CPE ( MAX_TRANSPORT_CHANNELS / CPE_CHANNELS ) /* max. number of CPEs */ + +#define MAX_BITS_METADATA 2640 /* max. bit-budget of metadata, one channel */ /* IVAS_fmToDo: to be confirmed for final value once mature */ +#define MAX_NUM_METADATA max( 2, MAX_NUM_OBJECTS ) /* number of max. metadata (now only 2 for DirAC) */ + + +#define IVAS_ENC_DELAY_NS ACELP_LOOK_NS +#define IVAS_DEC_DELAY_NS 3250000L /* 3.25 ms: IVAS decoder delay (without renderer delay) */ + +#define DELAY_FB_1_NS 1000000L /* 1.00 ms: filter-bank delay */ +#define DELAY_FB_4_NS 4000000L /* 4.00 ms: filter-bank delay */ + +#define IVAS_FB_ENC_DELAY_NS DELAY_FB_1_NS /* 1.00 ms: IVAS encoder filter-bank delay */ +#define IVAS_FB_DEC_DELAY_NS 5000000L /* 5.00 ms: IVAS decoder/renderer filter-bank delay */ + +#define IVAS_MAX_SBA_ORDER 3 /* Maximum supported Ambisonics order */ + + +/*----------------------------------------------------------------------------------* + * IVAS Bitrates + *----------------------------------------------------------------------------------*/ + +#define IVAS_SID_4k4 4400 /* SID frame bitrate */ +#define IVAS_SID_5k 5000 /* SBA SID frame bitrate */ +#define IVAS_13k2 13200 +#define IVAS_16k4 16400 +#define IVAS_24k4 24400 +#define IVAS_32k 32000 +#define IVAS_48k 48000 +#define IVAS_64k 64000 +#define IVAS_80k 80000 +#define IVAS_96k 96000 +#define IVAS_128k 128000 +#define IVAS_160k 160000 +#define IVAS_192k 192000 +#define IVAS_256k 256000 +#define IVAS_384k 384000 +#define IVAS_512k 512000 + +#define IVAS_BRATE_MAX IVAS_512k + +#define SIZE_IVAS_BRATE_TBL 17 +#define IVAS_NUM_ACTIVE_BRATES (SIZE_IVAS_BRATE_TBL - 3) + +/*----------------------------------------------------------------------------------* + * IVAS modes : IVAS SCE, IVAS CPE modes (DFT, TD, MDCT stereo) + *----------------------------------------------------------------------------------*/ + +#define EVS_MONO 0 /* EVS Mono BE operating mode */ +#define IVAS_SCE 1 /* IVAS SCE */ +#define IVAS_CPE_DFT 2 /* IVAS CPE: DFT-based parametric stereo */ +#define IVAS_CPE_TD 3 /* IVAS CPE: TD stereo */ +#define IVAS_CPE_MDCT 4 /* IVAS CPE: MDCT-based stereo */ + +#define MIN_BRATE_MDCT_STEREO IVAS_48k /* min. CPE bitrate where MDCT stereo is supported in stereo format coding */ + +#define PCA_BRATE IVAS_256k /* PCA supported bitrate */ + +#define NBITS_ELEMENT_MODE 1 /* number of bits to encode the stereo element mode */ +#define NBITS_BWIDTH 2 /* number of bits to encode all audio bandwidths */ + +/* format signalling in SID frames */ +#define SID_FORMAT_NBITS 3 /* Bit 0 | Bit 1 | Bit 2 */ + /*-------|-------|------ */ +#define SID_DFT_STEREO 0x0 /* 0| 0| 0 */ +#define SID_MDCT_STEREO 0x1 /* 1| 0| 0 */ +#define SID_ISM 0x2 /* 0| 1| 0 */ +#define SID_MASA_1TC 0x3 /* 1| 1| 0 */ +#define SID_MULTICHANNEL 0x4 /* 0| 0| 1 */ +#define SID_SBA_1TC 0x5 /* 1| 0| 1 */ +#define SID_SBA_2TC 0x6 /* 0| 1| 1 */ +#define SID_MASA_2TC 0x7 /* 1| 1| 1 */ + +/*----------------------------------------------------------------------------------* + * IVAS ACELP core constants + *----------------------------------------------------------------------------------*/ + +#define MIN_UNVOICED_TWO_STAGE_BRATE 7050 /* min. per channel bitrate where two stages UNVOICED is supported */ +#define MAX_UNVOICED_BRATE ACELP_13k20 /* max. per channel bitrate where UNVOICED is supported */ +#define MAX_VOICED_BRATE ACELP_13k20 /* max. per channel bitrate where VOICED is supported */ +#define MIN_TC_BRATE 6450 /* min. per channel bitrate where TRANSITION is supported */ +#define MAX_ACELP_BRATE 48000 /* max. per channel bitrate where ACELP core is supported */ +#define MAX_ACELP_BRATE_ISM 40000 /* max. per channel bitrate where ACELP core is supported in ISM format */ + +#define ACELP_12k8_HIGH_LIMIT 24350 /* max. per channel bitrate where the ACELP@12.8kHz is supported */ +#define ACELP_16k_LOW_LIMIT 13250 /* min. per channel bitrate where the ACELP@16kHz is supported */ +#define SCE_CORE_16k_LOW_LIMIT 17000 /* min. SCE bitrate where the ACELP@16kHz is supported; must be >= (ACELP_16k_LOW_LIMIT + SWB_TBE_1k6) */ +#define MIN_BRATE_AVQ_EXC ACELP_29k00 /* min. per channel bitrate where the AVQ excitation stage is supported */ +#define MAX_BRATE_AVQ_EXC_TD 40000 /* max. per channel bitrate where the AVQ excitation stage in time domain is supported */ + +#define MAX_GSC_INACTIVE_BRATE 28000 /* max. per channel bitrate where GSC Inactive (@16kHz) is supported (max. 31950 to ensure BE with EVS mono) */ + +#define FRMT_SHP_MIN_BRATE_IVAS 18000 /* min. bitrate where formant-sharpening flag is transmitted; applies both to SCE and CPE */ + +#define CNA_MAX_BRATE_STEREO IVAS_16k4 /* max. stereo bitrate where CNA is supported */ +#define CNA_MAX_BRATE_DFT_STEREO IVAS_32k /* max. stereo bitrate where CNA is supported in DFT stereo */ + +#define MIN_BRATE_WB_BWE 7150 /* min. per channel bitrate where WB BWE info is encoded */ +#define MIN_BRATE_SWB_BWE 7800 /* min. per channel bitrate where SWB BWE info is encoded */ + +#define MIN_BRATE_GSC_NOISY_FLAG 12000 /* min. per channel bitrate where gsc_noisy_flag in SWB is supported */ +#define GSC_L_RATE_STG 15000 /* bitrate below will use low rate GSC settings */ +#define GSC_H_RATE_STG 20000 /* bitrates above will use high rate GSC settings */ + +#define MIN_BRATE_SWB_SCE ACELP_9k60 /* min. SCE bitrate where SWB is supported */ +#define MIN_BRATE_SWB_STEREO IVAS_13k2 /* min. stereo bitrate where SWB is supported */ +#define MIN_BRATE_FB_STEREO IVAS_32k /* min. SCE and stereo bitrate where FB is supported */ +#define MIN_BRATE_FB_ISM 16000 /* min. SCE bitrate where FB is supported in ISM format */ + +#define MIN_TDM_BRATE_WB_TBE_1k05 12000 /* min. per channel bitrate where WB TBE @1.05 kbps is supported (0.35kbs at lower bitrates) */ +#define MIN_BRATE_WB_TBE_1k05 9650 /* min. per channel bitrate where WB TBE @1.05 kbps is supported (0.35kbs at lower bitrates) */ +#define MIN_BRATE_SWB_TBE_1k60 13200 /* min. per channel bitrate where SWB TBE @1.60 kbps is supported (0.95 kbps at lower bitrates) */ +#define MIN_BRATE_SWB_TBE_2k80 24400 /* min. per channel bitrate where SWB TBE @2.80 kbps is supported */ +#define MIN_MIN_BRATE_LRTD_SWB_BWE 5000 + +#define STEREO_TCX_MIN_RATE 9000 /* TCX coding down to this per channel bitrate */ +#define STEREO_GSC_BIT_RATE_ALLOC 9200 +#define HQ_MDCTCLASS_CROSSOVER_BRATE 32000 /* MDCT classifier crossover bitrate between 24.4 and 32 kbps tunings*/ +#define HQ_BWE_CROSSOVER_BRATE 26000 /* HQ crossover bitrate between 24.4 and 32 kbps BWE tunings */ + + +/*----------------------------------------------------------------------------------* + * ISm Constants + *----------------------------------------------------------------------------------*/ + +#define META_LINE_LENGTH 200 /* max number of characters at one line of metadata input/output file */ + +#define ISM_NB_BITS_METADATA_NOMINAL ( ( SCE_CORE_16k_LOW_LIMIT - ACELP_16k_LOW_LIMIT ) / FRAMES_PER_SEC ) /* nominal number of metadata bits - used for configuration of Core-Coder modules */ + +#define ISM_METADATA_VAD_FLAG_BITS 1 +#define ISM_METADATA_FLAG_BITS 2 + +#define ISM_NO_META 0 +#define ISM_LOW_IMP 1 +#define ISM_MEDIUM_IMP 2 +#define ISM_HIGH_IMP 3 + +#define ISM_AZIMUTH_NBITS 7 +#define ISM_AZIMUTH_MIN -180.0f +#define ISM_AZIMUTH_MAX 180.0f +#define ISM_AZIMUTH_LOW_BORDER -140.0f +#define ISM_AZIMUTH_HIGH_BORDER 135.0f + +#define ISM_ELEVATION_NBITS 6 +#define ISM_ELEVATION_MIN -90.0f +#define ISM_ELEVATION_MAX 90.0f +#define ISM_ELEVATION_LOW_BORDER -70.0f +#define ISM_ELEVATION_HIGH_BORDER 65.0f +#define ISM_Q_STEP 2.5f +#define ISM_Q_STEP_BORDER 5.0f + +/* Parametric ISM */ +#define MAX_PARAM_ISM_NBANDS 11 +#define MAX_PARAM_ISM_NBANDS_WB 9 +#define MAX_PARAM_ISM_NBANDS_NB 7 +#define PARAM_ISM_MDFT_NO_SLOTS 4 +#define MAX_PARAM_ISM_NBLOCKS 1 +#define MAX_PARAM_ISM_WAVE 2 +#define PARAM_ISM_OBJ_IND_NBITS 2 +#define PARAM_ISM_POW_RATIO_NBITS 3 +#define PARAM_ISM_MAX_DMX 2 +#define PARAM_ISM_MAX_CHAN 16 +#define PARAM_ISM_HYS_BUF_SIZE 10 + +typedef enum +{ + ISM_MODE_NONE, + ISM_MODE_DISC, /* discrete ISM */ + ISM_MODE_PARAM /* parametric ISM */ +} ISM_MODE; + + +/* ISm metadata bitstream */ +enum +{ + IND_ISM_NUM_OBJECTS, + IND_ISM_METADATA_FLAG = IND_ISM_NUM_OBJECTS + MAX_NUM_OBJECTS, + IND_ISM_VAD_FLAG = IND_ISM_METADATA_FLAG + MAX_NUM_OBJECTS, + + /* ------------- loop for objects -------------- */ + TAG_ISM_LOOP_START = IND_ISM_VAD_FLAG + MAX_NUM_OBJECTS, + IND_ISM_AZIMUTH_DIFF_FLAG = TAG_ISM_LOOP_START, + IND_ISM_AZIMUTH = TAG_ISM_LOOP_START, + IND_ISM_ELEVATION_DIFF_FLAG = TAG_ISM_LOOP_START, + IND_ISM_ELEVATION = TAG_ISM_LOOP_START, + TAG_ISM_LOOP_END = TAG_ISM_LOOP_START + 100, /* IVAS_fmToDo: to be reviewed once the final metadata are defined */ + /* --------- end of loop for objects ----------- */ + + ISM_MAX_NUM_INDICES +}; + + +/*----------------------------------------------------------------------------------* + * DFT Stereo Constants + *----------------------------------------------------------------------------------*/ + +/* Coding configurations*/ +#define STEREO_DFT_DMX_ACTIVE 1 /* Enable true spatialization */ + +/* residual coding modes */ +#define STEREO_DFT_RES_COD_OFF 0 +#define STEREO_DFT_RES_COD_1kHz 1 /* use residual coding up to 1 kHz */ +#define STEREO_DFT_RES_COD_1_6kHz 2 /* use residual coding up to 1.6 kHz */ + +/* residual prediction modes */ +#define STEREO_DFT_RESPRED_OFF 0 +#define STEREO_DFT_RESPRED_STEFI 1 /* full-band stereo filling (above residual) */ +#define STEREO_DFT_RESPRED_ESF 2 /* enhanced stereo filling in LB, regular stereo filling in HB */ + +/* band resolution */ +#define STEREO_DFT_BAND_RES_HIGH 1 /* use higher band resolution following ERB4 scale */ +#define STEREO_DFT_BAND_RES_LOW 2 /* use lower band resolution following ERB8 scale */ + +/* Processing constants*/ +#define STEREO_DFT_OVL_NS ACELP_LOOK_NS /* 8.75ms */ +#define STEREO_DFT_ZP_NS 3125000L /* 3.125ms */ +#define STEREO_DFT_HOP_NS 10000000L /* 10ms */ +#define STEREO_DFT_N_NS ( STEREO_DFT_HOP_NS + ACELP_LOOK_NS + 2 * STEREO_DFT_ZP_NS ) + +#define STEREO_DFT_ZP_NS_ENC 5625000L /* 5.625ms */ +#define STEREO_DFT_HOP_NS_ENC FRAME_SIZE_NS /* 20ms */ +#define STEREO_DFT_N_NS_ENC ( STEREO_DFT_HOP_NS_ENC + ACELP_LOOK_NS + 2 * STEREO_DFT_ZP_NS_ENC ) + +#define STEREO_DFT_OVL_MAX NS2SA( 48000, ACELP_LOOK_NS ) +#define STEREO_DFT_HOP_MAX NS2SA( 48000, STEREO_DFT_HOP_NS ) + +#define STEREO_DFT_ZP_MAX_ENC NS2SA( 48000, STEREO_DFT_ZP_NS_ENC ) +#define STEREO_DFT_HOP_MAX_ENC NS2SA( 48000, STEREO_DFT_HOP_NS_ENC ) +#define STEREO_DFT_N_MAX_ENC NS2SA( 48000, STEREO_DFT_N_NS_ENC ) + +#define STEREO_DFT_OVL_32k NS2SA( 32000, ACELP_LOOK_NS ) + +#define STEREO_DFT_ZP_32k_ENC NS2SA( 32000, STEREO_DFT_ZP_NS_ENC ) +#define STEREO_DFT_HOP_32k_ENC NS2SA( 32000, STEREO_DFT_HOP_NS_ENC ) +#define STEREO_DFT_N_32k_ENC NS2SA( 32000, STEREO_DFT_N_NS_ENC ) + +#define STEREO_DFT_OVL_16k NS2SA( 16000, ACELP_LOOK_NS ) + +#define STEREO_DFT_ZP_16k_ENC NS2SA( 16000, STEREO_DFT_ZP_NS_ENC ) +#define STEREO_DFT_HOP_16k_ENC NS2SA( 16000, STEREO_DFT_HOP_NS_ENC ) +#define STEREO_DFT_N_16k_ENC NS2SA( 16000, STEREO_DFT_N_NS_ENC ) + +#define STEREO_DFT_OVL_12k8 NS2SA( 12800, ACELP_LOOK_NS ) + +#define STEREO_DFT_ZP_12k8_ENC NS2SA( 12800, STEREO_DFT_ZP_NS_ENC ) +#define STEREO_DFT_HOP_12k8_ENC NS2SA( 12800, STEREO_DFT_HOP_NS_ENC ) +#define STEREO_DFT_N_12k8_ENC NS2SA( 12800, STEREO_DFT_N_NS_ENC ) + +#define STEREO_DFT_OVL_8k NS2SA( 8000, ACELP_LOOK_NS ) +#define STEREO_DFT_N_8k NS2SA( 8000, STEREO_DFT_N_NS ) + +#define STEREO_DFT_ZP_8k_ENC NS2SA( 8000, STEREO_DFT_ZP_NS_ENC ) +#define STEREO_DFT_HOP_8k_ENC NS2SA( 8000, STEREO_DFT_HOP_NS_ENC ) +#define STEREO_DFT_N_8k_ENC NS2SA( 8000, STEREO_DFT_N_NS_ENC ) + +#define STEREO_DFT32MS_N_NS FRAME_SIZE_NS /* 20 ms */ +#define STEREO_DFT32MS_OVL_NS 3125000L /* 3.125ms - Overlap for the outer edges of windows on decoder */ +#define STEREO_DFT32MS_OVL2_NS 9375000L /* 9.375ms - Overlap for the inner edges of windows on decoder */ +#define STEREO_DFT32MS_WIN_CENTER_NS ( int32_t )( ( FRAME_SIZE_NS + STEREO_DFT32MS_OVL_NS ) * 0.5f ) /* 11.5625ms - mid point of the two windows wrt the left edge of overlap */ +#if defined( DEBUG_MODE_DFT ) || defined( DEBUG_STEREO_DFT_NOCORE ) +#define STEREO_DFT32MS_HOP_NS 10000000L /* 10ms */ +#endif +#define STEREO_DFT32MS_ZP_NS ( int32_t )( 0.5f * ( STEREO_DFT32MS_N_NS - STEREO_DFT32MS_WIN_CENTER_NS - ( STEREO_DFT32MS_OVL2_NS * 0.5f ) ) ) /* 2 sided zp calculated such that window size is satisfied */ + +#define STEREO_DFT32MS_OVL_MAX NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) +#define STEREO_DFT32MS_OVL2_MAX NS2SA( 48000, STEREO_DFT32MS_OVL2_NS ) +#define STEREO_DFT32MS_N_MAX NS2SA( 48000, STEREO_DFT32MS_N_NS ) + +#define STEREO_DFT32MS_N_32k NS2SA( 32000, STEREO_DFT32MS_N_NS ) + +#define STEREO_DFT32MS_OVL_16k NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) +#define STEREO_DFT32MS_OVL2_16k NS2SA( 16000, STEREO_DFT32MS_OVL2_NS ) +#define STEREO_DFT32MS_N_16k NS2SA( 16000, STEREO_DFT32MS_N_NS ) + +#define STEREO_DFT32MS_OVL_12k8 NS2SA( 12800, STEREO_DFT32MS_OVL_NS ) +#define STEREO_DFT32MS_OVL2_12k8 NS2SA( 12800, STEREO_DFT32MS_OVL2_NS ) +#define STEREO_DFT32MS_N_12k8 NS2SA( 12800, STEREO_DFT32MS_N_NS ) + +#define STEREO_DFT32MS_OVL_8k NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) +#define STEREO_DFT32MS_OVL2_8k NS2SA( 8000, STEREO_DFT32MS_OVL2_NS ) +#define STEREO_DFT32MS_N_8k NS2SA( 8000, STEREO_DFT32MS_N_NS ) + +#define STEREO_DFT32MS_STEP 3 /* STEREO_DFT32MS_OVL2_NS / STEREO_DFT32MS_OVL_NS */ +#define STEREO_DFT_TRIGO_DEC_STEP 2 +#define STEREO_DFT_TRIGO_SRATE_8k_STEP 4 +#define STEREO_DFT_TRIGO_SRATE_12k8_STEP 1 +#define STEREO_DFT_TRIGO_SRATE_16k_STEP 2 +#define STEREO_DFT_TRIGO_SRATE_32k_STEP 1 +#define STEREO_DFT_TRIGO_SRATE_48k_STEP 1 + +#define STEREO_DFT_OFFSET 1 +#define STEREO_DFT_NBDIV 2 + +#define STEREO_DFT_DELAY_DEC_BWE_NS ( STEREO_DFT_OFFSET * STEREO_DFT_HOP_NS - ACELP_LOOK_NS ) /* 1.25ms/2.5ms: max delay for core decoder*/ + +#define STEREO_DFT_ENC_DFT_NB ( STEREO_DFT_OFFSET + 1 ) /*frame + lookahead*/ +#define STEREO_DFT_DEC_DFT_NB ( STEREO_DFT_NBDIV + STEREO_DFT_OFFSET ) /*frame + lookahead*/ + +#define STEREO_CNA_LR_CORR_LT_FILT 0.95f /* long-term averaging factor for L/R correlation estimation */ +#define STEREO_CNA_ILD_LT_FILT 0.9f /* long-term averaging factor for ILD estimation */ + +typedef enum +{ + DFT_STEREO_DEC_ANA_NOCORE = -1, /*-1: signal read from file (DEBUG mode)*/ + DFT_STEREO_DEC_ANA_FB, /* 0: full-band signal (e.g. HQ-CORE/TCX (M), residual (S))*/ + DFT_STEREO_DEC_ANA_FB_ADD, /* 1: full-band signal to add (e.g High-band signal of TD-BWE)*/ + DFT_STEREO_DEC_ANA_BPF, /* 2: Bass-post-filter error signal, to add and weight*/ + DFT_STEREO_DEC_ANA_LB, /* 3: low-band signal (e.g. ACELP (M), resiudal signal (S))*/ + DFT_STEREO_DEC_ANA_LB_ADD, /* 4: low-band signal to add (e.g. LB-TCX)*/ + DFT_STEREO_DEC_ANA_HB_ADD /* 5: high-band signal to add (e.g. transition to ACELP in MDCT->DFT switching) */ +} DFT_STEREO_DEC_ANA_TYPE; + +/*Stereo parameters*/ + +#define STEREO_DFT_ERB4_BANDS 14 +#define STEREO_DFT_ERB8_BANDS 8 +#define STEREO_DFT_BAND_MAX ( STEREO_DFT_ERB4_BANDS - 1 ) /*Maximum number of parameter bands*/ +#define STEREO_DFT_BUF_MAX STEREO_DFT32MS_N_MAX * STEREO_DFT_NBDIV + +#define STEREO_DFT_NRG_PAST_LEN 3 + +/*ITD*/ +#define STEREO_DFT_ITD_FS 32000 +#define STEREO_DFT_ITD_MAX 160 /*samples @ 32000*/ +#define STEREO_DFT_ITD_MAX_ANA 200 +#define STEREO_DFT_ITD_MIN max( STEREO_DFT_ITD_MAX - 256 + 1, 1 ) /*STEREO_DFT_ITD_MAX-pow(2,STEREO_DFT_ITD_NBITS-1)+1*/ +#define STEREO_DFT_ITD_NBITS 9 /* 1 bit for sign, the rest for the absolute value*/ +#define STEREO_DFT_ITD_MODE_NBITS 1 + +#define STEREO_DFT_SID_ITD_NBITS 4 /* Number of ITD bits SID frames */ +#define STEREO_DFT_SID_ITD_FAC 1 /* Quantization step reduction factor */ + +#define STEREO_DFT_FLAG_BITS 1 +#define STEREO_DFT_SIDEGAIN_NBITS 5 +#define STEREO_DFT_FEC_THRESHOLD 10 +#define STEREO_DFT_BITDIFF_LP_FAC (0.06f) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ +#define STEREO_DFT_BITDIFF_ABS_SELECT (0.8f) /* Constant to set tendency for selecting absolute coding mode */ +#define STEREO_DFT_BITDIFF_INIT (12.0f) /* Init value for low-pass bit difference */ + +#define STEREO_DFT_SIDE_GAIN_NBITS 5 +#define STEREO_DFT_IPD_NBITS 3 +#define STEREO_DFT_GIPD_NBITS 4 + +#define STEREO_DFT_ITD_VAD_BAND_NUM 20 + +#define STEREO_DFT_XCORR_LB_MAX 24 + +#define STEREO_DFT_N_COH_PRED 4 /* Number of intra-frame predictors for coherence vector */ +#define STEREO_DFT_COH_PRED_COEFFS 15 /* Number of coefficients per predictor */ +#define STEREO_DFT_PRED_NBITS 2 /* Bits to signal predictor (log_2(4) = 2) */ +#define STEREO_DFT_N_COH_ALPHA_STEPS 5 +#define STEREO_DFT_N_COH_ALPHA_LEVELS 2 +#define STEREO_DFT_N_COH_ALPHA_BITS 1 +#define STEREO_DFT_SG_ACT_CNT_MAX 1500 +#define STEREO_DFT_COH_MAXBAND 6 +#define STEREO_DFT_SID_GIPD_NBITS 2 +#define STEREO_DFT_FD_FILT 0.9f + +/*Residual prediction*/ +#define STEREO_DFT_PAST_MAX 4 +#define STEREO_DFT_RES_PRED_BAND_MAX 12 + +#define STEREO_DFT_REVERB_MODE_NBITS 1 +#define STEREO_DFT_RES_PRED_BAND_MIN 0 +#define STEREO_DFT_RES_PRED_BAND_MIN_RED 3 +#define STEREO_DFT_RES_PRED_BAND_MIN_CONST 3 + +#define STEREO_DFT_ALLPASS_BUFFERLEN 256 +#define STEREO_DFT_ALLPASS_FADELEN_12k8 32 +#define STEREO_DFT_ALLPASS_FADELEN_16k 40 +#define STEREO_DFT_CORE_HIST_MAX ( STEREO_DFT_PAST_MAX + 3 ) / 2 +#define STEREO_DFT_TD_STEFI_DELAY_NS FRAME_SIZE_NS + IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS +#define STEREO_DFT_TD_STEFI_SUBFR_DELAY 2 + +/*Residual coding*/ +#define STEREO_DFT_N_MAX_RES 800 /* Maximum of lines coded in residual coding */ +#define STEREO_DFT_RES_GLOBAL_GAIN_BITS 7 +#define STEREO_DFT_RES_GAINS_BITS 3 + +#define STEREO_DFT_RES_COD_SNR_MIN 10 +#define STEREO_DFT_RES_COD_SNR_MAX 40 +#define STEREO_DFT_L_SUBFR_8k 32 +#define STEREO_DFT_NBPSF_PIT_MAX_8k NBPSF_PIT_MAX / 2 + +/* Residual coding BPF */ +#define STEREO_DFT_BPF_ADAPT_ALPHA (0.61f) +#define STEREO_DFT_BPF_ADAPT_BETA (0.68f) + +/* Golomb-Rice encoding */ +#define NO_SYMB_GR_SIDE_G 31 +#define NO_SYMB_GR_PRED_G 8 + +#define STEREO_DFT_RES_BW_MAX 66 /*Maximum number of bin for residual signal in each frame (res_cod_band_max == 6 in 48kHz)*/ +#define SBA_DIRAC_STEREO_NUM_BANDS 5 +#define SBA_DIRAC_NRG_SMOOTH_LONG 10 +#define SBA_DIRAC_NRG_SMOOTH_SHORT 3 + +/* PLC for DFT Stereo residual */ +#define STEREO_DFT_RES_N_PEAKS_MAX 15 /*Maximum number of peaks within residual signal in each frame (res_cod_band_max == 6 in 48kHz)*/ + +/* MDCT to DFT Stereo switching */ +#define STEREO_MDCT2DFT_FADE_LEN_48k L_FRAME48k / 8 + +/* DFT stereo side-info bitstream*/ +enum +{ + IND_STEREO_DFT_ATTACK_PRESENT, + IND_STEREO_DFT_RES_COD, + IND_STEREO_DFT_SIDEGAIN_FLAG, + + IND_STEREO_DFT_SIDEGAINS, + IND_STEREO_DFT_ITD_MODE = IND_STEREO_DFT_SIDEGAINS + 4 * STEREO_DFT_BAND_MAX + 72, + + IND_STEREO_DFT_ITD_HUFF, + IND_STEREO_DFT_ITD_NEG, + IND_STEREO_DFT_ITD_COD, + + IND_STEREO_DFT_NO_IPD_FLAG, + IND_STEREO_DFT_GIPD, + + IND_STEREO_DFT_IPD_FLAG, + IND_STEREO_DFT_IPD_COD, + + IND_STEREO_DFT_REVERB_MODE = IND_STEREO_DFT_IPD_COD + 4 * STEREO_DFT_BAND_MAX + 2, /* max number for GR order 2 */ + + IND_STEREO_DFT_RES_PRED_FLAG, + IND_STEREO_DFT_PRED_GAIN_COD, + + IND_STEREO_DFT_NON_USED = IND_STEREO_DFT_PRED_GAIN_COD + 4 * STEREO_DFT_RES_PRED_BAND_MAX + 2, /* max number for GR order 2 */ + + /* residual coding */ + IND_STEREO_DFT_RESIDUAL_GLOBAL_GAIN, + IND_STEREO_DFT_RESIDUAL_COD, + IND_STEREO_DFT_SID_COH = IND_STEREO_DFT_RESIDUAL_COD + 56, /* max possible number of indices for residual coding */ + + STEREO_DFT_MAX_NUM_INDICES = IND_STEREO_DFT_SID_COH + 6 /* max possible number of indices for coherence encoding */ +}; + + +/*----------------------------------------------------------------------------------* + * Range coder constants + *----------------------------------------------------------------------------------*/ + +#define RANGE_UNI_BUFFER_BYTES_MAX 1024 +#define RANGE_N_CONTEXT 64 +#define RANGE_N_SYMBOLS 17 + + +/*----------------------------------------------------------------------------------* + * ECLVQ Stereo constants + *----------------------------------------------------------------------------------*/ + +#define ECSQ_VECTOR_SIZE_MAX 256 +#define ECSQ_GLOBAL_GAIN_INDEX_ALL_ZERO 127 /* indicates that all values in the vector are zero */ + +#define ECLVQ_GLOBAL_GAIN_FACTOR ( 20.0f * 127.0f / 90.0f ) +#define ECLVQ_INV_GLOBAL_GAIN_FACTOR ( 1.0f / ( 20.0f * 127.0f / 90.0f ) ) + +/* the currently defined configuration indexes are: + 0: un-optimized using uniform 4 bit parameters (reserved) + 1: optimized for 32 kbps target SNR + 2: optimized for 32 kbps target bits + 3: optimized for 48 kbps target SNR + 4: optimized for 48 kbps target bits + 5: optimized for 64 kbps target SNR + 6: optimized for 64 kbps target bits +*/ + +#define ECSQ_CONFIG_COUNT 7 /* number of different configurations, such as bitrates or profiles */ +#define ECSQ_PARAM_COUNT 16 /* number of different coding distributions, the first indicates only zero values */ +#define ECSQ_ALL_ZERO_PARAM -1 /* the integer exponent of the first parameter indicating only zero values */ +#define ECSQ_PROB_BITS 14 /* number of bits used for representing the probabilities in the actual AC */ +#define ECSQ_PROB_TOTAL ( 1 << ECSQ_PROB_BITS ) /* total count used for representing the probabilities in the actual AC */ + +#define ECSQ_TAB_VALS_SIZE 16 /* 0, 1, 2, 3, ... */ +#define ECSQ_SEGMENT_SIZE 8 +#define ECSQ_log2TB_SIZE 13 +#define ECSQ_PARAM_SEARCH_RANGE 1 +#define ECSQ_NONZERO_MAX 3 + + +/*----------------------------------------------------------------------------------* + * UNCLR & cross-talk stereo classifiers + *----------------------------------------------------------------------------------*/ + +#define XTALK_SCORE_BUF_LEN 5 + +#define SSC_MAX_NFEA 58 /* Maximum number of features for stereo scene classification */ +#define SIZE_UNCLR_ISEL_TD 10 +#define SIZE_UNCLR_ISEL_DFT 8 + +#define SIZE_XTALK_ISEL_TD 17 +#define SIZE_XTALK_ISEL_DFT 11 + +#define UNCLR_L_ETOT 3 +#define UNCLR_L_RELE 10 +#define UNCLR_RC_ORDER 20 +#define MAX_UV_CNT 100 + +#define XTALK_PHAT_LEN 200 + +enum fea_names +{ + E_d_clas, E_d_pitch, E_d_voicing, E_sum_d_LSF, E_d_lepsP_13, E_d_cor_map_sum, E_d_dE1, E_d_nchar, + E_d_non_sta, E_d_ps_sta, E_d_ps_diff, E_d_sp_div, E_clas, E_pitch, E_voicing, E_lsf_1, + E_lsf_4, E_lsf_9, E_lsf_14, E_lepsP_13, E_cor_map_sum, E_dE1, E_nchar, E_non_sta, + E_ps_sta, E_ps_diff, E_sp_div, E_corrLagStats0, E_ica_corr_value0, E_ica_instTargetGain, + E_diff_corrLM_corrRM, E_tdm_LT_es_em, E_sum_prod, E_tdm_es_em, E_m_corrL_corrR, E_d_corrL_corrR, E_corrEst0, E_corrLagMax, + E_d_corrLagMax, E_corrEstMax, E_corrEst_ncorr,E_sum_xcorr, E_es_em, E_cohSNR, E_d_prodL_prodR, E_xcorr_itd_value, + E_angle_rot, E_g_pred, E_g_side, E_gainILD, E_gainIPD, E_IPD, E_d_IPD, E_ITD, + E_gphat_d_itd2, E_gphat_itd1_flip, E_gphat_ratio_m1_m2, E_gphat_m2_m2 +}; + + +/*----------------------------------------------------------------------------------* + * ICA Stereo constants + *----------------------------------------------------------------------------------*/ + +#define L_CH_INDX 0 +#define R_CH_INDX 1 +#define CORR_INTER_FS 8000 +#define L_NCSHIFT_NS 5000000L +#define L_MEM_RECALC_NS ( L_NCSHIFT_NS * 3 ) / 2 +#define L_MEM_RECALC_TBE_NS ( L_NCSHIFT_NS + L_SAMPLES_LA_NS ) +#define L_NCSHIFTMAX NS2SA( 48000, L_NCSHIFT_NS ) +#define L_DEC_MEM_LEN_ICA L_NCSHIFTMAX + ( N_MAX_SHIFT_CHANGE + 1 ) + SINC_ORDER1 / INTERP_FACTOR1 +#define L_FRAME_DS NS2SA( CORR_INTER_FS, FRAME_SIZE_NS ) +#define L_XCORRMEM_DS NS2SA( CORR_INTER_FS, 2 * ( ACELP_LOOK_NS ) ) +#define L_NCSHIFT_DS ( int16_t )( ( ( int32_t )(CORR_INTER_FS) *L_NCSHIFTMAX ) / 48000L ) +#define L_SAMPLES_LA_NS 625000L + +#define L_MEM_RECALC_TBE_16K NS2SA( 16000, L_MEM_RECALC_TBE_NS ) +#define L_MEM_RECALC_48K NS2SA( 48000, L_MEM_RECALC_NS ) +#define L_MEM_RECALC_12K8 NS2SA( 12800, L_MEM_RECALC_NS ) +#define L_MEM_RECALC_16K NS2SA( 16000, L_MEM_RECALC_NS ) +#define N_MAX_SHIFT_CHANGE 20 + +#define L_MEM_RECALC_SCH_NS ( ACELP_LOOK_NS + DELAY_FIR_RESAMPL_NS - L_MEM_RECALC_NS ) +#define L_MEM_RECALC_48k_SCH NS2SA( 48000, L_MEM_RECALC_SCH_NS ) + +#define INTERP_FACTOR1 2 +#define SINC_ORDER1 24 +#define L_SHIFT_ADAPT_MAX 596 /* must be a multiple of 2 */ +#define L_SHIFT_ADAPT_16k 290 /* must be a multiple of 2 */ + +#define STEREO_BITS_TCA_CHAN 1 /* ref/target channel index */ +#define STEREO_BITS_TCA_CORRSTATS 5 /* target corrStats */ +#define STEREO_BITS_TCA_GD 5 /* target gain */ +#define STEREO_TCA_GDMIN -1.0f +#define STEREO_TCA_GDSTEP 0.05f +#define STEREO_BITS_TCA ( STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS + STEREO_BITS_TCA_GD ) + +#define STEREO_ICBWE_MSFLAG_BITS 1 /* BWE Multi Source flag */ + +#define STEREO_ICBWE_REFBITS 1 +#define STEREO_ICBWE_SPBITS 2 +#define STEREO_ICBWE_GSBITS 4 +#define STEREO_BITS_ICBWE ( STEREO_ICBWE_SPBITS + STEREO_ICBWE_GSBITS + STEREO_ICBWE_REFBITS ) + +#define STEREO_ICBWE_SPBITS_DFT 2 +#define STEREO_ICBWE_GSBITS_DFT 7 +#define STEREO_BITS_ICBWE_DFT ( STEREO_ICBWE_SPBITS_DFT + STEREO_ICBWE_GSBITS_DFT + STEREO_ICBWE_REFBITS ) + +#define MAX_DELAYREGLEN 12 /* max regression length */ +#define INV_MAX_DELAYREGLEN 0.083333333333333f /* (1/MAX_DELAYREGLEN) */ +#define MAX_INTERPOLATE 11 +#define ADDED_MEM_DS 40 + +#define STEREO_L_TCA_OVLP_NS 5000000L /* overlap length of the ICA gain scaling */ + + +/*----------------------------------------------------------------------------------* + * TD Stereo Constants + *----------------------------------------------------------------------------------*/ + +#define TDM_NQ ( 32 - 1 ) /* number of quantization steps of mixing factor */ +#define LRTD_STEREO_LEFT_IS_PRIM ( TDM_NQ - 1 ) /* Ratio index value indicating that left channel is coded as primary channel */ +#define LRTD_STEREO_RIGHT_IS_PRIM 0 /* Ratio index value indicating that right channel is coded as primary channel */ +#define LRTD_STEREO_QUARTER_RANGE ( ( TDM_NQ + 1 ) / 4 ) /* Ratio index value */ +#define LRTD_STEREO_MID_IS_PRIM ( ( TDM_NQ - 1 ) / 2 ) /* Ratio index value */ + +#define TDM_L_NOVA_NS 5000000L /* mixing overlap length */ + +#define TDM_SECONDARY_SIGNALLING 3 /* number of bits to code the signalling for secondary channel */ +#define TDM_RATIO_BITS 5 /* number of bits to code the correlation ratio */ +#define TDM_LP_REUSE_BITS 1 /* number of bits to code LP reuse flag for secondary channel */ +#define TDM_LR_CONTENT_BITS 1 /* number of bits to code flag when the content is LR or not */ +#define TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS + STEREO_BITS_TCA ) +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#define TDM_IC_LSF_PRED_BITS 1 /* Number of bits to code the inter channel lsf prediction mode */ +#endif +#endif + + +/*----------------------------------------------------------------------------------* + * MDCT Stereo Constants + *----------------------------------------------------------------------------------*/ + +/* MDCT stereo modes */ +#define SMDCT_MS_DECISION 0 +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE +#define SMDCT_FORCE_LR 1 +#define SMDCT_FORCE_MS 2 +#endif + +#define MAX_SFB 70 /* Maximum number of stereo frequency bands = 64 + 6 for TCX after ACELP */ + +#define SMDCT_DUAL_MONO 0 /* Dual-mono MDCT Stereo */ +#define SMDCT_MS_FULL 1 /* MS MDCT Stereo */ +#define SMDCT_BW_MS 2 /* Band-wise MS MDCT Stereo */ + +#define SMDCT_MINIMUM_ARITH_BITS 17 /* Minimum bits to reserve for the arithmetic coder */ +#define SMDCT_GLOBAL_ILD_BITS 4 +#define SMDCT_ILD_RANGE ( 1 << SMDCT_GLOBAL_ILD_BITS ) /* Range of the coded ILD */ +#define SMDCT_NBBITS_SPLIT_RATIO 3 +#define SMDCT_BITRATE_RATIO_RANGE ( 1 << SMDCT_NBBITS_SPLIT_RATIO ) /* Range of the coded bitrate distribution ratio */ +#define SMDCT_EQUAL_RATIO_RANGE ( SMDCT_BITRATE_RATIO_RANGE >> 1 ) + +#define SMDCT_MAX_STEREO_BANDS_TCX20 44 +#define SMDCT_MAX_STEREO_BANDS_TCX10 33 + +#define MAX_MDCT_ITD_BRATE IVAS_64k + +#define SNS_LOW_BR_MODE -1 +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT +#define SNS_NPTS 16 /* Number of downsampled SNS parameters */ + +#define MDCT_ST_PLC_FADEOUT_START_FRAME 3 + +typedef enum { + EQUAL_CORES, + TCX10_IN_0_TCX20_IN_1, + TCX20_IN_0_TCX10_IN_1, +} TONALMDCTCONC_NOISE_GEN_MODE; +#endif + + +/*----------------------------------------------------------------------------------* + * MDFT FB Constants + *----------------------------------------------------------------------------------*/ + +#define MDFT_FB_BANDS_240 240 +#define CLDFB_TO_MDFT_FAC 4 +#define MDFT_NO_COL_MAX 4 + +/*----------------------------------------------------------------------------------* + * General Parametric Coding Constants + *----------------------------------------------------------------------------------*/ +// VE: this should be renamed to e.g. N_SPATIAL_SUBFRAMES +#define MAX_PARAM_SPATIAL_SUBFRAMES 4 /* Maximum number of subframes for parameteric spatial coding */ + + +/*----------------------------------------------------------------------------------* + * SBA Constants + *----------------------------------------------------------------------------------*/ + +#define SBA_PLANAR_BITS 1 +#define SBA_ORDER_BITS 2 +#define SBA_NHARM_HOA3 16 + +typedef enum +{ + SBA_MODE_NONE, + SBA_MODE_DIRAC, + SBA_MODE_SPAR, // VE: this is actually SBA_MODE_SPAR_DIRAC +} SBA_MODE; + + +/*----------------------------------------------------------------------------------* + * DirAC Constants + *----------------------------------------------------------------------------------*/ + +#define DIRAC_MAX_ANA_CHANS 4 /* Maximum number of channels for DirAC analysis */ +#define DIRAC_MAX_TRANS_CHANS 8 /* Maximum number of transport channels for DirAC */ + +#define DIRAC_MIN_BITRATE_8_TRANS_CHAN IVAS_384k +#define DIRAC_MIN_BITRATE_6_TRANS_CHAN IVAS_256k +#define DIRAC_MIN_BITRATE_4_TRANS_CHAN IVAS_160k /* minimum bitrate for sending 4 transport channels (FOA) */ +#define DIRAC_MIN_BITRATE_2_TRANS_CHAN IVAS_48k /* minimum bitrate for sending 2 transport channels (Stereo) */ + +#define DIRAC_NUM_DIMS 3 /* number of directions to estimate (X,Y,Z) */ +#define DIRAC_MAX_NBANDS 12 /* Maximum number of frequency bands for the DirAC Side Parameter decoding */ +#define DIRAC_LOW_BANDRES_STEP 2 /* always combine two bands for low band resolution in the DirAC parameter coding */ +#define DIRAC_NO_COL_AVG_DIFF 32 /* Number of slots for averaging intensity vector for diffuseness computation */ +#define DIRAC_DIFFUSE_LEVELS 8 /* Size of the diffuseness alphabet (constant value) */ +#define DIRAC_DITH_SEED 29680 +#define DIRAC_MAX_BITS 512 /* Maximum number of bits for DirAC side information per frame */ +#define MAX_NUM_ENC_CLDFB_INSTANCES 8 /* Maximum Cldfb instances in DirAC encoder */ +#define DIRAC_NO_COL_AVG_DIFF_NS 40000000L +#define DIRAC_NO_FB_BANDS_MAX MDFT_FB_BANDS_240 +#define DELAY_DIRAC_ENC_CMP_NS_PARAM_ISM ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) /* == 12 ms */ + + +/* DirAC renderer setup */ +typedef enum +{ + DIRAC_SYNTHESIS_INVALID, + DIRAC_SYNTHESIS_PSD_LS, /* PSD renderer in loudspeakers domain */ + DIRAC_SYNTHESIS_GAIN_SHD, /* Gain renderer in Spherical Harmonic Domain*/ + DIRAC_SYNTHESIS_PSD_SHD, /* PSD renderer in Spherical Harmonic Domain*/ + DIRAC_SYNTHESIS_MONO, + DIRAC_SYNTHESIS_COV_MC_LS +} DIRAC_SYNTHESIS_CONFIG; + +/* DirAC renderer panning setup */ +typedef enum +{ + DIRAC_PANNING_INVALID, + DIRAC_PANNING_HOA3, /* HOA3 */ + DIRAC_PANNING_VBAP /* VBAP */ +} DIRAC_PANNING_CONFIG; + +#define DIRAC_DIFF_NUM_AMBI_COMP 4 +#define DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS 8 +#define DIRAC_GAIN_LIMIT 31.622776601683793f /* 30db gain limitiation */ +#define DIRAC_MAX_NUM_DECORR_FILTERS 22 +#define DIRAC_MAX_DECORR_FILTER_LEN 20 +#define DIRAC_DECORR_NUM_SPLIT_BANDS 3 +#define DIRAC_DECORR_FILTER_LEN_1 15 +#define DIRAC_DECORR_FILTER_LEN_2 6 +#define DIRAC_DECORR_FILTER_LEN_3 3 +#define DIRAC_ONSET_ALPHA 0.95f +#define DIRAC_ONSET_BETA 0.995f +#define DIRAC_ONSET_GAIN 4.0f + +#define DELAY_DIRAC_ENC_CMP_NS 9500000L /* Delay to be compensated on DirAC encoder */ +#define DELAY_DIRAC_SPAR_ENC_CMP_NS 500000L /* here we may set the 24 samples (at 48 kHz) additional delay to something else, leave as is for now*/ +#define DELAY_DIRAC_PARAM_DEC_SFR 2 /* Delay to be compensation for DirAC parameters in the decoder (subframes) */ + +#define DIRAC_SLOT_NS 1250000L /* time duration of a time slot, 1.25ms (==DELAY_RENERER_NS/MAX_PARAM_SPATIAL_SUBFRAMES) */ +#define DIRAC_SLOT_ENC_NS 5000000L + +typedef enum +{ + DIRAC_OPEN, /* initialize to default value */ + DIRAC_RECONFIGURE /* HOA3 */ +} DIRAC_CONFIG_FLAG; + + +/*----------------------------------------------------------------------------------* + * SPAR constants + *----------------------------------------------------------------------------------*/ + +#define SPAR_CONFIG_BW FB + +#define IVAS_SPAR_MAX_CH (2*IVAS_MAX_SBA_ORDER + 2) /* FOA + planar HOA */ + +#define IVAS_SPAR_P_LOWERTRI ((IVAS_SPAR_MAX_CH - 1) * (IVAS_SPAR_MAX_CH - 2)) >> 1 +#define IVAS_SPAR_MAX_C_COEFF (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * ( IVAS_SPAR_MAX_DMX_CHS - 1) + +#define IVAS_SPAR_HOA3_NP_CHS 8 /* number of higher order non-planar channels */ + +#define SPAR_NUM_CODING_STRAT_BITS ( 3 ) + +/* AGC constants */ +#define AGC_BITS_PER_CH 3 +#define AGC_EMAX 0 + +/* Common SPAR metadata constants */ +#define IVAS_ACTIVEW_DM_F_SCALE 0.5f +#define IVAS_ACTIVEW_DM_F_SCALE_DTX 0.25f +#define IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN 24000 + +#define MAX_QUANT_STRATS 3 +#define MAX_CODING_STRATS 3 +#define IVAS_NUM_PROB_MODELS 4 +#define IVAS_MAX_INPUT_LEN ( IVAS_MAX_NUM_BANDS * ( IVAS_SPAR_P_LOWERTRI ) ) +#define IVAS_MAX_QUANT_LEVELS 32 +#define BRATE_SPAR_Q_STRAT IVAS_256k + +#define SPAR_SID_BITS_TAR_PER_BAND 18 + +#ifndef FIX_SBA_CLEAN_UP_OPT +typedef enum +{ + WYXZ = 0, + WY = 0, + WX, + WZ, + WYiX, +} ivas_spar_foa_pmx_strings_t; +#else +typedef enum +{ + WYXZ = 0, + WY = 0, + WX, + WZ, + WYiX, +} ivas_spar_pmx_strings_t; +#endif + +#define NUM_MD_Q_COEFS_SET 4 + +#define IVAS_RED_BAND_FACT 2 + +typedef enum +{ + PRED_COEFF = 0, + DRCT_COEFF, + DECD_COEFF, + DECX_COEFF +} ivas_coeffs_type_t; + +#define IVAS_SPAR_BR_TABLE_LEN 18 + +/* TD decorr */ +enum +{ + IVAS_TD_DECORR_OUT_1CH = 1, + IVAS_TD_DECORR_OUT_2CH, + IVAS_TD_DECORR_OUT_3CH, + IVAS_TD_DECORR_OUT_4CH, + IVAS_TD_DECORR_OUT_5CH, + IVAS_TD_DECORR_OUT_6CH, + IVAS_TD_DECORR_OUT_7CH, + IVAS_TD_DECORR_OUT_8CH, + IVAS_TD_DECORR_OUT_9CH, + IVAS_TD_DECORR_OUT_10CH, + IVAS_TD_DECORR_OUT_11CH, + IVAS_TD_DECORR_OUT_12CH, + IVAS_TD_DECORR_OUT_13CH, + IVAS_TD_DECORR_OUT_14CH, + IVAS_TD_DECORR_OUT_15CH, + IVAS_TD_DECORR_OUT_16CH +}; + +#define IVAS_SPAR_MAX_DMX_CHS 4 +#define IVAS_MAX_DECORR_CHS IVAS_TD_DECORR_OUT_15CH +#define IVAS_MAX_DECORR_APD_SECTIONS 16 +#define IVAS_APD_2_SECT 2 +#define IVAS_APD_4_SECT 4 +#define IVAS_APD_8_SECT 8 +#define IVAS_APD_16_SECT 16 + +#define IVAS_DECORR_PARM_LOOKAHEAD_TAU 2e-3f +#define IVAS_DECORR_PARM_APD_TAU 20e-3f + +/* IVAS PCA */ +#define IVAS_PCA_NB_SUBR 20 /* 80 -> 0.25 ms, 40 -> 0.5 ms... */ +#define IVAS_PCA_COV_THRES 1e-9f +#define IVAS_PCA_QUAT_EPS 1e-7f +#define IVAS_PCA_QBITS 19 +#define IVAS_PCA_N1 91 +#define IVAS_PCA_N1_EQ ( (IVAS_PCA_N1-1)/2 ) +#define IVAS_PCA_BIT_LEN ( 1 + ( IVAS_PCA_QBITS - 1 + IVAS_PCA_QBITS ) ) +#define IVAS_PCA_INTERP 4 /* 4D (Quaternion) dimension */ +#define IVAS_PCA_N_SLOTS 40 //20 +#define IVAS_PCA_LEN_INTERP_Q ( IVAS_PCA_INTERP * IVAS_PCA_N_SLOTS ) +#define IVAS_PCA_DELAY_CMP 24 // 12 +#define IVAS_PCA_LEN_INTERP_EIG_DEC ( (IVAS_PCA_N_SLOTS+IVAS_PCA_DELAY_CMP)*16) +#define IVAS_PCA_THRES_MIN_DOT 0.8f +#define IVAS_PCA_THRES_MIN_DOT2 0.0f +#define IVAS_PCA_THRES_DIST_ALT 6.0f + +typedef enum +{ + PCA_MODE_ACTIVE = 0, + PCA_MODE_INACTIVE = 1 +} ivas_pca_bypass_mode; + +#ifdef FIX_SBA_CLEAN_UP_OPT +enum +{ + PRED_Q_1 = 0, + PRED_Q_7, + PRED_Q_15, + PRED_Q_21, + PRED_Q_31, + PRED_Q_7_ACTIVE_W, + TOTAL_PRED_QUANT_STRATS_HUFF = 5, + PRED_Q_15_ACTIVE_W, + PRED_Q_21_ACTIVE_W, + TOTAL_PRED_QUANT_STRATS_ARITH + }; + +enum +{ + DRCT_Q_1 = 0, + DRCT_Q_7, + DRCT_Q_9, + DRCT_Q_11, + TOTAL_DRCT_QUANT_STRATS + }; + +enum +{ + DECD_Q_1 = 0, + DECD_Q_3, + DECD_Q_5, + DECD_Q_7, + DECD_Q_9, + DECD_Q_11, + TOTAL_DECD_QUANT_STRATS + }; +#endif + +/*----------------------------------------------------------------------------------* + * MASA constants + *----------------------------------------------------------------------------------*/ + +#define MAX_NO_THETA 19 +#define NO_THETA16_MAX 122 /* number of theta values for 16 bits */ +#define NO_SPHERICAL_GRIDS 11 /* number of spherical grid structures */ + +#define MASA_FREQUENCY_BANDS 24 +#define MASA_MAXIMUM_CODING_SUBBANDS 24 +#define MASA_MAXIMUM_DIRECTIONS 2 +#define MASA_MAX_TRANSPORT_CHANNELS 2 +#define MASA_ENC_DELAY_SLOTS 7 +#define MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS 5 + +#define MASA_DELTA_AZI_DCT0 30 +#define MASA_DELTA_AZI_DCT 10 + +#define MASA_TRANSP_BITS 1 +#define MASA_HEADER_BITS 2 +#define MASA_SUBFRAME_BITS 1 +#define MASA_LOWBITRATE_MODE_BITS 1 +#define MASA_FACTOR_CV_COH 6 + +#define MASA_GR_ORD_EL 1 +#define MASA_GR_ORD_AZ 2 + +#define MASA_DIRECTION_MAX_BITS 11 +#define MASA_NO_INDEX 32767 +#define MASA_BITS_ER 3 +#define MASA_MIN_BITS_TF 4 +#define MASA_LIMIT_2D 2 +#define MASA_NO_CV_COH 8 +#define MASA_NO_CV_COH1 5 +#define MASA_MAX_NO_CV_SUR_COH 8 +#define MASA_NO_CB_SUR_COH 7 +#define MASA_MIN_BITS_SURR_COH 12 + +#define MASA_SUM_FREQ_RANGE_BINS 25 /* Constant for MASA transport signal type detection */ +#define MASA_HI_FREQ_START_BIN 14 /* Constant for MASA transport signal type detection */ +#define MASA_STEREO_INTERPOLATION_SLOTS 16 /* The number of slots to interpolate when changing MASA transport signal type */ +#define MASA_SUM_PROTO_START_BIN 7 /* Constant for Ambisonics rendering from MASA */ + +#define QMETADATA_MAXBIT_REQ_MASA 900 /* max bit-bit/direction for avoiding requantization in MASA path */ +#define QMETADATA_MAXBIT_REQ_SBA 400 /* max bit-bit/direction for avoiding requantization in SBA path */ +#define MASA_COH_LIMIT_2IDX 144 /* limit for sum of values across components for having two joint indexes */ +#define QMETADATA_MAX_NO_DIRECTIONS 2 +#define MASA_MAX_BITS 1300 /* max. bit-budget for MASA metadata */ +#define LIMIT_ER_ELEVATION_ENC 4 +#define LIMIT_ER_SIMPLE_ENC 6 +#define LIMIT_USE_COMMON 3 + +#define MASA_COHERENCE_TOLERANCE 0.1f +#define MASA_COHERENCE_THRESHOLD 0.1f +#define MASA_RATIO_TOLERANCE 0.1f +#define MASA_RATIO_THRESHOLD 0.1f +#define MASA_ANGLE_TOLERANCE 0.5f +#define MASA_LIMIT_NO_BANDS_SUR_COH 8 +#define MINIMUM_BIT_BUDGET_NORMAL_META 100 +#define DIFF_DFRATIO_2BIT_LIMIT_IDX 3 +#define DIFF_DFRATIO_1BIT_LIMIT_IDX 6 +#define DIFF_EC_HUFF_BAND_LIMIT 8 +#define DIFF_EC_HUFF_GR0_LIMIT 8 +#define VAR_AZI_THRESH 25 +#define MASA_LIMIT_IDX_AVG_AZI 4 + +#define MASA_NO_POINTS_EQUATOR 430 +#define MASA_NO_CIRCLES 121 +#define MASA_ASIN_OFFSET 0.0064471690266724975f +#define MASA_NTOT2_FAC 32768.00566947353f +#define MASA_ANGLE_AT_EQUATOR 0.012894427382667f +#define MASA_ANGLE_AT_EQUATOR_DEG 0.738796268264740f +#define MASA_INV_ANGLE_AT_EQUATOR_DEG 1.353553128183453f +#define MASA_STEREO_MIN_BITRATE IVAS_24k4 + +#define MASA_BIT_REDUCT_PARAM 10 + +typedef enum +{ + MASA_STEREO_NOT_DEFINED, + MASA_STEREO_SPACED_MICS, + MASA_STEREO_DOWNMIX +} MASA_TRANSPORT_SIGNAL_TYPE; + + +/*----------------------------------------------------------------------------------* + * Multichannel format + *----------------------------------------------------------------------------------*/ + +#define MC_LS_SETUP_BITS 3 /* number of bits for writing the MC LS configuration */ +#define LS_SETUP_CONVERSION_NUM_MAPPINGS 35 /* number of mappings for LS setup conversion */ + +typedef enum +{ + MC_MODE_NONE, + MC_MODE_MCT, + MC_MODE_PARAMMC, + MC_MODE_MCMASA +} MC_MODE; + +typedef enum +{ + MC_LS_SETUP_5_1, + MC_LS_SETUP_7_1, + MC_LS_SETUP_5_1_2, + MC_LS_SETUP_5_1_4, + MC_LS_SETUP_7_1_4, + MC_LS_SETUP_INVALID +} MC_LS_SETUP; + + +/*----------------------------------------------------------------------------------* + * McMASA constants + *----------------------------------------------------------------------------------*/ + +#define MCMASA_SEPARATE_BRATE IVAS_64k /* minimum bitrate from which separated channel coding is supported */ + +#define MCMASA_MAX_ANA_CHANS 11 /* Maximum number of channels currently used in analysis of multichannel formats */ +#define MCMASA_MONOBITRATIO 0.3f +#define MCMASA_MONOBITRATIO_64k 0.25f +#define MC_MASA_THR_ELEVATION 40 + +#define MCMASA_LFE_QLOW -6.5f +#define MCMASA_LFE_DELTA 1.0f +#define MCMASA_LFE_1BIT_THRES 0.03f +#define MCMASA_LFE_ALPHA 0.67f +#define MCMASA_LFE_BETA 0.09f +#define MCMASA_LFE_THETA 1.3f +#define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */ + +#define NUM_ELEVATED_SPEAKERS 4 + +#define MCMASA_MIN_SPEAKERS_SEPARATE_CENTER 4 + +/*----------------------------------------------------------------------------------* + * MCT constants + *----------------------------------------------------------------------------------*/ + +#define LFE_CHANNEL 3 + +#define MIN_LFE_NRG 0.5f +#define MCT_MAX_CHANNELS MAX_TRANSPORT_CHANNELS +#define MCT_MAX_BLOCKS ( MCT_MAX_CHANNELS / CPE_CHANNELS ) /* max. number of channel pairs (MCT_MAX_CHANNELS/2) within MCT*/ + +#define MAX_NUM_DATA max( MCT_MAX_CHANNELS, 4 ) + +#define NBBITS_MCT_RATIO 4 +#define BITRATE_MCT_RATIO_RANGE ( 1 << NBBITS_MCT_RATIO ) /* Range of the coded bitrate distribution ratio */ + +#define LFE_BITS 180 + +#define MCT_LFE_MAX_LINE 24 +#define MCT_NUM_BLOCK_DATA_BITS 4 + +typedef enum +{ + MCT_CHAN_MODE_REGULAR, + MCT_CHAN_MODE_LFE, + MCT_CHAN_MODE_IGNORE +} MCT_CHAN_MODE; + + +/*----------------------------------------------------------------------------------* + * Parametric MC Constants + *----------------------------------------------------------------------------------*/ + +typedef enum +{ + PARAM_MC_SYNTH_DIRECT, /* synthesis to the transport format */ + PARAM_MC_SYNTH_LS_CONV_COV, /* loudspeaker format conversion in the covariance domain */ + PARAM_MC_SYNTH_LS_CONV_CLDFB, /* loudspeaker format conversion in the CLDFB domain */ + PARAM_MC_SYNTH_MONO_STEREO /* synthesis to mono or stereo */ +} PARAM_MC_SYNTHESIS_CONF; + +#define PARAM_MC_REG_SX (0.2f) /* Regularization factor for mixing matrix calculation */ +#define PARAM_MC_REG_GHAT (0.001f) /* Regularization factor for mixing matrix calculation */ +#define PARAM_MC_MAX_PARAMETER_BANDS 20 /* Maximum number of parameter bands */ +#define PARAM_MC_MAX_PARAMETER_BANDS_RES 14 /* Maximum number of parameter bands with decorrelation */ +#define PARAM_MC_MAX_NSLOTS 16 /* Maximum number of CLDFB slots in a frame */ +#define PARAM_MC_MAX_NSLOTS_IN_SUBFRAME 4 /* Maximum number of CLDFB slots in a subframe */ +#define PARAM_MC_NSUBFRAMES_DEC 4 /* Number of subframes for the synthesis in the decoder */ +#define PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND 30 /* Maximum number of CLDFB frequency bands within a parameter band */ +#define PARAM_MC_PARAMETER_FRAMES 2 /* Number of frames a parameter set for a parameter band is used*/ +#define PARAM_MC_ICC_ERROR_BIAS_FAC (1.15f) /* factor for favouring past ICC maps in the adaptive ICC map decision */ +#define PARAM_MC_TRANSIENT_BAND_STEP 2 /* Number of parameter bands combined in case of a transient frame*/ +#define PARAM_MC_MAX_DECORR_CLDFB_BANDS 20 /* Maximum number of CLDFB bands with decorrelation */ +#define PARAM_MC_MAX_TRANSPORT_CHANS 4 /* Number of down mix channels */ +#define PARAM_MC_MAX_ILD_REF_CHANNELS 2 /* Maximum number of reference channels for a coded ILD */ +#define PARAM_MC_NUM_CONFIGS 15 /* Number of available Parametric MC configurations */ +#define PARAM_MC_MAX_BAND_LFE 1 /* Number of parameter bands for LFE coding */ +#define PARAM_MC_SZ_ICC_MAP 11 /* Maximum number of transmitted ICCs per parameter band */ +#define PARAM_MC_SZ_ILD_MAP 12 /* Maximum number of transmitted channel energies per band*/ +#define PARAM_MC_MAX_VAL_MAP_SIZE 12 /* Maximum number of transmitted parameters per band */ +#define PARAM_MC_RANGE_CODER_TOT_SHIFT 16 /* resolution of the range coder frequency tables */ +#define PARAM_MC_SZ_ICC_QUANTIZER 8 /* Length of the ICC quantizer for Parametric MC */ +#define PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT 3 /* Number of bits for ICC uniform coding */ +#define PARAM_MC_SZ_ILD_QUANTIZER_4BITS 16 /* Length of the ILD quantizer for Parametric MC */ +#define PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT 4 /* Number of bits for ILD uniform coding */ +#define PARAM_MC_DEFAULT_MIN_ILD (-92.0f) /* Default relative channel level for untransmitted channel energies */ +#define PARAM_MC_MAX_BITS 1024 /* Maximum number of bits for the Parametric MC metadata */ +#define PARAM_MC_MAX_BAND_ABS_COV_ENC 10 +#define PARAM_MC_MAX_PARAM_BAND_ABS_COV_ENC 10 +#define PARAM_MC_MAX_BAND_ABS_COV_DEC 10 +#define PARAM_MC_ENER_LIMIT_INTRAFRAME (1.5f) +#define PARAM_MC_ENER_LIMIT_INTERFRAME (2.0f) +#define PARAM_MC_LFE_ON_THRESH (8000.0f) +#define PARAM_MC_BAND_TO_MDCT_BAND_RATIO 16 /* Ratio of resolution of CLDFB Bands to MDCT Bands */ +#define PARAM_MC_SLOT_ENC_NS 2500000L +#define PARAM_MC_MDFT_NO_SLOTS 8 + +/*----------------------------------------------------------------------------------* + * LFE Coding Constants + *----------------------------------------------------------------------------------*/ + +#define IVAS_LFE_ID_BITS 1 + +typedef enum +{ + IVAS_FILTER_STAGE_0, + IVAS_FILTER_STAGE_1, + IVAS_FILTER_MAX_STAGES /* this becomes array len while declaring the array */ +} LFE_FILTERS_STAGES; + +/* IIR filter orders */ +typedef enum +{ + IVAS_FILTER_ORDER_1 = 1, + IVAS_FILTER_ORDER_2 = 2, + IVAS_FILTER_ORDER_4 = 4, +} ivas_filter_order; + +#define IVAS_BIQUAD_FILT_LEN 3 +#define IVAS_LFE_FADE_LEN_48K 384 +#define IVAS_LFE_FADE_LEN_32K 256 +#define IVAS_LFE_FADE_LEN_16K 128 +#define IVAS_LFE_FADE_LEN_8K 64 +#define IVAS_LFE_SHIFTS_PER_DOUBLE 4 +#define IVAS_LFE_NUM_COEFFS_IN_SUBGRP 2 +#define IVAS_LFE_MAX_NUM_DCT_PASS_BINS 8 +#define IVAS_LFE_MAX_NUM_DCT_COEFFS (IVAS_LFE_MAX_NUM_DCT_PASS_BINS * IVAS_LFE_NUM_COEFFS_IN_SUBGRP) +#ifdef SBA_CLEANING +#define IVAS_LFE_FADE_NS 8000000L /* 8.0 ms */ +#else +#define IVAS_LFE_FADE_LEN_SEC_FLOAT ((float)0.008) +#endif +#define IVAS_MAX_NUM_QUANT_STRATS 2 +#define IVAS_MAX_NUM_DCT_COEF_GROUPS 4 +#define IVAS_LFE_SHIFT_BITS 5 +#define IVAS_LFE_BITRATE_5000 5000 +#define IVAS_LFE_ABS_SUM_FLT_THR (0.000001f) +#define IVAS_ZERO_PAD_LEN_MULT_FAC (0.5f) + +/* LFE PLC */ +#define LFE_PLC_BUFLEN 240 +#define LFE_PLC_FS 1600 +#define L_FRAME_1k6 ( 20 * LFE_PLC_FS / 1000 ) +#define LFE_PLC_LENANA LFE_PLC_BUFLEN +#define LFE_PLC_FDEL 300 + + +/*----------------------------------------------------------------------------------* + * Amplitude Panning (EFAP, VBAP) constants + *----------------------------------------------------------------------------------*/ + +#define PANNING_AZI_RESOLUTION 2 +#define PANNING_ELE_RESOLUTION 5 + +#define EFAP_MAX_CHAN_NUM 5 /* Maximum number of channels that constitute a polygon, 4 or 5 */ +#define EFAP_MAX_POLY_SET 70 /* Upper bound on number of polygons; with a Speaker setup of 26.0, we obtain 54 polygons/triangles in the matlab implementation. */ + +#define EFAP_MODE_EFAP 0 /* EFAP Panning */ +#define EFAP_MODE_EFIP 1 /* EFIP Panning */ + +typedef enum +{ + EFAP_DMX_NONE, + EFAP_DMX_AMPLITUDE, + EFAP_DMX_INTENSITY +} EFAP_VTX_DMX_TYPE; + +#define VBAP_NUM_SEARCH_SECTORS 4 + +/*----------------------------------------------------------------------------------* + * Binaural Rendering Constants + *----------------------------------------------------------------------------------*/ + +#define BINAURAL_MAXBANDS 60 /* Max number of bands */ +#define BINAURAL_CONVBANDS 50 /* Bands upto which convolution is performed */ +#define BINAURAL_NTAPS_MAX 96 + +#define HRTF_SH_ORDER 3 +#define HRTF_SH_CHANNELS 16 +#define HRTF_NUM_BINS 60 +#define REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */ +#define GAIN_LFE 1.88364911f /* Gain applied to LFE during renderering */ +#define LOW_BIT_RATE_BINAURAL_EQ_BINS 17 /* Number of bins in an EQ applied at low bit rates in binauralization */ +#define LOW_BIT_RATE_BINAURAL_EQ_OFFSET 14 /* Offset of bins where the low-bit-rate EQ starts*/ + +#define BINAURAL_COHERENCE_DIFFERENCE_BINS 9 /* Number of bins for direction-dependent diffuse-field binaural coherence */ + + +/*----------------------------------------------------------------------------------* + * TD Binaural Object renderer + *----------------------------------------------------------------------------------*/ + +#define MAX_NUM_TDREND_CHANNELS 11 /* max. number of channels in TD renderer (objects or loudspeaker channels) */ + +#define SFX_SPAT_BIN_MAX_NO_OF_OUTPUT_SAMPLES 288 /* 288 = 6 msec @ 48 kHz. */ +#define HRTF_MODEL_N_SECTIONS 3 /* No. sections used in approximate evaluation of model */ +#define HRTF_MODEL_BSPLINE_NUM_COEFFS 4 /* No. BSpline coefficients, including zeroth order e.g. cubic -> 4 */ +#define HRTF_MODEL_BSPLINE_NUM_COEFFS_SQ 16 /* Square of HRTF_MODEL_BSPLINE_NUM_COEFFS */ +#define SFX_SPAT_BIN_MAX_FILTER_LENGTH 256 + +#define SPAT_BIN_MAX_INPUT_CHANNELS 1 /* Max number of input channels per source/object. Mono for now, but stereo objects may be considered. */ + +#define BINAURAL_TD_LATENCY_S 0.00675f /* Binaural TD renderer latency in second == 324 samples in between 333 and 315 */ + +/* ----- Enums - TD Renderer ----- */ + +typedef enum +{ + TDREND_DIST_ATTEN_MODEL_INV_DIST, + TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED +} TDREND_DistAttenModel_t; + +typedef enum +{ + TDREND_POSTYPE_ABSOLUTE, /* The source position is in absolute coordinates */ + TDREND_POSTYPE_RELATIVE_TO_LISTENER /* The source position is relative to the listener */ +} TDREND_PosType_t; + +typedef enum +{ + TDREND_PLAYSTATUS_INITIAL, + TDREND_PLAYSTATUS_PLAYING +} TDREND_PlayStatus_t; + +typedef enum +{ + TDREND_DeallocIndex_None, + TDREND_DeallocIndex_Signal, + TDREND_DeallocIndex_Source +} TDREND_DeallocFnIndex; + +typedef enum +{ + TDREND_HRFILT_Method_BSplineModel +#ifdef TDREND_HRTF_TABLE_METHODS + , + TDREND_HRFILT_Method_Table_F, + TDREND_HRFILT_Method_Table_S +#endif +} TDREND_HRFILT_Method_t; + +typedef enum +{ + SFX_ON, + SFX_TRANSIENT, + SFX_OFF +} SFX_OpMode_t; + + +/*----------------------------------------------------------------------------------* + * Crend constants + *----------------------------------------------------------------------------------*/ + +#define IVAS_REV_MAX_NR_BRANCHES 8 /* setup is for maximum */ + +#define IVAS_REV_MAX_IIR_FILTER_LENGTH 4 /* maximum nr of taps - MUST BE EVEN! */ + +#define RV_FILTER_MAX_FFT_SIZE ( 512 ) +#define RV_FILTER_MAX_HISTORY ( 512 - 160 ) /* for longest history */ + +#define RV_LENGTH_NR_FC ( RV_FILTER_MAX_FFT_SIZE / 2 ) + 1 + + +/* Orientation tracking types */ +#define IVAS_ORIENT_TRK_REF 0 +#define IVAS_ORIENT_TRK_AVG 1 + +typedef enum +{ + OTR_TRACKING_NONE = IVAS_ORIENT_TRK_REF-1, /* track orientation relative to external reference orientation (default: yaw=pitch=roll=0) */ + OTR_TRACKING_REF_ORIENT = IVAS_ORIENT_TRK_REF, /* track orientation relative to external reference orientation (default: yaw=pitch=roll=0) */ + OTR_TRACKING_AVG_ORIENT = IVAS_ORIENT_TRK_AVG /* track orientation relative to average orientation */ +} OTR_TRACKING_T; + + + +/*----------------------------------------------------------------------------------* + * Reverberator constants + *----------------------------------------------------------------------------------*/ + +#define IVAS_REVERB_DEFAULT_N_BANDS 31 +#define IVAS_REVERB_DEFAULT_PRE_DELAY 0.016f +#define IVAS_REVERB_DEFAULT_INPUT_DELAY 0.1f + + +/*----------------------------------------------------------------------------------* + * FB mixer constants + *----------------------------------------------------------------------------------*/ + +#define IVAS_ONE_BY_960 0.001041666666666666f +#define IVAS_ONE_BY_640 0.0015625f +#define IVAS_ONE_BY_320 0.003125f +#define IVAS_ONE_BY_240 0.004166666666666667f +#define IVAS_ONE_BY_160 0.00625f +#define IVAS_ONE_BY_80 0.0125f + +#define IVAS_960_PT_LEN 960 +#define IVAS_640_PT_LEN 640 +#define IVAS_480_PT_LEN 480 +#define IVAS_320_PT_LEN 320 +#define IVAS_240_PT_LEN 240 +#define IVAS_160_PT_LEN 160 +#define IVAS_80_PT_LEN 80 +#define IVAS_40_PT_LEN 40 + +#define IVAS_NUM_SUPPORTED_FS 3 + +/* FB windows ovlp */ +#define IVAS_FB_4MS_48K_SAMP 192 +#define IVAS_FB_1MS_48K_SAMP 48 +#define IVAS_FB_4MS_32K_SAMP 128 +#define IVAS_FB_1MS_32K_SAMP 32 +#define IVAS_FB_4MS_16K_SAMP 64 +#define IVAS_FB_1MS_16K_SAMP 16 + +#define IVAS_MAX_FB_MIXER_OUT_CH IVAS_SPAR_MAX_CH +#define IVAS_MAX_SPAR_FB_MIXER_IN_CH IVAS_SPAR_MAX_CH +#define IVAS_MAX_FB_MIXER_IN_CH MAX_CICP_CHANNELS + +#define MAX_NUM_BANDS_DIFF_NON48K 3 + +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0 ( 0 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1 ( 0 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2 ( 0 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3 ( 0 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4 ( 0 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5 ( 9 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6 ( 7 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7 ( 0 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8 ( 0 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9 ( 49 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10 ( 172 ) +#define IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11 ( 377 ) + +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_0 ( 179 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_1 ( 160 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_2 ( 215 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_3 ( 200 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_4 ( 186 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_5 ( 196 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_6 ( 230 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_7 ( 351 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_8 ( 456 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_9 ( 617 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_10 ( 892 ) +#define IVAS_FB_12_1MS_48K_END_BINS_BAND_11 ( 960 ) + +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_0 ( 0 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_1 ( 0 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_2 ( 0 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_3 ( 0 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_4 ( 0 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_5 ( 9 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_6 ( 7 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_7 ( 0 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_8 ( 0 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_9 ( 49 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_10 ( 172 ) +#define IVAS_FB_12_1MS_32K_START_OFFSET_BAND_11 ( 377 ) + +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_0 ( 179 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_1 ( 160 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_2 ( 215 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_3 ( 200 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_4 ( 186 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_5 ( 196 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_6 ( 230 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_7 ( 351 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_8 ( 456 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_9 ( 617 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_10 ( 640 ) +#define IVAS_FB_12_1MS_32K_END_BINS_BAND_11 ( 640 ) + +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_0 ( 0 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_1 ( 0 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_2 ( 0 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_3 ( 0 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_4 ( 0 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_5 ( 9 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_6 ( 7 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_7 ( 0 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_8 ( 0 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_9 ( 49 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_10 ( 172 ) +#define IVAS_FB_12_1MS_16K_START_OFFSET_BAND_11 ( 320 ) + +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_0 ( 179 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_1 ( 160 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_2 ( 215 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_3 ( 200 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_4 ( 186 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_5 ( 196 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_6 ( 230 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_7 ( 320 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_8 ( 320 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_9 ( 320 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_10 ( 320 ) +#define IVAS_FB_12_1MS_16K_END_BINS_BAND_11 ( 320 ) + +#define IVAS_FB_BANDS_12 12 +#define IVAS_FB_BANDS_20 20 +#define IVAS_MAX_NUM_BANDS IVAS_FB_BANDS_12 +#define IVAS_MAX_NUM_FB_BANDS IVAS_FB_BANDS_20 +#define IVAS_FB_12_1MS_LEN ( IVAS_FB_12_1MS_48K_END_BINS_BAND_0 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_1 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_2 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_3 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_4 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_5 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_6 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_7 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_8 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_9 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_10 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10 ) + ( IVAS_FB_12_1MS_48K_END_BINS_BAND_11 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11 ) +#define IVAS_16K_12BANDS_ACTIVE_BANDS 10 + +#define SPAR_DIRAC_SPLIT_START_BAND 8 +#define SPAR_DTX_BANDS 2 +#define DIRAC_DTX_BANDS 2 +#define SPAR_DIRAC_DTX_BANDS ( SPAR_DTX_BANDS + DIRAC_DTX_BANDS ) +#define CLDFB_PAR_WEIGHT_START_BAND 7 + +#endif +/* clang-format on */ +/* IVAS_CNST_H */ diff --git a/lib_com/ivas_error.h b/lib_com/ivas_error.h new file mode 100644 index 0000000..58c45ee --- /dev/null +++ b/lib_com/ivas_error.h @@ -0,0 +1,167 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 + ====================================================================================*/ + +/* options.h needed for debugging/development features + * It should be stripped for delivery along with debugging switches */ +#include "options.h" + +#ifndef IVAS_ERROR_H +#define IVAS_ERROR_H + +typedef enum +{ + /*----------------------------------------* + * no error * + *----------------------------------------*/ + IVAS_ERR_OK = 0x0000, + + /*----------------------------------------* + * API errors * + *----------------------------------------*/ + IVAS_ERR_INVALID_BANDWIDTH = 0x1000, + IVAS_ERR_INVALID_DTX_UPDATE_RATE, + IVAS_ERR_INVALID_SAMPLING_RATE, + IVAS_ERR_NOT_CONFIGURED, + IVAS_ERR_INVALID_STEREO_MODE, + IVAS_ERR_INVALID_CICP_INDEX, + IVAS_ERR_INVALID_BITRATE, + IVAS_ERR_INVALID_MASA_CONFIG, + IVAS_ERR_TOO_MANY_OBJECT_INPUTS, + IVAS_ERR_INDEX_OUT_OF_BOUNDS, + IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, + IVAS_ERR_INVALID_FEC_CONFIG, + IVAS_ERR_INVALID_FEC_OFFSET, + IVAS_ERR_INVALID_INPUT_BUFFER_SIZE, + IVAS_ERR_DTX_NOT_SUPPORTED, + IVAS_ERR_UNEXPECTED_NULL_POINTER, + IVAS_ERR_METADATA_NOT_EXPECTED, + IVAS_ERR_INVALID_SPAR_CONFIG, + IVAS_ERR_WRONG_PARAMS, + IVAS_ERR_INIT_ERROR, + IVAS_ERR_DECODER_ERROR, + IVAS_ERR_WRONG_MODE, + IVAS_ERR_INVALID_OUTPUT_FORMAT, + IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED, + IVAS_ERR_INVALID_HRTF, + IVAS_ERR_INVALID_INPUT_FORMAT, + IVAS_ERR_INVALID_INDEX, + IVAS_ERR_NOT_SUPPORTED_OPTION, + IVAS_ERR_NOT_IMPLEMENTED, +#ifdef DEBUGGING + IVAS_ERR_INVALID_FORCE_MODE, +#endif + IVAS_ERR_FILE_READER_TIMESTAMP_MISMATCH, + IVAS_ERR_ISM_FILE_READER_INVALID_METADATA_FORMAT, + IVAS_ERR_INVALID_MASA_FORMAT_METADATA_FILE, + + /*----------------------------------------* + * input data errors * + *----------------------------------------*/ + IVAS_ERR_INVALID_BITSTREAM = 0x2000, + + /*----------------------------------------* + * hardware errors * + *----------------------------------------*/ + IVAS_ERR_FAILED_ALLOC = 0x3000, + + /*----------------------------------------* + * internal errors * + *----------------------------------------*/ + IVAS_ERR_INTERNAL = 0x4000, + IVAS_ERR_INTERNAL_FATAL, + + /*----------------------------------------* + * file I/O errors (lib_util only) * + *----------------------------------------*/ + IVAS_ERR_FAILED_FILE_OPEN = 0x5000, + IVAS_ERR_FAILED_FILE_WRITE, + IVAS_ERR_FAILED_FILE_READ, + IVAS_ERR_FAILED_FILE_PARSE, + IVAS_ERR_END_OF_FILE, + IVAS_ERR_BITSTREAM_WRITER_INVALID_FORMAT, + IVAS_ERR_BITSTREAM_READER_INVALID_DATA, + IVAS_ERR_BITSTREAM_READER_INVALID_FORMAT, + + /*----------------------------------------* + * unknown error * + *----------------------------------------*/ + IVAS_ERR_UNKNOWN = 0xF000, /* fallback error code */ + +} ivas_error; + + +static inline const char *ivas_error_to_string( ivas_error error_code ) +{ + /* For error categories that are likely to still have many changes to + * specific error codes, return one string per category */ + if ( ( error_code & 0xF000 ) == 0x1000 ) + { + return "API error"; + } + if ( ( error_code & 0xF000 ) == 0x2000 ) + { + return "data error"; + } + + /* For categories that are unlikely to change, use more specific strings */ + switch ( error_code ) + { + case IVAS_ERR_OK: + return "No error"; + case IVAS_ERR_FAILED_ALLOC: + return "Failed allocation error"; + case IVAS_ERR_INTERNAL: + return "Internal error"; + case IVAS_ERR_INTERNAL_FATAL: + return "Internal fatal error"; + case IVAS_ERR_FAILED_FILE_OPEN: + return "File open error"; + case IVAS_ERR_FAILED_FILE_WRITE: + return "File write error"; + case IVAS_ERR_FAILED_FILE_READ: + return "File read error"; + case IVAS_ERR_FAILED_FILE_PARSE: + return "Parse error"; + case IVAS_ERR_END_OF_FILE: + return "End of file"; + default: + break; + } + + return "Unknown error"; +} + +#endif /* IVAS_ERROR_H */ diff --git a/lib_com/ivas_error_utils.h b/lib_com/ivas_error_utils.h new file mode 100644 index 0000000..412bd07 --- /dev/null +++ b/lib_com/ivas_error_utils.h @@ -0,0 +1,96 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include "options.h" + +#include +#include +#include + +#include "ivas_error.h" + +#ifdef DEBUGGING +#include +#endif + +#ifndef IVAS_ERROR_UTILS_H +#define IVAS_ERROR_UTILS_H + +/* + * Usage: + * + * IVAS_ERROR( error_code, decription_fmt, ... ); + * + * where: + * - error_code is of type enum ivas_error + * - decription_fmt is a description string with printf-like formatting + * - ... are (optional) printf-like arguments to place in the description format string + * + * Examples: + * + * IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for XXX" ); + * + * IVAS_ERROR( IVAS_ERR_INTERNAL, "Unexpected value %f in frame %d", var, frame ); + * + * Note: Contrary to printf, this macro is not able to verify at build time that the + * placeholders (e.g. "%f") in the format string match the types of provided arguments. + * If unexpected values are printed or the macro causes a crash, double check that the + * format specifiers are correct. + */ +#ifdef DEBUGGING +#define IVAS_ERROR( error_code, ... ) ivas_error_wrapper( error_code, __func__, __FILE__, __LINE__, __VA_ARGS__ ) +#else +#define IVAS_ERROR( error_code, ... ) ivas_error_wrapper( error_code ) +#endif + +#ifdef DEBUGGING +static inline ivas_error ivas_error_wrapper( const ivas_error error_code, const char *function, const char *file, int32_t line, const char *description, ... ) +{ + fprintf( stderr, "\n%s: ", ivas_error_to_string( error_code ) ); + + va_list args; + va_start( args, description ); + vfprintf( stderr, description, args ); + va_end( args ); + + fprintf( stderr, "\n\nIn function: %s(), %s:%d\n\n", function, file, line ); + // assert( 0 ); + return error_code; +} +#else +static inline ivas_error ivas_error_wrapper( const ivas_error error_code ) +{ + return error_code; +} +#endif + +#endif /* IVAS_ERROR_UTILS_H */ diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c new file mode 100644 index 0000000..f2c7da8 --- /dev/null +++ b/lib_com/ivas_rom_com.c @@ -0,0 +1,10568 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include "options.h" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include +#include "cnst_fx.h" +#include "ivas_cnst.h" +#include "ivas_rom_com.h" +#include "wmops.h" + +/* clang-format off */ + +/*----------------------------------------------------------------------------------* + * Table of IVAS bitrates + *----------------------------------------------------------------------------------*/ + +const int32_t ivas_brate_tbl[SIZE_IVAS_BRATE_TBL] = +{ + FRAME_NO_DATA, IVAS_SID_4k4, IVAS_SID_5k, + IVAS_13k2, IVAS_16k4, IVAS_24k4, IVAS_32k, IVAS_48k, + IVAS_64k, IVAS_80k, IVAS_96k, IVAS_128k, IVAS_160k, + IVAS_192k, IVAS_256k, IVAS_384k, IVAS_512k +}; + +const int16_t fast_FCB_bits_2sfr[] = { 8, 14, 18, 20, 24, 128/*stop value*/ }; + +const int16_t fast_FCB_rates_2sfr[] = {/*16*50,*/ (8 + 14) * 50, 28 * 50, 32 * 50, 34 * 50, 36 * 50, 38 * 50, 40 * 50, 42 * 50, 44 * 50, 48 * 50 }; + +#if 0 +/*------------------------------------------------------------------------- + * DFT Stereo ROM tables + *------------------------------------------------------------------------*/ + +/*4xERB scale: max of 14 bands*/ +const int16_t dft_band_limits_erb4[STEREO_DFT_ERB4_BANDS] = +{ + 1, 3, 5, 10, 18, 26, 41, 56, 84, 132, 214, 342, 470, 601 +}; + +/*8xERB scale: max of 8 bands*/ +const int16_t dft_band_limits_erb8[STEREO_DFT_ERB8_BANDS] = +{ + 1, 5, 18, 41, 84, 214, 470, 601 +}; + +const float dft_res_cod_alpha[STEREO_DFT_BAND_MAX] = +{ + .8f, .8f, .5f, .5f, .3f, .3f, .2f, .2f +}; + +const int16_t dft_band_ipd[3][4] = +{ + {0,8,10,13}, + {0,5,6,8}, + {0,2,3,4} +}; + +const int16_t dft_band_res_cod[3][4] = +{ + {0,8,10,11}, + {0,5,6,7}, + {0,5,6,7} +}; + +const float dft_res_gains_q[][2] = +{ + /* quantization points for joint quantization of prediction gain and residual energy */ + + /* column 1 (|ILD| = 0): */ + { 0.000000f, 0.000000f }, + { 0.000000f, 0.116982f }, + { 0.000000f, 0.226991f }, + { 0.000000f, 0.340693f }, + { 0.000000f, 0.464549f }, + { 0.000000f, 0.605079f }, + { 0.000000f, 0.776250f }, + { 0.000000f, 1.000000f }, + + /* column 2 (|ILD| = 2): */ + { 0.114623f, 0.000000f }, + { 0.116171f, 0.115424f }, + { 0.120448f, 0.223857f }, + { 0.127733f, 0.335704f }, + { 0.138966f, 0.457149f }, + { 0.155840f, 0.594270f }, + { 0.182248f, 0.760034f }, + { 0.226274f, 0.974064f }, + + /* column 3 (|ILD| = 4): */ + { 0.226274f, 0.000000f }, + { 0.229210f, 0.110915f }, + { 0.237306f, 0.214802f }, + { 0.251046f, 0.321340f }, + { 0.272098f, 0.435947f }, + { 0.303429f, 0.563535f }, + { 0.351766f, 0.714464f }, + { 0.430506f, 0.902588f }, + + /* column 4 (|ILD| = 6): */ + { 0.332279f, 0.000000f }, + { 0.336318f, 0.103909f }, + { 0.347423f, 0.200786f }, + { 0.366155f, 0.299242f }, + { 0.394585f, 0.403641f }, + { 0.436296f, 0.517359f }, + { 0.499282f, 0.647470f }, + { 0.598480f, 0.801138f }, + + /* column 5 (|ILD| = 8): */ + { 0.430506f, 0.000000f }, + { 0.435293f, 0.095060f }, + { 0.448405f, 0.183172f }, + { 0.470357f, 0.271705f }, + { 0.503282f, 0.363897f }, + { 0.550751f, 0.461614f }, + { 0.620606f, 0.568856f }, + { 0.726386f, 0.687287f }, + + /* column 6 (|ILD| = 10): */ + { 0.519494f, 0.000000f }, + { 0.524665f, 0.085097f }, + { 0.538769f, 0.163459f }, + { 0.562182f, 0.241193f }, + { 0.596843f, 0.320512f }, + { 0.645875f, 0.402058f }, + { 0.716076f, 0.487487f }, + { 0.818182f, 0.574960f }, + + /* column 7 (|ILD| = 13): */ + { 0.634158f, 0.000000f }, + { 0.639318f, 0.069554f }, + { 0.653296f, 0.132950f }, + { 0.676201f, 0.194597f }, + { 0.709442f, 0.255549f }, + { 0.755149f, 0.315316f }, + { 0.818046f, 0.373555f }, + { 0.904547f, 0.426375f }, + + /* column 8 (|ILD| = 16): */ + { 0.726386f, 0.000000f }, + { 0.731048f, 0.054862f }, + { 0.743597f, 0.104384f }, + { 0.763914f, 0.151643f }, + { 0.792863f, 0.197003f }, + { 0.831670f, 0.239542f }, + { 0.883261f, 0.278217f }, + { 0.950993f, 0.309212f }, + + /* column 9 (|ILD| = 19): */ + { 0.798235f, 0.000000f }, + { 0.802164f, 0.042077f }, + { 0.812683f, 0.079739f }, + { 0.829536f, 0.115098f }, + { 0.853180f, 0.148173f }, + { 0.884212f, 0.178009f }, + { 0.924333f, 0.203506f }, + { 0.975135f, 0.221614f }, + + /* column 10 (|ILD| = 22): */ + { 0.852825f, 0.000000f }, + { 0.855976f, 0.031585f }, + { 0.864374f, 0.059662f }, + { 0.877717f, 0.085671f }, + { 0.896203f, 0.109492f }, + { 0.920064f, 0.130302f }, + { 0.950256f, 0.147176f }, + { 0.987460f, 0.157870f }, + + /* column 11 (|ILD| = 25): */ + { 0.893520f, 0.000000f }, + { 0.895958f, 0.023331f }, + { 0.902435f, 0.043958f }, + { 0.912657f, 0.062866f }, + { 0.926684f, 0.079898f }, + { 0.944559f, 0.094403f }, + { 0.966814f, 0.105673f }, + { 0.993695f, 0.112114f }, + + /* column 12 (|ILD| = 30): */ + { 0.938693f, 0.000000f }, + { 0.940202f, 0.013738f }, + { 0.944192f, 0.025807f }, + { 0.950441f, 0.036736f }, + { 0.958923f, 0.046392f }, + { 0.969577f, 0.054375f }, + { 0.982605f, 0.060264f }, + { 0.998002f, 0.063182f }, + + /* column 13 (|ILD| = 35): */ + { 0.965056f, 0.000000f }, + { 0.965951f, 0.007932f }, + { 0.968314f, 0.014873f }, + { 0.971997f, 0.021112f }, + { 0.976963f, 0.026561f }, + { 0.983149f, 0.030984f }, + { 0.990633f, 0.034143f }, + { 0.999368f, 0.035554f }, + + /* column 14 (|ILD| = 40): */ + { 0.980198f, 0.000000f }, + { 0.980717f, 0.004528f }, + { 0.982085f, 0.008481f }, + { 0.984212f, 0.012019f }, + { 0.987068f, 0.015088f }, + { 0.990608f, 0.017552f }, + { 0.994866f, 0.019278f }, + { 0.999800f, 0.019998f }, + + /* column 15 (|ILD| = 45): */ + { 0.988816f, 0.000000f }, + { 0.989113f, 0.002568f }, + { 0.989895f, 0.004807f }, + { 0.991109f, 0.006806f }, + { 0.992735f, 0.008532f }, + { 0.994746f, 0.009911f }, + { 0.997156f, 0.010865f }, + { 0.999937f, 0.011246f }, + + /* column 16 (|ILD| = 50): */ + { 0.993695f, 0.000000f }, + { 0.993864f, 0.001451f }, + { 0.994308f, 0.002715f }, + { 0.994996f, 0.003842f }, + { 0.995917f, 0.004813f }, + { 0.997054f, 0.005586f }, + { 0.998414f, 0.006117f }, + { 0.999980f, 0.006324f } +}; + +const float dft_trigo_12k8[STEREO_DFT_N_12k8_ENC / 4 + 1] = +{ + 0.0000000f, 0.0122715f, 0.0245412f, 0.0368072f, 0.0490677f, 0.0613207f, 0.0735646f, 0.0857973f, 0.0980171f, 0.1102222f, 0.1224107f, 0.1345807f, 0.1467305f, 0.1588581f, + 0.1709619f, 0.1830399f, 0.1950903f, 0.2071114f, 0.2191012f, 0.2310581f, 0.2429802f, 0.2548657f, 0.2667128f, 0.2785197f, 0.2902847f, 0.3020059f, 0.3136817f, 0.3253103f, + 0.3368899f, 0.3484187f, 0.3598950f, 0.3713172f, 0.3826834f, 0.3939920f, 0.4052413f, 0.4164296f, 0.4275551f, 0.4386162f, 0.4496113f, 0.4605387f, 0.4713967f, 0.4821838f, + 0.4928982f, 0.5035384f, 0.5141027f, 0.5245897f, 0.5349976f, 0.5453250f, 0.5555702f, 0.5657318f, 0.5758082f, 0.5857979f, 0.5956993f, 0.6055110f, 0.6152316f, 0.6248595f, + 0.6343933f, 0.6438315f, 0.6531728f, 0.6624158f, 0.6715590f, 0.6806010f, 0.6895405f, 0.6983762f, 0.7071068f, 0.7157308f, 0.7242471f, 0.7326543f, 0.7409511f, 0.7491364f, + 0.7572088f, 0.7651673f, 0.7730105f, 0.7807372f, 0.7883464f, 0.7958369f, 0.8032075f, 0.8104572f, 0.8175848f, 0.8245893f, 0.8314696f, 0.8382247f, 0.8448536f, 0.8513552f, + 0.8577286f, 0.8639729f, 0.8700870f, 0.8760701f, 0.8819213f, 0.8876396f, 0.8932243f, 0.8986745f, 0.9039893f, 0.9091680f, 0.9142098f, 0.9191139f, 0.9238795f, 0.9285061f, + 0.9329928f, 0.9373390f, 0.9415441f, 0.9456073f, 0.9495282f, 0.9533060f, 0.9569403f, 0.9604305f, 0.9637761f, 0.9669765f, 0.9700313f, 0.9729400f, 0.9757021f, 0.9783174f, + 0.9807853f, 0.9831055f, 0.9852776f, 0.9873014f, 0.9891765f, 0.9909026f, 0.9924795f, 0.9939070f, 0.9951847f, 0.9963126f, 0.9972905f, 0.9981181f, 0.9987955f, 0.9993224f, + 0.9996988f, 0.9999247f, 1.0000000f +}; + +const float dft_trigo_32k[STEREO_DFT_N_32k_ENC / 4 + 1] = +{ + 0.0000000f, 0.0049087f, 0.0098173f, 0.0147257f, 0.0196337f, 0.0245412f, 0.0294482f, 0.0343544f, 0.0392598f, 0.0441643f, 0.0490677f, 0.0539699f, 0.0588708f, 0.0637703f, + 0.0686683f, 0.0735646f, 0.0784591f, 0.0833517f, 0.0882424f, 0.0931309f, 0.0980171f, 0.1029010f, 0.1077825f, 0.1126613f, 0.1175374f, 0.1224107f, 0.1272810f, 0.1321483f, + 0.1370123f, 0.1418731f, 0.1467305f, 0.1515843f, 0.1564345f, 0.1612809f, 0.1661234f, 0.1709619f, 0.1757963f, 0.1806264f, 0.1854522f, 0.1902736f, 0.1950903f, 0.1999024f, + 0.2047096f, 0.2095119f, 0.2143092f, 0.2191012f, 0.2238880f, 0.2286695f, 0.2334454f, 0.2382156f, 0.2429802f, 0.2477389f, 0.2524916f, 0.2572382f, 0.2619786f, 0.2667128f, + 0.2714404f, 0.2761616f, 0.2808761f, 0.2855838f, 0.2902847f, 0.2949785f, 0.2996653f, 0.3043448f, 0.3090170f, 0.3136817f, 0.3183389f, 0.3229884f, 0.3276302f, 0.3322640f, + 0.3368899f, 0.3415076f, 0.3461171f, 0.3507182f, 0.3553109f, 0.3598950f, 0.3644705f, 0.3690372f, 0.3735950f, 0.3781438f, 0.3826834f, 0.3872139f, 0.3917350f, 0.3962467f, + 0.4007488f, 0.4052413f, 0.4097240f, 0.4141969f, 0.4186597f, 0.4231125f, 0.4275551f, 0.4319874f, 0.4364092f, 0.4408206f, 0.4452213f, 0.4496113f, 0.4539905f, 0.4583587f, + 0.4627159f, 0.4670620f, 0.4713967f, 0.4757202f, 0.4800321f, 0.4843325f, 0.4886212f, 0.4928982f, 0.4971633f, 0.5014164f, 0.5056574f, 0.5098862f, 0.5141027f, 0.5183069f, + 0.5224986f, 0.5266776f, 0.5308440f, 0.5349976f, 0.5391383f, 0.5432660f, 0.5473807f, 0.5514821f, 0.5555702f, 0.5596450f, 0.5637063f, 0.5677540f, 0.5717880f, 0.5758082f, + 0.5798145f, 0.5838069f, 0.5877853f, 0.5917494f, 0.5956993f, 0.5996348f, 0.6035559f, 0.6074625f, 0.6113544f, 0.6152316f, 0.6190939f, 0.6229414f, 0.6267738f, 0.6305912f, + 0.6343933f, 0.6381801f, 0.6419516f, 0.6457076f, 0.6494480f, 0.6531728f, 0.6568819f, 0.6605751f, 0.6642524f, 0.6679137f, 0.6715590f, 0.6751880f, 0.6788007f, 0.6823972f, + 0.6859771f, 0.6895405f, 0.6930874f, 0.6966175f, 0.7001308f, 0.7036273f, 0.7071068f, 0.7105693f, 0.7140146f, 0.7174427f, 0.7208536f, 0.7242471f, 0.7276231f, 0.7309816f, + 0.7343225f, 0.7376457f, 0.7409511f, 0.7442387f, 0.7475083f, 0.7507599f, 0.7539935f, 0.7572088f, 0.7604060f, 0.7635848f, 0.7667452f, 0.7698871f, 0.7730105f, 0.7761152f, + 0.7792012f, 0.7822685f, 0.7853169f, 0.7883464f, 0.7913569f, 0.7943484f, 0.7973207f, 0.8002737f, 0.8032075f, 0.8061220f, 0.8090170f, 0.8118925f, 0.8147485f, 0.8175848f, + 0.8204014f, 0.8231983f, 0.8259753f, 0.8287325f, 0.8314696f, 0.8341867f, 0.8368838f, 0.8395606f, 0.8422172f, 0.8448536f, 0.8474695f, 0.8500651f, 0.8526402f, 0.8551947f, + 0.8577286f, 0.8602419f, 0.8627344f, 0.8652061f, 0.8676570f, 0.8700870f, 0.8724960f, 0.8748840f, 0.8772509f, 0.8795967f, 0.8819213f, 0.8842246f, 0.8865066f, 0.8887673f, + 0.8910065f, 0.8932243f, 0.8954206f, 0.8975952f, 0.8997483f, 0.9018797f, 0.9039893f, 0.9060771f, 0.9081432f, 0.9101873f, 0.9122095f, 0.9142098f, 0.9161880f, 0.9181441f, + 0.9200781f, 0.9219899f, 0.9238795f, 0.9257469f, 0.9275919f, 0.9294146f, 0.9312149f, 0.9329928f, 0.9347482f, 0.9364810f, 0.9381913f, 0.9398790f, 0.9415441f, 0.9431864f, + 0.9448060f, 0.9464029f, 0.9479770f, 0.9495282f, 0.9510565f, 0.9525619f, 0.9540444f, 0.9555039f, 0.9569403f, 0.9583537f, 0.9597440f, 0.9611112f, 0.9624552f, 0.9637761f, + 0.9650737f, 0.9663480f, 0.9675991f, 0.9688268f, 0.9700313f, 0.9712123f, 0.9723699f, 0.9735041f, 0.9746149f, 0.9757021f, 0.9767659f, 0.9778061f, 0.9788228f, 0.9798158f, + 0.9807853f, 0.9817311f, 0.9826533f, 0.9835518f, 0.9844266f, 0.9852776f, 0.9861050f, 0.9869085f, 0.9876883f, 0.9884443f, 0.9891765f, 0.9898849f, 0.9905693f, 0.9912300f, + 0.9918667f, 0.9924795f, 0.9930685f, 0.9936335f, 0.9941745f, 0.9946916f, 0.9951847f, 0.9956539f, 0.9960990f, 0.9965202f, 0.9969173f, 0.9972905f, 0.9976395f, 0.9979646f, + 0.9982656f, 0.9985426f, 0.9987955f, 0.9990243f, 0.9992290f, 0.9994097f, 0.9995663f, 0.9996988f, 0.9998072f, 0.9998916f, 0.9999518f, 0.9999880f, 1.0000000f +}; + +const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1] = +{ + 0.0000000f, 0.0032725f, 0.0065449f, 0.0098173f, 0.0130896f, 0.0163617f, 0.0196337f, 0.0229054f, 0.0261769f, 0.0294482f, 0.0327191f, 0.0359896f, 0.0392598f, 0.0425296f, + 0.0457989f, 0.0490677f, 0.0523360f, 0.0556037f, 0.0588708f, 0.0621373f, 0.0654031f, 0.0686683f, 0.0719327f, 0.0751963f, 0.0784591f, 0.0817211f, 0.0849822f, 0.0882424f, + 0.0915016f, 0.0947599f, 0.0980171f, 0.1012733f, 0.1045285f, 0.1077825f, 0.1110353f, 0.1142870f, 0.1175374f, 0.1207866f, 0.1240345f, 0.1272810f, 0.1305262f, 0.1337700f, + 0.1370123f, 0.1402532f, 0.1434926f, 0.1467305f, 0.1499668f, 0.1532014f, 0.1564345f, 0.1596658f, 0.1628955f, 0.1661234f, 0.1693495f, 0.1725738f, 0.1757963f, 0.1790169f, + 0.1822355f, 0.1854522f, 0.1886670f, 0.1918797f, 0.1950903f, 0.1982989f, 0.2015053f, 0.2047096f, 0.2079117f, 0.2111116f, 0.2143092f, 0.2175045f, 0.2206974f, 0.2238880f, + 0.2270763f, 0.2302620f, 0.2334454f, 0.2366262f, 0.2398045f, 0.2429802f, 0.2461533f, 0.2493238f, 0.2524916f, 0.2556567f, 0.2588190f, 0.2619786f, 0.2651354f, 0.2682894f, + 0.2714404f, 0.2745886f, 0.2777338f, 0.2808761f, 0.2840153f, 0.2871515f, 0.2902847f, 0.2934147f, 0.2965416f, 0.2996653f, 0.3027858f, 0.3059030f, 0.3090170f, 0.3121277f, + 0.3152350f, 0.3183389f, 0.3214395f, 0.3245366f, 0.3276302f, 0.3307203f, 0.3338069f, 0.3368899f, 0.3399692f, 0.3430450f, 0.3461171f, 0.3491854f, 0.3522500f, 0.3553109f, + 0.3583679f, 0.3614212f, 0.3644705f, 0.3675159f, 0.3705574f, 0.3735950f, 0.3766285f, 0.3796580f, 0.3826834f, 0.3857048f, 0.3887220f, 0.3917350f, 0.3947439f, 0.3977485f, + 0.4007488f, 0.4037449f, 0.4067366f, 0.4097240f, 0.4127070f, 0.4156856f, 0.4186597f, 0.4216294f, 0.4245945f, 0.4275551f, 0.4305111f, 0.4334625f, 0.4364092f, 0.4393513f, + 0.4422887f, 0.4452213f, 0.4481492f, 0.4510723f, 0.4539905f, 0.4569039f, 0.4598124f, 0.4627159f, 0.4656145f, 0.4685081f, 0.4713967f, 0.4742803f, 0.4771588f, 0.4800321f, + 0.4829003f, 0.4857634f, 0.4886212f, 0.4914739f, 0.4943212f, 0.4971633f, 0.5000000f, 0.5028314f, 0.5056574f, 0.5084780f, 0.5112931f, 0.5141027f, 0.5169069f, 0.5197055f, + 0.5224986f, 0.5252860f, 0.5280679f, 0.5308440f, 0.5336145f, 0.5363793f, 0.5391383f, 0.5418916f, 0.5446390f, 0.5473807f, 0.5501164f, 0.5528463f, 0.5555702f, 0.5582882f, + 0.5610003f, 0.5637063f, 0.5664062f, 0.5691001f, 0.5717880f, 0.5744697f, 0.5771452f, 0.5798145f, 0.5824777f, 0.5851346f, 0.5877853f, 0.5904296f, 0.5930676f, 0.5956993f, + 0.5983246f, 0.6009435f, 0.6035559f, 0.6061619f, 0.6087614f, 0.6113544f, 0.6139408f, 0.6165207f, 0.6190939f, 0.6216606f, 0.6242205f, 0.6267738f, 0.6293204f, 0.6318602f, + 0.6343933f, 0.6369196f, 0.6394390f, 0.6419516f, 0.6444573f, 0.6469562f, 0.6494480f, 0.6519330f, 0.6544109f, 0.6568819f, 0.6593458f, 0.6618027f, 0.6642524f, 0.6666951f, + 0.6691306f, 0.6715590f, 0.6739801f, 0.6763941f, 0.6788007f, 0.6812002f, 0.6835923f, 0.6859771f, 0.6883546f, 0.6907247f, 0.6930874f, 0.6954426f, 0.6977905f, 0.7001308f, + 0.7024637f, 0.7047890f, 0.7071068f, 0.7094170f, 0.7117196f, 0.7140146f, 0.7163019f, 0.7185816f, 0.7208536f, 0.7231179f, 0.7253744f, 0.7276231f, 0.7298641f, 0.7320972f, + 0.7343225f, 0.7365399f, 0.7387495f, 0.7409511f, 0.7431448f, 0.7453306f, 0.7475083f, 0.7496781f, 0.7518398f, 0.7539935f, 0.7561391f, 0.7582766f, 0.7604060f, 0.7625272f, + 0.7646403f, 0.7667452f, 0.7688418f, 0.7709303f, 0.7730105f, 0.7750824f, 0.7771460f, 0.7792012f, 0.7812482f, 0.7832867f, 0.7853169f, 0.7873387f, 0.7893520f, 0.7913569f, + 0.7933533f, 0.7953413f, 0.7973207f, 0.7992915f, 0.8012538f, 0.8032075f, 0.8051526f, 0.8070891f, 0.8090170f, 0.8109362f, 0.8128467f, 0.8147485f, 0.8166416f, 0.8185259f, + 0.8204014f, 0.8222682f, 0.8241262f, 0.8259753f, 0.8278156f, 0.8296471f, 0.8314696f, 0.8332833f, 0.8350880f, 0.8368838f, 0.8386706f, 0.8404484f, 0.8422172f, 0.8439770f, + 0.8457278f, 0.8474695f, 0.8492022f, 0.8509257f, 0.8526402f, 0.8543455f, 0.8560416f, 0.8577286f, 0.8594064f, 0.8610750f, 0.8627344f, 0.8643845f, 0.8660254f, 0.8676570f, + 0.8692793f, 0.8708923f, 0.8724960f, 0.8740903f, 0.8756753f, 0.8772509f, 0.8788171f, 0.8803739f, 0.8819213f, 0.8834592f, 0.8849876f, 0.8865066f, 0.8880161f, 0.8895161f, + 0.8910065f, 0.8924874f, 0.8939588f, 0.8954206f, 0.8968727f, 0.8983153f, 0.8997483f, 0.9011716f, 0.9025853f, 0.9039893f, 0.9053836f, 0.9067683f, 0.9081432f, 0.9095084f, + 0.9108638f, 0.9122095f, 0.9135455f, 0.9148716f, 0.9161880f, 0.9174945f, 0.9187912f, 0.9200781f, 0.9213551f, 0.9226223f, 0.9238795f, 0.9251269f, 0.9263644f, 0.9275919f, + 0.9288096f, 0.9300172f, 0.9312149f, 0.9324027f, 0.9335804f, 0.9347482f, 0.9359059f, 0.9370536f, 0.9381913f, 0.9393190f, 0.9404366f, 0.9415441f, 0.9426415f, 0.9437288f, + 0.9448060f, 0.9458732f, 0.9469301f, 0.9479770f, 0.9490136f, 0.9500402f, 0.9510565f, 0.9520627f, 0.9530586f, 0.9540444f, 0.9550199f, 0.9559853f, 0.9569403f, 0.9578852f, + 0.9588197f, 0.9597440f, 0.9606581f, 0.9615618f, 0.9624552f, 0.9633384f, 0.9642112f, 0.9650737f, 0.9659258f, 0.9667676f, 0.9675991f, 0.9684202f, 0.9692309f, 0.9700313f, + 0.9708212f, 0.9716008f, 0.9723699f, 0.9731287f, 0.9738770f, 0.9746149f, 0.9753423f, 0.9760593f, 0.9767659f, 0.9774620f, 0.9781476f, 0.9788228f, 0.9794874f, 0.9801416f, + 0.9807853f, 0.9814185f, 0.9820411f, 0.9826533f, 0.9832549f, 0.9838460f, 0.9844266f, 0.9849966f, 0.9855561f, 0.9861050f, 0.9866433f, 0.9871711f, 0.9876883f, 0.9881950f, + 0.9886910f, 0.9891765f, 0.9896514f, 0.9901157f, 0.9905693f, 0.9910124f, 0.9914449f, 0.9918667f, 0.9922779f, 0.9926785f, 0.9930685f, 0.9934478f, 0.9938165f, 0.9941745f, + 0.9945219f, 0.9948586f, 0.9951847f, 0.9955002f, 0.9958049f, 0.9960990f, 0.9963825f, 0.9966552f, 0.9969173f, 0.9971688f, 0.9974095f, 0.9976395f, 0.9978589f, 0.9980676f, + 0.9982656f, 0.9984529f, 0.9986295f, 0.9987955f, 0.9989507f, 0.9990952f, 0.9992290f, 0.9993522f, 0.9994646f, 0.9995663f, 0.9996573f, 0.9997376f, 0.9998072f, 0.9998661f, + 0.9999143f, 0.9999518f, 0.9999786f, 0.9999946f, 1.0000000f +}; + +/* tables for adaptive Golomb-Rice coding of DFT stereo parameters */ +const int16_t dft_code_itd[] = +{ + 0, 3, 4, 13, 8, 9, 12, 5, 10, 44, 23, 60, 45, 31, 235, 59, 28, 61, 234, 116 +}; + +const int16_t dft_len_itd[] = +{ + 2, 3, 4, 4, 4, 4, 4, 4, 4, 6, 5, 6, 6, 5, 8, 6, 5, 6, 8, 7 +}; + +const int16_t dft_maps_rpg[] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, + 2, 0, 1, 3, 4, 5, 6, 7, + 6, 2, 0, 1, 3, 4, 5, 7, + 7, 5, 2, 0, 1, 3, 4, 6, + 7, 6, 4, 3, 1, 0, 2, 5, + 7, 6, 5, 3, 2, 1, 0, 4, + 7, 6, 5, 4, 3, 2, 0, 1, + 7, 6, 5, 4, 3, 2, 0, 1, + 6, 5, 4, 3, 1, 0, 2, 7, +}; + +const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 15, 4, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 12, 9, 4, 1, 0, 2, 3, 5, 6, 7, 8, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 16, 14, 8, 4, 2, 0, 1, 3, 5, 6, 7, 9, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 18, 16, 14, 10, 5, 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 21, 19, 17, 15, 8, 4, 2, 0, 1, 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 21, 19, 17, 15, 12, 8, 4, 0, 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 21, 19, 17, 15, 13, 11, 9, 3, 0, 1, 2, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 24, 22, 20, 18, 16, 14, 12, 9, 6, 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 15, 17, 19, 21, 23, 25, 26, 27, 28, 29, 30, + 25, 23, 21, 19, 17, 15, 13, 11, 9, 6, 0, 1, 2, 3, 4, 5, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 27, 28, 29, 30, + 27, 25, 23, 21, 19, 17, 15, 13, 11, 8, 5, 0, 1, 2, 3, 4, 6, 7, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 29, 30, + 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 0, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 28, 29, 30, + 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 30, + 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 0, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, + 30, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, + 30, 29, 28, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, + 30, 29, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 9, 7, 6, 4, 3, 2, 1, 0, 5, 8, 11, 13, 15, 17, 19, 21, 23, 25, 27, + 30, 29, 28, 27, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 7, 5, 4, 3, 2, 1, 0, 6, 9, 11, 13, 15, 17, 19, 21, 23, 25, + 30, 29, 28, 27, 26, 25, 23, 21, 19, 17, 15, 13, 11, 10, 8, 7, 5, 4, 3, 2, 1, 0, 6, 9, 12, 14, 16, 18, 20, 22, 24, + 30, 29, 28, 27, 26, 25, 24, 23, 22, 20, 18, 16, 14, 12, 10, 8, 7, 6, 5, 4, 2, 1, 0, 3, 9, 11, 13, 15, 17, 19, 21, + 30, 29, 28, 27, 26, 25, 24, 23, 22, 20, 18, 16, 14, 13, 11, 10, 9, 7, 6, 5, 3, 2, 1, 0, 4, 8, 12, 15, 17, 19, 21, + 30, 29, 28, 27, 26, 25, 24, 23, 22, 20, 18, 16, 14, 13, 12, 11, 10, 9, 7, 6, 5, 3, 1, 0, 2, 4, 8, 15, 17, 19, 21, + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 17, 15, 13, 12, 11, 9, 8, 7, 6, 4, 3, 2, 1, 0, 5, 10, 14, 16, 18, + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 15, 13, 12, 11, 10, 9, 7, 6, 5, 3, 1, 0, 2, 4, 8, 14, 16, + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 11, 10, 8, 7, 6, 5, 3, 2, 0, 1, 4, 9, 12, + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 3, 2, 1, 0, 4, 15, + 30, 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, 0, 1, + 30, 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 +}; + + +/*------------------------------------------------------------------------- + * Range Coder ROM tables + *------------------------------------------------------------------------*/ + +/* Create separate tables for cumulative frequency and symbol frequency */ +const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] = +{ + { 0,16,47,153,241,269,325,468,591,674,798,912,1017,1082,1183,1277,1364,16384 }, + { 0,7401,7844,7886,7899,12065,12718,12790,12805,14099,14476,14533,14549,15058,15264,15299,15310,16384 }, + { 0,4362,6345,6864,7038,9037,11049,11736,12002,12569,13301,13656,13822,14021,14334,14515,14607,16384 }, + { 0,2955,5183,5822,6013,8153,10671,11614,11943,12586,13540,14025,14232,14437,14770,14978,15080,16384 }, + { 0,3155,4981,5615,5855,7969,9953,10739,11073,11936,12837,13208,13383,13767,14203,14400,14498,16384 }, + { 0,1216,2630,3264,3558,4831,6679,7661,8157,8709,9622,10204,10542,10799,11243,11568,11777,16384 }, + { 0,1759,3641,4350,4612,6325,8678,9732,10161,10790,11790,12361,12642,12883,13295,13566,13720,16384 }, + { 0,1109,2705,3433,3732,5226,7532,8732,9263,9978,11142,11842,12188,12490,12986,13321,13520,16384 }, + { 0,11524,13046,13170,13191,14956,15708,15813,15837,16028,16162,16195,16204,16245,16282,16295,16300,16384 }, + { 0,8027,10586,10909,10974,13291,14861,15157,15232,15535,15824,15914,15943,16014,16090,16123,16136,16384 }, + { 0,834,2034,2674,2997,4087,5843,6891,7455,8030,9013,9688,10085,10376,10893,11277,11528,16384 }, + { 0,6038,9086,9451,9519,12332,14521,14913,15003,15329,15711,15848,15893,15955,16045,16091,16111,16384 }, + { 0,4732,7685,8354,8545,10717,12924,13618,13852,14291,14842,15083,15181,15314,15491,15582,15625,16384 }, + { 0,745,1783,2347,2655,3537,4963,5864,6406,6863,7664,8248,8634,8891,9351,9708,9958,16384 }, + { 0,3957,6794,7669,7998,9743,11676,12498,12869,13313,13894,14186,14332,14498,14714,14835,14906,16384 }, + { 0,2779,5388,6021,6201,8582,11352,12260,12544,13117,13981,14408,14580,14751,15039,15213,15298,16384 }, + { 0,448,1160,1625,1920,2576,3706,4518,5053,5474,6234,6835,7262,7531,8032,8446,8758,16384 }, + { 0,1,2,1555,2246,2247,2248,3489,4112,5449,6596,7302,7710,8311,8876,9266,9517,16384 }, + { 0,2496,4910,5544,5722,8049,10799,11689,11973,12583,13467,13878,14047,14234,14537,14712,14803,16384 }, + { 0,921,2222,2880,3188,4407,6321,7406,7955,8573,9616,10296,10679,10978,11502,11880,12118,16384 }, + { 0,2620,4443,5017,5233,7072,9213,10083,10441,11049,11954,12442,12676,12918,13310,13565,13705,16384 }, + { 0,11205,13084,13178,13187,15164,16010,16081,16091,16213,16303,16321,16325,16340,16355,16360,16362,16384 }, + { 0,358,916,1288,1542,2055,2937,3594,4062,4399,5017,5524,5907,6136,6573,6941,7236,16384 }, + { 0,3575,5093,5536,5735,7408,9185,9878,10188,10727,11497,11933,12165,12410,12794,13019,13166,16384 }, + { 0,1,2,640,1036,1037,1038,1670,2096,2696,3287,3732,4056,4417,4800,5106,5339,16384 }, + { 0,969,1397,1518,1578,2633,3338,3566,3675,4197,4664,4857,4957,5288,5625,5783,5874,16384 }, + { 0,10458,12104,12294,12331,14246,15264,15437,15481,15752,15971,16031,16050,16120,16186,16210,16218,16384 }, + { 0,7178,9744,10039,10093,12701,14612,14961,15042,15360,15732,15869,15917,15978,16070,16117,16139,16384 }, + { 0,1298,2418,2879,3113,4146,5509,6227,6621,7053,7755,8229,8539,8776,9186,9492,9714,16384 }, + { 0,4957,7785,8252,8357,10978,13372,13955,14114,14561,15140,15378,15464,15570,15730,15820,15860,16384 }, + { 0,4823,8164,8570,8647,11604,14169,14653,14763,15105,15554,15727,15785,15852,15960,16018,16045,16384 }, + { 0,4735,7010,7517,7660,9986,12230,12914,13131,13666,14374,14689,14814,14972,15212,15342,15404,16384 }, + { 0,3363,5881,6658,6941,8864,11113,12015,12368,12889,13643,14019,14203,14394,14665,14823,14906,16384 }, + { 0,2569,4996,5779,6068,7917,10251,11209,11602,12129,12918,13321,13520,13696,13976,14155,14259,16384 }, + { 0,209,577,848,1046,1378,1982,2465,2835,3072,3513,3893,4202,4374,4703,4994,5241,16384 }, + { 0,2074,4337,5048,5274,7319,10003,11066,11446,12105,13112,13652,13885,14100,14464,14691,14810,16384 }, + { 0,1619,3560,4288,4550,6381,8955,10102,10543,11239,12362,12982,13261,13516,13958,14234,14381,16384 }, + { 0,89,257,441,582,734,1024,1325,1568,1716,1983,2222,2430,2545,2750,2941,3109,16384 }, + { 0,2202,3563,4044,4264,5686,7344,8100,8476,9006,9835,10331,10612,10864,11304,11599,11787,16384 }, + { 0,1220,2801,3492,3784,5223,7387,8496,8998,9640,10711,11369,11711,11993,12486,12829,13035,16384 }, + { 0,12626,13813,13903,13917,15396,15906,15972,15987,16139,16230,16251,16257,16289,16315,16323,16326,16384 }, + { 0,1579,3191,3831,4099,5678,7788,8761,9206,9842,10821,11388,11681,11958,12417,12722,12902,16384 }, + { 0,597,1514,2064,2379,3237,4679,5637,6213,6733,7649,8316,8755,9052,9599,10023,10323,16384 }, + { 0,9273,11762,12080,12151,14038,15210,15446,15514,15725,15929,15995,16019,16068,16124,16148,16158,16384 }, + { 0,9238,11681,11852,11872,14306,15644,15801,15828,16013,16183,16231,16243,16266,16297,16312,16318,16384 }, + { 0,6791,9200,9531,9594,12240,14178,14552,14639,15064,15506,15643,15687,15785,15908,15960,15983,16384 }, + { 0,7175,10415,10905,11033,13038,14621,15002,15123,15367,15651,15762,15806,15864,15938,15974,15992,16384 }, + { 0,5060,7703,8132,8225,10934,13270,13778,13911,14397,14972,15173,15242,15367,15537,15619,15654,16384 }, + { 0,3721,6311,6857,6992,9557,12180,12895,13098,13671,14418,14718,14830,14984,15212,15333,15390,16384 }, + { 0,5971,9288,10044,10269,11991,13680,14228,14437,14750,15130,15293,15374,15459,15579,15642,15677,16384 }, + { 0,3047,5311,5907,6078,8339,10850,11679,11946,12580,13442,13854,14024,14220,14534,14716,14810,16384 }, + { 0,2061,4280,4993,5228,7201,9735,10735,11097,11708,12606,13082,13295,13498,13836,14043,14161,16384 }, + { 0,4738,7949,8880,9234,10781,12502,13214,13531,13897,14355,14593,14718,14835,14998,15096,15153,16384 }, + { 0,3237,5045,5632,5860,7609,9702,10608,10986,11571,12476,12978,13230,13451,13830,14074,14208,16384 }, + { 0,1833,3889,4677,5028,6422,8379,9378,9884,10350,11086,11545,11809,12003,12327,12559,12711,16384 }, + { 0,3989,6858,7352,7459,10254,12936,13571,13735,14240,14895,15153,15242,15364,15548,15646,15690,16384 }, + { 0,1463,3197,3909,4220,5626,7609,8632,9127,9657,10520,11078,11380,11607,11991,12265,12442,16384 }, + { 0,14233,15083,15108,15110,16069,16300,16314,16316,16352,16370,16373,16374,16377,16380,16381,16382,16384 }, + { 0,1,2,2610,3293,3294,3295,5097,5671,8467,10332,11119,11437,12223,12850,13185,13345,16384 }, + { 0,2010,4053,4696,4910,6879,9391,10386,10750,11393,12376,12886,13119,13348,13726,13967,14099,16384 }, + { 0,7586,10517,10758,10791,13543,15346,15577,15619,15846,16082,16150,16169,16202,16245,16265,16273,16384 }, + { 0,3059,5772,6369,6524,9041,11801,12582,12813,13361,14115,14439,14567,14714,14944,15075,15141,16384 }, + { 0,8643,10594,10813,10856,13274,14686,14920,14975,15350,15680,15771,15799,15897,16003,16042,16057,16384 }, + { 0,6720,8878,9325,9467,11564,13248,13744,13929,14384,14880,15087,15167,15311,15488,15569,15607,16384 }, +}; + +const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = +{ + { 16,31,106,88,28,56,143,123,83,124,114,105,65,101,94,87,15020 }, + { 7401,443,42,13,4166,653,72,15,1294,377,57,16,509,206,35,11,1074 }, + { 4362,1983,519,174,1999,2012,687,266,567,732,355,166,199,313,181,92,1777 }, + { 2955,2228,639,191,2140,2518,943,329,643,954,485,207,205,333,208,102,1304 }, + { 3155,1826,634,240,2114,1984,786,334,863,901,371,175,384,436,197,98,1886 }, + { 1216,1414,634,294,1273,1848,982,496,552,913,582,338,257,444,325,209,4607 }, + { 1759,1882,709,262,1713,2353,1054,429,629,1000,571,281,241,412,271,154,2664 }, + { 1109,1596,728,299,1494,2306,1200,531,715,1164,700,346,302,496,335,199,2864 }, + { 11524,1522,124,21,1765,752,105,24,191,134,33,9,41,37,13,5,84 }, + { 8027,2559,323,65,2317,1570,296,75,303,289,90,29,71,76,33,13,248 }, + { 834,1200,640,323,1090,1756,1048,564,575,983,675,397,291,517,384,251,4856 }, + { 6038,3048,365,68,2813,2189,392,90,326,382,137,45,62,90,46,20,273 }, + { 4732,2953,669,191,2172,2207,694,234,439,551,241,98,133,177,91,43,759 }, + { 745,1038,564,308,882,1426,901,542,457,801,584,386,257,460,357,250,6426 }, + { 3957,2837,875,329,1745,1933,822,371,444,581,292,146,166,216,121,71,1478 }, + { 2779,2609,633,180,2381,2770,908,284,573,864,427,172,171,288,174,85,1086 }, + { 448,712,465,295,656,1130,812,535,421,760,601,427,269,501,414,312,7626 }, + { 1,1,1553,691,1,1,1241,623,1337,1147,706,408,601,565,390,251,6867 }, + { 2496,2414,634,178,2327,2750,890,284,610,884,411,169,187,303,175,91,1581 }, + { 921,1301,658,308,1219,1914,1085,549,618,1043,680,383,299,524,378,238,4266 }, + { 2620,1823,574,216,1839,2141,870,358,608,905,488,234,242,392,255,140,2679 }, + { 11205,1879,94,9,1977,846,71,10,122,90,18,4,15,15,5,2,22 }, + { 358,558,372,254,513,882,657,468,337,618,507,383,229,437,368,295,9148 }, + { 3575,1518,443,199,1673,1777,693,310,539,770,436,232,245,384,225,147,3218 }, + { 1,1,638,396,1,1,632,426,600,591,445,324,361,383,306,233,11045 }, + { 969,428,121,60,1055,705,228,109,522,467,193,100,331,337,158,91,10510 }, + { 10458,1646,190,37,1915,1018,173,44,271,219,60,19,70,66,24,8,166 }, + { 7178,2566,295,54,2608,1911,349,81,318,372,137,48,61,92,47,22,245 }, + { 1298,1120,461,234,1033,1363,718,394,432,702,474,310,237,410,306,222,6670 }, + { 4957,2828,467,105,2621,2394,583,159,447,579,238,86,106,160,90,40,524 }, + { 4823,3341,406,77,2957,2565,484,110,342,449,173,58,67,108,58,27,339 }, + { 4735,2275,507,143,2326,2244,684,217,535,708,315,125,158,240,130,62,980 }, + { 3363,2518,777,283,1923,2249,902,353,521,754,376,184,191,271,158,83,1478 }, + { 2569,2427,783,289,1849,2334,958,393,527,789,403,199,176,280,179,104,2125 }, + { 209,368,271,198,332,604,483,370,237,441,380,309,172,329,291,247,11143 }, + { 2074,2263,711,226,2045,2684,1063,380,659,1007,540,233,215,364,227,119,1574 }, + { 1619,1941,728,262,1831,2574,1147,441,696,1123,620,279,255,442,276,147,2003 }, + { 89,168,184,141,152,290,301,243,148,267,239,208,115,205,191,168,13275 }, + { 2202,1361,481,220,1422,1658,756,376,530,829,496,281,252,440,295,188,4597 }, + { 1220,1581,691,292,1439,2164,1109,502,642,1071,658,342,282,493,343,206,3349 }, + { 12626,1187,90,14,1479,510,66,15,152,91,21,6,32,26,8,3,58 }, + { 1579,1612,640,268,1579,2110,973,445,636,979,567,293,277,459,305,180,3482 }, + { 597,917,550,315,858,1442,958,576,520,916,667,439,297,547,424,300,6061 }, + { 9273,2489,318,71,1887,1172,236,68,211,204,66,24,49,56,24,10,226 }, + { 9238,2443,171,20,2434,1338,157,27,185,170,48,12,23,31,15,6,66 }, + { 6791,2409,331,63,2646,1938,374,87,425,442,137,44,98,123,52,23,401 }, + { 7175,3240,490,128,2005,1583,381,121,244,284,111,44,58,74,36,18,392 }, + { 5060,2643,429,93,2709,2336,508,133,486,575,201,69,125,170,82,35,730 }, + { 3721,2590,546,135,2565,2623,715,203,573,747,300,112,154,228,121,57,994 }, + { 5971,3317,756,225,1722,1689,548,209,313,380,163,81,85,120,63,35,707 }, + { 3047,2264,596,171,2261,2511,829,267,634,862,412,170,196,314,182,94,1574 }, + { 2061,2219,713,235,1973,2534,1000,362,611,898,476,213,203,338,207,118,2223 }, + { 4738,3211,931,354,1547,1721,712,317,366,458,238,125,117,163,98,57,1231 }, + { 3237,1808,587,228,1749,2093,906,378,585,905,502,252,221,379,244,134,2176 }, + { 1833,2056,788,351,1394,1957,999,506,466,736,459,264,194,324,232,152,3673 }, + { 3989,2869,494,107,2795,2682,635,164,505,655,258,89,122,184,98,44,694 }, + { 1463,1734,712,311,1406,1983,1023,495,530,863,558,302,227,384,274,177,3942 }, + { 14233,850,25,2,959,231,14,2,36,18,3,1,3,3,1,1,2 }, + { 1,1,2608,683,1,1,1802,574,2796,1865,787,318,786,627,335,160,3039 }, + { 2010,2043,643,214,1969,2512,995,364,643,983,510,233,229,378,241,132,2285 }, + { 7586,2931,241,33,2752,1803,231,42,227,236,68,19,33,43,20,8,111 }, + { 3059,2713,597,155,2517,2760,781,231,548,754,324,128,147,230,131,66,1243 }, + { 8643,1951,219,43,2418,1412,234,55,375,330,91,28,98,106,39,15,327 }, + { 6720,2158,447,142,2097,1684,496,185,455,496,207,80,144,177,81,38,777 }, +}; + + +/*------------------------------------------------------------------------- + * ECLVQ Stereo ROM tables + *------------------------------------------------------------------------*/ + +/* table with round(ECSQ_PROB_TOTAL / index) for entropy coding, with i in {1, .., ECSQ_SEGMENT_SIZE} */ +const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE] = +{ + 0, 16384, 8192, 5461, 4096, 3277, 2731, 2341, 2048 +}; + + +/*------------------------------------------------------------------------- + * Stereo ICA analysis ROM tables + *------------------------------------------------------------------------*/ + +const float ica_sincInterp2[2*SINC_ORDER1+1] = +{ + 0.0f,-0.002323f,0.0f, 0.003486f, 0.0f,-0.005865f,0.0f, 0.009735f, 0.0f,-0.015447f,0.0f, 0.023503f, + 0.0f,-0.034727f,0.0f, 0.050649f, 0.0f,-0.074578f,0.0f, 0.115220f, 0.0f,-0.204776f,0.0f, 0.634114f, + 1.0f, 0.634114f,0.0f,-0.204776f, 0.0f, 0.115220f,0.0f,-0.074578f, 0.0f, 0.050649f,0.0f,-0.034727f, + 0.0f, 0.023503f,0.0f,-0.015447f, 0.0f, 0.009735f,0.0f,-0.005865f, 0.0f, 0.003486f,0.0f,-0.002323f, 0.0f +}; + +const float ica_sincInterp4[2*SINC_ORDER1+1] = +{ + 0.0f,-0.003285f,-0.005537f,-0.004930f, 0.0f, 0.008295f, 0.015189f, 0.013767f, 0.0f,-0.021845f,-0.038282f,-0.033239f, + 0.0f, 0.049111f, 0.083913f, 0.071628f, 0.0f,-0.105469f,-0.183615f,-0.162946f, 0.0f, 0.289597f, 0.626641f, 0.896773f, + 1.0f, 0.896773f, 0.626641f, 0.289597f, 0.0f,-0.162946f,-0.183615f,-0.105469f, 0.0f, 0.071628f, 0.083913f, 0.049111f, + 0.0f,-0.033239f,-0.038282f,-0.021845f, 0.0f, 0.013767f, 0.015189f, 0.008295f, 0.0f,-0.004930f,-0.005537f,-0.003285f, 0.0f +}; + +const float ica_sincInterp6[2*SINC_ORDER1+1] = +{ + 0.0f,-0.003484f,-0.007192f,-0.010460f,-0.011712f,-0.008798f, 0.0f, 0.014603f, 0.032045f, 0.046341f, 0.049731f, 0.035255f, + 0.0f,-0.052090f,-0.109007f,-0.151947f,-0.159196f,-0.111867f, 0.0f, 0.172831f, 0.388013f, 0.614328f, 0.814030f, 0.951171f, + 1.0f, 0.951171f, 0.814030f, 0.614328f, 0.388013f, 0.172831f, 0.0f,-0.111867f,-0.159196f,-0.151947f,-0.109007f,-0.052090f, + 0.0f, 0.035255f, 0.049731f, 0.046341f, 0.032045f, 0.014603f, 0.0f,-0.008798f,-0.011712f,-0.010460f,-0.007192f,-0.003484f, 0.0f +}; + + +/*----------------------------------------------------------------------------------* + * Stereo IC-BWE ROM tables + *----------------------------------------------------------------------------------*/ + +const float icbwe_gsMapping_tbl[16] = +{ + -2.0000000f, -1.3494960f, -0.9607952f, -0.7098941f, -0.5589364f, -0.4453763f, -0.3429649f, -0.2527705f, + -0.1690688f, -0.0987095f, -0.0700000f, -0.0500000f, -0.0200000f, 0.0000000f, 0.0400000f, 0.0800000f +}; + +const float icbwe_gsMappingDFT_tbl[128] = +{ + -5.0000000f, -4.5000000f, -4.0000000f, -3.5000000f, -3.0000000f, -2.5000000f, -1.9000000f, -1.5474502f, + -1.5002078f, -1.4469336f, -1.3902478f, -1.3770106f, -1.3094972f, -1.2608015f, -1.0926061f, -1.0843442f, + -1.0345038f, -1.0286606f, -1.0161779f, -1.0036838f, -0.9812821f, -0.9698121f, -0.9573308f, -0.9405646f, + -0.9297086f, -0.9131601f, -0.9025761f, -0.8860643f, -0.8736950f, -0.8564931f, -0.8403996f, -0.8352164f, + -0.8241847f, -0.8038731f, -0.7923367f, -0.7789138f, -0.7679189f, -0.7595301f, -0.7566783f, -0.7507762f, + -0.7428076f, -0.7386452f, -0.7339793f, -0.7300271f, -0.7243238f, -0.7188097f, -0.7090309f, -0.7047743f, + -0.7000968f, -0.6903794f, -0.6844128f, -0.6792722f, -0.6724832f, -0.6680448f, -0.6638050f, -0.6587732f, + -0.6519668f, -0.6454810f, -0.6418348f, -0.6352437f, -0.6296001f, -0.6244346f, -0.6182194f, -0.6134241f, + -0.6093079f, -0.6042419f, -0.5995789f, -0.5946505f, -0.5897729f, -0.5851547f, -0.5806601f, -0.5759744f, + -0.5720182f, -0.5669503f, -0.5630283f, -0.5573819f, -0.5511614f, -0.5438205f, -0.5364699f, -0.5282783f, + -0.5198154f, -0.5095584f, -0.4986083f, -0.4861976f, -0.4725366f, -0.4591254f, -0.4449745f, -0.4310394f, + -0.4169318f, -0.4033374f, -0.3898838f, -0.3766562f, -0.3616849f, -0.3472800f, -0.3326788f, -0.3194550f, + -0.3060711f, -0.2916924f, -0.2783983f, -0.2642500f, -0.2506378f, -0.2368909f, -0.2203000f, -0.2036115f, + -0.1869981f, -0.1709912f, -0.1561569f, -0.1420659f, -0.1263750f, -0.1107119f, -0.0953914f, -0.0805369f, + -0.0660773f, -0.0529481f, -0.0401913f, -0.0287031f, -0.0184659f, -0.0094214f, 0.0000000f, 0.0073561f, + 0.0155180f, 0.0224511f, 0.0298570f, 0.0375954f, 0.0457853f, 0.0549424f, 0.0659733f, 0.0785186f +}; + + +/*----------------------------------------------------------------------------------* + * TD Stereo ROM tables + *----------------------------------------------------------------------------------*/ + +const float tdm_ratio_tabl[TDM_NQ+1] = +{ + 0.00f, 0.00f, 0.0109f, 0.0245f, 0.0432f, 0.0670f, 0.0955f, 0.1284f, + 0.1654f, 0.2061f, 0.2500f, 0.2966f, 0.3455f, 0.3960f, 0.4477f, 0.5000f, + 0.5523f, 0.6040f, 0.6545f, 0.7034f, 0.7500f, 0.7939f, 0.8346f, 0.8716f, + 0.9045f, 0.9330f, 0.9568f, 0.9755f, 0.9891f, 1.0000f, 1.0000f, 1.0000f +}; +const float tdm_den_ratio_tabl[TDM_NQ+1] = /* 1.0f/(2*LR_ratio*LR_ratio-2*LR_ratio+1) */ +{ + 1.0000f, 1.0000f, 1.0221f, 1.0501f, 1.0902f, 1.1429f, 1.2088f, 1.2884f, + 1.3815f, 1.4864f, 1.6000f, 1.7161f, 1.8257f, 1.9171f, 1.9784f, 2.0000f, + 1.9784f, 1.9171f, 1.8257f, 1.7161f, 1.6000f, 1.4864f, 1.3815f, 1.2884f, + 1.2088f, 1.1429f, 1.0902f, 1.0501f, 1.0221f, 1.0000f, 1.0000f, 1.0000f +}; + +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +const int16_t tdm_bit_allc_tbl[5][6] = +{ + /* IC -- UC -- GC -- TM --AC */ + { 1650, 3500, 0, 4400, 0, 5000 }, /* IVAS_13k2 */ + { 1650, 3500, 0, 5000, 0, 5000 }, /* IVAS_16k4 */ + { 1650, 3500, 0, 6000, 0, 5000 }, /* IVAS_24k4 */ + { 1650, 6050, 0, 10000, 0, 10000 }, /* IVAS_32k */ + { 1650, 6050, 0, 13000, 0, 14000 } /* IVAS_48k */ +}; +#else +const int16_t tdm_bit_allc_tbl[5][6] = +{ + /* IC -- UC -- GC -- TM --AC */ + { 1600, 3450, 0, 4400, 0, 5000 }, /* IVAS_13k2 */ + { 1600, 3450, 0, 5000, 0, 5000 }, /* IVAS_16k4 */ + { 1600, 3450, 0, 6000, 0, 5000 }, /* IVAS_24k4 */ + { 1600, 6000, 0, 10000, 0, 10000 }, /* IVAS_32k */ + { 1600, 6000, 0, 13000, 0, 14000 } /* IVAS_48k */ +}; +#endif + +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +/* LSFs Intra-frame prediction tables */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +const float tdm_LSF_MEAN_RE_USE_OUT[M] = +{ + 301.292f, 521.300f, 870.818f, 1340.278f, 1712.099f, 2091.456f, 2488.523f, 2841.096f, 3196.565f, 3593.040f, 3958.366f, 4293.334f, 4710.319f, 5118.806f, 5546.761f, 5918.579f, +}; + +const float tdm_LSF_MEAN_RE_USE_IN[M] = +{ + 286.414f, 522.366f, 887.297f, 1347.961f, 1725.604f, 2102.356f, 2511.703f, 2853.093f, 3211.319f, 3612.072f, 3970.889f, 4327.774f, 4732.423f, 5154.984f, 5572.849f, 5964.332f, +}; + +const float tdm_LSF_MEAN_RE_USE[M] = +{ + 265.534222F, 534.776631F, 919.574509F, 1346.991675F, 1756.991835F, 2123.061862F, 2556.845807F, 2927.484493F, + 3299.107307F, 3686.249102F, 4034.473656F, 4393.818819F, 4781.683038F, 5155.954294F, 5542.569582F, 5927.377309F +}; + +const float tdm_Beta_Q1bit_re_use_132[2] = { 0.97F, 0.75F }; +const float tdm_Beta_Q1bit_re_use_164[2] = { 0.95F, 0.71F }; +const float tdm_Beta_Q1bit_re_use_244_320[2] = { 0.93F, 0.73F }; +const float tdm_Beta_Q1bit_re_use_480[2] = { 0.97F, 0.77F }; + +const float tdm_RE_USE_adaptive_beta_prd_diag_3[15 + 16 + 15] = +{ + 0.8859f, 0.2060f, + 0.0585f, 0.8245f, 0.2294f, + 0.0365f, 0.8175f, 0.1696f, + -0.0060f, 0.8483f, 0.2061f, + 0.0663f, 0.8983f, 0.1357f, + 0.0664f, 0.7951f, 0.1934f, + 0.0935f, 0.7948f, 0.1685f, + 0.1109f, 0.7960f, 0.1828f, + 0.1073f, 0.7835f, 0.1804f, + 0.1479f, 0.7362f, 0.1982f, + 0.1335f, 0.7621f, 0.1900f, + 0.1903f, 0.7369f, 0.1715f, + 0.1785f, 0.7214f, 0.1646f, + 0.1967f, 0.6891f, 0.1229f, + 0.2043f, 0.6317f, 0.0543f, + 0.1767f, 0.5396f, +}; +#endif + +const float tdm_LSF_MEAN_PRED_QNT[M] = +{ + 391.31345F, 608.50453F, 968.00585F, 1354.23965F, 1709.71084F, 2080.49872F, 2450.64009F, 2796.96588F, + 3196.19608F, 3554.17092F, 3915.02370F, 4283.81121F, 4707.59835F, 5109.79026F, 5526.44936F, 5903.42625F +}; + +const float tdm_LSF_MEAN_PRED_QNT_IN[M] = +{ + 288.540f, 535.469f, 899.738f, 1342.313f, 1730.736f, 2107.070f, 2491.455f, 2859.828f, 3239.279f, 3625.673f, 3992.540f, 4356.748f, 4752.356f, 5153.685f, 5567.107f, 5972.623f, +}; +const float tdm_LSF_MEAN_PRED_QNT_OUT[M] = +{ + 286.414f, 522.366f, 887.297f, 1347.961f, 1725.604f, 2102.356f, 2511.703f, 2853.093f, 3211.319f, 3612.072f, 3970.889f, 4327.774f, 4732.423f, 5154.984f, 5572.849f, 5964.332f, +}; + +const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15] = +{ + 0.7040f, 0.1203f, + -0.1119f, 0.7340f, 0.1803f, + 0.0253f, 0.6702f, 0.1901f, + -0.1847f, 0.7892f, 0.3010f, + -0.0418f, 0.8716f, 0.1837f, + 0.0033f, 0.6915f, 0.2394f, + 0.0213f, 0.6728f, 0.2441f, + 0.0705f, 0.7549f, 0.1983f, + 0.0752f, 0.7152f, 0.2173f, + 0.0886f, 0.6163f, 0.3067f, + 0.0217f, 0.8121f, 0.2021f, + 0.1584f, 0.7311f, 0.1746f, + 0.1204f, 0.7296f, 0.1978f, + 0.1231f, 0.7502f, 0.1234f, + 0.1709f, 0.6372f, 0.1060f, + 0.1193f, 0.6574f, +}; +#endif + + +/*----------------------------------------------------------------------------------* + * MDCT Stereo ROM tables + *----------------------------------------------------------------------------------*/ + + /* PsychLPC */ + +const SpectrumWarping sw32000Hz[] = +{{ + { + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, + 6, 8, 8, 8, 8, 8, 10, 10, 10, 10, 12, 12, 12, 12, 14, 14, + 14, 16, 18, 18, 18, 20, 22, 22, 22, 24, 26, 26, 26, 28, 30, 32 + }, + { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, + 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10 + }, +}}; + +const SpectrumWarping sw25600Hz[] = +{{ + { + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, + 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 12, 12, 12, + 12, 12, 14, 14, 14, 14, 14, 16, 16, 18, 18, 18, 18, 18, 20, 20 + }, + { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7 + }, +}}; + +const SpectrumWarping sw16000Hz[] = +{{ + { + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 + }, + { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 + }, +}}; + +const MDCTStereoBands_config mdctStereoBands_32000_640[] = +{{ + /*TCX 20*/ + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, + 12, 20, 20, 20, 22, 22, 22, 22, 22, 22, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 42, + 64, 64, 96, 160}, + {44, 41,38, 29},/*number of bands for frame lengths 960, 640, 512, 320 respectively*/ + + /*TCX 10*/ + { + 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 20, 32, 32, + 32, 48, 80 + }, + {33, 29, 26, 18}/*number of bands for frame lengths 480, 320, 256, 160 respectively*/ +}}; + +const float nf_tw_smoothing_coeffs[N_LTP_GAIN_MEMS] = +{ + 0.4f,0.2f,0.2f,0.2f +}; + + +/*----------------------------------------------------------------------------------* + * Stereo DTX tables + *----------------------------------------------------------------------------------*/ + +const float dft_cng_coh_pred[STEREO_DFT_N_COH_PRED][STEREO_DFT_COH_PRED_COEFFS] = +{ + { 0.601337f, -0.101048f, 1.269064f, 0.085044f, 0.279032f, 0.669925f, 0.081573f, 0.188857f, -0.172930f, 0.321477f, 0.009332f, -0.084341f, 0.362245f, -0.426671f, 0.758383f}, + { 0.855349f, 0.420736f, 0.413285f, -0.009366f, -0.399699f, 1.385802f, 0.012428f, -0.015338f, 0.156471f, 0.517438f, 0.160248f, -0.303634f, 0.477768f, -0.560747f, 1.382583f}, + { 0.202543f, 0.048819f, 0.263407f, 0.023538f, 0.092021f, 0.395655f, 0.013064f, -0.011127f, 0.035466f, 0.976055f, 0.009968f, 0.162957f, 0.383185f, -0.365493f, 2.534677f}, + { 1.393664f, -0.131401f, 0.989429f, 0.738330f, 0.683865f, 0.001677f, -0.225448f, -0.012158f, 1.084608f, -0.115464f, 0.022371f, -0.045560f, -0.336230f, 0.422742f, 0.499163f} +}; + +const int16_t dft_cng_coh_u2i[9] = { 4, 5, 3, 6, 2, 7, 1, 8, 0 }; /* Coherence unary codeword -> residual codeword conversion table */ + +const int16_t dft_cng_coh_i2u[9] = { 8, 6, 4, 2, 0, 1, 3, 5, 7 }; /* Coherence residual codeword -> unary codeword conversion table */ + +const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1] = { 15, 16, 17, 18 }; + +const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS] = +{ + { 0.1f, 0.6f }, + { 0.1f, 0.6f }, + { 0.1f, 0.7f }, + { 0.1f, 0.9f }, + { 0.2f, 0.9f } +}; + + +/*----------------------------------------------------------------------------------* + * DirAC ROM tables + *----------------------------------------------------------------------------------*/ + +const float diffuseness_reconstructions[DIRAC_DIFFUSE_LEVELS] = +{ + 0.0f, + 0.03955078125f, + 0.089599609375f, + 0.158935546875f, + 0.308349609375f, + 0.473876953125f, + 0.63232421875f, + 0.85009765625f +}; + +const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1] = +{ + 0.0f, + 0.01904296875f, + 0.06298828125f, + 0.119384765625f, + 0.22119140625f, + 0.399169921875f, + 0.547607421875f, + 0.734619140625f, + 2.0f /* out-of-range large value to make searching easier */ +}; + +const int16_t DirAC_band_grouping_12[12 + 1] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 11, 17, 25, 40, 60 +}; + + +const int16_t DirAC_band_grouping_6[6 + 1] = +{ + 0, 1, 4, 8, 20, 30, 60 +}; + +const int16_t DirAC_band_grouping_5[5 + 1] = +{ + 0, 1, 3, 7, 15, 60 +}; + +const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = +{ + 0, 4, 8, 12, 16 +}; + +const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = +{ + 0, 1, 2, 3, 4 +}; + + + +/*----------------------------------------------------------------------* +* SPAR ROM tables +*-----------------------------------------------------------------------*/ + +const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN] = +{ +/* When AGC is ON additional (AGC_BITS_PER_CH+1) bits may be taken from each EVS channel + so minimum EVS bitrate per channel can be min EVS bitrates as per the table - AGC_BITS_PER_CH */ + { 24400, 0, 1, FB, 24000, 1, WYXZ, 1, 0,{ { 16400, 15200, 24350 } }, + { { 15, 1, 5, 1 },{ 15, 1, 3, 1 },{ 7, 1, 3, 1 } }, 0, 0, 0 }, + + { 32000, 0, 1, FB, 24000, 1, WYXZ, 1, 0,{{ 24000, 20450, 31950 }},{ { 21, 1, 5, 1 },{ 15, 1, 5, 1 },{ 15, 1, 3, 1 } }, 0, 0, 0 }, + + { 48000, 0, 1, FB, 24000, 2, WYXZ, 0, 0,{ { 24000, 21000, 31950 },{ 16000, 15000, 20400 } }, + { { 15, 7, 5, 1 },{ 15, 7, 3, 1 },{ 7, 7, 3, 1 } }, 1, 0, 0 }, + + { 64000, 0, 1, FB, 24000, 2, WYXZ, 0, 0,{ { 38000, 34050, 56000 },{ 16000, 15600, 20400 } },{ { 21, 7, 5, 1 },{ 15, 7, 5, 1 },{ 15, 7, 3, 1 } }, 1, 1, 0 }, + + { 80000, 0, 1, FB, 24000, 2, WYXZ, 0, 0,{ { 46000, 43000, 56000 },{ 24000, 23000, 31950 } }, + { { 21, 7, 5, 1 },{ 15, 7, 5, 1 },{ 15, 7, 3, 1 } }, 1, 0, 0 }, + + { 96000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 47000, 42600, 56000 },{ 23000, 22600, 31950 },{ 16000, 15600, 20400 } }, + { { 21, 9, 9, 1 },{ 21, 7, 5, 1 },{ 21, 7, 5, 1 } }, 1, 0, 0 }, + + { 128000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 55000, 50000, 56000 },{ 36000, 36000, 56000 },{ 27000, 27000, 31950 } }, + { { 21, 11, 9, 1 },{ 21, 9, 7, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 }, + + { 160000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 74000, 70900, 112000 },{ 41000, 40050, 56000 },{ 35000, 34050, 56000 } }, + { { 21, 11, 11, 1 },{ 21, 9, 9, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 }, + + { 192000, 0, 1, FB, 24000, 3, WYXZ, 0, 0,{ { 90000, 87900, 112000 },{ 50000, 48050, 56000 },{ 42000, 41050, 56000 } }, + { { 21, 11, 11, 1 },{ 21, 9, 9, 1 },{ 21, 7, 7, 1 } }, 1, 0, 0 }, + + { 256000, 0, 1, FB, 24000, 4, WYXZ, 0, 0,{ { 90000, 85000, 112000 },{ 70000, 69000, 112000 },{ 50000, 48950, 56000 },{ 36400, 35600, 56000 } }, + { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + { 256000, 0, 2, FB, 24000, 4, WYXZ, 0, 0,{ { 84650, 83000, 112000 },{ 65850, 64550, 56000 },{ 47000, 46100, 48000 },{ 28200, 27650, 40000 } }, + { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + { 256000, 0, 3, FB, 24000, 4, WYXZ, 0, 0,{ { 76300, 73550, 112000 },{ 59350, 57200, 56000 },{ 42400, 40850, 48000 },{ 25450, 24500, 40000 } }, + { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 31, 1, 1, 1 } }, 1, 2, 0 }, + + { 384000, 0, 1, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 100000, 100000, 128000 },{ 79850, 79850, 104000 },{ 66600, 66600, 104000 } }, // not yet optimized + { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + { 384000, 0, 2, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 105350, 103300, 112000 },{ 75200, 73750, 96000 },{ 45100, 44250, 48000 } }, // just added as a place holder, not necessarily operational + { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + { 384000, 0, 3, FB, 24000, 4, WYXZ, 0, 0,{ { 124300, 121550, 128000 },{ 96700, 94550, 112000 },{ 69050, 67500, 96000 },{ 41450, 40500, 48000 } }, // just added as a place holder, not necessarily operational + { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + { 512000, 0, 1, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 }, {118450, 118450, 128000 } }, // not yet optimized + { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + { 512000, 0, 2, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 97700, 93300, 128000 } }, // not yet optimized + { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + { 512000, 0, 3, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 127200, 122550, 128000 },{ 76300, 73550, 128000 } }, // not yet optimized + { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, + + +}; + +#ifdef FIX_SBA_CLEAN_UP_OPT +const ivas_freq_models_t ivas_arith_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ARITH] = +{ + /* entry for 1 quantization points */ + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points for br_table_idx >= 2 */ + { + /* pred_R real */ + { + { 0,546,1092,2184,8740,2184,1092,546, }, + { 0,1779,2116,2516,3562,2516,2116,1779, }, + { 0,1848,2614,5229,2614,1848,1307,924, }, + { 0,924,1307,1848,2614,5229,2614,1848, }, + }, + /* pred_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* pred_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 15 quantization points for br_table_idx >= 2 */ + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 21 quantization points for br_table_idx >= 2 */ + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 31 quantization points */ + { + /* pred real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, } + }, + /* pred real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, } + }, + /* pred real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points for br_table_idx < 2 */ + { + /* pred_R real */ + { + { 0,327,778,1851,10472,1851,778,327, }, + { 0,1057,1630,2514,5982,2514,1630,1057, }, + { 0,1668,2572,6122,2572,1668,1081,701, }, + { 0,701,1081,1668,2572,6122,2572,1668, }, + }, + /* pred_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* pred_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 15 quantization points for br_table_idx < 2 */ + { + /* pred real */ + { + { 0,9,23,56,133,318,757,1800,10192,1800,757,318,133,56,23,9, }, + { 0,156,240,371,573,883,1363,2102,5008,2102,1363,883,573,371,240,156, }, + { 0,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241,156,101, }, + { 0,101,156,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241, } + }, + /* pred real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, } + }, + /* pred real : values for general and differential */ + {-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7}, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 21 quantization points for br_table_idx < 2 */ + { + /* pred_R real */ + { + { 0,1,1,4,9,23,56,133,318,756,1799,10184,1799,756,318,133,56,23,9,4,1,1, }, + { 0,41,64,98,152,234,362,558,861,1329,2049,4888,2049,1329,861,558,362,234,152,98,64,41, }, + { 0,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64,41,26, }, + { 0,26,41,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + } +}; + + const ivas_freq_models_t ivas_arith_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + { + /* drct real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct real : values for general and differential */ + {0},{ 0 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points */ + { /* drct real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 9 quantization points */ + { + /* drct real */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,573,722,909,1146,1444,1819,2292,2888,4591, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* drct real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, } + }, + /* drct real : values for general and differential */ + { -4,-3,-2,-1,0,1,2,3,4 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 11 quantization points */ + { + /* drct real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + } +}; + + const ivas_freq_models_t ivas_arith_decd_r_consts[TOTAL_DECD_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + { + /* decd real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd real : values for general and differential */ + { 0 },{ 0 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 3 quantization points */ + { + /* decd real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd real : values for general and differential */ + { 0,1,2 },{-1,0,1}, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 5 quantization points */ + { + /* decd real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points */ + { + /* decd real */ + { + { 0,10983,2744,1372,686,343,171,85, }, + { 0,6573,3285,2322,1642,1161,821,580, }, + { 0,1603,2020,2546,4046,2546,2020,1603, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* decd real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, } + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4,5,6 },{ -3,-2,-1,0,1,2,3 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 9 quantization points */ + { /* decd real */ + { + { 0,10941,2734,1367,683,341,170,85,42,21, }, + { 0,6305,3150,2227,1575,1113,787,556,393,278, }, + { 0,1101,1388,1749,2203,3502,2203,1749,1388,1101, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* decd real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, } + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 11 quantization points */ + { + /* decd real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + } +}; +#else +const ivas_arith_consts_t ivas_arith_consts[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS] = +{ + /* tbl_idx 0 -- 24.4kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,9,23,56,133,318,757,1800,10192,1800,757,318,133,56,23,9, }, + { 0,156,240,371,573,883,1363,2102,5008,2102,1363,883,573,371,240,156, }, + { 0,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241,156,101, }, + { 0,101,156,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,9,23,56,133,318,757,1800,10192,1800,757,318,133,56,23,9, }, + { 0,156,240,371,573,883,1363,2102,5008,2102,1363,883,573,371,240,156, }, + { 0,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241,156,101, }, + { 0,101,156,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd_R real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2 },{ -1,0,1 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,327,778,1851,10472,1851,778,327, }, + { 0,1057,1630,2514,5982,2514,1630,1057, }, + { 0,1668,2572,6122,2572,1668,1081,701, }, + { 0,701,1081,1668,2572,6122,2572,1668, }, + }, + /* pred_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* pred_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd_R real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2 },{ -1,0,1 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 1 -- 32kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,4,9,23,56,133,318,756,1799,10184,1799,756,318,133,56,23,9,4,1,1, }, + { 0,41,64,98,152,234,362,558,861,1329,2049,4888,2049,1329,861,558,362,234,152,98,64,41, }, + { 0,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64,41,26, }, + { 0,26,41,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,9,23,56,133,318,757,1800,10192,1800,757,318,133,56,23,9, }, + { 0,156,240,371,573,883,1363,2102,5008,2102,1363,883,573,371,240,156, }, + { 0,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241,156,101, }, + { 0,101,156,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,9,23,56,133,318,757,1800,10192,1800,757,318,133,56,23,9, }, + { 0,156,240,371,573,883,1363,2102,5008,2102,1363,883,573,371,240,156, }, + { 0,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241,156,101, }, + { 0,101,156,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd_R real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2 },{ -1,0,1 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 2 -- 48kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd_R real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2 },{ -1,0,1 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,546,1092,2184,8740,2184,1092,546, }, + { 0,1779,2116,2516,3562,2516,2116,1779, }, + { 0,1848,2614,5229,2614,1848,1307,924, }, + { 0,924,1307,1848,2614,5229,2614,1848, }, + }, + /* pred_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* pred_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd_R real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2 },{ -1,0,1 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 3 -- 64kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd_R real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2 },{ -1,0,1 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 4 -- 80kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd_R real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2 },{ -1,0,1 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 5 -- 96kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,573,722,909,1146,1444,1819,2292,2888,4591, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* drct_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* drct_R real : values for general and differential */ + { -4,-3,-2,-1,0,1,2,3,4 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10941,2734,1367,683,341,170,85,42,21, }, + { 0,6305,3150,2227,1575,1113,787,556,393,278, }, + { 0,1101,1388,1749,2203,3502,2203,1749,1388,1101, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* decd_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd_R real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 6 -- 128kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10941,2734,1367,683,341,170,85,42,21, }, + { 0,6305,3150,2227,1575,1113,787,556,393,278, }, + { 0,1101,1388,1749,2203,3502,2203,1749,1388,1101, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* decd_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,573,722,909,1146,1444,1819,2292,2888,4591, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* drct_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* drct_R real : values for general and differential */ + { -4,-3,-2,-1,0,1,2,3,4 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10983,2744,1372,686,343,171,85, }, + { 0,6573,3285,2322,1642,1161,821,580, }, + { 0,1603,2020,2546,4046,2546,2020,1603, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* decd_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6 },{ -3,-2,-1,0,1,2,3 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10983,2744,1372,686,343,171,85, }, + { 0,6573,3285,2322,1642,1161,821,580, }, + { 0,1603,2020,2546,4046,2546,2020,1603, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* decd_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6 },{ -3,-2,-1,0,1,2,3 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 7 -- 160kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,573,722,909,1146,1444,1819,2292,2888,4591, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* drct_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* drct_R real : values for general and differential */ + { -4,-3,-2,-1,0,1,2,3,4 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10941,2734,1367,683,341,170,85,42,21, }, + { 0,6305,3150,2227,1575,1113,787,556,393,278, }, + { 0,1101,1388,1749,2203,3502,2203,1749,1388,1101, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* decd_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10983,2744,1372,686,343,171,85, }, + { 0,6573,3285,2322,1642,1161,821,580, }, + { 0,1603,2020,2546,4046,2546,2020,1603, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* decd_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6 },{ -3,-2,-1,0,1,2,3 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 8 -- 192kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,573,722,909,1146,1444,1819,2292,2888,4591, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* drct_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* drct_R real : values for general and differential */ + { -4,-3,-2,-1,0,1,2,3,4 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10941,2734,1367,683,341,170,85,42,21, }, + { 0,6305,3150,2227,1575,1113,787,556,393,278, }, + { 0,1101,1388,1749,2203,3502,2203,1749,1388,1101, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* decd_R real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10983,2744,1372,686,343,171,85, }, + { 0,6573,3285,2322,1642,1161,821,580, }, + { 0,1603,2020,2546,4046,2546,2020,1603, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* decd_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6 },{ -3,-2,-1,0,1,2,3 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 9 -- 256kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 10 -- 256kbps HOA2 */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 11 -- 256kbps HOA3 */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 12 -- 384kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 13 -- 384kbps HOA2 */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 14 -- 384kbps HOA3 */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 15 -- 512kbps FOA */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 16 -- 512kbps HOA2 */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + /* tbl_idx 17 -- 512kbps HOA3 */ + { + /* Quant strat = 0 */ + { + { + /* pred_R real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, }, + }, + /* pred_R real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct_R real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd_R real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd_R real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 1 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + /* Quant strat = 2 */ + { + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* drct_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct_R real : values for general and differential */ + { 0 },{ 0 }, + /* drct_R real : num dyn models for general and differential */ + 4, 4 + }, + { + /* decd_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd_R real : values for general and differential */ + { 0 },{ 0 }, + /* decd_R real : num dyn models for general and differential */ + 4, 4 + }, + }, + }, + +}; +#endif + +#ifdef FIX_SBA_CLEAN_UP_OPT +const ivas_huff_models_t ivas_huff_pred_r_consts[TOTAL_PRED_QUANT_STRATS_HUFF] = +{ + /* entry for 1 quantization points for br_table_idx */ + {{{ 0 }}, {{ 0 }}}, + /* entry for 7 quantization points for br_table_idx */ + { + /* pred_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* pred_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + /* entry for 15 quantization points for br_table_idx */ + { + /* pred_r codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5, 4, 4 },{ -4, 4, 5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 }, + { 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 } }, + /* pred_r differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5, 4, 4 },{ -4, 4, 5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 }, + { 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 } }, + }, + /* entry for 21 quantization points for br_table_idx=0 */ + { + /* pred_r codebook */ + { {-10,5,22},{-9,5,23},{-8,5,24},{-7,5,25},{-6,5,26}, { -5, 4, 0 },{ -4, 4, 1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 }, + { 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{6,5,27},{7,5,28},{8,5,29},{9,5,30},{10,5,31} }, + /* pred_r differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5, 4, 0 },{ -4, 4, 1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 }, + { 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 } }, + }, + + /* entry for 31 quantization points for br_table_idx>0 */ + { + /* pred_r codebook */ + { {-15,5,2},{-14,5,3},{-13,5,4},{-12,5,5},{-11,5,6}, { -10,5,7 },{ -9,5,8 },{ -8,5,9 }, + { -7,5,10 },{ -6,5,11 },{ -5, 5, 12 },{ -4, 5, 13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 }, + { 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 }, + { 8,5,24 },{ 9,5,25 },{ 10,5,26 },{11,5,27},{12,5,28},{13,5,29},{14,5,30},{15,5,31} }, + /* pred_r differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 }, + { -7,5,10 },{ -6,5,11 },{ -5, 5, 12 },{ -4, 5, 13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 }, + { 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 }, + { 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 } }, + }, + }; + + const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + {{{ 0 }}, {{ 0 }}}, + /* entry for 7 quantization points */ + { + /* drct_r codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } }, + /* drct_r differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } }, + }, + /* entry for 9 quantization points */ + { + /* drct_r codebook */ + { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } }, + /* drct_r differential codebook */ + { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } }, + }, + /* entry for 11 quantization points */ + { + /* drct_r codebook */ + { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } }, + /* drct_r differential codebook */ + { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } }, + }, +}; + +const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + {{{ 0 }}, {{ 0 }}}, + /* entry for 3 quantization points */ + { + /* decd_r codebook */ + { { 0, 2, 2 },{ 1, 1, 0 },{ 2,2,3 } }, + /* decd_r differential codebook */ + { { -1, 2, 2 },{ 0, 1, 0 },{ 1,2,3 } }, + }, + /* entry for 5 quantization points */ + { + /* decd_r codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 } }, + /* decd_r differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 } }, + }, + /* entry for 7 quantization points */ + { + /* decd_r */ + { { 0, 3, 2 },{ 1, 3, 3 },{ 2,3,4 },{ 3,3,0 },{ 4,3,5 },{ 5,3,6 },{ 6,3,7 } }, + /* decd_r codebook differential codebook */ + { { -3, 3, 2 },{ -2, 3, 3 },{ -1,3,4 },{ 0,3,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } }, + }, + /* entry for 9 quantization points */ + { + /* decd_r codebook */ + { { 0, 4, 14 },{ 1,3,0 },{ 2,3,1 },{ 3,3,2 },{ 4,3,3 },{ 5,3,4 },{ 6,3,5 },{ 7,3,6 },{ 8,4,15 } }, + /* decd_r differential codebook */ + { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } }, + }, + /* entry for 11 quantization points */ + { + /* decd_r codebook */ + { { 0, 4, 10 },{ 1, 4, 11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 } }, + /* decd_r differential codebook */ + { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } }, + }, +}; +#else +const ivas_huff_consts_t ivas_huff_const[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS] = +{ + /* tbl_idx 0 -- 24.4kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + { + /* decd_R codebook */ + { { 0,2,2 },{ 1,1,0 },{ 2,2,3 }, }, + /* decd_R differential codebook */ + { { -1,2,2 },{ 0,1,0 },{ 1,2,3 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* pred_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + { + /* decd_R codebook */ + { { 0,2,2 },{ 1,1,0 },{ 2,2,3 }, }, + /* decd_R differential codebook */ + { { -1,2,2 },{ 0,1,0 },{ 1,2,3 }, }, + }, + }, + }, + /* tbl_idx 1 -- 32kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + { + /* decd_R codebook */ + { { 0,2,2 },{ 1,1,0 },{ 2,2,3 }, }, + /* decd_R differential codebook */ + { { -1,2,2 },{ 0,1,0 },{ 1,2,3 }, }, + }, + }, + }, + /* tbl_idx 2 -- 48kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,2,2 },{ 1,1,0 },{ 2,2,3 }, }, + /* decd_R differential codebook */ + { { -1,2,2 },{ 0,1,0 },{ 1,2,3 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* pred_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,2,2 },{ 1,1,0 },{ 2,2,3 }, }, + /* decd_R differential codebook */ + { { -1,2,2 },{ 0,1,0 },{ 1,2,3 }, }, + }, + }, + }, + /* tbl_idx 3 -- 64kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,2,2 },{ 1,1,0 },{ 2,2,3 }, }, + /* decd_R differential codebook */ + { { -1,2,2 },{ 0,1,0 },{ 1,2,3 }, }, + }, + }, + }, + /* tbl_idx 4 -- 80kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + /* pred_R differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5,4,4 },{ -4,4,5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 },{ 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,2,2 },{ 1,1,0 },{ 2,2,3 }, }, + /* decd_R differential codebook */ + { { -1,2,2 },{ 0,1,0 },{ 1,2,3 }, }, + }, + }, + }, + /* tbl_idx 5 -- 96kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + /* drct_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,14 },{ 1,3,0 },{ 2,3,1 },{ 3,3,2 },{ 4,3,3 },{ 5,3,4 },{ 6,3,5 },{ 7,3,6 },{ 8,4,15 }, }, + /* decd_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 }, }, + /* decd_R differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 }, }, + }, + }, + }, + /* tbl_idx 6 -- 128kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,14 },{ 1,3,0 },{ 2,3,1 },{ 3,3,2 },{ 4,3,3 },{ 5,3,4 },{ 6,3,5 },{ 7,3,6 },{ 8,4,15 }, }, + /* decd_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + /* drct_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,2,0 },{ 4,3,5 },{ 5,3,6 },{ 6,3,7 }, }, + /* decd_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,2,0 },{ 4,3,5 },{ 5,3,6 },{ 6,3,7 }, }, + /* decd_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + }, + }, + /* tbl_idx 7 -- 160kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + /* drct_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,14 },{ 1,3,0 },{ 2,3,1 },{ 3,3,2 },{ 4,3,3 },{ 5,3,4 },{ 6,3,5 },{ 7,3,6 },{ 8,4,15 }, }, + /* decd_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,2,0 },{ 4,3,5 },{ 5,3,6 },{ 6,3,7 }, }, + /* decd_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + }, + }, + /* tbl_idx 8 -- 192kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + /* drct_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,14 },{ 1,3,0 },{ 2,3,1 },{ 3,3,2 },{ 4,3,3 },{ 5,3,4 },{ 6,3,5 },{ 7,3,6 },{ 8,4,15 }, }, + /* decd_R differential codebook */ + { { -4,4,14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 }, }, + }, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + /* pred_R differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5,4,0 },{ -4,4,1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 },{ 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* drct_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + { + /* decd_R codebook */ + { { 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,2,0 },{ 4,3,5 },{ 5,3,6 },{ 6,3,7 }, }, + /* decd_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + }, + }, + /* tbl_idx 9 -- 256kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ +{ + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 10 -- 256kbps HOA2 */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 11 -- 256kbps HOA3 */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 12 -- 384kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 13 -- 384kbps HOA2 */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 14 -- 384kbps HOA3 */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 15 -- 512kbps FOA */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 1 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 16 -- 512kbps HOA2 */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, + /* tbl_idx 17 -- 512kbps HOA3 */ + { + /* Quant strat 0 */ + { + { + /* pred_R codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + /* pred_R differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 },{ -7,5,10 },{ -6,5,11 },{ -5,5,12 },{ -4,5,13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 },{ 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 },{ 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 }, }, + }, + { + /* drct_R codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + /* drct_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + { + /* decd_R codebook */ + { { 0,4,10 },{ 1,4,11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 }, }, + /* decd_R differential codebook */ + { { -5,4,10 },{ -4,4,11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 }, }, + }, + }, + /* Quant strat 1 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + /* Quant strat 2 */ + { + /* pred_R */ + {{{ 0 }}, {{ 0 }}}, + /* drct_R */ + {{{ 0 }}, {{ 0 }}}, + /* decd_R */ + {{{ 0 }}, {{ 0 }}}, + }, + }, +}; +#endif + +/* DTX quantization and bitstream constants */ + +const float dtx_pd_real_min_max[2] = { 0, 1.6f }; +const int16_t dtx_pd_real_q_levels[3][3] = { { 7,7,7 },{ 7,7,0 },{ 3,0,0 } }; +const int16_t dtx_pr_real_q_levels[3][3] = { { 9,9,9 },{ 9,7,9 },{ 9,5,7 } }; +const int16_t pr_pr_idx_pairs[3][3][2] = { { { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 1, 3 },{ 0, 0 } } }; +const int16_t pr_pd_idx_pairs[3][3][2] = { { { 1, 1 },{ 2, 2 },{ 3, 3 } },{ { 1, 1 },{ 3, 2 },{ 2, 0 } },{ { 2, 1 },{ 0, 0 },{ 0, 0 } } }; + +const int16_t remix_order_set[1][IVAS_SPAR_MAX_CH] = { /* WYZX --> WYXZ... */ + { 0, 1, 3, 2, 4, 5, 6, 7} +}; +const int16_t keep_planar[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS] = { 1, 1, 1, 1 }; +const int16_t HOA_keep_ind[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 8, 9, 15}; + + +/*----------------------------------------------------------------------* +* PCA ROM tables +*-----------------------------------------------------------------------*/ + +const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1] = +{ + 0, 1, 9, 61, 163, 359, 685, 1125, 1747, + 2519, 3521, 4713, 6183, 7883, 9809, 12093, 14633, 17575, + 20807, 24343, 28181, 32487, 37121, 42097, 47405, 53057, 59061, + 65421, 72137, 79205, 86625, 94415, 102345, 110629, 119263, 128017, + 137097, 146515, 156043, 165637, 175551, 185515, 195535, 205837, 216183, + 226545, 236911, 247273, 257619, 267921, 277941, 287905, 297819, 307413, + 316941, 326359, 335439, 344193, 352827, 361111, 369041, 376831, 384251, + 391319, 398035, 404395, 410399, 416051, 421359, 426335, 430969, 435275, + 439113, 442649, 445881, 448823, 451363, 453647, 455573, 457273, 458743, + 459935, 460937, 461709, 462331, 462771, 463097, 463293, 463395, 463447, + 463455, 463456 +}; + +const int16_t ivas_pca_offset_index2[2692] = +{ + 0, 1, 0, 1, 7, 8, 0, 1, 7, 19, + 33, 45, 51, 52, 0, 1, 9, 23, 41, 61, + 79, 93, 101, 102, 0, 1, 7, 21, 39, 61, + 85, 111, 135, 157, 175, 189, 195, 196, 0, 1, + 7, 19, 37, 59, 85, 115, 147, 179, 211, 241, + 267, 289, 307, 319, 325, 326, 0, 1, 7, 21, + 41, 65, 95, 127, 163, 201, 239, 277, 313, 345, + 375, 399, 419, 433, 439, 440, 0, 1, 7, 19, + 37, 61, 91, 125, 163, 203, 245, 289, 333, 377, + 419, 459, 497, 531, 561, 585, 603, 615, 621, 622, + 0, 1, 7, 21, 41, 67, 97, 133, 173, 217, + 263, 311, 361, 411, 461, 509, 555, 599, 639, 675, + 705, 731, 751, 765, 771, 772, 0, 1, 7, 19, + 37, 61, 91, 127, 167, 211, 259, 309, 363, 417, + 473, 529, 585, 639, 693, 743, 791, 835, 875, 911, + 941, 965, 983, 995, 1001, 1002, 0, 1, 7, 21, + 41, 67, 99, 135, 177, 223, 273, 327, 383, 443, + 503, 565, 627, 689, 749, 809, 865, 919, 969, 1015, + 1057, 1093, 1125, 1151, 1171, 1185, 1191, 1192, 0, 1, + 7, 19, 37, 61, 91, 127, 169, 215, 265, 319, + 377, 437, 501, 567, 633, 701, 769, 837, 903, 969, + 1033, 1093, 1151, 1205, 1255, 1301, 1343, 1379, 1409, 1433, + 1451, 1463, 1469, 1470, 0, 1, 7, 21, 41, 67, + 99, 137, 179, 227, 279, 335, 395, 459, 525, 595, + 667, 739, 813, 887, 961, 1033, 1105, 1175, 1241, 1305, + 1365, 1421, 1473, 1521, 1563, 1601, 1633, 1659, 1679, 1693, + 1699, 1700, 0, 1, 9, 23, 43, 69, 101, 139, + 183, 231, 285, 343, 405, 471, 541, 613, 689, 765, + 843, 923, 1003, 1083, 1161, 1237, 1313, 1385, 1455, 1521, + 1583, 1641, 1695, 1743, 1787, 1825, 1857, 1883, 1903, 1917, + 1925, 1926, 0, 1, 7, 21, 41, 67, 99, 137, + 179, 227, 281, 339, 401, 467, 537, 611, 687, 767, + 849, 931, 1015, 1099, 1185, 1269, 1353, 1435, 1517, 1597, + 1673, 1747, 1817, 1883, 1945, 2003, 2057, 2105, 2147, 2185, + 2217, 2243, 2263, 2277, 2283, 2284, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 285, 345, 409, 477, + 549, 625, 705, 787, 871, 957, 1045, 1135, 1225, 1315, + 1405, 1495, 1583, 1669, 1753, 1835, 1915, 1991, 2063, 2131, + 2195, 2255, 2309, 2359, 2403, 2441, 2473, 2499, 2519, 2533, + 2539, 2540, 0, 1, 7, 19, 39, 65, 97, 135, + 177, 225, 279, 337, 401, 469, 541, 617, 697, 781, + 867, 955, 1045, 1137, 1231, 1327, 1423, 1519, 1615, 1711, + 1805, 1897, 1987, 2075, 2161, 2245, 2325, 2401, 2473, 2541, + 2605, 2663, 2717, 2765, 2807, 2845, 2877, 2903, 2923, 2935, + 2941, 2942, 0, 1, 7, 21, 41, 67, 99, 137, + 181, 229, 283, 343, 407, 477, 551, 629, 711, 797, + 885, 977, 1071, 1167, 1265, 1365, 1465, 1565, 1667, 1767, + 1867, 1967, 2065, 2161, 2255, 2347, 2435, 2521, 2603, 2681, + 2755, 2825, 2889, 2949, 3003, 3051, 3095, 3133, 3165, 3191, + 3211, 3225, 3231, 3232, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 347, 413, 483, 559, 639, + 723, 811, 903, 997, 1093, 1193, 1295, 1399, 1503, 1609, + 1715, 1821, 1927, 2033, 2137, 2241, 2343, 2443, 2539, 2633, + 2725, 2813, 2897, 2977, 3053, 3123, 3189, 3249, 3305, 3355, + 3399, 3437, 3469, 3495, 3515, 3529, 3535, 3536, 0, 1, + 7, 21, 41, 67, 99, 137, 181, 231, 287, 349, + 415, 487, 563, 645, 731, 821, 915, 1011, 1111, 1213, + 1317, 1423, 1531, 1641, 1751, 1863, 1975, 2087, 2197, 2307, + 2415, 2521, 2625, 2727, 2827, 2923, 3017, 3107, 3193, 3275, + 3351, 3423, 3489, 3551, 3607, 3657, 3701, 3739, 3771, 3797, + 3817, 3831, 3837, 3838, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 285, 345, 411, 481, 557, 637, + 721, 809, 901, 997, 1097, 1199, 1305, 1413, 1523, 1635, + 1749, 1863, 1979, 2095, 2211, 2327, 2443, 2557, 2671, 2783, + 2893, 3001, 3107, 3209, 3309, 3405, 3497, 3585, 3669, 3749, + 3825, 3895, 3961, 4021, 4075, 4125, 4169, 4207, 4239, 4265, + 4285, 4299, 4305, 4306, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 347, 413, 485, 561, 643, + 729, 819, 913, 1011, 1113, 1217, 1325, 1435, 1547, 1663, + 1779, 1897, 2017, 2137, 2257, 2377, 2497, 2617, 2737, 2855, + 2971, 3087, 3199, 3309, 3417, 3521, 3623, 3721, 3815, 3905, + 3991, 4073, 4149, 4221, 4287, 4347, 4403, 4453, 4497, 4535, + 4567, 4593, 4613, 4627, 4633, 4634, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 287, 349, 415, 487, + 565, 647, 733, 825, 921, 1021, 1125, 1231, 1341, 1453, + 1569, 1687, 1807, 1929, 2051, 2175, 2299, 2425, 2551, 2677, + 2801, 2925, 3047, 3169, 3289, 3407, 3523, 3635, 3745, 3851, + 3955, 4055, 4151, 4243, 4329, 4411, 4489, 4561, 4627, 4689, + 4745, 4795, 4839, 4877, 4909, 4935, 4955, 4969, 4975, 4976, + 0, 1, 7, 21, 41, 67, 99, 137, 181, 231, + 287, 349, 417, 489, 567, 649, 737, 829, 925, 1025, + 1129, 1237, 1349, 1463, 1581, 1701, 1823, 1947, 2073, 2201, + 2329, 2459, 2589, 2719, 2849, 2979, 3107, 3235, 3361, 3485, + 3607, 3727, 3845, 3959, 4071, 4179, 4283, 4383, 4479, 4571, + 4659, 4741, 4819, 4891, 4959, 5021, 5077, 5127, 5171, 5209, + 5241, 5267, 5287, 5301, 5307, 5308, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 287, 349, 417, 489, + 567, 651, 739, 831, 929, 1031, 1137, 1247, 1361, 1477, + 1597, 1719, 1843, 1969, 2097, 2227, 2359, 2491, 2625, 2759, + 2893, 3027, 3161, 3293, 3425, 3555, 3683, 3809, 3933, 4055, + 4175, 4291, 4405, 4515, 4621, 4723, 4821, 4913, 5001, 5085, + 5163, 5235, 5303, 5365, 5421, 5471, 5515, 5553, 5585, 5611, + 5631, 5645, 5651, 5652, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 569, 653, + 741, 835, 933, 1035, 1141, 1251, 1365, 1483, 1603, 1727, + 1853, 1983, 2115, 2249, 2383, 2519, 2657, 2795, 2933, 3071, + 3209, 3347, 3485, 3621, 3755, 3889, 4021, 4151, 4277, 4401, + 4521, 4639, 4753, 4863, 4969, 5071, 5169, 5263, 5351, 5435, + 5513, 5587, 5655, 5717, 5773, 5823, 5867, 5905, 5937, 5963, + 5983, 5997, 6003, 6004, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 569, 653, + 741, 835, 933, 1037, 1145, 1257, 1373, 1491, 1613, 1739, + 1867, 1997, 2131, 2267, 2405, 2543, 2683, 2825, 2967, 3109, + 3251, 3393, 3535, 3677, 3817, 3955, 4093, 4229, 4363, 4493, + 4621, 4747, 4869, 4987, 5103, 5215, 5323, 5427, 5525, 5619, + 5707, 5791, 5869, 5943, 6011, 6073, 6129, 6179, 6223, 6261, + 6293, 6319, 6339, 6353, 6359, 6360, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 287, 349, 417, 491, + 569, 653, 743, 837, 935, 1039, 1147, 1259, 1375, 1495, + 1619, 1745, 1875, 2007, 2143, 2281, 2421, 2563, 2705, 2849, + 2993, 3139, 3285, 3431, 3577, 3723, 3867, 4011, 4153, 4295, + 4435, 4573, 4709, 4841, 4971, 5097, 5221, 5341, 5457, 5569, + 5677, 5781, 5879, 5973, 6063, 6147, 6225, 6299, 6367, 6429, + 6485, 6535, 6579, 6617, 6649, 6675, 6695, 6709, 6715, 6716, + 0, 1, 7, 21, 41, 67, 99, 137, 181, 231, + 287, 349, 417, 491, 569, 653, 743, 837, 937, 1041, + 1149, 1261, 1377, 1497, 1621, 1749, 1879, 2013, 2149, 2287, + 2429, 2573, 2717, 2863, 3011, 3159, 3309, 3459, 3609, 3759, + 3909, 4057, 4205, 4351, 4495, 4639, 4781, 4919, 5055, 5189, + 5319, 5447, 5571, 5691, 5807, 5919, 6027, 6131, 6231, 6325, + 6415, 6499, 6577, 6651, 6719, 6781, 6837, 6887, 6931, 6969, + 7001, 7027, 7047, 7061, 7067, 7068, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 287, 349, 417, 491, + 569, 653, 743, 837, 937, 1041, 1149, 1261, 1377, 1497, + 1621, 1749, 1881, 2015, 2153, 2293, 2435, 2579, 2725, 2873, + 3023, 3175, 3327, 3479, 3633, 3787, 3941, 4093, 4245, 4397, + 4547, 4695, 4841, 4985, 5127, 5267, 5405, 5539, 5671, 5799, + 5923, 6043, 6159, 6271, 6379, 6483, 6583, 6677, 6767, 6851, + 6929, 7003, 7071, 7133, 7189, 7239, 7283, 7321, 7353, 7379, + 7399, 7413, 7419, 7420, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 489, 567, 651, + 741, 835, 935, 1039, 1147, 1259, 1377, 1499, 1625, 1753, + 1885, 2021, 2159, 2301, 2445, 2591, 2739, 2889, 3041, 3195, + 3349, 3505, 3661, 3817, 3973, 4129, 4285, 4441, 4595, 4749, + 4901, 5051, 5199, 5345, 5489, 5631, 5769, 5905, 6037, 6165, + 6291, 6413, 6531, 6643, 6751, 6855, 6955, 7049, 7139, 7223, + 7301, 7373, 7441, 7503, 7559, 7609, 7653, 7691, 7723, 7749, + 7769, 7783, 7789, 7790, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 571, 657, + 747, 843, 945, 1051, 1161, 1277, 1397, 1521, 1649, 1781, + 1915, 2053, 2195, 2339, 2485, 2635, 2787, 2941, 3095, 3251, + 3409, 3567, 3725, 3885, 4045, 4205, 4363, 4521, 4679, 4835, + 4989, 5143, 5295, 5445, 5591, 5735, 5877, 6015, 6149, 6281, + 6409, 6533, 6653, 6769, 6879, 6985, 7087, 7183, 7273, 7359, + 7439, 7513, 7581, 7643, 7699, 7749, 7793, 7831, 7863, 7889, + 7909, 7923, 7929, 7930, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 571, 657, + 747, 843, 943, 1049, 1159, 1273, 1393, 1517, 1645, 1777, + 1913, 2051, 2193, 2337, 2485, 2635, 2787, 2941, 3097, 3255, + 3415, 3575, 3737, 3899, 4061, 4223, 4385, 4547, 4709, 4869, + 5029, 5187, 5343, 5497, 5649, 5799, 5947, 6091, 6233, 6371, + 6507, 6639, 6767, 6891, 7011, 7125, 7235, 7341, 7441, 7537, + 7627, 7713, 7793, 7867, 7935, 7997, 8053, 8103, 8147, 8185, + 8217, 8243, 8263, 8277, 8283, 8284, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 287, 349, 417, 491, + 571, 655, 745, 841, 941, 1047, 1157, 1271, 1389, 1513, + 1641, 1773, 1907, 2045, 2187, 2331, 2479, 2629, 2783, 2939, + 3097, 3257, 3417, 3579, 3743, 3907, 4071, 4235, 4399, 4563, + 4727, 4891, 5055, 5217, 5377, 5537, 5695, 5851, 6005, 6155, + 6303, 6447, 6589, 6727, 6861, 6993, 7121, 7245, 7363, 7477, + 7587, 7693, 7793, 7889, 7979, 8063, 8143, 8217, 8285, 8347, + 8403, 8453, 8497, 8535, 8567, 8593, 8613, 8627, 8633, 8634, + 0, 1, 7, 21, 41, 67, 99, 137, 181, 231, + 287, 349, 417, 491, 571, 657, 749, 845, 947, 1053, + 1165, 1281, 1401, 1527, 1657, 1791, 1929, 2069, 2213, 2361, + 2511, 2663, 2819, 2977, 3137, 3299, 3463, 3627, 3793, 3959, + 4125, 4293, 4461, 4629, 4795, 4961, 5127, 5291, 5455, 5617, + 5777, 5935, 6091, 6243, 6393, 6541, 6685, 6825, 6963, 7097, + 7227, 7353, 7473, 7589, 7701, 7807, 7909, 8005, 8097, 8183, + 8263, 8337, 8405, 8467, 8523, 8573, 8617, 8655, 8687, 8713, + 8733, 8747, 8753, 8754, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 571, 657, + 747, 843, 943, 1049, 1159, 1275, 1395, 1519, 1647, 1779, + 1915, 2055, 2199, 2345, 2495, 2647, 2803, 2961, 3121, 3283, + 3447, 3613, 3779, 3947, 4115, 4285, 4455, 4625, 4795, 4965, + 5133, 5301, 5467, 5633, 5797, 5959, 6119, 6277, 6433, 6585, + 6735, 6881, 7025, 7165, 7301, 7433, 7561, 7685, 7805, 7921, + 8031, 8137, 8237, 8333, 8423, 8509, 8589, 8663, 8731, 8793, + 8849, 8899, 8943, 8981, 9013, 9039, 9059, 9073, 9079, 9080, + 0, 1, 7, 19, 39, 65, 97, 135, 179, 229, + 285, 347, 415, 489, 567, 651, 741, 835, 935, 1041, + 1151, 1265, 1385, 1509, 1637, 1769, 1905, 2045, 2189, 2335, + 2485, 2637, 2793, 2951, 3111, 3273, 3437, 3603, 3771, 3939, + 4109, 4279, 4451, 4623, 4795, 4967, 5139, 5309, 5479, 5647, + 5815, 5981, 6145, 6307, 6467, 6625, 6781, 6933, 7083, 7229, + 7373, 7513, 7649, 7781, 7909, 8033, 8153, 8267, 8377, 8483, + 8583, 8677, 8767, 8851, 8929, 9003, 9071, 9133, 9189, 9239, + 9283, 9321, 9353, 9379, 9399, 9411, 9417, 9418, 0, 1, + 7, 21, 41, 67, 99, 137, 181, 231, 287, 349, + 417, 491, 571, 657, 747, 843, 945, 1051, 1163, 1279, + 1399, 1525, 1655, 1789, 1927, 2069, 2213, 2361, 2513, 2667, + 2825, 2985, 3147, 3311, 3477, 3645, 3815, 3985, 4157, 4329, + 4503, 4677, 4851, 5025, 5199, 5371, 5543, 5713, 5883, 6051, + 6217, 6381, 6543, 6703, 6861, 7015, 7167, 7315, 7459, 7601, + 7739, 7873, 8003, 8129, 8249, 8365, 8477, 8583, 8685, 8781, + 8871, 8957, 9037, 9111, 9179, 9241, 9297, 9347, 9391, 9429, + 9461, 9487, 9507, 9521, 9527, 9528, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 287, 349, 417, 491, + 571, 657, 749, 845, 947, 1055, 1167, 1285, 1407, 1533, + 1663, 1797, 1935, 2077, 2223, 2373, 2525, 2681, 2839, 3001, + 3165, 3331, 3499, 3669, 3839, 4011, 4185, 4359, 4533, 4709, + 4885, 5061, 5235, 5409, 5583, 5755, 5925, 6095, 6263, 6429, + 6593, 6755, 6913, 7069, 7221, 7371, 7517, 7659, 7797, 7931, + 8061, 8187, 8309, 8427, 8539, 8647, 8749, 8845, 8937, 9023, + 9103, 9177, 9245, 9307, 9363, 9413, 9457, 9495, 9527, 9553, + 9573, 9587, 9593, 9594, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 571, 655, + 745, 841, 941, 1047, 1157, 1273, 1393, 1517, 1647, 1781, + 1919, 2061, 2207, 2355, 2507, 2663, 2821, 2981, 3145, 3311, + 3479, 3649, 3821, 3993, 4167, 4341, 4517, 4693, 4869, 5045, + 5221, 5397, 5573, 5747, 5921, 6093, 6265, 6435, 6603, 6769, + 6933, 7093, 7251, 7407, 7559, 7707, 7853, 7995, 8133, 8267, + 8397, 8521, 8641, 8757, 8867, 8973, 9073, 9169, 9259, 9343, + 9423, 9497, 9565, 9627, 9683, 9733, 9777, 9815, 9847, 9873, + 9893, 9907, 9913, 9914, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 571, 657, + 747, 843, 945, 1051, 1163, 1279, 1401, 1527, 1657, 1791, + 1929, 2071, 2217, 2367, 2519, 2675, 2835, 2997, 3161, 3327, + 3495, 3665, 3837, 4011, 4185, 4361, 4537, 4715, 4893, 5071, + 5249, 5427, 5603, 5779, 5953, 6127, 6299, 6469, 6637, 6803, + 6967, 7129, 7289, 7445, 7597, 7747, 7893, 8035, 8173, 8307, + 8437, 8563, 8685, 8801, 8913, 9019, 9121, 9217, 9307, 9393, + 9473, 9547, 9615, 9677, 9733, 9783, 9827, 9865, 9897, 9923, + 9943, 9957, 9963, 9964, 0, 1, 7, 21, 41, 67, + 99, 137, 181, 231, 287, 349, 417, 491, 571, 657, + 749, 845, 947, 1055, 1167, 1285, 1407, 1533, 1663, 1799, + 1939, 2083, 2229, 2379, 2533, 2689, 2849, 3011, 3177, 3345, + 3515, 3687, 3861, 4035, 4211, 4387, 4565, 4743, 4921, 5099, + 5277, 5455, 5633, 5809, 5985, 6159, 6333, 6505, 6675, 6843, + 7009, 7171, 7331, 7487, 7641, 7791, 7937, 8081, 8221, 8357, + 8487, 8613, 8735, 8853, 8965, 9073, 9175, 9271, 9363, 9449, + 9529, 9603, 9671, 9733, 9789, 9839, 9883, 9921, 9953, 9979, + 9999, 10013, 10019, 10020, 0, 1, 7, 19, 39, 65, + 97, 135, 179, 229, 285, 347, 415, 489, 567, 651, + 741, 837, 937, 1043, 1153, 1269, 1389, 1513, 1643, 1777, + 1915, 2057, 2203, 2351, 2503, 2659, 2817, 2979, 3143, 3309, + 3477, 3647, 3819, 3993, 4169, 4345, 4523, 4701, 4881, 5061, + 5241, 5421, 5601, 5779, 5957, 6133, 6309, 6483, 6655, 6825, + 6993, 7159, 7323, 7485, 7643, 7799, 7951, 8099, 8245, 8387, + 8525, 8659, 8789, 8913, 9033, 9149, 9259, 9365, 9465, 9561, + 9651, 9735, 9813, 9887, 9955, 10017, 10073, 10123, 10167, 10205, + 10237, 10263, 10283, 10295, 10301, 10302, 0, 1, 7, 21, + 41, 67, 99, 137, 181, 231, 287, 349, 417, 491, + 571, 655, 745, 841, 941, 1047, 1159, 1275, 1395, 1521, + 1651, 1785, 1923, 2065, 2211, 2361, 2513, 2669, 2829, 2991, + 3155, 3321, 3491, 3663, 3837, 4011, 4187, 4365, 4543, 4723, + 4903, 5083, 5263, 5443, 5623, 5803, 5981, 6159, 6335, 6509, + 6683, 6855, 7025, 7191, 7355, 7517, 7677, 7833, 7985, 8135, + 8281, 8423, 8561, 8695, 8825, 8951, 9071, 9187, 9299, 9405, + 9505, 9601, 9691, 9775, 9855, 9929, 9997, 10059, 10115, 10165, + 10209, 10247, 10279, 10305, 10325, 10339, 10345, 10346, 0, 1, + 7, 21, 41, 67, 99, 137, 181, 231, 287, 349, + 417, 491, 571, 655, 745, 841, 943, 1049, 1161, 1277, + 1397, 1523, 1653, 1787, 1925, 2067, 2213, 2363, 2517, 2673, + 2833, 2995, 3159, 3327, 3497, 3669, 3843, 4019, 4195, 4373, + 4551, 4731, 4911, 5091, 5271, 5451, 5631, 5811, 5989, 6167, + 6343, 6519, 6693, 6865, 7035, 7203, 7367, 7529, 7689, 7845, + 7999, 8149, 8295, 8437, 8575, 8709, 8839, 8965, 9085, 9201, + 9313, 9419, 9521, 9617, 9707, 9791, 9871, 9945, 10013, 10075, + 10131, 10181, 10225, 10263, 10295, 10321, 10341, 10355, 10361, 10362, + 0, 1, 7, 21, 41, 67, 99, 137, 181, 231, + 287, 349, 417, 491, 571, 657, 747, 843, 945, 1051, + 1163, 1279, 1399, 1525, 1655, 1789, 1927, 2069, 2215, 2365, + 2519, 2675, 2835, 2997, 3161, 3329, 3499, 3671, 3845, 4021, + 4197, 4375, 4553, 4733, 4913, 5093, 5273, 5453, 5633, 5813, + 5991, 6169, 6345, 6521, 6695, 6867, 7037, 7205, 7369, 7531, + 7691, 7847, 8001, 8151, 8297, 8439, 8577, 8711, 8841, 8967, + 9087, 9203, 9315, 9421, 9523, 9619, 9709, 9795, 9875, 9949, + 10017, 10079, 10135, 10185, 10229, 10267, 10299, 10325, 10345, 10359, + 10365, 10366 +}; + +const int16_t ivas_pca_offset_n2[IVAS_PCA_N1] = +{ + 0, 2, 6, 14, 24, 38, 56, 76, 100, 126, 156, 188, + 224, 262, 302, 346, 392, 442, 494, 548, 604, 664, 726, 790, + 856, 924, 994, 1066, 1140, 1216, 1294, 1374, 1454, 1536, 1620, 1704, + 1790, 1878, 1966, 2054, 2144, 2234, 2324, 2416, 2508, 2600, 2692, 2784, + 2876, 2968, 3058, 3148, 3238, 3326, 3414, 3502, 3588, 3672, 3756, 3838, + 3918, 3998, 4076, 4152, 4226, 4298, 4368, 4436, 4502, 4566, 4628, 4688, + 4744, 4798, 4850, 4900, 4946, 4990, 5030, 5068, 5104, 5136, 5166, 5192, + 5216, 5236, 5254, 5268, 5278, 5286, 5290 +}; + + +/*----------------------------------------------------------------------------------* + * Parametric MC ROM tables + *----------------------------------------------------------------------------------*/ + +const int16_t param_mc_band_grouping_20[20 + 1] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 23, 27, 33, 40, 52, 60 +}; + +const int16_t param_mc_coding_band_mapping_20[20] = +{ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +const int16_t param_mc_bands_coded_20[4] = +{ + 10, 14, 18, 20 +}; + +const int16_t param_mc_band_grouping_14[14 + 1] = +{ + 0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 28, 40, 60 +}; + + +const int16_t param_mc_coding_band_mapping_14[14] = +{ + 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 +}; + +const int16_t param_mc_bands_coded_14[4] = +{ + 8, 11, 13, 14 +}; + +const int16_t param_mc_band_grouping_10[10 + 1] = +{ + 0, 1, 2, 3, 5, 7, 10, 14, 20, 40, 60 +}; + + +const int16_t param_mc_bands_coded_10[4] = +{ + 6, 8, 9, 10 +}; + +const int16_t param_mc_coding_band_mapping_10[10] = +{ + 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 +}; + +const int16_t Param_MC_index[MAX_CICP_CHANNELS] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +}; + +const float ivas_param_mc_dmx_fac_CICP6_2tc[12] = +{ + 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, /*Lt*/ + 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f /*Rt*/ +}; + +const float ivas_param_mc_dmx_fac_CICP12_2tc[16] = +{ + 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/ + 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f, 0.0f, 1.0f /*Rt*/ +}; + +const float ivas_param_mc_dmx_fac_CICP12_3tc[24] = +{ + 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/ + 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/ + 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f /*Ct*/ +}; + +const float ivas_param_mc_dmx_fac_CICP14_2tc[16] = +{ + 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/ + 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f, 0.0f, 1.0f /*Rt*/ +}; +const float ivas_param_mc_dmx_fac_CICP14_3tc[24] = +{ + 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/ + 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/ + 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, /*Ct*/ +}; + +const float ivas_param_mc_dmx_fac_CICP16_3tc[30] = +{ + 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/ + 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/ + 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f /*Ct*/ +}; + +const float ivas_param_mc_dmx_fac_CICP19_3tc[36] = +{ + 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lt*/ + 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rt*/ + 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f /*Ct*/ +}; + +const float ivas_param_mc_dmx_fac_CICP19_4tc[48] = +{ + 1.0f, 0.0f, INV_SQRT2, INV_SQRT2, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, /*Lht*/ + 0.0f, 1.0f, INV_SQRT2, INV_SQRT2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, /*Rht*/ + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, /*Lut*/ + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, /*Rut*/ +}; + +/* Coefficient for Parametric MC ILD factorization */ +const float ivas_param_mc_ild_fac_CICP6_2tc[6] = +{ + 0.391608498887651f, + 0.391608498887651f, + 0.208150823035836f, + 0.323713613305539f, + 0.323713613305539f, + 0.208150823035836f, +}; + +const float ivas_param_mc_ild_fac_CICP12_2tc[8] = +{ + 0.365151211522008f, + 0.365151211522008f, + 0.208008958987949f, + 0.209863469733018f, + 0.209863469733018f, + 0.171473949468979f, + 0.171473949468979f, + 0.208008958987949f +}; + +const float ivas_param_mc_ild_fac_CICP12_3tc[8] = +{ + 0.5f, + 0.5f, + 0.29f, + 0.29f, + 0.2f, + 0.2f, + 1.0f, + 0.25f +}; + +const float ivas_param_mc_ild_fac_CICP14_2tc[8] = +{ + 0.36427054f, + 0.36427054f, + 0.18290930f, + 0.21193730f, + 0.21193730f, + 0.24564756f, + 0.24564756f, + 0.20800895f +}; + +const float ivas_param_mc_ild_fac_CICP14_3tc[8] = +{ + 0.49716263f, + 0.49716263f, + 0.25198298f, + 0.25198298f, + 0.29498283f, + 0.29498283f, + 1.0f, + 0.25f +}; + +const float ivas_param_mc_ild_fac_CICP16_3tc[10] = +{ + 0.34f, + 0.34f, + 0.22f, + 0.22f, + 0.20f, + 0.20f, + 0.18f, + 0.18f, + 1.0f, + 0.25f, +}; + +const float ivas_param_mc_ild_fac_CICP19_3tc[12] = +{ + 0.3f, + 0.3f, + 0.17f, + 0.17f, + 0.12f, + 0.12f, + 0.19f, + 0.19f, + 0.19f, + 0.19f, + 1.0f, + 0.5f +}; + +const float ivas_param_mc_ild_fac_CICP19_4tc[12] = +{ + 0.35f, + 0.35f, + 0.17f, + 0.22f, + 0.2f, + 0.2f, + 0.2f, + 0.5f, + 0.5f, + 0.5f, + 0.5f, + 0.2f, +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP6_2tc = +{ + 5, + 6, + {0,1,2,4,5,3}, + {1,1,2,1,1,2}, + {{0},{1},{0,1},{0},{1},{0,1}} +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP12_2tc = +{ + 7, + 8, + {0,1,2,4,5,6,7,3}, + {1,1,2,1,1,1,1,2}, + {{0},{1},{0,1},{0},{1},{0},{1},{0,1}} +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP12_3tc = +{ + 6, + 8, + {0,1,4,5,6,7,2,3}, + {1,1,1,1,1,1,1,1}, + {{0},{1},{0},{1},{0},{1},{2},{2}} +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP14_2tc = +{ + 7, + 8, + {0,1,2,4,5,6,7,3}, + {1,1,2,1,1,1,1,2}, + {{0},{1},{0,1},{0},{1},{0},{1},{0,1}} +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP14_3tc = +{ + 6, + 8, + {0,1,4,5,6,7,2,3}, + {1,1,1,1,1,1,1,1}, + {{0},{1},{0},{1},{0},{1},{2},{2}} +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP16_3tc = +{ + 8, + 10, + {0,1,4,5,6,7,8,9,2,3}, + {1,1,1,1,1,1,1,1,1,1}, + {{0},{1},{0},{1},{0},{1},{0},{1},{2},{2}} +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP19_3tc = +{ + 10, + 12, + {0,1,4,5,6,7,8,9,10,11,2,3}, + {1,1,1,1,1,1,1,1,1,1,1,1}, + {{0},{1},{0},{1},{0},{1},{0},{1},{0},{1},{2},{2}} +}; + +const PARAM_MC_ILD_MAPPING ivas_param_mc_ild_mapping_CICP19_4tc = +{ + 11, + 12, + {0,1,2,4,5,6,7,8,9,10,11,3}, + {1,1,2,1,1,1,1,1,1,1,1,2}, + {{0},{1},{0,1},{0},{1},{0},{1},{2},{3},{2},{3},{0,1}} +}; + +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP6_2tc = +{ + 4, + 5, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 2, 3 }} /* C/LFE */ +}; + +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP12_2tc = +{ + 6, + 7, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 2, 6 }, /* C/BLS */ + { 2, 7 }, /* C/BRS */ + { 2, 3 } /* C/LFE */ + } +}; + +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP12_3tc = +{ + 6, + 7, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 0, 6 }, /* L/BLS */ + { 1, 7 }, /* R/BRS */ + { 2, 3 } /* C/LFE */ + } +}; + +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP14_2tc = +{ + 6, + 7, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 2, 6 }, /* C/UFL */ + { 2, 7 }, /* C/UFR */ + { 2, 3 } /* C/LFE */ + } +}; +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP14_3tc = +{ + 6, + 7, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 0, 6 }, /* L/UFL */ + { 1, 7 }, /* R/UFR */ + { 2, 3 } /* C/LFE */ + } +}; + +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP16_3tc = +{ + 8, + 9, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 0, 6 }, /* L/UFL */ + { 1, 7 }, /* R/UFR */ + { 4, 8 }, /* LS/UBL */ + { 5, 9 }, /* RS/UBR */ + { 2, 3 } /* C/LFE */ + } +}; + +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP19_3tc = +{ + 10, + 11, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 0, 6 }, /* L/LBS */ + { 1, 7 }, /* R/RBS */ + { 0, 8 }, /* L/UFL */ + { 1, 9 }, /* R/UFR */ + { 6, 10 }, /* LBS/UBL */ + { 7, 11 }, /* RBS/UBR */ + { 2, 3 } /* C/LFE */ + } +}; + +const PARAM_MC_ICC_MAPPING ivas_param_mc_icc_mapping_CICP19_4tc = +{ + 8, + 9, + { { 0, 4 }, /* L/LS */ + { 1, 5 }, /* R/RS */ + { 0, 2 }, /* L/C */ + { 1, 2 }, /* R/C */ + { 0, 6 }, /* L/LBS */ + { 1, 7 }, /* R/RBS */ + { 8, 10 }, /*UFL/UBL */ + { 9, 11 }, /*UFR/UBR */ + { 2, 3 } /* C/LFE */ + } +}; + +const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = +{ + /* CICP6 48000 */ + { + MC_LS_SETUP_5_1, + 6, + 2, + IVAS_48k, + &ivas_param_mc_ild_mapping_CICP6_2tc, + &ivas_param_mc_icc_mapping_CICP6_2tc, + &ivas_param_mc_dmx_fac_CICP6_2tc[0], + &ivas_param_mc_ild_fac_CICP6_2tc[0] + }, + /* CICP6 64000 */ + { + MC_LS_SETUP_5_1, + 6, + 2, + IVAS_64k, + &ivas_param_mc_ild_mapping_CICP6_2tc, + &ivas_param_mc_icc_mapping_CICP6_2tc, + &ivas_param_mc_dmx_fac_CICP6_2tc[0], + &ivas_param_mc_ild_fac_CICP6_2tc[0] + }, + /* CICP6 80000 */ + { + MC_LS_SETUP_5_1, + 6, + 2, + IVAS_80k, + &ivas_param_mc_ild_mapping_CICP6_2tc, + &ivas_param_mc_icc_mapping_CICP6_2tc, + &ivas_param_mc_dmx_fac_CICP6_2tc[0], + &ivas_param_mc_ild_fac_CICP6_2tc[0] + }, + /* CICP12 48000 */ + { + MC_LS_SETUP_7_1, + 8, + 2, + IVAS_48k, + &ivas_param_mc_ild_mapping_CICP12_2tc, + &ivas_param_mc_icc_mapping_CICP12_2tc, + &ivas_param_mc_dmx_fac_CICP12_2tc[0], + &ivas_param_mc_ild_fac_CICP12_2tc[0] + }, + /* CICP12 64000 */ + { + MC_LS_SETUP_7_1, + 8, + 2, + IVAS_64k, + &ivas_param_mc_ild_mapping_CICP12_2tc, + &ivas_param_mc_icc_mapping_CICP12_2tc, + &ivas_param_mc_dmx_fac_CICP12_2tc[0], + &ivas_param_mc_ild_fac_CICP12_2tc[0] + }, + /* CICP12 80000 */ + { + MC_LS_SETUP_7_1, + 8, + 2, + IVAS_80k, + &ivas_param_mc_ild_mapping_CICP12_2tc, + &ivas_param_mc_icc_mapping_CICP12_2tc, + &ivas_param_mc_dmx_fac_CICP12_2tc[0], + &ivas_param_mc_ild_fac_CICP12_2tc[0] + }, + /* CICP12 96000 */ + { + MC_LS_SETUP_7_1, + 8, + 3, + IVAS_96k, + &ivas_param_mc_ild_mapping_CICP12_3tc, + &ivas_param_mc_icc_mapping_CICP12_3tc, + &ivas_param_mc_dmx_fac_CICP12_3tc[0], + &ivas_param_mc_ild_fac_CICP12_3tc[0] + }, + /* CICP14 48000 */ + { + MC_LS_SETUP_5_1_2, + 8, + 2, + IVAS_48k, + &ivas_param_mc_ild_mapping_CICP14_2tc, + &ivas_param_mc_icc_mapping_CICP14_2tc, + &ivas_param_mc_dmx_fac_CICP14_2tc[0], + &ivas_param_mc_ild_fac_CICP14_2tc[0] + }, + /* CICP14 64000 */ + { + MC_LS_SETUP_5_1_2, + 8, + 2, + IVAS_64k, + &ivas_param_mc_ild_mapping_CICP14_2tc, + &ivas_param_mc_icc_mapping_CICP14_2tc, + &ivas_param_mc_dmx_fac_CICP14_2tc[0], + &ivas_param_mc_ild_fac_CICP14_2tc[0] + }, + /* CICP14 80000 */ + { + MC_LS_SETUP_5_1_2, + 8, + 2, + IVAS_80k, + &ivas_param_mc_ild_mapping_CICP14_2tc, + &ivas_param_mc_icc_mapping_CICP14_2tc, + &ivas_param_mc_dmx_fac_CICP14_2tc[0], + &ivas_param_mc_ild_fac_CICP14_2tc[0] + }, + /* CICP14 96000 */ + { + MC_LS_SETUP_5_1_2, + 8, + 3, + IVAS_96k, + &ivas_param_mc_ild_mapping_CICP14_3tc, + &ivas_param_mc_icc_mapping_CICP14_3tc, + &ivas_param_mc_dmx_fac_CICP14_3tc[0], + &ivas_param_mc_ild_fac_CICP14_3tc[0] + }, + /* CICP16 96000 */ + { + MC_LS_SETUP_5_1_4, + 10, + 3, + IVAS_96k, + &ivas_param_mc_ild_mapping_CICP16_3tc, + &ivas_param_mc_icc_mapping_CICP16_3tc, + &ivas_param_mc_dmx_fac_CICP16_3tc[0], + &ivas_param_mc_ild_fac_CICP16_3tc[0] + }, + /* CICP16 128000 */ + { + MC_LS_SETUP_5_1_4, + 10, + 3, + IVAS_128k, + &ivas_param_mc_ild_mapping_CICP16_3tc, + &ivas_param_mc_icc_mapping_CICP16_3tc, + &ivas_param_mc_dmx_fac_CICP16_3tc[0], + &ivas_param_mc_ild_fac_CICP16_3tc[0] + }, + /* CICP19 128000 */ + { + MC_LS_SETUP_7_1_4, + 12, + 3, + IVAS_128k, + &ivas_param_mc_ild_mapping_CICP19_3tc, + &ivas_param_mc_icc_mapping_CICP19_3tc, + &ivas_param_mc_dmx_fac_CICP19_3tc[0], + &ivas_param_mc_ild_fac_CICP19_3tc[0] + }, + /* CICP19 160000 */ + { + MC_LS_SETUP_7_1_4, + 12, + 4, + IVAS_160k, + &ivas_param_mc_ild_mapping_CICP19_4tc, + &ivas_param_mc_icc_mapping_CICP19_4tc, + &ivas_param_mc_dmx_fac_CICP19_4tc[0], + &ivas_param_mc_ild_fac_CICP19_4tc[0] + } +}; + +const float ivas_param_mc_quant_ild_5d1_48[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + -100.0f, -20.0f, -13.0f, -10.0f, + -8.0f, -5.5f, -3.5f, -1.5f, 0.0f, 1.5f, 3.5f, 5.5f, 8.0f, 10.0f, 13.0f, 20.0f +}; + +/* Quantizer for ICCs in Parametric MC Processing */ +const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER] = +{ + -0.99f, -0.589f, 0.0f, 0.36764f, 0.60092f, 0.84118f, 0.937f, 1.0f +}; + +/* Alphabet for delta coding for the ICCs in Parametric MC processing */ +const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +{ + 0, 24, 224, 20873, 42384, 51699, 57122, 60572, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +{ + 24, 200, 20649, 21511, 9315, 5423, 3450, 4963 +}; + +const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +{ + 0, 4, 9, 124, 447, 1311, 4453, 18116, 48636, 60573, 63692, 64746, 65327, 65531, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +{ + 4, 5, 115, 323, 864, 3142, 13663, 30520, 11937, 3119, 1054, 581, 204, 3, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +{ + 0, 30, 848, 26611, 47846, 57358, 61679, 63237, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +{ + 30, 818, 25763, 21235, 9512, 4321, 1558, 2298 +}; + +const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +{ + 0, 2, 7, 53, 243, 979, 3994, 16732, 49642, 61343, 64331, 65158, 65438, 65532, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +{ + 2, 5, 46, 190, 736, 3015, 12738, 32910, 11701, 2988, 827, 280, 94, 2, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +{ + 0, 46, 826, 27798, 49552, 58447, 62046, 63284, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER ]={ + 46, 780, 26972, 21754, 8895, 3599, 1238, 2251 +}; + +const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +{ + 0, 3, 8, 36, 172, 763, 3436, 15845, 50168, 62005, 64676, 65298, 65481, 65533, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2* PARAM_MC_SZ_ICC_QUANTIZER - 1] = +{ + 3, 5, 28, 136, 591, 2673, 12409, 34323, 11837, 2671, 622, 183, 52, 1, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +{ + 0, 34, 552, 24717, 45819, 54772, 59054, 61166, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +{ + 34, 518, 24165, 21102, 8953, 4282, 2112, 4369 +}; + +const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +{ + 0, 3, 7, 74, 304, 1009, 3870, 16502, 49834, 61384, 64217, 65020, 65369, 65531, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +{ + 3, 4, 67, 230, 705, 2861, 12632, 33332, 11550, 2833, 803, 349, 162, 3, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +{ + 0, 1092, 5574, 8315, 10652, 13875, 19656, 27664, 36284, 47058, 56251, 62579, 65118, 65462, 65513, 65532, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 1092, 4482, 2741, 2337, 3223, 5781, 8008, 8620, 10774, 9193, 6328, 2539, 344, 51, 19, 3 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 0, 1, 2, 3, 5, 38, 146, 352, 638, 997, 1559, 2323, 3570, 5859, 10556, 21075, 44682, 55617, 60408, 62739, 63833, 64443, 64809, 65074, 65279, 65400, 65484, 65531, 65532, 65533, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +{ + 1, 1, 1, 2, 33, 108, 206, 286, 359, 562, 764, 1247, 2289, 4697, 10519, 23607, 10935, 4791, 2331, 1094, 610, 366, 265, 205, 121, 84, 47, 1, 1, 1, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +{ + 0, 967, 6335, 9941, 12837, 16652, 22416, 29814, 38807, 48497, 57184, 62661, 64916, 65466, 65514, 65530, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 967, 5368, 3606, 2896, 3815, 5764, 7398, 8993, 9690, 8687, 5477, 2255, 550, 48, 16, 5 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 0, 1, 2, 3, 5, 18, 61, 149, 320, 592, 1083, 1793, 2974, 5257, 10133, 21274, 44342, 55891, 60895, 63174, 64244, 64793, 65100, 65287, 65406, 65477, 65517, 65531, 65532, 65533, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +{ + 1, 1, 1, 2, 13, 43, 88, 171, 272, 491, 710, 1181, 2283, 4876, 11141, 23068, 11549, 5004, 2279, 1070, 549, 307, 187, 119, 71, 40, 14, 1, 1, 1, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +{ + 0, 229, 7068, 10910, 13856, 17467, 22629, 29174, 36906, 46558, 55579, 61802, 65222, 65505, 65527, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 229, 6839, 3842, 2946, 3611, 5162, 6545, 7732, 9652, 9021, 6223, 3420, 283, 22, 7, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 0, 1, 2, 3, 4, 12, 56, 153, 278, 475, 856, 1430, 2489, 4723, 9580, 20685, 45423, 56274, 60948, 63097, 64128, 64679, 65002, 65208, 65348, 65445, 65517, 65531, 65532, 65533, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +{ + 1, 1, 1, 1, 8, 44, 97, 125, 197, 381, 574, 1059, 2234, 4857, 11105, 24738, 10851, 4674, 2149, 1031, 551, 323, 206, 140, 97, 72, 14, 1, 1, 1, 1 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS+1] = +{ + 0, 1453, 8326, 12221, 15164, 18764, 24177, 31297, 39520, 49154, 57135, 62460, 64821, 65468, 65514, 65530, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 1453, 6873, 3895, 2943, 3600, 5413, 7120, 8223, 9634, 7981, 5325, 2361, 647, 46, 16, 5 +}; + +const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +{ + 0, 1, 2, 3, 5, 29, 98, 220, 414, 699, 1186, 1876, 3049, 5304, 10013, 20612, 45247, 56109, 60818, 63022, 64081, 64647, 64977, 65198, 65348, 65443, 65502, 65530, 65532, 65533, 65534, 65535 +}; + +const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +{ + 1, 1, 1, 2, 24, 69, 122, 194, 285, 487, 690, 1173, 2255, 4709, 10599, 24635, 10862, 4709, 2204, 1059, 566, 330, 221, 150, 95, 59, 28, 2, 1, 1, 1 +}; + + +/*----------------------------------------------------------------------------------* + * MASA ROM tables + *----------------------------------------------------------------------------------*/ + +const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS] = +{ + 11, + 11, + 10, + 9, + 7, + 6, + 5, + 3 +}; + +const float coherence_cb0_masa[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH] = +{ + /* this is the same */ + 0.0478f, 0.2547f, 0.5515f, 0.9865f, 1.3573f, 1.6838f, 1.9674f, 0.0f, + 0.1211f, 0.4123f, 0.6997f, 1.0154f, 1.4197f, 1.7971f, 0.0f, 0.0f, + 0.1614f, 0.5674f, 0.9708f, 1.3699f, 1.7357f, 0.0f, 0.0f, 0.0f, + 0.2349f, 0.7306f, 1.2051f, 1.6547f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.2381f, 0.7185f, 1.1758f, 1.6335f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.2400f, 0.7027f, 1.1407f, 1.6243f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.3518f, 0.9398f, 1.6454f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + + 0.1445f, 0.3432f, 0.5351f, 0.7524f, 1.0095f, 1.3210f, 1.7399f, 0.0f, + 0.2002f, 0.4447f, 0.6869f, 0.9593f, 1.3090f, 1.7029f, 0.0f, 0.0f, + 0.2617f, 0.5556f, 0.8645f, 1.2185f, 1.6051f, 0.0f, 0.0f, 0.0f, + 0.3318f, 0.6810f, 1.0445f, 1.4710f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.3324f, 0.6588f, 0.9980f, 1.4164f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.3378f, 0.6658f, 1.0009f, 1.4269f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.3986f, 0.8244f, 1.3526f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f + + /* 0.0478f, 0.2547f, 1.9674f, 0.9865f, 0.5515f, 1.6838f, 1.3573f, 0.0f, + 0.1211f, 0.4123f, 0.6997f, 1.0154f, 1.4197f, 1.7971f, 0.0f, 0.0f, + 0.5674f, 0.9708f, 0.1614f, 1.3699f, 1.7357f, 0.0f, 0.0f, 0.0f, + 0.7306f, 1.2051f, 0.2349f, 1.6547f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.7185f, 1.1758f, 0.2381f, 1.6335f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.7027f, 1.1407f, 0.2400f, 1.6243f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.9398f, 1.6454f, 0.3518f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + + 0.3432f, 0.1445f, 0.5351f, 0.7524f, 1.0095f, 1.3210f, 1.7399f, 0.0f, + 0.4447f, 0.2002f, 0.6869f, 0.9593f, 1.3090f, 1.7029f, 0.0f, 0.0f, + 0.5556f, 0.2617f, 0.8645f, 1.2185f, 1.6051f, 0.0f, 0.0f, 0.0f, + 0.6810f, 0.3318f, 1.0445f, 1.4710f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.6588f, 0.3324f, 0.9980f, 1.4164f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.6658f, 0.3378f, 1.0009f, 1.4269f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.3986f, 0.8244f, 1.3526f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f */ +}; + +const float coherence_cb1_masa[MASA_NO_CV_COH1*MASA_MAXIMUM_CODING_SUBBANDS] = +{ + -0.0019f, 0.2597f, -0.2696f, 0.6269f, -0.6295f, + -0.0055f, 0.2582f, -0.2784f, 0.6473f, -0.6538f, + -0.0029f, 0.2506f, -0.2630f, 0.6498f, -0.6540f, + -0.0004f, 0.2546f, -0.2579f, 0.6851f, -0.6743f, + 0.0017f, 0.2521f, -0.2479f, 0.7217f, -0.7157f +}; + +const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS] = { 7, 6, 5, 4, 4, 4, 3, 2 }; + +const uint8_t sur_coherence_cb_masa[MASA_MAX_NO_CV_SUR_COH*MASA_NO_CB_SUR_COH] = +{ + 16, 99, 0, 0, 0, 0, 0, 0, + 12, 64, 167, 0, 0, 0, 0, 0, + 10, 45, 100, 218, 0, 0, 0, 0, + 8, 34, 70, 124, 235, 0, 0, 0, + 7, 27, 55, 90, 141, 242, 0, 0, + 7, 23, 45, 71, 105, 153, 247, 0, + 6, 20, 38, 60, 86, 119, 165, 249 +}; + +const int16_t idx_cb_sur_coh_masa[MASA_MAX_NO_CV_SUR_COH] = { 0, 1, 2, 3, 4, 5, 5, 6 }; + +const int16_t len_huf_masa[MASA_NO_CV_COH1] = { 4, 2, 1, 3, 4 }; + +const int16_t huff_code_av_masa[MASA_NO_CV_COH1] = { 15, 2, 0, 6, 14 }; + +const int16_t no_theta_masa[NO_SPHERICAL_GRIDS-2] = /* from 1 to 11 bits */ +{ /*1, 1,*/ 2 ,2 , 4, 5, 6, 7, 10, 14, 19 + /*0, 2, 8, 6, 7, 12, 14, 16*/ +}; + +const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA] = /* from 1 to 11 bits*/ +{ + { 2 }, + { 4 }, + { 4, 2 }, + { 8, 4 }, /* 8, 4*/ + { 12, 7, 2, 1 }, /* 12, */ + { 14, 13, 9, 2, 1 }, + { 22, 21, 17, 11, 3, 1 }, + { 33, 32, 29, 23, 17, 9, 1 }, + { 48, 47, 45, 41, 35, 28, 20, 12, 2, 1 }, + { 60, 60, 58, 56, 54, 50, 46, 41, 36, 30, 23, 17, 10, 1 }, + { 89, 89, 88, 86, 84, 81, 77, 73, 68, 63, 57, 51, 44, 38, 30, 23, 15, 8, 1 } +}; + +const float delta_theta_masa[NO_SPHERICAL_GRIDS - 2] = +{ /*180.0f, 90.0f,*/ 45.0f, 45.0f, 36.0f, 25.5f, 20.0f, /*14.9f*/ 15.0f, 10.78f, 6.7f, 5.0f }; +/* spheres +11 (10.9951) : (4.05,5) 89 89 88 86 84 81 77 73 68 63 57 51 44 38 30 23 15 8 1 +10 (10.0000): (6, 6.7) 60 60 58 56 54 50 46 41 36 30 23 17 10 1 +9 (8.9944): (7.5, 10.78) 48 47 45 41 35 28 20 12 2 1 +8 (7.9944): (10.8, 14.9) 33 32 29 23 17 9 1 +7 (7.0000): (16.5,20) 22 21 17 11 3 1 +6 (6.0000): (25,25.5) 14 13 9 2 1 +5 (5.0000): (36,36) 10 8 2 1 +4 (4.0000): (45 45) 8 4 (no +-90) +3 (3.0000) (90,45) 4 2 (no +-90) +2 (2.0000) (90,90) 4 (no +-90) +1 () 2 +*/ + +const float azimuth_cb[8] = +{ + 0.0f, -180.0f, -90.0f, 90.0f, -45.0f, 45.0f, -135.0f, 135.0f +}; + +const int16_t MASA_band_grouping_24[24 + 1] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 40, 60 +}; + +const int16_t MASA_band_mapping_24_to_18[18 + 1] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 21, 22, 23, 24 +}; + +const int16_t MASA_band_mapping_24_to_12[12 + 1] = +{ + 0, 1, 2, 3, 4, 5, 7, 9, 12, 15, 20, 22, 24 +}; + +const int16_t MASA_band_mapping_24_to_8[8 + 1] = +{ + 0, 1, 2, 3, 5, 8, 12, 20, 24 +}; + +const int16_t MASA_band_mapping_24_to_5[5 + 1] = +{ + 0, 1, 3, 7, 15, 24 +}; + +const int16_t MASA_grouping_8_to_5[8] = +{ + 0, 1, 1, 2, 3, 3, 4, 4 +}; + +const int16_t MASA_grouping_12_to_5[12] = +{ + 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4 +}; + +const int16_t MASA_grouping_18_to_5[18] = +{ + 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 +}; + +const int16_t MASA_grouping_24_to_5[24] = +{ + 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4 +}; + +/* IVAS_13k2, IVAS_16k4, IVAS_24k4, IVAS_32k, IVAS_48k, IVAS_64k, IVAS_80k, IVAS_96k, IVAS_128k, IVAS_160k, IVAS_192k, IVAS_256k, IVAS_384k, IVAS_512k */ +const int16_t masa_bits[IVAS_NUM_ACTIVE_BRATES] = +{ + 50, 60, 70, 85, 140, 180, 220, 256, 350, 432, 528, 832, 1024, MASA_MAX_BITS +}; + +const int16_t masa_bits_LR_stereo[4] = +{ + 50, 50, 60, 70 +}; + +const int16_t mcmasa_bits[IVAS_NUM_ACTIVE_BRATES] = +{ + 50, 70, 80, 120, 140, 160, 220, 256, 288, 432, 528, 832, 1024, MASA_MAX_BITS +}; + +const uint8_t masa_nbands[IVAS_NUM_ACTIVE_BRATES] = +{ + 5, 5, 5, 5, 5, 5, 5, 5, 8, 12, 18, 24, 24, 24 +}; + +const uint8_t masa_joined_nbands[IVAS_NUM_ACTIVE_BRATES] = +{ + 5, 5, 5, 8, 12, 12, 12, 18, 18, 18, 18, 24, 24, 24 +}; + +const uint8_t masa_twodir_bands[IVAS_NUM_ACTIVE_BRATES] = +{ + 0, 0, 0, 0, 0, 1, 1, 1, 3, 4, 6, 6, 9, 12 +}; + +const uint8_t masa_twodir_bands_joined[IVAS_NUM_ACTIVE_BRATES] = +{ + 0, 0, 0, 0, 0, 2, 2, 3, 4, 6, 8, 9, 12, 18 +}; + + +/*----------------------------------------------------------------------------------* + * Multi-channel LS setups + *----------------------------------------------------------------------------------*/ + +const float ls_azimuth_CICP2[2] = { 30.0f, -30.0f }; +const float ls_elevation_CICP2[2] = { 0.0f, 0.0f }; + +const float ls_azimuth_CICP6[5] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f }; +const float ls_elevation_CICP6[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +const float ls_azimuth_CICP12[7] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f, 135.0f, -135.0f }; +const float ls_elevation_CICP12[7] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +const float ls_azimuth_CICP14[7] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f, 30.0f, -30.0f }; +const float ls_elevation_CICP14[7] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 35.0f, 35.0f }; + +const float ls_azimuth_CICP16[9] = { 30.0f, -30.0f, 0.0f, 110.0f, -110.0f, 30.0f, -30.0f, 110.0f, -110.0f }; +const float ls_elevation_CICP16[9] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 35.0f, 35.0f, 35.0f, 35.0f }; + +const float ls_azimuth_CICP19[11] = { 30.0f, -30.0f, 0.0f, 135.0f, -135.0f, 90.0f, -90.0f, 30.0f, -30.0f, 135.0f, -135.0f }; +const float ls_elevation_CICP19[11] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 35.0f, 35.0f, 35.0f, 35.0f }; + +const float cb_azi_chan[] = { 0.0f, 30.0f, 110.0f, 135.0f }; + +const float McMASA_LFEGain_vectors[64] = +{ + 0.38f, 0.33f, 0.19f, 0.20f, /* 1st bit */ + -0.16f, -0.22f, -0.35f, -0.34f, + 0.50f, 0.50f, 0.50f, 0.50f, /* 2nd bit*/ + -0.80f, -0.40f, 1.02f, 0.10f, + -0.50f, -0.50f, -0.50f, -0.50f, /* 3rd bit */ + -0.56f, -0.12f, -0.78f, 1.36f, + -1.02f, 1.18f, -0.57f, 0.33f, + 0.72f, -1.13f, 0.97f, -0.62f, + -0.91f, 0.93f, 1.00f, -1.10f, /* 4th bit*/ + 1.73f, -0.23f, -0.78f, -0.84f, + 0.95f, -1.60f, -0.34f, 0.93f, + 0.87f, 0.47f, -1.90f, 0.52f, + 0.67f, 1.42f, -0.97f, -1.24f, + 0.83f, 0.58f, 0.61f, -2.04f, + -0.80f, -1.58f, 0.82f, 1.42f, + -2.14f, 0.26f, 0.84f, 1.02f +}; + + +/*----------------------------------------------------------------------------------* + * ISM ROM tables + *----------------------------------------------------------------------------------*/ + +const float ism_azimuth_borders[4] = +{ + ISM_AZIMUTH_MIN, ISM_AZIMUTH_LOW_BORDER, ISM_AZIMUTH_HIGH_BORDER, ISM_AZIMUTH_MAX +}; + +const float ism_elevation_borders[4] = +{ + ISM_ELEVATION_MIN, ISM_ELEVATION_LOW_BORDER, ISM_ELEVATION_HIGH_BORDER, ISM_ELEVATION_MAX +}; + + +/*----------------------------------------------------------------------------------* + * Param ISM ROM tables + *----------------------------------------------------------------------------------*/ + +const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1] = +{ + 0, 1, 2, 3, 4, 6, 8, 11, 15, 21, 31, 60 +}; + +/*----------------------------------------------------------------------------------* + * LFE coding ROM tables + *----------------------------------------------------------------------------------*/ + +const float ivas_lfe_window_coeff_48k[IVAS_LFE_FADE_LEN_48K] = +{ + 0.000111037183489911f, 0.000184173600662723f, 0.000260431056232165f, 0.000343096680773904f, + 0.000433557036912299f, 0.000532702330090964f, 0.000641245198570983f, 0.000759825620233343f, + 0.000889053268887781f, 0.00102952705612861f, 0.00118184503626756f, 0.00134660978209878f, + 0.00152443144932643f, 0.00171592958031516f, 0.00192173418063960f, 0.00214248635511166f, + 0.00237883866481051f, 0.00263145529985620f, 0.00290101212545378f, 0.00318819663720802f, + 0.00349370784884686f, 0.00381825612758351f, 0.00416256298736225f, 0.00452736084701996f, + 0.00491339275828344f, 0.00532141210711066f, 0.00575218229092557f, 0.00620647637363723f, + 0.00668507671987614f, 0.00718877460956053f, 0.00771836983367896f, 0.00827467027201698f, + 0.00885849145344304f, 0.00947065609929077f, 0.0101119936503206f, 0.0107833397777077f, + 0.0114855358784815f, 0.0122194285558262f, 0.0129858690846493f, 0.0137857128628235f, + 0.0146198188485090f, 0.0154890489839742f, 0.0163942676063398f, 0.0173363408456805f, + 0.0183161360109349f, 0.0193345209640845f, 0.0203923634830761f, 0.0214905306139788f, + 0.0226298880128789f, 0.0238112992780310f, 0.0250356252727999f, 0.0263037234399395f, + 0.0276164471077718f, 0.0289746447888419f, 0.0303791594716384f, 0.0318308279059821f, + 0.0333304798826995f, 0.0348789375082095f, 0.0364770144746630f, 0.0381255153262869f, + 0.0398252347225964f, 0.0415769566991470f, 0.0433814539265092f, 0.0452394869681573f, + 0.0471518035379721f, 0.0491191377580651f, 0.0511422094176377f, 0.0532217232335982f, + 0.0553583681136604f, 0.0575528164226564f, 0.0598057232527990f, 0.0621177256986303f, + 0.0644894421373997f, 0.0669214715156123f, 0.0694143926424920f, 0.0719687634911028f, + 0.0745851205078720f, 0.0772639779312550f, 0.0800058271202837f, 0.0828111358937321f, + 0.0856803478806326f, 0.0886138818828696f, 0.0916121312505734f, 0.0946754632710273f, + 0.0978042185717987f, 0.100998710538792f, 0.104259224749915f, 0.107586018425039f, + 0.110979319892929f, 0.114439328075791f, 0.117966211992097f, 0.121560110278315f, + 0.125221130730162f, 0.128949349863999f, 0.132744812498936f, 0.136607531360247f, + 0.140537486704635f, 0.144534625967897f, 0.148598863435505f, 0.152730079936616f, + 0.156928122561981f, 0.161192804406232f, 0.165523904334983f, 0.169921166777162f, + 0.174384301542983f, 0.178912983667934f, 0.183506853283123f, 0.188165515512334f, + 0.192888540396077f, 0.197675462842929f, 0.202525782608415f, 0.207438964301664f, + 0.212414437420042f, 0.217451596411945f, 0.222549800767893f, 0.227708375140074f, + 0.232926609490399f, 0.238203759267182f, 0.243539045610445f, 0.248931655585895f, + 0.254380742447540f, 0.259885425928913f, 0.265444792562823f, 0.271057896029545f, + 0.276723757533309f, 0.282441366206947f, 0.288209679544493f, 0.294027623861544f, + 0.299894094783121f, 0.305807957758767f, 0.311768048604592f, 0.317773174071915f, + 0.323822112442170f, 0.329913614147682f, 0.336046402417904f, 0.342219173950673f, + 0.348430599608033f, 0.354679325136114f, 0.360963971908571f, 0.367283137693016f, + 0.373635397439901f, 0.380019304093226f, 0.386433389422488f, 0.392876164875198f, + 0.399346122449318f, 0.405841735584931f, 0.412361460074412f, 0.418903734990401f, + 0.425466983630787f, 0.432049614479962f, 0.438650022185529f, 0.445266588549660f, + 0.451897683534280f, 0.458541666279211f, 0.465196886132432f, 0.471861683691556f, + 0.478534391855649f, 0.485213336886453f, 0.491896839478123f, 0.498583215834516f, + 0.505270778753096f, 0.511957838714501f, 0.518642704976797f, 0.525323686673448f, + 0.531999093914013f, 0.538667238886587f, 0.545326436960981f, 0.551975007791651f, + 0.558611276419351f, 0.565233574370526f, 0.571840240753416f, 0.578429623349869f, + 0.585000079701846f, 0.591549978191620f, 0.598077699114643f, 0.604581635744092f, + 0.611060195386091f, 0.617511800424606f, 0.623934889355033f, 0.630327917805494f, + 0.636689359544871f, 0.643017707476609f, 0.649311474617338f, 0.655569195059378f, + 0.661789424916185f, 0.667970743249834f, 0.674111752979635f, 0.680211081770987f, + 0.686267382903617f, 0.692279336118339f, 0.698245648441503f, 0.704165054986320f, + 0.710036319730275f, 0.715858236267842f, 0.721629628537765f, 0.727349351524163f, + 0.733016291930776f, 0.738629368827644f, 0.744187534269598f, 0.749689773885909f, + 0.755135107440516f, 0.760522589362248f, 0.765851309244508f, 0.771120392313900f, + 0.776328999867319f, 0.781476329677057f, 0.786561616363500f, 0.791584131735037f, + 0.796543185094819f, 0.801438123514058f, 0.806268332071584f, 0.811033234059390f, + 0.815732291153985f, 0.820365003553343f, 0.824930910079335f, 0.829429588245527f, + 0.833860654290276f, 0.838223763175109f, 0.842518608548382f, 0.846744922674278f, + 0.850902476327233f, 0.854991078651907f, 0.859010576988885f, 0.862960856666304f, + 0.866841840757651f, 0.870653489806038f, 0.874395801515260f, 0.878068810408014f, + 0.881672587451697f, 0.885207239652212f, 0.888672909616291f, 0.892069775082842f, + 0.895398048423911f, 0.898657976115850f, 0.901849838181344f, 0.904973947602979f, + 0.908030649709079f, 0.911020321532565f, 0.913943371143645f, 0.916800236957154f, + 0.919591387015427f, 0.922317318247601f, 0.924978555706293f, 0.927575651782607f, + 0.930109185400495f, 0.932579761191496f, 0.934988008650908f, 0.937334581276497f, + 0.939620155690861f, 0.941845430748583f, 0.944011126629350f, 0.946117983918227f, + 0.948166762674299f, 0.950158241488903f, 0.952093216534711f, 0.953972500606916f, + 0.955796922157805f, 0.957567324326003f, 0.959284563961681f, 0.960949510649049f, + 0.962563045727414f, 0.964126061312150f, 0.965639459316855f, 0.967104150478033f, + 0.968521053383593f, 0.969891093506458f, 0.971215202244581f, 0.972494315968637f, + 0.973729375078655f, 0.974921323070827f, 0.976071105615721f, 0.977179669649101f, + 0.978247962476515f, 0.979276930892814f, 0.980267520317711f, 0.981220673948460f, + 0.982137331930712f, 0.983018430548546f, 0.983864901434662f, 0.984677670801652f, + 0.985457658695232f, 0.986205778270287f, 0.986922935090503f, 0.987610026452330f, + 0.988267940733967f, 0.988897556770000f, 0.989499743252276f, 0.990075358157522f, + 0.990625248202194f, 0.991150248324956f, 0.991651181197124f, 0.992128856761388f, + 0.992584071799021f, 0.993017609525750f, 0.993430239216404f, 0.993822715858368f, + 0.994195779833855f, 0.994550156630899f, 0.994886556582961f, 0.995205674636936f, + 0.995508190149341f, 0.995794766710354f, 0.996066051995373f, 0.996322677643671f, + 0.996565259163689f, 0.996794395864463f, 0.997010670812624f, 0.997214650814370f, + 0.997406886421766f, 0.997587911962687f, 0.997758245593683f, 0.997918389375006f, + 0.998068829367008f, 0.998210035747091f, 0.998342462946368f, 0.998466549805146f, + 0.998582719746365f, 0.998691380966053f, 0.998792926639904f, 0.998887735145004f, + 0.998976170295797f, 0.999058581593303f, 0.999135304486653f, 0.999206660645980f, + 0.999272958245696f, 0.999334492257230f, 0.999391544750254f, 0.999444385201492f, + 0.999493270810174f, 0.999538446819229f, 0.999580146841343f, 0.999618593188994f, + 0.999653997207632f, 0.999686559611161f, 0.999716470818948f, 0.999743911293550f, + 0.999769051878447f, 0.999792054135046f, 0.999813070678259f, 0.999832245510030f, + 0.999849714350153f, 0.999865604963813f, 0.999880037485284f, 0.999893124737258f, + 0.999904972545323f, 0.999915680047131f, 0.999925339995826f, 0.999934039057369f, + 0.999941858101379f, 0.999948872485197f, 0.999955152330868f, 0.999960762794806f, + 0.999965764329904f, 0.999970212939921f, 0.999974160425965f, 0.999977654624967f, + 0.999980739640031f, 0.999983456062595f, 0.999985841186357f, 0.999987929212949f, + 0.999989751449364f, 0.999991336497160f, 0.999992710433503f, 0.999993896984110f, + 0.999994917688186f, 0.999995792055471f, 0.999996537715509f, 0.999997170559301f, + 0.999997704873475f, 0.999998153467165f, 0.999998527791754f, 0.999998838053703f, + 0.999999093320636f, 0.999999301620911f, 0.999999470036880f, 0.999999604792064f, + 0.999999711332472f, 0.999999794402277f, 0.999999858114104f, 0.999999906014144f, + 0.999999941142332f, 0.999999966087832f, 0.999999983040042f, 0.999999993835372f +}; + +const float ivas_lfe_window_coeff_32k[IVAS_LFE_FADE_LEN_32K] = +{ + 0.000135992220705702f, 0.000243900754874608f, 0.000366502488193403f, 0.000507754555407233f, + 0.000670037413867230f, 0.000855400185342017f, 0.00106582120537505f, 0.00130328810233523f, + 0.00156982797844358f, 0.00186752014891622f, 0.00219850171292337f, 0.00256496978060437f, + 0.00296918195815542f, 0.00341345582581521f, 0.00390016777110998f, 0.00443175136707306f, + 0.00501069540002978f, 0.00563954160739932f, 0.00632088216212532f, 0.00705735692705637f, + 0.00785165049501826f, 0.00870648902594829f, 0.00962463688994814f, 0.0106088931237052f, + 0.0116620877070005f, 0.0127870776657112f, 0.0139867430076699f, 0.0152639824978695f, + 0.0166217092797368f, 0.0180628463495039f, 0.0195903218910554f, 0.0212070644790028f, + 0.0229159981581294f, 0.0247200374077382f, 0.0266220819998311f, 0.0286250117604275f, + 0.0307316812437090f, 0.0329449143290351f, 0.0352674987512187f, 0.0377021805747777f, + 0.0402516586231834f, 0.0429185788744125f, 0.0457055288343670f, 0.0486150318999676f, + 0.0516495417239329f, 0.0548114365934440f, 0.0581030138350493f, 0.0615264842582949f, + 0.0650839666506623f, 0.0687774823364692f, 0.0726089498124248f, 0.0765801794725421f, + 0.0806928684350862f, 0.0849485954841849f, 0.0893488161386407f, 0.0938948578603667f, + 0.0985879154147218f, 0.103429046394834f, 0.108419166921795f, 0.113559047532359f, + 0.118849309265507f, 0.124290419958929f, 0.129882690766145f, 0.135626272904605f, + 0.141521154644746f, 0.147567158549505f, 0.153763938973404f, 0.160110979829776f, + 0.166607592634260f, 0.173252914832108f, 0.180045908416344f, 0.186985358843200f, + 0.194069874250690f, 0.201297884985540f, 0.208667643443083f, 0.216177224224055f, + 0.223824524611575f, 0.231607265370904f, 0.239522991873889f, 0.247569075549288f, + 0.255742715659461f, 0.264040941403189f, 0.272460614343670f, 0.280998431159973f, + 0.289650926719540f, 0.298414477468569f, 0.307285305136374f, 0.316259480749104f, + 0.325332928947464f, 0.334501432602363f, 0.343760637721723f, 0.353106058640944f, + 0.362533083488876f, 0.372036979920440f, 0.381612901106401f, 0.391255891970138f, + 0.400960895660650f, 0.410722760250415f, 0.420536245646151f, 0.430396030699960f, + 0.440296720507817f, 0.450232853881834f, 0.460198910982274f, 0.470189321094825f, + 0.480198470538230f, 0.490220710686965f, 0.500250366093333f, 0.510281742692964f, + 0.520309136077485f, 0.530326839817815f, 0.540329153821353f, 0.550310392706136f, + 0.560264894174896f, 0.570187027371852f, 0.580071201204973f, 0.589911872616473f, + 0.599703554784248f, 0.609440825237056f, 0.619118333866323f, 0.628730810817558f, + 0.638273074244583f, 0.647740037909930f, 0.657126718615052f, 0.666428243444252f, + 0.675639856806586f, 0.684756927260328f, 0.693774954105018f, 0.702689573726534f, + 0.711496565681117f, 0.720191858504788f, 0.728771535235148f, 0.737231838633124f, + 0.745569176092876f, 0.753780124228688f, 0.761861433128389f, 0.769810030263551f, + 0.777623024047447f, 0.785297707032555f, 0.792831558740175f, 0.800222248115570f, + 0.807467635602894f, 0.814565774835047f, 0.821514913934526f, 0.828313496422214f, + 0.834960161732055f, 0.841453745330485f, 0.847793278440476f, 0.853977987371046f, + 0.860007292454100f, 0.865880806591466f, 0.871598333416011f, 0.877159865071782f, + 0.882565579619094f, 0.887815838071573f, 0.892911181073134f, 0.897852325223955f, + 0.902640159065461f, 0.907275738735386f, 0.911760283304927f, 0.916095169810981f, + 0.920281927997422f, 0.924322234780251f, 0.928217908452363f, 0.931970902644524f, + 0.935583300059946f, 0.939057306000627f, 0.942395241704333f, 0.945599537511766f, + 0.948672725884068f, 0.951617434291347f, 0.954436377993401f, 0.957132352734204f, + 0.959708227372067f, 0.962166936467612f, 0.964511472851888f, 0.966744880197007f, + 0.968870245611698f, 0.970890692284040f, 0.972809372193449f, 0.974629458913696f, + 0.976354140528315f, 0.977986612679290f, 0.979530071769289f, 0.980987708337022f, + 0.982362700624510f, 0.983658208354169f, 0.984877366732620f, 0.986023280697072f, + 0.987099019418999f, 0.988107611078563f, 0.989052037921982f, 0.989935231612664f, + 0.990760068885503f, 0.991529367512303f, 0.992245882584772f, 0.992912303120025f, + 0.993531248991970f, 0.994105268190439f, 0.994636834408346f, 0.995128344955654f, + 0.995582118997414f, 0.996000396111680f, 0.996385335161686f, 0.996739013475302f, + 0.997063426323498f, 0.997360486688307f, 0.997632025309661f, 0.997879790999405f, + 0.998105451209848f, 0.998310592843372f, 0.998496723288846f, 0.998665271669997f, + 0.998817590290322f, 0.998954956258775f, 0.999078573280101f, 0.999189573593561f, + 0.999289020043705f, 0.999377908266854f, 0.999457168977167f, 0.999527670336312f, + 0.999590220391194f, 0.999645569564531f, 0.999694413183629f, 0.999737394033262f, + 0.999775104919193f, 0.999808091229614f, 0.999836853482484f, 0.999861849847578f, + 0.999883498632868f, 0.999902180725714f, 0.999918241980199f, 0.999931995542854f, + 0.999943724109857f, 0.999953682109695f, 0.999962097806132f, 0.999969175317172f, + 0.999975096546511f, 0.999980023024807f, 0.999984097658787f, 0.999987446387008f, + 0.999990179741692f, 0.999992394316756f, 0.999994174142692f, 0.999995591969534f, + 0.999996710459602f, 0.999997583292189f, 0.999998256182726f, 0.999998767819300f, + 0.999999150719701f, 0.999999432012418f, 0.999999634145194f, 0.999999775524907f, + 0.999999871092647f, 0.999999932837961f, 0.999999970256211f, 0.999999990753058f +}; + +const float ivas_lfe_window_coeff_16k[IVAS_LFE_FADE_LEN_16K] = +{ + 0.000192322041967661f, 0.000432042541451336f, 0.000754275578824202f, 0.00117365342860051f, + 0.00170559736282027f, 0.00236656267363075f, 0.00317404503675108f, 0.00414654286875000f, + 0.00530350017263264f, 0.00666523498873026f, 0.00825285493787745f, 0.0100881605116261f, + 0.0121935365995684f, 0.0145918327721377f, 0.0173062329286553f, 0.0203601150332032f, + 0.0237769017796244f, 0.0275799031448139f, 0.0317921519028702f, 0.0364362332793203f, + 0.0415341100227591f, 0.0471069442593880f, 0.0531749175728265f, 0.0597570508160612f, + 0.0668710252134883f, 0.0745330063478375f, 0.0827574726486089f, 0.0915570500049407f, + 0.100942354116142f, 0.110921842167215f, 0.121501675374497f, 0.132685593888120f, + 0.144474805463665f, 0.156867889225514f, 0.169860715739713f, 0.183446384495299f, + 0.197615179761091f, 0.212354545640879f, 0.227649080995091f, 0.243480554732640f, + 0.259827941804377f, 0.276667480050824f, 0.293972747873422f, 0.311714762512102f, + 0.329862098524320f, 0.348381025873702f, 0.367235666851846f, 0.386388170876560f, + 0.405798906035553f, 0.425426666078274f, 0.445228891401677f, 0.465161902430052f, + 0.485181143655975f, 0.505241436490520f, 0.525297238967270f, 0.545302910257632f, + 0.565212977885414f, 0.584982405477527f, 0.604566858855629f, 0.623922968261127f, + 0.643008584513597f, 0.661783026930517f, 0.680207320884341f, 0.698244422941288f, + 0.715859431614468f, 0.733019781871777f, 0.749695421665815f, 0.765858968898205f, + 0.781485847393429f, 0.796554400636541f, 0.811045982224021f, 0.824945022186269f, + 0.838239068562518f, 0.850918803842860f, 0.862978036135913f, 0.874413665172658f, + 0.885225623515076f, 0.895416793600184f, 0.904992901513335f, 0.913962388646463f, + 0.922336262654064f, 0.930127929368794f, 0.937353007575688f, 0.944029128765173f, + 0.950175724185808f, 0.955813801693484f, 0.960965715039994f, 0.965654928355726f, + 0.969905778654342f, 0.973743239217655f, 0.977192686702912f, 0.980279674750013f, + 0.983029716751026f, 0.985468080278805f, 0.987619595456638f, 0.989508479289711f, + 0.991158177676277f, 0.992591226478046f, 0.993829132663272f, 0.994892276151289f, + 0.995799832594078f, 0.996569716939470f, 0.997218547242656f, 0.997761627838482f, + 0.998212950666223f, 0.998585213259802f, 0.998889851686633f, 0.999137086542491f, + 0.999335979990921f, 0.999494501774465f, 0.999619602119988f, 0.999717289508270f, + 0.999792711373630f, 0.999850235936272f, 0.999893533540622f, 0.999925656069088f, + 0.999949113214013f, 0.999965944612802f, 0.999977787074566f, 0.999985936344066f, + 0.999991403054165f, 0.999994962706365f, 0.999997199686635f, 0.999998545467760f, + 0.999999311268578f, 0.999999715534135f, 0.999999906669617f, 0.999999981506116f +}; + +const float ivas_lpf_4_butter_16k_sos[IVAS_BIQUAD_FILT_LEN << 2] = +{ + 3.97464794223146e-07f, 7.94929601777927e-07f, 3.97464788468481e-07f, 1.f, + -1.90746797905194f, 0.909956295365785f, 1.f, 1.99999996645833f, + 1.00000001447843f, 1.f, -1.95913666348268f, 0.961692382252710f +}; + +const float ivas_lpf_4_butter_32k_sos[IVAS_BIQUAD_FILT_LEN << 2] = +{ + 2.56674586654460e-08f, 5.13349181918215e-08f, 2.56674582938215e-08f, 1, + -1.95329015717623f, 0.953926661219383f, 1, 1.99999996645833f, + 1.00000001447843f, 1, -1.98000953138860f, 0.980654742275836f +}; + +const float ivas_lpf_4_butter_48k_sos[IVAS_BIQUAD_FILT_LEN << 2] = +{ + 5.12617881476274e-09f, 1.02523584294987e-08f, 5.12617879059970e-09f, + 1.0, -1.96875982668433f, 0.969044914826862f, 1.f , 1.99999984394358f, + 1.00000000471366f, 1.f , -1.98677297369091f, 0.987060670205863f +}; + +const float ivas_lpf_2_butter_16k[IVAS_BIQUAD_FILT_LEN << 1] = +{ + 0.000628720643081143f, 0.00125744128616229f, 0.000628720643081143f, 1.f, -1.92783286977036f, 0.930347752342683f +}; + +const float ivas_lpf_2_butter_32k[IVAS_BIQUAD_FILT_LEN << 1] = +{ + 0.000159990787823749f, 0.000319981575647499f, 0.000159990787823749f, 1.f, -1.96390539174033f, 0.964545354891623f +}; + +const float ivas_lpf_2_butter_48k[IVAS_BIQUAD_FILT_LEN << 1] = +{ + 7.15317998432330e-05f, 0.000143063599686466f, 7.15317998432330e-05f, 1.f, -1.97593552482925f, 0.976221652028620f +}; + +const ivas_lfe_freq_models ivas_str_lfe_freq_models = +{ + { 16384, 14924, 13463, 12003, 10542, 9082, 7622, 6161, + 4701, 4336, 3970, 3605, 3240, 2875, 2510, 2145, + 1780, 1689, 1597, 1506, 1415, 1323, 1232, 1141, + 1050, 1004, 958, 913, 867, 821, 776, 730, + 685, 639, 593, 548, 502, 456, 411, 365, + 319, 297, 274, 251, 228, 205, 183, 160, + 137, 126, 114, 103, 91, 80, 68, 57, + 46, 40, 34, 29, 23, 17, 11, 6, 0 }, + + { 16384, 13463, 10542, 7622, 4701, 3970, 3240, 2510, + 1780, 1597, 1415, 1232, 1050, 958, 867, 776, + 685, 593, 502, 411, 319, 274, 228, 183, + 137, 114, 91, 68, 46, 34, 23, 11, 0 }, + + { 16384, 4701, 1780, 1050, 685, 319, 137, 46, + 0, }, + + { 16384, 3277, 0 }, + + { 16384, 13463, 10542, 7622, 4701, 3970, 3240, 2510, + 1780, 1597, 1415, 1232, 1050, 958, 867, 776, + 685, 593, 502, 411, 319, 274, 228, 183, + 137, 114, 91, 68, 46, 34, 23, 11, + 0 }, + + { 16384, 10542, 4701, 3240, 1780, 1415, 1050, 867, + 685, 502, 319, 228, 137, 91, 46, 23, + 0 }, + + { 16384, 4468, 1489, 745, 0 }, 0, +}; + +const int16_t ivas_lfe_num_ele_in_coder_models[2][4] = +{ + { 63, 31, 7, 1 },{ 31, 15, 3, 0 } +}; + +const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 8, 6 }; + +const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 1, 0 }; + +const float ivas_lfe_lpf_delay[2] = { 0.00175f, 0.0035f }; + +const double d_hamm_lfe_plc[LFE_PLC_LENANA / 2] = +{ + 0.08000000000000002, 0.08015895227847719, 0.08063569926248770, 0.08142991147368656, 0.08254104003450596, 0.08396831704748331, 0.08571075612595230, 0.08776715307573196, + 0.09013608672734141, 0.09281591991816535, 0.09580480062389246, 0.09910066323844335, 0.10270123000150438, 0.10660401257268071, 0.11080631375118072, 0.11530522933984272, + 0.12009765015221685, 0.12518026416131367, 0.13054955878853602, 0.13620182333121073, 0.14213315152704381, 0.14833944425372619, 0.15481641236182375, 0.16155957963899570, + 0.16856428590349043, 0.17582569022478273, 0.18333877426912554, 0.19109834576770490, 0.19909904210500018, 0.20733533402487142, 0.21580152945181053, 0.22449177742471671, + 0.23340007214047787, 0.24252025710456171, 0.25184602938575001, 0.26137094397207467, 0.27108841822494550, 0.28099173642839037, 0.29107405443026624, 0.30132840437223085, + 0.31174769950520753, 0.32232473908701620, 0.33305221335878232, 0.34392270859668939, 0.35492871223557998, 0.36606261806086549, 0.37731673146515798, 0.38868327476598852, + 0.40015439258093899, 0.41172215725647360, 0.42337857434671339, 0.43511558813837425, 0.44692508721804453, 0.45879891007795709, 0.47072885075638249, 0.48270666450874267, + 0.49472407350552849, 0.50677277255308162, 0.51884443483328757, 0.53093071765821398, 0.54302326823571601, 0.55511372944202464, 0.56719374559732838, 0.57925496824035816, + 0.59128906189798180, 0.60328770984582458, 0.61524261985593010, 0.62714552992749328, 0.63898821399670414, 0.65076248762175315, 0.66246021363907504, 0.67407330778691554, + 0.68559374429233988, 0.69701356141781945, 0.70832486696356345, 0.71951984372179334, 0.73059075487919101, 0.74152994936378558, 0.75232986713258543, 0.76298304439630038, + 0.77348211877754336, 0.78381983439894576, 0.79398904689767136, 0.80398272836286389, 0.81379397219261318, 0.82341599786708708, 0.83284215563452701, 0.84206593110687011, + 0.85108094976182280, 0.85988098134827329, 0.86845994419199846, 0.87681190939868969, 0.88493110495139349, 0.89281191969953333, 0.90044890723675941, 0.90783678966494241, + 0.91497046124171255, 0.92184499190902180, 0.92845563070029180, 0.93479780902379184, 0.94086714381997805, 0.94665944059061280, 0.95217069629756890, 0.95739710212931617, + 0.96233504613317988, 0.96698111571154954, 0.97133209998031445, 0.97538499198789563, 0.97913699079334116, 0.98258550340204664, 0.98572814655776630, 0.98856274838967395, + 0.99108734991333569, 0.99330020638455863, 0.99519978850517732, 0.99678478347994692, 0.99805409592381300, 0.99900684861892730, 0.99964238312089115, 0.99996026021380402 +}; + + +/*------------------------------------------------------------------------------------------* + * MDFT/iMDFT ROM tables + *------------------------------------------------------------------------------------------*/ + +const float ivas_mdft_coeff_cos_twid_960[IVAS_960_PT_LEN + 1] = +{ + 1.00000000000000f, 0.999998661349528f, 0.999994645401697f, 0.999987952167257f, + 0.999978581664129f, 0.999966533917401f, 0.999951808959328f, 0.999934406829333f, + 0.999914327574007f, 0.999891571247108f, 0.999866137909562f, 0.999838027629461f, + 0.999807240482065f, 0.999773776549800f, 0.999737635922260f, 0.999698818696204f, + 0.999657324975557f, 0.999613154871411f, 0.999566308502021f, 0.999516785992811f, + 0.999464587476366f, 0.999409713092437f, 0.999352162987941f, 0.999291937316955f, + 0.999229036240723f, 0.999163459927649f, 0.999095208553300f, 0.999024282300407f, + 0.998950681358860f, 0.998874405925711f, 0.998795456205172f, 0.998713832408616f, + 0.998629534754574f, 0.998542563468736f, 0.998452918783950f, 0.998360600940223f, + 0.998265610184716f, 0.998167946771749f, 0.998067610962796f, 0.997964603026487f, + 0.997858923238604f, 0.997750571882084f, 0.997639549247016f, 0.997525855630641f, + 0.997409491337352f, 0.997290456678690f, 0.997168751973348f, 0.997044377547164f, + 0.996917333733128f, 0.996787620871373f, 0.996655239309180f, 0.996520189400975f, + 0.996382471508325f, 0.996242085999945f, 0.996099033251687f, 0.995953313646548f, + 0.995804927574662f, 0.995653875433303f, 0.995500157626885f, 0.995343774566954f, + 0.995184726672197f, 0.995023014368432f, 0.994858638088611f, 0.994691598272820f, + 0.994521895368273f, 0.994349529829318f, 0.994174502117428f, 0.993996812701206f, + 0.993816462056378f, 0.993633450665799f, 0.993447779019444f, 0.993259447614414f, + 0.993068456954926f, 0.992874807552322f, 0.992678499925058f, 0.992479534598710f, + 0.992277912105967f, 0.992073632986633f, 0.991866697787626f, 0.991657107062973f, + 0.991444861373810f, 0.991229961288385f, 0.991012407382049f, 0.990792200237260f, + 0.990569340443577f, 0.990343828597665f, 0.990115665303286f, 0.989884851171301f, + 0.989651386819670f, 0.989415272873448f, 0.989176509964781f, 0.988935098732911f, + 0.988691039824167f, 0.988444333891970f, 0.988194981596825f, 0.987942983606322f, + 0.987688340595138f, 0.987431053245027f, 0.987171122244825f, 0.986908548290446f, + 0.986643332084879f, 0.986375474338188f, 0.986104975767509f, 0.985831837097047f, + 0.985556059058078f, 0.985277642388941f, 0.984996587835043f, 0.984712896148850f, + 0.984426568089892f, 0.984137604424753f, 0.983846005927077f, 0.983551773377562f, + 0.983254907563955f, 0.982955409281056f, 0.982653279330712f, 0.982348518521816f, + 0.982041127670304f, 0.981731107599154f, 0.981418459138384f, 0.981103183125046f, + 0.980785280403230f, 0.980464751824058f, 0.980141598245680f, 0.979815820533276f, + 0.979487419559051f, 0.979156396202234f, 0.978822751349072f, 0.978486485892835f, + 0.978147600733806f, 0.977806096779282f, 0.977461974943572f, 0.977115236147994f, + 0.976765881320872f, 0.976413911397535f, 0.976059327320311f, 0.975702130038529f, + 0.975342320508513f, 0.974979899693582f, 0.974614868564045f, 0.974247228097201f, + 0.973876979277334f, 0.973504123095711f, 0.973128660550580f, 0.972750592647168f, + 0.972369920397677f, 0.971986644821279f, 0.971600766944121f, 0.971212287799312f, + 0.970821208426928f, 0.970427529874007f, 0.970031253194544f, 0.969632379449492f, + 0.969230909706754f, 0.968826845041188f, 0.968420186534595f, 0.968010935275723f, + 0.967599092360260f, 0.967184658890834f, 0.966767635977008f, 0.966348024735277f, + 0.965925826289068f, 0.965501041768733f, 0.965073672311547f, 0.964643719061708f, + 0.964211183170329f, 0.963776065795440f, 0.963338368101980f, 0.962898091261798f, + 0.962455236453647f, 0.962009804863184f, 0.961561797682962f, 0.961111216112432f, + 0.960658061357935f, 0.960202334632705f, 0.959744037156857f, 0.959283170157394f, + 0.958819734868193f, 0.958353732530011f, 0.957885164390477f, 0.957414031704088f, + 0.956940335732209f, 0.956464077743065f, 0.955985259011744f, 0.955503880820186f, + 0.955019944457187f, 0.954533451218389f, 0.954044402406280f, 0.953552799330194f, + 0.953058643306297f, 0.952561935657595f, 0.952062677713924f, 0.951560870811948f, + 0.951056516295154f, 0.950549615513851f, 0.950040169825165f, 0.949528180593037f, + 0.949013649188214f, 0.948496576988253f, 0.947976965377510f, 0.947454815747144f, + 0.946930129495106f, 0.946402908026138f, 0.945873152751771f, 0.945340865090320f, + 0.944806046466878f, 0.944268698313317f, 0.943728822068278f, 0.943186419177173f, + 0.942641491092178f, 0.942094039272230f, 0.941544065183021f, 0.940991570296997f, + 0.940436556093355f, 0.939879024058033f, 0.939318975683713f, 0.938756412469813f, + 0.938191335922484f, 0.937623747554606f, 0.937053648885784f, 0.936481041442343f, + 0.935905926757326f, 0.935328306370488f, 0.934748181828292f, 0.934165554683908f, + 0.933580426497202f, 0.932992798834739f, 0.932402673269775f, 0.931810051382254f, + 0.931214934758804f, 0.930617324992729f, 0.930017223684012f, 0.929414632439304f, + 0.928809552871924f, 0.928201986601852f, 0.927591935255724f, 0.926979400466833f, + 0.926364383875118f, 0.925746887127164f, 0.925126911876195f, 0.924504459782072f, + 0.923879532511287f, 0.923252131736957f, 0.922622259138823f, 0.921989916403245f, + 0.921355105223193f, 0.920717827298248f, 0.920078084334595f, 0.919435878045019f, + 0.918791210148898f, 0.918144082372204f, 0.917494496447491f, 0.916842454113897f, + 0.916187957117136f, 0.915531007209492f, 0.914871606149819f, 0.914209755703531f, + 0.913545457642601f, 0.912878713745555f, 0.912209525797468f, 0.911537895589956f, + 0.910863824921176f, 0.910187315595818f, 0.909508369425101f, 0.908826988226768f, + 0.908143173825081f, 0.907456928050819f, 0.906768252741266f, 0.906077149740215f, + 0.905383620897955f, 0.904687668071273f, 0.903989293123443f, 0.903288497924226f, + 0.902585284349861f, 0.901879654283062f, 0.901171609613013f, 0.900461152235364f, + 0.899748284052222f, 0.899033006972149f, 0.898315322910159f, 0.897595233787707f, + 0.896872741532688f, 0.896147848079432f, 0.895420555368697f, 0.894690865347664f, + 0.893958779969932f, 0.893224301195515f, 0.892487430990834f, 0.891748171328711f, + 0.891006524188368f, 0.890262491555416f, 0.889516075421856f, 0.888767277786068f, + 0.888016100652807f, 0.887262546033203f, 0.886506615944746f, 0.885748312411291f, + 0.884987637463042f, 0.884224593136556f, 0.883459181474733f, 0.882691404526809f, + 0.881921264348355f, 0.881148763001268f, 0.880373902553765f, 0.879596685080383f, + 0.878817112661965f, 0.878035187385663f, 0.877250911344924f, 0.876464286639493f, + 0.875675315375400f, 0.874883999664958f, 0.874090341626759f, 0.873294343385663f, + 0.872496007072797f, 0.871695334825548f, 0.870892328787557f, 0.870086991108712f, + 0.869279323945144f, 0.868469329459222f, 0.867657009819544f, 0.866842367200935f, + 0.866025403784439f, 0.865206121757311f, 0.864384523313017f, 0.863560610651224f, + 0.862734385977792f, 0.861905851504774f, 0.861075009450407f, 0.860241862039105f, + 0.859406411501453f, 0.858568660074204f, 0.857728610000272f, 0.856886263528723f, + 0.856041622914771f, 0.855194690419775f, 0.854345468311227f, 0.853493958862751f, + 0.852640164354092f, 0.851784087071117f, 0.850925729305802f, 0.850065093356229f, + 0.849202181526579f, 0.848336996127127f, 0.847469539474235f, 0.846599813890344f, + 0.845727821703973f, 0.844853565249707f, 0.843977046868193f, 0.843098268906136f, + 0.842217233716287f, 0.841333943657443f, 0.840448401094438f, 0.839560608398136f, + 0.838670567945424f, 0.837778282119209f, 0.836883753308409f, 0.835986983907947f, + 0.835087976318743f, 0.834186732947712f, 0.833283256207754f, 0.832377548517748f, + 0.831469612302545f, 0.830559449992965f, 0.829647064025785f, 0.828732456843738f, + 0.827815630895502f, 0.826896588635696f, 0.825975332524873f, 0.825051865029513f, + 0.824126188622016f, 0.823198305780696f, 0.822268218989775f, 0.821335930739376f, + 0.820401443525514f, 0.819464759850093f, 0.818525882220897f, 0.817584813151584f, + 0.816641555161679f, 0.815696110776568f, 0.814748482527489f, 0.813798672951530f, + 0.812846684591615f, 0.811892519996505f, 0.810936181720784f, 0.809977672324859f, + 0.809016994374948f, 0.808054150443073f, 0.807089143107059f, 0.806121974950521f, + 0.805152648562858f, 0.804181166539250f, 0.803207531480645f, 0.802231745993758f, + 0.801253812691061f, 0.800273734190774f, 0.799291513116864f, 0.798307152099032f, + 0.797320653772707f, 0.796332020779044f, 0.795341255764910f, 0.794348361382882f, + 0.793353340291235f, 0.792356195153942f, 0.791356928640660f, 0.790355543426726f, + 0.789352042193150f, 0.788346427626606f, 0.787338702419428f, 0.786328869269598f, + 0.785316930880745f, 0.784302889962131f, 0.783286749228650f, 0.782268511400816f, + 0.781248179204759f, 0.780225755372213f, 0.779201242640517f, 0.778174643752598f, + 0.777145961456971f, 0.776115198507728f, 0.775082357664531f, 0.774047441692607f, + 0.773010453362737f, 0.771971395451250f, 0.770930270740018f, 0.769887082016445f, + 0.768841832073460f, 0.767794523709512f, 0.766745159728562f, 0.765693742940071f, + 0.764640276159000f, 0.763584762205796f, 0.762527203906388f, 0.761467604092177f, + 0.760405965600031f, 0.759342291272276f, 0.758276583956687f, 0.757208846506485f, + 0.756139081780323f, 0.755067292642284f, 0.753993481961869f, 0.752917652613995f, + 0.751839807478977f, 0.750759949442534f, 0.749678081395770f, 0.748594206235171f, + 0.747508326862597f, 0.746420446185274f, 0.745330567115786f, 0.744238692572067f, + 0.743144825477394f, 0.742048968760379f, 0.740951125354959f, 0.739851298200392f, + 0.738749490241246f, 0.737645704427393f, 0.736539943713999f, 0.735432211061519f, + 0.734322509435686f, 0.733210841807505f, 0.732097211153246f, 0.730981620454432f, + 0.729864072697836f, 0.728744570875469f, 0.727623117984575f, 0.726499717027620f, + 0.725374371012288f, 0.724247082951467f, 0.723117855863248f, 0.721986692770910f, + 0.720853596702919f, 0.719718570692913f, 0.718581617779698f, 0.717442741007240f, + 0.716301943424654f, 0.715159228086199f, 0.714014598051268f, 0.712868056384380f, + 0.711719606155171f, 0.710569250438390f, 0.709416992313883f, 0.708262834866593f, + 0.707106781186548f, 0.705948834368849f, 0.704788997513670f, 0.703627273726243f, + 0.702463666116852f, 0.701298177800824f, 0.700130811898524f, 0.698961571535339f, + 0.697790459841680f, 0.696617479952964f, 0.695442635009612f, 0.694265928157036f, + 0.693087362545636f, 0.691906941330786f, 0.690724667672829f, 0.689540544737067f, + 0.688354575693754f, 0.687166763718086f, 0.685977111990193f, 0.684785623695130f, + 0.683592302022871f, 0.682397150168297f, 0.681200171331188f, 0.680001368716218f, + 0.678800745532942f, 0.677598304995789f, 0.676394050324054f, 0.675187984741891f, + 0.673980111478298f, 0.672770433767117f, 0.671558954847018f, 0.670345677961497f, + 0.669130606358858f, 0.667913743292216f, 0.666695092019479f, 0.665474655803342f, + 0.664252437911282f, 0.663028441615542f, 0.661802670193130f, 0.660575126925805f, + 0.659345815100069f, 0.658114738007160f, 0.656881898943041f, 0.655647301208395f, + 0.654410948108610f, 0.653172842953777f, 0.651932989058674f, 0.650691389742765f, + 0.649448048330184f, 0.648202968149730f, 0.646956152534857f, 0.645707604823667f, + 0.644457328358897f, 0.643205326487914f, 0.641951602562703f, 0.640696159939861f, + 0.639439001980585f, 0.638180132050665f, 0.636919553520476f, 0.635657269764965f, + 0.634393284163646f, 0.633127600100588f, 0.631860220964409f, 0.630591150148264f, + 0.629320391049838f, 0.628047947071334f, 0.626773821619470f, 0.625498018105461f, + 0.624220539945018f, 0.622941390558334f, 0.621660573370077f, 0.620378091809381f, + 0.619093949309834f, 0.617808149309472f, 0.616520695250769f, 0.615231590580627f, + 0.613940838750366f, 0.612648443215719f, 0.611354407436817f, 0.610058734878182f, + 0.608761429008721f, 0.607462493301711f, 0.606161931234795f, 0.604859746289968f, + 0.603555941953571f, 0.602250521716282f, 0.600943489073102f, 0.599634847523352f, + 0.598324600570659f, 0.597012751722948f, 0.595699304492433f, 0.594384262395609f, + 0.593067628953237f, 0.591749407690343f, 0.590429602136201f, 0.589108215824328f, + 0.587785252292473f, 0.586460715082607f, 0.585134607740916f, 0.583806933817786f, + 0.582477696867802f, 0.581146900449730f, 0.579814548126514f, 0.578480643465260f, + 0.577145190037234f, 0.575808191417845f, 0.574469651186643f, 0.573129572927301f, + 0.571787960227612f, 0.570444816679478f, 0.569100145878898f, 0.567753951425961f, + 0.566406236924833f, 0.565057005983753f, 0.563706262215017f, 0.562354009234973f, + 0.561000250664010f, 0.559644990126546f, 0.558288231251022f, 0.556929977669890f, + 0.555570233019602f, 0.554209000940606f, 0.552846285077328f, 0.551482089078169f, + 0.550116416595494f, 0.548749271285616f, 0.547380656808797f, 0.546010576829228f, + 0.544639035015027f, 0.543266035038224f, 0.541891580574752f, 0.540515675304440f, + 0.539138322911000f, 0.537759527082020f, 0.536379291508950f, 0.534997619887097f, + 0.533614515915612f, 0.532229983297479f, 0.530844025739510f, 0.529456646952329f, + 0.528067850650368f, 0.526677640551852f, 0.525286020378792f, 0.523892993856974f, + 0.522498564715949f, 0.521102736689023f, 0.519705513513249f, 0.518306898929413f, + 0.516906896682028f, 0.515505510519320f, 0.514102744193222f, 0.512698601459362f, + 0.511293086077052f, 0.509886201809281f, 0.508477952422700f, 0.507068341687617f, + 0.505657373377985f, 0.504245051271389f, 0.502831379149042f, 0.501416360795769f, + 0.500000000000000f, 0.498582300553759f, 0.497163266252654f, 0.495742900895868f, + 0.494321208286145f, 0.492898192229784f, 0.491473856536628f, 0.490048205020053f, + 0.488621241496955f, 0.487192969787746f, 0.485763393716340f, 0.484332517110141f, + 0.482900343800037f, 0.481466877620387f, 0.480032122409011f, 0.478596082007181f, + 0.477158760259609f, 0.475720161014437f, 0.474280288123229f, 0.472839145440959f, + 0.471396736825998f, 0.469953066140108f, 0.468508137248432f, 0.467061954019477f, + 0.465614520325111f, 0.464165840040552f, 0.462715917044350f, 0.461264755218387f, + 0.459812358447860f, 0.458358730621271f, 0.456903875630421f, 0.455447797370393f, + 0.453990499739547f, 0.452531986639508f, 0.451072261975153f, 0.449611329654607f, + 0.448149193589223f, 0.446685857693580f, 0.445221325885468f, 0.443755602085881f, + 0.442288690219001f, 0.440820594212194f, 0.439351317995994f, 0.437880865504095f, + 0.436409240673342f, 0.434936447443717f, 0.433462489758331f, 0.431987371563412f, + 0.430511096808295f, 0.429033669445413f, 0.427555093430282f, 0.426075372721496f, + 0.424594511280713f, 0.423112513072644f, 0.421629382065045f, 0.420145122228703f, + 0.418659737537428f, 0.417173231968043f, 0.415685609500371f, 0.414196874117224f, + 0.412707029804395f, 0.411216080550645f, 0.409724030347695f, 0.408230883190212f, + 0.406736643075800f, 0.405241314004990f, 0.403744899981227f, 0.402247405010863f, + 0.400748833103141f, 0.399249188270190f, 0.397748474527011f, 0.396246695891466f, + 0.394743856384267f, 0.393239960028970f, 0.391735010851956f, 0.390229012882428f, + 0.388721970152396f, 0.387213886696666f, 0.385704766552831f, 0.384194613761262f, + 0.382683432365090f, 0.381171226410203f, 0.379657999945233f, 0.378143757021541f, + 0.376628501693211f, 0.375112238017038f, 0.373594970052516f, 0.372076701861829f, + 0.370557437509836f, 0.369037181064067f, 0.367515936594704f, 0.365993708174577f, + 0.364470499879150f, 0.362946315786509f, 0.361421159977355f, 0.359895036534988f, + 0.358367949545300f, 0.356839903096763f, 0.355310901280416f, 0.353780948189858f, + 0.352250047921234f, 0.350718204573223f, 0.349185422247033f, 0.347651705046382f, + 0.346117057077493f, 0.344581482449081f, 0.343044985272340f, 0.341507569660936f, + 0.339969239730994f, 0.338429999601086f, 0.336889853392220f, 0.335348805227832f, + 0.333806859233771f, 0.332264019538291f, 0.330720290272038f, 0.329175675568039f, + 0.327630179561693f, 0.326083806390759f, 0.324536560195342f, 0.322988445117886f, + 0.321439465303162f, 0.319889624898253f, 0.318338928052550f, 0.316787378917734f, + 0.315234981647770f, 0.313681740398892f, 0.312127659329594f, 0.310572742600619f, + 0.309016994374947f, 0.307460418817785f, 0.305903020096554f, 0.304344802380877f, + 0.302785769842575f, 0.301225926655645f, 0.299665276996257f, 0.298103825042740f, + 0.296541574975571f, 0.294978530977364f, 0.293414697232857f, 0.291850077928904f, + 0.290284677254463f, 0.288718499400580f, 0.287151548560387f, 0.285583828929082f, + 0.284015344703923f, 0.282446100084212f, 0.280876099271292f, 0.279305346468526f, + 0.277733845881292f, 0.276161601716971f, 0.274588618184932f, 0.273014899496527f, + 0.271440449865074f, 0.269865273505849f, 0.268289374636071f, 0.266712757474899f, + 0.265135426243408f, 0.263557385164591f, 0.261978638463337f, 0.260399190366428f, + 0.258819045102521f, 0.257238206902140f, 0.255656679997665f, 0.254074468623318f, + 0.252491577015158f, 0.250908009411060f, 0.249323770050712f, 0.247738863175598f, + 0.246153293028993f, 0.244567063855944f, 0.242980179903264f, 0.241392645419519f, + 0.239804464655017f, 0.238215641861795f, 0.236626181293610f, 0.235036087205927f, + 0.233445363855905f, 0.231854015502391f, 0.230262046405902f, 0.228669460828619f, + 0.227076263034373f, 0.225482457288634f, 0.223888047858498f, 0.222293039012681f, + 0.220697435021501f, 0.219101240156870f, 0.217504458692281f, 0.215907094902801f, + 0.214309153065051f, 0.212710637457203f, 0.211111552358965f, 0.209511902051569f, + 0.207911690817759f, 0.206310922941784f, 0.204709602709380f, 0.203107734407763f, + 0.201505322325617f, 0.199902370753082f, 0.198298883981741f, 0.196694866304610f, + 0.195090322016128f, 0.193485255412143f, 0.191879670789901f, 0.190273572448036f, + 0.188666964686555f, 0.187059851806832f, 0.185452238111591f, 0.183844127904898f, + 0.182235525492147f, 0.180626435180053f, 0.179016861276633f, 0.177406808091201f, + 0.175796279934354f, 0.174185281117962f, 0.172573815955152f, 0.170961888760301f, + 0.169349503849025f, 0.167736665538162f, 0.166123378145765f, 0.164509645991092f, + 0.162895473394589f, 0.161280864677881f, 0.159665824163761f, 0.158050356176180f, + 0.156434465040231f, 0.154818155082141f, 0.153201430629259f, 0.151584296010041f, + 0.149966755554045f, 0.148348813591913f, 0.146730474455362f, 0.145111742477173f, + 0.143492621991180f, 0.141873117332253f, 0.140253232836296f, 0.138632972840227f, + 0.137012341681968f, 0.135391343700438f, 0.133769983235535f, 0.132148264628130f, + 0.130526192220052f, 0.128903770354076f, 0.127281003373913f, 0.125657895624201f, + 0.124034451450485f, 0.122410675199216f, 0.120786571217731f, 0.119162143854244f, + 0.117537397457838f, 0.115912336378446f, 0.114286964966846f, 0.112661287574648f, + 0.111035308554278f, 0.109409032258971f, 0.107782463042760f, 0.106155605260457f, + 0.104528463267653f, 0.102901041420696f, 0.101273344076683f, 0.0996453755934510f, + 0.0980171403295608f, 0.0963886426442880f, 0.0947598868976111f, 0.0931308774501999f, + 0.0915016186634025f, 0.0898721148992351f, 0.0882423705203694f, 0.0866123898901223f, + 0.0849821773724418f, 0.0833517373318973f, 0.0817210741336683f, 0.0800901921435302f, + 0.0784590957278450f, 0.0768277892535488f, 0.0751962770881400f, 0.0735645635996675f, + 0.0719326531567196f, 0.0703005501284112f, 0.0686682588843738f, 0.0670357837947423f, + 0.0654031292301431f, 0.0637702995616845f, 0.0621372991609429f, 0.0605041323999515f, + 0.0588708036511890f, 0.0572373172875686f, 0.0556036776824248f, 0.0539698892095020f, + 0.0523359562429437f, 0.0507018831572809f, 0.0490676743274181f, 0.0474333341286244f, + 0.0457988669365209f, 0.0441642771270675f, 0.0425295690765532f, 0.0408947471615835f, + 0.0392598157590687f, 0.0376247792462120f, 0.0359896420004986f, 0.0343544083996823f, + 0.0327190828217762f, 0.0310836696450389f, 0.0294481732479632f, 0.0278125980092656f, + 0.0261769483078731f, 0.0245412285229125f, 0.0229054430336971f, 0.0212695962197177f, + 0.0196336924606285f, 0.0179977361362357f, 0.0163617316264867f, 0.0147256833114587f, + 0.0130895955713446f, 0.0114534727864437f, 0.00981731933714973f, 0.00818113960393724f, + 0.00654493796735196f, 0.00490871880799808f, 0.00327248650652671f, 0.00163624544362412f, + 0.00000000000000000f +}; + +const float ivas_mdft_coeff_sin_twid_960[IVAS_960_PT_LEN] = +{ + 0.00000000000000f, 0.00163624544362405f, 0.00327248650652663f, 0.00490871880799799f, + 0.00654493796735186f, 0.00818113960393713f, 0.00981731933714962f, 0.0114534727864438f, + 0.0130895955713444f, 0.0147256833114585f, 0.0163617316264868f, 0.0179977361362355f, + 0.0196336924606283f, 0.0212695962197177f, 0.0229054430336971f, 0.0245412285229123f, + 0.0261769483078732f, 0.0278125980092656f, 0.0294481732479632f, 0.0310836696450387f, + 0.0327190828217761f, 0.0343544083996823f, 0.0359896420004984f, 0.0376247792462120f, + 0.0392598157590686f, 0.0408947471615835f, 0.0425295690765531f, 0.0441642771270674f, + 0.0457988669365208f, 0.0474333341286245f, 0.0490676743274180f, 0.0507018831572807f, + 0.0523359562429438f, 0.0539698892095019f, 0.0556036776824246f, 0.0572373172875686f, + 0.0588708036511890f, 0.0605041323999513f, 0.0621372991609427f, 0.0637702995616845f, + 0.0654031292301431f, 0.0670357837947420f, 0.0686682588843738f, 0.0703005501284112f, + 0.0719326531567194f, 0.0735645635996674f, 0.0751962770881399f, 0.0768277892535488f, + 0.0784590957278449f, 0.0800901921435301f, 0.0817210741336682f, 0.0833517373318975f, + 0.0849821773724417f, 0.0866123898901222f, 0.0882423705203695f, 0.0898721148992350f, + 0.0915016186634024f, 0.0931308774501998f, 0.0947598868976111f, 0.0963886426442878f, + 0.0980171403295606f, 0.0996453755934511f, 0.101273344076683f, 0.102901041420696f, + 0.104528463267653f, 0.106155605260457f, 0.107782463042759f, 0.109409032258971f, + 0.111035308554278f, 0.112661287574648f, 0.114286964966846f, 0.115912336378446f, + 0.117537397457838f, 0.119162143854244f, 0.120786571217731f, 0.122410675199216f, + 0.124034451450485f, 0.125657895624201f, 0.127281003373913f, 0.128903770354075f, + 0.130526192220052f, 0.132148264628130f, 0.133769983235535f, 0.135391343700438f, + 0.137012341681968f, 0.138632972840227f, 0.140253232836296f, 0.141873117332253f, + 0.143492621991179f, 0.145111742477173f, 0.146730474455362f, 0.148348813591913f, + 0.149966755554045f, 0.151584296010041f, 0.153201430629258f, 0.154818155082141f, + 0.156434465040231f, 0.158050356176180f, 0.159665824163761f, 0.161280864677880f, + 0.162895473394589f, 0.164509645991092f, 0.166123378145765f, 0.167736665538162f, + 0.169349503849025f, 0.170961888760301f, 0.172573815955152f, 0.174185281117962f, + 0.175796279934355f, 0.177406808091201f, 0.179016861276633f, 0.180626435180053f, + 0.182235525492147f, 0.183844127904898f, 0.185452238111591f, 0.187059851806832f, + 0.188666964686555f, 0.190273572448036f, 0.191879670789901f, 0.193485255412143f, + 0.195090322016128f, 0.196694866304610f, 0.198298883981740f, 0.199902370753082f, + 0.201505322325617f, 0.203107734407763f, 0.204709602709380f, 0.206310922941784f, + 0.207911690817759f, 0.209511902051569f, 0.211111552358965f, 0.212710637457203f, + 0.214309153065051f, 0.215907094902801f, 0.217504458692281f, 0.219101240156870f, + 0.220697435021501f, 0.222293039012681f, 0.223888047858498f, 0.225482457288634f, + 0.227076263034373f, 0.228669460828619f, 0.230262046405902f, 0.231854015502391f, + 0.233445363855905f, 0.235036087205927f, 0.236626181293610f, 0.238215641861795f, + 0.239804464655017f, 0.241392645419519f, 0.242980179903264f, 0.244567063855944f, + 0.246153293028993f, 0.247738863175598f, 0.249323770050712f, 0.250908009411060f, + 0.252491577015158f, 0.254074468623319f, 0.255656679997664f, 0.257238206902140f, + 0.258819045102521f, 0.260399190366428f, 0.261978638463337f, 0.263557385164591f, + 0.265135426243408f, 0.266712757474898f, 0.268289374636071f, 0.269865273505849f, + 0.271440449865074f, 0.273014899496527f, 0.274588618184932f, 0.276161601716971f, + 0.277733845881292f, 0.279305346468526f, 0.280876099271292f, 0.282446100084212f, + 0.284015344703923f, 0.285583828929082f, 0.287151548560387f, 0.288718499400580f, + 0.290284677254462f, 0.291850077928904f, 0.293414697232857f, 0.294978530977364f, + 0.296541574975571f, 0.298103825042740f, 0.299665276996257f, 0.301225926655644f, + 0.302785769842575f, 0.304344802380877f, 0.305903020096553f, 0.307460418817785f, + 0.309016994374947f, 0.310572742600619f, 0.312127659329594f, 0.313681740398891f, + 0.315234981647770f, 0.316787378917734f, 0.318338928052550f, 0.319889624898253f, + 0.321439465303162f, 0.322988445117886f, 0.324536560195342f, 0.326083806390759f, + 0.327630179561694f, 0.329175675568039f, 0.330720290272037f, 0.332264019538291f, + 0.333806859233771f, 0.335348805227832f, 0.336889853392220f, 0.338429999601086f, + 0.339969239730994f, 0.341507569660936f, 0.343044985272340f, 0.344581482449080f, + 0.346117057077493f, 0.347651705046382f, 0.349185422247033f, 0.350718204573223f, + 0.352250047921234f, 0.353780948189858f, 0.355310901280416f, 0.356839903096763f, + 0.358367949545300f, 0.359895036534988f, 0.361421159977355f, 0.362946315786509f, + 0.364470499879150f, 0.365993708174577f, 0.367515936594704f, 0.369037181064066f, + 0.370557437509836f, 0.372076701861829f, 0.373594970052516f, 0.375112238017038f, + 0.376628501693211f, 0.378143757021540f, 0.379657999945233f, 0.381171226410203f, + 0.382683432365090f, 0.384194613761262f, 0.385704766552831f, 0.387213886696666f, + 0.388721970152396f, 0.390229012882428f, 0.391735010851956f, 0.393239960028970f, + 0.394743856384267f, 0.396246695891466f, 0.397748474527011f, 0.399249188270190f, + 0.400748833103141f, 0.402247405010863f, 0.403744899981227f, 0.405241314004990f, + 0.406736643075800f, 0.408230883190212f, 0.409724030347695f, 0.411216080550645f, + 0.412707029804395f, 0.414196874117224f, 0.415685609500371f, 0.417173231968043f, + 0.418659737537428f, 0.420145122228702f, 0.421629382065045f, 0.423112513072644f, + 0.424594511280713f, 0.426075372721496f, 0.427555093430282f, 0.429033669445413f, + 0.430511096808295f, 0.431987371563412f, 0.433462489758331f, 0.434936447443717f, + 0.436409240673342f, 0.437880865504095f, 0.439351317995994f, 0.440820594212194f, + 0.442288690219001f, 0.443755602085881f, 0.445221325885468f, 0.446685857693580f, + 0.448149193589223f, 0.449611329654607f, 0.451072261975153f, 0.452531986639508f, + 0.453990499739547f, 0.455447797370393f, 0.456903875630421f, 0.458358730621271f, + 0.459812358447860f, 0.461264755218387f, 0.462715917044350f, 0.464165840040552f, + 0.465614520325111f, 0.467061954019477f, 0.468508137248431f, 0.469953066140108f, + 0.471396736825998f, 0.472839145440959f, 0.474280288123229f, 0.475720161014437f, + 0.477158760259608f, 0.478596082007181f, 0.480032122409011f, 0.481466877620387f, + 0.482900343800037f, 0.484332517110141f, 0.485763393716340f, 0.487192969787746f, + 0.488621241496955f, 0.490048205020053f, 0.491473856536628f, 0.492898192229784f, + 0.494321208286145f, 0.495742900895868f, 0.497163266252654f, 0.498582300553759f, + 0.500000000000000f, 0.501416360795769f, 0.502831379149042f, 0.504245051271389f, + 0.505657373377985f, 0.507068341687617f, 0.508477952422700f, 0.509886201809281f, + 0.511293086077052f, 0.512698601459362f, 0.514102744193222f, 0.515505510519320f, + 0.516906896682028f, 0.518306898929413f, 0.519705513513249f, 0.521102736689023f, + 0.522498564715949f, 0.523892993856974f, 0.525286020378792f, 0.526677640551852f, + 0.528067850650368f, 0.529456646952329f, 0.530844025739509f, 0.532229983297479f, + 0.533614515915612f, 0.534997619887097f, 0.536379291508950f, 0.537759527082020f, + 0.539138322911000f, 0.540515675304440f, 0.541891580574752f, 0.543266035038224f, + 0.544639035015027f, 0.546010576829228f, 0.547380656808797f, 0.548749271285616f, + 0.550116416595493f, 0.551482089078169f, 0.552846285077328f, 0.554209000940606f, + 0.555570233019602f, 0.556929977669889f, 0.558288231251022f, 0.559644990126546f, + 0.561000250664010f, 0.562354009234973f, 0.563706262215017f, 0.565057005983753f, + 0.566406236924833f, 0.567753951425961f, 0.569100145878898f, 0.570444816679478f, + 0.571787960227612f, 0.573129572927301f, 0.574469651186643f, 0.575808191417845f, + 0.577145190037234f, 0.578480643465260f, 0.579814548126514f, 0.581146900449730f, + 0.582477696867802f, 0.583806933817786f, 0.585134607740916f, 0.586460715082607f, + 0.587785252292473f, 0.589108215824328f, 0.590429602136201f, 0.591749407690343f, + 0.593067628953237f, 0.594384262395609f, 0.595699304492433f, 0.597012751722948f, + 0.598324600570659f, 0.599634847523352f, 0.600943489073102f, 0.602250521716282f, + 0.603555941953571f, 0.604859746289968f, 0.606161931234795f, 0.607462493301711f, + 0.608761429008721f, 0.610058734878182f, 0.611354407436817f, 0.612648443215719f, + 0.613940838750366f, 0.615231590580627f, 0.616520695250769f, 0.617808149309472f, + 0.619093949309834f, 0.620378091809381f, 0.621660573370077f, 0.622941390558334f, + 0.624220539945018f, 0.625498018105461f, 0.626773821619470f, 0.628047947071334f, + 0.629320391049838f, 0.630591150148264f, 0.631860220964409f, 0.633127600100588f, + 0.634393284163646f, 0.635657269764965f, 0.636919553520476f, 0.638180132050665f, + 0.639439001980585f, 0.640696159939861f, 0.641951602562703f, 0.643205326487914f, + 0.644457328358897f, 0.645707604823667f, 0.646956152534857f, 0.648202968149730f, + 0.649448048330184f, 0.650691389742765f, 0.651932989058674f, 0.653172842953777f, + 0.654410948108610f, 0.655647301208395f, 0.656881898943041f, 0.658114738007160f, + 0.659345815100069f, 0.660575126925805f, 0.661802670193130f, 0.663028441615542f, + 0.664252437911282f, 0.665474655803342f, 0.666695092019479f, 0.667913743292216f, + 0.669130606358858f, 0.670345677961497f, 0.671558954847018f, 0.672770433767117f, + 0.673980111478298f, 0.675187984741891f, 0.676394050324054f, 0.677598304995789f, + 0.678800745532942f, 0.680001368716218f, 0.681200171331188f, 0.682397150168297f, + 0.683592302022871f, 0.684785623695130f, 0.685977111990193f, 0.687166763718086f, + 0.688354575693754f, 0.689540544737067f, 0.690724667672829f, 0.691906941330786f, + 0.693087362545636f, 0.694265928157036f, 0.695442635009612f, 0.696617479952964f, + 0.697790459841680f, 0.698961571535339f, 0.700130811898524f, 0.701298177800824f, + 0.702463666116852f, 0.703627273726243f, 0.704788997513670f, 0.705948834368849f, + 0.707106781186548f, 0.708262834866593f, 0.709416992313883f, 0.710569250438390f, + 0.711719606155171f, 0.712868056384380f, 0.714014598051268f, 0.715159228086199f, + 0.716301943424654f, 0.717442741007240f, 0.718581617779698f, 0.719718570692913f, + 0.720853596702919f, 0.721986692770910f, 0.723117855863248f, 0.724247082951467f, + 0.725374371012288f, 0.726499717027620f, 0.727623117984575f, 0.728744570875469f, + 0.729864072697836f, 0.730981620454432f, 0.732097211153246f, 0.733210841807505f, + 0.734322509435686f, 0.735432211061519f, 0.736539943713999f, 0.737645704427393f, + 0.738749490241246f, 0.739851298200392f, 0.740951125354959f, 0.742048968760379f, + 0.743144825477394f, 0.744238692572067f, 0.745330567115786f, 0.746420446185274f, + 0.747508326862597f, 0.748594206235171f, 0.749678081395770f, 0.750759949442534f, + 0.751839807478977f, 0.752917652613995f, 0.753993481961869f, 0.755067292642284f, + 0.756139081780323f, 0.757208846506485f, 0.758276583956687f, 0.759342291272275f, + 0.760405965600031f, 0.761467604092177f, 0.762527203906388f, 0.763584762205796f, + 0.764640276159000f, 0.765693742940071f, 0.766745159728561f, 0.767794523709512f, + 0.768841832073460f, 0.769887082016445f, 0.770930270740018f, 0.771971395451250f, + 0.773010453362737f, 0.774047441692607f, 0.775082357664531f, 0.776115198507728f, + 0.777145961456971f, 0.778174643752598f, 0.779201242640517f, 0.780225755372213f, + 0.781248179204759f, 0.782268511400816f, 0.783286749228650f, 0.784302889962131f, + 0.785316930880745f, 0.786328869269598f, 0.787338702419428f, 0.788346427626606f, + 0.789352042193150f, 0.790355543426726f, 0.791356928640660f, 0.792356195153942f, + 0.793353340291235f, 0.794348361382881f, 0.795341255764910f, 0.796332020779044f, + 0.797320653772707f, 0.798307152099032f, 0.799291513116864f, 0.800273734190774f, + 0.801253812691061f, 0.802231745993758f, 0.803207531480645f, 0.804181166539250f, + 0.805152648562858f, 0.806121974950521f, 0.807089143107059f, 0.808054150443073f, + 0.809016994374948f, 0.809977672324859f, 0.810936181720784f, 0.811892519996505f, + 0.812846684591615f, 0.813798672951530f, 0.814748482527489f, 0.815696110776568f, + 0.816641555161679f, 0.817584813151584f, 0.818525882220897f, 0.819464759850093f, + 0.820401443525514f, 0.821335930739376f, 0.822268218989775f, 0.823198305780696f, + 0.824126188622016f, 0.825051865029513f, 0.825975332524873f, 0.826896588635696f, + 0.827815630895502f, 0.828732456843738f, 0.829647064025785f, 0.830559449992965f, + 0.831469612302545f, 0.832377548517748f, 0.833283256207754f, 0.834186732947712f, + 0.835087976318743f, 0.835986983907947f, 0.836883753308409f, 0.837778282119209f, + 0.838670567945424f, 0.839560608398136f, 0.840448401094438f, 0.841333943657443f, + 0.842217233716287f, 0.843098268906135f, 0.843977046868193f, 0.844853565249707f, + 0.845727821703973f, 0.846599813890344f, 0.847469539474234f, 0.848336996127127f, + 0.849202181526579f, 0.850065093356229f, 0.850925729305802f, 0.851784087071117f, + 0.852640164354092f, 0.853493958862750f, 0.854345468311227f, 0.855194690419775f, + 0.856041622914771f, 0.856886263528723f, 0.857728610000272f, 0.858568660074204f, + 0.859406411501453f, 0.860241862039105f, 0.861075009450407f, 0.861905851504774f, + 0.862734385977792f, 0.863560610651224f, 0.864384523313017f, 0.865206121757311f, + 0.866025403784439f, 0.866842367200935f, 0.867657009819544f, 0.868469329459222f, + 0.869279323945144f, 0.870086991108711f, 0.870892328787557f, 0.871695334825548f, + 0.872496007072797f, 0.873294343385663f, 0.874090341626759f, 0.874883999664958f, + 0.875675315375400f, 0.876464286639493f, 0.877250911344924f, 0.878035187385663f, + 0.878817112661965f, 0.879596685080383f, 0.880373902553765f, 0.881148763001268f, + 0.881921264348355f, 0.882691404526809f, 0.883459181474733f, 0.884224593136556f, + 0.884987637463042f, 0.885748312411291f, 0.886506615944746f, 0.887262546033203f, + 0.888016100652807f, 0.888767277786068f, 0.889516075421856f, 0.890262491555416f, + 0.891006524188368f, 0.891748171328711f, 0.892487430990834f, 0.893224301195515f, + 0.893958779969932f, 0.894690865347664f, 0.895420555368697f, 0.896147848079432f, + 0.896872741532688f, 0.897595233787707f, 0.898315322910159f, 0.899033006972149f, + 0.899748284052221f, 0.900461152235364f, 0.901171609613013f, 0.901879654283062f, + 0.902585284349861f, 0.903288497924226f, 0.903989293123443f, 0.904687668071273f, + 0.905383620897955f, 0.906077149740215f, 0.906768252741266f, 0.907456928050819f, + 0.908143173825081f, 0.908826988226768f, 0.909508369425101f, 0.910187315595818f, + 0.910863824921176f, 0.911537895589956f, 0.912209525797468f, 0.912878713745555f, + 0.913545457642601f, 0.914209755703531f, 0.914871606149819f, 0.915531007209492f, + 0.916187957117136f, 0.916842454113898f, 0.917494496447491f, 0.918144082372204f, + 0.918791210148898f, 0.919435878045019f, 0.920078084334595f, 0.920717827298248f, + 0.921355105223192f, 0.921989916403245f, 0.922622259138823f, 0.923252131736957f, + 0.923879532511287f, 0.924504459782072f, 0.925126911876195f, 0.925746887127164f, + 0.926364383875118f, 0.926979400466833f, 0.927591935255724f, 0.928201986601852f, + 0.928809552871924f, 0.929414632439304f, 0.930017223684012f, 0.930617324992729f, + 0.931214934758804f, 0.931810051382254f, 0.932402673269775f, 0.932992798834739f, + 0.933580426497202f, 0.934165554683908f, 0.934748181828292f, 0.935328306370488f, + 0.935905926757326f, 0.936481041442343f, 0.937053648885784f, 0.937623747554606f, + 0.938191335922484f, 0.938756412469813f, 0.939318975683713f, 0.939879024058033f, + 0.940436556093355f, 0.940991570296997f, 0.941544065183021f, 0.942094039272230f, + 0.942641491092178f, 0.943186419177173f, 0.943728822068278f, 0.944268698313317f, + 0.944806046466878f, 0.945340865090320f, 0.945873152751771f, 0.946402908026138f, + 0.946930129495106f, 0.947454815747144f, 0.947976965377510f, 0.948496576988253f, + 0.949013649188214f, 0.949528180593037f, 0.950040169825165f, 0.950549615513851f, + 0.951056516295154f, 0.951560870811948f, 0.952062677713924f, 0.952561935657595f, + 0.953058643306297f, 0.953552799330193f, 0.954044402406280f, 0.954533451218389f, + 0.955019944457187f, 0.955503880820186f, 0.955985259011744f, 0.956464077743065f, + 0.956940335732209f, 0.957414031704088f, 0.957885164390477f, 0.958353732530011f, + 0.958819734868193f, 0.959283170157394f, 0.959744037156857f, 0.960202334632705f, + 0.960658061357935f, 0.961111216112432f, 0.961561797682962f, 0.962009804863184f, + 0.962455236453647f, 0.962898091261798f, 0.963338368101980f, 0.963776065795440f, + 0.964211183170329f, 0.964643719061708f, 0.965073672311547f, 0.965501041768733f, + 0.965925826289068f, 0.966348024735277f, 0.966767635977008f, 0.967184658890834f, + 0.967599092360260f, 0.968010935275723f, 0.968420186534595f, 0.968826845041188f, + 0.969230909706754f, 0.969632379449491f, 0.970031253194544f, 0.970427529874007f, + 0.970821208426928f, 0.971212287799312f, 0.971600766944121f, 0.971986644821279f, + 0.972369920397677f, 0.972750592647168f, 0.973128660550580f, 0.973504123095711f, + 0.973876979277334f, 0.974247228097201f, 0.974614868564045f, 0.974979899693582f, + 0.975342320508513f, 0.975702130038529f, 0.976059327320311f, 0.976413911397535f, + 0.976765881320872f, 0.977115236147994f, 0.977461974943572f, 0.977806096779282f, + 0.978147600733806f, 0.978486485892835f, 0.978822751349072f, 0.979156396202234f, + 0.979487419559051f, 0.979815820533276f, 0.980141598245680f, 0.980464751824058f, + 0.980785280403230f, 0.981103183125046f, 0.981418459138384f, 0.981731107599154f, + 0.982041127670304f, 0.982348518521816f, 0.982653279330712f, 0.982955409281056f, + 0.983254907563955f, 0.983551773377562f, 0.983846005927077f, 0.984137604424753f, + 0.984426568089892f, 0.984712896148850f, 0.984996587835043f, 0.985277642388941f, + 0.985556059058078f, 0.985831837097047f, 0.986104975767509f, 0.986375474338188f, + 0.986643332084879f, 0.986908548290446f, 0.987171122244825f, 0.987431053245027f, + 0.987688340595138f, 0.987942983606322f, 0.988194981596825f, 0.988444333891970f, + 0.988691039824167f, 0.988935098732911f, 0.989176509964781f, 0.989415272873448f, + 0.989651386819670f, 0.989884851171301f, 0.990115665303286f, 0.990343828597665f, + 0.990569340443577f, 0.990792200237260f, 0.991012407382049f, 0.991229961288385f, + 0.991444861373810f, 0.991657107062973f, 0.991866697787626f, 0.992073632986633f, + 0.992277912105967f, 0.992479534598710f, 0.992678499925058f, 0.992874807552322f, + 0.993068456954926f, 0.993259447614414f, 0.993447779019444f, 0.993633450665799f, + 0.993816462056378f, 0.993996812701206f, 0.994174502117428f, 0.994349529829318f, + 0.994521895368273f, 0.994691598272820f, 0.994858638088611f, 0.995023014368432f, + 0.995184726672197f, 0.995343774566954f, 0.995500157626885f, 0.995653875433303f, + 0.995804927574662f, 0.995953313646548f, 0.996099033251687f, 0.996242085999945f, + 0.996382471508325f, 0.996520189400975f, 0.996655239309180f, 0.996787620871373f, + 0.996917333733128f, 0.997044377547164f, 0.997168751973348f, 0.997290456678690f, + 0.997409491337352f, 0.997525855630641f, 0.997639549247016f, 0.997750571882084f, + 0.997858923238604f, 0.997964603026487f, 0.998067610962796f, 0.998167946771749f, + 0.998265610184716f, 0.998360600940223f, 0.998452918783950f, 0.998542563468736f, + 0.998629534754574f, 0.998713832408616f, 0.998795456205172f, 0.998874405925711f, + 0.998950681358860f, 0.999024282300407f, 0.999095208553300f, 0.999163459927649f, + 0.999229036240723f, 0.999291937316955f, 0.999352162987941f, 0.999409713092437f, + 0.999464587476366f, 0.999516785992811f, 0.999566308502021f, 0.999613154871411f, + 0.999657324975557f, 0.999698818696204f, 0.999737635922260f, 0.999773776549800f, + 0.999807240482065f, 0.999838027629461f, 0.999866137909562f, 0.999891571247108f, + 0.999914327574007f, 0.999934406829333f, 0.999951808959328f, 0.999966533917401f, + 0.999978581664129f, 0.999987952167257f, 0.999994645401697f, 0.999998661349528f +}; + + +const float ivas_mdft_coeff_cos_twid_640[IVAS_640_PT_LEN +1] = +{ + 1.00000000000000f, 0.999996988037278f, 0.999987952167257f, 0.999972892444367f, + 0.999951808959328f, 0.999924701839145f, 0.999891571247108f, 0.999852417382795f, + 0.999807240482065f, 0.999756040817060f, 0.999698818696204f, 0.999635574464198f, + 0.999566308502021f, 0.999491021226926f, 0.999409713092437f, 0.999322384588350f, + 0.999229036240723f, 0.999129668611881f, 0.999024282300407f, 0.998912877941140f, + 0.998795456205172f, 0.998672017799843f, 0.998542563468736f, 0.998407093991674f, + 0.998265610184716f, 0.998118112900149f, 0.997964603026487f, 0.997805081488460f, + 0.997639549247016f, 0.997468007299307f, 0.997290456678690f, 0.997106898454717f, + 0.996917333733128f, 0.996721763655847f, 0.996520189400975f, 0.996312612182778f, + 0.996099033251687f, 0.995879453894286f, 0.995653875433303f, 0.995422299227608f, + 0.995184726672197f, 0.994941159198190f, 0.994691598272820f, 0.994436045399422f, + 0.994174502117428f, 0.993906970002356f, 0.993633450665799f, 0.993353945755417f, + 0.993068456954926f, 0.992776985984091f, 0.992479534598710f, 0.992176104590609f, + 0.991866697787626f, 0.991551316053606f, 0.991229961288385f, 0.990902635427780f, + 0.990569340443577f, 0.990230078343521f, 0.989884851171301f, 0.989533661006540f, + 0.989176509964781f, 0.988813400197476f, 0.988444333891970f, 0.988069313271492f, + 0.987688340595138f, 0.987301418157858f, 0.986908548290446f, 0.986509733359519f, + 0.986104975767509f, 0.985694277952645f, 0.985277642388941f, 0.984855071586178f, + 0.984426568089892f, 0.983992134481354f, 0.983551773377562f, 0.983105487431216f, + 0.982653279330712f, 0.982195151800116f, 0.981731107599154f, 0.981261149523195f, + 0.980785280403230f, 0.980303503105861f, 0.979815820533276f, 0.979322235623241f, + 0.978822751349072f, 0.978317370719628f, 0.977806096779282f, 0.977288932607910f, + 0.976765881320872f, 0.976236946068990f, 0.975702130038529f, 0.975161436451181f, + 0.974614868564045f, 0.974062429669605f, 0.973504123095711f, 0.972939952205560f, + 0.972369920397677f, 0.971794031105889f, 0.971212287799312f, 0.970624693982323f, + 0.970031253194544f, 0.969431969010818f, 0.968826845041188f, 0.968215884930876f, + 0.967599092360260f, 0.966976471044852f, 0.966348024735277f, 0.965713757217249f, + 0.965073672311547f, 0.964427773873996f, 0.963776065795440f, 0.963118552001719f, + 0.962455236453647f, 0.961786123146989f, 0.961111216112432f, 0.960430519415566f, + 0.959744037156857f, 0.959051773471624f, 0.958353732530011f, 0.957649918536965f, + 0.956940335732209f, 0.956224988390216f, 0.955503880820186f, 0.954777017366017f, + 0.954044402406280f, 0.953306040354194f, 0.952561935657595f, 0.951812092798916f, + 0.951056516295154f, 0.950295210697844f, 0.949528180593037f, 0.948755430601263f, + 0.947976965377510f, 0.947192789611197f, 0.946402908026138f, 0.945607325380521f, + 0.944806046466878f, 0.943999076112052f, 0.943186419177173f, 0.942368080557626f, + 0.941544065183021f, 0.940714378017165f, 0.939879024058033f, 0.939038008337734f, + 0.938191335922484f, 0.937339011912575f, 0.936481041442343f, 0.935617429680138f, + 0.934748181828292f, 0.933873303123092f, 0.932992798834739f, 0.932106674267327f, + 0.931214934758804f, 0.930317585680942f, 0.929414632439304f, 0.928506080473216f, + 0.927591935255724f, 0.926672202293573f, 0.925746887127164f, 0.924815995330528f, + 0.923879532511287f, 0.922937504310623f, 0.921989916403245f, 0.921036774497350f, + 0.920078084334595f, 0.919113851690058f, 0.918144082372204f, 0.917168782222852f, + 0.916187957117136f, 0.915201612963474f, 0.914209755703531f, 0.913212391312179f, + 0.912209525797468f, 0.911201165200584f, 0.910187315595818f, 0.909167983090522f, + 0.908143173825081f, 0.907112893972869f, 0.906077149740215f, 0.905035947366364f, + 0.903989293123443f, 0.902937193316419f, 0.901879654283062f, 0.900816682393908f, + 0.899748284052222f, 0.898674465693954f, 0.897595233787707f, 0.896510594834693f, + 0.895420555368697f, 0.894325121956035f, 0.893224301195515f, 0.892118099718401f, + 0.891006524188368f, 0.889889581301463f, 0.888767277786068f, 0.887639620402854f, + 0.886506615944746f, 0.885368271236879f, 0.884224593136556f, 0.883075588533209f, + 0.881921264348355f, 0.880761627535558f, 0.879596685080383f, 0.878426444000357f, + 0.877250911344924f, 0.876070094195407f, 0.874883999664958f, 0.873692634898524f, + 0.872496007072797f, 0.871294123396174f, 0.870086991108712f, 0.868874617482085f, + 0.867657009819544f, 0.866434175455865f, 0.865206121757311f, 0.863972856121587f, + 0.862734385977792f, 0.861490718786378f, 0.860241862039105f, 0.858987823258990f, + 0.857728610000272f, 0.856464229848356f, 0.855194690419775f, 0.853919999362139f, + 0.852640164354092f, 0.851355193105265f, 0.850065093356229f, 0.848769872878448f, + 0.847469539474235f, 0.846164100976699f, 0.844853565249707f, 0.843537940187827f, + 0.842217233716287f, 0.840891453790923f, 0.839560608398136f, 0.838224705554838f, + 0.836883753308409f, 0.835537759736646f, 0.834186732947712f, 0.832830681080094f, + 0.831469612302545f, 0.830103534814044f, 0.828732456843738f, 0.827356386650900f, + 0.825975332524873f, 0.824589302785025f, 0.823198305780696f, 0.821802349891147f, + 0.820401443525514f, 0.818995595122750f, 0.817584813151584f, 0.816169106110459f, + 0.814748482527489f, 0.813322950960406f, 0.811892519996505f, 0.810457198252595f, + 0.809016994374948f, 0.807571917039244f, 0.806121974950521f, 0.804667176843123f, + 0.803207531480645f, 0.801743047655882f, 0.800273734190774f, 0.798799599936358f, + 0.797320653772707f, 0.795836904608884f, 0.794348361382882f, 0.792855033061574f, + 0.791356928640660f, 0.789854057144609f, 0.788346427626606f, 0.786834049168500f, + 0.785316930880745f, 0.783795081902349f, 0.782268511400816f, 0.780737228572095f, + 0.779201242640517f, 0.777660562858748f, 0.776115198507728f, 0.774565158896617f, + 0.773010453362737f, 0.771451091271519f, 0.769887082016445f, 0.768318435018988f, + 0.766745159728562f, 0.765167265622459f, 0.763584762205797f, 0.761997659011457f, + 0.760405965600031f, 0.758809691559762f, 0.757208846506485f, 0.755603440083571f, + 0.753993481961870f, 0.752378981839648f, 0.750759949442534f, 0.749136394523459f, + 0.747508326862597f, 0.745875756267305f, 0.744238692572067f, 0.742597145638433f, + 0.740951125354959f, 0.739300641637149f, 0.737645704427393f, 0.735986323694910f, + 0.734322509435686f, 0.732654271672413f, 0.730981620454432f, 0.729304565857669f, + 0.727623117984575f, 0.725937286964068f, 0.724247082951467f, 0.722552516128436f, + 0.720853596702919f, 0.719150334909079f, 0.717442741007240f, 0.715730825283819f, + 0.714014598051268f, 0.712294069648014f, 0.710569250438390f, 0.708840150812579f, + 0.707106781186548f, 0.705369152001986f, 0.703627273726243f, 0.701881156852263f, + 0.700130811898524f, 0.698376249408973f, 0.696617479952964f, 0.694854514125194f, + 0.693087362545636f, 0.691316035859480f, 0.689540544737067f, 0.687760899873822f, + 0.685977111990193f, 0.684189191831585f, 0.682397150168297f, 0.680600997795453f, + 0.678800745532942f, 0.676996404225349f, 0.675187984741891f, 0.673375497976352f, + 0.671558954847018f, 0.669738366296610f, 0.667913743292216f, 0.666085096825230f, + 0.664252437911282f, 0.662415777590172f, 0.660575126925805f, 0.658730497006124f, + 0.656881898943041f, 0.655029343872374f, 0.653172842953777f, 0.651312407370671f, + 0.649448048330184f, 0.647579777063073f, 0.645707604823667f, 0.643831542889792f, + 0.641951602562703f, 0.640067795167023f, 0.638180132050665f, 0.636288624584773f, + 0.634393284163646f, 0.632494122204673f, 0.630591150148264f, 0.628684379457781f, + 0.626773821619470f, 0.624859488142386f, 0.622941390558334f, 0.621019540421789f, + 0.619093949309834f, 0.617164628822086f, 0.615231590580627f, 0.613294846229936f, + 0.611354407436817f, 0.609410285890327f, 0.607462493301711f, 0.605511041404326f, + 0.603555941953571f, 0.601597206726822f, 0.599634847523352f, 0.597668876164268f, + 0.595699304492433f, 0.593726144372402f, 0.591749407690343f, 0.589769106353971f, + 0.587785252292473f, 0.585797857456439f, 0.583806933817786f, 0.581812493369691f, + 0.579814548126514f, 0.577813110123727f, 0.575808191417845f, 0.573799804086349f, + 0.571787960227612f, 0.569772671960834f, 0.567753951425961f, 0.565731810783613f, + 0.563706262215017f, 0.561677317921925f, 0.559644990126546f, 0.557609291071472f, + 0.555570233019602f, 0.553527828254070f, 0.551482089078169f, 0.549433027815281f, + 0.547380656808797f, 0.545324988422047f, 0.543266035038224f, 0.541203809060310f, + 0.539138322911000f, 0.537069589032630f, 0.534997619887097f, 0.532922427955790f, + 0.530844025739510f, 0.528762425758396f, 0.526677640551852f, 0.524589682678469f, + 0.522498564715949f, 0.520404299261031f, 0.518306898929413f, 0.516206376355680f, + 0.514102744193222f, 0.511996015114163f, 0.509886201809281f, 0.507773316987935f, + 0.505657373377985f, 0.503538383725718f, 0.501416360795769f, 0.499291317371047f, + 0.497163266252654f, 0.495032220259813f, 0.492898192229784f, 0.490761195017794f, + 0.488621241496955f, 0.486478344558187f, 0.484332517110141f, 0.482183772079123f, + 0.480032122409011f, 0.477877581061184f, 0.475720161014437f, 0.473559875264908f, + 0.471396736825998f, 0.469230758728290f, 0.467061954019477f, 0.464890335764274f, + 0.462715917044350f, 0.460538710958240f, 0.458358730621271f, 0.456175989165483f, + 0.453990499739547f, 0.451802275508688f, 0.449611329654607f, 0.447417675375397f, + 0.445221325885468f, 0.443022294415467f, 0.440820594212194f, 0.438616238538528f, + 0.436409240673342f, 0.434199613911428f, 0.431987371563412f, 0.429772526955677f, + 0.427555093430282f, 0.425335084344881f, 0.423112513072644f, 0.420887393002174f, + 0.418659737537428f, 0.416429560097637f, 0.414196874117224f, 0.411961693045722f, + 0.409724030347695f, 0.407483899502658f, 0.405241314004990f, 0.402996287363860f, + 0.400748833103141f, 0.398498964761330f, 0.396246695891466f, 0.393992040061048f, + 0.391735010851956f, 0.389475621860365f, 0.387213886696666f, 0.384949818985382f, + 0.382683432365090f, 0.380414740488332f, 0.378143757021541f, 0.375870495644950f, + 0.373594970052516f, 0.371317193951838f, 0.369037181064066f, 0.366754945123831f, + 0.364470499879150f, 0.362183859091351f, 0.359895036534988f, 0.357604045997758f, + 0.355310901280416f, 0.353015616196696f, 0.350718204573223f, 0.348418680249435f, + 0.346117057077493f, 0.343813348922205f, 0.341507569660936f, 0.339199733183530f, + 0.336889853392220f, 0.334577944201551f, 0.332264019538291f, 0.329948093341349f, + 0.327630179561693f, 0.325310292162263f, 0.322988445117886f, 0.320664652415197f, + 0.318338928052550f, 0.316011286039934f, 0.313681740398892f, 0.311350305162432f, + 0.309016994374947f, 0.306681822092128f, 0.304344802380877f, 0.302005949319228f, + 0.299665276996257f, 0.297322799511999f, 0.294978530977364f, 0.292632485514051f, + 0.290284677254463f, 0.287935120341621f, 0.285583828929082f, 0.283230817180850f, + 0.280876099271292f, 0.278519689385053f, 0.276161601716971f, 0.273801850471989f, + 0.271440449865074f, 0.269077414121127f, 0.266712757474898f, 0.264346494170904f, + 0.261978638463337f, 0.259609204615985f, 0.257238206902140f, 0.254865659604515f, + 0.252491577015158f, 0.250115973435366f, 0.247738863175599f, 0.245360260555389f, + 0.242980179903264f, 0.240598635556650f, 0.238215641861795f, 0.235831213173673f, + 0.233445363855905f, 0.231058108280671f, 0.228669460828619f, 0.226279435888785f, + 0.223888047858498f, 0.221495311143304f, 0.219101240156870f, 0.216705849320900f, + 0.214309153065051f, 0.211911165826842f, 0.209511902051569f, 0.207111376192219f, + 0.204709602709380f, 0.202306596071156f, 0.199902370753082f, 0.197496941238030f, + 0.195090322016128f, 0.192682527584672f, 0.190273572448036f, 0.187863471117585f, + 0.185452238111591f, 0.183039887955141f, 0.180626435180053f, 0.178211894324786f, + 0.175796279934354f, 0.173379606560240f, 0.170961888760301f, 0.168543141098691f, + 0.166123378145766f, 0.163702614477995f, 0.161280864677881f, 0.158858143333862f, + 0.156434465040231f, 0.154009844397046f, 0.151584296010041f, 0.149157834490539f, + 0.146730474455362f, 0.144302230526747f, 0.141873117332253f, 0.139443149504679f, + 0.137012341681968f, 0.134580708507126f, 0.132148264628130f, 0.129715024697841f, + 0.127281003373913f, 0.124846215318711f, 0.122410675199216f, 0.119974397686941f, + 0.117537397457838f, 0.115099689192216f, 0.112661287574648f, 0.110222207293883f, + 0.107782463042759f, 0.105342069518114f, 0.102901041420696f, 0.100459393455077f, + 0.0980171403295608f, 0.0955742967560992f, 0.0931308774501999f, 0.0906868971308382f, + 0.0882423705203696f, 0.0857973123444399f, 0.0833517373318975f, 0.0809056602147037f, + 0.0784590957278450f, 0.0760120586092433f, 0.0735645635996675f, 0.0711166254426455f, + 0.0686682588843738f, 0.0662194786736304f, 0.0637702995616845f, 0.0613207363022087f, + 0.0588708036511890f, 0.0564205163668375f, 0.0539698892095020f, 0.0515189369415775f, + 0.0490676743274181f, 0.0466161161332467f, 0.0441642771270675f, 0.0417121720785753f, + 0.0392598157590687f, 0.0368072229413588f, 0.0343544083996823f, 0.0319013869096110f, + 0.0294481732479634f, 0.0269947821927155f, 0.0245412285229123f, 0.0220875270185784f, + 0.0196336924606283f, 0.0171797396307788f, 0.0147256833114584f, 0.0122715382857199f, + 0.00981731933714973f, 0.00736304124977978f, 0.00490871880799808f, 0.00245436679646048f + ,0.00000000000000000f +}; + +const float ivas_mdft_coeff_sin_twid_640[IVAS_640_PT_LEN] = +{ + 0.00000000000000f, 0.00245436679646029f, 0.00490871880799799f, 0.00736304124977957f, + 0.00981731933714962f, 0.0122715382857199f, 0.0147256833114585f, 0.0171797396307787f, + 0.0196336924606283f, 0.0220875270185783f, 0.0245412285229123f, 0.0269947821927154f, + 0.0294481732479632f, 0.0319013869096109f, 0.0343544083996823f, 0.0368072229413588f, + 0.0392598157590686f, 0.0417121720785753f, 0.0441642771270674f, 0.0466161161332467f, + 0.0490676743274180f, 0.0515189369415775f, 0.0539698892095019f, 0.0564205163668375f, + 0.0588708036511890f, 0.0613207363022086f, 0.0637702995616845f, 0.0662194786736303f, + 0.0686682588843738f, 0.0711166254426453f, 0.0735645635996674f, 0.0760120586092431f, + 0.0784590957278449f, 0.0809056602147038f, 0.0833517373318975f, 0.0857973123444399f, + 0.0882423705203695f, 0.0906868971308382f, 0.0931308774501998f, 0.0955742967560992f, + 0.0980171403295606f, 0.100459393455076f, 0.102901041420696f, 0.105342069518114f, + 0.107782463042759f, 0.110222207293883f, 0.112661287574648f, 0.115099689192216f, + 0.117537397457838f, 0.119974397686940f, 0.122410675199216f, 0.124846215318711f, + 0.127281003373913f, 0.129715024697841f, 0.132148264628130f, 0.134580708507126f, + 0.137012341681968f, 0.139443149504679f, 0.141873117332253f, 0.144302230526747f, + 0.146730474455362f, 0.149157834490539f, 0.151584296010041f, 0.154009844397046f, + 0.156434465040231f, 0.158858143333861f, 0.161280864677880f, 0.163702614477995f, + 0.166123378145765f, 0.168543141098691f, 0.170961888760301f, 0.173379606560240f, + 0.175796279934355f, 0.178211894324786f, 0.180626435180053f, 0.183039887955141f, + 0.185452238111591f, 0.187863471117585f, 0.190273572448036f, 0.192682527584672f, + 0.195090322016128f, 0.197496941238030f, 0.199902370753082f, 0.202306596071156f, + 0.204709602709380f, 0.207111376192219f, 0.209511902051569f, 0.211911165826842f, + 0.214309153065051f, 0.216705849320900f, 0.219101240156870f, 0.221495311143304f, + 0.223888047858498f, 0.226279435888785f, 0.228669460828619f, 0.231058108280671f, + 0.233445363855905f, 0.235831213173673f, 0.238215641861795f, 0.240598635556650f, + 0.242980179903264f, 0.245360260555389f, 0.247738863175598f, 0.250115973435366f, + 0.252491577015158f, 0.254865659604515f, 0.257238206902140f, 0.259609204615985f, + 0.261978638463337f, 0.264346494170904f, 0.266712757474898f, 0.269077414121127f, + 0.271440449865074f, 0.273801850471989f, 0.276161601716971f, 0.278519689385053f, + 0.280876099271292f, 0.283230817180850f, 0.285583828929082f, 0.287935120341621f, + 0.290284677254462f, 0.292632485514050f, 0.294978530977364f, 0.297322799511998f, + 0.299665276996257f, 0.302005949319228f, 0.304344802380877f, 0.306681822092128f, + 0.309016994374947f, 0.311350305162432f, 0.313681740398891f, 0.316011286039934f, + 0.318338928052550f, 0.320664652415197f, 0.322988445117886f, 0.325310292162263f, + 0.327630179561694f, 0.329948093341349f, 0.332264019538291f, 0.334577944201551f, + 0.336889853392220f, 0.339199733183530f, 0.341507569660936f, 0.343813348922205f, + 0.346117057077493f, 0.348418680249435f, 0.350718204573223f, 0.353015616196696f, + 0.355310901280416f, 0.357604045997758f, 0.359895036534988f, 0.362183859091351f, + 0.364470499879150f, 0.366754945123831f, 0.369037181064066f, 0.371317193951838f, + 0.373594970052516f, 0.375870495644949f, 0.378143757021541f, 0.380414740488332f, + 0.382683432365090f, 0.384949818985382f, 0.387213886696666f, 0.389475621860365f, + 0.391735010851956f, 0.393992040061048f, 0.396246695891466f, 0.398498964761330f, + 0.400748833103141f, 0.402996287363860f, 0.405241314004990f, 0.407483899502658f, + 0.409724030347695f, 0.411961693045722f, 0.414196874117224f, 0.416429560097637f, + 0.418659737537428f, 0.420887393002174f, 0.423112513072644f, 0.425335084344881f, + 0.427555093430282f, 0.429772526955677f, 0.431987371563412f, 0.434199613911428f, + 0.436409240673342f, 0.438616238538528f, 0.440820594212194f, 0.443022294415467f, + 0.445221325885468f, 0.447417675375397f, 0.449611329654607f, 0.451802275508688f, + 0.453990499739547f, 0.456175989165483f, 0.458358730621271f, 0.460538710958240f, + 0.462715917044350f, 0.464890335764274f, 0.467061954019477f, 0.469230758728290f, + 0.471396736825998f, 0.473559875264908f, 0.475720161014437f, 0.477877581061184f, + 0.480032122409011f, 0.482183772079123f, 0.484332517110141f, 0.486478344558187f, + 0.488621241496955f, 0.490761195017794f, 0.492898192229784f, 0.495032220259813f, + 0.497163266252654f, 0.499291317371047f, 0.501416360795769f, 0.503538383725718f, + 0.505657373377985f, 0.507773316987935f, 0.509886201809281f, 0.511996015114162f, + 0.514102744193222f, 0.516206376355680f, 0.518306898929413f, 0.520404299261031f, + 0.522498564715949f, 0.524589682678469f, 0.526677640551852f, 0.528762425758396f, + 0.530844025739509f, 0.532922427955790f, 0.534997619887097f, 0.537069589032630f, + 0.539138322911000f, 0.541203809060310f, 0.543266035038224f, 0.545324988422047f, + 0.547380656808796f, 0.549433027815281f, 0.551482089078169f, 0.553527828254070f, + 0.555570233019602f, 0.557609291071472f, 0.559644990126546f, 0.561677317921925f, + 0.563706262215017f, 0.565731810783613f, 0.567753951425961f, 0.569772671960834f, + 0.571787960227612f, 0.573799804086349f, 0.575808191417845f, 0.577813110123727f, + 0.579814548126514f, 0.581812493369691f, 0.583806933817786f, 0.585797857456439f, + 0.587785252292473f, 0.589769106353971f, 0.591749407690343f, 0.593726144372402f, + 0.595699304492433f, 0.597668876164268f, 0.599634847523352f, 0.601597206726822f, + 0.603555941953571f, 0.605511041404326f, 0.607462493301711f, 0.609410285890327f, + 0.611354407436817f, 0.613294846229936f, 0.615231590580627f, 0.617164628822086f, + 0.619093949309834f, 0.621019540421789f, 0.622941390558334f, 0.624859488142386f, + 0.626773821619470f, 0.628684379457781f, 0.630591150148264f, 0.632494122204672f, + 0.634393284163646f, 0.636288624584773f, 0.638180132050665f, 0.640067795167023f, + 0.641951602562703f, 0.643831542889792f, 0.645707604823667f, 0.647579777063073f, + 0.649448048330184f, 0.651312407370671f, 0.653172842953777f, 0.655029343872374f, + 0.656881898943041f, 0.658730497006124f, 0.660575126925805f, 0.662415777590172f, + 0.664252437911282f, 0.666085096825230f, 0.667913743292216f, 0.669738366296610f, + 0.671558954847018f, 0.673375497976352f, 0.675187984741890f, 0.676996404225348f, + 0.678800745532942f, 0.680600997795453f, 0.682397150168297f, 0.684189191831585f, + 0.685977111990193f, 0.687760899873822f, 0.689540544737067f, 0.691316035859480f, + 0.693087362545636f, 0.694854514125194f, 0.696617479952964f, 0.698376249408973f, + 0.700130811898524f, 0.701881156852263f, 0.703627273726243f, 0.705369152001986f, + 0.707106781186548f, 0.708840150812579f, 0.710569250438390f, 0.712294069648014f, + 0.714014598051268f, 0.715730825283819f, 0.717442741007240f, 0.719150334909079f, + 0.720853596702919f, 0.722552516128436f, 0.724247082951467f, 0.725937286964068f, + 0.727623117984575f, 0.729304565857668f, 0.730981620454432f, 0.732654271672413f, + 0.734322509435686f, 0.735986323694910f, 0.737645704427393f, 0.739300641637149f, + 0.740951125354959f, 0.742597145638433f, 0.744238692572067f, 0.745875756267305f, + 0.747508326862597f, 0.749136394523459f, 0.750759949442534f, 0.752378981839648f, + 0.753993481961869f, 0.755603440083571f, 0.757208846506485f, 0.758809691559762f, + 0.760405965600031f, 0.761997659011457f, 0.763584762205797f, 0.765167265622459f, + 0.766745159728562f, 0.768318435018988f, 0.769887082016445f, 0.771451091271519f, + 0.773010453362737f, 0.774565158896617f, 0.776115198507728f, 0.777660562858748f, + 0.779201242640517f, 0.780737228572095f, 0.782268511400816f, 0.783795081902349f, + 0.785316930880745f, 0.786834049168500f, 0.788346427626606f, 0.789854057144609f, + 0.791356928640660f, 0.792855033061574f, 0.794348361382882f, 0.795836904608884f, + 0.797320653772707f, 0.798799599936358f, 0.800273734190774f, 0.801743047655881f, + 0.803207531480645f, 0.804667176843123f, 0.806121974950521f, 0.807571917039243f, + 0.809016994374948f, 0.810457198252595f, 0.811892519996505f, 0.813322950960406f, + 0.814748482527489f, 0.816169106110459f, 0.817584813151584f, 0.818995595122750f, + 0.820401443525514f, 0.821802349891147f, 0.823198305780696f, 0.824589302785025f, + 0.825975332524873f, 0.827356386650900f, 0.828732456843738f, 0.830103534814044f, + 0.831469612302545f, 0.832830681080094f, 0.834186732947712f, 0.835537759736646f, + 0.836883753308409f, 0.838224705554838f, 0.839560608398136f, 0.840891453790923f, + 0.842217233716286f, 0.843537940187827f, 0.844853565249707f, 0.846164100976699f, + 0.847469539474234f, 0.848769872878448f, 0.850065093356229f, 0.851355193105265f, + 0.852640164354092f, 0.853919999362139f, 0.855194690419775f, 0.856464229848356f, + 0.857728610000272f, 0.858987823258990f, 0.860241862039105f, 0.861490718786378f, + 0.862734385977792f, 0.863972856121587f, 0.865206121757311f, 0.866434175455865f, + 0.867657009819544f, 0.868874617482086f, 0.870086991108711f, 0.871294123396174f, + 0.872496007072797f, 0.873692634898524f, 0.874883999664958f, 0.876070094195407f, + 0.877250911344924f, 0.878426444000357f, 0.879596685080383f, 0.880761627535558f, + 0.881921264348355f, 0.883075588533209f, 0.884224593136556f, 0.885368271236879f, + 0.886506615944746f, 0.887639620402854f, 0.888767277786068f, 0.889889581301463f, + 0.891006524188368f, 0.892118099718401f, 0.893224301195515f, 0.894325121956035f, + 0.895420555368697f, 0.896510594834693f, 0.897595233787707f, 0.898674465693954f, + 0.899748284052221f, 0.900816682393908f, 0.901879654283062f, 0.902937193316419f, + 0.903989293123443f, 0.905035947366364f, 0.906077149740215f, 0.907112893972869f, + 0.908143173825081f, 0.909167983090522f, 0.910187315595818f, 0.911201165200584f, + 0.912209525797468f, 0.913212391312179f, 0.914209755703531f, 0.915201612963474f, + 0.916187957117136f, 0.917168782222852f, 0.918144082372204f, 0.919113851690058f, + 0.920078084334595f, 0.921036774497350f, 0.921989916403245f, 0.922937504310623f, + 0.923879532511287f, 0.924815995330528f, 0.925746887127164f, 0.926672202293573f, + 0.927591935255724f, 0.928506080473216f, 0.929414632439304f, 0.930317585680942f, + 0.931214934758804f, 0.932106674267327f, 0.932992798834739f, 0.933873303123092f, + 0.934748181828292f, 0.935617429680138f, 0.936481041442343f, 0.937339011912575f, + 0.938191335922484f, 0.939038008337734f, 0.939879024058033f, 0.940714378017165f, + 0.941544065183021f, 0.942368080557626f, 0.943186419177173f, 0.943999076112052f, + 0.944806046466878f, 0.945607325380521f, 0.946402908026138f, 0.947192789611197f, + 0.947976965377510f, 0.948755430601262f, 0.949528180593037f, 0.950295210697844f, + 0.951056516295154f, 0.951812092798916f, 0.952561935657595f, 0.953306040354194f, + 0.954044402406280f, 0.954777017366017f, 0.955503880820186f, 0.956224988390216f, + 0.956940335732209f, 0.957649918536965f, 0.958353732530011f, 0.959051773471624f, + 0.959744037156857f, 0.960430519415566f, 0.961111216112432f, 0.961786123146989f, + 0.962455236453647f, 0.963118552001719f, 0.963776065795440f, 0.964427773873996f, + 0.965073672311547f, 0.965713757217249f, 0.966348024735277f, 0.966976471044852f, + 0.967599092360260f, 0.968215884930876f, 0.968826845041188f, 0.969431969010818f, + 0.970031253194544f, 0.970624693982323f, 0.971212287799312f, 0.971794031105889f, + 0.972369920397677f, 0.972939952205560f, 0.973504123095711f, 0.974062429669605f, + 0.974614868564045f, 0.975161436451181f, 0.975702130038529f, 0.976236946068990f, + 0.976765881320873f, 0.977288932607910f, 0.977806096779282f, 0.978317370719628f, + 0.978822751349072f, 0.979322235623241f, 0.979815820533276f, 0.980303503105861f, + 0.980785280403230f, 0.981261149523195f, 0.981731107599154f, 0.982195151800116f, + 0.982653279330712f, 0.983105487431216f, 0.983551773377562f, 0.983992134481354f, + 0.984426568089892f, 0.984855071586178f, 0.985277642388941f, 0.985694277952645f, + 0.986104975767509f, 0.986509733359519f, 0.986908548290446f, 0.987301418157858f, + 0.987688340595138f, 0.988069313271492f, 0.988444333891970f, 0.988813400197476f, + 0.989176509964781f, 0.989533661006540f, 0.989884851171301f, 0.990230078343521f, + 0.990569340443577f, 0.990902635427780f, 0.991229961288385f, 0.991551316053606f, + 0.991866697787626f, 0.992176104590609f, 0.992479534598710f, 0.992776985984091f, + 0.993068456954926f, 0.993353945755417f, 0.993633450665799f, 0.993906970002356f, + 0.994174502117428f, 0.994436045399422f, 0.994691598272820f, 0.994941159198190f, + 0.995184726672197f, 0.995422299227608f, 0.995653875433303f, 0.995879453894286f, + 0.996099033251687f, 0.996312612182778f, 0.996520189400975f, 0.996721763655847f, + 0.996917333733128f, 0.997106898454717f, 0.997290456678690f, 0.997468007299307f, + 0.997639549247016f, 0.997805081488460f, 0.997964603026487f, 0.998118112900149f, + 0.998265610184716f, 0.998407093991674f, 0.998542563468736f, 0.998672017799843f, + 0.998795456205172f, 0.998912877941140f, 0.999024282300407f, 0.999129668611881f, + 0.999229036240723f, 0.999322384588350f, 0.999409713092437f, 0.999491021226926f, + 0.999566308502021f, 0.999635574464198f, 0.999698818696204f, 0.999756040817060f, + 0.999807240482065f, 0.999852417382795f, 0.999891571247108f, 0.999924701839145f, + 0.999951808959328f, 0.999972892444367f, 0.999987952167257f, 0.999996988037278f +}; + +const float ivas_mdft_coeff_cos_twid_320[IVAS_320_PT_LEN + 1] = +{ + 1.00000000000000f, 0.999987952167257f, 0.999951808959328f, 0.999891571247108f, + 0.999807240482065f, 0.999698818696204f, 0.999566308502021f, 0.999409713092437f, + 0.999229036240723f, 0.999024282300407f, 0.998795456205172f, 0.998542563468736f, + 0.998265610184716f, 0.997964603026487f, 0.997639549247016f, 0.997290456678690f, + 0.996917333733128f, 0.996520189400975f, 0.996099033251687f, 0.995653875433303f, + 0.995184726672197f, 0.994691598272820f, 0.994174502117428f, 0.993633450665799f, + 0.993068456954926f, 0.992479534598710f, 0.991866697787626f, 0.991229961288385f, + 0.990569340443577f, 0.989884851171301f, 0.989176509964781f, 0.988444333891970f, + 0.987688340595138f, 0.986908548290446f, 0.986104975767509f, 0.985277642388941f, + 0.984426568089892f, 0.983551773377562f, 0.982653279330712f, 0.981731107599154f, + 0.980785280403230f, 0.979815820533276f, 0.978822751349072f, 0.977806096779282f, + 0.976765881320872f, 0.975702130038529f, 0.974614868564045f, 0.973504123095711f, + 0.972369920397677f, 0.971212287799312f, 0.970031253194544f, 0.968826845041188f, + 0.967599092360260f, 0.966348024735277f, 0.965073672311547f, 0.963776065795440f, + 0.962455236453647f, 0.961111216112432f, 0.959744037156857f, 0.958353732530011f, + 0.956940335732209f, 0.955503880820186f, 0.954044402406280f, 0.952561935657595f, + 0.951056516295154f, 0.949528180593037f, 0.947976965377510f, 0.946402908026138f, + 0.944806046466878f, 0.943186419177173f, 0.941544065183021f, 0.939879024058033f, + 0.938191335922484f, 0.936481041442343f, 0.934748181828292f, 0.932992798834739f, + 0.931214934758804f, 0.929414632439304f, 0.927591935255724f, 0.925746887127164f, + 0.923879532511287f, 0.921989916403245f, 0.920078084334595f, 0.918144082372204f, + 0.916187957117136f, 0.914209755703531f, 0.912209525797468f, 0.910187315595818f, + 0.908143173825081f, 0.906077149740215f, 0.903989293123443f, 0.901879654283062f, + 0.899748284052222f, 0.897595233787707f, 0.895420555368697f, 0.893224301195515f, + 0.891006524188368f, 0.888767277786068f, 0.886506615944746f, 0.884224593136556f, + 0.881921264348355f, 0.879596685080383f, 0.877250911344924f, 0.874883999664958f, + 0.872496007072797f, 0.870086991108712f, 0.867657009819544f, 0.865206121757311f, + 0.862734385977792f, 0.860241862039105f, 0.857728610000272f, 0.855194690419775f, + 0.852640164354092f, 0.850065093356229f, 0.847469539474235f, 0.844853565249707f, + 0.842217233716287f, 0.839560608398136f, 0.836883753308409f, 0.834186732947712f, + 0.831469612302545f, 0.828732456843738f, 0.825975332524873f, 0.823198305780696f, + 0.820401443525514f, 0.817584813151584f, 0.814748482527489f, 0.811892519996505f, + 0.809016994374948f, 0.806121974950521f, 0.803207531480645f, 0.800273734190774f, + 0.797320653772707f, 0.794348361382882f, 0.791356928640660f, 0.788346427626606f, + 0.785316930880745f, 0.782268511400816f, 0.779201242640517f, 0.776115198507728f, + 0.773010453362737f, 0.769887082016445f, 0.766745159728562f, 0.763584762205797f, + 0.760405965600031f, 0.757208846506485f, 0.753993481961870f, 0.750759949442534f, + 0.747508326862597f, 0.744238692572067f, 0.740951125354959f, 0.737645704427393f, + 0.734322509435686f, 0.730981620454432f, 0.727623117984575f, 0.724247082951467f, + 0.720853596702919f, 0.717442741007240f, 0.714014598051268f, 0.710569250438390f, + 0.707106781186548f, 0.703627273726243f, 0.700130811898524f, 0.696617479952964f, + 0.693087362545636f, 0.689540544737067f, 0.685977111990193f, 0.682397150168297f, + 0.678800745532942f, 0.675187984741891f, 0.671558954847018f, 0.667913743292216f, + 0.664252437911282f, 0.660575126925805f, 0.656881898943041f, 0.653172842953777f, + 0.649448048330184f, 0.645707604823667f, 0.641951602562703f, 0.638180132050665f, + 0.634393284163646f, 0.630591150148264f, 0.626773821619470f, 0.622941390558334f, + 0.619093949309834f, 0.615231590580627f, 0.611354407436817f, 0.607462493301711f, + 0.603555941953571f, 0.599634847523352f, 0.595699304492433f, 0.591749407690343f, + 0.587785252292473f, 0.583806933817786f, 0.579814548126514f, 0.575808191417845f, + 0.571787960227612f, 0.567753951425961f, 0.563706262215017f, 0.559644990126546f, + 0.555570233019602f, 0.551482089078169f, 0.547380656808797f, 0.543266035038224f, + 0.539138322911000f, 0.534997619887097f, 0.530844025739510f, 0.526677640551852f, + 0.522498564715949f, 0.518306898929413f, 0.514102744193222f, 0.509886201809281f, + 0.505657373377985f, 0.501416360795769f, 0.497163266252654f, 0.492898192229784f, + 0.488621241496955f, 0.484332517110141f, 0.480032122409011f, 0.475720161014437f, + 0.471396736825998f, 0.467061954019477f, 0.462715917044350f, 0.458358730621271f, + 0.453990499739547f, 0.449611329654607f, 0.445221325885468f, 0.440820594212194f, + 0.436409240673342f, 0.431987371563412f, 0.427555093430282f, 0.423112513072644f, + 0.418659737537428f, 0.414196874117224f, 0.409724030347695f, 0.405241314004990f, + 0.400748833103141f, 0.396246695891466f, 0.391735010851956f, 0.387213886696666f, + 0.382683432365090f, 0.378143757021541f, 0.373594970052516f, 0.369037181064066f, + 0.364470499879150f, 0.359895036534988f, 0.355310901280416f, 0.350718204573223f, + 0.346117057077493f, 0.341507569660936f, 0.336889853392220f, 0.332264019538291f, + 0.327630179561693f, 0.322988445117886f, 0.318338928052550f, 0.313681740398892f, + 0.309016994374947f, 0.304344802380877f, 0.299665276996257f, 0.294978530977364f, + 0.290284677254463f, 0.285583828929082f, 0.280876099271292f, 0.276161601716971f, + 0.271440449865074f, 0.266712757474898f, 0.261978638463337f, 0.257238206902140f, + 0.252491577015158f, 0.247738863175599f, 0.242980179903264f, 0.238215641861795f, + 0.233445363855905f, 0.228669460828619f, 0.223888047858498f, 0.219101240156870f, + 0.214309153065051f, 0.209511902051569f, 0.204709602709380f, 0.199902370753082f, + 0.195090322016128f, 0.190273572448036f, 0.185452238111591f, 0.180626435180053f, + 0.175796279934354f, 0.170961888760301f, 0.166123378145766f, 0.161280864677881f, + 0.156434465040231f, 0.151584296010041f, 0.146730474455362f, 0.141873117332253f, + 0.137012341681968f, 0.132148264628130f, 0.127281003373913f, 0.122410675199216f, + 0.117537397457838f, 0.112661287574648f, 0.107782463042759f, 0.102901041420696f, + 0.0980171403295608f, 0.0931308774501999f, 0.0882423705203696f, 0.0833517373318975f, + 0.0784590957278450f, 0.0735645635996675f, 0.0686682588843738f, 0.0637702995616845f, + 0.0588708036511890f, 0.0539698892095020f, 0.0490676743274181f, 0.0441642771270675f, + 0.0392598157590687f, 0.0343544083996823f, 0.0294481732479634f, 0.0245412285229123f, + 0.0196336924606283f, 0.0147256833114584f, 0.00981731933714973f, 0.00490871880799808f + ,0.0000000000000000f +}; + +const float ivas_mdft_coeff_sin_twid_320[IVAS_320_PT_LEN] = +{ + 0.00000000000000f, 0.00490871880799799f, 0.00981731933714962f, 0.0147256833114585f, + 0.0196336924606283f, 0.0245412285229123f, 0.0294481732479632f, 0.0343544083996823f, + 0.0392598157590686f, 0.0441642771270674f, 0.0490676743274180f, 0.0539698892095019f, + 0.0588708036511890f, 0.0637702995616845f, 0.0686682588843738f, 0.0735645635996674f, + 0.0784590957278449f, 0.0833517373318975f, 0.0882423705203695f, 0.0931308774501998f, + 0.0980171403295606f, 0.102901041420696f, 0.107782463042759f, 0.112661287574648f, + 0.117537397457838f, 0.122410675199216f, 0.127281003373913f, 0.132148264628130f, + 0.137012341681968f, 0.141873117332253f, 0.146730474455362f, 0.151584296010041f, + 0.156434465040231f, 0.161280864677880f, 0.166123378145765f, 0.170961888760301f, + 0.175796279934355f, 0.180626435180053f, 0.185452238111591f, 0.190273572448036f, + 0.195090322016128f, 0.199902370753082f, 0.204709602709380f, 0.209511902051569f, + 0.214309153065051f, 0.219101240156870f, 0.223888047858498f, 0.228669460828619f, + 0.233445363855905f, 0.238215641861795f, 0.242980179903264f, 0.247738863175598f, + 0.252491577015158f, 0.257238206902140f, 0.261978638463337f, 0.266712757474898f, + 0.271440449865074f, 0.276161601716971f, 0.280876099271292f, 0.285583828929082f, + 0.290284677254462f, 0.294978530977364f, 0.299665276996257f, 0.304344802380877f, + 0.309016994374947f, 0.313681740398891f, 0.318338928052550f, 0.322988445117886f, + 0.327630179561694f, 0.332264019538291f, 0.336889853392220f, 0.341507569660936f, + 0.346117057077493f, 0.350718204573223f, 0.355310901280416f, 0.359895036534988f, + 0.364470499879150f, 0.369037181064066f, 0.373594970052516f, 0.378143757021541f, + 0.382683432365090f, 0.387213886696666f, 0.391735010851956f, 0.396246695891466f, + 0.400748833103141f, 0.405241314004990f, 0.409724030347695f, 0.414196874117224f, + 0.418659737537428f, 0.423112513072644f, 0.427555093430282f, 0.431987371563412f, + 0.436409240673342f, 0.440820594212194f, 0.445221325885468f, 0.449611329654607f, + 0.453990499739547f, 0.458358730621271f, 0.462715917044350f, 0.467061954019477f, + 0.471396736825998f, 0.475720161014437f, 0.480032122409011f, 0.484332517110141f, + 0.488621241496955f, 0.492898192229784f, 0.497163266252654f, 0.501416360795769f, + 0.505657373377985f, 0.509886201809281f, 0.514102744193222f, 0.518306898929413f, + 0.522498564715949f, 0.526677640551852f, 0.530844025739509f, 0.534997619887097f, + 0.539138322911000f, 0.543266035038224f, 0.547380656808796f, 0.551482089078169f, + 0.555570233019602f, 0.559644990126546f, 0.563706262215017f, 0.567753951425961f, + 0.571787960227612f, 0.575808191417845f, 0.579814548126514f, 0.583806933817786f, + 0.587785252292473f, 0.591749407690343f, 0.595699304492433f, 0.599634847523352f, + 0.603555941953571f, 0.607462493301711f, 0.611354407436817f, 0.615231590580627f, + 0.619093949309834f, 0.622941390558334f, 0.626773821619470f, 0.630591150148264f, + 0.634393284163646f, 0.638180132050665f, 0.641951602562703f, 0.645707604823667f, + 0.649448048330184f, 0.653172842953777f, 0.656881898943041f, 0.660575126925805f, + 0.664252437911282f, 0.667913743292216f, 0.671558954847018f, 0.675187984741890f, + 0.678800745532942f, 0.682397150168297f, 0.685977111990193f, 0.689540544737067f, + 0.693087362545636f, 0.696617479952964f, 0.700130811898524f, 0.703627273726243f, + 0.707106781186548f, 0.710569250438390f, 0.714014598051268f, 0.717442741007240f, + 0.720853596702919f, 0.724247082951467f, 0.727623117984575f, 0.730981620454432f, + 0.734322509435686f, 0.737645704427393f, 0.740951125354959f, 0.744238692572067f, + 0.747508326862597f, 0.750759949442534f, 0.753993481961869f, 0.757208846506485f, + 0.760405965600031f, 0.763584762205797f, 0.766745159728562f, 0.769887082016445f, + 0.773010453362737f, 0.776115198507728f, 0.779201242640517f, 0.782268511400816f, + 0.785316930880745f, 0.788346427626606f, 0.791356928640660f, 0.794348361382882f, + 0.797320653772707f, 0.800273734190774f, 0.803207531480645f, 0.806121974950521f, + 0.809016994374948f, 0.811892519996505f, 0.814748482527489f, 0.817584813151584f, + 0.820401443525514f, 0.823198305780696f, 0.825975332524873f, 0.828732456843738f, + 0.831469612302545f, 0.834186732947712f, 0.836883753308409f, 0.839560608398136f, + 0.842217233716286f, 0.844853565249707f, 0.847469539474234f, 0.850065093356229f, + 0.852640164354092f, 0.855194690419775f, 0.857728610000272f, 0.860241862039105f, + 0.862734385977792f, 0.865206121757311f, 0.867657009819544f, 0.870086991108711f, + 0.872496007072797f, 0.874883999664958f, 0.877250911344924f, 0.879596685080383f, + 0.881921264348355f, 0.884224593136556f, 0.886506615944746f, 0.888767277786068f, + 0.891006524188368f, 0.893224301195515f, 0.895420555368697f, 0.897595233787707f, + 0.899748284052221f, 0.901879654283062f, 0.903989293123443f, 0.906077149740215f, + 0.908143173825081f, 0.910187315595818f, 0.912209525797468f, 0.914209755703531f, + 0.916187957117136f, 0.918144082372204f, 0.920078084334595f, 0.921989916403245f, + 0.923879532511287f, 0.925746887127164f, 0.927591935255724f, 0.929414632439304f, + 0.931214934758804f, 0.932992798834739f, 0.934748181828292f, 0.936481041442343f, + 0.938191335922484f, 0.939879024058033f, 0.941544065183021f, 0.943186419177173f, + 0.944806046466878f, 0.946402908026138f, 0.947976965377510f, 0.949528180593037f, + 0.951056516295154f, 0.952561935657595f, 0.954044402406280f, 0.955503880820186f, + 0.956940335732209f, 0.958353732530011f, 0.959744037156857f, 0.961111216112432f, + 0.962455236453647f, 0.963776065795440f, 0.965073672311547f, 0.966348024735277f, + 0.967599092360260f, 0.968826845041188f, 0.970031253194544f, 0.971212287799312f, + 0.972369920397677f, 0.973504123095711f, 0.974614868564045f, 0.975702130038529f, + 0.976765881320873f, 0.977806096779282f, 0.978822751349072f, 0.979815820533276f, + 0.980785280403230f, 0.981731107599154f, 0.982653279330712f, 0.983551773377562f, + 0.984426568089892f, 0.985277642388941f, 0.986104975767509f, 0.986908548290446f, + 0.987688340595138f, 0.988444333891970f, 0.989176509964781f, 0.989884851171301f, + 0.990569340443577f, 0.991229961288385f, 0.991866697787626f, 0.992479534598710f, + 0.993068456954926f, 0.993633450665799f, 0.994174502117428f, 0.994691598272820f, + 0.995184726672197f, 0.995653875433303f, 0.996099033251687f, 0.996520189400975f, + 0.996917333733128f, 0.997290456678690f, 0.997639549247016f, 0.997964603026487f, + 0.998265610184716f, 0.998542563468736f, 0.998795456205172f, 0.999024282300407f, + 0.999229036240723f, 0.999409713092437f, 0.999566308502021f, 0.999698818696204f, + 0.999807240482065f, 0.999891571247108f, 0.999951808959328f, 0.999987952167257f +}; + +const float ivas_mdft_coeff_cos_twid_240[IVAS_240_PT_LEN + 1] = +{ + 1.0000000000f, 0.9999785817f, 0.9999143276f, 0.9998072405f, 0.9996573250f, 0.9994645875f, + 0.9992290362f, 0.9989506814f, 0.9986295348f, 0.9982656102f, 0.9978589232f, 0.9974094913f, + 0.9969173337f, 0.9963824715f, 0.9958049276f, 0.9951847267f, 0.9945218954f, 0.9938164621f, + 0.9930684570f, 0.9922779121f, 0.9914448614f, 0.9905693404f, 0.9896513868f, 0.9886910398f, + 0.9876883406f, 0.9866433321f, 0.9855560591f, 0.9844265681f, 0.9832549076f, 0.9820411277f, + 0.9807852804f, 0.9794874196f, 0.9781476007f, 0.9767658813f, 0.9753423205f, 0.9738769793f, + 0.9723699204f, 0.9708212084f, 0.9692309097f, 0.9675990924f, 0.9659258263f, 0.9642111832f, + 0.9624552365f, 0.9606580614f, 0.9588197349f, 0.9569403357f, 0.9550199445f, 0.9530586433f, + 0.9510565163f, 0.9490136492f, 0.9469301295f, 0.9448060465f, 0.9426414911f, 0.9404365561f, + 0.9381913359f, 0.9359059268f, 0.9335804265f, 0.9312149348f, 0.9288095529f, 0.9263643839f, + 0.9238795325f, 0.9213551052f, 0.9187912101f, 0.9161879571f, 0.9135454576f, 0.9108638249f, + 0.9081431738f, 0.9053836209f, 0.9025852843f, 0.8997482841f, 0.8968727415f, 0.8939587800f, + 0.8910065242f, 0.8880161007f, 0.8849876375f, 0.8819212643f, 0.8788171127f, 0.8756753154f, + 0.8724960071f, 0.8692793239f, 0.8660254038f, 0.8627343860f, 0.8594064115f, 0.8560416229f, + 0.8526401644f, 0.8492021815f, 0.8457278217f, 0.8422172337f, 0.8386705679f, 0.8350879763f, + 0.8314696123f, 0.8278156309f, 0.8241261886f, 0.8204014435f, 0.8166415552f, 0.8128466846f, + 0.8090169944f, 0.8051526486f, 0.8012538127f, 0.7973206538f, 0.7933533403f, 0.7893520422f, + 0.7853169309f, 0.7812481792f, 0.7771459615f, 0.7730104534f, 0.7688418321f, 0.7646402762f, + 0.7604059656f, 0.7561390818f, 0.7518398075f, 0.7475083269f, 0.7431448255f, 0.7387494902f, + 0.7343225094f, 0.7298640727f, 0.7253743710f, 0.7208535967f, 0.7163019434f, 0.7117196062f, + 0.7071067812f, 0.7024636661f, 0.6977904598f, 0.6930873625f, 0.6883545757f, 0.6835923020f, + 0.6788007455f, 0.6739801115f, 0.6691306064f, 0.6642524379f, 0.6593458151f, 0.6544109481f, + 0.6494480483f, 0.6444573284f, 0.6394390020f, 0.6343932842f, 0.6293203910f, 0.6242205399f, + 0.6190939493f, 0.6139408388f, 0.6087614290f, 0.6035559420f, 0.5983246006f, 0.5930676290f, + 0.5877852523f, 0.5824776969f, 0.5771451900f, 0.5717879602f, 0.5664062369f, 0.5610002507f, + 0.5555702330f, 0.5501164166f, 0.5446390350f, 0.5391383229f, 0.5336145159f, 0.5280678507f, + 0.5224985647f, 0.5169068967f, 0.5112930861f, 0.5056573734f, 0.5000000000f, 0.4943212083f, + 0.4886212415f, 0.4829003438f, 0.4771587603f, 0.4713967368f, 0.4656145203f, 0.4598123584f, + 0.4539904997f, 0.4481491936f, 0.4422886902f, 0.4364092407f, 0.4305110968f, 0.4245945113f, + 0.4186597375f, 0.4127070298f, 0.4067366431f, 0.4007488331f, 0.3947438564f, 0.3887219702f, + 0.3826834324f, 0.3766285017f, 0.3705574375f, 0.3644704999f, 0.3583679495f, 0.3522500479f, + 0.3461170571f, 0.3399692397f, 0.3338068592f, 0.3276301796f, 0.3214394653f, 0.3152349816f, + 0.3090169944f, 0.3027857698f, 0.2965415750f, 0.2902846773f, 0.2840153447f, 0.2777338459f, + 0.2714404499f, 0.2651354262f, 0.2588190451f, 0.2524915770f, 0.2461532930f, 0.2398044647f, + 0.2334453639f, 0.2270762630f, 0.2206974350f, 0.2143091531f, 0.2079116908f, 0.2015053223f, + 0.1950903220f, 0.1886669647f, 0.1822355255f, 0.1757962799f, 0.1693495038f, 0.1628954734f, + 0.1564344650f, 0.1499667556f, 0.1434926220f, 0.1370123417f, 0.1305261922f, 0.1240344515f, + 0.1175373975f, 0.1110353086f, 0.1045284633f, 0.0980171403f, 0.0915016187f, 0.0849821774f, + 0.0784590957f, 0.0719326532f, 0.0654031292f, 0.0588708037f, 0.0523359562f, 0.0457988669f, + 0.0392598158f, 0.0327190828f, 0.0261769483f, 0.0196336925f, 0.0130895956f, 0.0065449380f, + 0.000000000f +}; + +const float ivas_mdft_coeff_sin_twid_240[IVAS_240_PT_LEN] = +{ + 0.0000000000f, 0.0065449380f, 0.0130895956f, 0.0196336925f, 0.0261769483f, 0.0327190828f, + 0.0392598158f, 0.0457988669f, 0.0523359562f, 0.0588708037f, 0.0654031292f, 0.0719326532f, + 0.0784590957f, 0.0849821774f, 0.0915016187f, 0.0980171403f, 0.1045284633f, 0.1110353086f, + 0.1175373975f, 0.1240344515f, 0.1305261922f, 0.1370123417f, 0.1434926220f, 0.1499667556f, + 0.1564344650f, 0.1628954734f, 0.1693495038f, 0.1757962799f, 0.1822355255f, 0.1886669647f, + 0.1950903220f, 0.2015053223f, 0.2079116908f, 0.2143091531f, 0.2206974350f, 0.2270762630f, + 0.2334453639f, 0.2398044647f, 0.2461532930f, 0.2524915770f, 0.2588190451f, 0.2651354262f, + 0.2714404499f, 0.2777338459f, 0.2840153447f, 0.2902846773f, 0.2965415750f, 0.3027857698f, + 0.3090169944f, 0.3152349816f, 0.3214394653f, 0.3276301796f, 0.3338068592f, 0.3399692397f, + 0.3461170571f, 0.3522500479f, 0.3583679495f, 0.3644704999f, 0.3705574375f, 0.3766285017f, + 0.3826834324f, 0.3887219702f, 0.3947438564f, 0.4007488331f, 0.4067366431f, 0.4127070298f, + 0.4186597375f, 0.4245945113f, 0.4305110968f, 0.4364092407f, 0.4422886902f, 0.4481491936f, + 0.4539904997f, 0.4598123584f, 0.4656145203f, 0.4713967368f, 0.4771587603f, 0.4829003438f, + 0.4886212415f, 0.4943212083f, 0.5000000000f, 0.5056573734f, 0.5112930861f, 0.5169068967f, + 0.5224985647f, 0.5280678507f, 0.5336145159f, 0.5391383229f, 0.5446390350f, 0.5501164166f, + 0.5555702330f, 0.5610002507f, 0.5664062369f, 0.5717879602f, 0.5771451900f, 0.5824776969f, + 0.5877852523f, 0.5930676290f, 0.5983246006f, 0.6035559420f, 0.6087614290f, 0.6139408388f, + 0.6190939493f, 0.6242205399f, 0.6293203910f, 0.6343932842f, 0.6394390020f, 0.6444573284f, + 0.6494480483f, 0.6544109481f, 0.6593458151f, 0.6642524379f, 0.6691306064f, 0.6739801115f, + 0.6788007455f, 0.6835923020f, 0.6883545757f, 0.6930873625f, 0.6977904598f, 0.7024636661f, + 0.7071067812f, 0.7117196062f, 0.7163019434f, 0.7208535967f, 0.7253743710f, 0.7298640727f, + 0.7343225094f, 0.7387494902f, 0.7431448255f, 0.7475083269f, 0.7518398075f, 0.7561390818f, + 0.7604059656f, 0.7646402762f, 0.7688418321f, 0.7730104534f, 0.7771459615f, 0.7812481792f, + 0.7853169309f, 0.7893520422f, 0.7933533403f, 0.7973206538f, 0.8012538127f, 0.8051526486f, + 0.8090169944f, 0.8128466846f, 0.8166415552f, 0.8204014435f, 0.8241261886f, 0.8278156309f, + 0.8314696123f, 0.8350879763f, 0.8386705679f, 0.8422172337f, 0.8457278217f, 0.8492021815f, + 0.8526401644f, 0.8560416229f, 0.8594064115f, 0.8627343860f, 0.8660254038f, 0.8692793239f, + 0.8724960071f, 0.8756753154f, 0.8788171127f, 0.8819212643f, 0.8849876375f, 0.8880161007f, + 0.8910065242f, 0.8939587800f, 0.8968727415f, 0.8997482841f, 0.9025852843f, 0.9053836209f, + 0.9081431738f, 0.9108638249f, 0.9135454576f, 0.9161879571f, 0.9187912101f, 0.9213551052f, + 0.9238795325f, 0.9263643839f, 0.9288095529f, 0.9312149348f, 0.9335804265f, 0.9359059268f, + 0.9381913359f, 0.9404365561f, 0.9426414911f, 0.9448060465f, 0.9469301295f, 0.9490136492f, + 0.9510565163f, 0.9530586433f, 0.9550199445f, 0.9569403357f, 0.9588197349f, 0.9606580614f, + 0.9624552365f, 0.9642111832f, 0.9659258263f, 0.9675990924f, 0.9692309097f, 0.9708212084f, + 0.9723699204f, 0.9738769793f, 0.9753423205f, 0.9767658813f, 0.9781476007f, 0.9794874196f, + 0.9807852804f, 0.9820411277f, 0.9832549076f, 0.9844265681f, 0.9855560591f, 0.9866433321f, + 0.9876883406f, 0.9886910398f, 0.9896513868f, 0.9905693404f, 0.9914448614f, 0.9922779121f, + 0.9930684570f, 0.9938164621f, 0.9945218954f, 0.9951847267f, 0.9958049276f, 0.9963824715f, + 0.9969173337f, 0.9974094913f, 0.9978589232f, 0.9982656102f, 0.9986295348f, 0.9989506814f, + 0.9992290362f, 0.9994645875f, 0.9996573250f, 0.9998072405f, 0.9999143276f, 0.9999785817f +}; + +const float ivas_mdft_coeff_cos_twid_160[IVAS_160_PT_LEN + 1] = +{ + 1.0000000000f, 0.9999518090f, 0.9998072405f, 0.9995663085f, 0.9992290362f, 0.9987954562f, + 0.9982656102f, 0.9976395492f, 0.9969173337f, 0.9960990333f, 0.9951847267f, 0.9941745021f, + 0.9930684570f, 0.9918666978f, 0.9905693404f, 0.9891765100f, 0.9876883406f, 0.9861049758f, + 0.9844265681f, 0.9826532793f, 0.9807852804f, 0.9788227513f, 0.9767658813f, 0.9746148686f, + 0.9723699204f, 0.9700312532f, 0.9675990924f, 0.9650736723f, 0.9624552365f, 0.9597440372f, + 0.9569403357f, 0.9540444024f, 0.9510565163f, 0.9479769654f, 0.9448060465f, 0.9415440652f, + 0.9381913359f, 0.9347481818f, 0.9312149348f, 0.9275919353f, 0.9238795325f, 0.9200780843f, + 0.9161879571f, 0.9122095258f, 0.9081431738f, 0.9039892931f, 0.8997482841f, 0.8954205554f, + 0.8910065242f, 0.8865066159f, 0.8819212643f, 0.8772509113f, 0.8724960071f, 0.8676570098f, + 0.8627343860f, 0.8577286100f, 0.8526401644f, 0.8474695395f, 0.8422172337f, 0.8368837533f, + 0.8314696123f, 0.8259753325f, 0.8204014435f, 0.8147484825f, 0.8090169944f, 0.8032075315f, + 0.7973206538f, 0.7913569286f, 0.7853169309f, 0.7792012426f, 0.7730104534f, 0.7667451597f, + 0.7604059656f, 0.7539934820f, 0.7475083269f, 0.7409511254f, 0.7343225094f, 0.7276231180f, + 0.7208535967f, 0.7140145981f, 0.7071067812f, 0.7001308119f, 0.6930873625f, 0.6859771120f, + 0.6788007455f, 0.6715589548f, 0.6642524379f, 0.6568818989f, 0.6494480483f, 0.6419516026f, + 0.6343932842f, 0.6267738216f, 0.6190939493f, 0.6113544074f, 0.6035559420f, 0.5956993045f, + 0.5877852523f, 0.5798145481f, 0.5717879602f, 0.5637062622f, 0.5555702330f, 0.5473806568f, + 0.5391383229f, 0.5308440257f, 0.5224985647f, 0.5141027442f, 0.5056573734f, 0.4971632663f, + 0.4886212415f, 0.4800321224f, 0.4713967368f, 0.4627159170f, 0.4539904997f, 0.4452213259f, + 0.4364092407f, 0.4275550934f, 0.4186597375f, 0.4097240303f, 0.4007488331f, 0.3917350109f, + 0.3826834324f, 0.3735949701f, 0.3644704999f, 0.3553109013f, 0.3461170571f, 0.3368898534f, + 0.3276301796f, 0.3183389281f, 0.3090169944f, 0.2996652770f, 0.2902846773f, 0.2808760993f, + 0.2714404499f, 0.2619786385f, 0.2524915770f, 0.2429801799f, 0.2334453639f, 0.2238880479f, + 0.2143091531f, 0.2047096027f, 0.1950903220f, 0.1854522381f, 0.1757962799f, 0.1661233781f, + 0.1564344650f, 0.1467304745f, 0.1370123417f, 0.1272810034f, 0.1175373975f, 0.1077824630f, + 0.0980171403f, 0.0882423705f, 0.0784590957f, 0.0686682589f, 0.0588708037f, 0.0490676743f, + 0.0392598158f, 0.0294481732f, 0.0196336925f, 0.0098173193f, 0.000000000f +}; + +const float ivas_mdft_coeff_sin_twid_160[IVAS_160_PT_LEN] = +{ + 0.0000000000f, 0.0098173193f, 0.0196336925f, 0.0294481732f, 0.0392598158f, 0.0490676743f, + 0.0588708037f, 0.0686682589f, 0.0784590957f, 0.0882423705f, 0.0980171403f, 0.1077824630f, + 0.1175373975f, 0.1272810034f, 0.1370123417f, 0.1467304745f, 0.1564344650f, 0.1661233781f, + 0.1757962799f, 0.1854522381f, 0.1950903220f, 0.2047096027f, 0.2143091531f, 0.2238880479f, + 0.2334453639f, 0.2429801799f, 0.2524915770f, 0.2619786385f, 0.2714404499f, 0.2808760993f, + 0.2902846773f, 0.2996652770f, 0.3090169944f, 0.3183389281f, 0.3276301796f, 0.3368898534f, + 0.3461170571f, 0.3553109013f, 0.3644704999f, 0.3735949701f, 0.3826834324f, 0.3917350109f, + 0.4007488331f, 0.4097240303f, 0.4186597375f, 0.4275550934f, 0.4364092407f, 0.4452213259f, + 0.4539904997f, 0.4627159170f, 0.4713967368f, 0.4800321224f, 0.4886212415f, 0.4971632663f, + 0.5056573734f, 0.5141027442f, 0.5224985647f, 0.5308440257f, 0.5391383229f, 0.5473806568f, + 0.5555702330f, 0.5637062622f, 0.5717879602f, 0.5798145481f, 0.5877852523f, 0.5956993045f, + 0.6035559420f, 0.6113544074f, 0.6190939493f, 0.6267738216f, 0.6343932842f, 0.6419516026f, + 0.6494480483f, 0.6568818989f, 0.6642524379f, 0.6715589548f, 0.6788007455f, 0.6859771120f, + 0.6930873625f, 0.7001308119f, 0.7071067812f, 0.7140145981f, 0.7208535967f, 0.7276231180f, + 0.7343225094f, 0.7409511254f, 0.7475083269f, 0.7539934820f, 0.7604059656f, 0.7667451597f, + 0.7730104534f, 0.7792012426f, 0.7853169309f, 0.7913569286f, 0.7973206538f, 0.8032075315f, + 0.8090169944f, 0.8147484825f, 0.8204014435f, 0.8259753325f, 0.8314696123f, 0.8368837533f, + 0.8422172337f, 0.8474695395f, 0.8526401644f, 0.8577286100f, 0.8627343860f, 0.8676570098f, + 0.8724960071f, 0.8772509113f, 0.8819212643f, 0.8865066159f, 0.8910065242f, 0.8954205554f, + 0.8997482841f, 0.9039892931f, 0.9081431738f, 0.9122095258f, 0.9161879571f, 0.9200780843f, + 0.9238795325f, 0.9275919353f, 0.9312149348f, 0.9347481818f, 0.9381913359f, 0.9415440652f, + 0.9448060465f, 0.9479769654f, 0.9510565163f, 0.9540444024f, 0.9569403357f, 0.9597440372f, + 0.9624552365f, 0.9650736723f, 0.9675990924f, 0.9700312532f, 0.9723699204f, 0.9746148686f, + 0.9767658813f, 0.9788227513f, 0.9807852804f, 0.9826532793f, 0.9844265681f, 0.9861049758f, + 0.9876883406f, 0.9891765100f, 0.9905693404f, 0.9918666978f, 0.9930684570f, 0.9941745021f, + 0.9951847267f, 0.9960990333f, 0.9969173337f, 0.9976395492f, 0.9982656102f, 0.9987954562f, + 0.9992290362f, 0.9995663085f, 0.9998072405f, 0.9999518090f +}; + +const float ivas_mdft_coeff_cos_twid_80[IVAS_80_PT_LEN + 1] = +{ + 1.0000000000f, 0.9998072405f, 0.9992290362f, 0.9982656102f, 0.9969173337f, 0.9951847267f, + 0.9930684570f, 0.9905693404f, 0.9876883406f, 0.9844265681f, 0.9807852804f, 0.9767658813f, + 0.9723699204f, 0.9675990924f, 0.9624552365f, 0.9569403357f, 0.9510565163f, 0.9448060465f, + 0.9381913359f, 0.9312149348f, 0.9238795325f, 0.9161879571f, 0.9081431738f, 0.8997482841f, + 0.8910065242f, 0.8819212643f, 0.8724960071f, 0.8627343860f, 0.8526401644f, 0.8422172337f, + 0.8314696123f, 0.8204014435f, 0.8090169944f, 0.7973206538f, 0.7853169309f, 0.7730104534f, + 0.7604059656f, 0.7475083269f, 0.7343225094f, 0.7208535967f, 0.7071067812f, 0.6930873625f, + 0.6788007455f, 0.6642524379f, 0.6494480483f, 0.6343932842f, 0.6190939493f, 0.6035559420f, + 0.5877852523f, 0.5717879602f, 0.5555702330f, 0.5391383229f, 0.5224985647f, 0.5056573734f, + 0.4886212415f, 0.4713967368f, 0.4539904997f, 0.4364092407f, 0.4186597375f, 0.4007488331f, + 0.3826834324f, 0.3644704999f, 0.3461170571f, 0.3276301796f, 0.3090169944f, 0.2902846773f, + 0.2714404499f, 0.2524915770f, 0.2334453639f, 0.2143091531f, 0.1950903220f, 0.1757962799f, + 0.1564344650f, 0.1370123417f, 0.1175373975f, 0.0980171403f, 0.0784590957f, 0.0588708037f, + 0.0392598158f, 0.0196336925f, 0.000000000f +}; + +const float ivas_mdft_coeff_sin_twid_80[IVAS_80_PT_LEN] = +{ + 0.0000000000f, 0.0196336925f, 0.0392598158f, 0.0588708037f, 0.0784590957f, 0.0980171403f, + 0.1175373975f, 0.1370123417f, 0.1564344650f, 0.1757962799f, 0.1950903220f, 0.2143091531f, + 0.2334453639f, 0.2524915770f, 0.2714404499f, 0.2902846773f, 0.3090169944f, 0.3276301796f, + 0.3461170571f, 0.3644704999f, 0.3826834324f, 0.4007488331f, 0.4186597375f, 0.4364092407f, + 0.4539904997f, 0.4713967368f, 0.4886212415f, 0.5056573734f, 0.5224985647f, 0.5391383229f, + 0.5555702330f, 0.5717879602f, 0.5877852523f, 0.6035559420f, 0.6190939493f, 0.6343932842f, + 0.6494480483f, 0.6642524379f, 0.6788007455f, 0.6930873625f, 0.7071067812f, 0.7208535967f, + 0.7343225094f, 0.7475083269f, 0.7604059656f, 0.7730104534f, 0.7853169309f, 0.7973206538f, + 0.8090169944f, 0.8204014435f, 0.8314696123f, 0.8422172337f, 0.8526401644f, 0.8627343860f, + 0.8724960071f, 0.8819212643f, 0.8910065242f, 0.8997482841f, 0.9081431738f, 0.9161879571f, + 0.9238795325f, 0.9312149348f, 0.9381913359f, 0.9448060465f, 0.9510565163f, 0.9569403357f, + 0.9624552365f, 0.9675990924f, 0.9723699204f, 0.9767658813f, 0.9807852804f, 0.9844265681f, + 0.9876883406f, 0.9905693404f, 0.9930684570f, 0.9951847267f, 0.9969173337f, 0.9982656102f, + 0.9992290362f, 0.9998072405f +}; + +const float ivas_mdft_coeff_cos_twid_40[IVAS_40_PT_LEN + 1] = +{ + 1.0000000000f, 0.9992290362f, 0.9969173337f, 0.9930684570f, 0.9876883406f, 0.9807852804f, + 0.9723699204f, 0.9624552365f, 0.9510565163f, 0.9381913359f, 0.9238795325f, 0.9081431738f, + 0.8910065242f, 0.8724960071f, 0.8526401644f, 0.8314696123f, 0.8090169944f, 0.7853169309f, + 0.7604059656f, 0.7343225094f, 0.7071067812f, 0.6788007455f, 0.6494480483f, 0.6190939493f, + 0.5877852523f, 0.5555702330f, 0.5224985647f, 0.4886212415f, 0.4539904997f, 0.4186597375f, + 0.3826834324f, 0.3461170571f, 0.3090169944f, 0.2714404499f, 0.2334453639f, 0.1950903220f, + 0.1564344650f, 0.1175373975f, 0.0784590957f, 0.0392598158f, 0.000000000f +}; + +const float ivas_mdft_coeff_sin_twid_40[IVAS_40_PT_LEN] = +{ + 0.0000000000f, 0.0392598158f, 0.0784590957f, 0.1175373975f, 0.1564344650f, 0.1950903220f, + 0.2334453639f, 0.2714404499f, 0.3090169944f, 0.3461170571f, 0.3826834324f, 0.4186597375f, + 0.4539904997f, 0.4886212415f, 0.5224985647f, 0.5555702330f, 0.5877852523f, 0.6190939493f, + 0.6494480483f, 0.6788007455f, 0.7071067812f, 0.7343225094f, 0.7604059656f, 0.7853169309f, + 0.8090169944f, 0.8314696123f, 0.8526401644f, 0.8724960071f, 0.8910065242f, 0.9081431738f, + 0.9238795325f, 0.9381913359f, 0.9510565163f, 0.9624552365f, 0.9723699204f, 0.9807852804f, + 0.9876883406f, 0.9930684570f, 0.9969173337f, 0.9992290362f +}; + +const float ivas_sin_twiddle_480[IVAS_480_PT_LEN >> 1] = +{ + -0.000818122995607253f, -0.00736304124977957f, -0.0139076440957708f, -0.0204516511845773f, + -0.0269947821927154f, -0.0335367568342299f, -0.0400772948727007f, -0.0466161161332467f, + -0.0531529405145281f, -0.0596874880007445f, -0.0662194786736303f, -0.0727486327244454f, + -0.0792746704659607f, -0.0857973123444399f, -0.0923162789516138f, -0.0988312910366500f, + -0.105342069518114f, -0.111848335495926f, -0.118349810263305f, -0.124846215318711f, + -0.131337272377774f, -0.137822703385212f, -0.144302230526747f, -0.150775576241001f, + -0.157242463231389f, -0.163702614477995f, -0.170155753249442f, -0.176601603114742f, + -0.183039887955141f, -0.189470331975943f, -0.195892659718330f, -0.202306596071156f, + -0.208711866282735f, -0.215108195972610f, -0.221495311143304f, -0.227872938192063f, + -0.234240803922570f, -0.240598635556650f, -0.246946160745958f, -0.253283107583640f, + -0.259609204615985f, -0.265924180854051f, -0.272227765785273f, -0.278519689385053f, + -0.284799682128326f, -0.291067475001103f, -0.297322799511998f, -0.303565387703730f, + -0.309794972164597f, -0.316011286039934f, -0.322214063043544f, -0.328403037469105f, + -0.334577944201551f, -0.340738518728429f, -0.346884497151231f, -0.353015616196696f, + -0.359131613228090f, -0.365232226256457f, -0.371317193951838f, -0.377386255654469f, + -0.383439151385947f, -0.389475621860365f, -0.395495408495417f, -0.401498253423481f, + -0.407483899502658f, -0.413452090327791f, -0.419402570241451f, -0.425335084344881f, + -0.431249378508924f, -0.437145199384900f, -0.443022294415467f, -0.448880411845434f, + -0.454719300732547f, -0.460538710958240f, -0.466338393238348f, -0.472118099133784f, + -0.477877581061184f, -0.483616592303511f, -0.489334887020625f, -0.495032220259813f, + -0.500708347966279f, -0.506363026993606f, -0.511996015114162f, -0.517607071029487f, + -0.523195954380619f, -0.528762425758396f, -0.534306246713712f, -0.539827179767727f, + -0.545324988422047f, -0.550799437168844f, -0.556250291500956f, -0.561677317921925f, + -0.567080283956001f, -0.572458958158102f, -0.577813110123727f, -0.583142510498826f, + -0.588446930989624f, -0.593726144372402f, -0.598979924503229f, -0.604208046327650f, + -0.609410285890327f, -0.614586420344631f, -0.619736227962191f, -0.624859488142386f, + -0.629955981421804f, -0.635025489483634f, -0.640067795167023f, -0.645082682476378f, + -0.650069936590618f, -0.655029343872374f, -0.659960691877147f, -0.664863769362399f, + -0.669738366296610f, -0.674584273868271f, -0.679401284494831f, -0.684189191831585f, + -0.688947790780520f, -0.693676877499095f, -0.698376249408973f, -0.703045705204703f, + -0.707685044862340f, -0.712294069648014f, -0.716872582126442f, -0.721420386169390f, + -0.725937286964068f, -0.730423091021479f, -0.734877606184707f, -0.739300641637149f, + -0.743692007910687f, -0.748051516893805f, -0.752378981839648f, -0.756674217374021f, + -0.760937039503328f, -0.765167265622459f, -0.769364714522605f, -0.773529206399025f, + -0.777660562858748f, -0.781758606928213f, -0.785823163060853f, -0.789854057144609f, + -0.793851116509396f, -0.797814169934493f, -0.801743047655882f, -0.805637581373517f, + -0.809497604258536f, -0.813322950960406f, -0.817113457614006f, -0.820868961846646f, + -0.824589302785025f, -0.828274321062119f, -0.831923858824010f, -0.835537759736646f, + -0.839115868992540f, -0.842658033317402f, -0.846164100976699f, -0.849633921782164f, + -0.853067347098221f, -0.856464229848356f, -0.859824424521420f, -0.863147787177854f, + -0.866434175455865f, -0.869683448577516f, -0.872895467354761f, -0.876070094195407f, + -0.879207193109004f, -0.882306629712678f, -0.885368271236879f, -0.888391986531075f, + -0.891377646069366f, -0.894325121956035f, -0.897234287931024f, -0.900105019375345f, + -0.902937193316419f, -0.905730688433339f, -0.908485385062073f, -0.911201165200584f, + -0.913877912513892f, -0.916515512339049f, -0.919113851690058f, -0.921672819262709f, + -0.924192305439348f, -0.926672202293573f, -0.929112403594856f, -0.931512804813095f, + -0.933873303123092f, -0.936193797408954f, -0.938474188268430f, -0.940714378017165f, + -0.942914270692887f, -0.945073772059515f, -0.947192789611197f, -0.949271232576274f, + -0.951309011921168f, -0.953306040354194f, -0.955262232329299f, -0.957177504049732f, + -0.959051773471624f, -0.960884960307514f, -0.962676986029777f, -0.964427773873996f, + -0.966137248842248f, -0.967805337706313f, -0.969431969010818f, -0.971017073076290f, + -0.972560582002147f, -0.974062429669605f, -0.975522551744506f, -0.976940885680082f, + -0.978317370719628f, -0.979651947899104f, -0.980944560049668f, -0.982195151800116f, + -0.983403669579260f, -0.984570061618221f, -0.985694277952645f, -0.986776270424848f, + -0.987815992685872f, -0.988813400197476f, -0.989768450234042f, -0.990681101884405f, + -0.991551316053606f, -0.992379055464567f, -0.993164284659685f, -0.993906970002356f, + -0.994607079678411f, -0.995264583697482f, -0.995879453894286f, -0.996451663929828f, + -0.996981189292537f, -0.997468007299307f, -0.997912097096476f, -0.998313439660714f, + -0.998672017799843f, -0.998987816153568f, -0.999260821194138f, -0.999491021226926f, + -0.999678406390929f, -0.999822968659191f, -0.999924701839145f, -0.999983601572879f +}; + +const float ivas_cos_twiddle_480[IVAS_480_PT_LEN >> 1] = +{ + 0.999999665337326f, 0.999972892444367f, 0.999903284040864f, 0.999790843108610f, + 0.999635574464198f, 0.999437484758823f, 0.999196582477986f, 0.998912877941140f, + 0.998586383301244f, 0.998217112544241f, 0.997805081488460f, 0.997350307783942f, + 0.996852810911678f, 0.996312612182778f, 0.995729734737558f, 0.995104203544548f, + 0.994436045399422f, 0.993725288923851f, 0.992971964564277f, 0.992176104590609f, + 0.991337743094838f, 0.990456915989581f, 0.989533661006540f, 0.988568017694885f, + 0.987560027419562f, 0.986509733359519f, 0.985417180505858f, 0.984282415659908f, + 0.983105487431216f, 0.981886446235473f, 0.980625344292344f, 0.979322235623241f, + 0.977977176049001f, 0.976590223187499f, 0.975161436451181f, 0.973690877044515f, + 0.972178607961371f, 0.970624693982323f, 0.969029201671875f, 0.967392199375607f, + 0.965713757217249f, 0.963993947095677f, 0.962232842681832f, 0.960430519415566f, + 0.958587054502409f, 0.956702526910263f, 0.954777017366017f, 0.952810608352092f, + 0.950803384102905f, 0.948755430601263f, 0.946666835574676f, 0.944537688491606f, + 0.942368080557626f, 0.940158104711519f, 0.937907855621296f, 0.935617429680138f, + 0.933286925002268f, 0.930916441418752f, 0.928506080473216f, 0.926055945417500f, + 0.923566141207236f, 0.921036774497350f, 0.918467953637493f, 0.915859788667400f, + 0.913212391312179f, 0.910525874977521f, 0.907800354744844f, 0.905035947366364f, + 0.902232771260093f, 0.899390946504765f, 0.896510594834693f, 0.893591839634558f, + 0.890634805934118f, 0.887639620402854f, 0.884606411344546f, 0.881535308691775f, + 0.878426444000357f, 0.875279950443708f, 0.872095962807140f, 0.868874617482085f, + 0.865616052460258f, 0.862320407327736f, 0.858987823258990f, 0.855618443010829f, + 0.852212410916289f, 0.848769872878448f, 0.845290976364179f, 0.841775870397828f, + 0.838224705554838f, 0.834637633955290f, 0.831014809257393f, 0.827356386650900f, + 0.823662522850458f, 0.819933376088899f, 0.816169106110459f, 0.812369874163934f, + 0.808535842995778f, 0.804667176843123f, 0.800764041426753f, 0.796826603943998f, + 0.792855033061574f, 0.788849498908361f, 0.784810173068109f, 0.780737228572095f, + 0.776630839891703f, 0.772491182930959f, 0.768318435018988f, 0.764112774902423f, + 0.759874382737746f, 0.755603440083571f, 0.751300129892866f, 0.746964636505118f, + 0.742597145638433f, 0.738197844381584f, 0.733766921185995f, 0.729304565857669f, + 0.724810969549055f, 0.720286324750863f, 0.715730825283819f, 0.711144666290356f, + 0.706528044226263f, 0.701881156852263f, 0.697204203225545f, 0.692497383691237f, + 0.687760899873822f, 0.682994954668502f, 0.678199752232508f, 0.673375497976352f, + 0.668522398555031f, 0.663640661859171f, 0.658730497006124f, 0.653792114331011f, + 0.648825725377709f, 0.643831542889792f, 0.638809780801415f, 0.633760654228152f, + 0.628684379457781f, 0.623581173941019f, 0.618451256282204f, 0.613294846229936f, + 0.608112164667659f, 0.602903433604202f, 0.597668876164268f, 0.592408716578875f, + 0.587123180175754f, 0.581812493369691f, 0.576476883652835f, 0.571116579584947f, + 0.565731810783613f, 0.560322807914407f, 0.554889802681009f, 0.549433027815281f, + 0.543952717067296f, 0.538449105195327f, 0.532922427955790f, 0.527372922093143f, + 0.521800825329746f, 0.516206376355680f, 0.510589814818519f, 0.504951381313066f, + 0.499291317371047f, 0.493609865450762f, 0.487907268926702f, 0.482183772079123f, + 0.476439620083580f, 0.470675059000427f, 0.464890335764274f, 0.459085698173413f, + 0.453261394879198f, 0.447417675375397f, 0.441554789987504f, 0.435672989862017f, + 0.429772526955677f, 0.423853654024676f, 0.417916624613831f, 0.411961693045722f, + 0.405989114409798f, 0.399999144551449f, 0.393992040061048f, 0.387968058262959f, + 0.381927457204511f, 0.375870495644949f, 0.369797433044349f, 0.363708529552499f, + 0.357604045997758f, 0.351484243875885f, 0.345349385338836f, 0.339199733183530f, + 0.333035550840599f, 0.326857102363098f, 0.320664652415198f, 0.314458466260842f, + 0.308238809752391f, 0.302005949319228f, 0.295760151956351f, 0.289501685212929f, + 0.283230817180850f, 0.276947816483228f, 0.270652952262902f, 0.264346494170904f, + 0.258028712354909f, 0.251699877447663f, 0.245360260555389f, 0.239010133246176f, + 0.232649767538342f, 0.226279435888785f, 0.219899411181310f, 0.213509966714943f, + 0.207111376192219f, 0.200703913707458f, 0.194287853735029f, 0.187863471117585f, + 0.181431041054297f, 0.174990839089060f, 0.168543141098691f, 0.162088223281113f, + 0.155626362143520f, 0.149157834490539f, 0.142682917412363f, 0.136201888272891f, + 0.129715024697841f, 0.123222604562857f, 0.116724905981611f, 0.110222207293883f, + 0.103714787053643f, 0.0972029240171147f, 0.0906868971308382f, 0.0841669855197180f, + 0.0776434684750678f, 0.0711166254426455f, 0.0645867360106837f, 0.0580540798979125f, + 0.0515189369415777f, 0.0449815870854525f, 0.0384423103678466f, 0.0319013869096108f, + 0.0253590969021360f, 0.0188157205953513f, 0.0122715382857199f, 0.00572683030423125f +}; + +const float ivas_sin_twiddle_320[IVAS_320_PT_LEN >> 1] = +{ + -0.00122718432228885f, -0.0110444371277961f, -0.0208606254474658f, -0.0306748031766366f, + -0.0404860244044325f, -0.0502933435049309f, -0.0600958152283046f, -0.0698924947919266f, + -0.0796824379714301f, -0.0894647011917154f, -0.0992383416178931f, -0.109002417246156f, + -0.118755986994574f, -0.128498110793793f, -0.138227849677645f, -0.147944265873646f, + -0.157646422893378f, -0.167333385622756f, -0.177004220412149f, -0.186657995166372f, + -0.196293779434521f, -0.205910644499654f, -0.215507663468299f, -0.225083911359793f, + -0.234638465195433f, -0.244170404087435f, -0.253678809327687f, -0.263162764476304f, + -0.272621355449949f, -0.282053670609936f, -0.291458800850100f, -0.300835839684411f, + -0.310183883334351f, -0.319502030816016f, -0.328789384026957f, -0.338045047832741f, + -0.347268130153228f, -0.356457742048546f, -0.365612997804774f, -0.374733015019307f, + -0.383816914685905f, -0.392863821279410f, -0.401872862840135f, -0.410843171057904f, + -0.419773881355741f, -0.428664132973198f, -0.437513069049322f, -0.446319836705237f, + -0.455083587126344f, -0.463803475644138f, -0.472478661817616f, -0.481108309514277f, + -0.489691586990715f, -0.498227666972782f, -0.506715726735323f, -0.515154948181472f, + -0.523544517921500f, -0.531883627351215f, -0.540171472729893f, -0.548407255257747f, + -0.556590181152914f, -0.564719461727967f, -0.572794313465923f, -0.580813958095765f, + -0.588777622667452f, -0.596684539626417f, -0.604533946887548f, -0.612325087908634f, + -0.620057211763289f, -0.627729573213322f, -0.635341432780567f, -0.642892056818157f, + -0.650380717581231f, -0.657806693297079f, -0.665169268234704f, -0.672467732773812f, + -0.679701383473197f, -0.686869523138552f, -0.693971460889654f, -0.701006512226963f, + -0.707973999097587f, -0.714873249960641f, -0.721703599851967f, -0.728464390448225f, + -0.735154970130347f, -0.741774694046338f, -0.748322924173428f, -0.754799029379569f, + -0.761202385484262f, -0.767532375318718f, -0.773788388785342f, -0.779969822916534f, + -0.786076081932809f, -0.792106577300212f, -0.798060727787049f, -0.803937959519903f, + -0.809737706038947f, -0.815459408352540f, -0.821102514991105f, -0.826666482060278f, + -0.832150773293332f, -0.837554860102865f, -0.842878221631741f, -0.848120344803297f, + -0.853280724370791f, -0.858358862966099f, -0.863354271147654f, -0.868266467447619f, + -0.873094978418290f, -0.877839338677730f, -0.882499090954623f, -0.887073786132345f, + -0.891562983292255f, -0.895966249756185f, -0.900283161128150f, -0.904513301335247f, + -0.908656262667757f, -0.912711645818445f, -0.916679059921043f, -0.920558122587921f, + -0.924348459946945f, -0.928049706677513f, -0.931661506045761f, -0.935183509938948f, + -0.938615378899008f, -0.941956782155269f, -0.945207397656329f, -0.948366912101102f, + -0.951435020969008f, -0.954411428549330f, -0.957295847969710f, -0.960088001223801f, + -0.962787619198060f, -0.965394441697689f, -0.967908217471710f, -0.970328704237180f, + -0.972655668702548f, -0.974888886590136f, -0.977028142657754f, -0.979073230719452f, + -0.981023953665385f, -0.982880123480816f, -0.984641561264233f, -0.986308097244599f, + -0.987879570797705f, -0.989355830461661f, -0.990736733951487f, -0.992022148172831f, + -0.993211949234795f, -0.994306022461875f, -0.995304262405018f, -0.996206572851780f, + -0.997012866835602f, -0.997723066644192f, -0.998337103827013f, -0.998854919201885f, + -0.999276462860683f, -0.999601694174153f, -0.999830581795823f, -0.999963103665029f +}; + +const float ivas_cos_twiddle_320[IVAS_320_PT_LEN >> 1] = +{ + 0.999999247009036f, 0.999939008344274f, 0.999782393476671f, 0.999529417501093f, + 0.999180104799892f, 0.998734489040553f, 0.998192613172451f, 0.997554529422708f, + 0.996820299291166f, 0.995989993544452f, 0.995063692209162f, 0.994041484564148f, + 0.992923469131909f, 0.991709753669100f, 0.990400455156143f, 0.988995699785954f, + 0.987495622951779f, 0.985900369234146f, 0.984210092386929f, 0.982424955322528f, + 0.980545130096168f, 0.978570797889318f, 0.976502148992226f, 0.974339382785576f, + 0.972082707721278f, 0.969732341302371f, 0.967288510062064f, 0.964751449541896f, + 0.962121404269042f, 0.959398627732738f, 0.956583382359856f, 0.953675939489602f, + 0.950676579347373f, 0.947585591017741f, 0.944403272416596f, 0.941129930262426f, + 0.937765880046764f, 0.934311446003768f, 0.930766961078984f, 0.927132766897244f, + 0.923409213729749f, 0.919596660460302f, 0.915695474550723f, 0.911706032005430f, + 0.907628717335198f, 0.903463923520102f, 0.899212051971637f, 0.894873512494035f, + 0.890448723244758f, 0.885938110694205f, 0.881342109584601f, 0.876661162888100f, + 0.871895721764085f, 0.867046245515693f, 0.862113201545536f, 0.857097065310660f, + 0.851998320276715f, 0.846817457871361f, 0.841554977436898f, 0.836211386182145f, + 0.830787199133548f, 0.825282939085545f, 0.819699136550175f, 0.814036329705948f, + 0.808295064345975f, 0.802475893825360f, 0.796579379007870f, 0.790606088211875f, + 0.784556597155575f, 0.778431488901510f, 0.772231353800360f, 0.765956789434051f, + 0.759608400558158f, 0.753186799043613f, 0.746692603817734f, 0.740126440804576f, + 0.733488942864595f, 0.726780749733659f, 0.720002507961382f, 0.713154870848815f, + 0.706238498385475f, 0.699254057185735f, 0.692202220424575f, 0.685083667772700f, + 0.677899085331031f, 0.670649165564576f, 0.663334607235692f, 0.655956115336735f, + 0.648514401022112f, 0.641010181539737f, 0.633444180161903f, 0.625817126115569f, + 0.618129754512079f, 0.610382806276310f, 0.602577028075254f, 0.594713172246063f, + 0.586791996723527f, 0.578814264967032f, 0.570780745886967f, 0.562692213770623f, + 0.554549448207560f, 0.546353234014470f, 0.538104361159537f, 0.529803624686295f, + 0.521451824637002f, 0.513049765975530f, 0.504598258509780f, 0.496098116813633f, + 0.487550160148436f, 0.478955212384045f, 0.470314101919413f, 0.461627661602753f, + 0.452896728651262f, 0.444122144570429f, 0.435304755072932f, 0.426445409997122f, + 0.417544963225117f, 0.408604272600502f, 0.399624199845647f, 0.390605610478656f, + 0.381549373729942f, 0.372456362458452f, 0.363327453067539f, 0.354163525420491f, + 0.344965462755725f, 0.335734151601668f, 0.326470481691301f, 0.317175345876411f, + 0.307849640041535f, 0.298494263017610f, 0.289110116495347f, 0.279698104938318f, + 0.270259135495788f, 0.260794117915276f, 0.251303964454877f, 0.241789589795333f, + 0.232251910951879f, 0.222691847185850f, 0.213110319916091f, 0.203508252630144f, + 0.193886570795236f, 0.184246201769091f, 0.174588074710540f, 0.164913120489970f, + 0.155222271599607f, 0.145516462063635f, 0.135796627348180f, 0.126063704271142f, + 0.116318630911905f, 0.106562346520921f, 0.0967957914291864f, 0.0870199069576083f, + 0.0772356353262796f, 0.0674439195636641f, 0.0576457034157070f, 0.0478419312548745f, + 0.0380335479891316f, 0.0282214989708730f, 0.0184067299058048f, 0.00859018676179777f +}; + +const float ivas_sin_twiddle_160[IVAS_160_PT_LEN >> 1] = +{ + -0.00245436679646029f, -0.0220875270185783f, -0.0417121720785753f, -0.0613207363022086f, + -0.0809056602147038f, -0.100459393455076f, -0.119974397686940f, -0.139443149504679f, + -0.158858143333861f, -0.178211894324786f, -0.197496941238030f, -0.216705849320900f, + -0.235831213173673f, -0.254865659604515f, -0.273801850471989f, -0.292632485514050f, + -0.311350305162432f, -0.329948093341349f, -0.348418680249435f, -0.366754945123831f, + -0.384949818985382f, -0.402996287363860f, -0.420887393002174f, -0.438616238538528f, + -0.456175989165483f, -0.473559875264908f, -0.490761195017794f, -0.507773316987935f, + -0.524589682678469f, -0.541203809060310f, -0.557609291071472f, -0.573799804086349f, + -0.589769106353971f, -0.605511041404326f, -0.621019540421789f, -0.636288624584773f, + -0.651312407370671f, -0.666085096825230f, -0.680600997795453f, -0.694854514125194f, + -0.708840150812579f, -0.722552516128436f, -0.735986323694910f, -0.749136394523459f, + -0.761997659011457f, -0.774565158896617f, -0.786834049168500f, -0.798799599936358f, + -0.810457198252595f, -0.821802349891147f, -0.832830681080094f, -0.843537940187827f, + -0.853919999362139f, -0.863972856121587f, -0.873692634898524f, -0.883075588533209f, + -0.892118099718401f, -0.900816682393908f, -0.909167983090522f, -0.917168782222852f, + -0.924815995330528f, -0.932106674267327f, -0.939038008337734f, -0.945607325380521f, + -0.951812092798916f, -0.957649918536965f, -0.963118552001719f, -0.968215884930876f, + -0.972939952205560f, -0.977288932607910f, -0.981261149523195f, -0.984855071586178f, + -0.988069313271492f, -0.990902635427780f, -0.993353945755417f, -0.995422299227608f, + -0.997106898454717f, -0.998407093991674f, -0.999322384588350f, -0.999852417382795f +}; + +const float ivas_cos_twiddle_160[IVAS_160_PT_LEN >> 1] = +{ + 0.999996988037278f, 0.999756040817060f, 0.999129668611881f, 0.998118112900149f, + 0.996721763655847f, 0.994941159198190f, 0.992776985984091f, 0.990230078343521f, + 0.987301418157858f, 0.983992134481354f, 0.980303503105861f, 0.976236946068990f, + 0.971794031105889f, 0.966976471044852f, 0.961786123146989f, 0.956224988390216f, + 0.950295210697844f, 0.943999076112052f, 0.937339011912575f, 0.930317585680942f, + 0.922937504310623f, 0.915201612963474f, 0.907112893972869f, 0.898674465693954f, + 0.889889581301463f, 0.880761627535558f, 0.871294123396174f, 0.861490718786378f, + 0.851355193105265f, 0.840891453790923f, 0.830103534814044f, 0.818995595122750f, + 0.807571917039244f, 0.795836904608884f, 0.783795081902349f, 0.771451091271519f, + 0.758809691559762f, 0.745875756267305f, 0.732654271672413f, 0.719150334909079f, + 0.705369152001986f, 0.691316035859480f, 0.676996404225349f, 0.662415777590172f, + 0.647579777063073f, 0.632494122204673f, 0.617164628822086f, 0.601597206726822f, + 0.585797857456439f, 0.569772671960834f, 0.553527828254070f, 0.537069589032630f, + 0.520404299261031f, 0.503538383725718f, 0.486478344558187f, 0.469230758728290f, + 0.451802275508688f, 0.434199613911428f, 0.416429560097637f, 0.398498964761330f, + 0.380414740488332f, 0.362183859091351f, 0.343813348922205f, 0.325310292162263f, + 0.306681822092128f, 0.287935120341621f, 0.269077414121127f, 0.250115973435366f, + 0.231058108280671f, 0.211911165826842f, 0.192682527584672f, 0.173379606560240f, + 0.154009844397046f, 0.134580708507126f, 0.115099689192216f, 0.0955742967560992f, + 0.0760120586092433f, 0.0564205163668375f, 0.0368072229413588f, 0.0171797396307788f +}; + +const float ivas_sin_twiddle_80[IVAS_80_PT_LEN >> 1] = +{ + -0.00490871880799799f, -0.0441642771270674f, -0.0833517373318975f, -0.122410675199216f, + -0.161280864677880f, -0.199902370753082f, -0.238215641861795f, -0.276161601716971f, + -0.313681740398891f, -0.350718204573223f, -0.387213886696666f, -0.423112513072644f, + -0.458358730621271f, -0.492898192229784f, -0.526677640551852f, -0.559644990126546f, + -0.591749407690343f, -0.622941390558334f, -0.653172842953777f, -0.682397150168297f, + -0.710569250438390f, -0.737645704427393f, -0.763584762205797f, -0.788346427626606f, + -0.811892519996505f, -0.834186732947712f, -0.855194690419775f, -0.874883999664958f, + -0.893224301195515f, -0.910187315595818f, -0.925746887127164f, -0.939879024058033f, + -0.952561935657595f, -0.963776065795440f, -0.973504123095711f, -0.981731107599154f, + -0.988444333891970f, -0.993633450665799f, -0.997290456678690f, -0.999409713092437f +}; + +const float ivas_cos_twiddle_80[IVAS_80_PT_LEN >> 1] = +{ + 0.999987952167257f, 0.999024282300407f, 0.996520189400975f, 0.992479534598710f, + 0.986908548290446f, 0.979815820533276f, 0.971212287799312f, 0.961111216112432f, + 0.949528180593037f, 0.936481041442343f, 0.921989916403245f, 0.906077149740215f, + 0.888767277786068f, 0.870086991108712f, 0.850065093356229f, 0.828732456843738f, + 0.806121974950521f, 0.782268511400816f, 0.757208846506485f, 0.730981620454432f, + 0.703627273726243f, 0.675187984741891f, 0.645707604823667f, 0.615231590580627f, + 0.583806933817786f, 0.551482089078169f, 0.518306898929413f, 0.484332517110141f, + 0.449611329654607f, 0.414196874117224f, 0.378143757021541f, 0.341507569660936f, + 0.304344802380877f, 0.266712757474898f, 0.228669460828619f, 0.190273572448036f, + 0.151584296010041f, 0.112661287574648f, 0.0735645635996675f, 0.0343544083996823f +}; + +const int16_t dirac_gains_P_idx[16] = +{ + -1, 1, 0, 1, 4, 3, 2, 3, 4, 8, 7, 6, 5, 6, 7, 8 +}; + +const float dirac_gains_norm_term[9] = +{ + 1.000000e+00f, 7.071068e-01f, 1.000000e+00f, 4.082483e-01f, 2.041242e-01f, 1.000000e+00f, 2.886751e-01f, 9.128709e-02f, 3.726780e-02f +}; + +const float dirac_gains_Pnm[91][9] = +{ + {-1.000000e+00f,-0.000000e+00f,1.000000e+00f,-0.000000e+00f,0.000000e+00f,-1.000000e+00f,-0.000000e+00f,0.000000e+00f,-0.000000e+00f}, + {-9.998477e-01f,1.745221e-02f,9.995431e-01f,-5.234867e-02f,9.137391e-04f,-9.990864e-01f,1.046734e-01f,-4.568000e-03f,7.973384e-05f}, + {-9.993909e-01f,3.489930e-02f,9.981732e-01f,-1.046341e-01f,3.653884e-03f,-9.963478e-01f,2.090770e-01f,-1.825829e-02f,6.375900e-04f}, + {-9.986295e-01f,5.233614e-02f,9.958913e-01f,-1.567932e-01f,8.217215e-03f,-9.917910e-01f,3.129416e-01f,-4.102976e-02f,2.150287e-03f}, + {-9.975641e-01f,6.975590e-02f,9.927012e-01f,-2.087579e-01f,1.459766e-02f,-9.854290e-01f,4.159897e-01f,-7.281048e-02f,5.091363e-03f}, + {-9.961947e-01f,8.715547e-02f,9.886059e-01f,-2.604715e-01f,2.278823e-02f,-9.772766e-01f,5.179674e-01f,-1.135075e-01f,9.930593e-03f}, + {-9.945220e-01f,1.045284e-01f,9.836106e-01f,-3.118673e-01f,3.277856e-02f,-9.673560e-01f,6.186047e-01f,-1.629950e-01f,1.713145e-02f}, + {-9.925461e-01f,1.218695e-01f,9.777218e-01f,-3.628832e-01f,4.455650e-02f,-9.556924e-01f,7.176415e-01f,-2.211219e-01f,2.715038e-02f}, + {-9.902681e-01f,1.391732e-01f,9.709461e-01f,-4.134564e-01f,5.810756e-02f,-9.423163e-01f,8.148217e-01f,-2.877103e-01f,4.043508e-02f}, + {-9.876884e-01f,1.564343e-01f,9.632925e-01f,-4.635251e-01f,7.341509e-02f,-9.272624e-01f,9.098945e-01f,-3.625562e-01f,5.742321e-02f}, + {-9.848077e-01f,1.736484e-01f,9.547693e-01f,-5.130307e-01f,9.046126e-02f,-9.105685e-01f,1.002619e+00f,-4.454347e-01f,7.854224e-02f}, + {-9.816272e-01f,1.908091e-01f,9.453878e-01f,-5.619103e-01f,1.092244e-01f,-8.922793e-01f,1.092752e+00f,-5.360881e-01f,1.042050e-01f}, + {-9.781475e-01f,2.079115e-01f,9.351591e-01f,-6.101044e-01f,1.296816e-01f,-8.724410e-01f,1.180063e+00f,-6.342387e-01f,1.348115e-01f}, + {-9.743701e-01f,2.249510e-01f,9.240957e-01f,-6.575567e-01f,1.518089e-01f,-8.511051e-01f,1.264332e+00f,-7.395903e-01f,1.707479e-01f}, + {-9.702957e-01f,2.419219e-01f,9.122107e-01f,-7.042075e-01f,1.755787e-01f,-8.283265e-01f,1.345341e+00f,-8.518162e-01f,2.123816e-01f}, + {-9.659258e-01f,2.588191e-01f,8.995191e-01f,-7.500002e-01f,2.009620e-01f,-8.041639e-01f,1.422883e+00f,-9.705719e-01f,2.600640e-01f}, + {-9.612616e-01f,2.756374e-01f,8.860360e-01f,-7.948789e-01f,2.279279e-01f,-7.786796e-01f,1.496760e+00f,-1.095492e+00f,3.141272e-01f}, + {-9.563048e-01f,2.923716e-01f,8.717782e-01f,-8.387891e-01f,2.564435e-01f,-7.519395e-01f,1.566788e+00f,-1.226191e+00f,3.748840e-01f}, + {-9.510565e-01f,3.090171e-01f,8.567626e-01f,-8.816782e-01f,2.864747e-01f,-7.240118e-01f,1.632789e+00f,-1.362268e+00f,4.426280e-01f}, + {-9.455186e-01f,3.255681e-01f,8.410082e-01f,-9.234920e-01f,3.179837e-01f,-6.949692e-01f,1.694595e+00f,-1.503298e+00f,5.176268e-01f}, + {-9.396926e-01f,3.420202e-01f,8.245332e-01f,-9.641815e-01f,3.509334e-01f,-6.648846e-01f,1.752055e+00f,-1.648848e+00f,6.001316e-01f}, + {-9.335804e-01f,3.583678e-01f,8.073587e-01f,-1.003696e+00f,3.852825e-01f,-6.338369e-01f,1.805025e+00f,-1.798461e+00f,6.903643e-01f}, + {-9.271840e-01f,3.746064e-01f,7.895051e-01f,-1.041987e+00f,4.209899e-01f,-6.019047e-01f,1.853375e+00f,-1.951675e+00f,7.885275e-01f}, + {-9.205049e-01f,3.907311e-01f,7.709939e-01f,-1.079010e+00f,4.580124e-01f,-5.691693e-01f,1.896987e+00f,-2.108013e+00f,8.947984e-01f}, + {-9.135456e-01f,4.067366e-01f,7.518480e-01f,-1.114717e+00f,4.963039e-01f,-5.357154e-01f,1.935757e+00f,-2.266981e+00f,1.009325e+00f}, + {-9.063079e-01f,4.226184e-01f,7.320906e-01f,-1.149067e+00f,5.358188e-01f,-5.016273e-01f,1.969593e+00f,-2.428084e+00f,1.132234e+00f}, + {-8.987941e-01f,4.383712e-01f,7.117461e-01f,-1.182016e+00f,5.765077e-01f,-4.669925e-01f,1.998415e+00f,-2.590808e+00f,1.263622e+00f}, + {-8.910065e-01f,4.539906e-01f,6.908387e-01f,-1.213526e+00f,6.183225e-01f,-4.318987e-01f,2.022162e+00f,-2.754647e+00f,1.403563e+00f}, + {-8.829476e-01f,4.694716e-01f,6.693946e-01f,-1.243556e+00f,6.612108e-01f,-3.964354e-01f,2.040781e+00f,-2.919073e+00f,1.552099e+00f}, + {-8.746198e-01f,4.848095e-01f,6.474397e-01f,-1.272072e+00f,7.051207e-01f,-3.606927e-01f,2.054234e+00f,-3.083563e+00f,1.709246e+00f}, + {-8.660253e-01f,5.000000e-01f,6.250001e-01f,-1.299038e+00f,7.500000e-01f,-3.247595e-01f,2.062500e+00f,-3.247595e+00f,1.875000e+00f}, + {-8.571672e-01f,5.150381e-01f,6.021037e-01f,-1.324421e+00f,7.957926e-01f,-2.887278e-01f,2.065570e+00f,-3.410637e+00f,2.049318e+00f}, + {-8.480480e-01f,5.299194e-01f,5.787782e-01f,-1.348191e+00f,8.424437e-01f,-2.526874e-01f,2.063448e+00f,-3.572164e+00f,2.232136e+00f}, + {-8.386706e-01f,5.446391e-01f,5.550525e-01f,-1.370318e+00f,8.898951e-01f,-2.167299e-01f,2.056155e+00f,-3.731644e+00f,2.423358e+00f}, + {-8.290377e-01f,5.591928e-01f,5.309552e-01f,-1.390776e+00f,9.380897e-01f,-1.809446e-01f,2.043725e+00f,-3.888559e+00f,2.622865e+00f}, + {-8.191521e-01f,5.735765e-01f,5.065152e-01f,-1.409539e+00f,9.869699e-01f,-1.454202e-01f,2.026202e+00f,-4.042392e+00f,2.830513e+00f}, + {-8.090171e-01f,5.877852e-01f,4.817629e-01f,-1.426585e+00f,1.036474e+00f,-1.102460e-01f,2.003651e+00f,-4.192627e+00f,3.046121e+00f}, + {-7.986355e-01f,6.018150e-01f,4.567280e-01f,-1.441893e+00f,1.086544e+00f,-7.550830e-02f,1.976144e+00f,-4.338763e+00f,3.269493e+00f}, + {-7.880108e-01f,6.156614e-01f,4.314414e-01f,-1.455444e+00f,1.137117e+00f,-4.129366e-02f,1.943771e+00f,-4.480302e+00f,3.500396e+00f}, + {-7.771459e-01f,6.293205e-01f,4.059335e-01f,-1.467221e+00f,1.188133e+00f,-7.685401e-03f,1.906632e+00f,-4.616763e+00f,3.738582e+00f}, + {-7.660444e-01f,6.427876e-01f,3.802360e-01f,-1.477211e+00f,1.239528e+00f,2.523343e-02f,1.864843e+00f,-4.747667e+00f,3.983766e+00f}, + {-7.547096e-01f,6.560589e-01f,3.543800e-01f,-1.485402e+00f,1.291240e+00f,5.738307e-02f,1.818529e+00f,-4.872555e+00f,4.235647e+00f}, + {-7.431449e-01f,6.691306e-01f,3.283964e-01f,-1.491783e+00f,1.343207e+00f,8.868646e-02f,1.767831e+00f,-4.990988e+00f,4.493906e+00f}, + {-7.313538e-01f,6.819984e-01f,3.023174e-01f,-1.496346e+00f,1.395365e+00f,1.190676e-01f,1.712898e+00f,-5.102528e+00f,4.758184e+00f}, + {-7.193397e-01f,6.946585e-01f,2.761744e-01f,-1.499086e+00f,1.447651e+00f,1.484544e-01f,1.653893e+00f,-5.206765e+00f,5.028115e+00f}, + {-7.071068e-01f,7.071068e-01f,2.500000e-01f,-1.500000e+00f,1.500000e+00f,1.767767e-01f,1.590990e+00f,-5.303301e+00f,5.303301e+00f}, + {-6.946585e-01f,7.193397e-01f,2.238256e-01f,-1.499086e+00f,1.552349e+00f,2.039685e-01f,1.524373e+00f,-5.391762e+00f,5.583331e+00f}, + {-6.819984e-01f,7.313538e-01f,1.976825e-01f,-1.496346e+00f,1.604635e+00f,2.299670e-01f,1.454233e+00f,-5.471792e+00f,5.867779e+00f}, + {-6.691307e-01f,7.431448e-01f,1.716038e-01f,-1.491783e+00f,1.656792e+00f,2.547115e-01f,1.380777e+00f,-5.543053e+00f,6.156183e+00f}, + {-6.560589e-01f,7.547096e-01f,1.456200e-01f,-1.485402e+00f,1.708760e+00f,2.781472e-01f,1.304214e+00f,-5.605237e+00f,6.448089e+00f}, + {-6.427876e-01f,7.660444e-01f,1.197639e-01f,-1.477212e+00f,1.760472e+00f,3.002205e-01f,1.224767e+00f,-5.658049e+00f,6.743000e+00f}, + {-6.293203e-01f,7.771461e-01f,9.406608e-02f,-1.467221e+00f,1.811868e+00f,3.208840e-01f,1.142662e+00f,-5.701226e+00f,7.040430e+00f}, + {-6.156614e-01f,7.880108e-01f,6.855855e-02f,-1.455444e+00f,1.862883e+00f,3.400929e-01f,1.058135e+00f,-5.734527e+00f,7.339859e+00f}, + {-6.018151e-01f,7.986354e-01f,4.327216e-02f,-1.441893e+00f,1.913455e+00f,3.578070e-01f,9.714287e-01f,-5.757732e+00f,7.640767e+00f}, + {-5.877852e-01f,8.090171e-01f,1.823708e-02f,-1.426585e+00f,1.963526e+00f,3.739910e-01f,8.827875e-01f,-5.770657e+00f,7.942629e+00f}, + {-5.735764e-01f,8.191520e-01f,-6.515074e-03f,-1.409539e+00f,2.013030e+00f,3.886124e-01f,7.924678e-01f,-5.773133e+00f,8.244888e+00f}, + {-5.591928e-01f,8.290376e-01f,-3.095508e-02f,-1.390776e+00f,2.061910e+00f,4.016449e-01f,7.007229e-01f,-5.765026e+00f,8.547005e+00f}, + {-5.446391e-01f,8.386706e-01f,-5.505246e-02f,-1.370318e+00f,2.110105e+00f,4.130656e-01f,6.078163e-01f,-5.746228e+00f,8.848414e+00f}, + {-5.299193e-01f,8.480480e-01f,-7.877823e-02f,-1.348191e+00f,2.157557e+00f,4.228564e-01f,5.140093e-01f,-5.716654e+00f,9.148557e+00f}, + {-5.150380e-01f,8.571674e-01f,-1.021038e-01f,-1.324421e+00f,2.204208e+00f,4.310043e-01f,4.195672e-01f,-5.676254e+00f,9.446875e+00f}, + {-5.000001e-01f,8.660253e-01f,-1.249999e-01f,-1.299038e+00f,2.250000e+00f,4.375000e-01f,3.247599e-01f,-5.625000e+00f,9.742785e+00f}, + {-4.848095e-01f,8.746197e-01f,-1.474395e-01f,-1.272072e+00f,2.294879e+00f,4.423398e-01f,2.298521e-01f,-5.562896e+00f,1.003573e+01f}, + {-4.694715e-01f,8.829476e-01f,-1.693947e-01f,-1.243556e+00f,2.338789e+00f,4.455244e-01f,1.351145e-01f,-5.489975e+00f,1.032514e+01f}, + {-4.539906e-01f,8.910065e-01f,-1.908388e-01f,-1.213526e+00f,2.381678e+00f,4.470587e-01f,4.081347e-02f,-5.406296e+00f,1.061045e+01f}, + {-4.383711e-01f,8.987940e-01f,-2.117461e-01f,-1.182016e+00f,2.423492e+00f,4.469530e-01f,-5.278682e-02f,-5.311945e+00f,1.089110e+01f}, + {-4.226183e-01f,9.063078e-01f,-2.320906e-01f,-1.149067e+00f,2.464181e+00f,4.452218e-01f,-1.454199e-01f,-5.207041e+00f,1.116653e+01f}, + {-4.067367e-01f,9.135454e-01f,-2.518479e-01f,-1.114717e+00f,2.503696e+00f,4.418841e-01f,-2.368270e-01f,-5.091725e+00f,1.143620e+01f}, + {-3.907311e-01f,9.205048e-01f,-2.709937e-01f,-1.079010e+00f,2.541987e+00f,4.369636e-01f,-3.267503e-01f,-4.966168e+00f,1.169956e+01f}, + {-3.746066e-01f,9.271839e-01f,-2.895049e-01f,-1.041988e+00f,2.579010e+00f,4.304885e-01f,-4.149371e-01f,-4.830570e+00f,1.195608e+01f}, + {-3.583679e-01f,9.335804e-01f,-3.073587e-01f,-1.003696e+00f,2.614717e+00f,4.224911e-01f,-5.011396e-01f,-4.685155e+00f,1.220525e+01f}, + {-3.420201e-01f,9.396927e-01f,-3.245333e-01f,-9.641814e-01f,2.649067e+00f,4.130083e-01f,-5.851153e-01f,-4.530170e+00f,1.244654e+01f}, + {-3.255681e-01f,9.455186e-01f,-3.410081e-01f,-9.234920e-01f,2.682016e+00f,4.020810e-01f,-6.666291e-01f,-4.365895e+00f,1.267948e+01f}, + {-3.090170e-01f,9.510564e-01f,-3.567626e-01f,-8.816779e-01f,2.713525e+00f,3.897543e-01f,-7.454509e-01f,-4.192628e+00f,1.290358e+01f}, + {-2.923717e-01f,9.563047e-01f,-3.717781e-01f,-8.387894e-01f,2.743556e+00f,3.760769e-01f,-8.213612e-01f,-4.010692e+00f,1.311838e+01f}, + {-2.756374e-01f,9.612617e-01f,-3.860361e-01f,-7.948790e-01f,2.772072e+00f,3.611015e-01f,-8.941467e-01f,-3.820433e+00f,1.332343e+01f}, + {-2.588190e-01f,9.659258e-01f,-3.995190e-01f,-7.499999e-01f,2.799038e+00f,3.448846e-01f,-9.636030e-01f,-3.622222e+00f,1.351832e+01f}, + {-2.419219e-01f,9.702957e-01f,-4.122107e-01f,-7.042072e-01f,2.824421e+00f,3.274858e-01f,-1.029536e+00f,-3.416446e+00f,1.370262e+01f}, + {-2.249510e-01f,9.743701e-01f,-4.240956e-01f,-6.575566e-01f,2.848191e+00f,3.089685e-01f,-1.091760e+00f,-3.203517e+00f,1.387596e+01f}, + {-2.079118e-01f,9.781476e-01f,-4.351591e-01f,-6.101051e-01f,2.870318e+00f,2.893990e-01f,-1.150101e+00f,-2.983865e+00f,1.403797e+01f}, + {-1.908090e-01f,9.816272e-01f,-4.453879e-01f,-5.619099e-01f,2.890776e+00f,2.688461e-01f,-1.204397e+00f,-2.757931e+00f,1.418832e+01f}, + {-1.736482e-01f,9.848077e-01f,-4.547695e-01f,-5.130303e-01f,2.909539e+00f,2.473820e-01f,-1.254495e+00f,-2.526181e+00f,1.432668e+01f}, + {-1.564344e-01f,9.876883e-01f,-4.632923e-01f,-4.635254e-01f,2.926584e+00f,2.250811e-01f,-1.300254e+00f,-2.289093e+00f,1.445277e+01f}, + {-1.391731e-01f,9.902681e-01f,-4.709463e-01f,-4.134560e-01f,2.941893e+00f,2.020205e-01f,-1.341547e+00f,-2.047161e+00f,1.456631e+01f}, + {-1.218693e-01f,9.925461e-01f,-4.777218e-01f,-3.628827e-01f,2.955444e+00f,1.782789e-01f,-1.378258e+00f,-1.800889e+00f,1.466707e+01f}, + {-1.045285e-01f,9.945219e-01f,-4.836107e-01f,-3.118677e-01f,2.967221e+00f,1.539375e-01f,-1.410285e+00f,-1.550796e+00f,1.475483e+01f}, + {-8.715577e-02f,9.961947e-01f,-4.886058e-01f,-2.604724e-01f,2.977212e+00f,1.290786e-01f,-1.437538e+00f,-1.297406e+00f,1.482941e+01f}, + {-6.975648e-02f,9.975641e-01f,-4.927011e-01f,-2.087597e-01f,2.985402e+00f,1.037861e-01f,-1.459940e+00f,-1.041256e+00f,1.489065e+01f}, + {-5.233594e-02f,9.986295e-01f,-4.958915e-01f,-1.567926e-01f,2.991783e+00f,7.814553e-02f,-1.477429e+00f,-7.828888e-01f,1.493841e+01f}, + {-3.489946e-02f,9.993909e-01f,-4.981730e-01f,-1.046346e-01f,2.996346e+00f,5.224292e-02f,-1.489957e+00f,-5.228543e-01f,1.497260e+01f}, + {-1.745235e-02f,9.998478e-01f,-4.995431e-01f,-5.234908e-02f,2.999086e+00f,2.616524e-02f,-1.497488e+00f,-2.617055e-01f,1.499315e+01f}, + {-4.371139e-08f,1.000000e+00f,-5.000000e-01f,-1.311342e-07f,3.000000e+00f,6.556709e-08f,-1.500000e+00f,-6.556709e-07f,1.500000e+01f} +}; + +const float dirac_gains_trg_term[181][2] = +{ + {-1.000000e+00f,8.742278e-08f}, + {-9.998477e-01f,-1.745246e-02f}, + {-9.993908e-01f,-3.489945e-02f}, + {-9.986295e-01f,-5.233605e-02f}, + {-9.975641e-01f,-6.975647e-02f}, + {-9.961947e-01f,-8.715564e-02f}, + {-9.945219e-01f,-1.045285e-01f}, + {-9.925461e-01f,-1.218693e-01f}, + {-9.902681e-01f,-1.391732e-01f}, + {-9.876884e-01f,-1.564344e-01f}, + {-9.848077e-01f,-1.736483e-01f}, + {-9.816272e-01f,-1.908090e-01f}, + {-9.781476e-01f,-2.079116e-01f}, + {-9.743701e-01f,-2.249511e-01f}, + {-9.702957e-01f,-2.419219e-01f}, + {-9.659258e-01f,-2.588191e-01f}, + {-9.612617e-01f,-2.756374e-01f}, + {-9.563048e-01f,-2.923716e-01f}, + {-9.510565e-01f,-3.090170e-01f}, + {-9.455186e-01f,-3.255681e-01f}, + {-9.396926e-01f,-3.420202e-01f}, + {-9.335805e-01f,-3.583679e-01f}, + {-9.271839e-01f,-3.746065e-01f}, + {-9.205049e-01f,-3.907312e-01f}, + {-9.135455e-01f,-4.067366e-01f}, + {-9.063078e-01f,-4.226183e-01f}, + {-8.987941e-01f,-4.383711e-01f}, + {-8.910065e-01f,-4.539906e-01f}, + {-8.829476e-01f,-4.694716e-01f}, + {-8.746198e-01f,-4.848095e-01f}, + {-8.660254e-01f,-5.000001e-01f}, + {-8.571673e-01f,-5.150380e-01f}, + {-8.480480e-01f,-5.299193e-01f}, + {-8.386706e-01f,-5.446390e-01f}, + {-8.290377e-01f,-5.591928e-01f}, + {-8.191521e-01f,-5.735765e-01f}, + {-8.090171e-01f,-5.877852e-01f}, + {-7.986355e-01f,-6.018151e-01f}, + {-7.880108e-01f,-6.156614e-01f}, + {-7.771459e-01f,-6.293205e-01f}, + {-7.660444e-01f,-6.427876e-01f}, + {-7.547097e-01f,-6.560590e-01f}, + {-7.431448e-01f,-6.691306e-01f}, + {-7.313537e-01f,-6.819983e-01f}, + {-7.193397e-01f,-6.946585e-01f}, + {-7.071068e-01f,-7.071068e-01f}, + {-6.946585e-01f,-7.193397e-01f}, + {-6.819983e-01f,-7.313537e-01f}, + {-6.691307e-01f,-7.431448e-01f}, + {-6.560590e-01f,-7.547097e-01f}, + {-6.427876e-01f,-7.660444e-01f}, + {-6.293203e-01f,-7.771460e-01f}, + {-6.156614e-01f,-7.880108e-01f}, + {-6.018151e-01f,-7.986355e-01f}, + {-5.877852e-01f,-8.090170e-01f}, + {-5.735765e-01f,-8.191520e-01f}, + {-5.591928e-01f,-8.290376e-01f}, + {-5.446391e-01f,-8.386706e-01f}, + {-5.299193e-01f,-8.480480e-01f}, + {-5.150380e-01f,-8.571673e-01f}, + {-5.000001e-01f,-8.660254e-01f}, + {-4.848095e-01f,-8.746197e-01f}, + {-4.694716e-01f,-8.829476e-01f}, + {-4.539906e-01f,-8.910065e-01f}, + {-4.383711e-01f,-8.987941e-01f}, + {-4.226183e-01f,-9.063078e-01f}, + {-4.067367e-01f,-9.135454e-01f}, + {-3.907312e-01f,-9.205049e-01f}, + {-3.746066e-01f,-9.271839e-01f}, + {-3.583679e-01f,-9.335805e-01f}, + {-3.420201e-01f,-9.396926e-01f}, + {-3.255681e-01f,-9.455186e-01f}, + {-3.090170e-01f,-9.510565e-01f}, + {-2.923717e-01f,-9.563047e-01f}, + {-2.756374e-01f,-9.612617e-01f}, + {-2.588190e-01f,-9.659258e-01f}, + {-2.419219e-01f,-9.702957e-01f}, + {-2.249510e-01f,-9.743701e-01f}, + {-2.079117e-01f,-9.781476e-01f}, + {-1.908090e-01f,-9.816272e-01f}, + {-1.736482e-01f,-9.848077e-01f}, + {-1.564344e-01f,-9.876884e-01f}, + {-1.391731e-01f,-9.902681e-01f}, + {-1.218693e-01f,-9.925461e-01f}, + {-1.045285e-01f,-9.945219e-01f}, + {-8.715577e-02f,-9.961947e-01f}, + {-6.975648e-02f,-9.975641e-01f}, + {-5.233594e-02f,-9.986295e-01f}, + {-3.489946e-02f,-9.993908e-01f}, + {-1.745235e-02f,-9.998477e-01f}, + {-4.371139e-08f,-1.000000e+00f}, + {1.745238e-02f,-9.998477e-01f}, + {3.489950e-02f,-9.993908e-01f}, + {5.233597e-02f,-9.986295e-01f}, + {6.975651e-02f,-9.975641e-01f}, + {8.715580e-02f,-9.961947e-01f}, + {1.045284e-01f,-9.945219e-01f}, + {1.218693e-01f,-9.925461e-01f}, + {1.391731e-01f,-9.902681e-01f}, + {1.564345e-01f,-9.876884e-01f}, + {1.736482e-01f,-9.848077e-01f}, + {1.908089e-01f,-9.816272e-01f}, + {2.079117e-01f,-9.781476e-01f}, + {2.249510e-01f,-9.743701e-01f}, + {2.419219e-01f,-9.702957e-01f}, + {2.588191e-01f,-9.659258e-01f}, + {2.756374e-01f,-9.612617e-01f}, + {2.923717e-01f,-9.563048e-01f}, + {3.090170e-01f,-9.510565e-01f}, + {3.255681e-01f,-9.455186e-01f}, + {3.420202e-01f,-9.396926e-01f}, + {3.583680e-01f,-9.335804e-01f}, + {3.746066e-01f,-9.271839e-01f}, + {3.907311e-01f,-9.205049e-01f}, + {4.067366e-01f,-9.135455e-01f}, + {4.226182e-01f,-9.063078e-01f}, + {4.383712e-01f,-8.987941e-01f}, + {4.539905e-01f,-8.910065e-01f}, + {4.694716e-01f,-8.829476e-01f}, + {4.848096e-01f,-8.746197e-01f}, + {5.000000e-01f,-8.660254e-01f}, + {5.150381e-01f,-8.571673e-01f}, + {5.299193e-01f,-8.480481e-01f}, + {5.446390e-01f,-8.386706e-01f}, + {5.591929e-01f,-8.290375e-01f}, + {5.735765e-01f,-8.191521e-01f}, + {5.877852e-01f,-8.090170e-01f}, + {6.018150e-01f,-7.986355e-01f}, + {6.156615e-01f,-7.880107e-01f}, + {6.293204e-01f,-7.771460e-01f}, + {6.427876e-01f,-7.660444e-01f}, + {6.560590e-01f,-7.547095e-01f}, + {6.691306e-01f,-7.431449e-01f}, + {6.819984e-01f,-7.313537e-01f}, + {6.946584e-01f,-7.193398e-01f}, + {7.071068e-01f,-7.071068e-01f}, + {7.193398e-01f,-6.946584e-01f}, + {7.313537e-01f,-6.819983e-01f}, + {7.431448e-01f,-6.691306e-01f}, + {7.547096e-01f,-6.560590e-01f}, + {7.660444e-01f,-6.427876e-01f}, + {7.771460e-01f,-6.293204e-01f}, + {7.880108e-01f,-6.156615e-01f}, + {7.986355e-01f,-6.018150e-01f}, + {8.090170e-01f,-5.877852e-01f}, + {8.191521e-01f,-5.735765e-01f}, + {8.290376e-01f,-5.591929e-01f}, + {8.386706e-01f,-5.446391e-01f}, + {8.480481e-01f,-5.299193e-01f}, + {8.571673e-01f,-5.150381e-01f}, + {8.660254e-01f,-5.000000e-01f}, + {8.746197e-01f,-4.848096e-01f}, + {8.829476e-01f,-4.694716e-01f}, + {8.910065e-01f,-4.539905e-01f}, + {8.987941e-01f,-4.383712e-01f}, + {9.063078e-01f,-4.226183e-01f}, + {9.135454e-01f,-4.067366e-01f}, + {9.205049e-01f,-3.907311e-01f}, + {9.271839e-01f,-3.746066e-01f}, + {9.335804e-01f,-3.583679e-01f}, + {9.396926e-01f,-3.420201e-01f}, + {9.455186e-01f,-3.255681e-01f}, + {9.510565e-01f,-3.090170e-01f}, + {9.563048e-01f,-2.923717e-01f}, + {9.612617e-01f,-2.756374e-01f}, + {9.659258e-01f,-2.588190e-01f}, + {9.702957e-01f,-2.419219e-01f}, + {9.743701e-01f,-2.249510e-01f}, + {9.781476e-01f,-2.079117e-01f}, + {9.816272e-01f,-1.908090e-01f}, + {9.848077e-01f,-1.736482e-01f}, + {9.876884e-01f,-1.564345e-01f}, + {9.902681e-01f,-1.391731e-01f}, + {9.925461e-01f,-1.218693e-01f}, + {9.945219e-01f,-1.045285e-01f}, + {9.961947e-01f,-8.715574e-02f}, + {9.975641e-01f,-6.975647e-02f}, + {9.986295e-01f,-5.233596e-02f}, + {9.993908e-01f,-3.489950e-02f}, + {9.998477e-01f,-1.745241e-02f}, + {1.000000e+00f,0.000000e+00f} +}; + +/*----------------------------------------------------------------------------------* + * FB ROM tables + *----------------------------------------------------------------------------------*/ + +const float ivas_fb_cf_4ms_48k[IVAS_FB_4MS_48K_SAMP] = +{ + 0.0000167330f, 0.0001505907f, 0.0004182700f, 0.0008196995f, 0.0013547717f, 0.0020233432f, 0.0028252351f, 0.0037602327f, + 0.0048280857f, 0.0060285082f, 0.0073611788f, 0.0088257407f, 0.0104218019f, 0.0121489350f, 0.0140066776f, 0.0159945324f, + 0.0181119671f, 0.0203584149f, 0.0227332744f, 0.0252359097f, 0.0278656508f, 0.0306217938f, 0.0335036006f, 0.0365102998f, + 0.0396410864f, 0.0428951221f, 0.0462715360f, 0.0497694239f, 0.0533878494f, 0.0571258438f, 0.0609824063f, 0.0649565044f, + 0.0690470742f, 0.0732530206f, 0.0775732174f, 0.0820065080f, 0.0865517057f, 0.0912075934f, 0.0959729248f, 0.1008464240f, + 0.1058267862f, 0.1109126781f, 0.1161027381f, 0.1213955767f, 0.1267897769f, 0.1322838945f, 0.1378764585f, 0.1435659718f, + 0.1493509111f, 0.1552297276f, 0.1612008475f, 0.1672626721f, 0.1734135785f, 0.1796519200f, 0.1859760265f, 0.1923842047f, + 0.1988747391f, 0.2054458921f, 0.2120959043f, 0.2188229954f, 0.2256253644f, 0.2325011901f, 0.2394486317f, 0.2464658292f, + 0.2535509039f, 0.2607019590f, 0.2679170800f, 0.2751943352f, 0.2825317763f, 0.2899274389f, 0.2973793430f, 0.3048854936f, + 0.3124438810f, 0.3200524817f, 0.3277092588f, 0.3354121622f, 0.3431591298f, 0.3509480875f, 0.3587769500f, 0.3666436213f, + 0.3745459953f, 0.3824819564f, 0.3904493799f, 0.3984461328f, 0.4064700741f, 0.4145190556f, 0.4225909225f, 0.4306835136f, + 0.4387946624f, 0.4469221974f, 0.4550639426f, 0.4632177182f, 0.4713813414f, 0.4795526264f, 0.4877293857f, 0.4959094302f, + 0.5040905698f, 0.5122706143f, 0.5204473736f, 0.5286186586f, 0.5367822818f, 0.5449360574f, 0.5530778026f, 0.5612053376f, + 0.5693164864f, 0.5774090775f, 0.5854809444f, 0.5935299259f, 0.6015538672f, 0.6095506201f, 0.6175180436f, 0.6254540047f, + 0.6333563787f, 0.6412230500f, 0.6490519125f, 0.6568408702f, 0.6645878378f, 0.6722907412f, 0.6799475183f, 0.6875561190f, + 0.6951145064f, 0.7026206570f, 0.7100725611f, 0.7174682237f, 0.7248056648f, 0.7320829200f, 0.7392980410f, 0.7464490961f, + 0.7535341708f, 0.7605513683f, 0.7674988099f, 0.7743746356f, 0.7811770046f, 0.7879040957f, 0.7945541079f, 0.8011252609f, + 0.8076157953f, 0.8140239735f, 0.8203480800f, 0.8265864215f, 0.8327373279f, 0.8387991525f, 0.8447702724f, 0.8506490889f, + 0.8564340282f, 0.8621235415f, 0.8677161055f, 0.8732102231f, 0.8786044233f, 0.8838972619f, 0.8890873219f, 0.8941732138f, + 0.8991535760f, 0.9040270752f, 0.9087924066f, 0.9134482943f, 0.9179934920f, 0.9224267826f, 0.9267469794f, 0.9309529258f, + 0.9350434956f, 0.9390175937f, 0.9428741562f, 0.9466121506f, 0.9502305761f, 0.9537284640f, 0.9571048779f, 0.9603589136f, + 0.9634897002f, 0.9664963994f, 0.9693782062f, 0.9721343492f, 0.9747640903f, 0.9772667256f, 0.9796415851f, 0.9818880329f, + 0.9840054676f, 0.9859933224f, 0.9878510650f, 0.9895781981f, 0.9911742593f, 0.9926388212f, 0.9939714918f, 0.9951719143f, + 0.9962397673f, 0.9971747649f, 0.9979766568f, 0.9986452283f, 0.9991803005f, 0.9995817300f, 0.9998494093f, 0.9999832670f, +}; + +const float ivas_fb_cf_4ms_32k[IVAS_FB_4MS_32K_SAMP] = +{ + 0.0000376491f, 0.0003388077f, 0.0009409435f, 0.0018436939f, 0.0030465150f, 0.0045486823f, 0.0063492909f, 0.0084472563f, + 0.0108413146f, 0.0135300239f, 0.0165117645f, 0.0197847403f, 0.0233469798f, 0.0271963373f, 0.0313304940f, 0.0357469598f, + 0.0404430742f, 0.0454160085f, 0.0506627672f, 0.0561801898f, 0.0619649529f, 0.0680135719f, 0.0743224034f, 0.0808876472f, + 0.0877053486f, 0.0947714009f, 0.1020815477f, 0.1096313857f, 0.1174163672f, 0.1254318027f, 0.1336728642f, 0.1421345874f, + 0.1508118753f, 0.1596995011f, 0.1687921112f, 0.1780842286f, 0.1875702559f, 0.1972444793f, 0.2071010713f, 0.2171340946f, + 0.2273375058f, 0.2377051587f, 0.2482308081f, 0.2589081140f, 0.2697306445f, 0.2806918807f, 0.2917852200f, 0.3030039800f, + 0.3143414030f, 0.3257906599f, 0.3373448539f, 0.3489970253f, 0.3607401553f, 0.3725671702f, 0.3844709459f, 0.3964443119f, + 0.4084800560f, 0.4205709283f, 0.4327096457f, 0.4448888964f, 0.4571013438f, 0.4693396318f, 0.4815963885f, 0.4938642309f, + 0.5061357691f, 0.5184036115f, 0.5306603682f, 0.5428986562f, 0.5551111036f, 0.5672903543f, 0.5794290717f, 0.5915199440f, + 0.6035556881f, 0.6155290541f, 0.6274328298f, 0.6392598447f, 0.6510029747f, 0.6626551461f, 0.6742093401f, 0.6856585970f, + 0.6969960200f, 0.7082147800f, 0.7193081193f, 0.7302693555f, 0.7410918860f, 0.7517691919f, 0.7622948413f, 0.7726624942f, + 0.7828659054f, 0.7928989287f, 0.8027555207f, 0.8124297441f, 0.8219157714f, 0.8312078888f, 0.8403004989f, 0.8491881247f, + 0.8578654126f, 0.8663271358f, 0.8745681973f, 0.8825836328f, 0.8903686143f, 0.8979184523f, 0.9052285991f, 0.9122946514f, + 0.9191123528f, 0.9256775966f, 0.9319864281f, 0.9380350471f, 0.9438198102f, 0.9493372328f, 0.9545839915f, 0.9595569258f, + 0.9642530402f, 0.9686695060f, 0.9728036627f, 0.9766530202f, 0.9802152597f, 0.9834882355f, 0.9864699761f, 0.9891586854f, + 0.9915527437f, 0.9936507091f, 0.9954513177f, 0.9969534850f, 0.9981563061f, 0.9990590565f, 0.9996611923f, 0.9999623509f, +}; + +const float ivas_fb_cf_4ms_16k[IVAS_FB_4MS_16K_SAMP] = +{ + 0.0001505907f, 0.0013547717f, 0.0037602327f, 0.0073611788f, 0.0121489350f, 0.0181119671f, 0.0252359097f, 0.0335036006f, + 0.0428951221f, 0.0533878494f, 0.0649565044f, 0.0775732174f, 0.0912075934f, 0.1058267862f, 0.1213955767f, 0.1378764585f, + 0.1552297276f, 0.1734135785f, 0.1923842047f, 0.2120959043f, 0.2325011901f, 0.2535509039f, 0.2751943352f, 0.2973793430f, + 0.3200524817f, 0.3431591298f, 0.3666436213f, 0.3904493799f, 0.4145190556f, 0.4387946624f, 0.4632177182f, 0.4877293857f, + 0.5122706143f, 0.5367822818f, 0.5612053376f, 0.5854809444f, 0.6095506201f, 0.6333563787f, 0.6568408702f, 0.6799475183f, + 0.7026206570f, 0.7248056648f, 0.7464490961f, 0.7674988099f, 0.7879040957f, 0.8076157953f, 0.8265864215f, 0.8447702724f, + 0.8621235415f, 0.8786044233f, 0.8941732138f, 0.9087924066f, 0.9224267826f, 0.9350434956f, 0.9466121506f, 0.9571048779f, + 0.9664963994f, 0.9747640903f, 0.9818880329f, 0.9878510650f, 0.9926388212f, 0.9962397673f, 0.9986452283f, 0.9998494093f, +}; + +const float ivas_fb_fcs_12band_1ms[IVAS_FB_BANDS_12] = +{ + 0.0083333333f, 0.0250000000f, 0.0416666667f, 0.0583333333f, + 0.0750000000f, 0.0916666667f, 0.1083333333f, 0.1416666667f, + 0.2166666667f, 0.3333333333f, 0.5083333333f, 0.8083333333f +}; + +const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +{ + { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 291, 367 }, + { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 260, 47 }, + { 24, 30, 30, 30, 30, 30, 42, 75, 122, 73, 0, 0 } +}; + +const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +{ + {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 }, + {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 }, + {0, 9, 25, 41, 57, 73, 88, 110, 159, 247, 0, 0 } +}; + +const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +{ + { + IVAS_FB_12_1MS_48K_END_BINS_BAND_0 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0, + IVAS_FB_12_1MS_48K_END_BINS_BAND_1 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1, + IVAS_FB_12_1MS_48K_END_BINS_BAND_2 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2, + IVAS_FB_12_1MS_48K_END_BINS_BAND_3 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3, + IVAS_FB_12_1MS_48K_END_BINS_BAND_4 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4, + IVAS_FB_12_1MS_48K_END_BINS_BAND_5 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5, + IVAS_FB_12_1MS_48K_END_BINS_BAND_6 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6, + IVAS_FB_12_1MS_48K_END_BINS_BAND_7 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7, + IVAS_FB_12_1MS_48K_END_BINS_BAND_8 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8, + IVAS_FB_12_1MS_48K_END_BINS_BAND_9 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9, + IVAS_FB_12_1MS_48K_END_BINS_BAND_10 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10, + IVAS_FB_12_1MS_48K_END_BINS_BAND_11 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11 + }, + { + IVAS_FB_12_1MS_32K_END_BINS_BAND_0 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_0, + IVAS_FB_12_1MS_32K_END_BINS_BAND_1 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_1, + IVAS_FB_12_1MS_32K_END_BINS_BAND_2 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_2, + IVAS_FB_12_1MS_32K_END_BINS_BAND_3 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_3, + IVAS_FB_12_1MS_32K_END_BINS_BAND_4 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_4, + IVAS_FB_12_1MS_32K_END_BINS_BAND_5 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_5, + IVAS_FB_12_1MS_32K_END_BINS_BAND_6 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_6, + IVAS_FB_12_1MS_32K_END_BINS_BAND_7 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_7, + IVAS_FB_12_1MS_32K_END_BINS_BAND_8 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_8, + IVAS_FB_12_1MS_32K_END_BINS_BAND_9 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_9, + IVAS_FB_12_1MS_32K_END_BINS_BAND_10 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_10, + IVAS_FB_12_1MS_32K_END_BINS_BAND_11 - IVAS_FB_12_1MS_32K_START_OFFSET_BAND_11 + }, + { + IVAS_FB_12_1MS_16K_END_BINS_BAND_0 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_0, + IVAS_FB_12_1MS_16K_END_BINS_BAND_1 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_1, + IVAS_FB_12_1MS_16K_END_BINS_BAND_2 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_2, + IVAS_FB_12_1MS_16K_END_BINS_BAND_3 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_3, + IVAS_FB_12_1MS_16K_END_BINS_BAND_4 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_4, + IVAS_FB_12_1MS_16K_END_BINS_BAND_5 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_5, + IVAS_FB_12_1MS_16K_END_BINS_BAND_6 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_6, + IVAS_FB_12_1MS_16K_END_BINS_BAND_7 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_7, + IVAS_FB_12_1MS_16K_END_BINS_BAND_8 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_8, + IVAS_FB_12_1MS_16K_END_BINS_BAND_9 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_9, + IVAS_FB_12_1MS_16K_END_BINS_BAND_10 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_10, + IVAS_FB_12_1MS_16K_END_BINS_BAND_11 - IVAS_FB_12_1MS_16K_START_OFFSET_BAND_11 + }, +}; + +const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +{ + { + IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1, + IVAS_FB_12_1MS_48K_START_OFFSET_BAND_2, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_3, + IVAS_FB_12_1MS_48K_START_OFFSET_BAND_4, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_5, + IVAS_FB_12_1MS_48K_START_OFFSET_BAND_6, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_7, + IVAS_FB_12_1MS_48K_START_OFFSET_BAND_8, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_9, + IVAS_FB_12_1MS_48K_START_OFFSET_BAND_10, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_11 + }, + { + IVAS_FB_12_1MS_32K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_1, + IVAS_FB_12_1MS_32K_START_OFFSET_BAND_2, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_3, + IVAS_FB_12_1MS_32K_START_OFFSET_BAND_4, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_5, + IVAS_FB_12_1MS_32K_START_OFFSET_BAND_6, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_7, + IVAS_FB_12_1MS_32K_START_OFFSET_BAND_8, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_9, + IVAS_FB_12_1MS_32K_START_OFFSET_BAND_10, IVAS_FB_12_1MS_32K_START_OFFSET_BAND_11 + }, + { + IVAS_FB_12_1MS_16K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_1, + IVAS_FB_12_1MS_16K_START_OFFSET_BAND_2, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_3, + IVAS_FB_12_1MS_16K_START_OFFSET_BAND_4, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_5, + IVAS_FB_12_1MS_16K_START_OFFSET_BAND_6, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_7, + IVAS_FB_12_1MS_16K_START_OFFSET_BAND_8, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_9, + IVAS_FB_12_1MS_16K_START_OFFSET_BAND_10, IVAS_FB_12_1MS_16K_START_OFFSET_BAND_11 + }, +}; + +const float ivas_fb_cf_1ms_48k[IVAS_FB_1MS_48K_SAMP] = +{ + 0.0002677063f, 0.0024076367f, 0.0066783340f, 0.0130615104f, 0.0215298321f, 0.0320470366f, 0.0445680875f, 0.0590393678f, + 0.0753989092f, 0.0935766577f, 0.1134947733f, 0.1350679637f, 0.1582038490f, 0.1828033579f, 0.2087611516f, 0.2359660747f, + 0.2643016316f, 0.2936464851f, 0.3238749760f, 0.3548576614f, 0.3864618685f, 0.4185522633f, 0.4509914298f, 0.4836404586f, + 0.5163595414f, 0.5490085702f, 0.5814477367f, 0.6135381315f, 0.6451423386f, 0.6761250240f, 0.7063535149f, 0.7356983684f, + 0.7640339253f, 0.7912388484f, 0.8171966421f, 0.8417961510f, 0.8649320363f, 0.8865052267f, 0.9064233423f, 0.9246010908f, + 0.9409606322f, 0.9554319125f, 0.9679529634f, 0.9784701679f, 0.9869384896f, 0.9933216660f, 0.9975923633f, 0.9997322937f, +}; + +const float ivas_fb_cf_1ms_32k[IVAS_FB_1MS_32K_SAMP] = +{ + 0.0006022719f, 0.0054117450f, 0.0149843734f, 0.0292279674f, 0.0480053534f, 0.0711356950f, 0.0983962343f, 0.1295244373f, + 0.1642205226f, 0.2021503478f, 0.2429486279f, 0.2862224533f, 0.3315550733f, 0.3785099100f, 0.4266347628f, 0.4754661628f, + 0.5245338372f, 0.5733652372f, 0.6214900900f, 0.6684449267f, 0.7137775467f, 0.7570513721f, 0.7978496522f, 0.8357794774f, + 0.8704755627f, 0.9016037657f, 0.9288643050f, 0.9519946466f, 0.9707720326f, 0.9850156266f, 0.9945882550f, 0.9993977281f, +}; + +const float ivas_fb_cf_1ms_16k[IVAS_FB_1MS_16K_SAMP] = +{ + 0.0024076367f, 0.0215298321f, 0.0590393678f, 0.1134947733f, 0.1828033579f, 0.2643016316f, 0.3548576614f, 0.4509914298f, + 0.5490085702f, 0.6451423386f, 0.7356983684f, 0.8171966421f, 0.8865052267f, 0.9409606322f, 0.9784701679f, 0.9975923633f, + }; + + +const float ivas_fb_fr_12band_1ms_re[IVAS_FB_12_1MS_LEN] = +{ + 0.9748788957f, 0.9427895242f, 0.8792742509f, 0.7856320394f, 0.6637543553f, 0.5159842697f, 0.3449612971f, 0.1523029468f, + -0.0629462677f, -0.2915070279f, -0.5097704228f, -0.6945723663f, -0.8280677163f, -0.8984664279f, -0.9013544787f, -0.8399030468f, + -0.7243177987f, -0.5703726081f, -0.3972779762f, -0.2251611328f, -0.0723653847f, 0.0469440290f, 0.1248973653f, 0.1617697860f, + 0.1709641074f, 0.1694810686f, 0.1629475939f, 0.1522105989f, 0.1386564071f, 0.1233728939f, 0.1073854103f, 0.0914740522f, + 0.0762871837f, 0.0622709857f, 0.0497418146f, 0.0388592902f, 0.0296823509f, 0.0221628349f, 0.0161914497f, 0.0115997684f, + 0.0081967931f, 0.0057721783f, 0.0041230995f, 0.0030548577f, 0.0023984605f, 0.0020073250f, 0.0017670262f, 0.0015886054f, + 0.0014126895f, 0.0012008765f, 0.0009366259f, 0.0006164015f, 0.0002494051f, -0.0001501884f, -0.0005632461f, -0.0009716328f, + -0.0013573205f, -0.0017064484f, -0.0020074979f, -0.0022538257f, -0.0024412527f, -0.0025696364f, -0.0026403325f, -0.0026573398f, + -0.0026249989f, -0.0025490667f, -0.0024348276f, -0.0022882409f, -0.0021144573f, -0.0019190182f, -0.0017066606f, -0.0014824738f, + -0.0012508539f, -0.0010165332f, -0.0007835930f, -0.0005563371f, -0.0003383404f, -0.0001331992f, 0.0000563549f, 0.0002277657f, + 0.0003794289f, 0.0005100093f, 0.0006190856f, 0.0007064556f, 0.0007726658f, 0.0008183240f, 0.0008445608f, 0.0008523932f, + 0.0008431696f, 0.0008180214f, 0.0007783263f, 0.0007252567f, 0.0006602600f, 0.0005846794f, 0.0005002207f, 0.0004085983f, + 0.0003119450f, 0.0002124378f, 0.0001126202f, 0.0000149855f, -0.0000777886f, -0.0001632865f, -0.0002391747f, -0.0003036357f, + -0.0003551891f, -0.0003930613f, -0.0004169567f, -0.0004273258f, -0.0004250606f, -0.0004116574f, -0.0003888481f, -0.0003586881f, + -0.0003231696f, -0.0002842913f, -0.0002437103f, -0.0002028533f, -0.0001626543f, -0.0001237419f, -0.0000862804f, -0.0000502315f, + -0.0000152759f, 0.0000188864f, 0.0000525857f, 0.0000859011f, 0.0001187387f, 0.0001506215f, 0.0001808384f, 0.0002083291f, + 0.0002319112f, 0.0002502468f, 0.0002621167f, 0.0002664223f, 0.0002624512f, 0.0002498541f, 0.0002288448f, 0.0002001024f, + 0.0001648717f, 0.0001247734f, 0.0000818072f, 0.0000380927f, -0.0000041840f, -0.0000430463f, -0.0000767750f, -0.0001041381f, + -0.0001243744f, -0.0001373295f, -0.0001433435f, -0.0001432806f, -0.0001383279f, -0.0001299462f, -0.0001196234f, -0.0001088038f, + -0.0000986591f, -0.0000900582f, -0.0000834123f, -0.0000787307f, -0.0000755665f, -0.0000731664f, -0.0000705050f, -0.0000664967f, + -0.0000600718f, -0.0000503921f, -0.0000369061f, -0.0000195076f, 0.0000014839f, 0.0000252601f, 0.0000506406f, 0.0000761070f, + 0.0000999980f, 0.0001206038f, 0.0001363885f, 0.0001460830f, 0.0001488707f, 0.0001444187f, 0.0001329747f, 0.0001153008f, + 0.0000926636f, 0.0000666729f, 0.0000391891f, + 0.0080195493f, 0.0152804795f, 0.0297236427f, 0.0512076944f, 0.0795504278f, 0.1146345202f, 0.1565217749f, 0.2067150266f, + 0.2696514371f, 0.3398196482f, 0.3975948769f, 0.4239235527f, 0.4051207537f, 0.3335063336f, 0.2086503840f, 0.0374772593f, + -0.1663484542f, -0.3839925014f, -0.5936160820f, -0.7729897529f, -0.9021602868f, -0.9658914408f, -0.9555491003f, -0.8702102709f, + -0.7168585697f, -0.5096278055f, -0.2682088520f, -0.0155786468f, 0.2246238492f, 0.4308147261f, 0.5858672047f, 0.6790005846f, + 0.7068091556f, 0.6734550535f, 0.5898178925f, 0.4719496963f, 0.3387034057f, 0.2092646386f, 0.1002222301f, 0.0233145798f, + -0.0225492413f, -0.0508402802f, -0.0698819559f, -0.0814769049f, -0.0871540019f, -0.0880955245f, -0.0854373943f, -0.0801296337f, + -0.0730507304f, -0.0649236398f, -0.0563762037f, -0.0478921962f, -0.0398550173f, -0.0325224860f, -0.0260651486f, -0.0205564484f, + -0.0160078488f, -0.0123673601f, -0.0095503829f, -0.0074410094f, -0.0059169243f, -0.0048497092f, -0.0041229035f, -0.0036294834f, + -0.0032833863f, -0.0030140242f, -0.0027726134f, -0.0025247022f, -0.0022531837f, -0.0019502609f, -0.0016189799f, -0.0012659033f, + -0.0009025224f, -0.0005393948f, -0.0001881199f, 0.0001429077f, 0.0004458867f, 0.0007165584f, 0.0009512703f, 0.0011491538f, + 0.0013092799f, 0.0014325460f, 0.0015192234f, 0.0015708276f, 0.0015881374f, 0.0015730908f, 0.0015271608f, 0.0014531585f, + 0.0013537657f, 0.0012330943f, 0.0010952099f, 0.0009453732f, 0.0007885040f, 0.0006301505f, 0.0004749667f, 0.0003275524f, + 0.0001910823f, 0.0000681798f, -0.0000401798f, -0.0001336577f, -0.0002133415f, -0.0002805985f, -0.0003376335f, -0.0003863124f, + -0.0004286391f, -0.0004657017f, -0.0004982282f, -0.0005257791f, -0.0005474775f, -0.0005614835f, -0.0005658893f, -0.0005584023f, + -0.0005372971f, -0.0005011582f, -0.0004497305f, -0.0003835612f, -0.0003046159f, -0.0002157155f, -0.0001208702f, -0.0000245120f, + 0.0000683937f, 0.0001532153f, 0.0002256208f, 0.0002823819f, 0.0003212462f, 0.0003415271f, 0.0003437577f, 0.0003299911f, + 0.0003032103f, 0.0002673723f, 0.0002266573f, 0.0001853871f, 0.0001472716f, 0.0001153747f, 0.0000915248f, 0.0000764751f, + 0.0000695838f, 0.0000692286f, 0.0000727574f, 0.0000771057f, 0.0000789150f, 0.0000752114f, 0.0000635256f, 0.0000424610f, + 0.0000116537f, -0.0000279010f, -0.0000741391f, -0.0001238800f, -0.0001733508f, -0.0002183440f, -0.0002548569f, -0.0002793014f, + -0.0002890885f, -0.0002827170f, -0.0002601490f, -0.0002226568f, -0.0001729141f, -0.0001145795f, -0.0000521398f, 0.0000096825f, + 0.0114335951f, 0.0118220569f, 0.0126166715f, 0.0138498428f, 0.0155597951f, 0.0177826837f, 0.0205365788f, 0.0238116184f, + 0.0275499857f, 0.0316384404f, 0.0358879435f, 0.0400334899f, 0.0437164087f, 0.0464960697f, 0.0478357348f, 0.0471294159f, + 0.0436878423f, 0.0367814109f, 0.0256142984f, 0.0093791332f, -0.0128147904f, -0.0419091622f, -0.0791441084f, -0.1267865122f, + -0.1929101618f, -0.2825839913f, -0.3844663503f, -0.4796058889f, -0.5493419153f, -0.5770955026f, -0.5509547813f, -0.4652700670f, + -0.3217444363f, -0.1294222853f, 0.0961203110f, 0.3345074656f, 0.5628461809f, 0.7584007007f, 0.9012417605f, 0.9766103137f, + 0.9766601036f, 0.9013929608f, 0.7586588937f, 0.5632193167f, 0.3350048195f, 0.0967502546f, -0.1286537645f, -0.3208359645f, + -0.4642258941f, -0.5497861643f, -0.5758205512f, -0.5479856830f, -0.4781988983f, -0.3830435617f, -0.2811824725f, -0.1915676007f, + -0.1255389320f, -0.0780249233f, -0.0409475096f, -0.0120357725f, 0.0099548733f, 0.0259692697f, 0.0369008806f, 0.0435579897f, + 0.0467369910f, 0.0471666204f, 0.0455359048f, 0.0424502401f, 0.0384477095f, 0.0339708748f, 0.0293829220f, 0.0249536436f, + 0.0208784147f, 0.0172747220f, 0.0142030489f, 0.0116695065f, 0.0096461650f, 0.0080756116f, 0.0068882718f, 0.0060058072f, + 0.0053538953f, 0.0048628684f, 0.0044756795f, 0.0041456204f, 0.0038402965f, 0.0035372856f, 0.0032255714f, 0.0029004385f, + 0.0025638810f, 0.0022199121f, 0.0018750824f, 0.0015349035f, 0.0012050131f, 0.0008888342f, 0.0005893582f, 0.0003077151f, + 0.0000451990f, -0.0001977660f, -0.0004197988f, -0.0006196394f, -0.0007948001f, -0.0009428845f, -0.0010607326f, -0.0011459111f, + -0.0011961438f, -0.0012107318f, -0.0011899721f, -0.0011362537f, -0.0010532349f, -0.0009464869f, -0.0008223739f, -0.0006883049f, + -0.0005514485f, -0.0004188116f, -0.0002960338f, -0.0001875645f, -0.0000957748f, -0.0000214335f, 0.0000367443f, 0.0000812780f, + 0.0001159924f, 0.0001449821f, 0.0001725036f, 0.0002019612f, 0.0002358809f, 0.0002751586f, 0.0003193210f, 0.0003661738f, + 0.0004124154f, 0.0004536598f, 0.0004853030f, 0.0005027457f, 0.0005022926f, 0.0004813241f, 0.0004389844f, 0.0003760837f, + 0.0002954100f, 0.0002012644f, 0.0000993832f, -0.0000038301f, -0.0001016317f, -0.0001878100f, -0.0002570235f, -0.0003055296f, + -0.0003312954f, -0.0003343869f, -0.0003167133f, -0.0002820121f, -0.0002352424f, -0.0001822598f, -0.0001290196f, -0.0000811569f, + -0.0000432400f, -0.0000185020f, -0.0000083679f, -0.0000125164f, -0.0000287954f, -0.0000536548f, -0.0000824102f, -0.0001099335f, + -0.0001310885f, -0.0001414598f, -0.0001377171f, -0.0001181463f, -0.0000827338f, -0.0000333400f, 0.0000265889f, 0.0000922209f, + 0.0001579388f, 0.0002177817f, 0.0002661695f, 0.0002983587f, 0.0003110497f, 0.0003026261f, 0.0002734474f, 0.0002257288f, + 0.0001634460f, 0.0000918569f, 0.0000170963f, -0.0000545144f, -0.0001169830f, -0.0001653182f, -0.0001959140f, -0.0002069779f, + -0.0001985967f, -0.0001727902f, -0.0001331990f, -0.0000847800f, -0.0000332059f, 0.0000156408f, 0.0000563515f, 0.0000844666f, + 0.0000970039f, 0.0000926836f, 0.0000721249f, 0.0000377027f, -0.0000066339f, -0.0000558449f, -0.0001042571f, -0.0001462224f, + -0.0001766430f, -0.0001915709f, -0.0001885647f, -0.0001670193f, -0.0001281871f, -0.0000751314f, -0.0000123776f, 0.0000544678f, + 0.0001193245f, 0.0001761818f, 0.0002197499f, 0.0002459308f, 0.0002522801f, 0.0002382003f, 0.0002050537f, + 0.0023329977f, 0.0022744367f, 0.0021570870f, 0.0019806181f, 0.0017457340f, 0.0014542507f, 0.0011108455f, 0.0007223346f, + 0.0002992379f, -0.0001466015f, -0.0006012791f, -0.0010533907f, -0.0014941798f, -0.0019241070f, -0.0023530883f, -0.0028080809f, + -0.0033317792f, -0.0039896152f, -0.0048647785f, -0.0060629391f, -0.0077015456f, -0.0099112032f, -0.0128179487f, -0.0165415563f, + -0.0211707180f, -0.0267603854f, -0.0333010728f, -0.0407193019f, -0.0488429494f, -0.0574105466f, -0.0660338484f, -0.0742229694f, + -0.0813438415f, -0.0866673269f, -0.0893099408f, -0.0883179181f, -0.0825536818f, -0.0708351065f, -0.0516356322f, -0.0231563648f, + 0.0229208886f, 0.1000615986f, 0.2093510203f, 0.3390457527f, 0.4725528568f, 0.5906840617f, 0.6745849094f, 0.7082031015f, + 0.6806592553f, 0.5877917414f, 0.4330061655f, 0.2270823403f, -0.0128552066f, -0.2652258122f, -0.5063946175f, -0.7133884257f, + -0.8665187769f, -0.9516510020f, -0.9617959599f, -0.8978644321f, -0.7684707435f, -0.5888227503f, -0.3788375243f, -0.1607017417f, + 0.0437915599f, 0.2158527937f, 0.3418541386f, 0.4148932359f, 0.4353978994f, 0.4110138144f, 0.3553491439f, 0.2873311989f, + 0.2264012967f, 0.1778272597f, 0.1368656384f, 0.1016489237f, 0.0716971046f, 0.0466686361f, 0.0262587636f, 0.0101140856f, + -0.0021717142f, -0.0110521236f, -0.0170125125f, -0.0205483075f, -0.0221473891f, -0.0222696986f, -0.0213345382f, -0.0197075856f, + -0.0176958703f, -0.0155434695f, -0.0134339314f, -0.0114932096f, -0.0097973566f, -0.0083798220f, -0.0072413978f, -0.0063587120f, + -0.0056935805f, -0.0052001373f, -0.0048316507f, -0.0045448649f, -0.0043035469f, -0.0040798367f, -0.0038548953f, -0.0036180007f, + -0.0033653668f, -0.0030981742f, -0.0028208099f, -0.0025389671f, -0.0022582881f, -0.0019832510f, -0.0017166811f, -0.0014595950f, + -0.0012115153f, -0.0009709890f, -0.0007362895f, -0.0005061076f, -0.0002801409f, -0.0000595032f, 0.0001531427f, 0.0003536750f, + 0.0005368997f, 0.0006970650f, 0.0008285636f, 0.0009265836f, 0.0009877836f, 0.0010107351f, 0.0009962610f, 0.0009474346f, + 0.0008694403f, 0.0007691024f, 0.0006543506f, 0.0005334591f, 0.0004143726f, 0.0003039581f, 0.0002074999f, 0.0001282497f, + 0.0000673202f, 0.0000236838f, -0.0000054823f, -0.0000243922f, -0.0000379908f, -0.0000513567f, -0.0000689891f, -0.0000943029f, + -0.0001291385f, -0.0001735855f, -0.0002258909f, -0.0002827035f, -0.0003393834f, -0.0003905818f, -0.0004307882f, -0.0004550220f, + -0.0004593576f, -0.0004414605f, -0.0004008453f, -0.0003390565f, -0.0002595254f, -0.0001673445f, -0.0000687564f, 0.0000293658f, + 0.0001202144f, 0.0001976297f, 0.0002567251f, 0.0002942795f, 0.0003090663f, 0.0003018805f, 0.0002754671f, 0.0002341572f, + 0.0001834501f, 0.0001293884f, 0.0000779842f, 0.0000345648f, 0.0000032926f, -0.0000132797f, -0.0000143893f, -0.0000011447f, + 0.0000236778f, 0.0000559218f, 0.0000905679f, 0.0001222509f, 0.0001458957f, 0.0001572350f, 0.0001533249f, 0.0001328377f, + 0.0000962676f, 0.0000458655f, -0.0000145297f, -0.0000799026f, -0.0001445204f, -0.0002025425f, -0.0002485698f, -0.0002782267f, + -0.0002885684f, -0.0002784187f, -0.0002484615f, -0.0002012166f, -0.0001407652f, -0.0000723891f, -0.0000020250f, 0.0000642779f, + 0.0006545440f, 0.0006092123f, 0.0005211283f, 0.0003952715f, 0.0002383557f, 0.0000584198f, -0.0001362653f, -0.0003375075f, + -0.0005383555f, -0.0007329456f, -0.0009174331f, -0.0010891536f, -0.0012472468f, -0.0013911728f, -0.0015212364f, -0.0016367530f, + -0.0017368889f, -0.0018188830f, -0.0018796284f, -0.0019142370f, -0.0019185646f, -0.0018880671f, -0.0018210801f, -0.0017174793f, + -0.0015821304f, -0.0014225231f, -0.0012516143f, -0.0010835462f, -0.0009352781f, -0.0008198418f, -0.0007467438f, -0.0007129147f, + -0.0007027599f, -0.0006778296f, -0.0005783377f, -0.0003132968f, 0.0002340159f, 0.0012135056f, 0.0027962862f, 0.0051783222f, + 0.0085600080f, 0.0131460500f, 0.0191158420f, 0.0266218006f, 0.0357510579f, 0.0465271020f, 0.0588638446f, 0.0725784015f, + 0.0873370030f, 0.1026908595f, 0.1180068601f, 0.1325484280f, 0.1453642259f, 0.1554807068f, 0.1616648578f, 0.1632688310f, + 0.1549027767f, 0.1198428714f, 0.0449861804f, -0.0696229208f, -0.2158023005f, -0.3790883171f, -0.5408894679f, -0.6808851285f, + -0.7797705919f, -0.8217682544f, -0.7968116423f, -0.7019652931f, -0.5420418321f, -0.3292210214f, -0.0818128466f, 0.1777726196f, + 0.4255266516f, 0.6385776439f, 0.7977664747f, 0.8898038418f, 0.9086949642f, 0.8563086554f, 0.7419773576f, 0.5812252250f, + 0.3937408613f, 0.2008871303f, 0.0230173731f, -0.1230428784f, -0.2260664125f, -0.2818374636f, -0.2937072611f, -0.2733437698f, + -0.2408584071f, -0.2098412063f, -0.1806909043f, -0.1526536550f, -0.1261957677f, -0.1017094943f, -0.0795968657f, -0.0600974864f, + -0.0433545981f, -0.0293681726f, -0.0180470916f, -0.0092000126f, -0.0025796754f, 0.0021127195f, 0.0051910943f, 0.0069776293f, + 0.0077756050f, 0.0078657031f, 0.0074886765f, 0.0068470105f, 0.0060965069f, 0.0053530166f, 0.0046907222f, 0.0041521192f, + 0.0037501212f, 0.0034789031f, 0.0033170573f, 0.0032371863f, 0.0032080612f, 0.0032016671f, 0.0031933530f, 0.0031660244f, + 0.0031082781f, 0.0030162723f, 0.0028905427f, 0.0027365419f, 0.0025611068f, 0.0023726939f, 0.0021783369f, 0.0019843040f, + 0.0017939931f, 0.0016092783f, 0.0014293389f, 0.0012525382f, 0.0010758415f, 0.0008968234f, 0.0007132020f, 0.0005245511f, + 0.0003315658f, 0.0001372209f, -0.0000543880f, -0.0002374465f, -0.0004059085f, -0.0005532434f, -0.0006739838f, -0.0007634986f, + -0.0008192976f, -0.0008405529f, -0.0008289575f, -0.0007878678f, -0.0007226939f, -0.0006397231f, -0.0005461962f, -0.0004490215f, + -0.0003547907f, -0.0002686412f, -0.0001944601f, -0.0001340918f, -0.0000878707f, -0.0000542351f, -0.0000305758f, -0.0000131627f, + 0.0000018427f, 0.0000183480f, 0.0000393727f, 0.0000671196f, 0.0001022671f, 0.0001443061f, 0.0001911748f, 0.0002398911f, + 0.0002864880f, 0.0003268414f, 0.0003567538f, 0.0003727940f, 0.0003723297f, 0.0003541905f, 0.0003184856f, 0.0002669707f, + 0.0002025844f, 0.0001295158f, 0.0000525132f, -0.0000232393f, -0.0000928921f, -0.0001520697f, -0.0001975396f, -0.0002271978f, + -0.0002404958f, -0.0002381708f, + -0.0001556937f, -0.0002232588f, -0.0003000471f, -0.0003807341f, -0.0004589754f, -0.0005276096f, -0.0005796476f, -0.0006085059f, + -0.0006090117f, -0.0005773878f, -0.0005120302f, -0.0004130497f, -0.0002827174f, -0.0001245430f, 0.0000565230f, 0.0002553084f, + 0.0004662156f, 0.0006844691f, 0.0009056254f, 0.0011266188f, 0.0013448100f, 0.0015587720f, 0.0017669159f, 0.0019681955f, + 0.0021605643f, 0.0023419522f, 0.0025089038f, 0.0026581873f, 0.0027858518f, 0.0028896115f, 0.0029682393f, 0.0030244845f, + 0.0030642863f, 0.0030995791f, 0.0031464520f, 0.0032269718f, 0.0033653351f, 0.0035879808f, 0.0039171130f, 0.0043689626f, + 0.0049448001f, 0.0056281538f, 0.0063744051f, 0.0071088295f, 0.0077167468f, 0.0080450691f, 0.0078953687f, 0.0070318498f, + 0.0051792603f, 0.0020396552f, -0.0027043718f, -0.0093630158f, -0.0182327050f, -0.0295599145f, -0.0435368078f, -0.0602568291f, + -0.0797235538f, -0.1017981297f, -0.1262457047f, -0.1526688648f, -0.1806793505f, -0.2098138162f, -0.2408276962f, -0.2733223455f, + -0.2937063941f, -0.2818656143f, -0.2261282142f, -0.1231384900f, 0.0228924303f, 0.2007416620f, 0.3935871743f, 0.5810779624f, + 0.7418520015f, 0.8562199711f, 0.9086554096f, 0.8898222505f, 0.7978469922f, 0.6387191949f, 0.4257228188f, 0.1780121397f, + -0.0815452149f, -0.3289431293f, -0.5417726272f, -0.7017230773f, -0.7966125143f, -0.8216246380f, -0.7796902592f, -0.6808705368f, + -0.5409377623f, -0.3791916953f, -0.2159490132f, -0.0697984743f, 0.0447973984f, 0.1196560777f, 0.1547311650f, 0.1631223252f, + 0.1615491774f, 0.1553970134f, 0.1453090286f, 0.1325143072f, 0.1179833627f, 0.1026659817f, 0.0872986185f, 0.0725159741f, + 0.0587697393f, 0.0463978659f, 0.0355880008f, 0.0264313485f, 0.0189090552f, 0.0129379217f, 0.0083680105f, 0.0050209526f, + 0.0026911244f, 0.0011756268f, 0.0002742518f, -0.0001893835f, -0.0003713645f, -0.0003945662f, -0.0003559061f, -0.0003199311f, + -0.0003286406f, -0.0003992283f, -0.0005347052f, -0.0007234444f, -0.0009489211f, -0.0011892232f, -0.0014247925f, -0.0016368658f, + -0.0018128572f, -0.0019435092f, -0.0020262245f, -0.0020613098f, -0.0020539729f, -0.0020103196f, -0.0019388124f, -0.0018466470f, + -0.0017412840f, -0.0016275801f, -0.0015096821f, -0.0013889666f, -0.0012662678f, -0.0011404183f, -0.0010105747f, -0.0008750310f, + -0.0007333545f, -0.0005851730f, -0.0004319169f, -0.0002754165f, -0.0001192014f, 0.0000330890f, 0.0001767485f, 0.0003076493f, + 0.0004214404f, 0.0005150718f, 0.0005859601f, 0.0006332532f, 0.0006568484f, 0.0006583487f, 0.0006399242f, 0.0006050121f, + 0.0005571017f, 0.0005002994f, 0.0004381601f, 0.0003742519f, 0.0003111446f, 0.0002510679f, 0.0001951108f, 0.0001440004f, + 0.0000974938f, 0.0000552356f, 0.0000162701f, -0.0000201054f, -0.0000548020f, -0.0000881717f, -0.0001205191f, -0.0001514697f, + -0.0001805617f, -0.0002067517f, -0.0002290677f, -0.0002462077f, -0.0002572013f, -0.0002610364f, -0.0002572665f, -0.0002456071f, + -0.0002264461f, -0.0002003792f, -0.0001686145f, + -0.0002097915f, -0.0002547683f, -0.0002867440f, -0.0003037080f, -0.0003049864f, -0.0002912099f, -0.0002641320f, -0.0002263469f, + -0.0001809155f, -0.0001309730f, -0.0000793326f, -0.0000281672f, 0.0000212324f, 0.0000685537f, 0.0001144458f, 0.0001603457f, + 0.0002082167f, 0.0002601799f, 0.0003181336f, 0.0003833534f, 0.0004561750f, 0.0005357423f, 0.0006199091f, 0.0007052503f, + 0.0007872414f, 0.0008605303f, 0.0009193285f, 0.0009578246f, 0.0009706279f, 0.0009531437f, 0.0009018903f, 0.0008146822f, + 0.0006907085f, 0.0005304701f, 0.0003356294f, 0.0001087751f, -0.0001468322f, -0.0004275067f, -0.0007293282f, -0.0010482464f, + -0.0013801011f, -0.0017205409f, -0.0020649160f, -0.0024081360f, -0.0027446427f, -0.0030684675f, -0.0033735725f, -0.0036543691f, + -0.0039066272f, -0.0041285253f, -0.0043220448f, -0.0044942599f, -0.0046587239f, -0.0048362859f, -0.0050555995f, -0.0053524607f, + -0.0057684191f, -0.0063476637f, -0.0071329714f, -0.0081596433f, -0.0094487437f, -0.0109984997f, -0.0127758558f, -0.0147068954f, + -0.0166688890f, -0.0184823228f, -0.0199064468f, -0.0206359860f, -0.0203032667f, -0.0184822593f, -0.0146993237f, -0.0084456516f, + 0.0008037916f, 0.0135712038f, 0.0303539710f, 0.0516053773f, 0.0777267032f, 0.1090646438f, 0.1459928995f, 0.1890045882f, + 0.2399569411f, 0.3035491657f, 0.3744326411f, 0.4330381754f, 0.4602649242f, 0.4422767198f, 0.3711532515f, 0.2461380555f, + 0.0737670473f, -0.1327449736f, -0.3550430014f, -0.5718089399f, -0.7613406410f, -0.9042683903f, -0.9859824923f, -0.9986999813f, + -0.9431316453f, -0.8322426947f, -0.6838587489f, -0.5090121248f, -0.3164353275f, -0.1160643779f, 0.0821150478f, 0.2684309672f, + 0.4341770987f, 0.5719923883f, 0.6762928566f, 0.7434950500f, 0.7721889543f, 0.7631234448f, 0.7191049971f, 0.6447409999f, + 0.5461062812f, 0.4303073808f, 0.3050115994f, 0.1779422698f, 0.0563953149f, -0.0532072816f, -0.1456894384f, -0.2173979596f, + -0.2663715333f, -0.2923808160f, -0.2968590700f, -0.2826977783f, -0.2539702782f, -0.2155328992f, -0.1726410340f, -0.1304388234f, + -0.0937203765f, -0.0651894568f, -0.0434204585f, -0.0262320261f, -0.0128620020f, -0.0027758731f, 0.0045023778f, 0.0094378307f, + 0.0124649620f, 0.0139956053f, 0.0143989384f, 0.0140037462f, 0.0130866052f, 0.0118760507f, 0.0105485285f, 0.0092355458f, + 0.0080250843f, 0.0069705449f, 0.0060949377f, 0.0053998515f, 0.0048701054f, 0.0044812646f, 0.0042032151f, 0.0040054335f, + 0.0038588251f, 0.0037386836f, 0.0036248683f, 0.0035029301f, 0.0033631517f, 0.0032005638f, 0.0030135068f, 0.0028032324f, + 0.0025725319f, 0.0023254060f, 0.0020660644f, 0.0017988746f, 0.0015277862f, 0.0012565431f, 0.0009884144f, 0.0007265302f, + 0.0004737413f, 0.0002329236f, 0.0000068230f, -0.0002017617f, -0.0003902098f, -0.0005560211f, -0.0006970975f, -0.0008117494f, + -0.0008989567f, -0.0009583547f, -0.0009904048f, -0.0009962992f, -0.0009780085f, -0.0009380932f, -0.0008796449f, -0.0008060398f, + -0.0007208281f, -0.0006274895f, -0.0005293371f, -0.0004293314f, -0.0003300469f, -0.0002335751f, -0.0001415683f, -0.0000552272f, + 0.0000245975f, 0.0000973664f, 0.0001627306f, 0.0002204858f, 0.0002704729f, 0.0003125597f, 0.0003465872f, 0.0003723927f, + 0.0003898040f, 0.0003986947f, 0.0003990072f, 0.0003908172f, 0.0003743577f, 0.0003500669f, 0.0003185900f, 0.0002807935f, + 0.0002377348f, 0.0001906413f, 0.0001408526f, 0.0000897771f, 0.0000388229f, -0.0000106507f, -0.0000573934f, -0.0001003004f, + -0.0001384514f, -0.0001711250f, -0.0001978125f, -0.0002182105f, -0.0002322144f, -0.0002398964f, -0.0002414880f, + -0.0001596129f, -0.0001562496f, -0.0001498931f, -0.0001412337f, -0.0001312006f, -0.0001208315f, -0.0001111500f, -0.0001030067f, + -0.0000969764f, -0.0000932334f, -0.0000915268f, -0.0000911372f, -0.0000909596f, -0.0000895515f, -0.0000853138f, -0.0000765980f, + -0.0000619367f, -0.0000401498f, -0.0000105563f, 0.0000269865f, 0.0000719478f, 0.0001231977f, 0.0001789736f, 0.0002370733f, + 0.0002949065f, 0.0003497691f, 0.0003989259f, 0.0004399015f, 0.0004705253f, 0.0004891741f, 0.0004947225f, 0.0004866983f, + 0.0004651169f, 0.0004305530f, 0.0003838811f, 0.0003263054f, 0.0002590637f, 0.0001834786f, 0.0001006881f, 0.0000117772f, + -0.0000824234f, -0.0001810986f, -0.0002835801f, -0.0003890188f, -0.0004964869f, -0.0006046168f, -0.0007117406f, -0.0008155628f, + -0.0009134018f, -0.0010019440f, -0.0010776210f, -0.0011364499f, -0.0011745303f, -0.0011879291f, -0.0011732401f, -0.0011274376f, + -0.0010484260f, -0.0009347877f, -0.0007862674f, -0.0006033735f, -0.0003877877f, -0.0001418301f, 0.0001311620f, 0.0004274542f, + 0.0007424943f, 0.0010715568f, 0.0014092217f, 0.0017500212f, 0.0020878151f, 0.0024164922f, 0.0027293133f, 0.0030197921f, + 0.0032811287f, 0.0035074177f, 0.0036932727f, 0.0038354464f, 0.0039326233f, 0.0039873724f, 0.0040058742f, 0.0039999004f, + 0.0039859967f, 0.0039869775f, 0.0040299079f, 0.0041465214f, 0.0043693426f, 0.0047305856f, 0.0052560067f, 0.0059622775f, + 0.0068486582f, 0.0078935236f, 0.0090446101f, 0.0102161743f, 0.0112791696f, 0.0120612232f, 0.0123383309f, 0.0118401814f, + 0.0102443788f, 0.0071893168f, 0.0022697611f, -0.0049422577f, -0.0149080197f, -0.0281014987f, -0.0450597042f, -0.0665503452f, + -0.0947658820f, -0.1311459738f, -0.1730055990f, -0.2155698254f, -0.2537148355f, -0.2822005637f, -0.2961808714f, -0.2915797030f, + -0.2654897618f, -0.2164403253f, -0.1446028708f, -0.0518524544f, 0.0582677361f, 0.1807212874f, 0.3092454104f, 0.4367256082f, + 0.5556248313f, 0.6584663388f, 0.7383128514f, 0.7892352587f, 0.8067145259f, 0.7879751516f, 0.7322001587f, 0.6406413437f, + 0.5165833320f, 0.3651995965f, 0.1932631326f, 0.0087845907f, -0.1794730708f, -0.3624711894f, -0.5314826505f, -0.6784496714f, + -0.7975387008f, -0.8869066714f, -0.9460978228f, -0.9743683484f, -0.9716887763f, -0.9388912477f, -0.8776913880f, -0.7906217616f, + -0.6809617759f, -0.5526158639f, -0.4099903122f, -0.2578384472f, -0.1011091221f, 0.0552204273f, 0.2063009082f, 0.3475689337f, + 0.4748858634f, 0.5846665399f, 0.6739816770f, 0.7406414471f, 0.7832480152f, 0.8012243690f, 0.7948108464f, 0.7650372454f, + 0.7136651972f, 0.6431094919f, 0.5563357930f, 0.4567441179f, 0.3480375726f, 0.2340859886f, 0.1187851647f, 0.0059210218f, + -0.1009603020f, -0.1986681163f, -0.2844680876f, -0.3561617036f, -0.4121449494f, -0.4514415411f, -0.4737129527f, -0.4792427680f, + -0.4688992715f, -0.4440758562f, -0.4066146191f, -0.3587143469f, -0.3028292405f, -0.2415605597f, -0.1775478604f, -0.1133622284f, + -0.0514077865f, 0.0061666480f, 0.0575405302f, 0.1012784567f, 0.1363672493f, 0.1622340919f, 0.1787438032f, 0.1861777807f, + 0.1851944065f, 0.1767749919f, 0.1621564237f, 0.1427557163f, 0.1200884424f, 0.0956867818f, 0.0710192746f, 0.0474178663f, + 0.0260137499f, 0.0076867119f, -0.0069716085f, -0.0176776741f, -0.0244598245f, -0.0276479905f, -0.0278485265f, -0.0259604376f, + -0.0231942463f, -0.0203712397f, -0.0176250103f, -0.0150030188f, -0.0125853805f, -0.0104245492f, -0.0085536471f, -0.0069822366f, + -0.0057037888f, -0.0046971305f, -0.0039324091f, -0.0033733475f, -0.0029816582f, -0.0027187689f, -0.0025487112f, -0.0024389400f, + -0.0023618935f, -0.0022949607f, -0.0022210429f, -0.0021279181f, -0.0020081783f, -0.0018582858f, -0.0016782193f, -0.0014704729f, + -0.0012396507f, -0.0009915718f, -0.0007329515f, -0.0004706874f, -0.0002116789f, 0.0000376970f, 0.0002716276f, 0.0004852251f, + 0.0006744554f, 0.0008363689f, 0.0009689456f, 0.0010712272f, 0.0011431025f, 0.0011853673f, 0.0011994712f, 0.0011875293f, + 0.0011520531f, 0.0010959403f, 0.0010222139f, 0.0009340189f, 0.0008343934f, 0.0007262955f, 0.0006124255f, 0.0004952948f, + 0.0003771045f, 0.0002598545f, 0.0001452665f, 0.0000349171f, -0.0000698172f, -0.0001676287f, -0.0002573385f, -0.0003377893f, + -0.0004079306f, -0.0004667485f, -0.0005133801f, -0.0005470765f, -0.0005673356f, -0.0005738781f, -0.0005667759f, -0.0005464152f, + -0.0005135934f, -0.0004694478f, -0.0004155042f, -0.0003535607f, -0.0002856874f, -0.0002140732f, -0.0001409939f, -0.0000686445f, + 0.0000008966f, 0.0000658187f, 0.0001245893f, 0.0001760633f, 0.0002194479f, 0.0002543579f, 0.0002807311f, 0.0002988367f, + 0.0003091550f, 0.0003123597f, 0.0003091881f, 0.0003004253f, 0.0002867930f, 0.0002689588f, 0.0002474626f, 0.0002227630f, + 0.0001952039f, 0.0001650929f, 0.0001326952f, 0.0000983261f, 0.0000623480f, 0.0000252528f, -0.0000123602f, -0.0000497334f, + -0.0000860060f, -0.0001202016f, -0.0001513162f, -0.0001783353f, -0.0002003408f, -0.0002165359f, -0.0002263463f, -0.0002294298f, + -0.0002257477f, -0.0002155386f, -0.0001993478f, -0.0001779591f, -0.0001523829f, -0.0001237555f, -0.0000933024f, -0.0000622262f, + -0.0000316695f, -0.0000026169f, 0.0000241191f, 0.0000479620f, 0.0000685482f, 0.0000857501f, 0.0000996158f, 0.0001103594f, + 0.0001182780f, 0.0001237279f, 0.0001270411f, 0.0001285109f, 0.0001283284f, 0.0001265953f, 0.0001232928f, 0.0001183261f, + 0.0001115250f, 0.0001027124f, 0.0000917214f, 0.0000784695f, 0.0000629720f, 0.0000454005f, 0.0000260736f, 0.0000054844f, + -0.0000157413f, -0.0000368512f, -0.0000570374f, -0.0000754661f, -0.0000913623f, -0.0001040431f, -0.0001129942f, + -0.0001518039f, -0.0001490944f, -0.0001437563f, -0.0001359447f, -0.0001258775f, -0.0001138183f, -0.0001000584f, -0.0000848958f, + -0.0000686184f, -0.0000514869f, -0.0000337271f, -0.0000155230f, 0.0000029786f, 0.0000216627f, 0.0000404299f, 0.0000591833f, + 0.0000778062f, 0.0000961486f, 0.0001140075f, 0.0001311212f, 0.0001471607f, 0.0001617373f, 0.0001744077f, 0.0001846979f, + 0.0001921197f, 0.0001962050f, 0.0001965285f, 0.0001927436f, 0.0001846019f, 0.0001719815f, 0.0001548948f, 0.0001335028f, + 0.0001081065f, 0.0000791461f, 0.0000471762f, 0.0000128542f, -0.0000230952f, -0.0000598950f, -0.0000967535f, -0.0001328756f, + -0.0001674945f, -0.0001998742f, -0.0002293319f, -0.0002552303f, -0.0002769922f, -0.0002940867f, -0.0003060409f, -0.0003124253f, + -0.0003128705f, -0.0003070572f, -0.0002947414f, -0.0002757524f, -0.0002500272f, -0.0002176130f, -0.0001787066f, -0.0001336551f, + -0.0000829924f, -0.0000274293f, 0.0000321218f, 0.0000945733f, 0.0001586548f, 0.0002229603f, 0.0002859566f, 0.0003460483f, + 0.0004015979f, 0.0004510007f, 0.0004927070f, 0.0005252984f, 0.0005475019f, 0.0005582587f, 0.0005567241f, 0.0005423236f, + 0.0005147357f, 0.0004739352f, 0.0004201606f, 0.0003539484f, 0.0002760880f, 0.0001876525f, 0.0000899450f, -0.0000154720f, + -0.0001268367f, -0.0002421597f, -0.0003592929f, -0.0004759036f, -0.0005895563f, -0.0006976915f, -0.0007977237f, -0.0008870259f, + -0.0009630432f, -0.0010232813f, -0.0010654313f, -0.0010873564f, -0.0010872233f, -0.0010634782f, -0.0010149807f, -0.0009409632f, + -0.0008411655f, -0.0007157758f, -0.0005655665f, -0.0003918178f, -0.0001964570f, 0.0000180385f, 0.0002485007f, 0.0004912017f, + 0.0007417257f, 0.0009951609f, 0.0012460131f, 0.0014884994f, 0.0017165405f, 0.0019242012f, 0.0021057906f, 0.0022564772f, + 0.0023724911f, 0.0024518980f, 0.0024948363f, 0.0025043647f, 0.0024865838f, 0.0024513953f, 0.0024122725f, 0.0023867094f, + 0.0023953488f, 0.0024618909f, 0.0026112876f, 0.0028689594f, 0.0032578396f, 0.0037969386f, 0.0044971599f, 0.0053595648f, + 0.0063700240f, 0.0074979980f, 0.0086900568f, 0.0098707813f, 0.0109344936f, 0.0117523261f, 0.0121588428f, 0.0119927747f, + 0.0108338004f, 0.0076669462f, 0.0015951619f, -0.0077015608f, -0.0201874668f, -0.0355062002f, -0.0530094339f, -0.0717877750f, + -0.0907221346f, -0.1085412898f, -0.1238936126f, -0.1354215686f, -0.1418421064f, -0.1420235850f, -0.1350600376f, -0.1203351392f, + -0.0975759142f, -0.0668903695f, -0.0287893898f, 0.0158109005f, 0.0656049927f, 0.1189337419f, 0.1738373906f, 0.2281255290f, + 0.2794600956f, 0.3254494085f, 0.3637483740f, 0.3921617568f, 0.4087452458f, 0.4119008001f, 0.4004612717f, 0.3737611396f, + 0.3316892920f, 0.2747217255f, 0.2039316066f, 0.1209761088f, 0.0280593378f, -0.0721274395f, -0.1764869974f, -0.2816158102f, + -0.3839191559f, -0.4797372694f, -0.5654782669f, -0.6377526073f, -0.6935042311f, -0.7301330421f, -0.7456040786f, -0.7385387273f, + -0.7082842960f, -0.6549586998f, -0.5794681743f, -0.4834966938f, -0.3694669951f, -0.2404740552f, -0.1001929952f, 0.0472356415f, + 0.1973394347f, 0.3454617961f, 0.4869187455f, 0.6171590292f, 0.7319219537f, 0.8273869572f, 0.9003096301f, 0.9481388242f, + 0.9691107389f, 0.9623160652f, 0.9277378915f, 0.8662587282f, 0.7796363134f, 0.6704507997f, 0.5420235210f, 0.3983429587f, + 0.2439770306f, 0.0835515600f, -0.0785437339f, -0.2379253926f, -0.3902709949f, -0.5314762215f, -0.6577657562f, -0.7658017175f, + -0.8527727865f, -0.9164711922f, -0.9553496178f, -0.9685606622f, -0.9559747754f, -0.9181785555f, -0.8564517514f, -0.7727251920f, + -0.6695198086f, -0.5498696134f, -0.4172301964f, -0.2753762088f, -0.1282903603f, 0.0199522336f, 0.1653013209f, 0.3038465453f, + 0.4319271716f, 0.5462330255f, 0.6438939828f, 0.7225552652f, 0.7804366545f, 0.8163739029f, 0.8298414763f, 0.8209560951f, + 0.7904613476f, 0.7396940415f, 0.6705336701f, 0.5853367342f, 0.4868582109f, 0.3781627335f, 0.2625283931f, 0.1433461974f, + 0.0240183452f, -0.0921415681f, -0.2020034062f, -0.3027076056f, -0.3917420558f, -0.4670065944f, -0.5268634348f, -0.5701722713f, + -0.5963093708f, -0.6051704118f, -0.5971574290f, -0.5731506218f, -0.5344663552f, -0.4828029698f, -0.4201764962f, -0.3488485038f, + -0.2712486558f, -0.1898944962f, -0.1073111782f, -0.0259536082f, 0.0518664854f, 0.1240464667f, 0.1887496815f, 0.2444518757f, + 0.2899758594f, 0.3245137882f, 0.3476366187f, 0.3592909899f, 0.3597839221f, 0.3497564092f, 0.3301470195f, 0.3021472383f, + 0.2671501836f, 0.2266948496f, 0.1824077493f, 0.1359442498f, 0.0889314191f, 0.0429145298f, -0.0006912934f, -0.0406425334f, + -0.0759009165f, -0.1056580541f, -0.1293508553f, -0.1466672055f, -0.1575424230f, -0.1621466320f, -0.1608642639f, -0.1542663510f, + -0.1430773876f, -0.1281377523f, -0.1103638299f, -0.0907069045f, -0.0701130981f, -0.0494852310f, -0.0296487968f, -0.0113224665f, + 0.0049049322f, 0.0185912359f, 0.0294499482f, 0.0373525686f, 0.0423229093f, 0.0445255530f, 0.0442471860f, 0.0418741009f, + 0.0378642492f, 0.0327185225f, 0.0269484800f, 0.0210472303f, 0.0154578360f, 0.0105498876f, 0.0065912187f, 0.0037323571f, + 0.0018671281f, 0.0006505029f, -0.0001484215f, -0.0006222332f, -0.0008521845f, -0.0009057969f, -0.0008424506f, -0.0007103595f, + -0.0005491202f, -0.0003884807f, -0.0002503188f, -0.0001485007f, -0.0000907440f, -0.0000790482f, -0.0001114146f, -0.0001824655f, + -0.0002849020f, -0.0004100554f, -0.0005489962f, -0.0006928821f, -0.0008336988f, -0.0009643687f, -0.0010791665f, -0.0011736223f, + -0.0012446927f, -0.0012905298f, -0.0013105005f, -0.0013048967f, -0.0012748875f, -0.0012222325f, -0.0011492257f, -0.0010584505f, + -0.0009527473f, -0.0008350241f, -0.0007082563f, -0.0005753473f, -0.0004391546f, -0.0003023856f, -0.0001676358f, -0.0000373054f, + 0.0000863632f, 0.0002013598f, 0.0003058750f, 0.0003983709f, 0.0004775550f, 0.0005424460f, 0.0005923474f, 0.0006269020f, + 0.0006460595f, 0.0006501134f, 0.0006396557f, 0.0006155940f, 0.0005790906f, 0.0005315601f, 0.0004745961f, 0.0004099540f, + 0.0003394710f, 0.0002650418f, 0.0001885408f, 0.0001117995f, 0.0000365379f, -0.0000356487f, -0.0001033434f, -0.0001653071f, + -0.0002205157f, -0.0002681453f, -0.0003075938f, -0.0003384554f, -0.0003605306f, -0.0003737941f, -0.0003783989f, -0.0003746427f, + -0.0003629698f, -0.0003439392f, -0.0003182272f, -0.0002865979f, -0.0002499066f, -0.0002090714f, -0.0001650754f, -0.0001189372f, + -0.0000717098f, -0.0000244485f, 0.0000217960f, 0.0000660121f, 0.0001072384f, 0.0001445996f, 0.0001773182f, 0.0002047476f, + 0.0002263802f, 0.0002418727f, 0.0002510450f, 0.0002538948f, 0.0002505843f, 0.0002414409f, 0.0002269326f, 0.0002076567f, + 0.0001843057f, 0.0001576490f, 0.0001284948f, 0.0000976709f, 0.0000659883f, 0.0000342273f, 0.0000031084f, -0.0000267131f, + -0.0000546656f, -0.0000802581f, -0.0001030882f, -0.0001228320f, -0.0001392462f, -0.0001521538f, -0.0001614454f, -0.0001670654f, + -0.0001690150f, -0.0001673428f, -0.0001621512f, -0.0001535906f, -0.0001418693f, -0.0001272490f, -0.0001100543f, -0.0000906661f, + -0.0000695268f, -0.0000471286f, -0.0000240107f, -0.0000007413f, 0.0000220928f, 0.0000439109f, 0.0000641527f, 0.0000823053f, + 0.0000979177f, 0.0001106244f, 0.0001201540f, 0.0001263447f, 0.0001291432f, 0.0001286087f, 0.0001249010f, 0.0001182738f, + -0.0000677642f, -0.0000523826f, -0.0000355858f, -0.0000177135f, 0.0000008632f, 0.0000197497f, 0.0000385362f, 0.0000568069f, + 0.0000741490f, 0.0000901630f, 0.0001044714f, 0.0001167282f, 0.0001266271f, 0.0001339090f, 0.0001383682f, 0.0001398580f, + 0.0001382933f, 0.0001336542f, 0.0001259858f, 0.0001153988f, 0.0001020662f, 0.0000862221f, 0.0000681561f, 0.0000482094f, + 0.0000267679f, 0.0000042570f, -0.0000188674f, -0.0000421254f, -0.0000650225f, -0.0000870579f, -0.0001077348f, -0.0001265690f, + -0.0001431007f, -0.0001569032f, -0.0001675946f, -0.0001748464f, -0.0001783945f, -0.0001780466f, -0.0001736910f, -0.0001653012f, + -0.0001529419f, -0.0001367694f, -0.0001170335f, -0.0000940728f, -0.0000683121f, -0.0000402526f, -0.0000104645f, 0.0000204271f, + 0.0000517530f, 0.0000828177f, 0.0001129118f, 0.0001413312f, 0.0001673905f, 0.0001904409f, 0.0002098828f, 0.0002251816f, + 0.0002358781f, 0.0002416012f, 0.0002420750f, 0.0002371285f, 0.0002266990f, 0.0002108387f, 0.0001897144f, 0.0001636105f, + 0.0001329251f, 0.0000981694f, 0.0000599596f, 0.0000190121f, -0.0000238695f, -0.0000678035f, -0.0001118486f, -0.0001550177f, + -0.0001963012f, -0.0002346852f, -0.0002691787f, -0.0002988340f, -0.0003227757f, -0.0003402211f, -0.0003505078f, -0.0003531107f, + -0.0003476646f, -0.0003339751f, -0.0003120340f, -0.0002820207f, -0.0002443090f, -0.0001994588f, -0.0001482132f, -0.0000914813f, + -0.0000303277f, 0.0000340527f, 0.0001003514f, 0.0001671757f, 0.0002330697f, 0.0002965468f, 0.0003561116f, 0.0004102952f, + 0.0004576768f, 0.0004969199f, 0.0005267939f, 0.0005462097f, 0.0005542410f, 0.0005501582f, 0.0005334466f, 0.0005038372f, + 0.0004613187f, 0.0004061612f, 0.0003389189f, 0.0002604423f, 0.0001718676f, 0.0000746148f, -0.0000296392f, -0.0001389767f, + -0.0002512831f, -0.0003642749f, -0.0004755563f, -0.0005826556f, -0.0006830878f, -0.0007743933f, -0.0008542007f, -0.0009202618f, + -0.0009705111f, -0.0010030942f, -0.0010164239f, -0.0010092036f, -0.0009804838f, -0.0009296846f, -0.0008566574f, -0.0007617096f, + -0.0006456731f, -0.0005099278f, -0.0003564679f, -0.0001879096f, -0.0000075330f, 0.0001807554f, 0.0003724395f, 0.0005625175f, + 0.0007456177f, 0.0009162481f, 0.0010690442f, 0.0011991672f, 0.0013026871f, 0.0013771151f, 0.0014218793f, 0.0014389208f, + 0.0014331600f, 0.0014130261f, 0.0013907522f, 0.0013826603f, 0.0014090891f, 0.0014942408f, 0.0016655626f, 0.0019530043f, + 0.0023877813f, 0.0030010282f, 0.0038221874f, 0.0048773753f, 0.0061889900f, 0.0077755997f, 0.0096751224f, 0.0119741302f, + 0.0145439912f, 0.0169456183f, 0.0187073400f, 0.0194030360f, 0.0186550704f, 0.0161628228f, 0.0117223361f, 0.0052458122f, + -0.0032269514f, -0.0135216735f, -0.0253307510f, -0.0382203402f, -0.0516449105f, -0.0649674012f, -0.0774853341f, -0.0884609329f, + -0.0971548077f, -0.1028611423f, -0.1049434729f, -0.1028690049f, -0.0962403901f, -0.0848231076f, -0.0685674901f, -0.0476239362f, + -0.0223507100f, 0.0066865637f, 0.0387237751f, 0.0728157951f, 0.1078619795f, 0.1426392416f, 0.1758415350f, 0.2061246656f, + 0.2321547755f, 0.2526589705f, 0.2664761293f, 0.2726061478f, 0.2702555997f, 0.2588781212f, 0.2382077111f, 0.2082835801f, + 0.1694652065f, 0.1224367910f, 0.0682004341f, 0.0080579540f, -0.0564185505f, -0.1234266811f, -0.1909833663f, -0.2569826708f, + -0.3192601922f, -0.3756619825f, -0.4241159008f, -0.4627029725f, -0.4897264437f, -0.5037760457f, -0.5037852577f, -0.4890793474f, + -0.4594123986f, -0.4149916704f, -0.3564881936f, -0.2850327525f, -0.2021970477f, -0.1099601299f, -0.0106608717f, 0.0930624757f, + 0.1983439454f, 0.3021708437f, 0.4014716150f, 0.4932080681f, 0.5744690342f, 0.6425626416f, 0.6951041455f, 0.7300965662f, + 0.7460013189f, 0.7417965309f, 0.7170208283f, 0.6718010612f, 0.6068626327f, 0.5235219179f, 0.4236604995f, 0.3096818407f, + 0.1844512322f, 0.0512207469f, -0.0864589501f, -0.2248372460f, -0.3600700554f, -0.4883307618f, -0.6059225628f, -0.7093885522f, + -0.7956164474f, -0.8619344004f, -0.9061952044f, -0.9268458353f, -0.9229804407f, -0.8943745512f, -0.8414997451f, -0.7655175933f, + -0.6682534406f, -0.5521499681f, -0.4202024874f, -0.2758769248f, -0.1230137793f, 0.0342802674f, 0.1917486212f, 0.3451070280f, + 0.4901663081f, 0.6229542130f, 0.7398298367f, 0.8375910214f, 0.9135663759f, 0.9656969770f, 0.9925961604f, 0.9936618731f, + 0.9690844417f, 0.9196504635f, 0.8467117373f, 0.7522210603f, 0.6386799560f, 0.5090760386f, 0.3668025779f, 0.2155702981f, + 0.0593086479f, -0.0979369079f, -0.2521117236f, -0.3992577525f, -0.5356173001f, -0.6577304376f, -0.7625247715f, -0.8473940864f, + -0.9102647317f, -0.9496471895f, -0.9646722171f, -0.9551100144f, -0.9213725472f, -0.8644985297f, -0.7861220221f, -0.6884251575f, + -0.5740767467f, -0.4461581538f, -0.3080788471f, -0.1634836803f, -0.0161547423f, 0.1300897818f, 0.2714967454f, 0.4044766502f, + 0.5256968794f, 0.6321672656f, 0.7213155657f, 0.7910510602f, 0.8398145087f, 0.8666133944f, 0.8710415117f, 0.8532826677f, + 0.8140984457f, 0.7548006627f, 0.6772093367f, 0.5835975864f, 0.4766250203f, 0.3592616720f, 0.2347045793f, 0.1062894680f, + -0.0226000741f, -0.1486233373f, -0.2685707508f, -0.3794472128f, -0.4785483597f, -0.5635277262f, -0.6324531653f, -0.6838510882f, + -0.7167375675f, -0.7306356074f, -0.7255783918f, -0.7020986046f, -0.6612044089f, -0.6043429290f, -0.5333525140f, -0.4504052564f, + -0.3579415767f, -0.2585987895f, -0.1551357820f, -0.0503559257f, 0.0529695663f, 0.1521757603f, 0.2447735547f, 0.3285128639f, + 0.4014377748f, 0.4619323450f, 0.5087559395f, 0.5410673824f, 0.5584374718f, 0.5608498058f, 0.5486901404f, 0.5227248799f, + 0.4840695396f, 0.4341483415f, 0.3746462780f, 0.3074552135f, 0.2346156774f, 0.1582561348f, 0.0805315031f, 0.0035627058f, + -0.0706210625f, -0.1401357650f, -0.2032902555f, -0.2586270896f, -0.3049554547f, -0.3413754822f, -0.3672935096f, -0.3824281003f, + -0.3868069422f, -0.3807549745f, -0.3648743722f, -0.3400172139f, -0.3072518737f, -0.2678243125f, -0.2231155831f, -0.1745969158f, + -0.1237838039f, -0.0721904757f, -0.0212861041f, 0.0275460057f, 0.0730451234f, 0.1141047432f, 0.1497983924f, 0.1793990348f, + 0.2023917050f, 0.2184792403f, 0.2275811871f, 0.2298261737f, 0.2255382274f, 0.2152176942f, 0.1995175598f, 0.1792160900f, + 0.1551867943f, 0.1283667617f, 0.0997244393f, 0.0702278948f, 0.0408145632f, 0.0123633806f, -0.0143298873f, -0.0385734628f, + -0.0597959924f, -0.0775582602f, -0.0915599770f, -0.1016416466f, -0.1077816401f, -0.1100888003f, -0.1087910023f, -0.1042202530f, + -0.0967949724f, -0.0870002132f, -0.0753665756f, -0.0624486407f, -0.0488036800f, -0.0349714234f, -0.0214555345f, -0.0087074338f, + 0.0028870743f, 0.0130179511f, 0.0214576480f, 0.0280642424f, 0.0327810674f, 0.0356329290f, 0.0367192621f, 0.0362045427f, + 0.0343065259f, 0.0312827821f, 0.0274162441f, 0.0230002982f, 0.0183241826f, 0.0136591847f, 0.0092463500f, 0.0052860575f, + 0.0019300215f, -0.0007241258f, -0.0026354098f, -0.0038192546f, -0.0043449892f, -0.0043308242f, -0.0039467893f, -0.0034183427f, + -0.0028980777f, -0.0024111931f, -0.0019661658f, -0.0015766458f, -0.0012505436f, -0.0009916652f, -0.0007991070f, -0.0006687325f, + -0.0005935987f, -0.0005651424f, -0.0005737315f, -0.0006095407f, -0.0006629742f, -0.0007252278f, -0.0007885086f, -0.0008463178f, + -0.0008934778f, -0.0009262011f, -0.0009419761f, -0.0009394996f, -0.0009184875f, -0.0008795438f, -0.0008239543f, -0.0007535478f, + -0.0006705140f, -0.0005772899f, -0.0004764213f, -0.0003704871f, -0.0002620058f, -0.0001533948f, -0.0000469126f, 0.0000553574f, + 0.0001515421f, 0.0002399825f, 0.0003192564f, 0.0003881782f, 0.0004458153f, 0.0004914859f, 0.0005247706f, 0.0005455066f, + 0.0005537921f, 0.0005499733f, 0.0005346385f, 0.0005085956f, 0.0004728546f, 0.0004285952f, 0.0003771392f, 0.0003199107f, + 0.0002584034f, 0.0001941376f, 0.0001286276f, 0.0000633423f, -0.0000003230f, -0.0000610784f, -0.0001177585f, -0.0001693439f, + -0.0002149716f, -0.0002539451f, -0.0002857364f, -0.0003099879f, -0.0003265074f, -0.0003352642f, -0.0003363800f, -0.0003301214f, + -0.0003168882f, -0.0002972036f, -0.0002717009f, -0.0002411115f, -0.0002062492f, -0.0001679960f, -0.0001272837f, -0.0000850767f, + -0.0000423512f, -0.0000000757f, 0.0000408118f, 0.0000794235f, 0.0001149437f, 0.0001466472f, 0.0001739170f, 0.0001962578f, + 0.0002133072f, 0.0002248417f, 0.0002307793f, 0.0002311773f, 0.0002262259f, 0.0002162377f, 0.0002016344f, 0.0001829302f, + 0.0001607141f, 0.0001356302f, 0.0001083590f, 0.0000795981f, 0.0000500456f, 0.0000203831f, -0.0000087366f, -0.0000367025f, + -0.0000629538f, -0.0000869878f, -0.0001083652f, -0.0001267149f, -0.0001417362f, -0.0001532019f, -0.0001609587f, -0.0001649294f, + -0.0001651125f, -0.0001615824f, -0.0001544884f, -0.0001440526f, -0.0001305669f, -0.0001143883f, -0.0000959318f, -0.0000756626f, + -0.0000540855f, -0.0000317331f, -0.0000091523f, 0.0000131100f, 0.0000345222f, 0.0000545822f, 0.0000728319f, 0.0000888696f, + 0.0001023607f, 0.0001130460f, 0.0001207471f, 0.0001253683f, 0.0001268968f, 0.0001253988f, 0.0001210137f, 0.0001139460f, + -0.0000409890f, -0.0000231831f, -0.0000044979f, 0.0000146405f, 0.0000337894f, 0.0000524983f, 0.0000703210f, 0.0000868245f, + 0.0001016007f, 0.0001142746f, 0.0001245146f, 0.0001320387f, 0.0001366230f, 0.0001381059f, 0.0001363940f, 0.0001314632f, + 0.0001233624f, 0.0001122120f, 0.0000982042f, 0.0000815988f, 0.0000627207f, 0.0000419531f, 0.0000197321f, -0.0000034635f, + -0.0000271191f, -0.0000506974f, -0.0000736478f, -0.0000954205f, -0.0001154773f, -0.0001333068f, -0.0001484351f, -0.0001604403f, + -0.0001689621f, -0.0001737145f, -0.0001744920f, -0.0001711796f, -0.0001637549f, -0.0001522934f, -0.0001369666f, -0.0001180419f, + -0.0000958757f, -0.0000709093f, -0.0000436571f, -0.0000146989f, 0.0000153358f, 0.0000457778f, 0.0000759362f, 0.0001051099f, + 0.0001326066f, 0.0001577542f, 0.0001799192f, 0.0001985179f, 0.0002130330f, 0.0002230225f, 0.0002281351f, 0.0002281154f, + 0.0002228168f, 0.0002122035f, 0.0001963592f, 0.0001754845f, 0.0001499022f, 0.0001200490f, 0.0000864751f, 0.0000498314f, + 0.0000108634f, -0.0000296076f, -0.0000706952f, -0.0001114718f, -0.0001509832f, -0.0001882759f, -0.0002224138f, -0.0002525068f, + -0.0002777271f, -0.0002973368f, -0.0003107015f, -0.0003173138f, -0.0003168019f, -0.0003089482f, -0.0002936908f, -0.0002711354f, + -0.0002415497f, -0.0002053687f, -0.0001631812f, -0.0001157294f, -0.0000638885f, -0.0000086610f, 0.0000488496f, 0.0001074488f, + 0.0001658824f, 0.0002228496f, 0.0002770388f, 0.0003271423f, 0.0003718955f, 0.0004100930f, 0.0004406281f, 0.0004625082f, + 0.0004748944f, 0.0004771120f, 0.0004686867f, 0.0004493486f, 0.0004190617f, 0.0003780176f, 0.0003266564f, 0.0002656483f, + 0.0001959041f, 0.0001185450f, 0.0000349034f, -0.0000535185f, -0.0001450543f, -0.0002379235f, -0.0003302403f, -0.0004200698f, + -0.0005054364f, -0.0005843853f, -0.0006549896f, -0.0007154171f, -0.0007639381f, -0.0007990015f, -0.0008192451f, -0.0008235853f, + -0.0008112325f, -0.0007817958f, -0.0007353001f, -0.0006723017f, -0.0005938949f, -0.0005018237f, -0.0003984545f, -0.0002868589f, + -0.0001707179f, -0.0000543437f, 0.0000575249f, 0.0001597921f, 0.0002473552f, 0.0003152810f, 0.0003593211f, 0.0003761803f, + 0.0003641895f, 0.0003236064f, 0.0002574060f, 0.0001714998f, 0.0000755882f, -0.0000168765f, -0.0000877911f, -0.0001149323f, + -0.0000708145f, 0.0000759664f, 0.0003632082f, 0.0008340171f, 0.0015932147f, 0.0027965684f, 0.0044938862f, 0.0066209827f, + 0.0090614394f, 0.0116532691f, 0.0142012098f, 0.0164868538f, 0.0182824288f, 0.0193635282f, 0.0195233202f, 0.0185852780f, + 0.0164156862f, 0.0129338578f, 0.0081207820f, 0.0020247377f, -0.0052355839f, -0.0134714261f, -0.0224272216f, -0.0317873061f, + -0.0411854169f, -0.0502171478f, -0.0584545493f, -0.0654627361f, -0.0708175739f, -0.0741240923f, -0.0750346389f, -0.0732663141f, + -0.0686167330f, -0.0609776578f, -0.0503456776f, -0.0368295907f, -0.0206538852f, -0.0021581782f, 0.0182077069f, 0.0398928946f, + 0.0622588452f, 0.0845965541f, 0.1061472474f, 0.1261258801f, 0.1437468496f, 0.1582510183f, 0.1689332690f, 0.1751695690f, + 0.1764426874f, 0.1723655442f, 0.1627013795f, 0.1473798510f, 0.1265084200f, 0.1003783769f, 0.0694651504f, 0.0344225859f, + -0.0039288047f, -0.0446195451f, -0.0865544564f, -0.1285410062f, -0.1693219800f, -0.2076116501f, -0.2421343744f, -0.2716645414f, + -0.2950666012f, -0.3113339711f, -0.3196255083f, -0.3192983638f, -0.3099360208f, -0.2913705151f, -0.2636979059f, -0.2272863207f, + -0.1827760335f, -0.1310713384f, -0.0733241526f, -0.0109096078f, 0.0546059294f, 0.1215036544f, 0.1879570196f, 0.2520811416f, + 0.3119856181f, 0.3658292498f, 0.4118751262f, 0.4485444179f, 0.4744672713f, 0.4885291873f, 0.4899114116f, 0.4781239515f, + 0.4530300662f, 0.4148612531f, 0.3642220549f, 0.3020842490f, 0.2297703310f, 0.1489264657f, 0.0614854435f, -0.0303795649f, + -0.1243093268f, -0.2178195955f, -0.3083672722f, -0.3934199265f, -0.4705267388f, -0.5373888894f, -0.5919273479f, -0.6323460927f, + -0.6571888364f, -0.6653875249f, -0.6563010343f, -0.6297427848f, -0.5859962378f, -0.5258176130f, -0.4504254723f, -0.3614772269f, + -0.2610329551f, -0.1515073286f, -0.0356107555f, 0.0837187871f, 0.2033915080f, 0.3202471384f, 0.4311396943f, 0.5330233362f, + 0.6230369707f, 0.6985851980f, 0.7574133141f, 0.7976741718f, 0.8179849388f, 0.8174720079f, 0.7958026627f, 0.7532024103f, + 0.6904573239f, 0.6089011023f, 0.5103870229f, 0.3972453408f, 0.2722271452f, 0.1384360281f, -0.0007506793f, -0.1417690856f, + -0.2809620112f, -0.4146758861f, -0.5393586304f, -0.6516558729f, -0.7485028256f, -0.8272092868f, -0.8855353494f, -0.9217556888f, + -0.9347105366f, -0.9238418625f, -0.8892136169f, -0.8315153830f, -0.7520491685f, -0.6526996069f, -0.5358882111f, -0.4045128580f, + -0.2618739995f, -0.1115895724f, 0.0424992034f, 0.1964285728f, 0.3462168980f, 0.4879703230f, 0.6179866516f, 0.7328545277f, + 0.8295452782f, 0.9054947981f, 0.9586733060f, 0.9876409196f, 0.9915876025f, 0.9703562358f, 0.9244482541f, 0.8550115930f, + 0.7638112998f, 0.6531839260f, 0.5259766298f, 0.3854793593f, 0.2353470917f, 0.0794266997f, -0.0783736011f, -0.2341094912f, + -0.3838855272f, -0.5239604170f, -0.6508401618f, -0.7613664334f, -0.8527950879f, -0.9228648741f, -0.9698533854f, -0.9926197484f, + -0.9906323266f, -0.9639812550f, -0.9133750995f, -0.8401220648f, -0.7460959702f, -0.6336880996f, -0.5057459675f, -0.3655007408f, + -0.2164850263f, -0.0624432571f, 0.0927631497f, 0.2452533396f, 0.3912248813f, 0.5270493663f, 0.6493633998f, 0.7551526079f, + 0.8418266049f, 0.9072829806f, 0.9499587608f, 0.9688680208f, 0.9636247817f, 0.9344506105f, 0.8821668237f, 0.8081715061f, + 0.7144020216f, 0.6032839905f, 0.4776681160f, 0.3407564859f, 0.1960202987f, 0.0471111158f, -0.1022320452f, -0.2482774188f, + -0.3873945568f, -0.5161453835f, -0.6313699144f, -0.7302645031f, -0.8104506434f, -0.8700326423f, -0.9076427350f, -0.9224725808f, + -0.9142903937f, -0.8834433701f, -0.8308454204f, -0.7579506175f, -0.6667131091f, -0.5595346127f, -0.4392008921f, -0.3088089180f, + -0.1716866150f, -0.0313073005f, 0.1087989808f, 0.2451349347f, 0.3743240333f, 0.4931948249f, 0.5988594260f, 0.6887842282f, + 0.7608510829f, 0.8134074688f, 0.8453044545f, 0.8559215759f, 0.8451781058f, 0.8135305285f, 0.7619564059f, 0.6919251500f, + 0.6053565671f, 0.5045683259f, 0.3922137963f, 0.2712119195f, 0.1446709795f, 0.0158082697f, -0.1121322505f, -0.2359621952f, + -0.3526287795f, -0.4592906218f, -0.5533874164f, -0.6327017647f, -0.6954116543f, -0.7401323484f, -0.7659467130f, -0.7724233338f, + -0.7596220816f, -0.7280871206f, -0.6788276697f, -0.6132871451f, -0.5333015981f, -0.4410486347f, -0.3389882280f, -0.2297970351f, + -0.1162979714f, -0.0013869076f, 0.1120416061f, 0.2211676650f, 0.3233165238f, 0.4160245192f, 0.4970987736f, 0.5646692200f, + 0.6172317171f, 0.6536812560f, 0.6733345403f, 0.6759414941f, 0.6616855531f, 0.6311728784f, 0.5854109229f, 0.5257770441f, + 0.4539781120f, 0.3720022713f, 0.2820642158f, 0.1865454701f, 0.0879312930f, -0.0112541288f, -0.1085124968f, -0.2014345624f, + -0.2877600257f, -0.3654326821f, -0.4326494615f, -0.4879021964f, -0.5300111477f, -0.5581495604f, -0.5718587503f, -0.5710534933f, + -0.5560177281f, -0.5273908494f, -0.4861450978f, -0.4335547859f, -0.3711582904f, -0.3007139250f, -0.2241509378f, -0.1435169935f, + -0.0609235618f, 0.0215093313f, 0.1017075454f, 0.1776950580f, 0.2476426746f, 0.3099120105f, 0.3630936929f, 0.4060388941f, + 0.4378835058f, 0.4580644620f, 0.4663279432f, 0.4627294004f, 0.4476255675f, 0.4216588257f, 0.3857344863f, 0.3409917280f, + 0.2887690825f, 0.2305654810f, 0.1679979813f, 0.1027573461f, 0.0365626923f, -0.0288835867f, -0.0919394404f, -0.1510642130f, + -0.2048561002f, -0.2520851099f, -0.2917207545f, -0.3229538699f, -0.3452121154f, -0.3581688961f, -0.3617456210f, -0.3561073997f, + -0.3416524423f, -0.3189955996f, -0.2889466186f, -0.2524838235f, -0.2107240303f, -0.1648895947f, -0.1162735377f, -0.0662037318f, + -0.0160071241f, 0.0330250452f, 0.0796701284f, 0.1228042256f, 0.1614288774f, 0.1946936678f, 0.2219142443f, 0.2425853919f, + 0.2563889487f, 0.2631964891f, 0.2630668532f, 0.2562387302f, 0.2431186436f, 0.2242647892f, 0.2003672939f, 0.1722255274f, + 0.1407231814f, 0.1068018529f, 0.0714339071f, 0.0355953755f, 0.0002396385f, -0.0337274180f, -0.0654701262f, -0.0942430905f, + -0.1194080954f, -0.1404475082f, -0.1569739116f, -0.1687358288f, -0.1756195042f, -0.1776468257f, -0.1749695713f, -0.1678602690f, + -0.1567000359f, -0.1419638484f, -0.1242037381f, -0.1040304695f, -0.0820942616f, -0.0590651422f, -0.0356134981f, -0.0123913771f, + 0.0099849609f, 0.0309507800f, 0.0500065129f, 0.0667289886f, 0.0807800207f, 0.0919121972f, 0.0999718200f, 0.1048990098f, + 0.1067250926f, 0.1055674412f, 0.1016220359f, 0.0951540418f, 0.0864867765f, 0.0759894469f, 0.0640640860f, 0.0511321002f, + 0.0376208624f, 0.0239507391f, 0.0105229429f, -0.0022914718f, -0.0141611639f, -0.0248023986f, -0.0339850878f, -0.0415368905f, + -0.0473453103f, -0.0513578334f, -0.0535801684f, -0.0540727489f, -0.0529456678f, -0.0503522968f, -0.0464818329f, -0.0415510875f, + -0.0357957930f, -0.0294617627f, -0.0227961726f, -0.0160392815f, -0.0094168137f, -0.0031332654f, 0.0026337157f, 0.0077376956f, + 0.0120665112f, 0.0155439285f, 0.0181299546f, 0.0198198008f, 0.0206416522f, 0.0206533153f, 0.0199379832f, 0.0185992414f, + 0.0167556135f, 0.0145347842f, 0.0120678335f, 0.0094835966f, 0.0069034859f, 0.0044368299f, 0.0021770482f, 0.0001986183f, + -0.0014448717f, -0.0027217639f, -0.0036221831f, -0.0041570536f, -0.0043559653f, -0.0042644747f, -0.0039403827f, -0.0034499387f, + -0.0028631090f, -0.0022496331f, -0.0016738218f, -0.0011929502f, -0.0008370454f, -0.0005846760f, -0.0004048972f, -0.0002842065f, + -0.0002119725f, -0.0001785258f, -0.0001746762f, -0.0001920559f, -0.0002230524f, -0.0002610877f, -0.0003005688f, -0.0003370221f, + -0.0003669912f, -0.0003880546f, -0.0003986770f, -0.0003981548f, -0.0003864480f, -0.0003640945f, -0.0003320500f, -0.0002916028f, + -0.0002442394f, -0.0001915781f, -0.0001352688f, -0.0000769517f, -0.0000181891f, 0.0000395524f, 0.0000949441f, 0.0001467973f, + 0.0001940871f, 0.0002359457f, 0.0002716760f, 0.0003007405f, 0.0003227698f, 0.0003375491f, 0.0003450236f, 0.0003452833f, + 0.0003385643f, 0.0003252319f, 0.0003057766f, 0.0002807946f, 0.0002509791f, 0.0002170975f, 0.0001799788f, 0.0001404893f, + 0.0000995183f, 0.0000579532f, 0.0000166659f, -0.0000235093f, -0.0000617873f, -0.0000974508f, -0.0001298571f, -0.0001584526f, + -0.0001827754f, -0.0002024649f, -0.0002172605f, -0.0002270070f, -0.0002316506f, -0.0002312399f, -0.0002259201f, -0.0002159308f, + -0.0002015976f, -0.0001833276f, -0.0001615981f, -0.0001369497f, -0.0001099729f, -0.0000812980f, -0.0000515797f, -0.0000214856f, + 0.0000083213f, 0.0000371946f, 0.0000645215f, 0.0000897344f, 0.0001123264f, 0.0001318594f, 0.0001479763f, 0.0001604052f, + 0.0001689663f, 0.0001735714f, 0.0001742252f, 0.0001710200f, 0.0001641324f, 0.0001538135f, 0.0001403825f, 0.0001242143f, + 0.0001057308f, 0.0000853884f, 0.0000636683f, 0.0000410646f, 0.0000180754f, -0.0000048078f, -0.0000271075f, -0.0000483697f, + -0.0000681699f, -0.0000861206f, -0.0001018770f, -0.0001151429f, -0.0001256753f, -0.0001332891f, -0.0001378602f, -0.0001393293f, + -0.0001377022f, -0.0001330520f, -0.0001255166f, -0.0001152976f, -0.0001026555f, -0.0000879046f, -0.0000714049f, -0.0000535546f, + -0.0000347786f, -0.0000155193f, 0.0000037762f, 0.0000226667f, 0.0000407288f, 0.0000575664f, 0.0000728215f, 0.0000861808f, + 0.0000582411f, 0.0000747547f, 0.0000898871f, 0.0001032552f, 0.0001145066f, 0.0001233290f, 0.0001294588f, 0.0001326885f, + 0.0001328735f, 0.0001299377f, 0.0001238768f, 0.0001147609f, 0.0001027340f, 0.0000880132f, 0.0000708843f, 0.0000516966f, + 0.0000308558f, 0.0000088150f, -0.0000139353f, -0.0000368781f, -0.0000594822f, -0.0000812142f, -0.0001015508f, -0.0001199912f, + -0.0001360692f, -0.0001493631f, -0.0001595073f, -0.0001661997f, -0.0001692106f, -0.0001683879f, -0.0001636621f, -0.0001550493f, + -0.0001426526f, -0.0001266610f, -0.0001073481f, -0.0000850672f, -0.0000602464f, -0.0000333807f, -0.0000050232f, 0.0000242254f, + 0.0000537286f, 0.0000828270f, 0.0001108523f, 0.0001371418f, 0.0001610527f, 0.0001819781f, 0.0001993603f, 0.0002127056f, + 0.0002215967f, 0.0002257043f, 0.0002247967f, 0.0002187482f, 0.0002075440f, 0.0001912841f, 0.0001701836f, 0.0001445712f, + 0.0001148842f, 0.0000816622f, 0.0000455367f, 0.0000072204f, -0.0000325082f, -0.0000728185f, -0.0001128466f, -0.0001517120f, + -0.0001885378f, -0.0002224679f, -0.0002526873f, -0.0002784386f, -0.0002990404f, -0.0003139008f, -0.0003225330f, -0.0003245650f, + -0.0003197504f, -0.0003079739f, -0.0002892583f, -0.0002637651f, -0.0002317973f, -0.0001937968f, -0.0001503441f, -0.0001021521f, + -0.0000500632f, 0.0000049600f, 0.0000618411f, 0.0001194039f, 0.0001763844f, 0.0002314533f, 0.0002832366f, 0.0003303508f, + 0.0003714378f, 0.0004052165f, 0.0004305340f, 0.0004464367f, 0.0004522372f, 0.0004476003f, 0.0004326187f, 0.0004079029f, + 0.0003746497f, 0.0003347161f, 0.0002906568f, 0.0002457555f, 0.0002040014f, 0.0001700503f, 0.0001491128f, 0.0001468223f, + 0.0001690255f, 0.0002215535f, 0.0003099526f, 0.0004392070f, 0.0006136491f, 0.0008369098f, 0.0011153908f, 0.0014626641f, + 0.0018595375f, 0.0022395932f, 0.0025311249f, 0.0026688715f, 0.0025944027f, 0.0022604100f, 0.0016336976f, 0.0006981998f, + -0.0005431676f, -0.0020672947f, -0.0038308355f, -0.0057710271f, -0.0078076165f, -0.0098456303f, -0.0117790591f, -0.0134951832f, + -0.0148794917f, -0.0158209062f, -0.0162171833f, -0.0159802046f, -0.0150409946f, -0.0133541921f, -0.0109018245f, -0.0076961552f, + -0.0037814932f, 0.0007651902f, 0.0058348824f, 0.0112884531f, 0.0169598389f, 0.0226604555f, 0.0281847079f, 0.0333164681f, + 0.0378363117f, 0.0415293031f, 0.0441930617f, 0.0456458479f, 0.0457343703f, 0.0443410397f, 0.0413903773f, 0.0368543265f, + 0.0307562218f, 0.0231732263f, 0.0142370712f, 0.0041330029f, -0.0069031215f, -0.0185895710f, -0.0306052464f, -0.0425978140f, + -0.0541932843f, -0.0650067808f, -0.0746542114f, -0.0827644992f, -0.0889920115f, -0.0930287926f, -0.0946162074f, -0.0935555973f, + -0.0897175729f, -0.0830495883f, -0.0735814928f, -0.0614287943f, -0.0467934430f, -0.0299620019f, -0.0113011569f, 0.0087494102f, + 0.0296866709f, 0.0509562355f, 0.0719663997f, 0.0921039151f, 0.1107510726f, 0.1273036411f, 0.1411891551f, 0.1518850212f, + 0.1589358970f, 0.1619698015f, 0.1607124306f, 0.1549991925f, 0.1447845216f, 0.1301481022f, 0.1112977047f, 0.0885684336f, + 0.0624182781f, 0.0334199675f, 0.0022492343f, -0.0303302958f, -0.0634852726f, -0.0963334260f, -0.1279665024f, -0.1574747445f, + -0.1839722700f, -0.2066226519f, -0.2246639837f, -0.2374326975f, -0.2443854241f, -0.2451182136f, -0.2393824923f, -0.2270972049f, + -0.2083566840f, -0.1834338958f, -0.1527788314f, -0.1170119438f, -0.0769126672f, -0.0334031935f, 0.0124721800f, 0.0595716856f, + 0.1066841340f, 0.1525596967f, 0.1959426466f, 0.2356052084f, 0.2703816159f, 0.2992014435f, 0.3211212759f, 0.3353538037f, + 0.3412934754f, 0.3385379160f, 0.3269044144f, 0.3064409015f, 0.2774309795f, 0.2403927139f, 0.1960710651f, 0.1454240053f, + 0.0896025447f, 0.0299250576f, -0.0321535327f, -0.0950769985f, -0.1572266359f, -0.2169627100f, -0.2726674612f, -0.3227885475f, + -0.3658817647f, -0.4006518763f, -0.4259904152f, -0.4410093734f, -0.4450697851f, -0.4378043259f, -0.4191331941f, -0.3892727036f, + -0.3487362065f, -0.2983271575f, -0.2391243433f, -0.1724595094f, -0.0998878249f, -0.0231518277f, 0.0558603212f, 0.1351612774f, + 0.2127145048f, 0.2864865610f, 0.3545003342f, 0.4148878376f, 0.4659411557f, 0.5061601567f, 0.5342956523f, 0.5493867774f, + 0.5507914983f, 0.5382093212f, 0.5116954608f, 0.4716659463f, 0.4188933721f, 0.3544932422f, 0.2799011075f, 0.1968409421f, + 0.1072854415f, 0.0134091535f, -0.0824644450f, -0.1779206367f, -0.2705144779f, -0.3578335937f, -0.4375611342f, -0.5075372480f, + -0.5658174366f, -0.6107262192f, -0.6409046287f, -0.6553502097f, -0.6534483577f, -0.6349940579f, -0.6002033141f, -0.5497138242f, + -0.4845747300f, -0.4062255582f, -0.3164647475f, -0.2174084443f, -0.1114405017f, -0.0011548715f, 0.1107082189f, 0.2213307209f, + 0.3278881365f, 0.4276219846f, 0.5179114992f, 0.5963426829f, 0.6607728958f, 0.7093892437f, 0.7407591825f, 0.7538719283f, + 0.7481694943f, 0.7235664280f, 0.6804576085f, 0.6197137625f, 0.5426646818f, 0.4510704345f, 0.3470811862f, 0.2331865442f, + 0.1121556241f, -0.0130307134f, -0.1392537831f, -0.2633353122f, -0.3821180118f, -0.4925464326f, -0.5917460154f, -0.6770982854f, + -0.7463102071f, -0.7974758632f, -0.8291287887f, -0.8402835311f, -0.8304652631f, -0.7997265817f, -0.7486509433f, -0.6783425346f, + -0.5904027183f, -0.4868935511f, -0.3702891985f, -0.2434164031f, -0.1093854415f, 0.0284867240f, 0.1667591937f, 0.3019536886f, + 0.4306427342f, 0.5495372068f, 0.6555710008f, 0.7459806116f, 0.8183775659f, 0.8708117817f, 0.9018241781f, 0.9104871053f, + 0.8964314857f, 0.8598598737f, 0.8015450208f, 0.7228138795f, 0.6255173800f, 0.5119866531f, 0.3849767570f, 0.2475992600f, + 0.1032453598f, -0.0444985629f, -0.1919408168f, -0.3353774466f, -0.4711860685f, -0.5959181193f, -0.7063871285f, -0.7997507598f, + -0.8735844695f, -0.9259448860f, -0.9554212155f, -0.9611733371f, -0.9429555253f, -0.9011251664f, -0.8366361515f, -0.7510170890f, + -0.6463347988f, -0.5251440036f, -0.3904244118f, -0.2455067964f, -0.0939898753f, 0.0603498686f, 0.2136531983f, 0.3620754993f, + 0.5018841040f, 0.6295530127f, 0.7418526589f, 0.8359323337f, 0.9093932351f, 0.9603501538f, 0.9874803034f, 0.9900578955f, + 0.9679736807f, 0.9217387716f, 0.8524727897f, 0.7618764115f, 0.6521892146f, 0.5261336069f, 0.3868465674f, 0.2378005415f, + 0.0827159689f, -0.0745329240f, -0.2300158926f, -0.3798465481f, -0.5202802756f, -0.6478099233f, -0.7592521853f, -0.8518447888f, + -0.9233379834f, -0.9720085218f, -0.9966758999f, -0.9967463299f, -0.9722295329f, -0.9237392201f, -0.8524778646f, -0.7602073639f, + -0.6492055631f, -0.5222103755f, -0.3823523682f, -0.2330778865f, -0.0780642593f, 0.0788705421f, 0.2338618240f, 0.3830931459f, + 0.5228902075f, 0.6498111734f, 0.7607313594f, 0.8529200672f, 0.9241077914f, 0.9725420391f, 0.9970304792f, 0.9969702721f, + 0.9723629327f, 0.9238142869f, 0.8525195846f, 0.7602340753f, 0.6492298214f, 0.5222397619f, 0.3823904496f, 0.2331250710f, + 0.0781186890f, -0.0788122482f, -0.2338038630f, -0.3830399929f, -0.5228461462f, -0.6497799862f, -0.7607160866f, -0.8529228980f, + -0.9241300035f, -0.9725840329f, -0.9970918334f, -0.9970498578f, -0.9724590238f, -0.9239246994f, -0.8526417953f, -0.7603653504f, + -0.6493673160f, -0.5223806210f, -0.3825318778f, -0.2332644031f, -0.0782534324f, 0.0786843684f, 0.2336848810f, 0.3829316749f, + 0.5227499799f, 0.6496971643f, 0.7606475046f, 0.8528691455f, 0.9240913688f, 0.9725605024f, 0.9970831041f, 0.9970553461f, + 0.9724778870f, 0.9239558554f, 0.8526839539f, 0.7604170426f, 0.6494269334f, 0.5224464521f, 0.3826021525f, 0.2333373314f, + 0.0783272488f, -0.0786113681f, -0.2336143011f, -0.3828649893f, -0.5226885022f, -0.6496420279f, -0.7605996436f, -0.8528292862f, + -0.9240600225f, -0.9725379675f, -0.9970694696f, -0.9970505028f, -0.9724815391f, -0.9239675382f, -0.8527030511f, -0.7604428078f, + -0.6494585103f, -0.5224828981f, -0.3826424594f, -0.2333804494f, -0.0783721069f, 0.0785658395f, 0.2335691502f, 0.3828212223f, + 0.5226470656f, 0.6496037895f, 0.7605653778f, 0.8527996583f, 0.9240355773f, 0.9725191181f, 0.9970564910f, 0.9970435264f, + 0.9724805522f, 0.9239723853f, 0.8527134405f, 0.7604583197f, 0.6494786105f, 0.5225069525f, 0.3826697534f, 0.2334102074f, + 0.0784035151f, -0.0785336112f, -0.2335369252f, -0.3827897961f, -0.5226171847f, -0.6495761346f, -0.7605405475f, -0.8527781579f, + -0.9240178096f, -0.9725053787f, -0.9970469656f, -0.9970382927f, -0.9724795834f, -0.9239755567f, -0.8527205369f, -0.7604690457f, + -0.6494926000f, -0.5225237804f, -0.3826889457f, -0.2334312532f, -0.0784258768f, 0.0785104868f, 0.2335135965f, 0.3827668158f, + 0.5225950899f, 0.6495554361f, 0.7605217198f, 0.8527616288f, 0.9240039504f, 0.9724944950f, 0.9970392893f, 0.9970339749f, + 0.9724786893f, 0.9239780624f, 0.8527263292f, 0.7604779239f, 0.6495042812f, 0.5225379070f, 0.3827050967f, 0.2334489562f, + 0.0784446231f, -0.0784912259f, -0.2334943534f, -0.3827481104f, -0.5225774136f, -0.6495392378f, -0.7605073937f, -0.8527495050f, + -0.9239942880f, -0.9724874781f, -0.9970350256f, -0.9970324969f, -0.9724799577f, -0.9239819717f, -0.8527327136f, -0.7604865652f, + -0.6495149161f, -0.5225502352f, -0.3827187881f, -0.2334636585f, -0.0784599687f, 0.0784756139f, 0.2334788543f, 0.3827330998f, + 0.5225632570f, 0.6495262837f, 0.7604959669f, 0.8527398987f, 0.9239867563f, 0.9724822286f, 0.9970322117f, +}; + +const float ivas_fb_fr_12band_1ms_im[IVAS_FB_12_1MS_LEN] = +{ + -0.0898684611f, -0.2670421131f, -0.4365041728f, -0.5932908852f, -0.7325431118f, -0.8497696909f, -0.9406026758f, -1.0013422309f, + -1.0229026702f, -0.9881074062f, -0.8887876846f, -0.7310424395f, -0.5284210279f, -0.2997529481f, -0.0664760115f, 0.1499611207f, + 0.3307974571f, 0.4621685196f, 0.5367125342f, 0.5543493827f, 0.5220560680f, 0.4529408018f, 0.3642519877f, 0.2760859332f, + 0.2047354522f, 0.1503391462f, 0.1061445796f, 0.0699189586f, 0.0406773254f, 0.0176462883f, 0.0000989137f, -0.0126721698f, + -0.0213825135f, -0.0267263252f, -0.0293754264f, -0.0299501298f, -0.0290147562f, -0.0270589183f, -0.0244976437f, -0.0216640086f, + -0.0188153473f, -0.0161349368f, -0.0137427038f, -0.0117024055f, -0.0100340803f, -0.0087231409f, -0.0077319011f, -0.0070077840f, + -0.0064920884f, -0.0061256992f, -0.0058543602f, -0.0056314631f, -0.0054200843f, -0.0051933287f, -0.0049340271f, -0.0046335801f, + -0.0042904244f, -0.0039083723f, -0.0034948095f, -0.0030592765f, -0.0026120102f, -0.0021631376f, -0.0017217846f, -0.0012959083f, + -0.0008918976f, -0.0005148542f, -0.0001684643f, 0.0001445255f, 0.0004223858f, 0.0006639324f, 0.0008686856f, 0.0010364896f, + 0.0011677783f, 0.0012632724f, 0.0013243012f, 0.0013525145f, 0.0013501876f, 0.0013198910f, 0.0012647346f, 0.0011879780f, + 0.0010932175f, 0.0009839640f, 0.0008638145f, 0.0007360481f, 0.0006038306f, 0.0004698724f, 0.0003366939f, 0.0002063576f, + 0.0000807864f, -0.0000384546f, -0.0001498232f, -0.0002520137f, -0.0003436527f, -0.0004235485f, -0.0004904478f, -0.0005433364f, + -0.0005812551f, -0.0006036329f, -0.0006101286f, -0.0006009525f, -0.0005766848f, -0.0005385389f, -0.0004881156f, -0.0004275804f, + -0.0003593427f, -0.0002861534f, -0.0002107341f, -0.0001358351f, -0.0000638656f, 0.0000030299f, 0.0000632842f, 0.0001157628f, + 0.0001599820f, 0.0001958747f, 0.0002239118f, 0.0002447961f, 0.0002595218f, 0.0002690444f, 0.0002743352f, 0.0002760865f, + 0.0002748168f, 0.0002706555f, 0.0002635301f, 0.0002530421f, 0.0002387283f, 0.0002200029f, 0.0001964510f, 0.0001677833f, + 0.0001341045f, 0.0000958227f, 0.0000538421f, 0.0000093907f, -0.0000358838f, -0.0000801695f, -0.0001214720f, -0.0001579178f, + -0.0001877626f, -0.0002096837f, -0.0002227536f, -0.0002266623f, -0.0002216081f, -0.0002084174f, -0.0001883368f, -0.0001630566f, + -0.0001344297f, -0.0001044404f, -0.0000749065f, -0.0000474557f, -0.0000232739f, -0.0000031484f, 0.0000126922f, 0.0000244381f, + 0.0000327553f, 0.0000385592f, 0.0000429983f, 0.0000471857f, 0.0000521670f, 0.0000586725f, 0.0000671313f, 0.0000774992f, + 0.0000893598f, 0.0001018532f, 0.0001138697f, 0.0001240625f, 0.0001311002f, 0.0001337149f, 0.0001309532f, 0.0001221967f, + 0.0001073512f, 0.0000867866f, 0.0000614274f, 0.0000325927f, 0.0000019882f, -0.0000285322f, -0.0000570333f, -0.0000817625f, + -0.0001012133f, -0.0001143489f, -0.0001206018f, + 0.0115080962f, 0.0339059662f, 0.0543805639f, 0.0716908215f, 0.0844892131f, 0.0915170903f, 0.0912773099f, 0.0825231458f, + 0.0581340647f, 0.0023722407f, -0.0920729561f, -0.2188408880f, -0.3647527624f, -0.5119701616f, -0.6406838355f, -0.7316665697f, + -0.7689724827f, -0.7420606704f, -0.6473949518f, -0.4890788171f, -0.2786409816f, -0.0338325103f, 0.2232845090f, 0.4688402469f, + 0.6798489622f, 0.8368463063f, 0.9260768759f, 0.9410292369f, 0.8830777791f, 0.7612013021f, 0.5907780504f, 0.3916368742f, + 0.1855876370f, -0.0062576017f, -0.1660331877f, -0.2812632874f, -0.3462706324f, -0.3628576835f, -0.3399405921f, -0.2936025661f, + -0.2446360780f, -0.2029515435f, -0.1662608743f, -0.1331801236f, -0.1036965299f, -0.0778301527f, -0.0556266777f, -0.0370208473f, + -0.0218709516f, -0.0099359945f, -0.0009127909f, 0.0055587915f, 0.0098621029f, 0.0123923627f, 0.0135300104f, 0.0136320444f, + 0.0130144200f, 0.0119494969f, 0.0106574266f, 0.0093099072f, 0.0080287757f, 0.0068943240f, 0.0059483248f, 0.0052043487f, + 0.0046523406f, 0.0042685237f, 0.0040192551f, 0.0038688810f, 0.0037816102f, 0.0037267014f, 0.0036781232f, 0.0036173442f, + 0.0035313060f, 0.0034136237f, 0.0032617350f, 0.0030774362f, 0.0028640174f, 0.0026268424f, 0.0023709699f, 0.0021021154f, + 0.0018248805f, 0.0015440826f, 0.0012634327f, 0.0009870117f, 0.0007181238f, 0.0004606754f, 0.0002179850f, -0.0000060719f, + -0.0002083660f, -0.0003855837f, -0.0005355681f, -0.0006564697f, -0.0007479765f, -0.0008103905f, -0.0008456256f, -0.0008561209f, + -0.0008455816f, -0.0008177548f, -0.0007769991f, -0.0007270455f, -0.0006715492f, -0.0006129898f, -0.0005533521f, -0.0004932746f, + -0.0004329280f, -0.0003714208f, -0.0003078363f, -0.0002408007f, -0.0001695470f, -0.0000934908f, -0.0000131639f, 0.0000703507f, + 0.0001547277f, 0.0002371760f, 0.0003140053f, 0.0003815783f, 0.0004360445f, 0.0004743392f, 0.0004939265f, 0.0004936813f, + 0.0004734847f, 0.0004348607f, 0.0003803348f, 0.0003137905f, 0.0002396098f, 0.0001628232f, 0.0000881507f, 0.0000200989f, + -0.0000379279f, -0.0000834126f, -0.0001153958f, -0.0001340265f, -0.0001409462f, -0.0001385916f, -0.0001303365f, -0.0001196396f, + -0.0001100798f, -0.0001045123f, -0.0001051708f, -0.0001129953f, -0.0001279408f, -0.0001485750f, -0.0001726416f, -0.0001969197f, + -0.0002179800f, -0.0002321940f, -0.0002365365f, -0.0002285757f, -0.0002071506f, -0.0001721838f, -0.0001251084f, -0.0000684218f, + -0.0000058329f, 0.0000584158f, 0.0001195994f, 0.0001732950f, 0.0002154726f, 0.0002432129f, 0.0002546651f, 0.0002495466f, + 0.0002438301f, 0.0007109472f, 0.0011162460f, 0.0013967943f, 0.0014698785f, 0.0012150300f, 0.0004822469f, -0.0009199449f, + -0.0032069948f, -0.0066234807f, -0.0114150534f, -0.0178284637f, -0.0260733522f, -0.0363216183f, -0.0486605071f, -0.0630990061f, + -0.0795130312f, -0.0976712096f, -0.1171685259f, -0.1374957541f, -0.1579441550f, -0.1777994651f, -0.1961712153f, -0.2131191727f, + -0.2256033924f, -0.2176912218f, -0.1719241079f, -0.0821949125f, 0.0489542717f, 0.2117008349f, 0.3903676656f, 0.5654257562f, + 0.7160273175f, 0.8226483779f, 0.8696490849f, 0.8473276976f, 0.7533117569f, 0.5930248684f, 0.3792476318f, 0.1307497118f, + -0.1297731860f, -0.3782729365f, -0.5920556328f, -0.7523549294f, -0.8463947331f, -0.8687564040f, -0.8218173622f, -0.7152833962f, + -0.5647972104f, -0.3898836504f, -0.2113895751f, -0.0488408019f, 0.0820902688f, 0.1715873934f, 0.2171153181f, 0.2247885078f, + 0.2120719043f, 0.1949040588f, 0.1763288922f, 0.1562894837f, 0.1356771490f, 0.1152063262f, 0.0955845402f, 0.0773202283f, + 0.0608172272f, 0.0463072409f, 0.0339148674f, 0.0236334444f, 0.0153777062f, 0.0089786185f, 0.0042273050f, 0.0008767894f, + -0.0013231927f, -0.0026245282f, -0.0032557343f, -0.0034239005f, -0.0032991260f, -0.0030209159f, -0.0026903446f, -0.0023798808f, + -0.0021307088f, -0.0019640207f, -0.0018807705f, -0.0018724257f, -0.0019209336f, -0.0020075151f, -0.0021115303f, -0.0022167724f, + -0.0023088853f, -0.0023794235f, -0.0024222081f, -0.0024359169f, -0.0024201044f, -0.0023771902f, -0.0023088214f, -0.0022179019f, + -0.0021056723f, -0.0019740384f, -0.0018233675f, -0.0016550209f, -0.0014695894f, -0.0012693378f, -0.0010565212f, -0.0008354568f, + -0.0006106656f, -0.0003884494f, -0.0001748112f, 0.0000233719f, 0.0002004956f, 0.0003512145f, 0.0004724032f, 0.0005620267f, + 0.0006206994f, 0.0006502675f, 0.0006548938f, 0.0006393557f, 0.0006097638f, 0.0005717449f, 0.0005310334f, 0.0004917912f, + 0.0004573339f, 0.0004288066f, 0.0004062166f, 0.0003875516f, 0.0003701287f, 0.0003500723f, 0.0003238297f, 0.0002877917f, + 0.0002397329f, 0.0001783203f, 0.0001042514f, 0.0000194643f, -0.0000721397f, -0.0001658244f, -0.0002556635f, -0.0003358859f, + -0.0004006984f, -0.0004456200f, -0.0004672301f, -0.0004642525f, -0.0004370215f, -0.0003881655f, -0.0003217097f, -0.0002433639f, + -0.0001593403f, -0.0000763999f, -0.0000005923f, 0.0000626983f, 0.0001098436f, 0.0001386930f, 0.0001493084f, 0.0001433260f, + 0.0001242838f, 0.0000966497f, 0.0000658480f, 0.0000371218f, 0.0000154755f, 0.0000046144f, 0.0000070450f, 0.0000233058f, + 0.0000523967f, 0.0000914031f, 0.0001362820f, 0.0001818299f, 0.0002227029f, 0.0002535449f, 0.0002700191f, 0.0002688537f, + 0.0002486530f, 0.0002096567f, 0.0001541806f, 0.0000860074f, 0.0000104494f, -0.0000665586f, -0.0001386343f, -0.0001999605f, + -0.0002454664f, -0.0002717048f, -0.0002768116f, -0.0002610555f, -0.0002264389f, -0.0001768539f, -0.0001173333f, -0.0000538987f, + 0.0000073883f, 0.0000606831f, 0.0001012735f, 0.0001257023f, 0.0001324276f, 0.0001216280f, 0.0000954836f, 0.0000576109f, + 0.0000129868f, -0.0000328906f, -0.0000742744f, -0.0001060758f, -0.0001240987f, -0.0001257785f, -0.0001101631f, -0.0000783123f, + -0.0000329127f, 0.0000217021f, 0.0000802673f, 0.0001368394f, 0.0001856737f, 0.0002215380f, 0.0002405175f, 0.0002401550f, + 0.0002199754f, 0.0001812890f, 0.0001273345f, 0.0000627166f, -0.0000067866f, -0.0000750345f, -0.0001358771f, + -0.0002517773f, -0.0007530438f, -0.0012480393f, -0.0017311495f, -0.0021966783f, -0.0026372659f, -0.0030463219f, -0.0034173391f, + -0.0037471961f, -0.0040359970f, -0.0042905892f, -0.0045239611f, -0.0047578551f, -0.0050204690f, -0.0053469980f, -0.0057745962f, + -0.0063401820f, -0.0070723578f, -0.0079867916f, -0.0090758990f, -0.0103033224f, -0.0115933185f, -0.0128269170f, -0.0138337134f, + -0.0143928060f, -0.0142296836f, -0.0130247299f, -0.0104168701f, -0.0060212390f, 0.0005608679f, 0.0097154142f, 0.0218030935f, + 0.0371260945f, 0.0559219991f, 0.0783277405f, 0.1044019092f, 0.1340918009f, 0.1673695867f, 0.2042412889f, 0.2460845096f, + 0.2951830943f, 0.3416235468f, 0.3646126368f, 0.3480671745f, 0.2830729765f, 0.1678292828f, 0.0080159731f, -0.1838899497f, + -0.3900215384f, -0.5892675140f, -0.7598185700f, -0.8818480868f, -0.9399786297f, -0.9252325823f, -0.8362335185f, -0.6794898766f, + -0.4687496028f, -0.2234686369f, 0.0333794198f, 0.2779351658f, 0.4881469775f, 0.6462666955f, 0.7407620319f, 0.7675102118f, + 0.7300140555f, 0.6387574230f, 0.5096096451f, 0.3616936194f, 0.2146955649f, 0.0863068159f, -0.0104489874f, -0.0693762132f, + -0.0979362074f, -0.1120025953f, -0.1187847101f, -0.1195709435f, -0.1158142700f, -0.1086494413f, -0.0991759892f, -0.0882830476f, + -0.0767682730f, -0.0652504848f, -0.0542380863f, -0.0440837698f, -0.0350361951f, -0.0272194074f, -0.0206775342f, -0.0153683003f, + -0.0112022098f, -0.0080423433f, -0.0057368530f, -0.0041194819f, -0.0030341283f, -0.0023328322f, -0.0018922260f, -0.0016079045f, + -0.0014038691f, -0.0012238901f, -0.0010359885f, -0.0008223621f, -0.0005812568f, -0.0003172104f, -0.0000423446f, 0.0002317528f, + 0.0004920317f, 0.0007298898f, 0.0009380570f, 0.0011144792f, 0.0012583706f, 0.0013727541f, 0.0014603320f, 0.0015255024f, + 0.0015706934f, 0.0015984889f, 0.0016087944f, 0.0016013362f, 0.0015736524f, 0.0015238602f, 0.0014491647f, 0.0013485610f, + 0.0012214393f, 0.0010698662f, 0.0008969515f, 0.0007085113f, 0.0005110819f, 0.0003130098f, 0.0001222403f, -0.0000529128f, + -0.0002059168f, -0.0003312324f, -0.0004261003f, -0.0004894620f, -0.0005232055f, -0.0005306961f, -0.0005175051f, -0.0004896578f, + -0.0004540531f, -0.0004166844f, -0.0003830510f, -0.0003566394f, -0.0003395923f, -0.0003316443f, -0.0003311733f, -0.0003346124f, + -0.0003378214f, -0.0003358194f, -0.0003242611f, -0.0002992259f, -0.0002585275f, -0.0002012956f, -0.0001289055f, -0.0000441984f, + 0.0000480368f, 0.0001421911f, 0.0002316974f, 0.0003103339f, 0.0003721995f, 0.0004129378f, 0.0004295640f, 0.0004213762f, + 0.0003894462f, 0.0003371019f, 0.0002690431f, 0.0001914421f, 0.0001108048f, 0.0000338794f, -0.0000335063f, -0.0000864746f, + -0.0001220386f, -0.0001388528f, -0.0001377697f, -0.0001212160f, -0.0000933503f, -0.0000591266f, -0.0000241894f, 0.0000061837f, + 0.0000272190f, 0.0000355810f, 0.0000293086f, 0.0000084300f, -0.0000254463f, -0.0000689080f, -0.0001174917f, -0.0001657726f, + -0.0002083169f, -0.0002398873f, -0.0002563684f, -0.0002548515f, -0.0002343135f, -0.0001953996f, -0.0001407304f, -0.0000743265f, + -0.0000015627f, 0.0000716768f, 0.0001392424f, 0.0001956345f, 0.0002362192f, 0.0002579841f, 0.0002595163f, 0.0002414285f, + -0.0000940837f, -0.0002770282f, -0.0004449239f, -0.0005888728f, -0.0007019644f, -0.0007792340f, -0.0008182743f, -0.0008186617f, + -0.0007820794f, -0.0007112881f, -0.0006099783f, -0.0004815832f, -0.0003292359f, -0.0001547948f, 0.0000407443f, 0.0002577725f, + 0.0004970701f, 0.0007599305f, 0.0010467681f, 0.0013572172f, 0.0016888066f, 0.0020376007f, 0.0023974682f, 0.0027617602f, + 0.0031234670f, 0.0034780578f, 0.0038243130f, 0.0041678751f, 0.0045219223f, 0.0049104098f, 0.0053672600f, 0.0059379719f, + 0.0066758931f, 0.0076410668f, 0.0088925844f, 0.0104843046f, 0.0124532460f, 0.0148130444f, 0.0175396030f, 0.0205645423f, + 0.0237604835f, 0.0269378529f, 0.0298327415f, 0.0321108152f, 0.0333602127f, 0.0331056565f, 0.0308069668f, 0.0258845713f, + 0.0177205355f, 0.0056930577f, -0.0108298743f, -0.0324583065f, -0.0598208742f, -0.0935922245f, -0.1346769337f, -0.1852485101f, + -0.2520452044f, -0.3349618030f, -0.4178137014f, -0.4806851731f, -0.5066093847f, -0.4828480682f, -0.4029110854f, -0.2674540766f, + -0.0845343107f, 0.1312173509f, 0.3601564597f, 0.5799075204f, 0.7679640489f, 0.9043772480f, 0.9741394604f, 0.9690106520f, + 0.8885379519f, 0.7401510478f, 0.5383256422f, 0.3028982916f, 0.0567716151f, -0.1767567296f, -0.3766491619f, -0.5265275449f, + -0.6164139497f, -0.6437430944f, -0.6133407543f, -0.5366180838f, -0.4297512054f, -0.3115454630f, -0.2005356394f, -0.1128598350f, + -0.0539105809f, -0.0139443690f, 0.0156565191f, 0.0370291041f, 0.0516278850f, 0.0605689917f, 0.0649188950f, 0.0656033918f, + 0.0635061831f, 0.0593951272f, 0.0539682831f, 0.0478045414f, 0.0413946012f, 0.0351122976f, 0.0292427409f, 0.0239693774f, + 0.0194022319f, 0.0155752485f, 0.0124736580f, 0.0100363326f, 0.0081800382f, 0.0068024870f, 0.0058015196f, 0.0050760480f, + 0.0045392915f, 0.0041164842f, 0.0037525515f, 0.0034068962f, 0.0030568884f, 0.0026909558f, 0.0023097105f, 0.0019188491f, + 0.0015296237f, 0.0011527869f, 0.0007995822f, 0.0004773732f, 0.0001916221f, -0.0000568089f, -0.0002688493f, -0.0004487434f, + -0.0006009421f, -0.0007311394f, -0.0008434559f, -0.0009415801f, -0.0010266406f, -0.0010987560f, -0.0011556747f, -0.0011947058f, + -0.0012119146f, -0.0012041634f, -0.0011684945f, -0.0011039351f, -0.0010107180f, -0.0008915962f, -0.0007507109f, -0.0005943565f, + -0.0004295220f, -0.0002642519f, -0.0001060642f, 0.0000378186f, 0.0001618981f, 0.0002620189f, 0.0003364193f, 0.0003850258f, + 0.0004100438f, 0.0004149209f, 0.0004045652f, 0.0003841255f, 0.0003590482f, 0.0003339070f, 0.0003125425f, 0.0002971555f, + 0.0002887091f, 0.0002863958f, 0.0002883494f, 0.0002914552f, 0.0002922766f, 0.0002870530f, 0.0002726535f, 0.0002465517f, + 0.0002076047f, 0.0001558242f, 0.0000928493f, 0.0000214333f, -0.0000544032f, -0.0001301223f, -0.0002007286f, -0.0002616070f, + -0.0003086144f, -0.0003388183f, -0.0003504396f, -0.0003433413f, -0.0003187137f, -0.0002792588f, -0.0002286183f, -0.0001713141f, + -0.0001120267f, -0.0000554389f, + -0.0001958521f, -0.0002037772f, -0.0001928163f, -0.0001589424f, -0.0001002894f, -0.0000163380f, 0.0000907887f, 0.0002175831f, + 0.0003582211f, 0.0005062409f, 0.0006538405f, 0.0007937851f, 0.0009186699f, 0.0010227885f, 0.0011010838f, 0.0011507705f, + 0.0011698159f, 0.0011582816f, 0.0011163741f, 0.0010456753f, 0.0009469803f, 0.0008217234f, 0.0006698794f, 0.0004918730f, + 0.0002867091f, 0.0000544686f, -0.0002054280f, -0.0004913183f, -0.0008012958f, -0.0011303304f, -0.0014731078f, -0.0018216574f, + -0.0021695528f, -0.0025102922f, -0.0028430159f, -0.0031713537f, -0.0035102261f, -0.0038841898f, -0.0043342737f, -0.0049142608f, + -0.0056961483f, -0.0067625723f, -0.0082096287f, -0.0101339707f, -0.0126325271f, -0.0157836972f, -0.0196448900f, -0.0242284914f, + -0.0294998526f, -0.0353498489f, -0.0415975524f, -0.0479616035f, -0.0540728812f, -0.0594457699f, -0.0635064362f, -0.0655612395f, + -0.0648457799f, -0.0604784184f, -0.0515339488f, -0.0369448838f, -0.0155927126f, 0.0139806398f, 0.0539164770f, 0.1128370459f, + 0.2004901808f, 0.3114870438f, 0.4296920027f, 0.5365714345f, 0.6133195725f, 0.6437584042f, 0.6164735032f, 0.5266348467f, + 0.3768028330f, 0.1769504498f, -0.0565487403f, -0.3026608074f, -0.5380905144f, -0.7399360850f, -0.8883601949f, -0.9688847331f, + -0.9740762507f, -0.9043827765f, -0.7680389511f, -0.5800469251f, -0.3603504723f, -0.1314519403f, 0.0842759659f, 0.2671900601f, + 0.4026590428f, 0.4826236485f, 0.5064248335f, 0.4805483640f, 0.4177275519f, 0.3349242893f, 0.2520497692f, 0.1852850777f, + 0.1347332064f, 0.0936551449f, 0.0598782099f, 0.0325001596f, 0.0108498369f, -0.0056970597f, -0.0177459594f, -0.0259244265f, + -0.0308505634f, -0.0331397240f, -0.0333704132f, -0.0320833599f, -0.0297560793f, -0.0268041178f, -0.0235666816f, -0.0203132117f, + -0.0172390062f, -0.0144767230f, -0.0120991121f, -0.0101332076f, -0.0085666335f, -0.0073617255f, -0.0064621794f, -0.0058047936f, + -0.0053242015f, -0.0049609363f, -0.0046632383f, -0.0043912873f, -0.0041162231f, -0.0038213107f, -0.0034990867f, -0.0031507115f, + -0.0027824416f, -0.0024044438f, -0.0020276438f, -0.0016629392f, -0.0013190459f, -0.0010025416f, -0.0007168319f, -0.0004629763f, + -0.0002395008f, -0.0000436500f, 0.0001284164f, 0.0002803877f, 0.0004156585f, 0.0005364447f, 0.0006439523f, 0.0007379710f, + 0.0008173893f, 0.0008801810f, 0.0009241189f, 0.0009469386f, 0.0009470262f, 0.0009235256f, 0.0008768074f, 0.0008083660f, + 0.0007209842f, 0.0006183917f, 0.0005051683f, 0.0003862499f, 0.0002667034f, 0.0001512287f, 0.0000439630f, -0.0000518813f, + -0.0001340642f, -0.0002014693f, -0.0002539655f, -0.0002923568f, -0.0003181036f, -0.0003331509f, -0.0003396076f, -0.0003395633f, + -0.0003348303f, -0.0003268422f, -0.0003165265f, -0.0003043290f, -0.0002902270f, -0.0002738620f, -0.0002546506f, -0.0002319638f, + -0.0002052612f, -0.0001742433f, -0.0001389381f, -0.0000997698f, -0.0000575586f, -0.0000134887f, 0.0000309765f, 0.0000742026f, + 0.0001145147f, 0.0001503321f, 0.0001802885f, + -0.0001277341f, -0.0000801832f, -0.0000218515f, 0.0000429946f, 0.0001101725f, 0.0001753791f, 0.0002352234f, 0.0002868790f, + 0.0003289280f, 0.0003607437f, 0.0003830779f, 0.0003971613f, 0.0004050891f, 0.0004087434f, 0.0004101314f, 0.0004103021f, + 0.0004098229f, 0.0004078547f, 0.0004029032f, 0.0003921299f, 0.0003724071f, 0.0003398196f, 0.0002909307f, 0.0002223256f, + 0.0001319189f, 0.0000183492f, -0.0001178379f, -0.0002750908f, -0.0004498764f, -0.0006379165f, -0.0008333771f, -0.0010303574f, + -0.0012220954f, -0.0014025519f, -0.0015654459f, -0.0017057905f, -0.0018186276f, -0.0019004727f, -0.0019477420f, -0.0019582025f, + -0.0019292104f, -0.0018593672f, -0.0017467341f, -0.0015908909f, -0.0013912094f, -0.0011493707f, -0.0008675713f, -0.0005513213f, + -0.0002071950f, 0.0001544857f, 0.0005229288f, 0.0008847642f, 0.0012288921f, 0.0015452051f, 0.0018312322f, 0.0020914322f, + 0.0023452820f, 0.0026261558f, 0.0029898311f, 0.0035112352f, 0.0042918405f, 0.0054520943f, 0.0071361390f, 0.0094977907f, + 0.0127016847f, 0.0169013256f, 0.0222371991f, 0.0288065364f, 0.0366610177f, 0.0457690119f, 0.0560179682f, 0.0671701450f, + 0.0788774558f, 0.0906296100f, 0.1017925366f, 0.1115401869f, 0.1189349031f, 0.1228106313f, 0.1219422410f, 0.1147682442f, + 0.0998698743f, 0.0698963887f, 0.0088203751f, -0.0909692208f, -0.2234220627f, -0.3756331554f, -0.5300042260f, -0.6668887743f, + -0.7671574389f, -0.8148547416f, -0.7993524069f, -0.7169019655f, -0.5713321080f, -0.3737662567f, -0.1415729584f, 0.1036716588f, + 0.3378392047f, 0.5399814296f, 0.7022792290f, 0.8235847390f, 0.9011912110f, 0.9335195531f, 0.9210148943f, 0.8662582998f, + 0.7738442006f, 0.6501373474f, 0.5028823140f, 0.3407552797f, 0.1728427401f, 0.0081212390f, -0.1450610431f, -0.2794406314f, + -0.3892283922f, -0.4703883896f, -0.5208081709f, -0.5403348331f, -0.5306924278f, -0.4952731730f, -0.4388331926f, -0.3670992988f, + -0.2863302758f, -0.2028454693f, -0.1225716070f, -0.0506164333f, 0.0090788383f, 0.0540159375f, 0.0833026194f, 0.0977385677f, + 0.0999946466f, 0.0952552716f, 0.0880995668f, 0.0797728807f, 0.0706660863f, 0.0613242080f, 0.0521689821f, 0.0435466445f, + 0.0356893133f, 0.0287479136f, 0.0227869173f, 0.0178107854f, 0.0137689980f, 0.0105778434f, 0.0081277168f, 0.0062997686f, + 0.0049716376f, 0.0040285807f, 0.0033660981f, 0.0028959547f, 0.0025456890f, 0.0022606635f, 0.0020013537f, 0.0017429261f, + 0.0014715303f, 0.0011828460f, 0.0008784722f, 0.0005645174f, 0.0002487848f, -0.0000600208f, -0.0003540749f, -0.0006264965f, + -0.0008722305f, -0.0010875779f, -0.0012705059f, -0.0014199592f, -0.0015359444f, -0.0016188954f, -0.0016697727f, -0.0016896254f, + -0.0016797991f, -0.0016416978f, -0.0015770686f, -0.0014878777f, -0.0013765796f, -0.0012459990f, -0.0010995021f, -0.0009408124f, + -0.0007740525f, -0.0006034858f, -0.0004334565f, -0.0002681040f, -0.0001112695f, 0.0000337496f, 0.0001642534f, 0.0002782887f, + 0.0003746198f, 0.0004527614f, 0.0005128644f, 0.0005556551f, 0.0005822707f, 0.0005941545f, 0.0005928931f, 0.0005801213f, + 0.0005574074f, 0.0005262036f, 0.0004878004f, 0.0004433324f, 0.0003937929f, 0.0003400774f, 0.0002830311f, 0.0002234973f, + 0.0001623637f, 0.0001005861f, 0.0000392083f, -0.0000206541f, -0.0000778269f, -0.0001311308f, -0.0001794168f, -0.0002216378f, + -0.0002568858f, -0.0002844591f, -0.0003038790f, -0.0003149350f, -0.0003176698f, -0.0003123947f, -0.0002996434f, -0.0002801639f, + -0.0002548507f, -0.0002247269f, -0.0001908697f, -0.0001543953f, -0.0001163917f, -0.0000779152f, -0.0000399357f, + 0.0000094413f, 0.0000277999f, 0.0000446903f, 0.0000593280f, 0.0000712651f, 0.0000803871f, 0.0000870097f, 0.0000917822f, + 0.0000956902f, 0.0000998716f, 0.0001055506f, 0.0001138098f, 0.0001255136f, 0.0001411003f, 0.0001605589f, 0.0001832996f, + 0.0002082298f, 0.0002337307f, 0.0002578403f, 0.0002783202f, 0.0002929118f, 0.0002994416f, 0.0002960857f, 0.0002814451f, + 0.0002547522f, 0.0002158569f, 0.0001653321f, 0.0001043455f, 0.0000346623f, -0.0000415774f, -0.0001219205f, -0.0002038633f, + -0.0002849129f, -0.0003628240f, -0.0004355962f, -0.0005016356f, -0.0005596549f, -0.0006087461f, -0.0006481918f, -0.0006774810f, + -0.0006960781f, -0.0007034418f, -0.0006988166f, -0.0006813178f, -0.0006497978f, -0.0006030351f, -0.0005396896f, -0.0004585888f, + -0.0003587409f, -0.0002396693f, -0.0001014165f, 0.0000551454f, 0.0002283928f, 0.0004157251f, 0.0006137740f, 0.0008182856f, + 0.0010244618f, 0.0012269217f, 0.0014201288f, 0.0015983649f, 0.0017561723f, 0.0018882664f, 0.0019899370f, 0.0020568553f, + 0.0020854261f, 0.0020725003f, 0.0020157272f, 0.0019132331f, 0.0017640560f, 0.0015678593f, 0.0013255131f, 0.0010388553f, + 0.0007114008f, 0.0003480516f, -0.0000442075f, -0.0004568793f, -0.0008795218f, -0.0013009102f, -0.0017091380f, -0.0020936476f, + -0.0024460089f, -0.0027628964f, -0.0030473913f, -0.0033126371f, -0.0035830824f, -0.0038981281f, -0.0043122790f, -0.0048977534f, + -0.0057421929f, -0.0069491136f, -0.0086317888f, -0.0109107455f, -0.0139027684f, -0.0177154927f, -0.0224311200f, -0.0280995831f, + -0.0347172313f, -0.0422222045f, -0.0504683384f, -0.0592304787f, -0.0681714904f, -0.0768802892f, -0.0848233610f, -0.0916208280f, + -0.0960365098f, -0.0934965965f, -0.0788165513f, -0.0493177686f, -0.0041840764f, 0.0557190363f, 0.1279300009f, 0.2085541449f, + 0.2925373176f, 0.3740109184f, 0.4467123250f, 0.5044329150f, 0.5414803943f, 0.5531103895f, 0.5359083733f, 0.4880865671f, + 0.4096810759f, 0.3026295623f, 0.1707255672f, 0.0194488912f, -0.1443186247f, -0.3126736143f, -0.4771477585f, -0.6292070969f, + -0.7607694851f, -0.8646983027f, -0.9352529748f, -0.9684532025f, -0.9623535812f, -0.9171949326f, -0.8354559290f, -0.7219447724f, + -0.5842261616f, -0.4299994224f, -0.2647671304f, -0.0936718584f, 0.0778573928f, 0.2444955397f, 0.4011508179f, 0.5431562386f, + 0.6663917866f, 0.7674190691f, 0.8435687444f, 0.8930187210f, 0.9148305827f, 0.9089668951f, 0.8762704359f, 0.8184215785f, + 0.7378630625f, 0.6377054994f, 0.5216082533f, 0.3936475943f, 0.2581703422f, 0.1196438490f, -0.0174973196f, -0.1489983380f, + -0.2709234334f, -0.3797794589f, -0.4726225629f, -0.5471418581f, -0.6017198326f, -0.6354657299f, -0.6482230521f, -0.6405498448f, + -0.6136745009f, -0.5694280123f, -0.5101568311f, -0.4386191067f, -0.3578694342f, -0.2711360702f, -0.1816960690f, -0.0927527129f, + -0.0073202620f, 0.0718799659f, 0.1425082935f, 0.2026771758f, 0.2510012829f, 0.2866256582f, 0.3092317499f, 0.3190214225f, + 0.3166807736f, 0.3033253264f, 0.2804301957f, 0.2497478163f, 0.2132181238f, 0.1728741342f, 0.1307484916f, 0.0887835046f, + 0.0487503059f, 0.0121784205f, -0.0196990379f, -0.0459852335f, -0.0661399413f, -0.0799836583f, -0.0876812985f, -0.0897120098f, + -0.0868204670f, -0.0799602374f, -0.0702221831f, -0.0587644272f, -0.0467300423f, -0.0351807009f, -0.0250131586f, -0.0169220452f, + -0.0110491061f, -0.0067999510f, -0.0036452141f, -0.0013776515f, 0.0001725658f, 0.0011515063f, 0.0016931166f, 0.0019128947f, + 0.0019119195f, 0.0017731008f, 0.0015641080f, 0.0013360166f, 0.0011263428f, 0.0009592385f, 0.0008486058f, 0.0007990396f, + 0.0008087142f, 0.0008704662f, 0.0009741845f, 0.0011076612f, 0.0012583569f, 0.0014138649f, 0.0015630668f, 0.0016962130f, + 0.0018055792f, 0.0018852562f, 0.0019314544f, 0.0019421196f, 0.0019170260f, 0.0018573192f, 0.0017655022f, 0.0016449753f, + 0.0014999823f, 0.0013351861f, 0.0011556142f, 0.0009662892f, 0.0007721962f, 0.0005779798f, 0.0003879485f, 0.0002058452f, + 0.0000348998f, -0.0001223239f, -0.0002638249f, -0.0003882481f, -0.0004947379f, -0.0005829688f, -0.0006529761f, -0.0007051597f, + -0.0007401195f, -0.0007586609f, -0.0007616586f, -0.0007500873f, -0.0007249274f, -0.0006872277f, -0.0006380521f, -0.0005785652f, + -0.0005100019f, -0.0004337551f, -0.0003513433f, -0.0002644761f, -0.0001749961f, -0.0000849056f, 0.0000037265f, 0.0000887799f, + 0.0001682047f, 0.0002400620f, 0.0003026539f, 0.0003545629f, 0.0003947614f, 0.0004226221f, 0.0004379830f, 0.0004411096f, + 0.0004327050f, 0.0004138228f, 0.0003858290f, 0.0003502817f, 0.0003088683f, 0.0002632783f, 0.0002151470f, 0.0001659510f, + 0.0001169830f, 0.0000692900f, 0.0000236931f, -0.0000192281f, -0.0000590766f, -0.0000956193f, -0.0001287082f, -0.0001582520f, + -0.0001841434f, -0.0002062459f, -0.0002243482f, -0.0002381838f, -0.0002474218f, -0.0002517193f, -0.0002507430f, -0.0002442414f, + -0.0002320758f, -0.0002142901f, -0.0001911276f, -0.0001630744f, -0.0001308436f, -0.0000953784f, -0.0000577970f, -0.0000193582f, + 0.0000186239f, 0.0000548367f, 0.0000880630f, 0.0001172340f, 0.0001415074f, 0.0001602936f, 0.0001732965f, 0.0001804997f, + 0.0001821637f, 0.0001787723f, 0.0001709948f, 0.0001596078f, 0.0001454431f, 0.0001293085f, 0.0001119454f, 0.0000939706f, + 0.0000758637f, 0.0000579434f, 0.0000403900f, 0.0000232563f, 0.0000065182f, -0.0000098944f, -0.0000260374f, -0.0000419222f, + -0.0000574677f, -0.0000724909f, -0.0000866869f, -0.0000996508f, -0.0001108899f, -0.0001198747f, -0.0001260737f, -0.0001290184f, + -0.0001283426f, -0.0001238392f, -0.0001154831f, -0.0001034619f, -0.0000881663f, -0.0000701856f, -0.0000502629f, + 0.0000100257f, 0.0000298715f, 0.0000491016f, 0.0000673457f, 0.0000842719f, 0.0000996175f, 0.0001131774f, 0.0001248226f, + 0.0001344760f, 0.0001421200f, 0.0001477626f, 0.0001514384f, 0.0001531732f, 0.0001529862f, 0.0001508606f, 0.0001467558f, + 0.0001405885f, 0.0001322589f, 0.0001216448f, 0.0001086385f, 0.0000931503f, 0.0000751504f, 0.0000546725f, 0.0000318520f, + 0.0000069213f, -0.0000197639f, -0.0000477443f, -0.0000764464f, -0.0001052188f, -0.0001333354f, -0.0001600439f, -0.0001845767f, + -0.0002062035f, -0.0002242408f, -0.0002380992f, -0.0002472837f, -0.0002514295f, -0.0002502882f, -0.0002437508f, -0.0002318205f, + -0.0002146257f, -0.0001923855f, -0.0001654183f, -0.0001341069f, -0.0000989108f, -0.0000603353f, -0.0000189514f, 0.0000246284f, + 0.0000697235f, 0.0001156056f, 0.0001614708f, 0.0002064618f, 0.0002496452f, 0.0002900437f, 0.0003266238f, 0.0003583420f, + 0.0003841453f, 0.0004030314f, 0.0004140579f, 0.0004164107f, 0.0004094151f, 0.0003926023f, 0.0003657128f, 0.0003287519f, + 0.0002819762f, 0.0002259319f, 0.0001614203f, 0.0000895170f, 0.0000115172f, -0.0000710597f, -0.0001565398f, -0.0002430985f, + -0.0003288369f, -0.0004117862f, -0.0004899853f, -0.0005614798f, -0.0006243974f, -0.0006769402f, -0.0007174577f, -0.0007444335f, + -0.0007565586f, -0.0007527147f, -0.0007320491f, -0.0006939555f, -0.0006381507f, -0.0005646499f, -0.0004738416f, -0.0003664521f, + -0.0002436140f, -0.0001068131f, 0.0000420546f, 0.0002007573f, 0.0003666837f, 0.0005369393f, 0.0007083151f, 0.0008774032f, + 0.0010405725f, 0.0011941030f, 0.0013341657f, 0.0014569762f, 0.0015587822f, 0.0016360436f, 0.0016854353f, 0.0017040651f, + 0.0016895002f, 0.0016400311f, 0.0015547178f, 0.0014336912f, 0.0012781928f, 0.0010908735f, 0.0008757648f, 0.0006385002f, + 0.0003861185f, 0.0001271046f, -0.0001290952f, -0.0003723192f, -0.0005925672f, -0.0007805994f, -0.0009292471f, -0.0010343329f, + -0.0010963449f, -0.0011215032f, -0.0011235784f, -0.0011247650f, -0.0011572825f, -0.0012635736f, -0.0014972500f, -0.0019220776f, + -0.0026119000f, -0.0036479956f, -0.0051179657f, -0.0071115979f, -0.0097197636f, -0.0130315445f, -0.0171388264f, -0.0221826026f, + -0.0285136326f, -0.0361307186f, -0.0442081981f, -0.0516559897f, -0.0573925315f, -0.0603652434f, -0.0596331395f, -0.0544264019f, + -0.0442109616f, -0.0287331963f, -0.0080564058f, 0.0174234593f, 0.0469759993f, 0.0795551974f, 0.1138332879f, 0.1482526191f, + 0.1810898747f, 0.2105329869f, 0.2347647762f, 0.2520519356f, 0.2608332916f, 0.2598051239f, 0.2479978629f, 0.2248419603f, + 0.1902182120f, 0.1444910892f, 0.0885218306f, 0.0236611727f, -0.0482797215f, -0.1250786276f, -0.2041714722f, -0.2827382419f, + -0.3578034522f, -0.4263466673f, -0.4854197016f, -0.5322651608f, -0.5644323798f, -0.5798852692f, -0.5770983111f, -0.5551358084f, + -0.5137115562f, -0.4532252989f, -0.3747746885f, -0.2801408533f, -0.1717482321f, -0.0525987506f, 0.0738169580f, 0.2036293318f, + 0.3327161135f, 0.4568415935f, 0.5718029559f, 0.6735794476f, 0.7584777874f, 0.8232695197f, 0.8653138344f, 0.8826624233f, + 0.8741407389f, 0.8394039127f, 0.7789631089f, 0.6941829200f, 0.5872472518f, 0.4610970982f, 0.3193391719f, 0.1661318331f, + 0.0060481020f, -0.1560745385f, -0.3152984295f, -0.4667504424f, -0.6057916885f, -0.7281716821f, -0.8301830623f, -0.9087761258f, + -0.9618416393f, -0.9883769508f, -0.9880544909f, -0.9610885174f, -0.9083986381f, -0.8315930415f, -0.7329302137f, -0.6152510066f, + -0.4818998000f, -0.3366264325f, -0.1834804423f, -0.0266942820f, 0.1294357761f, 0.2806718111f, 0.4229523505f, 0.5525059678f, + 0.6659544948f, 0.7604051258f, 0.8335268161f, 0.8836105772f, 0.9096104660f, 0.9111656060f, 0.8886015017f, 0.8429119395f, + 0.7757211639f, 0.6892286142f, 0.5861371807f, 0.4695681223f, 0.3429645973f, 0.2099875350f, 0.0744064202f, -0.0600110582f, + -0.1896077300f, -0.3109402608f, -0.4208745383f, -0.5166699060f, -0.5960503378f, -0.6572602031f, -0.6991036150f, -0.7209660923f, + -0.7228185799f, -0.7052037113f, -0.6692054230f, -0.6164028870f, -0.5488108092f, -0.4688079424f, -0.3790565546f, -0.2824152817f, + -0.1818484683f, -0.0803346471f, 0.0192227465f, 0.1140799262f, 0.2017298411f, 0.2799697880f, 0.3469574836f, 0.4012543426f, + 0.4418547649f, 0.4682010863f, 0.4801839581f, 0.4781287434f, 0.4627686220f, 0.4352058330f, 0.3968625180f, 0.3494232322f, + 0.2947711136f, 0.2349201359f, 0.1719456583f, 0.1079157418f, 0.0448253472f, -0.0154643795f, -0.0712800080f, -0.1211812328f, + -0.1639966775f, -0.1988491244f, -0.2251698043f, -0.2427015611f, -0.2514912990f, -0.2518722833f, -0.2444373910f, -0.2300045092f, + -0.2095756919f, -0.1842916891f, -0.1553837364f, -0.1241243795f, -0.0917792284f, -0.0595613097f, -0.0285896618f, 0.0001465056f, + 0.0258169100f, 0.0477717562f, 0.0655551910f, 0.0789104778f, 0.0877769862f, 0.0922794468f, 0.0927101873f, 0.0895053265f, + 0.0832161440f, 0.0744769454f, 0.0639709607f, 0.0523956967f, 0.0404293889f, 0.0286998006f, 0.0177569270f, 0.0080503829f, + -0.0000871632f, -0.0064505432f, -0.0109653717f, -0.0136854786f, -0.0147827090f, -0.0145338644f, -0.0132999155f, -0.0115279496f, + -0.0097143162f, -0.0081066262f, -0.0066892166f, -0.0054526910f, -0.0044043619f, -0.0035430638f, -0.0028610848f, -0.0023435648f, + -0.0019710460f, -0.0017207440f, -0.0015686177f, -0.0014906099f, -0.0014640505f, -0.0014684367f, -0.0014861739f, -0.0015028429f, + -0.0015073922f, -0.0014919944f, -0.0014518622f, -0.0013848537f, -0.0012910935f, -0.0011724856f, -0.0010322928f, -0.0008746803f, + -0.0007043572f, -0.0005262236f, -0.0003451249f, -0.0001656257f, 0.0000081168f, 0.0001724644f, 0.0003243294f, 0.0004612043f, + 0.0005811330f, 0.0006826956f, 0.0007649539f, 0.0008274212f, 0.0008700054f, 0.0008929815f, 0.0008969444f, 0.0008827894f, + 0.0008516741f, 0.0008050045f, 0.0007444000f, 0.0006716783f, 0.0005888158f, 0.0004979255f, 0.0004012090f, 0.0003009243f, + 0.0001993306f, 0.0000986487f, 0.0000010025f, -0.0000916200f, -0.0001774214f, -0.0002548259f, -0.0003225212f, -0.0003794749f, + -0.0004249577f, -0.0004585414f, -0.0004801021f, -0.0004897991f, -0.0004880609f, -0.0004755490f, -0.0004531324f, -0.0004218435f, + -0.0003828474f, -0.0003373970f, -0.0002868049f, -0.0002324032f, -0.0001755218f, -0.0001174565f, -0.0000594555f, -0.0000026960f, + 0.0000517227f, 0.0001027959f, 0.0001496166f, 0.0001913889f, 0.0002274293f, 0.0002571799f, 0.0002802094f, 0.0002962259f, + 0.0003050777f, 0.0003067640f, 0.0003014323f, 0.0002893851f, 0.0002710700f, 0.0002470789f, 0.0002181291f, 0.0001850528f, + 0.0001487686f, 0.0001102623f, 0.0000705516f, 0.0000306614f, -0.0000084134f, -0.0000457325f, -0.0000804436f, -0.0001118002f, + -0.0001391858f, -0.0001621210f, -0.0001802753f, -0.0001934613f, -0.0002016344f, -0.0002048759f, -0.0002033834f, -0.0001974478f, + -0.0001874396f, -0.0001737844f, -0.0001569508f, -0.0001374298f, -0.0001157277f, -0.0000923513f, -0.0000678073f, -0.0000425930f, + -0.0000172000f, 0.0000078915f, 0.0000322093f, 0.0000552949f, 0.0000767028f, 0.0000960105f, 0.0001128219f, 0.0001267820f, + 0.0001375845f, 0.0001449888f, 0.0001488284f, 0.0001490265f, 0.0001456006f, 0.0001386719f, 0.0001284619f, 0.0001152928f, + 0.0000995735f, 0.0000817902f, 0.0000624834f, 0.0000422315f, 0.0000216225f, 0.0000012352f, -0.0000183878f, -0.0000367552f, + 0.0001023410f, 0.0001121154f, 0.0001195973f, 0.0001245785f, 0.0001269032f, 0.0001264687f, 0.0001232335f, 0.0001172154f, + 0.0001084967f, 0.0000972190f, 0.0000835860f, 0.0000678549f, 0.0000503359f, 0.0000313814f, 0.0000113831f, -0.0000092410f, + -0.0000300509f, -0.0000505985f, -0.0000704325f, -0.0000891123f, -0.0001062126f, -0.0001213366f, -0.0001341197f, -0.0001442414f, + -0.0001514272f, -0.0001554600f, -0.0001561797f, -0.0001534931f, -0.0001473717f, -0.0001378600f, -0.0001250712f, -0.0001091929f, + -0.0000904812f, -0.0000692631f, -0.0000459277f, -0.0000209260f, 0.0000052416f, 0.0000320286f, 0.0000588582f, 0.0000851296f, + 0.0001102367f, 0.0001335760f, 0.0001545675f, 0.0001726629f, 0.0001873663f, 0.0001982416f, 0.0002049310f, 0.0002071594f, + 0.0002047497f, 0.0001976225f, 0.0001858068f, 0.0001694347f, 0.0001487471f, 0.0001240832f, 0.0000958818f, 0.0000646662f, + 0.0000310422f, -0.0000043212f, -0.0000406957f, -0.0000773156f, -0.0001133832f, -0.0001480928f, -0.0001806368f, -0.0002102303f, + -0.0002361185f, -0.0002576013f, -0.0002740408f, -0.0002848864f, -0.0002896805f, -0.0002880829f, -0.0002798740f, -0.0002649766f, + -0.0002434546f, -0.0002155298f, -0.0001815742f, -0.0001421204f, -0.0000978454f, -0.0000495727f, 0.0000017521f, 0.0000550676f, + 0.0001092294f, 0.0001630223f, 0.0002152001f, 0.0002645008f, 0.0003096899f, 0.0003495759f, 0.0003830534f, 0.0004091148f, + 0.0004268910f, 0.0004356569f, 0.0004348671f, 0.0004241540f, 0.0004033574f, 0.0003725151f, 0.0003318867f, 0.0002819362f, + 0.0002233505f, 0.0001570144f, 0.0000840236f, 0.0000056513f, -0.0000766447f, -0.0001612647f, -0.0002464668f, -0.0003304197f, + -0.0004112104f, -0.0004869065f, -0.0005555699f, -0.0006153285f, -0.0006643921f, -0.0007011284f, -0.0007240766f, -0.0007320225f, + -0.0007240025f, -0.0006993717f, -0.0006577934f, -0.0005992952f, -0.0005242405f, -0.0004333727f, -0.0003277670f, -0.0002088657f, + -0.0000784141f, 0.0000615090f, 0.0002085679f, 0.0003601400f, 0.0005134039f, 0.0006653091f, 0.0008126807f, 0.0009521955f, + 0.0010805136f, 0.0011942726f, 0.0012902629f, 0.0013654507f, 0.0014172107f, 0.0014433822f, 0.0014425598f, 0.0014141671f, + 0.0013587836f, 0.0012781916f, 0.0011756894f, 0.0010560340f, 0.0009256640f, 0.0007924355f, 0.0006656655f, 0.0005555507f, + 0.0004729584f, 0.0004284373f, 0.0004317362f, 0.0004903651f, 0.0006089185f, 0.0007872127f, 0.0010196237f, 0.0012928786f, + 0.0015857907f, 0.0018667312f, 0.0020943919f, 0.0022145657f, 0.0021631986f, 0.0018604759f, 0.0012208798f, 0.0000292075f, + -0.0021197116f, -0.0054807990f, -0.0100496540f, -0.0156837116f, -0.0221176153f, -0.0289836659f, -0.0358300499f, -0.0421477124f, + -0.0473972472f, -0.0510405877f, -0.0525715807f, -0.0515476777f, -0.0476183263f, -0.0405511583f, -0.0302526219f, -0.0167837577f, + -0.0003687048f, 0.0186033188f, 0.0395840702f, 0.0618793275f, 0.0846695731f, 0.1070368665f, 0.1279977851f, 0.1465405975f, + 0.1616659442f, 0.1724289210f, 0.1779814634f, 0.1776128485f, 0.1707870983f, 0.1571752579f, 0.1366814829f, 0.1094613028f, + 0.0759313883f, 0.0367697773f, -0.0070935349f, -0.0544959696f, -0.1040711201f, -0.1542864664f, -0.2034887901f, -0.2499561795f, + -0.2919547949f, -0.3277987591f, -0.3559109665f, -0.3748828886f, -0.3835310580f, -0.3809483068f, -0.3665476249f, -0.3400970096f, + -0.3017436398f, -0.2520263114f, -0.1918751666f, -0.1225984212f, -0.0458559702f, 0.0363795557f, 0.1218735116f, 0.2081903173f, + 0.2927633059f, 0.3729712075f, 0.4462190576f, 0.5100209195f, 0.5620818683f, 0.6003764644f, 0.6232211630f, 0.6293380722f, + 0.6179078583f, 0.5886097344f, 0.5416469980f, 0.4777568614f, 0.3982039462f, 0.3047571785f, 0.1996504916f, 0.0855281262f, + -0.0346240344f, -0.1575593206f, -0.2798609975f, -0.3980402954f, -0.5086387923f, -0.6083321215f, -0.6940317623f, -0.7629817970f, + -0.8128474994f, -0.8417929488f, -0.8485450365f, -0.8324417371f, -0.7934628536f, -0.7322420813f, -0.6500596798f, -0.5488157513f, + -0.4309846022f, -0.2995513767f, -0.1579325879f, -0.0098828159f, 0.1406098406f, 0.2894364546f, 0.4324848701f, 0.5657586229f, + 0.6854937093f, 0.7882695488f, 0.8711108731f, 0.9315772485f, 0.9678376107f, 0.9787272513f, 0.9637856763f, 0.9232737576f, + 0.8581699744f, 0.7701451849f, 0.6615174635f, 0.5351870989f, 0.3945560458f, 0.2434310351f, 0.0859296286f, -0.0736424535f, + -0.2310634168f, -0.3823114335f, -0.5235213255f, -0.6510808750f, -0.7617398230f, -0.8526941807f, -0.9216599849f, -0.9669314227f, + -0.9874241586f, -0.9827015967f, -0.9529842399f, -0.8991414091f, -0.8226659724f, -0.7256325245f, -0.6106403919f, -0.4807428752f, + -0.3393647947f, -0.1902104941f, -0.0371648883f, 0.1158098198f, 0.2647789049f, 0.4059385830f, 0.5357153558f, 0.6508586114f, + 0.7485239966f, 0.8263453865f, 0.8824935656f, 0.9157201366f, 0.9253855645f, 0.9114707230f, 0.8745717535f, 0.8158785137f, + 0.7371373367f, 0.6405992467f, 0.5289551681f, 0.4052600056f, 0.2728477634f, 0.1352400975f, -0.0039491512f, -0.1411108055f, + -0.2727359386f, -0.3955076155f, -0.5063863406f, -0.6026869640f, -0.6821450593f, -0.7429710985f, -0.7838911084f, -0.8041728778f, + -0.8036371970f, -0.7826540315f, -0.7421239451f, -0.6834454939f, -0.6084696882f, -0.5194429622f, -0.4189403872f, -0.3097911110f, + -0.1949981889f, -0.0776550965f, 0.0391387290f, 0.1523609846f, 0.2591459713f, 0.3568583179f, 0.4431590282f, 0.5160621741f, + 0.5739808402f, 0.6157612575f, 0.6407044060f, 0.6485747369f, 0.6395960249f, 0.6144347317f, 0.5741715934f, 0.5202624757f, + 0.4544898084f, 0.3789061628f, 0.2957717132f, 0.2074874749f, 0.1165262725f, 0.0253634355f, -0.0635908373f, -0.1480555764f, + -0.2259378928f, -0.2953850427f, -0.3548284161f, -0.4030183987f, -0.4390493642f, -0.4623743329f, -0.4728091652f, -0.4705264349f, + -0.4560394511f, -0.4301771396f, -0.3940507708f, -0.3490137022f, -0.2966155068f, -0.2385519527f, -0.1766124162f, -0.1126263061f, + -0.0484101006f, 0.0142835032f, 0.0738128901f, 0.1286900297f, 0.1776170652f, 0.2195161266f, 0.2535516850f, 0.2791450556f, + 0.2959808562f, 0.3040055207f, 0.3034181575f, 0.2946543119f, 0.2783633373f, 0.2553803089f, 0.2266934879f, 0.1934085139f, + 0.1567104961f, 0.1178252714f, 0.0779810094f, 0.0383713679f, 0.0001212356f, -0.0357439328f, -0.0683244197f, -0.0968674883f, + -0.1207831483f, -0.1396541129f, -0.1532399189f, -0.1614752576f, -0.1644628650f, -0.1624613596f, -0.1558686952f, -0.1452018785f, + -0.1310738418f, -0.1141682734f, -0.0952134023f, -0.0749555678f, -0.0541335559f, -0.0334544361f, -0.0135717544f, 0.0049333847f, + 0.0215677075f, 0.0359373755f, 0.0477554333f, 0.0568451598f, 0.0631392301f, 0.0666750625f, 0.0675865095f, 0.0660925397f, + 0.0624832536f, 0.0571040881f, 0.0503386382f, 0.0425910695f, 0.0342685282f, 0.0257645482f, 0.0174437200f, 0.0096285741f, + 0.0025886897f, -0.0034671163f, -0.0083958582f, -0.0121219514f, -0.0146360592f, -0.0159904888f, -0.0162924414f, -0.0156942489f, + -0.0143825819f, -0.0125652661f, -0.0104587259f, -0.0082734050f, -0.0062022974f, -0.0044063851f, -0.0030085782f, -0.0020299468f, + -0.0013564795f, -0.0008863453f, -0.0005771741f, -0.0003938621f, -0.0003061649f, -0.0002866266f, -0.0003117925f, -0.0003614869f, + -0.0004195045f, -0.0004730462f, -0.0005129312f, -0.0005329799f, -0.0005299127f, -0.0005026982f, -0.0004523006f, -0.0003810636f, + -0.0002924326f, -0.0001904381f, -0.0000794736f, 0.0000360876f, 0.0001520218f, 0.0002645035f, 0.0003701407f, 0.0004661098f, + 0.0005501197f, 0.0006204662f, 0.0006759537f, 0.0007159048f, 0.0007400667f, 0.0007486024f, 0.0007420006f, 0.0007210650f, + 0.0006868352f, 0.0006405800f, 0.0005837296f, 0.0005178714f, 0.0004446899f, 0.0003659600f, 0.0002834907f, 0.0001991139f, + 0.0001146287f, 0.0000317867f, -0.0000477626f, -0.0001224860f, -0.0001910156f, -0.0002521590f, -0.0003049377f, -0.0003485879f, + -0.0003825850f, -0.0004066332f, -0.0004206749f, -0.0004248679f, -0.0004195832f, -0.0004053722f, -0.0003829556f, -0.0003531864f, + -0.0003170337f, -0.0002755456f, -0.0002298325f, -0.0001810330f, -0.0001302996f, -0.0000787683f, -0.0000275484f, 0.0000223042f, + 0.0000697938f, 0.0001140082f, 0.0001541235f, 0.0001894239f, 0.0002193054f, 0.0002432921f, 0.0002610376f, 0.0002723377f, + 0.0002771279f, 0.0002754901f, 0.0002676451f, 0.0002539525f, 0.0002348963f, 0.0002110770f, 0.0001831908f, 0.0001520155f, + 0.0001183840f, 0.0000831661f, 0.0000472400f, 0.0000114735f, -0.0000233037f, -0.0000563155f, -0.0000868623f, -0.0001143311f, + -0.0001382112f, -0.0001580971f, -0.0001736964f, -0.0001848263f, -0.0001914138f, -0.0001934872f, -0.0001911719f, -0.0001846781f, + -0.0001742945f, -0.0001603745f, -0.0001433301f, -0.0001236179f, -0.0001017335f, -0.0000781989f, -0.0000535563f, -0.0000283571f, + -0.0000031551f, 0.0000215050f, 0.0000450945f, 0.0000671132f, 0.0000870967f, 0.0001046293f, 0.0001193514f, 0.0001309712f, + 0.0001392702f, 0.0001441122f, 0.0001454457f, 0.0001433077f, 0.0001378215f, 0.0001291946f, 0.0001177105f, 0.0001037219f, + 0.0000876371f, 0.0000699088f, 0.0000510177f, 0.0000314597f, 0.0000117289f, -0.0000076947f, -0.0000263593f, -0.0000438511f, + 0.0001150132f, 0.0001210457f, 0.0001243256f, 0.0001247272f, 0.0001221905f, 0.0001167241f, 0.0001084050f, 0.0000973782f, + 0.0000838538f, 0.0000681026f, 0.0000504506f, 0.0000312726f, 0.0000109840f, -0.0000099676f, -0.0000311119f, -0.0000519657f, + -0.0000720435f, -0.0000908672f, -0.0001079775f, -0.0001229433f, -0.0001353725f, -0.0001449210f, -0.0001513017f, -0.0001542924f, + -0.0001537428f, -0.0001495795f, -0.0001418111f, -0.0001305291f, -0.0001159099f, -0.0000982119f, -0.0000777730f, -0.0000550042f, + -0.0000303824f, -0.0000044402f, 0.0000222446f, 0.0000490630f, 0.0000753874f, 0.0001005877f, 0.0001240454f, 0.0001451693f, + 0.0001634096f, 0.0001782724f, 0.0001893315f, 0.0001962400f, 0.0001987389f, 0.0001966654f, 0.0001899567f, 0.0001786543f, + 0.0001629038f, 0.0001429540f, 0.0001191532f, 0.0000919438f, 0.0000618549f, 0.0000294929f, -0.0000044692f, -0.0000393044f, + -0.0000742456f, -0.0001085004f, -0.0001412677f, -0.0001717545f, -0.0001991934f, -0.0002228606f, -0.0002420939f, -0.0002563091f, + -0.0002650175f, -0.0002678393f, -0.0002645180f, -0.0002549296f, -0.0002390911f, -0.0002171644f, -0.0001894582f, -0.0001564244f, + -0.0001186528f, -0.0000768603f, -0.0000318787f, 0.0000153623f, 0.0000638538f, 0.0001125289f, 0.0001602850f, 0.0002060085f, + 0.0002485978f, 0.0002869886f, 0.0003201766f, 0.0003472410f, 0.0003673652f, 0.0003798567f, 0.0003841643f, 0.0003798944f, + 0.0003668225f, 0.0003449050f, 0.0003142851f, 0.0002752981f, 0.0002284708f, 0.0001745194f, 0.0001143417f, 0.0000490064f, + -0.0000202635f, -0.0000921091f, -0.0001650610f, -0.0002375657f, -0.0003080181f, -0.0003747934f, -0.0004362837f, -0.0004909328f, + -0.0005372734f, -0.0005739597f, -0.0005998016f, -0.0006137920f, -0.0006151340f, -0.0006032611f, -0.0005778563f, -0.0005388644f, + -0.0004865040f, -0.0004212729f, -0.0003439544f, -0.0002556177f, -0.0001576201f, -0.0000516007f, 0.0000605233f, 0.0001765734f, + 0.0002941267f, 0.0004105520f, 0.0005230524f, 0.0006287329f, 0.0007246810f, 0.0008080802f, 0.0008763365f, 0.0009272432f, + 0.0009591516f, 0.0009711764f, 0.0009633904f, 0.0009370386f, 0.0008947118f, 0.0008405162f, 0.0007801566f, 0.0007209907f, + 0.0006719403f, 0.0006433567f, 0.0006466802f, 0.0006940691f, 0.0007977534f, 0.0009694468f, 0.0012193921f, 0.0015557448f, + 0.0019833924f, 0.0025041582f, 0.0031158854f, 0.0038235626f, 0.0046346272f, 0.0054390989f, 0.0060159327f, 0.0061653048f, + 0.0057248818f, 0.0045689017f, 0.0026174491f, -0.0001576249f, -0.0037279496f, -0.0080071970f, -0.0128521554f, -0.0180669900f, + -0.0234101334f, -0.0286038762f, -0.0333460639f, -0.0373236148f, -0.0402271782f, -0.0417664366f, -0.0416853226f, -0.0397765655f, + -0.0358948666f, -0.0299681460f, -0.0220062759f, -0.0121068734f, -0.0004577646f, 0.0126640959f, 0.0268973823f, 0.0418047890f, + 0.0568849057f, 0.0715872627f, 0.0853301253f, 0.0975204815f, 0.1075755810f, 0.1149452916f, 0.1191344911f, 0.1197246774f, + 0.1163939799f, 0.1089347803f, 0.0972682074f, 0.0814548499f, 0.0617011436f, 0.0383610136f, 0.0119325064f, -0.0169506961f, + -0.0475328132f, -0.0789543128f, -0.1102746589f, -0.1404988789f, -0.1686072305f, -0.1935871058f, -0.2144662161f, -0.2303460115f, + -0.2404342559f, -0.2440756538f, -0.2407794617f, -0.2302430666f, -0.2123706161f, -0.1872859065f, -0.1553388989f, -0.1171054066f, + -0.0733797097f, -0.0251600584f, 0.0263727389f, 0.0798832323f, 0.1339151136f, 0.1869300341f, 0.2373504277f, 0.2836051694f, + 0.3241767553f, 0.3576486211f, 0.3827511531f, 0.3984049546f, 0.4037599595f, 0.3982290834f, 0.3815152127f, 0.3536305207f, + 0.3149072795f, 0.2659995936f, 0.2078757153f, 0.1418008973f, 0.0693110001f, -0.0078226274f, -0.0876362185f, -0.1680235605f, + -0.2467916047f, -0.3217202299f, -0.3906245377f, -0.4514179183f, -0.5021740836f, -0.5411862254f, -0.5670215229f, -0.5785692885f, + -0.5750812186f, -0.5562023763f, -0.5219918070f, -0.4729319281f, -0.4099261771f, -0.3342846951f, -0.2476981973f, -0.1522004957f, + -0.0501205046f, 0.0559751503f, 0.1633474747f, 0.2691567323f, 0.3705384397f, 0.4646816888f, 0.5489076127f, 0.6207458062f, + 0.6780064885f, 0.7188463213f, 0.7418258915f, 0.7459571192f, 0.7307390569f, 0.6961809001f, 0.6428113176f, 0.5716736392f, + 0.4843067689f, 0.3827121551f, 0.2693074809f, 0.1468681897f, 0.0184582454f, -0.1126480739f, -0.2430513537f, -0.3693168934f, + -0.4880668522f, -0.5960721328f, -0.6903415076f, -0.7682054473f, -0.8273923237f, -0.8660947411f, -0.8830241082f, -0.8774517523f, + -0.8492353530f, -0.7988297417f, -0.7272816665f, -0.6362084256f, -0.5277608621f, -0.4045714971f, -0.2696891599f, -0.1265016829f, + 0.0213512370f, 0.1700728247f, 0.3158090264f, 0.4547507613f, 0.5832357292f, 0.6978471330f, 0.7955064526f, 0.8735578646f, + 0.9298417700f, 0.9627555531f, 0.9712996189f, 0.9551076043f, 0.9144595827f, 0.8502781043f, 0.7641067542f, 0.6580721014f, + 0.5348295632f, 0.3974950823f, 0.2495638365f, 0.0948188243f, -0.0627690415f, -0.2191456458f, -0.3702816044f, -0.5122788950f, + -0.6414754270f, -0.7545417373f, -0.8485716286f, -0.9211570287f, -0.9704889399f, -0.9954247591f, -0.9954218673f, -0.9705217574f, + -0.9213839861f, -0.8492714879f, -0.7560202971f, -0.6439925425f, -0.5160173451f, -0.3753189325f, -0.2254355616f, -0.0701299883f, + 0.0867051692f, 0.2411456382f, 0.3893340590f, 0.5275770178f, 0.6524375705f, 0.7608213615f, 0.8500537691f, 0.9179464760f, + 0.9628514821f, 0.9837014823f, 0.9800353577f, 0.9520083832f, 0.9003867192f, 0.8265265439f, 0.7323382228f, 0.6202366175f, + 0.4930786891f, 0.3540901510f, 0.2067829436f, 0.0548657749f, -0.0978500833f, -0.2475472308f, -0.3904984352f, -0.5231602531f, + -0.6422616826f, -0.7448855335f, -0.8285405425f, -0.8912223677f, -0.9314620191f, -0.9483604838f, -0.9416087836f, -0.9114929628f, + -0.8588840025f, -0.7852129374f, -0.6924319284f, -0.5829623058f, -0.4596310148f, -0.3255970991f, -0.1842701886f, -0.0392230686f, + 0.1058993714f, 0.2474725071f, 0.3819832739f, 0.5061180987f, 0.6168452203f, 0.7114893652f, 0.7877968946f, 0.8439898530f, + 0.8788075843f, 0.8915349645f, 0.8820165939f, 0.8506567100f, 0.7984048958f, 0.7267280723f, 0.6375695654f, 0.5332964054f, + 0.4166362696f, 0.2906057742f, 0.1584319899f, 0.0234692546f, -0.1108865770f, -0.2412842200f, -0.3645012037f, -0.4775241203f, + -0.5776228825f, -0.6624171300f, -0.7299331734f, -0.7786500916f, -0.8075339158f, -0.8160591222f, -0.8042170147f, -0.7725108907f, + -0.7219382530f, -0.6539606307f, -0.5704619141f, -0.4736963677f, -0.3662277643f, -0.2508612725f, -0.1305699260f, -0.0084175965f, + 0.1125195105f, 0.2292308248f, 0.3388468469f, 0.4387101575f, 0.5264402212f, 0.5999904058f, 0.6576958356f, 0.6983109662f, + 0.7210360284f, 0.7255318034f, 0.7119224786f, 0.6807866622f, 0.6331369228f, 0.5703885257f, 0.4943182949f, 0.4070147863f, + 0.3108211535f, 0.2082722739f, 0.1020278156f, -0.0051969757f, -0.1107009698f, -0.2118655199f, -0.3062197747f, -0.3915012914f, + -0.4657104605f, -0.5271574266f, -0.5745004072f, -0.6067745424f, -0.6234106746f, -0.6242437161f, -0.6095105484f, -0.5798376568f, + -0.5362189802f, -0.4799846893f, -0.4127618434f, -0.3364280618f, -0.2530595200f, -0.1648746973f, -0.0741754031f, 0.0167133565f, + 0.1055030935f, 0.1899996005f, 0.2681572959f, 0.3381288062f, 0.3983085785f, 0.4473694991f, 0.4842916874f, 0.5083828586f, + 0.5192898714f, 0.5170013229f, 0.5018412808f, 0.4744544796f, 0.4357835192f, 0.3870388112f, 0.3296621862f, 0.2652852328f, + 0.1956835517f, 0.1227281969f, 0.0483356232f, -0.0255825221f, -0.0971684532f, -0.1646648843f, -0.2264580855f, -0.2811163005f, + -0.3274226190f, -0.3644015563f, -0.3913387774f, -0.4077935926f, -0.4136040520f, -0.4088846629f, -0.3940169539f, -0.3696332868f, + -0.3365944947f, -0.2959620717f, -0.2489657697f, -0.1969675619f, -0.1414230072f, -0.0838410952f, -0.0257436705f, 0.0313744817f, + 0.0860838469f, 0.1370557180f, 0.1830941784f, 0.2231637715f, 0.2564122248f, 0.2821877493f, 0.3000505886f, 0.3097786572f, + 0.3113672668f, 0.3050231025f, 0.2911527592f, 0.2703462881f, 0.2433563271f, 0.2110734944f, 0.1744988056f, 0.1347139397f, + 0.0928502123f, 0.0500571304f, 0.0074713874f, -0.0338128732f, -0.0727717585f, -0.1084765990f, -0.1401155933f, -0.1670116352f, + -0.1886359510f, -0.2046172992f, -0.2147466154f, -0.2189771152f, -0.2174199887f, -0.2103359435f, -0.1981229573f, -0.1813006959f, + -0.1604921331f, -0.1364029689f, -0.1097994880f, -0.0814855216f, -0.0522791841f, -0.0229900383f, 0.0056026879f, 0.0327702587f, + 0.0578524543f, 0.0802730249f, 0.0995522334f, 0.1153162297f, 0.1273031071f, 0.1353655831f, 0.1394703527f, 0.1396942492f, + 0.1362174419f, 0.1293139704f, 0.1193399898f, 0.1067201472f, 0.0919325573f, 0.0754928613f, 0.0579378715f, 0.0398092914f, + 0.0216379870f, 0.0039292462f, -0.0128505743f, -0.0282856818f, -0.0420204769f, -0.0537669816f, -0.0633099271f, -0.0705094521f, + -0.0753014229f, -0.0776954715f, -0.0777709009f, -0.0756706792f, -0.0715937815f, -0.0657861933f, -0.0585309019f, -0.0501372415f, + -0.0409299405f, -0.0312382391f, -0.0213854050f, -0.0116789736f, -0.0024019780f, 0.0061945814f, 0.0138978546f, 0.0205376997f, + 0.0259896162f, 0.0301760169f, 0.0330658894f, 0.0346729129f, 0.0350521841f, 0.0342957066f, 0.0325268747f, 0.0298941639f, + 0.0265643082f, 0.0227151980f, 0.0185287912f, 0.0141842567f, 0.0098516209f, 0.0056860875f, 0.0018232500f, -0.0016247097f, + -0.0045716876f, -0.0069591888f, -0.0087566559f, -0.0099606909f, -0.0105931800f, -0.0106985104f, -0.0103399437f, -0.0095954160f, + -0.0085528538f, -0.0073053349f, -0.0059461694f, -0.0045642672f, -0.0032398065f, -0.0020405892f, -0.0010189826f, -0.0002098435f, + 0.0003708603f, 0.0007263907f, 0.0008791003f, 0.0008719916f, 0.0007765784f, 0.0006548666f, 0.0005262292f, 0.0003982537f, + 0.0002793177f, 0.0001753141f, 0.0000904043f, 0.0000267020f, -0.0000151645f, -0.0000359786f, -0.0000374823f, -0.0000222110f, + 0.0000068647f, 0.0000464960f, 0.0000934169f, 0.0001444514f, 0.0001966810f, 0.0002474932f, 0.0002946695f, 0.0003363826f, + 0.0003712266f, 0.0003981800f, 0.0004166001f, 0.0004261695f, 0.0004268735f, 0.0004189444f, 0.0004028356f, 0.0003791712f, + 0.0003487233f, 0.0003123700f, 0.0002710780f, 0.0002258678f, 0.0001778001f, 0.0001279460f, 0.0000773754f, 0.0000271305f, + -0.0000217852f, -0.0000684311f, -0.0001119393f, -0.0001515353f, -0.0001865458f, -0.0002164146f, -0.0002407060f, -0.0002591149f, + -0.0002714651f, -0.0002777121f, -0.0002779362f, -0.0002723393f, -0.0002612330f, -0.0002450307f, -0.0002242325f, -0.0001994145f, + -0.0001712119f, -0.0001403075f, -0.0001074144f, -0.0000732647f, -0.0000385932f, -0.0000041262f, 0.0000294329f, 0.0000614144f, + 0.0000911952f, 0.0001182080f, 0.0001419530f, 0.0001620054f, 0.0001780247f, 0.0001897598f, 0.0001970554f, 0.0001998531f, + 0.0001981941f, 0.0001922157f, 0.0001821496f, 0.0001683132f, 0.0001511033f, 0.0001309836f, 0.0001084739f, 0.0000841346f, + 0.0000585541f, 0.0000323319f, 0.0000060653f, -0.0000196656f, -0.0000443104f, -0.0000673606f, -0.0000883586f, -0.0001069066f, + -0.0001226716f, -0.0001353906f, -0.0001448717f, -0.0001509959f, -0.0001537153f, -0.0001530521f, -0.0001490949f, -0.0001419958f, + -0.0001319651f, -0.0001192675f, -0.0001042156f, -0.0000871648f, -0.0000685059f, -0.0000486591f, -0.0000280649f, -0.0000071771f, + 0.0000135476f, 0.0000336575f, 0.0000527172f, 0.0000703161f, 0.0000860792f, 0.0000996749f, 0.0001108247f, 0.0001193085f, + 0.0001249716f, 0.0001277272f, 0.0001275584f, 0.0001245179f, 0.0001187256f, 0.0001103637f, 0.0000996709f, 0.0000869347f, + 0.0001080714f, 0.0000990683f, 0.0000875489f, 0.0000737219f, 0.0000578554f, 0.0000402709f, 0.0000213391f, 0.0000014712f, + -0.0000188884f, -0.0000392732f, -0.0000592037f, -0.0000782001f, -0.0000957929f, -0.0001115356f, -0.0001250152f, -0.0001358638f, + -0.0001437678f, -0.0001484773f, -0.0001498120f, -0.0001476681f, -0.0001420207f, -0.0001329265f, -0.0001205227f, -0.0001050259f, + -0.0000867271f, -0.0000659874f, -0.0000432293f, -0.0000189302f, 0.0000063897f, 0.0000321758f, 0.0000578526f, 0.0000828338f, + 0.0001065369f, 0.0001283935f, 0.0001478642f, 0.0001644485f, 0.0001776986f, 0.0001872284f, 0.0001927257f, 0.0001939584f, + 0.0001907842f, 0.0001831541f, 0.0001711180f, 0.0001548245f, 0.0001345226f, 0.0001105567f, 0.0000833641f, 0.0000534651f, + 0.0000214568f, -0.0000120012f, -0.0000461970f, -0.0000803840f, -0.0001137931f, -0.0001456534f, -0.0001752051f, -0.0002017210f, + -0.0002245193f, -0.0002429841f, -0.0002565765f, -0.0002648525f, -0.0002674704f, -0.0002642056f, -0.0002549531f, -0.0002397370f, + -0.0002187078f, -0.0001921470f, -0.0001604577f, -0.0001241645f, -0.0000838982f, -0.0000403913f, 0.0000055419f, 0.0000530134f, + 0.0001010845f, 0.0001487757f, 0.0001950921f, 0.0002390326f, 0.0002796173f, 0.0003158959f, 0.0003469755f, 0.0003720281f, + 0.0003903206f, 0.0004012217f, 0.0004042346f, 0.0003990046f, 0.0003853554f, 0.0003632970f, 0.0003330658f, 0.0002951288f, + 0.0002502244f, 0.0001993576f, 0.0001438330f, 0.0000852306f, 0.0000254212f, -0.0000334924f, -0.0000891888f, -0.0001392362f, + -0.0001811447f, -0.0002125359f, -0.0002312354f, -0.0002355083f, -0.0002241797f, -0.0001969318f, -0.0001544184f, -0.0000986120f, + -0.0000328538f, 0.0000377552f, 0.0001064640f, 0.0001643821f, 0.0002009417f, 0.0002030084f, 0.0001564122f, 0.0000272101f, + -0.0002474236f, -0.0007077450f, -0.0013549123f, -0.0021692285f, -0.0031123474f, -0.0041302220f, -0.0051556983f, -0.0061124129f, + -0.0069187044f, -0.0074922749f, -0.0077547251f, -0.0076363116f, -0.0070802717f, -0.0060468886f, -0.0045167944f, -0.0024936150f, + -0.0000055857f, 0.0028937610f, 0.0061260810f, 0.0095897406f, 0.0131624981f, 0.0167051532f, 0.0200661755f, 0.0230870624f, + 0.0256083449f, 0.0274759454f, 0.0285477406f, 0.0287000110f, 0.0278335968f, 0.0258794506f, 0.0228034121f, 0.0186099337f, + 0.0133446258f, 0.0070954201f, -0.0000077076f, -0.0077945612f, -0.0160580606f, -0.0245590879f, -0.0330327072f, -0.0411956451f, + -0.0487548015f, -0.0554165787f, -0.0608967236f, -0.0649304010f, -0.0672821451f, -0.0677553773f, -0.0662011304f, -0.0625256765f, + -0.0566967379f, -0.0487480334f, -0.0387819173f, -0.0269699584f, -0.0135513300f, 0.0011710168f, 0.0168363911f, 0.0330344995f, + 0.0493155343f, 0.0652019647f, 0.0802017491f, 0.0938226053f, 0.1055869534f, 0.1150470840f, 0.1218001096f, 0.1255022179f, + 0.1258817753f, 0.1227508252f, 0.1160145780f, 0.1056785154f, 0.0918528133f, 0.0747538316f, 0.0547025267f, 0.0321197033f, + 0.0075181359f, -0.0185083336f, -0.0452985039f, -0.0721400382f, -0.0982878107f, -0.1229839236f, -0.1454788614f, -0.1650532162f, + -0.1810393625f, -0.1928424604f, -0.1999601464f, -0.2020003079f, -0.1986963539f, -0.1899194667f, -0.1756873734f, -0.1561692785f, + -0.1316866814f, -0.1027099283f, -0.0698504512f, -0.0338487823f, 0.0044414588f, 0.0440732723f, 0.0840292465f, 0.1232472348f, + 0.1606481100f, 0.1951648730f, 0.2257723487f, 0.2515166502f, 0.2715435877f, 0.2851251931f, 0.2916835749f, 0.2908113564f, + 0.2822880398f, 0.2660917210f, 0.2424057072f, 0.2116197075f, 0.1743254190f, 0.1313064718f, 0.0835228630f, 0.0320901527f, + -0.0217461395f, -0.0766403699f, -0.1311801252f, -0.1839222820f, -0.2334308512f, -0.2783156266f, -0.3172706001f, -0.3491110990f, + -0.3728086001f, -0.3875222240f, -0.3926259708f, -0.3877308633f, -0.3727012727f, -0.3476648529f, -0.3130156636f, -0.2694102425f, + -0.2177565698f, -0.1591960621f, -0.0950789218f, -0.0269333587f, 0.0435706287f, 0.1146620553f, 0.1845133465f, 0.2512872136f, + 0.3131848107f, 0.3684939113f, 0.4156358207f, 0.4532097440f, 0.4800333796f, 0.4951785767f, 0.4980010130f, 0.4881629819f, + 0.4656485511f, 0.4307705397f, 0.3841689741f, 0.3268008962f, 0.2599216377f, 0.1850578889f, 0.1039731292f, 0.0186261878f, + -0.0688760906f, -0.1563309363f, -0.2414952059f, -0.3221429964f, -0.3961238341f, -0.4614199206f, -0.5162009081f, -0.5588747253f, + -0.5881330481f, -0.6029901331f, -0.6028138835f, -0.5873482068f, -0.5567259364f, -0.5114718287f, -0.4524953996f, -0.3810736314f, + -0.2988238434f, -0.2076672897f, -0.1097842922f, -0.0075619595f, 0.0964642567f, 0.1996737260f, 0.2994269495f, 0.3931333240f, + 0.4783186205f, 0.5526904067f, 0.6141996858f, 0.6610970894f, 0.6919820919f, 0.7058438677f, 0.7020926210f, 0.6805804458f, + 0.6416110407f, 0.5859378797f, 0.5147507447f, 0.4296508188f, 0.3326148490f, 0.2259491718f, 0.1122346729f, -0.0057360023f, + -0.1250274487f, -0.2426350011f, -0.3555608763f, -0.4608910229f, -0.5558706911f, -0.6379767588f, -0.7049849023f, -0.7550298238f, + -0.7866568993f, -0.7988638266f, -0.7911310876f, -0.7634403277f, -0.7162800506f, -0.6506383584f, -0.5679827902f, -0.4702276607f, + -0.3596896122f, -0.2390324220f, -0.1112023801f, 0.0206441788f, 0.1532193990f, 0.2831865095f, 0.4072444271f, 0.5222121895f, + 0.6251110517f, 0.7132421052f, 0.7842573939f, 0.8362226383f, 0.8676698916f, 0.8776386903f, 0.8657045557f, 0.8319940114f, + 0.7771856339f, 0.7024969994f, 0.6096577639f, 0.5008694615f, 0.3787529642f, 0.2462848589f, 0.1067243047f, -0.0364678261f, + -0.1797154905f, -0.3194175307f, -0.4520389446f, -0.5742010518f, -0.6827682255f, -0.7749289589f, -0.8482691444f, -0.9008356561f, + -0.9311885385f, -0.9384404163f, -0.9222820323f, -0.8829932011f, -0.8214388065f, -0.7390498855f, -0.6377901922f, -0.5201090426f, + -0.3888815657f, -0.2473378465f, -0.0989827048f, 0.0524918607f, 0.2032993783f, 0.3496543888f, 0.4878683054f, 0.6144431772f, + 0.7261609761f, 0.8201660863f, 0.8940388909f, 0.9458585157f, 0.9742531243f, 0.9784364026f, 0.9582292951f, 0.9140663528f, + 0.8469865241f, 0.7586085363f, 0.6510914981f, 0.5270816374f, 0.3896465540f, 0.2421985725f, 0.0884091910f, -0.0678832812f, + -0.2227704771f, -0.3723727403f, -0.5129372944f, -0.6409334118f, -0.7531420237f, -0.8467376100f, -0.9193601068f, -0.9691751619f, + -0.9949209725f, -0.9959407463f, -0.9721996606f, -0.9242862434f, -0.8533978301f, -0.7613110254f, -0.6503400677f, -0.5232887671f, + -0.3833452070f, -0.2339716460f, -0.0788505878f, 0.0781931324f, 0.2332895986f, 0.3826182078f, 0.5225019620f, 0.6494973950f, + 0.7604792743f, 0.8527171215f, 0.9239423238f, 0.9724036977f, 0.9969105248f, 0.9968616872f, 0.9722604412f, 0.9237142440f, + 0.8524198184f, 0.7601336589f, 0.6491288368f, 0.5221390436f, 0.3822913495f, 0.2330292358f, 0.0780278756f, -0.0788963298f, + -0.2338796641f, -0.3831062116f, -0.5229017760f, -0.6498243415f, -0.7607488022f, -0.8529439154f, -0.9241395420f, -0.9725825570f, + -0.9970800142f, -0.9970285365f, -0.9724291748f, -0.9238873987f, -0.8525981906f, -0.7603166365f, -0.6493147113f, -0.5223253486f, + -0.3824751467f, -0.2332073920f, -0.0781972729f, 0.0787386074f, 0.2337362092f, 0.3829791953f, 0.5227929031f, 0.6497348216f, + 0.7606793588f, 0.8528947992f, 0.9241105706f, 0.9725731485f, 0.9970892373f, 0.9970551505f, 0.9724716796f, 0.9239440737f, + 0.8526671417f, 0.7603958321f, 0.6494020269f, 0.5224186015f, 0.3825721394f, 0.2333059467f, 0.0782952740f, -0.0786431789f, + -0.2336452368f, -0.3828943954f, -0.5227157923f, -0.6496666924f, -0.7606212560f, -0.8528475077f, -0.9240746034f, -0.9725487476f, + -0.9970763762f, -0.9970535479f, -0.9724808145f, -0.9239632108f, -0.8526953557f, -0.7604320409f, -0.6494450222f, -0.5224670848f, + -0.3826247539f, -0.2333613129f, -0.0783520192f, 0.0785863895f, 0.2335896751f, 0.3828412460f, 0.5226661333f, 0.6496214780f, + 0.7605813048f, 0.8528134912f, 0.9240470409f, 0.9725280010f, 0.9970626504f, 0.9970468907f, 0.9724811225f, 0.9239702338f, + 0.8527087070f, 0.7604512067f, 0.6494693756f, 0.5224958998f, 0.3826572234f, 0.2333965660f, 0.0783891427f, -0.0785483312f, + -0.2335516168f, -0.3828041004f, -0.5226307686f, -0.6495886980f, -0.7605518286f, -0.8527879374f, -0.9240259128f, -0.9725116771f, + -0.9970513761f, -0.9970407770f, -0.9724801457f, -0.9239742417f, -0.8527174266f, -0.7604642572f, -0.6494862818f, -0.5225161097f, + -0.3826801252f, -0.2334215076f, -0.0784154487f, 0.0785213402f, 0.2335246089f, 0.3827777168f, 0.5226056112f, 0.6495653171f, + 0.7605307154f, 0.8527695153f, 0.9240105331f, 0.9724996141f, 0.9970428253f, 0.9970358530f, 0.9724788823f, 0.9239765920f, + 0.8527232652f, 0.7604733819f, 0.6494984183f, 0.5225309161f, 0.3826971989f, 0.2334403933f, 0.0784356488f, -0.0785003550f, + -0.2335033857f, -0.3827568073f, -0.5225855558f, -0.6495466309f, -0.7605138718f, -0.8527549335f, -0.9239985644f, -0.9724905323f, + -0.9970368187f, -0.9970330198f, -0.9724792289f, -0.9239800349f, -0.8527296357f, -0.7604824344f, -0.6495098398f, -0.5225443385f, + -0.3827122124f, -0.2334565601f, -0.0784525165f, 0.0784832397f, 0.2334864657f, 0.3827405037f, 0.5225702598f, 0.6495326959f, + 0.7605016087f, 0.8527446058f, 0.9239903860f, 0.9724846653f, 0.9970333725f, 0.9970320501f, 0.9724807380f, 0.9239839714f, + 0.8527358952f, 0.7604908594f, 0.6495202224f, 0.5225564219f, 0.3827256949f, 0.2334710996f, 0.0784677378f, +}; + + +const float ivas_fb_resp_cheby_ramp_32del[IVAS_FB_1MS_32K_SAMP + 1] = +{ + 0.010231040569020f, 0.007495943710050f, 0.010178929162785f, 0.013398453336031f, + 0.017224667421257f, 0.021716621502222f, 0.026933804139047f, 0.032948050269901f, + 0.039809603616101f, 0.047574690662976f, 0.056302264669850f, 0.066034303975194f, + 0.076798058466510f, 0.088625188565940f, 0.101547758277136f, 0.115583678333348f, + 0.130755763247409f, 0.147071750845082f, 0.164507415202116f, 0.183014970904299f, + 0.202613741800170f, 0.223272731589440f, 0.244918942156018f, 0.267509604208255f, + 0.290972907623430f, 0.315243955993690f, 0.340239023615672f, 0.365855210507665f, + 0.392018902968585f, 0.418630748275114f, 0.445572918038597f, 0.472730394874248f, + 0.500000000000000f +}; + +const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1] = +{ + 0.010924831305822f, 0.013910402297200f, 0.022265243822209f, 0.033383809618597f, + 0.047654785522720f, 0.065424889526712f, 0.087005871336219f, 0.112572807795153f, + 0.142228383484898f, 0.175983302431557f, 0.213688773924401f, 0.255075179343390f, + 0.299758845354607f, 0.347229042543433f, 0.396890172892483f, 0.448063390053926f, + 0.500000000000000f +}; + +const int16_t ivas_num_active_bands[FB - WB + 1] = +{ + IVAS_16K_12BANDS_ACTIVE_BANDS, IVAS_FB_BANDS_12, IVAS_FB_BANDS_12 +}; + +#endif +/* clang-format on */ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h new file mode 100644 index 0000000..1260472 --- /dev/null +++ b/lib_com/ivas_rom_com.h @@ -0,0 +1,420 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_ROM_COM_H +#define IVAS_ROM_COM_H + +#include +#include "options.h" +#include "cnst_fx.h" +#include "ivas_cnst.h" +#include "typedef.h" +//#include "stat_com.h" +//#include "ivas_stat_com.h" +#ifdef DEBUGGING +#include "debug.h" +#endif + + +/*----------------------------------------------------------------------------------* + * General IVAS ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int32_t ivas_brate_tbl[]; +extern const int16_t fast_FCB_bits_2sfr[]; +extern const int16_t fast_FCB_rates_2sfr[]; + +#if 0 +/*------------------------------------------------------------------------- + * DFT Stereo ROM tables + *------------------------------------------------------------------------*/ + +extern const int16_t dft_band_limits_erb4[]; +extern const int16_t dft_band_limits_erb8[]; +extern const int16_t dft_band_ipd[3][4]; +extern const int16_t dft_band_res_cod[3][4]; + +extern const float dft_res_gains_q[][2]; +extern const float dft_res_cod_alpha[STEREO_DFT_BAND_MAX]; + +extern const float dft_trigo_12k8[STEREO_DFT_N_12k8_ENC / 4 + 1]; +extern const float dft_trigo_32k[STEREO_DFT_N_32k_ENC / 4 + 1]; +extern const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1]; + +/* Golomb-Rice encoding tables */ +extern const int16_t dft_maps_rpg[]; +extern const int16_t dft_code_itd[]; +extern const int16_t dft_len_itd[]; +extern const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G]; + +/*----------------------------------------------------------------------------------* + * Range Coder ROM tables + *----------------------------------------------------------------------------------*/ + +extern const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS]; +extern const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; + +/*----------------------------------------------------------------------------------* + * ECLVQ Stereo ROM tables + *----------------------------------------------------------------------------------*/ + +extern const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE]; + +/*----------------------------------------------------------------------------------* + * Stereo ICA ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float ica_sincInterp2[]; +extern const float ica_sincInterp4[]; +extern const float ica_sincInterp6[]; + +/*----------------------------------------------------------------------------------* + * Stereo IC-BWE ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float icbwe_gsMapping_tbl[]; +extern const float icbwe_gsMappingDFT_tbl[]; + +/*----------------------------------------------------------------------------------* + * TD Stereo ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float tdm_ratio_tabl[]; +extern const float tdm_den_ratio_tabl[]; +extern const int16_t tdm_bit_allc_tbl[5][6]; + +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +/* LSFs Intra-frame prediction tables */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +extern const float tdm_LSF_MEAN_RE_USE_OUT[M]; +extern const float tdm_LSF_MEAN_RE_USE_IN[M]; +extern const float tdm_LSF_MEAN_RE_USE[M]; + +extern const float tdm_Beta_Q1bit_re_use_132[2]; +extern const float tdm_Beta_Q1bit_re_use_164[2]; +extern const float tdm_Beta_Q1bit_re_use_244_320[2]; +extern const float tdm_Beta_Q1bit_re_use_480[2]; + +extern const float tdm_RE_USE_adaptive_beta_prd_diag_3[15 + 16 + 15]; +#endif + +extern const float tdm_LSF_MEAN_PRED_QNT_OUT[M]; +extern const float tdm_LSF_MEAN_PRED_QNT_IN[M]; +extern const float tdm_LSF_MEAN_PRED_QNT[M]; +extern const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15]; +#endif + + +/*----------------------------------------------------------------------------------* + * MDCT Stereo ROM tables + *----------------------------------------------------------------------------------*/ + +extern const SpectrumWarping sw16000Hz[]; /* PsychLPC */ +extern const SpectrumWarping sw25600Hz[]; /* PsychLPC */ +extern const SpectrumWarping sw32000Hz[]; /* PsychLPC */ + +extern const MDCTStereoBands_config mdctStereoBands_32000_640[]; +extern const float nf_tw_smoothing_coeffs[N_LTP_GAIN_MEMS]; + +/*----------------------------------------------------------------------------------* + * Stereo DTX ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float dft_cng_coh_pred[][STEREO_DFT_COH_PRED_COEFFS]; +extern const int16_t dft_cng_coh_u2i[9]; +extern const int16_t dft_cng_coh_i2u[9]; +extern const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS]; +extern const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1]; + +/*----------------------------------------------------------------------------------* + * DirAC ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float diffuseness_reconstructions[DIRAC_DIFFUSE_LEVELS]; +extern const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1]; +extern const int16_t DirAC_band_grouping_12[12 + 1]; +extern const int16_t DirAC_band_grouping_6[6 + 1]; +extern const int16_t DirAC_band_grouping_5[5 + 1]; +extern const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; +extern const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; + +/*------------------------------------------------------------------------------------------* + * SPAR ROM tables + *------------------------------------------------------------------------------------------*/ + +#ifdef FIX_SBA_CLEAN_UP_OPT +extern const ivas_freq_models_t ivas_arith_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ARITH]; +extern const ivas_freq_models_t ivas_arith_drct_r_consts[TOTAL_DRCT_QUANT_STRATS]; +extern const ivas_freq_models_t ivas_arith_decd_r_consts[TOTAL_DECD_QUANT_STRATS]; +extern const ivas_huff_models_t ivas_huff_pred_r_consts[TOTAL_PRED_QUANT_STRATS_HUFF]; +extern const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS]; +extern const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS]; +#endif +extern const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN]; +#ifndef FIX_SBA_CLEAN_UP_OPT +extern const ivas_arith_consts_t ivas_arith_consts[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS]; +extern const ivas_huff_consts_t ivas_huff_const[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS]; +#endif +extern const int16_t remix_order_set[1][IVAS_SPAR_MAX_CH]; +extern const int16_t keep_planar[IVAS_SPAR_MAX_CH - FOA_CHANNELS]; +extern const int16_t HOA_keep_ind[IVAS_SPAR_MAX_CH]; + +extern const float dtx_pd_real_min_max[2]; +extern const int16_t dtx_pd_real_q_levels[3][3]; +extern const int16_t dtx_pr_real_q_levels[3][3]; +extern const int16_t pr_pr_idx_pairs[3][3][2]; +extern const int16_t pr_pd_idx_pairs[3][3][2]; + + +/*----------------------------------------------------------------------* + * PCA ROM tables + *-----------------------------------------------------------------------*/ + +extern const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1]; +extern const int16_t ivas_pca_offset_index2[2692]; +extern const int16_t ivas_pca_offset_n2[IVAS_PCA_N1]; + + +/*----------------------------------------------------------------------------------* + * Parametric MC ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int16_t param_mc_band_grouping_20[20 + 1]; +extern const int16_t param_mc_coding_band_mapping_20[20]; +extern const int16_t param_mc_bands_coded_20[4]; +extern const int16_t param_mc_band_grouping_14[14 + 1]; +extern const int16_t param_mc_coding_band_mapping_14[14]; +extern const int16_t param_mc_bands_coded_14[4]; +extern const int16_t param_mc_band_grouping_10[10 + 1]; +extern const int16_t param_mc_coding_band_mapping_10[10]; +extern const int16_t param_mc_bands_coded_10[4]; +extern const int16_t param_mc_start_bin_per_band_20[20]; +extern const int16_t param_mc_active_bins_per_band_20[20]; +extern const int16_t param_mc_start_bin_per_band_14[14]; +extern const int16_t param_mc_active_bins_per_band_14[14]; +extern const int16_t param_mc_start_bin_per_band_10[10]; +extern const int16_t param_mc_active_bins_per_band_10[10]; +extern const int16_t Param_MC_index[MAX_CICP_CHANNELS]; +extern const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS]; +extern const float ivas_param_mc_quant_ild_5d1_48[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + + +/*----------------------------------------------------------------------------------* + * MASA ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS]; +extern const int16_t no_theta_masa[NO_SPHERICAL_GRIDS - 2]; +extern const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA]; + +extern const float delta_theta_masa[NO_SPHERICAL_GRIDS - 2]; + +extern const float azimuth_cb[8]; +extern const float coherence_cb0_masa[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH]; +extern const float coherence_cb1_masa[MASA_NO_CV_COH1 * MASA_MAXIMUM_CODING_SUBBANDS]; /* 25 */ +extern const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS]; +extern const uint8_t sur_coherence_cb_masa[MASA_NO_CB_SUR_COH * MASA_MAX_NO_CV_SUR_COH]; +extern const int16_t idx_cb_sur_coh_masa[MASA_NO_CV_COH]; +extern const int16_t len_huf_masa[MASA_NO_CV_COH1]; +extern const int16_t huff_code_av_masa[MASA_NO_CV_COH1]; + +extern const int16_t MASA_band_grouping_24[24 + 1]; +extern const int16_t MASA_band_mapping_24_to_18[18 + 1]; +extern const int16_t MASA_band_mapping_24_to_12[12 + 1]; +extern const int16_t MASA_band_mapping_24_to_8[8 + 1]; +extern const int16_t MASA_band_mapping_24_to_5[5 + 1]; + +extern const int16_t MASA_grouping_8_to_5[8]; +extern const int16_t MASA_grouping_12_to_5[12]; +extern const int16_t MASA_grouping_18_to_5[18]; +extern const int16_t MASA_grouping_24_to_5[24]; +extern const int16_t masa_bits[14]; +extern const int16_t masa_bits_LR_stereo[4]; +extern const int16_t mcmasa_bits[]; +extern const uint8_t masa_nbands[]; +extern const uint8_t masa_joined_nbands[]; +extern const uint8_t masa_twodir_bands[]; +extern const uint8_t masa_twodir_bands_joined[]; + +/* Multi-channel input and output setups */ +extern const float ls_azimuth_CICP2[2]; +extern const float ls_elevation_CICP2[2]; +extern const float ls_azimuth_CICP6[5]; +extern const float ls_elevation_CICP6[5]; +extern const float ls_azimuth_CICP12[7]; +extern const float ls_elevation_CICP12[7]; +extern const float ls_azimuth_CICP14[7]; +extern const float ls_elevation_CICP14[7]; +extern const float ls_azimuth_CICP16[9]; +extern const float ls_elevation_CICP16[9]; +extern const float ls_azimuth_CICP19[11]; +extern const float ls_elevation_CICP19[11]; + +extern const float cb_azi_chan[]; + +extern const float McMASA_LFEGain_vectors[64]; + +/*----------------------------------------------------------------------------------* + * ISM ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float ism_azimuth_borders[4]; +extern const float ism_elevation_borders[4]; + +/*----------------------------------------------------------------------------------* + * Param ISM ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1]; + + +/*----------------------------------------------------------------------------------* + * LFE coding ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float ivas_lpf_4_butter_16k_sos[IVAS_BIQUAD_FILT_LEN << 2]; +extern const float ivas_lpf_4_butter_32k_sos[IVAS_BIQUAD_FILT_LEN << 2]; +extern const float ivas_lpf_4_butter_48k_sos[IVAS_BIQUAD_FILT_LEN << 2]; +extern const float ivas_lpf_2_butter_16k[IVAS_BIQUAD_FILT_LEN << 1]; +extern const float ivas_lpf_2_butter_32k[IVAS_BIQUAD_FILT_LEN << 1]; +extern const float ivas_lpf_2_butter_48k[IVAS_BIQUAD_FILT_LEN << 1]; + +extern const float ivas_lfe_window_coeff_48k[IVAS_LFE_FADE_LEN_48K]; +extern const float ivas_lfe_window_coeff_32k[IVAS_LFE_FADE_LEN_32K]; +extern const float ivas_lfe_window_coeff_16k[IVAS_LFE_FADE_LEN_16K]; + +extern const int16_t ivas_lfe_num_ele_in_coder_models[2][4]; +extern const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; +extern const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; +extern const ivas_lfe_freq_models ivas_str_lfe_freq_models; +extern const float ivas_lfe_lpf_delay[2]; + +extern const double d_hamm_lfe_plc[LFE_PLC_LENANA / 2]; + +extern const float ivas_sin_twiddle_480[IVAS_480_PT_LEN >> 1]; +extern const float ivas_cos_twiddle_480[IVAS_480_PT_LEN >> 1]; +extern const float ivas_sin_twiddle_320[IVAS_320_PT_LEN >> 1]; +extern const float ivas_cos_twiddle_320[IVAS_320_PT_LEN >> 1]; +extern const float ivas_sin_twiddle_160[IVAS_160_PT_LEN >> 1]; +extern const float ivas_cos_twiddle_160[IVAS_160_PT_LEN >> 1]; +extern const float ivas_sin_twiddle_80[IVAS_80_PT_LEN >> 1]; +extern const float ivas_cos_twiddle_80[IVAS_80_PT_LEN >> 1]; + +/*------------------------------------------------------------------------------------------* + * MDFT/iMDFT ROM tables + *------------------------------------------------------------------------------------------*/ + +extern const float ivas_mdft_coeff_cos_twid_240[IVAS_240_PT_LEN + 1]; +extern const float ivas_mdft_coeff_sin_twid_240[IVAS_240_PT_LEN]; +extern const float ivas_mdft_coeff_cos_twid_160[IVAS_160_PT_LEN + 1]; +extern const float ivas_mdft_coeff_sin_twid_160[IVAS_160_PT_LEN]; +extern const float ivas_mdft_coeff_cos_twid_80[IVAS_80_PT_LEN + 1]; +extern const float ivas_mdft_coeff_sin_twid_80[IVAS_80_PT_LEN]; +extern const float ivas_mdft_coeff_cos_twid_40[IVAS_40_PT_LEN + 1]; +extern const float ivas_mdft_coeff_sin_twid_40[IVAS_40_PT_LEN]; + +extern const float ivas_mdft_coeff_cos_twid_960[IVAS_960_PT_LEN + 1]; +extern const float ivas_mdft_coeff_sin_twid_960[IVAS_960_PT_LEN]; +extern const float ivas_mdft_coeff_cos_twid_640[IVAS_640_PT_LEN + 1]; +extern const float ivas_mdft_coeff_sin_twid_640[IVAS_640_PT_LEN]; +extern const float ivas_mdft_coeff_cos_twid_320[IVAS_320_PT_LEN + 1]; +extern const float ivas_mdft_coeff_sin_twid_320[IVAS_320_PT_LEN]; + +extern const int16_t dirac_gains_P_idx[16]; +extern const float dirac_gains_norm_term[9]; +extern const float dirac_gains_Pnm[91][9]; +extern const float dirac_gains_trg_term[181][2]; + +/*------------------------------------------------------------------------------------------* + * FB ROM tables + *------------------------------------------------------------------------------------------*/ + +extern const float ivas_fb_fcs_12band_1ms[IVAS_FB_BANDS_12]; + +extern const float ivas_fb_fr_12band_1ms_re[IVAS_FB_12_1MS_LEN]; +extern const float ivas_fb_fr_12band_1ms_im[IVAS_FB_12_1MS_LEN]; + +extern const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; + +extern const float ivas_fb_cf_4ms_48k[IVAS_FB_4MS_48K_SAMP]; +extern const float ivas_fb_cf_1ms_48k[IVAS_FB_1MS_48K_SAMP]; +extern const float ivas_fb_cf_4ms_32k[IVAS_FB_4MS_32K_SAMP]; +extern const float ivas_fb_cf_1ms_32k[IVAS_FB_1MS_32K_SAMP]; +extern const float ivas_fb_cf_4ms_16k[IVAS_FB_4MS_16K_SAMP]; +extern const float ivas_fb_cf_1ms_16k[IVAS_FB_1MS_16K_SAMP]; + +extern const float ivas_fb_resp_cheby_ramp_32del[IVAS_FB_1MS_32K_SAMP + 1]; +extern const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1]; + +extern const int16_t ivas_num_active_bands[FB - WB + 1]; +#endif +/* IVAS_ROM_COM_H */ +#endif diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h new file mode 100644 index 0000000..e4adbcd --- /dev/null +++ b/lib_com/ivas_stat_com.h @@ -0,0 +1,793 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_STAT_COM +#define IVAS_STAT_COM + +#include +#include "options.h" +#include "typedef.h" +#include "cnst_fx.h" +#include "ivas_cnst.h" + + +/*----------------------------------------------------------------------------------* + * Declaration of ISm common (encoder & decoder) structure + *----------------------------------------------------------------------------------*/ + +/* ISM metadata handle (storage for one frame of read ISM metadata) */ +typedef struct +{ + int16_t ism_metadata_flag; /* flag whether metadata are coded in particular frame of particular object */ + int16_t last_ism_metadata_flag; /* last frame ism_metadata_flag */ + + float azimuth; /* azimuth value read from the input metadata file */ + float elevation; /* azimuth value read from the input metadata file */ + + int16_t last_azimuth_idx; /* last frame index of coded azimuth */ + int16_t azimuth_diff_cnt; /* FEC counter of consecutive differentially azimuth coded frames */ + int16_t last_elevation_idx; /* last frame index of coded elevation */ + int16_t elevation_diff_cnt; /* FEC counter of consecutive differentially elevation coded frames */ + +} ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Declaration of DFT Stereo common (encoder & decoder) structure + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_dft_config_data_struct +{ + int16_t dmx_active; + int16_t band_res; + int16_t prm_res; /* Send prm every # DFT frames */ +#ifdef DEBUG_MODE_DFT + int16_t gipd_mode; /* mode : from 0 (off) to 1 (on) */ + int16_t itd_mode; /* mode : from 0 (off) to 1 (on) */ +#endif + int16_t res_pred_mode; /* mode : from 0 (off) to 1 (on) */ + int16_t res_cod_mode; /* mode : from 0 (off) to 3 */ + int16_t hybrid_itd_flag; + int16_t ada_wb_res_cod_mode; /* res_cod_mode for adaptive wide band residual coding */ + + int16_t force_mono_transmission; + +} STEREO_DFT_CONFIG_DATA, *STEREO_DFT_CONFIG_DATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Declaration of MDCT stereo common (encoder & decoder) structure + *----------------------------------------------------------------------------------*/ + +typedef struct +{ + uint8_t const bandLengthsTCX20[SMDCT_MAX_STEREO_BANDS_TCX20]; /* Length of a band in number of bins. Range is 4..160 */ + const int16_t bdnCnt_TCX20[4]; /* uppermost band for FB,SWB,WB,NB */ + uint8_t const bandLengthsTCX10[SMDCT_MAX_STEREO_BANDS_TCX10]; /* Length of a band in number of bins. Range is 2..80, always divisible by 2 */ + const int16_t bndCnt_TCX10[4]; /* uppermost band for FB,SWB,WB,NB */ + +} MDCTStereoBands_config; + +/* MDCT stereo frequency band structure */ +typedef struct stereo_mdct_dec_band_parameters_struct +{ + int16_t sfbOffset[MAX_SFB + 1]; /* stereo frequency band start offsets */ + int16_t sfbCnt; /* number of stereo frequency bands */ + int16_t nBandsStereoCore; /* number of stereo frequency bands in the core */ + int16_t sfbIgfStart; /*index for first IGF band*/ + +} STEREO_MDCT_BAND_PARAMETERS; + + +/*----------------------------------------------------------------------------------* + * Declaration of ECLVQ common (encoder & decoder) structure + *----------------------------------------------------------------------------------*/ + +typedef struct +{ + int16_t config_index; + int16_t encoding_active; /* internal state specifying if actual encoding is active or only length evaluation is active */ + int32_t bit_count_estimate; /* uses 22Q10 fixed-point representation */ + void *ac_handle; + +} ECSQ_instance; + +/*----------------------------------------------------------------------------------* + * PARAMETRIC ISM encoder/decoder (common) structure + *----------------------------------------------------------------------------------*/ +typedef struct ivas_param_ism_data_structure +{ + int16_t nbands; + int16_t nblocks[MAX_PARAM_ISM_NBANDS]; + int16_t band_grouping[MAX_PARAM_ISM_NBANDS + 1]; + int16_t num_obj; + + int16_t azi_index[MAX_NUM_OBJECTS]; + int16_t ele_index[MAX_NUM_OBJECTS]; + + int16_t obj_indices[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; + int16_t power_ratios_idx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS]; + + int16_t last_az_sgn[MAX_NUM_OBJECTS]; + int16_t last_az_diff[MAX_NUM_OBJECTS]; + int16_t last_el_sgn[MAX_NUM_OBJECTS]; + int16_t last_el_diff[MAX_NUM_OBJECTS]; + + int16_t flag_noisy_speech; + int16_t noisy_speech_buffer[PARAM_ISM_HYS_BUF_SIZE]; + +} PARAM_ISM_CONFIG_DATA, *PARAM_ISM_CONFIG_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Declaration of DirAC common (encoder & decoder) structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_dirac_config_data_struct +{ + int16_t enc_param_start_band; + int16_t dec_param_estim; + int16_t nbands; + +} DIRAC_CONFIG_DATA, *DIRAC_CONFIG_DATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Declaration of SPAR common structures + *----------------------------------------------------------------------------------*/ + +/* SPAR MD structures */ +typedef struct ivas_band_coeffs_t +{ + float pred_re[IVAS_SPAR_MAX_CH - 1]; + float C_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + float P_re[IVAS_SPAR_MAX_CH - 1]; + float pred_quant_re[IVAS_SPAR_MAX_CH - 1]; + float C_quant_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + float P_quant_re[IVAS_SPAR_MAX_CH - 1]; + +} ivas_band_coeffs_t; + +typedef struct ivas_band_coeffs_ind_t +{ + int16_t pred_index_re[IVAS_SPAR_MAX_CH - 1]; + int16_t drct_index_re[IVAS_SPAR_MAX_C_COEFF]; + int16_t decd_index_re[IVAS_SPAR_MAX_CH - 1]; + +} ivas_band_coeffs_ind_t; + +typedef struct ivas_spar_md_t +{ +#ifndef FIX_SBA_CLEAN_UP_OPT + ivas_band_coeffs_t band_coeffs[IVAS_MAX_NUM_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES]; +#else + ivas_band_coeffs_t *band_coeffs; +#endif + ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS]; + int16_t num_bands; + float min_max[2]; + int16_t dtx_vad; + float en_ratio_slow[IVAS_MAX_NUM_BANDS]; + float ref_pow_slow[IVAS_MAX_NUM_BANDS]; +} ivas_spar_md_t; + +typedef struct ivas_spar_md_prev_t +{ + ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS]; + ivas_band_coeffs_ind_t band_coeffs_idx_mapped[IVAS_MAX_NUM_BANDS]; + +} ivas_spar_md_prev_t; + +typedef struct ivas_quant_coeffs_t +{ + float min; + float max; + int16_t q_levels[2]; + +} ivas_quant_coeffs_t; + +typedef struct ivas_quant_strat_t +{ + ivas_quant_coeffs_t PR; + ivas_quant_coeffs_t C; + ivas_quant_coeffs_t P_r; + ivas_quant_coeffs_t P_c; + +} ivas_quant_strat_t; + +#ifndef FIX_SBA_CLEAN_UP_OPT +typedef struct ivas_spar_foa_md_com_cfg +{ + int16_t max_freq_per_chan[IVAS_SPAR_MAX_CH]; + int16_t num_dmx_chans_per_band[IVAS_MAX_NUM_BANDS]; + int16_t num_decorr_per_band[IVAS_MAX_NUM_BANDS]; + int16_t active_w; + int16_t remix_unmix_order; + ivas_quant_strat_t quant_strat[MAX_QUANT_STRATS]; + int16_t gen_bs; + int16_t quant_strat_bits; + int16_t nchan_transport; + int16_t num_quant_strats; + int16_t prior_strat; + int16_t tgt_bits_per_blk; + int16_t max_bits_per_blk; + int16_t prev_quant_idx; + int16_t agc_bits_ch_idx; + int16_t planarCP; + int16_t num_umx_chs; + +} ivas_spar_foa_md_com_cfg; +#else +typedef struct ivas_spar_md_com_cfg +{ + int16_t max_freq_per_chan[IVAS_SPAR_MAX_CH]; + int16_t num_dmx_chans_per_band[IVAS_MAX_NUM_BANDS]; + int16_t num_decorr_per_band[IVAS_MAX_NUM_BANDS]; + int16_t active_w; + int16_t remix_unmix_order; + ivas_quant_strat_t quant_strat[MAX_QUANT_STRATS]; + int16_t gen_bs; + int16_t quant_strat_bits; + int16_t nchan_transport; + int16_t num_quant_strats; + int16_t prior_strat; + int16_t tgt_bits_per_blk; + int16_t max_bits_per_blk; + int16_t prev_quant_idx; + int16_t agc_bits_ch_idx; + int16_t planarCP; + int16_t num_umx_chs; + +} ivas_spar_md_com_cfg; +#endif + + +/* arithmetic coder structures */ +typedef struct ivas_cell_dim_t +{ + int16_t dim1; + int16_t dim2; + +} ivas_cell_dim_t; + +typedef struct ivas_freq_models_t +{ + int16_t freq_model[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; + int16_t diff_freq_model[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; + int16_t vals[IVAS_MAX_QUANT_LEVELS]; + int16_t diff_vals[IVAS_MAX_QUANT_LEVELS]; + int16_t num_models; + int16_t diff_num_models; + +} ivas_freq_models_t; + +typedef struct ivas_huff_models_t +{ + int16_t code_book[IVAS_MAX_QUANT_LEVELS][3]; + int16_t diff_code_book[IVAS_MAX_QUANT_LEVELS][3]; + +} ivas_huff_models_t; + +#ifndef FIX_SBA_CLEAN_UP_OPT +typedef struct ivas_arith_consts_t +{ + ivas_freq_models_t pred_r; + ivas_freq_models_t drct_r; + ivas_freq_models_t decd_r; +} ivas_arith_consts_t; + +typedef struct ivas_huff_const_t +{ + ivas_huff_models_t pred_r; + ivas_huff_models_t drct_r; + ivas_huff_models_t decd_r; +} ivas_huff_consts_t; +#endif + +/* Entropy coder structures */ +typedef struct ivas_huffman_cfg_t +{ + const int16_t *codebook; + int16_t min_len; + int16_t max_len; + int16_t sym_len; + +} ivas_huffman_cfg_t; + +typedef struct ivas_arith_t +{ + int16_t dyn_model_bits; + const int16_t *pFreq_model; + const int16_t *pAlt_freq_models[IVAS_NUM_PROB_MODELS]; + const int16_t *vals; + int16_t cum_freq[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; + int16_t range; + int16_t num_models; + float saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; + +} ivas_arith_t; + +typedef struct ivas_arith_coeffs_t +{ + ivas_arith_t pred_arith_re[MAX_QUANT_STRATS]; + ivas_arith_t drct_arith_re[MAX_QUANT_STRATS]; + ivas_arith_t decd_arith_re[MAX_QUANT_STRATS]; + ivas_arith_t pred_arith_re_diff[MAX_QUANT_STRATS]; + ivas_arith_t drct_arith_re_diff[MAX_QUANT_STRATS]; + ivas_arith_t decd_arith_re_diff[MAX_QUANT_STRATS]; + +} ivas_arith_coeffs_t; + +typedef struct ivas_huff_coeffs_t +{ + ivas_huffman_cfg_t pred_huff_re[MAX_QUANT_STRATS]; + ivas_huffman_cfg_t drct_huff_re[MAX_QUANT_STRATS]; + ivas_huffman_cfg_t decd_huff_re[MAX_QUANT_STRATS]; + +} ivas_huff_coeffs_t; + +/* AGC structures */ +typedef struct ivas_agc_chan_data_t +{ + int16_t gainException; + int16_t absGainExp; + int16_t absGainExpCurr; + +} ivas_agc_chan_data_t; + +typedef struct ivas_agc_com_state_t +{ + float *winFunc; + int16_t in_delay; + uint16_t absEmin; + uint16_t betaE; + uint16_t maxAttExp; + uint16_t num_coeff; + +} ivas_agc_com_state_t; + +/* Covariance structures */ +typedef struct ivas_cov_smooth_state_t +{ + float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + int16_t prior_bank_idx; + float *pSmoothing_factor; + int16_t num_bins; + +} ivas_cov_smooth_state_t; + +typedef struct ivas_cov_smooth_cfg_t +{ + float max_update_rate; + int16_t min_pool_size; + int16_t max_bands; + int16_t num_bins; + +} ivas_cov_smooth_cfg_t; + +typedef struct ivas_cov_smooth_in_buf_t +{ + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + int16_t num_ch; + int16_t reset_cov; + +} ivas_cov_smooth_in_buf_t; + +/* SPAR bitrate constant table structure */ +typedef struct ivas_spar_br_table_t +{ + int32_t ivas_total_brate; + int16_t isPlanar; + int16_t sba_order; + int16_t bwidth; + int16_t fpcs; + int16_t nchan_transport; +#ifndef FIX_SBA_CLEAN_UP_OPT + ivas_spar_foa_pmx_strings_t dmx_str; +#else + ivas_spar_pmx_strings_t dmx_str; +#endif + int16_t active_w; + int16_t tmode; + int32_t evs_brs[FOA_CHANNELS][3]; + int16_t q_lvls[MAX_QUANT_STRATS][NUM_MD_Q_COEFS_SET]; + int16_t td_ducking; + int16_t agc_bits_ch_idx; /* 0-3, Indicates core-coder channel index from which AGC bits have been taken from*/ + int16_t usePlanarCoeff; +} ivas_spar_br_table_t; + + +/*----------------------------------------------------------------------------------* + * Declaration of MASA common structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_MASA_spherical_grid_deindexing +{ + float theta_cb[NO_THETA16_MAX]; + int16_t no_theta; + int16_t no_phi[NO_THETA16_MAX]; + +} SPHERICAL_GRID_DATA; + +typedef struct ivas_masa_descriptive_meta_struct +{ + uint8_t formatDescriptor[8]; /* 8x 8 bits */ + uint8_t numberOfDirections; /* 1 bit */ + uint8_t numberOfChannels; /* 1 bit */ + uint8_t sourceFormat; /* 2 bits */ + uint8_t transportDefinition; /* 3 bits */ + uint8_t channelAngle; /* 3 bits */ + uint8_t channelDistance; /* 6 bits */ + uint8_t channelLayout; /* 3 bits, used only when sourceFormat == bit value 10 */ + +} MASA_DECRIPTIVE_META; + +typedef struct ivas_masa_directional_spatial_meta_struct +{ + float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float elevation[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + +} MASA_DIRECTIONAL_SPATIAL_META; + +typedef struct ivas_masa_common_spatial_meta_struct +{ + float diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float remainder_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + +} MASA_COMMON_SPATIAL_META; + +typedef struct ivas_masa_metadata_frame_struct +{ + MASA_DECRIPTIVE_META descriptive_meta; + MASA_DIRECTIONAL_SPATIAL_META directional_meta[MASA_MAXIMUM_DIRECTIONS]; + MASA_COMMON_SPATIAL_META common_meta; + +} MASA_METADATA_FRAME, *MASA_METADATA_HANDLE; + +typedef struct ivas_masa_config_struct +{ + uint16_t max_metadata_bits; + int16_t block_grouping[5]; + int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; + uint8_t numCodingBands; + uint8_t numTwoDirBands; + uint8_t numberOfDirections; + uint8_t joinedSubframes; + uint8_t useCoherence; + uint8_t coherencePresent; + uint8_t mergeRatiosOverSubframes; + +} MASA_CODEC_CONFIG; + + +/*----------------------------------------------------------------------------------* + * Declaration of Qmetadata common structures + *----------------------------------------------------------------------------------*/ + +typedef struct +{ + int16_t nbands; + int16_t nblocks; + int16_t start_band; + int16_t search_effort; + MC_LS_SETUP mc_ls_setup; + +} IVAS_METADATA_CONFIG; + +typedef struct ivas_qdirection_band_data_struct +{ + uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; + float elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; + + float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint8_t distance[MAX_PARAM_SPATIAL_SUBFRAMES]; + + uint16_t bits_sph_idx[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint16_t energy_ratio_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint16_t energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint16_t azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES]; + float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; + float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; +} IVAS_QDIRECTION_BAND_DATA; + +typedef struct ivas_qdirection_band_coherence_data_struct +{ + uint8_t spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint16_t spread_coherence_dct0_index; + uint16_t spread_coherence_dct1_index; + +} IVAS_QDIRECTION_BAND_COHERENCE_DATA; + +typedef struct ivas_surround_coherence_band_data_struct +{ + uint8_t surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint16_t sur_coherence_index; + +} IVAS_SURROUND_COHERENCE_BAND_DATA; + + +typedef struct +{ + IVAS_METADATA_CONFIG cfg; + + IVAS_QDIRECTION_BAND_DATA *band_data; + IVAS_QDIRECTION_BAND_COHERENCE_DATA *coherence_band_data; + int16_t not_in_2D; + +} IVAS_QDIRECTION; /* IVAS_QMETADATA; */ + +typedef struct ivas_masa_qmetadata_frame_struct +{ + IVAS_QDIRECTION *q_direction; + uint16_t no_directions; + int16_t bits_frame_nominal; + uint16_t coherence_flag; + uint8_t all_coherence_zero; + uint8_t twoDirBands[MASA_MAXIMUM_CODING_SUBBANDS]; + uint8_t numTwoDirBands; + int16_t qmetadata_max_bit_req; + int16_t metadata_max_bits; /* maximum allowed number of bits for metadata per frame */ + uint8_t useLowerRes; + uint8_t useLowerBandRes; + IVAS_SURROUND_COHERENCE_BAND_DATA *surcoh_band_data; + + /* Additional helper values to include all data required for writing to output file */ + uint8_t numCodingBands; + int16_t *bandMap; + int16_t nchan_transport; + int16_t sba_inactive_mode; + /* Status values on metadata quality */ + int16_t ec_flag; + float dir_comp_ratio; + uint8_t is_masa_ivas_format; +} IVAS_QMETADATA, *IVAS_QMETADATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Declaration of Parametric MC common (encoder & decoder) structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_param_mc_ild_mapping_struct +{ + int16_t ild_map_size_wo_lfe; + int16_t ild_map_size_lfe; + int16_t ild_index[MAX_CICP_CHANNELS]; + int16_t num_ref_channels[MAX_CICP_CHANNELS]; + int16_t ref_channel_idx[MAX_CICP_CHANNELS][PARAM_MC_MAX_ILD_REF_CHANNELS]; + +} PARAM_MC_ILD_MAPPING, *HANDLE_PARAM_MC_ILD_MAPPING; + +typedef struct ivas_param_mc_icc_mapping_struct +{ + int16_t icc_map_size_wo_lfe; + int16_t icc_map_size_lfe; + int16_t icc_mapping[PARAM_MC_SZ_ICC_MAP][2]; + +} PARAM_MC_ICC_MAPPING, *HANDLE_PARAM_MC_ICC_MAPPING; + +typedef struct ivas_param_mc_conf_struct /* structure for ROM Table */ +{ + MC_LS_SETUP mc_ls_setup; + int16_t num_input_chan; + int16_t num_transport_chan; + int32_t ivas_total_brate; + const PARAM_MC_ILD_MAPPING *ild_mapping_conf; + const PARAM_MC_ICC_MAPPING *icc_mapping_conf; + const float *dmx_fac; + const float *ild_factors; + +} PARAM_MC_CONF; + +typedef struct ivas_parametric_mc_metadata_value_coding_info_struct +{ + const uint16_t *cum_freq; + const uint16_t *sym_freq; + const uint16_t *cum_freq_delta; + const uint16_t *sym_freq_delta; + const float *quantizer; + int16_t quantizer_size; + int16_t uni_bits; + +} PARAM_MC_PARAMETER_CODING_INFO, *HANDLE_PARAM_MC_PARAMETER_CODING_INFO; + +typedef struct ivas_parametric_mc_metadata_struct +{ + const PARAM_MC_ILD_MAPPING *ild_mapping_conf; + const PARAM_MC_ICC_MAPPING *icc_mapping_conf; + int16_t icc_mapping[PARAM_MC_PARAMETER_FRAMES][PARAM_MC_SZ_ICC_MAP][2]; + int16_t *icc_map_full[2]; + int16_t icc_map_size_full; + int16_t param_frame_idx; + int16_t flag_use_adaptive_icc_map; + const float *ild_factors; + int16_t coding_band_mapping[PARAM_MC_MAX_PARAMETER_BANDS]; + int16_t nbands_in_param_frame[PARAM_MC_PARAMETER_FRAMES]; + int16_t bAttackPresent; + int16_t attackIndex; + int16_t nbands_coded; + int16_t num_parameter_bands; + int16_t coded_bwidth; + int16_t last_coded_bwidth; + int16_t lfe_on; + PARAM_MC_PARAMETER_CODING_INFO icc_coding; + PARAM_MC_PARAMETER_CODING_INFO ild_coding; + +} IVAS_PARAM_MC_METADATA, *HANDLE_IVAS_PARAM_MC_METADATA; + + +/*----------------------------------------------------------------------------------* + * Declaration of LFE common (encoder & decoder) structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_lfe_window +{ + int16_t dct_len; + int16_t fade_len; + int16_t zero_pad_len; + int16_t full_len; + const float *pWindow_coeffs; + +} LFE_WINDOW_DATA, *LFE_WINDOW_HANDLE; + +typedef struct ivas_lfe_freq_models +{ + uint16_t entropy_coder_model_fine_sg1[65]; + uint16_t entropy_coder_model_fine_sg2[33]; + uint16_t entropy_coder_model_fine_sg3[9]; + uint16_t entropy_coder_model_fine_sg4[3]; + uint16_t entropy_coder_model_coarse_sg1[33]; + uint16_t entropy_coder_model_coarse_sg2[17]; + uint16_t entropy_coder_model_coarse_sg3[5]; + uint16_t entropy_coder_model_coarse_sg4; + +} ivas_lfe_freq_models; + +typedef struct ivas_filters_process_state_t +{ + int16_t order; + int16_t filt_len; + float num[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + float den[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + float state[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + +} ivas_filters_process_state_t; + + +/*----------------------------------------------------------------------------------* + * Transient Detector (TD) structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_trans_det_state_t +{ + ivas_filters_process_state_t env_hpf; + ivas_filters_process_state_t env_fast; + ivas_filters_process_state_t env_slow; + float in_duck_coeff; + float out_duck_coeff; + float in_duck_gain; + float out_duck_gain; + float duck_mult_fac; + +} ivas_trans_det_state_t; + + +/*----------------------------------------------------------------------------------* + * Filter Bank (FB) structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_fb_mixer_cfg_t +{ + int16_t fb_latency; + int16_t num_in_chans; + int16_t num_out_chans; + int16_t pcm_offset; + int16_t fade_len; /* this sets the stride length; no delay is introduced */ + int16_t prior_input_length; + int16_t windowed_fr_offset; + int16_t active_w_mixing; + const int16_t *remix_order; + +} IVAS_FB_CFG; + +typedef struct ivas_fb_consts_t +{ + const float *ppFilterbank_FRs[2][IVAS_MAX_NUM_BANDS]; + float *ppFilterbank_FRs_non48k[2][IVAS_MAX_NUM_BANDS]; + const int16_t *pFilterbank_bins_per_band; + const int16_t *pFilterbank_bins_start_offset; + +} ivas_fb_consts_t; + +typedef struct ivas_fb_bin_to_band_data_t +{ + float *pFb_bin_to_band[IVAS_MAX_NUM_FB_BANDS]; + const int16_t *pFb_start_bin_per_band; + const int16_t *pFb_active_bins_per_band; + float pp_cldfb_weights_per_spar_band[CLDFB_NO_CHANNELS_MAX][IVAS_MAX_NUM_FB_BANDS]; /* weights for linear combination of parameters from different spar bands*/ + int16_t p_spar_start_bands[CLDFB_NO_CHANNELS_MAX]; /* the first spar band per CLFB band when the weight is > 0 */ + int16_t p_cldfb_map_to_spar_band[CLDFB_NO_CHANNELS_MAX]; /* a direct mapping from CLDFB band to SPAR band */ + int16_t p_short_stride_start_bin_per_band[IVAS_MAX_NUM_FB_BANDS]; + int16_t p_short_stride_num_bins_per_band[IVAS_MAX_NUM_FB_BANDS]; + float p_short_stride_bin_to_band[2 * MDFT_FB_BANDS_240]; + float *pp_short_stride_bin_to_band[IVAS_MAX_NUM_FB_BANDS]; + int16_t short_stride; + int16_t num_cldfb_bands; + +} ivas_fb_bin_to_band_data_t; + +typedef struct ivas_filterbank_t +{ + int16_t filterbank_num_bands; + ivas_fb_consts_t fb_consts; + ivas_fb_bin_to_band_data_t fb_bin_to_band; + +} ivas_filterbank_t; + +typedef struct ivas_fb_mixer_state_structure +{ + IVAS_FB_CFG *fb_cfg; + + int16_t num_diff_bands; + ivas_filterbank_t *pFb; + + float *ppFilterbank_inFR_re[IVAS_MAX_FB_MIXER_IN_CH]; + float *ppFilterbank_inFR_im[IVAS_MAX_FB_MIXER_IN_CH]; + float *ppFilterbank_prior_input[IVAS_MAX_FB_MIXER_IN_CH]; + float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + + /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ + int16_t cross_fade_start_offset; + int16_t cross_fade_end_offset; + const float *pFilterbank_cross_fade; + int16_t ana_window_offset; + const float *pAna_window; + + int16_t prior_input_length; + int16_t windowed_fr_offset; + float cldfb_cross_fade[CLDFB_NO_COL_MAX]; + int16_t cldfb_cross_fade_start; + int16_t cldfb_cross_fade_end; + int16_t cldfb_latency; + + int16_t first_frame[IVAS_SPAR_MAX_CH]; + +} IVAS_FB_MIXER_DATA, *IVAS_FB_MIXER_HANDLE; + + +#endif /* IVAS_STAT_COM */ diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c index 56e3bf3..a4abea6 100644 --- a/lib_com/lag_wind.c +++ b/lib_com/lag_wind.c @@ -2,11 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include +#include "options.h" #include "prot_fx.h" #include "rom_com_fx.h" #include "basop_util.h" -#include "stl.h" /*-------------------------------------------------------------------* * Local constants @@ -25,7 +26,7 @@ void lag_wind( Word16 r_h[], /* in/out: autocorrelations */ Word16 r_l[], /* in/out: autocorrelations */ Word16 m, /* input : order of LP filter */ - Word32 sr, /* input : sampling rate */ + Word32 sr_core, /* input : sampling rate */ Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ) { @@ -35,7 +36,7 @@ void lag_wind( assert(0 <= strength && strength <= NUM_LAGW_STRENGTHS); - SWITCH (sr) + SWITCH (sr_core) { case 8000: assert(m <= 16); @@ -89,7 +90,7 @@ void adapt_lag_wind( Word16 m, /* input : order of LP filter */ const Word16 Top, /* input : open loop pitch lag */ const Word16 Tnc, /* input : open loop pitch gain */ - Word32 sr /* input : sampling rate */ + Word32 sr_core /* input : sampling rate */ ) { Word16 strength, pitch_lag; @@ -126,5 +127,5 @@ void adapt_lag_wind( move16(); } - lag_wind(r_h, r_l, m, sr, strength); + lag_wind(r_h, r_l, m, sr_core, strength); } diff --git a/lib_com/lerp.c b/lib_com/lerp.c index e866e23..d27ef9c 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -1,20 +1,30 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" #include "basop_util.h" #include "prot_fx.h" #include -#include "stl.h" +/*-------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------*/ #define shift_e (16-1) #define pos_e (16-1) +/*-------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------*/ static void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize); +/*-------------------------------------------------------------* + * procedure lerp() * + * * + * * + *-------------------------------------------------------------*/ void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) { @@ -75,8 +85,12 @@ void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) lerp_proc(f, f_out, bufferNewSize, bufferOldSize); } } - -void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) +/*-------------------------------------------------------------* + * procedure lerp_proc() * + * * + * * + *-------------------------------------------------------------*/ +static void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) { Word16 i, idx, n; diff --git a/lib_com/limit_t0_fx.c b/lib_com/limit_t0_fx.c index d5b31b1..810b7d9 100644 --- a/lib_com/limit_t0_fx.c +++ b/lib_com/limit_t0_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "rom_basop_util.h" @@ -166,10 +165,10 @@ void limit_T0_voiced( const Word16 T0, /* i : rough pitch estimate around which the search is done */ const Word16 T0_frac, /* i : pitch estimate fractional part */ const Word16 T0_res, /* i : pitch resolution */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_min_frac, /* o : lower pitch limit */ - Word16 *T0_max, /* o : higher pitch limit */ - Word16 *T0_max_frac, /* o : higher pitch limit */ + Word16 *T0_min, /* o : lower pitch limit */ + Word16 *T0_min_frac, /* o : lower pitch limit */ + Word16 *T0_max, /* o : higher pitch limit */ + Word16 *T0_max_frac, /* o : higher pitch limit */ const Word16 pit_min, /* i : Minimum pitch lag */ const Word16 pit_max /* i : Maximum pitch lag */ ) diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 957fcdf..562f56d 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -2,13 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ #include "rom_com_fx.h" /* Static table prototypes */ #include "cnst_fx.h" /* Common constants */ -/* Local constants */ +/*--------------------------------------------------------------------------* + * Local constants + *--------------------------------------------------------------------------*/ + #define THREN2POW 1518500250L /*--------------------------------------------------------------------------* @@ -20,7 +23,7 @@ void logqnorm_fx( const Word32 *L_x, /* i : coefficient vector Qx */ const Word16 qx, /* i : Q value of input */ - Word16 *k, /* o : index Q0 */ + Word16 *k, /* o : index Q0 */ const Word16 L, /* i : codebook length Q0 */ const Word16 N, /* i : sub-vector size Q0 */ const Word16 hvq_flag /* i : HVQ flag Q0 */ @@ -99,8 +102,8 @@ void logqnorm_2_fx( const Word16 L, /* i : codebook length */ const Word16 n_env_band, /* i : sub-vector size */ const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, - Word16 *normqlg2, + Word16 *ynrm, /* o : norm indices */ + Word16* normqlg2, /* o : quantized norm values */ const Word32 *thren /* i, Q10 : quantization thresholds */ ) { @@ -159,14 +162,14 @@ void logqnorm_2_fx( *--------------------------------------------------------------------------*/ void calc_norm_fx( - const Word32 *L_x, /* i : Input vector. Qx */ - const Word16 qx, /* i : Q value of input */ - Word16 *norm, /* o : Quantization indices for norms Q0 */ - Word16 *normlg, /* o : Quantized norms in log2 Q0 */ - const Word16 start_band, /* i : Indice of band to start coding Q0 */ - const Word16 num_bands, /* i : Number of bands Q0 */ - const Word16 *band_len, /* i : Length of bands Q0 */ - const Word16 *band_start /* i : Start of bands Q0 */ + const Word32 *L_x, /* i : Input vector. Qx */ + const Word16 qx, /* i : Q value of input */ + Word16 *norm, /* o : Quantization indices for norms Q0 */ + Word16 *normlg, /* o : Quantized norms in log2 Q0 */ + const Word16 start_band, /* i : Indice of band to start coding Q0 */ + const Word16 num_bands, /* i : Number of bands Q0 */ + const Word16 *band_len, /* i : Length of bands Q0 */ + const Word16 *band_start /* i : Start of bands Q0 */ ) { Word16 nrm; diff --git a/lib_com/longarith.c b/lib_com/longarith.c index c169347..716cb1c 100644 --- a/lib_com/longarith.c +++ b/lib_com/longarith.c @@ -2,12 +2,19 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include +#include "options.h" #include "prot_fx.h" -#include "stl.h" - + /*-------------------------------------------------------------------* +* longshiftright() +* +* long shift right: d[] = a[] >> b +* Logical shift right of unsigned vectors a[] by b bit-positions. +* Vector d[] is filled with leading zeroes, where lend exceeds lena. +* It is allowed to overlay d[] with a[]. +*--------------------------------------------------------------------*/ /** * \brief inplace long shift right: a[] = a[] >> bits * Logical shift right of UWord32 vector a[] by 'bits' positions. @@ -27,7 +34,11 @@ * \return void */ -void longshr(UWord32 a[], Word16 bits, Word16 len) +void longshr( + UWord32 a[], + Word16 bits, + Word16 len +) { Word16 fracb_u, k; diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 680b95e..b93c778 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* @@ -16,18 +15,18 @@ *--------------------------------------------------------------------------*/ void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ - const Word16 core /* i : Core */ + const Word16 *sfm_start, /* i : Sub band start indices */ + const Word16 *sfm_end, /* i : Sub band end indices */ + const Word16 *sfm_size, /* i : Sub band bandwidths */ + const Word16 *i_sort, /* i : Energy sorting indices */ + const Word16 *K, /* i : Number of pulses per band */ + const Word16 *maxpulse, /* i : Maximum pulse per band */ + const Word16 *R, /* i : Bits per sub band Q3 */ + const Word16 num_sfm, /* i : Number of sub bands */ + Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ + Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *fg_pred, /* o : Predicted fine gains Q12 */ + const Word16 core /* i : Core */ ) { Word16 i, band; @@ -127,13 +126,13 @@ void fine_gain_pred_fx( *--------------------------------------------------------------------------*/ void get_max_pulses_fx( - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 *k_sort, /* i : Indices for sorting by energy */ - const Word16 *npulses, /* i : Pulses per sub band */ - const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ + const Word16 *band_start, /* i : Sub band start indices */ + const Word16 *band_end, /* i : Sub band end indices */ + const Word16 *k_sort, /* i : Indices for sorting by energy */ + const Word16 *npulses, /* i : Pulses per sub band */ + const Word16 BANDS, /* i : Number of bands */ + Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ + Word16 *maxpulse /* o : Maximum pulse height per band */ ) { Word16 i, k; @@ -179,7 +178,7 @@ void fine_gain_dec_fx const Word16 *ord, /* i : Indices for energy order */ const Word16 num_sfm, /* i : Number of bands */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ ) { Word16 band; diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index d690482..3f42224 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" -#include "stl.h" #include "basop_mpy.h" #include "basop_util.h" @@ -26,9 +26,9 @@ void autocorr_fx( const Word16 x[], /* i : Input signal */ const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ - Word16 *Q_r, /* o : normalisation shift of r Q0 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ + Word16 r_l[], /* o : Autocorrelations (lsb) */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16* wind, /* i : Window used */ Word16 rev_flag, diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index 5c47967..2b10f85 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -3,10 +3,8 @@ ====================================================================================*/ -#include -#include -#include -#include "stl.h" +#include +#include "options.h" #include "basop_util.h" #include "rom_com_fx.h" #include "cnst_fx.h" @@ -20,26 +18,26 @@ * Bad frame, all active speech coders *---------------------------------------------------------------------*/ void lsf_dec_bfi( - const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ - Word16*lsf, /*!< o : 14Q1*1.28 quantized ISFs */ - const Word16*lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ + const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ + Word16*lsf, /*!< o : 14Q1*1.28 quantized ISFs */ + const Word16*lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ Word16*lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ - const Word16 lsfBase[], /* i : base for differential lsf coding */ + const Word16 lsfBase[], /* i : base for differential lsf coding */ Word16*mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ Word16*mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ - const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ + const Word16 last_coder_type,/*!< i : coding type in last good received fr. */ Word16 L_frame, - const Word16 last_good, /*!< i : last good received frame */ - const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ - Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ + const Word16 last_good, /*!< i : last good received frame */ + const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ + const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ + Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ const Word16 Last_GSC_pit_band_idx, - const Word16 Opt_AMR_WB /* i : IO flag */ - , const Word8 tcxonly - ,const short MODE1_bwidth /* i: coded bandwidth */ + const Word16 Opt_AMR_WB, /* i : IO flag */ + const Word8 tcxonly, + const short bwidth /* i: coded bandwidth */ ) { Word16 i; @@ -66,7 +64,7 @@ void lsf_dec_bfi( { pt_meansForFading = GEWB_Ave_fx; - if (EQ_16(MODE1_bwidth,NB)) + if (EQ_16(bwidth,NB)) { pt_meansForFading = GENB_Ave_fx; } @@ -255,9 +253,11 @@ void lsf_dec_bfi( return; } -Word16 const * PlcGetLsfBase (Word16 const lpcQuantization, - Word16 const narrowBand, - Word32 const sr_core) +Word16 const * PlcGetLsfBase ( + Word16 const lpcQuantization, + Word16 const narrowBand, + Word32 const sr_core +) { /* Not correct BW */ IF (lpcQuantization==0) @@ -283,7 +283,7 @@ Word16 const * PlcGetLsfBase (Word16 const lpcQuantization, /* lpcQuntization == 1 is left */ - IF (EQ_32(sr_core,16000)) + IF (EQ_32(sr_core, INT_FS_16k)) { return GEWB2_Ave_fx; } diff --git a/lib_com/lsf_msvq_ma.c b/lib_com/lsf_msvq_ma.c index 3889263..be34f9b 100644 --- a/lib_com/lsf_msvq_ma.c +++ b/lib_com/lsf_msvq_ma.c @@ -2,33 +2,31 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include "cnst_fx.h" +#include "options.h" #include "rom_com_fx.h" #include "prot_fx.h" -#include "stl.h" #include "basop_util.h" #include "prot_fx.h" -#include "options.h" - +#ifndef swap #define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - -extern const Word16 tbl_mid_gen_wb_5b_fx[]; -extern const Word16 tbl_mid_unv_wb_5b_fx[]; - - - - +#endif +/*---------------------------------------------------------------------* + * midlsf_dec() + * + * + *---------------------------------------------------------------------*/ void midlsf_dec( const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ - Word16 idx, /* i: codebook index */ + const Word16 idx, /* i: codebook index */ Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ - Word16 coder_type, + const Word16 coder_type, Word16 *mid_lsf_int, - Word16 prev_bfi, - Word16 safety_net) + const Word16 prev_bfi, + const Word16 safety_net +) { const Word16 *ratio=NULL; Word16 j; @@ -136,8 +134,8 @@ void midlsf_dec( Word16 lsf_ind_is_active( const Word16 lsf_q_ind[], const Word16 means[], - Word16 narrowband, - Word16 cdk + const Word16 narrowband, + const Word16 cdk ) { Word16 lsf[2], min_distance; diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index f5d593f..08329fd 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -2,19 +2,18 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "basop_util.h" #include "rom_com_fx.h" #include "cnst_fx.h" #include "prot_fx.h" -#include "rom_com_fx.h" /* Static table prototypes */ - +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ #define NC_MAX 8 #define GUESS_TBL_SZ 256 @@ -24,10 +23,6 @@ val2 = shr((cbp)[2], 4); \ val3 = add(add(shr(lshl((cbp)[2],12),4),lshr(lshl((cbp)[1],12),8)),s_and((cbp)[0],0xF)); -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - #define NC ( M/2) #define NC16k ( M16k/2) @@ -36,8 +31,8 @@ #define ALPHA_SQ ( ( 0.5f / PI2) * ( 0.5f / PI2)) /*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ + * Local functions + *-------------------------------------------------------------------*/ Word16 root_search_fx( Word16 low, Word16 high, Word32 *v_low, Word32 *coef,Word16 order); Word32 calc_weight( Word16 delta1,Word16 delta2,Word16 *n1 ); Word32 polynomial_eval_fx( Word16 f, Word32 *coef,Word16 order); @@ -45,7 +40,7 @@ void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); void E_LPC_lsp_lsf_conversion(const Word16 lsp[],Word16 lsf[],const Word16 m); Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1); -static Word16 chebyshev(Word16 x, Word32 *f, Word16 n, Word16 shift) +static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift) { Word16 cheb; @@ -1626,27 +1621,25 @@ Word16 vq_dec_lvq_fx ( return ber_flag; } -void lsf_allocate_fx( - const Word16 nBits, /* i : Number of bits to use for quantization */ - const Word16 framemode, /* i : ISF quantizer mode */ - const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ - Word16 *stages0, /* o : Number of stages for safety-net quantizer */ - Word16 *stages1, /* o : Number of stages for predictive quantizer */ - Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ - Word16 levels1[], /* o : Number of vectors for each stage for pred */ - Word16 bits0[], /* o : Number of bits for each stage safety net */ - Word16 bits1[] /* o : Number of bits for each stage pred */ +ivas_error lsf_allocate_fx( + const Word16 nBits, /* i : Number of bits to use for quantization */ + const Word16 framemode, /* i : ISF quantizer mode */ + const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ + Word16 *stages0, /* o : Number of stages for safety-net quantizer */ + Word16 *stages1, /* o : Number of stages for predictive quantizer */ + Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ + Word16 levels1[], /* o : Number of vectors for each stage for pred */ + Word16 bits0[], /* o : Number of bits for each stage safety net */ + Word16 bits1[] /* o : Number of bits for each stage pred */ ) { Word16 i; Word16 cumleft; Word16 bits_lvq, n_stages, nbits0; + ivas_error error; + + error = IVAS_ERR_OK; - /* VOICED@16kHz */ - IF(EQ_16(framemode, 14)) - { - return; - } cumleft = nBits; move16(); @@ -1774,23 +1767,31 @@ void lsf_allocate_fx( move16(); } } +#ifdef DEBUGGING ELSE { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "lsf_allocate(): invalid number of bits in used predictive mode\n"); } +#endif } - return; + return error; } -Word16 find_pred_mode( - const Word16 coder_type, /* i: coding type */ - const Word16 bwidth, /* i: bandwidth index */ - const Word32 int_fs, /* i: sampling frequency */ - Word16 * p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ - Word16 * p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ - Word32 core_brate) /* i: core bit rate */ +ivas_error find_pred_mode( + Word16* predmode, /* o: prediction mode */ + const Word16 coder_type, /* i: coding type */ + const Word16 bwidth, /* i: bandwidth index */ + const Word32 int_fs, /* i: sampling frequency */ + Word16 * p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ + Word16 * p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ + Word32 core_brate /* i: core bit rate */ +) { - Word16 idx, predmode; + Word16 idx; + ivas_error error; + + error = IVAS_ERR_OK; /* bwidth = 0(NB), 1 (WB), 2(WB2); line index in predmode_tab[][] */ idx = bwidth; @@ -1809,18 +1810,18 @@ Word16 find_pred_mode( { test(); test(); - if ((GE_32(core_brate, GENERIC_MA_LIMIT))&&(EQ_16(coder_type,GENERIC))&&(EQ_16(idx,1))) + if ((GE_32(core_brate, GENERIC_MA_LIMIT) )&& (EQ_16(coder_type,GENERIC)) && (EQ_16(idx,1))) { idx = 3; move16(); } } - predmode = predmode_tab[idx][coder_type]; + *predmode = predmode_tab[idx][coder_type]; move16(); IF (LE_16(idx, 2)) { *p_mode_lvq = add(i_mult2(NO_CODING_MODES, idx), coder_type); - IF (predmode>0) + IF (*predmode>0) { *p_mode_lvq_p = *p_mode_lvq; move16(); @@ -1841,7 +1842,7 @@ Word16 find_pred_mode( } ELSE { - IF (predmode>0) + IF (*predmode>0) { *p_mode_lvq_p = *p_mode_lvq; } @@ -1851,10 +1852,15 @@ Word16 find_pred_mode( } } } +#ifdef DEBUGGING + if (*predmode == -1) + { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "\nfind_pred_mode(): incorrect coder_type specification: %d\n", coder_type); + } +#endif - - return predmode; + return error; } /*---------------------------------------------------------------------------* @@ -1931,11 +1937,11 @@ void reorder_isf_fx( /* RETURN ARGUMENTS : */ /* _ (Word16) stab_fac_fx : LP filter stability Q15 */ /*========================================================================*/ -Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ +Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ + const Word16 L_frame /* i : frame length */ ) { Word16 i, m; @@ -2001,10 +2007,10 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ *-------------------------------------------------------------------*/ void lsp2isp_fx( - const Word16 *lsp, /* i : LSP vector */ + const Word16 *lsp, /* i : LSP vector */ Word16 *isp, /* o : ISP filter coefficients */ Word16 *stable_isp, /* i/o: ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 m /* i : order of LP analysis */ ) { Word16 a[M+1]; @@ -2027,10 +2033,10 @@ void lsp2isp_fx( *-------------------------------------------------------------------*/ void isp2lsp_fx( - const Word16 *isp, /* i : LSP vector */ + const Word16 *isp, /* i : LSP vector */ Word16 *lsp, /* o : ISP filter coefficients */ Word16 *stable_lsp, /* i/o: stable LSP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 m /* i : order of LP analysis */ ) { Word16 a[M+1]; @@ -2052,10 +2058,10 @@ void isp2lsp_fx( *-------------------------------------------------------------------*/ void lsf2isf_fx( - const Word16 *lsf, /* i : LSF vector */ + const Word16 *lsf, /* i : LSF vector */ Word16 *isf, /* o : ISF vector */ Word16 *stable_isp, /* i/o: stable ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ + const Word16 m /* i : order of LP analysis */ ) { Word16 tmp_lsp[M]; @@ -2081,7 +2087,7 @@ void lsf2isf_fx( *-------------------------------------------------------------------*/ void isf2lsf_fx( - const Word16 *isf, /* i : ISF vector */ + const Word16 *isf, /* i : ISF vector */ Word16 *lsf, /* o : LSF vector */ Word16 *stable_lsp /* i/o: stable LSP filter coefficients */ ) @@ -2124,9 +2130,9 @@ void isf2lsf_fx( /*==========================================================================*/ void lsp2lsf_fx( const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ - Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ - const Word16 m /* i : LPC order Q0*/ - ,Word32 int_fs + Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ + const Word16 m, /* i : LPC order Q0*/ + const Word32 int_fs /* i : internal sampling frequency */ ) { Word16 i; @@ -2168,10 +2174,10 @@ void lsp2lsf_fx( /* _ None */ /*===========================================================================*/ void lsf2lsp_fx( - const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ - Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ - const Word16 m /* i : LPC order Q0 */ - , Word32 int_fs + const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ + Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ + const Word16 m, /* i : LPC order Q0 */ + const Word32 int_fs /* i : internal sampling frequency */ ) { Word16 i, ind, offset; @@ -2215,7 +2221,11 @@ void lsf2lsp_fx( } -void tcvq_Dec_fx(Word16 *ind, /*float *d_out, */Word16 *d_out_fx, Word16 safety_net) +void tcvq_Dec_fx( + Word16 *ind, + Word16 *d_out_fx, + const Word16 safety_net +) { Word16 i; Word16 index[9]; @@ -2376,9 +2386,9 @@ void tcvq_Dec_fx(Word16 *ind, /*float *d_out, */Word16 *d_out_fx, Word16 safety_ } Word16 qlsf_ARSN_tcvq_Dec_16k_fx ( - Word16 *y_fx, /* o : Quantized LSF vector */ - Word16 *indice, /* i : Indices */ - const Word16 nBits /* i : number of bits */ + Word16 *y_fx, /* o : Quantized LSF vector */ + Word16 *indice, /* i : Indices */ + const Word16 nBits /* i : number of bits */ ) { Word16 i; @@ -2475,7 +2485,6 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx ( void lsf_syn_mem_backup_fx( Encoder_State_fx *st_fx, /* i: state structure */ - LPD_state* LPDmem, /* i: LPD state memory structure */ Word16 *btilt_code_fx, /* i: tilt code */ Word32 *gc_threshold_fx, /* i: */ Word16 *clip_var_bck_fx, /* o: */ @@ -2500,6 +2509,7 @@ void lsf_syn_mem_backup_fx( ) { Word16 i; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; *clip_var = st_fx->clip_var_fx[0]; move16(); @@ -2540,16 +2550,16 @@ void lsf_syn_mem_backup_fx( /* back-up memories */ FOR(i=0; iLPDmem.mem_syn[i]; + mem_syn_bck[i] = hLPDmem->mem_syn[i]; move16(); } - *mem_w0_bck = st_fx->LPDmem.mem_w0; + *mem_w0_bck = hLPDmem->mem_w0; move16(); - *btilt_code_fx = LPDmem->tilt_code; - *gc_threshold_fx = LPDmem->gc_threshold; + *btilt_code_fx = hLPDmem->tilt_code; + *gc_threshold_fx = hLPDmem->gc_threshold; Copy( st_fx->clip_var_fx, clip_var_bck_fx, 6 ); *next_force_sf_bck_fx = st_fx->next_force_safety_net_fx; @@ -2612,11 +2622,10 @@ void lsf_update_memory( /*=======================================================================*/ void lsf_syn_mem_restore_fx( Encoder_State_fx *st_fx, /* o: state structure */ - LPD_state* LPDmem, /* o: LPD_state vewctor */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ + Word16 btilt_code_fx, /* i: */ + Word32 gc_threshold_fx, /* i: */ + Word16 *clip_var_bck_fx, /* i: */ + Word16 next_force_sf_bck_fx, /* i: */ Word16 *lsp_new, /* o: LSP vector to quantize */ Word16 *lsf_new, /* o: quantized LSF vector */ @@ -2637,6 +2646,7 @@ void lsf_syn_mem_restore_fx( ) { Word16 i; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; /* restore lsf memories */ st_fx->clip_var_fx[0] = clip_var; @@ -2676,20 +2686,20 @@ void lsf_syn_mem_restore_fx( } /* restoring memories */ - st_fx->LPDmem.mem_w0 = mem_w0_bck; + hLPDmem->mem_w0 = mem_w0_bck; move16(); FOR(i=0; iLPDmem.mem_syn[i] = mem_syn_bck[i]; + hLPDmem->mem_syn[i] = mem_syn_bck[i]; move16(); } move16(); move32(); move16(); - LPDmem->tilt_code = btilt_code_fx; - LPDmem->gc_threshold = gc_threshold_fx; + hLPDmem->tilt_code = btilt_code_fx; + hLPDmem->gc_threshold = gc_threshold_fx; Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); st_fx->next_force_safety_net_fx = next_force_sf_bck_fx; @@ -2714,16 +2724,85 @@ Word16 tcxlpc_get_cdk( return cdk; } +#ifdef IVAS_MSVQ +/*--------------------------------------------------------------------------* + * dec_FDCNG_MSVQ_stage1() + * + * + *--------------------------------------------------------------------------*/ + +void dec_FDCNG_MSVQ_stage1( + int16_t j_full, /* i : index full range */ + int16_t n, /* i : dimension to generate */ + const float* invTrfMatrix, /* i : IDCT matrix for synthesis */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + float* uq, /* o : synthesized stage1 vector */ + Word16* uq_ind /* o : synthesized stage1 vector in BASOP */ +) +{ + int16_t col, segm_ind, j; + float dct_vec[FDCNG_VQ_MAX_LEN]; + float idct_vec[FDCNG_VQ_MAX_LEN]; + const Word8* cbpW8; + const Word16* dct_col_shift_tab; + + assert(n <= FDCNG_VQ_MAX_LEN); + assert(n >= FDCNG_VQ_DCT_MINTRUNC); + + segm_ind = 0; + for (col = 1; col <= FDCNG_VQ_DCT_NSEGM; col++) + { + if (j_full >= cdk1_ivas_cum_entries_per_segment[col]) + { + segm_ind++; + } + } + + j = j_full - cdk1_ivas_cum_entries_per_segment[segm_ind]; /* j is the local segment index */ + + assert(j < cdk1_ivas_entries_per_segment[segm_ind]); + + /* Word8 column variable Qx storage*/ + cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ + cbpW8 += j * cdk1_ivas_cols_per_segment[segm_ind]; /* adaptive ptr init */ + dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; + + for (col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++) + { + dct_vec[col] = (float)shl((Word16)cbpW8[col], dct_col_shift_tab[col]); + /* LOGIC( 1 ) , SHIFT( 1 ); + in BASOP: s_and(for W8->W16), shl() + */ + } + dctT2_N_apply_matrix((const float*)dct_vec, idct_vec, cdk1_ivas_cols_per_segment[segm_ind], n, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, idcttype); + + /*scale down to original fdcngvq domain and move to Q0 */ + v_multc(idct_vec, fdcng_dct_scaleF[1], idct_vec, n); + /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , + not really relevant for BASOP loop */ + + /*add common mid fdcng vector, in fdcng bands domain */ + v_add(idct_vec, cdk1r_tr_midQ_truncQ, uq, n); + assert(uq_ind == NULL); + + return; +} + +#endif void msvq_dec ( const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (14Q1*1.28)*/ const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages,/* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ - Word16 *uq /* o : quantized vector (14Q1*1.28)*/ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook dimension */ + const Word16 Idx[], /* i : Indices */ +#ifdef IVAS_MSVQ + const int16_t applyIDCT_flag, /* i : applyIDCT flag */ + const float* invTrfMatrix, /* i : matrix for IDCT synthesis */ +#endif + Word16 *uq /* o : quantized vector (14Q1*1.28)*/ ) { Word16 i,j,offset; @@ -2761,24 +2840,34 @@ void msvq_dec start = offs[i]; move16(); } - - /*vr_add( uq+start, cb[i]+Idx[i]*maxn, uq+start, n );, where uq = a zero vector*/ - offset = i_mult2(Idx[i],N34); - - FOR (j=0; j XX in worst case */ + dim_in = fdcngvq_dim; + dim_out = dct_dim; + mat_step_col = matrix_row_dim; /* matrix maximum storage size dependent, width of first row in matrix */ + mat_step_row = 0; + mat_step_col_flag = 1; + assert(dcttype == DCT_T2_21_XX || dcttype == DCT_T2_24_XX); + } + else + { + assert((dcttype & 1) != 0); /* idct */ + dim_in = dct_dim; + dim_out = fdcngvq_dim; + mat_step_col = 1; + mat_step_row = matrix_row_dim; + mat_step_col_flag = 0; + assert(dcttype == IDCT_T2_XX_24); + } + + pt_y = tmp_y; + for (i = 0; i < dim_out; i++) + { + pt_x = input; + *pt_y = 0; + + /* +i(DCT) or +i*maxTrunc(IDCT) */ +#define WMC_TOOL_SKIP + pt_A = &(matrix[i * (mat_step_row + mat_step_col_flag)]); /* ptr indexing */ + PTR_INIT(1); +#undef WMC_TOOL_SKIP + for (j = 0; j < dim_in; j++) + { +#define WMC_TOOL_SKIP + * pt_y += (*pt_x++) * (*pt_A); + pt_A += mat_step_col; /* step +maxtrunc or +1 */ /* ptr indexing*/ + MAC(1); +#undef WMC_TOOL_SKIP + } + pt_y++; + } + + mvr2r(tmp_y, output, dim_out); + + return; +} + + +/*-------------------------------------------------------------------* + * extend_dctN_input() + * + * (inputN, dctN) -> idct(N_ext) idct_N matrix application loop for + * extending, extrapolating a DCT basis vector length of N to N_ext + *-------------------------------------------------------------------*/ + +void extend_dctN_input( + const float* input, /* i : input in fdcng domain */ + const float* dct_input, /* i : input in dctN(fdcng) domain */ + const int16_t in_dim, /* i : in_dim == N */ + float* ext_sig, /* o : extended output in fdcng domain */ + const int16_t out_dim, /* i : output total dim */ + float* matrix, /* i : idct synthesis matrix N rows, n_cols columns */ + const int16_t n_cols, /* i : number of columns == DCT truncation length */ + const DCTTYPE dcttype /* i : matrix operation type */ +) +{ + int16_t i, j, i_rev; + const float(*ptr)[FDCNG_VQ_DCT_MAXTRUNC] = (void*)matrix; + + /* stored format is an IDCT_Nx(FDCNG_VQ_DCT_MAXTRUNC) matrix */ + assert(in_dim < FDCNG_VQ_MAX_LEN); + assert(out_dim <= FDCNG_VQ_MAX_LEN); + assert(out_dim > in_dim); + assert(n_cols == FDCNG_VQ_DCT_MAXTRUNC); /* for *ptr[MAX_TRUNC] adressing*/ + assert((dcttype & 1) != 0); /* idct tables always in use for this basis vector extension */ + + mvr2r(input, ext_sig, in_dim); /* copy initial part, i.e. only last/tail parts are extended */ + set_f(&(ext_sig[in_dim]), 0.0, out_dim - in_dim); + + i_rev = in_dim; /*ptr init*/ + for (i = in_dim; i < out_dim; i++) + { /* for each extension sample */ + /* i = 21 22 23; + i_rev = 20 19 18; for odd dctII reflect basis vector + */ + i_rev--; + + for (j = 0; j < n_cols; j++) /* for each available DCT coeff */ + { + /* DCTcoeff * reflected basis vector */ +#define WMC_TOOL_SKIP + /* pure ptr MAC operations */ + ext_sig[i] += dct_input[j] * ptr[i_rev][j]; /* sum up scaled and extended basis vector */ + MAC(1); +#undef WMC_TOOL_SKIP + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * create_IDCT_N_Matrix() + * + * inititate idct24 FDCNG_VQ_DCT_MAXTRUNCx N matrix in + * RAM from a quantized compressed ROM format + *-------------------------------------------------------------------*/ + +void create_IDCT_N_Matrix( + float* inv_matrixFloatQ, /* i/o: RAM buffer */ + const int16_t N, /* i : DCT length, number of time samples */ + const int16_t n_cols, /* i : number of dct coeffs (as DCT may be truncated) */ + const int16_t alloc_size /* i : RAM buffer size in elements */ +) +{ + int16_t c, c1, r, r_flip, W16_val; + int16_t len; + int16_t mat_cpy_size; + const Word16* absval_ptr; + const Word8* idx_ptr; + Word16 idx; + float(*ptr)[FDCNG_VQ_DCT_MAXTRUNC] = (void*)inv_matrixFloatQ; /* fixed number of columns pointers, to simplifies adressing in ANSIC */ + + absval_ptr = unique_idctT2_24coeffsQ16; + idx_ptr = idctT2_24_compressed_idx; + len = FDCNG_VQ_MAX_LEN; + + if (N == FDCNG_VQ_MAX_LEN_WB) + { + absval_ptr = unique_idctT2_21coeffsQ16; + idx_ptr = idctT2_21_compressed_idx; + len = N; + } + + assert(alloc_size >= (n_cols * len)); /* enough space for the full expanded IDCT matrix */ + assert(N <= len); + + mat_cpy_size = (n_cols) * (len >> 1); /* NB integer division of "len" */ + + if ((len & 1) != 0) + { /* odd sized DCT with a non-reflected center row */ + mat_cpy_size += n_cols; + } + + for (c = 0; c < mat_cpy_size; c++) + { + idx = (Word16)(idx_ptr[c]); + W16_val = absval_ptr[abs(idx)]; + + if (idx < 0) + { + W16_val = -(W16_val); + } + inv_matrixFloatQ[c] = (+1.52587890625e-05f) * ((float)W16_val); /* 1.0/2.^16 scaling to a float-"Q0" , a scaling that is not done in BASOP */ + } + + /* for even number of coeffs DCT24, + flip symmetry for odd, even is used to save 50% IDCT Table ROM */ + /* for an odd DCT center is not flipped e.g for DCT21 */ + + assert(n_cols == FDCNG_VQ_DCT_MAXTRUNC); + assert((n_cols & 1) == 0); + + for (c = 0; c < (n_cols); c += 2) + { + c1 = c + 1; + r_flip = len - 1; + for (r = 0; r < (len / 2); r++, r_flip--) + { +#define WMC_TOOL_SKIP + ptr[r_flip][c] = ptr[r][c]; /* flipped */ + ptr[r_flip][c1] = -(ptr[r][c1]); /* flipped and sign swapped */ + MOVE(2); + MULT(1); /* for negate */ +#undef WMC_TOOL_SKIP + } + } + + return; +} +#endif diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index cf37feb..0269ed4 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" - #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Local constants @@ -19,48 +18,15 @@ #define NC (M/2) /*-------------------------------------------------------------------* - * Local functions + * Local function prototypes *-------------------------------------------------------------------*/ -static void powerspect_fx( - const Word16 x[], /* i: Q15 Grid points x[0:m-1] */ - Word16 N, /* i: Number of grid points */ - Word32 R[], /* i: Q20 Coefficients of R(x) in R[0:NC] */ - Word32 S[], /* i: Q20 Coefficients of S(x) in S[0:NC] */ - Word32 G[], /* o: Q15 Power spectrum G[0:N] */ - Word16 mode /* i: Flag for up or down conversion */ -); - -static void spectautocorr_fx( - const Word16 x[], /* i: Grid points x[0:m-1] */ - const Word16 N, /* i: Number of grid points */ - const Word32 G[], /* i: Power spectrum G[0:N-1] */ - Word16 rh[], /* o: Autocorrelation r[0:M] */ - Word16 rl[] /* o: Autocorrelation r[0:M] */ -); - -static Word32 b_inv_sq( - const Word32 in32, /* i : Input not normalized to inverse */ - const Word16 exp_in /* I : input current exponent */ -); - -static Word32 inv_pow( - const Word32 re, - const Word32 se, - const Word16 x - -); - +static void powerspect_fx(const Word16 x[], Word16 N, Word32 R[], Word32 S[], Word32 G[], Word16 mode ); +static void spectautocorr_fx(const Word16 x[], const Word16 N, const Word32 G[], Word16 rh[], Word16 rl[] ); +static Word32 b_inv_sq(const Word32 in32, const Word16 exp_in ); +static Word32 inv_pow(const Word32 re, const Word32 se, const Word16 x); static void zeros2poly_fx( Word16 x[], Word32 R[], Word32 S[] ); - -static void polydecomp_fx( - Word16 A[], /* i: Q12 linear prediction coefficients */ - Word32 P[], /* o: Q22 coefficients of R(x) */ - Word32 Q[] /* o: Q22 coefficients of S(x) */ -); - -static void cheb2poly_fx( - Word32 L_P[] /* i/o Q22: The coefficients of C(x) and P(x) */ -); +static void polydecomp_fx(Word16 A[], Word32 P[], Word32 Q[] ); +static void cheb2poly_fx( Word32 L_P[] ); /*---------------------------------------------------------------------* * lsp_convert_poly() @@ -79,9 +45,9 @@ static void cheb2poly_fx( *---------------------------------------------------------------------*/ Word16 lsp_convert_poly_fx( - Word16 w[], /* i/o: LSP or ISP parameters */ - const Word16 L_frame, /* i : flag for up or down conversion */ - const Word16 Opt_AMRWB /* i : flag for the AMR-WB IO mode */ + Word16 w[], /* i/o: LSP or ISP parameters */ + const Word16 L_frame, /* i : flag for up or down conversion */ + const Word16 Opt_AMRWB /* i : flag for the AMR-WB IO mode */ ) { const Word16 N50 = GRID50_POINTS; diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index e092957..532e1ff 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -2,15 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include #include "rom_enc_fx.h" /* prototypes */ -#include "stl.h" - #include "basop_util.h" /*-----------------------------------------------------------------* @@ -43,12 +41,12 @@ /*==============================================================================*/ Word16 modify_Fs_fx( /* o : length of output Q0 */ const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ + Word16 lg, /* i : length of input Q0 */ const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ + Word16 sigOut_fx[], /* o : decimated signal Q0 */ const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[] /* i/o: filter memory Q0 */ - ,const Word16 nblp /* i : flag indicating if NB low-pass is applied */ + Word16 mem_fx[], /* i/o: filter memory Q0 */ + const Word16 nblp /* i : flag indicating if NB low-pass is applied */ ) { Word16 i; @@ -308,14 +306,19 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ return lg_out; } +/*-------------------------------------------------------------------* + * modify_Fs_intcub3m_sup() + * + * + *-------------------------------------------------------------------*/ -Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ - const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ - const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ - const Word32 fin, /* i : frequency of input */ - Word16 sigOut[], /* o : decimated signal */ - const Word32 fout, /* i : frequency of output */ - Word16 *delayout /* o : delay of output */ +Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ + const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ + const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ + const Word32 fin, /* i : frequency of input */ + Word16 sigOut[], /* o : decimated signal */ + const Word32 fout, /* i : frequency of output */ + Word16 *delayout /* o : delay of output */ ) { Word16 i, k, i1, i2, k1, k2, k3, kk, cind; @@ -598,18 +601,18 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ /*====================================================================*/ /* FUNCTION : Decimate_allpass_steep_fx1 () */ /*-------------------------------------------------------------------*/ -/* PURPOSE : decimation by a factor 2 */ +/* PURPOSE : decimation by a factor 2 */ /*-------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (const Word16 *) in_fx : input speech, Q0 */ -/* _ (Word16 []) state_fx: Stateinfo, Q0 */ +/* _ (Word16 []) mem: Stateinfo, Q0 */ /* Size: 2*ALLPASSSECTIONS_STEEP+1 */ /* _ (Word16) N: Number of Input samples */ -/* _ (Word16 []) out_fx :Output arry of size N/2 Q0 */ +/* _ (Word16 []) out_fx :Output arry of size N/2 Q0 */ /*-------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16 []) out_fx : output-signal, Q0 */ -/* _ (Word16 []) state_fx:gets updated, Q0 */ +/* _ (Word16 []) mem:gets updated, Q0 */ /*-------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /*-------------------------------------------------------------------*/ @@ -617,10 +620,11 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ /*===================================================================*/ -void Decimate_allpass_steep_fx( const Word16 *in_fx, - Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]) /* array of size N/2 */ +void Decimate_allpass_steep_fx( + const Word16 *in_fx, + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[]) /* array of size N/2 */ { Word16 k; @@ -636,58 +640,58 @@ void Decimate_allpass_steep_fx( const Word16 *in_fx, FOR ( k = 0; k < N/2; k++ ) { - Lacc = L_deposit_h( state_fx[0] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */ Lacc = L_mac( Lacc, AP1_STEEP_FX[0], in_fx[2*k] ); /* Q(16+x) */ Lacc1 = L_deposit_h( in_fx[2*k] ); /* Q16+Qx */ temp1 = extract_h( Lacc ); /* Qx */ Lacc1 = L_msu( Lacc1, AP1_STEEP_FX[0], temp1 ); /* Q16+Qx */ - state_fx[0] = extract_h( Lacc1 ); /* Qx */ + mem[0] = extract_h( Lacc1 ); /* Qx */ temp[0] = temp1; move16(); - Lacc1 = L_deposit_h( state_fx[1] ); /* Q16+Qx */ + Lacc1 = L_deposit_h( mem[1] ); /* Q16+Qx */ Lacc1 = ( L_mac( Lacc1, AP1_STEEP_FX[1], temp1 )); /* Q16+Qx */ temp2 = extract_h( Lacc1 ); /* Qx */ Lacc = L_msu( Lacc, AP1_STEEP_FX[1], temp2 ); /* Q16+Qx */ - state_fx[1] = extract_h(Lacc); /* Qx */ + mem[1] = extract_h(Lacc); /* Qx */ temp[1] = temp2; move16(); - Lacc = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP-1 ] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP-1 ] ); /* Q(16+x) */ out_fx[ k ] = extract_h( L_mac( Lacc, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], temp2 )); /* Qx format */ - state_fx[ ALLPASSSECTIONS_STEEP-1 ] = extract_h( L_msu ( Lacc1, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], out_fx[k] )); /* Qx */ + mem[ ALLPASSSECTIONS_STEEP-1 ] = extract_h( L_msu ( Lacc1, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], out_fx[k] )); /* Qx */ } /* lower allpass filter chain */ - Lacc = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ - Lacc = L_mac( Lacc, AP2_STEEP_FX[0], state_fx[2*ALLPASSSECTIONS_STEEP] ); /*Q(16+x) */ - Lacc1 = L_deposit_h( state_fx[2*ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ + Lacc = L_mac( Lacc, AP2_STEEP_FX[0], mem[2*ALLPASSSECTIONS_STEEP] ); /*Q(16+x) */ + Lacc1 = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ temp1 = extract_h( Lacc ); /* Qx */ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ - state_fx[ ALLPASSSECTIONS_STEEP ] = extract_h( Lacc1 ); + mem[ ALLPASSSECTIONS_STEEP ] = extract_h( Lacc1 ); temp[0] = temp1; move16(); - Lacc1 = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ + Lacc1 = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ Lacc1 = L_mac( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */ temp2 = extract_h( Lacc1 ); /* Qx */ temp[1] = temp2; move16(); Lacc = L_msu( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ - state_fx[ALLPASSSECTIONS_STEEP+1] = extract_h( Lacc ); /* Qx */ + mem[ALLPASSSECTIONS_STEEP+1] = extract_h( Lacc ); /* Qx */ - Lacc = L_deposit_h( state_fx[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp2 ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ temp[2] = extract_h( Lacc ); /* temp[2] in Qx */ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */ - state_fx[ 2*ALLPASSSECTIONS_STEEP-1 ] = extract_h( Lacc1 ); /* Qx */ + mem[ 2*ALLPASSSECTIONS_STEEP-1 ] = extract_h( Lacc1 ); /* Qx */ sum = mult_r( out_fx[0], 16384 ); /* Qx */ out_fx[0] = add( sum, mult_r(temp[ALLPASSSECTIONS_STEEP-1], 16384 )); /* Qx */ move16(); @@ -697,31 +701,31 @@ void Decimate_allpass_steep_fx( const Word16 *in_fx, { - Lacc = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ Lacc = L_mac(Lacc, AP2_STEEP_FX[0], in_fx[2*k-1] ); /* Q(16+x):temp[0] */ Lacc1 = L_deposit_h( in_fx[ 2*k-1 ] ); /* Q(16+x) */ temp1 = extract_h( Lacc ); /* Qx */ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ - state_fx[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); /* Qx */ + mem[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); /* Qx */ temp[0] = temp1; move16(); - Lacc1 = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ + Lacc1 = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ Lacc1 = L_mac(Lacc1,AP2_STEEP_FX[1],temp1); /* Q(16+x) */ temp2 = extract_h( Lacc1 ); /* Qx */ temp[1] = temp2; move16(); Lacc = L_msu(Lacc,AP2_STEEP_FX[1],temp2); /* Q(16+x) */ - state_fx[ALLPASSSECTIONS_STEEP+1]= extract_h(Lacc); /* Qx */ + mem[ALLPASSSECTIONS_STEEP+1]= extract_h(Lacc); /* Qx */ - Lacc = L_deposit_h( state_fx[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[1] ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ temp[2] = extract_h( Lacc ); /*temp[2] in Qx */ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */ - state_fx[2*ALLPASSSECTIONS_STEEP-1] = extract_h( Lacc1 ); /* Qx */ + mem[2*ALLPASSSECTIONS_STEEP-1] = extract_h( Lacc1 ); /* Qx */ @@ -733,19 +737,23 @@ void Decimate_allpass_steep_fx( const Word16 *in_fx, /* z^(-1) */ - state_fx[ 2*ALLPASSSECTIONS_STEEP ] = in_fx[ N-1 ]; + mem[ 2*ALLPASSSECTIONS_STEEP ] = in_fx[ N-1 ]; move16(); /* Qx */ } +/*-------------------------------------------------------------------* + * Interpolate_allpass_steep() + * + * Interpolation by a factor 2 + *-------------------------------------------------------------------*/ -void Interpolate_allpass_steep_fx(const Word16 *in_fx, - Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]) /* array of size 2*N */ - - +void Interpolate_allpass_steep_fx( + const Word16 *in_fx, + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[]) /* array of size 2*N */ { Word16 k; @@ -758,28 +766,28 @@ void Interpolate_allpass_steep_fx(const Word16 *in_fx, FOR (k=0; k +#include "options.h" #include "rom_com_fx.h" #include "prot_fx.h" -#include "stl.h" /*===================================================================*/ @@ -29,11 +30,11 @@ /* _ None. */ /*===================================================================*/ Word16 dequantize_uvg_fx( - Word16 iG1, - Word16 *iG2, - Word16 *G, - Word16 bwidth_fx - ,Word16 do_scale + const Word16 iG1, /* i: gain 1 index */ + const Word16* iG2, /* i: gain 2 index */ + Word16* G, /* o: quantized gain */ + const Word16 bwidth_fx, /* i: bandwidth */ + const Word16 do_scale ) { Word16 i, k; @@ -135,9 +136,9 @@ Word16 dequantize_uvg_fx( /*===================================================================*/ void generate_nelp_excitation_fx( Word16 *seed, /* i/o: random number seed */ - Word16 *Gains, /* i : excitation gains Q_exc*/ + const Word16 *Gains, /* i : excitation gains Q_exc*/ Word16 *output, /* o : excitation output */ - Word16 gain_fac /* i : gain factor */ + const Word16 gain_fac /* i : gain factor */ ) { Word16 i, len, j; diff --git a/lib_com/options.h b/lib_com/options.h index 6ff5ded..6846cd7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -6,11 +6,15 @@ #ifndef OPTIONS_H #define OPTIONS_H -#define DEBUGGING + + +#define DEBUGGING /*allows message printed out during run time */ + #ifdef DEBUGGING #include "debug.h" #endif + #include "stl.h" /* ################### Start compiler switches ######################## */ @@ -20,6 +24,93 @@ #endif #define SUPPORT_JBM_TRACEFILE /* support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * Keywors concerning IVAS to be search for in the code + * + *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + /* #define _DIFF_FLOAT_FIX_*/ /* ->>>>>>> difference observed between fix and floating point*/ + +/* IVAS_CNST_AND_ROM Some constant and ROM added for IVAS */ + +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +#define IVAS_CNST +#define REMOVE_IVAS_UNUSED_PARAMETERS_WARNING /*temporary operation on unused parameters to remove warnings */ +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING /*temporary operation on unused parameters to remove warnings (works in msvc, but not for gcc */ +#define MY_UNUSED_Word32(a) { Word32 b; b = a+1; b++; } +#define MY_UNUSED_Word(a) { Word16 b; b = a+1; b++; } +#define MY_UNUSED_Array(a) { Word16 b; if (a!= NULL) {b = a[0]+1; b++;}else {b= 0;} } +#endif + + //#define MSVQ_ROM ->>>>At least tables under MSVQ_ROM plus scales, scales_p, sigma_p, inv_sigma_p, need update +//#define MY_DEBUG + +#define MOD_BIT_ALLOC_ROM_TABLE // Just to highlight modification in bit allocation table and to ensure these modifications doesn't affect EVS modes*/ +#define SIMPLIFY_CODE_BE // Simplify synthesis loop + +//#define AFFECT_TEST_VECTOR_BE_1 /* This concerns the reset of infoTotalBitsPerFrameWritten */ +//#define AFFECT_TEST_VECTOR_BE_dec /* This is related to the CR concerning lead_deindexing, it is just that my test vectors are not updated accordingly */ + + +#if 0 /*These are a list of switches that highlight probable places where IVAS code would need to be added */ + #define IVAS_CODE /* General code added into EVS for IVAS purpose only*/ + #define NEW_IVAS_OPEN_DEC /* Structural changes un core_init_dec.c */ + + #define IVAS_CODE_AVQ + #define IVAS_CODE_AVQ_LPC + #define IVAS_CODE_TCX + #ifdef IVAS_CODE_TCX + #define IVAS_CODE_TCX_LTP + #define IVAS_CODE_TCX_UTIL + #endif + #define IVAS_CODE_FCB + #define IVAS_CODE_SWITCHING + #define IVAS_CODE_CNG + #ifdef IVAS_CODE_CNG + #define IVAS_CODE_CNG_COM + #define IVAS_CODE_CNG_FIX185_PLC_FADEOUT + #endif + #define IVAS_FEC_ECU_TO_COMPLETE + #define IVAS_CODE_MDCT_GSHAPE /*code to be completed/verified in TonalComponentDetection.c*/ + #define ADD_IVAS_TBE_CODE + + #define IVAS_CODE_TCX_COM + #define ADD_IVAS_HQ_CODE + #define ADD_IVAS_HQ_CODE_FEC + #define IVAS_CODE_COM_CONFIG_P1 /* core_com_conf */ + #define ADD_IVAS_BWE + #define AVQ_DEMUX + #define ADD_LRTD + #define GSC_IVAS + #define LSF_RE_USE_SECONDARY_CHANNEL + #define IVAS_GAIN_MOD + #define ADD_IVAS_GS_DEC_IMPR /* -> doesnt seem used at all in IVAS to be confirm */ + #define ADD_IVAS_CLDFB /* Code to be added to CLDFB for ivas */ + #define IVAS_CONTEXT_MAPPING /* Fixed point range decoder is missing */ + #define ADD_BPF_ADAPT /* bass post filter adaptation function missing */ + #define IVAS_CODE_CON_TCX /*missing code in er_dec_tcx*/ + #define ADD_IVAS_HTONALMDCTCONC /* handle for tonal mdct concealment is missing */ + #define ADD_IVAS_TNS /* Code to be completed in tns , cod_tcx*/ + #define IVAS_CODE_RANGE_CODER /* Range coder code that is missing, mainly in ACcontext_mapping */ + #define IVAS_CODE_BITSTREAM + + /* Encoder*/ +#define IVAS_CODE_CPE /*floating point code related to CPE */ +#define IVAS_CODE_DFT /*floating point code related to DFT (sp analysis and more) */ +#define IVAS_CODE_BWD /*floating point code in the BWD to be converted */ +#define IVAS_MSVQ /*floating point code in the lsf_tool to be converted */ +#endif + +/* #define FIX_I4_OL_PITCH */ + + +/*#define ADD_IVAS_HQ_CODE_L_SPEC*/ /*-->> might go hand in hand with SOLVED_COMP_ENC_DEC*/ +#ifdef ADD_IVAS_HQ_CODE_L_SPEC + #define SOLVED_COMP_ENC_DEC// /*HQ classifier must be aligned between encoder and decoder -> Does break to IO with legacy EVS 48 kHz high bitrate?, seems ok from preliminry tests */ +#endif + + /* */ /* ##################### End compiler switches ######################## */ diff --git a/lib_com/parameter_bitmaping.c b/lib_com/parameter_bitmaping.c index 2124258..b6fdbe9 100644 --- a/lib_com/parameter_bitmaping.c +++ b/lib_com/parameter_bitmaping.c @@ -2,8 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include "stl.h" +#include +#include "options.h" #include #include "prot_fx.h" @@ -12,7 +12,13 @@ /********************************/ /** Put nBits long encoded value from *pStream into bitstream. Using the function EncodeValue for encoding. */ -static Word16 PutIntoBitstream(Word16 const ** pStream, TEncodeValue EncodeValue, Word16 index, Encoder_State_fx *st_fx, Word16 nBits) +static Word16 PutIntoBitstream( + const Word16 ** pStream, + TEncodeValue EncodeValue, + Word16 index, + BSTR_ENC_HANDLE hBstr, + const Word16 nBits +) { Word16 value; Word16 codedValue; @@ -21,14 +27,20 @@ static Word16 PutIntoBitstream(Word16 const ** pStream, TEncodeValue EncodeValue value = *(*pStream)++; codedValue = EncodeValue(value, index); - push_next_indice_fx(st_fx, codedValue, nBits); + push_next_indice_fx(hBstr, codedValue, nBits); return value; } /** Get nBits long value from bitstream into *pStream. */ -static Word16 GetFromBitstream(Decoder_State_fx *st, TDecodeValue DecodeValue, Word16 index, Word16 nFixedBits, Word16 ** pStream) +static Word16 GetFromBitstream( + Decoder_State_fx *st, + TDecodeValue DecodeValue, + Word16 index, + Word16 nFixedBits, + Word16 ** pStream +) { Word16 value; @@ -50,7 +62,10 @@ static Word16 GetFromBitstream(Decoder_State_fx *st, TDecodeValue DecodeValue, W return value; } -static Word16 FixedWidthEncoding(Word16 value, Word16 index) +static Word16 FixedWidthEncoding( + Word16 value, + Word16 index +) { (void)index; return value; @@ -60,7 +75,14 @@ static Word16 FixedWidthEncoding(Word16 value, Word16 index) /* Interface functions */ /********************************/ -void GetParameters(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, void const * pParameter, Word16 ** pStream, Word16 * pnSize, Word16 * pnBits) +void GetParameters( + ParamsBitMap const * paramsBitMap, + const Word16 nArrayLength, + void const * pParameter, + Word16 ** pStream, + Word16 * pnSize, + Word16 * pnBits +) { Word16 index; Word16 iParam, nParams; @@ -128,7 +150,13 @@ void GetParameters(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, void } -void SetParameters(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, void * pParameter, Word16 const ** pStream, Word16 * pnSize) +void SetParameters( + ParamsBitMap const * paramsBitMap, + const Word16 nArrayLength, + void * pParameter, + const Word16 ** pStream, + Word16 * pnSize +) { Word16 index; Word16 iParam, nParams; @@ -172,11 +200,20 @@ void SetParameters(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, void } -void WriteToBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Word16 const ** pStream, Word16 * pnSize, Encoder_State_fx *st, Word16 * pnBits) +void WriteToBitstream( + ParamsBitMap const * paramsBitMap, + const Word16 nArrayLength, + const Word16 ** pStream, + Word16 * pnSize, + BSTR_ENC_HANDLE hBstr, + Word16 * pnBits +) { Word16 index; Word16 iParam, nParams; - assert((paramsBitMap != NULL) && (nArrayLength > 0) && (pStream != NULL) && (pnSize != NULL) && (st != NULL) && (pnBits != NULL)); + + + assert((paramsBitMap != NULL) && (nArrayLength > 0) && (pStream != NULL) && (pnSize != NULL) && (hBstr != NULL) && (pnBits != NULL)); nParams = paramsBitMap->nParams; FOR (index = 0; index < nArrayLength; index++) @@ -211,7 +248,7 @@ void WriteToBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Wo move16(); EncodeValue = &FixedWidthEncoding; } - value = PutIntoBitstream(pStream, EncodeValue, index, st, nBits); + value = PutIntoBitstream(pStream, EncodeValue, index, hBstr, nBits); if (fShiftValue) { value = add(value, 1); @@ -224,14 +261,20 @@ void WriteToBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Wo IF ((param->pSubParamBitMap != NULL) && (value > 0)) { - WriteToBitstream(param->pSubParamBitMap, value, pStream, pnSize, st, pnBits); + WriteToBitstream(param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits); } } } } -void ReadFromBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Decoder_State_fx *st, Word16 ** pStream, Word16 * pnSize) +void ReadFromBitstream( + ParamsBitMap const * paramsBitMap, + const Word16 nArrayLength, + Decoder_State_fx *st, + Word16 ** pStream, + Word16 * pnSize +) { Word16 index; Word16 iParam, nParams; diff --git a/lib_com/phase_dispersion.c b/lib_com/phase_dispersion.c index f2a5f67..10e5fd5 100644 --- a/lib_com/phase_dispersion.c +++ b/lib_com/phase_dispersion.c @@ -2,12 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" /* EV-VBR compilation switches */ #include "prot_fx.h" #include "basop_util.h" -#include "stl.h" /* Weighted mops computation related code */ /*-----------------------------------------------------------------------* * phase_dispersion: diff --git a/lib_com/ppp_fx.c b/lib_com/ppp_fx.c index 21d6b01..0e03039 100644 --- a/lib_com/ppp_fx.c +++ b/lib_com/ppp_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" -#include "stl.h" /*===================================================================*/ /* FUNCTION : Interpol_delay_fx () */ @@ -55,12 +55,11 @@ void Interpol_delay_fx(Word16 *out_fx, Word16 last_fx, Word16 current_fx, *--------------------------------------------------------------------*/ void deemph_lpc_fx( - Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ - Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ - Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ - Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ - Word16 deemph_old - + const Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ + const Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ + Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ + Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ + const Word16 deemph_old ) { Word16 k,temp; diff --git a/lib_com/pred_lt4_fx.c b/lib_com/pred_lt4_fx.c index 88f32da..80c89f1 100644 --- a/lib_com/pred_lt4_fx.c +++ b/lib_com/pred_lt4_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* @@ -23,14 +22,13 @@ void pred_lt4( const Word16 excI[], /* in : excitation buffer */ - Word16 excO[], /* out: excitation buffer */ - Word16 T0, /* input : integer pitch lag */ - Word16 frac, /* input : fraction of lag */ - Word16 L_subfr, /* input : subframe size */ + Word16 excO[], /* out: excitation buffer */ + const Word16 T0, /* input : integer pitch lag */ + Word16 frac, /* input : fraction of lag */ + const Word16 L_subfr, /* input : subframe size */ const Word16 *win, /* i : interpolation window */ const Word16 nb_coef, /* i : nb of filter coef */ const Word16 up_sample /* i : up_sample */ - ) { Word16 i, j; @@ -104,9 +102,9 @@ void pred_lt4( /* NONE */ /*=======================================================================*/ void pred_lt4_tc_fx( - Word16 exc[], /* i/o: excitation buffer */ + Word16 exc[], /* i/o: excitation buffer */ const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i: fraction of lag */ + Word16 frac, /* i: fraction of lag */ const Word16 *win, /* i : interpolation window */ const Word16 imp_pos, /* i : glottal impulse position */ const Word16 i_subfr /* i : subframe index */ diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index b667eec..efb7fbb 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -1,10 +1,9 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------* * preemph_copy_fx() @@ -13,10 +12,10 @@ *-------------------------------------------------------------*/ void preemph_copy_fx( const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx */ + Word16 y[], /* o : output signal Qx */ const Word16 mu, /* i : preemphasis coefficient Q15 */ const Word16 lg, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (x[-1]) Qx */ + Word16 *mem /* i/o: memory (x[-1]) Qx */ ) { Word16 i, temp; diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ef98679..5f00004 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10,17 +10,59 @@ #include "typedefs.h" #include "stat_dec_fx.h" #include "stat_enc_fx.h" +#include "ivas_stat_enc.h" #include "stat_com.h" #include "cnst_fx.h" #include "basop_util.h" #include "complex_basop.h" +#include "ivas_error_utils.h" +#ifdef RAM_COUNTING_TOOL +#include "mem_count.h" +#endif /*----------------------------------------------------------------------------------* * Prototypes of global macros *----------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------* + * Prototypes of RAM counting tool macros + *----------------------------------------------------------------------------------*/ + +#ifdef RAM_COUNTING_TOOL +#define count_malloc( n1 ) MALLOC_FCT_CALL( n1 ) +#define count_calloc( n1, n2 ) CALLOC_FCT_CALL( n1, n2 ) +#define count_free( ptr ) FREE_FCT_CALL( ptr ) +#else +#define count_malloc( n1 ) malloc( n1 ) +#define count_calloc( n1, n2 ) calloc( n1, n2 ) +#define count_free( ptr ) free( ptr ) +#endif -void reset_preecho_dec_fx ( - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); +#define dynamic_malloc( n1 ) malloc( n1 ) +#define dynamic_calloc( n1, n2 ) calloc( n1, n2 ) +#define dynamic_free( n1 ) free( n1 ) + +void reset_preecho_dec_fx( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +); +/*IVAS_CNST_AND_ROM*/ +#ifndef SWAP +#define SWAP( a, b ) \ + { \ + tempr = ( a ); \ + ( a ) = ( b ); \ + ( b ) = tempr; \ + } +#endif + +#ifndef swap +#define swap( x, y, type ) \ + { \ + type u__p; \ + u__p = x; \ + x = y; \ + y = u__p; \ + } +#endif +/*End of IVAS_CNST_AND_ROM*/ void preecho_sb_fx( const Word32 brate, /* i Q0 : core bit-rate */ @@ -42,8 +84,8 @@ void preecho_sb_fx( void calc_normal_length_fx_32( const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : input signal : Q12 */ - const Word16 mode, /* i : input mode : Q0 */ + const Word32 *sp, /* i : i signal : Q12 */ + const Word16 mode, /* i : i mode : Q0 */ const Word16 extl, /* i : extension layer : Q0 */ Word16 *L_swb_norm, /* o : normalize length : Q0 */ Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ @@ -53,42 +95,43 @@ void calc_norm_envelop_fx_32( const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ Word32 *envelope_fx, /* o : normalized envelope : Q16 */ const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of input/output : Q0 */ + const Word16 SWB_flength, /* i : Length of i /output : Q0 */ const Word16 st_offset /* i : offset : Q0 */ ); void push_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 id, /* i : ID of the indice */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 id, /* i : ID of the indice */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ ); void push_next_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ ); void push_next_bits_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ - Word16 nb_bits /* i : number of bits to pack */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ + Word16 nb_bits /* i : number of bits to pack */ ); void get_NextCoderType_fx( UWord8 *bitsteam, /* i : bitstream */ Word16 *next_coder_type /* o : next coder type */ ); -void evs_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal */ - const Word16 n_samples /* i : number of input samples */ +ivas_error evs_enc_fx( + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16* data, /* i : i signal */ + Word32* mem_hp20_in_fx, /* i/o: hp20 filter memory */ + const Word16 n_samples /* i : number of i samples */ ); void io_ini_enc_fx( const int argc, /* i : command line arguments number */ char *argv[], /* i : command line arguments */ - FILE **f_input, /* o : input signal file */ + FILE **f_input, /* o : i signal file */ FILE **f_stream, /* o : output bitstream file */ FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ @@ -108,7 +151,7 @@ void read_next_brate_fx( Word32 *total_brate, /* i/o: total bitrate */ const Word32 last_total_brate, /* i : last total bitrate */ FILE *f_rate, /* i : bitrate switching profile (0 if N/A) */ - Word32 input_Fs, /* i : input sampling frequency */ + Word32 input_Fs, /* i : i sampling frequency */ Word16 *Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ Word16 *Opt_SC_VBR, /* i/o: SC-VBR flag */ Word16 *codec_mode /* i/o: MODE1 or MODE2 */ @@ -119,7 +162,7 @@ void read_next_bwidth_fx( Word16 *max_bwidth, /* i/o: maximum encoded bandwidth */ FILE *f_bwidth, /* i : bandwidth switching profile (0 if N/A) */ Word32 *bwidth_profile_cnt, /* i/o: counter of frames for bandwidth switching profile file */ - Word32 input_Fs /* i : input sampling frequency */ + Word32 input_Fs /* i : i sampling frequency */ ); UWord16 get_next_indice_fx( /* o : value of the indice */ @@ -149,7 +192,7 @@ UWord16 get_indice_1_fx( /* o : value of the indice */ ); void reset_indices_enc_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder state structure */ ); @@ -158,12 +201,16 @@ void reset_indices_dec_fx( ); void write_indices_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - FILE *file /* i : output bitstream file */ - , UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + FILE* file /* i : output bitstream file */ + , UWord8* pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ ); - +Word16 rate2EVSmode( + const Word32 brate, /* i : bitrate */ + Word16* is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ +); Word16 read_indices_fx( /* o : 1 = OK, 0 = something wrong */ Decoder_State_fx *st_fx, /* i/o: decoder state structure */ FILE *file, /* i : bitstream file */ @@ -177,9 +224,10 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem ); void indices_to_serial( - const Encoder_State_fx *st_fx, /* i: encoder state structure */ - UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ - Word16 *pFrame_size /* i: size of the binary encoded access unit [bits] */ + const Encoder_State_fx* st_fx, /* i: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + UWord8* pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + Word16* pFrame_size /* o: size of the binary encoded access unit [bits] */ ); void indices_to_serial_generic( @@ -239,7 +287,9 @@ void get_rfTargetBits( Word16 *rf_target_bits /* o : Number of RF target bits */ ); - +Word16 get_codec_mode( + const Word32 total_brate /* i : total bitrate */ +); Word16 BRATE2IDX_fx(Word32 brate); Word16 BRATE2IDX16k_fx(Word32 brate); @@ -255,7 +305,7 @@ void save_old_syn_fx( Word16 *mem_deemph /* i/o: deemphasis filter memory */ ); -void evs_dec_fx( +ivas_error evs_dec_fx( Decoder_State_fx *st_fx, /* i/o : Decoder state structure */ Word16 output_sp[], /* o : output synthesis signal */ frameMode_fx frameMode /* i : Decoder frame mode */ @@ -276,7 +326,7 @@ Word16 decodeVoip( void io_ini_dec_fx( const int argc, /* i : command line arguments number */ char *argv[], /* i : command line arguments */ - FILE **f_stream, /* o : input bitstream file */ + FILE **f_stream, /* o : i bitstream file */ FILE **f_synth, /* o : output synthesis file */ Word16 *quietMode, /* o : limited printouts */ Word16 *noDelayCmp, /* o : turn off delay compensation */ @@ -297,17 +347,18 @@ Word16 deindex_lvq_cng_fx( ); void CNG_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step /* o : allow CN step Q0 */ - ,Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ - ,Word32 *q_env + Decoder_State_fx* st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16* lsp_new, /* i/o: current frame LSPs Q15 */ + Word16* lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16* allow_cn_step, /* o : allow CN step Q0 */ + Word16* sid_bw /* i : 0-NB/WB, 1-SWB SID */ + , Word32* q_env +); +void td_cng_dec_init( + DEC_CORE_HANDLE st /* i/o: decoder state structure */ ); - void swb_CNG_dec_fx( Decoder_State_fx *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ @@ -316,14 +367,26 @@ void swb_CNG_dec_fx( const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ); +void GSC_enc_init( + GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */ +); + +void HQ_core_enc_init( + HQ_ENC_HANDLE hHQ_core /* i/o: HQ core data handle */ +); + void CNG_reset_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ + LPD_state_HANDLE hLPDmemm, /* i/o: acelp memories */ Word16 *pitch_buf, /* o : floating pitch for each subframe */ Word16 *voice_factors /* o : voicing factors */ ,Word16 VBR_cng_reset_flag ); +void speech_music_clas_init( + SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ +); + void CNG_reset_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 *pitch_buf, /* o : floating pitch for each subframe */ @@ -331,49 +394,50 @@ void CNG_reset_dec_fx( ); void CNG_exc_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - Word32 *Enew, /* i/o: decoded SID energy Q6 */ - Word16 *seed, /* i/o: random generator seed */ - Word16 exc[], /* o : current non-enhanced excitation Q_new */ - Word16 exc2[], /* o : current enhanced excitation Q_new */ - Word32 *lp_ener, /* i/o: LP filtered E */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ - Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ - const Word16 allow_cn_step, /* i : allow CN step */ - Word16 *last_allow_cn_step, /* i/o: last allow step */ - const Word16 OldQ_exc, /* i : Old excitation scaling */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 num_ho /* i : number of selected hangover frames */ - ,Word32 q_env[] - ,Word32 *lp_env - ,Word32 *old_env - ,Word16 *exc_mem - ,Word16 *exc_mem1 - ,Word16 *sid_bw - ,Word16 *cng_ener_seed1 - ,Word16 exc3[] - ,Word16 Opt_AMR_WB + const Word32 core_brate, /* i : core bitrate */ + const Word16 L_frame, /* i : length of the frame */ + Word32* Enew, /* i/o: decoded SID energy Q6 */ + Word16* seed, /* i/o: random generator seed */ + Word16 exc[], /* o : current non-enhanced excitation Q_new */ + Word16 exc2[], /* o : current enhanced excitation Q_new */ + Word32* lp_ener, /* i/o: LP filtered E */ + const Word32 last_core_brate,/* i : previous frame core bitrate */ + Word16* first_CNG, /* i/o: first CNG frame flag for energy init. */ + Word16* cng_ener_seed, /* i/o: random generator seed for CNG energy */ + Word16 bwe_exc[], /* o : excitation for SWB TBE */ + const Word16 allow_cn_step, /* i : allow CN step */ + Word16* last_allow_cn_step, /* i/o: last allow step */ + const Word16 OldQ_exc, /* i : Old excitation scaling */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 num_ho, /* i : number of selected hangover frames */ + Word32 q_env[], + Word32* lp_env, + Word32* old_env, + Word16* exc_mem, + Word16* exc_mem1, + Word16* sid_bw, + Word16* cng_ener_seed1, + Word16 exc3[], + Word16 Opt_AMR_WB, + const Word16 element_mode /* i : IVAS Element mode */ +); +Word16 get_cng_mode( + const Word32 last_active_brate /* i : last active bitrate */ ); void CNG_enc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ - Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ - Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ - Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 burst_ho_cnt, /* i : hangover frames at end of speech burst Q0 */ - Word16 Q_new /* i : Q value of speech */ - ,Word32 *q_env - ,Word16 *sid_bw - ,Word16 *exc_mem2 + Encoder_State_fx* st_fx,/* i/o: State structure */ + Word16 Aq[], /* o : LP coefficients Q12 */ + const Word16* speech, /* i : pointer to current frame i speech buffer Q_new */ + Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ + const Word16* lsp_mid, /* i : mid frame LSPs Q15 */ + Word16* lsp_new, /* i/o: current frame ISPs Q15 */ + Word16* lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ + Word16* allow_cn_step, /* o : allow CN step Q0 */ + Word16 Q_new, /* i : Q value of speech */ + Word32* q_env, + Word16* sid_bw ); - void swb_CNG_enc_fx( Encoder_State_fx *st_fx, /* i/o: State structure */ const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ @@ -406,16 +470,20 @@ void cng_params_postupd_fx( const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ Word32 ho_env_circ[] /* i/o: Envelope buffer */ ); -Word32 get_delay_fx( /* o : delay value in ms */ - const Word16 what_delay, /* i : what delay? (ENC or DEC) */ - const Word32 io_fs /* i : input/output sampling frequency */ +Word32 get_delay_fx( /* o : delay value in ms */ + const Word16 what_delay, /* i : what delay? (ENC or DEC) */ + const Word32 io_fs, /* i : input/output sampling frequency */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + , + const AUDIO_CONFIG output_config /* i : decoder output config */ +#endif ); void signalling_enc_fx( - Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 sharpFlag /* i : formant sharpening flag */ + Encoder_State_fx *st_fx /* i : encoder state structure */ ); Word16 signalling_mode1_tcx20_enc( @@ -433,16 +501,11 @@ void decision_matrix_core_dec( void decision_matrix_enc_fx( Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 sp_aud_decision1, /* i : 1st stage speech/music classification */ - const Word16 sp_aud_decision2, /* i : 2nd stage speech/music classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 vad_flag, Word16 *hq_core_type /* o : HQ core_fx type */ ); void decision_matrix_dec_fx( Decoder_State_fx *st, /* i/o: decoder state structure */ - Word16 *coder_type, /* o : coder type */ Word16 *sharpFlag, /* o : formant sharpening flag */ Word16 *hq_core_type, /* o : HQ core type */ Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ @@ -453,10 +516,11 @@ void init_gp_clip_fx( ); void gp_clip_test_isf_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 isf[], /* i : isf values (in frequency domain) */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); void pitch_ol_init_fx( @@ -467,7 +531,7 @@ void pitch_ol_init_fx( ); void noise_est_down_fx( - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) */ Word32 bckr[], /* i/o: per band background noise energy estimate */ Word32 tmpN[], /* o : temporary noise update */ Word32 enr[], /* o : averaged energy over both subframes */ @@ -482,37 +546,23 @@ void noise_est_down_fx( ); void wb_vad_init_fx( - Word16 *nb_active_frames, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt, - Word16 *lp_speech, /* o : long-term active speech level */ - Word16 *nb_active_frames_he, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt_he, - Word16 *bcg_flux, /* o : background noise fluctuation */ - Word16 *soft_hangover, /* o : soft hangover counter */ - Word16 *voiced_burst, /* o : consecutive voiced speech counter */ - Word16 *bcg_flux_init, /* o : initialization period for noise fluctuation estimation */ - Word16 *nb_active_frames_he1, /* o : nb of consecutive active speech frames 1 */ - Word16 *hangover_cnt_he1, - Word32 *L_vad_flag_reg_H, - Word32 *L_vad_flag_reg_L, - Word32 *L_vad_prim_reg, - Word16 *vad_flag_cnt_50, - Word16 *vad_prim_cnt_16, - Word16 *hangover_cnt_dtx, - Word16 *hangover_cnt_music + VAD_HANDLE hVAD /* i/o: VAD data handle */ ); Word16 wb_vad_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ - Word16 *localVAD, - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure */ - Word16 *localVAD_HE_SAD, /* o : HE_SAD decision without hangovers */ - Word8 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new /* i : scaling factor Q0 */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Q_new+QSCALE*/ + Word16* noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16* clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16* NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16* snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16* localVAD_HE_SAD, + Word8* flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech, /* i : long term active speech energy average */ + Word16 lp_noise /* i : long term noise energy */ ); @@ -530,46 +580,36 @@ void dtx_hangover_control_fx( ); Word16 dtx_hangover_addition_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 localVAD, /* i Q0 */ - const Word16 vad_flag, /* i Q0 */ - const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 */ - Word16 *vad_hover_flag_ptr + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word16 vad_flag, /* i Q0 */ + const Word16 lp_snr, /* i Q8 */ + const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ + Word16* vad_hover_flag_ptr, + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ +); +void td_cng_enc_init( + TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ ); +void dtx_enc_init( + Encoder_State_fx* st, /* i : Encoder state handle */ + const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ + const Word16 interval_SID /* i : interval for SID update */ +); void noise_est_init_fx( - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 *first_noise_updt, /* o : noise update initialization flag */ - Word32 bckr[], /* o : per band background noise energy estimate */ - Word32 enrO[], /* o : per band old input energy */ - Word32 ave_enr[], /* o : per band long-term average energies */ - Word16 *pitO, /* o : open-loop pitch values from preceed. frame */ - Word16 *aEn, /* o : noise adaptation hangover counter */ - Word16 *st_harm_cor_cnt, /* i/o: 1st harm correlation timer */ - Word16 *bg_cnt, /* i/o: pause burst length counter */ - Word16 *lt_tn_track, /* Q15 */ - Word16 *lt_tn_dist, /* Q8 */ - Word16 *lt_Ellp_dist, /* Etot low lp same domain as *Etot_l_lp, Q8 */ - Word16 *lt_haco_ev, /* Q15 */ - Word16 *low_tn_track_cnt /* Q0 */ - ,Word16 *Etot_st_est, /* Q8: Short term Etot Estimate for variance calc */ - Word16 *Etot_sq_st_est /* Q2 : Short term Etot^2 Estimate for variance calc */ - + NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */ ); - - void noise_est_pre_fx( const Word16 Etot, /* i : Energy of current frame */ const Word16 ini_frame_fx, /* i : Frame number (init) */ - Word16 *Etot_l, /* i/o: Track energy from below */ /*Q8 */ - Word16 *Etot_h, /* i/o: Track energy from above */ /*Q8 */ - Word16 *Etot_l_lp, /* i/o: Smoothed low energy */ /*Q8 */ - Word16 *Etot_last, /* i/o: Energy of last frame */ /*Q8 */ - Word16 *Etot_v_h2, /* i/o: Energy variations */ /*Q8*/ - Word16 *sign_dyn_lp, /* i/o: Smoother signal dynamics */ /*Q8*/ - Word16 harm_cor_cnt, /* i : correlation counter */ - Word16 *Etot_lp /* i/o: Smoothed energy */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const Word16 idchan, /* i : channel ID */ + const Word16 element_mode, /* i : element mode */ + const Word16 last_element_mode /* i : last element mode */ + ); void Preemph_scaled( @@ -613,13 +653,14 @@ void Scale_mem_enc( ); void SetModeIndex( - Encoder_State_fx *st, - Word32 total_brate, - Word16 bwidth, + Encoder_State_fx* st, + Word32 last_total_brate, + const Word16 last_element_mode, + const Word16 is_mct, const Word16 shift ); -void init_encoder_fx( +ivas_error init_encoder_fx( Encoder_State_fx *st_fx /* i/o: Encoder static variables structure */ ); @@ -637,25 +678,27 @@ void analysisCldfbEncoder_fx( CLDFB_SCALE_FACTOR * scale ); -void cldfb_save_memory (HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ +ivas_error cldfb_save_memory (HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ void cldfb_restore_memory (HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ void cldfb_reset_memory (HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ Word16 gp_clip_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16* voicing, /* i : normalized correlations (from OL pitch) */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : type of coder */ + const Word16 xn[], /* i : target vector */ Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Q_new /* i : scaling factor */ + const Word16 Q_new /* i : scaling factor */ ); -void init_decoder_fx( - Decoder_State_fx *st_fx /* o: Decoder static variables structure */ +ivas_error init_decoder_fx( + Decoder_State_fx *st_fx, /* o: Decoder static variables structure */ + const Word16 idchan /* i : channel ID */ ); -void destroy_decoder( +void destroy_cldfb_decoder( Decoder_State_fx *st_fx /* o: Decoder static variables structure */ ); Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 */ @@ -663,54 +706,57 @@ Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 */ const Word16 len /* i : impulse response length Q0 */ ); void FEC_scale_syn_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ + const Word16 L_frame, /* i : length of the frame */ + Word16* update_flg, /* o: flag indicating re-synthesis after scaling*/ + Word16 clas, /* i/o: frame classification */ + const Word16 last_good, /* i: last good frame classification */ + Word16* synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ + const Word16* pitch, /* i: pitch values for each subframe */ + Word32 L_enr_old, /* i: energy at the end of previous frame */ + Word32 L_enr_q, /* i: transmitted energy for current frame */ + const Word16 coder_type, /* i: coder type */ + const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ + Word16* scaling_flag, /* i/o: flag to indicate energy control of syn */ + Word32* lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ + Word32* lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + const Word16 bfi, /* i: current frame BFI */ + const Word32 total_brate, /* i: total bitrate */ + const Word16 prev_bfi, /* i: previous frame BFI */ + const Word32 last_core_brate, /* i: previous frame core bitrate */ + Word16* exc, /* i/o: excitation signal without enhancement */ + Word16* exc2, /* i/o: excitation signal with enhancement */ + Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ + Word16* old_enr_LP, /* i/o: LP filter E of last good voiced frame */ + const Word16* mem_tmp, /* i: temp. initial synthesis filter states */ + Word16* mem_syn, /* o: initial synthesis filter states */ Word16 Q_exc, - Word16 Q_syn - , Word16 avoid_lpc_burst_on_recovery /* i : if true the excitation energy is limited if LP has big gain */ - , Word16 force_scaling /* i: force scaling */ + Word16 Q_syn, + const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ + const Word16 force_scaling /* i: force scaling */ ); void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q15 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type_fx /* i : Last coder_type */ + const Word16 clas, /* i : signal frame class */ + const Word16 coder_type, /* i : coder type */ + const Word32 core_brate, /* i : bitrate allocated to the core */ + Word16 *seed_tcx, /* i/o: Seed used for noise generation */ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ + Word16 *mem_syn2_fx, /* i/o: synthesis memory */ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q15 */ + const Word16 locattack, /* i : Flag for a detected attack */ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ + Word16 *exc2_fx, /* i/o: Decoded complete excitation */ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ + Word16 *syn_fx, /* o: Decoded synthesis to be updated */ + const Word16 Q_syn, /* i : Synthesis scaling Q0 */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer */ + const Word16 Last_ener_fx, /* i : Last energy (Q8) */ + const Word16 rate_switching_reset, /* i : rate switching reset flag */ + const Word16 last_coder_type_fx /* i : Last coder_type */ +#ifdef ADD_IVAS_GS_DEC_IMPR + ,const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ +#endif ); void FEC_pitch_estim_fx( @@ -734,21 +780,19 @@ Word16 div_s_ss( /* o: result of division (Word16 Q0) Word16 detect_transient_fx( const Word16 *in_fx, /*Q_new */ - /*Encoder_State *st, */ const Word16 L, - const Word16 coder_type, /* i : coder type */ Word16 Q_new, Encoder_State_fx *st_fx ); Word16 detect_transient_fx32( /* o : transient flag */ - const Word32* in_fx, /* i : input signal */ + const Word32* in_fx, /* i : i signal */ Encoder_State_fx *st_fx, /* i/o: Encoder state structure */ const Word16 L, /* i : length (32 or 48kHz) */ const Word16 coder_type /* i : coder type */ ); -void ar_encoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst, Word32 max_bits ); +void ar_encoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst, const Word32 max_bits ); void ar_encoder_done_fx( PARCODEC_FX arInst ); void ar_decoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst ); void ar_decoder_done_fx( PARCODEC_FX arInst ); @@ -769,22 +813,22 @@ void decode_magnitude_usq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Wo void decode_mangitude_tcq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out, Word32* surplus_fx); void decode_signs_fx(ARCODEC_FX* pardec, Word16 size, Word16* out); -void tcq_core_LR_enc_fx( - Encoder_State_fx* st_fx, - Word16 inp_vector_fx[], - const Word32 coefs_norm_fx[], - Word32 coefs_quant_fx[], - const Word16 bit_budget, /* number of bits */ - const Word16 nb_sfm, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word32 *R_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, +ivas_error tcq_core_LR_enc_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 inp_vector_fx[], /* x5 */ + const Word32 coefs_norm_fx[], /* Q12 */ + Word32 coefs_quant_fx[], /* Q12 */ + const Word16 bit_budget, /* number of bits */ + const Word16 BANDS, + const Word16* sfm_start, + const Word16* sfm_end, + const Word16* sfmsize, + Word32* R_fx, /* Q16 */ + Word16* npulses, + Word16* k_sort, + const Word16* p2a_flags, const Word16 p2a_bands, - const Word16 *last_bitalloc, + const Word16* last_bitalloc, const Word16 input_frame, const Word16 adjustFlag, const Word16 is_transient @@ -880,13 +924,13 @@ void window_ola_fx( ); void tcx_get_windows_mode1( - Word16 left_mode, /* i: overlap mode of left window half */ - Word16 right_mode, /* i: overlap mode of right window half */ - Word16 *left_win, /* o: left overlap window */ - Word16 *right_win, /* o: right overlap window */ - Word16 *left_win_int, /* o: left overlap window */ - Word16 *right_win_int, /* o: right overlap window */ - Word16 const L + const Word16 left_mode, /* i: overlap mode of left window half */ + const Word16 right_mode,/* i: overlap mode of right window half */ + Word16* left_win, /* o: left overlap window */ + Word16* right_win, /* o: right overlap window */ + Word16* left_win_int, /* o: left overlap window */ + Word16* right_win_int, /* o: right overlap window */ + const Word16 L /* i : length */ ); void sinq_fx( @@ -896,120 +940,19 @@ void sinq_fx( Word16 x[] /* o : output vector Q15*/ ); -Word16 FEC_phase_matching_fx( - Decoder_State_fx *st_fx, /* i : Decoder State */ - Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, - Word16 OldauOut_pha_fx[2][N_LEAD_NB] -); - -void FEC_phase_matching_nextgood_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 OldauOut_pha_fx[2][N_LEAD_NB], - Word16 mean_en_high_fx /* Q5 */ -); - -void FEC_phase_matching_burst_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 OldauOut_pha_fx[2][N_LEAD_NB], - Word16 *prev_oldauOut_fx /* i : OldauOut from previous frame */ -); - -void Repetition_smoothing_nextgood_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i : input */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 cur_data_use_flag, /* i : current imdct data use flag */ - Word16 overlap_time -); - -Word16 Repetition_smoothing_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i/o: audio from previous frame */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - const Word16 L, /* i : length */ - Word16 *prev_oldauOut_fx, /* i/o: IMDCT output from previous old frame */ - Word16 overlap_time /* i : overlapping time */ -); - void time_domain_FEC_HQ_fx( Decoder_State_fx *st_fx, /* i : Decoder State */ - Word32 *wtda_audio_fx, /* i : input */ + Word32 *wtda_audio_fx, /* i : i */ Word16 *out_fx, /* o : output audio */ Word16 mean_en_high_fx, /* i : transient flag */ const Word16 output_frame, Word16 *Q_synth ); -void common_overlapping_fx( - Word16 *auOut_fx, /* i : Input */ - Word16 *ImdctOutWin_fx, /* o : Output */ - Word16 *OldauOut_fx, /* i : Window */ - Word16 end1, /* i : Decay */ - Word16 offset1, - Word16 start2, - Word16 end2, - Word16 offset_i2, - Word16 offset2 -); - -void Smoothing_vector_scaledown_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2*/ - const Word16 ol_size /* i : Overlap size */ -); - -void Scaledown_fx( - Word16 x[], /* i : Input vector */ - Word16 y[], /* o : Output vector that contains vector 1 .* vector 2*/ - Word16 scale_v, - const Word16 N /* i : Overlap size */ -); - -void Smoothing_vector_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ -); -void Windowing_1st_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx, /* i : Window */ - const Word16 *smoothingWin_fx, /* i : Smoothing Window */ - Word16 smoothing_flag /* i : 1=Smoothing window, 0=Original window */ -); -void Windowing_2nd_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx /* i : Window */ -); -void Next_good_after_burst_erasures_fx( - const Word32 *ImdctOut_fx, - Word16 *auOut_fx, - Word16 *OldauOut_fx, - const Word16 ol_size -); -void subband_gain_bits_fx( - const Word16 *Rk, /* i : bit allocation per band Q3 */ - const Word16 N, /* i : number of bands */ - Word16 *bits, /* o : gain bits per band */ - const Word16 *sfmsize /* i : Size of bands */ -); Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits */ const Word16 core, /* i : HQ core */ @@ -1045,7 +988,7 @@ void fine_gain_pred_fx( ); void fine_gain_quant_fx( - Encoder_State_fx *st_fx, + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *ord, /* i : Indices for energy order */ const Word16 num_sfm, /* i : Number of bands */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ @@ -1073,56 +1016,40 @@ void get_max_pulses_fx( ); Word16 pvq_core_enc_fx( - Encoder_State_fx *st_fx, - Word16 coefs_norm[], - Word16 coefs_quant[], - Word16 *Q_coefs, - Word16 bits_tot, /* total number of bits */ - Word16 nb_sfm, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ + Word16 coefs_quant[], /* o : quantized coefficients */ + Word16* Q_coefs, + const Word16 bits_tot, /* i : total number of bits */ + const Word16 nb_sfm, /* i : number of bands */ + const Word16* sfm_start, /* i : Subband start coefficient */ + const Word16* sfm_end, /* i : Subband end coefficient */ + const Word16* sfmsize, /* i : subband width */ + Word16* R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16* Rs, /* i/o: Integer bit allocation */ + Word16* npulses, /* o : number of pulses */ + Word16* maxpulse, /* i : maximum pulse per band */ + const Word16 core /* i : number of bands */ ); void pvq_encode_frame_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *gopt, /* o : optimal shape gains */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16* coefs_norm, /* i : normalized coefficients to encode */ + Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ + Word16* coefs_quant, /* o : quantized coefficients */ + Word16* gopt, /* o : optimal shape gains */ + Word16* npulses, /* o : number of pulses per band */ + Word16* pulse_vector, /* o : non-normalized pulse shapes */ + const Word16* sfm_start, /* i : indices of first coefficients in the bands */ + const Word16* sfm_end, /* i : indices of last coefficients in the bands */ + const Word16* sfmsize, /* i : band sizes */ + const Word16 nb_sfm, /* i : total number of bands */ + const Word16* R, /* i : bitallocation per band Q3 */ + const Word16 pvq_bits, /* i : number of bits avaiable */ + const Word16 core /* i : core */ ); -void encode_energies_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs, - const Word16 Q_coefs, - Word16 Np, - Word16 *dim_part, - Word32 *E_part, /* 32-bit Q15 */ - Word16 *bits_part, - Word16 *g_part, /* Q15 */ - Word16 qband, - Word16 *bits_left, - Word32 enr, /* 32-bit Q15 */ - Word16 dim, - const Word16 strict_bits -); - Word16 pvq_core_dec_fx( Decoder_State_fx *st_fx, const Word16 *sfm_start, @@ -1155,6 +1082,7 @@ void pvq_decode_frame_fx( void decode_energies_fx( Decoder_State_fx *st_fx, + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 Np, Word16 *dim_part, Word16 *bits_part, @@ -1171,7 +1099,7 @@ Word16 atan2_fx( ); void srt_vec_ind16_fx ( - const Word16 *linear, /* linear input */ + const Word16 *linear, /* linear i */ Word16 *srt, /* sorted output*/ Word16 *I, /* index for sorted output */ Word16 length @@ -1197,31 +1125,35 @@ void mpvq_decode_vec_fx( /* o : void */ ); void rc_enc_init_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - Word16 tot_bits /* i : Total bit budget */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + Word16 tot_bits /* i : Total bit budget */ ); void rc_encode_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ UWord32 sym_freq, /* i : Symbol probability */ UWord32 tot /* i : Total cumulative frequency */ ); void rc_enc_uniform_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ UWord32 value, /* i : Value to encode */ UWord32 tot /* i : Maximum value */ ); void rc_enc_bits_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ UWord32 value, /* i : Value to encode */ Word16 bits /* i : Number of bits used */ ); void rc_enc_finish_fx( - Encoder_State_fx *st_fx /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ + PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ); Word16 rc_get_bits2_fx( /* o: Number of bits needed */ @@ -1237,61 +1169,69 @@ void rangeCoderFinalizationFBits_fx( ); void conservativeL1Norm_fx( - Word16 L, - Word16 Qvec, - Word16 Fcons, - Word16 Qavail, - Word16 Qreserv, - Word16 Dspec, - Word16 *Dvec, - Word16 *Qspare, - Word16 *Qreservplus, - Word16 *Dspecplus + const Word16 L, /* i : Length of vector segment */ + const Word16 Qvec, /* i : Assigned number of quanta */ + const Word16 Fcons, /* i : Conservative rounding flag */ + const Word16 Qavail, /* i : Input quanta remaining */ + const Word16 Qreserv, /* i : Input quanta in reservoir */ + const Word16 Dspec, /* i : assigned diracs from bitalloc */ + Word16* Dvec, /* o : actual number of diracs */ + Word16* Qspare, /* o : Output quanta remaining */ + Word16* Qreservplus, /* o : Output quanta in reservoir */ + Word16* Dspecplus /* o : Output number of diracs */ ); void bandBitsAdjustment_fx( - Word16 Brc, - UWord32 INTrc, - Word16 Bavail, - Word16 Nbands, - Word16 D, - Word16 L, - Word16 Bband, - Word16 Breserv, - Word16 *Bband_adj, - Word16 *Brem, - Word16 *Breservplus + const Word16 Brc, /* i : Current number of read quanta in range coder */ + const UWord32 INTrc, /* i : Range coder state */ + const Word16 Bavail, /* i : Available number of quanta */ + const Word16 Nbands, /* i : Number of bands */ + const Word16 D, /* i : Remaining number of bands to encode */ + const Word16 L, /* i : Size of current band */ + const Word16 Bband, /* i : Quanta allocation for current band */ + const Word16 Breserv, /* i : Quanta reservoir */ + Word16* Bband_adj, /* o : Actual used number of quanta */ + Word16* Brem, /* o : Quanta remaining */ + Word16* Breservplus /* o : Quanta pool size */ ); UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ + Word16* BER_detect, /* o : Bit error detection flag */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ UWord32 tot /* i : Total cumulative frequency */ ); void rc_dec_update_fx( Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency */ UWord32 sym_freq /* i : Symbol frequency */ ); UWord32 rc_dec_uniform_fx( /* i : Decoded value */ Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + UWord32 tot /* i : Maximum value */ ); void rc_dec_init_fx( Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 tot_bits /* i : Total bit budget */ ); Word32 rc_dec_bits_fx( /* i : Decoded value */ Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 bits /* i : Number of bits */ ); void rc_dec_finish_fx( - Decoder_State_fx *st_fx + Decoder_State_fx *st_fx, + PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ ); UWord32 UL_inverse( @@ -1305,11 +1245,12 @@ UWord32 UL_div( ); void hq_core_enc_fx( - Encoder_State_fx *st_fx, - const Word16 *audio, /* i : input audio signal Q0 */ - const Word16 input_frame_orig,/* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag + Encoder_State_fx* st_fx, + const Word16* audio, /* i : i audio signal Q0 */ + const Word16 input_frame_orig, /* i : frame length */ + const Word16 hq_core_type, /* i : HQ core type */ + const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ); void normalizecoefs_fx( @@ -1323,7 +1264,7 @@ void normalizecoefs_fx( void calc_norm_fx( const Word32 *L_x, /* i : Input vector. Qx */ - const Word16 qx, /* i : Q value of input */ + const Word16 qx, /* i : Q value of i */ Word16 *norm, /* o : Quantization indices for norms Q0 */ Word16 *normlg, /* o : Quantized norms in log2 Q0 */ const Word16 start_band, /* i : Indice of band to start coding Q0 */ @@ -1350,11 +1291,12 @@ void reordernorm_fx( ); void hq_hr_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure fx */ - Word32 *t_audio, /* i/o: transform-domain coefficients Q12? */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16 *num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient /* i : transient flag Q0 */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure fx */ + Word32* t_audio, /* i/o: transform-domain coefficients Q12 */ + const Word16 length, /* i : length of spectrum Q0 */ + Word16* num_bits, /* i : number of available bits Q0 */ + const Word16 is_transient, /* i : transient flag Q0 */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ); Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ @@ -1370,7 +1312,7 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 ); void hvq_classifier_fx( - const Word32 *input, /* i : input signal Q12 */ + const Word32 *i , /* i : i signal Q12 */ Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ Word16 *prev_peaks, /* i/o: Peak indices memory Q0 */ Word16 *hqswb_clas, /* i/o: HQ class Q0 */ @@ -1412,7 +1354,7 @@ void hq_wb_nf_bwe_fx( const Word16 prev_is_transient, /* i : previous transient flag */ Word32 *prev_normq_fx, /* i/o: previous norms */ Word32 *prev_env_fx, /* i/o: previous noise envelopes */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i */ Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ @@ -1434,19 +1376,20 @@ void harm_bwe_fine_fx( ); void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out /* o : coded/noisefilled spectrum */ + const Word16* coeff_fine, /* i : fine structure for BWE */ + const Word16* coeff, /* i : coded/noisefilled normalized spectrum */ + const Word16 num_sfm, /* i : Number of subbands */ + const Word16* sfm_start, /* i : Subband start coefficient */ + const Word16* sfm_end, /* i : Subband end coefficient */ + const Word16 last_sfm, /* i : last coded subband */ + const Word16* R, /* i : bit allocation */ + const Word16 prev_hq_mode, /* i : previous hq mode */ + Word16* norm, /* i/o: quantization indices for norms */ + Word16* noise_level, /* i/o: noise levels for harmonic modes */ + Word16* prev_noise_level, /* i/o: noise factor in previous frame */ + Word16* bwe_seed, /* i/o: random seed for generating BWE i */ + Word32* coeff_out, /* o : coded/noisefilled spectrum */ + const Word16 element_mode /* i : IVAS element mode */ ); void hq_generic_encoding_fx( @@ -1462,13 +1405,13 @@ void hq_generic_fine_fx( const Word16 last_sfm, /* i : Last coded band */ const Word16 *sfm_start, /* i : Subband start coefficient */ const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word16 *coeff_out1 /* o : HQ Generic input */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i */ + Word16 *coeff_out1 /* o : HQ Generic i */ ); void hq_bwe_fx( const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1, /* i/o: BWE input & temporary buffer */ + Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ Word32 *coeff_out, /* o : SWB signal in MDCT domain */ const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic bwe*/ @@ -1482,7 +1425,7 @@ void hq_bwe_fx( void hq_generic_decoding_fx( const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer */ + Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ @@ -1512,15 +1455,15 @@ Word16 get_nor_delta_hf_fx( ); Word16 calc_nor_delta_hf_fx( - Encoder_State_fx *st, - const Word32 *t_audio, - Word16 *ynrm, - Word16 *Rsubband, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 *sfmsize, - const Word16 *sfm_start, - const Word16 core_sfm + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32* t_audio, /* i : transform-domain coefficients */ + Word16* ynrm, /* i/o: norm indices */ + Word16* Rsubband, /* i/o: sub-band bit allocation */ + const Word16 num_env_bands, /* i : Number coded envelope bands */ + const Word16 nb_sfm, /* i : Number of envelope bands */ + const Word16* sfmsize, /* i : band length */ + const Word16* sfm_start, /* i : Start index of bands */ + const Word16 core_sfm /* i : index of the end band for core */ ); void HQ_FEC_processing_fx( @@ -1593,43 +1536,37 @@ void hvq_dec_fx( const Word16 core ); -void peak_vq_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 *coefs_out, /* o : Output coefficient vector Q12 */ - const Word16 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Number of peaks */ - const Word16 core -); - void hq_pred_hb_bws_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector */ + const Word16 length, /* i : frame length */ + const Word16 hqswb_clas, /* i : HQ SWB class */ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ ); void hq_core_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ + Word16 synth[], /* o : output synthesis */ + Word16 *Q_synth, /* o : Q value of synth */ + const Word16 output_frame, /* i : output frame length */ + const Word16 hq_core_type, /* i : HQ core type */ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ +); +void HQ_core_dec_init( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +); +void HQ_nbfec_init( + HQ_NBFEC_HANDLE hHQ_nbfec /* i/o: HQ NB FEC data handle */ ); - void hq_hr_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ - Word32 *L_coefsq, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv /* o : SWB frequency envelopes Q1 */ + Word32 *L_coefsq, /* o : transform-domain coefficients Q12 */ + const Word16 length, /* i : frame length Q0 */ + Word16 num_bits, /* i : number of available bits Q0 */ + Word16 *ynrm, /* o : norm quantization index vector Q0 */ + Word16 *is_transient, /* o : transient flag Q0 */ + Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ + Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ + const Word16 core_switching_flag /* i : Core switching flag */ ); void dequantize_norms_fx( @@ -1661,19 +1598,19 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 ); void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths */ - Word16 const **sfm_start, /* o : Subband start coefficients */ - Word16 const **sfm_end /* o : Subband end coefficients */ + Word16* nb_sfm, /* o : Number of sub bands Q0 */ + Word16* num_Sb, /* o : Number of FEC sub bands ? Q0 */ + Word16* num_bands_p, /* o : FEC sub bands Q0 */ + const Word16** sfmsize, /* o : Subband bandwidths */ + const Word16** sfm_start, /* o : Subband start coefficients */ + const Word16** sfm_end /* o : Subband end coefficients */ ); void hq_swb_harmonic_calc_norm_envelop_fx( - Word32 *L_SWB_signal, /* i : input signal Q=12*/ - Word32 *L_envelope, /* o : output envelope Q=12*/ - Word16 L_swb_norm, /* i : length of normaliztion */ - Word16 SWB_flength /* i : length of input signal */ + const Word32* L_SWB_signal, /* i : i signal Q=12*/ + Word32* L_envelope, /* o : output envelope Q=12*/ + const Word16 L_swb_norm, /* i : length of normaliztion */ + const Word16 SWB_flength /* i : length of i signal */ ); Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook */ @@ -1695,7 +1632,7 @@ Word16 find_last_band_fx( /* o : index of last band */ void apply_noisefill_HQ_fx( const Word16 *R, /* i : bit allocation */ - const Word16 length, /* i : input frame length */ + const Word16 length, /* i : i frame length */ const Word16 flag_32K_env_ho,/* i : envelope stability hangover flag*/ const Word32 L_core_brate, /* i : core bit rate */ const Word16 last_sfm, /* i : last coded subband */ @@ -1739,7 +1676,7 @@ void apply_nf_gain_fx( void logqnorm_fx( const Word32 *x, /* i : coefficient vector Qx */ - const Word16 qx, /* i : Q value of input */ + const Word16 qx, /* i : Q value of i */ Word16 *k, /* o : index Q0 */ const Word16 L, /* i : codebook length Q0 */ const Word16 N, /* i : sub-vector size Q0 */ @@ -1772,7 +1709,7 @@ void hvq_bwe_fx( Word16 *norm, /* i/o: quantization indices for norms Q0 */ Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i Q0 */ Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ const Word16 qin, const Word16 qout @@ -1811,16 +1748,17 @@ Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 * ); Word16 peak_vq_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 *coefs, /* i : Input coefficient vector Q14 */ - Word32 *coefs_out, /* o : Quantized output vector Q14 */ - const Word32 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q14 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32* coefs, /* i : Input coefficient vector Q12 */ + Word32* coefs_out, /* o : Quantized output vector Q12 */ + const Word32 brate, /* i : Core bitrate */ + const Word16 num_bits, /* i : Number of bits for HVQ */ + const Word16 vq_peaks, /* i : Number of identified peaks */ + const Word16* ynrm, /* i : Envelope coefficients */ + Word16* R, /* i/o: Bit allocation/updated bit allocation */ + Word16* vq_peak_idx, /* i : Peak index vector */ + Word32* nf_gains /* i : Estimated noise floor gains Q12 */ ); Word16 hvq_enc_fx( /* o : Consumed bits */ @@ -1897,8 +1835,9 @@ void env_adj_fx Word16 env_stability_fx( /* in Q15 */ const Word16 *ynrm, /*i: Norm vector for current frame */ const Word16 nb_sfm, /*i: Number of sub-bands */ - Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ - Word16 *mem_env_delta /*i/o: Envelope stability memory for smoothing in Q11 */ + Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ + Word16 *mem_env_delta, /*i/o: Envelope stability memory for smoothing in Q11 */ + const Word16 core_switching_flag/* i : Core switching flag */ ); Word16 env_stab_smo_fx( /* Q0 */ @@ -1929,9 +1868,9 @@ void hq_configure_fx( Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths Q0 */ - Word16 const **sfm_start, /* o : Subband start coefficients Q0 */ - Word16 const **sfm_end /* o : Subband end coefficients Q0 */ + Word16 *sfmsize, /* o : Subband bandwidths Q0 */ + Word16 *sfm_start, /* o : Subband start coefficients Q0 */ + Word16 *sfm_end /* o : Subband end coefficients Q0 */ ); Word16 hvq_pvq_bitalloc_fx( @@ -1953,15 +1892,15 @@ void disf_ns_28b_fx( ); void isf_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - Word16 *isf_new, /* o : quantized ISF vector */ - Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac /* o : ISF stability factor */ + Encoder_State_fx* st, /* i/o: state structure */ + Word16* isf_new, /* i/o: quantized ISF vector */ + Word16* isp_new, /* i/o: ISP vector to quantize/quantized */ + Word16* Aq /* o : quantized A(z) for 4 subframes */ ); void pvq_encode_fx( - Encoder_State_fx *st_fx, + BSTR_ENC_HANDLE hBstr, + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ Word16 *xq, /* o: quantized vector Q15 */ @@ -1973,8 +1912,9 @@ void pvq_encode_fx( void pvq_decode_fx( Decoder_State_fx *st_fx, - Word16 *xq, /* o: decoded vector (Q15) */ - Word16 *y, /* o: decoded vector (non-scaled int) */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 *xq, /* o: decoded vector (Q15) */ + Word16 *y, /* o: decoded vector (non-scaled int) */ const Word16 k_val, /* i: number of allocated pulses */ const Word16 dim, /* i: Length of vector */ const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ @@ -1985,30 +1925,26 @@ UWord32 intLimCDivPos_fx( Word16 DEN ); -Word32 intLimCDivSigned_fx( - Word32 NUM, - Word16 DEN -); Word16 shrtCDivSignedApprox( const Word16 num, const Word16 den ); void de_interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q? */ + Word32 *coefs, /* i/o: i and output coefficients Q? */ const Word16 length /* i : length of spectrum Q0 */ ); void interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q? */ + Word32 *coefs, /* i/o: i and output coefficients Q? */ const Word16 length /* i : length of spectrum Q0 */ ); void recovernorm_fx( - Word16 *idxbuf, /* i : reordered quantization indices */ - Word16 *ynrm, /* o : recovered quantization indices */ - Word16 *normqlg2, /* o : recovered quantized norms */ - Word16 nb_sfm /* i : number of SFMs */ + const Word16* idxbuf, /* i : reordered quantization indices */ + Word16* ynrm, /* o : recovered quantization indices */ + Word16* normqlg2, /* o : recovered quantized norms */ + const Word16 nb_sfm /* i : number of SFMs */ ); void map_quant_weight_fx( @@ -2030,7 +1966,7 @@ void fill_spectrum_fx( const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ + Word16 *bwe_seed, /* i/o: random seed for generating BWE i Q0 */ const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ const Word16 core_sfm, /* i : index of the end band for core Q0 */ const Word16 HQ_mode, /* i : HQ mode Q0 */ @@ -2053,17 +1989,15 @@ void fill_spectrum_fx( const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ const Word16 num_sfm, /* i : Total number of bands Q0 */ Word16 *prev_env_Q, - const Word16 num_env_bands + const Word16 num_env_bands, + const Word16 element_mode ); Word16 FEC_pos_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 last_good, /* i : last good classfication */ - Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ - Word16 *clas, /* o : decoded classification */ - Word32 *enr_q, /* o : decoded energy in Q0 */ - const Word32 core_brate /* i : decoded bitrate */ + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + Word16* last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ + Word32* enr_q, /* o : decoded energy in Q0 */ + const Word16 nBits_es_Pred /* i : number of bits for Es_pred Q */ ); void pit16k_Q_dec_fx( @@ -2162,17 +2096,16 @@ void FEC_lsf2lsp_interp( ); void FEC_lsf_estim_enc_fx( Encoder_State_fx *st_fx, /* i : Encoder static memory */ - const Word16 L_frame, /* i : length of the frame */ Word16 *lsf /* o : estimated LSF vector */ ); void FEC_clas_estim_fx( Decoder_State_fx *st_fx, /* i/o: decoder state handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ - const Word16 L_frame, /* i : length of the frame */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ + const Word16 L_frame, /* i : length of the frame */ Word16 *clas, /* i/o: frame classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 *pitch, /* i : pitch values for each subframe (Q6) */ + const Word16 coder_type, /* i : coder type */ + const Word16 *pitch, /* i : pitch values for each subframe (Q6) */ Word16 *syn, /* i : synthesis buffer */ Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ Word16 *decision_hyst, /* i/o: hysteresis of the music/speech decision */ /*A*/ @@ -2182,7 +2115,7 @@ void FEC_clas_estim_fx( Word16 *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ Word16 *lt_diff_etot, /* i/o: long-term total energy variation */ /*A*/ Word16 *amr_io_class, /* i/o: classification for AMR-WB IO mode */ /*A*/ - const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ + const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ Word16 Q_syn, /* i : Synthesis scaling */ Word16 *class_para, /* o : classification para. fmerit1 */ /*A*/ Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ @@ -2190,13 +2123,14 @@ void FEC_clas_estim_fx( Word16 LTP_Gain, /* i : LTP gain is 0..0.6 or negative Q15*/ /*B*/ Word16 mode, /* i : signal classifier mode *//*B*/ Word16 bfi, /* i : bad frame indicator *//*B*/ - Word32 last_core_brate /* i : bitrate of previous frame */ + Word32 last_core_brate, /* i : bitrate of previous frame */ + const Word16 FEC_mode /* i : ACELP FEC mode */ ); void non_linearity_fx( - const Word16 input[], /* i : input signal Q_inp */ + const Word16 i [], /* i : i signal Q_inp */ Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ + const Word16 length, /* i : i length */ Word32 *prev_scale, /* i/o: memory Q30 */ Word16 Q_inp, Word16 coder_type, /* i : Coder Type */ @@ -2205,12 +2139,12 @@ void non_linearity_fx( ); void stat_noise_uv_dec_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder static memory */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ + Decoder_State_fx *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector */ + Word16 *lsp_mid, /* i : mid-frame LSP vector */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ + Word16 *exc2 /* i/o: excitation buffer */ + , const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ); void stat_noise_uv_mod_fx( @@ -2231,7 +2165,7 @@ void stat_noise_uv_mod_fx( Word16 *st_min_alpha, /* i/o: minimum alpha */ Word16 *exc_pe, /* i/o: scale Q_stat_noise */ const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : input bandwidth */ + const Word16 bwidth_fx, /* i : i bandwidth */ Word16 *Q_stat_noise, /* i/o: noise scaling */ Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ); @@ -2240,7 +2174,7 @@ void stat_noise_uv_mod_fx( #define preemph_fx(signal,mu,L,mem) preemph_copy_fx((signal),(signal),(mu),(L),(mem)) void preemph_copy_fx( - const Word16 x[], /* i : input signal Qx */ + const Word16 x[], /* i : i signal Qx */ Word16 y[], /* o : output signal Qx */ const Word16 mu, /* i : preemphasis coefficient Q15 */ const Word16 lg, /* i : vector size Q0 */ @@ -2274,18 +2208,18 @@ void Vr_subt( ); Word16 gsc_gainQ_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 y_gain4[], /* i : Energy per band Q13 */ Word16 y_gainQ[], /* o : quantized energy per band Q13 */ const Word32 core_brate, /* i : Core rate */ const Word16 coder_type, /* i : coding type */ - const Word16 bwidth /* i : input signal bandwidth */ + const Word16 bwidth /* i : i signal bandwidth */ ); Word16 emaximum_fx( /* o : return index with max energy value in vector Q0 */ - const Word16 Qvec, /* i : Q of input vector Q0 */ - const Word16 *vec, /* i : input vector Qx */ - const Word16 lvec, /* i : length of input vector Q0 */ + const Word16 Qvec, /* i : Q of i vector Q0 */ + const Word16 *vec, /* i : i vector Qx */ + const Word16 lvec, /* i : length of i vector Q0 */ Word32 *ener_max /* o : maximum energy value Q0 */ ); @@ -2302,13 +2236,13 @@ void set32_fx( ); void Copy( - const Word16 x[], /* i : input vector */ + const Word16 x[], /* i : i vector */ Word16 y[], /* o : output vector */ const Word16 L /* i : vector length */ ); void Copy32( - const Word32 x[], /* i : input vector */ + const Word32 x[], /* i : i vector */ Word32 y[], /* o : output vector */ const Word16 L /* i : vector length */ ); @@ -2320,21 +2254,21 @@ void Scale_sig32( ); void Copy_Scale_sig( - const Word16 x[], /* i : signal to scale input Qx */ + const Word16 x[], /* i : signal to scale i Qx */ Word16 y[], /* o : scaled signal output Qx */ const Word16 lg, /* i : size of x[] Q0 */ const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ ); void Copy_Scale_sig_16_32( - const Word16 x[], /* i : signal to scale input Qx */ + const Word16 x[], /* i : signal to scale i Qx */ Word32 y[], /* o : scaled signal output Qx */ const Word16 lg, /* i : size of x[] Q0 */ const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ ); void Copy_Scale_sig_32_16( - const Word32 x[], /* i : signal to scale input Qx */ + const Word32 x[], /* i : signal to scale i Qx */ Word16 y[], /* o : scaled signal output Qx */ const Word16 lg, /* i : size of x[] Q0 */ const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ @@ -2349,18 +2283,14 @@ void init_lvq_fx( Word16 no_scales_p[][2] ); -void hf_synth_reset_fx( - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 mem_hf[], /* o : HF band-pass filter memory */ - Word16 mem_syn_hf[], /* o : HF synthesis memory */ - Word16 mem_hp400[], /* o : memory of hp 400 Hz filter */ - Word16 mem_hp_interp[], /* o : interpol. memory */ - Word16 delay_syn_hf[] /* o : HF synthesis memory */ +void sc_vbr_dec_init( + SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */ ); - void hf_synth_init_fx( - Word16 mem_hp400[], /* o : 400 Hz high pass filter memory initialization */ - Word16 mem_hf[] /* o : band pass 6kHz to 7kHz FIR filter initialization */ + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ +); +void hf_synth_reset_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ); Word16 Random( /* o : output random value */ @@ -2387,24 +2317,20 @@ void iDiv_and_mod_32( ); void lsf2lsp_fx( - const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ - Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ - const Word16 m, /* i : LPC order Q0 */ - Word32 int_fs + const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ + Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ + const Word16 m, /* i : LPC order Q0 */ + const Word32 int_fs /* i : internal sampling frequency */ ); void bass_psfilter_init_fx( - Word16 old_syn[], /* o : Old synthesis buffer 1 */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener /* o : long_term error signal energy */ + BPF_DEC_HANDLE hBPF /* o : BPF data handle */ ); - -void decod_gen_voic_fx( +ivas_error decod_gen_voic_fx( Decoder_State_fx *st_fx, /* i/o: decoder static memory */ const Word16 L_frame_fx, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ @@ -2422,23 +2348,21 @@ Word16 tc_classif_fx( ); void transition_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coder type */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *exc, /* o : excitation signal */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16 **pt_pitch, /* o : floating pitch values */ - Word16 *position, /* i/o: first glottal impulse position in frame */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *Q_exc /*i/o : scaling of excitation */ + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + Word16* Jopt_flag, /* i : joint optimization flag */ + Word16* exc, /* o : excitation signal */ + Word16* T0, /* o : close loop integer pitch */ + Word16* T0_frac, /* o : close loop fractional part of the pitch */ + Word16* T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16* T0_max, /* i/o: delta search max for sf 2 & 4 */ + Word16** pt_pitch, /* o : floating pitch values */ + Word16* position, /* i/o: first glottal impulse position in frame */ + Word16* bwe_exc, /* o : excitation for SWB TBE */ + Word16* Q_exc /*i/o : scaling of excitation */ ); void decod_tran_fx( @@ -2446,7 +2370,6 @@ void decod_tran_fx( const Word16 L_frame_fx, /* i : length of the frame */ const Word16 tc_subfr_fx, /* i : TC subframe index */ const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ Word16 *voice_factors_fx, /* o : voicing factors */ @@ -2459,9 +2382,9 @@ void decod_tran_fx( ); void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx */ + const Word16 inp_code_fx[], /* i : i vector Qx */ Word16 interp_code_fx[], /* o : output vector Qx */ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_length /* i : length of i vector */ ); void pred_lt4_tc_fx( @@ -2474,24 +2397,23 @@ void pred_lt4_tc_fx( ); void gaus_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word32 core_brate, /* i */ /*1 : core bitrate */ - const Word16 i_subfr, /* i */ /*2 : subframe index */ - Word16 *code, /* o */ /*3 : unvoiced excitation Q12 */ - Word32 *L_norm_gain_code, /* o */ /*4 : gain of normalized gaussian excitation Q16 */ - Word16 *lp_gainp, /* i/o */ /*5 : lp filtered pitch gain(FER) Q14 */ - Word16 *lp_gainc, /* i/o */ /*6 : lp filtered code gain (FER) Q3 */ - Word16 *inv_gain_inov, /* o */ /*7 : unscaled innovation gain Q12 */ - Word16 *tilt_code, /* o */ /*8 : synthesis excitation spectrum tilt Q15 */ - Word16 *voice_fac, /* o */ /*9 : estimated voicing factor Q15 */ - Word16 *gain_pit, /* o */ /*10 : pitch gain Q14 */ - Word16 *pt_pitch_1, /* o */ /*11 : floating pitch buffer Q6 */ - Word16 *exc, /* o */ /*12 : excitation signal frame */ - Word32 *L_gain_code, /* o */ /*13 : gain of the gaussian excitation Q16 */ - Word16 *exc2, /* o */ /*14 : Scaled excitation signal frame */ - Word16 *bwe_exc_fx, - Word16 *sQ_exc, /* i/o */ /*15 : Excitation scaling factor (Decoder state) */ - Word16 *sQsubfr /* i/o */ /*16 : Past excitation scaling factors (Decoder State) */ + Decoder_State_fx* st_fx, /* i/o: decoder static memory */ + const Word16 i_subfr, /* i : subframe index */ + Word16* code, /* o : unvoiced excitation Q12 */ + Word32* L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ + Word16* lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ + Word16* lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ + Word16* inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word16* tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ + Word16* voice_fac, /* o : estimated voicing factor Q15 */ + Word16* gain_pit, /* o : pitch gain Q14 */ + Word16* pt_pitch_1, /* o : floating pitch buffer Q6 */ + Word16* exc, /* o : excitation signal frame */ + Word32* L_gain_code, /* o : gain of the gaussian excitation Q16 */ + Word16* exc2, /* o : Scaled excitation signal frame */ + Word16* bwe_exc_fx, + Word16* sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ + Word16* sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ ); void decod_unvoiced_fx( @@ -2524,7 +2446,7 @@ void AVQ_demuxdec_fx( Word16 nq_out[] /* i/o: AVQ nq index */ ); -void re8_decode_base_index_fx(Word16 n, UWord16 I, Word16 *x); +void re8_decode_base_index_fx(const Word16 n, UWord16 I, Word16 *x); void re8_k2y_fx( const Word16 *k, /* i : Voronoi index k[0..7] */ @@ -2560,17 +2482,14 @@ void re8_dec_fx( ); void gain_dec_SQ_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *code, /* i : algebraic code excitation Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ - Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + const Word16 i_subfr, /* i : subframe number */ + const Word16* code, /* i : algebraic code excitation Q9*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ + Word16* gain_pit, /* o : Quantized pitch gain Q14*/ + Word32* gain_code, /* o : Quantized codeebook gain Q16*/ + Word16* gain_inov, /* o : unscaled innovation gain Q12*/ + Word32* norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ ); void gain_dec_amr_wb_fx( @@ -2599,7 +2518,7 @@ void syn_output_fx( const Word16 Q_syn2 /* i : Synthesis scaling factor */ ); -void amr_wb_dec_fx( +ivas_error amr_wb_dec_fx( Word16 output_sp[], /* o : synthesis output */ Decoder_State_fx *st_fx /* o : Decoder static variables structure */ ); @@ -2632,59 +2551,70 @@ void disf_2s_36b_fx( ); void transf_cdbk_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ const Word32 gain_code, /* i : innovative excitation gain (Q16) */ - Word16 *mem_preemp, /* i/o: dequantizer preemhasis memory */ - Word16 *gain_preQ, /* o : prequantizer excitation gain (Q2) */ - Word32 *norm_gain_preQ,/* o : normalized prequantizer excitation gain (Q16) */ + Word16* gain_preQ, /* o : prequantizer excitation gain (Q2) */ + Word32* norm_gain_preQ,/* o : normalized prequantizer excitation gain (Q16) */ Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ - Word16 *unbits /* o : number of AVQ unused bits */ + Word16* unbits /* o : number of AVQ unused bits */ ); void gain_enc_SQ_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *xn, /* i : target vector Q_xn */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ - const Word16 *code, /* i : algebraic excitation Q9 */ + const Word16* xn, /* i : target vector Q_xn */ + const Word16* yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ + const Word16* y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ + const Word16* code, /* i : algebraic excitation Q9 */ const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ - Word16 *gain_pit, /* o : quantized pitch gain Q14 */ - Word32 *gain_code, /* o : quantized codebook gain Q16 */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + Word16* gain_pit, /* o : quantized pitch gain Q14 */ + Word32* gain_code, /* o : quantized codebook gain Q16 */ + Word16* gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ + Word32* norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ + Word16* g_corr, /* i/o: correlations , ,, -2 and 2 */ const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ const Word16 Q_xn /* i : xn and y1 scaling */ ); -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ - const Word16 Q_in /* i: Scaling input */ +void AVQ_cod_fx( /* o: comfort noise gain factor */ + const Word16 xri[], /* i: vector to quantize */ + Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const Word16 NB_BITS, /* i: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ + const Word16 Q_in_ref /* i: Scaling i */ +); +void ordr_esti( + const Word16 svLength, /* i : sub-vector index */ + Word16* Mpos, /* i/o: dominant sub-vector position from ACV */ + Word16 svOrder[], /* i/o: AVQ sub-vecotr order */ + const Word16 Nsv /* i : total sub-vectors in a sub-frames */ ); - void AVQ_encmux_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 extl, /* i : extension layer */ - Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed - by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[] /* o : AVQ nq index */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 extl, /* i : extension layer */ + Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed + by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ + Word16* nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors */ + Word16 nq_out[], /* o : AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ +); +void E_ACELP_4t( + Word16 dn[], Word16 cn[] /* Q_xn */, Word16 H[], + Word16 R[], Word8 acelpautoc, + Word16 code[], + Word16 cdk_index, Word16 _index[] + , const Word16 L_frame, + const Word16 last_L_frame, + const Word32 total_brate, + const Word16 i_subfr, + const Word16 cmpl_flag ); - Word32 Dot_product( /* o : Sum */ const Word16 x[], /* i : 12bits: x vector */ const Word16 y[], /* i : 12bits: y vector */ @@ -2709,24 +2639,24 @@ Word16 gain_quant_fx( /* o: quantization index */ ); void gain_enc_mless_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *xn, /* i : target vector */ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation */ - const Word16 Q_xn, /* i : xn and y1 scaling */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word16 Es_pred, /* i : predicted scaled innovation energy */ - Word16 *gain_pit, /* o : quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 element_mode, /* i : element mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16* xn, /* i : target vector */ + const Word16* y1, /* i : zero-memory filtered adaptive excitation */ + const Word16 Q_xn, /* i : xn and y1 scaling */ + const Word16* y2, /* i : zero-memory filtered algebraic codebook excitation */ + const Word16* code, /* i : algebraic excitation */ + const Word16 Es_pred, /* i : predicted scaled innovation energy */ + Word16* gain_pit, /* o : quantized pitch gain */ + Word32* gain_code, /* o : quantized codebook gain */ + Word16* gain_inov, /* o : gain of the innovation (used for normalization) */ + Word32* norm_gain_code, /* o : norm. gain of the codebook excitation */ + Word16* g_corr, /* i/o: correlations , -2,, -2 and 2 */ + const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ ); Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ @@ -2736,105 +2666,90 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quantization const Word16 stepSize, /* i : Step size choice Q14 */ const Word16 inv_stepSize /* i : Step size choice Q15 */ ); - void gain_enc_tc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 xn_fx[], /* i : target vector */ - const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 code_fx[], /* i : algebraic excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ - Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ - Word32 *gain_code_fx, /* o : quantized codebook gain */ - Word16 *gain_inov_fx, /* o : innovation gain */ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ - const Word16 Q_xn /* i : xn and y1 scaling Q0 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 xn_fx[], /* i : target vector */ + const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 code_fx[], /* i : algebraic excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ + Word16* gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ + Word32* gain_code_fx, /* o : quantized codebook gain */ + Word16* gain_inov_fx, /* o : innovation gain */ + Word32* norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ + const Word16 Q_xn /* i : xn and y1 scaling Q0 */ ); Word16 gaus_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code, /* o : normalized innovative cb. gain Q16 */ - const Word32 core_brate /* i : core bitrate */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + const Word16* h1, /* i : weighted filter i response */ + const Word16* xn, /* i : target vector */ + Word16* exc, /* o : pointer to excitation signal frame */ + Word16* mem_w0, /* o : weighting filter denominator memory */ + Word16* clip_gain, /* o : memory of gain of pitch clipping algorithm */ + Word16* tilt_code, /* o : synthesis excitation spectrum tilt */ + Word16* code, /* o : algebraic excitation Q9 */ + Word32* gain_code, /* o : Code gain. Q16 */ + Word16* y2, /* o : zero-memory filtered adaptive excitation Q9 */ + Word16* gain_inov, /* o : innovation gain Q12 */ + Word16* voice_fac, /* o : voicing factor Q15 */ + Word16* gain_pit, /* o : adaptive excitation gain Q14 */ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32* norm_gain_code /* o : normalized innovative cb. gain Q16 */ ); void encod_unvoiced_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 vad_flag_fx, - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16* speech_fx, /* i : Input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16* Aq_fx, /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ + const Word16* res_fx, /* i : residual signal */ + Word16* syn_fx, /* o : core synthesis */ + Word16* tmp_noise_fx, /* o : long-term noise energy */ + Word16* exc_fx, /* i/o: current non-enhanced excitation */ + Word16* pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16* voice_factors_fx, /* o : voicing factors */ + Word16* bwe_exc_fx, /* i/o: excitation for SWB TBE */ const Word16 Q_new, const Word16 shift ); void transf_cdbk_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *mem_deemp, /* i/o: prequantizer deemhasis memory */ - Word16 *mem_preemp, /* i/o: prequantizer preemhasis memory */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ + const Word16 i_subfr, /* i : subframe index */ + Word16 cn[], /* i/o: target vector in residual domain */ + Word16 exc[], /* i/o: pointer to excitation signal frame */ + const Word16* p_Aq, /* i : 12k8 Lp coefficient */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 h1[], /* i : weighted filter i response */ + Word16 xn[], /* i/o: target vector */ + Word16 xn2[], /* i/o: target vector for innovation search */ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ + const Word16 y2[], /* i : zero-memory filtered innovative excitation */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + Word16* gain_pit, /* i/o: adaptive excitation gain */ + const Word32 gain_code, /* i : innovative excitation gain */ + Word16 g_corr[], /* o : ACELP correlation values */ + const Word16 clip_gain, /* i : adaptive gain clipping flag */ + Word16* gain_preQ, /* o : prequantizer excitation gain */ + Word16 code_preQ[], /* o : prequantizer excitation */ + Word16* unbits, /* o : number of AVQ unused bits */ + const Word16 Q_new, /* i : Current frame scaling */ + const Word16 shift /* i : shifting applied to y1, xn,... */ ); Word16 encod_tran_fx( Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 speech_fx[], /* i : input speech */ + const Word16 speech_fx[], /* i : i speech */ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 coder_type, /* i : coding type */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ const Word16 *res_fx, /* i : residual signal */ Word16 *syn_fx, /* i/o: core synthesis */ Word16 *exc_fx, /* i/o: current non-enhanced excitation */ @@ -2842,9 +2757,9 @@ Word16 encod_tran_fx( Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ Word16 *voice_factors, /* o : voicing factors */ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - const Word16 gsc_attack_flag, /* i : Flag to indicate when an audio attack is deal with TM */ + Word16 tc_subfr, /* i/o: TC subframe classification */ + Word16 position, /* i : maximum of residual signal index */ Word16 *unbits, /* i/o: number of unused bits */ - Word16 sharpFlag, /* o : formant sharpening flag */ const Word16 shift, /* i : Scaling to get 12 bits */ const Word16 Q_new /* i : Input scaling */ ); @@ -2854,8 +2769,12 @@ Word16 est_tilt_fx( /* o : tilt of the code const Word16 gain_pit, /* i : adaptive gain Q14 */ const Word16 *code, /* i : algebraic exctitation vector Q9 */ const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ +#ifdef ADD_LRTD + , const Word16 L_subfr /* i : Sub frame lenght */ +#endif + ); Word16 Est_tilt2( /* o : tilt of the code */ @@ -2869,23 +2788,17 @@ Word16 Est_tilt2( /* o : tilt of the code void transition_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ const Word16 i_subfr, /* i : subframe index */ Word16 *tc_subfr, /* i/o: TC subframe index */ Word16 *Jopt_flag, /* i : joint optimization flag */ Word16 *position, /* i/o: maximum of residual signal index */ - const Word16 voicing_fx[], /* i : normalized correlations (from OL pitch) Q15*/ - const Word16 T_op_fx[], /* i : open loop pitch estimates in current frame Q0*/ Word16 *T0, /* i/o: close loop integer pitch Q0*/ Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *res_fx, /* i : pointer to the LP residual signal frame Q_new*/ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *h1_fx, /* i : weighted filter i response Q(14+shift)*/ const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ @@ -2894,8 +2807,10 @@ void transition_enc_fx( Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ Word16 **pt_pitch_fx, /* o : floating pitch values */ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + Word16* unbits_ACELP, /* i/o: unused bits */ Word16 Q_new, /* i : Current scaling */ Word16 shift /* i : downscaling needs for 12 bits convolutions */ + ); Word16 abs_pit_enc_fx( /* o : pitch index */ @@ -2924,7 +2839,7 @@ void set_impulse_fx( ); void pit16k_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 nBits, /* i : # of Q bits */ const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ const Word16 T0, /* i : integer pitch lag */ @@ -2934,7 +2849,7 @@ void pit16k_Q_enc_fx( ); void gain_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *xn, /* i : target vector */ const Word16 Q_xn, /* i : xn and yy1 format Q0 */ const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ @@ -2951,70 +2866,74 @@ void gain_enc_amr_wb_fx( ); void gain_enc_lbr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *xn, /* i : target vector Q_xn*/ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 Q_xn, /* i : xn and y1 format */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - Word16 *gain_pit, /* o : quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16* xn, /* i : target vector Q_xn*/ + const Word16* y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ + const Word16 Q_xn, /* i : xn and y1 format */ + const Word16* y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ + const Word16* code, /* i : algebraic excitation Q9*/ + Word16* gain_pit, /* o : quantized pitch gain Q14*/ + Word32* gain_code, /* o : quantized codebook gain Q16*/ + Word16* gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ + Word32* norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ + Word16* g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + const Word16 L_subfr /* i : subframe length */ ); void gp_clip_test_gain_pit_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ ); void gp_clip_test_lsf_fx( - const Word16 lsf[], /* i : lsf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode */ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 m /* i : dimension of lsf */ ); Word16 inov_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16 *cn, /* i/o: target vector in residual domain Q_new*/ - const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ - Word16 *h2, /* i/o: weighted filter input response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16 *unbits, /* o : number of unused bits for PI */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 last_L_frame, /* i : length of the last frame */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16* p_Aq, /* i : LP filter coefficients Q12*/ + const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ + Word16* cn, /* i/o: target vector in residual domain Q_new*/ + const Word16* exc, /* i : pointer to excitation signal frame Q_new*/ + Word16* h2, /* i/o: weighted filter i response Q12*/ + const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ + const Word16* xn2, /* i : target vector for innovation search Q_new-1+shift*/ + Word16* code, /* o : algebraic excitation Q9*/ + Word16* y2, /* o : zero-memory filtered algebraic excitation Q9*/ + Word16* unbits, /* o : number of unused bits for PI */ + const Word16 L_subfr, /* i : subframe length */ Word16 shift ); Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ + const Word16 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ ); Word32 sum2_fx_mod( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ + const Word16 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ ); Word16 usdequant_fx( /* Qx*/ @@ -3032,29 +2951,25 @@ Word16 gain_dequant_fx( /* o: decoded gain */ ); void Es_pred_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate /* i : core bitrate */ + Word16* Es_pred, /* o : predicited scaled innovation energy Q8*/ + const Word16 enr_idx, /* i : indice */ + const Word16 nb_bits, /* i : number of bits */ + const Word16 no_ltp /* i : no LTP flag */ ); void gain_dec_tc_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 L_frame_fx, /* i : length of the frame */ + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + const Word16* code_fx, /* i : algebraic code excitation */ const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : pitch gain */ - Word32 *gain_code_fx, /* o : Quantized codeebook gain */ - Word16 *gain_inov_fx, /* o : unscaled innovation gain */ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ + Word16* gain_pit_fx, /* o : pitch gain */ + Word32* gain_code_fx, /* o : Quantized codeebook gain */ + Word16* gain_inov_fx, /* o : unscaled innovation gain */ + Word32* norm_gain_code_fx /* o : norm. gain of the codebook excit. */ ); void gain_dec_mless_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate_fx, /* i : core bitrate */ const Word16 L_frame_fx, /* i : length of the frame */ const Word16 coder_type_fx, /* i : coding type */ const Word16 i_subfr_fx, /* i : subframe number */ @@ -3068,25 +2983,26 @@ void gain_dec_mless_fx( ); void pre_echo_att_fx( - Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ - const Word16 Q_new - ,const Word16 last_coder_type_fx /* i : Last coding mode */ + Word32* Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ + Word16* exc_fx, /* i/o: Excitation of the current frame Q_new*/ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 Q_new, + const Word16 last_coder_type_fx, /* i : Last coding mode */ + const Word16 L_frame /* i : Frame length*/ ); void gain_dec_lbr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q12*/ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16* code_fx, /* i : algebraic excitation Q9 */ + Word16* gain_pit_fx, /* o : quantized pitch gain Q14*/ + Word32* gain_code_fx, /* o : quantized codebook gain Q16*/ + Word16* gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ + Word32* norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ + , const Word16 L_subfr /* i : subfr lenght */ ); void lp_gain_updt_fx( @@ -3139,38 +3055,39 @@ void delta_pit_dec_fx( const Word16 T0_min /* i : delta search min */ ); -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ +Word16 pit_decode_fx( /* o : floating pitch value */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const Word16 L_subfr /* i : subframe length */ +#ifdef ADD_LRTD + , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +#endif ); void pred_lt4( - const Word16 excI[], /* in: excitation buffer */ - Word16 excO[], /* out: excitation buffer */ - Word16 T0, /* input : integer pitch lag */ - Word16 frac, /* input : fraction of lag */ - Word16 L_subfr, /* input : subframe size */ - const Word16 *win, /* i : interpolation window */ - const Word16 nb_coef, /* i : nb of filter coef */ - const Word16 up_sample /* i : up_sample */ + const Word16 excI[], /* in : excitation buffer */ + Word16 excO[], /* out: excitation buffer */ + const Word16 T0, /* i : integer pitch lag */ + Word16 frac, /* i : fraction of lag */ + const Word16 L_subfr, /* i : subframe size */ + const Word16* win, /* i : interpolation window */ + const Word16 nb_coef, /* i : nb of filter coef */ + const Word16 up_sample /* i : up_sample */ ); void lp_filt_exc_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 codec_type, /* i : coder type */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coding type */ + const Word16 codec_mode, /* i : coder mode */ const Word16 i_subfr, /* i : subframe index */ const Word16 L_subfr, /* i : subframe size */ const Word16 L_frame, /* i : frame size */ @@ -3183,19 +3100,19 @@ void inov_decode_fx( const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ const Word16 sharpFlag, /* i : formant sharpening flag */ const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ Word16 *code /* o : algebraic excitation */ + , const Word16 L_subfr /* i : subframe length */ ); void dec_acelp_1t64_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 code[] /* o: algebraic (fixed) codebook excitation Q12*/ + ,const Word16 L_subfr /* i : sub frame lenght*/ ); void dec_acelp_2t32_fx( @@ -3227,7 +3144,7 @@ void weight_a_fx( void Residu3_lc_fx( const Word16 a[], /* i : prediction coefficients Q12 */ const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ + const Word16 x[], /* i : i signal (usually speech) Qx */ Word16 y[], /* o : output signal (usually residual) Qx */ const Word16 lg, /* i : vector size Q0 */ const Word16 shift /* i : 0=residu2, 1=residu */ @@ -3235,7 +3152,7 @@ void Residu3_lc_fx( void Residu3_10_fx( const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ + const Word16 x[], /* i : i signal (usually speech) Qx */ /* (note that values x[-10..-1] are needed) */ Word16 y[], /* o : output signal (usually residual) Qx */ const Word16 lg, /* i : vector size Q0 */ @@ -3244,7 +3161,7 @@ void Residu3_10_fx( void Residu3_fx( const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ + const Word16 x[], /* i : i signal (usually speech) Qx */ /* (note that values x[-M..-1] are needed) */ Word16 y[], /* o : output signal (usually residual) Qx */ const Word16 lg, /* i : vector size Q0 */ @@ -3253,7 +3170,7 @@ void Residu3_fx( void pre_exc_fx( const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 *speech, /* i : input speech Q_new-1*/ + const Word16 *speech, /* i : i speech Q_new-1*/ const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ const Word16 *p_A, /* i : unquantized A(q) filter with bandwidth expansion Q12*/ const Word16 coder_type, /* i : coding type */ @@ -3272,29 +3189,39 @@ void pre_exc_fx( ); void encod_audio_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 T_op[], /* i : open loop pitch */ - const Word16 voicing[], /* i : voicing Q15 */ - const Word16 *res, /* i : residual signal Q_new */ - Word16 *synth, /* i/o: core synthesis Q-1 */ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ - const Word16 gsc_attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : noise energy */ + Encoder_State_fx* st_fx, /* i/o: State structure */ + const Word16 speech[], /* i : i speech Q_new */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16* res, /* i : residual signal Q_new */ + Word16* synth, /* i/o: core synthesis Q-1 */ + Word16* exc, /* i/o: current non-enhanced excitation Q_new */ + Word16* pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ + Word16* voice_factors, /* o : voicing factors Q15 */ + Word16* bwe_exc, /* o : excitation for SWB TBE Q0 */ + const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ + Word16* lsf_new, /* i : current frame ISF vector */ + Word16* tmp_noise, /* o : noise energy */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, Word16 shift ); - +void gsc_enc_fx( + Encoder_State_fx* st_fx, /* i/o: State structure */ + Word16 res_dct_in[], /* i : dct of residual signal */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const Word16 Diff_len, + const Word16 bits_used, + const Word16 nb_subfr, + Word16* lsf_new, /* i : ISFs at the end of the frame */ + Word16* exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16* tmp_noise, /* o : noise energy */ + Word16 Q_exc +); Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 pitch_bits[], /* i : pitch bits */ const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 L_frame, /* i : length of the frame */ @@ -3308,8 +3235,10 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe Word16 *T0_max, /* i/o: higher limit for close-loop search */ Word16 *T0, /* i/o: close loop integer pitch */ Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn /* i : target vector */ + const Word16 *h1, /* i : weighted filter i response */ + const Word16 *xn, /* i : target vector */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); Word32 dotp_fx( /* o : dot product of x[] and y[] */ @@ -3328,21 +3257,21 @@ Word32 syn_kern_16( void syn_filt_s_lc_fx( const Word16 shift, /* i : scaling to apply Q0 */ const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 x[], /* i : input signal Qx */ + const Word16 x[], /* i : i signal Qx */ Word16 y[], /* o : output signal Qx-s */ const Word16 lg /* i : size of filtering Q0 */ ); void acelp_2t32_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[] /* o : filtered fixed codebook excitation */ ); Word16 acelp_4t64_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 dn[], /* i : corr. between target and h[]. */ const Word16 cn[], /* i : residual after long term prediction Q_new*/ const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ @@ -3356,11 +3285,12 @@ Word16 acelp_4t64_fx( ); void acelp_1t64_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[], /* o : filtered fixed codebook excitation */ + const Word16 L_subfr /* i : subframe length */ ); void cb_shape_fx( @@ -3376,6 +3306,7 @@ void cb_shape_fx( const Word16 tilt_code, /* i : tilt of code */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ const Word16 shift + , const Word16 L_subfr /* i : subframe lenght */ ); void corr_xh_fx( @@ -3466,28 +3397,20 @@ void unscale_AGC( const Word16 n ); -void LD_music_post_filter_fx( - const Word16 dtc_in[], /* i : input synthesis Qdct */ +void LD_music_post_filter_fx +( + MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ + const Word16 dtc_in[], /* i : i synthesis Qdct */ Word16 dtc_out[], /* o : output synthesis Qdct */ const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *last_music_flag, /* i/o : Previous music detection ouptut Q0 */ - Word16 *thresh, /* i/o : Detection thresold Q0 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 Q0 */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 Q0 */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation Q8 */ - Word16 *mem_etot, /* i/o : Total energy memory Q8 */ - const Word16 min_ns_gain, /* i : minimum gain for inter-harm noise red. Q15 */ - Word32 bckr[], /* i/o : per band bckgnd. noise energy estimate */ - Word32 lf_EO[], /* i/o : old per bin E for previous half frame 2*Qdct+10 */ - Word16 lp_gbin[], /* i/o : smoothed suppression gain, per FFT bin Q15 */ - Word16 *filt_lfE, /* i : post filter weighting coefficient Q15 */ - Word16 *last_nonfull_music, /* i : Number of frames sinces la "speech like" frame Q0*/ - Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ + Word16* Old_ener_Q, /* i/o : Old energy scaling factor */ const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ - const Word16 Last_coder_type, /* i : input scaling Q0 */ - const Word16 Qdct /* i : input scaling Q0 */ + const Word16 Last_coder_type, /* i : i scaling Q0 */ + const Word16 Qdct /* i : i scaling Q0 */ +); +void music_postfilt_init( + MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ ); - void Rescale_mem( const Word16 Q_exc, /* i : current excitation scaling (>=0) */ Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ @@ -3499,7 +3422,7 @@ void Rescale_mem( Word16 *pst_old_syn, /* i/o: psfiler */ Word16 *pst_mem_deemp_err, /* i/o: psfiler */ Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ + PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ const Word16 Vad_flag, const Word16 Cna_flag, const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ @@ -3544,62 +3467,65 @@ void updt_IO_switch_dec_fx( ); void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate /* i :core bitrate */ + const Word16 L_frame_fx, /* i : length of the frame */ +#ifdef ADD_IVAS_TBE_CODE + const Word16 L_subfr, +#endif + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[],/* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + Word32 core_brate /* i :core bitrate */ +#ifdef ADD_IVAS_TBE_CODE + ,const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ +#endif ); void interp_code_5over2_fx( - const Word16 inp_code[], /* i : input vector */ + const Word16 inp_code[], /* i : i vector */ Word16 interp_code[], /* o : output vector */ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_length /* i : length of i vector */ ); void lsp2lsf_fx( - const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ - Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ - const Word16 m, /* i : LPC order Q0*/ - Word32 int_fs + const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ + Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ + const Word16 m, /* i : LPC order Q0*/ + const Word32 int_fs /* i : internal sampling frequency */ ); void lsf_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* o : quantized LSF vector */ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac, /* o : LSF stability factor */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + Word16* lsf_new, /* o : quantized LSF vector */ + Word16* lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16* lsp_mid, /* i/o : mid-frame LSP vector */ + Word16* Aq, /* o : quantized A(z) for 4 subframes */ const Word16 Nb_ACELP_frames, - const Word16 Q_new + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ +#endif + const Word16 Q_new ); void lsf_mid_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 int_fs, /* i : internal (ACELP) sampling frequency */ - Word16 qlsp0[], /* i : quantized LSPs from frame beginning Q15*/ - Word16 qlsp1[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 qlsp[], /* o : quantized LSPs Q15*/ - const Word32 core_brate, /* i : core bitrate */ - Word16 ppp_mode, - Word16 nelp_mode, - Word16 prev_bfi, - Word16 *mid_lsf_int, - Word16 safety_net + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ + Word16 coder_type, /* i : Coder type */ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ @@ -3609,16 +3535,16 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ const Word16 L_frame /* i : frame length */ ); -void lsf_allocate_fx( - const Word16 nBits, /* i : Number of bits to use for quantization */ - const Word16 framemode, /* i : ISF quantizer mode */ - const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ - Word16 *stages0, /* o : Number of stages for safety-net quantizer */ - Word16 *stages1, /* o : Number of stages for predictive quantizer */ - Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ - Word16 levels1[], /* o : Number of vectors for each stage for pred */ - Word16 bits0[], /* o : Number of bits for each stage safety net */ - Word16 bits1[] /* o : Number of bits for each stage pred */ +ivas_error lsf_allocate_fx( + const Word16 nBits, /* i : Number of bits to use for quantization */ + const Word16 framemode, /* i : ISF quantizer mode */ + const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ + Word16* stages0, /* o : Number of stages for safety-net quantizer */ + Word16* stages1, /* o : Number of stages for predictive quantizer */ + Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ + Word16 levels1[], /* o : Number of vectors for each stage for pred */ + Word16 bits0[], /* o : Number of bits for each stage safety net */ + Word16 bits1[] /* o : Number of bits for each stage pred */ ); Word16 vq_dec_lvq_fx ( Word16 sf_flag, /* i : safety net flag */ @@ -3642,11 +3568,11 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx ( const Word16 nBits /* i : number of bits */ ); -void tcvq_Dec_fx(Word16 *ind, - /*float *d_out, */ - Word16 *d_out_fx, - Word16 safety_net - ); +void tcvq_Dec_fx( + Word16* ind, + Word16* d_out_fx, + const Word16 safety_net +); Word32 qlsf_ARSN_tcvq_Enc_16k_fx( const Word16 *x_fx, /* i : Vector to be encoded x2.65 */ @@ -3681,7 +3607,12 @@ void index_lvq_fx ( Word32 * p_offset_scale2, Word16 * p_no_scales ); - +void create_offset( + Word32* offset_scale1, + Word32* offset_scale2, + const Word16 mode, + const Word16 prediction_flag +); void multiply32_32_64_fx( Word32 x, Word32 y, @@ -3694,7 +3625,7 @@ void permute_fx( ); Word32 mslvq_fx ( - Word16 *pTmp, /* i : M-dimensional input vector */ + Word16 *pTmp, /* i : M-dimensional i vector */ Word16 *quant, /* o : quantized vector */ Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ @@ -3708,7 +3639,7 @@ Word32 mslvq_fx ( Word32 mslvq_cng_fx ( Word16 idx_cv, /* i : index of cv from previous stage */ - Word16 *pTmp, /* i : 16 dimensional input vector x2.56*/ + Word16 *pTmp, /* i : 16 dimensional i vector x2.56*/ Word16 *quant, /* o : quantized vector x2.56*/ Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ @@ -3724,74 +3655,60 @@ void sort_fx( ); void lsf_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ + Decoder_State_fx* st_fx, /* i/o: State structure */ const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid /* o : de-quantized mid-frame LSP vector */ + Word16* Aq, /* o : quantized A(z) for 4 subframes */ + Word16* LSF_Q_prediction, /* o : LSF prediction mode */ + Word16* lsf_new, /* o : de-quantized LSF vector */ + Word16* lsp_new, /* o : de-quantized LSP vector */ + Word16* lsp_mid, /* o : de-quantized mid-frame LSP vector */ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif ); void lsf_end_enc_fx( - Encoder_State_fx *st, - const Word16 *lsf, - Word16 *qlsf, - Word16 *mem_AR, - Word16 * mem_MA, - const Word16 nBits, - const Word16 coder_type_org, - const Word16 bwidth, - Word32 *Bin_Ener, - Word16 Q_ener, - const Word32 int_fs, - Word32 core_brate, - Word16 *streaklimit, - Word16 *pstreaklen, - Word16 force_sf, - Word16 RF_flag, - Word16 mode2_flag, - Word16 * lpc_param, - Word16 * no_stages, - Word16 * bits_param_lpc, - Word16 coder_type_raw + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16* lsf, /* i : LSF in the frequency domain (0..6400) */ + Word16* qlsf, /* o : quantized LSF */ + const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ + const Word16 coder_type_org, /* i : coding type */ + Word16 Q_ener, /* i : Q valuen for Bin_Ener */ + Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + Word16* lpc_param, + Word16* no_indices, + Word16* bits_param_lpc, + Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif ); void lsf_end_dec_fx( - Decoder_State_fx *st, + Decoder_State_fx* st, /* i/o: decoder state structure */ Word16 mode2_flag, - const Word16 coder_type_org, - const Word16 bwidth, - const Word16 nBits, - Word16 *qlsf, - Word16 *mem_AR, - Word16 *mem_MA, - const Word32 int_fs, - Word32 core_brate, - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p, - Word16 *safety_net, - Word16 *lpc_param, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 * nb_indices + const Word16 coder_type_org, /* i : coding type */ + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ + Word16* qlsf, /* o : quantized LSFs in the cosine domain */ + Word16* lpc_param, + Word16* LSF_Q_prediction, /* o : LSF prediction mode */ + Word16* nb_indices +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + , const float tdm_lsfQ_PCh[M] +#endif ); -Word16 find_pred_mode( - const Word16 coder_type, - const Word16 bwidth, - const Word32 int_fs, - Word16 * p_mode_lvq, - Word16 * p_mode_lvq_p, - Word32 core_brate +ivas_error find_pred_mode( + Word16* predmode, /* o: prediction mode */ + const Word16 coder_type, /* i: coding type */ + const Word16 bwidth, /* i: bandwidth index */ + const Word32 int_fs, /* i: sampling frequency */ + Word16* p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ + Word16* p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ + Word32 core_brate /* i: core bit rate */ ); - Word16 xsf_to_xsp( Word16 lsf ); @@ -3812,8 +3729,8 @@ void int_lsp4_fx( Word16 modify_Fs_fx( /* o : length of output Q0 */ const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ + Word16 lg, /* i : length of i Q0 */ + const Word32 fin, /* i : frequency of i Q0 */ Word16 sigOut_fx[], /* o : decimated signal Q0 */ const Word32 fout, /* i : frequency of output Q0 */ Word16 mem_fx[], /* i/o: filter memory Q0 */ @@ -3834,52 +3751,38 @@ void addBassPostFilterFx( ); void bass_psfilter_fx( - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ - Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) */ - const Word16 L_frame, /* i : length of the last frame */ + BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ + const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ + Word16 synth_in_fx[], /* i : i synthesis (at 16kHz) */ + const Word16 L_frame, /* i : length of the last frame */ Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ - Word16 old_syn_fx[], /* i/o: NBPSF_PIT_MAX */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener, /* o : long_term error signal energy */ - const Word16 bpf_off, /* i : do not use BPF when set to 1 */ - Word16 v_stab_fx, /* i : stability factor */ - Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ - Word16 *mem_mean_pit, /* i/o: average pitch memory */ - Word16 *Track_on_hist, /* i/o: History of half frame usage */ - Word16 *vibrato_hist, /* i/o: History of frames declared as vibrato*/ - Word16 *psf_att, /* i/o: Post filter attenuation factor */ - const Word16 coder_type, /* i : coder_type */ + const Word16 bpf_off, /* i : do not use BPF when set to 1 */ + Word16 v_stab_fx, /* i : stability factor */ + Word16* v_stab_smooth_fx, /* i/o: smoothed stability factor */ + const Word16 coder_type, /* i : coder_type */ Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ + Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ ); void speech_music_classif_fx( - Encoder_State_fx *st, /* i/o: state structure */ - Word16 *sp_aud_decision0, - Word16 *sp_aud_decision1, /* o : 1st stage speech/music */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music */ - const Word16 *new_inp, /* i : new input signal */ - const Word16 *inp, /* i : input signal to locate attach position */ - const Word16 vad_flag, - const Word16 localVAD, + Encoder_State_fx* st, /* i/o: state structure */ + const Word16* new_inp, /* i : new input signal */ + const Word16* inp, /* i : input signal to locate attach position */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ - const Word16 voicing[3], /* i : voicing estimate in three subframes Q15 */ const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ - const Word32 epsP[M+1], /* i : LP prediciton error Q_esp*/ + const Word32 epsP[M + 1], /* i : LP prediciton error Q_esp*/ const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ const Word16 Etot, /* i : total frame energy Q8 */ const Word16 old_cor, /* i : max correlation from previous frame Q15 */ - Word16 *coder_type, /* i/o: coding type */ - Word16 *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ + Word16* attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ Word16 relE, /* i : relative frame energy */ Word16 Q_esp, /* i : scaling of esP */ - Word16 Q_inp /* i : scaling of input */ - ,Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ - ,Word16 flag_spitch /* i: flag to indicate very short stable pitch */ -); + Word16 Q_inp, /* i : scaling of input */ + Word16* high_lpn_flag_ptr, /* o : noise log prob flag for NOISE_EST */ + Word16 flag_spitch /* i : flag to indicate very short stable pitch */ + ); Word32 sub_lsp2lsf_fx( const Word16 lsp_i /* i : lsp[m] (range: -1<=val<1) Q15*/ @@ -3916,18 +3819,32 @@ void Es_pred_enc_fx( const Word16 no_ltp, /* i : no_ltp flag */ Word16 Q_new /* i : Scaling in speech Q0 */ ); - +void calculate_hangover_attenuation_gain( + Encoder_State_fx* st, /* i : encoder state structure */ + Word16* att, /* o : attenuation factor */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ +); +void v_multc_att( + const Word16 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word16 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ +); +void v_multc_att32( + const Word32 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word32 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ +); void calc_residu_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq, /* i : quantized LP filter coefficients */ - const Word16 vad_hover_flag, - const Word16 vad_flag_dtx + Encoder_State_fx* st, /* i/o: state structure */ + const Word16* speech, /* i : weighted speech signal */ + Word16* res, /* o : residual signal */ + const Word16* p_Aq /* i : quantized LP filter coefficients */ ); void updt_IO_switch_enc_fx( Encoder_State_fx *st, /* i/o: state structure */ - const Word16 input_frame /* i : input frame length */ + const Word16 input_frame /* i : i frame length */ ); /*-------------------------------------------------------------------* * pre_proc() @@ -3938,19 +3855,15 @@ void updt_IO_switch_enc_fx( void pre_proc_fx( Encoder_State_fx *st, /* i/o: encoder state structure */ const Word16 input_frame, /* i : frame length */ - const Word16 signal_in[], /* i : new samples */ - Word16 old_inp_12k8[], /* i/o: buffer of old input signal */ - Word16 old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + Word16 old_inp_12k8[], /* i/o: buffer of old i signal */ + Word16 old_inp_16k[], /* i/o: buffer of old i signal @ 16kHz */ Word16 **inp, /* o : ptr. to inp. signal in the current frame */ - Word16 *sp_aud_decision1, /* o : 1st stage speech/music classification */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music classification */ Word32 fr_bands[2*NB_BANDS], /* o : energy in frequency bands */ - Word16 *vad_flag, - Word16 *localVAD, Word16 *Etot, /* o : total energy */ Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 pitch[3], /* o : open-loop pitch values for quantiz. */ - Word16 voicing[3], /* o : OL maximum normalized correlation */ +#ifndef FIX_I4_OL_PITCH + Word16 pitch_orig[3], /* o : open-loop pitch values for quantization */ +#endif Word16 A[NB_SUBFR16k*(M+1)], /* o : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k*(M+1)], /* o : weighted A(z) unquantized for subframes */ Word16 epsP_h[M+1], /* o : LP prediction errors */ @@ -3958,11 +3871,9 @@ void pre_proc_fx( Word32 epsP[M+1], /* o : LP prediction errors */ Word16 lsp_new[M], /* o : LSPs at the end of the frame */ Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ - Word16 *coder_type, /* o : coder type */ - Word16 *sharpFlag, /* o : formant sharpening flag */ Word16 *vad_hover_flag, Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *new_inp_resamp16k, /* o : new i signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb real buffer */ @@ -3978,9 +3889,9 @@ void pre_proc_fx( Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ const Word16 *Y, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ Encoder_State_fx *st_fx, /* i/o: Encoder state variable */ - Word16 vadflag - ,Word32 *cldfbBuf_Ener - ,Word16 enerBuffer_exp + Word32 *cldfbBuf_Ener, + Word16 enerBuffer_exp, + const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ); void floating_point_add( @@ -3989,40 +3900,51 @@ void floating_point_add( const Word32 my, /* i: mantissa of the adder Q31 */ const Word16 ey /* i: exponent of the adder Q0 */ ); +void delay_signal( + Word16 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the i signal */ + Word16 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ +); void MDCT_selector( - Encoder_State_fx *st /* i/o: Encoder State */ - , Word16 sp_floor /* i : Noise floor estimate Q7 */ - , Word16 Etot /* i : Total energy Q8 */ - , Word16 cor_map_sum /* i : harmonicity factor Q8 */ - , const Word16 voicing[] /* i : voicing factors Q15*/ - , const Word32 enerBuffer[] /* i : CLDFB buffers */ - , Word16 enerBuffer_exp /* i : exponent of enerBuffer */ - , Word16 vadflag + Encoder_State_fx* st, /* i/o: Encoder State */ + Word16 sp_floor, /* i : Noise floor estimate Q7 */ + const Word16 Etot, /* i : Total energy Q8 */ + const Word16 cor_map_sum, /* i : harmonicity factor Q8 */ + const Word32 enerBuffer[], /* i : CLDFB buffers */ + const Word16 enerBuffer_exp /* i : exponent of enerBuffer */ ); void MDCT_selector_reset( - Encoder_State_fx *st); /* i/o: Encoder State */ + TCX_ENC_HANDLE hTcxEnc +); +void MDCT_classifier_reset( + TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ +); +void fd_bwe_enc_init( + FD_BWE_ENC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ +); -Word16 minimum_fx( /* o : index of the minimum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *min_fx /* o : minimum value in the input vector */ +Word16 minimum_fx( /* o : index of the minimum value in the i vector */ + const Word16 *vec_fx, /* i : i vector */ + const Word16 lvec_fx, /* i : length of i vector */ + Word16 *min_fx /* o : minimum value in the i vector */ ); -Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ - const Word32 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word32 *min_fx /* o : minimum value in the input vector */ +Word16 minimum_32_fx( /* o : index of the minimum value in the i vector */ + const Word32 *vec_fx, /* i : i vector */ + const Word16 lvec_fx, /* i : length of i vector */ + Word32 *min_fx /* o : minimum value in the i vector */ ); -Word16 maximum_32_fx( /* o : index of the maximum value in the input vector */ - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word32 *max /* o : maximum value in the input vector */ +Word16 maximum_32_fx( /* o : index of the maximum value in the i vector */ + const Word32 *vec, /* i : i vector */ + const Word16 lvec, /* i : length of i vector */ + Word32 *max /* o : maximum value in the i vector */ ); -Word16 maximum_fx( /* o : index of the maximum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *max_fx /* o : maximum value in the input vector */ +Word16 maximum_fx( /* o : index of the maximum value in the i vector */ + const Word16 *vec_fx, /* i : i vector */ + const Word16 lvec_fx, /* i : length of i vector */ + Word16 *max_fx /* o : maximum value in the i vector */ ); Word16 Exp32Array( const Word16 n, /* (i): Array size */ @@ -4034,8 +3956,8 @@ Word16 Exp16Array( ); Word32 sum16_32_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ + const Word16 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ ); Word32 dot_product_mat_fx( /* o : the dot product x'*A*x */ const Word16 *x, /* i : vector x Q15 */ @@ -4045,28 +3967,28 @@ Word32 dot_product_mat_fx( /* o : the dot product x'*A*x */ ); Word16 std_fx( /* o: standard deviation */ - const Word16 *x, /* i: input vector */ - const Word16 len /* i: length of the input vector */ + const Word16 *x, /* i: i vector */ + const Word16 len /* i: length of the i vector */ ); Word16 stab_est_fx( Word16 etot, /* i : Total energy of the current frame */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ - Word16 *mem_etot, /* i/o : Total energy memory */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ - Word16 *thresh, /* i/o : Detection thresold */ - Word16 *last_music_flag,/* i/o : Previous music detection ouptut */ - Word16 vad_flag + Word16* lt_diff_etot, /* i/o : Long term total energy variation */ + Word16* mem_etot, /* i/o : Total energy memory */ + Word16* nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ + Word16* nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ + Word16* thresh, /* i/o : Detection thresold */ + Word16* last_music_flag,/* i/o : Previous music detection ouptut */ + const Word16 vad_flag /* i : VAD flag */ ); Word16 var_fx( /* o: variance of vector Qx*/ - const Word16 *x, /* i: input vector Qx*/ + const Word16 *x, /* i: i vector Qx*/ const Word16 Qx, const Word16 len /* i: length of inputvector */ ); void conv_fx( - const Word16 x[], /* i : input vector Q_new*/ - const Word16 h[], /* i : impulse response (or second input vector) Q(15)*/ + const Word16 x[], /* i : i vector Q_new*/ + const Word16 h[], /* i : impulse response (or second i vector) Q(15)*/ Word16 y[], /* o : output vetor (result of convolution) 12 bits*/ const Word16 L /* i : vector size */ ); @@ -4080,7 +4002,7 @@ void norm_corr_fx( const Word16 L_subfr /* i : subframe size */ ); void pit_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 nBits, /* i : # of Q bits */ const Word16 delta, /* i : Half the CL searched interval */ @@ -4118,28 +4040,28 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag ); Word32 var_fx_32( /* o: variance of vector Qx+16*/ - const Word16 *x, /* i: input vector Qx*/ + const Word16 *x, /* i: i vector Qx*/ const Word16 Qx, const Word16 len /* i: length of inputvector */ ); Word16 sum16_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ + const Word16 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ ); Word32 sum32_fx( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ + const Word32 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ ); Word32 Mean32( /* o : mean of the elements of the vector */ - const Word32 in[], /* i : input vector */ - const Word16 L /* i : length of input vector */ + const Word32 in[], /* i : i vector */ + const Word16 L /* i : length of i vector */ ); void Deemph2( - Word16 x[], /* i/o: input signal overwritten by the output Qx/Qx-1 */ + Word16 x[], /* i/o: i signal overwritten by the output Qx/Qx-1 */ const Word16 mu, /* i : deemphasis factor Q15 */ const Word16 L, /* i : vector size Q0 */ Word16 *mem /* i/o: memory (y[-1]) Qx-1 */ @@ -4165,14 +4087,14 @@ void Syn_filt_s( const Word16 shift, /* i : scaling to apply Q0 */ const Word16 a[], /* i : LP filter coefficients Q12 */ const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal Qx */ + const Word16 x[], /* i : i signal Qx */ Word16 y[], /* o : output signal Qx-s */ const Word16 lg, /* i : size of filtering Q0 */ Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ ); void hp400_12k8_fx( - Word16 signal[], /* i/o: input signal / output is divided by 16 */ + Word16 signal[], /* i/o: i signal / output is divided by 16 */ const Word16 lg, /* i : lenght of signal */ Word16 mem[] /* i/o: filter memory [6] */ ); @@ -4180,7 +4102,7 @@ Word16 dot_prod_satcontr(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, void syn_12k8_fx( Word16 L_frame, const Word16 *Aq, /* i : LP filter coefficients Q12 */ - const Word16 *exc, /* i : input signal Q_exc */ + const Word16 *exc, /* i : i signal Q_exc */ Word16 *synth, /* o : output signal Q_syn */ Word16 *mem, /* i/o: initial filter states Q_syn */ const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ @@ -4190,8 +4112,6 @@ void syn_12k8_fx( ); void updt_dec_fx( Decoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ const Word16 *old_exc_fx, /* i : buffer of excitation */ const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ const Word16 Es_pred, /* i : predicited scaled innovation energy */ @@ -4203,7 +4123,7 @@ void updt_dec_fx( , const Word16 *gain_buf /*Q14*/ ); Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ - const Word16 *x, /* i : input vector Q0 */ + const Word16 *x, /* i : i vector Q0 */ const Word16 *win, /* i : interpolation window Q14 */ const Word16 frac, /* i : fraction (0..up_samp) Q0 */ const Word16 up_samp, /* i : upsampling factor Q0 */ @@ -4230,18 +4150,16 @@ void updt_tar_HR_fx( Word16 *x2, /* o : new target (for codebook search) */ const Word16 *y, /* i : filtered adaptive codebook vector */ const Word16 gain, /* i : adaptive codebook gain */ - const Word16 Qx, /* i : Scaling factor to adapt output to input */ + const Word16 Qx, /* i : Scaling factor to adapt output to i */ const Word16 L /* i : subframe size */ ); Word16 lp_filt_exc_enc_fx( const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ const Word16 coder_type, /* i : coding type Q0 */ const Word16 i_subfr, /* i : subframe index Q0 */ Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ - const Word16 *h1, /* i : weighted filter input response Q(14+shift) */ + const Word16 *h1, /* i : weighted filter i response Q(14+shift) */ const Word16 *xn, /* i : target vector Q_new-1+shift */ Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ @@ -4254,7 +4172,7 @@ Word16 lp_filt_exc_enc_fx( ); Word16 Interpol_4( /* o : interpolated value */ - Word16 * x, /* i : input vector */ + Word16 * x, /* i : i vector */ Word16 frac /* i : fraction (-4..+3) */ ); @@ -4269,35 +4187,43 @@ void r_fft_fx_lc( ); void hf_synth_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory */ - Word16 *mem_hf, /* i/o: HF band-pass filter memory */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ - Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ -); -void acelp_core_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - Word16 coder_type_fx, /* i : coder type */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 output_frame, /* i : output frame length */ + const Word16* Aq, /* i : quantized Az */ + const Word16* exc, /* i : excitation at 12.8 kHz */ + Word16* synth, /* i : 12.8kHz synthesis signal */ + Word16* synth16k, /* o : 16kHz synthesis signal */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2, /* i : synthesis scaling */ + Word16* delay_syn_hf, /*i/o: HF synthesis memory */ + Word16* memExp1, /* o : HF excitation exponent */ + Word16* mem_hp_interp, /* i/o: interpol. memory */ + const Word16 extl, /* i : flag indicating BWE */ + const Word16 CNG_mode /* i : CNG_mode */ +); +ivas_error acelp_core_dec_fx( + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + Word16 output[], /* o : synthesis @internal Fs */ + Word16 synth_out[], /* o : synthesis */ + Word16 save_hb_synth[], /* o : HB synthesis */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16* voice_factors, /* o : voicing factors */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits /* o : number of unused bits */ - ,Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16* unbits, /* o : number of unused bits */ + Word16* sid_bw /* o : 0-NB/WB, 1-SWB SID */ + ,STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ + const Word16 nchan_out, /* i : number of output channels */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ + const Word16 read_sid_info /* i : read SID info flag */ ); void Inac_swtch_ematch_fx( Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ @@ -4306,46 +4232,44 @@ void Inac_swtch_ematch_fx( const Word16 coder_type, /* i : Coding mode */ const Word16 L_frame, /* i : Frame lenght */ const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ + const Word16 Q_exc /* i : i and output format of exc2 */ ,const Word16 bfi /* i : frame lost indicator */ ,const short last_core, /* i : Last core used */ const short last_codec_mode /* i : Last codec mode */ ); void stat_noise_uv_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 coder_type, /* i : coding type */ - const Word32 *LepsP, /* i : LP prediction errors */ - Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ - Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word32* LepsP, /* i : LP prediction errors */ + const Word16* isp_new, /* i : immittance spectral pairs at 4th sfr */ + const Word16* isp_mid, /* i : immittance spectral pairs at 2nd sfr */ + Word16* Aq, /* i : A(z) quantized for the 4 subframes */ + Word16* exc2, /* i/o: excitation buffer */ + const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ Word16 Q_new ); void updt_enc_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : speech coder type */ - const Word16 *old_exc, /* i : buffer of excitation */ - const Word16 *pitch_buf, /* i : floating pitch for each subframe */ + Encoder_State_fx* st, /* i/o: state structure */ + const Word16* old_exc, /* i : buffer of excitation */ + const Word16* pitch_buf, /* i : floating pitch for each subframe */ const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new, /* i : current frame LSF vector */ - const Word16 *lsp_new, /* i : current frame LSP vector */ - const Word16 *old_bwe_exc /* i : buffer of excitation */ + const Word16* Aq, /* i : A(z) quantized for all subframes */ + const Word16* lsf_new, /* i : current frame LSF vector */ + const Word16* lsp_new, /* i : current frame LSP vector */ + const Word16* old_bwe_exc /* i : buffer of excitation */ ); void FEC_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *synth, /* i : pointer to synthesized speech for E computation */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ + const Word16* synth, /* i : pointer to synthesized speech for E computation */ const Word16 coder_type, /* i : type of coder */ - Word16 clas, /* i : signal clas for current frame */ - const Word16 *fpit, /* i : close loop fractional pitch buffer */ - const Word16 *res, /* i : LP residual signal frame */ - Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ + Word16 clas, /* i : signal clas for current frame */ + const Word16* fpit, /* i : close loop fractional pitch buffer */ + const Word16* res, /* i : LP residual signal frame */ + Word16* last_pulse_pos, /* i/o: Position of the last pulse */ const Word16 L_frame, /* i : Frame length */ const Word32 total_brate, /* i : total codec bitrate */ - const Word32 core_brate, /* i : total codec bitrate */ - const Word16 Q_new, /* i : input scaling */ + const Word16 Q_new, /* i : i scaling */ const Word16 shift /* i : scaling to get 12bits */ ); void Ener_per_band_comp_fx( @@ -4355,24 +4279,18 @@ void Ener_per_band_comp_fx( const Word16 Mband, /* i : Max band */ const Word16 Eflag ); -void acelp_core_enc_fx( +ivas_error acelp_core_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 inp_fx[], /* i : input signal of the current frame */ - const Word16 vad_flag_fx, + const Word16 inp_fx[], /* i : i signal of the current frame */ const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing_fx[3], /* i : Open-loop pitch gains */ Word16 A_fx[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes*/ Word16 Aw_fx[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ const Word16 epsP_h_fx[M+1], /* i : LP prediction errors */ const Word16 epsP_l_fx[M+1], /* i : LP prediction errors */ Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ - Word16 coder_type_fx, /* i : coding type */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - Word16 vad_hover_flag_fx, - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + Word16 vad_hover_flag_fx, /* i : VAD hangover flag */ + const Word16 attack_flag, /* i : attack flag (GSC or TC) */ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ Word16 *voice_factors_fx, /* o : voicing factors */ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ @@ -4380,26 +4298,40 @@ void acelp_core_enc_fx( Word16 *unbits_fx, /* o : number of unused bits */ const Word16 Q_new, const Word16 shift +#ifdef ADD_LRTD + , + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif +); +void tc_classif_enc( + const Word16 Q_new, /* i : scaling factor */ + const Word16 L_frame, /* i : length of the frame */ + Word16* tc_subfr, /* o : TC subframe index */ + Word16* position, /* o : maximum of residual signal index */ + const Word16 attack_flag, /* i : attack flag */ + const Word16 pitch, /* i : open loop pitch estimates for first halfframe */ + const Word16* res /* i : pointer to the LP residual signal frame */ ); #define EDCT_FACTOR_SCALE 2 void edct_fx( - const Word32 *x, /* i : input signal Qq */ + const Word32 *x, /* i : i signal Qq */ Word32 *y, /* o : output transform Qq */ Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ + Word16 *q /* i : Q value of i signal */ ); void edst_fx( - const Word32 *x, /* i : input signal Qq */ + const Word32 *x, /* i : i signal Qq */ Word32 *y, /* o : output transform Qq */ Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ + Word16 *q /* i : Q value of i signal */ ); void DoRTFTn_fx( - Word32 *x, /* i/o : real part of input and output data */ - Word32 *y, /* i/o : imaginary part of input and output data */ + Word32 *x, /* i/o : real part of i and output data */ + Word32 *y, /* i/o : imaginary part of i and output data */ const Word16 n /* i : size of the FFT up to 1024 */ ); @@ -4413,50 +4345,54 @@ void edct2_fx( const Word16 *w ); void DoRTFT160_16fx( - Word16 x[], /* i/o : real part of input and output data */ - Word16 y[] /* i/o : imaginary part of input and output data */ + Word16 x[], /* i/o : real part of i and output data */ + Word16 y[] /* i/o : imaginary part of i and output data */ ); void DoRTFT320_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y /* i/o : imaginary part of input and output data */ + Word16 *x, /* i/o : real part of i and output data */ + Word16 *y /* i/o : imaginary part of i and output data */ ); void DoRTFT128_16fx( - Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct)*/ - Word16 *y /* i/o : imaginary part of input and output data Q(Qx+Q_edct)*/ + Word16 *x, /* i/o : real part of i and output data Q(Qx+Q_edct)*/ + Word16 *y /* i/o : imaginary part of i and output data Q(Qx+Q_edct)*/ ); void edct_16fx( - const Word16 *x, /* i : input signal Qx */ + const Word16 *x, /* i : i signal Qx */ Word16 *y, /* o : output transform Qx */ Word16 length, /* i : length */ - Word16 bh /* bit-headroom */ + Word16 bh, /* bit-headroom */ + const Word16 element_mode ); void highband_exc_dct_in_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *mfreq_bindiv_loc, /* i : bin per bands tables */ + const Word32 core_brate, /* i : core bitrate */ + const Word16* mfreq_bindiv, /* i : bin per bands tables */ Word16 last_bin, /* i : last bin of bit allocation */ Word16 Diff_len, /* i : number of bin before cut-off frequency */ Word16 noise_lev, /* i : pulses dynamic */ Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 *exc_diffQ, /* i : frequency coefficients of per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ + Word16* exc_diffQ, /* i : frequency coefficients of per band */ + Word16* seed_tcx, /* i : Seed for noise */ + Word16* Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *exc_dct_in, /* o : dct of residual signal */ + Word16* exc_dct_in, /* o : dct of residual signal */ Word16 last_coder_type, /* i : coding type of last frame */ - Word16 *bitallocation_band, /* i : bit allocation flag of each band */ - Word16 *lsf_new, /* i : LSFs at the end of the frame */ - Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16 *last_ener, /* i : frequency energy of last frame */ - Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ + Word16* bitallocation_band, /* i : bit allocation flag of each band */ + const Word16* lsf_new, /* i : LSFs at the end of the frame */ + Word16* last_exc_dct_in, /* i : dct of residual signal of last frame */ + Word16* last_ener, /* i : frequency energy of last frame */ + Word16* last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ + Word16* bitallocation_exc, /* i : flag of decoded coefficients */ Word16 bfi, /* i : bad frame indicator */ const Word16 coder_type, /* i : coder type */ Word16 bwidth, - Word16 *exc_wo_nf , /* o : temporal excitation (in f domain) without noisefill */ + Word16* exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ Word16 Qexc_diffQ, Word16 Q_exc, const Word16 GSC_noisy_speech - ,Word16 *lt_ener_per_band_fx /* i/o: Average per band energy */ + , Word16* lt_ener_per_band_fx, /* i/o: Average per band energy */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); @@ -4468,25 +4404,26 @@ void long_enr_fx( ); Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ + const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ ); void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_look, /* i : look-ahead */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o : current frame LSPs */ - Word16 lsp_mid[], /* o : current mid-frame LSPs */ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ - const Word16 Top[2], /* i : open loop pitch lag */ - const Word16 Tnc[2], /* i : open loop pitch gain */ - const Word32 Core_sr, /* i : Internal core sampling rate */ + const Word16 speech[], /* i : pointer to the speech frame */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_look, /* i : look-ahead */ + Word32* ener, /* o : residual energy from Levinson-Durbin */ + Word16 A[], /* o : A(z) filter coefficients */ + Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o : current frame LSPs */ + Word16 lsp_mid[], /* o : current mid-frame LSPs */ + Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ + const Word16 Top[2], /* i : open loop pitch lag */ + const Word16 Tnc[2], /* i : open loop pitch gain */ + const Word32 Core_sr, /* i : Internal core sampling rate */ + const Word16 sec_chan_low_rate, /* i : flag to signal second channel */ Word16 Q_new, - Word16 *Q_r + Word16* Q_r ); void analy_lp_AMR_WB_fx( @@ -4509,13 +4446,13 @@ void a2rc_fx(const Word16 *a, Word16 *refl,Word16 lpcorder); Word32 invert_dp(Word40 Linput, Word16 n, Word16 *Qout, Word16 wb_mode_bit); void vad_param_updt_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 pitch[3], /* i : open loop pitch lag for each half-frame Q0*/ - Word16 voicing[3], /* i : maximum normalized correlation for each half-frame Q15*/ - const Word16 old_pitch1,/* i : OL pitch value from last frame */ - Word16 corr_shift, /* i : correlation shift Q15*/ - Word16 vad_flag, /* i : vad flag Q0*/ - const Word16 Az[] /* i: a coeffs */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : OL pitch value from last frame */ + const Word16 corr_shift, /* i : correlation shift Q15*/ + const Word16 corr_shiftR, /* i : correlation shift */ + const Word16 Az[], /* i: a coeffs Q12 */ + FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ + const Word16 n_channels /* i : number of channels */ ); void pitch_ol2_fx( @@ -4557,52 +4494,61 @@ void Scale_wsp( const Word16 Len_p_look /* i : L_frame + look ahead */ ); -Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : input signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum /* Q8 */ - , Word16 *sp_floor /* o : noise floor estimate Q7 */ -); - -Word16 find_uv_fx( /* o : coding type */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6 */ - const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15 */ - const Word16 *voicing, /* i : correlation for 3 half-frames Q15 */ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ - const Word16 localVAD, /* i : vad without hangover */ - const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6 */ - const Word16 corr_shift, /* i : normalized correlation correction in noise Q15 */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 Etot, /* i : total energy Q8 */ - const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE */ +Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ + const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ + Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ + Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ + Word16* multi_harm_limit, /* i/o: multi harminic threshold Q9 */ + const Word32 total_brate, /* i : total bitrate Q0 */ + const Word16 bwidth, /* i : i signal bandwidth Q0 */ + Word16* cor_strong_limit, /* i/o: HF correlation indicator Q0 */ + Word16* st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ + Word16* st_last_sw_dyn, /* i/o: last dynamic Q7 */ + Word16* cor_map_sum, /* i : sum of correlation map Q8 */ + Word16* sp_floor, /* o: noise floor estimate Q7 */ + Word16 S_map[] /* o : short-term correlation map Q7 */ +); + +Word16 find_uv_fx( /* o : coding type */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word16* T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ + const Word16* voicing_fr, /* i : refined correlation for each subframes Q15*/ + const Word16* speech, /* i : pointer to speech signal for E computation Q_new*/ + const Word32* ee, /* i : lf/hf Energy ratio for present frame Q6*/ +#ifdef IVAS_CODE + Word32* dE1X, /* o : sudden energy increase for S/M classifier */ +#endif + const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ + const Word16 relE, /* i : relative frame energy Q8*/ + const Word16 Etot, /* i : total energy Q8*/ + const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/ const Word16 Q_new, - Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ - const Word16 voicing_sm /* i : smoothed open-loop pitch gains */ - , const Word16 shift - , const Word16 last_core_orig /* i : original last core */ -); - -Word16 signal_clas_fx( /* o : classification for current frames */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *coder_type, /* i/o: coder type */ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames */ - const Word16 *speech, /* i : pointer to speech signal for E computation */ - const Word16 localVAD, /* i : vad without hangover */ - const Word16 pit[3], /* i : open loop pitch values for 3 half-frames */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look , /* i : look-ahead */ - Word16 *uc_clas /* o : temporary classification used in music/speech class*/ + Word16* flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ + const Word16 shift, + const Word16 last_core_orig /* i : original last core */ +#ifdef IVAS_CODE + , STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ +#endif ); +Word16 signal_clas_fx( /* o : classification for current frames */ + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16* speech, /* i : pointer to speech signal for E computation */ + const Word32* ee, /* i : lf/hf E ration for 2 half-frames */ + const Word16 relE, /* i : frame relative E to the long term average */ + const Word16 L_look, /* i : look-ahead */ + Word16* uc_clas /* o : temporary classification used in music/speech class*/ +); +void select_TC( + const Word16 codec_mode, /* i : codec mode */ + const Word16 tc_cnt, /* i : TC frame counter */ + Word16* coder_type, /* i/o: coder type */ + const Word16 localVAD /* i : VAD without hangover */ +); +void coder_type_modif( + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16 relE /* i : frame relative E to the long term average */ +); void find_tilt_fx( const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ @@ -4611,7 +4557,7 @@ void find_tilt_fx( const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 bwidth, /* i : i signal bandwidth */ const Word16 max_band, /* i : maximum critical band */ Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ const Word16 codec_mode, /* i : MODE1 or MODE2 */ @@ -4650,31 +4596,32 @@ Word16 swb_bwe_dec_hr_fx( const Word16 pitch_buf[] /* i : pitch buffer */ ); Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp0, /* i : input signal */ + const Word16 *sp0, /* i : i signal */ const Word16 exp, /* i : Exp of inp signal */ const Word16 N /* i : signal length */ ); void Inverse_Transform( - const Word32 *in_mdct, /* i : input MDCT vector */ - Word16 *Q, /* i/o: Q value of input */ + const Word32 *in_mdct, /* i : i MDCT vector */ + Word16 *Q, /* i/o: Q value of i */ Word32 *out, /* o : output vector */ const Word16 is_transient, /* i : transient flag */ const Word16 L, /* i : output frame length */ - const Word16 L_inner /* i : length of the transform */ + const Word16 L_inner, /* i : length of the transform */ + const Word16 element_mode /* i : IVAS element mode */ ); void iedct_short_fx( - const Word32 *in, /* i : input vector */ - Word16 *Q, /* i/o: Q value of input */ + const Word32 *in, /* i : i vector */ + Word16 *Q, /* i/o: Q value of i */ Word32 *out, /* o : output vector */ const Word16 segment_length /* i : length */ ); void swb_bwe_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ - Word16 *old_input_16k_fx, /* i : input signal @16kHz for SWB BWE */ + Word16 *old_input_12k8_fx, /* i : i signal @12.8kHz for SWB BWE */ + Word16 *old_input_16k_fx, /* i : i signal @16kHz for SWB BWE */ const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - const Word16 *new_swb_speech_fx, /* i : original input signal at 32kHz */ + const Word16 *new_swb_speech_fx, /* i : original i signal at 32kHz */ Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ const Word16 coder_type, /* i : coding type */ Word16 Q_shb_speech, @@ -4682,7 +4629,7 @@ void swb_bwe_enc_fx( ); void wb_bwe_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *new_wb_speech_fx, /* i : original input signal at 16kHz */ + const Word16 *new_wb_speech_fx, /* i : original i signal at 16kHz */ Word16 coder_type /* i : coding type */ ); @@ -4697,13 +4644,18 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb signal * Word16 wb_bwe_dec_fx( - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 output_frame, /* i : frame length */ - Word16 coder_type, /* i : coding type */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ +#ifdef ADD_IVAS_BWE + const Word16 output[], /* i : suntehsis @ internal Fs */ +#endif + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ +#ifdef ADD_IVAS_BWE + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ +#endif + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors */ + const Word16 pitch_buf_fx[],/* i : pitch buffer */ + Decoder_State_fx *st_fx /* i/o: decoder state structure */ ,Word16 * Qpost ); @@ -4721,12 +4673,17 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ ); Word16 swb_bwe_dec_fx( +#ifdef ADD_IVAS_BWE + const Word16 output[], /* i : suntehsis @ internal Fs */ +#endif Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ +#ifdef ADD_IVAS_BWE + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ +#endif const Word16 output_frame /* i : frame length */ ,Word16 * Qpost - ,Word16 coder_type /* i : coding type */ ); Word16 WB_BWE_gain_pred_fx( @@ -4745,8 +4702,8 @@ Word16 WB_BWE_gain_pred_fx( ); void calc_normal_length_fx( const Word16 core, /* i : core */ - const Word16 *sp, /* i : input signal */ - const Word16 mode, /* i : input mode */ + const Word16 *sp, /* i : i signal */ + const Word16 mode, /* i : i mode */ const Word16 extl, /* i : extension layer */ Word16 *L_swb_norm, /* o : normalize length */ Word16 *prev_L_swb_norm, /*i/o : last normalize length */ @@ -4757,7 +4714,7 @@ void calc_norm_envelop_fx( const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ Word32 *envelope, /* o : normalized envelope Q_syn*/ const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 SWB_flength, /* i : Length of i /output */ const Word16 st_offset /* i : offset */ ); @@ -4765,7 +4722,7 @@ void WB_BWE_decoding_fx( const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ Word16 *WB_fenv, /* i : WB frequency envelopes */ Word32 *WB_signal32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of input/output */ + const Word16 WB_flength, /* i : Length of i /output */ const Word16 mode, /* i : classification for WB signal */ const Word16 last_extl, /* i : extl. layer for last frame */ Word32 *prev_Energy, /* i/o: energy for last frame */ @@ -4785,7 +4742,7 @@ void SWB_BWE_decoding_fx( const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ Word32 *SWB_signal, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 SWB_flength, /* i : Length of i /output */ const Word16 mode, /* i : classification for SWB signal */ Word16 *frica_flag, /* o : fricative signal flag */ Word16 *prev_Energy, /* i/o: energy for last frame */ @@ -4908,7 +4865,7 @@ void GetPredictedSignal_fx( ); void Get20Log10Spec_fx( - const Word32 *L_inBuf, /* i : input Q_inBuf */ + const Word32 *L_inBuf, /* i : i Q_inBuf */ Word16 *outBuf_fx, /* o : output Q7 */ const Word16 fLen, /* i : loop length */ const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ @@ -4944,7 +4901,7 @@ void SpectrumSmoothing_fx( void GetSynthesizedSpecThinOut_fx( const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */ - const Word16 Qss, /* i : Q value of input vector */ + const Word16 Qss, /* i : Q value of i vector */ Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ Word16 QsL, /* o : Q value of synthesized spectrum */ const Word16 nBands_fx, /* i : Q0: number of subbands calculated */ @@ -4965,7 +4922,7 @@ Word32 hq2_bit_alloc_fx ( const Word16 band_width[], /* i : Sub band bandwidth */ const Word16 num_bits, /* i : available bits */ const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : input bandwidth */ + const Word16 bwidth, /* i : i bandwidth */ const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ ); @@ -5083,23 +5040,23 @@ typedef struct GainItemStr_fx } GainItem_fx; void genhf_noise_fx( - Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ - Word16 Qss, /* i : Q0 Q value */ + const Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ + const Word16 Qss, /* i : Q0 Q value */ Word32 L_xSynth_har[], /* o : QsL hf non tonal components */ /* xSynth_har:QsL */ - Word16 QsL, /* i : Q0 Q value */ - Word16 *predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ - Word16 bands, /* i : Q0 total number of subbands in a frame */ - Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ - Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ - Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ - Word16 *pul_res, /* o : Q0 pulse resolution */ + const Word16 QsL, /* i : Q0 Q value */ + const Word16* predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ + const Word16 bands, /* i : Q0 total number of subbands in a frame */ + const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ + const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ + const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ + Word16* pul_res, /* o : Q0 pulse resolution */ GainItem_fx pk_sf_fx[], /* o : representative region */ - const Word16 fLenLow, /* i : Q0 low frequency length */ - const Word16 fLenHigh, /* i : Q0 high frequency length */ - const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ - const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ - const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ - const Word16 subband_search_offset[] /* i : Q0 most representative regions offsets in LF */ + const Word16 fLenLow, /* i : Q0 low frequency length */ + const Word16 fLenHigh, /* i : Q0 high frequency length */ + const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ + const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ + const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ + const Word16 subband_search_offset[]/* i : Q0 most representative regions offsets in LF */ ); void spt_shorten_domain_pre_fx( @@ -5151,7 +5108,7 @@ void updat_prev_frm_fx( Word32 L_t_audio[], /* o: core coder buffer */ Word32 L_bwe_br, /* i: core bitrate */ Word16 length_fx, /* i: frame length coded bw */ - const Word16 inner_frame_fx, /* i: input frame length */ + const Word16 inner_frame_fx, /* i: i frame length */ Word16 bands_fx, /* i: sub band resolution */ Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ const Word16 is_transient_fx, /* i: signal class information */ @@ -5204,23 +5161,23 @@ void noise_extr_corcod_fx( ); void ton_ene_est_fx( - Word32 L_xSynth_har[], /* i : QsL buffer with non tonal compoents */ - Word16 QsL, /* i : Q0 Q value for xSynth_har */ + Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */ + const Word16 QsL, /* i : Q0 Q value for xSynth_har */ Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */ - Word16 *QbeL, /* o : Q0 Q value for be_tonal */ - Word32 L_band_energy[], /* i : Qbe subband energies */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 band_start[], /* i : Q0 subband start indices */ - const Word16 band_end[], /* i : Q0 subband end indices */ - const Word16 band_width[], /* i : Q0 subband widths */ - const Word16 fLenLow, /* i : Q0 low frequency width */ - const Word16 fLenHigh, /* i : Q0 High frequency width */ - Word16 bands, /* i : Q0 total subbands */ - Word16 har_bands, /* i : Q0 total number of harmonics bands */ - Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ - GainItem_fx pk_sf_fx[], /* i : */ - Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ - Word16 *pul_res /* i : Q0 tonal resolution */ + Word16* QbeL, /* o : Q0 Q value for be_tonal */ + const Word32 L_band_energy[], /* i : Qbe subband energies */ + const Word16 Qbe, /* i : Q0 Q value for band_energy */ + const Word16 band_start[], /* i : Q0 subband start indices */ + const Word16 band_end[], /* i : Q0 subband end indices */ + const Word16 band_width[], /* i : Q0 subband widths */ + const Word16 fLenLow, /* i : Q0 low frequency width */ + const Word16 fLenHigh, /* i : Q0 High frequency width */ + const Word16 bands, /* i : Q0 total subbands */ + const Word16 har_bands, /* i : Q0 total number of harmonics bands */ + const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ + GainItem_fx pk_sf_fx[], /* i : */ + const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ + const Word16* pul_res /* i : Q0 tonal resolution */ ); void Gettonl_scalfact_fx @@ -5246,7 +5203,7 @@ void Gettonl_scalfact_fx void get_sigma_fx_har( - const Word32 L_x_abs[], /* i: Qi absolute input */ + const Word32 L_x_abs[], /* i: Qi absolute i */ const Word16 Qi, /* i: Q0 Q value of x_abs */ const Word16 avg_fx, /* i: Qavg average of x_abs */ const Word16 Qavg, /* i: Q0 Q value of avg */ @@ -5256,8 +5213,8 @@ void get_sigma_fx_har( ); void FindNBiggest2_simple_fx_har( - const Word32 *L_inBuf, /* i : input buffer (searched) */ - const Word16 Qabs_in, /* i : Q value of input buffer */ + const Word32 *L_inBuf, /* i : i buffer (searched) */ + const Word16 Qabs_in, /* i : Q value of i buffer */ GainItem_fx *pk_sf_fx, /* o : N biggest components found */ const Word16 nIdx_fx, /* i : search length */ Word16 *n_fx, /* i : number of components searched (N biggest) */ @@ -5292,15 +5249,15 @@ void noiseinj_hf_fx( ); void sqrt_32n_16_fx( - Word32 L_in, /* i : input vector (Word32) */ + Word32 L_in, /* i : i vector (Word32) */ Word16 Qin, /* i : Q value for L_in */ - Word16 *out_fx, /* o : sqrt input vector (Word16) */ + Word16 *out_fx, /* o : sqrt i vector (Word16) */ Word16 *Qout /* o : Q value for out_fx */ ); void norm_vec_32_16_scale_fx( - Word32 *L_vec_in, /* i : input vector */ - Word16 Qin, /* i : Q value for input vector */ + Word32 *L_vec_in, /* i : i vector */ + Word16 Qin, /* i : Q value for i vector */ Word16 length_fx, /* i :vector size */ Word16 *vec_out_fx, /* o : output vectror */ Word16 *Qout, /* o : Q value for output vectro */ @@ -5316,7 +5273,7 @@ void return_bits_normal2_fx( Word16 peak_avrg_ratio_fx( const Word32 total_brate, - const Word32 *input_hi_fx, /* i : input signal */ + const Word32 *input_hi_fx, /* i : i signal */ const Word16 length, /* i : number of coefficients */ Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ @@ -5338,7 +5295,7 @@ void diffcod_lrmdct_fx( ); Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ const Word16 num_sfm, /* i : Number of subbands Q0 */ const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ @@ -5409,34 +5366,41 @@ Word16 noise_est_AR1_Qx( /* o: Qx y(n) */ Word16 alpha /*i : Q15 scaling of driving x(n) */ ); void noise_est_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ - const Word16 *pit, /* i : open-loop pitch values for each half-frame Q0 */ - const Word16 cor[], /* i : normalized correlation for all half-frames Q15 */ - const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ - const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ - const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ - const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ - Word16 *cor_map_sum, /* o : Q8 */ - Word16 *sp_div, /* o : Q_sp_div */ - Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ - Word16 *loc_harm , /* o : multi-harmonicity flag for UV classifier */ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ - Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ - const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ - const Word16 Etot_v_h2, /* i : Energy variations Q8 */ - Word16 *bg_cnt, /* i : Background burst length timer Q0 */ - Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 */ - Word16 Q_new , /* i : Scaling of current frame */ - - const Word32 Le_min_scaled /*i : Minimum energy value */ - , Word16 *sp_floor /* o : noise floor estimate Q7 */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ + const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ + const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ + const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + Word16* cor_map_sum, /* o : Q8 */ + Word16* ncharX, /* o : IVAS_CODE -> size of ncharX needs validation noise character for sp/mus classifier Qx? */ + Word16* sp_div, /* o : Q_sp_div */ + Word16* Q_sp_div, /* o : Q factor for sp_div */ + Word16* non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16* loc_harm, /* o : multi-harmonicity flag for UV classifier */ + const Word32* lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ + Word16* st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ + const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ + const Word16 Etot_v_h2, /* i : Energy variations Q8 */ + Word16* bg_cnt, /* i : Background burst length timer Q0 */ + Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ + Word16 Q_new, /* i : SCaling of current frame */ + const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ + Word16* sp_floor, /* o : noise floor estimate Q7 */ + Word16 S_map[], /* o : short-term correlation map Q7 */ +#ifdef IVAS_CODE + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */ +#endif + const Word16 ini_frame /* i : Frame number (init) */ +); +void amr_wb_enc_init( + AMRWB_IO_ENC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO encoder handle */ ); - void autocorr_fx( const Word16 x[], /* i : Input signal */ @@ -5455,7 +5419,8 @@ void freq_dnw_scaling_fx( const Word16 noise_lev, /* i : Noise level */ const Word32 core_brate, /* i : Core bitrate */ Word16 fy_norm[], /* i/o: Frequency quantized parameter */ - Word16 Qx /* Q format of fy_norm*/ + Word16 Qx, /* Q format of fy_norm*/ + const Word16 L_frame /* i : frame length */ ); void Comp_and_apply_gain_fx( Word16 exc_diffQ[], /* i/o: Quantized excitation */ @@ -5467,41 +5432,48 @@ void Comp_and_apply_gain_fx( Word16 Q_exc ); void dec_pit_exc_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16 *gain_buf /*Q14*/ + Decoder_State_fx* st_fx, /* i/o: decoder static memory */ + const Word16* Aq_fx, /* i : LP filter coefficient */ + const Word16 coder_type_fx, /* i : coding type */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16* pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16* code_fx, /* o : innovation */ + Word16* exc_fx, /* i/o: adapt. excitation exc */ + Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ + const Word16 nb_subfr_fx /* i : Number of subframe considered */ + , Word16* gain_buf /*Q14*/ +#ifdef ADD_LRTD + , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +#endif ); Word16 mean_fx( /* o : mean of vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx /* i : length of input vector */ + const Word16 *vec_fx, /* i : i vector */ + const Word16 lvec_fx /* i : length of i vector */ +); +void GSC_dec_init( + GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ); void gsc_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + Decoder_State_fx *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + const Word16 coder_type, /* i : coding type */ + Word16 *last_bin, /* i : last bin of bit allocation */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ Word16 Q_exc ); void fft_rel_fx( - Word16 x[], /* i/o: input/output vector */ + Word16 x[], /* i/o: i /output vector */ const Word16 n, /* i : vector length */ const Word16 m /* i : log2 of vector length */ ); void ifft_rel_fx( - Word16 io[], /* i/o: input/output vector */ + Word16 io[], /* i/o: i /output vector */ const Word16 n, /* i : vector length */ const Word16 m /* i : log2 of vector length */ ); @@ -5512,10 +5484,10 @@ Word16 gsc_gaindec_fx( /* o : average frequency gain */ const Word32 core_brate_fx, /* i : core used */ Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ const Word16 coder_type_fx, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ + const Word16 bwidth_fx /* i : i signal bandwidth */ ); void Copy_Scale_sig( - const Word16 x[], /* i : signal to scale input Qx */ + const Word16 x[], /* i : signal to scale i Qx */ Word16 y[], /* o : scaled signal output Qx */ const Word16 lg, /* i : size of x[] Q0 */ const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ @@ -5527,17 +5499,20 @@ void bands_and_bit_alloc_fx( const Word32 core_brate, /* i : core bit rate */ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ const Word16 bits_used, /* i : Number of bit used before frequency Q */ - Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ - const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ - Word16 *max_ener_band, /* o : Sorted order */ - Word16 *bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ - Word16 *nb_subbands, /* o : Number of subband allowed */ - const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */ - Word16 *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */ - Word16 *pvq_len, /* o : Number of bin covered with the PVQ */ + Word16* bit, /* i/o: Number of bit allowed for frequency quantization */ + const Word16* Ener_per_bd_iQ, /* i/o: Quantized energy vector */ + Word16* max_ener_band, /* o : Sorted order */ + Word16* out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ + Word16* nb_subbands, /* o : Number of subband allowed */ + const Word16* exc_diff, /* i : Difference signal to quantize (encoder side only) */ + Word16* concat_in, /* o : Concatened PVQ's i vector (encoder side only) */ + Word16* pvq_len, /* o : Number of bin covered with the PVQ */ const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 GSC_noisy_speech + const Word16 bwidth, /* i : i signal bandwidth */ + const Word16 GSC_noisy_speech, /* i : GSC noisy speech flag */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); @@ -5545,7 +5520,6 @@ void decod_audio_fx( Decoder_State_fx *st_fx, /* i/o: decoder static memory */ Word16 dct_epit[], /* o : GSC excitation in DCT domain */ const Word16 *Aq, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ Word16 *pitch_buf, /* o : floating pitch values for each subframe */ Word16 *voice_factors, /* o : voicing factors */ Word16 *exc, /* i/o: adapt. excitation exc */ @@ -5555,155 +5529,117 @@ void decod_audio_fx( , Word16 *gain_buf /*Q14*/ ); Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ - const Word16 coder_type, /* i : coding type */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 *dct_res, /* i : DCT of residual */ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ + Word16 *pitch_buf, /* i/o: Pitch per subframe */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *hangover, /* i : hangover for the time contribution switching */ Word16 Qnew ); void enc_pit_exc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech, /* i : Input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ + Encoder_State_fx* st_fx, /* i/o: State structure */ + const Word16* speech, /* i : Input speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 *T_op, /* i : open loop pitch */ - const Word16 *voicing, /* i : voicing */ - const Word16 *res, /* i : residual signal */ - Word16 *synth, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + const Word16* res, /* i : residual signal */ + Word16* synth, /* i/o: core synthesis */ + Word16* exc, /* i/o: current non-enhanced excitation */ + Word16* T0, /* i/o: close loop integer pitch */ + Word16* T0_frac, /* i/o: close-loop pitch period - fractional part */ + Word16* pitch_buf, /* i/o: Fractionnal per subframe pitch */ const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *gpit, /* o : pitch mean gpit */ - Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + Word16* gpit, /* o : pitch mean gpit */ + Word16* saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, Word16 shift ); void encod_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[], /* i : voicing */ - const Word16 *res, /* i : residual signal */ - Word16 *syn, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *exc2, /* i/o: current enhanced excitation */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - const Word16 *speech16k_fx, + Encoder_State_fx* st, /* i/o: state structure */ + const Word16 speech[], /* i : i speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16* res, /* i : residual signal */ + Word16* syn, /* i/o: core synthesis */ + Word16* exc, /* i/o: current non-enhanced excitation */ + Word16* exc2, /* i/o: current enhanced excitation */ + Word16* pitch_buf, /* i/o: floating pitch values for each subframe */ + Word16 hf_gain_fx[NB_SUBFR],/* o : decoded HF gain */ + const Word16* speech16k_fx, /* i : i speech @16kHz */ Word16 shift, Word16 Q_new ); void amr_wb_enc_fx( Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal */ - const Word16 n_samples /* i : number of input samples */ + const Word16 input_sp[], /* i : i signal */ + const Word16 n_samples /* i : number of i samples */ ); void encod_gen_voic_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* o : formant sharpening flag */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 A_fx[], /* i : unquantized A(z) filter with bandwidth expansion */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : i speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16* res_fx, /* i : residual signal */ + Word16* syn_fx, /* i/o: core synthesis */ + Word16* exc_fx, /* i/o: current non-enhanced excitation */ + Word16* exc2_fx, /* i/o: current enhanced excitation */ + Word16* pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16* voice_factors_fx, /* o : voicing factors */ + Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16* unbits_fx, /* i/o: number of unused bits */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 shift, Word16 Q_new ); void bw_detect_fx( - Encoder_State_fx *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : input signal */ - const Word16 localVAD, - Word32 *enerBuffer, /* i : CLDFB Energy */ - Word16 *cldfbBuf_Ener_Exp /* i : CLDFB Energy Exponent */ + Encoder_State_fx* st, /* i/o: Encoder State */ + const Word16 signal_in[], /* i : i signal */ + Word16* spectrum, /* i : MDCT spectrum */ + const Word32* enerBuffer, /* i : CLDFB Energy Q31 */ + const Word16* cldfbBuf_Ener_Exp,/* i : CLDFB Energy Exponent */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t mct_on /* i : flag MCT mode */ +); +void set_bw( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + Encoder_State_fx* st, /* i/o: Encoder State */ + const Word16 codec_mode /* i : codec mode */ ); void hf_synth_amr_wb_init_fx( - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 mem_syn_hf_fx[], /* o : HF LPC synthesis filter initialization */ - Word16 *frame_count, /* o : frame counter initialization */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy initialization*/ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor initialization */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ +); +void amr_wb_dec_init( + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ ); - void hf_synth_amr_wb_reset_fx( - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 mem_syn_hf[], /* o : HF synthesis memory */ - Word16 mem_hp_interp[], /* o : interpol. memory */ - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 delay_syn_hf[], /* o : HF synthesis memory */ - Word16 *frame_count, /* o : frame counter memory */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy memory */ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor memory */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ ); void hf_synth_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + const Word32 core_brate, /* i : core bitrate */ const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Qexc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Qsyn */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qout */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qout */ - Word16 *prev_r, /* i/o : previous sub-frame gain : Q10 */ - Word16 *fmerit_w_sm, /* i/o: smoothed fmerit_w : Q14 */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qout */ - Word16 *synth_out, /* i/o: output signal at output Fs : Qout */ + const Word16* Aq, /* i : quantized Az : Q12 */ + const Word16* exc, /* i : excitation at 12.8 kHz : Q_exc */ + Word16* synth, /* i/o: synthesis signal at 12.8k : Q_syn */ + Word16* amr_io_class, /* i : signal class (determined by FEC algorithm) */ + Word16* synth_out, /* i/o: output signal at output Fs : Q_out */ Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ + const Word16* hf_gain, /* i : decoded HF gain */ + const Word16* voice_factors, /* i : voicing factors : Q15 */ const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - Word16 *frame_count, /* i/o: frame counter */ - Word16 *ne_min, /* i/o: minimum Noise gate : Q8 */ - Word16 *fmerit_m_sm, /* i/o: smoothed fmerit_m : Q14 */ - Word16 *voice_facor_sm, /* o : voice factor memory : Q15 */ - Word16 *unvoicing, /* o : unvoiced parameter : Q15 */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter : Q15 */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old, /* o : previous criterion value for deciding the start point */ + const Word16* lsf_new, /* i : ISF vector : Q2 */ const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : synth_out scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ); void hf_cod_init_fx( @@ -5765,7 +5701,7 @@ void pz_filter_sp_fx ( void Decimate_allpass_steep_fx( const Word16 *in_fx, Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ + Word16 N, /* number of i samples */ Word16 out_fx[] /* array of size N/2 */ ); @@ -5785,11 +5721,11 @@ Word32 root_a_over_b_fx( void fir_fx( - const Word16 x[], /* i : input vector */ + const Word16 x[], /* i : i vector */ const Word16 h[], /* i : impulse response of the FIR filter */ Word16 y[], /* o : output vector (result of filtering) */ - Word16 mem[], /* i/o: memory of the input signal (M samples) */ - const Word16 L, /* i : input vector size */ + Word16 mem[], /* i/o: memory of the i signal (M samples) */ + const Word16 L, /* i : i vector size */ const Word16 K, /* i : order of the FIR filter (M+1 coefs.) */ const Word16 upd, /* i : 1 = update the memory, 0 = not */ Word16 shift /* i : difference between Q15 and scaling of h[] */ @@ -5797,9 +5733,9 @@ void fir_fx( void Interpolate_allpass_steep_fx( - const Word16 *in_fx, /* i : input signal */ + const Word16 *in_fx, /* i : i signal */ Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ + Word16 N, /* number of i samples */ Word16 out_fx[] /* o : output signal, size 2*N */ ); @@ -5814,8 +5750,7 @@ void interpolate_3_over_1_allpass_fx( const Word16 *input_fx, const Word16 len, Word16 *out_fx, - Word16 *mem_fx, - const Word16 *filt_coeff_fx + Word16 *mem_fx ); void decimate_2_over_3_allpass_fx( const Word16 *input_fx, @@ -5844,14 +5779,14 @@ void lsp2lpc_fx( ); void PostShortTerm_fx( - Word16 *sig_in, /* i : input signal (pointer to current subframe */ + Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ Word16 *mem_stp, /* i/o: postfilter memory*/ Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - Word16 formant_fac_fx /* i : Strength of post-filter*/ + const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); void GenShapedWBExcitation_fx( @@ -5873,14 +5808,14 @@ void GenShapedWBExcitation_fx( ); void GenWBSynth_fx( - const Word16 *input_synspeech, /* i : input synthesized speech */ + const Word16 *input_synspeech, /* i : i synthesized speech */ Word16 *shb_syn_speech_16k, /* o : output highband compnent */ Word16 *state_lsyn_filt_shb1, /* i/o: memory */ Word16 *state_lsyn_filt_shb2 /* i/o: memory */ ); void GenSHBSynth_fx( - const Word16 *shb_target_speech, /* i : input synthesized speech */ + const Word16 *shb_target_speech, /* i : i synthesized speech */ Word16 *shb_syn_speech_32k, /* o : output highband component */ Word32 Hilbert_Mem[], /* i/o: memory */ Word16 genSHBsynth_allpass_mem[], /* i/o: memory */ @@ -5926,35 +5861,49 @@ void ScaleShapedWB_fx( ); void GenShapedSHBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32 *mem_csfilt, /* i/o: memory */ - Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16 *tbe_demph, /* i/o: de-emphasis memory */ - Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, - Word16 *shb_res_gshape, - Word16 *shb_res, - Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ - Word16 *Q_bwe_exc, - Word16 *Q_bwe_exc_fb, + Word16* excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16* lpc_shb, /* i : lpc coefficients Q12*/ + Word16* White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32* mem_csfilt, /* i/o: memory */ + Word16* mem_genSHBexc_filt_down_shb, /* i/o: memory */ + Word16* state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16* bwe_exc_extended, /* i : bandwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16* tbe_demph, /* i/o: de-emphasis memory */ + Word16* tbe_premph, /* i/o: pre-emphasis memory */ + Word16* lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: i shb ener, Q31 */ + Word16* shb_res_gshape, /* i: i res gain shape, Q14 */ + Word16* shb_res, + Word16* vf_ind, + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16* fb_tbe_demph, /* i/o: fb de-emphasis memory */ + Word16* Q_bwe_exc, + Word16* Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi -); +#ifdef ADD_IVAS_TBE_CODE + , /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16* nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word16* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16* Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ +#endif + ); void space_lsfs_fx ( @@ -5975,7 +5924,7 @@ void lsp_convolve_fx(Word32 x, Word32 *p1, Word32 *p2, Word16 len); Word32 poscos_fx(Word16 w); void flip_spectrum_and_decimby4_fx( - const Word16 input[], /* i : input spectrum */ + const Word16 i [], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ const Word16 length, /* i : vector length */ Word16 mem1[], /* i/o : memory */ @@ -6004,7 +5953,7 @@ void wb_tbe_enc_fx( const Word16 coder_type, /* i : coding type */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : input HB speech Q factor */ + const Word16 Q_new, /* i : i HB speech Q factor */ const Word16 voice_factors[], /* i : voicing factors */ const Word16 pitch_buf[], /* i : pitch for each subframe */ const Word16 voicing[] /* i : OL maximum normalized correlation */ @@ -6012,7 +5961,7 @@ void wb_tbe_enc_fx( void wb_pre_proc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *new_inp_resamp16k, /* i : original input signal */ + const Word16 *new_inp_resamp16k, /* i : original i signal */ Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */ ); @@ -6030,7 +5979,7 @@ void pz_filter_dp_fx ( ); void flip_and_downmix_generic_fx( - Word16 input[], /* i : input spectrum */ + Word16 i [], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ const Word16 length, /* i : length of spectra */ Word32 mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */ @@ -6049,11 +5998,36 @@ void wb_tbe_dec_fx( Word16 *synth, /* i/o: ACELP core synthesis/final synthesis */ Word16 *Q_synth ); - +ivas_error config_acelp1( + const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word32 total_brate, /* i : total bitrate */ + const Word32 core_brate_inp, /* i : core bitrate */ + const Word16 core, /* i : core */ + const Word16 extl, /* i : extension layer */ + const Word32 extl_brate, /* i : extension layer bitrate */ + const Word16 L_frame, /* i : frame length at internal Fs */ + const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ + ACELP_config* acelp_cfg, /* i : ACELP bit-allocation */ + const Word16 signalling_bits, /* i : number of signalling bits */ + const Word16 coder_type, /* i : coder type */ + const Word16 tc_subfr, /* i : TC subfr ID */ + const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ + Word16* nBits_es_Pred, /* o : number of bits for Es_pred Q */ + Word16* unbits, /* o : number of unused bits */ + const Word16 element_mode, /* i : element mode */ + Word16* uc_two_stage_flag, /* o : flag undicating two-stage UC */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 idchan, /* i : stereo channel ID */ + const Word16 active_cnt, /* i : Active frame counter */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ +); void swb_tbe_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ const Word16 coder_type_fx, /* i : coding type */ - Word16 *new_speech_fx, /* i : original input signal */ + Word16 *new_speech_fx, /* i : original i signal */ Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ const Word16 voice_factors_fx[], /* i : voicing factors */ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ @@ -6063,11 +6037,27 @@ void swb_tbe_enc_fx( Word16 *voicing_fx, /* i : OL maximum normalized correlation */ const Word16 pitch_buf[] /* i : pitch for each subframe */ ); +void td_bwe_dec_init_fx( + Decoder_State_fx* st_fx, /* i/o: SHB decoder structure */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ +#ifdef ADD_IVAS_BWE + const Word16 extl, /* i : BWE extension layer */ +#endif + const Word32 output_Fs /* i : output sampling rate */ +); + +void fd_bwe_dec_init( + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ +); +void hr_bwe_dec_init( + HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ +); void swb_pre_proc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *input_fx, /* i : original input signal */ - Word16 *new_swb_speech_fx, /* o : original input signal at 32kHz */ + const Word16 *input_fx, /* i : original i signal */ + Word16 *new_swb_speech_fx, /* o : original i signal at 32kHz */ Word16 *shb_speech_fx, /* o : SHB target signal (6-14kHz) at 16kHz */ Word16 *Q_shb_spch /* o : shb target signal Q factor */ , Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : real buffer */ @@ -6135,14 +6125,14 @@ void tbe_read_bitstream_fx( Decoder_State_fx *st_fx /* i/o: encoder state structure */ ); -Word16 get_tbe_bits_fx( /* o : TBE bit consumption per frame */ - Word32 bitrate, /* i : overall bitrate */ - Word16 bandwidth /* i : bandwidht mode */ - ,Word16 rf_mode +Word16 get_tbe_bits_fx( + const Word32 total_brate, /* o : TBE bit consumption per frame */ + const Word16 bwidth, /* i : overall bitrate */ + const Word16 rf_mode /* i : bandwidht mode */ ); void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ + const Word16 *i , /* i : gain shape overlap buffer */ const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ Word16 length, /* i : targeted length of transition signal */ Word16 *output, /* o : synthesized transitions signal */ @@ -6157,7 +6147,7 @@ void GenTransition_fx( ); void GenTransition_WB_fx( - const Word16 *input, /* i : gain shape overlap buffer */ + const Word16 *i , /* i : gain shape overlap buffer */ const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ const Word16 prev_Qx, /* i : scaling of old_hb_synth */ Word16 length, /* i : targeted length of transition signal */ @@ -6180,7 +6170,7 @@ void TBEreset_dec_fx( void fb_tbe_enc_fx( Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ + const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc ); @@ -6194,7 +6184,7 @@ void fb_tbe_dec_fx( ); void elliptic_bpf_48k_generic_fx( - const Word16 input_fx[], /* i : input signal */ + const Word16 input_fx[], /* i : i signal */ Word16 *Q_input_fx, Word16 output_fx[], /* o : output signal */ Word32 memory_fx[][4], /* i/o: 4 arrays of 4 for memory */ @@ -6217,7 +6207,6 @@ void synthesise_fb_high_band_fx( void lsf_syn_mem_restore_fx( Encoder_State_fx *st_fx, /* o: state structure */ - LPD_state* LPDmem, /* o: LPD_state vewctor */ Word16 btilt_code_fx, /* i: */ Word32 gc_threshold_fx, /* i: */ Word16 *clip_var_bck_fx, /* i: */ @@ -6241,21 +6230,21 @@ void lsf_syn_mem_restore_fx( ); void encod_nelp_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech_fx, /* i : input speech */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16* speech_fx, /* i : i speech */ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *res_fx, /* o : residual signal */ - Word16 *synth_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16* voice_factors_fx, /* o : voicing factors */ - Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16* res_fx, /* o : residual signal */ + Word16* synth_fx, /* o : core synthesis */ + Word16* tmp_noise_fx, /* o : long-term noise energy */ + Word16* exc_fx, /* i/o: current non-enhanced excitation */ + Word16* exc2_fx, /* i/o: current enhanced excitation */ + Word16* pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16* voice_factors_fx, /* o : voicing factors */ + Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ Word16 Q_new, Word16 shift + ); void nelp_encoder_fx( @@ -6267,11 +6256,11 @@ void nelp_encoder_fx( ); Word16 dequantize_uvg_fx( - Word16 iG1, /* i: gain 1 index */ - Word16 *iG2, /* i: gain 2 index */ - Word16 *G, /* o: quantized gain */ - Word16 bandwidth /* i: bandwidth */ - ,Word16 do_scale + const Word16 iG1, /* i: gain 1 index */ + const Word16* iG2, /* i: gain 2 index */ + Word16* G, /* o: quantized gain */ + const Word16 bandwidth, /* i: bandwidth */ + const Word16 do_scale ); void quantize_uvg_fx( @@ -6284,10 +6273,10 @@ void quantize_uvg_fx( void generate_nelp_excitation_fx( - Word16 *seed, - Word16 *Gains, - Word16 *output, - Word16 gain_fac + Word16* seed, /* i/o: random number seed */ + const Word16* Gains, /* i : excitation gains Q_exc*/ + Word16* output, /* o : excitation output */ + const Word16 gain_fac /* i : gain factor */ ); @@ -6304,54 +6293,54 @@ Word32 find_remd( ); void set_ppp_mode_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *coder_type /* i : coding type */ - ,const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ - const Word16 localVAD, - const Word16 localVAD_he, /* i : HE-SAD flag without hangover */ - Word16 *vad_flag - ,Word16 T_op_fx[] /* i : open loop pitch lag */ - ,Word16 sp_aud_decision1 /* i : Speech Audio Decision */ + const Word16 localVAD_he /* i : HE-SAD flag without hangover */ ); void update_average_rate_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ -); - - -void encod_ppp_fx( - Encoder_State_fx * st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech_fx[], /* i : input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *coder_type, /* i/o : coding type */ - Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing Q14*/ - Word16 *res_fx, /* i/o: residual signal Q_new*/ - Word16 *synth_fx, /* i/o: core synthesis Q-1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* o: current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ + SC_VBR_ENC_HANDLE hSC_VBR, /* i/o: SC-VBR state structure */ + const Word32 core_brate_fx /* i : core bitrate */ +); + +void sc_vbr_enc_init( + SC_VBR_ENC_HANDLE hSC_VBR /* i/o: SC-VBR encoder handle */ +); +ivas_error encod_ppp_fx( + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : i speech Q_new*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16* res_fx, /* i : residual signal Q_new*/ + Word16* synth_fx, /* o : core synthesis Q-1*/ + Word16* exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16* exc2_fx, /* o : current enhanced excitation Q0*/ + Word16* pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16* voice_factors, /* o : voicing factors */ + Word16* bwe_exc, /* o : excitation for SWB TBE */ Word16 Q_new, Word16 shift ); -void ppp_voiced_encoder_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *in_fx, /* i : residual signal */ - Word16 *out_fx, /* o : Quantized residual signal */ - Word16 delay_fx, /* i : open loop pitch */ - Word16 *lpc1_fx, /* i : prev frame de-emphasized LPC */ - Word16* lpc2_fx, /* i : current frame de-emphasized LPC */ - Word16 *exc_fx, /* i: previous frame quantized excitation */ - Word16 *pitch_fx, /* o: floating pitch values for each subframe */ - Word16 vadsnr_fx, /* i: current frame SNR Q7*/ +void LPDmem_enc_init( + LPD_state_HANDLE hLPDmem /* i/o: LP memories */ +); + +ivas_error ppp_voiced_encoder_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + SC_VBR_ENC_HANDLE hSC_VBR, + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 last_coder_type_raw, /* i : raw last_coder_type */ + const Word16 old_pitch_buf[], /* i : buffer of old subframe pitch values */ + Word16* in_fx, /* i : residual signal */ + Word16* out_fx, /* o : Quantized residual signal */ + Word16 delay_fx, /* i : open loop pitch */ + Word16* lpc1_fx, /* i : prev frame de-emphasized LPC */ + Word16* lpc2_fx, /* i : current frame de-emphasized LPC */ + Word16* exc_fx, /* i: previous frame quantized excitation */ + Word16* pitch_fx, /* o: floating pitch values for each subframe */ Word16 Qres ); @@ -6361,7 +6350,6 @@ Word16 rint_new_fx( void decod_nelp_fx( Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 coder_type, /* i : coding type */ Word16 *tmp_noise_fx, /* o : long term temporary noise energy */ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ Word16 *exc_fx, /* o : adapt. excitation exc */ @@ -6383,7 +6371,7 @@ void nelp_decoder_fx( , Word16 *gain_buf /*Q14*/ ); -void core_switching_pre_dec_fx( +ivas_error core_switching_pre_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ const Word16 output_frame /* i : frame length */ ); @@ -6394,24 +6382,34 @@ void fb_tbe_reset_synth_fx( Word16 *prev_fbbwe_ratio_fx ); -void core_switching_post_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth */ - const Word16 output_frame, /* i : frame length */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ - const Word16 coder_type, /* i : ACELP coder type */ - Word16 *Qsynth +ivas_error core_switching_post_dec_fx( + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + Word16* synth, /* i/o: output synthesis Qsynth */ +#ifdef IVAS_CODE_SWITCHING + float* output, /* i/o: LB synth/upsampled LB synth */ + float output_mem[], /* i : OLA memory from last TCX/HQ frame */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ +#endif + const Word16 output_frame, /* i : frame length */ + const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ +#ifdef IVAS_CODE_SWITCHING + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 nchan_out, /* i : number of output channels */ +#endif + const Word16 last_element_mode, /* i : element mode of previous frame */ + Word16* Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ ); -void acelp_core_switch_dec_bfi_fx( +ivas_error acelp_core_switch_dec_bfi_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 synth_out[], /* o : synthesis Q_syn */ const Word16 coder_type /* i : coder type */ ); -void acelp_core_switch_dec_fx( +ivas_error acelp_core_switch_dec_fx( Decoder_State_fx *st_fx, /* decoder state structure */ Word16 *synth_subfr_out, /* o synthesized ACELP subframe Q_syn*/ Word16 *tmp_synth_bwe, /* o synthesized ACELP subframe BWE Q_syn*/ - const Word16 output_frame, /* i : input frame legth */ + const Word16 output_frame, /* i : i frame legth */ const Word16 core_switching_flag, /* i : core switching flag */ Word16 *mem_synth, /* o : synthesis to overlap */ Word16 *Q_syn @@ -6443,13 +6441,10 @@ void core_switching_OLA_fx( ); void acelp_core_switch_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, - const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ - const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ - const Word16 T_op_orig[2], /* i : open-loop pitch values for quantiz. Q0*/ - const Word16 voicing[3], /* i : Open-loop pitch gains Q15 */ - const Word16 A[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes Q12*/ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word16 inp12k8[], /* i : i signal @12.8 kHz Q0 */ + const Word16 inp16k[], /* i : i signal @16 kHz Q0 */ + const Word16 A[NB_SUBFR16k * (M + 1)], /* i : A(z) unquantized for the 4 subframes Q12*/ Word16 shift, Word16 Q_new ); @@ -6463,18 +6458,17 @@ void core_switching_hq_prepare_enc_fx( ); void core_switching_pre_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */ - const Word16 *old_inp_16k /* i : old input signal @16kHz */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + const Word16* old_inp_12k8, /* i : old i signal @12.8kHz */ + const Word16* old_inp_16k, /* i : old i signal @16kHz */ + const Word16 active_cnt, /* i : active frame counter */ + const Word16 last_element_mode /* i : last_element_mode */ ); void core_switching_post_enc_fx( /*done */ Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : input signal @12.8 kHz */ - const Word16 inp16k[], /* i : input signal @16 kHz */ - const Word16 T_op[2], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : Open-loop pitch gains */ + const Word16 inp12k8[], /* i : i signal @12.8 kHz */ + const Word16 inp16k[], /* i : i signal @16 kHz */ const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ Word16 Qshift, Word16 Q_new, @@ -6484,8 +6478,8 @@ void core_switching_post_enc_fx( /*done */ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ - const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ - const Word32 fin, /* i : frequency of input */ + const Word16 lg, /* i : length of i (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ + const Word32 fin, /* i : frequency of i */ Word16 sigOut[], /* o : decimated signal */ const Word32 fout, /* i : frequency of output */ Word16 *delayout /* o : delay of output */ @@ -6558,23 +6552,22 @@ Word16 Invert16( /* result in Q'15 + 'exp' */ Word16 *exp); void swb_bwe_enc_hr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *new_input_fx, /* i : input signal */ - Word16 new_input_fx_exp, /* i : Exponent of input signal */ - const Word16 input_frame, /* i : frame length */ - const Word16 coder_type, /* i : coding type */ - const Word16 unbits /* i : number of core unused bits */ + Encoder_State_fx* st_fx, /* i/o: encoder state structure */ + Word16* new_input_fx, /* i : i signal */ + Word16 new_input_fx_exp, /* i : Exponent of i signal */ + const Word16 input_frame, /* i : frame length */ + const Word16 unbits /* i : number of core unused bits */ ); void wtda_fx( - Word16 *new_audio, /* i : input audio Q0 */ - Word16 *Q, /* i/o : Q of Output Audio (use 15 for 'qout' for backward compatibility - NON SWB ENC HR FX MODULES) */ - Word32 *wtda_audio, /* o : windowed audio Qout */ - Word16 *old_wtda, /* i/o: windowed audio from previous frame Qout */ - Word16 *Qold_wtda, - Word16 left_mode, - Word16 right_mode, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - const Word16 L + Word16* new_audio, /* i : i audio Q0 */ + Word16* Q, /* i/o : Q of i /Output Audio */ + Word32* wtda_audio, /* o : windowed audio Qout */ + Word16* old_wtda, /* i/o: windowed audio from previous frame Qout */ + Word16* Qold_wtda, + const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const Word16 L /* i : length */ ); void direct_transform_fx( @@ -6582,38 +6575,37 @@ void direct_transform_fx( Word32 out32_fx[], const Word16 is_transient, const Word16 L, - Word16 *Q + Word16 *Q, + const Word16 element_mode ); void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign); -DTFS_STRUCTURE_FX* DTFS_new_fx( - void -); +ivas_error DTFS_new_fx(DTFS_STRUCTURE_FX** dtfs_out); void DTFS_copy_fx( DTFS_STRUCTURE_FX *Xout_fx, /* o: DTFS structure */ DTFS_STRUCTURE_FX Xinp_fx /* i: DTFS structure */ ); -DTFS_STRUCTURE_FX DTFS_sub_fx( - DTFS_STRUCTURE_FX X1, /* i: DTFS input 1 */ - DTFS_STRUCTURE_FX X2 /* i: DTFS input 2 */ -); /* o: X1 - X2 */ +void DTFS_sub_fx( + DTFS_STRUCTURE_FX* tmp,/* o: X1 - X2 */ + DTFS_STRUCTURE_FX X1, /* i: DTFS i 1 */ + DTFS_STRUCTURE_FX X2 /* i: DTFS i 2 */ +); void DTFS_to_fs_fx( - const Word16 *x, /* i : time domain signal */ - Word16 N, /* i : Length of input vector */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure with a, b, lag */ - Word16 Fs, /* i : sampling rate */ - Word16 FR_flag, /* i: FR flag */ - Word16 *S_fx, - Word16 *C_fx + const Word16* x, /* i : time domain signal */ + Word16 N, /* i : Length of i vector */ + DTFS_STRUCTURE_FX* X_fx, /* o : DTFS structure with a, b, lag */ + const Word16 Fs, /* i : sampling rate */ + const Word16 FR_flag, /* i : FR flag */ + Word16* S_fx, + Word16* C_fx ); -void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE_FX *This,Word16 *out_fx, Word16 N_fx, Word16 LOG2N); void DTFS_car2pol_fx( DTFS_STRUCTURE_FX *X_fx /* i/o : DTFS structure a, b, lag */ @@ -6624,8 +6616,8 @@ Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE_FX *X_fx,Word16 lband, Word16 hban Word16 *cos_tab); Word32 DTFS_setEngyHarm_fx( - Word16 f1_fx, /* i : lower band freq of input to control energy */ - Word16 f2_fx, /* i : upper band freq of input to control energy */ + Word16 f1_fx, /* i : lower band freq of i to control energy */ + Word16 f2_fx, /* i : upper band freq of i to control energy */ Word16 g1_fx, /* i : lower band freq of output to control energy */ Word16 g2_fx, /* i : upper band freq of output to control energy */ Word32 en2_fx, /* i : Target Energy to set the DTFS to */ @@ -6641,7 +6633,7 @@ void quant_target_fx( DTFS_STRUCTURE_FX *X_fx,const Word16 *curr_lpc, Word16 *w, void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab); void DTFS_to_erb_fx( - const DTFS_STRUCTURE_FX X_fx, /* i : DTFS input */ + const DTFS_STRUCTURE_FX X_fx, /* i : DTFS i */ Word16 *out_fx /* o : ERB output */ ); @@ -6652,11 +6644,6 @@ Word32 DTFS_getEngy_fx( DTFS_STRUCTURE_FX *X_fx); Word32 DTFS_getEngy_P2A_fx( DTFS_STRUCTURE_FX *X_fx); -Word32 DTFS_getEngy_band_fx( - DTFS_STRUCTURE_FX X_fx, - Word16 lband, - Word16 hband -); Word32 DTFS_getEngy_band_wb_fx( DTFS_STRUCTURE_FX X_fx, @@ -6664,15 +6651,6 @@ Word32 DTFS_getEngy_band_wb_fx( Word16 hband ); -Word32 DTFS_freq_corr_fx( - DTFS_STRUCTURE_FX X1_DTFS_fx, /* i : X1 DTFS */ - DTFS_STRUCTURE_FX X2_DTFS_fx, /* i : X2 DTFS */ - Word16 lband, /* i : low cutoff */ - Word16 hband, /* i : high cutoff */ - Word16 *Qout /* o : Correlation Q format */ -); /* o : Correlation */ - -Word32 DTFS_setEngy_fx( DTFS_STRUCTURE_FX *X_DTFS_FX,Word32 en2_fx); void DTFS_adjustLag_fx( DTFS_STRUCTURE_FX *X_DTFS_FX, /* i/o : DTFS to adjust lag for */ @@ -6700,25 +6678,6 @@ Word16 DTFS_alignment_full_fx( , Word16 FR_flag ); -Word16 DTFS_alignment_extract_td_fx(Word16 *x1, Word16 *x2, Word16 lag); - -Word16 DTFS_alignment_weight_fx( - DTFS_STRUCTURE_FX *X_fx, - DTFS_STRUCTURE_FX X2, - Word16 Eshift, - const Word16 *LPC1, - const Word16 *LPC2, - Word16 *S_fx, - Word16 *C_fx, - Word16 *pf_temp1, - Word16 *pf_temp2, - Word16 *pf_temp, - Word16 *pf_n2 -); - - -Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE_FX X1_fx, DTFS_STRUCTURE_FX X2_fx, Word16 *S_fx, Word16 *C_fx); - void DTFS_phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx); void Q2phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx); @@ -6741,50 +6700,13 @@ void erb_add_fx( Word16 num_erb_fx /* i : number of ERBs */ ); -void LPCPowSpect_fx(Word16 *freq, Word16 Nf, Word16 *LPC, Word16 Np, - Word16 *out); - void erb_slot_fx( - Word16 lag_fx, /* i : input lag */ + Word16 lag_fx, /* i : i lag */ Word16 *out_fx, /* o : ERB slots */ Word16 *mfreq_fx, /* i : ERB frequencies */ Word16 num_erb_fx /* i : number of ERBs */ ); -Word16 DTFS_quant_cw_fx( - DTFS_STRUCTURE_FX *X_fx, /* i/o: DTFS unquant inp, quant out */ - Word16 pl, /* i : Previous lag */ - const Word16 *curr_lpc_fx, /* i : LPC */ - Word16 *POWER_IDX, /* o : Power index */ - Word16 *AMP_IDX, /* o : Amplitude index */ - Word16 *lastLgainE_fx, /* i/o: last frame lowband gain */ - Word16 *lastHgainE_fx, /* i/o: last frame highband gain */ - Word16 *lasterbE_fx, /* i/o: last frame ERB vector */ - Word16 *sin_tab, - Word16 *cos_tab -); - - -void DTFS_dequant_cw_fx( - Word16 pl_fx, /* i : Previous lag */ - Word16 POWER_IDX_fx, /* i : POWER index */ - const Word16 *AMP_IDX_fx, /* i : Amp Shape index */ - Word16 *lastLgainD_fx, /* i/o: low band last gain */ - Word16 *lastHgainD_fx, /* i/o: high band last gain */ - Word16 *lasterbD_fx, /* i/o: last frame ERB vector */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure dequantized */ - Word16 num_erb_fx -); - -void DTFS_transform_fx( - DTFS_STRUCTURE_FX X_fx, /* i : Starting DTFS to use in WI */ - DTFS_STRUCTURE_FX X2_fx, /* i : Ending DTFS to use in WI */ - const Word32 *phase_fx, /* i : Phase contour */ - Word16 *out_fx, /* o : Output time domain waveform */ - Word16 N, /* i : Number of samples to generate */ - Word16 FR_flag /* i : Flag to indicate called in FR context */ -); - void DTFS_peaktoaverage_fx( DTFS_STRUCTURE_FX X_fx, /* i : DTFS */ Word32 *pos_fx, /* o : positive peak to ave */ @@ -6796,7 +6718,7 @@ void DTFS_peaktoaverage_fx( Word16 ppp_extract_pitch_period_fx( - const Word16 *in, /* i : input residual */ + const Word16 *in, /* i : i residual */ Word16 *out, /* o : output residual */ Word16 l, /* i : lag */ Word16 *out_of_bound, /* o : out of bound flag */ @@ -6813,45 +6735,45 @@ void Interpol_delay_fx( ); -Word16 ppp_quarter_encoder_fx( - DTFS_STRUCTURE_FX *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ - DTFS_STRUCTURE_FX *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ - Word16 prevCW_lag, /* i : previous lag */ - DTFS_STRUCTURE_FX CURRCW_NQ_FX, /* i : Unquantized DTFS */ - const Word16 *curr_lpc_fx, /* i : LPCS */ - Word16 *lastLgainE_fx, /* i/o: last low band gain */ - Word16 *lastHgainE_fx, /* i/o: last high band gain */ - Word16 *lasterbE_fx, /* i/o: last ERB vector */ - DTFS_STRUCTURE_FX PREV_CW_E_FX, /* i : past DTFS */ - Word16 *S_fx, /* i : sin table, Q15 */ - Word16 *C_fx, /* i : cos table, Q15 */ - Encoder_State_fx *st_fx -); - - -void WIsyn_fx( - DTFS_STRUCTURE_FX PREVCW_FX, - DTFS_STRUCTURE_FX *CURR_CW_DTFS_FX, - const Word16 *curr_lpc_fx, - Word16 *ph_offset_fx, - Word16 *out_fx, - Word16 N, - Word16 FR_flag, /* i : called for post-smoothing in FR */ - Word16 *S_fx, +ivas_error ppp_quarter_encoder_fx( + Word16* returnFlag, /* o : return value */ + DTFS_STRUCTURE_FX* CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ + DTFS_STRUCTURE_FX* TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ + Word16 prevCW_lag, /* i : previous lag */ + DTFS_STRUCTURE_FX vCURRCW_NQ_FX, /* i : Unquantized DTFS */ + const Word16* curr_lpc_fx, /* i : LPCS */ + Word16* lastLgainE_fx, /* i/o: last low band gain */ + Word16* lastHgainE_fx, /* i/o: last high band gain */ + Word16* lasterbE_fx, /* i/o: last ERB vector */ + DTFS_STRUCTURE_FX PREV_CW_E_FX, /* i : past DTFS */ + Word16* S_fx, /* i : sin table, Q15 */ + Word16* C_fx, /* i : cos table, Q15 */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ +); + + +ivas_error WIsyn_fx( + DTFS_STRUCTURE_FX PREVCW_FX, /* i : Prev frame DTFS */ + DTFS_STRUCTURE_FX* CURR_CW_DTFS_FX, /* i/o: Curr frame DTFS */ + const Word16* curr_lpc_fx, /* i : LPC */ + Word16* ph_offset_fx, /* i/o: Phase offset to line up at end of frame */ + Word16* out_fx, /* o : Waveform Interpolated time domain signal */ + const Word16 N, /* i : Number of output samples to generate */ + const Word16 FR_flag, /* i : called for post-smoothing in FR */ + Word16* S_fx, Word16* C_fx, - Word16 *pf_temp1, - Word16 *pf_temp2, - Word16 *pf_temp, - Word16 *pf_n2 + Word16* pf_temp1, + Word16* pf_temp2, + Word16* pf_temp, + Word16* pf_n2 ); void deemph_lpc_fx( - Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ - Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ - Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame */ - Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame */ - Word16 deemph_old - + const Word16* p_Aq_curr_fx, /* i : LP coefficients current frame */ + const Word16* p_Aq_old_fx, /* i : LP coefficients previous frame */ + Word16* LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ + Word16* LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ + const Word16 deemph_old ); Word16 erb_diff_search_fx(Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_erb, @@ -6866,7 +6788,8 @@ void Acelp_dec_total_exc( const Word16 gain_code16, /* i : Gain code Q0 */ const Word16 gain_pit_fx, /* i ; Pitch gain in Q14 */ const Word16 i_subfr, /* i ; subfr */ - const Word16 *code_fx /* i : code in Q12 */ + const Word16 *code_fx, /* i : code in Q12 */ + const Word16 L_subfr /* i : Subframne lenght */ ); void tbe_celp_exc( const Word16 L_frame_fx, /* i : Frame lenght */ @@ -6883,7 +6806,6 @@ Word16 tbe_celp_exc_offset( ); void lsf_syn_mem_backup_fx( Encoder_State_fx *st_fx, /* i: state structure */ - LPD_state* LPDmem, /* i: LPD state memory structure */ Word16 *btilt_code, /* i: tilt code */ Word32 *bgc_threshold, /* i: */ Word16 *clip_var_bck, /* o: */ @@ -6906,7 +6828,7 @@ void lsf_syn_mem_backup_fx( Word16 *pstreaklen ); -void decod_ppp_fx( +ivas_error decod_ppp_fx( Decoder_State_fx *st_fx, /* i/o: state structure */ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ @@ -6918,7 +6840,7 @@ void decod_ppp_fx( Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ ); -void ppp_quarter_decoder_fx( +ivas_error ppp_quarter_decoder_fx( DTFS_STRUCTURE_FX *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ Word16 prevCW_lag_fx, /* i : Previous lag */ Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ @@ -6931,8 +6853,7 @@ void ppp_quarter_decoder_fx( ,Decoder_State_fx *st ); - -void ppp_voiced_decoder_fx( +ivas_error ppp_voiced_decoder_fx( Decoder_State_fx *st_fx, /* i/o: state structure */ Word16 *out_fx, /* o : residual signal */ const Word16 *lpc2_fx, /* i : current frame LPC */ @@ -6957,9 +6878,11 @@ void updt_bw_switching_fx( const Word16 Qpost ); void updt_dec_common_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 *synth /* i : decoded synthesis */ + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + Word16 hq_core_type_fx, /* i : HQ core type */ + const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ + const Word16* synth, /* i : decoded synthesis */ + const Word16 Qpostd /* i : Synthesis Q value */ ); void sort_32_fx( @@ -7022,33 +6945,23 @@ void hq_timedomain_conc_fx( Word16 ratio(const Word32, const Word32, Word16 *); -void nearProjQ15_fx( - Word16 x, - Word16 *result -); - -void Ratio_rQ3_fx( - Word16 opp, - Word16 near, - Word16 *result -); void densityAngle2RmsProjDec_fx( - Word16 D, /* i: density */ - Word16 indexphi, /* i: decoded index from AR dec */ - Word16 *oppQ15, /* o: proj*/ - Word16 *nearQ15, /* o: */ - Word16 *oppRatioQ3 /* o: */ -) ; + const Word16 D, /* i : density */ + const Word16 indexphi, /* i : decoded index from AR dec */ + Word16* oppQ15, /* o : opposite */ + Word16* nearQ15, /* o : near */ + Word16* oppRatioQ3 /* o : ratio */ +); -void densityAngle2RmsProjEnc_fx ( - Word16 D, - Word16 phiQ14uq, - Word16 *indexphi, /* o: index to send to AR */ - Word16 *oppQ15, /* o: proj*/ - Word16 *nearQ15, - Word16 *oppRatioQ3 -) ; +void densityAngle2RmsProjEnc_fx( + const Word16 D, /* i : density */ + const Word16 phiQ14uq, /* i : angle */ + Word16* indexphi, /* o : index */ + Word16* oppQ15, /* o : opposite */ + Word16* nearQ15, /* o : near */ + Word16* oppRatioQ3 /* o : ratio */ +); void dsDiracPerQuanta_fx( const Word16 td, const Word16 t_quanta, @@ -7058,10 +6971,10 @@ void dsDiracPerQuanta_fx( ); void QuantaPerDsDirac_fx( - Word16 td, - Word16 dsDiracIndex, - const unsigned char* const* dimFrQuanta, - Word16 *Quanta + const Word16 td, /* i : Length of vector segment */ + const Word16 dsDiracIndex, /* i : Quanta table index */ + const unsigned char* const* dimFrQuanta, /* i : Quanta lookup table */ + Word16* Quanta /* i : Quanta */ ); void obtainEnergyQuantizerDensity_fx( @@ -7105,7 +7018,7 @@ void IGFEncApplyMono(const IGF_ENC_INSTANCE_HANDLE hInstance, Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ Word16 PowerSpectrum_e, /**< in: | exponent of pPowerSpectrum */ - Word16 isTCX20, /**< in: Q0 | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + Word16 isTCX20, /**< in: Q0 | flag indicating if the i is TCX20 or TCX10/2xTCX5 */ Word16 isTNSActive, /**< in: Q0 | flag indicating if the TNS is active */ Word16 last_core_acelp /**< in: Q0 | indictaor if last frame was acelp coded */ ); @@ -7120,16 +7033,17 @@ void IGFEncConcatenateBitstream(const IGF_ENC_INSTANCE_HANDLE hInstance, void IGFEncResetTCX10BitCounter(const IGF_ENC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Encoder */ ); -void IGFEncSetMode(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word32 bitRate, /**< in: Q0 | encoder bitrate */ - const Word16 mode /**< in: Q0 | encoder bandwidth mode */ - , const Word16 rf_mode /**< in: | flag to signal the RF mode */ - - ); +void IGFEncSetMode( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ + const Word32 total_brate, /* i : encoder total bitrate */ + const Word16 bwidth, /* i : encoder audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +); Word16 IGFEncWriteBitstream( /**< out: | number of bits written per frame */ const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ @@ -7137,8 +7051,8 @@ Word16 IGFEncWriteBitstream( Word16 IGFEncWriteConcatenatedBitstream( /**< out: Q0 | total number of bits written */ const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - void *st /**< in: | encoder state */ -); + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ + ); /* IGFDec.c */ void IGFDecApplyMono(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ @@ -7170,14 +7084,18 @@ void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, const Word16 subFrameIdx /**< in: Q0 | index of subframe */ ); -void IGFDecSetMode(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 bitRate, /**< in: Q0 | bitrate */ - const Word16 mode, /**< in: Q0 | bandwidth mode */ - const Word16 defaultStartLine, /**< in: Q0 | default start subband index */ - const Word16 defaultStopLine /**< in: Q0 | default stop subband index */ - , const Word16 rf_mode /**< in: | flag to signal the RF mode */ - ); - +void IGFDecSetMode( + const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ + const Word32 total_brate, /* i : bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 defaultStartLine, /* i : default start subband index */ + const Word16 defaultStopLine, /* i : default stop subband index */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +); +void init_igf_dec( + IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ +); void IGFDecStoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ const Word16 subFrameIdx /**< in: Q0 | index of subframe */ ); @@ -7196,26 +7114,28 @@ void IGFCommonFuncsCalcSfbEnergyPowerSpec(const Word16 startSfb, Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ ); -Word16 IGFCommonFuncsIGFConfiguration( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - H_IGF_INFO hIGFInfo /**< out: | IGF info handle */ - ,Word16 rf_mode /**< in: flag to signal the RF mode */ -); - -Word16 IGFCommonFuncsIGFGetCFTables( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - Word16 rf_mode, /**< in: | flag to signal the RF mode */ - const Word16 **cf_se00, /**< out: | CF table for t == 0 and f == 0 */ - const Word16 **cf_se01, /**< out: | CF table for t == 0 and f == 1 */ - Word16 *cf_off_se01, /**< out: | offset for CF table above */ - const Word16 **cf_se02, /**< out: | CF tables for t == 0 and f >= 2 */ - const Word16 **cf_off_se02, /**< out: | offsets for CF tables above */ - const Word16 **cf_se10, /**< out: | CF table for t == 1 and f == 0 */ - Word16 *cf_off_se10, /**< out: | offset for CF table above */ - const Word16 **cf_se11, /**< out: | CF tables for t == 1 and f >= 1 */ - const Word16 **cf_off_se11 /**< out: | offsets for CF tables above */ +Word16 IGFCommonFuncsIGFConfiguration( + const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + H_IGF_INFO hIGFInfo, /* o : IGF info handle */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +); + +Word16 IGFCommonFuncsIGFGetCFTables( + const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : element mode */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const Word16** cf_se00, /* o : CF table for t == 0 and f == 0 */ + const Word16** cf_se01, /* o : CF table for t == 0 and f == 1 */ + Word16* cf_off_se01, /* o : offset for CF table above */ + const Word16** cf_se02, /* o : CF tables for t == 0 and f >= 2 */ + const Word16** cf_off_se02, /* o : offsets for CF tables above */ + const Word16** cf_se10, /* o : CF table for t == 1 and f == 0 */ + Word16* cf_off_se10, /* o : offset for CF table above */ + const Word16** cf_se11, /* o : CF tables for t == 1 and f >= 1 */ + const Word16** cf_off_se11 /* o : offsets for CF tables above */ ); void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ @@ -7227,18 +7147,20 @@ void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, Word16 indexOffset /**< in: Q0 | index offset */ ); -void IGFCommonFuncsWriteSerialBit(void *st, /**< in: | encoder/decoder state structure */ - Word16 *pBitOffset, /**< out: Q0 | bit offset */ - Word16 bit /**< in: Q0 | value of bit */ - ); +void IGFCommonFuncsWriteSerialBit( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16* pBitOffset, /**< out: Q0 | bit offset */ + Word16 bit /**< in: Q0 | value of bit */ + ); /* IGFSCFEncoder.c */ void IGFSCFEncoderOpen( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - , Word16 rf_mode /**< in: flag to signal the RF mode */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + H_IGF_INFO hIgfInfo, /* i : IGF info handle */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); void IGFSCFEncoderReset( @@ -7246,29 +7168,32 @@ void IGFSCFEncoderReset( ); Word16 IGFSCFEncoderEncode( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Encoder_State_fx *st, /* i/o: pointer to encoder state */ - Word16 bitCount, /* i: offset to the first bit in bitbuffer which should be written by the raw AC functions */ - Word16 *sfe, /* i: pointer to an array which contains the quantized SCF energies to be encoded */ - Word16 indepFlag, /* i: 1 if the block is an independent block, 0 otherwise */ - Word16 doRealEncoding /* i: whether the real encoding is needed, otherwise only the number of bits is used */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + Word16* sfe, /* i : ptr to an array which contain quantized scalefactor energies */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); void IGFSCFEncoderSaveContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ); void IGFSCFEncoderRestoreContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ); /* IGFSCFDecoder.c */ void IGFSCFDecoderOpen( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - ,Word16 rf_mode + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data */ + H_IGF_INFO hIgfInfo, /* i : IGF info handle */ + const Word32 total_brate, + const Word16 bwidth, + const Word16 element_mode, + const Word16 rf_mode ); void IGFSCFDecoderReset( @@ -7276,17 +7201,19 @@ void IGFSCFDecoderReset( ); void IGFSCFDecoderDecode( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Decoder_State_fx *st, /* i/o: pointer to decoder state */ - Word16 *sfe, /* o: pointer to an array which will contain the decoded quantized SCFs */ - Word16 indepFlag /* i: 1 if the block is an independent block, 0 otherwise */ + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ + Decoder_State_fx* st, /* i/o: pointer to decoder state */ + int16_t* sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, + if 0 on input the decoder will be forced to encode without a reset */ ); Word32 SFM_Cal(Word32 magn[], Word16 n); void Unified_weighting_fx( - Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ + const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, const Word16 lsf_fx[], /* i : LSF vector x2.56 */ Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ @@ -7297,34 +7224,31 @@ void Unified_weighting_fx( ); void lsf_dec_bfi( - const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ - Word16*lsf, /*!< o : 14Q1*1.28 quantized ISFs */ - const Word16*lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ - Word16*lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ - const Word16 lsfBase[], /* i : base for differential lsf coding */ - Word16*mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16*mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ + const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ + Word16* lsf, /*!< o : 14Q1*1.28 quantized ISFs */ + const Word16* lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ + Word16* lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ + const Word16 lsfBase[], /* i : base for differential lsf coding */ + Word16* mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ + Word16* mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ - const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ + const Word16 last_coder_type,/*!< i : coding type in last good received fr. */ Word16 L_frame, - const Word16 last_good, /*!< i : last good received frame */ - const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ - Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ + const Word16 last_good, /*!< i : last good received frame */ + const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ + const Word8 plcBackgroundNoiseUpdated, /* i : background noise already updated?*/ + Word16* lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ + Word16* lsf_cng, + Word16* old_lsf_q_cng, /* o : old quantized ISFs for background noise */ const Word16 Last_GSC_pit_band_idx, - const Word16 Opt_AMR_WB, /* i : IO flag */ - const Word8 tcxonly - ,const short MODE1_bwidth /* i: coded bandwidth */ + const Word16 Opt_AMR_WB, /* i : IO flag */ + const Word8 tcxonly, + const short bwidth /* i: coded bandwidth */ ); void lpc_quantization( - Encoder_State_fx * st, - const Word16 core, - const Word16 lpcQuantization, - const Word16 lsfold_q[], + Encoder_State_fx* st, const Word16 lsp[], const Word16 lspmid[], Word16 lsp_q[], @@ -7332,18 +7256,12 @@ void lpc_quantization( Word16 lspmid_q[], Word16 lspq_ind[], Word16 clip_var[], - Word16 mem_MA[], - Word16 mem_AR[], - const Word8 narrowBand, const Word16 coder_type, const Word8 acelp_midLpc, Word16 param_lpc[], Word16 nbits_lpc[], - Word16 * bits_param_lpc, - Word16 *no_param_lpc, - Word16 *seed_acelp, - Word32 * Bin_Ener_fx, - Word32 * Bin_Ener_old_fx, + Word16* bits_param_lpc, + Word16* no_param_lpc, const Word16 Q_ener ); @@ -7468,35 +7386,35 @@ void E_LPC_a_weight_inv(const Word16 *a, Word16 *ap, const Word16 gamma, const W void E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma, Word16 m); void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep); void E_LPC_a_lsp_conversion( - const Word16 *a, /* input : LP filter coefficients */ - Word16 *lsp, /* output: Line spectral pairs (in the cosine domain) */ - const Word16 *old_lsp, /* input : LSP vector from past frame */ - const Word16 m /* input : LPC order */ + const Word16 *a, /* i : LP filter coefficients */ + Word16 *lsp, /* o : Line spectral pairs (in the cosine domain) */ + const Word16 *old_lsp, /* i : LSP vector from past frame */ + const Word16 m /* i : LPC order */ ); void E_LPC_lsp_lsf_conversion( - const Word16 lsp[], /* input: lsp[m] (range: -1<=val<1) */ + const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) */ Word16 lsf[], /* output : lsf[m] normalized (range: 0<=val<=6400) */ - const Word16 m /* input : LPC order */ + const Word16 m /* i : LPC order */ ); void E_LPC_lsf_lsp_conversion( - const Word16 lsf[], /* input : lsf[m] normalized (range: 0<=val<=6400) */ - Word16 lsp[], /* output: lsp[m] (range: -1<=val<1) */ - const Word16 m /* input : LPC order */ + const Word16 lsf[], /* i : lsf[m] normalized (range: 0<=val<=6400) */ + Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) */ + const Word16 m /* i : LPC order */ ); void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); void E_LPC_a_isp_conversion( - const Word16 *a, /* input : LP filter coefficients */ - Word16 *isp, /* output: Line spectral pairs (in the cosine domain) */ - const Word16 *old_isp,/* input : LSP vector from past frame */ - const Word16 m /* input : LPC order */ + const Word16 *a, /* i : LP filter coefficients */ + Word16 *isp, /* o : Line spectral pairs (in the cosine domain) */ + const Word16 *old_isp,/* i : LSP vector from past frame */ + const Word16 m /* i : LPC order */ ); void E_LPC_isp_isf_conversion(const Word16 isp[], Word16 isf[], const Word16 m); void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); -void E_LPC_int_lpc_tcx(const Word16 lsp_old[], /* input : LSPs from past frame (1Q14) */ - const Word16 lsp_new[], /* input : LSPs from present frame (1Q14) */ - Word16 a[] /* output: interpolated LP coefficients (4Q11) */ +void E_LPC_int_lpc_tcx(const Word16 lsp_old[], /* i : LSPs from past frame (1Q14) */ + const Word16 lsp_new[], /* i : LSPs from present frame (1Q14) */ + Word16 a[] /* o : interpolated LP coefficients (4Q11) */ ); /* enc_gain.c */ @@ -7563,34 +7481,27 @@ void E_ACELP_adaptive_codebook( ); void E_ACELP_innovative_codebook( - Word16 *exc, /* i : pointer to the excitation frame */ - Word16 T0, /* i : integer pitch lag */ - Word16 T0_frac, /* i : fraction of lag */ - Word16 T0_res, /* i : pitch resolution */ - Word16 gain_pit, /* i : adaptive codebook gain */ - Word16 tilt_code, /* i : tilt factor */ - Word16 mode, /* i : innovative codebook mode */ - Word16 formant_enh, /* i : use formant enhancement Q15 */ - Word16 formant_tilt, /* i : use tilt of formant enhancement */ - const Word16 formant_enh_num, /* i : formant sharpening numerator weighting */ - const Word16 foramnt_enh_den, /* i : formant sharpening denominator weighting */ - Word16 pitch_sharpening,/* i : use pitch sharpening */ - Word16 pre_emphasis, - Word16 phase_scrambling, - Word16 i_subfr, /* i : subframe index */ - const Word16 *Aq, /* i : quantized LPC coefficients */ - Word16 *h1, /* i : impulse response of weighted synthesis filter */ - Word16 *xn, /* i : Close-loop Pitch search target vector */ - Word16 *cn, /* i : Innovative codebook search target vector */ - Word16 *y1, /* i : zero-memory filtered adaptive excitation */ - Word16 *y2, /* o : zero-memory filtered algebraic excitation */ - Word8 acelpautoc, /* i : autocorrelation mode enabled */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *code, /* o : innovative codebook Q9 */ - Word16 shift /* i : Scaling to get 12 bits */ - ,const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word32 total_brate /* i : total bit-rate */ + Word16* exc, /* i : pointer to the excitation frame Q_new */ + Word16 T0, /* i : integer pitch lag Q0 */ + Word16 T0_frac, /* i : fraction of lag Q0 */ + Word16 T0_res, /* i : pitch resolution Q0 */ + Word16 pitch_gain, /* i : adaptive codebook gain 1Q14 */ + Word16 tilt_code, /* i : tilt factor Q15 */ + ACELP_config* acelp_cfg,/* i/o: configuration of the ACELP */ + Word16 i_subfr, /* i : subframe index */ + const Word16* Aq, /* i : quantized LPC coefficients 3Q12 */ + Word16* h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ + Word16* xn, /* i : Close-loop Pitch search target vector Q_xn */ + Word16* cn, /* i : Innovative codebook search target vector Q_new */ + Word16* y1, /* i : zero-memory filtered adaptive excitation Q_xn */ + Word16* y2, /* o : zero-memory filtered algebraic excitation Q9 */ + Word8 acelpautoc, /* i : autocorrelation mode enabled */ + Word16** pt_indice, /* i/o: quantization indices pointer */ + Word16* code, /* o : innovative codebook Q9 Q9 */ + Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 last_L_frame,/* i : length of the last frame */ + const Word32 total_brate /* i : ttoal bit-rate */ ); Word16 E_ACELP_code43bit(const Word16 code[], UWord32 *ps, Word16 *p, UWord16 idxs[]); @@ -7632,18 +7543,18 @@ void fcb_pulse_track_joint_decode(UWord16 *idxs, Word16 wordcnt, UWord32 *index_ void lag_wind( Word16 r_h[], /* in/out: autocorrelations */ Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + Word16 m, /* i : order of LP filter */ + Word32 sr_core, /* i : sampling rate */ + Word16 strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ); void adapt_lag_wind( Word16 r_h[], /* in/out: autocorrelations */ Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - const Word16 Top, /* input : open loop pitch lag */ - const Word16 Tnc, /* input : open loop pitch gain */ - Word32 sr /* input : sampling rate */ + Word16 m, /* i : order of LP filter */ + const Word16 Top, /* i : open loop pitch lag */ + const Word16 Tnc, /* i : open loop pitch gain */ + Word32 sr_core /* i : sampling rate */ ); void hp20(Word16 signal[], /* i/o: signal to filter any */ @@ -7656,15 +7567,15 @@ void hp20(Word16 signal[], /* i/o: signal to filter any */ /* mem[3]: x[-1] << 16 */ /* Note: mem[0..3] need to be scaled per frame */ /* mem[4]: states scale */ - const Word32 sFreq); /* i : input sampling rate Q0 */ + const Word32 sFreq); /* i : i sampling rate Q0 */ /* pit_fr4.c */ void Mode2_pred_lt4(Word16 exc[], /* in/out: excitation buffer */ - Word16 T0, /* input : integer pitch lag */ - Word16 frac, /* input : fraction of lag */ - Word16 T0_res, /* input : pitch lag resolution */ - Word16 T0_res_max, /* input : maximum resolution */ - Word16 L_subfr); /* input : subframe size */ + Word16 T0, /* i : integer pitch lag */ + Word16 frac, /* i : fraction of lag */ + Word16 T0_res, /* i : pitch lag resolution */ + Word16 T0_res_max, /* i : maximum resolution */ + Word16 L_subfr); /* i : subframe size */ #define mvr2r_Word32(x,y,n) Copy32(x,y,n) @@ -7672,39 +7583,56 @@ void Mode2_pred_lt4(Word16 exc[], /* in/out: excitation buffer */ #define vr_intset(val, vector, count) { Word16 i; FOR(i=0; i<(count); i++) { vector[i]=val; } } float mean( /* o : the mean of the elements of the vector */ - const float *vec, /* i : input vector */ - const short lvec /* i : length of input vector */ + const float *vec, /* i : i vector */ + const short lvec /* i : length of i vector */ ); /* window.c */ void ham_cos_window(Word16 *fh, const Word16 n1, const Word16 n2); +Word16 cng_energy( + const Word16 element_mode, /* i : element mode */ + const Word16 bwidth, /* i : audio bandwidh */ + const Word16 CNG_mode, /* i : mode for DTX configuration */ + const Word16 CNG_att, /* i : attenuation factor for CNG */ + const Word16* exc, /* i : i signal */ + const Word16 len, /* i : vector length */ + const Word16 Q_new /* i : Input scaling */ +); /*---------------------------------------------------------------------* * main routines * *---------------------------------------------------------------------*/ -void init_coder_ace_plus( Encoder_State_fx* st,const Word16 shift); -void core_coder_reconfig( Encoder_State_fx *st); -void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, const Word32 bitrate, const Word16 shift); +void init_coder_ace_plus( + Encoder_State_fx* st, + const Word32 last_total_brate, /* i : last total bitrate */ + const Word16 shift, + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); +void core_coder_reconfig( + Encoder_State_fx* st, + const Word32 last_total_brate +); +void core_coder_mode_switch( + Encoder_State_fx* st, + const Word32 last_total_bitrate, + const Word16 is_mct, + const Word16 shift +); void enc_acelp_tcx_main( - const Word16 new_samples[], /* i : new samples */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: FD CNG handle */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[], /* o : floating pitch for each subframe */ - Word16 vad_hover_flag, - const Word16 vad_flag_dtx, - Word16 *Q_new, - Word16 *shift + const Word16 new_samples[], /* i : new samples */ + Encoder_State_fx* st, /* i/o: encoder state structure */ + Word16 Aw[NB_SUBFR16k * (M + 1)], /* i : weighted A(z) unquant. for subframes*/ + const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ + const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16* voice_factors, /* o : voicing factors */ + Word16 pitch_buf[], /* o : floating pitch for each subframe */ + Word16 vad_hover_flag, /* i : VAD hangover flag */ + Word16* Q_new, + Word16* shift ); /*-----------------------------------------------------------------* @@ -7735,8 +7663,6 @@ void get_subframe_pitch( void core_encode_openloop( Encoder_State_fx *st, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ const Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ const Word16 *lsp_new, /* i : LSPs at the end of the frame */ const Word16 *lsp_mid, /* i : LSPs at the middle of the frame */ @@ -7751,10 +7677,7 @@ void core_encode_openloop( void core_acelp_tcx20_switching( Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 vad_flag, - Word16 sp_aud_decision0, Word16 non_staX, - Word16 *pitch, /* i : open-loop pitch values for quantiz. */ Word16 *pitch_fr, /* i/o: fraction pitch values */ Word16 *voicing_fr, /* i/o: fractional voicing values */ const Word16 currFlatness, /* i : flatness */ @@ -7765,18 +7688,21 @@ void core_acelp_tcx20_switching( ); void core_encode_twodiv( - const Word16 new_samples[], - Encoder_State_fx *st, - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - Word16 *Q_new, - Word16 *shift + const Word16 new_samples[], /* i : new samples */ + Encoder_State_fx* st, /* i/o: coder memory state */ + const Word16 coder_type, /* i : coding type */ + Word16 Aw[NB_SUBFR16k * (M + 1)], /* i : weighted A(z) unquant. for subframes*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + Word16* Q_new, + Word16* shift ); void core_encode_update( Encoder_State_fx *st); - +void updt_enc_common( + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16 Etot, /* i : total energy */ + const Word16 Q_new /* i : CUrrent frame scaling */ +); void core_encode_update_cng( Encoder_State_fx *st, Word16 *timeDomainBuffer, Word16 *A, @@ -7795,25 +7721,24 @@ void core_signal_analysis_enc(const Word16 *new_samples, /*syn */ Word8 fb /* i: fullband flag */ ); @@ -8549,14 +8494,20 @@ Word16 tcx_res_invQ_spec( ); void InitTnsConfigs( - Word32 nSampleRate, - Word16 L_frame, - STnsConfig tnsConfig[2][2] - ,Word16 igfStopFreq - ,Word32 bitrate + const Word16 bwidth, + const Word16 L_frame, + STnsConfig tnsConfig[2][2], + const Word16 igfStopFreq, + const Word32 total_brate, + const Word16 element_mode, + const Word16 is_mct ); -void SetTnsConfig(TCX_config * tcx_cfg, Word8 isTCX20, Word8 isAfterACELP); +void SetTnsConfig( + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word8 isTCX20, + Word8 isAfterACELP +); /* ari.c */ @@ -8620,31 +8571,32 @@ Word16 ari_start_decoding_14bits_prm(const Word16 *ptr, Word16 bp, TastatDec *s) /*arith_code.c*/ Word32 expfp( /* o: Q31 */ - Word16 x, /* i: mantissa Q-e */ - Word16 x_e); /* i: exponent Q0 */ + const Word16 x, /* i: mantissa Q-e */ + const Word16 x_e); /* i: exponent Q0 */ -void powfp_odd2(Word16 base, /* Q15 */ - Word16 exp, /* Q0 */ - Word16 *pout1, /* Q15 */ - Word16 *pout2); /* Q15 */ +void powfp_odd2( + const Word16 base, /* Q15 */ + const Word16 exp, /* Q0 */ + Word16 *pout1, /* Q15 */ + Word16 *pout2); /* Q15 */ void tcx_arith_scale_envelope( - Word16 L_spec_core, /* i: number of lines to scale Q0 */ + const Word16 L_spec_core, /* i: number of lines to scale Q0 */ Word16 L_frame, /* i: number of lines Q0 */ - Word32 env[], /* i: unscaled envelope Q16 */ + const Word32 env[], /* i: unscaled envelope Q16 */ Word16 target_bits, /* i: number of available bits Q0 */ - Word16 low_complexity, /* i: low-complexity flag Q0 */ + const Word16 low_complexity,/* i: low-complexity flag Q0 */ Word16 s_env[], /* o: scaled envelope Q15-e */ Word16 *s_env_e /* o: scaled envelope exponent Q0 */ ); void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - Word16 L_frame, /* i: number of spectral lines */ - Word16 L_spec, - Word16 preemph_fac, /* i: pre-emphasis factor */ - Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ + const Word16 L_frame, /* i: number of spectral lines */ + const Word16 L_spec, + const Word16 preemph_fac, /* i: pre-emphasis factor */ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ Word32 env[] /* o: shaped signal envelope */ ); @@ -8658,31 +8610,38 @@ void tcx_get_gain(Word32 *x, /* i: spectrum 1 */ Word32 *en_y, /* o: energy of y (optional) */ Word16 *en_y_e /* o: energy of y exponent (optional) */ ); - -void init_TCX_config(TCX_config *tcx_cfg, - Word16 L_frame, - Word16 fscale - ,Word16 L_frameTCX - ,Word16 fscaleFB - ); +void init_TCX_config_dec( /* TEMPORARY */ + TCX_CONFIG_HANDLE hTcxCfg, + Word16 L_frame, + Word16 fscale + , Word16 L_frameTCX + , Word16 fscaleFB +); +void init_TCX_config( + TCX_CONFIG_HANDLE hTcxCfg, + Word16 L_frame, + Word16 fscale + ,Word16 L_frameTCX + ,Word16 fscaleFB +); void tcx_arith_encode_envelope( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ - Word16 L_frame, /* i: frame or MDCT length Q0 */ - Word16 L_frame_orig, /* i: length w/o BW limitation Q0 */ - Encoder_State_fx *st, /* i/o: coder state */ - const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ - Word16 target_bits, /* i: number of available bits Q0 */ - Word16 prm[], /* o: bitstream parameters Q0 */ - Word8 use_hm, /* i: use HM in current frame? */ - Word16 prm_hm[], /* o: HM parameter area Q0 */ - Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o: bits used for signaling Q0 */ - Word16 *nf_seed /* o: noise filling seed Q0 */ - ,Word16 low_complexity /* i: low-complexity flag Q0 */ + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16* spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i: frame or MDCT length Q0 */ + const Word16 L_spec, /* i: frame or MDCT length Q0 */ + Encoder_State_fx* st, /* i/o: coder state */ + const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ + Word16 target_bits, /* i: number of available bits Q0 */ + Word16 prm[], /* o: bitstream parameters Q0 */ + const Word8 use_hm, /* i: use HM in current frame? */ + Word16 prm_hm[], /* o: HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16* arith_bits, /* o: bits used for ari. coding Q0 */ + Word16* signaling_bits, /* o: bits used for signaling Q0 */ + Word16* nf_seed, /* o: noise filling seed Q0 */ + const Word16 low_complexity /* i: low-complexity flag Q0 */ ); void tcx_arith_decode_envelope( Word32 q_spectrum[], /* o: quantised MDCT coefficients Q31-e */ @@ -8750,7 +8709,8 @@ void ConfigureContextHm( Word16 EncodeIndex( Word16 Bandwidth, /* 0: NB, 1: (S)WB */ Word16 PeriodicityIndex, - Encoder_State_fx *st); + BSTR_ENC_HANDLE hBst /* i/o: bitstream handle */ + ); Word16 CountIndexBits( Word16 Bandwidth, /* 0: NB, 1: (S)WB */ @@ -8764,16 +8724,16 @@ DecodeIndex( void tcx_hm_analyse( - const Word32 abs_spectrum[], /* i: absolute spectrum Q31-e */ - Word16 *spectrum_e, /* i: absolute spectrum exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word32 env[], /* i/o: envelope shape Q16 */ - Word16 targetBits, /* i: target bit budget Q0 */ - Word16 coder_type, /* i: coder type Q0 */ - Word16 prm_hm[], /* o: HM parameters Q0 */ - Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ - Word16 LtpGain, /* i: LTP gain Q15 */ - Word16 *hm_bits /* o: bit consumption Q0 */ + const Word32 abs_spectrum[],/* i: absolute spectrum Q31-e */ + const Word16* spectrum_e, /* i: absolute spectrum exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + Word32 env[], /* i/o: envelope shape Q16 */ + const Word16 targetBits, /* i: target bit budget Q0 */ + const Word16 coder_type, /* i: coder type Q0 */ + Word16 prm_hm[], /* o: HM parameters Q0 */ + const Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ + const Word16 LtpGain, /* i: LTP gain Q15 */ + Word16* hm_bits_out /* o: bit consumption Q0 */ ); void tcx_hm_decode( @@ -8788,49 +8748,49 @@ void tcx_hm_decode( void coder_tcx( Word16 n, - TCX_config *tcx_cfg, /*input: configuration of TCX*/ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word16 A[], /* i : quantized coefficients NxAz_q[M+1] */ + Word16 Aqind[], /* i : frame-independent quantized coefficients (M+1) */ Word16 synth[], - Word16 L_frame_glob, /* input: frame length */ + Word16 L_frame_glob, /* i : frame length */ Word16 L_frameTCX_glob, Word16 L_spec, - Word16 nb_bits, /*input: bit budget*/ - Word8 tcxonly, /*input: only TCX flag*/ + Word16 nb_bits, /*i : bit budget*/ + Word8 tcxonly, /*i : only TCX flag*/ Word32 spectrum[], /* i/o: MDCT spectrum */ Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - LPD_state *LPDmem, /*i/o: memories*/ - Word16 prm[], /* output: tcx parameters */ + Word16 prm[], /* o : tcx parameters */ Encoder_State_fx *st, CONTEXT_HM_CONFIG *hm_cfg ); -void coder_tcx_post(Encoder_State_fx *st, - LPD_state *LPDmem, - TCX_config *tcx_cfg, - Word16 *synth, - const Word16 *A, - const Word16 *Ai, - Word16 *wsig, - Word16 Q_new, - Word16 shift - ); +void coder_tcx_post( + Encoder_State_fx *st, + LPD_state *LPDmem, + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word16 *synth, + const Word16 *A, + const Word16 *Ai, + Word16 *wsig, + Word16 Q_new, + Word16 shift + ); void decoder_tcx( - TCX_config *tcx_cfg, /* input: configuration of TCX */ - Word16 prm[], /* input: parameters */ - Word16 A[], /* input: coefficients NxAz[M+1] */ - Word16 Aind[], /* input: frame-independent coefficients Az[M+1] */ - Word16 L_frame_glob, /* input: frame length */ + TCX_CONFIG_HANDLE hTcxCfg, + Word16 prm[], /* i : parameters */ + Word16 A[], /* i : coefficients NxAz[M+1] */ + Word16 Aind[], /* i : frame-independent coefficients Az[M+1] */ + Word16 L_frame_glob, /* i : frame length */ Word16 L_frameTCX, Word16 L_spec, Word16 synth[], /* in/out: synth[-M-LFAC..lg] */ Word16 synthFB[], Decoder_State_fx*st, - Word16 coder_type, /* input : coder type */ - Word16 bfi, /* input: Bad frame indicator */ - Word16 frame_cnt, /* input: frame counter in the super_frame */ - Word16 stab_fac /* input: stability of isf */ + Word16 coder_type, /* i : coder type */ + Word16 bfi, /* i : Bad frame indicator */ + Word16 frame_cnt, /* i : frame counter in the super_frame */ + Word16 stab_fac /* i : stability of isf */ ); void decoder_tcx_post(Decoder_State_fx *st_fx, @@ -8841,39 +8801,32 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, ); /* cod_ace.c */ -Word16 coder_acelp( /* output SEGSNR for CL decision */ - ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - Word16 synth[], - LPD_state *LPDmem, - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ - Word16 *prm, /* output: acelp parameters */ +Word16 coder_acelp( /* o : SEGSNR for CL decision */ + const Word16 A[], /* i : coefficients 4xAz[M+1] */ + const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] */ + const Word16 speech[], /* i : speech[-M..lg] */ + Word16* prm, /* o : acelp parameters */ Word16 stab_fac, - Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 target_bits, /* i/o : coder memory state */ - Word16 Q_new, - Word16 shift, - Word16 *pitch_buf, /* output : pitch values for each subfr.*/ - Word16 *voice_factors, /* output : voicing factors */ - Word16 *bwe_exc /* output : excitation for SWB TBE */ + Encoder_State_fx* st, + PLC_ENC_EVS_HANDLE hPlc_Ext, + const Word16 target_bits, /* i/o: coder memory state */ + const Word16 Q_new, + const Word16 shift, + Word16* pitch_buf, /* o : pitch values for each subfr.*/ + Word16* voice_factors, /* o : voicing factors */ + Word16* bwe_exc /* o : excitation for SWB TBE */ ); void decoder_acelp( Decoder_State_fx *st, - Word16 coder_type, /* input: coder type */ - Word16 prm[], /* input: parameters */ - Word16 A[], /* input: coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* input: ACELP config */ + Word16 prm[], /* i : parameters */ + Word16 A[], /* i : coefficients NxAz[M+1] */ + ACELP_config acelp_cfg, /* i : ACELP config */ Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ Word16 *pT, /* out: pitch for all subframe Q0 */ Word16 *pgainT, /* out: pitch gain for all subfr 1Q14 */ - Word16 stab_fac, /* input: stability of isf */ + Word16 stab_fac, /* i : stability of isf */ Word16 *pitch_buffer, /* out: pitch values for each subfr.*/ Word16 *voice_factors, /* out: voicing factors */ const Word16 LSF_Q_prediction,/* i : LSF prediction mode */ @@ -8911,26 +8864,31 @@ void dec_prm_core( Decoder_State_fx *st ); -void analy_sp( /* o: fft0 bin energy Q0 */ - Word16 *speech, /* i: speech buffer Q_new - preemph_bits */ - const Word16 Q_new, /* i: current scaling exp Q0 */ - Word32 *fr_bands, /* o: energy in critical frequency bands Q_new + QSCALE */ - Word32 *lf_E, /* o: per bin E for first... Q_new + QSCALE - 2*/ - Word16 *Etot, /* o: total input energy Q8 */ - const Word16 min_band, /* i: minimum critical band Q0 */ - const Word16 max_band, /* i: maximum critical band Q0 */ - const Word32 e_min_scaled, /* i: minimum energy scaled Q_new + QSCALE */ - Word16 Scale_fac[2], /* o: FFT scales factors (2 values by frame) Q0 */ - Word32 *Bin_E, /* o : per bin log energy spectrum */ - Word32 *Bin_E_old, /* o : per bin log energy spectrum for mid-frame */ - Word32 *PS, /* o : Per bin energy spectrum */ - Word16 *EspecdB, /* o : log E spectrum (with f=0) of the current frame Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ - Word16 *fft_buff /* o : FFT coefficients */ +void analy_sp( + const Word16 element_mode, /* i : element mode */ +#ifdef IVAS_CODE_CPE + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ +#endif + const Word32 input_Fs, /* i : i sampling rate */ + Word16* speech, /* i : speech buffer Q_new - preemph_bits */ + const Word16 Q_new, /* i : current scaling exp Q0 */ + Word32* fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ + Word32* lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ + Word16* Etot, /* o : total i energy Q8 */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ + Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ + Word32* Bin_E, /* o : per-bin energy spectrum */ + Word32* Bin_E_old, /* o : per-bin energy spectrum of the previous frame */ + Word32* PS, /* o : per-bin energy spectrum */ + Word16* EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ + Word32* band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ + Word16* fft_buff /* o : FFT coefficients */ ); void E_UTIL_copy_scale_sig( - const Word16 x[], /* i : signal to scale input Qx */ + const Word16 x[], /* i : signal to scale i Qx */ Word16 y[], /* o : scaled signal output Qx */ const Word16 lg, /* i : size of x[] Q0 */ const Word16 exp0 /* i : exponent: x = round(x << exp) Qx xx exp */ @@ -9003,14 +8961,14 @@ void gaus_L2_dec( ); void tcx_ltp_get_lpc( - Word16 *x, - Word16 L, - Word16 *A, - Word16 order + Word16* x, + const Word16 L, + Word16* A, + const Word16 order ); void predict_signal( - const Word16 excI[], /* i : input excitation buffer */ + const Word16 excI[], /* i : i excitation buffer */ Word16 excO[], /* o : output excitation buffer */ const Word16 T0, /* i : integer pitch lag */ Word16 frac, /* i : fraction of lag */ @@ -9063,30 +9021,15 @@ void tcx_ltp_encode( Word8 tcxltp_on, Word16 lpcorder ); -void tcx_ltp_post( Word8 tcxltp_on, - Word16 core, - Word16 L_frame, - Word16 L_frame_core, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf, - Word16 tcx_buf_len, - Word16 bfi, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *filtIdx_past, - Word16 pitres, - Word16 *pitres_past, - Word16 damping, - Word16 SideInfoOnly, - Word16 *mem_in, - Word16 *mem_out, - Word32 bitrate - ); +void tcx_ltp_post( + Decoder_State_fx* st, + TCX_LTP_DEC_HANDLE hTcxLtpDec, + Word16 core, + Word16 output_frame, + Word16 delay, + Word16* sig, + Word16* tcx_buf +); Word16 tcx_ltp_decode_params( Word16 *ltp_param, Word16 *pitch_int, @@ -9124,6 +9067,10 @@ void msvq_dec const Word16 N, /* i : Vector dimension */ const Word16 maxN, /* i : Codebook dimension */ const Word16 Idx[], /* i : Indices */ +#ifdef IVAS_MSVQ + const int16_t applyIDCT_flag, /* i : applyIDCT flag */ + const float* invTrfMatrix, /* i : matrix for IDCT synthesis */ +#endif Word16 *uq /* o : quantized vector (3Q12) */ ); @@ -9228,16 +9175,16 @@ void lsf_update_memory( /* Returns: number of indices */ Word16 Q_lsf_tcxlpc( - /* const */ Word16 xsf[], /* (I) original xSF */ - Word16 xsf_q[], /* (O) quantized xSF */ - Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ - Word16 indices[], /* (O) VQ indices */ - Word16 lpcorder, /* (I) LPC order */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[], /* (I) MA memory */ - Word16 coder_type, - Word32 * Bin_Ener, + /* const */ Word16 lsf[], /* i : original lsf */ + Word16 lsf_q[], /* o : quantized lsf */ + Word16 lsp_q_ind[], /* o : quantized lsp (w/o MA prediction) */ + Word16 indices[], /* o : VQ indices */ + const Word16 lpcorder, /* i : LPC order */ + const Word16 narrowband, /* i : narrowband flag */ + const Word16 cdk, /* i : codebook selector */ + const Word16 mem_MA[], /* i : MA memory */ + const Word16 coder_type, + const Word32* Bin_Ener, const Word16 Q_ener ); @@ -9253,8 +9200,8 @@ Word16 D_lsf_tcxlpc( /* Returns: number of bits written */ Word16 enc_lsf_tcxlpc( - Word16 **indices, /* (I) Ptr to VQ indices */ - Encoder_State_fx *st /* (I/O) Encoder state */ + Word16** indices, /* i : Ptr to VQ indices */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); /* Returns: number of bits read */ @@ -9293,67 +9240,60 @@ void lsf_msvq_ma_dec( Word16 *lsfq, Word16 acelp_mode ); -Word16 lsf_msvq_ma_encprm( Encoder_State_fx * st, - Word16 *param_lpc, - Word16 core, - Word16 acelp_mode, - Word16 acelp_midLpc, - Word16 * bits_param_lpc, - Word16 no_indices - ); -Word16 lsf_msvq_ma_decprm( Decoder_State_fx *st, Word16 *param_lpc, Word16 core, Word16 acelp_mode, Word16 acelp_midLpc - ,Word16 narrowBand - ,Word32 sr_core - ); - -Word16 lsf_bctcvq_encprm( - Encoder_State_fx *st, +Word16 lsf_msvq_ma_encprm( + BSTR_ENC_HANDLE hBstr, Word16 *param_lpc, + Word16 core, + Word16 acelp_mode, + Word16 acelp_midLpc, Word16 * bits_param_lpc, Word16 no_indices ); +Word16 lsf_msvq_ma_decprm( Decoder_State_fx *st, Word16 *param_lpc); + +Word16 lsf_bctcvq_encprm( + BSTR_ENC_HANDLE hBstr, + Word16* param_lpc, + Word16* bits_param_lpc, + Word16 no_indices +); Word16 lsf_bctcvq_decprm( Decoder_State_fx * st, Word16 *param_lpc ); void lpc_unquantize( - Decoder_State_fx * st, - Word16 *lsfold, - Word16 *lspold, - Word16 *lsf, - Word16 *lsp, + Decoder_State_fx* st, + Word16* lsf, + Word16* lsp, const Word16 m, - const Word16 lpcQuantization, - Word16 *param_lpc, - const Word16 numlpc, - const Word16 core, - Word16 *mem_MA, - Word16 *mem_AR, - Word16 *lspmid, - Word16 *lsfmid, + Word16* param_lpc, + Word16* lspmid, + Word16* lsfmid, Word16 coder_type, - Word16 acelp_midLpc, - Word8 narrow_band, - Word16 *seed_acelp, - Word32 sr_core, - Word16 *mid_lsf_int, - Word16 prev_bfi, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *safety_net -); - -void midlsf_enc(const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 lsf[], /* i: lsf coefficients (3Q12) */ - Word16 *idx, /* o: codebook index */ - const Word16 lpcorder /* i: order of the lpc */ - , Word32 * Bin_Ener_128_fx - ,const Word16 Q_ener - ,Word8 narrowBand - ,Word32 sr_core - ,Word16 coder_type - ); + Word16* LSF_Q_prediction /* o : LSF prediction mode */ +); +Word16 set_ACELP_flag( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate per channel */ + const Word16 idchan, /* i : Channel id */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 cng_type /* i : CNG type */ +); +void midlsf_enc( + const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ + const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ + const Word16 lsf[], /* i: lsf coefficients (3Q12) */ + Word16* idx, /* o: codebook index */ + const Word16 lpcorder, /* i: order of the lpc */ + const Word32* Bin_Ener_128_fx, + const Word16 Q_ener, + const Word8 narrowBand, + const Word32 sr_core, + const Word16 coder_type +); void midlsf_dec( @@ -9377,17 +9317,40 @@ Word16 const * PlcGetLsfBase (Word16 const lpcQuantization, #define TCX_IMDCT_SCALE 15 #define TCX_IMDCT_HEADROOM 1 -void TCX_MDCT(const Word16 *x, Word32 *y, Word16 *y_e, Word16 l, Word16 m, Word16 r); - -void TCX_MDST(const Word16 *x, Word32 *y, Word16 *y_e, Word16 l, Word16 m, Word16 r); +void TCX_MDCT( + const Word16* x, + Word32* y, + Word16* y_e, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode +); + +void TCX_MDST( + const Word16* x, + Word32* y, + Word16* y_e, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode +); -void TCX_MDCT_Inverse(Word32 *x, Word16 x_e, Word16 *y, Word16 l, Word16 m, Word16 r); +void TCX_MDCT_Inverse( + Word32* x, + Word16 x_e, + Word16* y, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode +); /* post_dec.h */ void post_decoder( Decoder_State_fx *st, - Word16 coder_type, Word16 synth_buf[], Word16 pit_gain[], Word16 pitch[], @@ -9396,15 +9359,15 @@ void post_decoder( ); Word16 bass_pf_enc( - Word16 *orig, /* (i) : 12.8kHz original signal Q0 */ - Word16 *syn, /* (i) : 12.8kHz synthesis to postfilter Q0 */ - Word16 *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) Q0 */ - Word16 *gainT_sf, /* (i) : Pitch gain for all subframes (gainT_sf[16]) Q14 */ - Word16 l_frame, /* (i) : frame length (should be multiple of l_subfr) Q0 */ - Word16 l_subfr, /* (i) : sub-frame length (60/64) Q0 */ - Word16 *gain_factor_param, /* (o) : quantized gain factor Q0 */ - Word16 mode, /* (i) : coding mode of adapt bpf */ - struct MEM_BPF *mem_bpf /* i/o : memory state */ + const Word16* orig, /* i : 12.8kHz original signal Q0 */ + const Word16* syn, /* i : 12.8kHz synthesis to postfilter Q0 */ + const Word16* T_sf, /* i : Pitch period for all subframes (T_sf[16]) Q0 */ + const Word16* gainT_sf, /* i : Pitch gain for all subframes (gainT_sf[16]) Q14 */ + const Word16 l_frame, /* i : frame length (should be multiple of l_subfr) Q0 */ + const Word16 l_subfr, /* i : sub-frame length (60/64) Q0 */ + Word16* gain_factor_param, /* o : quantized gain factor Q0 */ + const Word16 mode, /* i : coding mode of adapt bpf */ + struct MEM_BPF* mem_bpf /* i/o: memory state */ ); void cldfb_synth_set_bandsToZero( Decoder_State_fx *st, @@ -9415,7 +9378,7 @@ void cldfb_synth_set_bandsToZero( ); /* fd_cng_common.h */ /* Create an instance of type FD_CNG */ -void createFdCngCom(HANDLE_FD_CNG_COM* hFdCngCom); +ivas_error createFdCngCom(HANDLE_FD_CNG_COM* hFdCngCom); void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale); @@ -9425,31 +9388,35 @@ void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom); void resetFdCngEnc( Encoder_State_fx * st); /* Initialize the spectral partitioning */ -void initPartitions( const Word16* part_in, - Word16 npart_in, - Word16 startBand, - Word16 stopBand, - Word16* part_out, - Word16* npart_out, - Word16* midband, - Word16* psize, - Word16* psize_norm, - Word16* psize_norm_exp, - Word16* psize_inv, - Word16 stopBandFR); +void initPartitions( + const Word16* part_in, + const Word16 npart_in, + const Word16 startBand, + const Word16 stopBand, + Word16* part_out, + Word16* npart_out, + Word16* midband, + Word16* psize, + Word16* psize_norm, + Word16* psize_norm_exp, + Word16* psize_inv, + const Word16 stopBandFR +); /* Noise estimation using Minimum Statistics (MS) */ -void compress_range(Word32 *in, - Word16 in_exp, - Word16 *out, - Word16 len - ); +void compress_range( + Word32* in, + Word16 in_exp, + Word16* out, + const Word16 len +); -void expand_range(Word16 *in, - Word32 *out, - Word16 *out_exp, - Word16 len - ); +void expand_range( + Word16* in, + Word32* out, + Word16* out_exp, + const Word16 len +); void minimum_statistics(Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ Word16 lenFFT, /* i : Number of FFT partitions */ @@ -9479,17 +9446,19 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, Word16 Q_new, Word16 gen_exc ); -void generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State_fx *stdec, - Word16 *Q_new, - Word16 gen_exc - ); +void generate_comfort_noise_dec ( + Word32 **bufferReal, /* o : matrix to real part of i bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ + Decoder_State_fx *stdec, + Word16 *Q_new, + Word16 gen_exc + , const Word16 nchan_out /* i : number of output channels */ +); void -generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ +generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to real part of i bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ Decoder_State_fx *stdec ); @@ -9512,122 +9481,140 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain ); /* Apply bitrate-dependant scale */ -void apply_scale(Word32 *scale, - Word16 bwmode, - Word32 bitrate - ); +void apply_scale( + Word32* scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP* scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ +); /* Compute the power for each partition */ -void bandcombinepow(Word32* bandpow, /* i : Power for each band */ - Word16 exp_bandpow, /* i : exponent of bandpow */ - Word16 nband, /* i : Number of bands */ - Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* psize_inv, /* i : Inverse partition sizes */ - Word32* partpow, /* o : Power for each partition */ - Word16* exp_partpow - ); +void bandcombinepow( + const Word32* bandpow, /* i : Power for each band */ + const Word16 exp_bandpow, /* i : exponent of bandpow */ + const Word16 nband, /* i : Number of bands */ + Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + const Word16* psize_inv, /* i : Inverse partition sizes */ + Word32* partpow, /* o : Power for each partition */ + Word16* exp_partpow +); /* Scale partitions (with smoothing) */ -void scalebands (Word32 *partpow, /* i : Power for each partition */ - Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16 *midband, /* i : Central band of each partition */ - Word16 nFFTpart, /* i : Number of FFT partitions */ - Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ - Word16 flag_fft_en - ); +void scalebands( + const Word32* partpow, /* i : Power for each partition */ + Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ + const Word16 npart, /* i : Number of partitions */ + Word16* midband, /* i : Central band of each partition */ + const Word16 nFFTpart, /* i : Number of FFT partitions */ + const Word16 nband, /* i : Number of bands */ + Word32* bandpow, /* o : Power for each band */ + const Word16 flag_fft_en +); -/* Get central band for each partition */ -void getmidbands(Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* midband, /* o : Central band of each partition */ - Word16* psize, /* o : Partition sizes */ - Word16* psize_norm, /* o : Partition sizes, fractional values */ - Word16* psize_norm_exp, /* o : Exponent for fractional partition sizes */ - Word16* psize_inv /* o : Inverse of partition sizes */ - ); /* STFT analysis filterbank */ -void AnalysisSTFT (const Word16 *timeDomainInput, /* i : pointer to time signal */ - Word16 Q, - Word32 *fftBuffer, /* o : FFT bins */ - Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - ); +void AnalysisSTFT( + const Word16* timeDomainInput, /* i : pointer to time signal */ + Word16 Q, + Word32* fftBuffer, /* o : FFT bins */ + Word16* fftBuffer_exp, /* i : exponent of FFT bins */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +); /* STFT synthesis filterbank */ -void SynthesisSTFT (Word32 *fftBuffer, /* i : pointer to FFT bins */ - Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ - Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ - const PWord16 *olapWin, /* i : pointer to overlap window */ - Word16 tcx_transition, - HANDLE_FD_CNG_COM st, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ - Word16 gen_exc, - Word16 *Q_new - ); +void SynthesisSTFT( + Word32* fftBuffer, /* i : pointer to FFT bins */ + Word16 fftBufferExp, /* i : exponent of FFT bins */ + Word16* timeDomainOutput, /* o : pointer to time domain signal */ + Word16* olapBuffer, /* i/o : pointer to overlap buffer */ + const PWord16* olapWin, /* i : pointer to overlap window */ + Word16 tcx_transition, + HANDLE_FD_CNG_COM hFdCngCom, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ + Word16 gen_exc, + Word16* Q_new, + const Word16 element_mode, /* i : element mode */ + const Word16 nchan_out /* i : number of output channels */ +); /* Compute some calues used in the bias correction of the minimum statistics algorithm */ -void mhvals(Word16 d, Word16 * m/*, float * h*/); +void mhvals( + const Word16 d, + Word16* m /*, float * h*/ +); /* Random generator with Gaussian distribution with mean 0 and std 1 */ Word32 rand_gauss (Word16 *seed); -void lpc_from_spectrum (Word32 *powspec, - Word16 powspec_exp, - Word16 start, - Word16 stop, - Word16 fftlen, - Word16 *A, - Word16 lpcorder, - Word16 preemph_fac); - -void msvq_decoder(const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 maxN, /* i : Codebook vector dimension */ - Word16 Idx[], /* i : Indices */ - Word16 *uq /* o : quantized vector */ - ); +void lpc_from_spectrum( + HANDLE_FD_CNG_COM hFdCngCom, + const Word16 start, /*i : start band*/ + const Word16 stop, /*i : stop band*/ + const Word16 preemph_fac /*i : preemphase factor format Q1.15*/ +); + +void msvq_decoder( + const Word16* const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook vector dimension */ + const Word16 Idx[], /* i : Indices */ + Word16* uq /* o : quantized vector */ +); /*fd_cng_dec.h*/ /* Create an instance of type FD_CNG */ -void createFdCngDec(HANDLE_FD_CNG_DEC* hFdCngDec); - -Word16 initFdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 scale); +ivas_error createFdCngDec(HANDLE_FD_CNG_DEC* hFdCngDec); +void initFdCngDec( + DEC_CORE_HANDLE st, /* i/o: decoder state structure */ + Word16 scale +); extern void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); extern void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); /* Delete the instance of type FD_CNG */ -void deleteFdCngDec(HANDLE_FD_CNG_DEC * hFdCngDec); - +void deleteFdCngDec(HANDLE_FD_CNG_DEC* hFdCngDec); /* Configure CLDFB-CNG */ -void configureFdCngDec(HANDLE_FD_CNG_DEC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, - Word32 bitrate, - Word16 cng_type); - - +void configureFdCngDec( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ + Word16 bandwidth, + Word32 bitrate, + Word16 L_frame, + const Word16 Last_L_frame, + const Word16 element_mode +); /* Apply the CLDFB-based CNG */ -Word16 ApplyFdCng (Word16 * timeDomainInput, /* i : pointer to time domain input */ - Word16 Q, - Word32 ** cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 ** cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ - Word16 * cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - HANDLE_FD_CNG_DEC st, /* i/o: pointer to FD_CNG structure containing all buffers and variables */ - Word16 m_frame_type, /* i : type of frame at the decoder side */ - Decoder_State_fx *stdec, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music - ); - +Word16 ApplyFdCng( + Word16* timeDomainInput, /* i : pointer to time domain i */ + Word16 Q, +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + Word16* powerSpectrum, +#endif + Word32** cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ + Word32** cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ + Word16* cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ + Decoder_State_fx* st, + const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ + Word16 is_music +); /* Perform noise estimation */ -void perform_noise_estimation_dec(const Word16 *timeDomainInput, /* i: pointer to time domain input */ - Word16 Q, - HANDLE_FD_CNG_DEC st /* i/o: FD_CNG structure containing all buffers and variables */ - ); +void perform_noise_estimation_dec( + const Word16* timeDomainInput, /* i: pointer to time domain i */ + const Word16 Q, +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + float* power_spectrum, +#endif + HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */ +#ifdef IVAS_CODE_CNG + , const Word16 element_mode, /* i : element mode */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 L_frame, /* i : frame length at internal Fs */ + const Word16 last_L_frame, /* i : frame length of the last frame at internal Fs */ + const Word32 last_core_brate, /* i : previous frame core bitrate */ + const Word16 VAD /* i : VAD flag in the decoder */ +#endif +); /* Decode the CLDFB-CNG bitstream */ void FdCng_decodeSID(HANDLE_FD_CNG_COM st, /* i/o: FD_CNG structure containing all buffers and variables */ @@ -9647,22 +9634,12 @@ void FdCng_exc( Word16 *exc2, /* o: LP excitation */ Word16 *bwe_exc /* o: LP excitation for BWE */ ); - void noisy_speech_detection( - const Word16 vad, - const Word16 *ftimeInPtr, /* i : input time-domain frame */ - const Word16 frameSize, /* i : frame size */ - const Word16 Q, - const Word32 *msNoiseEst, /* i : noise estimate over all critical bands */ - const Word16 msNoiseEst_exp, /* i : exponent for noise estimate over all critical bands */ - const Word16 *psize_norm, - const Word16 psize_norm_exp, - const Word16 nFFTpart, /* i : Number of partitions taken into account */ - Word32 *lp_noise, /* i/o: pointer to long term total Noise energy average */ - Word32 *lp_speech, /* i/o: pointer to long term active speech energy average */ - Word16 *flag_noisy_speech + HANDLE_FD_CNG_DEC hFdCngDec,/* i/o: FD_CNG structure */ + const Word16 vad, /* i : VAD flag */ + const Word16* syn, /* i : i time-domain frame */ + const Word16 Q ); - /* Create an instance of type FD_CNG */ void createFdCngEnc(HANDLE_FD_CNG_ENC* hFdCngEnc); @@ -9714,7 +9691,14 @@ void FdCng_encodeSID (HANDLE_FD_CNG_ENC st, /* i/o: FD_CNG structure contain * @param pnSize Set to the number of elements written to the stream. * @param pnBits Set to the number of required bits. */ -void GetParameters(ParamsBitMap const * paramsBitMap, Word16 nParams, void const * pParameter, Word16 ** pStream, Word16 * pnSize, Word16 * pnBits); +void GetParameters( + ParamsBitMap const* paramsBitMap, + const Word16 nArrayLength, + void const* pParameter, + Word16** pStream, + Word16* pnSize, + Word16* pnBits +); /** Reads parameters from a stream into paramsBitMap. * @param paramsBitMap Definition of parameters and mappings to a bitstream. @@ -9723,7 +9707,13 @@ void GetParameters(ParamsBitMap const * paramsBitMap, Word16 nParams, void const * @param pStream Pointer to a stream from which parameters are read. * @param pnSize Set to the number of elements read from the stream. */ -void SetParameters(ParamsBitMap const * paramsBitMap, Word16 nParams, void * pParameter, Word16 const ** pStream, Word16 * pnSize); +void SetParameters( + ParamsBitMap const* paramsBitMap, + const Word16 nArrayLength, + void* pParameter, + const Word16** pStream, + Word16* pnSize +); /** Writes parameters from a stream into a bitstream. * @param paramsBitMap Definition of parameters and mappings to a bitstream. @@ -9733,7 +9723,14 @@ void SetParameters(ParamsBitMap const * paramsBitMap, Word16 nParams, void * pPa * @param st Encoder state. * @param pnBits Set to the number of bits written. */ -void WriteToBitstream(ParamsBitMap const * paramsBitMap, Word16 nParams, Word16 const ** pStream, Word16 * pnSize, Encoder_State_fx *st, Word16 * pnBits); +void WriteToBitstream( + ParamsBitMap const* paramsBitMap, + const Word16 nArrayLength, + const Word16** pStream, + Word16* pnSize, + BSTR_ENC_HANDLE hBstr, + Word16* pnBits +); /** Reads parameters from a bitstream into a stream. * @param paramsBitMap Definition of parameters and mappings to a bitstream. @@ -9742,7 +9739,13 @@ void WriteToBitstream(ParamsBitMap const * paramsBitMap, Word16 nParams, Word16 * @param pStream Pointer to a stream where parameters should be stored. * @param pnSize Set to the number of elements written to the stream. */ -void ReadFromBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Decoder_State_fx *st, Word16 ** pStream, Word16 * pnSize); +void ReadFromBitstream( + ParamsBitMap const* paramsBitMap, + const Word16 nArrayLength, + Decoder_State_fx* st, + Word16** pStream, + Word16* pnSize +); void const * GetTnsFilterOrder(void const * p, Word16 index, Word16 * pValue); void * SetTnsFilterOrder(void * p, Word16 index, Word16 value); @@ -9793,17 +9796,20 @@ void ClearTnsFilterCoefficients(STnsFilter * pTnsFilter); /** Init TNS configuration. * Fills STnsConfig structure with sensible content. - * @param nSampleRate Sampling rate of the input. + * @param nSampleRate Sampling rate of the i . * @param nFrameLength Frame length. * @param pTnsConfig TNS configuration to be initialized. * @return 0 on success, otherwise 1. */ -Word16 InitTnsConfiguration(Word32 nSampleRate, - Word16 frameLength, - STnsConfig * pTnsConfig - ,Word16 igfStopFreq - ,Word32 bitrate - ); +void InitTnsConfiguration( + const Word16 bwidth, + const Word16 frameLength, + STnsConfig* pTnsConfig, + const Word16 igfStopFreq, + const Word32 total_brate, + const Word16 element_mode, + const Word16 is_mct +); /** Detect TNS parameters. * Detects if TNS should be used and fills TNS data in pTnsData. @@ -9822,7 +9828,7 @@ Word16 DetectTnsFilt(STnsConfig const * pTnsConfig, /** Modify spectrum using TNS filter. * Modifies spectrum unsing TNS filter defined by pTnsData. * If fIsAnalyses is true considers spectrum to be - * an input of encoder and returns residum. + * an i of encoder and returns residum. * If fIsAnalyses is false considers spectrum to be * a residum from decoder and returns output spectrum. * @param pTnsConfig TNS configuration. @@ -9832,10 +9838,12 @@ Word16 DetectTnsFilt(STnsConfig const * pTnsConfig, * in encoder (TRUE) or in decoder (FALSE). * @return 0 on success, otherwise 1. */ -Word16 ApplyTnsFilter(STnsConfig const * pTnsConfig, - STnsData const * pTnsData, - Word32 spectrum[], - Word8 fIsAnalysis); +void ApplyTnsFilter( + STnsConfig const * pTnsConfig, + STnsData const * pTnsData, + Word32 spectrum[], + const Word8 fIsAnalysis +); Word16 ITF_Detect_fx(Word32 const pSpectrum[], Word16 startLine, @@ -9847,7 +9855,7 @@ Word16 ITF_Detect_fx(Word32 const pSpectrum[], Word16* curr_order, Word16 Q); -TNS_ERROR ITF_Apply_fx(Word32 spectrum[], +void ITF_Apply_fx(Word32 spectrum[], Word16 startLine, Word16 stopLine, const Word16* A, Word16 Q_A, Word16 curr_order); @@ -9904,7 +9912,12 @@ Word16 WriteTnsData(STnsConfig const * pTnsConfig, * @param pnSize Set to the number of used elements from stream. * @return 0 on success, otherwise 1. */ -Word16 ReadTnsData(STnsConfig const * pTnsConfig, +#ifdef IVAS_CODE +void +#else +Word16 +#endif +ReadTnsData(STnsConfig const * pTnsConfig, Decoder_State_fx *st, Word16 * pnBits, Word16 * stream, @@ -9978,7 +9991,7 @@ void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle const Word16 frameSize /*!< FrameSize */ ); -void openCldfb ( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ +ivas_error openCldfb ( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ const Word16 type, /*!< analysis or synthesis */ const Word16 maxCldfbBands, /*!< number of cldfb bands */ const Word16 frameSize /*!< FrameSize */ @@ -10061,8 +10074,8 @@ GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q31 | pointer to the resul Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ Word32 *energyValuesSum, /*!< o: Q31 | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp /*!< o: pointer to exponents of energyValuesSum, not initialized */ - , HANDLE_TEC_ENC_FX hTecEnc + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE_FX hTECEnc ); /*bits_alloc.h*/ @@ -10085,29 +10098,6 @@ Word16 BITS_ALLOC_config_acelp( const Word16 nb_subfr ); -void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, - Word16 *tilt_code, - Word16 *rf_frame_type, - Word16 *rf_target_bits, - Word16 nb_subfr - , Word16 rf_fec_indicator - , Word16 *pitch_buf - ); -void BITS_ALLOC_TCX_config_rf( - Word16 *rf_frame_type, - Word16 *rf_target_bits, - Word16 PLC_Mode, - Word16 coder_type, - Word16 last_core, - Word16 TD_mode -); - -Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( - const Word16 bits_frame, /*i: bit budget */ - Word16 *fixed_cdk_index, /*o: codebook index */ - const Word16 nb_subfr /*i: number of subframes*/ -); - Word16 BITS_ALLOC_adjust_acelp_fixed_16KHZ_cdk( @@ -10131,11 +10121,11 @@ void InitTransientDetection(Word16 nFrameLength, /** Runs transient detection. * Runs all transient detectors defined in pTransientDetection * and calculates mean zero crossing. - * @param input New input samples. - * @param nSamplesAvailable Number of new input samples available. + * @param i New i samples. + * @param nSamplesAvailable Number of new i samples available. * @param pTransientDetection Structure that contains transient detectors to be run. */ -void RunTransientDetection(Word16 const * input, Word16 nSamplesAvailable, struct TransientDetection * pTransientDetection); +void RunTransientDetection(Word16 const * i , Word16 nSamplesAvailable, struct TransientDetection * pTransientDetection); /** Get the average temporal flatness measure using subblock energies aligned with the TCX. @@ -10169,24 +10159,29 @@ void SetTCXModeInfo(Encoder_State_fx *st, /* Tonal Concealment */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Init( TonalMDCTConcealPtr self, - Word16 nSamples, - Word16 nSamplesCore, - Word16 nScaleFactors, - TCX_config * tcx_cfg - ); +ivas_error TonalMDCTConceal_Init( + TonalMDCTConcealPtr self, + const Word16 nSamples, + const Word16 nSamplesCore, + const Word16 nScaleFactors, + TCX_CONFIG_HANDLE hTcxCfg /* TCX config */ +); /* Must be called only when a good frame is recieved - concealment is inactive */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr self, - Word32 const *mdctSpectrum, - Word16 const mdctSpectrum_exp, - Word16 nNewSamples, - Word16 nNewSamplesCore, - Word16 const *scaleFactors, - Word16 const *scaleFactors_exp, - Word16 const gain_tcx_exp - ); +void TonalMDCTConceal_SaveFreqSignal( + TonalMDCTConcealPtr self, + const Word32* mdctSpectrum, + const Word16 mdctSpectrum_exp, + Word16 nNewSamples, + Word16 nNewSamplesCore, + const Word16* scaleFactors, + const Word16* scaleFactors_exp, + const Word16 gain_tcx_exp +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ,const Word16 infoIGFStartLine +#endif +); /* The call to TonalMDCTConceal_UpdateState() should be called after TonalMDCTConceal_Apply. */ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, @@ -10198,10 +10193,11 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, /* The call to TonalMDCTConceal_SaveTimeSignal() should be at the * place where the TD signal corresponds to the FD signal stored with TonalMDCTConceal_SaveFreqSignal. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr self, - Word16 *timeSignal, - Word16 numSamples - ); +void TonalMDCTConceal_SaveTimeSignal( + TonalMDCTConcealPtr hTonalMDCTConc, + Word16 * timeSignal, + Word16 nNewSamples +); /* Calculates MDST, power spectrum and performs peak detection. * Uses the TD signal in pastTimeSignal; if pastTimeSignal is NULL, uses the @@ -10209,50 +10205,68 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr self * second last frame was also lost, it is expected that pastTimeSignal * could hold a signal somewhat different from the one stored in * TonalMDCTConceal_SaveTimeSignal (e.g. including fade-out).*/ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, /*IN */ - Word32 const pitchLag, /*IN */ - Word16 * const umIndices /*OUT*/ - ); +void TonalMDCTConceal_Detect( + const TonalMDCTConcealPtr self, /*IN */ + const Word32 pitchLag, /*IN */ + Word16 * umIndices /*OUT*/ +#ifdef IVAS_CODE_MDCT_GSHAPE + , const PsychoacousticParameters* psychParamsCurrent +#endif +); /* Conceals the lost frame using the FD signal previously stored using * TonalMDCTConceal_SaveFreqSignal. Stores the concealed harmonic part of * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply( TonalMDCTConcealPtr self, /*IN */ - Word32 * mdctSpectrum, /*OUT*/ - Word16 * mdctSpectrum_exp /*OUT*/ - ); +void TonalMDCTConceal_Apply( + const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32* mdctSpectrum, /*IN/OUT*/ + Word16* mdctSpectrum_exp /*IN */ +#ifdef IVAS_CODE_MDCT_GSHAPE + , const PsychoacousticParameters* psychParamsCurrent) +#endif + ); /* Conceals the lost frame using the FD signal previously stored using * TonalMDCTConceal_SaveFreqSignal. Stores the concealed noise part of * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, /*IN */ - Word32* mdctSpectrum, /*OUT*/ - Word16* mdctSpectrum_exp, /*OUT*/ - Word8 tonalConcealmentActive, - Word16* pSeed, /*IN/OUT*/ - Word16 tiltCompFactor, - Word16 crossfadeGain, - Word16 crossOverFreq); +void TonalMDCTConceal_InsertNoise( + const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32* mdctSpectrum, /*OUT*/ + Word16* mdctSpectrum_exp, /*OUT*/ + const Word8 tonalConcealmentActive, + Word16* pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, + Word16 crossfadeGain, +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + const Word16concealment_noise[L_FRAME48k], +#endif + const Word16 crossOverFreq +); /* Detect tonal components in the lastMDCTSpectrum, use * secondLastPowerSpectrum for the precise location of the peaks and * store them in indexOfTonalPeak. Updates lowerIndex, upperIndex, * pNumIndexes accordingly. */ -void DetectTonalComponents(Word16 indexOfTonalPeak[], /* OUT */ - Word16 lowerIndex[], /* OUT */ - Word16 upperIndex[], /* OUT */ - Word16 * pNumIndexes, /* OUT */ - Word32 lastPitchLag, Word32 currentPitchLag, /* IN */ - Word16 const lastMDCTSpectrum[], /* IN */ - Word16 lastMDCTSpectrum_exp, /* IN */ - Word16 const scaleFactors[], /* IN */ - Word16 const scaleFactors_exp[], /* IN */ - Word16 const scaleFactors_max_e, /* IN */ - Word32 const secondLastPowerSpectrum[], /* IN */ - Word16 nSamples /* IN */ - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* IN */ - ); +void DetectTonalComponents( + Word16 indexOfTonalPeak[], + Word16 lowerIndex[], + Word16 upperIndex[], + Word16* pNumIndexes, + const Word32 lastPitchLag, + const Word32 currentPitchLag, + const Word16 lastMDCTSpectrum[], + const Word16 lastMDCTSpectrum_exp, + const Word16 scaleFactors[], + const Word16 scaleFactors_exp[], + const Word16 scaleFactors_max_e, + const Word32 secondLastPowerSpectrum[], + const Word16 nSamples, + const Word16 nSamplesCore, + Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ +#ifdef IVAS_CODE_MDCT_GSHAPE + , const PsychoacousticParameters* psychParamsCurrent +#endif +); /* When called, the tonal components are already stored in * indexOfTonalPeak. Detect tonal components in the lastMDCTSpectrum, @@ -10260,24 +10274,28 @@ void DetectTonalComponents(Word16 indexOfTonalPeak[], /* OU * then keep in indexOfTonalPeak only the tonal components that are * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ -void RefineTonalComponents(Word16 indexOfTonalPeak[], /* OUT */ - Word16 lowerIndex[], /* OUT */ - Word16 upperIndex[], /* OUT */ - Word16 phaseDiff[], /* OUT */ - Word16 phases[], /* OUT */ - Word16 * pNumIndexes, /* OUT */ - Word32 lastPitchLag, /* IN */ - Word32 currentPitchLag, /* IN */ - Word16 const lastMDCTSpectrum[], /* IN */ - Word16 const lastMDCTSpectrum_exp, /* IN */ - Word16 const scaleFactors[], /* IN */ - Word16 const scaleFactors_exp[], /* IN */ - Word16 const scaleFactors_max_e, /* IN */ - Word32 const secondLastPowerSpectrum[], /* IN */ - Word16 nSamples /* IN */ - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* IN */ - ); +void RefineTonalComponents( + Word16 indexOfTonalPeak[], + Word16 lowerIndex[], + Word16 upperIndex[], + Word16 phaseDiff[], + Word16 phases[], + Word16* pNumIndexes, + const Word32 lastPitchLag, + const Word32 currentPitchLag, + const Word16 lastMDCTSpectrum[], + const Word16 lastMDCTSpectrum_exp, + const Word16 scaleFactors[], + const Word16 scaleFactors_exp[], + const Word16 scaleFactors_max_e, + const Word32 secondLastPowerSpectrum[], + const Word16 nSamples, + const Word16 nSamplesCore, + const Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ +#ifdef IVAS_CODE_MDCT_GSHAPE + , const PsychoacousticParameters* psychParamsCurrent +#endif +); void set_state(Word16 *state, Word16 num, Word16 N); void concealment_init_x(Word16 N, void *_plcInfo); @@ -10298,8 +10316,8 @@ void waveform_adj2_fix( Word16 *overlapbuf, Word16 bfi ); -Word16 ffr_getSfWord16(Word16 *vector, /*!< Pointer to input vector */ - Word16 len); /*!< Length of input vector */ +Word16 ffr_getSfWord16(Word16 *vector, /*!< Pointer to i vector */ + Word16 len); /*!< Length of i vector */ void concealment_decode_fix(Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale,void *_plcInfo); @@ -10314,10 +10332,10 @@ void concealment_signal_tuning_fx(Word16 bfi, Word16 *outdata2_fx, Decoder_State_fx *st); -Word16 Spl_GetScalingSquare_x(Word16 *in_vector, Word16 in_vector_length, Word16 times); -Word32 Spl_Energy_x(Word16* vector, Word16 vector_length, Word16* scale_factor); -void Log10OfEnergy_x(Word16 *s, Word32 *enerlogval, Word16 len); -void concealment_update2_x(Word16 *outx_new, void *_plcInfo, Word16 FrameSize); +Word16 Spl_GetScalingSquare_x(const Word16 *in_vector, const Word16 in_vector_length, Word16 times); +Word32 Spl_Energy_x(const Word16* vector, const Word16 vector_length, Word16* scale_factor); +void Log10OfEnergy_x(const Word16 *s, Word32 *enerlogval, const Word16 len); +void concealment_update2_x(const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize); Word16 Sqrt_x_fast(Word32 value); Word32 dot_w32_accuracy_x(Word16 *s1, Word16 *s2, Word16 nbits, Word16 N); @@ -10361,26 +10379,32 @@ void longshr (UWord32 a[], Word16 bits, Word16 len); /*qlpc_avq.h*/ -void lsf_weight_2st(const Word16 *lsfq, /* input: quantized lsf coefficients (3Q12) */ - Word16 *w, /* output: weighting function (0Q15) */ - const Word16 mode /* input: operational mode */ +void lsf_weight_2st(const Word16 *lsfq, /* i : quantized lsf coefficients (3Q12) */ + Word16 *w, /* o : weighting function (0Q15) */ + const Word16 mode /* i : operational mode */ ); void qlpc_avq( - const Word16 *lsf, /* (i) Input LSF vectors */ - const Word16 *lsfmid, /* (i) Input LSF vectors */ - Word16 *lsf_q, /* (o) Quantized LFS vectors */ - Word16 *lsfmid_q, /* (o) Quantized LFS vectors */ - Word16 *index, /* (o) Quantization indices */ - Word16 *nb_indices, /* (o) Number of quantization indices */ - Word16 *nbbits, /* (o) Number of quantization bits */ - const Word16 core, /* (i) TCX10 or TCX20 */ - Word32 sr_core + const Word16* lsf, /* i : Input LSF vectors (14Q1*1.28) */ + const Word16* lsfmid, /* i : Input LSF vectors (14Q1*1.28) */ + Word16* lsf_q, /* o : Quantized LFS vectors (14Q1*1.28) */ + Word16* lsfmid_q, /* o : Quantized LFS vectors (14Q1*1.28) */ + Word16* index, /* o : Quantization indices */ + Word16* nb_indices, /* o : Number of quantization indices */ + Word16* nbbits, /* o : Number of quantization bits */ + const Word16 core, /* i : TCX10 or TCX20 */ + const Word32 sr_core /* i : internal sampling rate */ ); -Word16 encode_lpc_avq( Encoder_State_fx *st, Word16 numlpc, Word16 *param_lpc, Word16 mode ); +Word16 encode_lpc_avq( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 numlpc, /* i : Number of sets of lpc */ + const Word16* param_lpc, /* i : lpc parameters */ + const Word16 core, /* i : core */ + const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ +); Word16 dlpc_avq( Word16 *index, /* (i) Quantization indices */ @@ -10388,33 +10412,51 @@ Word16 dlpc_avq( Word16 numlpc, /* (i) Number of sets of lpc */ Word32 sr_core ); +Word16 decode_lpc_avq( + Decoder_State_fx* st, /* i/o: decoder state structure */ + const Word16 numlpc, /* i : Number of sets of lpc */ + Word16* param_lpc /* o : lpc parameters */ +#ifdef IVAS_CODE_AVQ_LPC + , const Word16 ch, /* i : channel */ + const Word16 element_mode, /* i : element mode */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ +#endif +); -Word16 decode_lpc_avq( Decoder_State_fx *st, Word16 numlpc, Word16 *param_lpc ); - -Word16 vlpc_1st_cod(const Word16 *lsf, /* input: vector to quantize */ +Word16 vlpc_1st_cod(const Word16 *lsf, /* i : vector to quantize */ Word16 *lsfq /* i/o: i:prediction o:quantized lsf */ ,Word16 *wout /* o: lsf weights */ ,Word16 rf_mode ); -Word16 vlpc_2st_cod( /* output: number of allocated bits */ - const Word16 *lsf, /* input: normalized vector to quantize (3Q12) */ - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage (3Q12) */ - Word16 *indx, /* output: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ - Word32 sr_core +Word16 vlpc_2st_cod( /* o : number of allocated bits */ + const Word16* lsf, /* i : normalized vector to quantize */ + Word16* lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16* indx, /* o : index[] (4 bits per words) */ + const Word16 mode, /* i : 0=abs, >0=rel */ + const Word32 sr_core/* i : internal sampling rate */ ); void vlpc_2st_dec( Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16 *indx, /* input: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ + Word16 *indx, /* i : index[] (4 bits per words) */ + Word16 mode, /* i : 0=abs, >0=rel */ Word32 sr_core); void open_decoder_LPD( - Decoder_State_fx *st, - Word32 bitrate, - Word16 bandwidth + Decoder_State_fx* st, + const Word32 total_brate, +#ifdef NEW_IVAS_OPEN_DEC + const Word32 last_total_brate, +#endif + const Word16 bwidth +#ifdef NEW_IVAS_OPEN_DEC + , const Word16 is_mct, /* i : MCT mode flag */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + const Word16 last_element_mode, +#endif + const Word16 is_init /* i : indicate call from init_decoder() to avoid double TC initialization */ +#endif ); @@ -10432,59 +10474,65 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth_in, Word32 ); void decoder_LPD( - Word16 signal_out[], /* output: signal with LPD delay (7 subfrs) */ - Word16 signal_outFB[], - Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ - Decoder_State_fx *st , /* i/o: decoder memory state pointer */ - Word16 *bpf_noise_buf, - Word16 bfi, - Word16 *bitsRead, - Word16 *coder_type, - Word16 param[], - Word16 *pitch_buf, - Word16 *voice_factors, - Word16 *ptr_bwe_exc + Word16 signal_out[], /* o : signal with LPD delay (7 subfrs) */ + Word16 signal_outFB[], /* o : synthesis @output_FS */ + Word16* total_nbbits, /* i/o: number of bits / decoded bits */ + Decoder_State_fx* st, /* i/o: decoder memory state pointer */ + Word16* bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 bfi, /* i : BFI flag */ + Word16* bitsRead, /* o : number of read bits */ + Word16 param[], /* o : buffer of parameters */ + Word16* pitch_buf, /* i/o: floating pitch values for each subfr*/ + Word16* voice_factors, /* o : voicing factors */ + Word16* ptr_bwe_exc /* o : excitation for SWB TBE */ ); Word16 dec_acelp_tcx_frame( - Decoder_State_fx *st, - Word16 *coder_type, - Word16 *concealWholeFrame, - Word16 *pcmBuf, - Word16 * bpf_noise_buf, - Word16 * pcmbufFB, - Word32 bwe_exc_extended[], - Word16 *voice_factors, - Word16 pitch_buf[] -); + Decoder_State_fx* st, /* i/o: decoder state structure */ + Word16* concealWholeFrame, /* i/o: concealment flag */ + Word16* pcmBuf, /* o : synthesis */ + Word16* bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16* pcmbufFB, /* o : synthesis @output_FS */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16* voice_factors, /* o : voicing factors */ + Word16 pitch_buf[] /* o : floating pitch for each subframe */ +#ifdef IVAS_CODE_CNG + , STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ +#endif + ); -Word16 tcxGetNoiseFillingTilt(Word16 A[], - Word16 lpcorder, - Word16 L_frame, - Word16 mode, - Word16 *noiseTiltFactor - ); +Word16 tcxGetNoiseFillingTilt( + const Word16 A[], + const Word16 lpcorder, + const Word16 L_frame, + const Word16 mode, + Word16* noiseTiltFactor +); void tcxFormantEnhancement( Word16 xn_buf[], - Word16 gainlpc[], Word16 gainlpc_e[], - Word32 spectrum[], Word16 *spectrum_e, - Word16 L_frame - ,Word16 L_frameTCX + const Word16 gainlpc[], + const Word16 gainlpc_e[], + Word32 spectrum[], + Word16* spectrum_e, + const Word16 L_frame, + const Word16 L_frameTCX ); -void tcxInvertWindowGrouping(TCX_config *tcx_cfg, - Word32 xn_buf[], - Word32 spectrum[], - Word16 L_frame, - Word8 fUseTns, - Word16 last_core, - Word16 index, - Word16 frame_cnt, - Word16 bfi); +void tcxInvertWindowGrouping( + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word32 xn_buf[], + Word32 spectrum[], + const Word16 L_frame, + const Word8 fUseTns, + const Word16 last_core, + const Word16 index, + const Word16 frame_cnt, + const Word16 bfi +); /*lerp.h*/ @@ -10492,30 +10540,59 @@ void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize); void attenuateNbSpectrum(Word16 L_frame, Word32 *spectrum); -Word8 getTcxonly(const Word32 bitrate); -Word8 getCtxHm(const Word32 bitrate, const Word16 rf_flag); +Word16 getTcxonly( +#ifdef IVAS_CODE_SWITCHING + const Word16 element_mode, /* i : IVAS element mode */ +#endif + const Word32 total_brate /* i : total bitrate */ +#ifdef IVAS_CODE_SWITCHING + , const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const int16_t is_ism_format /* i : flag indicating ISM format */ +#endif +); +Word8 getCtxHm( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_flag /* i : flag to signal the RF mode */ +); Word8 getResq(const Word32 bitrate); -Word8 getTnsAllowed(const Word32 bitrate - ,const Word16 igf - ); +Word16 getTnsAllowed( + const Word32 total_brate, /* i : total bitrate */ + const Word16 igf, /* i : flag indicating IGF activity*/ + const Word16 element_mode /* i : IVAS element mode */ +); -Word8 getRestrictedMode(const Word32 bitrate, const Word16 Opt_AMR_WB); +Word8 getRestrictedMode( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +); Word16 sr2fscale(const Word32 sr); -Word32 getCoreSamplerateMode2(const Word32 bitrate, const Word16 bandwidth, const Word16 rf_flag); +Word32 getCoreSamplerateMode2( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ +); Word16 getTcxBandwidth(const Word16 bandwidth); -Word8 getIgfPresent( - const Word32 bitrate, - const Word16 bandwidth - , const Word16 rf_mode +Word16 getIgfPresent( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 rf_mode /* i : flag to signal the RF mode */ ); -Word8 getCnaPresent( - const Word32 bitrate, - const Word16 bandwidth +Word16 getCnaPresent( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth /* i : audio bandwidth */ ); Word8 getTcxLtp( @@ -10534,9 +10611,9 @@ Word16 initPitchLagParameters( Word16 getNumTcxCodedLines(const Word16 bwidth); Word16 getTcxLpcShapedAri( - const Word32 total_brate, - const Word16 bwidth - ,const Word16 rf_mode + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const Word16 element_mode /* i : IVAS element mode */ ); @@ -10550,16 +10627,17 @@ void subband_FFT( Word16 *fftoQ /*(o) the Scaling */ ); -void UpdateState( T_CldfbVadState *vad_state, - Word16 vad_flag, - Word32 frame_energy, /*(i) current frame energy*/ - Word16 sacle_sbpower, /*(i) the Scaling of current frame energy*/ - Word32 update_flag, /*(i) current frame update flag*/ - Word16 music_backgound_f, /*(i) backgound music flag*/ - Word32 HB_Power, /*(i) current frame high frequency energy*/ - Word16 HB_Power_Q /*(i) the Scaling of current frame high frequency energy*/ - ,Word32 snr - ); +void UpdateState( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 vad_flag, /* i : VAD flag */ + Word32 frame_energy, /* i : current frame energy */ + Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ + Word32 update_flag, /* i : current frame update flag */ + Word16 music_backgound_f, /* i : background music flag */ + Word32 HB_Power, /* i : current frame high frequency energy */ + Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + Word32 snr +); void calc_snr_flux( Word32 tsnr_fix, /*(i) time-domain SNR*/ Word32 *pre_snr, /*(io)time-domain SNR storage*/ @@ -10567,112 +10645,122 @@ void calc_snr_flux( Word32 tsnr_fix, /*(i) time-domain SNR*/ ); Word16 update_decision( - T_CldfbVadState *st, - Word32 frame_energy, /*(i) current frame energy*/ - Word32 HB_Power, /*(i) current frame high frequency energy*/ - Word16 frameloop, /*(i) amount of frames*/ - Word16 bw, /*(i) band width index*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 HB_Power_Q, /*(i) the Scaling of current frame high frequency energy*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word16 vad_flag, - Word16 music_backgound_f /*(i) background music flag*/ -); - -void frame_spec_dif_cor_rate( T_CldfbVadState *st, /*(io) vad state*/ - Word32 *spec_amp, /*(i) spectral amplitude*/ - Word16 sacle, /*(i) the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /*(o) tonality rate*/ - ); - -void ltd_stable( T_CldfbVadState *st, /*(io) vad state*/ - Word16 *ltd_stable_rate, /*(o) time-domain stable rate*/ - Word32 frame_energy, /*(i) current frame energy*/ - Word16 frameloop, /*(i) amount of frames*/ - Word16 Q_frames_power /*(i) the Scaling of frames_power*/ - ); - -void snr_calc( T_CldfbVadState *st, /*(io) vad state*/ - Word16 sacle_sbpower, /*(i) the Scaling of sbpower*/ - Word32 *snr, /*(o) frequency domain SNR */ - Word32 *tsnr, /*(o) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word32 bandwith /*(i) band width*/ - ); - -void bg_music_decision( T_CldfbVadState *st, - Word16 *music_backgound_f, /*(i) background music flag*/ - Word32 frame_energy, /*(i) current frame energy 1*/ - Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ - ); - -void background_update( T_CldfbVadState *st, - Word16 scale, /*(i) the Scaling of frame energy*/ - Word32 frame_energy, /*(i) current frame energy*/ - Word32 update_flag, /*(i) update flag*/ - Word16 music_backgound_f /*(i) background music flag*/ - ,Word32 snr - ); - -void spec_center( Word32* sb_power, /*(i) energy of sub-band divided uniformly*/ - Word16* sp_center, /*(o) spectral center*/ - Word32 bandwith, /*(i) band width*/ - Word16 Q_sb_p /*(i) the Scaling of sb_power*/ - ); + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word32 frame_energy, /* i : current frame energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 bw, /* i : band width index*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 tsnr, /* i : time domain SNR */ + const Word16 vad_flag, /* i : VAD flag */ + const Word16 music_backgound_f /* i : background music flag*/ +); + +void frame_spec_dif_cor_rate( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32* spec_amp, /* i : spectral amplitude*/ + Word16 sacle, /* i : the scaling of spec_amp*/ + Word16 f_tonality_rate[3] /* o : tonality rate*/ +); + +void ltd_stable( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16* ltd_stable_rate, /* o : time-domain stable rate*/ + const Word32 frame_energy, /* i : current frame energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 Q_frames_power /* i : the Scaling of frames_power*/ +); + +void snr_calc( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32* snr, /* o : frequency domain SNR */ + Word32* tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ +); + +void bg_music_decision( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *music_backgound_f, /*(i) background music flag*/ + Word32 frame_energy, /*(i) current frame energy 1*/ + Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ +); + +void background_update( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy*/ + Word32 frame_energy, /* i : current frame energy*/ + Word32 update_flag, /* i : update flag*/ + Word16 music_backgound_f, /* i : background music flag*/ + Word32 snr +); + +void spec_center( + Word32* sb_power, /* i : energy of sub-band divided uniformly*/ + Word16* sp_center, /* o : spectral center*/ + const Word32 bandwith, /* i : band width*/ + const Word16 Q_sb_p /* i : the Scaling of sb_power*/ +); void spec_flatness( Word32 *spec_amp, /*(i) spectral amplitude*/ Word32 smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ Word16 sSFM[5] /*(o) spectral flatness rate*/ ); -void calc_lt_snr( T_CldfbVadState *st, /*(io) vad state*/ - Word32 *lt_snr_org, /*(o) original long time SNR*/ - Word32 *lt_snr, /*(o) long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /*(i) foreground energy sum */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word32 bg_energy, /*(i) background energy sum */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index, /*(i) band width index*/ - Word16 lt_noise_sp_center0 /*(i) long time noise spectral center by 0*/ - ); - -Word16 vad_decision( T_CldfbVadState *st, - Word32 l_snr, /*(i) long time frequency domain*/ - Word32 lt_snr_org, /*(i) original long time SNR*/ - Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ - Word32 snr_flux, /*(i) average tsnr of several frames*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word16 music_backgound_f, /*(i) background music flag*/ - Word16 frame_energy_Q /*(i) the scaling of current frame energy*/ - ); - -Word16 comvad_decision( T_CldfbVadState *st, - Word32 l_snr, /*(i) long time frequency domain*/ - Word32 lt_snr_org, /*(i) original long time SNR*/ - Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ - Word32 snr_flux, /*(i) average tsnr of several frames*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word16 music_backgound_f, /*(i) background music flag*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 *cldfb_addition, /*(o) adjust the harmonized hangover */ - Word16 vada_flag - ); +void calc_lt_snr( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32* lt_snr_org_fp, /* o : original long time SNR*/ + Word32* lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ + Word32 fg_energy, /* i : foreground energy sum */ + Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + Word32 bg_energy, /* i : background energy sum */ + Word16 bg_energy_count, /* i : amount of the background energy frame */ + Word16 bw_index, /* i : band width index*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ +); + +Word16 vad_decision( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 l_snr, /*(i) long time frequency domain*/ + Word32 lt_snr_org, /*(i) original long time SNR*/ + Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ + Word32 snr_flux, /*(i) average tsnr of several frames*/ + Word32 snr, /*(i) frequency domain SNR */ + Word32 tsnr, /*(i) time domain SNR */ + Word32 frame_energy, /*(i) current frame energy */ + Word16 music_backgound_f, /*(i) background music flag*/ + Word16 frame_energy_Q /*(i) the scaling of current frame energy*/ +); + +Word16 comvad_decision( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 l_snr, /*(i) long time frequency domain*/ + Word32 lt_snr_org, /*(i) original long time SNR*/ + Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ + Word32 snr_flux, /*(i) average tsnr of several frames*/ + Word32 snr, /*(i) frequency domain SNR */ + Word32 tsnr, /*(i) time domain SNR */ + Word32 frame_energy, /*(i) current frame energy */ + Word16 music_backgound_f, /*(i) background music flag*/ + Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ + Word16 *cldfb_addition, /*(o) adjust the harmonized hangover */ + Word16 vada_flag + ); void calc_lf_snr( - Word32 *lf_snr_smooth, /*(o) smoothed lf_snr*/ - Word32 *lf_snr, /*(o) long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ - Word32 l_speech_snr, /*(i) sum of active frames snr */ - Word32 l_speech_snr_count, /*(i) amount of the active frame */ - Word32 l_silence_snr, /*(i) sum of the nonactive frames snr*/ - Word32 l_silence_snr_count, /*(i) amount of the nonactive frame */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index /*(i) band width index*/ + Word32* lf_snr_smooth, /* o : smoothed lf_snr*/ + Word32* lf_snr, /* o : long time frequency domain + SNR calculated by l_speech_snr and l_silence_snr*/ + const Word32 l_speech_snr, /* i : sum of active frames snr */ + const Word32 l_speech_snr_count, /* i : amount of the active frame */ + const Word32 l_silence_snr, /* i : sum of the nonactive frames snr*/ + const Word32 l_silence_snr_count,/* i : amount of the nonactive frame */ + const Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + const Word16 bg_energy_count, /* i : amount of the background energy frame */ + const Word16 bw_index /* i : band width index*/ ); Word32 construct_snr_thresh( Word16 sp_center[], /*(i) spectral center*/ @@ -10685,31 +10773,32 @@ Word32 construct_snr_thresh( Word16 sp_center[], /*(i) spectral cen Word16 bw_index /*(i) band width index*/ ); -Word16 vad_proc(T_CldfbVadState *vad_st, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: real values */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: imag values */ - Word16 riBuffer_exp, /* i: exponent of real & imag Buffer */ - - Word16 *cldfb_addition, /*o: adjust the harmonized hangover */ - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word16 bandwidth, /* 1: NB; 2:WB;3:SWB;4:FB*/ - Word16 vada_flag - ); - -void est_energy(Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word32 *frame_sb_energy, /*(o) energy of sub-band divided non-uniformly*/ - Word32 *frame_energy2_p, /*(o) frame energy 2*/ - Word32 *HB_Power_p, /*(o) high frequency energy*/ - Word32 *frame_energy_p, /*(o) frame energy 1*/ - Word16 *sb_power_Q, /*(o) the scaling of sb_power*/ - Word16 *frame_energy2_Q, /*(o) the scaling of frame_energy*/ - Word16 *HB_Power_Q, /*(o) the scaling of HB_Power*/ - Word16 *frame_energy_Q, /*(o) the Scaling of frame_energy*/ - Word16 *frame_sb_energy_scale, /*(o) the Scaling of frame_sb_energy[]*/ - Word32 bandwidth /*(i) band width*/ - ); +Word16 vad_proc( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real values */ + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag values */ + Word16 riBuffer_exp, /* i : exponent of real & imag Buffer */ + Word16* cldfb_addition, /* o : adjust the harmonized hangover */ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word16 numBands, /* i : band width 1: NB; 2:WB;3:SWB;4:FB*/ + Word16 vada_flag /* i : VAD flag */ +); + +void est_energy( + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word32* frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ + Word32* frame_energy2_p, /* o : frame energy 2*/ + Word32* HB_Power_p, /* o : high frequency energy*/ + Word32* frame_energy_p, /* o : frame energy 1*/ + Word16* sb_power_Q, /* o : the scaling of sb_power*/ + Word16* frame_energy2_Q, /* o : the scaling of frame_energy*/ + Word16* HB_Power_Q, /* o : the scaling of HB_Power*/ + Word16* frame_energy_Q, /* o : the Scaling of frame_energy*/ + Word16* frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ + const Word32 bandwidth /* i : band width*/ +); /** * \brief Function performs a complex 16-point FFT @@ -10720,9 +10809,9 @@ void est_energy(Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy * WOPS with 32x16 bit multiplications (scale on ): 288 cycles * WOPS with 32x16 bit multiplications (scale off): 256 cycles * - * \param [i/o] re real input / output - * \param [i/o] im imag input / output - * \param [i ] s stride real and imag input / output + * \param [i/o] re real i / output + * \param [i/o] im imag i / output + * \param [i ] s stride real and imag i / output * * \return void */ @@ -10767,15 +10856,23 @@ void isf_dec_bfi( const Word16 xsfBase[] /* i : base for differential XSF coding */ ); -void tfaCalcEnv_fx(const Word16* shb_speech, Word32* enr); -Word16 tfaEnc_TBE_fx(Word32* enr, - Word16 last_core, - Word16* voicing, /* Q15 */ - Word16* pitch_buf, /* Q6 */ - Word16 Q_enr - ); +void tfaCalcEnv_fx( + const Word16* shb_speech, + Word32* enr +); +Word16 tfaEnc_TBE_fx( + const Word32* enr, + const Word16 last_core, + const Word16* voicing, /* Q15 */ + const Word16* pitch_buf, /* Q6 */ + const Word16 Q_enr +); -void tecEnc_TBE_fx(Word16* corrFlag, const Word16* voicing, Word16 coder_type); +void tecEnc_TBE_fx( + Word16* corrFlag, + const Word16* voicing, + const Word16 coder_type +); void set_TEC_TFA_code_fx(const Word16 corrFlag, Word16* tec_flag, Word16* tfa_flag); @@ -10790,22 +10887,21 @@ Word16 procTecTfa_TBE_Fx(Word16 *hb_synth_Fx, ); -void -calcGainTemp_TBE_Fx( +void calcGainTemp_TBE_Fx( Word32** pCldfbRealSrc_Fx, Word32** pCldfbImagSrc_Fx, Word16 cldfb_exp, Word16* loBuffer_Fx, - Word16 startPos, /*!< Start position of the current envelope. */ - Word16 stopPos, /*!< Stop position of the current envelope. */ - Word16 lowSubband, /* lowSubband */ + const Word16 startPos, /*!< Start position of the current envelope. */ + const Word16 stopPos, /*!< Stop position of the current envelope. */ + const Word16 lowSubband, /* lowSubband */ Word16* pGainTemp_m, - Word16* pGainTemp_e - , Word16 code + Word16* pGainTemp_e, + const Word16 code ); void resetTecEnc_Fx( - HANDLE_TEC_ENC_FX hTecEnc, + TEC_ENC_HANDLE_FX hTECEnc, Word16 flag ); @@ -10815,24 +10911,25 @@ resetTecDec_Fx( HANDLE_TEC_DEC_FX hTecDec ); + void calcHiEnvLoBuff_Fix( - Word16 noCols, - Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16 nSfb, /*!< Number of scalefactors. */ - Word32** pCldfbPow_Fix /*float** pCldfbPow*/, - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, + const Word16 noCols, + const Word16* pFreqBandTable, /*!< freqbandTable. */ + const Word16 nSfb, /*!< Number of scalefactors. */ + Word32** pCldfbPow_Fix /*float** pCldfbPow*/, + Word16* loBuffer_Fix /*float* loBuffer Q8*/, + Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, Word16 pCldfbPow_FixScale ); void calcLoEnvCheckCorrHiLo_Fix( - Word16 noCols, - Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16* loBuffer_Fix /*float* loBuffer*/, - Word16* loTempEnv_Fix /*float* loTempEnv*/, - Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16* corrFlag /*int* corrFlag*/ + const Word16 noCols, + const Word16* pFreqBandTable, /*!< freqbandTable. */ + Word16* loBuffer_Fix /*float* loBuffer Q8*/, + Word16* loTempEnv_Fix /*float* loTempEnv Q7*/, + Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, + Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, + Word16* corrFlag /*int* corrFlag*/ ); @@ -10842,11 +10939,11 @@ void calcLoEnvCheckCorrHiLo_Fix( /*----------------------------------------------------------------------* * PLC: [ACELP: Fade-out] * PLC: getLevelSynDeemph: derive on subframe basis the level of LPC - * synthesis and deeemphasis based on the given input + * synthesis and deeemphasis based on the given i *----------------------------------------------------------------------*/ Word16 getLevelSynDeemph( /*10Q5*/ - Word16 h1Init[], /* i: input value or vector to be processed */ /* Q15 */ + Word16 h1Init[], /* i: i value or vector to be processed */ /* Q15 */ Word16 const A[], /* i: LPC coefficients */ /* Qx */ Word16 const lpcorder, /* i: LPC order */ /* Q0 */ Word16 const lenLpcExc, /* i: length of the LPC excitation buffer */ /* Q0 */ @@ -10958,9 +11055,10 @@ Word32 VAD_Log2( Word32 i_s32Val, Word16 i_s16Q ); -Word16 ffr_getSfWord32( Word32 *vector, - Word16 len - ); +Word16 ffr_getSfWord32( + const Word32* vector, /*!< Pointer to i vector */ + const Word16 len /*!< Length of i vector */ +); Word32 VAD_Pow( Word32 i_s32Base, Word32 i_s32Exp, @@ -10985,44 +11083,69 @@ void cfftf( Word16* scale, ); -void getLookAheadResSig( Word16 *speechLookAhead, Word16 *A_3Q12, Word16 *res, Word16 L_frame, Word16 numSubFrame ); -void updateLSFForConcealment( HANDLE_PLC_ENC_EVS decState, Word16 *isf_14Q1, Word16 m ); -void getConcealedLP( HANDLE_PLC_ENC_EVS memDecState, Word16 *AqCon, const Word16 xsfBase[], Word16 last_good, Word16 L_frame ); -void getConcealedLSF( HANDLE_PLC_ENC_EVS memDecState, const Word16 xsfBase[], Word16 last_good, Word16 L_frame ); +void getLookAheadResSig( + Word16* speechLookAhead, + Word16* A_3Q12, + Word16* res, + const Word16 L_frame, + const Word16 numSubFrame +); +void updateLSFForConcealment( + PLC_ENC_EVS_HANDLE decState, + Word16* lsf_14Q1 +); +void getConcealedLP( + PLC_ENC_EVS_HANDLE memDecState, + Word16* AqCon, + const Word16 lsfBase[], + const Word16 last_good, + const Word16 L_frame +); +void getConcealedLSF( + PLC_ENC_EVS_HANDLE memDecState, + const Word16 lsfBase[], + const Word16 last_good, + const Word16 L_frame +); + +void RecLpcSpecPowDiffuseLc( + Word16* lspq, + Word16* lsp_old, + Word16* lsfq, + Decoder_State_fx* st, + const Word16 reset_q +); -void RecLpcSpecPowDiffuseLc( Word16 *ispq, Word16 *isp_old, Word16 *isfq, Decoder_State_fx *st - , Word16 reset_q - ); void modify_lsf( Word16 *lsf, const Word16 n, - const Word32 sr_core - , Word16 reset_q + const Word32 sr_core, + const Word16 reset_q ); void coderLookAheadInnovation( - Word16 A_3Q12[], /* input: coefficients NxAz[M+1] */ + Word16 A_3Q12[], /* i : coefficients NxAz[M+1] */ Word16 *pT, /* out: pitch for all subframe */ - HANDLE_PLC_ENC_EVS st, /* i/o: coder memory state */ - Word16 *speechLookAhead_Qx, /* i: input speech in Q(st->Qold) */ - Word16 *old_exc, /* i: input excitation in Q(st->Qold) */ - Word16 L_frame /* i: input frame length */ + PLC_ENC_EVS_HANDLE st, /* i/o: coder memory state */ + Word16 *speechLookAhead_Qx, /* i: i speech in Q(st->Qold) */ + Word16 *old_exc, /* i: i excitation in Q(st->Qold) */ + Word16 L_frame /* i: i frame length */ ); void encoderSideLossSimulation( - Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 *isf_q, /* Q1*1.28 */ - Word16 stab_fac, /* Q15 */ - Word8 calcOnlyISF, + Encoder_State_fx* st, + PLC_ENC_EVS_HANDLE hPlc_Ext, + Word16* lsf_q, /* Q1*1.28 */ + const Word16 stab_fac, /* Q15 */ + const Word8 calcOnlyISF, const Word16 L_frame ); -void enc_prm_side_Info( HANDLE_PLC_ENC_EVS hPlc_Ext, Encoder_State_fx *st ); +void enc_prm_side_Info( PLC_ENC_EVS_HANDLE hPlc_Ext, Encoder_State_fx *st ); void GplcTcxEncSetup(Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, + PLC_ENC_EVS_HANDLE hPlc_Ext, Word16 Q_new); Word16 encSideSpecPowDiffuseDetector( Word16 *isf_ref, @@ -11036,8 +11159,8 @@ Word16 encSideSpecPowDiffuseDetector( void updateSpecPowDiffuseIdx( Encoder_State_fx *st); void blend_subfr2( - Word16 *sigIn1, /* i : input signal for fade-out */ - Word16 *sigIn2, /* i : input signal for fade-in */ + Word16 *sigIn1, /* i : i signal for fade-out */ + Word16 *sigIn2, /* i : i signal for fade-in */ Word16 *sigOut /* o : output signal */ ); @@ -11047,13 +11170,13 @@ void BASOP_cfft16(Word16 *re, Word16 *im, Word16 sizeOfFft, Word16 s, Word16 *sc void BASOP_rfft(Word32 *x, Word16 sizeOfFft, Word16 *scale, Word16 isign); void BASOP_rfft16(Word16 *x, Word16 sizeOfFft, Word16 *scale, Word16 isign); -void open_PLC_ENC_EVS( - HANDLE_PLC_ENC_EVS hPlcExt, +void init_PLC_enc( + PLC_ENC_EVS_HANDLE hPlcExt, Word32 sampleRate ); void gPLC_encInfo ( - HANDLE_PLC_ENC_EVS self, + PLC_ENC_EVS_HANDLE self, Word32 modeBitrate, Word16 modeBandwidth, Word16 old_clas, @@ -11063,13 +11186,13 @@ void gPLC_encInfo ( void v_sort(Word16 *r, const Word16 lo, const Word16 up); void coder_acelp_rf( - ACELP_config *acelp_cfg_rf, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ + ACELP_config *acelp_cfg_rf, /*i /o : configuration of the ACELP coding*/ + const Word16 coder_type, /* i : coding type */ + const Word16 A[], /* i : coefficients 4xAz[M+1] */ + const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] */ + Word16 speech[], /* i : speech[-M..lg] */ + const Word16 voicing[], /* i : open-loop LTP gain */ + const Word16 T_op[], /* i : open-loop LTP lag */ Word16 stab_fac, Encoder_State_fx *st, Word16 target_bits, /* i/o : coder memory state */ diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 69b5518..5634710 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -1,18 +1,13 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ - #include "prot_fx.h" /* Function prototypes */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ - - -#include "options.h" - + /*! r: Approximate integer division for positive input using lookup table */ UWord32 intLimCDivPos_fx( UWord32 NUM, Word16 DEN @@ -23,10 +18,11 @@ UWord32 intLimCDivPos_fx( return UL_ru; } - -Word32 intLimCDivSigned_fx( +/*! r: Approximate integer division for signed input using lookup table */ +static Word32 intLimCDivSigned_fx( Word32 NUM, - Word16 DEN) + Word16 DEN +) { Word32 L_tmp; @@ -38,10 +34,11 @@ Word32 intLimCDivSigned_fx( return L_tmp; } - -Word16 shrtCDivSignedApprox( const Word16 num, - const Word16 den - ) +/*! r: Approximate integer division for negative input */ +Word16 shrtCDivSignedApprox( + const Word16 num, + const Word16 den +) { Word16 pool_part; @@ -54,9 +51,9 @@ Word16 shrtCDivSignedApprox( const Word16 num, return pool_part; } -void nearProjQ15_fx( - Word16 x, - Word16 *result +static void nearProjQ15_fx( + const Word16 x, /* i : input coefficient */ + Word16* result /* o : projection */ ) { const Word16 a[4] = {14967, -25518, 3415, 32351}; @@ -79,9 +76,10 @@ void nearProjQ15_fx( * *-------------------------------------------------------------------*/ void obtainEnergyQuantizerDensity_fx( - const Word16 L, - const Word16 R, - Word16 *Density ) + const Word16 L, /* i : left vector energy */ + const Word16 R, /* i : right vector energy */ + Word16* Density /* o : quantizer density */ +) { Word16 Rnrg, den, n; @@ -112,8 +110,8 @@ void obtainEnergyQuantizerDensity_fx( * *-------------------------------------------------------------------*/ void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, - Word16 *diracs + const Word16 dsDiracIndex, /* i : input index */ + Word16* diracs /* o : number of diracs */ ) { *diracs = dsDiracsTab[dsDiracIndex]; @@ -121,11 +119,11 @@ void dsDirac2Dirac_fx( } void dsDiracPerQuanta_fx( - const Word16 td, - const Word16 t_quanta, - const Word16 dsm, - const unsigned char* const *frQuanta, - Word16 *DsIdx + const Word16 td, /* i : Length of vector segment */ + const Word16 t_quanta, /* i : Assigned number of quanta */ + const Word16 dsm, /* i : Conservative rounding flag */ + const unsigned char* const* frQuanta, /* i : Quanta lookup table */ + Word16* DsIdx /* o : Lookup table index */ ) { const unsigned char *sv; @@ -167,7 +165,7 @@ void dsDiracPerQuanta_fx( dsIndex = add(dsIndex, lshr(sub(sv[dsIndex], t_quanta_o), 15)); dsIndex = sub(dsIndex, lshr(sub(1, dsIndex), 15)); - IF (dsm > 0) + IF (EQ_16(dsm, PVQ_CONS)) { *DsIdx=dsIndex; move16(); @@ -178,10 +176,10 @@ void dsDiracPerQuanta_fx( } void QuantaPerDsDirac_fx( - Word16 td, - Word16 dsDiracIndex, - const unsigned char* const* dimFrQuanta, - Word16 *Quanta + const Word16 td, /* i : Length of vector segment */ + const Word16 dsDiracIndex, /* i : Quanta table index */ + const unsigned char* const* dimFrQuanta, /* i : Quanta lookup table */ + Word16* Quanta /* i : Quanta */ ) { *Quanta = dimFrQuanta[td][dsDiracIndex]; @@ -195,16 +193,16 @@ void QuantaPerDsDirac_fx( } void conservativeL1Norm_fx( - Word16 L, - Word16 Qvec, - Word16 Fcons, - Word16 Qavail, - Word16 Qreserv, - Word16 Dspec, - Word16 *Dvec, - Word16 *Qspare, - Word16 *Qreservplus, - Word16 *Dspecplus + const Word16 L, /* i : Length of vector segment */ + const Word16 Qvec, /* i : Assigned number of quanta */ + const Word16 Fcons, /* i : Conservative rounding flag */ + const Word16 Qavail, /* i : Input quanta remaining */ + const Word16 Qreserv, /* i : Input quanta in reservoir */ + const Word16 Dspec, /* i : assigned diracs from bitalloc */ + Word16* Dvec, /* o : actual number of diracs */ + Word16* Qspare, /* o : Output quanta remaining */ + Word16* Qreservplus, /* o : Output quanta in reservoir */ + Word16* Dspecplus /* o : Output number of diracs */ ) { @@ -247,17 +245,18 @@ void conservativeL1Norm_fx( void bandBitsAdjustment_fx( - Word16 Brc, - UWord32 INTrc, - Word16 Bavail, - Word16 Nbands, - Word16 D, - Word16 L, - Word16 Bband, - Word16 Breserv, - Word16 *Bband_adj, - Word16 *Brem, - Word16 *Breservplus) + const Word16 Brc, /* i : Current number of read quanta in range coder */ + const UWord32 INTrc, /* i : Range coder state */ + const Word16 Bavail, /* i : Available number of quanta */ + const Word16 Nbands, /* i : Number of bands */ + const Word16 D, /* i : Remaining number of bands to encode */ + const Word16 L, /* i : Size of current band */ + const Word16 Bband, /* i : Quanta allocation for current band */ + const Word16 Breserv, /* i : Quanta reservoir */ + Word16* Bband_adj, /* o : Actual used number of quanta */ + Word16* Brem, /* o : Quanta remaining */ + Word16* Breservplus /* o : Quanta pool size */ +) { Word16 Btemp; Word16 Bff; @@ -281,13 +280,14 @@ void bandBitsAdjustment_fx( *Brem = sub(Bavail, Bff); *Bband_adj = s_min(*Brem, add(*Bband_adj, Btemp)); *Bband_adj = s_max(0, *Bband_adj); + return; } -static Word16 Ratio_base2Q11_fx( /* o : Q11 */ - const Word16 opp, /* i : Q15 */ - const Word16 near /* i : Q15 */ +static Word16 Ratio_base2Q11_fx( /* o : Q11 */ + const Word16 opp, /* i : opposite Q15 */ + const Word16 near /* i : near Q15 */ ) { Word16 mc, nc, ms, ns, d, z; @@ -310,10 +310,10 @@ static Word16 Ratio_base2Q11_fx( /* o : Q11 */ return result; } -void Ratio_rQ3_fx( - Word16 opp, - Word16 near, - Word16 *result +static void Ratio_rQ3_fx( + Word16 opp, /* i : opposite */ + Word16 near, /* i : near */ + Word16* result /* o : ratio */ ) { Word16 tmp; @@ -325,11 +325,11 @@ void Ratio_rQ3_fx( void densityAngle2RmsProjDec_fx( - Word16 D, - Word16 indexphi, - Word16 *oppQ15, - Word16 *nearQ15, - Word16 *oppRatioQ3 + const Word16 D, /* i : density */ + const Word16 indexphi, /* i : decoded index from AR dec */ + Word16* oppQ15, /* o : opposite */ + Word16* nearQ15, /* o : near */ + Word16* oppRatioQ3 /* o : ratio */ ) { Word16 phiQ14q; @@ -361,12 +361,12 @@ void densityAngle2RmsProjDec_fx( } void densityAngle2RmsProjEnc_fx( - Word16 D, - Word16 phiQ14uq, - Word16 *indexphi, - Word16 *oppQ15, - Word16 *nearQ15, - Word16 *oppRatioQ3 + const Word16 D, /* i : density */ + const Word16 phiQ14uq, /* i : angle */ + Word16* indexphi, /* o : index */ + Word16* oppQ15, /* o : opposite */ + Word16* nearQ15, /* o : near */ + Word16* oppRatioQ3 /* o : ratio */ ) { *indexphi = mult_r(shl(D, 1), phiQ14uq); @@ -380,21 +380,21 @@ void densityAngle2RmsProjEnc_fx( } void NearOppSplitAdjustment_fx( - const Word16 qband, - const Word16 qzero, - const Word16 Qac, - const UWord32 INTac, - const Word16 qglobal, - const Word16 FlagCons, - const Word16 Np, - const Word16 Nhead, - const Word16 Ntail, - const Word16 Nnear, - const Word16 Nopp, - Word16 oppRQ3, - Word16 *qnear, - Word16 *qopp, - Word16 *qglobalupd + const Word16 qband, /* i : quanta for current band */ + const Word16 qzero, /* i : range coder finalization quanta */ + const Word16 Qac, /* i : range coder current quanta */ + const UWord32 INTac, /* i : range coder state */ + const Word16 qglobal, /* i : quanta input */ + const Word16 FlagCons, /* i : conservative rounding flag */ + const Word16 Np, /* i : number of parts */ + const Word16 Nhead, /* i : first part */ + const Word16 Ntail, /* i : remaining parts */ + const Word16 Nnear, /* i : length of near component */ + const Word16 Nopp, /* i : length of opposite component */ + Word16 oppRQ3, /* i : ratio */ + Word16* qnear, /* o : quantized near */ + Word16* qopp, /* o : quantized opposite */ + Word16* qglobalupd /* o : quanta remaining */ ) { @@ -449,7 +449,7 @@ void apply_gain_fx( const Word16 *band_end, /* i : Sub band end indices */ const Word16 num_sfm, /* i : Number of bands */ const Word16 *gains, /* i : Band gain vector Q12 */ - Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ + Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ ) { Word16 band,i; @@ -477,12 +477,12 @@ void apply_gain_fx( *--------------------------------------------------------------------------*/ void fine_gain_quant_fx( - Encoder_State_fx *st_fx, - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *ord, /* i : Indices for energy order */ + const Word16 num_sfm, /* i : Number of bands */ + const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ + const Word16 *gopt /* i : Optimal gains Q12 */ ) { Word16 band; @@ -517,7 +517,7 @@ void fine_gain_quant_fx( gain_db = round_fx(L_shl(L_tmp, 17)); idx = squant_fx(gain_db, &gain_dbq, finegain_fx[gbits-1], gain_cb_size[gbits-1]); - push_indice_fx( st_fx, IND_PVQ_FINE_GAIN, idx, gbits ); + push_indice_fx( hBstr, IND_PVQ_FINE_GAIN, idx, gbits ); L_tmp = L_mult0(gain_dbq, 21771); /* 21771=0.05*log2(10) */ /* 14+17=31 */ L_tmp = L_shr(L_tmp, 15); @@ -541,7 +541,7 @@ void fine_gain_quant_fx( *-------------------------------------------------------------------*/ void srt_vec_ind16_fx ( - const Word16 *linear, /* linear input */ + const Word16 *linear,/* linear input */ Word16 *srt, /* sorted output*/ Word16 *I, /* index for sorted output */ Word16 length @@ -599,8 +599,8 @@ void srt_vec_ind16_fx ( * - 8.0 to infinity *---------------------------------------------------------------------------*/ Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ - const Word32 y, /* i: Argument must be positive (Q15) */ - const Word32 x /* i: Q15 */ + const Word32 y, /* i : near side (Argument must be positive) (Q15) */ + const Word32 x /* i : opposite side (Q15) */ ) { Word32 acc, arg; diff --git a/lib_com/range_com_fx.c b/lib_com/range_com_fx.c index 1e7aa09..036767d 100644 --- a/lib_com/range_com_fx.c +++ b/lib_com/range_com_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*-------------------------------------------------------------------* @@ -23,10 +22,16 @@ Word16 rc_get_bits2_fx( /* o: Number of bits needed */ return add(add(N, 2), norm_ul(range)); } +/*-------------------------------------------------------------------* + * rangeCoderFinalizationFBits() + * + * Fractional (Q3) bits for range coder finalization + *-------------------------------------------------------------------*/ + void rangeCoderFinalizationFBits_fx( - Word16 Brc, - UWord32 INTrc, - Word16 *FBits + Word16 Brc, /* i : Current number of decoded bits */ + UWord32 INTrc, /* i : Range coder state */ + Word16* FBits /* i : Fractional finalization bits */ ) { Word32 L_Bq15; diff --git a/lib_com/re8_ppv_fx.c b/lib_com/re8_ppv_fx.c index 873ff54..b43766b 100644 --- a/lib_com/re8_ppv_fx.c +++ b/lib_com/re8_ppv_fx.c @@ -8,8 +8,8 @@ #include "stl.h" /*-------------------------------------------------------------------* - * Prototypes - *-------------------------------------------------------------------*/ + * Local function prototypes + *-------------------------------------------------------------------*/ static void nearest_neighbor_2D8_fx( const Word32 x[], Word16 y[] ); static Word32 compute_error_2D8_fx( const Word32 x[], const Word16 y[] ); @@ -24,8 +24,8 @@ static Word32 compute_error_2D8_fx( const Word32 x[], const Word16 y[] ); * --------------------------------------------------------------*/ void re8_PPV_fx( - const Word32 x[], /* i : point in R^8Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ + const Word32 x[], /* i : point in R^8Q15 */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ ) { Word16 i, y0[8]; diff --git a/lib_com/re8_util_fx.c b/lib_com/re8_util_fx.c index b67c73f..94a410f 100644 --- a/lib_com/re8_util_fx.c +++ b/lib_com/re8_util_fx.c @@ -2,15 +2,15 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* - * Prototypes + * Local function prototypes *-------------------------------------------------------------------*/ static Word16 re8_identify_absolute_leader_fx( const Word16 y[] ); diff --git a/lib_com/recovernorm_fx.c b/lib_com/recovernorm_fx.c index f061c71..8594d38 100644 --- a/lib_com/recovernorm_fx.c +++ b/lib_com/recovernorm_fx.c @@ -1,9 +1,8 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ -#include "stl.h" /* required for wmc_tool */ #include "prot_fx.h" /* Function prototypes */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ @@ -15,10 +14,10 @@ *--------------------------------------------------------------------------*/ void recovernorm_fx( - Word16 *idxbuf, /* i : reordered quantization indices */ + const Word16 *idxbuf, /* i : reordered quantization indices */ Word16 *ynrm, /* o : recovered quantization indices */ Word16 *normqlg2, /* o : recovered quantized norms */ - Word16 nb_sfm /* i : number of SFMs */ + const Word16 nb_sfm /* i : number of SFMs */ ) { Word16 i,j,k; diff --git a/lib_com/reordvct_fx.c b/lib_com/reordvct_fx.c index 952c483..2c2ffe9 100644 --- a/lib_com/reordvct_fx.c +++ b/lib_com/reordvct_fx.c @@ -2,8 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "prot_fx.h" /* Function prototypes */ @@ -15,7 +15,7 @@ void reordvct_fx( Word16 *y, /* i/o: vector to rearrange */ - const Word16 N, /* i : dimensions */ + const Word16 N, /* i : dimensions */ Word16 *idx /* o : reordered vector index */ ) { diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 67528b9..48d3de5 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*--------------------------------------------------------------------* * Residu3_lc_fx: @@ -20,7 +20,7 @@ void Residu3_lc_fx( const Word16 a[], /* i : prediction coefficients Q12 */ const Word16 m, /* i : order of LP filter Q0 */ const Word16 x[], /* i : input signal (usually speech) Qx */ - Word16 y[], /* o : output signal (usually residual) Qx */ + Word16 y[], /* o : output signal (usually residual) Qx */ const Word16 lg, /* i : vector size Q0 */ const Word16 shift ) @@ -70,9 +70,10 @@ void Residu3_lc_fx( void Residu3_10_fx( const Word16 a[], /* i : prediction coefficients Q12 */ const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-10..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ const Word16 shift + /* (note that values x[-10..-1] are needed) */ + Word16 y[], /* o : output signal (usually residual) Qx */ + const Word16 lg, /* i : vector size Q0 */ + const Word16 shift ) { Word16 i,j; @@ -102,8 +103,8 @@ void Residu3_10_fx( void Residu3_fx( const Word16 a[], /* i : prediction coefficients Q12 */ const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-M..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ + /* (note that values x[-M..-1] are needed) */ + Word16 y[], /* o : output signal (usually residual) Qx */ const Word16 lg, /* i : vector size Q0 */ const Word16 shift ) @@ -150,18 +151,13 @@ void Residu3_fx( /*==========================================================================*/ void calc_residu_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq, /* i : quantized LP filter coefficients */ - const Word16 vad_hover_flag, - const Word16 vad_flag_dtx + Encoder_State_fx *st, /* i/o: state structure */ + const Word16 *speech, /* i : weighted speech signal */ + Word16 *res, /* o : residual signal */ + const Word16 *p_Aq /* i : quantized LP filter coefficients */ ) { Word16 i_subfr; - Word16 i; - Word16 att; - Word16 offset; FOR( i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR ) { @@ -171,40 +167,6 @@ void calc_residu_fx( /* next subframe */ p_Aq += (M+1); } - /* smoothing in case of CNG */ - test(); - IF( (st->Opt_DTX_ON_fx != 0 ) && (vad_hover_flag != 0) ) /* corresponds to line 504 in FLT acelp_core_enc.c */ - { - st->burst_ho_cnt_fx = add(st->burst_ho_cnt_fx,1); - st->burst_ho_cnt_fx = s_min(st->burst_ho_cnt_fx, HO_HIST_SIZE); - IF( NE_16(st->bwidth_fx, NB)) - { - offset = 5; - test(); - if( EQ_16(st->bwidth_fx, WB)&&st->CNG_mode_fx>=0) - { - offset = st->CNG_mode_fx; - move16(); - } - - att = CNG_burst_att_fx[offset][sub(st->burst_ho_cnt_fx,1)]; /*Q15*/ - - FOR( i = 0; i < st->L_frame_fx; i++ ) - { - res[i] = mult_r(res[i], att); - move16(); - } - } - } - ELSE - { - test(); - IF( (st->Opt_DTX_ON_fx != 0) && (vad_flag_dtx != 0) ) - { - st->burst_ho_cnt_fx = 0; - move16(); - } - } return; } diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index dba0f3a..05ee311 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -22,7 +22,17 @@ const Word32 brate_tbl[SIZE_BRATE_TBL] = ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_13k20, ACELP_16k40, ACELP_24k40, ACELP_32k, ACELP_48k, ACELP_64k, HQ_96k, HQ_128k }; - +/*----------------------------------------------------------------------------------* + * Table of bitrates + *----------------------------------------------------------------------------------*/ + /*IVAS_CNST_AND_ROM*/ +const Word32 brate_intermed_tbl[SIZE_BRATE_INTERMED_TBL] = +{ + ACELP_5k00, ACELP_6k15, ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_11k60, ACELP_12k15, ACELP_12k85, ACELP_13k20, + ACELP_14k80, ACELP_16k40, ACELP_22k60, ACELP_24k40, ACELP_29k00, ACELP_29k20, ACELP_30k20, + ACELP_30k40, ACELP_32k, ACELP_48k, ACELP_64k, HQ_96k, HQ_128k +}; +/*End of IVAS_CNST_AND_ROM*/ /*----------------------------------------------------------------------------------* * Conversion of ACELP signalling parameters (ACELP internal Fs, coder type, bandwidth, sharpening flag) to index * (to be consulted with the decision matrix) @@ -32,8 +42,6 @@ const Word32 brate_tbl[SIZE_BRATE_TBL] = * - the other values represent indices created by combining different parameters into a single value through the macro SIG2IND() *----------------------------------------------------------------------------------*/ -/* Combine coder_type, bandwidth, formant sharpening flag, and channel-aware flag into one indice */ -#define SIG2IND(ctype, bw, sf, ca_rf) ( ctype | (bw << 3) | (sf << 6) | (ca_rf << 7) ) const Word32 acelp_sig_tbl[MAX_ACELP_SIG] = { @@ -88,16 +96,27 @@ const Word32 acelp_sig_tbl[MAX_ACELP_SIG] = /* bit allocation table for end-frame LSF quantizer */ const Word16 LSF_bits_tbl[] = { +#ifdef MOD_BIT_ALLOC_ROM_TABLE + 22, 31, 24, 29, 24, 22, /* ACELP_5k00 */ + 22, 31, 24, 29, 24, 22, /* ACELP_6k15 */ +#endif /* IC UC VC GC TC AC */ 22, 37, 31, 29, 31, 22, /* ACELP_7k20 */ 22, 40, 36, 33, 34, 22, /* ACELP_8k00 */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE + 27, 40, 34, 35, 37, 27, /* ACELP_9k60 */ +#endif 31, 0, 37, 37, 40, 31, /* ACELP_11k60 */ 31, 0, 39, 39, 41, 31, /* ACELP_12k15 */ 31, 0, 38, 38, 40, 31, /* ACELP_12k85 */ 31, 0, 38, 38, 40, 31, /* ACELP_13k20 */ 31, 0, 37, 42, 42, 31, /* ACELP_14k80 */ 31, 0, 43, 40, 40, 31, /* ACELP_16k40 */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE + 31, 0, 42, 40, 40, 31, /* ACELP_22k60 */ +#else 31, 0, 42, 40, 40, 0, /* ACELP_22k60 */ +#endif 31, 0, 46, 41, 41, 31, /* ACELP_24k40 */ 41, 0, 0, 41, 41, 0, /* ACELP_29k00 */ 41, 0, 0, 41, 41, 0, /* ACELP_29k20 */ @@ -109,6 +128,32 @@ const Word16 LSF_bits_tbl[] = }; /* bit allocation table for mid-frame LSF quantizer */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE +const int16_t mid_LSF_bits_tbl[] = +{ + /* IC UC VC GC TC AC */ + 2, 5, 1, 2, 2, 2, /* ACELP_5k00 */ + 2, 5, 1, 2, 2, 2, /* ACELP_6k15 */ + 2, 5, 4, 5, 5, 2, /* ACELP_7k20 */ + 2, 5, 4, 5, 5, 2, /* ACELP_8k00 */ + 2, 5, 4, 5, 5, 2, /* ACELP_9k60 */ + 2, 5, 4, 5, 5, 2, /* ACELP_11k60 */ + 2, 5, 5, 5, 5, 2, /* ACELP_12k15 */ + 2, 5, 5, 5, 5, 2, /* ACELP_12k85 */ + 2, 5, 5, 5, 5, 2, /* ACELP_13k20 */ + 4, 0, 5, 5, 5, 4, /* ACELP_14k80 */ + 4, 0, 5, 5, 5, 4, /* ACELP_16k40 */ + 5, 0, 5, 5, 5, 5, /* ACELP_22k60 */ + 5, 0, 5, 5, 5, 5, /* ACELP_24k40 */ + 5, 0, 0, 5, 5, 5, /* ACELP_29k00 */ + 5, 0, 0, 5, 5, 5, /* ACELP_29k20 */ + 5, 0, 0, 5, 5, 5, /* ACELP_30k20 */ + 5, 0, 0, 5, 5, 5, /* ACELP_30k40 */ + 5, 0, 0, 5, 5, 5, /* ACELP_32k */ + 5, 0, 0, 5, 5, 5, /* ACELP_48k */ + 5, 0, 0, 5, 5, 5, /* ACELP_64k */ +}; +#else const Word16 mid_LSF_bits_tbl[] = { /* IC UC VC GC TC AC */ @@ -130,14 +175,21 @@ const Word16 mid_LSF_bits_tbl[] = 5, 0, 0, 5, 5, 5, /* ACELP_48k */ 5, 0, 0, 5, 5, 5, /* ACELP_64k */ }; - +#endif /* bit allocation table for scaled innovation energy prediction */ const Word16 Es_pred_bits_tbl[] = { /* UC VC GC TC */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE + 0, 0, 0, 4, /* ACELP_5k00 */ + 0, 0, 0, 4, /* ACELP_6k15 */ +#endif 0, 0, 0, 4, /* ACELP_7k20 */ 0, 0, 0, 4, /* ACELP_8k00 */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE + 0, 5, 5, 5, /* ACELP_9k60 */ +#endif 0, 5, 4, 4, /* ACELP_11k60 */ 0, 5, 5, 5, /* ACELP_12k15 */ 0, 5, 4, 5, /* ACELP_12k85 */ @@ -157,6 +209,156 @@ const Word16 Es_pred_bits_tbl[] = /* bit allocation table for gain quantizer (ACELP@12.8kHz) */ /* the 4 values allocated correspond to 4 subframes */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE +const int16_t gain_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 6,6,6,6, 7,6,6,6, 7,6,6,6, 5,5,5,5, 5,5,6,5, 5,3,6,6, 5,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_5k00 */ + 6,6,6,6, 7,6,6,6, 7,6,6,6, 5,5,5,5, 5,5,6,5, 5,3,6,6, 5,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_6k15 */ + 7,7,7,7, 7,6,6,6, 6,6,6,6, 5,5,5,5, 5,5,6,5, 5,3,6,6, 5,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_7k20 */ + 7,7,7,7, 8,7,6,6, 8,7,6,6, 5,5,5,5, 5,6,5,5, 5,3,6,6, 5,3,3,6, 3,5,5,5, 3,3,6,6, 3,3,3,14, /* ACELP_8k00 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_9k60 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,13, /* ACELP_11k60 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,14, /* ACELP_12k15 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,5, 3,3,3,14, /* ACELP_12k85 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_13k20 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_14k80 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_16k40 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,14, /* ACELP_22k60 */ + 7,7,7,7, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_24k40 */ +}; + + +/* bit allocation table for gain gain quantizer (ACELP@16kHz) */ +/* the 5 values allocated correspond to 5 subframes */ +const int16_t gain_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0,0,0,0,0, 6,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0, 0, /* ACELP_8k00 */ + 0,0,0,0,0, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,15, /* ACELP_14k80 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,15, /* ACELP_22k60 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,16, /* ACELP_24k40 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_29k00 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_29k20 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_30k20 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_30k40 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_32k */ + 12,12,12,12,12, 12,12,12,12,12, 12,12,12,12,12, 6,12,12,12,12, 6,6,12,12,12, 6,6,6,12,12, 6,6,6,6,12, /* ACELP_48k */ + 12,12,12,12,12, 12,12,12,12,12, 12,12,12,12,12, 6,12,12,12,12, 6,6,12,12,12, 6,6,6,12,12, 6,6,6,6,12 /* ACELP_64k */ +}; + +/* bit allocation table for adaptive codebook (pitch) (ACELP@12.8kHz) */ +/* the 4 values correspond to 4 subframes */ +const int16_t ACB_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 0,0,0,0, 9,5,5,5, 8,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,8, /* ACELP_5k00 */ + 0,0,0,0, 9,5,5,5, 8,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,8, /* ACELP_6k15 */ + 0,0,0,0, 9,5,5,5, 8,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,8, /* ACELP_7k20 */ + 0,0,0,0, 10,5,5,5, 9,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,5, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_8k00 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_9k60 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_11k60 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_12k15 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_12k85 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_13k20 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_14k80 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_16k40 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_22k60 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_24k40 */ +}; + +/* bit allocation table for adaptive codebook (pitch) (ACELP@16kHz) */ +/* the 5 values correspond to 5 subframes */ +const int16_t ACB_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0,0, 0,0,0, 9,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0,0, 0,0, 0,0,0,0, 0, /* ACELP_8k00 */ + 0,0, 0,0,0, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_14k80 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_22k60 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_24k40 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_29k00 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_29k20 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_30k20 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_30k40 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_32k */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_48k */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10 /* ACELP_64k */ +}; + +/* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@12.8kHz) */ +/* the 4 values correspond to 4 subframes */ +const int16_t FCB_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 8,8,8,8, 12,12,12,20, 7, 7, 0, 7, 12, 7,12,12, 12,12, 7,12, 12,12,12,12, 12,12,20,12, 12,12,12,12, 12,12,12,12, 12,12,12,20, /* ACELP_5k00 */ + 10,10,10,10, 12,12,12,20, 12, 7,12, 7, 12, 7,12,12, 12,12, 7,12, 12,12,12,12, 12,12,20,12, 12,12,12,12, 12,12,12,12, 12,12,12,20, /* ACELP_6k15 */ + 13,13,13,13, 12,12,12,20, 12,12,12,20, 12, 7,12,12, 12,12, 7,12, 12,12,12,12, 12,12,20,12, 12,12,12,12, 12,12,12,12, 12,12,12,20, /* ACELP_7k20 */ + 13,13,13,13, 12,20,12,20, 12,20,12,20, 20,12,12,12, 20,12,12,12, 20,12,20,12, 20,12,20,20, 20,12,12,20, 20,12,20,12, 12,20,12,20, /* ACELP_8k00 */ + 13,13,13,13, 20,28,20,28, 20,20,20,28, 20,20,20,20, 20,20,20,20, 20,20,28,20, 20,28,20,28, 20,28,20,20, 20,20,20,28, 20,28,20,28, /* ACELP_9k60 */ + 0, 0, 0, 0, 28,36,28,36, 28,28,28,36, 28,28,28,28, 28,28,28,28, 28,28,36,28, 28,36,28,36, 28,36,28,28, 28,28,28,36, 28,36,28,36, /* ACELP_11k60 */ + 0, 0, 0, 0, 28,36,36,36, 28,36,28,36, 36,28,28,28, 36,28,28,28, 36,28,36,28, 36,36,28,43, 28,36,28,36, 28,36,28,36, 28,36,36,36, /* ACELP_12k15 */ + 0, 0, 0, 0, 36,36,36,43, 36,36,36,36, 36,36,28,36, 36,28,36,36, 36,36,36,36, 36,36,43,43, 36,36,36,36, 36,36,36,43, 36,36,36,43, /* ACELP_12k85 */ + 0, 0, 0, 0, 36,43,36,43, 36,36,36,43, 36,36,36,36, 36,36,36,36, 36,36,43,36, 36,43,43,43, 36,43,36,36, 43,36,43,36, 36,43,36,43, /* ACELP_13k20 */ + 0, 0, 0, 0, 43,50,43,50, 43,43,43,43, 43,43,43,43, 43,43,43,43, 43,43,50,43, 43,50,50,50, 43,43,43,50, 50,43,50,43, 43,50,43,50, /* ACELP_14k80 */ + 0, 0, 0, 0, 50,56,50,56, 50,50,50,56, 56,50,50,50, 56,50,50,50, 56,50,56,56, 56,56,56,56, 50,56,50,56, 50,56,56,56, 50,56,56,56, /* ACELP_16k40 */ + 0, 0, 0, 0, 83,83,83,87, 78,83,83,83, 83,78,83,83, 83,78,83,87, 83,87,83,87, 83,87,87,92, 87,83,87,83, 87,83,87,87, 83,87,87,87, /* ACELP_22k60 */ + 0, 0, 0, 0, 92,92,92,92, 87,92,92,92, 92,87,92,92, 92,87,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, /* ACELP_24k40 */ +}; + +/* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@16kHz) */ +/* the 5 values correspond to 5 subframes */ +const int16_t FCB_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ + 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_14k80 */ + 0, 0, 0, 0, 0, 62,56,56,56,62, 62,56,56,56,56, 56,56,56,56,73, 62,56,62,62,62, 56,62,62,62,73, 62,62,62,62,68, /* ACELP_22k60 */ + 0, 0, 0, 0, 0, 68,68,68,73,73, 68,68,68,68,73, 68,73,68,73,73, 73,73,73,73,73, 73,78,73,73,78, 73,78,73,73,78, /* ACELP_24k40 */ + 12,12,12,12,12, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, /* ACELP_29k00 */ + 12,12,12,12,12, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, /* ACELP_29k20 */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_30k20 */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_30k40 */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_32k */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_48k */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36 /* ACELP_64k */ +}; + +/* bit allocation table for AVQ bits in active segments (ACELP@16kHz) */ +const int16_t AVQ_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_14k80 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_22k60 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_24k40 */ + 78, 78, 78, 78, 78, 48, 48, 48, 48, 49, 48, 49, 49, 48, 49, 50, 50, 51, 52, 52, 50, 54, 53, 54, 54, 55, 55, 55, 55, 54, 52, 56, 56, 56, 56, /* ACELP_29k00 */ + 79, 79, 79, 79, 78, 49, 49, 49, 49, 49, 50, 49, 49, 50, 49, 52, 52, 51, 52, 52, 54, 54, 53, 54, 54, 56, 55, 55, 56, 56, 56, 56, 56, 56, 56, /* ACELP_29k20 */ + 78, 78, 78, 78, 78, 50, 50, 50, 50, 49, 51, 50, 50, 50, 50, 53, 53, 53, 52, 52, 55, 55, 55, 54, 54, 57, 57, 56, 56, 56, 57, 57, 57, 57, 56, /* ACELP_30k20 */ + 79, 79, 79, 79, 78, 51, 51, 51, 50, 50, 51, 51, 51, 51, 51, 54, 54, 53, 53, 53, 56, 56, 56, 55, 54, 58, 57, 57, 57, 57, 58, 58, 58, 57, 57, /* ACELP_30k40 */ + 86, 85, 85, 85, 85, 57, 57, 57, 57, 57, 58, 58, 57, 57, 57, 60, 60, 60, 60, 59, 62, 62, 62, 62, 61, 64, 64, 64, 63, 63, 64, 64, 64, 64, 64, /* ACELP_32k */ + 143,142,142,142,142, 116,115,115,115,115, 116,116,115,115,115, 119,119,118,118,118, 121,121,121,121,121, 124,124,123,123,123, 126,126,126,126,126, /* ACELP_48k */ + 207,206,206,206,206, 180,179,179,179,179, 180,180,179,179,179, 183,183,182,182,182, 185,185,185,185,185, 188,188,187,187,187, 190,190,190,190,190 /* ACELP_64k */ +}; + +/* bit allocation table for reserved bits (ACELP@12.8kHz) */ +const int16_t reserved_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_5k00 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_6k15 */ + 1, 0, 0, 0, 0, 2, 4, 0, 3, 0, /* ACELP_7k20 */ + 14, 0, 0, 0, 0, 0, 1, 0, 0, 0, /* ACELP_8k00 */ + 46, 0, 0, 0, 1, 2, 4, 1, 4, 0, /* ACELP_9k60 */ + 0, 0, 0, 0, 1, 3, 6, 2, 6, 0, /* ACELP_11k60 */ + 0, 0, 0, 0, 2, 4, 0, 3, 7, 0, /* ACELP_12k15 */ + 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, /* ACELP_12k85 */ + 0, 0, 0, 0, 1, 4, 1, 3, 0, 0, /* ACELP_13k20 */ + 0, 0, 0, 0, 2, 5, 2, 4, 1, 1, /* ACELP_14k80 */ + 0, 0, 0, 0, 2, 0, 5, 5, 3, 3, /* ACELP_16k40 */ + 0, 0, 2, 2, 0, 1, 3, 0, 0, 1, /* ACELP_22k60 */ + 0, 0, 1, 1, 3, 8, 19, 7, 11, 11, /* ACELP_24k40 */ +}; +#else const Word16 gain_bits_tbl[] = { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ @@ -292,7 +494,7 @@ const Word16 reserved_bits_tbl[] = 0, 0, 2, 2, 0, 1, 3, 0, 0, 1, /* ACELP_22k60 */ 0, 0, 1, 1, 3, 8, 19, 7, 11, 11, /* ACELP_24k40 */ }; - +#endif /*----------------------------------------------------------------------------------* @@ -470,9 +672,9 @@ const Word16 band_end_harm[SFM_N_HARM_FB] = 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 256, 288, 320, 368, 416, 464, 512, 576, 640, 704, 800 }; +const Word16 min_lat_bits_SN_fx[] = { -1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 }; -const Word16 min_lat_bits_SN_fx[] = {-1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 - }; +#if 1 /*_DIFF_FLOAT_FIX_*/ const Word16 min_lat_bits_pred_fx[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, -1, 26, -1, 26, 16}; @@ -519,19 +721,72 @@ const Word16 offset_in_lvq_mode_pred_fx[][32] = {0,0,0,0,0,0,1,2,3,4,5,6}, /* A 16k */ {0,0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB MA*/ }; +const Word16 offset_lvq_modes_SN_fx[] = { -1,-1,26,51,77,96,-1,-1,12,36,66,90,-1,-1,105,-1,88,102,112}; /* CNG */ +const Word16 offset_lvq_modes_pred_fx[] = { 74, 95, 15, 45, -1, 66, 81, 102, 0, 30, -1, 60, 88, -1, 109, 117, -1, 139, 124 }; +#else + +const int16_t min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16 }; + +const int16_t offset_lvq_modes_SN_fx[] = { -1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135,112}; /* CNG */ + +const int16_t offset_lvq_modes_pred_fx[] = { 119, 153, 31, 67, -1, 102, 126, 160, 0, 46, -1, 82, 146, -1, 175, 191, -1, 225, 203 }; +const int16_t offset_in_lvq_mode_SN_fx[][21] = +{ + {0}, /* I NB */ + {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/ + {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0,1,1,1,1,2,3,4,5,5,5,6,6,6,7,8}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {0}, /* I WB */ + {0}, /* UV WB*/ + {1}, /* V WB */ /* granularity 1 */ + {1}, /* G WB */ /* granularity 1 */ + {1}, /* T WB */ /* granularity 1 */ + {1}, /* A WB */ /* granularity 1 */ + {0}, /* I 16k */ + {0}, /* UV 16k */ + {1}, /* V 16k */ /* granularity 1 */ + {0}, /* G 16k */ + {0,1}, /* T 16k */ + {0}, /* A 16k */ +}; +const int16_t offset_in_lvq_mode_pred_fx[][32] = +{ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */ + {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */ + {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {1}, /* I WB */ + {1}, /* UV WB */ /* granularity 1 */ + {1}, /* V WB */ /* granularity 1 */ + {1}, /* G WB */ + {0}, /* T WB */ + {1}, /* A WB */ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I 16k */ + {0}, /* UV 16k */ + {1}, /* V 16k */ + {1}, /* G 16k */ + {0}, /* T 16k */ + {1}, /* A 16k */ + {1}, /* G WB MA*/ +}; + +#endif -const Word16 offset_lvq_modes_SN_fx[] = {-1,-1,26,51,77,96,-1,-1,12,36,66,90,-1,-1,105,-1,88,102, - 112 - }; /* CNG */ -const Word16 offset_lvq_modes_pred_fx[] = {74, 95, 15, 45, -1, 66, 81, 102, 0, 30, -1, 60, 88, -1, 109, 117, -1, 139, 124}; const Word16 sfm_width[20] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8}; const Word16 a_table_fx[20] = {8, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 7, 11}; const Word16 inner_frame_tbl[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB */ +//IVAS_CODE +const Word16 l_spec_tbl[4] = { L_SPEC8k, L_SPEC16k, L_SPEC32k, L_SPEC48k }; /* corresponds to NB, WB, SWB, FB */ +const Word16 l_spec_ext_tbl[4] = { 0, L_SPEC16k_EXT, L_SPEC32k_EXT, L_SPEC48k_EXT }; /* corresponds to NB, WB, SWB, FB */ @@ -3025,7 +3280,11 @@ const Word16 CB_lsf_fx[] = 9, /* Mode 11 : AUDIO WB, Safety net */ -1, /* Mode 12 : INACTIVE WB16k, Safety net */ -1, /* Mode 13 : UNVOICED WB16k, Safety net */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE + 14, /* Mode 14 : VOICED WB16k, Safety net */ +#else -1, /* Mode 14 : VOICED WB16k, Safety net */ +#endif -1, /* Mode 15 : GENERIC WB 16k, Safety net */ 10, /* Mode 16 : TRANSITION WB16k, Safety net */ -1, /* Mode 17 : AUDIO WB16k, Safety net */ @@ -3048,7 +3307,11 @@ const Word16 CB_p_lsf_fx[] = -1, /* Mode 11 : AUDIO WB, Predictive */ 0, /* Mode 12 : INACTIVE WB16k, Predictive */ -1, /* Mode 13 : UNVOICED WB16k, Predictive */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE + 11, +#else -1, /* Mode 14 : VOICED WB16k, Predictive */ +#endif 8, /* Mode 15 : GENERIC WB16k, Predictive */ -1, /* Mode 16 : TRANSITION WB16k, Predictive */ 10, /* Mode 17 : AUDIO WB16k, Predictive */ @@ -3857,6 +4120,9 @@ const Word16 sigma_MSLVQ_fx[][16] = }; /* An 16-by-19 matrix in Scale = 2.56f */ +#ifdef MSVQ_ROM +PMT("sigma_p_fx and sigma_p_fx needs update") +#endif const Word16 sigma_p_fx[][16] = { {152, 164, 179, 170, 172, 176, 171, 169, 169, 174, 175, 216, 247, 304, 113, 110}, @@ -4010,7 +4276,698 @@ const Word16 CNG_details_codebook_fx[64][NUM_ENV_CNG]= /* Q6 */ {765,778,764,484,607,791,757,760,700,687,789,777,779,783,768,791,778,757,784,770}, {800,825,775,782,821,679,805,824,752,824,796,785,829,817,824,803,814,807,762,779} }; - +#ifdef MSVQ_ROM +PMT ("scales, scales_p, sigma and sigma_p needs update") + +const Word16 leaders_short[][MAX_NO_SCALES] = +{ { 0, 0, 0}, +{ 1, 0, 0}, +{ 15, 3, 3}, +{ 2, 2, 0}, +{ 2, 0, 0}, +{ 2, 1, 0}, +{ 4, 0, 0}, +{ 9, 7, 6}, +{ 4, 1, 0}, +{ 5, 2, 0}, +{ 6, 3, 2}, +{ 5, 3, 1}, +{ 8, 3, 0}, +{ 9, 3, 0}, +{ 2, 2, 1}, +{ 9, 8, 5}, +{ 5, 5, 0}, +{ 17, 3, 0}, +{ 5, 2, 1}, +{ 7, 3, 0}, +{ 5, 4, 0}, +{ 5, 5, 1}, +{ 2, 2, 2}, +{ 4, 2, 2}, +{ 5, 2, 2}, +{ 6, 6, 5}, +{ 5, 3, 2}, +{ 6, 3, 0}, +{ 12, 3, 2}, +{ 15, 3, 2}, +{ 19, 3, 2}, +{ 7, 6, 3}, +{ 5, 4, 2}, +{ 9, 8, 2}, +{ 6, 5, 2}, +{ 5, 4, 1}, +{ 9, 9, 3}, +{ 6, 6, 2}, +{ 8, 6, 2}, +{ 8, 7, 2}, +{ 8, 8, 2}, +{ 4, 2, 0}, +{ 11, 8, 2}, +{ 13, 11, 2}, +{ 5, 5, 2}, +{ 16, 13, 2}, +{ 13, 12, 2}, +{ 18, 17, 2}, +{ 21, 17, 2}, +{ 18, 16, 2}, +{ 32, 28, 2}, +{ 8, 8, 4}, +{ 7, 5, 2}, +{ 13, 11, 9}, +{ 38, 31, 2}, +{ 4, 4, 2}, +{ 8, 8, 3}, +{ 9, 8, 3}, +{ 8, 5, 2}, +{ 10, 9, 3}, +{ 11, 10, 3}, +{ 13, 10, 3}, +{ 22, 10, 3}, +{ 23, 10, 3}, +{ 13, 11, 3}, +{ 15, 13, 3}, +{ 35, 15, 3}, +{ 32, 16, 3}, +{ 5, 5, 4}, +{ 8, 7, 4}, +{ 33, 31, 2}, +{ 9, 9, 4}, +{ 16, 12, 4}, +{ 17, 13, 4}, +{ 5, 5, 5}, +{ 7, 5, 5}, +{ 4, 3, 2}, +{ 8, 6, 5}, +{ 9, 6, 5}, +{ 9, 7, 5}, +{ 8, 8, 5}, +{ 3, 2, 0}, +{ 10, 8, 5}, +{ 11, 8, 5}, +{ 12, 8, 5}, +{ 13, 8, 5}, +{ 16, 8, 5}, +{ 18, 8, 5}, +{ 10, 9, 5}, +{ 18, 9, 5}, +{ 23, 21, 2}, +{ 13, 8, 8}, +{ 14, 10, 5}, +{ 11, 11, 5}, +{ 13, 11, 5}, +{ 13, 13, 5}, +{ 14, 13, 5}, +{ 15, 13, 5}, +{ 16, 13, 5}, +{ 17, 13, 5}, +{ 18, 13, 5}, +{ 18, 16, 5}, +{ 18, 17, 5}, +{ 19, 18, 5}, +{ 13, 10, 5}, +{ 21, 21, 5}, +{ 23, 21, 5}, +{ 24, 21, 5}, +{ 25, 23, 5}, +{ 32, 23, 5}, +{ 11, 10, 5}, +{ 8, 8, 6}, +{ 5, 5, 7}, +{ 8, 7, 7}, +{ 8, 8, 7}, +{ 10, 8, 7}, +{ 13, 8, 7}, +{ 10, 9, 7}, +{ 13, 11, 7}, +{ 9, 8, 8}, +{ 12, 8, 8}, +{ 23, 18, 5}, +{ 9, 9, 8}, +{ 11, 9, 8}, +{ 13, 9, 8}, +{ 18, 10, 8}, +{ 26, 10, 8}, +{ 27, 10, 8}, +{ 31, 10, 8}, +{ 40, 21, 11}, +{ 13, 11, 8}, +{ 13, 12, 8}, +{ 14, 12, 8}, +{ 18, 12, 8}, +{ 13, 13, 8}, +{ 14, 13, 8}, +{ 16, 13, 8}, +{ 18, 13, 8}, +{ 18, 16, 8}, +{ 18, 17, 8}, +{ 23, 18, 8}, +{ 23, 21, 8}, +{ 24, 21, 8}, +{ 28, 23, 8}, +{ 31, 31, 8}, +{ 36, 31, 8}, +{ 38, 31, 8}, +{ 11, 9, 9}, +{ 12, 9, 9}, +{ 13, 9, 9}, +{ 12, 11, 9}, +{ 42, 31, 2}, +{ 14, 12, 9}, +{ 13, 13, 9}, +{ 14, 13, 9}, +{ 16, 13, 9}, +{ 17, 13, 9}, +{ 18, 13, 9}, +{ 18, 14, 9}, +{ 18, 18, 9}, +{ 26, 25, 9}, +{ 13, 11, 10}, +{ 18, 12, 10}, +{ 18, 13, 10}, +{ 21, 14, 10}, +{ 22, 16, 10}, +{ 18, 18, 10}, +{ 23, 18, 10}, +{ 24, 18, 10}, +{ 24, 21, 10}, +{ 23, 22, 10}, +{ 24, 23, 10}, +{ 32, 25, 10}, +{ 34, 28, 10}, +{ 42, 31, 10}, +{ 17, 11, 11}, +{ 18, 13, 11}, +{ 21, 13, 11}, +{ 18, 17, 11}, +{ 18, 18, 11}, +{ 48, 35, 24}, +{ 18, 17, 12}, +{ 18, 18, 12}, +{ 20, 18, 12}, +{ 39, 30, 12}, +{ 31, 31, 12}, +{ 43, 34, 12}, +{ 16, 13, 13}, +{ 17, 13, 13}, +{ 16, 16, 13}, +{ 18, 17, 13}, +{ 20, 18, 13}, +{ 22, 18, 13}, +{ 23, 18, 13}, +{ 22, 21, 13}, +{ 23, 23, 13}, +{ 24, 23, 13}, +{ 43, 36, 13}, +{ 43, 40, 13}, +{ 43, 41, 13}, +{ 31, 30, 18}, +{ 24, 21, 14}, +{ 31, 31, 14}, +{ 23, 18, 16}, +{ 23, 23, 16}, +{ 31, 25, 16}, +{ 31, 29, 16}, +{ 45, 35, 16}, +{ 23, 21, 17}, +{ 23, 22, 17}, +{ 23, 23, 17}, +{ 31, 31, 17}, +{ 21, 18, 18}, +{ 23, 21, 18}, +{ 23, 22, 18}, +{ 27, 23, 18}, +{ 29, 23, 18}, +{ 32, 23, 18}, +{ 31, 27, 18}, +{ 30, 28, 18}, +{ 31, 28, 18}, +{ 43, 42, 13}, +{ 31, 31, 18}, +{ 32, 31, 18}, +{ 36, 31, 18}, +{ 46, 48, 18}, +{ 46, 32, 19}, +{ 43, 38, 19}, +{ 43, 42, 19}, +{ 32, 32, 20}, +{ 27, 23, 21}, +{ 31, 23, 21}, +{ 31, 24, 21}, +{ 32, 30, 21}, +{ 32, 31, 21}, +{ 43, 33, 21}, +{ 43, 34, 21}, +{ 24, 23, 23}, +{ 32, 32, 23}, +{ 48, 40, 23}, +{ 48, 46, 23}, +{ 28, 24, 24}, +{ 32, 31, 24}, +{ 34, 32, 24}, +{ 36, 32, 24}, +{ 48, 32, 24}, +{ 35, 10, 8}, +{ 40, 28, 25}, +{ 45, 31, 25}, +{ 44, 32, 25}, +{ 31, 31, 27}, +{ 39, 32, 27}, +{ 44, 32, 27}, +{ 32, 32, 28}, +{ 43, 32, 28}, +{ 48, 32, 28}, +{ 36, 36, 28}, +{ 48, 45, 28}, +{ 40, 32, 29}, +{ 44, 34, 30}, +{ 40, 32, 31}, +{ 41, 32, 31}, +{ 42, 32, 31}, +{ 44, 43, 31}, +{ 48, 37, 32}, +{ 48, 39, 32}, +{ 46, 43, 32}, +{ 48, 48, 34}, +{ 48, 36, 35}, +{ 48, 41, 35}, +{ 47, 43, 36}, +{ 48, 48, 37}, +{ 48, 48, 40}, +{ 48, 48, 45}, +{ 48, 48, 47}, +{ 48, 48, 48} }; + +const Word16 no_lead_idx[][2] = { +{ 1, 1}, +{ 4, 1}, +{ 41, 1}, +{ 41, 4}, +{ 52, 32}, +{ 56, 38}, +{ 41, 1}, +{ 6, 5}, +{119, 14}, +{ 58, 18}, +{138, 21}, +{169, 40}, +{ 4, 4}, +{ 41, 1}, +{ 35, 1}, +{ 35, 4}, +{ 52, 4}, +{ 18, 8}, +{ 44, 41}, +{ 58, 6}, +{ 58, 9}, +{ 69, 26}, +{ 51, 34}, +{ 85, 34}, +{ 85, 38}, +{ 85, 42}, +{139, 40}, +{142, 33}, +{140, 64}, +{141, 73}, +{236, 124}, +{235, 133}, +{211, 160}, +{ 4, 3}, +{ 41, 1}, +{ 52, 3}, +{ 39, 3}, +{ 42, 3}, +{153, 3}, +{118, 9}, +{158, 44}, +{202, 93}, +{250, 201}, +{ 20, 0}, +{ 52, 0}, +{ 1, 1}, +{ 4, 1}, +{ 4, 4}, +{ 4, 4}, +{ 41, 1}, +{ 41, 4}, +{ 20, 4}, +{ 52, 4}, +{ 39, 4}, +{ 44, 41}, +{ 58, 6}, +{ 80, 41}, +{114, 9}, +{124, 9}, +{130, 21}, +{124, 58}, +{165, 34}, +{164, 39}, +{169, 40}, +{ 35, 0}, +{ 4, 4}, +{ 35, 1}, +{ 35, 4}, +{ 52, 4}, +{ 58, 5}, +{ 15, 5}, +{135, 3}, +{116, 41}, +{124, 24}, +{137, 24}, +{177, 26}, +{194, 44}, +{208, 52}, +{230, 58}, +{ 4, 4}, +{ 41, 1}, +{ 41, 4}, +{ 20, 4}, +{ 8, 6}, +{ 9, 8}, +{ 44, 41}, +{ 58, 6}, +{ 58, 9}, +{114, 9}, +{124, 9}, +{ 92, 21}, +{124, 58}, +{ 92, 51}, +{104, 91}, +{141, 51}, +{121, 91}, +{ 4, 3}, +{ 41, 1}, +{ 52, 3}, +{ 69, 3}, +{ 83, 3}, +{ 87, 3}, +{ 86, 44}, +{143, 74}, +{144, 112}, +{179, 78}, +{196, 78}, +{196, 78}, +{224, 78}, +{ 4, 3}, +{ 41, 1}, +{ 20, 1}, +{ 20, 4}, +{ 52, 4}, +{ 52, 3}, +{111, 5}, +{132, 4}, +{ 57, 41}, +{123, 41}, +{214, 3}, +{183, 81}, +{215, 41}, +{213, 32}, +{219, 44}, +{233, 52}, +{ 7, 52}, +{ 3, 57}, +{ 14, 59}, +{ 11, 53}, +{ 62, 0}, +{ 37, 4}, +{ 37, 3}, +{ 63, 3}, +{ 67, 3}, +{184, 3}, +{123, 41}, +{ 19, 124}, +{ 39, 4}, +{ 44, 41}, +{ 58, 6}, +{ 58, 9}, +{ 58, 44}, +{115, 32}, +{ 95, 16}, +{102, 21}, +{ 99, 38}, +{126, 58}, +{141, 57}, +{206, 56}, +{205, 120}, +{226, 124}, +{226, 133}, +{225, 182}, +{152, 3}, +{ 65, 3}, +{ 17, 14}, +{ 61, 22}, +{135, 3}, +{ 19, 11}, +{ 76, 25}, +{ 41, 36}, +{ 41, 33}, +{ 41, 7}, +{ 27, 10}, +{ 81, 15}, +{ 3, 2}, +{ 41, 36}, +{ 55, 31}, +{ 81, 7}, +}; +const Word16 no_lead_p_idx[][2] = { + { 5, 0}, +{ 3, 0}, +{ 41, 0}, +{ 35, 0}, +{ 52, 0}, +{ 1, 1}, +{ 4, 1}, +{ 4, 4}, +{ 3, 4}, +{ 41, 1}, +{ 41, 4}, +{ 35, 4}, +{ 52, 4}, +{ 39, 4}, +{ 44, 41}, +{ 58, 6}, +{ 80, 41}, +{ 15, 9}, +{ 94, 9}, +{110, 34}, +{ 96, 52}, +{ 98, 39}, +{105, 58}, +{107, 51}, +{105, 104}, +{109, 94}, +{145, 98}, +{207, 100}, +{239, 103}, +{240, 108}, +{207, 146}, +{ 4, 0}, +{ 41, 4}, +{ 39, 3}, +{ 94, 5}, +{ 80, 41}, +{ 94, 18}, +{ 94, 44}, +{ 96, 52}, +{106, 44}, +{121, 58}, +{107, 51}, +{199, 15}, +{197, 104}, +{198, 156}, +{221, 200}, +{ 4, 1}, +{ 3, 1}, +{ 3, 4}, +{ 41, 1}, +{ 35, 1}, +{ 35, 4}, +{ 52, 4}, +{ 39, 4}, +{ 88, 4}, +{135, 4}, +{135, 3}, +{190, 3}, +{155, 41}, +{135, 20}, +{190, 32}, +{194, 44}, +{231, 44}, +{230, 58}, +{231, 15}, +{242, 83}, +{253, 130}, +{ 4, 1}, +{ 32, 1}, +{ 58, 5}, +{ 39, 3}, +{ 43, 5}, +{ 45, 3}, +{ 48, 3}, +{ 46, 44}, +{ 49, 44}, +{ 90, 44}, +{ 50, 44}, +{ 54, 52}, +{ 70, 51}, +{151, 122}, +{151, 53}, +{ 52, 4}, +{ 39, 4}, +{ 83, 4}, +{ 89, 4}, +{ 80, 41}, +{ 85, 41}, +{100, 8}, +{101, 9}, +{ 85, 38}, +{ 85, 15}, +{195, 52}, +{234, 52}, +{217, 15}, +{254, 15}, +{251, 104}, +{ 10, 153}, +{ 18, 157}, +{ 19, 192}, +{ 19, 237}, +{ 19, 0}, +{ 52, 4}, +{153, 3}, +{159, 3}, +{171, 32}, +{185, 44}, +{186, 68}, +{ 85, 15}, +{220, 44}, +{218, 75}, +{227, 75}, +{ 1, 77}, +{228, 147}, +{ 15, 150}, +{ 18, 187}, +{ 16, 212}, +{ 16, 241}, +{ 17, 248}, +{ 4, 3}, +{ 52, 4}, +{ 52, 3}, +{161, 3}, +{166, 3}, +{149, 9}, +{247, 47}, +{178, 0}, +{ 41, 1}, +{ 20, 1}, +{ 20, 4}, +{ 52, 4}, +{ 58, 5}, +{117, 4}, +{117, 3}, +{153, 3}, +{182, 3}, +{204, 3}, +{162, 9}, +{163, 44}, +{167, 44}, +{173, 44}, +{254, 44}, +{ 12, 52}, +{254, 15}, +{ 13, 82}, +{244, 188}, +{ 3, 4}, +{ 52, 4}, +{ 58, 5}, +{153, 3}, +{190, 3}, +{209, 3}, +{243, 189}, +{ 41, 1}, +{ 20, 1}, +{ 39, 4}, +{ 88, 4}, +{ 97, 4}, +{138, 21}, +{ 6, 44}, +{ 1, 1}, +{ 4, 1}, +{ 4, 4}, +{ 5, 4}, +{ 41, 1}, +{ 41, 4}, +{ 20, 4}, +{ 52, 4}, +{ 39, 4}, +{ 83, 4}, +{135, 4}, +{ 80, 41}, +{116, 41}, +{136, 41}, +{110, 34}, +{ 13, 6}, +{113, 41}, +{114, 18}, +{ 91, 24}, +{125, 24}, +{127, 24}, +{163, 12}, +{168, 13}, +{172, 13}, +{128, 84}, +{174, 28}, +{252, 29}, +{249, 30}, +{246, 129}, +{246, 180}, +{ 9, 66}, +{110, 41}, +{155, 41}, +{154, 20}, +{158, 44}, +{203, 21}, +{232, 44}, +{210, 39}, +{223, 79}, +{222, 123}, +{229, 131}, +{238, 139}, +{238, 170}, +{ 4, 4}, +{ 4, 4}, +{ 41, 1}, +{ 20, 1}, +{ 20, 4}, +{ 52, 4}, +{ 39, 4}, +{ 88, 4}, +{135, 4}, +{ 80, 41}, +{110, 41}, +{136, 41}, +{134, 32}, +{176, 44}, +{193, 44}, +{195, 52}, +{210, 39}, +{242, 39}, +{ 6, 71}, +{ 2, 148}, +{ 4, 175}, +{ 5, 191}, +{110, 41}, +{204, 3}, +{216, 22}, +{210, 23}, +{195, 32}, +{220, 44}, +{210, 39}, +{222, 33}, +{245, 57}, +{255, 60}, +{ 8, 72}, +{ 8, 181}, +}; +#endif const Word16 interpol_frac_mid_fx[NB_SUBFR*3] = { 16384, 16384, 0, 0, 32767, 0, 0, 16384, 16384, @@ -4158,6 +5115,7 @@ const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS]= /*Q1 */ }; /* An 6-by-128 matrix in Scale = 2048.00f */ + const Word16 scales_fx[][6] = { {3129, 0, 0, 3138, 0, 0, }, /* 14 */ @@ -6640,6 +7598,24 @@ const Word16 gsc_sfm_size[MBANDS_GN] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, /*GSC related */ +#ifdef MOD_BIT_ALLOC_ROM_TABLE +const Word16 GSC_freq_bits[] = +{ + 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_5k00*/ + 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_6k15*/ + 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_7k20*/ + 21, 74, -4, 26, 16, 12, 11, 9, 0, 0, 4, 4, 1, 1, 3, 0, 0, /* ACELP_8k00*/ + 26, 80, -3, 28, 18, 13, 12, 9, 0, 0, 4, 4, 1, 1, 3, 0, 0, /* ACELP_9k60*/ + 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_11k60*/ + 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_12k15*/ + 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_12k85*/ + 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_13k20*/ + 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_14k80*/ + 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ + 26, 96, 0, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_22k60*/ + 26, 96, 0, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4 /* ACELP_24k40*/ +}; +#else const Word16 GSC_freq_bits[] = { 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_7k20*/ @@ -6649,7 +7625,7 @@ const Word16 GSC_freq_bits[] = 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_12k85*/ 31, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_13k20*/ }; - +#endif /***IN Q2 ****/ const Word16 mfreq_loc_Q2fx[] = { 700, 1500, 3100, 4700, 6300, 7900, 9500, 11100, 12700, 14300, 15900, 17500, 19100, 20700, 22300, 25500, 28700, 31900 }; const Word16 mfreq_loc_div_25[] = {7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 207, 223, 255, 287, 319}; @@ -7320,7 +8296,23 @@ const Word16 sm_table_fx[] = 2494, 2254, 2025, 1809, 1602, 1412, 1229, 1062, 904, 760, 629, 511, 403, 308, 226, 157, 102, 56, 26, 7, }; - +#ifdef MOD_BIT_ALLOC_ROM_TABLE +const Word32 GSC_freq_bits_fx[] = +{ + 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_5k00*/ + 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_6k15*/ + 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_7k20*/ + 5505024, 19660800, -1048576, 6815744, 4194304, 3145728, 2883584, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ + 6815744, 20971520, -786432, 7340032, 4718592, 3407872, 3145728, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ + 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_11k60*/ + 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k15*/ + 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k85*/ + 8126464, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_14k80*/ + 8126464, 25165824, -262144, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ + 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ + 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ +}; +#else const Word32 GSC_freq_bits_fx[] = { 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_7k20*/ @@ -7330,7 +8322,7 @@ const Word32 GSC_freq_bits_fx[] = 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k85*/ 8126464, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ }; - +#endif const Word32 pow2_fx[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576 @@ -15108,7 +16100,7 @@ const Word16 msQeqInvAv_thresh[3] = { 328/*0.01f Q15*/, 983/*0.03f Q15*/, const Word16 msNoiseSlopeMax[4] = { 32767/*2.f Q14*/, 26214/*1.6f Q14*/, 21299/*1.3f Q14*/, 18022/*1.1f Q14*/ }; const Word16 preemphCompensation[NB_BANDS] = { 19960/*9.7461f Q11*/, 19493/*9.5182f Q11*/, 18486/*9.0262f Q11*/, 17099/*8.3493f Q11*/, 15516/*7.5764f Q11*/, 13893/*6.7838f Q11*/, 11956/*5.8377f Q11*/, 9933/*4.8502f Q11*/, 8263/*4.0346f Q11*/, 6715/*3.2788f Q11*/, 5383/*2.6283f Q11*/, 4284/*2.0920f Q11*/, 3339/*1.6304f Q11*/, 2632/*1.2850f Q11*/, 2070/*1.0108f Q11*/, 1621/*0.7916f Q11*/, 1284/*0.6268f Q11*/, 1026/*0.5011f Q11*/, 844/*0.4119f Q11*/, 745/*0.3637f Q11*/ }; -const SCALE_SETUP scaleTable[20] = +const SCALE_SETUP scaleTableMono[SIZE_SCALE_TABLE_MONO] = { { 0, 8000, -704/*-5.5f Q7*/, 0 }, { 8000, 9600, -640/*-5.0f Q7*/, 0 }, @@ -19552,7 +20544,7 @@ const Word16 cldfb_scale_2_5ms[7] = /**********************************************************************/ /** igf settings structure for each bitrate mode **************************************************************************/ -const Word16 swb_offset_LB_new[15][IGF_MAX_SFB] = +const Word16 swb_offset_LB_new[][IGF_MAX_SFB] = { /* 0: for 9600 kbs WB */ { @@ -19590,27 +20582,35 @@ const Word16 swb_offset_LB_new[15][IGF_MAX_SFB] = { 4, 512, 534, 576, 640 }, - /* 9: for 16400 kbs FB */ + /* 9: for 64000 kbs SWB */ + { + 4, 512, 534, 576, 640 + }, + /* 10: for 16400 kbs FB */ { 10, 256, 288, 328, 376, 432, 496, 576, 640, 720, 800 }, - /* 10: for 24400 kbs FB */ + /* 11: for 24400 kbs FB */ { 11, 256, 284, 318, 358, 402, 450, 508, 576, 640, 720, 800 }, - /* 11: for 32000 kbs FB */ + /* 12: for 32000 kbs FB */ { 11, 256, 284, 318, 358, 402, 450, 508, 576, 640, 720, 800 }, - /* 12: for 48000 kbs FB */ + /* 13: for 48000 kbs FB */ + { + 5, 512, 584, 656, 728, 800 + }, + /* 14: for 64000 kbs FB */ { 5, 512, 584, 656, 728, 800 }, - /* 13: for 96000 kbs FB */ + /* 15: for 96000 kbs FB */ { 3, 640, 720, 800 /* old: 640, 760, 880 */ }, - /* 14: for 128000 kbs FB */ + /* 16: for 128000 kbs FB */ { 3, 640, 720, 800 /* old: 640, 760, 880 */ } @@ -19618,7 +20618,7 @@ const Word16 swb_offset_LB_new[15][IGF_MAX_SFB] = -const Word16 igf_whitening_TH[15][2][IGF_MAX_TILES] = +const Word16 igf_whitening_TH[][2][IGF_MAX_TILES] = { /* 0: for 9600 kbs WB */ { @@ -19665,32 +20665,42 @@ const Word16 igf_whitening_TH[15][2][IGF_MAX_TILES] = /* medium */ { 9421/*1.15f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, /* strong */ { 9748/*1.19f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} }, - /* 9: for 16400 kbs FB */ + /* 9: for 64000 kbs SWB */ + { + /* medium */ { 9421/*1.15f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 9748/*1.19f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 10: for 16400 kbs FB */ { /* medium */ { 5161/*0.63f Q13*/, 2212/*0.27f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/}, /* strong */ { 12534/*1.53f Q13*/, 10813/*1.32f Q13*/, 5489/*0.67f Q13*/, 0/*0.f Q13*/} }, - /* 10: for 24400 kbs FB */ + /* 11: for 24400 kbs FB */ { /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} }, - /* 11: for 32000 kbs FB */ + /* 12: for 32000 kbs FB */ { /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} }, - /* 12: for 48000 kbs FB */ + /* 13: for 48000 kbs FB */ + { + /* medium */ { 6554/*0.80f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 8192/*1.00f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 14: for 64000 kbs FB */ { /* medium */ { 6554/*0.80f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, /* strong */ { 8192/*1.00f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} }, - /* 13: for 96000 kbs FB */ + /* 15: for 96000 kbs FB */ { /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} }, - /* 14: for 128000 kbs FB */ + /* 16: for 128000 kbs FB */ { /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} @@ -19738,68 +20748,121 @@ const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = { +0, +1, +0, +0, +3, +0, +3} }; + const Word16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1] = { 16384, 16356, 16299, 16185, 15904, 15282, 14669, 13598, 11886, 9541, 6613, 3845, 1799, 606, 153, 32, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; -const Word16 cf_se01_tab[9][IGF_SYMBOLS_IN_TABLE + 1] = -{ - {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 9.6 kbs B*/ - {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 13.2 kbs WB RF B*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 9.6 kbs SWB B*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs A*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs SWB RF B*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 16.4 kbs B*/ - {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0}, /* 24.4 kbs B*/ - {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0}, /* 32.0 kbs A*/ - {16384, 16368, 16355, 16334, 16291, 16212, 16071, 15816, 15359, 14523, 13014, 10534, 7345, 4272, 2228, 1149, 626, 357, 215, 139, 93, 67, 53, 43, 36, 28, 22, 0} /* 48.0 kbs B*/ -}; - -const Word16 cf_se02_tab[4][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = -{ - { /* 9.6 kbs B */ - { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0 }, -{ 16384, 16371, 16358, 16339, 16290, 16241, 16153, 16040, 15813, 15397, 14601, 13301, 11360, 8916, 6254, 3911, 2220, 1280, 755, 461, 278, 177, 111, 70, 35, 20, 12, 0 }, -{ 16384, 16375, 16359, 16333, 16286, 16243, 16154, 16024, 15771, 15380, 14712, 13537, 11742, 9425, 6872, 4378, 2327, 1197, 671, 412, 259, 145, 93, 52, 26, 13, 5, 0 }, -{ 16384, 16372, 16358, 16326, 16289, 16241, 16147, 16014, 15765, 15321, 14670, 13546, 11912, 9787, 7323, 4824, 2536, 1330, 731, 438, 258, 148, 86, 37, 22, 11, 2, 0 }, -{ 16384, 16376, 16364, 16344, 16315, 16272, 16219, 16119, 15910, 15620, 15100, 14254, 13063, 11489, 9413, 7100, 4738, 2751, 1584, 973, 597, 349, 201, 96, 47, 22, 9, 0 }, -{ 16384, 16364, 16340, 16312, 16288, 16237, 16166, 16026, 15756, 15390, 14833, 13870, 12627, 10998, 8985, 6893, 4720, 3048, 1860, 1131, 725, 449, 215, 111, 56, 34, 14, 0 }, -{ 16384, 16326, 16297, 16246, 16183, 16064, 15884, 15632, 15240, 14763, 14107, 13230, 12185, 10886, 9390, 7781, 6194, 4696, 3350, 2259, 1506, 975, 604, 356, 201, 106, 48, 0 } - }, - - { /* 9.6 kbs SWB B*/ - { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0 }, -{ 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0 }, -{ 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0 }, -{ 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0 }, -{ 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0 }, -{ 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0 }, -{ 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0 } - }, - -{ /* 24.4 kbs B */ - { 16384, 16351, 16333, 16303, 16254, 16163, 15993, 15681, 15080, 13987, 12109, 9465, 6588, 4160, 2488, 1480, 912, 589, 389, 266, 190, 131, 93, 68, 47, 34, 24, 0 }, -{ 16384, 16379, 16375, 16369, 16360, 16345, 16328, 16286, 16211, 16078, 15810, 15233, 14058, 11933, 8881, 5609, 2940, 1290, 558, 274, 150, 80, 47, 29, 17, 11, 6, 0 }, -{ 16384, 16382, 16380, 16377, 16370, 16358, 16337, 16300, 16224, 16088, 15811, 15233, 14112, 12019, 9061, 5723, 2780, 1121, 480, 239, 123, 69, 41, 22, 13, 8, 5, 0 }, -{ 16384, 16377, 16375, 16369, 16363, 16351, 16325, 16268, 16172, 16009, 15686, 15039, 13830, 11799, 8924, 5422, 2444, 960, 441, 220, 111, 63, 37, 22, 11, 6, 3, 0 }, -{ 16384, 16374, 16369, 16363, 16356, 16335, 16290, 16214, 16068, 15826, 15382, 14550, 13126, 10956, 8000, 4622, 2090, 973, 478, 249, 128, 75, 42, 19, 13, 7, 4, 0 }, -{ 16384, 16375, 16370, 16367, 16362, 16340, 16298, 16232, 16097, 15860, 15440, 14718, 13570, 11874, 9557, 6790, 4053, 2166, 1150, 622, 323, 179, 96, 53, 33, 17, 12, 0 }, -{ 16384, 16335, 16304, 16276, 16228, 16166, 16094, 15983, 15775, 15501, 15040, 14417, 13552, 12326, 10847, 9117, 7308, 5373, 3666, 2297, 1336, 807, 495, 313, 216, 152, 114, 0 } -}, - -{ /* 48.0 kbs B */ - { 16384, 16334, 16310, 16285, 16254, 16204, 16128, 16031, 15903, 15697, 15380, 14820, 13857, 12267, 9878, 7099, 4509, 2576, 1478, 871, 531, 349, 230, 163, 111, 80, 62, 0}, - { 16384, 16337, 16327, 16307, 16278, 16239, 16178, 16092, 15947, 15719, 15286, 14428, 12833, 10246, 7123, 4088, 1896, 849, 481, 287, 190, 139, 94, 66, 52, 34, 24, 0 }, - { 16384, 16352, 16341, 16329, 16312, 16295, 16265, 16223, 16151, 16026, 15825, 15437, 14645, 13089, 10612, 7364, 4077, 1783, 779, 444, 281, 192, 138, 93, 65, 43, 30, 0 }, - { 16384, 16354, 16347, 16337, 16314, 16284, 16233, 16165, 16051, 15847, 15450, 14621, 13069, 10623, 7298, 3789, 1569, 727, 445, 302, 207, 143, 96, 59, 36, 18, 9, 0 }, - { 16384, 16352, 16342, 16330, 16314, 16295, 16266, 16215, 16127, 15984, 15709, 15190, 14242, 12540, 9979, 6448, 3160, 1392, 752, 481, 344, 251, 169, 115, 73, 28, 8, 0 }, - { 16384, 16340, 16320, 16302, 16272, 16257, 16220, 16135, 16011, 15784, 15370, 14688, 13423, 11457, 8721, 5529, 2736, 1375, 784, 525, 353, 263, 172, 113, 78, 26, 11, 0 }, - { 16384, 16238, 16170, 16113, 16077, 16030, 16000, 15948, 15873, 15752, 15535, 15157, 14595, 13788, 12569, 10767, 8611, 6186, 4101, 2459, 1478, 881, 607, 385, 243, 168, 116, 0 } -} -}; - -/* only needed for >= 48 kbs */ +const Word16 cf_se01_tab[10][IGF_SYMBOLS_IN_TABLE + 1] = +{ + {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 9.6 kbs B*/ + {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 13.2 kbs WB RF B*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 9.6 kbs SWB B*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs A*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs SWB RF B*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 16.4 kbs B*/ + {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0 }, /* 24.4 kbs B*/ + {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0}, /* 32.0 kbs A*/ + {16384, 16368, 16355, 16334, 16291, 16212, 16071, 15816, 15359, 14523, 13014, 10534, 7345, 4272, 2228, 1149, 626, 357, 215, 139, 93, 67, 53, 43, 36, 28, 22, 0}, /* 48.0 kbs B*/ + {16384, 16368, 16355, 16334, 16291, 16212, 16071, 15816, 15359, 14523, 13014, 10534, 7345, 4272, 2228, 1149, 626, 357, 215, 139, 93, 67, 53, 43, 36, 28, 22, 0} /* 64.0 kbs B*/ +}; + +const Word16 cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = +{ + { /* 9.6 kbs B */ + { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, + { 16384, 16371, 16358, 16339, 16290, 16241, 16153, 16040, 15813, 15397, 14601, 13301, 11360, 8916, 6254, 3911, 2220, 1280, 755, 461, 278, 177, 111, 70, 35, 20, 12, 0}, + { 16384, 16375, 16359, 16333, 16286, 16243, 16154, 16024, 15771, 15380, 14712, 13537, 11742, 9425, 6872, 4378, 2327, 1197, 671, 412, 259, 145, 93, 52, 26, 13, 5, 0}, + { 16384, 16372, 16358, 16326, 16289, 16241, 16147, 16014, 15765, 15321, 14670, 13546, 11912, 9787, 7323, 4824, 2536, 1330, 731, 438, 258, 148, 86, 37, 22, 11, 2, 0}, + { 16384, 16376, 16364, 16344, 16315, 16272, 16219, 16119, 15910, 15620, 15100, 14254, 13063, 11489, 9413, 7100, 4738, 2751, 1584, 973, 597, 349, 201, 96, 47, 22, 9, 0}, + { 16384, 16364, 16340, 16312, 16288, 16237, 16166, 16026, 15756, 15390, 14833, 13870, 12627, 10998, 8985, 6893, 4720, 3048, 1860, 1131, 725, 449, 215, 111, 56, 34, 14, 0}, + { 16384, 16326, 16297, 16246, 16183, 16064, 15884, 15632, 15240, 14763, 14107, 13230, 12185, 10886, 9390, 7781, 6194, 4696, 3350, 2259, 1506, 975, 604, 356, 201, 106, 48, 0} + }, + { /* 13.2 kbs WB RF B*/ + { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, + { 16384, 16371, 16358, 16339, 16290, 16241, 16153, 16040, 15813, 15397, 14601, 13301, 11360, 8916, 6254, 3911, 2220, 1280, 755, 461, 278, 177, 111, 70, 35, 20, 12, 0}, + { 16384, 16375, 16359, 16333, 16286, 16243, 16154, 16024, 15771, 15380, 14712, 13537, 11742, 9425, 6872, 4378, 2327, 1197, 671, 412, 259, 145, 93, 52, 26, 13, 5, 0}, + { 16384, 16372, 16358, 16326, 16289, 16241, 16147, 16014, 15765, 15321, 14670, 13546, 11912, 9787, 7323, 4824, 2536, 1330, 731, 438, 258, 148, 86, 37, 22, 11, 2, 0}, + { 16384, 16376, 16364, 16344, 16315, 16272, 16219, 16119, 15910, 15620, 15100, 14254, 13063, 11489, 9413, 7100, 4738, 2751, 1584, 973, 597, 349, 201, 96, 47, 22, 9, 0}, + { 16384, 16364, 16340, 16312, 16288, 16237, 16166, 16026, 15756, 15390, 14833, 13870, 12627, 10998, 8985, 6893, 4720, 3048, 1860, 1131, 725, 449, 215, 111, 56, 34, 14, 0}, + { 16384, 16326, 16297, 16246, 16183, 16064, 15884, 15632, 15240, 14763, 14107, 13230, 12185, 10886, 9390, 7781, 6194, 4696, 3350, 2259, 1506, 975, 604, 356, 201, 106, 48, 0} + }, + { /* 9.6 kbs SWB B*/ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 13.2 kbs A */ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 13.2 kbs SWB RF B*/ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 16.4 kbs B */ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 24.4 kbs B */ + { 16384, 16351, 16333, 16303, 16254, 16163, 15993, 15681, 15080, 13987, 12109, 9465, 6588, 4160, 2488, 1480, 912, 589, 389, 266, 190, 131, 93, 68, 47, 34, 24, 0}, + { 16384, 16379, 16375, 16369, 16360, 16345, 16328, 16286, 16211, 16078, 15810, 15233, 14058, 11933, 8881, 5609, 2940, 1290, 558, 274, 150, 80, 47, 29, 17, 11, 6, 0}, + { 16384, 16382, 16380, 16377, 16370, 16358, 16337, 16300, 16224, 16088, 15811, 15233, 14112, 12019, 9061, 5723, 2780, 1121, 480, 239, 123, 69, 41, 22, 13, 8, 5, 0}, + { 16384, 16377, 16375, 16369, 16363, 16351, 16325, 16268, 16172, 16009, 15686, 15039, 13830, 11799, 8924, 5422, 2444, 960, 441, 220, 111, 63, 37, 22, 11, 6, 3, 0}, + { 16384, 16374, 16369, 16363, 16356, 16335, 16290, 16214, 16068, 15826, 15382, 14550, 13126, 10956, 8000, 4622, 2090, 973, 478, 249, 128, 75, 42, 19, 13, 7, 4, 0}, + { 16384, 16375, 16370, 16367, 16362, 16340, 16298, 16232, 16097, 15860, 15440, 14718, 13570, 11874, 9557, 6790, 4053, 2166, 1150, 622, 323, 179, 96, 53, 33, 17, 12, 0}, + { 16384, 16335, 16304, 16276, 16228, 16166, 16094, 15983, 15775, 15501, 15040, 14417, 13552, 12326, 10847, 9117, 7308, 5373, 3666, 2297, 1336, 807, 495, 313, 216, 152, 114, 0} + }, + { /* 32.0 kbs A */ + { 16384, 16351, 16333, 16303, 16254, 16163, 15993, 15681, 15080, 13987, 12109, 9465, 6588, 4160, 2488, 1480, 912, 589, 389, 266, 190, 131, 93, 68, 47, 34, 24, 0}, + { 16384, 16379, 16375, 16369, 16360, 16345, 16328, 16286, 16211, 16078, 15810, 15233, 14058, 11933, 8881, 5609, 2940, 1290, 558, 274, 150, 80, 47, 29, 17, 11, 6, 0}, + { 16384, 16382, 16380, 16377, 16370, 16358, 16337, 16300, 16224, 16088, 15811, 15233, 14112, 12019, 9061, 5723, 2780, 1121, 480, 239, 123, 69, 41, 22, 13, 8, 5, 0}, + { 16384, 16377, 16375, 16369, 16363, 16351, 16325, 16268, 16172, 16009, 15686, 15039, 13830, 11799, 8924, 5422, 2444, 960, 441, 220, 111, 63, 37, 22, 11, 6, 3, 0}, + { 16384, 16374, 16369, 16363, 16356, 16335, 16290, 16214, 16068, 15826, 15382, 14550, 13126, 10956, 8000, 4622, 2090, 973, 478, 249, 128, 75, 42, 19, 13, 7, 4, 0}, + { 16384, 16375, 16370, 16367, 16362, 16340, 16298, 16232, 16097, 15860, 15440, 14718, 13570, 11874, 9557, 6790, 4053, 2166, 1150, 622, 323, 179, 96, 53, 33, 17, 12, 0}, + { 16384, 16335, 16304, 16276, 16228, 16166, 16094, 15983, 15775, 15501, 15040, 14417, 13552, 12326, 10847, 9117, 7308, 5373, 3666, 2297, 1336, 807, 495, 313, 216, 152, 114, 0} + }, + { /* 48.0 kbs B */ + { 16384, 16334, 16310, 16285, 16254, 16204, 16128, 16031, 15903, 15697, 15380, 14820, 13857, 12267, 9878, 7099, 4509, 2576, 1478, 871, 531, 349, 230, 163, 111, 80, 62, 0}, + { 16384, 16337, 16327, 16307, 16278, 16239, 16178, 16092, 15947, 15719, 15286, 14428, 12833, 10246, 7123, 4088, 1896, 849, 481, 287, 190, 139, 94, 66, 52, 34, 24, 0}, + { 16384, 16352, 16341, 16329, 16312, 16295, 16265, 16223, 16151, 16026, 15825, 15437, 14645, 13089, 10612, 7364, 4077, 1783, 779, 444, 281, 192, 138, 93, 65, 43, 30, 0}, + { 16384, 16354, 16347, 16337, 16314, 16284, 16233, 16165, 16051, 15847, 15450, 14621, 13069, 10623, 7298, 3789, 1569, 727, 445, 302, 207, 143, 96, 59, 36, 18, 9, 0}, + { 16384, 16352, 16342, 16330, 16314, 16295, 16266, 16215, 16127, 15984, 15709, 15190, 14242, 12540, 9979, 6448, 3160, 1392, 752, 481, 344, 251, 169, 115, 73, 28, 8, 0}, + { 16384, 16340, 16320, 16302, 16272, 16257, 16220, 16135, 16011, 15784, 15370, 14688, 13423, 11457, 8721, 5529, 2736, 1375, 784, 525, 353, 263, 172, 113, 78, 26, 11, 0}, + { 16384, 16238, 16170, 16113, 16077, 16030, 16000, 15948, 15873, 15752, 15535, 15157, 14595, 13788, 12569, 10767, 8611, 6186, 4101, 2459, 1478, 881, 607, 385, 243, 168, 116, 0} + }, + { /* 64.0 kbs B */ + { 16384, 16334, 16310, 16285, 16254, 16204, 16128, 16031, 15903, 15697, 15380, 14820, 13857, 12267, 9878, 7099, 4509, 2576, 1478, 871, 531, 349, 230, 163, 111, 80, 62, 0}, + { 16384, 16337, 16327, 16307, 16278, 16239, 16178, 16092, 15947, 15719, 15286, 14428, 12833, 10246, 7123, 4088, 1896, 849, 481, 287, 190, 139, 94, 66, 52, 34, 24, 0}, + { 16384, 16352, 16341, 16329, 16312, 16295, 16265, 16223, 16151, 16026, 15825, 15437, 14645, 13089, 10612, 7364, 4077, 1783, 779, 444, 281, 192, 138, 93, 65, 43, 30, 0}, + { 16384, 16354, 16347, 16337, 16314, 16284, 16233, 16165, 16051, 15847, 15450, 14621, 13069, 10623, 7298, 3789, 1569, 727, 445, 302, 207, 143, 96, 59, 36, 18, 9, 0}, + { 16384, 16352, 16342, 16330, 16314, 16295, 16266, 16215, 16127, 15984, 15709, 15190, 14242, 12540, 9979, 6448, 3160, 1392, 752, 481, 344, 251, 169, 115, 73, 28, 8, 0}, + { 16384, 16340, 16320, 16302, 16272, 16257, 16220, 16135, 16011, 15784, 15370, 14688, 13423, 11457, 8721, 5529, 2736, 1375, 784, 525, 353, 263, 172, 113, 78, 26, 11, 0}, + { 16384, 16238, 16170, 16113, 16077, 16030, 16000, 15948, 15873, 15752, 15535, 15157, 14595, 13788, 12569, 10767, 8611, 6186, 4101, 2459, 1478, 881, 607, 385, 243, 168, 116, 0} + } +}; + +/* only needed for >= 48 kbps */ const Word16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1] = { @@ -19873,11 +20936,10 @@ const Word16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] } }; - /**********************************************************************/ /** igf settings table for each bitrate mode **************************************************************************/ -const IGF_MODE igfMode[15] = +const IGF_MODE igfMode[] = { /* sampleRate, frameLength, bitRate, igfMinFq, transFac, maxHopsize */ { 16000, 320, 9600, 774, 20480/*1.25f Q14*/, 4 }, /* 9.6kbs WB 0 */ @@ -19889,10 +20951,12 @@ const IGF_MODE igfMode[15] = { 32000, 640, 24400, 800, 20480/*1.25f Q14*/, 4 }, /* 24.4kbs SWB 6 */ { 32000, 640, 32000, 800, 20480/*1.25f Q14*/, 4 }, /* 32.0kbs SWB 7 */ { 32000, 640, 48000, 1600, 20480/*1.25f Q14*/, 4 }, /* 48.0kbs SWB 8 */ + { 32000, 640, 64000, 1600, 20480/*1.25f Q14*/, 4 }, /* 48.0kbs SWB 8 */ { 48000, 960, 16400, 800, 20480/*1.25f Q14*/, 4 }, /* 16.4kbs FB 9 */ { 48000, 960, 24400, 800, 20480/*1.25f Q14*/, 2 }, /* 24.4kbs FB 10 */ { 48000, 960, 32000, 800, 20480/*1.25f Q14*/, 2 }, /* 32.0kbs FB 11 */ { 48000, 960, 48000, 1600, 20480/*1.25f Q14*/, 2 }, /* 48.0kbs FB 12 */ + { 48000, 960, 64000, 1600, 20480/*1.25f Q14*/, 2 }, /* 48.0kbs FB 12 */ { 48000, 960, 96000, 1600, 8192/*0.50f Q14*/, 1 }, /* 96.0kbs FB 13 */ { 48000, 960, 128000, 1600, 8192/*0.50f Q14*/, 1 } /*128.0kbs FB 14 */ }; @@ -20579,7 +21643,15 @@ const Word16 grid40_fx[(GRID40_POINTS-1)/2 - 1] = 17121, 14876, 12540, 10126, 7650, 5126, 2571 }; - +#ifdef MOD_BIT_ALLOC_ROM_TABLE +const Word16 bit_rates_div50[] = /* bit rate values / 50 to Fit in a Word16 */ +{ + ACELP_5k00/50, ACELP_6k15/50, ACELP_7k20/50, ACELP_8k00/50, ACELP_9k60/50, ACELP_11k60/50, ACELP_12k15/50, + ACELP_12k85/50, ACELP_13k20/50, ACELP_14k80/50, ACELP_16k40/50, ACELP_22k60/50, + ACELP_24k40/50, ACELP_29k00/50, ACELP_29k20/50, ACELP_30k20/50, ACELP_30k40/50, + ACELP_32k /50, ACELP_48k /50, ACELP_64k /50, HQ_96k /50, HQ_128k /50 +}; +#else const Word16 bit_rates_div50[] = /* bit rate values / 50 to Fit in a Word16 */ { ACELP_7k20/50, ACELP_8k00/50, ACELP_11k60/50, ACELP_12k15/50, @@ -20587,7 +21659,7 @@ const Word16 bit_rates_div50[] = /* bit rate values / 50 to Fit in a Word16 */ ACELP_24k40/50, ACELP_29k00/50, ACELP_29k20/50, ACELP_30k20/50, ACELP_30k40/50, ACELP_32k /50, ACELP_48k /50, ACELP_64k /50, HQ_96k /50, HQ_128k /50 }; - +#endif const Word16 bit_rates_16k_div50[] = /* bit rate values / 50 to Fit in a Word16 */ { ACELP_8k00 /50, ACELP_14k80/50, ACELP_22k60/50, ACELP_24k40/50, ACELP_29k00/50, diff --git a/lib_com/rom_com_fx.h b/lib_com/rom_com_fx.h index 530d2df..04d1f42 100644 --- a/lib_com/rom_com_fx.h +++ b/lib_com/rom_com_fx.h @@ -10,7 +10,8 @@ #include "stat_enc_fx.h" /* Encoder static structure */ #include "stat_dec_fx.h" /* Decoder static structure */ - + /* Combine coder_type, bandwidth, formant sharpening flag, and channel-aware flag into one indice */ +#define SIG2IND(ctype, bw, sf, ca_rf) ( ctype | (bw << 3) | (sf << 6) | (ca_rf << 7) ) typedef struct { Word32 fin_fx; /* input frequency Q0 */ @@ -23,6 +24,14 @@ typedef struct UNS_Word16 flags_fx; /* flags from config. table Q0 */ } Resampling_cfg_fx; +enum FUNC_GAIN_ENC +{ + FUNC_GAIN_ENC_MLESS = 0, /* Memory-less gain coding */ + FUNC_GAIN_ENC_2 = 1, /* AMR-WB gains quantizer (6bits/subfr (mode 4) or 7bits/subfr (mode 5)) */ /* !!! to be removed !!! */ + FUNC_GAIN_ENC_UV, /* UV gains quantizer (5bits/subfr) */ + FUNC_GAIN_ENC_GACELP_UV /* UV GACELP gain quantizer ((7=5-2bits/subfr) */ +}; + /*-----------------------------------------------------------------* * Tables with bit-allocations *-----------------------------------------------------------------*/ @@ -52,7 +61,9 @@ extern const Word16 crit_bins_corr_fx[]; extern const Word32 brate_tbl[SIZE_BRATE_TBL]; extern const Word32 acelp_sig_tbl[MAX_ACELP_SIG]; - +/*IVAS_CNST_AND_ROM*/ +extern const Word32 brate_intermed_tbl[]; +/*End of IVAS_CNST_AND_ROM*/ extern const Word16 Nb[NB_SFM]; extern const Word16 LNb[ NB_SFM]; @@ -194,7 +205,11 @@ extern const Word16 inv_sigma_p_fx[][16]; extern const Word16 inv_sigma_MSLVQ_fx[][16]; extern const Word16 perm_MSLVQ_fx[][4]; extern const Word16 pl_HQ_fx[]; - +#ifdef MSVQ_ROM +extern const Word16 no_lead_idx[][2]; +extern const Word16 no_lead_p_idx[][2]; +extern const Word16 leaders_short[][MAX_NO_SCALES]; +#endif /*----------------------------------------------------------------------------------* * ISF quantization (AMR-WB IO mode) *----------------------------------------------------------------------------------*/ @@ -428,6 +443,9 @@ extern const Word16 hp12800_48000_fx[]; extern const Word16 hp16000_48000_fx[]; extern const Word16 hp12800_16000_fx[]; extern const Word16 inner_frame_tbl_fx[]; +/* HQ spectrum length lookup tables */ +extern const Word16 l_spec_tbl[]; +extern const Word16 l_spec_ext_tbl[]; extern const Word16 EnvCdbk11_fx []; @@ -882,7 +900,7 @@ extern const Word16 msNoiseSlopeMax[4]; extern const Word16 preemphCompensation[NB_BANDS]; #define msNoiseSlopeMax_EXP 3 -extern const SCALE_SETUP scaleTable[20]; +extern const SCALE_SETUP scaleTableMono[SIZE_SCALE_TABLE_MONO]; extern const SCALE_SETUP scaleTable_cn_only[18]; extern const Word16 scaleTable_cn_only_amrwbio[3][2]; @@ -1058,6 +1076,8 @@ extern const Word16 lsf_numbits[TCXLPC_NUMSTAGES]; extern const Word16 lsf_dims[TCXLPC_NUMSTAGES]; extern const Word16 lsf_offs[TCXLPC_NUMSTAGES]; extern const Word16 lsf_q_diff_cb_8b_rf[]; +extern const Word16 dico_lsf_abs_8b[]; + extern const Word16 lsf_cdk_nb_gc_stg1[]; extern const Word16 lsf_cdk_nb_gc_stg2[]; extern const Word16 lsf_cdk_nb_gc_stg3[]; @@ -1166,9 +1186,9 @@ typedef struct igf_mode_type } IGF_MODE,*H_IGF_MODE; -extern const IGF_MODE igfMode[15]; -extern const Word16 swb_offset_LB_new[15][IGF_MAX_SFB]; -extern const Word16 igf_whitening_TH[15][2][IGF_MAX_TILES]; +extern const IGF_MODE igfMode[]; +extern const Word16 swb_offset_LB_new[][IGF_MAX_SFB]; +extern const Word16 igf_whitening_TH[][2][IGF_MAX_TILES]; extern const Word16 cf_off_se01_tab[9]; @@ -1179,8 +1199,8 @@ extern const Word16 cf_off_se02_tab[9][IGF_CTX_COUNT]; extern const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT]; extern const Word16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1]; -extern const Word16 cf_se01_tab[9][IGF_SYMBOLS_IN_TABLE + 1]; -extern const Word16 cf_se02_tab[4][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; +extern const Word16 cf_se01_tab[][IGF_SYMBOLS_IN_TABLE + 1]; +extern const Word16 cf_se02_tab[][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; extern const Word16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1]; extern const Word16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c index 3f24bef..dce719c 100644 --- a/lib_com/scale_mem_fx.c +++ b/lib_com/scale_mem_fx.c @@ -164,7 +164,7 @@ void Rescale_mem( Word16 *pst_old_syn, /* i/o: psfiler */ Word16 *pst_mem_deemp_err, /* i/o: psfiler */ Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ + PFSTAT_HANDLE hPFstat, /* i/o: All memories related to NB post filter */ const Word16 Vad_flag, const Word16 Cna_flag, const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ @@ -247,9 +247,9 @@ void Rescale_mem( Scale_sig(mem_deemph, 1, exp_scale); Scale_sig(pst_old_syn, NBPSF_PIT_MAX, exp_scale); Scale_sig(pst_mem_deemp_err, 1, exp_scale); - Scale_sig(pf_stat->mem_pf_in, L_SUBFR, exp_scale); /* NB post_filter mem */ - Scale_sig(pf_stat->mem_res2, DECMEM_RES2, exp_scale); /* NB post_filter mem */ - Scale_sig(pf_stat->mem_stp, L_SUBFR, exp_scale); /* NB post_filter mem */ + Scale_sig(hPFstat->mem_pf_in, L_SUBFR, exp_scale); /* NB post_filter mem */ + Scale_sig(hPFstat->mem_res2, DECMEM_RES2, exp_scale); /* NB post_filter mem */ + Scale_sig(hPFstat->mem_stp, L_SUBFR, exp_scale); /* NB post_filter mem */ Scale_sig(mem_agc, 1, exp_scale); /* NB post_filter mem */ return; } diff --git a/lib_com/stab_est_fx.c b/lib_com/stab_est_fx.c index d85fe5b..d853eac 100644 --- a/lib_com/stab_est_fx.c +++ b/lib_com/stab_est_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ #include "basop_mpy.h" /*-------------------------------------------------------------------* @@ -40,7 +39,7 @@ Word16 stab_est_fx( Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ Word16 *thresh, /* i/o : Detection thresold */ Word16 *last_music_flag,/* i/o : Previous music detection ouptut */ - Word16 vad_flag + const Word16 vad_flag /* i : VAD flag */ ) { Word16 i, music_flag2, tmp16, exp1, exp2; diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 640bde1..f7672db 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -5,6 +5,7 @@ #ifndef STAT_COM_H #define STAT_COM_H +#include #include "options.h" #include "basop_util.h" #include "cnst_fx.h" @@ -28,7 +29,7 @@ typedef struct Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual */ Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ Word16 gain_prec; /* for gain adjustment */ -} PFSTAT; +} PFSTAT, * PFSTAT_HANDLE; typedef struct { @@ -113,6 +114,15 @@ typedef struct Word16 fixed_cdk_index[NB_SUBFR16k]; + /* IVAS related parameters */ + Word16 pitch_bits[NB_SUBFR16k]; + Word16 lsf_bits; + Word16 mid_lsf_bits; + Word16 AVQ_cdk_bits[NB_SUBFR16k]; + Word16 FEC_mode; /* 0 == no FEC bits; 1 == class; 2 == clas+energy; 3== class+energy+pulse */ + Word16 ubits; + Word16 fcb_mode; /* 0 == mode1; 1 == mode2 */ + } ACELP_config; /*tns_base.h*/ @@ -134,6 +144,9 @@ typedef struct * Upper borders for other filters is the lower border of previous filter. */ Word16 iFilterBorders[TNS_MAX_NUM_OF_FILTERS+1]; +#ifdef ADD_IVAS_TNS + Flag allowTnsOnWhite; +#endif } STnsConfig; @@ -224,7 +237,7 @@ typedef struct Word16 lfacNextFB; /* TNS */ - Word8 fIsTNSAllowed; + Word16 fIsTNSAllowed; STnsConfig tnsConfig[2][2]; STnsConfig const * pCurrentTnsConfig; @@ -244,7 +257,8 @@ typedef struct Word16 na_scale; Word32 SFM2; -} TCX_config; +} +TCX_config, *TCX_CONFIG_HANDLE; /* prot.h */ typedef struct @@ -585,16 +599,7 @@ typedef struct } TEMPORAL_ENVELOPE_CODING_DECODER_FX; typedef TEMPORAL_ENVELOPE_CODING_DECODER_FX* HANDLE_TEC_DEC_FX; -typedef struct -{ - Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC]; - Word16 loTempEnv[CLDFB_NO_COL_MAX]; - Word16 loTempEnv_ns[CLDFB_NO_COL_MAX]; - Word16 hiTempEnv[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV]; - Word16 tranFlag; - Word16 corrFlag; -} TEMPORAL_ENVELOPE_CODING_ENCODER_FX; -typedef TEMPORAL_ENVELOPE_CODING_ENCODER_FX* HANDLE_TEC_ENC_FX; + typedef enum { @@ -669,7 +674,11 @@ typedef Word16 (*get_next_coeff_function)( Word16 *idx, /* o : index in unmapped domain */ CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); - +typedef enum +{ + LPC_ABS_QUANT_BITS = 8, + SNS_ABS_QUANT_BITS = 10 +} ABS_QUANT_BITS; /*CLDFB-VAD*/ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index da16a0c..19e282a 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -2,14 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "cnst_fx.h" /* Function prototypes */ -#include "stl.h" /*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ + * Local function prototypes + *---------------------------------------------------------------------*/ #define TILT_COMP_LIM_FX 24576 /* 0.75 in Q15 */ #define GE_SHIFT 6 @@ -29,15 +29,15 @@ Word32 L_Sqrt_Q0(const Word32 x); *--------------------------------------------------------------------*/ void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ + const Word16 coder_type, /* i : Coder type */ Word16 noisiness, /* i : noisiness parameter */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr */ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr */ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr */ Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ Word16 *exc2, /* i/o: excitation buffer */ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi , /* i : Bad frame indicator */ + const Word16 bfi , /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain */ Word16 *uv_count, /* i/o: unvoiced counter */ Word16 *act_count, /* i/o: activation counter */ @@ -45,8 +45,8 @@ void stat_noise_uv_mod_fx( Word16 *noimix_seed, /* i/o: mixture seed */ Word16 *st_min_alpha, /* i/o: minimum alpha */ Word16 *exc_pe, /* i/o: scale Q_stat_noise */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : input bandwidth */ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : input bandwidth */ Word16 *Q_stat_noise, /* i/o: noise scaling */ Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ) @@ -334,7 +334,7 @@ void stat_noise_uv_mod_fx( static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ const Word16 *x, /* i : Signal input */ const Word16 Q_shift, /* i : input scaling */ - const Word16 len /* i : lenght */ + const Word16 len /* i : length */ ) { Word16 i; diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index d953245..0b5b286 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2,13 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" -#include "stl.h" /*==========================================================================*/ @@ -39,16 +37,16 @@ Word16 WB_BWE_gain_pred_fx( Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ + const Word16 coder_type, /* i : coding type */ Word16 prev_coder_type, /* i : coding type of last frame */ Word16 prev_WB_fenv, /* i : envelope for last frame */ Word16 *voice_factors, /* i : voicing factors //Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ + const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener , /* i : previous frame wb bwe signal energy */ - Word16 Q_syn - ,Word16 last_extl_fx, + Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ + Word16 Q_syn, /* i : synthesis scaling */ + Word16 last_extl_fx, /* i : extl. layer for last frame */ Word16 tilt_wb_fx ) { @@ -305,13 +303,13 @@ Word16 WB_BWE_gain_pred_fx( *-------------------------------------------------------------------*/ static void calc_norm_envelop_lf_fx( - const Word32 SWB_signal[], /* i : SWB spectrum */ /* Q12 */ - Word32 *envelope, /* o : normalized envelope */ /* Q12 */ - Word16 *L_swb_norm, /* i/o : length of envelope */ - const Word16 HQ_mode, /* i : HQ mode */ /* Q0 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic */ /* Q0 */ - Word16 *sfreq, /* i : starting frequency index */ - Word16 *efreq /* i : ending frequency index */ + const Word32 SWB_signal[], /* i : SWB spectrum */ /* Q12 */ + Word32 *envelope, /* o : normalized envelope */ /* Q12 */ + Word16 *L_swb_norm, /* i/o : length of envelope */ + const Word16 HQ_mode, /* i : HQ mode */ /* Q0 */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic */ /* Q0 */ + Word16 *sfreq, /* i : starting frequency index */ + Word16 *efreq /* i : ending frequency index */ ) { Word16 lookback, env_index, n_freq, n_lag_now, n_lag; @@ -384,14 +382,18 @@ void calc_norm_envelop_lf_fx( return; } +/*-------------------------------------------------------------------* + * calc_normal_length() + * + *-------------------------------------------------------------------*/ void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : input signal */ - const Word16 mode, /* i : input mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + const Word16 core, /* i : core */ + const Word16 *sp, /* i : input signal */ + const Word16 mode, /* i : input mode */ + const Word16 extl, /* i : extension layer */ + Word16 *L_swb_norm, /* o : normalize length */ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ Word16 Q_syn ) { @@ -508,7 +510,13 @@ void calc_normal_length_fx( return; } -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ +/*-------------------------------------------------------------------* + * calc_tilt_bwe() + * + * calculate tilt parameter + *-------------------------------------------------------------------*/ + +Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ const Word16 *sp, /* i : input signal */ const Word16 exp_sp, /* i : Exp of inp signal */ const Word16 N /* i : signal length */ @@ -595,12 +603,18 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ return L_temp; } +/*-------------------------------------------------------------------* + * calc_norm_envelop() + * + * calculate normalized parameter + *-------------------------------------------------------------------*/ + void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 st_offset /* i : offset */ + const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ + Word32 *envelope, /* o : normalized envelope Q_syn*/ + const Word16 L_swb_norm, /* i : length of envelope Q0 */ + const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 st_offset /* i : offset */ ) { Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; @@ -681,23 +695,23 @@ void calc_norm_envelop_fx( /* CALLED FROM : */ /*==========================================================================*/ void WB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *WB_fenv, /* i : WB frequency envelopes */ - Word32 *WB_signal_32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for WB signal */ - const Word16 last_extl, /* i : extl. layer for last frame */ - Word32 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word32 total_brate, /* i : core layer bitrate */ - Word16 *Seed, /* i/o: random generator seed */ - Word16 *prev_flag, /* i/o: attenu flag of last frame */ - Word16 prev_coder_type , /* i : coding type of last frame */ + const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ + Word16 *WB_fenv, /* i : WB frequency envelopes */ + Word32 *WB_signal_32, /* o : WB signal in MDCT domain */ + const Word16 WB_flength, /* i : Length of input/output */ + const Word16 mode, /* i : classification for WB signal */ + const Word16 last_extl, /* i : extl. layer for last frame */ + Word32 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ + const Word16 extl, /* i : extension layer */ + const Word16 coder_type, /* i : coding type */ + const Word32 total_brate, /* i : core layer bitrate */ + Word16 *Seed, /* i/o: random generator seed */ + Word16 *prev_flag, /* i/o: attenu flag of last frame */ + Word16 prev_coder_type , /* i : coding type of last frame */ Word16 Q_syn, - Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ + Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ ) { Word16 n_freq, n_band; @@ -919,7 +933,7 @@ void WB_BWE_decoding_fx( test(); test(); test(); - IF( EQ_16(coder_type,GENERIC)||((GT_32(EnergyL,L_shr(*prev_Energy,1))&>_32(*prev_Energy,L_shr(EnergyL,1))&&EQ_16(*prev_flag,1)))) + IF( EQ_16(coder_type,GENERIC) || ( GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1)) && EQ_16(*prev_flag,1) )) { WB_fenv[0] = shr( WB_fenv[0], 1); move16(); @@ -1113,22 +1127,22 @@ void WB_BWE_decoding_fx( /*--------------------------------------------------------------------------*/ void SWB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ - Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for SWB signal */ - Word16 *frica_flag, /* o : fricative signal flag */ - Word16 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ - const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ - Word16 *Seed, /* i/o: random generator seed */ - const Word16 st_offset, /* i : offset value due to different core */ - Word16 *prev_weight, /* i/o: excitation weight value of last frame */ - const Word16 extl , /* i : extension layer */ + const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */ + Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ + Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */ + const Word16 SWB_flength, /* i : Length of input/output */ + const Word16 mode, /* i : classification for SWB signal */ + Word16 *frica_flag, /* o : fricative signal flag */ + Word16 *prev_Energy, /* i/o: energy for last frame */ + Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ + Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ + const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ + Word16 *Seed, /* i/o: random generator seed */ + const Word16 st_offset, /* i : offset value due to different core */ + Word16 *prev_weight, /* i/o: excitation weight value of last frame */ + const Word16 extl , /* i : extension layer */ Word16 Q_syn - ,const Word16 last_extl /* i : extension layer of last frame */ + ,const Word16 last_extl /* i : extension layer of last frame */ ) { Word16 n_freq, n_band, L, L_swb_norm; @@ -1775,7 +1789,7 @@ void SWB_BWE_decoding_fx( void time_envelop_shaping_fx( Word16 werr[], /* i/o: SHB synthesis Q_synth*/ Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ - const Word16 L , /* i : frame length */ + const Word16 L , /* i : frame length */ Word16 *Q_synth ) { @@ -1873,10 +1887,10 @@ void time_envelop_shaping_fx( /* _ None */ /*--------------------------------------------------------------------------*/ void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ + const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ Word16 *error, /* i/o: SHB BWE synthesis Q0*/ Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ + const Word16 L, /* i : subframe length */ Word16 Q_syn, Word16 Q_synth ) @@ -2041,12 +2055,12 @@ void time_reduce_pre_echo_fx( * *-------------------------------------------------------------------*/ void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : input signal : Q12 */ - const Word16 mode, /* i : input mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ + const Word16 core, /* i : core : Q0 */ + const Word32 *sp, /* i : input signal : Q12 */ + const Word16 mode, /* i : input mode : Q0 */ + const Word16 extl, /* i : extension layer : Q0 */ + Word16 *L_swb_norm, /* o : normalize length : Q0 */ + Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ ) { Word16 i, n_freq, n_band, THRES; @@ -2219,13 +2233,13 @@ void calc_norm_envelop_fx_32( * *-------------------------------------------------------------------*/ void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode : Q0 */ + const Word16 HQ_mode, /* i : HQ mode : Q0 */ Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ const Word16 *R ) { diff --git a/lib_com/swb_bwe_com_hr_fx.c b/lib_com/swb_bwe_com_hr_fx.c index d583717..681377a 100644 --- a/lib_com/swb_bwe_com_hr_fx.c +++ b/lib_com/swb_bwe_com_hr_fx.c @@ -2,9 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" #include "prot_fx.h" -#include "stl.h" /*-------------------------------------------------------------------* * swb_hr_nonzero_subband_noise_fill() @@ -12,11 +12,11 @@ * SWB BWE HR noise filling of zero subbands *-------------------------------------------------------------------*/ static void swb_hr_nonzero_subband_noise_fill_fx( - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ + const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ Word16 *t_audio_fx, /* i/o: mdct spectrum */ Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - const Word16 N, /* i : length of subband */ - const Word16 Nsv, /* i : number of subband */ + const Word16 N, /* i : length of subband */ + const Word16 Nsv, /* i : number of subband */ Word16 Q_audio ) { @@ -78,15 +78,15 @@ static void swb_hr_nonzero_subband_noise_fill_fx( * SWB BWE HR noise filling *-------------------------------------------------------------------*/ void swb_hr_noise_fill_fx( - const Word16 is_transient, /* i : transient flag */ - const Word16 spect_start, /* i : spectrum start point */ - const Word16 spect_end, /* i : spectrum end point */ - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ - const Word16 pitch_fx, /* i : pitch value */ - const Word16 nq[], /* i : AVQ nq index */ - Word16 Nsv, /* i : number of subband */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - Word16 *t_audio_fx, /* i/o: mdct spectrum */ + const Word16 is_transient, /* i : transient flag */ + const Word16 spect_start, /* i : spectrum start point */ + const Word16 spect_end, /* i : spectrum end point */ + const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ + const Word16 pitch_fx, /* i : pitch value */ + const Word16 nq[], /* i : AVQ nq index */ + Word16 Nsv, /* i : number of subband */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + Word16 *t_audio_fx, /* i/o: mdct spectrum */ Word16 Q_audio ) { diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 7a15dea..a7cc052 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -1,14 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" #include "cnst_fx.h" - #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ #include "basop_mpy.h" #include @@ -20,7 +17,7 @@ *-------------------------------------------------------------------*/ void GetPredictedSignal_fx( const Word16 *predBuf_fx, /* i: Q8 */ - Word32 *L_outBuf, /* o: Q9 */ + Word32 *L_outBuf, /* o: Q9 */ const Word16 lag_fx, /* i: Q0 */ const Word16 fLen_fx, /* i: Q0 */ const Word16 lagGains_fx, /* i: Qgain */ @@ -165,7 +162,7 @@ Word16 har_est_fx( Word16 i, j, q, k , k1, k2; Word16 blk_end,blk_st; - Word16 peak_pos,blk_peak_pos[30], diff_peak_pos[30], sharp, sharp1, sharp2; + Word16 peak_pos,blk_peak_pos[30], diff_peak_pos[30], sharp, sharp1; Word16 min_har_pos; Word16 blk_peak_pos_te[30]; Word16 temp; @@ -438,8 +435,6 @@ Word16 har_est_fx( move16(); sharp1 = 0; move16(); - sharp2 = 0; - move16(); k2 = 0; move16(); @@ -463,7 +458,6 @@ Word16 har_est_fx( } ELSE IF ( diff_peak_pos[i] > 0 ) { - sharp2 = add(sharp2, diff_peak_pos[i]); k2 = add(k2, 1); } q = add(q, 1); @@ -570,29 +564,27 @@ Word16 har_est_fx( } } } - - return blk_peak_pos_max; } void genhf_noise_fx( - Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ - Word16 Qss, /* i : Q0 Q value */ + const Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ + const Word16 Qss, /* i : Q0 Q value */ Word32 L_xSynth_har[], /* o : QsL hf non tonal components */ /* xSynth_har:QsL */ - Word16 QsL, /* i : Q0 Q value */ - Word16 *predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ - Word16 bands, /* i : Q0 total number of subbands in a frame */ - Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ - Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ - Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ + const Word16 QsL, /* i : Q0 Q value */ + const Word16 *predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ + const Word16 bands, /* i : Q0 total number of subbands in a frame */ + const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ + const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ + const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ Word16 *pul_res, /* o : Q0 pulse resolution */ GainItem_fx pk_sf_fx[], /* o : representative region */ - const Word16 fLenLow, /* i : Q0 low frequency length */ - const Word16 fLenHigh, /* i : Q0 high frequency length */ - const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ - const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ - const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ - const Word16 subband_search_offset[] /* i : Q0 most representative regions offsets in LF */ + const Word16 fLenLow, /* i : Q0 low frequency length */ + const Word16 fLenHigh, /* i : Q0 high frequency length */ + const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ + const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ + const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ + const Word16 subband_search_offset[]/* i : Q0 most representative regions offsets in LF */ ) { Word16 k,j,ii,st_pos,dst_pos; @@ -756,9 +748,9 @@ void genhf_noise_fx( *-------------------------------------------------------------------*/ static void SmoothSpec_fx( - Word16 *inBuf, /* (i) : Input spectrum Q8 */ - Word16 *outBuf, /* (o) : Smoothed spectrum Q8 */ - Word16 num_subband /* (i) : subband number */ + Word16 *inBuf, /* i : Input spectrum Q8 */ + Word16 *outBuf, /* o : Smoothed spectrum Q8 */ + Word16 num_subband /* i : subband number */ ) { Word16 i, tmp; @@ -867,11 +859,11 @@ void SmoothSpec_fx( *-------------------------------------------------------------------*/ void SpectrumSmoothing_fx( - const Word32 *L_inBuf, /* i : Qs Low band MDCT */ - Word16 *outBuf_fx, /* o : Qss output */ - Word16 *Qss, /* o : Q0 Q value of output vector */ - const Word16 fLen, /* i : Q0 length */ - const Word16 th_cut_fx /* i : Qss threshold of cut */ + const Word32 *L_inBuf, /* i : Qs Low band MDCT */ + Word16 *outBuf_fx, /* o : Qss output */ + Word16 *Qss, /* o : Q0 Q value of output vector */ + const Word16 fLen, /* i : Q0 length */ + const Word16 th_cut_fx /* i : Qss threshold of cut */ ) { /* internal variable */ @@ -1081,10 +1073,10 @@ void SpectrumSmoothing_fx( *-------------------------------------------------------------------*/ void Get20Log10Spec_fx( - const Word32 *L_inBuf, /* i : input Q_inBuf */ /* L_inBuf >=0, so L_abs is omitted. */ - Word16 *outBuf_fx, /* o : output Q7 */ - const Word16 fLen, /* i : loop length */ - const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ + const Word32 *L_inBuf, /* i : input Q_inBuf */ /* L_inBuf >=0, so L_abs is omitted. */ + Word16 *outBuf_fx, /* o : output Q7 */ + const Word16 fLen, /* i : loop length */ + const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ ) { Word16 i; @@ -1120,7 +1112,11 @@ void Get20Log10Spec_fx( return; } - +/*-------------------------------------------------------------------* + * convert_lagIndices_pls2smp() + * + * + *-------------------------------------------------------------------*/ void convert_lagIndices_pls2smp_fx( Word16 lagIndices_in_fx[], Word16 nBands_search_fx, @@ -1162,6 +1158,11 @@ void convert_lagIndices_pls2smp_fx( return; } +/*-------------------------------------------------------------------* + * get_usebit_npswb() + * + * + *-------------------------------------------------------------------*/ Word16 get_usebit_npswb_fx( Word16 hqswb_clas_fx ) @@ -1203,12 +1204,16 @@ Word16 get_usebit_npswb_fx( return bits; } - +/*-------------------------------------------------------------------* + * SpectrumSmoothing_nss() + * + * + *-------------------------------------------------------------------*/ void SpectrumSmoothing_nss_fx( - const Word32 *L_inBuf, /* i : lowband MDCT */ - Word16 *outBuf_fx, /* o : output */ - Word16 *Qss, /* o : Q value of output vector */ - const Word16 fLen /* i : length */ + const Word32 *L_inBuf, /* i : lowband MDCT */ + Word16 *outBuf_fx, /* o : output */ + Word16 *Qss, /* o : Q value of output vector */ + const Word16 fLen /* i : length */ ) { /* internal variable */ @@ -1502,7 +1507,7 @@ void SpectrumSmoothing_nss_fx( *-------------------------------------------------------------------*/ void return_bits_normal2_fx( - Word16 *bit_budget_fx, /* i/o : bit budget */ + Word16 *bit_budget_fx, /* i/o : bit budget */ const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ const Word16 bands_fx, /* i : Total number of Subbands in a frame */ const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */ @@ -1534,13 +1539,13 @@ void preset_hq2_swb_fx ( const Word16 hqswb_clas_fx, /* i : HQ2 class information */ const Word16 band_end_fx[], /* i : band end of each SB */ - Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ - Word16 p2a_bands_fx, /* i : flag for peakness */ + Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ + Word16 p2a_bands_fx, /* i : flag for peakness */ const Word16 length_fx, /* i : processed band length */ const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - Word16 *lowlength_fx, /* o : lowband length */ - Word16 *highlength_fx, /* o : highband length */ - Word32 L_m[] /* o : MDCT */ + Word16 *lowlength_fx, /* o : lowband length */ + Word16 *highlength_fx, /* o : highband length */ + Word32 L_m[] /* o : MDCT */ ) { IF( EQ_16(hqswb_clas_fx, HQ_HARMONIC)) @@ -1581,8 +1586,8 @@ void post_hq2_swb_fx const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ const Word16 band_start_fx[], /* i : band start of each SB */ const Word16 band_end_fx[], /* i : band end of each SB */ - Word32 L_y2[], /* o : output signal */ - Word16 npulses_fx[] /* i/o : Number of coded spectrum */ + Word32 L_y2[], /* o : output signal */ + Word16 npulses_fx[] /* i/o : Number of coded spectrum */ ) { Word16 i, k; @@ -1629,8 +1634,8 @@ void post_hq2_swb_fx void GetSynthesizedSpecThinOut_fx( const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */ const Word16 Qss, /* i : Q value of input vector */ - Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ - Word16 QsL, /* o : Q value of synthesized spectrum */ + Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ + Word16 QsL, /* o : Q value of synthesized spectrum */ const Word16 nBands_fx, /* i : Q0: number of subbands calculated */ const Word16 *sbWidth_fx, /* i : Q0: subband lengths */ const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */ @@ -1718,7 +1723,11 @@ Word16 div_s_ss( /* o: result of division (Word16 Q0) */ return res; } - +/*-------------------------------------------------------------------* + * hf_parinitiz() + * + * + *-------------------------------------------------------------------*/ void hf_parinitiz_fx( const Word32 L_total_brate, const Word16 hqswb_clas_fx, @@ -1825,8 +1834,8 @@ void GetlagGains_fx( const Word16 *sbWidth, /* i: Q0 width of SWB subbands */ const Word16 *lagIndices, /* i: Q0 lagIndices */ const Word16 predBufLen, /* i: Q0 length of predBuf */ - Word16 *lagGains_fx, /* o: QlagGains lagGains */ - Word16 *QlagGains /* o: Q0 Q value of lagGains */ + Word16 *lagGains_fx, /* o: QlagGains lagGains */ + Word16 *QlagGains /* o: Q0 Q value of lagGains */ ) { Word16 i; @@ -1943,11 +1952,11 @@ void GetlagGains_fx( void noise_extr_corcod_fx( Word32 L_spectra[], /* i : QsL core coder */ - const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ + const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ + const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ Word16 prev_hqswb_clas_fx, /* i : Q0 classification information */ Word16 *prev_ni_ratio_fx, /* i : Q15 noise parameter */ Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ @@ -2091,23 +2100,23 @@ void noise_extr_corcod_fx( *--------------------------------------------------------------------------*/ void ton_ene_est_fx( - Word32 L_xSynth_har[], /* i : QsL buffer with non tonal compoents */ - Word16 QsL, /* i : Q0 Q value for xSynth_har */ + Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */ + const Word16 QsL, /* i : Q0 Q value for xSynth_har */ Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */ Word16 *QbeL, /* o : Q0 Q value for be_tonal */ - Word32 L_band_energy[], /* i : Qbe subband energies */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 band_start[], /* i : Q0 subband start indices */ - const Word16 band_end[], /* i : Q0 subband end indices */ - const Word16 band_width[], /* i : Q0 subband widths */ - const Word16 fLenLow, /* i : Q0 low frequency width */ - const Word16 fLenHigh, /* i : Q0 High frequency width */ - Word16 bands, /* i : Q0 total subbands */ - Word16 har_bands, /* i : Q0 total number of harmonics bands */ - Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ - GainItem_fx pk_sf_fx[], /* i : */ - Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ - Word16 *pul_res /* i : Q0 tonal resolution */ + const Word32 L_band_energy[], /* i : Qbe subband energies */ + const Word16 Qbe, /* i : Q0 Q value for band_energy */ + const Word16 band_start[], /* i : Q0 subband start indices */ + const Word16 band_end[], /* i : Q0 subband end indices */ + const Word16 band_width[], /* i : Q0 subband widths */ + const Word16 fLenLow, /* i : Q0 low frequency width */ + const Word16 fLenHigh, /* i : Q0 High frequency width */ + const Word16 bands, /* i : Q0 total subbands */ + const Word16 har_bands, /* i : Q0 total number of harmonics bands */ + const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ + GainItem_fx pk_sf_fx[], /* i : */ + const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ + const Word16 *pul_res /* i : Q0 tonal resolution */ ) { Word16 i, j, k; @@ -2360,19 +2369,19 @@ void Gettonl_scalfact_fx ( Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */ Word16 QsL, /* i : Q0 Q value for outBuf */ - const Word32 *L_codbuf, /* i : QsL core coder */ - const Word16 fLenLow, /* i : Q0 lowband length */ - const Word16 fLenHigh, /* i : Q0 highband length */ - const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ - const Word16 bands, /* i : Q0 total number of subbands in a frame */ + const Word32 *L_codbuf, /* i : QsL core coder */ + const Word16 fLenLow, /* i : Q0 lowband length */ + const Word16 fLenHigh, /* i : Q0 highband length */ + const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ + const Word16 bands, /* i : Q0 total number of subbands in a frame */ Word32 *L_band_energy, /* i : Qbe band energy of each subband */ Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 *band_start, /* i : Q0 subband start indices */ - const Word16 *band_end, /* i : Q0 subband end indices */ - const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ + const Word16 *band_start, /* i : Q0 subband start indices */ + const Word16 *band_end, /* i : Q0 subband end indices */ + const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ Word32 L_be_tonal[], /* i : QbeL tonal energy */ Word16 QbeL, /* i : Q0 Q value for be_tonal */ - GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ + GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */ Word16 *pul_res_pk /* i : Q0 pulse resolution information */ ) @@ -2647,8 +2656,8 @@ void get_sigma_fx_har( const Word16 avg_fx, /* i: Qavg average of x_abs */ const Word16 Qavg, /* i: Q0 Q value of avg */ const Word16 length_fx, /* i: Q0 length */ - Word16 *sigma_fx, /* o: Qsigma sigma */ - Word16 *Qsigma /* o: Q0 Q value of sigma */ + Word16 *sigma_fx, /* o: Qsigma sigma */ + Word16 *Qsigma /* o: Q0 Q value of sigma */ ) { Word16 i; @@ -2749,12 +2758,12 @@ void get_sigma_fx_har( } void FindNBiggest2_simple_fx_har( - const Word32 *L_inBuf, /* i : input buffer (searched) */ - const Word16 Qabs_in, /* i : Q value of input buffer */ - GainItem_fx *pk_sf_fx, /* o : N biggest components found */ - const Word16 nIdx_fx, /* i : search length */ - Word16 *n_fx, /* i : number of components searched (N biggest) */ - Word16 n_nbiggestsearch /* i : */ + const Word32 *L_inBuf, /* i : input buffer (searched) */ + const Word16 Qabs_in, /* i : Q value of input buffer */ + GainItem_fx *pk_sf_fx, /* o : N biggest components found */ + const Word16 nIdx_fx, /* i : search length */ + Word16 *n_fx, /* i : number of components searched (N biggest) */ + Word16 n_nbiggestsearch /* i : */ ) { Word16 j; @@ -2915,16 +2924,16 @@ void FindNBiggest2_simple_fx_har( * spectrumsmooth_noiseton() * Spectrum normalization for the the core coder *--------------------------------------------------------------------------*/ -Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ - Word32 L_spectra[], /* i : Qs core coder */ - /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ - const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - Word16 *Qss, /* o : Q0 Q value for sspectra* */ - const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ - Word16 *ni_seed_fx /* io : Q0 random seed */ +Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ + Word32 L_spectra[], /* i : Qs core coder */ + /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ + const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ + Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ + Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ + Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ + Word16 *Qss, /* o : Q0 Q value for sspectra* */ + const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ + Word16 *ni_seed_fx /* io : Q0 random seed */ ) { Word16 i; @@ -3067,12 +3076,12 @@ void noiseinj_hf_fx( Word32 L_band_energy[], /* i : Qbe subband energies */ Word16 Qbe, /* i : Q0 Q value for band_energy */ Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */ - const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ - const Word16 BANDS_fx, /* i : Q0 total bands */ - const Word16 band_start_fx[], /* i : Q0 band start indices */ - const Word16 band_end_fx[], /* i : Q0 band end indices */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ - const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ + const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ + const Word16 BANDS_fx, /* i : Q0 total bands */ + const Word16 band_start_fx[], /* i : Q0 band start indices */ + const Word16 band_end_fx[], /* i : Q0 band end indices */ + const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ + const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ ) { Word16 k,i; @@ -3245,10 +3254,10 @@ void updat_prev_frm_fx( Word32 L_t_audio[], /* o: core coder buffer */ Word32 L_bwe_br, /* i: core bitrate */ Word16 length_fx, /* i: frame length coded bw */ - const Word16 inner_frame_fx, /* i: input frame length */ + const Word16 inner_frame_fx, /* i: input frame length */ Word16 bands_fx, /* i: sub band resolution */ Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ - const Word16 is_transient_fx, /* i: signal class information */ + const Word16 is_transient_fx, /* i: signal class information */ Word16 hqswb_clas_fx, /* i: signal class information */ Word16 *prev_hqswb_clas_fx, /* o: update signal class information */ Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 1e6fa69..fc74e1a 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3,28 +3,22 @@ ====================================================================================*/ -#include +#include #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" #include "basop_util.h" /*-----------------------------------------------------------------* -* Local functions +* Local function prototypes *-----------------------------------------------------------------*/ static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[] ); - static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); - static void Calc_st_filt_tbe(Word16 * apond2,Word16 * apond1,Word16 * parcor0,Word16 * sig_ltp_ptr,Word16 * mem_zero ); - static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); - static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); - void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); @@ -34,7 +28,6 @@ void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const W * Reset the SWB TBE encoder *-------------------------------------------------------------------*/ - void swb_tbe_reset_fx( Word32 mem_csfilt[], Word16 mem_genSHBexc_filt_down_shb[], @@ -249,13 +242,15 @@ void tbe_celp_exc( /* RETURN ARGUMENTS : */ /* _ None */ /*---------------------------------------------------------------------------*/ -void flip_and_downmix_generic_fx( Word16 input[], /* i : input spectrum Qx*/ - Word16 output[], /* o : output spectrum Qx*/ - const Word16 length, /* i : length of spectra */ - Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx+16*/ - Word32 mem2_ext[2*HILBERT_ORDER2], /* i/o: memory Qx+16*/ - Word32 mem3_ext[2*HILBERT_ORDER2], /* i/o: memory Qx+16*/ - Word16* phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ ) +void flip_and_downmix_generic_fx( + Word16 input[], /* i : input spectrum Qx*/ + Word16 output[], /* o : output spectrum Qx*/ + const Word16 length, /* i : length of spectra */ + Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx+16*/ + Word32 mem2_ext[2*HILBERT_ORDER2], /* i/o: memory Qx+16*/ + Word32 mem3_ext[2*HILBERT_ORDER2], /* i/o: memory Qx+16*/ + Word16* phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ +) { Word16 i, j; Word16 tmp_16[L_FRAME32k + HILBERT_ORDER1]; @@ -388,13 +383,14 @@ void flip_and_downmix_generic_fx( Word16 input[], /* i : input spectrum Qx*/ /*---------------------------------------------- * Hilbert transform - Double precision *------------------------------------------------*/ -static void Hilbert_transform_fx( Word32 tmp_R[], /* i: Real component of HB */ - Word32 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ - ) +static void Hilbert_transform_fx( + Word32 tmp_R[], /* i: Real component of HB */ + Word32 tmp_I[], /* i: Real component of HB */ + Word32 tmpi_R[], /* o: Real component of HB */ + Word32 tmpi_I[], /* o: Imag. component of HB */ + const Word16 length, /* i: input length */ + const Word16 HB_stage_id /* i: HB transform stage */ +) { Word16 i, hb_filter_stage, offset; Word32 L_tmp; @@ -449,13 +445,14 @@ static void Hilbert_transform_fx( Word32 tmp_R[], /* i: Real compon /*---------------------------------------------- * Hilbert transform - Single precision Stage 0 *------------------------------------------------*/ -static void Hilbert_transform_sp_fx( Word16 tmp_R[], /* i: Real component of HB */ - Word16 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ - ) +static void Hilbert_transform_sp_fx( + Word16 tmp_R[], /* i: Real component of HB */ + Word16 tmp_I[], /* i: Real component of HB */ + Word32 tmpi_R[], /* o: Real component of HB */ + Word32 tmpi_I[], /* o: Imag. component of HB */ + const Word16 length, /* i: input length */ + const Word16 HB_stage_id /* i: HB transform stage */ +) { Word16 i, hb_filter_stage, offset; Word32 L_tmp; @@ -493,9 +490,9 @@ static void Hilbert_transform_sp_fx( Word16 tmp_R[], /* i: Real com * flip_spectrum_fx *----------------------------------------------*/ void flip_spectrum_fx( - const Word16 input[], /* i : input spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length /* i : vector length */ + const Word16 input[], /* i : input spectrum */ + Word16 output[], /* o : output spectrum */ + const Word16 length /* i : vector length */ ) { Word16 i; @@ -674,9 +671,9 @@ static void filt_mu_fx( } static void scale_st_swb( - const Word16 * sig_in_fx, /* i : postfilter i signal */ - Word16 * sig_out_fx, /* i/o: postfilter o signal */ - Word16 * gain_prec_fx, /* i/o: last value of gain for subframe */ + const Word16 * sig_in_fx, /* i : postfilter i signal */ + Word16 * sig_out_fx, /* i/o: postfilter o signal */ + Word16 * gain_prec_fx, /* i/o: last value of gain for subframe */ Word16 SubFrameLength ) { @@ -783,7 +780,7 @@ void PostShortTerm_fx( Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - Word16 formant_fac_fx /* i : Strength of post-filter*/ + const Word16 formant_fac_fx /* i : Strength of post-filter*/ ) { Word16 apond1_fx[LPC_SHB_ORDER+1]; /* denominator coeff.*/ @@ -836,13 +833,13 @@ void PostShortTerm_fx( } void flip_spectrum_and_decimby4_fx( - const Word16 input[], /* i : input spectrum Q_inp */ - Word16 output[], /* o : output spectrum Q_inp */ - const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory Q_inp */ - Word16 mem2[], /* i/o : memory Q_inp */ - const Word16 - ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ ) + const Word16 input[], /* i : input spectrum Q_inp */ + Word16 output[], /* o : output spectrum Q_inp */ + const Word16 length, /* i : vector length */ + Word16 mem1[], /* i/o : memory Q_inp */ + Word16 mem2[], /* i/o : memory Q_inp */ + const Word16 ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ +) { Word16 i; Word16 factor, tmp[L_FRAME16k/2]; @@ -876,8 +873,8 @@ void flip_spectrum_and_decimby4_fx( move16(); } - Decimate_allpass_steep_fx( input_change, mem1, L_FRAME16k, tmp ); - Decimate_allpass_steep_fx( tmp, mem2, L_FRAME16k / 2, output ); + Decimate_allpass_steep_fx( input_change, mem1, length, tmp ); + Decimate_allpass_steep_fx( tmp, mem2, length / 2, output ); return; } @@ -891,7 +888,7 @@ void flip_spectrum_and_decimby4_fx( /* INPUT ARGUMENTS : */ /* _Word16 *lpc_shb i : lpc coefficients Q12 */ /* _Word16 coder_type i : coding type */ -/* _Word16 *bwe_exc_extended i : bandwidth extended exciatation Q_bwe_exc*/ +/* _Word16 *bwe_exc_extended i : bwidth extended exciatation Q_bwe_exc*/ /* _Word16 Q_bwe_exc i : Q format */ /* _Word16 voice_factors[] i : voicing factor Q15 */ /*--------------------------------------------------------------------------*/ @@ -912,21 +909,22 @@ void flip_spectrum_and_decimby4_fx( /*--------------------------------------------------------------------------*/ /* CALLED FROM : */ /*==========================================================================*/ -void GenShapedWBExcitation_fx( Word16* excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ - const Word16* lpc_shb, /* i : lpc coefficients Q12*/ - Word16* exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ - Word32* mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ - Word16* mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ - Word16* mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ - Word16* mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ - Word16* state_lpc_syn, /* i/o : memory Q_bwe_exc*/ - const Word16 coder_type, /* i : coding type */ - const Word16* bwe_exc_extended, /* i : bandwidth extended exciatation Q_bwe_exc*/ - const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor Q15*/ - const Word16 uv_flag /* i : unvoiced flag */ - , const Word16 igf_flag - ) +void GenShapedWBExcitation_fx( + Word16* excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16* lpc_shb, /* i : lpc coefficients Q12*/ + Word16* exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32* mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ + Word16* mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ + Word16* mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ + Word16* mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ + Word16* state_lpc_syn, /* i/o : memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16* bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag +) { Word16 i, j, k; Word16 wht_fil_mem [ LPC_WHTN_ORDER_WB ]; @@ -947,7 +945,7 @@ void GenShapedWBExcitation_fx( Word16* excSHB, /* o : synthesized shaped shb ex Word32 L_tmp, Ltemp1, Ltemp2; Word16 temp1, temp2, exp; Word32 Lmax; - Word16 max, n1, n2, sc; + Word16 max_val, n1, n2, sc; Word32 LepsP[LPC_WHTN_ORDER_WB+1]; Word16 tmp_vfac; Word16 avg_voice_fac; @@ -1016,16 +1014,16 @@ void GenShapedWBExcitation_fx( Word16* excSHB, /* o : synthesized shaped shb ex LPC_WHTN_ORDER_WB, 0, 3 ); /* Ensure pow1 is greater than zero when computing normalization */ - max = 0; + max_val = 0; FOR ( i = 0; i < L_FRAME16k / 4; i++ ) { excTmp2[i] = abs_s( exc4kWhtnd[i] ); move16(); /* Q_bwe_exc */ - max = s_max( max, excTmp2[i] ); + max_val = s_max( max_val, excTmp2[i] ); move16(); } - IF ( max == 0 ) + IF ( max_val == 0 ) { pow1 = 1; move16(); @@ -1034,7 +1032,7 @@ void GenShapedWBExcitation_fx( Word16* excSHB, /* o : synthesized shaped shb ex } ELSE { - n1 = norm_s( max ); + n1 = norm_s( max_val ); FOR ( i = 0; i < L_FRAME16k / 4; i++ ) { excTmp2_frac[i] = shl( excTmp2[i], n1 ); @@ -1161,9 +1159,10 @@ void GenShapedWBExcitation_fx( Word16* excSHB, /* o : synthesized shaped shb ex void GenWBSynth_fx( const Word16* input_synspeech, /* i : input synthesized speech Qx*/ - Word16* shb_syn_speech_16k, /* o : output highband compnent Qx*/ - Word16* state_lsyn_filt_shb1, /* i/o: memory Qx*/ - Word16* state_lsyn_filt_shb2 /* i/o: memory Qx*/ ) + Word16* shb_syn_speech_16k, /* o : output highband compnent Qx*/ + Word16* state_lsyn_filt_shb1, /* i/o: memory Qx*/ + Word16* state_lsyn_filt_shb2 /* i/o: memory Qx*/ +) { Word16 speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k]; Word16 i, maxm, nor; @@ -1201,7 +1200,73 @@ void GenWBSynth_fx( return; } +#ifdef ADD_IVAS_TBE_CODE +void find_td_envelope( + const float inp[], /* i : input signal */ + const int16_t len, /* i : length of the input signal */ + const int16_t len_h, /* i : length of the MA filter */ + float mem_h[], /* i/o: memory of the MA filter, length len_h/2 */ + float out[] /* o : td envelope of the input signal */ +) +{ + int16_t k, K; + float buf_in[L_FRAME16k + MAX_LEN_MA_FILTER], * p_in, * p_out, * p_prev, w; + + assert(len > 0 && len <= L_FRAME16k); + + K = (int16_t)(len_h / 2); /* length of FIR filter memory = half of the total filter length */ + w = 1.0f / len_h; /* MA filtering coefficient */ + + /* copy filter memory to the input buffer */ + if (mem_h != NULL) + { + mvr2r(mem_h, buf_in, K); + } + else + { + /* no memory available, use the first len_h/2 samples as memory */ + p_in = buf_in; + for (k = 0; k < K; k++) + { + *p_in++ = (float)fabs(inp[k]) * w; + } + } + + /* take the absolute value of the input signal and copy it to the input buffer */ + /* multiply each value by 1 / filter length */ + p_in = &buf_in[K]; + for (k = 0; k < len; k++) + { + *p_in++ = (float)fabs(inp[k]) * w; + } + + /* update filter memory from the end of the input buffer */ + if (mem_h != NULL) + { + mvr2r(&buf_in[len], mem_h, K); + } + + /* do MA filtering */ + out[0] = sum_f(buf_in, len_h); + p_out = &buf_in[0]; /* pointer to leaving sample */ + p_in = &buf_in[len_h]; /* pointer to entering sample*/ + for (k = 1; k < len - K; k++) + { + out[k] = out[k - 1] - *p_out++ + *p_in++; + } + /* use IIR filtering to extrapolate the last K samples */ + p_in = &buf_in[len - K]; + p_out = &out[len - K]; + p_prev = p_out - 1; + for (k = 0; k < K; k++) + { + *p_out++ = 0.05f * (*p_in++) + 0.95f * (*p_prev++); + } + + return; +} +#endif /*======================================================================================*/ /* FUNCTION : void GenShapedSHBExcitation_fx () */ /*--------------------------------------------------------------------------------------*/ @@ -1209,8 +1274,8 @@ void GenWBSynth_fx( /*--------------------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _(Word16) coder_type : coding type Q_bwe_exc */ -/* _(Word16) bwidth : input signal bandwidth Q0 */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q_bwe_exc */ +/* _(Word16) bwidth : input signal bwidth Q0 */ +/* _(Word16*) bwe_exc_extended :bwidth extended exciatation Q_bwe_exc */ /* _(Word16[]) voice_factors :voicing factors Q15 */ /* _(Word16*) lpc_shb :lpc coefficients Q12 */ /* _(Word16*) Q_bwe_exc :Q Format of bwe_exc_extended */ @@ -1236,34 +1301,48 @@ void GenWBSynth_fx( /* CALLED FROM : RX */ /*======================================================================================*/ void GenShapedSHBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32 *mem_csfilt, /* i/o: memory */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word32 *mem_csfilt, /* i/o: memory */ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16 *tbe_demph, /* i/o: de-emphasis memory */ - Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *state_lpc_syn, /* i/o: memory */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ + Word16 *tbe_demph, /* i/o: de-emphasis memory */ + Word16 *tbe_premph, /* i/o: pre-emphasis memory */ + Word16 *lpc_shb_sf, /* i: LP coefficients */ + const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + Word16 fb_state_lpc_syn[], /* i/o: memory */ + Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi +#ifdef ADD_IVAS_TBE_CODE + , /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16* nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */ + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word16* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ + Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */ + Word16* Env_error, /* o : error in SHB residual envelope modelling*/ + Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ +#endif ) { Word16 i, j, k; @@ -1302,7 +1381,20 @@ void GenShapedSHBExcitation_fx( Word32 White_exc16k_32[L_FRAME16k]; Word16 Q_temp; Word16 prev_Q_bwe_exc_fb; - +#ifdef ADD_IVAS_TBE_CODE + Word32 tempD; + Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; + Word16 cbsize; + Word16 mix_factor, old_fact, new_fact, fact, old_scale, new_scale, step_scale; + Word16 c0, c1, c2, c3, c4, c5, g1, g2, g, den; + Word16 EnvWhiteExc16k[L_FRAME16k], EnvExc16kWhtnd[L_FRAME16k]; + Word16 EnvWhiteExc16k_4k[L_FRAME4k] = { 0 }, EnvExc16kWhtnd_4k[L_FRAME4k] = { 0 }; + Word16 flag_plosive; + Word16 delta; + Word16 c0_part[NUM_SHB_SUBGAINS], c1_part[NUM_SHB_SUBGAINS], c2_part[NUM_SHB_SUBGAINS], c3_part[NUM_SHB_SUBGAINS], c4_part[NUM_SHB_SUBGAINS], c5_part[NUM_SHB_SUBGAINS]; + + mix_factor = 0.0f; +#endif set16_fx( zero_mem, 0, LPC_SHB_ORDER ); set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); @@ -1335,7 +1427,11 @@ void GenShapedSHBExcitation_fx( /* i: exc16k in Q_bwe_exc */ /* o: exc16kWhtnd in Q_bwe_exc */ - IF( GE_32(bitrate, ACELP_24k40)) +#ifdef ADD_IVAS_TBE_CODE + IF(GE_32(extl_brate, SWB_TBE_2k8)) +#else + IF(GE_32(bitrate, ACELP_24k40)) +#endif { temp2 = 0; move16(); @@ -1368,7 +1464,11 @@ void GenShapedSHBExcitation_fx( Q_pow1 = shl(*Q_bwe_exc,1); test(); +#ifdef ADD_IVAS_TBE_CODE + IF(EQ_16(flag_ACELP16k,0)) +#else IF( (LE_32( bitrate, ACELP_13k20 ))&&(GE_32(bitrate,ACELP_7k20))) +#endif { /* varEnvShape = mean_fx(voice_factors, 4); */ /* unroll the loop */ @@ -1394,7 +1494,7 @@ void GenShapedSHBExcitation_fx( tmp = mult_r(varEnvShape, varEnvShape); tmp = mult_r(tmp, varEnvShape); - /* max((0.68f - (float)pow(varEnvShape, 3)), 0.48f); */ + /* max_val((0.68f - (float)pow(varEnvShape, 3)), 0.48f); */ fb_deemph_fac = sub(22282/*0.68f Q15*/, tmp); fb_deemph_fac = s_max(fb_deemph_fac, 15729/*0.48f Q15*/); } @@ -1402,7 +1502,7 @@ void GenShapedSHBExcitation_fx( /*varEnvShape = 1.09875f - 0.49875f * varEnvShape; */ varEnvShape = msu_r(1179773824l/*0.549375f Q31*/, 8172/*0.249375f Q15*/, varEnvShape); - /*varEnvShape = min( max(varEnvShape, 0.6f), 0.999f); */ + /*varEnvShape = min( max_val(varEnvShape, 0.6f), 0.999f); */ varEnvShape = s_max(varEnvShape, 9830/*0.3f Q15*/); varEnvShape = s_min(varEnvShape, 16368/*0.4995f Q15*/); varEnvShape = shl(varEnvShape, 1); @@ -1414,7 +1514,11 @@ void GenShapedSHBExcitation_fx( test(); test(); test(); +#ifdef ADD_IVAS_TBE_CODE + IF (EQ_16(element_mode, EVS_MONO) && *mem_csfilt == 0 && ( (EQ_32( bitrate, ACELP_9k60 ))||(EQ_32(bitrate,ACELP_16k40))||(EQ_32(bitrate,ACELP_24k40)))) +#else IF ( *mem_csfilt == 0 && ( (EQ_32( bitrate, ACELP_9k60 ))||(EQ_32(bitrate,ACELP_16k40))||(EQ_32(bitrate,ACELP_24k40)))) +#endif { /* pre-init smoothing filter to avoid energy drop outs */ L_tmp = L_mult(excTmp2[0], 1638); @@ -1441,101 +1545,273 @@ void GenShapedSHBExcitation_fx( *mem_csfilt = Mult_32_16( L_tmp, varEnvShape ); move32(); } - - /* Track the low band envelope */ - L_tmp = *mem_csfilt; - move32(); - FOR ( i = 0; i < L_FRAME16k; i++ ) +#ifdef ADD_IVAS_TBE_CODE + if (MSFlag > 0) { - excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], excTmp2[i] ); - move16(); - /* excNoisyEnv : Q_bwe_exc, - *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ - L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_bwe_exc+16 */ + varEnvShape = 0.995f; + csfilt_num2[0] = 1.0f - varEnvShape; + csfilt_den2[1] = -varEnvShape; } - *mem_csfilt = L_tmp; - move32(); - /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; - create_random_vector_fx( White_exc16k, 256, bwe_seed ); - create_random_vector_fx( White_exc16k + 256, L_FRAME16k - 256, bwe_seed ); - L_tmp = L_deposit_l(0); - tmp = add(*Q_bwe_exc, 1); - FOR ( k = 0; k < L_FRAME16k; k++ ) + /* Track the low band envelope */ + if (element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT) + { + if (extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75) + { + mem_csfilt_left = 0.0f; + mem_csfilt_right = 0.0f; + for (k = 0; k < L_FRAME16k; k++) + { + excNoisyEnvLeft[k] = mem_csfilt_left + csfilt_num2[0] * excTmp2[k]; + mem_csfilt_left = -csfilt_den2[1] * excNoisyEnvLeft[k]; + excNoisyEnvRight[L_FRAME16k - k - 1] = mem_csfilt_right + csfilt_num2[0] * excTmp2[L_FRAME16k - k - 1]; + mem_csfilt_right = -csfilt_den2[1] * excNoisyEnvRight[L_FRAME16k - k - 1]; + } + + alpha = 0.0f; + step = 1.0f / L_FRAME16k; + for (k = 0; k < L_FRAME16k; k++) + { + excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + (1 - alpha) * excNoisyEnvRight[k]; + alpha += step; + } + } + } + else +#endif { - L_tmp4 = L_shl(L_deposit_l(White_exc16k[k]), tmp); - if(excNoisyEnv[k] != 0) + /* Track the low band envelope */ + L_tmp = *mem_csfilt; + move32(); + FOR(i = 0; i < L_FRAME16k; i++) { - L_tmp4 = L_mult(excNoisyEnv[k], White_exc16k[k]);/* (Q_bwe_exc) +5 +1*/ + excNoisyEnv[i] = mac_r(L_tmp, csfilt_num2[0], excTmp2[i]); + move16(); + /* excNoisyEnv : Q_bwe_exc, + *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ + L_tmp = L_mult(excNoisyEnv[i], neg_csfilt_den2[1]); /* Q_bwe_exc+16 */ } - White_exc16k_32[k] = L_tmp4; + *mem_csfilt = L_tmp; move32(); - L_tmp = L_max(L_tmp, L_abs(White_exc16k_32[k])); } - Q_temp = norm_l( L_tmp ); - if(L_tmp == 0) +#ifdef ADD_IVAS_TBE_CODE + if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) { - Q_temp = 31; - } - /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ - /* White_exc16k in Q6 */ + /* generate gaussian (white) excitation */ + for (k = 0; k < L_FRAME16k; k++) + { + White_exc16k[k] = (float)own_random(&bwe_seed[0]); + } - /* calculate pow22 */ - /* pow22=0.00001f */ - tmp = sub(shl(sub(*Q_bwe_exc, NOISE_QADJ), 1), 31); - pow22 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ - tmp = sub(NOISE_QFAC, 5); - FOR ( k = 0; k < L_FRAME16k; k++ ) - { - /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = mult_r( excNoisyEnv[k], shl(White_exc16k[k], tmp) ); - move16(); - /* i: excNoisyEnv in (Q_bwe_exc) */ - /* i: White_exc16k in Q6 */ - /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ - /* pow22 += White_exc16k[k] * White_exc16k[k]; */ - pow22 = L_mac0( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ + /* normalize the amplitude of the gaussian excitation to that of the LB exc. */ + pow22 = POW_EXC16k_WHTND; + v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); } - /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ - Q_pow22 = shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1); + else +#endif + { + /* create a random excitation - Reuse exc16k memory */ + White_exc16k = exc16k; + create_random_vector_fx(White_exc16k, L_FRAME, bwe_seed); + create_random_vector_fx(White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed); + + L_tmp = L_deposit_l(0); + tmp = add(*Q_bwe_exc, 1); + FOR(k = 0; k < L_FRAME16k; k++) + { + L_tmp4 = L_shl(L_deposit_l(White_exc16k[k]), tmp); + if (excNoisyEnv[k] != 0) + { + L_tmp4 = L_mult(excNoisyEnv[k], White_exc16k[k]);/* (Q_bwe_exc) +5 +1*/ + } + White_exc16k_32[k] = L_tmp4; + move32(); + L_tmp = L_max(L_tmp, L_abs(White_exc16k_32[k])); + } + Q_temp = norm_l(L_tmp); + if (L_tmp == 0) + { + Q_temp = 31; + } + /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ + /* White_exc16k in Q6 */ + /* calculate pow22 */ + /* pow22=0.00001f */ + tmp = sub(shl(sub(*Q_bwe_exc, NOISE_QADJ), 1), 31); + pow22 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ + tmp = sub(NOISE_QFAC, 5); + FOR(k = 0; k < L_FRAME16k; k++) + { + /* White_exc16k[k] *= excNoisyEnv[k]; */ + White_exc16k[k] = mult_r(excNoisyEnv[k], shl(White_exc16k[k], tmp)); + move16(); + /* i: excNoisyEnv in (Q_bwe_exc) */ + /* i: White_exc16k in Q6 */ + /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ + /* pow22 += White_exc16k[k] * White_exc16k[k]; */ + pow22 = L_mac0(pow22, White_exc16k[k], White_exc16k[k]); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ + } + /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ + Q_pow22 = shl(sub(*Q_bwe_exc, NOISE_QADJ), 1); + } +#ifdef ADD_IVAS_TBE_CODE + flag_plosive = 0; + move16(); + test(); test(); test(); + IF(GE_32(extl_brate, SWB_TBE_2k8) || EQ_32(extl_brate, SWB_TBE_1k10) || EQ_32(extl_brate, SWB_TBE_1k75))) +#else IF( GE_32(bitrate, ACELP_24k40)) +#endif { IF( EQ_16(*vf_ind,20)) /* encoder side */ { - Estimate_mix_factors_fx(shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, - White_exc16k, (*Q_bwe_exc-NOISE_QADJ), pow1, Q_pow1, - pow22, Q_pow22, voiceFacEst, vf_ind); - tmp = voiceFacEst[0]; +#ifdef ADD_IVAS_TBE_CODE + if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) + { + /* calculate TD envelopes of exc16kWhtnd and White_exc16k */ + find_td_envelope(White_exc16k, L_FRAME16k, 20, NULL, EnvWhiteExc16k); + find_td_envelope(exc16kWhtnd, L_FRAME16k, 20, NULL, EnvExc16kWhtnd); + + for (k = 0; k < L_FRAME4k; k++) + { + EnvWhiteExc16k_4k[k] = EnvWhiteExc16k[4 * k]; + EnvExc16kWhtnd_4k[k] = EnvExc16kWhtnd[4 * k]; + } + + /* calculate the optimal mix factor */ + c0 = c1 = c2 = c3 = c4 = c5 = 0.0f; + for (i = 0; i < NUM_SHB_SUBGAINS; i++) + { + c0_part[i] = sum2_f(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + c1_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + c2_part[i] = sum2_f(&EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + c3_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + c4_part[i] = 2.0f * dotp(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + c5_part[i] = sum2_f(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS); + + c0 += c0_part[i]; + c1 += c1_part[i]; + c2 += c2_part[i]; + c3 += c3_part[i]; + c4 += c4_part[i]; + c5 += c5_part[i]; + } + + den = 4.0f * c0 * c2 - c4 * c4; + g1 = (c3 * c4 - 2 * c1 * c2) / den; + g2 = (c1 * c4 - 2 * c0 * c3) / den; + + *Env_error = 0.0f; + flag_plosive = 0; + for (i = 0; i < NUM_SHB_SUBGAINS; i++) + { + Env_error_part[i] = c5_part[i] + g1 * g1 * c0_part[i] + g1 * c1_part[i] + g2 * g2 * c2_part[i] + g2 * c3_part[i] + g1 * g2 * c4_part[i]; + *Env_error += Env_error_part[i]; + + if (Env_error_part[i] > THR_ENV_ERROR_PLOSIVE) + { + /* envelope error is too high -> likely a plosive */ + flag_plosive = 1; + } + } + + if (flag_plosive) + { + /* plosive detected -> set the mixing factor to 0 */ + *vf_ind = 0; + mix_factor = 0.0f; + } + else + { + /* normalize gain */ + g = g2 / (g1 + g2); + + /* quantization of the mixing factor */ + cbsize = 1 << NUM_BITS_SHB_VF; + delta = 1.0f / (cbsize - 1); + if (g > 1.0f) + { + g = 1.0f; + } + else if (g < delta) + { + /* prevent low gains to be quantized to 0 as this is reserved for plosives */ + g = delta; + } + + *vf_ind = usquant(g, &mix_factor, 0.0f, 1.0f / (cbsize - 1), cbsize); + } + } + else +#endif + { + Estimate_mix_factors_fx(shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, + (*Q_bwe_exc - NOISE_QADJ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind); + tmp = voiceFacEst[0]; + tmp2 = MAX_16; + if (LE_16(tmp, 22938/*0.7f Q15*/)) + { + tmp2 = 26214/*0.8f Q15*/; + } + } } ELSE /* decoder side */ { - /* *vf_ind is an integer scale by 0.125f*/ - tmp = shl( *vf_ind, (15-3) ); +#ifdef ADD_IVAS_TBE_CODE + if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) + { + if (*vf_ind == 0) + { + mix_factor = 0.0f; + flag_plosive = 1; + } + else + { + mix_factor = usdequant(*vf_ind, 0.0f, 1.0f / ((1 << NUM_BITS_SHB_VF) - 1)); + } + } + else +#endif + { + /* *vf_ind is an integer scale by 0.125f*/ + tmp = shl(*vf_ind, (15 - 3)); + tmp2 = MAX_16; + if( LE_16(tmp, 22938/*0.7f Q15*/)) + { + tmp2 = 26214/*0.8f Q15*/; + } + } } - tmp2 = MAX_16; - if( LE_16(tmp, 22938/*0.7f Q15*/)) +#ifdef ADD_IVAS_TBE_CODE + IF (NE_32(extl_brate, SWB_TBE_1k10) && NE_32(extl_brate, SWB_TBE_1k75) ) +#endif { - tmp2 = 26214/*0.8f Q15*/; + voice_factors[0] = mult_r(voice_factors[0], tmp2); + move16(); + voice_factors[1] = mult_r(voice_factors[1], tmp2); + move16(); + voice_factors[2] = mult_r(voice_factors[2], tmp2); + move16(); + voice_factors[3] = mult_r(voice_factors[3], tmp2); + move16(); + voice_factors[4] = mult_r(voice_factors[4], tmp2); + move16(); } - voice_factors[0] = mult_r(voice_factors[0], tmp2); - move16(); - voice_factors[1] = mult_r(voice_factors[1], tmp2); - move16(); - voice_factors[2] = mult_r(voice_factors[2], tmp2); - move16(); - voice_factors[3] = mult_r(voice_factors[3], tmp2); - move16(); - voice_factors[4] = mult_r(voice_factors[4], tmp2); - move16(); } - +#ifdef ADD_IVAS_TBE_CODE + if (element_mode >= IVAS_CPE_DFT && nlExc16k != NULL) { - tmp = sub(Q_temp, 3); + /* save buffers for IC-BWE */ + mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); + v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); } +#endif + + tmp = sub(Q_temp, 3); FOR ( k = 0; k < L_FRAME16k; k++ ) { White_exc16k_FB[k] = round_fx(L_shl(White_exc16k_32[k], tmp)); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ @@ -1546,106 +1822,149 @@ void GenShapedSHBExcitation_fx( deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ - - IF ( EQ_16(coder_type, UNVOICED)) +#ifdef ADD_IVAS_TBE_CODE + if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75) { - L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ - - FOR ( k = 0; k < L_FRAME16k; k++ ) + if (!flag_plosive) /* use only LB excitation in case of plosives */ { - /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ - L_tmp = L_mult( White_exc16k[k], scale ); - /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx( L_shl(L_tmp, NOISE_QADJ) ); - /* exc16kWhtnd: Q_bwe_exc */ + /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */ + old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1); + new_scale = 1.0f; + step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); + scale = old_scale; + + /* interpolate between the old and the new value of the mixing factor */ + old_fact = *prev_mix_factor; + new_fact = mix_factor; + step = (new_fact - old_fact) / (L_FRAME16k / 2); + fact = old_fact; + + /* mixing of LB and gaussian excitation in the first half of the frame */ + for (k = 0; k < L_FRAME16k / 2; k++) + { + exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; + fact += step; + scale += step_scale; + } + + /* mixing of LB and gaussian excitation in the second half of the frame */ + for (; k < L_FRAME16k; k++) + { + exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; + } } - preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); - /* i/o: exc16kWhtnd (Q_bwe_exc) */ - /* i/o: tbe_premph (Q_bwe_exc) */ + preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); } - ELSE + else +#endif { - Word16 nbSubFr, lSubFr; - Word16 tempQ15; - Word32 tempQ31; - /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ - nbSubFr = NB_SUBFR16k; - lSubFr = (L_FRAME16k/NB_SUBFR16k); - IF(LT_32(bitrate, ACELP_24k40)) +#ifdef ADD_IVAS_TBE_CODE + if (coder_type == UNVOICED || MSFlag == 1) +#else + IF(EQ_16(coder_type, UNVOICED)) +#endif { - nbSubFr = NB_SUBFR; - move16(); - lSubFr = (L_FRAME16k/NB_SUBFR); - move16(); + L_tmp = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &exp); + scale = round_fx(L_shl(L_tmp, exp)); /*Q15 */ + + FOR(k = 0; k < L_FRAME16k; k++) + { + /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ + L_tmp = L_mult(White_exc16k[k], scale); + /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ + exc16kWhtnd[k] = round_fx(L_shl(L_tmp, NOISE_QADJ)); + /* exc16kWhtnd: Q_bwe_exc */ + } + preemph_fx(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); + /* i/o: exc16kWhtnd (Q_bwe_exc) */ + /* i/o: tbe_premph (Q_bwe_exc) */ } - k = 0; - FOR( i = 0; i < nbSubFr; i++ ) + ELSE { - test(); - IF( EQ_16(coder_type, VOICED)&&(LT_32(bitrate,ACELP_24k40))) + Word16 nbSubFr, lSubFr; + Word16 tempQ15; + Word32 tempQ31; + /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ + nbSubFr = NB_SUBFR16k; + lSubFr = (L_FRAME16k / NB_SUBFR16k); + IF(LT_32(bitrate, ACELP_24k40)) { - exp = 0; - tempQ15 = Sqrt16(voice_factors[i], &exp); /* Q15 */ - temp = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ - exp = 0; - tempQ15 = Sqrt16(temp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ - temp = sub(MAX_16, temp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + nbSubFr = NB_SUBFR; + move16(); + lSubFr = (L_FRAME16k / NB_SUBFR); + move16(); } - ELSE + k = 0; + FOR(i = 0; i < nbSubFr; i++) { - /* Adjust noise mixing for formant sharpening filter */ - tempQ15 = mult_r(SWB_NOISE_MIX_FAC_FX, formant_fac); - /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ - vf_tmp = sub(MAX_16, tempQ15); - vf_tmp = mult_r(voice_factors[i], vf_tmp); - - exp = 0; - tempQ15 = Sqrt16(vf_tmp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ - temp = sub(MAX_16, vf_tmp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ - } + test(); + IF(EQ_16(coder_type, VOICED) && (LT_32(bitrate,ACELP_24k40))) + { + exp = 0; + tempQ15 = Sqrt16(voice_factors[i], &exp); /* Q15 */ + temp = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + exp = 0; + tempQ15 = Sqrt16(temp, &exp); /* Q15 */ + temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + + /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ + temp = sub(MAX_16, temp); + tempQ31 = Mult_32_16(pow1, temp); + L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp); + temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + } + ELSE + { + /* Adjust noise mixing for formant sharpening filter */ + tempQ15 = mult_r(SWB_NOISE_MIX_FAC_FX, formant_fac); + /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ + vf_tmp = sub(MAX_16, tempQ15); + vf_tmp = mult_r(voice_factors[i], vf_tmp); + + exp = 0; + tempQ15 = Sqrt16(vf_tmp, &exp); /* Q15 */ + temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ + + /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ + temp = sub(MAX_16, vf_tmp); + tempQ31 = Mult_32_16(pow1, temp); + L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp); + temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ + } - FOR( j = 0; j < lSubFr; j++) - { - /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ - L_tmp = L_mult(temp2, White_exc16k[k+j]); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ - L_tmp = L_shl(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k+j] = mac_r(L_tmp, temp1, exc16kWhtnd[k+j]); - move16(); - /* Q_bwe_exc */ - } - k = add(k, lSubFr); + FOR(j = 0; j < lSubFr; j++) + { + /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ + L_tmp = L_mult(temp2, White_exc16k[k + j]); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ + L_tmp = L_shl(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r(L_tmp, temp1, exc16kWhtnd[k + j]); + move16(); + /* Q_bwe_exc */ + } + k = add(k, lSubFr); - /* estimate the pre-emph factor */ - tempQ15 = sub(MAX_16, voice_factors[i]); - exp = 0; - temp = Sqrt16(tempQ15, &exp); - temp = shl(temp, exp-1); + /* estimate the pre-emph factor */ + tempQ15 = sub(MAX_16, voice_factors[i]); + exp = 0; + temp = Sqrt16(tempQ15, &exp); + temp = shl(temp, exp - 1); - temp2 = add( temp, shl(temp1, -1) ); /* shift right by 1 to avoid overflow */ - temp = div_s( temp, temp2 ); /* Q15 */ - temp = mult_r( PREEMPH_FAC, temp ); + temp2 = add(temp, shl(temp1, -1)); /* shift right by 1 to avoid overflow */ + temp = div_s(temp, temp2); /* Q15 */ + temp = mult_r(PREEMPH_FAC, temp); - preemph_fx( &exc16kWhtnd[i*lSubFr], temp, lSubFr, tbe_premph ); - /* exc16kWhtnd: Q_bwe_exc; - tbe_premph: Q_bwe_exc*/ + preemph_fx(&exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph); + /* exc16kWhtnd: Q_bwe_exc; + tbe_premph: Q_bwe_exc*/ + } } } - +#ifdef ADD_IVAS_TBE_CODE + IF ( LT_32(extl_brate, SWB_TBE_2k8)) +#else IF ( LT_32(bitrate, ACELP_24k40)) +#endif { Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); /* i: exc16kWhtnd in Q_bwe_exc */ @@ -1754,6 +2073,10 @@ void GenShapedSHBExcitation_fx( set16_fx( White_exc16k_FB, 0, L_FRAME16k); } +#ifdef ADD_IVAS_TBE_CODE + *prev_pow_exc16kWhtnd = pow1; + *prev_mix_factor = mix_factor; +#endif return; } @@ -1779,11 +2102,11 @@ void GenShapedSHBExcitation_fx( /*------------------------------------------------------------------------------------*/ void GenSHBSynth_fx( - const Word16* input_synspeech, /* i : input synthesized speech */ + const Word16* input_synspeech, /* i : input synthesized speech */ Word16* shb_syn_speech_32k, /* o : output highband component */ Word32 Hilbert_Mem[], /* i/o: memory */ Word16 allpass_mem[], /* i/o: memory */ - const Word16 L_frame, /* i : ACELP frame length */ + const Word16 L_frame, /* i : ACELP frame length */ Word16* syn_dm_phase ) { @@ -1882,14 +2205,14 @@ void GenSHBSynth_fx( void ScaleShapedSHB_fx( const Word16 length, /* i : SHB overlap length */ - Word16* synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ - Word16* overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ + Word16* synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ + Word16* overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ const Word16* subgain, /* i : subframe gain Q15*/ const Word32 frame_gain, /* i : frame gain Q18 */ const Word16* win, /* i : window Q15*/ const Word16* subwin, /* i : subframes window Q15*/ Word16 *Q_bwe_exc - ,Word16* Qx /* o : newly computed Q factor for synSHB */ + ,Word16* Qx /* o : newly computed Q factor for synSHB */ ,Word16 n_mem3 ,Word16 prev_Q_bwe_syn2 ) @@ -2060,22 +2383,26 @@ void ScaleShapedSHB_fx( return; } - +/*-------------------------------------------------------------------* + * ScaleShapedWB() + * + * + *-------------------------------------------------------------------*/ void ScaleShapedWB_fx( const Word16 length, /* i : SHB overlap length */ - Word16* synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ - Word16* overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ + Word16* synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ + Word16* overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ const Word16* subgain, /* i : subframe gain Q15*/ const Word32 frame_gain, /* i : frame gain Q18 */ const Word16* win, /* i : window Q15*/ const Word16* subwin, /* i : subframes window Q15*/ const Word16 Q_bwe_exc - ,Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - ,Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ - ,Word16* Qx /* o : newly computed Q factor for synSHB */ - ,Word16 prev_Qx /* i : prev_Qx for memory scaling */ - ,Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + ,Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + ,Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ + ,Word16* Qx /* o : newly computed Q factor for synSHB */ + ,Word16 prev_Qx /* i : prev_Qx for memory scaling */ + ,Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ) { const Word16* skip; @@ -2084,7 +2411,7 @@ void ScaleShapedWB_fx( Word32 mod_syn[L_FRAME16k+L_SHB_LAHEAD]; Word16 sum_gain; Word32 L_tmp; - Word16 max, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2; + Word16 max_val, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2; /* Init */ set32_fx( mod_syn, 0, L_FRAME16k+L_SHB_LAHEAD ); @@ -2183,14 +2510,14 @@ void ScaleShapedWB_fx( - max = 0; + max_val = 0; move16(); FOR( i = 0; i < l_frame + l_shb_lahead; i++ ) { abs_sig = abs_s( round_fx(mod_syn[i]) ); - if(GT_16(abs_sig,max)) + if(GT_16(abs_sig,max_val)) { - max = abs_sig; + max_val = abs_sig; move16(); } } @@ -2198,14 +2525,14 @@ void ScaleShapedWB_fx( FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { abs_sig = abs_s( round_fx(Hilbert_Mem[i]) ); - if(GT_16(abs_sig,max)) + if(GT_16(abs_sig,max_val)) { - max = abs_sig; + max_val = abs_sig; move16(); } } - sc1 = norm_s( max ); /* max headroom in mod_syn[] */ + sc1 = norm_s( max_val ); /* max_val headroom in mod_syn[] */ sc2 = norm_s( round_fx(frame_gain));/* headroom in GainFrame */ IF(dynQ == 0 ) @@ -2223,7 +2550,7 @@ void ScaleShapedWB_fx( /* make sure 14 > Qx > 2 */ min_shift = 2-(Q_bwe_exc+3-16); max_shift = 13-(Q_bwe_exc+3-16); - max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max headroom to avoid overflow */ + max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max_val headroom to avoid overflow */ shift = s_min(min_shift,max_shift2); *Qx = (Q_bwe_exc+3) + shift - 16; @@ -2236,7 +2563,7 @@ void ScaleShapedWB_fx( /* make sure 14 > Qx > 3 */ min_shift = 3-(Q_bwe_exc+3-16); max_shift = 13-(Q_bwe_exc+3-16); - max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max headroom to avoid overflow */ + max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max_val headroom to avoid overflow */ shift = s_min(min_shift,max_shift2); *Qx = (Q_bwe_exc+3) + shift - 16; @@ -2274,14 +2601,20 @@ void ScaleShapedWB_fx( return; } +/*-------------------------------------------------------------------* + * non_linearity() + * + * Apply a non linearity to the SHB excitation + * -------------------------------------------------------------------*/ + static Word32 non_linearity_scaled_copy( const Word16 input[], Word16 j, - Word16 length, + const Word16 length, Word32 output[], Word32 prev_scale, - Word16 scale_step, - Word16 en_abs + const Word16 scale_step, + const Word16 en_abs ) { Word16 i; @@ -2363,19 +2696,19 @@ static Word32 non_linearity_scaled_copy( /*==========================================================================*/ void non_linearity_fx( - const Word16 input[], /* i : input signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ - Word32* pPrevScale, /* i/o: memory Q30 */ - Word16 Q_inp - ,Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ + const Word16 input[], /* i : input signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : input length */ + Word32* pPrevScale, /* i/o: memory Q30 */ + Word16 Q_inp, + Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ ) { Word16 i, j; - Word16 max=0; + Word16 max_val=0; Word32 scale; Word16 scale_step; Word16 exp, tmp; @@ -2431,20 +2764,20 @@ void non_linearity_fx( FOR ( i = j = 0; i < length_half; i++ ) { tmp = abs_s(input[i]); - if(GT_16(tmp,max)) + if(GT_16(tmp,max_val)) { j = i; move16(); } - max = s_max(max, tmp); + max_val = s_max(max_val, tmp); } - IF ( GT_16(max, shl(1,Q_inp))) + IF ( GT_16(max_val, shl(1,Q_inp))) { - exp = norm_s( max ); - tmp = div_s( shl(1, sub( 14, exp)), max ); /* Q(29-exp-Q_inp) */ + exp = norm_s( max_val ); + tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp,14)) ); /* Q31 */ } ELSE @@ -2501,24 +2834,24 @@ void non_linearity_fx( prev_scale = non_linearity_scaled_copy( input, j, length_half, output, prev_scale, scale_step, en_abs ); - max = 0; + max_val = 0; move16(); j = shr(length, 1); FOR ( i = length_half; i < length; i++ ) { tmp = abs_s(input[i]); - if(GT_16(tmp,max)) + if(GT_16(tmp,max_val)) { j = i; move16(); } - max = s_max(max, tmp); + max_val = s_max(max_val, tmp); } - IF ( GT_16( max, shl( 1, Q_inp ) )) + IF ( GT_16( max_val, shl( 1, Q_inp ) )) { - exp = norm_s( max ); - tmp = div_s( shl(1, sub( 14, exp)), max ); /* Q(29-exp-Q_inp) */ + exp = norm_s( max_val ); + tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */ scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)) ); /* Q31 */ } ELSE @@ -2594,7 +2927,7 @@ void non_linearity_fx( * create_random_vector() * * creates random number vector -* Note: the abs(max) value coming out of create_random_vector should +* Note: the abs(max_val) value coming out of create_random_vector should * fit into the precision of Q6. * -------------------------------------------------------------------*/ @@ -2677,9 +3010,9 @@ void create_random_vector_fx( /*======================================================================================*/ void interp_code_5over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx*/ + Word16 interp_code_fx[], /* o : output vector Qx*/ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, kk, kkp1, i_len2; @@ -2772,9 +3105,9 @@ void interp_code_5over2_fx( /*======================================================================================*/ void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx*/ + Word16 interp_code_fx[], /* o : output vector Qx*/ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, j; @@ -2805,10 +3138,12 @@ void interp_code_4over2_fx( * Reset the extra parameters only required for WB TBE synthesis *-------------------------------------------------------------------*/ -void wb_tbe_extras_reset_synth_fx( Word16 state_lsyn_filt_shb[], Word16 state_lsyn_filt_dwn_shb[], - Word16 state_32and48k_WB_upsample[] - ,Word16 state_resamp_HB[] - ) +void wb_tbe_extras_reset_synth_fx( + Word16 state_lsyn_filt_shb[], + Word16 state_lsyn_filt_dwn_shb[], + Word16 state_32and48k_WB_upsample[], + Word16 state_resamp_HB[] +) { set16_fx( state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); set16_fx( state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); @@ -3081,15 +3416,15 @@ void elliptic_bpf_48k_generic_fx( *-------------------------------------------------------------------*/ void synthesise_fb_high_band_fx( - const Word16 excitation_in[], /* i : full band excitation */ + const Word16 excitation_in[], /* i : full band excitation */ Word16 Q_fb_exc, - Word16 output[], /* o : high band speech - 14.0 to 20 kHz */ - const Word32 fb_exc_energy, /* i : full band excitation energy */ - const Word16 ratio, /* i : energy ratio */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 bfi, /* i : fec flag */ - Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ - Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */ + Word16 output[], /* o : high band speech - 14.0 to 20 kHz */ + const Word32 fb_exc_energy, /* i : full band excitation energy */ + const Word16 ratio, /* i : energy ratio */ + const Word16 L_frame, /* i : ACELP frame length */ + const Word16 bfi, /* i : fec flag */ + Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ + Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */ Word16 bpf_memory_Q[], Word16 Qout ) @@ -3189,18 +3524,18 @@ void synthesise_fb_high_band_fx( * Estimate mix factors for SHB excitation generation * *-------------------------------------------------------------------*/ void Estimate_mix_factors_fx( - const Word16 *shb_res, /* i : SHB LP residual in Q = Q_shb */ + const Word16 *shb_res, /* i : SHB LP residual in Q = Q_shb */ const Word16 Q_shb, - const Word16 *exc16kWhtnd, /* i : SHB transformed low band excitation Q_bwe_exc */ + const Word16 *exc16kWhtnd, /* i : SHB transformed low band excitation Q_bwe_exc */ const Word16 Q_bwe_exc, - const Word16 *White_exc16k_frac, /* i : Modulated envelope shaped white noise Q_frac */ + const Word16 *White_exc16k_frac,/* i : Modulated envelope shaped white noise Q_frac */ const Word16 Q_frac, - const Word32 pow1, /* i : SHB exc. power for normalization in Q_pow1 */ + const Word32 pow1, /* i : SHB exc. power for normalization in Q_pow1 */ const Word16 Q_pow1, - const Word32 pow22, /* i : White noise excitation for normalization in Q_pow22 */ + const Word32 pow22, /* i : White noise excitation for normalization in Q_pow22 */ const Word16 Q_pow22, - Word16 *vf_modified, /* o : Estimated voice factors */ - Word16 *vf_ind /* o : voice factors VQ index */ + Word16 *vf_modified, /* o : Estimated voice factors */ + Word16 *vf_ind /* o : voice factors VQ index */ ) { Word16 shb_res_local[L_FRAME16k], WN_exc_local[L_FRAME16k]; @@ -3257,7 +3592,7 @@ void Estimate_mix_factors_fx( temp_p1_p2 = Dot_product(temp_numer1, temp_numer2, length); /* 2*(Q_bwe_exc)+1 */ temp_p1_p3 = Dot_product(temp_numer2, temp_numer2, length); /* 2*(Q_bwe_exc)+1 */ - /* vf_modified[i] = min( max( (temp_p1_p2 / temp_p1_p3), 0.1f), 0.99f); */ + /* vf_modified[i] = min( max_val( (temp_p1_p2 / temp_p1_p3), 0.1f), 0.99f); */ /* tmp = (temp_p1_p2 / temp_p1_p3); */ IF(temp_p1_p3>0) { @@ -3326,7 +3661,56 @@ void Estimate_mix_factors_fx( return; } +#ifdef ADD_IVAS_TBE_CODE +/*-------------------------------------------------------------------* + * tbe_celp_exc() * + * * + * Prepare adaptive part of TBE excitation * + *-------------------------------------------------------------------*/ + +void tbe_celp_exc( + const int16_t element_mode, /* i : element mode */ + const int16_t idchan, /* i : channel ID */ + float* bwe_exc, /* i/o: BWE excitation */ + const int16_t L_frame, /* i : frame length */ + const int16_t L_subfr, /* i : subframe length */ + const int16_t i_subfr, /* i : subframe index */ + const int16_t T0, /* i : integer pitch lag */ + const int16_t T0_frac, /* i : fraction of lag */ + float* error, /* i/o: error */ + const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ +) +{ + int16_t i, offset; + if (element_mode == IVAS_CPE_TD && idchan == 1 && !tdm_LRTD_flag) + { + return; + } + + if (L_frame == L_FRAME) + { + offset = tbe_celp_exc_offset(T0, T0_frac); + + for (i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++) + { + bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset + (int16_t)*error]; + } + *error += (float)offset - (float)T0 * HIBND_ACB_L_FAC - 0.25f * HIBND_ACB_L_FAC * (float)T0_frac; + } + else + { + offset = T0 * 2 + (int16_t)((float)T0_frac * 0.5f + 4 + 0.5f) - 4; + for (i = 0; i < L_subfr * 2; i++) + { + bwe_exc[i + i_subfr * 2] = bwe_exc[i + i_subfr * 2 - offset + (int16_t)*error]; + } + *error += (float)offset - (float)T0 * 2 - 0.5f * (float)T0_frac; + } + + return; +} +#endif /*======================================================================================*/ /* FUNCTION : prep_tbe_exc_fx() */ /*--------------------------------------------------------------------------------------*/ @@ -3356,25 +3740,35 @@ void Estimate_mix_factors_fx( /*======================================================================================*/ void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate /* i :core bitrate */ + const Word16 L_frame_fx, /* i : length of the frame */ +#ifdef ADD_IVAS_TBE_CODE + const Word16 L_subfr, +#endif + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + Word32 core_brate +#ifdef ADD_IVAS_TBE_CODE + , /* i : core bitrate */ + const int16_t element_mode, /* i : element mode */ + const int16_t idchan, /* i : channel ID */ + const int16_t flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ +#endif ) { Word16 i; - Word16 tmp_code_fx[L_SUBFR * HIBND_ACB_L_FAC]; + Word16 tmp_code_fx[2*L_SUBFR * HIBND_ACB_L_FAC]; Word16 tmp_code_preInt_fx[L_SUBFR]; Word16 gain_code16 = 0; Word16 tmp /*, tmp1, tmp2*/; @@ -3384,10 +3778,13 @@ void prep_tbe_exc_fx( Word32 L_tmp, Ltemp1, Ltemp2; Word32 tempQ31; Word16 tempQ15; +#ifndef ADD_IVAS_TBE_CODE + Word16 L_subfr = L_SUBFR; +#endif /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; = VF_0th_PARAM + voice_fac * (VF_1st_PARAM + VF_2nd_PARAM * voice_fac ) - *voice_factors = min( max(0.0f, *voice_factors), 1.0f); */ + *voice_factors = min( max_val(0.0f, *voice_factors), 1.0f); */ tempQ31 = L_deposit_h( VF_1st_PARAM_FX ); tempQ15 = mac_r(tempQ31, VF_2nd_PARAM_FX, voice_fac_fx); tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); @@ -3409,12 +3806,22 @@ void prep_tbe_exc_fx( *voice_factors_fx = s_min(s_max(*voice_factors_fx, 0), MAX_16); move16(); - +#ifdef ADD_IVAS_TBE_CODE + IF (EQ_16(element_mode, IVAS_CPE_TD) && EQ_16(idchan, 1) && !tdm_LRTD_flag) + { + IF (flag_TD_BWE && i_subfr == 0) + { + set16_fx(bwe_exc, 0, L_FRAME32k); + } + return; + } + +#endif IF ( EQ_16(L_frame_fx,L_FRAME)) { - interp_code_5over2_fx( code_fx, tmp_code_fx, L_SUBFR ); /* code: Q9, tmp_code: Q9 */ + interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr); /* code: Q9, tmp_code: Q9 */ gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */ - FOR ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + FOR ( i = 0; i < L_subfr* HIBND_ACB_L_FAC; i++ ) { L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ @@ -3427,7 +3834,7 @@ void prep_tbe_exc_fx( { IF( gain_preQ_fx != 0 ) { - FOR( i = 0; i < L_SUBFR; i++ ) + FOR( i = 0; i < L_subfr; i++ ) { /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ @@ -3441,7 +3848,7 @@ void prep_tbe_exc_fx( } ELSE { - FOR( i = 0; i < L_SUBFR; i++ ) + FOR( i = 0; i < L_subfr; i++ ) { /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ @@ -3450,8 +3857,8 @@ void prep_tbe_exc_fx( } } - interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_SUBFR ); /* o: tmp_code in Q_exc */ - FOR ( i = 0; i < L_SUBFR * 2; i++ ) + interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr); /* o: tmp_code in Q_exc */ + FOR ( i = 0; i < L_subfr * 2; i++ ) { L_tmp = L_mult(gain_pit_fx, bwe_exc_fx[i + i_subfr_fx*2]); /*Q14+Q_exc+1 */ tmp = round_fx(L_shl(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ )); /* tmp in Q_exc */ @@ -3532,12 +3939,17 @@ void wb_tbe_extras_reset_fx( return; } +/*-------------------------------------------------------------------* +* get_tbe_bits() * +* * +* Determine TBE bit consumption per frame from bitrate * +*-------------------------------------------------------------------*/ Word16 get_tbe_bits_fx( - Word32 bitrate, - Word16 bandwidth - ,Word16 rf_mode + const Word32 total_brate, /* o : TBE bit consumption per frame */ + const Word16 bwidth, /* i : overall bitrate */ + const Word16 rf_mode /* i : bandwidht mode */ ) { Word16 i, bits = 0; @@ -3547,13 +3959,13 @@ Word16 get_tbe_bits_fx( /* TBE bits for core, primary frame */ test(); test(); - IF( (EQ_16(bandwidth, WB ))&&(EQ_32(bitrate,ACELP_13k20))) + IF( (EQ_16(bwidth, WB ))&&(EQ_32(total_brate,ACELP_13k20))) { /* Gain frame: 4, Gain shapes: 0, and LSFs: 2 */ bits = NUM_BITS_SHB_FrameGain_LBR_WB + NUM_BITS_LBR_WB_LSF; move16(); } - ELSE IF( (EQ_16(bandwidth, SWB ))&&(EQ_32(bitrate,ACELP_13k20))) + ELSE IF( (EQ_16(bwidth, SWB ))&&(EQ_32(total_brate,ACELP_13k20))) { /* Gain frame: 5, Gain shapes: 5, and lowrate LSFs: 8 */ bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; @@ -3564,20 +3976,20 @@ Word16 get_tbe_bits_fx( { test(); test(); - IF( (EQ_16(bandwidth, WB ))&&(EQ_32(bitrate,ACELP_9k60))) + IF( (EQ_16(bwidth, WB ))&&(EQ_32(total_brate,ACELP_9k60))) { bits = NUM_BITS_LBR_WB_LSF + NUM_BITS_SHB_FrameGain_LBR_WB; move16(); } - ELSE IF( (EQ_16( bandwidth, SWB ))||(EQ_16(bandwidth,FB))) + ELSE IF( (EQ_16( bwidth, SWB ))||(EQ_16(bwidth,FB))) { test(); - IF( EQ_32(bitrate, ACELP_9k60)) + IF( EQ_32(total_brate, ACELP_9k60)) { bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; move16(); } - ELSE IF( (GE_32( bitrate, ACELP_13k20 ))&&(LE_32(bitrate,ACELP_32k))) + ELSE IF( (GE_32( total_brate, ACELP_13k20 ))&&(LE_32(total_brate,ACELP_32k))) { bits = NUM_BITS_SHB_SUBGAINS + NUM_BITS_SHB_FRAMEGAIN + NUM_LSF_GRID_BITS + MIRROR_POINT_BITS; move16(); @@ -3588,19 +4000,19 @@ Word16 get_tbe_bits_fx( } } - if ( GE_32( bitrate, ACELP_24k40 )) + if ( GE_32( total_brate, ACELP_24k40 )) { bits = add( bits, NUM_BITS_SHB_ENER_SF + NUM_BITS_SHB_VF + NUM_BITS_SHB_RES_GS*NB_SUBFR16k ); } test(); test(); - if( EQ_16(bandwidth, SWB)&&(EQ_32(bitrate,ACELP_16k40)||EQ_32(bitrate,ACELP_24k40))) + if( EQ_16(bwidth, SWB)&&(EQ_32(total_brate,ACELP_16k40)||EQ_32(total_brate,ACELP_24k40))) { bits = add( bits, BITS_TEC+BITS_TFA ); } - if ( EQ_16(bandwidth, FB)) + if ( EQ_16(bwidth, FB)) { /* full band slope */ bits = add( bits, 4 ); diff --git a/lib_com/syn_12k8_fx.c b/lib_com/syn_12k8_fx.c index c774c7c..0b3657a 100644 --- a/lib_com/syn_12k8_fx.c +++ b/lib_com/syn_12k8_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include "options.h" /* Compilation switches */ +#include +#include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*===========================================================================*/ @@ -36,9 +35,9 @@ void syn_12k8_fx( Word16 L_frame, const Word16 *Aq, /* i : LP filter coefficients Q12 */ - const Word16 *exc, /* i : input signal Q_exc */ - Word16 *synth, /* o : output signal Q_syn */ - Word16 *mem, /* i/o: initial filter states Q_syn */ + const Word16 *exc, /* i : input signal Q_exc */ + Word16 *synth, /* o : output signal Q_syn */ + Word16 *mem, /* i/o: initial filter states Q_syn */ const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ /* 1 --> update of memory */ const Word16 Q_exc, /* i : Excitation scaling Q0 */ diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 05e1577..6882022 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -2,13 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "basop_util.h" #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" static Word32 syn_kern_2(Word32 L_tmp, const Word16 a[], const Word16 y[]) { @@ -62,7 +61,7 @@ void syn_filt_s_lc_fx( const Word16 shift, /* i : scaling to apply Q0 */ const Word16 a[], /* i : LP filter coefficients Q12 */ const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ + Word16 y[], /* o : output signal Qx-s */ const Word16 lg /* i : size of filtering Q0 */ ) { @@ -109,9 +108,9 @@ void Syn_filt_s( const Word16 a[], /* i : LP filter coefficients Q12 */ const Word16 m, /* i : order of LP filter Q0 */ const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ + Word16 y[], /* o : output signal Qx-s */ const Word16 lg, /* i : size of filtering Q0 */ - Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ + Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ ) { @@ -236,17 +235,17 @@ void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Wo void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ + Word16 old_exc[], /* i/o: excitation buffer */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec /* i : flag for decoder indication */ ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; /* Residual and update old_exc */ - IF( EQ_16(dec, DEC)) + IF( GE_16(dec, DEC)) { lerp( old_exc+L_EXC_MEM_DEC-(last_L_frame+last_L_frame/2), old_exc+L_EXC_MEM_DEC-(L_frame+L_frame/2), L_frame+L_frame/2, last_L_frame+last_L_frame/2 ); } @@ -254,7 +253,25 @@ void synth_mem_updt2( { lerp( old_exc+L_EXC_MEM-last_L_frame, old_exc+L_EXC_MEM-L_frame, L_frame, last_L_frame ); } - +#ifdef ADD_LRTD + IF (EQ_16(dec, DEC_IVAS) ) + { + IF (EQ_16(L_frame, L_FRAME16k)) + { + /* find scaling factor */ + PME() + en1 = 1.25f * sum2_f(mem_syn2, M); + en2 = sum2_f(mem_syn_r + L_SYN_MEM - M, M); + + loc_rat = sqrtf(en2) / (sqrtf(en1) + 0.01f); + /* scale synthesis filter memory */ + FOR (i = 0; i < M; i++) + { + mem_syn_r[L_SYN_MEM - M + i] *= loc_rat; + } + } + } +#endif /*Resamp memory*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index 48dc303..86deb5a 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -2,17 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include -#include +#include #include "options.h" /* Compilation switches */ #include "stl.h" #include "rom_com_fx.h" #include "prot_fx.h" -Word32 ar_div(Word32 num, Word32 denum) +Word32 ar_div( + Word32 num, + Word32 denum +) { Word16 exp1, exp2, exp, i; Word32 varout; @@ -65,7 +65,10 @@ Word32 ar_div(Word32 num, Word32 denum) return varout; } -static void bitstream_save_bit(PBITSTREAM_FX pBS, Word32 bit) +static void bitstream_save_bit( + PBITSTREAM_FX pBS, + Word32 bit +) { UWord8 cur; @@ -90,7 +93,9 @@ static void bitstream_save_bit(PBITSTREAM_FX pBS, Word32 bit) return; } -static UWord32 bitstream_load_bit(PBITSTREAM_FX pBS) +static UWord32 bitstream_load_bit( + PBITSTREAM_FX pBS +) { UWord32 bit; Word16 *curPos; @@ -118,7 +123,10 @@ static UWord32 bitstream_load_bit(PBITSTREAM_FX pBS) return bit; } -static void bitstream_rollback(PBITSTREAM_FX pBS, Word32 numBits) +static void bitstream_rollback( + PBITSTREAM_FX pBS, + Word32 numBits +) { FOR ( ; numBits > 0; numBits--) @@ -136,7 +144,10 @@ static void bitstream_rollback(PBITSTREAM_FX pBS, Word32 numBits) return; } -static void transmission_bits( PARCODEC_FX arInst, Word32 bit ) +static void transmission_bits( + PARCODEC_FX arInst, + Word32 bit +) { bitstream_save_bit( arInst->bsInst, bit ); arInst->num_bits = L_add(arInst->num_bits, 1); @@ -152,7 +163,10 @@ static void transmission_bits( PARCODEC_FX arInst, Word32 bit ) return; } -static Word32 ar_make_model_fx( const Word16 *freq, Word16 *model, Word16 len ) +static Word32 ar_make_model_fx( + const Word16 *freq, + Word16 *model, + const Word16 len ) { Word16 dist; Word32 sum = 0; @@ -203,7 +217,11 @@ static Word32 ar_make_model_fx( const Word16 *freq, Word16 *model, Word16 len ) return (model[0] > model[1]); } -void ar_encoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst, Word32 max_bits ) +void ar_encoder_start_fx( + PARCODEC_FX arInst, + PBITSTREAM_FX bsInst, + const Word32 max_bits +) { arInst->bsInst = bsInst; move32(); @@ -219,7 +237,11 @@ void ar_encoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst, Word32 max_b move32(); } -static void ar_encode_fx( PARCODEC_FX arInst, Word16 const *model, Word32 symbol ) +static void ar_encode_fx( + PARCODEC_FX arInst, + const Word16 *model, + Word32 symbol +) { Word32 range, high, low; @@ -277,7 +299,11 @@ static void ar_encode_fx( PARCODEC_FX arInst, Word16 const *model, Word32 symbol return; } -static void ar_encode_uniform_fx( PARCODEC_FX arInst, UWord32 data, Word32 bits ) +static void ar_encode_uniform_fx( + PARCODEC_FX arInst, + UWord32 data, + const Word32 bits +) { Word32 i; @@ -290,7 +316,9 @@ static void ar_encode_uniform_fx( PARCODEC_FX arInst, UWord32 data, Word32 bits return; } -void ar_encoder_done_fx( PARCODEC_FX arInst ) +void ar_encoder_done_fx( + PARCODEC_FX arInst +) { arInst->bits_to_follow ++; move16(); @@ -299,7 +327,10 @@ void ar_encoder_done_fx( PARCODEC_FX arInst ) return; } -void ar_decoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst ) +void ar_decoder_start_fx( + PARCODEC_FX arInst, + PBITSTREAM_FX bsInst +) { Word16 i; @@ -319,7 +350,10 @@ void ar_decoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst ) return; } -static Word16 ar_decode_fx( PARCODEC_FX arInst, Word16 const *model ) +static Word16 ar_decode_fx( + PARCODEC_FX arInst, + const Word16 *model +) { Word32 range, high, low, value, i; Word16 cum; @@ -374,14 +408,19 @@ static Word16 ar_decode_fx( PARCODEC_FX arInst, Word16 const *model ) return (symbol - 1); } -void ar_decoder_done_fx( PARCODEC_FX arInst ) +void ar_decoder_done_fx( + PARCODEC_FX arInst +) { bitstream_rollback( arInst->bsInst, AR_BITS - 2 ); return; } -static Word16 quantize_fx( Word16 val, Word16 D) +static Word16 quantize_fx( + Word16 val, + const Word16 D +) { Word16 qval4_fx; Word16 retval_fx; @@ -402,7 +441,10 @@ static Word16 quantize_fx( Word16 val, Word16 D) return retval_fx; } -static Word32 GetBitsFromPulses_fx(Word16 m, Word16 n) +static Word32 GetBitsFromPulses_fx( + Word16 m, + Word16 n +) { Word16 i, tmp, integer_fx, temp_fx1, temp_fx2, exp1, exp2; Word32 temp32; @@ -484,8 +526,19 @@ static Word32 GetBitsFromPulses_fx(Word16 m, Word16 n) } static -void TCQnew_fx( Word32 *v_fx, Word32 scale_fx, Word16 Qscale, - Word16 length, Word16 *vout_fx, Word16 pulses, Word16 *pulsesout, Word16* nzposout, Word32 *savedstates, Word32 * lasttrellislevel, Word32 terminate) +void TCQnew_fx( + Word32 *v_fx, + Word32 scale_fx, + Word16 Qscale, + Word16 length, + Word16 *vout_fx, + Word16 pulses, + Word16 *pulsesout, + Word16* nzposout, + Word32 *savedstates, + Word32 * lasttrellislevel, + Word32 terminate +) { Word16 i, st, dminpos, position; Word16 pulsesnum, nzpos = 0; @@ -656,8 +709,22 @@ void TCQnew_fx( Word32 *v_fx, Word32 scale_fx, Word16 Qscale, return; } -Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *magn_fx, Word32 *qscale_fx, Word32 *surplus_fx, Word16 *pulses, Word32* savedstates, Word32 noTCQ, - Word16 *nzpout, Word16 *bcount, Word32 *abuffer, Word16 *mbuffer, Word32 *sbuffer) +Word32 GetISCScale_fx( + Word32 *quants_fx, + Word16 size, + Word32 bits_fx, + Word16 *magn_fx, + Word32 *qscale_fx, + Word32 *surplus_fx, + Word16 *pulses, + Word32* savedstates, + Word32 noTCQ, + Word16 *nzpout, + Word16 *bcount, + Word32 *abuffer, + Word16 *mbuffer, + Word32 *sbuffer +) { Word32 pos, terminate, trellislevel, st; Word32 lasttrellislevel; @@ -693,7 +760,7 @@ Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *m pulsesnum = 0; move16(); - IF( surplus_fx != 0 ) + IF( surplus_fx != NULL ) { /* *surplus_fx += bits_fx; */ *surplus_fx = L_add(*surplus_fx, bits_fx); @@ -707,7 +774,7 @@ Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *m *nzpout = 0; move16(); - if ( pulses != 0 ) + if ( pulses != NULL) { *pulses = pulsesnum; move16(); @@ -1182,7 +1249,7 @@ Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *m move16(); } test(); - IF ( *nzpout > 1 && bcount != 0 ) + IF ( GT_16(*nzpout, 1) && bcount != NULL) { flag_g1 = 0; move16(); @@ -1230,7 +1297,13 @@ Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *m return L_shl(magnbits_fx, 1); } -void TCQLSB_fx(Word16 bcount, Word32 *abuffer_fx, Word16 *mbuffer_fx, Word32 *sbuffer_fx, Word16 *dpath) +void TCQLSB_fx( + Word16 bcount, + Word32 *abuffer_fx, + Word16 *mbuffer_fx, + Word32 *sbuffer_fx, + Word16 *dpath +) { Word16 i, st, dminpos, position; Word16 q_fx = 6554;/*Q15*/ @@ -1436,7 +1509,11 @@ void TCQLSB_fx(Word16 bcount, Word32 *abuffer_fx, Word16 *mbuffer_fx, Word32 *sb return; } -void TCQLSBdec_fx( Word16 *dpath, Word16 *mbuffer, Word16 bcount ) +void TCQLSBdec_fx( + Word16 *dpath, + Word16 *mbuffer, + Word16 bcount +) { /*float q = QTCQ;*/ Word16 q = 1;/*x5*/ @@ -1471,7 +1548,12 @@ void TCQLSBdec_fx( Word16 *dpath, Word16 *mbuffer, Word16 bcount ) return; } -void RestoreTCQ_fx( Word16 * magn, Word16 size, Word16 *bcount, Word16 *mbuffer) +void RestoreTCQ_fx( + Word16 * magn, + Word16 size, + Word16 *bcount, + Word16 *mbuffer +) { Word16 i, nzpos = 0, flag_g1 = 0; @@ -1512,7 +1594,12 @@ void RestoreTCQ_fx( Word16 * magn, Word16 size, Word16 *bcount, Word16 *mbuffer) return; } -void RestoreTCQdec_fx( Word16 * magn, Word16 size, Word16 *bcount, Word16 *mbuffer) +void RestoreTCQdec_fx( + Word16 * magn, + Word16 size, + Word16 *bcount, + Word16 *mbuffer +) { Word16 i, nzpos = 0, flag_g1 = 0; @@ -1557,14 +1644,20 @@ void RestoreTCQdec_fx( Word16 * magn, Word16 size, Word16 *bcount, Word16 *mbuff return; } -void InitLSBTCQ_fx(Word16 *bcount) +void InitLSBTCQ_fx( + Word16 *bcount +) { *bcount = 0; move16(); return; } -void SaveTCQdata_fx( PARCODEC_FX arInst, Word16 *dpath, Word16 bcount) +void SaveTCQdata_fx( + PARCODEC_FX arInst, + Word16 *dpath, + Word16 bcount +) { Word16 i; FOR ( i = 0; i < bcount; i++) @@ -1574,7 +1667,11 @@ void SaveTCQdata_fx( PARCODEC_FX arInst, Word16 *dpath, Word16 bcount) return; } -void LoadTCQdata_fx( PARCODEC_FX arInst, Word16 *dpath, Word16 bcount) +void LoadTCQdata_fx( + PARCODEC_FX arInst, + Word16 *dpath, + Word16 bcount +) { Word32 i; FOR ( i = 0; i < bcount; i++) @@ -1586,7 +1683,12 @@ void LoadTCQdata_fx( PARCODEC_FX arInst, Word16 *dpath, Word16 bcount) } -Word32 encode_position_ari_fx(PARCODEC_FX parenc, Word16* quants, Word16 size, Word32* est_bits_frame_fx) +Word32 encode_position_ari_fx( + PARCODEC_FX parenc, + Word16* quants, + Word16 size, + Word32* est_bits_frame_fx +) { Word16 i, tmp; Word16 nz = 0, pulses = 0; @@ -1734,7 +1836,14 @@ Word32 encode_position_ari_fx(PARCODEC_FX parenc, Word16* quants, Word16 size, W } return bits_fx; } -Word32 encode_magnitude_usq_fx(ARCODEC_FX* parenc, Word16* magn_fx, Word16 size, Word16 npulses, Word16 nzpos, Word32* est_frame_bits_fx) +Word32 encode_magnitude_usq_fx( + ARCODEC_FX* parenc, + Word16* magn_fx, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32* est_frame_bits_fx +) { Word16 i, j, k, tmp, magnp, magnzp; Word16 magn_position[MAX_PULSES]; @@ -1839,7 +1948,15 @@ Word32 encode_magnitude_usq_fx(ARCODEC_FX* parenc, Word16* magn_fx, Word16 size, } return bits_fx; } -Word32 encode_magnitude_tcq_fx(ARCODEC_FX* parenc, Word16* magn_fx, Word16 size, Word16 npulses, Word16 nzpos, Word32* savedstates, Word32* est_frame_bits_fx) +Word32 encode_magnitude_tcq_fx( + ARCODEC_FX* parenc, + Word16* magn_fx, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32* savedstates, + Word32* est_frame_bits_fx +) { Word32 tcq_bits_fx, bits_fx/*, est_frame_bits_fx*/; Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; @@ -1939,7 +2056,13 @@ Word32 encode_magnitude_tcq_fx(ARCODEC_FX* parenc, Word16* magn_fx, Word16 size, return bits_fx; } -Word32 encode_signs_fx(ARCODEC_FX* parenc, Word16* magn, Word16 size, Word16 npos, Word32* est_frame_bits_fx) +Word32 encode_signs_fx( + ARCODEC_FX* parenc, + Word16* magn, + Word16 size, + Word16 npos, + Word32* est_frame_bits_fx +) { Word32 i, sign; @@ -1959,7 +2082,13 @@ Word32 encode_signs_fx(ARCODEC_FX* parenc, Word16* magn, Word16 size, Word16 npo return L_deposit_h(npos); } -void decode_position_ari_fx(PARCODEC_FX pardec, Word16 size, Word16 npulses, Word16* nz, Word16* position) +void decode_position_ari_fx( + PARCODEC_FX pardec, + Word16 size, + Word16 npulses, + Word16* nz, + Word16* position +) { Word16 i, tmp, nzp; Word16 mode_num_nz[TCQ_MAX_BAND_SIZE]; @@ -2130,7 +2259,14 @@ void decode_position_ari_fx(PARCODEC_FX pardec, Word16 size, Word16 npulses, Wor return; } -void decode_magnitude_usq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out) +void decode_magnitude_usq_fx( + ARCODEC_FX* pardec, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word16* positions, + Word16* out +) { Word16 i, magnp, magnzp; Word16 magns[TCQ_MAX_BAND_SIZE], magncout = 0; @@ -2295,7 +2431,15 @@ void decode_magnitude_usq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Wo return; } -void decode_mangitude_tcq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out, Word32* surplus_fx) +void decode_mangitude_tcq_fx( + ARCODEC_FX* pardec, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word16* positions, + Word16* out, + Word32* surplus_fx +) { Word32 tcq_bits_fx, bits_fx/*, surplus_fx*/; Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; @@ -2458,7 +2602,11 @@ void decode_mangitude_tcq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Wo return; } -void decode_signs_fx(ARCODEC_FX* pardec, Word16 size, Word16* out) +void decode_signs_fx( + ARCODEC_FX* pardec, + Word16 size, + Word16* out +) { Word16 i; @@ -2479,7 +2627,11 @@ void decode_signs_fx(ARCODEC_FX* pardec, Word16 size, Word16* out) return; } -Word16 GetScale_fx( Word16 blen, Word32 bits_fx/*Q16*/, Word32 *surplus_fx/*Q16*/) +Word16 GetScale_fx( + Word16 blen, + Word32 bits_fx/*Q16*/, + Word32 *surplus_fx/*Q16*/ +) { Word16 pulses = MAX_PULSES, p_est, exp, exp1, exp2, magicnum; Word32 t, a, b, ab, estbits_fx = 0; diff --git a/lib_com/tcx_ltp.c b/lib_com/tcx_ltp.c index b23037e..5bf6716 100644 --- a/lib_com/tcx_ltp.c +++ b/lib_com/tcx_ltp.c @@ -1,19 +1,25 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" #include "prot_fx.h" -#include "stl.h" #include "cnst_fx.h" #include "basop_util.h" #include "rom_com_fx.h" -#define ALPHA 27853/*0.85f Q15*/ +/*------------------------------------------------------------------- + * Local constants + *-------------------------------------------------------------------*/ +#define ALPHA 27853/*0.85f Q15*/ -void tcx_ltp_get_lpc(Word16 *x, Word16 L, Word16 *A, Word16 order) +void tcx_ltp_get_lpc( + Word16 *x, + const Word16 L, + Word16 *A, + const Word16 order +) { Word16 i, j, s, s2, tmp; Word32 r, L_tmp; @@ -100,7 +106,19 @@ void tcx_ltp_get_lpc(Word16 *x, Word16 L, Word16 *A, Word16 order) } -static void tcx_ltp_get_zir( Word16 *zir, Word16 length, Word16 *synth_ltp, Word16 *synth, Word16 *A, Word16 lpcorder, Word16 gain, Word16 pitch_int, Word16 pitch_fr, Word16 pitres, Word16 filtIdx ) +static void tcx_ltp_get_zir( + Word16 *zir, + const Word16 length, + Word16 *synth_ltp, + Word16 *synth, + Word16 *A, + const Word16 lpcorder, + const Word16 gain, + const Word16 pitch_int, + const Word16 pitch_fr, + const Word16 pitres, + const Word16 filtIdx +) { Word16 buf[TCXLTP_LTP_ORDER], alpha, step; Word16 *x0, *x1; @@ -175,12 +193,12 @@ static void tcx_ltp_get_zir( Word16 *zir, Word16 length, Word16 *synth_ltp, Word } void predict_signal( - const Word16 excI[], /* i : input excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max,/* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ + const Word16 excI[], /* i : input excitation buffer */ + Word16 excO[], /* o : output excitation buffer */ + const Word16 T0, /* i : integer pitch lag */ + Word16 frac, /* i : fraction of lag */ + const Word16 frac_max, /* i : max fraction */ + const Word16 L_subfr /* i : subframe size */ ) { Word16 j; @@ -215,17 +233,18 @@ void predict_signal( } -static void tcx_ltp_synth_filter( Word16 *synth_ltp, - Word16 *synth, - Word16 length, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 pitch_res - ,Word16 *zir /* can be NULL */ - ,Word16 fade /* 0=normal, +1=fade-in, -1=fade-out */ - ,Word16 filtIdx - ) +static void tcx_ltp_synth_filter( + Word16 *synth_ltp, + Word16 *synth, + Word16 length, + Word16 pitch_int, + Word16 pitch_fr, + Word16 gain, + Word16 pitch_res, + Word16 *zir, /* can be NULL */ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out */ + Word16 filtIdx + ) { Word16 *x0, *x1; Word16 *y0, *y1; @@ -319,16 +338,17 @@ static void tcx_ltp_synth_filter( Word16 *synth_ltp, } } -Word16 tcx_ltp_decode_params( Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres - ) +Word16 tcx_ltp_decode_params( + Word16 *ltp_param, + Word16 *pitch_int, + Word16 *pitch_fr, + Word16 *gain, + Word16 pitmin, + Word16 pitfr1, + Word16 pitfr2, + Word16 pitmax, + Word16 pitres +) { Word16 tmp, tmp2; @@ -404,66 +424,96 @@ Word16 tcx_ltp_decode_params( Word16 *ltp_param, return 0; } -void tcx_ltp_post( Word8 tcxltp_on, - Word16 core, - Word16 L_frame, - Word16 L_frame_core, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf, - Word16 tcx_buf_len, - Word16 bfi, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *filtIdx_past, - Word16 pitres, - Word16 *pitres_past, - Word16 damping, - Word16 SideInfoOnly, - Word16 *mem_in, - Word16 *mem_out, - Word32 bitrate - ) +void tcx_ltp_post( + Decoder_State_fx* st, + TCX_LTP_DEC_HANDLE hTcxLtpDec, + Word16 core, + Word16 output_frame, + Word16 delay, + Word16 *sig, + Word16 *tcx_buf +) { Word16 tmp, L_transition, lpcorder, filtIdx; - Word16 gain2; + Word16 gain, gain2; Word32 tmp32; Word16 zir[L_FRAME_PLUS/4], A[TCXLTP_LTP_ORDER+1]; Word16 buf_in[TCXLTP_MAX_DELAY+L_FRAME48k+TCXLTP_MAX_DELAY], buf_out[2*L_FRAME48k]; Word16 *sig_in, *sig_out; + Word16 pitch_int, pitch_fr; + Word16 tcx_buf_len, bfi, L_frame_core, SideInfoOnly; + Word32 total_brate; + + total_brate = st->total_brate_fx; + move32(); + IF (EQ_16(st->element_mode, IVAS_CPE_MDCT)) + { + total_brate = st->bits_frame_nominal* FRAMES_PER_SEC; + move32(); + } filtIdx = 0; /* just to avoid comilation warnings */ + tcx_buf_len = NS2SA(st->output_Fs_fx, TCXLTP_DELAY_NS); + SideInfoOnly = 0; + if (GE_32(total_brate, HQ_96k)) + { + SideInfoOnly = 1; + move16(); + } + + L_frame_core = st->L_frame_fx; + move16(); + + if (EQ_16(st->element_mode, IVAS_CPE_MDCT)) + { + L_frame_core = L_FRAME; + move16(); + } + + IF (EQ_16(core, ACELP_CORE)) + { + bfi = 0; + pitch_int = 0; + pitch_fr = 0; + gain = 0; + L_frame_core = st->L_frame_past; + move16(); move16(); move16(); move16(); + } + ELSE + { + bfi = st->bfi_fx; + pitch_int = hTcxLtpDec->tcxltp_pitch_int; + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr; + gain = hTcxLtpDec->tcxltp_gain; + move16(); move16(); move16(); move16(); + } /******** Init ********/ /* Parameters */ - L_transition = shr(L_frame, 2); + L_transition = shr(output_frame, 2); lpcorder = TCXLTP_LTP_ORDER; move16(); /* Input buffer */ sig_in = buf_in + tcx_buf_len; - Copy( mem_in, buf_in, tcx_buf_len ); - Copy( sig, buf_in+tcx_buf_len, L_frame ); + Copy(hTcxLtpDec->tcxltp_mem_in, buf_in, tcx_buf_len ); + Copy( sig, buf_in+tcx_buf_len, output_frame ); IF ( core > ACELP_CORE ) { - Copy( tcx_buf, sig_in+L_frame, tcx_buf_len ); + Copy( tcx_buf, sig_in+output_frame, tcx_buf_len ); } - Copy( sig+L_frame-tcx_buf_len, mem_in, tcx_buf_len ); + Copy( sig+output_frame-tcx_buf_len, hTcxLtpDec->tcxltp_mem_in, tcx_buf_len ); /* Output buffer */ - sig_out = buf_out + L_frame; - Copy( mem_out, buf_out, L_frame ); + sig_out = buf_out + output_frame; + Copy(hTcxLtpDec->tcxltp_mem_out, buf_out, output_frame ); /* TCX-LTP parameters: integer pitch, fractional pitch, gain */ test(); test(); - IF ( !(SideInfoOnly != 0 || tcxltp_on != 0) || EQ_16(core, ACELP_CORE)) + IF ( !(SideInfoOnly != 0 || hTcxLtpDec->tcxltp != 0) || EQ_16(core, ACELP_CORE)) { /* No LTP */ pitch_int = 0; @@ -476,21 +526,32 @@ void tcx_ltp_post( Word8 tcxltp_on, ELSE IF (bfi == 0) { /* LTP and good frame */ - IF (NE_16(L_frame, L_frame_core)) - { - tmp = div_s(L_frame, shl(L_frame_core, 2)); /* Q13 */ - tmp32 = L_mult0(add(imult1616(pitch_int, pitres), pitch_fr), tmp); /* Q13 */ - tmp = round_fx(L_shl(tmp32, 3)); /* Q0 */ - pitch_int = idiv1616U(tmp, pitres); - pitch_fr = sub(tmp, imult1616(pitch_int, pitres)); - } - test(); - test(); - IF ( EQ_32(bitrate, 48000)&&EQ_16(L_frame_core,L_FRAME16k)) + IF(EQ_16(st->element_mode, EVS_MONO)) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ { - gain = mult_r(gain, 10486/*0.32f Q15*/); + IF(NE_16(output_frame, L_frame_core)) + { + tmp = div_s(output_frame, shl(L_frame_core, 2)); /* Q13 */ + tmp32 = L_mult0(add(imult1616(pitch_int, st->pit_res_max), pitch_fr), tmp); /* Q13 */ + tmp = round_fx(L_shl(tmp32, 3)); /* Q0 */ + pitch_int = idiv1616U(tmp, st->pit_res_max); + pitch_fr = sub(tmp, imult1616(pitch_int, st->pit_res_max)); + } + test(); + test(); + IF(EQ_32(total_brate, 48000) && EQ_16(L_frame_core, L_FRAME16k)) + { + gain = mult_r(gain, 10486/*0.32f Q15*/); + } + ELSE IF(EQ_32(total_brate, 48000) && EQ_16(L_frame_core, 512)) + { + gain = mult_r(gain, 13107/*0.40f Q15*/); + } + ELSE + { + gain = mult_r(gain, 20972/*0.64f Q15*/); + } } - ELSE IF ( EQ_32(bitrate, 48000)&&EQ_16(L_frame_core,512)) + ELSE IF (GT_16(st->element_mode, IVAS_SCE) && GE_32(total_brate, IVAS_96k)) { gain = mult_r(gain, 13107/*0.40f Q15*/); } @@ -503,13 +564,13 @@ void tcx_ltp_post( Word8 tcxltp_on, { /* PLC: [TCX: Fade-out] * PLC: LTP and bad frame (concealment) */ - IF (pitres == *pitres_past) /* ensure consistent core SR to previous frame; otherwise, set gain to 0 */ + IF (st->pit_res_max == st->pit_res_max_past) /* ensure consistent core SR to previous frame; otherwise, set gain to 0 */ { - pitch_int = *pitch_int_past; + pitch_int = hTcxLtpDec->tcxltp_pitch_int_post_prev; move16(); - pitch_fr = *pitch_fr_past; + pitch_fr = hTcxLtpDec->tcxltp_pitch_fr_post_prev; move16(); - gain = shl(mult_r(*gain_past, damping), 1); + gain = shl(mult_r(hTcxLtpDec->tcxltp_gain_post_prev, st->hTcxDec->damping), 1); } ELSE { @@ -525,7 +586,7 @@ void tcx_ltp_post( Word8 tcxltp_on, move16(); if ( bfi != 0 ) { - *gain_past = 0; + hTcxLtpDec->tcxltp_gain_post_prev = 0; move16(); } } @@ -534,7 +595,7 @@ void tcx_ltp_post( Word8 tcxltp_on, IF (EQ_16(L_frame_core, L_FRAME)) { - SWITCH ( L_frame ) + SWITCH ( output_frame ) { case L_FRAME8k: filtIdx = 0; @@ -558,7 +619,7 @@ void tcx_ltp_post( Word8 tcxltp_on, } ELSE IF (EQ_16(L_frame_core, L_FRAME16k)) { - SWITCH ( L_frame ) + SWITCH ( output_frame ) { case L_FRAME8k: filtIdx = 4; @@ -582,7 +643,7 @@ void tcx_ltp_post( Word8 tcxltp_on, } ELSE IF (EQ_16(L_frame_core, 512)) { - SWITCH ( L_frame ) + SWITCH ( output_frame ) { case L_FRAME8k: filtIdx = 8; @@ -613,101 +674,77 @@ void tcx_ltp_post( Word8 tcxltp_on, /******** Previous-frame part ********/ - tcx_ltp_synth_filter( sig_out, - sig_in, - delay, - *pitch_int_past, - *pitch_fr_past, - *gain_past, - *pitres_past, - NULL, - 0, - *filtIdx_past - ); + tcx_ltp_synth_filter( sig_out, sig_in, delay, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, + st->pit_res_max_past, NULL, 0, hTcxLtpDec->tcxltp_filt_idx_prev); /******** Transition part ********/ test(); test(); test(); - IF ( gain==0 && *gain_past==0 ) +#ifdef IVAS_CODE_TCX_LTP + if (st->element_mode != EVS_MONO) { - Copy( sig_in+delay, sig_out+delay, L_transition ); - } - ELSE IF ( *gain_past==0 ) - { - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - pitch_int, - pitch_fr, - gain, - pitres, - NULL, - 1, - filtIdx - ); - } - ELSE IF ( gain==0 ) - { - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - *pitch_int_past, - *pitch_fr_past, - *gain_past, - *pitres_past, - NULL, - -1, - *filtIdx_past - ); - } - ELSE IF ( EQ_16(gain, *gain_past)&&EQ_16(pitch_int,*pitch_int_past)&&EQ_16(pitch_fr,*pitch_fr_past)) - { - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - pitch_int, - pitch_fr, - gain, - pitres, - NULL, - 0, - filtIdx - ); + if (gain == 0.f && hTcxLtpDec->tcxltp_gain_post_prev == 0.f) + { + /* The filtering is deactivated, just copy input to the output */ + mvr2r(sig_in + delay, sig_out + delay, L_transition); + } + else if (gain == 0.f && hTcxLtpDec->tcxltp_gain_post_prev != 0.f) + { + /* Filtering with the first filter unit */ + tcx_ltp_synth_filter_10(sig_out + delay, sig_in + delay, L_transition, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev); + } + else if (gain != 0.f && hTcxLtpDec->tcxltp_gain_post_prev == 0.f) + { + /* Filtering with the second filter unit */ + tcx_ltp_synth_filter_01(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx); + } + else if (gain == hTcxLtpDec->tcxltp_gain_post_prev && pitch_int == hTcxLtpDec->tcxltp_pitch_int_post_prev && pitch_fr == hTcxLtpDec->tcxltp_pitch_fr_post_prev && st->pit_res_max == st->pit_res_max_past && filtIdx == hTcxLtpDec->tcxltp_filt_idx_prev) + { + tcx_ltp_synth_filter(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx); + } + else + { + /* Filtering with the first filter unit, followed by the filtering with the second filter unit */ + tcx_ltp_synth_filter_11_unequal_pitch(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx, + hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev); + } } ELSE +#endif { - tcx_ltp_get_lpc( sig_out+delay-L_frame, L_frame, A, lpcorder ); - - tcx_ltp_get_zir( zir, L_transition, sig_out+delay-lpcorder, sig_in+delay-lpcorder, A, lpcorder, gain, pitch_int, pitch_fr, pitres, filtIdx ); - - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - pitch_int, - pitch_fr, - gain, - pitres, - zir, - 0, - filtIdx - ); + IF(gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0) + { + Copy(sig_in + delay, sig_out + delay, L_transition); + } + ELSE IF(hTcxLtpDec->tcxltp_gain_post_prev == 0) + { + tcx_ltp_synth_filter(sig_out + delay, sig_in + delay, L_transition, pitch_int, + pitch_fr, gain, st->pit_res_max, NULL, 1, filtIdx ); + } + ELSE IF(gain == 0) + { + tcx_ltp_synth_filter(sig_out + delay,sig_in + delay,L_transition, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, + hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, NULL, -1, hTcxLtpDec->tcxltp_filt_idx_prev); + } + ELSE IF(EQ_16(gain, hTcxLtpDec->tcxltp_gain_post_prev) && EQ_16(pitch_int,hTcxLtpDec->tcxltp_pitch_int_post_prev) && EQ_16(pitch_fr,hTcxLtpDec->tcxltp_pitch_fr_post_prev)) + { + tcx_ltp_synth_filter(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx ); + } + ELSE + { + tcx_ltp_get_lpc(sig_out + delay - output_frame, output_frame, A, lpcorder); + + tcx_ltp_get_zir(zir, L_transition, sig_out + delay - lpcorder, sig_in + delay - lpcorder, A, lpcorder, gain, pitch_int, pitch_fr, st->pit_res_max, filtIdx); + + tcx_ltp_synth_filter(sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, zir, 0, filtIdx); + } } - /******** Current-frame part ********/ + /******** Current-frame part - subsequent subinterval, filtered with the third filter unit ********/ - tcx_ltp_synth_filter( sig_out+(delay+L_transition), - sig_in+(delay+L_transition), - L_frame-(delay+L_transition), - pitch_int, - pitch_fr, - gain, - pitres, - NULL, - 0, - filtIdx - ); + tcx_ltp_synth_filter( sig_out+(delay+L_transition),sig_in+(delay+L_transition), output_frame-(delay+L_transition), pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx); /******** Output ********/ @@ -715,18 +752,18 @@ void tcx_ltp_post( Word8 tcxltp_on, /* copy to output */ - Copy( sig_out, sig, L_frame ); + Copy( sig_out, sig, output_frame ); /* Update */ - *pitch_int_past = pitch_int; + hTcxLtpDec->tcxltp_pitch_int_post_prev = pitch_int; move16(); - *pitch_fr_past = pitch_fr; + hTcxLtpDec->tcxltp_pitch_fr_post_prev = pitch_fr; move16(); - *gain_past = gain2; + hTcxLtpDec->tcxltp_gain_post_prev = gain2; move16(); - *filtIdx_past = filtIdx; + hTcxLtpDec->tcxltp_filt_idx_prev = filtIdx; move16(); - *pitres_past = pitres; - Copy( sig_out, mem_out, L_frame ); + st->pit_res_max_past = st->pit_res_max; + Copy( sig_out, hTcxLtpDec->tcxltp_mem_out, output_frame ); } diff --git a/lib_com/tcx_mdct.c b/lib_com/tcx_mdct.c index 698b2b3..a17a107 100644 --- a/lib_com/tcx_mdct.c +++ b/lib_com/tcx_mdct.c @@ -2,15 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include +#include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "basop_util.h" -#include "stl.h" -static Word16 TCX_MDCT_GetScaleFactor(Word16 L, Word16 *factor_e) +static Word16 TCX_MDCT_GetScaleFactor( + const Word16 L, + Word16 *factor_e +) { Word16 factor; @@ -49,7 +50,10 @@ static Word16 TCX_MDCT_GetScaleFactor(Word16 L, Word16 *factor_e) return factor; } -static Word16 TCX_MDCT_Inverse_GetScaleFactor(Word16 L, Word16 *factor_e) +static Word16 TCX_MDCT_Inverse_GetScaleFactor( + const Word16 L, + Word16 *factor_e +) { Word16 factor; @@ -88,13 +92,23 @@ static Word16 TCX_MDCT_Inverse_GetScaleFactor(Word16 L, Word16 *factor_e) } -void TCX_MDCT(const Word16 *x, Word32 *y, Word16* y_e, Word16 l, Word16 m, Word16 r) +void TCX_MDCT( + const Word16 *x, + Word32 *y, + Word16* y_e, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode +) { Word16 i; Word16 factor, neg_factor; Word16 factor_e; - +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(element_mode) +#endif factor = TCX_MDCT_GetScaleFactor(add(add(shr(l, 1), m), shr(r, 1)), &factor_e); *y_e = add(*y_e, factor_e); @@ -126,17 +140,28 @@ void TCX_MDCT(const Word16 *x, Word32 *y, Word16* y_e, Word16 l, Word16 m, Word1 *y_e = sub(15, *y_e); edct_fx(y, y, l/2 + m + r/2, y_e); *y_e = sub(15-1, *y_e); + return; } -void TCX_MDST(const Word16 *x, Word32 *y, Word16* y_e, Word16 l, Word16 m, Word16 r) +void TCX_MDST( + const Word16 *x, + Word32 *y, + Word16* y_e, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode +) { Word16 i; Word16 factor, neg_factor; Word16 factor_e; - +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING +MY_UNUSED_Word(element_mode) +#endif factor = TCX_MDCT_GetScaleFactor(add(add(shr(l, 1), m), shr(r, 1)), &factor_e); *y_e = add(*y_e, factor_e); neg_factor = negate(factor); @@ -167,17 +192,27 @@ void TCX_MDST(const Word16 *x, Word32 *y, Word16* y_e, Word16 l, Word16 m, Word1 *y_e = sub(15, *y_e); edst_fx(y, y, l/2 + m + r/2, y_e); *y_e = sub(15-1, *y_e); - + return; } -void TCX_MDCT_Inverse(Word32 *x, Word16 x_e, Word16 *y, Word16 l, Word16 m, Word16 r) +void TCX_MDCT_Inverse( + Word32 *x, + Word16 x_e, + Word16 *y, + const Word16 l, + const Word16 m, + const Word16 r, + const Word16 element_mode +) { Word16 i, fac, negfac, s; Word16 L2 = l, R2 = r; Word32 tmp_buf[N_MAX+L_MDCT_OVLP_MAX/2]; Word16 fac_e; - +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word (element_mode) +#endif L2 = shr(l, 1); R2 = shr(r, 1); diff --git a/lib_com/tcx_mdct_window.c b/lib_com/tcx_mdct_window.c index cf69732..72d6133 100644 --- a/lib_com/tcx_mdct_window.c +++ b/lib_com/tcx_mdct_window.c @@ -2,24 +2,73 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include "options.h" #include "cnst_fx.h" #include "basop_util.h" #include "rom_basop_util.h" #include "prot_fx.h" -#include "stl.h" +#include "rom_com_fx.h" + +/*------------------------------------------------------------------- + * mdct_window_sine() + * + * + *-------------------------------------------------------------------*/ void mdct_window_sine(const PWord16 **window, const Word16 n) { - *window = getSineWindowTable(n); -} +#ifdef IVAS_CODE + if (element_mode == EVS_MONO) +#endif + { + *window = getSineWindowTable(n); + PMT("getSineWindowTable needs to be updated for IVAS") + } +#ifdef IVAS_CODE + else + { + const float* window_table = 0; + int16_t buf_in_size = 0; + switch (window_type) + { + case FULL_OVERLAP: + window_table = tcx_mdct_window_48; + buf_in_size = 420; + break; + case HALF_OVERLAP: + window_table = tcx_mdct_window_half_48; + buf_in_size = 180; + break; + case TRANSITION_OVERLAP: + case MIN_OVERLAP: + window_table = tcx_mdct_window_trans_48; + buf_in_size = 60; + break; + default: + assert(0 && "Unsupported window type"); + break; + } + + if (Fs == 48000) + { + mvr2r(window_table, window, n); + } + else + { + lerp(window_table, window, n, buf_in_size); + } + } +#endif +} -extern const Word16 window_48kHz_fx[]; -extern const Word16 window_256kHz[]; -extern const Word16 window_8_16_32kHz_fx[]; +/*------------------------------------------------------------------- + * mdct_window_aldo() + * + * + *-------------------------------------------------------------------*/ void mdct_window_aldo( Word16 *window1, diff --git a/lib_com/tcx_utils.c b/lib_com/tcx_utils.c index e11be3b..3d1f21c 100644 --- a/lib_com/tcx_utils.c +++ b/lib_com/tcx_utils.c @@ -2,10 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include -#include "stl.h" #include "options.h" #include "prot_fx.h" #include "rom_com_fx.h" @@ -14,8 +12,14 @@ #define inv_int InvIntTable - -Word16 getInvFrameLen(Word16 L_frame) /* returns 1/L_frame in Q21 format */ + /*-------------------------------------------------------------------* + * getInvFrameLen() + * + * + *-------------------------------------------------------------------*/ +Word16 getInvFrameLen( /* returns 1/L_frame in Q21 format */ + const Word16 L_frame +) { Word16 idx, s; @@ -30,64 +34,70 @@ Word16 getInvFrameLen(Word16 L_frame) /* returns 1/L_frame in Q21 format */ return shl(L_frame_inv[idx], sub(s, 7)); } - +/*-------------------------------------------------------------------* + *tcx_get_windows() + * + * + * ------------------------------------------------------------------ - */ static void tcx_get_windows( - TCX_config const * tcx_cfg, /* i: TCX configuration */ - Word16 left_mode, /* i: overlap mode of left window half */ - Word16 right_mode, /* i: overlap mode of right window half */ - Word16 *left_overlap, /* o: left overlap length */ - PWord16 const **left_win, /* o: left overlap window */ - Word16 *right_overlap, /* o: right overlap length */ - PWord16 const **right_win, /* o: right overlap window */ - Word8 fullband /* i: fullband flag */ + TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX configuration */ + const Word16 left_mode, /* i: overlap mode of left window half */ + const Word16 right_mode, /* i: overlap mode of right window half */ + Word16 *left_overlap, /* o: left overlap length */ + const PWord16 **left_win, /* o: left overlap window */ + Word16 *right_overlap, /* o: right overlap length */ + const PWord16 **right_win, /* o: right overlap window */ + const Word8 fullband /* i: fullband flag */ ) -{ +{ /* LFE is only FULL_OVERLAP*/ IF (fullband == 0) { /* Left part */ SWITCH (left_mode) { case TRANSITION_OVERLAP: /* ACELP->TCX transition */ - *left_overlap = tcx_cfg->tcx_mdct_window_trans_length; + *left_overlap = hTcxCfg->tcx_mdct_window_trans_length; move16(); - *left_win = tcx_cfg->tcx_mdct_window_trans; + *left_win = hTcxCfg->tcx_mdct_window_trans; BREAK; case MIN_OVERLAP: - *left_overlap = tcx_cfg->tcx_mdct_window_min_length; + *left_overlap = hTcxCfg->tcx_mdct_window_min_length; move16(); - *left_win = tcx_cfg->tcx_mdct_window_minimum; + *left_win = hTcxCfg->tcx_mdct_window_minimum; BREAK; case HALF_OVERLAP: - *left_overlap = tcx_cfg->tcx_mdct_window_half_length; + *left_overlap = hTcxCfg->tcx_mdct_window_half_length; move16(); - *left_win = tcx_cfg->tcx_mdct_window_half; + *left_win = hTcxCfg->tcx_mdct_window_half; BREAK; case FULL_OVERLAP: - *left_overlap = tcx_cfg->tcx_mdct_window_length; + *left_overlap = hTcxCfg->tcx_mdct_window_length; + move16(); + *left_win = hTcxCfg->tcx_aldo_window_1_trunc; move16(); - *left_win = tcx_cfg->tcx_aldo_window_1_trunc; BREAK; default: assert(!"Not supported overlap"); } /* Right part */ - SWITCH (right_mode) + SWITCH(right_mode) { case MIN_OVERLAP: - *right_overlap = tcx_cfg->tcx_mdct_window_min_length; + *right_overlap = hTcxCfg->tcx_mdct_window_min_length; move16(); - *right_win = tcx_cfg->tcx_mdct_window_minimum; + *right_win = hTcxCfg->tcx_mdct_window_minimum; BREAK; case HALF_OVERLAP: - *right_overlap = tcx_cfg->tcx_mdct_window_half_length; + *right_overlap = hTcxCfg->tcx_mdct_window_half_length; move16(); - *right_win = tcx_cfg->tcx_mdct_window_half; + *right_win = hTcxCfg->tcx_mdct_window_half; BREAK; case FULL_OVERLAP: - *right_overlap = tcx_cfg->tcx_mdct_window_delay; + *right_overlap = hTcxCfg->tcx_mdct_window_delay; + move16(); + *right_win = hTcxCfg->tcx_aldo_window_2; move16(); - *right_win = tcx_cfg->tcx_aldo_window_2; BREAK; default: assert(!"Not supported overlap"); @@ -99,19 +109,19 @@ static void tcx_get_windows( SWITCH (left_mode) { case TRANSITION_OVERLAP: /* ACELP->TCX transition */ - *left_overlap = tcx_cfg->tcx_mdct_window_trans_lengthFB; + *left_overlap = hTcxCfg->tcx_mdct_window_trans_lengthFB; move16(); - *left_win = tcx_cfg->tcx_mdct_window_transFB; + *left_win = hTcxCfg->tcx_mdct_window_transFB; BREAK; case MIN_OVERLAP: - *left_overlap = tcx_cfg->tcx_mdct_window_min_lengthFB; + *left_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; move16(); - *left_win = tcx_cfg->tcx_mdct_window_minimumFB; + *left_win = hTcxCfg->tcx_mdct_window_minimumFB; BREAK; case HALF_OVERLAP: - *left_overlap = tcx_cfg->tcx_mdct_window_half_lengthFB; + *left_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; move16(); - *left_win = tcx_cfg->tcx_mdct_window_halfFB; + *left_win = hTcxCfg->tcx_mdct_window_halfFB; BREAK; case RECTANGULAR_OVERLAP: *left_overlap = 0; @@ -119,9 +129,10 @@ static void tcx_get_windows( *left_win = NULL; BREAK; case FULL_OVERLAP: - *left_overlap = tcx_cfg->tcx_mdct_window_lengthFB; - move16(); - *left_win = tcx_cfg->tcx_aldo_window_1_FB_trunc; + *left_overlap = hTcxCfg->tcx_mdct_window_lengthFB; + *left_win = hTcxCfg->tcx_aldo_window_1_FB_trunc; + move16();move16(); + BREAK; default: assert(!"Not supported overlap"); @@ -131,14 +142,14 @@ static void tcx_get_windows( SWITCH (right_mode) { case MIN_OVERLAP: - *right_overlap = tcx_cfg->tcx_mdct_window_min_lengthFB; + *right_overlap = hTcxCfg->tcx_mdct_window_min_lengthFB; move16(); - *right_win = tcx_cfg->tcx_mdct_window_minimumFB; + *right_win = hTcxCfg->tcx_mdct_window_minimumFB; BREAK; case HALF_OVERLAP: - *right_overlap = tcx_cfg->tcx_mdct_window_half_lengthFB; + *right_overlap = hTcxCfg->tcx_mdct_window_half_lengthFB; move16(); - *right_win = tcx_cfg->tcx_mdct_window_halfFB; + *right_win = hTcxCfg->tcx_mdct_window_halfFB; BREAK; case RECTANGULAR_OVERLAP: *right_overlap = 0; @@ -146,9 +157,9 @@ static void tcx_get_windows( *right_win = NULL; BREAK; case FULL_OVERLAP: - *right_overlap = tcx_cfg->tcx_mdct_window_delayFB; - move16(); - *right_win = tcx_cfg->tcx_aldo_window_2_FB; + *right_overlap = hTcxCfg->tcx_mdct_window_delayFB; + move16();move16(); + *right_win = hTcxCfg->tcx_aldo_window_2_FB; BREAK; default: assert(!"Not supported overlap"); @@ -202,18 +213,23 @@ static void tcx_windowing_analysis( move16(); } } - +/*-------------------------------------------------------------------* + * WindowSignal() + * + * + *-------------------------------------------------------------------*/ void WindowSignal( - TCX_config const *tcx_cfg, /* input: configuration of TCX */ - Word16 offset, /* input: left folding point offset relative to the input signal pointer */ - Word16 left_overlap_mode, /* input: overlap mode of left window half */ - Word16 right_overlap_mode, /* input: overlap mode of right window half */ - Word16 * left_overlap_length, /* output: TCX window left overlap length */ - Word16 * right_overlap_length, /* output: TCX window right overlap length */ - Word16 const in[], /* input: input signal */ - Word16 * L_frame, /* input/output: frame length */ - Word16 out[] /* output: output windowed signal */ - ,Word8 fullband /* input: fullband flag */ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word16 offset, /* i : left folding point offset relative to the input signal pointer */ + const Word16 left_overlap_mode, /* i : overlap mode of left window half */ + Word16 right_overlap_mode, /* i : overlap mode of right window half */ + Word16 * left_overlap_length, /* o : TCX window left overlap length */ + Word16 * right_overlap_length, /* o : TCX window right overlap length */ + const Word16 in[], /* i : input signal */ + Word16 * L_frame, /* i/o: frame length */ + Word16 out[], /* o : output windowed signal */ + const Word16 truncate_aldo, /* i : nonzero to truncate long ALDO slope */ + const Word8 fullband /* i : fullband flag */ ) { Word16 l, r; @@ -225,7 +241,7 @@ void WindowSignal( * Init * *-----------------------------------------------------------*/ - tcx_get_windows(tcx_cfg, left_overlap_mode, right_overlap_mode, &l, &left_win, &r, &right_win, fullband); + tcx_get_windows(hTcxCfg, left_overlap_mode, right_overlap_mode, &l, &left_win, &r, &right_win, fullband); /* Init lengths */ @@ -235,15 +251,15 @@ void WindowSignal( /* Increase frame size for 5ms */ IF (fullband == 0) { - *L_frame = add(*L_frame, tcx_cfg->tcx5Size); + *L_frame = add(*L_frame, hTcxCfg->tcx5Size); move16(); - offset = negate(shr(tcx_cfg->tcx_mdct_window_trans_length, 1)); + offset = negate(shr(hTcxCfg->tcx_mdct_window_trans_length, 1)); } ELSE { - *L_frame = add(*L_frame, tcx_cfg->tcx5SizeFB); + *L_frame = add(*L_frame, hTcxCfg->tcx5SizeFB); move16(); - offset = negate(shr(tcx_cfg->tcx_mdct_window_trans_lengthFB, 1)); + offset = negate(shr(hTcxCfg->tcx_mdct_window_trans_lengthFB, 1)); } } @@ -252,19 +268,19 @@ void WindowSignal( *-----------------------------------------------------------*/ tcx_windowing_analysis(in-shr(l,1)+offset, *L_frame, l, left_win, r, right_win, out); - - IF (EQ_16(left_overlap_mode, FULL_OVERLAP)) + test(); test(); + IF (EQ_16(left_overlap_mode, FULL_OVERLAP) && truncate_aldo ) { /* fade truncated ALDO window to avoid discontinuities */ Word16 i, tmp; const PWord16 *p; - p = tcx_cfg->tcx_mdct_window_minimum; - tmp = shr(tcx_cfg->tcx_mdct_window_min_length, 1); + p = hTcxCfg->tcx_mdct_window_minimum; + tmp = shr(hTcxCfg->tcx_mdct_window_min_length, 1); IF (fullband != 0) { - p = tcx_cfg->tcx_mdct_window_minimumFB; - tmp = shr(tcx_cfg->tcx_mdct_window_min_lengthFB, 1); + p = hTcxCfg->tcx_mdct_window_minimumFB; + tmp = shr(hTcxCfg->tcx_mdct_window_min_lengthFB, 1); } FOR (i = 0; i < tmp; i++) @@ -285,27 +301,32 @@ void WindowSignal( move16(); } +/*-------------------------------------------------------------------* + * tcx_windowing_synthesis_current_frame() + * + * + *-------------------------------------------------------------------*/ void tcx_windowing_synthesis_current_frame( Word16 *signal, /* i/o: signal vector */ const PWord16 *window, /* i: TCX window vector */ const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ const PWord16 *window_min, /* i: TCX minimum overlap window */ - Word16 window_length, /* i: TCX window length */ - Word16 window_half_length, /* i: TCX half window length */ - Word16 window_min_length, /* i: TCX minimum overlap length */ - Word16 left_rect, /* i: left part is rectangular */ - Word16 left_mode, /* i: overlap mode of left window half */ + const Word16 window_length, /* i: TCX window length */ + const Word16 window_half_length, /* i: TCX half window length */ + const Word16 window_min_length, /* i: TCX minimum overlap length */ + const Word16 left_rect, /* i: left part is rectangular */ + const Word16 left_mode, /* i: overlap mode of left window half */ Word16 *acelp_zir, /* i: acelp ZIR */ - Word16 *old_syn, - Word16 *syn_overl, - Word16 *A_zir, - const PWord16 *window_trans, + const Word16* old_syn, + const Word16* syn_overl, + const Word16* A_zir, + const PWord16 *window_trans, Word16 acelp_zir_len, - Word16 acelp_mem_len, - Word16 last_core_bfi, /* i : last core */ - Word8 last_is_cng - ,Word16 fullbandScale + const Word16 acelp_mem_len, + const Word16 last_core_bfi, /* i : last core */ + const Word8 last_is_cng, + const Word16 fullbandScale ) { @@ -565,16 +586,20 @@ void tcx_windowing_synthesis_current_frame( /* Right part asymmetric window : with ALDO do nothing->can be skipped*/ } - +/*-------------------------------------------------------------------* + * tcx_windowing_synthesis_past_frame() + * + * + *-------------------------------------------------------------------*/ void tcx_windowing_synthesis_past_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - Word16 window_length, /* i: TCX window length */ - Word16 window_half_length, /* i: TCX half window length */ - Word16 window_min_length, /* i: TCX minimum overlap length */ - Word16 right_mode /* i: overlap mode (left_mode of current frame) */ + Word16 *signal, /* i/o: signal vector */ + const PWord16 *window, /* i: TCX window vector */ + const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ + const PWord16 *window_min, /* i: TCX minimum overlap window */ + const Word16 window_length, /* i: TCX window length */ + const Word16 window_half_length, /* i: TCX half window length */ + const Word16 window_min_length, /* i: TCX minimum overlap length */ + const Word16 right_mode /* i: overlap mode (left_mode of current frame) */ ) { @@ -645,10 +670,22 @@ void tcx_windowing_synthesis_past_frame( } } - -void lpc2mdct(Word16 *lpcCoeffs, Word16 lpcOrder, - Word16 *mdct_gains, Word16 *mdct_gains_exp, - Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp) +/*-------------------------------------------------------------------* + * lpc2mdct() + * + * + *-------------------------------------------------------------------*/ + +void lpc2mdct( + Word16 *lpcCoeffs, + const Word16 lpcOrder, + Word16 *mdct_gains, + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, + Word16 *mdct_inv_gains_exp, + const int16_t length, + const int16_t noInverse +) { Word32 ComplexData[2*FDNS_NPTS]; Word16 i, j, k, sizeN, step, scale, s, tmp16; @@ -656,7 +693,14 @@ void lpc2mdct(Word16 *lpcCoeffs, Word16 lpcOrder, Word32 tmp32; const PWord16 *ptwiddle; Word32 workBuffer[2*BASOP_CFFT_MAX_LENGTH]; - sizeN = shl(FDNS_NPTS, 1); + +#ifndef IVAS_CODE_TCX_UTIL + MY_UNUSED_Word(noInverse) +#endif + + assert(length <= FDNS_NPTS); + sizeN = shl(length, 1); + BASOP_getTables(NULL, &ptwiddle, &step, sizeN); /*ODFT*/ assert(lpcOrder < FDNS_NPTS); @@ -675,92 +719,111 @@ void lpc2mdct(Word16 *lpcCoeffs, Word16 lpcOrder, ComplexData[2*i] = L_deposit_l(0); ComplexData[2*i+1] = L_deposit_l(0); } - /* half length FFT */ - scale = add(norm_s(lpcCoeffs[0]),1); - BASOP_cfft((cmplx *)ComplexData, FDNS_NPTS, &scale, workBuffer); - /*Get amplitude*/ - j = sub(FDNS_NPTS, 1); - k = 0; + move16(); - FOR (i=0; i In float the fft type changes as well + /*Get amplitude*/ + j = sub(length, 1); + k = 0; + for (i = 0; i < length; i++) { - mdct_gains[k] = g; - move16(); - } - if (mdct_gains_exp != 0) - { - mdct_gains_exp[k] = g_e; - move16(); + mdct_gains[i] = (float)(sqrt(RealData[i] * RealData[i] + ImagData[i] * ImagData[i])); } - if (mdct_inv_gains != 0) - { - mdct_inv_gains[k] = ig; - move16(); - } - if (mdct_inv_gains_exp != 0) - { - mdct_inv_gains_exp[k] = ig_e; - move16(); + } + else +#endif + { + /* half length FFT */ + scale = add(norm_s(lpcCoeffs[0]), 1); + BASOP_cfft((cmplx*)ComplexData, FDNS_NPTS, &scale, workBuffer); + /*Get amplitude*/ + j = sub(length, 1); + k = 0; + FOR(i = 0; i < length / 2; i++) + { + s = sub(norm_l(L_max(L_abs(ComplexData[2 * i]), L_abs(ComplexData[2 * i + 1]))), 1); + tmp16 = extract_h(L_shl(ComplexData[2 * i], s)); + tmp32 = L_mult(tmp16, tmp16); + tmp16 = extract_h(L_shl(ComplexData[2 * i + 1], s)); + tmp16 = mac_r(tmp32, tmp16, tmp16); + s = shl(sub(scale, s), 1); + if (tmp16 == 0) + { + s = -16; + move16(); + } + if (tmp16 == 0) + { + tmp16 = 1; + move16(); + } + BASOP_Util_Sqrt_InvSqrt_MantExp(tmp16, s, &g, &g_e, &ig, &ig_e); + if (mdct_gains != 0) + { + mdct_gains[k] = g; + move16(); + } + if (mdct_gains_exp != 0) + { + mdct_gains_exp[k] = g_e; + move16(); + } + if (mdct_inv_gains != 0) + { + mdct_inv_gains[k] = ig; + move16(); + } + if (mdct_inv_gains_exp != 0) + { + mdct_inv_gains_exp[k] = ig_e; + move16(); + } + k = add(k, 1); + s = sub(norm_l(L_max(L_abs(ComplexData[2 * j]), L_abs(ComplexData[2 * j + 1]))), 1); + tmp16 = extract_h(L_shl(ComplexData[2 * j], s)); + tmp32 = L_mult(tmp16, tmp16); + tmp16 = extract_h(L_shl(ComplexData[2 * j + 1], s)); + tmp16 = mac_r(tmp32, tmp16, tmp16); + s = shl(sub(scale, s), 1); + if (tmp16 == 0) + { + s = -16; + move16(); + } + if (tmp16 == 0) + { + tmp16 = 1; + move16(); + } + BASOP_Util_Sqrt_InvSqrt_MantExp(tmp16, s, &g, &g_e, &ig, &ig_e); + if (mdct_gains != 0) + { + mdct_gains[k] = g; + move16(); + } + if (mdct_gains_exp != 0) + { + mdct_gains_exp[k] = g_e; + move16(); + } + if (mdct_inv_gains != 0) + { + mdct_inv_gains[k] = ig; + move16(); + } + if (mdct_inv_gains_exp != 0) + { + mdct_inv_gains_exp[k] = ig_e; + move16(); + } + j = sub(j, 1); + k = add(k, 1); } - j = sub(j, 1); - k = add(k, 1); } } /** @@ -771,7 +834,13 @@ void lpc2mdct(Word16 *lpcCoeffs, Word16 lpcOrder, * \param gains shaping gains mantissas * \param gains_exp shaping gains exponents */ -void mdct_shaping(Word32 x[], Word16 lg, Word16 const gains[], Word16 const gains_exp[]) +void mdct_shaping( + Word32 x[], + const Word16 lg, + const Word16 gains[], + const Word16 gains_exp[] + /*const Word16 nBands*/ /*Parameter added in IVAS, but always equal to FDNS_NPTS */ +) { Word16 i, k, l; @@ -779,6 +848,7 @@ void mdct_shaping(Word32 x[], Word16 lg, Word16 const gains[], Word16 const gain Word32 * px = x; Word16 const * pgains = gains; Word16 const * pgainsexp = gains_exp; + /* FDNS_NPTS = 64 */ k = shr(lg, 6); @@ -859,7 +929,14 @@ void mdct_shaping(Word32 x[], Word16 lg, Word16 const gains[], Word16 const gain } -void mdct_shaping_16(Word16 const x[], Word16 lg, Word16 lg_total, Word16 const gains[], Word16 const gains_exp[], Word16 gains_max_exp, Word32 y[]) +void mdct_shaping_16( + const Word16 x[], + const Word16 lg, + const Word16 lg_total, + const Word16 gains[], + const Word16 gains_exp[], + Word16 gains_max_exp, Word32 y[] +) { Word16 i, k, l; Word16 m, gain_exp; @@ -906,7 +983,12 @@ void mdct_shaping_16(Word16 const x[], Word16 lg, Word16 lg_total, Word16 const } } -void mdct_noiseShaping_interp(Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[]) +void mdct_noiseShaping_interp( + Word32 x[], + const Word16 lg, + Word16 gains[], + Word16 gains_exp[] +) { Word16 i, j, jp, jn, k, l; Word16 g, pg, ng, e, tmp; @@ -1051,20 +1133,22 @@ void mdct_noiseShaping_interp(Word32 x[], Word16 lg, Word16 gains[], Word16 gain } -void PsychAdaptLowFreqDeemph(Word32 x[], - const Word16 lpcGains[], const Word16 lpcGains_e[], - Word16 lf_deemph_factors[] - ) +void PsychAdaptLowFreqDeemph( + Word32 x[], + const Word16 lpcGains[], + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] +) { Word16 i; - Word16 max, max_e, fac, min, min_e, tmp, tmp_e; + Word16 max_val, max_e, fac, min, min_e, tmp, tmp_e; Word32 L_tmp; assert(lpcGains[0] >= 0x4000); - max = lpcGains[0]; + max_val = lpcGains[0]; move16(); max_e = lpcGains_e[0]; move16(); @@ -1073,7 +1157,7 @@ void PsychAdaptLowFreqDeemph(Word32 x[], min_e = lpcGains_e[0]; move16(); - /* find minimum (min) and maximum (max) of LPC gains in low frequencies */ + /* find minimum (min) and maximum (max_val) of LPC gains in low frequencies */ FOR (i = 1; i < 9; i++) { IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], min, min_e) < 0) @@ -1084,9 +1168,9 @@ void PsychAdaptLowFreqDeemph(Word32 x[], move16(); } - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], max, max_e) > 0) + IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], max_val, max_e) > 0) { - max = lpcGains[i]; + max_val = lpcGains[i]; move16(); max_e = lpcGains_e[i]; move16(); @@ -1096,20 +1180,20 @@ void PsychAdaptLowFreqDeemph(Word32 x[], min_e = add(min_e, 5); /* min *= 32.0f; */ test(); - IF ((compMantExp16Unorm(max, max_e, min, min_e) < 0) && (min > 0)) + IF ((compMantExp16Unorm(max_val, max_e, min, min_e) < 0) && (min > 0)) { - /* fac = tmp = (float)pow(max / min, 0.0078125f); */ + /* fac = tmp = (float)pow(max_val / min, 0.0078125f); */ tmp_e = min_e; move16(); tmp = Inv16(min, &tmp_e); - L_tmp = L_shl(L_mult(tmp, max), add(tmp_e, max_e)); /* Q31 */ + L_tmp = L_shl(L_mult(tmp, max_val), add(tmp_e, max_e)); /* Q31 */ L_tmp = BASOP_Util_Log2(L_tmp); /* Q25 */ L_tmp = L_shr(L_tmp, 7); /* 0.0078125f = 1.f/(1<<7) */ L_tmp = BASOP_Util_InvLog2(L_tmp); /* Q31 */ tmp = round_fx(L_tmp); /* Q15 */ fac = tmp; /* Q15 */ move16(); - /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ + /* gradual lowering of lowest 32 bins; DC is lowered by (max_val/tmp)^1/4 */ FOR (i = 31; i >= 0; i--) { x[i] = Mpy_32_16_1(x[i], fac); @@ -1125,12 +1209,15 @@ void PsychAdaptLowFreqDeemph(Word32 x[], } -void AdaptLowFreqDeemph(Word32 x[], Word16 x_e, - Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], Word16 lpcGains_e[], - const Word16 lg, - Word16 lf_deemph_factors[] - ) +void AdaptLowFreqDeemph( + Word32 x[], + Word16 x_e, + Word16 tcx_lpc_shaped_ari, + Word16 lpcGains[], + Word16 lpcGains_e[], + const Word16 lg, + Word16 lf_deemph_factors[] +) { Word16 i, i_max, i_max_old, lg_4; @@ -1308,16 +1395,17 @@ void AdaptLowFreqDeemph(Word32 x[], Word16 x_e, } void tcx_noise_filling( - Word32 *Q, + Word32* Q, Word16 Q_e, Word16 seed, - Word16 iFirstLine, - Word16 lowpassLine, - Word16 nTransWidth, - Word16 L_frame, - Word16 tiltCompFactor, + const Word16 iFirstLine, + const Word16 lowpassLine, + const Word16 nTransWidth, + const Word16 L_frame, + const Word16 tiltCompFactor, Word16 fac_ns, - Word16 *infoTCXNoise + Word16* infoTCXNoise, + const Word16 element_mode /* i : IVAS element mode */ ) { Word16 i, m, segmentOffset; @@ -1331,7 +1419,7 @@ void tcx_noise_filling( /* get inverse frame length */ tmp1 = getInvFrameLen(L_frame); - /* tilt_factor = (float)pow(max(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ + /* tilt_factor = (float)pow(max_val(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ tmp32 = BASOP_Util_Log2(L_deposit_h(s_max(0x3000, tiltCompFactor))); /* 6Q25 */ tmp32 = L_shr(Mpy_32_16_1(tmp32, tmp1), 6); BASOP_SATURATE_WARNING_OFF; @@ -1339,25 +1427,34 @@ void tcx_noise_filling( BASOP_SATURATE_WARNING_ON; /* find last nonzero line below iFirstLine, use it as start offset */ + i = iFirstLine; + move16(); tmp1 = shr(iFirstLine, 1); - FOR (i = iFirstLine; i > tmp1; i--) + IF (EQ_16(element_mode, IVAS_CPE_MDCT)) /* ... but only in mono or parametric stereo since it may cause binaural unmasking in discrete stereo */ { - IF (Q[i] != 0) - { - BREAK; - } + segmentOffset = i; + move16(); } - /* fac_ns *= (float)pow(tilt_factor, (float)i); */ - FOR (m = 0; m < i; m++) + ELSE { - fac_ns = mult_r(fac_ns, tilt_factor); + FOR(; i > tmp1; i--) + { + IF(Q[i] != 0) + { + BREAK; + } + } + /* fac_ns *= (float)pow(tilt_factor, (float)i); */ + FOR(m = 0; m < i; m++) + { + fac_ns = mult_r(fac_ns, tilt_factor); + } + i = add(i, 1); + segmentOffset = i; } - nrg = L_deposit_l(1); win = 0; move16(); - i = add(i, 1); - segmentOffset = i; move16(); FOR (; i < lowpassLine; i++) @@ -1442,43 +1539,71 @@ void tcx_noise_filling( /*--------------------------------------------------------------- - * Residual Quantization + * InitTnsConfigs() *--------------------------------------------------------------*/ -void InitTnsConfigs(Word32 nSampleRate, Word16 L_frame, - STnsConfig tnsConfig[2][2] - ,Word16 igfStopFreq - ,Word32 bitrate - ) +void InitTnsConfigs( + const Word16 bwidth, + const Word16 L_frame, + STnsConfig tnsConfig[2][2], + const Word16 igfStopFreq, + const Word32 total_brate, + const int16_t element_mode, + const int16_t MCT_flag +) { - IF (GT_32(bitrate,ACELP_32k)) + IF (GT_32(total_brate,ACELP_32k)) { - InitTnsConfiguration(nSampleRate, shr(L_frame,1), &tnsConfig[0][0], igfStopFreq, bitrate); + InitTnsConfiguration(bwidth, shr(L_frame,1), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag); } - InitTnsConfiguration(nSampleRate, L_frame, &tnsConfig[1][0], igfStopFreq, bitrate); - InitTnsConfiguration(nSampleRate, add(L_frame, shr(L_frame,2)), &tnsConfig[1][1], igfStopFreq, bitrate); + InitTnsConfiguration(bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag); + InitTnsConfiguration(bwidth, add(L_frame, shr(L_frame,2)), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag); } -void SetTnsConfig(TCX_config * tcx_cfg, Word8 isTCX20, Word8 isAfterACELP) +void SetTnsConfig( + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ + Word8 isTCX20, + Word8 isAfterACELP +) { move16(); - tcx_cfg->pCurrentTnsConfig = &tcx_cfg->tnsConfig[isTCX20][isAfterACELP]; - assert(tcx_cfg->pCurrentTnsConfig != NULL); + hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[isTCX20][isAfterACELP]; + assert(hTcxCfg->pCurrentTnsConfig != NULL); } +#ifdef IVAS_CODE_TCX_UTIL +/*-------------------------------------------------------------------* + * SetAllowTnsOnWhite + * + * set TNS config flag for possible application of TNS in the whitened domain + *-------------------------------------------------------------------*/ + +void SetAllowTnsOnWhite( + STnsConfig tnsConfig[2][2], /* o : updated TNS configurations */ + const int8_t allowTnsOnWhite /* i : flag for TNS in whiteded domain mode */ +) +{ + tnsConfig[0][0].allowTnsOnWhite = allowTnsOnWhite; + tnsConfig[0][1].allowTnsOnWhite = allowTnsOnWhite; + tnsConfig[1][0].allowTnsOnWhite = allowTnsOnWhite; + tnsConfig[1][1].allowTnsOnWhite = allowTnsOnWhite; - -void tcx_get_gain(Word32 *x, /* i: spectrum 1 */ - Word16 x_e, /* i: spectrum 1 exponent */ - Word32 *y, /* i: spectrum 2 */ - Word16 y_e, /* i: spectrum 2 exponent */ - Word16 n, /* i: length */ - Word16 *gain, /* o: gain */ - Word16 *gain_e, /* o: gain exponent */ - Word32 *en_y, /* o: energy of y (optional) */ - Word16 *en_y_e /* o: energy of y exponent (optional) */ - ) + return; +} +#endif + +void tcx_get_gain( + Word32 *x, /* i: spectrum 1 */ + Word16 x_e, /* i: spectrum 1 exponent */ + Word32 *y, /* i: spectrum 2 */ + Word16 y_e, /* i: spectrum 2 exponent */ + Word16 n, /* i: length */ + Word16 *gain, /* o: gain */ + Word16 *gain_e, /* o: gain exponent */ + Word32 *en_y, /* o: energy of y (optional) */ + Word16 *en_y_e /* o: energy of y exponent (optional) */ +) { Word32 maxX, minX, maxY, minY; Word32 corr, ener; @@ -1545,49 +1670,95 @@ void tcx_get_gain(Word32 *x, /* i: spectrum 1 */ } } +void init_TCX_config_dec( /* TEMPORARY */ + TCX_CONFIG_HANDLE hTcxCfg, + Word16 L_frame, + Word16 fscale + , Word16 L_frameTCX + , Word16 fscaleFB +) +{ + /* Initialize the TCX MDCT windows */ + hTcxCfg->tcx_mdct_window_length = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscale), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_delay = hTcxCfg->tcx_mdct_window_length; + move16(); + + hTcxCfg->tcx_mdct_window_half_length = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscale), LD_FSCALE_DENOM)); + + hTcxCfg->tcx_mdct_window_min_length = shr(L_frame, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_length = shr(L_frame, 4); /* 1.25ms */ + + hTcxCfg->tcx5Size = shr(L_frame, 2); /* 5ms */ + + hTcxCfg->tcx_mdct_window_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscaleFB), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_delayFB = hTcxCfg->tcx_mdct_window_lengthFB; + move16(); + + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscaleFB), LD_FSCALE_DENOM)); + + hTcxCfg->tcx_mdct_window_min_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ -void init_TCX_config(TCX_config *tcx_cfg, - Word16 L_frame, - Word16 fscale - ,Word16 L_frameTCX - ,Word16 fscaleFB - ) + hTcxCfg->tcx5SizeFB = shr(L_frameTCX, 2); /* 5ms */ + + mdct_window_sine(&hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_window_length); + mdct_window_sine(&hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_half_length); + mdct_window_sine(&hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length); + mdct_window_sine(&hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_trans_length); + + mdct_window_sine(&hTcxCfg->tcx_mdct_windowFB, hTcxCfg->tcx_mdct_window_lengthFB); + mdct_window_sine(&hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_half_lengthFB); + mdct_window_sine(&hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB); + mdct_window_sine(&hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_lengthFB); + + /*ALDO windows for MODE2*/ + mdct_window_aldo(hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame); + mdct_window_aldo(hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, L_frameTCX); +} + +void init_TCX_config( + TCX_CONFIG_HANDLE hTcxCfg, + Word16 L_frame, + Word16 fscale + ,Word16 L_frameTCX + ,Word16 fscaleFB +) { /* Initialize the TCX MDCT windows */ - tcx_cfg->tcx_mdct_window_length = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscale), LD_FSCALE_DENOM)); - tcx_cfg->tcx_mdct_window_delay = tcx_cfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_length = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscale), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_delay = hTcxCfg->tcx_mdct_window_length; move16(); - tcx_cfg->tcx_mdct_window_half_length = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscale), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_half_length = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscale), LD_FSCALE_DENOM)); - tcx_cfg->tcx_mdct_window_min_length = shr(L_frame, 4); /* 1.25ms */ - tcx_cfg->tcx_mdct_window_trans_length = shr(L_frame, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_length = shr(L_frame, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_length = shr(L_frame, 4); /* 1.25ms */ - tcx_cfg->tcx5Size = shr(L_frame, 2); /* 5ms */ + hTcxCfg->tcx5Size = shr(L_frame, 2); /* 5ms */ - tcx_cfg->tcx_mdct_window_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscaleFB), LD_FSCALE_DENOM)); - tcx_cfg->tcx_mdct_window_delayFB = tcx_cfg->tcx_mdct_window_lengthFB; + hTcxCfg->tcx_mdct_window_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscaleFB), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_delayFB = hTcxCfg->tcx_mdct_window_lengthFB; move16(); - tcx_cfg->tcx_mdct_window_half_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscaleFB), LD_FSCALE_DENOM)); + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscaleFB), LD_FSCALE_DENOM)); - tcx_cfg->tcx_mdct_window_min_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ - tcx_cfg->tcx_mdct_window_trans_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_trans_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ - tcx_cfg->tcx5SizeFB = shr(L_frameTCX, 2); /* 5ms */ + hTcxCfg->tcx5SizeFB = shr(L_frameTCX, 2); /* 5ms */ - mdct_window_sine( &tcx_cfg->tcx_mdct_window, tcx_cfg->tcx_mdct_window_length ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_half_length ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_min_length ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_trans_length ); + mdct_window_sine( &hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_window_length ); + mdct_window_sine( &hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_half_length ); + mdct_window_sine( &hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length ); + mdct_window_sine( &hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_trans_length ); - mdct_window_sine( &tcx_cfg->tcx_mdct_windowFB, tcx_cfg->tcx_mdct_window_lengthFB ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_half_lengthFB ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_min_lengthFB ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_trans_lengthFB ); + mdct_window_sine( &hTcxCfg->tcx_mdct_windowFB, hTcxCfg->tcx_mdct_window_lengthFB ); + mdct_window_sine( &hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_half_lengthFB ); + mdct_window_sine( &hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB ); + mdct_window_sine( &hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ); /*ALDO windows for MODE2*/ - mdct_window_aldo(tcx_cfg->tcx_aldo_window_1, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, L_frame); - mdct_window_aldo(tcx_cfg->tcx_aldo_window_1_FB, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, L_frameTCX); + mdct_window_aldo(hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame); + mdct_window_aldo(hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, L_frameTCX); } diff --git a/lib_com/tec_com.c b/lib_com/tec_com.c index 6611489..d61dbad 100644 --- a/lib_com/tec_com.c +++ b/lib_com/tec_com.c @@ -2,30 +2,30 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include -#include "stl.h" +#include +#include "options.h" #include "basop_util.h" #include "prot_fx.h" #include "cnst_fx.h" +/*------------------------------------------------------------------- + * Local constants + *-------------------------------------------------------------------*/ -#ifndef EPS -#define EPS ( 1e-12f) -#endif - +/*#define EPS ( 1e-12f)*/ #define ENV_SCALE_OFFSET_1_FX 1515133568l/*90.309f/128.0 Q31*/ /* 10*log10(2^30) */ /* scaled by 1/128.0 */ -#define MAX_TEC_BW_LO (12) -#define MAX_NB_TEC_LOW_BAND ( 3) - -static const Word16 TecSmoothingDeg = 5; -static const Word16 NbTecLowBand = 3; - -#define LOBUF_NO_SMOOTHING_MODE 1 - -void -resetTecDec_Fx( +#define MAX_TEC_BW_LO (12) +#define MAX_NB_TEC_LOW_BAND ( 3) +#define NBTECLOWBAND 3 +#define TECSMOOTHINGDEG 5 +#define LOBUF_NO_SMOOTHING_MODE 1 + +/*------------------------------------------------------------------- + * resetTecDec_Fx() + * + * + *-------------------------------------------------------------------*/ +void resetTecDec_Fx( HANDLE_TEC_DEC_FX hTecDec ) { @@ -38,9 +38,12 @@ resetTecDec_Fx( return; } - -void -resetTecEnc_Fx(HANDLE_TEC_ENC_FX hTecEnc, Word16 flag) +/*------------------------------------------------------------------- + * resetTecEnc_Fx() + * + * + *-------------------------------------------------------------------*/ +void resetTecEnc_Fx(TEC_ENC_HANDLE_FX hTecEnc, Word16 flag) { IF (flag == 0) { @@ -56,8 +59,17 @@ resetTecEnc_Fx(HANDLE_TEC_ENC_FX hTecEnc, Word16 flag) return; } +/*------------------------------------------------------------------- + * calcVar() + * + * + *-------------------------------------------------------------------*/ -static Word32 calcVar_Fix(const Word32 in[], Word32 len, Word32* x) +static Word32 calcVar_Fix( + const Word32 in[], + const Word32 len, + Word32* x +) { Word32 xx; Word32 i; @@ -101,11 +113,21 @@ static Word32 calcVar_Fix(const Word32 in[], Word32 len, Word32* x) } return ans; } - -static Word32 -calcCorrelationCoefficient2_Fix( - const Word32 in_vec1[], const Word32 in_vec2[], Word32 len, - Word32 var_x, Word32 var_y, Word32 x, Word32 y) +/*------------------------------------------------------------------- + * calcCorrelationCoefficient2() + * + * + *-------------------------------------------------------------------*/ + +static Word32 calcCorrelationCoefficient2_Fix( + const Word32 in_vec1[], + const Word32 in_vec2[], + const Word32 len, + Word32 var_x, + Word32 var_y, + Word32 x, + Word32 y +) { Word16 i; @@ -207,15 +229,19 @@ calcCorrelationCoefficient2_Fix( return ans; } - -static void -calcLoBufferEnc_Fx (Word32 **pCldfbPow_Fx, /* Q31 */ - Word16 scale, - Word16 startPos, - Word16 stopPos, - Word16 bandOffsetBottom, - Word16 *loBuffer /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ - ) +/*------------------------------------------------------------------- + * calcLoBufferEnc() + * + * + *-------------------------------------------------------------------*/ +static void calcLoBufferEnc_Fx ( + Word32 **pCldfbPow_Fx, /* Q31 */ + const Word16 scale, + const Word16 startPos, + const Word16 stopPos, + const Word16 bandOffsetBottom, + Word16 *loBuffer /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ +) { Word16 lb; Word16 li; @@ -231,7 +257,7 @@ calcLoBufferEnc_Fx (Word32 **pCldfbPow_Fx, /* Q31 */ /* scaling nrg : scale - 1 (sum up nrg) + 1 (inv_bw = 0.5) */ - FOR (lb=0; lb < NbTecLowBand; lb++) + FOR (lb=0; lb < NBTECLOWBAND; lb++) { li = TecLowBandTable[lb]; move16(); @@ -266,16 +292,21 @@ calcLoBufferEnc_Fx (Word32 **pCldfbPow_Fx, /* Q31 */ } } - -static void -calcHiTempEnv_Fx(Word32 **pCldfbPow, /* Q31 */ - Word16 scale, - Word16 startPos, - Word16 stopPos, - Word16 lowSubband, - Word16 highSubband, - Word16 *hiTempEnv /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ - ) +/*------------------------------------------------------------------- + * calcHiTempEnv() + * + * + *-------------------------------------------------------------------*/ + +static void calcHiTempEnv_Fx( + Word32 **pCldfbPow, /* Q31 */ + Word16 scale, + const Word16 startPos, + const Word16 stopPos, + const Word16 lowSubband, + const Word16 highSubband, + Word16 *hiTempEnv /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ +) { Word16 k; Word16 s1; @@ -325,16 +356,21 @@ calcHiTempEnv_Fx(Word32 **pCldfbPow, /* Q31 */ } } - -static void -calcLoBufferDec_Fx(Word32 **pCldfbReal, - Word32 **pCldfbImag, - Word16 *loBuffer, - Word16 startPos, - Word16 stopPos, - Word16 offset, - Word16 scale - ) +/*------------------------------------------------------------------- + * calcLoBufferDec() + * + * + *-------------------------------------------------------------------*/ + +static void calcLoBufferDec_Fx( + Word32 **pCldfbReal, + Word32 **pCldfbImag, + Word16 *loBuffer, + const Word16 startPos, + const Word16 stopPos, + const Word16 offset, + const Word16 scale +) { Word16 k; Word16 lb; @@ -350,7 +386,7 @@ calcLoBufferDec_Fx(Word32 **pCldfbReal, { tmp = L_deposit_l(0); - FOR (lb=0; lb < NbTecLowBand; lb++) + FOR (lb=0; lb < NBTECLOWBAND; lb++) { Word16 li; Word16 ui; @@ -412,13 +448,17 @@ calcLoBufferDec_Fx(Word32 **pCldfbReal, } } } - -static void -calcLoTempEnv_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - Word16 noCols, - Word16* loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - Word16 adjFac_Fx - ) +/*------------------------------------------------------------------- + * calcLoTempEnv_Fx() + * + * + *-------------------------------------------------------------------*/ +static void calcLoTempEnv_Fx( + Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, + Word16* loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ + const Word16 adjFac_Fx +) { Word16 i; Word16 slot; @@ -428,7 +468,7 @@ calcLoTempEnv_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ FOR (slot = 0; slot < noCols; slot++) { accu = L_mult0(TecSC_Fx[0], loBuffer_Fx[slot]); - FOR (i=1; i < TecSmoothingDeg + 1; i++) + FOR (i=1; i < TECSMOOTHINGDEG + 1; i++) { accu = L_mac0(accu,TecSC_Fx[i], loBuffer_Fx[sub(slot, i)]); } @@ -436,11 +476,16 @@ calcLoTempEnv_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ loTempEnv_Fx[slot] = extract_h(Mpy_32_16_1(accu,adjFac_Fx)); } } - -static void calcLoTempEnv_ns_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - Word16 noCols, - Word16* loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - ) + /*------------------------------------------------------------------- + * calcLoTempEnv_ns() + * + * + *-------------------------------------------------------------------*/ +static void calcLoTempEnv_ns_Fx( + Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, + Word16* loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ +) { Word16 slot; @@ -452,13 +497,17 @@ static void calcLoTempEnv_ns_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCA return; } - -static void -calcLoTempEnv_TBE_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - Word16 noCols, - Word16* loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - Word16 adjFac_Fx - ) +/*------------------------------------------------------------------- + * calcLoTempEnv_ns_TBE() + * + * + *-------------------------------------------------------------------*/ +static void calcLoTempEnv_TBE_Fx( + Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, + Word16* loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ + const Word16 adjFac_Fx +) { Word16 i; Word16 slot; @@ -469,7 +518,7 @@ calcLoTempEnv_TBE_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ FOR (slot = 0; slot < noCols; slot++) { accu = L_mult0(TecSC_Fx[0], loBuffer_Fx[slot - delay]); - FOR (i=1; i < TecSmoothingDeg + 1; i++) + FOR (i=1; i < TECSMOOTHINGDEG + 1; i++) { accu = L_mac0(accu,TecSC_Fx[i], loBuffer_Fx[slot-i-delay]); } @@ -477,11 +526,17 @@ calcLoTempEnv_TBE_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ loTempEnv_Fx[slot] = extract_h(Mpy_32_16_1(accu,adjFac_Fx)); } } - -static void calcLoTempEnv_ns_TBE_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - Word16 noCols, - Word16* loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - ) +/*------------------------------------------------------------------- + * calcLoTempEnv_ns_TBE() + * + * + *-------------------------------------------------------------------*/ + +static void calcLoTempEnv_ns_TBE_Fx( + Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, + Word16* loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ +) { Word16 slot; Word16 delay = 1; @@ -496,12 +551,18 @@ static void calcLoTempEnv_ns_TBE_Fx(Word16* loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA return; } - -static void calcGainLinear_TBE_Fx(const Word16* loTempEnv_m, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - const Word16 startPos, - const Word16 stopPos, - Word16* pGainTemp_m, /* Q0 */ - Word16* pGainTemp_e /* Q0 */) +/*------------------------------------------------------------------- + * calcGainLinear_TBE() + * + * + *-------------------------------------------------------------------*/ +static void calcGainLinear_TBE_Fx( + const Word16* loTempEnv_m, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ + const Word16 startPos, + const Word16 stopPos, + Word16* pGainTemp_m, /* Q0 */ + Word16* pGainTemp_e /* Q0 */ +) { Word16 slot; @@ -554,25 +615,28 @@ static void calcGainLinear_TBE_Fx(const Word16* loTempEnv_m, /* Q7 = Q(15 - (LD_ pGainTemp_e[slot] = sub(s,s2); } } - -void -calcGainTemp_TBE_Fx( +/*------------------------------------------------------------------- + * calcGainTemp_TBE() + * + * + *-------------------------------------------------------------------*/ +void calcGainTemp_TBE_Fx( Word32** pCldfbRealSrc_Fx, Word32** pCldfbImagSrc_Fx, Word16 cldfb_exp, Word16* loBuffer_Fx, - Word16 startPos, /*!< Start position of the current envelope. */ - Word16 stopPos, /*!< Stop position of the current envelope. */ - Word16 lowSubband, /* lowSubband */ + const Word16 startPos, /*!< Start position of the current envelope. */ + const Word16 stopPos, /*!< Stop position of the current envelope. */ + const Word16 lowSubband, /* lowSubband */ Word16* pGainTemp_m, - Word16* pGainTemp_e - , Word16 code + Word16* pGainTemp_e, + const Word16 code ) { Word16 loTempEnv_Fx[16]; - const Word16 BW_LO = TecLowBandTable[NbTecLowBand]; + const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; Word16 slot; Word16 noCols = stopPos - startPos; @@ -612,19 +676,34 @@ calcGainTemp_TBE_Fx( move16(); } } - -static void setSubfrConfig_Fix(Word16 i_offset, Word16* k_offset, Word16* n_subfr - , Word16 l_subfr - ) +/*------------------------------------------------------------------- + * setSubfrConfig() + * + * + *-------------------------------------------------------------------*/ + +static void setSubfrConfig_Fix( + const Word16 i_offset, + Word16* k_offset, + Word16* n_subfr, + const Word16 l_subfr +) { *n_subfr = sub((Word16)N_TEC_TFA_SUBFR,i_offset); *k_offset = i_mult(i_offset,l_subfr); } - -static Word16 calcSum_Fx(Word16* vec_m, /*Q0*/ - Word16* vec_e, /*Q0*/ - const Word16 len, - Word16* sum16_m /*Q0*/) +/*------------------------------------------------------------------- + * calcSum_Fx() + * + * + *-------------------------------------------------------------------*/ + +static Word16 calcSum_Fx( + Word16* vec_m, /*Q0*/ + Word16* vec_e, /*Q0*/ + const Word16 len, + Word16* sum16_m /*Q0*/ +) { Word16 slot; Word16 sum16_e; /* Q0 */ @@ -644,17 +723,21 @@ static Word16 calcSum_Fx(Word16* vec_m, /*Q0*/ return sum16_e; } - - -static Word16 calcSubfrNrg_Fx(Word16* hb_synth_Fx, - Word16 exp_syn, - const Word16 i_offset, - Word16* enr_m, - Word16* enr_e, - Word16 k_offset, - Word16* sum16_m - ,Word16 l_subfr - ) +/*------------------------------------------------------------------- + * calcSubfrNrg() + * + * + *-------------------------------------------------------------------*/ +static Word16 calcSubfrNrg_Fx( + Word16* hb_synth_Fx, + Word16 exp_syn, + const Word16 i_offset, + Word16* enr_m, + Word16* enr_e, + const Word16 k_offset, + Word16* sum16_m, + const Word16 l_subfr +) { Word16 i, j, k; Word16 s; @@ -723,16 +806,21 @@ static Word16 calcSubfrNrg_Fx(Word16* hb_synth_Fx, return sum16_e; } - -static Word16 procTec_Fx(Word16* hb_synth_Fx, - Word16 exp_syn, - Word16* gain_m, - Word16* gain_e, - - Word16 i_offset, - Word16 l_subfr - , Word16 code - ) +/*------------------------------------------------------------------- + * procTec() + * + * + *-------------------------------------------------------------------*/ + +static Word16 procTec_Fx( + Word16* hb_synth_Fx, + Word16 exp_syn, + Word16* gain_m, + Word16* gain_e, + const Word16 i_offset, + const Word16 l_subfr, + const Word16 code +) { Word16 i,j,k; Word16 k_offset, n_subfr; @@ -981,12 +1069,17 @@ static Word16 procTec_Fx(Word16* hb_synth_Fx, return exp_syn; } - -static Word16 procTfa_Fx(Word16* hb_synth_Fx, - Word16 exp_syn, - Word16 i_offset, - Word16 l_subfr - ) +/*------------------------------------------------------------------- + * procTfa_TBE() + * + * + *-------------------------------------------------------------------*/ +static Word16 procTfa_Fx( + Word16* hb_synth_Fx, + Word16 exp_syn, + const Word16 i_offset, + const Word16 l_subfr +) { Word16 i,j,k; Word16 k_offset, n_subfr; @@ -1108,17 +1201,21 @@ static Word16 procTfa_Fx(Word16* hb_synth_Fx, return exp_syn; } - - -Word16 procTecTfa_TBE_Fx(Word16 *hb_synth_Fx, - Word16 hb_synth_fx_exp, - Word16 *gain_m, - Word16 *gain_e, - Word16 flat_flag, - Word16 last_core - , Word16 l_subfr - , Word16 code - ) +/*------------------------------------------------------------------- + * procTecTfa_TBE() + * + * + *-------------------------------------------------------------------*/ +Word16 procTecTfa_TBE_Fx( + Word16 *hb_synth_Fx, + Word16 hb_synth_fx_exp, + Word16 *gain_m, + Word16 *gain_e, + const Word16 flat_flag, + const Word16 last_core, + const Word16 l_subfr, + const Word16 code +) { Word16 i_offset = 0; Word16 exp_syn_frame = sub(15, hb_synth_fx_exp); @@ -1158,18 +1255,23 @@ Word16 procTecTfa_TBE_Fx(Word16 *hb_synth_Fx, } -void -calcHiEnvLoBuff_Fix( - Word16 noCols, - Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16 nSfb, /*!< Number of scalefactors. */ - Word32** pCldfbPow_Fix /*float** pCldfbPow*/, - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, +/*------------------------------------------------------------------- + * calcHiEnvLoBuff() + * + * + *-------------------------------------------------------------------*/ + +void calcHiEnvLoBuff_Fix( + const Word16 noCols, + const Word16* pFreqBandTable, /*!< freqbandTable. */ + const Word16 nSfb, /*!< Number of scalefactors. */ + Word32** pCldfbPow_Fix /*float** pCldfbPow*/, + Word16* loBuffer_Fix /*float* loBuffer Q8*/, + Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, Word16 pCldfbPow_FixScale ) { - const Word16 BW_LO = TecLowBandTable[NbTecLowBand]; + const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; const Word16 lowSubband = pFreqBandTable[0]; const Word16 highSubband = pFreqBandTable[nSfb]; @@ -1202,18 +1304,22 @@ calcHiEnvLoBuff_Fix( /* ============================================================ */ } -void -calcLoEnvCheckCorrHiLo_Fix( - Word16 noCols, - Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* loTempEnv_Fix /*float* loTempEnv Q7*/, - Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16* corrFlag /*int* corrFlag*/ +/*------------------------------------------------------------------- + * calcLoEnvCheckCorrHiLo() + * + * + *-------------------------------------------------------------------*/ +void calcLoEnvCheckCorrHiLo_Fix( + const Word16 noCols, + const Word16* pFreqBandTable, /*!< freqbandTable. */ + Word16* loBuffer_Fix /*float* loBuffer Q8*/, + Word16* loTempEnv_Fix /*float* loTempEnv Q7*/, + Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, + Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, + Word16* corrFlag /*int* corrFlag*/ ) { - const Word16 BW_LO = TecLowBandTable[NbTecLowBand]; + const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; const Word16 lowSubband = pFreqBandTable[0]; Word16 i; @@ -1452,7 +1558,17 @@ calcLoEnvCheckCorrHiLo_Fix( } -void tecEnc_TBE_fx(Word16* corrFlag, const Word16* voicing, Word16 coder_type) +/*------------------------------------------------------------------- + * tecEnc_TBE() + * + * + *-------------------------------------------------------------------*/ + +void tecEnc_TBE_fx( + Word16* corrFlag, + const Word16* voicing, + const Word16 coder_type +) { Word16 voice_sum; Word16 voice_diff; @@ -1475,7 +1591,7 @@ void tecEnc_TBE_fx(Word16* corrFlag, const Word16* voicing, Word16 coder_type) test(); test(); /*if( ((voice_sum > 0.35 * 2 && voice_sum < 0.55 * 2) && (voice_diff < 0.2)) )*/ - if( EQ_16(coder_type,INACTIVE)||((GT_16(voice_sum,11469/*0.35 Q15*/)&<_16(voice_sum,18022/*0.55 Q15*/))&&(sub(voice_diff,6554/*0.2 Q15*/)<0))) + if( EQ_16(coder_type,INACTIVE) || (GT_16(voice_sum,11469/*0.35 Q15*/) && LT_16(voice_sum,18022/*0.55 Q15*/) && (sub(voice_diff,6554/*0.2 Q15*/)<0))) { *corrFlag = 0; move16(); @@ -1487,8 +1603,16 @@ void tecEnc_TBE_fx(Word16* corrFlag, const Word16* voicing, Word16 coder_type) move16(); } } - -void set_TEC_TFA_code_fx(const Word16 corrFlag, Word16* tec_flag, Word16* tfa_flag) +/*------------------------------------------------------------------- + * set_TEC_TFA_code() + * + * + *-------------------------------------------------------------------*/ +void set_TEC_TFA_code_fx( + const Word16 corrFlag, + Word16* tec_flag, + Word16* tfa_flag +) { *tec_flag = 0; move16(); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index a39813b..a60d207 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -3,16 +3,26 @@ ====================================================================================*/ -#include "stl.h" -#include "stat_com.h" -#include "stl.h" -#include #include +#include +#include +#include "options.h" +#include "stat_com.h" #include "rom_com_fx.h" #include "prot_fx.h" #include "basop_util.h" +/*---------------------------------------------------------------------------- + * Local constants + *---------------------------------------------------------------------------*/ + #define HLM_MIN_NRG 32768.0f +#define MAX_SUBDIVISIONS 3 + + +/*---------------------------------------------------------------------------- + * Local prototypes + *---------------------------------------------------------------------------*/ /** Linear prediction analysis/synthesis filter definition. * @param order filter order. @@ -34,7 +44,7 @@ static void Index2Parcor(Word16 const index[], Word16 parCoeff[], Word16 order); /** Linear prediction analysis filter. * See TLinearPredictionFilter for details. */ -static Word32 FIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x); +static Word32 FIRLattice(const Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x); /** Linear prediction synthesis filter. * See TLinearPredictionFilter for details. @@ -51,53 +61,52 @@ static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Wo * @param output filtered output spectrum values. Inplace operation is supported, so it can be equal to spectrum. */ -static void TnsFilter(Word32 const spectrum[], Word16 numOfLines, - Word16 const parCoeff[], Word16 order, - TLinearPredictionFilter filter, Word32 * state, - Word32 output[]); - -static void ITF_TnsFilter_fx( Word32 const spectrum[], - const Word16 numOfLines, - const Word16 A[], /* Q14 */ - const Word16 Q_A, - const Word16 order, - Word32 output[]); - -static void ITF_GetFilterParameters_fx(Word32 rxx[], - Word16 maxOrder, - Word16* A, /* Q14 */ - Word16* Q_A, - Word16* predictionGain); +static void TnsFilter(const Word32 spectrum[], const Word16 numOfLines, const Word16 parCoeff[], const Word16 order, TLinearPredictionFilter filter, Word32 * state, Word32 output[]); + +static void ITF_TnsFilter_fx( const Word32 spectrum[], const Word16 numOfLines, const Word16 A[], /* Q14 */ const Word16 Q_A, const Word16 order, Word32 output[]); + +static void ITF_GetFilterParameters_fx(Word32 rxx[], const Word16 maxOrder, Word16* A, /* Q14 */Word16* Q_A, Word16* predictionGain); /********************************/ /* Interface functions */ /********************************/ -#define MAX_SUBDIVISIONS 3 - -Word16 InitTnsConfiguration( - Word32 nSampleRate, - Word16 frameLength, +/** Init TNS configuration. + * Fills STnsConfig structure with sensible content. + * @param nSampleRate Sampling rate of the input. + * @param nFrameLength Frame length. + * @param pTnsConfig TNS configuration to be initialized. + * @return 0 on success, otherwise 1. + */ +void InitTnsConfiguration( + const Word16 bwidth, + const Word16 frameLength, STnsConfig * pTnsConfig, - Word16 igfStopFreq, - Word32 bitrate + const Word16 igfStopFreq, + const Word32 total_brate, + const int16_t element_mode, + const int16_t is_mct ) { Word16 iFilter = 0; Word16 * startLineFilter; Word32 L_tmp; + Word32 nSampleRate; Word16 s1; Word16 s2; - - - move16(); +#ifndef ADD_IVAS_TNS + MY_UNUSED_Word(element_mode); + MY_UNUSED_Word(is_mct); +#endif + nSampleRate = bwMode2fs[bwidth]; + move32(); startLineFilter = &pTnsConfig->iFilterBorders[1]; /* Sanity checks */ assert((nSampleRate > 0) && (frameLength > 0) && (pTnsConfig != NULL)); if ((nSampleRate <= 0) || (frameLength <= 0) || (pTnsConfig == NULL)) { - return TNS_FATAL_ERROR; + return /*TNS_FATAL_ERROR*/; } @@ -105,7 +114,7 @@ Word16 InitTnsConfiguration( move16(); pTnsConfig->maxOrder = TNS_MAX_FILTER_ORDER; - IF (LE_32(bitrate, ACELP_32k)) + IF (LE_32(total_brate, ACELP_32k)) { move16(); move16(); @@ -123,18 +132,36 @@ Word16 InitTnsConfiguration( pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } ELSE - IF ( GT_32(nSampleRate,16000)) + IF ( GT_32(nSampleRate,INT_FS_16k)) { - move16(); - pTnsConfig->nMaxFilters = sizeof(tnsParameters32kHz)/sizeof(tnsParameters32kHz[0]); +#ifdef ADD_IVAS_TNS + if ((element_mode > IVAS_SCE) && (total_brate >= (is_mct ? IVAS_32k : IVAS_48k))) + { + pTnsConfig->nMaxFilters = sizeof(tnsParameters32kHz_Stereo) / sizeof(tnsParameters32kHz_Stereo[0]); + if (nSampleRate == 100 * frameLength) /* sub-frame length is <= 10 ms */ + { + pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; + } + else + { + pTnsConfig->pTnsParameters = tnsParameters32kHz_Stereo; + } + } + else +#endif + { - move16(); - pTnsConfig->pTnsParameters = tnsParameters32kHz; + move16(); + pTnsConfig->nMaxFilters = sizeof(tnsParameters32kHz) / sizeof(tnsParameters32kHz[0]); - if ( EQ_32(nSampleRate, L_mult0(100, frameLength))) /* sub-frame length is <= 10 ms */ - { move16(); - pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; + pTnsConfig->pTnsParameters = tnsParameters32kHz; + + if (EQ_32(nSampleRate, L_mult0(100, frameLength))) /* sub-frame length is <= 10 ms */ + { + move16(); + pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; + } } } ELSE @@ -183,18 +210,24 @@ Word16 InitTnsConfiguration( move16(); pTnsConfig->iFilterBorders[0] = frameLength; } - - return TNS_NO_ERROR; +#ifdef ADD_IVAS_TNS + pTnsConfig->allowTnsOnWhite = 0; +#endif + return; /*TNS_NO_ERROR;*/ } +/*-------------------------------------------------------------------* + * ApplyTnsFilter() + * + *-------------------------------------------------------------------*/ -Word16 ApplyTnsFilter( +void ApplyTnsFilter( STnsConfig const * pTnsConfig, STnsData const * pTnsData, Word32 spectrum[], - Word8 fIsAnalysis) + const Word8 fIsAnalysis +) { - Word16 result; TLinearPredictionFilter filter; Word32 state[TNS_MAX_FILTER_ORDER]; Word16 iFilter; @@ -216,7 +249,7 @@ Word16 ApplyTnsFilter( FOR (iFilter = pTnsConfig->nMaxFilters-1; iFilter >= 0; iFilter--) { Word16 parCoeff[TNS_MAX_FILTER_ORDER]; - STnsFilter const * pFilter; + const STnsFilter * pFilter; move16(); @@ -236,47 +269,48 @@ Word16 ApplyTnsFilter( } move16(); - result = TNS_NO_ERROR; - if (pTnsData->nFilters < 0) - { - move16(); - result = TNS_FATAL_ERROR; - } - return result; + return /*result*/; } -TNS_ERROR ITF_Apply_fx(Word32 spectrum[], - Word16 startLine, - Word16 stopLine, - const Word16* A, - Word16 Q_A, - Word16 order - ) +/*-------------------------------------------------------------------* + * ITF_Apply() + * + *-------------------------------------------------------------------*/ + +void ITF_Apply_fx( + Word32 spectrum[], + Word16 startLine, + Word16 stopLine, + const Word16* A, + Word16 Q_A, + Word16 order +) { - ITF_TnsFilter_fx(&spectrum[startLine], - (Word16)(stopLine-startLine), - A, - Q_A, - (Word16)order, - &spectrum[startLine]); + ITF_TnsFilter_fx(&spectrum[startLine],(Word16)(stopLine-startLine), A, Q_A, (Word16)order, &spectrum[startLine]); - return TNS_NO_ERROR; + return /*TNS_NO_ERROR*/; } - -Word16 ITF_Detect_fx(Word32 const pSpectrum[], - Word16 startLine, - Word16 stopLine, - Word16 maxOrder, - Word16* A, - Word16* Q_A, - Word16* predictionGain, - Word16* curr_order, - Word16 Q ) +/*-------------------------------------------------------------------* +* ITF_Detect() +* +* +*-------------------------------------------------------------------*/ + +Word16 ITF_Detect_fx( + const Word32 pSpectrum[], + const Word16 startLine, + const Word16 stopLine, + const Word16 maxOrder, + Word16* A, + Word16* Q_A, + Word16* predictionGain, + Word16* curr_order, + Word16 Q +) { - Word16 const idx0 = startLine; - Word16 const idx1 = stopLine; + Word16 spectrumLength; Word16 const nSubdivisions = MAX_SUBDIVISIONS; Word16 iSubdivisions; @@ -306,15 +340,15 @@ Word16 ITF_Detect_fx(Word32 const pSpectrum[], { assert((nSubdivisions == 1) || (nSubdivisions == 3)); - tmp = sub(idx1, idx0); + tmp = sub(stopLine, startLine); iStartLine = imult1616(tmp, iSubdivisions); iEndLine = add(iStartLine, tmp); if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, idx0); + iStartLine = add(iStartLine, startLine); if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, idx0); + iEndLine = add(iEndLine, startLine); headroom = getScaleFactor32(pSpectrum+iStartLine-IGF_START_MN, sub(iEndLine, iStartLine)); /* Calculate norm of spectrum band */ L_tmp = Norm32Norm(pSpectrum+iStartLine-IGF_START_MN, headroom, sub(iEndLine, iStartLine), &shift); @@ -358,72 +392,68 @@ Word16 ITF_Detect_fx(Word32 const pSpectrum[], } /* Calculate normalized autocorrelation for spectrum subdivision and get filter parameters based on it */ -#define RXX_E (3) - { - set32_fx(rxx, 0, ITF_MAX_FILTER_ORDER+1); + set32_fx(rxx, 0, ITF_MAX_FILTER_ORDER+1); - spectrumLength = sub(idx1, idx0); + spectrumLength = sub(stopLine, startLine); - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + { + IF ( facs[iSubdivisions] == 0 ) { - IF ( facs[iSubdivisions] == 0 ) - { - BREAK; - } + BREAK; + } - assert((nSubdivisions == 1) || (nSubdivisions == 3)); + assert((nSubdivisions == 1) || (nSubdivisions == 3)); - iStartLine = imult1616(spectrumLength, iSubdivisions); - iEndLine = add(iStartLine, spectrumLength); + iStartLine = imult1616(spectrumLength, iSubdivisions); + iEndLine = add(iStartLine, spectrumLength); - if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); - iStartLine = add(iStartLine, idx0); + if (EQ_16(nSubdivisions, 3))iStartLine=mult(iStartLine,0x2AAB); + iStartLine = add(iStartLine, startLine); - if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); - iEndLine = add(iEndLine, idx0); + if (EQ_16(nSubdivisions, 3))iEndLine=mult(iEndLine,0x2AAB); + iEndLine = add(iEndLine, startLine); - move16(); - shift = shifts[iSubdivisions]; + move16(); + shift = shifts[iSubdivisions]; - n = sub(iEndLine, iStartLine); - assert(n < (Word16)(sizeof(tmpbuf)/sizeof(Word16))); - FOR (i = 0; i < n; i++) - { - tmpbuf[i] = round_fx(L_shl(pSpectrum[iStartLine+i-IGF_START_MN], shift)); - } + n = sub(iEndLine, iStartLine); + assert(n < (Word16)(sizeof(tmpbuf)/sizeof(Word16))); + FOR (i = 0; i < n; i++) + { + tmpbuf[i] = round_fx(L_shl(pSpectrum[iStartLine+i-IGF_START_MN], shift)); + } - FOR (lag = 0; lag <= maxOrder; lag++) - { - n = sub(sub(iEndLine,lag), iStartLine); + FOR (lag = 0; lag <= maxOrder; lag++) + { + n = sub(sub(iEndLine,lag), iStartLine); + { + Word64 tmp64 = 0; + FOR (i = 0; i < n; i++) { - Word64 tmp64 = 0; - FOR (i = 0; i < n; i++) - { - tmp64 = W_mac0_16_16(tmp64, tmpbuf[i], tmpbuf[i+lag]); - } - L_tmp = W_sat_l(tmp64); + tmp64 = W_mac0_16_16(tmp64, tmpbuf[i], tmpbuf[i+lag]); } - - L_tmp = Mpy_32_16_1(L_tmp, facs[iSubdivisions]); - L_tmp = L_shl(L_tmp, facs_e[iSubdivisions]); - - rxx[lag] = L_add(rxx[lag], L_tmp); - move32(); + L_tmp = W_sat_l(tmp64); } + L_tmp = Mpy_32_16_1(L_tmp, facs[iSubdivisions]); + L_tmp = L_shl(L_tmp, facs_e[iSubdivisions]); + + rxx[lag] = L_add(rxx[lag], L_tmp); + move32(); } - IF ( EQ_16(iSubdivisions,nSubdivisions)) /* meaning there is no subdivision with low energy */ - { - /* Limit the maximum order to spectrum length/4 */ - ITF_GetFilterParameters_fx(rxx, s_min (maxOrder, shr(spectrumLength,2)), A, Q_A, predictionGain); + } - *curr_order = maxOrder; - } + IF ( EQ_16(iSubdivisions,nSubdivisions)) /* meaning there is no subdivision with low energy */ + { + /* Limit the maximum order to spectrum length/4 */ + ITF_GetFilterParameters_fx(rxx, s_min (maxOrder, shr(spectrumLength,2)), A, Q_A, predictionGain); + *curr_order = maxOrder; } return 1; @@ -513,76 +543,76 @@ static Word16 DecodeUsingTable(Decoder_State_fx *st, Word16 * pValue, const Codi /* TNS filter coefficients */ -void const * GetTnsFilterCoeff(void const * p, Word16 index, Word16 * pValue) +void const * GetTnsFilterCoeff(void const * p, const Word16 index, Word16 * pValue) { *pValue = ((Word16 const *)p)[index] + INDEX_SHIFT; return NULL; } -void * SetTnsFilterCoeff(void * p, Word16 index, Word16 value) +void * SetTnsFilterCoeff(void * p, const Word16 index, const Word16 value) { ((Word16 *)p)[index] = sub(value, INDEX_SHIFT); return NULL; } -Word16 GetSWBTCX20TnsFilterCoeffBits(Word16 value, Word16 index) +Word16 GetSWBTCX20TnsFilterCoeffBits(const Word16 value, const Word16 index) { assert((index >= 0) && (index < nTnsCoeffTables)); return GetBitsFromTable(value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); } -Word16 EncodeSWBTCX20TnsFilterCoeff(Word16 value, Word16 index) +Word16 EncodeSWBTCX20TnsFilterCoeff(const Word16 value, const Word16 index) { assert((index >= 0) && (index < nTnsCoeffTables)); return EncodeUsingTable(value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); } -Word16 DecodeSWBTCX20TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue) +Word16 DecodeSWBTCX20TnsFilterCoeff(Decoder_State_fx *st, const Word16 index, Word16 * pValue) { assert((index >= 0) && (index < nTnsCoeffTables)); return DecodeUsingTable(st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); } -Word16 GetSWBTCX10TnsFilterCoeffBits(Word16 value, Word16 index) +Word16 GetSWBTCX10TnsFilterCoeffBits(const Word16 value, const Word16 index) { assert((index >= 0) && (index < nTnsCoeffTables)); return GetBitsFromTable(value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); } -Word16 EncodeSWBTCX10TnsFilterCoeff(Word16 value, Word16 index) +Word16 EncodeSWBTCX10TnsFilterCoeff(const Word16 value, const Word16 index) { assert((index >= 0) && (index < nTnsCoeffTables)); return EncodeUsingTable(value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); } -Word16 DecodeSWBTCX10TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue) +Word16 DecodeSWBTCX10TnsFilterCoeff(Decoder_State_fx *st, const Word16 index, Word16 * pValue) { assert((index >= 0) && (index < nTnsCoeffTables)); return DecodeUsingTable(st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); } -Word16 GetWBTCX20TnsFilterCoeffBits(Word16 value, Word16 index) +Word16 GetWBTCX20TnsFilterCoeffBits(const Word16 value, const Word16 index) { assert((index >= 0) && (index < nTnsCoeffTables)); return GetBitsFromTable(value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); } -Word16 EncodeWBTCX20TnsFilterCoeff(Word16 value, Word16 index) +Word16 EncodeWBTCX20TnsFilterCoeff(const Word16 value, const Word16 index) { assert((index >= 0) && (index < nTnsCoeffTables)); return EncodeUsingTable(value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); } -Word16 DecodeWBTCX20TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue) +Word16 DecodeWBTCX20TnsFilterCoeff(Decoder_State_fx *st, const Word16 index, Word16 * pValue) { assert((index >= 0) && (index < nTnsCoeffTables)); @@ -593,7 +623,7 @@ Word16 DecodeWBTCX20TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * /* TNS filter order */ -void const * GetTnsFilterOrder(void const * p, Word16 index, Word16 * pValue) +void const * GetTnsFilterOrder(void const * p, const Word16 index, Word16 * pValue) { move16(); *pValue = ((STnsFilter const *)p)[index].order; @@ -602,7 +632,7 @@ void const * GetTnsFilterOrder(void const * p, Word16 index, Word16 * pValue) return ((STnsFilter const *)p)[index].coefIndex; } -void * SetTnsFilterOrder(void * p, Word16 index, Word16 value) +void * SetTnsFilterOrder(void * p, const Word16 index, const Word16 value) { move16(); ((STnsFilter *)p)[index].order = value; @@ -611,63 +641,63 @@ void * SetTnsFilterOrder(void * p, Word16 index, Word16 value) return ((STnsFilter *)p)[index].coefIndex; } -Word16 GetTnsFilterOrderBitsSWBTCX20(Word16 value, Word16 index) +Word16 GetTnsFilterOrderBitsSWBTCX20(const Word16 value, const Word16 index) { (void)index; return GetBitsFromTable(value-1, codesTnsOrderTCX20, nTnsOrderCodes); } -Word16 EncodeTnsFilterOrderSWBTCX20(Word16 value, Word16 index) +Word16 EncodeTnsFilterOrderSWBTCX20(const Word16 value, const Word16 index) { (void)index; return EncodeUsingTable(value-1, codesTnsOrderTCX20, nTnsOrderCodes); } -Word16 DecodeTnsFilterOrderSWBTCX20(Decoder_State_fx *st, Word16 index, Word16 * pValue) +Word16 DecodeTnsFilterOrderSWBTCX20(Decoder_State_fx *st, const Word16 index, Word16 * pValue) { (void)index; return DecodeUsingTable(st, pValue, codesTnsOrderTCX20, nTnsOrderCodes); } -Word16 GetTnsFilterOrderBitsSWBTCX10(Word16 value, Word16 index) +Word16 GetTnsFilterOrderBitsSWBTCX10(const Word16 value, const Word16 index) { (void)index; return GetBitsFromTable(value-1, codesTnsOrderTCX10, nTnsOrderCodes); } -Word16 EncodeTnsFilterOrderSWBTCX10(Word16 value, Word16 index) +Word16 EncodeTnsFilterOrderSWBTCX10(const Word16 value, const Word16 index) { (void)index; return EncodeUsingTable(value-1, codesTnsOrderTCX10, nTnsOrderCodes); } -Word16 DecodeTnsFilterOrderSWBTCX10(Decoder_State_fx *st, Word16 index, Word16 * pValue) +Word16 DecodeTnsFilterOrderSWBTCX10(Decoder_State_fx *st, const Word16 index, Word16 * pValue) { (void)index; return DecodeUsingTable(st, pValue, codesTnsOrderTCX10, nTnsOrderCodes); } -Word16 GetTnsFilterOrderBits(Word16 value, Word16 index) +Word16 GetTnsFilterOrderBits(const Word16 value, const Word16 index) { (void)index; return GetBitsFromTable(value-1, codesTnsOrder, nTnsOrderCodes); } -Word16 EncodeTnsFilterOrder(Word16 value, Word16 index) +Word16 EncodeTnsFilterOrder(const Word16 value, const Word16 index) { (void)index; return EncodeUsingTable(value-1, codesTnsOrder, nTnsOrderCodes); } -Word16 DecodeTnsFilterOrder(Decoder_State_fx *st, Word16 index, Word16 * pValue) +Word16 DecodeTnsFilterOrder(Decoder_State_fx *st, const Word16 index, Word16 * pValue) { (void)index; @@ -676,14 +706,14 @@ Word16 DecodeTnsFilterOrder(Decoder_State_fx *st, Word16 index, Word16 * pValue) /* Number of TNS filters */ -void const * GetNumOfTnsFilters(void const * p, Word16 index, Word16 * pValue) +void const * GetNumOfTnsFilters(void const * p, const Word16 index, Word16 * pValue) { *pValue = ((STnsData const *)p)[index].nFilters; return ((STnsData const *)p)[index].filter; } -void * SetNumOfTnsFilters(void * p, Word16 index, Word16 value) +void * SetNumOfTnsFilters(void * p, const Word16 index, Word16 value) { ((STnsData *)p)[index].nFilters = value; @@ -692,11 +722,11 @@ void * SetNumOfTnsFilters(void * p, Word16 index, Word16 value) /* TNS enabled/disabled flag */ -void const * GetTnsEnabled(void const * p, Word16 index, Word16 * pValue) +void const * GetTnsEnabled(void const * p, const Word16 index, Word16 * pValue) { move16(); *pValue = 0; - if (((STnsData const *)p)[index].nFilters > 0) + if (((STnsData const *)p)[index].nFilters != 0) { move16(); *pValue = 1; @@ -704,13 +734,34 @@ void const * GetTnsEnabled(void const * p, Word16 index, Word16 * pValue) return NULL; } -void * SetTnsEnabled(void * p, Word16 index, Word16 value) +void * SetTnsEnabled(void * p, const Word16 index, const Word16 value) { (void)p,(void)index,(void)value; return NULL; } +#ifdef ADD_IVAS_TNS +/* TNS on whitened spectra flag */ -void const * GetTnsEnabledSingleFilter(void const * p, Word16 index, Word16 * pValue) +void const* GetTnsOnWhite(void const* p, const int16_t index, int16_t* pValue) +{ + *pValue = ((STnsData const*)p)[index].tnsOnWhitenedSpectra > 0 ? 1 : 0; + return NULL; +} + +void* SetTnsOnWhite(void* p, const int16_t index, const int16_t value) +{ + ((STnsData*)p)[index].tnsOnWhitenedSpectra = value; + return NULL; +} + +void const* GetTnsEnabledSingleFilter(void const* p, const int16_t index, int16_t* pValue) +{ + *pValue = ((STnsData const*)p)[index].nFilters != 0 ? 1 : 0; + return ((STnsData const*)p)[index].filter; +} +#endif + +void const * GetTnsEnabledSingleFilter(void const * p, const Word16 index, Word16 * pValue) { move16(); *pValue = 0; @@ -722,15 +773,16 @@ void const * GetTnsEnabledSingleFilter(void const * p, Word16 index, Word16 * pV return ((STnsData const *)p)[index].filter; } -void * SetTnsEnabledSingleFilter(void * p, Word16 index, Word16 value) +void * SetTnsEnabledSingleFilter(void * p, const Word16 index, const Word16 value) { ((STnsData *)p)[index].nFilters = value; return ((STnsData *)p)[index].filter; } -/********************************/ -/* Private functions */ -/********************************/ +/*-------------------------------------------------------------------* + * ResetTnsData() + * + *-------------------------------------------------------------------*/ void ResetTnsData(STnsData * pTnsData) { @@ -738,31 +790,36 @@ void ResetTnsData(STnsData * pTnsData) pTnsData->nFilters = 0; - +#ifdef ADD_IVAS_TNS + pTnsData->tnsOnWhitenedSpectra = 0; +#endif FOR (iFilter = 0; iFilter < (Word16) (sizeof(pTnsData->filter)/sizeof(pTnsData->filter[0])); iFilter++) { STnsFilter * const pTnsFilter = &pTnsData->filter[iFilter]; pTnsFilter->spectrumLength = 0; pTnsFilter->predictionGain = 128/*1.0f Q7*/; pTnsFilter->avgSqrCoef = 0; +#ifdef ADD_IVAS_TNS + pTnsFilter->filterType = TNS_FILTER_OFF; +#endif ClearTnsFilterCoefficients(pTnsFilter); } } +/*-------------------------------------------------------------------* + * ClearTnsFilterCoefficients() + * + *-------------------------------------------------------------------*/ -void ClearTnsFilterCoefficients(STnsFilter * pTnsFilter) +void ClearTnsFilterCoefficients( + STnsFilter * pTnsFilter +) { move16(); pTnsFilter->order = 0; assert(TNS_MAX_FILTER_ORDER == 8); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + move16();move16();move16();move16(); + move16();move16();move16();move16(); pTnsFilter->coefIndex[0] = 0; pTnsFilter->coefIndex[1] = 0; pTnsFilter->coefIndex[2] = 0; @@ -773,9 +830,15 @@ void ClearTnsFilterCoefficients(STnsFilter * pTnsFilter) pTnsFilter->coefIndex[7] = 0; } +/** Inverse quantization for reflection coefficients. + * + * @param index input quantized values. + * @param parCoeff output reflection coefficients. + * @param order number of coefficients/values. + */ static void Index2Parcor(const Word16 index[], Word16 parCoeff[], Word16 order) { - Word16 const * values; + const Word16 * values; Word16 i; move16(); @@ -786,12 +849,17 @@ static void Index2Parcor(const Word16 index[], Word16 parCoeff[], Word16 order) move16(); parCoeff[i] = values[add(index[i], INDEX_SHIFT)]; } - + return; } - -static Word32 FIRLattice(Word16 order, const Word16 *parCoeff /*Q15*/, Word32 *state, Word32 x /* Q0 */) +/* Linear prediction analysis filter. */ +static Word32 FIRLattice( + const Word16 order, + const Word16 *parCoeff /*Q15*/, + Word32 *state, + Word32 x /* Q0 */ +) { Word16 i; Word32 tmpSave, tmp; @@ -836,11 +904,25 @@ static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Wo state[0] = x; return x; } - -static void TnsFilter(Word32 const spectrum[], Word16 numOfLines, - Word16 const parCoeff[], Word16 order, - TLinearPredictionFilter filter, Word32 * state, - Word32 output[]) +/** TNS analysis/synthesis filter. + * @param spectrum input spectrum values. + * @param numOfLines number of lines in the spectrum. + * @param parCoeff filter (PARCOR) coefficients. + * @param order filter order. + * @param filter function that implements filtering. + By this function it is defined whether analysis or synthesis is performed. + * @param output filtered output spectrum values. + Inplace operation is supported, so it can be equal to spectrum. + */ +static void TnsFilter( + const Word32 spectrum[], + const Word16 numOfLines, + const Word16 parCoeff[], + const Word16 order, + TLinearPredictionFilter filter, + Word32 * state, + Word32 output[] +) { Word16 j; @@ -868,14 +950,17 @@ static void TnsFilter(Word32 const spectrum[], Word16 numOfLines, } } } + return; } -static void ITF_TnsFilter_fx( Word32 const spectrum[], - const Word16 numOfLines, - const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ - const Word16 Q_A, - const Word16 order, - Word32 output[]) +static void ITF_TnsFilter_fx( + const Word32 spectrum[], + const Word16 numOfLines, + const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ + const Word16 Q_A, + const Word16 order, + Word32 output[] +) { Word16 i, j; Word32 buf[ITF_MAX_FILTER_ORDER + N_MAX]; @@ -914,14 +999,16 @@ static void ITF_TnsFilter_fx( Word32 const spectrum[], ++p; } } - + return; } -static void ITF_GetFilterParameters_fx(Word32 rxx[], - Word16 maxOrder, - Word16* A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ - Word16* Q_A, - Word16* predictionGain) +static void ITF_GetFilterParameters_fx( + Word32 rxx[], + const Word16 maxOrder, + Word16* A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ + Word16* Q_A, + Word16* predictionGain +) { Word16 i, j, i_2, tmp; Word16 parCoeff[ITF_MAX_FILTER_ORDER]; @@ -976,5 +1063,6 @@ static void ITF_GetFilterParameters_fx(Word32 rxx[], } *Q_A = add(11, tmp); } + return; } diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index ff2ab2e..7765331 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -659,7 +659,7 @@ Word16 minimum_32_fx( /* o : index of the minimum value in the input vecto Word16 maximum_32_fx( /* o : index of the maximum value in the input vector */ const Word32 *vec, /* i : input vector */ const Word16 lvec, /* i : length of input vector */ - Word32 *max /* o : maximum value in the input vector */ + Word32 *max_val /* o : maximum value in the input vector */ ) { Word16 j, ind; @@ -678,7 +678,7 @@ Word16 maximum_32_fx( /* o : index of the maximum value in the input ve } tmp = L_max(tmp,vec[j]); } - *max = tmp; + *max_val = tmp; move32(); return ind; @@ -1783,6 +1783,51 @@ void Copy_Scale_sig32_16( } } +/*-------------------------------------------------------------------* + * v_multc_att() + * + * Attenuation of a vector,, attenuation factor in Q15 + *-------------------------------------------------------------------*/ + +void v_multc_att( + const Word16 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word16 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ +) +{ + Word16 i; + IF(LT_16(att, 32767)) + { + FOR(i = 0; i < N; i++) + { + y[i] = mult_r(x[i], att); + move16(); + } + } +}/*-------------------------------------------------------------------* + * v_multc_att32() + * + * Attenuation of a vector,, attenuation factor in Q15 + *-------------------------------------------------------------------*/ + +void v_multc_att32( + const Word32 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word32 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ +) +{ + Word16 i; + IF(LT_16(att, 32767)) + { + FOR(i = 0; i < N; i++) + { + y[i] = Mpy_32_16_r(x[i], att); + move32(); + } + } +} /*-------------------------------------------------------------------* * add_vec() * @@ -2325,17 +2370,19 @@ Word16 erb_diff_search_fx(Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_ } void Acelp_dec_total_exc( - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - const Word16 gain_code16, /* i : Gain code Q0 */ - const Word16 gain_pit_fx, /* i ; Pitch gain in Q14 */ - const Word16 i_subfr, /* i ; subfr */ - const Word16 *code_fx /* i : code in Q9 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + const Word16 gain_code16, /* i : Gain code Q0 */ + const Word16 gain_pit_fx, /* i ; Pitch gain in Q14 */ + const Word16 i_subfr, /* i ; subfr */ + const Word16 *code_fx, /* i : code in Q9 */ + const Word16 L_subfr /* i : Subframne lenght */ ) { Word16 i; Word32 L_tmp; - FOR (i = 0; i < L_SUBFR; i++) + + FOR (i = 0; i < L_subfr; i++) { L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i+i_subfr]), 1); /*Q16+Q_exc*/ exc2_fx[i+i_subfr] = round_fx(L_tmp); /*Q_exc*/ @@ -2627,4 +2674,25 @@ void floating_point_add( *ex = sub(add(*ex, expo), 1); /* Subtract 1 due to 1-bit down-shift above ensuring 1 bit headroom before addition. */ return; } +/*-------------------------------------------------------------------* + * delay_signal() + * + * Delay buffer by defined number of samples + *-------------------------------------------------------------------*/ + +void delay_signal( + Word16 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word16 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ +) +{ + Word16 tmp_buffer[L_FRAME48k]; + + Copy(mem, tmp_buffer, delay); + Copy(x + len - delay, mem, delay); + Copy(x, x + delay, len - delay); + Copy(tmp_buffer, x, delay); + return; +} diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index 88d9495..aeb63e5 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -1,21 +1,24 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "cnst_fx.h" /* Common FX constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Function prototypes */ - - -void direct_transform_fx( - const Word32 in32_fx[], - Word32 out32_fx[], - const Word16 is_transient, - const Word16 L, - Word16 *Q +/*------------------------------------------------------------------- + * direct_transform() + * + * Transformation of the signal to DCT domain + *-------------------------------------------------------------------*/ + void direct_transform_fx( + const Word32 in32_fx[], /* i : input signal */ + Word32 out32_fx[], /* o : transformation */ + const Word16 is_transient, /* i : is transient */ + const Word16 L, /* i : length */ + Word16 *Q, + const Word16 element_mode /* i : IVAS element mode */ ) { @@ -37,7 +40,9 @@ void direct_transform_fx( Word16 shift, Qmin = 31; Word32 L_tmp; Word16 Qs[NUM_TIME_SWITCHING_BLOCKS]; - +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(element_mode); +#endif segment_length = shr(L, 1); segment_length2 = shr(segment_length, 1); diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index 05aecbe..c3adcf3 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -1,9 +1,8 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Function prototypes */ #include "rom_dec_fx.h" @@ -28,12 +27,12 @@ *--------------------------------------------------------------------------*/ void preecho_sb_fx( - const Word32 brate, /* i Q0 : core bit-rate */ + const Word32 core_brate, /* i Q0 : core bit-rate */ Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal, used to compute imdct_mem_fx when not 24400 bps */ Word16 q_sig32, /* i Q value for wtda_audio_fx */ Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */ Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */ - const Word16 framelength, /* i Q0 : frame length */ + const Word16 framelength, /* i Q0 : frame length */ Word16 *memfilt_lb_fx, /* i/o Q0 : memory */ Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */ Word16 *smoothmem_fx, /* i/o Q15 : memory */ @@ -42,7 +41,7 @@ void preecho_sb_fx( Word16 *wmold_hb_fx, /* i/o Q15 : memory */ Word16 *prevflag, /* i/o Q0 : flag */ Word16 *pastpre, /* i/o Q0 : flag */ - const Word16 bwidth /* i Q0 : bandwidth */ + const Word16 bwidth /* i Q0 : bandwidth */ ) { Word16 i, j, len3xLp20; @@ -72,12 +71,12 @@ void preecho_sb_fx( Word32 savehalfe_hb_fx, last2_hb_fx; Word32 plus_es_mdct_fx[64], max_es_fx, max_es_hb_fx, max_plus_es_mdct_fx; Word16 imdct_mem_fx[L_FRAME48k]; /* memory of the imdct transform, used in the next frame */ - Word16 rec_sig_lb_fx[960], rec_sig_hb_fx[960]; /* 960 max frame length at 48 kHz */ + Word16 rec_sig_lb_fx[L_FRAME48k], rec_sig_hb_fx[L_FRAME48k]; /* 960 max frame length at 48 kHz */ Word16 min_g_fx[13], g_fx, gt_fx[13]; Word16 min_g_hb_fx[13], gt_hb_fx[13]; - Word16 preechogain_fx[960+PREECHO_SMOOTH_LEN]; - Word16 preechogain_hb_fx[960]; + Word16 preechogain_fx[L_FRAME48k +PREECHO_SMOOTH_LEN]; + Word16 preechogain_hb_fx[L_FRAME48k]; Word16 pre_g_ch_tab[9]; Word32 eshbmean2_fx, eshbmean3_fx, sxyhb2_fx, sxylb3_fx; Word16 wmold_fx; @@ -91,7 +90,7 @@ void preecho_sb_fx( q16p1 = add(q_sig16, 1); qmemp1 = q16p1; - IF(LE_32(brate, HQ_32k)) + IF(LE_32(core_brate, HQ_32k)) { mean_prev_fx_loc = L_add(*mean_prev_fx, 0); @@ -950,12 +949,13 @@ void preecho_sb_fx( *--------------------------------------------------------------------------*/ void Inverse_Transform( - const Word32 *in_mdct, /* i : input MDCT vector */ - Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 is_transient, /* i : transient flag */ - const Word16 L, /* i : output frame length */ - const Word16 L_inner /* i : length of the transform */ + const Word32 *in_mdct, /* i : input MDCT vector */ + Word16 *Q, /* i/o: Q value of input */ + Word32 *out, /* o : output vector */ + const Word16 is_transient, /* i : transient flag */ + const Word16 L, /* i : output frame length */ + const Word16 L_inner, /* i : length of the transform */ + const Word16 element_mode /* i : IVAS element mode */ ) { Word16 ta, seg, tmp16; @@ -970,6 +970,9 @@ void Inverse_Transform( Word16 segment_length_div2, segment_length_div4; Word16 tmp, q_out; Word32 L_temp; +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(element_mode); +#endif /* This value is used to right shift all vectors returned by 'iedct_short_fx()' */ /* to bring them to a scaling that is equal to the 1st 'Q' returned by the 1st */ /* call to 'iedct_short_fx()' minus these guard bits. */ diff --git a/lib_com/vlpc_2st_com.c b/lib_com/vlpc_2st_com.c index ac54149..90fbe70 100644 --- a/lib_com/vlpc_2st_com.c +++ b/lib_com/vlpc_2st_com.c @@ -2,19 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include +#include "options.h" #include "cnst_fx.h" #include "prot_fx.h" -#include "stl.h" #include "control.h" #include "basop_util.h" void lsf_weight_2st( const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ - Word16 *w, /* output: weighting function (0Q15*1.28) */ + Word16 *w, /* output: weighting function (0Q15*1.28) */ const Word16 mode /* input: operational mode */ ) { diff --git a/lib_com/weight_a_fx.c b/lib_com/weight_a_fx.c index 49622fc..b13e0f4 100644 --- a/lib_com/weight_a_fx.c +++ b/lib_com/weight_a_fx.c @@ -1,12 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Function prototypes */ -#include "prot_fx.h" /* Function prototypes */ #include /*------------------------------------------------------------------ @@ -55,7 +53,7 @@ void weight_a_subfr_fx( /*==============================================================================*/ void weight_a_lc_fx( const Word16 a[], /* i: LP filter coefficients Q12 */ - Word16 ap[], /* o: weighted LP filter coefficients Q12 */ + Word16 ap[], /* o: weighted LP filter coefficients Q12 */ const Word16 *gammatbl, /* i: weighting factor Q15 */ const Word16 m /* i: order of LP filter Q0 */ ) @@ -91,10 +89,10 @@ void weight_a_lc_fx( * Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i) *------------------------------------------------------------------*/ void weight_a_fx( - const Word16 a[], /* i: LP filter coefficients Q12 */ - Word16 ap[], /* o: weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i: weighting factor Q15 */ - const Word16 m /* i: order of LP filter Q0 */ + const Word16 a[], /* i: LP filter coefficients Q12 */ + Word16 ap[], /* o: weighted LP filter coefficients Q12 */ + const Word16 gamma, /* i: weighting factor Q15 */ + const Word16 m /* i: order of LP filter Q0 */ ) { Word16 i, fac; @@ -140,7 +138,12 @@ void weight_a_fx( * Returns: * void */ -void E_LPC_a_weight_inv(const Word16 *a, Word16 *ap, const Word16 inv_gamma, const Word16 m) +void E_LPC_a_weight_inv( + const Word16 *a, + Word16 *ap, + const Word16 inv_gamma, + const Word16 m +) { Word16 i; static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924, /* Q14 */ diff --git a/lib_com/weight_fx.c b/lib_com/weight_fx.c index 270ef3b..4c6daf5 100644 --- a/lib_com/weight_fx.c +++ b/lib_com/weight_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* * sfm2mqb_fx() @@ -17,7 +17,7 @@ static void sfm2mqb_fx( Word16 spe[], /* i : sub-vectors */ Word16 spe2q[], /* o : pbands */ - const Word16 nb_sfm /* i : number of norms */ + const Word16 nb_sfm /* i : number of norms */ ) { Word16 tmp, i; @@ -117,9 +117,9 @@ static void sfm2mqb_fx( *--------------------------------------------------------------------------*/ static void mqb2sfm_fx( - Word16 spe2q[], /* i : pbands */ - Word16 spe[], /* o : sub-vectors */ - const Word16 lnb_sfm /* i : number of norms */ + Word16 spe2q[], /* i : pbands */ + Word16 spe[], /* o : sub-vectors */ + const Word16 lnb_sfm /* i : number of norms */ ) { Word16 i; @@ -216,9 +216,9 @@ static void mqb2sfm_fx( *--------------------------------------------------------------------------*/ void map_quant_weight_fx( - const Word16 normqlg2[], /* i : quantized norms */ - Word16 wnorm[], /* o : weighted norm */ - const Word16 is_transient /* i : transient flag */ + const Word16 normqlg2[], /* i : quantized norms */ + Word16 wnorm[], /* o : weighted norm */ + const Word16 is_transient /* i : transient flag */ ) { Word16 sfm; diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index ddd4fa7..aca7b73 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -2,15 +2,15 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include - +#include #include "options.h" #include "prot_fx.h" #include "rom_com_fx.h" #include "log2.h" -#include "stl.h" +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ #define WARP_OS_RATE 8 #define LL 256 #define LL_OS (WARP_OS_RATE*LL) @@ -21,26 +21,37 @@ #define CUTFREE_REL_RANGE_Q2 1 #define WI_THRESHLD 0.8 #define WI_SAMPLE_THLD 20 -#define ERB_CBSIZE1 64 -#define ERB_CBSIZE2 64 -#define P_CBSIZE 64 /*#define _POLY1(x, c) ((c)[0] * (x) + (c)[1]) */ /*#define _POLY2(x, c) (_POLY1((x), (c)) * (x) + (c)[2]) */ /*#define _POLY3(x, c) (_POLY2((x), (c)) * (x) + (c)[3]) */ +/*-------------------------------------------------------------------* + * Local functions + *--------------------------------------------------------------------*/ + +static Word32 DTFS_setEngy_fx(DTFS_STRUCTURE_FX* X_DTFS_FX, Word32 en2_fx); + /*-------------------------------------------------------------------* * DTFS_new_fx() * * DTFS structure initialization. *-------------------------------------------------------------------*/ -DTFS_STRUCTURE_FX* DTFS_new_fx(void) +ivas_error DTFS_new_fx( + DTFS_STRUCTURE_FX** dtfs_out +) { Word16 i ; DTFS_STRUCTURE_FX* dtfs_fx = NULL; dtfs_fx = (DTFS_STRUCTURE_FX *) calloc(1,sizeof(DTFS_STRUCTURE_FX)); + PMT("verif mem alloc") + IF (dtfs_fx == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTFS (SC-VBR) structure\n")); + } + dtfs_fx->lag_fx = 0 ; move16(); dtfs_fx->nH_fx=0; @@ -61,9 +72,8 @@ DTFS_STRUCTURE_FX* DTFS_new_fx(void) dtfs_fx->b_fx[i] = 0; move16(); } - - return dtfs_fx; /* o: DTFS structure_fx */ - + *dtfs_out = dtfs_fx; + return IVAS_ERR_OK; } /*-------------------------------------------------------------------* * DTFS_copy_fx() @@ -103,6 +113,8 @@ void DTFS_copy_fx( move16(); Xout_fx->Q = Xinp_fx.Q; move16(); + return; + } @@ -111,13 +123,12 @@ void DTFS_copy_fx( * * Subtract one DTFS STRUCTURE from another. *-------------------------------------------------------------------*/ -DTFS_STRUCTURE_FX DTFS_sub_fx( - +void DTFS_sub_fx( + DTFS_STRUCTURE_FX *tmp,/* o: X1 - X2 */ DTFS_STRUCTURE_FX X1, /* i: DTFS input 1 */ DTFS_STRUCTURE_FX X2 /* i: DTFS input 2 */ ) { - DTFS_STRUCTURE_FX tmp ; Word16 i ,sft, tmp_loop; sft = sub(X1.Q,X2.Q); @@ -127,12 +138,12 @@ DTFS_STRUCTURE_FX DTFS_sub_fx( FOR(i=0; i<=tmp_loop; i++) { - tmp.a_fx[i] = sub(shr(X1.a_fx[i],sft),X2.a_fx[i]); + tmp->a_fx[i] = sub(shr(X1.a_fx[i],sft),X2.a_fx[i]); move16(); - tmp.b_fx[i] = sub(shr(X1.b_fx[i],sft),X2.b_fx[i]); + tmp->b_fx[i] = sub(shr(X1.b_fx[i],sft),X2.b_fx[i]); move16(); } - tmp.Q = X2.Q; + tmp->Q = X2.Q; move16(); } ELSE @@ -141,25 +152,30 @@ DTFS_STRUCTURE_FX DTFS_sub_fx( FOR(i=0; i<=tmp_loop; i++) { - tmp.a_fx[i] = sub(X1.a_fx[i],shl(X2.a_fx[i],sft)); + tmp->a_fx[i] = sub(X1.a_fx[i],shl(X2.a_fx[i],sft)); move16(); - tmp.b_fx[i] = sub(X1.b_fx[i],shl(X2.b_fx[i],sft)); + tmp->b_fx[i] = sub(X1.b_fx[i],shl(X2.b_fx[i],sft)); move16(); } - tmp.Q = X1.Q; + tmp->Q = X1.Q; move16(); } - tmp.lag_fx = s_max(X1.lag_fx, X2.lag_fx) ; - tmp.nH_fx=s_max(X1.nH_fx,X2.nH_fx); - tmp.nH_4kHz_fx=s_max(X1.nH_4kHz_fx,X2.nH_4kHz_fx); - tmp.upper_cut_off_freq_of_interest_fx=X1.upper_cut_off_freq_of_interest_fx; + tmp->lag_fx = s_max(X1.lag_fx, X2.lag_fx) ; + tmp->nH_fx=s_max(X1.nH_fx,X2.nH_fx); + tmp->nH_4kHz_fx=s_max(X1.nH_4kHz_fx,X2.nH_4kHz_fx); + tmp->upper_cut_off_freq_of_interest_fx=X1.upper_cut_off_freq_of_interest_fx; move16(); - tmp.upper_cut_off_freq_fx=X1.upper_cut_off_freq_fx; + tmp->upper_cut_off_freq_fx=X1.upper_cut_off_freq_fx; move16(); - return tmp ; + return ; } +/*-------------------------------------------------------------------* + * DTFS_fast_fs_inv() + * + * DTFS inverse. + *-------------------------------------------------------------------*/ -void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *out_fx, Word16 N_fx, Word16 LOG2N) +static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *out_fx, Word16 N_fx, Word16 LOG2N) { Word16 i, M_2, N_2, s; Word16 dbuf_fx[256+1]; @@ -198,157 +214,7 @@ void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *out_fx, Word16 N_fx, W out_fx[i]=dbuf_fx[i];/* Q0 */ move16(); } } -/*==============================================================================*/ -/* FUNCTION : DTFS_freq_corr_fx () */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X1_DTFS_fx : a_fx/b_fx in X1_DTFS_fx.Q */ -/* _ (struct DTFS_STRUCTURE_FX) X2_DTFS_fx : a_fx/b_fx in X2_DTFS_fx.Q */ -/* _ (Word16) lband: Q0 */ -/* _ (Word16) hband: Q0 */ -/*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) *Qout : Q of output result */ -/*------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word32) Result : Qout */ -/*------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*==============================================================================*/ - -Word32 DTFS_freq_corr_fx( DTFS_STRUCTURE_FX X1_DTFS_fx, DTFS_STRUCTURE_FX X2_DTFS_fx, Word16 lband, Word16 hband, Word16 *Qout) -{ - Word16 k, HalfLag, lk, hk ; - Word32 corr_fx; - Word32 freq_fx, L_lband, L_hband; - Word32 E_fx; - Word32 Num, Den, Result; - Word16 E1_fx, E2_fx, Q1, Q2, Qr; - Word16 expa,expb,fraca,fracb,scale; - Word16 exp,tmp; - Word32 L_tmp; - Word16 Q_num,Q_den; - - IF (LT_16(X1_DTFS_fx.lag_fx ,X2_DTFS_fx.lag_fx)) - { - DTFS_zeroPadd_fx(X2_DTFS_fx.lag_fx,&X1_DTFS_fx) ; - } - - corr_fx = L_deposit_l(0); - - L_lband = L_mult(lband, X2_DTFS_fx.lag_fx); - L_hband = L_mult(hband, X2_DTFS_fx.lag_fx); - HalfLag = s_min(shr(X2_DTFS_fx.lag_fx, 1),X2_DTFS_fx.nH_4kHz_fx); - - /* get lband and hband */ - FOR (k=0; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - IF (GE_32(freq_fx, L_lband)) - { - BREAK; - } - } - lk = k; - FOR (k=0; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - IF (GE_32(freq_fx, L_hband)) - { - BREAK; - } - } - hk = k; - move16(); - - FOR (k=lk; k0) - { - Result = L_add(L_tmp, 0); - } - ELSE - { - Result = L_negate(L_tmp); - } - *Qout = sub(30,exp); - - } - return Result; -} /*===================================================================*/ /* FUNCTION : DTFS_alignment_weight_fx () */ @@ -375,7 +241,19 @@ Word32 DTFS_freq_corr_fx( DTFS_STRUCTURE_FX X1_DTFS_fx, DTFS_STRUCTURE_FX X2_DTF /* CALLED FROM : TX/RX */ /*===================================================================*/ -Word16 DTFS_alignment_weight_fx( DTFS_STRUCTURE_FX *X_fx, DTFS_STRUCTURE_FX X2, Word16 Eshift, const Word16 *LPC1, const Word16 *LPC2, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1,Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2) +static Word16 DTFS_alignment_weight_fx( + DTFS_STRUCTURE_FX *X_fx, /* i : X1 the reference DTFS to keep fixed */ + DTFS_STRUCTURE_FX X2, /* i : X2 the test DTFS to shift to find best match */ + Word16 Eshift, /* i : Expected shift - coarse value */ + const Word16* LPC1, /* i : LPC to filter to find correlation in spch */ + const Word16* LPC2, /* i : LPC to filter to find correlation in spch */ + Word16 *S_fx, + Word16 *C_fx, + Word16 *pf_temp1, + Word16 *pf_temp2, + Word16 *pf_temp, + Word16 *pf_n2 +) { /* Eshift is w.r.t X2 */ Word16 k, HalfLag, start, end, ab1[MAXLAG_WI], ab2[MAXLAG_WI] ; @@ -495,152 +373,8 @@ Word16 DTFS_alignment_weight_fx( DTFS_STRUCTURE_FX *X_fx, DTFS_STRUCTURE_FX X2, return fshift_fx ; } -/*===================================================================*/ -/* FUNCTION : DTFS_alignment_extract_td_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : search for alignment in time domain */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 *) x1: Q? */ -/* _ (Word16 *) x2: Q? */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) lag : Q0 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ (Word16 *) idx: Q0 */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ - -Word16 DTFS_alignment_extract_td_fx(Word16 *x1, Word16 *x2, Word16 lag) -{ - Word16 j, k, idx, Adiff_fx ; - Word32 maxcorr, corr; - - maxcorr = L_add(MIN_32, 0); - Adiff_fx = (Word16)(s_max(4, shr(lag, 3))); - - idx=0; - move16(); - FOR ( j=negate(Adiff_fx); j<=Adiff_fx; j++) - { - corr=L_deposit_l(0); - FOR (k=0; k 0 ) - { - fshift_fx = n ; - move16(); - maxcorr_fx = (Word32)L_shl(corr_fx, Qcorr) ; /* Qcorr */ - Qmaxcorr = Qcorr; - move16(); - } - } - return fshift_fx ; -} /*===========================================================================*/ /* FUNCTION : DTFS_alignment_full_fx () */ /*---------------------------------------------------------------------------*/ @@ -663,9 +397,14 @@ Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE_FX X1_fx, DTFS_STRUCTURE_FX X2 /* CALLED FROM : TX */ /*===========================================================================*/ -Word16 DTFS_alignment_full_fx( DTFS_STRUCTURE_FX X1_DTFS_fx, DTFS_STRUCTURE_FX X2_DTFS_fx, Word16 ph_offset_fx,Word16 *S_fx, Word16 *C_fx - , Word16 FR_flag - ) +Word16 DTFS_alignment_full_fx( + DTFS_STRUCTURE_FX X1_DTFS_fx, + DTFS_STRUCTURE_FX X2_DTFS_fx, + Word16 ph_offset_fx, + Word16 *S_fx, + Word16 *C_fx, + Word16 FR_flag +) { Word16 temp, temp1, k, start, end, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI] ; Word16 n, fshift_fx; @@ -804,6 +543,7 @@ void DTFS_phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 * L_temp2 = L_add(L_temp2, ph); } } + return; } /*===================================================================*/ @@ -828,7 +568,13 @@ void DTFS_phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 * /* CALLED FROM : TX/RX */ /*===================================================================*/ -void Q2phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx) +void Q2phaseShift_fx( + DTFS_STRUCTURE_FX *X_fx, + Word16 ph, + Word16 Lag, + Word16 *S_fx, + Word16 *C_fx +) { Word16 k ; Word16 temp, HalfLag; @@ -869,7 +615,7 @@ void Q2phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_f /* PURPOSE : zeroPadding */ /*-------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ (Word16) N_fx: length , Q0 */ +/* _ (Word16) N_fx: length , Q0 */ /*-------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ None. */ @@ -883,7 +629,10 @@ void Q2phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_f /* CALLED FROM : TX/RX */ /*===================================================================*/ -void DTFS_zeroPadd_fx(Word16 N_fx,DTFS_STRUCTURE_FX *X_fx) +void DTFS_zeroPadd_fx( + Word16 N_fx, + DTFS_STRUCTURE_FX *X_fx +) { Word16 i, start, end ,diff_fx,rem_fx; @@ -944,8 +693,8 @@ void DTFS_to_fs_fx( const Word16 *x, /* i : time domain signal */ Word16 N, /* i : Length of input vector */ DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure with a, b, lag */ - Word16 Fs, /* i : sampling rate */ - Word16 FR_flag, /* i : FR flag */ + const Word16 Fs, /* i : sampling rate */ + const Word16 FR_flag, /* i : FR flag */ Word16 *S_fx, Word16 *C_fx ) @@ -1142,7 +891,7 @@ void DTFS_to_fs_fx( move16(); X_fx->nH_4kHz_fx=nH_4kHz; move16(); - + return; } @@ -1167,13 +916,13 @@ void DTFS_to_fs_fx( /*-------------------------------------------------------------------*/ /* CALLED FROM : TX/RX */ /*===================================================================*/ -void DTFS_transform_fx( +static void DTFS_transform_fx( DTFS_STRUCTURE_FX X_fx, /* i : Starting DTFS to use in WI */ DTFS_STRUCTURE_FX X2_fx, /* i : Ending DTFS to use in WI */ const Word32 *phase_fx, /* i : Phase contour */ Word16 *out_fx, /* o : Output time domain waveform */ Word16 N, /* i : Number of samples to generate */ - Word16 FR_flag /* i : Flag to indicate called in FR context */ + const Word16 FR_flag /* i : Flag to indicate called in FR context */ ) { @@ -1193,9 +942,27 @@ void DTFS_transform_fx( Word16 tmp, tmp1, tmp2, frac, exp1, exp2; Word16 expa, expb, fraca, fracb, scale; - DTFS_STRUCTURE_FX *tmp2_dtfs_fx = DTFS_new_fx(); - DTFS_STRUCTURE_FX *tmp1_dtfs_fx = DTFS_new_fx(); - DTFS_STRUCTURE_FX *tmp3_dtfs_fx = DTFS_new_fx(); + ivas_error error; + + DTFS_STRUCTURE_FX* tmp1_dtfs_fx; + DTFS_STRUCTURE_FX* tmp2_dtfs_fx; + DTFS_STRUCTURE_FX* tmp3_dtfs_fx; + + error = IVAS_ERR_OK; + + IF ((error = DTFS_new_fx(&tmp1_dtfs_fx)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure 1"); + } + IF ((error = DTFS_new_fx(&tmp2_dtfs_fx)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure 2"); + } + IF ((error = DTFS_new_fx(&tmp3_dtfs_fx)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure 3"); + } + DTFS_copy_fx(tmp1_dtfs_fx,X_fx); DTFS_copy_fx(tmp2_dtfs_fx,X2_fx); @@ -1359,9 +1126,10 @@ void DTFS_transform_fx( } - free(tmp1_dtfs_fx); - free(tmp2_dtfs_fx); - free(tmp3_dtfs_fx); + count_free(tmp1_dtfs_fx); + count_free(tmp2_dtfs_fx); + count_free(tmp3_dtfs_fx); + return; } /*===================================================================*/ /* FUNCTION : zeroFilter_fx() */ @@ -1388,7 +1156,13 @@ void DTFS_transform_fx( /* CALLED FROM : TX/RX */ /*===================================================================*/ -void DTFS_zeroFilter_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx) +void DTFS_zeroFilter_fx( + DTFS_STRUCTURE_FX *X_fx, + Word16 *LPC, + Word16 N, + Word16 *S_fx, + Word16 *C_fx +) { Word32 sum1_fx, sum2_fx ; Word16 k, n, HalfLag ; @@ -1467,6 +1241,7 @@ void DTFS_zeroFilter_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *LPC, Word16 N, Word16 * X_fx->Q = add(X_fx->Q, Qmin); move16(); + return; } /*===================================================================*/ /* FUNCTION : DTFS_poleFilter_fx() */ @@ -1496,7 +1271,13 @@ void DTFS_zeroFilter_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *LPC, Word16 N, Word16 * /* PORTING: Handling the functions with variable no. of arguments */ -void DTFS_poleFilter_fx_9( DTFS_STRUCTURE_FX *X_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1) +void DTFS_poleFilter_fx_9( + DTFS_STRUCTURE_FX *X_fx, + Word16 *pf_temp1, + Word16 *pf_temp2, + Word16 *pf_temp, + Word16 *pf_n2_temp1 +) { Word16 temp, temp1, temp2, HalfLag ; Word32 sum1_fx, sum2_fx; @@ -1574,6 +1355,7 @@ void DTFS_poleFilter_fx_9( DTFS_STRUCTURE_FX *X_fx, Word16 *pf_temp1, Word16 *pf } X_fx->Q = add(X_fx->Q, Qmin); + return; } /*===================================================================*/ /* FUNCTION : DTFS_adjustLag_fx () */ @@ -1666,6 +1448,7 @@ void DTFS_adjustLag_fx( move16(); } } + return; } /*===================================================================*/ /* FUNCTION : DTFS_getEngy_fx () */ @@ -1686,7 +1469,9 @@ void DTFS_adjustLag_fx( /*===================================================================*/ -Word32 DTFS_getEngy_fx( DTFS_STRUCTURE_FX *X_fx) +Word32 DTFS_getEngy_fx( + DTFS_STRUCTURE_FX *X_fx +) { Word16 k, HalfLag_fx; Word32 en_fx=0; @@ -1744,7 +1529,9 @@ Word32 DTFS_getEngy_fx( DTFS_STRUCTURE_FX *X_fx) /* CALLED FROM : TX/RX */ /*===================================================================*/ -Word32 DTFS_getEngy_P2A_fx( DTFS_STRUCTURE_FX *X_fx) +Word32 DTFS_getEngy_P2A_fx( + DTFS_STRUCTURE_FX *X_fx +) { Word16 k, HalfLag_fx; Word32 en_fx=0; @@ -1769,81 +1556,7 @@ Word32 DTFS_getEngy_P2A_fx( DTFS_STRUCTURE_FX *X_fx) } -/*=================================================================================*/ -/* FUNCTION : DTFS_getEngy_band_fx (Word16 lband, Word16 hband) */ -/*---------------------------------------------------------------------------------*/ -/* PURPOSE : compute the energy of X1.a[k] and X2.b[k] */ -/*---------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx : a_fx/b_fx in X_fx.Q, lag in Q0 */ -/* _ (Word16) lband: Q0 */ -/* _ (Word16) hband: Q0 */ -/*---------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word40) en_fx : 2*X1.Q */ -/*---------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*---------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*---------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*=================================================================================*/ - -/* PORTING: Handling the functions with variable no. of arguments */ - -Word32 DTFS_getEngy_band_fx(DTFS_STRUCTURE_FX X_fx,Word16 lband, Word16 hband) -{ - Word16 k, lk, hk, HalfLag ; - Word32 freq_fx, L_lband, L_hband; - Word32 en_fx=0; - L_lband = L_mult(lband, X_fx.lag_fx); - L_hband = L_mult(hband, X_fx.lag_fx); - HalfLag = s_min(shr(sub(X_fx.lag_fx, 1), 1),X_fx.nH_4kHz_fx); - /* get lband and hband */ - FOR (k=1; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - IF (GE_32(freq_fx, L_lband)) - { - BREAK; - } - } - lk = k; - move16(); - FOR (k=1; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - IF (GE_32(freq_fx, L_hband)) - { - BREAK; - } - } - hk = k; - move16(); - - FOR (k=lk; kb_fx[k]= 0; move16(); /* clear b[k]; */ } + return; } @@ -2206,10 +1923,13 @@ Word32 DTFS_setEngyHarm_fx( /*===================================================================*/ /* NOTE: This function outputs phase in (-1,1) */ /*===================================================================*/ -static -void cubicPhase_fx( - Word16 ph1_fx, Word16 ph2_fx, Word16 L1, Word16 L2, - Word16 N, Word32 *phOut_fx +static void cubicPhase_fx( + Word16 ph1_fx, /* i : phase offset */ + Word16 ph2_fx, /* i : phase 2 */ + const Word16 L1, /* i : previous lag */ + const Word16 L2, /* i : current lag */ + Word16 N, /* i : input length */ + Word32* phOut_fx /* o : cubic phase output */ ) { Word16 n; @@ -2497,7 +2217,7 @@ void cubicPhase_fx( move32(); /* Q27 */ } - + return; } /*===================================================================*/ @@ -2631,6 +2351,7 @@ void DTFS_to_erb_fx( out_fx[i] = round_fx(L_tmp); } } + return; } /*===================================================================*/ /* FUNCTION : erb_slot_fx () */ @@ -2778,7 +2499,7 @@ void erb_slot_fx( } } - + return; } /*===================================================================*/ /* FUNCTION : DTFS_erb_inv_fx () */ @@ -2924,291 +2645,9 @@ void DTFS_erb_inv_fx( } X_fx->Q=min_q; + return; } -/*===================================================================*/ -/* FUNCTION : LPCPowSpect_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Compute LPC power spectrum */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 []) freq : ERB frequency bounds, Q15 */ -/* _ (Word16 []) LPC : LPC coefficients, Q12 */ -/* _ (Word16) Nf: number of ERB bins, Q0 */ -/* _ (Word16) Np : order of LPC, Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) out : LPC power spectrum, Q7 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ -/* NOTE: Frequency is normalized by 12800, i.e. 1=12800Hz */ -/*===================================================================*/ -void LPCPowSpect_fx(Word16 *freq, Word16 Nf, Word16 *LPC, Word16 Np, - Word16 *out) -{ - Word16 i, k; - Word16 w; /* Q9 */ - Word16 t1, dt; - /*Word16 t2; */ - Word16 dh, dl; - Word32 Re, Im; /* Q27 */ - Word32 Ltemp, Lw; - Word32 Lacc; - Word16 tmp,exp; - - FOR (k=0; k 0) - { - tmp = div_s(16384, tmp); /* 15+exp1 */ - } - ELSE - { - tmp = 0; - move16(); - } - Ltemp = L_deposit_h(tmp); - out[k] = round_fx(L_shl(Ltemp,negate(add(exp,8)))); - - /* out[k] = shl(tmp,-exp-8); in Q7 */ - - } -} -/*===================================================================*/ -/* FUNCTION : erb_diff_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Quantize erb amplitude for QPPP */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pl : previous pitch lag, Q0 */ -/* _ (Word16) l : current pitch lag, Q0 */ -/* _ (Word16 []) prev_erb : Previous erb amplitude, Q13 */ -/* _ (Word16 []) curr_erb : Current erb amplitude, Q13 */ -/* _ (Word16 []) curr_lsp : LSP coefficients, Q12 */ -/* _ (Word16 []) num_erb : Number of ERBs , Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) index: quantized differential erb index */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ -static -void erb_diff_fx( - const Word16 *prev_erb, /* i : previous ERB */ - Word16 pl, /* i : previous lag */ - const Word16 *curr_erb, /* i : current ERB */ - Word16 l, /* i : current lag */ - const Word16 *curr_lsp, /* i : current LSP coefficients */ - Word16 *index, /* 0 : ERB index */ - Word16 num_erb /* i : Number of ERBs */ -) -{ - Word16 i; - Word16 pslot[NUM_ERB_WB], cslot[NUM_ERB_WB]; - Word16 tmp, t_prev_erb[NUM_ERB_WB], LPC[M+1], mfreq[NUM_ERB_WB], PowSpect[NUM_ERB_WB], dif_erb[NUM_ERB_WB] ; - const Word16 *AmpCB1_fx = NULL; - - IF (EQ_16(num_erb,NUM_ERB_NB)) - { - AmpCB1_fx=AmpCB1_NB_fx; - move16(); - } - ELSE IF (EQ_16(num_erb,NUM_ERB_WB)) - { - AmpCB1_fx=AmpCB1_WB_fx; - move16(); - - } - erb_slot_fx (l,cslot,mfreq,num_erb);/* cslot in Qo and mfreq in Q15 */ - erb_slot_fx (pl,pslot,t_prev_erb,num_erb); - - FOR (i=0; i=0; i--) - { - IF (pslot[i]!=0) - { - tmp = t_prev_erb[i]; - move16(); - } - ELSE - { - t_prev_erb[i] = tmp ; - move16(); - } - } - } - FOR(i=0; iupper_cut_off_freq_fx,0x2800))/* 4000 hz normalized to 12800 in Q15 */ - { - num_erb=NUM_ERB_NB; - move16(); - PowerCB_fx=PowerCB_NB_fx; - move16(); - } - ELSE IF (EQ_16(X_fx->upper_cut_off_freq_fx,0x4000))/* 6400 hz normalized to 12800 in Q15 */ - { - num_erb=NUM_ERB_WB; - move16(); - PowerCB_fx=PowerCB_WB_fx; - move16(); - } - - /* Get weighting and target */ - quant_target_fx(X_fx,curr_lpc_fx, w, target, sin_tab, cos_tab); - - /* Power Quantization in log domain */ - target[0]=sub(target[0],*lastLgainE_fx); - move16(); - target[1]=sub(target[1],*lastHgainE_fx); - move16(); - - minerror = L_add(EVS_LW_MAX, 0); - *POWER_IDX = 0; - move16(); - - j=0; - move16(); - FOR (n=0; n=0 && d2>=0) - { - Ltemp= Mult_32_16(Ltemp,0x6666); /* *=0.8 */ - } - IF (LT_32(Ltemp, minerror)) - { - minerror = L_add(Ltemp, 0); - *POWER_IDX = j ; - move16(); - } - j = add(j,1); - } - DTFS_to_erb_fx (*X_fx,curr_erb_fx) ; - - FOR(j=0; jlag_fx, slot, mfreq,num_erb) ; - /* Amplitude Quantization */ - - - erb_diff_fx(lasterbE_fx,pl,curr_erb_fx,X_fx->lag_fx,curr_lpc_fx,AMP_IDX,num_erb); - - - /* Dequantization of prototype */ - /* PORTING: Removing the references */ - /* DTFS_dequant_cw_fx(pl, *POWER_IDX, AMP_IDX,lastLgainE_fx,lastHgainE_fx, lasterbE_fx,X_fx,num_erb,curr_erb_fx); */ - - /* Determine IF the amplitude quantization is good enough */ - erb_add_fx(curr_erb_fx,X_fx->lag_fx,lasterbE_fx,pl,AMP_IDX,num_erb); - - curr_erb_fx[0] = mult_r(curr_erb_fx[1],9830); - move16(); /* 0.3 inQ15 leaves curr_erb in Q13 */ - curr_erb_fx[sub(num_erb,2)] = mult_r(curr_erb_fx[sub(num_erb,3)],9830);/* Q13 */ - - curr_erb_fx[sub(num_erb,1)] = 0; - move16(); - flag=1; - move16(); - - Ltemp = L_deposit_l(0); - n=0; - move16(); - FOR (j=1; j<10; j++) - { - IF (slot[j]!=0) - { - Ltemp=L_add(Ltemp,abs_s(sub(erb_uq[j],curr_erb_fx[j]))); /* Q13 */ - n=add(n,1); /* n++ */ - } - } - - exp = norm_s(n); - tmp = div_s(shl(1,sub(14,exp)),n);/* 29 - exp */ - Lacc = L_shl( Mult_32_16(Ltemp , tmp), exp +4); - - tmp=round_fx(Lacc); /* tmp in Q15 */ - - test(); - if (GT_16(tmp,0x3C29)&>_16(target[0],-819)) - { - flag = 0 ; /* Bumping up */ move16(); - } - - /* mfreq normalized (2.56) in Q15 */ - DTFS_erb_inv_fx(curr_erb_fx, slot, mfreq, X_fx,num_erb) ; - - - /* Back up the lasterbD memory after power normalization */ - DTFS_setEngyHarm_fx(236,2828,0,2828,1,0,&Ql,X_fx); - DTFS_setEngyHarm_fx(2828,X_fx->upper_cut_off_freq_of_interest_fx,2828,X_fx->upper_cut_off_freq_fx,1,0,&Qh,X_fx); - - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - - /* This logic adjusts difference between Q formats of both bands */ - - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); - - tmp=shl(*POWER_IDX,1); /* tmp=2*POWER_IDX */ - *lastLgainE_fx =add(*lastLgainE_fx, PowerCB_fx[tmp]) ; /* Q11 */ - *lastHgainE_fx =add(*lastHgainE_fx, PowerCB_fx[tmp+1]); /* Q11 */ - - Ltemp=log10_fx(X_fx->lag_fx); /* Ltemp=10*log10(lag), Q23 */ - logLag_fx= Mult_32_16(Ltemp,0x6666); /* logLag=log10(lag), Q26 */ - - Ltemp=L_sub(L_shr(L_deposit_h(*lastLgainE_fx),1),logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ - - L_tmp=pow_10(Ltemp,&Q); /* Lacc=10^Lgain/lag, Q15 */ - n=norm_l(L_tmp); - Ltemp=(Word32)L_shl(L_tmp,n); /* Ltemp in Q(15+n) */ - - - DTFS_setEngyHarm_fx(236,2828,0,2828,Ltemp, add(Q,n),&Ql,X_fx); - - Ltemp=L_sub(L_shr(L_deposit_h(*lastHgainE_fx),1),logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ - - /* Ltemp = L_shr(Ltemp,1); */ - L_tmp = pow_10(Ltemp,&Q); /* Lacc=10^Lgain/lag, Q15 */ - n=norm_l(L_tmp); - Ltemp=(Word32)L_shl(L_tmp,n); /* Ltemp in Q(15+n) */ - - DTFS_setEngyHarm_fx(2828,X_fx->upper_cut_off_freq_of_interest_fx,2828,X_fx->upper_cut_off_freq_fx,Ltemp,add(Q,n),&Qh,X_fx); - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); - - return flag; -} /*===================================================================*/ /* FUNCTION : struct quant_target_fx() */ /*-------------------------------------------------------------------*/ @@ -3661,192 +2880,7 @@ void quant_target_fx( DTFS_STRUCTURE_FX *X_fx,const Word16 *curr_lpc, Word16 *w, IF (n<0) rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); ELSE IF (n>0) rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); } -/*===================================================================*/ -/* FUNCTION : struct DTFS_fx::dequant_cw_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Dequantize QPPP prototype */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pl: previous lag */ -/* _ (Word16) p_idx: Power index */ -/* _ (Word16[]) a_idx: Amplitude indices, 2 words */ -/* _ (struct DTFS_fx) X : prototype in polar domain */ -/* (Word16) lag: length of prototype */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X : prototype in polar domain */ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (Word16[]) curr_erb: Quantized current ERB, Q13 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) lasterb: ERB history for differential */ -/* quantization, Q13 */ -/* _ (Word16) Lgain: low band power history, log domain, Q11 */ -/* _ (Word16) Hgain: high band power history, log domain, Q11 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_dequant_cw_fx( - Word16 pl_fx, /* i : Previous lag */ - Word16 POWER_IDX_fx, /* i : POWER index */ - const Word16 *AMP_IDX_fx, /* i : Amp Shape index */ - Word16 *lastLgainD_fx, /* i/o: low band last gain */ - Word16 *lastHgainD_fx, /* i/o: high band last gain */ - Word16 *lasterbD_fx, /* i/o: last frame ERB vector */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure dequantized */ - Word16 num_erb_fx -) - -{ - Word16 tmp_fx, mfreq_fx[NUM_ERB_WB], curr_erb_fx[NUM_ERB_WB]; - const Word16 *PowerCB_fx=NULL; - Word16 slot_fx[NUM_ERB_WB]; - Word16 Ql, Qh, n; - Word32 Ltemp_fx,logLag_fx; - Word16 exp,frac,exp1; - Word32 L_tmp,L_temp; - Word32 L_tmp2; - - IF (num_erb_fx==NUM_ERB_NB) - { - PowerCB_fx=PowerCB_NB_fx; - move16(); - } - ELSE IF (num_erb_fx==NUM_ERB_WB) - { - PowerCB_fx=PowerCB_WB_fx; - move16(); - } - - /* Amplitude Dequantization */ - - erb_add_fx(curr_erb_fx,X_fx->lag_fx,lasterbD_fx,pl_fx,AMP_IDX_fx,num_erb_fx); - - curr_erb_fx[0] = mult_r(curr_erb_fx[1],9830);/* 0.3 inQ15 leaves curr_erb in Q13 */ - curr_erb_fx[sub(num_erb_fx,2)] = mult_r(curr_erb_fx[sub(num_erb_fx,3)],9830);/* Q13 */ - - move16(); - - curr_erb_fx[sub(num_erb_fx,1)] = 0; - - erb_slot_fx(X_fx->lag_fx,slot_fx,mfreq_fx,num_erb_fx); - - /* mfreq normalized (2.56) in Q15 */ - DTFS_erb_inv_fx(curr_erb_fx, slot_fx, mfreq_fx, X_fx,num_erb_fx) ; - - - /* Back up the lasterbD memory after power normalization */ - - DTFS_setEngyHarm_fx(236,2828,0,2828,1,0,&Ql,X_fx); - DTFS_setEngyHarm_fx(2828,X_fx->upper_cut_off_freq_of_interest_fx,2828,X_fx->upper_cut_off_freq_fx,1,0,&Qh,X_fx); - - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - - - /* This logic adjusts difference between Q formats of both bands */ - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); - - DTFS_to_erb_fx(*X_fx,lasterbD_fx); - - - /* Power Dequantization */ - - tmp_fx=shl(POWER_IDX_fx,1); /* tmp=2*POWER_IDX */ - *lastLgainD_fx =add(*lastLgainD_fx, PowerCB_fx[tmp_fx]) ; /* Q11 */ - *lastHgainD_fx =add(*lastHgainD_fx, PowerCB_fx[tmp_fx+1]); /* Q11 */ - - L_tmp = L_deposit_h(X_fx->lag_fx); /* Q16 */ - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,exp); - frac = Log2_norm_lc(L_tmp); - exp = sub(30,add(exp,16)); - L_tmp = Mpy_32_16(exp,frac,12330);/* Q13 */ /* 10*log10(2) in Q12*/ - Ltemp_fx = L_shl(L_tmp, 10);/* Q23 */ - - - logLag_fx= Mult_32_16(Ltemp_fx,0x6666); /* logLag=log10(lag), Q26 */ - - Ltemp_fx=L_sub(L_shr(L_deposit_h(*lastLgainD_fx),1),logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ - - /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Lgain/lag, Q15 */ - - L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ - L_tmp = L_shr(L_tmp,8); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_tmp =Pow2(14, frac); - exp1 = sub(exp1,14); - L_temp = L_shl(L_tmp, add(exp1,15) ); /* Q15 */ - - L_tmp2 = L_temp; - if( GE_32( L_temp, 2147483647 )) - { - L_temp = L_shl(L_tmp, 15 ); /*Q(15-exp1) */ - } - - n=norm_l(L_temp); - Ltemp_fx=L_shl(L_temp,n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ - - IF( GE_32( L_tmp2, 2147483647 )) - { - DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, Ltemp_fx, add(15,sub(n,exp1)), &Ql, X_fx ); - } - ELSE - { - DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, Ltemp_fx, add(15,n), &Ql, X_fx ); - } - - Ltemp_fx=L_sub(L_shr(L_deposit_h(*lastHgainD_fx),1),logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ - /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Hgain/lag, Q15 */ - L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ /* Q24 */ - L_tmp = L_shr(L_tmp,8); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_tmp =Pow2(14, frac); - exp1 = sub(exp1,14); - L_temp = L_shl(L_tmp,exp1 +15 ); /* Q15 */ - - L_tmp2 = L_temp; - if( GE_32( L_temp, 2147483647 )) - { - L_temp = L_shl(L_tmp, 15 ); /*Q(15-exp1) */ - } - - - n=norm_l(L_temp); - Ltemp_fx=L_shl(L_temp,n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ - - IF( GE_32( L_tmp2, 2147483647 )) - { - DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx,2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx,add( 15, sub( n, exp1 )),&Qh, X_fx ); - } - ELSE - { - DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx,2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add( 15, n ), &Qh, X_fx ); - } - - - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - - - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); -} /*==========================================================================*/ /* FUNCTION : WIsyn_fx () */ /*--------------------------------------------------------------------------*/ @@ -3854,7 +2888,7 @@ void DTFS_dequant_cw_fx( /*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (struct DTFS_STRUCTURE_FX) PREVCW_FX: a/b in PREVCW_FX.Q */ -/* _ (struct DTFS_fx *) CURR_CW_DTFS_FX: a/b in CURR_CW_DTFS_FX->Q */ +/* _ (struct DTFS_fx *) CURRCW_DTFS_out: a/b in CURRCW_DTFS_out->Q */ /* _ (Word16 *) curr_lpc_fx: lpc coefficients in Q12 */ /* _ (Word16 *) ph_offset_fx: in Q15, normalized by 2pi */ /* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ @@ -3865,20 +2899,19 @@ void DTFS_dequant_cw_fx( /* _ (Word16 *) out_fx: Q0 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX *) CURR_CW_DTFS_FX: a/b in CURR_CW_DTFS_FX->Q*/ +/* _ (struct DTFS_STRUCTURE_FX *) CURRCW_DTFS_out: a/b in CURRCW_DTFS_out->Q*/ /* _ (Word16 *) ph_offset_fx: in Q15, normalized by 2pi */ /*--------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : _ None. */ /*==========================================================================*/ - -void WIsyn_fx( - DTFS_STRUCTURE_FX PREVCW_FX, - DTFS_STRUCTURE_FX *CURR_CW_DTFS_FX, - const Word16 *curr_lpc_fx, - Word16 *ph_offset_fx, - Word16 *out_fx, - Word16 N, - Word16 FR_flag, /* i : called for post-smoothing in FR */ +ivas_error WIsyn_fx( + DTFS_STRUCTURE_FX PREVCW_FX, /* i : Prev frame DTFS */ + DTFS_STRUCTURE_FX* CURRCW_DTFS_out, /* i/o: Curr frame DTFS */ + const Word16* curr_lpc_fx, /* i : LPC */ + Word16* ph_offset_fx, /* i/o: Phase offset to line up at end of frame */ + Word16* out_fx, /* o : Waveform Interpolated time domain signal */ + const Word16 N, /* i : Number of output samples to generate */ + const Word16 FR_flag, /* i : called for post-smoothing in FR */ Word16 * S_fx, Word16* C_fx, Word16 *pf_temp1, @@ -3899,41 +2932,48 @@ void WIsyn_fx( /* prev_lsp_fx; */ - DTFS_STRUCTURE_FX *CURRCW_DTFS_FX=DTFS_new_fx(); + DTFS_STRUCTURE_FX *CURRCW_DTFS_FX; + ivas_error error; + error = IVAS_ERR_OK; - IF (LT_16(PREVCW_FX.Q,CURR_CW_DTFS_FX->Q)) + IF ((error = DTFS_new_fx(&CURRCW_DTFS_FX)) != IVAS_ERR_OK) + { + return IVAS_ERROR(error, "Error creating new DTFS structure\n"); + } + IF(LT_16(PREVCW_FX.Q, CURRCW_DTFS_out->Q)) { - temp = sub(CURR_CW_DTFS_FX->Q, PREVCW_FX.Q); - tmp = s_min(shr(CURR_CW_DTFS_FX->lag_fx,1),CURR_CW_DTFS_FX->nH_fx); - FOR (i=0; i<=tmp; i++) + temp = sub(CURRCW_DTFS_out->Q, PREVCW_FX.Q); + tmp = s_min(shr(CURRCW_DTFS_out->lag_fx, 1), CURRCW_DTFS_out->nH_fx); + FOR(i = 0; i <= tmp; i++) { - CURR_CW_DTFS_FX->a_fx[i] = shr(CURR_CW_DTFS_FX->a_fx[i], temp); + CURRCW_DTFS_out->a_fx[i] = shr(CURRCW_DTFS_out->a_fx[i], temp); move16(); - CURR_CW_DTFS_FX->b_fx[i] = shr(CURR_CW_DTFS_FX->b_fx[i], temp); + CURRCW_DTFS_out->b_fx[i] = shr(CURRCW_DTFS_out->b_fx[i], temp); move16(); } - CURR_CW_DTFS_FX->Q=PREVCW_FX.Q; + CURRCW_DTFS_out->Q = PREVCW_FX.Q; move16(); } - IF (LT_16(CURR_CW_DTFS_FX->Q,PREVCW_FX.Q)) + IF(LT_16(CURRCW_DTFS_out->Q, PREVCW_FX.Q)) { - temp = sub(PREVCW_FX.Q, CURR_CW_DTFS_FX->Q); - tmp = s_min(shr(PREVCW_FX.lag_fx, 1),PREVCW_FX.nH_fx); - FOR (i=0; i<=tmp; i++) + temp = sub(PREVCW_FX.Q, CURRCW_DTFS_out->Q); + tmp = s_min(shr(PREVCW_FX.lag_fx, 1), PREVCW_FX.nH_fx); + FOR(i = 0; i <= tmp; i++) { PREVCW_FX.a_fx[i] = shr(PREVCW_FX.a_fx[i], temp); move16(); PREVCW_FX.b_fx[i] = shr(PREVCW_FX.b_fx[i], temp); move16(); } - PREVCW_FX.Q=CURR_CW_DTFS_FX->Q; + PREVCW_FX.Q = CURRCW_DTFS_out->Q; move16(); } - DTFS_copy_fx( CURRCW_DTFS_FX, *CURR_CW_DTFS_FX); + DTFS_copy_fx(CURRCW_DTFS_FX, *CURRCW_DTFS_out); + /* Calculating the expected alignment shift */ alignment_fx = mult_r(*ph_offset_fx, shl(PREVCW_FX.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */ @@ -3997,7 +3037,7 @@ void WIsyn_fx( } DTFS_phaseShift_fx(CURRCW_DTFS_FX, alignment_fx, CURRCW_DTFS_FX->lag_fx, S_fx, C_fx) ; /* Qmin */ - DTFS_phaseShift_fx(CURR_CW_DTFS_FX, alignment_fx, CURR_CW_DTFS_FX->lag_fx, S_fx, C_fx);/* Qmin */ + DTFS_phaseShift_fx(CURRCW_DTFS_out, alignment_fx, CURRCW_DTFS_out->lag_fx, S_fx, C_fx);/* Qmin */ /* Compute the cubic phase track and transform to 1-D signal */ cubicPhase_fx(*ph_offset_fx, tmp_fx, PREVCW_FX.lag_fx , CURRCW_DTFS_FX->lag_fx, N, phase_fx) ; @@ -4016,7 +3056,7 @@ void WIsyn_fx( /* Adjust the phase offset and wrap it between 0 and 2pi */ - +PMT("NEED a complete verification of mem flow and assignment") IF (EQ_16(flag,2)) @@ -4039,6 +3079,7 @@ void WIsyn_fx( /* free(phase_fx) ; */ free(CURRCW_DTFS_FX); + return error; } diff --git a/lib_com/window.c b/lib_com/window.c index ecdc446..4bf8b52 100644 --- a/lib_com/window.c +++ b/lib_com/window.c @@ -3,10 +3,11 @@ ====================================================================================*/ +#include +#include "options.h" #include #include "basop_util.h" #include "prot_fx.h" -#include "stl.h" #define PI_HALF_0Q15 51472 /* ~=round(pi/2*2^15) */ #define PI2_15Q16 0x0006487F /* ~=round(2*PI*2^16) */ @@ -20,10 +21,11 @@ #include "rom_basop_util.h" -void ham_cos_window(Word16 *fh, /* o: 0Q15 */ - const Word16 n1, /* i: */ - const Word16 n2 /* i: */ - ) +void ham_cos_window( + Word16 *fh, /* o: 0Q15 */ + const Word16 n1, /* i: */ + const Word16 n2 /* i: */ +) { Word16 i; Word32 cte, cc; diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 163ce54..373503c 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -475,16 +475,145 @@ void window_ola_fx( *p2++=*p1++; } - /* for (i = 0; i < n; i++) - { - OldauOut[ i] = -ImdctOut[L/2 - 1 - i]; - } - for (i =0; i = MDCT_II ? -1.f : 1.f); + int16_t i, decimate, decay; + int16_t n, n16, windecay48, windecay16; + float win_right[R2_48]; + float win_int_left[R1_16]; + float win_left[R1_48]; + float win_int_right[R2_16]; + float* paout; + + n = (int16_t)((float)L * N_ZERO_MDCT_NS / FRAME_SIZE_NS); + n16 = (int16_t)((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS); + windecay48 = (int16_t)(2 * ((float)L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_48; + windecay16 = (int16_t)(2 * ((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_16; + decimate = 1; + decay = 0; + + tcx_get_windows_mode1(left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L); + + if (L == L_FRAME32k || L == L_FRAME16k) + { + decimate = 3; + decay = 1; + } + else if (L == L_FRAME8k) + { + decimate = 6; + decay = 2; + } + + else if (L == 512) + { + windecay48 = (int16_t)(2 * ((float)512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_25; + decimate = 1; + decay = 0; + } + else if (L == 256) + { + windecay48 = (int16_t)(2 * ((float)512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_25; + decimate = 2; + decay = 0; + } + paout = auOut - n; + + if (L == L_FRAME32k) + { + for (i = n; i < L / 2; i += 2) + { + paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[(2 * L_FRAME16k - (n16 + (i - n) / 2)) * decimate - 1 - decay - windecay48] + OldauOut[i]; + paout[i + 1] = sign_right * ImdstOut[L / 2 + i + 1] * win_int_right[2 * L_FRAME16k - (n16 + (i - n) / 2) - 1 - windecay16] + OldauOut[i + 1]; + } + + for (i = 0; i < L / 2 - n; i += 2) + { + paout[L / 2 + i + 1] = -ImdstOut[L - 1 - (i + 1)] * win_right[(3 * L_FRAME16k / 2 - 1 - i / 2) * decimate + decay - windecay48] + OldauOut[i + L / 2 + 1]; + paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_int_right[(3 * L_FRAME16k / 2 - 1 - i / 2) - windecay16] + OldauOut[i + L / 2]; + } + + for (i = L / 2 - n; i < L / 2; i += 2) + { + paout[L / 2 + i + 1] = -ImdstOut[L - 1 - (i + 1)] + OldauOut[i + L / 2 + 1]; + paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2]; + } + + for (i = 0; i < L / 2; i += 2) + { + OldauOut[L / 2 + i + 1] = sign_left * ImdstOut[i + 1] * win_left[(L_FRAME16k / 2 - i / 2 - 1) * decimate + decay]; + OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_int_left[(L_FRAME16k / 2 - i / 2 - 1)]; + } + + + for (i = n; i < L / 2; i += 2) + { + OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[(L_FRAME16k - i / 2) * decimate - decay - 1]; + OldauOut[i + 1] = -ImdstOut[L / 2 - 1 - (i + 1)] * win_int_left[L_FRAME16k - (i / 2) - 1]; + } + } + else + { + for (i = n; i < L / 2; i++) + { + paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[(2 * L - i) * decimate - 1 - decay - windecay48] + OldauOut[i]; + } + + for (i = 0; i < L / 2 - n; i++) + { + paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_right[(3 * L / 2 - 1 - i) * decimate + decay - windecay48] + OldauOut[i + L / 2]; + } + + for (i = L / 2 - n; i < L / 2; i++) + { + paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2]; + } + + for (i = 0; i < L / 2; i++) + { + OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_left[(L / 2 - i - 1) * decimate + decay]; + } + + + for (i = n; i < L / 2; i++) + { + OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[(L - i) * decimate - decay - 1]; + } + } + + for (i = 0; i < n; i++) + { + OldauOut[i] = -ImdstOut[L / 2 - 1 - i]; + } + for (i = 0; i < n; i++) + { + paout[L + i] = OldauOut[i]; + } + + return; +} +#endif @@ -495,14 +624,14 @@ void window_ola_fx( * overlapp ACELP and HQ *---------------------------------------------------------------------*/ void core_switching_OLA_fx( - Word16 *mem_over_hp, /* i : upsampling filter memory Qsubrf (except at 8kHz) */ - const Word16 last_L_frame, /* i : last L_frame lengthture */ - const Word32 output_Fs, /* i : output sampling rate */ - Word16 *synth, /* i/o: synthesized signal from HQ core Qsynth*/ - Word16 *synth_subfr_out, /* i : synthesized signal from ACELP core Qsubfr*/ - Word16 *synth_subfr_bwe, /* i : synthesized BWE from ACELP core Qbwe (todo) */ - const Word16 output_frame, /* i : output frame length */ - const Word16 bwidth, /* i : output bandwidth */ + Word16 *mem_over_hp, /* i : upsampling filter memory Qsubrf (except at 8kHz) */ + const Word16 last_L_frame, /* i : last L_frame lengthture */ + const Word32 output_Fs, /* i : output sampling rate */ + Word16 *synth, /* i/o: synthesized signal from HQ core Qsynth*/ + Word16 *synth_subfr_out, /* i : synthesized signal from ACELP core Qsubfr*/ + Word16 *synth_subfr_bwe, /* i : synthesized BWE from ACELP core Qbwe (todo) */ + const Word16 output_frame, /* i : output frame length */ + const Word16 bwidth, /* i : output bandwidth */ Word16* Qsynth, Word16* Qsubfr ) diff --git a/lib_com/wtda_fx.c b/lib_com/wtda_fx.c index 8d4b5cc..2936b7b 100644 --- a/lib_com/wtda_fx.c +++ b/lib_com/wtda_fx.c @@ -1,24 +1,22 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required by wmc_tool */ - #include "prot_fx.h" /* required by wmc_tool */ #include "stat_com.h" -/*--------------------------------------------------------------------------* - * wtda() - * - * Windowing and time-domain aliasing - *--------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------* + * mvr2r_inv() + * + * + *--------------------------------------------------------------------------*/ static void mvs2s_inv( - const Word16 *in, - Word16 *out, - Word16 L, - Word16 decimate + const Word16 *in, /* i : input vector */ + Word16* out, /* o : output vector */ + const Word16 L, /* i : length */ + const Word16 decimate /* i : decimation flag [-1,1] */ ) { Word16 i; @@ -33,13 +31,16 @@ static void mvs2s_inv( } } - - +/*--------------------------------------------------------------------------* + * mvr2r_dec() + * + * + *--------------------------------------------------------------------------*/ static void mvs2s_dec( - const Word16 *in, - Word16 *out, - Word16 L, - Word16 decimate + const Word16 *in, /* i : input vector */ + Word16* out, /* o : output vector */ + const Word16 L, /* i : length */ + const Word16 decimate /* i : decimation flag [-1,1] */ ) { Word16 i; @@ -54,14 +55,20 @@ static void mvs2s_dec( } } +/*--------------------------------------------------------------------------* + * copy_win() + * + * + *--------------------------------------------------------------------------*/ static void copy_win( - Word16 *out_win, - Word16 nb_zero, - const Word16 *in_win, - Word16 win_lenght, - Word16 nb_one, - Word16 decimate) + Word16 *out_win, /* o : output window buffer */ + const Word16 nb_zero, /* i : length of zero padding */ + const Word16* in_win, /* i : input window */ + const Word16 win_lenght, /* i : length */ + const Word16 nb_one, /* i : length of flat section (ones) */ + const Word16 decimate /* i : input window */ +) { IF (decimate<0) { @@ -76,15 +83,20 @@ static void copy_win( set16_fx(out_win+add(nb_zero,win_lenght),32767,nb_one); } } +/*--------------------------------------------------------------------------* + * tcx_get_windows_mode1() + * + * + *--------------------------------------------------------------------------*/ void tcx_get_windows_mode1( - Word16 left_mode, /* i: overlap mode of left window half */ - Word16 right_mode, /* i: overlap mode of right window half */ - Word16 *left_win, /* o: left overlap window */ - Word16 *right_win, /* o: right overlap window */ - Word16 *left_win_int, /* o: left overlap window */ - Word16 *right_win_int, /* o: right overlap window */ - Word16 const L + const Word16 left_mode, /* i: overlap mode of left window half */ + const Word16 right_mode,/* i: overlap mode of right window half */ + Word16 *left_win, /* o: left overlap window */ + Word16 *right_win, /* o: right overlap window */ + Word16 *left_win_int, /* o: left overlap window */ + Word16 *right_win_int, /* o: right overlap window */ + const Word16 L /* i : length */ ) { /* Left part */ @@ -180,16 +192,21 @@ void tcx_get_windows_mode1( } } +/*--------------------------------------------------------------------------* + * wtda() + * + * Windowing and time-domain aliasing + *--------------------------------------------------------------------------*/ void wtda_fx( - Word16 *new_audio, /* i : input audio Q0 */ - Word16 *Q, /* i/o : Q of input/Output Audio */ - Word32 *wtda_audio, /* o : windowed audio Qout */ - Word16 *old_wtda, /* i/o: windowed audio from previous frame Qout */ + Word16 *new_audio, /* i : input audio Q0 */ + Word16 *Q, /* i/o : Q of input/Output Audio */ + Word32 *wtda_audio, /* o : windowed audio Qout */ + Word16 *old_wtda, /* i/o: windowed audio from previous frame Qout */ Word16 *Qold_wtda, - Word16 left_mode, - Word16 right_mode, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - const Word16 L + const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const Word16 L /* i : length */ ) { Word16 i, decimate, decay, tmp; @@ -392,50 +409,114 @@ void wtda_fx( p4-=decimate; /* wtda_audio[i+L/2]=allsig_l[i]*win_left[i*decimate+decay]-allsig_l[L-i-1]*win_left[L*decimate-i*decimate-1-decay];*/ } + } + + *Q=add(*Q,15); /* output Q */ + if (old_wtda != NULL) + { + Copy(new_audio,old_wtda,L); - /* Windowing and foldin for the MDST */ - /* if (wtda_audio_dst != NULL) - { + } + return; + +} +#ifdef IVAS_CODE + +void wtda_ext( + const float* new_audio, /* i : input audio */ + float* wtda_audio, /* o : windowed audio */ + const int16_t left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const int16_t right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const int16_t L, /* i : length */ + const uint16_t kernel_type /* i : transform kernel type (0 - 3) */ +) +{ + const float sign_left = (kernel_type >= 2 ? -1.f : 1.f); + const float sign_right = (kernel_type & 1 ? 1.f : -1.f); + int16_t i, decimate, decay; + int16_t n, windecay48, windecay16; + const float* allsig_l, * allsig_r; + float win_right[R2_48]; + float win_int_left[R1_16]; + float win_left[R1_48]; + float win_int_right[R2_16]; + + tcx_get_windows_mode1(left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L); + + decimate = 1; /* L_FRAME 48k */ + decay = 0; + windecay48 = (int16_t)(2 * ((float)L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_48; + + if (L == L_FRAME32k || L == L_FRAME16k) + { + decimate = 3; + decay = 1; + } + else if (L == L_FRAME8k) + { + decimate = 6; + decay = 2; + } + n = (int16_t)((float)L * N_ZERO_MDCT_NS / FRAME_SIZE_NS); + windecay16 = (int16_t)(2 * ((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_16; + allsig_r = new_audio + n; + allsig_l = new_audio + n - L; - for (i=n;i -#include -#include +#include #include #include "options.h" -#include "stl.h" #include "rom_com_fx.h" #include "rom_dec_fx.h" #include "basop_util.h" -#include "stl.h" #include "cnst_fx.h" #include "prot_fx.h" -/** - * \brief Arithmetic decoder - * \param[i/o] st - * \param[o] x - * \param[i] nt - * \param[i] nbbits - * \param[i] resQMaxBits - * \return resQBits - */ +/*-------------------------------------------------------------------* + * ACcontextMapping_decode2_no_mem_s17_LC() + * + * Arithmetic decoder + *-------------------------------------------------------------------*/ + Word16 ACcontextMapping_decode2_no_mem_s17_LC( Decoder_State_fx *st,/* i/o: decoder state */ Word16 *x, /* o: decoded spectrum */ @@ -226,7 +219,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /*Dectect overflow*/ IF (add(sub(st->next_bit_pos_fx, start_bit_pos), rest_bits) > 0) { - /* Roll back bit-stream position to overflow_bit_pos */ + /* Roll back bitstream position to overflow_bit_pos */ get_next_indice_tmp_fx(st, sub(overflow_bit_pos, st->next_bit_pos_fx)); rest_bits = rest_bits_overflow; move16(); @@ -282,7 +275,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( IF (NE_16(k, lastnz)) { rest_bits = add(rest_bits, nbbits_m2); - /* Set bit-stream position to (start_bit_pos+nbbits-rest_bits) */ + /* Set bitstream position to (start_bit_pos+nbbits-rest_bits) */ get_next_indice_tmp_fx(st, sub((sub(add(start_bit_pos, nbbits), rest_bits)), st->next_bit_pos_fx)); } @@ -317,10 +310,372 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); } - /* Set bit-stream pointer to end of buffer */ + /* Set bitstream pointer to end of buffer */ get_next_indice_tmp_fx(st, sub(add(start_bit_pos, nbbits), st->next_bit_pos_fx)); + return resQBits; +} +#ifdef IVAS_CONTEXT_MAPPING + +/*-------------------------------------------------------------------* + * RCcontextMapping_decode2_no_mem_s17_LCS() + * + * Range decoder + *-------------------------------------------------------------------*/ + + /*! r: resQBits */ +int16_t RCcontextMapping_decode2_no_mem_s17_LCS( + Decoder_State* st, /* i/o: decoder state */ + int16_t* x, /* o : decoded spectrum */ + const int16_t nt, /* i : size of spectrum */ + const int16_t nbbits, /* i : bit budget */ + const int16_t resQMaxBits, /* i : residual coding maximum bits */ + CONTEXT_HM_CONFIG* hm_cfg /* i : context-based harmonic model configuration*/ +) +{ + RangeUniDecState rc_st_dec; /* State of the range decoder */ + int16_t start_bit_pos, lsbs_bit_pos; + int16_t a, b, a1, b1, k; + uint16_t t; + int16_t lev, pki, esc_nb; + int16_t rateFlag; + int16_t lastnz, n; + uint16_t r; + int16_t resQBits; + int16_t rest_bits; + int16_t nt_half; + int16_t nbbits_m2; + int16_t bits_tups; /* No. of bits for coding the no. of tuples */ + + set_s(x, 0, nt); + + /*Decode number of ntuples*/ + start_bit_pos = st->next_bit_pos; + lsbs_bit_pos = start_bit_pos + nbbits - 1; + n = 0; + k = 1; + nt_half = nt >> 1; + + while (k < nt_half) + { + ++n; + k = k << 1; + } + + bits_tups = n; + + n = get_next_indice(st, n) + 1; + + t = 0; + + lastnz = n << 1; + + if (lastnz > nt) + { + st->BER_detect = 1; + return 0; + } + + if (hm_cfg) + { + int16_t a1_i, b1_i; + int32_t c[2], * ctx; + int32_t p1, p2; + int16_t ii[2]; + int16_t idx1, idx2, idx; + int16_t numPeakIndicesOrig, numHoleIndices; + + /* Rate flag */ + if (nbbits > 400) + { + rateFlag = 2 << NBITS_CONTEXT; + } + else + { + rateFlag = 0; + } + + /* Init */ + c[0] = c[1] = 0; + + /* mapped domain */ + numPeakIndicesOrig = hm_cfg->numPeakIndices; + hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz); + numHoleIndices = lastnz - hm_cfg->numPeakIndices; + + /* Mark hole indices beyond lastnz as pruned */ + for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + { + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; + } + + ii[0] = numPeakIndicesOrig; + ii[1] = 0; + + p1 = p2 = 0; /* to avoid compilation warnings */ + + /* Start Decoding */ + /* Initialize range decoder */ + rc_uni_dec_init(&rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits); /* (nbbits + 30) entries are read by the decoder */ + + nbbits_m2 = nbbits; + rest_bits = -nbbits_m2; + + /* Main Loop through the 2-tuples */ + for (k = 0; k < lastnz; k += 2) + { + a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg); + b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg); + idx = min(idx1, idx2); + + /* Get context */ + ctx = &c[p1 | p2]; + + t = (uint16_t)(*ctx + rateFlag); + t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + + esc_nb = 0; + r = 0; + + /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/ + if ((t >= (1 << (NBITS_CONTEXT + NBITS_RATEQ))) || lsbs_bit_pos <= 0) + { + st->BER_detect = 1; + return 0; + } + + a = b = 0; + + /* MSBs decoding */ + for (lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev) + { + esc_nb = min(lev, 3); + pki = ari_lookup_s17_LC[t + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + r = rc_uni_dec_read_symbol_fastS(&rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ + /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ + + if (r < VAL_ESC) /* If symbol read corresponds to MSB */ + { + break; + } + + /* LSBs decoding */ + a += get_indice_1(st, lsbs_bit_pos--) << lev; + b += get_indice_1(st, lsbs_bit_pos--) << lev; + } + + if ((lsbs_bit_pos < -1 && r >= VAL_ESC) || (lev > 14)) + { + x[a1_i] = 0; + x[b1_i] = 0; + st->BER_detect = 1; + return 0; + } + + /* MSBs contributions */ + b1 = r >> 2; + a1 = r & 0x3; + a += a1 << lev; + b += b1 << lev; + + /* Add 2 LSB bits per bit-plane */ + rest_bits += 2 * lev; + /* Sign bits */ + rest_bits += min(a, 1); + rest_bits += min(b, 1); + + /* Update bitstream pointer */ + st->next_bit_pos = start_bit_pos + bits_tups + rc_uni_dec_virtual_finish(&rc_st_dec); + + /* Confirm that there is no overflow */ +#ifdef DEBUGGING + assert(st->next_bit_pos - start_bit_pos + rest_bits <= 0); +#endif + + /* Store decoded data */ + x[a1_i] = a; + x[b1_i] = b; + + /* Update context for next 2-tuple */ + if (p1 == p2) + { + /* peak-peak or hole-hole context */ + lev = esc_nb - 1; + + if (lev <= 0) + { + t = 1 + (a1 + b1) * (lev + 2); + } + else + { + t = 13 + lev; + } + + *ctx = (*ctx & 0xf) * 16 + t; + } + else + { + /* mixed context */ + + if (idx1 & 1) + { + /* update first context */ + c[p1] = update_mixed_context(c[p1], a); + } + + if (idx2 & 1) + { + /* update second context */ + c[p2] = update_mixed_context(c[p2], b); + } + } + } + + /* We don't need to finish because virtual_finish() already does the same */ + /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/ + + /* Check for bitstream errors */ + assert(rc_st_dec.bit_error_detected == 0); + + /* Cross-check: No overflow */ +#ifdef DEBUGGING + assert(k == lastnz); +#endif + + /* Decode signs */ + n = nt; + } + else /* if(!hm_cfg) */ + { + int16_t c, rateQ; + uint16_t s; + + /* Rate flag */ + if (nbbits > 400) + { + rateFlag = 2; + } + else + { + rateFlag = 0; + } + + /* Start Decoding */ + /* Initialize range decoder */ + rc_uni_dec_init(&rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits); /* (nbbits + 30) entries are read by the decoder */ + + nbbits_m2 = nbbits; + rest_bits = -nbbits_m2; + + t = 0; + s = 0; + + /* Main Loop through the 2-tuples */ + for (k = 0; k < lastnz; k += 2) + { + rateQ = rateFlag + (k > (nt_half)); + + /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/ + if ((t >= (1 << (NBITS_CONTEXT))) || lsbs_bit_pos <= 0) + { + st->BER_detect = 1; + return 0; + } + + a = b = 0; + esc_nb = 0; + r = 0; + + /* MSBs decoding */ + for (lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev) + { + esc_nb = min(lev, 3); + pki = ari_lookup_s17_LC[t + ((rateQ) << NBITS_CONTEXT) + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + r = rc_uni_dec_read_symbol_fastS(&rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ + /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ + + if (r < VAL_ESC) /* If symbol read corresponds to MSB */ + { + break; + } + + /* LSBs decoding */ + a += get_indice_1(st, lsbs_bit_pos--) << lev; + b += get_indice_1(st, lsbs_bit_pos--) << lev; + } + + if ((lsbs_bit_pos < -1 && r >= VAL_ESC) || (lev > 14)) + { + x[k + 0] = 0; + x[k + 1] = 0; + st->BER_detect = 1; + return 0; + } + + /* MSBs contributions */ + b1 = r >> 2; + a1 = r & 0x3; + a += a1 << lev; + b += b1 << lev; + + /* Add 2 LSB bits per bit-plane */ + rest_bits += 2 * lev; + /* Sign bits */ + rest_bits += min(a, 1); + rest_bits += min(b, 1); + + /* Update bitstream pointer */ + st->next_bit_pos = start_bit_pos + bits_tups + rc_uni_dec_virtual_finish(&rc_st_dec); + + /* Confirm that there is no overflow */ +#ifdef DEBUGGING + assert(st->next_bit_pos - start_bit_pos + rest_bits <= 0); +#endif + + /* Store decoded data */ + x[k + 0] = a; + x[k + 1] = b; + + /* Update context for next 2-tuple */ + if (esc_nb < 2) + { + c = 1 + ((a1 + b1) * (esc_nb + 1)); + } + else + { + c = 12 + esc_nb; + } + + s = s << 4; /*Shift old 4 bits*/ + s = s + c; /*replace last 4 bits*/ + t = s & 0xFF; + } + + /* Decode signs */ + n = lastnz; + } /* end of if(hm_cfg) */ + + for (k = 0; k < n; k++) + { + if (x[k] > 0) + { + x[k] *= 1 - 2 * get_next_indice_1(st); + } + } + + /* Decode Residual Q */ + resQBits = min(resQMaxBits, lsbs_bit_pos + 1 - st->next_bit_pos); + + for (k = 0; k < resQBits; ++k) + { + x[nt + k] = get_indice_1(st, lsbs_bit_pos - k); + } + + /* Set bitstream pointer to end of buffer */ + get_next_indice_tmp(st, (start_bit_pos + nbbits) - st->next_bit_pos); + return resQBits; } +#endif diff --git a/lib_dec/EvsRXlib.c b/lib_dec/EvsRXlib.c index 4de16cc..e715ff9 100644 --- a/lib_dec/EvsRXlib.c +++ b/lib_dec/EvsRXlib.c @@ -335,7 +335,7 @@ EVS_RX_GetSamples(EVS_RX_HANDLE hEvsRX, /* initialize, since this is needed within read_indices_from_djb_fx, to correctly set st->last_codec_mode */ st->ini_frame_fx = 0; st->prev_use_partial_copy = 0; - init_decoder_fx( st ); + init_decoder_fx( st, EVS_MONO); /* parse frame again because init_decoder() overwrites st->total_brate_fx */ read_indices_from_djb_fx( st, dataUnit->data, dataUnit->dataSize, @@ -518,7 +518,7 @@ EVS_RX_Close(EVS_RX_HANDLE* phRX ) return EVS_RX_NO_ERROR; } - destroy_decoder( (*phRX)->st ); + destroy_cldfb_decoder( (*phRX)->st ); IF( (*phRX)->hJBM ) { diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 0645cc7..c632e97 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -1,17 +1,29 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -#include "prot_fx.h" +#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" +/*---------------------------------------------------------------------* + * Local function prototypes + *---------------------------------------------------------------------*/ + +static Word16 FEC_phase_matching_fx(HQ_NBFEC_HANDLE st_fx, Word32* ImdctOut_fx, Word16* auOut_fx, Word16* OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB]); +static void FEC_phase_matching_nextgood_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word16* OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB],Word16 mean_en_high_fx); +static void FEC_phase_matching_burst_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word16* OldauOut_fx, Word16 OldauOut_pha_fx[2][N_LEAD_NB], Word16* prev_oldauOut_fx ); +static void Repetition_smoothing_nextgood_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word32* OldImdctOut_fx, Word16* OldauOut_fx, Word16 cur_data_use_flag, Word16 overlap_time); +static Word16 Repetition_smoothing_fx(const Word32* ImdctOut_fx, Word16* auOut_fx, Word32* OldImdctOut_fx, Word16* OldauOut_fx, const Word16 L, Word16* prev_oldauOut_fx, Word16 overlap_time ); +static void Smoothing_vector_scaledown_NB_fx(const Word16 OldauOutnoWin_fx[], const Word16 ImdctOutWin_fx[], const Word16 SmoothingWin_fx[], Word16 auOut_fx[], const Word16 ol_size); +static void Smoothing_vector_NB_fx(const Word16 OldauOutnoWin_fx[], const Word16 ImdctOutWin_fx[], const Word16 SmoothingWin_fx[], Word16 auOut_fx[], const Word16 ol_size); +static void Windowing_1st_NB_fx(Word16* ImdctOutWin_fx, const Word32* ImdctOut_fx, const Word16* win_fx, const Word16* smoothingWin_fx, Word16 smoothing_flag ); +static void Windowing_2nd_NB_fx(Word16* ImdctOutWin_fx, const Word32* ImdctOut_fx, const Word16* win_fx ); +static void Scaledown_fx(Word16 x[], Word16 y[], Word16 scale_v,const Word16 N ); +static void Next_good_after_burst_erasures_fx(const Word32* ImdctOut_fx, Word16* auOut_fx,Word16* OldauOut_fx, const Word16 ol_size); +static void common_overlapping_fx(Word16* auOut_fx, Word16* ImdctOutWin_fx, Word16* OldauOut_fx, Word16 end1, Word16 offset1, Word16 start2, Word16 end2, Word16 offset_i2, Word16 offset2); /*--------------------------------------------------------------------------* @@ -132,16 +144,20 @@ void HQ_FEC_processing_fx( Word32 norm_p_fx[MAX_SB_NB]; Word32 *norm_values_fx, *r_p_fx; Word16 energy_diff_fx; + HQ_NBFEC_HANDLE hHQ_nbfec; + HQ_DEC_HANDLE hHQ_core; + hHQ_nbfec = st_fx->hHQ_nbfec; + hHQ_core = st_fx->hHQ_core; /* Decide the start frame number for adaptive muting */ /* Normalized energy difference between the current frame and the moving average */ - tmp_fx = abs_s(sub(st_fx->energy_MA_Curr_fx[1], st_fx->energy_MA_Curr_fx[0])); + tmp_fx = abs_s(sub(hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0])); exp1 = sub(norm_s(tmp_fx), 1); - st_fx->energy_MA_Curr_fx[0] = s_max(st_fx->energy_MA_Curr_fx[0],1); + hHQ_nbfec->energy_MA_Curr_fx[0] = s_max(hHQ_nbfec->energy_MA_Curr_fx[0],1); move16(); - exp2 = norm_s(st_fx->energy_MA_Curr_fx[0]); - tmp_fx = div_s(shl(tmp_fx, exp1), shl(st_fx->energy_MA_Curr_fx[0], exp2));/*15 + exp1 - exp2*/ + exp2 = norm_s(hHQ_nbfec->energy_MA_Curr_fx[0]); + tmp_fx = div_s(shl(tmp_fx, exp1), shl(hHQ_nbfec->energy_MA_Curr_fx[0], exp2));/*15 + exp1 - exp2*/ energy_diff_fx = shl(tmp_fx, sub(sub(exp2, exp1), 5));/*10*/ test(); IF ((LT_16(energy_diff_fx, 1024))&&(is_transient==0)) /* First erasure frame */ @@ -170,7 +186,7 @@ void HQ_FEC_processing_fx( { FOR (i=0; i < output_frame; i++) { - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; + t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } } @@ -178,20 +194,20 @@ void HQ_FEC_processing_fx( { FOR (i=0; i < output_frame; i++) { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170);/*23170, 3dB, Q15*/ - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170);/*23170, 3dB, Q15*/ + t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } } /* Sign prediction in 4-dim bands up to 1.6 kHz*/ - IF (st_fx->old_is_transient_fx[1] == 0) + IF (hHQ_core->old_is_transient_fx[1] == 0) { - IF (st_fx->old_is_transient_fx[2] == 0) + IF (hHQ_core->old_is_transient_fx[2] == 0) { FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) { - IF (GE_16(st_fx->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES)) + IF (GE_16(hHQ_nbfec->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES)) { FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) { @@ -205,7 +221,7 @@ void HQ_FEC_processing_fx( { FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) { - IF (GE_16(st_fx->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES_TRANS)) + IF (GE_16(hHQ_nbfec->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES_TRANS)) { FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) { @@ -220,7 +236,7 @@ void HQ_FEC_processing_fx( { FOR (i = RANDOM_START*8; i < output_frame; i++) { - IF(Random(&st_fx->HQ_FEC_seed_fx) < 0) + IF(Random(&hHQ_nbfec->HQ_FEC_seed_fx) < 0) { t_audio_q_fx[i] = L_negate(t_audio_q_fx[i]); move32(); @@ -230,12 +246,12 @@ void HQ_FEC_processing_fx( } ELSE { - IF( st_fx->old_is_transient_fx[1] ) /* hangover */ + IF(hHQ_core->old_is_transient_fx[1] ) /* hangover */ { FOR (i=0; i < output_frame; i++) { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); + t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } } @@ -243,22 +259,22 @@ void HQ_FEC_processing_fx( { FOR (i = 0; i < RANDOM_START*8; i++) { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); + t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } FOR (i = RANDOM_START*8; i < output_frame; i++) { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); - IF (Random(&st_fx->HQ_FEC_seed_fx) < 0) + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); + IF (Random(&hHQ_nbfec->HQ_FEC_seed_fx) < 0) { - t_audio_q_fx[i] = L_negate(st_fx->old_coeffs_fx[i]); + t_audio_q_fx[i] = L_negate(hHQ_nbfec->old_coeffs_fx[i]); move32(); } ELSE { - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; + t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } } @@ -298,7 +314,7 @@ void HQ_FEC_processing_fx( /* Scaling */ FOR ( i=0; i < output_frame; i++ ) { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); + hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); move32(); } } @@ -339,7 +355,7 @@ void HQ_FEC_processing_fx( FOR ( j=0; jNorm_gain_fx[k++] = shl(tmp_fx, 1); + hHQ_nbfec->Norm_gain_fx[k++] = shl(tmp_fx, 1); move16(); } } @@ -348,7 +364,7 @@ void HQ_FEC_processing_fx( /* Scale down the last gain with the fixed gain(-3dB) */ FOR (j=0; jNorm_gain_fx[k] = mult_r(st_fx->Norm_gain_fx[k], 23170); + hHQ_nbfec->Norm_gain_fx[k] = mult_r(hHQ_nbfec->Norm_gain_fx[k], 23170); move16(); k++; } @@ -356,7 +372,7 @@ void HQ_FEC_processing_fx( } /* Scaling for core band */ - FEC_scaling_fx( st_fx->old_coeffs_fx, t_audio_q_fx, st_fx->Norm_gain_fx, &st_fx->HQ_FEC_seed_fx, nb_sfm, sfm_start, sfm_end ); + FEC_scaling_fx(hHQ_nbfec->old_coeffs_fx, t_audio_q_fx, hHQ_nbfec->Norm_gain_fx, &hHQ_nbfec->HQ_FEC_seed_fx, nb_sfm, sfm_start, sfm_end ); } @@ -391,41 +407,49 @@ void HQ_FEC_Mem_update_fx( Word32* norm_values_fx; Word32 L_tmp, tmp_energy_fx = 0, Max_coeff_fx; Word32 en_high_fx[MAX_SB_NB]; - - - IF (is_transient) - { - set16_fx(st_fx->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM); - set16_fx(st_fx->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM); - } - ELSE + HQ_NBFEC_HANDLE hHQ_nbfec; + HQ_DEC_HANDLE hHQ_core; + hHQ_nbfec = st_fx->hHQ_nbfec; + hHQ_core = st_fx->hHQ_core; +#ifdef ADD_IVAS_HQ_CODE_FEC + IF(EQ_16(output_frame, L_FRAME8k)) { - FOR (j = 0; j < HQ_FEC_SIGN_SFM; j++) - { - st_fx->prev_sign_switch_fx[j] = st_fx->prev_sign_switch_2_fx[j]; - move16(); - st_fx->prev_sign_switch_2_fx[j] = 0; - move16(); +#endif - FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) + IF (is_transient) + { + set16_fx(hHQ_nbfec->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM); + set16_fx(hHQ_nbfec->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM); + } + ELSE + { + FOR (j = 0; j < HQ_FEC_SIGN_SFM; j++) { - test(); - test(); - test(); - IF ((st_fx->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]>0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]<0) - || (st_fx->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]<0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]>0)) + hHQ_nbfec->prev_sign_switch_fx[j] = hHQ_nbfec->prev_sign_switch_2_fx[j]; + move16(); + hHQ_nbfec->prev_sign_switch_2_fx[j] = 0; + move16(); + + FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) { - st_fx->prev_sign_switch_fx[j] = add(st_fx->prev_sign_switch_fx[j], 1); - move16(); - st_fx->prev_sign_switch_2_fx[j] = add(st_fx->prev_sign_switch_2_fx[j], 1); - move16(); + test(); + test(); + test(); + IF ((hHQ_nbfec->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]>0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]<0) + || (hHQ_nbfec->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]<0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]>0)) + { + hHQ_nbfec->prev_sign_switch_fx[j] = add(hHQ_nbfec->prev_sign_switch_fx[j], 1); + move16(); + hHQ_nbfec->prev_sign_switch_2_fx[j] = add(hHQ_nbfec->prev_sign_switch_2_fx[j], 1); + move16(); + } } } } - } - +#ifndef ADD_IVAS_HQ_CODE_FEC IF(EQ_16(output_frame, L_FRAME8k)) { +#endif /* if LR MDCT core is used, recalculate norms from decoded MDCT spectrum (using code from hq_hr_enc_fx()) */ test(); IF ( ( EQ_16(hqswb_clas, HQ_HVQ))||(EQ_16(hq_core_type,LOW_RATE_HQ_CORE))) @@ -463,7 +487,7 @@ void HQ_FEC_Mem_update_fx( move16(); FOR (i=0; iynrm_values_fx[i][0]; + norm_values_fx = &hHQ_nbfec->ynrm_values_fx[i][0]; Copy32(norm_values_fx, &norm_values_fx[1], MAX_PGF-1); L_tmp = L_deposit_l(0); @@ -483,31 +507,31 @@ void HQ_FEC_Mem_update_fx( { FOR (j=1; jynrm_values_fx[i][j]=st_fx->ynrm_values_fx[i][0]; + hHQ_nbfec->ynrm_values_fx[i][j]= hHQ_nbfec->ynrm_values_fx[i][0]; move32(); } } } - set16_fx(st_fx->Norm_gain_fx, 32767, SFM_N_NB);/*15*/ + set16_fx(hHQ_nbfec->Norm_gain_fx, 32767, SFM_N_NB);/*15*/ /* st->energy_MA_Curr[1]=Energy of the current frame */ tmp_fx = inv_tbl_fx[nb_sfm]; move16();/*15*/ L_tmp = Mult_32_16(tmp_energy_fx, tmp_fx);/*8 + 15 - 15*/ - st_fx->energy_MA_Curr_fx[1] = extract_h(L_shl(L_tmp, 16-8)); + hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h(L_shl(L_tmp, 16-8)); /* Moving Average */ - st_fx->energy_MA_Curr_fx[0] = s_max(1,add(mult_r(26214, st_fx->energy_MA_Curr_fx[0]), mult_r(6554, st_fx->energy_MA_Curr_fx[1]))); + hHQ_nbfec->energy_MA_Curr_fx[0] = s_max(1,add(mult_r(26214, hHQ_nbfec->energy_MA_Curr_fx[0]), mult_r(6554, hHQ_nbfec->energy_MA_Curr_fx[1]))); /*st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); */ - st_fx->diff_energy_fx = abs_s(sub(st_fx->energy_MA_Curr_fx[1], st_fx->energy_MA_Curr_fx[0])); - exp1 = sub(norm_l(st_fx->diff_energy_fx), 1); - exp2 = norm_l(st_fx->energy_MA_Curr_fx[0]); - st_fx->diff_energy_fx = div_s(extract_h(L_shl(st_fx->diff_energy_fx, exp1)), extract_h(L_shl(st_fx->energy_MA_Curr_fx[0], exp2))); + hHQ_nbfec->diff_energy_fx = abs_s(sub(hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0])); + exp1 = sub(norm_l(hHQ_nbfec->diff_energy_fx), 1); + exp2 = norm_l(hHQ_nbfec->energy_MA_Curr_fx[0]); + hHQ_nbfec->diff_energy_fx = div_s(extract_h(L_shl(hHQ_nbfec->diff_energy_fx, exp1)), extract_h(L_shl(hHQ_nbfec->energy_MA_Curr_fx[0], exp2))); exp = add(15, sub(exp1, exp2)); - st_fx->diff_energy_fx = shl(st_fx->diff_energy_fx, sub(11, exp));/*11*/ + hHQ_nbfec->diff_energy_fx = shl(hHQ_nbfec->diff_energy_fx, sub(11, exp));/*11*/ /* Classify the stationary mode : 12% */ - IF (LT_16(st_fx->diff_energy_fx, ED_THRES_12P_fx)) + IF (LT_16(hHQ_nbfec->diff_energy_fx, ED_THRES_12P_fx)) { stat_mode_curr = 1; move16(); @@ -519,13 +543,13 @@ void HQ_FEC_Mem_update_fx( } /* Apply Hysteresis to prevent frequent mode changing */ - IF(EQ_16(st_fx->stat_mode_old_fx, stat_mode_curr)) + IF(EQ_16(hHQ_nbfec->stat_mode_old_fx, stat_mode_curr)) { - st_fx->stat_mode_out_fx = stat_mode_curr; + hHQ_nbfec->stat_mode_out_fx = stat_mode_curr; move16(); } - st_fx->stat_mode_old_fx = stat_mode_curr; + hHQ_nbfec->stat_mode_old_fx = stat_mode_curr; move16(); /* Find max. band index (Minimum value means maximum energy) */ @@ -571,7 +595,7 @@ void HQ_FEC_Mem_update_fx( FOR (j=0; j<2; j++) { /*en_high[i] += 0.5f*st->ynrm_values[i][j+1];*/ - en_high_fx[i] = L_add(en_high_fx[i], L_shr(st_fx->ynrm_values_fx[i][j+1], 1));/*Q12*/ move32(); + en_high_fx[i] = L_add(en_high_fx[i], L_shr(hHQ_nbfec->ynrm_values_fx[i][j+1], 1));/*Q12*/ move32(); } } @@ -581,8 +605,8 @@ void HQ_FEC_Mem_update_fx( { /* *mean_en_high += (float)(en_high[i]/st->ynrm_values[i][0]);*/ exp1 = sub(norm_l(en_high_fx[i]), 1); - exp2 = norm_l(st_fx->ynrm_values_fx[i][0]); - tmp_fx = div_s(extract_h(L_shl(en_high_fx[i], exp1)), extract_h(L_shl(st_fx->ynrm_values_fx[i][0], exp2))); + exp2 = norm_l(hHQ_nbfec->ynrm_values_fx[i][0]); + tmp_fx = div_s(extract_h(L_shl(en_high_fx[i], exp1)), extract_h(L_shl(hHQ_nbfec->ynrm_values_fx[i][0], exp2))); exp = add(15, sub(exp1, exp2)); *mean_en_high_fx = add(*mean_en_high_fx, shr(tmp_fx, sub(exp, 5))); } @@ -597,39 +621,39 @@ void HQ_FEC_Mem_update_fx( test(); test(); test(); - IF ((LT_16(Min_ind, 5))&&(LT_16(abs_s(sub(Min_ind,st_fx->old_Min_ind_fx)),2))&&(LT_16(st_fx->diff_energy_fx,ED_THRES_90P_fx))&&(!st_fx->bfi_fx)&&(!st_fx->prev_bfi_fx)&&(!st_fx->prev_old_bfi_fx) - &&(!is_transient)&&(!st_fx->old_is_transient_fx[1]) && (st_fx->prev_last_core_fx==HQ_CORE) && (st_fx->last_core_fx==HQ_CORE)) + IF ((LT_16(Min_ind, 5))&&(LT_16(abs_s(sub(Min_ind, hHQ_nbfec->old_Min_ind_fx)),2))&&(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_90P_fx))&&(!st_fx->bfi_fx)&&(!st_fx->prev_bfi_fx)&&(!st_fx->prev_old_bfi_fx) + &&(!is_transient)&&(!hHQ_core->old_is_transient_fx[1]) && (hHQ_nbfec->prev_last_core_fx==HQ_CORE) && (st_fx->last_core_fx==HQ_CORE)) { - st_fx->phase_mat_flag_fx = 1; + hHQ_nbfec->phase_mat_flag_fx = 1; move16(); test(); if ((Min_ind == 0)&&(LT_16(Max_ind, 3))) { - st_fx->phase_mat_flag_fx = 0; + hHQ_nbfec->phase_mat_flag_fx = 0; move16(); } } ELSE { - st_fx->phase_mat_flag_fx = 0; + hHQ_nbfec->phase_mat_flag_fx = 0; move16(); } - st_fx->old_Min_ind_fx = Min_ind; + hHQ_nbfec->old_Min_ind_fx = Min_ind; move16(); } FOR (i=0; i < L_FRAME8k; i++) { - st_fx->old_coeffs_fx[i] = t_audio_q_fx[i]; + hHQ_nbfec->old_coeffs_fx[i] = t_audio_q_fx[i]; move32(); } - st_fx->old_is_transient_fx[2] = st_fx->old_is_transient_fx[1]; + hHQ_core->old_is_transient_fx[2] = hHQ_core->old_is_transient_fx[1]; move16(); - st_fx->old_is_transient_fx[1] = st_fx->old_is_transient_fx[0]; + hHQ_core->old_is_transient_fx[1] = hHQ_core->old_is_transient_fx[0]; move16(); - st_fx->old_is_transient_fx[0] = is_transient; + hHQ_core->old_is_transient_fx[0] = is_transient; move16(); return; @@ -835,8 +859,8 @@ static Word16 Search_Max_Corr_fx( return pos; } -Word16 FEC_phase_matching_fx( - Decoder_State_fx *st_fx, /* i : Decoder State */ +static Word16 FEC_phase_matching_fx( + HQ_NBFEC_HANDLE st_fx, /* i : Decoder State */ Word32 *ImdctOut_fx, /* i : input */ Word16 *auOut_fx, /* o : output audio */ Word16 *OldauOut_fx, @@ -955,7 +979,7 @@ Word16 FEC_phase_matching_fx( return 0; } -void FEC_phase_matching_nextgood_fx( +static void FEC_phase_matching_nextgood_fx( const Word32 *ImdctOut_fx, /* i : input */ Word16 *auOut_fx, /* o : output audio */ Word16 *OldauOut_fx, /* i/o: audio from previous frame */ @@ -1025,7 +1049,7 @@ void FEC_phase_matching_nextgood_fx( return; } -void FEC_phase_matching_burst_fx( +static void FEC_phase_matching_burst_fx( const Word32 *ImdctOut_fx, /* i : input */ Word16 *auOut_fx, /* o : output audio */ Word16 *OldauOut_fx, /* i/o: audio from previous frame */ @@ -1094,7 +1118,7 @@ void FEC_phase_matching_burst_fx( return; } -void Repetition_smoothing_nextgood_fx( +static void Repetition_smoothing_nextgood_fx( const Word32 *ImdctOut_fx, /* i : input */ Word16 *auOut_fx, /* o : output audio */ Word32 *OldImdctOut_fx, /* i : input */ @@ -1186,7 +1210,7 @@ void Repetition_smoothing_nextgood_fx( return; } -Word16 Repetition_smoothing_fx( +static Word16 Repetition_smoothing_fx( const Word32 *ImdctOut_fx, /* i : input */ Word16 *auOut_fx, /* o : output audio */ Word32 *OldImdctOut_fx, /* i : input */ @@ -1251,7 +1275,7 @@ Word16 Repetition_smoothing_fx( return 0; } -void common_overlapping_fx( +static void common_overlapping_fx( Word16 *auOut_fx, /* i : Input */ Word16 *ImdctOutWin_fx, /* o : Output */ Word16 *OldauOut_fx, /* i : Window */ @@ -1283,7 +1307,7 @@ void common_overlapping_fx( } -void Smoothing_vector_NB_fx( +static void Smoothing_vector_NB_fx( const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ const Word16 SmoothingWin_fx[], /* i : Smoothing window */ @@ -1306,7 +1330,7 @@ void Smoothing_vector_NB_fx( } -void Windowing_1st_NB_fx( +static void Windowing_1st_NB_fx( Word16 *ImdctOutWin_fx, /* o : Output */ const Word32 *ImdctOut_fx, /* i : Input */ const Word16 *win_fx, /* i : Window */ @@ -1354,7 +1378,7 @@ void Windowing_1st_NB_fx( return; } -void Windowing_2nd_NB_fx( +static void Windowing_2nd_NB_fx( Word16 *ImdctOutWin_fx, /* o : Output */ const Word32 *ImdctOut_fx, /* i : Input */ const Word16 *win_fx /* i : Window */ @@ -1388,7 +1412,7 @@ void Windowing_2nd_NB_fx( return; } -void Smoothing_vector_scaledown_NB_fx( +static void Smoothing_vector_scaledown_NB_fx( const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ const Word16 SmoothingWin_fx[], /* i : Smoothing window */ @@ -1413,7 +1437,7 @@ void Smoothing_vector_scaledown_NB_fx( } -void Scaledown_fx( +static void Scaledown_fx( Word16 x[], /* i : Input vector */ Word16 y[], /* o : Output vector that contains vector 1 .* vector 2 */ Word16 scale_v, /*Q15 */ @@ -1440,10 +1464,15 @@ void time_domain_FEC_HQ_fx( Word16 *Q_synth ) { - IF(st_fx->Q_old_wtda != 0) + HQ_NBFEC_HANDLE hHQ_nbfec; + HQ_DEC_HANDLE hHQ_core; + hHQ_nbfec = st_fx->hHQ_nbfec; + hHQ_core = st_fx->hHQ_core; + + IF(hHQ_core->Q_old_wtda != 0) { - Scale_sig(st_fx->old_out_fx, output_frame, negate(st_fx->Q_old_wtda)); - st_fx->Q_old_wtda = 0; + Scale_sig(hHQ_core->old_out_fx, output_frame, negate(hHQ_core->Q_old_wtda)); + hHQ_core->Q_old_wtda = 0; move16(); } @@ -1453,36 +1482,36 @@ void time_domain_FEC_HQ_fx( test(); test(); test(); - IF( (EQ_16(st_fx->nbLostCmpt, 1))&&(EQ_16(st_fx->phase_mat_flag_fx,1))&&(EQ_16(st_fx->phase_mat_next_fx,0))) + IF( (EQ_16(st_fx->nbLostCmpt, 1))&&(EQ_16(hHQ_nbfec->phase_mat_flag_fx,1))&&(EQ_16(hHQ_nbfec->phase_mat_next_fx,0))) { - IF (FEC_phase_matching_fx(st_fx, wtda_audio_fx, out_fx, st_fx->old_out_fx, st_fx->old_out_pha_fx) ) + IF (FEC_phase_matching_fx(hHQ_nbfec, wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx) ) { /* window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 ); */ - window_ola_fx(wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); - st_fx->phase_mat_next_fx = 0; + window_ola_fx(wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); + hHQ_nbfec->phase_mat_next_fx = 0; move16(); } ELSE { - st_fx->phase_mat_next_fx = 1; + hHQ_nbfec->phase_mat_next_fx = 1; move16(); *Q_synth = 0; move16(); } } - ELSE IF((EQ_16(st_fx->prev_bfi_fx, 1))&&(st_fx->bfi_fx==0)&&(EQ_16(st_fx->phase_mat_next_fx,1))) + ELSE IF((EQ_16(st_fx->prev_bfi_fx, 1))&&(st_fx->bfi_fx==0)&&(EQ_16(hHQ_nbfec->phase_mat_next_fx,1))) { - FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, st_fx->old_out_fx, st_fx->old_out_pha_fx, mean_en_high_fx); + FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, mean_en_high_fx); - st_fx->phase_mat_next_fx = 0; + hHQ_nbfec->phase_mat_next_fx = 0; move16(); *Q_synth = 0; move16(); } - ELSE IF((EQ_16(st_fx->prev_bfi_fx, 1))&&(EQ_16(st_fx->bfi_fx,1))&&(EQ_16(st_fx->phase_mat_next_fx,1))) + ELSE IF((EQ_16(st_fx->prev_bfi_fx, 1))&&(EQ_16(st_fx->bfi_fx,1))&&(EQ_16(hHQ_nbfec->phase_mat_next_fx,1))) { - FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, st_fx->old_out_fx, st_fx->old_out_pha_fx, st_fx->prev_oldauOut_fx); - st_fx->phase_mat_next_fx = 1; + FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, hHQ_nbfec->prev_oldauOut_fx); + hHQ_nbfec->phase_mat_next_fx = 1; move16(); *Q_synth = 0; move16(); @@ -1494,7 +1523,7 @@ void time_domain_FEC_HQ_fx( IF (st_fx->bfi_fx == 0 && EQ_16(st_fx->prev_bfi_fx, 1)) { test(); - IF((EQ_16(st_fx->stat_mode_out_fx, 1))||(LT_16(st_fx->diff_energy_fx,ED_THRES_50P_fx)))/* Q11 */ + IF((EQ_16(hHQ_nbfec->stat_mode_out_fx, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx)))/* Q11 */ { Word16 tmp; @@ -1503,34 +1532,34 @@ void time_domain_FEC_HQ_fx( { tmp = 1; } - Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, st_fx->oldIMDCTout_fx, st_fx->old_out_fx, tmp, N_LEAD_NB); + Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, tmp, N_LEAD_NB); *Q_synth = 0; move16(); } ELSE IF(GT_16(st_fx->old_bfi_cnt_fx, 1)) { - Next_good_after_burst_erasures_fx( wtda_audio_fx, out_fx, st_fx->old_out_fx, N_LEAD_NB ); + Next_good_after_burst_erasures_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, N_LEAD_NB ); *Q_synth = 0; move16(); } ELSE { /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0); */ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi_fx, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); } } ELSE /* if(st->bfi_fx == 1) */ { test(); - IF( (EQ_16(st_fx->stat_mode_out_fx, 1))||(LT_16(st_fx->diff_energy_fx,ED_THRES_50P_fx))) + IF( (EQ_16(hHQ_nbfec->stat_mode_out_fx, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx))) { /* if( window_ola_bfi( wtda_audio, out, st->oldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) */ - IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, st_fx->oldIMDCTout_fx, st_fx->old_out_fx, output_frame, st_fx->prev_oldauOut_fx, N_LEAD_NB) ) + IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, output_frame, hHQ_nbfec->prev_oldauOut_fx, N_LEAD_NB) ) { /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0);*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi_fx, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); } ELSE { @@ -1541,18 +1570,18 @@ void time_domain_FEC_HQ_fx( ELSE { /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 );*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi_fx, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); } } - st_fx->phase_mat_next_fx = 0; + hHQ_nbfec->phase_mat_next_fx = 0; move16(); } return; } -void Next_good_after_burst_erasures_fx( +static void Next_good_after_burst_erasures_fx( const Word32 *ImdctOut_fx, Word16 *auOut_fx, Word16 *OldauOut_fx, @@ -1588,3 +1617,89 @@ void Next_good_after_burst_erasures_fx( return; } +#ifdef ADD_IVAS_HQ_CODE_FEC +/*-------------------------------------------------------------------------- + * save_synthesis_hq_fec() + * + * Save synthesis for HQ FEC + *-------------------------------------------------------------------------*/ + +void save_synthesis_hq_fec( + Decoder_State* st, /* i/o: decoder state structure */ + const float* output, /* i : decoded synthesis */ + const int16_t output_frame, /* i : decoded synthesis */ + CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */ +) +{ + int16_t post_hq_delay; + + switch (st->element_mode) + { + case EVS_MONO: + post_hq_delay = NS2SA(st->output_Fs, POST_HQ_DELAY_NS); + break; + case IVAS_SCE: + post_hq_delay = NS2SA(st->output_Fs, DELAY_CLDFB_NS); + break; + case IVAS_CPE_DFT: + if (hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF) + { + post_hq_delay = NS2SA(st->output_Fs, DELAY_CLDFB_NS); + } + else + { + post_hq_delay = 0; + } + break; + default: + post_hq_delay = 0; + break; + } + + + if ((st->codec_mode == MODE1 && st->hTcxDec != NULL) && ((st->core == ACELP_CORE && !(st->bfi == 1 && st->con_tcx == 1)) || st->core == HQ_CORE)) + { + mvr2r(st->hTcxDec->synth_history + output_frame, st->hTcxDec->synth_history, output_frame - post_hq_delay + NS2SA(st->output_Fs, PH_ECU_MEM_NS)); + mvr2r(output, st->hTcxDec->old_synthFB + output_frame - post_hq_delay, output_frame); + + if (st->element_mode == EVS_MONO) + { + /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill + this buffer are not available for all cases, the impact on the output is limited */ + set_f(st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, 0.f, post_hq_delay); + if (output_frame >= L_FRAME16k) + { + mvr2r(st->prev_synth_buffer, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); + } + else + { + mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + } + + if (st->core != ACELP_CORE) + { + if (output_frame >= L_FRAME16k) + { + mvr2r(st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_CLDFB_NS), NS2SA(st->output_Fs, DELAY_CLDFB_NS)); + mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + } + else + { + mvr2r(st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA(st->output_Fs, DELAY_CLDFB_NS)); + mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + } + } + } + else + { + if (st->core != ACELP_CORE) + { + mvr2r(st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, post_hq_delay); + mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + } + } + } + + return; +} +#endif \ No newline at end of file diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 64a9168..e01313a 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "rom_dec_fx.h" /* Static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" -#include "stl.h" #include "basop_util.h" /*---------------------------------------------------------------------* @@ -44,6 +44,14 @@ #define PFIND_SENS_FX 31785 /* 0.97 in Q15 */ #define CMPLMNT_PFIND_SENS_FX 983 /* (1.0 - pfind_sen) in Q15 */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE +#define DELTA_CORR_F0_INT 2 /* Constant controls the bin range where Jacobsen is used */ +#define ST_PFIND_SENS 0.93f /* peakfinder sensitivity */ +#define L_PROT_NS 32000000L /* Prototype frame length in nanoseconds (32 ms) */ +#define PH_ECU_CORR_LIMIT 0.85f /* Correlation limit for IVAS Phase ECU activation */ +#define PH_ECU_N_LIMIT 56 /* fec_alg analysis frame limit for IVAS Phase ECU activation */ +#endif + #define FEC_HQ_ECU_POINT5 (0x4000) /* 0.5 in Q15. Prefix with FEC_HQ namespace to avoid naming conflict. */ #define FEC_HQ_ECU_ROOT2 (0x5a83) /* sqrt(2) in Q14 */ #define FEC_HQ_HAMM_A0 17695 /* 0.54 in Q15 */ @@ -57,26 +65,31 @@ static Word16 sqrt2ndOrder(const Word16); static void windowing(const Word16*, Word16*, const Word16*, const Word16, const Word16); static void windowing_ROM_optimized(const Word16*, Word16*, const Word16, const Word16, const Word16); static void fft_spec2_fx(const Word16 [], Word32 [], const Word16); -static void trans_ana_fx(const Word16*, Word16*, Word16*, Word16*, const Word16, const Word16, const Word16 - ,const Word16 - ,Word16*, Word16*, Word16*, Word16* - - ); -static void peakfinder_fx(const Word16*, const Word16, Word16*, Word16*, const Word16); +static void trans_ana_fx(const Word16*, Word16*, Word16*, Word16*, const Word16, const Word16, const Word16,const Word16,Word16*, Word16*, Word16*, Word16*); +static void peakfinder_fx(const Word16*, const Word16, Word16*, Word16*, const Word16 +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , const Word16 endpoints /* i : Flag to include endpoints in peak search */ +#endif + ); static Word16 imax_fx( const Word16 *, const Word16); -static void spec_ana_fx(const Word16*, Word16*, Word32*, Word16*, Word16*, const Word16, const Word16, Word16*); +static void spec_ana_fx(const Word16* prevsynth, Word16* plocs, Word32* plocsi, Word16* num_plocs, Word16* X_sav, const Word16 output_frame, const Word16 bwidth_fx, Word16* Q +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , const Word16 element_mode, Word16* noise_fac, const Word16 pcorr +#endif + ); static void subst_spec_fx(const Word16*, const Word32*, Word16*, const Word16, Word16*, const Word16*, const Word16, const Word16*, const Word16, Word16* - ,const Word16*, const Word16*, Word16, const Word16* - ); -Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F); - + ,const Word16*, const Word16*, Word16, const Word16*); +static Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F); +#ifdef IVAS_FEC_ECU_TO_COMPLETE +static float imax2_jacobsen_mag(const float* y_re, const float* y_im); +#endif /*------------------------------------------------------------------* * rand_phase() * * randomized phase in form of sin and cos components *------------------------------------------------------------------*/ -Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F) +static Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F) { const Word16 *sincos = sincos_t_ext_fx + 128; Word16 seed2 = own_random2_fx(seed); @@ -100,6 +113,74 @@ Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F) return seed2; } +#ifdef IVAS_FEC_ECU_TO_COMPLETE +/*----------------------------------------------------------------------------- + * imax2_jacobsen_mag() + * + * refine peak interpolation using jacobsen and periodic speca ana windows + *----------------------------------------------------------------------------*/ + + /*! r: The location, relative to the middle of the 3 given data point, of the maximum. (Q15)*/ +static float imax2_jacobsen_mag( + const float* y_re, /* i : The 3 given data points. real part order -1 0 1 */ + const float* y_im /* i : The 3 given data points. imag part order 1 0 -1 (from FFT) */ +) +{ + float posi; + const float* pY; + float y_m1_re, y_0_re, y_p1_re; + float y_m1_im, y_0_im, y_p1_im; + float N_re, N_im; + float D_re, D_im; + float numer, denom; + + /* Jacobsen estimates peak offset relative y_0 using + * X_m1 - X_p1 + * d = REAL ( ------------------- ) * c_jacob + * 2*X_0 - X_m1 -Xp1 + * + * Where c_jacob is a window dependent constant + */ +#define C_JACOB 1.1453f /* % assume 0.1875 hammrect window 'symmetric' */ + + /* Get the bin parameters into variables */ + pY = y_re; + y_m1_re = *pY++; + y_0_re = *pY++; + y_p1_re = *pY++; + + /* Same for imaginary parts - note reverse order from FFT */ + pY = y_im; + y_p1_im = *pY++; + y_0_im = *pY++; + y_m1_im = *pY++; + + /* prepare numerator real and imaginary parts*/ + N_re = y_m1_re - y_p1_re; + N_im = y_m1_im - y_p1_im; + + /* prepare denominator real and imaginary parts */ + + D_re = 2 * y_0_re - y_m1_re - y_p1_re; + D_im = 2 * y_0_im - y_m1_im - y_p1_im; + + /* REAL part of complex division */ + numer = N_re * D_re + N_im * D_im; + denom = D_re * D_re + D_im * D_im; + + test(); + if (numer != 0 && denom != 0) + { + posi = numer / denom * C_JACOB; + } + else + { + posi = 0; /* flat top, division is not possible choose center freq */ + } + + return posi; +} +#endif /*----------------------------------------------------------------------------- * fft_spec2_fx() @@ -501,6 +582,9 @@ static void peakfinder_fx( Word16 *plocs, /* o : the indices of the identified peaks in x0 Q0 */ Word16 *cInd, /* o : number of identified peaks Q0 */ const Word16 sel /* i : The amount above surrounding data for a peak to be identified */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ,const Word16 endpoints /* i : Flag to include endpoints in peak search */ +#endif ) { const Word16 *pX0; @@ -535,13 +619,24 @@ static void peakfinder_fx( pInd = indarr; pDx01 = dx0; pDx0 = pDx01 + 1; - *pX++ = *pX0++; - move16(); - *pInd++ = 0; - move16(); - len = 2; +#ifdef IVAS_FEC_ECU_TO_COMPLETE + len = 0; move16(); + IF(endpoints) +#endif + { + *pX++ = *pX0++; + move16(); + *pInd++ = 0; + move16(); + len = 2; + move16(); + } len0Minus2 = sub(len0, 2); +#ifdef IVAS_FEC_ECU_TO_COMPLETE + PMT("\nlen0Minus2 = sub(len0, 2) is it still correct if IVAS_FEC_ECU_TO_COMPLETE is activated\n") +#endif + FOR (i = 0; i < len0Minus2; i++) { IF (s_xor(*pDx01++, *pDx0++) < 0) /* Detect sign change. */ @@ -553,16 +648,25 @@ static void peakfinder_fx( } pX0++; } - *pInd = len0Minus1; - move16(); - *pX = *pX0; - move16(); - +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(endpoints) +#endif + { + *pInd = len0Minus1; + move16(); + *pX = *pX0; + move16(); + } /* x[] only has the peaks, valleys, and endpoints */ minimum_fx(x, len, &minMag); pInd = indarr; +#ifdef IVAS_FEC_ECU_TO_COMPLETE + test(); test(); + IF(GT_16(len, 2) || (!endpoints && (len > 0))) +#else IF (GT_16(len, 2)) +#endif { /* Set initial parameters for loop */ tempMag = minMag; @@ -573,45 +677,62 @@ static void peakfinder_fx( move16(); threshold = add(leftMin, sel); - /* Deal with first point a little differently since tacked it on - Calculate the sign of the derivative since we took the first point - on it does not necessarily alternate like the rest. */ - - /* The first point is larger or equal to the second */ - pX = x; - xAt0 = *pX++; - move16(); - xAt1 = *pX++; - move16(); - xAt2 = *pX--; /* After decrement, pX points to x[1]. */ move16(); - IF (GE_16(xAt0, xAt1)) +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(len > 0) +#endif { - ii = -1; + /* Deal with first point a little differently since tacked it on + Calculate the sign of the derivative since we took the first point + on it does not necessarily alternate like the rest. */ + + /* The first point is larger or equal to the second */ + pX = x; + xAt0 = *pX++; + move16(); + xAt1 = *pX++; move16(); - IF (GE_16(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ + xAt2 = *pX--; /* After decrement, pX points to x[1]. */ move16(); + IF(GE_16(xAt0, xAt1)) { - *pX = xAt0; /* x[1] = x[0] */ move16(); - tmp16 = *pInd++; + ii = -1; move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); + IF(GE_16(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ + { + *pX = xAt0; /* x[1] = x[0] */ move16(); + tmp16 = *pInd++; + move16(); + *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); + len = sub(len, 1); + } + pX--; /* After decrement, pX points to x[0]. */ } - pX--; /* After decrement, pX points to x[0]. */ + ELSE /* First point is smaller than the second */ + { + ii = 0; + IF(LT_16(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ + { + *pX = xAt0; /* x[1] = x[0] */ move16(); + tmp16 = *pInd++; + move16(); + *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); + len = sub(len, 1); + } + } + pX--; /* After decrement, pX points to either x[-1] or x[0]. */ } - ELSE /* First point is smaller than the second */ - { - ii = 0; - IF (LT_16(xAt1, xAt2)) /* x[1] is not extremum -> overwrite with x[0] */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ELSE + { PMTE () + ii = -1; /* First point is a peak */ + if (len >= 2) { - *pX = xAt0; /* x[1] = x[0] */ move16(); - tmp16 = *pInd++; - move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); + if (x[1] >= x[0]) + { + ii = 0; /* First point is a valley, skip it */ + } } } - pX--; /* After decrement, pX points to either x[-1] or x[0]. */ - +#endif *cInd = 0; move16(); /*Loop through extrema which should be peaks and then valleys*/ @@ -714,28 +835,40 @@ static void peakfinder_fx( } ELSE /* This is a monotone function where an endpoint is the only peak */ { - xInd = 1; - move16(); - if (GT_16(x[0], x[1])) +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(endpoints) +#endif { - xInd = 0; + xInd = 1; move16(); - } + if (GT_16(x[0], x[1])) + { + xInd = 0; + move16(); + } - peakMag[0] = x[xInd]; - move16(); - IF (GT_16(peakMag[0], add(minMag, sel))) - { - plocs[0] = *(indarr + xInd); - move16(); - *cInd = 1; + peakMag[0] = x[xInd]; move16(); + IF(GT_16(peakMag[0], add(minMag, sel))) + { + plocs[0] = *(indarr + xInd); + move16(); + *cInd = 1; + move16(); + } + ELSE + { + *cInd = 0; + move16(); + } } +#ifdef IVAS_FEC_ECU_TO_COMPLETE ELSE - { + {/* Input constant or all zeros -- no peaks found */ *cInd = 0; move16(); } +#endif } } @@ -842,24 +975,29 @@ static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given * Spectral analysis *-----------------------------------------------------------------------------*/ static void spec_ana_fx( - const Word16 *prevsynth, /* i : Input signal */ - Word16 *plocs, /* o : The indicies of the identified peaks Q0 */ - Word32 *plocsi, /* o : Interpolated positions of the identified peaks Q16 */ - Word16 *num_plocs, /* o : Number of identified peaks Q0 */ - Word16 *X_sav, /* o : Stored fft spectrum */ - const Word16 output_frame, /* i : Frame length Q0 */ - const Word16 bwidth_fx, /* i : Encoded bandwidth index Q0 */ - Word16 *Q /* o : Q value of the fft spectrum */ + const Word16* prevsynth, /* i : Input signal */ + Word16* plocs, /* o : The indicies of the identified peaks Q0 */ + Word32* plocsi, /* o : Interpolated positions of the identified peaks Q16 */ + Word16* num_plocs, /* o : Number of identified peaks Q0 */ + Word16* X_sav, /* o : Stored fft spectrum */ + const Word16 output_frame, /* i : Frame length Q0 */ + const Word16 bwidth_fx, /* i : Encoded bandwidth index Q0 */ + Word16* Q /* o : Q value of the fft spectrum */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , const Word16 element_mode, /* i : IVAS element mode */ + Word16* noise_fac, /* o : for few peaks zeroing valleys decision making */ + const Word16 pcorr +#endif ) { - Word16 Lprot, LprotLog2Minus1=0, hamm_len2=0, Lprot2, Lprot2_1, m, n; - const Word16 *pFftTbl = NULL; + Word16 Lprot, LprotLog2Minus1 = 0, hamm_len2 = 0, Lprot2, Lprot2_1, m, n; + const Word16* pFftTbl = NULL; Word16 xfp[Lprot48k]; - Word32 magSq[Lprot48k/2+1], *pMagSq; - Word16 *pXfp, *pXfp1, *pXsav, *pPlocs; + Word32 magSq[Lprot48k / 2 + 1], * pMagSq; + Word16* pXfp, * pXfp1, * pXsav, * pPlocs; Word16 Xmax, Xmin, sel, man, expo, expoBy2; Word16 sinTblOffset, rectLength, fraction, special; - Word32 *pPlocsi; + Word32* pPlocsi; Word32 acc; Word16 stop_band_start; Word16 stop_band_length; @@ -868,12 +1006,12 @@ static void spec_ana_fx( sinTblOffset = 0; - IF (EQ_16(output_frame, L_FRAME48k)) + IF(EQ_16(output_frame, L_FRAME48k)) { Lprot = Lprot48k; /* 1536=(2*output_frame)*1024/1280; */ move16(); hamm_len2 = Lprot_hamm_len2_48k; /* half Hamming window = 288 */ move16(); } - ELSE IF (EQ_16(output_frame, L_FRAME32k)) + ELSE IF(EQ_16(output_frame, L_FRAME32k)) { Lprot = Lprot32k; /* 1024 */ move16(); sinTblOffset = 4; @@ -895,39 +1033,77 @@ static void spec_ana_fx( Lprot2 = shr(Lprot, 1); Lprot2_1 = add(Lprot2, 1); - rectLength = sub(Lprot, shl(hamm_len2,1)); /* The length of the rectangular portion of the Hamming-Rectangular window. */ + rectLength = sub(Lprot, shl(hamm_len2, 1)); /* The length of the rectangular portion of the Hamming-Rectangular window. */ *Q = s_max(0, sub(Exp16Array(Lprot, prevsynth), 1)); move16(); Copy_Scale_sig(prevsynth, xfp, Lprot, *Q); - IF (EQ_16(output_frame, L_FRAME48k)) + IF(EQ_16(output_frame, L_FRAME48k)) { /* Apply hamming-rect window */ - windowing(xfp, xfp, w_hamm_sana48k_2_fx, rectLength, hamm_len2); - /* Spectrum */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(EQ_16(element_mode, EVS_MONO)) +#endif + { + windowing(xfp, xfp, w_hamm_sana48k_2_fx, rectLength, hamm_len2); + } +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ELSE + { + PMTE() + //window_corr = w_hamm[0]; + //window_corr_step = w_hamm[0] / hamm_len2; + //for (i = 0; i < hamm_len2; i++) + //{ + // xfp[i] = prevsynth[i] * (w_hamm[i] - window_corr); + // xfp[Lprot - i - 1] = prevsynth[Lprot - i - 1] * (w_hamm[i] - window_corr); + // window_corr -= window_corr_step; + //} + } +#endif + /* Spectrum */ fft3_fx(xfp, xfp, Lprot); } ELSE { +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(EQ_16(element_mode, EVS_MONO)) +#endif + { /* Apply hamming-rect window */ windowing_ROM_optimized(xfp, xfp, sinTblOffset, rectLength, hamm_len2); - /* Spectrum */ + } +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ELSE + { + PMTE() + //window_corr = w_hamm[0]; + //window_corr_step = w_hamm[0] / hamm_len2; + //for (i = 0; i < hamm_len2; i++) + //{ + // xfp[i] = prevsynth[i] * (w_hamm[i] - window_corr); + // xfp[Lprot - i - 1] = prevsynth[Lprot - i - 1] * (w_hamm[i] - window_corr); + // window_corr -= window_corr_step; + //} + } +#endif + /* Spectrum */ r_fft_fx_lc(pFftTbl, Lprot, Lprot2, LprotLog2Minus1, xfp, xfp, 1); } - /* Apply zeroing of non-coded FFT spectrum */ - IF (GT_16(output_frame, inner_frame_tbl_fx[bwidth_fx])) + /* Apply zeroing of non-coded FFT spectrum */ + IF(GT_16(output_frame, inner_frame_tbl_fx[bwidth_fx])) { stop_band_start = shl(128, bwidth_fx); - stop_band_length = sub(Lprot, shl(stop_band_start,1)); + stop_band_length = sub(Lprot, shl(stop_band_start, 1)); stop_band_start = add(stop_band_start, 1); - set16_fx( xfp + stop_band_start, 0, stop_band_length ); + set16_fx(xfp + stop_band_start, 0, stop_band_length); } pXfp = xfp; pXsav = X_sav; - FOR (m = 0; m < Lprot; m++) + FOR(m = 0; m < Lprot; m++) { *pXsav++ = *pXfp++; move16(); @@ -939,9 +1115,9 @@ static void spec_ana_fx( /* Compute xfp[m] = sqrt(magSq[m]) */ pXfp = xfp; pMagSq = magSq; - FOR (m = 0; m < Lprot2_1; m++) + FOR(m = 0; m < Lprot2_1; m++) { - IF (*pMagSq == 0) + IF(*pMagSq == 0) { *pXfp++ = extract_l(*pMagSq++); /* magSq[] is zero */ } @@ -951,7 +1127,7 @@ static void spec_ana_fx( man = extract_h(L_shl(*pMagSq++, expo)); /* mantissa */ man = sqrt2ndOrder(man); expoBy2 = shr(expo, 1); /* Divided by 2-- square root operation. */ - IF (s_and(expo,1) == 0) /* Check even or odd. */ + IF(s_and(expo,1) == 0) /* Check even or odd. */ { man = mult_r(man,FEC_HQ_ECU_ROOT2); /* FEC_HQ_ECU_ROOT2 is sqrt(2) in Q14 */ expoBy2 = sub(expoBy2, 1); @@ -964,51 +1140,178 @@ static void spec_ana_fx( /* Find maximum and minimum. */ maximum_fx(xfp, Lprot2_1, &Xmax); minimum_fx(xfp, Lprot2_1, &Xmin); - sel = mult_r(sub(Xmax, Xmin), CMPLMNT_PFIND_SENS_FX); - peakfinder_fx(xfp, Lprot2_1, plocs, num_plocs, sel); +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(EQ_16(element_mode, EVS_MONO)) +#endif + { + sel = mult_r(sub(Xmax, Xmin), CMPLMNT_PFIND_SENS_FX); + } +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ELSE + { + sel = (Xmax - Xmin) * (1.0f - ST_PFIND_SENS); + } +#endif + peakfinder_fx(xfp, Lprot2_1, plocs, num_plocs, sel +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , endpoints +#endif + ); + - /* Refine peaks */ - pPlocsi = plocsi; - pPlocs = plocs; - n = sub(*num_plocs, 1); /* -1 so as to exclude the very last peak. */ - /* Special case-- The very 1st peak if it is at 0 index position */ - IF (EQ_16(*pPlocs, 0)) /* Only the very 1st peak is possible the peak at 0 index position. */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + /* Currently not the pitch correlation but some LF correlation */ + if (element_mode != EVS_MONO && *num_plocs > 50 && pcorr < 0.6f) { - fraction = imax_fx(xfp, -1); /* -1 signifies special left edge case. */ - acc = L_deposit_h(*pPlocs++); /* N.B., (*pPlocs) must be zero here. */ - *pPlocsi++ = L_mac(acc, fraction, 1); - move32();/* in Q16 */ - n = sub(n, 1); /* This special case is taken care of-- one less to go */ + *num_plocs = 0; } - /* All peaks except the very last peak but including the very 1st one if it has not been taken care of. */ - pXfp1 = xfp - 1; - FOR (m = 0; m < n; m++) /* Loop through up to the last but one peak. (The last one is excluded.) */ + + IF(EQ_16(element_mode, EVS_MONO)) +#endif { - pXfp = pXfp1 + *pPlocs; - fraction = imax_fx(pXfp, 0); /* in Q15 */ - acc = L_deposit_h(*pPlocs++); - *pPlocsi++ = L_mac(acc, fraction, 1); - move32();/* in Q16. Append the fractional part to the integral part. */ + + /* Refine peaks */ + pPlocsi = plocsi; + pPlocs = plocs; + n = sub(*num_plocs, 1); /* -1 so as to exclude the very last peak. */ + /* Special case-- The very 1st peak if it is at 0 index position */ + IF(EQ_16(*pPlocs, 0)) /* Only the very 1st peak is possible the peak at 0 index position. */ + { + fraction = imax_fx(xfp, -1); /* -1 signifies special left edge case. */ + acc = L_deposit_h(*pPlocs++); /* N.B., (*pPlocs) must be zero here. */ + *pPlocsi++ = L_mac(acc, fraction, 1); + move32();/* in Q16 */ + n = sub(n, 1); /* This special case is taken care of-- one less to go */ + } + /* All peaks except the very last peak but including the very 1st one if it has not been taken care of. */ + pXfp1 = xfp - 1; + FOR(m = 0; m < n; m++) /* Loop through up to the last but one peak. (The last one is excluded.) */ + { + pXfp = pXfp1 + *pPlocs; + fraction = imax_fx(pXfp, 0); /* in Q15 */ + acc = L_deposit_h(*pPlocs++); + *pPlocsi++ = L_mac(acc, fraction, 1); + move32();/* in Q16. Append the fractional part to the integral part. */ + } + IF(n >= 0) + { + /* Special case-- The very last peak */ + pXfp = pXfp1 + *pPlocs; + IF(EQ_16(*pPlocs, Lprot2)) /* Only the very last peak is possible the peak at Lprot2 index position. */ + { + pXfp--; /* Special case needs extra decrement */ + special = 1; /* Signify special right edge case. */ move16(); + } + ELSE + { + special = 0; + move16(); + } + fraction = imax_fx(pXfp, special); /* in Q15 */ + acc = L_deposit_h(*pPlocs); + *pPlocsi = L_mac(acc, fraction, 1); + move32();/* in Q16. Append the fractional part to the integral part. */ + } } - IF ( n >= 0 ) +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ELSE { - /* Special case-- The very last peak */ - pXfp = pXfp1 + *pPlocs; - IF (EQ_16(*pPlocs, Lprot2)) /* Only the very last peak is possible the peak at Lprot2 index position. */ + Lprot2p1 = Lprot / 2 + 1; + + /* Refine peaks */ + pPlocsi = plocsi; + pPlocs = plocs; + n = *num_plocs; /* number of peaks to process */ + + /* Special case-- The very 1st peak if it is at 0 index position (DC) */ + /* With DELTA_CORR_F0_INT == 2 one needs to handle both *pPlocs==0 and *pPlocs==1 */ + if (n > 0 && *pPlocs == 0) /* Very 1st peak position possible to have a peak at 0/DC index position. */ { - pXfp--; /* Special case needs extra decrement */ - special = 1; /* Signify special right edge case. */ move16(); + *pPlocsi++ = *pPlocs + imax_pos(&xfp[*pPlocs]); + pPlocs++; + n = n - 1; } - ELSE + + if (n > 0 && *pPlocs == 1) /* Also 2nd peak position uses DC which makes jacobsen unsuitable. */ { - special = 0; - move16(); + *pPlocsi++ = *pPlocs - 1 + imax_pos(&xfp[*pPlocs - 1]); + currPlocs = *pPlocs++; + n = n - 1; + } + + /* All remaining peaks except the very last two possible integer positions */ + currPlocs = *pPlocs++; + endPlocs = Lprot2p1 - DELTA_CORR_F0_INT; /* last *pPlocs position for Jacobsen */ + + /* precompute number of turns based on endpoint integer location and make into a proper for loop */ + if (n > 0) + { + nJacob = n; + if (sub(endPlocs, plocs[sub(*num_plocs, 1)]) <= 0) + { + nJacob = sub(nJacob, 1); + } + + for (k = 0; k < nJacob; k++) + { + *pPlocsi++ = currPlocs + imax2_jacobsen_mag(&(X_sav[currPlocs - 1]), &(X_sav[Lprot - 1 - currPlocs])); + currPlocs = *pPlocs++; + } + n = n - nJacob; + } + + /* At this point there should at most two plocs left to process */ + /* the position before fs/2 and fs/2 both use the same magnitude points */ + if (n > 0) + { + /* [ . . . . . . . ] Lprot/2+1 positions */ + /* | | | */ + /* 0 (Lprot/2-2) (Lprot/2) */ + + if (currPlocs == (Lprot2p1 - DELTA_CORR_F0_INT)) /* Also 2nd last peak position uses fs/2 which makes jacobsen less suitable. */ + { + *pPlocsi++ = currPlocs - 1 + imax_pos(&xfp[currPlocs - 1]); + currPlocs = *pPlocs++; + n = n - 1; + } + + /* Here the only remaining point would be a fs/2 plocs */ + /* pXfp = xfp + sub(Lprot2,1); already set just a reminder where it + * whould point */ + if (n > 0) /* fs/2 which makes special case . */ + { + *pPlocsi++ = currPlocs - 2 + imax_pos(&xfp[currPlocs - 2]); + currPlocs = *pPlocs++; + n = n - 1; + } + } + + /* For few peaks decide noise floor attenuation */ + if (*num_plocs < 3 && *num_plocs > 0) + { + sig = sum_f(xfp, Lprot2_1) + EPSILON; + + /*excluding peaks and neighboring bins*/ + for (i = 0; i < *num_plocs; i++) + { + st_point = max(0, plocs[i] - DELTA_CORR); + end_point = min(Lprot2_1 - 1, plocs[i] + DELTA_CORR); + set_f(&xfp[st_point], 0.0f, end_point - st_point + 1); + } + noise = sum_f(xfp, Lprot2_1) + EPSILON; + nsr = noise / sig; + + if (nsr < 0.03f) + { + *noise_fac = 0.5f; + } + else + { + *noise_fac = 1.0f; + } } - fraction = imax_fx(pXfp, special); /* in Q15 */ - acc = L_deposit_h(*pPlocs); - *pPlocsi = L_mac(acc, fraction, 1); - move32();/* in Q16. Append the fractional part to the integral part. */ } +#endif } /*-------------------------------------------------------------------* @@ -1032,6 +1335,11 @@ static void subst_spec_fx( const Word16 *beta, /* i : Magnitude modification factors for fade to average Q15 */ Word16 beta_mute, /* i : Factor for long-term mute Q15 */ const Word16 *Xavg /* i : Frequency group averages to fade to Q0 */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ,const Word16 element_mode, /* i : IVAS element mode */ + const Word16 ph_ecu_lookahead, /* i : Phase ECU lookahead */ + const Word16 noise_fac /* i : noise factor */ +#endif ) { Word16 Xph_short; @@ -1052,7 +1360,11 @@ static void subst_spec_fx( Word16 alpha_local; Word16 beta_local; Word16 expo; - +#ifdef IVAS_FEC_ECU_TO_COMPLETE + Word16 one_peak_flag_mask; + Word16 alpha_local; + Word16 beta_local; +#endif Word16 mag_chg_local; /*for peak attenuation in burst */ Lprot = 512; @@ -1101,7 +1413,21 @@ static void subst_spec_fx( *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ move32(); } } - +#ifdef IVAS_FEC_ECU_TO_COMPLETE + one_peak_flag_mask = 1; /* all ones mask -> keep */ + IF(NE_16(element_mode, EVS_MONO)) + { + if ((*num_plocs > 0) && sub(*num_plocs, 3) < 0) + { + one_peak_flag_mask = noise_fac; /* all zeroes mask -> zero */ + } + if (*num_plocs == 0) + { + X[0] = 0; /* reset DC if there are no peaks */ + X[shr(Lprot, 1)] = 0; /* also reset fs/2 if there are no peaks */ + } + } +#endif lprotBy2Minus1 = sub(shr(Lprot, 1), 1); i = 1; move16(); @@ -1158,8 +1484,21 @@ static void subst_spec_fx( move16(); im = *pImX; move16(); - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(EQ_16(element_mode, EVS_MONO)) +#endif + { + tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); + im = add(mult_r(re, sin_F), mult_r(im, cos_F)); + } +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ELSE + { + PMTE() + //tmp = one_peak_flag_mask * (X[i] * cos_F - X[im_ind] * sin_F); + //X[im_ind] = one_peak_flag_mask * (X[i] * sin_F + X[im_ind] * cos_F); + } +#endif IF (LT_16(alpha[k], 32766)) { *seed = rand_phase_fx(*seed, &sin_F, &cos_F); @@ -1177,7 +1516,7 @@ static void subst_spec_fx( move16(); } i = add(i, 1); - if (GE_16(i, gwlpr_fx[k+1])) + if (GE_16(i, ivas_gwlpr_fx[k+1])) { k = add(k, 1); } @@ -1273,8 +1612,21 @@ static void subst_spec_fx( move16(); im = *pImX; move16(); - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(EQ_16(element_mode, EVS_MONO)) +#endif + { + tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); + im = add(mult_r(re, sin_F), mult_r(im, cos_F)); + } +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ELSE + { + PMTE() + //tmp = one_peak_flag_mask * (X[i] * cos_F - X[im_ind] * sin_F); + //X[im_ind] = one_peak_flag_mask * (X[i] * sin_F + X[im_ind] * cos_F); + } +#endif IF (LT_16(alpha[k], 32766)) { alpha_local = mag_chg_local; @@ -1315,7 +1667,7 @@ static void subst_spec_fx( } i = add(i, 1); - if (GE_16(i, gwlpr_fx[k+1])) + if (GE_16(i, ivas_gwlpr_fx[k+1])) { k = add(k, 1); } @@ -1352,7 +1704,7 @@ static void subst_spec_fx( } i = add(i, 1); - if (GE_16(i, gwlpr_fx[k+1])) + if (GE_16(i, ivas_gwlpr_fx[k+1])) { k = add(k, 1); } @@ -1382,7 +1734,98 @@ static void rec_wtda_fx( Word16 *p_ecu; Word16 g; Word16 tbl_delta; +#ifdef IVAS_FEC_ECU_TO_COMPLETE + float xsubst_[2 * L_FRAME48k]; + const float* w_hamm; + float* pX_start, * pX_end; + float tmp; + int16_t hamm_len2; + float* pNew; + const float* pOldW, * pNewW; + float xfwin[NS2SA(L_FRAME48k * FRAMES_PER_SEC, N_ZERO_MDCT_NS - (2 * FRAME_SIZE_NS - L_PROT_NS) / 2)]; + const float* pOld; + int16_t copy_len; + int16_t ola_len; + + copy_len = NS2SA(output_frame * FRAMES_PER_SEC, (2 * FRAME_SIZE_NS - L_PROT_NS) / 2); /* prototype fill on each side of xsubst to fill MDCT Frame */ + ola_len = NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS - (2 * FRAME_SIZE_NS - L_PROT_NS) / 2); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */ + if (output_frame == L_FRAME48k) + { + w_hamm = w_hamm_sana48k_2; + hamm_len2 = L_PROT_HAMM_LEN2_48k; + } + else if (output_frame == L_FRAME32k) + { + w_hamm = w_hamm_sana32k_2; + hamm_len2 = L_PROT_HAMM_LEN2_32k; + } + else + { + w_hamm = w_hamm_sana16k_2; + hamm_len2 = L_PROT_HAMM_LEN2_16k; + } + + if (element_mode != EVS_MONO && *num_p > 0 && plocs[0] > 3) + { + /* Perform inverse windowing of hammrect */ + pX_start = X; + pX_end = X + Lprot - 1; + for (i = 0; i < hamm_len2; i++) + { + tmp = 1.0f / *w_hamm; + *pX_start *= tmp; + *pX_end *= tmp; + pX_start++; + pX_end--; + w_hamm++; + } + } + + /* extract reconstructed frame with aldo window */ + timesh = NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS) - (2 * output_frame - Lprot) / 2; + + set_f(xsubst_, 0.0f, 2 * output_frame - Lprot + timesh); + mvr2r(X, xsubst_ + 2 * output_frame - Lprot + timesh, Lprot - timesh); + + /* Copy and OLA look ahead zero part of MDCT window from decoded signal */ + if (element_mode != EVS_MONO) + { + mvr2r(old_dec, xsubst_ + NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS), copy_len); /* also need to scale to Q0 ?? */ + pOld = old_dec + copy_len; + pNew = xsubst_ + copy_len + NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS); + sinq(EVS_PI / (ola_len * 2), 0.0f, ola_len, xfwin); + v_mult(xfwin, xfwin, xfwin, ola_len); /* xfwin = sin^2 of 0..pi/4 */ + pOldW = xfwin + ola_len - 1; + pNewW = xfwin; + for (i = 0; i < ola_len; i++) + { + *pNew = *pOld * *pOldW + *pNew * *pNewW; + pOld += 1; + pNew += 1; + pOldW -= 1; + pNewW += 1; + } + } + else + { + /* Smoothen onset of ECU frame */ + xf_len = (int16_t)((float)output_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS) - (output_frame - Lprot / 2); + p_ecu = xsubst_ + 2 * output_frame - Lprot + timesh; + tbl_delta = 64.f / xf_len; /* 64 samples = 1/4 cycle in sincos_t */ + for (i = 0; i < xf_len; i++, p_ecu++) + { + g = sincos_t[((int16_t)(i * tbl_delta))]; + g *= g; + *p_ecu = g * (*p_ecu); + } + } + + /* Apply TDA and windowing to ECU frame */ + wtda(xsubst_ + output_frame, ecu_rec, NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame); + +#else + PMTE() xsubst_ = rec_buf + output_frame; Lprot2 = shr(Lprot, 1); @@ -1428,7 +1871,7 @@ static void rec_wtda_fx( out_ptr = rec_buf + sub(shl(output_frame,1), timesh); wtda_fx(out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame); - +#endif return; } @@ -1442,6 +1885,12 @@ static void rec_frame_fx( Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ const Word16 output_frame, /* i : Frame length */ const Word16 Q +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ,const float* old_dec, /* i : end of last decoded for OLA before tda and itda */ + const int16_t element_mode, /* i : IVAS element mode */ + const int16_t* num_p, /* i : Number of peaks */ + const int16_t* plocs /* i : Peak locations */ +#endif ) { const Word16 *pFftTbl; @@ -1567,6 +2016,12 @@ void fir_dwn_fx( return; } +/*-------------------------------------------------------------------------- + * fec_ecu_pitch() + * + * Pitch/correlation analysis and adaptive analysis frame length calculation + *--------------------------------------------------------------------------*/ + static void fec_ecu_pitch_fx( const Word16 *prevsynth_fx, /*Q15 16 */ @@ -1880,6 +2335,12 @@ Word16 abs_iter_fx(Word16 re, Word16 im, Word16 N) return A; } +/*-------------------------------------------------------------------------- +* fec_ecu_dft() +* +* DFT analysis on adaptive frame length. Analysis frame stretched to +* next power of 2 using linear interpolation. +*--------------------------------------------------------------------------*/ static void fec_ecu_dft_fx( @@ -1891,12 +2352,27 @@ void fec_ecu_dft_fx( Word16 *Tf_abs, /*Qout */ Word16 *Nfft, Word16 *exp /*Qout = Qin+exp */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ,const int16_t element_mode /* i : IVAS element mode */ +#endif ) { Word32 L_tmp, Tmp, Tfr32[512], Tfi32[512], fac, *Pt1, *Pt2; Word16 i, tmp, tmp_short,N_LP, target[2*L_FRAME48k], Tfr16[FEC_FFT_MAX_SIZE], *pt1, *pt2, *pt3; Word16 tmp_loop; +#ifdef IVAS_FEC_ECU_TO_COMPLETE + int16_t alignment_point; + Lon20 = (int16_t)160 / 20; + if (element_mode == EVS_MONO) + { + alignment_point = 2 * 160 - 3 * Lon20; + } + else + { + alignment_point = 2 * 160; + } +#endif tmp = sub(296,N); Copy(&prevsynth_LP[tmp], target, N); @@ -2272,6 +2748,10 @@ void fec_noise_filling_fx( const Word16 N, const Word16 HqVoicing, Word16 *gapsynth_fx /*Qsynth */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ,const int16_t element_mode, /* i : IVAS element mode */ + const float* old_out +#endif ) { @@ -2286,7 +2766,21 @@ void fec_noise_filling_fx( Word32 L_tmp; const Word16 *sinq_tab; +#ifdef IVAS_FEC_ECU_TO_COMPLETE + const float* p_mdct_ola; + int16_t alignment_point; + PMTE() + if (element_mode == EVS_MONO) + { + alignment_point = 2 * L - 3 * L / 20; + } + else + { + alignment_point = 2 * L; + } + mvr2r(prevsynth + alignment_point - N, noisevect, N); +#endif IF ( EQ_16(L, L_FRAME32k)) { @@ -2358,6 +2852,18 @@ void fec_noise_filling_fx( tmp_fx = div_s(1, Rnd_N_noise); /*Q15 */ tmp_fx = round_fx(L_shl(L_mult(tmp_fx, 25736),2)); /*Q15 */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + if (element_mode == EVS_MONO) + { + kk = 7 * L / 20; + p_mdct_ola = prevsynth + 37 * L / 20; + } + else + { + kk = NS2SA(L * FRAMES_PER_SEC, N_ZERO_MDCT_NS); + p_mdct_ola = old_out + kk; + } +#endif sinq_fx( shr(tmp_fx,1), shr(tmp_fx,2), Rnd_N_noise, SS_fx); @@ -2412,6 +2918,10 @@ void fec_alg_fx( const Word16 decimatefactor, const Word16 HqVoicing, Word16 *gapsynth /*Qin */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + ,const Word16 element_mode, /* i : IVAS element mode */ + const Word16* old_out +#endif ) { Word16 Nfft; @@ -2423,12 +2933,19 @@ void fec_alg_fx( Word16 exp; Word16 n,Q; - fec_ecu_dft_fx( prevsynth_LP, N, - Tfr, Tfi, &sum_Tf_abs, Tf_abs, &Nfft, &exp ); + fec_ecu_dft_fx( prevsynth_LP, N, Tfr, Tfi, &sum_Tf_abs, Tf_abs, &Nfft, &exp +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , element_mode +#endif + ); sinusoidal_synthesis_fx( Tfr, Tfi, Tf_abs, N, output_frame, decimatefactor, Nfft, sum_Tf_abs, synthesis, HqVoicing, exp ); - fec_noise_filling_fx(prevsynth,synthesis,ni_seed_forfec,output_frame,i_mult2(N, decimatefactor),HqVoicing,gapsynth); + fec_noise_filling_fx(prevsynth,synthesis,ni_seed_forfec,output_frame,i_mult2(N, decimatefactor),HqVoicing,gapsynth +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , element_mode, old_out +#endif + ); n = R1_48-R2_48; move16(); @@ -2479,6 +2996,10 @@ static void hq_phase_ecu_fx( Word16 *beta_mute, /* o : Factor for long-term mute */ const Word16 bwidth_fx, /* i : Encoded bandwidth */ const Word16 output_frame /* i : frame length */ +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , const Word16 pcorr, + const Word16 element_mode /* i : IVAS element mode */ +#endif ) { Word16 lprot, offset; @@ -2486,6 +3007,22 @@ static void hq_phase_ecu_fx( Word16 seed; Word16 alpha[Lgw_max], beta[Lgw_max]; +#ifdef IVAS_FEC_ECU_TO_COMPLETE + const float* old_dec; + float noise_fac; + int16_t ph_ecu_lookahead; + + noise_fac = 1.0f; + + if (element_mode == EVS_MONO) + { + ph_ecu_lookahead = NS2SA(output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS); + } + else + { + ph_ecu_lookahead = 0; + } +#endif IF (EQ_16(output_frame, L_FRAME48k)) { lprot = Lprot48k; /* 1536 = (2*output_frame)*1024/1280 */ move16(); @@ -2511,18 +3048,30 @@ static void hq_phase_ecu_fx( IF ( prev_bfi == 0 || (prev_bfi != 0 && *last_fec != 0 && (EQ_16(*time_offs, output_frame)))) { test(); - if( !(prev_bfi != 0 && *last_fec != 0) ) + PMT("verify condition compared to float") +#ifdef IVAS_FEC_ECU_TO_COMPLETE + IF(!(prev_bfi != 0 && *last_fec != 0) && EQ_16(element_mode == EVS_MONO)) +#else + IF( !(prev_bfi != 0 && *last_fec != 0) ) +#endif { *time_offs = 0; move16(); } +#ifdef IVAS_FEC_ECU_TO_COMPLETE + offset = add(sub(sub(shl(output_frame, 1), lprot), *time_offs), ph_ecu_lookahead); +#else offset = sub(sub(shl(output_frame, 1), lprot), *time_offs); - +#endif trans_ana_fx(prevsynth + offset, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, *last_fec, alpha, beta, beta_mute, Xavg); - spec_ana_fx(prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec); + spec_ana_fx(prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , element_mode, noise_fac, pcorr +#endif + ); test(); IF( prev_bfi != 0 && *last_fec != 0 ) @@ -2550,10 +3099,21 @@ static void hq_phase_ecu_fx( } subst_spec_fx(plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, - alpha, beta, *beta_mute, Xavg); + alpha, beta, *beta_mute, Xavg +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , element_mode, ph_ecu_lookahead, noise_fac +#endif + ); /* reconstructed frame in tda domain */ - rec_frame_fx(X, ecu_rec, output_frame, *Q_spec); +#ifdef IVAS_FEC_ECU_TO_COMPLETE + old_dec = prevsynth + 2 * output_frame - NS2SA(output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS); +#endif + rec_frame_fx(X, ecu_rec, output_frame, *Q_spec +#ifdef IVAS_FEC_ECU_TO_COMPLETE + , old_dec, element_mode, num_p, plocs +#endif + ); *last_fec = 0; *ph_ecu_active = 1; @@ -2593,7 +3153,22 @@ void hq_ecu_fx( Word16 decimatefactor; Word16 corr; /*Q15 */ Word16 prevsynth_LP[2*L_FRAME8k]; +#ifdef IVAS_FEC_ECU_TO_COMPLETE + HQ_DEC_HANDLE hHQ_core; + const float* fec_alg_input; + int16_t evs_mode_selection; + int16_t ivas_mode_selection; + hHQ_core = st->hHQ_core; + if (st->element_mode == EVS_MONO) + { + fec_alg_input = prevsynth + NS2SA(output_frame * FRAMES_PER_SEC, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS); + } + else + { + fec_alg_input = prevsynth - NS2SA(output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS); + } +#endif /* init (values ar changed after) */ decimatefactor=4; N=shr(output_frame,2); @@ -2603,7 +3178,11 @@ void hq_ecu_fx( IF (!(LT_16(output_frame,L_FRAME16k))) { +#ifdef IVAS_FEC_ECU_TO_COMPLETE + fec_ecu_pitch_fx(fec_alg_input, prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing); +#else fec_ecu_pitch_fx( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing); +#endif } ELSE { @@ -2611,27 +3190,39 @@ void hq_ecu_fx( move16(); /* just to avoid using uninitialized value in if statement below */ } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test();test(); + test();test();test();test();test();test(); + test();test();test(); +#if defined IVAS_FEC_ECU_TO_COMPLETE + evs_mode_selection = (st->total_brate >= 48000 && (output_frame >= L_FRAME16k && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]) && + (ph_ecu_HqVoicing || (((hHQ_core->env_stab_plc > 0.5) && (corr < 0.6)) || (hHQ_core->env_stab_plc < 0.5 && (corr > 0.85)))))) || + (st->total_brate < 48000 && ((ph_ecu_HqVoicing || corr > 0.85) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]))); + + ivas_mode_selection = (N < PH_ECU_N_LIMIT) || (corr < PH_ECU_CORR_LIMIT); + if (((st->element_mode == EVS_MONO) && evs_mode_selection) || + ((st->element_mode != EVS_MONO) && evs_mode_selection && ivas_mode_selection)) + + { + fec_alg_fx(fec_alg_input, prevsynth_LP, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, &hHQ_core->ni_seed_forfec, st->element_mode, st->hHQ_core->old_out); + *last_fec = 1; + *ph_ecu_active = 0; + move16(); + *time_offs = output_frame; + move16();; + } + else + { + hq_phase_ecu(prevsynth - NS2SA(output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS), ecu_rec, time_offs, X_sav, num_p, plocs, plocsi, env_stab, last_fec, prev_bfi, old_is_transient, mag_chg_1st, Xavg, beta_mute, st->bwidth, output_frame, corr, st->element_mode); + + *last_fec = 0; + *ph_ecu_active = 1; + } +#else IF ( (GE_32(st_fx->total_brate_fx,48000)&& - ( GE_16(output_frame, L_FRAME16k) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1] ) && (NE_16(ph_ecu_HqVoicing,0) || ( ((NE_16(st_fx->env_stab_plc_fx ,0)) && (LT_16(corr,19661))) || (!(NE_16(st_fx->env_stab_plc_fx ,0)) && (GT_16(corr, 27853)) ))))) || + ( GE_16(output_frame, L_FRAME16k) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1] ) && (NE_16(ph_ecu_HqVoicing,0) || ( ((NE_16(st_fx->hHQ_core->env_stab_plc_fx ,0)) && (LT_16(corr,19661))) || (!(NE_16(st_fx->hHQ_core->env_stab_plc_fx ,0)) && (GT_16(corr, 27853)) ))))) || (LT_32(st_fx->total_brate_fx,48000) && ( ( ph_ecu_HqVoicing || GT_16(corr, 27853)) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]) )) ) { - fec_alg_fx( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, &st_fx->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth); - + fec_alg_fx( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth); *last_fec = 1; *ph_ecu_active = 0; move16(); @@ -2644,7 +3235,7 @@ void hq_ecu_fx( env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, mag_chg_1st, Xavg, beta_mute, st_fx->bwidth_fx, output_frame ); } - +#endif return; } diff --git a/lib_dec/FEC_adapt_codebook_fx.c b/lib_dec/FEC_adapt_codebook_fx.c index 772d7f2..67dcd8f 100644 --- a/lib_dec/FEC_adapt_codebook_fx.c +++ b/lib_dec/FEC_adapt_codebook_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_dec_fx.h" /* Decoder static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*---------------------------------------------------------------------* diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index 6c29507..49265a9 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -2,20 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_util.h" /*-------------------------------------------------------------------* - * Local functions + * Local function prototypes *-------------------------------------------------------------------*/ - -static Word16 FEC_dec_class_fx( Decoder_State_fx *st_fx, const Word32 bitrate, const Word16 coder_type, Word32 *enr_q, const Word16 last_good); - +static Word16 FEC_dec_class_fx( Decoder_State_fx *st_fx, Word32 *enr_q); static void Corre(const Word16 *x,const Word16 *y,const Word16 l,Word16 *gain); /*---------------------------------------------------------------------* @@ -51,11 +48,11 @@ static void Corre(const Word16 *x,const Word16 *y,const Word16 l,Word16 *gain); void FEC_clas_estim_fx( Decoder_State_fx *st_fx , /* i/o: decoder state handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ - const Word16 L_frame, /* i : length of the frame */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ + const Word16 L_frame, /* i : length of the frame */ Word16 *clas, /* i/o: frame classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 *pitch, /* i : pitch values for each subframe (Q6)*/ + const Word16 coder_type, /* i : coder type */ + const Word16 *pitch, /* i : pitch values for each subframe (Q6)*/ Word16 *syn, /* i : synthesis buffer */ Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ Word16 *decision_hyst, /* i/o: hysteresis of the music/speech decision */ /*A*/ @@ -65,7 +62,7 @@ void FEC_clas_estim_fx( Word16 *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ Word16 *lt_diff_etot, /* i/o: long-term total energy variation */ /*A*/ Word16 *amr_io_class, /* i/o: classification for AMR-WB IO mode */ /*A*/ - const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ + const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ Word16 Q_syn, /* i : Synthesis scaling */ Word16 *class_para, /* o : classification para. fmerit1 */ /*A*/ Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ @@ -73,7 +70,8 @@ void FEC_clas_estim_fx( Word16 LTP_Gain, /* i : LTP gain is 0..0.6 or -1 Q15 *//*B*/ Word16 mode, /* i : signal classifier mode *//*B*/ Word16 bfi, /* i : bad frame indicator *//*B*/ - Word32 last_core_brate /* i : bitrate of previous frame */ + Word32 last_core_brate, /* i : bitrate of previous frame */ + const int16_t FEC_mode /* i : ACELP FEC mode */ ) { Word16 i, j, pos; @@ -103,17 +101,7 @@ void FEC_clas_estim_fx( *------------------------------------------------------------------------*/ /* After Rate Switching st->last_core is reset to 0. Check for last_core_brate is needed */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test();test();test();test();test();test();test(); IF((EQ_32(last_core_brate, SID_1k75)||EQ_32(last_core_brate,ACELP_6k60)||EQ_32(last_core_brate,ACELP_8k85) || EQ_32(last_core_brate, ACELP_12k65) || EQ_32(last_core_brate, ACELP_14k25) || EQ_32(last_core_brate, ACELP_15k85) || EQ_32(last_core_brate, ACELP_18k25) || EQ_32(last_core_brate, ACELP_19k85) || EQ_32(last_core_brate, ACELP_23k05) @@ -196,16 +184,8 @@ void FEC_clas_estim_fx( /* Do the classification only - MODE1: when the class is not transmitted in the bitstream - MODE2: on good frames (classifier is also called for bfi=1) */ - test(); - test(); - test(); - test(); - test(); - test(); - IF (( EQ_16(codec_mode , MODE1)&&(LT_32(bitrate,ACELP_11k60) - || LE_16(coder_type , UNVOICED) || Opt_AMR_WB)) || - (EQ_16(codec_mode , MODE2) && NE_16(bfi,1) && !tcxonly )) - + test();test();test();test();test();test(); + IF (( EQ_16(codec_mode , MODE1) && (FEC_mode == 0 || LE_16(coder_type , UNVOICED) || Opt_AMR_WB)) || (EQ_16(codec_mode , MODE2) && NE_16(bfi,1) && !tcxonly )) { /*------------------------------------------------------------------------* * Overwrite classification decision using coder_type information @@ -740,10 +720,7 @@ void FEC_clas_estim_fx( static Word16 FEC_dec_class_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 coder_type, /* i : coder type */ - Word32 *enr_q, /* i : decoded energy Q0 */ - const Word16 last_good /* i : Last good FEC classification */ + Word32 *enr_q /* i : decoded energy Q0 */ ) { Word16 clas, tmpS; @@ -753,7 +730,7 @@ static Word16 FEC_dec_class_fx( clas = ONSET; move16(); - IF( NE_16(coder_type,VOICED)) + IF( NE_16(st_fx->coder_type_fx,VOICED)) { /* decode the class */ tmpS = (Word16)get_next_indice_fx( st_fx, FEC_BITS_CLS ); @@ -765,7 +742,7 @@ static Word16 FEC_dec_class_fx( } ELSE IF( EQ_16(tmpS,1)) { - IF( GE_16(last_good,VOICED_TRANSITION)) + IF( GE_16(st_fx->last_good_fx,VOICED_TRANSITION)) { clas = VOICED_TRANSITION; move16(); @@ -791,7 +768,7 @@ static Word16 FEC_dec_class_fx( /* decode the energy */ test(); test(); - IF( GE_32(bitrate,ACELP_14k80)&&NE_16(coder_type,TRANSITION)&<_16(coder_type,AUDIO)) + IF(GT_16(st_fx->acelp_cfg.FEC_mode , 1) ) { tmpS = (Word16)get_next_indice_fx( st_fx, FEC_BITS_ENR ); /* convert from logarithmic to linear domain (the range is 0 : 3.0 : 96 dB) */ @@ -807,13 +784,10 @@ static Word16 FEC_dec_class_fx( } Word16 FEC_pos_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 last_good, /* i : last good classfication */ - Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ - Word16 *clas, /* o : decoded classification */ - Word32 *enr_q, /* o : decoded energy in Q0 */ - const Word32 core_brate /* i : decoded bitrate */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ + Word32 *enr_q, /* o : decoded energy in Q0 */ + const Word16 nBits_es_Pred /* i : number of bits for Es_pred Q */ ) { Word16 pitch_index, T0, T0_frac, T0_min, T0_max; @@ -821,49 +795,34 @@ Word16 FEC_pos_dec_fx( T0 = 0; move16(); - IF( GT_16(coder_type,UNVOICED)) + IF( GT_16(st_fx->coder_type_fx,UNVOICED)) { /* decode the clas and energy information */ - IF( LT_16(coder_type,AUDIO)) + IF( LT_16(st_fx->coder_type_fx,AUDIO)) { - *clas = FEC_dec_class_fx( st_fx, core_brate, coder_type, enr_q, last_good); + st_fx->clas_dec = FEC_dec_class_fx( st_fx, enr_q); move16(); test(); test(); test(); - IF( EQ_16(coder_type,GENERIC)&&EQ_16(*clas,VOICED_CLAS)&&(LE_16(last_good,UNVOICED_CLAS)||EQ_16(last_good,INACTIVE_CLAS))) + IF( EQ_16(st_fx->coder_type_fx,GENERIC) && EQ_16(st_fx->clas_dec,VOICED_CLAS) && (LE_16(st_fx->last_good_fx,UNVOICED_CLAS) || EQ_16(st_fx->last_good_fx,INACTIVE_CLAS))) { - *clas = SIN_ONSET; + st_fx->clas_dec = SIN_ONSET; move16(); } } test(); - IF( EQ_16(coder_type,GENERIC)&>_32(core_brate,ACELP_24k40)) + IF( EQ_16(st_fx->coder_type_fx,GENERIC) && GT_16(st_fx->acelp_cfg.FEC_mode,2) ) { - nBits = 0; - move16(); - IF( NE_16(coder_type,AUDIO)) + nBits = st_fx->acelp_cfg.pitch_bits[0]; /* The first pitch index is located right after the actual position + the last pulse position index + predicted innovation energy index */ + bit_pos_pitch_index = st_fx->next_bit_pos_fx + FEC_BITS_POS + nBits_es_Pred; + IF (GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate_fx, MAX_BRATE_AVQ_EXC_TD) && EQ_16(st_fx->coder_type_fx, GENERIC)) { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, 0, 0)]; - move16(); + /* Harmonic flag is present */ + bit_pos_pitch_index = add(bit_pos_pitch_index, 1); } - - /* use the absolute position of pitch index in the bitstream (this value is hard-coded and must be udpated when it changes in the encoder) */ - bit_pos_pitch_index = 71; - move16(); /* 64 kbps WB,SWB and FB*/ - if( LE_32(core_brate,ACELP_32k)) - { - bit_pos_pitch_index = 72; - move16(); /* 32 kbp, WB*/ - if(GT_16(st_fx->bwidth_fx,WB)) - { - bit_pos_pitch_index = 73; - move16(); /* 32 kbp, SWB, FB*/ - } - } - /* retrieve the pitch index */ pitch_index = (Word16)get_indice_fx( st_fx, bit_pos_pitch_index, nBits ); diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 2ea49e5..361ab48 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -2,17 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Common static table prototypes */ #include "rom_dec_fx.h" /* Decoder static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_util.h" /*-------------------------------------------------------------------* - * Local functions + * Local function prototypes *-------------------------------------------------------------------*/ static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 new_pit, Word16 Tc, Word16 L_frame); void gain_dec_bfi_fx(Word16 *past_qua_en); @@ -96,8 +95,12 @@ void FEC_exc_estim_fx( Word16 cond1, cond2; Word32 cond3; Word32 predPitchLag; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; - /* nb_subfr = L_frame/L_SUBFR */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO; + hAmrwb_IO = st_fx->hAmrwb_IO; + /* nb_subfr = L_frame/L_SUBFR */ nb_subfr = shr(L_frame, 6); Diff_len = 0; /* to avoid compilation flags */ set16_fx( exc_dct_in, 0, L_FRAME16k ); @@ -269,7 +272,7 @@ void FEC_exc_estim_fx( ELSE IF( EQ_16(st_fx->last_coder_type_fx,AUDIO)||EQ_16(st_fx->last_good_fx,INACTIVE_CLAS)) { test(); - IF( st_fx->Last_GSC_pit_band_idx_fx > 0 && GT_16(st_fx->nbLostCmpt,1)) + IF( hGSCDec->Last_GSC_pit_band_idx_fx > 0 && GT_16(st_fx->nbLostCmpt,1)) { alpha = 26214; move16(); @@ -361,7 +364,7 @@ void FEC_exc_estim_fx( test(); test(); IF( (GE_16(st_fx->last_good_fx,UNVOICED_TRANSITION)&<_16(st_fx->last_good_fx,INACTIVE_CLAS))|| - ( (EQ_16(st_fx->last_coder_type_fx,AUDIO) || EQ_16(st_fx->last_good_fx,INACTIVE_CLAS) ) && st_fx->Last_GSC_pit_band_idx_fx > 0) ) + ( (EQ_16(st_fx->last_coder_type_fx,AUDIO) || EQ_16(st_fx->last_good_fx,INACTIVE_CLAS) ) && hGSCDec->Last_GSC_pit_band_idx_fx > 0) ) { pt_exc = exc; @@ -467,13 +470,13 @@ void FEC_exc_estim_fx( } test(); test(); - IF( (EQ_16(st_fx->last_coder_type_fx,AUDIO)||EQ_16(st_fx->last_good_fx,INACTIVE_CLAS))&&st_fx->Last_GSC_pit_band_idx_fx>0) + IF( (EQ_16(st_fx->last_coder_type_fx,AUDIO)||EQ_16(st_fx->last_good_fx,INACTIVE_CLAS))&& hGSCDec->Last_GSC_pit_band_idx_fx>0) { - Diff_len = mfreq_loc_div_25[st_fx->Last_GSC_pit_band_idx_fx]; + Diff_len = mfreq_loc_div_25[hGSCDec->Last_GSC_pit_band_idx_fx]; move16(); /* Transform to frequency domain */ - edct_16fx( exc, exc_dct_in, st_fx->L_frame_fx, 5 ); + edct_16fx( exc, exc_dct_in, st_fx->L_frame_fx, 5, st_fx->element_mode); /* Reset unvaluable part of the adaptive (pitch) excitation contribution */ max_len = sub(st_fx->L_frame_fx,Diff_len); @@ -501,15 +504,15 @@ void FEC_exc_estim_fx( test(); test(); test(); - IF( EQ_16(st_fx->last_coder_type_fx,AUDIO)||(EQ_16(st_fx->last_good_fx,INACTIVE_CLAS)&&LE_32(st_fx->total_brate_fx,ACELP_24k40)&&!st_fx->Opt_AMR_WB_fx)) + IF( EQ_16(st_fx->last_coder_type_fx,AUDIO)||(EQ_16(st_fx->last_good_fx,INACTIVE_CLAS)&&LE_32(st_fx->total_brate_fx, MAX_GSC_INACTIVE_BRATE)&&!st_fx->Opt_AMR_WB_fx)) { st_fx->GSC_noisy_speech_fx = st_fx->Last_GSC_noisy_speech_flag_fx; move16(); /* Replication of the last spectrum, with a slight downscaling of its dynamic */ - gsc_dec_fx( st_fx, exc_dct_in, st_fx->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame_fx/L_SUBFR, st_fx->last_coder_type_fx, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); + gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame_fx/L_SUBFR, st_fx->last_coder_type_fx, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); *tmp_noise = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ /* Transform back to time domain */ - edct_16fx( exc_dct_in, exc, st_fx->L_frame_fx, 5 ); + edct_16fx( exc_dct_in, exc, st_fx->L_frame_fx, 5, st_fx->element_mode); } ELSE { @@ -649,7 +652,7 @@ void FEC_exc_estim_fx( test(); test(); test(); - IF( (EQ_16(st_fx->last_coder_type_fx,AUDIO)||EQ_16(st_fx->last_good_fx,INACTIVE_CLAS))&&LE_32(st_fx->total_brate_fx,ACELP_24k40)&&!st_fx->Opt_AMR_WB_fx) + IF( (EQ_16(st_fx->last_coder_type_fx,AUDIO)||EQ_16(st_fx->last_good_fx,INACTIVE_CLAS))&&LE_32(st_fx->total_brate_fx, MAX_GSC_INACTIVE_BRATE)&&!st_fx->Opt_AMR_WB_fx) { /* For GSC - the excitation is already computed */ Copy( exc, exc2, st_fx->L_frame_fx ); @@ -688,15 +691,17 @@ void FEC_exc_estim_fx( Copy( exc2_buf + MODE1_L_FIR_FER/2, exc, L_frame ); Copy( exc2_buf + MODE1_L_FIR_FER/2, exc2, L_frame ); } - - IF( EQ_16(L_frame,L_FRAME)) + IF(st_fx->hBWE_TD != NULL) { + IF(EQ_16(L_frame, L_FRAME)) + { - interp_code_5over2_fx( exc, bwe_exc, L_frame ); - } - ELSE - { - interp_code_4over2_fx( exc, bwe_exc, L_frame ); + interp_code_5over2_fx(exc, bwe_exc, L_frame); + } + ELSE + { + interp_code_4over2_fx(exc, bwe_exc, L_frame); + } } test(); IF( EQ_16(st_fx->last_coder_type_fx,AUDIO)||EQ_16(st_fx->last_good_fx,INACTIVE_CLAS)) @@ -723,7 +728,7 @@ void FEC_exc_estim_fx( } IF( st_fx->Opt_AMR_WB_fx ) { - gain_dec_bfi_fx(st_fx->past_qua_en_fx); + gain_dec_bfi_fx(hAmrwb_IO->past_qua_en_fx); } st_fx->bfi_pitch_fx = pitch_buf[(L_frame/L_SUBFR)-1]; move16(); diff --git a/lib_dec/FEC_lsf_estim_fx.c b/lib_dec/FEC_lsf_estim_fx.c index 63ecfe9..ca1618a 100644 --- a/lib_dec/FEC_lsf_estim_fx.c +++ b/lib_dec/FEC_lsf_estim_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" + /*-------------------------------------------------------------------* * FEC_lsf_estim() diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c index 0d8c948..b14bb3f 100644 --- a/lib_dec/FEC_pitch_estim_fx.c +++ b/lib_dec/FEC_pitch_estim_fx.c @@ -1,7 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ @@ -58,8 +58,12 @@ void FEC_pitch_estim_fx( tmp16k1 = round_fx(L_shl(Mpy_32_16_1(old_pitch_buf[2*NB_SUBFR16k-1],22938), 6)); /*Q6 0.7f * old_pitch_buf[2*NB_SUBFR16k-1]*/ tmp16k2 = shl(tmp16k1,1); /*Q6 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]*/ - +#ifdef IVAS_CODE + test(); test(); + IF (EQ_16(last_core, HQ_CORE) || EQ_16(last_core, TCX_20_CORE) || EQ_16(last_core, TCX_10_CORE)) +#else IF( EQ_16(last_core,HQ_CORE)) +#endif { *bfi_pitch = pitch_buf[shr(L_frame,6)-1]; move16(); diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 05ddbac..bf48df3 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_mpy.h" /*-------------------------------------------------------------------* @@ -54,33 +53,33 @@ void FEC_scale_syn_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ + Word16 clas, /* i/o: frame classification */ + const Word16 last_good, /* i: last good frame classification */ + Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ + const Word16 *pitch, /* i: pitch values for each subframe */ + Word32 L_enr_old, /* i: energy at the end of previous frame */ + Word32 L_enr_q, /* i: transmitted energy for current frame */ + const Word16 coder_type, /* i: coder type */ + const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ + Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ + Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ + Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + const Word16 bfi, /* i: current frame BFI */ + const Word32 total_brate, /* i: total bitrate */ + const Word16 prev_bfi, /* i: previous frame BFI */ + const Word32 last_core_brate, /* i: previous frame core bitrate */ + Word16 *exc, /* i/o: excitation signal without enhancement */ + Word16 *exc2, /* i/o: excitation signal with enhancement */ + Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ + Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ + const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ + Word16 *mem_syn, /* o: initial synthesis filter states */ Word16 Q_exc, - Word16 Q_syn - , Word16 avoid_lpc_burst_on_recovery /* i : if true the excitation energy is limited if LP has big gain */ - , Word16 force_scaling /* i: force scaling */ + Word16 Q_syn, + const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ + const Word16 force_scaling /* i: force scaling */ ) { Word16 i; diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index 758daea..f757c6a 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* @@ -16,9 +16,9 @@ #define INV_MAX_SNR_FX 745 /* Q15 {1/(45-1)} Max. SNR considered for noise subtraction in voiced segments */ #define MAX_SNR_SNR1_FX 16756 /* Q14 45* (1/(max_snr1-1)) */ -#define BIN_1KHZ (short)(1000/BIN_16kdct_fx) -#define BIN_2KHZ (short)(2000/BIN_16kdct_fx) -#define BIN_4KHZ (short)(4000/BIN_16kdct_fx) +#define BIN_1KHZ (Word16)(1000/BIN_16kdct_fx) +#define BIN_2KHZ (Word16)(2000/BIN_16kdct_fx) +#define BIN_4KHZ (Word16)(4000/BIN_16kdct_fx) #define MAX_GN_R_Q14_FX 3277 #define ALPH_Q15_FX 32767 @@ -28,7 +28,7 @@ #define MAXX_FX 5 /*-------------------------------------------------------------------* - * Local functions + * Local function prototypes *-------------------------------------------------------------------*/ static void analy_sp_dct_fx(const Word16 *dct_buf, Word32 *fr_bands, Word32 *lf_E, Word16 *etot, const Word16 Qdct); static void find_enr_dct_fx(const Word16 data[], Word32 band[], Word32 *ptE, Word32 *Etot, const Word16 min_band, @@ -45,21 +45,10 @@ static void spectrum_mod_dct_fx(const Word16 Qdct,Word16 data[], const Word32 lf *------------------------------------------------------------------------*/ void LD_music_post_filter_fx ( + MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ const Word16 dtc_in[], /* i : input synthesis Qdct */ Word16 dtc_out[], /* o : output synthesis Qdct */ const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *last_music_flag, /* i/o : Previous music detection ouptut Q0 */ - Word16 *thresh, /* i/o : Detection thresold Q0 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 Q0 */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 Q0 */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation Q8 */ - Word16 *mem_etot, /* i/o : Total energy memory Q8 */ - const Word16 min_ns_gain, /* i : minimum gain for inter-harm noise red. Q15 */ - Word32 bckr[], /* i/o : per band bckgnd. noise energy estimate */ - Word32 lf_EO[], /* i/o : old per bin E for previous half frame 2*Qdct+10 */ - Word16 lp_gbin[], /* i/o : smoothed suppression gain, per FFT bin Q15 */ - Word16 *filt_lfE, /* i : post filter weighting coefficient Q15 */ - Word16 *last_nonfull_music, /* i: Number of frames sinces la "speech like" frame Q0*/ Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ const Word16 Last_coder_type, /* i : input scaling Q0 */ @@ -72,7 +61,7 @@ void LD_music_post_filter_fx Word16 LG_etot; /*Q8*/ Word16 i, j, k; Word16 min_band = 0; - Word16 local_min_gain = min_ns_gain; + Word16 local_min_gain; Word16 music_flag2 = 0; Word32 max_val; Word16 max_ovf_2k, max_ovf_4k, max_ovf_6k; @@ -84,6 +73,10 @@ void LD_music_post_filter_fx Word16 mant, exp1, s_ave, tmp16, old_tmp16; Word16 diff_sc; Word16 old_tmp16_1; + + + local_min_gain = hMusicPF->LDm_enh_min_ns_gain_fx; + /*------------------------------------------------------------------------* * Frequency analysis *------------------------------------------------------------------------*/ @@ -93,13 +86,13 @@ void LD_music_post_filter_fx *Old_ener_Q = Qdct; move16(); - Scale_sig32(lf_EO, VOIC_BINS_HR, diff_sc); + Scale_sig32(hMusicPF->LDm_enh_lf_EO_fx, VOIC_BINS_HR, diff_sc); /*------------------------------------------------------------------------* * Find signal classification *------------------------------------------------------------------------*/ - music_flag2 = stab_est_fx( LG_etot, lt_diff_etot, mem_etot - , nb_thr_3, nb_thr_1, thresh, last_music_flag, 1 ); + music_flag2 = stab_est_fx( LG_etot, hMusicPF->LDm_lt_diff_etot_fx, &hMusicPF->LDm_mem_etot_fx + , &hMusicPF->LDm_nb_thr_3_fx, &hMusicPF->LDm_nb_thr_1_fx, hMusicPF->LDm_thres_fx, &hMusicPF->LDm_last_music_flag_fx, 1 ); test(); if ( LT_32(core_brate,ACELP_6k60)||NE_16(Last_coder_type,AUDIO)) @@ -109,16 +102,16 @@ void LD_music_post_filter_fx move16(); } - *last_nonfull_music = add(*last_nonfull_music,1); + hMusicPF->last_nonfull_music_fx = add(hMusicPF->last_nonfull_music_fx,1); move16(); if( LT_16(music_flag2,4)) { - *last_nonfull_music = 0; + hMusicPF->last_nonfull_music_fx = 0; move16(); } - *last_nonfull_music = s_min( 51, *last_nonfull_music ); + hMusicPF->last_nonfull_music_fx = s_min( 51, hMusicPF->last_nonfull_music_fx); /*------------------------------------------------------------------------* * Remapping of bands @@ -193,7 +186,7 @@ void LD_music_post_filter_fx m_ave = Mult_32_16(Ltmp,inv_mfreq_bindiv_LD_M1_fx[i]); /*bckr[i] = m_ave*sc_qnoise[i];*/ - bckr[i] = Mult_32_16(m_ave,sc_qnoise_fx[i]); + hMusicPF->LDm_bckr_noise_fx[i] = Mult_32_16(m_ave,sc_qnoise_fx[i]); move32(); j+=mfreq_bindiv_LD[i]; @@ -244,13 +237,13 @@ void LD_music_post_filter_fx FOR(i = 0; i < BIN_4KHZ; i++) { /*filt_lfE[i] = tmp_lfE[i]*.05f + .95f*filt_lfE[i] ;*/ - filt_lfE[i] = round_fx(L_mac(L_mult(tmp_lfE[i],1638), 31130, filt_lfE[i])) ; + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_mult(tmp_lfE[i],1638), 31130, hMusicPF->filt_lfE_fx[i])) ; } FOR(; i < DCT_L_POST; i++) { /*filt_lfE[i] = tmp_lfE[i]*(.15f) + .85f*filt_lfE[i] ;*/ - filt_lfE[i] = round_fx(L_mac(L_mult(tmp_lfE[i],4915), 27853, filt_lfE[i])) ; + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_mult(tmp_lfE[i],4915), 27853, hMusicPF->filt_lfE_fx[i])) ; } /*------------------------------------------------------------------------* * - Reduce inter-harmonic noise with SNR based method @@ -266,7 +259,7 @@ void LD_music_post_filter_fx Copy(dtc_in, dtc_out, DCT_L_POST); - spectrum_mod_dct_fx( Qdct, dtc_out, lf_E, lf_EO, bckr, local_min_gain, lp_gbin, music_flag2, min_band, MAX_GN, MAX_band ); + spectrum_mod_dct_fx( Qdct, dtc_out, lf_E, hMusicPF->LDm_enh_lf_EO_fx, hMusicPF->LDm_bckr_noise_fx, local_min_gain, hMusicPF->LDm_enh_lp_gbin_fx, music_flag2, min_band, MAX_GN, MAX_band ); i = 0; move16(); @@ -274,12 +267,12 @@ void LD_music_post_filter_fx { FOR(i = 0; i < BIN_1KHZ; i++) { - tmp16 = s_min(4096, filt_lfE[i]); + tmp16 = s_min(4096, hMusicPF->filt_lfE_fx[i]); dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); } } { - IF( GT_16(*last_nonfull_music,40)) + IF( GT_16(hMusicPF->last_nonfull_music_fx,40)) { max_ovf_2k = 5120; /*1.25 Q12*/ move16(); max_ovf_4k = 6144; /*1.5 Q12*/ move16(); @@ -330,7 +323,7 @@ void LD_music_post_filter_fx FOR(; i < BIN_2KHZ; i++) { - tmp16 = s_min(max_ovf_2k, filt_lfE[i]); + tmp16 = s_min(max_ovf_2k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_2k, tmp16); /*DCT_buf[i] *= ftmp;*/ dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); @@ -339,7 +332,7 @@ void LD_music_post_filter_fx FOR(; i < BIN_4KHZ; i++) { - tmp16 = s_min(max_ovf_4k, filt_lfE[i]); + tmp16 = s_min(max_ovf_4k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_4k, tmp16); /*DCT_buf[i] *= ftmp;*/ dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); @@ -351,19 +344,19 @@ void LD_music_post_filter_fx /* Do not modify HF when coded with GSC at LR, because the spectrum is just noise */ FOR(; i < DCT_L_POST; i++) { - tmp16 = s_min(max_ovf_6k, filt_lfE[i]); + tmp16 = s_min(max_ovf_6k, hMusicPF->filt_lfE_fx[i]); tmp16 = s_max(min_g_6k, tmp16); /*DCT_buf[i] *= ftmp;*/ dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); } } } - ELSE IF( GT_16(*last_nonfull_music,25)) + ELSE IF( GT_16(hMusicPF->last_nonfull_music_fx,25)) { /* When unsure on content type only slight clean-up allowed, no overshoot allowed */ FOR(; i < DCT_L_POST; i++) { - tmp16 = s_min(4096,filt_lfE[i]); + tmp16 = s_min(4096, hMusicPF->filt_lfE_fx[i]); /*DCT_buf[i] *= ftmp;*/ dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); } @@ -751,8 +744,11 @@ void Prep_music_postP_fx( /*------------------------------------------------------------* * Resetting some memories in case of switching *------------------------------------------------------------*/ - - IF( EQ_16(last_core,HQ_CORE)) +#ifdef _DIFF_FLOAT_FIX_ + IF( EQ_16(last_core,HQ_CORE) || EQ_16(last_core, TCX_20_CORE) || EQ_16(last_core, TCX_10_CORE) ) +#else + IF(EQ_16(last_core, HQ_CORE)) +#endif { set16_fx( filt_lfE, 4096, DCT_L_POST ); set16_fx( LDm_enh_lp_gbin, 16384, VOIC_BINS_HR ); @@ -814,7 +810,7 @@ void Prep_music_postP_fx( * EDCT and back to 16 bits *------------------------------------------------------------*/ - edct_16fx(exc16, dct_buffer_out, DCT_L_POST, 6); + edct_16fx(exc16, dct_buffer_out, DCT_L_POST, 6, EVS_MONO); *qdct = Q_exc; move16(); @@ -889,7 +885,7 @@ void Post_music_postP_fx( * Go back to time domain *------------------------------------------------------------------------*/ - edct_16fx( dct_buffer_in, exc16, DCT_L_POST, 6); + edct_16fx( dct_buffer_in, exc16, DCT_L_POST, 6, EVS_MONO); Copy( exc16 + OFFSET2, exc2, L_FRAME); @@ -912,3 +908,67 @@ void Post_music_postP_fx( } +/*-------------------------------------------------------------------* + * music_postfilt_init() + * + * Initialize LD music postfilter state structure + *-------------------------------------------------------------------*/ +void music_postfilt_init( + MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */ +) +{ + Word16 i, e_db, f_db; + Word32 L_tmp; + + set16_fx(hMusicPF->dct_post_old_exc_fx, 0, DCT_L_POST - OFFSET2); + /*st->LDm_enh_min_ns_gain = (float)pow(10.0f, -12/20.0f);*/ + L_tmp = L_mult(((-12 * 256)), 5443); /* *0.166096 in Q15 -> Q24 */ + L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ + f_db = L_Extract_lc(L_tmp, &e_db); /* Extract exponent */ + f_db = extract_l(Pow2(14, f_db)); /* Put 14 as exponent so that */ + e_db = add(e_db, 15 - 14); + f_db = add(f_db, shr(1, add(e_db, 1))); + hMusicPF->LDm_enh_min_ns_gain_fx = shl(f_db, e_db); + + hMusicPF->LDm_last_music_flag_fx = 0; + move16(); + set16_fx(hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT); + + hMusicPF->LDm_thres_fx[0] = TH_0_MIN_FX; + move16(); + hMusicPF->LDm_thres_fx[1] = TH_1_MIN_FX; + move16(); + hMusicPF->LDm_thres_fx[2] = TH_2_MIN_FX; + move16(); + hMusicPF->LDm_thres_fx[3] = TH_3_MIN_FX; + move16(); + + hMusicPF->LDm_nb_thr_1_fx = 0; + move16(); + hMusicPF->LDm_nb_thr_3_fx = 0; + move16(); + hMusicPF->LDm_mem_etot_fx = 0; + move16(); + + FOR(i = 0; i < VOIC_BINS_HR; i++) + { + hMusicPF->LDm_enh_lp_gbin_fx[i] = 16384; + move16(); + hMusicPF->LDm_enh_lf_EO_fx[i] = 328; + move16(); + } + + FOR(i = 0; i < MBANDS_GN_LD; i++) + { + hMusicPF->LDm_bckr_noise_fx[i] = E_MIN_Q15; + move16(); + } + set16_fx(hMusicPF->filt_lfE_fx, 4096, DCT_L_POST); + move16(); + hMusicPF->last_nonfull_music_fx = 0; + move16(); + hMusicPF->Old_ener_Q = 0; + move16(); + + return; +} diff --git a/lib_dec/TonalComponentDetection.c b/lib_dec/TonalComponentDetection.c index ebdd9f8..3c0e6ac 100644 --- a/lib_dec/TonalComponentDetection.c +++ b/lib_dec/TonalComponentDetection.c @@ -5,79 +5,81 @@ #define _USE_MATH_DEFINES #include -#include "stl.h" - +#include #include "options.h" #include "prot_fx.h" #include "cnst_fx.h" #include "rom_basop_util.h" #include "basop_util.h" - -/***********************************************************************************/ -/* forward declaration for local functions, see implementation at end of this file */ -/***********************************************************************************/ -static void calcPseudoSpec(Word32 * mdctSpec, Word16 mdctSpec_exp, Word16 nSamples, Word16 floorPowerSpectrum, Word32 * powerSpec, Word16 * powerSpec_exp); -static void getEnvelope(Word16 nSamples, Word32 const * powerSpec, Word16 F0, Word32 * envelope, Word32 * smoothedSpectrum); -static void GetF0(Word16 const nSamples, - Word16 const nSamplesCore, - Word32 const * const powerSpectrum, Word32 const pitchLag, Word16 * const pOrigF0, Word16 * const pF0); -static void findStrongestHarmonics(Word16 nSamples, Word32 const * powerSpectrum, Word16 F0, Word16 nTotalHarmonics, Word16 * pHarmonicIndexes, Word16 * pnHarmonics); -static void CorrectF0(Word16 const * pHarmonicIndexes, Word16 const nHarmonics, Word16 * pF0); -static void findCandidates(Word16 nSamples, - Word32 * MDCTSpectrum, /* i: MDCT spectrum */ - Word16 MDCTSpectrum_exp, Word16 * thresholdModificationNew - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ - ); +/*---------------------------------------------------------------------* + * Local function prototypes + *---------------------------------------------------------------------*/ +static void calcPseudoSpec(const Word32 * mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 * powerSpec, Word16 * powerSpec_exp); +static void getEnvelope(const Word16 nSamples, const Word32 * powerSpec, Word16 F0, Word32 * envelope, Word32 * smoothedSpectrum); +static void GetF0(Word16 const nSamples,Word16 const nSamplesCore,Word32 const * const powerSpectrum, Word32 const pitchLag, Word16 * const pOrigF0, Word16 * const pF0); +static void findStrongestHarmonics(const Word16 nSamples, const Word32 * powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 * pHarmonicIndexes, Word16 * pnHarmonics); +static void CorrectF0(const Word16 * pHarmonicIndexes, const Word16 nHarmonics, Word16 * pF0); +static void findCandidates(const Word16 nSamples, const Word32 * MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 * thresholdModificationNew, Word16 floorPowerSpectrum ); static void modifyThreshold(Word16 i, Word16 F0, Word16 threshold, Word16 * thresholdModification); static void modifyThresholds(Word16 F0, Word16 origF0, Word16 * thresholdModification); -static void RefineThresholdsUsingPitch(Word16 nSamples, - Word16 nSamplesCore, - Word32 const powerSpectrum[], - Word32 lastPitchLag, - Word32 currentPitchLag, - Word16 * pF0, - Word16 * thresholdModification); - +static void RefineThresholdsUsingPitch(const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 * pF0, Word16 * thresholdModification); static void findTonalComponents(Word16 * indexOfTonalPeak, Word16 * lowerIndex, Word16 * upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 * powerSpectrum, Word16 F0, Word16 * thresholdModification); -/*******************************************************/ -/*-------------- public functions -------------------- */ -/*******************************************************/ - -/* Detect tonal components in the lastMDCTSpectrum, use +/*-------------------------------------------------------------------* + * DetectTonalComponents() + * + * Detect tonal components in the lastMDCTSpectrum, use * secondLastPowerSpectrum for the precise location of the peaks and * store them in indexOfTonalPeak. Updates lowerIndex, upperIndex, - * pNumIndexes accordingly. */ -void DetectTonalComponents(Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 * pNumIndexes, - Word32 lastPitchLag, Word32 currentPitchLag, - Word16 const lastMDCTSpectrum[], - Word16 lastMDCTSpectrum_exp, - Word16 const scaleFactors[], - Word16 const scaleFactors_exp[], - Word16 const scaleFactors_max_e, - Word32 const secondLastPowerSpectrum[], - Word16 nSamples - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ - ) + * pNumIndexes accordingly. + *-------------------------------------------------------------------*/ +void DetectTonalComponents( + Word16 indexOfTonalPeak[], + Word16 lowerIndex[], + Word16 upperIndex[], + Word16* pNumIndexes, + const Word32 lastPitchLag, + const Word32 currentPitchLag, + const Word16 lastMDCTSpectrum[], + const Word16 lastMDCTSpectrum_exp, + const Word16 scaleFactors[], + const Word16 scaleFactors_exp[], + const Word16 scaleFactors_max_e, + const Word32 secondLastPowerSpectrum[], + const Word16 nSamples, + const Word16 nSamplesCore, + Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ +#ifdef IVAS_CODE_MDCT_GSHAPE + , const PsychoacousticParameters* psychParamsCurrent +#endif +) { Word16 F0; - Word16 thresholdModification[L_FRAME_MAX]; + Word16 thresholdModification[L_FRAME_MAX], lastMDCTSpect_exp; Word32 pScaledMdctSpectrum[L_FRAME_MAX]; +#ifdef IVAS_CODE_MDCT_GSHAPE + Word16 nBands; + IF (psychParamsCurrent == NULL) + { + nBands = FDNS_NPTS; + PMT("add nBands argument to mdct_shaping_16") +#endif - mdct_shaping_16(lastMDCTSpectrum, nSamplesCore, nSamples, - scaleFactors, scaleFactors_exp, - scaleFactors_max_e, pScaledMdctSpectrum); - lastMDCTSpectrum_exp = add(lastMDCTSpectrum_exp, scaleFactors_max_e); + mdct_shaping_16(lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum); +#ifdef IVAS_CODE_MDCT_GSHAPE + } + ELSE + { + sns_shape_spectrum(pScaledMdctSpectrum, psychParamsCurrent, scaleFactors, nSamplesCore); + nBands = psychParamsCurrent->nBands; + } +#endif + + lastMDCTSpect_exp = add(lastMDCTSpectrum_exp, scaleFactors_max_e); /* Find peak candidates in the last frame. */ - findCandidates(nSamples, pScaledMdctSpectrum, lastMDCTSpectrum_exp, thresholdModification - , floorPowerSpectrum - ); + findCandidates(nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum); /* Refine peak candidates using the pitch information */ RefineThresholdsUsingPitch(nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification); @@ -86,28 +88,38 @@ void DetectTonalComponents(Word16 indexOfTonalPeak[], findTonalComponents(indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, F0, thresholdModification); } +/*-------------------------------------------------------------------* + * RefineTonalComponents() + * + *-------------------------------------------------------------------*/ /* When called, the tonal components are already stored in * indexOfTonalPeak. Detect tonal components in the lastMDCTSpectrum, * use secondLastPowerSpectrum for the precise location of the peaks and * then keep in indexOfTonalPeak only the tonal components that are * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ -void RefineTonalComponents(Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 phaseDiff[], - Word16 phases[], Word16 * pNumIndexes, - Word32 lastPitchLag, Word32 currentPitchLag, - Word16 const lastMDCTSpectrum[], - Word16 const lastMDCTSpectrum_exp, - Word16 const scaleFactors[], - Word16 const scaleFactors_exp[], - Word16 const scaleFactors_max_e, - Word32 const secondLastPowerSpectrum[], - Word16 nSamples - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ - ) +void RefineTonalComponents( + Word16 indexOfTonalPeak[], + Word16 lowerIndex[], + Word16 upperIndex[], + Word16 phaseDiff[], + Word16 phases[], + Word16 * pNumIndexes, + const Word32 lastPitchLag, + const Word32 currentPitchLag, + const Word16 lastMDCTSpectrum[], + const Word16 lastMDCTSpectrum_exp, + const Word16 scaleFactors[], + const Word16 scaleFactors_exp[], + const Word16 scaleFactors_max_e, + const Word32 secondLastPowerSpectrum[], + const Word16 nSamples, + const Word16 nSamplesCore, + const Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ +#ifdef IVAS_CODE_MDCT_GSHAPE + ,const PsychoacousticParameters* psychParamsCurrent +#endif +) { Word16 newIndexOfTonalPeak[MAX_NUMBER_OF_IDX]; Word16 newLowerIndex[MAX_NUMBER_OF_IDX]; @@ -117,21 +129,12 @@ void RefineTonalComponents(Word16 indexOfTonalPeak[], Word16 * pOldPhase, * pNewPhase; - DetectTonalComponents(newIndexOfTonalPeak, - newLowerIndex, - newUpperIndex, - &newNumIndexes, - lastPitchLag, - currentPitchLag, - lastMDCTSpectrum, - lastMDCTSpectrum_exp, - scaleFactors, - scaleFactors_exp, - scaleFactors_max_e, - secondLastPowerSpectrum, - nSamples, - nSamplesCore, - floorPowerSpectrum); + DetectTonalComponents(newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, + lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, nSamples, nSamplesCore, floorPowerSpectrum +#ifdef IVAS_CODE_MDCT_GSHAPE + , psychParamsCurrent +#endif + ); nPreservedPeaks = 0; move16(); @@ -185,18 +188,20 @@ void RefineTonalComponents(Word16 indexOfTonalPeak[], } *pNumIndexes = nPreservedPeaks; move16(); - + return; } -/***************************************************** ----------------- private functions ------------------- -******************************************************/ -static void calcPseudoSpec(Word32 * mdctSpec, /* i: MDCT spectrum */ - Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - Word16 nSamples, /* i: frame size */ - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word32 * powerSpec, /* o: estimated power spectrum */ - Word16 * powerSpec_exp) /* o: exponent of estimated power spectrum */ +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ +static void calcPseudoSpec( + const Word32 * mdctSpec, /* i: MDCT spectrum */ + const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ + const Word16 nSamples, /* i: frame size */ + Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ + Word32 * powerSpec, /* o: estimated power spectrum */ + Word16 * powerSpec_exp /* o: exponent of estimated power spectrum */ +) { Word16 k; Word32 x, L_tmp, L_tmp_floor; @@ -239,16 +244,18 @@ static void calcPseudoSpec(Word32 * mdctSpec, /* i: MDCT spectrum move32(); powerSpec[nSamples-1] = L_shr(powerSpec[nSamples-2], 1); move32(); + return; } #define LEVEL_EXP 3/*+4*/ -static void getEnvelope(Word16 nSamples, /*i: Q0 */ - Word32 const * powerSpec, /*i: powerSpec_exp */ - Word16 F0, /*i: 5Q10*/ - Word32 * envelope, /*o: powerSpec_exp + LEVEL_EXP*/ - Word32 * smoothedSpectrum /*o: powerSpec_exp + LEVEL_EXP*/ - ) +static void getEnvelope( + const Word16 nSamples, /*i: Q0 */ + const Word32* powerSpec, /*i: powerSpec_exp */ + Word16 F0, /*i: 5Q10*/ + Word32 * envelope, /*o: powerSpec_exp + LEVEL_EXP*/ + Word32 * smoothedSpectrum /*o: powerSpec_exp + LEVEL_EXP*/ +) { Word16 nFilterLength, nHalfFilterLength, nSecondHalfFilterLength, n1, n2; Word16 level, inv_len; @@ -330,16 +337,17 @@ static void getEnvelope(Word16 nSamples, /*i: move32(); smoothedSpectrum[0] = L_add(Mpy_32_16_1(powerSpec[1],3072/*0.75f Q12*/),L_shr(powerSpec[0],LEVEL_EXP)); smoothedSpectrum[nSamples-1] = L_add(Mpy_32_16_1(powerSpec[nSamples-2],3072/*0.75f Q12*/),L_shr(powerSpec[nSamples-1],LEVEL_EXP)); - + return; } -static void GetF0(Word16 /*int*/ const nSamples, /*i - Q0 */ - Word16 /*int*/ const nSamplesCore, /*i - Q0 */ - Word32 /*float*/ const * const powerSpectrum, /*i - Qx */ /*is justed handed over and given back*/ - Word32 /*float*/ const pitchLag, /*i - Q16*/ - Word16 /*float*/ * const pOrigF0, /*o - Q10*/ - Word16 /*float*/ * const pF0) /*o - Q10*/ +static void GetF0( + Word16 /*int*/ const nSamples, /*i - Q0 */ + Word16 /*int*/ const nSamplesCore, /*i - Q0 */ + Word32 /*float*/ const * const powerSpectrum, /*i - Qx */ /*is justed handed over and given back*/ + Word32 /*float*/ const pitchLag, /*i - Q16*/ + Word16 /*float*/ * const pOrigF0, /*o - Q10*/ + Word16 /*float*/ * const pF0) /*o - Q10*/ { Word16 /*float*/ tmpPitchLag; Word16 /*int*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; @@ -388,16 +396,18 @@ static void GetF0(Word16 /*int*/ const nSamples, /*i - Q0 *pF0 = 0; *pOrigF0 = 0; } - + return; } -static void findStrongestHarmonics(Word16 nSamples, - Word32 const * powerSpectrum, - Word16 F0/*5Q10*/, - Word16 nTotalHarmonics, - Word16 * pHarmonicIndexes, - Word16 * pnHarmonics) +static void findStrongestHarmonics( + const Word16 nSamples, + const Word32 * powerSpectrum, + const Word16 F0/*5Q10*/, + const Word16 nTotalHarmonics, + Word16 * pHarmonicIndexes, + Word16 * pnHarmonics +) { Word32 peaks[MAX_PEAKS_FROM_PITCH], smallestPeak; Word16 nPeaksToCheck, nPeaks, iSmallestPeak; @@ -472,13 +482,14 @@ static void findStrongestHarmonics(Word16 nSamples, *pnHarmonics = nPeaks; move16(); - + return; } /* Use new F0, for which harmonics are most common in pHarmonicIndexes */ -static void CorrectF0(Word16 /*int*/ const * pHarmonicIndexes, /*I - Q0 */ - Word16 /*int*/ const nHarmonics, /*I - Q0 */ - Word16 /*float*/ * pF0) /*I/O - Q10 range: {0}, [4..18) */ +static void CorrectF0( + const Word16 /*int*/ * pHarmonicIndexes, /*I - Q0 */ + const Word16 /*int*/ nHarmonics, /*I - Q0 */ + Word16 /*float*/ * pF0) /*I/O - Q10 range: {0}, [4..18) */ { Word16 /*int*/ i; Word16 /*float*/ F0; @@ -487,7 +498,15 @@ static void CorrectF0(Word16 /*int*/ const * pHarmonicIndexes, /*I - Q0 */ Word16 tmp; - +#ifdef IVAS_CODE + FOR (i = 0; i < MAX_PEAKS_FROM_PITCH - 1; i++) + { + diff[i] = 0; + sortedDiff[i] = 0; + move16)); + move16)); + } +#endif F0 = *pF0; test(); @@ -616,13 +635,14 @@ static void CorrectF0(Word16 /*int*/ const * pHarmonicIndexes, /*I - Q0 */ *pF0 = F0; move16(); } - + return; } -static void modifyThreshold(Word16 /*int*/ i, /*I - Q0 */ - Word16 /*float*/ F0, /*I - Q10*/ - Word16 /*float*/ threshold, /*I - Q10*/ - Word16* /*float*/ thresholdModification) /*I/O - Q10*/ +static void modifyThreshold( + Word16 /*int*/ i, /*I - Q0 */ + Word16 /*float*/ F0, /*I - Q10*/ + Word16 /*float*/ threshold, /*I - Q10*/ + Word16* /*float*/ thresholdModification) /*I/O - Q10*/ { Word32 harmonic; Word16 fractional /*Q15*/; @@ -642,19 +662,18 @@ static void modifyThreshold(Word16 /*int*/ i, /*I - Q0 thresholdModification[k-1] = add(threshold/*Q10*/, twoTimesFract/*Q10*/); /*Q10*/ move16(); thresholdModification[k+1] = add(threshold/*Q10*/, sub(2048/*2 in Q10*/, twoTimesFract/*Q10*/)/*Q10*/); /*Q10*/ - + return; } -static void modifyThresholds(Word16 /*float*/ F0, /*I - Q10*/ - Word16 /*float*/ origF0, /*I - Q10*/ - Word16* /*float*/ thresholdModification) /*I/O - Q10*/ +static void modifyThresholds( + Word16 /*float*/ F0, /*I - Q10*/ + Word16 /*float*/ origF0, /*I - Q10*/ + Word16* /*float*/ thresholdModification) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; - - IF (origF0 > 0) { IF (F0 == 0) @@ -684,15 +703,16 @@ static void modifyThresholds(Word16 /*float*/ F0, /*I } } } - + return; } -static void findCandidates(Word16 nSamples, /* i: frame size */ - Word32 * MDCTSpectrum, /* i: MDCT spectrum */ - Word16 MDCTSpectrum_exp, /* i: exponent of MDCT spectrum */ - Word16 * thresholdModificationNew /* o: threshold modification Q10 */ - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ - ) +static void findCandidates( + const Word16 nSamples, /* i: frame size */ + const Word32 * MDCTSpectrum, /* i: MDCT spectrum */ + const Word16 MDCTSpectrum_exp, /* i: exponent of MDCT spectrum */ + Word16 * thresholdModificationNew, /* o: threshold modification Q10 */ + Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ +) { Word32 powerSpectrum[L_FRAME_MAX]; Word16 powerSpectrum_exp; @@ -818,16 +838,17 @@ static void findCandidates(Word16 nSamples, /* i: frame siz } k = add(k, 1); } - + return; } -static void RefineThresholdsUsingPitch(Word16 nSamples, - Word16 nSamplesCore, - Word32 const powerSpectrum[], - Word32 lastPitchLag, - Word32 currentPitchLag, - Word16 * pF0, - Word16 * thresholdModification) +static void RefineThresholdsUsingPitch( + const Word16 nSamples, + const Word16 nSamplesCore, + const Word32 powerSpectrum[], + const Word32 lastPitchLag, + const Word32 currentPitchLag, + Word16 * pF0, + Word16 * thresholdModification) { Word16 pitchIsStable; Word16 origF0; @@ -856,17 +877,18 @@ static void RefineThresholdsUsingPitch(Word16 nSamples, *pF0 = 0; move16(); } - + return; } -static void findTonalComponents(Word16 * indexOfTonalPeak, /* OUT */ - Word16 * lowerIndex, /* OUT */ - Word16 * upperIndex, /* OUT */ - Word16 *numIndexes, /* OUT */ - Word16 nSamples, /* IN */ - const Word32 * powerSpectrum, /* IN */ - Word16 F0, /* IN */ - Word16 * thresholdModification) /* IN */ +static void findTonalComponents( + Word16 * indexOfTonalPeak, /* OUT */ + Word16 * lowerIndex, /* OUT */ + Word16 * upperIndex, /* OUT */ + Word16 *numIndexes, /* OUT */ + Word16 nSamples, /* IN */ + const Word32 * powerSpectrum, /* IN */ + Word16 F0, /* IN */ + Word16 * thresholdModification) /* IN */ { Word32 envelope[L_FRAME_MAX]; Word32 smoothedSpectrum[L_FRAME_MAX]; @@ -1008,6 +1030,6 @@ static void findTonalComponents(Word16 * indexOfTonalPeak, /* OUT */ *numIndexes = nrOfFIS; move16(); - + return; } diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 3087b3d..9f04094 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -2,13 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include +#include #include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_mpy.h" +#include "ivas_cnst.h" /* Common constants */ +#include "cnst_fx.h" /* Common constants */ /*==========================================================================*/ /* FUNCTION : void acelp_core_dec_fx () */ @@ -35,17 +36,28 @@ /* CALLED FROM : RX */ /*==========================================================================*/ -void acelp_core_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ - Word16 coder_type_fx, /* i : coder type */ +ivas_error acelp_core_dec_fx( + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + Word16 output[], /* o : synthesis @internal Fs */ + Word16 synth_out[], /* o : synthesis */ + Word16 save_hb_synth[], /* o : HB synthesis */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits, /* o : number of unused bits */ - Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 *unbits, /* o : number of unused bits */ + Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD,/* i/o: TD stereo decoder handle */ + const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ + const Word16 nchan_out, /* i : number of output channels */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ + const Word16 read_sid_info /* i : read SID info flag */ ) { Word16 old_exc_fx[L_EXC_DEC] = {0}, *exc_fx; /* excitation signal buffer (Q0) */ @@ -93,7 +105,101 @@ void acelp_core_dec_fx( Word32 imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 LSF_Q_prediction; /* o : LSF prediction mode */ Word16 avoid_lpc_burst_on_recovery; + Word16 uc_two_stage_flag, dec; + Word16 nb_bits, indice; + Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; +#ifdef ADD_LRTD + Word16 * p_tdm_Pri_pitch_buf; +#endif + MUSIC_POSTFILT_HANDLE hMusicPF; + BPF_DEC_HANDLE hBPF; + TD_BWE_DEC_HANDLE hBWE_TD; + FD_BWE_DEC_HANDLE hBWE_FD; + TCX_DEC_HANDLE hTcxDec; + ivas_error error; +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Array(tdm_lspQ_PCh); MY_UNUSED_Array(tdm_lsfQ_PCh); + MY_UNUSED_Word(use_cldfb_for_dft); + MY_UNUSED_Word(last_element_mode); + MY_UNUSED_Word32(last_element_brate); MY_UNUSED_Word(flag_sec_CNA); MY_UNUSED_Word(nchan_out); + MY_UNUSED_Array(save_hb_synth); MY_UNUSED_Array(output); + MY_UNUSED_Word(read_sid_info); + + (void*)hStereoCng; +#endif + hMusicPF = st_fx->hMusicPF; + hBPF = st_fx->hBPF; + hBWE_TD = st_fx->hBWE_TD; + hBWE_FD = st_fx->hBWE_FD; + hTcxDec = st_fx->hTcxDec; + error = IVAS_ERR_OK; + + IF ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_32(last_element_brate, IVAS_SID_4k4) ) + { + /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ + return error; + } + + +#ifdef IVAS_CODE + output_frame = (int16_t)(st->output_Fs / FRAMES_PER_SEC); + + /*----------------------------------------------------------------* + * stereo SID and CNG frames processing + *----------------------------------------------------------------*/ + + if (st->core_brate <= SID_2k40 && st->element_mode == IVAS_CPE_DFT && nchan_out == 2) + { + if (st->cng_type == FD_CNG) + { + configureFdCngDec(st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode); + + /* Only run parameter decoding in SID frames */ + if (st->core_brate == SID_2k40) + { + FdCng_decodeSID(st); + } + + for (i = 0; i < NPART; i++) + { + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + (1 - STEREO_DFT_FD_FILT) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; + } + +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ApplyFdCng(NULL, NULL, NULL, NULL, st, 0, 0); +#else + ApplyFdCng(NULL, NULL, NULL, NULL, st, 0, 0); +#endif + } + else + { + configureFdCngDec(st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode); + + /* decode CNG parameters */ + CNG_dec(st, last_element_mode, Aq, lsp_new, lsf_new, &allow_cn_step, sid_bw, q_env); + + /* comfort noise generation */ + CNG_exc(st->core_brate, st->L_frame, &st->hTdCngDec->Enew, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener, st->last_core_brate, &st->first_CNG, &(st->hTdCngDec->cng_ener_seed), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->hTdCngDec->num_ho, q_env, st->hTdCngDec->lp_env, st->hTdCngDec->old_env, st->hTdCngDec->exc_mem, st->hTdCngDec->exc_mem1, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode); + + mvr2r(Aq, st->Aq_cng, M + 1); + + /* update old LSP and LSF vector */ + mvr2r(lsf_new, st->lsf_old, M); + mvr2r(lsp_new, st->lsp_old, M); + } + set_f(output, 0, output_frame); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ + set_f(synth, 0, output_frame); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ + + /* CN generation done in DFT domain */ + wmops_sub_end(); + return error; + } + + /*----------------------------------------------------------------* + * Active frames processing + *----------------------------------------------------------------*/ +#endif FOR( i=0; ibpf_off_fx = 0; move16(); - if( EQ_16(st_fx->last_core_fx,HQ_CORE)) + test(); test(); test(); test(); + IF ( EQ_16(st_fx->last_core_fx, HQ_CORE) || EQ_16(st_fx->last_core_fx, TCX_20_CORE) || EQ_16(st_fx->last_core_fx, TCX_10_CORE) || (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && LE_32(st_fx->last_core_brate_fx, SID_2k40)) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && LE_32(st_fx->last_core_brate_fx, SID_2k40) )) { /* in case of HQ->ACELP switching, do not apply BPF */ st_fx->bpf_off_fx = 1; move16(); /* in case of core switching, reset post-filter memories */ - st_fx->pfstat.on = 0; + IF (st_fx->hPFstat != NULL) + { + st_fx->hPFstat->on = 0; + } move16(); /* reset the GSC pre echo energy threshold in case of switching */ - st_fx->Last_frame_ener_fx = MAX_32; + IF (st_fx->hGSCDec != NULL) + { + st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + } move32(); } if(st_fx->prev_bfi_fx > 0) { /* reset the GSC pre echo energy threshold in case of FEC */ - st_fx->Last_frame_ener_fx = MAX_32; + IF(st_fx->hGSCDec != NULL) + { + st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + } move32(); } +#ifdef IVAS_CODE + if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && (st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA)) + { + set_zero(st->hFdCngDec->hFdCngCom->olapBufferSynth2, FFTLEN); + set_zero(hStereoCng->olapBufferSynth22, FFTLEN); + } +#endif st_fx->clas_dec = st_fx->last_good_fx; move16(); enr_q_fx = 0; @@ -151,10 +274,25 @@ void acelp_core_dec_fx( Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); exc_fx = old_exc_fx + L_EXC_MEM_DEC; move16(); - Copy( st_fx->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); + IF (st_fx->hWIDec != NULL) + { + Copy(st_fx->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM); + } + ELSE + { + set16_fx(old_exc2_fx, 0, L_EXC_MEM); + } exc2_fx = old_exc2_fx + L_EXC_MEM; - Copy( st_fx->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; + IF (st_fx->hBWE_TD != NULL) + { + Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); + bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; + } + ELSE + { + bwe_exc_fx = NULL; + } + move16(); last_pulse_pos = 0; move16(); @@ -186,12 +324,14 @@ void acelp_core_dec_fx( } /* reset post-filter in case post-filtering was off in previous frame */ - if( st_fx->pfstat.on == 0 ) + IF(st_fx->hPFstat != NULL) { - st_fx->pfstat.reset = 1; - move16(); + if (st_fx->hPFstat->on == 0) + { + st_fx->hPFstat->reset = 1; + move16(); + } } - avoid_lpc_burst_on_recovery = 0; move16(); test(); @@ -201,23 +341,51 @@ void acelp_core_dec_fx( avoid_lpc_burst_on_recovery = 1; move16(); } - + /* TD stereo parameters */ + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && st_fx->idchan == 1) + { + tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; + tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; + tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; +#ifdef ADD_LRTD + p_tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf; +#endif + move16(); move16(); move16(); move16(); + } + else + { + tdm_lp_reuse_flag = 0; + tdm_low_rate_mode = 0; + move16(); move16(); + test(); + IF (EQ_16(st_fx->element_mode, IVAS_SCE) && st_fx->low_rate_mode) + { + tdm_low_rate_mode = 1; + move16(); + } + tdm_Pitch_reuse_flag = 0; +#ifdef ADD_LRTD + p_tdm_Pri_pitch_buf = NULL; +#endif + move16(); move16(); + } /*----------------------------------------------------------------* * Updates in case of internal sampling rate switching *----------------------------------------------------------------*/ test(); - IF( NE_16(st_fx->last_L_frame_fx,st_fx->L_frame_fx)&&NE_16(st_fx->last_core_fx,HQ_CORE)) + test(); + IF (NE_16(st_fx->last_L_frame_fx, st_fx->L_frame_fx) && (EQ_16(st_fx->last_core_fx, ACELP_CORE) || EQ_16(st_fx->last_core_fx, AMR_WB_CORE))) { - if( st_fx->pfstat.on != 0 ) + if( st_fx->hPFstat->on != 0 ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; mem_syn_r_size_old = shr(st_fx->last_L_frame_fx, 4); mem_syn_r_size_new = shr(st_fx->L_frame_fx, 4); - lerp( st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } - /* convert quantized LSP vector */ st_fx->rate_switching_reset=lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame_fx, 0); /* convert old quantized LSF vector */ @@ -229,7 +397,7 @@ void acelp_core_dec_fx( Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); /* Reset LPC mem */ - IF( EQ_32(st_fx->sr_core,16000)) + IF( EQ_32(st_fx->sr_core, INT_FS_16k)) { Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); } @@ -238,9 +406,20 @@ void acelp_core_dec_fx( Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); } set16_fx( st_fx->mem_MA_fx,0, M ); +#if 1//def IVAS_CODE + dec = DEC; + move16(); + IF (NE_16(st_fx->element_mode, EVS_MONO)) + { + dec = DEC_IVAS; + move16(); + } /* update synthesis filter memories */ + synth_mem_updt2( st_fx->L_frame_fx, st_fx->last_L_frame_fx, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, dec ); +#else synth_mem_updt2( st_fx->L_frame_fx, st_fx->last_L_frame_fx, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); +#endif Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); Copy_Scale_sig(st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn)); /*Q-1*/ @@ -383,17 +562,29 @@ void acelp_core_dec_fx( { /*----------------------------------------------------------------* - * Decoding of TC subframe clasification + * Decoding of TC subframe classification *----------------------------------------------------------------*/ tc_subfr_fx = -1; move16(); - if( EQ_16(coder_type_fx,TRANSITION)) + if( EQ_16(st_fx->coder_type_fx,TRANSITION)) { tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame_fx ); move16(); } - +#if 1//def IVAS_CODE + /*----------------------------------------------------------------* + * Decoding of GSC IVAS mode + *----------------------------------------------------------------*/ + st_fx->GSC_IVAS_mode = 0; + IF (GT_16(st_fx->element_mode, EVS_MONO) && st_fx->idchan == 0 && !(EQ_32(st_fx->core_brate_fx, FRAME_NO_DATA) || EQ_32(st_fx->core_brate_fx, SID_2k40)) && !tdm_low_rate_mode) + { + IF (EQ_16(st_fx->coder_type_fx, AUDIO) || (EQ_16(st_fx->coder_type_fx, INACTIVE) && LE_32(st_fx->total_brate_fx, MAX_GSC_INACTIVE_BRATE))) + { + st_fx->GSC_IVAS_mode = get_next_indice_fx(st_fx, 2); + } + } +#endif /*----------------------------------------------------------------* * Decoding of inactive CNG frames *----------------------------------------------------------------*/ @@ -404,23 +595,60 @@ void acelp_core_dec_fx( IF ( EQ_16(st_fx->cng_type_fx,LP_CNG)) { - CNG_dec_fx( st_fx, st_fx->L_frame_fx, Aq_fx, st_fx->core_brate_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); - + CNG_dec_fx( st_fx, st_fx->last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); +#ifdef IVAS_CODE + local_element_mode = st_fx->element_mode; + move16(); + IF ((EQ_16(nchan_out, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) || EQ_16(st_fx->masa_sid_format,1)) + { + local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ + move16(); + } +#endif /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate_fx, st_fx->L_frame_fx, &st_fx->Enew_fx, &st_fx->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, - &st_fx->first_CNG_fx, &(st_fx->cng_ener_seed_fx), bwe_exc_fx, allow_cn_step_fx, &st_fx->last_allow_cn_step_fx, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->num_ho_fx, - q_env, st_fx->lp_env_fx, st_fx->old_env_fx, st_fx->exc_mem_fx, st_fx->exc_mem1_fx, sid_bw, &st_fx->cng_ener_seed1_fx, exc3_fx ,st_fx->Opt_AMR_WB_fx ); + CNG_exc_fx( st_fx->core_brate_fx, st_fx->L_frame_fx, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, + &st_fx->first_CNG_fx, &(st_fx->hTdCngDec->cng_ener_seed_fx), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step_fx, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho_fx, + q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1_fx, exc3_fx ,st_fx->Opt_AMR_WB_fx, st_fx->element_mode ); +#if 1//def IVAS_CODE + Copy(Aq_fx, st_fx->Aq_cng, M + 1); +#endif + } ELSE { - IF( EQ_32(st_fx->core_brate_fx,SID_2k40)) + IF( EQ_32(st_fx->core_brate_fx,SID_2k40) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT) ) { FdCng_decodeSID(st_fx->hFdCngDec_fx->hFdCngCom, st_fx); *sid_bw=0; move16(); + } +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_DFT) + { + assert(nchan_out == 1); + + for (i = 0; i < NPART; i++) + { + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + (1 - STEREO_DFT_FD_FILT) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; + } +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ApplyFdCng(syn, 0, NULL, realBuffer, imagBuffer, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); +#else + ApplyFdCng(syn, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); +#endif } + if (!read_sid_info) + { + float noise_lvl_highest; - generate_comfort_noise_dec( NULL, NULL, NULL, st_fx, &(st_fx->Q_exc), 2 ); + noise_lvl_highest = st->hFdCngDec->hFdCngCom->cngNoiseLevel[st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand - 1]; + for (int16_t b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest; + } + } +#endif + generate_comfort_noise_dec( NULL, NULL, NULL, st_fx, &(st_fx->Q_exc), 2, -1 ); FdCng_exc(st_fx->hFdCngDec_fx->hFdCngCom, &st_fx->CNG_mode_fx, st_fx->L_frame_fx, st_fx->lsp_old_fx, st_fx->first_CNG_fx, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx); @@ -436,17 +664,25 @@ void acelp_core_dec_fx( move16(); } i = st_fx->Q_exc; - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame_fx, st_fx->L_frame_fx* HIBND_ACB_L_FAC, 0, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, INACTIVE); - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx,&st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 0, 0, NULL ); + &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx,&hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); Copy_Scale_sig(exc2_fx, exc2_fx, st_fx->L_frame_fx, sub(st_fx->Q_exc, i)); /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - + IF(hMusicPF != NULL) + { + Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2); + Copy(exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST - L_FRAME - OFFSET2), L_FRAME); + /* Update music post processing values */ + /* Filter energies update */ + FOR(i = 0; i < DCT_L_POST; i++) + { + /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, hMusicPF->filt_lfE_fx[i])); + } + } /* synthesis at 12.8kHz sampling rate */ syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc3_fx, syn1_fx, st_fx->mem_syn3_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -460,17 +696,13 @@ void acelp_core_dec_fx( /* update old synthesis for classification */ Copy( syn1_fx + st_fx->L_frame_fx - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac((1228<<(16)), 22938, st_fx->filt_lfE_fx[i])); - } /* save and delay synthesis to be used by SWB BWE */ Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame_fx, sub(-1,st_fx->Q_syn)); - save_old_syn_fx( st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx); + IF (hBWE_FD != NULL) + { + save_old_syn_fx(st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx); + } } /*----------------------------------------------------------------* @@ -479,12 +711,47 @@ void acelp_core_dec_fx( ELSE { + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + nb_bits = 0; + st_fx->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; + move16(); move16(); move16(); + test(); + IF (!st_fx->nelp_mode_dec_fx && !st_fx->ppp_mode_dec_fx) + { + Word16 tc_subfr_tmp; + + tc_subfr_tmp = tc_subfr_fx; + move16(); + IF (LT_16(tc_subfr_tmp, L_SUBFR)) + { + tc_subfr_tmp = 0; + move16(); + } + + IF (EQ_16(tc_subfr_fx, TC_0_192)) + { + nb_bits = -1; + move16(); + } + + config_acelp1(DEC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame_fx, st_fx->GSC_noisy_speech_fx, &(st_fx->acelp_cfg), st_fx->next_bit_pos_fx, st_fx->coder_type_fx, tc_subfr_tmp, 1, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + + test(); test(); test(); + IF (EQ_16(st_fx->coder_type_fx, TRANSITION) && LT_16(tc_subfr_fx, L_SUBFR) && EQ_16(st_fx->L_frame_fx, L_FRAME)) + { + config_acelp1(DEC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame_fx, -1, &(st_fx->acelp_cfg), st_fx->next_bit_pos_fx, st_fx->coder_type_fx, tc_subfr_fx, 2, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + } + } + /*-----------------------------------------------------------------* * After CNG period, use the most up-to-date LSPs *-----------------------------------------------------------------*/ - test(); - IF ( st_fx->last_core_brate_fx == FRAME_NO_DATA || EQ_32(st_fx->last_core_brate_fx,SID_2k40)) + test(); test(); + IF (st_fx->hTdCngDec != NULL && (st_fx->last_core_brate_fx == FRAME_NO_DATA || EQ_32(st_fx->last_core_brate_fx,SID_2k40))) { Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); @@ -501,6 +768,10 @@ void acelp_core_dec_fx( move16(); st_fx->last_nq_preQ_fx = 0; move16(); +#ifdef IVAS_CODE + st_fx->last_code_preq = 0; + move16(); +#endif } st_fx->use_acelp_preq = 0; @@ -509,21 +780,100 @@ void acelp_core_dec_fx( /*-----------------------------------------------------------------* * LSF de-quantization and interpolation *-----------------------------------------------------------------*/ +#ifdef ADD_LRTD + if (!tdm_lp_reuse_flag) +#endif + { + lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx,&LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,tdm_lsfQ_PCh +#endif + ); + } +#ifdef ADD_LRTD + else + { + const float* pt_interp_2; +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if (st->active_cnt != 1) + { + int16_t beta_index; - lsf_dec_fx( st_fx, tc_subfr_fx, st_fx->L_frame_fx, coder_type_fx, st_fx->bwidth_fx, Aq_fx, - &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx ); + beta_index = get_next_indice(st, TDM_IC_LSF_PRED_BITS); + tdm_SCh_lsf_reuse(DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, &beta_index); + } + else + { + mvr2r(tdm_lspQ_PCh, lsp_new, M); + mvr2r(tdm_lsfQ_PCh, lsf_new, M); + } +#else + mvr2r(tdm_lspQ_PCh, lsp_new, M); + mvr2r(tdm_lsfQ_PCh, lsf_new, M); +#endif + if (st->rate_switching_reset) + { + /* extrapolation in case of unstable LSF convert */ + mvr2r(lsp_new, st->lsp_old, M); + mvr2r(lsf_new, st->lsf_old, M); + } + + pt_interp_2 = interpol_frac_12k8; + if (tdm_low_rate_mode == 1 && st->coder_type > UNVOICED) + { + pt_interp_2 = interpol_frac2; + } + if (st->active_cnt == 1) + { + mvr2r(lsp_new, st->lsp_old, M); + lsp2lsf(lsp_new, st->lsf_old, M, st->sr_core); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp(st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0); + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab(lsf_new, st->lsf_old, 0, st->L_frame); + } + + if (st->last_core == HQ_CORE && st->element_mode > EVS_MONO) + { + /* Prepare ACB memory from last HQ frame */ + old_exc_s = st->old_exc + L_EXC_MEM_DEC - st->L_frame; + tmpF = *old_exc_s; + st->mem_deemph = old_exc_s[st->L_frame - 1]; + preemph(old_exc_s, st->preemph_fac, L_FRAME16k, &tmpF); + mvr2r(old_exc_s + st->L_frame - M, st->mem_syn2, M); + residu(Aq, M, old_exc_s, old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame); + } + if (st->last_core != ACELP_CORE && st->element_mode > EVS_MONO) + { + /* Prepare ACB memory of old_bwe_exc */ +#ifdef CR_FIX_639_HQ_ACELP_TRANSITION + if (st->L_frame == L_FRAME) + { + lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); + } + else + { + lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC); + } +#else + lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); +#endif + } +#endif /*-----------------------------------------------------------------* * FEC - first good frame after lost frame(s) (possibility to correct the ACB) *-----------------------------------------------------------------*/ - IF( GE_32(st_fx->core_brate_fx,ACELP_11k60)) + IF( st_fx->acelp_cfg.FEC_mode > 0) { last_pulse_pos = 0; move16(); /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st_fx, coder_type_fx, st_fx->last_good_fx, &last_pulse_pos, &st_fx->clas_dec, &enr_q_fx, st_fx->core_brate_fx ); + T0_tmp = FEC_pos_dec_fx( st_fx, &last_pulse_pos, &enr_q_fx, nb_bits); move16(); test(); @@ -541,7 +891,7 @@ void acelp_core_dec_fx( st_fx->Q_exc = FEC_SinOnset_fx( old_exc_fx+L_EXC_MEM_DEC-L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame_fx, st_fx->Q_exc ); } - ELSE IF( (EQ_16(coder_type_fx,GENERIC)||EQ_16(coder_type_fx,VOICED))&&last_pulse_pos!=0&&EQ_16(st_fx->old_bfi_cnt_fx,1)&&EQ_16(output_frame,L_FRAME16k)) + ELSE IF( (EQ_16(st_fx->coder_type_fx,GENERIC) || EQ_16(st_fx->coder_type_fx,VOICED)) && last_pulse_pos!=0 && EQ_16(st_fx->old_bfi_cnt_fx,1) && EQ_16(output_frame,L_FRAME16k) && st_fx->hWIDec != NULL) { do_WI_fx = FEC_enhACB_fx( st_fx->L_frame_fx, st_fx->last_L_frame_fx, old_exc_fx+L_EXC_MEM_DEC-L_EXC_MEM , T0_tmp, last_pulse_pos, st_fx->bfi_pitch_fx ); } @@ -556,7 +906,8 @@ void acelp_core_dec_fx( test(); test(); test(); - IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt_fx > 0 && NE_16(st_fx->clas_dec,VOICED_CLAS)&&NE_16(st_fx->clas_dec,ONSET)&&st_fx->relax_prev_lsf_interp_fx==0) + IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt_fx > 0 && NE_16(st_fx->clas_dec,VOICED_CLAS) && NE_16(st_fx->clas_dec,ONSET) && + st_fx->relax_prev_lsf_interp_fx==0 && !(EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1))) { int_lsp4_fx(st_fx->L_frame_fx, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); } @@ -565,29 +916,36 @@ void acelp_core_dec_fx( * Decoding of the scaled predicted innovation energy *---------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16(coder_type_fx,UNVOICED)&& - NE_16(coder_type_fx,AUDIO) && - NE_16(coder_type_fx,INACTIVE) && - !(LE_32(st_fx->core_brate_fx,ACELP_8k00) && NE_16(coder_type_fx,TRANSITION) ) ) || - (EQ_16(coder_type_fx,INACTIVE) && GE_32(st_fx->total_brate_fx,ACELP_32k) ) - ) + IF (nb_bits > 0) { - Es_pred_dec_fx( st_fx, &Es_pred_fx, coder_type_fx, st_fx->core_brate_fx ); + indice = get_next_indice_fx(st_fx, nb_bits); + Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag); } /*------------------------------------------------------------* * Decode excitation according to coding type *------------------------------------------------------------*/ + test(); test(); test(); +#ifdef ADD_LRTD + IF (tdm_low_rate_mode) /* tdm stereo low rate mode */ + { + IF (LE_16(st_fx->coder_type_fx, UNVOICED)) + { + tdm_low_rate_dec(st_fx, dct_exc_tmp, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new); + } + ELSE /* GENERIC */ + { + decod_gen_2sbfr(st_fx, sharpFlag, Aq, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf); - test(); - test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + tmp_noise = st_fx->lp_gainc_fx; + move16(); + } + } + } + else +#endif IF( EQ_16(st_fx->nelp_mode_dec_fx,1)) { /* SC-VBR - NELP frames */ @@ -595,58 +953,72 @@ void acelp_core_dec_fx( st_fx->Q_exc = 0; move16(); - decod_nelp_fx( st_fx, coder_type_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, - voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi_fx, gain_buf ); - - Rescale_exc(st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, coder_type_fx); + decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx,voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi_fx, gain_buf ); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type_fx); } - ELSE IF( EQ_16(coder_type_fx,UNVOICED)) + ELSE IF( EQ_16(st_fx->coder_type_fx,UNVOICED)) { /* UNVOICED frames */ - decod_unvoiced_fx( st_fx, Aq_fx, coder_type_fx, &tmp_noise_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, gain_buf ); + decod_unvoiced_fx( st_fx, Aq_fx, st_fx->coder_type_fx, &tmp_noise_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, gain_buf ); } ELSE IF ( EQ_16(st_fx->ppp_mode_dec_fx,1)) { Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); st_fx->Q_exc = 0; /* SC-VBR - PPP frames */ - decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi_fx, gain_buf, voice_factors, bwe_exc_fx ); + IF ((error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi_fx, gain_buf, voice_factors, bwe_exc_fx )) != IVAS_ERR_OK) + { + return error; + } - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, coder_type_fx ); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type_fx ); } - ELSE IF( EQ_16(coder_type_fx,TRANSITION )) + ELSE IF( EQ_16(st_fx->coder_type_fx,TRANSITION )) { - decod_tran_fx( st_fx, st_fx->L_frame_fx, tc_subfr_fx, Aq_fx, coder_type_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); + decod_tran_fx( st_fx, st_fx->L_frame_fx, tc_subfr_fx, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); } - ELSE IF( EQ_16(coder_type_fx,AUDIO)||(EQ_16(coder_type_fx,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_24k40))) + ELSE IF( EQ_16(st_fx->coder_type_fx,AUDIO) || (EQ_16(st_fx->coder_type_fx,INACTIVE) && LE_32(st_fx->core_brate_fx, MAX_GSC_INACTIVE_BRATE))) { - decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, coder_type_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf ); + decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf +#ifdef ADD_LRTD + , tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf +#endif + ); tmp_noise_fx = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ } ELSE { - decod_gen_voic_fx( st_fx, st_fx->L_frame_fx, sharpFlag, Aq_fx, coder_type_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf ); + IF ((error = decod_gen_voic_fx(st_fx, st_fx->L_frame_fx, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf/*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/)) != IVAS_ERR_OK) + { + return error; + } + + IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + tmp_noise_fx = shr_r(st_fx->lp_gainc_fx, 3); /*Q0*/ + } } /* synthesis for ACELP core switching and SWB BWE */ syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); - + IF (hBWE_FD != NULL) + { + save_old_syn_fx(st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx); + } /*-----------------------------------------------------------------* * Apply energy matching when switching to inactive frames *-----------------------------------------------------------------*/ - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->lt_ener_per_band_fx, coder_type_fx, st_fx->L_frame_fx, st_fx->core_brate_fx, st_fx->Q_exc, st_fx->bfi_fx, st_fx->last_core_fx, st_fx->last_codec_mode ); - + Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->hGSCDec->lt_ener_per_band_fx, st_fx->coder_type_fx, st_fx->L_frame_fx, st_fx->core_brate_fx, st_fx->Q_exc, st_fx->bfi_fx, st_fx->last_core_fx, st_fx->last_codec_mode ); /*------------------------------------------------------------* * Decode information and modify the excitation signal of stationary unvoiced frames *------------------------------------------------------------*/ - - IF ( NE_16(st_fx->nelp_mode_dec_fx,1)) + test(); test(); test(); + IF (!(EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && NE_16(st_fx->nelp_mode_dec_fx, 1) && !(EQ_16(st_fx->element_mode, IVAS_SCE) && tdm_low_rate_mode)) { - stat_noise_uv_dec_fx( st_fx, coder_type_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx ); + stat_noise_uv_dec_fx( st_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag); } /*------------------------------------------------------------* @@ -655,37 +1027,46 @@ void acelp_core_dec_fx( *------------------------------------------------------------*/ /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - Copy( st_fx->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST-OFFSET2 ); - + IF(hMusicPF != NULL) + { + Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2); + Copy(exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST - L_FRAME - OFFSET2), L_FRAME); + Copy(hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2); + } test(); - IF( EQ_16(coder_type_fx, AUDIO )&&st_fx->GSC_noisy_speech_fx==0) + IF(hMusicPF != NULL && ((EQ_16(st_fx->coder_type_fx, AUDIO) && EQ_16(st_fx->GSC_noisy_speech_fx, 0)) || (GE_16(st_fx->GSC_IVAS_mode, 1) && EQ_16(st_fx->L_frame_fx, L_FRAME)))) { + Word16 last_coder_type = st_fx->last_coder_type_fx; + + if ( (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD)) || (GE_16(st_fx->GSC_IVAS_mode, 1) && st_fx->GSC_noisy_speech_fx == 0)) + { + last_coder_type = AUDIO; + } /* Extrapolation of the last future part, windowing and high resolution DCT transform */ qdct = 0; - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st_fx->filt_lfE_fx, st_fx->last_coder_type_fx, pitch_buf_fx, - st_fx->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); - +#ifdef _DIFF_FLOAT_FIX_ /* FLoat point using last_core which fits with the inner part of the function */ + Prep_music_postP_fx(exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core_fx, pitch_buf_fx, + hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct); +#else + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_coder_type_fx, pitch_buf_fx, + hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); +#endif /* LD music post-filter */ - LD_music_post_filter_fx( dct_buffer_fx, dct_buffer_fx, st_fx->core_brate_fx, &st_fx->LDm_last_music_flag_fx, - st_fx->LDm_thres_fx, &st_fx->LDm_nb_thr_1_fx, &st_fx->LDm_nb_thr_3_fx, st_fx->LDm_lt_diff_etot_fx, - &st_fx->LDm_mem_etot_fx, st_fx->LDm_enh_min_ns_gain_fx, st_fx->LDm_bckr_noise_fx, - st_fx->LDm_enh_lf_EO_fx, st_fx->LDm_enh_lp_gbin_fx, st_fx->filt_lfE_fx, &st_fx->last_nonfull_music_fx, - &st_fx->Old_ener_Q, AUDIO, st_fx->last_coder_type_fx, qdct ); + LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate_fx, + &hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ Post_music_postP_fx( dct_buffer_fx, exc2_fx, st_fx->mem_syn2_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, - &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx,0, &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, temp_buf_fx, mem_tmp_fx ); + &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx,0, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, + &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, temp_buf_fx, mem_tmp_fx ); } ELSE { /* Core synthesis at 12.8kHz or 16kHz */ i = 1; move16(); - if( EQ_16(coder_type_fx,INACTIVE)) + if( EQ_16(st_fx->coder_type_fx,INACTIVE)) { i = 0; move16(); @@ -695,23 +1076,24 @@ void acelp_core_dec_fx( move16(); test(); test(); - if( EQ_16(coder_type_fx, INACTIVE)&&st_fx->flag_cna&&GE_16(round_fx(L_shl(st_fx->lp_noise,1)),15<<7)) + if( EQ_16(st_fx->coder_type_fx, INACTIVE)&&st_fx->flag_cna&&GE_16(round_fx(L_shl(st_fx->lp_noise,1)),15<<7)) { k = 1; move16(); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, i, k, temp_buf_fx ); - + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, i, k, temp_buf_fx ); Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1 , st_fx->Q_exc, st_fx->Q_syn); - - FOR( i = 0; i < DCT_L_POST; i++ ) + IF(hMusicPF != NULL) { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac((1228<<(16)), 22938, st_fx->filt_lfE_fx[i])); + FOR(i = 0; i < DCT_L_POST; i++) + { + /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, hMusicPF->filt_lfE_fx[i])); + } } } @@ -719,18 +1101,18 @@ void acelp_core_dec_fx( * FEC - Estimate the classification information *------------------------------------------------------------*/ - FEC_clas_estim_fx( st_fx, st_fx->Opt_AMR_WB_fx, st_fx->L_frame_fx, &st_fx->clas_dec, coder_type_fx, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, &st_fx->decision_hyst_fx, - NULL, NULL, NULL, NULL, 0, NULL, st_fx->core_brate_fx, st_fx->Q_syn, temp_buf_fx, - st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate_fx ); + FEC_clas_estim_fx( st_fx, st_fx->Opt_AMR_WB_fx, st_fx->L_frame_fx, &st_fx->clas_dec, st_fx->coder_type_fx, pitch_buf_fx, + syn_fx, &st_fx->lp_ener_FER_fx, &st_fx->decision_hyst_fx, + NULL, NULL, NULL, NULL, 0, NULL, st_fx->core_brate_fx, st_fx->Q_syn, temp_buf_fx, + st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, + 0, 0, 0, st_fx->last_core_brate_fx, st_fx->acelp_cfg.FEC_mode); /*------------------------------------------------------------* * FEC - Estimate pitch *------------------------------------------------------------*/ FEC_pitch_estim_fx( st_fx->Opt_AMR_WB_fx, st_fx->last_core_fx, st_fx->L_frame_fx, st_fx->clas_dec, st_fx->last_good_fx, pitch_buf_fx, st_fx->old_pitch_buf_fx, - &st_fx->bfi_pitch_fx, &st_fx->bfi_pitch_frame_fx, &st_fx->upd_cnt_fx, coder_type_fx ); + &st_fx->bfi_pitch_fx, &st_fx->bfi_pitch_frame_fx, &st_fx->upd_cnt_fx, st_fx->coder_type_fx ); /*------------------------------------------------------------* * FEC - Smooth the speech energy evolution when recovering after a BAD frame @@ -746,12 +1128,12 @@ void acelp_core_dec_fx( k++; } - FEC_scale_syn_fx( st_fx->L_frame_fx, &update_flg, st_fx->clas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, coder_type_fx, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi_fx, st_fx->total_brate_fx, st_fx->prev_bfi_fx, st_fx->last_core_brate_fx, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn , avoid_lpc_burst_on_recovery, 0 ); + FEC_scale_syn_fx( st_fx->L_frame_fx, &update_flg, st_fx->clas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type_fx, LSF_Q_prediction, + &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi_fx, st_fx->total_brate_fx, st_fx->prev_bfi_fx, st_fx->last_core_brate_fx, + exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn , avoid_lpc_burst_on_recovery, 0 ); test(); - if( (EQ_32(st_fx->total_brate_fx,ACELP_7k20))||(EQ_32(st_fx->total_brate_fx,ACELP_8k00))) + IF((EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD) && LE_32(st_fx->total_brate_fx, ACELP_7k20) ) || (EQ_32(st_fx->total_brate_fx,ACELP_7k20))||(EQ_32(st_fx->total_brate_fx,ACELP_8k00))) { frame_ener_fx( st_fx->L_frame_fx, st_fx->clas_dec, syn_fx, pitch_buf_tmp[sub(shr(st_fx->L_frame_fx,6),1)], &st_fx->enr_old_fx, st_fx->L_frame_fx, st_fx->Q_syn, 3, 0 ); } @@ -782,8 +1164,8 @@ void acelp_core_dec_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); + st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame_fx, Aq_fx, lsf_new_fx, lsp_new_fx ); @@ -794,13 +1176,11 @@ void acelp_core_dec_fx( st_fx->Q_exc = 0; move16(); - decod_nelp_fx( st_fx, coder_type_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, - voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi_fx, gain_buf ); - + decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi_fx, gain_buf ); FEC_pitch_fx = pitch_buf_fx[3]; move16(); - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, coder_type_fx ); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type_fx ); } ELSE { @@ -808,8 +1188,8 @@ void acelp_core_dec_fx( FEC_exc_estim_fx( st_fx, st_fx->L_frame_fx, exc_fx, exc2_fx, dct_exc_tmp, pitch_buf_fx, voice_factors, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx ); - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, L_FRAME32k, (Word32)0, - &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, st_fx->L_frame_fx, st_fx->last_coder_type_fx ); + Rescale_exc( NULL, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame_fx, L_FRAME32k, (Word32)0, + &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, st_fx->L_frame_fx, st_fx->last_coder_type_fx ); tmp_noise_fx = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ @@ -822,29 +1202,46 @@ void acelp_core_dec_fx( syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /*old_syn_12k8_16k directly in q-1*/ /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); - + IF (hBWE_FD != NULL) + { + save_old_syn_fx( st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); + } /* Apply energy matching when switching to inactive frames */ - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->lt_ener_per_band_fx, coder_type_fx, st_fx->L_frame_fx, st_fx->core_brate_fx, st_fx->Q_exc, st_fx->bfi_fx, st_fx->last_core_fx, st_fx->last_codec_mode ); + Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->hGSCDec->lt_ener_per_band_fx, st_fx->coder_type_fx, st_fx->L_frame_fx, st_fx->core_brate_fx, st_fx->Q_exc, st_fx->bfi_fx, st_fx->last_core_fx, st_fx->last_codec_mode ); /* udate past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - + IF (hMusicPF != NULL) + { + Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + /* Update music post processing values */ + /* Filter energies update */ + FOR(i = 0; i < DCT_L_POST; i++) + { + /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, hMusicPF->filt_lfE_fx[i])); + } + /* Update circular buffer, keep last energy difference unchanged */ + FOR(i = 1; i < MAX_LT; i++) + { + hMusicPF->LDm_lt_diff_etot_fx[i - 1] = hMusicPF->LDm_lt_diff_etot_fx[i]; + move16(); + } + } /* synthesis at 12k8 Hz sampling rate */ /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ k = 0; move16(); test(); test(); - if( EQ_16(coder_type_fx, INACTIVE)&&st_fx->flag_cna&&GE_16(round_fx(L_shl(st_fx->lp_noise,1)),15<<7)) + if( EQ_16(st_fx->coder_type_fx, INACTIVE)&&st_fx->flag_cna&&GE_16(round_fx(L_shl(st_fx->lp_noise,1)),15<<7)) { k = 1; move16(); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 1, k, temp_buf_fx ); + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, k, temp_buf_fx ); if( (EQ_32(st_fx->total_brate_fx,ACELP_7k20))||(EQ_32(st_fx->total_brate_fx,ACELP_8k00))) { @@ -853,26 +1250,17 @@ void acelp_core_dec_fx( syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn); /* update buffer for classifier */ - Copy( exc2_fx + st_fx->L_frame_fx - L_EXC_MEM, st_fx->old_exc2_fx, L_EXC_MEM ); - Copy( syn_fx + st_fx->L_frame_fx - L_EXC_MEM, st_fx->old_syn2_fx, L_EXC_MEM ); + IF (st_fx->hWIDec != NULL) + { + Copy(exc2_fx + st_fx->L_frame_fx - L_EXC_MEM, st_fx->hWIDec->old_exc2_fx, L_EXC_MEM); + Copy(syn_fx + st_fx->L_frame_fx - L_EXC_MEM, st_fx->hWIDec->old_syn2_fx, L_EXC_MEM); + } st_fx->prev_Q_exc_fr = st_fx->Q_exc; st_fx->prev_Q_syn_fr = st_fx->Q_syn; Copy( syn_fx + st_fx->L_frame_fx - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac((1228<<(16)), 22938, st_fx->filt_lfE_fx[i])); - } - /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; iLDm_lt_diff_etot_fx[i-1] = st_fx->LDm_lt_diff_etot_fx[i]; - move16(); - } + if( (EQ_32(st_fx->total_brate_fx,ACELP_7k20))||(EQ_32(st_fx->total_brate_fx,ACELP_8k00))) { @@ -890,7 +1278,7 @@ void acelp_core_dec_fx( * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - FEC_scale_syn_fx( st_fx->L_frame_fx, &update_flg, st_fx->clas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, coder_type_fx, LSF_Q_prediction, + FEC_scale_syn_fx( st_fx->L_frame_fx, &update_flg, st_fx->clas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type_fx, LSF_Q_prediction, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi_fx, st_fx->total_brate_fx, st_fx->prev_bfi_fx, st_fx->last_core_brate_fx, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); } @@ -902,29 +1290,30 @@ void acelp_core_dec_fx( IF ( st_fx->nelp_mode_dec_fx !=1 ) { /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx( coder_type_fx, 0, st_fx->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st_fx->Q_exc, 1, &st_fx->ge_sm_fx, + stat_noise_uv_mod_fx( st_fx->coder_type_fx, 0, st_fx->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st_fx->Q_exc, 1, &st_fx->ge_sm_fx, &st_fx->uv_count_fx, &st_fx->act_count_fx, st_fx->lspold_s_fx, &st_fx->noimix_seed_fx, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate_fx,st_fx->bwidth_fx, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); } /* SC-VBR */ - st_fx->FadeScale_fx = mult(st_fx->FadeScale_fx,24576); /*24576 in Q15*/ + st_fx->hSC_VBR->FadeScale_fx = mult(st_fx->hSC_VBR->FadeScale_fx,24576); /*24576 in Q15*/ } - + IF(hBWE_TD != NULL) + { IF (EQ_16(st_fx->L_frame_fx,L_FRAME)) { - Copy( Aq_fx+2*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); + Copy( Aq_fx+2*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1) ); } ELSE { - Copy( Aq_fx+3*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); + Copy( Aq_fx+3*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1) ); + } } - /*--------------------------------------------------------* * Apply NB postfilter in case of 8kHz output *--------------------------------------------------------*/ - - IF( EQ_16(st_fx->last_bwidth_fx,NB)) + test(); + IF( EQ_16(st_fx->last_bwidth_fx,NB) && st_fx->hPFstat != NULL) { k = 0; move16(); @@ -937,15 +1326,15 @@ void acelp_core_dec_fx( IF(EQ_16(st_fx->bwidth_fx,NB)) { - st_fx->pfstat.on = 1; + st_fx->hPFstat->on = 1; move16(); - nb_post_filt( st_fx->L_frame_fx, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, coder_type_fx, st_fx->BER_detect, 0 ); + nb_post_filt( st_fx->L_frame_fx, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, st_fx->coder_type_fx, st_fx->BER_detect, 0 ); } ELSE { - st_fx->pfstat.on = 0; + st_fx->hPFstat->on = 0; move16(); - nb_post_filt( st_fx->L_frame_fx, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt( st_fx->L_frame_fx, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); } } ELSE @@ -965,38 +1354,42 @@ void acelp_core_dec_fx( Copy(syn_fx_tmp2, syn_fx, st_fx->L_frame_fx); /* Update MODE2 memories*/ - Copy_Scale_sig( syn_fx + st_fx->L_frame_fx/2, st_fx->old_syn_Overl, st_fx->L_frame_fx/2, sub(-1,st_fx->Q_syn)); /*Q-1*/ + IF(hTcxDec != NULL) + { + Copy_Scale_sig( syn_fx + st_fx->L_frame_fx/2, hTcxDec->old_syn_Overl, st_fx->L_frame_fx/2, sub(-1,st_fx->Q_syn)); /*Q-1*/ + } Copy_Scale_sig( syn_fx + st_fx->L_frame_fx-M-1, st_fx->syn, M+1, sub(0,st_fx->Q_syn)); /*Q0*/ /*------------------------------------------------------------------* * Formant post-filter *-----------------------------------------------------------------*/ - test(); - test(); - IF( GE_16(st_fx->last_bwidth_fx,WB)&>_32(st_fx->core_brate_fx,ACELP_24k40)&&LE_32(st_fx->core_brate_fx,ACELP_32k)) + IF(st_fx->hPFstat != NULL) + { + test(); test(); test(); + IF(GE_16(st_fx->last_bwidth_fx, WB) && (GT_32(st_fx->core_brate_fx, ACELP_24k40) || GT_16(st_fx->element_mode, EVS_MONO)) && LE_32(st_fx->core_brate_fx, ACELP_32k)) { Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); - st_fx->pfstat.on = 1; + st_fx->hPFstat->on = 1; move16(); - formant_post_filt( &(st_fx->pfstat), temp_buf + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME16k, st_fx->lp_noise, st_fx->total_brate_fx, 0); + formant_post_filt( st_fx->hPFstat, temp_buf + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME16k, st_fx->lp_noise, st_fx->total_brate_fx, 0); } ELSE IF( GE_16(st_fx->last_bwidth_fx,WB)) { - if( st_fx->pfstat.on ) + if( st_fx->hPFstat->on ) { - Copy( st_fx->pfstat.mem_pf_in+L_SYN_MEM-M, temp_buf, M ); + Copy( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-M, temp_buf, M ); Copy( syn_fx, temp_buf + M, L_SUBFR ); Residu3_fx ( Aq_fx, temp_buf + M, temp_buf+M+L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, Aq_fx, temp_buf+M+L_SUBFR, temp_buf, L_SUBFR, st_fx->pfstat.mem_stp+L_SYN_MEM-M, 0, M ); - scale_st ( syn_fx, temp_buf, &st_fx->pfstat.gain_prec, L_SUBFR ); + E_UTIL_synthesis ( 1, Aq_fx, temp_buf+M+L_SUBFR, temp_buf, L_SUBFR, st_fx->hPFstat->mem_stp+L_SYN_MEM-M, 0, M ); + scale_st ( syn_fx, temp_buf, &st_fx->hPFstat->gain_prec, L_SUBFR ); Copy( temp_buf, syn_fx, L_SUBFR/2 ); blend_subfr2( temp_buf + L_SUBFR/2, syn_fx + L_SUBFR/2, syn_fx + L_SUBFR/2 ); } - st_fx->pfstat.on = 0; + st_fx->hPFstat->on = 0; move16(); } - + } /*----------------------------------------------------------------* * Comfort noise addition *----------------------------------------------------------------*/ @@ -1005,66 +1398,173 @@ void acelp_core_dec_fx( test(); test(); test(); - IF( st_fx->flag_cna || (EQ_16(st_fx->cng_type_fx,FD_CNG)&&LE_32(st_fx->total_brate_fx,ACELP_32k))||(EQ_16(st_fx->cng_type_fx,LP_CNG)&&LE_32(st_fx->total_brate_fx,SID_2k40))) + IF((st_fx->hFdCngDec_fx != NULL || EQ_16(st_fx->idchan, 1)) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) { - /*VAD only for non inactive frame*/ - test(); - st_fx->VAD = st_fx->VAD && (coder_type_fx != INACTIVE); + IF(EQ_16(st_fx->element_mode, IVAS_CPE_TD) || st_fx->flag_cna || (EQ_16(st_fx->cng_type_fx, FD_CNG) && LE_32(st_fx->total_brate_fx, ACELP_32k)) || (EQ_16(st_fx->cng_type_fx, LP_CNG) && LE_32(st_fx->total_brate_fx, SID_2k40))) + { + /*VAD only for non inactive frame*/ + test(); + st_fx->VAD = st_fx->VAD && (st_fx->coder_type_fx != INACTIVE); - /*Noisy speech detector*/ - noisy_speech_detection( st_fx->VAD, syn_fx, st_fx->L_frame_fx, st_fx->Q_syn, st_fx->hFdCngDec_fx->msNoiseEst, st_fx->hFdCngDec_fx->msNoiseEst_exp, - st_fx->hFdCngDec_fx->psize_shaping_norm, st_fx->hFdCngDec_fx->psize_shaping_norm_exp, st_fx->hFdCngDec_fx->nFFTpart_shaping, - &(st_fx->hFdCngDec_fx->lp_noise), &(st_fx->hFdCngDec_fx->lp_speech), &(st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech) ); + IF(st_fx->idchan == 0 && (st_fx->flag_cna || (EQ_16(st_fx->cng_type_fx, FD_CNG) && LE_32(st_fx->total_brate_fx, ACELP_32k)) || + (EQ_16(st_fx->cng_type_fx, LP_CNG) && LE_32(st_fx->total_brate_fx, SID_2k40)))) + { + /*Noisy speech detector*/ + noisy_speech_detection(st_fx->hFdCngDec_fx, st_fx->VAD, syn_fx, st_fx->Q_syn); - st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = mult_r(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF ( st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech != 0 ) - { - st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = add(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); - move16(); - } - st_fx->lp_noise = st_fx->hFdCngDec_fx->lp_noise; - move32(); + st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = mult_r(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); + IF(st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech != 0) + { + st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = add(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); + move16(); + } + } + IF(st_fx->idchan == 0) + { + st_fx->lp_noise = st_fx->hFdCngDec_fx->lp_noise; + move32(); + } + /*Noise estimate*/ + test(); + test(); + IF(NE_16(st_fx->element_mode, IVAS_CPE_TD)/* && !st->cng_ism_flag IVAS_CODE */ ) + { +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + PMT("Code for IVAS_CODE_CNG_FIX185_PLC_FADEOUT not done") + ApplyFdCng(syn, st_fx->Q_syn, NULL, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); +#else + ApplyFdCng(syn_fx, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st_fx, 0, (EQ_16(st_fx->coder_type_fx, AUDIO) && st_fx->GSC_noisy_speech_fx == 0)); +#endif + } + /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + test(); + test(); + test(); + test(); +#ifdef IVAS_CODE + if (!st->cna_dirac_flag) + { + /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + if (st->flag_cna && !(st->coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech))) + { + if (st->element_mode == IVAS_CPE_TD && nchan_out == 2) + { + if (hStereoCng->flag_cna_fade) + { + generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out); + hStereoCng->flag_cna_fade = 0; + } + else + { + if (st->element_mode != last_element_mode && st->idchan == 0) + { + /* Clear memory for secondary channel CNA */ + set_f(hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2); + } + + generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out); + } + } + else if (st->element_mode != IVAS_CPE_DFT) + { + if (st->idchan == 0) + { + if (st->element_mode != last_element_mode) + { + set_f(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.0f, st->hFdCngDec->hFdCngCom->fftlen); + } + generate_masking_noise(syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out); + } + } + } + else if (st->flag_cna && st->coder_type == AUDIO && ((st->last_core == ACELP_CORE && !(st->last_coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag))) || st->last_core == TCX_20_CORE)) + { + if (st->element_mode == IVAS_CPE_TD && nchan_out == 2) + { + generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out); + hStereoCng->flag_cna_fade = 1; + } + else + { + v_multc(st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4, (float)(st->hFdCngDec->hFdCngCom->fftlen / 2), temp_buf, st->hFdCngDec->hFdCngCom->frameSize / 2); + v_add(temp_buf, syn, syn, st->hFdCngDec->hFdCngCom->frameSize / 2); + } + } + else + { + if (hStereoCng != NULL) + { + hStereoCng->flag_cna_fade = 1; + hStereoCng->enableSecCNA = 0; + } + } - /*Noise estimate*/ - test(); - test(); - ApplyFdCng( syn_fx, st_fx->Q_syn, realBuffer, imagBuffer, 0, st_fx->hFdCngDec_fx, st_fx->m_frame_type, st_fx, 0, - (EQ_16(coder_type_fx, AUDIO ) && st_fx->GSC_noisy_speech_fx == 0) ); + if (st->element_mode == IVAS_CPE_TD) + { + /*Noise estimate*/ + if (st->idchan == 0 && (nchan_out == 2 || (st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40))) + { +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ApplyFdCng(syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); +#else + ApplyFdCng(syn, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); +#endif + } + } + } + } - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - test(); - test(); - test(); - test(); - IF( st_fx->flag_cna && NE_16(coder_type_fx,AUDIO)) + if (!st->cna_dirac_flag) { - generate_masking_noise( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec_fx->hFdCngCom, st_fx->hFdCngDec_fx->hFdCngCom->frameSize, 0 ); + if (st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ((st->last_core == ACELP_CORE && !(st->last_coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag))) || st->last_core == AMR_WB_CORE)) + { + v_multc(st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2); + v_add(temp_buf, syn, syn, st->L_frame / 2); + } + + if (st->flag_cna == 0 || (st->coder_type == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech))) + { + if (st->idchan == 0) + { + set_f(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen); + } + if (hStereoCng != NULL && st->idchan == 0) + { + set_f(hStereoCng->olapBufferSynth22, 0.f, st->hFdCngDec->hFdCngCom->fftlen); + } + } } - ELSE IF( st_fx->flag_cna && coder_type_fx == AUDIO && st_fx->last_core_fx == ACELP_CORE && st_fx->last_coder_type_fx != AUDIO ) +#else + IF(st_fx->flag_cna && NE_16(st_fx->coder_type_fx, AUDIO)) + { + generate_masking_noise(syn_fx, st_fx->Q_syn, st_fx->hFdCngDec_fx->hFdCngCom, st_fx->hFdCngDec_fx->hFdCngCom->frameSize, 0); + } + ELSE IF(st_fx->flag_cna && st_fx->coder_type_fx == AUDIO && st_fx->last_core_fx == ACELP_CORE && st_fx->last_coder_type_fx != AUDIO) + { + FOR(i = 0; i < st_fx->hFdCngDec_fx->hFdCngCom->frameSize / 2; i++) + { + syn_fx[i] = add(syn_fx[i], shr_r(mult_r(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->hFdCngDec_fx->hFdCngCom->frameSize / 4], st_fx->hFdCngDec_fx->hFdCngCom->fftlenFac), -st_fx->Q_syn)); + move16(); + } + } + } + + IF(st_fx->flag_cna == 0 && EQ_16(st_fx->L_frame_fx, L_FRAME16k) && st_fx->last_flag_cna == 1 && ((st_fx->last_core_fx == ACELP_CORE && st_fx->last_coder_type_fx != AUDIO) || st_fx->last_core_fx == AMR_WB_CORE)) { - FOR (i=0; i < st_fx->hFdCngDec_fx->hFdCngCom->frameSize/2; i++) + FOR(i = 0; i < st_fx->L_frame_fx / 2; i++) { - syn_fx[i] = add( syn_fx[i], shr_r( mult_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i+5*st_fx->hFdCngDec_fx->hFdCngCom->frameSize/4], st_fx->hFdCngDec_fx->hFdCngCom->fftlenFac ), -st_fx->Q_syn ) ); + syn_fx[i] = add(syn_fx[i], shr_r(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame_fx / 4], -st_fx->Q_syn)); move16(); } } - } - IF( st_fx->flag_cna == 0 && EQ_16(st_fx->L_frame_fx,L_FRAME16k)&&st_fx->last_flag_cna==1&&((st_fx->last_core_fx==ACELP_CORE&&st_fx->last_coder_type_fx!=AUDIO)||st_fx->last_core_fx==AMR_WB_CORE)) - { - FOR (i=0; i < st_fx->L_frame_fx/2; i++) + test(); + IF(st_fx->flag_cna == 0 || EQ_16(st_fx->coder_type_fx, AUDIO)) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame_fx/4], -st_fx->Q_syn ) ); - move16(); + set16_fx(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec_fx->hFdCngCom->fftlen); } +#endif } - - test(); - IF( st_fx->flag_cna == 0 || EQ_16(coder_type_fx,AUDIO)) - { - set16_fx( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec_fx->hFdCngCom->fftlen ); - } - /*----------------------------------------------------------------* * Resample to the output sampling rate (8/16/32/48 kHz) * Bass post-filter @@ -1074,7 +1574,7 @@ void acelp_core_dec_fx( IF( (st_fx->cldfbAna_fx->usb * st_fx->cldfbAna_fx->no_col) != st_fx->L_frame_fx ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame_fx,50)); + Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame_fx, FRAMES_PER_SEC)); resampleCldfb( st_fx->cldfbAna_fx, newCldfbBands, st_fx->L_frame_fx, 0 ); resampleCldfb( st_fx->cldfbBPF_fx, newCldfbBands, st_fx->L_frame_fx, 0 ); @@ -1083,108 +1583,189 @@ void acelp_core_dec_fx( st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels,st_fx->cldfbAna_fx->no_channels); } } +#ifdef ADD_LRTD + /* analyze pitch coherence for bass post-filter */ + bpf_pitch_coherence(st, pitch_buf); +#endif + IF(!(EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && st_fx->bpf_off_fx)) + { + test(); + IF( NE_16(st_fx->L_frame_fx,st_fx->last_L_frame_fx)&&NE_16(st_fx->last_codec_mode,MODE2)) + { + IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) + { + retro_interp5_4_fx(hBPF->pst_old_syn_fx ); + } + ELSE IF( EQ_16(st_fx->L_frame_fx,L_FRAME16k)) + { + retro_interp4_5_fx( syn_fx, hBPF->pst_old_syn_fx ); + } + } + bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB_fx, syn_fx, st_fx->L_frame_fx, pitch_buf_fx, st_fx->bpf_off_fx, + st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, st_fx->coder_type_fx, st_fx->Q_syn, bpf_error_signal ); + } test(); - IF( NE_16(st_fx->L_frame_fx,st_fx->last_L_frame_fx)&&NE_16(st_fx->last_codec_mode,MODE2)) + IF (NE_16(st_fx->element_mode, IVAS_CPE_DFT) || use_cldfb_for_dft) { - IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) +#ifdef IVAS_CODE + float realBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float imagBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float* pRealSave[CLDFB_NO_COL_MAX], * pImagSave[CLDFB_NO_COL_MAX]; + for (i = 0; i < CLDFB_NO_COL_MAX; i++) { - retro_interp5_4_fx( st_fx->pst_old_syn_fx ); + pRealSave[i] = realBufferSave[i]; + pImagSave[i] = imagBufferSave[i]; } - ELSE IF( EQ_16(st_fx->L_frame_fx,L_FRAME16k)) + if (st->p_bpf_noise_buf) { - retro_interp4_5_fx( syn_fx, st_fx->pst_old_syn_fx ); + mvr2r(bpf_error_signal, st->p_bpf_noise_buf, st->L_frame); } - } +#endif + /* analysis of the synthesis at internal sampling rate */ + cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX, workBuffer); - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, syn_fx, st_fx->L_frame_fx, pitch_buf_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, - st_fx->mem_mean_pit_fx, st_fx->Track_on_hist_fx, st_fx->vibrato_hist_fx, &st_fx->psf_att_fx, coder_type_fx, st_fx->Q_syn, bpf_error_signal ); + scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); - /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX, workBuffer); + /* analysis and add the BPF error signal */ + i = 0; + move16(); + if( st_fx->bpf_off_fx == 0 ) + { + i = CLDFB_NO_COL_MAX; + move16(); + } + addBassPostFilterFx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF_fx, workBuffer, negate(st_fx->Q_syn), + i, st_fx->cldfbAna_fx->no_col, st_fx->cldfbAna_fx->no_channels, &scaleFactor ); - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); + /* set output mask for upsampling */ + IF( EQ_16(st_fx->bwidth_fx,NB)) + { + /* set NB mask for upsampling */ + st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels,10); + } + ELSE if( NE_16(st_fx->cldfbSyn_fx->bandsToZero,sub(st_fx->cldfbSyn_fx->no_channels,st_fx->cldfbAna_fx->no_channels))) + { + /* in case of BW switching, re-init to default */ + st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels, st_fx->cldfbAna_fx->no_channels); + } - /* analysis and add the BPF error signal */ - i = 0; - move16(); - if( st_fx->bpf_off_fx == 0 ) - { - i = CLDFB_NO_COL_MAX; + /*WB/SWB-FD_CNG*/ + scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); - } - addBassPostFilterFx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF_fx, workBuffer, negate(st_fx->Q_syn), - i, st_fx->cldfbAna_fx->no_col, st_fx->cldfbAna_fx->no_channels, &scaleFactor ); - /* set output mask for upsampling */ - IF( EQ_16(st_fx->bwidth_fx,NB)) - { - /* set NB mask for upsampling */ - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels,10); - } - ELSE if( NE_16(st_fx->cldfbSyn_fx->bandsToZero,sub(st_fx->cldfbSyn_fx->no_channels,st_fx->cldfbAna_fx->no_channels))) - { - /* in case of BW switching, re-init to default */ - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels, st_fx->cldfbAna_fx->no_channels); - } + test(); + test(); + test(); + IF(!st_fx->cng_sba_flag || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF((EQ_32(st_fx->core_brate_fx, FRAME_NO_DATA) || EQ_32(st_fx->core_brate_fx, SID_2k40)) && (EQ_16(st_fx->cng_type_fx, FD_CNG)) && (LT_16(st_fx->hFdCngDec_fx->hFdCngCom->numCoreBands, st_fx->cldfbSyn_fx->no_channels))) + { + generate_comfort_noise_dec_hf(realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx); - /*WB/SWB-FD_CNG*/ - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); + st_fx->cldfbSyn_fx->bandsToZero = 0; + move16(); + if (LT_16(st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand, st_fx->cldfbSyn_fx->no_channels)) + { + st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels, st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand); + } + st_fx->cldfbSyn_fx->lsb = st_fx->cldfbAna_fx->no_channels; + move16(); + } + } + /* synthesis of the combined signal */ + st_fx->Q_syn2 = st_fx->Q_syn; + move16(); +#ifdef IVAS_CODE + if (save_hb_synth != NULL) + { + /* save and then zero-out lowband */ + for (int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) + { + for (i = 0; i < CLDFB_NO_COL_MAX; i++) + { + realBufferSave[i][j] = realBuffer[i][j]; + imagBufferSave[i][j] = imagBuffer[i][j]; + if (j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots) + { + realBuffer[i][j] = 0.0f; + imagBuffer[i][j] = 0.0f; + } + } + } - test(); - test(); - test(); - IF( ( EQ_32(st_fx->core_brate_fx,FRAME_NO_DATA)||EQ_32(st_fx->core_brate_fx,SID_2k40))&&(EQ_16(st_fx->cng_type_fx,FD_CNG))&&(LT_16(st_fx->hFdCngDec_fx->hFdCngCom->numCoreBands,st_fx->cldfbSyn_fx->no_channels))) - { - generate_comfort_noise_dec_hf( realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx ); + cldfbSynthesis(realBuffer, imagBuffer, save_hb_synth, -1, st->cldfbSynHB); - st_fx->cldfbSyn_fx->bandsToZero = 0; - move16(); - if( LT_16(st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand, st_fx->cldfbSyn_fx->no_channels)) + /* restore lowband */ + for (int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) + { + for (i = 0; i < CLDFB_NO_COL_MAX; i++) + { + realBuffer[i][j] = realBufferSave[i][j]; + imagBuffer[i][j] = imagBufferSave[i][j]; + } + } + + cldfbSynthesis(pRealSave, pImagSave, synth, -1, st->cldfbSyn); + } + else +#endif { - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels, st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand); + cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn2), CLDFB_NO_COL_MAX, workBuffer); } - st_fx->cldfbSyn_fx->lsb = st_fx->cldfbAna_fx->no_channels; - move16(); + /* Bring CLDFB output to Q0 */ + Scale_sig(synth_out, output_frame, negate(st_fx->Q_syn2)); + st_fx->Q_syn2 = 0; + move16(); + + /* save synthesis - needed in case of core switching */ + Copy( synth_out, st_fx->previoussynth_fx, output_frame ); } +#ifdef IVAS_CODE + ELSE + { + int16_t nSamples = NS2SA(st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ - /* synthesis of the combined signal */ - st_fx->Q_syn2 = st_fx->Q_syn; - move16(); - cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn2), CLDFB_NO_COL_MAX, workBuffer); + /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ + cldfbAnalysis(syn + st->L_frame - nSamples, realBuffer, imagBuffer, nSamples, st->cldfbAna); - /* Bring CLDFB output to Q0 */ - Scale_sig(synth_out, output_frame, negate(st_fx->Q_syn2)); - st_fx->Q_syn2 = 0; - move16(); + /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ + addBassPostFilter(bpf_error_signal + st->L_frame - nSamples, st->bpf_off ? 0 : nSamples, realBuffer, imagBuffer, st->cldfbBPF); - /* save synthesis - needed in case of core switching */ - Copy( synth_out, st_fx->previoussynth_fx, output_frame ); + /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ + cldfbSynthesis(realBuffer, imagBuffer, synth /*dummy*/, NS2SA(st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/), st->cldfbSyn); - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz (only for 16kHz input signals) - *-----------------------------------------------------------------*/ + if (st->p_bpf_noise_buf) + { + mvr2r(bpf_error_signal, st->p_bpf_noise_buf, st->L_frame); + } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (EQ_16(st_fx->L_frame_fx,L_FRAME)&&NE_16(st_fx->bwidth_fx,NB)&&GE_16(output_frame,L_FRAME16k)&& - ( EQ_16(st_fx->extl_fx,-1) || EQ_16(st_fx->extl_fx,SWB_CNG) || (EQ_16(st_fx->extl_fx,WB_BWE) && st_fx->extl_brate_fx == 0 && NE_16(coder_type_fx,AUDIO) )) ) ) + set_f(synth, 0.0f, output_frame); + } + + /* Copy output signal */ + if (st->element_mode > EVS_MONO) { - hf_synth_fx( st_fx->core_brate_fx, output_frame, Aq_fx, exc2_fx, syn_fx, synth_out, &st_fx->seed2_fx, - st_fx->mem_hp400_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hf_fx, st_fx->Q_exc, - st_fx->Q_syn2, st_fx->delay_syn_hf_fx, &st_fx->memExp1, st_fx->mem_hp_interp_fx, st_fx->extl_fx, st_fx->CNG_mode_fx ); + mvr2r(syn, output, st->L_frame); } - ELSE +#endif + /*-----------------------------------------------------------------* + * Bandwidth extension 6kHz-7kHz + *-----------------------------------------------------------------*/ + IF(st_fx->hBWE_zero != NULL) { - hf_synth_reset_fx( &st_fx->seed2_fx, st_fx->mem_hf_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp400_fx, st_fx->mem_hp_interp_fx, st_fx->delay_syn_hf_fx ); + test(); test(); test(); test(); test(); test(); test(); + IF( (EQ_16(st_fx->L_frame_fx,L_FRAME)&&NE_16(st_fx->bwidth_fx,NB)&&GE_16(output_frame,L_FRAME16k)&& + ( EQ_16(st_fx->extl_fx,-1) || EQ_16(st_fx->extl_fx,SWB_CNG) || (EQ_16(st_fx->extl_fx,WB_BWE) && st_fx->extl_brate_fx == 0 && NE_16(st_fx->coder_type_fx,AUDIO) )) ) ) + { + hf_synth_fx( st_fx->hBWE_zero, st_fx->core_brate_fx, output_frame, Aq_fx, exc2_fx, syn_fx, synth_out, st_fx->Q_exc, + st_fx->Q_syn2, st_fx->hBWE_zero->delay_syn_hf_fx, &hBWE_FD->memExp1, st_fx->hBWE_zero->mem_hp_interp_fx, st_fx->extl_fx, st_fx->CNG_mode_fx ); + } + ELSE + { + hf_synth_reset_fx( st_fx->hBWE_zero ); + } } /*-----------------------------------------------------------------* @@ -1192,56 +1773,51 @@ void acelp_core_dec_fx( *-----------------------------------------------------------------*/ /* Apply a non linearity to the SHB excitation */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( !st_fx->bfi_fx && ( st_fx->prev_bfi_fx )) || ((EQ_16(st_fx->last_vbr_hw_BWE_disable_dec_fx,1))&&(st_fx->vbr_hw_BWE_disable_dec_fx==0))||((EQ_16(st_fx->extl_fx,SWB_TBE)||EQ_16(st_fx->extl_fx,WB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE))&&NE_16(st_fx->last_extl_fx,SWB_TBE)&&NE_16(st_fx->last_extl_fx,WB_TBE)&&NE_16(st_fx->last_extl_fx,FB_TBE))) + IF(hBWE_TD != NULL) { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } + test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); + IF((!st_fx->bfi_fx && (st_fx->prev_bfi_fx)) || ((EQ_16(st_fx->last_vbr_hw_BWE_disable_dec_fx, 1)) && (st_fx->vbr_hw_BWE_disable_dec_fx == 0)) || ((EQ_16(st_fx->extl_fx, SWB_TBE) || EQ_16(st_fx->extl_fx, WB_TBE) || EQ_16(st_fx->extl_fx, FB_TBE)) + && NE_16(st_fx->last_extl_fx, SWB_TBE) && NE_16(st_fx->last_extl_fx, WB_TBE) && NE_16(st_fx->last_extl_fx, FB_TBE)) + || (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD) && !st_fx->tdm_LRTD_flag)) + { + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + } - IF( !st_fx->ppp_mode_dec_fx ) - { - non_linearity_fx( bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &st_fx->bwe_non_lin_prev_scale_fx, st_fx->Q_exc , - coder_type_fx, voice_factors, st_fx->L_frame_fx ); - } + IF(!st_fx->ppp_mode_dec_fx && (st_fx->idchan == 0 || NE_16(st_fx->element_mode, IVAS_CPE_TD) || (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD) && st_fx->tdm_LRTD_flag))) + { + non_linearity_fx(bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st_fx->Q_exc, + st_fx->coder_type_fx, voice_factors, st_fx->L_frame_fx); + } - test(); - if( EQ_32(st_fx->core_brate_fx,FRAME_NO_DATA)||EQ_32(st_fx->core_brate_fx,SID_2k40)) - { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + test(); + IF( EQ_32(st_fx->core_brate_fx,FRAME_NO_DATA)||EQ_32(st_fx->core_brate_fx,SID_2k40)) + { + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + } } - /*----------------------------------------------------------------------* * Updates *----------------------------------------------------------------------*/ - updt_dec_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); + updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); - IF( GT_32(st_fx->core_brate_fx,SID_2k40)) + IF( GT_32(st_fx->core_brate_fx,SID_2k40) && st_fx->hTdCngDec != NULL && st_fx->hFdCngDec_fx != NULL) { /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame_fx, &st_fx->ho_circ_ptr_fx, st_fx->ho_ener_circ_fx, &st_fx->ho_circ_size_fx, st_fx->ho_lsp_circ_fx, - st_fx->Q_exc, DEC, st_fx->ho_env_circ_fx, NULL, NULL, NULL, NULL, st_fx->last_active_brate_fx ); - + cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame_fx, &st_fx->hTdCngDec->ho_circ_ptr_fx, st_fx->hTdCngDec->ho_ener_circ_fx, &st_fx->hTdCngDec->ho_circ_size_fx, st_fx->hTdCngDec->ho_lsp_circ_fx, + st_fx->Q_exc, DEC, st_fx->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st_fx->last_active_brate_fx ); /* Set 16k LSP flag for CNG buffer */ - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 0; + st_fx->hTdCngDec->ho_16k_lsp_fx[st_fx->hTdCngDec->ho_circ_ptr_fx] = 0; move16(); - if( NE_16(st_fx->L_frame_fx, L_FRAME)) + if (NE_16(st_fx->L_frame_fx, L_FRAME)) { - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 1; + st_fx->hTdCngDec->ho_16k_lsp_fx[st_fx->hTdCngDec->ho_circ_ptr_fx] = 1; move16(); } } - return; + return IVAS_ERR_OK; + } diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 8a0e2dc..b6b1ca9 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -2,18 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*---------------------------------------------------------------------* -* Local functions -*---------------------------------------------------------------------*/ + * Local function prototypes + *---------------------------------------------------------------------*/ -static void decod_gen_voic_core_switch_fx( Decoder_State_fx *st_fx, const Word16 L_frame, const Word16 sharpFlag, const Word16 *Aq, const Word16 coder_type, +static void decod_gen_voic_core_switch_fx( Decoder_State_fx *st_fx, const Word16 L_frame, const Word16 sharpFlag, const Word16 *Aq, Word16 *exc, const Word32 core_brate, Word16 *Q_exc ); /*-------------------------------------------------------------------* @@ -22,7 +21,7 @@ static void decod_gen_voic_core_switch_fx( Decoder_State_fx *st_fx, const Word16 * ACELP core decoder in the first ACELP->HQ switching frame *-------------------------------------------------------------------*/ -void acelp_core_switch_dec_fx( +ivas_error acelp_core_switch_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 *synth_subfr_out, /* o : synthesized ACELP subframe Q_syn*/ Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ @@ -48,6 +47,11 @@ void acelp_core_switch_dec_fx( Word16 syn_fx_tmp[L_FRAME_16k]; Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + BPF_DEC_HANDLE hBPF; + hBPF = st_fx->hBPF; + + ivas_error error; + error = IVAS_ERR_OK; FOR( i=0; iQ_exc ); + config_acelp1(DEC, st_fx->total_brate_fx, cbrate, st_fx->core_fx, -1, -1, st_fx->last_L_frame_fx, -1, &(st_fx->acelp_cfg), st_fx->next_bit_pos_fx, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); + decod_gen_voic_core_switch_fx( st_fx, L_frame_for_cs, 0, Aq, exc, cbrate, &st_fx->Q_exc ); /*----------------------------------------------------------------* * synthesis, deemphasis, postprocessing and resampling @@ -132,11 +136,11 @@ void acelp_core_switch_dec_fx( /* Core synthesis at 12.8kHz or 16kHz */ Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, - 4, &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx,&st_fx->agc_mem_fx[1], &st_fx->pfstat , 1, 0, NULL ); + 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx,&st_fx->agc_mem_fx[1], st_fx->hPFstat , 1, 0, NULL ); syn_12k8_fx( 2*L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - IF(st_fx->pfstat.on && (EQ_16(st_fx->last_bwidth_fx,NB))) + IF(st_fx->hPFstat->on && (EQ_16(st_fx->last_bwidth_fx,NB))) { Word16 tmp_noise, pitch_buf_tmp[2]; tmp_noise = 0; @@ -145,7 +149,7 @@ void acelp_core_switch_dec_fx( pitch_buf_tmp[i] = L_SUBFR; move16(); } - nb_post_filt( 2*L_SUBFR, &(st_fx->pfstat), &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt( 2*L_SUBFR, st_fx->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); } IF( EQ_16(L_frame_for_cs,L_FRAME)) @@ -161,17 +165,18 @@ void acelp_core_switch_dec_fx( Copy( syn_fx_tmp+M, synth_intFreq, 2*L_SUBFR ); test(); - IF( st_fx->pfstat.on && (NE_16(st_fx->last_bwidth_fx,NB))) + IF( st_fx->hPFstat->on && (NE_16(st_fx->last_bwidth_fx,NB))) { - Copy( st_fx->pfstat.mem_pf_in+L_SYN_MEM-M, bpf_error_signal, M ); + Copy( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-M, bpf_error_signal, M ); Copy( synth_intFreq, bpf_error_signal + M, L_SUBFR ); Residu3_fx ( Aq, bpf_error_signal + M, exc, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->pfstat.mem_stp+L_SYN_MEM-M, 0, M ); - scale_st ( synth_intFreq, bpf_error_signal, &st_fx->pfstat.gain_prec, L_SUBFR ); + E_UTIL_synthesis ( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->hPFstat->mem_stp+L_SYN_MEM-M, 0, M ); + scale_st ( synth_intFreq, bpf_error_signal, &st_fx->hPFstat->gain_prec, L_SUBFR ); Copy( bpf_error_signal, synth_intFreq, L_SUBFR/2 ); blend_subfr2( bpf_error_signal + L_SUBFR/2, synth_intFreq + L_SUBFR/2, synth_intFreq + L_SUBFR/2 ); } - st_fx->pfstat.on = 0; + st_fx->hPFstat->on = 0; + move16(); IF ( st_fx->flag_cna != 0 ) @@ -184,12 +189,14 @@ void acelp_core_switch_dec_fx( * Bass post-filter *----------------------------------------------------------------*/ - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, synth_intFreq, 2*L_SUBFR, NULL, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, - st_fx->mem_mean_pit_fx, st_fx->Track_on_hist_fx, st_fx->vibrato_hist_fx, &st_fx->psf_att_fx, GENERIC, - st_fx->Q_syn, bpf_error_signal ); + bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB_fx, synth_intFreq, 2*L_SUBFR, NULL, + st_fx->bpf_off_fx, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, + GENERIC, st_fx->Q_syn, bpf_error_signal ); - cldfb_save_memory( st_fx->cldfbAna_fx ); + if ((error = cldfb_save_memory( st_fx->cldfbAna_fx )) != IVAS_ERR_OK) + { + return error; + } cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, synth_intFreq, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH, workBuffer); cldfb_restore_memory( st_fx->cldfbAna_fx ); @@ -199,7 +206,10 @@ void acelp_core_switch_dec_fx( move16(); /* CLDFB analysis and add the BPF error signal */ - cldfb_save_memory( st_fx->cldfbBPF_fx ); + if ((error = cldfb_save_memory( st_fx->cldfbBPF_fx )) != IVAS_ERR_OK) + { + return error; + } i = 0; move16(); if( st_fx->bpf_off_fx == 0 ) @@ -214,7 +224,10 @@ void acelp_core_switch_dec_fx( /* CLDFB synthesis of the combined signal */ scaleFactor.hb_scale = scaleFactor.lb_scale; - cldfb_save_memory( st_fx->cldfbSyn_fx ); + if ((error = cldfb_save_memory( st_fx->cldfbSyn_fx )) != IVAS_ERR_OK) + { + return error; + } cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_subfr_out, 0, CLDFB_NO_COL_MAX_SWITCH, workBuffer); cldfb_restore_memory( st_fx->cldfbSyn_fx ); *Q_syn = 0; @@ -322,7 +335,7 @@ void acelp_core_switch_dec_fx( } } - return; + return error; } @@ -332,7 +345,7 @@ void acelp_core_switch_dec_fx( * ACELP core decoder in the first ACELP->HQ switching frame in case of BAD frame *-------------------------------------------------------------------*/ -void acelp_core_switch_dec_bfi_fx( +ivas_error acelp_core_switch_dec_bfi_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 synth_out[], /* o : synthesis Q_syn */ const Word16 coder_type /* i : coder type */ @@ -364,6 +377,13 @@ void acelp_core_switch_dec_bfi_fx( Word16 i; CLDFB_SCALE_FACTOR scaleFactor; Word32 workBuffer[128*3]; + MUSIC_POSTFILT_HANDLE hMusicPF; + BPF_DEC_HANDLE hBPF; + ivas_error error; + + hMusicPF = st_fx->hMusicPF; + hBPF = st_fx->hBPF; + error = IVAS_ERR_OK; FOR( i=0; iold_exc_fx, old_exc, L_EXC_MEM_DEC ); exc = old_exc + L_EXC_MEM_DEC; - Copy( st_fx->old_exc2_fx, old_exc2, L_EXC_MEM ); + IF(st_fx->hWIDec != NULL) + { + Copy(st_fx->hWIDec->old_exc2_fx, old_exc2, L_EXC_MEM); + } + ELSE + { + set16_fx(old_exc2, 0, L_EXC_MEM); + } exc2 = old_exc2 + L_EXC_MEM; - Copy( st_fx->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2); - bwe_exc = old_bwe_exc + PIT16k_MAX * 2; + if (st_fx->hBWE_TD != NULL) + { + Copy(st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2); + bwe_exc = old_bwe_exc + PIT16k_MAX * 2; + } + else + { + bwe_exc = NULL; + } + st_fx->GSC_noisy_speech_fx = 0; move16(); st_fx->relax_prev_lsf_interp_fx = 0; @@ -407,9 +442,9 @@ void acelp_core_switch_dec_bfi_fx( Copy(st_fx->mem_MA_fx,tmp_float2,M); /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); + lsf_dec_bfi(MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, + st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame_fx, Aq, lsf_new, lsp_new); @@ -426,10 +461,10 @@ void acelp_core_switch_dec_bfi_fx( Scale_sig(exc-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); st_fx->Q_exc = 0; /* SC-VBR */ - decod_nelp_fx( st_fx, coder_type, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi_fx, gain_buf ); + decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi_fx, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); - Rescale_exc( st_fx->dct_post_old_exc_fx, exc, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type); st_fx->Q_exc = Q_exc; } ELSE @@ -449,8 +484,9 @@ void acelp_core_switch_dec_bfi_fx( /* calculation of excitation signal */ FEC_exc_estim_fx( st_fx, st_fx->L_frame_fx, exc, exc2, syn /* dummy buffer */, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &Q_exc, &tmp_noise ); - Rescale_exc( NULL, exc, bwe_exc, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, L_FRAME32k, (Word32)0, - &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame_fx, st_fx->last_coder_type_fx); + Rescale_exc( NULL, exc, bwe_exc, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame_fx, L_FRAME32k, (Word32)0, + &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame_fx, st_fx->last_coder_type_fx); + st_fx->seed_fx = tmp_float[5]; move16(); st_fx->bfi_pitch_fx = tmp_float[0]; @@ -470,7 +506,7 @@ void acelp_core_switch_dec_bfi_fx( *-----------------------------------------------------------------*/ Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 1, 0, NULL ); + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); Copy( st_fx->mem_syn2_fx,tmp_float,M); syn_12k8_fx( st_fx->L_frame_fx, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); @@ -499,25 +535,32 @@ void acelp_core_switch_dec_bfi_fx( st_fx->bpf_off_fx=1; move16(); - Copy( st_fx->pst_old_syn_fx,tmp_float,NBPSF_PIT_MAX); + Copy(hBPF->pst_old_syn_fx,tmp_float,NBPSF_PIT_MAX); tmp_float3 = st_fx->stab_fac_smooth_fx; move16(); - Copy( st_fx->mem_mean_pit_fx,tmp_float4, L_TRACK_HIST); - Copy( st_fx->Track_on_hist_fx,tmp_float5, L_TRACK_HIST); - Copy( st_fx->vibrato_hist_fx,tmp_float6, L_TRACK_HIST); - tmp_float7 = st_fx->psf_att_fx; + Copy(hBPF->mem_mean_pit_fx,tmp_float4, L_TRACK_HIST); + Copy(hBPF->Track_on_hist_fx,tmp_float5, L_TRACK_HIST); + Copy(hBPF->vibrato_hist_fx,tmp_float6, L_TRACK_HIST); + tmp_float7 = hBPF->psf_att_fx; move16(); - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, syn, st_fx->L_frame_fx, pitch_buf, tmp_float, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &tmp_float3, - tmp_float4, tmp_float5, tmp_float6, &tmp_float7, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/); + bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB_fx, syn, st_fx->L_frame_fx, pitch_buf, + st_fx->bpf_off_fx, st_fx->stab_fac_fx, &tmp_float3, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/); + Copy(tmp_float, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX); + Copy(tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST); + Copy(tmp_float5, hBPF->Track_on_hist_fx, L_TRACK_HIST); + Copy(tmp_float6, hBPF->vibrato_hist_fx, L_TRACK_HIST); + hBPF->psf_att_fx = tmp_float7 ; /*----------------------------------------------------------------* * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - cldfb_save_memory( st_fx->cldfbAna_fx ); + if ((error = cldfb_save_memory( st_fx->cldfbAna_fx )) != IVAS_ERR_OK) + { + return error; + } cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, syn, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer); cldfb_restore_memory( st_fx->cldfbAna_fx ); @@ -525,7 +568,10 @@ void acelp_core_switch_dec_bfi_fx( scaleFactor.hb_scale = scaleFactor.lb_scale; /* CLDFB synthesis of the combined signal */ - cldfb_save_memory( st_fx->cldfbSyn_fx ); + if ((error = cldfb_save_memory( st_fx->cldfbSyn_fx )) != IVAS_ERR_OK) + { + return error; + } cldfbSynthesisFiltering( st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); @@ -534,14 +580,14 @@ void acelp_core_switch_dec_bfi_fx( cldfb_restore_memory( st_fx->cldfbSyn_fx ); - return; + return error; } /*-------------------------------------------------------------------* * decod_gen_voic_core_switch() * -* Decode excitation signal in teh first ACELP->HQ switching frame +* Decode excitation signal in the first ACELP->HQ switching frame *-------------------------------------------------------------------*/ static void decod_gen_voic_core_switch_fx( @@ -549,7 +595,6 @@ static void decod_gen_voic_core_switch_fx( const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag, /* i : flag for formant sharpening */ const Word16 *Aq, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ Word16 *exc, /* i/o: adapt. excitation exc */ const Word32 core_brate, /* i : switching frame bit-rate */ Word16 *Q_exc @@ -566,6 +611,9 @@ static void decod_gen_voic_core_switch_fx( Word16 i; /* tmp variables */ Word16 pitch_limit_flag; Word16 *pt1; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; + /*----------------------------------------------------------------------* * initializations @@ -590,7 +638,7 @@ static void decod_gen_voic_core_switch_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, coder_type, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); /*Q6*/ + pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); /*Q6*/ /*--------------------------------------------------------------* * Find the adaptive codebook vector. @@ -602,13 +650,13 @@ static void decod_gen_voic_core_switch_fx( * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx( st_fx, MODE1, core_brate,0, coder_type, 0, L_SUBFR, L_frame, 0, exc); /*Scaling of exc doesn't change*/ + lp_filt_exc_dec_fx(st_fx, MODE1, 0, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc); /*Scaling of exc doesn't change*/ - /*--------------------------------------------------------------* + /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - inov_decode_fx( st_fx, core_brate, 0, L_frame, coder_type, sharpFlag, 0, -1, Aq, st_fx->tilt_code_fx, pitch, code); /*code in Q9*/ + inov_decode_fx( st_fx, core_brate, 0, L_frame, sharpFlag, 0, Aq, st_fx->tilt_code_fx, pitch, code, L_SUBFR); /*code in Q9*/ /*--------------------------------------------------------------* * Gain decoding @@ -617,11 +665,11 @@ static void decod_gen_voic_core_switch_fx( IF( EQ_16(L_frame, L_FRAME)) { - gain_dec_mless_fx( st_fx, core_brate, L_frame, TRANSITION, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + gain_dec_mless_fx( st_fx, L_frame, TRANSITION, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); } ELSE { - gain_dec_mless_fx( st_fx, core_brate, L_frame, coder_type, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + gain_dec_mless_fx( st_fx, L_frame, GENERIC, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); } /* _ (Word16*) gain_pit : quantized pitch gain (Q14) */ @@ -637,12 +685,12 @@ static void decod_gen_voic_core_switch_fx( /* Rescaling for 12.8k core */ IF ( EQ_16(L_frame,L_FRAME)) { - Rescale_exc( NULL, &exc[0], NULL, st_fx->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC ); + Rescale_exc( NULL, &exc[0], NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC ); } /* Rescaling for 16k core */ ELSE { - Rescale_exc(NULL, &exc[0], NULL, st_fx->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * 2, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC); + Rescale_exc(NULL, &exc[0], NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * 2, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC); } gain_code16 = round_fx(L_shl(gain_code,st_fx->Q_exc)); /*Q_exc*/ diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 41a14b1..979db6d 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" #include "cnst_fx.h" #include "rom_com_fx.h" #include "prot_fx.h" -#include "stl.h" #include "basop_mpy.h" #include "basop_util.h" /* Function prototypes */ @@ -17,14 +16,13 @@ * AMR-WB decoder *-------------------------------------------------------------------*/ -void amr_wb_dec_fx( +ivas_error amr_wb_dec_fx( Word16 output_sp[], /* o : synthesis output */ Decoder_State_fx *st_fx /* o : Decoder static variables structure */ ) { Word16 i; Word16 vad_flag; - Word16 coder_type; Word16 output_frame; /* frame length at output sampling freq. */ Word16 allow_cn_step; Word16 locattack, amr_io_class; @@ -76,7 +74,23 @@ void amr_wb_dec_fx( Word16 avoid_lpc_burst_on_recovery; Word16 delta_mem_scale; - + MUSIC_POSTFILT_HANDLE hMusicPF; + TCX_DEC_HANDLE hTcxDec; + HQ_DEC_HANDLE hHQ_core; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + BPF_DEC_HANDLE hBPF; + ivas_error error; + + hMusicPF = st_fx->hMusicPF; + hBPF = st_fx->hBPF; + hHQ_core = st_fx->hHQ_core; + hTcxLtpDec = st_fx->hTcxLtpDec; + hTcxDec = st_fx->hTcxDec; + + error = IVAS_ERR_OK; + st_fx->idchan = 0; + move16(); + move16(); /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ @@ -98,6 +112,8 @@ void amr_wb_dec_fx( st_fx->use_partial_copy = 0; move16(); + st_fx->rf_frame_type = RF_NO_DATA; + move16(); st_fx->rf_flag = 0; move16(); st_fx->rf_flag_last = 0; @@ -115,7 +131,7 @@ void amr_wb_dec_fx( move16(); st_fx->bwidth_fx = WB; move16(); - coder_type = GENERIC; + st_fx->coder_type_fx = GENERIC; move16(); output_frame = st_fx->output_frame_fx; move16(); /* frame length of the input signal */ @@ -126,7 +142,7 @@ void amr_wb_dec_fx( { st_fx->bpf_off_fx = 1; move16(); - st_fx->pfstat.on = 0; + st_fx->hPFstat->on = 0; move16(); } st_fx->igf = 0; @@ -152,7 +168,10 @@ void amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ - core_switching_pre_dec_fx( st_fx, output_frame ); + if ((error = core_switching_pre_dec_fx( st_fx, output_frame )) != IVAS_ERR_OK) + { + return error; + } last_core_ori = st_fx->last_core_fx; move16(); @@ -167,9 +186,9 @@ void amr_wb_dec_fx( Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); exc_fx = old_exc_fx + L_EXC_MEM_DEC; /* reset post-filter in case of switching */ - if( st_fx->pfstat.on == 0 ) + if( st_fx->hPFstat->on == 0 ) { - st_fx->pfstat.reset = 1; + st_fx->hPFstat->reset = 1; move16(); } IF( st_fx->bfi_fx > 0 ) @@ -187,17 +206,14 @@ void amr_wb_dec_fx( test(); test(); test(); - IF (!st_fx->bfi_fx - && st_fx->prev_bfi_fx - && (EQ_16(st_fx->last_codec_mode, MODE2) ) - && (EQ_16(st_fx->last_core_bfi, TCX_20_CORE) - || EQ_16(st_fx->last_core_bfi, TCX_10_CORE) )) + IF (!st_fx->bfi_fx && st_fx->prev_bfi_fx && (EQ_16(st_fx->last_codec_mode, MODE2) ) + && (EQ_16(st_fx->last_core_bfi, TCX_20_CORE) || EQ_16(st_fx->last_core_bfi, TCX_10_CORE) )) { /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ /* st_fx->old_out_fx, st_fx->L_frameTCX); */ - FOR( i = 0; i < st_fx->L_frameTCX; i++ ) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - st_fx->old_out_fx[i] = shl(mult_r(st_fx->old_out_fx[i], st_fx->plcInfo.recovery_gain), 1); + hHQ_core->old_out_fx[i] = shl(mult_r(hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain), 1); } } @@ -224,16 +240,15 @@ void amr_wb_dec_fx( st_fx->bpf_off_fx = 1; move16(); - if(st_fx->pfstat.on!=0) + if(st_fx->hPFstat->on!=0) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; mem_syn_r_size_old = shr(st_fx->last_L_frame_fx, 4); mem_syn_r_size_new = shr(st_fx->L_frame_fx, 4); - lerp( st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } - st_fx->rate_switching_reset=lsp_convert_poly_fx( st_fx->lsp_old_fx, L_FRAME, 1 ); /* convert old quantized LSF vector */ lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, INT_FS_FX ); @@ -314,16 +329,18 @@ void amr_wb_dec_fx( st_fx->bfi_pitch_frame_fx = L_FRAME; move16(); } - +#ifdef _DIFF_FLOAT_FIX_ + PMT("the code below has been removed in IVAS float (or moved somewhere else), is it ok?") +#endif IF( NE_16(st_fx->last_core_fx,AMR_WB_CORE)) { /* reset the unvoiced/audio signal improvement memories */ - E_LPC_f_isp_a_conversion( st_fx->lsp_old_fx, st_fx->old_Aq_fx, M ); - Copy( st_fx->old_Aq_fx, st_fx->old_Aq_fx + (M+1), M+1 ); - Copy( st_fx->old_Aq_fx, st_fx->old_Aq_fx + 2*(M+1), M+1 ); - Copy( st_fx->old_Aq_fx, st_fx->old_Aq_fx + 3*(M+1), M+1 ); + E_LPC_f_isp_a_conversion( st_fx->lsp_old_fx, st_fx->hAmrwb_IO->old_Aq_fx, M ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + (M+1), M+1 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 2*(M+1), M+1 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 3*(M+1), M+1 ); } - + /*End of _DIFF_FLOAT_FIX_*/ test(); if( EQ_16(st_fx->last_bwidth_fx,NB)&&st_fx->ini_frame_fx!=0) { @@ -346,24 +363,24 @@ void amr_wb_dec_fx( IF ( EQ_32(st_fx->core_brate_fx,FRAME_NO_DATA)||EQ_32(st_fx->core_brate_fx,SID_1k75)) { /* decode CNG parameters */ - CNG_dec_fx( st_fx, L_FRAME, Aq_fx, st_fx->core_brate_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); + CNG_dec_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate_fx, L_FRAME, &st_fx->Enew_fx, &st_fx->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, - &st_fx->first_CNG_fx, &st_fx->cng_ener_seed_fx, dummy_buf_fx, allow_cn_step, &st_fx->last_allow_cn_step_fx, st_fx->prev_Q_exc, st_fx->Q_exc , st_fx->num_ho_fx, - q_env, st_fx->lp_env_fx, st_fx->old_env_fx, st_fx->exc_mem_fx, st_fx->exc_mem1_fx, &sid_bw, &st_fx->cng_ener_seed1_fx, exc3, st_fx->Opt_AMR_WB_fx ); + CNG_exc_fx( st_fx->core_brate_fx, L_FRAME, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, + &st_fx->first_CNG_fx, &st_fx->hTdCngDec->cng_ener_seed_fx, dummy_buf_fx, allow_cn_step, &st_fx->hTdCngDec->last_allow_cn_step_fx, st_fx->prev_Q_exc, st_fx->Q_exc , st_fx->hTdCngDec->num_ho_fx, + q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, &sid_bw, &st_fx->hTdCngDec->cng_ener_seed1_fx, exc3, st_fx->Opt_AMR_WB_fx, st_fx->element_mode); set16_fx( voice_factors_fx, 32767, NB_SUBFR ); class_para_fx = 0; move16(); - if( st_fx->first_CNG_fx == 0 ) - { - st_fx->first_CNG_fx = 1; - move16(); - } - - + // has been moved to updt_dec_common_fx() + //if( st_fx->first_CNG_fx == 0 ) + //{ + // st_fx->first_CNG_fx = 1; + // move16(); + //} + delta_mem_scale = 3; move16(); test(); @@ -374,16 +391,15 @@ void amr_wb_dec_fx( } i = st_fx->Q_exc; - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame_fx, st_fx->L_frame_fx* HIBND_ACB_L_FAC, 0, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, INACTIVE); - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx,&st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 0, 0, NULL ); + &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx,&hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); Copy_Scale_sig(exc2_fx, exc2_fx, st_fx->L_frame_fx, sub(st_fx->Q_exc, i)); /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); /* synthesis at 12k8 Hz sampling rate */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -413,7 +429,7 @@ void amr_wb_dec_fx( FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, st_fx->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, hMusicPF->filt_lfE_fx[i])); } vad_flag = 0; @@ -444,11 +460,11 @@ void amr_wb_dec_fx( vad_flag = (Word16)get_next_indice_fx( st_fx, 1 ); - coder_type = GENERIC; + st_fx->coder_type_fx = GENERIC; move16(); if ( vad_flag == 0 ) { - coder_type = INACTIVE; + st_fx->coder_type_fx = INACTIVE; move16(); } @@ -472,7 +488,7 @@ void amr_wb_dec_fx( * Update ISP vector for CNG *------------------------------------------------------------*/ - IF( EQ_16(coder_type,INACTIVE)) + IF( EQ_16(st_fx->coder_type_fx,INACTIVE)) { IF( GT_16(st_fx->unv_cnt_fx,20)) { @@ -508,13 +524,13 @@ void amr_wb_dec_fx( move16(); test(); test(); - if(EQ_16(coder_type,INACTIVE)&&st_fx->flag_cna&&GE_16(st_fx->psf_lp_noise_fx,15<<7)) + if(EQ_16(st_fx->coder_type_fx,INACTIVE)&&st_fx->flag_cna&&GE_16(st_fx->psf_lp_noise_fx,15<<7)) { tmp16 = 1; move16(); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 5, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, vad_flag, tmp16, tmp_buffer_fx ); + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, vad_flag, tmp16, tmp_buffer_fx ); Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -522,20 +538,20 @@ void amr_wb_dec_fx( * FEC - Estimate the classification information *------------------------------------------------------------*/ - FEC_clas_estim_fx( st_fx, 1, L_FRAME, &st_fx->clas_dec, coder_type, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, - &st_fx->decision_hyst_fx, &st_fx->UV_cnt_fx, &st_fx->LT_UV_cnt_fx, &st_fx->Last_ener_fx, &locattack, st_fx->lt_diff_etot_fx, - &amr_io_class, st_fx->core_brate_fx, st_fx->Q_syn, &class_para_fx, st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate_fx ); + FEC_clas_estim_fx( st_fx, 1, L_FRAME, &st_fx->clas_dec, st_fx->coder_type_fx, pitch_buf_fx, + syn_fx, &st_fx->lp_ener_FER_fx, + &st_fx->decision_hyst_fx, &st_fx->hAmrwb_IO->UV_cnt_fx, &st_fx->hAmrwb_IO->LT_UV_cnt_fx, &st_fx->hAmrwb_IO->Last_ener_fx, &locattack, st_fx->hAmrwb_IO->lt_diff_etot_fx, + &amr_io_class, st_fx->core_brate_fx, st_fx->Q_syn, &class_para_fx, st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, + 0, 0, 0, st_fx->last_core_brate_fx, -1); /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - Copy( st_fx->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST-OFFSET2 ); + Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + Copy(hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST-OFFSET2 ); IF( NE_16(output_frame,L_FRAME8k)) { - IF ( EQ_16(coder_type,INACTIVE)) + IF ( EQ_16(st_fx->coder_type_fx,INACTIVE)) { frame_energy_fx( L_FRAME, pitch_buf_fx, syn_fx, 0, &frame_e_fx, st_fx->Q_syn ); /*st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; */ @@ -545,7 +561,7 @@ void amr_wb_dec_fx( test(); test(); - IF( NE_16(amr_io_class,UNVOICED_CLAS)&&NE_16(coder_type,INACTIVE)&<_16(st_fx->psf_lp_noise_fx,15<<8)) + IF( NE_16(amr_io_class,UNVOICED_CLAS)&&NE_16(st_fx->coder_type_fx,INACTIVE)&<_16(st_fx->psf_lp_noise_fx,15<<8)) { tmp_coder_type = AUDIO; move16(); @@ -556,19 +572,15 @@ void amr_wb_dec_fx( move16(); } /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st_fx->filt_lfE_fx, st_fx->last_core_fx, pitch_buf_fx, st_fx->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &Qdct ); + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core_fx, pitch_buf_fx, hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &Qdct ); /* LD music post-filter */ - LD_music_post_filter_fx( dct_buffer_fx, dct_buffer_fx, st_fx->core_brate_fx, &st_fx->LDm_last_music_flag_fx, - st_fx->LDm_thres_fx, &st_fx->LDm_nb_thr_1_fx, &st_fx->LDm_nb_thr_3_fx, st_fx->LDm_lt_diff_etot_fx, - &st_fx->LDm_mem_etot_fx, st_fx->LDm_enh_min_ns_gain_fx, st_fx->LDm_bckr_noise_fx, - st_fx->LDm_enh_lf_EO_fx, st_fx->LDm_enh_lp_gbin_fx, st_fx->filt_lfE_fx, &st_fx->last_nonfull_music_fx, - &st_fx->Old_ener_Q, -1, tmp_coder_type, Qdct ); + LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate_fx,&hMusicPF->Old_ener_Q, -1, tmp_coder_type, Qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ Post_music_postP_fx( dct_buffer_fx, exc2_fx, mem_tmp_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, - &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx, 1, &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, NULL, NULL ); + &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx, 1, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, + &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, NULL, NULL ); } ELSE { @@ -576,13 +588,13 @@ void amr_wb_dec_fx( * Improvement for unvoiced and audio signals *------------------------------------------------------------*/ - improv_amr_wb_gs_fx( amr_io_class, coder_type, st_fx->core_brate_fx, &st_fx->seed_tcx_fx, st_fx->old_Aq_fx, st_fx->mem_syn2_fx, st_fx->lt_voice_fac_fx, - locattack, Aq_fx, exc2_fx, st_fx->Q_exc, mem_tmp_fx, syn_fx, st_fx->Q_syn, pitch_buf_fx, st_fx->Last_ener_fx, st_fx->rate_switching_reset, st_fx->last_coder_type_fx ); + improv_amr_wb_gs_fx(amr_io_class, st_fx->coder_type_fx, st_fx->core_brate_fx, &st_fx->hGSCDec->seed_tcx_fx, st_fx->hAmrwb_IO->old_Aq_fx, st_fx->mem_syn2_fx, st_fx->hAmrwb_IO->lt_voice_fac_fx, + locattack, Aq_fx, exc2_fx, st_fx->Q_exc, mem_tmp_fx, syn_fx, st_fx->Q_syn, pitch_buf_fx, st_fx->hAmrwb_IO->Last_ener_fx, st_fx->rate_switching_reset, st_fx->last_coder_type_fx); FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i] ;*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, st_fx->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, hMusicPF->filt_lfE_fx[i])); } } @@ -634,8 +646,8 @@ void amr_wb_dec_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); + st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame_fx, Aq_fx, lsf_new_fx, lsp_new_fx ); /* calculation of excitation signal */ @@ -646,26 +658,25 @@ void amr_wb_dec_fx( syn_12k8_fx( L_FRAME, Aq_fx, exc_fx, tmp_buffer_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /* update past excitation signals */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + Copy(hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); /* Update music post processing values */ /* Update circular buffer, keep last energy difference unchanged */ FOR( i = 1; iLDm_lt_diff_etot_fx[i-1] = st_fx->LDm_lt_diff_etot_fx[i]; + hMusicPF->LDm_lt_diff_etot_fx[i-1] = hMusicPF->LDm_lt_diff_etot_fx[i]; move16(); } /* Filter energies update */ FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, st_fx->filt_lfE_fx[i])); + hMusicPF->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, hMusicPF->filt_lfE_fx[i])); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 1, 0, tmp_buffer_fx ); - + hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, tmp_buffer_fx ); Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); /* synthesis at 12k8 Hz sampling rate */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1 , st_fx->Q_exc, st_fx->Q_syn ); @@ -707,15 +718,15 @@ void amr_wb_dec_fx( } IF( EQ_16(output_frame,L_FRAME8k)) { - st_fx->pfstat.on = 1; + st_fx->hPFstat->on = 1; move16(); - nb_post_filt( L_FRAME, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, coder_type, st_fx->BER_detect, 0 ); + nb_post_filt( L_FRAME, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, st_fx->coder_type_fx, st_fx->BER_detect, 0 ); } ELSE { - st_fx->pfstat.on = 0; + st_fx->hPFstat->on = 0; move16(); - nb_post_filt( L_FRAME, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt( L_FRAME, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); } } @@ -732,7 +743,7 @@ void amr_wb_dec_fx( Copy( syn_fx_tmp2, syn_fx, L_FRAME ); /* TCX=Q-1, ACELP2 Q0 */ - Copy_Scale_sig( syn_fx + L_FRAME/2, st_fx->old_syn_Overl, L_FRAME/2, sub(-1,st_fx->Q_syn)); /*Q_syn*/ + Copy_Scale_sig( syn_fx + L_FRAME/2, hTcxDec->old_syn_Overl, L_FRAME/2, sub(-1,st_fx->Q_syn)); /*Q_syn*/ Copy_Scale_sig( syn_fx + L_FRAME-M-1, st_fx->syn, M+1, sub(0,st_fx->Q_syn)); /*Q0*/ /*------------------------------------------------------------------* @@ -742,10 +753,10 @@ void amr_wb_dec_fx( Copy( syn_fx, tmp_buffer_fx + L_SYN_MEM, L_FRAME ); IF( NE_16(output_frame,L_FRAME8k)&&NE_16(st_fx->last_bwidth_fx,NB)) { - st_fx->pfstat.on = 1; + st_fx->hPFstat->on = 1; move16(); test(); - formant_post_filt( &(st_fx->pfstat), tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl(st_fx->psf_lp_noise_fx,15), st_fx->total_brate_fx, sub(amr_io_class,AUDIO_CLAS) == 0); + formant_post_filt( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl(st_fx->psf_lp_noise_fx,15), st_fx->total_brate_fx, sub(amr_io_class,AUDIO_CLAS) == 0); } /*----------------------------------------------------------------* @@ -755,11 +766,11 @@ void amr_wb_dec_fx( flag_cna = 0; move16(); test(); - IF( (GE_16(st_fx->psf_lp_noise_fx,15<<8))||(coder_type==INACTIVE)) + IF( (GE_16(st_fx->psf_lp_noise_fx,15<<8))||(st_fx->coder_type_fx==INACTIVE)) { /*VAD only for non inactive frame*/ test(); - IF( EQ_16(st_fx->VAD, 1)&&NE_16(coder_type,INACTIVE)) + IF( EQ_16(st_fx->VAD, 1)&&NE_16(st_fx->coder_type_fx,INACTIVE)) { st_fx->VAD = 1; move16(); @@ -769,14 +780,16 @@ void amr_wb_dec_fx( st_fx->VAD = 0; move16(); } - ApplyFdCng( syn_fx, st_fx->Q_syn, NULL, NULL, 0, st_fx->hFdCngDec_fx, st_fx->m_frame_type, st_fx, 0, 0 ); - +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + PMT("Fixed point not done here ") + ApplyFdCng(syn, NULL, NULL, NULL, st, 0, 0); +#else + ApplyFdCng( syn_fx, st_fx->Q_syn, NULL, NULL, NULL, st_fx, 0, 0 ); +#endif st_fx->hFdCngDec_fx->hFdCngCom->frame_type_previous = st_fx->m_frame_type; /*Noisy speech detector*/ - noisy_speech_detection( st_fx->VAD, syn_fx, L_FRAME, st_fx->Q_syn, st_fx->hFdCngDec_fx->msNoiseEst, st_fx->hFdCngDec_fx->msNoiseEst_exp, - st_fx->hFdCngDec_fx->psize_shaping_norm, st_fx->hFdCngDec_fx->psize_shaping_norm_exp, st_fx->hFdCngDec_fx->nFFTpart_shaping, - &(st_fx->hFdCngDec_fx->lp_noise), &(st_fx->hFdCngDec_fx->lp_speech), &(st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech) ); + noisy_speech_detection(st_fx->hFdCngDec_fx, st_fx->VAD, syn_fx, st_fx->Q_syn); st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = mult_r(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); IF ( st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech != 0 ) @@ -843,9 +856,8 @@ void amr_wb_dec_fx( } } - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, syn_fx, L_FRAME, pitch_buf_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, - st_fx->mem_mean_pit_fx, st_fx->Track_on_hist_fx, st_fx->vibrato_hist_fx, &st_fx->psf_att_fx, GENERIC, st_fx->Q_syn, bpf_error_signal); + bass_psfilter_fx(st_fx->hBPF, st_fx->Opt_AMR_WB_fx, syn_fx, L_FRAME, pitch_buf_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, + &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal); cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX, workBuffer ); @@ -911,38 +923,25 @@ void amr_wb_dec_fx( test(); IF( GE_16(output_frame,L_FRAME16k)&&(NE_16(st_fx->cldfbSyn_fx->bandsToZero,sub(st_fx->cldfbSyn_fx->no_channels,10))||NE_16(st_fx->last_flag_filter_NB,1))) { - hf_synth_amr_wb_fx( st_fx->core_brate_fx, output_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn_hf_fx, - st_fx->delay_syn_hf_fx, &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, &amr_io_class, st_fx->mem_hp_interp_fx, synth_out_fx, + hf_synth_amr_wb_fx( st_fx->hAmrwb_IO, st_fx->hBWE_zero, + st_fx->core_brate_fx, output_frame, Aq_fx, exc2_fx, syn_fx, &amr_io_class, synth_out_fx, class_para_fx, hf_gain_fx, voice_factors_fx, pitch_buf_fx, st_fx->Ng_ener_ST_fx, lsf_new_fx, - &st_fx->frame_count_fx, &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, - &st_fx->unvoicing_flag_fx, &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx, st_fx->Q_exc, st_fx->Q_syn2 ); + st_fx->Q_exc, st_fx->Q_syn2 ); } ELSE { - hf_synth_amr_wb_reset_fx( &st_fx->seed2_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp_interp_fx, - &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, st_fx->delay_syn_hf_fx, &st_fx->frame_count_fx, - &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, - &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, &st_fx->unvoicing_flag_fx, - &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx ); + hf_synth_amr_wb_reset_fx( st_fx->hBWE_zero, st_fx->hAmrwb_IO); } /*----------------------------------------------------------------------* * Updates *----------------------------------------------------------------------*/ - updt_dec_fx( st_fx, L_FRAME, coder_type, old_exc_fx, pitch_buf_fx, 0, Aq_fx , lsf_new_fx, lsp_new_fx, voice_factors_fx, dummy_buf_fx, gain_buf ); - + updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, 0, Aq_fx , lsf_new_fx, lsp_new_fx, voice_factors_fx, dummy_buf_fx, gain_buf ); /* update old_Aq[] - needed in improv_amr_wb_gs_fx() */ - Copy( Aq_fx, st_fx->old_Aq_fx, NB_SUBFR * (M+1) ); + Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * (M+1) ); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test();test();test();test(); if (!st_fx->bfi_fx && st_fx->prev_bfi_fx && GE_32(st_fx->last_total_brate_fx, HQ_48k) @@ -986,6 +985,8 @@ void amr_wb_dec_fx( st_fx->last_flag_cna = flag_cna; move16(); + updt_dec_common_fx(st_fx, -1, -1, NULL, 0); + /*----------------------------------------------------------------* * Overlap of ACELP synthesis with old MDCT memory *----------------------------------------------------------------*/ @@ -993,19 +994,22 @@ void amr_wb_dec_fx( if( st_fx->bfi_fx ) { /* calculate another loss frame to fill gap in case of switching frame loss */ - acelp_core_switch_dec_bfi_fx( st_fx, st_fx->fer_samples_fx, coder_type ); + if ((error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type_fx )) != IVAS_ERR_OK) + { + return error; + } } delay_comp = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(st_fx->Q_syn2,st_fx->Q_old_postdec)); - st_fx->Q_old_postdec=st_fx->Q_syn2; + Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(st_fx->Q_syn2, hHQ_core->Q_old_postdec)); + hHQ_core->Q_old_postdec=st_fx->Q_syn2; move16(); IF( EQ_16(last_core_ori,HQ_CORE)) { Word16 step, alpha,nz; - Scale_sig(st_fx->old_out_fx, L_FRAME48k, sub(st_fx->Q_syn2,st_fx->Q_old_wtda)); - st_fx->Q_old_wtda=st_fx->Q_syn2; + Scale_sig(hHQ_core->old_out_fx, L_FRAME48k, sub(st_fx->Q_syn2, hHQ_core->Q_old_wtda)); + hHQ_core->Q_old_wtda=st_fx->Q_syn2; move16(); Copy( st_fx->delay_buf_out_fx,synth_out_fx, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ @@ -1020,51 +1024,19 @@ void amr_wb_dec_fx( move16(); test(); - IF( st_fx->prev_bfi_fx && st_fx->HqVoicing_fx ) + IF( st_fx->prev_bfi_fx && hHQ_core->HqVoicing_fx ) { - Copy_Scale_sig( st_fx->fer_samples_fx, &st_fx->old_out_fx[nz], tmps,negate(st_fx->Q_syn2)); + Copy_Scale_sig(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps,negate(st_fx->Q_syn2)); } FOR (i = 0; i < tmps; i++) { - synth_out_fx[i+delay_comp] = msu_r(L_mult(synth_out_fx[i+delay_comp], alpha), st_fx->old_out_fx[i+nz], add(alpha, -32768)); + synth_out_fx[i+delay_comp] = msu_r(L_mult(synth_out_fx[i+delay_comp], alpha), hHQ_core->old_out_fx[i+nz], add(alpha, -32768)); move16(); alpha = add(alpha, step); } } - st_fx->prev_bfi_fx = st_fx->bfi_fx; - st_fx->last_con_tcx = st_fx->con_tcx; - - if( GT_32(st_fx->core_brate_fx,SID_1k75)) - { - st_fx->last_active_brate_fx = st_fx->total_brate_fx; - move32(); - } - - test(); - IF( GT_32(st_fx->core_brate_fx,SID_1k75)&&st_fx->first_CNG_fx) - { - if( GE_16(st_fx->act_cnt_fx,BUF_DEC_RATE)) - { - st_fx->act_cnt_fx = 0; - move16(); - } - - st_fx->act_cnt_fx = add(st_fx->act_cnt_fx,1); - - test(); - if( EQ_16(st_fx->act_cnt_fx,BUF_DEC_RATE)&&st_fx->ho_hist_size_fx>0) - { - st_fx->ho_hist_size_fx = sub(st_fx->ho_hist_size_fx,1); - } - - st_fx->act_cnt2_fx = add(st_fx->act_cnt2_fx,1); - st_fx->act_cnt2_fx = s_min(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD); - } - st_fx->prev_bws_cnt_fx = 0; - st_fx->bws_cnt_fx = 0; - st_fx->bws_cnt1_fx = 0; /*----------------------------------------------------------------* * HP filtering * Final synthesis output @@ -1075,11 +1047,7 @@ void amr_wb_dec_fx( { tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS); Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx) ); - - Copy( synth_out_fx, tmp_buffer_fx, output_frame ); - Copy( st_fx->prev_synth_buffer_fx, synth_out_fx, tmps ); - Copy( tmp_buffer_fx, synth_out_fx + tmps, output_frame - tmps ); - Copy( tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps ); + delay_signal(synth_out_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps); } if (waveadj_rec) @@ -1090,19 +1058,9 @@ void amr_wb_dec_fx( tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS); } - waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, - synth_out_fx+tmps, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - tmps, - add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), - st_fx->bfi_fx); + waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, synth_out_fx+tmps, st_fx->plcInfo.data_noise, &st_fx->plcInfo.outx_new_n1_fx, + &st_fx->plcInfo.nsapp_gain_fx, &st_fx->plcInfo.nsapp_gain_n_fx, &st_fx->plcInfo.recovery_gain, st_fx->plcInfo.step_concealgain_fx, + st_fx->plcInfo.Pitch_fx, st_fx->plcInfo.FrameSize, tmps, add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), st_fx->bfi_fx); } /* HP filter */ @@ -1111,25 +1069,55 @@ void amr_wb_dec_fx( hp20( synth_out_fx, 1/*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0(output_frame, 50) ); /* save synthesis for core switching */ - Copy_Scale_sig( synth_out_fx+NS2SA_fx2( st_fx->output_Fs_fx,ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs_fx,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS), sub(st_fx->Q_old_postdec, st_fx->Q_syn2) ); + Copy_Scale_sig( synth_out_fx+NS2SA_fx2( st_fx->output_Fs_fx,ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs_fx,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS), sub(hHQ_core->Q_old_postdec, st_fx->Q_syn2) ); { /* TCX-LTP Postfilter: used in AMR-WB IO to update memories and to avoid discontinuities when the past frame was TCX */ Word16 delta = NS2SA_fx2( st_fx->output_Fs_fx, TCXLTP_DELAY_NS ); - Scale_sig(st_fx->tcxltp_mem_in, delta, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); - Scale_sig(st_fx->tcxltp_mem_out, output_frame, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); - tcx_ltp_post( st_fx->tcxltp, ACELP_CORE, output_frame, st_fx->L_frame_past, 0, synth_out_fx, NULL, - delta, 0, 0, 0, 0, &st_fx->tcxltp_pitch_int_post_prev, - &st_fx->tcxltp_pitch_fr_post_prev, &st_fx->tcxltp_gain_post_prev, - &st_fx->tcxltp_filt_idx_prev, st_fx->pit_res_max, - &st_fx->pit_res_max_past, - 0, 0, st_fx->tcxltp_mem_in, - st_fx->tcxltp_mem_out, st_fx->total_brate_fx ); + Scale_sig(hTcxLtpDec->tcxltp_mem_in, delta, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); + Scale_sig(hTcxLtpDec->tcxltp_mem_out, output_frame, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); + tcx_ltp_post(st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL); } /* final output of synthesis signal */ syn_output_fx( st_fx->codec_mode, synth_out_fx, output_frame, output_sp, st_fx->Q_syn2 ); + return error; +} +/*------------------------------------------------------------------* + * amr_wb_dec_init() + * + * AMR-WB decoder initialization + *------------------------------------------------------------------*/ + +void amr_wb_dec_init( + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ +) +{ + Word16 i; + /* gain quantization memory (used in AMR-WB IO mode) */ + FOR(i = 0; i < GAIN_PRED_ORDER; i++) + { + hAmrwb_IO->past_qua_en_fx[i] = -14336; + move16(); /* Q10; */ /* gain quantization memory (used also in AMR-WB IO mode) */ + } + /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ + hAmrwb_IO->UV_cnt_fx = 30; + move16(); + hAmrwb_IO->LT_UV_cnt_fx = (60<<6); + move16(); + set16_fx(hAmrwb_IO->lt_diff_etot_fx, 0, MAX_LT); + hAmrwb_IO->Last_ener_fx = 0; + move16(); + + set16_fx(hAmrwb_IO->old_Aq_fx, 0, NB_SUBFR * (M + 1)); + hAmrwb_IO->old_Aq_fx[0] = 16384; + hAmrwb_IO->old_Aq_fx[M + 1] = 16384; + hAmrwb_IO->old_Aq_fx[2 * (M + 1)] = 16384; + hAmrwb_IO->old_Aq_fx[3 * (M + 1)] = 16384; + move16(); move16(); move16(); move16(); + hAmrwb_IO->lt_voice_fac_fx = 0; + move16(); return; } diff --git a/lib_dec/ari_dec.c b/lib_dec/ari_dec.c index c2c8259..df01720 100644 --- a/lib_dec/ari_dec.c +++ b/lib_dec/ari_dec.c @@ -2,9 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "assert.h" -#include "stl.h" +#include "options.h" #include "basop_mpy.h" #include "cnst_fx.h" #include "rom_com_fx.h" @@ -25,7 +25,10 @@ Word16 ari_decode_overflow(TastatDec *s) * \param[i/o] st * \param[o] s */ -void ari_start_decoding_14bits(Decoder_State_fx *st, TastatDec *s) +void ari_start_decoding_14bits( + Decoder_State_fx *st, + TastatDec *s +) { Word32 val; @@ -34,11 +37,15 @@ void ari_start_decoding_14bits(Decoder_State_fx *st, TastatDec *s) s->low = L_deposit_l(0); s->high = ari_q4new+1; move32(); - s->vobf = val; + s->value = val; move32(); } -Word16 ari_start_decoding_14bits_prm(const Word16 *ptr, Word16 bp, TastatDec *s) +Word16 ari_start_decoding_14bits_prm( + const Word16 *ptr, + Word16 bp, + TastatDec *s +) { Word32 val; Word16 i; @@ -59,13 +66,17 @@ Word16 ari_start_decoding_14bits_prm(const Word16 *ptr, Word16 bp, TastatDec *s s->low = L_deposit_l(0); s->high = ari_q4new+1; move32(); - s->vobf = val; + s->value = val; move32(); return add(bp,i); } -static Word16 ari_lookup_s17(Word32 cum, Word32 range, UWord16 const *cum_freq) +static Word16 ari_lookup_s17( + Word32 cum, + Word32 range, + UWord16 const *cum_freq +) { Word32 tmp; const UWord16 *p; @@ -119,7 +130,11 @@ static Word16 ari_lookup_s17(Word32 cum, Word32 range, UWord16 const *cum_freq) return extract_l(p - cum_freq); } -static Word16 ari_lookup_s27(Word32 cum, Word32 range, UWord16 const *cum_freq) +static Word16 ari_lookup_s27( + Word32 cum, + Word32 range, + UWord16 const *cum_freq +) { Word32 tmp; Word16 range_l, range_h; @@ -214,7 +229,11 @@ static Word16 ari_lookup_s27(Word32 cum, Word32 range, UWord16 const *cum_freq) return il; } -static Word16 ari_lookup_bit(Word32 cum, Word32 range, UWord16 const *cum_freq) +static Word16 ari_lookup_bit( + Word32 cum, + Word32 range, + UWord16 const *cum_freq +) { Word16 symbol = 0; /* initialize just to avoid compiler warning */ @@ -256,7 +275,7 @@ static Word16 ari_decode_14bits_ext( move32(); high = s->high; move32(); - value = s->vobf; + value = s->value; move32(); range = L_sub(high, low); @@ -297,7 +316,7 @@ static Word16 ari_decode_14bits_ext( move32(); s->high = high; move32(); - s->vobf = value; + s->value = value; move32(); return symbol; @@ -340,7 +359,7 @@ static Word16 ari_lookup_pow(TastatDec *s, Word16 base) Word16 k; range = L_sub(s->high, s->low); - cum = L_add(L_shl(L_sub(s->vobf, s->low), stat_bitsnew), sub(shl(1,stat_bitsnew),1)); + cum = L_add(L_shl(L_sub(s->value, s->low), stat_bitsnew), sub(shl(1,stat_bitsnew),1)); range_h = extract_l(L_shr(range,15)); range_l = extract_l(L_and(range,0x7FFF)); @@ -416,7 +435,7 @@ static Word16 ari_lookup_sign(TastatDec *s, Word16 base) (void)base; range = L_sub(s->high, s->low); - cum = L_sub(s->vobf, s->low); + cum = L_sub(s->value, s->low); range = L_shr(range, 1); IF (GT_32(range, cum)) @@ -454,7 +473,7 @@ static Word16 ari_decode_14bits_notbl( low = L_add(s->low, 0); high = L_add(s->high, 0); - value = L_add(s->vobf, 0); + value = L_add(s->value, 0); FOR (; bplow,low))&&(EQ_32(s->high,L_sub(high,1)))&&(EQ_32(s->vobf,value))))) + IF ((lookup_fn != ari_lookup_sign) && !(NE_16(bp, bits)||!((EQ_32(s->low,low))&&(EQ_32(s->high,L_sub(high,1)))&&(EQ_32(s->value,value))))) { /* This should not happen except of bit errors. */ s->high = 0; @@ -497,7 +516,7 @@ static Word16 ari_decode_14bits_notbl( move32(); s->high = high; move32(); - s->vobf = value; + s->value = value; move32(); *res = symbol; diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index e8889ba..2ee790e 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -3,11 +3,9 @@ ====================================================================================*/ -#include -#include -#include #include -#include "stl.h" +#include +#include "options.h" #include "cnst_fx.h" #include "basop_util.h" #include "rom_com_fx.h" @@ -19,10 +17,16 @@ DecodeIndex( Word16 Bandwidth, Word16 *PeriodicityIndex) { + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; + + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; + test(); - IF ( (st->tcx_hm_LtpPitchLag > 0) && GT_16(st->tcxltp_gain, kLtpHmGainThr)) + IF ( (hTcxDec->tcx_hm_LtpPitchLag > 0) && GT_16(hTcxLtpDec->tcxltp_gain, kLtpHmGainThr)) { - Word16 LtpPitchIndex = sub(mult_r(st->tcx_hm_LtpPitchLag, 1 << (15-kLtpHmFractionalResolution)), 2); + Word16 LtpPitchIndex = sub(mult_r(hTcxDec->tcx_hm_LtpPitchLag, 1 << (15-kLtpHmFractionalResolution)), 2); *PeriodicityIndex = kLtpHmFlag; move16(); @@ -49,7 +53,7 @@ static Word16 tcx_hm_dequantize_gain( ) { - assert(0 <= coder_type && coder_type <= 1); + assert(0 <= coder_type && coder_type <= UNVOICED); /* safety check in case of bit errors */ test(); @@ -111,14 +115,9 @@ void tcx_hm_decode( move16(); /* Convert the index to lag */ - UnmapIndex( - prm_hm[1], - (L_frame_m_256 >= 0), - LtpPitchLag, + UnmapIndex(prm_hm[1], (L_frame_m_256 >= 0), LtpPitchLag, (( LE_16(NumTargetBits,kSmallerLagsTargetBitsThreshold) ) || ( L_frame_m_256 < 0 )), - &fract_res, - &lag - ); + &fract_res, &lag ); test(); test(); @@ -139,14 +138,7 @@ void tcx_hm_decode( return; } - tcx_hm_modify_envelope( - gain, - lag, - fract_res, - p, - env, - L_frame - ); + tcx_hm_modify_envelope(gain, lag, fract_res, p, env, L_frame ); } diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index ade2b83..f45907d 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -2,15 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include #include - +#include #include "options.h" #include "cnst_fx.h" #include "rom_com_fx.h" -#include "stl.h" #include "prot_fx.h" /* Returns: number of bits consumed */ @@ -109,13 +105,18 @@ void tcx_arith_decode_envelope( Word16 *envelope; /* scaled envelope */ Word16 envelope_e; Word16 L_spec_core; - TCX_config *tcx_cfg; + TCX_CONFIG_HANDLE tcx_cfg; Word16 gamma_w, gamma_uw; Word16 hm_bits; + tcx_cfg = st->hTcxCfg; test(); test(); - IF( GT_16(L_spec,N_MAX_ARI)||GT_16(target_bits,(ACELP_13k20/50))||(target_bits<=0)) + + IF( GT_16(L_spec,N_MAX_ARI)|| (EQ_16(st->element_mode, EVS_MONO) && GT_16(target_bits,(ACELP_13k20/ FRAMES_PER_SEC))) || + (EQ_16(st->element_mode, IVAS_SCE) && (GT_16(st->bits_frame_nominal, (LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC)))) || + (GT_16(st->element_mode, IVAS_SCE) && (GT_16(st->bits_frame_nominal, (LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC)))) || + (target_bits <= 0)) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -132,38 +133,22 @@ void tcx_arith_decode_envelope( } - tcx_cfg = &st->tcx_cfg; *signaling_bits = 0; move16(); - assert(st->enableTcxLpc); + assert(st->hTcxDec->enableTcxLpc); + gamma_w = 32767/*1.0f Q15*/; move16(); gamma_uw = st->inv_gamma; move16(); - tcx_arith_render_envelope( - A_ind, - L_frame, - L_spec, - tcx_cfg->preemph_fac, - gamma_w, - gamma_uw, - env - ); + tcx_arith_render_envelope(A_ind, L_frame, L_spec, tcx_cfg->preemph_fac, gamma_w, gamma_uw, env); IF (use_hm != 0) { IF (prm_hm[0] != 0) { - tcx_hm_decode( - L_spec, - env, - target_bits, - tcx_cfg->coder_type, - prm_hm, - tcxltp_pitch, - &hm_bits - ); + tcx_hm_decode(L_spec, env, target_bits, tcx_cfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits); IF (hm_bits < 0) { @@ -194,30 +179,13 @@ void tcx_arith_decode_envelope( move16(); if (st->igf) { - L_spec_core = s_min(L_spec_core, st->hIGFDec.infoIGFStartLine); + L_spec_core = s_min(L_spec_core, st->hIGFDec->infoIGFStartLine); } envelope = (Word16*)env; - tcx_arith_scale_envelope( - L_spec, - L_spec_core, - env, - target_bits, - low_complexity, - envelope, - &envelope_e - ); - - *arith_bits = tcx_arith_decode( - L_spec, - envelope, - envelope_e, - target_bits, - prm, - q_spectrum, - q_spectrum_e, - nf_seed - ); + tcx_arith_scale_envelope(L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e); + + *arith_bits = tcx_arith_decode(L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed); move16(); /* safety check in case of bit errors */ diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index cfa14a7..96bc85c 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -2,11 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ + +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-----------------------------------------------------------------* * Function AVQ_Demuxdec_Bstr * @@ -15,17 +16,28 @@ *-----------------------------------------------------------------*/ void AVQ_demuxdec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ + Decoder_State_fx *st_fx,/* i/o: decoder state structure */ + Word16 xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ + Word16 *nb_bits, /* i/o: number of allocated bits */ const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[] /* i/o: AVQ nq index */ + Word16 nq[] /* i/o: AVQ nq index */ +#ifdef IVAS_CODE_AVQ + ,Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ +#endif ) { Word16 i,j, bits, order_v; UWord16 I[NSV_MAX]; - Word16 nq[NSV_MAX], *kv, code[8]; + Word16 *kv, code[8]; Word16 tmp16; +#ifdef IVAS_CODE_AVQ + Word16 nq_est, unused_bits_idx; + Word16 bitsMod; + Word16 underflow; + Word16 unusedbitsFlag; + Word16 svOrder[NSV_MAX], k, nullVec, dummy_bits; +#endif set16_fx( (Word16*)I, 0, NSV_MAX ); set16_fx( code, 0, 8 ); @@ -33,9 +45,45 @@ void AVQ_demuxdec_fx( kv = xriq; /* reuse vector to save memory */ bits = *nb_bits; move16(); +#ifdef IVAS_CODE_AVQ + bitsMod = 0; + move16(); + underflow = 0; + move16(); + unusedbitsFlag = 0; + move16(); + nullVec = 0; + move16(); + dummy_bits = 0; + move16(); + svOrder[Nsv - 1] = trgtSvPos; + move16(); + svOrder[0] = 0; + move16(); + svOrder[1] = 1; + move16(); + i = 2; + move16(); + j = i; + move16(); + if (EQ_16(avq_bit_sFlag, 2)) + { + j = add(i, 1); + } + WHILE (LT_16(i, sub(Nsv, 1))) + { + move16(); + svOrder[i] = j; + i++; + j++; + } +#endif FOR( i=0; iBER_detect = 1; move16(); set16_fx( xriq, 0, shl(Nsv,3) ); - set16_fx( nq_out, 0, Nsv ); + set16_fx( nq, 0, Nsv ); *nb_bits = 0; move16(); @@ -143,7 +191,7 @@ void AVQ_demuxdec_fx( FOR ( i=0; i -#include +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_dec_fx.h" /* Static table prototypes */ -#include "stl.h" #include "basop_mpy.h" #include "basop_util.h" @@ -22,7 +21,7 @@ #define BPF_STOP_STOPBAND_16 16 /*---------------------------------------------------------------------* - * Local functions + * Local function prototypes *---------------------------------------------------------------------*/ static Word16 Pit_track_fx(Word16 syn[], Word16 T); @@ -32,17 +31,19 @@ static Word16 Pit_track_fx(Word16 syn[], Word16 T); * Initialisation of postfiltering variables *---------------------------------------------------------------------*/ void bass_psfilter_init_fx( - Word16 old_syn[], /* o : Old synthesis buffer 1 */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener /* o : long_term error signal energy */ + BPF_DEC_HANDLE hBPF /* o : BPF data handle */ ) { /* post-filter memories */ - *mem_deemph_err = 0; + hBPF->pst_mem_deemp_err_fx = 0; move16(); - *lp_ener = 0; + hBPF->pst_lp_ener_fx = 0; move16();/*0 in Q8 */ - set16_fx(old_syn, 0, NBPSF_PIT_MAX); + set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); + set16_fx(hBPF->Track_on_hist_fx, 0, L_TRACK_HIST); + set16_fx(hBPF->vibrato_hist_fx, 0, L_TRACK_HIST); + set16_fx(hBPF->mem_mean_pit_fx, 80, L_TRACK_HIST); + hBPF->psf_att_fx = 32767; return; } @@ -76,23 +77,17 @@ void bass_psfilter_init_fx( /*=========================================================================*/ void bass_psfilter_fx( - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ - Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) */ - const Word16 L_frame, /* i : length of the last frame */ + BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ + const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ + Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) */ + const Word16 L_frame, /* i : length of the last frame */ Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ - Word16 old_syn_fx[], /* i/o: NBPSF_PIT_MAX */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener, /* o : long_term error signal energy */ - const Word16 bpf_off, /* i : do not use BPF when set to 1 */ - Word16 v_stab_fx, /* i : stability factor */ - Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ - Word16 *mem_mean_pit, /* i/o: average pitch memory */ - Word16 *Track_on_hist, /* i/o: History of half frame usage */ - Word16 *vibrato_hist, /* i/o: History of frames declared as vibrato*/ - Word16 *psf_att, /* i/o: Post filter attenuation factor */ - const Word16 coder_type, /* i : coder_type */ + const Word16 bpf_off, /* i : do not use BPF when set to 1 */ + Word16 v_stab_fx, /* i : stability factor */ + Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ + const Word16 coder_type, /* i : coder_type */ Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ + Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ ) { Word16 i, j, i_subfr, T, exp, exp2; @@ -111,14 +106,31 @@ void bass_psfilter_fx( Word16 loc_pit_max, loc_pit_min, diff_pit; Word16 TrackOnR, vibratR, alp_tmp; Word16 Q_syn2x; + Word16 subfr_len; + Word16 nbpsf_pit_max; + Track_on = 0; move16(); vibrato = 0; move16(); - - nb_subfr = shr(L_frame,6); + IF(EQ_16(L_frame, L_FRAME8k)) + { + subfr_len = STEREO_DFT_L_SUBFR_8k; + move16(); + nbpsf_pit_max = STEREO_DFT_NBPSF_PIT_MAX_8k; + move16(); + nb_subfr = shr(L_frame,5); + } + ELSE + { + subfr_len = L_SUBFR; + move16(); + nbpsf_pit_max = NBPSF_PIT_MAX; + move16(); + nb_subfr = shr(L_frame,6); + } move16(); /*------------------------------------------------------- @@ -135,15 +147,15 @@ void bass_psfilter_fx( Q_syn2x = shl(Q_syn, 1); move16(); - Copy(old_syn_fx, syn_buf_fx, NBPSF_PIT_MAX); - Copy(synth_in_fx, syn_buf_fx+NBPSF_PIT_MAX, L_frame); + Copy(hBPF->pst_old_syn_fx, syn_buf_fx, nbpsf_pit_max); + Copy(synth_in_fx, syn_buf_fx+nbpsf_pit_max, L_frame); test(); IF( !(pitch_buf_fx == NULL || bpf_off) ) { FOR(i = L_TRACK_HIST-1; i > 0; i--) { - mem_mean_pit[i] = mem_mean_pit[i-1]; + hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[i-1]; move16(); /*Q6 */ } Ltmp = L_deposit_l(0); @@ -158,15 +170,15 @@ void bass_psfilter_fx( { tmp = mult_r(tmp, 26214); /* multiply by 0.8 for case where L_frame == L_FRAME16k*/ } - mem_mean_pit[i] = tmp; /*Q4 */ move16(); + hBPF->mem_mean_pit_fx[i] = tmp; /*Q4 */ move16(); } - idx_pit_min = minimum_fx(mem_mean_pit, L_TRACK_HIST, &loc_pit_min); - idx_pit_max = maximum_fx(mem_mean_pit, L_TRACK_HIST, &loc_pit_max); + idx_pit_min = minimum_fx(hBPF->mem_mean_pit_fx, L_TRACK_HIST, &loc_pit_min); + idx_pit_max = maximum_fx(hBPF->mem_mean_pit_fx, L_TRACK_HIST, &loc_pit_max); dist_pit_diff = abs_s(sub(idx_pit_max,idx_pit_min)); diff_pit = sub(loc_pit_max,loc_pit_min); /*Q4 */ - - if( EQ_16(L_frame,L_FRAME16k)) + test(); + if( EQ_16(L_frame,L_FRAME16k) || EQ_16(L_frame, L_FRAME8k)) { diff_pit = mult_r(diff_pit,26214); /*Q4 */ } @@ -180,10 +192,10 @@ void bass_psfilter_fx( move16(); } - tmp = sum16_fx(Track_on_hist,L_TRACK_HIST); + tmp = sum16_fx(hBPF->Track_on_hist_fx,L_TRACK_HIST); TrackOnR = round_fx(L_shl(L_mult0(tmp,3277),16)); /*Q15 */ - vibratR = sum16_fx(vibrato_hist,L_TRACK_HIST); /*Q0 */ + vibratR = sum16_fx(hBPF->vibrato_hist_fx,L_TRACK_HIST); /*Q0 */ alp_tmp = sub(32767,TrackOnR); /*Q15 */ @@ -198,26 +210,30 @@ void bass_psfilter_fx( alp_tmp = s_max( 3277, alp_tmp ); - IF( GT_16(alp_tmp,*psf_att)) + IF( GT_16(alp_tmp, hBPF->psf_att_fx)) { /**psf_att = add(mult_r(1638,alp_tmp),mult_r(31130,*psf_att)); //Q15 */ - *psf_att = round_fx(L_mac(L_mult(1638,alp_tmp),31130,*psf_att)); /*Q15 */ + hBPF->psf_att_fx = round_fx(L_mac(L_mult(1638,alp_tmp),31130, hBPF->psf_att_fx)); /*Q15 */ } ELSE { /**psf_att = add(mult_r(13107,alp_tmp),mult_r(19661,*psf_att)); //Q15 */ - *psf_att = round_fx(L_mac(L_mult(13107,alp_tmp),19661,*psf_att)); /*Q15 */ + hBPF->psf_att_fx = round_fx(L_mac(L_mult(13107,alp_tmp),19661,hBPF->psf_att_fx)); /*Q15 */ } test(); IF( pitch_buf_fx == NULL || bpf_off ) { /* do not use BPF for HQ core */ T_update = 80; + if (EQ_16(L_frame, L_FRAME8k)) + { + T_update = 40; + } move16(); set16_fx( T_sf, 0, 5 ); - syn_fx = &syn_buf_fx[NBPSF_PIT_MAX+L_frame]; + syn_fx = &syn_buf_fx[add(nbpsf_pit_max,L_frame)]; sigPtr = syn_fx-T_update; - FOR (i=0; ipst_lp_ener_fx), &tmp2); /* 2786635L is Q31 : 0.1xLog2(10) / 256 (/256 because lp_ener is Q8) */ /* Note: 'Ltmp' is still the absolute value of 'Lcorr' 'tmp' is still 'Ltmp' normalized and rounded to 16 bits However, exp has to be recalculated because it is affected by exp = sub(exp, 1) before the div_s */ @@ -374,7 +394,7 @@ void bass_psfilter_fx( alpha = s_min(alpha, 16384);/*Q15 */ - alpha = mult_r(alpha,*psf_att); + alpha = mult_r(alpha,hBPF->psf_att_fx); test(); test(); IF (GT_16(alpha,9830)&&Track_on) @@ -409,7 +429,7 @@ void bass_psfilter_fx( tmp = sub(tmp,delta_v_stab);/*Q14 */ alpha = mult(tmp,alpha);/*Q14 */ - FOR (i=0; ipst_mem_deemp_err_fx)); /* +20dB at 50Hz */ Lener = L_deposit_h(-32768); /* by using the maximum negative value it is possible to gain another bit of range for the 'Lener' sum. This sum is divided by 4 */ - FOR (i=0; ipst_lp_ener_fx = mac_r(Lener, hBPF->pst_lp_ener_fx, 32440); move16(); /* just write out the error signal */ - Copy( syn2_fx, bpf_noise_buf + i_subfr, L_SUBFR ); + Copy( syn2_fx, bpf_noise_buf + i_subfr, subfr_len ); } ELSE { /* symetric pitch prediction : phase is opposite between harmonic */ - FOR (i=0; ipst_lp_ener_fx), &tmp2); /* 2786635L is Q31 : 0.1xLog2(10) / 256 (/256 because lp_ener is Q8) */ /* Note: 'Ltmp' is still the absolute value of 'Lcorr' 'tmp' is still 'Ltmp' normalized and rounded to 16 bits However, exp has to be recalculated because it is affected by exp = sub(exp, 1) before the div_s */ @@ -565,21 +585,21 @@ void bass_psfilter_fx( *v_stab_smooth_fx = add(tmp2,tmp); move16(); - FOR (i=0; ipst_mem_deemp_err_fx)); /* +20dB at 50Hz */ Lener = L_deposit_h(-32768); /* by using the maximum negative value it is possible to gain another bit of range for the 'Lener' sum. This sum is divided by 4 */ - FOR (i=0; ipst_lp_ener_fx = mac_r(Lener, hBPF->pst_lp_ener_fx, 32440); move16(); /* just write out the error signal */ - Copy( syn2_fx, bpf_noise_buf + i_subfr, L_SUBFR ); + Copy( syn2_fx, bpf_noise_buf + i_subfr, subfr_len ); } subfr_pos = add(subfr_pos, 1); @@ -626,18 +646,18 @@ void bass_psfilter_fx( FOR( i = L_TRACK_HIST-1; i > 0; i-- ) { - Track_on_hist[i] = Track_on_hist[i-1]; + hBPF->Track_on_hist_fx[i] = hBPF->Track_on_hist_fx[i-1]; move16(); - vibrato_hist[i] = vibrato_hist[i-1]; + hBPF->vibrato_hist_fx[i] = hBPF->vibrato_hist_fx[i-1]; move16(); } - Track_on_hist[i] = Track_on; + hBPF->Track_on_hist_fx[i] = Track_on; move16(); - vibrato_hist[i] = vibrato; + hBPF->vibrato_hist_fx[i] = vibrato; move16(); - Copy( syn_buf_fx+L_frame, old_syn_fx, NBPSF_PIT_MAX ); + Copy( syn_buf_fx+L_frame, hBPF->pst_old_syn_fx, nbpsf_pit_max ); return; @@ -774,17 +794,18 @@ static Word16 Pit_track_fx( /* o : Pitch */ * Add BPF component in cldfb domain *---------------------------------------------------------------------*/ -void addBassPostFilterFx (const Word16 *harm_timeIn_Fx, - Word32 **rAnalysis_Fx, - Word32 **iAnalysis_Fx, - HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, - Word32 *workBuffer, - const Word16 timeIn_e, - const Word16 nTimeSlots, - const Word16 nTimeSlotsTotal, - const Word16 nBandsTotal, - CLDFB_SCALE_FACTOR *cldfb_scale - ) +void addBassPostFilterFx ( + const Word16 *harm_timeIn_Fx, + Word32 **rAnalysis_Fx, + Word32 **iAnalysis_Fx, + HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, + Word32 *workBuffer, + const Word16 timeIn_e, + const Word16 nTimeSlots, + const Word16 nTimeSlotsTotal, + const Word16 nBandsTotal, + CLDFB_SCALE_FACTOR *cldfb_scale + ) { Word16 i, scale1, scale2; Word16 b; @@ -866,3 +887,108 @@ void addBassPostFilterFx (const Word16 *harm_timeIn_Fx, return; } +#ifdef ADD_BPF_ADAPT +/*---------------------------------------------------------------------* + * res_bpf_adapt() + * + * Analyze BPF output and decide if it should be applied on DFT stereo + * residual signal + *---------------------------------------------------------------------*/ + + /*! r: Decision to enable or disable BPF on DFT stereo residual */ +int16_t res_bpf_adapt( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ + const float* bpf_error_signal_8k, /* i : BPF modification signal */ + float res_buf[STEREO_DFT_BUF_MAX] /* i : residual buffer */ +) +{ + float error_nrg; + float tmp; + float res_hb_nrg; + float bpf_error_ratio; + int16_t res_bpf_flag; + int16_t i; + int16_t i_start; + int16_t i_end; + float bw_inv; + + if (hStereoDft->res_cod_band_max == 6) + { + i_start = 39; + i_end = 64; + bw_inv = 0.04f; /* 1/(64 - 39) */ + } + else + { + i_start = 28; + i_end = 40; + bw_inv = 0.083f; /* 1/(40 - 28) */ + } + + /* Measure energy of high frequency band in MDCT domain */ + res_hb_nrg = EPSILON; + for (i = i_start; i < i_end; i++) + { + res_hb_nrg += res_buf[i] * res_buf[i]; + } + res_hb_nrg *= bw_inv; + res_hb_nrg = STEREO_DFT_BPF_ADAPT_ALPHA * res_hb_nrg + (1 - STEREO_DFT_BPF_ADAPT_ALPHA) * hStereoDft->res_hb_nrg_mem; + hStereoDft->res_hb_nrg_mem = res_hb_nrg; + + /* Measure energy of discontinuities at subframe boundaries */ + error_nrg = 0; + for (i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k) + { + tmp = bpf_error_signal_8k[i] - hStereoDft->bpf_error_signal_last; + error_nrg += tmp * tmp; + hStereoDft->bpf_error_signal_last = bpf_error_signal_8k[i + STEREO_DFT_L_SUBFR_8k - 1]; + } + error_nrg *= 0.2f; /* Division by 5 for average value */ + bpf_error_ratio = min(2, error_nrg / res_hb_nrg); /* Form decision variable and apply limit */ + bpf_error_ratio = STEREO_DFT_BPF_ADAPT_BETA * bpf_error_ratio + (1 - STEREO_DFT_BPF_ADAPT_BETA) * hStereoDft->bpf_error_ratio_mem; + hStereoDft->bpf_error_ratio_mem = bpf_error_ratio; + + res_bpf_flag = bpf_error_ratio < 1; + + return res_bpf_flag; +} + +/*---------------------------------------------------------------------* + * bpf_pitch_coherence() + * + * Analyse pitch coherence + *---------------------------------------------------------------------*/ +void bpf_pitch_coherence( + Decoder_State* st, /* i/o: decoder state structure */ + const float pitch_buf[] /* i : pitch for every subfr [0,1,2,3] */ +) +{ + int16_t nb_subfr; + float pc, pcn1, pcn2, pcn3; + + nb_subfr = st->L_frame / L_SUBFR; + + if (st->clas_dec > UNVOICED_CLAS && st->element_mode != EVS_MONO) + { + pc = (float)fabs(st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - st->old_pitch_buf[nb_subfr] - st->old_pitch_buf[nb_subfr + 1]) * 256.0f / (float)st->L_frame; + pcn1 = K_PC_DEC * pc + C_PC_DEC; + pcn1 = max(min(pcn1, 1.0f), 0.0f); + + pc = (float)fabs(pitch_buf[nb_subfr - 1] + pitch_buf[nb_subfr - 2] - pitch_buf[1] - pitch_buf[0]) * 256.0f / (float)st->L_frame; + pcn2 = K_PC_DEC * pc + C_PC_DEC; + pcn2 = max(min(pcn2, 1.0f), 0.0f); + + pc = (float)fabs(st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - pitch_buf[1] - pitch_buf[0]) * 256.0f / (float)st->L_frame; + pcn3 = K_PC_DEC * pc + C_PC_DEC; + pcn3 = max(min(pcn3, 1.0f), 0.0f); + + if (pcn1 + pcn2 + pcn3 < 2.5f) + { + st->hBPF->psf_att = 0.4f; + set_s(&st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr); + } + } + + return; +} +#endif \ No newline at end of file diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index f048c79..583f2ab 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -2,40 +2,36 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ - -#include "stl.h" #include "prot_fx.h" #include "cnst_fx.h" #include "rom_com_fx.h" #include "basop_mpy.h" -#include +#include "ivas_cnst.h" /*Temporary location to be move in prot* when merge is done*/ void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); void E_LPC_f_lsp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); /*-----------------------------------------------------------------* - * Local functions + * Local function prototypes *-----------------------------------------------------------------*/ -static void shb_CNG_decod_fx( Decoder_State_fx *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw - ,const Word16 Qsyn - ); +static void shb_CNG_decod_fx( Decoder_State_fx *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw,const Word16 Qsyn); /*-----------------------------------------------------------------* * Decode residual signal energy *-----------------------------------------------------------------*/ void CNG_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ + Decoder_State_fx *st_fx, /* i/o: State structure */ + const Word16 last_element_mode, /* i : last element mode Q0 */ + Word16 Aq[], /* o : LP coefficients Q12 */ + Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ + Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ + Word16 *allow_cn_step, /* o : allow CN step Q0 */ + Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ ,Word32 *q_env ) { @@ -54,7 +50,7 @@ void CNG_dec_fx( Word16 tmp1,exp; Word16 lsf_tmp[M]; Word32 C[M]; - Word32 max[2]; + Word32 max_val[2]; Word16 max_idx[2]; Word16 ftmp_fx; Word16 lsp_tmp[M]; @@ -71,7 +67,12 @@ void CNG_dec_fx( Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; Word16 tmp_loop; + Word16 enr_new, Aq_tmp[M + 1]; + Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ + TD_CNG_DEC_HANDLE hTdCngDec; + + hTdCngDec = st_fx->hTdCngDec; m = 0; move16(); @@ -79,44 +80,42 @@ void CNG_dec_fx( * Decode CNG spectral envelope (only in SID frame) *-----------------------------------------------------------------*/ test(); - IF ( EQ_32(core_brate,SID_1k75)||EQ_32(core_brate,SID_2k40)) + IF ( EQ_32(st_fx->core_brate_fx,SID_1k75) || EQ_32(st_fx->core_brate_fx,SID_2k40)) { /* de-quantize the LSF vector */ IF ( st_fx->Opt_AMR_WB_fx != 0 ) { /* Flt function */ isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new); - { - Word16 enr_new, Aq_tmp[M + 1]; - /* check if ISPs may trigger too much synthesis energy */ + /* check if ISPs may trigger too much synthesis energy */ - E_LPC_f_isp_a_conversion(lsp_new, Aq_tmp, M); - enr_new = Enr_1_Az_fx(Aq_tmp, 2 * L_SUBFR); + E_LPC_f_isp_a_conversion(lsp_new, Aq_tmp, M); + enr_new = Enr_1_Az_fx(Aq_tmp, 2 * L_SUBFR); - IF ((shr(enr_new, 14) > 0)) - { - /* Use old LSP vector */ - Copy(st_fx->lsp_old_fx, lsp_new, M); - Copy(st_fx->lsf_old_fx, lsf_new, M); - } + IF ((shr(enr_new, 14) > 0)) + { + /* Use old LSP vector */ + Copy(st_fx->lsp_old_fx, lsp_new, M); + Copy(st_fx->lsf_old_fx, lsf_new, M); } } ELSE { - lsf_dec_fx( st_fx, 0, L_frame, INACTIVE, -1, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0 ); - { - Word16 enr_new, Aq_tmp[M + 1]; - /* check if LSPs may trigger too much synthesis energy */ + lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,NULL +#endif + ); + /* check if LSPs may trigger too much synthesis energy */ - E_LPC_f_lsp_a_conversion(lsp_new, Aq_tmp, M); - enr_new = Enr_1_Az_fx(Aq_tmp, 2 * L_SUBFR); + E_LPC_f_lsp_a_conversion(lsp_new, Aq_tmp, M); + enr_new = Enr_1_Az_fx(Aq_tmp, 2 * L_SUBFR); - IF(shr(enr_new, 14) > 0) - { - /* Use old LSP vector */ - Copy(st_fx->lsp_old_fx, lsp_new, M); - Copy(st_fx->lsf_old_fx, lsf_new, M); - } + IF(shr(enr_new, 14) > 0) + { + /* Use old LSP vector */ + Copy(st_fx->lsp_old_fx, lsp_new, M); + Copy(st_fx->lsf_old_fx, lsf_new, M); } } } @@ -140,17 +139,17 @@ void CNG_dec_fx( *allow_cn_step = 0; move16(); test(); - IF( EQ_32(core_brate,SID_1k75)||EQ_32(core_brate,SID_2k40)) + IF( EQ_32(st_fx->core_brate_fx,SID_1k75) || EQ_32(st_fx->core_brate_fx,SID_2k40)) { istep = ISTEP_AMR_WB_SID_FX; move16(); - if( EQ_32(core_brate,SID_2k40)) + if( EQ_32(st_fx->core_brate_fx,SID_2k40)) { istep = ISTEP_SID_FX; move16(); } - /* intialize the energy quantization parameters */ + /* initialize the energy quantization parameters */ num_bits = 6; move16(); if( st_fx->Opt_AMR_WB_fx == 0 ) @@ -164,13 +163,13 @@ void CNG_dec_fx( IF( LE_32(st_fx->last_core_brate_fx, SID_2k40) || EQ_16(st_fx->prev_bfi_fx, 1) ) { - tmp1 = add(st_fx->old_enr_index_fx, 20); + tmp1 = add(hTdCngDec->old_enr_index_fx, 20); } ELSE { - tmp1 = add(st_fx->old_enr_index_fx, 40); + tmp1 = add(hTdCngDec->old_enr_index_fx, 40); } - IF( GT_16(L_enr_index, tmp1) && st_fx->old_enr_index_fx >= 0 ) /* Likely bit error and not startup */ + IF( GT_16(L_enr_index, tmp1) && hTdCngDec->old_enr_index_fx >= 0 ) /* Likely bit error and not startup */ { L_enr_index = tmp1; move16(); L_enr_index = s_min(L_enr_index, 127); @@ -183,16 +182,16 @@ void CNG_dec_fx( test(); test(); test(); - if (GT_32(st_fx->last_core_brate_fx,SID_1k75)&& + IF (GT_32(st_fx->last_core_brate_fx,SID_1k75)&& st_fx->first_CNG_fx != 0 && - st_fx->old_enr_index_fx >= 0 && - GT_16(L_enr_index, add(st_fx->old_enr_index_fx,1))) + hTdCngDec->old_enr_index_fx >= 0 && + GT_16(L_enr_index, add(hTdCngDec->old_enr_index_fx,1))) { *allow_cn_step = 1; move16(); } - st_fx->old_enr_index_fx = L_enr_index; + hTdCngDec->old_enr_index_fx = L_enr_index; move16(); if ( L_enr_index == 0 ) { @@ -201,16 +200,16 @@ void CNG_dec_fx( } /* st_fx->Enew = L_enr_index / step - 2.0f;*/ L_ener = L_mult(L_enr_index, istep); /* Q16 (0+15) */ - /* substract by 2 not done to leave Energy in Q2 */ + /* subtract by 2 not done to leave Energy in Q2 */ /* extract integral and fractional parts */ ener_fra = L_Extract_lc(L_ener, &ener_int); ener_int = add(ener_int, 4); /* Q2 to Q6 */ /* find the new energy value */ - st_fx->Enew_fx = Pow2(ener_int, ener_fra); + hTdCngDec->Enew_fx = Pow2(ener_int, ener_fra); - IF( EQ_32(core_brate,SID_2k40)) + IF( EQ_32(st_fx->core_brate_fx,SID_2k40)) { burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */ @@ -230,9 +229,9 @@ void CNG_dec_fx( /* Reset CNG history if CNG frame length is changed */ test(); test(); - if ( EQ_16(st_fx->bwidth_fx,WB)&&st_fx->first_CNG_fx!=0&&NE_16(st_fx->L_frame_fx,st_fx->last_CNG_L_frame_fx)) + IF ( EQ_16(st_fx->bwidth_fx,WB) && st_fx->first_CNG_fx!=0 && NE_16(st_fx->L_frame_fx,st_fx->last_CNG_L_frame_fx)) { - st_fx->ho_hist_size_fx = 0; + hTdCngDec->ho_hist_size_fx = 0; move16(); } } @@ -249,12 +248,12 @@ void CNG_dec_fx( /* Reset hangover counter if not first SID period */ if( GT_32(st_fx->core_brate_fx,FRAME_NO_DATA)) { - st_fx->num_ho_fx = 0; + hTdCngDec->num_ho_fx = 0; move16(); } - /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ + /* Update LSPs if last SID energy not outliers or insufficient number of hangover frames */ test(); - IF( LT_16(st_fx->num_ho_fx,3)||LT_32(Mult_32_16(st_fx->Enew_fx,21845/*1/1.5f, Q15*/),st_fx->lp_ener_fx)) + IF( LT_16(hTdCngDec->num_ho_fx,3) || LT_32(Mult_32_16(hTdCngDec->Enew_fx,21845/*1/1.5f, Q15*/),st_fx->lp_ener_fx)) { FOR( i=0; iOpt_AMR_WB_fx || EQ_16(st_fx->bwidth_fx,WB)) - && ( !st_fx->first_CNG_fx || GE_16(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD) ) ) + && ( !st_fx->first_CNG_fx || GE_16(hTdCngDec->act_cnt2_fx,MIN_ACT_CNG_UPD) ) ) { IF( GT_32(st_fx->last_active_brate_fx,ACELP_16k40)) { st_fx->CNG_mode_fx = -1; move16(); } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_13k20)) - { - st_fx->CNG_mode_fx = 4; - move16(); - } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_9k60)) - { - st_fx->CNG_mode_fx = 3; - move16(); - } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_8k00)) - { - st_fx->CNG_mode_fx = 2; - move16(); - } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_7k20)) - { - st_fx->CNG_mode_fx = 1; - move16(); - } ELSE { - st_fx->CNG_mode_fx = 0; + st_fx->CNG_mode_fx = get_cng_mode(st_fx->last_active_brate_fx); move16(); } } /* If first sid after active burst update LSF history from circ buffer */ - burst_ho_cnt = s_min(burst_ho_cnt, st_fx->ho_circ_size_fx); /* MODE1_DTX_IN_CODEC_B_FIX */ - st_fx->act_cnt_fx = 0; + burst_ho_cnt = s_min(burst_ho_cnt, hTdCngDec->ho_circ_size_fx); /* MODE1_DTX_IN_CODEC_B_FIX */ + hTdCngDec->act_cnt_fx = 0; move16(); - s_ptr = add(sub(st_fx->ho_circ_ptr_fx, burst_ho_cnt),1); + s_ptr = add(sub(hTdCngDec->ho_circ_ptr_fx, burst_ho_cnt),1); move16(); if( s_ptr < 0 ) { - s_ptr = add(s_ptr,st_fx->ho_circ_size_fx); + s_ptr = add(s_ptr, hTdCngDec->ho_circ_size_fx); } FOR( ll = burst_ho_cnt; ll > 0; ll-- ) { - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx,1); - if( EQ_16(st_fx->ho_hist_ptr_fx, HO_HIST_SIZE)) + hTdCngDec->ho_hist_ptr_fx = add(hTdCngDec->ho_hist_ptr_fx,1); + if( EQ_16(hTdCngDec->ho_hist_ptr_fx, HO_HIST_SIZE)) { - st_fx->ho_hist_ptr_fx = 0; + hTdCngDec->ho_hist_ptr_fx = 0; move16(); } @@ -329,66 +308,72 @@ void CNG_dec_fx( test(); test(); test(); - IF( ( EQ_16(L_frame,L_FRAME16k)&&st_fx->ho_16k_lsp_fx[s_ptr]==0)||(EQ_16(L_frame,L_FRAME)&&EQ_16(st_fx->ho_16k_lsp_fx[s_ptr],1))) + IF( ( EQ_16(st_fx->L_frame_fx,L_FRAME16k) && hTdCngDec->ho_16k_lsp_fx[s_ptr]==0) || (EQ_16(st_fx->L_frame_fx,L_FRAME) && EQ_16(hTdCngDec->ho_16k_lsp_fx[s_ptr],1))) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &(st_fx->ho_lsp_circ_fx[s_ptr*M]), L_frame, 0 ); + lsp_convert_poly_fx( &(hTdCngDec->ho_lsp_circ_fx[s_ptr*M]), st_fx->L_frame_fx, 0 ); } /* update the circular buffers */ - Copy(&(st_fx->ho_lsp_circ_fx[s_ptr*M]), &(st_fx->ho_lsp_hist_fx[st_fx->ho_hist_ptr_fx*M]), M ); - Copy32(&(st_fx->ho_ener_circ_fx[s_ptr]), &(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx]), 1 ); - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - Copy32(&(st_fx->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(st_fx->ho_env_hist_fx[st_fx->ho_hist_ptr_fx*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy(&(hTdCngDec->ho_lsp_circ_fx[s_ptr*M]), &(hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr_fx*M]), M ); + Copy32(&(hTdCngDec->ho_ener_circ_fx[s_ptr]), &(hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr_fx]), 1 ); + hTdCngDec->ho_sid_bw_fx = L_shl(L_and(hTdCngDec->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); + Copy32(&(hTdCngDec->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr_fx*NUM_ENV_CNG]), NUM_ENV_CNG ); - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); + hTdCngDec->ho_hist_size_fx = add(hTdCngDec->ho_hist_size_fx,1); - if (GT_16(st_fx->ho_hist_size_fx, HO_HIST_SIZE)) + if (GT_16(hTdCngDec->ho_hist_size_fx, HO_HIST_SIZE)) { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; + hTdCngDec->ho_hist_size_fx = HO_HIST_SIZE; move16(); } s_ptr = add(s_ptr,1); - if( EQ_16(s_ptr, st_fx->ho_circ_size_fx)) + if( EQ_16(s_ptr, hTdCngDec->ho_circ_size_fx)) { s_ptr = 0; move16(); } } - IF( st_fx->ho_hist_size_fx > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ + IF(hTdCngDec->ho_hist_size_fx > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ { /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ - L_tmp1 = L_shr(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx], 2); + L_tmp1 = L_shr(hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr_fx], 2); L_tmp1 = L_sub(L_tmp1, st_fx->lp_ener_fx); - if(L_tmp1 > 0) + test(); test(); + if( ( L_tmp1 > 0 && (st_fx->first_CNG_fx || EQ_16(st_fx->element_mode, EVS_MONO) ) ) ) { *allow_cn_step = s_or(*allow_cn_step,1); } } + IF ( EQ_16(last_element_mode, IVAS_CPE_TD) ) + { + *allow_cn_step = 1; + move16(); + } test(); - IF ( *allow_cn_step == 0 && st_fx->ho_hist_size_fx > 0 ) + IF ( *allow_cn_step == 0 && hTdCngDec->ho_hist_size_fx > 0 ) { /* Use average of energies below last energy */ - ptr = st_fx->ho_hist_ptr_fx; + ptr = hTdCngDec->ho_hist_ptr_fx; move16(); - Copy( &(st_fx->ho_lsp_hist_fx[ptr*M]), tmp, M ); + Copy( &(hTdCngDec->ho_lsp_hist_fx[ptr*M]), tmp, M ); m1 = 0; move16(); - IF( L_and(st_fx->ho_sid_bw_fx, (Word32) 0x1) == 0 ) + IF( L_and(hTdCngDec->ho_sid_bw_fx, (Word32) 0x1) == 0 ) { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } - L_enr = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ + L_enr = Mult_32_16(hTdCngDec->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ weights = W_DTX_HO_FX[0]; /* Q15 */ m = 1; move16(); - FOR( k=1; kho_hist_size_fx; k++ ) + FOR( k=1; k< hTdCngDec->ho_hist_size_fx; k++ ) { ptr = sub(ptr,1); if( ptr < 0 ) @@ -398,20 +383,20 @@ void CNG_dec_fx( } test(); - IF ( LT_32(Mult_32_16(st_fx->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx])&& - GT_32(st_fx->ho_ener_hist_fx[ptr],Mult_32_16(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx], BUF_L_NRG_FX))) + IF ( LT_32(Mult_32_16(hTdCngDec->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr_fx])&& + GT_32(hTdCngDec->ho_ener_hist_fx[ptr],Mult_32_16(hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr_fx], BUF_L_NRG_FX))) { /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/ - L_tmp1 = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ + L_tmp1 = Mult_32_16(hTdCngDec->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ L_enr = L_add(L_enr,L_tmp1); /* Q6 */ /*weights += W_DTX_HO[k];*/ weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ - Copy( &st_fx->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); - IF( L_and(st_fx->ho_sid_bw_fx, L_shl((Word32)0x1,k)) == 0 ) + Copy( &hTdCngDec->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); + IF( L_and(hTdCngDec->ho_sid_bw_fx, L_shl((Word32)0x1,k)) == 0 ) { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); m1 = add(m1,1); } m = add(m,1); @@ -426,7 +411,7 @@ void CNG_dec_fx( st_fx->lp_ener_fx = L_enr; /* Q6 */ - set32_fx( max, 0, 2 ); + set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); FOR( i=0; ilp_env_fx, NUM_ENV_CNG); + Copy32(env, hTdCngDec->lp_env_fx, NUM_ENV_CNG); } } ELSE @@ -581,33 +566,33 @@ void CNG_dec_fx( } test(); - IF( EQ_32(st_fx->core_brate_fx, SID_1k75)||EQ_32(st_fx->core_brate_fx,SID_2k40)) + IF( EQ_32(st_fx->core_brate_fx, SID_1k75) || EQ_32(st_fx->core_brate_fx,SID_2k40)) { /* Update hangover memory during CNG */ test(); - IF ( *allow_cn_step == 0 && LT_32(st_fx->Enew_fx,L_add(st_fx->lp_ener_fx,L_shr(st_fx->lp_ener_fx,1)))) + IF ( *allow_cn_step == 0 && LT_32(hTdCngDec->Enew_fx,L_add(st_fx->lp_ener_fx,L_shr(st_fx->lp_ener_fx,1)))) { /* update the pointer to circular buffer of old LSP vectors */ - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx, 1); - if( EQ_16(st_fx->ho_hist_ptr_fx,HO_HIST_SIZE)) + hTdCngDec->ho_hist_ptr_fx = add(hTdCngDec->ho_hist_ptr_fx, 1); + if( EQ_16(hTdCngDec->ho_hist_ptr_fx,HO_HIST_SIZE)) { - st_fx->ho_hist_ptr_fx = 0; + hTdCngDec->ho_hist_ptr_fx = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(st_fx->ho_lsp_hist_fx[(st_fx->ho_hist_ptr_fx)*M]), M ); + Copy( lsp_new, &(hTdCngDec->ho_lsp_hist_fx[(hTdCngDec->ho_hist_ptr_fx)*M]), M ); /* update the hangover energy buffer */ - st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx] = st_fx->Enew_fx; + hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr_fx] = hTdCngDec->Enew_fx; move32(); test(); - IF ( EQ_32(core_brate,SID_2k40)&&*sid_bw==0) + IF ( EQ_32(st_fx->core_brate_fx,SID_2k40)&&*sid_bw==0) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l(st_fx->Enew_fx); - L_tmp = L_shl(st_fx->Enew_fx,exp);/*Q(exp+6)*/ - L_tmp = Mult_32_16(L_tmp,shl(L_frame,5));/*Q(exp+6+5-15=exp-4)*/ + exp = norm_l(hTdCngDec->Enew_fx); + L_tmp = L_shl(hTdCngDec->Enew_fx,exp);/*Q(exp+6)*/ + L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame_fx,5));/*Q(exp+6+5-15=exp-4)*/ L_tmp = L_shr(L_tmp,sub(exp,10));/*Q6*/ exp = norm_l(L_tmp); @@ -627,22 +612,22 @@ void CNG_dec_fx( exp_pow = sub(14, temp_hi_fx); L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ env[i] = L_shl(L_tmp, sub(6, exp_pow)); /* Q6 */ - L_tmp = L_add(st_fx->Enew_fx,st_fx->Enew_fx); + L_tmp = L_add(hTdCngDec->Enew_fx, hTdCngDec->Enew_fx); env[i] = L_add(env[i],L_tmp); /* Q6 */ move32(); } - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - Copy32( env, &(st_fx->ho_env_hist_fx[(st_fx->ho_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); + hTdCngDec->ho_sid_bw_fx = L_shl(L_and(hTdCngDec->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); + Copy32( env, &(hTdCngDec->ho_env_hist_fx[(hTdCngDec->ho_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); } ELSE IF( *sid_bw != 0 ) { - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - st_fx->ho_sid_bw_fx = L_or(st_fx->ho_sid_bw_fx, 0x1L); + hTdCngDec->ho_sid_bw_fx = L_shl(L_and(hTdCngDec->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); + hTdCngDec->ho_sid_bw_fx = L_or(hTdCngDec->ho_sid_bw_fx, 0x1L); } - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); - if( GT_16(st_fx->ho_hist_size_fx,HO_HIST_SIZE)) + hTdCngDec->ho_hist_size_fx = add(hTdCngDec->ho_hist_size_fx,1); + if( GT_16(hTdCngDec->ho_hist_size_fx,HO_HIST_SIZE)) { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; + hTdCngDec->ho_hist_size_fx = HO_HIST_SIZE; move16(); } } @@ -650,9 +635,9 @@ void CNG_dec_fx( st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; move16(); - if( NE_32(core_brate,SID_1k75)) + if( NE_32(st_fx->core_brate_fx,SID_1k75)) { - st_fx->num_ho_fx = m; + hTdCngDec->num_ho_fx = m; move16(); } } @@ -660,9 +645,9 @@ void CNG_dec_fx( /* Update the frame length memory */ st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; - if( NE_32(core_brate,SID_1k75)) + if( NE_32(st_fx->core_brate_fx,SID_1k75)) { - st_fx->num_ho_fx = m; + hTdCngDec->num_ho_fx = m; move16(); } @@ -675,7 +660,7 @@ void CNG_dec_fx( E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); } - tmp_loop = shr(L_frame,6); + tmp_loop = shr(st_fx->L_frame_fx,6); FOR( i=1; ilast_vad_fx = 0; move16(); - st_fx->burst_cnt_fx = 0; + st_fx->hTdCngDec->burst_cnt_fx = 0; move16(); } ELSE { st_fx->last_vad_fx = 1; move16(); - st_fx->burst_cnt_fx = add(st_fx->burst_cnt_fx, 1); - if ( GT_16(st_fx->burst_cnt_fx, 10)) + st_fx->hTdCngDec->burst_cnt_fx = add(st_fx->hTdCngDec->burst_cnt_fx, 1); + if ( GT_16(st_fx->hTdCngDec->burst_cnt_fx, 10)) { - st_fx->burst_cnt_fx = 0; + st_fx->hTdCngDec->burst_cnt_fx = 0; move16(); } } @@ -761,7 +746,8 @@ static void shb_CNG_decod_fx( Word16 tmp2; Word16 allow_cn_step_fx=0; Word16 q; - + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; IF ( st_fx->bfi_fx == 0 ) { @@ -775,10 +761,20 @@ static void shb_CNG_decod_fx( idx_ener_fx = -15; move16(); } - - /* de-quantization of SHB CNG parameters */ - L_tmp = L_mult(idx_ener_fx, 27400); /*Q14*/ - st_fx->last_shb_cng_ener_fx = extract_l(L_shr(L_sub(L_tmp, 295924), 6)); /*Q8 */ + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + /* de-quantization of SHB CNG parameters */ + L_tmp = L_mult(idx_ener_fx, 27400); /*Q14 */ + st_fx->last_shb_cng_ener_fx = extract_l(L_shr(L_sub(L_tmp, 295924), 6)); /*Q8 */ + } + ELSE + { +#ifdef IVAS_CODE_CNG + /* de-quantization of SHB CNG parameters */ To be verified + L_tmp = L_mult(idx_ener_fx, 17615); /*Q13*/ + st_fx->last_shb_cng_ener_fx = extract_l(L_shr(L_sub(L_tmp, 147962), 5)); /*Q8 */ +#endif + } } } @@ -796,18 +792,21 @@ static void shb_CNG_decod_fx( move16(); /*Q14*/ } - if ( LT_16(st_fx->shb_dtx_count_fx, 1000)) + IF (NE_16(st_fx->element_mode, IVAS_CPE_DFT)) { - st_fx->shb_dtx_count_fx = add(st_fx->shb_dtx_count_fx, 1); + if (LT_16(st_fx->shb_dtx_count_fx, 1000)) + { + st_fx->shb_dtx_count_fx = add(st_fx->shb_dtx_count_fx, 1); + } } - E_LPC_lsf_lsp_conversion(shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER); /*Q14*/ E_LPC_f_lsp_a_conversion(tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER); Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER+1, sub(norm_s(shb_lpcCNG_fx[0]),2) ); /* Q12 */ - - +#ifdef IVAS_CODE_CNG + //mvr2r(shb_lpcCNG, st->hTdCngDec->shb_lpcCNG, LPC_SHB_ORDER + 1); +#endif /* SHB energy estimation */ wb_ener_fx = L_deposit_l(1);/*Q1 */ FOR ( i=0; istate_lpc_syn_fx, 1 ); + Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, hBWE_TD->state_lpc_syn_fx, 1 ); /* synthesis signal gain shaping */ @@ -897,7 +896,7 @@ static void shb_CNG_decod_fx( st_fx->trans_cnt_fx = 0; move16(); test(); - if ( GT_16(st_fx->burst_cnt_fx, 3)&&NE_16(st_fx->last_core_fx,HQ_CORE)) + if ( GT_16(st_fx->hTdCngDec->burst_cnt_fx, 3)&&NE_16(st_fx->last_core_fx,HQ_CORE)) { st_fx->trans_cnt_fx = 5; move16(); @@ -946,6 +945,9 @@ static void shb_CNG_decod_fx( L_tmp = L_deposit_h(tmp); /*Q31 */ tmp = -(q+exp1)+(5+exp); L_gain_fx = Isqrt_lc(L_tmp, &tmp); /*Q31-Qtmp */ +#ifdef IVAS_CODE_CNG + st->hTdCngDec->shb_cng_gain = ener_fx; +#endif FOR ( i=0; igenSHBsynth_Hilbert_Mem_fx[i] = L_shr(st_fx->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2); move32(); } FOR(i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr(st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2); } } - GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame_fx, &(st_fx->syn_dm_phase_fx) ); + GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame_fx, &(hBWE_TD->syn_dm_phase_fx) ); IF ( EQ_32(st_fx->output_Fs_fx,48000)) { interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st_fx->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } +#ifdef IVAS_CODE_CNG + ResetSHBbuffer_Dec(st->hBWE_TD, st->extl); +#else ResetSHBbuffer_Dec_fx( st_fx ); +#endif return; } +/*-------------------------------------------------------------------* + * td_cng_dec_init() + * + * + *-------------------------------------------------------------------*/ + +void td_cng_dec_init( + DEC_CORE_HANDLE st /* i/o: decoder state structure */ +) +{ + TD_CNG_DEC_HANDLE hTdCngDec; + + hTdCngDec = st->hTdCngDec; + + hTdCngDec->cng_seed_fx = RANDOM_INITSEED; move16(); + hTdCngDec->cng_ener_seed_fx = RANDOM_INITSEED; move16(); + hTdCngDec->cng_ener_seed1_fx = RANDOM_INITSEED; move16(); + hTdCngDec->old_enr_index_fx = -1; move16(); + hTdCngDec->Enew_fx = L_deposit_l(0); + hTdCngDec->last_allow_cn_step_fx = 0; move16(); +#ifdef IVAS_CODE_CNG + // mvr2r(st->lsp_old, st->lspCNG, M); +// hTdCngDec->shb_cng_ener = -6.02f; + IF (st->element_mode != EVS_MONO) + { + //set_f(hTdCngDec->shb_lpcCNG, 0.0f, LPC_SHB_ORDER + 1); + //hTdCngDec->shb_lpcCNG[0] = 1.0f; + //hTdCngDec->shb_cng_gain = -82.0; /* a dB value approximately corresponding to shb index 0(used as index -15) */ + } + //hTdCngDec->wb_cng_ener = -6.02f; + //hTdCngDec->last_wb_cng_ener = -6.02f; + //hTdCngDec->last_shb_cng_ener = -6.02f; + //hTdCngDec->swb_cng_seed = RANDOM_INITSEED; +#endif + hTdCngDec->ho_hist_ptr_fx = -1; move16(); + hTdCngDec->ho_sid_bw_fx = L_deposit_l(0); + set16_fx(hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE* M); + set32_fx(hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE); + set32_fx(hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE* NUM_ENV_CNG); + hTdCngDec->ho_hist_size_fx = 0; move16(); + hTdCngDec->act_cnt_fx = 0; move16(); + hTdCngDec->ho_circ_ptr_fx = -1; move16(); + set16_fx(hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE* M); + set32_fx(hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE); + set32_fx(hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE* NUM_ENV_CNG); + hTdCngDec->ho_circ_size_fx = 0; move16(); + + set16_fx(hTdCngDec->ho_16k_lsp_fx, 0, HO_HIST_SIZE); + hTdCngDec->act_cnt2_fx = 0; move16(); + hTdCngDec->num_ho_fx = 0; move16(); + hTdCngDec->last_cng_type_fx = -1; move16(); + set32_fx(hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG); + set16_fx(hTdCngDec->exc_mem_fx, 0, 24); + set16_fx(hTdCngDec->exc_mem1_fx, 0, 30); + set32_fx(hTdCngDec->old_env_fx, 0, NUM_ENV_CNG); +#ifdef IVAS_CODE_CNG + //st->CNG_mode = -1; + //for (i = 0; i < LPC_SHB_ORDER; i++) + //{ + // if (st->element_mode != EVS_MONO) + // { + // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1)); + // } + // else + // { + // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)i) / ((float)LPC_SHB_ORDER); + // } + // hTdCngDec->lsp_shb_prev_prev[i] = hTdCngDec->lsp_shb_prev[i]; + //} + + //hTdCngDec->shb_dtx_count = 0; + //hTdCngDec->trans_cnt = 0; + //hTdCngDec->last_shb_ener = 0.001f; + //set_f(hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN); +#endif + hTdCngDec->burst_cnt_fx = 0; move16(); + return; +} diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index 62c9bd9..c8bc615 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -3,14 +3,13 @@ ====================================================================================*/ #include -#include +#include #include #include +#include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" -#include "options.h" -#include "stl.h" #include "cnst_fx.h" /* for MIN_CNG_LEV */ /*-----------------------------------------------------------------------* @@ -19,45 +18,95 @@ * Initialization of state variables *-----------------------------------------------------------------------*/ -void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_mode ) +void open_decoder_LPD( + Decoder_State_fx *st, + const Word32 total_brate, +#ifdef NEW_IVAS_OPEN_DEC + const Word32 last_total_brate, +#endif + const Word16 bwidth +#ifdef NEW_IVAS_OPEN_DEC + ,const Word16 is_mct, /* i : MCT mode flag */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + const Word16 last_element_mode, +#endif + const Word16 is_init /* i : indicate call from init_decoder() to avoid double TC initialization */ +#endif +) { Word16 i; Word16 mem_syn_r_size_new; Word16 mem_syn_r_size_old; Word16 fscaleFB; + BPF_DEC_HANDLE hBPF; + TD_BWE_DEC_HANDLE hBWE_TD; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + HQ_DEC_HANDLE hHQ_core; + TCX_DEC_HANDLE hTcxDec; + + hBPF = st->hBPF; + hBWE_TD = st->hBWE_TD; + hHQ_core = st->hHQ_core; + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; +#ifndef NEW_IVAS_OPEN_DEC + st->total_brate_fx = total_brate; +#endif + IF (NE_16(st->codec_mode, MODE1)) /*already updated in MODE1*/ + { + st->fscale_old = st->fscale; + } + st->sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate_fx, bwidth, st->flag_ACELP16k, st->rf_flag , st->is_ism_format ); - st->total_brate_fx = bit_rate; - st->fscale_old = st->fscale; - st->sr_core = getCoreSamplerateMode2(st->total_brate_fx, bandwidth_mode, st->rf_flag); st->fscale = sr2fscale(st->sr_core); fscaleFB = sr2fscale(st->output_Fs_fx); /* initializing variables for frame lengths etc. right in the beginning */ st->L_frame_fx = extract_l(Mult_32_16(st->sr_core , 0x0290)); - st->L_frameTCX = extract_l(Mult_32_16(st->output_Fs_fx , 0x0290)); - +#ifndef NEW_IVAS_OPEN_DEC + hTcxDec->L_frameTCX = extract_l(Mult_32_16(st->output_Fs_fx , 0x0290)); +#endif IF (st->ini_frame_fx == 0) { st->last_L_frame_fx = st->L_frame_past = st->L_frame_fx; move16(); move16(); - st->L_frameTCX_past = st->L_frameTCX; +#ifndef NEW_IVAS_OPEN_DEC + st->L_frameTCX_past = hTcxDec->L_frameTCX; +#endif move16(); } - - st->tcxonly = getTcxonly(st->total_brate_fx); +#ifdef NEW_IVAS_OPEN_DEC + IF(st->hTcxDec != NULL) + { + hTcxDec->L_frameTCX = extract_l(Mult_32_16(st->output_Fs_fx, 0x0290)); + IF(st->ini_frame_fx == 0) + { + st->L_frameTCX_past = st->hTcxDec->L_frameTCX; + } + } +#endif + st->tcxonly = getTcxonly( +#ifdef IVAS_CODE_SWITCHING + st->element_mode, +#endif + st->total_brate_fx +#ifdef IVAS_CODE_SWITCHING + ,is_mct +#endif + /*, st->is_ism_format Needed in the last version of float IVAS */ + ); move16(); /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ st->nb_subfr = NB_SUBFR; move16(); - test(); - test(); - test(); - test(); - if ( (EQ_16(st->L_frame_fx,L_FRAME16k)&&LE_32(st->total_brate_fx,32000))|| + test();test();test();test(); + + if ( (EQ_16(st->element_mode, EVS_MONO) && EQ_16(st->L_frame_fx,L_FRAME16k) && LE_32(st->total_brate_fx,32000)) || + (GT_16(st->element_mode, EVS_MONO) && EQ_16(st->L_frame_fx, L_FRAME16k) && LE_32(total_brate, MAX_ACELP_BRATE)) || (st->tcxonly != 0 && (EQ_32(st->sr_core,32000) || EQ_32(st->sr_core,16000)) ) ) { @@ -72,31 +121,52 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m assert(st->fscale == 2 * st->L_frame_fx); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ assert(st->bits_frame == (int)( (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate_fx/100.0f + 0.49f )); - st->TcxBandwidth = getTcxBandwidth(bandwidth_mode); + st->TcxBandwidth = getTcxBandwidth(bwidth); st->narrowBand = 0; move16(); - if (EQ_16(bandwidth_mode, NB)) + if (EQ_16(bwidth, NB)) { st->narrowBand = 1; move16(); } - st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + IF (EQ_16(st->element_mode, IVAS_CPE_MDCT)) + { + st->pit_res_max = initPitchLagParameters(INT_FS_12k8, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + IF(hTcxDec != NULL) + { + //st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + //hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800); + //hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800); + PMT("Fixed point to be verified here") + i = mult_r(hTcxDec->L_frameTCX, getInvFrameLen(L_FRAME)); + hTcxDec->pit_max_TCX = extract_l(L_shr(L_mult(st->pit_max, i), 7)); + hTcxDec->pit_min_TCX = extract_l(L_shr(L_mult(st->pit_min, i), 7)); + + } + } + ELSE + { + st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + IF (hTcxDec != NULL) + { + i = mult_r(hTcxDec->L_frameTCX, getInvFrameLen(st->L_frame_fx)); + hTcxDec->pit_max_TCX = extract_l(L_shr(L_mult(st->pit_max, i), 7)); + hTcxDec->pit_min_TCX = extract_l(L_shr(L_mult(st->pit_min, i), 7)); + } + } IF ( st->ini_frame_fx == 0) { st->pit_res_max_past = st->pit_res_max; } - i = mult_r(st->L_frameTCX, getInvFrameLen(st->L_frame_fx)); - st->pit_max_TCX = extract_l(L_shr(L_mult(st->pit_max, i), 7)); - st->pit_min_TCX = extract_l(L_shr(L_mult(st->pit_min, i), 7)); /*Preemphasis param*/ st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF ( LT_16(st->fscale, (16000*FSCALE_DENOM)/12800)) + IF ( LT_16(st->fscale, (16000*FSCALE_DENOM)/ INT_FS_12k8)) { st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); } - ELSE if ( LT_16(st->fscale, (24000*FSCALE_DENOM)/12800)) + ELSE if ( LT_16(st->fscale, (24000*FSCALE_DENOM)/ INT_FS_12k8)) { st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); } @@ -105,7 +175,9 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m move16(); st->inv_gamma = GAMMA1_INV; move16(); - IF ( EQ_32(st->sr_core, 16000)) + IF ( EQ_32(st->sr_core, INT_FS_16k) || + (GT_32(st->sr_core, INT_FS_16k) && EQ_16(st->element_mode, IVAS_CPE_MDCT) ) + ) { st->gamma = GAMMA16k; move16(); @@ -117,7 +189,7 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m st-> lpcQuantization = 0; move16(); test(); - if( st->tcxonly == 0 && LE_32(st->sr_core, 16000)) + if( st->tcxonly == 0 && LE_32(st->sr_core, INT_FS_16k)) { st->lpcQuantization = 1; } @@ -132,59 +204,95 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m /* Initialize TBE */ st->prev_coder_type_fx = GENERIC; - set16_fx( st->prev_lsf_diff_fx,16384,LPC_SHB_ORDER-2 ); - st->prev_tilt_para_fx = 0; - set16_fx( st->cur_sub_Aq_fx, 0, M+1 ); + if (st->hBWE_TD != NULL) + { + set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + hBWE_TD->prev_tilt_para_fx = 0; + set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); + } /*TCX config*/ - st->tcx_cfg.preemph_fac = st->preemph_fac; +#ifndef NEW_IVAS_OPEN_DEC + st->hTcxCfg->preemph_fac = st->preemph_fac; move16(); - st->tcx_cfg.tcx_mdct_window_length_old = st->tcx_cfg.tcx_mdct_window_length; + st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length; move16(); - - init_TCX_config( &st->tcx_cfg, st->L_frame_fx, st->fscale, st->L_frameTCX, fscaleFB ); - - IF (st->ini_frame_fx == 0) + init_TCX_config_dec( st->hTcxCfg, st->L_frame_fx, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY should be rename to init_TCX_config + IF(st->ini_frame_fx == 0) { - st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); move16(); } /* TCX Offset */ - st->tcx_cfg.tcx_offset = shr(st->tcx_cfg.tcx_mdct_window_delay, 1); - st->tcx_cfg.tcx_offsetFB = shr(st->tcx_cfg.tcx_mdct_window_delayFB, 1); + st->hTcxCfg->tcx_offset = shr(st->hTcxCfg->tcx_mdct_window_delay, 1); + st->hTcxCfg->tcx_offsetFB = shr(st->hTcxCfg->tcx_mdct_window_delayFB, 1); /* Initialize FAC */ - st->tcx_cfg.lfacNext = sub(st->tcx_cfg.tcx_offset,shr(st->L_frame_fx,2)); - st->tcx_cfg.lfacNextFB = sub(st->tcx_cfg.tcx_offsetFB,shr(st->L_frameTCX,2)); + st->hTcxCfg->lfacNext = sub(st->hTcxCfg->tcx_offset, shr(st->L_frame_fx, 2)); + st->hTcxCfg->lfacNextFB = sub(st->hTcxCfg->tcx_offsetFB, shr(hTcxDec->L_frameTCX, 2)); /* set number of coded lines */ - st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(st->bwidth_fx); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(st->bwidth_fx); /* TNS in TCX */ - st->tcx_cfg.pCurrentTnsConfig = NULL; - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate_fx, st->igf); + st->hTcxCfg->pCurrentTnsConfig = NULL; + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(st->total_brate_fx, st->igf, st->element_mode); + + IF(st->hTcxCfg->fIsTNSAllowed != 0) + { + InitTnsConfigs(st->bwidth_fx, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate_fx, st->element_mode, 0/*is_mct*/); - IF (st->tcx_cfg.fIsTNSAllowed != 0) + } + /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ + if (st->tcxonly == 0) { - InitTnsConfigs(bwMode2fs[st->bwidth_fx], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFDec.infoIGFStopFreq, st->total_brate_fx); + assert(0 == (st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0)); } - resetTecDec_Fx( &(st->tecDec_fx) ); + resetTecDec_Fx(&(st->tecDec_fx)); - /* Initialize decoder delay */ + +#else + if (st->hIGFDec != NULL) + { + PMT("To be done") + //if (!is_init || st->element_mode != IVAS_CPE_MDCT) + //{ + // init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); + //} + //else + //{ + // st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + // st->hTcxCfg->last_aldo = 1; + //} + } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if ( st->tcxonly==0 ) + if (st->tcxonly == 0) { - assert(0 == (st->tcx_cfg.lfacNext>0 ? st->tcx_cfg.lfacNext : 0) ); + assert(0 == (st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0)); } + //if (st->tecDec_fx != NULL) + { + resetTecDec_Fx(&(st->tecDec_fx)); + } + +#endif + + + + /* Initialize decoder delay */ - st->flag_cna = 0; - move16(); + IF (NE_16(st->element_mode, IVAS_SCE)) + { + st->flag_cna = 0; + move16(); + } IF( st->ini_frame_fx == 0 ) { + st->flag_cna = 0; st->last_flag_cna = 0; move16(); } @@ -198,17 +306,19 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m st->rate_switching_reset = 0; move16(); - set16_fx(st->old_syn_Overl, 0, L_FRAME32k/2); - - set16_fx(st->syn_Overl_TDAC, 0, L_FRAME32k/2); - set16_fx(st->syn_OverlFB, 0, L_FRAME_MAX/2); - set16_fx(st->syn_Overl_TDACFB, 0, L_FRAME_MAX/2); + IF(hTcxDec != NULL) + { + set16_fx(hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2); - set16_fx(st->syn_Overl, 0, L_FRAME32k/2); + set16_fx(hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2); + set16_fx(hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2); + set16_fx(hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2); - set16_fx(st->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); - set16_fx( st->synth_history_fx, 0, Lprot48k + L_FRAME_MAX); + set16_fx(hTcxDec->syn_Overl, 0, L_FRAME32k / 2); + set16_fx(hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); + set16_fx(hTcxDec->synth_history_fx, 0, Lprot48k + L_FRAME_MAX); + } set16_fx(st->syn, 0, M+1); set16_fx(st->mem_syn_r, 0, L_SYN_MEM); @@ -222,9 +332,9 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m { /* Reset old_synth in case of core sampling rate switching and codec switching*/ test(); - IF( (NE_16(st->L_frame_fx, st->last_L_frame_fx))||(EQ_16(st->last_codec_mode,MODE1))) + IF(st->hTcxDec != NULL && ((NE_16(st->L_frame_fx, st->last_L_frame_fx))||(EQ_16(st->last_codec_mode,MODE1)))) { - set16_fx(st->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); + set16_fx(hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); } /*Size of LPC syn memory*/ @@ -240,7 +350,7 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m { /*LPC quant. mem*/ set16_fx(st->mem_MA_fx, 0, M); - IF( EQ_32(st->sr_core,16000)) + IF( EQ_32(st->sr_core, INT_FS_16k)) { Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); } @@ -251,7 +361,7 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m } /*Codec switching*/ - IF( EQ_16(st->last_codec_mode,MODE1)) + IF( EQ_16(st->last_codec_mode,MODE1) && EQ_16(st->element_mode, EVS_MONO)) { Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); @@ -266,52 +376,57 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m } /*Codec switching from ACELP-A */ - test(); - IF( EQ_16(st->last_codec_mode, MODE1)&&EQ_16(st->last_core_fx,ACELP_CORE)) + test(); test(); test(); test(); + IF( (NE_16(st->element_mode, IVAS_CPE_DFT) || (EQ_16(st->element_mode, IVAS_CPE_DFT) && st->prev_bfi_fx ) ) && EQ_16(st->last_codec_mode, MODE1) && EQ_16(st->last_core_fx,ACELP_CORE) ) { st->last_core_bfi = ACELP_CORE; move16(); /*PLC*/ +#ifndef NEW_IVAS_OPEN_DEC IF(st->prev_bfi_fx!=0) { PWord16 const *w; Word16 W1,W2,nz,delay_comp; - W1 = st->tcx_cfg.tcx_mdct_window_lengthFB; + W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); - W2 = shr(st->tcx_cfg.tcx_mdct_window_lengthFB,1); - w = st->tcx_cfg.tcx_mdct_windowFB; /*pointer - no need to instrument*/ + W2 = shr(st->hTcxCfg->tcx_mdct_window_lengthFB, 1); + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ nz = NS2SA_fx2(st->output_Fs_fx, N_ZERO_MDCT_NS); delay_comp = NS2SA_fx2(st->output_Fs_fx, DELAY_CLDFB_NS); /*CLDFB delay*/ - Copy(st->fer_samples_fx+delay_comp, st->syn_OverlFB, shr(st->L_frameTCX,1)); + Copy(hHQ_core->fer_samples_fx+delay_comp, hTcxDec->syn_OverlFB, shr(hTcxDec->L_frameTCX,1)); - lerp(st->fer_samples_fx+delay_comp, st->syn_Overl , shr(st->L_frame_fx,1), shr(st->L_frameTCX,1)); /*Q0: ACELP(bfi)->TCX(rect)*/ + lerp(hHQ_core->fer_samples_fx+delay_comp, hTcxDec->syn_Overl , shr(st->L_frame_fx,1), shr(hTcxDec->L_frameTCX,1)); /*Q0: ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ - st->Q_old_wtda=-1; - set16_fx(st->old_out_fx, 0, nz); - Copy_Scale_sig(st->fer_samples_fx+delay_comp, st->old_out_fx+nz,W1, st->Q_old_wtda); /*Q-1*/ + hHQ_core->Q_old_wtda=-1; + set16_fx(hHQ_core->old_out_fx, 0, nz); + Copy_Scale_sig(hHQ_core->fer_samples_fx+delay_comp, hHQ_core->old_out_fx+nz,W1, hHQ_core->Q_old_wtda); /*Q-1*/ FOR (i=0; i < W2; i++) { - st->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re),st->old_out_fx[i+nz])); + hHQ_core->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re), hHQ_core->old_out_fx[i+nz])); } FOR ( ; i < W1; i++) { - st->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im),st->old_out_fx[i+nz])); + hHQ_core->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im), hHQ_core->old_out_fx[i+nz])); } - set16_fx(&st->old_out_fx[W1+nz], 0, nz); + set16_fx(&hHQ_core->old_out_fx[W1+nz], 0, nz); - lerp(st->old_out_fx , st->old_out_LB_fx , st->L_frame_fx , st->L_frameTCX); + lerp(hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx,st->L_frame_fx , hTcxDec->L_frameTCX); - Copy(st->old_out_fx +nz, st->syn_Overl_TDACFB, shr(st->L_frameTCX,1)); + Copy(hHQ_core->old_out_fx +nz, hTcxDec->syn_Overl_TDACFB, shr(hTcxDec->L_frameTCX,1)); nz = NS2SA_fx2(st->sr_core, N_ZERO_MDCT_NS); - Copy(st->old_out_LB_fx+nz, st->syn_Overl_TDAC , shr(st->L_frame_fx,1)); - st->Q_old_wtda_LB = st->Q_old_wtda; + Copy(hHQ_core->old_out_LB_fx+nz, hTcxDec->syn_Overl_TDAC , shr(st->L_frame_fx,1)); + hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; } +#else + PMT("acelp_plc_mdct_transition is missing") + //acelp_plc_mdct_transition(st); +#endif } test(); @@ -327,7 +442,7 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m ( GT_16(st->last_core_fx, ACELP_CORE) && GT_16(st->core_fx, ACELP_CORE) ) || st->prev_bfi_fx ) ) { - lerp(st->old_out_LB_fx, st->old_out_LB_fx, st->L_frame_fx, st->last_L_frame_fx); + lerp(hHQ_core->old_out_LB_fx, hHQ_core->old_out_LB_fx, st->L_frame_fx, st->last_L_frame_fx); } /* Rate switching */ @@ -348,28 +463,47 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m set16_fx(st->mem_syn2_fx, 0, M); /*OLA -> zero */ - set16_fx(st->old_syn_Overl, 0, L_FRAME32k/2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(st->syn_Overl_TDAC, 0, L_FRAME32k/2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(st->syn_Overl_TDACFB, 0, L_FRAME_MAX/2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(st->syn_Overl, 0, L_FRAME32k/2); /*HQ-CORE(bfi)->TCX don't need it*/ - - Copy_Scale_sig(st->old_out_fx+NS2SA(st->output_Fs_fx, N_ZERO_MDCT_NS), st->syn_OverlFB, st->tcx_cfg.tcx_mdct_window_lengthFB, negate(add(st->Q_old_wtda, TCX_IMDCT_HEADROOM))); + if (st->hTcxDec != NULL) + { + set16_fx(hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx(hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx(hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx(hTcxDec->syn_Overl, 0, L_FRAME32k / 2); /*HQ-CORE(bfi)->TCX don't need it*/ + PMT("to be moved to reset_tcx_overl_buf") + } + if (st->hTcxCfg != NULL) + { + Copy_Scale_sig(hHQ_core->old_out_fx + NS2SA(st->output_Fs_fx, N_ZERO_MDCT_NS), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate(add(hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM))); - move16(); - move16(); - st->tcx_cfg.last_aldo=1; /*It was previously ALDO*/ - st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + move16(); + move16(); + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + } /*OLA for MDCT-LB always reset in codec switching cases*/ - set16_fx( st->old_out_LB_fx, 0, st->L_frame_fx ); + if (st->hHQ_core != NULL) + { + set16_fx(hHQ_core->old_out_LB_fx, 0, st->L_frame_fx); + } move16(); st->last_core_bfi = TCX_20_CORE; - st->pfstat.on=0; + if (st->hPFstat != NULL) + { + st->hPFstat->on = 0; + } move16(); /* reset CLDFB memories */ cldfb_reset_memory( st->cldfbAna_fx ); cldfb_reset_memory( st->cldfbBPF_fx ); cldfb_reset_memory( st->cldfbSyn_fx ); +#ifndef NEW_IVAS_OPEN_DEC + PMT("cldfbSynHB is missing ") + //if (st->cldfbSynHB != NULL) + //{ + // cldfb_reset_memory(st->cldfbSynHB); + //} +#endif } ELSE IF( (NE_16(st->L_frame_fx,st->last_L_frame_fx))&&(LE_16(st->L_frame_fx,L_FRAME16k))&&(LE_16(st->last_L_frame_fx,L_FRAME16k))) /* Rate switching between 12.8 and 16 kHz*/ { @@ -431,15 +565,18 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m st->rate_switching_reset=1; move16(); } - - st->old_synth_len = shl(st->L_frame_fx, 1); - st->old_synth_lenFB = shl(st->L_frameTCX, 1); - + IF (st->hTcxDec != NULL) + { + hTcxDec->old_synth_len = shl(st->L_frame_fx, 1); + hTcxDec->old_synth_lenFB = shl(hTcxDec->L_frameTCX, 1); + } /* bass pf reset */ st->bpf_gain_param = 0; move16(); - set16_fx( st->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); - + if (st->hBPF != NULL) + { + set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); + } /* Formant postfilter */ IF ( st->ini_frame_fx==0 ) { @@ -449,24 +586,24 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m { IF (st->tcxonly==0) { - IF ( st->pfstat.on!=0 ) + IF ( st->hPFstat->on!=0 ) { - lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { - set16_fx( st->pfstat.mem_stp, 0,L_SYN_MEM ); - set16_fx( st->pfstat.mem_pf_in, 0,L_SYN_MEM ); - st->pfstat.reset = 1; - st->pfstat.gain_prec = 16384; + set16_fx( st->hPFstat->mem_stp, 0,L_SYN_MEM ); + set16_fx( st->hPFstat->mem_pf_in, 0,L_SYN_MEM ); + st->hPFstat->reset = 1; + st->hPFstat->gain_prec = 16384; move16(); } } - ELSE IF ( st->pfstat.on!=0 ) + ELSE IF ( st->hPFstat->on!=0 ) { - lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->hPFstat->mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE @@ -475,24 +612,37 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m /*reset post-filter except for Narrowband*/ IF ( NE_32(st->output_Fs_fx,8000)) { - st->pfstat.reset = 1; - if(st->pfstat.on!=0) + if (st->hPFstat != NULL) { - st->pfstat.reset = 0; - Scale_sig(st->pfstat.mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ - Scale_sig(st->pfstat.mem_stp, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ - lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + st->hPFstat->reset = 1; + if (st->hPFstat->on != 0) + { + st->hPFstat->reset = 0; + Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ + Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ + lerp(st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + lerp(st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + } } } - ELSE{ - Scale_sig(st->pfstat.mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ - Scale_sig(st->pfstat.mem_res2, DECMEM_RES2, negate(st->Q_syn)); /* NB post_filter mem */ - Scale_sig(st->pfstat.mem_stp, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ + ELSE + { + if (st->hPFstat != NULL) + { + Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ + Scale_sig(st->hPFstat->mem_res2, DECMEM_RES2, negate(st->Q_syn)); /* NB post_filter mem */ + Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ + } /*feed last value old_synth as it is used for pre-emphasis mem*/ - st->old_synth[st->old_synth_len-1]=st->syn[M]; + if (st->hTcxDec != NULL) + { + hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; + } move16(); - st->pst_old_syn_fx[NBPSF_PIT_MAX-1]=st->syn[M]; + if (st->hBPF != NULL) + { + hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; + } move16(); } } @@ -506,7 +656,7 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m set16_fx(st->lsf_cng, 0, M); } - st->seed_tcx_plc = 21845; + st->seed_tcx_plc = RANDOM_INITSEED; move16(); st->past_gpit = 0; move16(); @@ -536,8 +686,10 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m move16(); st->last_concealed_gain_syn_deemph_e = 1; move16(); - st->conceal_eof_gain = 32768/2;/*Q14*/ move16(); - + if (hTcxDec != NULL) + { + hTcxDec->conceal_eof_gain = 32768 / 2;/*Q14*/ move16(); + } } /* Post processing */ @@ -575,6 +727,8 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m test(); IF( EQ_16(st->core_fx,ACELP_CORE)&&EQ_16(st->last_core_fx,HQ_CORE)) { + /*_DIFF_FLOAT_FIX_*/ + PMT("floating point is using L_frameTCX instead of output_frame, is it ok?") frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); } } @@ -588,19 +742,35 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m st->prev_widow_left_rect = 0; move16(); + if (st->hTcxDec != NULL) + { +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + /* Todo: should be considered for other stereo modes as well */ + if (is_init || MCT_flag || !(st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode)) + { PMT("Fixed point to be done") + st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV; + st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; + st->hTcxDec->CurrLevelIndex_bfi = 0; + st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV; + set_f(st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); - st->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV; /*Q15*/ move16(); - st->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE-1; - move16(); - st->conCurrLevelIndex = 0; - move16(); - st->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); - set16_fx(st->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ - set16_fx(st->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); - st->conLastFrameLevel_e = 0; - st->conCngLevelBackgroundTrace_e = 0; + st->hTcxDec->cummulative_damping_tcx = 1.0f; + } +#else + hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; + move16(); + hTcxDec->conCurrLevelIndex = 0; + move16(); + hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); + set16_fx(hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ + set16_fx(hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); + hTcxDec->conLastFrameLevel_e = 0; + hTcxDec->conCngLevelBackgroundTrace_e = 0; - st->cummulative_damping_tcx = 32767/*1.0f Q15*/; + hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; +#endif + } move16(); st->cummulative_damping = 32767/*1.0f Q15*/; move16(); @@ -617,8 +787,9 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m st->old_fpitch = L_deposit_h(st->pit_min); - st->old_fpitchFB = L_deposit_h(st->pit_min_TCX); - +#ifndef NEW_IVAS_OPEN_DEC + st->old_fpitchFB = L_deposit_h(hTcxDec->pit_min_TCX); +#endif st->rate_switching_init = 1; move16(); @@ -634,52 +805,65 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m st->voice_fac = -1; /* purely unvoiced */ move16(); /* TCX-LTP */ - st->tcxltp = getTcxLtp(st->sr_core); + if (hTcxLtpDec != NULL) + { + hTcxLtpDec->tcxltp = getTcxLtp(st->sr_core); + } move16(); test(); - IF ( st->ini_frame_fx == 0 || EQ_16(st->last_codec_mode,MODE1)) + IF (hTcxLtpDec != NULL && (st->ini_frame_fx == 0 || (EQ_16(st->last_codec_mode,MODE1) && EQ_16(st->element_mode, EVS_MONO)))) { - st->tcxltp_pitch_int = st->pit_max; + PMT("TO be verify, update seems to differ from float") + hTcxLtpDec->tcxltp_pitch_int = st->pit_max; move16(); - st->tcxltp_pitch_fr = 0; + hTcxLtpDec->tcxltp_pitch_fr = 0; move16(); - st->tcxltp_last_gain_unmodified = 0; + if (hTcxDec != NULL) + { + hTcxDec->tcxltp_last_gain_unmodified = 0; + } move16(); IF ( st->ini_frame_fx == 0) { - set16_fx( st->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); - set16_fx( st->tcxltp_mem_out, 0, L_FRAME48k ); - st->tcxltp_pitch_int_post_prev = 0; + set16_fx(hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); + set16_fx(hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); + hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; move16(); - st->tcxltp_pitch_fr_post_prev = 0; + hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; move16(); - st->tcxltp_gain_post_prev = 0; + hTcxLtpDec->tcxltp_gain_post_prev = 0; move16(); - st->tcxltp_filt_idx_prev = -1; + hTcxLtpDec->tcxltp_filt_idx_prev = -1; move16(); } } /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */ - st->lp_error_ener = Mpy_32_16_1(L_shl(st->pst_lp_ener_fx, 8), 0x2a86); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ + if (st->hBPF != NULL) + { + + st->lp_error_ener = Mpy_32_16_1(L_shl(hBPF->pst_lp_ener_fx, 8), 0x2a86); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ + } + else + { + st->lp_error_ener = 0; + } st->mem_error = L_deposit_l(0); - st->tcx_cfg.ctx_hm = getCtxHm (st->total_brate_fx, st->rf_flag); + st->hTcxCfg->ctx_hm = getCtxHm (st->element_mode, total_brate, st->rf_flag); st->last_ctx_hm_enabled = 0; move16(); - st->tcx_cfg.resq = getResq(st->total_brate_fx); + st->hTcxCfg->resq = getResq(total_brate); move16(); - st->tcx_cfg.sq_rounding = 12288/*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ move16(); - - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - st->total_brate_fx, - bandwidth_mode - ,st->rf_flag - ); + st->hTcxCfg->sq_rounding = 12288/*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ move16(); + if (hTcxDec != NULL) + { + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode); - st->envWeighted = 0; + hTcxDec->envWeighted = 0; + } move16(); st->p_bpf_noise_buf = NULL; @@ -692,8 +876,8 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m move16(); test(); test(); - if ( EQ_16(bandwidth_mode, SWB)&& - (EQ_32(st->total_brate_fx, ACELP_16k40) || EQ_32(st->total_brate_fx, ACELP_24k40)) ) + if ( EQ_16(bwidth, SWB)&& + (EQ_32(st->total_brate_fx, ACELP_16k40) || EQ_32(st->total_brate_fx, ACELP_24k40)) && EQ_16(st->element_mode, EVS_MONO)) { st->tec_tfa = 1; move16(); @@ -719,7 +903,7 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m st->enablePlcWaveadjust = 0; move16(); - IF(GE_32(st->total_brate_fx, 48000)) + IF(st->hTcxDec != NULL && GE_32(st->total_brate_fx, 48000) && EQ_16(st->element_mode, EVS_MONO)) { st->enablePlcWaveadjust = 1; move16(); @@ -728,59 +912,74 @@ void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_m test(); IF (st->ini_frame_fx == 0 || LT_32(st->last_total_brate_fx, HQ_48k)||EQ_16(st->last_codec_mode,MODE1)||st->force_lpd_reset) { - concealment_init_x( st->L_frameTCX, &st->plcInfo ); + concealment_init_x(hTcxDec->L_frameTCX, &st->plcInfo ); } } /* PLC: [TCX: Tonal Concealment] */ - st->tonalMDCTconceal.nScaleFactors = 0; - move16(); - st->tonalMDCTconceal.nSamples = 0; - move16(); - st->tonalMDCTconceal.lastPcmOut = 0x0; - move16(); - st->tonalMDCTconceal.lastBlockData.tonalConcealmentActive = 0; - move16(); - st->tonalMDCTconceal.lastBlockData.nSamples = 0; - move16(); - - TonalMDCTConceal_Init(&st->tonalMDCTconceal, - st->L_frameTCX, - st->L_frame_fx, - FDNS_NPTS, - &(st->tcx_cfg) - ); + PMT("handle to tonalMDCTconceal is missing") +//#ifdef ADD_IVAS_HTONALMDCTCONC + if (/*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !(GT_16(st->element_mode, EVS_MONO) && NE_16(st->ini_frame_fx,0) && EQ_16(st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX))) + { + st->tonalMDCTconceal.nScaleFactors = 0; + move16(); + st->tonalMDCTconceal.nSamples = 0; + move16(); + st->tonalMDCTconceal.lastPcmOut = 0x0; + move16(); + st->tonalMDCTconceal.lastBlockData.tonalConcealmentActive = 0; + move16(); + st->tonalMDCTconceal.lastBlockData.nSamples = 0; + move16(); + TonalMDCTConceal_Init(&st->tonalMDCTconceal, hTcxDec->L_frameTCX, st->L_frame_fx, FDNS_NPTS, st->hTcxCfg); + } st->last_tns_active = 0; st->second_last_tns_active = 0; st->second_last_core = -1; - st->tcxltp_second_last_pitch = st->old_fpitch; - move16(); - st->tcxltp_third_last_pitch = st->old_fpitch; - move16(); - +#ifdef NEW_IVAS_OPEN_DEC + if (st->hTcxCfg != NULL && NE_16(st->element_mode, EVS_MONO ) ) + { + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf); + } +#endif + if (hTcxDec != NULL) + { + hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; + move16(); + hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; + move16(); + } move16(); st->dec_glr = 0; test(); test(); test(); - if( (EQ_32(st->total_brate_fx, 9600))||(EQ_32(st->total_brate_fx,16400))|| - (EQ_32(st->total_brate_fx, 24400))) + if ((total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) + + if( ((EQ_32(st->total_brate_fx, 9600))||(EQ_32(st->total_brate_fx,16400))|| + (EQ_32(st->total_brate_fx, 24400))) && st->element_mode == EVS_MONO) { move16(); st->dec_glr = 1; } move16(); st->dec_glr_idx = 0; - - st->enableTcxLpc = 1; - st->VAD = 0; - st->old_gaintcx_bfi = 0; - st->old_gaintcx_bfi_e = 0 ; - st->tcx_cfg.na_scale = 32767/*1.0f Q15*/; - st->tcx_hm_LtpPitchLag = -1; - st->tcxltp_gain = 0; - + if (hTcxDec != NULL) + { + hTcxDec->enableTcxLpc = 1; + st->VAD = 0; + hTcxDec->old_gaintcx_bfi = 0; + hTcxDec->old_gaintcx_bfi_e = 0; + hTcxDec->tcx_hm_LtpPitchLag = -1; + } +#ifndef NEW_IVAS_OPEN_DEC + st->hTcxCfg->na_scale = 32767/*1.0f Q15*/; +#endif + if (hTcxLtpDec != NULL) + { + hTcxLtpDec->tcxltp_gain = 0; + } return; } diff --git a/lib_dec/core_dec_reconf.c b/lib_dec/core_dec_reconf.c index 979b5d5..fd76c26 100644 --- a/lib_dec/core_dec_reconf.c +++ b/lib_dec/core_dec_reconf.c @@ -2,35 +2,47 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include +#include "options.h" #include "basop_util.h" #include "prot_fx.h" -#include "options.h" -#include "stl.h" #include "rom_com_fx.h" -void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandwidth_mode, Word32 bitrate, Word16 L_frame_old) +void reconfig_decoder_LPD( + Decoder_State_fx *st, /* i/o: decoder state structure */ + Word16 bits_frame, /* i : bit budget */ + Word16 bwidth, /* i : audio bandwidth */ + Word32 total_brate, /* i : total bitrate */ + Word16 L_frame_old /* i : frame length */ +) { + Word16 newLen; + Word16 oldLen; + Word32 lowrate_tcxlpc_max_br; + + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; move16(); st->bits_frame=bits_frame; - IF (bandwidth_mode==0) + IF (EQ_16(bwidth, NB)) { move16(); st->narrowBand = 1; } - ELSE if (bandwidth_mode>0) + ELSE if (GT_16(bwidth,NB)) { move16(); st->narrowBand = 0; } - BITS_ALLOC_init_config_acelp(bitrate, st->narrowBand, st->nb_subfr, &(st->acelp_cfg)); + BITS_ALLOC_init_config_acelp(st->total_brate_fx, st->narrowBand, st->nb_subfr, &(st->acelp_cfg)); /*Configuration of partial copy*/ st->acelp_cfg_rf.mode_index = 1; @@ -44,21 +56,27 @@ void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandw st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; - st->flag_cna = getCnaPresent(bitrate, bandwidth_mode); + IF (NE_16(st->element_mode, IVAS_SCE)) + { + st->flag_cna = (Word8)getCnaPresent(st->element_mode, st->element_brate, total_brate, bwidth); + } move16(); /* TCX-LTP */ - st->tcxltp = getTcxLtp(st->sr_core); + IF (hTcxLtpDec != NULL) + { + hTcxLtpDec->tcxltp = getTcxLtp(st->sr_core); + } move16(); + if (st->hTcxCfg != NULL) { Word16 i; /*Scale TCX for non-active frames to adjust loudness with ACELP*/ - st->tcx_cfg.na_scale=32767/*1.0f Q15*/; - + st->hTcxCfg->na_scale=32767/*1.0f Q15*/; test(); - IF ((LT_16(bandwidth_mode,SWB))&&!(st->tcxonly)) + IF ((LT_16(bwidth,SWB))&&!(st->tcxonly)) { Word16 scaleTableSize = sizeof (scaleTcxTable) / sizeof (scaleTcxTable[0]); /* is a constant */ @@ -66,16 +84,17 @@ void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandw { test(); test(); - IF ( (EQ_16(bandwidth_mode,scaleTcxTable[i].bwmode)) && - (GE_32 (bitrate,scaleTcxTable[i].bitrateFrom) ) && - (LT_32 (bitrate,scaleTcxTable[i].bitrateTo) ) + IF ( (EQ_16(bwidth,scaleTcxTable[i].bwmode)) && + (GE_32 (total_brate,scaleTcxTable[i].bitrateFrom) ) && + (LT_32 (total_brate,scaleTcxTable[i].bitrateTo) ) ) { if( st->rf_flag ) { i--; } - st->tcx_cfg.na_scale=scaleTcxTable[i].scale; + st->hTcxCfg->na_scale=scaleTcxTable[i].scale; + move16(); BREAK; } } @@ -88,22 +107,19 @@ void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandw test(); test(); test(); - IF( NE_16 (st->fscale,st->fscale_old) - && ! (st->last_codec_mode == MODE1 - && st->last_core_fx == ACELP_CORE - && st->prev_bfi_fx != 0)) + IF(st->hTcxCfg != NULL && + (NE_16 (st->fscale,st->fscale_old) && + !(EQ_16(st->element_mode, EVS_MONO) && EQ_16(st->last_codec_mode, MODE1) && + EQ_16(st->last_core_fx, ACELP_CORE) && st->prev_bfi_fx != 0))) /* no resempling is needed here when recovering from mode 1 acelp plc, since the buffers are already sampled with the correct sampling rate in open_decoder_LPD() */ { - Word16 newLen; - Word16 oldLen; - newLen = st->tcx_cfg.tcx_mdct_window_length; + newLen = st->hTcxCfg->tcx_mdct_window_length; + oldLen = st->hTcxCfg->tcx_mdct_window_length_old; move16(); - oldLen = st->tcx_cfg.tcx_mdct_window_length_old; move16(); - test(); test(); IF( (st->prev_bfi_fx && EQ_16(st->last_core_bfi,ACELP_CORE))||EQ_16(st->last_core_fx,ACELP_CORE)) @@ -111,14 +127,16 @@ void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandw newLen = shr(st->L_frame_fx,1); oldLen = shr(L_frame_old,1); } - - lerp( st->old_syn_Overl, st->old_syn_Overl, newLen, oldLen ); - lerp( st->syn_Overl, st->syn_Overl, newLen, oldLen ); - - test(); - IF( st->prev_bfi_fx && EQ_16(st->last_core_bfi,ACELP_CORE)) + IF (st->hTcxDec != NULL) { - lerp( st->syn_Overl_TDAC, st->syn_Overl_TDAC, newLen, oldLen ); + lerp(hTcxDec->old_syn_Overl, hTcxDec->old_syn_Overl, newLen, oldLen); + lerp(hTcxDec->syn_Overl, hTcxDec->syn_Overl, newLen, oldLen); + + test(); + IF(st->prev_bfi_fx && EQ_16(st->last_core_bfi, ACELP_CORE)) + { + lerp(hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDAC, newLen, oldLen); + } } } @@ -129,22 +147,19 @@ void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandw { IF (NE_16(st->L_frame_fx,st->last_L_frame_fx)) { - Word16 oldLenClasBuff; - Word16 newLenClasBuff; IF (GT_16(st->L_frame_fx,st->last_L_frame_fx)) { - oldLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->last_L_frame_fx,getInvFrameLen(st->L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); - - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + oldLen = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->last_L_frame_fx,getInvFrameLen(st->L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + newLen = L_SYN_MEM_CLAS_ESTIM; move16(); } ELSE { - oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - newLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->L_frame_fx,getInvFrameLen(st->last_L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + oldLen = L_SYN_MEM_CLAS_ESTIM; + newLen = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->L_frame_fx,getInvFrameLen(st->last_L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); } - lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + lerp( &st->mem_syn_clas_estim_fx[sub(L_SYN_MEM_CLAS_ESTIM, oldLen)], &st->mem_syn_clas_estim_fx[sub(L_SYN_MEM_CLAS_ESTIM, newLen)], newLen, oldLen); } } ELSE @@ -157,11 +172,18 @@ void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandw } test(); test(); - st->enableTcxLpc = (st->numlpc == 1) && (st->lpcQuantization == 1) && (bitrate <= LOWRATE_TCXLPC_MAX_BR || st->rf_flag); + lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR; + move16(); + IF (GT_16(st->element_mode, IVAS_SCE)) + { + lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE; + } + hTcxDec->enableTcxLpc = EQ_16(st->numlpc, 1) && EQ_16(st->lpcQuantization, 1) && (LE_32(total_brate, lowrate_tcxlpc_max_br)/*LOWRATE_TCXLPC_MAX_BR*/ || st->rf_flag); if (st->ini_frame_fx == 0) { - st->envWeighted = 0; + hTcxDec->envWeighted = 0; + move16(); } diff --git a/lib_dec/core_dec_switch.c b/lib_dec/core_dec_switch.c index 97c8e7b..e2a5f2d 100644 --- a/lib_dec/core_dec_switch.c +++ b/lib_dec/core_dec_switch.c @@ -3,23 +3,38 @@ ====================================================================================*/ #include -#include -#include +#include +#include "options.h" #include "basop_util.h" #include "prot_fx.h" -#include "stl.h" -#include "options.h" #include "rom_com_fx.h" -void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bitrate, Word16 frame_size_index - ) +void mode_switch_decoder_LPD( + Decoder_State_fx *st, /* i/o: decoder state structure */ + Word16 bwidth, /* i : audio bandwidth */ + Word32 total_brate, /* i : total bitrate */ +#ifdef IVAS_CODE_SWITCHING + const int32_t last_total_brate, /* i : last frame total bitrate */ +#endif + Word16 frame_size_index /* i : index determining the frame size*/ +#ifdef IVAS_CODE_SWITCHING + ,const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ,const int16_t last_element_mode +#endif +#endif +) { Word16 fscale, switchWB; Word32 sr_core; Word8 bSwitchFromAmrwbIO; Word16 frame_size; + TD_BWE_DEC_HANDLE hBWE_TD; + TCX_DEC_HANDLE hTcxDec; + hBWE_TD = st->hBWE_TD; + hTcxDec = st->hTcxDec; switchWB = 0; move16(); @@ -32,22 +47,21 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bit move16(); } - sr_core = getCoreSamplerateMode2(bitrate, bandwidth, st->rf_flag); + sr_core = getCoreSamplerateMode2(st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); fscale = sr2fscale(sr_core); move16(); /* set number of coded lines */ - st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(bandwidth); - - test(); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(bwidth); test(); - IF (( (GE_16(bandwidth, WB))&&(EQ_16(fscale,(FSCALE_DENOM*16000)/12800))&&(EQ_16(fscale,st->fscale)))) + test(); + IF (( (GE_16(bwidth, WB)) && (EQ_16(fscale,(FSCALE_DENOM*16000)/12800)) && (EQ_16(fscale,st->fscale)))) { test(); test(); test(); - if ( ((GT_32(bitrate, 32000))&&(st->tcxonly==0))||((LE_32(bitrate,32000))&&(st->tcxonly!=0))) + if ( ((GT_32(total_brate, 32000)) && (st->tcxonly==0)) || ((LE_32(total_brate,32000)) && (st->tcxonly!=0))) { switchWB = 1; move16(); @@ -55,22 +69,24 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bit } test(); - if( GT_16(st->last_L_frame_fx,L_FRAME16k)&&LE_32(st->total_brate_fx,ACELP_32k)) + if( GT_16(st->last_L_frame_fx,L_FRAME16k) && LE_32(total_brate ,ACELP_32k)) { switchWB = 1; move16(); } + st->igf = getIgfPresent(st->element_mode, total_brate, bwidth, st->rf_flag); - st->igf = getIgfPresent(bitrate, bandwidth, st->rf_flag); - - st->hIGFDec.infoIGFStopFreq = -1; + IF(st->hIGFDec != NULL) + { + st->hIGFDec->infoIGFStopFreq = -1; + } move16(); - IF( st->igf ) + test(); test(); + IF( st->igf && (st->idchan == 0 || EQ_16(st->element_mode, IVAS_CPE_MDCT) ) ) { /* switch IGF configuration */ - IGFDecSetMode( &st->hIGFDec, st->total_brate_fx, bandwidth, -1, -1, st->rf_flag); - + IGFDecSetMode( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag); } test(); @@ -79,7 +95,16 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bit test(); IF ( NE_16(fscale, st->fscale)||switchWB!=0||bSwitchFromAmrwbIO!=0||EQ_16(st->last_codec_mode,MODE1)||st->force_lpd_reset) { - open_decoder_LPD( st, bitrate, bandwidth ); +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + open_decoder_LPD(st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0); +#else +#ifdef IVAS_CODE + open_decoder_LPD(st, total_brate, last_total_brate, bwidth, is_mct, 0); +#else + open_decoder_LPD(st, total_brate, bwidth); +#endif +#endif + } ELSE { @@ -90,48 +115,55 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bit st->fscale = fscale; move16(); st->L_frame_fx = extract_l(Mult_32_16(st->sr_core , 0x0290)); - st->L_frameTCX = extract_l(Mult_32_16(st->output_Fs_fx , 0x0290)); - - st->tcx_cfg.ctx_hm = getCtxHm(bitrate, st->rf_flag); - st->tcx_cfg.resq = getResq(bitrate); + IF(hTcxDec != NULL) + { + hTcxDec->L_frameTCX = extract_l(Mult_32_16(st->output_Fs_fx, 0x0290)); + } + IF (st->hTcxCfg != NULL) + { + st->hTcxCfg->ctx_hm = getCtxHm(st->element_mode, total_brate, st->rf_flag); + st->hTcxCfg->resq = getResq(total_brate); + } move16(); - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - bitrate, - bandwidth - ,st->rf_flag - ); + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode ); st->narrowBand = 0; move16(); - if ( EQ_16(bandwidth, NB)) + if ( EQ_16(bwidth, NB)) { st->narrowBand = 1; move16(); } - st->TcxBandwidth = getTcxBandwidth(bandwidth); + st->TcxBandwidth = getTcxBandwidth(bwidth); - st->tcx_cfg.pCurrentTnsConfig = NULL; - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(bitrate, st->igf ); - move16(); - - IF (st->tcx_cfg.fIsTNSAllowed != 0) + IF (st->hTcxCfg != NULL) { - InitTnsConfigs(bwMode2fs[bandwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFDec.infoIGFStopFreq, st->total_brate_fx); + st->hTcxCfg->pCurrentTnsConfig = NULL; + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(total_brate, st->igf, st->element_mode); + move16(); + + IF(st->hTcxCfg->fIsTNSAllowed != 0 && st->hIGFDec != NULL) + { + InitTnsConfigs(bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0/* 0 should be replaced with MCT_flag*/); +#ifdef IVAS_CODE + SetAllowTnsOnWhite(st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT); +#endif + } } } frame_size = FrameSizeConfig[frame_size_index].frame_net_bits; move16(); - reconfig_decoder_LPD( st, frame_size, bandwidth, bitrate, st->last_L_frame_fx ); + reconfig_decoder_LPD( st, frame_size, bwidth, total_brate, st->last_L_frame_fx ); test(); - IF (st->envWeighted != 0 && st->enableTcxLpc == 0) + IF (hTcxDec->envWeighted != 0 && hTcxDec->enableTcxLpc == 0) { Copy(st->lspold_uw, st->lsp_old_fx, M); Copy(st->lsfold_uw, st->lsf_old_fx, M); - st->envWeighted = 0; + hTcxDec->envWeighted = 0; move16(); } @@ -144,38 +176,36 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bit { E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsfoldbfi1_fx, M ); } - mvr2r_Word16(st->lsfoldbfi1_fx, st->lsfoldbfi0_fx,M); - mvr2r_Word16(st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx,M); + Copy(st->lsfoldbfi1_fx, st->lsfoldbfi0_fx,M); + Copy(st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx,M); - IF( st->igf != 0 ) + IF( st->igf != 0 && hBWE_TD != NULL) { - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test(); IF( (EQ_16(st->bwidth_fx, WB)&&NE_16(st->last_extl_fx,WB_TBE))|| (EQ_16(st->bwidth_fx, SWB) && NE_16(st->last_extl_fx, SWB_TBE)) || (EQ_16(st->bwidth_fx, FB) && NE_16(st->last_extl_fx,FB_TBE)) ) { +#ifdef IVAS_CODE + TBEreset_dec_fx(st); +#else TBEreset_dec_fx(st, st->bwidth_fx); +#endif } ELSE { - set16_fx( st->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st->gain_prec_swb_fx = 16384; + set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } } test(); test(); - IF( (EQ_16(bandwidth, SWB))&& - (EQ_32(st->total_brate_fx, ACELP_16k40) || EQ_32(st->total_brate_fx, ACELP_24k40)) - ) + IF( (EQ_16(bwidth, SWB))&& (EQ_32(total_brate, ACELP_16k40) || EQ_32(total_brate, ACELP_24k40)) && EQ_16(st->element_mode, EVS_MONO) ) { IF (st->tec_tfa == 0) { @@ -200,12 +230,7 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bit move16(); test(); test(); - test(); - test(); - test(); - if( (EQ_16(bandwidth, WB )&&EQ_32(bitrate,24400))|| - (sub(bandwidth, SWB) == 0 && L_sub(bitrate, 24400) == 0 )|| - (sub(bandwidth, FB) == 0 && L_sub(bitrate, 24400) == 0 ) ) + IF ( GE_16(bwidth, WB) && EQ_32(total_brate, 24400) && EQ_16(st->element_mode, EVS_MONO) ) { st->enableGplc = 1; move16(); @@ -214,8 +239,8 @@ void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bit st->dec_glr = 0; test(); test(); - if( (EQ_32(st->total_brate_fx, 9600))||(EQ_32(st->total_brate_fx,16400))|| - (EQ_32(st->total_brate_fx, 24400))) + test(); + IF (( EQ_32(total_brate, 9600) || EQ_32(total_brate,16400) || EQ_32(total_brate, 24400)) && EQ_16(st->element_mode, EVS_MONO) ) { st->dec_glr = 1; move16(); diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index cee2189..8387195 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ #include "basop_mpy.h" /*required for CodeB_Mpy_32_16()*/ #include "basop_util.h" /* Function prototypes */ @@ -17,11 +16,24 @@ * * *---------------------------------------------------------------------*/ - +#ifdef IVAS_CODE_SWITCHING +static void core_switch_lb_upsamp(Decoder_State* st, float* output); +static void smoothTransitionDtxToTcx(float synth[], const int16_t output_frame, const int16_t delay_comp); +#endif void bandwidth_switching_detect_fx( Decoder_State_fx *st_fx /* i/o: encoder state structure */ ) { + IF ((EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1) ) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */ + st_fx->prev_bws_cnt_fx = 0; + st_fx->bws_cnt_fx = 0; + st_fx->bws_cnt1_fx = 0; + move16(); move16(); move16(); + + return; + } /* update band-width switching counter */ test(); test(); @@ -164,7 +176,24 @@ void bw_switching_pre_proc_fx( Word16 i; Word16 syn_dct_fx[L_FRAME]; Word32 L_tmp; - IF( EQ_16(st_fx->core_fx, ACELP_CORE)) + +#ifdef IVAS_CODE_SWITCHING + IF (GT_16(st_fx->element_mode, EVS_MONO)) + { + test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); + IF (EQ_16(st_fx->core_fx, ACELP_CORE) && !(EQ_16(st_fx->bfi_fx, 1) && EQ_16(st_fx->con_tcx, 1)) && + st_fx->hBWE_FD != NULL && !(LE_16(st_fx->core_brate_fx, SID_2k40) && EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && EQ_16(nchan_out, 2)) && + !(EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_16(last_element_brate, IVAS_SID_4k4))) + { + /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ + calc_tilt_bwe(old_syn_12k8_16k, &st->tilt_wb, st->L_frame); + } + + return; + } +#endif + test(); test(); + IF( EQ_16(st_fx->core_fx, ACELP_CORE) && !(EQ_16(st_fx->bfi_fx, 1) && EQ_16(st_fx->con_tcx, 1))) { /*----------------------------------------------------------------------* * Calculate tilt of the ACELP core synthesis @@ -176,7 +205,7 @@ void bw_switching_pre_proc_fx( * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis *-------------------------------------------------------------------------------*/ - edct_16fx(old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6); + edct_16fx(old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode); L_tmp = L_deposit_l(0); FOR ( i=0; i < L_FRAME/2; i++ ) @@ -195,7 +224,7 @@ void bw_switching_pre_proc_fx( } ELSE { - IF( st_fx->old_is_transient_fx[0] ) + IF( st_fx->hHQ_core->old_is_transient_fx[0] ) { L_tmp = L_deposit_l(0); FOR ( i=0; i<32; i++ ) @@ -244,7 +273,7 @@ void bw_switching_pre_proc_fx( move16(); set16_fx(st_fx->prev_SWB_fenv_fx, 0, SWB_FENV); } - ELSE if(((EQ_16(st_fx->core_fx, ACELP_CORE)&&EQ_16(st_fx->last_core_fx,HQ_CORE))||(EQ_16(st_fx->core_fx,st_fx->last_core_fx)&&NE_16(st_fx->extl_fx,st_fx->last_extl_fx)))&&GE_16(st_fx->last_bwidth_fx,SWB)) + ELSE if(((EQ_16(st_fx->core_fx, ACELP_CORE) && ( EQ_16(st_fx->last_core_fx,HQ_CORE) || EQ_16(st_fx->last_core_fx, TCX_10_CORE) || EQ_16(st_fx->last_core_fx, TCX_20_CORE)))||(EQ_16(st_fx->core_fx,st_fx->last_core_fx)&&NE_16(st_fx->extl_fx,st_fx->last_extl_fx)))&&GE_16(st_fx->last_bwidth_fx,SWB)) { st_fx->attenu_fx = 3277; move16(); @@ -264,22 +293,176 @@ void bw_switching_pre_proc_fx( return; } +#ifdef IVAS_CODE_SWITCHING + + +/*---------------------------------------------------------------------* + * core_switch_lb_upsamp() + * + * Resample HQ/TCX-LB to the output sampling rate (8/16/32/48 kHz) + *---------------------------------------------------------------------*/ + +static void core_switch_lb_upsamp( + Decoder_State* st, /* i/o: Decoder state */ + float* output /* i/o: LB synth/upsampled LB synth */ +) +{ + int16_t i; + float* realBuffer[CLDFB_OVRLP_MIN_SLOTS], * imagBuffer[CLDFB_OVRLP_MIN_SLOTS]; + float realBufferTmp[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX]; + float imagBufferTmp[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX]; + + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for (i = 0; i < CLDFB_OVRLP_MIN_SLOTS; i++) + { + set_f(realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); + set_f(imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX); + realBuffer[i] = realBufferTmp[i]; + imagBuffer[i] = imagBufferTmp[i]; + } + + /* check if the CLDFB works on the right sample rate */ + if ((st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame) + { + resampleCldfb(st->cldfbAna, st->L_frame * FRAMES_PER_SEC); + + if (st->cldfbBPF != NULL && st->L_frame <= L_FRAME16k) + { + resampleCldfb(st->cldfbBPF, st->L_frame * FRAMES_PER_SEC); + } + + if (st->ini_frame > 0) + { + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; + } + } + + /* analysis of the synthesis at internal sampling rate */ + cldfbAnalysis(output, realBuffer, imagBuffer, CLDFB_OVRLP_MIN_SLOTS * st->cldfbAna->no_channels, st->cldfbAna); + + /* analysis and add the BPF error signal */ + if (st->p_bpf_noise_buf) + { + addBassPostFilter(st->p_bpf_noise_buf, st->bpf_off ? 0 : CLDFB_OVRLP_MIN_SLOTS * st->cldfbBPF->no_channels, realBuffer, imagBuffer, st->cldfbBPF); + } + + /* set output mask for upsampling */ + if (st->bwidth == NB) + { + /* set NB mask for upsampling */ + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - 10; + } + else if (st->cldfbSyn->bandsToZero != st->cldfbSyn->no_channels - st->cldfbAna->no_channels) + { + /* in case of BW switching, re-init to default */ + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; + } + + /* synthesis of the combined signal */ + cldfbSynthesis(realBuffer, imagBuffer, output, CLDFB_OVRLP_MIN_SLOTS * st->cldfbSyn->no_channels, st->cldfbSyn); + + /* save synthesis - needed in case of core switching */ + if (st->hTcxDec != NULL) + { + mvr2r(output, st->previoussynth, st->hTcxDec->L_frameTCX); + } + + return; +} + +/*---------------------------------------------------------------------* + * smoothTransitionMdctStereoDtx() + * + * apply smoothing to the transition part for MDCT-Stereo DTX + *---------------------------------------------------------------------*/ + +#define TRANSITION_SMOOTHING_LEN_16k 15 +#define TRANSITION_SMOOTHING_LEN_32k 31 +#define TRANSITION_SMOOTHING_LEN_48k 47 + +static void smoothTransitionMdctStereoDtx( + float synth[], /* i/o: synthesis */ + const int16_t output_frame, /* i : output frame length */ + const int16_t delay_comp /* i : delay compensation in samples */ +) +{ + int16_t i, filter_len; + float w, mem, step, fade_in; + float smoothing_input_buffer[2 * NS2SA(48000, DELAY_CLDFB_NS) + TRANSITION_SMOOTHING_LEN_48k]; + float smoothing_out_buffer[2 * NS2SA(48000, DELAY_CLDFB_NS) + TRANSITION_SMOOTHING_LEN_48k]; + + filter_len = TRANSITION_SMOOTHING_LEN_16k; + if (output_frame == L_FRAME32k) + { + filter_len = TRANSITION_SMOOTHING_LEN_32k; + } + else if (output_frame == L_FRAME48k) + { + filter_len = TRANSITION_SMOOTHING_LEN_48k; + } + + /* prepare buffer */ + for (i = 0; i < filter_len / 2; i++) + { + smoothing_input_buffer[i] = synth[0]; + } + mvr2r(synth, smoothing_input_buffer + filter_len / 2, 2 * delay_comp + filter_len / 2); + + /* apply Mean filter */ + w = 1.f / filter_len; + mem = sum_f(smoothing_input_buffer, filter_len); + for (i = 0; i < 2 * delay_comp; i++) + { + smoothing_out_buffer[i] = w * mem; + mem = mem - smoothing_input_buffer[i] + smoothing_input_buffer[i + filter_len]; + } + + /* apply fades around transition */ + step = 1.f / delay_comp; + fade_in = 0.f; + for (i = 0; i < delay_comp; i++) + { + synth[i] = smoothing_out_buffer[i] * fade_in + synth[i] * (1 - fade_in); + fade_in += step; + } + fade_in = 0.f; + for (; i < 2 * delay_comp; i++) + { + synth[i] = synth[i] * fade_in + smoothing_out_buffer[i] * (1 - fade_in); + fade_in += step; + } + + return; +} +#endif /*---------------------------------------------------------------------* * core_switching_pre_dec_fx() * * Preprocessing/preparation for ACELP/HQ core switching *---------------------------------------------------------------------*/ - -void core_switching_pre_dec_fx( +ivas_error core_switching_pre_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ const Word16 output_frame /* i : frame length */ ) { - Word16 oldLenClasBuff, newLenClasBuff; - + Word16 oldLenClasBuff, newLenClasBuff, i; + BPF_DEC_HANDLE hBPF; + TD_BWE_DEC_HANDLE hBWE_TD; + FD_BWE_DEC_HANDLE hBWE_FD; + HQ_DEC_HANDLE hHQ_core; + TCX_DEC_HANDLE hTcxDec; + ivas_error error; + + hBWE_TD = st_fx->hBWE_TD; + hBWE_FD = st_fx->hBWE_FD; + hHQ_core = st_fx->hHQ_core; + hBPF = st_fx->hBPF; + hTcxDec = st_fx->hTcxDec; + + error = IVAS_ERR_OK; /* Codec switching */ - IF( EQ_16(st_fx->last_codec_mode,MODE2)) + IF( EQ_16(st_fx->last_codec_mode,MODE2) || ((EQ_16(st_fx->last_core_fx, TCX_20_CORE) || EQ_16(st_fx->last_core_fx, TCX_10_CORE)) && GT_16(st_fx->element_mode, EVS_MONO))) { st_fx->mem_deemph_fx = st_fx->syn[M]; move16(); @@ -290,12 +473,15 @@ void core_switching_pre_dec_fx( st_fx->bpf_off_fx = 1; move16(); - Scale_sig(st_fx->pfstat.mem_pf_in, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ - Scale_sig(st_fx->pfstat.mem_res2, DECMEM_RES2, st_fx->Q_syn); /* NB post_filter mem */ - Scale_sig(st_fx->pfstat.mem_stp, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ - set16_fx( st_fx->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ - st_fx->pst_lp_ener_fx = round_fx(L_shl(Mpy_32_16_1(st_fx->lp_error_ener, 0x6054), 2+8)); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ - st_fx->pst_mem_deemp_err_fx = 0; + Scale_sig(st_fx->hPFstat->mem_pf_in, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ + Scale_sig(st_fx->hPFstat->mem_res2, DECMEM_RES2, st_fx->Q_syn); /* NB post_filter mem */ + Scale_sig(st_fx->hPFstat->mem_stp, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ + IF (hBPF != NULL) + { + set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); /* BPF mem*/ + hBPF->pst_lp_ener_fx = round_fx(L_shl(Mpy_32_16_1(st_fx->lp_error_ener, 0x6054), 2 + 8)); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ + hBPF->pst_mem_deemp_err_fx = 0; + } move16(); st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); @@ -309,8 +495,6 @@ void core_switching_pre_dec_fx( st_fx->old_bwe_delay_fx = NS2SA_fx2( st_fx->output_Fs_fx, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); } set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS) ); - st_fx->prev_hb_synth_fx_exp = 31; - move16(); /* reset upd_cnt */ st_fx->upd_cnt_fx = MAX_UPD_CNT; @@ -318,55 +502,72 @@ void core_switching_pre_dec_fx( st_fx->igf = 0; move16(); - IF( NE_16(st_fx->last_core_fx,ACELP_CORE)) + + IF(hBWE_TD != NULL && NE_16(st_fx->last_core_fx,ACELP_CORE)) { + hBWE_TD->prev_hb_synth_fx_exp = 31; + move16(); /* reset BWE memories */ - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); } - IF( GE_32(st_fx->output_Fs_fx,16000)) + IF( GE_32(st_fx->output_Fs_fx,16000) && st_fx->hBWE_zero != NULL) { - hf_synth_reset_fx( &st_fx->seed2_fx, st_fx->mem_hf_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp400_fx, st_fx->mem_hp_interp_fx, st_fx->delay_syn_hf_fx ); + hf_synth_reset_fx(st_fx->hBWE_zero); } - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + IF (st_fx->hBWE_FD != NULL) + { + set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + } + IF(st_fx->hHQ_core != NULL) + { + set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB); + set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB); - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + hHQ_core->last_max_pos_pulse_fx = 0; + move16(); - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); + IF(GT_32(st_fx->output_Fs_fx, 16000)) + { + set32_fx(hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE); + } - IF( GT_32(st_fx->output_Fs_fx,16000)) - { - set32_fx( st_fx->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + /* pre-echo */ + hHQ_core->pastpre_fx = 0; + move16(); } - - /* pre-echo */ - st_fx->pastpre_fx = 0; - move16(); /* reset the GSC pre echo energy threshold in case of switching */ - st_fx->Last_frame_ener_fx = MAX_32; + IF (st_fx->hGSCDec != NULL) + { + st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + } move32(); test(); IF( EQ_16(st_fx->last_core_fx,TCX_20_CORE)||EQ_16(st_fx->last_core_fx,TCX_10_CORE)) { - st_fx->last_core_fx = HQ_CORE; - move16(); - Copy( st_fx->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + st_fx->last_core_fx = HQ_CORE; + move16(); + Copy(hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); + } + IF (hHQ_core != NULL) + { + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + hHQ_core->last_max_pos_pulse_fx = 0; + move16(); - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); + set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); + hHQ_core->prev_frm_hfe2_fx = 0; + move16(); + hHQ_core->prev_stab_hfe2_fx = 0; + move16(); + } } IF(st_fx->prev_bfi_fx!=0) @@ -374,22 +575,25 @@ void core_switching_pre_dec_fx( Word16 delay_comp; /*switch off Hq Voicing as it was not uodated in MODE2*/ - st_fx->oldHqVoicing_fx=0; - st_fx->HqVoicing_fx=0; - move16(); + IF(hHQ_core != NULL) + { + hHQ_core->oldHqVoicing_fx = 0; + hHQ_core->HqVoicing_fx = 0; + move16();move16(); + } delay_comp = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS); IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16(st_fx->core_fx,HQ_CORE)) { - Word16 i, no_col; - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 no_col; + Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; + Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; CLDFB_SCALE_FACTOR scaleFactor; Word32 workBuffer[128*3]; - FOR( i=0; icldfbAna_fx->no_col, idiv1616(sub(add(delay_comp, st_fx->cldfbAna_fx->no_channels),1) , st_fx->cldfbAna_fx->no_channels)); /* CLDFB analysis of the synthesis at internal sampling rate */ - cldfb_save_memory( st_fx->cldfbAna_fx ); - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, st_fx->syn_Overl, 0, no_col, workBuffer); + IF ((error = cldfb_save_memory( st_fx->cldfbAna_fx )) != IVAS_ERR_OK) + { + return error; + } + cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer); cldfb_restore_memory( st_fx->cldfbAna_fx ); scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); /* CLDFB synthesis of the combined signal */ - cldfb_save_memory( st_fx->cldfbSyn_fx ); - cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, st_fx->fer_samples_fx, 0, no_col, workBuffer); + IF ((error = cldfb_save_memory( st_fx->cldfbSyn_fx )) != IVAS_ERR_OK) + { + return error; + } + cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer); cldfb_restore_memory( st_fx->cldfbSyn_fx ); } IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16(st_fx->core_fx,HQ_CORE)) { - lerp(st_fx->syn_Overl, st_fx->fer_samples_fx+delay_comp,shr(st_fx->output_frame_fx,1), shr(st_fx->last_L_frame_fx,1)); + lerp(hTcxDec->syn_Overl, hHQ_core->fer_samples_fx+delay_comp,shr(st_fx->output_frame_fx,1), shr(st_fx->last_L_frame_fx,1)); /*Set to zero the remaining part*/ - set16_fx( st_fx->fer_samples_fx+delay_comp+shr(st_fx->output_frame_fx,1), 0, shr(st_fx->output_frame_fx,1)-delay_comp); + set16_fx(hHQ_core->fer_samples_fx+delay_comp+shr(st_fx->output_frame_fx,1), 0, shr(st_fx->output_frame_fx,1)-delay_comp); } } @@ -486,8 +696,21 @@ void core_switching_pre_dec_fx( test(); test(); - IF( (EQ_16(st_fx->core_fx,ACELP_CORE)||EQ_16(st_fx->core_fx,AMR_WB_CORE))&&EQ_16(st_fx->last_core_fx,HQ_CORE)) + IF( ((EQ_16(st_fx->core_fx,ACELP_CORE)||EQ_16(st_fx->core_fx,AMR_WB_CORE))&&EQ_16(st_fx->last_core_fx,HQ_CORE) ) +//#ifdef IVAS_CODE_SWITCHING +// || ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || +// (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && last_element_mode == IVAS_CPE_DFT)) && EQ_16(nchan_out,2) && +// NE_16(st_fx->core_brate_fx, SID_2k40) && NE_16(st_fx->core_brate_fx, FRAME_NO_DATA) && (EQ_16(last_core_brate_st0, FRAME_NO_DATA) || EQ_16(last_core_brate_st0, SID_2k40))) +//#endif + ) { + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + st_fx->hPFstat->reset = 1; + move16(); + } + IF(EQ_16(st_fx->L_frame_fx, L_FRAME16k)) { Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M ); @@ -505,6 +728,14 @@ void core_switching_pre_dec_fx( lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); } +#ifdef IVAS_CODE_SWITCHING + if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && nchan_out == 2 && st->core_brate > SID_2k40 && (last_core_brate_st0 == FRAME_NO_DATA || last_core_brate_st0 == SID_2k40) && st->hTcxDec != NULL) + { + /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ + set_f(st->hTcxDec->old_syn_Overl, 0.0f, L_FRAME32k / 2); + set_f(st->hFdCngDec->hFdCngCom->olapBufferAna, 0.0f, FFTLEN); + } +#endif set16_fx( st_fx->agc_mem_fx, 0, 2 ); st_fx->mem_deemph_fx = 0; move16(); @@ -513,12 +744,14 @@ void core_switching_pre_dec_fx( set16_fx( st_fx->mem_syn2_fx, 0, M ); } set16_fx( st_fx->mem_syn1_fx, 0, M ); - st_fx->bwe_non_lin_prev_scale_fx = 0; - move16(); - + IF(hBWE_TD != NULL) + { + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move16(); + } /* Reset ACELP parameters */ set16_fx( st_fx->mem_MA_fx,0, M ); - IF( EQ_32(st_fx->sr_core,16000)) + IF( EQ_32(st_fx->sr_core, INT_FS_16k)) { Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); } @@ -572,7 +805,8 @@ void core_switching_pre_dec_fx( /* reset TBE memories */ test(); - IF (!st_fx->last_con_tcx) + + IF (!st_fx->last_con_tcx && !((EQ_16(st_fx->last_core_fx, HQ_CORE)) && GT_16(st_fx->element_mode, EVS_MONO))) { set16_fx(st_fx->old_exc_fx,0, L_EXC_MEM_DEC ); } @@ -582,47 +816,124 @@ void core_switching_pre_dec_fx( synth_mem_updt2( st_fx->L_frame_fx, L_FRAME16k, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); } - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); + IF (hBWE_TD != NULL) + { + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + } - IF( GE_32(st_fx->output_Fs_fx, 16000L)) + IF( GE_32(st_fx->output_Fs_fx, 16000L) && st_fx->hBWE_zero != NULL) { - hf_synth_reset_fx( &st_fx->seed2_fx, st_fx->mem_hf_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp400_fx, st_fx->mem_hp_interp_fx, st_fx->delay_syn_hf_fx ); + hf_synth_reset_fx(st_fx->hBWE_zero); + } + IF(hBWE_FD != NULL) + { + set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); } - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); } +#ifdef IVAS_CODE_SWITCHING + if ((st->core == ACELP_CORE || st->core == AMR_WB_CORE) && (st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE)) + { + if (st->hBWE_TD != NULL) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + set_f(st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2); + } - test(); - test(); - IF( EQ_16(st_fx->core_fx,HQ_CORE)&&(EQ_16(st_fx->last_core_fx,ACELP_CORE)||st_fx->last_core_fx==AMR_WB_CORE)) + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + set_f(st->dispMem, 0, 8); + + st->last_coder_type = GENERIC; + + fer_energy(output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); + st->lp_gainp = 0.0f; + st->lp_gainc = (float)sqrt(st->lp_ener); + + st->last_voice_factor = 0; + st->Last_GSC_noisy_speech_flag = 0; + + if (st->output_Fs >= 16000 && st->hBWE_zero != NULL) + { + hf_synth_reset(st->hBWE_zero); + } + + if (st->hBWE_FD != NULL) + { + set_f(st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + } + + if (nchan_out == 1 && st->element_mode == IVAS_CPE_DFT && st->element_brate <= IVAS_24k4 && last_element_brate > IVAS_24k4) + { + /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ + int16_t offset; + offset = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels; + mvr2r(st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state, offset); + } + } +#endif + test(); test(); test(); test(); test(); + IF(hHQ_core!= NULL && EQ_16(st_fx->core_fx,HQ_CORE) && (EQ_16(st_fx->last_core_fx,ACELP_CORE) || EQ_16(st_fx->last_core_fx,AMR_WB_CORE) || (NE_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->last_core_fx, HQ_CORE ) ) ) ) { - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); + set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse_fx = 0; - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; - st_fx->prev_stab_hfe2_fx = 0; + set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2_fx = 0; + hHQ_core->prev_stab_hfe2_fx = 0; IF( GT_32(st_fx->output_Fs_fx,16000)) { - set32_fx( st_fx->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + set32_fx(hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } +#ifdef IVAS_CODE_SWITCHING + if (st->element_mode != EVS_MONO) + { + /* Estimate mem_env_delta to reinit env_stab */ + tmp = max(0, ENV_STAB_EST1 + (ENV_STAB_EST2 * st->stab_fac_smooth_lt) + (ENV_STAB_EST3 * st->log_energy_diff_lt)); + st->hHQ_core->mem_env_delta = (int16_t)min(MAX16B, (int32_t)(tmp * (1 << 12))); /* Convert to Q12 and handle saturation */ + + if (st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE) + { + set_f(st->hHQ_core->old_out, 0, output_frame); + set_f(st->hHQ_core->old_outLB, 0, L_FRAME16k); + } + + st->hHQ_core->no_att_hangover = 0; + st->hHQ_core->energy_lt = 300.0f; - set16_fx( st_fx->old_out_fx, 0, output_frame ); - st_fx->Q_old_wtda_LB = 15; - st_fx->Q_old_wtda = 15; + set_s(st->hHQ_core->old_is_transient, 0, 3); + set_f(st->hHQ_core->prev_noise_level, 0.0f, 2); + st->hHQ_core->prev_R = 0; + set_s(st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); + st->hHQ_core->prev_hqswb_clas = HQ_NORMAL; + st->hHQ_core->prev_ni_ratio = 0.5f; + set_f(st->hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS); + } + else +#endif + { + set16_fx(hHQ_core->old_out_fx, 0, output_frame); + hHQ_core->Q_old_wtda_LB = 15; + hHQ_core->Q_old_wtda = 15; +#ifdef IVAS_CODE_SWITCHING + set_f(st->hHQ_core->old_outLB, 0, L_FRAME16k); +#endif + } } /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ - st_fx->pastpre_fx--; - IF( st_fx->pastpre_fx <= 0 ) + IF (hHQ_core != NULL) { - reset_preecho_dec_fx( st_fx ); + hHQ_core->pastpre_fx--; + IF(hHQ_core->pastpre_fx <= 0) + { + reset_preecho_dec_fx(hHQ_core); + } } - IF( EQ_32(st_fx->core_brate_fx,FRAME_NO_DATA)) { st_fx->VAD = 0; @@ -630,7 +941,7 @@ void core_switching_pre_dec_fx( st_fx->m_frame_type = ZERO_FRAME; move16(); } - ELSE IF( LE_32(st_fx->core_brate_fx,SID_2k40)) + ELSE IF( EQ_32(st_fx->core_brate_fx,SID_2k40) || EQ_32(st_fx->core_brate_fx, SID_1k75) ) { st_fx->VAD = 0; move16(); @@ -650,22 +961,24 @@ void core_switching_pre_dec_fx( test(); test(); test(); - IF( NE_16(st_fx->core_fx,AMR_WB_CORE)&&st_fx->VAD&&LE_32(st_fx->total_brate_fx,CNA_MAX_BRATE)) - { - st_fx->flag_cna = 1; - move16(); - } - ELSE IF( EQ_16(st_fx->core_fx,AMR_WB_CORE)&&st_fx->VAD&&LE_32(st_fx->total_brate_fx,ACELP_8k85)) + IF(EQ_16(st_fx->element_mode, EVS_MONO)) /* for IVAS modes, st->flag_cna is set earlier */ { - st_fx->flag_cna = 1; - move16(); - } - ELSE IF( st_fx->VAD || ( EQ_16(st_fx->cng_type_fx,FD_CNG)&&EQ_16(st_fx->L_frame_fx,L_FRAME16k))) - { - st_fx->flag_cna = 0; - move16(); + IF(NE_16(st_fx->core_fx, AMR_WB_CORE) && st_fx->VAD && LE_32(st_fx->total_brate_fx, CNA_MAX_BRATE)) + { + st_fx->flag_cna = 1; + move16(); + } + ELSE IF(EQ_16(st_fx->core_fx, AMR_WB_CORE) && st_fx->VAD && LE_32(st_fx->total_brate_fx, ACELP_8k85)) + { + st_fx->flag_cna = 1; + move16(); + } + ELSE IF(st_fx->VAD || (EQ_16(st_fx->cng_type_fx, FD_CNG) && EQ_16(st_fx->L_frame_fx, L_FRAME16k))) + { + st_fx->flag_cna = 0; + move16(); + } } - if( EQ_16(st_fx->core_fx,AMR_WB_CORE)) { st_fx->cng_type_fx = LP_CNG; @@ -693,11 +1006,11 @@ void core_switching_pre_dec_fx( tmp = ACELP_9k60; move32(); } - configureFdCngDec(st_fx->hFdCngDec_fx, st_fx->bwidth_fx, tmp, st_fx->L_frame_fx ); + configureFdCngDec(st_fx->hFdCngDec_fx, st_fx->bwidth_fx, tmp, st_fx->L_frame_fx, st_fx->last_L_frame_fx, st_fx->element_mode ); } ELSE { - configureFdCngDec(st_fx->hFdCngDec_fx, 1, ACELP_8k00, st_fx->L_frame_fx ); + configureFdCngDec(st_fx->hFdCngDec_fx, 1, ACELP_8k00, st_fx->L_frame_fx, st_fx->last_L_frame_fx, st_fx->element_mode); if( st_fx->VAD ) { @@ -710,32 +1023,37 @@ void core_switching_pre_dec_fx( test(); IF ( NE_16(st_fx->last_L_frame_fx,st_fx->L_frame_fx)&&LE_16(st_fx->L_frame_fx,L_FRAME16k)&&LE_16(st_fx->last_L_frame_fx,L_FRAME16k)) { - lerp( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st_fx->L_frame_fx*2, st_fx->last_L_frame_fx*2 ); + test(); +#ifdef IVAS_CODE_SWITCHING + IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + lerp(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferAna + st_fx->last_L_frame_fx, st_fx->hFdCngDec_fx->hFdCngCom->olapBufferAna + st_fx->L_frame_fx, st_fx->L_frame_fx, st_fx->last_L_frame_fx); + } +#endif + lerp(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st_fx->L_frame_fx * 2, st_fx->last_L_frame_fx * 2); test(); IF( LE_32(st_fx->total_brate_fx,SID_2k40)&&LE_32(st_fx->last_total_brate_fx,SID_2k40)) { lerp( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st_fx->L_frame_fx*2, st_fx->last_L_frame_fx*2 ); IF( EQ_16(st_fx->L_frame_fx, L_FRAME)) { - Word16 n; - FOR( n=0; n < st_fx->L_frame_fx*2; n++ ) + FOR( i=0; i < st_fx->L_frame_fx*2; i++ ) { - st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n] = mult_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n], 20480 ); + st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[i] = mult_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[i], 20480 ); } } ELSE { - Word16 n; - FOR( n=0; n < st_fx->L_frame_fx*2; n++ ) + FOR( i=0; i < st_fx->L_frame_fx*2; i++ ) { - st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n] = mult_r( shl(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n],1), 26214 ); + st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[i] = mult_r( shl(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[i],1), 26214 ); } } } } } - return; + return error; } /*---------------------------------------------------------------------* @@ -744,12 +1062,22 @@ void core_switching_pre_dec_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ -void core_switching_post_dec_fx( +ivas_error core_switching_post_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 *synth, /* i/o: output synthesis Qsynth */ +#ifdef IVAS_CODE_SWITCHING + float* output, /* i/o: LB synth/upsampled LB synth */ + float output_mem[], /* i : OLA memory from last TCX/HQ frame */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ +#endif const Word16 output_frame, /* i : frame length */ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ - const Word16 coder_type, /* i : ACELP coder type */ +#ifdef IVAS_CODE_SWITCHING + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 nchan_out, /* i : number of output channels */ +#endif + const Word16 last_element_mode, /* i : element mode of previous frame */ Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ ) { @@ -760,16 +1088,35 @@ void core_switching_post_dec_fx( Word16 mem_synth[NS2SA(16000, DELAY_CLDFB_NS)+2]; Word16 Qtmp; Word16 Qsubfr; + TD_BWE_DEC_HANDLE hBWE_TD; + FD_BWE_DEC_HANDLE hBWE_FD; + HQ_DEC_HANDLE hHQ_core; + ivas_error error; +#ifdef IVAS_CODE_SWITCHING + int16_t offset; +#endif +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(last_element_mode); +#endif + hBWE_TD = st_fx->hBWE_TD; + hBWE_FD = st_fx->hBWE_FD; + hHQ_core = st_fx->hHQ_core; + error = IVAS_ERR_OK; + + PMT("core_switching_post_dec_fx : Only handles has been converted, code needs to be entirely reviewed ") /* Rescale synthesis in Q0 to avoid multiple rescaling after */ tmp = Find_Max_Norm16(synth,output_frame); Scale_sig(synth,output_frame,tmp); *Qsynth=add(*Qsynth,tmp); - test(); - IF( EQ_16(st_fx->core_fx, ACELP_CORE)&&st_fx->bfi_fx) + test(); test(); test(); + IF( EQ_16(st_fx->core_fx, ACELP_CORE)&&st_fx->bfi_fx && hHQ_core != NULL && !st_fx->con_tcx) { - acelp_core_switch_dec_bfi_fx( st_fx, st_fx->fer_samples_fx, coder_type ); /*the output at Q0*/ + if ((error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type_fx )) != IVAS_ERR_OK) + { + return error; + } /*the output at Q0*/ } /* set multiplication factor according to the sampling rate */ @@ -795,7 +1142,7 @@ void core_switching_post_dec_fx( Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec));*/ - st_fx->mem_deemph_old_syn_fx = 0; + hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); test(); @@ -803,24 +1150,27 @@ void core_switching_post_dec_fx( test(); IF ( core_switching_flag && EQ_16(st_fx->last_L_frame_fx, st_fx->last_L_frame_ori_fx)&&(EQ_16(st_fx->last_core_fx,ACELP_CORE)||EQ_16(st_fx->last_core_fx,AMR_WB_CORE))) { - acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr ); + if ((error = acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr )) != IVAS_ERR_OK) + { + return error; + } } test(); test(); IF( core_switching_flag && EQ_16(st_fx->last_core_fx, HQ_CORE)&&st_fx->prev_bfi_fx) { Copy( st_fx->delay_buf_out_fx, synth_subfr_out, delay_comp ); - Qsubfr=st_fx->Q_old_postdec; + Qsubfr= hHQ_core->Q_old_postdec; } /* delay HQ synthesis to synchronize with ACELP synthesis */ /* rescaling to the min exp of the 2 */ - Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec); + Qtmp=s_min(*Qsynth, hHQ_core->Q_old_postdec); Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); *Qsynth=Qtmp; move16(); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec)); - st_fx->Q_old_postdec=Qtmp; + Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp, hHQ_core->Q_old_postdec)); + hHQ_core->Q_old_postdec=Qtmp; move16(); Copy( synth, &synth[delay_comp], output_frame); @@ -850,8 +1200,8 @@ void core_switching_post_dec_fx( shift = i_mult2(Fs_kHz, 10); tmp = i_mult2(delta,shr(N16_CORE_SW,1)); - Scale_sig(st_fx->fer_samples_fx, output_frame, *Qsynth); - ptmp2 = &st_fx->fer_samples_fx[tmp]; + Scale_sig(hHQ_core->fer_samples_fx, output_frame, *Qsynth); + ptmp2 = &hHQ_core->fer_samples_fx[tmp]; tmp = div_s(1, shift); /*Q15*/ tmpF = 0; move16(); @@ -874,8 +1224,8 @@ void core_switching_post_dec_fx( tmpF = 0; move16(); ptmp1 = synth; - Scale_sig(st_fx->fer_samples_fx, output_frame, *Qsynth); - ptmp2 = st_fx->fer_samples_fx; + Scale_sig(hHQ_core->fer_samples_fx, output_frame, *Qsynth); + ptmp2 = hHQ_core->fer_samples_fx; FOR( i=0; ibwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); IF ( !(EQ_16(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME16k)&&EQ_32(st_fx->core_brate_fx,HQ_32k))) { - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); + set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB ); } Copy_Scale_sig( synth, st_fx->previoussynth_fx, output_frame, negate(*Qsynth) ); /*scaling of st_fx->previoussynth_fx set at Q0*/ /*Set post-filtering flag to zero*/ - st_fx->pfstat.on = 0; + st_fx->hPFstat->on = 0; move16(); } ELSE { IF ( EQ_16(st_fx->last_core_fx, HQ_CORE)) /* MDCT to ACELP transition */ { - Qtmp = s_min(s_min(*Qsynth, st_fx->Q_old_postdec), st_fx->Q_old_wtda); + Qtmp = s_min(s_min(*Qsynth, hHQ_core->Q_old_postdec), hHQ_core->Q_old_wtda); Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec)); - Scale_sig(st_fx->old_out_fx, L_FRAME48k, sub(Qtmp, st_fx->Q_old_wtda)); + Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp, hHQ_core->Q_old_postdec)); + Scale_sig(hHQ_core->old_out_fx, L_FRAME48k, sub(Qtmp, hHQ_core->Q_old_wtda)); *Qsynth = Qtmp; move16(); - st_fx->Q_old_postdec=Qtmp; + hHQ_core->Q_old_postdec=Qtmp; move16(); - st_fx->Q_old_wtda=Qtmp; + hHQ_core->Q_old_wtda=Qtmp; move16(); Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ @@ -919,12 +1269,12 @@ void core_switching_post_dec_fx( tmp = i_mult2(delta, N_ZERO_8); shift = i_mult2(Fs_kHz, 3); test(); - IF( st_fx->prev_bfi_fx && st_fx->HqVoicing_fx ) + IF( st_fx->prev_bfi_fx && hHQ_core->HqVoicing_fx ) { - Copy_Scale_sig( st_fx->fer_samples_fx, &st_fx->old_out_fx[tmp], shift, *Qsynth ); + Copy_Scale_sig(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[tmp], shift, *Qsynth ); } - ptmp2 = &st_fx->old_out_fx[tmp]; + ptmp2 = &hHQ_core->old_out_fx[tmp]; tmp = div_s(1, shift); ptmp1 = &synth[delay_comp]; tmpF = 0; @@ -938,13 +1288,13 @@ void core_switching_post_dec_fx( } set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); - st_fx->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing_fx = 0; move16(); - set16_fx(st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - st_fx->prev_frm_hfe2_fx = 0; + set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); + hHQ_core->prev_frm_hfe2_fx = 0; move16(); - st_fx->prev_stab_hfe2_fx = 0; + hHQ_core->prev_stab_hfe2_fx = 0; move16(); } @@ -961,7 +1311,7 @@ void core_switching_post_dec_fx( test(); test(); test(); - IF(st_fx->bws_cnt_fx == 0 || (st_fx->bws_cnt_fx > 0 && NE_16(coder_type, INACTIVE)&&NE_16(coder_type,AUDIO))) + IF(st_fx->bws_cnt_fx == 0 || (st_fx->bws_cnt_fx > 0 && NE_16(st_fx->coder_type_fx, INACTIVE)&&NE_16(st_fx->coder_type_fx,AUDIO))) { st_fx->attenu_fx = 3277; move16(); @@ -970,29 +1320,29 @@ void core_switching_post_dec_fx( IF( ( NE_16(st_fx->last_extl_fx, SWB_BWE)&&EQ_16(st_fx->extl_fx,SWB_BWE))||(NE_16(st_fx->last_extl_fx,FB_BWE)&&EQ_16(st_fx->extl_fx,FB_BWE))|| ((EQ_16(st_fx->last_core_fx, HQ_CORE) || EQ_16(st_fx->last_extl_fx, SWB_TBE) ) && st_fx->extl_fx < 0 && NE_16(st_fx->core_fx, HQ_CORE) ) || (EQ_16(st_fx->last_core_fx,ACELP_CORE) && EQ_16(st_fx->core_fx,ACELP_CORE) - && ((NE_16(st_fx->prev_coder_type_fx,INACTIVE) && EQ_16(coder_type,INACTIVE) ) || (NE_16(st_fx->prev_coder_type_fx,AUDIO) && EQ_16(coder_type,AUDIO) )) + && ((NE_16(st_fx->prev_coder_type_fx,INACTIVE) && EQ_16(st_fx->coder_type_fx,INACTIVE) ) || (NE_16(st_fx->prev_coder_type_fx,AUDIO) && EQ_16(st_fx->coder_type_fx,AUDIO) )) && st_fx->bws_cnt_fx > 0) ) { - set16_fx( st_fx->L_old_wtda_swb_fx, 0, output_frame ); - st_fx->old_wtda_swb_fx_exp = 0; + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); + hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); if( NE_16(st_fx->last_extl_fx, WB_BWE)) { - st_fx->prev_mode_fx = NORMAL; + hBWE_FD->prev_mode_fx = NORMAL; move16(); } - st_fx->prev_Energy_fx = 0; + hBWE_FD->prev_Energy_fx = 0; move16(); - st_fx->prev_L_swb_norm_fx = 8; + hBWE_FD->prev_L_swb_norm_fx = 8; move16(); - st_fx->prev_frica_flag_fx = 0; + hBWE_FD->prev_frica_flag_fx = 0; move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_td_energy_fx = 0; + set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); + hBWE_FD->prev_td_energy_fx = 0; move16(); - st_fx->prev_weight_fx = 6554; + hBWE_FD->prev_weight_fx = 6554; move16(); /*0.2 in Q15*/ st_fx->prev_fb_ener_adjust_fx = 0; move16(); @@ -1002,20 +1352,20 @@ void core_switching_post_dec_fx( test(); IF( NE_16(st_fx->last_extl_fx, WB_BWE)&&EQ_16(st_fx->extl_fx,WB_BWE)) { - set16_fx(st_fx->L_old_wtda_swb_fx, 0, output_frame); + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, output_frame); test(); if ( NE_16(st_fx->last_extl_fx, SWB_BWE)&&NE_16(st_fx->last_extl_fx,FB_BWE)) { - st_fx->prev_mode_fx = NORMAL; + hBWE_FD->prev_mode_fx = NORMAL; move16(); } - st_fx->prev_Energy_wb_fx = 0; + hBWE_FD->prev_Energy_wb_fx = 0; move16(); - st_fx->prev_L_swb_norm_fx = 8; + hBWE_FD->prev_L_swb_norm_fx = 8; move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_flag_fx = 0; + set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); + hBWE_FD->prev_flag_fx = 0; move16(); } @@ -1041,29 +1391,29 @@ void core_switching_post_dec_fx( || ((EQ_16(st_fx->prev_coder_type_fx, AUDIO) || EQ_16(st_fx->prev_coder_type_fx, INACTIVE) ) && st_fx->bws_cnt_fx > 0) || (st_fx->bws_cnt_fx == 0 && EQ_16(st_fx->prev_bws_cnt_fx, N_WS2N_FRAMES)) ) { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx) - ,st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); + swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx) + , hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); IF( EQ_16(output_frame, L_FRAME16k)) { /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ - set16_fx( st_fx->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); } - set16_fx(st_fx->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); + set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); } ELSE IF( ( EQ_16(st_fx->extl_fx, SWB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE))&& ( NE_32(st_fx->last_total_brate_fx, st_fx->total_brate_fx) || NE_16(st_fx->last_bwidth_fx, st_fx->bwidth_fx) || NE_16(st_fx->last_codec_mode, MODE1) || NE_16(st_fx->rf_flag, st_fx->rf_flag_last) ) ) { - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st_fx->gain_prec_swb_fx = 16384; + set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } @@ -1073,7 +1423,7 @@ void core_switching_post_dec_fx( test(); IF(EQ_32(st_fx->output_Fs_fx,48000)&&((GT_32(st_fx->last_core_brate_fx,SID_2k40))&&(EQ_32(st_fx->core_brate_fx,FRAME_NO_DATA)||EQ_32(st_fx->core_brate_fx,SID_2k40)))) { - set16_fx( st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set16_fx(st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); } /* reset FB TBE buffers */ @@ -1081,24 +1431,24 @@ void core_switching_post_dec_fx( test(); IF( EQ_16(st_fx->extl_fx, FB_TBE)&&(NE_16(st_fx->last_extl_fx,FB_TBE)||NE_16(st_fx->L_frame_fx,st_fx->last_L_frame_fx))) { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); } /* reset WB TBE buffers */ test(); IF( NE_16(st_fx->last_extl_fx, WB_TBE)&&EQ_16(st_fx->extl_fx,WB_TBE)) { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->state_32and48k_WB_upsample_fx, st_fx->mem_resamp_HB_fx ); + wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_synth_fx(hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); + set16_fx(hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx(hBWE_TD->mem_csfilt_fx, 0, 2 ); } - return; + return error; } /*---------------------------------------------------------------------* @@ -1119,10 +1469,10 @@ void core_switching_hq_prepare_dec_fx( test(); IF( EQ_16(st_fx->last_core_fx, HQ_CORE)&&st_fx->prev_bfi_fx) { - Copy_Scale_sig( st_fx->old_out_fx, st_fx->fer_samples_fx, output_frame, negate(st_fx->Q_old_wtda) ); /*Q0*/ + Copy_Scale_sig( st_fx->hHQ_core->old_out_fx, st_fx->hHQ_core->fer_samples_fx, output_frame, negate(st_fx->hHQ_core->Q_old_wtda) ); /*Q0*/ } - /* set switching frame bit-rate */ + /* set switching frame bitrate */ IF( EQ_16(st_fx->last_L_frame_fx, L_FRAME)) { cbrate = L_add(st_fx->core_brate_fx, 0); @@ -1174,8 +1524,7 @@ void core_switching_hq_prepare_dec_fx( } /* reset state of old_out if switching */ - set16_fx( st_fx->old_out_fx, 0, output_frame ); - + set16_fx( st_fx->hHQ_core->old_out_fx, 0, output_frame ); return; } diff --git a/lib_dec/d_gain2p.c b/lib_dec/d_gain2p.c index b0b0ab4..59ec508 100644 --- a/lib_dec/d_gain2p.c +++ b/lib_dec/d_gain2p.c @@ -2,16 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -/*-------------------------------------------------------------------* - * Decoding of pitch and codebook gains (see q_gain2_plus.c) * - *-------------------------------------------------------------------*/ -#include +#include #include #include "prot_fx.h" #include "basop_util.h" #include "stl.h" #include "rom_com_fx.h" + /*-------------------------------------------------------------------* + * Decoding of pitch and codebook gains (see q_gain2_plus.c) * + *-------------------------------------------------------------------*/ /********************* * private functions * @@ -357,8 +357,7 @@ void decode_acelp_gains( } ELSE { - fprintf(stderr, "invalid gains coding for acelp!\n"); - assert(0); + IVAS_ERROR(IVAS_ERR_INTERNAL, "invalid gains coding for acelp!"); } } diff --git a/lib_dec/dec2t32_fx.c b/lib_dec/dec2t32_fx.c index 80d3966..20e2b6e 100644 --- a/lib_dec/dec2t32_fx.c +++ b/lib_dec/dec2t32_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*==========================================================================*/ @@ -96,8 +95,10 @@ void dec_acelp_2t32_fx( /* CALLED FROM : */ /*==========================================================================*/ void dec_acelp_1t64_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation Q12*/ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + Word16 code[], /* o: algebraic (fixed) codebook excitation Q12*/ + const Word16 L_subfr /* i : sub frame lenght*/ + ) { Word16 pos,sgn; @@ -105,19 +106,27 @@ void dec_acelp_1t64_fx( /*-----------------------------------------------------------------* * decode the positions and signs of pulses and build the codeword *-----------------------------------------------------------------*/ - pos = (Word16)get_next_indice_fx( st_fx, 7 ); - move16(); + IF ( EQ_16(L_subfr, L_SUBFR) ) + { + pos = (Word16)get_next_indice_fx(st_fx, 7); + move16(); + } + ELSE /* L_subfr == 2*L_SUBFR */ + { + pos = (Word16)get_next_indice_fx(st_fx, 8); + move16(); + } sgn = -512; move16(); - IF( GE_16(pos,L_SUBFR)) + IF( GE_16(pos, L_subfr)) { - pos = sub(pos, L_SUBFR); + pos = sub(pos, L_subfr); move16(); sgn = 512; move16(); } - set16_fx(code, 0, L_SUBFR); + set16_fx(code, 0, L_subfr); code[pos] = sgn; move16(); return; diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 40a905a..162aa30 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "assert.h" /* Static table prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Local functions @@ -20,7 +19,7 @@ static void dec_4p_4N1_fx(const Word32 index, const Word16 N, const Word16 offse static void dec_4p_4N_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[]); static void dec_5p_5N_fx(const Word32 index,const Word16 N,const Word16 offset,Word16 pos[]); static void dec_6p_6N2_fx(const Word32 index,const Word16 N,const Word16 offset,Word16 pos[]); -static Word32 fcb_decode_PI_fx(Word32 code_index,Word16 sector_6p[],Word16 pulse_num); +static void fcb_decode_PI_fx(Word32 code_index,Word16 sector_6p[],Word16 pulse_num); /*==========================================================================*/ @@ -714,7 +713,7 @@ static void fcb_decode_position_fx( return; } -static Word32 fcb_decode_PI_fx( /* o: return pulse position number */ +static void fcb_decode_PI_fx( /* o: return pulse position number */ Word32 code_index, /* i: fcb index information */ Word16 sector_6p[], /* o: decoded pulse position */ Word16 pulse_num /* i: pulse number for the track */ @@ -757,7 +756,7 @@ static Word32 fcb_decode_PI_fx( /* o: return pulse position number */ } } - return pulse_pos_num; + return ; } @@ -797,4 +796,239 @@ void D_ACELP_decode_43bit(UWord16 idxs[], Word16 code[], Word16 *pulsestrack) return; } +#ifdef IVAS_CODE_FCB + +/*-------------------------------------------------------* + * dec_1p_N1() + * + * Decode 1 pulse with N+1 bits + *-------------------------------------------------------*/ + +static void dec_1p_N1_L_subfr( + const int32_t index, /* i : quantization index */ + const int16_t nb_pos, /* i : number of positions */ + const int16_t N, /* i : nb. of bits */ + int16_t pos[] /* o : pulse position */ +) +{ + int16_t i, pos1; + int32_t mask; + + mask = ((1 << N) - 1); + pos1 = (int16_t)(index & mask); + i = (int16_t)(index >> N) & 1; + + if (i == 1) + { + pos1 += nb_pos; + } + + pos[0] = pos1; + + return; +} + +/*-------------------------------------------------------* + * add_pulses() + * + * Add decoded pulses to the codeword + *-------------------------------------------------------*/ + +static void add_pulses_L_subfr( + const int16_t nb_pos, /* i : number of positions */ + const int16_t pos[], /* i : pulse position */ + const int16_t nb_pulse, /* i : nb. of pulses */ + const int16_t track, /* i : no. of the tracks */ + float code[] /* i/o: decoded codevector */ +) +{ + int16_t i, k; + + for (k = 0; k < nb_pulse; k++) + { + i = ((pos[k] & (nb_pos - 1)) * NB_TRACK_FCB_4T) + track; + if ((pos[k] & nb_pos) == 0) + { + code[i] += 1.0f; + } + else + { + code[i] -= 1.0f; + } + } + + return; +} + +/*----------------------------------------------------------------------------------* + * dec_acelp_fast() + * + * fast algebraic codebook decoder + *----------------------------------------------------------------------------------*/ + +void dec_acelp_fast( + Decoder_State* st, /* i/o: decoder state structure */ + const int16_t cdk_index, /* i : codebook index */ + float code[], /* o : algebraic (fixed) codebook excitation */ + const int16_t L_subfr /* i : subframe length */ +) +{ + int16_t k, pos[7], skip_track; + int32_t L_index; + PulseConfig config; + + skip_track = -1; + set_f(code, 0.0f, L_subfr); + + if (L_subfr == L_SUBFR) + { + config = PulseConfTable[cdk_index]; + + if (cdk_index == 2) + { + dec_acelp_2t32(st, code); + } + else if (config.nb_pulse == 2) + { + /* 10 bits, 2 pulses, 4 tracks 1010 (used only even tracks) */ + for (k = 0; k < NB_TRACK_FCB_4T - 1; k += 2) + { + L_index = get_next_indice(st, 5); + dec_1p_N1(L_index, 4, 0, pos); + add_pulses(pos, 1, k, code); + } + } + else if (config.nb_pulse == 3) + { + if (config.codetrackpos == TRACKPOS_FIXED_FIRST) + { + /* 15 bits, 3 pulses, 4 tracks 1110 fixed track to first ? */ + for (k = 0; k < NB_TRACK_FCB_4T - 1; k++) + { + L_index = get_next_indice(st, 5); + dec_1p_N1(L_index, 4, 0, pos); + add_pulses(pos, 1, k, code); + } + } + else if (config.codetrackpos == TRACKPOS_FREE_THREE) + { + /* 17 bits, 3 pulses, 4 tracks (used all tracks) - 1110, 1101, 1011, 0111 */ + skip_track = get_next_indice(st, 2); + for (k = 0; k < NB_TRACK_FCB_4T; k++) + { + if (k != skip_track) + { + L_index = get_next_indice(st, 5); + dec_1p_N1(L_index, 4, 0, pos); + add_pulses(pos, 1, k, code); + } + } + } + } + else + { + if (config.bits == 20) + { + skip_track = -1; + } + else if (config.codetrackpos == TRACKPOS_FIXED_FIRST) + { + skip_track = 0; + } + else if (config.codetrackpos == TRACKPOS_FREE_ONE) + { + skip_track = get_next_indice(st, 2); + } + for (k = 0; k < NB_TRACK_FCB_4T; k++) + { + if (k == skip_track) + { + L_index = get_next_indice(st, 9); + dec_2p_2N1(L_index, 4, 0, pos); + add_pulses(pos, 2, k, code); + } + else + { + L_index = get_next_indice(st, 5); + dec_1p_N1(L_index, 4, 0, pos); + add_pulses(pos, 1, k, code); + } + } + } + } + else /* L_subfr == 2*L_SUBFR */ + { + config.bits = cdk_index; + + if (cdk_index == 14) + { + /* 14 bits, 2 pulses, 2 tracks: 11 (used all tracks) */ + int16_t index, i0, i1; + + index = get_next_indice(st, 14); + + i0 = ((index >> 7) & (NB_POS_FCB_2T_128 - 1)) * NB_TRACK_FCB_2T; + i1 = ((index & (NB_POS_FCB_2T_128 - 1)) * NB_TRACK_FCB_2T) + 1; + + code[i0] = -1.0f; + if ((index & 0x2000) == 0) + { + code[i0] = 1.0f; + } + + code[i1] = -1.0f; + if ((index & 0x40) == 0) + { + code[i1] = 1.0f; + } + } + else if (cdk_index == 12) + { + /* 12 bits, 2 pulses, 4 tracks: 1010 (used only even tracks) */ + for (k = 0; k < NB_TRACK_FCB_4T - 1; k += 2) + { + L_index = get_next_indice(st, 6); + dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); + add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + } + } + else if (cdk_index == 18) + { + /* 18 bits, 3 pulses, 4 tracks: 1110 (used first three tracks) */ + for (k = 0; k < NB_TRACK_FCB_4T - 1; k++) + { + L_index = get_next_indice(st, 6); + dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); + add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + } + } + else if (cdk_index == 20) + { + /* 20 bits, 3 pulses, 4 tracks (used all tracks): 1110, 1101, 1011, 0111 */ + skip_track = get_next_indice(st, 2); + for (k = 0; k < NB_TRACK_FCB_4T; k++) + { + if (k != skip_track) + { + L_index = get_next_indice(st, 6); + dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); + add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + } + } + } + else if (cdk_index == 24) + { + /* 24 bits, 4 pulses, 4 tracks: 1111 */ + for (k = 0; k < NB_TRACK_FCB_4T; k++) + { + L_index = get_next_indice(st, 6); + dec_1p_N1_L_subfr(L_index, NB_POS_FCB_4T_128, 5, pos); + add_pulses_L_subfr(NB_POS_FCB_4T_128, pos, 1, k, code); + } + } + } + + return; +} +#endif \ No newline at end of file diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index a80d389..f7716ae 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -4,13 +4,11 @@ #include -#include -#include +#include +#include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" -#include "options.h" -#include "stl.h" /* #if defined(_WIN32) && (_MSC_VER <= 1200) /\* disable global optimizations to overcome an internal compiler error *\/ */ #if defined(_MSC_VER) && (_MSC_VER <= 1200) /* disable global optimizations to overcome an internal compiler error */ @@ -20,22 +18,21 @@ /*-------------------------------------------------------------------* * decoder_LPD() * -* Core decoder +* Core decoder MODE2 *--------------------------------------------------------------------*/ void decoder_LPD( - Word16 signal_out[], /* output: signal with LPD delay (7 subfrs) */ - Word16 signal_outFB[], - Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ - Decoder_State_fx *st, - Word16 * bpf_noise_buf, - Word16 bfi, - Word16 *bitsRead, - Word16 *coder_type, - Word16 param[], - Word16 *pitch_buf, - Word16 *voice_factors, - Word16 *ptr_bwe_exc + Word16 signal_out[], /* output: signal with LPD delay (7 subfrs) */ + Word16 signal_outFB[], /* o : synthesis @output_FS */ + Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ + Decoder_State_fx *st, /* i/o: decoder memory state pointer */ + Word16 * bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 bfi, /* i : BFI flag */ + Word16 *bitsRead, /* o : number of read bits */ + Word16 param[], /* o : buffer of parameters */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *ptr_bwe_exc /* o : excitation for SWB TBE */ ) { Word16 *param_lpc; @@ -60,6 +57,13 @@ void decoder_LPD( Word32 lsp_diff; Word16 LSF_Q_prediction; Word16 tcx_last_overlap_mode, tcx_current_overlap_mode; + TD_BWE_DEC_HANDLE hBWE_TD; + TCX_DEC_HANDLE hTcxDec; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + + hBWE_TD = st->hBWE_TD; + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; st->core_fx = 0; /* to avoid compilation warnings */ prm = NULL; /* to avoid compilation warnings */ @@ -98,20 +102,20 @@ void decoder_LPD( /* Framing parameters */ L_frame = st->L_frame_fx; move16(); - L_frameTCX = st->L_frameTCX; + L_frameTCX = hTcxDec->L_frameTCX; move16(); nb_subfr = st->nb_subfr; move16(); /* Initialize pointers */ - synth = synth_buf + st->old_synth_len; + synth = synth_buf + hTcxDec->old_synth_len; /*st->old_synth: Q_0*/ - Copy(st->old_synth, synth_buf, st->old_synth_len); + Copy(hTcxDec->old_synth, synth_buf, hTcxDec->old_synth_len); set16_fx(synth, 0, L_FRAME_PLUS + M); - synthFB = synth_bufFB + st->old_synth_lenFB; - Copy(st->old_synthFB_fx, synth_bufFB, st->old_synth_lenFB); + synthFB = synth_bufFB + hTcxDec->old_synth_lenFB; + Copy(hTcxDec->old_synthFB_fx, synth_bufFB, hTcxDec->old_synth_lenFB); set16_fx(synthFB, 0, L_FRAME_PLUS + M); /*For post-processing (post-filtering+blind BWE)*/ @@ -141,20 +145,20 @@ void decoder_LPD( /* PLC: [TCX: Tonal Concealment] */ st->second_last_core = st->last_core_fx; move16(); - tcx_last_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode; + tcx_last_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; move16(); - tcx_current_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; + tcx_current_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); - dec_prm(coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead); + dec_prm(&st->coder_type_fx, param, param_lpc, total_nbbits, st, L_frame, bitsRead); IF(!st->rate_switching_init && EQ_16((st->last_codec_mode), MODE2)&&st->BER_detect) { - *coder_type = st->last_coder_type_fx; + st->coder_type_fx = st->last_coder_type_fx; move16(); st->last_core_fx = st->second_last_core; move16(); - st->tcx_cfg.tcx_last_overlap_mode = tcx_last_overlap_mode; + st->hTcxCfg->tcx_last_overlap_mode = tcx_last_overlap_mode; move16(); - st->tcx_cfg.tcx_curr_overlap_mode = tcx_current_overlap_mode; + st->hTcxCfg->tcx_curr_overlap_mode = tcx_current_overlap_mode; move16(); st->bfi_fx = 1; move16(); @@ -168,6 +172,7 @@ void decoder_LPD( move16(); st->core_fx = GetPLCModeDecision( st ); } + } ELSE { @@ -176,7 +181,7 @@ void decoder_LPD( test(); IF( st->use_partial_copy && GE_16(st->rf_frame_type, RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)) { - dec_prm( coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); + dec_prm( &st->coder_type_fx, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); } if (GT_16(st->nbLostCmpt, 1)) @@ -226,11 +231,11 @@ void decoder_LPD( test(); IF(EQ_16(st->use_partial_copy,1)&&(LT_16(st->rf_frame_type,RF_TCXFD)||GT_16(st->rf_frame_type,RF_TCXTD2))) { - IF( EQ_16((Word16)st->envWeighted,1)) + IF( EQ_16((Word16)hTcxDec->envWeighted,1)) { Copy( st->lspold_uw, st->lsp_old_fx, M ); Copy( st->lsfold_uw, st->lsf_old_fx, M ); - st->envWeighted = 0; + hTcxDec->envWeighted = 0; move16(); } @@ -283,8 +288,7 @@ void decoder_LPD( Copy( &lsf[(k+1)*M], &xsfnew_uw[k*M], M ); } } - ELSE - IF ((st->enableTcxLpc !=0 && NE_16(st->core_fx , ACELP_CORE))||(bfi&&st->use_partial_copy&&st->rf_frame_type==RF_TCXFD)) + ELSE IF ((hTcxDec->enableTcxLpc !=0 && NE_16(st->core_fx , ACELP_CORE))||(bfi&&st->use_partial_copy&&st->rf_frame_type==RF_TCXFD)) { Word16 tcx_lpc_cdk; IF(bfi && st->use_partial_copy && EQ_16(st->rf_frame_type, RF_TCXFD)) @@ -293,7 +297,7 @@ void decoder_LPD( } ELSE { - tcx_lpc_cdk = tcxlpc_get_cdk(*coder_type); /* inlined */ + tcx_lpc_cdk = tcxlpc_get_cdk(st->coder_type_fx); /* inlined */ } Copy(st->lsf_old_fx, &lsf[0], M); @@ -306,7 +310,7 @@ void decoder_LPD( lsf_update_memory( (Word16)st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); Copy(&lsf[M], st->mem_AR_fx, M); - st->envWeighted = 1; + hTcxDec->envWeighted = 1; move16(); E_LPC_lsp_unweight( &lsp[M], xspnew_uw, xsfnew_uw, st->inv_gamma, M ); @@ -314,26 +318,23 @@ void decoder_LPD( ELSE { - IF (st->envWeighted) + IF (hTcxDec->envWeighted) { Copy(st->lspold_uw, st->lsp_old_fx, M); Copy(st->lsfold_uw, st->lsf_old_fx, M); - st->envWeighted = 0; + hTcxDec->envWeighted = 0; move16(); } IF (EQ_16(st->core_fx, TCX_20_CORE)) { - lpc_unquantize( st, st->lsf_old_fx, st->lsp_old_fx, lsf, lsp, M, st->lpcQuantization, param_lpc, st->numlpc, st->core_fx, - st->mem_MA_fx, st->mem_AR_fx, lspmid, lsfmid, AUDIO, st->acelp_cfg.midLpc, st->narrowBand, &(st->seed_acelp), - st->sr_core, &st->mid_lsf_int_fx, st->prev_bfi_fx, &LSF_Q_prediction, &st->safety_net_fx ); + lpc_unquantize( st, lsf, lsp, M, param_lpc, lspmid, lsfmid, AUDIO, &LSF_Q_prediction); } ELSE { - lpc_unquantize( st, st->lsf_old_fx, st->lsp_old_fx, lsf, lsp, M, st->lpcQuantization, param_lpc, st->numlpc, st->core_fx, - st->mem_MA_fx, st->mem_AR_fx, lspmid, lsfmid, *coder_type, st->acelp_cfg.midLpc, st->narrowBand, &(st->seed_acelp), - st->sr_core, &st->mid_lsf_int_fx, st->prev_bfi_fx, &LSF_Q_prediction, &st->safety_net_fx ); + lpc_unquantize( st, lsf, lsp, M, param_lpc, lspmid, lsfmid, st->coder_type_fx, &LSF_Q_prediction); + IF(EQ_16(st->prev_use_partial_copy,1)&&EQ_16(st->last_core_fx,ACELP_CORE)&&EQ_16(st->core_fx,ACELP_CORE) - && GE_16(st->prev_rf_frame_type, RF_GENPRED) && EQ_16(*coder_type,UNVOICED) ) + && GE_16(st->prev_rf_frame_type, RF_GENPRED) && EQ_16(st->coder_type_fx, UNVOICED)) { IF ( st->lpcQuantization && st->acelp_cfg.midLpc ) { @@ -384,29 +385,12 @@ void decoder_LPD( Copy(st->lsp_old_fx, st->old_lsp_q_cng, M); } move16(); - xsfBase = PlcGetLsfBase (st->lpcQuantization, - (Word16)st->narrowBand, - st->sr_core); - - dlpc_bfi( st->L_frame_fx, - xsfnew_uw, - st->lsfold_uw, - st->last_good_fx, - st->nbLostCmpt, - st->mem_MA_fx, - st->mem_AR_fx, - &(st->stab_fac_fx), - st->lsf_adaptive_mean_fx, - st->numlpc, - st->lsf_cng, - st->plcBackgroundNoiseUpdated, - st->lsf_q_cng, - st->old_lsf_q_cng, - xsfBase, - st->tcxonly - ); - - st->envWeighted = 0; + xsfBase = PlcGetLsfBase (st->lpcQuantization, (Word16)st->narrowBand, st->sr_core); + + dlpc_bfi( st->L_frame_fx,xsfnew_uw,st->lsfold_uw,st->last_good_fx,st->nbLostCmpt,st->mem_MA_fx,st->mem_AR_fx, + &(st->stab_fac_fx), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, xsfBase, st->tcxonly); + + hTcxDec->envWeighted = 0; move16(); Copy( st->lspold_uw, lsp, M ); @@ -466,7 +450,7 @@ void decoder_LPD( test(); test(); test(); - IF( (st->prev_bfi_fx!=0) && (bfi==0) && (EQ_16(*coder_type,VOICED))&>_16(st->prev_nbLostCmpt,4)) + IF( (st->prev_bfi_fx!=0) && (bfi==0) && (EQ_16(st->coder_type_fx,VOICED))&>_16(st->prev_nbLostCmpt,4)) { st->dec_glr_idx = 1; move16(); @@ -535,7 +519,7 @@ void decoder_LPD( test(); test(); test(); - if ( EQ_16(st->clas_dec, UNVOICED_CLAS)||EQ_16(st->clas_dec,SIN_ONSET)||EQ_16(st->clas_dec,INACTIVE_CLAS)||EQ_16(*coder_type,GENERIC)||EQ_16(*coder_type,TRANSITION)) + IF ( EQ_16(st->clas_dec, UNVOICED_CLAS)||EQ_16(st->clas_dec,SIN_ONSET)||EQ_16(st->clas_dec,INACTIVE_CLAS)||EQ_16(st->coder_type_fx,GENERIC)||EQ_16(st->coder_type_fx,TRANSITION)) { st->relax_prev_lsf_interp_fx = 1; move16(); @@ -547,7 +531,7 @@ void decoder_LPD( test(); test(); test(); - if (st->stab_fac_fx == 0 && st->old_bfi_cnt_fx > 0 && NE_16(st->clas_dec, VOICED_CLAS)&&NE_16(st->clas_dec,ONSET)&&st->relax_prev_lsf_interp_fx==0) + IF (st->stab_fac_fx == 0 && st->old_bfi_cnt_fx > 0 && NE_16(st->clas_dec, VOICED_CLAS)&&NE_16(st->clas_dec,ONSET)&&st->relax_prev_lsf_interp_fx==0) { st->relax_prev_lsf_interp_fx = 2; move16(); @@ -566,8 +550,12 @@ void decoder_LPD( IF (bfi!=0 && st->last_core_fx != ACELP_CORE) { /* PLC: [TCX: TD PLC] */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + con_tcx(st, &synthFB[0], -1.f, NULL, 0, NULL); +#else con_tcx( st, &synthFB[0] ); - lerp( synthFB, synth, st->L_frame_fx, st->L_frameTCX ); +#endif + lerp( synthFB, synth, st->L_frame_fx, hTcxDec->L_frameTCX ); st->con_tcx = 1; move16(); set16_fx (st->mem_pitch_gain+2,round_fx(L_shl(st->Mode2_lp_gainp , 1)), st->nb_subfr); @@ -575,39 +563,31 @@ void decoder_LPD( ELSE { /* ACELP decoder */ - IF (EQ_16(st->L_frame_fx,L_FRAME)) + IF(hBWE_TD != NULL) { - Copy(Aq+2*(M+1), st->cur_sub_Aq_fx, (M+1)); - } - ELSE - { - Copy(Aq+3*(M+1), st->cur_sub_Aq_fx, (M+1)); + IF(EQ_16(st->L_frame_fx,L_FRAME)) + { + Copy(Aq + 2 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + } + ELSE + { + Copy(Aq + 3 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + } } IF ( bfi != 0 ) { /* PLC: [ACELP: general] * PLC: Use the ACELP like concealment */ - con_acelp(Aq, - st->core_ext_mode, - &synth[0], - pitch, - pit_gain, - st->stab_fac_fx, - st, - &st->Q_exc, - &st->Q_syn, /*Q format of st->mem_syn*/ - pitch_buf, - voice_factors, - ptr_bwe_exc - ); + con_acelp(Aq,st->core_ext_mode,&synth[0],pitch,pit_gain,st->stab_fac_fx,st, + &st->Q_exc, &st->Q_syn, /*Q format of st->mem_syn*/ pitch_buf, voice_factors, ptr_bwe_exc); Copy(&st->mem_pitch_gain[2], &st->mem_pitch_gain[st->nb_subfr+2], st->nb_subfr); set16_fx(&st->mem_pitch_gain[2],0,st->nb_subfr); } ELSE { - decoder_acelp(st, *coder_type, prm, Aq, st->acelp_cfg, &synth[0], - pitch, pit_gain, st->stab_fac_fx, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc); + decoder_acelp(st, prm, Aq, st->acelp_cfg, &synth[0], pitch, pit_gain, st->stab_fac_fx, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc); + IF(st->flagGuidedAcelp > 0) { st->guidedT0 = s_max(s_min(add(st->T0_4th, st->guidedT0), NBPSF_PIT_MAX), PIT_MIN_16k); @@ -627,7 +607,7 @@ void decoder_LPD( /* LPC for ACELP/BBWE */ test(); test(); - IF( st->narrowBand || (EQ_32(st->sr_core, 12800))||(EQ_32(st->sr_core,16000))) + IF( st->narrowBand || (EQ_32(st->sr_core, INT_FS_12k8))||(EQ_32(st->sr_core, INT_FS_16k))) { Copy(Aq, st->mem_Aq, nb_subfr*(M+1)); } @@ -640,7 +620,7 @@ void decoder_LPD( { st->second_last_tns_active = st->last_tns_active; st->last_tns_active = 0; - st->tcxltp_last_gain_unmodified = 0; + hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } @@ -670,7 +650,7 @@ void decoder_LPD( } } - IF (st->enableTcxLpc) + IF (hTcxDec->enableTcxLpc) { /* Convert quantized xSP to A */ E_LPC_f_lsp_a_conversion(&lsp[M], Aq, M); @@ -702,27 +682,13 @@ void decoder_LPD( } test(); - IF ( bfi == 0 && st->tcx_lpc_shaped_ari != 0 ) + IF ( bfi == 0 && hTcxDec->tcx_lpc_shaped_ari != 0 ) { E_LPC_f_lsp_a_conversion(lspind, Aind, M); } /* TCX decoder */ - decoder_tcx(&st->tcx_cfg, - prm, - Aq, - Aind, - L_frame, - L_frameTCX, - st->tcx_cfg.tcx_coded_lines, - &synth[0], - &synthFB[0], - st, - *coder_type, - bfi, - 0, - st->stab_fac_fx - ); + decoder_tcx(st->hTcxCfg,prm,Aq,Aind,L_frame,L_frameTCX,st->hTcxCfg->tcx_coded_lines,&synth[0],&synthFB[0],st, st->coder_type_fx, bfi,0,st->stab_fac_fx); } @@ -748,22 +714,9 @@ void decoder_LPD( /* TCX decoder */ - IGFDecRestoreTCX10SubFrameData( &st->hIGFDec, k ); - decoder_tcx(&st->tcx_cfg, - prm, - Aq, - Aind, - shr(L_frame, 1), - shr(L_frameTCX, 1), - shr(st->tcx_cfg.tcx_coded_lines, 1), - &synth[k*L_frame/2], - &synthFB[k*L_frameTCX/2], - st, - *coder_type, - bfi, - k, - st->stab_fac_fx - ); + IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k ); + decoder_tcx(st->hTcxCfg,prm,Aq,Aind,shr(L_frame, 1),shr(L_frameTCX, 1), + shr(st->hTcxCfg->tcx_coded_lines, 1),&synth[k*L_frame/2],&synthFB[k*L_frameTCX/2],st, st->coder_type_fx, bfi, k, st->stab_fac_fx ); } } @@ -802,14 +755,17 @@ void decoder_LPD( { TonalMDCTConceal_SaveTimeSignal( &st->tonalMDCTconceal, synthFB, L_frameTCX ); } +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + decoder_tcx_post(st, synth, synthFB, Aq, bfi, 0); +#else decoder_tcx_post( st, synth, synthFB, Aq, bfi ); - +#endif IF (EQ_16(st->core_fx, TCX_20_CORE)) { - /* LPC Interpolation for BBWE/post-processing */ + /* LPC Interpolation for BWE/post-processing */ test(); test(); - IF( st->narrowBand || (EQ_32(st->sr_core, 12800))||(EQ_32(st->sr_core,16000))) + IF( st->narrowBand || (EQ_32(st->sr_core, INT_FS_12k8))||(EQ_32(st->sr_core, INT_FS_16k))) { int_lsp_fx( L_frame, st->lspold_uw, xspnew_uw, Aq, M, interpol_frac_fx, 0 ); Copy(Aq, st->mem_Aq, nb_subfr*(M+1)); @@ -819,7 +775,7 @@ void decoder_LPD( /* PLC: [Common: Classification] */ - IF( LE_32( st->sr_core, 16000)) + IF( LE_32( st->sr_core, INT_FS_16k)) { test(); test(); @@ -840,9 +796,9 @@ void decoder_LPD( } LTP_Gain = -32768/*-1.0f Q15*/; - if(st->tcxltp) + if(hTcxLtpDec->tcxltp) { - LTP_Gain = st->tcxltp_last_gain_unmodified; + LTP_Gain = hTcxDec->tcxltp_last_gain_unmodified; move16(); } @@ -871,21 +827,22 @@ void decoder_LPD( LTP_Gain, /* i : means LTP Gain */ 1 /*CLASSIFIER_TCX*/, /* i : signal classifier mode */ bfi, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ + st->last_core_brate_fx, /* i : bitrate of previous frame */ + -1 ); } } /*--------------------------------------------------------------------------------* - * END + * Updates *--------------------------------------------------------------------------------*/ test(); IF( bfi && NE_16(st->last_core_bfi , ACELP_CORE)) { /* Update FEC_scale_syn parameters */ - IF(st->tcxltp_gain == 0) + IF(hTcxLtpDec->tcxltp_gain == 0) { frame_ener_fx( L_frame, UNVOICED_CLAS, synth, shr(L_frame,1), &st->enr_old_fx, L_frame, 0, 0, 0 ); } @@ -920,12 +877,11 @@ void decoder_LPD( /* Update */ - Copy(synth_buf+L_frame, st->old_synth, st->old_synth_len); - - Copy( st->old_synthFB_fx + L_frameTCX - NS2SA_fx2(st->output_Fs_fx, PH_ECU_MEM_NS), st->synth_history_fx, NS2SA_fx2(st->output_Fs_fx, PH_ECU_MEM_NS) ); - Copy(synth_bufFB+L_frameTCX, st->old_synthFB_fx, st->old_synth_lenFB); - Copy_Scale_sig( st->old_out_fx+NS2SA_fx2(st->output_Fs_fx, N_ZERO_MDCT_NS), st->old_synthFB_fx+st->old_synth_lenFB, NS2SA_fx2(st->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(st->Q_old_wtda)); + Copy(synth_buf+L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len); + Copy(hTcxDec->old_synthFB_fx + L_frameTCX - NS2SA_fx2(st->output_Fs_fx, PH_ECU_MEM_NS), hTcxDec->synth_history_fx, NS2SA_fx2(st->output_Fs_fx, PH_ECU_MEM_NS) ); + Copy(synth_bufFB+L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB); + Copy_Scale_sig( st->hHQ_core->old_out_fx+NS2SA_fx2(st->output_Fs_fx, N_ZERO_MDCT_NS), hTcxDec->old_synthFB_fx+ hTcxDec->old_synth_lenFB, NS2SA_fx2(st->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(st->hHQ_core->Q_old_wtda)); Copy(&xspnew_uw[(st->numlpc-1)*M], st->lspold_uw, M); Copy(&xsfnew_uw[(st->numlpc-1)*M], st->lsfold_uw, M); @@ -944,10 +900,10 @@ void decoder_LPD( Copy(st->lsf_q_cng, st->old_lsf_q_cng, M); /* Update LP_CNG parameters */ - IF( st->tcxonly == 0 ) + IF( st->tcxonly == 0 && st->hTdCngDec != NULL ) { /* update CNG parameters in active frames */ - IF (EQ_16(st->bwidth_fx,NB)&&st->enableTcxLpc!=0&&NE_16(st->core_fx,ACELP_CORE)) + IF (EQ_16(st->bwidth_fx,NB)&& hTcxDec->enableTcxLpc!=0&&NE_16(st->core_fx,ACELP_CORE)) { Word16 buf[L_LP], res[L_FRAME], A[M+1], Qexc, r_l[M+1], r_h[M+1], lsptmp[M], Q_r, tmp; @@ -960,24 +916,24 @@ void decoder_LPD( E_LPC_lev_dur(r_h, r_l, A, NULL, M, NULL); E_LPC_a_lsp_conversion(A, lsptmp, &xspnew_uw[0], M); Residu3_fx(A, buf+L_LP-L_FRAME, res, L_FRAME, 1); - cng_params_upd_fx( lsptmp, res, st->L_frame_fx, &st->ho_circ_ptr_fx, - st->ho_ener_circ_fx, &st->ho_circ_size_fx, st->ho_lsp_circ_fx, - Qexc, DEC, st->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate_fx ); + cng_params_upd_fx( lsptmp, res, st->L_frame_fx, &st->hTdCngDec->ho_circ_ptr_fx, + st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size_fx, st->hTdCngDec->ho_lsp_circ_fx, + Qexc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate_fx ); } ELSE { cng_params_upd_fx( &lsp[M], st->old_exc_fx+L_EXC_MEM_DEC-st->L_frame_fx, - st->L_frame_fx, &st->ho_circ_ptr_fx, st->ho_ener_circ_fx, - &st->ho_circ_size_fx, st->ho_lsp_circ_fx, st->Q_exc, DEC, - st->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate_fx ); + st->L_frame_fx, &st->hTdCngDec->ho_circ_ptr_fx, st->hTdCngDec->ho_ener_circ_fx, + &st->hTdCngDec->ho_circ_size_fx, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, + st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate_fx ); } /* Set 16k LSP flag for CNG buffer */ - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 1; + st->hTdCngDec->ho_16k_lsp_fx[st->hTdCngDec->ho_circ_ptr_fx] = 1; move16(); if ( EQ_16(st->L_frame_fx,L_FRAME)) { - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 0; + st->hTdCngDec->ho_16k_lsp_fx[st->hTdCngDec->ho_circ_ptr_fx] = 0; move16(); } } @@ -986,14 +942,7 @@ void decoder_LPD( st->last_is_cng = 0; /* Postfiltering */ - post_decoder( st, - *coder_type, - synth_buf, - pit_gain, - pitch, - signal_out, - bpf_noise_buf - ); + post_decoder( st, synth_buf, pit_gain, pitch, signal_out, bpf_noise_buf); IF( signal_outFB ) { diff --git a/lib_dec/dec_ace.c b/lib_dec/dec_ace.c index 5ae1ee7..80248af 100644 --- a/lib_dec/dec_ace.c +++ b/lib_dec/dec_ace.c @@ -4,7 +4,7 @@ /*BASOp version info: This file is up to date with trunk rev. 39929 */ -#include +#include #include #include #include "options.h" @@ -15,12 +15,11 @@ /*-------------------------------------------------------------------* * decoder_acelp() * - * Decode ACELP frame + * Decode ACELP frame MODE2 *-------------------------------------------------------------------*/ void decoder_acelp( Decoder_State_fx *st, - Word16 coder_type, /* i : coder type */ Word16 prm[], /* i : parameters */ Word16 A[], /* i : coefficients NxAz[M+1] */ ACELP_config acelp_cfg, /* i : ACELP config */ @@ -76,7 +75,11 @@ void decoder_acelp( Word32 gain_code_pre; Word16 avoid_lpc_burst_on_recovery; Word16 force_scale_syn; + TD_BWE_DEC_HANDLE hBWE_TD; + TCX_DEC_HANDLE hTcxDec; + hBWE_TD = st->hBWE_TD; + hTcxDec = st->hTcxDec; gain_code_pre = 0; move16(); @@ -207,7 +210,7 @@ void decoder_acelp( * Fast recovery flag *------------------------------------------------------------------------*/ test(); - if(st->prev_bfi_fx && EQ_16(coder_type,VOICED)) + if(st->prev_bfi_fx && EQ_16(st->coder_type_fx,VOICED)) { /*Force BPF to be applied fully*/ st->bpf_gain_param=3; @@ -253,8 +256,7 @@ void decoder_acelp( { IF( i_subfr == 0 ) { - decod_nelp_fx( st, UNVOICED, &tmp_noise, dummy_pitch_buf, exc, exc2, voice_factors, bwe_exc, &st->Q_exc, st->bfi_fx, pgainT ); - + decod_nelp_fx( st, &tmp_noise, dummy_pitch_buf, exc, exc2, voice_factors, bwe_exc, &st->Q_exc, st->bfi_fx, pgainT ); set32_fx(pitch_buf, L_SUBFR_Q16, NB_SUBFR); set16_fx(pitch_buffer, 4096, NB_SUBFR); /* L_SUBFR_Q16 in Q6 */ } @@ -274,33 +276,9 @@ void decoder_acelp( IF ( acelp_cfg.ltp_bits != 0 ) { - /*if( st->use_partial_copy - && st->rf_frame_type == RF_GENPRED - && ( i_subfr == L_SUBFR || i_subfr == 3*L_SUBFR ) ) - { - *pt_pitch = (float)T0 + (float)T0_frac/(float)T0_res; - } - else*/ - { /* pitch lag decoding */ - pitch_buf[i_subfr/L_SUBFR] = Mode2_pit_decode( acelp_cfg.ltp_mode, - i_subfr, - L_SUBFR, - &prm, - &T0, - &T0_frac, - &T0_res, - &T0_min, - &T0_min_frac, - &T0_max, - &T0_max_frac, - st->pit_min, - st->pit_fr1, - st->pit_fr1b, - st->pit_fr2, - st->pit_max, - st->pit_res_max); - } + pitch_buf[i_subfr/L_SUBFR] = Mode2_pit_decode( acelp_cfg.ltp_mode, i_subfr, L_SUBFR, &prm, &T0, &T0_frac, &T0_res, + &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max); /* find pitch excitation */ test(); IF( EQ_16(st->pit_res_max,6)&&!(st->use_partial_copy)) @@ -337,7 +315,7 @@ void decoder_acelp( prm++; } - lp_filt_exc_dec_fx( st, MODE2, st->core_brate_fx, 0, coder_type, i_subfr, L_SUBFR, st->L_frame_fx, lp_flag, exc ); + lp_filt_exc_dec_fx(st, MODE2, i_subfr, L_SUBFR, st->L_frame_fx, lp_flag, exc); } ELSE @@ -382,7 +360,7 @@ void decoder_acelp( *-------------------------------------------------------*/ cb_shape_fx( acelp_cfg.pre_emphasis, acelp_cfg.pitch_sharpening, acelp_cfg.phase_scrambling, acelp_cfg.formant_enh, acelp_cfg.formant_tilt, - acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code_fx, extract_h(L_add(pitch_buf[i_subfr/L_SUBFR],26216)), 1 ); + acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code_fx, extract_h(L_add(pitch_buf[i_subfr/L_SUBFR],26216)), 1, L_SUBFR); } /*-------------------------------------------------------* * - Generate Gaussian excitation * @@ -403,22 +381,17 @@ void decoder_acelp( *-------------------------------------------------*/ IF( st->acelp_cfg.gains_mode[i_subfr/L_SUBFR] != 0 ) { - decode_acelp_gains( code, - acelp_cfg.gains_mode[i_subfr/L_SUBFR], - Es_pred, - &gain_pit, - &gain_code, - &prm, - &(st->past_gpit), - &(st->past_gcode), - &gain_inov, - L_SUBFR, - code2, - &gain_code2 - ); + decode_acelp_gains( code, acelp_cfg.gains_mode[i_subfr/L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &(st->past_gpit), + &(st->past_gcode), &gain_inov, L_SUBFR, code2, &gain_code2 ); + } + IF(st->use_partial_copy&& st->rf_frame_type == RF_ALLPRED) + { + st->past_gcode = 0; + } + IF(st->use_partial_copy&& st->rf_frame_type == RF_NOPRED) + { + st->past_gpit = 67; } - IF(st->use_partial_copy && st->rf_frame_type == RF_ALLPRED) st->past_gcode = 0; - IF(st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) st->past_gpit = 67; IF( st->igf != 0 ) { /* Rescaling for 12.8k and 16k cores related to BWE */ @@ -449,18 +422,7 @@ void decoder_acelp( * Update parameters for the next subframe. * * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced) * *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc, - i_subfr, - code, - gain_pit, - gain_code, - &(st->voice_fac), - &(st->tilt_code_fx), - L_SUBFR, - acelp_cfg.voice_tilt, - st->Q_exc, - 0 - ); + E_UTIL_voice_factor( exc, i_subfr, code, gain_pit, gain_code, &(st->voice_fac), &(st->tilt_code_fx), L_SUBFR, acelp_cfg.voice_tilt, st->Q_exc, 0); pgainT[i_subfr/L_SUBFR] = gain_pit; move16(); @@ -521,43 +483,24 @@ void decoder_acelp( gain_pit = gain_pit_tmp; IF( st->igf != 0 ) { - prep_tbe_exc_fx( st->L_frame_fx, - i_subfr, - gain_pit, - gain_code, - code, - st->voice_fac, - &voice_factors[i_subfr/L_SUBFR], - bwe_exc, - gain_preQ, - code_preQ, - st->Q_exc, - T0, - T0_frac, - coder_type, - st->core_brate_fx); + prep_tbe_exc_fx( st->L_frame_fx, +#ifdef ADD_IVAS_TBE_CODE + L_SUBFR, +#endif + i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[i_subfr/L_SUBFR], bwe_exc, + gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type_fx, st->core_brate_fx +#ifdef ADD_IVAS_TBE_CODE + , st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 +#endif + ); } /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ - E_UTIL_enhancer( st->voice_fac, - stab_fac, - st->past_gcode, - gain_inov, - &(st->gc_threshold_fx), - code, - &exc2[i_subfr], - gain_pit, - &st->dm_fx.prev_gain_code, - st->dm_fx.prev_gain_pit, - &st->dm_fx.prev_state, - coder_type, - acelp_cfg.fixed_cdk_index[i_subfr/L_SUBFR], - L_SUBFR, - st->L_frame_fx, - st->Q_exc - ); + E_UTIL_enhancer( st->voice_fac, stab_fac, st->past_gcode, gain_inov, &(st->gc_threshold_fx), code, &exc2[i_subfr], + gain_pit, & st->dm_fx.prev_gain_code, st->dm_fx.prev_gain_pit, & st->dm_fx.prev_state, st->coder_type_fx, + acelp_cfg.fixed_cdk_index[i_subfr/L_SUBFR], L_SUBFR, st->L_frame_fx, st->Q_exc ); } /* !RF_NELP frame partial copy */ /*----------------------------------------------------------* @@ -643,32 +586,10 @@ void decoder_acelp( pit16[k] = shl(extract_h(pitch_buf[k]),6);/*Q6*/ } - FEC_clas_estim_fx( - st, - /*Opt_AMR_WB*/0, /*A*/ - st->L_frame_fx, - &(st->clas_dec), - st->core_ext_mode, - pit16, - syn, - &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - st->Q_syn, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ - &st->classifier_Q_mem_syn, /* i/o: exponent for memory of synthesis signal for frame class estimation */ - -32768/*-1.f Q15*/, /* i : LTP Gain */ - 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ - 0/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ - ); + FEC_clas_estim_fx(st, /*Opt_AMR_WB*/0, st->L_frame_fx, &(st->clas_dec), st->core_ext_mode, pit16, syn, + &st->lp_ener_FER_fx, /**decision_hyst*/NULL, /**UV_cnt*/ NULL, /**LT_UV_cnt*/ NULL, /**Last_ener*/ NULL, /**locattack*/ NULL, + /**lt_diff_etot*/NULL, /**amr_io_class*/ NULL, /*bitrate*/ 0 , st->Q_syn, /**class_para*/ NULL, st->mem_syn_clas_estim_fx, + &st->classifier_Q_mem_syn, -32768/*-1.f Q15*/, 0/*CLASSIFIER_ACELP*/, 0/*bfi*/, st->last_core_brate_fx, -1); } /* Update Pitch Lag memory */ @@ -698,34 +619,9 @@ void decoder_acelp( move16(); } - FEC_scale_syn_fx( st->L_frame_fx, - &update_flg, - st->clas_dec, - st->last_good_fx, - syn, - pBuf_scaleSyn, - st->enr_old_fx, - 0, - coder_type, - LSF_Q_prediction, - &st->scaling_flag, - &st->lp_ener_FEC_av, - &st->lp_ener_FEC_max, - st->bfi_fx, - st->total_brate_fx, - st->prev_bfi_fx, - st->last_core_brate_fx, - exc, - exc2, - A, - &(st->old_enr_LP), - mem_back, - mem_syn, - st->Q_exc, - st->Q_syn - , avoid_lpc_burst_on_recovery - , force_scale_syn - ); + FEC_scale_syn_fx( st->L_frame_fx, &update_flg,st->clas_dec, st->last_good_fx, syn, pBuf_scaleSyn, st->enr_old_fx, 0, + st->coder_type_fx, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi_fx, st->total_brate_fx, st->prev_bfi_fx, st->last_core_brate_fx, + exc, exc2, A, &(st->old_enr_LP), mem_back, mem_syn, st->Q_exc, st->Q_syn , avoid_lpc_burst_on_recovery , force_scale_syn); } /* update ACELP synthesis memory */ Copy( mem_syn, st->mem_syn2_fx, M ); @@ -736,13 +632,15 @@ void decoder_acelp( move16(); E_UTIL_deemph2(st->Q_syn, syn, st->preemph_fac, st->L_frame_fx, &tmp_deemph); /* tmp_deemph and syn in Q0 starting from here*/ - bufferCopyFx(syn+st->L_frame_fx- st->L_frame_fx/2, st->old_syn_Overl, shr(st->L_frame_fx, 1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); + bufferCopyFx(syn+st->L_frame_fx- st->L_frame_fx/2, hTcxDec->old_syn_Overl, shr(st->L_frame_fx, 1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); Copy(syn+st->L_frame_fx-M-1, st->syn, 1+M); /*Q0*/ Copy(syn, synth, st->L_frame_fx); - - Copy( syn, st->old_core_synth_fx, st->L_frame_fx ); + IF (st->hBWE_TD != NULL) + { + Copy(syn, hBWE_TD->old_core_synth_fx, st->L_frame_fx); + } /* update old_Aq */ @@ -755,15 +653,15 @@ void decoder_acelp( } - st->tcxltp_last_gain_unmodified = 0; + hTcxDec->tcxltp_last_gain_unmodified = 0; /*Update MODE1*/ Copy( p_A-(M+1), st->old_Aq_12_8_fx, M+1 ); st->old_Es_pred_fx = Es_pred; - st->tcxltp_third_last_pitch = st->tcxltp_second_last_pitch; - st->tcxltp_second_last_pitch = st->old_fpitch; - st->old_fpitch = pitch_buf[(st->L_frame_fx/L_SUBFR) - 1]; + hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; + hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; + st->old_fpitch = pitch_buf[shr(st->L_frame_fx, 6) - 1]; move32(); diff --git a/lib_dec/dec_acelp.c b/lib_dec/dec_acelp.c index ef015c7..0dbe7d4 100644 --- a/lib_dec/dec_acelp.c +++ b/lib_dec/dec_acelp.c @@ -2,9 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include #include -#include "stl.h" +#include "options.h" #include "basop_util.h" #include "prot_fx.h" #include "rom_com_fx.h" @@ -13,6 +14,9 @@ #define _1_CODE 0x200 /*codebook excitation Q9 */ +/*---------------------------------------------------------------------* + * Local function prototypes + *---------------------------------------------------------------------*/ static void D_ACELP_decode_arithtrack(Word16 v[], Word32 s, Word16 p, Word16 trackstep, Word16 tracklen); /*---------------------------------------------------------------------* diff --git a/lib_dec/dec_acelp_tcx_main.c b/lib_dec/dec_acelp_tcx_main.c index dcdfe80..f714bdf 100644 --- a/lib_dec/dec_acelp_tcx_main.c +++ b/lib_dec/dec_acelp_tcx_main.c @@ -3,16 +3,20 @@ ====================================================================================*/ +#include #include +#include "options.h" #include "rom_com_fx.h" #include "stat_com.h" -#include "options.h" -#include "stl.h" #include "prot_fx.h" #include "basop_util.h" static -void decode_frame_type(Decoder_State_fx *st) +void decode_frame_type(Decoder_State_fx *st +#ifdef IVAS_CODE_CNG + , STEREO_CNG_DEC_HANDLE hStereoCng +#endif +) { Word32 L_tmp; Word16 num_bits; @@ -90,18 +94,18 @@ void decode_frame_type(Decoder_State_fx *st) IF ( frame_len_indicator == 0 ) { st->L_frame_fx = L_FRAME; - st->total_brate_fx = 9600; + st->total_brate_fx = ACELP_9k60; } ELSE { st->L_frame_fx = L_FRAME16k; - IF ( st->last_total_brate_fx==16400 || st->last_total_brate_fx==24400 ) + IF ( st->last_total_brate_fx== ACELP_16k40 || st->last_total_brate_fx== ACELP_24k40) { st->total_brate_fx = st->last_total_brate_fx; } ELSE { - st->total_brate_fx = 16400; + st->total_brate_fx = ACELP_16k40; } } @@ -199,8 +203,11 @@ void decode_frame_type(Decoder_State_fx *st) move16(); /* Reconf Core */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + mode_switch_decoder_LPD(st, st->bwidth_fx, st->total_brate_fx, st->last_total_brate_fx, frame_size_index, 0, st->element_mode); +#else mode_switch_decoder_LPD( st, st->bwidth_fx, st->total_brate_fx, frame_size_index ); - +#endif /* Reconf CLDFB */ IF( NE_16 (i_mult(st->cldfbAna_fx->no_channels,st->cldfbAna_fx->no_col), st->L_frame_fx) ) { @@ -230,17 +237,19 @@ void decode_frame_type(Decoder_State_fx *st) L_tmp = ACELP_9k60; move32(); } - configureFdCngDec( st->hFdCngDec_fx, st->bwidth_fx, L_tmp, st->L_frame_fx ); + configureFdCngDec( st->hFdCngDec_fx, st->bwidth_fx, L_tmp, st->L_frame_fx, st->last_L_frame_fx, st->element_mode); test(); test(); - IF ( (NE_16(st->last_L_frame_fx,st->L_frame_fx))&&(LE_16(st->L_frame_fx,320))&&(LE_16(st->last_L_frame_fx,320))) + IF ( (NE_16(st->last_L_frame_fx,st->L_frame_fx))&&(LE_16(st->L_frame_fx, L_FRAME16k))&&(LE_16(st->last_L_frame_fx, L_FRAME16k))) { lerp( st->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st->L_frame_fx*2, st->last_L_frame_fx*2 ); test(); IF ( EQ_16(st->m_frame_type, SID_FRAME)&&NE_16(st->hFdCngDec_fx->hFdCngCom->frame_type_previous,ACTIVE_FRAME)) { lerp( st->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st->L_frame_fx*2, st->last_L_frame_fx*2 ); - +#ifdef IVAS_CODE_CNG + lerp(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2); +#endif IF( EQ_16(st->L_frame_fx, L_FRAME)) { FOR( n=0; n < st->L_frame_fx*2; n++ ) @@ -277,27 +286,32 @@ void decode_frame_type(Decoder_State_fx *st) } -Word16 dec_acelp_tcx_frame(Decoder_State_fx *st, - Word16 *coder_type, - Word16 *concealWholeFrame, - Word16 *pcmBuf, - Word16 * bpf_noise_buf, - Word16 * pcmbufFB, - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[] /* o : floating pitch for each subframe */ +Word16 dec_acelp_tcx_frame( + Decoder_State_fx *st, /* i/o: decoder state structure */ + Word16* concealWholeFrame, /* i/o: concealment flag */ + Word16* pcmBuf, /* o : synthesis */ + Word16* bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16* pcmbufFB, /* o : synthesis @output_FS */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16* voice_factors, /* o : voicing factors */ + Word16 pitch_buf[] /* o : floating pitch for each subframe */ +#ifdef IVAS_CODE_CNG + , STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ +#endif ) { - Word16 num_bits; - Word32 L_tmp; - UWord16 lsb; - Word16 bitsRead; - Word16 tmp; - Word16 i; - Word16 start_bit_pos; - Word16 param[DEC_NPRM_DIV*NB_DIV+NPRM_LPC_NEW]; - Word16 old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ - Word16 *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */ + Word16 num_bits; + Word32 L_tmp; + UWord16 lsb; + Word16 bitsRead; + Word16 tmp; + Word16 i; + Word16 start_bit_pos; + Word16 param[DEC_NPRM_DIV*NB_DIV+NPRM_LPC_NEW]; + Word16 old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ + Word16 *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */ + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st->hBWE_TD; Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ @@ -330,7 +344,11 @@ Word16 dec_acelp_tcx_frame(Decoder_State_fx *st, Word16 L_frame = st->L_frame_fx; Word32 total_brate = st->last_total_brate_fx; - decode_frame_type( st ); + decode_frame_type( st +#ifdef IVAS_CODE_CNG + , hStereoCng +#endif + ); st->force_lpd_reset = 0; @@ -375,9 +393,9 @@ Word16 dec_acelp_tcx_frame(Decoder_State_fx *st, move32(); st->bfi_fx = 1; move16(); - IF(st->ini_frame_fx == 0 ) + IF(st->ini_frame_fx == 0 && st->hTcxCfg != NULL ) { - st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(SWB); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(SWB); } } ELSE @@ -412,23 +430,11 @@ Word16 dec_acelp_tcx_frame(Decoder_State_fx *st, set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2; - Copy( st->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); IF ( EQ_16(st->m_decodeMode, DEC_NO_FRAM_LOSS)) { - decoder_LPD(pcmBuf, - pcmbufFB, - &tmp, - st, - bpf_noise_buf, - 0, - &bitsRead, - coder_type, - param, - pitch_buf, - voice_factors, - ptr_bwe_exc - ); + decoder_LPD(pcmBuf, pcmbufFB, &tmp, st, bpf_noise_buf, 0, &bitsRead, param, pitch_buf, voice_factors, ptr_bwe_exc ); test(); test(); @@ -449,48 +455,36 @@ Word16 dec_acelp_tcx_frame(Decoder_State_fx *st, ELSE IF (EQ_16(st->m_decodeMode, DEC_CONCEALMENT_EXT)) { /* Decode the LPD data */ - decoder_LPD( pcmBuf, - pcmbufFB, - NULL, - st, - bpf_noise_buf, - 1, - &bitsRead, - coder_type, - NULL, - pitch_buf, - voice_factors, - ptr_bwe_exc - ); + decoder_LPD( pcmBuf, pcmbufFB, NULL, st, bpf_noise_buf, 1, &bitsRead, NULL, pitch_buf, voice_factors, ptr_bwe_exc ); } test(); test(); test(); test(); - IF( ( st->bfi_fx == 0 && (EQ_16(st->prev_bfi_fx, 1)||EQ_16(st->prev_use_partial_copy,1)))||((EQ_16(st->last_vbr_hw_BWE_disable_dec_fx,1))&&(st->vbr_hw_BWE_disable_dec_fx==0))) - { - st->bwe_non_lin_prev_scale_fx = 0; - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - - test(); - test(); - IF( st->core_fx == ACELP_CORE && st->igf != 0 && st->con_tcx == 0) + if (st->hBWE_TD != NULL) { - non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale_fx, st->Q_exc, - *coder_type, voice_factors, st->L_frame_fx - ); + IF((st->bfi_fx == 0 && (EQ_16(st->prev_bfi_fx, 1) || EQ_16(st->prev_use_partial_copy, 1))) || ((EQ_16(st->last_vbr_hw_BWE_disable_dec_fx, 1)) && (st->vbr_hw_BWE_disable_dec_fx == 0))) + { + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); + } - /* update the old BWE exe memory */ - Copy( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc_fx, PIT16k_MAX * 2 ); - } - ELSE - { - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - set16_fx( st->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st->bwe_non_lin_prev_scale_fx = 0; - move32(); + test(); + test(); + IF(st->core_fx == ACELP_CORE && st->igf != 0 && st->con_tcx == 0) + { + non_linearity_fx(ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type_fx, voice_factors, st->L_frame_fx); + /* update the old BWE exe memory */ + Copy(&old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2); + } + ELSE + { + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + } } /* for ACELP mode, skip core data to read TD-BWE side info */ @@ -514,8 +508,7 @@ Word16 dec_acelp_tcx_frame(Decoder_State_fx *st, /* updates */ st->last_voice_factor_fx = voice_factors[st->nb_subfr-1];; move16(); - st->last_coder_type_fx = *coder_type; - + st->last_coder_type_fx = st->coder_type_fx; } ELSE { diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index 60e4078..96dc0fa 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*---------------------------------------------------------------------* @@ -16,14 +16,14 @@ *---------------------------------------------------------------------*/ void decod_amr_wb_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ + Decoder_State_fx *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* i : LP filter coefficients */ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ Word16 *exc_fx, /* i/o: adapt. excitation exc */ Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *gain_buf /* o : Q14 */ + Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ @@ -38,6 +38,11 @@ void decod_amr_wb_fx( Word16 i_subfr; /* tmp variables */ Word16 pitch_limit_flag; Word32 L_Voice_fac_ave, L_tmp; + Word16 lp_flag; + AMRWB_IO_DEC_HANDLE hAmrwb_IO; + hAmrwb_IO = st_fx->hAmrwb_IO; + MUSIC_POSTFILT_HANDLE hMusicPF; + hMusicPF = st_fx->hMusicPF; /*------------------------------------------------------------------* * Initializations @@ -49,6 +54,13 @@ void decod_amr_wb_fx( pitch_limit_flag = 0; move16(); /* always restrained pitch Q range in IO mode */ + lp_flag = NORMAL_OPERATION; + move16(); /* always restrained pitch Q range in IO mode */ + IF (LT_32(st_fx->core_brate_fx, ACELP_11k60) ) + { + lp_flag = LOW_PASS; + move16(); /* always restrained pitch Q range in IO mode */ + } /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ @@ -59,7 +71,11 @@ void decod_amr_wb_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate_fx, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); + *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate_fx, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR +#ifdef ADD_LRTD + , 0 , NULL +#endif + ); /*--------------------------------------------------------------* * Find the adaptive codebook vector @@ -71,27 +87,26 @@ void decod_amr_wb_fx( * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx( st_fx, MODE1, st_fx->core_brate_fx, 1, -1, i_subfr, L_SUBFR, L_FRAME, 0, exc_fx ); - + lp_filt_exc_dec_fx(st_fx, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc_fx); /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - inov_decode_fx( st_fx, st_fx->core_brate_fx, 1, L_FRAME, -1, 0, i_subfr, -1, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx); + inov_decode_fx( st_fx, st_fx->core_brate_fx, 1, L_FRAME, 0, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_amr_wb_fx( st_fx, st_fx->core_brate_fx, &gain_pit_fx, &L_gain_code_fx, st_fx->past_qua_en_fx, &gain_inov_fx, code_fx, &L_norm_gain_code_fx ); + gain_dec_amr_wb_fx( st_fx, st_fx->core_brate_fx, &gain_pit_fx, &L_gain_code_fx, hAmrwb_IO->past_qua_en_fx, &gain_inov_fx, code_fx, &L_norm_gain_code_fx ); /* update LP filtered gains for the case of frame erasures */ lp_gain_updt_fx( i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->last_exc_dct_in_fx, L_SUBFR, 0, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, 0, L_gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, -1 ); gain_code16 = round_fx(L_shl(L_gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ @@ -100,7 +115,7 @@ void decod_amr_wb_fx( * Find the total excitation *----------------------------------------------------------------------*/ - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx ); + Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR); /*----------------------------------------------------------------* * Excitation enhancements @@ -133,7 +148,7 @@ void decod_amr_wb_fx( gain_buf[i_subfr/L_SUBFR] = gain_pit_fx; } - st_fx->lt_voice_fac_fx = round_fx(L_Voice_fac_ave); + hAmrwb_IO->lt_voice_fac_fx = round_fx(L_Voice_fac_ave); return; } diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 99aeced..721d0b1 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -22,7 +22,6 @@ /* _ (Word16) L_frame_fx : length of the frame */ /* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type_fx : coding type Q12 */ /* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ /* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ @@ -38,12 +37,11 @@ /* _ None */ /*======================================================================*/ -void decod_gen_voic_fx( +ivas_error decod_gen_voic_fx( Decoder_State_fx *st_fx, /* i/o: decoder static memory */ const Word16 L_frame_fx, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ @@ -105,8 +103,14 @@ void decod_gen_voic_fx( Word16 pf_temp2[MAXLAG_WI]; Word16 pf_temp[MAXLAG_WI]; Word16 pf_n2[MAXLAG_WI]; + MUSIC_POSTFILT_HANDLE hMusicPF; + hMusicPF = st_fx->hMusicPF; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; + ivas_error error; + error = IVAS_ERR_OK; T0_fx = PIT_MIN; move16(); @@ -118,7 +122,7 @@ void decod_gen_voic_fx( move16(); test(); test(); - IF( (GT_32(st_fx->core_brate_fx,ACELP_24k40)&&LE_32(st_fx->core_brate_fx,ACELP_32k))&&EQ_16(coder_type_fx,GENERIC)) + IF( (GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC)&&LE_32(st_fx->core_brate_fx, MAX_BRATE_AVQ_EXC_TD))&&EQ_16(st_fx->coder_type_fx,GENERIC)) { harm_flag_acelp = (Word16)get_next_indice_fx( st_fx, 1 ); } @@ -143,7 +147,7 @@ void decod_gen_voic_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, i_subfr_fx, coder_type_fx, &pitch_limit_flag_fx, + *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, i_subfr_fx, st_fx->coder_type_fx, &pitch_limit_flag_fx, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR ); move16(); /*Q6*/ @@ -158,28 +162,24 @@ void decod_gen_voic_fx( /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ - - lp_filt_exc_dec_fx( st_fx, MODE1, st_fx->core_brate_fx, 0, coder_type_fx, i_subfr_fx, L_SUBFR, L_frame_fx, 0, exc_fx ); - + lp_filt_exc_dec_fx(st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame_fx, st_fx->acelp_cfg.ltf_mode, exc_fx); /*-----------------------------------------------------------------* * Transform-domain contribution decoding (active frames) *-----------------------------------------------------------------*/ test(); - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)&&NE_16(coder_type_fx,INACTIVE)) + IF( GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC)&&NE_16(st_fx->coder_type_fx,INACTIVE)) { gain_code_fx = 0; move16(); - transf_cdbk_dec_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, harm_flag_acelp, i_subfr_fx, -1, Es_pred_fx, gain_code_fx, &st_fx->mem_preemp_preQ_fx, - &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); + transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ - inov_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, coder_type_fx, - sharpFlag_fx, i_subfr_fx, -1, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx ); + inov_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); /*--------------------------------------------------------------* * Gain decoding @@ -188,15 +188,15 @@ void decod_gen_voic_fx( IF( LE_32(st_fx->core_brate_fx,ACELP_8k00)) { - gain_dec_lbr_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem ); + gain_dec_lbr_fx( st_fx, st_fx->coder_type_fx, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR); } ELSE IF( GT_32(st_fx->core_brate_fx,ACELP_32k)) { - gain_dec_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); + gain_dec_SQ_fx( st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } ELSE { - gain_dec_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type_fx, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); + gain_dec_mless_fx( st_fx, L_frame_fx, st_fx->coder_type_fx, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); @@ -204,10 +204,9 @@ void decod_gen_voic_fx( * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GT_32( st_fx->core_brate_fx,ACELP_24k40)&&EQ_16(coder_type_fx,INACTIVE)) + IF( GE_32( st_fx->core_brate_fx, MAX_GSC_INACTIVE_BRATE) && EQ_16(st_fx->coder_type_fx,INACTIVE)) { - transf_cdbk_dec_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, harm_flag_acelp, i_subfr_fx, -1, Es_pred_fx, gain_code_fx, &st_fx->mem_preemp_preQ_fx, - &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); + transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } /* update LP filtered gains for the case of frame erasures */ @@ -219,15 +218,15 @@ void decod_gen_voic_fx( IF ( EQ_16(L_frame_fx,L_FRAME)) /* Rescaling for 12.8k core */ { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, coder_type_fx ); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type_fx ); } ELSE /* Rescaling for 16k core */ { L_tmp_GC = L_max(gain_code_fx, L_shl(gain_preQ_fx,16)); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, coder_type_fx ); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type_fx ); } gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ @@ -236,7 +235,7 @@ void decod_gen_voic_fx( * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)) + IF (gain_preQ_fx != 0) { tmp1_fx = add(15-Q_AVQ_OUT_DEC-2,st_fx->Q_exc); FOR( i = 0; i < L_SUBFR; i++ ) @@ -261,7 +260,7 @@ void decod_gen_voic_fx( } ELSE { - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx ); + Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR); } /*-----------------------------------------------------------------* @@ -270,7 +269,7 @@ void decod_gen_voic_fx( prep_tbe_exc_fx( L_frame_fx, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[i_subfr_fx/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, coder_type_fx, st_fx->core_brate_fx ); + st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type_fx, st_fx->core_brate_fx ); /*----------------------------------------------------------------* @@ -278,13 +277,13 @@ void decod_gen_voic_fx( *----------------------------------------------------------------*/ test(); - IF( GT_32(st_fx->core_brate_fx,ACELP_32k)||EQ_16(coder_type_fx,INACTIVE)) + IF( GT_32(st_fx->core_brate_fx,ACELP_32k)||EQ_16(st_fx->coder_type_fx,INACTIVE)) { Copy( exc_fx+i_subfr_fx, exc2_fx+i_subfr_fx, L_SUBFR ); } ELSE { - enhancer_fx( st_fx->core_brate_fx, 0, coder_type_fx, i_subfr_fx, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx, + enhancer_fx( st_fx->core_brate_fx, 0, st_fx->coder_type_fx, i_subfr_fx, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); } @@ -304,9 +303,9 @@ void decod_gen_voic_fx( rint_bfi_pitch = rint_new_fx(L_tmp); /*Q0*/ shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/ - p_exc = st_fx->old_exc2_fx + shft_prev; + p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; + p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; move16(); - p_syn = st_fx->old_syn2_fx + shft_prev; move16(); prev_res_nrg = L_deposit_l(1); @@ -402,11 +401,18 @@ void decod_gen_voic_fx( st_fx->bfi_pitch_fx < 9600 && /*Q6*/ pitch_buf_fx[ sub( NB_SUBFR16k, 1 ) ] < 9600 ) /*Q6*/ { - PREVP = DTFS_new_fx(); - CURRP = DTFS_new_fx(); + IF ((error = DTFS_new_fx(&PREVP)) != IVAS_ERR_OK) + { + return error; + } + + IF ((error = DTFS_new_fx(&CURRP)) != IVAS_ERR_OK) + { + return error; + } GetSinCosTab_fx(rint_bfi_pitch,S_fx,C_fx); - DTFS_to_fs_fx( st_fx->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16)st_fx->output_Fs_fx, do_WI_fx, S_fx, C_fx); + DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16)st_fx->output_Fs_fx, do_WI_fx, S_fx, C_fx); PREVP->Q = add(PREVP->Q, st_fx->prev_Q_exc_fr); GetSinCosTab_fx(rint_pitch,S_fx,C_fx); @@ -415,7 +421,10 @@ void decod_gen_voic_fx( ph_offset_fx = 0; move16(); - WIsyn_fx(*PREVP, CURRP, dummy2, &(ph_offset_fx), out_fx, (Word16)st_fx->L_frame_fx, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); + if ((error = WIsyn_fx(*PREVP, CURRP, dummy2, &(ph_offset_fx), out_fx, (Word16)st_fx->L_frame_fx, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2)) != IVAS_ERR_OK) + { + return error; + } Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame_fx, st_fx->Q_exc ); @@ -427,8 +436,8 @@ void decod_gen_voic_fx( interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + (i_subfr_fx*2), L_SUBFR ); } - free(PREVP); - free(CURRP); + count_free(PREVP); + count_free(CURRP); } } @@ -439,5 +448,5 @@ void decod_gen_voic_fx( st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx; move16(); /*Q15*/ - return; + return error; } diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index 983a7d1..45e69a2 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -1,30 +1,26 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*-----------------------------------------------------------------* + * transf_cdbk_dec() * Transform domain contribution decoding *-----------------------------------------------------------------*/ void transf_cdbk_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ - const Word32 gain_code, /* i : innovative excitation gain (Q16) */ - Word16 *mem_preemp, /* i/o: dequantizer preemhasis memory */ - Word16 *gain_preQ, /* o : prequantizer excitation gain (Q2) */ - Word32 *norm_gain_preQ,/* o : normalized prequantizer excitation gain (Q16) */ - Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ - Word16 *unbits /* o : number of AVQ unused bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ + const Word32 gain_code, /* i : innovative excitation gain (Q16) */ + Word16 *gain_preQ, /* o : prequantizer excitation gain (Q2) */ + Word32 *norm_gain_preQ, /* o : normalized prequantizer excitation gain (Q16) */ + Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ + Word16 *unbits /* o : number of AVQ unused bits */ ) { Word16 i, index, nBits; @@ -33,12 +29,23 @@ void transf_cdbk_dec_fx( Word32 L_tmp; Word32 dct_code32[L_SUBFR]; Word16 qdct; +#ifdef IVAS_CODE + Word16 avq_bit_sFlag; + Word16 trgtSvPos; + avq_bit_sFlag = 0; + move16(); + IF (GT_16(st_fx->element_mode, EVS_MONO)) + { + move16(); + avq_bit_sFlag = 1; + } +#endif /*--------------------------------------------------------------* * Set bit-allocation *--------------------------------------------------------------*/ - nBits = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr(i_subfr, 6)]; move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -50,13 +57,13 @@ void transf_cdbk_dec_fx( index = (Word16)get_next_indice_fx(st_fx, G_AVQ_BITS ); - IF( EQ_16(coder_type,INACTIVE)) + IF(EQ_16(st_fx->coder_type_fx, INACTIVE)) { - IF( EQ_32(core_brate,ACELP_64k)) + IF(GT_32(st_fx->core_brate_fx, 56000)) { gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12>>1 ); } - ELSE IF( EQ_32(core_brate,ACELP_48k)) + ELSE IF( GT_32(st_fx->core_brate_fx,42000)) { gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12>>1 ); } @@ -71,7 +78,7 @@ void transf_cdbk_dec_fx( } ELSE { - IF( LE_32(core_brate,ACELP_32k)) + IF( GT_32(st_fx->core_brate_fx,ACELP_24k40) && LE_32(st_fx->core_brate_fx,42000)) { gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); } @@ -92,13 +99,25 @@ void transf_cdbk_dec_fx( L_tmp = L_shl(L_tmp,add(exp16,9)); /* Q18*/ *gain_preQ = round_fx(L_tmp); /* Q2*/ } - +#ifdef IVAS_CODE + trgtSvPos =sub(Nsv, 1); + test(); test(); test(); test(); test(); + IF (avq_bit_sFlag && GT_16(nBits, 85) && !harm_flag_acelp && (EQ_16(st_fx->coder_type_fx, GENERIC) || EQ_16(st_fx->coder_type_fx, TRANSITION) || EQ_16(st_fx->coder_type_fx, INACTIVE) )) + { + trgtSvPos = 2; + avq_bit_sFlag = 2; + move16(); move16(); + } +#endif /*--------------------------------------------------------------* * Demultiplex and decode subvectors from bit-stream *--------------------------------------------------------------*/ +#ifdef IVAS_CODE_AVQ + AVQ_demuxdec_fx(st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos); +#else AVQ_demuxdec_fx(st_fx, code_preQ, &nBits, 8, nq ); - +#endif FOR( i=0; icoder_type_fx,INACTIVE) || GT_32(st_fx->core_brate_fx, MAX_BRATE_AVQ_EXC_TD)||harm_flag_acelp) { qdct = 0; move16(); @@ -125,7 +144,23 @@ void transf_cdbk_dec_fx( Copy_Scale_sig_32_16(dct_code32, code_preQ, L_SUBFR, qdct); /* Output in Q_AVQ_OUT_DEC */ /*qdct = Q_AVQ_OUT_DEC;*/ } +#ifdef IVAS_CODE_AVQ + /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + IF (GT_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->coder_type_fx, INACTIVE) && GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate_fx, MAX_BRATE_AVQ_EXC_TD) && !harm_flag_acelp && code_preQ[0] != 0) + { + PMT("Fixed point taking accound of the scaling needs to be done here ") + IF (fabs((float)(st->last_code_preq)) > 16.0f * (float)fabs(code_preQ[0])) + { + st->mem_preemp_preQ /= 16; + } + ELSE IF (fabs((float)(st->last_code_preq)) > 8.0f * (float)fabs(code_preQ[0])) + { + st->mem_preemp_preQ /= 8; + } + } + st->last_code_preq = (int16_t)code_preQ[L_SUBFR - 1]; +#endif /*--------------------------------------------------------------* * Preemphasise *--------------------------------------------------------------*/ @@ -134,14 +169,13 @@ void transf_cdbk_dec_fx( if( (nq[7] != 0) && (GT_16( sub(st_fx->last_nq_preQ_fx, nq[0]), 7))) { /* *mem_preemp /= 16; */ - *mem_preemp = shr(*mem_preemp,4); + st_fx->mem_preemp_preQ_fx= shr(st_fx->mem_preemp_preQ_fx,4); move16(); } st_fx->last_nq_preQ_fx = nq[7]; move16(); - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, mem_preemp ); - + preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx); /*--------------------------------------------------------------* * Compute normalized prequantizer excitation gain for FEC * @@ -189,9 +223,9 @@ void transf_cdbk_dec_fx( /* * range using the specified number of levels. */ /*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* Word16 index i: quantization index */ -/* Word16 min i : value of lower limit */ -/* Word16 max i : value of upper limit */ +/* Word16 index i: quantization index */ +/* Word16 min_val i : value of lower limit */ +/* Word16 max_val i : value of upper limit */ /* Word16 bits i : number of bits to dequantize */ /*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ @@ -206,8 +240,8 @@ void transf_cdbk_dec_fx( /*==========================================================================*/ Word16 gain_dequant_fx( /* o: decoded gain */ Word16 index, /* i: quantization index */ - const Word16 min, /* i: value of lower limit */ - const Word16 max, /* i: value of upper limit */ + const Word16 min_val, /* i: value of lower limit */ + const Word16 max_val, /* i: value of upper limit */ const Word16 bits, /* i: number of bits to dequantize */ Word16 *expg ) @@ -225,9 +259,9 @@ Word16 gain_dequant_fx( /* o: decoded gain */ /* y =(index/cmult) + c_min - = index/((levels-1)/(log10(max)-log10(min))) + log10(min) - = (index*(log10(max)-log10(min)))/(levels-1) + log10(min) - = x*log10(max) + (1-x)*log10(min) + = index/((levels-1)/(log10(max_val)-log10(min))) + log10(min) + = (index*(log10(max_val)-log10(min)))/(levels-1) + log10(min) + = x*log10(max_val) + (1-x)*log10(min) where x = index/(levels-1) gain = pow(10.0,y) @@ -237,15 +271,15 @@ Word16 gain_dequant_fx( /* o: decoded gain */ tmp = div_s(1,sub(levels,1)); /*Q15*/ tmp = extract_l(L_shr(L_mult(index,tmp),1)); /*Q15*/ - e_tmp = norm_l(max); - f_tmp = Log2_norm_lc(L_shl(max, e_tmp)); - e_tmp = sub(30,e_tmp);/*Q(max)=0*/ + e_tmp = norm_l(max_val); + f_tmp = Log2_norm_lc(L_shl(max_val, e_tmp)); + e_tmp = sub(30,e_tmp);/*Q(max_val)=0*/ L_tmp = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ /*log10(2) in Q15*/ c_max = round_fx(L_shl(L_tmp, 14)); /* Q14 */ - e_tmp = norm_l(min); - f_tmp = Log2_norm_lc(L_shl(min, e_tmp)); - e_tmp = sub(sub(30,e_tmp),15);/*Q(min)=15*/ + e_tmp = norm_l(min_val); + f_tmp = Log2_norm_lc(L_shl(min_val, e_tmp)); + e_tmp = sub(sub(30,e_tmp),15);/*Q(min_val)=15*/ L_tmp = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ /*log10(2) in Q15*/ c_min = round_fx(L_shl(L_tmp, 14)); /* Q14 */ diff --git a/lib_dec/dec_nelp_fx.c b/lib_dec/dec_nelp_fx.c index c5bdc84..a9b21e3 100644 --- a/lib_dec/dec_nelp_fx.c +++ b/lib_dec/dec_nelp_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*======================================================================*/ /* FUNCTION : decod_nelp_fx() */ @@ -43,7 +42,6 @@ void decod_nelp_fx( Decoder_State_fx *st_fx, - const Word16 coder_type, Word16 *tmp_noise_fx, Word16 *pitch_buf_fx, Word16 *exc_fx, @@ -56,14 +54,23 @@ void decod_nelp_fx( { Word16 i; Word16 exc_nelp_fx[L_FRAME]; + Word16 coder_type; + test(); + IF (st_fx->use_partial_copy && EQ_16(st_fx->rf_frame_type, RF_NELP)) + { + coder_type = UNVOICED; + move16(); + } + ELSE + { + coder_type = st_fx->coder_type_fx; + move16(); + } *tmp_noise_fx = 0; move16(); - nelp_decoder_fx(st_fx, exc_nelp_fx, exc_fx, Q_exc, bfi, coder_type - , gain_buf - - ); + nelp_decoder_fx(st_fx, exc_nelp_fx, exc_fx, Q_exc, bfi, coder_type, gain_buf); Copy(exc_nelp_fx, exc_fx, L_FRAME); Copy(exc_nelp_fx, exc2_fx, L_FRAME); @@ -87,6 +94,9 @@ void decod_nelp_fx( set16_fx(pitch_buf_fx, L_SUBFR_Q6, NB_SUBFR); /* L_SUBFR = 64, Q6 */ set16_fx(voice_factors, 0, NB_SUBFR16k); - interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); + IF (st_fx->hBWE_TD != NULL) + { + interp_code_5over2_fx(exc2_fx, bwe_exc_fx, L_FRAME); + } return; } diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 508735c..29f157b 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*==========================================================================*/ @@ -32,16 +31,20 @@ /* _ None */ /*==========================================================================*/ void dec_pit_exc_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16 *gain_buf /*Q14*/ + Decoder_State_fx *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 coder_type_fx, /* i : coding type */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *code_fx, /* o : innovation */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + const Word16 nb_subfr_fx /* i : Number of subframe considered */ + , Word16 *gain_buf /*Q14*/ +#ifdef ADD_LRTD + , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +#endif ) { Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */ @@ -54,51 +57,112 @@ void dec_pit_exc_fx( const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ - Word16 Local_BR_fx, Pitch_BR_fx, Pitch_CT_fx; - Word16 pitch_limit_flag; + Word32 Local_BR_fx, Pitch_BR_fx; + Word16 pitch_limit_flag, Pitch_CT_fx; Word16 exc2_bidon[L_SUBFR]; Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ Word16 gain_code16,gain_pitx2; Word32 L_tmp; Word16 nbits; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; + + MUSIC_POSTFILT_HANDLE hMusicPF; + hMusicPF = st_fx->hMusicPF; - IF( EQ_16(st_fx->GSC_noisy_speech_fx,1)) + Word16 use_fcb; + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + + use_fcb = 0; + move16(); + test(); test(); test(); + IF (GT_16(st_fx->GSC_IVAS_mode, 0) && (EQ_16(st_fx->GSC_noisy_speech_fx, 1) || GT_32(st_fx->core_brate_fx, GSC_H_RATE_STG) ) ) + { + Local_BR_fx = ACELP_8k00; + Pitch_CT_fx = GENERIC; + Pitch_BR_fx = ACELP_8k00; + move32(); move32(); move16(); + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + Local_BR_fx = ACELP_14k80; + IF (GT_16(st_fx->GSC_IVAS_mode, 0 ) ) + { + Local_BR_fx = ACELP_9k60; + move32(); + } + Pitch_BR_fx = st_fx->core_brate_fx; + move32(); + } + } + ELSE IF( EQ_16(st_fx->GSC_noisy_speech_fx,1)) { Local_BR_fx = ACELP_7k20; - move16(); + move32(); Pitch_CT_fx = GENERIC; move16(); Pitch_BR_fx = ACELP_7k20; - move16(); + move32(); + IF(EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + Pitch_BR_fx = st_fx->core_brate_fx; + move32(); + } } ELSE { Local_BR_fx = ACELP_7k20; - move16(); + move32(); Pitch_CT_fx = AUDIO; move16(); - Pitch_BR_fx = extract_l(st_fx->core_brate_fx); + Pitch_BR_fx = st_fx->core_brate_fx; + move32(); + IF(EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + Pitch_BR_fx = ACELP_13k20; + move32(); + Pitch_CT_fx = GENERIC; + move16(); + } } + L_subfr_fx = mult_r(st_fx->L_frame_fx, div_s(1, nb_subfr_fx)); /* TV2Opt : this could be less complex with 2 ifs*/ + + gain_code_fx = 0; move16(); pitch_limit_flag = 1; move16();/* always extended pitch Q range */ - + test(); test(); test(); test(); test(); test(); + IF (((GE_32(st_fx->core_brate_fx, MIN_RATE_FCB) || (EQ_16(st_fx->GSC_noisy_speech_fx, 1) && ((EQ_16(st_fx->L_frame_fx, L_FRAME) && GE_32(st_fx->core_brate_fx, ACELP_13k20)) || (EQ_16(st_fx->L_frame_fx, L_FRAME16k) && GE_32(st_fx->core_brate_fx, GSC_H_RATE_STG)) || st_fx->GSC_IVAS_mode == 0))) && EQ_16(L_subfr_fx, L_SUBFR))) + { + use_fcb = 1; move16(); + } + ELSE IF (GT_16(st_fx->GSC_IVAS_mode, 0) && EQ_16(L_subfr_fx, 2 * L_SUBFR) && LT_16(st_fx->GSC_IVAS_mode, 3) ) + { + use_fcb = 2; + st_fx->acelp_cfg.fcb_mode = 1; + move16(); move16(); + set16_fx(st_fx->acelp_cfg.gains_mode, 6, 4); + set16_fx(st_fx->acelp_cfg.pitch_bits, 9, 4); + set16_fx(st_fx->acelp_cfg.fixed_cdk_index, 14, 5); + } /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - L_subfr_fx = mult_r(L_FRAME,div_s(1,nb_subfr_fx)); p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ pt_gain = gain_buf; /* pointer to the gain buffer */ - FOR ( i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_subfr_fx ) + FOR ( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame_fx; i_subfr_fx += L_subfr_fx ) { /*----------------------------------------------------------------------* * Decode pitch lag *----------------------------------------------------------------------*/ - - *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, L_FRAME, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx ); + *pt_pitch_fx = pit_decode_fx(st_fx, Pitch_BR_fx, 0, st_fx->L_frame_fx, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx +#ifdef ADD_LRTD + , tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf +#endif + ); move16(); /*--------------------------------------------------------------* @@ -111,21 +175,46 @@ void dec_pit_exc_fx( * Innovation decoding *--------------------------------------------------------------*/ - IF( EQ_16(st_fx->GSC_noisy_speech_fx,1)) + IF( EQ_16(use_fcb,1)) { - inov_decode_fx( st_fx, Local_BR_fx, 0, L_FRAME, LOCAL_CT, 1, i_subfr_fx, -1, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx ); + inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame_fx, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx); /*--------------------------------------------------------------* * Gain decoding * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_mless_fx( st_fx, Local_BR_fx, L_FRAME, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); + gain_dec_mless_fx( st_fx, st_fx->L_frame_fx, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); + + st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx,0 +#ifdef ADD_LRTD + , L_subfr_fx +#endif + ); + } + ELSE IF(EQ_16(use_fcb, 2)) /* IVAS only */ + { + inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame_fx, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx); + /*--------------------------------------------------------------* + * Gain decoding + * Estimate spectrum tilt and voicing + *--------------------------------------------------------------*/ + + gain_dec_lbr_fx(st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx); + + st_fx->tilt_code_fx = est_tilt_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 +#ifdef ADD_LRTD + , L_subfr_fx +#endif + ); - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx,0 ); } ELSE { - nbits = 4; + nbits = 5; + IF ( LT_32(st_fx->core_brate_fx, MIN_RATE_FCB) ) + { + nbits = 4; + } move16(); set16_fx(code_fx, 0, L_SUBFR); @@ -150,14 +239,14 @@ void dec_pit_exc_fx( * Find the total excitation *----------------------------------------------------------------------*/ - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type_fx); gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ - IF( EQ_16(st_fx->GSC_noisy_speech_fx,1)) + IF( NE_16(use_fcb,0)) { - Acelp_dec_total_exc( exc_fx, exc2_bidon-i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx ); + Acelp_dec_total_exc( exc_fx, exc2_bidon-i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx); } ELSE { @@ -180,7 +269,55 @@ void dec_pit_exc_fx( } } } - IF( EQ_16(L_subfr_fx,128)) /*2*L_SUBFR*/ + + IF (EQ_16(L_subfr_fx, L_FRAME16k)) + { + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = gain_pit_fx; move16(); + st_fx->lp_gainc_fx = 0; move32(); + + pt_pitch_fx++; + *pt_pitch_fx = *(pt_pitch_fx - 1); + pt_pitch_fx++; + *pt_pitch_fx = *(pt_pitch_fx - 1); + pt_pitch_fx++; + *pt_pitch_fx = *(pt_pitch_fx - 1); + pt_pitch_fx++; + *pt_pitch_fx = *(pt_pitch_fx - 1); + pt_pitch_fx++; + move16(); move16(); move16(); move16(); move16(); + p_Aq_fx += 5 * (M + 1); + } + ELSE IF (EQ_16(L_subfr_fx, L_FRAME16k/2)) + { + IF (i_subfr_fx == 0) + { + pt_pitch_fx++; + *pt_pitch_fx = *(pt_pitch_fx - 1); + pt_pitch_fx++; + p_Aq_fx += 2 * (M + 1); + move16(); move16(); move16(); move16(); + + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = extract_h(L_mult(6554, gain_pit_fx)); /*Q14 (3/15 in Q15 9830)*/ + st_fx->lp_gainc_fx = 0; move32(); + } + ELSE + { + pt_pitch_fx++; + *pt_pitch_fx = *(pt_pitch_fx - 1); + pt_pitch_fx++; + *pt_pitch_fx = *(pt_pitch_fx - 1); + pt_pitch_fx++; + p_Aq_fx += 3 * (M + 1); + move16(); move16(); move16(); move16(); + + /* update gains for FEC - equivalent to lp_gain_updt() */ + st_fx->lp_gainp_fx = extract_h(L_mult(26214, gain_pit_fx)); /*Q14 (12/15 in Q15 9830)*/ + st_fx->lp_gainc_fx = 0; move32(); + } + } + ELSE IF( EQ_16(L_subfr_fx,128)) /*2*L_SUBFR*/ { p_Aq_fx += 2*(M+1); move16(); @@ -252,7 +389,7 @@ void dec_pit_exc_fx( move16(); pt_gain++; - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); + lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame_fx); } } diff --git a/lib_dec/dec_post.c b/lib_dec/dec_post.c index 23687b3..62e2338 100644 --- a/lib_dec/dec_post.c +++ b/lib_dec/dec_post.c @@ -1,12 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "stl.h" /* Weighted mops computation related code */ #include "rom_dec_fx.h" #include "cnst_fx.h" @@ -16,10 +14,10 @@ #define FORMAT_POST_FILT_G1_MIN 24576/*0.75f Q15*/ /*for high bit-rates on clean speech and noisy speech*/ /*-------------------------------------------------------------------------- - * Local functions + * Local function prototypes *--------------------------------------------------------------------------*/ -static void Dec_postfilt( PFSTAT * pfstat, const Word16 t0, const Word16 *signal_ptr, const Word16 *coeff, +static void Dec_postfilt( PFSTAT_HANDLE hPFstat, const Word16 t0, const Word16 *signal_ptr, const Word16 *coeff, Word16 *sig_out, const Word16 gamma1, const Word16 gamma2, const Word16 Gain_factor, const Word16 disable_hpf ); static void pst_ltp( Word16 t0, Word16 * ptr_sig_in, Word16 * ptr_sig_pst0, Word16 gain_factor ); @@ -37,7 +35,7 @@ static void calc_st_filt( Word16 * apond2, Word16 * apond1, Word16 * parcor0, Wo static void modify_pst_param( const Word16 lp_noise, Word16 *g1, Word16 *g2, const Word16 coder_type, Word16 *gain_factor ); -static void Dec_formant_postfilt( PFSTAT *pfstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); +static void Dec_formant_postfilt( PFSTAT_HANDLE hPFstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); /*-------------------------------------------------------------------------- @@ -46,29 +44,29 @@ static void Dec_formant_postfilt( PFSTAT *pfstat, Word16 *signal_ptr, Word16 *co * post filter initialization *--------------------------------------------------------------------------*/ void Init_post_filter( - PFSTAT * pfstat /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat /* i : core decoder parameters */ ) { /* It is off by default */ - pfstat->on = 0; + hPFstat->on = 0; /* Reset */ - pfstat->reset = 0; + hPFstat->reset = 0; /* Initialize arrays and pointers */ - set16_fx(pfstat->mem_pf_in, 0, L_SUBFR); + set16_fx(hPFstat->mem_pf_in, 0, L_SUBFR); /* res2 = A(gamma2) residual */ - set16_fx(pfstat->mem_res2, 0, DECMEM_RES2); + set16_fx(hPFstat->mem_res2, 0, DECMEM_RES2); /* 1/A(gamma1) memory */ - set16_fx(pfstat->mem_stp, 0, L_SUBFR); + set16_fx(hPFstat->mem_stp, 0, L_SUBFR); /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ - set16_fx(pfstat->mem_zero, 0, M); + set16_fx(hPFstat->mem_zero, 0, M); /* for gain adjustment */ - pfstat->gain_prec = 16384; /*Q14*/ move16(); + hPFstat->gain_prec = 16384; /*Q14*/ move16(); return; } @@ -80,10 +78,10 @@ void Init_post_filter( *--------------------------------------------------------------------------*/ void nb_post_filt( const Word16 L_frame, /* i : frame length */ - PFSTAT *Pfstat, /* i/o: Post filter related memories */ - Word16 *psf_lp_noise, /* i : Long term noise Q8 */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *psf_lp_noise, /* i : Long term noise Q8 */ const Word16 tmp_noise, /* i : noise energy Q0 */ - Word16 *Synth, /* i : 12k8 synthesis Qsyn */ + Word16 *Synth, /* i : 12k8 synthesis Qsyn */ const Word16 *Aq, /* i : LP filter coefficient Q12 */ const Word16 *Pitch_buf, /* i : Fractionnal subframe pitch buffer Q6 */ const Word16 coder_type, /* i : coder_type */ @@ -107,21 +105,21 @@ void nb_post_filt( modify_pst_param( *psf_lp_noise, &Post_G1, &Post_G2, coder_type, &Gain_factor ); - if(Pfstat->reset) + if(hPFstat->reset) { - set16_fx(Pfstat->mem_res2, 0, DECMEM_RES2); - Copy( &Synth[L_frame-L_SYN_MEM], Pfstat->mem_pf_in, L_SYN_MEM); - Copy( &Synth[L_frame-L_SYN_MEM], Pfstat->mem_stp, L_SYN_MEM ); - Pfstat->gain_prec = 16384; + set16_fx(hPFstat->mem_res2, 0, DECMEM_RES2); + Copy( &Synth[L_frame-L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM); + Copy( &Synth[L_frame-L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); + hPFstat->gain_prec = 16384; move16(); - Pfstat->reset = 0; + hPFstat->reset = 0; move16(); return; } Pf_in = &pf_in_buffer[M]; - Copy( Pfstat->mem_pf_in+L_SYN_MEM-M, &Pf_in[-M], M ); + Copy( hPFstat->mem_pf_in+L_SYN_MEM-M, &Pf_in[-M], M ); Copy( Synth, Pf_in, L_frame ); - Copy( &Synth[L_frame - L_SYN_MEM], Pfstat->mem_pf_in, L_SYN_MEM ); + Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); /* deactivation of the post filter in case of AUDIO because it causes problems to singing sequences */ if( EQ_16(coder_type,AUDIO)) { @@ -143,7 +141,7 @@ void nb_post_filt( { T0_first = Pitch_buf[j]; - Dec_postfilt( Pfstat, T0_first, &Pf_in[i], p_Aq, &Synth[i], Post_G1, Post_G2, Gain_factor, disable_hpf ); + Dec_postfilt( hPFstat, T0_first, &Pf_in[i], p_Aq, &Synth[i], Post_G1, Post_G2, Gain_factor, disable_hpf ); p_Aq += (M+1); j = add(j,1); @@ -177,11 +175,11 @@ void nb_post_filt( * 2. search around best integer with fract. delays (1/8) *----------------------------------------------------------------------------*/ static void Dec_postfilt( - PFSTAT * pfstat, /* i/o: states strucure */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ const Word16 t0, /* i : pitch delay given by coder */ const Word16 * signal_ptr, /* i : input signal (pointer to current subframe */ const Word16 * coeff, /* i : LPC coefficients for current subframe */ - Word16 * sig_out, /* o : postfiltered output */ + Word16 * sig_out, /* o : postfiltered output */ const Word16 gamma1, /* i : short term postfilt. den. weighting factor */ const Word16 gamma2, /* i : short term postfilt. num. weighting factor */ const Word16 Gain_factor, /* i : Gain Factor (Q15) */ @@ -203,8 +201,8 @@ static void Dec_postfilt( /* Init pointers and restore memories */ res2_ptr = res2 + DECMEM_RES2; - ptr_mem_stp = pfstat->mem_stp + L_SYN_MEM - 1; - Copy(pfstat->mem_res2, res2, DECMEM_RES2); + ptr_mem_stp = hPFstat->mem_stp + L_SYN_MEM - 1; + Copy(hPFstat->mem_res2, res2, DECMEM_RES2); /* Compute weighted LPC coefficients */ weight_a_fx(coeff, apond1, gamma1, M); @@ -232,19 +230,19 @@ static void Dec_postfilt( move16(); /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt(apond2, apond1, &parcor0, sig_ltp_ptr, pfstat->mem_zero ); + calc_st_filt(apond2, apond1, &parcor0, sig_ltp_ptr, hPFstat->mem_zero ); - E_UTIL_synthesis(1, apond1, sig_ltp_ptr, sig_ltp_ptr, L_SUBFR, pfstat->mem_stp+L_SYN_MEM-M, 0, M); - Copy( sig_ltp_ptr+L_SUBFR-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM ); + E_UTIL_synthesis(1, apond1, sig_ltp_ptr, sig_ltp_ptr, L_SUBFR, hPFstat->mem_stp+L_SYN_MEM-M, 0, M); + Copy( sig_ltp_ptr+L_SUBFR-L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); /* Tilt filtering */ Filt_mu(sig_ltp, sig_out, parcor0, L_SUBFR); /* Gain control */ - scale_st(signal_ptr, sig_out, &pfstat->gain_prec, L_SUBFR); + scale_st(signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR); /* Update for next subframe */ - Copy(&res2[L_SUBFR], pfstat->mem_res2, DECMEM_RES2); + Copy(&res2[L_SUBFR], hPFstat->mem_res2, DECMEM_RES2); return; @@ -256,14 +254,14 @@ static void Dec_postfilt( * Main routine to perform formant post filtering *--------------------------------------------------------------------------*/ void formant_post_filt( - PFSTAT *pfstat, /* i/o: Post filter related memories */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: input signal */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *synth_in, /* i : 12k8 synthesis */ + Word16 *Aq, /* i : LP filter coefficient */ + Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ + Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + Word32 brate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ ) { Word16 i_subfr; @@ -279,14 +277,14 @@ void formant_post_filt( IF (LT_32(lp_noise, LP_NOISE_THRESH)) { /*Clean speech*/ - IF (LT_32(rate, ACELP_13k20)) + IF (LT_32(brate, ACELP_13k20)) { /*Low rates*/ post_G1 = 26214/*0.8f Q15*/; move16(); } - ELSE IF (LT_32(rate, ACELP_24k40)) + ELSE IF (LT_32(brate, ACELP_24k40)) { /*Low rates*/ @@ -303,7 +301,7 @@ void formant_post_filt( { post_G1 = 22938/*0.7f Q15*/; move16(); - if (LT_32(rate, ACELP_15k85)) + if (LT_32(brate, ACELP_15k85)) { /*Low rates*/ post_G1 = 24576/*0.75f Q15*/; @@ -320,17 +318,17 @@ void formant_post_filt( { post_G1 = 24904/*0.76f Q15*/; } - ELSE IF (EQ_32(rate, ACELP_13k20)) + ELSE IF (EQ_32(brate, ACELP_13k20)) { post_G1 = 26870/*0.82f Q15*/; move16(); } - ELSE IF (EQ_32(rate, ACELP_16k40)) + ELSE IF (EQ_32(brate, ACELP_16k40)) { post_G1 = 26214/*0.80f Q15*/; move16(); } - ELSE IF (EQ_32(rate, ACELP_24k40)||EQ_32(rate,ACELP_32k)) + ELSE IF (EQ_32(brate, ACELP_24k40)||EQ_32(brate,ACELP_32k)) { post_G1 = 25559/*0.78f Q15*/; move16(); @@ -350,17 +348,17 @@ void formant_post_filt( } /* Reset post filter */ - if( pfstat->reset != 0 ) + if( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); post_G2 = MAX16B; move16(); - pfstat->reset = 0; + hPFstat->reset = 0; move16(); - Copy( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM); - Copy( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_stp, L_SYN_MEM ); - pfstat->gain_prec = 16384; + Copy( &synth_in[L_frame-L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM); + Copy( &synth_in[L_frame-L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); + hPFstat->gain_prec = 16384; move16(); Copy( synth_in,synth_out, L_frame ); @@ -368,14 +366,14 @@ void formant_post_filt( } /* input memory*/ - Copy( pfstat->mem_pf_in, synth_in-L_SYN_MEM, L_SYN_MEM); - Copy( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM); + Copy( hPFstat->mem_pf_in, synth_in-L_SYN_MEM, L_SYN_MEM); + Copy( &synth_in[L_frame-L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM); move16(); p_Aq = Aq; FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { - Dec_formant_postfilt( pfstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); + Dec_formant_postfilt(hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); p_Aq += (M+1); } @@ -397,7 +395,7 @@ void formant_post_filt( * gamma3 = gamma3_minus if k1<0, gamma3_plus if k1>0 *----------------------------------------------------------------------------*/ static void Dec_formant_postfilt( - PFSTAT *pfstat, /* i/o: states strucure */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ Word16 *coeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -440,25 +438,25 @@ static void Dec_formant_postfilt( ELSE { Residu3_fx(apond2, signal_ptr, res2, L_SUBFR, 0); - Scale_sig(pfstat->mem_stp, L_SYN_MEM, -1); + Scale_sig(hPFstat->mem_stp, L_SYN_MEM, -1); } /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt(apond2, apond1, &parcor0, res2, pfstat->mem_zero ); + calc_st_filt(apond2, apond1, &parcor0, res2, hPFstat->mem_zero ); /* 1/A(gamma1) filtering, mem_stp is updated */ - resynth[0] = *(pfstat->mem_stp + sub(L_SYN_MEM, 1)); + resynth[0] = *(hPFstat->mem_stp + sub(L_SYN_MEM, 1)); move16(); - E_UTIL_synthesis(1, apond1, res2, &(resynth[1]), L_SUBFR, pfstat->mem_stp+L_SYN_MEM-M, 0, M); + E_UTIL_synthesis(1, apond1, res2, &(resynth[1]), L_SUBFR, hPFstat->mem_stp+L_SYN_MEM-M, 0, M); IF (!scale_down) { - Copy( &(resynth[1])+L_SUBFR-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM ); + Copy( &(resynth[1])+L_SUBFR-L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); } ELSE { - Copy_Scale_sig( &(resynth[1])+L_SUBFR-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM, 1 ); + Copy_Scale_sig( &(resynth[1])+L_SUBFR-L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM, 1 ); } /* Tilt filtering */ @@ -469,7 +467,7 @@ static void Dec_formant_postfilt( } /* Gain control */ - scale_st(signal_ptr, sig_out, &pfstat->gain_prec, L_SUBFR); + scale_st(signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR); return; diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index 8671891..36cd637 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*===================================================================*/ /* FUNCTION : void decod_ppp_fx () */ @@ -46,23 +46,25 @@ /*-------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*===================================================================*/ - -void decod_ppp_fx( - Decoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ +ivas_error decod_ppp_fx( + Decoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ Word16 *exc_fx, /* i/o: current non-enhanced excitation */ Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 bfi /* i : bad frame indicator */ - , Word16 *gain_buf - ,Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ + Word16 bfi, /* i : bad frame indicator */ + Word16 *gain_buf, + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ ) { Word16 k; Word16 LPC_de_curr_fx[M+1], p_Aq_curr_fx[M], p_Aq_old_fx[M+1]; Word16 excQ_ppp_fx[L_FRAME], pitch_fx[NB_SUBFR], LPC_de_old_fx[M+1]; + ivas_error error; + + error = IVAS_ERR_OK; /* call voiced decoder at this point */ FOR( k=0; ktilt_code_fx = st_fx->tilt_code_dec_fx[3]; move16(); @@ -96,11 +101,14 @@ void decod_ppp_fx( Copy(pitch_fx, pitch_buf_fx, NB_SUBFR);/*Q6 */ - interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); + IF(st_fx->hBWE_TD != NULL) + { + interp_code_5over2_fx(exc2_fx, bwe_exc_fx, L_FRAME); + } set16_fx( voice_factors, 0, NB_SUBFR16k ); set16_fx(gain_buf,0,NB_SUBFR16k); - return; + return error; } diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index 93af7f6..cb24571 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -23,7 +23,7 @@ static void dec_prm_hm( /* Disable HM for non-GC,VC modes */ test(); - IF (NE_16(st->tcx_cfg.coder_type, VOICED)&&NE_16(st->tcx_cfg.coder_type,GENERIC)) + IF (NE_16(st->hTcxCfg->coder_type, VOICED)&&NE_16(st->hTcxCfg->coder_type,GENERIC)) { prm_hm[0] = 0; move16(); @@ -53,7 +53,7 @@ static void dec_prm_hm( DecodeIndex(st, tmp, &prm_hm[1]); /* Gain index */ - IF (EQ_16(st->tcx_cfg.coder_type, VOICED)) + IF (EQ_16(st->hTcxCfg->coder_type, VOICED)) { prm_hm[2] = get_next_indice_fx(st, kTcxHmNumGainBits); move16(); @@ -102,6 +102,11 @@ void dec_prm( Word16 ltp_mode, gains_mode; Word16 ind; Word16 prm_ltp[LTPSIZE]; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; + + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; /*--------------------------------------------------------------------------------* * INIT @@ -152,9 +157,9 @@ void dec_prm( move16(); /* Init LTP data */ - st->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); - st->tcxltp_gain = 0; + hTcxLtpDec->tcxltp_gain = 0; move16(); /*--------------------------------------------------------------------------------* @@ -200,9 +205,9 @@ void dec_prm( /* 2 bits instead of 3 as TCX is already signaled */ st->core_fx = TCX_20_CORE; move16(); - st->tcx_cfg.coder_type = get_next_indice_fx(st, 2); + st->hTcxCfg->coder_type = get_next_indice_fx(st, 2); move16(); - *coder_type = st->tcx_cfg.coder_type; + *coder_type = st->hTcxCfg->coder_type; move16(); } ELSE @@ -215,9 +220,9 @@ void dec_prm( assert(!(tmp & 4) || !"HQ_CORE encountered in dec_prm"); st->core_fx = TCX_20_CORE; move16(); - st->tcx_cfg.coder_type = tmp; + st->hTcxCfg->coder_type = tmp; move16(); - *coder_type = st->tcx_cfg.coder_type; + *coder_type = st->hTcxCfg->coder_type; move16(); } ELSE /* ACELP */ @@ -244,7 +249,7 @@ void dec_prm( { st->core_fx = TCX_20_CORE; move16(); - st->tcx_cfg.coder_type = *coder_type; + st->hTcxCfg->coder_type = *coder_type; move16(); } } @@ -260,7 +265,7 @@ void dec_prm( st->core_fx = TCX_20_CORE; move16(); *coder_type=sub(*coder_type,ACELP_MODE_MAX); - st->tcx_cfg.coder_type = *coder_type; + st->hTcxCfg->coder_type = *coder_type; move16(); } } @@ -303,7 +308,7 @@ void dec_prm( move16(); test(); test(); - IF( ( NE_16(st->core_fx, ACELP_CORE) || st->tcx_cfg.lfacNext > 0 ) && st->use_partial_copy == 0 ) + IF( ( NE_16(st->core_fx, ACELP_CORE) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) { st->last_core_bs_fx = get_next_indice_fx(st, 1); move16(); @@ -348,31 +353,31 @@ void dec_prm( test(); IF ((EQ_16(st->last_core_fx, ACELP_CORE))||(EQ_16(st->last_core_fx,AMR_WB_CORE))) { - st->tcx_cfg.tcx_last_overlap_mode = TRANSITION_OVERLAP; + st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; move16(); } ELSE { test(); - IF ((EQ_16(st->core_fx, TCX_10_CORE))&&(EQ_16(st->tcx_cfg.tcx_curr_overlap_mode,ALDO_WINDOW))) + IF ((EQ_16(st->core_fx, TCX_10_CORE))&&(EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,ALDO_WINDOW))) { - st->tcx_cfg.tcx_last_overlap_mode = FULL_OVERLAP; + st->hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP; move16(); } ELSE { - st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; + st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); test(); - if ((NE_16(st->core_fx, TCX_10_CORE))&&(EQ_16(st->tcx_cfg.tcx_curr_overlap_mode,FULL_OVERLAP))) + if ((NE_16(st->core_fx, TCX_10_CORE))&&(EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,FULL_OVERLAP))) { - st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); } } } /* Set the current overlap mode based on the current frame type and coded overlap mode */ - st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); IF (NE_16(st->core_fx, ACELP_CORE)) @@ -384,7 +389,7 @@ void dec_prm( { tmp = add(2, get_next_indice_fx(st, 1)); } - st->tcx_cfg.tcx_curr_overlap_mode = tmp; + st->hTcxCfg->tcx_curr_overlap_mode = tmp; move16(); /* TCX10 : always symmetric windows */ @@ -393,7 +398,7 @@ void dec_prm( test(); if ((EQ_16(st->core_fx, TCX_20_CORE))&&(tmp==0)&&(NE_16(st->last_core_fx,ACELP_CORE))&&(NE_16(st->last_core_fx,AMR_WB_CORE))) { - st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); } } @@ -472,7 +477,7 @@ void dec_prm( /* Decode LPC parameters */ test(); - IF (st->enableTcxLpc && NE_16(st->core_fx, ACELP_CORE)) + IF (hTcxDec->enableTcxLpc && NE_16(st->core_fx, ACELP_CORE)) { Word16 tcx_lpc_cdk; tcx_lpc_cdk = tcxlpc_get_cdk(*coder_type); @@ -482,7 +487,11 @@ void dec_prm( { IF (st->lpcQuantization==0) { - decode_lpc_avq( st, st->numlpc, param_lpc ); + decode_lpc_avq( st, st->numlpc, param_lpc +#ifdef IVAS_CODE_AVQ_LPC + , , , +#endif + ); move16(); } ELSE IF (EQ_16(st->lpcQuantization, 1)) @@ -495,7 +504,7 @@ void dec_prm( } ELSE { - lsf_msvq_ma_decprm( st, param_lpc, st->core_fx, *coder_type, st->acelp_cfg.midLpc, st->narrowBand, st->sr_core ); + lsf_msvq_ma_decprm( st, param_lpc); } } @@ -735,7 +744,7 @@ void dec_prm( /* LTP data */ /* PLC pitch info for HB */ test(); - IF (st->tcxltp != 0 || GT_32(st->sr_core, 25600)) + IF (hTcxLtpDec->tcxltp != 0 || GT_32(st->sr_core, 25600)) { prm[j] = get_next_indice_fx(st, 1); @@ -751,26 +760,26 @@ void dec_prm( st->BER_detect = st->BER_detect | tcx_ltp_decode_params(&prm[j], - &(st->tcxltp_pitch_int), - &(st->tcxltp_pitch_fr), - &(st->tcxltp_gain), + &(hTcxLtpDec->tcxltp_pitch_int), + &(hTcxLtpDec->tcxltp_pitch_fr), + &(hTcxLtpDec->tcxltp_gain), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max); - st->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); - st->tcxltp_last_gain_unmodified = st->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; move16(); test(); - IF ((st->tcxonly == 0) && (LT_16(st->tcxltp_pitch_int, L_frame))) + IF ((st->tcxonly == 0) && (LT_16(hTcxLtpDec->tcxltp_pitch_int, L_frame))) { Word32 tmp32 = L_shl(L_mult0(st->L_frame_fx, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - Word16 tmp1 = add(imult1616(st->tcxltp_pitch_int, st->pit_res_max), st->tcxltp_pitch_fr); - st->tcx_hm_LtpPitchLag = div_l(tmp32, tmp1); + Word16 tmp1 = add(imult1616(hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max), hTcxLtpDec->tcxltp_pitch_fr); + hTcxDec->tcx_hm_LtpPitchLag = div_l(tmp32, tmp1); } } @@ -779,16 +788,16 @@ void dec_prm( /* TCX spectral data */ lg = L_frame; move16(); - lgFB = st->tcx_cfg.tcx_coded_lines; + lgFB = st->hTcxCfg->tcx_coded_lines; move16(); IF (st->last_core_bs_fx == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); - if(st->tcx_cfg.lfacNext < 0) + lg = add(lg, st->hTcxCfg->tcx_offset); + if (st->hTcxCfg->lfacNext < 0) { - lg = sub(lg,st->tcx_cfg.lfacNext); + lg = sub(lg, st->hTcxCfg->lfacNext); } lgFB = add(lgFB, shr(lgFB, 2)); @@ -800,17 +809,17 @@ void dec_prm( nTnsBits = 0; move16(); - IF (st->tcx_cfg.fIsTNSAllowed) + IF (st->hTcxCfg->fIsTNSAllowed) { - SetTnsConfig(&st->tcx_cfg, 1, st->last_core_bs_fx == ACELP_CORE); - ReadTnsData(st->tcx_cfg.pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); + SetTnsConfig(st->hTcxCfg, 1, st->last_core_bs_fx == ACELP_CORE); + ReadTnsData(st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); j = add(j, nTnsParams); } hm_size = shl(mult(st->TcxBandwidth, lg), 1); test(); - IF (st->tcx_lpc_shaped_ari != 0 && NE_16(st->last_core_bs_fx, ACELP_CORE)) + IF (hTcxDec->tcx_lpc_shaped_ari != 0 && NE_16(st->last_core_bs_fx, ACELP_CORE)) { dec_prm_hm(st, &prm[j], hm_size); } @@ -823,7 +832,7 @@ void dec_prm( /*Context HM flag*/ test(); - IF ( st->tcx_cfg.ctx_hm && NE_16(st->last_core_bs_fx, ACELP_CORE)) + IF ( st->hTcxCfg->ctx_hm && NE_16(st->last_core_bs_fx, ACELP_CORE)) { prm[j] = get_next_indice_fx(st, 1); move16(); @@ -852,7 +861,7 @@ void dec_prm( lgFB, nbits_tcx, *(prm+j+1), - st->tcx_hm_LtpPitchLag, + hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg); nbits_tcx = sub(nbits_tcx, NumIndexBits); @@ -868,21 +877,20 @@ void dec_prm( move16(); IF (EQ_16(st->last_core_bs_fx, ACELP_CORE)) { - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); - + IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); + IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); } ELSE { - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); + IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); + IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); } nbits_tcx = sub(nbits_tcx, sub(st->next_bit_pos_fx, n)); } nbits_tcx = sub(st->bits_frame_core, sub(st->next_bit_pos_fx, start_bit_pos)); - IF (st->tcx_lpc_shaped_ari != 0) + IF (hTcxDec->tcx_lpc_shaped_ari != 0) { prm[j++] = nbits_tcx; /* store length of buffer */ move16(); prms = &prm[j]; @@ -903,12 +911,7 @@ void dec_prm( phm_cfg = &hm_cfg; move16(); } - st->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC(st, - prm+j, - lgFB, - nbits_tcx, - NPRM_RESQ*st->tcx_cfg.resq, - phm_cfg); + hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC(st, prm+j, lgFB, nbits_tcx,NPRM_RESQ*st->hTcxCfg->resq,phm_cfg); move16(); j = add(j, lg); } @@ -950,12 +953,12 @@ void dec_prm( IF( EQ_16(st->rf_frame_type, RF_TCXFD)) { /* TCX Gain = 7 bits */ - st->old_gaintcx_bfi = get_next_indice_fx(st, 7); + hTcxDec->old_gaintcx_bfi = get_next_indice_fx(st, 7); } ELSE { /* LTP data */ - IF( st->tcxltp != 0 ) + IF(hTcxLtpDec->tcxltp != 0 ) { IF( EQ_16(st->rf_frame_type, RF_TCXTD2)||EQ_16(st->rf_frame_type,RF_TCXTD1)) { @@ -968,10 +971,10 @@ void dec_prm( IF( st->prev_bfi_fx == 0 ) { st->BER_detect = st->BER_detect | - tcx_ltp_decode_params(&prm_ltp[0], &(st->tcxltp_pitch_int), &(st->tcxltp_pitch_fr), &(st->tcxltp_gain), + tcx_ltp_decode_params(&prm_ltp[0], &(hTcxLtpDec->tcxltp_pitch_int), &(hTcxLtpDec->tcxltp_pitch_fr), &(hTcxLtpDec->tcxltp_gain), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); - st->tcxltp_last_gain_unmodified = st->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; move16(); } } @@ -1001,14 +1004,13 @@ void dec_prm( n = st->next_bit_pos_fx; move16(); - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); - IGFDecStoreTCX10SubFrameData( &st->hIGFDec, 0 ); - - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); - IGFDecStoreTCX10SubFrameData( &st->hIGFDec, 1 ); + IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); + IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); + IGFDecStoreTCX10SubFrameData( st->hIGFDec, 0 ); + IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); + IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); + IGFDecStoreTCX10SubFrameData( st->hIGFDec, 1 ); nbits_igf = sub(st->next_bit_pos_fx, n); } @@ -1040,7 +1042,7 @@ void dec_prm( /* LTP data */ test(); test(); - IF ( (k == 0) && ((st->tcxltp != 0) || (GT_32(st->sr_core, 25600)))) + IF ( (k == 0) && ((hTcxLtpDec->tcxltp != 0) || (GT_32(st->sr_core, 25600)))) { prm[j] = get_next_indice_fx(st, 1); move16(); @@ -1063,18 +1065,18 @@ void dec_prm( st->BER_detect = st->BER_detect | tcx_ltp_decode_params(&prm[j], - &(st->tcxltp_pitch_int), - &(st->tcxltp_pitch_fr), - &(st->tcxltp_gain), + &(hTcxLtpDec->tcxltp_pitch_int), + &(hTcxLtpDec->tcxltp_pitch_fr), + &(hTcxLtpDec->tcxltp_gain), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max); - st->tcxltp_last_gain_unmodified = st->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; move16(); - st->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); j = add(j, 3); @@ -1091,16 +1093,16 @@ void dec_prm( /* TCX spectral data */ lg = shr(L_frame, 1); - lgFB = shr(st->tcx_cfg.tcx_coded_lines, 1); + lgFB = shr(st->hTcxCfg->tcx_coded_lines, 1); test(); IF ( k == 0 && st->last_core_bs_fx == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); - if(st->tcx_cfg.lfacNext<0) + lg = add(lg, st->hTcxCfg->tcx_offset); + if(st->hTcxCfg->lfacNext<0) { - lg = sub(lg,st->tcx_cfg.lfacNext); + lg = sub(lg,st->hTcxCfg->lfacNext); } lgFB = add(lgFB, shr(lgFB, 1)); @@ -1112,7 +1114,7 @@ void dec_prm( nTnsBits = 0; move16(); - IF (st->tcx_cfg.fIsTNSAllowed) + IF (st->hTcxCfg->fIsTNSAllowed) { IF( EQ_16(st->last_core_bs_fx, ACELP_CORE)&&(k==0)) { @@ -1122,10 +1124,9 @@ void dec_prm( } test(); test(); - SetTnsConfig(&st->tcx_cfg, 0, (st->last_core_bs_fx == ACELP_CORE) && (k == 0)); - - ReadTnsData(st->tcx_cfg.pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); + SetTnsConfig(st->hTcxCfg, 0, (st->last_core_bs_fx == ACELP_CORE) && (k == 0)); + ReadTnsData(st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); j = add(j, nTnsParams); } @@ -1137,7 +1138,7 @@ void dec_prm( /*Context HM flag*/ test(); test(); - IF ( st->tcx_cfg.ctx_hm && !(st->last_core_bs_fx == ACELP_CORE && k == 0) ) + IF ( st->hTcxCfg->ctx_hm && !(st->last_core_bs_fx == ACELP_CORE && k == 0) ) { prm[j] = get_next_indice_fx(st, 1); move16(); @@ -1146,19 +1147,12 @@ void dec_prm( IF (prm[j]) /* Read PeriodicityIndex */ { - Word16 NumIndexBits = DecodeIndex(st, - hm_size >= 256, - prm+j+1); + Word16 NumIndexBits = DecodeIndex(st,hm_size >= 256,prm+j+1); flag_ctx_hm = 1; move16(); - ConfigureContextHm( - lgFB, - nbits_tcx, - *(prm+j+1), - -1, - &hm_cfg); + ConfigureContextHm(lgFB,nbits_tcx,*(prm+j+1),-1,&hm_cfg); nbits_tcx = sub(nbits_tcx, NumIndexBits); } @@ -1171,11 +1165,7 @@ void dec_prm( phm_cfg = &hm_cfg; move16(); } - st->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC(st, prm+j, - lgFB, - nbits_tcx, - NPRM_RESQ*st->tcx_cfg.resq, - phm_cfg); + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC(st, prm+j,lgFB,nbits_tcx,NPRM_RESQ*st->hTcxCfg->resq,phm_cfg); move16(); j = add(j, lgFB); diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index efbb2b0..269d67e 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -2,7 +2,7 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include #include #include "prot_fx.h" @@ -51,7 +51,7 @@ static void IMDCT(Word32 *x, Word16 x_e, void decoder_tcx( - TCX_config *tcx_cfg, /* input: configuration of TCX */ + TCX_CONFIG_HANDLE hTcxCfg, Word16 prm[], /* input: parameters */ Word16 A[], /* input: coefficients NxAz[M+1] */ Word16 Aind[], /* input: frame-independent coefficients Az[M+1] */ @@ -105,6 +105,11 @@ void decoder_tcx( Word16 noise_filling_index; Word16 infoIGFStartLine; Word16 L_spec_con; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; + + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; prm_target = NULL; /* just to suppress MSVC warnigs */ @@ -135,21 +140,21 @@ void decoder_tcx( /* Init lengths */ - overlap = tcx_cfg->tcx_mdct_window_length; + overlap = hTcxCfg->tcx_mdct_window_length; move16(); - overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; + overlapFB = hTcxCfg->tcx_mdct_window_lengthFB; move16(); /* Modified the overlap to the delay in case of short blocks*/ - tcx_offset = tcx_cfg->tcx_offset; + tcx_offset = hTcxCfg->tcx_offset; move16(); - tcx_offsetFB = tcx_cfg->tcx_offsetFB; + tcx_offsetFB = hTcxCfg->tcx_offsetFB; move16(); L_spec_con = L_spec; move16(); gamma1 = st->gamma; move16(); - if (st->enableTcxLpc != 0) + if (hTcxDec->enableTcxLpc != 0) { gamma1 = 0x7FFF; move16(); @@ -171,12 +176,12 @@ void decoder_tcx( IF (left_rect != 0) { - tcx_offset = tcx_cfg->lfacNext; + tcx_offset = hTcxCfg->lfacNext; move16(); - tcx_offsetFB = tcx_cfg->lfacNextFB; + tcx_offsetFB = hTcxCfg->lfacNextFB; move16(); - L_spec = add(L_spec, shr(st->tcx_cfg.tcx_coded_lines, 2)); - L_spec_con = add(L_spec_con, shr(st->tcx_cfg.tcx_coded_lines, 2)); + L_spec = add(L_spec, shr(st->hTcxCfg->tcx_coded_lines, 2)); + L_spec_con = add(L_spec_con, shr(st->hTcxCfg->tcx_coded_lines, 2)); } } ELSE @@ -186,20 +191,20 @@ void decoder_tcx( { if (st->prev_bfi_fx == 0) { - tcx_cfg->last_aldo = 0; + hTcxCfg->last_aldo = 0; move16(); } /* if past frame is ACELP */ L_frame = add(L_frame_glob, tcx_offset); L_frameTCX = add(L_frameTCX_glob, tcx_offsetFB); - L_spec_con = add(L_spec_con, shr(st->tcx_cfg.tcx_coded_lines, 2)); - assert(tcx_cfg->lfacNext<=0); - L_frame = sub(L_frame , tcx_cfg->lfacNext); - L_frameTCX = sub(L_frameTCX, tcx_cfg->lfacNextFB); - tcx_offset = tcx_cfg->lfacNext; + L_spec_con = add(L_spec_con, shr(st->hTcxCfg->tcx_coded_lines, 2)); + assert(hTcxCfg->lfacNext<=0); + L_frame = sub(L_frame , hTcxCfg->lfacNext); + L_frameTCX = sub(L_frameTCX, hTcxCfg->lfacNextFB); + tcx_offset = hTcxCfg->lfacNext; move16(); - tcx_offsetFB = tcx_cfg->lfacNextFB; + tcx_offsetFB = hTcxCfg->lfacNextFB; move16(); left_rect = 1; move16(); @@ -221,7 +226,7 @@ void decoder_tcx( IF ( frame_cnt == 0 && EQ_16(st->last_core_bs_fx, ACELP_CORE) ) { - L_spec += st->tcx_cfg.tcx_coded_lines >> 2; + L_spec += st->hTcxCfg->tcx_coded_lines >> 2; } st->L_frame_past = L_frame; @@ -233,10 +238,7 @@ void decoder_tcx( test(); IF ( (EQ_16(L_frame, shr(st->L_frame_fx, 1)))&&(st->tcxonly)) { - IGFDecUpdateInfo( - &st->hIGFDec, - IGF_GRID_LB_SHORT - ); + IGFDecUpdateInfo( st->hIGFDec,IGF_GRID_LB_SHORT); } ELSE { @@ -244,17 +246,11 @@ void decoder_tcx( test(); IF ((EQ_16(st->last_core_fx, ACELP_CORE))||(left_rect&&st->bfi_fx)) { - IGFDecUpdateInfo( - &st->hIGFDec, - IGF_GRID_LB_TRAN - ); + IGFDecUpdateInfo(st->hIGFDec,IGF_GRID_LB_TRAN); } ELSE { - IGFDecUpdateInfo( - &st->hIGFDec, - IGF_GRID_LB_NORM - ); + IGFDecUpdateInfo(st->hIGFDec,IGF_GRID_LB_NORM); } } @@ -275,7 +271,7 @@ void decoder_tcx( } ELSE { - infoIGFStartLine = s_min(st->hIGFDec.infoIGFStartLine,L_frameTCX); + infoIGFStartLine = s_min(st->hIGFDec->infoIGFStartLine,L_frameTCX); move16(); } @@ -283,7 +279,7 @@ void decoder_tcx( move16(); if (st->igf != 0) { - noiseFillingSize = st->hIGFDec.infoIGFStartLine; + noiseFillingSize = st->hIGFDec->infoIGFStartLine; move16(); } @@ -321,10 +317,10 @@ void decoder_tcx( /* read TNS data */ test(); - IF ((bfi == 0) && (tcx_cfg->fIsTNSAllowed != 0)) + IF ((bfi == 0) && (hTcxCfg->fIsTNSAllowed != 0)) { cast16(); - fUseTns = (Word8)DecodeTnsData(tcx_cfg->pCurrentTnsConfig, + fUseTns = (Word8)DecodeTnsData(hTcxCfg->pCurrentTnsConfig, prm_tns, &tnsSize, &tnsData); @@ -352,7 +348,7 @@ void decoder_tcx( *-----------------------------------------------------------*/ test(); test(); - IF(tcx_cfg->ctx_hm != 0 && ( (st->last_core_bs_fx != ACELP_CORE) || (frame_cnt > 0) ) ) + IF(hTcxCfg->ctx_hm != 0 && ( (st->last_core_bs_fx != ACELP_CORE) || (frame_cnt > 0) ) ) { st->last_ctx_hm_enabled = prm_hm[0]; move16(); @@ -368,10 +364,10 @@ void decoder_tcx( x_e = SPEC_EXP_DEC; move16(); } - ELSE /* tcx_cfg->ctx_hm == 0 */ + ELSE /* hTcxCfg->ctx_hm == 0 */ { - IF (st->tcx_lpc_shaped_ari != 0) /* low rates: new arithmetic coder */ + IF (hTcxDec->tcx_lpc_shaped_ari != 0) /* low rates: new arithmetic coder */ { prm_target = prm_sqQ; move16(); @@ -396,14 +392,14 @@ void decoder_tcx( prm_sqQ, tmp8, prm_hm, /* HM parameter area */ - st->tcx_hm_LtpPitchLag, + hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, &nf_seed, shr(st->bwidth_fx, 1) /* equivalent to: (st->bwidth_fx > WB)?1:0 */ ); - st->resQBits[frame_cnt] = sub(*prm_target, arith_bits); + hTcxDec->resQBits[frame_cnt] = sub(*prm_target, arith_bits); move16(); } ELSE /* TCX-only: old arithmetic coder */ @@ -422,7 +418,7 @@ void decoder_tcx( move16(); } - } /* else of if tcx_cfg->ctx_hm */ + } /* else of if hTcxCfg->ctx_hm */ tmp1 = s_max(L_frame, L_frameTCX); tmp1 = s_max(tmp1, L_spec_con); set32_fx(x+L_spec, 0, sub(tmp1, L_spec)); @@ -434,7 +430,7 @@ void decoder_tcx( weight_a_fx(A, Ap, gamma1, M); - lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e); + lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS, 0); /* initialize LF deemphasis factors in xn_buf */ @@ -443,13 +439,13 @@ void decoder_tcx( IF (st->tcxonly == 0) { - AdaptLowFreqDeemph( x, x_e, st->tcx_lpc_shaped_ari, gainlpc2, gainlpc2_e, + AdaptLowFreqDeemph( x, x_e, hTcxDec->tcx_lpc_shaped_ari, gainlpc2, gainlpc2_e, L_frame, xn_buf /* LF deemphasis factors */ ); } } /* Global Gain */ - st->damping = 0; + hTcxDec->damping = 0; IF(bfi==0) { @@ -473,12 +469,12 @@ void decoder_tcx( gain_tcx = mult(gain_tcx, tmp1); gain_tcx_e = add(gain_tcx_e, s); - st->old_gaintcx_bfi = gain_tcx; + hTcxDec->old_gaintcx_bfi = gain_tcx; move16(); - st->old_gaintcx_bfi_e = gain_tcx_e; + hTcxDec->old_gaintcx_bfi_e = gain_tcx_e; move16(); - st->cummulative_damping_tcx = 32767/*1.0f Q15*/; + hTcxDec->cummulative_damping_tcx = 32767/*1.0f Q15*/; move16(); } ELSE /* bfi = 1 */ @@ -491,7 +487,7 @@ void decoder_tcx( { IF( EQ_16(st->rf_frame_type, RF_TCXFD)) { - tmp32 = L_shl(L_mult0(st->old_gaintcx_bfi, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ + tmp32 = L_shl(L_mult0(hTcxDec->old_gaintcx_bfi, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ gain_tcx_e = add(extract_l(L_shr(tmp32, 25)), 1); /* get exponent */ gain_tcx = round_fx(BASOP_Util_InvLog2(L_or(tmp32, 0xFE000000))); @@ -502,31 +498,31 @@ void decoder_tcx( gain_tcx = mult(gain_tcx, tmp1); gain_tcx_e = add(gain_tcx_e, s); - st->old_gaintcx_bfi = gain_tcx; + hTcxDec->old_gaintcx_bfi = gain_tcx; move16(); - st->old_gaintcx_bfi_e = gain_tcx_e; + hTcxDec->old_gaintcx_bfi_e = gain_tcx_e; move16(); } ELSE { - gain_tcx = st->old_gaintcx_bfi; + gain_tcx = hTcxDec->old_gaintcx_bfi; move16(); - gain_tcx_e = st->old_gaintcx_bfi_e; + gain_tcx_e = hTcxDec->old_gaintcx_bfi_e; move16(); } - st->damping = 16384/*1.f Q14*/; /*Q14*/ move16(); + hTcxDec->damping = 16384/*1.f Q14*/; /*Q14*/ move16(); } ELSE { - st->damping = Damping_fact(coder_type, st->nbLostCmpt, st->last_good_fx, stab_fac, &(st->Mode2_lp_gainp), st->last_core_fx); - gain_tcx = st->old_gaintcx_bfi; + hTcxDec->damping = Damping_fact(coder_type, st->nbLostCmpt, st->last_good_fx, stab_fac, &(st->Mode2_lp_gainp), st->last_core_fx); + gain_tcx = hTcxDec->old_gaintcx_bfi; move16(); - gain_tcx_e = st->old_gaintcx_bfi_e; + gain_tcx_e = hTcxDec->old_gaintcx_bfi_e; move16(); } - st->cummulative_damping_tcx = shl(mult(st->cummulative_damping_tcx,st->damping),1);/*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ + hTcxDec->cummulative_damping_tcx = shl(mult(hTcxDec->cummulative_damping_tcx,hTcxDec->damping),1);/*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ } { @@ -535,7 +531,7 @@ void decoder_tcx( { gamma = gamma1; move16(); - if (st->envWeighted) + if (hTcxDec->envWeighted) { gamma = st->gamma; move16(); @@ -543,17 +539,17 @@ void decoder_tcx( /* PLC: [TCX: Fade-out] * PLC: invert LPC weighting in case of PLC */ - IF (st->enableTcxLpc != 0) + IF (hTcxDec->enableTcxLpc != 0) { - gamma = add(mult_r(st->cummulative_damping_tcx,sub(st->gamma, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); + gamma = add(mult_r(hTcxDec->cummulative_damping_tcx,sub(st->gamma, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); } ELSE { - gamma = add(mult_r(st->cummulative_damping_tcx,sub(gamma1, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); + gamma = add(mult_r(hTcxDec->cummulative_damping_tcx,sub(gamma1, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); } weight_a_fx(A, Ap, gamma, M); - lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e); + lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS, 0); } tmp2 = 0; @@ -575,13 +571,13 @@ void decoder_tcx( tmp32 = Sqrt32(tmp32,&st->last_gain_syn_deemph_e); st->last_gain_syn_deemph = round_fx(tmp32); /*for avoiding compiler warnings*/ - st->gainHelper = 32768/2; + hTcxDec->gainHelper = 32768/2; move16(); - st->gainHelper_e = 1; + hTcxDec->gainHelper_e = 1; move16(); - st->stepCompensate = 0; + hTcxDec->stepCompensate = 0; move16(); - st->stepCompensate_e = 0; + hTcxDec->stepCompensate_e = 0; move16(); } /* not instrumenting the additional test() here seems to be common practice */ @@ -603,31 +599,31 @@ void decoder_tcx( IF (EQ_16(st->nbLostCmpt,1)) { /* stepCompensate = (1.f - gainCompensate)/st->L_frame_fx; */ - st->stepCompensate_e = BASOP_Util_Add_MantExp( + hTcxDec->stepCompensate_e = BASOP_Util_Add_MantExp( tmp1, -7, negate(mult(gainCompensate,tmp1)), add(-7,gainCompensate_e), - &st->stepCompensate); + &hTcxDec->stepCompensate); - st->gainHelper = 32768/2; + hTcxDec->gainHelper = 32768/2; move16(); - st->gainHelper_e = 1; + hTcxDec->gainHelper_e = 1; move16(); } ELSE { /* stepCompensate = (st->last_concealed_gain_syn_deemph - gainCompensate)/st->L_frame_fx; */ - st->stepCompensate_e = BASOP_Util_Add_MantExp( + hTcxDec->stepCompensate_e = BASOP_Util_Add_MantExp( mult(tmp1,st->last_concealed_gain_syn_deemph), add(-7, st->last_concealed_gain_syn_deemph_e), negate(mult(tmp1,gainCompensate)), add(-7, gainCompensate_e), - &st->stepCompensate); + &hTcxDec->stepCompensate); move16(); move16(); - st->gainHelper = st->last_concealed_gain_syn_deemph; - st->gainHelper_e = st->last_concealed_gain_syn_deemph_e; + hTcxDec->gainHelper = st->last_concealed_gain_syn_deemph; + hTcxDec->gainHelper_e = st->last_concealed_gain_syn_deemph_e; } move16(); move16(); @@ -642,40 +638,33 @@ void decoder_tcx( * Residual inv. Q. * *-----------------------------------------------------------*/ test(); - IF ((bfi == 0) && (tcx_cfg->resq != 0)) + IF ((bfi == 0) && (hTcxCfg->resq != 0)) { - IF (st->tcx_lpc_shaped_ari != 0) /* new arithmetic coder */ + IF (hTcxDec->tcx_lpc_shaped_ari != 0) /* new arithmetic coder */ { Word16 *prm_resq; prm_resq = prm_sqQ + *prm_target /* = targetBits */ - - st->resQBits[frame_cnt]; + - hTcxDec->resQBits[frame_cnt]; i = tcx_ari_res_invQ_spec(x, x_e, L_spec, prm_resq, - st->resQBits[frame_cnt], + hTcxDec->resQBits[frame_cnt], 0, - tcx_cfg->sq_rounding, + hTcxCfg->sq_rounding, xn_buf /* LF deemphasis factors */ ); } ELSE /* old arithmetic coder */ { - i = tcx_res_invQ_gain(&gain_tcx, &gain_tcx_e, - &prm_sqQ[L_spec], - st->resQBits[frame_cnt]); + i = tcx_res_invQ_gain(&gain_tcx, &gain_tcx_e, &prm_sqQ[L_spec], hTcxDec->resQBits[frame_cnt]); tmpP16 = xn_buf; if (st->tcxonly != 0) tmpP16 = NULL; - tcx_res_invQ_spec(x, x_e, L_spec, - &prm_sqQ[L_spec], - st->resQBits[frame_cnt], - i, - tcx_cfg->sq_rounding, - tmpP16 /* LF deemphasis factors */ ); + tcx_res_invQ_spec(x, x_e, L_spec, &prm_sqQ[L_spec],hTcxDec->resQBits[frame_cnt],i,hTcxCfg->sq_rounding,tmpP16 /* LF deemphasis factors */ ); } } test(); @@ -683,7 +672,7 @@ void decoder_tcx( { test(); test(); - IF (st->tcxltp && (st->tcxltp_gain > 0) && !fUseTns) + IF (hTcxLtpDec->tcxltp && (hTcxLtpDec->tcxltp_gain > 0) && !fUseTns) { PsychAdaptLowFreqDeemph(x, gainlpc2, gainlpc2_e, NULL); @@ -710,7 +699,7 @@ void decoder_tcx( if(st->VAD==0 ) { - gain_tcx = mult_r(gain_tcx, tcx_cfg->na_scale); + gain_tcx = mult_r(gain_tcx, hTcxCfg->na_scale); } i = norm_s(gain_tcx); @@ -748,12 +737,12 @@ void decoder_tcx( move16(); test(); test(); - if ((tcx_cfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE) && (st->last_ctx_hm_enabled != 0)) + if ((hTcxCfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE) && (st->last_ctx_hm_enabled != 0)) { tmp1 = 10240/*0.3125f Q15*/; move16(); } - noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(st->tcxltp_gain, tmp1)); + noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(hTcxLtpDec->tcxltp_gain, tmp1)); if (EQ_16(L_frame, shr(st->L_frame_fx, 1))) { @@ -762,7 +751,7 @@ void decoder_tcx( } - IF (st->tcx_lpc_shaped_ari == 0) /* old arithmetic coder */ + IF (hTcxDec->tcx_lpc_shaped_ari == 0) /* old arithmetic coder */ { /* noise filling seed */ tmp32 = L_deposit_l(0); @@ -779,19 +768,11 @@ void decoder_tcx( pInfoTCXNoise = NULL; if (st->igf) { - pInfoTCXNoise = st->hIGFDec.infoTCXNoise; + pInfoTCXNoise = st->hIGFDec->infoTCXNoise; move16(); } - tcx_noise_filling(x, x_e, - tmp1 /* seed */, - firstLine, - noiseFillingSize, - noiseTransWidth, - L_frame, - noiseTiltFactor, - fac_ns, - pInfoTCXNoise - ); + tcx_noise_filling(x, x_e,tmp1 /* seed */, firstLine, noiseFillingSize, noiseTransWidth, L_frame, noiseTiltFactor, + fac_ns, pInfoTCXNoise, st->element_mode); st->seed_tcx_plc = tmp1; move16(); } @@ -833,7 +814,7 @@ void decoder_tcx( } } - if (GT_16(L_frameTCX, st->L_frameTCX)) + if (GT_16(L_frameTCX, hTcxDec->L_frameTCX)) { st->plcInfo.concealment_method = TCX_TONAL; move16(); @@ -861,12 +842,8 @@ void decoder_tcx( IF (bfi == 0) { - TonalMDCTConceal_SaveFreqSignal(&st->tonalMDCTconceal, - x, x_e, - L_frameTCX, - L_frame, - gainlpc2, gainlpc2_e, - gain_tcx_e); + TonalMDCTConceal_SaveFreqSignal(&st->tonalMDCTconceal,x, x_e, L_frameTCX, + L_frame, gainlpc2, gainlpc2_e, gain_tcx_e); } ELSE { @@ -877,7 +854,7 @@ void decoder_tcx( /* set f to 1 to not fade out */ /* set f to 0 to immediately switch to white noise */ - f = st->cummulative_damping_tcx; + f = hTcxDec->cummulative_damping_tcx; move16(); if (0 != st->tcxonly) { @@ -887,10 +864,10 @@ void decoder_tcx( test(); test(); - IF ( (frame_cnt == 0) && (EQ_16(L_frameTCX, shr(st->L_frameTCX, 1))) + IF ( (frame_cnt == 0) && (EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1))) && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (EQ_16(st->nbLostCmpt, 1)) - && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) - && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) + && (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) + && (hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) { Word16 exp1, exp2; Word32 E_2ndlast, E_last; @@ -937,15 +914,12 @@ void decoder_tcx( tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); - TonalMDCTConceal_InsertNoise(&st->tonalMDCTconceal, - x, - &x_e, - st->tonal_mdct_plc_active, - &st->seed_tcx_plc, - noiseTiltFactor, - f, - infoIGFStartLine - ); + TonalMDCTConceal_InsertNoise(&st->tonalMDCTconceal, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, + noiseTiltFactor, f, +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + concealment_noise, +#endif + infoIGFStartLine ); } } @@ -970,18 +944,13 @@ void decoder_tcx( test(); test(); IF ( bfi && (!st->enablePlcWaveadjust || EQ_16(temp_concealment_method, TCX_TONAL)) - && st->igf && (frame_cnt == 0) && (EQ_16(L_frameTCX, shr(st->L_frameTCX, 1))) + && st->igf && (frame_cnt == 0) && (EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1))) && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (EQ_16(st->nbLostCmpt, 1)) - && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) - && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) + && (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) + && (hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_SHORT - ); - Copy(st->hIGFDec.igfData.igf_curr_subframe[0][0], st->hIGFDec.igfData.igf_curr_subframe[1][0], IGF_MAX_SFB); + IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_SHORT ); + Copy(st->hIGFDec->igfData.igf_curr_subframe[0][0], st->hIGFDec->igfData.igf_curr_subframe[1][0], IGF_MAX_SFB); } /*-----------------------------------------------------------* @@ -993,33 +962,17 @@ void decoder_tcx( test(); IF ( (EQ_16(L_frame, shr(st->L_frame_fx, 1)))&&(st->tcxonly)) { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_SHORT - ); + IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_SHORT); } ELSE { IF (EQ_16(st->last_core_fx, ACELP_CORE)) { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_TRAN - ); + IGFDecCopyLPCFlatSpectrum(st->hIGFDec, x, x_e, IGF_GRID_LB_TRAN ); } ELSE { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_NORM - ); - + IGFDecCopyLPCFlatSpectrum(st->hIGFDec, x, x_e, IGF_GRID_LB_NORM ); } } } @@ -1056,7 +1009,7 @@ void decoder_tcx( } tmp32 = L_deposit_h(0); - if(st->tcxltp_last_gain_unmodified > 0) + if(hTcxDec->tcxltp_last_gain_unmodified > 0) { tmp32 = L_add(st->old_fpitch, 0); } @@ -1110,31 +1063,18 @@ void decoder_tcx( igfGridIdx = IGF_GRID_LB_NORM; } - st->hIGFDec.igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); - - IGFDecApplyMono( - &st->hIGFDec, - x, - &x_e, - igfGridIdx, - bfi - ); + st->hIGFDec->igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); + IGFDecApplyMono(st->hIGFDec, x, &x_e, igfGridIdx, bfi); } test(); test(); IF (st->igf && ((EQ_16(L_frame, shr(st->L_frame_fx, 1)))&&(st->tcxonly))) { - st->hIGFDec.igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); - IGFDecApplyMono( - &st->hIGFDec, - x, - &x_e, - IGF_GRID_LB_SHORT, - bfi - ); + st->hIGFDec->igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); + IGFDecApplyMono(st->hIGFDec,x,&x_e,IGF_GRID_LB_SHORT,bfi); } - index = tcx_cfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); + index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); /* normalize spectrum to minimize IMDCT noise */ tmp1 = s_max(s_max(L_frame,L_frameTCX), L_spec); @@ -1145,15 +1085,15 @@ void decoder_tcx( IF(st->igf) { test(); - IF(st->hIGFDec.flatteningTrigger != 0 && fUseTns == 0) + IF(st->hIGFDec->flatteningTrigger != 0 && fUseTns == 0) { - Word16 startLine = st->hIGFDec.infoIGFStartLine; - Word16 endLine = st->hIGFDec.infoIGFStopLine; + Word16 startLine = st->hIGFDec->infoIGFStartLine; + Word16 endLine = st->hIGFDec->infoIGFStopLine; Word32 x_itf[N_MAX_TCX-IGF_START_MN]; Word16 j; - const Word16* chk_sparse = st->hIGFDec.flag_sparse; - const Word32* virtualSpec = st->hIGFDec.virtualSpec; + const Word16* chk_sparse = st->hIGFDec->flag_sparse; + const Word32* virtualSpec = st->hIGFDec->virtualSpec; const Word16 maxOrder = 8; Word16 curr_order = 0; /* not counted */ @@ -1213,13 +1153,13 @@ void decoder_tcx( test(); test(); test(); - if ((tcx_cfg->fIsTNSAllowed != 0 && fUseTns != 0 && bfi == 0) || (GT_16(L_spec, L_frameTCX))) + if ((hTcxCfg->fIsTNSAllowed != 0 && fUseTns != 0 && bfi == 0) || (GT_16(L_spec, L_frameTCX))) { L = L_spec; move16(); } - tcxInvertWindowGrouping(tcx_cfg, + tcxInvertWindowGrouping(hTcxCfg, xn_buf32, x, L, @@ -1238,14 +1178,14 @@ void decoder_tcx( test(); test(); - IF ((tcx_cfg->fIsTNSAllowed != 0) && (fUseTns != 0) && bfi == 0 ) + IF ((hTcxCfg->fIsTNSAllowed != 0) && (fUseTns != 0) && bfi == 0 ) { /* Apply TNS to get the reconstructed signal */ test(); test(); - SetTnsConfig(tcx_cfg, L_frame_glob == st->L_frame_fx, (st->last_core_fx == ACELP_CORE) && (frame_cnt == 0)); + SetTnsConfig(hTcxCfg, L_frame_glob == st->L_frame_fx, (st->last_core_fx == ACELP_CORE) && (frame_cnt == 0)); - ApplyTnsFilter(tcx_cfg->pCurrentTnsConfig, &tnsData, x, 0); + ApplyTnsFilter(hTcxCfg->pCurrentTnsConfig, &tnsData, x, 0); test(); IF ((EQ_16(L_frame, shr(st->L_frame_fx, 1)))&&(st->tcxonly!=0)) @@ -1254,13 +1194,13 @@ void decoder_tcx( test(); test(); test(); - IF ((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)) + IF ((hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) || + ((hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)) ) { - tmp1 = shr(tcx_cfg->tnsConfig[0][0].iFilterBorders[0], 1); + tmp1 = shr(hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1); /* undo rearrangement of LF sub-window lines for TNS synthesis filtering */ - IF (s_max(L_frameTCX, L_spec) > tcx_cfg->tnsConfig[0][0].iFilterBorders[0]) + IF (s_max(L_frameTCX, L_spec) > hTcxCfg->tnsConfig[0][0].iFilterBorders[0]) { tmp2 = shr(s_max(L_frameTCX, L_spec), 1); Copy32(x+tmp1+8, x+tmp2+8, sub(tmp1, 8)); @@ -1290,78 +1230,23 @@ void decoder_tcx( IF(st->igf != 0) { - set32_fx( xn_buf32+st->hIGFDec.infoIGFStartLine, 0, sub(L_frameTCX, st->hIGFDec.infoIGFStartLine) ); + set32_fx( xn_buf32+st->hIGFDec->infoIGFStartLine, 0, sub(L_frameTCX, st->hIGFDec->infoIGFStartLine) ); } - IMDCT(xn_buf32, x_e, - st->syn_Overl, - st->syn_Overl_TDAC, - xn_buf, - tcx_cfg->tcx_aldo_window_1, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_aldo_window_2, - st->tcx_cfg.tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - st->tcx_cfg.tcx_mdct_window_trans, - st->tcx_cfg.tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - index, - left_rect, - tcx_offset, - overlap, - L_frame, - L_frameTCX, - shr(s_max(L_frameTCX, L_spec), 1), - L_frame_glob, - frame_cnt, - bfi, - st->old_out_LB_fx, - &st->Q_old_wtda_LB, - st, - 0, - acelp_zir); + IMDCT(xn_buf32, x_e, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, + st->hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, st->hTcxCfg->tcx_mdct_window_trans, st->hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, + index, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr(s_max(L_frameTCX, L_spec), 1), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, + &st->hHQ_core->Q_old_wtda_LB,st, 0, acelp_zir); /* Generate additional comfort noise to mask potential coding artefacts */ IF ( st->flag_cna != 0 ) { - generate_masking_noise_mdct (x, - &x_e, - st->hFdCngDec_fx->hFdCngCom, - s_max(s_max(L_frame,L_frameTCX), L_spec) - ); + generate_masking_noise_mdct (x, &x_e, st->hFdCngDec_fx->hFdCngCom, s_max(s_max(L_frame,L_frameTCX), L_spec) ); } - IMDCT(x, x_e, - st->syn_OverlFB, - st->syn_Overl_TDACFB, - xn_bufFB, - tcx_cfg->tcx_aldo_window_1_FB, - tcx_cfg->tcx_aldo_window_1_FB_trunc, - tcx_cfg->tcx_aldo_window_2_FB, - tcx_cfg->tcx_mdct_window_halfFB, - tcx_cfg->tcx_mdct_window_minimumFB, - tcx_cfg->tcx_mdct_window_transFB, - tcx_cfg->tcx_mdct_window_half_lengthFB, - tcx_cfg->tcx_mdct_window_min_lengthFB, - index, - left_rect, - tcx_offsetFB, - overlapFB, - L_frameTCX, - L_frameTCX, - shr(s_max(L_frameTCX, L_spec), 1), - L_frameTCX_glob, - frame_cnt, - bfi, - st->old_out_fx, - &st->Q_old_wtda, - st, - div_l(L_mult(FSCALE_DENOM, L_frameTCX_glob), L_frame_glob), - acelp_zir - ); - - - - + IMDCT(x, x_e, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, + hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, + index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr(s_max(L_frameTCX, L_spec), 1), L_frameTCX_glob, + frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, st, div_l(L_mult(FSCALE_DENOM, L_frameTCX_glob), L_frame_glob), acelp_zir); /* PLC: [TCX: Tonal Concealment] */ @@ -1371,27 +1256,27 @@ void decoder_tcx( st->last_tns_active = 0; move16(); test(); - if ( tcx_cfg->fIsTNSAllowed && fUseTns) + if ( hTcxCfg->fIsTNSAllowed && fUseTns) { st->last_tns_active = 1; move16(); } - st->tcxltp_third_last_pitch = st->tcxltp_second_last_pitch; + hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; move32(); - st->tcxltp_second_last_pitch = st->old_fpitch; + hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move32(); - st->old_fpitch = L_add(L_deposit_h(st->tcxltp_pitch_int), L_mult( st->tcxltp_pitch_fr, div_s(1,st->pit_res_max) /*Q16*/)); + st->old_fpitch = L_add(L_deposit_h(hTcxLtpDec->tcxltp_pitch_int), L_mult(hTcxLtpDec->tcxltp_pitch_fr, div_s(1,st->pit_res_max) /*Q16*/)); st->old_fpitchFB = Mpy_32_16_1(st->old_fpitch/*Q16*/, mult_r(L_frameTCX/*Q0*/,getInvFrameLen(L_frame)/*Q21*/)/*Q6*/)/*Q7*/; st->old_fpitchFB = L_shr(st->old_fpitchFB,7-16);/*->Q16*/ } /* Update old_syn_overl */ - IF (st->tcx_cfg.last_aldo == 0) + IF (st->hTcxCfg->last_aldo == 0) { - Copy(xn_buf+L_frame, st->syn_Overl, overlap); - Copy(xn_bufFB+L_frameTCX, st->syn_OverlFB, overlapFB); + Copy(xn_buf+L_frame, hTcxDec->syn_Overl, overlap); + Copy(xn_bufFB+L_frameTCX, hTcxDec->syn_OverlFB, overlapFB); } /* Output */ @@ -1418,6 +1303,9 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, Word16 tmp1, tmp2, s; Word32 tmp32; Word32 tmp32_1, tmp32_2; + TCX_DEC_HANDLE hTcxDec; + + hTcxDec = st_fx->hTcxDec; /* TCX output */ Copy( synth, xn_buf, st_fx->L_frame_fx ); @@ -1427,7 +1315,7 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, test(); if (!st_fx->bfi_fx && st_fx->prev_bfi_fx && EQ_16(st_fx->last_core_fx,ACELP_CORE)) { - st_fx->tcxltp_last_gain_unmodified = 0; + hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } IF (bfi != 0 && st_fx->use_partial_copy == 0) @@ -1437,19 +1325,19 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, IF ( 0 == st_fx->enablePlcWaveadjust || EQ_16(st_fx->plcInfo.concealment_method,TCX_TONAL)) { UWord32 dmy; - tmp32_1 /*gainHelperFB*/ = L_shl_r(L_deposit_h(st_fx->gainHelper) ,sub(st_fx->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensateFB*/= L_shl_r(L_deposit_h(st_fx->stepCompensate),sub(st_fx->stepCompensate_e,31-28));/*Q28*/ + tmp32_1 /*gainHelperFB*/ = L_shl_r(L_deposit_h(hTcxDec->gainHelper) ,sub(hTcxDec->gainHelper_e, 31-28));/*Q28*/ + tmp32_2 /*stepCompensateFB*/= L_shl_r(L_deposit_h(hTcxDec->stepCompensate),sub(hTcxDec->stepCompensate_e,31-28));/*Q28*/ Mpy_32_32_ss(tmp32_2/*Q28*/, L_shl(L_mult0(st_fx->L_frame_fx, - getInvFrameLen(st_fx->L_frameTCX)/*Q21*/)/*Q21*/, + getInvFrameLen(hTcxDec->L_frameTCX)/*Q21*/)/*Q21*/, 8)/*Q29*/, &tmp32_2, &dmy ); /*Q26*/ tmp32_2 = L_shl(tmp32_2,3-1); /*Q28*/ - FOR( i=0; i < st_fx->L_frameTCX; i++ ) + FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) { tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ synthFB[i] = round_fx(L_shl(Mpy_32_16_1(tmp32,synthFB[i]), 16)); @@ -1457,8 +1345,8 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, tmp32_1 = L_sub(tmp32_1 , tmp32_2); } } - tmp32_1 /*gainHelper*/ = L_shl_r(L_deposit_h(st_fx->gainHelper) ,sub(st_fx->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensate*/= L_shl_r(L_deposit_h(st_fx->stepCompensate),sub(st_fx->stepCompensate_e,31-28));/*Q28*/ + tmp32_1 /*gainHelper*/ = L_shl_r(L_deposit_h(hTcxDec->gainHelper) ,sub(hTcxDec->gainHelper_e, 31-28));/*Q28*/ + tmp32_2 /*stepCompensate*/= L_shl_r(L_deposit_h(hTcxDec->stepCompensate),sub(hTcxDec->stepCompensate_e,31-28));/*Q28*/ FOR( i=0; i < st_fx->L_frame_fx; i++ ) { tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ @@ -1472,18 +1360,18 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, * PLC: estimate and update CNG energy */ /* level_syn = (float)sqrt(( dot_product(synthFB, synthFB, L_frame)) / L_frame ); */ - s = sub(getScaleFactor16(synthFB, st_fx->L_frameTCX), 4); + s = sub(getScaleFactor16(synthFB, hTcxDec->L_frameTCX), 4); { Word64 tmp64 = 0; move64(); - FOR (i = 0; i < st_fx->L_frameTCX; i++) + FOR (i = 0; i < hTcxDec->L_frameTCX; i++) { tmp1 = shl(synthFB[i], s); tmp64 = W_mac0_16_16(tmp64, tmp1, tmp1); } tmp32 = W_sat_l(tmp64); } - tmp32 = Mpy_32_16_1(tmp32, getInvFrameLen(st_fx->L_frameTCX)); + tmp32 = Mpy_32_16_1(tmp32, getInvFrameLen(hTcxDec->L_frameTCX)); tmp2 = norm_l(tmp32); tmp1 = round_fx(L_shl(tmp32, tmp2)); s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); @@ -1503,22 +1391,22 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, Word16 Qnew_levelBackgroundTrace; Qnew_levelBackgroundTrace = 0; move16(); - minimumStatistics(st_fx->conNoiseLevelMemory, /*Q15*/ - &st_fx->conNoiseLevelIndex, /*Q0 */ - &st_fx->conCurrLevelIndex, /*Q0 */ - &st_fx->conCngLevelBackgroundTrace, /*Q15*/ - &st_fx->conLastFrameLevel, /*Q15*/ + minimumStatistics(hTcxDec->conNoiseLevelMemory, /*Q15*/ + &hTcxDec->conNoiseLevelIndex, /*Q0 */ + &hTcxDec->conCurrLevelIndex, /*Q0 */ + &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/ + &hTcxDec->conLastFrameLevel, /*Q15*/ level_syn, /*Q15*/ - st_fx->conNoiseLevelMemory_e, - st_fx->conCngLevelBackgroundTrace_e, + hTcxDec->conNoiseLevelMemory_e, + hTcxDec->conCngLevelBackgroundTrace_e, &Qnew_levelBackgroundTrace, - &st_fx->conLastFrameLevel_e, + &hTcxDec->conLastFrameLevel_e, level_syn_e /*scaling of level_syn*/ ); /*note: All parameters being different from Q0 have to have the same Q-format*/ - st_fx->conCngLevelBackgroundTrace_e = Qnew_levelBackgroundTrace; + hTcxDec->conCngLevelBackgroundTrace_e = Qnew_levelBackgroundTrace; move16(); } @@ -1539,8 +1427,8 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, IF(level_syn != 0) { BASOP_Util_Divide_MantExp ( - st_fx->conCngLevelBackgroundTrace, - st_fx->conCngLevelBackgroundTrace_e, + hTcxDec->conCngLevelBackgroundTrace, + hTcxDec->conCngLevelBackgroundTrace_e, level_syn, level_syn_e, &gainCNG, @@ -1564,42 +1452,42 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, if ((EQ_16(st_fx->nbLostCmpt, 1))) { - st_fx->conceal_eof_gain = 16384/*1.0f Q14*/; /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = 16384/*1.0f Q14*/; /*Q14*/ move16(); } /* step = (st_fx->conceal_eof_gain - ( st_fx->conceal_eof_gain * st_fx->damping + gainCNG * (1 - st_fx->damping) )) / st_fx->L_frame_fx; */ tmp2 = BASOP_Util_Add_MantExp( - mult_r(st_fx->conceal_eof_gain /*Q14*/, - st_fx->damping /*Q14*/), + mult_r(hTcxDec->conceal_eof_gain /*Q14*/, + hTcxDec->damping /*Q14*/), 15-13/*->Q15*/, - mult_r(gainCNG/*Q15*/,sub(0x4000,st_fx->damping/*Q14*/)) /*Q14*/, + mult_r(gainCNG/*Q15*/,sub(0x4000, hTcxDec->damping/*Q14*/)) /*Q14*/, add(gainCNG_e,15-14)/*->Q15*/, &tmp1); - tmp2 = BASOP_Util_Add_MantExp(st_fx->conceal_eof_gain, 15-14, negate(tmp1), tmp2, &tmp1); + tmp2 = BASOP_Util_Add_MantExp(hTcxDec->conceal_eof_gain, 15-14, negate(tmp1), tmp2, &tmp1); step = L_shl(L_mult(tmp1, getInvFrameLen(st_fx->L_frame_fx)), sub(tmp2,6/*scaling from table lookup*/ +1/*go to Q30*/)); /*Q30*/ { Word32 stepFB; UWord32 dmy; - conceal_eof_gainFB = L_deposit_h(st_fx->conceal_eof_gain); /*Q30*/ - Mpy_32_32_ss(step,L_shl(L_mult0(st_fx->L_frame_fx, getInvFrameLen(st_fx->L_frameTCX)),8),&stepFB ,&dmy ); + conceal_eof_gainFB = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ + Mpy_32_32_ss(step,L_shl(L_mult0(st_fx->L_frame_fx, getInvFrameLen(hTcxDec->L_frameTCX)),8),&stepFB ,&dmy ); stepFB = L_shl(stepFB,3-1); /*Q30*/ - FOR( i=0; i < st_fx->L_frameTCX; i++ ) + FOR( i=0; i < hTcxDec->L_frameTCX; i++ ) { synthFB[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gainFB, synthFB[i]),1)); move16(); conceal_eof_gainFB = L_sub(conceal_eof_gainFB, stepFB); } } - conceal_eof_gain32 = L_deposit_h(st_fx->conceal_eof_gain); /*Q30*/ + conceal_eof_gain32 = L_deposit_h(hTcxDec->conceal_eof_gain); /*Q30*/ FOR( i=0; i < st_fx->L_frame_fx; i++ ) { xn_buf[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gain32 /*Q30*/, xn_buf[i]),1)); move16(); conceal_eof_gain32 = L_sub(conceal_eof_gain32,step); } - st_fx->conceal_eof_gain = round_fx(conceal_eof_gain32); /*Q14*/ move16(); + hTcxDec->conceal_eof_gain = round_fx(conceal_eof_gain32); /*Q14*/ move16(); /* run lpc gain compensation not for waveform adjustment */ test(); IF ( 0 == st_fx->enablePlcWaveadjust || EQ_16(st_fx->plcInfo.concealment_method,TCX_TONAL)) { @@ -1615,7 +1503,7 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, st_fx->plcInfo.step_concealgain_fx = round_fx(L_shl(L_mult0( round_fx(step), - round_fx(L_shl(L_mult0(st_fx->L_frame_fx, getInvFrameLen(st_fx->L_frameTCX)),8))),3)); /*Q15*/ + round_fx(L_shl(L_mult0(st_fx->L_frame_fx, getInvFrameLen(hTcxDec->L_frameTCX)),8))),3)); /*Q15*/ } /*-----------------------------------------------------------* @@ -1625,10 +1513,8 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, /* Update synth, exc and old_Aq */ tcx_decoder_memory_update(xn_buf, /*Q0*/ synth, /*Q0*/ - st_fx->L_frame_fx, A, st_fx, - st_fx->syn, /*Q0*/ 0 ); @@ -1654,7 +1540,7 @@ void decoder_tcx_post(Decoder_State_fx *st_fx, { st_fx->mem_pitch_gain[2*st_fx->nb_subfr-1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i]; move16(); - st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i] = st_fx->tcxltp_last_gain_unmodified; + st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i] = hTcxDec->tcxltp_last_gain_unmodified; move16(); } } @@ -1721,7 +1607,7 @@ static void IMDCT(Word32 *x, Word16 x_e, Word16 fullbandScale, Word16 *acelp_zir) { - const TCX_config *tcx_cfg = &st->tcx_cfg; + const TCX_CONFIG_HANDLE tcx_cfg = st->hTcxCfg; Word16 tmp_offset; Word16 tmp1, tmp2, tmp3, *tmpP16; Word32 tmp32; @@ -1729,6 +1615,9 @@ static void IMDCT(Word32 *x, Word16 x_e, Word16 i; Word16 nz; Word16 aldo=0; + TCX_DEC_HANDLE hTcxDec; + + hTcxDec = st->hTcxDec; /* number of zero for ALDO windows*/ tmp32 = L_add(st->sr_core, 0); @@ -1746,7 +1635,7 @@ static void IMDCT(Word32 *x, Word16 x_e, } test(); - IF ((EQ_16(L_frameTCX, shr(st->L_frameTCX, 1)))&&(st->tcxonly!=0)) + IF ((EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)))&&(st->tcxonly!=0)) { /* Mode decision in PLC @@ -1790,7 +1679,7 @@ static void IMDCT(Word32 *x, Word16 x_e, FOR (w = 0; w < 2 ; w++) { - TCX_MDCT_Inverse(x+L_mult0(w,L_spec_TCX5), sub(x_e,TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM),win, L_ola, sub(L_win,L_ola), L_ola); + TCX_MDCT_Inverse(x+L_mult0(w,L_spec_TCX5), sub(x_e,TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM),win, L_ola, sub(L_win,L_ola), L_ola, st->element_mode); tmp1 = left_rect; move16(); @@ -1835,7 +1724,7 @@ static void IMDCT(Word32 *x, Word16 x_e, tmp1, tmp2, acelp_zir, - st->old_syn_Overl, + hTcxDec->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8_fx, tcx_mdct_window_trans, @@ -1889,7 +1778,7 @@ static void IMDCT(Word32 *x, Word16 x_e, TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), win + L_win, - 0, sub(L_win, shr(L_ola, 1)), L_ola); + 0, sub(L_win, shr(L_ola, 1)), L_ola, st->element_mode); set16_fx(xn_buf, 0, shr(overlap,1)); /* copy new sub-window region not overlapping with previous window */ @@ -1898,7 +1787,7 @@ static void IMDCT(Word32 *x, Word16 x_e, /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ TCX_MDCT_Inverse(x + L_spec_TCX5, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), win, - L_ola, sub(L_win, L_ola), L_ola); + L_ola, sub(L_win, L_ola), L_ola, st->element_mode); tcx_windowing_synthesis_current_frame(win, tcx_aldo_window_2, @@ -1910,7 +1799,7 @@ static void IMDCT(Word32 *x, Word16 x_e, 0, /* left_rect */ MIN_OVERLAP, /* left_mode */ acelp_zir, - st->old_syn_Overl, + hTcxDec->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8_fx, tcx_mdct_window_trans, @@ -1962,7 +1851,7 @@ static void IMDCT(Word32 *x, Word16 x_e, left_rect, 0, /* left_mode */ acelp_zir, - st->old_syn_Overl, + hTcxDec->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8_fx, tcx_mdct_window_trans, @@ -1977,9 +1866,7 @@ static void IMDCT(Word32 *x, Word16 x_e, ELSE /* default i.e. maximum overlap, single transform, no grouping */ { - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf, - overlap, sub(L_frame, overlap), overlap); + TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM),xn_buf, overlap, sub(L_frame, overlap), overlap, st->element_mode); tmp1 = index; move16(); @@ -2018,7 +1905,7 @@ static void IMDCT(Word32 *x, Word16 x_e, left_rect, tmp1, acelp_zir, - st->old_syn_Overl, + hTcxDec->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8_fx, tcx_mdct_window_trans, @@ -2034,7 +1921,7 @@ static void IMDCT(Word32 *x, Word16 x_e, { assert(frame_cnt == 0); - IF (NE_16(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP)) + IF (NE_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) { Word32 tmp_buf[L_FRAME_PLUS]; Word16 Q; @@ -2095,8 +1982,7 @@ static void IMDCT(Word32 *x, Word16 x_e, ELSE { - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf, overlap, sub(L_frame, overlap), overlap); + TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), xn_buf, overlap, sub(L_frame, overlap), overlap, st->element_mode); /*-----------------------------------------------------------* @@ -2120,7 +2006,7 @@ static void IMDCT(Word32 *x, Word16 x_e, left_rect, tcx_cfg->tcx_last_overlap_mode, acelp_zir, - st->old_syn_Overl, + hTcxDec->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8_fx, tcx_mdct_window_trans, @@ -2139,7 +2025,7 @@ static void IMDCT(Word32 *x, Word16 x_e, { test(); test(); - IF (((EQ_16(L_frameTCX, shr(st->L_frameTCX, 1)))&&(st->tcxonly!=0))||(EQ_16(st->tcx_cfg.tcx_last_overlap_mode,TRANSITION_OVERLAP))) + IF (((EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)))&&(st->tcxonly!=0))||(EQ_16(st->hTcxCfg->tcx_last_overlap_mode,TRANSITION_OVERLAP))) { test(); test(); @@ -2292,9 +2178,7 @@ static void IMDCT(Word32 *x, Word16 x_e, } } /* aldo must not become 0 unless for TCX10 and frames after tansistion frames */ - assert( aldo != 0 || - (L_frameTCX == st->L_frameTCX >> 1 && st->tcxonly) || - st->tcx_cfg.tcx_last_overlap_mode == TRANSITION_OVERLAP); + assert( aldo != 0 || (L_frameTCX == hTcxDec->L_frameTCX >> 1 && st->tcxonly) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP); } ELSE { @@ -2314,8 +2198,8 @@ static void IMDCT(Word32 *x, Word16 x_e, test(); test(); IF ( (aldo == 0) && - ((EQ_16(L_frameTCX, shr(st->L_frameTCX, 1)) && frame_cnt > 0) || - NE_16(L_frameTCX, shr(st->L_frameTCX, 1)) ) ) + ((EQ_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)) && frame_cnt > 0) || + NE_16(L_frameTCX, shr(hTcxDec->L_frameTCX, 1)) ) ) { /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ FOR (i = 0; i < nz; i++) @@ -2353,7 +2237,7 @@ static void IMDCT(Word32 *x, Word16 x_e, } if (fullbandScale != 0) { - st->tcx_cfg.last_aldo = aldo; + st->hTcxCfg->last_aldo = aldo; move16(); } @@ -2372,13 +2256,13 @@ static void IMDCT(Word32 *x, Word16 x_e, FOR (i = 0; i < tmp3; i++) { xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r( st->syn_OverlFB[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); + xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r( st->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); + xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); move16(); } } @@ -2389,13 +2273,13 @@ static void IMDCT(Word32 *x, Word16 x_e, FOR (i = 0; i < tmp3; i++) { xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[i].v.im ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r( st->syn_Overl[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); + xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); move16(); } FOR ( ; i < tcx_mdct_window_half_length; i++) { xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r( st->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); + xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r(hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); move16(); } } diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index c7f6c68..a722e0b 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*======================================================================*/ /* FUNCTION : decod_tran_fx() */ @@ -34,20 +33,19 @@ /*=======================================================================*/ void decod_tran_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + Decoder_State_fx *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 tc_subfr_fx, /* i : TC subframe index */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ Word16 *voice_factors_fx, /* o : voicing factors */ Word16 *exc_fx, /* i/o: adapt. excitation exc */ Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ Word16 *unbits, /* i/o: number of unused bits */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 *gain_buf + const Word16 sharpFlag, /* i : formant sharpening flag */ + Word16 *gain_buf /* o : floating pitch gain for each subframe */ ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ @@ -68,6 +66,11 @@ void decod_tran_fx( Word16 gain_code16; Word32 L_tmp; Word16 tmp16, tmp1_fx, tmp_fx; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; + MUSIC_POSTFILT_HANDLE hMusicPF; + hMusicPF = st_fx->hMusicPF; + gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -97,31 +100,27 @@ void decod_tran_fx( tmp16 = sub(2, st_fx->Q_exc); Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, tmp16); Scale_sig(bwe_exc_fx-PIT16k_MAX*2, PIT16k_MAX*2, tmp16); - Scale_sig(st_fx->last_exc_dct_in_fx, L_FRAME, tmp16); + Scale_sig(hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16); st_fx->Q_exc = add(st_fx->Q_exc,tmp16); } - transition_dec_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, i_subfr, coder_type_fx, tc_subfr_fx, &Jopt_flag, exc_fx, + transition_dec_fx( st_fx, 0, L_frame_fx, i_subfr, tc_subfr_fx, &Jopt_flag, exc_fx, &T0, &T0_frac, &T0_min, &T0_max, &pt_pitch_fx, &position, bwe_exc_fx, &st_fx->Q_exc ); - /*-----------------------------------------------------------------* * Transform domain contribution decoding - active frames *-----------------------------------------------------------------*/ - - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)) + IF( GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC)) { gain_code_fx = 0; move16(); - transf_cdbk_dec_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, 0, i_subfr, tc_subfr_fx, - Es_pred_fx, gain_code_fx, &st_fx->mem_preemp_preQ_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits); + transf_cdbk_dec_fx( st_fx, 0, i_subfr, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits); } /*-----------------------------------------------------------------* * ACELP codebook search + pitch sharpening *-----------------------------------------------------------------*/ - inov_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, coder_type_fx, - sharpFlag, i_subfr, tc_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx ); + inov_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, sharpFlag, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR); /*-----------------------------------------------------------------* * De-quantize the gains @@ -131,19 +130,18 @@ void decod_tran_fx( IF( Jopt_flag == 0 ) { /* 2/3-bit decoding */ - gain_dec_tc_fx( st_fx, st_fx->core_brate_fx, code_fx, L_frame_fx, i_subfr, tc_subfr_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); + gain_dec_tc_fx( st_fx, code_fx, i_subfr,Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx); } ELSE { /* 5-bit decoding */ IF( GT_32(st_fx->core_brate_fx,ACELP_32k)) { - gain_dec_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr, tc_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); + gain_dec_SQ_fx( st_fx, i_subfr, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } ELSE { - gain_dec_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type_fx, i_subfr, tc_subfr_fx , code_fx, - Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); + gain_dec_mless_fx( st_fx, L_frame_fx, st_fx->coder_type_fx, i_subfr, tc_subfr_fx , code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } } @@ -159,23 +157,22 @@ void decod_tran_fx( IF ( EQ_16(L_frame_fx,L_FRAME)) /* Rescaling for 12.8k core */ { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, coder_type_fx ); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type_fx ); } ELSE /* Rescaling for 16k core */ { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, coder_type_fx ); + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr,st_fx->coder_type_fx ); } gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx ); + Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR); /*-----------------------------------------------------------------* * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)) + IF(GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC)) { tmp1_fx = add(15-Q_AVQ_OUT_DEC-2,st_fx->Q_exc); FOR( i = 0; i < L_SUBFR; i++ ) @@ -197,7 +194,7 @@ void decod_tran_fx( prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[i_subfr/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0, T0_frac, coder_type_fx, st_fx->core_brate_fx ); + st_fx->Q_exc, T0, T0_frac, st_fx->coder_type_fx, st_fx->core_brate_fx ); /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) @@ -209,8 +206,8 @@ void decod_tran_fx( } ELSE { - enhancer_fx( st_fx->core_brate_fx, 0, coder_type_fx, i_subfr, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); + enhancer_fx( st_fx->core_brate_fx, 0, st_fx->coder_type_fx, i_subfr, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx, + norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); } p_Aq_fx += (M+1); diff --git a/lib_dec/dec_uv.c b/lib_dec/dec_uv.c index 2ab1995..bf67a7d 100644 --- a/lib_dec/dec_uv.c +++ b/lib_dec/dec_uv.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * decod_unvoiced() @@ -14,16 +13,16 @@ *-------------------------------------------------------------------*/ void decod_unvoiced_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type_fx, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx /* Q_X i/o: excitation for SWB TBE */ - ,Word16 *gain_buf + Decoder_State_fx *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + const Word16 coder_type_fx, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + Word16 *gain_buf ) { Word16 gain_pit_fx = 0; /* Quantized pitch gain */ @@ -54,8 +53,7 @@ void decod_unvoiced_fx( * Unvoiced subframe processing *----------------------------------------------------------------*/ - gaus_dec_fx( st_fx, st_fx->core_brate_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, - &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, + gaus_dec_fx( st_fx, i_subfr_fx, code_fx, &norm_gain_code_fx,&st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx,&(st_fx->Q_exc),st_fx->Q_subfr ); *tmp_noise_fx = extract_h(norm_gain_code_fx); /*Q16*/ diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 916ec42..1752e1e 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -2,8 +2,7 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include "options.h" #include "prot_fx.h" #include "stat_dec_fx.h" @@ -15,13 +14,12 @@ * decision_matrix_dec() * * ACELP/HQ core selection - * Read ACELP signalling bits from the bitstream + * Read ACELP signaling bits from the bitstream * Set extension layers *-----------------------------------------------------------------*/ void decision_matrix_dec_fx( Decoder_State_fx *st, /* i/o: decoder state structure */ - Word16 *coder_type, /* o : coder type */ Word16 *sharpFlag, /* o : formant sharpening flag */ Word16 *hq_core_type, /* o : HQ core type */ Word16 *core_switching_flag/* o : ACELP->HQ switching frame flag */ @@ -33,6 +31,7 @@ void decision_matrix_dec_fx( Word16 nBits; Word16 tmp16, temp_core; + /* init */ st->core_fx = -1; move16(); st->core_brate_fx = L_deposit_l(0); @@ -152,7 +151,7 @@ void decision_matrix_dec_fx( { st->ppp_mode_dec_fx = 1; move16(); - *coder_type = VOICED; + st->coder_type_fx = VOICED; move16(); st->bwidth_fx = NB; move16(); @@ -161,7 +160,7 @@ void decision_matrix_dec_fx( { st->ppp_mode_dec_fx = 1; move16(); - *coder_type = VOICED; + st->coder_type_fx = VOICED; move16(); st->bwidth_fx = WB; move16(); @@ -170,7 +169,7 @@ void decision_matrix_dec_fx( { st->nelp_mode_dec_fx = 1; move16(); - *coder_type = UNVOICED; + st->coder_type_fx = UNVOICED; move16(); st->bwidth_fx = NB; move16(); @@ -179,7 +178,7 @@ void decision_matrix_dec_fx( { st->nelp_mode_dec_fx = 1; move16(); - *coder_type = UNVOICED; + st->coder_type_fx = UNVOICED; move16(); st->bwidth_fx = WB; move16(); @@ -215,12 +214,12 @@ void decision_matrix_dec_fx( } /*-----------------------------------------------------------------* - * Read ACELP signalling bits from the bitstream + * Read ACELP signaling bits from the bitstream *-----------------------------------------------------------------*/ IF( EQ_16(st->core_fx,ACELP_CORE)) { - /* find the section in the ACELP signalling table corresponding to bitrate */ + /* find the section in the ACELP signaling table corresponding to bitrate */ start_idx = 0; move16(); WHILE( NE_32(acelp_sig_tbl[start_idx],st->total_brate_fx)) @@ -253,13 +252,12 @@ void decision_matrix_dec_fx( } ELSE { - /* retrieve the signalling indice */ + /* retrieve the signaling indice */ ind = acelp_sig_tbl[start_idx]; - /* convert signalling indice into signalling information */ - *coder_type = extract_l(L_and(ind,0x7L)); - - IF( EQ_16(*coder_type,LR_MDCT)) + /* convert signaling indice into signaling information */ + st->coder_type_fx = extract_l(L_and(ind,0x7L)); + IF(EQ_16(st->coder_type_fx, LR_MDCT)) { st->core_fx = HQ_CORE; move16(); @@ -273,7 +271,7 @@ void decision_matrix_dec_fx( } } - /* detect corrupted signalling (due to bit errors) */ + /* detect corrupted signaling (due to bit errors) */ test(); test(); test(); @@ -294,10 +292,10 @@ void decision_matrix_dec_fx( ( GE_32(ind,1<<7) ) || ( LE_32(st->total_brate_fx,ACELP_13k20) && EQ_16(st->bwidth_fx,FB) ) || ( GE_32(st->total_brate_fx,ACELP_32k) && EQ_16(st->bwidth_fx,NB) ) || - ( GE_32(st->total_brate_fx,ACELP_32k) && !(EQ_16(*coder_type,GENERIC) || EQ_16(*coder_type,TRANSITION) || EQ_16(*coder_type,INACTIVE) ) ) || - ( LT_32(st->total_brate_fx,ACELP_13k20) && NE_16(st->bwidth_fx,NB) && EQ_16(*coder_type,LR_MDCT) ) || - ( GE_32(st->total_brate_fx,ACELP_13k20) && EQ_16(*coder_type,UNVOICED) ) || - ( GE_32(st->total_brate_fx,ACELP_13k20) && EQ_16(*coder_type,AUDIO) && EQ_16(st->bwidth_fx,NB) ) + ( GE_32(st->total_brate_fx,ACELP_32k) && !(EQ_16(st->coder_type_fx,GENERIC) || EQ_16(st->coder_type_fx,TRANSITION) || EQ_16(st->coder_type_fx,INACTIVE) ) ) || + ( LT_32(st->total_brate_fx,ACELP_13k20) && NE_16(st->bwidth_fx,NB) && EQ_16(st->coder_type_fx,LR_MDCT) ) || + ( GE_32(st->total_brate_fx,ACELP_13k20) && EQ_16(st->coder_type_fx,UNVOICED) ) || + ( GE_32(st->total_brate_fx,ACELP_13k20) && EQ_16(st->coder_type_fx,AUDIO) && EQ_16(st->bwidth_fx,NB) ) ) { st->BER_detect = 0; @@ -318,7 +316,7 @@ void decision_matrix_dec_fx( } ELSE IF( EQ_32(st->last_total_brate_fx, -1)) /* can happen in case of BER when no good frame was received before */ { - *coder_type = st->last_coder_type_fx; + st->coder_type_fx = st->last_coder_type_fx; move16(); st->bwidth_fx = st->last_bwidth_fx; move16(); @@ -355,7 +353,7 @@ void decision_matrix_dec_fx( } ELSE { - *coder_type = st->last_coder_type_fx; + st->coder_type_fx = st->last_coder_type_fx; move16(); st->bwidth_fx = st->last_bwidth_fx; move16(); @@ -508,7 +506,7 @@ void decision_matrix_dec_fx( st->core_brate_fx = L_sub(st->total_brate_fx,st->extl_brate_fx); /*-----------------------------------------------------------------* - * Read HQ signalling bits from the bitstream + * Read HQ signaling bits from the bitstream * Set HQ core type *-----------------------------------------------------------------*/ @@ -571,7 +569,7 @@ void decision_matrix_dec_fx( } } - /* detect bit errors in signalling */ + /* detect bit errors in signaling */ test(); test(); test(); @@ -653,14 +651,14 @@ void decision_matrix_dec_fx( st->L_frame_fx = st->last_L_frame_fx; move16(); } - ELSE IF( EQ_32(st->core_brate_fx,SID_2k40)&&EQ_16(st->bwidth_fx,WB)&&st->first_CNG_fx&<_16(st->act_cnt2_fx,MIN_ACT_CNG_UPD)) + ELSE IF( EQ_32(st->core_brate_fx,SID_2k40)&&EQ_16(st->bwidth_fx,WB)&&st->first_CNG_fx&<_16(st->hTdCngDec->act_cnt2_fx,MIN_ACT_CNG_UPD)) { /* prevent "L_frame" changes in SID frame after short segment of active frames */ st->L_frame_fx = st->last_CNG_L_frame_fx; move16(); } ELSE IF( ( EQ_32(st->core_brate_fx,SID_2k40)&&GE_32(st->total_brate_fx,ACELP_9k60)&&EQ_16(st->bwidth_fx,WB))|| - ( GT_32(st->total_brate_fx,ACELP_24k40) && LT_32(st->total_brate_fx,HQ_96k) ) || ( EQ_32(st->total_brate_fx,ACELP_24k40) && GE_16(st->bwidth_fx,WB) ) ) + ( GE_32(st->total_brate_fx, ACELP_32k) && LT_32(st->total_brate_fx,HQ_96k) ) || ( EQ_32(st->total_brate_fx,ACELP_24k40) && GE_16(st->bwidth_fx,WB) ) ) { st->L_frame_fx = L_FRAME16k; move16(); @@ -678,7 +676,10 @@ void decision_matrix_dec_fx( st->nb_subfr = NB_SUBFR16k; move16(); } - +#if 1//def ADD_IVAS_BWE 0> NEEDED for IO with conf_acelp1 + st->extl_orig = st->extl_fx; + st->extl_brate_orig = st->extl_brate_fx; +#endif test(); IF( EQ_32(st->output_Fs_fx,8000)) { diff --git a/lib_dec/decoder.c b/lib_dec/decoder.c index 46949df..2018011 100644 --- a/lib_dec/decoder.c +++ b/lib_dec/decoder.c @@ -97,8 +97,9 @@ int main(int argc, char *argv[]) /*------------------------------------------------------------------------------------------* * Regular EVS decoder with ITU-T G.192 bitstream *------------------------------------------------------------------------------------------*/ - - init_decoder_fx(st_fx); + PMT("Find a proper place to initialize mct_chan_mode") + st_fx->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + init_decoder_fx(st_fx, EVS_MONO); /* output frame length */ output_frame = st_fx->output_frame_fx; @@ -107,7 +108,11 @@ int main(int argc, char *argv[]) { /* calculate the compensation (decoded signal aligned with original signal) */ /* the number of first output samples will be reduced by this amount */ - dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx)); +#ifdef SPLIT_REND_WITH_HEAD_ROT + dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx, MONO_FORMAT, NULL, AUDIO_CONFIG_MONO)); +#else + dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx, MONO_FORMAT, NULL)); +#endif } else { @@ -244,7 +249,7 @@ int main(int argc, char *argv[]) set16_fx( output, 0, zero_pad ); fwrite( output, sizeof(Word16), zero_pad, f_synth ); BASOP_init - destroy_decoder( st_fx ); + destroy_cldfb_decoder( st_fx ); BASOP_end_noprint } diff --git a/lib_dec/dlpc_avq.c b/lib_dec/dlpc_avq.c index a836f4e..db64e90 100644 --- a/lib_dec/dlpc_avq.c +++ b/lib_dec/dlpc_avq.c @@ -3,16 +3,14 @@ ====================================================================================*/ -/* Header files */ +#include +#include "options.h" #include -#include -#include -#include "stl.h" #include "prot_fx.h" -/* Constants */ -#define M 16 /* length of LPC */ + /* Constants */ +#define M 16 /* length of LPC */ #define BFI_FAC 29491/*0.9f Q15*/ /***********************************************/ @@ -20,10 +18,10 @@ /***********************************************/ Word16 dlpc_avq( - Word16 *index, /* (i) Quantization indices */ - Word16 *LSF_Q, /* (o) Quantized LSF vectors */ - Word16 numlpc, /* (i) Number of sets of lpc */ - Word32 sr_core + Word16 *index, /* i : Quantization indices */ + Word16 *LSF_Q, /* o : Quantized LSF vectors */ + Word16 numlpc, /* i : Number of sets of lpc */ + Word32 sr_core /* i : Core sampling rate */ ) { Word16 i, nbi, last; @@ -93,7 +91,10 @@ Word16 dlpc_avq( return (Word16)(p_index-index); } -static Word16 unary_decode(Decoder_State_fx *st, Word16 *ind) +static Word16 unary_decode( + Decoder_State_fx *st, + Word16 *ind +) { Word16 start_bit_pos; @@ -122,7 +123,11 @@ static Word16 unary_decode(Decoder_State_fx *st, Word16 *ind) } -static Word16 pack4bits(Word16 nbits, Decoder_State_fx *st, Word16 *prm) +static Word16 pack4bits( + Word16 nbits, + Decoder_State_fx *st, + Word16 *prm +) { Word16 i; @@ -145,12 +150,24 @@ static Word16 pack4bits(Word16 nbits, Decoder_State_fx *st, Word16 *prm) return(i); } -Word16 decode_lpc_avq( Decoder_State_fx *st, Word16 numlpc, Word16 *param_lpc ) +Word16 decode_lpc_avq( + Decoder_State_fx *st, /* i/o: decoder state structure */ + const Word16 numlpc, /* i : Number of sets of lpc */ + Word16* param_lpc /* o : lpc parameters */ +#ifdef IVAS_CODE_AVQ_LPC + ,const int16_t ch, /* i : channel */ + const int16_t element_mode, /* i : element mode */ + const int16_t sns_low_br_mode /* i : SNS low-bitrate mode */ +#endif +) { Word16 k,j; Word16 nb, qn1, qn2, avqBits, q_type; Word16 start_bit_pos; - +#ifdef IVAS_CODE_AVQ_LPC + Word16 stereo_mode = 0; +#endif + move16(); move16(); move16(); j = 0; @@ -176,98 +193,149 @@ Word16 decode_lpc_avq( Decoder_State_fx *st, Word16 numlpc, Word16 *param_lpc ) param_lpc[j] = q_type; j = add(j,1); } - - /* Decode quantization indices */ - - IF (q_type==0) +#ifdef IVAS_CODE_AVQ_LPC + test(); + IF (EQ_16(element_mode, IVAS_CPE_MDCT) && k == 0) { - /* Absolute quantizer with 1st stage stochastic codebook */ + stereo_mode = ch; + move16(); + if (ch == 0) + { + stereo_mode = param_lpc[j]; + move16(); + } + param_lpc[j++] = stereo_mode; move16(); - param_lpc[j] = get_next_indice_fx(st, 8); - j = add(j,1); } +#endif + /* Decode quantization indices */ - /* 2 bits to specify Q2,Q3,Q4,ext */ - qn1 = add(2, get_next_indice_fx(st, 2)); - qn2 = add(2, get_next_indice_fx(st, 2)); - - /* Unary code */ - /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ - - IF ( GT_16(qn1,4)) + IF (q_type==0) { - nb = unary_decode(st, &qn1); - - if ( EQ_16(nb,1)) - { - qn1 = add(qn1, 5); - } - if (EQ_16(nb,2)) - { - qn1 = add(qn1, 4); - } - if ( EQ_16(nb,3)) + /* Absolute quantizer with 1st stage stochastic codebook */ +#ifdef IVAS_CODE_AVQ_LPC + IF (EQ_16(element_mode, IVAS_CPE_MDCT)) { + IF (NE_16(stereo_mode, 3) ) + { + param_lpc[j] = get_next_indice_fx(st, SNS_ABS_QUANT_BITS); + } + ELSE + { + param_lpc[j] = sub(get_next_indice_fx(st, 1), 2); + } move16(); - qn1 = 0; } - if ( GT_16(nb,3)) + ELSE +#endif { - qn1 = add(qn1, 3); + move16(); + param_lpc[j] = get_next_indice_fx(st, 8); } + j = add(j,1); } - - IF ( GT_16(qn2,4)) + /* + * 2nd stage decoding is skipped if: + * - we are in low bitrate mode and no joint SNS coding is used + * - OR the side-SNS-is-zero flag is set for joint SNS + */ +#ifdef IVAS_CODE_AVQ_LPC + IF(NE_16(element_mode, IVAS_CPE_MDCT) || (!(sns_low_br_mode && (EQ_16(stereo_mode, 0) || EQ_16(stereo_mode, 1)) && !(EQ_16(q_type, 0) && EQ_16(param_lpc[j - 1], -2)))) +#endif { - nb = unary_decode(st, &qn2); + /* 2 bits to specify Q2,Q3,Q4,ext */ + qn1 = add(2, get_next_indice_fx(st, 2)); + qn2 = add(2, get_next_indice_fx(st, 2)); + + /* Unary code */ + /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ - if ( EQ_16(nb,1)) + IF(GT_16(qn1, 4)) { - qn2 = add(qn2, 5); + nb = unary_decode(st, &qn1); + + if (EQ_16(nb, 1)) + { + qn1 = add(qn1, 5); + } + if (EQ_16(nb, 2)) + { + qn1 = add(qn1, 4); + } + if (EQ_16(nb, 3)) + { + move16(); + qn1 = 0; + } + if (GT_16(nb, 3)) + { + qn1 = add(qn1, 3); + } } - if (EQ_16(nb,2)) + + IF(GT_16(qn2, 4)) { - qn2 = add(qn2, 4); + nb = unary_decode(st, &qn2); + + if (EQ_16(nb, 1)) + { + qn2 = add(qn2, 5); + } + if (EQ_16(nb, 2)) + { + qn2 = add(qn2, 4); + } + if (EQ_16(nb, 3)) + { + move16(); + qn2 = 0; + } + if (GT_16(nb, 3)) + { + qn2 = add(qn2, 3); + } } - if ( EQ_16(nb,3)) + + /* check for potential bit errors */ + test(); + IF((GT_16(qn1, NB_SPHERE)) || (GT_16(qn2, NB_SPHERE))) { + qn1 = 0; move16(); qn2 = 0; + move16(); + st->BER_detect = 1; + move16(); } - if ( GT_16(nb,3)) - { - qn2 = add(qn2, 3); - } - } - /* check for potential bit errors */ - test(); - IF( (GT_16(qn1, NB_SPHERE))||(GT_16(qn2,NB_SPHERE))) - { - qn1 = 0; move16(); - qn2 = 0; + param_lpc[j] = qn1; + j = add(j, 1); move16(); - st->BER_detect = 1; - move16(); - } - - move16(); - param_lpc[j] = qn1; - j = add(j, 1); - move16(); - param_lpc[j] = qn2; - j = add(j, 1); + param_lpc[j] = qn2; + j = add(j, 1); - /* Decode Split-by-2 algebraic VQ */ - avqBits = shl(qn1,2); + /* Decode Split-by-2 algebraic VQ */ + avqBits = shl(qn1, 2); - pack4bits(avqBits, st, ¶m_lpc[j]); - j = add(j, qn1); + pack4bits(avqBits, st, ¶m_lpc[j]); + j = add(j, qn1); - avqBits = shl(qn2,2); - pack4bits(avqBits, st, ¶m_lpc[j]); - j = add(j, qn2); + avqBits = shl(qn2, 2); + pack4bits(avqBits, st, ¶m_lpc[j]); + j = add(j, qn2); + } +#ifdef IVAS_CODE_AVQ_LPC + ELSE + { + param_lpc[j] = 0; + j = add(j, 1); + param_lpc[j] = 0; + j = add(j, 1); + move16(); + move16(); + } +#endif } return sub(st->next_bit_pos_fx, start_bit_pos); diff --git a/lib_dec/dlpc_stoch.c b/lib_dec/dlpc_stoch.c index f42f519..bb32cf4 100644 --- a/lib_dec/dlpc_stoch.c +++ b/lib_dec/dlpc_stoch.c @@ -5,42 +5,26 @@ /* Header files */ #include -#include -#include -#include "stl.h" +#include +#include "options.h" #include "basop_util.h" #include "prot_fx.h" /* Constants */ #define M 16 - #define BFI_FAC 0.9f void lpc_unquantize( Decoder_State_fx * st, - Word16 *lsfold, - Word16 *lspold, Word16 *lsf, Word16 *lsp, const Word16 m, - const Word16 lpcQuantization, - Word16 *param_lpc, - const Word16 numlpc, - const Word16 core, - Word16 *mem_MA, - Word16 * mem_AR, + Word16* param_lpc, Word16 *lspmid, Word16 *lsfmid, Word16 coder_type, - Word16 acelp_midLpc, - Word8 narrow_band, - Word16 *seed_acelp, - Word32 sr_core, - Word16 *mid_lsf_int, - Word16 prev_bfi, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *safety_net + Word16 *LSF_Q_prediction /* o : LSF prediction mode */ ) { Word16 nb_indices, k; @@ -49,70 +33,74 @@ void lpc_unquantize( nb_indices = 0; /* to avoid compilation warnings */ - Copy(lsfold, &lsf[0], m); - Copy(lspold, &lsp[0], m); + Copy(st->lsf_old_fx, &lsf[0], m); + Copy(st->lsp_old_fx, &lsp[0], m); - IF( lpcQuantization == 0 ) + IF(st->lpcQuantization == 0 ) { - nb_indices = dlpc_avq(param_lpc, &lsf[m], numlpc, st->sr_core); - FOR ( k=0; knumlpc, st->sr_core); + FOR ( k=0; k< st->numlpc; k++ ) { E_LPC_lsf_lsp_conversion(&lsf[(k+1)*m], &lsp[(k+1)*m], m); } } - ELSE IF ( EQ_16(lpcQuantization, 1)) + ELSE IF ( EQ_16(st->lpcQuantization, 1)) { test(); - IF ((EQ_32(sr_core, INT_FS_16k))&&(EQ_16(coder_type,UNVOICED))) + IF ((EQ_32(st->sr_core, INT_FS_16k))&&(EQ_16(coder_type,UNVOICED))) { - lsf_end_dec_fx( st, 1, GENERIC, sub(1,narrow_band) /* st->bwidth */ , 31, &lsf[m], mem_AR, mem_MA, sr_core, st->core_brate_fx, - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0], &st->safety_net_fx, param_lpc, LSF_Q_prediction, &nb_indices ); + lsf_end_dec_fx( st, 1, GENERIC, sub(1, st->narrowBand) /* st->bwidth */ , ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,NULL +#endif + ); } ELSE { IF (EQ_16(st->core_fx, TCX_20_CORE)) { - lsf_end_dec_fx( st, 1, AUDIO, sub(1, narrow_band) /* st->bwidth */ , 31, &lsf[m], mem_AR, mem_MA, sr_core, st->core_brate_fx, - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0], &st->safety_net_fx, param_lpc, LSF_Q_prediction, &nb_indices); + lsf_end_dec_fx( st, 1, AUDIO, sub(1, st->narrowBand) /* st->bwidth */ , ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,NULL +#endif + ); + } ELSE { - lsf_end_dec_fx( st, 1, coder_type, sub(1, narrow_band) /* st->bwidth */ , 31, &lsf[m], mem_AR, mem_MA, sr_core, st->core_brate_fx, - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0], &st->safety_net_fx, param_lpc, LSF_Q_prediction, &nb_indices); + lsf_end_dec_fx( st, 1, coder_type, sub(1, st->narrowBand) /* st->bwidth */ , ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,NULL +#endif + ); + } } - lsf2lsp_fx(&lsf[m], &lsp[m], M, sr_core); + lsf2lsp_fx(&lsf[m], &lsp[m], M, st->sr_core); } ELSE { assert(0); } - *seed_acelp=0; + st->seed_acelp=0; move16(); FOR(i=nb_indices-1; i>=0; i--) { - *seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(*seed_acelp, 1), 31821), param_lpc[i], 31821)); + st->seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(st->seed_acelp, 1), 31821), param_lpc[i], 31821)); } /* Decoded mid-frame isf */ test(); test(); test(); - IF ( lpcQuantization && acelp_midLpc && core==ACELP_CORE && st->rate_switching_reset==0) + IF (st->lpcQuantization && st->acelp_cfg.midLpc&& st->core_fx==ACELP_CORE && st->rate_switching_reset==0) { midlsf_dec ( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid - ,coder_type - ,mid_lsf_int, - prev_bfi, - *safety_net - ); - reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, sr_core ); - lsf2lsp_fx(lsfmid, lspmid, M, sr_core); + ,coder_type ,&(st->mid_lsf_int_fx), st->prev_bfi_fx, st->safety_net_fx); + reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); + lsf2lsp_fx(lsfmid, lspmid, M, st->sr_core); } diff --git a/lib_dec/er_dec_acelp.c b/lib_dec/er_dec_acelp.c index 6632f93..ee927cb 100644 --- a/lib_dec/er_dec_acelp.c +++ b/lib_dec/er_dec_acelp.c @@ -5,14 +5,12 @@ /*VERSIONINFO: File up to date with trunk rev. 39929*/ -#include -#include +#include +#include "options.h" #include #include "prot_fx.h" #include "basop_util.h" #include "rom_dec_fx.h" -#include "options.h" -#include "stl.h" extern const Word16 T_DIV_L_Frame[];/*0Q15 * 2^-7 */ @@ -70,7 +68,7 @@ void con_acelp( Word16 tmpSeed, Tc; /*Q0*/ Word16 s_32; Word16 synthScaling; - PWord16 const *w = st->tcx_cfg.tcx_mdct_window; + PWord16 const *w = st->hTcxCfg->tcx_mdct_window; Word16 W1, W2; Word16 nSubframes; Word16 s_16, s_gain_inov, s2; @@ -93,6 +91,11 @@ void con_acelp( Word16 g, g_e; Word16 n; const Word16 scale_h1 = 5; + HQ_DEC_HANDLE hHQ_core; + TCX_DEC_HANDLE hTcxDec; + + hHQ_core = st->hHQ_core; + hTcxDec = st->hTcxDec; /*Inits*/ move16(); @@ -698,18 +701,19 @@ void con_acelp( { noise_buf = exc_unv; } - - IF( EQ_16( st->L_frame_fx, L_FRAME )) - { - interp_code_5over2_fx(noise_buf, bwe_exc, st->L_frame_fx); - set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR); - } - ELSE + IF(st->hBWE_TD != NULL) { - interp_code_4over2_fx(noise_buf, bwe_exc, st->L_frame_fx); - set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR16k); + IF(EQ_16(st->L_frame_fx, L_FRAME)) + { + interp_code_5over2_fx(noise_buf, bwe_exc, st->L_frame_fx); + set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR); + } + ELSE + { + interp_code_4over2_fx(noise_buf, bwe_exc, st->L_frame_fx); + set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR16k); + } } - /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ @@ -959,7 +963,8 @@ void con_acelp( -32768/*-1.f Q15*/, /* i : LTP Gain */ 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ 1/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ + st->last_core_brate_fx, /* i : bitrate of previous frame */ + -1 ); } @@ -984,94 +989,96 @@ void con_acelp( Copy(syn, synth, st->L_frame_fx); - bufferCopyFx(syn+st->L_frame_fx-st->L_frame_fx/2, st->old_syn_Overl, shr(st->L_frame_fx,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); + bufferCopyFx(syn+st->L_frame_fx-st->L_frame_fx/2, hTcxDec->old_syn_Overl, shr(st->L_frame_fx,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); /* save last half frame if next frame is TCX */ - bufferCopyFx(syn+st->L_frame_fx, st->syn_Overl_TDAC, shr(st->L_frame_fx,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/ ); + bufferCopyFx(syn+st->L_frame_fx, hTcxDec->syn_Overl_TDAC, shr(st->L_frame_fx,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/ ); Copy(syn+st->L_frame_fx-M-1, st->syn, add(1,M)); /* update old_Aq */ Copy(p_A-(M+1), st->old_Aq_12_8_fx, add(M,1)); - Copy(syn+st->L_frame_fx, st->syn_Overl, shr(st->L_frame_fx,1)); + Copy(syn+st->L_frame_fx, hTcxDec->syn_Overl, shr(st->L_frame_fx,1)); /* create aliasing and windowing */ - W1 = st->tcx_cfg.tcx_mdct_window_length; + W1 = st->hTcxCfg->tcx_mdct_window_length; move16(); W2 = shr(W1,1); - - st->tcx_cfg.tcx_curr_overlap_mode = FULL_OVERLAP; + st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); n = extract_h(L_mult(st->L_frame_fx,9216/*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/)); - st->Q_old_wtda_LB = getScaleFactor16(syn+st->L_frame_fx-n, + hHQ_core->Q_old_wtda_LB = getScaleFactor16(syn+st->L_frame_fx-n, sub(st->L_frame_fx,n)); move16(); - bufferCopyFx(syn+st->L_frame_fx-n, st->old_out_LB_fx, sub(st->L_frame_fx, n), 0, 0, st->Q_old_wtda_LB, 0); + bufferCopyFx(syn+st->L_frame_fx-n, hHQ_core->old_out_LB_fx, sub(st->L_frame_fx, n), 0, 0, hHQ_core->Q_old_wtda_LB, 0); FOR (i=0; i < W2; i++) { - st->old_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re),st->old_out_LB_fx[i+n])); + hHQ_core->old_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re), hHQ_core->old_out_LB_fx[i+n])); } FOR ( ; i < W1; i++) { - st->old_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im),st->old_out_LB_fx[i+n])); + hHQ_core->old_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im), hHQ_core->old_out_LB_fx[i+n])); } - set16_fx(&st->old_out_LB_fx[W1+n], 0, n); + set16_fx(&hHQ_core->old_out_LB_fx[W1+n], 0, n); - st->Q_old_wtda = st->Q_old_wtda_LB; + hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; FOR (i=0; isyn_Overl_TDAC[i],w[i].v.re); + buf[i] = mult_r(hTcxDec->syn_Overl_TDAC[i],w[i].v.re); } FOR(; isyn_Overl_TDAC[i],w[W1-1-i].v.im); + buf[i] = mult_r(hTcxDec->syn_Overl_TDAC[i],w[W1-1-i].v.im); } FOR (i=0; isyn_Overl_TDAC[i] = add(buf[i],buf[W1-1-i]); /* A-D */ + hTcxDec->syn_Overl_TDAC[i] = add(buf[i],buf[W1-1-i]); /* A-D */ } /*-2*/ FOR (i=0; isyn_Overl_TDAC[W2+i] = add(buf[W2+i],buf[W1-1-W2-i]);/* B-C */ + hTcxDec->syn_Overl_TDAC[W2+i] = add(buf[W2+i],buf[W1-1-W2-i]);/* B-C */ } FOR (i=0; isyn_Overl_TDAC[i] = mult_r(st->syn_Overl_TDAC[i],w[i].v.re); + hTcxDec->syn_Overl_TDAC[i] = mult_r(hTcxDec->syn_Overl_TDAC[i],w[i].v.re); } FOR(; isyn_Overl_TDAC[i] = mult_r(st->syn_Overl_TDAC[i],w[W1-1-i].v.im); + hTcxDec->syn_Overl_TDAC[i] = mult_r(hTcxDec->syn_Overl_TDAC[i],w[W1-1-i].v.im); } /* update memory for full band */ - lerp(st->syn_Overl_TDAC, st->syn_Overl_TDACFB, shr(st->L_frameTCX, 1), shr(st->L_frame_fx, 1)); - lerp(st->syn_Overl, st->syn_OverlFB, shr(st->L_frameTCX, 1), shr(st->L_frame_fx, 1)); - lerp(st->old_out_LB_fx, st->old_out_fx, st->L_frameTCX, st->L_frame_fx); + lerp(hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDACFB, shr(hTcxDec->L_frameTCX, 1), shr(st->L_frame_fx, 1)); + lerp(hTcxDec->syn_Overl, hTcxDec->syn_OverlFB, shr(hTcxDec->L_frameTCX, 1), shr(st->L_frame_fx, 1)); + lerp(hHQ_core->old_out_LB_fx, hHQ_core->old_out_fx, hTcxDec->L_frameTCX, st->L_frame_fx); /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - lerp(exc, st->old_exc2_fx, L_EXC_MEM, st->L_frame_fx); - lerp(syn, st->old_syn2_fx, L_EXC_MEM, st->L_frame_fx); + IF(st->hWIDec != NULL) + { + lerp(exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, st->L_frame_fx); + lerp(syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, st->L_frame_fx); + } st->bfi_pitch_fx = shl(round_fx(pitch_buf[st->nb_subfr-1]),6); move16(); st->bfi_pitch_frame_fx = st->L_frame_fx; diff --git a/lib_dec/er_dec_tcx.c b/lib_dec/er_dec_tcx.c index e3f502a..3765435 100644 --- a/lib_dec/er_dec_tcx.c +++ b/lib_dec/er_dec_tcx.c @@ -3,14 +3,12 @@ ====================================================================================*/ -#include -#include #include +#include #include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_dec_fx.h" -#include "stl.h" /***************************************************** @@ -106,8 +104,17 @@ con_tcx *******************************************************/ void con_tcx( - Decoder_State_fx *st, /* i/o: coder memory state */ - Word16 synth[] /* i/o: synth[] *//*Q0 */ + Decoder_State_fx *st, /* i/o: coder memory state */ + Word16 synth[] /* i/o: synth[] *//*Q0 */ +#ifdef IVAS_CODE_CON_TCX + ,const Word16 coh, /* i : coherence of stereo signal */ + Word16 * noise_seed, /* i/o: noise seed for stereo */ + const Word16 only_left /* i : TD-PLC only in left channel */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ,const float* A_cng /* i : CNG LP filter coefficients */ +#endif +#endif + ) { Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; @@ -138,6 +145,13 @@ void con_tcx( Word32 old_pitch_buf[2*NB_SUBFR16k+2]; Word16 Q_exc, new_Q, exp_scale; Word16 offset; + HQ_DEC_HANDLE hHQ_core; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; + + hTcxLtpDec = st->hTcxLtpDec; + hHQ_core = st->hHQ_core; + hTcxDec = st->hTcxDec; /* inits */ alpha = 0; @@ -154,22 +168,24 @@ void con_tcx( move16(); /* Framing parameters */ - L_frame = st->L_frameTCX; + L_frame = hTcxDec->L_frameTCX; move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r(st->L_frameTCX,div_s(1,st->nb_subfr)); - assert( L_subfr == st->L_frameTCX/st->nb_subfr ); + L_subfr = mult_r(hTcxDec->L_frameTCX,div_s(1,st->nb_subfr)); + assert( L_subfr == hTcxDec->L_frameTCX/st->nb_subfr ); move32(); - w = st->tcx_cfg.tcx_mdct_windowFB; /*pointer - no need to instrument*/ - W1 = st->tcx_cfg.tcx_mdct_window_lengthFB; + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); - W2 = shr(st->tcx_cfg.tcx_mdct_window_lengthFB,1); + W2 = shr(st->hTcxCfg->tcx_mdct_window_lengthFB, 1); W12 = shr(W1,1); /* take the previous frame last pitch */ Tc = round_fx(st->old_fpitchFB); - set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ + + set16_fx(buf,0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2); /* initialize buf with 0 */ + //set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ c = BASOP_Util_Divide1616_Scale( L_frame, @@ -191,11 +207,11 @@ void con_tcx( move16(); test(); - IF ( (EQ_16( st->nbLostCmpt, 1 ))||st->tcxConceal_recalc_exc) + IF ( (EQ_16( st->nbLostCmpt, 1 ))|| hTcxDec->tcxConceal_recalc_exc) { /* apply pre-emphasis to the signal */ - mem = synth[-((shr(L_frame,1))+st->pit_max_TCX+M+M)-1]; - Q_exc = E_UTIL_f_preemph3(&(synth[-((shr(L_frame,1))+st->pit_max_TCX+2*M)]), st->preemph_fac, add(add(shr(L_frame,1),st->pit_max_TCX),shl(M,1)), &mem,1); + mem = synth[-((shr(L_frame,1))+ hTcxDec->pit_max_TCX+M+M)-1]; + Q_exc = E_UTIL_f_preemph3(&(synth[-((shr(L_frame,1))+ hTcxDec->pit_max_TCX+2*M)]), st->preemph_fac, add(add(shr(L_frame,1), hTcxDec->pit_max_TCX),shl(M,1)), &mem,1); st->Mode2_lp_gainc = L_deposit_l(0); st->Mode2_lp_gainp = get_gain2( synth-2*L_subfr, synth-2*L_subfr-Tc, shl(L_subfr,1) ); @@ -221,7 +237,7 @@ void con_tcx( Copy(A_local, st->old_Aq_12_8_fx, M+1); /* Residu */ - assert((2*L_subfr+Tc+1+M) <= st->old_synth_lenFB); + assert((2*L_subfr+Tc+1+M) <= hTcxDec->old_synth_lenFB); BASOP_SATURATE_WARNING_OFF /*saturation possible in case of spiky synthesis*/ Residu3_fx( @@ -243,10 +259,10 @@ void con_tcx( IF(GE_16(st->last_good_fx, UNVOICED_TRANSITION)) { tmp16 = s_max(Tc - shr(L_frame,1), 0); - Copy_Scale_sig(st->old_excFB_fx, &(exc[-tmp16]), offset+tmp16, Q_exc-st->Q_exc); + Copy_Scale_sig(hTcxDec->old_excFB_fx, &(exc[-tmp16]), offset+tmp16, Q_exc-st->Q_exc); } ELSE { - Copy_Scale_sig(st->old_excFB_fx, &(exc[-2*L_subfr]), 2*L_subfr+offset, Q_exc-st->Q_exc); + Copy_Scale_sig(hTcxDec->old_excFB_fx, &(exc[-2*L_subfr]), 2*L_subfr+offset, Q_exc-st->Q_exc); } } @@ -259,7 +275,7 @@ void con_tcx( IF( GT_16(st->last_good_fx, UNVOICED_CLAS)&&!(EQ_16(st->last_good_fx,UNVOICED_TRANSITION)&&EQ_16(st->core_ext_mode,GENERIC))) { - IF ( EQ_16(st->nbLostCmpt,1)||st->tcxConceal_recalc_exc) + IF ( EQ_16(st->nbLostCmpt,1)|| hTcxDec->tcxConceal_recalc_exc) { calcGainc( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &(st->Mode2_lp_gainc)); } @@ -276,10 +292,10 @@ void con_tcx( test(); test(); test(); - IF( ((EQ_16(st->nbLostCmpt,1))||st->tcxConceal_recalc_exc)&&GE_16(st->rf_frame_type,RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)&&st->use_partial_copy) + IF( ((EQ_16(st->nbLostCmpt,1))|| hTcxDec->tcxConceal_recalc_exc)&&GE_16(st->rf_frame_type,RF_TCXFD)&&LE_16(st->rf_frame_type,RF_TCXTD2)&&st->use_partial_copy) { - Word32 tcxltp_pitch_tmp = L_add(L_deposit_h(st->tcxltp_pitch_int), L_shl(L_deposit_l(div_s(st->tcxltp_pitch_fr,st->pit_res_max)),1)); /*15Q16*/ - Word16 scale_tmp = mult_r(st->L_frameTCX, getInvFrameLen(st->L_frame_fx)); /*getInvFrameLen()->9Q6*/ + Word32 tcxltp_pitch_tmp = L_add(L_deposit_h(hTcxLtpDec->tcxltp_pitch_int), L_shl(L_deposit_l(div_s(hTcxLtpDec->tcxltp_pitch_fr,st->pit_res_max)),1)); /*15Q16*/ + Word16 scale_tmp = mult_r(hTcxDec->L_frameTCX, getInvFrameLen(st->L_frame_fx)); /*getInvFrameLen()->9Q6*/ Word16 tmp_shift = norm_s(scale_tmp); predPitchLag = L_shl(Mpy_32_16_1(tcxltp_pitch_tmp, shl(scale_tmp, tmp_shift)), sub(9, tmp_shift)); @@ -306,8 +322,8 @@ void con_tcx( old_pitch_buf, &(st->old_fpitchFB), &predPitchLag, - st->pit_min_TCX, - st->pit_max_TCX, + hTcxDec->pit_min_TCX, + hTcxDec->pit_max_TCX, st->mem_pitch_gain, tmp16, st->plc_use_future_lag, @@ -461,8 +477,19 @@ void con_tcx( move16(); /* PLC: calculate damping factor */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + alpha = 1.0f; + if (st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME) + { + alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + } + else if (st->element_mode != IVAS_CPE_MDCT) + { + alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + } +#else alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good_fx, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ - +#endif IF ( EQ_16(st->nbLostCmpt , 1)) { st->cummulative_damping = 32767/*1.f Q15*/; @@ -500,7 +527,7 @@ void con_tcx( /* update old exc without random part */ offset = s_max(round_fx(st->old_fpitchFB) - shr(L_frame,1), 0); - Copy(exc+L_frame-offset, st->old_excFB_fx, shr(L_frame,1)+offset); + Copy(exc+L_frame-offset, hTcxDec->old_excFB_fx, shr(L_frame,1)+offset); /* copy old_exc as 16kHz for acelp decoding */ IF ( EQ_16(st->nbLostCmpt, 1)) { @@ -523,33 +550,84 @@ void con_tcx( } set32_fx( pitch_buf, L_deposit_h(L_SUBFR), st->nb_subfr); /* PLC: calculate damping factor */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + alpha = 1.0f; + if (st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME) + { + alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + } + else if (st->element_mode != IVAS_CPE_MDCT) + { + alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0); + } +#else alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good_fx, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ +#endif } /*-----------------------------------------------------------------* * Construct the random part of excitation *-----------------------------------------------------------------*/ - tmpSeed = st->seed_acelp; - move16(); - noise = buf; - noise_e = 1;/*set exponent of noise to 1*/ move16(); +#ifdef IVAS_CODE_CON_TCX + if (coh != -1.f) + { + int16_t tmpSeed1; + float alpha_coh; + float random1, random2; + + tmpSeed1 = *noise_seed; + noise = buf; + + alpha_coh = sqrtf((1 - coh) / (1 + coh)); + if (st->idchan == 1) + { + alpha_coh = -alpha_coh; + } + + for (i = 0; i < L_frame + L_FIR_FER2 - 1; i++) + { + random1 = (float)own_random(&tmpSeed1); + random2 = (float)own_random(&tmpSeed1); + noise[i] = random1 + alpha_coh * random2; + } + + if (st->idchan == 1 || only_left) + { + *noise_seed = tmpSeed1; + } - tmp_loop = add(L_frame,L_FIR_FER2-1); - FOR (i = 0; i < tmp_loop; i++) + for (; i < L_frame + (L_frame / 2) + 2 * L_FIR_FER2; i++) + { + random1 = (float)own_random(&tmpSeed1); + random2 = (float)own_random(&tmpSeed1); + noise[i] = random1 + alpha_coh * random2; + } + } + else +#endif /*IVAS_CODE_CON_TCX*/ { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed,noise_e); + tmpSeed = st->seed_acelp; move16(); - } - st->seed_acelp = tmpSeed; - move16(); + noise = buf; + noise_e = 1;/*set exponent of noise to 1*/ move16(); - tmp_loop = add(add(L_frame,shr(L_frame,1)) ,shl(L_FIR_FER2,1)); - FOR ( ; i < tmp_loop; i++) - { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed,noise_e); + tmp_loop = add(L_frame, L_FIR_FER2 - 1); + FOR(i = 0; i < tmp_loop; i++) + { + tmpSeed = own_random2_fx(tmpSeed); + noise[i] = shr(tmpSeed, noise_e); + move16(); + } + st->seed_acelp = tmpSeed; move16(); + + tmp_loop = add(add(L_frame, shr(L_frame, 1)), shl(L_FIR_FER2, 1)); + FOR(; i < tmp_loop; i++) + { + tmpSeed = own_random2_fx(tmpSeed); + noise[i] = shr(tmpSeed, noise_e); + move16(); + } } test(); IF (EQ_16(st->last_good_fx , VOICED_CLAS)||EQ_16(st->last_good_fx,ONSET)) @@ -608,22 +686,40 @@ void con_tcx( } /* PLC: [TCX: Fade-out] retrieve background level */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + if (A_cng != NULL) + { + gainSynthDeemph = getLevelSynDeemph(&(tmp), A_cng, L_frame / 4, st->preemph_fac, 1) / 4.f; + } + else + { + gainSynthDeemph = getLevelSynDeemph(&(tmp), A_local, L_frame / 4, st->preemph_fac, 1); + } +#else tmp16 = 32767; move16(); - gainSynthDeemph = getLevelSynDeemph(&(tmp16), - A_local, - M, - shr(L_frame,2), - st->preemph_fac, - 1, - &gainSynthDeemph_e); + gainSynthDeemph = getLevelSynDeemph(&(tmp16), A_local, M, shr(L_frame,2), st->preemph_fac, 1, &gainSynthDeemph_e); +#endif IF (0 != st->tcxonly) { /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp(st->conCngLevelBackgroundTrace, - st->conCngLevelBackgroundTrace_e, + BASOP_Util_Divide_MantExp(hTcxDec->conCngLevelBackgroundTrace, + hTcxDec->conCngLevelBackgroundTrace_e, gainSynthDeemph, gainSynthDeemph_e, &gainCNG, &gainCNG_e); +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + if (st->element_mode == IVAS_CPE_MDCT && A_cng != NULL) + { + if (st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN) + { + gainCNG = 0.f; + } + else if (st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) + { + gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; + } + } +#endif } ELSE { @@ -739,7 +835,7 @@ void con_tcx( ELSE { bufferCopyFx(noise+L_FIR_FER2/2, exc, add(L_frame , shr(L_frame,1)),0/*Q_noise*/, noise_e, Q_exc, 0/*exc_e*/); - Copy(exc+L_frame-2*L_subfr, st->old_excFB_fx, 2*L_subfr+shr(L_frame,1)); + Copy(exc+L_frame-2*L_subfr, hTcxDec->old_excFB_fx, 2*L_subfr+shr(L_frame,1)); /* copy old_exc as 16kHz for acelp decoding */ IF ( EQ_16(st->nbLostCmpt, 1)) { @@ -783,7 +879,34 @@ void con_tcx( /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ /*buf[0;M] Q0: mem_syn*/ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + if (A_cng != NULL) + { + float alpha_delayed; + alpha_delayed = 1.0f; + if (st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE) + { + alpha_delayed = Damping_fact(st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac, &(st->lp_gainp), ACELP_CORE); + } + + if (st->plcBackgroundNoiseUpdated && alpha_delayed != 1.0f) + { + float lsp_local[M], lsp_fade[M], alpha_inv; + + alpha_inv = 1.0f - alpha_delayed; + + a2lsp_stab(A_local, lsp_local, lsp_local); + + for (i = 0; i < M; i++) + { + lsp_fade[i] = alpha_delayed * lsp_local[i] + alpha_inv * st->lspold_cng[i]; + } + + lsp2a_stab(lsp_fade, A_local, M); + } + } +#endif E_UTIL_synthesis( sub(Q_exc, Q_syn), A_local, @@ -814,21 +937,21 @@ void con_tcx( bufferCopyFx(syn+L_frame-M-1, st->syn, 1+M, Q_syn, 0, 0, 0); - lerp( syn+L_frame-shr(L_frame, 1), st->old_syn_Overl, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); - Copy(syn+L_frame-n, st->old_out_fx, sub(L_frame,n)); + lerp( syn+L_frame-shr(L_frame, 1), hTcxDec->old_syn_Overl, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); + Copy(syn+L_frame-n, hHQ_core->old_out_fx, sub(L_frame,n)); FOR (i=0; i < W12; i++) { - st->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re),st->old_out_fx[i+n])); + hHQ_core->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re), hHQ_core->old_out_fx[i+n])); } FOR ( ; i < W1; i++) { - st->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W12-1-(i-W12)].v.im,w[W12-1-(i-W12)].v.im),st->old_out_fx[i+n])); + hHQ_core->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W12-1-(i-W12)].v.im,w[W12-1-(i-W12)].v.im), hHQ_core->old_out_fx[i+n])); } - set16_fx(&st->old_out_fx[W1+n], 0, n); + set16_fx(&hHQ_core->old_out_fx[W1+n], 0, n); - st->Q_old_wtda = Q_syn; + hHQ_core->Q_old_wtda = Q_syn; move16(); /* As long as there is no synth scaling factor introduced, which @@ -837,65 +960,68 @@ void con_tcx( bufferCopyFx(syn, synth, L_frame, Q_syn, 0, 0, 0); BASOP_SATURATE_WARNING_ON - Copy_Scale_sig(syn+L_frame, st->syn_OverlFB, shr(L_frame,1), negate(Q_syn)); + Copy_Scale_sig(syn+L_frame, hTcxDec->syn_OverlFB, shr(L_frame,1), negate(Q_syn)); /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - lerp(exc, st->old_exc2_fx, L_EXC_MEM, L_frame); - lerp(syn, st->old_syn2_fx, L_EXC_MEM, L_frame); + IF(st->hWIDec != NULL) + { + lerp(exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame); + lerp(syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame); + } + st->bfi_pitch_fx/*Q6*/ = round_fx(L_shl(pitch_buf[st->nb_subfr-1]/*15Q16*/,6/*Q6*/)); move16(); st->bfi_pitch_frame_fx = st->L_frame_fx; move16(); /* create aliasing and windowing need for transition to TCX10/5 */ - bufferCopyFx(syn+L_frame, st->syn_Overl_TDACFB, shr(L_frame,1),Q_syn,0,-1,0); + bufferCopyFx(syn+L_frame, hTcxDec->syn_Overl_TDACFB, shr(L_frame,1),Q_syn,0,-1,0); FOR (i=0 ; i < W12 ; i++) { - buf[i] = mult_r(st->syn_Overl_TDACFB[i] , w[i].v.re); + buf[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i] , w[i].v.re); move16(); } FOR ( ; i syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); + buf[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); move16(); } FOR (i=0; isyn_Overl_TDACFB[i] = add(buf[i] , buf[W1-1-i]); + hTcxDec->syn_Overl_TDACFB[i] = add(buf[i] , buf[W1-1-i]); move16(); } FOR (i=0; isyn_Overl_TDACFB[W2+i] = add(buf[W2+i] , buf[W1-1-W2-i]); + hTcxDec->syn_Overl_TDACFB[W2+i] = add(buf[W2+i] , buf[W1-1-W2-i]); move16(); } FOR (i=0 ; i < W12 ; i++) { - st->syn_Overl_TDACFB[i] = mult_r(st->syn_Overl_TDACFB[i],w[i].v.re); + hTcxDec->syn_Overl_TDACFB[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i],w[i].v.re); move16(); } FOR ( ; i syn_Overl_TDACFB[i] = mult_r(st->syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); + hTcxDec->syn_Overl_TDACFB[i] = mult_r(hTcxDec->syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); move16(); } - st->tcx_cfg.tcx_curr_overlap_mode = FULL_OVERLAP; + st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; synth[-1] = pre_emph_buf; move16(); /* update memory for low band */ - Scale_sig(st->old_syn_Overl, shr(st->L_frame_fx, 1), sub(-1, Q_syn)); - lerp( st->syn_OverlFB, st->syn_Overl, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); - lerp( st->syn_Overl_TDACFB, st->syn_Overl_TDAC, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); - lerp( st->old_out_fx, st->old_out_LB_fx, st->L_frame_fx, L_frame ); - + Scale_sig(hTcxDec->old_syn_Overl, shr(st->L_frame_fx, 1), sub(-1, Q_syn)); + lerp(hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); + lerp(hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); + lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame_fx, L_frame ); st->old_enr_LP = Enr_1_Az_fx(A_local, L_SUBFR); /*Q3*/ diff --git a/lib_dec/er_scale_syn.c b/lib_dec/er_scale_syn.c index d63dc7b..61f76e9 100644 --- a/lib_dec/er_scale_syn.c +++ b/lib_dec/er_scale_syn.c @@ -4,12 +4,11 @@ /*This file is up to date with trunk rev 36531*/ -#include -#include +#include +#include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "cnst_fx.h" -#include "stl.h" /*----------------------------------------------------------------------------------* @@ -19,13 +18,13 @@ *----------------------------------------------------------------------------------*/ /*This BASOP version was ported based on trunk rev. 27621 and updated based on trunk rev. 29287, re-updated based on trunk rev. 32244 */ -Word16 Damping_fact( /* o : damping factor *//*Q14*/ - const Word16 coder_type, /* i : coding type in last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bfi frames */ - const Word16 last_good, /* i : last good frame class */ - const Word16 stab_fac, /* i : ISF stability factor *//*Q15*/ - Word32 *lp_gainp, /*i/o: damped pitch gain *//*2Q29 Word32!*/ - const Word16 core /* i : current coding mode */ +Word16 Damping_fact( /* o : damping factor *//*Q14*/ + const Word16 coder_type, /* i : coding type in last good received frame */ + const Word16 nbLostCmpt, /* i : counter of consecutive bfi frames */ + const Word16 last_good, /* i : last good frame class */ + const Word16 stab_fac, /* i : ISF stability factor *//*Q15*/ + Word32 *lp_gainp, /*i/o: damped pitch gain *//*2Q29 Word32!*/ + const Word16 core /* i : current coding mode */ ) { Word16 alpha; /*Q14*/ diff --git a/lib_dec/er_sync_exc.c b/lib_dec/er_sync_exc.c index 79feced..5b8e47b 100644 --- a/lib_dec/er_sync_exc.c +++ b/lib_dec/er_sync_exc.c @@ -4,11 +4,11 @@ /*This BASOP port is up to date with trunk rev. 36554*/ +#include +#include +#include "options.h" #include "cnst_fx.h" -#include "stl.h" #include "prot_fx.h" -#include -#include #include "basop32.h" #include "basop_util.h" @@ -32,9 +32,6 @@ static Word16 GetMinimumPosition( Word16 cnt, tmp_e, tmp16; Word32 energy, energy_old, tmptest; - - - filterLength = s_min(filterLength, length); center = shr(filterLength,1); iMinEnergyPos = center; @@ -103,8 +100,6 @@ static Word16 FindMaxPeak { Word16 iMax, i; - - iMax = 0; move16(); FOR (i = 1; i < length; i++) @@ -134,8 +129,6 @@ static void AddSamples( Word16 last_min_pos, i, j; Word16 ftmp; - - pt_dest = new_exc; move16(); pt_src = old_exc; diff --git a/lib_dec/er_util.c b/lib_dec/er_util.c index 3cfa51d..e09ace2 100644 --- a/lib_dec/er_util.c +++ b/lib_dec/er_util.c @@ -3,15 +3,13 @@ ====================================================================================*/ +#include #include "options.h" -#include "stl.h" #include "prot_fx.h" #include "basop_util.h" #include -#define MODE_DECISION_BASED_ON_PEAK_DETECTION - /* static void setnoiseLevelMemory() * @@ -29,17 +27,18 @@ static void setnoiseLevelMemory(Word16 f, Word16* new_noiseEstimate_e, Word16* n /* PLC: [Common: Fade-out] * PLC: and for PLC fade out */ -void minimumStatistics(Word16* noiseLevelMemory, /* Qx, internal state */ - Word16* noiseLevelIndex, /* Q0, internal state */ - Word16* currLevelIndex, /* Q0, internal state (circular buffer) */ - Word16* noiseEstimate, /* Qx, previous estimate of background noise */ - Word16* lastFrameLevel, /* Qx, level of the last frame */ - Word16 currentFrameLevel, /* Qx, level of the current frame */ - Word16* noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ - Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ - Word16* new_noiseEstimate_e, /* new exponent of noise Estimate*/ - Word16* const lastFrameLevel_e, /* exponent of lastFrameLevel */ - Word16 currentFrameLevel_e) /* exponent of currentFrameLevel */ +void minimumStatistics( + Word16* noiseLevelMemory, /* Qx, internal state */ + Word16* noiseLevelIndex, /* Q0, internal state */ + Word16* currLevelIndex, /* Q0, internal state (circular buffer) */ + Word16* noiseEstimate, /* Qx, previous estimate of background noise */ + Word16* lastFrameLevel, /* Qx, level of the last frame */ + Word16 currentFrameLevel, /* Qx, level of the current frame */ + Word16* noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ + Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ + Word16* new_noiseEstimate_e, /* new exponent of noise Estimate*/ + Word16* const lastFrameLevel_e, /* exponent of lastFrameLevel */ + Word16 currentFrameLevel_e) /* exponent of currentFrameLevel */ { Word16 aOpt, aOpt_e; Word16 f, p, i; @@ -255,15 +254,19 @@ Word16 getLevelSynDeemph( /*10Q5*/ } /* BASOP version: up to date with rev 7422 */ -void genPlcFiltBWAdap(const Word32 sr_core, Word16 *lpFiltAdapt, const Word16 type, const Word16 alpha - ) +void genPlcFiltBWAdap( + const Word32 sr_core, /* i : core sampling rate */ + Word16* lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */ + const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass */ + const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt */ +) { Word16 a, b, exp; assert(type == 0 || type == 1); - IF ( EQ_32(sr_core, 16000)) + IF ( EQ_32(sr_core, INT_FS_16k)) { IF (type == 0) { @@ -290,7 +293,7 @@ void genPlcFiltBWAdap(const Word32 sr_core, Word16 *lpFiltAdapt, const Word16 ty *lpFiltAdapt = a; } } - ELSE + ELSE /*sr_core = INT_FS_12k8 */ { IF (type == 0) { @@ -326,11 +329,11 @@ void genPlcFiltBWAdap(const Word32 sr_core, Word16 *lpFiltAdapt, const Word16 ty *-----------------------------------------------------------------*/ /*VERSIONINFO: This port is up to date with trunk rev. 32434*/ void highPassFiltering( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ - Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ - const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer) /* i: high pass filter length */ + const Word16 last_good, /* i: short last classification type */ + const Word16 L_buffer, /* i: int buffer length */ + Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ + const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ + const Word16 l_fir_fer) /* i: high pass filter length */ { Word16 i; /*int*/ @@ -355,6 +358,9 @@ Word16 GetPLCModeDecision( { Word16 /*int*/ core; Word16 numIndices = 0; + TCX_DEC_HANDLE hTcxDec; + + hTcxDec = st->hTcxDec; IF( EQ_16(st->flagGuidedAcelp,1)) @@ -367,7 +373,7 @@ Word16 GetPLCModeDecision( move16(); test(); test(); - if(( st->last_core_fx > ACELP_CORE && st->tcxltp_last_gain_unmodified!=0 ) + if(( st->last_core_fx > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified!=0 ) || ( EQ_16(st->flagGuidedAcelp,1) ) ) { @@ -414,26 +420,30 @@ Word16 GetPLCModeDecision( test(); test(); test(); - IF ((EQ_16(st->last_core_fx,TCX_20_CORE))&&(EQ_16(st->second_last_core,TCX_20_CORE)) +PMT("handle to tonalMDCTconceal is missing") +//#ifdef ADD_IVAS_HTONALMDCTCONC + IF ((/*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ EQ_16(st->last_core_fx,TCX_20_CORE))&&(EQ_16(st->second_last_core,TCX_20_CORE)) && ((LE_32(st->old_fpitch,L_deposit_h(shr(st->L_frame_fx,1)))) - || (LE_16(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) + || (LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) /* it is fine to call the detection even if no ltp information is available, meaning that st->old_fpitch == st->tcxltp_second_last_pitch == st->L_frame */ - && (EQ_32(st->old_fpitch, st->tcxltp_second_last_pitch)) + && (EQ_32(st->old_fpitch, hTcxDec->tcxltp_second_last_pitch)) && !st->last_tns_active && !st->second_last_tns_active) { Word32 pitch; pitch = L_deposit_h(0); - if(st->tcxltp_last_gain_unmodified > 0) + if(hTcxDec->tcxltp_last_gain_unmodified > 0) { pitch = L_add(st->old_fpitch, 0); } - TonalMDCTConceal_Detect(&st->tonalMDCTconceal, - pitch, - &numIndices); + TonalMDCTConceal_Detect(&st->tonalMDCTconceal, pitch, &numIndices +#ifdef ADD_IVAS_HTONALMDCTCONC + , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) +#endif + ); test(); test(); @@ -443,16 +453,16 @@ Word16 GetPLCModeDecision( test(); IF ((GT_16(numIndices,10)) || ((GT_16(numIndices,5) ) - && (LT_32(L_abs(L_sub(st->tcxltp_third_last_pitch,st->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) )) - || ((numIndices > 0) && ((LE_16(st->last_good_fx,UNVOICED_TRANSITION))||(LE_16(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) - && (LT_32(L_abs(L_sub(st->tcxltp_third_last_pitch,st->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) ))) + && (LT_32(L_abs(L_sub(hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) )) + || ((numIndices > 0) && ((LE_16(st->last_good_fx,UNVOICED_TRANSITION))||(LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/))) + && (LT_32(L_abs(L_sub(hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) ))) { core = TCX_20_CORE; move16(); st->tonal_mdct_plc_active = 1; move16(); } - ELSE IF (LE_16(st->last_good_fx,UNVOICED_TRANSITION)||LE_16(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) + ELSE IF (LE_16(st->last_good_fx,UNVOICED_TRANSITION)||LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) { core = TCX_20_CORE; move16(); @@ -461,7 +471,7 @@ Word16 GetPLCModeDecision( ELSE IF (st->last_core_fx != ACELP_CORE) { test(); - if (LE_16(st->last_good_fx,UNVOICED_TRANSITION)||LE_16(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) + if (LE_16(st->last_good_fx,UNVOICED_TRANSITION)||LE_16(hTcxDec->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)) { core = st->last_core_fx; move16(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 414b927..fed9c14 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1,15 +1,14 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include +#include /* Debug prototypes */ #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include /* Debug prototypes */ /*--------------------------------------------------------------------------* * evs_dec() @@ -17,13 +16,13 @@ * Principal decoder routine *--------------------------------------------------------------------------*/ -void evs_dec_fx( +ivas_error evs_dec_fx( Decoder_State_fx *st_fx, /* i/o : Decoder state structure */ Word16 output_sp[], /* o : output synthesis signal */ frameMode_fx frameMode /* i : Decoder frame mode */ ) { - Word16 i, j, output_frame, coder_type; + Word16 i, j, output_frame; Word16 sharpFlag; Word16 tmps, incr; Word16 core_switching_flag; @@ -38,9 +37,13 @@ void evs_dec_fx( Word16 exp,fra; Word16 tmp_buffer_fx[L_FRAME48k]; Word16 tmp16,tmp16_2; +#ifdef IVAS_CODE + Word16 synth_fx[L_FRAME48k]; +#else Word16 synth_fx[L_FRAME48k + HQ_DELTA_MAX*HQ_DELAY_COMP]; +#endif Word16 fb_exc_fx[L_FRAME16k]; - Word16 pitch_buf_fx[NB_SUBFR16k]; + Word16 pitch_buf_fx[NB_SUBFR16k] = { 0 }; Word16 Q_fb_exc; Word16 old_syn_12k8_16k_fx[L_FRAME16k]; Word16 sid_bw=-1; @@ -59,6 +62,17 @@ void evs_dec_fx( Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 timeIn_e; + TD_BWE_DEC_HANDLE hBWE_TD; + HQ_DEC_HANDLE hHQ_core; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; + ivas_error error; + + hBWE_TD = st_fx->hBWE_TD; + hHQ_core = st_fx->hHQ_core; + hTcxLtpDec = st_fx->hTcxLtpDec; + hTcxDec = st_fx->hTcxDec; + error = IVAS_ERR_OK; timeIn_e = 0; move16(); @@ -72,6 +86,11 @@ void evs_dec_fx( /*------------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ + + st_fx->idchan = 0; + st_fx->element_brate = st_fx->total_brate_fx; + st_fx->flag_ACELP16k = set_ACELP_flag(EVS_MONO, -1, st_fx->total_brate_fx, 0, 0, -1, -1); + FOR( i=0; ibfi_fx == 0 ) { st_fx->extl_fx = -1; @@ -106,16 +124,16 @@ void evs_dec_fx( IF( EQ_16(st_fx->bfi_fx,1)) { - hq_core_type = st_fx->last_hq_core_type_fx; + hq_core_type = hHQ_core->last_hq_core_type_fx; move16(); - coder_type = st_fx->last_coder_type_fx; + st_fx->coder_type_fx = st_fx->last_coder_type_fx; move16(); } ELSE { hq_core_type = -1; move16(); - coder_type = INACTIVE; + st_fx->coder_type_fx = INACTIVE; move16(); } @@ -133,38 +151,38 @@ void evs_dec_fx( { /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ /* st_fx->old_out_fx, st_fx->L_frameTCX); */ - FOR( i = 0; i < st_fx->L_frameTCX; i++ ) + FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - st_fx->old_out_fx[i] = shl(mult_r(st_fx->old_out_fx[i] , st_fx->plcInfo.recovery_gain), 1); + hHQ_core->old_out_fx[i] = shl(mult_r(hHQ_core->old_out_fx[i] , st_fx->plcInfo.recovery_gain), 1); } FOR( i = 0; i < st_fx->L_frame_fx; i++ ) { - st_fx->old_out_LB_fx[i] = shl(mult_r(st_fx->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain), 1); + hHQ_core->old_out_LB_fx[i] = shl(mult_r(hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain), 1); } /* attenuate PLC buffers, if no aldo window is used and if no sid or zero frame is received */ - IF ( 0 == st_fx->tcx_cfg.last_aldo ) + IF ( 0 == st_fx->hTcxCfg->last_aldo ) { Word32 f; Word16 s; Word16 tmp1; - f = L_deposit_l(st_fx->conceal_eof_gain); /*Q14*/ + f = L_deposit_l(hTcxDec->conceal_eof_gain); /*Q14*/ s = norm_l(f); s = sub(16,s); tmp1 = extract_l(L_shr_r(f,s)); - FOR( i=0; i < st_fx->tcx_cfg.tcx_mdct_window_lengthFB; i++ ) + FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { - st_fx->syn_OverlFB[i] = shl(mult(tmp1,st_fx->syn_OverlFB[i]), add(s,1)); + hTcxDec->syn_OverlFB[i] = shl(mult(tmp1, hTcxDec->syn_OverlFB[i]), add(s,1)); move16(); } s = norm_l(f); s = sub(16,s); tmp1 = extract_l(L_shr_r(f,s)); - FOR( i=0; i < st_fx->tcx_cfg.tcx_mdct_window_length; i++ ) + FOR( i=0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ ) { - st_fx->syn_Overl[i] = shl(mult(tmp1,st_fx->syn_Overl[i]),s); + hTcxDec->syn_Overl[i] = shl(mult(tmp1, hTcxDec->syn_Overl[i]),s); move16(); } } @@ -194,8 +212,7 @@ void evs_dec_fx( IF( NE_16(frameMode,FRAMEMODE_MISSING)) /* frame mode normal or future frame */ { - getPartialCopyInfo(st_fx, &coder_type, &sharpFlag); - + getPartialCopyInfo(st_fx, &st_fx->coder_type_fx, &sharpFlag); frameMode = st_fx->bfi_fx; } @@ -233,7 +250,7 @@ void evs_dec_fx( } /* if previous frame was HQ Core or TCX10, drop partial copy info and continue HQ Core/TCX10 concealment */ - IF( st_fx->use_partial_copy && ((sub(st_fx->last_core_fx, HQ_CORE) == 0) || (sub(st_fx->last_core_fx, TCX_10_CORE) == 0) || ((sub(st_fx->last_core_fx, TCX_20_CORE) == 0) && getTcxonly(st_fx->last_total_brate_fx))) ) + IF( st_fx->use_partial_copy && ((sub(st_fx->last_core_fx, HQ_CORE) == 0) || (sub(st_fx->last_core_fx, TCX_10_CORE) == 0) || ((sub(st_fx->last_core_fx, TCX_20_CORE) == 0) && getTcxonly(/*EVS_MONO, */st_fx->last_total_brate_fx/*, 0, 0*/))) ) { st_fx->bfi_fx = 1; move16(); @@ -259,11 +276,10 @@ void evs_dec_fx( IF ( NE_16(st_fx->bfi_fx,1)) { - decision_matrix_dec_fx( st_fx, &coder_type, &sharpFlag, &hq_core_type, &core_switching_flag ); - + decision_matrix_dec_fx( st_fx, &sharpFlag, &hq_core_type, &core_switching_flag ); IF( NE_16(st_fx->bfi_fx,1)) { - st_fx->sr_core = i_mult(st_fx->L_frame_fx,50); + st_fx->sr_core = i_mult(st_fx->L_frame_fx, FRAMES_PER_SEC); st_fx->fscale_old = st_fx->fscale; st_fx->fscale = sr2fscale(st_fx->sr_core); } @@ -274,7 +290,6 @@ void evs_dec_fx( } } } - IF( EQ_16(st_fx->codec_mode,MODE1)) { /*------------------------------------------------------------------* @@ -302,8 +317,11 @@ void evs_dec_fx( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - - core_switching_pre_dec_fx( st_fx, output_frame ); +PMT("core_switching_pre_dec_fx missign args") + if ((error = core_switching_pre_dec_fx( st_fx, output_frame )) != IVAS_ERR_OK) + { + return error; + } /*---------------------------------------------------------------------* * ACELP core decoding @@ -312,27 +330,41 @@ void evs_dec_fx( IF ( EQ_16(st_fx->core_fx,ACELP_CORE)) { /* ACELP core decoder */ - acelp_core_dec_fx( st_fx, synth_fx, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, coder_type, sharpFlag, pitch_buf_fx, &unbits, &sid_bw ); + if ((error = acelp_core_dec_fx(st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1)) != IVAS_ERR_OK) + { + return error; + } Qpostd = st_fx->Q_syn2; move16(); } ELSE { +PMT("HQ core missing args") hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag ); Qpostd = Q_synth; move16(); } - /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, coder_type, &Qpostd ); - + if ((error = core_switching_post_dec_fx( st_fx, synth_fx, +#ifdef IVAS_CODE_SWITCHING + output, output_mem[], IVAS_FORMAT ivas_format, use_cldfb_for_dft, +#endif + output_frame, core_switching_flag, +#ifdef IVAS_CODE_SWITCHING + sba_dirac_stereo_flag, nchan_out, +#endif + st_fx->last_element_mode, &Qpostd )) != IVAS_ERR_OK) + { + return error; + } /*---------------------------------------------------------------------* * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ +PMT("bw_switching_pre_proc_fx missing args") bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx ); /*---------------------------------------------------------------------* @@ -343,12 +375,20 @@ void evs_dec_fx( IF ( EQ_16(st_fx->extl_fx,WB_TBE)) { /* WB TBE decoder */ - wb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); + wb_tbe_dec_fx( st_fx, st_fx->coder_type_fx, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); } ELSE IF ( EQ_16(st_fx->extl_fx,WB_BWE)&&st_fx->bws_cnt_fx==0) { /* WB BWE decoder */ - hb_synth_fx_exp = wb_bwe_dec_fx( synth_fx, hb_synth_fx, output_frame, coder_type, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); + hb_synth_fx_exp = wb_bwe_dec_fx( +#ifdef ADD_IVAS_BWE + NULL, +#endif + synth_fx, hb_synth_fx, +#ifdef ADD_IVAS_BWE + 0, +#endif + output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); } /*---------------------------------------------------------------------* @@ -368,14 +408,12 @@ void evs_dec_fx( test(); test(); IF ( EQ_16(st_fx->extl_fx,SWB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE) - || (NE_16(coder_type,AUDIO) && NE_16(coder_type,INACTIVE) && GT_32(st_fx->core_brate_fx,SID_2k40) && EQ_16(st_fx->core_fx,ACELP_CORE) + || (NE_16(st_fx->coder_type_fx,AUDIO) && NE_16(st_fx->coder_type_fx,INACTIVE) && GT_32(st_fx->core_brate_fx,SID_2k40) && EQ_16(st_fx->core_fx,ACELP_CORE) && GE_32(st_fx->output_Fs_fx,32000) && GT_16(st_fx->bwidth_fx,NB) && st_fx->bws_cnt_fx > 0 && !st_fx->ppp_mode_dec_fx && !( EQ_16( st_fx->nelp_mode_dec_fx, 1) && EQ_16( st_fx->bfi_fx, 1) ) ) ) - { - swb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, + swb_tbe_dec_fx( st_fx, st_fx->coder_type_fx, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); - /* FB TBE decoder/synthesis */ test(); IF ( EQ_16(output_frame,L_FRAME48k)&&EQ_16(st_fx->extl_fx,FB_TBE)) @@ -388,7 +426,15 @@ void evs_dec_fx( && !( EQ_16( st_fx->nelp_mode_dec_fx, 1) && EQ_16( st_fx->bfi_fx, 1) ) ) ) { /* SWB BWE decoder */ - hb_synth_fx_exp = swb_bwe_dec_fx( st_fx, synth_fx, hb_synth_fx, output_frame, &Qpostd, coder_type ); + hb_synth_fx_exp = swb_bwe_dec_fx( +#ifdef ADD_IVAS_BWE + NULL, +#endif + st_fx, synth_fx, hb_synth_fx, +#ifdef ADD_IVAS_BWE + 0, +#endif + output_frame, &Qpostd); } ELSE IF( EQ_16(st_fx->extl_fx,SWB_BWE_HIGHRATE)||EQ_16(st_fx->extl_fx,FB_BWE_HIGHRATE)) { @@ -603,7 +649,7 @@ void evs_dec_fx( Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); } /* Delay hb_synth */ - tmp16 = sub(hb_synth_fx_exp, st_fx->prev_hb_synth_fx_exp); + tmp16 = sub(hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp); IF ( tmp16 != 0 ) { Scale_sig(st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); @@ -625,10 +671,10 @@ void evs_dec_fx( IF( ( st_fx->ppp_mode_dec_fx || (EQ_16(st_fx->nelp_mode_dec_fx,1)&&EQ_16(st_fx->bfi_fx,1)))&&EQ_16(st_fx->L_frame_fx,st_fx->last_L_frame_fx)&&(st_fx->bws_cnt_fx>1||st_fx->last_extl_fx!=-1)) { - Copy( st_fx->old_hb_synth_fx, hb_synth_fx, output_frame ); - IF(LT_16(st_fx->prev_hb_synth_fx_exp, 14)) + Copy(hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); + IF(LT_16(hBWE_TD->prev_hb_synth_fx_exp, 14)) { - hb_synth_fx_exp = add(st_fx->prev_hb_synth_fx_exp, 1); + hb_synth_fx_exp = add(hBWE_TD->prev_hb_synth_fx_exp, 1); } ELSE { @@ -637,7 +683,7 @@ void evs_dec_fx( } ELSE { - Copy( hb_synth_fx, st_fx->old_hb_synth_fx, output_frame ); + Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); } add_vec_fx( synth_fx, Qpostd, hb_synth_fx, hb_synth_fx_exp, synth_fx, Qpostd, output_frame ); @@ -674,20 +720,14 @@ void evs_dec_fx( st_fx->last_shb_ener_fx = round_fx(L_shl(L_tmp, 10)); /*Q8*/ } } - st_fx->prev_hb_synth_fx_exp = hb_synth_fx_exp; + hBWE_TD->prev_hb_synth_fx_exp = hb_synth_fx_exp; move16(); /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */ delta = NS2SA_fx2( st_fx->output_Fs_fx, TCXLTP_DELAY_NS ); - Scale_sig(st_fx->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); - Scale_sig(st_fx->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); - tcx_ltp_post( st_fx->tcxltp, ACELP_CORE, output_frame, st_fx->L_frame_past, 0, synth_fx, NULL, - delta, 0, 0, 0, 0, &st_fx->tcxltp_pitch_int_post_prev, - &st_fx->tcxltp_pitch_fr_post_prev, &st_fx->tcxltp_gain_post_prev, - &st_fx->tcxltp_filt_idx_prev, st_fx->pit_res_max, - &st_fx->pit_res_max_past, - 0, 0, st_fx->tcxltp_mem_in, - st_fx->tcxltp_mem_out, st_fx->total_brate_fx ); + Scale_sig(hTcxLtpDec->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); + Scale_sig(hTcxLtpDec->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); + tcx_ltp_post(st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL); /* final output of synthesis signal */ @@ -742,8 +782,8 @@ void evs_dec_fx( /* DECODE CORE */ /* -------------------------------------------------------------- */ - dec_acelp_tcx_frame( st_fx, &coder_type, &concealWholeFrame, output_sp, - st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx ); + dec_acelp_tcx_frame(st_fx, &concealWholeFrame, output_sp, + st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx); concealWholeFrameTmp = concealWholeFrame; move16(); @@ -776,6 +816,17 @@ void evs_dec_fx( move16(); st_fx->extl_brate_fx = SWB_TBE_1k6; move32(); + + IF ( LT_32(st_fx->total_brate_fx, ACELP_13k20)) + { + st_fx->extl_brate_fx = SWB_TBE_0k95; + move32(); + } + ELSE IF (GE_32(st_fx->total_brate_fx, ACELP_24k40)) + { + st_fx->extl_brate_fx = SWB_TBE_2k8; + move32(); + } BREAK; case FB: @@ -783,6 +834,11 @@ void evs_dec_fx( move16(); st_fx->extl_brate_fx = FB_TBE_1k8; move32(); + IF(GE_32(st_fx->total_brate_fx, ACELP_24k40)) + { + st_fx->extl_brate_fx = FB_TBE_3k0; + move32(); + } BREAK; } } @@ -795,7 +851,7 @@ void evs_dec_fx( test(); test(); - if( EQ_32(st_fx->output_Fs_fx,8000)||(EQ_32(st_fx->output_Fs_fx,16000)&&EQ_16(st_fx->L_frame_fx,L_FRAME16k))) + if( EQ_32(st_fx->output_Fs_fx,8000)||(EQ_32(st_fx->output_Fs_fx, INT_FS_16k)&&EQ_16(st_fx->L_frame_fx,L_FRAME16k))) { st_fx->extl_fx = -1; move16(); @@ -819,21 +875,20 @@ void evs_dec_fx( test(); IF( EQ_16(st_fx->extl_fx, WB_TBE)) { - wb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); + wb_tbe_dec_fx( st_fx, st_fx->coder_type_fx, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); } ELSE IF( EQ_16(st_fx->extl_fx, SWB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE)) { /* SWB TBE decoder */ - swb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, st_fx->old_core_synth_fx, + swb_tbe_dec_fx( st_fx, st_fx->coder_type_fx, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); - test(); IF( EQ_16(st_fx->extl_fx, FB_TBE)&&EQ_16(output_frame,L_FRAME48k)) { fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); } } - Copy( hb_synth_fx, st_fx->old_hb_synth_fx, output_frame ); + Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); } ELSE { @@ -846,18 +901,18 @@ void evs_dec_fx( IF( ( EQ_16(st_fx->bwidth_fx, SWB)||EQ_16(st_fx->bwidth_fx,FB))&& (( EQ_16(st_fx->last_extl_fx, SWB_TBE) || EQ_16(st_fx->last_extl_fx, FB_TBE) ) && EQ_16(st_fx->last_codec_mode, MODE2) ) ) { - GenTransition_fx( st_fx->syn_overlap_fx, st_fx->old_tbe_synth_fx, 2*NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), hb_synth_fx, - st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, - st_fx->mem_resamp_HB_32k_fx, - &(st_fx->syn_dm_phase_fx), st_fx->output_Fs_fx, st_fx->int_3_over_2_tbemem_dec_fx, st_fx->rf_flag, st_fx->total_brate_fx ); + GenTransition_fx(hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, 2*NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), hb_synth_fx, + hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, + hBWE_TD->mem_resamp_HB_32k_fx, + &(hBWE_TD->syn_dm_phase_fx), st_fx->output_Fs_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx, st_fx->rf_flag, st_fx->total_brate_fx ); hb_synth_fx_exp = st_fx->prev_Q_bwe_syn2; move16(); } ELSE IF ( st_fx->bwidth_fx == WB && st_fx->last_extl_fx == WB_TBE ) { - GenTransition_WB_fx( st_fx->syn_overlap_fx, st_fx->old_tbe_synth_fx, st_fx->prev_Qx, 2*NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), hb_synth_fx, - st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->output_Fs_fx, st_fx->mem_resamp_HB_fx ); + GenTransition_WB_fx(hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, st_fx->prev_Qx, 2*NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), hb_synth_fx, + hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, st_fx->output_Fs_fx, hBWE_TD->mem_resamp_HB_fx ); hb_synth_fx_exp = st_fx->prev_Qx; move16(); @@ -867,15 +922,15 @@ void evs_dec_fx( } ELSE IF ( EQ_16(st_fx->last_codec_mode,MODE1)) { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx), st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); + swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx), hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); IF( EQ_16(st_fx->extl_fx, FB_TBE)) { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); } - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); } } } @@ -907,7 +962,7 @@ void evs_dec_fx( test(); test(); test(); - IF ( st_fx->hFdCngDec_fx != NULL && (EQ_32(st_fx->sr_core,8000)||EQ_32(st_fx->sr_core,12800)||EQ_32(st_fx->sr_core,16000))&&LE_32(st_fx->total_brate_fx,ACELP_32k)) + IF ( st_fx->hFdCngDec_fx != NULL && (EQ_32(st_fx->sr_core,8000)||EQ_32(st_fx->sr_core, INT_FS_12k8)||EQ_32(st_fx->sr_core, INT_FS_16k))&&LE_32(st_fx->total_brate_fx,ACELP_32k)) { /*************************************** In CLDFB domain: @@ -916,10 +971,7 @@ void evs_dec_fx( ****************************************/ HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec_fx; move16(); - - noisy_speech_detection( st_fx->VAD && st_fx->m_frame_type==ACTIVE_FRAME, output_sp, st_fx->L_frame_fx, 0, hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, - hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, - &(hFdCngDec->lp_noise), &(hFdCngDec->lp_speech), &(hFdCngDec->hFdCngCom->flag_noisy_speech) ); + noisy_speech_detection(st_fx->hFdCngDec_fx, st_fx->VAD && st_fx->m_frame_type == ACTIVE_FRAME, output_sp, 0); hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r(hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); IF ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) @@ -929,8 +981,11 @@ void evs_dec_fx( } st_fx->lp_noise = hFdCngDec->lp_noise; move32(); - ApplyFdCng( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, hFdCngDec, st_fx->m_frame_type, st_fx, concealWholeFrame, 0); - +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ApplyFdCng(output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0); +#else + ApplyFdCng( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0); +#endif /* Generate additional comfort noise to mask potential coding artefacts */ test(); IF( EQ_16(st_fx->m_frame_type,ACTIVE_FRAME)&&st_fx->flag_cna) @@ -961,7 +1016,7 @@ void evs_dec_fx( timeIn_e = s_max(0, sub(getScaleFactor16( output_sp, st_fx->L_frame_fx ), 3)); IF( NE_16(st_fx->core_fx,ACELP_CORE)) { - timeIn_e = s_max(0, s_min(sub(getScaleFactor16( pcmbufFB, st_fx->L_frameTCX ), 3),timeIn_e)); + timeIn_e = s_max(0, s_min(sub(getScaleFactor16( pcmbufFB, hTcxDec->L_frameTCX ), 3),timeIn_e)); } Scale_sig( output_sp, st_fx->L_frame_fx, timeIn_e ); timeIn_e = negate( timeIn_e ); @@ -977,8 +1032,7 @@ void evs_dec_fx( Copy( st_fx->hFdCngDec_fx->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame_fx ); Copy( st_fx->hFdCngDec_fx->hFdCngCom->A_cng, A, M+1 ); - update_decoder_LPD_cng( st_fx, coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); - + update_decoder_LPD_cng( st_fx, st_fx->coder_type_fx, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); /* Generate additional comfort noise to mask potential coding artefacts */ IF( st_fx->flag_cna ) { @@ -1078,8 +1132,8 @@ void evs_dec_fx( /* MODE1 MDCT to ACELP 2 transition */ delay_comp = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, negate(st_fx->Q_old_postdec)); - st_fx->Q_old_postdec = 0; + Scale_sig(st_fx->delay_buf_out_fx, delay_comp, negate(hHQ_core->Q_old_postdec)); + hHQ_core->Q_old_postdec = 0; move16(); delay_tdbwe= NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS- DELAY_CLDFB_NS); IF( GE_16(output_frame,L_FRAME16k)) @@ -1105,20 +1159,20 @@ void evs_dec_fx( move16(); test(); - IF( st_fx->prev_bfi_fx && st_fx->HqVoicing_fx ) + IF( st_fx->prev_bfi_fx && hHQ_core->HqVoicing_fx ) { - Copy( st_fx->fer_samples_fx, &st_fx->old_out_fx[nz], tmps); + Copy(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps); } ELSE { - Scale_sig(st_fx->old_out_fx, nz+tmps, negate(st_fx->Q_old_wtda)); + Scale_sig(hHQ_core->old_out_fx, nz+tmps, negate(hHQ_core->Q_old_wtda)); } - st_fx->Q_old_wtda = 0; + hHQ_core->Q_old_wtda = 0; move16(); FOR (i = 0; i < tmps; i++) { - output_sp[i+delay_comp] = msu_r(L_mult(output_sp[i+delay_comp], alpha), shr(st_fx->old_out_fx[i+nz], timeIn_e), add(alpha, -32768)); + output_sp[i+delay_comp] = msu_r(L_mult(output_sp[i+delay_comp], alpha), shr(hHQ_core->old_out_fx[i+nz], timeIn_e), add(alpha, -32768)); move16(); alpha = add(alpha, step); } @@ -1127,12 +1181,12 @@ void evs_dec_fx( { IF( EQ_32(st_fx->output_Fs_fx,8000)) { - Copy(st_fx->delay_buf_out_fx, st_fx->FBTCXdelayBuf, delay_comp); + Copy(st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp); } ELSE { - Copy( st_fx->prev_synth_buffer_fx, st_fx->FBTCXdelayBuf, delay_tdbwe ); - Copy( st_fx->delay_buf_out_fx, st_fx->FBTCXdelayBuf + delay_tdbwe, delay_comp ); + Copy( st_fx->prev_synth_buffer_fx, hTcxDec->FBTCXdelayBuf, delay_tdbwe ); + Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp ); } } } @@ -1146,14 +1200,14 @@ void evs_dec_fx( } ELSE { - Copy( st_fx->old_synthFB_fx+st_fx->old_synth_lenFB-delay_comp, st_fx->delay_buf_out_fx, delay_comp ); + Copy(hTcxDec->old_synthFB_fx+ hTcxDec->old_synth_lenFB-delay_comp, st_fx->delay_buf_out_fx, delay_comp ); IF( EQ_32(st_fx->output_Fs_fx, 8000)) { - Copy(st_fx->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp); + Copy(hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp); } ELSE { - Copy( st_fx->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); + Copy(hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); } Copy(pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub(output_frame, delay_comp)); } @@ -1175,7 +1229,7 @@ void evs_dec_fx( test(); test(); test(); - IF( st_fx->bfi_fx == 0 && EQ_16(st_fx->core_fx, ACELP_CORE)&&(st_fx->tec_flag!=0||st_fx->tfa_flag!=0)&>_32(st_fx->output_Fs_fx,8000)) + IF( st_fx->bfi_fx == 0 && EQ_16(st_fx->core_fx, ACELP_CORE)&&(st_fx->tec_flag!=0||st_fx->tfa_flag!=0)&>_32(st_fx->output_Fs_fx,8000) /*&& st_fx->hTECDec_fx != NULL*/) { tmp16 = 0; move16(); @@ -1225,8 +1279,8 @@ void evs_dec_fx( test(); IF ( GT_16(st_fx->last_core_bfi, ACELP_CORE)||(st_fx->bfi_fx&&st_fx->last_core_fx>ACELP_CORE)||(st_fx->prev_bfi_fx&&st_fx->last_con_tcx)) { - Copy_Scale_sig(st_fx->FBTCXdelayBuf, output_sp, tmps, negate(timeIn_e)); - Copy_Scale_sig(pcmbufFB, output_sp + tmps, sub(st_fx->L_frameTCX, tmps), negate(timeIn_e)); + Copy_Scale_sig(hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate(timeIn_e)); + Copy_Scale_sig(pcmbufFB, output_sp + tmps, sub(hTcxDec->L_frameTCX, tmps), negate(timeIn_e)); } ELSE { @@ -1245,22 +1299,22 @@ void evs_dec_fx( move16(); alpha = add(alpha, step); } - Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl(tmps,1), sub(st_fx->L_frameTCX, shl(tmps,1)), negate(timeIn_e) ); + Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl(tmps,1), sub(hTcxDec->L_frameTCX, shl(tmps,1)), negate(timeIn_e) ); } - Copy( pcmbufFB + st_fx->L_frameTCX - tmps, st_fx->FBTCXdelayBuf, tmps ); + Copy( pcmbufFB + hTcxDec->L_frameTCX - tmps, hTcxDec->FBTCXdelayBuf, tmps ); test(); IF( st_fx->bfi_fx && GT_16(st_fx->last_core_fx, ACELP_CORE)) { IF( EQ_32(st_fx->output_Fs_fx, 8000)) { - Copy(st_fx->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs_fx, DELAY_CLDFB_NS)); + Copy(hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs_fx, DELAY_CLDFB_NS)); } ELSE { - Copy( st_fx->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); - Copy( st_fx->FBTCXdelayBuf + NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs_fx, DELAY_CLDFB_NS) ); + Copy(hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); + Copy(hTcxDec->FBTCXdelayBuf + NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs_fx, DELAY_CLDFB_NS) ); } } } @@ -1268,7 +1322,7 @@ void evs_dec_fx( { Word16 step, alpha; - Copy_Scale_sig(st_fx->FBTCXdelayBuf, output_sp, delta, negate(timeIn_e)); + Copy_Scale_sig(hTcxDec->FBTCXdelayBuf, output_sp, delta, negate(timeIn_e)); i = 15; move16(); @@ -1279,24 +1333,20 @@ void evs_dec_fx( FOR (i = delta; i < tmps; i++) { - output_sp[i] = msu_r(L_mult(output_sp[i], alpha), shr(st_fx->FBTCXdelayBuf[i], timeIn_e), add(alpha, -32768)); + output_sp[i] = msu_r(L_mult(output_sp[i], alpha), shr(hTcxDec->FBTCXdelayBuf[i], timeIn_e), add(alpha, -32768)); move16(); alpha = add(alpha, step); } } - Scale_sig(st_fx->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); - Scale_sig(st_fx->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); + Scale_sig(hTcxLtpDec->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); + Scale_sig(hTcxLtpDec->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); test(); Scale_sig( output_sp, output_frame, timeIn_e ); - tcx_ltp_post( st_fx->tcxltp, st_fx->core_fx, st_fx->L_frameTCX, st_fx->L_frame_fx, NS2SA_fx2( st_fx->output_Fs_fx, ACELP_LOOK_NS ) + tmps, - output_sp, st_fx->FBTCXdelayBuf, delta, st_fx->bfi_fx, st_fx->tcxltp_pitch_int, st_fx->tcxltp_pitch_fr, st_fx->tcxltp_gain, - &st_fx->tcxltp_pitch_int_post_prev, &st_fx->tcxltp_pitch_fr_post_prev, &st_fx->tcxltp_gain_post_prev, &st_fx->tcxltp_filt_idx_prev, - st_fx->pit_res_max, - &st_fx->pit_res_max_past, - st_fx->damping, L_sub(st_fx->total_brate_fx, 96000) >= 0, st_fx->tcxltp_mem_in, st_fx->tcxltp_mem_out, st_fx->total_brate_fx ); + tcx_ltp_post(st_fx, hTcxLtpDec, st_fx->core_fx, output_frame/*hTcxDec->L_frameTCX*/, NS2SA_fx2( st_fx->output_Fs_fx, ACELP_LOOK_NS ) + tmps, + output_sp, hTcxDec->FBTCXdelayBuf); Copy( output_sp, synth_fx, output_frame ); } /* end of MODE2 */ @@ -1305,38 +1355,38 @@ void evs_dec_fx( /*----------------------------------------------------------------* * Save synthesis for HQ FEC *----------------------------------------------------------------*/ + PMT("The code below could be move to save_synthesis_hq_fec") post_hq_delay = NS2SA_fx2( st_fx->output_Fs_fx, POST_HQ_DELAY_NS ); IF (EQ_16(st_fx->codec_mode, MODE1)) { - Copy( st_fx->synth_history_fx+output_frame, st_fx->synth_history_fx, output_frame-post_hq_delay+NS2SA_fx2( st_fx->output_Fs_fx, PH_ECU_MEM_NS )); - Copy_Scale_sig( synth_fx, st_fx->old_synthFB_fx+output_frame-post_hq_delay, output_frame,negate(Qpostd)); /* output_sp not initialized yet */ + Copy(hTcxDec->synth_history_fx+output_frame, hTcxDec->synth_history_fx, output_frame-post_hq_delay+NS2SA_fx2( st_fx->output_Fs_fx, PH_ECU_MEM_NS )); + Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx+output_frame-post_hq_delay, output_frame,negate(Qpostd)); /* output_sp not initialized yet */ /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill this buffer are not available for all cases, the impact on the output is limited */ - set16_fx( st_fx->old_synthFB_fx+2*output_frame-post_hq_delay, 0, post_hq_delay ); + set16_fx(hTcxDec->old_synthFB_fx+2*output_frame-post_hq_delay, 0, post_hq_delay ); IF( GE_16(output_frame, L_FRAME16k)) { - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS),negate(st_fx->Qprev_synth_buffer_fx)); + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS),negate(st_fx->Qprev_synth_buffer_fx)); } IF( NE_16(st_fx->core_fx,ACELP_CORE)) { IF( GE_16(output_frame, L_FRAME16k)) { - Copy_Scale_sig( synth_fx+output_frame, st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS),negate(Qpostd)); - Copy_Scale_sig( st_fx->old_out_fx+NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS), st_fx->old_synthFB_fx+2*output_frame, NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(st_fx->Q_old_wtda)); + Copy_Scale_sig( synth_fx+output_frame, hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS),negate(Qpostd)); + Copy_Scale_sig(hHQ_core->old_out_fx+NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS), hTcxDec->old_synthFB_fx+2*output_frame, NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(hHQ_core->Q_old_wtda)); } ELSE { - Copy_Scale_sig( synth_fx+output_frame, st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS),negate(Qpostd)); - Copy_Scale_sig( st_fx->old_out_fx+NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS), st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(st_fx->Q_old_wtda)); + Copy_Scale_sig( synth_fx+output_frame, hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS),negate(Qpostd)); + Copy_Scale_sig(hHQ_core->old_out_fx+NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS), hTcxDec->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(hHQ_core->Q_old_wtda)); } } } - /*----------------------------------------------------------------* * HP filtering *----------------------------------------------------------------*/ @@ -1382,7 +1432,7 @@ void evs_dec_fx( st_fx->bfi_fx = 1; move16(); } - updt_dec_common_fx( st_fx, -1, output_sp ); + updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, Qpostd); } ELSE { @@ -1391,118 +1441,8 @@ void evs_dec_fx( st_fx->bfi_fx = 0; move16(); } - updt_dec_common_fx( st_fx, hq_core_type, output_sp ); - } - IF( EQ_16(st_fx->codec_mode,MODE2)) - { - test(); - IF(EQ_16(st_fx->use_partial_copy,1)&&EQ_16(st_fx->rf_frame_type,RF_NELP)) - { - st_fx->last_nelp_mode_dec_fx = 1; - } - ELSE - { - st_fx->last_nelp_mode_dec_fx = 0; - } - } - - st_fx->prev_use_partial_copy = st_fx->use_partial_copy; - move16(); - - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - - st_fx->prev_Q_exc = st_fx->Q_exc; - move16(); - - L_tmp = L_mult(st_fx->tilt_code_dec_fx[0], 4096); - FOR( i=1; itilt_code_dec_fx[i], 4096); - } - st_fx->prev_tilt_code_dec_fx = round_fx(L_tmp); - - st_fx->prev_coder_type_fx = coder_type; - move16(); - if( EQ_16(st_fx->core_fx,HQ_CORE)) - { - st_fx->prev_coder_type_fx = GENERIC; - move16(); - } - - test(); - IF ( GT_32(st_fx->core_brate_fx,SID_2k40)&&EQ_16(st_fx->first_CNG_fx,1)) - { - if( GE_16(st_fx->act_cnt_fx,BUF_DEC_RATE)) - { - st_fx->act_cnt_fx = 0; - move16(); - } - - st_fx->act_cnt_fx = add(st_fx->act_cnt_fx, 1); - - test(); - if( (EQ_16(st_fx->act_cnt_fx,BUF_DEC_RATE))&&(st_fx->ho_hist_size_fx>0)) - { - st_fx->ho_hist_size_fx = sub(st_fx->ho_hist_size_fx,1); - } - - st_fx->act_cnt2_fx = add(st_fx->act_cnt2_fx,1); - if( GE_16(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD)) - { - st_fx->act_cnt2_fx = MIN_ACT_CNG_UPD; - move16(); - } + updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, Qpostd); } + return IVAS_ERR_OK; - test(); - test(); - if ( LE_32(st_fx->core_brate_fx,SID_2k40)&&st_fx->first_CNG_fx==0&&EQ_16(st_fx->cng_type_fx,LP_CNG)) - { - st_fx->first_CNG_fx = 1; - move16(); - } - - /* update bandwidth switching parameters */ - IF( EQ_16(st_fx->codec_mode, MODE1)) - { - updt_bw_switching_fx( st_fx, synth_fx, Qpostd ); - } - ELSE - { - st_fx->last_bwidth_fx = st_fx->bwidth_fx; - move32(); - } - - /* synchronisation of CNG seeds*/ - test(); - test(); - IF( st_fx->bfi_fx || (NE_32(st_fx->core_brate_fx,FRAME_NO_DATA)&&NE_32(st_fx->core_brate_fx,SID_2k40))) - { - Random( &(st_fx->cng_seed_fx) ); - Random( &(st_fx->cng_ener_seed_fx) ); - } - - test(); - IF( st_fx->enablePlcWaveadjust && !concealWholeFrameTmp ) - { - /* update the parameters used in waveform adjustment */ - concealment_update2_x( output_sp, &st_fx->plcInfo, st_fx->L_frameTCX ); - } - - st_fx->last_total_brate_ber_fx = st_fx->total_brate_fx; - move32(); - if( st_fx->bfi_fx == 0 ) - { - st_fx->last_total_brate_fx = st_fx->total_brate_fx; - move32(); - } - - st_fx->last_flag_cna = st_fx->flag_cna; - move16(); - st_fx->hFdCngDec_fx->hFdCngCom->frame_type_previous = st_fx->m_frame_type; - move16(); - st_fx->prev_bws_cnt_fx = st_fx->bws_cnt_fx; - - return; } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 5f94890..836730a 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -4,19 +4,16 @@ #include +#include "typedef.h" +#include +#include "options.h" #include "rom_com_fx.h" #include "stat_dec_fx.h" -#include "stl.h" -#include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" - - - - /******************************** * External tables * ********************************/ @@ -34,89 +31,127 @@ extern const Word16 T_DIV_L_Frame[]; /* format: 0Q15 * 2^-7 */ Function: create an instance of type FD_CNG */ -void createFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) +ivas_error createFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) { HANDLE_FD_CNG_DEC hs; + ivas_error error; + error = IVAS_ERR_OK; /* Allocate memory */ - hs = (HANDLE_FD_CNG_DEC) calloc(1, sizeof (FD_CNG_DEC)); - + hs = (HANDLE_FD_CNG_DEC)count_malloc(sizeof (FD_CNG_DEC)); - createFdCngCom(&(hs->hFdCngCom)); + if (hs == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG DEC structure"); + } + if ((error = createFdCngCom(&(hs->hFdCngCom))) != IVAS_ERR_OK) + { + return error; + } *hFdCngDec = hs; + return error; } -Word16 initFdCngDec (HANDLE_FD_CNG_DEC hs, Word16 scale) +void initFdCngDec( + DEC_CORE_HANDLE st, /* i/o: decoder state structure */ + Word16 scale +) { /* Initialize common */ + HANDLE_FD_CNG_DEC hFdCngDec; + + hFdCngDec = st->hFdCngDec_fx; - initFdCngCom( hs->hFdCngCom, scale ); - set16_fx( hs->olapBufferAna, 0, 320 ); - hs->hFdCngCom->olapBufferAna = hs->olapBufferAna; + initFdCngCom( hFdCngDec->hFdCngCom, scale ); + set16_fx( hFdCngDec->olapBufferAna, 0, 320 ); + hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; move16(); - set16_fx( hs->olapBufferSynth2, 0, FFTLEN ); - hs->hFdCngCom->olapBufferSynth2 = hs->olapBufferSynth2; + set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); + hFdCngDec->hFdCngCom->olapBufferSynth2 = hFdCngDec->olapBufferSynth2; move16(); /* Set some counters and flags */ - hs->flag_dtx_mode = 0; + hFdCngDec->flag_dtx_mode = 0; move16(); - hs->lp_noise = -167772160l/*-20.f Q23*/; /* format: Q8.24 */ - hs->lp_speech = 209715200l/* 25.f Q23*/; /* format: Q8.24 */ + hFdCngDec->lp_noise = -167772160l/*-20.f Q23*/; /* format: Q8.24 */ + hFdCngDec->lp_speech = 209715200l/* 25.f Q23*/; /* format: Q8.24 */ /* Initialization of the noise estimation algorithm */ - set32_fx( hs->bandNoiseShape, 0, FFTLEN2 ); - set16_fx( &hs->bandNoiseShape_exp, 0, 1); + set32_fx( hFdCngDec->bandNoiseShape, 0, FFTLEN2 ); + set16_fx( &hFdCngDec->bandNoiseShape_exp, 0, 1); - set32_fx (hs->partNoiseShape, 0, NPART ); - set16_fx( &hs->partNoiseShape_exp, 0, 1); + set32_fx (hFdCngDec->partNoiseShape, 0, NPART ); + set16_fx( &hFdCngDec->partNoiseShape_exp, 0, 1); - set32_fx( hs->msPeriodog, 0, NPART_SHAPING ); - set16_fx( &hs->msPeriodog_exp, 0, 1); + set32_fx( hFdCngDec->msPeriodog, 0, NPART_SHAPING ); + set16_fx( &hFdCngDec->msPeriodog_exp, 0, 1); - set32_fx( hs->msAlpha, 0, NPART_SHAPING ); + set32_fx( hFdCngDec->msAlpha, 0, NPART_SHAPING ); - set32_fx( hs->msBminWin, 0, NPART_SHAPING ); + set32_fx( hFdCngDec->msBminWin, 0, NPART_SHAPING ); - set32_fx( hs->msBminSubWin, 0, NPART_SHAPING ); + set32_fx( hFdCngDec->msBminSubWin, 0, NPART_SHAPING ); - set16_fx( hs->msPsd, 0, NPART_SHAPING ); - set16_fx( hs->msNoiseFloor, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msPsd, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); - set32_fx( hs->msNoiseEst, 0, NPART_SHAPING ); - set16_fx( &hs->msNoiseEst_exp, 0, 1); + set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); + set16_fx( &hFdCngDec->msNoiseEst_exp, 0, 1); - set32_fx( hs->msMinBuf, 2147483647l/*1.0 Q31*/, MSNUMSUBFR*NPART_SHAPING ); + set32_fx( hFdCngDec->msMinBuf, 2147483647l/*1.0 Q31*/, MSNUMSUBFR*NPART_SHAPING ); - set32_fx( hs->msCurrentMin, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); + set32_fx( hFdCngDec->msCurrentMin, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); - set32_fx( hs->msCurrentMinOut, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); + set32_fx( hFdCngDec->msCurrentMinOut, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); - set32_fx( hs->msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); + set32_fx( hFdCngDec->msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); - set16_fx( hs->msLocalMinFlag, 0, NPART_SHAPING ); - set16_fx( hs->msNewMinFlag, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); - set16_fx( hs->msPsdFirstMoment, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msPsdFirstMoment, 0, NPART_SHAPING ); - set32_fx( hs->msPsdSecondMoment, 0, NPART_SHAPING ); - set16_fx( hs->msPeriodogBuf, 0, MSBUFLEN*NPART_SHAPING ); + set32_fx( hFdCngDec->msPsdSecondMoment, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msPeriodogBuf, 0, MSBUFLEN*NPART_SHAPING ); - hs->msPeriodogBufPtr = 0; + hFdCngDec->msPeriodogBufPtr = 0; move16(); - set16_fx( hs->msLogPeriodog, 0, NPART_SHAPING ); - set16_fx( hs->msLogNoiseEst, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msLogPeriodog, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msLogNoiseEst, 0, NPART_SHAPING ); - set16_fx( hs->psize_shaping, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->psize_shaping, 0, NPART_SHAPING ); move16(); - hs->nFFTpart_shaping = 0; - + hFdCngDec->nFFTpart_shaping = 0; +#ifdef IVAS_CODE_CNG + set_f(hFdCngDec->hFdCngCom->sidNoiseEstLp, 0.0f, NPART); + + set_f(hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k); + set_f(hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING); + + hFdCngDec->ms_last_inactive_bwidth = NB; + hFdCngDec->ms_cnt_bw_up = 0; + + hFdCngDec->cna_LR_LT = 0.5f; + hFdCngDec->cna_ILD_LT = 0.0f; + hFdCngDec->first_cna_noise_updated = 0; + hFdCngDec->first_cna_noise_update_cnt = 0; + hFdCngDec->cna_nbands = 6; + mvs2s(cna_init_bands, hFdCngDec->cna_band_limits, MAX_CNA_NBANDS + 1); + hFdCngDec->cna_act_fact = 1.0f; + hFdCngDec->cna_rescale_fact = 0.0f; + hFdCngDec->cna_seed = 5687; + set_zero(hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX); + set_zero(hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX); + + st->CNG_mode = -1; + mvr2r(st->lsp_old, st->lspCNG, M); +#endif + return; - return 0; } /* @@ -136,31 +171,55 @@ Word16 initFdCngDec (HANDLE_FD_CNG_DEC hs, Word16 scale) Returns: void */ -void configureFdCngDec (HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, - Word32 bitrate, - Word16 L_frame +void configureFdCngDec ( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ + Word16 bwidth, + Word32 total_brate, + Word16 L_frame, + const Word16 Last_L_frame, + const Word16 element_mode ) { Word16 j, stopBandFR; - HANDLE_FD_CNG_COM hsCom = hsDec->hFdCngCom; + HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; - hsCom->CngBandwidth = bandwidth; + hsCom->CngBandwidth = bwidth; IF ( EQ_16( hsCom->CngBandwidth, FB )) { hsCom->CngBandwidth = SWB; } test(); - if ( bitrate != FRAME_NO_DATA && NE_32(bitrate, SID_2k40)) + if ( total_brate != FRAME_NO_DATA && NE_32(total_brate, SID_2k40)) + { + hsCom->CngBitrate = total_brate; + move32(); + } + ELSE IF (EQ_32(hsCom->CngBitrate, -1 )) + { + /* set minimum active CBR bitrate if CngBitrate is uninitialized */ + hsCom->CngBitrate = ACELP_7k20; + IF (GT_16(element_mode, EVS_MONO)) + { + hsCom->CngBitrate = IVAS_13k2; + move32(); + } + move32(); + } + + /* FD-CNG config for MDCT-Stereo is always the same (since for > 48 kbps only) */ + /* This may need adjustment in the future if 2TC DTX for some mode uses MDCT-Stereo DTX for lower bitrates too */ + IF (EQ_16(element_mode, IVAS_CPE_MDCT)) { - hsCom->CngBitrate = L_add(bitrate, 0); + hsCom->CngBitrate = IVAS_48k; + move32(); } + hsCom->numSlots = 16; move16(); /* NB configuration */ - IF ( bandwidth == NB ) + IF ( bwidth == NB ) { hsCom->FdCngSetup = FdCngSetup_nb; hsCom->numCoreBands = 16; @@ -170,7 +229,7 @@ void configureFdCngDec (HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variable } /* WB configuration */ - ELSE IF ( EQ_16(bandwidth, WB)) + ELSE IF ( EQ_16(bwidth, WB)) { /* FFT 6.4kHz, no CLDFB */ test(); @@ -218,7 +277,9 @@ void configureFdCngDec (HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variable move16(); hsCom->regularStopBand = 20; move16(); + } + } /* SWB/FB configuration */ @@ -243,6 +304,12 @@ void configureFdCngDec (HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variable move16(); hsCom->regularStopBand = 40; move16(); + test(); + IF(EQ_16(Last_L_frame, L_FRAME) && EQ_16(element_mode, IVAS_CPE_DFT)) + { + hsCom->regularStopBand = 35; + move16(); + } } } hsCom->fftlen = hsCom->FdCngSetup.fftlen; @@ -255,7 +322,8 @@ void configureFdCngDec (HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variable hsCom->startBand = 2; move16(); hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions-1], 1 ); - initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); + initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, + &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); hsCom->nFFTpart = 21; move16(); @@ -286,10 +354,10 @@ void configureFdCngDec (HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variable move16(); } initPartitions(hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, - hsCom->startBand, hsCom->stopFFTbin, hsDec->part_shaping, &hsDec->npart_shaping, hsDec->midband_shaping, - hsDec->psize_shaping, hsDec->psize_shaping_norm, &hsDec->psize_shaping_norm_exp, hsDec->psize_inv_shaping, + hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, + hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); - hsDec->nFFTpart_shaping = hsDec->npart_shaping; + hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; move16(); SWITCH (hsCom->fftlen) @@ -337,7 +405,7 @@ void deleteFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) IF ( hsDec != NULL ) { deleteFdCngCom (&(hsDec->hFdCngCom)); - free(hsDec); + count_free(hsDec); *hFdCngDec = NULL; } } @@ -355,7 +423,7 @@ void deleteFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) st i/o: pointer to FD_CNG structure containing all buffers and variables m_frame_type i : type of frame at the decoder side stcod i : pointer to Coder_State structure - stdec i : pointer to Decoder_State structure + st i : pointer to Decoder_State structure bitrate i : bitrate concealWholeFrame i : binary flag indicating frame loss @@ -365,14 +433,16 @@ void deleteFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) Returns: error */ -Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time domain input */ +Word16 ApplyFdCng ( + Word16 *timeDomainInput, /* i : pointer to time domain input */ Word16 Q, +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + Word16* powerSpectrum, +#endif Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - HANDLE_FD_CNG_DEC st, /* i/o: pointer to FD_CNG structure containing all buffers and variables */ - Word16 m_frame_type, /* i : type of frame at the decoder side */ - Decoder_State_fx *stdec, + Decoder_State_fx *st, const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ Word16 is_music ) @@ -388,20 +458,39 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma Word16 tmp_loop; Word32 L_c; Word16 lsp_cng[M]; + HANDLE_FD_CNG_DEC hFdCngDec; + HANDLE_FD_CNG_COM hFdCngCom; +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + int16_t L_frame, last_L_frame; + int32_t sr_core; + + PMT("Fix point code missing for IVAS_CODE_CNG_FIX185_PLC_FADEOUT") + /* limit L_frame and core fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ + L_frame = min(st->L_frame, L_FRAME16k); + last_L_frame = min(st->last_L_frame, L_FRAME16k); + sr_core = min(st->sr_core, INT_FS_16k); +#endif + hFdCngDec = st->hFdCngDec_fx; + hFdCngCom = hFdCngDec->hFdCngCom; - if(EQ_16(st->hFdCngCom->frame_type_previous,ACTIVE_FRAME)) + + if(EQ_16(hFdCngCom->frame_type_previous,ACTIVE_FRAME)) { - st->hFdCngCom->inactive_frame_counter = 0; + hFdCngCom->inactive_frame_counter = 0; move16(); } + IF (EQ_16(st->element_mode, IVAS_CPE_TD)) + { + hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG_fx; + test(); move16(); + } + cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; + move16(); move16(); + nBins = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); - cngNoiseLevel = st->hFdCngCom->cngNoiseLevel; - cngNoiseLevel_exp = &st->hFdCngCom->cngNoiseLevelExp; - - nBins = sub(st->hFdCngCom->stopFFTbin,st->hFdCngCom->startBand); - - SWITCH ( m_frame_type ) + SWITCH ( st->m_frame_type ) { case ACTIVE_FRAME: @@ -409,71 +498,68 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma * ACTIVE_FRAME at DECODER * **************************/ - st->hFdCngCom->inactive_frame_counter = 0; + hFdCngCom->inactive_frame_counter = 0; move16(); - st->hFdCngCom->sid_frame_counter = 0; + hFdCngCom->sid_frame_counter = 0; move16(); /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ /* set noise estimation inactive during concealment, no update with noise generated by concealment should be performed. */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test();test(); + test();test();test();test(); +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + if (concealWholeFrame == 0 && + (timeDomainInput == NULL || + (*timeDomainInput(-FLT_MAX) && + *(timeDomainInput + hFdCngCom->frameSize - 1) < FLT_MAX && + *(timeDomainInput + hFdCngCom->frameSize - 1) > (-FLT_MAX))) && + ((((st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode) || !st->VAD) && + !(st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode) && (is_music == 0)) || + (st->element_mode == IVAS_CPE_TD)) && + (!st->BER_detect)) +#else IF( (concealWholeFrame == 0) && - (*timeDomainInput < MAXVAL_WORD16) && (*timeDomainInput > MINVAL_WORD16) && (*(timeDomainInput+st->hFdCngCom->frameSize-1) < MAXVAL_WORD16) && (*(timeDomainInput+st->hFdCngCom->frameSize-1) > MINVAL_WORD16) - && ( ((st->flag_dtx_mode == 0) && (stdec->VAD != 0)) == 0 ) - && ( ((stdec->cng_type_fx == LP_CNG) && (st->flag_dtx_mode != 0)) == 0) + (*timeDomainInput < MAXVAL_WORD16) && (*timeDomainInput > MINVAL_WORD16) && (*(timeDomainInput+hFdCngCom->frameSize-1) < MAXVAL_WORD16) && (*(timeDomainInput+hFdCngCom->frameSize-1) > MINVAL_WORD16) + && ( ((hFdCngDec->flag_dtx_mode == 0) && (st->VAD != 0)) == 0 ) + && ( ((st->cng_type_fx == LP_CNG) && (hFdCngDec->flag_dtx_mode != 0)) == 0) && ( is_music == 0 ) - && (stdec->BER_detect == 0) + && (st->BER_detect == 0) ) +#endif { /* Perform noise estimation at the decoder */ - perform_noise_estimation_dec ( - timeDomainInput, - Q, - st - ); - +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + perform_noise_estimation_dec(timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD); +#else + perform_noise_estimation_dec (timeDomainInput, Q, hFdCngDec); +#endif /* Update the shaping parameters */ - scalebands ( - st->msNoiseEst, - st->part_shaping, - st->nFFTpart_shaping, - st->midband_shaping, - st->nFFTpart_shaping, - nBins, - st->bandNoiseShape, - 1 - ); - - st->bandNoiseShape_exp = st->msNoiseEst_exp; + test(); + IF (NE_16(st->element_mode, IVAS_CPE_TD) && NE_16(st->element_mode, IVAS_CPE_DFT)) + { + scalebands(hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape,1 ); + } + hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* Update CNG levels */ test(); - IF ( st->flag_dtx_mode != 0 && stdec->cng_type_fx == FD_CNG ) + IF ( hFdCngDec->flag_dtx_mode != 0 && st->cng_type_fx == FD_CNG ) { /* This needs to be done only once per inactive phase */ bandcombinepow ( - st->bandNoiseShape, - st->bandNoiseShape_exp, + hFdCngDec->bandNoiseShape, + hFdCngDec->bandNoiseShape_exp, nBins, - st->hFdCngCom->part, - st->hFdCngCom->nFFTpart, - st->hFdCngCom->psize_inv, - st->partNoiseShape, - &st->partNoiseShape_exp + hFdCngCom->part, + hFdCngCom->nFFTpart, + hFdCngCom->psize_inv, + hFdCngDec->partNoiseShape, + &hFdCngDec->partNoiseShape_exp ); @@ -481,27 +567,27 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma move16(); s2 = -(WORD32_BITS-1); move16(); - FOR (k=0; k < st->hFdCngCom->nFFTpart; k++) + FOR (k=0; k < hFdCngCom->nFFTpart; k++) { - assert(st->partNoiseShape[k]>=0); - assert(st->hFdCngCom->sidNoiseEst[k]>=0); + assert(hFdCngDec->partNoiseShape[k]>=0); + assert(hFdCngCom->sidNoiseEst[k]>=0); /* add DELTA as it is done in FLC version, in order to avoid num > denom */ facTab[k] = 0; move16(); - IF ( st->partNoiseShape[k] != 0) + IF ( hFdCngDec->partNoiseShape[k] != 0) { - s1 = norm_l(st->hFdCngCom->sidNoiseEst[k]); - L_tmp = L_shl(st->hFdCngCom->sidNoiseEst[k], s1); - L_tmp_exp = sub(st->hFdCngCom->sidNoiseEstExp, s1); + s1 = norm_l(hFdCngCom->sidNoiseEst[k]); + L_tmp = L_shl(hFdCngCom->sidNoiseEst[k], s1); + L_tmp_exp = sub(hFdCngCom->sidNoiseEstExp, s1); L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); L_tmp = L_shr(L_tmp, 1); s = add(L_tmp_exp, 1); num = extract_h(L_tmp); - s1 = norm_l(st->partNoiseShape[k]); - L_tmp = L_shl(st->partNoiseShape[k], s1); - L_tmp_exp = sub(st->partNoiseShape_exp, s1); + s1 = norm_l(hFdCngDec->partNoiseShape[k]); + L_tmp = L_shl(hFdCngDec->partNoiseShape[k], s1); + L_tmp_exp = sub(hFdCngDec->partNoiseShape_exp, s1); L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); s = sub(s, L_tmp_exp); denom = extract_h(L_tmp); @@ -520,13 +606,13 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma s2 = s_max(s2,facTabExp[k]); } - FOR (k=0; k < st->hFdCngCom->nFFTpart; k++) + FOR (k=0; k < hFdCngCom->nFFTpart; k++) { s = sub(facTabExp[k],s2); s = s_max(s_min(s,WORD32_BITS-1),-(WORD32_BITS-1)); - FOR ( ; j <= st->hFdCngCom->part[k]; j++) + FOR ( ; j <= hFdCngCom->part[k]; j++) { - cngNoiseLevel[j] = L_shl(Mpy_32_16_1(st->bandNoiseShape[j],facTab[k]),s); + cngNoiseLevel[j] = L_shl(Mpy_32_16_1(hFdCngDec->bandNoiseShape[j],facTab[k]),s); move32(); } } @@ -534,34 +620,43 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma /* adapt scaling for rest of the buffer */ IF (NE_16(s2,-(WORD32_BITS-1))) { - s = sub(*cngNoiseLevel_exp,add(st->bandNoiseShape_exp,s2)); - FOR ( ; k < st->hFdCngCom->npart; k++) + s = sub(*cngNoiseLevel_exp,add(hFdCngDec->bandNoiseShape_exp,s2)); + FOR ( ; k < hFdCngCom->npart; k++) { - FOR( ; j <= st->hFdCngCom->part[k]; j++) + FOR( ; j <= hFdCngCom->part[k]; j++) { cngNoiseLevel[j] = L_shl(cngNoiseLevel[j],s); move32(); } } - *cngNoiseLevel_exp = add(st->bandNoiseShape_exp,s2); + *cngNoiseLevel_exp = add(hFdCngDec->bandNoiseShape_exp,s2); move16(); } } ELSE { /* This sets the new CNG levels until a SID update overwrites it */ - Copy32 ( - st->bandNoiseShape, - cngNoiseLevel, - nBins - ); - - *cngNoiseLevel_exp = st->bandNoiseShape_exp; + test(); test(); test(); + IF(!(EQ_16(st->element_mode, IVAS_CPE_TD)) || (EQ_16(st->element_mode, IVAS_CPE_TD) && !hFdCngDec->flag_dtx_mode && !st->VAD)) + { + Copy32(hFdCngDec->bandNoiseShape,cngNoiseLevel,nBins); + *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } - /*stdec->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, st->hFdCngCom->stopFFTbin - st->hFdCngCom->startBand) / 2 * st->hFdCngCom->fftlen) / stdec->Mode2_L_frame);*/ - tmp_loop = sub(st->hFdCngCom->stopFFTbin , st->hFdCngCom->startBand); + } +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + if (st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf(sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / NORM_MDCT_FACTOR); + } + else + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); + } +#endif + /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ + tmp_loop = sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand); L_tmp = L_deposit_h(0); L_c = L_deposit_h(0); FOR(j = 0 ; j < tmp_loop; j++) @@ -583,66 +678,132 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma L_tmp = norm_llQ31(L_c,L_tmp,&L_tmp_exp); L_tmp_exp = sub(add(L_tmp_exp,*cngNoiseLevel_exp),1); - L_tmp = Mpy_32_16_1(L_tmp,st->hFdCngCom->fftlen); /*Q16*/ + L_tmp = Mpy_32_16_1(L_tmp,hFdCngCom->fftlen); /*Q16*/ - L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,stdec->L_frame_fx,95),1-15)]);/*Q16,exp -7*/ + L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame_fx,95),1-15)]);/*Q16,exp -7*/ L_tmp_exp = add(L_tmp_exp,-7); /*->Q16, L_tmp_exp */ L_tmp_exp = add(L_tmp_exp,31-16); /*->Q31, L_tmp_exp*/ - stdec->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); - stdec->cngTDLevel_e = L_tmp_exp; + st->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); + st->cngTDLevel_e = L_tmp_exp; move16(); + } + ELSE IF (EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT)) + { + IF (hFdCngCom->active_frame_counter > 0) + { + /* Perform noise estimation in active frames in the decoder for downward updates */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + perform_noise_estimation_dec(timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD); +#else + perform_noise_estimation_dec(timeDomainInput, Q, hFdCngDec); +#endif + } } test(); test(); L_tmp = 0; - FOR( j=st->hFdCngCom->startBand; jhFdCngCom->stopFFTbin; j++ ) + FOR( j=hFdCngCom->startBand; jstopFFTbin; j++ ) { L_tmp = L_add(L_tmp,L_shr(cngNoiseLevel[j],16)); } L_tmp_exp = add(*cngNoiseLevel_exp,16); - IF (EQ_16(concealWholeFrame,1)&&EQ_16(stdec->nbLostCmpt,1)&&(L_shl(L_tmp,L_tmp_exp)>21474836 /*0.01f Q31*/)) + IF (EQ_16(concealWholeFrame,1)&&EQ_16(st->nbLostCmpt,1)&&(L_shl(L_tmp,L_tmp_exp)>21474836 /*0.01f Q31*/)) { /* update isf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ - lpc_from_spectrum(cngNoiseLevel, *cngNoiseLevel_exp, st->hFdCngCom->startBand, st->hFdCngCom->stopFFTbin, st->hFdCngCom->fftlen, st->hFdCngCom->A_cng, - M, 0); - E_LPC_a_lsp_conversion( st->hFdCngCom->A_cng, lsp_cng, stdec->lspold_cng, M ); - Copy( lsp_cng, stdec->lspold_cng, M); +#ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0); + E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); + Copy( lsp_cng, st->lspold_cng, M); + + lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); +#else + if (st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE) + { + float scf[SNS_NPTS]; + float scf_int[FDNS_NPTS]; + float whitenend_noise_shape[L_FRAME16k]; + int16_t inc, start_idx, stop_idx; + float* noiseLevelPtr; + + + inc = (st->core > TCX_20) ? 2 : 1; + start_idx = hFdCngCom->startBand / inc; + stop_idx = L_frame / inc; + noiseLevelPtr = cngNoiseLevel; + + set_zero(whitenend_noise_shape, start_idx); + for (j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc) + { + whitenend_noise_shape[j] = *noiseLevelPtr; + } + if (st->core == TCX_20_CORE) + { + st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX20; + } + else + { + st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX10; + } - lsp2lsf_fx( lsp_cng, stdec->lsf_cng, M, stdec->sr_core ); - stdec->plcBackgroundNoiseUpdated = 1; + sns_compute_scf(whitenend_noise_shape, st->hTonalMDCTConc->psychParams, L_frame, scf); + sns_interpolate_scalefactors(scf_int, scf, ENC); + sns_interpolate_scalefactors(st->hTonalMDCTConc->scaleFactorsBackground, scf, DEC); + sns_shape_spectrum(whitenend_noise_shape, st->hTonalMDCTConc->psychParams, scf_int, L_frame); + + mvr2r(whitenend_noise_shape + start_idx, cngNoiseLevel, stop_idx - start_idx); + wmops_sub_end(); + } + else if (st->element_mode != IVAS_CPE_MDCT) + { + lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f); + a2lsp_stab(hFdCngCom->A_cng, lsp_cng, st->lspold_cng); + mvr2r(lsp_cng, st->lspold_cng, M); + lsp2lsf(lsp_cng, st->lsf_cng, M, sr_core); + } + +#endif + st->plcBackgroundNoiseUpdated = 1; move16(); } BREAK; case SID_FRAME: - st->flag_dtx_mode = 1; + hFdCngDec->flag_dtx_mode = 1; move16(); /* no break */ case ZERO_FRAME: test(); - IF(stdec!=NULL && stdec->cng_type_fx==LP_CNG) + IF(st!=NULL && st->cng_type_fx==LP_CNG) { /* Perform noise estimation on inactive phase at the decoder */ - perform_noise_estimation_dec(timeDomainInput, Q, st - ); - +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + perform_noise_estimation_dec(timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD); +#else + perform_noise_estimation_dec(timeDomainInput, Q, hFdCngDec); +#endif /* Update the shaping parameters */ - scalebands(st->msNoiseEst, st->part_shaping, st->nFFTpart_shaping, st->midband_shaping, st->nFFTpart_shaping, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand, st->bandNoiseShape, 1); - st->bandNoiseShape_exp = st->msNoiseEst_exp; + + IF (NE_16(st->element_mode, IVAS_CPE_TD) && NE_16(st->element_mode, IVAS_CPE_DFT)) + { + scalebands(hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape, 1); + } + hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); /* This sets the new CNG levels until a SID update overwrites it */ - Copy32(st->bandNoiseShape, cngNoiseLevel, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand); /* This sets the new CNG levels until a SID update overwrites it */ - *cngNoiseLevel_exp = st->bandNoiseShape_exp; + Copy32(hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin-hFdCngCom->startBand); /* This sets the new CNG levels until a SID update overwrites it */ + *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); - - /*stdec->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, st->hFdCngCom->stopFFTbin - st->hFdCngCom->startBand) / 2 * st->hFdCngCom->fftlen) / stdec->Mode2_L_frame);*/ - tmp_loop = sub(st->hFdCngCom->stopFFTbin , st->hFdCngCom->startBand); +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + st->cngTDLevel = (float)sqrt((sum_f(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / L_frame); +#else + /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ + tmp_loop = sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand); L_tmp = L_deposit_h(0); L_c = L_deposit_h(0); FOR(j = 0 ; j < tmp_loop; j++) @@ -664,19 +825,19 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma L_tmp = norm_llQ31(L_c,L_tmp,&L_tmp_exp); L_tmp_exp = sub(add(L_tmp_exp,*cngNoiseLevel_exp),1); - L_tmp = Mpy_32_16_1(L_tmp,st->hFdCngCom->fftlen); /*Q16*/ + L_tmp = Mpy_32_16_1(L_tmp,hFdCngCom->fftlen); /*Q16*/ - L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,stdec->L_frame_fx,95),1-15)]);/*Q16,exp -7*/ + L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame_fx,95),1-15)]);/*Q16,exp -7*/ L_tmp_exp = add(L_tmp_exp,-7); /*->Q16, L_tmp_exp */ L_tmp_exp = add(L_tmp_exp,31-16); /*->Q31, L_tmp_exp*/ - stdec->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); - stdec->cngTDLevel_e = L_tmp_exp; + st->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); + st->cngTDLevel_e = L_tmp_exp; move16(); - +#endif BREAK; } - st->hFdCngCom->inactive_frame_counter = add(st->hFdCngCom->inactive_frame_counter,1); + hFdCngCom->inactive_frame_counter = add(hFdCngCom->inactive_frame_counter,1); move16(); /************************************* @@ -684,56 +845,53 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma *************************************/ /* Detect first non-active frame */ - IF ( EQ_16(st->hFdCngCom->inactive_frame_counter,1)) + IF ( EQ_16(hFdCngCom->inactive_frame_counter,1)) { /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ bandcombinepow ( - st->bandNoiseShape, - st->bandNoiseShape_exp, + hFdCngDec->bandNoiseShape, + hFdCngDec->bandNoiseShape_exp, nBins, - st->hFdCngCom->part, - st->hFdCngCom->nFFTpart, - st->hFdCngCom->psize_inv, - st->partNoiseShape, - &st->partNoiseShape_exp + hFdCngCom->part, + hFdCngCom->nFFTpart, + hFdCngCom->psize_inv, + hFdCngDec->partNoiseShape, + &hFdCngDec->partNoiseShape_exp ); + IF (EQ_16(st->element_mode, IVAS_CPE_DFT)) + { +#ifdef IVAS_CODE_CNG + Copy(hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART); +#endif + } } - IF ( EQ_16(m_frame_type,SID_FRAME)) + IF ( EQ_16(st->m_frame_type,SID_FRAME)) { - IF ( LT_32(st->hFdCngCom->msFrCnt_init_counter,L_deposit_l(st->hFdCngCom->msFrCnt_init_thresh))) + IF ( LT_32(hFdCngCom->msFrCnt_init_counter,L_deposit_l(hFdCngCom->msFrCnt_init_thresh))) { /* At initialization, interpolate the bin/band-wise levels from the partition levels */ - scalebands ( - st->hFdCngCom->sidNoiseEst, - st->hFdCngCom->part, - st->hFdCngCom->npart, - st->hFdCngCom->midband, - st->hFdCngCom->nFFTpart, - sub(st->hFdCngCom->stopBand,st->hFdCngCom->startBand), - cngNoiseLevel, - 1 - ); - *cngNoiseLevel_exp = st->hFdCngCom->sidNoiseEstExp; + scalebands (hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, + hFdCngCom->nFFTpart, sub(hFdCngCom->stopBand,hFdCngCom->startBand), cngNoiseLevel,1 ); + *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } ELSE { + if (EQ_16(st->element_mode, IVAS_CPE_DFT)) + { +#ifdef IVAS_CODE_CNG + sidNoiseEst = hFdCngCom->sidNoiseEstLp; +#endif + move16(); + } /* Interpolate the CLDFB band levels from the SID (partition) levels */ - IF ( GT_16( st->hFdCngCom->regularStopBand, st->hFdCngCom->numCoreBands )) + IF ( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands )) { - scalebands ( - st->hFdCngCom->sidNoiseEst, - st->hFdCngCom->part, - st->hFdCngCom->npart, - st->hFdCngCom->midband, - st->hFdCngCom->nFFTpart, - sub(st->hFdCngCom->stopBand,st->hFdCngCom->startBand), - cngNoiseLevel, - 0 - ); - - *cngNoiseLevel_exp = st->hFdCngCom->sidNoiseEstExp; + scalebands ( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, + hFdCngCom->nFFTpart, sub(hFdCngCom->stopBand,hFdCngCom->startBand), cngNoiseLevel, 0); + + *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } @@ -742,26 +900,26 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); - FOR (k=0; k < st->hFdCngCom->nFFTpart ; k++) + FOR (k=0; k < hFdCngCom->nFFTpart ; k++) { - assert(st->partNoiseShape[k]>=0); + assert(hFdCngDec->partNoiseShape[k]>=0); /* add DELTA as it is done in FLC version, in order to avoid num > denom */ facTab[k] = 0; move16(); - IF ( st->partNoiseShape[k] != 0) + IF ( hFdCngDec->partNoiseShape[k] != 0) { - s1 = norm_l(st->hFdCngCom->sidNoiseEst[k]); - L_tmp = L_shl(st->hFdCngCom->sidNoiseEst[k], s1); - L_tmp_exp = sub(st->hFdCngCom->sidNoiseEstExp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(st->hFdCngCom->sidNoiseEst[k], st->hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); + s1 = norm_l(hFdCngCom->sidNoiseEst[k]); + L_tmp = L_shl(hFdCngCom->sidNoiseEst[k], s1); + L_tmp_exp = sub(hFdCngCom->sidNoiseEstExp, s1); + L_tmp = BASOP_Util_Add_Mant32Exp(hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); L_tmp = L_shr(L_tmp, 1); s = add(L_tmp_exp, 1); num = extract_h(L_tmp); - s1 = norm_l(st->partNoiseShape[k]); - L_tmp = L_shl(st->partNoiseShape[k], s1); - L_tmp_exp = sub(st->partNoiseShape_exp, s1); + s1 = norm_l(hFdCngDec->partNoiseShape[k]); + L_tmp = L_shl(hFdCngDec->partNoiseShape[k], s1); + L_tmp_exp = sub(hFdCngDec->partNoiseShape_exp, s1); L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); s = sub(s, L_tmp_exp); denom = extract_h(L_tmp); @@ -780,43 +938,52 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma s2 = s_max(s2,facTabExp[k]); } - FOR (k=0; k < st->hFdCngCom->nFFTpart; k++) + FOR (k=0; k < hFdCngCom->nFFTpart; k++) { s = sub(facTabExp[k],s2); s = s_max(s_min(s,WORD32_BITS-1),-(WORD32_BITS-1)); - FOR( ; j <= st->hFdCngCom->part[k]; j++) + FOR( ; j <= hFdCngCom->part[k]; j++) { - cngNoiseLevel[j] = L_shl(Mpy_32_16_1(st->bandNoiseShape[j],facTab[k]),s); + cngNoiseLevel[j] = L_shl(Mpy_32_16_1(hFdCngDec->bandNoiseShape[j],facTab[k]),s); move32(); } } /* adapt scaling for rest of the buffer */ - s = sub(*cngNoiseLevel_exp,add(st->bandNoiseShape_exp,s2)); - FOR ( ; k < st->hFdCngCom->npart; k++) + s = sub(*cngNoiseLevel_exp,add(hFdCngDec->bandNoiseShape_exp,s2)); + FOR ( ; k < hFdCngCom->npart; k++) { - FOR( ; j <= st->hFdCngCom->part[k]; j++) + FOR( ; j <= hFdCngCom->part[k]; j++) { cngNoiseLevel[j] = L_shl(cngNoiseLevel[j],s); move32(); } } - *cngNoiseLevel_exp = add(st->bandNoiseShape_exp,s2); + *cngNoiseLevel_exp = add(hFdCngDec->bandNoiseShape_exp,s2); move16(); } } - - - IF ( EQ_16(stdec->codec_mode, MODE2)) +#ifdef IVAS_CODE_CNG + else if (st->element_mode == IVAS_CPE_DFT) + { + if (!(hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh)) + { + sidNoiseEst = hFdCngCom->sidNoiseEstLp; + j = 0; + for (k = 0; k < hFdCngCom->nFFTpart; k++) + { + factor = (sidNoiseEst[k] + DELTA) / (hFdCngDec->partNoiseShape[k] + DELTA); + for (; j <= hFdCngCom->part[k]; j++) + { + cngNoiseLevel[j] = hFdCngDec->bandNoiseShape[j] * factor; + } + } + } + } +#endif + IF ( EQ_16(st->codec_mode, MODE2)) { /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec ( - cldfbBufferReal, - cldfbBufferImag, - cldfbBufferScale, - stdec, - &(stdec->Q_exc), - 2 - ); + generate_comfort_noise_dec (cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &(st->Q_exc), 2, -1); } BREAK; @@ -845,9 +1012,21 @@ Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time doma Returns: void */ -void perform_noise_estimation_dec (const Word16 *timeDomainInput, /* i: pointer to time domain input */ +void perform_noise_estimation_dec ( + const Word16 *timeDomainInput, /* i: pointer to time domain input */ Word16 Q, - HANDLE_FD_CNG_DEC st /* i/o: FD_CNG structure containing all buffers and variables */ +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + float* power_spectrum, +#endif + HANDLE_FD_CNG_DEC hFdCngDec /* i/o: FD_CNG structure containing all buffers and variables */ +#ifdef IVAS_CODE_CNG + ,const int16_t element_mode, /* i : element mode */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t L_frame, /* i : frame length at internal Fs */ + const int16_t last_L_frame, /* i : frame length of the last frame at internal Fs */ + const int32_t last_core_brate, /* i : previous frame core bitrate */ + const int16_t VAD /* i : VAD flag in the decoder */ +#endif ) { Word16 i, tmp_r, tmp_i, fac, fftBuffer_exp; @@ -856,40 +1035,309 @@ void perform_noise_estimation_dec (const Word16 *timeDomainInput, /* i: pointe Word16 *part, *psize_inv, *psize_norm; Word32 tmp, *fftBuffer, *periodog, *ptr_per, *ptr_r, *ptr_i; - +#ifdef IVAS_CODE_CNG + PMT("lots of code related to IVAS needs to be done ") +#endif /* pointer initialization */ - periodog = st->hFdCngCom->periodog; - fftBuffer = st->hFdCngCom->fftBuffer; + periodog = hFdCngDec->hFdCngCom->periodog; + fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; - part = st->part_shaping; - psize_inv = st->psize_inv_shaping; - psize_norm = st->psize_shaping_norm; + part = hFdCngDec->part_shaping; + psize_inv = hFdCngDec->psize_inv_shaping; + psize_norm = hFdCngDec->psize_shaping_norm; /* variable initialization */ - startBand = st->hFdCngCom->startBand; + startBand = hFdCngDec->hFdCngCom->startBand; move16(); - stopFFTbin = st->hFdCngCom->stopFFTbin; + stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin; move16(); - npart = st->npart_shaping; + npart = hFdCngDec->npart_shaping; move16(); - nFFTpart = st->nFFTpart_shaping; + nFFTpart = hFdCngDec->nFFTpart_shaping; move16(); /* Perform STFT analysis */ - AnalysisSTFT ( - timeDomainInput, - Q, - fftBuffer, - &fftBuffer_exp, - st->hFdCngCom - ); - +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + IF (!(EQ_16(element_mode, IVAS_CPE_MDCT) && power_spectrum != NULL)) + { + /* Perform STFT analysis */ + AnalysisSTFT(timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom); + } +#else + /* Perform STFT analysis */ + AnalysisSTFT (timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom); +#endif fftBuffer_exp = add(fftBuffer_exp,WORD16_BITS-1); +#ifdef IVAS_CODE_CNG + if (element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT) + { + /* Calculate periodogram (squared magnitude in each FFT bin) */ + if (startBand == 0) + { + (*ptr_per) = fftBuffer[0] * fftBuffer[0]; + ptr_per++; + ptr_r = fftBuffer + 2; + } + else + { + ptr_r = fftBuffer + 2 * startBand; + } + + ptr_i = ptr_r + 1; + + for (; ptr_per < periodog + stopFFTbin - startBand; ptr_per++) + { + (*ptr_per) = (*ptr_r) * (*ptr_r) + (*ptr_i) * (*ptr_i); + ptr_r += 2; + ptr_i += 2; + } + + /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ + v_multc(periodog, 4.f / (float)(hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen), periodog, stopFFTbin - startBand); + + /* Combine bins of power spectrum into partitions */ + i = 0; + for (p = 0; p < npart; p++) + { + + /* calculate mean over all bins in power partition */ + temp = 0; + for (; i <= part[p]; i++) + { + temp += periodog[i]; + } + msPeriodog[p] = temp * psize_inv[p]; + } + + /* compensate for the loss of variance - don't do when first noise update is not completed yet due to risk of msPeriodog[p] < 0 */ + if (hFdCngDec->first_cna_noise_updated) + { + i = 0; + for (p = 0; p < npart; p++) + { + /* calculate variance over all bins in power partition */ + temp = 0; + for (; i <= part[p]; i++) + { + delta = periodog[i] - msPeriodog[p]; + temp += delta * delta; + } + temp *= psize_inv[p]; + + /* compensate for the loss of variance */ + msPeriodog[p] = (float)(msPeriodog[p] + sqrt(temp) * rand_gauss(&ftemp, &hFdCngDec->cna_seed)); + + if (msPeriodog[p] < 1e-5f) + { + msPeriodog[p] = 1e-5f; + } + } + } + + /* calculate total energy (short-term and long-term) */ + enr_tot = sum_f(msPeriodog, npart) + EPSILON; + enr_tot0 = sum_f(msNoiseEst, npart) + EPSILON; + + /* update short-term periodogram on larger partitions */ + for (p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++) + { + if (L_frame != last_L_frame || last_core_brate <= SID_2k40) + { + /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */ + hFdCngDec->msPeriodog_ST[p] = msPeriodog[p]; + } + else + { + hFdCngDec->msPeriodog_ST[p] = (float)(ST_PERIODOG_FACT * hFdCngDec->msPeriodog_ST[p] + (1 - ST_PERIODOG_FACT) * msPeriodog[p]); + } + } + + /* core Fs has changed -> partitions have changed -> re-calculate long-term periodogram */ + /* part L_FRAME16k L_FRAME */ + /* ... */ + /* [55] 146 146 */ + /* [56] 174 160 */ + /* [57] 210 174 */ + /* [58] 254 190 */ + /* [59] 306 210 */ + /* [60] 317 230 */ + /* [61] 253 */ + + if (last_L_frame == L_FRAME16k && L_frame == L_FRAME) + { + msNoiseEst[61] = msNoiseEst[58]; + msNoiseEst[60] = min(msNoiseEst[58], msNoiseEst[57]); + msNoiseEst[59] = msNoiseEst[57]; + msNoiseEst[58] = msNoiseEst[56]; + msNoiseEst[57] = msNoiseEst[56]; + msNoiseEst[56] = min(msNoiseEst[56], msNoiseEst[55]); + } + else if (last_L_frame == L_FRAME && L_frame == L_FRAME16k) + { + msNoiseEst[56] = min(msNoiseEst[56], msNoiseEst[57]); + msNoiseEst[57] = min(msNoiseEst[58], msNoiseEst[59]); + msNoiseEst[58] = min(msNoiseEst[60], msNoiseEst[61]); + msNoiseEst[59] = 0.0f; + msNoiseEst[60] = 0.0f; + msNoiseEst[61] = 0.0f; + + hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; + } + + /* Smooth with IIR filter */ + if (!hFdCngDec->first_cna_noise_updated) + { + if (!VAD) + { + /* background noise update with moving average */ + alpha = 1.0f / (hFdCngDec->first_cna_noise_update_cnt + 1); + for (p = 0; p < npart; p++) + { + msNoiseEst[p] = (1 - alpha) * msNoiseEst[p] + alpha * msPeriodog[p]; + } + + /* check, if we reached the required number of first CNA noise update frames */ + if (hFdCngDec->first_cna_noise_update_cnt < FIRST_CNA_NOISE_UPD_FRAMES - 1) + { + hFdCngDec->first_cna_noise_update_cnt++; + } + else + { + hFdCngDec->first_cna_noise_updated = 1; + if (hFdCngDec->hFdCngCom->msFrCnt_init_counter == 0) + { + hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1; + } + } + } + else + { + hFdCngDec->first_cna_noise_update_cnt = 0; + } + } + else + { + hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1; + if (VAD) + { + /* no updates during active frames except for significant energy drops */ + enr_ratio = enr_tot / enr_tot0; + if (enr_ratio < 0.5f) + { + /* total energy significantly decreases during active frames -> downward update */ + wght = lin_interp(enr_ratio, 0.0f, 0.8f, 0.5f, 0.95f, 1); + for (p = 0; p < npart; p++) + { + if (msPeriodog[p] < msNoiseEst[p]) + { + msNoiseEst[p] = wght * msNoiseEst[p] + (1 - wght) * msPeriodog[p]; + } + } + } + else + { + /* energy significantly decreases in one of the larger partitions during active frames -> downward update */ + for (p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++) + { + if (hFdCngDec->msPeriodog_ST[p] < msNoiseEst[p]) + { + msNoiseEst[p] = (float)(CNA_ACT_DN_FACT * msNoiseEst[p] + (1 - CNA_ACT_DN_FACT) * hFdCngDec->msPeriodog_ST[p]); + } + } + } + } + else + { + if (bwidth >= WB && hFdCngDec->ms_last_inactive_bwidth == NB) + { + /* bandwidth increased -> set counter for fast initilization */ + hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; + } + hFdCngDec->ms_last_inactive_bwidth = bwidth; + /* update background noise during inactive frames */ + ptr_per = msNoiseEst; + for (p = 0; p < npart; p++) + { + enr = msPeriodog[p]; + alpha = 0.95f; + /* bandwidth increased -> do fast re-initilization */ + if (hFdCngDec->ms_cnt_bw_up > 0 && p > 55) + { + alpha = 1.0f / (hFdCngDec->ms_cnt_bw_up + 1); + } + else if (enr < *ptr_per && part[p] == 1) + { + /* faster downward update for single-bin partitions */ + alpha = 0.8f; + } + else if (enr > 2.0f * (*ptr_per)) + { + /* prevent abrupt upward updates */ + enr = 2.0f * (*ptr_per); + } + + /* IIR smoothing */ + *ptr_per *= alpha; + *ptr_per += (1 - alpha) * enr; + ptr_per++; + } + + if (hFdCngDec->ms_cnt_bw_up > 0) + { + hFdCngDec->ms_cnt_bw_up--; + } + } + } + + mvr2r(msNoiseEst, hFdCngDec->msPsd, npart); + + /* Expand partitions into bins of power spectrum */ + scalebands(msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, stopFFTbin - startBand, hFdCngDec->bandNoiseShape, 1); + + mvr2r(hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd[startBand], stopFFTbin - startBand); + set_zero(&hFdCngDec->smoothed_psd[stopFFTbin], L_FRAME16k - stopFFTbin); + } + else +#endif + { +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + if (element_mode == IVAS_CPE_MDCT && power_spectrum != NULL) + { + /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ + periodog = power_spectrum; + } + else + { + /* Compute the squared magnitude in each FFT bin */ + if (startBand == 0) + { + (*ptr_per) = fftBuffer[0] * fftBuffer[0]; /* DC component */ + ptr_per++; + ptr_r = fftBuffer + 2; + } + else + { + ptr_r = fftBuffer + 2 * startBand; + } + + ptr_i = ptr_r + 1; + + for (; ptr_per < periodog + stopFFTbin - startBand; ptr_per++) + { + (*ptr_per) = (*ptr_r) * (*ptr_r) + (*ptr_i) * (*ptr_i); + ptr_r += 2; + ptr_i += 2; + } + /* Nyquist frequency is discarded */ + /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ + v_multc(periodog, 4.f / (float)(hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen), periodog, stopFFTbin - startBand); + } +#else assert(startBand != 0); len = sub(stopFFTbin, startBand); @@ -929,30 +1377,30 @@ void perform_noise_estimation_dec (const Word16 *timeDomainInput, /* i: pointe ptr_per++; } - st->hFdCngCom->periodog_exp = shl(sub(fftBuffer_exp,s),1); + hFdCngDec->hFdCngCom->periodog_exp = shl(sub(fftBuffer_exp, s), 1); /* Rescale */ - assert( (st->hFdCngCom->fftlen == 640) || (st->hFdCngCom->fftlen == 512) || (st->hFdCngCom->fftlen == 320) ); + assert((hFdCngDec->hFdCngCom->fftlen == 640) || (hFdCngDec->hFdCngCom->fftlen == 512) || (hFdCngDec->hFdCngCom->fftlen == 320)); fac = 20972/*0.64 Q15*/; move16(); - if( EQ_16(st->hFdCngCom->fftlen,512)) + if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 512)) { fac = 16384/*0.5 Q15*/; move16(); } - if ( EQ_16(st->hFdCngCom->fftlen,640)) + if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 640)) { s = 18; move16(); } - if ( EQ_16(st->hFdCngCom->fftlen,512)) + if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 512)) { s = 17; move16(); } - if ( EQ_16(st->hFdCngCom->fftlen,320)) + if (EQ_16(hFdCngDec->hFdCngCom->fftlen, 320)) { s = 16; move16(); @@ -961,52 +1409,55 @@ void perform_noise_estimation_dec (const Word16 *timeDomainInput, /* i: pointe len = sub(stopFFTbin, startBand); FOR (i=0; i < len; i++) { - st->hFdCngCom->periodog[i] = Mpy_32_16_1(st->hFdCngCom->periodog[i],fac); + hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1(hFdCngDec->hFdCngCom->periodog[i], fac); } - st->hFdCngCom->periodog_exp = add(st->hFdCngCom->periodog_exp,sub(2,s)); - + hFdCngDec->hFdCngCom->periodog_exp = add(hFdCngDec->hFdCngCom->periodog_exp, sub(2, s)); +#endif /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */ - bandcombinepow(periodog, st->hFdCngCom->periodog_exp, sub(stopFFTbin,startBand), part, npart, psize_inv, st->msPeriodog, &st->msPeriodog_exp); + bandcombinepow(periodog, hFdCngDec->hFdCngCom->periodog_exp, sub(stopFFTbin, startBand), part, npart, psize_inv, hFdCngDec->msPeriodog, &hFdCngDec->msPeriodog_exp); - st->msPeriodog_exp_fft = st->msPeriodog_exp; + hFdCngDec->msPeriodog_exp_fft = hFdCngDec->msPeriodog_exp; move16(); - st->msPeriodog_exp_cldfb = st->msPeriodog_exp; + hFdCngDec->msPeriodog_exp_cldfb = hFdCngDec->msPeriodog_exp; move16(); /* Compress MS inputs */ - compress_range(st->msPeriodog, st->msPeriodog_exp, st->msLogPeriodog, npart); + compress_range(hFdCngDec->msPeriodog, hFdCngDec->msPeriodog_exp, hFdCngDec->msLogPeriodog, npart); /* Call the minimum statistics routine for noise estimation */ minimum_statistics ( npart, nFFTpart, psize_norm, - st->msLogPeriodog, - st->msNoiseFloor, - st->msLogNoiseEst, - st->msAlpha, - st->msPsd, - st->msPsdFirstMoment, - st->msPsdSecondMoment, - st->msMinBuf, - st->msBminWin, - st->msBminSubWin, - st->msCurrentMin, - st->msCurrentMinOut, - st->msCurrentMinSubWindow, - st->msLocalMinFlag, - st->msNewMinFlag, - st->msPeriodogBuf, - &(st->msPeriodogBufPtr), - st->hFdCngCom + hFdCngDec->msLogPeriodog, + hFdCngDec->msNoiseFloor, + hFdCngDec->msLogNoiseEst, + hFdCngDec->msAlpha, + hFdCngDec->msPsd, + hFdCngDec->msPsdFirstMoment, + hFdCngDec->msPsdSecondMoment, + hFdCngDec->msMinBuf, + hFdCngDec->msBminWin, + hFdCngDec->msBminSubWin, + hFdCngDec->msCurrentMin, + hFdCngDec->msCurrentMinOut, + hFdCngDec->msCurrentMinSubWindow, + hFdCngDec->msLocalMinFlag, + hFdCngDec->msNewMinFlag, + hFdCngDec->msPeriodogBuf, + &(hFdCngDec->msPeriodogBufPtr), + hFdCngDec->hFdCngCom +#ifdef IVAS_CODE_CNG + , DEC, element_mode +#endif ); /* Expand MS outputs */ - expand_range(st->msLogNoiseEst, st->msNoiseEst, &st->msNoiseEst_exp, npart); - + expand_range(hFdCngDec->msLogNoiseEst, hFdCngDec->msNoiseEst, &hFdCngDec->msNoiseEst_exp, npart); +} } @@ -1133,7 +1584,7 @@ void FdCng_decodeSID (HANDLE_FD_CNG_COM st, Decoder_State_fx *corest) move16(); - lpc_from_spectrum (st->cngNoiseLevel, st->cngNoiseLevelExp, st->startBand, st->stopFFTbin, st->fftlen, st->A_cng, M, preemph_fac); + lpc_from_spectrum (st, st->startBand, st->stopFFTbin, preemph_fac); } @@ -1159,19 +1610,12 @@ void FdCng_decodeSID (HANDLE_FD_CNG_COM st, Decoder_State_fx *corest) void */ -void noisy_speech_detection (const Word16 vad, - const Word16 *ftimeInPtr, /* i : input time-domain frame */ - const Word16 frameSize, /* i : frame size */ - const Word16 Q, - const Word32 *msNoiseEst, /* i : noise estimate over all critical bands */ - const Word16 msNoiseEst_exp, /* i : exponent for noise estimate over all critical bands */ - const Word16 *psize_norm, - const Word16 psize_norm_exp, - const Word16 nFFTpart, /* i : Number of partitions taken into account */ - Word32 *lp_noise, /* i/o: pointer to long term total Noise energy average */ - Word32 *lp_speech, /* i/o: pointer to long term active speech energy average */ - Word16 *flag_noisy_speech - ) +void noisy_speech_detection ( + HANDLE_FD_CNG_DEC hFdCngDec,/* i/o: FD_CNG structure */ + const Word16 vad, + const Word16 * syn, /* i : input time-domain frame */ + const Word16 Q +) { Word16 i; Word32 tmp; @@ -1187,7 +1631,7 @@ void noisy_speech_detection (const Word16 vad, IF ( vad == 0 ) { - totalNoise = dotWord32_16_Mant32Exp(msNoiseEst, msNoiseEst_exp, psize_norm, psize_norm_exp, nFFTpart, &totalNoise_exp); + totalNoise = dotWord32_16_Mant32Exp(hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, &totalNoise_exp); /* - logTotalNoise is scaled by LD_DATA_SCALE+2 @@ -1206,16 +1650,16 @@ void noisy_speech_detection (const Word16 vad, logTotalNoise = Mpy_32_16_1(L_add(logTotalNoise,logTotalNoiseExp),24660/*0.75257498916 Q15*/); } - *lp_noise = L_add(Mpy_32_16_1(*lp_noise,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logTotalNoise,20972/*0.64 Q15*/),7)); + hFdCngDec->lp_noise = L_add(Mpy_32_16_1(hFdCngDec->lp_noise,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logTotalNoise,20972/*0.64 Q15*/),7)); move32(); } ELSE { Etot = 0; Etot_exp = 31; - FOR( i = 0; i < frameSize ; i++ ) + FOR( i = 0; i < hFdCngDec->hFdCngCom->frameSize; i++ ) { - tmp = L_shr_r( L_mult0( ftimeInPtr[i], ftimeInPtr[i] ), sub( Etot_exp, 31 ) ); + tmp = L_shr_r( L_mult0(syn[i], syn[i] ), sub( Etot_exp, 31 ) ); IF( L_sub( maxWord32, tmp ) < Etot ) { Etot_exp = add( Etot_exp, 1 ); @@ -1241,7 +1685,7 @@ void noisy_speech_detection (const Word16 vad, logEtot = BASOP_Util_Log2(Etot); logEtotExp = L_shl(L_deposit_l(Etot_exp),WORD32_BITS-1-LD_DATA_SCALE); logEtot = Mpy_32_16_1(L_add(logEtot,logEtotExp),24660/*0.75257498916 Q15*/); - IF ( EQ_16( frameSize, L_FRAME16k )) + IF ( EQ_16( hFdCngDec->hFdCngCom->frameSize, L_FRAME16k )) { logEtot = L_add( logEtot, -184894985l/*-0.086098436822497 Q31*/ ); } @@ -1251,23 +1695,23 @@ void noisy_speech_detection (const Word16 vad, } } - *lp_speech = L_add(Mpy_32_16_1(*lp_speech,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logEtot,20972/*0.64 Q15*/),7)); + hFdCngDec->lp_speech = L_add(Mpy_32_16_1(hFdCngDec->lp_speech,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logEtot,20972/*0.64 Q15*/),7)); move32(); } - tmp = L_sub(*lp_speech,377487360l/*45.0 Q23*/); + tmp = L_sub(hFdCngDec->lp_speech,377487360l/*45.0 Q23*/); - if ( LT_32(*lp_noise,tmp)) + if ( LT_32(hFdCngDec->lp_noise,tmp)) { - *lp_noise = tmp; + hFdCngDec->lp_noise = tmp; move32(); } - *flag_noisy_speech = 0; + hFdCngDec->hFdCngCom->flag_noisy_speech = 0; move16(); - if ( LT_32(L_sub(*lp_speech,*lp_noise),234881024l/*28.0 Q23*/)) + if ( LT_32(L_sub(hFdCngDec->lp_speech, hFdCngDec->lp_noise),234881024l/*28.0 Q23*/)) { - *flag_noisy_speech = 1; + hFdCngDec->hFdCngCom->flag_noisy_speech = 1; move16(); } @@ -1277,13 +1721,15 @@ void noisy_speech_detection (const Word16 vad, void -generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State_fx *stdec, - Word16 *Q_new, - Word16 gen_exc - ) +generate_comfort_noise_dec ( + Word32 **bufferReal, /* o : matrix to real part of input bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ + Decoder_State_fx *st, + Word16 *Q_new, + Word16 gen_exc, + const Word16 nchan_out /* i : number of output channels */ +) { Word16 i, j, s, sc, sn, cnt; Word16 startBand2; @@ -1302,25 +1748,27 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real Word32 *fftBuffer; Word16 old_syn_pe_tmp[16]; Word16 tcx_transition = 0; - HANDLE_FD_CNG_DEC std = stdec->hFdCngDec_fx; - HANDLE_FD_CNG_COM st = std->hFdCngCom; - + HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec_fx; + HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; + TCX_DEC_HANDLE hTcxDec; + hTcxDec = st->hTcxDec; /* Warning fix */ s = 0; +PMTE(); /*IVAS CODE need to be added */ /* pointer initialization */ - cngNoiseLevel = st->cngNoiseLevel; - cngNoiseLevelExp = st->cngNoiseLevelExp; + cngNoiseLevel = hFdCngCom->cngNoiseLevel; + cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; ptr_level = cngNoiseLevel; - seed = &(st->seed); - fftBuffer = st->fftBuffer; - timeDomainOutput = st->timeDomainBuffer; + seed = &(hFdCngCom->seed); + fftBuffer = hFdCngCom->fftBuffer; + timeDomainOutput = hFdCngCom->timeDomainBuffer; /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult(st->invScalingFactor,CLDFB_SCALING); + scaleCLDFB = mult(hFdCngCom->invScalingFactor,CLDFB_SCALING); /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -1338,8 +1786,8 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real randGaussExp = CNG_RAND_GAUSS_SHIFT; move16(); - cnt = sub(st->stopFFTbin, st->startBand); - IF ( st->startBand == 0 ) + cnt = sub(hFdCngCom->stopFFTbin, hFdCngCom->startBand); + IF ( hFdCngCom->startBand == 0 ) { /* DC component in FFT */ s = 0; @@ -1358,7 +1806,7 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real } ELSE { - startBand2 = shl(st->startBand,1); + startBand2 = shl(hFdCngCom->startBand,1); set32_fx(fftBuffer, 0, startBand2); ptr_r = fftBuffer + startBand2; } @@ -1385,18 +1833,18 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real } /* Remaining FFT bins are set to zero */ - stopFFTbin2 = shl(st->stopFFTbin,1); - set32_fx(fftBuffer+stopFFTbin2, 0, sub(st->fftlen,stopFFTbin2)); + stopFFTbin2 = shl(hFdCngCom->stopFFTbin,1); + set32_fx(fftBuffer+stopFFTbin2, 0, sub(hFdCngCom->fftlen,stopFFTbin2)); fftBufferExp = add(shr(cngNoiseLevelExp,1),randGaussExp); /* If previous frame is active, reset the overlap-add buffer */ - IF ( st->frame_type_previous == ACTIVE_FRAME ) + IF ( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) { - set16_fx(st->olapBufferSynth, 0, st->fftlen); + set16_fx(hFdCngCom->olapBufferSynth, 0, hFdCngCom->fftlen); test(); test(); - if ( ( stdec->last_core_bfi > ACELP_CORE && stdec->codec_mode == MODE2 ) || stdec->codec_mode == MODE1 ) + if ( ( st->last_core_bfi > ACELP_CORE && st->codec_mode == MODE2 ) || st->codec_mode == MODE1 ) { tcx_transition = 1; move16(); @@ -1404,9 +1852,8 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real } /* Perform STFT synthesis */ - SynthesisSTFT (fftBuffer, fftBufferExp, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, - tcx_transition, - st, gen_exc, Q_new); + SynthesisSTFT (fftBuffer, fftBufferExp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, + tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out); { Word32 Lener, att; @@ -1414,27 +1861,27 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real /* update CNG excitation energy for LP_CNG */ /* calculate the residual signal energy */ - /*enr = dotp( st->exc_cng, st->exc_cng, st->frameSize ) / st->frameSize;*/ - Lener = Dot_productSq16HQ(1,st->exc_cng,stdec->L_frame_fx,&exp); + /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ + Lener = Dot_productSq16HQ(1,hFdCngCom->exc_cng,st->L_frame_fx,&exp); exp = add(sub(shl(sub(15,*Q_new),1),8),exp); /*8 = log2(256)*/ /* convert log2 of residual signal energy */ /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ Lener = BASOP_Util_Log2(Lener); Lener = L_add(Lener,L_shl(L_deposit_l(exp),WORD32_BITS-1-LD_DATA_SCALE)); /*Q25*/ - if(stdec->L_frame_fx == L_FRAME16k) + if(st->L_frame_fx == L_FRAME16k) { Lener = L_sub(Lener, 10802114l/*0.3219280949f Q25*/); /*log2(320) = 8.3219280949f*/ } /* decrease the energy in case of WB input */ - IF( NE_16(stdec->bwidth_fx, NB)) + IF( NE_16(st->bwidth_fx, NB)) { - IF( EQ_16(stdec->bwidth_fx,WB)) + IF( EQ_16(st->bwidth_fx,WB)) { - IF( stdec->CNG_mode_fx >= 0 ) + IF( st->CNG_mode_fx >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl(L_deposit_l(ENR_ATT_fx[stdec->CNG_mode_fx]),17); + att = L_shl(L_deposit_l(ENR_ATT_fx[st->CNG_mode_fx]),17); } ELSE { @@ -1449,12 +1896,12 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real } Lener = L_sub(Lener, att ); } - /*stdec->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ + /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ Lener = BASOP_util_Pow2(Lener, 6, &exp); Lener = Mult_32_16(Lener, 6554/*0.2f Q15*/); exp = sub(25,exp); Lener = L_shr(Lener, exp); /*Q6*/ - stdec->lp_ener_fx = L_add(Mult_32_16(stdec->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ + st->lp_ener_fx = L_add(Mult_32_16(st->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ } /* @@ -1462,7 +1909,7 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each band */ test(); - IF ( bufferReal!=NULL && (LT_16(st->numCoreBands,st->regularStopBand))) + IF ( bufferReal!=NULL && (LT_16(hFdCngCom->numCoreBands,hFdCngCom->regularStopBand))) { sn = sub(sn,1); @@ -1470,14 +1917,14 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real move16(); assert( ((cngNoiseLevelExp+CLDFBinvScalingFactor_EXP+1-1)&1) == 0); - FOR (j=st->numCoreBands; jregularStopBand; j++) + FOR (j=hFdCngCom->numCoreBands; jregularStopBand; j++) { /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); sqrtNoiseLevel = Sqrt32(L_shr(Mpy_32_16_1(*ptr_level,scaleCLDFB),sn), &s); - FOR (i=0; inumSlots; i++) + FOR (i=0; inumSlots; i++) { /* Real part in CLDFB band */ bufferReal[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); @@ -1497,7 +1944,7 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real /* Overlap-add when previous frame is active */ test(); - IF ( st->frame_type_previous == ACTIVE_FRAME && stdec->codec_mode == MODE2 ) + IF ( hFdCngCom->frame_type_previous == ACTIVE_FRAME && st->codec_mode == MODE2 ) { Word32 old_exc_ener, gain, noise32; Word16 seed_loc, lpcorder, old_syn, tmp, gain16, N, N2, N4, N8; @@ -1509,68 +1956,42 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real Word16 Q_exc, Q_syn; - assert(st->frameSize <= 640); + assert(hFdCngCom->frameSize <= 640); - seed_loc = st->seed; + seed_loc = hFdCngCom->seed; move16(); - N = st->frameSize; + N = hFdCngCom->frameSize; move16(); - N2 = shr(st->frameSize,1); + N2 = shr(hFdCngCom->frameSize,1); - IF ( stdec->last_core_bfi > ACELP_CORE ) + IF ( st->last_core_bfi > ACELP_CORE ) { Word16 left_overlap_mode; - left_overlap_mode = stdec->tcx_cfg.tcx_last_overlap_mode; + left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; move16(); if (EQ_16(left_overlap_mode, ALDO_WINDOW)) { left_overlap_mode = FULL_OVERLAP; move16(); } + tcx_windowing_synthesis_current_frame( timeDomainOutput,st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half,st->hTcxCfg->tcx_mdct_window_minimum,st->hTcxCfg->tcx_mdct_window_length,st->hTcxCfg->tcx_mdct_window_half_length, + st->hTcxCfg->tcx_mdct_window_min_length,0,left_overlap_mode,NULL,NULL,NULL,NULL,NULL,N/2,shr(sub(abs_s(st->hTcxCfg->tcx_offset), st->hTcxCfg->tcx_offset), 1), 1,0,0); - tcx_windowing_synthesis_current_frame( timeDomainOutput, - stdec->tcx_cfg.tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ - stdec->tcx_cfg.tcx_mdct_window_half, - stdec->tcx_cfg.tcx_mdct_window_minimum, - stdec->tcx_cfg.tcx_mdct_window_length, - stdec->tcx_cfg.tcx_mdct_window_half_length, - stdec->tcx_cfg.tcx_mdct_window_min_length, - 0, - left_overlap_mode, - NULL, - NULL, - NULL, - NULL, - NULL, - N/2, - shr(sub(abs_s(stdec->tcx_cfg.tcx_offset), stdec->tcx_cfg.tcx_offset), 1), /* equivalent to: stdec->tcx_cfg.tcx_offset<0?-stdec->tcx_cfg.tcx_offset:0 */ - 1, - 0, - 0 - ); - - IF (stdec->tcx_cfg.last_aldo != 0) + IF (st->hTcxCfg->last_aldo != 0) { - FOR (i=0; iframeSize,NS2SA(stdec->sr_core, N_ZERO_MDCT_NS)); i++) + FOR (i=0; iframeSize,NS2SA(st->sr_core, N_ZERO_MDCT_NS)); i++) { - timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(stdec->old_out_LB_fx[i+NS2SA(stdec->sr_core, N_ZERO_MDCT_NS)],stdec->Q_old_wtda_LB)); + timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(st->hHQ_core->old_out_LB_fx[i+NS2SA(st->sr_core, N_ZERO_MDCT_NS)],st->hHQ_core->Q_old_wtda_LB)); } } ELSE { - tcx_windowing_synthesis_past_frame( stdec->syn_Overl, - stdec->tcx_cfg.tcx_mdct_window, - stdec->tcx_cfg.tcx_mdct_window_half, - stdec->tcx_cfg.tcx_mdct_window_minimum, - stdec->tcx_cfg.tcx_mdct_window_length, - stdec->tcx_cfg.tcx_mdct_window_half_length, - stdec->tcx_cfg.tcx_mdct_window_min_length, - stdec->tcx_cfg.tcx_last_overlap_mode - ); - - FOR (i=0; itcx_cfg.tcx_mdct_window_length; i++) + tcx_windowing_synthesis_past_frame(hTcxDec->syn_Overl,st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, + st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->hTcxCfg->tcx_last_overlap_mode); + + FOR (i=0; ihTcxCfg->tcx_mdct_window_length; i++) { - timeDomainOutput[i] += shl(stdec->syn_Overl[i],TCX_IMDCT_HEADROOM); + timeDomainOutput[i] += shl(hTcxDec->syn_Overl[i],TCX_IMDCT_HEADROOM); } } } @@ -1591,16 +2012,16 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real lpcorder = M; move16(); - old_Aq = stdec->old_Aq_12_8_fx; - old_exc = stdec->old_exc_fx+sub(L_EXC_MEM_DEC,N2); - old_syn_pe = stdec->mem_syn2_fx; - old_syn = stdec->syn[lpcorder]; + old_Aq = st->old_Aq_12_8_fx; + old_exc = st->old_exc_fx+sub(L_EXC_MEM_DEC,N2); + old_syn_pe = st->mem_syn2_fx; + old_syn = st->syn[lpcorder]; move16(); - preemph_fac = stdec->preemph_fac; + preemph_fac = st->preemph_fac; move16(); - Q_exc = stdec->Q_exc; + Q_exc = st->Q_exc; move16(); - Q_syn = stdec->Q_syn; + Q_syn = st->Q_syn; move16(); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -1694,10 +2115,10 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real FOR (i=0; iolapWinSyn[i].v.re); + tmp = mult(noise[i],hFdCngCom->olapWinSyn[i].v.re); timeDomainOutput[i] = add(timeDomainOutput[i],tmp); move16(); - tmp = mult(noise[i+N4],st->olapWinSyn[N4-1-i].v.im); + tmp = mult(noise[i+N4],hFdCngCom->olapWinSyn[N4-1-i].v.im); timeDomainOutput[i+N4] = add(timeDomainOutput[i+N4],tmp); move16(); } @@ -1708,10 +2129,11 @@ generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real void -generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to real part of input bands */ +generate_comfort_noise_dec_hf ( + Word32 **bufferReal, /* o : matrix to real part of input bands */ Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State_fx *stdec + Decoder_State_fx *st ) { Word16 i, j, s, sc, sn; @@ -1722,15 +2144,15 @@ generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to r Word16 *seed; Word32 *cngNoiseLevel; Word32 *ptr_level; - HANDLE_FD_CNG_COM st = stdec->hFdCngDec_fx->hFdCngCom; + HANDLE_FD_CNG_COM hFdCngCom = st->hFdCngDec_fx->hFdCngCom; - cngNoiseLevel = st->cngNoiseLevel+st->stopFFTbin-st->startBand; - cngNoiseLevelExp = st->cngNoiseLevelExp; + cngNoiseLevel = hFdCngCom->cngNoiseLevel+hFdCngCom->stopFFTbin-hFdCngCom->startBand; + cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; ptr_level = cngNoiseLevel; - seed = &(st->seed); + seed = &(hFdCngCom->seed); /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult(st->invScalingFactor,CLDFB_SCALING); + scaleCLDFB = mult(hFdCngCom->invScalingFactor,CLDFB_SCALING); sn = 0; move16(); @@ -1744,21 +2166,21 @@ generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to r randGaussExp = CNG_RAND_GAUSS_SHIFT; move16(); - IF ( LT_16(st->numCoreBands,st->regularStopBand)) + IF ( LT_16(hFdCngCom->numCoreBands,hFdCngCom->regularStopBand)) { sc = add(shr(add(cngNoiseLevelExp,CLDFBinvScalingFactor_EXP+1-1),1),randGaussExp); move16(); assert( ((cngNoiseLevelExp+CLDFBinvScalingFactor_EXP+1-1)&1) == 0); - FOR (j=st->numCoreBands; jregularStopBand; j++) + FOR (j=hFdCngCom->numCoreBands; jregularStopBand; j++) { /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ s = 0; move16(); sqrtNoiseLevel = Sqrt32(L_shr(Mpy_32_16_1(*ptr_level,scaleCLDFB),sn), &s); - FOR (i=0; inumSlots; i++) + FOR (i=0; inumSlots; i++) { /* Real part in CLDFB band */ bufferReal[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); @@ -1794,9 +2216,10 @@ generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to r void */ -void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time domain output buffer 15Q0 */ +void generate_masking_noise ( + Word16 *timeDomainBuffer, /* i/o : pointer to time domain output buffer 15Q0 */ Word16 Q, - HANDLE_FD_CNG_COM st /* i/o : pointer to FD_CNG_COM structure */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ ,Word16 length ,Word16 core ) @@ -1810,15 +2233,15 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time Word32 *fftBuffer; Word16 *seed; - + PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = st->cngNoiseLevel; - fftBuffer = st->fftBuffer; - seed = &(st->seed); + cngNoiseLevel = hFdCngCom->cngNoiseLevel; + fftBuffer = hFdCngCom->fftBuffer; + seed = &(hFdCngCom->seed); /* Compute additional CN level */ - cngNoiseLevelExp = st->cngNoiseLevelExp; + cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); IF(core!=AMR_WB_CORE) @@ -1833,9 +2256,9 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time { test(); test(); - IF ( ( EQ_16(st->CngBandwidth,scaleTable_cn_only[i].bwmode)) - && (GE_32(st->CngBitrate,scaleTable_cn_only[i].bitrateFrom) ) - && ( LT_32(st->CngBitrate,scaleTable_cn_only[i].bitrateTo) )) + IF ( ( EQ_16(hFdCngCom->CngBandwidth,scaleTable_cn_only[i].bwmode)) + && (GE_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateFrom) ) + && ( LT_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateTo) )) { scale = scaleTable_cn_only[i].scale; @@ -1855,7 +2278,7 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time move16(); FOR (i=0; i < scaleTableSize; i++) { - IF ( GE_32(st->CngBitrate,scaleTable_cn_only_amrwbio[i][0])) + IF ( GE_32(hFdCngCom->CngBitrate,scaleTable_cn_only_amrwbio[i][0])) { scale = scaleTable_cn_only_amrwbio[i][1]; move16(); @@ -1867,11 +2290,11 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time /* Exclude clean speech */ s1 = norm_s(scale); - s2 = norm_s(st->likelihood_noisy_speech); + s2 = norm_s(hFdCngCom->likelihood_noisy_speech); /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub(1,add(s1,s2)); - scale = mult_r(shl(scale,s1),shl(st->likelihood_noisy_speech,s2)); + scale = mult_r(shl(scale,s1),shl(hFdCngCom->likelihood_noisy_speech,s2)); { /* add exponent of scale and cngNoiseLevel */ @@ -1887,12 +2310,12 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time /* consider scaling of random noise */ fftBufferExp = add(fftBufferExp,CNG_RAND_GAUSS_SHIFT); - cnt = sub(st->stopFFTbin,st->startBand); + cnt = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ - IF ( st->startBand == 0 ) + IF ( hFdCngCom->startBand == 0 ) { /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ @@ -1901,21 +2324,21 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time /* -s => consider scalefactor adaptation for sqrt calculation */ sq = sub(0,s); sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); - st->fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); + hFdCngCom->fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); move32(); - st->fftBuffer[1] = 0; + hFdCngCom->fftBuffer[1] = 0; move32(); - fftBuffer = st->fftBuffer + 2; + fftBuffer = hFdCngCom->fftBuffer + 2; cngNoiseLevel++; cnt = sub(cnt,1); } ELSE { - startBand2 = shl(st->startBand,1); - set32_fx(st->fftBuffer,0,startBand2); - fftBuffer = st->fftBuffer + startBand2; + startBand2 = shl(hFdCngCom->startBand,1); + set32_fx(hFdCngCom->fftBuffer,0,startBand2); + fftBuffer = hFdCngCom->fftBuffer + startBand2; } FOR (i=0; istopFFTbin,1); - set32_fx(st->fftBuffer+stopFFTbin2, 0, sub(st->fftlen,stopFFTbin2)); + stopFFTbin2 = shl(hFdCngCom->stopFFTbin,1); + set32_fx(hFdCngCom->fftBuffer+stopFFTbin2, 0, sub(hFdCngCom->fftlen,stopFFTbin2)); /* perform STFT synthesis */ - assert(st->olapBufferSynth2 != NULL); - SynthesisSTFT(st->fftBuffer, fftBufferExp, maskingNoise, st->olapBufferSynth2, st->olapWinSyn, - 0, - st, 0, NULL); + assert(hFdCngCom->olapBufferSynth2 != NULL); + SynthesisSTFT(hFdCngCom->fftBuffer, fftBufferExp, maskingNoise, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, + 0, hFdCngCom, 0, NULL, -1/*st->element_mode*/, -1/*nchan_out*/); + PMT("parameters need update") /* add some comfort noise on top of decoded signal */ - IF ( st->frameSize > length ) + IF ( hFdCngCom->frameSize > length ) { FOR (i=0; iframeSize; i++) + FOR (i=0; iframeSize; i++) { timeDomainBuffer[i] = add(timeDomainBuffer[i],shr_r(maskingNoise[i],-Q)); move16(); @@ -1982,18 +2405,18 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time *-------------------------------------------------------------------*/ void generate_masking_noise_update_seed ( - HANDLE_FD_CNG_COM st /* i/o : pointer to FD_CNG_COM structure */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o : pointer to FD_CNG_COM structure */ ) { Word16 *seed; Word16 cnt, i; /* pointer initializations */ - seed = &(st->seed); + seed = &(hFdCngCom->seed); - cnt = sub(st->stopFFTbin, st->startBand); + cnt = sub(hFdCngCom->stopFFTbin, hFdCngCom->startBand); - IF ( st->startBand == 0 ) + IF ( hFdCngCom->startBand == 0 ) { rand_gauss(seed); cnt = sub(cnt,1); @@ -2013,9 +2436,10 @@ void generate_masking_noise_update_seed ( /************************************************************ * Generate additional comfort noise (kind of noise filling) * ************************************************************/ -void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain signal */ +void generate_masking_noise_mdct ( + Word32 *mdctBuffer, /* i/o: time-domain signal */ Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ,Word16 L_frame ) { @@ -2029,13 +2453,13 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain Word32 *cngNoiseLevel; Word16 *seed; - +PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ - cngNoiseLevel = st->cngNoiseLevel; - seed = &(st->seed); + cngNoiseLevel = hFdCngCom->cngNoiseLevel; + seed = &(hFdCngCom->seed); /* Compute additional CN level */ - cngNoiseLevelExp = st->cngNoiseLevelExp; + cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); /* Compute additional CN level */ @@ -2049,9 +2473,9 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain { test(); test(); - IF ( ( EQ_16(st->CngBandwidth,scaleTable_cn_only[i].bwmode)) - && ( GE_32(st->CngBitrate,scaleTable_cn_only[i].bitrateFrom) ) - && ( LT_32(st->CngBitrate,scaleTable_cn_only[i].bitrateTo) ) + IF ( ( EQ_16(hFdCngCom->CngBandwidth,scaleTable_cn_only[i].bwmode)) + && ( GE_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateFrom) ) + && ( LT_32(hFdCngCom->CngBitrate,scaleTable_cn_only[i].bitrateTo) ) ) { scale = scaleTable_cn_only[i].scale; @@ -2063,11 +2487,11 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain /* Exclude clean speech */ s1 = norm_s(scale); - s2 = norm_s(st->likelihood_noisy_speech); + s2 = norm_s(hFdCngCom->likelihood_noisy_speech); /* scaleTable_cn_only[i].scale is scaled by 1 bit */ scaleExp = sub(1,add(s1,s2)); - scale = mult_r(shl(scale,s1),shl(st->likelihood_noisy_speech,s2)); + scale = mult_r(shl(scale,s1),shl(hFdCngCom->likelihood_noisy_speech,s2)); /* add exponent of scale and cngNoiseLevel */ maskingNoiseExp = add(scaleExp,cngNoiseLevelExp); @@ -2082,13 +2506,13 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain /* consider scaling of random noise */ maskingNoiseExp = add(maskingNoiseExp,CNG_RAND_GAUSS_SHIFT); - cnt = sub(st->stopFFTbin,st->startBand); + cnt = sub(hFdCngCom->stopFFTbin,hFdCngCom->startBand); /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ - IF ( st->startBand == 0 ) + IF ( hFdCngCom->startBand == 0 ) { /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ @@ -2107,8 +2531,8 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain } ELSE { - set32_fx(maskingNoise,0,st->startBand); - pMaskingNoise = maskingNoise + st->startBand; + set32_fx(maskingNoise,0,hFdCngCom->startBand); + pMaskingNoise = maskingNoise + hFdCngCom->startBand; } FOR (i=0; istopFFTbin; i++) + FOR (i=0; i < hFdCngCom->stopFFTbin; i++) { /* If shifting negative noise values the lowest result is -1 but never 0. Shift positive noise values to avoid unwanted amplification of these small values later */ @@ -2162,13 +2586,13 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain } ELSE { - FOR (i=0; i < st->stopFFTbin; i++) + FOR (i=0; i < hFdCngCom->stopFFTbin; i++) { mdctBuffer[i] = L_add(L_shr(mdctBuffer[i],s1), Mpy_32_16_1(maskingNoise[i],25905/*0.79056941504 Q15*/)); move32(); } - FOR (i=st->stopFFTbin; i < L_frame; i++) + FOR (i=hFdCngCom->stopFFTbin; i < L_frame; i++) { mdctBuffer[i] = L_shr(mdctBuffer[i],s1); move32(); @@ -2179,3 +2603,507 @@ void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain } } + +#ifdef IVAS_CODE_CNG + +/*------------------------------------------------------------------- + * generate_stereo_masking_noise() + * + * Generate additional comfort noise (kind of noise filling) + *-------------------------------------------------------------------*/ + +void generate_stereo_masking_noise( + float* syn, /* i/o: time-domain signal */ + Decoder_State* st, /* i/o: decoder state structure */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ + const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ + const int16_t fadeOut, /* i : only fade out of previous state */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const int16_t nchan_out /* i : number of output channels */ +) +{ + HANDLE_FD_CNG_COM hFdCngCom; + float gamma, scale, SP_ratio; + float Np[L_FRAME16k]; + float Ns[L_FRAME16k]; + float N1[L_FRAME16k]; + float N2[L_FRAME16k]; + int16_t i; + + if (st->idchan == 0) + { + hFdCngCom = st->hFdCngDec->hFdCngCom; + mvr2r(hFdCngCom->olapBufferSynth2, Np, hFdCngCom->frameSize / 2); + mvr2r(hStereoCng->olapBufferSynth22, Ns, hFdCngCom->frameSize / 2); + set_f(&Np[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2); + set_f(&Ns[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2); + + if (!fadeOut) + { + generate_masking_noise(N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); + /* Generate masking noise for secondary channel */ + if (flag_sec_CNA) + { + generate_masking_noise(N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out); + gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT; + scale = 1.0f; + if (gamma < 0.9f) + { + gamma = gamma / (1 - gamma); + gamma = (float)sqrt(gamma + 1) - (float)sqrt(gamma); + scale = 1.0f / (float)sqrt(1 + gamma * gamma); + } + else + { + gamma = 0.0f; + } + + for (i = 0; i < 2 * hFdCngCom->frameSize / 4; i++) + { + Np[i] += scale * (N1[i] + gamma * N2[i]); + Ns[i] += scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]); + } + for (; i < hFdCngCom->frameSize; i++) + { + Np[i] = scale * (N1[i] + gamma * N2[i]); + Ns[i] = scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]); + } + scale *= (float)(hFdCngCom->fftlen / 2); + for (i = 0; i < hFdCngCom->frameSize / 2; i++) + { + hFdCngCom->olapBufferSynth2[i] = scale * (hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); + hStereoCng->olapBufferSynth22[i] = sign(hStereoCng->c_PS_LT) * scale * (hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); + } + } + else + { + for (i = 0; i < hFdCngCom->frameSize / 2; i++) + { + Np[i] += N1[i]; + } + mvr2r(&N1[hFdCngCom->frameSize / 2], &Np[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2); + scale = (float)(hFdCngCom->fftlen / 2); + for (i = 0; i < hFdCngCom->frameSize; i++) + { + hFdCngCom->olapBufferSynth2[i] = scale * hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4]; + } + } + } + else + { + set_f(hFdCngCom->olapBufferSynth2, 0.0f, hFdCngCom->frameSize / 2); + set_f(hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize / 2); + } + if (flag_sec_CNA) + { + mvr2r(Ns, hStereoCng->maskingNoiseS, hFdCngCom->frameSize); + hStereoCng->enableSecCNA = 1; + } + else + { + set_f(hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize); + } + + /* add masking noise */ + v_add(Np, syn, syn, hFdCngCom->frameSize); + } + else if (hStereoCng->enableSecCNA) + { + SP_ratio = hStereoTD->SP_ratio_LT; /* Use long-term SP ratio based on L/R synthesis */ + /* scale and add masking noise */ + for (i = 0; i < *hStereoCng->frameSize / 4; i++) + { + scale = ((hStereoTD->prevSP_ratio * (*hStereoCng->frameSize / 4 - (float)i) + SP_ratio * (float)i) / (*hStereoCng->frameSize / 4)); + syn[i] += scale * hStereoCng->maskingNoiseS[i]; + } + for (; i < *hStereoCng->frameSize / 2; i++) + { + syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; + } + for (; i < *hStereoCng->frameSize; i++) + { + syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; + } + hStereoTD->prevSP_ratio = SP_ratio; + } + + return; +} + +/*------------------------------------------------------------------- + * generate_masking_noise_hf_cldfb() + * + * Generate additional comfort noise (kind of noise filling) + *-------------------------------------------------------------------*/ + +void generate_masking_noise_dirac( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + float* tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + float* Cldfb_RealBuffer, /* o : CLDFD real buffer */ + float* Cldfb_ImagBuffer, /* o : CLDFD imaginary buffer */ + const int16_t slot_index, /* i : CLDFB slot index */ + const int16_t cna_flag, /* i : CNA flag for LB and HB */ + const int16_t fd_cng_flag /* i : FD-CNG flag for HB */ +) +{ + int16_t i; + float* cngNoiseLevel = hFdCngCom->cngNoiseLevel; + float* fftBuffer = hFdCngCom->fftBuffer; + float* ptr_r; + float* ptr_i; + float* ptr_level; + int16_t* seed = &(hFdCngCom->seed); + float scale; + + wmops_sub_start("fd_cng_dirac"); + + /* Init */ + scale = 0.f; + + /* Resample CLDFB memories if necessary*/ + if ((h_cldfb->no_channels * h_cldfb->no_col) != hFdCngCom->frameSize) + { + resampleCldfb(h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC); + } + + set_zero(Cldfb_RealBuffer, CLDFB_NO_CHANNELS_MAX); + set_zero(Cldfb_ImagBuffer, CLDFB_NO_CHANNELS_MAX); + + /*LB CLDFB - CNA from STFT*/ +#ifdef DEBUG_MODE_DIRAC + { + int16_t tmp_s; + tmp_s = (int16_t)(32768.f * 0.5f * hFdCngCom->likelihood_noisy_speech * cna_flag + 0.5f); + dbgwrite(&tmp_s, sizeof(int16_t), 1, hFdCngCom->frameSize / 16, "./res/ivas_dirac_likelihood_noisy.pcm"); + } +#endif + if (cna_flag) + { + /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ + if (hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE) + { + /* Compute additional CN level */ + for (i = 0; i < 15; i++) + { + if ((hFdCngCom->CngBandwidth == scaleTable_cn_dirac[i].bwmode) && + (hFdCngCom->CngBitrate >= scaleTable_cn_dirac[i].bitrateFrom) && + (hFdCngCom->CngBitrate < scaleTable_cn_dirac[i].bitrateTo)) + { + break; + } + } + + scale = (float)pow(10.f, -scaleTable_cn_dirac[i].scale / 10.f) - 1.f; + scale *= hFdCngCom->likelihood_noisy_speech; + } + } + + /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/ + if (cna_flag && tdBuffer != NULL) + { + if (scale != 0) + { + /*Generate LF comfort noise only at first slot, for the whole frame*/ + if (slot_index == 0) + { + ptr_level = cngNoiseLevel; + + /* Generate Gaussian random noise in real and imaginary parts of the FFT bins + Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ + if (hFdCngCom->startBand == 0) + { + rand_gauss(&fftBuffer[0], seed); + ptr_r = fftBuffer + 2; + fftBuffer[0] *= (float)sqrt(scale * *ptr_level); /* DC component in FFT */ + ptr_level++; + } + else + { + fftBuffer[0] = 0.f; + set_f(fftBuffer + 2, 0.0f, 2 * (hFdCngCom->startBand - 1)); + ptr_r = fftBuffer + 2 * hFdCngCom->startBand; + } + ptr_i = ptr_r + 1; + + for (; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++) + { + /* Real part in FFT bins */ + rand_gauss(ptr_r, seed); + (*ptr_r) *= (float)sqrt((scale * *ptr_level) * 0.5f); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss(ptr_i, seed); + (*ptr_i) *= (float)sqrt((scale * *ptr_level) * 0.5f); + ptr_i += 2; + } + + /* Remaining FFT bins are set to zero */ + set_f(fftBuffer + 2 * hFdCngCom->stopFFTbin, 0.0f, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin); + /* Nyquist frequency is discarded */ + fftBuffer[1] = 0.f; + + /* Perform STFT synthesis */ + SynthesisSTFT(fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, X, Y, -1, -1); + +#ifdef DEBUG_MODE_DIRAC + { + int16_t tmp[1000]; + + for (i = 0; i < hFdCngCom->frameSize; i++) + { + tmp[i] = (int16_t)(tdBuffer[i] + 0.5f); + } + dbgwrite(tmp, sizeof(int16_t), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm"); + } +#endif + } + + /* LF CLDFB*/ + cldfbAnalysis_ts(&(tdBuffer[hFdCngCom->numCoreBands * slot_index]), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb); + } + else + { + if (slot_index == 0) + { + /* very low level case - update random seeds */ + generate_masking_noise_update_seed(hFdCngCom); + + set_f(fftBuffer, 0.f, hFdCngCom->fftlen); + + /* Perform STFT synthesis */ + SynthesisSTFT(fftBuffer, tdBuffer, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom,X, Y , -1, -1); + +#ifdef DEBUG_MODE_DIRAC + { + int16_t tmp[1000]; + + for (i = 0; i < hFdCngCom->frameSize; i++) + { + tmp[i] = (int16_t)(tdBuffer[i] + 0.5f); + } + dbgwrite(tmp, sizeof(int16_t), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm"); + } +#endif + } + + /* LB ana CLDFB*/ + cldfbAnalysis_ts(&(tdBuffer[hFdCngCom->numCoreBands * slot_index]), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb); + } + } + + /*HF CLDFB - CNA and/or FD-CNG*/ + if (fd_cng_flag) + { + scale += 1.f; + } + if (scale != 0) + { + scale *= CLDFB_SCALING * (h_cldfb->scale * h_cldfb->scale * 8.f); + ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; + + for (i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++) + { + /* Real part in CLDFB band */ + rand_gauss(&Cldfb_RealBuffer[i], seed); + Cldfb_RealBuffer[i] *= (float)sqrt((scale * *ptr_level) * 0.5f); + /* Imaginary part in CLDFB band */ + rand_gauss(&Cldfb_ImagBuffer[i], seed); + Cldfb_ImagBuffer[i] *= (float)sqrt((scale * *ptr_level) * 0.5f); + + ptr_level++; + } + } + + wmops_sub_end(); + + return; +} + + +/*------------------------------------------------------------------- + * FdCngDecodeMDCTStereoSID() + * + * Decode FD-Cng parameters for CNG in MDCT-Stereo mode from the bitstream + * + *-------------------------------------------------------------------*/ + +void FdCngDecodeMDCTStereoSID( + CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ +) +{ + DEC_CORE_HANDLE sts[CPE_CHANNELS]; + HANDLE_FD_CNG_COM hFdCngCom; + float* ms_ptr[CPE_CHANNELS]; + float* lr_ptr[CPE_CHANNELS]; + float logNoiseEst[CPE_CHANNELS][NPART]; + float gain[CPE_CHANNELS]; + int16_t indices[FD_CNG_stages_37bits]; + int16_t N, i, ch, p, stages; + int16_t is_out_ms; + + is_out_ms = 0; + if (hCPE->hCoreCoder[0]->cng_sba_flag) + { + is_out_ms = 1; + } + + N = 0; /* to avoid compilation warning */ + + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + sts[ch] = hCPE->hCoreCoder[ch]; + ms_ptr[ch] = &logNoiseEst[ch][0]; + lr_ptr[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; + } + + /* decode noise shapes and gains */ + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + sts[ch] = hCPE->hCoreCoder[ch]; + hFdCngCom = (sts[ch]->hFdCngDec)->hFdCngCom; + N = hFdCngCom->npart; + hFdCngCom->sid_frame_counter++; + + if (ch) + { + stages = FD_CNG_JOINT_stages_25bits; + } + else + { + stages = FD_CNG_stages_37bits; + } + + /* read bitstream */ + for (i = 0; i < stages; i++) + { + indices[i] = get_next_indice(sts[ch], bits_37bits[i]); + } + { + gain[ch] = ((float)get_next_indice(sts[ch], 7) - GAIN_Q_OFFSET_IVAS) / 1.5f; + } + + /* MSVQ decoder */ + msvq_dec(cdk_37bits_ivas, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, ms_ptr[ch], NULL); + } + + if (sts[0]->hFdCngDec->hFdCngCom->no_side_flag) + { + set_zero(ms_ptr[1], NPART); + } + + if (is_out_ms == 0) + { + inverseMS(N, ms_ptr[0], ms_ptr[1], 1.f); + } + + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom; + for (p = 0; p < N; p++) + { + lr_ptr[ch][p] = powf(10.f, (ms_ptr[ch][p] + gain[ch]) / 10.f); + } + + scalebands(hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1); + + lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac); + } + + if (hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_4k4) + { + /* create proper M noise shape in channel zero after gains have been applied */ + for (p = 0; p < N; p++) + { + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * (sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p]); + } + } + + return; +} + + +/*------------------------------------------------------------------- + * FdCngDecodeDiracMDCTStereoSID() + * + * Decode FD-Cng parameters for CNG in 2TC DirAC mode from the bitstream + *-------------------------------------------------------------------*/ + +void FdCngDecodeDiracMDCTStereoSID( + CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ +) +{ + DEC_CORE_HANDLE sts[CPE_CHANNELS]; + HANDLE_FD_CNG_COM hFdCngCom; + float* ms_ptr[CPE_CHANNELS]; + float* lr_ptr[CPE_CHANNELS]; + float logNoiseEst[CPE_CHANNELS][NPART]; + float gain[CPE_CHANNELS]; + int16_t indices[FD_CNG_stages_37bits]; + int16_t N, i, ch, p; + + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + sts[ch] = hCPE->hCoreCoder[ch]; + ms_ptr[ch] = &logNoiseEst[ch][0]; + lr_ptr[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0]; + (sts[ch]->hFdCngDec)->hFdCngCom->sid_frame_counter++; + } + + /* decode noise shapes and gains */ + hFdCngCom = (sts[0]->hFdCngDec)->hFdCngCom; + N = hFdCngCom->npart; + + /* read bitstream */ + for (i = 0; i < FD_CNG_stages_37bits; i++) + { + indices[i] = get_next_indice(sts[0], bits_37bits[i]); + } + gain[0] = ((float)get_next_indice(sts[0], 7) - GAIN_Q_OFFSET_IVAS) / 1.5f; + gain[1] = gain[0]; + + /* MSVQ decoder */ + msvq_dec(cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, ms_ptr[0], NULL); + mvr2r(ms_ptr[0], ms_ptr[1], N); + + /*inverseMS( N, ms_ptr[0], ms_ptr[1], 1.f );*/ + + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom; + for (p = 0; p < N; p++) + { + lr_ptr[ch][p] = powf(10.f, (ms_ptr[ch][p] + gain[ch]) / 10.f); + } + + /* NB last band energy compensation */ + if (hFdCngCom->CngBandwidth == NB) + { + lr_ptr[ch][N - 1] *= NB_LAST_BAND_SCALE; + } + else if (hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20) + { + lr_ptr[ch][N - 1] *= SWB_13k2_LAST_BAND_SCALE; + } + + scalebands(hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1); + + lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac); + } + sts[0]->hFdCngDec->hFdCngCom->coherence = 0.0f; + sts[1]->hFdCngDec->hFdCngCom->coherence = 0.0f; + + if (hCPE->nchan_out == 1) + { + /* create proper M noise shape in channel zero after gains have been applied */ + for (p = 0; p < N; p++) + { + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * (sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p]); + } + sts[0]->hFdCngDec->hFdCngCom->coherence = 0.0f; + sts[1]->hFdCngDec->hFdCngCom->coherence = 0.0f; + } + + return; +} +#endif \ No newline at end of file diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index d679d9d..d816baa 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*===========================================================================*/ @@ -30,21 +29,21 @@ /* _ None */ /*===========================================================================*/ void Es_pred_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate /* i : core bitrate */ + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ + const Word16 enr_idx, /* i : indice */ + const Word16 nb_bits, /* i : number of bits */ + const Word16 no_ltp /* i : no LTP flag */ ) { - Word16 enr_idx, nb_bits; - { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, -1, -1)]; - move16(); - enr_idx = (Word16)get_next_indice_fx( st_fx, nb_bits ); - move16(); - } - SWITCH ( nb_bits ) +#ifdef IVAS_GAIN_MOD + PMT("Verify if Es_pred_dec_fx should use noltp parameters") +#endif +#if 1//def IVAS_GAIN_MOD + IF(no_ltp == 0) +#endif { + SWITCH(nb_bits) + { case 5: *Es_pred = Es_pred_qua_5b_fx[enr_idx]; move16(); @@ -53,11 +52,23 @@ void Es_pred_dec_fx( *Es_pred = Es_pred_qua_4b_fx[enr_idx]; move16(); BREAK; +#ifdef IVAS_GAIN_MOD + case 3: + *Es_pred = Es_pred_qua_3b_fx[enr_idx]; + break; +#endif default: *Es_pred = Es_pred_qua_5b_fx[enr_idx]; move16(); BREAK; + } } +#ifdef IVAS_GAIN_MOD + ELSE + { + *Es_pred = Es_pred_qua_4b_no_ltp_fx[enr_idx]; + } +#endif } /*======================================================================================*/ /* FUNCTION : void gain_dec_tc_fx () */ @@ -88,11 +99,8 @@ void Es_pred_dec_fx( void gain_dec_tc_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate_fx, /* i : core bitrate */ const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 L_frame_fx, /* i : length of the frame */ const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ Word16 *gain_pit_fx, /* o : pitch gain */ Word32 *gain_code_fx, /* o : Quantized codeebook gain */ @@ -113,17 +121,7 @@ void gain_dec_tc_fx( /*----------------------------------------------------------------* * find number of bits for gain dequantization *----------------------------------------------------------------*/ - IF( EQ_16(L_frame_fx,L_FRAME)) - { - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate_fx, TRANSITION, i_subfr_fx, TC_SUBFR2IDX_fx(tc_subfr_fx))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate_fx, TRANSITION, i_subfr_fx, TC_SUBFR2IDX_16KHZ_fx(tc_subfr_fx))]; - move16(); - } - + nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr_fx, 6)]; /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ @@ -233,7 +231,6 @@ void gain_dec_tc_fx( /*======================================================================================*/ void gain_dec_mless_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate_fx, /* i : core bitrate */ const Word16 L_frame_fx, /* i : length of the frame */ const Word16 coder_type_fx, /* i : coding type */ const Word16 i_subfr_fx, /* i : subframe number */ @@ -255,16 +252,7 @@ void gain_dec_mless_fx( /*-----------------------------------------------------------------* * decode pitch gain *-----------------------------------------------------------------*/ - IF( EQ_16(L_frame_fx,L_FRAME)) - { - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate_fx, coder_type_fx, i_subfr_fx, TC_SUBFR2IDX_fx(tc_subfr_fx))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate_fx, coder_type_fx, i_subfr_fx, TC_SUBFR2IDX_16KHZ_fx(tc_subfr_fx))]; - move16(); - } + nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr_fx, 6) ]; test(); test(); test(); @@ -354,6 +342,11 @@ void gain_dec_mless_fx( { qua_table_fx = gain_qua_mless_6b_fx; move16(); + IF (GT_16(st_fx->element_mode, EVS_MONO) ) + { + PMT("gain_qua_mless_6b_stereo to fixed point") + //qua_table_fx = gain_qua_mless_6b_stereo; + } BREAK; } case 5: @@ -471,17 +464,17 @@ void gain_dec_mless_fx( /* _ None */ /*==================================================================================*/ void gain_dec_lbr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q9 */ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *code_fx, /* i : algebraic excitation Q9 */ + Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ + Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 L_subfr /* i : subfr lenght */ ) { Word16 index, nBits, n_pred, ctype; @@ -491,9 +484,16 @@ void gain_dec_lbr_fx( const Word16 *b_fx ,*cdbk_fx = 0; /* Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; *gain_inov = 1.0f / (float)sqrt(Ecode); */ + Word16 shift_L_subfr; + shift_L_subfr = 6; + move16(); + IF(GT_16(L_subfr, L_SUBFR)) + { + shift_L_subfr = add(shift_L_subfr, 1); + } + L_tmp = Dot_product12(code_fx, code_fx, L_subfr, &expg); + expg = sub(expg, add(18, shift_L_subfr)); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ expg2 = expg; move16(); L_tmp2 = L_tmp; /* sets to 'L_tmp' in 1 clock */ @@ -507,8 +507,7 @@ void gain_dec_lbr_fx( * select the codebook, size and number of bits * set the gains searching range *-----------------------------------------------------------------*/ - - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; + nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr, shift_L_subfr)]; move16(); ctype = shl(sub(coder_type, 1),1); @@ -599,7 +598,7 @@ void gain_dec_lbr_fx( gp_mem[0] = *gain_pit_fx; move16(); /*Q14*/ } - ELSE IF (EQ_16(i_subfr,L_SUBFR)) + ELSE IF (EQ_16(i_subfr,L_SUBFR) || EQ_16(L_subfr, 2*L_SUBFR)) { b_fx = b_2sfr_fx; move16(); @@ -676,6 +675,13 @@ void gain_dec_lbr_fx( move16(); cdbk_fx = gp_gamma_3sfr_6b_fx; +#ifdef IVAS_GAIN_MOD + IF(EQ_16(nBits, 7)) + { + cdbk_fx = gp_gamma_3sfr_7b_fx; + PMT("verify if gp_gamma_3sfr_7b_fx is correct") + } +#endif move16(); /* Q14/Q9*/ /* calculate predicted gain */ @@ -741,7 +747,15 @@ void gain_dec_lbr_fx( n_pred = 8; move16(); + cdbk_fx = gp_gamma_4sfr_6b_fx; +#ifdef IVAS_GAIN_MOD + IF(EQ_16(nBits, 7)) + { + cdbk_fx = gp_gamma_4sfr_7b_fx; + PMT("verify if gp_gamma_4sfr_7b_fx is correct") + } +#endif move16(); /* Q14/Q9*/ /* calculate predicted gain */ @@ -991,17 +1005,14 @@ Word32 gain_dec_gaus_fx( /* o : quantized codebook gain *-------------------------------------------------------------------------*/ void gain_dec_SQ_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *code, /* i : algebraic code excitation Q9*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ - Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word16 i_subfr, /* i : subframe number */ + const Word16 *code, /* i : algebraic code excitation Q9*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ + Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ + Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ + Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ + Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ ) { Word16 index, nBits; @@ -1013,7 +1024,7 @@ void gain_dec_SQ_fx( * get number of bits *-----------------------------------------------------------------*/ - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr)) ]; + nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr, 6)]; move16(); /*-----------------------------------------------------------------* diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index 4890b2b..b0d27f9 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -2,15 +2,15 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ + * Local function prototypes + *---------------------------------------------------------------------*/ void gaus_dec2v_fx( Decoder_State_fx *st_fx, Word16 *code, const Word16 lg, const Word16 nb_bits); static void dec_2pos_fx(Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1, Word16 *sign2, Word16 log2_n); @@ -24,7 +24,6 @@ static void dec_2pos_fx(Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1, *---------------------------------------------------------------------*/ void gaus_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word32 core_brate, /* i : core bitrate */ const Word16 i_subfr, /* i : subframe index */ Word16 *code, /* o : unvoiced excitation Q12 */ Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ @@ -46,12 +45,15 @@ void gaus_dec_fx( Word16 i, exp, gain_code; Word16 idx, nb_bits; Word32 L_tmp; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; + MUSIC_POSTFILT_HANDLE hMusicPF; + hMusicPF = st_fx->hMusicPF; /*------------------------------------------------------------------------------------------* * Unvoiced : Gaussian codebook *------------------------------------------------------------------------------------------*/ - - nb_bits = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX_fx(-1))]; + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[shr(i_subfr,6)]; move16(); gaus_dec2v_fx( st_fx, code, L_SUBFR, shr(nb_bits,1)); @@ -65,13 +67,13 @@ void gaus_dec_fx( L_tmp = Isqrt_lc(L_tmp, &exp); *inv_gain_inov = extract_h(L_shl(L_tmp, sub(exp, 3))); /* inv_gain_inov in Q12 */ - nb_bits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX_fx(-1))]; + nb_bits = st_fx->acelp_cfg.gains_mode[shr(i_subfr, 6)]; move16(); idx = (Word16)get_next_indice_fx( st_fx, nb_bits ); move16(); /* safety check in case of bit errors */ - IF( GT_16(idx,78)) + IF( GT_16(idx,78) && EQ_16(st_fx->element_mode, EVS_MONO)) { idx = 78; move16(); @@ -103,12 +105,12 @@ void gaus_dec_fx( IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); } ELSE { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * 2], st_fx->last_exc_dct_in_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * 2], hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR* 2, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); } @@ -276,7 +278,7 @@ void gaus_L2_dec( move16(); /*Shape the gaussian excitation*/ - cb_shape_fx( 1, 0, 0, 1, 0, formant_enh, FORMANT_SHARPENING_G2, A, code, tilt_code, 0, 1 ); + cb_shape_fx( 1, 0, 0, 1, 0, formant_enh, FORMANT_SHARPENING_G2, A, code, tilt_code, 0, 1 , L_SUBFR); return; diff --git a/lib_dec/gs_dec_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index f3a5e5a..ce31d4d 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* @@ -25,6 +25,23 @@ #define NORMALIZE_SPECS_Q_OUT 6 #define ENER_FX_Q_GUARD 1 +#ifdef ADD_IVAS_GS_DEC_IMPR +#define CONTR_LIMIT 3012 to be verified for fixed point /* Threshold to allow an increase in the contribution length */ +#endif + /*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ +static void NoiseFill_fx(Word16* exc_diffQ_fx, Word16* seed_tcx, const Word16 Mbands_gn, const Word16 Q_out); +static void Ener_per_band_fx(const Word16 exc_diff_fx[], const Word16 exc_diff_exp, Word32 y_gain4_fx[]); +static void Apply_gain_fx(Word16 exc_diffQ_fx[], Word32 L_Ener_per_bd_iQ[], Word32 L_Ener_per_bd_yQ[], const Word16 Q_out); +static void normalize_spec_fx(Word16 fac_up_fx, Word16 fy_norm_fx[], const Word16 L_frame, const Word16 Q_out); +static void gs_dec_amr_wb_fx(const long core_brate, Word16* seed_tcx, const Word16 dct_in_fx[], const Word16 Q_dct_in, + Word16 dct_out_fx[], Word16 Q_dct_out, const Word16 pitch_fx[], const Word16 voice_fac, const Word16 clas, const Word16 coder_type +#ifdef ADD_IVAS_GS_DEC_IMPR + , const Word16 VeryLowRateSTflag +#endif + ); + /*-------------------------------------------------------------------* * NoiseFill_fx() * @@ -196,16 +213,19 @@ static void normalize_spec_fx( *-------------------------------------------------------------------*/ static void gs_dec_amr_wb_fx( - const long core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: seed used for noise generation */ - const Word16 dct_in_fx[], /* i : cdt of residual signal */ - const Word16 Q_dct_in, /* i : Exponent of dct_in_fx */ - Word16 dct_out_fx[], /* o : dct of pitch only excitation */ - Word16 Q_dct_out, /* o : Exponent of dct_out_fx */ - const Word16 pitch_fx[], /* i : pitch buffer */ - const Word16 voice_fac, /* i : gain pitch Q15 */ - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type /* i : coder type */ + const long core_brate, /* i : bitrate allocated to the core */ + Word16 *seed_tcx, /* i/o: seed used for noise generation */ + const Word16 dct_in_fx[], /* i : cdt of residual signal */ + const Word16 Q_dct_in, /* i : Exponent of dct_in_fx */ + Word16 dct_out_fx[], /* o : dct of pitch only excitation */ + Word16 Q_dct_out, /* o : Exponent of dct_out_fx */ + const Word16 pitch_fx[], /* i : pitch buffer */ + const Word16 voice_fac, /* i : gain pitch Q15 */ + const Word16 clas, /* i : signal frame class */ + const Word16 coder_type /* i : coder type */ +#ifdef ADD_IVAS_GS_DEC_IMPR + ,const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ +#endif ) { Word16 i, mDiff_len; @@ -258,8 +278,12 @@ static void gs_dec_amr_wb_fx( temp = Invert16(temp, &exp); L_temp = L_mult(temp, 12800); L_temp = L_shl(L_temp, sub(3, exp)); /* *8.0f */ - - if( GE_32(core_brate, ACELP_12k65)) +#ifdef ADD_IVAS_GS_DEC_IMPR + test(); test(); + IF (L_temp <= CONTR_LIMIT && (VeryLowRateSTflag || GE_32(core_brate, ACELP_12k65))) +#else + IF( GE_32(core_brate, ACELP_12k65)) +#endif { L_temp = L_shl(L_temp, 1); } @@ -283,16 +307,25 @@ static void gs_dec_amr_wb_fx( mDiff_len = s_max(round_fx(L_temp), BIN_1k2); - Copy(dct_in_fx, exc_diffQ_fx, mDiff_len); - set16_fx(exc_diffQ_fx+mDiff_len, 0, sub(L_FRAME, mDiff_len)); - /*--------------------------------------------------------------------------------------* - * normalization of the spectrum and noise fill - *--------------------------------------------------------------------------------------*/ +#ifdef ADD_IVAS_GS_DEC_IMPR + IF ((VeryLowRateSTflag && (EQ_16(clas, VOICED_CLAS) || EQ_16(clas, AUDIO_CLAS) ) ) ) /* Do not apply normalization on VOICED signal in case of stereo */ + { + Copy(dct_in_fx, exc_diffQ, L_FRAME); - normalize_spec_fx(4*256, exc_diffQ_fx, mDiff_len, NORMALIZE_SPECS_Q_OUT); /* Factors in Q8 */ - NoiseFill_fx( exc_diffQ_fx, seed_tcx, CRIT_NOIS_BAND, NORMALIZE_SPECS_Q_OUT); + /* normalization of the spectrum and noise fill */ + normalize_spec_fx(1*256, exc_diffQ + mDiff_len, L_FRAME - mDiff_len, NORMALIZE_SPECS_Q_OUT); + } + ELSE +#endif + { + Copy(dct_in_fx, exc_diffQ_fx, mDiff_len); + set16_fx(exc_diffQ_fx + mDiff_len, 0, sub(L_FRAME, mDiff_len)); + /* normalization of the spectrum and noise fill*/ + normalize_spec_fx(4 * 256, exc_diffQ_fx, mDiff_len, NORMALIZE_SPECS_Q_OUT); /* Factors in Q8 */ + } + NoiseFill_fx(exc_diffQ_fx, seed_tcx, CRIT_NOIS_BAND, NORMALIZE_SPECS_Q_OUT); /*--------------------------------------------------------------------------------------* * Recompute energy per band of the modified excitation vector (in frequency domain) *--------------------------------------------------------------------------------------*/ @@ -332,24 +365,27 @@ static void gs_dec_amr_wb_fx( * unvoiced and audio signals (used only in AMR-WB IO mode) *-------------------------------------------------------------------*/ void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ + const Word16 clas, /* i : signal frame class */ + const Word16 coder_type, /* i : coder type */ + const Word32 core_brate, /* i : bitrate allocated to the core */ Word16 *seed_tcx, /* i/o: Seed used for noise generation */ Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14 */ - const Word16 locattack, /* i : Flag for a detected attack */ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14 */ + const Word16 locattack, /* i : Flag for a detected attack */ Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6 */ - const Word16 Last_ener_fx /* i : Last energy (Q8) */ - ,const Word16 rate_switching_reset /* i : rate switching reset flag */ - ,const Word16 last_coder_type_fx /* i : Last coder_type */ + const Word16 Q_syn, /* i : Synthesis scaling Q0 */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6 */ + const Word16 Last_ener_fx, /* i : Last energy (Q8) */ + const Word16 rate_switching_reset, /* i : rate switching reset flag */ + const Word16 last_coder_type_fx /* i : Last coder_type */ +#ifdef ADD_IVAS_GS_DEC_IMPR + ,const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ +#endif ) { Word16 i, exp_a, exp_b, exp_diff, j; @@ -368,9 +404,16 @@ void improv_amr_wb_gs_fx( test(); test(); test(); +#ifdef ADD_IVAS_GS_DEC_IMPR + IF(VeryLowRateSTflag || + ((locattack == 0 && LE_32(core_brate, ACELP_12k65)) && + ((LT_32(core_brate, ACELP_8k85) && NE_16(clas, AUDIO_CLAS) && + (EQ_16(clas, UNVOICED_CLAS) || EQ_16(clas, VOICED_TRANSITION))) || EQ_16(coder_type, INACTIVE)))) +#else IF( ( locattack == 0 && LE_32(core_brate, ACELP_12k65))&& ( (LT_32(core_brate, ACELP_8k85) && NE_16(clas, AUDIO_CLAS) && (EQ_16(clas, UNVOICED_CLAS) || EQ_16(clas, VOICED_TRANSITION) )) || EQ_16(coder_type, INACTIVE) ) ) +#endif { /*------------------------------------------------------------* * two differents paths: @@ -438,10 +481,14 @@ void improv_amr_wb_gs_fx( * Do the excitation modification according to the content * Go back to time domain -> Overwrite exctiation *------------------------------------------------------------*/ - edct_16fx(exc2_fx, dct_exc_in_fx, L_FRAME, 6); - gs_dec_amr_wb_fx( core_brate, seed_tcx, dct_exc_in_fx, Q_exc2, dct_exc_out_fx, Q_exc2, pitch_buf_fx, lt_voice_fac_fx, clas, coder_type ); - - edct_16fx(dct_exc_out_fx, exc2_fx, L_FRAME, 6); + edct_16fx(exc2_fx, dct_exc_in_fx, L_FRAME, 6, EVS_MONO); + gs_dec_amr_wb_fx( core_brate, seed_tcx, dct_exc_in_fx, Q_exc2, dct_exc_out_fx, Q_exc2, pitch_buf_fx, lt_voice_fac_fx, clas, coder_type +#ifdef ADD_IVAS_GS_DEC_IMPR + , VeryLowRateSTflag +#endif + ); + + edct_16fx(dct_exc_out_fx, exc2_fx, L_FRAME, 6, EVS_MONO); /*------------------------------------------------------------* * Redo core synthesis at 12k8 Hz with the modified excitation *------------------------------------------------------------*/ diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 903d5b5..a263de8 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -2,11 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "stl.h" +#include #include "options.h" #include "cnst_fx.h" #include "rom_com_fx.h" #include "prot_fx.h" +#include "ivas_cnst.h" /*=========================================================================*/ /* FUNCTION : void decod_audio_fx(); */ @@ -34,7 +35,6 @@ void decod_audio_fx( Decoder_State_fx *st_fx, /* i/o: decoder static memory */ Word16 dct_epit[], /* o : GSC excitation in DCT domain */ const Word16 *Aq, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ Word16 *pitch_buf, /* o : floating pitch values for each subframe */ Word16 *voice_factors, /* o : voicing factors */ Word16 *exc, /* i/o: adapt. excitation exc */ @@ -45,7 +45,7 @@ void decod_audio_fx( ) { Word16 tmp_nb_bits_tot, pit_band_idx; - Word16 code[L_SUBFR]; + Word16 code[4*L_SUBFR]; Word16 Diff_len, nb_subfr, i; Word16 nb_frame_flg; Word16 Es_pred = 0; @@ -56,7 +56,9 @@ void decod_audio_fx( Word16 last_bin; Word16 nbits; - Word16 exc_wo_nf[L_FRAME]; + Word16 exc_wo_nf[L_FRAME16k]; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; /*---------------------------------------------------------------* @@ -70,69 +72,134 @@ void decod_audio_fx( /* decode GSC SWB speech flag */ test(); - IF( NE_16(coder_type,INACTIVE)&&GE_32(st_fx->total_brate_fx,ACELP_13k20)) +#if !defined ADD_LRTD + IF( NE_16(st_fx->coder_type_fx,INACTIVE)&&GE_32(st_fx->total_brate_fx,ACELP_13k20)) +#else + if (st_fx->GSC_IVAS_mode >= 1 || (st_fx->coder_type != INACTIVE && ((st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20) || + (st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k)))) +#endif { st_fx->GSC_noisy_speech_fx = (Word16) get_next_indice_fx( st_fx, 1 ); } /* safety check in case of bit errors */ test(); - IF( st_fx->GSC_noisy_speech_fx && NE_16(st_fx->bwidth_fx,SWB)) + IF(st_fx->GSC_noisy_speech_fx && LT_16(st_fx->bwidth_fx, SWB) && st_fx->GSC_IVAS_mode == 0) { st_fx->BER_detect = 1; move16(); st_fx->GSC_noisy_speech_fx = 0; move16(); } - + /* set bit-allocation */ +#ifdef ADD_LRTD + config_acelp1(DEC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame_fx, st_fx->GSC_noisy_speech_fx, &(st_fx->acelp_cfg), st_fx->next_bit_pos_fx, st_fx->coder_type_fx, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); +#else + config_acelp1(DEC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame_fx, st_fx->GSC_noisy_speech_fx, &(st_fx->acelp_cfg), st_fx->next_bit_pos_fx, st_fx->coder_type_fx, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); +#endif /*---------------------------------------------------------------* * Decode energy dynamics *---------------------------------------------------------------*/ +#if defined ADD_LRTD + test(); test(); + IF (st_fx->GSC_IVAS_mode >= 1 || (EQ_16(st_fx->GSC_noisy_speech_fx, 1) && st_fx->GSC_IVAS_mode == 0)) +#else IF( EQ_16(st_fx->GSC_noisy_speech_fx,1)) +#endif { nb_subfr = NB_SUBFR; move16(); - st_fx->cor_strong_limit_fx = 0; + hGSCDec->cor_strong_limit_fx = 0; move16(); - st_fx->noise_lev_fx = NOISE_LEVEL_SP3; + hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3; move16(); +#ifdef ADD_LRTD + if (st_fx->GSC_IVAS_mode >= 1) + { + if (st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3) + { + nb_subfr = 2; + } + hGSCDec->noise_lev = NOISE_LEVEL_SP2; + + if (st_fx->GSC_IVAS_mode == 3) /* Music like */ + { + hGSCDec->noise_lev = NOISE_LEVEL_SP0; + } + else if (st_fx->GSC_noisy_speech == 0) /* speech like but not noisy */ + { + hGSCDec->noise_lev = NOISE_LEVEL_SP3; + } + } +#endif } ELSE { IF( LE_32(st_fx->core_brate_fx,ACELP_8k00)) { - st_fx->noise_lev_fx = add((Word16)get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2); + hGSCDec->noise_lev_fx = add((Word16)get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2); } ELSE { - st_fx->noise_lev_fx = add((Word16)get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0); + hGSCDec->noise_lev_fx = add((Word16)get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0); } /*---------------------------------------------------------------* * Decode number of subframes *---------------------------------------------------------------*/ - - st_fx->cor_strong_limit_fx = 1; - move16(); - nb_subfr = SWNB_SUBFR; - move16(); - - IF( GE_32(st_fx->core_brate_fx,ACELP_9k60)) +#ifdef ADD_LRTD + if (st_fx->L_frame == L_FRAME16k && (st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE)) { - nbits = 1; + hGSCDec->cor_strong_limit = 0; + nb_subfr = 1; + } + else +#endif + { + hGSCDec->cor_strong_limit_fx = 1; + move16(); + nb_subfr = SWNB_SUBFR; move16(); - nb_frame_flg = (Word16)get_next_indice_fx( st_fx, nbits ); - IF( s_and(nb_frame_flg,0x1) == 0) + IF(GE_32(st_fx->core_brate_fx,ACELP_9k60)) { - nb_subfr = 2*SWNB_SUBFR; - move16(); - st_fx->cor_strong_limit_fx = 0; + nbits = 1; move16(); +#ifdef ADD_LRTD + if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR) + { + nbits = 2; + } +#endif + nb_frame_flg = (Word16)get_next_indice_fx(st_fx, nbits); + + IF(s_and(nb_frame_flg,0x1) == 0) + { + nb_subfr = 2 * SWNB_SUBFR; + move16(); + hGSCDec->cor_strong_limit_fx = 0; + move16(); + } +#ifdef ADD_LRTD + else if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR) + { + nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */ + } + + if ((nb_frame_flg >> 1) == 1) + { + nb_subfr *= 2; + } +#endif } } } - +#if 0 + if (st_fx->L_frame == L_FRAME16k && nb_subfr == NB_SUBFR) + { + nb_subfr = NB_SUBFR16k; + } +#endif /*---------------------------------------------------------------* * Decode the last band where the adaptive (pitch) contribution is significant *---------------------------------------------------------------*/ @@ -142,7 +209,7 @@ void decod_audio_fx( nbits = 3; move16(); test(); - if( LT_32(st_fx->core_brate_fx,ACELP_9k60)&&(EQ_16(coder_type,INACTIVE))) + if( LT_32(st_fx->core_brate_fx,ACELP_9k60)&&(EQ_16(st_fx->coder_type_fx,INACTIVE))) { nbits = 1; move16(); @@ -154,7 +221,7 @@ void decod_audio_fx( move16(); } test(); - IF( LT_32(st_fx->core_brate_fx,ACELP_9k60)&&NE_16(coder_type,INACTIVE)) + IF( LT_32(st_fx->core_brate_fx,ACELP_9k60)&&NE_16(st_fx->coder_type_fx,INACTIVE)) { pit_band_idx = 1; move16(); @@ -187,7 +254,7 @@ void decod_audio_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; move16(); } - st_fx->Last_GSC_pit_band_idx_fx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx; move16(); @@ -201,18 +268,35 @@ void decod_audio_fx( * Decode adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ test(); +#ifdef ADD_LRTD + if (!(st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3) && + ((st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech) && + ((nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME) || (nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k)))) +#else IF( EQ_16(st_fx->GSC_noisy_speech_fx,1)&&EQ_16(nb_subfr,NB_SUBFR)) +#endif { - Es_pred_dec_fx( st_fx, &Es_pred, GENERIC, st_fx->core_brate_fx ); - } + Word16 indice; + nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, GENERIC, -1, -1)]; + move16(); + IF (GT_16(st_fx->element_mode, EVS_MONO)) + { + nbits = 5; + move16(); + } - dec_pit_exc_fx( st_fx, Aq, coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr - , gain_buf - ); + indice = get_next_indice_fx(st_fx, nbits); + Es_pred_dec_fx( &Es_pred, indice, nbits, 0); + } +#ifdef ADD_LRTD + dec_pit_exc_fx(st_fx, Aq, coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); +#else + dec_pit_exc_fx(st_fx, Aq, st_fx->coder_type_fx, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf); +#endif IF( LT_32(st_fx->core_brate_fx,ACELP_9k60)) { - minimum_fx( pitch_buf, shr(L_FRAME,6), &low_pit); + minimum_fx(pitch_buf, shr(st_fx->L_frame_fx, 6), &low_pit); low_pit = shr(low_pit, 6); /*Q6 -> Q0 */ IF( LT_16(low_pit,64)) @@ -238,20 +322,20 @@ void decod_audio_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; move16(); - st_fx->Last_GSC_pit_band_idx_fx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx; move16(); } /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, L_FRAME, 7 ); + edct_16fx( exc, dct_epit, st_fx->L_frame_fx, 7 , st_fx->element_mode); /*---------------------------------------------------------------* * Reset unvaluable part of the adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ - max_len = sub( L_FRAME, Diff_len ); + max_len = sub(st_fx->L_frame_fx, Diff_len ); if(EQ_16(st_fx->bwidth_fx,NB)) { @@ -291,7 +375,7 @@ void decod_audio_fx( } st_fx->bfi_pitch_fx = mean_fx(pitch_buf, nb_subfr); move16(); - st_fx->bfi_pitch_frame_fx = L_FRAME; + st_fx->bfi_pitch_frame_fx = st_fx->L_frame_fx; move16(); Diff_len = add(Diff_len,1); @@ -303,13 +387,21 @@ void decod_audio_fx( /* No adaptive (pitch) excitation contribution */ st_fx->bpf_off_fx = 1; move16(); - set16_fx( dct_epit, 0, L_FRAME ); - set16_fx( pitch_buf, shl(L_SUBFR,6), NB_SUBFR ); + set16_fx(dct_epit, 0, st_fx->L_frame_fx); + + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + set16_fx(pitch_buf, shl(L_SUBFR16k, 6), NB_SUBFR16k); + } + ELSE + { + set16_fx(pitch_buf, shl(L_SUBFR, 6), NB_SUBFR); + } set16_fx( gain_buf, 0, NB_SUBFR16k); st_fx->bfi_pitch_fx = shl(L_SUBFR,6); - st_fx->bfi_pitch_frame_fx = L_FRAME; + st_fx->bfi_pitch_frame_fx = st_fx->L_frame_fx; move16(); st_fx->lp_gainp_fx = 0; move16(); @@ -331,8 +423,11 @@ void decod_audio_fx( tmp_nb_bits_tot = st_fx->next_bit_pos_fx; move16(); - +#ifdef IVAS_CODE + if( st_fx->extl_brate_fx_orig > 0 ) +#else if( st_fx->extl_brate_fx > 0 ) +#endif { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ tmp_nb_bits_tot = sub(tmp_nb_bits_tot, 1); @@ -340,41 +435,62 @@ void decod_audio_fx( test(); - if( EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_9k60)) +#if defined ADD_LRTD + test(); + if( EQ_16(st_fx->coder_type_fx,INACTIVE) && LE_32(st_fx->core_brate_fx,ACELP_9k60) && st_fx->idchan == 0) +#else + if (EQ_16(st_fx->coder_type_fx, INACTIVE) && LE_32(st_fx->core_brate_fx, ACELP_9k60)) +#endif { tmp_nb_bits_tot = add(tmp_nb_bits_tot,5); } - gsc_dec_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); - +#ifdef ADD_LRTD + IF (EQ_16(st_fx->idchan, 1) ) + { + tmp_nb_bits_tot = add(tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS); + IF (EQ_16(st_fx->tdm_LRTD_flag, 1)) + { + tmp_nb_bits_tot = sub(tmp_nb_bits_tot, STEREO_BITS_TCA); + } + } +#endif + gsc_dec_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type_fx, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ - edct_16fx( dct_epit, exc, L_FRAME, 7 ); - edct_16fx( exc_wo_nf, exc_wo_nf, L_FRAME, 7 ); + edct_16fx( dct_epit, exc, st_fx->L_frame_fx, 7, st_fx->element_mode); + edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame_fx, 7, st_fx->element_mode); /*----------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ - pre_echo_att_fx( &st_fx->Last_frame_ener_fx, exc, gsc_attack_flag - ,st_fx->Q_exc - ,st_fx->last_coder_type_fx - ); + pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag + ,st_fx->Q_exc ,st_fx->last_coder_type_fx, st_fx->L_frame_fx); /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ - set16_fx( voice_factors, 0, NB_SUBFR16k ); - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - + if (st_fx->hBWE_TD != NULL) + { + set16_fx(voice_factors, 0, NB_SUBFR16k); + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + interp_code_4over2_fx(exc, bwe_exc, st_fx->L_frame_fx); + } + ELSE + { + interp_code_5over2_fx(exc, bwe_exc, L_FRAME); + } + } /*--------------------------------------------------------------------------------------* * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, L_FRAME ); - Copy( exc_wo_nf, exc, L_FRAME ); + Copy( exc, exc2, st_fx->L_frame_fx); + Copy( exc_wo_nf, exc, st_fx->L_frame_fx); /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -409,20 +525,29 @@ void decod_audio_fx( /* _None */ /*==========================================================================*/ void gsc_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + Decoder_State_fx *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ + const Word16 bits_used, /* i : Number of bit used before frequency Q */ const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + const Word16 coder_type, /* i : coding type */ + Word16 *last_bin, /* i : last bin of bit allocation */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ Word16 Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; +#if 1//def ADD_LRTD + Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; + Word16 bitallocation_exc[2]; + Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; + Word16 max_ener_band[MBANDS_GN_BITALLOC16k]; + Word16 exc_diffQ[L_FRAME16k]; + Word16 bits_per_bands[MBANDS_GN_BITALLOC16k]; + Word16 concat_out[L_FRAME16k]; +#else Word16 bitallocation_band[MBANDS_GN]; Word16 bitallocation_exc[2]; Word16 Ener_per_bd_iQ[MBANDS_GN]; @@ -430,6 +555,7 @@ void gsc_dec_fx( Word16 exc_diffQ[L_FRAME]; Word16 bits_per_bands[MBANDS_GN]; Word16 concat_out[L_FRAME]; +#endif Word16 inpulses_fx[NB_SFM]; Word16 imaxpulse_fx[NB_SFM]; Word16 mean_gain; @@ -438,6 +564,8 @@ void gsc_dec_fx( Word32 L_tmp; Word16 Q_tmp; Word16 seed_init; + GSC_DEC_HANDLE hGSCDec; + hGSCDec = st_fx->hGSCDec; set16_fx(inpulses_fx, 0,NB_SFM); set16_fx(imaxpulse_fx, 0,NB_SFM); @@ -447,7 +575,20 @@ void gsc_dec_fx( *--------------------------------------------------------------------------------------*/ bit = bits_used; move16(); - set16_fx( exc_diffQ, 0, L_FRAME ); +#ifdef ADD_LRTD + test(); test(); test(); test(); + IF (EQ_16(coder_type, INACTIVE) && (EQ_16(st_fx->tdm_LRTD_flag, 1) || EQ_16(st_fx->element_mode, IVAS_SCE) ) && LE_32(st_fx->core_brate, GSC_LRES_GAINQ_LIMIT) ) + { + bit = add( bit, GSC_LRES_NB_NITS); + } + + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k) ) + { + Mbands_gn = MBANDS_GN16k; + move16(); + } +#endif + set16_fx( exc_diffQ, 0, st_fx->L_frame_fx ); /*--------------------------------------------------------------------------------------* * Gain decoding @@ -457,7 +598,7 @@ void gsc_dec_fx( IF( st_fx->bfi_fx || st_fx->BER_detect ) { /* copy old gain */ - Copy( st_fx->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); + Copy(hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); mean_gain = mult_r(st_fx->lp_gainc_fx,3277); /*Q3*/ FOR( i=0; icore_brate_fx, st_fx->old_y_gain_fx, coder_type, st_fx->bwidth_fx ); +#ifdef ADD_LRTD + i = 0; + move16(); + While (LT_16(i, SIZE_BRATE_INTERMED_TBL)) + { + IF (LQ_32(st_fx->core_brate, brate_intermed_tbl[i])) + { + break; + } + i = add(i,1); + } + + test(); test(); test(); test(); + IF (GT_16(st_fx->element_mode, EVS_MONO) > && EQ_16(coder_type, AUDIO) && + LE_32(st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i],ACELP_9k60) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ + { + i--; + } + mean_gain = gsc_gaindec_fx(st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth); + +#else + mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate_fx, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth_fx ); +#endif st_fx->lp_gainc_fx = mult_r(640,mean_gain); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ } @@ -494,22 +657,26 @@ void gsc_dec_fx( * reduce spectral dynamic * save spectrum *--------------------------------------------------------------------------------------*/ +#ifdef ADD_LRTD + max_eq = 32767; + move16(); +#endif test(); IF( EQ_16(st_fx->last_good_fx,INACTIVE_CLAS)||EQ_16(st_fx->Last_GSC_noisy_speech_flag_fx,1)) { - FOR( i=0; iL_frame_fx; i++ ) { - L_tmp = L_shr(L_mult(Random(&st_fx->seed_tcx_fx),26214),5); /*Q10*/ - L_tmp = L_mac(L_tmp, st_fx->Last_GSC_spectrum_fx[i],6554); - st_fx->Last_GSC_spectrum_fx[i] = round_fx(L_tmp); /*Q10*/ + L_tmp = L_shr(L_mult(Random(&hGSCDec->seed_tcx_fx),26214),5); /*Q10*/ + L_tmp = L_mac(L_tmp, hGSCDec->Last_GSC_spectrum_fx[i],6554); + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx(L_tmp); /*Q10*/ } } - Copy( st_fx->Last_GSC_spectrum_fx, exc_diffQ, L_FRAME ); + Copy(hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame_fx); - FOR( i=0; iL_frame_fx; i++ ) { - st_fx->Last_GSC_spectrum_fx[i] = mult_r(st_fx->Last_GSC_spectrum_fx[i],24576); /*Q10*/ move16(); + hGSCDec->Last_GSC_spectrum_fx[i] = mult_r(hGSCDec->Last_GSC_spectrum_fx[i],24576); /*Q10*/ move16(); } } @@ -519,15 +686,34 @@ void gsc_dec_fx( * PVQ decoder *--------------------------------------------------------------------------------------*/ - bands_and_bit_alloc_fx( st_fx->cor_strong_limit_fx, st_fx->noise_lev_fx, st_fx->core_brate_fx, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth_fx, st_fx->GSC_noisy_speech_fx ); - - pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig(concat_out, gsc_sfm_end[nb_subbands-1], sub(Q_PVQ_OUT, Q_tmp)); + bands_and_bit_alloc_fx(hGSCDec->cor_strong_limit_fx, hGSCDec->noise_lev_fx, st_fx->core_brate_fx, Diff_len, bit, &bit, Ener_per_bd_iQ, + max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth_fx, st_fx->GSC_noisy_speech_fx, + st_fx->L_frame_fx, st_fx->element_mode, st_fx->GSC_IVAS_mode ); +#ifdef ADD_LRTD + if (bit == 0) + { + set16_fx(concact_out, 0, L_FRAME16k); + } +#endif + { + pvq_core_dec_fx(st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE); + Scale_sig(concat_out, gsc_sfm_end[nb_subbands - 1], sub(Q_PVQ_OUT, Q_tmp)); + } seed_init = 0; move16(); +#ifdef ADD_LRTD + max_eq = 0.0f; + max_eq_val = 1.0f; + + if (((st_fx->core_brate < ACELP_7k20 && st_fx->GSC_noisy_speech == 1) || st_fx->core_brate < 6000) && coder_type <= UNVOICED) + { + j = emaximum(concat_out, nb_subbands * 16, &max_eq); + max_eq = (float)(max_eq_val / (fabs(concat_out[j]) + 0.01f)); + max_eq = min(max_eq_val, max_eq); + } +#endif /* Reorder Q bands */ FOR(j = 0; j < nb_subbands; j++) { @@ -558,7 +744,7 @@ void gsc_dec_fx( } } - st_fx->seed_tcx_fx = seed_init; + hGSCDec->seed_tcx_fx = seed_init; move16(); } test(); @@ -577,25 +763,47 @@ void gsc_dec_fx( } } - Copy( exc_diffQ, st_fx->Last_GSC_spectrum_fx, L_FRAME ); + Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame_fx ); /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ - freq_dnw_scaling_fx( st_fx->cor_strong_limit_fx, coder_type, st_fx->noise_lev_fx, st_fx->core_brate_fx, exc_diffQ, Qexc_diffQ ); +#ifdef ADD_LRTD + test(); test(); test(); test(); test(); test(); + IF (GE_16(st_fx->GSC_IVAS_mode, 1) && EQ_16(st_fx->GSC_noisy_speech, 1)) + { + FOR (i = 64; i < st_fx->L_frame; i++) + { + PMT("GSC FIX point to be done here") + exc_diffQ[i] *= max_eq; + } + } + ELSE IF (((LT_32(st_fx->core_brate, ACELP_7k20) && EQ_16(st_fx->GSC_noisy_speech, 1) ) || LT_32(st_fx->core_brate, 6000) ) && LE_16(st_fx->coder_type, UNVOICED)) + { + FOR (i = 0; i < L_FRAME; i++) + { + PMT("GSC FIX point to be done here") + exc_diffQ[i] *= max_eq; + } + } + else +#endif + { + freq_dnw_scaling_fx(hGSCDec->cor_strong_limit_fx, st_fx->coder_type_fx, hGSCDec->noise_lev_fx, st_fx->core_brate_fx, exc_diffQ, Qexc_diffQ, st_fx->L_frame_fx); + } } /*--------------------------------------------------------------------------------------* * Estimate noise level *--------------------------------------------------------------------------------------*/ - highband_exc_dct_in_fx( st_fx->core_brate_fx, mfreq_bindiv_loc, *last_bin, Diff_len, st_fx->noise_lev_fx, pit_band_idx, exc_diffQ, - &st_fx->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type_fx, bitallocation_band, lsf_new, - st_fx->last_exc_dct_in_fx, &st_fx->last_ener_fx, st_fx->last_bitallocation_band_fx, bitallocation_exc, st_fx->bfi_fx, coder_type, - st_fx->bwidth_fx, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech_fx - ,st_fx->lt_ener_per_band_fx + highband_exc_dct_in_fx( st_fx->core_brate_fx, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev_fx, pit_band_idx, exc_diffQ, + &hGSCDec->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type_fx, bitallocation_band, lsf_new, + hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band_fx, bitallocation_exc, st_fx->bfi_fx, coder_type, + st_fx->bwidth_fx, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech_fx, hGSCDec->lt_ener_per_band_fx + , st_fx->L_frame_fx, st_fx->element_mode, st_fx->GSC_IVAS_mode ); exc_dct_in[0] = 0; @@ -604,3 +812,42 @@ void gsc_dec_fx( return; } +/*-------------------------------------------------------------------* +* GSC_dec_init() +* +* Initialize GSC decoder state structure +*-------------------------------------------------------------------*/ + +void GSC_dec_init( + GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ +) +{ + hGSCDec->seed_tcx_fx = 15687; + hGSCDec->cor_strong_limit_fx = 1; + move16(); + move16(); + + hGSCDec->noise_lev_fx = NOISE_LEVEL_SP0; + hGSCDec->Last_GSC_pit_band_idx_fx = 0; + move16(); + move16(); + +#ifdef ADD_LRTD + set16_fx(hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k); + set16_fx(hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k); + set16_fx(hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN_BITALLOC16k); + set16_fx(hGSCDec->old_y_gain_fx, 0, MBANDS_GN_BITALLOC16k); +#else + set16_fx(hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME); + set16_fx(hGSCDec->last_exc_dct_in_fx, 0, L_FRAME); + set16_fx(hGSCDec->old_y_gain_fx, 0, MBANDS_GN); + set16_fx(hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN);/*Q12*/ +#endif + hGSCDec->last_ener_fx = 0; + move16(); + set16_fx(hGSCDec->last_bitallocation_band_fx, 0, 6); + + hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); + return; +} diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index 4501f4b..21b0942 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" #include "rom_dec_fx.h" -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------*/ /* Function hdecnrm_fx */ @@ -14,9 +13,9 @@ /* Huffman decoding for indices of quantized norms */ /*--------------------------------------------------------------------------*/ void hdecnrm_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* (i) number of norms */ - Word16 *index) /* (o) indices of quantized norms */ + Decoder_State_fx *st_fx,/* i/o: decoder state structure */ + const Word16 numNorms, /* i : number of norms */ + Word16 *index) /* o : indices of quantized norms */ { Word16 i, j, k, n, m; Word16 temp; diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index c9013f4..a3d916d 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -1,14 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" #include "basop32.h" -#include "cnst_fx.h" /*---------------------------------------------------------------------* * Local constants @@ -18,23 +16,19 @@ #define L_SUBFR32k 160 /*---------------------------------------------------------------------* - * Local functions + * Local function prototypes *---------------------------------------------------------------------*/ static void filt_6k_7k_scale_fx(Word16 signal[], Word16 lg, Word16 mem[], Word16 fact, Word16 exp); -static void hf_synthesis_fx( const Word32 core_brate, const Word16 output_subfr,const Word16 Aq[], - const Word16 exc[], const Word16 Q_exc,Word16 synth[],Word16 synth16k[],Word16 *seed2, Word16 *mem_hp400,Word16 *mem_syn_hf, - Word16 *mem_hf, const Word16 Q_syn,Word16 *delay_syn_hf,Word16 *memExp1,Word16 *mem_hp_interp, const Word16 extl, const Word16 CNG_mode ); - +static void hf_synthesis_fx(ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr,const Word16 Aq[], + const Word16 exc[], const Word16 Q_exc,Word16 synth[],Word16 synth16k[] + , const Word16 Q_syn, Word16* delay_syn_hf, Word16 *memExp1, Word16* mem_hp_interp, const Word16 extl, const Word16 CNG_mode ); static void hf_synthesis_amr_wb_fx( const Word32 core_brate, const Word16 output_subfr, const Word16 Ap[], Word16 exc16k[], Word16 synth_out[], Word16 *mem_syn_hf, Word16 *delay_syn_hf, Word16 *mem_hp_interp, Word16 p_r, Word16 HF_corr_gain, Word16 til, Word16 voice_factors, const Word16 exc[], const Word16 Q_exc, const Word16 Q_out, Word16 qhf ); - -static void envelope_fx( const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, - Word16 voice_factor, Word16 *prev_r, Word16 *voice_fac, Word16 *unvoicing, Word16 *unvoicing_sm, Word16 *unvoicing_flag); - +static void envelope_fx(AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, Word16 voice_factor); static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const Word16 *lsf, const Word16 voicing_fac, const Word16 clas, Word16 *voicing_flag, Word16 *start_band_old, Word32 *OptCrit_old ); @@ -48,47 +42,35 @@ static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const * - initialization of band pass 6kHz to 7kHz FIR filter *-------------------------------------------------------------------*/ void hf_synth_init_fx( - Word16 mem_hp400[], /* o : 400 Hz high pass filter memory initialization */ - Word16 mem_hf[] /* o : band pass 6kHz to 7kHz FIR filter initialization */ + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) { - Word16 i; - - FOR (i=0; i<6; i++) - { - mem_hp400[i] = 0; - move16(); - } - FOR(i=0; i<2*L_FILT16k; i++) - { - mem_hf[i] = 0; - move16(); - } + hBWE_zero->seed2_fx = RANDOM_INITSEED; + set16_fx(hBWE_zero->mem_hf_fx, 0, 2 * L_FILT16k); + set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); + set16_fx(hBWE_zero->mem_hp400_fx, 0, 4); + set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); + set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); return; } void hf_synth_reset_fx( - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 mem_hf[], /* o : HF band-pass filter memory */ - Word16 mem_syn_hf[], /* o : HF synthesis memory */ - Word16 mem_hp400[], /* o : memory of hp 400 Hz filter */ - Word16 mem_hp_interp[], /* o : interpol. memory */ - Word16 delay_syn_hf[] /* o : HF synthesis memory */ + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) { Word16 i; - FOR( i=0; iseed2_fx); } - set16_fx( mem_hf, 0, 2*L_FILT16k ); - set16_fx( mem_syn_hf, 0, M ); - set16_fx( mem_hp400, 0, 4 ); - set16_fx( delay_syn_hf, 0, NS2SA(16000,DELAY_CLDFB_NS) ); - set16_fx( mem_hp_interp, 0, INTERP_3_1_MEM_LEN ); + set16_fx(hBWE_zero->mem_hf_fx, 0, 2 * L_FILT16k); + set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); + set16_fx(hBWE_zero->mem_hp400_fx, 0, 4); + set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); + set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); return; } @@ -100,21 +82,18 @@ void hf_synth_reset_fx( *---------------------------------------------------------------------*/ void hf_synth_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ + const Word16 output_frame, /* i : output frame length */ const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory */ - Word16 *mem_hf, /* i/o: HF band-pass filter memory */ + const Word16 *exc, /* i : excitation at 12.8 kHz */ + Word16 *synth, /* i : 12.8kHz synthesis signal */ + Word16 *synth16k, /* o : 16kHz synthesis signal */ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ - Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *memExp1, /* o : HF excitation exponent */ + Word16 *mem_hp_interp, /* i/o: interpol. memory */ const Word16 extl, /* i : flag indicating BWE */ const Word16 CNG_mode /* i : CNG_mode */ ) @@ -129,8 +108,7 @@ void hf_synth_fx( move16(); FOR( i_subfr=0; i_subfrseed2_fx, L_SUBFR16k, HF_exc, 3); /* 3 = Shift Right by 3 */ + /* o: HF_exc in Q-3 */ /*-----------------------------------------------------------------* @@ -223,7 +199,7 @@ static void hf_synthesis_fx( * (tilt: 1=voiced, -1=unvoiced) *-----------------------------------------------------------------*/ - hp400_12k8_fx( synth, L_SUBFR, mem_hp400 ); + hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); /* i: mem_hp400 in Q_syn */ /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ @@ -277,7 +253,7 @@ static void hf_synthesis_fx( * high pass filtering (0.94ms of delay) *-----------------------------------------------------------------*/ - filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, mem_hf,tmp,exp2 ); + filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx,tmp,exp2 ); /* i: input HF_exc is scaled in float, here scaling is done inside this filter */ /* i: mem_hf in Q-2 */ /* o: HF_exc in Q0 */ @@ -290,8 +266,7 @@ static void hf_synthesis_fx( weight_a_lc_fx(Aq, Ap, Gamma_19661_Tbl_fx, M); /* o: Ap in Q14 */ - Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, mem_syn_hf, 1 ); - + Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, hBWE_zero->mem_syn_hf_fx, 1 ); /* i: Ap in Q14 */ /* i: HF_exc in Q0 */ /* o: HF_syn in Q0 */ @@ -319,7 +294,7 @@ static void hf_synthesis_fx( sub(Find_Max_Norm16(mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3), 1)), 0 ); Scale_sig(HF_syn, L_SUBFR16k, s); Scale_sig(mem_hp_interp, INTERP_3_1_MEM_LEN, s); - interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp, allpass_poles_3_ov_2 ); + interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp); Scale_sig(upsampled_HF_syn, 3*L_SUBFR16k, -s); Scale_sig(mem_hp_interp, INTERP_3_1_MEM_LEN, -s); Scale_sig(HF_syn, L_SUBFR16k, -s); @@ -401,110 +376,83 @@ static void filt_6k_7k_scale_fx( *-------------------------------------------------------------------*/ void hf_synth_amr_wb_init_fx( - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 mem_syn_hf_fx[], /* HF LPC synthesis filter initialization */ - Word16 *frame_count, /* o : frame counter initialization */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy initialization*/ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor initialization */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ ) { - *prev_r = 0; + hAmrwb_IO->prev_r_fx = 0; move16(); - set16_fx( mem_syn_hf_fx, 0, M ); - *fmerit_w_sm = 0; + hAmrwb_IO->fmerit_w_sm_fx = 0; move16(); - *frame_count = 0; + hAmrwb_IO->frame_count_fx = 0; move16(); - *ne_min = -7680; + hAmrwb_IO->ne_min_fx = -7680; move16(); /*Q8*/ - *fmerit_m_sm = 0; + hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); - *voice_fac = 0; + hAmrwb_IO->voice_fac_amr_wb_hf = 0; move16(); - *unvoicing = 0; + hAmrwb_IO->unvoicing_fx = 0; move16(); - *unvoicing_sm = 32767; + hAmrwb_IO->unvoicing_sm_fx = 32767; move16(); /*Q15*/ - *unvoicing_flag = 0; + hAmrwb_IO->unvoicing_flag_fx = 0; move16(); - *voicing_flag = 0; + hAmrwb_IO->voicing_flag_fx = 0; move16(); - *start_band_old = 160; + hAmrwb_IO->start_band_old_fx = 160; move16(); - *OptCrit_old = 32768; - move32(); /*Q15*/ ; + hAmrwb_IO->OptCrit_old_fx = 32768; + move32(); /*Q15*/; return; } + /*-------------------------------------------------------------------* * hf_synth_amr_wb_reset() * * reset of HF synthesis filters * - needed in switching scenarios *-------------------------------------------------------------------*/ - void hf_synth_amr_wb_reset_fx( - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 mem_syn_hf[], /* o : HF synthesis memory */ - Word16 mem_hp_interp[], /* o : interpol. memory */ - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 delay_syn_hf[], /* o : HF synthesis memory */ - Word16 *frame_count, /* o : frame counter memory */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy memory */ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor memory */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ ) { Word16 i; - FOR( i=0; iseed2_fx); } - set16_fx( mem_syn_hf, 0, M ); - set16_fx( delay_syn_hf, 0, NS2SA(16000,DELAY_CLDFB_NS) ); - set16_fx( mem_hp_interp, 0, INTERP_3_1_MEM_LEN ); + set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); + set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); + set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); - *prev_r = 0; + hAmrwb_IO->prev_r_fx = 0; move16(); - *fmerit_w_sm = 0; + hAmrwb_IO->fmerit_w_sm_fx = 0; move16(); - *frame_count = 0; + hAmrwb_IO->frame_count_fx = 0; move16(); - *ne_min = -7680; + hAmrwb_IO->ne_min_fx = -7680; move16(); /*Q8*/ - *fmerit_m_sm = 0; + hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); - *voice_fac = 0; + hAmrwb_IO->voice_fac_amr_wb_hf = 0; move16(); - *unvoicing = 0; + hAmrwb_IO->unvoicing_fx = 0; move16(); - *unvoicing_sm = 32767; + hAmrwb_IO->unvoicing_sm_fx = 32767; move16(); /*Q15*/ - *unvoicing_flag = 0; + hAmrwb_IO->unvoicing_flag_fx = 0; move16(); - *voicing_flag = 0; + hAmrwb_IO->voicing_flag_fx = 0; move16(); - *start_band_old = 160; + hAmrwb_IO->start_band_old_fx = 160; move16(); - *OptCrit_old = 32768; + hAmrwb_IO->OptCrit_old_fx = 32768; move32(); /*Q15*/ return; @@ -517,17 +465,14 @@ void hf_synth_amr_wb_reset_fx( *-------------------------------------------------------------------*/ void hf_synth_amr_wb_fx( + AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ const Word32 core_brate, /* i : core bitrate */ const Word16 output_frame, /* i : output frame length */ const Word16 *Aq, /* i : quantized Az : Q12 */ const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out */ - Word16 *prev_r, /* i/o : previous sub-frame gain : Q10 */ - Word16 *fmerit_w_sm, /* i/o: smoothed fmerit_w : Q14 */ Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out */ Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ Word16 fmerit, /* i : classify parameter from FEC : Q14 */ const Word16 *hf_gain, /* i : decoded HF gain */ @@ -535,16 +480,6 @@ void hf_synth_amr_wb_fx( const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ const Word16 *lsf_new, /* i : ISF vector : Q2 */ - Word16 *frame_count, /* i/o: frame counter */ - Word16 *ne_min, /* i/o: minimum Noise gate : Q8 */ - Word16 *fmerit_m_sm, /* i/o: smoothed fmerit_m : Q14 */ - Word16 *voice_facor_sm, /* o : voice factor memory : Q15 */ - Word16 *unvoicing, /* o : unvoiced parameter : Q15 */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter : Q15 */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old, /* o : previous criterion value for deciding the start point */ const Word16 Q_exc, /* i : exc scaling */ const Word16 Q_out /* i : Q_syn2-1 */ ) @@ -579,7 +514,6 @@ void hf_synth_amr_wb_fx( Word16 e_subfr1, e_subfr2; Word32 exc32[L_FRAME], dct_exc32[L_FRAME], dct_hb32[L_FRAME16k], exc16k32[L_FRAME16k]; Word16 q_tmp; - Word16 gamma; Scale_sig(synth, L_FRAME, -3); @@ -627,28 +561,19 @@ void hf_synth_amr_wb_fx( pitch_var_cur = add(pitch_var_cur, shr(tmp1,1)); /*Q6 -> Q5 */ } test(); - IF( GT_16(*frame_count, FRAME_COUNT)&&*amr_io_class==UNVOICED_CLAS) + IF( GT_16(hAmrwb_IO->frame_count_fx, FRAME_COUNT) && *amr_io_class == UNVOICED_CLAS) { - *frame_count = 0; + hAmrwb_IO->frame_count_fx = 0; + hAmrwb_IO->ne_min_fx = -7680; move16(); - *ne_min = -7680; move16();/*Q8; */ } ELSE { - tmp1 = *frame_count; move16(); - *frame_count = add(*frame_count ,1); - if(GT_16(tmp1, 2*FRAME_COUNT)) - { - *frame_count = 2*FRAME_COUNT; - move16(); - } - if ( LT_16(ng_ener_ST, *ne_min)) - { - *ne_min = ng_ener_ST; - move16();/*Q8; */ - } + hAmrwb_IO->frame_count_fx = s_min(hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT-1); + hAmrwb_IO->frame_count_fx = add(hAmrwb_IO->frame_count_fx, 1); + hAmrwb_IO->ne_min_fx = s_min(hAmrwb_IO->ne_min_fx, ng_ener_ST); } pt6 = voice_factors; @@ -673,8 +598,9 @@ void hf_synth_amr_wb_fx( L_tmp = L_mult(fmerit_w, add(16384, voice_fac)); fmerit_w = extract_l(L_shr(L_tmp, 15)); /*Q14 */ /**fmerit_w_sm = add(mult_r(*fmerit_w_sm, 29491), mult_r(fmerit_w, 3277)); //Q14 */ - *fmerit_w_sm = round_fx(L_mac(L_mult(*fmerit_w_sm, 29491), fmerit_w, 3277)); /*Q14 */ - fmerit_w = *fmerit_w_sm; + hAmrwb_IO->fmerit_w_sm_fx = round_fx(L_mac(L_mult(hAmrwb_IO->fmerit_w_sm_fx, 29491), fmerit_w, 3277)); /*Q14 */ + fmerit_w = hAmrwb_IO->fmerit_w_sm_fx; + move16(); tmp1 = fmerit; @@ -685,8 +611,8 @@ void hf_synth_amr_wb_fx( move16(); } fmerit_m = negate(add(-32768, tmp1)); - *fmerit_m_sm = add(shr(*fmerit_m_sm, 1), shr(fmerit_m, 1)); /*Q14 */ - fmerit_m = *fmerit_m_sm; + hAmrwb_IO->fmerit_m_sm_fx = add(shr(hAmrwb_IO->fmerit_m_sm_fx, 1), shr(fmerit_m, 1)); /*Q14 */ + fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; move16(); pt1 = til; @@ -703,7 +629,7 @@ void hf_synth_amr_wb_fx( tmp1 = sub(8192, *pt1); *pt1 = s_max(6554, tmp1); move16(); - tmp1 = add(*ne_min, 7680); /*Q8 */ + tmp1 = add(hAmrwb_IO->ne_min_fx, 7680); /*Q8 */ tmp1 = mult_r(tmp1, 7340); /*Q20 - > 0.007 //Q13 */ *pt1 = add(*pt1, tmp1); move16();/*Q13 */ @@ -720,8 +646,7 @@ void hf_synth_amr_wb_fx( pt6 = voice_factors; FOR( i = 0; i < NB_SUBFR; i++ ) { - envelope_fx( core_brate, p_Aq, p_Ap, pt1, *pt2, *pt3, *pt6, prev_r, - voice_facor_sm, unvoicing, unvoicing_sm, unvoicing_flag ); + envelope_fx(hAmrwb_IO, core_brate, p_Aq, p_Ap, pt1, *pt2, *pt3, *pt6); pt1++; pt2++; pt3++; @@ -731,8 +656,7 @@ void hf_synth_amr_wb_fx( p_Ap += (M+1); } - AdaptiveStartBand_fx( &start_band, core_brate, lsf_new, voice_fac, *amr_io_class, voicing_flag, start_band_old, OptCrit_old ); - + AdaptiveStartBand_fx( &start_band, core_brate, lsf_new, voice_fac, *amr_io_class, &hAmrwb_IO->voicing_flag_fx, &hAmrwb_IO->start_band_old_fx, &hAmrwb_IO->OptCrit_old_fx ); q_tmp = Exp16Array(L_FRAME, exc); qdct = sub(q_tmp, 1); @@ -949,7 +873,7 @@ void hf_synth_amr_wb_fx( { *pt1 = mult_r(*pt1, scale); /*qdct */ move16(); - IF ( GE_16(i, sub(320, filt_weight_coeff))) + IF ( GE_16(i, sub(L_FRAME16k, filt_weight_coeff))) { *pt1 = round_fx(L_shl(L_mult(*pt3, *pt1), 1)); /*qdct */ } @@ -988,7 +912,7 @@ void hf_synth_amr_wb_fx( move16(); } - IF ( GE_16(i, sub(320, filt_weight_coeff))) + IF ( GE_16(i, sub(L_FRAME16k, filt_weight_coeff))) { *pt1 = round_fx(L_shl(L_mult(*pt3, *pt1), 1)); /*qdct */ } @@ -1069,9 +993,8 @@ void hf_synth_amr_wb_fx( FOR( i = 0; i < NB_SUBFR; i++ ) { - hf_synthesis_amr_wb_fx( core_brate, output_subfr, p_Ap, pt1, pt2, - mem_syn_hf, delay_syn_hf, mem_hp_interp, *pt3, *pt4, *pt5, *pt6, pt7, - Q_exc, Q_out, qhf); + hf_synthesis_amr_wb_fx( core_brate, output_subfr, p_Ap, pt1, pt2, hBWE_zero->mem_syn_hf_fx, hBWE_zero->delay_syn_hf_fx, + hBWE_zero->mem_hp_interp_fx, *pt3, *pt4, *pt5, *pt6, pt7, Q_exc, Q_out, qhf); p_Ap += (M+1); pt1 += L_SUBFR16k; pt2 += output_subfr; @@ -1103,9 +1026,8 @@ static void hf_synthesis_amr_wb_fx( Word16 qhf /*exc16k scaling*/ ) { - Word16 i, delay; + Word16 i; Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_SUBFR48k]; - Word16 temp_buffer[NS2SA(16000,DELAY_CLDFB_NS)]; Word16 ener, tmp, scale, exc2385[L_SUBFR16k]; Word32 L_tmp; Word16 q1, q2,q3, shift; @@ -1203,13 +1125,7 @@ static void hf_synthesis_amr_wb_fx( * Synchronize LB and HB components (delay componsation) * Add synthesised high band to speech synthesis *-----------------------------------------------------------------*/ - - /* compensate CLDFB resampling delay */ - delay = NS2SA(16000,DELAY_CLDFB_NS); - Copy( HF_syn+L_SUBFR16k-delay, temp_buffer, delay ); - Copy( HF_syn, HF_syn+delay, L_SUBFR16k-delay ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); + delay_signal(HF_syn, L_SUBFR16k, delay_syn_hf, NS2SA(16000, DELAY_CLDFB_NS)); IF( EQ_16(output_subfr, L_SUBFR48k)) /* 48kHz sampled output */ { @@ -1219,7 +1135,7 @@ static void hf_synthesis_amr_wb_fx( Scale_sig( HF_syn, L_SUBFR16k, s ); Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); - interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp, allpass_poles_3_ov_2 ); + interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp); Scale_sig( upsampled_HF_syn, L_SUBFR48k, add(-s,-1) ); Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); @@ -1309,18 +1225,14 @@ static Word16 EnhanceClass_fx( } static void envelope_fx( + AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, /* i : core bitrate */ const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ Word16 Ap[], /* o : extended LPC coefficents, Q12 */ Word16 *sub_gain, /* o : sub-frame gain, Q12 */ Word16 tilt0, /* i : spectrum tilt, Q14 */ Word16 tilt, /* i : spectrum tilt, Q13 */ - Word16 voice_factor, /* i : voice factor, Q15 */ - Word16 *prev_r, /* i/o: previous sub-frame gain, Q10 */ - Word16 *voice_fac, /* i/o: smoothed voiced parameter, Q15 */ - Word16 *unvoicing, /* i/o: unvoiced parameter, Q15 */ - Word16 *unvoicing_sm, /* i/o: smoothed unvoiced parameter, Q15*/ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ + Word16 voice_factor /* i : voice factor, Q15 */ ) { @@ -1535,18 +1447,17 @@ static void envelope_fx( L_tmp = L_mac(L_tmp, qy, qy); qq = round_fx(Isqrt(L_shr(L_tmp, add(11, shl(q1, 1))))); /*Q10*/ - Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, voice_fac, unvoicing, unvoicing_sm, unvoicing_flag ); - + Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); alpha = 0; move16(); IF ( Unvoicing_flag ) { - IF ( GT_16(rr, (*prev_r))) + IF ( GT_16(rr, (hAmrwb_IO->prev_r_fx))) { - rr = shr(add(rr, (*prev_r)), 1); + rr = shr(add(rr, (hAmrwb_IO->prev_r_fx)), 1); } - *prev_r = rr; + hAmrwb_IO->prev_r_fx = rr; move16(); L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ @@ -1565,18 +1476,18 @@ static void envelope_fx( ELSE { test(); - IF ( LT_16(rr, 1024)&<_16((*prev_r),1024)) + IF ( LT_16(rr, 1024)&<_16((hAmrwb_IO->prev_r_fx),1024)) { L_tmp = L_mult(rr, rr); /*Q21*/ tmp = round_fx(L_shl(L_tmp, 9)); /*Q14*/ L_tmp = L_sub(2097152, L_tmp); /*Q21*/ alpha = round_fx(L_shl(L_tmp, 9)); /*Q14*/ - L_tmp = L_mult(alpha, (*prev_r)); /*Q25*/ + L_tmp = L_mult(alpha, (hAmrwb_IO->prev_r_fx)); /*Q25*/ L_tmp = L_mac(L_tmp, tmp, rr); /*Q25*/ rr = round_fx(L_shl(L_tmp, 1)); /*Q10*/ } - *prev_r = rr; + hAmrwb_IO->prev_r_fx = rr; move16(); L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ @@ -1617,7 +1528,7 @@ static void envelope_fx( void AdaptiveStartBand_fx( Word16 *start_band, /* o : start point of copied band */ - const Word32 rate, /* i : core bitrate */ + const Word32 core_rate, /* i : core bitrate */ const Word16 *lsf_fx, /* i : Q2 lsf frequency */ const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ @@ -1653,10 +1564,10 @@ void AdaptiveStartBand_fx( move16(); } - /* rate adaptive start band */ + /* core_rate adaptive start band */ *start_band = 160; move16(); - IF( LT_32(rate, ACELP_23k05)) + IF( LT_32(core_rate, ACELP_23k05)) { pt1 = lsf_diff_fx+1; pt2 = lsf_fx+1; @@ -1666,7 +1577,7 @@ void AdaptiveStartBand_fx( *pt1++ = sub(*pt2++, *pt3++); move16();/*Q2 */ } - tmp1 = extract_l(Mult_32_16(rate, 27046)); /*Q14 */ + tmp1 = extract_l(Mult_32_16(core_rate, 27046)); /*Q14 */ L_tmp = L_shr(L_mult0(tmp1, 22370), 15); /*Q27->1/6000 ->Q26 */ tmp2 = extract_l(L_tmp); /*Q26 */ W_fx = mult_r(tmp1, tmp2); /*Q25 */ @@ -1681,15 +1592,15 @@ void AdaptiveStartBand_fx( M2 = sub(M, 2); IF( EQ_16(*voicing_flag,1)) { - IF( LE_32(rate, ACELP_8k85)) + IF( LE_32(core_rate, ACELP_8k85)) { M2 = sub(M, 8); } - ELSE IF( LE_32(rate, ACELP_12k65)) + ELSE IF( LE_32(core_rate, ACELP_12k65)) { M2 = sub(M, 6); } - ELSE IF( LE_32(rate, ACELP_15k85)) + ELSE IF( LE_32(core_rate, ACELP_15k85)) { M2 = sub(M, 4); } diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index 28813e7..69390c7 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -1,10 +1,9 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* * hq_classifier_dec() @@ -12,31 +11,46 @@ * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ -Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : Core bit rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - Word16 *is_transient, /* o : Transient flag Q0 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ +Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : Core bit rate Q0 */ + const Word16 length, /* i : Frame length Q0 */ + Word16 *is_transient, /* o : Transient flag Q0 */ + Word16 *hqswb_clas /* o : HQ class Q0 */ ) { Word16 bits; + Word32 max_brate; + max_brate = HQ_32k; + move32(); + if (GT_16(st_fx->element_mode, EVS_MONO)) + { + max_brate = HQ_48k; + move32(); + } +#ifndef SOLVED_COMP_ENC_DEC + IF((EQ_16(length, L_SPEC32k) || EQ_16(length, L_FRAME48k)) && LE_32(core_brate, max_brate)) +#else + /*_DIFF_FLOAT_FIX_ -> could this modification break the interoperability with EVS ?? */ test(); - IF ( GE_16(length, L_FRAME32k)&&LE_32(core_brate,HQ_32k)) + IF ((EQ_16(length, L_SPEC32k) || EQ_16(length, L_SPEC48k)) && LE_32(core_brate, max_brate)) +#endif { *hqswb_clas = get_next_indice_fx( st_fx, 2 ); + bits = 2; move16(); - test(); - if (( EQ_16(length, L_FRAME48k))&&(EQ_16(*hqswb_clas,HQ_NORMAL))) - { - *hqswb_clas = HQ_GEN_FB; - move16(); - } + } + ELSE IF( EQ_16(length, L_SPEC16k_EXT) || EQ_16(length, L_SPEC48k_EXT) ) + { + *hqswb_clas = HQ_NORMAL; + bits = 0; + move16(); move16(); } ELSE { *hqswb_clas = get_next_indice_fx( st_fx, 1 ); + bits = 1; move16(); } @@ -49,20 +63,23 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 } test(); - test(); - if ( *hqswb_clas == HQ_NORMAL && EQ_16(length, L_FRAME32k)&&LE_32(core_brate,HQ_32k)) + IF (LE_32(st_fx->core_brate_fx, HQ_32k) && EQ_16(*hqswb_clas, HQ_NORMAL)) { - *hqswb_clas = HQ_GEN_SWB; - move16(); - } - - bits = 1; - move16(); - test(); - if ( GE_16(length, L_FRAME32k)&&LE_32(core_brate,HQ_32k)) - { - bits = 2; move16(); + IF (EQ_16(length, L_SPEC32k) ) + { + *hqswb_clas = HQ_GEN_SWB; + move16(); + } +#ifndef SOLVED_COMP_ENC_DEC + ELSE IF (EQ_16(length, L_FRAME48k)) +#else + ELSE IF (EQ_16(length, L_SPEC48k)) +#endif + { + *hqswb_clas = HQ_GEN_FB; + move16(); + } } return bits; diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index eb50364..d5af8ba 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" #include "cnst_fx.h" -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* @@ -19,9 +18,9 @@ void hq_configure_bfi_fx( Word16 *nb_sfm, /* o : Number of sub bands Q0 */ Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths */ - Word16 const **sfm_start, /* o : Subband start coefficients */ - Word16 const **sfm_end /* o : Subband end coefficients */ + const Word16 **sfmsize, /* o : Subband bandwidths */ + const Word16 **sfm_start, /* o : Subband start coefficients */ + const Word16 **sfm_end /* o : Subband end coefficients */ ) { *num_Sb = MAX_SB_NB; @@ -32,8 +31,8 @@ void hq_configure_bfi_fx( *sfmsize = band_len_wb; *sfm_start = band_start_wb; *sfm_end = band_end_wb; - - - + move16(); + move16(); + move16(); return; } diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 8380f04..fa501f6 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*-------------------------------------------------------------------------- * hq_core_dec() * @@ -26,7 +25,7 @@ void hq_core_dec_fx( Word16 i, j, flag_uv, num_Sb, nb_sfm; Word16 ynrm[NB_SFM], num_bands_p[MAX_SB_NB]; Word16 ener_match; /* Q13 */ - Word32 t_audio_q[L_FRAME48k]; /* Q12 */ + Word32 t_audio_q[L_FRAME48k_EXT]; /* Q12 */ Word16 Q_audio; Word32 wtda_audio[2*L_FRAME48k]; Word16 delay_comp; @@ -38,12 +37,17 @@ void hq_core_dec_fx( Word16 tmp, tmp_loop; Word32 L_tmp; UWord16 lsb; + Word16 L_spec; + HQ_NBFEC_HANDLE hHQ_nbfec; + HQ_DEC_HANDLE hHQ_core; + hHQ_nbfec = st_fx->hHQ_nbfec; + hHQ_core = st_fx->hHQ_core; /*-------------------------------------------------------------------------- * Initializations *--------------------------------------------------------------------------*/ - set32_fx( t_audio_q, 0, L_FRAME48k ); + set32_fx( t_audio_q, 0, L_FRAME48k_EXT); set16_fx( gapsynth_fx, 0, L_FRAME48k ); set16_fx( num_bands_p, 0, MAX_SB_NB ); set16_fx( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */ @@ -54,16 +58,15 @@ void hq_core_dec_fx( sfm_start = sfm_end = NULL; num_Sb = nb_sfm = 0; - st_fx->tcx_cfg.tcx_last_overlap_mode = st_fx->tcx_cfg.tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; move16(); - if (EQ_16(st_fx->tcx_cfg.tcx_curr_overlap_mode, FULL_OVERLAP)) + if (EQ_16(st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP)) { - st_fx->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); } - st_fx->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); - /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding *--------------------------------------------------------------------------*/ @@ -73,40 +76,58 @@ void hq_core_dec_fx( Mpy_32_16_ss(st_fx->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l(L_shr(L_tmp, 3)); /*Q0 */ +#ifdef ADD_IVAS_HQ_CODE_L_SPEC + /* Set default spectrum length */ + L_spec = l_spec_tbl[st_fx->bwidth_fx]; +#endif IF( !st_fx->bfi_fx ) { IF ( EQ_16(core_switching_flag, 1)) { - core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame ); - - /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - if ( GT_16(num_bits, HQ_48k / 50)) +#ifdef ADD_IVAS_HQ_CODE_L_SPEC + IF (NE_16(st_fx->element_mode, EVS_MONO)) { - num_bits = (Word16)(HQ_48k / 50); - move16(); + L_spec = l_spec_ext_tbl[st_fx->bwidth_fx]; } - } + ELSE +#endif + { + core_switching_hq_prepare_dec_fx(st_fx, &num_bits, output_frame); + /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ + if (GT_16(num_bits, HQ_48k / 50)) + { + num_bits = (Word16)(HQ_48k / 50); + move16(); + } + } + } +#ifdef ADD_IVAS_HQ_CODE + IF (hq_recovery_flag) + { + acelp_plc_mdct_transition(st); + } +#endif /* subtract signalling bits */ num_bits = sub(num_bits, st_fx->next_bit_pos_fx); /* set FEC parameters */ - flag_uv = sub(1, st_fx->HqVoicing_fx); + flag_uv = sub(1, hHQ_core->HqVoicing_fx); /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF ( !(core_switching_flag) && GT_32(st_fx->core_brate_fx, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) { - st_fx->HqVoicing_fx = get_next_indice_fx( st_fx, 1 ); + hHQ_core->HqVoicing_fx = get_next_indice_fx( st_fx, 1 ); num_bits = sub(num_bits, 1); } ELSE { - st_fx->HqVoicing_fx = 0; + hHQ_core->HqVoicing_fx = 0; move16(); if ( GT_32(st_fx->core_brate_fx, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) { - st_fx->HqVoicing_fx = 1; + hHQ_core->HqVoicing_fx = 1; move16(); } } @@ -119,15 +140,18 @@ void hq_core_dec_fx( /* set inner frame (== coded bandwidth) length */ inner_frame = inner_frame_tbl[st_fx->bwidth_fx]; +#ifndef ADD_IVAS_HQ_CODE_L_SPEC + L_spec = inner_frame; +#endif move16(); IF ( st_fx->bfi_fx == 0) { - st_fx->ph_ecu_HqVoicing_fx = 0; + hHQ_core->ph_ecu_HqVoicing_fx = 0; move16(); if ( GE_16(output_frame, L_FRAME16k)) { - st_fx->ph_ecu_HqVoicing_fx = st_fx->HqVoicing_fx; + hHQ_core->ph_ecu_HqVoicing_fx = hHQ_core->HqVoicing_fx; move16(); } } @@ -143,24 +167,24 @@ void hq_core_dec_fx( IF( EQ_16(st_fx->bfi_fx, 1)) { - is_transient = st_fx->old_is_transient_fx[0]; + is_transient = hHQ_core->old_is_transient_fx[0]; move16(); IF ( GE_16(output_frame, L_FRAME16k)) /* Apply phase ecu for WB, SWB and FB */ { /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ - hq_ecu_fx( st_fx->prev_good_synth_fx, t_audio_q, &st_fx->time_offs_fx, st_fx->X_sav_fx, &st_fx->Q_X_sav, &st_fx->num_p_fx, st_fx->plocs_fx, st_fx->plocsi_fx, st_fx->env_stab_fx, - &st_fx->last_fec_fx, st_fx->ph_ecu_HqVoicing_fx, &st_fx->ph_ecu_active_fx, gapsynth_fx, st_fx->prev_bfi_fx, st_fx->old_is_transient_fx, st_fx->mag_chg_1st_fx, - st_fx->Xavg_fx, &st_fx->beta_mute_fx, output_frame, st_fx ); + hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs_fx, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p_fx, hHQ_core->plocs_fx, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, + &hHQ_core->last_fec_fx, hHQ_core->ph_ecu_HqVoicing_fx, &hHQ_core->ph_ecu_active_fx, gapsynth_fx, st_fx->prev_bfi_fx, hHQ_core->old_is_transient_fx, hHQ_core->mag_chg_1st_fx, + hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); } ELSE { - HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, st_fx->ynrm_values_fx, st_fx->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, + HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, hHQ_nbfec->ynrm_values_fx, hHQ_nbfec->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, output_frame, sfm_start, sfm_end ); } - st_fx->old_is_transient_fx[2] = st_fx->old_is_transient_fx[1]; + hHQ_core->old_is_transient_fx[2] = hHQ_core->old_is_transient_fx[1]; move16(); - st_fx->old_is_transient_fx[1] = st_fx->old_is_transient_fx[0]; + hHQ_core->old_is_transient_fx[1] = hHQ_core->old_is_transient_fx[0]; move16(); IF ( GE_16(output_frame, L_FRAME16k)) @@ -173,8 +197,8 @@ void hq_core_dec_fx( flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - st_fx->HqVoicing_fx = sub(1, flag_uv); /* safety setting for HQ->ACELP switch logic */ - set16_fx( st_fx->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ + hHQ_core->HqVoicing_fx = sub(1, flag_uv); /* safety setting for HQ->ACELP switch logic */ + set16_fx(hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } ELSE @@ -183,15 +207,14 @@ void hq_core_dec_fx( { IF( EQ_16(st_fx->prev_bfi_fx, 1)) { - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse_fx = 0; move16(); } /* HQ low rate decoder */ - hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - + hq_lr_dec_fx(st_fx, t_audio_q, inner_frame, num_bits, &is_transient); hqswb_clas = is_transient; move16(); Q_audio = 12; @@ -200,32 +223,37 @@ void hq_core_dec_fx( ELSE { /* HQ high rate decoder */ - hq_hr_dec_fx(st_fx, t_audio_q, inner_frame, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx); + hq_hr_dec_fx(st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag); Q_audio = 12; move16(); } - /* scaling (coefficients are in nominal level) */ - IF( NE_16(output_frame, NORM_MDCT_FACTOR)) +#ifdef ADD_IVAS_HQ_CODE + test(); test(); test(); + IF (EQ_16(st_fx->element_mode, EVS_MONO) || (!core_switching_flag && !hq_recovery_flag)) +#endif { - IF (EQ_16(output_frame, L_FRAME32k)) - { - Q_audio = sub(Q_audio, 1); /* Multiply by 2 */ - } - ELSE + /* scaling (coefficients are in nominal level) */ + IF(NE_16(output_frame, NORM_MDCT_FACTOR)) { - tmp = mult_r(output_frame, 410/2); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; - FOR( i=0; i < inner_frame; i++ ) + IF(EQ_16(output_frame, L_FRAME32k)) { - /*t_audio_q[i] *= ener_match;*/ - Mpy_32_16_ss(t_audio_q[i], ener_match, &L_tmp, &lsb); /*12+13-15=10 */ - t_audio_q[i] = L_add(L_shl(L_tmp, 2), lshr(lsb, 14)); - move16(); /* Q12 */ + Q_audio = sub(Q_audio, 1); /* Multiply by 2 */ + } + ELSE + { + tmp = mult_r(output_frame, 410 / 2); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; + FOR(i = 0; i < inner_frame; i++) + { + /*t_audio_q[i] *= ener_match;*/ + Mpy_32_16_ss(t_audio_q[i], ener_match, &L_tmp, &lsb); /*12+13-15=10 */ + t_audio_q[i] = L_add(L_shl(L_tmp, 2), lshr(lsb, 14)); + move16(); /* Q12 */ + } } } } - HQ_FEC_Mem_update_fx( st_fx, t_audio_q, normq_fx, ynrm, num_bands_p, is_transient, hqswb_clas, core_switching_flag, nb_sfm, num_Sb, &mean_en_high_fx, hq_core_type, output_frame ); } @@ -285,48 +313,119 @@ void hq_core_dec_fx( * Overlap-add * Pre-echo reduction *--------------------------------------------------------------------------*/ +#ifdef ADD_IVAS_HQ_CODE + if (st->element_mode > EVS_MONO && (core_switching_flag || hq_recovery_flag)) + { + /* Initializations for TCX MDCT framework, to be used for switching frame */ + tcx_cfg = st->hTcxCfg; + L_frameTCX_glob = hTcxDec->L_frameTCX; + L_frame_glob = st->L_frame; + L_spec = hTcxDec->L_frameTCX; + st->fscale = sr2fscale(st->sr_core); + fscaleFB = sr2fscale(st->output_Fs); + encoderLookahead = (L_LOOK_12k8 * st->fscale) / FSCALE_DENOM; + encoderLookaheadFB = (L_LOOK_12k8 * fscaleFB) / FSCALE_DENOM; + mdctWindowLength = getMdctWindowLength(st->fscale); + mdctWindowLengthFB = (int16_t)(mdctWindowLength * st->output_Fs / st->sr_core); + if (core_switching_flag) + { + tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; + tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; + } + else + { + tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st->last_core = HQ_CORE; /* Needed to decode non-transition frame */ + } - test(); - IF (EQ_16(output_frame, L_FRAME8k)||st_fx->bfi_fx==0) + init_tcx_window_cfg(tcx_cfg, st->sr_core, st->output_Fs, st->L_frame, hTcxDec->L_frameTCX, encoderLookahead, encoderLookaheadFB, mdctWindowLength, mdctWindowLengthFB, st->element_mode); + + init_tcx_info(st, L_frame_glob, L_frameTCX_glob, 0, st->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec); + + overlap = tcx_cfg->tcx_mdct_window_length; + overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; + index = tcx_cfg->tcx_last_overlap_mode; + + /* LB synthesis */ + IMDCT(t_audio_q, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, wtda_audio, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, index, + MDCT_IV, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, max(L_frameTCX, L_spec) >> 1, L_frame_glob, 0, st->bfi, hHQ_core->old_outLB, 0, st, 0, acelp_zir); + + mvr2r(wtda_audio + (overlap >> 1) - tcx_offset, output, L_frame_glob); + + /* FB synthesis */ + IMDCT(t_audio_q, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, + MDCT_IV, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max(L_frameTCX, L_spec) >> 1, L_frameTCX_glob, 0, st->bfi, hHQ_core->old_out, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir); + + mvr2r(wtda_audio + (overlapFB >> 1) - tcx_offsetFB, synth, L_frameTCX_glob); + + if (!core_switching_flag) + { + st->last_core = ACELP_CORE; /* Restore last core */ + } + } + else +#endif { test(); - IF( NE_16(inner_frame, output_frame)&&EQ_16(st_fx->bfi_fx,1)) + IF(EQ_16(output_frame, L_FRAME8k) || st_fx->bfi_fx == 0) { - Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, output_frame ); + test(); + IF(NE_16(inner_frame, output_frame) && EQ_16(st_fx->bfi_fx, 1)) + { + Inverse_Transform(t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, output_frame, st_fx->element_mode); + } + ELSE + { + Inverse_Transform(t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, inner_frame, st_fx->element_mode); + } + *Q_synth = Q_audio; + move16(); } - ELSE + } +#ifdef ADD_IVAS_HQ_CODE + if (st->element_mode > EVS_MONO) + { + if (st->bfi) { - Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, inner_frame ); + /* Rough resampling, but reduces energy loss in case of switch to ACELP in first good frame */ + lerp(t_audio_q, wtda_audio_LB, st->L_frame, inner_frame); + v_multc(t_audio_q, 0.5f, wtda_audio_LB, st->L_frame); + } + else + { + /* LB synthesis for potential switch to ACELP */ + ener_match = (float)sqrt((float)st->L_frame / (float)output_frame); + v_multc(t_audio_q, ener_match, t_audio_q, inner_frame); + inverse_transform(t_audio_q, wtda_audio_LB, is_transient, st->L_frame, inner_frame, st->element_mode); } - *Q_synth = Q_audio; - move16(); } - +#endif IF ( EQ_16(output_frame, L_FRAME8k)) { test(); IF( st_fx->bfi_fx == 0 && st_fx->prev_bfi_fx == 0) { - Copy_Scale_sig(st_fx->old_out_fx+N_ZERO_NB, st_fx->prev_oldauOut_fx, output_frame-N_ZERO_NB, negate(st_fx->Q_old_wtda) ); + Copy_Scale_sig(hHQ_core->old_out_fx+N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame-N_ZERO_NB, negate(hHQ_core->Q_old_wtda) ); } ELSE IF( EQ_16(st_fx->prev_bfi_fx, 1)) { - set16_fx( st_fx->prev_oldauOut_fx, 0, output_frame ); + set16_fx(hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); } test(); test(); test(); test(); - IF( (EQ_16(st_fx->prev_bfi_fx, 1)||EQ_16(st_fx->bfi_fx,1))&&st_fx->old_is_transient_fx[2]==0&&EQ_16(st_fx->last_core_fx,HQ_CORE)&&EQ_16(st_fx->last_codec_mode,MODE1)) + IF( (EQ_16(st_fx->prev_bfi_fx, 1)||EQ_16(st_fx->bfi_fx,1))&& hHQ_core->old_is_transient_fx[2]==0&&EQ_16(st_fx->last_core_fx,HQ_CORE)&&EQ_16(st_fx->last_codec_mode,MODE1)) { time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); } ELSE { - window_ola_fx( wtda_audio, synth, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); - st_fx->phase_mat_next_fx = 0; + window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi_fx, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); + hHQ_nbfec->phase_mat_next_fx = 0; move16(); } @@ -334,8 +433,8 @@ void hq_core_dec_fx( test(); IF ( (st_fx->bfi_fx == 0 && st_fx->prev_bfi_fx == 0) || !(GE_16(output_frame, L_FRAME16k))) { - preecho_sb_fx( st_fx->core_brate_fx, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &st_fx->memfilt_lb_fx, - &st_fx->mean_prev_hb_fx, &st_fx->smoothmem_fx, &st_fx->mean_prev_fx, &st_fx->mean_prev_nc_fx, &st_fx->wmold_hb_fx, &st_fx->prevflag_fx, &st_fx->pastpre_fx, st_fx->bwidth_fx ); + preecho_sb_fx( st_fx->core_brate_fx, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, + &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag_fx, &hHQ_core->pastpre_fx, st_fx->bwidth_fx ); } } ELSE @@ -346,24 +445,31 @@ void hq_core_dec_fx( /* PHASE_ECU active */ Q_audio = 15; move16(); - window_ola_fx( t_audio_q, synth, &Q_audio, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi_fx && !st_fx->ph_ecu_active_fx, st_fx->oldHqVoicing_fx, st_fx->oldgapsynth_fx ); + window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi_fx && !hHQ_core->ph_ecu_active_fx, hHQ_core->oldHqVoicing_fx, hHQ_core->oldgapsynth_fx ); *Q_synth = Q_audio; move16(); } ELSE { /* no BFI or baseline PLC active */ - window_ola_fx( wtda_audio, synth, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx && !st_fx->ph_ecu_active_fx, st_fx->oldHqVoicing_fx, st_fx->oldgapsynth_fx); + window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi_fx && !hHQ_core->ph_ecu_active_fx, hHQ_core->oldHqVoicing_fx, hHQ_core->oldgapsynth_fx); } - +#ifdef ADD_IVAS_HQ_CODE + if (st->element_mode > EVS_MONO) + { + /* LB synthesis for potential switch to ACELP */ + window_ola(wtda_audio_LB, output, hHQ_core->old_outLB, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, st->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth); + } +#endif test(); test(); IF ( (st_fx->bfi_fx == 0 && st_fx->prev_bfi_fx == 0) || !(GE_16(output_frame, L_FRAME16k))) { - preecho_sb_fx( st_fx->core_brate_fx, wtda_audio, Q_audio, synth,*Q_synth, output_frame, &st_fx->memfilt_lb_fx, - &st_fx->mean_prev_hb_fx, &st_fx->smoothmem_fx, &st_fx->mean_prev_fx, &st_fx->mean_prev_nc_fx, &st_fx->wmold_hb_fx, &st_fx->prevflag_fx, &st_fx->pastpre_fx, st_fx->bwidth_fx ); + preecho_sb_fx( st_fx->core_brate_fx, wtda_audio, Q_audio, synth,*Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, + &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, + &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag_fx, &hHQ_core->pastpre_fx, st_fx->bwidth_fx ); } } @@ -401,35 +507,35 @@ void hq_core_dec_fx( IF (GE_16(output_frame, L_FRAME16k)) { - IF (EQ_16(st_fx->ph_ecu_HqVoicing_fx, 1)) + IF (EQ_16(hHQ_core->ph_ecu_HqVoicing_fx, 1)) { - st_fx->oldHqVoicing_fx = 1; + hHQ_core->oldHqVoicing_fx = 1; move16(); - Copy( gapsynth_fx, st_fx->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); } ELSE { - st_fx->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing_fx = 0; move16(); } } ELSE { - st_fx->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing_fx = 0; move16(); } if( EQ_16(st_fx->nbLostCmpt, FRAMECTTOSTART_MDCT)) { - st_fx->HqVoicing_fx = 0; + hHQ_core->HqVoicing_fx = 0; move16(); } IF( EQ_16(output_frame, L_FRAME8k)) { - Copy32( wtda_audio, st_fx->oldIMDCTout_fx, L_FRAME8k/2 ); - Copy(&st_fx->old_auOut_2fr_fx[output_frame], st_fx->old_auOut_2fr_fx, output_frame); - Copy_Scale_sig(synth, &st_fx->old_auOut_2fr_fx[output_frame], output_frame, negate(*Q_synth)); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k/2 ); + Copy(&hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame); + Copy_Scale_sig(synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate(*Q_synth)); } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -455,6 +561,153 @@ void hq_core_dec_fx( Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr+2], nbsubfr ); set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } +#ifdef ADD_IVAS_HQ_CODE + /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ + if (st->element_mode > EVS_MONO) + { + mvr2r(output, st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame); + } +#endif + return; +} +/*-------------------------------------------------------------------* + * hq_core_dec_init() + * + * Initialize HQ core state structure + *-------------------------------------------------------------------*/ + +void HQ_core_dec_init( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +) +{ + + set16_fx(hHQ_core->old_out_fx, 0, L_FRAME48k); + set16_fx(hHQ_core->old_out_LB_fx, 0, L_FRAME32k); + hHQ_core->Q_old_wtda = 15; + hHQ_core->Q_old_postdec = 0; + + hHQ_core->last_hq_core_type_fx = -1; + set16_fx(hHQ_core->old_is_transient_fx, 0, 3); + + hHQ_core->mem_norm_fx[0] = 31; + set16_fx(hHQ_core->mem_norm_fx + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta_fx = 0; + hHQ_core->no_att_hangover_fx = 0; + move16(); move16(); move16(); move16(); + hHQ_core->energy_lt_fx = 2457600; /*Q13*/ + hHQ_core->hq_generic_seed_fx = RANDOM_INITSEED; + set16_fx(hHQ_core->prev_noise_level_fx, 0, 2); + hHQ_core->prev_hqswb_clas_fx = HQ_NORMAL; + hHQ_core->prev_R_fx = 0; + move16(); + set32_fx(hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE); + set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); + + hHQ_core->HqVoicing_fx = 0; + set16_fx(hHQ_core->fer_samples_fx, 0, L_FRAME48k); + set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB); + set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB); + set16_fx(hHQ_core->prev_env_Q, 0, SFM_N_WB); + + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + hHQ_core->last_max_pos_pulse_fx = 0; + move16(); + + reset_preecho_dec_fx(hHQ_core); + + hHQ_core->prev_frm_hfe2_fx = 0; + move16(); + hHQ_core->prev_stab_hfe2_fx = 0; + move16(); + hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + move16(); + set16_fx(hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS); + + + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ + hHQ_core->time_offs_fx = 0; + set16_fx(hHQ_core->X_sav_fx, 0, PH_ECU_SPEC_SIZE); + hHQ_core->Q_X_sav = 0; + hHQ_core->num_p_fx = 0; + + //set16_fx(hHQ_core->plocs_fx, 0, MAX_PLOCS); + //set32_fx(hHQ_core->plocsi_fx, 0, MAX_PLOCS); + hHQ_core->env_stab_fx = 0x6000; /*0.75 Q15*/ + hHQ_core->mem_norm_hqfec_fx[0] = 31; + move16(); + set16_fx(hHQ_core->mem_norm_hqfec_fx + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta_hqfec_fx = 0; + hHQ_core->env_stab_plc_fx = 0; + set16_fx(hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES); + hHQ_core->envstabplc_hocnt_fx = 0; + set16_fx(hHQ_core->mag_chg_1st_fx, 32767, Lgw_max); + set16_fx(hHQ_core->Xavg_fx, 0, Lgw_max); + hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; + hHQ_core->last_fec_fx = 0; + hHQ_core->ph_ecu_HqVoicing_fx = 0; + hHQ_core->oldHqVoicing_fx = 0; + set16_fx(hHQ_core->oldgapsynth_fx, 0, L_FRAME48k); + hHQ_core->ph_ecu_active_fx = 0; + hHQ_core->ni_seed_forfec = 0; + hHQ_core->ber_occured_in_pvq = 0; + move16(); move16(); move16(); move16(); move16(); + + + return; +} + +/*-------------------------------------------------------------------* + * HQ_nbfec_init() + * + * Initialize HQ NB FEC state structure + *-------------------------------------------------------------------*/ + +void HQ_nbfec_init( + HQ_NBFEC_HANDLE hHQ_nbfec /* i/o: HQ NB FEC data handle */ +) +{ + int16_t i, j; + + hHQ_nbfec->prev_last_core_fx = -1; + hHQ_nbfec->diff_energy_fx = 0; + hHQ_nbfec->stat_mode_out_fx = 0; + hHQ_nbfec->stat_mode_old_fx = 0; + move16(); move16(); + hHQ_nbfec->phase_mat_flag_fx = 0; + hHQ_nbfec->phase_mat_next_fx = 0; + hHQ_nbfec->old_Min_ind_fx = 0; + move16(); move16(); move16(); move16(); + set16_fx(hHQ_nbfec->old_auOut_2fr_fx, 0, L_FRAME8k * 2); + set16_fx(hHQ_nbfec->old_out_pha_fx[0], 0, N_LEAD_NB); + set16_fx(hHQ_nbfec->old_out_pha_fx[1], 0, N_LEAD_NB); + + FOR(i = 0; i < MAX_SB_NB; i++) + { + FOR(j = 0; j < MAX_PGF; j++) + { + hHQ_nbfec->ynrm_values_fx[i][j] = 0; + move16(); + } + FOR(j = 0; j < MAX_ROW; j++) + { + hHQ_nbfec->r_p_values_fx[i][j] = 0; + move16(); + } + } + + set16_fx(hHQ_nbfec->Norm_gain_fx, 1, SFM_N_NB); + hHQ_nbfec->HQ_FEC_seed_fx = RANDOM_INITSEED; + set16_fx(hHQ_nbfec->energy_MA_Curr_fx, 100, 2); + + set16_fx(hHQ_nbfec->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM); + set16_fx(hHQ_nbfec->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM); + + set32_fx(hHQ_nbfec->old_coeffs_fx, 0, L_FRAME8k); + set32_fx(hHQ_nbfec->oldIMDCTout_fx, 0, L_FRAME8k / 2); + set16_fx(hHQ_nbfec->prev_oldauOut_fx, 0, L_FRAME8k); return; } diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index f9d0f1d..d7e4431 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ /*------------------------------------------------------------------------* * decode_envelope_indices_fx() @@ -14,13 +13,13 @@ * Decode envelope indices *------------------------------------------------------------------------*/ -Word16 decode_envelope_indices_fx( /* o : Number of bits */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ +Word16 decode_envelope_indices_fx( /* o : Number of bits */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : starting band index */ + const Word16 num_sfm, /* i : Number of subbands */ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ + Word16 *difidx, /* o : Diff indices/encoded diff indices */ + const Word16 flag_HQ2 /* i : indicator of HQ2 core */ ,const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ ) { diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index a403f1f..85d6833 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -1,12 +1,16 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ +/*--------------------------------------------------------------------------* + * hq_pred_hb_bws() + * + * HQ core HB band-width switching handling + *--------------------------------------------------------------------------*/ void hq_pred_hb_bws_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ @@ -63,19 +67,20 @@ void hq_pred_hb_bws_fx( * HQ High rate decoding routine *--------------------------------------------------------------------------*/ void hq_hr_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ - Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv /* o : SWB frequency envelopes Q1 */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ + Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ + const Word16 length, /* i : frame length Q0 */ + Word16 num_bits, /* i : number of available bits Q0 */ + Word16 *ynrm, /* o : norm quantization index vector Q0 */ + Word16 *is_transient, /* o : transient flag Q0 */ + Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ + Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ + const Word16 core_switching_flag /* i : Core switching flag */ ) { Word16 nb_sfm; Word16 sum, hcode_l; - const Word16 *sfmsize, *sfm_start, *sfm_end; + Word16 sfmsize[NB_SFM], sfm_start[NB_SFM], sfm_end[NB_SFM]; Word16 num_sfm, numnrmibits; Word16 nf_idx; Word16 normqlg2[NB_SFM], R[NB_SFM]; @@ -84,7 +89,7 @@ void hq_hr_dec_fx( Word16 Rsubband[NB_SFM]; /*Q3*/ Word16 start_norm, Npeaks = 0; Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /*Q15*/ - Word16 peak_idx[HVQ_MAX_PEAKS_32k]; + Word16 peak_idx[HVQ_MAX_PEAKS]; Word16 hq_generic_offset; Word16 num_env_bands; Word16 hq_generic_exc_clas = 0; @@ -99,6 +104,12 @@ void hq_hr_dec_fx( Word16 b_delta_env; Word16 tmp,n_band; Word16 Q_shift; + Word16 bits_left; + Word16 csw_flag1, csw_flag2; + + HQ_DEC_HANDLE hHQ_core = st_fx->hHQ_core; + + move16(); Q_audio = 0; /* to avoid compilation warnings */ @@ -114,24 +125,24 @@ void hq_hr_dec_fx( move16(); har_freq_est2 = 0; move16(); - set16_fx( peak_idx, 0, HVQ_MAX_PEAKS_32k); + set16_fx( peak_idx, 0, HVQ_MAX_PEAKS); /*------------------------------------------------------------------* * Decode classification *------------------------------------------------------------------*/ bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate_fx, length, is_transient, hqswb_clas); - num_bits = sub(num_bits, bits); + bits_left = sub(num_bits, bits); /*------------------------------------------------------------------* * set quantization parameters *------------------------------------------------------------------*/ hq_configure_fx( length, *hqswb_clas, st_fx->core_brate_fx, &num_sfm, &nb_sfm, &start_norm, - &num_env_bands, &numnrmibits, &hq_generic_offset, &sfmsize, &sfm_start, &sfm_end ); + &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); /*------------------------------------------------------------------* - * Unpacking bit-stream + * Unpacking bitstream *------------------------------------------------------------------*/ nf_idx = 0; @@ -139,7 +150,7 @@ void hq_hr_dec_fx( test(); test(); test(); - IF( !*is_transient && NE_16(*hqswb_clas, HQ_HVQ)&&!(EQ_16(length,L_FRAME16k)&&EQ_32(st_fx->core_brate_fx,HQ_32k))) + IF( !*is_transient && NE_16(*hqswb_clas, HQ_HVQ) && !(EQ_16(length,L_FRAME16k) && LE_32(st_fx->core_brate_fx,HQ_32k))) { nf_idx = get_next_indice_fx( st_fx, 2 ); } @@ -149,69 +160,73 @@ void hq_hr_dec_fx( *------------------------------------------------------------------*/ hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - num_bits = sub(num_bits, add(hcode_l, NORM0_BITS + FLAGS_BITS)); + bits_left = sub(bits_left, add(hcode_l, NORM0_BITS + FLAGS_BITS)); dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); test(); IF ( EQ_16(*hqswb_clas, HQ_GEN_SWB)||EQ_16(*hqswb_clas,HQ_GEN_FB)) { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate_fx == HQ_32k, *hqswb_clas ); + hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate_fx >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ if ( EQ_16(hq_generic_exc_clas , HQ_GENERIC_SP_EXC)) { - num_bits = add(num_bits,1); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add(bits_left,1); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } env_stab = 0; move16(); + + csw_flag1 = s_and(core_switching_flag, (Word16)NE_16(st_fx->element_mode, EVS_MONO) ); + csw_flag2 = s_and(csw_flag1, (Word16)EQ_16(length, L_SPEC32k_EXT)); + test(); IF( EQ_16(*hqswb_clas, HQ_HVQ)) { - st_fx->mem_env_delta_fx = 0; + hHQ_core->mem_env_delta_fx = 0; move16(); } - ELSE IF( EQ_16(length, L_FRAME32k)) + ELSE IF (EQ_16(length, L_FRAME32k) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, st_fx->mem_norm_fx, &st_fx->mem_env_delta_fx ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm_fx, &hHQ_core->mem_env_delta_fx, csw_flag1); } ELSE { - st_fx->mem_norm_fx[0] = 31; + hHQ_core->mem_norm_fx[0] = 31; move16(); - st_fx->mem_env_delta_fx = 0; + hHQ_core->mem_env_delta_fx = 0; move16(); } IF ( EQ_16(*hqswb_clas, HQ_HVQ)) { - st_fx->env_stab_fx = 32767; + hHQ_core->env_stab_fx = 32767; move16(); /* 1 in Q15, stable by definition */ } ELSE { - IF ( EQ_16(length, L_FRAME32k)) + IF ( EQ_16(length, L_FRAME32k) || csw_flag2) { - st_fx->env_stab_fx = env_stab; move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; } ELSE { - st_fx->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, st_fx->mem_norm_hqfec_fx, &st_fx->mem_env_delta_hqfec_fx ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec_fx, &hHQ_core->mem_env_delta_hqfec_fx, csw_flag1); } } - st_fx->env_stab_plc_fx = env_stab_smo_fx(s_min(st_fx->env_stab_fx, sub(32767, stab_trans_fx[L_STAB_TBL-1])), st_fx->env_stab_state_p_fx, &st_fx->envstabplc_hocnt_fx); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx(s_min(hHQ_core->env_stab_fx, sub(32767, stab_trans_fx[L_STAB_TBL-1])), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt_fx); /*------------------------------------------------------------------* * Bit allocation *------------------------------------------------------------------*/ - hq_bit_allocation_fx( st_fx->core_brate_fx, length, *hqswb_clas, &num_bits, normqlg2, nb_sfm, sfmsize, noise_level, + hq_bit_allocation_fx( st_fx->core_brate_fx, length, *hqswb_clas, &bits_left, normqlg2, nb_sfm, sfmsize, noise_level, R, Rsubband, &sum, &core_sfm, num_env_bands ); test(); test(); - IF( EQ_16(*hqswb_clas, HQ_GEN_SWB)&&st_fx->bws_cnt1_fx>0&&EQ_32(st_fx->core_brate_fx,HQ_24k40)) + IF( EQ_16(*hqswb_clas, HQ_GEN_SWB) && st_fx->bws_cnt1_fx>0 && LT_32(st_fx->core_brate_fx,HQ_32k)) { tmp = i_mult(st_fx->bws_cnt1_fx, 1638); move16(); @@ -244,7 +259,7 @@ void hq_hr_dec_fx( IF( EQ_16(*hqswb_clas, HQ_HVQ)) { - hvq_dec_fx( st_fx, num_bits, st_fx->core_brate_fx, ynrm, R, noise_level, peak_idx, &Npeaks, t_audio_q, st_fx->core_fx ); + hvq_dec_fx( st_fx, bits_left, st_fx->core_brate_fx, ynrm, R, noise_level, peak_idx, &Npeaks, t_audio_q, st_fx->core_fx ); } ELSE { @@ -269,28 +284,31 @@ void hq_hr_dec_fx( } } - har_est_fx( t_audio_q, 300 ,&har_freq_est1, &har_freq_est2, &flag_dis, &st_fx->prev_frm_hfe2_fx, subband_search_offset, wBands, &st_fx->prev_stab_hfe2_fx ); + har_est_fx( t_audio_q, 300 ,&har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2_fx, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2_fx ); - st_fx->prev_frm_hfe2_fx = har_freq_est2; + hHQ_core->prev_frm_hfe2_fx = har_freq_est2; move16(); } test(); test(); - IF ( NE_16(*hqswb_clas, HQ_HARMONIC)||NE_16(*hqswb_clas,HQ_HVQ)||flag_dis==0) +#if 0 + IF ( NE_16(*hqswb_clas, HQ_HARMONIC)||NE_16(*hqswb_clas,HQ_HVQ)||flag_dis==0) // TV2VE -> always reset in floating point code, is it OK +#endif { - st_fx->prev_frm_hfe2_fx = 0; /*reset*/ move16(); - st_fx->prev_stab_hfe2_fx = 0; /*reset*/ move16(); + hHQ_core->prev_frm_hfe2_fx = 0; /*reset*/ move16(); + hHQ_core->prev_stab_hfe2_fx = 0; /*reset*/ move16(); } /*------------------------------------------------------------------* * Spectral filling *------------------------------------------------------------------*/ fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, - &st_fx->no_att_hangover_fx, &st_fx->energy_lt_fx, &st_fx->hq_generic_seed_fx, hq_generic_exc_clas, - core_sfm, *hqswb_clas, noise_level, st_fx->core_brate_fx, st_fx->prev_noise_level_fx, &st_fx->prev_R_fx, st_fx->prev_coeff_out_fx, peak_idx, Npeaks, pulses, st_fx->old_is_transient_fx[0], - st_fx->prev_normq_fx, st_fx->prev_env_fx, st_fx->prev_bfi_fx, sfmsize, sfm_start, sfm_end, &st_fx->prev_L_swb_norm_fx, st_fx->prev_hqswb_clas_fx, num_sfm, - st_fx->prev_env_Q, num_env_bands ); + &hHQ_core->no_att_hangover_fx, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed_fx, hq_generic_exc_clas, + core_sfm, *hqswb_clas, noise_level, st_fx->core_brate_fx, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R_fx, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient_fx[0], + hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi_fx, sfmsize, sfm_start, sfm_end, + &st_fx->hBWE_FD->prev_L_swb_norm_fx, hHQ_core->prev_hqswb_clas_fx, num_sfm, hHQ_core->prev_env_Q, num_env_bands + ,st_fx->element_mode); enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); @@ -306,7 +324,7 @@ void hq_hr_dec_fx( hq_pred_hb_bws_fx(st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - st_fx->prev_hqswb_clas_fx = *hqswb_clas; + hHQ_core->prev_hqswb_clas_fx = *hqswb_clas; move16(); return; diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 6982abc..521cfcc 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -3,18 +3,16 @@ ====================================================================================*/ #include -#include -#include +#include #include "options.h" #include "cnst_fx.h" #include "rom_dec_fx.h" #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ #include "basop_mpy.h" /*--------------------------------------------------------------------------* - * Local functions + * Local function prototypes *--------------------------------------------------------------------------*/ static Word16 p2a_threshold_dequant_fx( Decoder_State_fx *st_fx, Word16 *p2a_flags, const Word16 bands, const Word16 p2a_bands ); @@ -70,11 +68,8 @@ static void spt_shorten_domain_set_dec_fx( ) { Word16 j,k; - Word16 kpos; Word16 spt_shorten_flag[SPT_SHORTEN_SBNUM]; - kpos = 0; - move16(); j = 0; move16(); FOR( k = sub(bands,SPT_SHORTEN_SBNUM); k < bands; k++ ) @@ -96,7 +91,6 @@ static void spt_shorten_domain_set_dec_fx( } } - kpos = add(kpos, 1); j = add(j, 1); } @@ -184,6 +178,8 @@ void hq_lr_dec_fx( Word16 adjustFlag; Word16 bw_low, bw_high; + HQ_DEC_HANDLE hHQ_core = st_fx->hHQ_core; + tmp2 = 0; /* to avoid compilation flags */ set16_fx(last_bitalloc_max_band, 0, 2); @@ -258,13 +254,13 @@ void hq_lr_dec_fx( test(); IF(( EQ_32(L_bwe_br, HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))&&EQ_16(st_fx->bwidth_fx,SWB)) { - IF( NE_16(st_fx->prev_hqswb_clas_fx, HQ_NORMAL)) + IF( NE_16(hHQ_core->prev_hqswb_clas_fx, HQ_NORMAL)) { j = 0; move16(); FOR(k=sub(bands_fx,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos_fx[j] = 0; + hHQ_core->prev_SWB_peak_pos_fx[j] = 0; move16(); j = add(j, 1); } @@ -324,9 +320,9 @@ void hq_lr_dec_fx( IF( EQ_16(flag_spt_fx, 1)) { - /* initalize the desired parameters for SPT */ + /* initialize the desired parameters for SPT */ spt_shorten_domain_band_save_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - spt_shorten_domain_pre_fx(band_start, band_end, st_fx->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); + spt_shorten_domain_pre_fx(band_start, band_end, hHQ_core->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); spt_shorten_domain_set_dec_fx(st_fx, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx); } @@ -827,7 +823,7 @@ void hq_lr_dec_fx( Copy32( L_y2, L_y2_ni, band_end[bands_fx-1]+1 ); hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, - st_fx->last_ni_gain_fx, st_fx->last_env_fx, &st_fx->last_max_pos_pulse_fx, p2a_flags_fx, p2a_bands_fx, + hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse_fx, p2a_flags_fx, p2a_bands_fx, hqswb_clas_fx, st_fx->bwidth_fx, L_bwe_br ); test(); @@ -839,16 +835,9 @@ void hq_lr_dec_fx( { preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx,length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); - swb_bwe_dec_lr_fx( - st_fx, - L_y2, SWB_BWE_LR_Qs, L_m, - L_bwe_br, - bands_fx, band_start, band_end, - L_band_energy, SWB_BWE_LR_Qbe, - p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, har_bands_fx, - &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx - , band_width, L_y2_ni, &ni_seed_fx - ); + swb_bwe_dec_lr_fx(st_fx, L_y2, SWB_BWE_LR_Qs, L_m, L_bwe_br, bands_fx, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, + p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, har_bands_fx, &hHQ_core->prev_frm_hfe2_fx, &hHQ_core->prev_stab_hfe2_fx + , band_width, L_y2_ni, &ni_seed_fx); post_hq2_swb_fx( L_m, lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx, p2a_flags_fx, band_start, band_end, L_y2, npulses_fx ); @@ -893,13 +882,14 @@ void hq_lr_dec_fx( } st_fx->prev_ener_shb_fx = extract_l(L_shr(L_tmp, 14)); } - IF( GE_16(st_fx->last_inner_frame_fx,L_FRAME32k)) + test(); + IF(GE_16(st_fx->last_inner_frame_fx, L_FRAME32k) && st_fx->hBWE_FD != NULL) { - set16_fx(st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx ,SWB_FENV); + set16_fx(st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV); } - updat_prev_frm_fx( L_y2, L_yout, L_bwe_br, length_fx, inner_frame, bands_fx, st_fx->bwidth_fx, *is_transient_fx, hqswb_clas_fx, &st_fx->prev_hqswb_clas_fx, - st_fx->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx, st_fx->bws_cnt_fx ); + updat_prev_frm_fx( L_y2, L_yout, L_bwe_br, length_fx, inner_frame, bands_fx, st_fx->bwidth_fx, *is_transient_fx, hqswb_clas_fx, &hHQ_core->prev_hqswb_clas_fx, + hHQ_core->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &hHQ_core->prev_frm_hfe2_fx, &hHQ_core->prev_stab_hfe2_fx, st_fx->bws_cnt_fx ); return; } diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index 227f979..220ab70 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -1412,11 +1412,7 @@ void IGFDecReadLevel( IF (IGFAllZero == 0) { Copy(hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb); - IGFSCFDecoderDecode(&hPrivateData->hArithSCFdec, - st, - &hPrivateData->igf_curr[m_igfSfbStart], /* 0Q15, hPrivateData->igf_curr = [0, 91] */ - isIndepFrame - ); + IGFSCFDecoderDecode(&hPrivateData->hArithSCFdec, st, &hPrivateData->igf_curr[m_igfSfbStart],/* 0Q15, hPrivateData->igf_curr = [0, 91] */igfGridIdx, isIndepFrame ); } ELSE { @@ -1570,41 +1566,38 @@ void IGFDecApplyMono(const IGF_DEC_INSTANCE_HANDLE hInstance, /**********************************************************************/ /* set mode is used to init the IGF dec with a new bitrate **************************************************************************/ -void IGFDecSetMode(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 bitRate, /**< in: Q0 | bitrate */ - const Word16 mode, /**< in: Q0 | bandwidth mode */ - const Word16 defaultStartLine, /**< in: Q0 | default start subband index */ - const Word16 defaultStopLine /**< in: Q0 | default stop subband index */ - , const Word16 rf_mode /**< in: | flag to signal the RF mode */ - ) +void IGFDecSetMode( + const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ + const Word32 total_brate, /* i : bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 defaultStartLine, /* i : default start subband index */ + const Word16 defaultStopLine, /* i : default stop subband index */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - hPrivateData = &hInstance->igfData; - hInstance->isIGFActive = 0; + hPrivateData = &hIGFDec->igfData; + hIGFDec->isIGFActive = 0; move16(); - IF (IGFCommonFuncsIGFConfiguration(bitRate, mode, &hPrivateData->igfInfo, rf_mode) != 0) + IF (IGFCommonFuncsIGFConfiguration(total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode) != 0) { - IGFSCFDecoderOpen(&hPrivateData->hArithSCFdec, - sub(hPrivateData->igfInfo.grid[0].stopSfb, hPrivateData->igfInfo.grid[0].startSfb), - bitRate, - mode - ,rf_mode - ); - - hInstance->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine; + IGFSCFDecoderOpen(&hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode); + + hIGFDec->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine; move16(); - hInstance->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine; + hIGFDec->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine; move16(); - hInstance->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency; + hIGFDec->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency; move16(); - hInstance->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency; + hIGFDec->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency; move16(); - hInstance->infoIGFAllZero = 0; + hIGFDec->infoIGFAllZero = 0; move16(); - hInstance->isIGFActive = 1; + hIGFDec->isIGFActive = 1; move16(); test(); @@ -1617,13 +1610,13 @@ void IGFDecSetMode(const IGF_DEC_INSTANCE_HANDLE hInstance, } ELSE { - hInstance->infoIGFStopLine = defaultStopLine; + hIGFDec->infoIGFStopLine = defaultStopLine; move16(); - hInstance->infoIGFStartLine = defaultStartLine; + hIGFDec->infoIGFStartLine = defaultStartLine; move16(); - hInstance->infoIGFStopFreq = -1; + hIGFDec->infoIGFStopFreq = -1; move16(); - hInstance->infoIGFStartFreq = -1; + hIGFDec->infoIGFStartFreq = -1; move16(); fprintf(stderr,"IGFDecSetMode: initialization error!\n"); } @@ -1733,3 +1726,35 @@ void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, move16(); } +/*-----------------------------------------------------------------------* + * init_igf_dec() + * + * Initialize IGF decoder parameters + *-----------------------------------------------------------------------*/ +void init_igf_dec( + IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ +) +{ + set16_fx(hIGFDec->infoTCXNoise, 0, IGF_START_MX); + set16_fx(hIGFDec->flag_sparse, 0, N_MAX_TCX - IGF_START_MN); + set32_fx(hIGFDec->virtualSpec, 0, N_MAX_TCX - IGF_START_MN); + hIGFDec->virtualSpec_e = 0; + hIGFDec->infoIGFStopFreq = -1; + move16(); + hIGFDec->infoIGFStartFreq = -1; + move16(); + hIGFDec->flatteningTrigger = -1; + move16(); + hIGFDec->infoIGFStartLine = -1; + move16(); + hIGFDec->isIGFActive = -1; + move16(); + hIGFDec->infoIGFAllZero = 0; + move16(); + hIGFDec->infoIGFStopLine = -1; + move16(); + hIGFDec->infoIGFStartLine = -1; + move16(); + + return; +} diff --git a/lib_dec/igf_scf_dec.c b/lib_dec/igf_scf_dec.c index df936fb..ec3ba43 100644 --- a/lib_dec/igf_scf_dec.c +++ b/lib_dec/igf_scf_dec.c @@ -17,34 +17,25 @@ initialization of an instance of this module **************************************************************************/ void IGFSCFDecoderOpen( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - ,Word16 rf_mode + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data */ + H_IGF_INFO hIgfInfo, /* i : IGF info handle */ + const Word32 total_brate, + const Word16 bwidth, + const Word16 element_mode, + const Word16 rf_mode ) { - hPublicData->scfCountLongBlock = scfCountLongBlock; - move16(); + hPublicData->scfCountLongBlock[0] = hIgfInfo->grid[0].swb_offset_len - 1; + hPublicData->scfCountLongBlock[1] = hIgfInfo->grid[1].swb_offset_len - 1; + hPublicData->scfCountLongBlock[2] = hIgfInfo->grid[2].swb_offset_len - 1; + move16();move16();move16();move16(); + hPublicData->t = 0; move16(); /* protect against the invalid request of starting decoding with a dependent block */ - IGFCommonFuncsIGFGetCFTables( - bitRate, - mode, - rf_mode, - &hPublicData->cf_se00, - &hPublicData->cf_se01, - &hPublicData->cf_off_se01, - &hPublicData->cf_se02, - &hPublicData->cf_off_se02, - &hPublicData->cf_se10, - &hPublicData->cf_off_se10, - &hPublicData->cf_se11, - &hPublicData->cf_off_se11 - ); + IGFCommonFuncsIGFGetCFTables(total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11); } @@ -311,16 +302,15 @@ void IGFSCFDecoderReset( main decoder function **************************************************************************/ void IGFSCFDecoderDecode( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Decoder_State_fx *st, /* i/o: pointer to decoder state */ - Word16 *sfe, /* o: pointer to an array which will contain the decoded quantized SCFs */ - Word16 indepFlag /* i: 1 if the block is an independent block, 0 otherwise */ + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ + Decoder_State_fx* st, /* i/o: pointer to decoder state */ + int16_t* sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, + if 0 on input the decoder will be forced to encode without a reset */ ) { - - - - /* insert data */ + /* insert data */ hPublicData->bitsRead = st->next_bit_pos_fx; move16(); ari_start_decoding_14bits(st, &hPublicData->acState); /* start AC decoding */ @@ -332,19 +322,13 @@ void IGFSCFDecoderDecode( IGFSCFDecoderReset(hPublicData); } - decode_sfe_vector_fx(hPublicData, - st, - hPublicData->t, - hPublicData->prev, - sfe, - hPublicData->scfCountLongBlock - ); + decode_sfe_vector_fx(hPublicData, st, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); arith_decode_flush_fx(st); /* finish AC decoding */ /* advance history */ - Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock); + Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx]); hPublicData->t = add(hPublicData->t, 1); hPublicData->bitsRead = sub(st->next_bit_pos_fx, hPublicData->bitsRead); diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 74c6b97..fd92e1b 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -15,13 +15,19 @@ * Initialization of static variables for the decoder *----------------------------------------------------------------------*/ -void init_decoder_fx( - Decoder_State_fx *st_fx /* o: Decoder static variables structure */ +ivas_error init_decoder_fx( + Decoder_State_fx *st_fx, /* o: Decoder static variables structure */ + const Word16 idchan /* i : channel ID */ +#ifdef IVAS_CODE + ,const MC_MODE mc_mode /* i : MC mode */ +#endif ) { - Word16 i, j; - Word16 f_db, e_db; - Word32 L_tmp; + Word16 i; + ivas_error error; + + error = IVAS_ERR_OK; + Word16 newCldfbBands; @@ -67,11 +73,9 @@ void init_decoder_fx( st_fx->last_core_fx = -1; move16(); - st_fx->prev_last_core_fx = -1; st_fx->last_extl_fx = st_fx->extl_fx; move16(); - st_fx->last_hq_core_type_fx = -1; - move16(); + /* LSF initilaizations */ Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); @@ -89,16 +93,6 @@ void init_decoder_fx( move16(); } - /* HF synth init */ - hf_synth_amr_wb_init_fx( &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, st_fx->mem_syn_hf_fx, - &st_fx->frame_count_fx, &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, - &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, &st_fx->unvoicing_flag_fx, - &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx ); - - hf_synth_init_fx( st_fx->mem_hp400_fx, st_fx->mem_hf_fx ); - set16_fx( st_fx->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); - set16_fx( st_fx->delay_syn_hf_fx, 0, NS2SA_fx2(16000,DELAY_CLDFB_NS) ); - st_fx->tilt_code_fx = 0; move16(); st_fx->gc_threshold_fx = L_deposit_l(0); @@ -124,9 +118,63 @@ void init_decoder_fx( st_fx->mem_deemph_fx = 0; move16(); + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF ((st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE)count_malloc(sizeof(FD_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n")); + } + + fd_bwe_dec_init(st_fx, st_fx->hBWE_FD); + } + ELSE + { + st_fx->hBWE_FD = NULL; + } + + /*-----------------------------------------------------------------* + * IGF + *-----------------------------------------------------------------*/ + + IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) ) + { + IF ((st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE)count_malloc(sizeof(IGFDEC_INSTANCE))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n")); + } + + st_fx->igf = 0; + //init_igf_dec(st_fx->hIGFDec); + set16_fx((Word16*)st_fx->hIGFDec, 0, (sizeof(st_fx->hIGFDec) + 1) / sizeof(Word16)); + st_fx->hIGFDec->igfData.igfInfo.nfSeed = 9733; + } + else + { + st_fx->hIGFDec = NULL; + } + + /*-----------------------------------------------------------------* + * HR SWB BWE parameters + *-----------------------------------------------------------------*/ + + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF ((st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE)count_malloc(sizeof(HR_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n")); + } + + hr_bwe_dec_init(st_fx->hBWE_FD_HR); + } + ELSE + { + st_fx->hBWE_FD_HR = NULL; + } set16_fx( st_fx->mem_syn1_fx, 0, M ); - st_fx->mem_deemph_old_syn_fx = 0; move16(); set16_fx( st_fx->mem_syn2_fx, 0, M ); st_fx->stab_fac_fx = 0; @@ -136,11 +184,7 @@ void init_decoder_fx( set16_fx( st_fx->agc_mem_fx, 0, 2 ); set32_fx( st_fx->L_mem_hp_out_fx, 0, 5 ); set16_fx( st_fx->mem_syn3_fx, 0, M ); - FOR (i=0; ipast_qua_en_fx[i] = -14336; - move16(); /* Q10; */ /* gain quantization memory (used also in AMR-WB IO mode) */ - } + Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); @@ -148,30 +192,64 @@ void init_decoder_fx( move16(); st_fx->safety_net_fx = 0; move16(); - - /* parameters for AC mode (GSC) */ - st_fx->seed_tcx_fx = 15687; - move16(); /*check if it is Q0*/ st_fx->GSC_noisy_speech_fx = 0; move16(); - st_fx->Last_GSC_noisy_speech_flag_fx = 0; - move16(); - st_fx->cor_strong_limit_fx = 1; - move16(); - set16_fx(st_fx->old_y_gain_fx, 0 , MBANDS_GN ); - st_fx->noise_lev_fx = NOISE_LEVEL_SP0; - move16(); - set16_fx( st_fx->Last_GSC_spectrum_fx, 0, L_FRAME ); - st_fx->Last_GSC_pit_band_idx_fx = 0; + st_fx->last_voice_factor_fx = 0; move16(); - set16_fx( st_fx->lt_ener_per_band_fx, 4096, MBANDS_GN );/*Q12*/ - set16_fx( st_fx->last_exc_dct_in_fx, 0, L_FRAME); - st_fx->last_ener_fx = 0; - set16_fx( st_fx->last_bitallocation_band_fx, 0, 6 ); + set16_fx(st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); + + IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF ((st_fx->hGSCDec = (GSC_DEC_HANDLE)count_malloc(sizeof(GSC_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); + } + + GSC_dec_init(st_fx->hGSCDec); + } + ELSE + { + st_fx->hGSCDec = NULL; + } + + /*-----------------------------------------------------------------* + * parameters for fast recovery (WI) + *-----------------------------------------------------------------*/ + test(); test(); + IF (EQ_32(st_fx->output_Fs_fx, 16000) && EQ_16(st_fx->element_mode, EVS_MONO ) ) + { + IF ((st_fx->hWIDec = (WI_DEC_HANDLE)count_malloc(sizeof(WI_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n")); + } + + set16_fx(st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM); + set16_fx(st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM); + } + else + { + st_fx->hWIDec = NULL; + } /* NB post-filter */ - Init_post_filter( &(st_fx->pfstat) ); + /*-----------------------------------------------------------------* + * NB/formant post-filter + *-----------------------------------------------------------------*/ + IF ((idchan == 0 && NE_16(st_fx->element_mode,IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF ((st_fx->hPFstat = (PFSTAT_HANDLE)count_malloc(sizeof(PFSTAT))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n")); + } + + Init_post_filter(st_fx->hPFstat); + st_fx->psf_lp_noise_fx = 0; + } + ELSE + { + st_fx->hPFstat = NULL; + } st_fx->psf_lp_noise_fx = 0; move16(); @@ -221,9 +299,6 @@ void init_decoder_fx( st_fx->decision_hyst_fx = 0; move16(); - /* fast recovery */ - set16_fx( st_fx->old_exc2_fx, 0, L_EXC_MEM ); - set16_fx( st_fx->old_syn2_fx, 0, L_EXC_MEM ); /* Stationary noise UV modification */ st_fx->unv_cnt_fx = 0; @@ -240,82 +315,46 @@ void init_decoder_fx( move16(); /*1; Q15*/ st_fx->exc_pe_fx = 0; move16(); - - st_fx->cng_ener_seed1_fx = RANDOM_INITSEED; - move16(); - set32_fx(st_fx->lp_env_fx, 0, NUM_ENV_CNG); - set16_fx(st_fx->exc_mem_fx, 0, 24); - set16_fx(st_fx->exc_mem1_fx, 0, 30); - set32_fx(st_fx->old_env_fx, 0, NUM_ENV_CNG); - /* LD music post-filter */ - set16_fx(st_fx->dct_post_old_exc_fx, 0, DCT_L_POST-OFFSET2 ); - /*st->LDm_enh_min_ns_gain = (float)pow(10.0f, -12/20.0f);*/ - L_tmp = L_mult(((-12*256)), 5443); /* *0.166096 in Q15 -> Q24 */ - L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ - f_db = L_Extract_lc(L_tmp, &e_db); /* Extract exponent */ - f_db = extract_l(Pow2(14, f_db)); /* Put 14 as exponent so that */ - e_db = add(e_db, 15-14); - f_db = add(f_db, shr(1,add(e_db,1))); - st_fx->LDm_enh_min_ns_gain_fx = shl(f_db, e_db); - - st_fx->LDm_last_music_flag_fx = 0; - move16(); - set16_fx( st_fx->LDm_lt_diff_etot_fx, 0, MAX_LT ); - - st_fx->LDm_thres_fx[0] = TH_0_MIN_FX; - move16(); - st_fx->LDm_thres_fx[1] = TH_1_MIN_FX; - move16(); - st_fx->LDm_thres_fx[2] = TH_2_MIN_FX; - move16(); - st_fx->LDm_thres_fx[3] = TH_3_MIN_FX; - move16(); - - st_fx->LDm_nb_thr_1_fx = 0; - move16(); - st_fx->LDm_nb_thr_3_fx = 0; - move16(); - st_fx->LDm_mem_etot_fx = 0; - move16(); - - FOR (i = 0; i < VOIC_BINS_HR; i++) + /*-----------------------------------------------------------------* + * LD music post-filter + *-----------------------------------------------------------------*/ + IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) { - st_fx->LDm_enh_lp_gbin_fx[i] = 16384; - move16(); - st_fx->LDm_enh_lf_EO_fx [i] = 328; - move16(); - } + IF ((st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE)count_malloc(sizeof(MUSIC_POSTFILT_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n")); + } - FOR (i = 0; i < MBANDS_GN_LD; i++) + music_postfilt_init(st_fx->hMusicPF); + } + ELSE { - st_fx->LDm_bckr_noise_fx[i] = E_MIN_Q15; - move16(); + st_fx->hMusicPF = NULL; } - set16_fx(st_fx->filt_lfE_fx, 4096, DCT_L_POST); - move16(); - st_fx->last_nonfull_music_fx = 0; - move16(); - st_fx->Old_ener_Q = 0; - move16(); - /* CNG and DTX */ + test(); test(); test(); + IF (idchan == 0 && (EQ_16(st_fx->element_mode, EVS_MONO) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) )) + { + if ((st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE)count_malloc(sizeof(TD_CNG_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n")); + } + + td_cng_dec_init(st_fx); + } + ELSE + { + st_fx->hTdCngDec = NULL; + } + st_fx->cng_type_fx = -1; st_fx->CNG_fx = 0; move16(); /* RTXDTX handler CNG=1 nonCNG= 0,*/ st_fx->prev_ft_speech_fx = 1; move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ - st_fx->cng_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->cng_ener_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->old_enr_index_fx = -1; - move16(); - st_fx->Enew_fx = L_deposit_l(0); st_fx->first_CNG_fx = 0; move16(); Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - st_fx->last_allow_cn_step_fx = 0; - move16(); st_fx->shb_cng_ener_fx = -1541; move16(); st_fx->wb_cng_ener_fx = -1541; @@ -326,37 +365,13 @@ void init_decoder_fx( move16(); st_fx->swb_cng_seed_fx = RANDOM_INITSEED; move16(); - st_fx->ho_hist_ptr_fx = -1; - move16(); - st_fx->ho_sid_bw_fx = L_deposit_l(0); - set16_fx( st_fx->ho_lsp_hist_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_hist_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_hist_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_hist_size_fx = 0; - move16(); - st_fx->act_cnt_fx = 0; - move16(); - st_fx->ho_circ_ptr_fx = -1; - move16(); - set16_fx( st_fx->ho_lsp_circ_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_circ_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_circ_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_circ_size_fx = 0; - move16(); - set16_fx( st_fx->ho_16k_lsp_fx, 0, HO_HIST_SIZE ); + st_fx->CNG_mode_fx = -1; move16(); st_fx->last_active_brate_fx = ACELP_7k20; move32(); st_fx->last_CNG_L_frame_fx = L_FRAME; move16(); - st_fx->act_cnt2_fx = 0; - move16(); - st_fx->num_ho_fx = 0; - move16(); - st_fx->cng_type_fx = -1; - move16(); - st_fx->last_cng_type_fx = -1; move16(); FOR ( i=0; itrans_cnt_fx = 0; move16(); - st_fx->burst_cnt_fx = 0; - move16(); st_fx->last_shb_ener_fx = 0; move16(); /* HF (6-7kHz) BWE */ - st_fx->seed2_fx = RANDOM_INITSEED; move16(); st_fx->Q_stat_noise_ge = GE_SHIFT; move16(); @@ -386,269 +398,137 @@ void init_decoder_fx( st_fx->cngTDLevel_e = 0; move16(); - /*-----------------------------------------------------------------* - * HR SWB BWE parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->t_audio_prev_fx, 0, 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( st_fx->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ - st_fx->old_is_transient_hr_bwe_fx = 0; - move16(); - st_fx->bwe_highrate_seed_fx = 12345; - move16(); - - st_fx->L_mem_EnergyLT_fx = L_deposit_h(16384); - st_fx->mem_EnergyLT_fx_exp = 40; - move16(); /* set to a high exponent */ - + /*-----------------------------------------------------------------* * HQ core parameters *-----------------------------------------------------------------*/ + test(); test(); test(); test(); test(); test(); + IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, EVS_MONO)) ) + { + IF ((st_fx->hHQ_core = (HQ_DEC_HANDLE)count_malloc(sizeof(HQ_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n")); + } - set16_fx( st_fx->old_out_fx, 0, L_FRAME48k ); - set16_fx( st_fx->old_out_LB_fx, 0, L_FRAME32k ); - set32_fx( st_fx->old_coeffs_fx, 0, L_FRAME8k ); - st_fx->Q_old_wtda = 15; - move16(); - st_fx->Q_old_postdec = 0; - move16(); - st_fx->Qprev_synth_buffer_fx = 15; - move16(); - set16_fx( st_fx->old_is_transient_fx, 0, 3 ); - st_fx->old_bfi_cnt_fx = 0; - move16(); - set16_fx(st_fx->old_auOut_2fr_fx, 0, L_FRAME8k*2); - set16_fx(st_fx->old_out_pha_fx[0], 0, N_LEAD_NB); - set16_fx(st_fx->old_out_pha_fx[1], 0, N_LEAD_NB); - st_fx->prev_old_bfi_fx = 0; - move16(); - st_fx->phase_mat_flag_fx = 0; - move16(); - st_fx->phase_mat_next_fx = 0; - move16(); - st_fx->old_Min_ind_fx = 0; - move16(); - st_fx->diff_energy_fx = 0; - move16(); - set32_fx( st_fx->oldIMDCTout_fx, 0, L_FRAME8k/2 ); - set16_fx( st_fx->prev_oldauOut_fx, 0, L_FRAME8k ); - st_fx->stat_mode_out_fx = 0; - move16(); - st_fx->stat_mode_old_fx = 0; - move16(); - st_fx->oldHqVoicing_fx = 0; - move16(); + /* HQ core initialization */ + HQ_core_dec_init(st_fx->hHQ_core); - FOR( i=0; i element_mode, EVS_MONO)) { - st_fx->ynrm_values_fx[i][j] = 0; - move16(); + /* HQ NB FEC initialization */ + IF ((st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE)count_malloc(sizeof(HQ_NBFEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n")); + } + HQ_nbfec_init(st_fx->hHQ_nbfec); } - FOR( j=0; jr_p_values_fx[i][j] = 0; + st_fx->hHQ_nbfec = NULL; move16(); } } - set16_fx(st_fx->Norm_gain_fx, 1, SFM_N_NB); /*check if it is in Q0 */ - set16_fx(st_fx->energy_MA_Curr_fx, 100, 2);/*check if it is in Q0*/ - st_fx->HQ_FEC_seed_fx = RANDOM_INITSEED; - move16(); - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); - set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k); - set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA(48000,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS) ); - set16_fx( st_fx->prev_noise_level_fx, 0, 2 ); - - st_fx->prev_R_fx = 0; - set32_fx( st_fx->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); - set16_fx(st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - - /* HQ GENERIC */ - st_fx->hq_generic_seed_fx = RANDOM_INITSEED; - move16(); - - st_fx->mem_norm_fx[0] = 31; - move16(); - set16_fx(st_fx->mem_norm_fx+1, 39, SFM_N_ENV_STAB-1); - st_fx->mem_env_delta_fx = 0; - move16(); - st_fx->no_att_hangover_fx = 0; - move16(); - st_fx->energy_lt_fx = 2457600; - move16(); /* 300 in Q13 */ - - st_fx->HqVoicing_fx = 0; - move16(); - set16_fx( st_fx->fer_samples_fx, 0, L_FRAME48k ); - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); - st_fx->prev_hqswb_clas_fx = HQ_NORMAL; - move16(); - - /* LRMDCT_DELTA_NOISE_INJECT_FX */ - set32_fx( st_fx->last_ni_gain_fx, 0x0L, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - st_fx->prev_ni_ratio_fx = 16384; - move16(); /* 0.5 */ - set16_fx( st_fx->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); - - /* pre-echo reduction */ - reset_preecho_dec_fx( st_fx ); + ELSE + { + st_fx->hHQ_core = NULL; + st_fx->hHQ_nbfec = NULL; + move16(); move16(); + } + st_fx->Qprev_synth_buffer_fx = 15; + st_fx->old_bfi_cnt_fx = 0; + st_fx->prev_old_bfi_fx = 0; + set16_fx(st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX* HQ_DELAY_COMP); + set16_fx(st_fx->previoussynth_fx, 0, L_FRAME48k); + IF (EQ_16(st_fx->element_mode, EVS_MONO ) ) + { + set16_fx(st_fx->old_synth_sw_fx, 0, NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)); + } + /*-----------------------------------------------------------------* + * TCX core + *-----------------------------------------------------------------*/ + /* TCX-LTP */ + IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) ) + { + IF ((st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE)count_malloc(sizeof(TCX_LTP_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n")); + } + } + ELSE + { + st_fx->hTcxLtpDec = NULL; + } - /*----------------------------------------------------------------------------------* - * HQ FEC - *----------------------------------------------------------------------------------*/ - st_fx->old_synthFB_fx = st_fx->synth_history_fx + NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_MEM_NS); - st_fx->prev_good_synth_fx = st_fx->old_synthFB_fx + NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS); - set16_fx( st_fx->X_sav_fx, 0, PH_ECU_SPEC_SIZE ); - st_fx->Q_X_sav = 0; - move16(); - st_fx->num_p_fx = 0; - move16(); - st_fx->ph_ecu_active_fx = 0; - move16(); - st_fx->ni_seed_forfec = 0; - move16(); - st_fx->last_fec_fx = 0; - move16(); - st_fx->ph_ecu_HqVoicing_fx = 0; - move16(); - set16_fx( st_fx->oldgapsynth_fx, 0, L_FRAME48k ); - st_fx->env_stab_fx = 0x6000; /* 0.75 (Q15) */ move16(); - st_fx->mem_norm_hqfec_fx[0] = 31; - move16(); - set16_fx(st_fx->mem_norm_hqfec_fx+1, 39, SFM_N_ENV_STAB-1); - st_fx->mem_env_delta_hqfec_fx = 0; - move16(); - st_fx->env_stab_plc_fx = 0; - move16(); - set16_fx( st_fx->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); - st_fx->envstabplc_hocnt_fx = 0; - move16(); - set16_fx(st_fx->mag_chg_1st_fx, 32767, Lgw_max); - set16_fx(st_fx->Xavg_fx, 0, Lgw_max); - st_fx->beta_mute_fx = BETA_MUTE_FAC_INI; - move16(); - set16_fx( st_fx->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM ); - set16_fx( st_fx->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM ); - /* st->ni_seed_forfec = 0; */ - st_fx->time_offs_fx = 0; - move16(); - st_fx->ber_occured_in_pvq = 0; - move16(); + /* TCX core */ + // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 + IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF ((st_fx->hTcxDec = (TCX_DEC_HANDLE)count_malloc(sizeof(TCX_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n")); + } - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - st_fx->old_wtda_wb_fx_exp = 0; - move16(); - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); - st_fx->old_wtda_swb_fx_exp = 0; - move16(); - st_fx->mem_imdct_exp_fx = 0; - move16(); + set16_fx(st_fx->hTcxDec->FBTCXdelayBuf, 0, 111); - st_fx->prev_mode_fx = NORMAL; - move16(); - set16_fx( st_fx->prev_SWB_fenv_fx, 0, SWB_FENV ); - st_fx->prev_Energy_fx = 0; - move16(); - st_fx->prev_L_swb_norm_fx = 8; - move16(); - st_fx->Seed_fx = 21211; - move16(); - st_fx->prev_frica_flag_fx = 0; - move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_td_energy_fx = 0; - move16(); - st_fx->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); - st_fx->prev_flag_fx = 0; - move16(); + st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA(st_fx->output_Fs_fx, PH_ECU_MEM_NS); + st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS); + } + ELSE + { + st_fx->hTcxDec = NULL; + } + /* TCX config. data structure */ + IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + { + IF ((st_fx->hTcxCfg = (TCX_CONFIG_HANDLE)count_malloc(sizeof(TCX_config))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n")); + } + } + ELSE + { + st_fx->hTcxCfg = NULL; + } st_fx->prev_coder_type_fx = GENERIC; move16(); - st_fx->last_wb_bwe_ener_fx = 0; - move16(); - st_fx->prev_hb_synth_fx_exp = 0; + move16(); st_fx->tilt_wb_fx = 0; move16(); - st_fx->prev_Energy_wb_fx = L_deposit_l(0); + set16_fx(st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); + set16_fx(st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS)); + st_fx->old_bwe_delay_fx = -1; /*Q0*/ move16(); /*-----------------------------------------------------------------* * TBE parameters *-----------------------------------------------------------------*/ - InitSWBdecBuffer_fx( st_fx ); - ResetSHBbuffer_Dec_fx(st_fx); - IF( EQ_32(st_fx->output_Fs_fx,48000)) + IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) { - set32_fx( st_fx->fbbwe_hpf_mem_fx[0], 0, 4 ); - set32_fx( st_fx->fbbwe_hpf_mem_fx[1], 0, 4 ); - set32_fx( st_fx->fbbwe_hpf_mem_fx[2], 0, 4 ); - set32_fx( st_fx->fbbwe_hpf_mem_fx[3], 0, 4 ); - set16_fx( st_fx->fbbwe_hpf_mem_fx_Q, 0, 4 ); - } - - set16_fx( st_fx->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN ); - set16_fx( st_fx->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS) ); - st_fx->old_bwe_delay_fx = -1; /*Q0*/ move16(); - - st_fx->tilt_mem_fx = 0; - move16(); - set16_fx( st_fx->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = 0; - move16(); - set16_fx( st_fx->cur_sub_Aq_fx, 0, M+1 ); - set16_fx( st_fx->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); - set16_fx( st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); + if ((st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE)count_malloc(sizeof(TD_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n")); + } - /* TD BWE post-processing */ - st_fx->ptr_mem_stp_swb_fx = st_fx->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx(st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER); + td_bwe_dec_init_fx(st_fx, st_fx->hBWE_TD, +#ifdef ADD_IVAS_BWE + st_fx->extl, +#endif + st_fx->output_Fs_fx); - FOR ( i=0; iswb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; - move16(); + st_fx->hBWE_TD = NULL; } - st_fx->prev1_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - st_fx->prev2_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - st_fx->prev3_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - st_fx->prev_res_shb_gshape_fx = 8192; /* 0.125 in Q14*/ move16(); - st_fx->prev_mixFactors_fx = 16384; /* 0.5 in Q15*/ move16(); - st_fx->prev_GainShape_fx = 0; - move16(); - st_fx->prev_Q_bwe_exc_fb = 51; - move16(); - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - move16(); - - - /*-----------------------------------------------------------------* - * WB/SWB bandwidth switching parameters - *-----------------------------------------------------------------*/ - st_fx->tilt_swb_fx = 0; - move16(); - st_fx->prev_ener_fx = L_deposit_l(0); + st_fx->tilt_wb_fx = 0; + st_fx->prev_ener_shb_fx = 0; move16(); st_fx->prev_enerLH_fx = 0; @@ -671,8 +551,6 @@ void init_decoder_fx( move16(); st_fx->last_bwidth_fx = 0; move16(); - st_fx->prev_weight1_fx = 16384; - move16(); /*-----------------------------------------------------------------* * channel-aware mode parameters @@ -706,55 +584,86 @@ void init_decoder_fx( st_fx->rf_indx_tbeGainFr = 0; move16(); + /*----------------------------------------------------------------------------------* + * AMR-WB IO mode parameters + *----------------------------------------------------------------------------------*/ + IF (st_fx->Opt_AMR_WB_fx || EQ_16(st_fx->element_mode, EVS_MONO) ) + { + IF ((st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE)count_malloc(sizeof(AMRWB_IO_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n")); + } + + /* AMR-WB IO init */ + amr_wb_dec_init(st_fx->hAmrwb_IO); + + /* AMR-WB IO HF synth init */ + hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); + } + ELSE + { + st_fx->hAmrwb_IO = NULL; + } /*-----------------------------------------------------------------* - * Improvement of unvoiced and audio signals in AMR-WB IO mode parameters + * HF (6-7kHz) (zero) BWE parameters *-----------------------------------------------------------------*/ - st_fx->UV_cnt_fx = 30; - move16(); - st_fx->LT_UV_cnt_fx = (60<<6); - move16(); - set16_fx( st_fx->lt_diff_etot_fx, 0, MAX_LT ); - st_fx->Last_ener_fx = 0; - move16(); - set16_fx(st_fx->old_Aq_fx, 0, 4*(M+1)); - st_fx->old_Aq_fx[0] = 16384; - move16(); - st_fx->old_Aq_fx[M+1] = 16384; - move16(); - st_fx->old_Aq_fx[2*(M+1)] = 16384; - move16(); - st_fx->old_Aq_fx[3*(M+1)] = 16384; - move16(); - st_fx->lt_voice_fac_fx = 0; - move16(); + IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF ((st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE)count_malloc(sizeof(ZERO_BWE_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n")); + } + + hf_synth_init_fx(st_fx->hBWE_zero); + } + ELSE + { + st_fx->hBWE_zero = NULL; + } + + /* HF synth init */ + hf_synth_amr_wb_init_fx(st_fx->hAmrwb_IO); - /*-----------------------------------------------------------------* - * Postfilters - *-----------------------------------------------------------------*/ - bass_psfilter_init_fx( st_fx->pst_old_syn_fx, &(st_fx->pst_mem_deemp_err_fx), &(st_fx->pst_lp_ener_fx) ); st_fx->bpf_off_fx = 0; - move16(); - set16_fx( st_fx->Track_on_hist_fx, 0, L_TRACK_HIST ); - set16_fx( st_fx->vibrato_hist_fx, 0, L_TRACK_HIST ); - set16_fx( st_fx->mem_mean_pit_fx, 80, L_TRACK_HIST ); - st_fx->psf_att_fx = 32767; - move16(); + /*-----------------------------------------------------------------* + * Bass post-filter parameters + *-----------------------------------------------------------------*/ + test(); test(); test(); + IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF ((st_fx->hBPF = (BPF_DEC_HANDLE)count_malloc(sizeof(BPF_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n")); + } + bass_psfilter_init_fx(st_fx->hBPF); + } + ELSE + { + st_fx->hBPF = NULL; + } /*-----------------------------------------------------------------* * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ /* open analysis for max. SR 48kHz */ - openCldfb ( &st_fx->cldfbAna_fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(48000), 320 ); + if ((error = openCldfb(&st_fx->cldfbAna_fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(48000), 320)) != IVAS_ERR_OK) + { + return error; + } /* open analysis BPF for max. SR 16kHz */ - openCldfb ( &st_fx->cldfbBPF_fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(16000), 320 ); - + if ((error = openCldfb(&st_fx->cldfbBPF_fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(16000), 320)) != IVAS_ERR_OK) + { + return error; + } /* open synthesis for output SR */ - openCldfb ( &st_fx->cldfbSyn_fx, CLDFB_SYNTHESIS, CLDFB_getNumChannels(st_fx->output_Fs_fx), st_fx->output_frame_fx); - + if ((error = openCldfb(&st_fx->cldfbSyn_fx, CLDFB_SYNTHESIS, CLDFB_getNumChannels(st_fx->output_Fs_fx), st_fx->output_frame_fx)) != IVAS_ERR_OK) + { + return error; + } move16(); move16(); move16(); @@ -763,7 +672,6 @@ void init_decoder_fx( move16(); move32(); st_fx->last_active_bandsToZero_bwdec = 0; - st_fx->flag_NB_bwddec = 0; st_fx->perc_bwddec = 0; st_fx->last_flag_filter_NB = 0; st_fx->active_frame_cnt_bwddec = 0; @@ -773,8 +681,6 @@ void init_decoder_fx( st_fx->Ng_ener_ST_fx = -13056; move16(); /*-51 IN Q8*/ - st_fx->Last_frame_ener_fx = MAX_32; - move32(); st_fx->old_Es_pred_fx = 0; move16(); set16_fx(st_fx->old_Aq_12_8_fx + 1, 0, M ); @@ -782,10 +688,23 @@ void init_decoder_fx( move16(); /*1 in Q12*/ /*-----------------------------------------------------------------* - * SC-VBR + * SC-VBR parameters *-----------------------------------------------------------------*/ - st_fx->FadeScale_fx = 32767; - move16(); /* Q15*/ + + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF ((st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE)count_malloc(sizeof(SC_VBR_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); + } + + sc_vbr_dec_init(st_fx->hSC_VBR); + } + ELSE + { + st_fx->hSC_VBR = NULL; + } + st_fx->last_ppp_mode_dec_fx = 0; move16(); st_fx->old_ppp_mode_fx = 0; @@ -796,10 +715,6 @@ void init_decoder_fx( move16(); st_fx->nelp_mode_dec_fx = 0; move16(); - st_fx->nelp_dec_seed_fx = 0; - move16(); - st_fx->firstTime_voiceddec_fx = 1; - move16(); st_fx->prev_gain_pit_dec_fx = 0; move16(); st_fx->prev_tilt_code_dec_fx = 0; @@ -808,43 +723,9 @@ void init_decoder_fx( move16(); st_fx->last_vbr_hw_BWE_disable_dec_fx = 0; move16(); - set16_fx( st_fx->old_hb_synth_fx, 0, L_FRAME48k ); - /* DTFS variables */ - set16_fx( st_fx->dtfs_dec_a_fx, 0, MAXLAG_WI ); - set16_fx( st_fx->dtfs_dec_b_fx, 0, MAXLAG_WI ); - st_fx->dtfs_dec_lag_fx = 0; - move16(); - st_fx->dtfs_dec_nH_fx = 0; - move16(); - st_fx->dtfs_dec_nH_4kHz_fx = 0; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx = 0; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_fx = 0; - move16(); - st_fx->ph_offset_D_fx = 0; - move16(); - st_fx->lastLgainD_fx = 0; - move16(); - st_fx->lastHgainD_fx = 0; - move16(); - set16_fx( st_fx->lasterbD_fx, 0, NUM_ERB_WB ); - st_fx->dtfs_dec_Q = 0; - move16(); - /* NELP decoder variables */ - set32_fx( st_fx->bp1_filt_mem_nb_dec_fx, 0, 14 ); - set16_fx( st_fx->bp1_filt_mem_wb_dec_fx, 0, 8 ); - set16_fx( st_fx->shape1_filt_mem_dec_fx, 0, 10 ); - set16_fx( st_fx->shape2_filt_mem_dec_fx, 0, 10 ); - set16_fx( st_fx->shape3_filt_mem_dec_fx, 0, 10 ); - /* IGF */ - st_fx->igf = 0; - move16(); - set16_fx( (Word16*)&st_fx->hIGFDec, 0, (sizeof(st_fx->hIGFDec)+1)/sizeof(Word16) ); - st_fx->hIGFDec.igfData.igfInfo.nfSeed = 9733; - move16(); + st_fx->enablePlcWaveadjust = 0; move16(); @@ -864,12 +745,26 @@ void init_decoder_fx( resampleCldfb( st_fx->cldfbAna_fx, newCldfbBands, st_fx->L_frame_fx, 1 ); resampleCldfb( st_fx->cldfbBPF_fx, newCldfbBands, st_fx->L_frame_fx, 1 ); +#ifdef IVAS_CODE + IF((EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || idchan == 0 ) && NE_16(mc_mode, MC_MODE_MCT) && NE_16(mc_mode, MC_MODE_PARAMUPMIX) ) // TBV Fixed point missing +#else + IF ( ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || idchan == 0) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/) +#endif + { + /* Create FD_CNG instance */ - /* Create FD_CNG instance */ - createFdCngDec(&st_fx->hFdCngDec_fx); + if ((error = createFdCngDec(&st_fx->hFdCngDec_fx)) != IVAS_ERR_OK ) + { + return error; + } - /* Init FD-CNG */ - initFdCngDec( st_fx->hFdCngDec_fx, st_fx->cldfbSyn_fx->scale ); + /* Init FD-CNG */ + initFdCngDec( st_fx, st_fx->cldfbSyn_fx->scale ); + } + ELSE + { + st_fx->hFdCngDec_fx = NULL; + } st_fx->lp_noise = -167772160l/*-20.f Q23*/; st_fx->force_lpd_reset = 0; @@ -879,8 +774,6 @@ void init_decoder_fx( * initialzie Q values *-----------------------------------------------------------------*/ - st_fx->memExp1 = 0; - move16(); st_fx->Q_syn2 = 0; move16(); st_fx->Q_exc = 8; @@ -897,16 +790,34 @@ void init_decoder_fx( move16(); } - /* Previous frame LPC initialization for PPP */ - st_fx->prev_Q_synth = 0; - move16(); - st_fx->prev_Q_exc_fr = 0; move16(); st_fx->prev_Q_syn_fr = 0; move16(); - return; + /*----------------------------------------------------------------------------------* + * Stereo/IVAS parameters + *----------------------------------------------------------------------------------*/ +#if 1 // IVAS_CODE -> To be verified + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + st_fx->element_mode = EVS_MONO; /* element mode */ + st_fx->last_element_mode = st_fx->element_mode; /* element mode */ + st_fx->element_brate = -1; /* element bitrate */ + st_fx->low_rate_mode = 0; /* low-rate mode flag */ + st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ + //st_fx->cng_ism_flag = 0; + //st_fx->coder_type_fx = GENERIC; /* low-rate mode flag */ + +#endif +#ifdef DEBUGGING + st_fx->id_element = -1; /* element ID */ +#endif + st_fx->extl_orig = -1; /* extension layer */ + st_fx->extl_brate_orig = 0; /* extension layer bitrate */ + + return error; } @@ -916,36 +827,34 @@ void init_decoder_fx( * * Initialization of static variables for pre-echo *----------------------------------------------------------------------*/ - void reset_preecho_dec_fx( - Decoder_State_fx *st_fx /* i/o: Decoder static variables structure */ + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ) { - st_fx->memfilt_lb_fx = 0; + hHQ_core->memfilt_lb_fx = 0; move16(); - st_fx->mean_prev_hb_fx = L_deposit_l(0); - st_fx->smoothmem_fx = 32767; + hHQ_core->mean_prev_hb_fx = L_deposit_l(0); + hHQ_core->smoothmem_fx = 32767; move16(); - st_fx->mean_prev_fx = L_deposit_l(0); - st_fx->mean_prev_nc_fx = L_deposit_l(0); - st_fx->wmold_hb_fx = 32767; + hHQ_core->mean_prev_fx = L_deposit_l(0); + hHQ_core->mean_prev_nc_fx = L_deposit_l(0); + hHQ_core->wmold_hb_fx = 32767; move16(); - st_fx->prevflag_fx = 0; + hHQ_core->prevflag_fx = 0; move16(); - st_fx->pastpre_fx = 0; + hHQ_core->pastpre_fx = 0; move16(); return; } - /*----------------------------------------------------------------------* - * destroy_decoder() + * destroy_cldfb_decoder() * * Free memory which was allocated in init_decoder() *----------------------------------------------------------------------*/ -void destroy_decoder( +void destroy_cldfb_decoder( Decoder_State_fx *st_fx /* o: Decoder static variables structure */ ) { diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 9698229..678cb32 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*======================================================================*/ /* FUNCTION : inov_decode_fx() */ @@ -44,14 +44,13 @@ void inov_decode_fx( const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ const Word16 sharpFlag, /* i : formant sharpening flag */ const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code /* o : algebraic excitation */ + Word16 *code, /* o : algebraic excitation */ + const Word16 L_subfr /* i : subframe length */ ) { Word16 nBits; @@ -70,27 +69,77 @@ void inov_decode_fx( IF ( !Opt_AMR_WB ) { - IF( EQ_16(L_frame, L_FRAME)) +#ifdef IVAS_CODE + if (st_fx->acelp_cfg.fcb_mode) { - nBits = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - } - IF(EQ_16(nBits,7)) - { - dec_acelp_1t64_fx(st_fx, code); - } - ELSE IF( EQ_16(nBits,12)) - { - dec_acelp_2t32_fx( st_fx, code ); + int16_t i; + int16_t indexing_indices[8], wordcnt, bitcnt; + PulseConfig config; + if (st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0) + { + if (L_subfr == 2 * L_SUBFR) + { + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + + if (nBits == 8) + { + //dec_acelp_1t64(st_fx, code, L_subfr); + } + else + { + //dec_acelp_fast(st_fx, nBits, code, L_subfr); + } + } + //else if ((st_fx->idchan == 1 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7) || (st_fx->idchan == 0 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3)) + //{ + // if (st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0) + // { + // dec_acelp_1t64(st_fx, code, L_SUBFR); + // } + // else + // { + // dec_acelp_fast(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR); + // } + //} + else + { + wordcnt = ACELP_FIXED_CDK_BITS(st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) >> 4; + bitcnt = ACELP_FIXED_CDK_BITS(st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) & 15; +PMT("CONDITION above is missing -> idchan") + for (i = 0; i < wordcnt; i++) + { + indexing_indices[i] = get_next_indice_fx(st_fx, 16); + } + if (bitcnt) + { + indexing_indices[i] = get_next_indice_fx(st_fx, bitcnt); + } + config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; + D_ACELP_indexing(code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect); + } + } + else + { + set16_fx(code, 0.0f, L_SUBFR); + } } - ELSE + else +#endif { - dec_acelp_4t64_fx( st_fx, nBits, code, Opt_AMR_WB ); + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + + IF(EQ_16(nBits,7)) + { + dec_acelp_1t64_fx(st_fx, code, L_SUBFR); + } + ELSE IF( EQ_16(nBits,12)) + { + dec_acelp_2t32_fx( st_fx, code ); + } + ELSE + { + dec_acelp_4t64_fx( st_fx, nBits, code, Opt_AMR_WB ); + } } } ELSE @@ -129,7 +178,7 @@ void inov_decode_fx( } } - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0 ); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0, L_subfr); return; } diff --git a/lib_dec/io_dec_fx.c b/lib_dec/io_dec_fx.c index 50aaa01..188f84d 100644 --- a/lib_dec/io_dec_fx.c +++ b/lib_dec/io_dec_fx.c @@ -66,6 +66,7 @@ void io_ini_dec_fx( char stmp[50]; Word16 evs_magic, amrwb_magic; char bit_rate_string[14]; + #ifdef DEBUGGING short i_FEC_pattern = 0; #endif @@ -143,7 +144,7 @@ void io_ini_dec_fx( i = i + 2; } #ifdef DEBUGGING - ELSE IF(strcmp(to_upper(argv[i]), "-FEC") == 0) + ELSE IF (strcmp(to_upper(argv[i]), "-FEC") == 0) { float ftmp = 0.0f; if (sscanf(argv[i + 1], "%f", &ftmp) != 1) @@ -475,15 +476,14 @@ static void usage_dec( void ) fprintf(stdout, " Reading RFC4867 AMR/AMR-WB RTP payload format is not supported.\n"); #ifdef SUPPORT_JBM_TRACEFILE fprintf(stdout, "-Tracefile TF : VoIP mode: Generate trace file named TF\n"); -#endif -#ifdef DEBUGGING - fprintf(stdout, "\n-FEC X : Insert frame erasures, X = 0-10 is the percentage\n\n"); #endif fprintf(stdout, "-fec_cfg_file RF : VoIP mode: Optimal channel aware configuration computed by the JBM\n"); fprintf(stdout, " as described in Section 6.3.1 of TS26.448. The output is\n"); fprintf(stdout, " written into a file named RF. Each line contains the FER indicator\n"); fprintf(stdout, " (HI|LO) and optimal FEC offset.\n"); - +#ifdef DEBUGGING + fprintf(stdout, "\n-FEC X : Insert frame erasures, X = 0-10 is the percentage\n\n"); +#endif fprintf(stdout, "-no_delay_cmp : Turn off delay compensation\n"); fprintf(stdout, "-mime : Mime bitstream file format\n"); fprintf(stdout, " The decoder may read both TS26.445 Annex A.2.6 and RFC4867 Mime Storage\n"); diff --git a/lib_dec/jbm_pcmdsp_window.c b/lib_dec/jbm_pcmdsp_window.c index cc7ec0e..6e6746d 100644 --- a/lib_dec/jbm_pcmdsp_window.c +++ b/lib_dec/jbm_pcmdsp_window.c @@ -8,7 +8,6 @@ /* local headers */ #include "jbm_pcmdsp_window.h" #include "options.h" -#include "stl.h" /* Overlap/Add of two signal with a given window. */ diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index 6aba3a3..fba19e4 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -2,18 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ - #include "cnst_fx.h" #include "rom_com_fx.h" #include "rom_dec_fx.h" #include "prot_fx.h" -#include "stl.h" /*-------------------------------------------------------------------* * Local function prototype *-------------------------------------------------------------------*/ -static void fcb_decode_pos_fx(Word16 index, Word16 pos_vector[], Word16 pulse_num, Word16 pos_num); +static void fcb_decode_pos_fx(const Word16 index, Word16 pos_vector[], const Word16 pulse_num, const Word16 pos_num); /*-------------------------------------------------------------------* * re8_decode_base_index_fx @@ -21,13 +20,13 @@ static void fcb_decode_pos_fx(Word16 index, Word16 pos_vector[], Word16 pulse_nu * Decode RE8 base index *-------------------------------------------------------------------*/ void re8_decode_base_index_fx( - Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + const Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ Word16 *x /* o : point in RE8 (8-dimensional integer vector) */ ) { Word16 i,j,k1,l,m,m1,m2; - Word16 setor_8p_temp[8],setor_8p_temp_1[8],setor_8p_temp_2[8]= {0}; + Word16 setor_8p_temp[8],setor_8p_temp_1[8],setor_8p_temp_2[8]; Word16 sign_8p; Word16 code_level; const Word16 *a1,*a2; @@ -36,7 +35,12 @@ void re8_decode_base_index_fx( UWord16 offset; Word16 code_index; - Word16 element_a10, element_a11 = 0, element_a12 = 0; + Word16 element_a10, element_a11, element_a12; + move16(); + move16(); + element_a11 = 0; + element_a12 = 0; + set16_fx(setor_8p_temp_2, 0, 8); IF (LT_16( n, 2 )) { @@ -129,7 +133,7 @@ void re8_decode_base_index_fx( move16(); } code_index = shr(code_index, 1); - /* no break */ + /* FALLTHRU */ case 3: @@ -148,7 +152,7 @@ void re8_decode_base_index_fx( move16(); element_a12 = a1[2]; move16(); - /* no break */ + /* FALLTHRU */ case 2: @@ -189,16 +193,31 @@ void re8_decode_base_index_fx( m1 = sub(k1, 1); m2 = 8; move16(); +#ifdef AFFECT_TEST_VECTOR_BE_dec + l = 1; + FOR(i = 0; i < 8; i++) + { + if (x[i] == 0) + { + l = 0; + move16(); + } + } + test(); + /* if the signs are constrained and all components are non-zero */ + IF((k1 == 7) && (l > 0)) +#else IF(k1 == 7) +#endif { m2 = 7; move16(); } FOR(i = 0; i < m2; i++) { - IF (x[i] != 0) + IF(x[i] != 0) { - IF (s_and(shr(sign_8p, m1), 1) != 0) + IF(s_and(shr(sign_8p, m1), 1) != 0) { x[i] = sub(0, x[i]); move16(); @@ -235,16 +254,15 @@ void re8_decode_base_index_fx( * base function for decoding position index *-------------------------------------------------------------------*/ static void fcb_decode_pos_fx( - Word16 index, /* i : Index to decoder */ + const Word16 index, /* i : Index to decoder */ Word16 pos_vector[], /* o : Position vector */ - Word16 pulse_num, /* i : Number of pulses */ - Word16 pos_num /* i : Number of positions */ + const Word16 pulse_num, /* i : Number of pulses */ + const Word16 pos_num /* i : Number of positions */ ) { Word16 i,k,l; Word16 temp1,temp2,tmp_loop; - const Word16 *select_table23; - const Word16 *select_table24; + const Word16 *select_table23, *select_table24; k = index; move16(); diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index 3fed3cb..e502f90 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" +#include +#include "options.h" /* Compilation switches */ +#include "cnst_fx.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ /*======================================================================*/ /* FUNCTION : lp_filt_exc_dec_fx() */ @@ -33,15 +33,12 @@ /*=======================================================================*/ void lp_filt_exc_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 codec_type, /* i : coder type */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 L_subfr, /* i : subframe size */ - const Word16 L_frame, /* i : frame size */ - Word16 lp_flag, /* i : operation mode signalling */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word16 codec_mode, /* i : coder mode */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 L_subfr, /* i : subframe size */ + const Word16 L_frame, /* i : frame size */ + Word16 lp_flag, /* i : operation mode signaling */ Word16 *exc ) { @@ -53,33 +50,18 @@ void lp_filt_exc_dec_fx( /*-----------------------------------------------------------------* * Select LP filtering of the adaptive excitation *-----------------------------------------------------------------*/ - IF( EQ_16(codec_type, MODE1)) + IF(EQ_16(codec_mode, MODE1)) { - test(); - test(); - test(); - IF ( ( Opt_AMR_WB || EQ_16(coder_type,GENERIC)||EQ_16(coder_type,TRANSITION))&<_32(core_brate,ACELP_11k60)) - { - lp_flag = LOW_PASS; - move16(); - } - ELSE IF ( GE_32(core_brate,ACELP_11k60)) + IF(EQ_16(lp_flag, NORMAL_OPERATION)) { - lp_flag = (Word16)get_next_indice_fx( st_fx, 1 ); - move16(); - } - ELSE - { - lp_flag = FULL_BAND; - move16(); + lp_flag = (Word16)get_next_indice_fx(st_fx, 1); } } - IF ( EQ_16(lp_flag, LOW_PASS)) { - /* pointer positionning to avoid doing it inside the loop */ + /* pointer positioning to avoid doing it inside the loop */ test(); - IF(codec_type==MODE2 && L_frame==L_FRAME16k) + IF(codec_mode ==MODE2 && L_frame==L_FRAME16k) { fac_n = 6881/*0.21f Q15*/; fac_m = 19005/*0.58f Q15*/; diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index dbd4263..b65522f 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -2,16 +2,19 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - +#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#include "ivas_prot.h" +#include "ivas_rom_com.h" +#endif /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ +static void dqlsf_CNG_fx(Decoder_State_fx* st_fx, Word16* lsf_q); /*--------------------------------------------------------------------------------------* * dqlsf_CNG_fx() @@ -27,10 +30,7 @@ static void dqlsf_CNG_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *lsf_q, /* o : decoded LSFs */ - Word32 * p_offset_scale1, /* i : offset for 1st LVQ subvector */ - Word32 * p_offset_scale2, /* i : offset for second LVQ subvector */ - Word16 * p_no_scales /* i : number of scales for LVQ struct */ + Word16 *lsf_q /* o : decoded LSFs */ ) { Word16 indice[4]; @@ -45,7 +45,7 @@ static void dqlsf_CNG_fx( /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ ber_flag= - deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG-4, p_offset_scale1, p_offset_scale2, p_no_scales ); + deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG-4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0]); st_fx->BER_detect = s_or(ber_flag, st_fx->BER_detect); @@ -96,31 +96,44 @@ static void dqlsf_CNG_fx( void lsf_dec_fx( Decoder_State_fx *st_fx, /* i/o: State structure */ const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid /* o : de-quantized mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ + Word16 *lsf_new, /* o : de-quantized LSF vector */ + Word16 *lsp_new, /* o : de-quantized LSP vector */ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif ) { Word16 i; - Word16 int_fs; + Word16 no_param_lpc; + Word16 param_lpc[NPRM_LPC_NEW]; Word32 L_tmp; Word16 nBits = 0; Word16 tmp_old[M+1], tmp_new[M+1]; Word16 enr_old = 0, enr_new = 0; - Word16 lsf_diff; + Word16 lsf_diff, coder_type; +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(tdm_low_rate_mode); +#endif /* initialize */ - int_fs = INT_FS_16k_FX; - move16(); - if( EQ_16(L_frame,L_FRAME)) + coder_type = st_fx->coder_type_fx; + if ( EQ_32(st_fx->core_brate_fx, SID_2k40) ) { - int_fs = INT_FS_FX; + coder_type = INACTIVE; move16(); } + test(); + if ( EQ_16(coder_type, AUDIO) && GT_16( st_fx->GSC_IVAS_mode, 0) ) + { + coder_type = GENERIC; + move16(); + } + no_param_lpc = 0; + nBits = 0; + move16();move16(); /* Find the number of bits for LSF quantization */ IF ( EQ_32(st_fx->core_brate_fx,SID_2k40)) @@ -133,7 +146,7 @@ void lsf_dec_fx( test(); IF ( st_fx->nelp_mode_dec_fx == 0 && st_fx->ppp_mode_dec_fx == 0 ) { - nBits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type)]; + nBits = st_fx->acelp_cfg.lsf_bits; move16(); } ELSE IF ( EQ_16(st_fx->nelp_mode_dec_fx,1)) @@ -142,7 +155,7 @@ void lsf_dec_fx( { nBits = 30; move16(); - if ( EQ_16(bwidth,NB)) + if ( EQ_16(st_fx->bwidth_fx,NB)) { nBits = 32; move16(); @@ -157,13 +170,24 @@ void lsf_dec_fx( } /* LSF de-quantization */ - lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth_fx, nBits, lsf_new, st_fx->mem_AR_fx,st_fx->mem_MA_fx, int_fs, st_fx->core_brate_fx, - &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->offset_scale1_p_fx[0][0], &st_fx->offset_scale2_p_fx[0][0], - &st_fx->no_scales_fx[0][0], &st_fx->no_scales_p_fx[0][0], &st_fx->safety_net_fx, NULL, LSF_Q_prediction, NULL ); + lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth_fx, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc); /* convert quantized LSFs to LSPs */ - lsf2lsp_fx(lsf_new, lsp_new, M ,int_fs); + lsf2lsp_fx(lsf_new, lsp_new, M ,st_fx->sr_core); + /* set seed_acelp used in UC mode */ + test(); + IF (EQ_16(coder_type, UNVOICED) && GT_16(st_fx->element_mode, EVS_MONO)) + { + st_fx->seed_acelp = 0; + move16(); + FOR (i = no_param_lpc - 1; i >= 0; i--) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st_fx->seed_acelp = (int16_t)((((st_fx->seed_acelp) >> 1) + param_lpc[i]) * 31821L + 13849L); + PMTE() /*IVAS_CODE to be completed */ + } + } IF ( EQ_32(st_fx->core_brate_fx,SID_2k40)) { /* return if SID frame (conversion to A(z) done in the calling function) */ @@ -184,11 +208,11 @@ void lsf_dec_fx( test(); test(); - IF ( ( st_fx->prev_bfi_fx && (EQ_16(coder_type,TRANSITION))&&(EQ_16(tc_subfr,sub(L_frame,L_SUBFR))))) + IF ( ( st_fx->prev_bfi_fx && (EQ_16(coder_type,TRANSITION))&&(EQ_16(tc_subfr,sub(st_fx->L_frame_fx,L_SUBFR))))) { lsf_diff = 1205; move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ - if( EQ_16(L_frame,L_FRAME)) + if( EQ_16(st_fx->L_frame_fx,L_FRAME)) { lsf_diff = 964; move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ @@ -201,7 +225,7 @@ void lsf_dec_fx( st_fx->lsf_old_fx[i] = add(st_fx->lsf_old_fx[i-1], lsf_diff); move16(); } - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, int_fs ); + lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); } /*-------------------------------------------------------------------------------------* * Mid-frame LSF decoding @@ -215,12 +239,11 @@ void lsf_dec_fx( } { /* Mid-frame LSF decoding */ - lsf_mid_dec_fx( st_fx, int_fs, st_fx->lsp_old_fx, lsp_new, coder_type, lsp_mid, st_fx->core_brate_fx, st_fx->ppp_mode_dec_fx, st_fx->nelp_mode_dec_fx - ,st_fx->prev_bfi_fx, &(st_fx->mid_lsf_int_fx), st_fx->safety_net_fx); + lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid); } test(); test(); - IF ( !( st_fx->prev_bfi_fx && (EQ_16(coder_type,TRANSITION))&&(EQ_16(tc_subfr,sub(L_frame,L_SUBFR))))) + IF ( !( st_fx->prev_bfi_fx && (EQ_16(coder_type,TRANSITION))&&(EQ_16(tc_subfr,sub(st_fx->L_frame_fx,L_SUBFR))))) { IF ( st_fx->prev_bfi_fx) { @@ -230,9 +253,7 @@ void lsf_dec_fx( E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M); enr_new = Enr_1_Az_fx( tmp_new, 2*L_SUBFR ); - } - IF ( st_fx->prev_bfi_fx ) - { + IF( LT_16(enr_new, mult_r(9830/*0.3 Q15*/,enr_old))) { /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */ @@ -255,12 +276,28 @@ void lsf_dec_fx( { /* update old LSPs/LSFs in case of HQ->ACELP core switching */ Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, int_fs ); + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core); } +#ifdef ADD_LRTD + IF (EQ_16(tdm_low_rate_mode, 1) && GT_16(coder_type, UNVOICED)) + { + PMT("To be verified") + IF (EQ_16(st_fx->active_cnt_fx, 1) ) + { + Copy(lsp_mid, st_fx->lsp_old, M); + lsp2lsf_fx(lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core); + Copy(lsp_new, lsp_mid, M); + } - /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_fx( L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp_fx ); - + /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ + int_lsp4_fx(st_fx->L_frame_fx, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2); + } + ELSE +#endif + { + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp4_fx(st_fx->L_frame_fx, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp_fx); + } /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ @@ -306,26 +343,18 @@ void lsf_dec_fx( /*========================================================================*/ void lsf_end_dec_fx( - Decoder_State_fx * st, /* i/o: decoder state structure */ + Decoder_State_fx * st, /* i/o: decoder state structure */ Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word32 int_fs, /* i : sampling frequency */ - Word32 core_brate, /* i : Coding Bit Rate */ - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p, - Word16 *safe_net, - Word16 *lpc_param, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 * nb_indices + const Word16 coder_type_org, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ + Word16 *lpc_param, /* i : LPC parameters */ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ + Word16 * nb_indices /* o : number of indices */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif ) { Word16 pred0[M]; /* Prediction for the safety-net quantizer (usually mean)*/ @@ -345,21 +374,33 @@ void lsf_end_dec_fx( Word16 num_bits; Word16 * p_lpc_param; - Word16 nr_ind; Word16 nBits; Word16 coder_type; Word16 ber_flag; + Word16 flag_1bit_gran; +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + Word16 pred3[M]; +#endif + flag_1bit_gran = (Word16)GT_16(st->element_mode, EVS_MONO); + nBits = nBits_in; - move16(); + *nb_indices = 0; + move16();move16();move16(); test(); test(); - IF((EQ_16(coder_type_org, GENERIC))&&(EQ_32(int_fs,INT_FS_16k))&&(mode2_flag==0)) +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF((EQ_16(coder_type_org, GENERIC)) && (EQ_32(st->sr_core,INT_FS_16k)) && (mode2_flag==0) && (st->idchan == 0)) +#else + IF((EQ_16(coder_type_org, GENERIC)) && (EQ_32(st->sr_core,INT_FS_16k)) && (mode2_flag==0)) +#endif { + /* this bit is used only for primary channel or mono */ coder_type = (Word16)get_next_indice_fx( st, 1 ); coder_type = add(coder_type,2); - if (EQ_16(coder_type, GENERIC)) + test(); test(); + if (EQ_16(coder_type, GENERIC) || (EQ_16(coder_type, VOICED) && EQ_16(flag_1bit_gran, 1))) { nBits = sub(nBits,1); } @@ -374,17 +415,17 @@ void lsf_end_dec_fx( * LSF de-quantization of SID frames *--------------------------------------------------------------------------------*/ - IF ( core_brate == SID_2k40 ) + IF ( st->core_brate_fx == SID_2k40 ) { - dqlsf_CNG_fx( st, qlsf, p_offset_scale1, p_offset_scale2, p_no_scales ); + dqlsf_CNG_fx( st, qlsf); sort_fx( qlsf, 0, M-1); - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, int_fs ); + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); return; } - predmode = find_pred_mode(coder_type, bwidth, int_fs, &mode_lvq, &mode_lvq_p, st->total_brate_fx); + find_pred_mode(&predmode, coder_type, bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate_fx); /*----------------------------------------------------------------* * Calculate number of stages and levels for each stage based on the allowed bit allocation * (subtract one bit for LSF predictor selection) @@ -396,9 +437,17 @@ void lsf_end_dec_fx( /*--------------------------------------------------------------------------* * Select safety_net or predictive mode *--------------------------------------------------------------------------*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF (st->tdm_LRTD_flag == 0 && EQ_16(st->idchan, 1) && tdm_lsfQ_PCh != NULL) + { + /* if secondary channel predmode is set to be > 2 */ + /*predmode += 3;*/ + predmode =add(predmode , 3); + } +#endif p_lpc_param = lpc_param; - nr_ind = 0; + move16(); IF ( predmode == 0 ) { @@ -412,13 +461,13 @@ void lsf_end_dec_fx( } ELSE { - IF (EQ_16(mode2_flag, 1)) + IF (EQ_16(mode2_flag, 1) || EQ_16(st->core_fx, TCX_20_CORE) || EQ_16(st->core_fx, TCX_10_CORE)) { - nr_ind = add(nr_ind,1); /* read from param_lpc */ safety_net = p_lpc_param[0]; move16(); p_lpc_param++; + *nb_indices = add(*nb_indices, 1); } ELSE { @@ -426,111 +475,119 @@ void lsf_end_dec_fx( } } - *safe_net = safety_net; + st->safety_net_fx = safety_net; move16(); /*--------------------------------------------------------------------------* * Read indices from array *--------------------------------------------------------------------------*/ - - IF ( safety_net ) - { - stages = stages0; - move16(); - levels = levels0; - move16(); - bits = bits0; - move16(); - } - ELSE +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + /* Make sure there are the correct bit allocations */ + IF (st->idchan == 1 && predmode > 2) { - stages = stages1; - move16(); - levels = levels1; - move16(); - bits = bits1; - move16(); + PMTE() + /* use same AR prediction bit allocation for intra and inter modes*/ + lsf_allocate(nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1); + stages0 = stages1; + mvs2s(levels1, levels0, stages0); + mvs2s(bits1, bits0, stages0); } +#endif - IF (EQ_16(mode2_flag, 1)) + test(); test(); + IF (EQ_32(st->sr_core , INT_FS_16k) && EQ_16(coder_type, VOICED) && flag_1bit_gran == 0) { - /* VOICED_WB@16kHz */ - test(); - IF ( EQ_32(int_fs, INT_FS_16k)&&EQ_16(coder_type,VOICED)) + /* BC-TCVQ - only in VOICED_WB@16kHz */ + test(); test(); + IF (EQ_16(st->codec_mode, MODE2) || EQ_16(st->core_fx, TCX_20_CORE) || EQ_16(st->core_fx, TCX_10_CORE)) { *nb_indices = 10; move16(); - FOR(i=0; i<*nb_indices; i++) + move16(); + TCQIdx[0] = safety_net; + FOR (i = 1; i < *nb_indices; i++) { - TCQIdx[i] = (Word16)lpc_param[i]; + TCQIdx[i] = *p_lpc_param++; move16(); } } ELSE { - FOR ( i=0; icore_fx, TCX_20_CORE) || EQ_16(st->core_fx, TCX_10_CORE)) + { + FOR(i = 0; i < stages - 1; i++) { num_bits = bits[i]; move16(); - lindice[i+1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; move16(); - nr_ind = add(nr_ind,1); } - cumleft = levels[stages-1]; + cumleft = levels[stages - 1]; move16(); - WHILE ( cumleft > 0 ) + WHILE(cumleft > 0) { - IF ( GT_16(cumleft, LEN_INDICE)) + IF(GT_16(cumleft, LEN_INDICE)) { cumleft = sub(cumleft, LEN_INDICE); - num_bits = LEN_INDICE; - move16(); } ELSE { - num_bits = (Word16)cumleft; - move16(); cumleft = 0; move16(); } - lindice[i+1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; move16(); - nr_ind = add(nr_ind,1); i = add(i,1); } - *nb_indices = nr_ind; - move16(); - } - } - ELSE - { - /* VOICED_WB@16kHz */ - test(); - IF ( EQ_32(int_fs, INT_FS_16k)&&EQ_16(coder_type,VOICED)) - { - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - TCQIdx[0] = safety_net; + *nb_indices = add(*nb_indices , i); move16(); - FOR ( i=0; i<(M/2)+3; i++ ) - { - TCQIdx[i+1] = (Word16)get_next_indice_fx( st, Bit_alloc1[i] ); - } } ELSE { - FOR ( i=0; i 0 ) + WHILE(cumleft > 0) { - IF ( GT_16(cumleft, LEN_INDICE)) + IF(GT_16(cumleft, LEN_INDICE)) { cumleft = sub(cumleft, LEN_INDICE); num_bits = LEN_INDICE; @@ -544,12 +601,11 @@ void lsf_end_dec_fx( move16(); } - lindice[i+1] = (Word16)get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16)get_next_indice_fx(st, num_bits); i = add(i,1); } } } - IF(EQ_16(st->reset_mem_AR,1)) { FOR( i=0; isr_core, INT_FS_16k) && EQ_16(coder_type,VOICED) && flag_1bit_gran == 0) { /* BC-TCVQ decoder */ safety_net = qlsf_ARSN_tcvq_Dec_16k_fx ( qlsf, TCQIdx, nBits-1 ); /* Update mem_MA */ - Copy( qlsf, mem_MA, M ); + Copy( qlsf, st->mem_MA_fx, M ); IF (safety_net) { @@ -584,7 +640,7 @@ void lsf_end_dec_fx( { FOR(i = 0; i < M; i++) { - pred0[i] = add(ModeMeans_fx[mode_lvq][i], mult(Predictors_fx[mode_lvq_p][i],(sub(mem_AR[i], ModeMeans_fx[mode_lvq][i])))); /* Q(x2.56)*/ + pred0[i] = add(ModeMeans_fx[mode_lvq][i], mult(Predictors_fx[mode_lvq_p][i],(sub(st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i])))); /* Q(x2.56)*/ } *LSF_Q_prediction = AUTO_REGRESSIVE; move16(); @@ -599,32 +655,64 @@ void lsf_end_dec_fx( /* for mem_MA update */ FOR (i=0; imem_MA_fx[i])); } - +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ + if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + { + tdm_SCh_LSF_intra_pred(st->element_brate, tdm_lsfQ_PCh, pred3); + } +#endif IF ( safety_net ) { /* LVQ */ - ber_flag = - vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0-1], - p_offset_scale1, p_offset_scale2, p_offset_scale1_p, p_offset_scale2_p, - p_no_scales, p_no_scales_p ); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + { - st->BER_detect = s_or(st->BER_detect, ber_flag); - Vr_add( qlsf, pred0, qlsf, M ); - Vr_subt( qlsf, pred1, mem_MA, M); + /* intra mode*/ + st->BER_detect = st->BER_detect | + vq_dec_lvq(0, qlsf, &lindice[1], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1]); + + v_add(qlsf, pred3, qlsf, M); + v_sub(qlsf, pred1, st->mem_MA, M); + } + else +#endif + { + ber_flag = vq_dec_lvq_fx(1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0]); + + st->BER_detect = s_or(st->BER_detect, ber_flag); + Vr_add(qlsf, pred0, qlsf, M); + Vr_subt(qlsf, pred1, st->mem_MA_fx, M); + } } ELSE { - ber_flag = - vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1-1], - p_offset_scale1, p_offset_scale2, p_offset_scale1_p, p_offset_scale2_p, - p_no_scales, p_no_scales_p ); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF (EQ_16(predmode, 4)) + { + mode_lvq_p = 9; + predmode = 2; + move16(); move16(); + } +#endif + ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1-1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0]); st->BER_detect = s_or(st->BER_detect, ber_flag); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + test(); + IF (EQ_16(predmode, 1) || EQ_16(predmode, 4)) /* MA only */ +#else IF (EQ_16(predmode, 1)) /* MA only */ +#endif { - Copy(qlsf, mem_MA, M); + Copy(qlsf, st->mem_MA_fx, M); Vr_add( qlsf, pred1, qlsf, M ); *LSF_Q_prediction = MOVING_AVERAGE; move16(); @@ -634,10 +722,10 @@ void lsf_end_dec_fx( /* AR */ FOR ( i=0; imem_AR_fx[i], pred0[i]))); } Vr_add( qlsf, pred2, qlsf, M ); - Vr_subt( qlsf, pred1, mem_MA, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); *LSF_Q_prediction = AUTO_REGRESSIVE; move16(); } @@ -654,9 +742,9 @@ void lsf_end_dec_fx( sort_fx( qlsf, 0, M-1 ); /* Verify stability */ - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, int_fs ); + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); /* Update predictor memory */ - Copy( qlsf, mem_AR, M ); + Copy( qlsf, st->mem_AR_fx, M ); st->mode_lvq = mode_lvq; move16(); @@ -673,15 +761,9 @@ void lsf_end_dec_fx( /*------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (Word16) coder_type : Coder type */ -/* _ (Word16) int_fs : internal (ACELP) sampling frequency */ /* _ (Word32) core_brate : core bitrate */ -/* _ (Word32) ppp_mode : PPP mode */ -/* _ (Word32) nelp_mode : NELP mode */ -/* _ (Word16[]) qlsp0 : quantized LSPs from frame beginning Q15 */ -/* _ (Word16[]) qlsp1 : quantized LSPs from frame end Q15 */ -/* _ (Word16) prev_bfi, */ -/* _ (Word16 *)mid_lsf_int, */ -/* _ (Word16) safety_net */ +/* _ (Word16[]) lsp_new : quantized LSPs from frame beginning Q15 */ +/* _ (Word16[]) lsp_mid : quantized LSPs from frame end Q15 */ /*------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ @@ -695,17 +777,9 @@ void lsf_end_dec_fx( /*========================================================================*/ void lsf_mid_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 int_fs, /* i : internal (ACELP) sampling frequency */ - Word16 qlsp0[], /* i : quantized LSPs from frame beginning Q15*/ - Word16 qlsp1[], /* i : quantized LSPs from frame endSQ15*/ + Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ Word16 coder_type, /* i : Coder type */ - Word16 qlsp[], /* o : quantized LSPs Q15*/ - const Word32 core_brate, /* i : core bitrate */ - Word16 ppp_mode, - Word16 nelp_mode, - Word16 prev_bfi, - Word16 *mid_lsf_int, - Word16 safety_net + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; @@ -719,17 +793,17 @@ void lsf_mid_dec_fx( /* Convert LSPs to LSFs */ - lsp2lsf_fx( qlsp0, qlsf0, M, int_fs); - lsp2lsf_fx( qlsp1, qlsf1, M, int_fs); + lsp2lsf_fx(st_fx->lsp_old_fx, qlsf0, M, st_fx->sr_core); + lsp2lsf_fx( lsp_new, qlsf1, M, st_fx->sr_core); /* Codebook selection */ - IF ( EQ_16(ppp_mode,1)) + IF ( EQ_16(st_fx->ppp_mode_dec_fx,1)) { nb_bits = 1; move16(); ratio = &tbl_mid_voi_wb_1b_fx[0]; } - ELSE IF ( EQ_16(nelp_mode,1)) + ELSE IF ( EQ_16(st_fx->nelp_mode_dec_fx,1)) { nb_bits = 4; move16(); @@ -737,7 +811,7 @@ void lsf_mid_dec_fx( } ELSE { - nb_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; + nb_bits = st_fx->acelp_cfg.mid_lsf_bits; move16(); /* codebook selection */ @@ -756,6 +830,11 @@ void lsf_mid_dec_fx( ratio = tbl_mid_voi_wb_4b_fx; BREAK; } + case 1: + { + ratio = tbl_mid_voi_wb_1b_fx; + break; + } } } ELSE IF ( coder_type == UNVOICED ) @@ -772,6 +851,13 @@ void lsf_mid_dec_fx( ratio = tbl_mid_gen_wb_5b_fx; BREAK; } +#ifdef IVAS_CODE + case 4: + { + ratio = tbl_mid_gen_wb_4b_fx; + break; + } +#endif case 2: { ratio = tbl_mid_gen_wb_2b_fx; @@ -793,7 +879,7 @@ void lsf_mid_dec_fx( } /* check for incorrect LSF ordering */ - IF ( EQ_16(*mid_lsf_int, 1)) + IF ( EQ_16(st_fx->mid_lsf_int_fx, 1)) { FOR (j=1; jprev_bfi_fx || ( EQ_16(st_fx->mid_lsf_int_fx, 1) && bad_spacing)) { FOR (j=0; jprev_bfi_fx ) { /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ - *mid_lsf_int = 1; + st_fx->mid_lsf_int_fx = 1; move16(); } - if ( safety_net ) + if (st_fx->safety_net_fx ) { /* safety-net encountered -> stop redoing mid-LSF interpolation with 0.4 */ - *mid_lsf_int = 0; + st_fx->mid_lsf_int_fx = 0; move16(); } - reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, int_fs ); + reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, st_fx->sr_core); /* convert back to LSPs */ - lsf2lsp_fx( qlsf, qlsp, M, int_fs); + lsf2lsp_fx( qlsf, lsp_mid, M, st_fx->sr_core); return; } diff --git a/lib_dec/lsf_msvq_ma_dec.c b/lib_dec/lsf_msvq_ma_dec.c index e698cc8..e1358f9 100644 --- a/lib_dec/lsf_msvq_ma_dec.c +++ b/lib_dec/lsf_msvq_ma_dec.c @@ -2,23 +2,24 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include -#include "stl.h" #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" +#ifndef swap + #define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} +#endif +/*---------------------------------------------------------------------* + * lsf_msvq_ma_decprm() + * + * + *---------------------------------------------------------------------*/ -#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - - -Word16 lsf_msvq_ma_decprm( Decoder_State_fx * st, Word16 *param_lpc, Word16 core, Word16 acelp_mode, Word16 acelp_midLpc, - Word16 narrowBand, Word32 sr_core - ) +Word16 lsf_msvq_ma_decprm( Decoder_State_fx * st, Word16 *param_lpc) { Word16 i, nbits_lpc, tmp; Word16 bits_midlpc; @@ -30,29 +31,26 @@ Word16 lsf_msvq_ma_decprm( Decoder_State_fx * st, Word16 *param_lpc, Word16 core move16(); test(); - IF ((EQ_32(sr_core, INT_FS_16k))&&(EQ_16(acelp_mode,UNVOICED))) + IF ((EQ_32(st->sr_core, INT_FS_16k))&&(EQ_16(st->coder_type_fx,UNVOICED))) { - predmode = find_pred_mode(GENERIC, sub(1, narrowBand) /*st->bwidth*/, sr_core, + find_pred_mode(&predmode, GENERIC, sub(1, st->narrowBand) /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate_fx); move16(); } ELSE { - IF (EQ_16(core, TCX_20_CORE)) + IF (EQ_16(st->core_fx, TCX_20_CORE)) { - predmode = find_pred_mode(AUDIO, sub(1,narrowBand)/*st->bwidth*/, sr_core, - &mode_lvq, &mode_lvq_p, st->total_brate_fx ); + find_pred_mode(&predmode, AUDIO, sub(1,st->narrowBand)/*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate_fx ); move16(); } ELSE { - predmode = find_pred_mode(acelp_mode, sub(1, narrowBand)/*st->bwidth*/, sr_core, - &mode_lvq, &mode_lvq_p, st->total_brate_fx ); + find_pred_mode(&predmode, st->coder_type_fx, sub(1, st->narrowBand)/*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate_fx ); move16(); } } - lsf_allocate_fx( sub(31, shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, - bits0, bits1); + lsf_allocate_fx( sub(ENDLSF_NBITS, shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1); nbits_lpc = 0; @@ -112,7 +110,7 @@ Word16 lsf_msvq_ma_decprm( Decoder_State_fx * st, Word16 *param_lpc, Word16 core test(); test(); - IF ( NE_16(acelp_mode, VOICED)&&core==0&&acelp_midLpc) + IF ( NE_16(st->coder_type_fx, VOICED) && st->core_fx==0 && st->acelp_cfg.midLpc) { *param_lpc = get_next_indice_fx(st, bits_midlpc); @@ -151,12 +149,12 @@ Word16 lsf_bctcvq_decprm( /* Returns: number of indices */ Word16 D_lsf_tcxlpc( - const Word16 indices[], /* (I) VQ indices */ - Word16 lsf_q[], /* (O) quantized LSF */ - Word16 lsp_q_ind[], /* (O) quantized LSP (w/o MA prediction) */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ + const Word16 indices[], /* i : VQ indices */ + Word16 lsf_q[], /* o : quantized LSF */ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) */ + Word16 narrowband, /* i : narrowband flag */ + Word16 cdk, /* i : codebook selector */ + Word16 mem_MA[] /* i : MA memory */ ) { Word16 i; @@ -177,6 +175,9 @@ Word16 D_lsf_tcxlpc( M, M, indices + NumIndices, +#ifdef IVAS_MSVQ + 0, NULL, +#endif lsf_q ); @@ -198,6 +199,9 @@ Word16 D_lsf_tcxlpc( M, M, indices + NumIndices, +#ifdef IVAS_MSVQ + 0, NULL, +#endif lsf_rem_q_ind ); NumIndices = add(NumIndices, TCXLPC_IND_NUMSTAGES); @@ -242,10 +246,10 @@ Word16 D_lsf_tcxlpc( /* Returns: number of bits read */ Word16 dec_lsf_tcxlpc( - Decoder_State_fx *st, /* (I/O) Decoder state */ - Word16 **indices, /* (O) Ptr to VQ indices */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk /* (I) codebook selector */ + Decoder_State_fx *st, /* i/o: Decoder state */ + Word16** indices, /* o : Ptr to VQ indices */ + Word16 narrowband, /* i : narrowband flag */ + Word16 cdk /* i : codebook selector */ ) { Word16 i, start_bit_pos; @@ -275,6 +279,9 @@ Word16 dec_lsf_tcxlpc( M, M, flag+1, +#ifdef IVAS_MSVQ + 0, NULL, +#endif lsf_q_ind ); diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index ae7d48e..4269e52 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -2,12 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ - #include "rom_com_fx.h" -#include "stl.h" /*===================================================================*/ /* FUNCTION : normalize_arr() */ @@ -73,6 +71,7 @@ static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) /*-------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16[]) exc_nelp : adapt. excitation/total exc (Q0) */ +/* (Word16[]) gain_buf : floating pitch gain for each subframe */ /*-------------------------------------------------------------------*/ /* _ (Word16[]) shape1_filt_mem_dec : filter memory (Q0) */ @@ -104,6 +103,9 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo Word16 n; Word16 max_val = 0, norm_val = 0; Word16 qGain=0; + SC_VBR_DEC_HANDLE hSC_VBR; + + hSC_VBR = st_fx->hSC_VBR; if (EQ_16(st_fx->last_nelp_mode_dec_fx,1)&&NE_16(st_fx->bwidth_fx,st_fx->last_bwidth_fx)) { @@ -120,7 +122,7 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo BP1_ORDER = 7; move16(); - set32_fx(st_fx->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER*2); + set32_fx(hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER*2); } } ELSE IF ( EQ_16(coder_type,UNVOICED)&&(EQ_16(st_fx->bwidth_fx,WB)||EQ_16(st_fx->bwidth_fx,SWB))) @@ -129,15 +131,15 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo move16(); IF (NE_16(st_fx->last_nelp_mode_dec_fx,1)) { - set16_fx(st_fx->bp1_filt_mem_wb_dec_fx, 0 , BP1_ORDER*2); + set16_fx(hSC_VBR->bp1_filt_mem_wb_dec_fx, 0 , BP1_ORDER*2); } } IF (NE_16(st_fx->last_nelp_mode_dec_fx,1)) { - set16_fx(st_fx->shape1_filt_mem_dec_fx, 0, 10); - set16_fx(st_fx->shape2_filt_mem_dec_fx, 0, 10); - set16_fx(st_fx->shape3_filt_mem_dec_fx, 0, 10); + set16_fx(hSC_VBR->shape1_filt_mem_dec_fx, 0, 10); + set16_fx(hSC_VBR->shape2_filt_mem_dec_fx, 0, 10); + set16_fx(hSC_VBR->shape3_filt_mem_dec_fx, 0, 10); } IF (bfi == 0) @@ -251,7 +253,7 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo normalize_arr(Gains, &qGain, 10, 4); } - generate_nelp_excitation_fx(&(st_fx->nelp_dec_seed_fx), Gains, ptr, gain_fac); + generate_nelp_excitation_fx(&(hSC_VBR->nelp_dec_seed_fx), Gains, ptr, gain_fac); /* o: ptr = nelp_exc in Q=qGain, qGain = 0 always for NB */ test(); @@ -260,11 +262,11 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo { BP1_ORDER =4; move16(); - Scale_sig(st_fx->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, qGain); /* bring filter prev memory from Q0 to qGain */ - pz_filter_sp_fx(bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, st_fx->bp1_filt_mem_wb_dec_fx, + Scale_sig(hSC_VBR->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, qGain); /* bring filter prev memory from Q0 to qGain */ + pz_filter_sp_fx(bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_wb_dec_fx, BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_WB_QF))); - Scale_sig(st_fx->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, -qGain); /* bring filter prev memory from qGain to Q0 */ + Scale_sig(hSC_VBR->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, -qGain); /* bring filter prev memory from qGain to Q0 */ Scale_sig(ptr_tmp, L_FRAME, -qGain); /* bring nelp_exc to Q0 */ Copy(ptr_tmp,ptr,L_FRAME); } @@ -282,7 +284,7 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo tmp = shl(BP1_ORDER,1); FOR (i=0; i < tmp; i++ ) { - max_val = s_max( round_fx( L_shr( st_fx->bp1_filt_mem_nb_dec_fx[i], 16)), max_val ); + max_val = s_max( round_fx( L_shr(hSC_VBR->bp1_filt_mem_nb_dec_fx[i], 16)), max_val ); } norm_val = norm_s(max_val); @@ -292,20 +294,20 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo IF ( norm_val > 0 ) { - Scale_sig32(st_fx->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), norm_val) ; + Scale_sig32(hSC_VBR->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), norm_val) ; Scale_sig(ptr, L_FRAME, norm_val); *Q_exc = add( norm_val, *Q_exc ); } BP1_ORDER = 7; move16(); - pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, st_fx->bp1_filt_mem_nb_dec_fx, + pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_nb_dec_fx, BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_NB_QF_ORDER7))); IF ( norm_val > 0 ) { - Scale_sig32(st_fx->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), -norm_val) ; + Scale_sig32(hSC_VBR->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), -norm_val) ; } @@ -323,7 +325,7 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo test(); IF ( EQ_16(coder_type,UNVOICED )&&(EQ_16(st_fx->bwidth_fx,WB)||EQ_16(st_fx->bwidth_fx,SWB))) { - pz_filter_sp_fx(shape1_num_coef_fx, shape1_den_coef_fx, ptr, ptr_tmp, st_fx->shape1_filt_mem_dec_fx, + pz_filter_sp_fx(shape1_num_coef_fx, shape1_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape1_filt_mem_dec_fx, 10, 10, L_FRAME, (sub(16,SHAPE1_COEF_QF))); Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ @@ -331,11 +333,11 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo { case 1: /* Update other filter memory */ - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, st_fx->shape3_filt_mem_dec_fx, + pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, hSC_VBR->shape3_filt_mem_dec_fx, 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); /* filter the residual to desired shape */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, ptr_tmp, st_fx->shape2_filt_mem_dec_fx, + pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape2_filt_mem_dec_fx, 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ @@ -343,11 +345,11 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo BREAK; case 2: /* Update other filter memory */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, st_fx->shape2_filt_mem_dec_fx, + pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, hSC_VBR->shape2_filt_mem_dec_fx, 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); /* filter the residual to desired shape */ - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, ptr_tmp, st_fx->shape3_filt_mem_dec_fx, + pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, ptr_tmp, hSC_VBR->shape3_filt_mem_dec_fx, 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ @@ -355,9 +357,9 @@ void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Wo BREAK; default: /* Update other filter memory */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, st_fx->shape2_filt_mem_dec_fx, + pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, hSC_VBR->shape2_filt_mem_dec_fx, 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, st_fx->shape3_filt_mem_dec_fx, + pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, hSC_VBR->shape3_filt_mem_dec_fx, 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); BREAK; diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 398f2a4..aaea6ff 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -2,19 +2,23 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ +#include "enh64.h" #define PK_VQ_NOISE_DELTA ((Word16)3277) /* 0.1 in Q15 */ -/* Local functions */ +/*------------------------------------------------------------------------* + * Local function prototypes + *------------------------------------------------------------------------*/ static void dequant_peaks_fx( Decoder_State_fx *st_fx, Word32 *vect_out, const Word32 *peak_gain); static Word16 hvq_dec_pos_fx(Decoder_State_fx *st_fx, Word16 *pos_vec, const Word16 length, const Word16 num_peaks ); static Word16 sparse_dec_pos_fx(Decoder_State_fx *st_fx, Word16 *out, const Word16 length ); - +static void peak_vq_dec_fx(Decoder_State_fx* st_fx, Word32* coefs_out, const Word32 brate, const Word16 num_bits, const Word16* ynrm, + Word16* R, Word16* vq_peak_idx, Word16* Npeaks, const Word16 core); /*-------------------------------------------------------------------------- * hvq_dec_fx() * @@ -31,7 +35,7 @@ void hvq_dec_fx( Word16 *peak_idx, /* o : Peak position vector */ Word16 *Npeaks, /* o : Total number of peaks */ Word32 *coefsq_norm, /* o : Output vector in Q12 */ - const Word16 core + const Word16 core /* i : Core */ ) { Word16 i; @@ -49,7 +53,7 @@ void hvq_dec_fx( bits = sub(bits, 2); } - peak_vq_dec_fx( st_fx, coefsq_norm, (Word16)core_brate, bits, ynrm, R, peak_idx, + peak_vq_dec_fx( st_fx, coefsq_norm, core_brate, bits, ynrm, R, peak_idx, Npeaks, core ); } @@ -59,10 +63,10 @@ void hvq_dec_fx( * Vector de-quantization of MDCT peaks *--------------------------------------------------------------------------*/ -void peak_vq_dec_fx( +static void peak_vq_dec_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word32 *coefs_out, /* o : Output coefficient vector Q12 */ - const Word16 brate, /* i : Core bitrate */ + const Word32 core_brate, /* i : Core bitrate */ const Word16 num_bits, /* i : Number of bits for HVQ */ const Word16 *ynrm, /* i : Envelope coefficients */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ @@ -73,10 +77,10 @@ void peak_vq_dec_fx( { Word16 vq_peaks, i, j, k, FlagN, hcode_l, diff; Word16 bin_th, bin_th2, max_peaks, pvq_bands; - Word16 nf_gains_idx[HVQ_NF_GROUPS], pgain_difidx[HVQ_MAX_PEAKS_32k], pvq_norm[MAX_PVQ_BANDS]; + Word16 nf_gains_idx[HVQ_NF_GROUPS], pgain_difidx[HVQ_MAX_PEAKS], pvq_norm[MAX_PVQ_BANDS]; Word16 gain_bits_array[MAX_PVQ_BANDS]; Word16 pos_bits; - Word32 nf_gains_fx[HVQ_NF_GROUPS], peak_gains_fx[HVQ_MAX_PEAKS_32k]; + Word32 nf_gains_fx[HVQ_NF_GROUPS], peak_gains_fx[HVQ_MAX_PEAKS]; Word16 pvq_vector[HVQ_PVQ_BUF_LEN]; Word16 res_vec[HVQ_THRES_BIN_32k]; Word16 k_sort[HVQ_MAX_PVQ_WORDS]; @@ -109,22 +113,24 @@ void peak_vq_dec_fx( set16_fx( npulses, 0, MAX_PVQ_BANDS ); set16_fx( pvq_inp_vector, 0, HVQ_PVQ_BUF_LEN ); - /* Set bitrate dependent variables */ - IF (EQ_16(brate, HQ_24k40)) + assert((core_brate > HQ_16k40 && core_brate <= HQ_48k) && "HVQ rate not supported"); +PMT("max_peaks equation needs to be converted") + max_peaks = (Word16)((core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS) / HVQ_PEAKS_BPS_DELTA); + /*max_peaks = ((core_brate * HVQ_PEAKS_PER_DELTA / HVQ_PEAKS_BPS_DELTA + HVQ_PEAKS_PER_DELTA_OFFS / HVQ_PEAKS_BPS_DELTA) );*/ +#if 0 { - max_peaks = HVQ_MAX_PEAKS_24k; - move16(); - bin_th = HVQ_THRES_BIN_24k; - move16(); - bin_th2 = HVQ_THRES_BIN_24k/HVQ_NF_GROUPS; - move16(); + #define INV_HVQ_PEAKS_BPS_DELTA_Q31 (Word32)((1.0f/HVQ_PEAKS_BPS_DELTA)*(1<<31)) + #define DELTAINV_HVQ_PEAKS_BPS_DELTA_Q31 (Word32)(((float)HVQ_PEAKS_PER_DELTA/HVQ_PEAKS_BPS_DELTA)*(1<<31)) + + max_peaks = W_round32_s(W_add(W_mult_32_32(HVQ_PEAKS_PER_DELTA_OFFS, INV_HVQ_PEAKS_BPS_DELTA_Q31), W_mult_32_32(core_brate, DELTAINV_HVQ_PEAKS_BPS_DELTA_Q31))); + printf("Fixed point code needed to be completed"); } - ELSE +#endif + bin_th = HVQ_THRES_BIN_24k; + bin_th2 = HVQ_THRES_BIN_24k/HVQ_NF_GROUPS; + IF (GE_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { - max_peaks = HVQ_MAX_PEAKS_32k; - move16(); bin_th = HVQ_THRES_BIN_32k; - move16(); bin_th2 = HVQ_THRES_BIN_32k/HVQ_NF_GROUPS; move16(); } @@ -287,11 +293,12 @@ void peak_vq_dec_fx( pvq_bits = sub(num_bits, diff); /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx(pvq_bits, brate, st_fx->bwidth_fx, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, + pvq_bands = hvq_pvq_bitalloc_fx(pvq_bits, core_brate, st_fx->bwidth_fx, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds); /* safety check in case of bit errors */ - if (pvq_bands == 0) + test(); + if (pvq_bands == 0 && EQ_16(st_fx->element_mode, EVS_MONO)) /* PVQ bands may be zero for IVAS */ { st_fx->BER_detect = 1; move16(); @@ -450,14 +457,14 @@ static void dequant_peaks_fx( static Word16 hvq_dec_pos_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *pos_vec, - const Word16 length, - const Word16 num_peaks + Word16 *pos_vec, /* o : decoded peak positions */ + const Word16 length, /* i : length */ + const Word16 num_peaks /* i : number of peaks */ ) { - Word16 peak_idx[HVQ_MAX_PEAKS_32k]; - Word16 delta[HVQ_MAX_PEAKS_32k]; - Word16 sign_vec[HVQ_MAX_PEAKS_32k]; + Word16 peak_idx[HVQ_MAX_PEAKS]; + Word16 delta[HVQ_MAX_PEAKS]; + Word16 sign_vec[HVQ_MAX_PEAKS]; Word16 mode; Word16 num_bits, tmp; @@ -553,8 +560,8 @@ static Word16 hvq_dec_pos_fx( static Word16 sparse_dec_pos_fx( Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *out, - const Word16 length + Word16* out, /* o : decoded peak positions */ + const Word16 length /* i : length */ ) { Word16 layer2[HVQ_CP_L2_MAX]; diff --git a/lib_dec/pit_dec.c b/lib_dec/pit_dec.c index 7a4e183..b41cc1c 100644 --- a/lib_dec/pit_dec.c +++ b/lib_dec/pit_dec.c @@ -2,15 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include #include +#include +#include "options.h" #include "cnst_fx.h" #include "prot_fx.h" -#include "stl.h" -#include "options.h" - #include "rom_basop_util.h" + #define inv_T0_res InvIntTable /*----------------------------------------------------------* @@ -315,19 +313,23 @@ void Mode2_delta_pit_dec( /*=======================================================================*/ -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ +Word16 pit_decode_fx( /* o : floating pitch value */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ + const Word16 coder_type, /* i : coding type */ Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ Word16 *T0, /* o : close loop integer pitch */ Word16 *T0_frac, /* o : close loop fractional part of the pitch */ Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ + const Word16 L_subfr /* i : subframe length */ +#ifdef ADD_LRTD + , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ +#endif ) { Word16 pitch; /*Q2*/ @@ -392,17 +394,8 @@ Word16 pit_decode_fx( /* o : floating pitch value IF( NE_16(coder_type, AUDIO)) { /* find the number of bits */ - IF( EQ_16(L_frame,L_FRAME)) - { - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } - + nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr,6)]; + move16(); pitch_index = (Word16)get_next_indice_fx( st_fx, nBits ); move16(); } @@ -459,6 +452,54 @@ Word16 pit_decode_fx( /* o : floating pitch value pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } +#ifdef ADD_LRTD + ELSE IF ( EQ_16(st_fx->idchan, 1) && (EQ_16(tdm_Pitch_reuse_flag, 1) || EQ_16(nBits,4) ) ) + { + test(); test(); + /*-------------------------------------------------------* + * Pitch decoding with reusing of primary channel information + *-------------------------------------------------------*/ + Word16 loc_T0, loc_frac, delta, pit_tmp1, pit_tmp2, isubfridx; + + delta = 4; + pit_flag = L_SUBFR; + move16(); move16(); + isubfridx = shr(i_subfr, 6); + IF ( EQ_16(L_subfr, 2 * L_SUBFR ) ) + { + move16(); move16(); + pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */ + pit_tmp2 = tdm_Pri_pitch_buf[shr(add(i_subfr, 1), 6)]; + /*loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]);*/ + loc_T0 = mac_r( L_mult(16384, pit_tmp1, 16384, pit_tmp2) ); + /*loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f);*/ + } + ELSE + { + /*loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR];*/ + loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/ + /*loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f);*/ + } + loc_frac = shr(sub(loc_T0, shl(shr(loc_T0, 6), 6)), 4)); /* Final result in Q 2*/ + loc_T0 = shr (loc_T0, 6); /*Q6 -> Q0*/ + + + limit_T0_fx(L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max); + + IF (nBits > 0) + { + pit_Q_dec_fx(0, pitch_index, nBits, delta, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect); + } + ELSE + { + *T0 = loc_T0; + *T0_frac = loc_frac; + move16(); + move16(); + } +printf("function not tested yet\n"); + } +#endif ELSE { /*-------------------------------------------------------* diff --git a/lib_dec/pitch_extr.c b/lib_dec/pitch_extr.c index f647f64..2ae6972 100644 --- a/lib_dec/pitch_extr.c +++ b/lib_dec/pitch_extr.c @@ -3,16 +3,12 @@ ====================================================================================*/ -/*This file is up to date with trunk rev. 36531*/ - -#include -#include +#include #include +#include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "basop_util.h" -#include "stl.h" -#include "options.h" @@ -32,8 +28,8 @@ *-----------------------------------------------------------------*/ /*port is up to date with trunk 38840*/ void pitch_pred_linear_fit( - const Word16 /*short*/ bfi_cnt, /* i: bfi counter */ /*Q0 */ - const Word16 /*short*/ last_good, /* i: last classification type */ /*Q0 */ + const Word16 /*short*/ bfi_cnt, /* i: bfi counter */ /*Q0 */ + const Word16 /*short*/ last_good, /* i: last classification type */ /*Q0 */ Word32 /*float*/ *old_pitch_buf, /* i: pitch lag buffer */ /*Q16*/ Word32 /*float*/ *old_fpitch, /* i: */ /*Q16*/ Word32 /*float*/ *T0_out, /* o: estimated close loop pitch */ /*Q16*/ diff --git a/lib_dec/post_dec.c b/lib_dec/post_dec.c index b92e222..dc48ea0 100644 --- a/lib_dec/post_dec.c +++ b/lib_dec/post_dec.c @@ -2,15 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - - #include -#include -#include +#include #include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "stl.h" /*---------------------------------------------------------------------* @@ -29,7 +25,6 @@ static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word void post_decoder( Decoder_State_fx *st, - Word16 coder_type, Word16 synth_buf[], Word16 pit_gain[], Word16 pitch[], @@ -46,15 +41,25 @@ void post_decoder( Word16 synth_buf2[PIT_MAX_16k+1+L_FRAME_MAX+M]; Word32 bitrate; Word8 tmp8; + BPF_DEC_HANDLE hBPF; + Word16 coder_type = st->coder_type_fx; - + move16(); +// if (st->hPFstat != NULL || st->hBPF == NULL) +// { +//#ifdef DEBUGGING +// IVAS_ERROR(IVAS_ERR_INTERNAL, "ERROR::: In function post_decoder, at least one post filter handle is not initialized, at frame %d\n", frame); +//#endif +// return; +// } + hBPF = st->hBPF; L_frame = st->L_frame_fx; move16(); nb_subfr = st->nb_subfr; move16(); - pfstat_on_previous = st->pfstat.on; + pfstat_on_previous = st->hPFstat->on; move16(); - st->pfstat.on = 0; + st->hPFstat->on = 0; move16(); bitrate = L_add(st->total_brate_fx, 0); @@ -67,19 +72,19 @@ void post_decoder( /*Adapt Bpf: copy old and current adapt bpf parameters*/ set16_fx(pitch_gain_adjust, st->bpf_gain_param, nb_subfr); - synth = synth_buf + st->old_synth_len; + synth = synth_buf + st->hTcxDec->old_synth_len; synth2 = synth_buf2 + NBPSF_PIT_MAX; - Copy( st->pst_old_syn_fx, synth_buf2, NBPSF_PIT_MAX ); + Copy(hBPF->pst_old_syn_fx, synth_buf2, NBPSF_PIT_MAX ); IF ( st->tcxonly != 0 ) { Copy( synth, synth2, L_frame ); IF ( pfstat_on_previous ) { - Copy( st->pfstat.mem_pf_in+L_SYN_MEM-M, synth-M, M ); + Copy( st->hPFstat->mem_pf_in+L_SYN_MEM-M, synth-M, M ); Residu3_fx ( st->old_Aq_12_8_fx, synth, synth_buf, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_SUBFR, st->pfstat.mem_stp+L_SYN_MEM-M, 0, M ); - scale_st ( synth, synth2, &st->pfstat.gain_prec, L_SUBFR ); + E_UTIL_synthesis ( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_SUBFR, st->hPFstat->mem_stp+L_SYN_MEM-M, 0, M ); + scale_st ( synth, synth2, &st->hPFstat->gain_prec, L_SUBFR ); blend_subfr2(synth2+L_SUBFR/2, synth+L_SUBFR/2, synth2+L_SUBFR/2); } } @@ -108,24 +113,23 @@ void post_decoder( if(pfstat_on_previous==0) { - st->pfstat.reset = 1; + st->hPFstat->reset = 1; move16(); } IF ( EQ_16(st->bwidth_fx,NB)) { - st->pfstat.on = 1; + st->hPFstat->on = 1; move16(); tmp_noise = 0; - nb_post_filt( L_frame, &(st->pfstat), &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, GENERIC, st->BER_detect, tmp ); + nb_post_filt( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, GENERIC, st->BER_detect, tmp ); } ELSE { - st->pfstat.on = 0; + st->hPFstat->on = 0; move16(); tmp_noise = 0; - nb_post_filt( L_frame, &(st->pfstat), &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, AUDIO, st->BER_detect, tmp ); + nb_post_filt( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, AUDIO, st->BER_detect, tmp ); } - Copy(synth2_pe, synth2, L_frame); tmp = synth2[-1]; @@ -136,20 +140,20 @@ void post_decoder( { if(pfstat_on_previous==0) { - st->pfstat.reset = 1; + st->hPFstat->reset = 1; move16(); } IF ( GE_16(st->last_bwidth_fx,WB)) { - st->pfstat.on = 1; + st->hPFstat->on = 1; move16(); - formant_post_filt( &(st->pfstat), synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); + formant_post_filt( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); } ELSE { - st->pfstat.on = 0; + st->hPFstat->on = 0; move16(); - formant_post_filt( &(st->pfstat), synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); + formant_post_filt( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); } } @@ -170,7 +174,7 @@ void post_decoder( Copy( synth2, signal_out, L_frame ); /* Update synth2 memory */ - Copy( synth_buf2 + L_frame, st->pst_old_syn_fx, NBPSF_PIT_MAX ); + Copy( synth_buf2 + L_frame, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX ); return; diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 5031b0e..5e90a67 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -2,13 +2,197 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include +#include "options.h" #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" + /*===================================================================*/ + /* FUNCTION : struct DTFS_fx::dequant_cw_fx () */ + /*-------------------------------------------------------------------*/ + /* PURPOSE : Dequantize QPPP prototype */ + /*-------------------------------------------------------------------*/ + /* INPUT ARGUMENTS : */ + /* _ (Word16) pl: previous lag */ + /* _ (Word16) p_idx: Power index */ + /* _ (Word16[]) a_idx: Amplitude indices, 2 words */ + /* _ (struct DTFS_fx) X : prototype in polar domain */ + /* (Word16) lag: length of prototype */ + /*-------------------------------------------------------------------*/ + /* OUTPUT ARGUMENTS : */ + /* _ (struct DTFS_fx) X : prototype in polar domain */ + /* (Word16) lag: length of prototype in time domain */ + /* (Word16 []) a: amplitude of harmonics, normalized */ + /* (Word16) Q: norm factor of a */ + /* _ (Word16[]) curr_erb: Quantized current ERB, Q13 */ + /*-------------------------------------------------------------------*/ + /* INPUT/OUTPUT ARGUMENTS : */ + /* _ (Word16[]) lasterb: ERB history for differential */ + /* quantization, Q13 */ + /* _ (Word16) Lgain: low band power history, log domain, Q11 */ + /* _ (Word16) Hgain: high band power history, log domain, Q11 */ + /*-------------------------------------------------------------------*/ + /* RETURN ARGUMENTS : _ None. */ + /*-------------------------------------------------------------------*/ + /* CALLED FROM : TX/RX */ + /*===================================================================*/ +static void DTFS_dequant_cw_fx( + Word16 pl_fx, /* i : Previous lag */ + Word16 POWER_IDX_fx, /* i : POWER index */ + const Word16* AMP_IDX_fx, /* i : Amp Shape index */ + Word16* lastLgainD_fx, /* i/o: low band last gain */ + Word16* lastHgainD_fx, /* i/o: high band last gain */ + Word16* lasterbD_fx, /* i/o: last frame ERB vector */ + DTFS_STRUCTURE_FX* X_fx, /* o : DTFS structure dequantized */ + Word16 num_erb_fx +) + +{ + Word16 tmp_fx, mfreq_fx[NUM_ERB_WB], curr_erb_fx[NUM_ERB_WB]; + const Word16* PowerCB_fx = NULL; + Word16 slot_fx[NUM_ERB_WB]; + Word16 Ql, Qh, n; + Word32 Ltemp_fx, logLag_fx; + Word16 exp, frac, exp1; + Word32 L_tmp, L_temp; + Word32 L_tmp2; + + IF(num_erb_fx == NUM_ERB_NB) + { + PowerCB_fx = PowerCB_NB_fx; + move16(); + } + ELSE IF(num_erb_fx == NUM_ERB_WB) + { + PowerCB_fx = PowerCB_WB_fx; + move16(); + } + + /* Amplitude Dequantization */ + + erb_add_fx(curr_erb_fx, X_fx->lag_fx, lasterbD_fx, pl_fx, AMP_IDX_fx, num_erb_fx); + + curr_erb_fx[0] = mult_r(curr_erb_fx[1], 9830);/* 0.3 inQ15 leaves curr_erb in Q13 */ + curr_erb_fx[sub(num_erb_fx, 2)] = mult_r(curr_erb_fx[sub(num_erb_fx, 3)], 9830);/* Q13 */ + + move16(); + + curr_erb_fx[sub(num_erb_fx, 1)] = 0; + + erb_slot_fx(X_fx->lag_fx, slot_fx, mfreq_fx, num_erb_fx); + + /* mfreq normalized (2.56) in Q15 */ + DTFS_erb_inv_fx(curr_erb_fx, slot_fx, mfreq_fx, X_fx, num_erb_fx); + + + /* Back up the lasterbD memory after power normalization */ + + DTFS_setEngyHarm_fx(236, 2828, 0, 2828, 1, 0, &Ql, X_fx); + DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx); + + /* Need to unify the Q factors of both bands */ + X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ + n = sub(Ql, Qh); /* compare band Q factors */ + + + + + /* This logic adjusts difference between Q formats of both bands */ + IF(n < 0) + rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); + ELSE IF(n > 0) + rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); + + DTFS_to_erb_fx(*X_fx, lasterbD_fx); + + + /* Power Dequantization */ + + tmp_fx = shl(POWER_IDX_fx, 1); /* tmp=2*POWER_IDX */ + *lastLgainD_fx = add(*lastLgainD_fx, PowerCB_fx[tmp_fx]); /* Q11 */ + *lastHgainD_fx = add(*lastHgainD_fx, PowerCB_fx[tmp_fx + 1]); /* Q11 */ + + L_tmp = L_deposit_h(X_fx->lag_fx); /* Q16 */ + exp = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, exp); + frac = Log2_norm_lc(L_tmp); + exp = sub(30, add(exp, 16)); + L_tmp = Mpy_32_16(exp, frac, 12330);/* Q13 */ /* 10*log10(2) in Q12*/ + Ltemp_fx = L_shl(L_tmp, 10);/* Q23 */ + + + logLag_fx = Mult_32_16(Ltemp_fx, 0x6666); /* logLag=log10(lag), Q26 */ + + Ltemp_fx = L_sub(L_shr(L_deposit_h(*lastLgainD_fx), 1), logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ + + /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Lgain/lag, Q15 */ + + L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ + L_tmp = L_shr(L_tmp, 8); /* Q16 */ + frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ + L_tmp = Pow2(14, frac); + exp1 = sub(exp1, 14); + L_temp = L_shl(L_tmp, add(exp1, 15)); /* Q15 */ + + L_tmp2 = L_temp; + if (GE_32(L_temp, 2147483647)) + { + L_temp = L_shl(L_tmp, 15); /*Q(15-exp1) */ + } + + n = norm_l(L_temp); + Ltemp_fx = L_shl(L_temp, n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ + + IF(GE_32(L_tmp2, 2147483647)) + { + DTFS_setEngyHarm_fx(236, 2828, 0, 2828, Ltemp_fx, add(15, sub(n, exp1)), &Ql, X_fx); + } + ELSE + { + DTFS_setEngyHarm_fx(236, 2828, 0, 2828, Ltemp_fx, add(15,n), &Ql, X_fx); + } + + Ltemp_fx = L_sub(L_shr(L_deposit_h(*lastHgainD_fx), 1), logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ + /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Hgain/lag, Q15 */ + L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ /* Q24 */ + L_tmp = L_shr(L_tmp, 8); /* Q16 */ + frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ + L_tmp = Pow2(14, frac); + exp1 = sub(exp1, 14); + L_temp = L_shl(L_tmp, exp1 + 15); /* Q15 */ + + L_tmp2 = L_temp; + if (GE_32(L_temp, 2147483647)) + { + L_temp = L_shl(L_tmp, 15); /*Q(15-exp1) */ + } + + + n = norm_l(L_temp); + Ltemp_fx = L_shl(L_temp, n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ + + IF(GE_32(L_tmp2, 2147483647)) + { + DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add(15, sub(n, exp1)), &Qh, X_fx); + } + ELSE + { + DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx,2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add(15, n), &Qh, X_fx); + } + + + /* Need to unify the Q factors of both bands */ + X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ + n = sub(Ql, Qh); /* compare band Q factors */ + + + + IF(n < 0) + rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); + ELSE IF(n > 0) + rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); +} /*===================================================================*/ /* FUNCTION : void ppp_quarter_decoder_fx () */ /*-------------------------------------------------------------------*/ @@ -49,21 +233,20 @@ /*-------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*===================================================================*/ - -void ppp_quarter_decoder_fx( +ivas_error ppp_quarter_decoder_fx( DTFS_STRUCTURE_FX *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ - Word16 prevCW_lag_fx, /* i : Previous lag */ - Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ - Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ - Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ - Word16 bfi, /* i : FER flag */ - Word16 *S_fx, /* i : sine table, Q15 */ - Word16 *C_fx, /* i : cosine table, Q15 */ + Word16 prevCW_lag_fx, /* i : Previous lag */ + Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ + Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ + Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ + Word16 bfi, /* i : FER flag */ + Word16 *S_fx, /* i : sine table, Q15 */ + Word16 *C_fx, /* i : cosine table, Q15 */ DTFS_STRUCTURE_FX PREV_CW_D_FX, /* i : Previous DTFS */ Decoder_State_fx *st_fx ) { - DTFS_STRUCTURE_FX *PREVDTFS_FX = DTFS_new_fx(); + DTFS_STRUCTURE_FX *PREVDTFS_FX; Word16 AMP_IDX_fx[2]; Word16 temp_pl_fx = prevCW_lag_fx, temp_l_fx = CURRCW_Q_DTFS_FX->lag_fx; Word16 temp_fx; @@ -74,7 +257,14 @@ void ppp_quarter_decoder_fx( Word32 temp32d_fx,temp32n_fx; Word32 L_tmp, L_tmp1; Word16 tmp, exp; + ivas_error error; + error = IVAS_ERR_OK; + move16(); + IF ((error = DTFS_new_fx(&PREVDTFS_FX)) != IVAS_ERR_OK) + { + return error; + } IF ( EQ_16(CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,4000 )) { @@ -155,8 +345,7 @@ void ppp_quarter_decoder_fx( Q2phaseShift_fx(CURRCW_Q_DTFS_FX,temp_fx,CURRCW_Q_DTFS_FX->lag_fx,S_fx,C_fx); } - free(PREVDTFS_FX); - - return; + count_free(PREVDTFS_FX); + return error; } diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index a3e1361..0faeb82 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -2,29 +2,33 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" -#include "basop_util.h" -static Word16 get_pvq_splits_fx(Decoder_State_fx *st_fx, const Word16 band_bits, const Word16 sfmsize, Word16 *bits); - -static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, const Word16 density, const Word16 opp_sz, const Word16 near_sz, Word16 *index_phi); - -/* Decode band with PVQ */ +/*-------------------------------------------------------------------* + * Local prototypes + * + *-------------------------------------------------------------------*/ +static Word16 get_pvq_splits_fx(Decoder_State_fx* st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, Word16* bits); +static void densitySymbolIndexDecode_fx(Decoder_State_fx* st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 density, const Word16 opp_sz, const Word16 near_sz, Word16* index_phi); +/*-------------------------------------------------------------------* + * pvq_decode_band() + * + *-------------------------------------------------------------------*/ static void pvq_decode_band_fx( - Decoder_State_fx *st_fx, - Word16 *pulse_vector, - Word16 *npulses, - Word16 *coefs_quant, - const Word16 sfmsize, - const Word16 band_bits, - Word16 *bits_left, - const Word16 strict_bits -) + Decoder_State_fx *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16* pulse_vector, /* i/o: decoded integer shape vector */ + Word16* npulses, /* i/o: number of pulses */ + Word16* coefs_quant, /* i/o: decoded coefficients buffer */ + const Word16 sfmsize, /* i : band length */ + const Word16 band_bits, /* i : assigned bit budget */ + Word16* bits_left, /* i/o: number of bits / bits remaining */ + const Word16 strict_bits /* i : Conservative rounding flag */ +) { Word16 K_val; @@ -37,7 +41,8 @@ static void pvq_decode_band_fx( Word16 sg_part[MAX_SPLITS+1]; Word16 idx_sort[MAX_SPLITS+1]; Word16 js, band_bits_tot, split_bit; - Np = get_pvq_splits_fx(st_fx, band_bits, sfmsize, &split_bit); + + Np = get_pvq_splits_fx(st_fx, hPVQ, band_bits, sfmsize, &split_bit); band_bits_tot = sub(band_bits, split_bit); dim_parts = extract_h(L_mult(negate(sfmsize),lim_neg_inv_tbl_fx[Np])); @@ -57,7 +62,7 @@ static void pvq_decode_band_fx( set16_fx( g_part_neg, -32768, Np ); IF( GT_16(Np, 1)) { - decode_energies_fx( st_fx, Np, dim_part, bits_part, g_part_neg, band_bits_tot, bits_left, sfmsize, strict_bits ); + decode_energies_fx( st_fx, hPVQ, Np, dim_part, bits_part, g_part_neg, band_bits_tot, bits_left, sfmsize, strict_bits ); } ELSE { @@ -89,7 +94,7 @@ static void pvq_decode_band_fx( IF( K_val > 0 ) { - pvq_decode_fx(st_fx, coefs_quant + part_start[js], pulse_vector + part_start[js], + pvq_decode_fx(st_fx, hPVQ, coefs_quant + part_start[js], pulse_vector + part_start[js], K_val, dim_part[js], g_part_neg[js]); } ELSE @@ -104,9 +109,9 @@ static void pvq_decode_band_fx( void pvq_decode_frame_fx( Decoder_State_fx *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ + Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *npulses, /* o : number of pulses per band */ + Word16 *pulse_vector, /* o : non-normalized pulse shapes */ const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ const Word16 *sfmsize, /* i : band sizes */ @@ -124,8 +129,10 @@ void pvq_decode_frame_fx( Word16 R_sort[NB_SFM]; Word16 is, i_sort[NB_SFM]; Word16 strict_bits; + PVQ_DEC_DATA pvq_dec; + PVQ_DEC_HANDLE hPVQ = &pvq_dec; - rc_dec_init_fx(st_fx, pvq_bits); + rc_dec_init_fx(st_fx, hPVQ, pvq_bits); bits = shl(sub(pvq_bits, RC_BITS_RESERVED), 3); @@ -141,13 +148,13 @@ void pvq_decode_frame_fx( IF (core == ACELP_CORE) { - strict_bits = 1; + strict_bits = PVQ_CONS; move16(); srt_vec_ind16_fx (R, R_sort, i_sort, nb_sfm); } ELSE { - strict_bits = 0; + strict_bits = PVQ_NEAREST; move16(); FOR (i = 0; i < nb_sfm; i++) { @@ -164,10 +171,10 @@ void pvq_decode_frame_fx( move16(); IF(R[is] > 0) { - bandBitsAdjustment_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ + bandBitsAdjustment_fx(hPVQ->rc_num_bits_fx, hPVQ->rc_range_fx, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ &band_bits, &bits_left, &bit_pool); /* outputs */ - pvq_decode_band_fx( st_fx, &pulse_vector[sfm_start[is]], &npulses[is], + pvq_decode_band_fx( st_fx, hPVQ, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, &bits_left, strict_bits); @@ -186,7 +193,7 @@ void pvq_decode_frame_fx( } } - rc_dec_finish_fx(st_fx); + rc_dec_finish_fx(st_fx, hPVQ); } /*-------------------------------------------------------------------* @@ -218,8 +225,11 @@ Word16 pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - st_fx->ber_occured_in_pvq = 0; - move16(); + IF (st_fx->hHQ_core != NULL) + { + st_fx->hHQ_core->ber_occured_in_pvq = 0; + move16(); + } R_upd = shl(bits_tot, 3); assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); @@ -258,10 +268,12 @@ Word16 pvq_core_dec_fx( nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred); - - IF( st_fx->ber_occured_in_pvq != 0 ) + IF(st_fx->hHQ_core != NULL) { - set16_fx( fg_pred, 1, nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ + IF(st_fx->hHQ_core->ber_occured_in_pvq != 0) + { + set16_fx(fg_pred, 1, nb_sfm); /* low complex ECU action in case of detetected BER in PVQ decoding */ + } } apply_gain_fx(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); *Q_coefs = 12; @@ -269,8 +281,13 @@ Word16 pvq_core_dec_fx( return bits_tot; } +/*-------------------------------------------------------------------* + * decode_energies() + * + *-------------------------------------------------------------------*/ void decode_energies_fx( Decoder_State_fx *st_fx, + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 Np, Word16 *dim_part, Word16 *bits_part, @@ -303,9 +320,9 @@ void decode_energies_fx( r_dim = sub(dim, l_dim); obtainEnergyQuantizerDensity_fx(dim, qband, &density); - rangeCoderFinalizationFBits_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx, &qzero); + rangeCoderFinalizationFBits_fx(hPVQ->rc_num_bits_fx, hPVQ->rc_range_fx, &qzero); - densitySymbolIndexDecode_fx( st_fx, density, r_dim, l_dim, &index_phi); + densitySymbolIndexDecode_fx( st_fx, hPVQ, density, r_dim, l_dim, &index_phi); densityAngle2RmsProjDec_fx(density, index_phi, &ir, &il, &oppRQ3); @@ -326,7 +343,7 @@ void decode_energies_fx( move16(); } - NearOppSplitAdjustment_fx( qband, qzero, st_fx->rc_num_bits_fx, st_fx->rc_range_fx, *bits_left, + NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits_fx, hPVQ->rc_range_fx, *bits_left, strict_bits, Np, dim_part[0], dim_part[Np-1], l_dim, r_dim, oppRQ3, &l_bits, &r_bits, bits_left); @@ -334,7 +351,7 @@ void decode_energies_fx( IF (GT_16(l_Np, 1)) { - decode_energies_fx( st_fx, l_Np, dim_part, bits_part, g_part, l_bits, bits_left, l_dim, strict_bits ); + decode_energies_fx( st_fx, hPVQ, l_Np, dim_part, bits_part, g_part, l_bits, bits_left, l_dim, strict_bits ); } ELSE { @@ -344,7 +361,7 @@ void decode_energies_fx( IF (GT_16(r_Np, 1)) { - decode_energies_fx( st_fx, r_Np, &dim_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_dim, strict_bits ); + decode_energies_fx( st_fx, hPVQ, r_Np, &dim_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_dim, strict_bits ); } ELSE { @@ -355,12 +372,18 @@ void decode_energies_fx( return; } -static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, - const Word16 density, - const Word16 opp_sz, - const Word16 near_sz, - Word16 *index_phi - ) +/*-------------------------------------------------------------------* + * densitySymbolIndexDecode() + * + *-------------------------------------------------------------------*/ +static void densitySymbolIndexDecode_fx( + Decoder_State_fx *st_fx, + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + const Word16 density, + const Word16 opp_sz, + const Word16 near_sz, + Word16 *index_phi +) { Word16 density1, density2; Word32 tmp1; @@ -390,7 +413,7 @@ static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, tot = L_mac0(1L, density, add(density, 1)); IF (c == 0) { - dec_freq = rc_decode_fx(st_fx, tot); + dec_freq = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); density1 = add(density, 1); acc = L_mult0(density1, density1); @@ -401,7 +424,7 @@ static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, } ELSE IF (EQ_16(c, density)) { - dec_freq = rc_decode_fx(st_fx, tot); + dec_freq = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); alpha = getSqrtWord32(dec_freq); sym_freq = L_add(L_shl(alpha, 1), 1); @@ -415,7 +438,7 @@ static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ tot = L_add(L_add(acc, (Word32)density), 1L); - dec_freq = rc_decode_fx(st_fx, tot); + dec_freq = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); acc = L_mult0(sub(density_c, 1), density_c); Mpy_32_16_ss(acc, c, &acc, &lsb); @@ -487,7 +510,7 @@ static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, } } - rc_dec_update_fx(st_fx, cum_freq, sym_freq); + rc_dec_update_fx(st_fx, hPVQ, cum_freq, sym_freq); *index_phi = alpha; return; } @@ -499,11 +522,12 @@ static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, * Retrieve the number of segments *--------------------------------------------------------------------------*/ -static Word16 get_pvq_splits_fx( /* o : Number of segments */ - Decoder_State_fx *st_fx, /* i/o: Decoder state */ - const Word16 band_bits, /* i : Band bit rate */ - const Word16 sfmsize, /* i : Band width */ - Word16 *bits /* o : Used bits */ +static Word16 get_pvq_splits_fx( /* o : Number of segments */ + Decoder_State_fx *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + const Word16 band_bits, /* i : Band bit budget */ + const Word16 sfmsize, /* i : Band width */ + Word16 *bits /* o : Used bits */ ) { Word16 Np, i; @@ -530,7 +554,7 @@ static Word16 get_pvq_splits_fx( /* o : Number of segments */ acc = L_mult0(8*THR_ADD_SPLIT, sfmsize); IF (GT_32(band_bits, acc)) { - flag = rc_dec_bits_fx(st_fx, 1); + flag = rc_dec_bits_fx(st_fx, hPVQ, 1); *bits = 8; move16(); if (flag != 0) diff --git a/lib_dec/pvq_decode_fx.c b/lib_dec/pvq_decode_fx.c index 189d53d..73fab37 100644 --- a/lib_dec/pvq_decode_fx.c +++ b/lib_dec/pvq_decode_fx.c @@ -2,9 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "prot_fx.h" #include "rom_com_fx.h" @@ -16,11 +15,12 @@ void pvq_decode_fx( Decoder_State_fx *st_fx, - Word16 *xq, /* o: decoded vector (Q15) */ - Word16 *y, /* o: decoded vector (non-scaled int) */ - const Word16 k_val, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + Word16 *xq, /* o: decoded vector (Q15) */ + Word16 *y, /* o: decoded vector (non-scaled int) */ + const Word16 k_val, /* i: number of allocated pulses */ + const Word16 dim, /* i: Length of vector */ + const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ ) { Word16 i; @@ -31,32 +31,34 @@ void pvq_decode_fx( Word16 neg_gain_norm, shift_num,shift_den,shift_tot; Word32 L_yy,L_isqrt,L_tmp; - UWord16 u16_tmp; + UWord16 u16_tmp; entry = get_size_mpvq_calc_offset_fx(dim, k_val, h_mem); /* get size & prepare H(adaptive table for entry.size=N_MPVQ(dim,k_val) */ + IF( NE_16(dim, 1)) { - entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, 1); - entry.index = rc_dec_uniform_fx(st_fx, entry.size); - + entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, hPVQ, 1); + entry.index = rc_dec_uniform_fx(st_fx, hPVQ, entry.size); - /* safety check in case of bit errors */ - test(); - IF( GE_32(entry.index, entry.size)||st_fx->ber_occured_in_pvq!=0) + IF(st_fx->hHQ_core != NULL) { - st_fx->ber_occured_in_pvq = 1; - move16(); - st_fx->BER_detect = 1; - move16(); - entry.index = 0; - move16(); /* a zero index will essentially disable PVQ index decompostion complexity */ + /* safety check in case of bit errors */ + test(); + IF(GE_32(entry.index, entry.size) || st_fx->hHQ_core->ber_occured_in_pvq != 0) + { + st_fx->hHQ_core->ber_occured_in_pvq = 1; + move16(); + st_fx->BER_detect = 1; + move16(); + entry.index = 0; + move16(); /* a zero index will essentially disable PVQ index decompostion complexity */ + } } - } ELSE { - entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, 1); /* always a single sign bit */ + entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, hPVQ, 1); /* always a single sign bit */ entry.index = L_deposit_l(0); } diff --git a/lib_dec/range_dec_fx.c b/lib_dec/range_dec_fx.c index 5fb30ec..e3f48b1 100644 --- a/lib_dec/range_dec_fx.c +++ b/lib_dec/range_dec_fx.c @@ -2,18 +2,18 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ +#include +#include "options.h" /* Compilation switches */ +#include "cnst_fx.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -static Word16 rc_dec_read_fx(Decoder_State_fx *st_fx); +/*-------------------------------------------------------------------* + * Local prototypes + *-------------------------------------------------------------------*/ +static Word16 rc_dec_read_fx(Decoder_State_fx *st_fx, PVQ_DEC_HANDLE hPVQ); /*-------------------------------------------------------------------* * rc_dec_init() * @@ -21,24 +21,25 @@ static Word16 rc_dec_read_fx(Decoder_State_fx *st_fx); *-------------------------------------------------------------------*/ void rc_dec_init_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder State */ + Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 tot_bits /* i : Total bit budget */ ) { Word16 i; - st_fx->rc_low_fx = L_deposit_l(0); - st_fx->rc_range_fx = 0xffffffff; + hPVQ->rc_low_fx = L_deposit_l(0); + hPVQ->rc_range_fx = 0xffffffff; move32(); - st_fx->rc_num_bits_fx = 0; + hPVQ->rc_num_bits_fx = 0; move16(); - st_fx->rc_offset_fx = add(tot_bits, st_fx->next_bit_pos_fx); - st_fx->rc_end_fx = st_fx->rc_offset_fx; + hPVQ->rc_offset_fx = add(tot_bits, st_fx->next_bit_pos_fx); + hPVQ->rc_end_fx = hPVQ->rc_offset_fx; move16(); FOR (i = 0; i < 4; i++) { - st_fx->rc_low_fx = UL_addNsD(UL_lshl(st_fx->rc_low_fx, 8), UL_deposit_l(rc_dec_read_fx(st_fx))); + hPVQ->rc_low_fx = UL_addNsD(UL_lshl(hPVQ->rc_low_fx, 8), UL_deposit_l(rc_dec_read_fx(st_fx, hPVQ))); } } @@ -49,7 +50,8 @@ void rc_dec_init_fx( *-------------------------------------------------------------------*/ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ + Word16* BER_detect, /* o : Bit error detection flag */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ UWord32 tot /* i : Total cumulative frequency */ ) { @@ -58,22 +60,22 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ UWord16 sgn; inv = UL_inverse(tot, &exp); - Mpy_32_32_uu(st_fx->rc_range_fx, inv, &(st_fx->rc_help_fx), &lsb);/*0+exp-32*/ - st_fx->rc_help_fx = UL_lshr(st_fx->rc_help_fx, sub(exp, 32)); + Mpy_32_32_uu(hPVQ->rc_range_fx, inv, &(hPVQ->rc_help_fx), &lsb);/*0+exp-32*/ + hPVQ->rc_help_fx = UL_lshr(hPVQ->rc_help_fx, sub(exp, 32)); - exp_den = norm_ul(st_fx->rc_help_fx); - UL_tmp2 = UL_lshl(st_fx->rc_help_fx, exp_den); - exp_num = sub(norm_ul(st_fx->rc_low_fx), 1); - UL_tmp1 = UL_lshl(st_fx->rc_low_fx, exp_num); + exp_den = norm_ul(hPVQ->rc_help_fx); + UL_tmp2 = UL_lshl(hPVQ->rc_help_fx, exp_den); + exp_num = sub(norm_ul(hPVQ->rc_low_fx), 1); + UL_tmp1 = UL_lshl(hPVQ->rc_low_fx, exp_num); exp = add(32, sub(exp_num, exp_den)); val = UL_div(UL_tmp1, UL_tmp2); val = UL_lshr(val, exp); - UL_tmp1 = UL_Mpy_32_32(val, st_fx->rc_help_fx); - UL_tmp2 = UL_Mpy_32_32(UL_addNsD(val, 1), st_fx->rc_help_fx); - UL_tmp1 = UL_subNsD(st_fx->rc_low_fx, UL_tmp1); - UL_tmp2 = UL_subNsD(st_fx->rc_low_fx, UL_tmp2); + UL_tmp1 = UL_Mpy_32_32(val, hPVQ->rc_help_fx); + UL_tmp2 = UL_Mpy_32_32(UL_addNsD(val, 1), hPVQ->rc_help_fx); + UL_tmp1 = UL_subNsD(hPVQ->rc_low_fx, UL_tmp1); + UL_tmp2 = UL_subNsD(hPVQ->rc_low_fx, UL_tmp2); if (UL_tmp2 < UL_tmp1) { val = UL_addNsD(val, 1); @@ -83,7 +85,7 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ UL_tmp1 = UL_subNs(tot,val,&sgn); IF ( sgn != 0) { - st_fx->BER_detect = 1; + *BER_detect = 1; move16(); return 0; } @@ -99,19 +101,20 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ void rc_dec_update_fx( Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ UWord32 cum_freq, /* i : Cumulative frequency */ UWord32 sym_freq /* i : Symbol frequency */ ) { - st_fx->rc_low_fx = UL_subNsD(st_fx->rc_low_fx, UL_Mpy_32_32(cum_freq, st_fx->rc_help_fx)); /*0+0*/ - st_fx->rc_range_fx = UL_Mpy_32_32(st_fx->rc_help_fx, sym_freq); + hPVQ->rc_low_fx = UL_subNsD(hPVQ->rc_low_fx, UL_Mpy_32_32(cum_freq, hPVQ->rc_help_fx)); /*0+0*/ + hPVQ->rc_range_fx = UL_Mpy_32_32(hPVQ->rc_help_fx, sym_freq); - WHILE (st_fx->rc_range_fx < 1<<24) + WHILE (hPVQ->rc_range_fx < 1<<24) { L_sub(0, 0); /* For comparision in while*/ - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, 8); - st_fx->rc_low_fx = UL_addNsD(UL_lshl(st_fx->rc_low_fx, 8), UL_deposit_l(rc_dec_read_fx(st_fx))); - st_fx->rc_range_fx = UL_lshl(st_fx->rc_range_fx, 8); + hPVQ->rc_num_bits_fx = add(hPVQ->rc_num_bits_fx, 8); + hPVQ->rc_low_fx = UL_addNsD(UL_lshl(hPVQ->rc_low_fx, 8), UL_deposit_l(rc_dec_read_fx(st_fx, hPVQ))); + hPVQ->rc_range_fx = UL_lshl(hPVQ->rc_range_fx, 8); } } @@ -123,24 +126,25 @@ void rc_dec_update_fx( Word32 rc_dec_bits_fx( /* i : Decoded value */ Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 bits /* i : Number of bits */ ) { Word32 value; - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, bits); + hPVQ->rc_num_bits_fx = add(hPVQ->rc_num_bits_fx, bits); IF (GT_16(bits, 16)) { - st_fx->rc_offset_fx = sub(st_fx->rc_offset_fx, sub(bits, 16)); - value = UL_lshl(UL_deposit_l(get_indice_fx(st_fx, st_fx->rc_offset_fx, sub(bits, 16))), 16); - st_fx->rc_offset_fx = sub(st_fx->rc_offset_fx, 16); - value = UL_or(value, UL_deposit_l(get_indice_fx(st_fx, st_fx->rc_offset_fx, 16))); + hPVQ->rc_offset_fx = sub(hPVQ->rc_offset_fx, sub(bits, 16)); + value = UL_lshl(UL_deposit_l(get_indice_fx(st_fx, hPVQ->rc_offset_fx, sub(bits, 16))), 16); + hPVQ->rc_offset_fx = sub(hPVQ->rc_offset_fx, 16); + value = UL_or(value, UL_deposit_l(get_indice_fx(st_fx, hPVQ->rc_offset_fx, 16))); } ELSE { - st_fx->rc_offset_fx = sub(st_fx->rc_offset_fx, bits); - value = UL_deposit_l(get_indice_fx(st_fx, st_fx->rc_offset_fx, bits)); + hPVQ->rc_offset_fx = sub(hPVQ->rc_offset_fx, bits); + value = UL_deposit_l(get_indice_fx(st_fx, hPVQ->rc_offset_fx, bits)); } return value; @@ -152,8 +156,9 @@ Word32 rc_dec_bits_fx( /* i : Decoded value */ * Encode with uniform distribution *-------------------------------------------------------------------*/ -UWord32 rc_dec_uniform_fx( /* i : Decoded value */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ +UWord32 rc_dec_uniform_fx( /* i : Decoded value */ + Decoder_State_fx *st_fx, /* i/o: Decoder State */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ UWord32 tot /* i : Maximum value */ ) { @@ -163,16 +168,16 @@ UWord32 rc_dec_uniform_fx( /* i : Decoded value */ IF (LE_16(n, 8)) { - value = rc_decode_fx(st_fx, tot); - rc_dec_update_fx(st_fx, value, 1); + value = rc_decode_fx(&st_fx->BER_detect, hPVQ, tot); + rc_dec_update_fx(st_fx, hPVQ, value, 1); } ELSE { n = sub(n, 8); - value = rc_decode_fx(st_fx, UL_addNsD(UL_lshr(tot, n), 1)); - rc_dec_update_fx(st_fx, value, 1); + value = rc_decode_fx(&st_fx->BER_detect, hPVQ, UL_addNsD(UL_lshr(tot, n), 1)); + rc_dec_update_fx(st_fx, hPVQ, value, 1); value = UL_lshl(value, n); - value = UL_or(value, rc_dec_bits_fx(st_fx, n)); + value = UL_or(value, rc_dec_bits_fx(st_fx, hPVQ, n)); } return value; @@ -184,9 +189,12 @@ UWord32 rc_dec_uniform_fx( /* i : Decoded value */ * Finalize range decoder *-------------------------------------------------------------------*/ -void rc_dec_finish_fx(Decoder_State_fx *st_fx) +void rc_dec_finish_fx( + Decoder_State_fx *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ +) { - st_fx->next_bit_pos_fx = st_fx->rc_end_fx; + st_fx->next_bit_pos_fx = hPVQ->rc_end_fx; } /*-------------------------------------------------------------------* @@ -196,11 +204,14 @@ void rc_dec_finish_fx(Decoder_State_fx *st_fx) *-------------------------------------------------------------------*/ -static Word16 rc_dec_read_fx(Decoder_State_fx *st_fx) +static Word16 rc_dec_read_fx( + Decoder_State_fx* st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ /* i/o: PVQ decoder handle */ +) { Word16 bits; - bits = sub( st_fx->rc_end_fx, st_fx->next_bit_pos_fx ); + bits = sub(hPVQ->rc_end_fx, st_fx->next_bit_pos_fx ); /* If the end of the buffer has been reached, pad the last byte with zeros */ IF(sub(bits, 8) < 0) diff --git a/lib_dec/re8_dec_fx.c b/lib_dec/re8_dec_fx.c index 14a590c..96f76a1 100644 --- a/lib_dec/re8_dec_fx.c +++ b/lib_dec/re8_dec_fx.c @@ -2,9 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------------- * re8_dec_fx() diff --git a/lib_dec/rom_dec_fx.c b/lib_dec/rom_dec_fx.c index 561b1b8..2f2848c 100644 --- a/lib_dec/rom_dec_fx.c +++ b/lib_dec/rom_dec_fx.c @@ -2,10 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "stl.h" +#include +#include "options.h" #include "cnst_fx.h" /* Common constants */ -#include "basop_util.h" +/* clang-format off */ /* 125 375 750 1250 2000 4000 8000 16000 24000 */ const Word16 gw_fx[Lgw_max] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* frequency group start bins for transient analysis */ @@ -16,7 +17,7 @@ const Word16 gw_len_inv_fx[Lgw_max-1] = /* Q15 */ }; /* 31.25 343.75 718.75 1218.75 1968.75 4000 8000 16000 24000 */ -const Word16 gwlpr_fx[Lgw_max] = { 1, 3*Quot_Lpr_Ltr-1, 6*Quot_Lpr_Ltr-1, 10*Quot_Lpr_Ltr-1, 16*Quot_Lpr_Ltr-1, 32*Quot_Lpr_Ltr, 64*Quot_Lpr_Ltr, 128*Quot_Lpr_Ltr, 192*Quot_Lpr_Ltr }; /* frequency group start bins for transient analysis */ +const Word16 ivas_gwlpr_fx[Lgw_max] = { 1, 3*Quot_Lpr_Ltr-1, 6*Quot_Lpr_Ltr-1, 10*Quot_Lpr_Ltr-1, 16*Quot_Lpr_Ltr-1, 32*Quot_Lpr_Ltr, 64*Quot_Lpr_Ltr, 128*Quot_Lpr_Ltr, 192*Quot_Lpr_Ltr }; /* frequency group start bins for transient analysis */ const Word16 hestable_fx[15]= @@ -454,3 +455,4 @@ const Word16 pcmdsp_window_hann_640[640] = }; +/* clang-format on */ \ No newline at end of file diff --git a/lib_dec/rom_dec_fx.h b/lib_dec/rom_dec_fx.h index d99979e..d325b70 100644 --- a/lib_dec/rom_dec_fx.h +++ b/lib_dec/rom_dec_fx.h @@ -6,7 +6,7 @@ #ifndef ROM_DEC_FX_H #define ROM_DEC_FX_H -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" @@ -15,7 +15,7 @@ *----------------------------------------------------------------------------------*/ extern const Word16 gw_fx[Lgw_max]; extern const Word16 gw_len_inv_fx[Lgw_max-1]; -extern const Word16 gwlpr_fx[Lgw_max]; +extern const Word16 ivas_gwlpr_fx[Lgw_max]; extern const Word16 hestable_fx[15]; diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index 718f460..2071692 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -78,7 +78,7 @@ void CNG_reset_dec_fx( st_fx->bpf_off_fx = 1; move16(); /* Reset active frame counter */ - st_fx->act_cnt2_fx = 0; + st_fx->hTdCngDec->act_cnt2_fx = 0; move16(); return; diff --git a/lib_dec/stat_dec_fx.h b/lib_dec/stat_dec_fx.h index 800d304..1705a89 100644 --- a/lib_dec/stat_dec_fx.h +++ b/lib_dec/stat_dec_fx.h @@ -5,8 +5,9 @@ #ifndef STAT_DEC_FX_H #define STAT_DEC_FX_H - +#include #include "options.h" /* Compilation switches */ +#include "ivas_cnst.h" #include "cnst_fx.h" #include "stat_com.h" @@ -25,8 +26,8 @@ typedef enum _DEC_MODE typedef enum { - FRAMEMODE_NORMAL = 0x0, /**< frame available */ - FRAMEMODE_MISSING = 0x1, /**< frame missing => conceal */ + FRAMEMODE_NORMAL = 0x0, /* frame available */ + FRAMEMODE_MISSING = 0x1, /* frame missing => conceal */ FRAMEMODE_FUTURE = 0x2 } frameMode_fx; @@ -42,7 +43,7 @@ struct dispMem_fx /*ari.h*/ typedef struct { - Word32 low,high,vobf; + Word32 low,high,value; } TastatDec; /*---------------------------------------------------------------* @@ -53,7 +54,7 @@ typedef struct { Word16 bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ Word16 prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block, short or long */ - Word16 scfCountLongBlock; + Word16 scfCountLongBlock[IGF_NOF_GRIDS]; Word16 t; const Word16 *cf_se00; const Word16 *cf_se01; @@ -113,8 +114,8 @@ typedef struct igfdec_instance_struct Word16 infoIGFAllZero; Word16 infoIGFStopLine; Word16 infoIGFStartLine; - Word16 infoIGFStopFreq; - Word16 infoIGFStartFreq; + Word16 infoIGFStopFreq;// + Word16 infoIGFStartFreq; // Word16 infoTCXNoise[IGF_START_MX]; Word16 flag_sparse[N_MAX_TCX-IGF_START_MN]; Word32 virtualSpec[N_MAX_TCX-IGF_START_MN]; /* Q31 | buffer for temp flattening */ @@ -220,143 +221,71 @@ struct tonalmdctconceal }; typedef struct tonalmdctconceal* TonalMDCTConcealPtr; +/*----------------------------------------------------------------------------------* +* TD Stereo decoder structure +*----------------------------------------------------------------------------------*/ -/*****************************************/ -/* STAT DEC */ -/*****************************************/ - -/*fd_cng_dec.h*/ -/* Arrays and variables specific to decoder */ -typedef struct +typedef struct stereo_td_dec_data_structure { - HANDLE_FD_CNG_COM hFdCngCom; - - Word16 olapBufferAna[320]; - Word16 olapBufferSynth2[FFTLEN]; - - Word32 msPeriodog[NPART_SHAPING]; /* Periodogram */ - Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ - Word16 msPeriodog_exp_fft; - Word16 msPeriodog_exp_cldfb; - Word32 msBminWin[NPART_SHAPING]; - Word32 msBminSubWin[NPART_SHAPING]; - Word16 msPsd[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ - Word16 msPsd_exp_fft; - Word32 msAlpha[NPART_SHAPING]; /* Optimal smoothing parameter */ - - - Word32 msMinBuf[MSNUMSUBFR*NPART_SHAPING]; /* Buffer of minima */ - Word32 msCurrentMinOut[NPART_SHAPING]; - Word32 msCurrentMin[NPART_SHAPING]; - Word32 msCurrentMinSubWindow[NPART_SHAPING]; - - Word16 msLocalMinFlag[NPART_SHAPING]; - Word16 msNewMinFlag[NPART_SHAPING]; - - Word16 msPsdFirstMoment[NPART_SHAPING]; - Word32 msPsdSecondMoment[NPART_SHAPING]; - Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ - Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ - Word16 msNoiseEst_exp; + Word16 tdm_last_ratio_idx; /* last TDM ratio index */ + Word16 tdm_last_SM_flag; /* last channel combination scheme flag */ + Word16 tdm_prev_last_SM_flag; /* channel combination scheme flag before last frame */ + Word16 tdm_SM_flag; /* current channel combination scheme flag */ + Word16 tdm_use_IAWB_Ave_lpc; /* Flag to indicate the usage of mean inactive LP coefficients */ - Word16 npart_shaping; /* Number of partitions */ - Word16 nFFTpart_shaping; /* Number of hybrid spectral partitions */ - Word16 part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ - Word16 midband_shaping[NPART_SHAPING]; /* Central band of each partition */ - Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ - Word16 psize_shaping_norm[NPART_SHAPING]; /* Partition sizes, fractional variable */ - Word16 psize_shaping_norm_exp; /* Partition sizes exponent for fractional variable */ - Word16 psize_inv_shaping[NPART_SHAPING]; /* Inverse of partition sizes */ - Word32 bandNoiseShape[FFTLEN2]; /* CNG spectral shape computed at the decoder */ - Word16 bandNoiseShape_exp; /* exponent of bandNoiseShape */ - Word32 partNoiseShape[NPART]; /* CNG spectral shape computed at the decoder */ - Word16 partNoiseShape_exp; /* exponent of partNoiseShape */ + Word16 tdm_lp_reuse_flag; /* Flag that indicate if it is possible to reuse the LP coefficient from the primary channel or not */ + Word16 tdm_low_rate_mode; /* secondary channel low rate mode flag */ + Word16 tdm_Pri_pitch_buf[NB_SUBFR]; + Word16 tdm_Pitch_reuse_flag; + Word16 tdm_LRTD_flag; + Word16 flag_skip_DMX; /* flag that indicates whether the TD downmixing is skipped */ - Word16 flag_dtx_mode; + Word16 TCX_old_syn_Overl[L_FRAME16k / 2]; /* past ovrl buffer for possible switching from TD stereo ACELP to MDCT stereo TCX frame */ - Word32 lp_speech; /* format: Q9.23 */ - Word32 lp_noise; /* format: Q9.23 */ + Word16 prevSP_ratio; /* previous SP ratio */ + Word16 SP_ratio_LT; /* longterm SP ratio */ + Word16 c_LR_LT; /* left-right cross-correlation */ - Word16 msPeriodogBuf[MSBUFLEN*NPART_SHAPING]; - Word16 msPeriodogBufPtr; +} STEREO_TD_DEC_DATA, * STEREO_TD_DEC_DATA_HANDLE; - Word16 msLogPeriodog[NPART_SHAPING]; - Word16 msLogNoiseEst[NPART_SHAPING]; -} -FD_CNG_DEC; -typedef FD_CNG_DEC *HANDLE_FD_CNG_DEC; +/*----------------------------------------------------------------------------------* + * Stereo CNG handle + *----------------------------------------------------------------------------------*/ -typedef struct Decoder_State_fx +typedef struct stereo_dec_cng +{ + Word32 coh[STEREO_DFT_BAND_MAX + 1]; /* coherence */ + Word32 cm[STEREO_DFT_BAND_MAX]; /* cm */ + Word16 first_SID; /* first SID indicator */ + Word16 first_SID_after_TD; /* first SID after TD-stereo indicator */ + Word16 prev_sid_nodata; /* previous frame SID/FRAME_NO_DATA indicator */ + Word16 last_tdm_idx; /* last tdm index */ + Word32 c_LR_LT; /* left right cross correlation */ + Word16 active_frame_counter; /* counter for active frames */ + Word16 xfade_frame_counter; /* xfade counter */ + Word16 xfade_length; /* number of frames to perform xfade */ + Word16 nr_dft_frames; /* dft frame counter */ + Word16 nr_corr_frames; /* correlation frame counter */ + Word16 nr_sid_frames; /* sid frame counter */ + Word16 last_act_element_mode; /* Element mode of last active frame */ + Word16 olapBufferSynth22[FFTLEN]; /* overlap buffer for secondary channel CNA */ + Word16 flag_cna_fade; /* flag enabling CNA fade out */ + Word32 maskingNoiseS[L_FRAME16k]; /* masking noise (CNA) for secondary channel */ + Word16 enableSecCNA; /* flag enabling secondary channel CNA */ + Word32 c_PS_LT; /* long term cross-correlation between primary and secondary channel */ + const Word16 * frameSize; /* Frame size in samples */ + const Word16 * fftlen; /* FFT length used for the decomposition */ + +} STEREO_CNG_DEC, * STEREO_CNG_DEC_HANDLE; + +/*----------------------------------------------------------------------------------* + * GSC static variables + *----------------------------------------------------------------------------------*/ + +typedef struct gsc_dec_structure { - - /*----------------------------------------------------------------------------------* - * Common parameters - *----------------------------------------------------------------------------------*/ - Word16 codec_mode; /* MODE1 or MODE2 */ - Word16 mdct_sw_enable; /* MDCT switching enable flag */ - Word16 mdct_sw; /* MDCT switching indicator */ - Word16 last_codec_mode; /* last used codec mode*/ - UWord16 *bit_stream_fx; - Word16 next_bit_pos_fx; /* position of the next bit to be read from the bitstream */ - Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ - Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ - Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ - Word16 total_num_bits; /* == st->total_brate / 50 */ - Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ - - Word32 output_Fs_fx; /* output sampling rate Q0*/ - Word16 output_frame_fx; /* Output frame length Q0*/ - Word32 total_brate_fx; /* total bitrate in kbps of the codec Q0*/ - Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ - Word32 last_total_brate_ber_fx; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - Word32 core_brate_fx; /* core bitrate */ - Word32 last_core_brate_fx; /* previous frame core bitrate Q0*/ - Word16 extl_fx; /* extension layer Q0*/ - Word16 last_extl_fx; /* previous extension layer Q0*/ - Word32 extl_brate_fx; /* extension layer bitrate */ - Word16 L_frame_fx; /* ACELP core internal frame length */ - Word16 bwidth_fx; /* encoded signal bandwidth */ - Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode Q0*/ - Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ - Word16 ini_frame_fx; /* initialization frames counter */ - Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ - Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ - - /*----------------------------------------------------------------------------------* - * ACELP core parameters - *----------------------------------------------------------------------------------*/ - - Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ - Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ - Word32 offset_scale1_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ - Word32 offset_scale2_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ - Word32 offset_scale1_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ - Word32 offset_scale2_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ - Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ - Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 tilt_code_fx; /* tilt of code Q15*/ - Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ - Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - Word16 mem_syn3_fx[M]; - Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ - Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ - Word16 stab_fac_fx; /* LSF stability factor Q15*/ - Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ - Word16 last_coder_type_fx; /* previous coder type Q0*/ - Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ - Word16 past_qua_en_fx[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ - Word16 mid_lsf_int_fx; - Word16 safety_net_fx; - Word16 seed_tcx_fx; /* AC mode (GSC) - seed for noise fill Q0*/ - Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */ - Word16 Last_GSC_noisy_speech_flag_fx; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ Word16 cor_strong_limit_fx; /* AC mode (GSC) - Indicator about high spectral correlation per band */ Word16 old_y_gain_fx[MBANDS_GN]; /* AC mode (GSC) - AR mem for low rate gain quantization */ Word16 noise_lev_fx; /* AC mode (GSC) - noise level Q0*/ @@ -367,71 +296,61 @@ typedef struct Decoder_State_fx Word16 last_exc_dct_in_fx[L_FRAME]; /* AC mode (GSC) - previous excitation */ Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ Word16 last_bitallocation_band_fx[6]; /* AC mode (GSC) - previous bit allocation of each band */ +} GSC_DEC_DATA, * GSC_DEC_HANDLE; +/*----------------------------------------------------------------------------------* + * FEC - ACELP fast recovery + *----------------------------------------------------------------------------------*/ - Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ +typedef struct WI_dec_structure +{ + Word16 old_exc2_fx[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ + Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ - Word16 prev_r_fx; /* HF BWE - previous sub-frame gain */ - Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ - Word16 frame_count_fx; /* HF BWE - frame count */ - Word16 ne_min_fx; /* HF BWE - minimum Noise gate - short-term energy */ - Word16 fmerit_m_sm_fx; /* HF BWE - memory of fmerit_m param */ - Word16 voice_fac_amr_wb_hf; /* HF BWE - voice factor */ - Word16 unvoicing_fx; /* HF BWE - unvoiced parameter */ - Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ - Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - Word16 voicing_flag_fx; /* HF BWE - voiced flag */ - Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ - Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ +} WI_DEC_DATA, * WI_DEC_HANDLE; +/*----------------------------------------------------------------------------------* +* LD music post-filter +*----------------------------------------------------------------------------------*/ - Word16 seed2_fx; /* HF (6-7kHz) BWE - seed for random signal generator Q0*/ - Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ - Word16 mem_hf_fx[2*L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ - Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ - Word16 delay_syn_hf_fx[NS2SA(16000,DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ - Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ +typedef struct ld_music_postfilt_structure +{ + Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ + Word16 LDm_last_music_flag_fx; /* LD music post-filter - last music flag */ + Word16 LDm_nb_thr_1_fx; /* LD music post-filter - number of consecutives frames of level 1 */ + Word16 LDm_nb_thr_3_fx; + Word16 dct_post_old_exc_fx[DCT_L_POST - OFFSET2]; + Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ + Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ + Word16 LDm_enh_lp_gbin_fx[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ + Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ + Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ + Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ + Word16 filt_lfE_fx[DCT_L_POST]; + Word16 last_nonfull_music_fx; + Word16 Old_ener_Q; /* Old energy scaling factor */ - Word16 unv_cnt_fx; /* Stationary noise UV modification - unvoiced frame counter Q0*/ - Word16 uv_count_fx; /* Stationary noise UV modification - unvoiced counter Q0*/ - Word16 act_count_fx; /* Stationary noise UV modification - activation counter Q0*/ - Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ - Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ - Word16 noimix_seed_fx; /* Stationary noise UV modification - mixture seed Q0*/ - Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ - Word16 Q_stat_noise; /* Q of Exc_pe */ - Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ - Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ +} MUSIC_POSTFILT_DATA, * MUSIC_POSTFILT_HANDLE; +/*----------------------------------------------------------------------------------* + * Bass post-filter + *----------------------------------------------------------------------------------*/ - Word16 bfi_fx; /* FEC - bad frame indicator */ - Word16 prev_bfi_fx; /* FEC - previous bad frame indicator Q0*/ - Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ - Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ - Word16 last_good_fx; /* FEC - clas of last good received Q0*/ - Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ - Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ - Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ - Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ - Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/ - Word32 old_pitch_buf_fx[2*NB_SUBFR16k+2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - Word16 upd_cnt_fx; /* FEC - counter of frames since last update Q0*/ - Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ - Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ - Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ - Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ - Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ - Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ - Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ - Word16 decision_hyst_fx; /* FEC - hysteresis of the music/speech decision Q0*/ - Word16 old_exc2_fx[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ - Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ - Word16 relax_prev_lsf_interp_fx; - Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ - Word16 tilt_swb_fec_fx; /* FEC - SWB TBE TILT */ +typedef struct bass_postfilt_structure +{ + Word16 pst_old_syn_fx[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ + Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ + Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ + Word16 Track_on_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + Word16 vibrato_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ + Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ + +} BPF_DEC_DATA, * BPF_DEC_HANDLE; +/*------------------------------------------------------------------------------------------* + * DTX and TD CNG structure + *------------------------------------------------------------------------------------------*/ +typedef struct td_cng_dec_structure +{ Word16 cng_seed_fx; /*CNG and DTX - seed for white noise random generator*/ - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ - Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag Q0*/ Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ Word16 old_enr_index_fx; /* CNG and DTX - index of last encoded CNG energy Q0*/ Word16 cng_ener_seed_fx; /*CNG and DTX - seed for random generator for variation of excitation energyQ0*/ @@ -440,60 +359,52 @@ typedef struct Decoder_State_fx Word16 ho_hist_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ Word16 ho_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ Word32 ho_sid_bw_fx; /* CNG and DTX - SID bandwidth flags */ - Word16 ho_lsp_hist_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ + Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /*Q6 */ - Word32 ho_env_hist_fx[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 act_cnt_fx; /* CNG and DTX - counter of active frames */ + Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; Word16 ho_circ_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ Word16 ho_circ_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word16 ho_lsp_circ_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ + Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /* Q6 */ - Word32 ho_env_circ_fx[HO_HIST_SIZE*NUM_ENV_CNG]; + Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; Word16 num_ho_fx; /* DTX/CNG - number of selected hangover frames */ Word16 ho_16k_lsp_fx[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ - Word32 last_active_brate_fx; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ - Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ - Word16 act_cnt2_fx; /* DTX/CNG - counter of active frames for CNG_mode switching */ - Word16 cng_type_fx; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */ Word32 old_env_fx[20]; Word32 lp_env_fx[20]; Word16 exc_mem_fx[24]; Word16 exc_mem1_fx[30]; + Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */ + Word16 act_cnt2_fx; /* DTX/CNG - counter of active frames for CNG_mode switching */ + Word16 act_cnt_fx; /* CNG and DTX - counter of active frames */ + Word16 burst_cnt_fx; - Word16 bpf_off_fx; /* Bass post-filter - do not use BPF when this flag is set to 1 Q0*/ - Word16 pst_old_syn_fx[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ - Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ - Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ - Word16 Track_on_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - Word16 vibrato_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ - Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ - - Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ - - Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */ - Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - Word16 last_nq_preQ_fx; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ - /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ - Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ - Word16 LT_UV_cnt_fx; /* long-term consecutives frames classified as UV */ - Word16 Last_ener_fx; /* last_energy frame */ - Word16 lt_diff_etot_fx[MAX_LT]; /* stability estimation - long-term total energy variation */ - Word16 old_Aq_fx[68]; /* old LPC filter coefficient */ - Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */ - /*----------------------------------------------------------------------------------* - * SC-VBR - *----------------------------------------------------------------------------------*/ + float interpol_3_2_cng_dec[INTERP_3_2_MEM_LEN]; +#ifdef IVAS_CODE_CNG + + /* SWB DTX/CNG parameters */ + float shb_cng_ener; + float shb_lpcCNG[LPC_SHB_ORDER + 1]; + float shb_cng_gain; + float wb_cng_ener; + float last_wb_cng_ener; + float last_shb_cng_ener; + Word16 swb_cng_seed; + float lsp_shb_prev_prev[LPC_SHB_ORDER]; + float lsp_shb_prev[LPC_SHB_ORDER]; + Word16 shb_dtx_count; + Word16 trans_cnt; + Word16 burst_cnt; + float last_shb_ener; +#endif +} TD_CNG_DEC_DATA, * TD_CNG_DEC_HANDLE; +/*----------------------------------------------------------------------------------* + * SC-VBR structure + *----------------------------------------------------------------------------------*/ - Word16 last_ppp_mode_dec_fx; /*Q0*/ - Word16 ppp_mode_dec_fx; /*Q0*/ - Word16 last_nelp_mode_dec_fx; - Word16 nelp_mode_dec_fx; /* Q0 */ +typedef struct sc_vbr_dec_structure +{ Word16 firstTime_voiceddec_fx; /*Q0*/ /* DTFS variables */ @@ -518,83 +429,54 @@ typedef struct Decoder_State_fx Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ Word16 nelp_dec_seed_fx; /* Q0*/ Word16 FadeScale_fx; /*Q15*/ - Word16 prev_gain_pit_dec_fx; /*Q14*/ - Word16 prev_tilt_code_dec_fx; /*Q15*/ +} SC_VBR_DEC_DATA, * SC_VBR_DEC_HANDLE; - /*----------------------------------------------------------------------------------* - * channel-aware mode - *----------------------------------------------------------------------------------*/ - - Word16 tilt_code_dec_fx[NB_SUBFR16k]; - Word16 rf_frame_type; - Word16 use_partial_copy; - Word16 prev_use_partial_copy; - Word16 rf_flag; - Word16 rf_flag_last; - - Word16 rf_fec_offset; - Word16 next_coder_type; - Word16 prev_rf_frame_type; - Word16 rf_target_bits; - - Word16 rf_indx_nelp_fid; - Word16 rf_indx_nelp_iG1; - Word16 rf_indx_nelp_iG2[2]; - Word16 rf_indx_tbeGainFr; - - /*----------------------------------------------------------------------------------* - * HR SWB BWE parameters - *----------------------------------------------------------------------------------*/ - - Word16 bwe_highrate_seed_fx; - Word16 t_audio_prev_fx[2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF]; - Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - Word16 old_is_transient_hr_bwe_fx; - Word32 L_mem_EnergyLT_fx; - Word16 mem_EnergyLT_fx_exp; - - /*----------------------------------------------------------------------------------* - * HQ core parameters - *----------------------------------------------------------------------------------*/ - - Word16 synth_history_fx[Lprot48k + L_FRAME_MAX]; /* unified synthesis memory */ - Word16 *old_synthFB_fx; - Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ +/*----------------------------------------------------------------------------------* + * HQ NB FEC structure + *----------------------------------------------------------------------------------*/ - Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ - Word16 Q_old_wtda_LB; - Word16 Q_old_wtda; - Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ - Word16 Qprev_synth_buffer_fx; - Word32 oldIMDCTout_fx[L_FRAME8k/2]; - Word16 prev_oldauOut_fx[L_FRAME8k]; - Word16 old_auOut_2fr_fx[L_FRAME8k*2]; - Word16 old_out_pha_fx[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ +typedef struct hq_nbfec_structure +{ + Word16 prev_last_core_fx; /* !!! note: the parameter is identical to last_core in IVAS */ Word16 diff_energy_fx; - Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ Word16 stat_mode_out_fx; Word16 stat_mode_old_fx; Word16 phase_mat_flag_fx; Word16 phase_mat_next_fx; Word16 old_Min_ind_fx; - Word16 old_is_transient_fx[3]; /* HQ core - previous transient flag (for FEC) */ - Word16 old_bfi_cnt_fx; /* HQ core - # of bfi until previous frame(for FEC) */ - Word16 prev_old_bfi_fx; + Word16 old_auOut_2fr_fx[L_FRAME8k * 2]; + Word16 old_out_pha_fx[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ + Word32 ynrm_values_fx[MAX_SB_NB][MAX_PGF]; Word32 r_p_values_fx[MAX_SB_NB][MAX_ROW]; /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ Word16 Norm_gain_fx[SFM_N_NB]; Word16 HQ_FEC_seed_fx; Word16 energy_MA_Curr_fx[2]; - Word16 last_core_fx; /*Q0*/ - Word16 last_core_bs_fx; - Word16 prev_last_core_fx; + + Word16 prev_sign_switch_fx[HQ_FEC_SIGN_SFM]; + Word16 prev_sign_switch_2_fx[HQ_FEC_SIGN_SFM]; + + Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ + Word32 oldIMDCTout_fx[L_FRAME8k / 2]; + Word16 prev_oldauOut_fx[L_FRAME8k]; + +} HQ_NBFEC_DATA, * HQ_NBFEC_HANDLE; +/*----------------------------------------------------------------------------------* + * HQ core structure + *----------------------------------------------------------------------------------*/ + +typedef struct hq_dec_structure +{ + Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ + Word16 Q_old_wtda_LB; + Word16 Q_old_wtda; + Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ Word16 last_hq_core_type_fx; /*Q0*/ - Word16 last_L_frame_ori_fx; - Word16 previoussynth_fx[L_FRAME48k]; - Word16 old_synth_sw_fx[NS2SA(48000,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS)]; - Word16 delay_buf_out_fx[HQ_DELTA_MAX*HQ_DELAY_COMP]; /*Q0*/ + Word16 old_is_transient_fx[3]; /* HQ core - previous transient flag (for FEC) */ + Word16 mem_norm_fx[SFM_N_ENV_STAB]; /* Q0 */ Word16 mem_env_delta_fx; /* Q11 */ Word16 no_att_hangover_fx; /* Q0 */ @@ -605,91 +487,626 @@ typedef struct Decoder_State_fx Word16 prev_R_fx; /* the table of bit allocation of last frame */ Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; - Word16 old_Aq_12_8_fx[M+1]; /* Q12 old Aq[] for core switching */ - Word16 old_Es_pred_fx; /* old Es_pred for core switching */ - Word16 HqVoicing_fx; Word16 fer_samples_fx[L_FRAME48k]; Word32 prev_normq_fx[SFM_N_WB]; /* Q14 */ /* previous norms */ Word32 prev_env_fx[SFM_N_WB]; /* previous noise envelopes */ + Word16 prev_env_Q[SFM_N_WB]; Word32 last_ni_gain_fx[BANDS_MAX]; Word16 last_env_fx[BANDS_MAX]; Word16 last_max_pos_pulse_fx; - /* pre-echo reduction */ - Word16 memfilt_lb_fx; /* Q0 */ - Word32 mean_prev_hb_fx; /* Q0 */ - Word16 smoothmem_fx; /* Q15 */ - Word32 mean_prev_fx; /* Q0 */ - Word32 mean_prev_nc_fx; /* Q0 */ - Word16 wmold_hb_fx; /* Q15 */ - Word16 prevflag_fx; /* Q0 */ - Word16 pastpre_fx; /* Q0 */ + /* pre-echo reduction */ + Word16 memfilt_lb_fx; /* Q0 */ + Word32 mean_prev_hb_fx; /* Q0 */ + Word16 smoothmem_fx; /* Q15 */ + Word32 mean_prev_fx; /* Q0 */ + Word32 mean_prev_nc_fx; /* Q0 */ + Word16 wmold_hb_fx; /* Q15 */ + Word16 prevflag_fx; /* Q0 */ + Word16 pastpre_fx; /* Q0 */ + + Word16 prev_frm_hfe2_fx; + Word16 prev_stab_hfe2_fx; + Word16 prev_ni_ratio_fx; /* 15 */ + Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ + + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ + + /* HQ PHASE ECU internal state */ + Word16 time_offs_fx; + Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; + Word16 Q_X_sav; + Word16 num_p_fx; + Word16 plocs_fx[MAX_PLOCS]; + Word32 plocsi_fx[MAX_PLOCS]; + Word16 env_stab_fx; + Word16 mem_norm_hqfec_fx[SFM_N_ENV_STAB]; + Word16 mem_env_delta_hqfec_fx; + Word16 env_stab_plc_fx; + Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; + Word16 envstabplc_hocnt_fx; + Word16 mag_chg_1st_fx[Lgw_max]; /* i/o: per band magnitude modifier for transients*/ + Word16 Xavg_fx[Lgw_max]; /* Frequency group average gain to fade to */ + Word16 beta_mute_fx; /* Factor for long-term mute */ + Word16 last_fec_fx; + Word16 ph_ecu_HqVoicing_fx; + Word16 oldHqVoicing_fx; + Word16 oldgapsynth_fx[L_FRAME48k]; + Word16 ph_ecu_active_fx; /* Set if Phase ECU was used in last bad frame */ + Word16 ni_seed_forfec; + Word16 ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ + +} HQ_DEC_DATA, * HQ_DEC_HANDLE; +/*----------------------------------------------------------------------------------* + * HF (6-7kHz) (zero) BWE structure + *----------------------------------------------------------------------------------*/ + +typedef struct zero_bwe_dec_structure +{ + Word16 seed2_fx; /* HF (6-7kHz) BWE - seed for random signal generator Q0*/ + Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ + Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ + Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ + Word16 delay_syn_hf_fx[NS2SA(16000, DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ + Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ + +} ZERO_BWE_DEC_DATA, * ZERO_BWE_DEC_HANDLE; +/*----------------------------------------------------------------------------------* + * TD BWE structure + *----------------------------------------------------------------------------------*/ + +typedef struct td_bwe_dec_structure +{ + /* states for the filters used in generating SHB excitation from WB excitation */ + Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; + Word32 mem_csfilt_fx[2]; + + /* states for the filters used in generating SHB signal from SHB excitation*/ + Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; + Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + + /* previous frame parameters for frame error concealment */ + Word16 lsp_prevfrm_fx[LPC_SHB_ORDER]; + Word32 GainFrame_prevfrm_fx; + Word16 GainAttn_fx; + + float GainShape_Delay[NUM_SHB_SUBFR / 2]; + + Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ + Word16 bwe_seed_fx[2]; /*Q0*/ + Word32 bwe_non_lin_prev_scale_fx; + Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; + + Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; + Word16 mem_genSHBexc_filt_down_shb_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + Word16 mem_genSHBexc_filt_down_wb2_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + Word16 mem_genSHBexc_filt_down_wb3_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[2 * ALLPASSSECTIONS_STEEP]; + Word16 state_lsyn_filt_shb_fx[2 * ALLPASSSECTIONS_STEEP]; + Word16 state_lsyn_filt_dwn_shb_fx[2 * ALLPASSSECTIONS_STEEP]; + Word16 mem_resamp_HB_fx[INTERP_3_1_MEM_LEN]; + Word16 mem_resamp_HB_32k_fx[2 * ALLPASSSECTIONS_STEEP + 1]; + Word16 state_32and48k_WB_upsample_fx[2 * ALLPASSSECTIONS_STEEP]; /* !!! this memory in FLP is called mem_resamp_HB */ + +#if 0 + float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ + float prev_mix_factor; /* mixing factor in the previous frame */ +#endif + Word16 syn_dm_phase_fx; + Word32 fbbwe_hpf_mem_fx[4][4]; + Word16 fbbwe_hpf_mem_fx_Q[4]; + Word32 prev_wb_bwe_frame_pow_fx; + Word32 prev_swb_bwe_frame_pow_fx; + Word32 prev_ener_fx; + Word16 prev_GainShape_fx; + Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; + + //Word16 prev_Q_bwe_exc_fb; + //Word16 prev_Qx; + //Word16 prev_Q_bwe_exc; + //Word16 prev_Q_synth; + + Word16 fb_tbe_demph_fx; + Word16 prev_fbbwe_ratio_fx; + + Word16 tbe_demph_fx; + Word16 tbe_premph_fx; + Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; + Word16* ptr_mem_stp_swb_fx; + Word16 gain_prec_swb_fx; + Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; + Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; + Word32 prev1_shb_ener_sf_fx, prev2_shb_ener_sf_fx, prev3_shb_ener_sf_fx; + Word16 prev_res_shb_gshape_fx, prev_mixFactors_fx; + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; + Word16 prev_tilt_para_fx; + Word16 cur_sub_Aq_fx[M + 1]; + + /* quantized data */ + Word16 lsf_idx_fx[NUM_Q_LSF]; + Word16 m_idx_fx; + Word16 grid_idx_fx; + Word16 idxSubGains_fx; + Word16 idxFrameGain_fx; + Word16 idx_shb_fr_gain_fx; + Word16 idx_res_gs_fx[NB_SUBFR16k]; + Word16 idx_mixFac_fx; + + Word16 lsf_WB_fx; + Word16 gFrame_WB_fx; + + Word16 idxGain_fx; + + Word16 old_core_synth_fx[L_FRAME16k]; + Word16 old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH]; + Word16 int_3_over_2_tbemem_dec_fx[INTERP_3_2_MEM_LEN]; + + Word16 tilt_swb_fec_fx; /* FEC - SWB TBE TILT */ + Word16 old_hb_synth_fx[L_FRAME48k]; + Word16 prev_hb_synth_fx_exp; + Word16 tilt_mem_fx; /* Formant factor adaptation tilt smoothing memory */ + +} TD_BWE_DEC_DATA, * TD_BWE_DEC_HANDLE; +/*----------------------------------------------------------------------------------* + * FD BWE structure + *----------------------------------------------------------------------------------*/ + +typedef struct fd_bwe_dec_structure +{ + Word16 old_wtda_wb_fx_exp; + Word16 L_old_wtda_swb_fx[L_FRAME48k]; + Word16 old_wtda_swb_fx_exp; + Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; /*Q_syn2-1*/ + + Word16 mem_deemph_old_syn_fx; + Word16 prev_mode_fx; + //Word16 prev_SWB_fenv_fx[SWB_FENV]; + Word16 prev_Energy_fx; + Word32 prev_Energy_wb_fx; + Word16 prev_L_swb_norm_fx; + Word16 Seed_fx; + Word16 memExp1; + Word16 prev_frica_flag_fx; + Word16 mem_imdct_fx[L_FRAME48k]; + Word16 mem_imdct_exp_fx; + Word16 prev_td_energy_fx; + Word16 prev_weight_fx; + + Word16 prev_flag_fx; + //Word16 last_wb_bwe_ener_fx; + //Word16 prev_frame_pow_exp; + //Word16 prev_Qx; + //Word16 prev_Q_bwe_exc; + //Word16 prev_Q_synth; + //Word16 prev_fb_ener_adjust_fx; + +} FD_BWE_DEC_DATA, * FD_BWE_DEC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * HR SWB BWE structure + *----------------------------------------------------------------------------------*/ + +typedef struct hr_swb_bwe_dec_structure +{ + + Word16 bwe_highrate_seed_fx; + Word16 t_audio_prev_fx[2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF]; + Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; + Word16 old_is_transient_hr_bwe_fx; + Word32 L_mem_EnergyLT_fx; + Word16 mem_EnergyLT_fx_exp; + +} HR_BWE_DEC_DATA, * HR_BWE_DEC_HANDLE; + +/*---------------------------------------------------------------* + * PVQ range decoder state + *---------------------------------------------------------------*/ + +typedef struct pvq_dec_structure +{ + /* PVQ range coder state */ + UWord32 rc_low_fx; + UWord32 rc_range_fx; + UWord32 rc_help_fx; + Word16 rc_num_bits_fx; + Word16 rc_offset_fx; + Word16 rc_end_fx; + +} PVQ_DEC_DATA, * PVQ_DEC_HANDLE; +/*---------------------------------------------------------------* + * AMR-WB IO mode decoder structure + *---------------------------------------------------------------*/ + +typedef struct amrwb_io_dec_structure +{ + Word16 past_qua_en_fx[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ + + Word16 prev_r_fx; /* HF BWE - previous sub-frame gain */ + Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ + Word16 frame_count_fx; /* HF BWE - frame count */ + Word16 ne_min_fx; /* HF BWE - minimum Noise gate - short-term energy */ + Word16 fmerit_m_sm_fx; /* HF BWE - memory of fmerit_m param */ + Word16 voice_fac_amr_wb_hf; /* HF BWE - voice factor */ + Word16 unvoicing_fx; /* HF BWE - unvoiced parameter */ + Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ + Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ + Word16 voicing_flag_fx; /* HF BWE - voiced flag */ + Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ + Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ + + /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ + Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ + Word16 LT_UV_cnt_fx; /* long-term consecutives frames classified as UV */ + Word16 Last_ener_fx; /* last_energy frame */ + Word16 lt_diff_etot_fx[MAX_LT]; /* stability estimation - long-term total energy variation */ + Word16 old_Aq_fx[68]; /* old LPC filter coefficient */ + Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */ + +} AMRWB_IO_DEC_DATA, * AMRWB_IO_DEC_HANDLE; + + +/*****************************************/ +/* STAT DEC */ +/*****************************************/ + +/*fd_cng_dec.h*/ +/* Arrays and variables specific to decoder */ +typedef struct +{ + HANDLE_FD_CNG_COM hFdCngCom; + + Word16 olapBufferAna[320]; + Word16 olapBufferSynth2[FFTLEN]; + + Word32 msPeriodog[NPART_SHAPING]; /* Periodogram */ + Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ + Word16 msPeriodog_exp_fft; + Word16 msPeriodog_exp_cldfb; + Word32 msBminWin[NPART_SHAPING]; + Word32 msBminSubWin[NPART_SHAPING]; + Word16 msPsd[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ + Word16 msPsd_exp_fft; + Word32 msAlpha[NPART_SHAPING]; /* Optimal smoothing parameter */ + + + Word32 msMinBuf[MSNUMSUBFR*NPART_SHAPING]; /* Buffer of minima */ + Word32 msCurrentMinOut[NPART_SHAPING]; + Word32 msCurrentMin[NPART_SHAPING]; + Word32 msCurrentMinSubWindow[NPART_SHAPING]; + + Word16 msLocalMinFlag[NPART_SHAPING]; + Word16 msNewMinFlag[NPART_SHAPING]; + + Word16 msPsdFirstMoment[NPART_SHAPING]; + Word32 msPsdSecondMoment[NPART_SHAPING]; + Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ + Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ + Word16 msNoiseEst_exp; + + Word16 npart_shaping; /* Number of partitions */ + Word16 nFFTpart_shaping; /* Number of hybrid spectral partitions */ + Word16 part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ + Word16 midband_shaping[NPART_SHAPING]; /* Central band of each partition */ + Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ + Word16 psize_shaping_norm[NPART_SHAPING]; /* Partition sizes, fractional variable */ + Word16 psize_shaping_norm_exp; /* Partition sizes exponent for fractional variable */ + Word16 psize_inv_shaping[NPART_SHAPING]; /* Inverse of partition sizes */ + Word32 bandNoiseShape[FFTLEN2]; /* CNG spectral shape computed at the decoder */ + Word16 bandNoiseShape_exp; /* exponent of bandNoiseShape */ + Word32 partNoiseShape[NPART]; /* CNG spectral shape computed at the decoder */ + Word16 partNoiseShape_exp; /* exponent of partNoiseShape */ + + Word16 flag_dtx_mode; + + Word32 lp_speech; /* format: Q9.23 */ + Word32 lp_noise; /* format: Q9.23 */ + + Word16 msPeriodogBuf[MSBUFLEN*NPART_SHAPING]; + Word16 msPeriodogBufPtr; + + Word16 msLogPeriodog[NPART_SHAPING]; + Word16 msLogNoiseEst[NPART_SHAPING]; +} +FD_CNG_DEC, * HANDLE_FD_CNG_DEC; +//typedef FD_CNG_DEC *HANDLE_FD_CNG_DEC; +/*------------------------------------------------------------------------------------------* + * TCX LTP decoder + *------------------------------------------------------------------------------------------*/ + +typedef struct tcx_ltp_dec_structure +{ + /* TCX-LTP */ + Word8 tcxltp; + Word16 tcxltp_gain; + Word16 tcxltp_pitch_int; + Word16 tcxltp_pitch_fr; + + Word16 tcxltp_mem_in[TCXLTP_MAX_DELAY]; + Word16 tcxltp_mem_out[L_FRAME48k]; + Word16 tcxltp_pitch_int_post_prev; + Word16 tcxltp_pitch_fr_post_prev; + Word16 tcxltp_gain_post_prev; + Word16 tcxltp_filt_idx_prev; +} TCX_LTP_DEC_DATA, * TCX_LTP_DEC_HANDLE; +/*------------------------------------------------------------------------------------------* + * TCX decoder + *------------------------------------------------------------------------------------------*/ + +typedef struct tcx_dec_structure +{ + Word8 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ + Word8 envWeighted; /* are is{p,f}_old[] weighted or not? */ + + Word32 tcxltp_second_last_pitch; + Word32 tcxltp_third_last_pitch; + Word16 tcxltp_last_gain_unmodified; + + Word16 tcx_hm_LtpPitchLag; + Word16 tcx_lpc_shaped_ari; + + Word16 pit_max_TCX; /*int Q0*/ + Word16 pit_min_TCX; /*int*/ + + Word16 L_frameTCX; + + Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ + + Word16 old_synth_len; + Word16 old_synth_lenFB; + Word16 old_synth[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ + Word16 synth_history_fx[Lprot48k + L_FRAME_MAX]; /*TCX unified synthesis memory */ + + Word16* old_synthFB_fx; + Word16* prev_good_synth_fx; + + Word16 old_syn_Overl[L_FRAME32k / 2]; + + Word16 syn_Overl_TDAC[L_FRAME32k / 2]; + Word16 syn_Overl_TDACFB[L_FRAME_MAX / 2]; + + Word16 syn_Overl[L_FRAME32k / 2]; + Word16 syn_OverlFB[L_FRAME_MAX / 2]; + + Word16 FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ + + /*TCX resisual Q*/ + Word16 resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ + + /* IVAS - PLC */ +#ifdef IVAS_CODE_TCX + int16_t noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ + int16_t tnsActive[NB_DIV]; + float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ + uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ +#endif + Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ + Word16 conCngLevelBackgroundTrace_e; + + /* state variables for the minimum statistics used for PLC */ + Word16 conNoiseLevelMemory[PLC_MIN_STAT_BUFF_SIZE], conNoiseLevelMemory_e[PLC_MIN_STAT_BUFF_SIZE];/*Q15*/ + Word16 conNoiseLevelIndex; /*Q0*/ + Word16 conCurrLevelIndex; /*Q0*/ + Word16 conLastFrameLevel, conLastFrameLevel_e;/*Q15*/ + Word16 old_gaintcx_bfi, old_gaintcx_bfi_e; + Word16 conceal_eof_gain; /*Q14*/ + Word16 damping; /* 1Q14 */ + Word16 gainHelper, gainHelper_e; /*can be >1*/ + Word16 stepCompensate, stepCompensate_e; + Word16 tcxConceal_recalc_exc; + Word16 cummulative_damping_tcx; + +} TCX_DEC_DATA, * TCX_DEC_HANDLE; + +typedef struct Decoder_State_fx +{ + + /*----------------------------------------------------------------------------------* + * Common parameters + *----------------------------------------------------------------------------------*/ + Word16 codec_mode; /* MODE1 or MODE2 */ + Word16 mdct_sw_enable; /* MDCT switching enable flag */ + Word16 mdct_sw; /* MDCT switching indicator */ + Word16 last_codec_mode; /* last used codec mode*/ + UWord16 *bit_stream_fx; + Word16 next_bit_pos_fx; /* position of the next bit to be read from the bitstream */ + Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ + Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ + Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ + Word16 total_num_bits; /* == st->total_brate / 50 */ + Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ + + Word32 output_Fs_fx; /* output sampling rate Q0*/ + Word16 output_frame_fx; /* Output frame length Q0*/ + Word32 total_brate_fx; /* total bitrate in kbps of the codec Q0*/ + Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ + Word32 last_total_brate_ber_fx; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + Word32 core_brate_fx; /* core bitrate */ + Word32 last_core_brate_fx; /* previous frame core bitrate Q0*/ + Word16 extl_fx; /* extension layer Q0*/ + Word16 last_extl_fx; /* previous extension layer Q0*/ + Word32 extl_brate_fx; /* extension layer bitrate */ + Word16 L_frame_fx; /* ACELP core internal frame length */ + Word16 bwidth_fx; /* encoded signal bandwidth */ + Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode Q0*/ + Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ + Word16 ini_frame_fx; /* initialization frames counter */ + Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ + Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ + + /*----------------------------------------------------------------------------------* + * ACELP core parameters + *----------------------------------------------------------------------------------*/ + + Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ + Word32 offset_scale1_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ + Word32 offset_scale2_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ + Word32 offset_scale1_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ + Word32 offset_scale2_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ + Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ + Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ + Word16 tilt_code_fx; /* tilt of code Q15*/ + Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ + Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ + Word16 mem_syn3_fx[M]; + Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ + Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ + Word16 stab_fac_fx; /* LSF stability factor Q15*/ + Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ + Word16 last_coder_type_fx; /* previous coder type Q0*/ + Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ + Word16 mid_lsf_int_fx; + Word16 safety_net_fx; + + GSC_DEC_HANDLE hGSCDec; + Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ + + Word16 Last_GSC_noisy_speech_flag_fx; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ + Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */ + + Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ + struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ + + ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ + + Word16 unv_cnt_fx; /* Stationary noise UV modification - unvoiced frame counter Q0*/ + Word16 uv_count_fx; /* Stationary noise UV modification - unvoiced counter Q0*/ + Word16 act_count_fx; /* Stationary noise UV modification - activation counter Q0*/ + Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ + Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ + Word16 noimix_seed_fx; /* Stationary noise UV modification - mixture seed Q0*/ + Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ + Word16 Q_stat_noise; /* Q of Exc_pe */ + Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ + Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ + + Word16 bfi_fx; /* FEC - bad frame indicator */ + Word16 prev_bfi_fx; /* FEC - previous bad frame indicator Q0*/ + Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ + Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ + Word16 last_good_fx; /* FEC - clas of last good received Q0*/ + Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ + Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ + Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ + Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ + Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ + Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/ + Word32 old_pitch_buf_fx[2*NB_SUBFR16k+2]; /* FEC - buffer of old subframe pitch values 15Q16 */ + Word16 upd_cnt_fx; /* FEC - counter of frames since last update Q0*/ + Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ + Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ + Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ + Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ + Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ + Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ + Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ + Word16 decision_hyst_fx; /* FEC - hysteresis of the music/speech decision Q0*/ + + WI_DEC_HANDLE hWIDec; + Word16 relax_prev_lsf_interp_fx; + Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ + /*----------------------------------------------------------------------------------* + * DTX and TD CNG parameters + *----------------------------------------------------------------------------------*/ + Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag Q0*/ + Word16 cng_type_fx; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ + Word32 last_active_brate_fx; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ + Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ + Word16 active_cnt; + + TD_CNG_DEC_HANDLE hTdCngDec; + Word16 bpf_off_fx; /* Bass post-filter - do not use BPF when this flag is set to 1 Q0*/ + BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */ + Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ + + Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */ + Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ + Word16 last_nq_preQ_fx; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + + AMRWB_IO_DEC_HANDLE hAmrwb_IO; + + SC_VBR_DEC_HANDLE hSC_VBR; + /*----------------------------------------------------------------------------------* + * SC-VBR + *----------------------------------------------------------------------------------*/ + Word16 last_ppp_mode_dec_fx; /*Q0*/ + Word16 ppp_mode_dec_fx; /*Q0*/ + Word16 last_nelp_mode_dec_fx; + Word16 nelp_mode_dec_fx; /* Q0 */ + Word16 prev_gain_pit_dec_fx; /*Q14*/ + Word16 prev_tilt_code_dec_fx; /*Q15*/ + Word16 vbr_hw_BWE_disable_dec_fx; + Word16 last_vbr_hw_BWE_disable_dec_fx; + + /*----------------------------------------------------------------------------------* + * channel-aware mode + *----------------------------------------------------------------------------------*/ - Word16 prev_frm_hfe2_fx; - Word16 prev_stab_hfe2_fx; - Word16 prev_ni_ratio_fx; /* 15 */ - Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ + Word16 tilt_code_dec_fx[NB_SUBFR16k]; + Word16 rf_frame_type; + Word16 use_partial_copy; + Word16 prev_use_partial_copy; + Word16 rf_flag; + Word16 rf_flag_last; - /* PVQ range coder state */ - UWord32 rc_low_fx; - UWord32 rc_range_fx; - UWord32 rc_help_fx; - Word16 rc_num_bits_fx; - Word16 rc_offset_fx; - Word16 rc_end_fx; + Word16 rf_fec_offset; + Word16 next_coder_type; + Word16 prev_rf_frame_type; + Word16 rf_target_bits; - Word16 prev_env_Q[SFM_N_WB]; + Word16 rf_indx_nelp_fid; + Word16 rf_indx_nelp_iG1; + Word16 rf_indx_nelp_iG2[2]; + Word16 rf_indx_tbeGainFr; /*----------------------------------------------------------------------------------* - * TBE parameters + * HR SWB BWE parameters *----------------------------------------------------------------------------------*/ + HR_BWE_DEC_HANDLE hBWE_FD_HR; + Word16 Qprev_synth_buffer_fx; - /* states for the filters used in generating SHB excitation from WB excitation */ - Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; - Word32 mem_csfilt_fx [2]; + /*----------------------------------------------------------------------------------* + * HQ core parameters + *----------------------------------------------------------------------------------*/ + Word16 last_core_fx; /*Q0*/ + Word16 last_core_bs_fx; + Word16 last_L_frame_ori_fx; + Word16 previoussynth_fx[L_FRAME48k]; + Word16 old_synth_sw_fx[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)]; + Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/ + Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ + Word16 old_Es_pred_fx; /* old Es_pred for core switching */ - /* states for the filters used in generating SHB signal from SHB excitation*/ - Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; - Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + HQ_DEC_HANDLE hHQ_core; - /* previous frame parameters for frame error concealment */ - Word16 lsp_prevfrm_fx[ LPC_SHB_ORDER]; - Word32 GainFrame_prevfrm_fx; - Word16 GainAttn_fx; + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - Word16 bwe_seed_fx[2]; /*Q0*/ - Word32 bwe_non_lin_prev_scale_fx; - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; - Word16 last_voice_factor_fx; /* Q6*/ + Word16 old_bfi_cnt_fx; /* HQ core - # of bfi until previous frame(for FEC) */ + Word16 prev_old_bfi_fx; + HQ_NBFEC_HANDLE hHQ_nbfec; - Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; - Word16 mem_genSHBexc_filt_down_shb_fx[2*ALLPASSSECTIONS_STEEP+1]; - Word16 mem_genSHBexc_filt_down_wb2_fx[2*ALLPASSSECTIONS_STEEP+1]; - Word16 mem_genSHBexc_filt_down_wb3_fx[2*ALLPASSSECTIONS_STEEP+1]; - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[ 2 * ALLPASSSECTIONS_STEEP ]; - Word16 state_lsyn_filt_shb_fx[ 2 * ALLPASSSECTIONS_STEEP ]; - Word16 state_lsyn_filt_dwn_shb_fx[ 2 * ALLPASSSECTIONS_STEEP ]; - Word16 state_32and48k_WB_upsample_fx[2 * ALLPASSSECTIONS_STEEP]; /* !!! this memory in FLP is called mem_resamp_HB */ + /*----------------------------------------------------------------------------------* + * TBE parameters + *----------------------------------------------------------------------------------*/ + TD_BWE_DEC_HANDLE hBWE_TD; Word16 hb_prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS)]; Word16 old_bwe_delay_fx; /*Q0*/ - Word16 syn_dm_phase_fx; - Word32 fbbwe_hpf_mem_fx[4][4]; - Word16 fbbwe_hpf_mem_fx_Q[4]; - Word32 prev_wb_bwe_frame_pow_fx; - Word32 prev_swb_bwe_frame_pow_fx; - Word32 prev_ener_fx; - Word16 prev_ener_fx_Q; - Word16 prev_GainShape_fx; - Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 prev_Q_bwe_exc_fb; - Word16 fb_tbe_demph_fx; - Word16 prev_fbbwe_ratio_fx; - /* WB/SWB bandwidth switching */ Word16 tilt_wb_fx; Word16 tilt_swb_fx; @@ -706,74 +1123,16 @@ typedef struct Decoder_State_fx Word16 attenu_fx; Word16 last_inner_frame_fx; /* (HQ_CORE) DCT length */ Word16 last_bwidth_fx; - Word16 prev_weight1_fx; Word16 t_audio_q_fx[L_FRAME]; - Word16 tbe_demph_fx; - Word16 tbe_premph_fx; - Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; - Word16 *ptr_mem_stp_swb_fx; - Word16 gain_prec_swb_fx; - Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; - - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; - Word32 prev1_shb_ener_sf_fx, prev2_shb_ener_sf_fx, prev3_shb_ener_sf_fx; - Word16 prev_res_shb_gshape_fx, prev_mixFactors_fx; - Word16 tilt_mem_fx; /* Formant factor adaptation tilt smoothing memory */ - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER-2]; - Word16 prev_tilt_para_fx; - Word16 cur_sub_Aq_fx[M+1]; - - Word16 lsf_idx_fx[NUM_Q_LSF]; - Word16 m_idx_fx; - Word16 grid_idx_fx; - Word16 idxSubGains_fx; - Word16 idxFrameGain_fx; - Word16 idx_shb_fr_gain_fx; - Word16 idx_res_gs_fx[NB_SUBFR16k]; - Word16 idx_mixFac_fx; - - Word16 lsf_WB_fx; - Word16 gFrame_WB_fx; - Word16 idxGain_fx; - Word16 old_core_synth_fx[L_FRAME16k]; - Word16 old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH]; - Word16 int_3_over_2_tbemem_dec_fx[INTERP_3_2_MEM_LEN]; Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; - Word16 mem_resamp_HB_fx[INTERP_3_1_MEM_LEN]; - Word16 mem_resamp_HB_32k_fx[2*ALLPASSSECTIONS_STEEP+1]; /*----------------------------------------------------------------------------------* * SWB BWE parameters *----------------------------------------------------------------------------------*/ - Word16 old_wtda_wb_fx_exp; - Word16 L_old_wtda_swb_fx[L_FRAME48k]; - Word16 old_wtda_swb_fx_exp; - Word16 mem_imdct_exp_fx; - Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; /*Q_syn2-1*/ - - Word16 mem_deemph_old_syn_fx; - Word16 prev_mode_fx; - Word16 prev_SWB_fenv_fx[SWB_FENV]; - Word16 prev_Energy_fx; - Word32 prev_Energy_wb_fx; - Word16 prev_L_swb_norm_fx; - Word16 Seed_fx; - Word16 memExp1; - Word16 prev_frica_flag_fx; - Word16 mem_imdct_fx[L_FRAME48k]; - Word16 prev_td_energy_fx; - Word16 prev_weight_fx; + FD_BWE_DEC_HANDLE hBWE_FD; Word16 prev_coder_type_fx; - Word16 prev_flag_fx; - Word16 last_wb_bwe_ener_fx; - Word16 prev_frame_pow_exp; - Word16 prev_Qx; - Word16 prev_Q_bwe_exc; - Word16 prev_Q_synth; - Word16 prev_fb_ener_adjust_fx; - /*----------------------------------------------------------------------------------* * SWB DTX/CNG parameters *----------------------------------------------------------------------------------*/ @@ -788,58 +1147,14 @@ typedef struct Decoder_State_fx Word16 shb_dtx_count_fx; Word16 last_vad_fx; Word16 trans_cnt_fx; - Word16 burst_cnt_fx; + //Word16 burst_cnt_fx; Word16 last_shb_ener_fx; - /*----------------------------------------------------------------------------------* - * HQ FEC - *----------------------------------------------------------------------------------*/ - - Word16 *prev_good_synth_fx; - Word16 prev_sign_switch_fx[HQ_FEC_SIGN_SFM]; - Word16 prev_sign_switch_2_fx[HQ_FEC_SIGN_SFM]; - - /* HQ PHASE ECU internal state */ - Word16 time_offs_fx; - Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; - Word16 Q_X_sav; - Word16 num_p_fx; - Word16 plocs_fx[MAX_PLOCS]; - Word32 plocsi_fx[MAX_PLOCS]; - Word16 env_stab_fx; - Word16 mem_norm_hqfec_fx[SFM_N_ENV_STAB]; - Word16 mem_env_delta_hqfec_fx; - Word16 env_stab_plc_fx; - Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; - Word16 envstabplc_hocnt_fx; - Word16 mag_chg_1st_fx[Lgw_max]; /* i/o: per band magnitude modifier for transients*/ - Word16 Xavg_fx[Lgw_max]; /* Frequency group average gain to fade to */ - Word16 beta_mute_fx; /* Factor for long-term mute */ - Word16 last_fec_fx; - Word16 ph_ecu_HqVoicing_fx; - Word16 oldHqVoicing_fx; - Word16 oldgapsynth_fx[L_FRAME48k]; - Word16 ph_ecu_active_fx; /* Set if Phase ECU was used in last bad frame */ - Word16 ni_seed_forfec; - Word16 ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ - + /*----------------------------------------------------------------------------------* * LD music post-filter *----------------------------------------------------------------------------------*/ - Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ - Word16 LDm_last_music_flag_fx; /* LD music post-filter - last music flag */ - Word16 LDm_nb_thr_1_fx; /* LD music post-filter - number of consecutives frames of level 1 */ - Word16 LDm_nb_thr_3_fx; - Word16 dct_post_old_exc_fx[DCT_L_POST-OFFSET2]; - Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ - Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ - Word16 LDm_enh_lp_gbin_fx[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ - Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ - Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ - Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ - Word16 filt_lfE_fx[DCT_L_POST]; - Word16 last_nonfull_music_fx; - Word16 Old_ener_Q; /* Old energy scaling factor */ + MUSIC_POSTFILT_HANDLE hMusicPF; /*----------------------------------------------------------------------------------* * Fixed point only @@ -851,23 +1166,29 @@ typedef struct Decoder_State_fx Word16 prev_Q_bwe_syn; Word16 prev_Q_bwe_syn2; + Word16 prev_Q_bwe_exc_fb; + Word16 prev_Qx; + Word16 prev_Q_bwe_exc; + Word16 prev_Q_synth; + Word16 prev_SWB_fenv_fx[SWB_FENV]; + Word16 Q_syn2; Word16 Q_syn; Word16 prev_Q_syn; - Word16 prev_hb_synth_fx_exp; + Word16 prev_frame_pow_exp; + Word16 prev_ener_fx_Q; + Word16 last_wb_bwe_ener_fx; + Word16 prev_fb_ener_adjust_fx; Word16 prev_synth_buffer_fx[NS2SA(48000,DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)]; Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; Word16 GainShape_Delay[NUM_SHB_SUBFR/2]; - Word16 vbr_hw_BWE_disable_dec_fx; - Word16 last_vbr_hw_BWE_disable_dec_fx; HANDLE_CLDFB_FILTER_BANK cldfbAna_fx; /* main analysis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbBPF_fx; /* BPF analysis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbSyn_fx; /* main synthesis filter bank handle */ Word16 last_active_bandsToZero_bwdec; - Word16 flag_NB_bwddec; Word16 last_flag_filter_NB; Word16 perc_bwddec; /*Q14*/ Word16 active_frame_cnt_bwddec; @@ -883,11 +1204,9 @@ typedef struct Decoder_State_fx ACELP_config acelp_cfg_rf; /* configuration for RF frame */ - /*TCX config*/ - TCX_config tcx_cfg; - Word16 L_frameTCX; + TCX_CONFIG_HANDLE hTcxCfg; /* TCX config */ - /* evs decoder */ + /* evs decoder */ Word16 m_decodeMode; Word16 m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ Word16 m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ @@ -901,16 +1220,7 @@ typedef struct Decoder_State_fx Word8 last_is_cng; - Word16 old_syn_Overl[L_FRAME32k/2]; - Word16 syn_Overl_TDAC[L_FRAME32k/2]; - Word16 syn_Overl_TDACFB[L_FRAME_MAX/2]; - - Word16 syn_Overl[L_FRAME32k/2]; - Word16 syn_OverlFB[L_FRAME_MAX/2]; - Word16 old_synth[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ - Word16 old_synth_len; - Word16 old_synth_lenFB; Word16 syn[M+1]; /* bass_pf.c */ @@ -938,9 +1248,6 @@ typedef struct Decoder_State_fx Word16 last_concealed_gain_syn_deemph; /*Q15*/ Word16 last_concealed_gain_syn_deemph_e; - Word8 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ - Word8 envWeighted; /* are is{p,f}_old[] weighted or not? */ - /* variables for framing */ Word16 nb_subfr; @@ -956,8 +1263,6 @@ typedef struct Decoder_State_fx Word16 pit_res_max; Word16 pit_res_max_past; - Word16 pit_max_TCX; /*int Q0*/ - Word16 pit_min_TCX; /*int*/ /*Preemphasis factor*/ Word16 preemph_fac; /*0Q15*/ @@ -977,33 +1282,18 @@ typedef struct Decoder_State_fx Word16 clas_dec; Word16 mem_pitch_gain[2*NB_SUBFR16k+2]; /* Pitch gain memory Q14 */ Word8 plc_use_future_lag; - Word16 prev_widow_left_rect; Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ - Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ - Word16 conCngLevelBackgroundTrace_e; - /* state variables for the minimum statistics used for PLC */ - Word16 conNoiseLevelMemory[PLC_MIN_STAT_BUFF_SIZE];/*Q15*/ - Word16 conNoiseLevelMemory_e[PLC_MIN_STAT_BUFF_SIZE]; - Word16 conNoiseLevelIndex; /*Q0*/ - Word16 conCurrLevelIndex; /*Q0*/ - Word16 conLastFrameLevel;/*Q15*/ - Word16 conLastFrameLevel_e; - Word16 old_gaintcx_bfi, old_gaintcx_bfi_e; - Word16 cummulative_damping_tcx; Word16 cummulative_damping; /*Q15*/ Word16 cngTDLevel; Word16 cngTDLevel_e; - Word16 conceal_eof_gain; /*Q14*/ - Word16 damping; /* 1Q14 */ - Word16 gainHelper; /*can be >1*/ - Word16 gainHelper_e; - Word16 stepCompensate; - Word16 stepCompensate_e; + Word16 prev_widow_left_rect; + + + Word16 reset_mem_AR; - Word16 tcxConceal_recalc_exc; Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ @@ -1018,42 +1308,33 @@ typedef struct Decoder_State_fx Word16 TcxBandwidth; /* For NB and formant post-filter */ - PFSTAT pfstat; + PFSTAT_HANDLE hPFstat; /* NB and formant post-filter states */ Word16 psf_lp_noise_fx; + Word16 last_voice_factor_fx; /* Q6*/ /* For adaptive tilt_code */ Word16 voice_fac; - Word8 tcxonly; + Word16 tcxonly; - /*TCX resisual Q*/ - Word16 resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ Word16 last_ctx_hm_enabled; - /* TCX-LTP */ - Word8 tcxltp; - Word16 tcxltp_gain; - Word16 tcxltp_pitch_int; - Word16 tcxltp_pitch_fr; - - Word16 tcxltp_mem_in[TCXLTP_MAX_DELAY]; - Word16 tcxltp_mem_out[L_FRAME48k]; - Word16 tcxltp_pitch_int_post_prev; - Word16 tcxltp_pitch_fr_post_prev; - Word16 tcxltp_gain_post_prev; - Word16 tcxltp_filt_idx_prev; + /*----------------------------------------------------------------------------------* + * TCX LTP decoder handle + *----------------------------------------------------------------------------------*/ + TCX_LTP_DEC_HANDLE hTcxLtpDec; struct tonalmdctconceal tonalMDCTconceal; Word8 tonal_mdct_plc_active; Word8 last_tns_active; Word8 second_last_tns_active; Word16 second_last_core; - Word32 tcxltp_second_last_pitch; - Word32 tcxltp_third_last_pitch; - Word16 tcxltp_last_gain_unmodified; + /*----------------------------------------------------------------------------------* + * TCX core decoder handle + *----------------------------------------------------------------------------------*/ - Word16 FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ + TCX_DEC_HANDLE hTcxDec; /* parameters for switching */ Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ @@ -1086,12 +1367,9 @@ typedef struct Decoder_State_fx Word8 dec_glr; Word16 dec_glr_idx; - Word16 tcx_hm_LtpPitchLag; - Word16 tcx_lpc_shaped_ari; Word16 igf; - IGFDEC_INSTANCE hIGFDec; - + IGF_DEC_INSTANCE_HANDLE hIGFDec; CLDFB_SCALE_FACTOR scaleFactor; Word16 tec_tfa; @@ -1102,13 +1380,38 @@ typedef struct Decoder_State_fx Word16 con_tcx; Word16 last_con_tcx; Word16 old_ppp_mode_fx; - Word16 old_hb_synth_fx[L_FRAME48k]; Word16 prev_Q_exc_fr; Word16 prev_Q_syn_fr; Word16 writeFECoffset; - -} Decoder_State_fx; + /*----------------------------------------------------------------------------------* + * Stereo/IVAS parameters + *----------------------------------------------------------------------------------*/ + Word16 bits_frame_nominal; /* avg bits per frame on active frame */ + Word16 last_bits_frame_nominal; /* last avg bits per frame on active frame */ + Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ + + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ + Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 cng_sba_flag; /* CNG in SBA flag */ + Word16 idchan; /* channel ID (audio channel number) */ + Word16 element_mode; /* element mode */ + Word16 last_element_mode; /* element mode */ + Word16 low_rate_mode; /* low-rate mode flag */ + Word16 last_low_rate_mode; /* previous low-rate mode flag */ + Word16 coder_type_fx; /* low-rate mode flag */ + Word16 mct_chan_mode; + Word16 cng_ism_flag; /* CNG in ISM format flag */ + Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ + +#ifdef DEBUGGING + Word16 id_element; /* element ID */ +#endif + Word32 element_brate; /* element bitrate */ + Word16 extl_orig; /* extension layer */ + Word32 extl_brate_orig; /* extension layer bitrate */ + +} Decoder_State_fx, * DEC_CORE_HANDLE; #endif diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index 8fa2b8a..dbb5fe6 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -2,8 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "prot_fx.h" /* Function prototypes */ @@ -14,22 +14,24 @@ *---------------------------------------------------------*/ void stat_noise_uv_dec_fx( Decoder_State_fx *st_fx, /* i/o: Decoder static memory */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ + Word16 *lsp_new, /* i : end-frame LSP vector */ + Word16 *lsp_mid, /* i : mid-frame LSP vector */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ + Word16 *exc2 /* i/o: excitation buffer */ + , const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ) { Word16 noisiness = 0, i; Word32 L_tmp; + Word16 coder_type = st_fx->coder_type_fx; + /*-----------------------------------------------------------------* * Decode the VAD flag *-----------------------------------------------------------------*/ test(); test(); - IF( EQ_16(coder_type,UNVOICED )||(EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_9k60))) + IF( (EQ_16(coder_type,UNVOICED ) && !uc_two_stage_flag) ||(EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_9k60))) { /* read the noisiness parameter */ noisiness = (Word16)get_next_indice_fx( st_fx, 5 ); diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 17b1370..7ec0328 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -2,15 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "rom_com_fx.h" #include "rom_enc_fx.h" - -#include "stl.h" #define MAX_Q_NEW_INPUT 8 #define Q_WTDA_FX 13 #define Q_32_BITS 15 @@ -26,7 +24,6 @@ Word16 para_pred_bws_fx( Word16 *signal_wb_fx, /* i : wideband frequency signal */ Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ Word16 Q_syn - ,Word16 coder_type /* i : coding type */ ) { Word16 i, j, k; @@ -40,6 +37,7 @@ Word16 para_pred_bws_fx( Word32 mean_fx[7], peak_32_fx; Word32 avrg1_fx, avrg2_fx, min_fx; Word16 att_fx; + Word16 coder_type = st_fx->coder_type_fx; mode = NORMAL; move16(); @@ -232,7 +230,7 @@ Word16 para_pred_bws_fx( FOR(i=0; iprev_coder_type_fx, coder_type)&>_16(mult_r(SWB_fenv_fx[i],16384),st_fx->prev_SWB_fenv_fx[i])) + IF(NE_16(st_fx->prev_coder_type_fx, coder_type)&>_16(mult_r(SWB_fenv_fx[i],16384), st_fx->prev_SWB_fenv_fx[i])) { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], 3277), st_fx->prev_SWB_fenv_fx[i], 29491)); @@ -261,7 +259,7 @@ Word16 para_pred_bws_fx( { FOR(i=0; iprev_SWB_fenv_fx[i])) + if(GT_16(mult_r(SWB_fenv_fx[i], 16384), st_fx->prev_SWB_fenv_fx[i])) { SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; move16(); @@ -354,13 +352,18 @@ Word16 WB_BWE_gain_deq_fx( * WB BWE decoder (only for 16kHz signals) *-------------------------------------------------------------------*/ Word16 wb_bwe_dec_fx( - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 output_frame, /* i : frame length */ - Word16 coder_type, /* i : coding type */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ +#ifdef ADD_IVAS_BWE + const Word16 output[], /* i : suntehsis @ internal Fs */ +#endif + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ +#ifdef ADD_IVAS_BWE + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ +#endif + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors */ + const Word16 pitch_buf_fx[], /* i : pitch buffer */ + Decoder_State_fx *st_fx /* i/o: decoder state structure */ ,Word16 * Qpost ) { @@ -371,18 +374,36 @@ Word16 wb_bwe_dec_fx( Word32 L_wtda_synth_fx[2*L_FRAME48k], ysynth_32[L_FRAME48k], t_audio32_tmp[L_FRAME48k]; Word16 scl, new_input_fx_exp; Word16 i; + FD_BWE_DEC_HANDLE hBWE_FD; + + Word16 coder_type = st_fx->coder_type_fx; + + hBWE_FD = st_fx->hBWE_FD; /* MDCT of the core synthesis signal */ new_input_fx_exp = *Qpost; move16(); - wtda_fx(synth_fx, &new_input_fx_exp, L_wtda_synth_fx, st_fx->L_old_wtda_swb_fx, - &st_fx->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); - *Qpost = sub(new_input_fx_exp,15); - /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp); +#ifdef ADD_IVAS_BWE + if (st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft) + { + /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ + /* IVAS_fmToDo: delay output[] by 1.25ms ? */ + lerp(output, ysynth, L_FRAME16k, st->L_frame); + wtda(ysynth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k); + direct_transform(wtda_synth, ysynth, 0, /*st->L_frame*/ L_FRAME16k, st->element_mode); + } + else +#endif + { + wtda_fx(synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + output_frame); + *Qpost = sub(new_input_fx_exp, 15); + /* DCT of the ACELP core synthesis */ + direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode); + } /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); /* Possible to Upscale? */ @@ -398,7 +419,11 @@ Word16 wb_bwe_dec_fx( Q_syn = add(sub(new_input_fx_exp, 16), scl); IF( !st_fx->bfi_fx ) { +#ifdef ADD_IVAS_BWE + IF( st_fx->extl_brate > 0) +#else IF( EQ_32(st_fx->total_brate_fx, ACELP_13k20)) +#endif { /* de-quantization */ mode = WB_BWE_gain_deq_fx(st_fx, WB_fenv_fx ); @@ -406,6 +431,17 @@ Word16 wb_bwe_dec_fx( } ELSE { + int32_t tmp_brate; + + tmp_brate = st_fx->last_core_brate_fx; +#if 1//def ADD_IVAS_BWE + test(); + IF (EQ_32(st_fx->last_total_brate_fx, ACELP_9k60) && EQ_16(st_fx->last_extl_fx, SWB_TBE ) ) + { + tmp_brate = ACELP_8k00; /* this is needed in order to stay BE wrt. EVS mono */ + move16(); + } +#endif if( NE_16(st_fx->last_extl_fx, WB_BWE)) { st_fx->prev_SWB_fenv_fx[0] = 0; @@ -413,9 +449,8 @@ Word16 wb_bwe_dec_fx( } mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type_fx, st_fx->prev_SWB_fenv_fx[0], - voice_factors_fx, pitch_buf_fx, st_fx->last_core_brate_fx, st_fx->last_wb_bwe_ener_fx, Q_syn - ,st_fx->last_extl_fx, st_fx->tilt_wb_fx - ); + voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->last_wb_bwe_ener_fx, Q_syn + ,st_fx->last_extl_fx, st_fx->tilt_wb_fx); move16(); } } @@ -435,19 +470,19 @@ Word16 wb_bwe_dec_fx( Copy( WB_fenv_fx, st_fx->prev_SWB_fenv_fx, 2 ); } - exp = norm_l(st_fx->prev_Energy_wb_fx); + exp = norm_l(hBWE_FD->prev_Energy_wb_fx); IF(GT_16(add(st_fx->prev_Q_synth, exp),Q_syn)) { - st_fx->prev_Energy_wb_fx = L_shr(st_fx->prev_Energy_wb_fx, sub(st_fx->prev_Q_synth, Q_syn)); + hBWE_FD->prev_Energy_wb_fx = L_shr(hBWE_FD->prev_Energy_wb_fx, sub(st_fx->prev_Q_synth, Q_syn)); } ELSE { Q_syn = add(st_fx->prev_Q_synth, exp); - st_fx->prev_Energy_wb_fx = L_shl(st_fx->prev_Energy_wb_fx, exp); + hBWE_FD->prev_Energy_wb_fx = L_shl(hBWE_FD->prev_Energy_wb_fx, exp); } WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode, - st_fx->last_extl_fx, &st_fx->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &st_fx->prev_L_swb_norm_fx, - st_fx->extl_fx, coder_type, st_fx->total_brate_fx, &st_fx->Seed_fx, &st_fx->prev_flag_fx, + st_fx->last_extl_fx, &hBWE_FD->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm_fx, + st_fx->extl_fx, coder_type, st_fx->total_brate_fx, &hBWE_FD->Seed_fx, &hBWE_FD->prev_flag_fx, st_fx->prev_coder_type_fx, Q_syn, &Q_syn_hb ); IF ( EQ_32(st_fx->output_Fs_fx, 32000)) { @@ -457,10 +492,19 @@ Word16 wb_bwe_dec_fx( { set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME32k ); } - Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame ); - window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, st_fx->mem_imdct_fx, &st_fx->mem_imdct_exp_fx, output_frame, + Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode ); + window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW,ALDO_WINDOW, 0,0,0); - st_fx->prev_mode_fx = mode; + +#ifdef ADD_IVAS_BWE + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && !use_cldfb_for_dft) + { + /* add HB synth from hf_synth() */ + v_add(hb_synth, synth, hb_synth, output_frame); + } +#endif + hBWE_FD->prev_mode_fx = mode; st_fx->prev_Q_synth = Q_syn; return Q_syn_hb; } @@ -701,15 +745,20 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ /*-------------------------------------------------------------------* * swb_bwe_dec() * - * SWB BWE decoder (only for 32kHz signals) + * SWB BWE decoder *-------------------------------------------------------------------*/ Word16 swb_bwe_dec_fx( +#ifdef ADD_IVAS_BWE + const Word16 output[], /* i : suntehsis @ internal Fs */ +#endif Decoder_State_fx *st_fx, /* i/o: decoder state structure */ Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ +#ifdef ADD_IVAS_BWE + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ +#endif const Word16 output_frame /* i : frame length */ ,Word16 * Qpost - ,Word16 coder_type /* i : coding type */ ) { Word16 i, l_subfr; @@ -732,20 +781,38 @@ Word16 swb_bwe_dec_fx( Word16 j = 0; Word16 ener_adjust_quan_fx; Word16 tmp2; + Word16 fb_band_begin; + FD_BWE_DEC_HANDLE hBWE_FD; + hBWE_FD = st_fx->hBWE_FD; + /*---------------------------------------------------------------------* * SWB BWE decoding *---------------------------------------------------------------------*/ /* windowing of the ACELP core synthesis */ new_input_fx_exp = *Qpost; - wtda_fx(synth_fx, &new_input_fx_exp, L_wtda_synth_fx, st_fx->L_old_wtda_swb_fx, - &st_fx->old_wtda_swb_fx_exp, +#ifdef ADD_IVAS_BWE + if (st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft) + { + /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ + /* IVAS_fmToDo: delay output[] by 1.25ms ? */ + lerp(output, ysynthIfx, L_FRAME16k, st_fx->L_frame); + + wtda_fx(ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k); + direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, /*st->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode); + } + else +#endif + { + wtda_fx(synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); - *Qpost = sub(new_input_fx_exp,15); - /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp); - + output_frame); + *Qpost = sub(new_input_fx_exp, 15); + /* DCT of the ACELP core synthesis */ + direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode); + } /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); /* Possible to Upscale? */ @@ -765,7 +832,7 @@ Word16 swb_bwe_dec_fx( IF( st_fx->bws_cnt_fx > 0 ) { /* estimate parameters */ - mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn, coder_type ); + mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn); move16(); } ELSE @@ -798,9 +865,9 @@ Word16 swb_bwe_dec_fx( ELSE { /* SHB FEC */ - IF( NE_16(st_fx->prev_mode_fx, TRANSIENT)) + IF( NE_16(hBWE_FD->prev_mode_fx, TRANSIENT)) { - mode = st_fx->prev_mode_fx; + mode = hBWE_FD->prev_mode_fx; move16(); } ELSE @@ -809,39 +876,37 @@ Word16 swb_bwe_dec_fx( move16(); } - Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); + Copy(st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); } /* reconstruction of MDCT spectrum of the error signal */ set32_fx( ysynth_32, 0, output_frame ); IF ( EQ_16(st_fx->L_frame_fx, L_FRAME16k)) { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &st_fx->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, - &st_fx->prev_L_swb_norm_fx, st_fx->tilt_wb_fx, &st_fx->Seed_fx, 80, &st_fx->prev_weight_fx, st_fx->extl_fx, Q_syn - ,st_fx->last_extl_fx - ); + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, + &hBWE_FD->prev_L_swb_norm_fx, st_fx->tilt_wb_fx, &hBWE_FD->Seed_fx, 80, &hBWE_FD->prev_weight_fx, st_fx->extl_fx, Q_syn + ,st_fx->last_extl_fx); } ELSE { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &st_fx->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, - &st_fx->prev_L_swb_norm_fx, st_fx->tilt_wb_fx, &st_fx->Seed_fx, 6, &st_fx->prev_weight_fx, st_fx->extl_fx, Q_syn - ,st_fx->last_extl_fx - ); + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, + &hBWE_FD->prev_L_swb_norm_fx, st_fx->tilt_wb_fx, &hBWE_FD->Seed_fx, 6, &hBWE_FD->prev_weight_fx, st_fx->extl_fx, Q_syn, + st_fx->last_extl_fx); } test(); - IF ( EQ_16(st_fx->prev_frica_flag_fx, 1)&&frica_flag==0) + IF ( EQ_16(hBWE_FD->prev_frica_flag_fx, 1) && frica_flag==0) { FOR( i = 0; i < L_SUBFR; i++ ) { tmp = sub(32767, extract_l(L_mult0(i, 512))); /*Q15 */ - st_fx->mem_imdct_fx[i] = mult_r(st_fx->mem_imdct_fx[i], tmp); + hBWE_FD->mem_imdct_fx[i] = mult_r(hBWE_FD->mem_imdct_fx[i], tmp); move16(); /*Q_synth */ } FOR( ; i < output_frame; i++ ) { - st_fx->mem_imdct_fx[i] = 0; + hBWE_FD->mem_imdct_fx[i] = 0; move16(); } } @@ -882,8 +947,14 @@ Word16 swb_bwe_dec_fx( move16(); /*Q13*/ } } - - FOR( i = FB_BAND_BEGIN; i < FB_BAND_BEGIN+DE_OFFSET1; i++ ) + fb_band_begin = FB_BAND_BEGIN; +#ifdef ADD_IVAS_BWE + IF (st_fx->L_frame == L_FRAME) + { + fb_band_begin = FB_BAND_BEGIN_12k8; + } +#endif + FOR( i = fb_band_begin; i < fb_band_begin +DE_OFFSET1; i++ ) { tmp = sub(32767, i_mult(j, 1024)); tmp = mult_r(tmp, ener_adjust_quan_fx); /*Q13*/ @@ -909,9 +980,8 @@ Word16 swb_bwe_dec_fx( } Q_syn_hb = add(Q_syn, Q_32_BITS); - Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame ); - window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, st_fx->mem_imdct_fx, &st_fx->mem_imdct_exp_fx, output_frame, - ALDO_WINDOW, ALDO_WINDOW, 0,0,0); + Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode ); + window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0,0,0); l_subfr = mult(output_frame, 8192); test(); @@ -927,12 +997,12 @@ Word16 swb_bwe_dec_fx( time_envelop_shaping_fx( hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); Q_syn_hb = sub(Q_syn_hb, 3); - st_fx->prev_td_energy_fx = SWB_tenv_fx[3]; + hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3]; move16(); } - ELSE IF( EQ_16(frica_flag, 1)&&st_fx->prev_frica_flag_fx==0) + ELSE IF( EQ_16(frica_flag, 1) && hBWE_FD->prev_frica_flag_fx==0) { - time_reduce_pre_echo_fx( synth_fx, hb_synth_fx, st_fx->prev_td_energy_fx, l_subfr, *Qpost, Q_syn_hb ); + time_reduce_pre_echo_fx( synth_fx, hb_synth_fx, hBWE_FD->prev_td_energy_fx, l_subfr, *Qpost, Q_syn_hb ); } ELSE { @@ -944,7 +1014,7 @@ Word16 swb_bwe_dec_fx( } L_tmp = Mult_32_16(L_tmp, div_s(1, l_subfr)); /*(2*Q_syn_hb) */ - st_fx->prev_td_energy_fx = 0; + hBWE_FD->prev_td_energy_fx = 0; move16(); IF(L_tmp != 0) { @@ -955,14 +1025,75 @@ Word16 swb_bwe_dec_fx( tmp = div_s(16384, frac); L_tmp = L_deposit_h(tmp); L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - st_fx->prev_td_energy_fx = round_fx(L_shl(L_tmp, sub(exp,15))); /*Q0 */ + hBWE_FD->prev_td_energy_fx = round_fx(L_shl(L_tmp, sub(exp,15))); /*Q0 */ } } - - st_fx->prev_frica_flag_fx = frica_flag; +#ifdef ADD_IVAS_BWE + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && !use_cldfb_for_dft) + { + /* add HB synth from hf_synth() */ + v_add(hb_synth, synth, hb_synth, output_frame); + } +#endif + hBWE_FD->prev_frica_flag_fx = frica_flag; move16(); - st_fx->prev_mode_fx = mode; + hBWE_FD->prev_mode_fx = mode; move16(); return Q_syn_hb; } + + +/*-------------------------------------------------------------------* +* fd_bwe_dec_init() +* +* Initialize FD BWE state structure at the decoder +*-------------------------------------------------------------------*/ + +void fd_bwe_dec_init( + Decoder_State_fx* st_fx, /* i/o: decoder state structure */ + FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ +) +{ + hBWE_FD->old_wtda_wb_fx_exp = 0; + move16(); + set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k); + hBWE_FD->old_wtda_swb_fx_exp = 0; + move16(); + hBWE_FD->mem_imdct_exp_fx = 0; + move16(); + + hBWE_FD->prev_mode_fx = NORMAL; + move16(); + set16_fx(st_fx->prev_SWB_fenv_fx, 0, SWB_FENV); + hBWE_FD->prev_Energy_fx = 0; + move16(); + hBWE_FD->prev_L_swb_norm_fx = 8; + move16(); + hBWE_FD->Seed_fx = 21211; + move16(); + hBWE_FD->prev_frica_flag_fx = 0; + move16(); + set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k); + hBWE_FD->prev_td_energy_fx = 0; + move16(); + hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); + hBWE_FD->prev_flag_fx = 0; + move16(); + st_fx->last_wb_bwe_ener_fx = 0; + move16(); + hBWE_FD->prev_Energy_wb_fx = L_deposit_l(0); + hBWE_FD->memExp1 = 0; + move16(); + + /* Previous frame LPC initialization for PPP */ + st_fx->prev_Q_synth = 0; + move16(); + + hBWE_FD->mem_deemph_old_syn_fx = 0; + st_fx->prev_fb_ener_adjust_fx = 0; + + return; +} \ No newline at end of file diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 7855044..4a9bc33 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_dec_fx.h" /* Static table prototypes */ #include "cnst_fx.h" /* Static table prototypes */ -#include "stl.h" #define Q_GUARD 1 #define Q_32_BITS 14 /* scaling of 't_audio32' */ @@ -29,8 +28,8 @@ versus gain_dequant_fx() which does. */ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ Word16 index, /* i: quantization index */ - const Word16 min, /* i: value of lower limit (Q13) */ - const Word16 bits, /* i: number of bits to dequantize */ + const Word16 min, /* i: value of lower limit (Q13) */ + const Word16 bits, /* i: number of bits to dequantize */ Word16 *exp /* o: exponent of Decoded Gain */ ) { @@ -113,7 +112,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ *-------------------------------------------------------------------*/ static Word16 TD_Postprocess( /* o : gain in Q15 */ - Word16 hb_synth_fx[], /* i/o: high-band synthesis */ + Word16 hb_synth_fx[], /* i/o: high-band synthesis */ const Word16 hb_synth_fx_exp, /* i : Q of high-band synthesis */ const Word16 input_frame, /* i : frame length */ const Word16 last_extl /* i : last extension layer */ @@ -267,13 +266,19 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ Word16 *t_audio, *t_audio_tmp; Word16 env = 0; Word16 exp_L, inv_L, frac; + FD_BWE_DEC_HANDLE hBWE_FD; + HR_BWE_DEC_HANDLE hBWE_FD_HR; + + hBWE_FD = st_fx->hBWE_FD; + hBWE_FD_HR = st_fx->hBWE_FD_HR; /* Use 't_audio32_tmp' Word32 Buffer as two Word16 Buffers to save local Stack. */ /* There is no possible overlap so it is ok */ t_audio = (Word16 *)&t_audio32_tmp[0]; t_audio_tmp = (Word16 *)&t_audio32_tmp[L_FRAME48k/2]; - st_fx->bwe_highrate_seed_fx = extract_l(L_mult0(pitch_buf[0],pitch_buf[3])); + hBWE_FD_HR->bwe_highrate_seed_fx = extract_l(L_mult0(pitch_buf[0],pitch_buf[3])); + /*---------------------------------------------------------------------* * initializations @@ -299,8 +304,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ test(); IF( EQ_16(st_fx->last_core_fx, HQ_CORE)||NE_16(st_fx->last_extl_fx,st_fx->extl_fx)) { - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); - st_fx->Q_old_wtda = 14; + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); + st_fx->hHQ_core->Q_old_wtda = 14; move16(); } @@ -328,7 +333,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ IF( st_fx->bfi_fx ) { - is_transient = st_fx->old_is_transient_hr_bwe_fx; + is_transient = hBWE_FD_HR->old_is_transient_hr_bwe_fx; move16(); /* Replication of the last spectrum, with an attenuation */ @@ -379,11 +384,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* So, after the loop, the Q will be 'Q_32_Bits' */ FOR( k=0; kt_audio_prev_fx_exp[k], Q_32_BITS); + temp4 = sub(hBWE_FD_HR->t_audio_prev_fx_exp[k], Q_32_BITS); temp4 = add(temp4, t_audio_exp); FOR( i=0; it_audio_prev_fx[i + ind1]); + L_temp = L_mult(alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1]); L_temp = L_shr(L_temp, temp4); t_audio32[pos + i] = L_temp; move32(); @@ -396,8 +401,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ { temp = add(NUM_TRANS_START_FREQ_COEF, len); temp4 = Find_Max_Norm32(t_audio32 + temp, tmpS); - Copy_Scale_sig32_16(t_audio32 + temp, st_fx->t_audio_prev_fx + i_mult2(k, tmpS), tmpS, temp4); - st_fx->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); + Copy_Scale_sig32_16(t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx + i_mult2(k, tmpS), tmpS, temp4); + hBWE_FD_HR->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); move16(); len = add(len, shr(output_frame, 2)); } @@ -417,12 +422,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* reconstruct */ /* Here t_audio was initialy filled with zeros */ /* So, after the loop, the Q will be 'Q_32_Bits' */ - temp4 = sub(st_fx->t_audio_prev_fx_exp[0], Q_32_BITS); + temp4 = sub(hBWE_FD_HR->t_audio_prev_fx_exp[0], Q_32_BITS); temp4 = add(temp4, t_audio_exp); ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; FOR( i=0; it_audio_prev_fx[i]); + L_temp = L_mult(alpha, hBWE_FD_HR->t_audio_prev_fx[i]); L_temp = L_shr(L_temp, temp4); *ptr32++ = L_temp; move32(); @@ -431,14 +436,14 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ temp = NUM_NONTRANS_START_FREQ_COEF; move16(); /* not necessary but improves readability and allows a larger common code path */ temp4 = Find_Max_Norm32(t_audio32 + temp, tmpS); - Copy_Scale_sig32_16(t_audio32 + temp, st_fx->t_audio_prev_fx, tmpS, temp4); - st_fx->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); + Copy_Scale_sig32_16(t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx, tmpS, temp4); + hBWE_FD_HR->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); move16(); } - st_fx->L_mem_EnergyLT_fx = Mul_flt32_Q15(st_fx->L_mem_EnergyLT_fx, &st_fx->mem_EnergyLT_fx_exp, alpha); + hBWE_FD_HR->L_mem_EnergyLT_fx = Mul_flt32_Q15(hBWE_FD_HR->L_mem_EnergyLT_fx, &hBWE_FD_HR->mem_EnergyLT_fx_exp, alpha); move32(); - st_fx->mem_EnergyLT_fx_exp = add(st_fx->mem_EnergyLT_fx_exp, t_audio_exp); + hBWE_FD_HR->mem_EnergyLT_fx_exp = add(hBWE_FD_HR->mem_EnergyLT_fx_exp, t_audio_exp); /* Set Exponent */ t_audio_exp = Q_32_BITS; @@ -447,13 +452,13 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ inv_L = div_s(shl(1,sub(14,exp_L)), output_frame); /*Q(29-exp_L)*/ /*Q(st_fx->mem_EnergyLT_fx_exp+29-exp_L-15) -> Q(st_fx->mem_EnergyLT_fx_exp-exp_L+14)*/ - st_fx->L_mem_EnergyLT_fx = Mul_flt32_Q15(st_fx->L_mem_EnergyLT_fx, &st_fx->mem_EnergyLT_fx_exp, inv_L); + hBWE_FD_HR->L_mem_EnergyLT_fx = Mul_flt32_Q15(hBWE_FD_HR->L_mem_EnergyLT_fx, &hBWE_FD_HR->mem_EnergyLT_fx_exp, inv_L); move32(); - IF(st_fx->L_mem_EnergyLT_fx != 0) + IF(hBWE_FD_HR->L_mem_EnergyLT_fx != 0) { - exp1 = norm_l(st_fx->L_mem_EnergyLT_fx); - frac = extract_h(L_shl(st_fx->L_mem_EnergyLT_fx, exp1)); - exp1 = sub(exp1,sub(16,sub(st_fx->mem_EnergyLT_fx_exp,exp_L))); + exp1 = norm_l(hBWE_FD_HR->L_mem_EnergyLT_fx); + frac = extract_h(L_shl(hBWE_FD_HR->L_mem_EnergyLT_fx, exp1)); + exp1 = sub(exp1,sub(16,sub(hBWE_FD_HR->mem_EnergyLT_fx_exp,exp_L))); temp = div_s(16384, frac); L_temp = L_deposit_h(temp); @@ -575,8 +580,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; move16(); +#ifdef AVQ_DEMUX + AVQ_demuxdec_fx(st_fx, x_norm, &nBits, Nsv, nq, 0, sub(Nsv,1)); +#else AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq ); - +#endif temp = add(len, NUM_TRANS_START_FREQ_COEF); /* 't_audio' in Q8 */ t_audio_exp = 8; @@ -590,7 +598,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* apply noise-fill */ swb_hr_noise_fill_fx( is_transient, NUM_TRANS_START_FREQ_COEF, NUM_TRANS_END_FREQ_COEF, round_fx(L_shl(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ - pitch, nq, Nsv, &st_fx->bwe_highrate_seed_fx, t_audio+temp, t_audio_exp ); + pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio+temp, t_audio_exp ); /* Go from Q't_audio_exp' on 16 Bits to 'Q_32_BITS' on 32 bits */ temp2 = i_mult2(WIDTH_BAND, Nsv); @@ -702,8 +710,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ pos = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; } temp4 = Find_Max_Norm32(t_audio32 + temp, pos); - Copy_Scale_sig32_16(t_audio32 + temp, st_fx->t_audio_prev_fx + i_mult2(k, pos), pos, temp4); - st_fx->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); + Copy_Scale_sig32_16(t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx + i_mult2(k, pos), pos, temp4); + hBWE_FD_HR->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); move16(); len = add(len, shr(output_frame, 2)); @@ -830,8 +838,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ /* Nsv = i / WIDTH_BAND */ Nsv = shr(i, 3); +#ifdef AVQ_DEMUX + AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq, 0, sub(Nsv,1) ); +#else AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq ); - +#endif /*---------------------------------------------------------------------* * second stage decoding *---------------------------------------------------------------------*/ @@ -868,7 +879,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ } nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); +#ifdef AVQ_DEMUX + AVQ_demuxdec_fx( st_fx, x_norm1, &nBits, Nsv2, nq2, 0, sub(Nsv2,1) ); +#else AVQ_demuxdec_fx( st_fx, x_norm1, &nBits, Nsv2, nq2 ); +#endif } /*---------------------------------------------------------------------* @@ -1003,7 +1018,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ { swb_hr_noise_fill_fx( is_transient, NUM_NONTRANS_START_FREQ_COEF, NUM_NONTRANS_END_FREQ_COEF, round_fx(L_shl(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ - pitch, nq, Nsv, &st_fx->bwe_highrate_seed_fx, t_audio + NUM_NONTRANS_START_FREQ_COEF, t_audio_exp ); + pitch, nq, Nsv, &hBWE_FD_HR->bwe_highrate_seed_fx, t_audio + NUM_NONTRANS_START_FREQ_COEF, t_audio_exp ); } /* Go from Q't_audio_exp' on 16 Bits to Q16 on 32 bits */ @@ -1237,8 +1252,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ pos = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; } temp4 = Find_Max_Norm32(t_audio32 + temp, pos); - Copy_Scale_sig32_16(t_audio32 + temp, st_fx->t_audio_prev_fx, pos, temp4); - st_fx->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); + Copy_Scale_sig32_16(t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx, pos, temp4); + hBWE_FD_HR->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); move16(); /* attenuate HFs in case of band-width switching */ @@ -1282,12 +1297,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ *---------------------------------------------------------------------*/ t_audio_exp = Q_32_BITS; - - Inverse_Transform( t_audio32, &t_audio_exp, t_audio32_tmp, is_transient, output_frame, output_frame ); - - window_ola_fx( t_audio32_tmp, hb_synth_fx, &t_audio_exp, st_fx->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, 0,0,0); - + + Inverse_Transform( t_audio32, &t_audio_exp, t_audio32_tmp, is_transient, output_frame, output_frame, st_fx->element_mode); + window_ola_fx( t_audio32_tmp, hb_synth_fx, &t_audio_exp, hBWE_FD->L_old_wtda_swb_fx, &st_fx->hHQ_core->Q_old_wtda, output_frame,ALDO_WINDOW, ALDO_WINDOW, 0,0,0); hb_synth_fx_exp = t_audio_exp; move16(); @@ -1299,8 +1311,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ { IsTransient = 0; move16(); - L_EnergyLT = L_add(st_fx->L_mem_EnergyLT_fx, 0); - temp4 = st_fx->mem_EnergyLT_fx_exp; + L_EnergyLT = L_add(hBWE_FD_HR->L_mem_EnergyLT_fx, 0); + temp4 = hBWE_FD_HR->mem_EnergyLT_fx_exp; move16(); pos = 0; move16(); @@ -1389,7 +1401,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ IF( EQ_16(st_fx->last_extl_fx, st_fx->extl_fx)) { - L_temp = Div_flt32_flt32( L_ener_saved, ener_saved_exp, st_fx->L_mem_EnergyLT_fx, st_fx->mem_EnergyLT_fx_exp, &temp2 ); + L_temp = Div_flt32_flt32( L_ener_saved, ener_saved_exp, hBWE_FD_HR->L_mem_EnergyLT_fx, hBWE_FD_HR->mem_EnergyLT_fx_exp, &temp2 ); temp3 = sub(temp2, 1); L_temp2 = Isqrt_lc(L_temp, &temp3); temp3 = sub(sub(30+31-15+1, temp2), temp3); @@ -1446,11 +1458,11 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ } } - st_fx->L_mem_EnergyLT_fx = L_EnergyLT; + hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; move32(); - st_fx->mem_EnergyLT_fx_exp = temp4; + hBWE_FD_HR->mem_EnergyLT_fx_exp = temp4; move16(); - st_fx->old_is_transient_hr_bwe_fx = is_transient; + hBWE_FD_HR->old_is_transient_hr_bwe_fx = is_transient; move16(); } @@ -1464,7 +1476,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ FOR( i=0; iL_old_wtda_swb_fx[i] = mult_r(st_fx->L_old_wtda_swb_fx[i], temp); + hBWE_FD->L_old_wtda_swb_fx[i] = mult_r(hBWE_FD->L_old_wtda_swb_fx[i], temp); move16(); } @@ -1478,7 +1490,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ FOR( i=0; it_audio_prev_fx[i] = mult_r(st_fx->t_audio_prev_fx[i], temp); + hBWE_FD_HR->t_audio_prev_fx[i] = mult_r(hBWE_FD_HR->t_audio_prev_fx[i], temp); move16(); } } @@ -1486,3 +1498,27 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ return hb_synth_fx_exp; } + +/*-------------------------------------------------------------------* + * hr_bwe_dec_init() + * + * Initialize HR BWE state structure at the decoder + *-------------------------------------------------------------------*/ + +void hr_bwe_dec_init( + HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ +) +{ + set16_fx(hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF); + set16_fx(hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS); /* one exp per switching block */ + hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; + move16(); + hBWE_FD_HR->bwe_highrate_seed_fx = 12345; + move16(); + + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h(16384); + hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; + move16(); /* set to a high exponent */ + + return; +} diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index cb8fd84..5f26cba 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -4,12 +4,9 @@ #include "options.h" #include "cnst_fx.h" - #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ - /*-------------------------------------------------------------------* * DecodeSWBGenericParameters() * @@ -17,8 +14,8 @@ *-------------------------------------------------------------------*/ static void DecodeSWBGenericParameters_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + Word16 *lagIndices_fx, /* o : lowband index for each subband */ const Word16 nBands_search_fx, /* i : number of subbnads for SSearch */ const Word16 BANDS_fx, /* i : total number of subbands per frame */ const Word16 *p2a_flags_fx, /* i : HF tonal flag */ @@ -63,14 +60,15 @@ static void DecodeSWBGenericParameters_fx( *-------------------------------------------------------------------*/ static void DecodeSWBSubbands_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ Word32 *L_spectra, /* i/o: MDCT domain spectrum */ Word16 QsL, /* i : Q value of spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : subband offsets */ + const Word16 fLenLow_fx, /* i : lowband length */ + const Word16 fLenHigh_fx, /* i : highband length */ + const Word16 nBands_fx, /* i : number of subbands */ + const Word16 *sbWidth_fx, /* i : subband lengths */ + const Word16 *subband_offsets_fx, /* i : subband offsets */ Word16 *lagIndices_fx, /* i : lowband index for each subband */ Word16 *lagGains_fx, /* i : first gain for each subband */ Word16 *QlagGains, /* i : Q value of lagGains */ @@ -80,13 +78,13 @@ static void DecodeSWBSubbands_fx( Word32 *L_band_energy, /* i : band energy of each SB */ Word16 Qbe, /* i : Q value of band energy */ Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - const Word16 har_bands_fx, /* i : number of LF harmonic bands */ + const Word16 hqswb_clas_fx, /* i : class information */ + const Word16 har_bands_fx, /* i : number of LF harmonic bands */ const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ Word16 *prev_frm_hfe2_fx, /* i/o: */ Word16 *prev_stab_hfe2_fx, /* i/o: */ Word16 band_width_fx[], /* i : subband band widths */ - const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ + const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ ) { @@ -132,7 +130,7 @@ static void DecodeSWBSubbands_fx( IF( EQ_16(hqswb_clas_fx, HQ_HARMONIC)) { pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2_fx, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2_fx ); - noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, st_fx->prev_hqswb_clas_fx, &(st_fx->prev_ni_ratio_fx), &Qss); + noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas_fx, &(hHQ_core->prev_ni_ratio_fx), &Qss); IF( flag_dis == 0 ) { test(); @@ -237,11 +235,8 @@ static void DecodeSWBSubbands_fx( ); /* Level adjustment for the missing bands */ - noiseinj_hf_fx( - L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, st_fx->prev_En_sb_fx, - p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx - ); - + noiseinj_hf_fx( L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, + p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx); FOR( k = sub(BANDS_fx, NB_SWB_SUBBANDS); k < BANDS_fx; k++ ) { IF( p2a_flags_fx[k] == 0 ) @@ -272,25 +267,25 @@ static void DecodeSWBSubbands_fx( * Main decoding routine of SWB BWE for the LR MDCT core *-------------------------------------------------------------------*/ void swb_bwe_dec_lr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis */ + const Word16 QsL, /* i : Q value of m_core */ Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ Word16 BANDS_fx, /* i : Number subbands/Frame */ Word16 *band_start_fx, /* i : Band Start of each SB */ Word16 *band_end_fx, /* i : Band end of each SB */ Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ Word16 Qbe, /* i : Q value of band energy */ Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ + const Word16 hqswb_clas_fx, /* i : class information */ Word16 lowlength_fx, /* i : Lowband Length */ Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ Word16 *prev_frm_hfe2_fx, /* i/o: */ Word16 *prev_stab_hfe2_fx, /* i/o: */ Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ Word16 *ni_seed_fx /* i/o: random seed */ ) { @@ -322,16 +317,10 @@ void swb_bwe_dec_lr_fx( Copy32( L_m_core, L_m, swb_lowband_fx + swb_highband_fx ); /* Generic subband processing */ - DecodeSWBSubbands_fx( - st_fx, - L_m, QsL, - swb_lowband_fx, swb_highband_fx, nBands_fx, wBands_fx, subband_offsets_fx, - lagIndices_fx, lagGains_fx, QlagGains, - BANDS_fx, band_start_fx, band_end_fx, - L_band_energy, Qbe, - p2a_flags_fx, hqswb_clas_fx, har_bands_fx, subband_search_offset_fx, - prev_frm_hfe2_fx, prev_stab_hfe2_fx, band_width_fx, L_y2_ni, ni_seed_fx - ); + DecodeSWBSubbands_fx(st_fx,st_fx->hHQ_core,L_m, QsL,swb_lowband_fx, swb_highband_fx, nBands_fx, wBands_fx, subband_offsets_fx, + lagIndices_fx, lagGains_fx, QlagGains,BANDS_fx, band_start_fx, band_end_fx, + L_band_energy, Qbe, p2a_flags_fx, hqswb_clas_fx, har_bands_fx, subband_search_offset_fx, + prev_frm_hfe2_fx, prev_stab_hfe2_fx, band_width_fx, L_y2_ni, ni_seed_fx); p_L_m = &L_m[sub(allband_fx, 1)]; *p_L_m = Mult_32_16(*p_L_m, 2028); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 441cecd..742ae43 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -50,18 +50,20 @@ void find_max_mem_dec( Word16 tempQ15, max2 = 0; Word16 max3; Word32 tempQ32, Lmax3; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; /* old BWE exc max */ FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - tempQ15 = abs_s( st_fx->old_bwe_exc_extended_fx[i] ); + tempQ15 = abs_s(hBWE_TD->old_bwe_exc_extended_fx[i] ); max = s_max( max, tempQ15 ); } /* decimate all-pass steep memory */ FOR ( i = 0; i < 7; i++ ) { - tempQ15 = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); + tempQ15 = abs_s(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); max = s_max(max, tempQ15); } @@ -70,21 +72,21 @@ void find_max_mem_dec( /* findMaxMem2() inside tbe com */ FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s( st_fx->state_lpc_syn_fx[i] ); + tempQ15 = abs_s(hBWE_TD->state_lpc_syn_fx[i] ); max2 = s_max(max2, tempQ15); } /* findMaxMem2() inside tbe com */ FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s( st_fx->state_syn_shbexc_fx[i] ); + tempQ15 = abs_s(hBWE_TD->state_syn_shbexc_fx[i] ); max2 = s_max(max2, tempQ15); } /* findMaxMem2() inside tbe com */ FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s( st_fx->mem_stp_swb_fx[i] ); + tempQ15 = abs_s(hBWE_TD->mem_stp_swb_fx[i] ); max2 = s_max(max2, tempQ15); } @@ -98,21 +100,21 @@ void find_max_mem_dec( } /* de-emph and pre-emph memory */ - tempQ15 = abs_s( st_fx->tbe_demph_fx ); + tempQ15 = abs_s(hBWE_TD->tbe_demph_fx ); max = s_max(max, tempQ15); - tempQ15 = abs_s( st_fx->tbe_premph_fx ); + tempQ15 = abs_s(hBWE_TD->tbe_premph_fx ); max = s_max(max, tempQ15); IF( EQ_16(st_fx->extl_fx, FB_TBE)) { FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s( st_fx->fb_state_lpc_syn_fx[i] ); + tempQ15 = abs_s(hBWE_TD->fb_state_lpc_syn_fx[i] ); max = s_max(max, tempQ15); } /* FB de-emph memory */ - tempQ15 = abs_s( st_fx->fb_tbe_demph_fx); + tempQ15 = abs_s(hBWE_TD->fb_tbe_demph_fx); max = s_max(max, tempQ15); } /* estimate the norm for 16-bit memories */ @@ -123,7 +125,7 @@ void find_max_mem_dec( } /* estimate the norm for 32-bit memories */ - Lmax = L_abs( st_fx->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ + Lmax = L_abs(hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ n_mem_32 = norm_l( Lmax ); if( Lmax == 0 ) @@ -143,13 +145,13 @@ void find_max_mem_dec( /* find max in prev overlapSyn */ FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s( st_fx->syn_overlap_fx[i] ); + tempQ15 = abs_s(hBWE_TD->syn_overlap_fx[i] ); max3 = s_max(max3, tempQ15); } /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */ FOR ( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - tempQ15 = abs_s( st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i] ); + tempQ15 = abs_s(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] ); max3 = s_max(max3, tempQ15); } /* find max in prev int_3_over_2_tbemem_dec_fx */ @@ -157,7 +159,7 @@ void find_max_mem_dec( { FOR ( i = 0; i < INTERP_3_2_MEM_LEN; i++ ) { - tempQ15 = abs_s( st_fx->int_3_over_2_tbemem_dec_fx[i] ); + tempQ15 = abs_s(hBWE_TD->int_3_over_2_tbemem_dec_fx[i] ); max3 = s_max(max3, tempQ15); } } @@ -165,7 +167,7 @@ void find_max_mem_dec( { FOR ( i = 0; i < (2*ALLPASSSECTIONS_STEEP+1); i++ ) { - tempQ15 = abs_s( st_fx->mem_resamp_HB_32k_fx[i] ); + tempQ15 = abs_s(hBWE_TD->mem_resamp_HB_32k_fx[i] ); max3 = s_max(max3, tempQ15); } } @@ -179,7 +181,7 @@ void find_max_mem_dec( /* find max in prev genSHBsynth_Hilbert_Mem_fx */ FOR ( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - tempQ32 = L_abs( st_fx->genSHBsynth_Hilbert_Mem_fx[i] ); + tempQ32 = L_abs(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] ); Lmax3 = L_max(Lmax3, tempQ32); } } @@ -204,16 +206,18 @@ void rescale_genSHB_mem_dec( Word16 sf ) { Word16 i; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - st_fx->old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); + hBWE_TD->old_bwe_exc_extended_fx[i] = shl(hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } @@ -222,13 +226,13 @@ void rescale_genSHB_mem_dec( { FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); + hBWE_TD->state_lpc_syn_fx[i] = shl(hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); + hBWE_TD->state_syn_shbexc_fx[i] = shl(hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); } } @@ -236,12 +240,12 @@ void rescale_genSHB_mem_dec( IF( EQ_16(st_fx->extl_fx, FB_TBE)) { } - st_fx->mem_csfilt_fx[0] = L_shl( st_fx->mem_csfilt_fx[0], sf ); + hBWE_TD->mem_csfilt_fx[0] = L_shl(hBWE_TD->mem_csfilt_fx[0], sf ); move32(); - st_fx->tbe_demph_fx = shl_r( st_fx->tbe_demph_fx, sf ); + hBWE_TD->tbe_demph_fx = shl_r(hBWE_TD->tbe_demph_fx, sf ); move16(); - st_fx->tbe_premph_fx = shl_r( st_fx->tbe_premph_fx, sf ); + hBWE_TD->tbe_premph_fx = shl_r(hBWE_TD->tbe_premph_fx, sf ); move16(); } @@ -252,42 +256,45 @@ void find_max_mem_wb( Decoder_State_fx* st_fx, Word16* n_mem ) Word16 max = 0; Word32 Lmax = 0; Word16 n_mem_32; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) - max = s_max( max, abs_s( st_fx->old_bwe_exc_extended_fx[i] ) ); - + FOR(i = 0; i < NL_BUFF_OFFSET; i++) + { + max = s_max(max, abs_s(hBWE_TD->old_bwe_exc_extended_fx[i])); + } FOR( i = 0; i < 7; i++ ) { - if( abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); + if( abs_s(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) + max = abs_s(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); } FOR( i = 0; i < 7; i++ ) { - if( abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ); + if( abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) + max = abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ); } FOR( i = 0; i < 7; i++ ) { - if( abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ); + if( abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) + max = abs_s(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } FOR( i = 0; i < 10; i++ ) { - if( abs_s( st_fx->state_lpc_syn_fx[i] ) > max ) - max = abs_s( st_fx->state_lpc_syn_fx[i] ); + if( abs_s(hBWE_TD->state_lpc_syn_fx[i] ) > max ) + max = abs_s(hBWE_TD->state_lpc_syn_fx[i] ); } FOR( i = 0; i < 5; i++ ) { - if( abs_s( st_fx->state_syn_shbexc_fx[i] ) > max ) - max = abs_s( st_fx->state_syn_shbexc_fx[i] ); + if( abs_s(hBWE_TD->state_syn_shbexc_fx[i] ) > max ) + max = abs_s(hBWE_TD->state_syn_shbexc_fx[i] ); } IF ( max == 0 ) @@ -305,8 +312,8 @@ void find_max_mem_wb( Decoder_State_fx* st_fx, Word16* n_mem ) FOR( i = 0; i < 2; i++ ) { - if( L_abs( st_fx->mem_csfilt_fx[i] ) > Lmax ) - Lmax = L_abs( st_fx->mem_csfilt_fx[i] ); + if( L_abs(hBWE_TD->mem_csfilt_fx[i] ) > Lmax ) + Lmax = L_abs(hBWE_TD->mem_csfilt_fx[i] ); } IF ( Lmax == 0 ) @@ -326,45 +333,48 @@ void find_max_mem_wb( Decoder_State_fx* st_fx, Word16* n_mem ) void rescale_genWB_mem( Decoder_State_fx* st_fx, Word16 sf ) { Word16 i; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - st_fx->old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); + hBWE_TD->old_bwe_exc_extended_fx[i] = shl(hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } FOR( i = 0; i < 10; i++ ) { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); + hBWE_TD->state_lpc_syn_fx[i] = shl(hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } FOR( i = 0; i < 5; i++ ) { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); + hBWE_TD->state_syn_shbexc_fx[i] = shl(hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_wb2_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb2_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i], sf ); move16(); } FOR( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_wb3_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb3_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] = shl(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i], sf ); move16(); } FOR( i = 0; i < 2; i++ ) { - st_fx->mem_csfilt_fx[i] = L_shl( st_fx->mem_csfilt_fx[i], sf ); + hBWE_TD->mem_csfilt_fx[i] = L_shl(hBWE_TD->mem_csfilt_fx[i], sf ); move32(); } } @@ -375,31 +385,29 @@ void InitSWBdecBuffer_fx( Decoder_State_fx* st_fx /* i/o: SHB decoder structure */ ) { - set16_fx( st_fx->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - st_fx->bwe_seed_fx[0] = 23; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); + hBWE_TD->bwe_seed_fx[0] = 23; move16(); - st_fx->bwe_seed_fx[1] = 59; + hBWE_TD->bwe_seed_fx[1] = 59; move16(); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - st_fx->bwe_non_lin_prev_scale_fx = 0; - move16(); - st_fx->last_voice_factor_fx = 0; + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); - set32_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); - set16_fx(st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ + set32_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); + set16_fx(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ - st_fx->syn_dm_phase_fx = 0; + hBWE_TD->syn_dm_phase_fx = 0; move16(); - st_fx->prev_fbbwe_ratio_fx = 32767/*1.0f Q15*/; + hBWE_TD->prev_fbbwe_ratio_fx = 32767/*1.0f Q15*/; /* these are fd-bwe constants */ - st_fx->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ - st_fx->prev_swb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ - st_fx->prev_fb_ener_adjust_fx = 0; - - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ st_fx->prev_Q_bwe_exc = 31; move16(); st_fx->prev_ener_fx_Q = 31; @@ -421,6 +429,8 @@ void ResetSHBbuffer_Dec_fx( Decoder_State_fx* st_fx /* i/o: SHB encoder structur Word16 i; Word16 f; Word16 inc; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; IF( st_fx->extl_fx != WB_TBE ) { @@ -438,29 +448,29 @@ void ResetSHBbuffer_Dec_fx( Decoder_State_fx* st_fx /* i/o: SHB encoder structur } /* states for the filters used in generating SHB excitation from WB excitation*/ - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); + set32_fx(hBWE_TD->mem_csfilt_fx, 0, 2 ); /* states for the filters used in generating SHB signal from SHB excitation*/ - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); IF( EQ_16(st_fx->extl_fx, FB_TBE)) { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; move16(); - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); + fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); } /* states for the filters used in generating SHB signal from SHB excitation in wideband*/ - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->state_lsyn_filt_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx( st_fx->state_lsyn_filt_dwn_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx( st_fx->state_32and48k_WB_upsample_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); + set16_fx(hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); + set16_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); + set16_fx(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); + set16_fx(hBWE_TD->state_lsyn_filt_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); + set16_fx(hBWE_TD->state_lsyn_filt_dwn_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); + set16_fx(hBWE_TD->state_32and48k_WB_upsample_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* States for the local synthesis filters */ - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set16_fx(hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); /* States for FEC */ @@ -468,7 +478,7 @@ void ResetSHBbuffer_Dec_fx( Decoder_State_fx* st_fx /* i/o: SHB encoder structur { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->lsp_prevfrm_fx[i] = f; + hBWE_TD->lsp_prevfrm_fx[i] = f; move16(); /*Q15*/ f = add( f, inc ); move16(); @@ -478,30 +488,30 @@ void ResetSHBbuffer_Dec_fx( Decoder_State_fx* st_fx /* i/o: SHB encoder structur { FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->lsp_prevfrm_fx[i] = f; + hBWE_TD->lsp_prevfrm_fx[i] = f; move16();/*Q15*/ f = add( f, inc ); move16(); } FOR( ; ilsp_prevfrm_fx[i] = 0; + hBWE_TD->lsp_prevfrm_fx[i] = 0; move16(); } } - st_fx->GainFrame_prevfrm_fx = 0; + hBWE_TD->GainFrame_prevfrm_fx = 0; move16();/*Q18*/ - st_fx->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; move16();/*Q15*/ - st_fx->tbe_demph_fx = 0; - st_fx->tbe_premph_fx = 0; - set16_fx(st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER); - st_fx->gain_prec_swb_fx = 16384;/*Q14 =1*/ + hBWE_TD->tbe_demph_fx = 0; + hBWE_TD->tbe_premph_fx = 0; + set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER); + hBWE_TD->gain_prec_swb_fx = 16384;/*Q14 =1*/ set16_fx( &st_fx->GainShape_Delay[0], 0, NUM_SHB_SUBFR / 2 ); - set16_fx(st_fx->old_core_synth_fx, 0, L_FRAME16k); - set16_fx(st_fx->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH); - st_fx->tilt_swb_fec_fx = 0; + set16_fx(hBWE_TD->old_core_synth_fx, 0, L_FRAME16k); + set16_fx(hBWE_TD->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH); + hBWE_TD->tilt_swb_fec_fx = 0; move16(); return; @@ -567,6 +577,8 @@ void wb_tbe_dec_fx( Word16 dummy=0; Word32 dummy2[HILBERT_MEM_SIZE]= {0}; Word16 f, inc; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; IF( st_fx->bws_cnt_fx == 0 ) { @@ -580,15 +592,15 @@ void wb_tbe_dec_fx( { IF(NE_16(st_fx->last_extl_fx, WB_TBE)) { - st_fx->GainFrame_prevfrm_fx = 0; - st_fx->lsp_prevfrm_fx[0] = 3277/*0.1f Q15*/; + hBWE_TD->GainFrame_prevfrm_fx = 0; + hBWE_TD->lsp_prevfrm_fx[0] = 3277/*0.1f Q15*/; move16(); FOR (i=1; ilsp_prevfrm_fx[i] = add(st_fx->lsp_prevfrm_fx[i-i], 3277/*0.1f Q15*/); + hBWE_TD->lsp_prevfrm_fx[i] = add(hBWE_TD->lsp_prevfrm_fx[i-i], 3277/*0.1f Q15*/); } } - Copy( st_fx->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy(hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR/2 ); IF( EQ_16(st_fx->rf_frame_type,RF_NELP)) @@ -598,10 +610,10 @@ void wb_tbe_dec_fx( Copy32( SHBCB_FrameGain16_fx + st_fx->rf_indx_tbeGainFr, &GainFrame, 1 ); IF( EQ_16(st_fx->core_fx,ACELP_CORE)&&EQ_16(st_fx->last_core_fx,ACELP_CORE) && !st_fx->prev_use_partial_copy && EQ_16(st_fx->prev_coder_type_fx,UNVOICED) - && NE_32(GainFrame,st_fx->GainFrame_prevfrm_fx) && EQ_16(st_fx->last_extl_fx, WB_TBE) ) + && NE_32(GainFrame, hBWE_TD->GainFrame_prevfrm_fx) && EQ_16(st_fx->last_extl_fx, WB_TBE) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); + GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); } } ELSE @@ -613,24 +625,24 @@ void wb_tbe_dec_fx( { case 0: GainFrame = 131072; /* 0.5f in Q18 */ - IF(LE_32(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)) temp = 26214/*0.8 Q15*/; + IF(LE_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)) temp = 26214/*0.8 Q15*/; move16(); BREAK; case 1: GainFrame = 524288; /* 2.0f in Q18 */ - IF(GT_32(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)&&LE_32(st_fx->GainFrame_prevfrm_fx,786432l/*3 Q18*/)) temp = 26214/*0.8 Q15*/; + IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,786432l/*3 Q18*/)) temp = 26214/*0.8 Q15*/; move16(); test(); BREAK; case 2: GainFrame = 1048576;/* 4.0f in Q18 */ - IF(GT_32(st_fx->GainFrame_prevfrm_fx, 786432l/*3 Q18*/)&&LE_32(st_fx->GainFrame_prevfrm_fx,1572864l/*6 Q18*/)) temp = 26214/*0.8 Q15*/; + IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 786432l/*3 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,1572864l/*6 Q18*/)) temp = 26214/*0.8 Q15*/; move16(); test(); BREAK; case 3: GainFrame = 2097152;/* 8.0f in Q18 */ - IF(GT_32(st_fx->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/)&&LE_32(st_fx->GainFrame_prevfrm_fx,4194304l/*16 Q18*/)) temp = 26214/*0.8 Q15*/; + IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,4194304l/*16 Q18*/)) temp = 26214/*0.8 Q15*/; move16(); test(); BREAK; @@ -640,7 +652,7 @@ void wb_tbe_dec_fx( IF(EQ_16(st_fx->last_extl_fx, WB_TBE)) { - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); + GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); } IF(EQ_16(st_fx->core_fx,ACELP_CORE)&&EQ_16(st_fx->last_core_fx,ACELP_CORE)) { @@ -662,24 +674,24 @@ void wb_tbe_dec_fx( { IF( EQ_32( st_fx->extl_brate_fx, WB_TBE_0k35)) { - Copy( st_fx->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy(hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); } ELSE { - Copy( st_fx->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); + Copy(hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 27853 ); + hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 27853 ); move16(); IF(EQ_16(st_fx->codec_mode, MODE1)) { - GainFrame = Mult_32_16( st_fx->GainFrame_prevfrm_fx, st_fx->GainAttn_fx ); /*Q18*/ + GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ } ELSE { - GainFrame = st_fx->GainFrame_prevfrm_fx; /*Q18*/ + GainFrame = hBWE_TD->GainFrame_prevfrm_fx; /*Q18*/ } } @@ -759,27 +771,27 @@ void wb_tbe_dec_fx( prev_pow = 0; FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - prev_pow = L_mac0( prev_pow, st_fx->state_syn_shbexc_fx[i], st_fx->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ } rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + Copy(hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - Copy( st_fx->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); + Copy(hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, st_fx->mem_csfilt_fx, - st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->mem_genSHBexc_filt_down_wb2_fx, - st_fx->mem_genSHBexc_filt_down_wb3_fx, st_fx->state_lpc_syn_fx, coder_type, - bwe_exc_extended_16, Q_bwe_exc_ext, st_fx->bwe_seed_fx, vf_modified, uv_flag + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed_fx, vf_modified, uv_flag , st_fx->igf ); @@ -808,12 +820,12 @@ void wb_tbe_dec_fx( shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ /* Update SHB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); /* Adjust the subframe and frame gain of the synthesized shb signal */ /* Scale the shaped excitation */ - ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, st_fx->syn_overlap_fx, GainShape, GainFrame, + ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, Q_bwe_exc_ext , st_fx->L_frame_fx @@ -860,15 +872,15 @@ void wb_tbe_dec_fx( } ELSE { - st_fx->prev_wb_bwe_frame_pow_fx = L_shr( st_fx->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); + hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr(hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); } test(); IF( !st_fx->bfi_fx && st_fx->prev_bfi_fx ) { - IF( GT_32( L_shr( curr_frame_pow, 1 ), st_fx->prev_wb_bwe_frame_pow_fx )) + IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx )) { - L_tmp = root_a_over_b_fx( st_fx->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); + L_tmp = root_a_over_b_fx(hBWE_TD->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); @@ -910,7 +922,7 @@ void wb_tbe_dec_fx( } } - st_fx->prev_wb_bwe_frame_pow_fx = curr_frame_pow; + hBWE_TD->prev_wb_bwe_frame_pow_fx = curr_frame_pow; move32(); st_fx->prev_frame_pow_exp = curr_frame_pow_exp; move16(); @@ -938,28 +950,28 @@ void wb_tbe_dec_fx( move16(); FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - if( abs_s( st_fx->state_lsyn_filt_shb_fx[i] ) > max ) - max = abs_s( st_fx->state_lsyn_filt_shb_fx[i] ); + if( abs_s(hBWE_TD->state_lsyn_filt_shb_fx[i] ) > max ) + max = abs_s(hBWE_TD->state_lsyn_filt_shb_fx[i] ); } FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - if( abs_s( st_fx->state_lsyn_filt_dwn_shb_fx[i] ) > max ) - max = abs_s( st_fx->state_lsyn_filt_dwn_shb_fx[i] ); + if( abs_s(hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ) > max ) + max = abs_s(hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); } IF( EQ_32(st_fx->output_Fs_fx, 32000)) { FOR ( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - max = s_max(max, abs_s( st_fx->state_32and48k_WB_upsample_fx[i] )); + max = s_max(max, abs_s(hBWE_TD->state_32and48k_WB_upsample_fx[i] )); } } IF( EQ_32(st_fx->output_Fs_fx, 48000)) { FOR ( i = 0; i < INTERP_3_1_MEM_LEN; i++ ) { - max = s_max(max, abs_s( st_fx->mem_resamp_HB_fx[i] )); + max = s_max(max, abs_s(hBWE_TD->mem_resamp_HB_fx[i] )); } } n_mem = 15; @@ -980,19 +992,19 @@ void wb_tbe_dec_fx( FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - st_fx->state_lsyn_filt_shb_fx[i] = shl( st_fx->state_lsyn_filt_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_shb_fx[i] = shl(hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); move16(); } FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - st_fx->state_lsyn_filt_dwn_shb_fx[i] = shl( st_fx->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl(hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); move16(); } - GenWBSynth_fx( shaped_wb_excitation, error, st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx ); + GenWBSynth_fx( shaped_wb_excitation, error, hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx ); - Copy( error + L_FRAME16k - L_SHB_TRANSITION_LENGTH, st_fx->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); + Copy( error + L_FRAME16k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); FOR( i = 0; i < L_FRAME16k; i++ ) { @@ -1040,14 +1052,14 @@ void wb_tbe_dec_fx( IF( EQ_32(st_fx->output_Fs_fx, 32000)) /* 32kHz sampling rate, but only WB output - interpolate */ { - Scale_sig(st_fx->state_32and48k_WB_upsample_fx, 2*ALLPASSSECTIONS_STEEP, sub( Qx, st_fx->prev_Qx )); - Interpolate_allpass_steep_fx( synth, st_fx->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); + Scale_sig(hBWE_TD->state_32and48k_WB_upsample_fx, 2*ALLPASSSECTIONS_STEEP, sub( Qx, st_fx->prev_Qx )); + Interpolate_allpass_steep_fx( synth, hBWE_TD->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); Copy( upsampled_synth, synth, L_FRAME32k ); } ELSE IF( EQ_32(st_fx->output_Fs_fx, 48000)) { - Scale_sig(st_fx->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, st_fx->prev_Qx )); - interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, st_fx->mem_resamp_HB_fx, allpass_poles_3_ov_2 ); + Scale_sig(hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, st_fx->prev_Qx )); + interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx); Copy( upsampled_synth, synth, L_FRAME48k ); } } @@ -1067,7 +1079,7 @@ void wb_tbe_dec_fx( GainFrame = 0; /* Q18 */ Qx = 0; Q_bwe_exc = 31; - st_fx->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ st_fx->prev_frame_pow_exp = 0; move16(); } @@ -1075,17 +1087,17 @@ void wb_tbe_dec_fx( /* Update previous frame parameters for FEC */ IF( EQ_32( st_fx->extl_brate_fx, WB_TBE_0k35 ) ) { - Copy( lsf_wb, st_fx->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); } ELSE { - Copy( lsf_wb, st_fx->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); } - st_fx->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ + hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ if( !st_fx->bfi_fx ) { - st_fx->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; move16(); } @@ -1198,6 +1210,9 @@ void swb_tbe_dec_fx( Word32 curr_frame_pow; Word16 curr_frame_pow_exp; Word32 L_prev_ener_shb; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + /* initializations */ GainFrame = L_deposit_l(0); mixFactors = 0; @@ -1218,7 +1233,7 @@ void swb_tbe_dec_fx( test(); IF( st_fx->bfi_fx && NE_16(st_fx->clas_dec,UNVOICED_CLAS)) { - tilt_swb_fec = st_fx->tilt_swb_fec_fx; + tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; move16(); } @@ -1260,13 +1275,13 @@ void swb_tbe_dec_fx( inc_fx = 1489; /*Q15*/ IF(EQ_16(is_fractive, 1)) { - Copy(lsf_tab_fx, st_fx->lsp_prevfrm_fx, LPC_SHB_ORDER); + Copy(lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER); } ELSE { FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; move16(); f_fx = add(f_fx, inc_fx); } @@ -1288,15 +1303,15 @@ void swb_tbe_dec_fx( } ELSE { - if(GT_16(st_fx->prev_GainShape_fx, 11587)) + if(GT_16(hBWE_TD->prev_GainShape_fx, 11587)) { - st_fx->prev_GainShape_fx = 11587; + hBWE_TD->prev_GainShape_fx = 11587; move16(); } - set16_fx( GainShape, st_fx->prev_GainShape_fx, NUM_SHB_SUBFR ); + set16_fx( GainShape, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); } - Copy( st_fx->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + Copy(hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); set16_fx( shb_res_gshape, 3277/*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ } ELSE /* No bandwidth switching */ @@ -1308,7 +1323,7 @@ void swb_tbe_dec_fx( inc_fx = 1489; /*Q15*/ move16(); FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; move16(); f_fx = add(f_fx, inc_fx); } @@ -1320,7 +1335,7 @@ void swb_tbe_dec_fx( { IF(NE_16(st_fx->last_extl_fx, SWB_TBE)) { - st_fx->GainFrame_prevfrm_fx = 0; + hBWE_TD->GainFrame_prevfrm_fx = 0; move16(); move16(); move16(); @@ -1328,12 +1343,12 @@ void swb_tbe_dec_fx( inc_fx = 1489/*0.045454f Q15*/;; /*Q15*/ FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; move16(); f_fx = add(f_fx, inc_fx); } } - Copy( st_fx->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + Copy(hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); IF( EQ_16(st_fx->rf_frame_type,RF_NELP)) @@ -1348,10 +1363,10 @@ void swb_tbe_dec_fx( GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ IF( EQ_16(st_fx->core_fx,ACELP_CORE)&&EQ_16(st_fx->last_core_fx,ACELP_CORE) && !st_fx->prev_use_partial_copy && EQ_16(st_fx->prev_coder_type_fx,UNVOICED) - && NE_32(GainFrame,st_fx->GainFrame_prevfrm_fx) && NE_16(st_fx->next_coder_type,GENERIC) && EQ_16(st_fx->last_extl_fx, SWB_TBE) ) + && NE_32(GainFrame, hBWE_TD->GainFrame_prevfrm_fx) && NE_16(st_fx->next_coder_type,GENERIC) && EQ_16(st_fx->last_extl_fx, SWB_TBE) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); + GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); } } ELSE @@ -1363,24 +1378,24 @@ void swb_tbe_dec_fx( { case 0: GainFrame = 131072; /* 0.5f in Q18 */ - IF(LE_32(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)) temp = 26214/*0.8 Q15*/; + IF(LE_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)) temp = 26214/*0.8 Q15*/; move16(); BREAK; case 1: GainFrame = 524288; /* 2.0f in Q18 */ - IF(GT_32(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)&&LE_32(st_fx->GainFrame_prevfrm_fx,786432l/*3 Q18*/)) temp = 26214/*0.8 Q15*/; + IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,786432l/*3 Q18*/)) temp = 26214/*0.8 Q15*/; move16(); test(); BREAK; case 2: GainFrame = 1048576;/* 4.0f in Q18 */ - IF(GT_32(st_fx->GainFrame_prevfrm_fx, 786432l/*3 Q18*/)&&LE_32(st_fx->GainFrame_prevfrm_fx,1572864l/*6 Q18*/)) temp = 26214/*0.8 Q15*/; + IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 786432l/*3 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,1572864l/*6 Q18*/)) temp = 26214/*0.8 Q15*/; move16(); test(); BREAK; case 3: GainFrame = 2097152;/* 8.0f in Q18 */ - IF(GT_32(st_fx->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/)&&LE_32(st_fx->GainFrame_prevfrm_fx,4194304l/*16Q18*/)) temp = 26214/*0.8 Q15*/; + IF(GT_32(hBWE_TD->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/)&&LE_32(hBWE_TD->GainFrame_prevfrm_fx,4194304l/*16Q18*/)) temp = 26214/*0.8 Q15*/; move16(); test(); BREAK; @@ -1389,7 +1404,7 @@ void swb_tbe_dec_fx( } IF(EQ_16(st_fx->last_extl_fx, SWB_TBE)) { - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); + GainFrame = L_add(Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); } IF(EQ_16(st_fx->core_fx,ACELP_CORE)&&EQ_16(st_fx->last_core_fx,ACELP_CORE)) { @@ -1416,7 +1431,7 @@ void swb_tbe_dec_fx( } ELSE /* FER concealment of TBE parameters */ { - Copy( st_fx->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + Copy(hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); /* Gain shape concealment */ IF( EQ_16(st_fx->codec_mode, MODE1)) @@ -1440,21 +1455,21 @@ void swb_tbe_dec_fx( { IF ( EQ_16(st_fx->nbLostCmpt, 1)) { - GainFrame = Mult_32_16(st_fx->GainFrame_prevfrm_fx, 19661/*0.6f Q15*/); + GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 19661/*0.6f Q15*/); } ELSE IF( EQ_16(st_fx->nbLostCmpt, 2)) { - GainFrame = Mult_32_16(st_fx->GainFrame_prevfrm_fx, 11469/*0.35f Q15*/); + GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 11469/*0.35f Q15*/); } ELSE { - GainFrame = Mult_32_16(st_fx->GainFrame_prevfrm_fx, 6554/*0.2f Q15*/); + GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, 6554/*0.2f Q15*/); } GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping); } ELSE { - GainFrame = st_fx->GainFrame_prevfrm_fx; + GainFrame = hBWE_TD->GainFrame_prevfrm_fx; move16(); /* gain locking */ } } @@ -1466,9 +1481,9 @@ void swb_tbe_dec_fx( IF(EQ_16(st_fx->codec_mode, MODE1)) { /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ - L_tmp = L_mult(extract_l(st_fx->prev2_shb_ener_sf_fx), extract_l(st_fx->prev3_shb_ener_sf_fx)); /*Q1*/ + L_tmp = L_mult(extract_l(hBWE_TD->prev2_shb_ener_sf_fx), extract_l(hBWE_TD->prev3_shb_ener_sf_fx)); /*Q1*/ tmp = round_fx(root_a_fx(L_tmp, 1, &exp)); /* Q = 15-exp */ - tmp1 = extract_l(st_fx->prev1_shb_ener_sf_fx); /*Q0*/ + tmp1 = extract_l(hBWE_TD->prev1_shb_ener_sf_fx); /*Q0*/ i = sub(norm_s(tmp1), 1); tmp1 = shl(tmp1, i); /* Qi */ if(tmp == 0) @@ -1483,14 +1498,14 @@ void swb_tbe_dec_fx( /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ tmp = shl(scale, 15 - exp - i); /*Q15*/ } - scale = mult_r(st_fx->prev_res_shb_gshape_fx, tmp); /* Q14 */ + scale = mult_r(hBWE_TD->prev_res_shb_gshape_fx, tmp); /* Q14 */ test(); - IF( GT_32( L_shr(st_fx->prev2_shb_ener_sf_fx, 1), st_fx->prev1_shb_ener_sf_fx )|| - GT_32( L_shr(st_fx->prev3_shb_ener_sf_fx, 1), st_fx->prev2_shb_ener_sf_fx ) ) + IF( GT_32( L_shr(hBWE_TD->prev2_shb_ener_sf_fx, 1), hBWE_TD->prev1_shb_ener_sf_fx )|| + GT_32( L_shr(hBWE_TD->prev3_shb_ener_sf_fx, 1), hBWE_TD->prev2_shb_ener_sf_fx ) ) { /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = Mult_32_16( st_fx->prev1_shb_ener_sf_fx, scale ); + shb_ener_sf_32 = Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, scale ); if( GT_16(st_fx->nbLostCmpt, 1)) { @@ -1502,27 +1517,27 @@ void swb_tbe_dec_fx( { /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ L_tmp = L_mult(scale, scale); /* Q29 */ - shb_ener_sf_32 = L_shl(Mult_32_16(st_fx->prev1_shb_ener_sf_fx, round_fx(L_tmp)), 2); + shb_ener_sf_32 = L_shl(Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, round_fx(L_tmp)), 2); } } ELSE { test(); - IF( GT_32( L_shr(st_fx->prev2_shb_ener_sf_fx, 1), st_fx->prev1_shb_ener_sf_fx )|| - GT_32( L_shr(st_fx->prev3_shb_ener_sf_fx, 1), st_fx->prev2_shb_ener_sf_fx ) ) + IF( GT_32( L_shr(hBWE_TD->prev2_shb_ener_sf_fx, 1), hBWE_TD->prev1_shb_ener_sf_fx )|| + GT_32( L_shr(hBWE_TD->prev3_shb_ener_sf_fx, 1), hBWE_TD->prev2_shb_ener_sf_fx ) ) { /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = L_shr( Mult_32_16( st_fx->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); + shb_ener_sf_32 = L_shr( Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); } ELSE { - shb_ener_sf_32 = Mult_32_16( st_fx->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); + shb_ener_sf_32 = Mult_32_16(hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); } } } shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l/*1.0f Q0*/ ); - mixFactors = st_fx->prev_mixFactors_fx; + mixFactors = hBWE_TD->prev_mixFactors_fx; IF(EQ_16(st_fx->codec_mode, MODE1)) { @@ -1587,7 +1602,7 @@ void swb_tbe_dec_fx( IF( EQ_16(st_fx->last_extl_fx, SWB_TBE)||EQ_16(st_fx->last_extl_fx,FB_TBE)) { /* SHB LSP values from prev. frame for interpolation */ - Copy(st_fx->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER); + Copy(hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER); } ELSE { @@ -1610,7 +1625,7 @@ void swb_tbe_dec_fx( move16(); } - a2rc_fx (st_fx->cur_sub_Aq_fx+1, refl, M); + a2rc_fx (hBWE_TD->cur_sub_Aq_fx+1, refl, M); tmp = add(16384, shr(refl[0],1)); /*Q14*/ tmp1 = mult(27425,tmp); tmp1 = mult(tmp1,tmp); /*Q10*/ @@ -1622,7 +1637,7 @@ void swb_tbe_dec_fx( { FOR( i=1; iprev_lsf_diff_fx[i-1] = shr(lsf_diff[i], 1); + hBWE_TD->prev_lsf_diff_fx[i-1] = shr(lsf_diff[i], 1); move16(); } } @@ -1634,17 +1649,17 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF(!(GT_16(st_fx->prev_tilt_para_fx,5120)&&(EQ_16(coder_type,TRANSITION)||LT_16(tilt_para,1024)))&& - !(((LT_16(st_fx->prev_tilt_para_fx,3072) && GE_16(st_fx->prev_coder_type_fx,VOICED))) && GT_16(tilt_para,5120) )) + IF(!(GT_16(hBWE_TD->prev_tilt_para_fx,5120)&&(EQ_16(coder_type,TRANSITION)||LT_16(tilt_para,1024)))&& + !(((LT_16(hBWE_TD->prev_tilt_para_fx,3072) && GE_16(st_fx->prev_coder_type_fx,VOICED))) && GT_16(tilt_para,5120) )) { FOR( i = 1; i < LPC_SHB_ORDER-1; i++ ) { - IF(LT_16(lsf_diff[i],st_fx->prev_lsf_diff_fx[i-1])) + IF(LT_16(lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i-1])) { tmp = mult(26214,lsf_diff[i]); test(); - IF( st_fx->prev_lsf_diff_fx[i-1] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ + IF(hBWE_TD->prev_lsf_diff_fx[i-1] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ { st_fx->BER_detect = 1; move16(); @@ -1652,7 +1667,7 @@ void swb_tbe_dec_fx( } ELSE { - tmp = div_s(tmp,st_fx->prev_lsf_diff_fx[i-1]); + tmp = div_s(tmp,hBWE_TD->prev_lsf_diff_fx[i-1]); } tmp = s_max(tmp,16384); @@ -1661,7 +1676,7 @@ void swb_tbe_dec_fx( } ELSE { - tmp = mult(26214,st_fx->prev_lsf_diff_fx[i-1]); + tmp = mult(26214,hBWE_TD->prev_lsf_diff_fx[i-1]); test(); IF( lsf_diff[i] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ @@ -1697,8 +1712,8 @@ void swb_tbe_dec_fx( } } - Copy( lsf_diff + 1, st_fx->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = tilt_para; + Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); + hBWE_TD->prev_tilt_para_fx = tilt_para; } ELSE { @@ -1740,15 +1755,15 @@ void swb_tbe_dec_fx( } /* Save the SWB LSP values from current frame for interpolation */ - Copy(lsp_shb_2, st_fx->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); + Copy(lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); /* lsp_shb_2_fx in Q15 */ /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ - st_fx->prev3_shb_ener_sf_fx = st_fx->prev2_shb_ener_sf_fx; - st_fx->prev2_shb_ener_sf_fx = st_fx->prev1_shb_ener_sf_fx; - st_fx->prev1_shb_ener_sf_fx = shb_ener_sf_32; - st_fx->prev_res_shb_gshape_fx = shb_res_gshape[4]; - st_fx->prev_mixFactors_fx = mixFactors; + hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx; + hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx; + hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32; + hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape[4]; + hBWE_TD->prev_mixFactors_fx = mixFactors; /* SWB CNG/DTX - update memories */ Copy( st_fx->lsp_shb_prev_fx, st_fx->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ @@ -1760,7 +1775,7 @@ void swb_tbe_dec_fx( /* o: vind in Q0 */ /* Determine formant PF strength */ - formant_fac = swb_formant_fac_fx( lpc_shb[1], &st_fx->tilt_mem_fx ); + formant_fac = swb_formant_fac_fx( lpc_shb[1], &hBWE_TD->tilt_mem_fx ); /* o: formant_fac in Q15 */ /* -------- start of memory rescaling -------- */ @@ -1794,17 +1809,17 @@ void swb_tbe_dec_fx( } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + Copy(hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( st_fx->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); + Copy(hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); /* save the previous Q factor (32-bit) of the buffer */ st_fx->prev_Q_bwe_exc = Q_bwe_exc; @@ -1826,11 +1841,11 @@ void swb_tbe_dec_fx( /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the low band ACELP core excitation */ GenShapedSHBExcitation_fx( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, - st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - coder_type, bwe_exc_extended_16, st_fx->bwe_seed_fx, vf_modified, st_fx->extl_fx, - &( st_fx->tbe_demph_fx ), &( st_fx->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, - shb_res_gshape, shb_res_dummy, &vind, formant_fac, st_fx->fb_state_lpc_syn_fx, - &(st_fx->fb_tbe_demph_fx), &Q_bwe_exc, &Q_bwe_exc_fb,Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate_fx, st_fx->prev_bfi_fx ); + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed_fx, vf_modified, st_fx->extl_fx, + &(hBWE_TD->tbe_demph_fx ), &(hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, + shb_res_gshape, shb_res_dummy, &vind, formant_fac, hBWE_TD->fb_state_lpc_syn_fx, + &(hBWE_TD->fb_tbe_demph_fx), &Q_bwe_exc, &Q_bwe_exc_fb,Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate_fx, st_fx->prev_bfi_fx ); *Q_white_exc = Q_bwe_exc_fb; IF( EQ_16(st_fx->extl_fx, FB_TBE)) @@ -1848,15 +1863,15 @@ void swb_tbe_dec_fx( /* rescale the TBE post proc memory */ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->mem_stp_swb_fx[i] = shl(st_fx->mem_stp_swb_fx[i], Q_bwe_exc - st_fx->prev_Q_bwe_syn); + hBWE_TD->mem_stp_swb_fx[i] = shl(hBWE_TD->mem_stp_swb_fx[i], Q_bwe_exc - st_fx->prev_Q_bwe_syn); move16(); } FOR( i = 0; i < L_FRAME16k; i+=L_SUBFR16k ) { /* TD BWE post-processing */ - PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD+i], lpc_shb, &shaped_shb_excitationTemp[i], st_fx->mem_stp_swb_fx, - st_fx->ptr_mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx), st_fx->mem_zero_swb_fx, formant_fac ); + PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD+i], lpc_shb, &shaped_shb_excitationTemp[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx), hBWE_TD->mem_zero_swb_fx, formant_fac ); } Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ @@ -1901,7 +1916,7 @@ void swb_tbe_dec_fx( } /* Update SHB excitation */ - Copy( shaped_shb_excitation + L_FRAME16k, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ + Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ l_subframe_fx = L_FRAME16k/NUM_SHB_SUBGAINS; L_ener = 0; @@ -2081,7 +2096,7 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( NE_16(st_fx->clas_dec, UNVOICED_CLAS)&&NE_16(st_fx->clas_dec,UNVOICED_TRANSITION)&<_16(st_fx->tilt_swb_fec_fx,16384)&& + IF( NE_16(st_fx->clas_dec, UNVOICED_CLAS)&&NE_16(st_fx->clas_dec,UNVOICED_TRANSITION)&<_16(hBWE_TD->tilt_swb_fec_fx,16384)&& ((GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) && LT_32(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx) )|| (GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) && LT_32(L_shr(st_fx->enerLH_fx, 1), st_fx->prev_enerLH_fx)))) { IF(GT_32(L_shr(prev_ener_ratio_fx, 2), GainFrame))/*18*/ @@ -2098,17 +2113,17 @@ void swb_tbe_dec_fx( } test(); - IF(GT_16(tilt_swb_fec, st_fx->tilt_swb_fec_fx)&&st_fx->tilt_swb_fec_fx>0) + IF(GT_16(tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx)&& hBWE_TD->tilt_swb_fec_fx>0) { - exp = norm_s(st_fx->tilt_swb_fec_fx); - tmp = shl(st_fx->tilt_swb_fec_fx, exp);/*Q(11+exp)*/ + exp = norm_s(hBWE_TD->tilt_swb_fec_fx); + tmp = shl(hBWE_TD->tilt_swb_fec_fx, exp);/*Q(11+exp)*/ tmp = div_s(16384, tmp);/*Q(15+14-11-exp)*/ tmp = extract_h(L_shl(L_mult0(tmp, st_fx->tilt_wb_fx),sub(exp,1)));/*18 -exp +11 + exp -1 -16 =12; */ GainFrame = L_shl(Mult_32_16(GainFrame, s_min(tmp, 20480)), 3); /*Q18 = 18 +12 -15 +3 */ } } - ELSE IF( (NE_16(st_fx->clas_dec, UNVOICED_CLAS)||GT_16(st_fx->tilt_swb_fec_fx,16384))&>_32(L_shr(prev_ener_ratio_fx,2),GainFrame)&& + ELSE IF( (NE_16(st_fx->clas_dec, UNVOICED_CLAS)||GT_16(hBWE_TD->tilt_swb_fec_fx,16384))&>_32(L_shr(prev_ener_ratio_fx,2),GainFrame)&& (GT_32(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) || GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) ) ) { GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 6554), Mult_32_16(GainFrame, 26214)); @@ -2127,7 +2142,7 @@ void swb_tbe_dec_fx( IF(GT_32(L_shr(prev_ener_ratio_fx, 2), GainFrame)&&((EQ_16(st_fx->codec_mode,MODE1)&>_32(st_fx->enerLL_fx,st_fx->prev_enerLL_fx)&>_32(st_fx->enerLH_fx,st_fx->prev_enerLH_fx))||EQ_16(st_fx->codec_mode,MODE2))) { test(); - IF( GT_16(tilt_swb_fec, 20480)&>_16(st_fx->tilt_swb_fec_fx,20480)) + IF( GT_16(tilt_swb_fec, 20480)&>_16(hBWE_TD->tilt_swb_fec_fx,20480)) { GainFrame = L_min(L_add(Mult_32_16(prev_ener_ratio_fx, 26214), Mult_32_16(GainFrame, 6554)), L_shl(Mult_32_16(GainFrame, 16384), 3)); /*Q18*/ } @@ -2139,7 +2154,7 @@ void swb_tbe_dec_fx( ELSE IF(GT_32(prev_ener_ratio_fx, GainFrame)&&((EQ_16(st_fx->codec_mode,MODE1)&>_32(st_fx->enerLL_fx,st_fx->prev_enerLL_fx)&>_32(st_fx->enerLH_fx,st_fx->prev_enerLH_fx))||EQ_16(st_fx->codec_mode,MODE2))) { test(); - IF( GT_16(tilt_swb_fec, 20480)&>_16(st_fx->tilt_swb_fec_fx,20480)) + IF( GT_16(tilt_swb_fec, 20480)&>_16(hBWE_TD->tilt_swb_fec_fx,20480)) { GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 16384), Mult_32_16(GainFrame, 16384)); } @@ -2198,7 +2213,7 @@ void swb_tbe_dec_fx( { /* if( ener_tmp_fx[i]*GainShape_tmp_fx[i] > st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ L_tmp1 = Mult_32_16(ener_tmp[i], GainShape_tmp[i]); /* (2*Q_bwe_exc) */ - L_tmp2 = Mult_32_16(st_fx->prev_ener_fx, st_fx->prev_GainShape_fx); /* (2*st_fx->prev_ener_fx_Q) */ + L_tmp2 = Mult_32_16(hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx); /* (2*st_fx->prev_ener_fx_Q) */ tmp = sub(shl(Q_bwe_exc, 1), shl(st_fx->prev_ener_fx_Q, 1)); L_tmp2 = L_shl(L_tmp2, tmp); /* new Q = (2*Q_bwe_exc) */ @@ -2230,8 +2245,8 @@ void swb_tbe_dec_fx( GainShape_tmp[i] = add(tmp,shr(GainShape_tmp[i],1));/* Q15 */ } - st_fx->prev_ener_fx = ener_tmp[i]; - st_fx->prev_GainShape_fx = GainShape_tmp[i]; + hBWE_TD->prev_ener_fx = ener_tmp[i]; + hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; st_fx->prev_ener_fx_Q = Q_bwe_exc; } FOR(i=0; isyn_overlap_fx, + hBWE_TD->syn_overlap_fx, GainShape, /* Q15 */ GainFrame, /* Q18 */ window_shb_fx, @@ -2311,7 +2326,7 @@ void swb_tbe_dec_fx( st_fx->prev_frame_pow_exp = add(curr_frame_pow_exp,32); tmp = 32; } - st_fx->prev_swb_bwe_frame_pow_fx = L_shr(st_fx->prev_swb_bwe_frame_pow_fx, tmp); + hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr(hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp); st_fx->prev_frame_pow_exp = curr_frame_pow_exp; move16(); } @@ -2333,10 +2348,10 @@ void swb_tbe_dec_fx( test(); test(); - IF( ( GT_32( L_shr( curr_frame_pow, 1 ), st_fx->prev_swb_bwe_frame_pow_fx ))&& - ( GT_32( st_fx->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16(st_fx->prev_coder_type_fx,UNVOICED) ) + IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ))&& + ( GT_32(hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16(st_fx->prev_coder_type_fx,UNVOICED) ) { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); @@ -2399,22 +2414,22 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( GT_32(curr_frame_pow, st_fx->prev_swb_bwe_frame_pow_fx)&& + IF( GT_32(curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx)&& NE_16(st_fx->prev_coder_type_fx, UNVOICED) && NE_16(st_fx->last_good_fx,UNVOICED_CLAS) ) { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ + L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ scale = round_fx( L_shl( L_tmp, sub(exp,3))); /*Q12*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); temp = round_fx( L_shl( L_tmp, sub(exp,3))); /*Q12*/ } - ELSE IF( LT_32(curr_frame_pow, L_shr(st_fx->prev_swb_bwe_frame_pow_fx,1))&&EQ_16(st_fx->nbLostCmpt,1)&& + ELSE IF( LT_32(curr_frame_pow, L_shr(hBWE_TD->prev_swb_bwe_frame_pow_fx,1))&&EQ_16(st_fx->nbLostCmpt,1)&& (GT_32(st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx,1)) || GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx,1)) ) && - (EQ_16(st_fx->prev_coder_type_fx ,UNVOICED) || EQ_16(st_fx->last_good_fx, UNVOICED_CLAS) || GT_16(st_fx->tilt_swb_fec_fx , 10240) )) + (EQ_16(st_fx->prev_coder_type_fx ,UNVOICED) || EQ_16(st_fx->last_good_fx, UNVOICED_CLAS) || GT_16(hBWE_TD->tilt_swb_fec_fx , 10240) )) { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); scale = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); @@ -2429,9 +2444,9 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( GT_32(curr_frame_pow , st_fx->prev_swb_bwe_frame_pow_fx)) + IF( GT_32(curr_frame_pow , hBWE_TD->prev_swb_bwe_frame_pow_fx)) { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); scale = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); @@ -2439,11 +2454,11 @@ void swb_tbe_dec_fx( temp = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ } - ELSE IF( LT_32(curr_frame_pow, L_shr(st_fx->prev_swb_bwe_frame_pow_fx,1))&& + ELSE IF( LT_32(curr_frame_pow, L_shr(hBWE_TD->prev_swb_bwe_frame_pow_fx,1))&& (GT_32(st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx,1)) || GT_32(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx,1)) ) && - (st_fx->prev_coder_type_fx == UNVOICED || st_fx->last_good_fx == UNVOICED_CLAS || GT_16(st_fx->tilt_swb_fec_fx , 10240)) ) + (st_fx->prev_coder_type_fx == UNVOICED || st_fx->last_good_fx == UNVOICED_CLAS || GT_16(hBWE_TD->tilt_swb_fec_fx , 10240)) ) { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = root_a_over_b_fx(hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); L_tmp =L_min(L_tmp,L_shl(2,(31 - exp)));/*31 - exp*/ scale = round_fx( L_shl( L_tmp, sub(exp,3) )); /*Q12*/ L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); @@ -2486,7 +2501,7 @@ void swb_tbe_dec_fx( } } - st_fx->prev_swb_bwe_frame_pow_fx = curr_frame_pow; + hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow; move32(); st_fx->prev_frame_pow_exp = curr_frame_pow_exp; move16(); @@ -2542,7 +2557,7 @@ void swb_tbe_dec_fx( { FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) { - st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); move16(); } @@ -2550,27 +2565,27 @@ void swb_tbe_dec_fx( { FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - st_fx->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( st_fx->genSHBsynth_Hilbert_Mem_fx[i], sc ); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); move32(); } } IF( st_fx->output_Fs_fx == 48000 ) { - Scale_sig(st_fx->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc); + Scale_sig(hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc); } IF( st_fx->output_Fs_fx == 16000 ) { - Scale_sig(st_fx->mem_resamp_HB_32k_fx, 2*ALLPASSSECTIONS_STEEP + 1, sc); + Scale_sig(hBWE_TD->mem_resamp_HB_32k_fx, 2*ALLPASSSECTIONS_STEEP + 1, sc); } } /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ /* i/o: st_fx->genSHBsynth_Hilbert_Mem_fx in (Q_bwe_exc) */ /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ /* o: error in (Qx) */ - GenSHBSynth_fx( shaped_shb_excitation, error, st_fx->genSHBsynth_Hilbert_Mem_fx, - st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame_fx, &( st_fx->syn_dm_phase_fx ) ); + GenSHBSynth_fx( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame_fx, &(hBWE_TD->syn_dm_phase_fx ) ); - Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, st_fx->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); + Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); /* resample SHB synthesis (if needed) and scale down */ synth_scale_fx = 32767; @@ -2625,7 +2640,7 @@ void swb_tbe_dec_fx( } } - interpolate_3_over_2_allpass_fx( error, L_FRAME32k, synth, st_fx->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); + interpolate_3_over_2_allpass_fx( error, L_FRAME32k, synth, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); } ELSE IF( EQ_32(st_fx->output_Fs_fx, 32000)) { @@ -2653,20 +2668,20 @@ void swb_tbe_dec_fx( } } - Decimate_allpass_steep_fx( error, st_fx->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); + Decimate_allpass_steep_fx( error, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); } /* Update previous frame parameters for FEC */ - Copy( lsf_shb, st_fx->lsp_prevfrm_fx, LPC_SHB_ORDER ); + Copy( lsf_shb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); IF(EQ_16(st_fx->codec_mode, MODE1)) { - st_fx->GainFrame_prevfrm_fx = GainFrame; + hBWE_TD->GainFrame_prevfrm_fx = GainFrame; move16(); /*Q18*/ - st_fx->tilt_swb_fec_fx = tilt_swb_fec; + hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; if( !st_fx->bfi_fx ) { - st_fx->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; move16(); } } @@ -2674,17 +2689,17 @@ void swb_tbe_dec_fx( { IF( !st_fx->bfi_fx ) { - st_fx->GainFrame_prevfrm_fx = GainFrame; + hBWE_TD->GainFrame_prevfrm_fx = GainFrame; move16(); /*Q18*/ - st_fx->tilt_swb_fec_fx = tilt_swb_fec; + hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; move16(); - st_fx->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; move16(); } } - st_fx->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS-1]; - st_fx->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR-1]; + hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS-1]; + hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR-1]; *Q_synth = Q_bwe_exc; move16(); st_fx->prev_Q_bwe_syn2 = Q_bwe_exc; @@ -2704,6 +2719,8 @@ static void gradientGainShape( Word16 GainGrad0[3]; Word16 GainGrad1[3]; Word16 GainGradFEC[4]; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ FOR( j = 0; j < 3; j++ ) @@ -2818,7 +2835,7 @@ static void gradientGainShape( } } } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 31129 ); } ELSE IF( st_fx->prev_coder_type_fx == UNVOICED || st_fx->last_good_fx == UNVOICED_CLAS ) { @@ -2838,7 +2855,7 @@ static void gradientGainShape( } } } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 31129 ); } ELSE IF( st_fx->nbLostCmpt > 1 ) { @@ -2850,7 +2867,7 @@ static void gradientGainShape( move16(); } } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 16384 ); + hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 16384 ); } ELSE { @@ -2870,10 +2887,10 @@ static void gradientGainShape( } } } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 27852 ); + hBWE_TD->GainAttn_fx = mult_r(hBWE_TD->GainAttn_fx, 27852 ); } - *GainFrame = Mult_32_16( st_fx->GainFrame_prevfrm_fx, st_fx->GainAttn_fx ); /* Q18 */ + *GainFrame = Mult_32_16(hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ } /*-------------------------------------------------------------------* @@ -3023,6 +3040,8 @@ static void dequantizeSHBparams_fx_9_1( Word16 tmp, frac, exp; Word16 idx_shb_fr_gain, idx_res_gs[5], idx_mixFac; Word16 temp_shb_ener_sf_fx; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; /* LSFs */ @@ -3030,8 +3049,8 @@ static void dequantizeSHBparams_fx_9_1( { IF( EQ_32( extl_brate, WB_TBE_0k35 )) { - idxFrameGain = st_fx->gFrame_WB_fx; - idxLSF = st_fx->lsf_WB_fx; + idxFrameGain = hBWE_TD->gFrame_WB_fx; + idxLSF = hBWE_TD->lsf_WB_fx; Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + idxLSF * LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB ); set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -3077,8 +3096,8 @@ static void dequantizeSHBparams_fx_9_1( { IF(EQ_16(st_fx->codec_mode,MODE2)) { - idxSubGain = st_fx->idxSubGains_fx; - idxFrameGain = st_fx->idxFrameGain_fx; + idxSubGain = hBWE_TD->idxSubGains_fx; + idxFrameGain = hBWE_TD->idxFrameGain_fx; } ELSE { @@ -3091,7 +3110,7 @@ static void dequantizeSHBparams_fx_9_1( { IF(EQ_16(st_fx->codec_mode,MODE2)) { - idx_shb_fr_gain = st_fx->idx_shb_fr_gain_fx; + idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain_fx; } ELSE { @@ -3112,7 +3131,7 @@ static void dequantizeSHBparams_fx_9_1( { IF(EQ_16(st_fx->codec_mode,MODE2)) { - idx_res_gs[i] = st_fx->idx_res_gs_fx[i]; + idx_res_gs[i] = hBWE_TD->idx_res_gs_fx[i]; move16(); } ELSE @@ -3130,7 +3149,7 @@ static void dequantizeSHBparams_fx_9_1( IF(EQ_16(st_fx->codec_mode,MODE2)) { - idx_mixFac = st_fx->idx_mixFac_fx; + idx_mixFac = hBWE_TD->idx_mixFac_fx; move16(); } ELSE @@ -3170,7 +3189,7 @@ static void dequantizeSHBparams_fx_9_1( { FOR (i = 0; i < NUM_Q_LSF; i++) { - lsf_idx[i] = st_fx->lsf_idx_fx[i]; + lsf_idx[i] = hBWE_TD->lsf_idx_fx[i]; move16(); } @@ -3188,7 +3207,7 @@ static void dequantizeSHBparams_fx_9_1( IF(EQ_16(st_fx->codec_mode,MODE2)) { - m_idx = st_fx->m_idx_fx; + m_idx = hBWE_TD->m_idx_fx; } ELSE { @@ -3207,7 +3226,7 @@ static void dequantizeSHBparams_fx_9_1( IF(EQ_16(st_fx->codec_mode,MODE2)) { - grid_idx = st_fx->grid_idx_fx; + grid_idx = hBWE_TD->grid_idx_fx; } ELSE { @@ -3232,7 +3251,7 @@ static void dequantizeSHBparams_fx_9_1( ELSE { set16_fx(lsf_idx, 0, 5); - Copy(st_fx->lsf_idx_fx, lsf_idx, 5); + Copy(hBWE_TD->lsf_idx_fx, lsf_idx, 5); grid_idx = 0; m_idx = 0; Copy(swb_tbe_lsfvq_cbook_8b + lsf_idx[0]*LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER); @@ -3292,6 +3311,8 @@ void fb_tbe_dec_fx( Word16 ratio = 0; Word32 fb_exc_energy = 0; Word16 fb_synth[L_FRAME48k]; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st->hBWE_TD; /* decode FB slope information */ test(); @@ -3300,7 +3321,7 @@ void fb_tbe_dec_fx( { IF( EQ_16(st->codec_mode,MODE2)) { - i = st->idxGain_fx; + i = hBWE_TD->idxGain_fx; move16(); } ELSE @@ -3311,13 +3332,13 @@ void fb_tbe_dec_fx( } ELSE if ( EQ_16(st->extl_fx,FB_TBE)&&st->bfi_fx) { - ratio = st->prev_fbbwe_ratio_fx; + ratio = hBWE_TD->prev_fbbwe_ratio_fx; move16(); } fb_exc_energy = sum2_fx_mod(fb_exc,L_FRAME16k); /* FB TBE synthesis */ - synthesise_fb_high_band_fx( fb_exc,Q_fb_exc,fb_synth,fb_exc_energy,ratio, st->L_frame_fx, st->bfi_fx, &(st->prev_fbbwe_ratio_fx), st->fbbwe_hpf_mem_fx, st->fbbwe_hpf_mem_fx_Q,hb_synth_exp); + synthesise_fb_high_band_fx( fb_exc,Q_fb_exc,fb_synth,fb_exc_energy,ratio, st->L_frame_fx, st->bfi_fx, &(hBWE_TD->prev_fbbwe_ratio_fx), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,hb_synth_exp); /* add the fb_synth component to the hb_synth component */ /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ @@ -3334,6 +3355,8 @@ void tbe_read_bitstream_fx( ) { Word16 i; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; test(); test(); @@ -3343,10 +3366,10 @@ void tbe_read_bitstream_fx( IF ( (EQ_16(st_fx->rf_flag,1)||EQ_32(st_fx->total_brate_fx,ACELP_9k60))&&EQ_16(st_fx->bwidth_fx,WB)) { /* WB LSF */ - st_fx->lsf_WB_fx = get_next_indice_fx(st_fx, NUM_BITS_LBR_WB_LSF); + hBWE_TD->lsf_WB_fx = get_next_indice_fx(st_fx, NUM_BITS_LBR_WB_LSF); /* WB frame gain */ - st_fx->gFrame_WB_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_FrameGain_LBR_WB); + hBWE_TD->gFrame_WB_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_FrameGain_LBR_WB); } ELSE IF ( ( GE_32( st_fx->total_brate_fx, ACELP_9k60 ))&&(LE_32(st_fx->total_brate_fx,ACELP_32k))&& ( ( EQ_16( st_fx->bwidth_fx, SWB ) ) || ( EQ_16( st_fx->bwidth_fx, FB ) ) ) ) @@ -3356,45 +3379,45 @@ void tbe_read_bitstream_fx( { FOR (i = 0; i < NUM_Q_LSF; i++) { - st_fx->lsf_idx_fx[i] = get_next_indice_fx(st_fx, lsf_q_num_bits[i]); + hBWE_TD->lsf_idx_fx[i] = get_next_indice_fx(st_fx, lsf_q_num_bits[i]); move16(); } - st_fx->m_idx_fx = get_next_indice_fx(st_fx, MIRROR_POINT_BITS); + hBWE_TD->m_idx_fx = get_next_indice_fx(st_fx, MIRROR_POINT_BITS); - st_fx->grid_idx_fx = get_next_indice_fx(st_fx, NUM_LSF_GRID_BITS); + hBWE_TD->grid_idx_fx = get_next_indice_fx(st_fx, NUM_LSF_GRID_BITS); } ELSE { - st_fx->lsf_idx_fx[0] = get_next_indice_fx(st_fx, 8); + hBWE_TD->lsf_idx_fx[0] = get_next_indice_fx(st_fx, 8); move16(); - st_fx->m_idx_fx = 0; + hBWE_TD->m_idx_fx = 0; move16(); - st_fx->grid_idx_fx = 0; + hBWE_TD->grid_idx_fx = 0; move16(); } /* shape gains */ - st_fx->idxSubGains_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_SUBGAINS); + hBWE_TD->idxSubGains_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_SUBGAINS); /* frame gain */ - st_fx->idxFrameGain_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_FRAMEGAIN); + hBWE_TD->idxFrameGain_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_FRAMEGAIN); IF ( GE_32( st_fx->total_brate_fx, ACELP_24k40 )) { /* sub frame energy*/ - st_fx->idx_shb_fr_gain_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_ENER_SF); + hBWE_TD->idx_shb_fr_gain_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_ENER_SF); /* gain shapes residual */ FOR (i = 0; i < NB_SUBFR16k; i++) { - st_fx->idx_res_gs_fx[i] = get_next_indice_fx(st_fx, NUM_BITS_SHB_RES_GS); + hBWE_TD->idx_res_gs_fx[i] = get_next_indice_fx(st_fx, NUM_BITS_SHB_RES_GS); move16(); } /* voicing factor */ - st_fx->idx_mixFac_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_VF); + hBWE_TD->idx_mixFac_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_VF); } IF (EQ_16(st_fx->tec_tfa, 1)) @@ -3421,7 +3444,7 @@ void tbe_read_bitstream_fx( IF ( EQ_16( st_fx->bwidth_fx, FB )) { - st_fx->idxGain_fx = get_next_indice_fx(st_fx, 4); + hBWE_TD->idxGain_fx = get_next_indice_fx(st_fx, 4); } } @@ -3562,7 +3585,7 @@ void GenTransition_WB_fx( } ELSE IF( EQ_32(output_Fs, 48000)) { - interpolate_3_over_1_allpass_fx( output, L_FRAME16k, upsampled_synth, up_mem, allpass_poles_3_ov_2 ); + interpolate_3_over_1_allpass_fx( output, L_FRAME16k, upsampled_synth, up_mem ); Copy( upsampled_synth, output, L_FRAME48k ); } @@ -3579,10 +3602,13 @@ void TBEreset_dec_fx( Word16 bandwidth /* i : bandwidth mode */ ) { + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + IF( NE_16(st_fx->last_core_fx,ACELP_CORE)) { - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); st_fx->prev_Q_bwe_exc = 31; move16(); } @@ -3590,35 +3616,112 @@ void TBEreset_dec_fx( test(); IF( EQ_16(bandwidth, WB)) { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->state_32and48k_WB_upsample_fx, st_fx->mem_resamp_HB_fx ); + wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_synth_fx(hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); - set16_fx( st_fx->state_lpc_syn_fx, 0, 10 ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); + set16_fx(hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); + set16_fx(hBWE_TD->state_lpc_syn_fx, 0, 10 ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); + set16_fx(hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx(hBWE_TD->mem_csfilt_fx, 0, 2 ); } ELSE IF( EQ_16(bandwidth, SWB)||EQ_16(bandwidth,FB)) { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), - &(st_fx->tbe_premph_fx), st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); + swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), + &(hBWE_TD->tbe_premph_fx), hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - set16_fx( st_fx->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); - set16_fx( st_fx->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); + set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); IF( EQ_16(bandwidth, FB)) { st_fx->prev_fb_ener_adjust_fx = 0; - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); } } return; } + + +/*-------------------------------------------------------------------* + * td_bwe_dec_init() + * + * Initialize TD BWE state structure at the decoder + *-------------------------------------------------------------------*/ + +void td_bwe_dec_init_fx( + Decoder_State_fx* st_fx, /* i/o: SHB decoder structure */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ +#ifdef ADD_IVAS_BWE + const Word16 extl, /* i : BWE extension layer */ +#endif + const Word32 output_Fs /* i : output sampling rate */ +) +{ + int16_t i; + + /* init. SHB buffers */; + InitSWBdecBuffer_fx(st_fx); + + /* reset SHB buffers */ + ResetSHBbuffer_Dec_fx(st_fx); + IF(EQ_32(output_Fs, 48000)) + { + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[0], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[1], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[2], 0, 4); + set32_fx(hBWE_TD->fbbwe_hpf_mem_fx[3], 0, 4); + set16_fx(hBWE_TD->fbbwe_hpf_mem_fx_Q, 0, 4); + } + + set16_fx(hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN); + set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + + hBWE_TD->tilt_mem_fx = 0; + move16(); + set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + hBWE_TD->prev_tilt_para_fx = 0; + move16(); + set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); + set16_fx(hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); + + /* TD BWE post-processing */ + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; + set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER); + + FOR(i = 0; i < LPC_SHB_ORDER; i++) + { + hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + move16(); + } + + hBWE_TD->prev1_shb_ener_sf_fx = 32767; /* Q15*/ move16(); + hBWE_TD->prev2_shb_ener_sf_fx = 32767; /* Q15*/ move16(); + hBWE_TD->prev3_shb_ener_sf_fx = 32767; /* Q15*/ move16(); + hBWE_TD->prev_res_shb_gshape_fx = 8192; /* 0.125 in Q14*/ move16(); + hBWE_TD->prev_mixFactors_fx = 16384; /* 0.5 in Q15*/ move16(); + hBWE_TD->prev_GainShape_fx = 0; + move16(); + st_fx->prev_Q_bwe_exc_fb = 51; + move16(); + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); + + + + set16_fx(hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k); + + + hBWE_TD->prev_ener_fx = L_deposit_l(0); + + + return; +} diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index c26b00e..36fc68d 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Debug prototypes */ -#include "stl.h" /* required for wmc_tool */ /*-------------------------------------------------------------------* * syn_output() @@ -32,7 +32,7 @@ void syn_output_fx( *-----------------------------------------------------------------*/ test(); - IF( codec_mode == MODE2 || EQ_16(output_frame,L_FRAME8k)) + IF( EQ_16(codec_mode, MODE2) || EQ_16(output_frame,L_FRAME8k)) { /* integer conversion */ /*mvr2s( synth, synth_out, output_frame ); */ @@ -63,26 +63,26 @@ void unscale_AGC( const Word16 n /* i: vector size */ ) { - Word16 i, fac, tmp, frame_fac, max; + Word16 i, fac, tmp, frame_fac, max_val; Word32 L_tmp; /*----------------------------------------------------------------* * calculate AGC factor to avoid saturation *----------------------------------------------------------------*/ - max = abs_s(x[0]); + max_val = abs_s(x[0]); FOR (i = 1; i < n; i++) { - max = s_max(max, abs_s(x[i])); + max_val = s_max(max_val, abs_s(x[i])); } BASOP_SATURATE_WARNING_OFF tmp = shl(30000, Qx); /* saturation can occurs here */ BASOP_SATURATE_WARNING_ON frame_fac = 0; move16(); - IF (GT_16(max, tmp)) + IF (GT_16(max_val, tmp)) { - frame_fac = sub(16384, div_s(shr(tmp, 1), max)); /* frame fac in Q15 */ + frame_fac = sub(16384, div_s(shr(tmp, 1), max_val)); /* frame fac in Q15 */ } /*----------------------------------------------------------------* diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 68f4dbb..0c17939 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -1,14 +1,17 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ - +#include "options.h" /* Compilation switches */ +#include "cnst_fx.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ +/*---------------------------------------------------------------------* + * tcq_core_LR_dec() + * + * Main Generic Audio Decoder Routine for LR-MDCT + *---------------------------------------------------------------------*/ void tcq_core_LR_dec_fx( Decoder_State_fx *st_fx, diff --git a/lib_dec/tcx_utils_dec.c b/lib_dec/tcx_utils_dec.c index 91cc01d..8dc8a7b 100644 --- a/lib_dec/tcx_utils_dec.c +++ b/lib_dec/tcx_utils_dec.c @@ -3,32 +3,36 @@ ====================================================================================*/ +#include #include #include #include -#include "stl.h" #include "options.h" #include "prot_fx.h" #include "rom_basop_util.h" #include "basop_util.h" #include "rom_com_fx.h" +/*--------------------------------------------------------------- + * tcx_decoder_memory_update() + * + * + *--------------------------------------------------------------*/ void tcx_decoder_memory_update( Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ Word16 *synthout, /* o: synth */ - Word16 L_frame_glob, /* i: global frame length */ Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State_fx *st, - Word16 *syn, /* o: st->syn */ + Decoder_State_fx *st, /* i/o: decoder memory state */ Word8 fb /* i: fullband flag */ ) { Word16 tmp; Word16 *synth; Word16 buf[1+M+LFAC+L_FRAME_PLUS]; + Word16 L_frame_glob; Word16 preemph; - + L_frame_glob = st->L_frame_fx; preemph = st->preemph_fac; move16(); @@ -38,42 +42,43 @@ void tcx_decoder_memory_update( /* Update synth */ synth = buf + M+1; - Copy(syn, buf, M+1); + Copy(st->syn, buf, M+1); Copy(xn_buf, synth, L_frame_glob); - Copy(synth + sub(L_frame_glob, M+1), syn, M+1); - + Copy(synth + sub(L_frame_glob, M+1), st->syn, M+1); - IF (!fb) + IF (NE_16(st->element_mode, IVAS_CPE_MDCT)) { + IF(!fb) /* TV2FhG -> Condition differs from floating point */ + { - /* Emphasis of synth -> synth_pe */ - tmp = synth[-M-1]; - move16(); - st->Q_syn = E_UTIL_f_preemph3(synth - M, preemph, add(M, L_frame_glob), &tmp, 1); - st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; - Copy(synth + sub(L_frame_glob, M), st->mem_syn2_fx, M); - Copy(synth + sub(L_frame_glob, L_SYN_MEM), st->mem_syn_r, L_SYN_MEM); + /* Emphasis of synth -> synth_pe */ + tmp = synth[-M - 1]; + move16(); + st->Q_syn = E_UTIL_f_preemph3(synth - M, preemph, add(M, L_frame_glob), &tmp, 1); + st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; + Copy(synth + sub(L_frame_glob, M), st->mem_syn2_fx, M); + Copy(synth + sub(L_frame_glob, L_SYN_MEM), st->mem_syn_r, L_SYN_MEM); - test(); - IF ( st->tcxonly == 0 || LE_16(L_frame_glob,L_FRAME16k)) - { - /* Update excitation */ - IF(NE_16(st->Q_syn+1,st->Q_exc)) + test(); + IF(st->tcxonly == 0 || LE_16(L_frame_glob, L_FRAME16k)) { - Scale_sig(st->old_exc_fx, L_EXC_MEM_DEC, sub(st->Q_syn+1,st->Q_exc)); - } - st->Q_exc = st->Q_syn + 1; - st->Q_subfr[0] = st->Q_subfr[1] = st->Q_subfr[2] = st->Q_subfr[3] = st->Q_subfr[4] = st->Q_exc; + /* Update excitation */ + IF(NE_16(st->Q_syn + 1, st->Q_exc)) + { + Scale_sig(st->old_exc_fx, L_EXC_MEM_DEC, sub(st->Q_syn + 1, st->Q_exc)); + } + st->Q_exc = st->Q_syn + 1; + st->Q_subfr[0] = st->Q_subfr[1] = st->Q_subfr[2] = st->Q_subfr[3] = st->Q_subfr[4] = st->Q_exc; - assert(L_frame_glob< L_EXC_MEM_DEC); - Copy( st->old_exc_fx + L_frame_glob, st->old_exc_fx, sub(L_EXC_MEM_DEC, L_frame_glob) ); - Residu3_fx(A, synth, st->old_exc_fx + sub(L_EXC_MEM_DEC, L_frame_glob), L_frame_glob, 1); + assert(L_frame_glob < L_EXC_MEM_DEC); + Copy(st->old_exc_fx + L_frame_glob, st->old_exc_fx, sub(L_EXC_MEM_DEC, L_frame_glob)); + Residu3_fx(A, synth, st->old_exc_fx + sub(L_EXC_MEM_DEC, L_frame_glob), L_frame_glob, 1); + } + /* Update old_Aq */ + Copy(A, st->old_Aq_12_8_fx, M + 1); } - - /* Update old_Aq */ - Copy(A, st->old_Aq_12_8_fx, M+1); } - + return; } /* Returns: number of bits used (including "bits") */ @@ -81,7 +86,7 @@ Word16 tcx_ari_res_invQ_spec( Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bit-stream Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ Word16 target_bits, /* i: number of bits available Q0 */ Word16 bits, /* i: number of bits used so far Q0 */ Word16 deadzone, /* i: quantizer deadzone Q15 */ @@ -159,7 +164,11 @@ Word16 tcx_ari_res_invQ_spec( return bits; } - +/*--------------------------------------------------------------- + * tcx_res_invQ_gain() + * + * + *--------------------------------------------------------------*/ Word16 tcx_res_invQ_gain( Word16 *gain_tcx, Word16 *gain_tcx_e, @@ -205,6 +214,11 @@ Word16 tcx_res_invQ_gain( return bits; } +/*--------------------------------------------------------------- + * tcx_res_invQ_spec() + * + * + *--------------------------------------------------------------*/ Word16 tcx_res_invQ_spec( Word32 *x, Word16 x_e, diff --git a/lib_dec/tns_base_dec.c b/lib_dec/tns_base_dec.c index 96ae4c0..c7e47c3 100644 --- a/lib_dec/tns_base_dec.c +++ b/lib_dec/tns_base_dec.c @@ -3,11 +3,10 @@ ====================================================================================*/ -#include "stl.h" +#include +#include "options.h" #include "prot_fx.h" -#include "stl.h" #include -#include #include "rom_com_fx.h" /** Linear prediction analysis/synthesis filter definition. @@ -22,8 +21,24 @@ typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[] /********************************/ /* Interface functions */ /********************************/ - -Word16 ReadTnsData(STnsConfig const * pTnsConfig, Decoder_State_fx *st, Word16 * pnBits, Word16 * stream, Word16 * pnSize) +/*---------------------------------------------------------------------* + * ReadTnsData() + * + * + *---------------------------------------------------------------------*/ + +#ifdef IVAS_CODE +void +#else +Word16 +#endif + ReadTnsData( + STnsConfig const * pTnsConfig, + Decoder_State_fx *st, + Word16 * pnBits, + Word16 * stream, + Word16 * pnSize +) { Word16 start_bit_pos; @@ -33,14 +48,30 @@ Word16 ReadTnsData(STnsConfig const * pTnsConfig, Decoder_State_fx *st, Word16 * IF ( GT_16(pTnsConfig->nMaxFilters, 1)) { - - IF ( LT_16(pTnsConfig->iFilterBorders[0],512)) +#ifdef IVAS_CODE + IF(pTnsConfig->allowTnsOnWhite) { - ReadFromBitstream(tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize); + IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + { + ReadFromBitstream(&tnsEnabledOnWhiteSWBTCX10BitMap, 1, st, &stream, pnSize); + } + ELSE + { + ReadFromBitstream(&tnsEnabledOnWhiteSWBTCX20BitMap, 1, st, &stream, pnSize); + } } ELSE +#endif { - ReadFromBitstream(tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize); + + IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + { + ReadFromBitstream(tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize); + } + ELSE + { + ReadFromBitstream(tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize); + } } } ELSE @@ -52,10 +83,24 @@ Word16 ReadTnsData(STnsConfig const * pTnsConfig, Decoder_State_fx *st, Word16 * *pnBits = sub(st->next_bit_pos_fx, start_bit_pos); +#ifdef IVAS_CODE + return; +#else return TNS_NO_ERROR; +#endif } - -Word16 DecodeTnsData(STnsConfig const * pTnsConfig, Word16 const * stream, Word16 * pnSize, STnsData * pTnsData) +/*---------------------------------------------------------------------* +* DecodeTnsData() +* +* +*---------------------------------------------------------------------*/ + +Word16 DecodeTnsData( + STnsConfig const * pTnsConfig, + Word16 const * stream, + Word16 * pnSize, + STnsData * pTnsData +) { Word16 result; @@ -66,13 +111,29 @@ Word16 DecodeTnsData(STnsConfig const * pTnsConfig, Word16 const * stream, Word1 IF ( GT_16(pTnsConfig->nMaxFilters, 1)) { - IF ( LT_16(pTnsConfig->iFilterBorders[0],512)) +#ifdef IVAS_CODE + IF (pTnsConfig->allowTnsOnWhite) { - SetParameters(tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize); + IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + { + SetParameters(&tnsEnabledOnWhiteSWBTCX10BitMap, 1, pTnsData, &stream, pnSize); + } + ELSE + { + SetParameters(&tnsEnabledOnWhiteSWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + } } ELSE +#endif { - SetParameters(tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + IF(LT_16(pTnsConfig->iFilterBorders[0], 512)) + { + SetParameters(tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize); + } + ELSE + { + SetParameters(tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + } } } ELSE diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 54454d4..63032c8 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -5,7 +5,8 @@ #define _USE_MATH_DEFINES #include -#include "stl.h" +#include +#include "options.h" #include "basop_util.h" #include "options.h" #include "typedef.h" @@ -14,138 +15,129 @@ #include "stat_com.h" -/************************************************************************************/ -/* forward declarations for local functions, see implementation at end of this file */ -/************************************************************************************/ - -static void CalcMDXT(TonalMDCTConcealPtr const self, - Word16 const type, - Word16 const * const timeSignal, - Word32 * const mdxtOutput, - Word16 * const mdxtOutput_e); - -static void CalcPowerSpec(Word32 * mdctSpec, /* i: MDCT spectrum */ - Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - Word32 * mdstSpec, /* i: MDST spectrum */ - Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ - Word16 nSamples, /* i: frame size */ - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word32 * powerSpec, /* o: power spectrum */ - Word16 * powerSpec_exp); - -static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self, - Word32 secondLastMDST[], - Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], - Word16 secondLastMDCT_exp, - Word32 const pitchLag); -static void FindPhases( /* o: current phase [-pi;pi] 2Q13 */ - TonalMDCTConcealPtr const self, /* i: pointer to internal structure */ - Word32 secondLastMDCT[], /* i: MDST spectrum data */ - Word32 secondLastMDST[], /* i: MDCT spectrum data */ - Word16 diff_exp); /* i: exp_MDST - exp_MDCT */ +/************************************************************************************ + * local functions + ************************************************************************************/ -static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ - TonalMDCTConcealPtr const self, /* i: Pointer to internal structure */ - Word32 powerSpectrum[]); /* i: Power spectrum data */ +static void CalcMDXT(const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, const Word16 * timeSignal, Word32 * mdxtOutput, Word16 * mdxtOutput_e); +static void CalcPowerSpec(const Word32 * mdctSpec, const Word16 mdctSpec_exp, const Word32 * mdstSpec, const Word16 mdstSpec_exp, const Word16 nSamples, const Word16 floorPowerSpectrum, Word32 * powerSpec, Word16 * powerSpec_exp); +static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], Word16 secondLastMDST_exp, Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag); +static void FindPhases(TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDCT[], Word32 secondLastMDST[], Word16 diff_exp); +static void FindPhaseDifferences(TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[]); /*******************************************************/ /*-------------- public functions -------------------- */ /*******************************************************/ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Init( TonalMDCTConcealPtr self, - Word16 nSamples, - Word16 nSamplesCore, - Word16 nScaleFactors, - TCX_config * tcx_cfg - ) +ivas_error TonalMDCTConceal_Init( + TonalMDCTConcealPtr hTonalMDCTConc, + const Word16 nSamples, + const Word16 nSamplesCore, + const Word16 nScaleFactors, + TCX_CONFIG_HANDLE hTcxCfg /* TCX config */ +) { test(); IF (GT_16(nSamples,L_FRAME_MAX)||GT_16(nScaleFactors,FDNS_NPTS)) { assert(nSamples <= L_FRAME_MAX); assert(nScaleFactors <= FDNS_NPTS); - return TONALMDCTCONCEAL_NSAMPLES_LARGER_THAN_MAXBLOCKSIZE; + return (IVAS_ERROR(IVAS_ERR_INTERNAL, "TonalMDCT FEC: Number of samples larger than max. block size\n")); } - assert((self->nScaleFactors == nScaleFactors) || (self->nSamples != nSamples)); /* If nSamples doesn't change then also nScaleFactors must stay the same */ + assert((hTonalMDCTConc->nScaleFactors == nScaleFactors) || (hTonalMDCTConc->nSamples != nSamples)); /* If nSamples doesn't change then also nScaleFactors must stay the same */ - self->tcx_cfg = tcx_cfg; + hTonalMDCTConc->tcx_cfg = hTcxCfg; - self->lastBlockData.spectralData = self->spectralDataBuffers[0]; + hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; move16(); - self->secondLastBlockData.spectralData = self->spectralDataBuffers[1]; + hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1]; move16(); - self->secondLastPowerSpectrum = self->secondLastBlockData.spectralData; + hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; move16(); - self->lastBlockData.scaleFactors = self->scaleFactorsBuffers[0]; + hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; move16(); - self->secondLastBlockData.scaleFactors = self->scaleFactorsBuffers[1]; + hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1]; move16(); - self->lastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[0]; + hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; move16(); - self->secondLastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[1]; + hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[1]; move16(); - self->lastBlockData.blockIsValid = 0; + hTonalMDCTConc->lastBlockData.blockIsValid = 0; move16(); - self->secondLastBlockData.blockIsValid = 0; + hTonalMDCTConc->secondLastBlockData.blockIsValid = 0; move16(); - self->nSamples = 0; + hTonalMDCTConc->nSamples = 0; move16(); - self->nScaleFactors = 0; + hTonalMDCTConc->nScaleFactors = 0; move16(); - self->lastBlockData.blockIsConcealed = 0; + hTonalMDCTConc->lastBlockData.blockIsConcealed = 0; move16(); - self->secondLastBlockData.blockIsConcealed = 0; + hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0; move16(); - self->pTCI = (TonalComponentsInfo *)self->timeDataBuffer; + hTonalMDCTConc->pTCI = (TonalComponentsInfo *)hTonalMDCTConc->timeDataBuffer; move16(); - self->lastPitchLag = L_deposit_l(0); + hTonalMDCTConc->lastPitchLag = L_deposit_l(0); - IF (NE_16(self->nSamples,nSamples)) + IF (NE_16(hTonalMDCTConc->nSamples,nSamples)) { - self->secondLastBlockData.blockIsValid = 0; + hTonalMDCTConc->secondLastBlockData.blockIsValid = 0; move16(); - self->lastBlockData.blockIsValid = 0; + hTonalMDCTConc->lastBlockData.blockIsValid = 0; move16(); } - self->nSamples = nSamples; + hTonalMDCTConc->nSamples = nSamples; move16(); - self->nSamplesCore = nSamplesCore; + hTonalMDCTConc->nSamplesCore = nSamplesCore; move16(); - self->nScaleFactors = nScaleFactors; + hTonalMDCTConc->nScaleFactors = nScaleFactors; move16(); - +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + PMTE() + set_zero(hTonalMDCTConc->scaleFactorsBackground, FDNS_NPTS); + PsychoacousticParameters_Init(INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20); + PsychoacousticParameters_Init(INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10); + hTonalMDCTConc->psychParams = NULL; + hTonalMDCTConc->scf_fadeout = 1.0f; + hTonalMDCTConc->last_block_nrg = 0.0f; + hTonalMDCTConc->curr_noise_nrg = 0.0f; + hTonalMDCTConc->faded_signal_nrg = 0.0f; + +#endif /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when new time samples are stored in lastPcmOut */ move16(); move16(); /* just the second half of the second last pcm output is needed */ - self->secondLastPcmOut = &self->timeDataBuffer[sub((3*L_FRAME_MAX)/2,3*(s_min(L_FRAME_MAX, nSamples))/2)]; - self->lastPcmOut = &self->timeDataBuffer[sub((3*L_FRAME_MAX)/2, s_min(L_FRAME_MAX, nSamples)) ]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub((3*L_FRAME_MAX)/2,3*(s_min(L_FRAME_MAX, nSamples))/2)]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub((3*L_FRAME_MAX)/2, s_min(L_FRAME_MAX, nSamples)) ]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ - assert(sizeof(*self->pTCI) <= (self->lastPcmOut-self->timeDataBuffer)*sizeof(self->timeDataBuffer[0])); + assert(sizeof(*hTonalMDCTConc->pTCI) <= (hTonalMDCTConc->lastPcmOut-hTonalMDCTConc->timeDataBuffer)*sizeof(hTonalMDCTConc->timeDataBuffer[0])); - return TONALMDCTCONCEAL_OK; + return IVAS_ERR_OK; } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr self, - Word32 const *mdctSpectrum, - Word16 const mdctSpectrum_exp, - Word16 nNewSamples, - Word16 nNewSamplesCore, - Word16 const *scaleFactors, - Word16 const *scaleFactors_exp, - Word16 const gain_tcx_exp - ) +void TonalMDCTConceal_SaveFreqSignal( + TonalMDCTConcealPtr hTonalMDCTConc, + const Word32 *mdctSpectrum, + const Word16 mdctSpectrum_exp, + Word16 nNewSamples, + Word16 nNewSamplesCore, + const Word16 *scaleFactors, + const Word16 *scaleFactors_exp, + const Word16 gain_tcx_exp +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + ,const int16_t infoIGFStartLine +#endif +) { Word16 * temp; Word16 nOldSamples, tmp_exp, s, i, max_exp; @@ -153,116 +145,131 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr self assert(nNewSamples > 0 && nNewSamples <= 2*L_FRAME_MAX); - /* Avoid overwriting self->secondLastPowerSpectrum stored in spectralData, + /* Avoid overwriting hTonalMDCTConc->secondLastPowerSpectrum stored in spectralData, because it is needed if the second last and the current frame are lost and concealed using the Tonal MDCT PLC */ test(); - IF (!self->lastBlockData.tonalConcealmentActive || NE_16(self->lastBlockData.nSamples,nNewSamples)) + IF (!hTonalMDCTConc->lastBlockData.tonalConcealmentActive || NE_16(hTonalMDCTConc->lastBlockData.nSamples,nNewSamples)) { IF (LE_16(nNewSamples,L_FRAME_MAX)) { /* Shift the buffers */ - temp = self->secondLastBlockData.spectralData; /* Save the pointer */ move16(); - self->secondLastBlockData.spectralData = self->lastBlockData.spectralData; + temp = hTonalMDCTConc->secondLastBlockData.spectralData; /* Save the pointer */ move16(); + hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->lastBlockData.spectralData; move16(); - self->lastBlockData.spectralData = temp; + hTonalMDCTConc->lastBlockData.spectralData = temp; move16(); - tmp_exp = self->secondLastBlockData.spectralData_exp; /* Save the pointer */ move16(); - self->secondLastBlockData.spectralData_exp = self->lastBlockData.spectralData_exp; + tmp_exp = hTonalMDCTConc->secondLastBlockData.spectralData_exp; /* Save the pointer */ move16(); + hTonalMDCTConc->secondLastBlockData.spectralData_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); - self->lastBlockData.spectralData_exp = tmp_exp; + hTonalMDCTConc->lastBlockData.spectralData_exp = tmp_exp; move16(); - tmp_exp = self->secondLastBlockData.gain_tcx_exp; /* Save the pointer */ move16(); - self->secondLastBlockData.gain_tcx_exp = self->lastBlockData.gain_tcx_exp; + tmp_exp = hTonalMDCTConc->secondLastBlockData.gain_tcx_exp; /* Save the pointer */ move16(); + hTonalMDCTConc->secondLastBlockData.gain_tcx_exp = hTonalMDCTConc->lastBlockData.gain_tcx_exp; move16(); - self->lastBlockData.gain_tcx_exp = tmp_exp; + hTonalMDCTConc->lastBlockData.gain_tcx_exp = tmp_exp; move16(); - tmp_exp = self->secondLastBlockData.scaleFactors_max_e; /* Save the pointer */ move16(); - self->secondLastBlockData.scaleFactors_max_e = self->lastBlockData.scaleFactors_max_e; + tmp_exp = hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e; /* Save the pointer */ move16(); + hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = hTonalMDCTConc->lastBlockData.scaleFactors_max_e; move16(); - self->lastBlockData.scaleFactors_max_e = tmp_exp; + hTonalMDCTConc->lastBlockData.scaleFactors_max_e = tmp_exp; move16(); - temp = self->secondLastBlockData.scaleFactors; + temp = hTonalMDCTConc->secondLastBlockData.scaleFactors; move16(); - self->secondLastBlockData.scaleFactors = self->lastBlockData.scaleFactors; + hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->lastBlockData.scaleFactors; move16(); - self->lastBlockData.scaleFactors = temp; + hTonalMDCTConc->lastBlockData.scaleFactors = temp; move16(); - temp = self->secondLastBlockData.scaleFactors_exp; + temp = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp; move16(); - self->secondLastBlockData.scaleFactors_exp = self->lastBlockData.scaleFactors_exp; + hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->lastBlockData.scaleFactors_exp; move16(); - self->lastBlockData.scaleFactors_exp = temp; + hTonalMDCTConc->lastBlockData.scaleFactors_exp = temp; move16(); } ELSE { - self->lastBlockData.spectralData = self->spectralDataBuffers[0]; + hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; move16(); - self->secondLastBlockData.spectralData = self->spectralDataBuffers[1]; + hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1]; move16(); - self->lastBlockData.scaleFactors = self->scaleFactorsBuffers[0]; + hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; move16(); - self->secondLastBlockData.scaleFactors = self->scaleFactorsBuffers[1]; + hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1]; move16(); - self->lastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[0]; + hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; move16(); - self->secondLastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[1]; + hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[1]; move16(); } - nOldSamples = self->lastBlockData.nSamples; + nOldSamples = hTonalMDCTConc->lastBlockData.nSamples; move16(); - self->lastBlockData.nSamples = nNewSamples; + hTonalMDCTConc->lastBlockData.nSamples = nNewSamples; move16(); - self->secondLastBlockData.nSamples = nOldSamples; + hTonalMDCTConc->secondLastBlockData.nSamples = nOldSamples; move16(); - nOldSamples = self->lastBlockData.nSamplesCore; + nOldSamples = hTonalMDCTConc->lastBlockData.nSamplesCore; move16(); - self->lastBlockData.nSamplesCore = nNewSamplesCore; + hTonalMDCTConc->lastBlockData.nSamplesCore = nNewSamplesCore; move16(); - self->secondLastBlockData.nSamplesCore = nOldSamples; + hTonalMDCTConc->secondLastBlockData.nSamplesCore = nOldSamples; move16(); } test(); IF ((nNewSamples > 0) && (LE_16(nNewSamples,2*L_FRAME_MAX))) { +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + int16_t i; + PMTE() + hTonalMDCTConc->last_block_nrg = 0.0f; + for (i = 0; i < infoIGFStartLine; i++) + { + hTonalMDCTConc->lastBlockData.spectralData[i] = mdctSpectrum[i]; + hTonalMDCTConc->last_block_nrg += mdctSpectrum[i] * mdctSpectrum[i]; + } + for (; i < nNewSamples; i++) + { + hTonalMDCTConc->lastBlockData.spectralData[i] = mdctSpectrum[i]; + } +#else /* Store new data */ s = getScaleFactor32(mdctSpectrum, nNewSamples); - /*Copy(scaleFactors_exp, self->lastBlockData.scaleFactors_exp, self->nScaleFactors);*/ + /*Copy(scaleFactors_exp, hTonalMDCTConc->lastBlockData.scaleFactors_exp, hTonalMDCTConc->nScaleFactors);*/ max_exp = 0; - FOR (i = 0; i < self->nScaleFactors; i++) + FOR (i = 0; i < hTonalMDCTConc->nScaleFactors; i++) { - self->lastBlockData.scaleFactors_exp[i] = scaleFactors_exp[i]; + hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] = scaleFactors_exp[i]; move16(); max_exp = s_max(max_exp, scaleFactors_exp[i]); } /*s = sub(s, max_exp);*/ - self->lastBlockData.scaleFactors_max_e = max_exp; + hTonalMDCTConc->lastBlockData.scaleFactors_max_e = max_exp; FOR (i = 0; i < nNewSamples; i++) { - self->lastBlockData.spectralData[i] = extract_h(L_shl(mdctSpectrum[i], s)); + hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h(L_shl(mdctSpectrum[i], s)); move16(); } - self->lastBlockData.spectralData_exp = sub(mdctSpectrum_exp,s); + hTonalMDCTConc->lastBlockData.spectralData_exp = sub(mdctSpectrum_exp,s); +#endif move16(); - self->lastBlockData.gain_tcx_exp = gain_tcx_exp; + hTonalMDCTConc->lastBlockData.gain_tcx_exp = gain_tcx_exp; - Copy(scaleFactors, self->lastBlockData.scaleFactors, self->nScaleFactors); + Copy(scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->nScaleFactors); } - return TONALMDCTCONCEAL_OK; + return; } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr hTonalMDCTConc, Word16 nNewSamples, Word32 pitchLag, Word16 badBlock, @@ -275,7 +282,7 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, IF (badBlock) { - newBlockIsValid = self->lastBlockData.blockIsValid; + newBlockIsValid = hTonalMDCTConc->lastBlockData.blockIsValid; move16(); } ELSE @@ -293,24 +300,24 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, /* Shift old state */ move16(); move16(); move16(); - self->secondLastBlockData.blockIsConcealed = self->lastBlockData.blockIsConcealed; - self->secondLastBlockData.blockIsValid = self->lastBlockData.blockIsValid; - self->secondLastBlockData.tonalConcealmentActive = self->lastBlockData.tonalConcealmentActive; + hTonalMDCTConc->secondLastBlockData.blockIsConcealed = hTonalMDCTConc->lastBlockData.blockIsConcealed; + hTonalMDCTConc->secondLastBlockData.blockIsValid = hTonalMDCTConc->lastBlockData.blockIsValid; + hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive = hTonalMDCTConc->lastBlockData.tonalConcealmentActive; /* Store new state */ move16(); move16(); move16(); - self->lastBlockData.blockIsConcealed = badBlock; - self->lastBlockData.blockIsValid = newBlockIsValid; - self->lastBlockData.tonalConcealmentActive = tonalConcealmentActive; + hTonalMDCTConc->lastBlockData.blockIsConcealed = badBlock; + hTonalMDCTConc->lastBlockData.blockIsValid = newBlockIsValid; + hTonalMDCTConc->lastBlockData.tonalConcealmentActive = tonalConcealmentActive; - self->lastPitchLag = pitchLag; + hTonalMDCTConc->lastPitchLag = pitchLag; move32(); return TONALMDCTCONCEAL_OK; } static void FindPhases( /* o: currenc phase [-pi;pi] 2Q13 */ - TonalMDCTConcealPtr const self, /* i: pointer to internal structure */ + TonalMDCTConcealPtr const hTonalMDCTConc, /* i: pointer to internal structure */ Word32 secondLastMDCT[], /* i: MDST spectrum data */ Word32 secondLastMDST[], /* i: MDCT spectrum data */ Word16 diff_exp) /* i: exp_MDST - exp_MDCT */ @@ -321,11 +328,11 @@ static void FindPhases( /* o: currenc phase [-p - pCurrentPhase = self->pTCI->phase_currentFramePredicted; + pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; /* for each index/index group */ - FOR( i = 0; i < self->pTCI->numIndexes; i++) + FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { /* in contrast to the float code, the parameter secondLastMDST[l] needs not to be negated - due to a different implementation of @@ -346,7 +353,7 @@ static void FindPhases( /* o: currenc phase [-p #define J 31946 /* FL2WORD16(sin((3*EVS_PI)/BANDWIDTH)); */ static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ - TonalMDCTConcealPtr const self, /* i: Pointer to internal structure */ + TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ Word32 powerSpectrum[]) /* i: Power spectrum data */ { Word16 i, k; @@ -360,33 +367,38 @@ static void FindPhaseDifferences( /* o: Phase j = J; move16(); - phaseDiff = self->pTCI->phaseDiff; + phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; - FOR (i = 0; i < self->pTCI->numIndexes; i++) + FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { m = MM; move16(); n = N; move16(); - k = self->pTCI->indexOfTonalPeak[i]; + k = hTonalMDCTConc->pTCI->indexOfTonalPeak[i]; move16(); IF (GE_32(Mpy_32_16_1(powerSpectrum[k-1],512/*1.0f Q9*/),Mpy_32_16_1(powerSpectrum[k+1], MAXRATIO))) { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); - if(s_and(k,1) != 0) + if (s_and(k, 1) != 0) + { phaseDiff[i] = -12868/*-EVS_PI 3Q12*/; + } } ELSE { IF (GE_32(Mpy_32_16_1(powerSpectrum[k+1],512/*1.0f Q9*/),Mpy_32_16_1(powerSpectrum[k-1], MAXRATIO))) { phaseDiff[i] = 12868/*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ move16(); - if(s_and(k,1) != 0) + if (s_and(k, 1) != 0) + { phaseDiff[i] = 0/*0 Q13*/; /*2Q13*/ + } } - ELSE { + ELSE + { /*Q = (float)pow(odft_left/odft_right, G); a = (m - Q * s) / (n + Q * j); phaseDiff[i] = (float)atan(a) * (bandwidth/2.0f);*/ @@ -396,9 +408,10 @@ static void FindPhaseDifferences( /* o: Phase L_tmp = Mpy_32_16_1(Q,s); sfn = sub(sf, 2); - if(sfn > 0) + if (sfn > 0) + { m = L_shr(m, sfn); - + } IF(sfn < 0) { L_tmp = L_shl(L_tmp, sfn); @@ -414,7 +427,8 @@ static void FindPhaseDifferences( /* o: Phase sfd = add(sf,1); n = L_shr(n,sfd); } - ELSE{ + ELSE + { sfd = 0; L_tmp = L_shl(L_tmp, sf); } @@ -443,12 +457,17 @@ static void FindPhaseDifferences( /* o: Phase } } -static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self, - Word32 secondLastMDST[], - Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], - Word16 secondLastMDCT_exp, - Word32 const pitchLag) +static void CalcPowerSpecAndDetectTonalComponents( + TonalMDCTConcealPtr const hTonalMDCTConc, + Word32 secondLastMDST[], + Word16 secondLastMDST_exp, + Word32 secondLastMDCT[], + Word16 secondLastMDCT_exp, + Word32 const pitchLag +#ifdef IVAS_CODE_MDCT_GSHAPE + ,const PsychoacousticParameters* psychParamsCurrent +#endif +) { Word16 nSamples; Word16 i; @@ -460,11 +479,11 @@ static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self - nSamples = self->nNonZeroSamples; + nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); /* It is taken into account that the MDCT is not normalized. */ - floorPowerSpectrum/*Q0*/ = extract_l(Mpy_32_16_1(L_mult0(self->nSamples,self->nSamples),82)); /*1/400 = 82 Q15*/ + floorPowerSpectrum/*Q0*/ = extract_l(Mpy_32_16_1(L_mult0(hTonalMDCTConc->nSamples,hTonalMDCTConc->nSamples),82)); /*1/400 = 82 Q15*/ powerSpectrum_exp = 0; move16(); @@ -477,41 +496,41 @@ static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self powerSpectrum, &powerSpectrum_exp); - /* This setting to minimal level is required because the power spectrum is used in the threshold adaptation using the pitch up to self->nSamples. */ - set32_fx(powerSpectrum+nSamples, floorPowerSpectrum, sub(self->nSamples, nSamples)); + /* This setting to minimal level is required because the power spectrum is used in the threshold adaptation using the pitch up to hTonalMDCTConc->nSamples. */ + set32_fx(powerSpectrum+nSamples, floorPowerSpectrum, sub(hTonalMDCTConc->nSamples, nSamples)); /* this setting to zero is needed since the FDNS needs to be called - with self->nSamplesCore; it relevant only for nb; it has no effect + with hTonalMDCTConc->nSamplesCore; it relevant only for nb; it has no effect to the output, but memory checker may complain otherwise due to the usage of uninitialized values */ - IF ( GT_16(self->nSamplesCore, self->nSamples)) + IF ( GT_16(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)) { - set32_fx(powerSpectrum+self->nSamples, 0, sub(self->nSamplesCore, self->nSamples)); + set32_fx(powerSpectrum+hTonalMDCTConc->nSamples, 0, sub(hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples)); } - DetectTonalComponents(self->pTCI->indexOfTonalPeak, - self->pTCI->lowerIndex, - self->pTCI->upperIndex, - &self->pTCI->numIndexes, - self->lastPitchLag, + DetectTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, + hTonalMDCTConc->pTCI->lowerIndex, + hTonalMDCTConc->pTCI->upperIndex, + &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, pitchLag, - self->lastBlockData.spectralData, - add(self->lastBlockData.spectralData_exp,self->lastBlockData.gain_tcx_exp), - self->lastBlockData.scaleFactors, - self->lastBlockData.scaleFactors_exp, - self->lastBlockData.scaleFactors_max_e, + hTonalMDCTConc->lastBlockData.spectralData, + add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, powerSpectrum, nSamples, - self->nSamplesCore, + hTonalMDCTConc->nSamplesCore, floorPowerSpectrum); - FindPhases(self, secondLastMDCT, secondLastMDST, sub(secondLastMDST_exp,secondLastMDCT_exp)); + FindPhases(hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub(secondLastMDST_exp,secondLastMDCT_exp)); - FindPhaseDifferences(self, powerSpectrum); + FindPhaseDifferences(hTonalMDCTConc, powerSpectrum); - IF (self->pTCI->numIndexes > 0) + IF (hTonalMDCTConc->pTCI->numIndexes > 0) { - self->secondLastPowerSpectrum = self->secondLastBlockData.spectralData; + hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; @@ -524,18 +543,31 @@ static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self move32(); } - FOR (i = 0; i < self->nScaleFactors; i++) + FOR (i = 0; i < hTonalMDCTConc->nScaleFactors; i++) { move16(); move16(); - invScaleFactors_exp[i] = self->secondLastBlockData.scaleFactors_exp[i]; - invScaleFactors[i] = Inv16(self->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i]); + invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; + invScaleFactors[i] = Inv16(hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i]); } /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ - mdct_shaping(powerSpectrum, self->nSamplesCore, invScaleFactors, invScaleFactors_exp); - FOR (i = self->nSamplesCore; i < nSamples; i++) +#ifdef IVAS_CODE_MDCT_GSHAPE + IF (psychParamsCurrent == NULL) +#endif + { + mdct_shaping(powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp); + } +#ifdef IVAS_CODE_MDCT_GSHAPE + ELSE + { +PMTE() + sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); + nBands = psychParamsCurrent->nBands; + } +#endif + FOR (i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++) { powerSpectrum[i] = L_shl(Mpy_32_16_1(powerSpectrum[i], invScaleFactors[FDNS_NPTS-1]), invScaleFactors_exp[FDNS_NPTS-1]); move32(); @@ -544,62 +576,53 @@ static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self /* 16 bits are now enough for storing the power spectrum */ FOR (i = 0; i < nSamples; i++) { - self->secondLastPowerSpectrum[i] = round_fx(powerSpectrum[i]); + hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx(powerSpectrum[i]); } - powerSpectrum_exp = sub(powerSpectrum_exp, self->secondLastBlockData.gain_tcx_exp); - self->secondLastPowerSpectrum_exp = powerSpectrum_exp; + powerSpectrum_exp = sub(powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp); + hTonalMDCTConc->secondLastPowerSpectrum_exp = powerSpectrum_exp; move16(); } } -static void CalcMDXT(TonalMDCTConcealPtr const self, - Word16 const type, - Word16 const * const timeSignal, - Word32 * const mdxtOutput, - Word16 * const mdxtOutput_e) +static void CalcMDXT( + const TonalMDCTConcealPtr hTonalMDCTConc, + const Word16 type, + const Word16 * timeSignal, + Word32 * mdxtOutput, + Word16 * mdxtOutput_e +) { Word16 windowedTimeSignal[L_FRAME_PLUS+2*L_MDCT_OVLP_MAX]; Word16 left_overlap, right_overlap, L_frame; - L_frame = self->nSamples; + L_frame = hTonalMDCTConc->nSamples; move16(); - WindowSignal(self->tcx_cfg, - self->tcx_cfg->tcx_offsetFB, - FULL_OVERLAP, - FULL_OVERLAP, - &left_overlap, - &right_overlap, - timeSignal, - &L_frame, - windowedTimeSignal, - 1); + WindowSignal(hTonalMDCTConc->tcx_cfg, hTonalMDCTConc->tcx_cfg->tcx_offsetFB, FULL_OVERLAP, + FULL_OVERLAP, &left_overlap, &right_overlap, timeSignal, &L_frame, windowedTimeSignal, 1, 1); IF (type == 0) { - TCX_MDST(windowedTimeSignal, - mdxtOutput, - mdxtOutput_e, - left_overlap, - sub(L_frame, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + TCX_MDST(windowedTimeSignal, mdxtOutput, mdxtOutput_e, left_overlap, + sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap, EVS_MONO); } ELSE { - TCX_MDCT(windowedTimeSignal, - mdxtOutput, - mdxtOutput_e, - left_overlap, - sub(L_frame, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + TCX_MDCT(windowedTimeSignal, mdxtOutput, mdxtOutput_e, left_overlap, + sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap, EVS_MONO); } } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, - Word32 const pitchLag, - Word16 * const numIndices) +void TonalMDCTConceal_Detect( + const TonalMDCTConcealPtr hTonalMDCTConc, + const Word32 pitchLag, + Word16 * numIndices +#ifdef IVAS_CODE_MDCT_GSHAPE + ,const PsychoacousticParameters* psychParamsCurrent +#endif +) { Word32 secondLastMDST[L_FRAME_MAX]; Word32 secondLastMDCT[L_FRAME_MAX]; @@ -609,7 +632,7 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, Word16 nSamples; - nSamples = self->nSamples; + nSamples = hTonalMDCTConc->nSamples; move16(); secondLastMDST_exp = 16; /*time signal Q-1*/ secondLastMDCT_exp = 16; /*time signal Q-1*/ @@ -618,32 +641,32 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, test(); test(); test(); - IF (self->lastBlockData.blockIsValid && self->secondLastBlockData.blockIsValid - && (EQ_16(self->lastBlockData.nSamples,nSamples) ) && (EQ_16(self->secondLastBlockData.nSamples,nSamples) ) - && (!self->secondLastBlockData.blockIsConcealed || self->secondLastBlockData.tonalConcealmentActive || (pitchLag != 0)) /* Safety if the second last frame was concealed and tonal concealment was inactive */ - ) + IF (hTonalMDCTConc->lastBlockData.blockIsValid && hTonalMDCTConc->secondLastBlockData.blockIsValid + && (EQ_16(hTonalMDCTConc->lastBlockData.nSamples,nSamples) ) && (EQ_16(hTonalMDCTConc->secondLastBlockData.nSamples,nSamples) ) + && (!hTonalMDCTConc->secondLastBlockData.blockIsConcealed || hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive || (pitchLag != 0)) ) { + /* Safety if the second last frame was concealed and tonal concealment was inactive */ - IF (self->lastBlockData.blockIsConcealed == 0) + IF (hTonalMDCTConc->lastBlockData.blockIsConcealed == 0) { - IF (self->secondLastBlockData.tonalConcealmentActive == 0) + IF (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0) { - CalcMDXT(self, 0, self->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp); - CalcMDXT(self, 1, self->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp); - self->nNonZeroSamples = 0; - FOR (i = 0; i < self->nSamples; i++) + CalcMDXT(hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp); + CalcMDXT(hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp); + hTonalMDCTConc->nNonZeroSamples = 0; + FOR (i = 0; i < hTonalMDCTConc->nSamples; i++) { - if (self->secondLastBlockData.spectralData[i] != 0) + if (hTonalMDCTConc->secondLastBlockData.spectralData[i] != 0) { - self->nNonZeroSamples = i; + hTonalMDCTConc->nNonZeroSamples = i; move16(); } } /* 23 is the maximum length of the MA filter in getEnvelope */ - self->nNonZeroSamples = s_min(self->nSamples, add(self->nNonZeroSamples, 23)); + hTonalMDCTConc->nNonZeroSamples = s_min(hTonalMDCTConc->nSamples, add(hTonalMDCTConc->nNonZeroSamples, 23)); move16(); - nSamples = self->nNonZeroSamples; + nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); s = getScaleFactor32(secondLastMDST, nSamples); @@ -664,18 +687,29 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, } secondLastMDCT_exp = sub(secondLastMDCT_exp, s); move16(); - CalcPowerSpecAndDetectTonalComponents(self, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag); + CalcPowerSpecAndDetectTonalComponents(hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag); } ELSE { /* If the second last frame was also lost, it is expected that pastTimeSignal could hold a bit different signal (e.g. including fade-out) from the one stored in TonalMDCTConceal_SaveTimeSignal. */ /* That is why we reuse the already stored information about the concealed spectrum in the second last frame */ - nSamples = self->nNonZeroSamples; - move16(); - mdct_shaping_16(self->secondLastPowerSpectrum, self->nSamplesCore, nSamples, - self->secondLastBlockData.scaleFactors, self->secondLastBlockData.scaleFactors_exp, - self->secondLastBlockData.scaleFactors_max_e, powerSpectrum); - +#ifdef IVAS_CODE_MDCT_GSHAPE + IF (psychParamsCurrent == NULL) +#endif + { + nSamples = hTonalMDCTConc->nNonZeroSamples; + move16(); + mdct_shaping_16(hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, + hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, + hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum); + } +#ifdef IVAS_CODE_MDCT_GSHAPE + ELSE + { + sns_shape_spectrum(powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore); + nBands = psychParamsCurrent->nBands; + } +#endif powerSpectrum_exp = getScaleFactor32(powerSpectrum, nSamples); powerSpectrum_exp = sub(powerSpectrum_exp, 3); /*extra 3 bits of headroom for MA filter in getEnvelope*/ @@ -687,78 +721,285 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, move32(); } - RefineTonalComponents(self->pTCI->indexOfTonalPeak, - self->pTCI->lowerIndex, - self->pTCI->upperIndex, - self->pTCI->phaseDiff, - self->pTCI->phase_currentFramePredicted, - &self->pTCI->numIndexes, - self->lastPitchLag, - pitchLag, - self->lastBlockData.spectralData, - add(self->lastBlockData.spectralData_exp,self->lastBlockData.gain_tcx_exp), - self->lastBlockData.scaleFactors, - self->lastBlockData.scaleFactors_exp, - self->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - self->nSamplesCore, - extract_l(Mpy_32_16_1(L_mult0(self->nSamples,self->nSamples),82))); /* floorPowerSpectrum */ + RefineTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, + hTonalMDCTConc->pTCI->lowerIndex, + hTonalMDCTConc->pTCI->upperIndex, + hTonalMDCTConc->pTCI->phaseDiff, + hTonalMDCTConc->pTCI->phase_currentFramePredicted, + &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + add(hTonalMDCTConc->lastBlockData.spectralData_exp,hTonalMDCTConc->lastBlockData.gain_tcx_exp), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, + nSamples, + hTonalMDCTConc->nSamplesCore, + extract_l(Mpy_32_16_1(L_mult0(hTonalMDCTConc->nSamples,hTonalMDCTConc->nSamples),82))); /* floorPowerSpectrum */ } } } ELSE { - self->pTCI->numIndexes = 0; + hTonalMDCTConc->pTCI->numIndexes = 0; move16(); } - *numIndices = self->pTCI->numIndexes; + *numIndices = hTonalMDCTConc->pTCI->numIndexes; move16(); - return TONALMDCTCONCEAL_OK; + return ; } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, /*IN */ - Word32* mdctSpectrum, /*OUT*/ - Word16* mdctSpectrum_exp, /*OUT*/ - Word8 tonalConcealmentActive, - Word16* pSeed, /*IN/OUT*/ - Word16 tiltCompFactor, - Word16 crossfadeGain, - Word16 crossOverFreq) +void TonalMDCTConceal_InsertNoise( + const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32* mdctSpectrum, /*OUT*/ + Word16* mdctSpectrum_exp, /*OUT*/ + const Word8 tonalConcealmentActive, + Word16* pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, + Word16 crossfadeGain, +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + const Word16concealment_noise[L_FRAME48k], + const float cngLevelBackgroundTrace_bfi, +#endif + const Word16 crossOverFreq +) { Word16 i, ld, fac; Word16 rnd, exp, exp_last, exp_noise, inv_samples, inv_exp; Word16 g, tiltFactor, tilt, tmp; Word32 nrgNoiseInLastFrame, nrgWhiteNoise, L_tmp, L_tmp2; - - +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + float last_block_nrg_correct; +#endif g = sub(32767/*1.0f Q15*/,crossfadeGain); rnd = 1977; move16(); - if (self->lastBlockData.blockIsConcealed) + if (hTonalMDCTConc->lastBlockData.blockIsConcealed) { rnd = *pSeed; move16(); } - - IF (self->lastBlockData.blockIsValid == 0) +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + /* based on what is done in tcx_noise_filling() */ + /* always initialize these to avoid compiler warnings */ + tiltFactor = (float)pow(max(0.375f, tiltCompFactor), 1.0f / hTonalMDCTConc->lastBlockData.nSamples); + tilt = 1.0f; + nrgNoiseInLastFrame = 0.0f; + nrgWhiteNoise = 0.0f; + hTonalMDCTConc->faded_signal_nrg = 0.0f; + last_block_nrg_correct = 0.0f; +#endif + IF (hTonalMDCTConc->lastBlockData.blockIsValid == 0) { /* may just become active if the very first frame is lost */ - set32_fx(mdctSpectrum, 0, self->nSamples); + set32_fx(mdctSpectrum, 0, hTonalMDCTConc->nSamples); *mdctSpectrum_exp = SPEC_EXP_DEC; } +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT + else if (concealment_noise != NULL) + { + if (!tonalConcealmentActive) + { + /* if fadeout has not started yet, only apply sign scrambling */ + if (crossfadeGain == 1.0f) + { + for (i = 0; i < crossOverFreq; i++) + { + if (concealment_noise[i] > 0) + { + mdctSpectrum[i] = hTonalMDCTConc->lastBlockData.spectralData[i]; + } + else + { + mdctSpectrum[i] = -hTonalMDCTConc->lastBlockData.spectralData[i]; + } + } + + for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + { + mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; + } + } + /* actual fadeout is done in this case */ + else + { + g *= (float)sqrt(cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg); + + for (i = 0; i < crossOverFreq; i++) + { + x = hTonalMDCTConc->lastBlockData.spectralData[i]; + y = concealment_noise[i]; + + if (y > 0) + { + mdctSpectrum[i] = g * y + crossfadeGain * x; + } + else + { + mdctSpectrum[i] = g * y - crossfadeGain * x; + } + + hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[i] * mdctSpectrum[i]; + } + for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + { + mdctSpectrum[l] = 0.0f; + } + } + } + else + { + assert(hTonalMDCTConc->pTCI->numIndexes > 0); + + /* initialize bins of tonal components with zero: basically not + necessary, but currently the whole spectrum is rescaled in + mdct_noiseShaping() and then there would be a processing of + uninitialized values */ + for (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) + { + for (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) + { + mdctSpectrum[l] = 0; + if (l < crossOverFreq) + { + last_block_nrg_correct += hTonalMDCTConc->lastBlockData.spectralData[l] * hTonalMDCTConc->lastBlockData.spectralData[l]; + hTonalMDCTConc->curr_noise_nrg -= concealment_noise[l] * concealment_noise[l]; + } + } + } + + /* if fadeout has not started yet, only apply sign scrambling */ + if (crossfadeGain == 1.0f) + { + for (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) + { + if (concealment_noise[l] > 0) + { + mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; + } + else + { + mdctSpectrum[l] = -hTonalMDCTConc->lastBlockData.spectralData[l]; + } + } + for (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) + { + for (l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) + { + if (concealment_noise[l] > 0) + { + mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; + } + else + { + mdctSpectrum[l] = -hTonalMDCTConc->lastBlockData.spectralData[l]; + } + } + } + + for (l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++) + { + if (concealment_noise[l] > 0) + { + mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; + } + else + { + mdctSpectrum[l] = -hTonalMDCTConc->lastBlockData.spectralData[l]; + } + } + + for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + { + mdctSpectrum[l] = hTonalMDCTConc->lastBlockData.spectralData[l]; + } + } + /* actual fadeout is done in this case */ + else + { + g *= (float)sqrt(cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg); + + for (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) + { + x = hTonalMDCTConc->lastBlockData.spectralData[l]; + y = concealment_noise[l]; + + if (y > 0) + { + mdctSpectrum[l] = g * y + crossfadeGain * x; + } + else + { + mdctSpectrum[l] = g * y - crossfadeGain * x; + } + hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[l] * mdctSpectrum[l]; + } + for (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) + { + for (l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) + { + x = hTonalMDCTConc->lastBlockData.spectralData[l]; + y = concealment_noise[l]; + + if (y > 0) + { + mdctSpectrum[l] = g * y + crossfadeGain * x; + } + else + { + mdctSpectrum[l] = g * y - crossfadeGain * x; + } + hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[l] * mdctSpectrum[l]; + } + } + + for (l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++) + { + x = hTonalMDCTConc->lastBlockData.spectralData[l]; + y = concealment_noise[l]; + + if (y > 0) + { + mdctSpectrum[l] = g * y + crossfadeGain * x; + } + else + { + mdctSpectrum[l] = g * y - crossfadeGain * x; + } + hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[l] * mdctSpectrum[l]; + } + + for (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) + { + mdctSpectrum[l] = 0.0f; + } + } + } + + if (hTonalMDCTConc->faded_signal_nrg > 0.0f && hTonalMDCTConc->curr_noise_nrg > MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG) + { + float nrg_corr_factor; + + nrg_corr_factor = sqrtf((hTonalMDCTConc->last_block_nrg - last_block_nrg_correct) / hTonalMDCTConc->faded_signal_nrg); + v_multc(mdctSpectrum, nrg_corr_factor, mdctSpectrum, crossOverFreq); + } + } +#endif ELSE { +#ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT L_tmp = 805306368l/*0.375f Q31*/; inv_exp = 15; move16(); - inv_samples = Inv16(self->lastBlockData.nSamples, &inv_exp); + inv_samples = Inv16(hTonalMDCTConc->lastBlockData.nSamples, &inv_exp); tiltFactor = round_fx(BASOP_Util_fPow(L_max(L_tmp, L_deposit_h(tiltCompFactor)), 0, L_deposit_h(inv_samples),inv_exp, &exp)); BASOP_SATURATE_WARNING_OFF /*next op may result in 32768*/ tiltFactor = shl(tiltFactor, exp); @@ -770,16 +1011,17 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, nrgNoiseInLastFrame = L_deposit_h(0); nrgWhiteNoise = L_deposit_h(0); exp_last = exp_noise = 0; +#endif move16(); move16(); IF (!tonalConcealmentActive) { - ld = sub(14,norm_s(self->lastBlockData.nSamples)); + ld = sub(14,norm_s(hTonalMDCTConc->lastBlockData.nSamples)); fac = shr(-32768,ld); FOR (i = 0; i < crossOverFreq; i++) { - Word16 x = self->lastBlockData.spectralData[i]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; Word32 y; rnd = extract_l(L_mac0(13849, rnd, 31821)); y = L_mult(tilt,rnd); @@ -800,7 +1042,7 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, } ELSE { - exp_last = add(ld,shl(self->lastBlockData.spectralData_exp,1)); + exp_last = add(ld,shl(hTonalMDCTConc->lastBlockData.spectralData_exp,1)); exp_noise = add(ld,30); IF (nrgWhiteNoise > 0) @@ -824,18 +1066,18 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, g = mult_r(g,tmp); L_tmp = L_deposit_h(0); - ld = sub(self->lastBlockData.spectralData_exp, 15); + ld = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, 15); exp = sub(ld, exp); IF(exp > 0) { g = shr(g,exp); - *mdctSpectrum_exp = self->lastBlockData.spectralData_exp; + *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; } ELSE { crossfadeGain = shl(crossfadeGain,exp); - *mdctSpectrum_exp = sub(self->lastBlockData.spectralData_exp,exp); + *mdctSpectrum_exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp,exp); } /*make a headroom for mdct_shaping*/ exp = sub(*mdctSpectrum_exp, SPEC_EXP_DEC); @@ -852,7 +1094,7 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, FOR (i = 0; i < crossOverFreq; i++) { - Word16 const x = self->lastBlockData.spectralData[i]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; Word32 const y = mdctSpectrum[i]; if(g > 0) @@ -869,28 +1111,28 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, move32(); } } - exp = sub(self->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); - FOR (i = crossOverFreq; i < self->lastBlockData.nSamples; i++) + exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); + FOR (i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++) { - mdctSpectrum[i] = L_shl(L_deposit_l(self->lastBlockData.spectralData[i]), exp); + mdctSpectrum[i] = L_shl(L_deposit_l(hTonalMDCTConc->lastBlockData.spectralData[i]), exp); move32(); } } ELSE { Word16 l; - assert(self->pTCI->numIndexes > 0); + assert(hTonalMDCTConc->pTCI->numIndexes > 0); - FOR (l = self->pTCI->lowerIndex[0]; l <= self->pTCI->upperIndex[0]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++) { mdctSpectrum[l] = L_deposit_l(0); } - ld = sub(14,norm_s(self->lastBlockData.nSamples)); + ld = sub(14,norm_s(hTonalMDCTConc->lastBlockData.nSamples)); fac = shr(-32768,ld); - FOR (l = 0; l < self->pTCI->lowerIndex[0]; l++) + FOR (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) { - Word16 x = self->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; rnd = extract_l(L_mac0(13849, rnd, 31821)); y = L_mult(tilt,rnd); @@ -904,21 +1146,21 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, tilt = mult_r(tilt,tiltFactor); } - FOR (i = 1; i < self->pTCI->numIndexes; i++) + FOR (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - /*tilt *= (float)pow(tiltFactor, self->pTCI->upperIndex[i-1]-self->pTCI->lowerIndex[i-1]+1);*/ - tmp= round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(self->pTCI->upperIndex[i-1]-self->pTCI->lowerIndex[i-1]+1),15, &exp)); + /*tilt *= (float)pow(tiltFactor, hTonalMDCTConc->pTCI->upperIndex[i-1]-hTonalMDCTConc->pTCI->lowerIndex[i-1]+1);*/ + tmp= round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI->upperIndex[i-1]-hTonalMDCTConc->pTCI->lowerIndex[i-1]+1),15, &exp)); tmp = shl(tmp, exp); tilt = mult_r(tilt,tmp); - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { mdctSpectrum[l] = L_deposit_l(0); } - FOR (l = self->pTCI->upperIndex[i-1]+1; l < self->pTCI->lowerIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) { - Word16 x = self->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; rnd = extract_l(L_mac0(13849, rnd, 31821)); y = L_mult(tilt,rnd); @@ -933,15 +1175,15 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, } } - tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(self->pTCI->upperIndex[self->pTCI->numIndexes-1]-self->pTCI->lowerIndex[self->pTCI->numIndexes-1]+1),15, &exp)); + tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1]-hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes-1]+1),15, &exp)); BASOP_SATURATE_WARNING_OFF /*next op may result in 32768*/ tmp = shl(tmp, exp); BASOP_SATURATE_WARNING_ON tilt = mult_r(tilt,tmp); - FOR (l = add(self->pTCI->upperIndex[self->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) + FOR (l = add(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) { - Word16 x = self->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 y; rnd = extract_l(L_mac0(13849, rnd, 31821)); y = L_mult(tilt,rnd); @@ -962,7 +1204,7 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, } ELSE { - exp_last = add(ld,shl(self->lastBlockData.spectralData_exp,1)); + exp_last = add(ld,shl(hTonalMDCTConc->lastBlockData.spectralData_exp,1)); exp_noise = add(ld,shl(15,1)); ld = norm_l(nrgNoiseInLastFrame); @@ -984,16 +1226,17 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, g = mult_r(g,tmp); L_tmp = L_deposit_h(0); - ld = sub(self->lastBlockData.spectralData_exp, 15); + ld = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, 15); exp = sub(ld, exp); IF(exp > 0) { g = shr(g,exp); - *mdctSpectrum_exp = self->lastBlockData.spectralData_exp; + *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; } - ELSE { + ELSE + { crossfadeGain = shl(crossfadeGain,exp); - *mdctSpectrum_exp = sub(self->lastBlockData.spectralData_exp,exp); + *mdctSpectrum_exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp,exp); } /*make a headroom for mdct_shaping*/ exp = sub(*mdctSpectrum_exp, SPEC_EXP_DEC); @@ -1008,9 +1251,9 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, exp = 0; } - FOR (l = 0; l < self->pTCI->lowerIndex[0]; l++) + FOR (l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++) { - Word16 const x = self->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; if(g > 0) @@ -1027,11 +1270,11 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, move32(); } - FOR (i = 1; i < self->pTCI->numIndexes; i++) + FOR (i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - FOR (l = self->pTCI->upperIndex[i-1]+1; l < self->pTCI->lowerIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->upperIndex[i-1]+1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++) { - Word16 const x = self->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; if(g > 0) @@ -1053,17 +1296,17 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, necessary, but currently the whole spectrum is rescaled in mdct_noiseShaping() and then there would be a processing of uninitialized values */ - FOR (i = 0; i < self->pTCI->numIndexes; i++) + FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { mdctSpectrum[l] = L_deposit_l(0); } } - FOR (l = add(self->pTCI->upperIndex[self->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) + FOR (l = add(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) { - Word16 const x = self->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; Word32 const y = mdctSpectrum[l]; if(g > 0) @@ -1080,10 +1323,10 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, move32(); } } - exp = sub(self->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); - FOR (l = crossOverFreq; l < self->lastBlockData.nSamples; l++) + exp = sub(hTonalMDCTConc->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); + FOR (l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++) { - mdctSpectrum[l] = L_shl(L_deposit_l(self->lastBlockData.spectralData[l]), exp); + mdctSpectrum[l] = L_shl(L_deposit_l(hTonalMDCTConc->lastBlockData.spectralData[l]), exp); move32(); } } @@ -1092,13 +1335,17 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, *pSeed = rnd; move16(); - return TONALMDCTCONCEAL_OK; + return ; } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply(TonalMDCTConcealPtr self, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ - Word16 *mdctSpectrum_exp /*IN */ - ) +void TonalMDCTConceal_Apply( + const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32 *mdctSpectrum, /*IN/OUT*/ + Word16 *mdctSpectrum_exp /*IN */ +#ifdef IVAS_CODE_MDCT_GSHAPE + ,const PsychoacousticParameters* psychParamsCurrent) +#endif + ) { Word16 i, l, exp; Word16 * phaseDiff, * pCurrentPhase; @@ -1108,40 +1355,52 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply(TonalMDCTConcealPtr self, /*IN - IF (self->lastBlockData.blockIsValid & self->secondLastBlockData.blockIsValid) + IF (hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid) { - assert(self->pTCI->numIndexes > 0); + assert(hTonalMDCTConc->pTCI->numIndexes > 0); - nSamples = self->nNonZeroSamples; + nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); - assert(self->pTCI->upperIndex[self->pTCI->numIndexes-1] < nSamples); + assert(hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes-1] < nSamples); +#ifdef IVAS_CODE_MDCT_GSHAPE + IF (psychParamsCurrent == NULL) +#endif + { - mdct_shaping_16(self->secondLastPowerSpectrum, self->nSamplesCore, nSamples, - self->secondLastBlockData.scaleFactors, self->secondLastBlockData.scaleFactors_exp, - self->secondLastBlockData.scaleFactors_max_e, powerSpectrum); + mdct_shaping_16(hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, + hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, + hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum); + } +#ifdef IVAS_CODE_MDCT_GSHAPE + ELSE + { + sns_shape_spectrum(powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore); + nBands = psychParamsCurrent->nBands; - phaseDiff = self->pTCI->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ - pCurrentPhase = self->pTCI->phase_currentFramePredicted; + } +#endif + phaseDiff = hTonalMDCTConc->pTCI->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ + pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; - exp = sub(*mdctSpectrum_exp, add(add(self->secondLastPowerSpectrum_exp, add(self->secondLastBlockData.gain_tcx_exp,1)),self->secondLastBlockData.scaleFactors_max_e)); + exp = sub(*mdctSpectrum_exp, add(add(hTonalMDCTConc->secondLastPowerSpectrum_exp, add(hTonalMDCTConc->secondLastBlockData.gain_tcx_exp,1)),hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e)); - IF (!self->lastBlockData.blockIsConcealed) + IF (!hTonalMDCTConc->lastBlockData.blockIsConcealed) { - if (self->secondLastBlockData.tonalConcealmentActive != 0) + if (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0) { - self->nFramesLost = add(self->nFramesLost,2); /*Q1*/ move16(); + hTonalMDCTConc->nFramesLost = add(hTonalMDCTConc->nFramesLost,2); /*Q1*/ move16(); } - if (self->secondLastBlockData.tonalConcealmentActive == 0) + if (hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0) { - self->nFramesLost = 3; /*Q1*/ move16(); + hTonalMDCTConc->nFramesLost = 3; /*Q1*/ move16(); } } /* for each index group */ - FOR (i = 0; i < self->pTCI->numIndexes; i++) + FOR (i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++) { - /*phaseToAdd = self->nFramesLost*phaseDiff[i]; */ - phaseToAdd = L_mult0(self->nFramesLost,phaseDiff[i]); /*Q1*3Q12=2Q13*/ + /*phaseToAdd = hTonalMDCTConc->nFramesLost*phaseDiff[i]; */ + phaseToAdd = L_mult0(hTonalMDCTConc->nFramesLost,phaseDiff[i]); /*Q1*3Q12=2Q13*/ /* Move phaseToAdd to range -PI..PI */ WHILE (GT_32(phaseToAdd, 25736l/*EVS_PI Q13*/)) @@ -1153,7 +1412,7 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply(TonalMDCTConcealPtr self, /*IN phaseToAdd = L_add(phaseToAdd, 51472l/*2*EVS_PI Q13*/); } - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + FOR (l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++) { /* *pCurrentPhase and phaseToAdd are in range -PI..PI */ currentPhase = L_mac0(phaseToAdd, (*pCurrentPhase++), 1); /*2Q13+2Q13=3Q13*/ @@ -1174,36 +1433,39 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply(TonalMDCTConcealPtr self, /*IN } } - self->nFramesLost = add(self->nFramesLost,2); /*Q1*/ move16(); + hTonalMDCTConc->nFramesLost = add(hTonalMDCTConc->nFramesLost,2); /*Q1*/ move16(); - return TONALMDCTCONCEAL_OK; + return ; } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr self, - Word16* timeSignal, - Word16 nNewSamples - ) +void TonalMDCTConceal_SaveTimeSignal( + TonalMDCTConcealPtr hTonalMDCTConc, + Word16* timeSignal, + Word16 nNewSamples + +) { - IF (EQ_16(nNewSamples,self->nSamples)) + IF (EQ_16(nNewSamples,hTonalMDCTConc->nSamples)) { assert(nNewSamples <= L_FRAME_MAX); - IF (!self->secondLastBlockData.tonalConcealmentActive) + IF (!hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive) { - Copy(self->lastPcmOut + self->nSamples/2, self->secondLastPcmOut, self->nSamples/2); + Copy(hTonalMDCTConc->lastPcmOut + hTonalMDCTConc->nSamples/2, hTonalMDCTConc->secondLastPcmOut, hTonalMDCTConc->nSamples/2); } - Copy(timeSignal, self->lastPcmOut, self->nSamples); + Copy(timeSignal, hTonalMDCTConc->lastPcmOut, hTonalMDCTConc->nSamples); } - return TONALMDCTCONCEAL_OK; + return ; } -static void CalcPowerSpec(Word32 * mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ - Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - Word32 * mdstSpec, /* i: MDST spectrum Q31,mdstSpec_exp */ - Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ - Word16 nSamples, /* i: frame size */ - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins Q0 */ - Word32 * powerSpec, /* o: power spectrum */ - Word16 * powerSpec_exp) /* o: exponent of power spectrum */ +static void CalcPowerSpec( + const Word32 * mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ + const Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ + const Word32 * mdstSpec, /* i: MDST spectrum Q31,mdstSpec_exp */ + const Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ + const Word16 nSamples, /* i: frame size */ + const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins Q0 */ + Word32 * powerSpec, /* o: power spectrum */ + Word16 * powerSpec_exp) /* o: exponent of power spectrum */ { Word16 k, s1, s2, tmp; Word32 x, L_tmp, L_tmp_floor; @@ -1244,3 +1506,214 @@ static void CalcPowerSpec(Word32 * mdctSpec, /* i: MDCT spectrum move32(); } +#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT +void TonalMdctConceal_create_concealment_noise( + float concealment_noise[L_FRAME48k], + CPE_DEC_HANDLE hCPE, + const int16_t L_frameTCX, + const int16_t L_frame, + const int16_t idchan, + const int16_t subframe_idx, + const int16_t core, + const int16_t crossfade_gain, + const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode) +{ + STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct; + TonalMDCTConcealPtr hTonalMDCTConc; + Decoder_State* st; + HANDLE_FD_CNG_COM hFdCngCom; + int16_t* rnd_c, * rnd; + int16_t crossOverFreq, i, save_rnd_c, max_noise_line; + float c, c_inv; + float noise_shape_buffer[L_FRAME48k]; + int16_t inc, start_idx, stop_idx; + float* cngNoiseLevelPtr; + float last_scf; + + wmops_sub_start("create_conc_noise"); + + hStereoMdct = hCPE->hStereoMdct; + st = hCPE->hCoreCoder[idchan]; + hTonalMDCTConc = st->hTonalMDCTConc; + hFdCngCom = st->hFdCngDec->hFdCngCom; + rnd = &hStereoMdct->noise_seeds_channels[idchan]; + rnd_c = &hStereoMdct->noise_seed_common; + + /* determine start bin for IGF */ + if (st->igf == 0) + { + if (st->narrowBand == 0) + { + /* minimum needed for output with sampling rates lower then the + nominal sampling rate */ + crossOverFreq = min(L_frameTCX, L_frame); + } + else + { + crossOverFreq = L_frameTCX; + } + } + else + { + crossOverFreq = min(st->hIGFDec->infoIGFStartLine, L_frameTCX); + } + + /* for tonal mdct concealment with tonal components above the crossover frequency, conditionally raise the frequency index until which noise is generated */ + max_noise_line = crossOverFreq; + if (st->tonal_mdct_plc_active) + { + max_noise_line = max(max_noise_line, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1); + } + + /* first lost frame is handled separately */ + if (!hTonalMDCTConc->lastBlockData.blockIsConcealed) + { + *rnd = 1977 + idchan; + /* will be set twice when looping over two channels, but does not matter */ + *rnd_c = 1979; + } + + if (crossfade_gain == 1.0f) + { + /* In first frame, noise is weighted with zero anyway, we only need the random numbers for the sign scrambling */ + for (i = 0; i < max_noise_line; i++) + { + *rnd = own_random(rnd); + concealment_noise[i] = *rnd; + } + + wmops_sub_end(); + + return; + } + + save_rnd_c = *rnd_c; + + c = sqrtf(hStereoMdct->lastCoh); + c_inv = sqrtf(1 - hStereoMdct->lastCoh); + + /* pre-compute the noise shape for later weighting of the noise spectra */ + cngNoiseLevelPtr = &hFdCngCom->cngNoiseLevel[0]; + inc = (st->core > TCX_20_CORE) ? 2 : 1; + start_idx = hFdCngCom->startBand / inc; + stop_idx = hFdCngCom->stopFFTbin / inc; + + for (i = 0; i < start_idx; i++) + { + noise_shape_buffer[i] = 0.0f; + } + for (; i < stop_idx; i++, cngNoiseLevelPtr += inc) + { + noise_shape_buffer[i] = sqrtf(*(cngNoiseLevelPtr)); + } + + last_scf = sqrtf(*(cngNoiseLevelPtr - inc)); + + for (; i < max_noise_line; i++) + { + noise_shape_buffer[i] = last_scf; + } + + /* fill the noise vector */ + hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG; + if (noise_gen_mode == EQUAL_CORES || ((noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 0) || (noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 1))) + { + /* current channel is TCX20 -> generate noise for "full-length" spectrum */ + for (i = 0; i < max_noise_line; i++) + { + *rnd = own_random(rnd); + *rnd_c = own_random(rnd_c); + + concealment_noise[i] = (c_inv * *rnd + c * *rnd_c) * noise_shape_buffer[i]; + hTonalMDCTConc->curr_noise_nrg += concealment_noise[i] * concealment_noise[i]; + } + } + else /* ( ( noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 0 ) || ( noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 1 ) ) */ + { + /* current channel is TCX10 and the other is TCX20 -> generate noise for "half-length" spectrum, but "increment" mid seed twice, to have the same seed in mid as the other (TCX20) channel for next frame */ + for (i = 0; i < max_noise_line; i++) + { + *rnd = own_random(rnd); + *rnd_c = own_random(rnd_c); + + concealment_noise[i] = (c_inv * *rnd + c * *rnd_c) * noise_shape_buffer[i]; + hTonalMDCTConc->curr_noise_nrg += concealment_noise[i] * concealment_noise[i]; + + *rnd_c = own_random(rnd_c); + } + } + if (st->tonal_mdct_plc_active) + { + for (i = crossOverFreq; i < max(crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1]); ++i) + { + concealment_noise[i] *= 0.0f; + } + } + /* restore common seed + - after finishing the first channel + - after a first subframe if the current channel is TCX10 */ + if ((idchan == 0 && (core == TCX_20 || (core == TCX_10 && subframe_idx == 1))) || (core == TCX_10 && subframe_idx == 0)) + { + *rnd_c = save_rnd_c; + } + st->seed_tcx_plc = *rnd; + wmops_sub_end(); + + return; +} +void TonalMdctConceal_whiten_noise_shape( + Decoder_State* st, + const int16_t L_frame, + const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE whitening_mode) +{ + int16_t inc, start_idx, stop_idx; + float* noiseLevelPtr, * scfs_bg, * scfs_for_shaping; + HANDLE_FD_CNG_COM hFdCngCom; + float whitenend_noise_shape[L_FRAME16k]; + float scfs_int[FDNS_NPTS]; + const PsychoacousticParameters* psychParams; + + push_wmops("apply_sns_on_noise_shape"); + + scfs_bg = &st->hTonalMDCTConc->scaleFactorsBackground[0]; + psychParams = st->hTonalMDCTConc->psychParams; + hFdCngCom = st->hFdCngDec->hFdCngCom; + + inc = ((whitening_mode == ON_FIRST_LOST_FRAME ? st->core : st->last_core) > TCX_20_CORE) ? 2 : 1; + start_idx = hFdCngCom->startBand / inc; + stop_idx = L_frame / inc; + noiseLevelPtr = hFdCngCom->cngNoiseLevel; + + set_zero(whitenend_noise_shape, start_idx); + for (int16_t j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc) + { + whitenend_noise_shape[j] = *noiseLevelPtr; + } + + if (whitening_mode == ON_FIRST_LOST_FRAME) + { + float scf[SNS_NPTS]; + + sns_compute_scf(whitenend_noise_shape, psychParams, L_frame, scf); + sns_interpolate_scalefactors(scfs_int, scf, ENC); + sns_interpolate_scalefactors(scfs_bg, scf, DEC); + scfs_for_shaping = &scfs_int[0]; + } + else /* whitening_mode == ON_FIRST_GOOD_FRAME */ + { + scfs_for_shaping = &scfs_bg[0]; + } + + if (sum_f(scfs_for_shaping, FDNS_NPTS) > 0.0f) + { + sns_shape_spectrum(whitenend_noise_shape, psychParams, scfs_for_shaping, L_frame); + mvr2r(whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel, stop_idx - start_idx); + } + else + { + set_zero(hFdCngCom->cngNoiseLevel, stop_idx - start_idx); + } + + pop_wmops(); +} +#endif diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 500c4e5..5921aa0 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -1,7 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ @@ -9,12 +9,10 @@ #include "stl.h" /*----------------------------------------------------------------------* - * Local functions + * Local function prototypes *----------------------------------------------------------------------*/ - static void tc_dec_fx( Decoder_State_fx *st_fx, const Word16 L_frame,Word16 exc[], Word16 *T0,Word16 *T0_frac, const Word16 i_subfr, - const Word16 tc_subfr, Word16 *position, const Word32 core_brate, Word16 bwe_exc[], Word16 *Q_exc ); - + const Word16 tc_subfr, Word16 *position, Word16 bwe_exc[], Word16 *Q_exc ); /*======================================================================*/ /* FUNCTION : transition_dec_fx() */ /*----------------------------------------------------------------------*/ @@ -22,7 +20,6 @@ static void tc_dec_fx( Decoder_State_fx *st_fx, const Word16 L_frame,Word16 exc[ /* */ /*----------------------------------------------------------------------*/ /* GLOBAL INPUT ARGUMENTS : */ -/* const Word32 core_brate, : core bitrate Q0 */ /* _ (Word16) L_frame_fx : length of the frame Q0 */ /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ /* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ @@ -39,29 +36,32 @@ static void tc_dec_fx( Decoder_State_fx *st_fx, const Word16 L_frame,Word16 exc[ /*=======================================================================*/ void transition_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coder type */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *exc, /* o : excitation signal */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16 **pt_pitch, /* o : floating pitch values */ - Word16 *position, /* i/o: first glottal impulse position in frame */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *Q_exc /*i/o : scaling of excitation */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *exc, /* o : excitation signal */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + Word16 **pt_pitch, /* o : floating pitch values */ + Word16 *position, /* i/o: first glottal impulse position in frame */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ + Word16 *Q_exc /*i/o : scaling of excitation */ ) { Word16 pit_flag, pit_start, pit_limit, index, nBits; Word16 i, offset,temp,tmp; Word16 limit_flag; + Word16 i_subfridx; +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(Opt_AMR_WB); +#endif + i_subfridx = shr(i_subfr, 6); /*i_subfr / L_SUBFR*/ /* Set limit_flag to 0 for restrained limits, and 1 for extended limits */ limit_flag = 0; @@ -108,8 +108,7 @@ void transition_dec_fx( } /* glottal shape codebook contribution construction */ - tc_dec_fx( st_fx, L_frame, exc, T0, T0_frac, i_subfr, tc_subfr, position, core_brate, bwe_exc, Q_exc ); - + tc_dec_fx( st_fx, L_frame, exc, T0, T0_frac, i_subfr, tc_subfr, position, bwe_exc, Q_exc ); **pt_pitch = shl(add(shl(*T0,2),*T0_frac),4); move16(); /* save subframe pitch values Q6 */ @@ -155,8 +154,7 @@ void transition_dec_fx( /*-----------------------------------------------------------------* * get number of bits for pitch decoding *-----------------------------------------------------------------*/ - - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; + nBits = st_fx->acelp_cfg.pitch_bits[i_subfridx]; move16(); /*------------------------------------------------------------* @@ -379,7 +377,7 @@ void transition_dec_fx( *-----------------------------------------------------------------*/ IF( *Jopt_flag ) { - lp_filt_exc_dec_fx( st_fx, MODE1, core_brate, Opt_AMR_WB, coder_type, i_subfr, L_SUBFR, L_frame, 0, exc ); + lp_filt_exc_dec_fx(st_fx, MODE1, i_subfr, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc); } /*---------------------------------------------------------------------* @@ -482,8 +480,7 @@ void transition_dec_fx( /*-----------------------------------------------------------------* * get number of bits and index for pitch decoding *-----------------------------------------------------------------*/ - - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + nBits = st_fx->acelp_cfg.pitch_bits[i_subfridx]; move16(); index = (Word16)get_next_indice_fx( st_fx, nBits ); @@ -570,8 +567,7 @@ void transition_dec_fx( bwe_exc[i + i_subfr * 2] = bwe_exc[i + i_subfr * 2 - offset]; } - lp_filt_exc_dec_fx( st_fx, MODE1, core_brate, Opt_AMR_WB, coder_type, i_subfr, L_SUBFR, L_frame, 0, exc ); - + lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc ); *Jopt_flag = 1; move16(); } @@ -618,7 +614,6 @@ void transition_dec_fx( /* * - uses gain_trans */ /*----------------------------------------------------------------------*/ /* GLOBAL INPUT ARGUMENTS : */ -/* const Word32 core_brate, : core bitrate Q0 */ /* _ (Word16) L_frame_fx : length of the frame Q0 */ /*----------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ @@ -633,15 +628,14 @@ void transition_dec_fx( /*======================================================================*/ static void tc_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame, /* i : length of the frame */ + Decoder_State_fx *st_fx,/* i/o: decoder state structure */ + const Word16 L_frame, /* i : length of the frame */ Word16 exc[], /* o : glottal codebook contribution */ Word16 *T0, /* o : close-loop pitch period */ Word16 *T0_frac, /* o : close-loop pitch period - fractional part */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ Word16 *position, /* o : first glottal impulse position in frame */ - const Word32 core_brate, /* i : core bitrate */ Word16 bwe_exc[], /* o : excitation for SWB TBE */ Word16 *Q_exc /*i/o : scaling of excitation */ ) @@ -655,17 +649,8 @@ static void tc_dec_fx( /*----------------------------------------------------------------* * find the number of bits *----------------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) - { - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - } - + nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr,6)]; + move16(); /*----------------------------------------------------------------* * decode parameter T0 (pitch period) *----------------------------------------------------------------*/ @@ -823,16 +808,17 @@ static void tc_dec_fx( *--------------------------------------------------------------*/ pred_lt4_tc_fx( exc, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); - - IF( EQ_16(L_frame,L_FRAME)) + IF (st_fx->hBWE_TD != NULL) { - interp_code_5over2_fx(&exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); - } - ELSE - { - interp_code_4over2_fx(&exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR); + IF(EQ_16(L_frame, L_FRAME)) + { + interp_code_5over2_fx(&exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); + } + ELSE + { + interp_code_4over2_fx(&exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR); + } } - *position = add(imp_pos, i_subfr); move16(); return; @@ -845,13 +831,15 @@ static void tc_dec_fx( *-------------------------------------------------------------------*/ Word16 tc_classif_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame /* i : length of the frame */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame /* i : length of the frame */ ) { Word16 tc_subfr, indice; - - IF( EQ_16(L_frame,L_FRAME)) +#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING + MY_UNUSED_Word(L_frame); +#endif + IF( EQ_16(st_fx->L_frame_fx, L_FRAME)) { if ( get_next_indice_fx( st_fx, 1 ) ) { diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 13efe62..ef1941a 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ +#include +#include +#include "options.h" #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include /* Debug prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * updt_dec() @@ -16,8 +16,6 @@ *-------------------------------------------------------------------*/ void updt_dec_fx( Decoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ const Word16 *old_exc_fx, /* i : buffer of excitation */ const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ const Word16 Es_pred, /* i : predicited scaled innovation energy */ @@ -26,16 +24,20 @@ void updt_dec_fx( const Word16 *lsp_new_fx, /* i : current frame LSP vector */ const Word16 voice_factors[], /* i : voicing factors */ const Word16 *old_bwe_exc_fx, /* i : buffer of excitation */ - const Word16 *gain_buf /* i : Q14*/ + const Word16 *gain_buf /* i : floating pitch gain for each subframe Q14*/ ) { Word16 i, len; + HQ_DEC_HANDLE hHQ_core; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + hHQ_core = st_fx->hHQ_core; /* update old excitation buffer */ - Copy( &old_exc_fx[L_frame], st_fx->old_exc_fx, L_EXC_MEM_DEC ); - IF( !st_fx->Opt_AMR_WB_fx ) + Copy( &old_exc_fx[st_fx->L_frame_fx], st_fx->old_exc_fx, L_EXC_MEM_DEC ); + IF( !st_fx->Opt_AMR_WB_fx && hBWE_TD != NULL) { - Copy( &old_bwe_exc_fx[L_FRAME32k], st_fx->old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( &old_bwe_exc_fx[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } /* update old LSP and LSF vector */ @@ -43,26 +45,30 @@ void updt_dec_fx( Copy( lsp_new_fx, st_fx->lsp_old_fx, M ); /* update last coding type */ - st_fx->last_coder_type_fx = coder_type; + st_fx->last_coder_type_fx = st_fx->coder_type_fx; test(); test(); test(); - if( EQ_16(coder_type,INACTIVE)||(EQ_16(st_fx->bpf_off_fx,1)&&NE_16(coder_type,AUDIO)&&NE_16(coder_type,TRANSITION))) + if( EQ_16(st_fx->coder_type_fx,INACTIVE) || (EQ_16(st_fx->bpf_off_fx,1) && NE_16(st_fx->coder_type_fx,AUDIO) && NE_16(st_fx->coder_type_fx,TRANSITION))) { st_fx->last_coder_type_fx = UNVOICED; move16(); } test(); test(); - if( (NE_16(coder_type,AUDIO)||st_fx->Last_GSC_noisy_speech_flag_fx!=0)&&st_fx->Last_GSC_pit_band_idx_fx>0) + IF (st_fx->hGSCDec != NULL ) { - st_fx->Last_GSC_pit_band_idx_fx = 0; - move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ + IF ((NE_16(st_fx->coder_type_fx, AUDIO) || st_fx->Last_GSC_noisy_speech_flag_fx != 0) && st_fx->hGSCDec->Last_GSC_pit_band_idx_fx > 0) + { + st_fx->hGSCDec->Last_GSC_pit_band_idx_fx = 0; + move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ + } } + /* this ensures that st_fx->last_coder_type_fx is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ test(); - if( GT_32(st_fx->total_brate_fx,ACELP_24k40)&&EQ_16(coder_type,INACTIVE)) + if( GT_32(st_fx->total_brate_fx,ACELP_24k40) && EQ_16(st_fx->coder_type_fx,INACTIVE)) { st_fx->last_coder_type_fx = GENERIC; move16(); @@ -70,7 +76,8 @@ void updt_dec_fx( test(); test(); test(); - IF( EQ_16(st_fx->Opt_AMR_WB_fx,1)&&EQ_16(coder_type,INACTIVE)&&NE_32(st_fx->core_brate_fx,SID_1k75)&&NE_32(st_fx->core_brate_fx,FRAME_NO_DATA)) + IF( EQ_16(st_fx->Opt_AMR_WB_fx,1) && EQ_16(st_fx->coder_type_fx,INACTIVE) && + NE_32(st_fx->core_brate_fx,SID_1k75) && NE_32(st_fx->core_brate_fx,FRAME_NO_DATA)) { /* overwrite previous coding type to help FEC */ st_fx->last_coder_type_fx = UNVOICED; @@ -91,19 +98,18 @@ void updt_dec_fx( move16(); } } - test(); - IF ( coder_type != AUDIO && coder_type != INACTIVE ) + IF(st_fx->hGSCDec != NULL && st_fx->coder_type_fx != AUDIO && st_fx->coder_type_fx != INACTIVE) { - st_fx->noise_lev_fx = NOISE_LEVEL_SP3; + st_fx->hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3; move16(); - set16_fx( st_fx->old_y_gain_fx, 0, MBANDS_GN ); + set16_fx(st_fx->hGSCDec->old_y_gain_fx, 0, MBANDS_GN); - FOR( i = 0; i < L_FRAME; i++ ) + FOR(i = 0; i < L_FRAME; i++) { - Word16 tmp_seed = st_fx->seed_tcx_fx; + Word16 tmp_seed = st_fx->hGSCDec->seed_tcx_fx; move16(); - st_fx->Last_GSC_spectrum_fx[i] = shr_r(Random( &tmp_seed ),5); + st_fx->hGSCDec->Last_GSC_spectrum_fx[i] = shr_r(Random(&tmp_seed), 5); move16(); /*Q10*/ } } @@ -117,15 +123,15 @@ void updt_dec_fx( st_fx->upd_cnt_fx = s_min(st_fx->upd_cnt_fx, MAX_UPD_CNT); - len = shr(L_frame,6); + len = shr(st_fx->L_frame_fx,6); Copy32( &st_fx->old_pitch_buf_fx[len], st_fx->old_pitch_buf_fx, len ); FOR ( i = 0; i < len; i++ ) { st_fx->old_pitch_buf_fx[len+i] = L_mult0(pitch_buf_fx[i], 1<<10); move32(); } - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[L_frame/L_SUBFR+2], L_frame/L_SUBFR ); - IF (EQ_16(L_frame , L_FRAME)) + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[st_fx->L_frame_fx/L_SUBFR+2], st_fx->L_frame_fx/L_SUBFR ); + IF (EQ_16(st_fx->L_frame_fx , L_FRAME)) { st_fx->mem_pitch_gain[2] = gain_buf[3]; move16(); @@ -156,15 +162,18 @@ void updt_dec_fx( Copy( lsf_new_fx, st_fx->lsfoldbfi0_fx, M ); /* update of pitch and voicing information for HQ FEC */ - IF ( NE_16(st_fx->last_core_fx,HQ_CORE)) + IF(hHQ_core != NULL) { - st_fx->HqVoicing_fx = 1; - move16(); - test(); - if( !st_fx->Opt_AMR_WB_fx && EQ_16(coder_type,UNVOICED)) + IF(NE_16(st_fx->last_core_fx, HQ_CORE)) { - st_fx->HqVoicing_fx = 0; + hHQ_core->HqVoicing_fx = 1; move16(); + test(); + if (!st_fx->Opt_AMR_WB_fx && EQ_16(st_fx->coder_type_fx, UNVOICED)) + { + hHQ_core->HqVoicing_fx = 0; + move16(); + } } } @@ -197,6 +206,13 @@ void updt_IO_switch_dec_fx( ) { Word16 xsp_tmp[M]; + Word16 tmp_buf[MAX_LT]; + FD_BWE_DEC_HANDLE hBWE_FD; + TD_BWE_DEC_HANDLE hBWE_TD; + + hBWE_TD = st_fx->hBWE_TD; + hBWE_FD = st_fx->hBWE_FD; + IF( EQ_16(st_fx->last_core_fx,AMR_WB_CORE)) /* switching to EVS primary mode */ { /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode mode LSF(LSP) */ @@ -210,63 +226,73 @@ void updt_IO_switch_dec_fx( Copy( stable_LSP_fx, xsp_tmp, M ); /*isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M, grid100 );*/ isp2lsp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M); - - st_fx->old_enr_index_fx = s_min(shl(st_fx->old_enr_index_fx,1), 127 ); - + IF(st_fx->hTdCngDec != NULL) + { + st_fx->hTdCngDec->old_enr_index_fx = s_min(shl(st_fx->hTdCngDec->old_enr_index_fx, 1), 127); + } /* reset TD BWE buffers */ - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - st_fx->bwe_non_lin_prev_scale_fx = 0; - move16(); st_fx->last_voice_factor_fx = 0; - move16(); + IF(hBWE_TD != NULL) + { + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move16(); + move16(); - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->state_32and48k_WB_upsample_fx, st_fx->mem_resamp_HB_fx ); + wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx); + wb_tbe_extras_reset_synth_fx(hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx); + IF( GE_16(output_frame,L_FRAME32k)) + { + swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &hBWE_TD->tbe_demph_fx, &hBWE_TD->tbe_premph_fx + , hBWE_TD->mem_stp_swb_fx,&(hBWE_TD->gain_prec_swb_fx) ); + set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); + swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + } - IF( GE_16(output_frame,L_FRAME32k)) - { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &st_fx->tbe_demph_fx, &st_fx->tbe_premph_fx - ,st_fx->mem_stp_swb_fx,&(st_fx->gain_prec_swb_fx) ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); + IF( EQ_16(output_frame,L_FRAME48k)) + { + st_fx->prev_fb_ener_adjust_fx = 0; + move16(); + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + fb_tbe_reset_synth_fx(hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q,&hBWE_TD->prev_fbbwe_ratio_fx ); + } + hBWE_FD->prev_Energy_wb_fx = L_deposit_l(0); + hBWE_FD->prev_weight_fx = 6554; } + move16(); - IF( EQ_16(output_frame,L_FRAME48k)) + IF(hBWE_FD != NULL) { - st_fx->prev_fb_ener_adjust_fx = 0; + /* reset FD BWE buffers */ + hBWE_FD->prev_mode_fx = NORMAL; + move16(); + hBWE_FD->prev_Energy_fx = 0; + move16(); + hBWE_FD->prev_L_swb_norm_fx = 8; + move16(); + hBWE_FD->prev_frica_flag_fx = 0; + move16(); + set16_fx(hBWE_FD->mem_imdct_fx, 0, L_FRAME48k); + hBWE_FD->prev_td_energy_fx = 0; move16(); - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k); } - st_fx->prev_Energy_wb_fx = L_deposit_l(0); - st_fx->prev_weight_fx = 6554; - move16(); - - /* reset FD BWE buffers */ - st_fx->prev_mode_fx = NORMAL; - move16(); - st_fx->prev_Energy_fx = 0; - move16(); - st_fx->prev_L_swb_norm_fx = 8; - move16(); - st_fx->prev_frica_flag_fx = 0; - move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_td_energy_fx = 0; - move16(); - set16_fx(st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); /* HQ core buffers */ set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); /* reset the unvoiced/audio signal improvement memories */ - st_fx->seed_tcx_fx = 15687; + IF(st_fx->hGSCDec != NULL) + { + st_fx->hGSCDec->seed_tcx_fx = 15687; + } move16(); - st_fx->UV_cnt_fx = 30; + st_fx->hAmrwb_IO->UV_cnt_fx = 30; + st_fx->hAmrwb_IO->LT_UV_cnt_fx = (60<<6); + move16(); - st_fx->LT_UV_cnt_fx = (60<<6); move16(); st_fx->use_acelp_preq = 0; @@ -277,10 +303,11 @@ void updt_IO_switch_dec_fx( move16(); move16(); move16(); - if(EQ_16(st_fx->last_flag_filter_NB, 1)) + if (EQ_16(st_fx->last_flag_filter_NB, 1)) + { st_fx->cldfbSyn_fx->bandsToZero = 0; + } st_fx->last_active_bandsToZero_bwdec = 0; - st_fx->flag_NB_bwddec = 0; st_fx->perc_bwddec = 0; st_fx->last_flag_filter_NB = 0; st_fx->active_frame_cnt_bwddec = 0; @@ -301,32 +328,24 @@ void updt_IO_switch_dec_fx( Copy( stable_ISP_fx, xsp_tmp, M ); lsp2isp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M); - st_fx->old_enr_index_fx = s_max(s_min(shr(st_fx->old_enr_index_fx, 1), 63 ),0); - - - /* gain quantization memory */ - set16_fx( st_fx->past_qua_en_fx, -14*1024, GAIN_PRED_ORDER ); - + IF(st_fx->hTdCngDec != NULL) + { + st_fx->hTdCngDec->old_enr_index_fx = s_max(s_min(shr(st_fx->hTdCngDec->old_enr_index_fx, 1), 63), 0); + } + /* HF synthesis memories */ st_fx->Ng_ener_ST_fx = -51*256; /*Q8*/ move16(); - hf_synth_amr_wb_reset_fx( &st_fx->seed2_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp_interp_fx, - &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, st_fx->delay_syn_hf_fx, &st_fx->frame_count_fx, - &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, - &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, &st_fx->unvoicing_flag_fx, - &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx ); - /* reset the unvoiced/audio signal improvement memories */ - st_fx->seed_tcx_fx = 15687; - move16(); - st_fx->UV_cnt_fx = 30; - move16(); - st_fx->LT_UV_cnt_fx = 60<<6; - move16(); - st_fx->Last_ener_fx = 0; - move16(); - st_fx->lt_voice_fac_fx = 0; - move16(); + IF(st_fx->hGSCDec != NULL) + { + st_fx->hGSCDec->seed_tcx_fx = 15687; + } + + Copy(st_fx->hAmrwb_IO->lt_diff_etot_fx, tmp_buf, MAX_LT); + amr_wb_dec_init(st_fx->hAmrwb_IO); + Copy(tmp_buf, st_fx->hAmrwb_IO->lt_diff_etot_fx, MAX_LT); + hf_synth_amr_wb_reset_fx(st_fx->hBWE_zero, st_fx->hAmrwb_IO); st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); @@ -342,7 +361,10 @@ void updt_IO_switch_dec_fx( } /* CNG - reset */ - st_fx->ho_hist_size_fx = 0; + IF(st_fx->hTdCngDec != NULL) + { + st_fx->hTdCngDec->ho_hist_size_fx = 0; + } move16(); /* LSF Q memories */ @@ -391,14 +413,6 @@ void updt_bw_switching_fx( st_fx->last_inner_frame_fx = L_FRAME16k; move16(); } - - st_fx->prev_weight1_fx = 16384; - move16(); - if(EQ_16(st_fx->prev_mode_fx, HARMONIC)) - { - st_fx->prev_weight1_fx = 6554; - move16(); - } } ELSE { @@ -410,21 +424,9 @@ void updt_bw_switching_fx( st_fx->last_inner_frame_fx = inner_frame_tbl[st_fx->bwidth_fx]; move16(); } - - test(); - IF(GE_16(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME32k)||LE_32(st_fx->core_brate_fx,HQ_16k40)) - { - st_fx->prev_weight1_fx = 16384; - move16(); - test(); - if(EQ_16(st_fx->prev_hqswb_clas_fx, HQ_HARMONIC)||EQ_16(st_fx->prev_hqswb_clas_fx,HQ_HVQ)) - { - st_fx->prev_weight1_fx = 6554; - move16(); - } - } } - + st_fx->prev_bws_cnt_fx = st_fx->bws_cnt_fx; + move16(); return; } @@ -435,11 +437,19 @@ void updt_bw_switching_fx( *-------------------------------------------------------------------*/ void updt_dec_common_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 *synth /* i : decoded synthesis */ + Decoder_State_fx *st_fx, /* i/o: decoder state structure */ + Word16 hq_core_type_fx, /* i : HQ core type */ + const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ + const Word16 *synth, /* i : decoded synthesis */ + const Word16 Qpostd /* i : Synthesis Q value */ + ) { + Word16 i; + Word32 L_tmp; + + TCX_DEC_HANDLE hTcxDec; + hTcxDec = st_fx->hTcxDec; st_fx->last_codec_mode = st_fx->codec_mode; move16(); @@ -449,30 +459,36 @@ void updt_dec_common_fx( move16(); st_fx->prev_old_bfi_fx = st_fx->prev_bfi_fx; - move16(); st_fx->prev_bfi_fx = st_fx->bfi_fx; move16(); - st_fx->old_bfi_cnt_fx = st_fx->nbLostCmpt; + if (NE_16(st_fx->core_fx, AMR_WB_CORE)) + { + st_fx->old_bfi_cnt_fx = st_fx->nbLostCmpt; + move16(); + } move16(); st_fx->last_con_tcx = st_fx->con_tcx; move16(); st_fx->con_tcx = 0; move16(); - st_fx->prev_last_core_fx = st_fx->last_core_fx; - - st_fx->tcxConceal_recalc_exc = 0; - move16(); - test(); - test(); - IF( (GE_16(st_fx->rf_frame_type,RF_TCXFD)&&LE_16(st_fx->rf_frame_type,RF_TCXTD2)&&st_fx->use_partial_copy&&st_fx->bfi_fx)||!st_fx->bfi_fx) + if(st_fx->hHQ_nbfec != NULL) { - test(); - test(); - test(); - if( st_fx->bfi_fx && (LE_16(st_fx->last_good_fx, UNVOICED_TRANSITION))&&(GT_16(st_fx->clas_dec,UNVOICED_TRANSITION))&&st_fx->last_con_tcx) + st_fx->hHQ_nbfec->prev_last_core_fx = st_fx->last_core_fx; + } + if(st_fx->hTcxDec != NULL) + { + hTcxDec->tcxConceal_recalc_exc = 0; + move16(); + } + test();test(); + IF( (GE_16(st_fx->rf_frame_type,RF_TCXFD) && LE_16(st_fx->rf_frame_type,RF_TCXTD2) && st_fx->use_partial_copy && st_fx->bfi_fx) || !st_fx->bfi_fx) + { + test();test(); + test(); test(); + if( st_fx->bfi_fx && (LE_16(st_fx->last_good_fx, UNVOICED_TRANSITION)) && (GT_16(st_fx->clas_dec,UNVOICED_TRANSITION)) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL) { - st_fx->tcxConceal_recalc_exc = 1; + hTcxDec->tcxConceal_recalc_exc = 1; move16(); } st_fx->last_good_fx = st_fx->clas_dec; @@ -487,7 +503,7 @@ void updt_dec_common_fx( st_fx->prev_rf_frame_type = INACTIVE; } - if (EQ_16(st_fx->m_frame_type, ACTIVE_FRAME)&&(st_fx->bfi_fx!=1||st_fx->use_partial_copy!=0)) + if (EQ_16(st_fx->m_frame_type, ACTIVE_FRAME) && (st_fx->bfi_fx!=1 || st_fx->use_partial_copy!=0)) { st_fx->rf_flag_last = st_fx->rf_flag; } @@ -495,7 +511,7 @@ void updt_dec_common_fx( IF( EQ_16(st_fx->codec_mode,MODE1)) { test(); - if( !st_fx->bfi_fx && st_fx->core_brate_fx > SID_2k40 ) + if( !st_fx->bfi_fx && (st_fx->core_brate_fx > SID_2k40 || (GT_32(st_fx->core_brate_fx, SID_1k75) && EQ_16(st_fx->core_fx, AMR_WB_CORE)))) { move16(); st_fx->last_active_brate_fx = st_fx->total_brate_fx; @@ -504,7 +520,10 @@ void updt_dec_common_fx( move16(); move16(); st_fx->last_core_fx = st_fx->core_fx; - st_fx->last_hq_core_type_fx = hq_core_type_fx; + if (st_fx->hHQ_core != NULL) + { + st_fx->hHQ_core->last_hq_core_type_fx = hq_core_type_fx; + } } ELSE IF( EQ_16(st_fx->codec_mode,MODE2)) { @@ -534,11 +553,31 @@ void updt_dec_common_fx( st_fx->last_core_brate_fx = st_fx->core_brate_fx; /* save synthesis for core switching */ - Copy_Scale_sig( synth + NS2SA_fx2(st_fx->output_Fs_fx,ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs_fx,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS), st_fx->Q_old_postdec ); - + test(); + IF (EQ_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->core_fx, AMR_WB_CORE)) + { + Copy_Scale_sig(synth + NS2SA_fx2(st_fx->output_Fs_fx, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs_fx, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS), st_fx->hHQ_core->Q_old_postdec); + } test(); test(); test(); +#ifdef IVAS_CODE + /* Store long-term estimates of stab_fac and log energy diff to estimate env_stab in case of core switch ACELP/TCX->HQ */ + if (st->element_mode != EVS_MONO) + { + output_frame = NS2SA(st->output_Fs, FRAME_SIZE_NS); + log_energy = log2f((sum2_f(synth, output_frame) / output_frame) + 1.0f); + log_energy_diff = fabsf(st->log_energy_old - log_energy); + st->log_energy_old = log_energy; + st->log_energy_diff_lt = ENV_SMOOTH_FAC * log_energy_diff + (1.0f - ENV_SMOOTH_FAC) * st->log_energy_diff_lt; + if (st->core == HQ_CORE) + { + st->stab_fac = min(1, (STAB_FAC_EST1 + (STAB_FAC_EST2 * st->hHQ_core->mem_env_delta) + (STAB_FAC_EST3 * st->log_energy_diff_lt))); + st->stab_fac = max(0, st->stab_fac); + } + st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + (1.0f - ENV_SMOOTH_FAC) * st->stab_fac_smooth_lt; + } +#endif IF( ((LE_32(st_fx->core_brate_fx,SID_2k40))&&EQ_16(st_fx->cng_type_fx,FD_CNG)) || (st_fx->tcxonly && EQ_16(st_fx->codec_mode,MODE2)) ) @@ -546,7 +585,7 @@ void updt_dec_common_fx( { /* reset LP memories */ set16_fx( st_fx->mem_MA_fx,0, M ); - IF( EQ_32(st_fx->sr_core,16000)) + IF( EQ_32(st_fx->sr_core,INT_FS_16k)) { Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); } @@ -555,11 +594,162 @@ void updt_dec_common_fx( Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); } } + IF(EQ_16(st_fx->codec_mode, MODE2)) + { + test(); + IF(EQ_16(st_fx->use_partial_copy, 1) && EQ_16(st_fx->rf_frame_type, RF_NELP)) + { + st_fx->last_nelp_mode_dec_fx = 1; + } + ELSE + { + st_fx->last_nelp_mode_dec_fx = 0; + } + } + + st_fx->prev_use_partial_copy = st_fx->use_partial_copy; + move16(); + + st_fx->prev_tilt_code_dec_fx = 0; + move16(); + + st_fx->prev_Q_exc = st_fx->Q_exc; + move16(); + + L_tmp = L_mult(st_fx->tilt_code_dec_fx[0], 4096); + FOR(i = 1; i < NB_SUBFR; i++) + { + L_tmp = L_mac(L_tmp, st_fx->tilt_code_dec_fx[i], 4096); + } + st_fx->prev_tilt_code_dec_fx = round_fx(L_tmp); + + IF (EQ_16(st_fx->core_fx, HQ_CORE)) + { + st_fx->prev_coder_type_fx = GENERIC; + } + ELSE IF (NE_16(st_fx->core_fx, AMR_WB_CORE) ) + { + st_fx->prev_coder_type_fx = st_fx->coder_type_fx; + } + + test(); + IF((GT_32(st_fx->core_brate_fx, SID_2k40) || (GT_32(st_fx->core_brate_fx, SID_1k75) && EQ_16(st_fx->core_fx, AMR_WB_CORE))) && EQ_16(st_fx->first_CNG_fx, 1) && st_fx->hTdCngDec != NULL) + { + if (GE_16(st_fx->hTdCngDec->act_cnt_fx, BUF_DEC_RATE)) + { + st_fx->hTdCngDec->act_cnt_fx = 0; + move16(); + } + + st_fx->hTdCngDec->act_cnt_fx = add(st_fx->hTdCngDec->act_cnt_fx, 1); + + test(); + if ((EQ_16(st_fx->hTdCngDec->act_cnt_fx, BUF_DEC_RATE)) && (st_fx->hTdCngDec->ho_hist_size_fx > 0)) + { + st_fx->hTdCngDec->ho_hist_size_fx = sub(st_fx->hTdCngDec->ho_hist_size_fx, 1); + } + + st_fx->hTdCngDec->act_cnt2_fx = add(st_fx->hTdCngDec->act_cnt2_fx, 1); + if (GE_16(st_fx->hTdCngDec->act_cnt2_fx, MIN_ACT_CNG_UPD)) + { + st_fx->hTdCngDec->act_cnt2_fx = MIN_ACT_CNG_UPD; + move16(); + } + } + + test(); + test(); + if (LE_32(st_fx->core_brate_fx, SID_2k40) && st_fx->first_CNG_fx == 0 && (EQ_16(st_fx->cng_type_fx, LP_CNG) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) + { + st_fx->first_CNG_fx = 1; + move16(); + } + + /* update bandwidth switching parameters */ + test(); test(); + st_fx->last_flag_cna = st_fx->flag_cna; + move16(); + if (st_fx->hFdCngDec_fx != NULL) + { + st_fx->hFdCngDec_fx->hFdCngCom->frame_type_previous = st_fx->m_frame_type; + move16(); + } + + if (GT_16(st_fx->element_mode, EVS_MONO)) + { + st_fx->m_old_frame_type = st_fx->m_frame_type; + } + + /* update bandwidth switching parameters */ + IF ( EQ_16(st_fx->core_fx, AMR_WB_CORE)) + { + st_fx->last_bwidth_fx = WB; + + st_fx->prev_bws_cnt_fx = 0; + st_fx->bws_cnt_fx = 0; + st_fx->bws_cnt1_fx = 0; + move16();move16();move16();move16(); + + } + ELSE IF(EQ_16(st_fx->codec_mode, MODE1) && ((GT_32(st_fx->core_brate_fx, SID_2k40)) || (EQ_16(st_fx->element_mode, EVS_MONO)))) + { + updt_bw_switching_fx(st_fx, synth, Qpostd); + } + ELSE + { + st_fx->last_bwidth_fx = st_fx->bwidth_fx; + st_fx->prev_bws_cnt_fx = st_fx->bws_cnt_fx; + move32(); + move16(); + } + + /* synchronisation of CNG seeds*/ + test(); + test(); + IF(st_fx->hTdCngDec != NULL && (st_fx->bfi_fx || (NE_32(st_fx->core_brate_fx, FRAME_NO_DATA) && NE_32(st_fx->core_brate_fx, SID_2k40))) && NE_16(st_fx->core_fx, AMR_WB_CORE)) + { + Random(&(st_fx->hTdCngDec->cng_seed_fx)); + Random(&(st_fx->hTdCngDec->cng_ener_seed_fx)); + } + + test();test();test(); + IF(st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16(st_fx->core_fx, AMR_WB_CORE)) + { + /* update the parameters used in waveform adjustment */ + concealment_update2_x(synth, &st_fx->plcInfo, hTcxDec->L_frameTCX); + } + + st_fx->last_total_brate_ber_fx = st_fx->total_brate_fx; + move32(); + if (st_fx->bfi_fx == 0) + { + st_fx->last_total_brate_fx = st_fx->total_brate_fx; + st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal; + move32(); + } + st_fx->last_low_rate_mode = st_fx->low_rate_mode; move16(); + if (LT_16(st_fx->ini_frame_fx, MAX_FRAME_COUNTER)) + { + st_fx->ini_frame_fx = add(st_fx->ini_frame_fx,1); + } + return; } -void update_decoder_LPD_cng( Decoder_State_fx *st, Word16 coder_type, Word16 *timeDomainBuffer, Word16 *A, Word16 *bpf_noise_buf) +/*-------------------------------------------------------------------* + * update_decoder_LPD_cng() + * + * + *--------------------------------------------------------------------*/ + +void update_decoder_LPD_cng( + Decoder_State_fx *st, + Word16 coder_type, + Word16 *timeDomainBuffer, + Word16 *A, + Word16 *bpf_noise_buf +) { Word16 i; Word16 lsp[M], lsf[M]; @@ -568,7 +758,10 @@ void update_decoder_LPD_cng( Decoder_State_fx *st, Word16 coder_type, Word16 *ti Word16 pf_pitch[NB_SUBFR16k]; Word16 pf_gain[NB_SUBFR16k]; Word16 pitch[NB_SUBFR16k]; + TCX_DEC_HANDLE hTcxDec; + hTcxDec = st->hTcxDec; + synth = synth_buf + (1 + M); /* LPC order */ move16(); @@ -586,23 +779,25 @@ void update_decoder_LPD_cng( Decoder_State_fx *st, Word16 coder_type, Word16 *ti E_LPC_lsp_lsf_conversion( lsp, lsf, M ); } + IF(hTcxDec != NULL) + { + Copy(hTcxDec->old_synth, buf_synth, hTcxDec->old_synth_len); + Copy(timeDomainBuffer, buf_synth + hTcxDec->old_synth_len, st->L_frame_fx); - Copy( st->old_synth, buf_synth, st->old_synth_len ); - Copy( timeDomainBuffer, buf_synth+st->old_synth_len, st->L_frame_fx ); - - /* Update synth memory */ + /* Update synth memory */ - move16(); - synth = synth_buf + (1+M) ; + move16(); - Copy( st->syn, synth_buf, 1+M ); - Copy( timeDomainBuffer, synth, st->L_frame_fx ); - Copy( synth+st->L_frame_fx-(1+M), st->syn, 1+M ); - Copy( st->old_synth+st->L_frame_fx, st->old_synth, st->old_synth_len-st->L_frame_fx ); - Copy( synth, st->old_synth+st->old_synth_len-st->L_frame_fx, st->L_frame_fx ); - bufferCopyFx( synth+st->L_frame_fx-(st->L_frame_fx/2), st->old_syn_Overl, st->L_frame_fx/2,0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); + Copy(st->syn, synth_buf, 1 + M); + Copy(timeDomainBuffer, synth, st->L_frame_fx); + Copy(synth + st->L_frame_fx - (1 + M), st->syn, 1 + M); + Copy(hTcxDec->old_synth + st->L_frame_fx, hTcxDec->old_synth, hTcxDec->old_synth_len - st->L_frame_fx); + Copy(synth, hTcxDec->old_synth + hTcxDec->old_synth_len - st->L_frame_fx, st->L_frame_fx); + bufferCopyFx(synth + st->L_frame_fx - (st->L_frame_fx / 2), hTcxDec->old_syn_Overl, st->L_frame_fx / 2, 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/); - st->tcxltp_last_gain_unmodified = 0; + hTcxDec->tcxltp_last_gain_unmodified = 0; + hTcxDec->envWeighted = 0; + } /* Update pe-synth memory */ move16(); @@ -631,7 +826,6 @@ void update_decoder_LPD_cng( Decoder_State_fx *st, Word16 coder_type, Word16 *ti Copy( lsf, st->lsfold_uw, M ); move16(); move16(); - st->envWeighted = 0; Copy( A, st->old_Aq_12_8_fx, M+1 ); st->old_Es_pred_fx=0; @@ -658,8 +852,10 @@ void update_decoder_LPD_cng( Decoder_State_fx *st, Word16 coder_type, Word16 *ti /* Reset TCX overlap */ move16(); move16(); - st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; - + if (st->hTcxCfg != NULL) + { + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + } /* For BBWE and Postfilter */ Copy( A, &(st->mem_Aq[0]), M+1 ); @@ -713,26 +909,17 @@ void update_decoder_LPD_cng( Decoder_State_fx *st, Word16 coder_type, Word16 *ti -32768/*-1.f Q15*/, /* i : LTP Gain */ 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ 0/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ + st->last_core_brate_fx, /* i : bitrate of previous frame */ + -1 ); /* Postfiltering */ - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - pf_pitch[0] = pf_pitch[1] = pf_pitch[2] = pf_pitch[3] = pf_pitch[4] = L_SUBFR; - pf_gain[0] = pf_gain[1] = pf_gain[2] = pf_gain[3] = pf_gain[4] = 0; + set16_fx(pf_pitch, L_SUBFR, NB_SUBFR16k); + set16_fx(pf_gain, 0, NB_SUBFR16k); st->bpf_gain_param=0; move16(); - post_decoder( st, coder_type, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf ); + post_decoder( st, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf ); return; } diff --git a/lib_dec/vlpc_1st_dec.c b/lib_dec/vlpc_1st_dec.c index a891e83..97ef958 100644 --- a/lib_dec/vlpc_1st_dec.c +++ b/lib_dec/vlpc_1st_dec.c @@ -3,10 +3,11 @@ ====================================================================================*/ #include +#include +#include "options.h" #include "prot_fx.h" -#include "stl.h" +#include "rom_com_fx.h" -extern Word16 const dico_lsf_abs_8b[]; void vlpc_1st_dec( Word16 index, /* input: codebook index */ diff --git a/lib_dec/vlpc_2st_dec.c b/lib_dec/vlpc_2st_dec.c index 8214da5..5a19c90 100644 --- a/lib_dec/vlpc_2st_dec.c +++ b/lib_dec/vlpc_2st_dec.c @@ -2,21 +2,22 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include +#include "options.h" #include "prot_fx.h" -#include "stl.h" void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16 *indx, /* input: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ - Word32 sr_core) + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *indx, /* i : index[] (4 bits per words) */ + Word16 mode, /* i : 0=abs, >0=rel */ + Word32 sr_core /* i : internal sampling rate */ +) { Word16 i; Word16 w[M]; Word16 xq[M]; - Word16 gap; + Word16 gap; diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index b3be6fb..9c5809c 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include +#include "options.h" #include "prot_fx.h" #include "rom_com_fx.h" #include "log2.h" -#include "stl.h" /*===================================================================*/ /* FUNCTION : void ppp_voiced_decoder_fx () */ @@ -40,7 +40,7 @@ /*-------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*===================================================================*/ -void ppp_voiced_decoder_fx( +ivas_error ppp_voiced_decoder_fx( Decoder_State_fx *st_fx, /* i/o: state structure */ Word16 *out_fx, /* o : residual signal */ const Word16 *lpc2_fx, /* i : current frame LPC */ @@ -56,18 +56,35 @@ void ppp_voiced_decoder_fx( Word32 logLag,Ltemp_q,Ltemp,rem32,temp32_fx,tempnH_fx; Word16 exp,tmp; Word32 L_tmp; - - DTFS_STRUCTURE_FX *TMPDTFS_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *CURRP_Q_D_FX = DTFS_new_fx(); - - DTFS_STRUCTURE_FX *dtfs_temp_fx = DTFS_new_fx(); - + DTFS_STRUCTURE_FX* TMPDTFS_FX; + DTFS_STRUCTURE_FX* CURRP_Q_D_FX; + DTFS_STRUCTURE_FX* dtfs_temp_fx; Word16 pf_temp1[MAXLAG_WI]; /*maynot need more than MAXLAG_WI/2+1 */ Word16 pf_temp2[MAXLAG_WI]; Word16 pf_temp[MAXLAG_WI]; Word16 pf_n2[MAXLAG_WI]; Word16 S_fx[4*PIT_MAX+1], C_fx[4*PIT_MAX+1]; Word16 temp_Fs; + SC_VBR_DEC_HANDLE hSC_VBR; + + hSC_VBR = st_fx->hSC_VBR; + + ivas_error error; + + error = IVAS_ERR_OK; + + IF ((error = DTFS_new_fx(&TMPDTFS_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } + IF ((error = DTFS_new_fx(&CURRP_Q_D_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } + IF ((error = DTFS_new_fx(&dtfs_temp_fx)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } test(); IF (EQ_16(st_fx->bwidth_fx,WB)||EQ_16(st_fx->bwidth_fx,SWB)) @@ -96,31 +113,31 @@ void ppp_voiced_decoder_fx( /* Initialization */ - IF (st_fx->firstTime_voiceddec_fx) + IF (hSC_VBR->firstTime_voiceddec_fx) { - st_fx->firstTime_voiceddec_fx=0; + hSC_VBR->firstTime_voiceddec_fx=0; move16(); /* (st_fx->PREV_CW_D) = DTFS_new();*/ - st_fx->dtfs_dec_lag_fx = 0; + hSC_VBR->dtfs_dec_lag_fx = 0; move16(); - st_fx->dtfs_dec_nH_fx = 0; + hSC_VBR->dtfs_dec_nH_fx = 0; move16(); - st_fx->dtfs_dec_nH_4kHz_fx = 0; + hSC_VBR->dtfs_dec_nH_4kHz_fx = 0; move16(); - st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx = 3300; + hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx = 3300; move16(); - st_fx->dtfs_dec_upper_cut_off_freq_fx = 4000; + hSC_VBR->dtfs_dec_upper_cut_off_freq_fx = 4000; move16(); FOR(k = 0; k < MAXLAG_WI; k++) { - st_fx->dtfs_dec_a_fx[k] = 0; + hSC_VBR->dtfs_dec_a_fx[k] = 0; move16(); - st_fx->dtfs_dec_b_fx[k] = 0; + hSC_VBR->dtfs_dec_b_fx[k] = 0; move16(); } - st_fx->dtfs_dec_Q = 0; + hSC_VBR->dtfs_dec_Q = 0; move16(); } @@ -199,7 +216,7 @@ void ppp_voiced_decoder_fx( GetSinCosTab_fx(pl, S_fx, C_fx); DTFS_to_fs_fx(exc_fx-pl, pl, dtfs_temp_fx, temp_Fs, 0, S_fx, C_fx); - st_fx->ph_offset_D_fx = 0 ; + hSC_VBR->ph_offset_D_fx = 0 ; move16(); /* Copy over PREV_CW_D into TMPDTFS */ @@ -224,7 +241,7 @@ void ppp_voiced_decoder_fx( Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - st_fx->lastLgainD_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ + hSC_VBR->lastLgainD_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ @@ -234,7 +251,7 @@ void ppp_voiced_decoder_fx( Ltemp=log10_fx(Ltemp); Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - st_fx->lastHgainD_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ + hSC_VBR->lastHgainD_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ /* Need to unify the Q factors of both bands */ @@ -251,26 +268,26 @@ void ppp_voiced_decoder_fx( rshiftHarmBand_fx(TMPDTFS_FX,0, 2828, sub(Qh,Ql)); } - DTFS_to_erb_fx(*TMPDTFS_FX,st_fx->lasterbD_fx); + DTFS_to_erb_fx(*TMPDTFS_FX, hSC_VBR->lasterbD_fx); } ELSE { /* Copy DTFS related parameters from 'st' to 'dtfs_temp' structure */ - dtfs_temp_fx->lag_fx = st_fx->dtfs_dec_lag_fx; + dtfs_temp_fx->lag_fx = hSC_VBR->dtfs_dec_lag_fx; move16(); - dtfs_temp_fx->nH_fx = st_fx->dtfs_dec_nH_fx; + dtfs_temp_fx->nH_fx = hSC_VBR->dtfs_dec_nH_fx; move16(); - dtfs_temp_fx->nH_4kHz_fx = st_fx->dtfs_dec_nH_4kHz_fx; + dtfs_temp_fx->nH_4kHz_fx = hSC_VBR->dtfs_dec_nH_4kHz_fx; move16(); - dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx; + dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx; move16(); - dtfs_temp_fx->upper_cut_off_freq_fx = st_fx->dtfs_dec_upper_cut_off_freq_fx; + dtfs_temp_fx->upper_cut_off_freq_fx = hSC_VBR->dtfs_dec_upper_cut_off_freq_fx; move16(); - Copy(st_fx->dtfs_dec_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); - Copy(st_fx->dtfs_dec_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); - dtfs_temp_fx->Q = st_fx->dtfs_dec_Q; + Copy(hSC_VBR->dtfs_dec_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); + Copy(hSC_VBR->dtfs_dec_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); + dtfs_temp_fx->Q = hSC_VBR->dtfs_dec_Q; move16(); } @@ -328,36 +345,76 @@ void ppp_voiced_decoder_fx( IF ( bfi == 0 ) { - ppp_quarter_decoder_fx(CURRP_Q_D_FX,dtfs_temp_fx->lag_fx,&(st_fx->lastLgainD_fx), - &(st_fx->lastHgainD_fx),st_fx->lasterbD_fx,bfi,S_fx,C_fx,*dtfs_temp_fx, st_fx); + IF((error = ppp_quarter_decoder_fx(CURRP_Q_D_FX, dtfs_temp_fx->lag_fx, &(hSC_VBR->lastLgainD_fx), + &(hSC_VBR->lastHgainD_fx), hSC_VBR->lasterbD_fx, bfi, S_fx, C_fx, *dtfs_temp_fx, st_fx)) != IVAS_ERR_OK) + { + return error; + } } - WIsyn_fx(*dtfs_temp_fx, CURRP_Q_D_FX, lpc2_fx, &(st_fx->ph_offset_D_fx), out_fx, (Word16)L_FRAME, 0, - S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); + IF ((error = WIsyn_fx(*dtfs_temp_fx, CURRP_Q_D_FX, lpc2_fx, &(hSC_VBR->ph_offset_D_fx), out_fx, (Word16)L_FRAME, 0, + S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2)) != IVAS_ERR_OK) + { + return error; + } DTFS_copy_fx(dtfs_temp_fx, *CURRP_Q_D_FX); /* Copy DTFS related parameters from 'dtfs_temp' to 'st' structure */ - st_fx->dtfs_dec_lag_fx = dtfs_temp_fx->lag_fx; + hSC_VBR->dtfs_dec_lag_fx = dtfs_temp_fx->lag_fx; move16(); - st_fx->dtfs_dec_nH_fx = dtfs_temp_fx->nH_fx; + hSC_VBR->dtfs_dec_nH_fx = dtfs_temp_fx->nH_fx; move16(); - st_fx->dtfs_dec_nH_4kHz_fx = dtfs_temp_fx->nH_4kHz_fx; + hSC_VBR->dtfs_dec_nH_4kHz_fx = dtfs_temp_fx->nH_4kHz_fx; move16(); - st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; + hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; move16(); - st_fx->dtfs_dec_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; + hSC_VBR->dtfs_dec_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; move16(); - Copy(dtfs_temp_fx->a_fx, st_fx->dtfs_dec_a_fx, MAXLAG_WI); - Copy(dtfs_temp_fx->b_fx, st_fx->dtfs_dec_b_fx, MAXLAG_WI); + Copy(dtfs_temp_fx->a_fx, hSC_VBR->dtfs_dec_a_fx, MAXLAG_WI); + Copy(dtfs_temp_fx->b_fx, hSC_VBR->dtfs_dec_b_fx, MAXLAG_WI); - st_fx->dtfs_dec_Q = dtfs_temp_fx->Q; + hSC_VBR->dtfs_dec_Q = dtfs_temp_fx->Q; move16(); - free(TMPDTFS_FX); - free(CURRP_Q_D_FX); - free(dtfs_temp_fx); + count_free(TMPDTFS_FX); + count_free(CURRP_Q_D_FX); + count_free(dtfs_temp_fx); + + return IVAS_ERR_OK; +} +/*---------------------------------------------------------------------* +* sc_vbr_dec_init() +* +* Initialize SC-VBR decoder +*---------------------------------------------------------------------*/ +void sc_vbr_dec_init( + SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */ +) +{ + hSC_VBR->nelp_dec_seed_fx = 0; + hSC_VBR->firstTime_voiceddec_fx = 1; + + /* DTFS variables */ + set16_fx(hSC_VBR->dtfs_dec_a_fx, 0, MAXLAG_WI); + set16_fx(hSC_VBR->dtfs_dec_b_fx, 0, MAXLAG_WI); + hSC_VBR->dtfs_dec_lag_fx = 0; + hSC_VBR->dtfs_dec_nH_fx = 0; + hSC_VBR->dtfs_dec_nH_4kHz_fx = 0; + hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx = 0; + hSC_VBR->dtfs_dec_upper_cut_off_freq_fx = 0; + hSC_VBR->ph_offset_D_fx = 0; + hSC_VBR->lastLgainD_fx = 0; + hSC_VBR->lastHgainD_fx = 0; + set16_fx(hSC_VBR->lasterbD_fx, 0, NUM_ERB_WB); + + /* NELP decoder variables */ + set32_fx(hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, 14); + set16_fx(hSC_VBR->bp1_filt_mem_wb_dec_fx, 0, 8); + set16_fx(hSC_VBR->shape1_filt_mem_dec_fx, 0, 10); + set16_fx(hSC_VBR->shape2_filt_mem_dec_fx, 0, 10); + set16_fx(hSC_VBR->shape3_filt_mem_dec_fx, 0, 10); return; } diff --git a/lib_dec/voip_client.c b/lib_dec/voip_client.c index 1fc17ec..ff01cfc 100644 --- a/lib_dec/voip_client.c +++ b/lib_dec/voip_client.c @@ -142,7 +142,11 @@ Word16 decodeVoip( /* calculate the delay compensation to have the decoded signal aligned with the original input signal */ /* the number of first output samples will be reduced by this amount */ - dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx)); +#ifdef SPLIT_REND_WITH_HEAD_ROT + dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx, MONO_FORMAT, NULL, AUDIO_CONFIG_MONO)); +#else + dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx, MONO_FORMAT, NULL)); +#endif zero_pad = dec_delay; /* start WMOPS counting for decoding process only */ diff --git a/lib_dec/waveadjust_fec_dec.c b/lib_dec/waveadjust_fec_dec.c index 8cd6734..49a7c81 100644 --- a/lib_dec/waveadjust_fec_dec.c +++ b/lib_dec/waveadjust_fec_dec.c @@ -98,7 +98,7 @@ void concealment_update_x(Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 return; } -static Word16 zero_pass_w32_x(Word16 *s, Word16 N) +static Word16 zero_pass_w32_x(const Word16 *s, const Word16 N) { Word16 i; Word32 temp, zp = L_deposit_l(0); @@ -865,13 +865,13 @@ void concealment_decode_fix(Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_s } -Word16 Spl_GetScalingSquare_x(Word16 *in_vector, Word16 in_vector_length, Word16 times) +Word16 Spl_GetScalingSquare_x(const Word16 *in_vector, const Word16 in_vector_length, Word16 times) { Word16 nbits = sub(15, norm_s(times))/*Spl_GetSizeInBits_x(times)*/; Word16 i; Word16 smax = -1; Word16 sabs; - Word16 *sptr = in_vector; + const Word16 *sptr = in_vector; Word16 t; move16(); FOR (i = in_vector_length; i > 0; i--) @@ -899,7 +899,7 @@ Word16 Spl_GetScalingSquare_x(Word16 *in_vector, Word16 in_vector_length, Word16 } -Word32 Spl_Energy_x(Word16* vector, Word16 vector_length, Word16* scale_factor) +Word32 Spl_Energy_x(const Word16* vector, const Word16 vector_length, Word16* scale_factor) { Word32 en = L_deposit_l(0); Word32 i; @@ -916,7 +916,7 @@ Word32 Spl_Energy_x(Word16* vector, Word16 vector_length, Word16* scale_factor) return en; } -void Log10OfEnergy_x(Word16 *s, Word32 *enerlogval, Word16 len) +void Log10OfEnergy_x(const Word16 *s, Word32 *enerlogval, const Word16 len) { Word32 energy = L_deposit_l(0), tmp2 = L_deposit_l(0); Word16 shfts = 0; @@ -1036,7 +1036,7 @@ Word32 con_Log10(Word32 i_s32Val, Word16 i_s16Q) return s32Out; } -void concealment_update2_x(Word16 *outx_new, void *_plcInfo, Word16 FrameSize) +void concealment_update2_x(const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize) { T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; diff --git a/lib_enc/ACcontextMapping_enc.c b/lib_enc/ACcontextMapping_enc.c index c574f5f..851eff4 100644 --- a/lib_enc/ACcontextMapping_enc.c +++ b/lib_enc/ACcontextMapping_enc.c @@ -2,19 +2,20 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include #include #include "options.h" -#include "stl.h" #include "basop_util.h" -#include "stl.h" #include "cnst_fx.h" #include "prot_fx.h" #include "rom_com_fx.h" -/** +/*-------------------------------------------------------------------* + * ACcontextMapping_encode2_no_mem_s17_LC() + * + * Arithmetic encoder + *-------------------------------------------------------------------*/ + /** * \brief Arithmetic encoder * \param[i] x * \param[o] ntuples amount of encoded tuple (2 lines per tuple) @@ -23,14 +24,15 @@ * \param[i] resQMaxBits * \return none */ -Word16 ACcontextMapping_encode2_no_mem_s17_LC( - Encoder_State_fx *st, +void ACcontextMapping_encode2_no_mem_s17_LC( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ Word16 *x, Word16 nt, Word16 lastnz, Word16 nbbits, Word16 resQMaxBits, - CONTEXT_HM_CONFIG *hm_cfg) + CONTEXT_HM_CONFIG *hm_cfg +) { Word16 ptr[BITBUFSIZE]; TastatEnc as, as_overflow; @@ -156,7 +158,7 @@ Word16 ACcontextMapping_encode2_no_mem_s17_LC( /* Get context */ ctx = &c[s_or(p1, p2)]; move16(); - + /* _DIFF_FLOAT_FIX_ float is using t as UWord16 */ t = add(*ctx, rateFlag); if (GT_16(idx, nt_half)) { @@ -234,7 +236,7 @@ Word16 ACcontextMapping_encode2_no_mem_s17_LC( bp = ari_encode_14bits_ext(ptr, bp, &as, add(a1, shl(b1, A_THRES_SHIFT)), ari_pk_s17_LC_ext[pki]); /* Check bit budget */ - IF (GT_16(add(add(add(bp, extract_l(as.vobf)), nbbits_signs), nbbits_lsbs), nbbits_m2)) + IF (GT_16(add(add(add(bp, extract_l(as.value)), nbbits_signs), nbbits_lsbs), nbbits_m2)) { ari_copy_states(&as_overflow, &as); bp = bp_overflow; @@ -264,7 +266,7 @@ Word16 ACcontextMapping_encode2_no_mem_s17_LC( move16(); bp = ari_encode_14bits_ext(ptr, bp, &as, 0, ari_pk_s17_LC_ext[pki]); - IF (GT_16(add(add(add(bp, extract_l(as.vobf)), nbbits_signs), nbbits_lsbs), nbbits_m2)) + IF (GT_16(add(add(add(bp, extract_l(as.value)), nbbits_signs), nbbits_lsbs), nbbits_m2)) { ari_copy_states(&as_overflow, &as); bp = bp_overflow; @@ -332,13 +334,13 @@ Word16 ACcontextMapping_encode2_no_mem_s17_LC( /* Push number of encoded tuples */ value = sub(shr(lastnz, 1), 1); - push_next_indice_fx(st, value, nbbits_ntuples); + push_next_indice_fx(hBstr, value, nbbits_ntuples); /* Push arithmetic coded bits */ - push_next_bits_fx(st, &ptr[nbbits_ntuples], sub(bp, nbbits_ntuples)); + push_next_bits_fx(hBstr, &ptr[nbbits_ntuples], sub(bp, nbbits_ntuples)); /* Push sign bits */ - push_next_bits_fx(st, signs, nbbits_signs); + push_next_bits_fx(hBstr, signs, nbbits_signs); bp = add(bp, nbbits_signs); /*write residual Quantization bits*/ @@ -361,11 +363,15 @@ Word16 ACcontextMapping_encode2_no_mem_s17_LC( assert( bp+k <= nbbits ); /* Push the rest of the buffer */ - push_next_bits_fx(st, &ptr[bp], sub(nbbits, bp)); + push_next_bits_fx(hBstr, &ptr[bp], sub(nbbits, bp)); - return (bp+nbbits_lsbs); /*return only for debug plot*/ + return /*(bp+nbbits_lsbs)*/; /*return only for debug plot*/ } - +/*-------------------------------------------------------------------* + * find_last_nz_pair() + * + * + *-------------------------------------------------------------------*/ static Word16 find_last_nz_pair( const Word16 x[], Word16 length, @@ -431,7 +437,11 @@ static Word16 find_last_nz_pair( return s_max(last_nz, 2); } - +/*-------------------------------------------------------------------* + * ACcontextMapping_encode2_estimate_no_mem_s17_LC() + * + * + *-------------------------------------------------------------------*/ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC( const Word16 *x, Word16 nt, @@ -710,4 +720,858 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC( return nbits_old; } +#ifdef IVAS_CODE_RANGE_CODER + +/* Range Coder Functions */ + +/*-------------------------------------------------------------------* + * RCcontextMapping_encode2_no_mem_s17_LCS() + * + * Range encoder + *-------------------------------------------------------------------*/ + +void RCcontextMapping_encode2_no_mem_s17_LCS( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + int16_t* x, + const int16_t nt, + int16_t lastnz, + const int16_t nbbits, + const int16_t resQMaxBits, + CONTEXT_HM_CONFIG* hm_cfg) +{ + int16_t ptr[BITBUFSIZE]; + RangeUniEncState rc_st_enc; + int16_t bp; + int16_t rc_tot_bits; /* No. of bits returned by range coder */ + int16_t pki, lev1; + uint16_t t; + int16_t rateFlag; + int16_t value; + int16_t nbbits_ntuples, nbbits_lsbs, nbbits_signs; + int16_t* lsbs_bits; + int16_t nt_half; + int16_t signs[N_MAX]; + int16_t a1, b1, k; + + a1 = 0; /* to avoid compilation warnings */ + b1 = 0; /* to avoid compilation warnings */ + + /* Init */ + nt_half = nt >> 1; + + /* Bits for encoding the number of encoded tuples */ + nbbits_ntuples = 0; + k = 1; + while (k < nt / 2) + { + nbbits_ntuples++; + k = k << 1; + } + + t = 0; + nbbits_signs = 0; + nbbits_lsbs = 0; + + if (hm_cfg) + { + int16_t a1_i, b1_i; + int32_t c[2], * ctx; + int32_t p1, p2; + int16_t ii[2]; + int16_t idx1, idx2, idx; + int16_t numPeakIndicesOrig, numHoleIndices; + + /* Rate flag */ + if (nbbits > 400) + { + rateFlag = 2 << NBITS_CONTEXT; + } + else + { + rateFlag = 0; + } + + c[0] = c[1] = 0; + + /* mapped domain */ + numPeakIndicesOrig = hm_cfg->numPeakIndices; + hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz); + numHoleIndices = lastnz - hm_cfg->numPeakIndices; + + /* Mark hole indices beyond lastnz as pruned */ + for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + { + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; + } + + ii[0] = numPeakIndicesOrig; + ii[1] = 0; + + p1 = p2 = 0; /* to avoid compilation warnings */ + + lsbs_bits = ptr + nbbits - 1; + + /*Start Encoding*/ + /* Initialize range encoder */ + rc_uni_enc_init(&rc_st_enc); + + /*Main Loop through the 2-tuples*/ + b1_i = -1; + + for (k = 0; k < lastnz; k += 2) + { + a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg); + b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg); + + idx = min(idx1, idx2); + + /* Get context */ + ctx = &c[p1 | p2]; + + t = (uint16_t)(*ctx + rateFlag); + t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + + /* Init current 2-tuple encoding */ + a1 = (int16_t)abs(x[a1_i]); + b1 = (int16_t)abs(x[b1_i]); + + lev1 = -1; + + /*Signs encoding*/ + if (a1 > 0) + { + signs[nbbits_signs++] = ((uint16_t)x[a1_i] >> (sizeof(uint16_t) * 8 - 1)); + } + + if (b1 > 0) + { + signs[nbbits_signs++] = ((uint16_t)x[b1_i] >> (sizeof(uint16_t) * 8 - 1)); + } + + /* MSBs coding */ + while (max(a1, b1) >= A_THRES) + { + pki = ari_lookup_s17_LC[t + ((lev1 + 1) << (NBITS_CONTEXT + NBITS_RATEQ))]; + rc_uni_enc_encode_symbol_fastS(&rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode ESC symbol */ + + *lsbs_bits-- = a1 & 1; + *lsbs_bits-- = b1 & 1; + + /* LSBs bit counting */ + nbbits_lsbs += 2; + + a1 >>= 1; + b1 >>= 1; + + lev1 = min(lev1 + 1, 2); + } + + pki = ari_lookup_s17_LC[t + ((lev1 + 1) << (NBITS_CONTEXT + NBITS_RATEQ))]; + rc_uni_enc_encode_symbol_fastS(&rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode MSB symbol */ + + /*Confirm that there is no overflow, i.e. bit-budget has not exceeded */ +#ifdef DEBUGGING + assert(rc_uni_enc_virtual_finish(&rc_st_enc) <= nbbits - nbbits_signs - nbbits_lsbs - nbbits_ntuples); +#endif + + /* Update context for next 2-tuple */ + if (p1 == p2) + { + /* peak-peak or hole-hole context */ + + if (lev1 <= 0) + { + t = 1 + (a1 + b1) * (lev1 + 2); + } + else + { + t = 13 + lev1; + } + + *ctx = (*ctx & 0xf) * 16 + t; + } + else + { + /* mixed context */ + + if (idx1 & 1) + { + /* update first context */ + c[p1] = update_mixed_context(c[p1], (int16_t)abs(x[a1_i])); + } + + if (idx2 & 1) + { + /* update second context */ + c[p2] = update_mixed_context(c[p2], (int16_t)abs(x[b1_i])); + } + } + + } /*end of the 2-tuples loop*/ + } + else /* if (!hm_cfg) */ + { + int16_t cp; + int16_t esc_nb, rateQ; + uint16_t s; + + /* Rate flag */ + if (nbbits > 400) + { + rateFlag = 2; + } + else + { + rateFlag = 0; + } + + s = 0; + + /* Find last non-zero tuple */ + /* ensure termination of while loop by dummy value */ + a1 = x[0]; + x[0] = 1; /* ensure first tuple is non-zero */ + + while (x[lastnz - 1] == 0 && x[lastnz - 2] == 0) + { + lastnz -= 2; + } + x[0] = a1; + + lsbs_bits = ptr + nbbits - 1; + + /*Start Encoding*/ + /* Initialize range encoder */ + rc_uni_enc_init(&rc_st_enc); + + /*Main Loop through the 2-tuples*/ + for (k = 0; k < lastnz; k += 2) + { + + /* Init current 2-tuple encoding */ + a1 = (int16_t)abs(x[k + 0]); + b1 = (int16_t)abs(x[k + 1]); + + lev1 = 0; + esc_nb = 0; + + /*Signs encoding*/ + if (a1 > 0) + { + signs[nbbits_signs++] = ((uint16_t)x[k + 0] >> (sizeof(uint16_t) * 8 - 1)); + } + + if (b1 > 0) + { + signs[nbbits_signs++] = ((uint16_t)x[k + 1] >> (sizeof(uint16_t) * 8 - 1)); + } + + rateQ = rateFlag + (k > (nt >> 1)); + + /* MSBs coding */ + while (max(a1, b1) >= A_THRES) + { + pki = ari_lookup_s17_LC[t + ((rateQ) << NBITS_CONTEXT) + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + rc_uni_enc_encode_symbol_fastS(&rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode ESC symbol */ + + *lsbs_bits-- = a1 & 1; + *lsbs_bits-- = b1 & 1; + + /* LSBs bit counting */ + nbbits_lsbs += 2; + + a1 >>= 1; + b1 >>= 1; + + lev1++; + esc_nb = min(lev1, 3); + } + + pki = ari_lookup_s17_LC[t + ((rateQ) << NBITS_CONTEXT) + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + rc_uni_enc_encode_symbol_fastS(&rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14); /* Encode MSB symbol */ + + /*Confirm that there is no overflow, i.e. bit-budget has not exceeded */ +#ifdef DEBUGGING + assert(rc_uni_enc_virtual_finish(&rc_st_enc) <= nbbits - nbbits_signs - nbbits_lsbs - nbbits_ntuples); +#endif + + /* Update context for next 2-tuple */ + if (esc_nb < 2) + { + cp = 1 + ((a1 + b1) * (esc_nb + 1)); + } + else + { + cp = 12 + esc_nb; + } + + /*Shift old 4 bits, replace last 4 bits*/ + s = (s << 4) + cp; + t = s & 0xFF; + + } /*end of the 2-tuples loop*/ + } + + /* Finish range encoder */ + rc_tot_bits = rc_uni_enc_finish(&rc_st_enc); /* No. of bits consumed by range coder */ + bp = rc_tot_bits + nbbits_ntuples; /* Update bitstream pointer */ + + /* Cross-check that there is no overflow */ +#ifdef DEBUGGING + assert(k == lastnz); +#endif + + /* Push number of encoded tuples */ + value = (lastnz >> 1) - 1; + push_next_indice(hBstr, value, nbbits_ntuples); + + /* Push range coded bits from byte_buffer to bitstream */ + /* 1) Push all complete bytes, one byte at a time */ + for (k = 0; k < (rc_tot_bits >> 3); k++) + { + push_next_indice(hBstr, rc_st_enc.byte_buffer[k], 8); + } + /* 2) Push remaining bits */ + if ((rc_tot_bits & 7) != 0) + { + push_next_indice(hBstr, rc_st_enc.byte_buffer[k] >> (8 - (rc_tot_bits & 7)), rc_tot_bits & 7); + } + + /* Push sign bits */ + push_next_bits(hBstr, (uint16_t*)signs, nbbits_signs); + bp += nbbits_signs; + + /*write residual Quantization bits*/ + + for (k = 0; k < min(nbbits - bp - nbbits_lsbs, resQMaxBits); k++) + { + ptr[nbbits - 1 - nbbits_lsbs - k] = x[nt + k]; + } + /* Write filler bits */ + for (; k < nbbits - bp - nbbits_lsbs; ++k) + { + ptr[nbbits - 1 - nbbits_lsbs - k] = 0; + } + + /* Check for debugging */ + assert(bp + k <= nbbits); + + /* Push the rest of the buffer */ + push_next_bits(hBstr, (uint16_t*)&ptr[bp], nbbits - bp); + + /* return (bp+nbbits_lsbs);*/ /*return only for debug plot*/ + return; +} + +/*-------------------------------------------------------------------* + * RCcontextMapping_encode2_estimate_no_mem_s17_LCS() + * + * Range coder bit-estimation + *-------------------------------------------------------------------*/ + +int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( + int16_t* x, /* Spectral coefficients */ + const int16_t nt, /* L - size of spectrum (no. of spectral coefficients) */ + int16_t* lastnz_out, + int16_t* nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */ + const int16_t target, /* Target bits */ + int16_t* stop, + int16_t mode, + CONTEXT_HM_CONFIG* hm_cfg /* context-based harmonic model configuration */ +) +{ + /* Common variables */ + int16_t a1, b1; + int16_t k, pki, lev1; + uint16_t t; + int16_t lastnz, lastnz2; + int16_t rateFlag; + float bit_estimate; + int16_t symbol; + const uint8_t* lookup; + float nbits2; + + /* Initialization */ + bit_estimate = 2.0f; + nbits2 = 0.f; + + /* bits to encode lastnz */ + k = 1; + + while (k < nt / 2) + { + bit_estimate++; + k = k << 1; + /* check while condition */ + } + + nbits2 = bit_estimate; + + if (hm_cfg) + { + int16_t a1_i, b1_i; + int16_t stop2; + int16_t total_output_bits; + int16_t nt_half; + int32_t c[2], * ctx; + int32_t p1, p2; + int16_t ii[2]; + int16_t idx1, idx2, idx; + int16_t numPeakIndicesOrig = 0, numHoleIndices = 0; /* only to avoid compiler warning */ + + /* Rate flag */ + if (target > 400) + { + rateFlag = 2 << NBITS_CONTEXT; /* Select context-A for higher bitrates */ + } + else + { + rateFlag = 0; /* Select context-B for lower bitrates */ + } + + nt_half = nt >> 1; + stop2 = 0; + c[0] = c[1] = 0; + + /* Find last non-zero tuple in the mapped domain signal */ + lastnz = find_last_nz_pair(x, nt, hm_cfg); + + lastnz2 = 2; + + /* mapped domain */ + numPeakIndicesOrig = hm_cfg->numPeakIndices; + hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz); + numHoleIndices = lastnz - hm_cfg->numPeakIndices; + + /* Mark hole indices beyond lastnz as pruned */ + for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + { + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; + } + + ii[0] = numPeakIndicesOrig; + ii[1] = 0; + + p1 = p2 = 0; /* to avoid compilation warnings */ + + /* Main Loop through the 2-tuples */ + for (k = 0; k < lastnz; k += 2) + { + a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg); + b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg); + + idx = min(idx1, idx2); + + /* Get context */ + ctx = &c[p1 | p2]; + + t = (uint16_t)(*ctx + rateFlag); + t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + + /* Init current 2-tuple encoding */ + a1 = (int16_t)abs(x[a1_i]); + b1 = (int16_t)abs(x[b1_i]); + lev1 = -(1 << (NBITS_CONTEXT + NBITS_RATEQ)); + + /* Signs Bits */ + bit_estimate += min(a1, 1); + bit_estimate += min(b1, 1); + + /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ + lookup = &ari_lookup_s17_LC[t] + (1 << (NBITS_CONTEXT + NBITS_RATEQ)); + + /* check while condition */ + /* MSBs coding */ + while (max(a1, b1) >= A_THRES) + { + pki = lookup[lev1]; /* ESC symbol */ + + bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; + bit_estimate += 2; /* Add 2 LSB bits corresponding to the bit-plane */ + + (a1) >>= 1; + (b1) >>= 1; + + lev1 = min(lev1 + (1 << (NBITS_CONTEXT + NBITS_RATEQ)), 2 << (NBITS_CONTEXT + NBITS_RATEQ)); + + /* check while condition */ + } + + pki = lookup[lev1]; + + symbol = a1 + A_THRES * b1; + bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; + + /* Should we truncate? */ + if (bit_estimate > target) + { + stop2 = 1; + + if (*stop) + { + break; + } + } + else + { + lastnz2 = b1_i + 1; + nbits2 = bit_estimate; + } + + /* Update context for next 2-tuple */ + if (p1 == p2) /* peak-peak or hole-hole context */ + { + lev1 >>= NBITS_CONTEXT + NBITS_RATEQ; + + if (lev1 <= 0) + { + t = 1 + (a1 + b1) * (lev1 + 2); + } + else + { + t = 13 + lev1; + } + + *ctx = (*ctx & 0xf) * 16 + t; + } + else + { + /* mixed context */ + + if (idx1 & 1) + { + /* update first context */ + c[p1] = update_mixed_context(c[p1], (int16_t)abs(x[a1_i])); + } + + if (idx2 & 1) + { + /* update second context */ + c[p2] = update_mixed_context(c[p2], (int16_t)abs(x[b1_i])); + } + } + + } /*end of the 2-tuples loop*/ + + total_output_bits = (int16_t)(bit_estimate + 0.5f); + if (*stop) + { + total_output_bits = (int16_t)(nbits2 + 0.5f); + } + + if (stop2) + { + stop2 = total_output_bits; + } + *nEncoded = lastnz2; + *stop = stop2; /* If zero, it means no overflow occured during bit-estimation */ + *lastnz_out = lastnz; + + /* Restore hole indices beyond lastnz */ + for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k) + { + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] - nt; + } + hm_cfg->numPeakIndices = numPeakIndicesOrig; + + return (int16_t)(nbits2 + 0.5f); + } + else /* if (!hm_cfg) */ + { + int16_t esc_nb, cp, rateQ; + uint16_t s; + int16_t tot_bits2; + int16_t overflow_flag = 0; + + /* Rate flag */ + if (target > 400) + { + rateFlag = 2; + } + else + { + rateFlag = 0; /* Select context-B for lower bitrates */ + } + + t = 0; + s = 0; + cp = 0; + lastnz = 1; + lastnz2 = 0; + tot_bits2 = 0; + + /* Find last non-zero tuple in the mapped domain signal */ + for (lastnz = (nt - 2); lastnz >= 0; lastnz -= 2) + { + if ((x[lastnz] != 0) || (x[lastnz + 1] != 0)) + { + break; + } + } + lastnz += 2; + if (lastnz < 2) + { + lastnz = 2; /* At least one tuple is coded */ + } + + lastnz2 = 2; + + /* Main Loop through the 2-tuples */ + for (k = 0; k < lastnz; k += 2) + { + /* Init current 2-tuple encoding */ + a1 = (int16_t)abs(x[k]); + b1 = (int16_t)abs(x[k + 1]); + lev1 = 0; + esc_nb = 0; + rateQ = rateFlag + (k > (nt >> 1)); + + /* Signs Bits */ + bit_estimate += min(a1, 1); + bit_estimate += min(b1, 1); + + /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ + lookup = &ari_lookup_s17_LC[t + (rateQ << NBITS_CONTEXT)]; + + /* check while condition */ + /* MSBs coding */ + while (max(a1, b1) >= A_THRES) + { + pki = lookup[(esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + + bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; + bit_estimate += 2; /* Add 2 LSB bits corresponding to the bit-plane */ + + (a1) >>= 1; + (b1) >>= 1; + + lev1++; + esc_nb = min(lev1, 3); + + /* check while condition */ + } + + pki = lookup[(esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + + symbol = a1 + A_THRES * b1; + bit_estimate = bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; + + /* Should we truncate? */ + if (bit_estimate > target) /* Overflow occured */ + { + overflow_flag = 1; + } + else + { + if (abs(x[k]) || abs(x[k + 1])) /* No overflow & non-zero tuple */ + { + nbits2 = bit_estimate; + lastnz2 = k + 2; + } + } + + /* Update context for next 2-tuple */ + if (esc_nb < 2) + { + cp = 1 + (a1 + b1) * (esc_nb + 1); + } + else + { + cp = 12 + esc_nb; + } + /*shift old bits and replace last 4 bits*/ + s = (s << 4) + cp; + t = s & 0xFF; + + } /*end of the 2-tuples loop*/ + + tot_bits2 = (int16_t)(nbits2 + 0.5f); + if (lastnz2 < lastnz) /* Overflow occured because unable to code all tuples */ + { + overflow_flag = 1; + } + if (mode == -1) + { + tot_bits2 = (int16_t)(bit_estimate + 0.5f); + } + if (overflow_flag == 0) /* No overflow */ + { + *stop = 0; + } + else /* Overflow */ + { + if (*stop) + { + *stop = tot_bits2; + } + else + { + *stop = (int16_t)(bit_estimate + 0.5f); + } + } + + *lastnz_out = lastnz; + *nEncoded = lastnz2; + /* Safety mechanism to avoid overflow */ + if (lastnz2 == 2 && overflow_flag == 1) + { + for (k = 0; k < lastnz2; k++) + { + x[k] = 0; + } + } + + return tot_bits2; + } +} + +/*-------------------------------------------------------------------* + * RCcontextMapping_encode2_estimate_bandWise_start() + * + * Range coder - start bandwise bit-estimation + *-------------------------------------------------------------------*/ + +int16_t RCcontextMapping_encode2_estimate_bandWise_start( + int16_t* x, + const int16_t nt, + const int16_t target, + HANDLE_RC_CONTEXT_MEM hContextMem) +{ + int16_t i, k; + + /* Rate flag */ + if (target > 400) + { + hContextMem->rateFlag = 2 << NBITS_CONTEXT; + } + else + { + hContextMem->rateFlag = 0; + } + + hContextMem->bit_estimate = 2.0f; + + /* Init */ + hContextMem->nt_half = nt >> 1; + + /* bits to encode lastnz */ + k = 1; + + while (k < hContextMem->nt_half) + { + hContextMem->bit_estimate++; + + k = k << 1; + /* check while condition */ + } + + /* bits to encode lastnz */ + hContextMem->nbits_old = (int16_t)hContextMem->bit_estimate; + + hContextMem->ctx = 0; + hContextMem->lastnz = 2; + + /* Find last non-zero tuple */ + + for (i = nt; i >= 4; i -= 2) + { + + if (x[i - 2] != 0 || x[i - 1] != 0) + { + hContextMem->lastnz = i; + break; + } + } + + return (int16_t)hContextMem->bit_estimate; +} + +/*-------------------------------------------------------------------* + * RCcontextMapping_encode2_estimate_bandWise() + * + * Range coder - bandwise bit-estimation + *-------------------------------------------------------------------*/ + +int16_t RCcontextMapping_encode2_estimate_bandWise( + int16_t* x, + const int16_t start_line, + const int16_t end_line, + HANDLE_RC_CONTEXT_MEM hContextMem) +{ + int16_t a1, b1, a1_i, b1_i; + int16_t k, pki, lev1; + uint16_t t; + int16_t bandBits = 0; + int16_t total_output_bits; /* No. of bits after finalization */ + int16_t symbol; + const uint8_t* lookup; + int16_t idx; + + /* Main Loop through the 2-tuples */ + /*hContextMem->nt_half = end_line >> 1;*/ + for (k = start_line; k < min(hContextMem->lastnz, end_line); k += 2) + { + a1_i = k; + b1_i = k + 1; + + idx = k; + + /* Get context */ + t = hContextMem->ctx + hContextMem->rateFlag; + t += (hContextMem->nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + + /* Init current 2-tuple encoding */ + a1 = (int16_t)abs(x[a1_i]); + b1 = (int16_t)abs(x[b1_i]); + lev1 = -(1 << (NBITS_CONTEXT + NBITS_RATEQ)); + + /* Signs Bits */ + hContextMem->bit_estimate += min(a1, 1); + hContextMem->bit_estimate += min(b1, 1); + + /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ + lookup = &ari_lookup_s17_LC[t] + (1 << (NBITS_CONTEXT + NBITS_RATEQ)); + + /* check while condition */ + /* MSBs coding */ + while (max(a1, b1) >= A_THRES) + { + pki = lookup[lev1]; + hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; + hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */ + + (a1) >>= 1; + (b1) >>= 1; + + lev1 = min(lev1 + (1 << (NBITS_CONTEXT + NBITS_RATEQ)), 2 << (NBITS_CONTEXT + NBITS_RATEQ)); + /* check while condition */ + } + + pki = lookup[lev1]; + symbol = a1 + A_THRES * b1; /* MSB symbol */ + hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; + + /* Update context */ + lev1 >>= NBITS_CONTEXT + NBITS_RATEQ; + + if (lev1 <= 0) + { + t = 1 + (a1 + b1) * (lev1 + 2); + } + else + { + t = 13 + lev1; + } + + hContextMem->ctx = (hContextMem->ctx & 0xf) * 16 + t; + + } /*end of the 2-tuples loop*/ + total_output_bits = (int16_t)(hContextMem->bit_estimate + 0.5f); + + bandBits = total_output_bits - hContextMem->nbits_old; + hContextMem->nbits_old = total_output_bits; + + return bandBits; +} +#endif diff --git a/lib_enc/FEC_enc_fx.c b/lib_enc/FEC_enc_fx.c index 404dd2b..1078576 100644 --- a/lib_enc/FEC_enc_fx.c +++ b/lib_enc/FEC_enc_fx.c @@ -1,13 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - /*============================================================================*/ @@ -36,16 +34,16 @@ /* */ /*============================================================================*/ void FEC_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ const Word16 *synth, /* i : pointer to synthesized speech for E computation */ const Word16 coder_type, /* i : type of coder */ - Word16 clas, /* i : signal clas for current frame */ + Word16 clas, /* i : signal clas for current frame */ const Word16 *fpit, /* i : close loop fractional pitch buffer */ const Word16 *res, /* i : LP residual signal frame */ - Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ + Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ const Word16 L_frame, /* i : Frame length */ const Word32 total_brate, /* i : total codec bitrate */ - const Word32 core_brate, /* i : total codec bitrate */ const Word16 Q_new, /* i : input scaling */ const Word16 shift /* i : scaling to get 12bits */ ) @@ -55,7 +53,6 @@ void FEC_encode_fx( Word32 enr_q, Ltmp; Word16 enr_lg_ent, enr_lg_frac, exp_enrq; - tmpS = 0; move16(); enr_q = 1; @@ -64,7 +61,7 @@ void FEC_encode_fx( move16(); test(); test(); - IF( GT_16(coder_type,UNVOICED)&<_16(coder_type,AUDIO)&&GE_32(core_brate,ACELP_11k60)) + IF( GT_16(coder_type,UNVOICED) && LT_16(coder_type,AUDIO) && acelp_cfg.FEC_mode>0) { /*-----------------------------------------------------------------* * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits) @@ -93,14 +90,14 @@ void FEC_encode_fx( index = 3; move16(); } - push_indice_fx( st_fx, IND_FEC_CLAS, index, FEC_BITS_CLS); + push_indice_fx(hBstr, IND_FEC_CLAS, index, FEC_BITS_CLS); } /*-----------------------------------------------------------------* * encode frame energy (5 bits) *-----------------------------------------------------------------*/ test(); - IF( GE_32(total_brate,ACELP_16k40)&&NE_16(coder_type,TRANSITION)) /* GENERIC and VOICED frames */ + IF(GT_16(acelp_cfg.FEC_mode, 1)) /* GENERIC and VOICED frames */ { /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */ /*frame_ener( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, 0 );*/ @@ -117,13 +114,13 @@ void FEC_encode_fx( tmpS = s_min(tmpS, 31); tmpS = s_max(tmpS, 0); - push_indice_fx( st_fx, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); + push_indice_fx(hBstr, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); } /*-----------------------------------------------------------------* * Encode last glottal pulse position (8 bits) *-----------------------------------------------------------------*/ test(); - IF( GE_32(total_brate,ACELP_32k)&&NE_16(coder_type,TRANSITION)) /* GENERIC frames */ + IF(GT_16(acelp_cfg.FEC_mode, 2)) /* GENERIC frames */ { /* retrieve the last glottal pulse position of the previous frame */ /* use the current pitch information to scale or not the quantization */ @@ -158,7 +155,7 @@ void FEC_encode_fx( maxi = add(maxi,128);/* use 8 bits (MSB represent the sign of the pulse) */ } - push_indice_fx( st_fx, IND_FEC_POS, maxi, FEC_BITS_POS ); + push_indice_fx(hBstr, IND_FEC_POS, maxi, FEC_BITS_POS ); } maxi = 0; move16(); @@ -199,7 +196,6 @@ void FEC_encode_fx( void FEC_lsf_estim_enc_fx( Encoder_State_fx *st_fx, /* i : Encoder static memory */ - const Word16 L_frame, /* i : length of the frame */ Word16 *lsf /* o : estimated LSF vector */ ) { @@ -207,7 +203,7 @@ void FEC_lsf_estim_enc_fx( Word16 alpha, lsf_mean[M]; Word16 tmp; - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx, L_FRAME)) { Copy( UVWB_Ave_fx, lsf_mean, M ); } @@ -281,7 +277,7 @@ void FEC_lsf_estim_enc_fx( } /* check LSF stability through LSF ordering */ - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx, L_FRAME)) { reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M , INT_FS_FX); } diff --git a/lib_enc/SNR_calc.c b/lib_enc/SNR_calc.c index d40df5b..cf8f8aa 100644 --- a/lib_enc/SNR_calc.c +++ b/lib_enc/SNR_calc.c @@ -2,30 +2,32 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include - -#include "basop_util.h" +#include +#include "options.h" #include "options.h" -#include "stl.h" +#include "basop_util.h" #include "vad_basop.h" -#include "rom_enc_fx.h" #include "prot_fx.h" #include "rom_enc_fx.h" +/*-------------------------------------------------------------------* + * calc_lf_snr() + * + * + *-------------------------------------------------------------------*/ void calc_lf_snr( - Word32 *lf_snr_smooth, /*(o) smoothed lf_snr*/ - Word32 *lf_snr, /*(o) long time frequency domain - SNR calculated by l_speech_snr and l_silence_snr*/ - Word32 l_speech_snr, /*(i) sum of active frames snr */ - Word32 l_speech_snr_count, /*(i) amount of the active frame */ - Word32 l_silence_snr, /*(i) sum of the nonactive frames snr*/ - Word32 l_silence_snr_count, /*(i) amount of the nonactive frame */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index /*(i) band width index*/ + Word32 *lf_snr_smooth, /* o : smoothed lf_snr*/ + Word32 *lf_snr, /* o : long time frequency domain + SNR calculated by l_speech_snr and l_silence_snr*/ + const Word32 l_speech_snr, /* i : sum of active frames snr */ + const Word32 l_speech_snr_count, /* i : amount of the active frame */ + const Word32 l_silence_snr, /* i : sum of the nonactive frames snr*/ + const Word32 l_silence_snr_count,/* i : amount of the nonactive frame */ + const Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + const Word16 bg_energy_count, /* i : amount of the background energy frame */ + const Word16 bw_index /* i : band width index*/ ) { @@ -61,19 +63,24 @@ void calc_lf_snr( *lf_snr = l_snr; move32(); - + return; } - -void calc_lt_snr(T_CldfbVadState *st, /*(io) vad state*/ - Word32 *lt_snr_org_fp, /*(o) original long time SNR*/ - Word32 *lt_snr_fp, /*(o) long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /*(i) foreground energy sum */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word32 bg_energy, /*(i) background energy sum */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index, /*(i) band width index*/ - Word16 lt_noise_sp_center0 /*(i) long time noise spectral center by 0*/ - ) +/*-------------------------------------------------------------------* + * calc_lt_snr() + * + * + *-------------------------------------------------------------------*/ +void calc_lt_snr( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *lt_snr_org_fp, /* o : original long time SNR*/ + Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ + Word32 fg_energy, /* i : foreground energy sum */ + Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + Word32 bg_energy, /* i : background energy sum */ + Word16 bg_energy_count, /* i : amount of the background energy frame */ + Word16 bw_index, /* i : band width index*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ +) { Word16 tmp_lt_noise_sp_center; Word16 q_div1,q_div2,q_divout,q_divout1; @@ -95,16 +102,16 @@ void calc_lt_snr(T_CldfbVadState *st, /*(io) vad state*/ } div1 = MUL_F(fg_energy,bg_energy_count); - div1 = VAD_L_ADD(div1,st->fg_energy_scale, 1, 126 ,&q_div1); + div1 = VAD_L_ADD(div1,hVAD_CLDFB ->fg_energy_scale, 1, 126 ,&q_div1); div2 = MUL_F(bg_energy,fg_energy_count); - div2 = VAD_L_ADD(div2,st->bg_energy_scale, 1, 126 ,&q_div2); + div2 = VAD_L_ADD(div2,hVAD_CLDFB ->bg_energy_scale, 1, 126 ,&q_div2); if( div2 == 0 ) { div2 = 1; move32(); /* div2==0 , may occur for >30000 frames all zero input */ if(div1 != 0) { - st->bg_energy_scale = add(st->fg_energy_scale, 50); + hVAD_CLDFB ->bg_energy_scale = add(hVAD_CLDFB ->fg_energy_scale, 50); } } div2 = VAD_L_div(div1,div2,q_div1,q_div2,&q_divout); @@ -154,14 +161,18 @@ void calc_lt_snr(T_CldfbVadState *st, /*(io) vad state*/ *lt_snr_fp = lt_snr; move32(); - + return; } - +/*-------------------------------------------------------------------* + * calc_snr_flux() + * + * + *-------------------------------------------------------------------*/ void calc_snr_flux( - Word32 tsnr, /*(i) time-domain SNR*/ - Word32 *pre_snr, /*(io) time-domain SNR storage*/ - Word32 *snr_flux_fp /*(o) average tsnr*/ + Word32 tsnr, /* i : time-domain SNR*/ + Word32 *pre_snr, /* i/o: time-domain SNR storage*/ + Word32 *snr_flux_fp /* o : average tsnr*/ ) { Word32 i; @@ -189,7 +200,7 @@ void calc_snr_flux( /*calculate snr_flux*/ snr_flux = 0; - move32(); + move32(); s16MaxCoefNorm = sub(ffr_getSfWord32(pre_snr, 32), 5); FOR(i=0; i<32; i++) { @@ -206,18 +217,24 @@ void calc_snr_flux( pre_snr[i] = pre_snr[i-1]; move32(); } + return; } - -void snr_calc(T_CldfbVadState *st, /*(io) vad state*/ - Word16 sacle_sbpower, /*(i) the Scaling of sbpower*/ - Word32 *snr, /*(o) frequency domain SNR */ - Word32 *tsnr, /*(o) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word32 bandwith /*(i) band width*/ - ) +/*-------------------------------------------------------------------* + * SNR_calc() + * + * + *-------------------------------------------------------------------*/ +void snr_calc( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32 *snr, /* o : frequency domain SNR */ + Word32* tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ +) { Word32 i; Word32 tmpframe_eg,tmpsb_eg,constff,div1,div2; @@ -233,19 +250,19 @@ void snr_calc(T_CldfbVadState *st, /*(io) vad state*/ Word32 snr_tmpidx[12] = {0}; - SNR_sb_num = SNR_SUB_BAND_NUM[bandwith-CLDFBVAD_NB_ID]; - move16(); - sb_bg_energy = st->sb_bg_energy; - frame_sb_energy = st->frame_sb_energy; - t_bg_energy = st->t_bg_energy; - move32(); + SNR_sb_num = SNR_SUB_BAND_NUM[bwidth-CLDFBVAD_NB_ID]; + move16(); + sb_bg_energy = hVAD_CLDFB ->sb_bg_energy; + frame_sb_energy = hVAD_CLDFB ->frame_sb_energy; + t_bg_energy = hVAD_CLDFB ->t_bg_energy; + move32(); snr_tmp = 0; - move32(); + move32(); FOR(i=0; iframe_sb_energy_scale, CONSTfix, 44, &tmp_addQ1); - div2 = VAD_L_ADD(sb_bg_energy[i], st->sb_bg_energy_scale, CONSTfix, 44, &tmp_addQ2); + div1 = VAD_L_ADD(frame_sb_energy[i], hVAD_CLDFB ->frame_sb_energy_scale, CONSTfix, 44, &tmp_addQ1); + div2 = VAD_L_ADD(sb_bg_energy[i], hVAD_CLDFB ->sb_bg_energy_scale, CONSTfix, 44, &tmp_addQ2); tmp = VAD_L_div(div1, div2, tmp_addQ1, tmp_addQ2, &q_divout); tmp = VAD_Log2(tmp, q_divout); @@ -263,17 +280,17 @@ void snr_calc(T_CldfbVadState *st, /*(io) vad state*/ snr_tmp = L_add(snr_tmp, tmpspec_amp); } snr_tmp = L_max(0, snr_tmp); - snr_tmp = MUL_F(snr_tmp,BAND_MUL[bandwith-CLDFBVAD_NB_ID]); + snr_tmp = MUL_F(snr_tmp,BAND_MUL[bwidth-CLDFBVAD_NB_ID]); *snr = L_shr(snr_tmp,s16MaxCoefNorm); move32(); - IF(bandwith == CLDFBVAD_SWB_ID) + IF(bwidth == CLDFBVAD_SWB_ID) { IF(t_bg_energy) { minscale = norm_l(t_bg_energy); - minscale2 = sub(s_min(add(minscale,st->scale_t_bg_energy),31),1); - tmpsb_eg = L_shr(t_bg_energy,sub(st->scale_t_bg_energy,minscale2)); + minscale2 = sub(s_min(add(minscale,hVAD_CLDFB ->scale_t_bg_energy),31),1); + tmpsb_eg = L_shr(t_bg_energy,sub(hVAD_CLDFB ->scale_t_bg_energy,minscale2)); constff = L_shr(1,sub(31,minscale2)); } ELSE @@ -301,7 +318,7 @@ void snr_calc(T_CldfbVadState *st, /*(io) vad state*/ } *tsnr = VAD_Log2(tmp, minscale2); move32(); - *tsnr = L_add(*tsnr, MUL_F(*tsnr, 6226)); /* *tsnr *= 1.2; */ + *tsnr = L_add(*tsnr, MUL_F(*tsnr, 6226)); /* *tsnr *= 1.2; */ move32(); } ELSE @@ -324,8 +341,8 @@ void snr_calc(T_CldfbVadState *st, /*(io) vad state*/ IF(t_bg_energy) { minscale = norm_l(t_bg_energy); - minscale2 = sub(s_min(add(minscale,st->scale_t_bg_energy),44),1); - tmpsb_eg = L_shr(t_bg_energy,sub(st->scale_t_bg_energy,minscale2)); + minscale2 = sub(s_min(add(minscale,hVAD_CLDFB ->scale_t_bg_energy),44),1); + tmpsb_eg = L_shr(t_bg_energy,sub(hVAD_CLDFB ->scale_t_bg_energy,minscale2)); constff = L_shr(CONSTfix,sub(44,minscale2)); } ELSE @@ -340,18 +357,19 @@ void snr_calc(T_CldfbVadState *st, /*(io) vad state*/ *tsnr = VAD_Log2(tmp,q_divout); move32(); } - + return; } -Word32 construct_snr_thresh( Word16 sp_center[], /*(i) spectral center*/ - Word32 snr_flux, /*(i) snr flux*/ - Word32 lt_snr, /*(i) long time time domain snr*/ - Word32 l_snr, /*(i) long time frequency domain snr*/ - Word32 continuous_speech_num, /*(i) amount of continuous speech frames*/ - Word16 continuous_noise_num, /*(i) amount of continuous noise frames*/ - Word32 fg_energy_est_start, /*(i) whether if estimated energy*/ - Word16 bw_index /*(i) band width index*/ - ) +Word32 construct_snr_thresh( + Word16 sp_center[], /* i : spectral center*/ + Word32 snr_flux, /* i : snr flux*/ + Word32 lt_snr, /* i : long time time domain snr*/ + Word32 l_snr, /* i : long time frequency domain snr*/ + Word32 continuous_speech_num, /* i : amount of continuous speech frames*/ + Word16 continuous_noise_num, /* i : amount of continuous noise frames*/ + Word32 fg_energy_est_start, /* i : whether if estimated energy*/ + Word16 bw_index /* i : band width index*/ +) { Word32 bw_snr,tmp_snr,snr_delta,test_l_snr,tmp,div1,div2; diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index b7fb8b5..7dc1052 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -2,38 +2,31 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * acelp_core_enc() * * ACELP core encoder *--------------------------------------------------------------------*/ -void acelp_core_enc_fx( +ivas_error acelp_core_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ const Word16 inp_fx[], /* i : input signal of the current frame */ - const Word16 vad_flag_fx, const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing_fx[3], /* i : Open-loop pitch gains */ Word16 A_fx[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes*/ Word16 Aw_fx[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ const Word16 epsP_h_fx[M+1], /* i : LP prediction errors */ const Word16 epsP_l_fx[M+1], /* i : LP prediction errors */ Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ - Word16 coder_type_fx, /* i : coding type */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - Word16 vad_hover_flag_fx, - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + Word16 vad_hover_flag_fx, /* i : VAD hangover flag */ + const Word16 attack_flag, /* i : attack flag (GSC or TC) */ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ Word16 *voice_factors_fx, /* o : voicing factors */ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ @@ -41,6 +34,11 @@ void acelp_core_enc_fx( Word16 *unbits_fx, /* o : number of unused bits */ const Word16 Q_new, const Word16 shift +#ifdef ADD_LRTD + , + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif ) { Word16 nBits; /* reserved bits */ @@ -53,7 +51,7 @@ void acelp_core_enc_fx( Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ Word16 Es_pred_fx; /* predicited scaled innovation energy */ Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ - Word16 tc_subfr_fx; /* TC sub-frame indication */ + Word16 tc_subfr_fx, position; /* TC sub-frame indication */ Word16 old_bwe_exc_fx[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ Word16 *bwe_exc_fx; /* excitation for SWB TBE */ Word16 allow_cn_step_fx; @@ -64,15 +62,11 @@ void acelp_core_enc_fx( Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT/2]; Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; - Word16 T_op_fx[3]; Word16 nb_bits; Word16 indice; Word16 tmp16; Word16 enr_index; - Word16 enr, maxv, scale, att; - Word16 hi, lo; - Word16 *pt_res; - Word32 L_tmp, L_ener; + Word16 enr; Word16 tilt_code_bck_fx; Word32 gc_threshold_bck_fx; @@ -80,11 +74,33 @@ void acelp_core_enc_fx( Word16 next_force_sf_bck_fx; Word32 q_env[NUM_ENV_CNG]; Word16 sid_bw=-1; + Word16 coder_type; Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; - - - + Word16 ppp_mode, nelp_mode; + Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; + Word16* tdm_Pri_pitch_buf; + Word16 uc_two_stage_flag; + Word16 att; + + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + + ivas_error error; + + error = IVAS_ERR_OK; + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && LE_32(st_fx->core_brate_fx, SID_2k40) ) + { + /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */ + return error; + } /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ @@ -92,34 +108,35 @@ void acelp_core_enc_fx( Es_pred_fx = 0; move16(); - Copy( pitch, T_op_fx, 3 ); + coder_type = st_fx->coder_type; - /* convert pitch values to 16kHz domain */ - IF ( EQ_16(st_fx->L_frame_fx,L_FRAME16k)) - { - /*T_op[0] = (short)(T_op[0] * 1.25f + 0.5f);*/ - T_op_fx[0] = round_fx(L_mac(L_shl(T_op_fx[0],16), T_op_fx[0], 8192)); - /*T_op[1] = (short)(T_op[1] * 1.25f + 0.5f);*/ - T_op_fx[1] = round_fx(L_mac(L_shl(T_op_fx[1],16), T_op_fx[1], 8192)); - T_op_fx[2] = T_op_fx[1]; - move16(); - } exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - Copy( mem->old_exc, old_exc_fx, L_EXC_MEM ); + Copy(hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ - Copy( st_fx->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); + IF(hBWE_TD != NULL) + { + bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ + Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); + } + ELSE + { + bwe_exc_fx = NULL; + } st_fx->bpf_off_fx = 0; move16(); - test(); - IF( EQ_16(st_fx->last_core_fx,HQ_CORE)||EQ_16(st_fx->last_codec_mode,MODE2)) + test();test();test(); + IF( EQ_16(st_fx->last_core_fx,HQ_CORE) || EQ_16(st_fx->last_codec_mode,MODE2) || + EQ_16(st_fx->last_core_fx, TCX_20_CORE) || EQ_16(st_fx->last_core_fx, TCX_10_CORE) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st_fx->bpf_off_fx = 1; move16(); - st_fx->Last_frame_ener_fx = MAX_32; - move32(); + if (hGSCEnc != NULL) + { + hGSCEnc->Last_frame_ener_fx = MAX_32; + move32(); + } } /* force safety-net LSFQ in the first frames after CNG segment */ @@ -140,11 +157,13 @@ void acelp_core_enc_fx( tmp_noise_fx = 0; move16(); - tc_subfr_fx = 0; + tc_subfr_fx = -1; + move16(); + position = -1; move16(); /* SC-VBR temporary variables */ - mCb1_fx = 0; + mCb1_fx = 0; //-> to be removed move16(); pstreaklen_fx = 0; move16(); @@ -157,12 +176,51 @@ void acelp_core_enc_fx( /* channel-aware mode */ reset_rf_indices(st_fx); + /* VBR modes */ + IF (st_fx->Opt_SC_VBR_fx) + { + ppp_mode = hSC_VBR->ppp_mode_fx; + nelp_mode = hSC_VBR->nelp_mode_fx; + move16(); move16(); + + } + ELSE + { + ppp_mode = 0; + nelp_mode = 0; + move16();move16(); + } + /* TD stereo */ + test(); +#ifdef ADD_LRTD + IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1)) + { + tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; + tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; + tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; + tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf; + } + ELSE +#endif + { + tdm_lp_reuse_flag = 0; + tdm_low_rate_mode = 0; + move16(); move16(); + if (EQ_16(st_fx->element_mode, IVAS_SCE) && st_fx->low_rate_mode) + { + tdm_low_rate_mode = 1; + move16(); + } + tdm_Pitch_reuse_flag = 0; + tdm_Pri_pitch_buf = NULL; + move16(); move16(); + } /*-----------------------------------------------------------------* * ACELP@12k8 / ACELP@16k switching *-----------------------------------------------------------------*/ test(); - IF( NE_16(st_fx->last_L_frame_fx,st_fx->L_frame_fx)&&NE_16(st_fx->last_core_fx,HQ_CORE)) + IF( NE_16(st_fx->last_L_frame_fx,st_fx->L_frame_fx) && (EQ_16(st_fx->last_core_fx, ACELP_CORE) || EQ_16(st_fx->last_core_fx, AMR_WB_CORE) ) ) { /* in case of switching, do not apply BPF */ st_fx->bpf_off_fx = 1; @@ -203,10 +261,10 @@ void acelp_core_enc_fx( set16_fx( st_fx->mem_MA_fx,0, M ); /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame_fx, st_fx->last_L_frame_fx, mem->old_exc, mem->mem_syn_r,mem->mem_syn2, mem->mem_syn, ENC ); - Copy( mem->old_exc, old_exc_fx, L_EXC_MEM ); - Copy( mem->mem_syn2,st_fx->mem_syn1_fx, M ); - Copy( mem->mem_syn2, mem->mem_syn3, M ); + synth_mem_updt2( st_fx->L_frame_fx, st_fx->last_L_frame_fx, hLPDmem->old_exc, hLPDmem->mem_syn_r,hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); + Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); + Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); + Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* update Aw[] coefficients */ weight_a_subfr_fx( shr(st_fx->L_frame_fx,6), A_fx, Aw_fx, st_fx->gamma, M ); @@ -229,137 +287,84 @@ void acelp_core_enc_fx( IF( EQ_16(st_fx->cng_type_fx,LP_CNG)) { /* Run CNG post parameter update */ - cng_params_postupd_fx( st_fx->ho_circ_ptr_fx, &st_fx->cng_buf_cnt, st_fx->cng_exc2_buf, st_fx->cng_Qexc_buf, - st_fx->cng_brate_buf, st_fx->ho_env_circ_fx); + cng_params_postupd_fx(hTdCngEnc->ho_circ_ptr_fx, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, + hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx); /* encode CNG parameters */ - CNG_enc_fx( st_fx, st_fx->L_frame_fx, Aq_fx, inp_fx, ener_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, st_fx->burst_ho_cnt_fx, sub(Q_new,1), q_env, &sid_bw, st_fx->exc_mem2_fx ); + CNG_enc_fx( st_fx, Aq_fx, inp_fx, ener_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub(Q_new,1), q_env, &sid_bw); /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate_fx, st_fx->L_frame_fx, &st_fx->Enew_fx, &st_fx->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, - &st_fx->first_CNG_fx, &st_fx->cng_ener_seed_fx, bwe_exc_fx, allow_cn_step_fx, &st_fx->last_allow_cn_step_fx, sub(st_fx->prev_Q_new,1), sub(Q_new,1), st_fx->num_ho_fx, - q_env, st_fx->lp_env_fx, st_fx->old_env_fx, st_fx->exc_mem_fx, st_fx->exc_mem1_fx, &sid_bw, &st_fx->cng_ener_seed1_fx, exc3_fx, st_fx->Opt_AMR_WB_fx ); + CNG_exc_fx( st_fx->core_brate_fx, st_fx->L_frame_fx, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed_fx, exc_fx, exc2_fx, &hTdCngEnc->lp_ener_fx, st_fx->last_core_brate_fx, + &hDtxEnc->first_CNG_fx, &hTdCngEnc->cng_ener_seed_fx, bwe_exc_fx, allow_cn_step_fx, &hTdCngEnc->last_allow_cn_step_fx, sub(st_fx->prev_Q_new,1), sub(Q_new,1), hTdCngEnc->num_ho_fx, + q_env, hTdCngEnc->lp_env_fx, hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1_fx, exc3_fx, st_fx->Opt_AMR_WB_fx, st_fx->element_mode); } ELSE { - IF( EQ_32(st_fx->core_brate_fx, SID_2k40)) + test(); + IF( EQ_32(st_fx->core_brate_fx, SID_2k40) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT) ) { FdCng_encodeSID( st_fx->hFdCngEnc_fx, st_fx, st_fx->preemph_fac ); - st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; + hDtxEnc->last_CNG_L_frame_fx = st_fx->L_frame_fx; move16(); } generate_comfort_noise_enc( st_fx, Q_new, 1 ); - FdCng_exc( st_fx->hFdCngEnc_fx->hFdCngCom, &st_fx->CNG_mode_fx, st_fx->L_frame_fx, st_fx->lsp_old_fx, - st_fx->first_CNG_fx, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); + FdCng_exc( st_fx->hFdCngEnc_fx->hFdCngCom, &hDtxEnc->CNG_mode_fx, st_fx->L_frame_fx, st_fx->lsp_old_fx, + hDtxEnc->first_CNG_fx, hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); Copy( exc2_fx, exc3_fx, st_fx->L_frame_fx ); IF( EQ_32(st_fx->core_brate_fx, SID_2k40)) { - maxv = 0; - move16(); - FOR(i = 0; i < st_fx->L_frame_fx; i++) - { - maxv = s_max(maxv, abs_s(exc_fx[i])); - } - scale = norm_s(maxv); - pt_res = exc_fx; - L_ener = L_deposit_l(1); - IF( EQ_16(st_fx->L_frame_fx, L_FRAME)) - { - FOR (i=0; i<128; i++) - { - tmp16 = shl(*pt_res,scale); - L_tmp = L_mult0(tmp16, tmp16); - pt_res++; - tmp16 = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ + IF (hTdCngEnc != NULL) { - FOR (i=0; i<160; i++) - { - tmp16 = shl(*pt_res,scale); - L_tmp = L_mult0(tmp16, tmp16); - pt_res++; - tmp16 = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ - } - } + /*IVAS_CODE CNG_att is missing */ + enr = cng_energy(st_fx->element_mode, st_fx->bwidth_fx, hDtxEnc->CNG_mode_fx, /*st_fx->hTdCngEnc->CNG_att*/0, exc_fx, st_fx->L_frame_fx, Q_new); - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(30, add(hi, shl(add(Q_new, scale), 1))); /* log2 exp in Q2*(Q_new+scale) */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ + /* calculate the energy quantization index */ + enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ + enr_index = extract_l(L_shr(L_mult0(enr_index, STEP_SID_FX), 12 + 8)); /* Q0 (8+12-(8+12)) */ - /* decrease the energy in case of WB input */ - IF( NE_16(st_fx->bwidth_fx, NB)) - { - IF( EQ_16(st_fx->bwidth_fx,WB)) - { - IF( st_fx->CNG_mode_fx >= 0 ) - { - /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[st_fx->CNG_mode_fx]; - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = ENR_ATT_fx[4]; - } - } - ELSE - { - att = 384; - move16();/*Q8*/ - } - enr = sub(enr, att ); - } - - /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, STEP_SID_FX), 12+8)); /* Q0 (8+12-(8+12)) */ - - /* limit the energy quantization index */ - enr_index = s_min(enr_index, 127); - enr_index = s_max(enr_index, 0); + /* limit the energy quantization index */ + enr_index = s_min(enr_index, 127); + enr_index = s_max(enr_index, 0); - st_fx->old_enr_index_fx = enr_index; - move16(); + hTdCngEnc->old_enr_index_fx = enr_index; + move16(); + } } } - - st_fx->burst_ho_cnt_fx = 0; - + /* Reset HO counter in the first SID frame */ + if (hTdCngEnc != NULL) + { + hTdCngEnc->burst_ho_cnt_fx = 0; + move16(); + } /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc3_fx, syn1_fx, mem->mem_syn3, 1, Q_new, st_fx->Q_syn ); + syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_new, st_fx->Q_syn ); /* reset the encoder */ - CNG_reset_enc_fx( st_fx, mem, pitch_buf_fx, voice_factors_fx, 0 ); + CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 0 ); /* update st->mem_syn1 for ACELP core switching */ - Copy( mem->mem_syn3, st_fx->mem_syn1_fx, M ); + Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); /* update ACELP core synthesis filter memory */ - Copy( mem->mem_syn3, mem->mem_syn, M ); + Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn1_fx + st_fx->L_frame_fx - L_SYN_MEM, mem->mem_syn_r, L_SYN_MEM ); + Copy( syn1_fx + st_fx->L_frame_fx - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); - /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, syn1_fx, old_syn_12k8_16k_fx, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); + IF (hBWE_FD != NULL) + { + /* save and delay synthesis to be used by SWB BWE */ + save_old_syn_fx( st_fx->L_frame_fx, syn1_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); + } /* Update MODE2 core switching memory */ - tmp16 = mem->syn[M]; + tmp16 = hLPDmem->syn[M]; move16(); E_UTIL_deemph2( sub(Q_new,1), syn1_fx, st_fx->preemph_fac, st_fx->L_frame_fx, &tmp16 ); - Copy( syn1_fx+st_fx->L_frame_fx-M-1, mem->syn, M+1 ); + Copy( syn1_fx+st_fx->L_frame_fx-M-1, hLPDmem->syn, M+1 ); } @@ -369,6 +374,23 @@ void acelp_core_enc_fx( ELSE { + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + + nb_bits = 0; + st_fx->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; + move16();move16();move16(); + test(); + IF (!nelp_mode && !ppp_mode) + { + config_acelp1(ENC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_fx, st_fx->extl_brate_fx, + st_fx->L_frame_fx, st_fx->GSC_noisy_speech_fx, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, st_fx->coder_type, + tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, + tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + } + /*-----------------------------------------------------------------* * After inactive period, use the most up-to-date ISPs *-----------------------------------------------------------------*/ @@ -376,9 +398,9 @@ void acelp_core_enc_fx( test(); IF ( EQ_32(st_fx->last_core_brate_fx,FRAME_NO_DATA)||EQ_32(st_fx->last_core_brate_fx,SID_2k40)) { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); + Copy(hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx ); + lsp2lsf_fx(hDtxEnc->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx ); } /*-----------------------------------------------------------------* @@ -403,37 +425,114 @@ void acelp_core_enc_fx( *-----------------------------------------------------------------*/ /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - lsf_syn_mem_backup_fx( st_fx, &(st_fx->LPDmem), &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, + lsf_syn_mem_backup_fx( st_fx, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, lsp_new_fx, lsf_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx); - lsf_enc_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, &st_fx->stab_fac_fx, - st_fx->Nb_ACELP_frames_fx, Q_new ); + + if (!tdm_lp_reuse_flag) + { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + lsf_enc_fx(st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames_fx, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new); +#else + lsf_enc_fx(st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames_fx, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new); +#endif + } +#ifdef ADD_LRTD + else + { + const float* pt_interp_2; +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if (st->active_cnt != 1) + { + int16_t beta_index; + float lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf(lsp_new, lsf_new, M, 12800); + + Unified_weighting(&st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M); + + tdm_SCh_lsf_reuse(ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index); + + push_indice(hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS); + } +#endif + pt_interp_2 = interpol_frac_12k8; + if (tdm_low_rate_mode == 1 && st->coder_type > UNVOICED) + { + pt_interp_2 = interpol_frac2; + } +#ifndef LSF_RE_USE_SECONDARY_CHANNEL + if (st->active_cnt == 1) + { + mvr2r(lsp_new, st->lsp_old, M); + lsp2lsf(lsp_new, st->lsf_old, M, st->sr_core); + lsp2lsf(lsp_new, lsf_new, M, st->sr_core); + } +#endif + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp(st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab(lsf_new, st->lsf_old, 0, st->L_frame); + } + if (st->last_core == HQ_CORE && st->element_mode > EVS_MONO) + { + /* Prepare ACB memory from last HQ frame */ + tmpF = hLPDmem->old_exc[0]; + preemph(hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF); + mvr2r(hLPDmem->old_exc + st->L_frame - M, hLPDmem->mem_syn, M); + residu(Aq, M, hLPDmem->old_exc, old_exc, st->L_frame); + } + + if (st->last_core != ACELP_CORE && st->element_mode > EVS_MONO) + { + /* Prepare ACB memory of old_bwe_exc */ +#ifdef CR_FIX_639_HQ_ACELP_TRANSITION + if (st->L_frame == L_FRAME) + { + lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); + } + else + { + lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC); + } +#else + lerp(old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC); +#endif + } +#endif + /*---------------------------------------------------------------* * Calculation of LP residual (filtering through A[z] filter) *---------------------------------------------------------------*/ + calc_residu_fx(st_fx, inp_fx, res_fx, Aq_fx); + calculate_hangover_attenuation_gain(st_fx, &att, vad_hover_flag_fx); + v_multc_att(res_fx, att, res_fx, st_fx->L_frame_fx); - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx, vad_hover_flag_fx, vad_flag_fx ); + /*-----------------------------------------------------------------* + * Determine TC subframe classification + *-----------------------------------------------------------------*/ + + IF (EQ_16(st_fx->coder_type, TRANSITION ) ) + { + tc_classif_enc(Q_new, st_fx->L_frame_fx, &tc_subfr_fx, &position, attack_flag, st_fx->pitch_fx[0], res_fx); + + config_acelp1(ENC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_fx, st_fx->extl_brate_fx, st_fx->L_frame_fx, + -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, + tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + } /*---------------------------------------------------------------* * Calculation of prediction for scaled innovation energy * (for memory-less gain quantizer) *---------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16(coder_type_fx,UNVOICED)&&NE_16(coder_type_fx,AUDIO)&&NE_16(coder_type_fx,INACTIVE) - && !(LE_32(st_fx->core_brate_fx,ACELP_8k00) && NE_16(coder_type_fx,TRANSITION) ) ) - || (EQ_16(coder_type_fx,INACTIVE) && GE_32(st_fx->total_brate_fx,ACELP_32k) ) ) + IF(nb_bits > 0) { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type_fx, -1, -1)]; - move16(); - Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame_fx, res_fx, voicing_fx, nb_bits, 0, Q_new ); - push_indice_fx( st_fx, IND_ES_PRED, indice, nb_bits ); + Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame_fx, res_fx, st_fx->voicing_fx, nb_bits, 0, Q_new ); + push_indice_fx( st_fx->hBstr, IND_ES_PRED, indice, nb_bits ); } @@ -442,106 +541,139 @@ void acelp_core_enc_fx( *------------------------------------------------------------*/ test(); test(); - IF( st_fx->nelp_mode_fx ) +#ifdef ADD_LRTD + if (tdm_low_rate_mode) /* tdm stereo low rate mode */ + { + if (st->coder_type <= UNVOICED) + { + tdm_low_rate_enc(st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise); + } + else /* GENERIC */ + { + encod_gen_2sbfr(st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); + } + } + else +#endif + IF(hSC_VBR->nelp_mode_fx ) { /* SC-VBR - NELP frames */ - encod_nelp_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, + encod_nelp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift); } - ELSE IF( EQ_16(coder_type_fx,UNVOICED)) + ELSE IF( EQ_16(coder_type,UNVOICED)) { /* UNVOICED frames (Gauss. excitation) */ - encod_unvoiced_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, vad_flag_fx, res_fx, syn_fx, - &tmp_noise_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx,Q_new,shift ); + encod_unvoiced_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, + pitch_buf_fx, voice_factors_fx, bwe_exc_fx,Q_new,shift ); } - ELSE IF( EQ_16(coder_type_fx,TRANSITION)) + ELSE IF( EQ_16(coder_type,TRANSITION)) { - tc_subfr_fx = encod_tran_fx( st_fx, mem, st_fx->L_frame_fx, inp_fx, Aw_fx, Aq_fx, coder_type_fx, Es_pred_fx, T_op_fx, voicing_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, gsc_attack_flag_fx, unbits_fx, sharpFlag_fx, shift, Q_new ); + tc_subfr_fx = encod_tran_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, + exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr_fx, position, unbits_fx, shift, Q_new ); move16(); } - ELSE IF( st_fx->ppp_mode_fx ) + ELSE IF(hSC_VBR->ppp_mode_fx ) { - encod_ppp_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, &coder_type_fx, sharpFlag_fx, T_op_fx, voicing_fx, - res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift); + IF ((error = encod_ppp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift)) != IVAS_ERR_OK) + { + return error; + } - IF( st_fx->bump_up_fx ) /* PPP failed, bump up */ + IF(hSC_VBR->bump_up_fx ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ - lsf_syn_mem_restore_fx( st_fx, &(st_fx->LPDmem), tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, - lsp_mid_bck_fx, mCb1_fx, Bin_E_fx,Bin_E_old_fx,mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); + lsf_syn_mem_restore_fx( st_fx, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck_fx, + lsp_new_fx, lsf_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, + lsp_mid_bck_fx, mCb1_fx, Bin_E_fx,Bin_E_old_fx,mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); - /* redo LSF quantization */ - lsf_enc_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, &st_fx->stab_fac_fx, st_fx->Nb_ACELP_frames_fx, Q_new ); + /* Configure ACELP bit allocation */ + config_acelp1(ENC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_fx, st_fx->extl_brate_fx, st_fx->L_frame_fx, + -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, + st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode); + /* redo LSF quantization */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + lsf_enc_fx(st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames_fx, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new); +#else + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames_fx, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); +#endif /* recalculation of LP residual (filtering through A[z] filter) */ - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx, 0, 0 ); - st_fx->burst_ho_cnt_fx = 0; + calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx); + + hTdCngEnc->burst_ho_cnt_fx = 0; move16(); /* VOICED frames in SC-VBR when bumped up*/ - encod_gen_voic_fx( st_fx, mem, st_fx->L_frame_fx, sharpFlag_fx, inp_fx, Aw_fx, Aq_fx, coder_type_fx, Es_pred_fx, T_op_fx, voicing_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, shift, Q_new ); + encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, + exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); } } - ELSE IF( EQ_16(coder_type_fx,AUDIO)||(EQ_16(coder_type_fx,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_24k40))) + ELSE IF( EQ_16(coder_type,AUDIO)||(EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_24k40))) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ - encod_audio_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, T_op_fx, voicing_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, - gsc_attack_flag_fx, coder_type_fx, lsf_new_fx, &tmp_noise_fx, Q_new , shift); + encod_audio_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, + attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new , shift); } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - encod_gen_voic_fx( st_fx, mem, st_fx->L_frame_fx, sharpFlag_fx, inp_fx, Aw_fx, Aq_fx, coder_type_fx, Es_pred_fx, T_op_fx, voicing_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, shift, Q_new ); + encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, + exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); } /* update st->mem_syn1 for ACELP core switching */ - Copy( mem->mem_syn, st_fx->mem_syn1_fx, M ); + Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + st_fx->L_frame_fx - L_SYN_MEM, mem->mem_syn_r, L_SYN_MEM ); + Copy( syn_fx + st_fx->L_frame_fx - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, syn_fx, old_syn_12k8_16k_fx, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); - + IF (hBWE_FD != NULL) + { + save_old_syn_fx(st_fx->L_frame_fx, syn_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx); + } /*Update MODE2 core switching memory*/ Copy( syn_fx, syn1_fx, st_fx->L_frame_fx ); - E_UTIL_deemph2( sub(Q_new,1), syn1_fx, st_fx->preemph_fac, st_fx->L_frame_fx, &mem->syn[M] ); - Copy( syn1_fx+st_fx->L_frame_fx-M-1, mem->syn, M+1 ); - + E_UTIL_deemph2( sub(Q_new,1), syn1_fx, st_fx->preemph_fac, st_fx->L_frame_fx, &hLPDmem->syn[M] ); + Copy( syn1_fx+st_fx->L_frame_fx-M-1, hLPDmem->syn, M+1 ); + IF (GT_16(st_fx->element_mode, EVS_MONO) && st_fx->hTcxEnc != NULL) + { + Copy(syn1_fx + st_fx->L_frame_fx / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame_fx / 2); + } /*--------------------------------------------------------------------------------------* * Modify the excitation signal when the noise is stationary *--------------------------------------------------------------------------------------*/ - IF ( NE_16(st_fx->nelp_mode_fx,1)) + IF (!(EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && NE_16(nelp_mode, 1) && !(EQ_16(st_fx->element_mode, IVAS_SCE) && tdm_low_rate_mode)) { L_epsP[0] = L_Comp(epsP_h_fx[2],epsP_l_fx[2]); move32(); L_epsP[1] = L_Comp(epsP_h_fx[M],epsP_l_fx[M]); move32(); Copy(exc_fx, exc2_fx, st_fx->L_frame_fx); - stat_noise_uv_enc_fx( st_fx, coder_type_fx, L_epsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, Q_new ); + stat_noise_uv_enc_fx( st_fx, L_epsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag, Q_new ); } /*-----------------------------------------------------------------* * Encode supplementary information for Frame Error Concealment *-----------------------------------------------------------------*/ - FEC_encode_fx( st_fx, syn_fx, coder_type_fx, st_fx->clas_fx, pitch_buf_fx, res_fx, &st_fx->Last_pulse_pos_fx, - st_fx->L_frame_fx, st_fx->total_brate_fx, st_fx->core_brate_fx, Q_new, shift ); + FEC_encode_fx(hBstr, st_fx->acelp_cfg, syn_fx, coder_type, st_fx->clas_fx, pitch_buf_fx, res_fx, &st_fx->Last_pulse_pos_fx, + st_fx->L_frame_fx, st_fx->total_brate_fx, Q_new, shift ); - IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) - { - Copy( Aq_fx+2*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); - } - ELSE + + IF (hBWE_TD != NULL) { - Copy( Aq_fx+3*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); + IF(EQ_16(st_fx->L_frame_fx, L_FRAME)) + { + Copy(Aq_fx + 2 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + } + ELSE + { + Copy(Aq_fx + 3 * (M + 1), hBWE_TD->cur_sub_Aq_fx, (M + 1)); + } } - } /* end of active inp coding */ /*-----------------------------------------------------------------* @@ -553,27 +685,12 @@ void acelp_core_enc_fx( IF ( NE_32(st_fx->core_brate_fx,SID_2k40)&&NE_32(st_fx->core_brate_fx,FRAME_NO_DATA)&&NE_32(st_fx->core_brate_fx,PPP_NELP_2k80)) { /* reserved bits */ - test(); - test(); - IF ( EQ_16(coder_type_fx,AUDIO)||(EQ_16(coder_type_fx,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_24k40))) - { - nBits = 0; - move16(); - } - ELSE IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) - { - nBits = reserved_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type_fx, -1, TC_SUBFR2IDX_fx(tc_subfr_fx))]; - move16(); - } - ELSE - { - nBits = 0; - move16(); - } + nBits = st_fx->acelp_cfg.ubits; + WHILE( nBits > 0 ) { i = s_min(nBits, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); + push_indice_fx( st_fx->hBstr, IND_UNUSED, 0, i ); nBits = sub(nBits,i); } } @@ -582,73 +699,70 @@ void acelp_core_enc_fx( /*-----------------------------------------------------------------* * Apply non linearity in case of SWB TBE *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (EQ_16(st_fx->last_Opt_SC_VBR_fx,1)&&st_fx->Opt_SC_VBR_fx==0)||((EQ_16(st_fx->extl_fx,SWB_TBE)||EQ_16(st_fx->extl_fx,WB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE))&&NE_16(st_fx->last_extl_fx,SWB_TBE)&&NE_16(st_fx->last_extl_fx,WB_TBE)&&NE_16(st_fx->last_extl_fx,FB_TBE))) + IF(hBWE_TD != NULL) { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - IF( !st_fx->Opt_SC_VBR_fx ) - { - /* Apply a non linearity to the SHB excitation */ - non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st_fx->bwe_non_lin_prev_scale_fx, Q_new, coder_type_fx, voice_factors_fx, st_fx->L_frame_fx); - } - test(); - if ( EQ_32(st_fx->core_brate_fx,SID_2k40)||EQ_32(st_fx->core_brate_fx,FRAME_NO_DATA)) - { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - } + test(); test(); + test(); test(); + test(); test(); test(); + IF((EQ_16(st_fx->last_Opt_SC_VBR_fx, 1) && st_fx->Opt_SC_VBR_fx == 0) || ((EQ_16(st_fx->extl_fx, SWB_TBE) || EQ_16(st_fx->extl_fx, WB_TBE) || EQ_16(st_fx->extl_fx, FB_TBE)) && NE_16(st_fx->last_extl_fx, SWB_TBE) && NE_16(st_fx->last_extl_fx, WB_TBE) && NE_16(st_fx->last_extl_fx, FB_TBE))) + { + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); + } + + IF(!st_fx->Opt_SC_VBR_fx) + { + /* Apply a non linearity to the SHB excitation */ + non_linearity_fx(bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame_fx); + } + test(); + if (EQ_32(st_fx->core_brate_fx, SID_2k40) || EQ_32(st_fx->core_brate_fx, FRAME_NO_DATA)) + { + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + } + } /*-----------------------------------------------------------------* * Updates *-----------------------------------------------------------------*/ - updt_enc_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, old_exc_fx, pitch_buf_fx, - Es_pred_fx,Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); + updt_enc_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx,Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); test(); - IF( (st_fx->Opt_DTX_ON_fx != 0 ) && (GT_32(st_fx->core_brate_fx,SID_2k40))) + IF(hTdCngEnc != NULL && (st_fx->Opt_DTX_ON_fx != 0 ) && (GT_32(st_fx->core_brate_fx,SID_2k40))) { /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame_fx, &st_fx->ho_circ_ptr_fx, st_fx->ho_ener_circ_fx, - &st_fx->ho_circ_size_fx, st_fx->ho_lsp_circ_fx, Q_new, ENC, NULL, &st_fx->cng_buf_cnt, - st_fx->cng_exc2_buf, st_fx->cng_Qexc_buf, st_fx->cng_brate_buf, st_fx->last_active_brate_fx ); + cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame_fx, &hTdCngEnc->ho_circ_ptr_fx, hTdCngEnc->ho_ener_circ_fx, + &hTdCngEnc->ho_circ_size_fx, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, + hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate_fx ); IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) { /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st_fx->lsp_old16k_fx, &(st_fx->ho_lsp_circ2_fx[(st_fx->ho_circ_ptr_fx)*M]), M ); + Copy( st_fx->lsp_old16k_fx, &(hTdCngEnc->ho_lsp_circ2_fx[(hTdCngEnc->ho_circ_ptr_fx)*M]), M ); } /* Set 16k LSP flag for CNG buffer */ - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 0; + hTdCngEnc->ho_16k_lsp_fx[hTdCngEnc->ho_circ_ptr_fx] = 0; move16(); if(NE_16(st_fx->L_frame_fx, L_FRAME)) { - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 1; + hTdCngEnc->ho_16k_lsp_fx[hTdCngEnc->ho_circ_ptr_fx] = 1; move16(); } /* efficient DTX hangover control */ - IF ( GT_16(st_fx->burst_ho_cnt_fx,1)) + IF ( GT_16(hTdCngEnc->burst_ho_cnt_fx,1)) { dtx_hangover_control_fx( st_fx, lsp_new_fx ); } } /* SC-VBR update of average data rate */ - IF ( EQ_16(vad_flag_fx,1)) + IF ( EQ_16(st_fx->vad_flag,1) && (hSC_VBR != NULL) ) { - update_average_rate_fx( st_fx ); - + update_average_rate_fx(hSC_VBR, st_fx->core_brate_fx); } - return; + return error; } diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index fe42397..c33efc0 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -2,21 +2,18 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" #include "rom_com_fx.h" #include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ /*---------------------------------------------------------------------* - * Local functions + * Local function prototypes *---------------------------------------------------------------------*/ static void encod_gen_voic_core_switch_fx( Encoder_State_fx *st_fx, - LPD_state *mem, - const Word16 L_frame_fx, const Word16 inp_fx[], - const Word16 Aq_fx[], const Word16 A_fx[], const Word16 coder_type_fx, const Word16 T_op_fx[], - const Word16 voicing_fx[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); + const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], + Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); static void bwe_switch_enc_fx( Encoder_State_fx *st_fx, const Word16 *new_speech ); @@ -30,37 +27,37 @@ static Word16 dotprod_satcont(const Word16 *x, const Word16 *y, Word16 qx, Word1 void acelp_core_switch_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ - const Word16 T_op_orig[2], /* i : open-loop pitch values for quantiz. Q0 */ - const Word16 voicing[3], /* i : Open-loop pitch gains Q15 */ const Word16 A[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes Q12*/ Word16 shift, Word16 Q_new ) { - Word16 i, T_op[2]; + Word16 i, j, T_op[2]; Word16 old_exc[L_EXC], *exc; /* excitation signal buffer Qexc */ const Word16 *inp; Word32 cbrate; Word16 Aq[2*(M+1)]; + LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + + hLPDmem = st_fx->hLPDmem; /* initializations */ exc = &old_exc[L_EXC_MEM]; move16(); /* pointer to excitation signal in the current frame */ - Copy( mem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */ + Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */ Copy( st_fx->old_Aq_12_8_fx, Aq, M+1 ); Copy( st_fx->old_Aq_12_8_fx, Aq + (M+1), M+1 ); - - T_op[0] = T_op_orig[0]; + T_op[0] = st_fx->pitch_fx[0]; move16(); - T_op[1] = T_op_orig[1]; + T_op[1] = st_fx->pitch_fx[1]; move16(); /*----------------------------------------------------------------* - * set switching frame bit-rate + * set switching frame bitrate *----------------------------------------------------------------*/ IF( EQ_16(st_fx->last_L_frame_fx, L_FRAME)) /* ACELP@12k8 core */ @@ -93,7 +90,30 @@ void acelp_core_switch_enc_fx( cbrate = L_min( st_fx->core_brate_fx, ACELP_22k60 ); } } - +#ifdef FIX_I4_OL_PITCH + PMTE() + IF (EQ_16(st_fx->last_codec_mode, MODE1)) + { + /* in MODE1 T_op is at 12.8 kHz */ + IF (NE_16(st_fx->last_L_frame_fx, L_FRAME)) /* ACELP@16k core -> convert T_op to 16 kHz */ + { + T_op[0] = shr(add(round_fx(L_shl(L_mult(20480, T_op[0]), 2)), 1), 1); + move16(); + T_op[1] = shr(add(round_fx(L_shl(L_mult(20480, T_op[1]), 2)), 1), 1); + move16(); + } + } + ELSE + { + /* in MODE2 T_op is at 16 kHz */ + IF (EQ_16(st_fx->last_L_frame_fx, L_FRAME)) /* ACELP@12.8k core -> convert T_op to 12.8 kHz */ + { + move16();move16(); + T_op[0] = mult_r(26214, T_op[0]); + T_op[1] = mult_r(26214, T_op[1]); + } + } +#else IF( NE_16(st_fx->last_L_frame_fx, L_FRAME) ) { T_op[0] = shr(add(round_fx(L_shl(L_mult(20480, T_op[0]), 2)), 1), 1); @@ -101,27 +121,40 @@ void acelp_core_switch_enc_fx( T_op[1] = shr(add(round_fx(L_shl(L_mult(20480, T_op[1]), 2)), 1), 1); move16(); } - +#endif /*----------------------------------------------------------------* * Excitation encoding *----------------------------------------------------------------*/ + config_acelp1(ENC, st_fx->total_brate_fx, cbrate, st_fx->core_fx, -1, -1, st_fx->last_L_frame_fx, -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, + GENERIC, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/); - encod_gen_voic_core_switch_fx( st_fx, mem, st_fx->last_L_frame_fx, inp, Aq, A, GENERIC, T_op, voicing, exc, cbrate, shift, Q_new ); + encod_gen_voic_core_switch_fx( st_fx, st_fx->last_L_frame_fx, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); /*----------------------------------------------------------------* * bit-stream: modify the layer of sub frame CELP *----------------------------------------------------------------*/ - +#ifdef IVAS_CODE_BITSTREAM + i = find_indice(hBstr, TAG_ACELP_SUBFR_LOOP_START, &value, &nb_bits); +#ifdef DEBUGGING + assert(i >= 0 && "Internal error in ACELP core switching - unable to find ACELP subframe indices!"); +#endif + while (hBstr->ind_list[i].id == TAG_ACELP_SUBFR_LOOP_START) + { + push_indice(hBstr, IND_CORE_SWITCHING_CELP_SUBFRAME, hBstr->ind_list[i].value, hBstr->ind_list[i].nb_bits); + i++; + } + delete_indice(hBstr, TAG_ACELP_SUBFR_LOOP_START); +#else FOR( i=0; i<20; i++ ) { - st_fx->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].value=st_fx->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].value; + hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].value= hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].value; move16(); - st_fx->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].nb_bits=st_fx->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits; + hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].nb_bits= hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits; move16(); - st_fx->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits=-1; + hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits=-1; move16(); } - +#endif /*----------------------------------------------------------------* * BWE encoding *----------------------------------------------------------------*/ @@ -144,16 +177,13 @@ void acelp_core_switch_enc_fx( static void encod_gen_voic_core_switch_fx( Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, const Word16 L_frame, /* i : length of the frame */ const Word16 inp[], /* i : input signal */ const Word16 Aq[], /* i : LP coefficients */ const Word16 A[], /* i : unquantized A(z) filter */ - const Word16 coder_type, /* i : coding type */ const Word16 T_op[], /* i : open loop pitch */ - const Word16 voicing[], /* i : voicing */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - const Word32 core_bitrate, /* i : switching frame bit-rate */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + const Word32 core_bitrate, /* i : switching frame bitrate */ Word16 shift, Word16 Q_new ) @@ -185,8 +215,16 @@ static void encod_gen_voic_core_switch_fx( Word16 pitch_limit_flag; Word32 L_tmp, Lgcode; Word16 shift_wsp; - Word16 h2[L_SUBFR+(M+1)]; + Word16 h2[L_SUBFR + (M + 1)]; + Word16 dummyF[NB_SUBFR16k]; Word16 lp_select, lp_flag; + LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ + BSTR_ENC_HANDLE hBstr; + + hLPDmem = st_fx->hLPDmem; + hBstr = st_fx->hBstr; + + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; /*------------------------------------------------------------------* * Initializations @@ -220,8 +258,9 @@ static void encod_gen_voic_core_switch_fx( move16(); st_fx->L_frame_fx=L_SUBFR; move16(); - calc_residu_fx(st_fx, inp, res, Aq, 0, 0); - st_fx->burst_ho_cnt_fx = 0; + calc_residu_fx(st_fx, inp, res, Aq); + + hTdCngEnc->burst_ho_cnt_fx = 0; move16(); st_fx->L_frame_fx=tmp16; move16(); @@ -236,12 +275,12 @@ static void encod_gen_voic_core_switch_fx( IF( EQ_16(L_frame,L_FRAME16k)) { weight_a_fx( A, Ap, GAMMA16k, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_fx(inp, mem->mem_syn, 0, &mem->mem_w0, Aq, res, L_SUBFR, Ap, PREEMPH_FAC_16k, xn, cn, h1); + find_targets_fx(inp, hLPDmem->mem_syn, 0, &(hLPDmem->mem_w0), Aq, res, L_SUBFR, Ap, PREEMPH_FAC_16k, xn, cn, h1); } ELSE { weight_a_fx( A, Ap, GAMMA1, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_fx(inp, mem->mem_syn,0,&mem->mem_w0, Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn ,h1); + find_targets_fx(inp, hLPDmem->mem_syn,0,&(hLPDmem->mem_w0), Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn ,h1); } /*Scale_sig(h1, L_SUBFR, shift); *//*Q14-shift */ @@ -255,9 +294,10 @@ static void encod_gen_voic_core_switch_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ - - pitch = pit_encode_fx( st_fx, core_bitrate, 0, L_frame, coder_type, &pitch_limit_flag, - 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn ); + set16_fx(dummyF, -1, NB_SUBFR16k); /* hack to signal ACELP->HQ switching frame */ + pitch = pit_encode_fx(hBstr, + st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn + , 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/); /*-----------------------------------------------------------------* * Find adaptive exitation @@ -270,46 +310,46 @@ static void encod_gen_voic_core_switch_fx( * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = gp_clip_fx( core_bitrate, voicing, 0, coder_type, xn, st_fx->clip_var_fx, sub(shift_wsp, 1) ); + clip_gain = gp_clip_fx(st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub(shift_wsp, 1) ); /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ - - lp_select = lp_filt_exc_enc_fx( MODE1, core_bitrate, 0, coder_type, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); + lp_flag = st_fx->acelp_cfg.ltf_mode; + lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); IF( EQ_16(lp_flag,NORMAL_OPERATION)) { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ - inov_encode_fx( st_fx, core_bitrate, 0, L_frame,st_fx->last_L_frame_fx, coder_type, st_fx->bwidth_fx, 0, 0, -1, Aq, gain_pit, cn, exc, - h2, mem->tilt_code, pitch, xn2, code, y2, &unbits,shift); + inov_encode_fx( st_fx, core_bitrate, 0, L_frame,st_fx->last_L_frame_fx, GENERIC, st_fx->bwidth_fx, 0, 0, -1, Aq, gain_pit, cn, exc, + h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ IF( EQ_16(L_frame,L_FRAME)) { - gain_enc_mless_fx( st_fx,core_bitrate, L_frame, TRANSITION, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, + gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } ELSE { - gain_enc_mless_fx( st_fx,core_bitrate, L_frame, coder_type, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, + gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } - gp_clip_test_gain_pit_fx( core_bitrate, gain_pit, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx(st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx ); Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx(Lgcode); - mem->tilt_code = Est_tilt2( exc+0, gain_pit, code, gain_code, &voice_fac,shift ); + hLPDmem->tilt_code = Est_tilt2( exc+0, gain_pit, code, gain_code, &voice_fac,shift ); /*-----------------------------------------------------------------* * Construct adaptive part of the excitation @@ -328,7 +368,7 @@ static void encod_gen_voic_core_switch_fx( /* write reserved bits */ IF( unbits ) { - push_indice_fx(st_fx, IND_UNUSED, 0, unbits ); + push_indice_fx(hBstr, IND_UNUSED, 0, unbits ); } /*-----------------------------------------------------------------* @@ -370,8 +410,10 @@ static void bwe_switch_enc_fx( Word32 L_tmp1, L_tmp2, L_tmp3, min_sq_cross_fx; Word16 accA_fx, accB_fx, min_corr_fx, E1_fx, E2_fx, gain_fx; Word16 synth_subfr_bwe_fx[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ - Word16 n, L; + BSTR_ENC_HANDLE hBstr; + + hBstr = st_fx->hBstr; L = NS2SA_fx2(st_fx->input_Fs_fx,FRAME_SIZE_NS); /* set multiplication factor according to the sampling rate */ @@ -458,7 +500,7 @@ static void bwe_switch_enc_fx( } } - push_indice_fx(st_fx, IND_CORE_SWITCHING_AUDIO_DELAY, d1m_fx, AUDIODELAYBITS ); + push_indice_fx(hBstr, IND_CORE_SWITCHING_AUDIO_DELAY, d1m_fx, AUDIODELAYBITS ); tmp = add(i_mult2(d1m_fx,delta_fx),fdelay_fx); ptmp = &hb_synth_tmp_fx[tmp]; @@ -486,7 +528,7 @@ static void bwe_switch_enc_fx( gain_fx = round_fx(Isqrt(L_tmp1)); /*Q12 */ ind1_fx = usquant_fx( gain_fx, &gain_fx, shr(MINVALUEOFFIRSTGAIN_FX,1), shr(DELTAOFFIRSTGAIN_FX,4), (1 << NOOFGAINBITS1) ); - push_indice_fx( st_fx,IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); + push_indice_fx(hBstr,IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); return; } diff --git a/lib_enc/acelp_enc_util.c b/lib_enc/acelp_enc_util.c index bfd1bfb..4213e39 100644 --- a/lib_enc/acelp_enc_util.c +++ b/lib_enc/acelp_enc_util.c @@ -3,14 +3,12 @@ ====================================================================================*/ -#include +#include #include -#include "stl.h" +#include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "options.h" #include "cnst_fx.h" -#include "stl.h" #include "rom_com_fx.h" #include "rom_enc_fx.h" @@ -31,7 +29,13 @@ * d = toeplitz(R)*c * Vector length is L_SUBFR */ -Word16 E_ACELP_toeplitz_mul(const Word16 R[], const Word16 c[], Word16 d[], const Word16 L_subfr, const Word16 highrate) +Word16 E_ACELP_toeplitz_mul( + const Word16 R[], + const Word16 c[], + Word16 d[], + const Word16 L_subfr, + const Word16 highrate +) { static const Word16 step = 4; Word16 k, j, i; diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index bc10a23..e4418db 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -2,14 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required by wmc_tool */ #include "basop_util.h" /*-------------------------------------------------------------------* @@ -37,12 +35,8 @@ void amr_wb_enc_fx( Word16 corr_shift; /* correlation shift */ Word16 relE; /* frame relative energy */ Word16 cor_map_sum, sp_div; - Word16 vad_flag; - Word16 localVAD; Word16 Etot; /* total energy */ Word32 ener = 0; /* residual energy from Levinson-Durbin */ - Word16 pitch[3]; /* open-loop pitch values */ - Word16 voicing[3]; /* open-loop pitch gains */ Word16 A[NB_SUBFR*(M+1)]; /* A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR*(M+1)]; /* A(z) unquantized for the 4 subframes */ Word16 vad_hover_flag, noisy_speech_HO, clean_speech_HO, NB_speech_HO; @@ -64,7 +58,6 @@ void amr_wb_enc_fx( Word16 high_lpn_flag; Word16 localVAD_HE_SAD; Word16 vad_flag_dtx; - Word16 coder_type; Word16 hf_gain_fx[NB_SUBFR]; Word16 Q_new, Q_exp,Q_r[2]; Word16 excitation_max_test, shift; @@ -78,6 +71,16 @@ void amr_wb_enc_fx( Word16 exc3[L_FRAME]; Word32 lp_bckr, hp_bckr, Ltmp; Word16 tmp, e_tmp; + Word16 old_pitch1; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; + VAD_HANDLE hVAD = st->hVAD; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + LPD_state_HANDLE hLPDmem = st->hLPDmem; + GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; + AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD; /*------------------------------------------------------------------* * Initialization @@ -95,7 +98,7 @@ void amr_wb_enc_fx( move16(); st->bwidth_fx = st->last_bwidth_fx; move16(); - coder_type = GENERIC; + st->coder_type = GENERIC; move16(); input_frame = st->input_frame_fx; move16(); /* frame length of the input signal */ @@ -122,13 +125,13 @@ void amr_wb_enc_fx( /* Updates in case of HQ -> AMR-WB IO mode switching */ Q_new = 0; move16(); /* prevent compiler warning only*/ - core_switching_pre_enc_fx( st,&(st->LPDmem), NULL, NULL ); + core_switching_pre_enc_fx( st, NULL, NULL, 0, 0 ); set16_fx( hf_gain_fx, 0, NB_SUBFR ); set16_fx( old_inp, 0, L_INP_12k8 ); exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - Copy( st->LPDmem.old_exc, old_exc, L_EXC_MEM ); + Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); new_inp = old_inp + L_INP_MEM; /* pointer to new samples of the input signal */ inp = new_inp - L_LOOK_12k8; /* pointer to current frame of input signal */ @@ -145,7 +148,7 @@ void amr_wb_enc_fx( test(); IF( EQ_32(st->total_brate_fx,ACELP_23k85)&&NE_32(st->last_core_brate_fx,ACELP_23k85)) { - hf_cod_init_fx( st->mem_hp400_enc_fx, st->mem_hf_enc_fx, st->mem_syn_hf_enc_fx, st->mem_hf2_enc_fx, &st->gain_alpha_fx ); + hf_cod_init_fx(hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, &hAmrwb_IO->gain_alpha_fx ); } /*----------------------------------------------------------------* @@ -193,10 +196,11 @@ void amr_wb_enc_fx( set16_fx( st->mem_MA_fx,0, M ); /* update synthesis filter memories */ - synth_mem_updt2( L_FRAME, st->last_L_frame_fx, st->LPDmem.old_exc, st->LPDmem.mem_syn_r, st->mem_syn1_fx, st->LPDmem.mem_syn, ENC ); - Copy( st->LPDmem.old_exc, old_exc, L_EXC_MEM ); - Copy( st->mem_syn1_fx, st->LPDmem.mem_syn2, M ); - Copy( st->LPDmem.mem_syn2, st->LPDmem.mem_syn3, M ); + synth_mem_updt2(L_FRAME, st->last_L_frame_fx, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC); + Copy(hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M); + + Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); + Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* lsp -> isp */ Copy( stable_ISP_fx, isp_tmp, M ); @@ -265,13 +269,13 @@ void amr_wb_enc_fx( st->Q_old = Q_new; move16(); - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, &Q_new, old_inp, &(st->mem_wsp_fx), st->enrO_fx, st->bckr_fx, st->ave_enr_fx, - st->ave_enr2_fx, st->fr_bands1_fx, st->fr_bands2_fx, st->Bin_E_old_fx ); + Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, &Q_new, old_inp, &(st->mem_wsp_fx), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, hNoiseEst->ave_enr_fx, + hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); Q_exp = sub(Q_new, st->prev_Q_new); move16(); - Scale_mem_enc( Q_exp, old_inp_16k, old_exc, st->old_bwe_exc_fx, &(st->LPDmem.mem_w0), st->LPDmem.mem_syn, st->LPDmem.mem_syn2, - &st->mem_deemp_preQ_fx, st->last_exc_dct_in_fx, st->old_input_lp_fx ); + Scale_mem_enc( Q_exp, old_inp_16k, old_exc, hBWE_TD->old_bwe_exc_fx, &(hLPDmem->mem_w0), hLPDmem->mem_syn, hLPDmem->mem_syn2, + &st->mem_deemp_preQ_fx, hGSCEnc->last_exc_dct_in_fx, hBWE_FD->old_input_lp_fx ); /*----------------------------------------------------------------* * Compute spectrum, find energy per critical frequency band @@ -279,27 +283,31 @@ void amr_wb_enc_fx( * Detect NB spectrum in a 16kHz-sampled input *----------------------------------------------------------------*/ - analy_sp( inp, Q_new, fr_bands, lf_E, &Etot, st->min_band_fx, st->max_band_fx, Le_min_scaled, Scale_fac, st->Bin_E_fx, - st->Bin_E_old_fx, PS, st->lgBin_E_fx, st->band_energies, fft_buff ); + analy_sp(st->element_mode, +#ifdef IVAS_CODE_CPE + hCPE, +#endif + st->input_Fs_fx, inp, Q_new, fr_bands, lf_E, & Etot, st->min_band_fx, st->max_band_fx, Le_min_scaled, Scale_fac, st->Bin_E_fx, + st->Bin_E_old_fx, PS, st->lgBin_E_fx, st->band_energies, fft_buff ); - noise_est_pre_fx( Etot, st->ini_frame_fx, &st->Etot_l_fx, &st->Etot_h_fx, &st->Etot_l_lp_fx, &st->Etot_last_fx, - &st->Etot_v_h2_fx, &st->sign_dyn_lp_fx, st->harm_cor_cnt_fx, &st->Etot_lp_fx ); + noise_est_pre_fx( Etot, st->ini_frame_fx, hNoiseEst, 0, EVS_MONO, EVS_MONO); /*----------------------------------------------------------------* * VAD *----------------------------------------------------------------*/ - vad_flag = wb_vad_fx( st, fr_bands, &localVAD, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr), Q_new ) ; + st->vad_flag = wb_vad_fx( st, fr_bands, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, + &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr), Q_new + , hVAD,hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ) ; - if ( vad_flag == 0 ) + if (st->vad_flag == 0 ) { - coder_type = INACTIVE; + st->coder_type = INACTIVE; move16(); } /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, localVAD, vad_flag, sub(st->lp_speech_fx, st->lp_noise_fx), 0, &vad_hover_flag ); + vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub(st->lp_speech_fx, st->lp_noise_fx), 0, &vad_hover_flag, NULL, NULL); /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled @@ -328,23 +336,27 @@ void amr_wb_enc_fx( * Correlation correction as a function of total noise level *----------------------------------------------------------------*/ - noise_est_down_fx( fr_bands, st->bckr_fx, tmpN, tmpE, st->min_band_fx, st->max_band_fx, &st->totalNoise_fx, - Etot, &st->Etot_last_fx, &st->Etot_v_h2_fx, Q_new, Le_min_scaled ); + noise_est_down_fx( fr_bands, hNoiseEst->bckr_fx, tmpN, tmpE, st->min_band_fx, st->max_band_fx, &hNoiseEst->totalNoise_fx, + Etot, &hNoiseEst->Etot_last_fx, &hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); high_lpn_flag = 0; move16(); /* Q0 flag */ - long_enr_fx( st, Etot, localVAD_HE_SAD, high_lpn_flag ); + long_enr_fx( st, Etot, localVAD_HE_SAD, high_lpn_flag +#ifdef IVAS_CODE + , NULL, 1, NULL, NULL +#endif + ); relE = sub(Etot, st->lp_speech_fx); /* Q8 */ IF( NE_16(st->bwidth_fx, NB)) { - lp_bckr = Mean32( st->bckr_fx, 10 ); + lp_bckr = Mean32(hNoiseEst->bckr_fx, 10 ); } ELSE { - lp_bckr = Mean32( st->bckr_fx+1, 9 ); + lp_bckr = Mean32(hNoiseEst->bckr_fx+1, 9 ); } - hp_bckr = L_shr(L_add(st->bckr_fx[st->max_band_fx-1] , st->bckr_fx[st->max_band_fx]),1); + hp_bckr = L_shr(L_add(hNoiseEst->bckr_fx[st->max_band_fx-1] , hNoiseEst->bckr_fx[st->max_band_fx]),1); if( hp_bckr == 0 ) /* Avoid division by zero. */ { hp_bckr = L_deposit_l(1); @@ -353,13 +365,13 @@ void amr_wb_enc_fx( Ltmp = L_shr_r( L_deposit_h( tmp ), sub( 15, e_tmp ) ); st->bckr_tilt_lt = L_add( Mpy_32_16_r( st->bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); - corr_shift = correlation_shift_fx( st->totalNoise_fx ); + corr_shift = correlation_shift_fx(hNoiseEst->totalNoise_fx ); /*----------------------------------------------------------------* * WB, SWB and FB bandwidth detector *----------------------------------------------------------------*/ - bw_detect_fx( st, st->input, localVAD, NULL, NULL ); + bw_detect_fx( st, st->input, NULL, NULL, NULL, MONO_FORMAT, 0); /* in AMR_WB IO, limit the maximum band-width to WB */ if( GT_16(st->bwidth_fx,WB)) @@ -375,12 +387,13 @@ void amr_wb_enc_fx( * Perform 1/4 pitch precision improvement *----------------------------------------------------------------*/ - IF ( vad_flag == 0 ) + IF (st->vad_flag == 0 ) { /* reset the OL pitch tracker memories during inactive frames */ pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit_fx, &st->old_corr_fx) ; } - + old_pitch1 = st->pitch_fx[1]; + move16(); analy_lp_AMR_WB_fx( inp, &ener, A, epsP_h, epsP_l, isp_new, st->lsp_old1_fx, isf_new, st->old_pitch_la, st->old_voicing_la, Q_new, Q_r ); @@ -401,21 +414,26 @@ void amr_wb_enc_fx( shift = -1; move16(); } - pitch_ol_fx( pitch, voicing, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit_fx, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, 0, st->bwidth_fx, st->Opt_SC_VBR_fx ); - st->old_pitch_la = pitch[2]; + pitch_ol_fx( st->pitch_fx, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit_fx, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, 0, st->bwidth_fx, st->Opt_SC_VBR_fx ); + st->old_pitch_la = st->pitch_fx[2]; move16(); - st->old_voicing_la = voicing[2]; + st->old_voicing_la = st->voicing_fx[2]; move16(); /* VAD parameters update */ - vad_param_updt_fx( st, pitch, voicing, st->pitO_fx, corr_shift, vad_flag, A ); + vad_param_updt_fx( st, old_pitch1 , corr_shift, corr_shift, A, NULL, 1 ); /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - noise_est_fx( st, tmpN, pitch, voicing, epsP_h, epsP_l, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, &sp_div, &Q_sp_div, &non_staX, &harm_flag, - lf_E, &st->harm_cor_cnt_fx, st->Etot_l_lp_fx, st->Etot_v_h2_fx, &st->bg_cnt_fx, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor ); + noise_est_fx( st, old_pitch1, tmpN, epsP_h, epsP_l, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, + NULL, &sp_div, &Q_sp_div, &non_staX, &harm_flag, + lf_E, &hNoiseEst->harm_cor_cnt_fx, hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_v_h2_fx, &hNoiseEst->bg_cnt_fx, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor, NULL, +#ifdef IVAS_CODE + NULL, NULL, +#endif + st->ini_frame_fx); /*----------------------------------------------------------------* * Change the sampling frequency to 16 kHz, @@ -444,38 +462,37 @@ void amr_wb_enc_fx( IF ( EQ_32(st->core_brate_fx,SID_1k75)||EQ_32(st->core_brate_fx,FRAME_NO_DATA)) { /* encode CNG parameters */ - CNG_enc_fx( st, L_FRAME, Aq, inp, ener, isp_new, isf_new , &allow_cn_step, st->burst_ho_cnt_fx, sub(Q_new,1), - q_env, &sid_bw, st->exc_mem2_fx ); + CNG_enc_fx( st, Aq, inp, ener, isp_new, isp_new, isf_new , &allow_cn_step, sub(Q_new,1), q_env, &sid_bw ); /* comfort noise generation */ - CNG_exc_fx( st->core_brate_fx, L_FRAME, &st->Enew_fx, &st->cng_seed_fx, exc, exc2, &st->lp_ener_fx, - st->last_core_brate_fx, &st->first_CNG_fx, &st->cng_ener_seed_fx, dummy_buf, allow_cn_step, - &st->last_allow_cn_step_fx, sub(st->prev_Q_new,1), sub(Q_new,1), st->num_ho_fx, q_env, st->lp_env_fx, - st->old_env_fx, st->exc_mem_fx, st->exc_mem1_fx, &sid_bw, &st->cng_ener_seed1_fx, exc3, st->Opt_AMR_WB_fx ); + CNG_exc_fx( st->core_brate_fx, L_FRAME, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed_fx, exc, exc2, &hTdCngEnc->lp_ener_fx, + st->last_core_brate_fx, &hDtxEnc->first_CNG_fx, &hTdCngEnc->cng_ener_seed_fx, dummy_buf, allow_cn_step, + &hTdCngEnc->last_allow_cn_step_fx, sub(st->prev_Q_new,1), sub(Q_new,1), hTdCngEnc->num_ho_fx, q_env, hTdCngEnc->lp_env_fx, + hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1_fx, exc3, st->Opt_AMR_WB_fx, st->element_mode); - if ( st->first_CNG_fx == 0 ) + if (hDtxEnc->first_CNG_fx == 0 ) { - st->first_CNG_fx = 1; + hDtxEnc->first_CNG_fx = 1; move16(); } /* synthesis */ - syn_12k8_fx( L_FRAME, Aq, exc2, dummy_buf, st->LPDmem.mem_syn3, 1, Q_new, st->Q_syn ); + syn_12k8_fx( L_FRAME, Aq, exc2, dummy_buf, hLPDmem->mem_syn3, 1, Q_new, st->Q_syn ); /* reset the encoder */ - CNG_reset_enc_fx( st, &(st->LPDmem), pitch_buf, dummy_buf+L_FRAME, 0 ); + CNG_reset_enc_fx( st, hLPDmem, pitch_buf, dummy_buf+L_FRAME, 0 ); /* update st->mem_syn1 for ACELP core switching */ - Copy( st->LPDmem.mem_syn3, st->mem_syn1_fx, M ); + Copy(hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M); /* update ACELP core synthesis filter memory */ - Copy( st->LPDmem.mem_syn3, st->LPDmem.mem_syn, M ); + Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( dummy_buf + L_FRAME - L_SYN_MEM, st->LPDmem.mem_syn_r, L_SYN_MEM ); + Copy( dummy_buf + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* Update MODE2 core switching memory */ - E_UTIL_deemph2( sub(Q_new,1), dummy_buf, PREEMPH_FAC, L_FRAME, &(st->LPDmem.syn[M]) ); - Copy( dummy_buf+L_FRAME-M-1, st->LPDmem.syn, M+1 ); + E_UTIL_deemph2( sub(Q_new,1), dummy_buf, PREEMPH_FAC, L_FRAME, &(hLPDmem->syn[M]) ); + Copy( dummy_buf+L_FRAME-M-1, hLPDmem->syn, M+1 ); } @@ -491,8 +508,8 @@ void amr_wb_enc_fx( test(); IF( EQ_32(st->last_core_brate_fx,FRAME_NO_DATA)||EQ_32(st->last_core_brate_fx,SID_1k75)) { - Copy( st->lspCNG_fx, st->lsp_old_fx, M ); - E_LPC_isp_isf_conversion( st->lspCNG_fx, st->lsf_old_fx, M); + Copy(hDtxEnc->lspCNG_fx, st->lsp_old_fx, M ); + E_LPC_isp_isf_conversion(hDtxEnc->lspCNG_fx, st->lsf_old_fx, M); set16_fx( old_exc, 0, L_EXC_MEM ); } @@ -500,37 +517,41 @@ void amr_wb_enc_fx( * ISF Quantization and interpolation *-----------------------------------------------------------------*/ - isf_enc_amr_wb_fx( st, isf_new, isp_new, Aq, &st->stab_fac_fx); + isf_enc_amr_wb_fx( st, isf_new, isp_new, Aq); /*---------------------------------------------------------------* * Calculation of LP residual (filtering through A[z] filter) *---------------------------------------------------------------*/ - calc_residu_fx( st, inp, res, Aq, 0, 0 ); - st->burst_ho_cnt_fx = 0; + calc_residu_fx(st, inp, res, Aq); + if (hTdCngEnc != NULL) + { + hTdCngEnc->burst_ho_cnt_fx = 0; + } + move16(); /*------------------------------------------------------------* * Encode excitation *------------------------------------------------------------*/ - encod_amr_wb_fx( st, &(st->LPDmem), inp, Aw, Aq, pitch, voicing, res, syn, exc, exc2, pitch_buf, hf_gain_fx, inp_16k, shift, Q_new ); + encod_amr_wb_fx( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, hf_gain_fx, inp_16k, shift, Q_new ); /* update st->mem_syn1 for ACELP core switching */ - Copy( st->LPDmem.mem_syn, st->mem_syn1_fx, M ); + Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn + L_FRAME - L_SYN_MEM, st->LPDmem.mem_syn_r, L_SYN_MEM ); + Copy( syn + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* Update MODE2 core switching memory */ - E_UTIL_deemph2( sub(Q_new,1), syn, PREEMPH_FAC, L_FRAME, &(st->LPDmem.syn[M]) ); - Copy( syn+L_FRAME-M-1, st->LPDmem.syn, M+1 ); + E_UTIL_deemph2( sub(Q_new,1), syn, PREEMPH_FAC, L_FRAME, &(hLPDmem->syn[M]) ); + Copy( syn+L_FRAME-M-1, hLPDmem->syn, M+1 ); /*--------------------------------------------------------------------------------------* * Write VAD information into the bitstream in AMR-WB IO mode *--------------------------------------------------------------------------------------*/ - push_indice_fx( st, IND_VAD_FLAG, vad_flag, 1 ); + push_indice_fx( st->hBstr, IND_VAD_FLAG, st->vad_flag, 1 ); } /*-----------------------------------------------------------------* @@ -550,7 +571,7 @@ void amr_wb_enc_fx( } /* update of old per-band energy spectrum */ - Copy32( fr_bands + NB_BANDS, st->enrO_fx, NB_BANDS ); + Copy32( fr_bands + NB_BANDS, hNoiseEst->enrO_fx, NB_BANDS ); /* update the last bandwidth */ st->last_input_bwidth_fx = st->input_bwidth_fx; @@ -559,67 +580,36 @@ void amr_wb_enc_fx( /* update signal buffers */ Copy( new_inp, st->buf_speech_enc_pe+L_FRAME, L_FRAME ); Copy( wsp, st->buf_wspeech_enc+L_FRAME+L_SUBFR, L_FRAME + L_LOOK_12k8 ); - updt_enc_fx( st, L_FRAME, coder_type, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); - - core_encode_update( st ); + updt_enc_fx( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec parameters */ - st->last_extl_fx = -1; - move16(); - st->last_core_fx = st->core_fx; - move16(); - st->last_L_frame_fx = L_FRAME; - move16(); - st->last_core_brate_fx = st->core_brate_fx; - move16(); - st->last_total_brate_fx = st->total_brate_fx; - move16(); - st->Etot_last_fx = Etot; - move16(); - st->last_coder_type_raw_fx = st->coder_type_raw_fx; - move16(); - st->last_codec_mode = st->codec_mode; - move16(); + updt_enc_common(st, Etot, Q_new); - st->prev_Q_new = Q_new; + return; +} +/*---------------------------------------------------------------------* + * amr_wb_enc_init() + * + * Initialize AMR-WB encoder + *---------------------------------------------------------------------*/ - /* Increase the counter of initialization frames */ - if( LT_16(st->ini_frame_fx,MAX_FRAME_COUNTER)) - { - st->ini_frame_fx = add(st->ini_frame_fx,1); - } +void amr_wb_enc_init( + AMRWB_IO_ENC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO encoder handle */ +) +{ + int16_t i; - if( GT_32(st->core_brate_fx,SID_1k75)) - { - st->last_active_brate_fx = st->total_brate_fx; - move32(); - } + /* HF (6-7kHz) BWE */ + hAmrwb_IO->seed2_enc_fx = RANDOM_INITSEED; + move16(); - test(); - IF ( GT_32(st->core_brate_fx,SID_1k75)&&st->first_CNG_fx) + FOR (i = 0; i < GAIN_PRED_ORDER; i++) { - if( GE_16(st->act_cnt_fx,BUF_DEC_RATE)) - { - st->act_cnt_fx = 0; - move16(); - } - - st->act_cnt_fx = add(st->act_cnt_fx,1); - - test(); - if( EQ_16(st->act_cnt_fx,BUF_DEC_RATE)&&st->ho_hist_size_fx>0) - { - st->ho_hist_size_fx = sub(st->ho_hist_size_fx,1); - } - - st->act_cnt2_fx = add(st->act_cnt2_fx,1); - if( GE_16(st->act_cnt2_fx, MIN_ACT_CNG_UPD)) - { - st->act_cnt2_fx = MIN_ACT_CNG_UPD; - move16(); - } + hAmrwb_IO->past_qua_en_fx[i] = -14336; /* Q10gain quantization memory (used also in AMR-WB IO mode) */ + move16(); } + hf_cod_init_fx(hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, &hAmrwb_IO->gain_alpha_fx); return; } diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index 0ca8c66..54e04f1 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_enc_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * analy_lp() @@ -22,19 +22,20 @@ *-------------------------------------------------------------------*/ void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_look, /* i : look-ahead */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o : current frame LSPs */ - Word16 lsp_mid[], /* o : current mid-frame LSPs */ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ - const Word16 Top[2], /* i : open loop pitch lag */ - const Word16 Tnc[2], /* i : open loop pitch gain */ - const Word32 Core_sr, /* i : Internal core sampling rate */ + const Word16 speech[], /* i : pointer to the speech frame */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_look, /* i : look-ahead */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A[], /* o : A(z) filter coefficients */ + Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o : current frame LSPs */ + Word16 lsp_mid[], /* o : current mid-frame LSPs */ + Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ + const Word16 Top[2], /* i : open loop pitch lag */ + const Word16 Tnc[2], /* i : open loop pitch gain */ + const Word32 Core_sr, /* i : Internal core sampling rate */ + const Word16 sec_chan_low_rate, /* i : flag to signal second channel */ Word16 Q_new, Word16 *Q_r ) @@ -89,9 +90,16 @@ void analy_lp_fx( lsp = lsp_new; } - - /* LSP interpolation */ - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A , M, 0 ); + IF (EQ_16(sec_chan_low_rate, 1) ) + { + /* LSP interpolation */ + int_lsp4_fx(L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2); + } + ELSE + { + /* LSP interpolation */ + int_lsp4_fx(L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0); + } Copy (lsp_new, lsp_old, M); *ener = L_Comp(epsP_h[M],epsP_l[M]); move32(); diff --git a/lib_enc/analy_sp.c b/lib_enc/analy_sp.c index 149f738..551d907 100644 --- a/lib_enc/analy_sp.c +++ b/lib_enc/analy_sp.c @@ -2,18 +2,25 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" #include "cnst_fx.h" -#include "stl.h" #include "basop_util.h" #include "prot_fx.h" #include "rom_enc_fx.h" #include +/*-------------------------------------------------------------------* + * Local prototypes + *-------------------------------------------------------------------*/ static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); +#ifdef IVAS_CODE_CPE +static void find_enr_dft(CPE_ENC_HANDLE hCPE, const int32_t input_Fs, float DFT_past_DMX[], float band[], float* ptE, float* Etot, const int16_t min_band, const int16_t max_band, float* Bin_E, float* band_ener); +#endif + /*-------------------------------------------------------------------* * analy_sp() * @@ -21,21 +28,26 @@ static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, *-------------------------------------------------------------------*/ void analy_sp( - Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ - const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ - Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ - Word16 *Etot, /* o : total input energy Q8 */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ + const Word16 element_mode, /* i : element mode */ +#ifdef IVAS_CODE_CPE + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ +#endif + const Word32 input_Fs, /* i : input sampling rate */ + Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ + const Word16 Q_new, /* i : current scaling exp Q0 */ + Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ + Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ + Word16 *Etot, /* o : total input energy Q8 */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ - Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ - Word32 *Bin_E, /* o : per-bin energy spectrum */ - Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame */ - Word32 *PS, /* o : per-bin energy spectrum */ - Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies,/* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ - Word16 *fft_buff /* o : FFT coefficients */ + Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ + Word32 *Bin_E, /* o : per-bin energy spectrum */ + Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame */ + Word32 *PS, /* o : per-bin energy spectrum */ + Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ + Word16 *fft_buff /* o : FFT coefficients */ ) { Word16 *pt; @@ -46,8 +58,9 @@ void analy_sp( Word16 Min_val, Max_val; Word16 Scale_fac2; Word16 fft_temp[L_FFT]; - - +#ifndef IVAS_CODE_CPE + MY_UNUSED_Word32(input_Fs) +#endif /*-----------------------------------------------------------------* * Compute spectrum * find energy per critical frequency band and total energy in dB @@ -56,59 +69,73 @@ void analy_sp( pt_bands = fr_bands; pt_fft = fft_buff; LEtot = L_deposit_l(0); - - FOR (i_subfr=0; i_subfr <= 1; i_subfr++) + IF(NE_16(element_mode, IVAS_CPE_DFT)) { - pt = speech + 3*(L_SUBFR/2) - L_FFT/2; - if(i_subfr != 0) + FOR(i_subfr = 0; i_subfr <= 1; i_subfr++) { - pt = speech + 7*(L_SUBFR/2) - L_FFT/2; - } - - /* Clear 1st value of 1st part, copy 1st value of 2nd part */ - fft_temp[0] = 0; - move16(); - fft_temp[L_FFT/2] = pt[L_FFT/2]; - move16(); - Max_val = s_max(fft_temp[0],fft_temp[L_FFT/2]); - Min_val = s_min(fft_temp[0],fft_temp[L_FFT/2]); + pt = speech + 3 * (L_SUBFR / 2) - L_FFT / 2; + if (i_subfr != 0) + { + pt = speech + 7 * (L_SUBFR / 2) - L_FFT / 2; + } - FOR (i=1; i 0) - Max_val = s_max(Max_val, fft_temp[i]); - if (fft_temp[i] < 0) - Min_val = s_min(Min_val, fft_temp[i]); - - /* 2nd windowed part */ - fft_temp[L_FFT-i] = mult_r(pt[L_FFT-i], sqrt_han_window[i]); + fft_temp[L_FFT / 2] = pt[L_FFT / 2]; move16(); - if (fft_temp[L_FFT-i] > 0) - Max_val = s_max(Max_val, fft_temp[L_FFT-i]); - if (fft_temp[L_FFT-i] < 0) - Min_val = s_min(Min_val, fft_temp[L_FFT-i]); - } + Max_val = s_max(fft_temp[0], fft_temp[L_FFT / 2]); + Min_val = s_min(fft_temp[0], fft_temp[L_FFT / 2]); + + FOR(i = 1; i < L_FFT / 2; i++) + { + /* 1st windowed part */ + fft_temp[i] = mult_r(pt[i], sqrt_han_window[i]); + move16(); + if (fft_temp[i] > 0) + Max_val = s_max(Max_val, fft_temp[i]); + if (fft_temp[i] < 0) + Min_val = s_min(Min_val, fft_temp[i]); - /* Combine -Min_val and Max_val into one */ - Max_val = s_max(negate(Min_val),Max_val); + /* 2nd windowed part */ + fft_temp[L_FFT - i] = mult_r(pt[L_FFT - i], sqrt_han_window[i]); + move16(); + if (fft_temp[L_FFT - i] > 0) + Max_val = s_max(Max_val, fft_temp[L_FFT - i]); + if (fft_temp[L_FFT - i] < 0) + Min_val = s_min(Min_val, fft_temp[L_FFT - i]); + } - Scale_fac[i_subfr] = s_min(sub(norm_s(Max_val), 1), 6); - move16(); - Scale_fac2 = shl(Scale_fac[i_subfr], 1); - Scale_sig(fft_temp, L_FRAME_12k8, Scale_fac[i_subfr]); + /* Combine -Min_val and Max_val into one */ + Max_val = s_max(negate(Min_val), Max_val); - r_fft_fx_lc(FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1); + Scale_fac[i_subfr] = s_min(sub(norm_s(Max_val), 1), 6); + move16(); + Scale_fac2 = shl(Scale_fac[i_subfr], 1); + Scale_sig(fft_temp, L_FRAME_12k8, Scale_fac[i_subfr]); - /* find energy per critical band */ - find_enr( pt_fft, pt_bands, lf_E + i_subfr*VOIC_BINS, &LEtot, min_band, max_band, - add(Q_new,Scale_fac2), e_min_scaled, &Bin_E[i_subfr*L_FFT/2], BIN, band_energies + i_subfr*NB_BANDS); + r_fft_fx_lc(FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1); + + /* find energy per critical band */ + find_enr(pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, + add(Q_new, Scale_fac2), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS); - pt_bands += NB_BANDS; - pt_fft += L_FFT; + pt_bands += NB_BANDS; + pt_fft += L_FFT; + } } +#ifdef IVAS_CODE_CPE + ELSE + { + /* find energy per critical band */ + find_enr_dft(hCPE, input_Fs, hCPE->hStereoDft->DFT[0], pt_bands, lf_E, Etot, min_band, max_band, Bin_E, band_ener); + mvr2r(lf_E, lf_E + VOIC_BINS, VOIC_BINS); + mvr2r(Bin_E, Bin_E + (L_FFT / 2), L_FFT / 2); + mvr2r(band_ener, band_ener + NB_BANDS, NB_BANDS); + mvr2r(pt_bands, pt_bands + NB_BANDS, NB_BANDS); + *Etot *= 2.f; + } +#endif /* Average total log energy over both half-frames */ frac_etot = 0; @@ -173,17 +200,17 @@ void analy_sp( *------------------------------------------------------------------------*/ static void find_enr( - Word16 data[], /* i : fft result */ - Word32 band[], /* o : per band energy Q_new + QSCALE */ - Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ - Word32 *LEtot, /* o : total energy Q_new + QSCALE */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - const Word16 Q_new2, /* i : scaling factor Q0 */ - const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ - Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ - Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ - Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ + Word16 data[], /* i : fft result */ + Word32 band[], /* o : per band energy Q_new + QSCALE */ + Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ + Word32 *LEtot, /* o : total energy Q_new + QSCALE */ + const Word16 min_band, /* i : minimum critical band Q0 */ + const Word16 max_band, /* i : maximum critical band Q0 */ + const Word16 Q_new2, /* i : scaling factor Q0 */ + const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ + Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ + Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ + Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ ) { Word16 i, cnt, shift_to_norm; @@ -385,3 +412,151 @@ static void find_enr( return; } +#ifdef IVAS_CODE_CPE +/*------------------------------------------------------------------------* + * find_enr_dft() + * + * find input signal energy for each critical band using the DFT buffers + *------------------------------------------------------------------------*/ + +static void find_enr_dft( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const int32_t input_Fs, /* i : input sampling rate */ + float DFT_past_DMX[], + float band[], /* o : per band energy */ + float* ptE, /* o : per bin energy for low frequencies */ + float* Etot, /* i/o: total energy */ + const int16_t min_band, /* i : minimum critical band */ + const int16_t max_band, /* i : maximum critical band */ + float* Bin_E, /* o : Per bin energy */ + float* band_ener /* o : per band energy without E_MIN */ +) +{ + int16_t i, cnt; + float freq, tmp; + const float* ptR, * ptI; + float norm_val; + int16_t bin_cnt = 0; + + float c, s; + /* One window - 40ms*12.8kHz = 512 samples */ + float c_1 = cosf(PI2 / STEREO_DFT_N_12k8_ENC); + float s_1 = sinf(PI2 / STEREO_DFT_N_12k8_ENC); + float g_1 = 1.f + 0.68f * 0.68f; + float g_2 = 2 * 0.68f; + float g; + float scaleWin; + + float BinE[STEREO_DFT_N_12k8_ENC / 2]; /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ + float bin_freq = input_Fs / (float)hCPE->hStereoDft->NFFT; /* adaptive frequency bin width */ + + scaleWin = 1 / (2 * hCPE->hStereoDft->win_ana_energy); + scaleWin *= (float)BIN / bin_freq; + norm_val = scaleWin * 4.0f / (hCPE->hStereoDft->NFFT * hCPE->hStereoDft->NFFT); + + ptR = &DFT_past_DMX[2]; /* first real */ + ptI = &DFT_past_DMX[3]; /* first imaginary */ + c = c_1; + s = s_1; + + /* for low frequency bins, save per bin energy for the use in find_tilt() */ + freq = bin_freq; + for (i = 0; i < NB_BANDS - 1; i++) /* up to maximum allowed voiced critical band */ + { + band[i] = 0.0f; + cnt = 0; + + /* bins up to crit_band 17 (<= 3700 Hz): + * bin_cnt old (bin_width 50 Hz): 74 (74 * FRAMES_PER_SEC = 3700) + * bin_cnt new (bin_width 40 Hz): 92 (92 * 40 = 3680) + */ + + while (freq <= crit_bands[i]) + { + BinE[bin_cnt] = *ptR * *ptR + *ptI * *ptI; /* energy */ + g = g_1 - g_2 * c; + tmp = c * c_1 - s * s_1; + s = s * c_1 + c * s_1; + c = tmp; + BinE[bin_cnt] *= norm_val * g; /* normalization - corresponds to FFT normalization by 2/L_FFT */ + band[i] += BinE[bin_cnt]; + ptR += 2; + ptI += 2; + + freq += bin_freq; + cnt++; + bin_cnt++; + } + + band[i] *= inv_tbl[cnt]; /* normalization per frequency bin */ + + band_ener[i] = band[i]; /* per band energy without E_MIN */ + + if (band[i] < E_MIN) + { + band[i] = E_MIN; + } + } + + /* continue computing the energy per critical band for higher frequencies */ + + /* old version, FFT 256 @ SR12.8 (-> bin_width = 50 Hz): + NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 127 = L_FFT/2-1*/ + + /* new version: DFT (1200/800/400) @ input SR (48/32/16) (-> bin_width = 40 Hz): + * + */ + /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ + /* NB_BANDS = 21 (= 7700Hz) = highest band available for SR 16 -> bin_cnt = 192 */ + /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 32 -> bin_cnt = 387 */ + /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 48 -> bin_cnt = 387 */ + + for (; i < NB_BANDS; i++) + { + band[i] = 0.0f; + cnt = 0; + while (freq < 6399.0f) + { + BinE[bin_cnt] = *ptR * *ptR + *ptI * *ptI; + g = g_1 - g_2 * c; + BinE[bin_cnt] *= norm_val * g; + band[i] += BinE[bin_cnt]; + ptR += 2; + ptI += 2; + + freq += bin_freq; + cnt++; + bin_cnt++; + } + + band[i] *= inv_tbl[cnt]; /* normalization per frequency bin */ + + band_ener[i] = band[i]; /* per band energy without E_MIN */ + + if (band[i] < E_MIN) + { + band[i] = E_MIN; + } + } + + /* put bin energies from BinE into Bin_E[L_FFT/2-1] (interpolate 40 Hz bin values to fit into 50 Hz bins) */ + /* Last value of Bin_E is handled outside this function*/ + assert(bin_cnt == (STEREO_DFT_N_12k8_ENC / 2 - 1)); + BinE[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE[STEREO_DFT_N_12k8_ENC / 2 - 2]; + lerp(BinE, Bin_E, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2); + mvr2r(Bin_E, ptE, VOIC_BINS); + + + /* find the total log energy */ + tmp = *Etot; + for (i = min_band; i <= max_band; i++) + { + tmp += band[i]; + } + + *Etot = tmp; + + return; +} + +#endif \ No newline at end of file diff --git a/lib_enc/ari_enc.c b/lib_enc/ari_enc.c index afae0f3..386715b 100644 --- a/lib_enc/ari_enc.c +++ b/lib_enc/ari_enc.c @@ -2,29 +2,29 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "assert.h" -#include "stl.h" +#include "options.h" #include "basop_mpy.h" #include "cnst_fx.h" #include "rom_com_fx.h" #include "prot_fx.h" -/** - * \brief Copy state +/*--------------------------------------------------------------- + * ari_copy_states() * * \param[i] source * \param[o] dest * * \return none - */ + *-------------------------------------------------------------*/ void ari_copy_states(TastatEnc *source, TastatEnc *dest) { dest->low = source->low; move32(); dest->high = source->high; move32(); - dest->vobf = source->vobf; + dest->value = source->value; move16(); } @@ -33,24 +33,26 @@ void ari_copy_states(TastatEnc *source, TastatEnc *dest) -------------------------------------------------------------*/ -/** - * \brief Start ArCo encoding +/*--------------------------------------------------------------- + * ari_start_encoding_14bits() * - * \param[o] s + * \param[o] s * * \return none - */ + *-------------------------------------------------------------*/ void ari_start_encoding_14bits(TastatEnc *s) { s->low = L_deposit_l(0); s->high = ari_q4new + 1; move32(); - s->vobf = 0; + s->value = 0; move16(); } - -/* Returns: new bit-stream position */ +/*--------------------------------------------------------------- + * Ari encoder 14 bits routines + * Returns: new bit-stream position + *-------------------------------------------------------------*/ static Word16 ari_put_bit_plus_follow( Word16 ptr[], /* o: bit-stream */ Word16 bp, /* i: bit-stream position */ @@ -68,15 +70,16 @@ static Word16 ari_put_bit_plus_follow( return bp; } -/** - * \brief Finish ArCo encoding +/*-------------------------------------------------------------- - + *ari_done_encoding_14bits() + * * * \param[o] ptr * \param[i] bp * \param[i] s * * \return bit consumption - */ + * ------------------------------------------------------------ - */ Word16 ari_done_encoding_14bits(Word16 *ptr, Word16 bp, TastatEnc *s) { Word16 bit; @@ -87,13 +90,15 @@ Word16 ari_done_encoding_14bits(Word16 *ptr, Word16 bp, TastatEnc *s) { bit = s_xor(bit,1); } - return ari_put_bit_plus_follow(ptr, bp, add(s->vobf, 1), bit); + return ari_put_bit_plus_follow(ptr, bp, add(s->value, 1), bit); } - -/** - * \brief encode function for extended proba tables: less branches needed for coding +/*--------------------------------------------------------------- + *ari_encode_14bits_ext() + * + * encode function for extended proba tables : less branches needed for coding + * * * \param[o] ptr * \param[i] bp @@ -102,7 +107,7 @@ Word16 ari_done_encoding_14bits(Word16 *ptr, Word16 bp, TastatEnc *s) * \param[i] cum_freq * * \return bit consumption - */ + * ------------------------------------------------------------ - */ Word16 ari_encode_14bits_ext( Word16 *ptr, Word16 bp, @@ -132,7 +137,7 @@ Word16 ari_encode_14bits_ext( high = L_add(low, range); low = L_add(low, L_temp2); - bits_to_follow = s->vobf; + bits_to_follow = s->value; move16(); FOR (i = 0; i < 0x7FFF; i++) @@ -175,23 +180,31 @@ Word16 ari_encode_14bits_ext( move32(); s->high = high; move32(); - s->vobf = bits_to_follow; + s->value = bits_to_follow; move16(); return bp; } - +/*------------------------------------------------------------------------ + * Function: ari_encode_overflow() + * + * + *-------------------------------------------------------------------------*/ Word16 ari_encode_overflow(TastatEnc *s) { return L_sub(L_sub(s->high, 1), s->low) <= 0; } - +/*------------------------------------------------------------------------ + * Function: ari_encode_14bits_high_low() + * + * + *-------------------------------------------------------------------------*/ static Word16 ari_encode_14bits_high_low(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word32 high, Word32 low) { Word16 bits_to_follow, tmp; - bits_to_follow = s->vobf; + bits_to_follow = s->value; move16(); /* while there are more than 16 bits left */ @@ -236,7 +249,7 @@ static Word16 ari_encode_14bits_high_low(Word16 *ptr, Word16 bp, Word16 bits, Ta move32(); s->high = high; move32(); - s->vobf = bits_to_follow; + s->value = bits_to_follow; move16(); return bp; @@ -298,14 +311,14 @@ Word16 ari_done_cbr_encoding_14bits(Word16 *ptr, Word16 bp, Word16 bits, TastatE Word16 high, tmp, k; tmp = sub(bits, 16); - WHILE (GT_16(sub(tmp, bp), s->vobf)) + WHILE (GT_16(sub(tmp, bp), s->value)) { bp = ari_encode_14bits_sign(ptr, bp, bits, s, 0); } high = extract_l(L_sub(s->high, 1)); - bp = ari_put_bit_plus_follow(ptr, bp, s->vobf, lshr(high, 15)); + bp = ari_put_bit_plus_follow(ptr, bp, s->value, lshr(high, 15)); high = lshl(high, 1); tmp = s_min(15, sub(bits, bp)); diff --git a/lib_enc/ari_hm_enc.c b/lib_enc/ari_hm_enc.c index 89519e8..51290ba 100644 --- a/lib_enc/ari_hm_enc.c +++ b/lib_enc/ari_hm_enc.c @@ -3,21 +3,25 @@ ====================================================================================*/ -#include -#include -#include +#include #include -#include "stl.h" +#include "options.h" #include "cnst_fx.h" #include "basop_util.h" #include "rom_com_fx.h" #include "rom_enc_fx.h" #include "prot_fx.h" +/*-------------------------------------------------------------------* + * EncodeIndex() + * + * + *-------------------------------------------------------------------*/ + Word16 EncodeIndex( - Word16 Bandwidth, + const Word16 Bandwidth, Word16 PeriodicityIndex, - Encoder_State_fx *st + BSTR_ENC_HANDLE hBst /* i/o: bitstream handle */ ) { Word16 NumRatioBitsBwLtpIndx; @@ -33,21 +37,25 @@ Word16 EncodeIndex( NumRatioBitsBwLtpIndx = NumRatioBits[Bandwidth][LtpPitchIndex]; move16(); - push_next_indice_fx(st, s_and(PeriodicityIndex, 0xff), NumRatioBitsBwLtpIndx); + push_next_indice_fx(hBst, s_and(PeriodicityIndex, 0xff), NumRatioBitsBwLtpIndx); return NumRatioBitsBwLtpIndx; } ELSE { - push_next_indice_fx(st, PeriodicityIndex, 8); + push_next_indice_fx(hBst, PeriodicityIndex, 8); return 8; } } - +/*-------------------------------------------------------------------* + * SearchPeriodicityIndex_Single() + * + * + *-------------------------------------------------------------------*/ static Word16 SearchPeriodicityIndex_Single( const Word16 AbsMdct3[], - Word16 NumToConsider, - Word32 Lag, - Word16 FractionalResolution + const Word16 NumToConsider, + const Word32 Lag, + const Word16 FractionalResolution ) { Word16 HighestMultiplier; @@ -83,15 +91,19 @@ static Word16 SearchPeriodicityIndex_Single( return Result; } - +/*-------------------------------------------------------------------* + * SearchPeriodicityIndex_Range() + * + * + *-------------------------------------------------------------------*/ static void SearchPeriodicityIndex_Range( const Word16 AbsMdct3[], - Word16 NumToConsider, - Word16 Lo, - Word16 Hi, - Word16 FractionalResolution, - Word16 Adj, - Word16 Spacing, + const Word16 NumToConsider, + const Word16 Lo, + const Word16 Hi, + const Word16 FractionalResolution, + const Word16 Adj, + const Word16 Spacing, Word16 *PeriodicityIndex, Word16 *Score ) @@ -172,15 +184,19 @@ static void SearchPeriodicityIndex_Range( move16(); } -/* Returns: PeriodicityIndex */ +/*-------------------------------------------------------------------* + * SearchPeriodicityIndex() + * + * + *-------------------------------------------------------------------*/ Word16 SearchPeriodicityIndex( - const Word32 Mdct[], /* (I) Coefficients, Mdct[0..NumCoeffs-1] */ - const Word32 UnfilteredMdct[], /* (I) Unfiltered coefficients, UnfilteredMdct[0..NumCoeffs-1] */ - Word16 NumToConsider, /* (I) Number of coefficients */ - Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - Word16 LtpPitchLag, - Word16 LtpGain, /* (I) LTP gain */ - Word16 *RelativeScore /* (O) Energy concentration factor (2Q13) */ + const Word32 Mdct[], /* i : Coefficients, Mdct[0..NumCoeffs-1] */ + const Word32 UnfilteredMdct[], /* i : Unfiltered coefficients, UnfilteredMdct[0..NumCoeffs-1] */ + Word16 NumToConsider, /* i : Number of coefficients */ + const Word16 TargetBits, /* i : Target bit budget (excl. Done flag) */ + const Word16 LtpPitchLag, /* i : TCX-LTP pitch */ + const Word16 LtpGain, /* i : LTP gain */ + Word16 *RelativeScore /* o : Energy concentration factor (2Q13) */ ) { Word16 AbsMdct3[MAX_LENGTH]; @@ -422,15 +438,20 @@ Word16 SearchPeriodicityIndex( return PeriodicityIndex; } +/*-------------------------------------------------------------------* + * PeakFilter() + * + * + *-------------------------------------------------------------------*/ static void PeakFilter( - const Word32 x[], /* (I) absolute spectrum */ - Word32 y[], /* (O) filtered absolute spectrum, must not alias x[] */ - Word16 L_frame /* (I) number of spectral lines */ + const Word32 x[], /* i : absolute spectrum */ + Word32 y[], /* O : filtered absolute spectrum, must not alias x[] */ + const Word16 L_frame /* i : number of spectral lines */ ) { Word16 flen, i; -#define kPeakElevationThreshold 1.0f +/*#define kPeakElevationThreshold 1.0f*/ Word16 m; Word32 a; @@ -468,16 +489,19 @@ static void PeakFilter( } - -/* Returns: RE error */ +/*-------------------------------------------------------------------* + * tcx_hm_get_re() + * + * + *-------------------------------------------------------------------*/ static Word32 tcx_hm_get_re( const Word16 x[], /* i: absolute spectrum */ - Word16 gain, /* o: quantized harmonic model gain Q11 */ - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[], /* i: harmonic model Q13 */ - Word32 env[], /* i: envelope Q16 */ - Word16 L_frame /* i: number of spectral lines Q0 */ + const Word16 gain, /* o: quantized harmonic model gain Q11 */ + const Word32 lag, /* i: pitch lag Q0 */ + const Word16 fract_res, /* i: fractional resolution of the lag Q0 */ + Word16 p[], /* i: harmonic model Q13 */ + const Word32 env[], /* i: envelope Q16 */ + const Word16 L_frame /* i: number of spectral lines Q0 */ ) { Word16 i, inv_G, tmp; @@ -534,19 +558,24 @@ static Word32 tcx_hm_get_re( return e; } +/*-------------------------------------------------------------------* + * tcx_hm_quantize_gain() + * + * + *-------------------------------------------------------------------*/ static void tcx_hm_quantize_gain( - const Word32 x[], /* i: absolute spectrum Q31-e */ - Word16 *x_e, /* i: absolute spectrum exponent Q0 */ - Word32 env[], /* i: envelope Q16 */ - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[], /* i: harmonic model Q13 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word16 coder_type, /* i: coder_type Q0 */ - Word16 relative_score, /* i: periodicity score Q13 */ - Word16 *gain_idx, /* o: quantization index Q0 */ - Word16 *gain /* o: quantized harmonic model gain Q11 */ + const Word32 x[], /* i: absolute spectrum Q31-e */ + const Word16 *x_e, /* i: absolute spectrum exponent Q0 */ + const Word32 env[], /* i: envelope Q16 */ + const Word32 lag, /* i: pitch lag Q0 */ + const Word16 fract_res, /* i: fractional resolution of the lag Q0 */ + Word16 p[], /* i: harmonic model Q13 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 coder_type, /* i: coder_type Q0 */ + Word16 relative_score, /* i: periodicity score Q13 */ + Word16 *gain_idx, /* o: quantization index Q0 */ + Word16 *gain /* o: quantized harmonic model gain Q11 */ ) { Word16 g; @@ -651,12 +680,12 @@ static void tcx_hm_quantize_gain( } static Word16 tcx_hm_search( - const Word32 abs_spectrum[], /* i: absolute spectrum Q31-e */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word16 targetBits, /* i: target bit budget Q0 */ - Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ - Word16 LtpGain, /* i: LTP gain Q15 */ - Word16 *RelativeScore /* o: Energy concentration factor Q13 */ + const Word32 abs_spectrum[], /* i: absolute spectrum Q31-e */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 targetBits, /* i: target bit budget Q0 */ + const Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ + const Word16 LtpGain, /* i: LTP gain Q15 */ + Word16 *RelativeScore /* o: Energy concentration factor Q13 */ ) { Word32 fspec[N_MAX_ARI]; @@ -677,16 +706,16 @@ static Word16 tcx_hm_search( } void tcx_hm_analyse( - const Word32 abs_spectrum[], /* i: absolute spectrum Q31-e */ - Word16 *spectrum_e, /* i: absolute spectrum exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word32 env[], /* i/o: envelope shape Q16 */ - Word16 targetBits, /* i: target bit budget Q0 */ - Word16 coder_type, /* i: coder type Q0 */ - Word16 prm_hm[], /* o: HM parameters Q0 */ - Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ - Word16 LtpGain, /* i: LTP gain Q15 */ - Word16 *hm_bits_out /* o: bit consumption Q0 */ + const Word32 abs_spectrum[],/* i: absolute spectrum Q31-e */ + const Word16 *spectrum_e, /* i: absolute spectrum exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + Word32 env[], /* i/o: envelope shape Q16 */ + const Word16 targetBits, /* i: target bit budget Q0 */ + const Word16 coder_type, /* i: coder type Q0 */ + Word16 prm_hm[], /* o: HM parameters Q0 */ + const Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ + const Word16 LtpGain, /* i: LTP gain Q15 */ + Word16 *hm_bits_out /* o: bit consumption Q0 */ ) { Word32 lag; @@ -697,7 +726,7 @@ void tcx_hm_analyse( Word16 hm_bits, bw_flag; - /* Disable HM for non-GENERC, VOICED modes */ + /* Disable HM for non-GENERC, VOICED coder types */ if ( LT_16(coder_type, VOICED)) { *hm_bits_out = 0; diff --git a/lib_enc/arith_coder_enc.c b/lib_enc/arith_coder_enc.c index 19d3e0e..10fac8f 100644 --- a/lib_enc/arith_coder_enc.c +++ b/lib_enc/arith_coder_enc.c @@ -2,25 +2,46 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include #include - #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" -#include "stl.h" -/* Returns: estimated SQ scale Q15-e */ + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define kMaxNumHeapElems 10 +#define LOG2_E 23637/*1.44269504089f Q14*/ + +typedef struct HeapElem +{ + Word32 mScore; /* Sort key */ + Word16 mIndex; /* Original index */ +} HeapElem; + +typedef struct Heap +{ + HeapElem mElem[2 * kMaxNumHeapElems + 1]; + Word16 mSize; +} Heap; + +/*-------------------------------------------------------------------* + * tcx_arith_estimate_scale() + * + * + * Returns: estimated SQ scale Q15-e + *-------------------------------------------------------------------*/ static Word16 tcx_arith_estimate_scale( const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ + const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ Word16 *scale_e /* o: scale exponent Q0 */ ) { @@ -74,31 +95,19 @@ static Word16 tcx_arith_estimate_scale( scale = ISqrt16(scale, &s); *scale_e = s; - return scale; } -#define kMaxNumHeapElems 10 - -typedef struct HeapElem -{ - Word32 mScore; /* Sort key */ - Word16 mIndex; /* Original index */ -} HeapElem; - -typedef struct Heap -{ - HeapElem mElem[2*kMaxNumHeapElems+1]; - Word16 mSize; -} Heap; - +/*-------------------------------------------------------------------* + * MinHeapify_i() + * + * + *-------------------------------------------------------------------*/ static void MinHeapify_i(Heap *H, Word16 i) { Word16 left, right, largest; HeapElem T; - - left = add(shl(i, 1), 1); right = add(left, 1); largest = i; @@ -152,15 +161,19 @@ static void MinHeapify_i(Heap *H, Word16 i) } } - +/*-------------------------------------------------------------------* + * tcx_arith_find_max_scale() + * + * + *-------------------------------------------------------------------*/ static Word16 tcx_arith_find_max_scale( /* Q15-e */ const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ + const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ + const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ Word16 *scale_e /* o: scale exponent Q0 */ ) { @@ -170,20 +183,15 @@ static Word16 tcx_arith_find_max_scale( /* Q15-e */ Word16 tmpi1, tmpi2; const Word32 limit = -325614240l/*-9.70406052784f Q25*/; /* = ln(1/16384): log of smallest allowed probability */ - - /* Find the top most offending lines according to probability estimates */ - heap.mSize = kMaxNumHeapElems; - move16(); - - FOR (i = 0; i < heap.mSize; i++) + FOR (i = 0; i < kMaxNumHeapElems; i++) { heap.mElem[i].mIndex = 0; move16(); heap.mElem[i].mScore = L_deposit_l(0); } - tmp = add(shl(heap.mSize, 1), 1); + tmp = add(shl(kMaxNumHeapElems, 1), 1); FOR (; i < tmp; i++) { heap.mElem[i].mScore = L_deposit_h(0x7FFF); @@ -207,12 +215,12 @@ static Word16 tcx_arith_find_max_scale( /* Q15-e */ /* Also limit scale to avoiding saturation of the gain quantizer */ /* scale = 1.0f/(float)sqrt(L_frame*0.5f); */ tmp = 15-1; - move16(); scale = ISqrt16(L_frame, &tmp); + move16(); *scale_e = tmp; move16(); - FOR (i = 0; i < heap.mSize; i++) + FOR (i = 0; i < kMaxNumHeapElems; i++) { k = heap.mElem[i].mIndex; move16(); @@ -278,16 +286,20 @@ static Word16 tcx_arith_find_max_scale( /* Q15-e */ return scale; } - -/* Returns: index of highest freq. nonzero line (-1 if all zeros) */ +/*-------------------------------------------------------------------* + * tcx_arith_find_kMax() + * + * + * Returns: index of highest freq. nonzero line (-1 if all zeros) + *-------------------------------------------------------------------*/ static Word16 tcx_arith_find_kMax( const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word16 scale, /* i: scalar quantizer scale Q15-e */ - Word16 scale_e, /* i: scale exponent Q0 */ - Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - const Word8 deadzone_flags[] /* i: line-wise deadzone control */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 scale, /* i: scalar quantizer scale Q15-e */ + const Word16 scale_e, /* i: scale exponent Q0 */ + const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ + const Word8 deadzone_flags[] /* i: line-wise deadzone control */ ) { Word16 kMax; @@ -311,21 +323,24 @@ static Word16 tcx_arith_find_kMax( return kMax; } -#define LOG2_E 23637/*1.44269504089f Q14*/ - -/* Returns: best scale Q15-e */ +/*-------------------------------------------------------------------* + * tcx_arith_rateloop() + * + * + * Returns: best scale Q15-e + *-------------------------------------------------------------------*/ static Word16 tcx_arith_rateloop( - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - Word16 target_bits, /* i: target bit budget Q0 */ - Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - const Word8 deadzone_flags[], /* i: line-wise deadzone control Q0 */ - Word16 *target_bits_fac, /* i/o: scale estimator compensation Q14 */ - Word16 *scale_e /* o: scale exponent Q0 */ + const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ + const Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ + const Word16 L_frame, /* i: number of spectral lines Q0 */ + const Word16 envelope[], /* i: scaled envelope Q15-e */ + const Word16 envelope_e, /* i: scaled envelope exponent Q0 */ + const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ + const Word16 target_bits, /* i: target bit budget Q0 */ + const Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ + const Word8 deadzone_flags[], /* i: line-wise deadzone control Q0 */ + Word16 *target_bits_fac, /* i/o: scale estimator compensation Q14 */ + Word16 *scale_e /* o: scale exponent Q0 */ ) { Word16 k, kMax, q; @@ -392,14 +407,8 @@ static Word16 tcx_arith_rateloop( tmp2 = L_msu0(L_sub(max_complexity, 48), L_frame, 11); WHILE (LT_32(complexity, tmp2)) { - kMax = tcx_arith_find_kMax( - abs_spectrum, - abs_spectrum_e, - L_frame, - scale, *scale_e, - deadzone, - deadzone_flags - ); + kMax = tcx_arith_find_kMax(abs_spectrum, abs_spectrum_e, L_frame, scale, *scale_e, deadzone, deadzone_flags); + complexity = L_mac0(L_mac0(L_add(complexity, 16+2), sub(L_frame, kMax), 5), kMax, 2); bits = /*estimator_undershoot * kMax +*/ L_deposit_l(1<<9); /* Q9 */ @@ -491,12 +500,16 @@ static Word16 tcx_arith_rateloop( return scale_best; } - -/* Returns: number of bits consumed */ +/*-------------------------------------------------------------------* + * tcx_arith_encode() + * + * + * Returns: number of bits consumed + *-------------------------------------------------------------------*/ static Word16 tcx_arith_encode( Word16 q_abs_spectrum[], /* i/o: scalar quantized absolute spectrum Q0 */ const Word16 signs[], /* i: signs */ - Word16 kMax, /* i: number of nonzero spectral lines to code Q0 */ + const Word16 kMax, /* i: number of nonzero spectral lines to code Q0 */ Word16 L_frame, /* i: nominal number of spectral lines Q0 */ const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ Word16 target_bits, /* i: target bit budget Q0 */ @@ -620,28 +633,32 @@ static Word16 tcx_arith_encode( IF (EQ_16(kEncoded, sub(L_frame, 1))) /* RESQ bits possibly available */ { /* Limit target bits to actually needed bits */ - target_bits = add(add(bp, 16), extract_l(as.vobf)); + target_bits = add(add(bp, 16), extract_l(as.value)); } return ari_done_cbr_encoding_14bits(prm, bp, target_bits, &as); } - +/*-------------------------------------------------------------------* + * tcx_arith_encode_envelope() + * + * + *-------------------------------------------------------------------*/ void tcx_arith_encode_envelope( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ - Word16 L_frame, /* i: frame or MDCT length Q0 */ - Word16 L_spec, /* i: frame or MDCT length Q0 */ - Encoder_State_fx *st, /* i/o: coder state */ - const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ - Word16 target_bits, /* i: number of available bits Q0 */ - Word16 prm[], /* o: bitstream parameters Q0 */ - Word8 use_hm, /* i: use HM in current frame? */ - Word16 prm_hm[], /* o: HM parameter area Q0 */ - Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o: bits used for signaling Q0 */ - Word16 *nf_seed /* o: noise filling seed Q0 */ - ,Word16 low_complexity /* i: low-complexity flag Q0 */ + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i: frame or MDCT length Q0 */ + const Word16 L_spec, /* i: frame or MDCT length Q0 */ + Encoder_State_fx *st, /* i/o: coder state */ + const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ + Word16 target_bits, /* i: number of available bits Q0 */ + Word16 prm[], /* o: bitstream parameters Q0 */ + const Word8 use_hm, /* i: use HM in current frame? */ + Word16 prm_hm[], /* o: HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o: bits used for signaling Q0 */ + Word16 *nf_seed, /* o: noise filling seed Q0 */ + const Word16 low_complexity /* i: low-complexity flag Q0 */ ) { Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ @@ -650,7 +667,7 @@ void tcx_arith_encode_envelope( Word16 exponents[N_MAX_ARI]; /* Q15 */ Word16 L_spec_core; Word16 *q_spectrum; - TCX_config *tcx_cfg; + TCX_CONFIG_HANDLE hTcxCfg; Word16 scale, scale_e; Word16 k, kMax; Word16 deadzone; @@ -659,15 +676,14 @@ void tcx_arith_encode_envelope( Word16 hm_bits; Word32 L_tmp, L_tmp2; Word16 tmp; - + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; assert(L_spec <= N_MAX_ARI); - - tcx_cfg = &st->tcx_cfg; - deadzone = tcx_cfg->sq_rounding; + hTcxCfg = st->hTcxCfg; + deadzone = hTcxCfg->sq_rounding; move16(); - deadzone_flags = st->memQuantZeros; + deadzone_flags = hTcxEnc->memQuantZeros; *signaling_bits = 0; move16(); @@ -677,15 +693,7 @@ void tcx_arith_encode_envelope( gamma_uw = st->inv_gamma; move16(); - tcx_arith_render_envelope( - A_ind, - L_frame, - L_spec, - tcx_cfg->preemph_fac, - gamma_w, - gamma_uw, - env - ); + tcx_arith_render_envelope(A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env); FOR (k = 0; k < L_spec; k++) { @@ -699,18 +707,7 @@ void tcx_arith_encode_envelope( IF (use_hm != 0) { - tcx_hm_analyse( - spectrum, - spectrum_e, - L_spec, - env, - target_bits, - tcx_cfg->coder_type, - prm_hm, - tcxltp_pitch, - st->tcxltp_gain, - &hm_bits - ); + tcx_hm_analyse(spectrum, spectrum_e, L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, hTcxEnc->tcxltp_gain, &hm_bits); target_bits = sub(target_bits, hm_bits); *signaling_bits = add(*signaling_bits, hm_bits); @@ -727,19 +724,11 @@ void tcx_arith_encode_envelope( move16(); if (st->igf) { - L_spec_core = s_min(L_spec_core, st->hIGFEnc.infoStartLine); + L_spec_core = s_min(L_spec_core, st->hIGFEnc->infoStartLine); } envelope = (Word16*)env; - tcx_arith_scale_envelope( - L_spec, - L_spec_core, - env, - target_bits, - low_complexity, - envelope, - &envelope_e - ); + tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e); tmp = sub(envelope_e, 1+15); FOR (k = 0; k < L_spec; k++) @@ -747,29 +736,10 @@ void tcx_arith_encode_envelope( exponents[k] = round_fx(expfp(envelope[k], tmp)); } - scale = tcx_arith_rateloop( - spectrum, - *spectrum_e, - L_spec, - envelope, - envelope_e, - exponents, - target_bits, - deadzone, - deadzone_flags, - &st->LPDmem.tcx_target_bits_fac, - &scale_e - ); + scale = tcx_arith_rateloop(spectrum, *spectrum_e, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &(hTcxEnc->tcx_target_bits_fac), &scale_e); /* Final quantization */ - kMax = tcx_arith_find_kMax( - spectrum, - *spectrum_e, - L_spec, - scale, scale_e, - deadzone, - deadzone_flags - ); + kMax = tcx_arith_find_kMax( spectrum, *spectrum_e, L_spec, scale, scale_e, deadzone, deadzone_flags ); q_spectrum = (Word16*)env; /* Reuse buffer */ @@ -782,15 +752,7 @@ void tcx_arith_encode_envelope( } /* Final encoding */ - *arith_bits = tcx_arith_encode( - q_spectrum, - signs, - kMax, - L_spec, - exponents, - target_bits, - prm - ); + *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm); /* Multiply back the signs */ L_tmp2 = L_deposit_l(0); diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index 5b968bd..3162813 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -1,11 +1,15 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" + +/*-------------------------------------------------------------------* + * Local prototypes + *-------------------------------------------------------------------*/ +static void wrte_cv(BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 * bits); /*-------------------------------------------------------------------* * Function AVQ_cod() * @@ -13,12 +17,12 @@ * Split algevraic vector quantizer (AVQ) base on RE8 latice * *-------------------------------------------------------------------*/ -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv /* i: number of subvectors (lg=Nsv*8) */ - ,const Word16 Q_in_ref /* i: Scaling input */ +void AVQ_cod_fx( /* o: comfort noise gain factor */ + const Word16 xri[], /* i: vector to quantize */ + Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const Word16 NB_BITS, /* i: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ + const Word16 Q_in_ref /* i: Scaling input */ ) { Word16 i, l, iter, c[8]; @@ -146,25 +150,31 @@ void AVQ_cod_fx( /* o: comfort noise gain factor */ /*-----------------------------------------------------------------* -* AVQ_encmux() -* -* Encode subvectors and write indexes into the bitstream -*-----------------------------------------------------------------*/ + * AVQ_encmux() + * + * Encode subvectors and write indexes into the bitstream + *-----------------------------------------------------------------*/ void AVQ_encmux_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 extl, /* i : extension layer */ - Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 extl, /* i : extension layer */ + Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[] /* o : AVQ nq index */ + Word16 *nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors */ + Word16 nq_out[], /* o : AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ ) { - Word16 i, j=0, bits, pos, pos_max, overflow, pos_tmp; + Word16 i, j=0, bits, pos, pos_max, overflow, pos_tmp, bit_tmp; Word16 sort_idx[NSV_MAX], nq[NSV_MAX], kv[NSV_MAX*8]; Word16 *t; UWord16 I[NSV_MAX]; Word16 nq_ind, i_ind, kv_ind; + Word16 nq_est, unused_bits, unused_bits_idx; + Word16 bitsMod, Nsvm1, Nsvm2; + Word16 unusedbitsFlag; + Word16 svOrder[NSV_MAX], k, nullVec, dummy_bits; test(); IF( EQ_16(extl,SWB_BWE_HIGHRATE)||EQ_16(extl,FB_BWE_HIGHRATE)) @@ -191,7 +201,9 @@ void AVQ_encmux_fx( I[i] = (UWord16)-1; move16(); } - + unusedbitsFlag = 0; + bitsMod = 0; + move16();move16(); /*----------------------------------------------------------------- * Encode subvectors and fix possible overflows in total bit budget, * i.e. find for each subvector a codebook index nq (nq=0,2,3,4,...,NSV_MAX), @@ -282,7 +294,27 @@ void AVQ_encmux_fx( } } } - + nullVec = 0; + Nsvm1 = sub(Nsv, 1); + Nsvm2 = sub(Nsvm1, 1); + dummy_bits = 0; + svOrder[Nsvm1] = trgtSvPos; + svOrder[0] = 0; + svOrder[1] = 1; + i = 2; + j = i; + move16(); move16(); move16(); move16(); move16(); move16(); + if (EQ_16(avq_bit_sFlag, 2)) + { + j = add(i, 1); + } + WHILE (LT_16(i, Nsvm1)) + { + svOrder[i] = j; + move16(); + i++; /*ptr*/ + j = add(j, 1); + } /* write indexes to the bitstream */ /* ============================== */ @@ -290,10 +322,36 @@ void AVQ_encmux_fx( move16(); overflow = 0; move16(); - FOR( i=0; i 0) + { + test();test(); + IF (EQ_16(sub(*nb_bits, bits), 7) || LT_16(bits, BIT_SAVING_LOW_THR) || GE_16(bits, BIT_SAVING_HIGH_THR)) + { + avq_bit_sFlag = 0; + move16(); + } + ELSE + { + BREAK; + } + } + + if( EQ_16(sub(i_mult2(5,nq[k]),1),bits)) /* check the overflow */ { overflow = 1; move16(); @@ -301,79 +359,172 @@ void AVQ_encmux_fx( IF( GT_16(bits,8)) { - /* write the unary code for nq[i] */ - j = sub(nq[i], 1); - IF ( nq[i] > 0 ) + /* write the unary code for nq[i] */ + j = sub(nq[k], 1); + IF ( nq[k] > 0 ) { /* write the unary code */ FOR( ; j > 16; j -= 16 ) { - push_indice_fx( st_fx, nq_ind, 65535, 16 ); + push_indice_fx( hBstr, nq_ind, 65535, 16 ); bits = sub(bits,16); } IF ( j > 0 ) { - push_indice_fx( st_fx, nq_ind, extract_l(L_sub(L_shl(1L,j),1L)), j ); + push_indice_fx( hBstr, nq_ind, extract_l(L_sub(L_shl(1L,j),1L)), j ); bits = sub(bits,j); } } IF ( !overflow ) { /* write the stop bit */ - push_indice_fx( st_fx, nq_ind, 0, 1 ); + push_indice_fx( hBstr, nq_ind, 0, 1 ); bits = sub(bits,1); } - /* write codebook indices (rank I and event. Voronoi index kv) */ - IF( nq[i] == 0 ) /* Q0 */ + wrte_cv(hBstr, nq[k], i_ind, kv_ind, I[k], &kv[shl(k, 3 )], &bits); + } + } /* for */ + /* Bit Saving Solution */ + test(); + IF (avq_bit_sFlag > 0 && bits > 8) + { +PMT("code not validated yet") + bitsMod = s_and(bits, 4/*bits%5*/); + i = svOrder[Nsvm1]; + move16(); + IF ( NE_16(i, Nsvm1)) + { + nullVec = 0; + move16(); + FOR (j = i; j < Nsv - 1; j++) { - /* nothing to write */ + if (nq[svOrder[j]] == 0) + { + nullVec = add(nullVec,1); + } } - ELSE IF( LT_16(nq[i],5)) /* Q2, Q3, Q4 */ + /*nq_est = bits / 5;*/ + nq_est = mult(bits,6554); + assert(nq_est == bits / 5); + + test();test();test();test();test();test();test();test();test();test();test(); + IF ((bitsMod > 0 || (EQ_16(nullVec, 4) && EQ_16(nq_est, 5))) && NE_16(bitsMod, 4) && GE_16(add(bits, nullVec), add(add(shl(nq_est ,2), nq_est),4))/*5 * nq_est + 4*/ && nq[svOrder[Nsvm2]] == 0) /* detect need for dummy bits */ { - push_indice_fx( st_fx, i_ind, I[i], shl(nq[i],2) ); - bits = sub(bits, shl(nq[i],2)); + dummy_bits = sub(5, bitsMod); + bits = add(bits, dummy_bits); /* add dummy bits */ + bitsMod = 0; + move16(); } - ELSE IF( s_and(nq[i],1) == 0 ) /* Q4 + Voronoi extensions r=1,2,3,... */ + ELSE IF (nq_est > 4 && ((bitsMod == 0 && nullVec > 3 && nullVec < 6) || (bitsMod == 4 && nullVec == 5)) && nq[svOrder[Nsvm2]] == 0) /* wasted bits 4, 5 for nq 6,7..*/ { - push_indice_fx( st_fx, i_ind, I[i], 4*4 ); - bits = sub(bits,4*4); - pos = sub(shr(nq[i],1), 2); /* Voronoi order determination */ - move16(); /*ptr init*/ - FOR( j=0; j<8; j++ ) + overflow = 0; + move16(); + if (s_and(add(bitsMod, nullVec), 4) != 0) { - push_indice_fx( st_fx, kv_ind, kv[i*8+j], pos ); + overflow = 1; + move16(); } + dummy_bits = add(nullVec, overflow); + bits = add(bits, dummy_bits); /* add dummy bits */ + bitsMod = 0; + move16(); + } + } - bits = sub(bits,shl(pos,3)); + overflow = 1; + move16(); + IF (NE_16(bitsMod, 4)) + { + overflow = 0; + move16(); + bits = sub(bits, bitsMod); + } + bits = add(bits, overflow); /*add fake bit */ + unused_bits = sub(bits, add(shl(nq[i],2), nq[i])); + if (nq[i] == 0) /*no bit savings*/ + { + unused_bits = sub(unused_bits, 1); /*Stop Bit*/ + } + /*unused_bits_idx = (int16_t)unused_bits / 5;*/ + unused_bits_idx = mult(unused_bits, 6554); + assert(unused_bits_idx == unused_bits / 5); + unusedbitsFlag = 0; + move16(); + IF (dummy_bits == 0) + { + test(); test(); + IF (EQ_16(unused_bits_idx, 1) && GT_16(bits, BIT_SAVING_LOW_THR)) + { + unused_bits_idx = 0; + unusedbitsFlag = 1; + move16();move16(); } - ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ + ELSE IF (unused_bits_idx == 0 && GT_16(bits, BIT_SAVING_LOW_THR)) { - push_indice_fx( st_fx, i_ind, I[i], 4*3 ); - bits = sub(bits, 4*3); + unused_bits_idx = 1; + unusedbitsFlag = -1; + move16(); move16(); + } + } - pos = sub(shr(nq[i],1), 1); /* Voronoi order determination */ - move16(); /* ptr init */ - FOR( j=0; j<8; j++ ) - { - push_indice_fx( st_fx, kv_ind, kv[i*8+j], pos ); - } + j = unused_bits_idx; + move16(); + /*Encode Unused Bit Unary Codeword */ + IF (j > 0) + { + /* write the unary code */ + push_indice_fx(hBstr, nq_ind, sub(shl(1, j), 1), j); + } - bits = sub(bits,shl(pos,3)); - } + IF (nq[i] != 0) + { + /* write the stop bit */ + push_indice_fx(hBstr, nq_ind, 0, 1); } - } /* for */ + /*Compute AVQ code book number from unused Bits */ + bit_tmp = add(unusedbitsFlag, unused_bits_idx); + /*nq_est = (int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx)));*/ + nq_est = mult(6554, sub(bits, add(shl(bit_tmp, 2), bit_tmp))); + assert((int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx))) == nq_est); + + if (EQ_16(nq_est, 1)) + { + nq_est = 0; + move16(); + } + bits = sub(bits, overflow); + + bits = sub(bits, j); + + if (nq_est != 0) + { + bits = sub(bits, 1); + } + nq[i] = nq_est; + move16(); + + /* write codebook indices (rank I and event. Voronoi index kv) */ + wrte_cv(hBstr, nq[i], i_ind, kv_ind, I[i], &kv[shl(i, 3)], &bits); + + bits = sub (bits, dummy_bits); + + if (NE_16(bitsMod, 4)) + { + bits = add(bits, bitsMod); + } + } *nb_bits = bits; move16(); - FOR( i=0; i -#include -#include +#include #include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "stl.h" - - +/*---------------------------------------------------------------------* + * bass_pf_enc() + * + * Low-frequency postfiltering, decoder parammeter estimation + *---------------------------------------------------------------------*/ Word16 bass_pf_enc( - Word16 *orig, /* (i) : 12.8kHz original signal Q0 */ - Word16 *syn, /* (i) : 12.8kHz synthesis to postfilter Q0 */ - Word16 *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) Q0 */ - Word16 *gainT_sf, /* (i) : Pitch gain for all subframes (gainT_sf[16]) Q14 */ - Word16 l_frame, /* (i) : frame length (should be multiple of l_subfr) Q0 */ - Word16 l_subfr, /* (i) : sub-frame length (60/64) Q0 */ - Word16 *gain_factor_param, /* (o) : quantized gain factor Q0 */ - Word16 mode, /* (i) : coding mode of adapt bpf */ - struct MEM_BPF *mem_bpf /* i/o : memory state */ + const Word16* orig, /* i : 12.8kHz original signal Q0 */ + const Word16* syn, /* i : 12.8kHz synthesis to postfilter Q0 */ + const Word16* T_sf, /* i : Pitch period for all subframes (T_sf[16]) Q0 */ + const Word16* gainT_sf, /* i : Pitch gain for all subframes (gainT_sf[16]) Q14 */ + const Word16 l_frame, /* i : frame length (should be multiple of l_subfr) Q0 */ + const Word16 l_subfr, /* i : sub-frame length (60/64) Q0 */ + Word16 *gain_factor_param, /* o : quantized gain factor Q0 */ + const Word16 mode, /* i : coding mode of adapt bpf */ + struct MEM_BPF *mem_bpf /* i/o: memory state */ ) { Word16 i, j, sf, i_subfr, T, lg, l_filt; diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 6ca3dca..2645057 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -2,25 +2,29 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - +#include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" #include "basop_util.h" +#include "ivas_cnst.h" /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ +#define BWD_MIN_BRATE_WIDER_BW_MDCT IVAS_48k +#define BWD_MIN_BRATE_WIDER_BW_ISM IVAS_32k +#define BWD_MAX_BRATE_WIDER_BW_MDCT IVAS_80k +#define BWD_MAX_BRATE_WIDER_BW_ISM IVAS_64k #define ALPHA_BWD_FX 24576 /* 0.75 in Q15*/ #define BWD_LT_THRESH_FX 19661 /* 0.6 in Q15*/ #define BWD_COUNT_MAX 100 #define BWD_COUNT_WIDER_BW 10 +#define BWD_COUNT_WIDER_BW_MDCT 0 #define BWD_N_BINS_MAX 13 @@ -33,19 +37,21 @@ *--------------------------------------------------------------------*/ void bw_detect_fx( - Encoder_State_fx *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : input signal */ - const Word16 localVAD, - Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ - Word16 *cldfbBuf_Ener_Exp /* i : CLDFB Energy Exponent */ + Encoder_State_fx *st, /* i/o: Encoder State */ + const Word16 signal_in[], /* i : input signal */ + Word16* spectrum, /* i : MDCT spectrum */ + const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ + const Word16 *cldfbBuf_Ener_Exp,/* i : CLDFB Energy Exponent */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t mct_on /* i : flag MCT mode */ ) { Word16 Q_dct; Word16 i, j, k, bw_max, bin_width, n_bins; Word16 max_NB, max_WB, max_SWB, max_FB, mean_NB, mean_WB, mean_SWB, mean_FB; /* Q11*/ const Word16 *pt, *pt1; - Word16 spect[BWD_TOTAL_WIDTH], spect_bin[BWD_N_BINS_MAX]; - Word32 spect32[BWD_TOTAL_WIDTH],in_win32[BWD_TOTAL_WIDTH]; + Word16 spect[L_FRAME48k], spect_bin[BWD_N_BINS_MAX]; + Word32 spect32[L_FRAME48k],in_win32[BWD_TOTAL_WIDTH]; Word16 e_tmp, f_tmp; Word32 L_tmp, sum32; @@ -57,14 +63,18 @@ void bw_detect_fx( Word16 cldfb_bin_width = 4; const Word32 *pt32; Word32 max_NB32, max_WB32, max_SWB32, max_FB32, mean_NB32, mean_WB32, mean_SWB32, mean_FB32; /* Q11*/ /* we need Word32 for the new cldfb energy vectors */ - - /* only for debugging */ - /* float cldfbBuf_Ener_float[CLDFB_NO_CHANNELS_MAX]; - for(i=0; i< CLDFB_NO_CHANNELS_MAX; i++){ - cldfbBuf_Ener_float[i] = (enerBuffer[i] * pow (2, -(31 - cldfbBuf_Ener_Exp[i]))); - } - */ - + Word16 bwd_count_wider_bw, l_frame; +#ifndef IVAS_CODE_BWD + MY_UNUSED_Array(spectrum) +#endif + + bwd_count_wider_bw = BWD_COUNT_WIDER_BW; move16(); + test();test();test();test();test(); + if (st->ini_frame_fx > 0 && ((EQ_16(st->element_mode, IVAS_CPE_MDCT) && (GE_32(st->element_brate, BWD_MIN_BRATE_WIDER_BW_MDCT) || mct_on)) || + (EQ_16(ivas_format, ISM_FORMAT) && GE_32(st->element_brate, BWD_MIN_BRATE_WIDER_BW_ISM)))) + { + bwd_count_wider_bw = BWD_COUNT_WIDER_BW_MDCT; move16(); + } IF( GT_32(st->input_Fs_fx,8000)) { @@ -245,37 +255,52 @@ void bw_detect_fx( n_bins = BWD_N_BINS_MAX; move16(); /* spectrum to 19.5 kHz */ } - - /*---------------------------------------------------------------------* - * windowing of the input signal - *---------------------------------------------------------------------*/ - Q_dct = 0; + Q_dct = 0; move16(); - pt = signal_in; - pt1 = hann_window_320_fx; - /* 1st half of the window */ - FOR( i=0; i Q16*/ + /*---------------------------------------------------------------------* + * windowing of the input signal + *---------------------------------------------------------------------*/ + pt = signal_in; + pt1 = hann_window_320_fx; + /* 1st half of the window */ + FOR(i = 0; i < BWD_TOTAL_WIDTH / 2; i++) + { + /*in_win[i] = *pt++ * *pt1++;*/ + in_win32[i] = L_mult(*pt++,*pt1++); + move32(); /* Q0*Q15 -> Q16*/ + } + pt1--; + /* 2nd half of the window */ + FOR(; i < BWD_TOTAL_WIDTH; i++) + { + /*in_win[i] = *pt++ * *pt1--;*/ + in_win32[i] = L_mult(*pt++,*pt1--); + move32(); + } + edct_fx(in_win32, spect32, BWD_TOTAL_WIDTH, &Q_dct /*,st->element_mode*/); + + FOR(i = 0; i < BWD_TOTAL_WIDTH; i++) + { + spect[i] = round_fx(L_shr(spect32[i],Q_dct)); + } + Q_dct = -2; + move16(); } - pt1--; - /* 2nd half of the window */ - FOR(; iinput_Fs / FRAMES_PER_SEC); + if (st->core == TCX_10_CORE) + { + l_frame /= 2; + } - FOR( i=0; ilp_noise > 30 )*/ test(); - IF( localVAD || GT_16(st->lp_noise_fx,7680)) + IF( st->localVAD || GT_16(st->lp_noise_fx,7680)) { /*st->lt_mean_NB_fx = ALPHA_BWD * st->lt_mean_NB_fx + (1-ALPHA_BWD) * mean_NB;*/ L_tmp = L_mult(ALPHA_BWD_FX, st->lt_mean_NB_fx); /* Q15 * Q11 -> Q27 */ @@ -710,21 +735,21 @@ void bw_detect_fx( /* switching to a higher BW */ IF( EQ_16(st->last_input_bwidth_fx,NB)) { - IF( GT_16(st->count_WB_fx,BWD_COUNT_WIDER_BW)) + IF( GT_16(st->count_WB_fx, bwd_count_wider_bw)) { st->input_bwidth_fx = WB; move16(); st->count_WB_fx = BWD_COUNT_MAX; move16(); - IF( GT_16(st->count_SWB_fx,BWD_COUNT_WIDER_BW)) + IF( GT_16(st->count_SWB_fx, bwd_count_wider_bw)) { st->input_bwidth_fx = SWB; move16(); st->count_SWB_fx = BWD_COUNT_MAX; move16(); - IF( GT_16(st->count_FB_fx,BWD_COUNT_WIDER_BW)) + IF( GT_16(st->count_FB_fx, bwd_count_wider_bw)) { st->input_bwidth_fx = FB; move16(); @@ -738,14 +763,14 @@ void bw_detect_fx( test(); IF( EQ_16(st->last_input_bwidth_fx,WB)&>_32(st->input_Fs_fx,16000)) { - IF( GT_16(st->count_SWB_fx,BWD_COUNT_WIDER_BW)) + IF( GT_16(st->count_SWB_fx, bwd_count_wider_bw)) { st->input_bwidth_fx = SWB; move16(); st->count_SWB_fx = BWD_COUNT_MAX; move16(); - IF( GT_16(st->count_FB_fx,BWD_COUNT_WIDER_BW)) + IF( GT_16(st->count_FB_fx, bwd_count_wider_bw)) { st->input_bwidth_fx = FB; move16(); @@ -758,7 +783,7 @@ void bw_detect_fx( test(); IF( EQ_16(st->last_input_bwidth_fx,SWB)&>_32(st->input_Fs_fx,32000)) { - IF( GT_16(st->count_FB_fx,BWD_COUNT_WIDER_BW)) + IF( GT_16(st->count_FB_fx, bwd_count_wider_bw)) { st->input_bwidth_fx = FB; move16(); @@ -848,11 +873,35 @@ void bw_detect_fx( st->input_bwidth_fx = st->max_bwidth_fx; move16(); } + IF (EQ_16(st->element_mode, EVS_MONO) ) + { + set_bw(-1, -1, st, st->codec_mode); + } + + + return; +} +/*-------------------------------------------------------------------* + * set_bw() + * + * Set and limit the encoded bandwidth + *-------------------------------------------------------------------*/ + +void set_bw( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + Encoder_State_fx* st, /* i/o: Encoder State */ + const Word16 codec_mode /* i : codec mode */ +) +{ + Word32 total_brate_fx, L_tmp; + /* initialization */ + st->bwidth_fx = st->input_bwidth_fx; + move16(); /* Set and limit the encoded bandwidth */ - IF ( EQ_16(st->codec_mode,MODE1)) + IF(EQ_16(st->codec_mode, MODE1)) { - Word32 total_brate_fx; st->bwidth_fx = st->input_bwidth_fx; move16(); @@ -865,23 +914,72 @@ void bw_detect_fx( test(); test(); test(); - IF ( LE_32(total_brate_fx, ACELP_9k60)&&NE_16(st->bwidth_fx,NB)&&NE_16(st->bwidth_fx,WB)) + IF (GT_16(element_mode, IVAS_SCE)) + { + PMT("this IVAS_SCE section has not been verified ") + IF (LT_32(element_brate, MIN_BRATE_SWB_STEREO)) + { + st->bwidth_fx = WB; + move16(); + } + ELSE + { + test(); + IF (st->idchan == 0 || EQ_16(element_mode, IVAS_CPE_MDCT)) + { + IF (GE_32(element_brate, MIN_BRATE_FB_STEREO)) + { + st->bwidth_fx = s_min(st->bwidth_fx, FB); + } + ELSE + { + st->bwidth_fx = s_min(st->bwidth_fx, SWB); + } + st->bwidth_fx = s_max(st->bwidth_fx, WB); + } + ELSE + { + st->bwidth_fx = WB; + move16(); + } + } + } + ELSE IF (EQ_16(element_mode, IVAS_SCE)) + { + test(); + IF ( LT_32(element_brate, MIN_BRATE_SWB_SCE) || LT_16(st->bwidth_fx, WB) ) + { + st->bwidth_fx = WB; + move16(); + } + ELSE IF (GT_16(st->bwidth_fx, SWB) && ((LT_32(element_brate, MIN_BRATE_FB_STEREO) && !st->is_ism_format) || (LT_32(element_brate, MIN_BRATE_FB_ISM) && st->is_ism_format))) + { + st->bwidth_fx = SWB; + move16(); + } + ELSE IF (GT_32(element_brate, BWD_MAX_BRATE_WIDER_BW_ISM)) + { + st->bwidth_fx = st->max_bwidth_fx; move16(); + } + } + /* element_mode == EVS_MONO */ + ELSE IF(LE_32(total_brate_fx, ACELP_9k60) && GT_16(st->bwidth_fx, WB) ) { st->bwidth_fx = WB; move16(); } - ELSE IF ( GE_32(st->total_brate_fx,ACELP_13k20)&&LE_32(st->total_brate_fx,ACELP_16k40)&>_16(st->bwidth_fx,SWB)) + ELSE IF(GE_32(st->total_brate_fx, ACELP_13k20) && LE_32(st->total_brate_fx, ACELP_16k40) && GT_16(st->bwidth_fx, SWB)) { st->bwidth_fx = SWB; move16(); } - ELSE IF ( GE_32(st->total_brate_fx,ACELP_32k)&<_16(st->bwidth_fx,WB)) + ELSE IF(GE_32(st->total_brate_fx, ACELP_32k) && LT_16(st->bwidth_fx, WB)) { st->bwidth_fx = WB; move16(); } } - ELSE + ELSE IF (EQ_16(codec_mode , MODE2) ) { Word16 n, bits_frame_nominal; @@ -891,25 +989,120 @@ void bw_detect_fx( Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ bits_frame_nominal = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - FOR (n=0; nrf_mode,1)) + if (EQ_16(st->rf_mode,1)) { tmpbandwidthMin = WB; } st->bwidth_fx = s_max(s_min(st->input_bwidth_fx, FrameSizeConfig[n].bandwidth_max), tmpbandwidthMin); } +} +#ifdef IVAS_CODE_BWD + +/*-------------------------------------------------------------------* + * set_bw_stereo() + * + * Set encoded bandwidth for stereo (CPE) channels + *-------------------------------------------------------------------*/ + +void set_bw_stereo( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures */ +) +{ + Encoder_State** sts = hCPE->hCoreCoder; + + if (hCPE->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT) + { + sts[0]->bwidth = sts[0]->max_bwidth; + sts[1]->bwidth = sts[1]->max_bwidth; + } + else if (hCPE->element_mode == IVAS_CPE_MDCT) + { + /* ensure that both CPE channels have the same audio band-width */ + if (sts[0]->input_bwidth == sts[1]->input_bwidth) + { + sts[0]->bwidth = sts[0]->input_bwidth; + sts[1]->bwidth = sts[0]->input_bwidth; + } + else + { + sts[0]->bwidth = max(sts[0]->input_bwidth, sts[1]->input_bwidth); + sts[1]->bwidth = max(sts[0]->input_bwidth, sts[1]->input_bwidth); + } + } + + sts[0]->bwidth = max(sts[0]->bwidth, WB); + sts[1]->bwidth = max(sts[1]->bwidth, WB); return; } +/*-------------------------------------------------------------------* + * set_bw_mct() + * + * Set encoded bandwidth for MCT + *-------------------------------------------------------------------*/ + + /*! r: flag indicating whether the coded BW has changed */ +int16_t set_bw_mct( + CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ + const int16_t nCPE /* i : number of CPEs */ +) +{ + Encoder_State* sts[MCT_MAX_CHANNELS]; + int16_t ch, cpe_id; + int16_t mct_bwidth, last_mct_bwidth, bw_changed; + + mct_bwidth = WB; /* minimum coded audio band-width */ + last_mct_bwidth = hCPE[0]->hCoreCoder[0]->last_bwidth; /* supposes that LFE is not in the first channel */ + + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + sts[ch] = hCPE[cpe_id]->hCoreCoder[ch]; + if (st->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + { + continue; + } + + mct_bwidth = max(mct_bwidth, sts[ch]->input_bwidth); + } + } + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + if (hCPE[cpe_id]->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT) + { + mct_bwidth = max(mct_bwidth, hCPE[cpe_id]->hCoreCoder[0]->max_bwidth); + } + } + bw_changed = 0; + if (mct_bwidth != last_mct_bwidth) + { + bw_changed = 1; + + for (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + sts[ch] = hCPE[cpe_id]->hCoreCoder[ch]; + sts[ch]->bwidth = mct_bwidth; + } + } + } + + return bw_changed; +} + +#endif \ No newline at end of file diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 3bdc655..d44313f 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1,15 +1,15 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_mpy.h" +#include /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -20,40 +20,35 @@ #define INT_L 8 /*---------------------------------------------------------------------* - * Local functions + * Local function prototypes *---------------------------------------------------------------------*/ -static void shb_CNG_encod_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 update_fx /* i : SID update flag */ -); -static Word16 shb_DTX_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */ -); - +static void shb_CNG_encod_fx(Encoder_State_fx *st_fx, const Word16 update_fx ); +static Word16 shb_DTX_fx(Encoder_State_fx *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); +/*---------------------------------------------------------------------* +* CNG_enc() +* +* Confort noise generation for the coder +*---------------------------------------------------------------------*/ void CNG_enc_fx( Encoder_State_fx *st_fx,/* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ + const Word16* lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 burst_ho_cnt, /* i : hangover frames at end of speech burst Q0 */ - Word16 Q_new /* i : Q value of speech */ - ,Word32 *q_env - ,Word16 *sid_bw - ,Word16 *exc_mem2 + Word16 Q_new, /* i : Q value of speech */ + Word32 *q_env, + Word16 *sid_bw ) { Word16 enr_index; Word16 i, j, ptr; Word16 m1; Word16 res[L_FRAME16k]; - Word16 step_inv=0; - Word16 hi, lo; + Word16 step_inv=0; + Word16 hi, lo; Word16 maxl=0; Word16 num_bits=0; Word16 step=0; @@ -72,7 +67,7 @@ void CNG_enc_fx( Word16 tmpv, maxv, scale, att = 1; Word16 lsf_tmp[M]; Word32 C[M]; - Word32 max[2]; + Word32 max_val[2]; Word16 max_idx[2]; Word16 ftmp_fx; Word16 lsp_tmp[M]; @@ -95,15 +90,25 @@ void CNG_enc_fx( Word16 force_cn_step=0; Word16 tmp_loop; Word16 st_lp_sp_enr; - - st_lp_sp_enr = st_fx->lp_sp_enr_fx; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; + Word16 lp_ener_thr_scale; /* Temp variables for floating point functions */ + lp_ener_thr_scale = 8; /* 4.0f*/ /*IVAS_CODE Q2 */ + move16(); + if (NE_16(st_fx->element_mode, EVS_MONO)) + { + lp_ener_thr_scale = 7; /* 3.5f;*/ + move16(); + } /*sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f);*//*9.1 */ pt_sp = speech; L_ener = L_deposit_l(1); /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx, L_FRAME)) { FOR (j=0; j<128; j++) { @@ -142,9 +147,9 @@ void CNG_enc_fx( move16(); } test(); - IF ( st_fx->first_CNG_fx == 0 || st_fx->old_enr_index_fx < 0 ) + IF (hDtxEnc->first_CNG_fx == 0 || hTdCngEnc->old_enr_index_fx < 0 ) { - st_fx->lp_sp_enr_fx = sp_enr; + hTdCngEnc->lp_sp_enr_fx = sp_enr; move16(); /* Q8 */ } ELSE @@ -153,29 +158,29 @@ void CNG_enc_fx( test(); test(); test(); - IF( GT_32(st_fx->last_core_brate_fx, SID_2k40) && ( EQ_16( st_fx->last_core_fx, HQ_CORE ) || burst_ho_cnt > 0 ) && LT_16(st_fx->lp_sp_enr_fx, 1536) && - GT_16(sub(sp_enr, st_fx->lp_sp_enr_fx), 1024) && GT_16(sp_enr, 1536) ) + IF( GT_32(st_fx->last_core_brate_fx, SID_2k40) && ( EQ_16( st_fx->last_core_fx, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt_fx > 0 ) && LT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && + GT_16(sub(sp_enr, hTdCngEnc->lp_sp_enr_fx), 1024) && GT_16(sp_enr, 1536) ) { - st_fx->lp_sp_enr_fx = sp_enr; + hTdCngEnc->lp_sp_enr_fx = sp_enr; move16(); force_cn_step = 1; move16(); } ELSE { - st_fx->lp_sp_enr_fx = round_fx(L_mac(L_mult(29491 /* 0.9, Q15 */,st_fx->lp_sp_enr_fx), 3277 /* 0.1, Q15 */,sp_enr)); /* Q8 (8+15+1-16) */ + hTdCngEnc->lp_sp_enr_fx = round_fx(L_mac(L_mult(29491 /* 0.9, Q15 */,hTdCngEnc->lp_sp_enr_fx), 3277 /* 0.1, Q15 */,sp_enr)); /* Q8 (8+15+1-16) */ } } /* update the pointer to circular buffer of old LSP vectors */ - st_fx->cng_hist_ptr_fx = add(st_fx->cng_hist_ptr_fx,1); - if(EQ_16(st_fx->cng_hist_ptr_fx, DTX_HIST_SIZE)) + hTdCngEnc->cng_hist_ptr_fx = add(hTdCngEnc->cng_hist_ptr_fx,1); + if(EQ_16(hTdCngEnc->cng_hist_ptr_fx, DTX_HIST_SIZE)) { - st_fx->cng_hist_ptr_fx = 0; + hTdCngEnc->cng_hist_ptr_fx = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(st_fx->cng_lsp_hist_fx[(st_fx->cng_hist_ptr_fx)*M]), M ); + Copy( lsp_new, &(hTdCngEnc->cng_lsp_hist_fx[(hTdCngEnc->cng_hist_ptr_fx)*M]), M ); /*-----------------------------------------------------------------* * Find CNG spectral envelope @@ -183,16 +188,16 @@ void CNG_enc_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( (EQ_32(st_fx->core_brate_fx, SID_2k40)||EQ_32(st_fx->core_brate_fx,SID_1k75))&&GE_16(st_fx->cng_cnt_fx,sub(st_fx->cng_hist_size_fx,1))) + IF( (EQ_32(st_fx->core_brate_fx, SID_2k40) || EQ_32(st_fx->core_brate_fx,SID_1k75)) && GE_16(hDtxEnc->cng_cnt_fx,sub(hDtxEnc->cng_hist_size_fx,1))) { - set32_fx( max, 0, 2 ); + set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); - FOR( i=0; icng_hist_size_fx; i++ ) + FOR( i=0; i< hDtxEnc->cng_hist_size_fx; i++ ) { IF ( EQ_16(st_fx->L_frame_fx,L_FRAME)) { - lsp2lsf_fx( &st_fx->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; move16();/*QX2.56 */ tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ @@ -200,7 +205,7 @@ void CNG_enc_fx( } ELSE { - lsp2lsf_fx( &st_fx->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_16k ); + lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_16k ); ftmp_fx = 1205; move16();/*QX2.56 */ tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ @@ -218,20 +223,20 @@ void CNG_enc_fx( C[i] = Mpy_32_16_1(L_tmp,1928); move32();/*QX6.5536 */ - IF ( GT_32(C[i],max[0])) + IF ( GT_32(C[i],max_val[0])) { - max[1] = max[0]; + max_val[1] = max_val[0]; move32(); max_idx[1] = max_idx[0]; move16(); - max[0] = C[i]; + max_val[0] = C[i]; move32(); max_idx[0] = i; move16(); } - ELSE IF ( GT_32(C[i],max[1])) + ELSE IF ( GT_32(C[i],max_val[1])) { - max[1] = C[i]; + max_val[1] = C[i]; move32(); max_idx[1] = i; move16(); @@ -241,13 +246,13 @@ void CNG_enc_fx( FOR ( i=0; icng_hist_size_fx; j++ ) + FOR ( j=0; j< hDtxEnc->cng_hist_size_fx; j++ ) { - L_tmp = L_add(L_tmp,L_deposit_l(st_fx->cng_lsp_hist_fx[j*M+i])); /*Q15 */ + L_tmp = L_add(L_tmp,L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[j*M+i])); /*Q15 */ } - L_tmp = L_sub(L_tmp,L_add(L_deposit_l(st_fx->cng_lsp_hist_fx[max_idx[0]*M+i]),L_deposit_l(st_fx->cng_lsp_hist_fx[max_idx[1]*M+i]))); /*Q15 */ - tmpv= div_s(1,sub(st_fx->cng_hist_size_fx,2)); /*Q15 */ + L_tmp = L_sub(L_tmp,L_add(L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[0]*M+i]),L_deposit_l(hTdCngEnc->cng_lsp_hist_fx[max_idx[1]*M+i]))); /*Q15 */ + tmpv= div_s(1,sub(hDtxEnc->cng_hist_size_fx,2)); /*Q15 */ L_tmp = Mpy_32_16_1(L_tmp,tmpv); /*Q15 */ lsp_new[i] = extract_l(L_tmp); /*Q15 */ } @@ -269,35 +274,58 @@ void CNG_enc_fx( test(); test(); test(); - IF( ((st_fx->cng_cnt_fx == 0) && - GT_16(st_fx->lp_sp_enr_fx, 1536) && + IF( ((hDtxEnc->cng_cnt_fx == 0) && + GT_16(hTdCngEnc->lp_sp_enr_fx, 1536) && (LT_16(add(st_lp_sp_enr, 1024 /* 4.0, Q8 */), sp_enr)) && - (st_fx->first_CNG_fx != 0) && - (st_fx->old_enr_index_fx >= 0) && + (hDtxEnc->first_CNG_fx != 0) && + (hTdCngEnc->old_enr_index_fx >= 0) && (GT_32(st_fx->last_core_brate_fx, SID_2k40))) || EQ_16(force_cn_step, 1)) { *allow_cn_step = 1; move16(); } + + /* Initialize the CNG spectral envelope in case of the very first CNG frame */ + IF(hDtxEnc->first_CNG_fx == 0) + { + Copy(st_fx->lsp_old_fx, hDtxEnc->lspCNG_fx, M); + + /* Average the CNG spectral envelope in case of the very first CNG frame */ + IF (NE_16(st_fx->element_mode, EVS_MONO)) + { + FOR (i = 0; i < M; i++) + { + /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ + lsp_new[i] = mac_r(L_mult(lsp_mid[i], 16384), lsp_new[i], 16384); + move16(); + } + } + } + + test(); - IF( EQ_32(st_fx->core_brate_fx, SID_2k40)||EQ_32(st_fx->core_brate_fx,SID_1k75)) + IF( EQ_32(st_fx->core_brate_fx, SID_2k40) || EQ_32(st_fx->core_brate_fx,SID_1k75)) { /* LSF quantization */ IF ( st_fx->Opt_AMR_WB_fx != 0 ) { - isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0, 0 ); + isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0); } ELSE { - lsf_enc_fx( st_fx, L_frame, INACTIVE, lsf_new, lsp_new, 0, 0, 0, 100, Q_new ); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + lsf_enc_fx(st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, NULL, Q_new); +#else + lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL,100, 0, 0, Q_new ); +#endif } /* Reset CNG history if CNG frame length is changed */ test(); test(); - if ( EQ_16(st_fx->bwidth_fx,WB)&&st_fx->first_CNG_fx!=0&&NE_16(st_fx->L_frame_fx,st_fx->last_CNG_L_frame_fx)) + if ( EQ_16(st_fx->bwidth_fx,WB) && hDtxEnc->first_CNG_fx!=0 && NE_16(st_fx->L_frame_fx, hDtxEnc->last_CNG_L_frame_fx)) { - st_fx->ho_hist_size_fx = 0; + hTdCngEnc->ho_hist_size_fx = 0; move16(); } } @@ -308,12 +336,6 @@ void CNG_enc_fx( Copy( st_fx->lsf_old_fx, lsf_new, M ); } - /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->first_CNG_fx == 0 ) - { - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - } - /*---------------------------------------------------------------------* * CNG spectral envelope update * Find A(z) coefficients @@ -324,17 +346,17 @@ void CNG_enc_fx( /* Reset hangover counter if not first SID period */ if( GT_32(st_fx->core_brate_fx,FRAME_NO_DATA)) { - st_fx->num_ho_fx = 0; + hTdCngEnc->num_ho_fx = 0; move16(); } /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ test(); - IF( LT_16(st_fx->num_ho_fx,3)||LT_32(Mult_32_16(st_fx->Enew_fx,21845 /*1/1.5f, Q15*/), st_fx->lp_ener_fx)) + IF( LT_16(hTdCngEnc->num_ho_fx,3) || LT_32(Mult_32_16(hTdCngEnc->Enew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) { FOR( i=0; ilspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX,st_fx->lspCNG_fx[i]),32768-CNG_ISF_FACT_FX,lsp_new[i]); + hDtxEnc->lspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i]),32768-CNG_ISF_FACT_FX,lsp_new[i]); move16(); /* Q15 (15+15+1-16) */ } } @@ -345,128 +367,119 @@ void CNG_enc_fx( test(); test(); test(); - IF( ( st_fx->Opt_AMR_WB_fx || EQ_16(st_fx->bwidth_fx,WB)) - && ( !st_fx->first_CNG_fx || GE_16(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD) ) ) + IF( EQ_16(st_fx->element_mode, EVS_MONO) && (( st_fx->Opt_AMR_WB_fx || EQ_16(st_fx->bwidth_fx,WB)) + && ( !hDtxEnc->first_CNG_fx || GE_16(hTdCngEnc->act_cnt2_fx,MIN_ACT_CNG_UPD) ) ) ) { - IF( GT_32(st_fx->last_active_brate_fx,ACELP_16k40)) - { - st_fx->CNG_mode_fx = -1; - move16(); - } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_13k20)) + IF (GT_32(hDtxEnc->last_active_brate_fx, ACELP_16k40)) { - st_fx->CNG_mode_fx = 4; - move16(); - } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_9k60)) - { - st_fx->CNG_mode_fx = 3; - move16(); - } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_8k00)) - { - st_fx->CNG_mode_fx = 2; - move16(); - } - ELSE IF( GT_32(st_fx->last_active_brate_fx,ACELP_7k20)) - { - st_fx->CNG_mode_fx = 1; + hDtxEnc->CNG_mode_fx = -1; move16(); } ELSE { - st_fx->CNG_mode_fx = 0; - move16(); + hDtxEnc->CNG_mode_fx = get_cng_mode(hDtxEnc->last_active_brate_fx); } } /* If first sid after active burst update LSF history from circ buffer */ - st_fx->act_cnt_fx = 0; + hTdCngEnc->burst_ho_cnt_fx = s_min(hTdCngEnc->burst_ho_cnt_fx, hTdCngEnc->ho_circ_size_fx); + hTdCngEnc->act_cnt_fx = 0; move16(); - s_ptr = add(sub(st_fx->ho_circ_ptr_fx,burst_ho_cnt),1); + s_ptr = add(sub(hTdCngEnc->ho_circ_ptr_fx, hTdCngEnc->burst_ho_cnt_fx),1); if( s_ptr < 0 ) { - s_ptr = add(s_ptr, st_fx->ho_circ_size_fx); + s_ptr = add(s_ptr, hTdCngEnc->ho_circ_size_fx); } - FOR( ll = burst_ho_cnt; ll > 0; ll-- ) + FOR( ll = hTdCngEnc->burst_ho_cnt_fx; ll > 0; ll-- ) { - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx,1); - if( EQ_16(st_fx->ho_hist_ptr_fx, HO_HIST_SIZE)) + hTdCngEnc->ho_hist_ptr_fx = add(hTdCngEnc->ho_hist_ptr_fx,1); + if( EQ_16(hTdCngEnc->ho_hist_ptr_fx, HO_HIST_SIZE)) { - st_fx->ho_hist_ptr_fx = 0; + hTdCngEnc->ho_hist_ptr_fx = 0; move16(); } /* Conversion between 12.8k and 16k LSPs */ test(); test(); - IF( EQ_16(L_frame,L_FRAME )&&EQ_16(st_fx->ho_16k_lsp_fx[s_ptr],1)) + IF( EQ_16(st_fx->L_frame_fx,L_FRAME )&&EQ_16(hTdCngEnc->ho_16k_lsp_fx[s_ptr],1)) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &(st_fx->ho_lsp_circ_fx[s_ptr*M]), L_frame, 0 ); + lsp_convert_poly_fx( &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), st_fx->L_frame_fx, 0 ); } - ELSE IF ( EQ_16(L_frame,L_FRAME16k)&&st_fx->ho_16k_lsp_fx[s_ptr]==0) + ELSE IF ( EQ_16(st_fx->L_frame_fx,L_FRAME16k)&& hTdCngEnc->ho_16k_lsp_fx[s_ptr]==0) { /* 16k LSPs already converted and stored, just copy to the other buffer */ - Copy(&(st_fx->ho_lsp_circ2_fx[s_ptr*M]), &(st_fx->ho_lsp_circ_fx[s_ptr*M]), M ); + Copy(&(hTdCngEnc->ho_lsp_circ2_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), M ); } /* update the circular buffers */ - Copy(&(st_fx->ho_lsp_circ_fx[s_ptr*M]), &(st_fx->ho_lsp_hist_fx[st_fx->ho_hist_ptr_fx*M]), M ); - Copy32(&(st_fx->ho_ener_circ_fx[s_ptr]), &(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx]), 1 ); - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - Copy32(&(st_fx->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(st_fx->ho_env_hist_fx[st_fx->ho_hist_ptr_fx*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy(&(hTdCngEnc->ho_lsp_circ_fx[s_ptr*M]), &(hTdCngEnc->ho_lsp_hist_fx[hTdCngEnc->ho_hist_ptr_fx*M]), M ); + Copy32(&(hTdCngEnc->ho_ener_circ_fx[s_ptr]), &(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr_fx]), 1 ); + hTdCngEnc->ho_sid_bw_fx = L_shl(L_and(hTdCngEnc->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); + Copy32(&(hTdCngEnc->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(hTdCngEnc->ho_env_hist_fx[hTdCngEnc->ho_hist_ptr_fx*NUM_ENV_CNG]), NUM_ENV_CNG ); - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); - if (GT_16(st_fx->ho_hist_size_fx, HO_HIST_SIZE)) + hTdCngEnc->ho_hist_size_fx = add(hTdCngEnc->ho_hist_size_fx,1); + if (GT_16(hTdCngEnc->ho_hist_size_fx, HO_HIST_SIZE)) { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; + hTdCngEnc->ho_hist_size_fx = HO_HIST_SIZE; move16(); } s_ptr = add(s_ptr,1); - if( EQ_16(s_ptr, st_fx->ho_circ_size_fx)) + if( EQ_16(s_ptr, hTdCngEnc->ho_circ_size_fx)) { s_ptr = 0; move16(); } } - IF ( burst_ho_cnt > 0) + IF(hTdCngEnc->burst_ho_cnt_fx > 0) { - /**allow_cn_step |= ( st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx] > 4 * st_fx->lp_ener_fx ); */ - L_tmp1 = L_shr(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx],2); - L_tmp1 = L_sub(L_tmp1,st_fx->lp_ener_fx); - - if(L_tmp1>0) + /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr_fx] > 4 * hTdCngEnc->lp_ener_fx ); */ +#if 1 + /*allow_cn_step |= (hDtxEnc->first_CNG || st->element_mode == EVS_MONO) && (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener);*/ + /* (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener); */ + L_tmp1 = L_shr(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr_fx], 2); + IF(NE_16(lp_ener_thr_scale, 8)) + { + L_tmp1 = L_add(L_tmp1, L_shr(hTdCngEnc->lp_ener_fx, 8)); + } + L_tmp1 = L_sub(L_tmp1, hTdCngEnc->lp_ener_fx); +#else + L_tmp1 = L_shr(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr_fx],2); + L_tmp1 = L_sub(L_tmp1,hTdCngEnc->lp_ener_fx); +#endif + test();test(); + IF((hDtxEnc->first_CNG_fx > 0 || EQ_16(st_fx->element_mode, EVS_MONO)) && L_tmp1>0) { *allow_cn_step = s_or(*allow_cn_step,1); } } test(); - IF ( *allow_cn_step == 0 && st_fx->ho_hist_size_fx > 0 ) + IF ( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size_fx > 0 ) { /* Use average of energies below last energy */ - ptr = st_fx->ho_hist_ptr_fx; + ptr = hTdCngEnc->ho_hist_ptr_fx; move16(); - Copy( &(st_fx->ho_lsp_hist_fx[ptr*M]), tmp, M ); + Copy( &(hTdCngEnc->ho_lsp_hist_fx[ptr*M]), tmp, M ); m1 = 0; move16(); - IF( L_and(st_fx->ho_sid_bw_fx, (Word32) 0x1) == 0 ) + IF( L_and(hTdCngEnc->ho_sid_bw_fx, (Word32) 0x1) == 0 ) { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } - L_enr = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ + L_enr = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ weights = W_DTX_HO_FX[0]; /* Q15 */ m = 1; move16(); - FOR( k=1; kho_hist_size_fx; k++ ) + FOR( k=1; kho_hist_size_fx; k++ ) { ptr = sub(ptr,1); if( ptr < 0 ) @@ -476,20 +489,20 @@ void CNG_enc_fx( } test(); - IF ( LT_32(Mult_32_16(st_fx->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx])&& - GT_32(st_fx->ho_ener_hist_fx[ptr],Mult_32_16(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx], BUF_L_NRG_FX)) ) + IF ( LT_32(Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr_fx])&& + GT_32(hTdCngEnc->ho_ener_hist_fx[ptr],Mult_32_16(hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr_fx], BUF_L_NRG_FX)) ) { /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr]; */ - L_tmp1 = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ + L_tmp1 = Mult_32_16(hTdCngEnc->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ L_enr = L_add(L_enr,L_tmp1); /* Q6 */ /*weights += W_DTX_HO[k]; */ weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ - Copy( &st_fx->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); - IF( L_and(st_fx->ho_sid_bw_fx, L_shl((Word32)0x1,k)) == 0 ) + Copy( &hTdCngEnc->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); + IF( L_and(hTdCngEnc->ho_sid_bw_fx, L_shl((Word32)0x1,k)) == 0 ) { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); + Copy32( &hTdCngEnc->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); m1 = add(m1,1); } m = add(m,1); @@ -502,10 +515,10 @@ void CNG_enc_fx( L_tmp1 = Mult_32_16(L_enr,tmp1); /* Q(14-exp+6-15)->Q(5-exp) */ L_enr = L_shl(L_tmp1,add(exp,1)); /* Q6 */ - st_fx->lp_ener_fx = L_enr; + hTdCngEnc->lp_ener_fx = L_enr; move32();/* Q6 */ - set32_fx( max, 0, 2 ); + set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); FOR( i=0; ilspCNG_fx[i] = lsp_tmp[i]; + hDtxEnc->lspCNG_fx[i] = lsp_tmp[i]; move16(); /*Q15 */ } } @@ -622,7 +635,7 @@ void CNG_enc_fx( FOR( i=0; ilspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); + hDtxEnc->lspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); move16(); } } @@ -637,39 +650,39 @@ void CNG_enc_fx( L_tmp = L_add(L_tmp,tmp_env[j*NUM_ENV_CNG+i]); } /* env[i] /= (float)m1; */ - /* env[i] = env[i] - 2*st_fx->lp_ener_fx; */ + /* env[i] = env[i] - 2*hTdCngEnc->lp_ener_fx; */ IF(EQ_16(m1,1)) { - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); + L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); } ELSE { tmp1 = div_s(1,m1); L_tmp = Mult_32_16(L_tmp,tmp1); - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); + L_tmp = L_sub(L_tmp,L_add(hTdCngEnc->lp_ener_fx,hTdCngEnc->lp_ener_fx)); } env[i] = L_tmp; move32(); } - Copy32(env, st_fx->lp_env_fx, NUM_ENV_CNG); + Copy32(env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG); } } ELSE { - Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ + Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ } } IF ( st_fx->Opt_AMR_WB_fx != 0 ) { - E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); + E_LPC_f_isp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); } ELSE { - E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ + E_LPC_f_lsp_a_conversion(hDtxEnc->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ } - tmp_loop = shr(L_frame,6); + tmp_loop = shr(st_fx->L_frame_fx,6); FOR( i=1; ibwidth_fx,NB)) + Residu3_fx(Aq, speech, res, st_fx->L_frame_fx, 0); + Copy(res, res1, st_fx->L_frame_fx); + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + PMT("Code to be completed") +#ifdef IVAS_CODE + att = powf(10.0f, hTdCngEnc->CNG_att / 20.0f); + v_multc(res1, att, res1, st->L_frame); +#endif + } + ELSE IF( NE_16(st_fx->bwidth_fx,NB)) { test(); - IF( EQ_16(st_fx->bwidth_fx,WB)&&st_fx->CNG_mode_fx>=0) + IF( EQ_16(st_fx->bwidth_fx,WB) && hDtxEnc->CNG_mode_fx>=0) { - ftmp_fx = HO_ATT_FX[st_fx->CNG_mode_fx]; + ftmp_fx = HO_ATT_FX[hDtxEnc->CNG_mode_fx]; } ELSE { @@ -701,18 +723,22 @@ void CNG_enc_fx( tmp1 = add(16384,tmp1); att = div_s(16374,tmp1); /* Q15 */ +#if 0 IF ( LT_16(att,ftmp_fx)) { att = ftmp_fx; move16(); } - FOR( i = 0; i < st_fx->L_frame_fx; i++ ) { /*res1[i] *= att;*/ res1[i] = mult(res1[i],att); move16();/* Q_new */ } +#else + att = s_max(att, ftmp_fx); + v_multc_att(res1, att, res1, st_fx->L_frame_fx); +#endif att = shr(att,7);/* Q8 */ } @@ -721,7 +747,7 @@ void CNG_enc_fx( IF ( EQ_16(st_fx->L_frame_fx,L_FRAME16k)) { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem2,0); + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx,0); } fft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); @@ -741,7 +767,7 @@ void CNG_enc_fx( ptI--; } - Copy32( env, &(st_fx->cng_res_env_fx[(st_fx->cng_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy32( env, &(hTdCngEnc->cng_res_env_fx[(hTdCngEnc->cng_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); /* calculate the residual signal energy */ /*enr = dotp( res, res, L_frame ) / L_frame; */ @@ -754,7 +780,7 @@ void CNG_enc_fx( scale = norm_s(maxv); pt_res = res; L_ener = L_deposit_l(1); - IF( EQ_16(L_frame, L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx, L_FRAME)) { FOR (j=0; j<128; j++) { @@ -790,7 +816,7 @@ void CNG_enc_fx( enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ /* update the circular buffer of old energies */ - st_fx->cng_ener_hist_fx[st_fx->cng_hist_ptr_fx] = enr; + hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr_fx] = enr; move16(); /* Q8 */ /*-----------------------------------------------------------------* @@ -799,21 +825,21 @@ void CNG_enc_fx( test(); IF( EQ_32(st_fx->core_brate_fx, SID_2k40)||EQ_32(st_fx->core_brate_fx,SID_1k75)) { - IF( GE_16(st_fx->cng_cnt_fx,sub(st_fx->cng_hist_size_fx,1))) + IF( GE_16(hDtxEnc->cng_cnt_fx,sub(hDtxEnc->cng_hist_size_fx,1))) { /* average the envelope except outliers */ FOR ( i=0; icng_hist_size_fx; j++ ) + FOR ( j=0; j< hDtxEnc->cng_hist_size_fx; j++ ) { - L_tmp1 = L_add(L_tmp1,st_fx->cng_res_env_fx[j*NUM_ENV_CNG+i]); + L_tmp1 = L_add(L_tmp1,hTdCngEnc->cng_res_env_fx[j*NUM_ENV_CNG+i]); } - L_tmp = L_add(st_fx->cng_res_env_fx[max_idx1[0]*NUM_ENV_CNG+i],st_fx->cng_res_env_fx[max_idx1[1]*NUM_ENV_CNG+i]); + L_tmp = L_add(hTdCngEnc->cng_res_env_fx[max_idx1[0]*NUM_ENV_CNG+i],hTdCngEnc->cng_res_env_fx[max_idx1[1]*NUM_ENV_CNG+i]); L_tmp1 = L_sub(L_tmp1,L_tmp); /* env[i] /= (float)(st_fx->cng_hist_size_fx - 2); */ - tmp1 = sub(st_fx->cng_hist_size_fx,2); + tmp1 = sub(hDtxEnc->cng_hist_size_fx,2); IF(GT_16(tmp1,1)) { tmp1 = div_s(1,tmp1); @@ -825,13 +851,13 @@ void CNG_enc_fx( } /* compute average excitation energy */ L_tmp = L_deposit_l(0); - ptr = st_fx->cng_hist_ptr_fx; + ptr = hTdCngEnc->cng_hist_ptr_fx; move16(); - FOR (k=0; kcng_hist_size_fx; k++) + FOR (k=0; k< hDtxEnc->cng_hist_size_fx; k++) { /* enr += W_HIST[k]*cng_ener_hist[ptr] */ - L_tmp = L_mac0(L_tmp, W_HIST_FX[k], st_fx->cng_ener_hist_fx[ptr]); /* Q24 (8+16) */ + L_tmp = L_mac0(L_tmp, W_HIST_FX[k], hTdCngEnc->cng_ener_hist_fx[ptr]); /* Q24 (8+16) */ ptr = sub(ptr, 1); if (ptr < 0) /* check for circular pointer */ { @@ -858,14 +884,20 @@ void CNG_enc_fx( enr = round_fx(L_tmp); /* Q8 */ } /* decrease the energy in case of WB input */ - IF( NE_16(st_fx->bwidth_fx, NB)) + IF ( EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) + { + PMT("CNG IVAS_SCE and IVAS_CPE_DFT code missing") + //IVAS_CODE + //enr += hTdCngEnc->CNG_att * FAC_LOG2 / 10.0f; + } + ELSE IF( NE_16(st_fx->bwidth_fx, NB)) { IF( EQ_16(st_fx->bwidth_fx,WB)) { - IF( st_fx->CNG_mode_fx >= 0 ) + IF(hDtxEnc->CNG_mode_fx >= 0 ) { /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[st_fx->CNG_mode_fx]; + att = ENR_ATT_fx[hDtxEnc->CNG_mode_fx]; move16(); } ELSE @@ -916,22 +948,22 @@ void CNG_enc_fx( /* allow only slow energy increase */ test(); - IF( st_fx->old_enr_index_fx >= 0 && GT_16(enr_index, add(st_fx->old_enr_index_fx, MAX_DELTA))) + IF( hTdCngEnc->old_enr_index_fx >= 0 && GT_16(enr_index, add(hTdCngEnc->old_enr_index_fx, MAX_DELTA))) { IF( *allow_cn_step != 0 ) { - tmp1 = mult(27853 /* Q15(0.85) */,sub(enr_index,st_fx->old_enr_index_fx)); - enr_index = add(st_fx->old_enr_index_fx,tmp1); + tmp1 = mult(27853 /* Q15(0.85) */,sub(enr_index,hTdCngEnc->old_enr_index_fx)); + enr_index = add(hTdCngEnc->old_enr_index_fx,tmp1); } ELSE { - enr_index = add(st_fx->old_enr_index_fx, MAX_DELTA); + enr_index = add(hTdCngEnc->old_enr_index_fx, MAX_DELTA); } } - st_fx->old_enr_index_fx = enr_index; + hTdCngEnc->old_enr_index_fx = enr_index; move16(); - push_indice_fx( st_fx, IND_ENERGY, enr_index, num_bits ); + push_indice_fx( hBstr, IND_ENERGY, enr_index, num_bits ); if ( enr_index == 0 ) { enr_index = -5; @@ -943,13 +975,13 @@ void CNG_enc_fx( L_tmp = L_mult(enr_index, step_inv); /* Q16(0+15+1) */ /* substract by 2 not done to leave Energy in Q2 */ lo = L_Extract_lc(L_tmp, &hi); - st_fx->Enew_fx = Pow2(add(hi, 4), lo); /* Q6 */ + hTdCngEnc->Enew_fx = Pow2(add(hi, 4), lo); /* Q6 */ IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l(st_fx->Enew_fx); - L_tmp = L_shl(st_fx->Enew_fx,exp); /*Q(exp+6) */ - L_tmp = Mult_32_16(L_tmp,shl(L_frame,5));/* Q(exp+6+5-15=exp-4) */ + exp = norm_l(hTdCngEnc->Enew_fx); + L_tmp = L_shl(hTdCngEnc->Enew_fx,exp); /*Q(exp+6) */ + L_tmp = Mult_32_16(L_tmp,shl(st_fx->L_frame_fx,5));/* Q(exp+6+5-15=exp-4) */ L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ exp = norm_l(L_tmp); @@ -962,7 +994,7 @@ void CNG_enc_fx( { /* env[i] -= 2 * st->Enew;*/ L_tmp1 = L_add(env[i], 0); - L_tmp = L_add(st_fx->Enew_fx,st_fx->Enew_fx); + L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); L_tmp1 = L_sub(L_tmp1,L_tmp); /*Q6*/ IF ( L_tmp1 < 0 ) @@ -1018,7 +1050,7 @@ void CNG_enc_fx( move16(); } } - push_indice_fx( st_fx, IND_CNG_ENV1, min1_idx, 6 ); + push_indice_fx( hBstr, IND_CNG_ENV1, min1_idx, 6 ); /* get quantized res_env_details */ FOR ( i=0; iEnew_fx,21845 /*1/1.5f, Q15*/), st_fx->lp_ener_fx)) + IF ( *allow_cn_step == 0 && LT_32(Mult_32_16(hTdCngEnc->Enew_fx,21845 /*1/1.5f, Q15*/), hTdCngEnc->lp_ener_fx)) { /* update the pointer to circular buffer of old LSP vectors */ - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx, 1); - if( EQ_16(st_fx->ho_hist_ptr_fx,HO_HIST_SIZE)) + hTdCngEnc->ho_hist_ptr_fx = add(hTdCngEnc->ho_hist_ptr_fx, 1); + if( EQ_16(hTdCngEnc->ho_hist_ptr_fx,HO_HIST_SIZE)) { - st_fx->ho_hist_ptr_fx = 0; + hTdCngEnc->ho_hist_ptr_fx = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(st_fx->ho_lsp_hist_fx[(st_fx->ho_hist_ptr_fx)*M]), M ); + Copy( lsp_new, &(hTdCngEnc->ho_lsp_hist_fx[(hTdCngEnc->ho_hist_ptr_fx)*M]), M ); /* update the hangover energy buffer */ - st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx] = st_fx->Enew_fx; + hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr_fx] = hTdCngEnc->Enew_fx; move32(); IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) { @@ -1057,16 +1089,16 @@ void CNG_enc_fx( L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ env[i] = L_shl(L_tmp, sub(6, exp_pow)); move32(); /* Q6 */ - L_tmp = L_add(st_fx->Enew_fx,st_fx->Enew_fx); + L_tmp = L_add(hTdCngEnc->Enew_fx,hTdCngEnc->Enew_fx); env[i] = L_add(env[i],L_tmp); move32();/* Q6 */ } - Copy32( env, &(st_fx->ho_env_hist_fx[(st_fx->ho_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); + Copy32( env, &(hTdCngEnc->ho_env_hist_fx[(hTdCngEnc->ho_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); } - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); - if( GT_16(st_fx->ho_hist_size_fx,HO_HIST_SIZE)) + hTdCngEnc->ho_hist_size_fx = add(hTdCngEnc->ho_hist_size_fx,1); + if( GT_16(hTdCngEnc->ho_hist_size_fx,HO_HIST_SIZE)) { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; + hTdCngEnc->ho_hist_size_fx = HO_HIST_SIZE; move16(); } } @@ -1074,30 +1106,27 @@ void CNG_enc_fx( /* dithering bit for AMR-WB IO mode is always set to 0 */ IF( EQ_32(st_fx->core_brate_fx, SID_1k75)) { - push_indice_fx( st_fx, IND_DITHERING, 0, 1 ); + push_indice_fx( hBstr, IND_DITHERING, 0, 1 ); } IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) { IF(EQ_16(st_fx->L_frame_fx, L_FRAME16k)) { - push_indice_fx( st_fx, IND_ACELP_16KHZ, 1, 1 ); + push_indice_fx( hBstr, IND_ACELP_16KHZ, 1, 1 ); } ELSE { - push_indice_fx( st_fx, IND_ACELP_16KHZ, 0, 1 ); + push_indice_fx( hBstr, IND_ACELP_16KHZ, 0, 1 ); } - } - IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) - { - push_indice_fx( st_fx, IND_CNG_HO, s_min(st_fx->burst_ho_cnt_fx, 7 ), 3 ); - st_fx->num_ho_fx = m; + push_indice_fx( hBstr, IND_CNG_HO, s_min(hTdCngEnc->burst_ho_cnt_fx, 7 ), 3 ); + hTdCngEnc->num_ho_fx = m; move16(); - push_indice_fx( st_fx, IND_SID_TYPE, 0, 1 ); + push_indice_fx( hBstr, IND_SID_TYPE, 0, 1 ); - IF ( LT_32(st_fx->input_Fs_fx, 32000)) + IF ( LT_32(st_fx->input_Fs_fx, 32000) && NE_16(st_fx->element_mode, IVAS_CPE_DFT)) { - push_indice_fx( st_fx, IND_SID_BW, 0, 1 ); + push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); *sid_bw = 0; move16(); } @@ -1110,17 +1139,17 @@ void CNG_enc_fx( test(); IF( EQ_32(st_fx->core_brate_fx, SID_2k40)||EQ_32(st_fx->core_brate_fx,SID_1k75)) { - st_fx->cng_cnt_fx = 0; + hDtxEnc->cng_cnt_fx = 0; move16(); - st_fx->cng_hist_ptr_fx = -1; + hTdCngEnc->cng_hist_ptr_fx = -1; move16(); /* update frame length memory */ - st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; + hDtxEnc->last_CNG_L_frame_fx = st_fx->L_frame_fx; move16(); } ELSE { - st_fx->cng_cnt_fx = add(st_fx->cng_cnt_fx,1); + hDtxEnc->cng_cnt_fx = add(hDtxEnc->cng_cnt_fx,1); } return; @@ -1137,24 +1166,39 @@ void swb_CNG_enc_fx( ) { Word16 shb_SID_updt_fx=0; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; test(); IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)||st_fx->core_brate_fx==FRAME_NO_DATA) { IF (EQ_16(st_fx->cng_type_fx,LP_CNG)) { - /* decide if SHB SID encoding or not */ - shb_SID_updt_fx = shb_DTX_fx( st_fx, shb_speech_fx, syn_12k8_16k_fx ); + IF (GE_32(st_fx->input_Fs_fx, L_FRAME32k * FRAMES_PER_SEC)) + { + /* decide if SHB SID encoding or not */ + shb_SID_updt_fx = shb_DTX_fx(st_fx, shb_speech_fx, syn_12k8_16k_fx); - /* SHB CNG encoding */ - shb_CNG_encod_fx( st_fx, shb_SID_updt_fx ); + /* SHB CNG encoding */ + shb_CNG_encod_fx(st_fx, shb_SID_updt_fx); + } + ELSE IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) && EQ_32(st_fx->core_brate_fx, SID_2k40)) + { + PMT("CNG IVAS_CPE_DFT code not implemented") +#ifdef IVAS_CODE + /* LF-boost not used in DFT-stereo, instead the bandwidth is transmitted */ + delete_indice(st->hBstr, IND_CNG_ENV1); + push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); + push_indice(st->hBstr, IND_UNUSED, 0, 4); + push_indice(st->hBstr, IND_SID_BW, 1, 1); +#endif + } } - st_fx->last_vad_fx = 0; + hTdCngEnc->last_vad_fx = 0; move16(); } ELSE { - st_fx->last_vad_fx = 1; + hTdCngEnc->last_vad_fx = 1; move16(); } @@ -1172,13 +1216,29 @@ static void shb_CNG_encod_fx( ) { Word16 idx_ener_fx; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; +#ifdef IVAS_CODE + Word16 ener_mid_dec_thr; +#endif idx_ener_fx = 0; move16(); IF ( EQ_16(update_fx, 1)) { /* SHB energy quantization */ - idx_ener_fx = shr(add(mult(st_fx->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ + } + ELSE + { + /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/ + PMT("shb_CNG_encod_fx quantization in missing") +#if 0 + idx_ener_fx = shr(add(mult(hTdCngEnc->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ +#endif + } if ( LT_16(st_fx->bwidth_fx, SWB)) { @@ -1195,22 +1255,52 @@ static void shb_CNG_encod_fx( { idx_ener_fx = s_max(idx_ener_fx,0); } +#ifdef IVAS_CODE + /* prevent toggling of idx_ener by adding small dead-zone interval around decision thresholds */ + if (st->element_mode != EVS_MONO) + { + if (abs(idx_ener - st->hTdCngEnc->last_idx_ener) == 1) + { + ener_mid_dec_thr = 0.5f * ((st->hTdCngEnc->last_idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); + ener_mid_dec_thr += 0.5f * ((idx_ener / 0.7f - 6.0f) / 0.1f) * (float)log10(2.0f); - push_indice_fx( st_fx, IND_SHB_CNG_GAIN, idx_ener_fx, 4); - push_indice_fx( st_fx, IND_SID_BW, 1, 1 ); - st_fx->nb_bits_tot_fx = sub(st_fx->nb_bits_tot_fx,st_fx->ind_list_fx[IND_CNG_ENV1].nb_bits); - st_fx->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; + if (fabs(st->hTdCngEnc->mov_shb_cng_ener - ener_mid_dec_thr) / ener_mid_dec_thr < ENER_MID_DEAD_ZONE) + { + idx_ener = st->hTdCngEnc->last_idx_ener; + } + } + } + + st->hTdCngEnc->last_idx_ener = idx_ener; +#endif + push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4); + push_indice_fx( hBstr, IND_SID_BW, 1, 1 ); +#ifndef IVAS_CODE + hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits); + hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; +#else + delete_indice(hBstr, IND_CNG_ENV1); +#endif move16(); - push_indice_fx( st_fx, IND_UNUSED, 0, 2); - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - st_fx->ho_sid_bw_fx = L_or(st_fx->ho_sid_bw_fx, 0x1L); +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_DFT) + { + push_indice(st->hBstr, IND_BWIDTH, st->bwidth, 2); + } + else +#endif + { + push_indice_fx(hBstr, IND_UNUSED, 0, 2); + } + hTdCngEnc->ho_sid_bw_fx = L_shl(L_and(hTdCngEnc->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); + hTdCngEnc->ho_sid_bw_fx = L_or(hTdCngEnc->ho_sid_bw_fx, 0x1L); } ELSE { IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) { - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - push_indice_fx( st_fx, IND_SID_BW, 0, 1 ); + hTdCngEnc->ho_sid_bw_fx = L_shl(L_and(hTdCngEnc->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); + push_indice_fx( hBstr, IND_SID_BW, 0, 1 ); } } @@ -1239,12 +1329,16 @@ static Word16 shb_DTX_fx( Word16 tmp; Word16 exp; Word16 fra; + Word16 att; /*Q8*/ Word16 allow_cn_step_fx=0; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; shb_new_speech_fx = shb_old_speech_fx + (ACELP_LOOK_12k8 + L_SUBFR) * 5/4; - Copy( st_fx->old_speech_shb_fx, shb_old_speech_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); + Copy(hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, st_fx->old_speech_shb_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); + Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); shb_ener_fx = L_deposit_l(0); FOR ( i=0; ifirst_CNG_fx == 0 ) + test(); + IF (EQ_16(st_fx->element_mode, IVAS_SCE) || EQ_16(st_fx->element_mode, IVAS_CPE_DFT)) { - st_fx->mov_wb_cng_ener_fx = log_wb_ener_fx; + att = 0; move16(); - st_fx->mov_shb_cng_ener_fx = log_shb_ener_fx; + PMT("apply_scale is not implemented") +#if 0 + apply_scale(&att, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); +#endif + } + else + { + att = 1664; /*6.5 in Q8*/ move16(); - st_fx->last_wb_cng_ener_fx = log_wb_ener_fx; + } + + log_shb_ener_fx = sub(round_fx(L_shl(shb_ener_fx, 10)), att); /* log_shb_ener_fx in Q8 */ + + IF (hDtxEnc->first_CNG_fx == 0 ) + { + hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; move16(); - st_fx->last_shb_cng_ener_fx = log_shb_ener_fx; + hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; + move16(); + hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; + move16(); + hTdCngEnc->last_shb_cng_ener_fx = log_shb_ener_fx; move16(); } - if ( GT_16(abs_s(sub(log_wb_ener_fx, st_fx->mov_wb_cng_ener_fx)), 3072)) + if ( GT_16(abs_s(sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx)), 3072)) { allow_cn_step_fx = 1; move16(); } - +#ifdef IVAS_CODE + /* Also allow step if shb energy has dropped 12 dB */ + if ((st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) && ((hTdCngEnc->mov_shb_cng_ener - log_shb_ener) > 12.0f)) + { + allow_cn_step = 1; + } +#endif IF ( EQ_16(allow_cn_step_fx, 1)) { - st_fx->mov_wb_cng_ener_fx = log_wb_ener_fx; + hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; move16(); - st_fx->mov_shb_cng_ener_fx = log_shb_ener_fx; + hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; move16(); } ELSE { - tmp = sub(log_wb_ener_fx, st_fx->mov_wb_cng_ener_fx); /* Q8 */ + tmp = sub(log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx); /* Q8 */ tmp = mult(tmp, 29491); /* Q8 */ - st_fx->mov_wb_cng_ener_fx = add(st_fx->mov_wb_cng_ener_fx, tmp); /* Q8 */ + hTdCngEnc->mov_wb_cng_ener_fx = add(hTdCngEnc->mov_wb_cng_ener_fx, tmp); /* Q8 */ - tmp = sub(log_shb_ener_fx, st_fx->mov_shb_cng_ener_fx); + tmp = sub(log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx); tmp = mult(tmp, 8192); /* Q8 */ - st_fx->mov_shb_cng_ener_fx = add(st_fx->mov_shb_cng_ener_fx, tmp); /* Q8 */ + hTdCngEnc->mov_shb_cng_ener_fx = add(hTdCngEnc->mov_shb_cng_ener_fx, tmp); /* Q8 */ } - st_fx->shb_NO_DATA_cnt_fx = add(st_fx->shb_NO_DATA_cnt_fx, 1); + hTdCngEnc->shb_NO_DATA_cnt_fx = add(hTdCngEnc->shb_NO_DATA_cnt_fx, 1); update_fx = 0; move16(); @@ -1317,22 +1434,22 @@ static Word16 shb_DTX_fx( { test(); test(); - IF ( st_fx->first_CNG_fx == 0 || EQ_16(st_fx->last_vad_fx, 1)||GE_16(st_fx->shb_NO_DATA_cnt_fx,100)) + IF (hDtxEnc->first_CNG_fx == 0 || EQ_16(hTdCngEnc->last_vad_fx, 1)||GE_16(hTdCngEnc->shb_NO_DATA_cnt_fx,100)) { update_fx = 1; move16(); } ELSE { - IF ( st_fx->shb_cng_ini_cnt_fx > 0 ) + IF ( hTdCngEnc->shb_cng_ini_cnt_fx > 0 ) { update_fx = 1; move16(); - st_fx->shb_cng_ini_cnt_fx = sub(st_fx->shb_cng_ini_cnt_fx, 1); + hTdCngEnc->shb_cng_ini_cnt_fx = sub(hTdCngEnc->shb_cng_ini_cnt_fx, 1); } ELSE { - IF ( GT_16(abs_s(sub(sub(st_fx->mov_wb_cng_ener_fx, st_fx->mov_shb_cng_ener_fx), sub(st_fx->last_wb_cng_ener_fx, st_fx->last_shb_cng_ener_fx))), 768)) + IF ( GT_16(abs_s(sub(sub(hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx), sub(hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx))), 768)) { update_fx = 1; move16(); @@ -1340,7 +1457,7 @@ static Word16 shb_DTX_fx( ELSE { test(); - IF ( GE_16(st_fx->bwidth_fx, SWB)&<_16(st_fx->last_SID_bwidth_fx,SWB)) + IF ( GE_16(st_fx->bwidth_fx, SWB)&<_16(hTdCngEnc->last_SID_bwidth_fx,SWB)) { update_fx = 1; move16(); @@ -1348,7 +1465,7 @@ static Word16 shb_DTX_fx( ELSE { test(); - IF ( LT_16(st_fx->bwidth_fx, SWB)&&GE_16(st_fx->last_SID_bwidth_fx,SWB)) + IF ( LT_16(st_fx->bwidth_fx, SWB)&&GE_16(hTdCngEnc->last_SID_bwidth_fx,SWB)) { update_fx = 1; move16(); @@ -1358,20 +1475,77 @@ static Word16 shb_DTX_fx( } } - st_fx->last_SID_bwidth_fx = st_fx->bwidth_fx; + hTdCngEnc->last_SID_bwidth_fx = st_fx->bwidth_fx; + move16(); + } + /* LF-boost not yet implemented in decoder which means that the specific wb_sid information is not used */ + test();test(); + if ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) && EQ_32(st_fx->core_brate_fx, SID_2k40)) + { + update_fx = 1; move16(); } IF ( EQ_16(update_fx, 1)) { - st_fx->last_wb_cng_ener_fx = st_fx->mov_wb_cng_ener_fx; + hTdCngEnc->last_wb_cng_ener_fx = hTdCngEnc->mov_wb_cng_ener_fx; move16(); - st_fx->last_shb_cng_ener_fx = st_fx->mov_shb_cng_ener_fx; + hTdCngEnc->last_shb_cng_ener_fx = hTdCngEnc->mov_shb_cng_ener_fx; move16(); - st_fx->shb_NO_DATA_cnt_fx = 0; + hTdCngEnc->shb_NO_DATA_cnt_fx = 0; move16(); } return (update_fx); } + +/*---------------------------------------------------------------------* + * calculate_hangover_attenuation_gain() + * + * + *---------------------------------------------------------------------*/ + +void calculate_hangover_attenuation_gain( + Encoder_State_fx* st, /* i : encoder state structure */ + Word16* att, /* o : attenuation factor */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ +) +{ + Word16 offset; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + + *att = 32767; + + move16(); + /* smoothing in case of CNG */ + IF (hTdCngEnc != NULL) + { + test();test();test(); + IF( hTdCngEnc->burst_ho_cnt_fx > 0 && (vad_hover_flag != 0) && (NE_16(st->bwidth_fx, NB) || GT_16(st->element_mode, EVS_MONO))) /* corresponds to line 504 in FLT acelp_core_enc.c */ + { +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD) + { + *att = powf(10.0f, (st->hTdCngEnc->CNG_att / 160.0f) * st->hTdCngEnc->burst_ho_cnt); + } + else +#endif + { + offset = 5; + test(); + if (EQ_16(st->bwidth_fx, WB) && st->hDtxEnc->CNG_mode_fx >= 0) + { + offset = st->hDtxEnc->CNG_mode_fx; + move16(); + } + assert(hTdCngEnc->burst_ho_cnt_fx > 0); + *att = CNG_burst_att_fx[offset][sub(hTdCngEnc->burst_ho_cnt_fx, 1)]; /*Q15*/ + move16(); + } + } + + + } + return; +} diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index 588a00a..a8735ae 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -1,12 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - /*-------------------------------------------------------------------* * Local Constants @@ -28,11 +26,11 @@ *----------------------------------------------------------------------------------*/ void acelp_2t32_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[] /* o : filtered fixed codebook excitation */ ) { Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1,index; @@ -305,7 +303,7 @@ void acelp_2t32_fx( } { /* write index to array of indices */ - push_indice_fx( st_fx, IND_ALG_CDBK_2T32, index, 12 ); + push_indice_fx( hBstr, IND_ALG_CDBK_2T32, index, 12 ); } return; } @@ -320,11 +318,12 @@ void acelp_2t32_fx( *----------------------------------------------------------------------------------*/ void acelp_1t64_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 h[], /* i : impulse response of weighted synthesis filter */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 y[], /* o : filtered fixed codebook excitation */ + const Word16 L_subfr /* i : subframe length */ ) { Word16 i, pos, sgn, index; @@ -332,7 +331,7 @@ void acelp_1t64_fx( /*-------------------------------------------------------------------* * Find position and sign of maximum impulse. *-------------------------------------------------------------------*/ - pos = emaximum_fx( 0, dn, L_SUBFR, &L_tmp ); + pos = emaximum_fx( 0, dn, L_subfr, &L_tmp ); IF(dn[pos]<0) { @@ -349,13 +348,13 @@ void acelp_1t64_fx( * Build the codeword, the filtered codeword and index of codevector. *-------------------------------------------------------------------*/ - set16_fx( code, 0, L_SUBFR ); + set16_fx( code, 0, L_subfr ); code[pos] = sgn; move16(); - set16_fx( y, 0, L_SUBFR ); + set16_fx( y, 0, L_subfr ); - FOR( i=pos; i0) { @@ -373,10 +372,15 @@ void acelp_1t64_fx( move16(); if( sgn > 0 ) { - index = add(index,L_SUBFR); + index = add(index,L_subfr); + } + IF (EQ_16(L_subfr, L_SUBFR) ) + { + push_indice_fx( hBstr, IND_ALG_CDBK_1T64, index, 7 ); } + ELSE /* L_subfr == 2*L_SUBFR */ { - push_indice_fx( st_fx, IND_ALG_CDBK_1T64, index, 7 ); + push_indice_fx(hBstr, IND_ALG_CDBK_1T64, index, 8); } return; diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c index 3008aaf..d08619e 100644 --- a/lib_enc/cod4t64_fx.c +++ b/lib_enc/cod4t64_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* VMR-WB compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* @@ -30,9 +29,9 @@ static Word32 quant_6p_6N_2_fx( const Word16 pos[], const Word16 N ); -static Word32 fcb_encode_position_fx(Word16 pos_vector[],Word32 n,Word32 pos_num,Word32 flag); -static Word32 fcb_encode_class_fx(Word32 sector_6p_num[],Word32 pulse_num,Word32 pulse_pos_num); -static Word32 fcb_encode_PI_fx(const Word16 v[], Word32 pulse_num); +static Word32 fcb_encode_position_fx(const Word16 pos_vector[],Word32 n, const Word32 pos_num, const Word32 flag); +static Word32 fcb_encode_class_fx(const Word32 sector_6p_num[], const Word32 pulse_num, const Word32 pulse_pos_num); +static Word32 fcb_encode_PI_fx(const Word16 v[], const Word32 pulse_num); static Word32 pre_process_fx( const Word16 v[], Word16 sector_6p[], Word32 sector_6p_num[], Word32 *pulse_pos_num ); /*---------------------------------------------------------------------* @@ -56,17 +55,17 @@ static Word32 pre_process_fx( const Word16 v[], Word16 sector_6p[], Word32 secto *---------------------------------------------------------------------*/ Word16 acelp_4t64_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 cn[], /* i : residual after long term prediction Q_new*/ - const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ - Word16 R[], /* i : autocorrelation values */ - const Word16 acelpautoc, /* i : autocorrealtion flag */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - Word16 y[], /* o : filtered fixed codebook excitation Q9*/ - Word16 nbbits, /* i : number of bits per codebook */ - const Word16 cmpl_flag, /* i : complexity reduction flag */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 dn[], /* i : corr. between target and h[]. */ + const Word16 cn[], /* i : residual after long term prediction Q_new*/ + const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ + Word16 R[], /* i : autocorrelation values */ + const Word16 acelpautoc, /* i : autocorrealtion flag */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ + Word16 y[], /* o : filtered fixed codebook excitation Q9*/ + Word16 nbbits, /* i : number of bits per codebook */ + const Word16 cmpl_flag, /* i : complexity reduction flag */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ) { @@ -331,11 +330,11 @@ Word16 acelp_4t64_fx( bitcnt = s_and(nbbits, 15); FOR ( i = 0; i < wordcnt; i++ ) { - push_indice_fx( st_fx, IND_ALG_CDBK_4T64, indexing_indices[i], 16 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64, indexing_indices[i], 16 ); } IF ( bitcnt ) { - push_indice_fx( st_fx, IND_ALG_CDBK_4T64, indexing_indices[i], bitcnt ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64, indexing_indices[i], bitcnt ); } } ELSE @@ -348,7 +347,7 @@ Word16 acelp_4t64_fx( { k = i_mult2(track, NPMAXPT); index = quant_1p_N1_fx(ind[k], 4); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64, index, 5 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64, index, 5 ); } } ELSE IF (EQ_16(nbbits,36)) @@ -358,7 +357,7 @@ Word16 acelp_4t64_fx( k = i_mult2(track, NPMAXPT); /* k = track * NPMAXPT;*/ index = quant_2p_2N1_fx(ind[k], ind[k+1], 4); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64, index, 9 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64, index, 9 ); } } ELSE IF (EQ_16(nbbits,44)) /* AMR-WB pulse indexing */ @@ -367,14 +366,14 @@ Word16 acelp_4t64_fx( { k = i_mult2(track, NPMAXPT); index = quant_3p_3N1_fx(ind[k], ind[k+1], ind[k+2], 4); - push_indice_fx(st_fx, IND_ALG_CDBK_4T64, index, 13 ); + push_indice_fx(hBstr, IND_ALG_CDBK_4T64, index, 13 ); } FOR (track = 2; track < NB_TRACK_FCB_4T; track++) { k = i_mult2(track, NPMAXPT); index = quant_2p_2N1_fx(ind[k], ind[k+1], 4); - push_indice_fx(st_fx, IND_ALG_CDBK_4T64, index, 9 ); + push_indice_fx(hBstr, IND_ALG_CDBK_4T64, index, 9 ); } } ELSE IF (EQ_16(nbbits,52)) /* AMR-WB pulse indexing */ @@ -383,7 +382,7 @@ Word16 acelp_4t64_fx( { k = i_mult2(track,NPMAXPT); index = quant_3p_3N1_fx(ind[k], ind[k+1], ind[k+2], 4); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64, index, 13 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64, index, 13 ); } } ELSE IF (EQ_16(nbbits,64)) /* AMR-WB pulse indexing */ @@ -394,7 +393,7 @@ Word16 acelp_4t64_fx( L_index = quant_4p_4N_fx(&ind[k], 4); index = extract_l(L_shr(L_index, 14) & 3); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_1, index, 2 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_1, index, 2 ); } FOR (track = 0; track < NB_TRACK_FCB_4T; track++) @@ -403,7 +402,7 @@ Word16 acelp_4t64_fx( L_index = quant_4p_4N_fx(&ind[k], 4); index = extract_l(L_index & 0x3FFF); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_2, index, 14 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_2, index, 14 ); } } ELSE IF (EQ_16(nbbits,72)) @@ -414,7 +413,7 @@ Word16 acelp_4t64_fx( L_index = quant_5p_5N_fx(&ind[k], 4); index = extract_l(L_shr(L_index, 10) & 0x03FF); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_1, index, 10 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_1, index, 10 ); } FOR(track = 2; track < NB_TRACK_FCB_4T; track++) @@ -423,7 +422,7 @@ Word16 acelp_4t64_fx( L_index = quant_4p_4N_fx(&ind[k], 4); index = extract_l(L_shr(L_index, 14) & 3); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_1, index, 2 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_1, index, 2 ); } FOR(track=0; track< (NB_TRACK_FCB_4T - 2); track++) @@ -432,7 +431,7 @@ Word16 acelp_4t64_fx( L_index = quant_5p_5N_fx(&ind[k], 4); index = extract_l(L_index & 0x03FF); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_2, index, 10 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_2, index, 10 ); } FOR(track = 2; track < NB_TRACK_FCB_4T; track++) @@ -441,7 +440,7 @@ Word16 acelp_4t64_fx( L_index = quant_4p_4N_fx(&ind[k], 4); index = extract_l(L_index & 0x3FFF); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_2, index, 14 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_2, index, 14 ); } } ELSE IF (EQ_16(nbbits,88)) @@ -452,7 +451,7 @@ Word16 acelp_4t64_fx( L_index = quant_6p_6N_2_fx(&ind[k], 4); index = extract_l(L_shr(L_index, 11) & 0x07FF); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_1, index, 11 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_1, index, 11 ); } FOR (track = 0; track < NB_TRACK_FCB_4T; track++) @@ -461,7 +460,7 @@ Word16 acelp_4t64_fx( L_index = quant_6p_6N_2_fx(&ind[k], 4); index = extract_l(L_index & 0x07FF); logic16(); - push_indice_fx( st_fx, IND_ALG_CDBK_4T64_2, index, 11 ); + push_indice_fx( hBstr, IND_ALG_CDBK_4T64_2, index, 11 ); } } } @@ -476,9 +475,9 @@ Word16 acelp_4t64_fx( *---------------------------------------------------------------------*/ static Word32 fcb_encode_cl_fx(/* o: class index of the pulse on a track */ - Word32 buffer[], /* i: pulses on a track */ - Word32 pulse_num, /* i: pulses number on a track */ - Word32 pos_num /* i: number of the position which have pulse */ + const Word32 buffer[], /* i: pulses on a track */ + const Word32 pulse_num, /* i: pulses number on a track */ + const Word32 pos_num /* i: number of the position which have pulse */ ) { Word32 i,k; @@ -505,7 +504,7 @@ static Word32 fcb_encode_cl_fx(/* o: class index of the pulse on a track *---------------------------------------------------------------------*/ static Word32 fcb_encode_PI_fx( /* o: return index of the pulse on a track */ const Word16 v[], /* i: pulse on a track */ - Word32 pulse_num /* i: number of the pulse on a track */ + const Word32 pulse_num /* i: number of the pulse on a track */ ) { Word16 sector_p[7]; @@ -532,9 +531,9 @@ static Word32 fcb_encode_PI_fx( /* o: return index of the pulse on a track */ *encode the class and compute class offset * *---------------------------------------------------------------------*/ static Word32 fcb_encode_class_fx(/* o: class offset */ - Word32 sector_6p_num[], /* i: position which have pulse on a track */ - Word32 pulse_num, /* i: pulse number on a track */ - Word32 pulse_pos_num /* i: number of position which have pulse on a track */ + const Word32 sector_6p_num[], /* i: position which have pulse on a track */ + const Word32 pulse_num, /* i: pulse number on a track */ + const Word32 pulse_pos_num /* i: number of position which have pulse on a track */ ) { Word32 i,j,k; @@ -568,10 +567,10 @@ static Word32 fcb_encode_class_fx(/* o: class offset */ *encode the position * *---------------------------------------------------------------------*/ static Word32 fcb_encode_position_fx( /* o: return index of the positions which have pulse*/ - Word16 pos_vector[], /* i: position of the pulse on a track */ + const Word16 pos_vector[], /* i: position of the pulse on a track */ Word32 n, - Word32 pos_num, /* i: the number of position which have pulse */ - Word32 flag + const Word32 pos_num, /* i: the number of position which have pulse */ + const Word32 flag ) { Word32 i; @@ -617,7 +616,8 @@ static Word32 fcb_encode_position_fx( /* o: return index of the positions whic *-------------------------------------------------------------*/ static Word16 quant_1p_N1_fx( /* o : return N+1 bits */ const Word16 pos, /* i : position of the pulse */ - const Word16 N) /* i : number of bits FOR position */ + const Word16 N /* i : number of bits FOR position */ +) { Word16 mask; Word16 index; @@ -642,7 +642,8 @@ static Word16 quant_1p_N1_fx( /* o : return N+1 bits */ static Word16 quant_2p_2N1_fx( /* o: return (2*N)+1 bits */ const Word16 pos1, /* i: position of the pulse 1 */ const Word16 pos2, /* i: position of the pulse 2 */ - const Word16 N) /* i: number of bits FOR position */ + const Word16 N /* i: number of bits FOR position */ +) { Word16 mask, tmp; Word16 index; @@ -706,11 +707,12 @@ static Word16 quant_2p_2N1_fx( /* o: return (2*N)+1 bits */ /*---------------------------------------------------------------------* * Quantization of 3 pulses with 3*N+1 bits: * *---------------------------------------------------------------------*/ -static Word16 quant_3p_3N1_fx( /* (o) return (3*N)+1 bits */ - const Word16 pos1, /* (i) position of the pulse 1 */ - const Word16 pos2, /* (i) position of the pulse 2 */ - const Word16 pos3, /* (i) position of the pulse 3 */ - const Word16 N) /* (i) number of bits for position */ +static Word16 quant_3p_3N1_fx( /* o : return (3*N)+1 bits */ + const Word16 pos1, /* i : position of the pulse 1 */ + const Word16 pos2, /* i : position of the pulse 2 */ + const Word16 pos3, /* i : position of the pulse 3 */ + const Word16 N /* i : number of bits for position */ +) { Word16 nb_pos; Word16 index; @@ -757,12 +759,13 @@ static Word16 quant_3p_3N1_fx( /* (o) return (3*N)+1 bits /*---------------------------------------------------------------------* * Quantization of 4 pulses with 4*N+1 bits: * *---------------------------------------------------------------------*/ -static Word32 quant_4p_4N1_fx( /* (o) return (4*N)+1 bits */ - const Word16 pos1, /* (i) position of the pulse 1 */ - const Word16 pos2, /* (i) position of the pulse 2 */ - const Word16 pos3, /* (i) position of the pulse 3 */ - const Word16 pos4, /* (i) position of the pulse 4 */ - const Word16 N) /* (i) number of bits for position */ +static Word32 quant_4p_4N1_fx( /* o : return (4*N)+1 bits */ + const Word16 pos1, /* i : position of the pulse 1 */ + const Word16 pos2, /* i : position of the pulse 2 */ + const Word16 pos3, /* i : position of the pulse 3 */ + const Word16 pos4, /* i : position of the pulse 4 */ + const Word16 N /* i : number of bits for position */ +) { Word16 nb_pos; Word32 index; @@ -808,9 +811,10 @@ static Word32 quant_4p_4N1_fx( /* (o) return (4*N)+1 bits * Quantization of 4 pulses with 4*N bits: * *---------------------------------------------------------------------*/ -static Word32 quant_4p_4N_fx( /* (o) return 4*N bits */ - const Word16 pos[], /* (i) position of the pulse 1..4 */ - const Word16 N) /* (i) number of bits for position */ +static Word32 quant_4p_4N_fx( /* o : return 4*N bits */ + const Word16 pos[], /* i : position of the pulse 1..4 */ + const Word16 N /* i : number of bits for position */ +) { Word16 i, j, k, nb_pos, n_1, tmp; Word16 posA[4], posB[4]; @@ -839,7 +843,7 @@ static Word32 quant_4p_4N_fx( /* (o) return 4*N bits } } - SWITCH (i) + SWITCH (i) { case 0: tmp = sub(shl(N, 2), 3); /* index = 1 << ((4*N)-3); */ @@ -873,16 +877,16 @@ static Word32 quant_4p_4N_fx( /* (o) return 4*N bits fprintf(stderr, "Error in function quant_4p_4N_fx\n"); } tmp = sub(shl(N, 2), 2); /* index += (i & 3) << ((4*N)-2); */ - index = L_add(index, L_shl((L_deposit_l(i) & (3L)), tmp)); + index = L_add(index, L_shl((L_deposit_l (i) & (3L)), tmp)); logic16(); return (index); } -static Word32 quant_5p_5N_fx( /* (o) return 5*N bits */ - const Word16 pos[], /* (i) position of the pulse 1..5 */ - const Word16 N) /* (i) number of bits for position */ +static Word32 quant_5p_5N_fx( /* o : return 5*N bits */ + const Word16 pos[], /* i : position of the pulse 1..5 */ + const Word16 N) /* i : number of bits for position */ { Word16 i, j, k, nb_pos, n_1, tmp; Word16 posA[5], posB[5]; @@ -911,7 +915,7 @@ static Word32 quant_5p_5N_fx( /* (o) return 5*N bits } } - SWITCH (i) + SWITCH (i) { case 0: tmp = sub(extract_l(L_shr(L_mult(5, N), 1)), 1); /* ((5*N)-1)) */ @@ -960,9 +964,9 @@ static Word32 quant_5p_5N_fx( /* (o) return 5*N bits return (index); } -static Word32 quant_6p_6N_2_fx( /* (o) return (6*N)-2 bits */ - const Word16 pos[], /* (i) position of the pulse 1..6 */ - const Word16 N) /* (i) number of bits for position */ +static Word32 quant_6p_6N_2_fx( /* o : return (6*N)-2 bits */ + const Word16 pos[], /* i : position of the pulse 1..6 */ + const Word16 N) /* i : number of bits for position */ { Word16 i, j, k, nb_pos, n_1; Word16 posA[6], posB[6]; @@ -1037,7 +1041,7 @@ static Word32 quant_6p_6N_2_fx( /* (o) return (6*N)-2 bits index = 0; fprintf(stderr, "Error in function quant_6p_6N_2_fx\n"); } - index = L_add(index, L_shl((L_deposit_l(i) & 3L), (Word16) (6 * N - 4))); + index = L_add(index, L_shl((L_deposit_l (i) & 3L), (Word16) (6 * N - 4))); logic16();/* index += (i & 3) << ((6*N)-4); */ return (index); @@ -1095,7 +1099,12 @@ static Word32 pre_process_fx( /* o: return sign value of pulse on a track * trackstep - (input) step between tracks *--------------------------------------------------------------------------*/ -Word16 E_ACELP_code43bit(const Word16 code[], UWord32 *ps, Word16 *p, UWord16 idxs[]) +Word16 E_ACELP_code43bit( + const Word16 code[], + UWord32 *ps, + Word16 *p, + UWord16 idxs[] +) { Word16 i,j,k,track; Word16 ind[32]; diff --git a/lib_enc/cod_ace.c b/lib_enc/cod_ace.c index 3d8137b..75ac72f 100644 --- a/lib_enc/cod_ace.c +++ b/lib_enc/cod_ace.c @@ -2,14 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include +#include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "options.h" -#include "stl.h" - #include "rom_basop_util.h" /*-------------------------------------------------------------------* @@ -18,32 +16,32 @@ * Encode ACELP frame *-------------------------------------------------------------------*/ -Word16 coder_acelp( /* output SEGSNR for CL decision */ - ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - Word16 synth[], - LPD_state *LPDmem, - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ - Word16 *prm, /* output: acelp parameters */ +Word16 coder_acelp( /* o : SEGSNR for CL decision */ + const Word16 A[], /* i : coefficients 4xAz[M+1] */ + const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] */ + const Word16 speech[], /* i : speech[-M..lg] */ + Word16 *prm, /* o : acelp parameters */ Word16 stab_fac, Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 target_bits, /* i/o : coder memory state */ - Word16 Q_new, - Word16 shift - ,Word16 *pitch_buf /* output : pitch values for each subfr.*/ - ,Word16 *voice_factors /* output : voicing factors */ - ,Word16 *bwe_exc /* output : excitation for SWB TBE */ + PLC_ENC_EVS_HANDLE hPlc_Ext, + const Word16 target_bits, /* i/o: coder memory state */ + const Word16 Q_new, + const Word16 shift, + Word16 *pitch_buf, /* o : pitch values for each subfr.*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc /* o : excitation for SWB TBE */ ) { +#ifndef SIMPLIFY_CODE_BE Word16 i, j, i_subfr, j_subfr; + Word16 tmp, tmp2, Es_pred; + Word32 gain_code_vect[2]; +#else + Word16 i, i_subfr, j_subfr; + Word16 tmp, Es_pred; +#endif Word16 T0, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; Word16 T0_frac; - Word16 tmp, tmp2, Es_pred; Word16 gain_pit, voice_fac; Word32 gain_code, Ltmp, Ltmp2; ACELP_CbkCorr g_corr; @@ -69,12 +67,19 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ Word32 gain_code2; Word16 code2[L_SUBFR]; Word16 y22[L_SUBFR]; /* Filtered adaptive excitation */ - Word32 gain_code_vect[2]; Word16 error = 0; Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ Word16 dummy = 0; + ACELP_config* acelp_cfg; + + acelp_cfg = &(st->acelp_cfg); + LPD_state_HANDLE hLPDmem = st->hLPDmem; + RF_ENC_HANDLE hRF = st->hRF; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + set16_fx(code_preQ, 0, L_SUBFR); @@ -85,7 +90,7 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ /* Configure ACELP */ - LPDmem->nbits = BITS_ALLOC_config_acelp( target_bits, coder_type, &(st->acelp_cfg), st->narrowBand, st->nb_subfr ); + hLPDmem->nbits = BITS_ALLOC_config_acelp( target_bits, st->coder_type, acelp_cfg, st->narrowBand, st->nb_subfr ); /* Init Framing parameters */ move16(); @@ -108,63 +113,52 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ Q_new_p5 = add(Q_new, 5); /* Reset phase dispersion */ - IF (st->last_core_fx > ACELP_CORE) + IF (GT_16(st->last_core_fx, ACELP_CORE)) { move16(); move16(); move16(); - st->dm_fx.prev_gain_code = 0; - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); - st->dm_fx.prev_state = 0; + + hLPDmem->dm_fx.prev_gain_code = 0; + set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + hLPDmem->dm_fx.prev_state = 0; + } /* set excitation memory*/ move16(); move16(); exc = exc_buf+L_EXC_MEM; - Copy(LPDmem->old_exc, exc_buf, L_EXC_MEM); + Copy(hLPDmem->old_exc, exc_buf, L_EXC_MEM); *(exc+st->L_frame_fx) = 0; /* Init syn buffer */ move16(); syn = syn_buf + M; - Copy(LPDmem->mem_syn, syn_buf, M); + Copy(hLPDmem->mem_syn, syn_buf, M); /* calculate residual */ - move16(); - p_Aq = Aq; - FOR (i_subfr=0; i_subfrnrg_mode>0) { - - Es_pred_enc_fx(&Es_pred, prm, L_frame, exc, voicing, acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1, Q_new - ); + Es_pred_enc_fx(&Es_pred, prm, L_frame, exc, st->voicing_fx, acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1, Q_new); prm++; } - ELSE - { - - Es_pred=0; - } IF (EQ_16(st->L_frame_fx,L_FRAME)) { - Copy(Aq+2*(M+1), st->cur_sub_Aq_fx, (M+1)); + Copy(Aq+2*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1)); } ELSE { - Copy(Aq+3*(M+1), st->cur_sub_Aq_fx, (M+1)); + Copy(Aq+3*(M+1), hBWE_TD->cur_sub_Aq_fx, (M+1)); } @@ -210,20 +204,7 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * Find target for pitch search (xn[]), target for innovation search (cn[]) * * and impulse response of the weighted synthesis filter (h1[]). * *--------------------------------------------------------------------------*/ - find_targets_fx( - speech, - &syn[i_subfr-M], - i_subfr, - &LPDmem->mem_w0, - p_Aq, - exc, - L_SUBFR, - p_A, - st->preemph_fac, - xn, - cn - ,h1 - ); + find_targets_fx(speech, &syn[i_subfr-M], i_subfr, &hLPDmem->mem_w0, p_Aq, exc, L_SUBFR, p_A, st->preemph_fac, xn, cn, h1); /*---------------------------------------------------------------* * Compute impulse response, h1[], of weighted synthesis filter * @@ -238,7 +219,7 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = Mode2_gp_clip( voicing, i_subfr, coder_type, xn, st->clip_var_fx, L_SUBFR, Q_xn ); + clip_gain = Mode2_gp_clip( st->voicing_fx, i_subfr, st->coder_type, xn, st->clip_var_fx, L_SUBFR, Q_xn ); /*-----------------------------------------------------------------* * - find unity gain pitch excitation (adaptive codebook entry) * @@ -251,50 +232,11 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ { /* Adaptive Codebook (GC and VC) */ - Mode2_pit_encode( acelp_cfg->ltp_mode, - i_subfr, - &prm, - &exc[i_subfr], - T_op, - &T0_min, - &T0_min_frac, - &T0_max, - &T0_max_frac, - &T0, - &T0_frac, - &T0_res, - h1, - xn, - st->pit_min, - st->pit_fr1, - st->pit_fr1b, - st->pit_fr2, - st->pit_max, - st->pit_res_max); - - E_ACELP_adaptive_codebook( exc, - T0, - T0_frac, - T0_res, - st->pit_res_max, - acelp_cfg->ltf_mode, - i_subfr, - L_SUBFR, - L_frame, - h1, - clip_gain, - xn, - y1, - &g_corr, - &prm, - &gain_pit, - xn_exp - ,0 - ,0 - ,&dummy - ); - + Mode2_pit_encode( acelp_cfg->ltp_mode, i_subfr, &prm, &exc[i_subfr], st->pitch_fx, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, + &T0, &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max); + E_ACELP_adaptive_codebook( exc, T0, T0_frac, T0_res, st->pit_res_max, acelp_cfg->ltf_mode, i_subfr, L_SUBFR, L_frame, h1, clip_gain, xn, + y1, &g_corr, &prm, &gain_pit, xn_exp, 0, 0, &dummy); } ELSE IF ( acelp_cfg->ltp_bits==0 ) @@ -310,6 +252,7 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ T0 = L_SUBFR; T0_frac = 0; T0_res = 1; + move16(); move16(); move16(); move16(); move16(); move16(); move16(); move16(); } IF( st->igf != 0 ) @@ -323,35 +266,7 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - E_ACELP_innovative_codebook( exc, - T0, - T0_frac, - T0_res, - gain_pit, - LPDmem->tilt_code, - acelp_cfg->fixed_cdk_index[j_subfr], - acelp_cfg->formant_enh, - acelp_cfg->formant_tilt, - acelp_cfg->formant_enh_num, - acelp_cfg->formant_enh_den, - acelp_cfg->pitch_sharpening, - acelp_cfg->pre_emphasis, - acelp_cfg->phase_scrambling, - i_subfr, - p_Aq, - h1, - xn, - cn, - y1, - y2, - st->acelp_autocorr, - &prm, - code, - shift - ,st->L_frame_fx, - st->last_L_frame_fx, - st->total_brate_fx - ); + E_ACELP_innovative_codebook( exc, T0, T0_frac, T0_res, gain_pit, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq, h1, xn, cn, y1, y2, st->acelp_autocorr, &prm, code, shift ,st->L_frame_fx, st->last_L_frame_fx, st->total_brate_fx); E_ACELP_xy2_corr(xn, y1, y2, &g_corr, L_SUBFR, Q_xn); @@ -367,20 +282,8 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ IF (EQ_16(acelp_cfg->gains_mode[j_subfr], 7)) { - - gauss_L2(h1, - code2, - y2, - y22, - &gain_code2, - &g_corr, - gain_pit, - LPDmem->tilt_code, - p_Aq, - acelp_cfg->formant_enh_num, - &(st->seed_acelp), - shift - ); + assert(gain_pit == 0); + gauss_L2(h1, code2, y2, y22, &gain_code2, &g_corr, gain_pit, hLPDmem->tilt_code, p_Aq, acelp_cfg->formant_enh_num, &(st->seed_acelp), shift ); } ELSE { @@ -394,47 +297,26 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * - quantize fixed codebook gain * *----------------------------------------------------------*/ - encode_acelp_gains( code, - acelp_cfg->gains_mode[j_subfr], - Es_pred, - clip_gain, - &g_corr, - &gain_pit, - &gain_code, - &prm, - &past_gcode, - &gain_inov, - L_SUBFR, - code2, - &gain_code2, - st->flag_noisy_speech_snr - ); - - gp_clip_test_gain_pit_fx( st->core_brate_fx, gain_pit, st->clip_var_fx ); + encode_acelp_gains( code, acelp_cfg->gains_mode[j_subfr], Es_pred, clip_gain, &g_corr, &gain_pit, &gain_code, &prm, + &past_gcode, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr ); + + gp_clip_test_gain_pit_fx(st->element_mode, st->core_brate_fx, gain_pit, st->clip_var_fx ); +#ifndef SIMPLIFY_CODE_BE gain_code_vect[0] = gain_code; move32(); gain_code_vect[1] = gain_code; move32(); - +#endif /*----------------------------------------------------------* * - voice factor (for pitch enhancement) * *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc, - i_subfr, - code, - gain_pit, - gain_code, - &voice_fac, - &(LPDmem->tilt_code), - L_SUBFR, - acelp_cfg->voice_tilt, - Q_new, - shift - ); - - st->rf_tilt_buf[i_subfr/L_SUBFR] = LPDmem->tilt_code; + E_UTIL_voice_factor( exc, i_subfr, code, gain_pit, gain_code, &voice_fac, &(hLPDmem->tilt_code), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift); + IF(st->Opt_RF_ON) + { + hRF->rf_tilt_buf[i_subfr / L_SUBFR] = hLPDmem->tilt_code; + } /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ @@ -446,18 +328,16 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR-1]); Ltmp2 = L_shl(Ltmp2, add(5,Q_xn)); Ltmp = L_add(Ltmp, Ltmp2); - LPDmem->mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); + hLPDmem->mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); move16(); BASOP_SATURATE_WARNING_OFF; - LPDmem->mem_w0 =shr(LPDmem->mem_w0, shift); /*Qnew-1*/ + hLPDmem->mem_w0 =shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ BASOP_SATURATE_WARNING_ON; - - /*-------------------------------------------------------* * - Find the total excitation. * *-------------------------------------------------------*/ - +#ifndef SIMPLIFY_CODE_BE tmp2 = shr(L_SUBFR, 1); FOR (j = 0; j < 2; j++) { @@ -482,57 +362,48 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ tmp2 = L_SUBFR; move16(); } - +#else + FOR (i = 0; i < L_SUBFR; i++) + { + /* code in Q9, gain_pit in Q14; exc Q_new */ + Ltmp = Mpy_32_16_1(gain_code2, code2[i]); + Ltmp = L_shl(Ltmp, Q_new_p5); + Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); + BASOP_SATURATE_WARNING_OFF + exc2[i] = round_fx(L_shl(Ltmp, 1)); + BASOP_SATURATE_WARNING_ON + + Ltmp2 = Mpy_32_16_1(gain_code, code[i]); + Ltmp2 = L_shl(Ltmp2, Q_new_p5); + Ltmp = L_add(Ltmp, Ltmp2); + BASOP_SATURATE_WARNING_OFF + Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ + BASOP_SATURATE_WARNING_ON + exc[i + i_subfr] = round_fx(Ltmp); + } +#endif /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ IF( st->igf != 0 ) { - prep_tbe_exc_fx( L_frame, - i_subfr, - gain_pit, - gain_code, - code, - voice_fac, - &voice_factors[i_subfr/L_SUBFR], - bwe_exc, - gain_preQ, - code_preQ, - Q_new, - T0, - T0_frac, - coder_type, - st->core_brate_fx ); + prep_tbe_exc_fx( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], + bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate_fx ); } /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ - E_UTIL_enhancer( voice_fac, - stab_fac, - past_gcode, - gain_inov, - &LPDmem->gc_threshold, - code, - exc2, - gain_pit, - &st->dm_fx.prev_gain_code, - st->dm_fx.prev_gain_pit, - &st->dm_fx.prev_state, - coder_type, - acelp_cfg->fixed_cdk_index[j_subfr], - L_SUBFR, - L_frame, - Q_new - ); + E_UTIL_enhancer( voice_fac, stab_fac, past_gcode, gain_inov, &hLPDmem->gc_threshold, code, exc2, gain_pit, &hLPDmem->dm_fx.prev_gain_code, + hLPDmem->dm_fx.prev_gain_pit, &hLPDmem->dm_fx.prev_state, st->coder_type, acelp_cfg->fixed_cdk_index[j_subfr], L_SUBFR, L_frame, Q_new); /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, LPDmem->mem_syn2, 1, M); + E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, hLPDmem->mem_syn2, 1, M); /*Save data for BPF*/ @@ -571,9 +442,9 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ /*----------------------------------------------------------* * Update LPD memory * *----------------------------------------------------------*/ - Copy (exc+L_frame-L_EXC_MEM, LPDmem->old_exc, L_EXC_MEM); - Copy(syn+L_frame-M, LPDmem->mem_syn, M); - Copy(syn+L_frame-L_SYN_MEM, LPDmem->mem_syn_r, L_SYN_MEM); + Copy (exc+L_frame-L_EXC_MEM, hLPDmem->old_exc, L_EXC_MEM); + Copy(syn+L_frame-M, hLPDmem->mem_syn, M); + Copy(syn+L_frame-L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM); IF( hPlc_Ext != NULL ) { @@ -589,12 +460,15 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ *----------------------------------------------------------*/ Copy(syn2, syn, L_frame); move16(); - tmp = LPDmem->syn[M]; + tmp = hLPDmem->syn[M]; E_UTIL_deemph2(sub(Q_new,1), syn, st->preemph_fac, L_frame, &tmp); - bufferCopyFx(syn+L_frame-(L_frame/2), LPDmem->Txnq, shr(L_frame,1),0 /*Qf_syn*/, -1 /*Qf_Txnq*/, 0 /*Q_syn*/ , 0 /*Q_Txnq*/); - Copy(syn+L_frame-M-1, LPDmem->syn, 1+M); /*Q0*/ - Copy(syn, synth, L_frame); + if (st->hTcxEnc != NULL) + { + bufferCopyFx(syn + L_frame - (L_frame / 2), hTcxEnc->Txnq, shr(L_frame, 1), 0 /*Qf_syn*/, -1 /*Qf_Txnq*/, 0 /*Q_syn*/, 0 /*Q_Txnq*/); + } + Copy(syn+L_frame-M-1, hLPDmem->syn, 1+M); /*Q0*/ + Copy(syn, st->synth, L_frame); assert(T0_res <= 6); diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index dcd3ddc..8d5ca1b 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -16,7 +16,7 @@ /* Up to the Autocorrelation it is the same code as in GetMDCT, with the difference in the parameters in the call to tcx_windowing_analysis */ void HBAutocorrelation( - TCX_config *tcx_cfg, /* input: configuration of TCX */ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 left_overlap_mode, /* input: overlap mode of left window half */ Word16 right_overlap_mode, /* input: overlap mode of right window half */ Word16 speech[], /* input: speech[-LFAC..L_frame+LFAC] */ @@ -35,7 +35,7 @@ void HBAutocorrelation( * Windowing * *-----------------------------------------------------------*/ - WindowSignal(tcx_cfg, tcx_cfg->tcx_offset, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, speech, &L_frame, y, 0); + WindowSignal(hTcxCfg, hTcxCfg->tcx_offset, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, speech, &L_frame, y, 1, 0); /*-----------------------------------------------------------* * Autocorrelation * @@ -126,9 +126,489 @@ void HBAutocorrelation( } } +#ifdef ADD_IVAS_TNS +/*-------------------------------------------------------------------* + * TNSAnalysisStereo() + * + * + *-------------------------------------------------------------------*/ + +#define SIMILAR_TNS_THRESHOLD ( 0.04f ) +#define TNS_GAIN_THRESHOLD_FOR_WHITE ( 3.0f ) + +void TNSAnalysisStereo( + Encoder_State** sts, /* i : encoder state handle */ + float* mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* o : MDST spectrum */ + const int16_t bWhitenedDomain, /* i : whitened domain flag */ + int16_t tnsSize[MCT_MAX_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm */ + int16_t tnsBits[MCT_MAX_CHANNELS][NB_DIV], /* i : number of tns bits in the frame */ + int16_t param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters */ + const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ +) +{ + int16_t ch, k, L_spec, L_frame, nSubframes, iFilter; + float* spectrum; + Encoder_State* st = NULL; + TCX_ENC_HANDLE hTcxEnc = NULL; + int16_t individual_decision[NB_DIV]; + float maxPredictionGain = 0.f, meanPredictionGain; + + individual_decision[0] = 0; + individual_decision[1] = 0; + L_spec = -1; + L_frame = -1; + + /* TNS filter analysis, loop over channels */ + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + st = sts[ch]; + if (st->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + { + continue; + } + + hTcxEnc = st->hTcxEnc; + + nSubframes = (hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + + for (k = 0; k < nSubframes; k++) + { + /* reset tns on whitened domain flag */ + if (!bWhitenedDomain) + { + hTcxEnc->bTnsOnWhithenedSpectra[k] = 0; + hTcxEnc->fUseTns[k] = 0; + } + + if (st->hTcxCfg->fIsTNSAllowed && (!bWhitenedDomain || hTcxEnc->bTnsOnWhithenedSpectra[k])) + { + + spectrum = hTcxEnc->spectrum[k]; + L_frame = hTcxEnc->L_frameTCX; + st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (st->last_core == ACELP_CORE)]; + L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; + + /*-----------------------------------------------------------* + * Temporal Noise Shaping analysis * + *-----------------------------------------------------------*/ + + if (hTcxEnc->transform_type[k] == TCX_5) + { + /* rearrange LF sub-window lines prior to TNS analysis & filtering */ + tcx5TnsGrouping(L_frame >> 2, L_spec >> 1, spectrum); + } + + /* WMOPS: All initializations are either for safety or static (tables) and thus not to be counted */ + ResetTnsData(&hTcxEnc->tnsData[k]); + if (st->hTcxCfg->pCurrentTnsConfig->maxOrder <= 0) + { + break; + } + + CalculateTnsFilt(st->hTcxCfg->pCurrentTnsConfig, spectrum, &hTcxEnc->tnsData[k], NULL); + } + } + } + + if (!mct_on) + { + /* TNS decision */ + /* if framing differs between channels, keep the filter decision per channel */ + if ((sts[0]->hTcxEnc->transform_type[0] != sts[1]->hTcxEnc->transform_type[0] && + sts[0]->hTcxEnc->transform_type[1] != sts[1]->hTcxEnc->transform_type[1]) || + sts[0]->hTcxCfg->fIsTNSAllowed != sts[1]->hTcxCfg->fIsTNSAllowed) + { + individual_decision[0] = individual_decision[1] = 1; + } + else if (bWhitenedDomain) + { + nSubframes = (sts[0]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + for (k = 0; k < nSubframes; k++) + { + if (sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] != sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k]) + { + individual_decision[k] = 1; + } + } + } + + /* framing equal, check for similar filters, if very similar (also indicator for and M signal), + * use at least the same decision, maybe use the same filter + */ + { + int16_t isTCX10; + isTCX10 = (sts[0]->hTcxEnc->tcxMode == TCX_20) ? 0 : 1; + + nSubframes = (sts[0]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + + for (k = 0; k < nSubframes; k++) + { + if (sts[0]->hTcxCfg->fIsTNSAllowed && individual_decision[k] != 1 && (!bWhitenedDomain || sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k])) + { + float maxPredGain = -1.0f; + sts[0]->hTcxCfg->pCurrentTnsConfig = &sts[0]->hTcxCfg->tnsConfig[sts[0]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[0]->last_core == ACELP_CORE)]; + sts[1]->hTcxCfg->pCurrentTnsConfig = &sts[1]->hTcxCfg->tnsConfig[sts[1]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[1]->last_core == ACELP_CORE)]; + +#ifdef DEBUGGING + assert(sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters == sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters); +#endif + for (iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + { + STnsFilter* pFilter[2]; + struct TnsParameters const* pTnsParameters[2]; + pFilter[0] = sts[0]->hTcxEnc->tnsData[k].filter + iFilter; + pTnsParameters[0] = sts[0]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter; + pFilter[1] = sts[1]->hTcxEnc->tnsData[k].filter + iFilter; + pTnsParameters[1] = sts[1]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter; + +#ifdef DEBUGGING + assert(pTnsParameters[0]->startLineFrequency == pTnsParameters[1]->startLineFrequency); + assert(pTnsParameters[0]->nSubdivisions == pTnsParameters[1]->nSubdivisions); +#endif + /* if prediction gain and avgSqrCoef are both close we are pretty sure the filters are quite similar, use the avg of + * both filters for the decision + */ + meanPredictionGain = (pFilter[0]->predictionGain + pFilter[1]->predictionGain) * 0.5f; + maxPredictionGain = max(maxPredictionGain, meanPredictionGain); + + if ((pFilter[0]->predictionGain > pTnsParameters[0]->minPredictionGain) && (sts[0]->element_brate < IVAS_80k) && + (pFilter[1]->predictionGain > pTnsParameters[1]->minPredictionGain) && (sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters)) + { + pFilter[0]->predictionGain = pFilter[1]->predictionGain = meanPredictionGain; /* more TNS filter sync at 48kbps */ + } + if ((fabs(pFilter[0]->predictionGain - pFilter[1]->predictionGain) < SIMILAR_TNS_THRESHOLD * meanPredictionGain) && + (sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters)) + { + float maxAvgSqrCoef = max(pFilter[0]->avgSqrCoef, pFilter[1]->avgSqrCoef); + float meanLtpGain = (sts[0]->hTcxEnc->tcxltp_gain + sts[1]->hTcxEnc->tcxltp_gain) * 0.5f; + maxPredGain = max(maxPredGain, meanPredictionGain); + if ((meanPredictionGain > pTnsParameters[0]->minPredictionGain) || (maxAvgSqrCoef > pTnsParameters[0]->minAvgSqrCoef)) + { + if (sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || meanLtpGain < 0.6f) + { + ++sts[0]->hTcxEnc->tnsData[k].nFilters; + pFilter[0]->filterType = TNS_FILTER_ON; + ++sts[1]->hTcxEnc->tnsData[k].nFilters; + pFilter[1]->filterType = TNS_FILTER_ON; + } + else + { + const float maxEnergyChange = (GetTCXMaxenergyChange(sts[0]->hTranDet, isTCX10, NSUBBLOCKS, 3) + GetTCXMaxenergyChange(sts[1]->hTranDet, isTCX10, NSUBBLOCKS, 3)) * 0.5f; + + if (maxEnergyChange >= pTnsParameters[0]->minEnergyChange) + { + ++sts[0]->hTcxEnc->tnsData[k].nFilters; + pFilter[0]->filterType = TNS_FILTER_ON; + ++sts[1]->hTcxEnc->tnsData[k].nFilters; + pFilter[1]->filterType = TNS_FILTER_ON; + } + else + { + pFilter[0]->filterType = TNS_FILTER_OFF; + pFilter[1]->filterType = TNS_FILTER_OFF; + } + } + } + else if (sts[0]->hTcxEnc->tnsData[k].nFilters > 0 && sts[1]->hTcxEnc->tnsData[k].nFilters > 0) /* If a previous filter is turned on */ + { + pFilter[0]->filterType = TNS_FILTER_ON_ZERO; + pFilter[1]->filterType = TNS_FILTER_ON_ZERO; + ++sts[0]->hTcxEnc->tnsData[k].nFilters; + ++sts[1]->hTcxEnc->tnsData[k].nFilters; + } + else if (sts[0]->hTcxEnc->tnsData[k].nFilters != sts[1]->hTcxEnc->tnsData[k].nFilters) /* sanity check */ + { + assert(0); + } + else + { + pFilter[0]->filterType = TNS_FILTER_OFF; + pFilter[1]->filterType = TNS_FILTER_OFF; + } + if ((pFilter[0]->filterType == TNS_FILTER_ON) && (pFilter[1]->filterType == TNS_FILTER_ON) && (sts[0]->element_brate < IVAS_80k)) + { + int16_t tmpIntValue = 0; + int16_t tmpCoeff[TNS_MAX_FILTER_ORDER]; + int16_t i, maxOrder = max(pFilter[0]->order, pFilter[1]->order); + + set_s(tmpCoeff, 0, TNS_MAX_FILTER_ORDER); + for (i = 0; i < maxOrder; i++) + { + tmpIntValue = (int16_t)max(tmpIntValue, abs(pFilter[0]->coefIndex[i] - pFilter[1]->coefIndex[i])); + } + if (tmpIntValue == 1) /* the TNS coefficients are sufficiently similar to equalize the two filters */ + { + for (i = maxOrder - 1; i >= 0; i--) + { + tmpCoeff[i] = (abs(pFilter[0]->coefIndex[i]) < abs(pFilter[1]->coefIndex[i]) ? pFilter[0]->coefIndex[i] : pFilter[1]->coefIndex[i]); + if ((tmpIntValue > 0) && (tmpCoeff[i] == 0)) + { + maxOrder--; + } + else + { + tmpIntValue = 0; + } + } + /* make sure that maxOrder is non zero and not all coefficients are zero (could happen in rare cases) */ + if (maxOrder > 0) + { + for (i = TNS_MAX_FILTER_ORDER - 1; i >= 0; i--) + { + pFilter[0]->coefIndex[i] = pFilter[1]->coefIndex[i] = tmpCoeff[i]; + } + + pFilter[0]->order = pFilter[1]->order = maxOrder; + } + } + } + } + else + { + individual_decision[k] = 1; + } + } + + if (individual_decision[k] == 0) + { + sts[0]->hTcxEnc->fUseTns[k] = (sts[0]->hTcxEnc->tnsData[k].nFilters > 0) ? 1 : 0; + sts[1]->hTcxEnc->fUseTns[k] = (sts[1]->hTcxEnc->tnsData[k].nFilters > 0) ? 1 : 0; + } + else + { + sts[0]->hTcxEnc->tnsData[k].nFilters = 0; + sts[1]->hTcxEnc->tnsData[k].nFilters = 0; + sts[0]->hTcxEnc->fUseTns[k] = 0; + sts[1]->hTcxEnc->fUseTns[k] = 0; + for (iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + { + sts[0]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; + sts[1]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; + } + } + + if (!bWhitenedDomain && individual_decision[k] == 0 && maxPredGain < TNS_GAIN_THRESHOLD_FOR_WHITE && sts[0]->hTcxEnc->transform_type[k] != TCX_5) + { + sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1; + sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1; + sts[0]->hTcxEnc->tnsData[k].nFilters = 0; + sts[1]->hTcxEnc->tnsData[k].nFilters = 0; + sts[0]->hTcxEnc->fUseTns[k] = 0; + sts[1]->hTcxEnc->fUseTns[k] = 0; + for (iFilter = sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + { + ClearTnsFilterCoefficients(sts[0]->hTcxEnc->tnsData[k].filter + iFilter); + ClearTnsFilterCoefficients(sts[1]->hTcxEnc->tnsData[k].filter + iFilter); + } + } + maxPredictionGain = max(maxPredictionGain, maxPredGain); + } + } + } + } + + /* individual decision for each channel */ + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + if (sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + { + continue; + } + + int16_t isTCX10; + isTCX10 = (sts[ch]->hTcxEnc->tcxMode == TCX_20) ? 0 : 1; + + nSubframes = (sts[ch]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + + for (k = 0; k < nSubframes; k++) + { + if (sts[ch]->hTcxCfg->fIsTNSAllowed && (individual_decision[k] || mct_on) && + (!bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k])) + { + float maxPredGain = -1.0f; + + sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[ch]->last_core == ACELP_CORE)]; + + for (iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + { + STnsFilter* pFilter; + const struct TnsParameters* pTnsParameters; + pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter; + pTnsParameters = sts[ch]->hTcxCfg->pCurrentTnsConfig->pTnsParameters + iFilter; + maxPredGain = max(maxPredGain, pFilter->predictionGain); + + if ((pFilter->predictionGain > pTnsParameters->minPredictionGain) || (pFilter->avgSqrCoef > pTnsParameters->minAvgSqrCoef)) + { + if (sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || sts[ch]->hTcxEnc->tcxltp_gain < 0.6f) + { + ++sts[ch]->hTcxEnc->tnsData[k].nFilters; + pFilter->filterType = TNS_FILTER_ON; + } + else + { + const float maxEnergyChange = GetTCXMaxenergyChange(sts[ch]->hTranDet, isTCX10, NSUBBLOCKS, 3); + + if (maxEnergyChange >= pTnsParameters->minEnergyChange) + { + ++sts[ch]->hTcxEnc->tnsData[k].nFilters; + pFilter->filterType = TNS_FILTER_ON; + } + else + { + pFilter->filterType = TNS_FILTER_OFF; + } + } + } + else if (sts[ch]->hTcxEnc->tnsData[k].nFilters > 0) /* If a previous filter is turned on */ + { + pFilter->filterType = TNS_FILTER_ON_ZERO; + ++sts[ch]->hTcxEnc->tnsData[k].nFilters; + } + else + { + pFilter->filterType = TNS_FILTER_OFF; + } + } + + sts[ch]->hTcxEnc->fUseTns[k] = (sts[ch]->hTcxEnc->tnsData[k].nFilters > 0) ? 1 : 0; + + if (!bWhitenedDomain && maxPredGain < TNS_GAIN_THRESHOLD_FOR_WHITE && sts[ch]->hTcxEnc->transform_type[k] != TCX_5) + { + sts[ch]->hTcxEnc->fUseTns[k] = 0; + sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k] = 1; + sts[ch]->hTcxEnc->tnsData[k].nFilters = 0; + for (iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + { + ClearTnsFilterCoefficients(sts[ch]->hTcxEnc->tnsData[k].filter + iFilter); + sts[ch]->hTcxEnc->tnsData[k].filter[iFilter].filterType = TNS_FILTER_OFF; + } + } + maxPredictionGain = max(maxPredictionGain, maxPredGain); + } + } + } + + + /* we have the decision, set filter data accordingly */ + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + if (sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + { + continue; + } + + nSubframes = (sts[ch]->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + + for (k = 0; k < nSubframes; k++) + { + if (sts[ch]->hTcxCfg->fIsTNSAllowed && (!bWhitenedDomain || sts[ch]->hTcxEnc->bTnsOnWhithenedSpectra[k])) + { + sts[ch]->hTcxCfg->pCurrentTnsConfig = &sts[ch]->hTcxCfg->tnsConfig[sts[ch]->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (sts[ch]->last_core == ACELP_CORE)]; + + for (iFilter = sts[ch]->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + { + STnsFilter* pFilter; + pFilter = sts[ch]->hTcxEnc->tnsData[k].filter + iFilter; + switch (pFilter->filterType) + { + case TNS_FILTER_OFF: + ClearTnsFilterCoefficients(sts[ch]->hTcxEnc->tnsData[k].filter + iFilter); + break; + case TNS_FILTER_ON_ZERO: + /* Since TNS filter of order 0 is not allowed we have to signal in the stream filter of order 1 with the 0th coefficient equal to 0 */ + ClearTnsFilterCoefficients(pFilter); + pFilter->order = 1; + break; + } + } + } + } + } + + /* Apply filters, loop over channels */ + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + st = sts[ch]; + if (st->mct_chan_mode == MCT_CHAN_MODE_IGNORE) + { + continue; + } + + nSubframes = (st->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + + for (k = 0; k < nSubframes; k++) + { + if (bWhitenedDomain && (ch > 0) && /* test for identical TNS filter data in both channels */ + sts[0]->hTcxCfg->fIsTNSAllowed && sts[0]->hTcxEnc->fUseTns[k] && + sts[1]->hTcxCfg->fIsTNSAllowed && sts[1]->hTcxEnc->fUseTns[k]) + { + int16_t equalFilterData = (sts[0]->hTcxCfg->pCurrentTnsConfig->nMaxFilters == sts[1]->hTcxCfg->pCurrentTnsConfig->nMaxFilters && + sts[0]->hTcxEnc->bTnsOnWhithenedSpectra[k] == sts[1]->hTcxEnc->bTnsOnWhithenedSpectra[k] && + sts[0]->hTcxEnc->tnsData[k].nFilters == sts[1]->hTcxEnc->tnsData[k].nFilters) + ? 1 + : 0; + if (equalFilterData) + { + for (iFilter = st->hTcxCfg->pCurrentTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter--) + { + const int16_t* pDataCh0 = (const int16_t*)&sts[0]->hTcxEnc->tnsData[k].filter[iFilter]; + const int16_t* pDataCh1 = (const int16_t*)&sts[1]->hTcxEnc->tnsData[k].filter[iFilter]; + int16_t i = 2 + TNS_MAX_FILTER_ORDER; /* excl. informative float data. Portable? */ + + while ((i >= 0) && (pDataCh0[i] == pDataCh1[i])) + { + i--; + } + if (i >= 0) + { + equalFilterData = 0; + break; + } + } + if (equalFilterData) + { + st->hTcxEnc->tnsData[k].nFilters *= -1; /* signals common TNS */ + } + } + } + if (st->hTcxCfg->fIsTNSAllowed && (!bWhitenedDomain || st->hTcxEnc->bTnsOnWhithenedSpectra[k])) + { + L_spec = st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; + spectrum = st->hTcxEnc->spectrum[k]; + /* If TNS should be used then get the residual after applying it inplace in the spectrum */ + if (st->hTcxEnc->fUseTns[k]) + { + st->hTcxCfg->pCurrentTnsConfig = &st->hTcxCfg->tnsConfig[st->hTcxEnc->transform_type[k] == TCX_20][(k == 0) && (st->last_core == ACELP_CORE)]; + + ApplyTnsFilter(st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], spectrum, 1); + } + + if (st->hTcxEnc->transform_type[k] == TCX_5) + { + tcx5TnsUngrouping(L_frame >> 2, L_spec >> 1, st->hTcxEnc->spectrum[k], ENC); + } + + st->hTcxEnc->tnsData[k].tnsOnWhitenedSpectra = st->hTcxEnc->bTnsOnWhithenedSpectra[k]; + + EncodeTnsData(st->hTcxCfg->pCurrentTnsConfig, &st->hTcxEnc->tnsData[k], param_core[ch] + k * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, tnsSize[ch] + k, tnsBits[ch] + k); + } + + if (st->hTcxEnc->transform_type[k] == TCX_5) + { + tcx5SpectrumInterleaving(st->hTcxCfg->tcx5SizeFB, st->hTcxEnc->spectrum[k]); + tcx5SpectrumInterleaving(st->hTcxCfg->tcx5SizeFB, mdst_spectrum[ch][k]); + } + } + } + + return; +} + + +#endif void TNSAnalysis( - TCX_config *tcx_cfg, /* input: configuration of TCX */ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 L_frame, /* input: frame length */ Word16 L_spec, Word16 tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ @@ -148,11 +628,11 @@ void TNSAnalysis( *pfUseTns = 0; move16(); - IF (tcx_cfg->fIsTNSAllowed != 0) + IF (hTcxCfg->fIsTNSAllowed != 0) { - tcx_cfg->pCurrentTnsConfig = &tcx_cfg->tnsConfig[sub(tcxMode, TCX_20) == 0][isAfterACELP]; + hTcxCfg->pCurrentTnsConfig = &hTcxCfg->tnsConfig[sub(tcxMode, TCX_20) == 0][isAfterACELP]; test(); - L_spec = tcx_cfg->pCurrentTnsConfig->iFilterBorders[0]; + L_spec = hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; move16(); /*-----------------------------------------------------------* @@ -181,12 +661,12 @@ void TNSAnalysis( } move16(); - *pfUseTns = (Word8)DetectTnsFilt(tcx_cfg->pCurrentTnsConfig, spectrum, pTnsData, predictionGain); + *pfUseTns = (Word8)DetectTnsFilt(hTcxCfg->pCurrentTnsConfig, spectrum, pTnsData, predictionGain); /* If TNS should be used then get the residual after applying it inplace in spectrum */ IF (*pfUseTns != 0) { - ApplyTnsFilter(tcx_cfg->pCurrentTnsConfig, pTnsData, spectrum, 1); + ApplyTnsFilter(hTcxCfg->pCurrentTnsConfig, pTnsData, spectrum, 1); } IF (EQ_16(tcxMode, TCX_5)) @@ -212,7 +692,7 @@ void TNSAnalysis( } void ShapeSpectrum( - TCX_config *tcx_cfg,/*input: configuration of TCX*/ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ Word16 gainlpc[], /* output: MDCT gains for the previous frame */ Word16 gainlpc_e[], /* output: MDCT gains exponents */ @@ -230,7 +710,7 @@ void ShapeSpectrum( Word16 gainlpc_noinv_e[FDNS_NPTS]; Word16 i; Word32 max_low_pre = 0, max_high_pre = 0; - + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /*-----------------------------------------------------------* * Init * @@ -251,11 +731,11 @@ void ShapeSpectrum( IF (st->last_core_fx == ACELP_CORE) { - L_frame = add(L_frame, tcx_cfg->tcx_offset); - L_spec = add(L_spec, shr(tcx_cfg->tcx_coded_lines, 2)); - if(tcx_cfg->lfacNext<0) + L_frame = add(L_frame, hTcxCfg->tcx_offset); + L_spec = add(L_spec, shr(hTcxCfg->tcx_coded_lines, 2)); + if(hTcxCfg->lfacNext<0) { - L_frame = sub(L_frame,tcx_cfg->lfacNext); + L_frame = sub(L_frame,hTcxCfg->lfacNext); move16(); } } @@ -265,12 +745,12 @@ void ShapeSpectrum( M, L_frame, (GE_32(st->total_brate_fx, ACELP_13k20) && st->rf_mode == 0 ), - &st->noiseTiltFactor); + &hTcxEnc->noiseTiltFactor); /* Calculate Spectrum Flatness Measure for the TCX Concealment */ IF (st->enablePlcWaveadjust) { - tcx_cfg->SFM2 = SFM_Cal(spectrum, s_min(200, L_frame)); + hTcxCfg->SFM2 = SFM_Cal(spectrum, s_min(200, L_frame)); } test(); @@ -310,7 +790,7 @@ void ShapeSpectrum( weight_a_fx( A, Ap, gamma1, M ); - lpc2mdct( Ap, M, gainlpc_noinv, gainlpc_noinv_e, gainlpc, gainlpc_e ); + lpc2mdct( Ap, M, gainlpc_noinv, gainlpc_noinv_e, gainlpc, gainlpc_e, FDNS_NPTS, 0); mdct_shaping( spectrum, L_frame, gainlpc_noinv, gainlpc_noinv_e ); FOR (i = L_frame; i < L_spec; i++) @@ -336,7 +816,7 @@ void ShapeSpectrum( /* max_fac = 3 */ max_fac_s = 2; move16(); - if( st->tcx_lpc_shaped_ari ) + if(hTcxEnc->tcx_lpc_shaped_ari ) { /* max_fac = 1.5 */ max_fac_s = 1; @@ -437,16 +917,162 @@ void ShapeSpectrum( test(); test(); test(); - IF( st->tcxonly && st->tcxltp && (st->tcxltp_gain > 0) && !pfUseTns ) + IF( st->tcxonly && hTcxEnc->tcxltp && (hTcxEnc->tcxltp_gain > 0) && !pfUseTns ) { PsychAdaptLowFreqEmph(spectrum, gainlpc, gainlpc_e); } } +#ifdef ADD_IVAS_TNS +/*-----------------------------------------------------------* + * EstimateStereoTCXNoiseLevel() + * + * Estimate and quantize stereo noise factors + *-----------------------------------------------------------*/ + +void EstimateStereoTCXNoiseLevel( + Encoder_State** sts, /* i : state handle */ + float* q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ + float gain_tcx[][NB_DIV], /* i : global gain */ + int16_t L_frame[][NB_DIV], /* i : frame length */ + int16_t noiseFillingBorder[][NB_DIV], /* i : noise filling border */ + int16_t hm_active[][NB_DIV], /* i : flag indicating if the harmonic model is active */ + const int16_t ignore_chan[], /* i : flag indicating whether the channel should be ignored */ + float fac_ns[][NB_DIV], /* o : noise filling level */ + int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +) +{ + int16_t ch, n; + int16_t nSubframes, maxNfCalcBw, iStart, noiseTransWidth; + float smooth_gain; + float combined_q_spectrum[N_MAX]; + int16_t* fac_ns_q; + int32_t total_brate; + + for (ch = 0; ch < CPE_CHANNELS; ch++) + { + Encoder_State* st = sts[ch]; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + + nSubframes = (st->hTcxEnc->tcxMode == TCX_20) ? 1 : NB_DIV; + + if (ignore_chan[ch]) + { + continue; + } + total_brate = (st->element_mode == IVAS_CPE_MDCT && !MCT_flag) ? st->element_brate : st->total_brate; + + for (n = 0; n < nSubframes; n++) + { + fac_ns_q = param_core[ch] + n * NPRM_DIV + 1; + maxNfCalcBw = min(noiseFillingBorder[ch][n], (int16_t)(hTcxEnc->measuredBwRatio * (float)L_frame[ch][n] + 0.5f)); + if ((total_brate >= HQ_96k && (st->element_mode <= IVAS_SCE || st->bwidth < SWB)) || total_brate > IVAS_192k) + { + fac_ns[ch][n] = 0.0f; + *fac_ns_q = 0; + } + else + { + iStart = L_frame[ch][n] / ((total_brate >= ACELP_13k20 && !st->rf_mode) ? 6 : 8); /* noise filling start bin*/ + + if (n == 0) + { + mvr2r(hTcxEnc->ltpGainMemory, &hTcxEnc->ltpGainMemory[1], N_LTP_GAIN_MEMS - 1); + hTcxEnc->ltpGainMemory[0] = st->hTcxEnc->tcxltp_gain; + } + + smooth_gain = dotp(hTcxEnc->ltpGainMemory, nf_tw_smoothing_coeffs, N_LTP_GAIN_MEMS); + + noiseTransWidth = GetTransWidth(st->tcxonly, (L_frame[ch][n] == st->L_frame >> 1), smooth_gain, (st->hTcxCfg->ctx_hm && st->last_core != ACELP_CORE && hm_active[ch][n])); + + mvr2r(q_spectrum[ch][n], combined_q_spectrum, L_frame[ch][n]); + tcx_noise_factor(hTcxEnc->spectrum[n], combined_q_spectrum, iStart, maxNfCalcBw, noiseTransWidth, L_frame[ch][n], gain_tcx[ch][n], hTcxEnc->noiseTiltFactor, &fac_ns[ch][n], fac_ns_q, st->element_mode); + + /* hysteresis for very tonal passages (more stationary noise filling level) */ + if (*fac_ns_q == 1) + { + hTcxEnc->noiseLevelMemory_cnt = (int16_t)min(INT16_MAX, 1 + abs(hTcxEnc->noiseLevelMemory_cnt)); /* update counter */ + } + else + { + if ((*fac_ns_q == 2) && (abs(hTcxEnc->noiseLevelMemory_cnt) > 5)) + { + *fac_ns_q = 1; /* reduce noise filling level by one step */ + fac_ns[ch][n] = 0.75f / (1 << NBITS_NOISE_FILL_LEVEL); + + /* signal that noise level is changed by inverting sign of level memory */ + hTcxEnc->noiseLevelMemory_cnt = (hTcxEnc->noiseLevelMemory_cnt < 0) ? 5 : -1 - hTcxEnc->noiseLevelMemory_cnt; + } + else + { + hTcxEnc->noiseLevelMemory_cnt = 0; /* reset memory since level is too different */ + } + } + } /* bitrate */ + } +#ifdef DEBUG_MODE_MDCT + dbgwrite(&smooth_gain, sizeof(float), 1, 1, "./res/smooth_gain"); + dbgwrite(&st->hTcxEnc->tcxltp_gain, sizeof(float), 1, 1, "./res/tcxltp_gain"); + dbgwrite(&noiseTransWidth, sizeof(int16_t), 1, 1, "./res/noiseTrans"); + dbgwrite(&fac_ns[ch][0], sizeof(float), 2, 1, "./res/fac_ns"); +#endif + } + + return; +} + +/*-----------------------------------------------------------* + * DecideTonalSideInfo() + * + * + *-----------------------------------------------------------*/ + +static int16_t DecideTonalSideInfo( + const float spectrum[], + const int16_t L_frame_glob, + float SFM2) +{ + float SFM, K, K2; + int16_t Tonal_SideInfo; + + SFM = SFM_Cal(spectrum, min(200, L_frame_glob)); + + if (L_frame_glob <= 256) + { + K = 0.4f; + K2 = 0.1f; + } + else if (L_frame_glob == 320 || L_frame_glob == 512) + { + K = 0.4f; + K2 = 0.1f; + } + else /*FrameSize_Core == 640*/ + { + K = 0.35f; + K2 = 0.04f; + } + + + Tonal_SideInfo = 0; + if (SFM < K) + { + Tonal_SideInfo = 1; + } + + if (SFM2 < K2) + { + Tonal_SideInfo = 1; + } + + return Tonal_SideInfo; +} +#endif void QuantizeSpectrum( - TCX_config *tcx_cfg, /*input: configuration of TCX*/ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ Word16 gainlpc[], /* input: MDCT gains of the previous frame */ @@ -462,7 +1088,6 @@ void QuantizeSpectrum( STnsData * pTnsData, /* input: Tns data */ Word8 fUseTns, /* input: Flag indicating if TNS is used */ Word16 tnsSize, /* input: number of tns parameters put into prm */ - LPD_state *LPDmem, /*i/o: memories*/ Word16 prm[], /* output: tcx parameters */ Word16 frame_cnt, /* input: frame counter in the super_frame */ Encoder_State_fx *st, @@ -498,7 +1123,7 @@ void QuantizeSpectrum( Word16 aldo; /* ALDO flag in current frame*/ Word16 nz; /* non-zero length in ALDO window*/ CONTEXT_HM_CONFIG * phm_cfg; - + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Stack memory is split between encoder and internal decoder to reduce max stack memory usage. */ @@ -540,14 +1165,14 @@ void QuantizeSpectrum( move16(); L_frameTCX = L_frameTCX_glob; move16(); - overlap = tcx_cfg->tcx_mdct_window_length; + overlap = hTcxCfg->tcx_mdct_window_length; move16(); aldo = 0; move16(); nz = NS2SA_fx2(st->sr_core, N_ZERO_MDCT_NS); move16(); /* Modified the overlap to the delay in case of short blocks*/ - tcx_offset = tcx_cfg->tcx_offset; + tcx_offset = hTcxCfg->tcx_offset; move16(); OriginalSpectrum = NULL; @@ -575,22 +1200,22 @@ void QuantizeSpectrum( IF (st->last_core_fx == ACELP_CORE) { - tcx_cfg->last_aldo = 0; + hTcxCfg->last_aldo = 0; move16(); L_frame = add(L_frame, tcx_offset); - L_frameTCX = add(L_frameTCX, tcx_cfg->tcx_offsetFB); - L_spec = add(L_spec, shr(tcx_cfg->tcx_coded_lines, 2)); + L_frameTCX = add(L_frameTCX, hTcxCfg->tcx_offsetFB); + L_spec = add(L_spec, shr(hTcxCfg->tcx_coded_lines, 2)); tcx_offset = 0; move16(); - IF(tcx_cfg->lfacNext<0) + IF(hTcxCfg->lfacNext<0) { - L_frame = sub(L_frame,tcx_cfg->lfacNext); - L_frameTCX = sub(L_frameTCX, tcx_cfg->lfacNextFB); - tcx_offset = tcx_cfg->lfacNext; + L_frame = sub(L_frame,hTcxCfg->lfacNext); + L_frameTCX = sub(L_frameTCX, hTcxCfg->lfacNextFB); + tcx_offset = hTcxCfg->lfacNext; move16(); } - st->noiseLevelMemory = 0; + hTcxEnc->noiseLevelMemory = 0; move16(); } @@ -641,7 +1266,7 @@ void QuantizeSpectrum( move16(); } - if ( LT_32(tcx_cfg->SFM2, K2)) + if ( LT_32(hTcxCfg->SFM2, K2)) { st->Tonal_SideInfo = 1; move16(); @@ -661,16 +1286,16 @@ void QuantizeSpectrum( move16(); IF (st->igf != 0) { - noiseFillingSize = st->hIGFEnc.infoStartLine; + noiseFillingSize = st->hIGFEnc->infoStartLine; move16(); } ELSE { - st->hIGFEnc.infoStopLine = noiseFillingSize; + st->hIGFEnc->infoStopLine = noiseFillingSize; move16(); } - FOR (i=st->hIGFEnc.infoStopLine; ihIGFEnc->infoStopLine; itcx_lpc_shaped_ari == 0) /* old arithmetic coder */ + IF (hTcxEnc->tcx_lpc_shaped_ari == 0) /* old arithmetic coder */ { /* Fast estimation of the scalar quantizer step size */ test(); - IF ((tcx_cfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE)) + IF ((hTcxCfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE)) { LtpPitchLag = -1; move16(); test(); - IF ((tcxonly == 0) && (LT_16(st->tcxltp_pitch_int, st->L_frame_fx))) + IF ((tcxonly == 0) && (LT_16(hTcxEnc->tcxltp_pitch_int, st->L_frame_fx))) { tmp32 = L_shl(L_mult0(st->L_frame_fx, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - tmp1 = add(imult1616(st->tcxltp_pitch_int, st->pit_res_max), st->tcxltp_pitch_fr); + tmp1 = add(imult1616(hTcxEnc->tcxltp_pitch_int, st->pit_res_max), hTcxEnc->tcxltp_pitch_fr); LtpPitchLag = div_l(tmp32, tmp1); } @@ -706,9 +1331,9 @@ void QuantizeSpectrum( tmp1 = -1; move16(); - if (st->tcxltp != 0) + if (hTcxEnc->tcxltp != 0) { - tmp1 = st->tcxltp_gain; + tmp1 = hTcxEnc->tcxltp_gain; move16(); } PeriodicityIndex = SearchPeriodicityIndex( @@ -743,7 +1368,7 @@ void QuantizeSpectrum( /* Quantize original spectrum */ sqGain = SQ_gain(OriginalSpectrum, OriginalSpectrum_e, - shl(mult(LPDmem->tcx_target_bits_fac, sqTargetBits), 1), + shl(mult(hTcxEnc->tcx_target_bits_fac, sqTargetBits), 1), L_spec, &sqGain_e); @@ -751,8 +1376,8 @@ void QuantizeSpectrum( sqQ, L_spec, sqGain, sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, tcxonly); /* Estimate original bitrate */ @@ -836,7 +1461,7 @@ void QuantizeSpectrum( move16(); sqGain = SQ_gain(spectrum, *spectrum_e, - shl(mult(LPDmem->tcx_target_bits_fac, sqTargetBits), 1), + shl(mult(hTcxEnc->tcx_target_bits_fac, sqTargetBits), 1), L_spec, &sqGain_e); @@ -846,8 +1471,8 @@ void QuantizeSpectrum( sqQ, L_spec, sqGain, sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, tcxonly ); @@ -883,17 +1508,17 @@ void QuantizeSpectrum( tmp1 = BASOP_Util_Divide1616_Scale(sqTargetBits, tmp1, &tmp2); BASOP_SATURATE_WARNING_OFF - LPDmem->tcx_target_bits_fac = shl(mult(LPDmem->tcx_target_bits_fac, tmp1), tmp2); + hTcxEnc->tcx_target_bits_fac = shl(mult(hTcxEnc->tcx_target_bits_fac, tmp1), tmp2); BASOP_SATURATE_WARNING_ON - if (GT_16(LPDmem->tcx_target_bits_fac, 0x5000)) + if (GT_16(hTcxEnc->tcx_target_bits_fac, 0x5000)) { - LPDmem->tcx_target_bits_fac = 0x5000; + hTcxEnc->tcx_target_bits_fac = 0x5000; move16(); } - if (LT_16(LPDmem->tcx_target_bits_fac, 0x3000)) + if (LT_16(hTcxEnc->tcx_target_bits_fac, 0x3000)) { - LPDmem->tcx_target_bits_fac = 0x3000; + hTcxEnc->tcx_target_bits_fac = 0x3000; move16(); } @@ -909,15 +1534,15 @@ void QuantizeSpectrum( sqQ, L_spec, &sqGain, &sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, - tcx_cfg->tcxRateLoopOpt, + hTcxCfg->tcxRateLoopOpt, tcxonly, phm_cfg ); @@ -1035,8 +1660,8 @@ void QuantizeSpectrum( sqQ, L_spec, sqGain, sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, tcxonly ); @@ -1086,7 +1711,7 @@ void QuantizeSpectrum( AdaptLowFreqEmph(spectrum, *spectrum_e, NULL, 0, 0, - st->tcx_lpc_shaped_ari, + hTcxEnc->tcx_lpc_shaped_ari, gainlpc, gainlpc_e, L_frame ); @@ -1101,10 +1726,10 @@ void QuantizeSpectrum( LtpPitchLag = -1; move16(); - IF (LT_16(st->tcxltp_pitch_int, st->L_frame_fx)) + IF (LT_16(hTcxEnc->tcxltp_pitch_int, st->L_frame_fx)) { tmp32 = L_shl(L_mult0(st->L_frame_fx, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - tmp1 = add(imult1616(st->tcxltp_pitch_int, st->pit_res_max), st->tcxltp_pitch_fr); + tmp1 = add(imult1616(hTcxEnc->tcxltp_pitch_int, st->pit_res_max), hTcxEnc->tcxltp_pitch_fr); LtpPitchLag = div_l(tmp32, tmp1); } @@ -1150,7 +1775,7 @@ void QuantizeSpectrum( { AdaptLowFreqDeemph(spectrum, *spectrum_e, - st->tcx_lpc_shaped_ari, + hTcxEnc->tcx_lpc_shaped_ari, gainlpc, gainlpc_e, L_frame, xn_buf16 /* LF deemphasis factors */ @@ -1191,12 +1816,12 @@ void QuantizeSpectrum( * Residual Quantization * *-----------------------------------------------------------*/ - IF (tcx_cfg->resq) + IF (hTcxCfg->resq) { resQTargetBits = sub(sqTargetBits, sqBits); - IF (st->tcx_lpc_shaped_ari) /* new arithmetic coder */ + IF (hTcxEnc->tcx_lpc_shaped_ari) /* new arithmetic coder */ { Word16 *prm_resq; @@ -1206,7 +1831,7 @@ void QuantizeSpectrum( prm_resq, resQTargetBits, resQBits, - tcx_cfg->sq_rounding, + hTcxCfg->sq_rounding, xn_buf16 /* LF deemphasis factors */ ); /* Transmit zeros when there bits remain after RESQ */ @@ -1234,7 +1859,7 @@ void QuantizeSpectrum( &sqQ[L_spec], resQTargetBits, resQBits, - tcx_cfg->sq_rounding, + hTcxCfg->sq_rounding, tmpP16 /* LF deemphasis factors */ ); } @@ -1250,7 +1875,7 @@ void QuantizeSpectrum( { test(); test(); - IF (st->tcxltp != 0 && (st->tcxltp_gain > 0) && fUseTns == 0) + IF (hTcxEnc->tcxltp != 0 && (hTcxEnc->tcxltp_gain > 0) && fUseTns == 0) { PsychAdaptLowFreqDeemph(spectrum, gainlpc, gainlpc_e, NULL); @@ -1262,7 +1887,7 @@ void QuantizeSpectrum( *-----------------------------------------------------------*/ { - maxNfCalcBw = s_min(noiseFillingSize, round_fx(L_shl(L_mult(st->measuredBwRatio, L_frame), 1))); + maxNfCalcBw = s_min(noiseFillingSize, round_fx(L_shl(L_mult(hTcxEnc->measuredBwRatio, L_frame), 1))); /*-----------------------------------------------------------* * Estimate and quantize noise factor * @@ -1290,12 +1915,12 @@ void QuantizeSpectrum( move16(); test(); test(); - if ((tcx_cfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE) && (prm_hm[0] != 0)) + if ((hTcxCfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE) && (prm_hm[0] != 0)) { tmp1 = 10240/*0.3125f Q15*/; move16(); } - noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(st->tcxltp_gain, tmp1)); + noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(hTcxEnc->tcxltp_gain, tmp1)); if (EQ_16(L_frame, shr(st->L_frame_fx, 1))) { @@ -1312,19 +1937,19 @@ void QuantizeSpectrum( noiseTransWidth, L_frame, gain_tcx, gain_tcx_e, - st->noiseTiltFactor, + hTcxEnc->noiseTiltFactor, &fac_ns, &prm[NOISE_FILL_RANGES] ); /* hysteresis for very tonal passages (more stationary noise filling level) */ IF (EQ_16(prm[NOISE_FILL_RANGES], 1)) { - st->noiseLevelMemory = add(1, abs_s(st->noiseLevelMemory)); /* update counter */ + hTcxEnc->noiseLevelMemory = add(1, abs_s(hTcxEnc->noiseLevelMemory)); /* update counter */ } ELSE { test(); IF ((EQ_16(prm[NOISE_FILL_RANGES], 2))&& - (GT_16(abs_s(st->noiseLevelMemory), 5))) + (GT_16(abs_s(hTcxEnc->noiseLevelMemory), 5))) { /* reduce noise filling level by one step */ prm[NOISE_FILL_RANGES] = 1; @@ -1334,15 +1959,15 @@ void QuantizeSpectrum( /* signal that noise level is changed by inverting sign of level memory */ tmp1 = 5; move16(); - if (st->noiseLevelMemory >= 0) + if (hTcxEnc->noiseLevelMemory >= 0) { - tmp1 = sub(-1, st->noiseLevelMemory); + tmp1 = sub(-1, hTcxEnc->noiseLevelMemory); } - st->noiseLevelMemory = tmp1; + hTcxEnc->noiseLevelMemory = tmp1; } ELSE { /* reset memory since level is too different */ - st->noiseLevelMemory = 0; + hTcxEnc->noiseLevelMemory = 0; move16(); } } @@ -1392,18 +2017,9 @@ void QuantizeSpectrum( M, L_frame, tmp1, - &st->noiseTiltFactor); - - tcx_noise_filling(spectrum, *spectrum_e, - nf_seed /* seed */, - i, - noiseFillingSize, - noiseTransWidth, - L_frame, - st->noiseTiltFactor, - fac_ns, - NULL - ); + &hTcxEnc->noiseTiltFactor); + + tcx_noise_filling(spectrum, *spectrum_e,nf_seed /* seed */, i, noiseFillingSize, noiseTransWidth, L_frame, hTcxEnc->noiseTiltFactor, fac_ns, NULL, st->element_mode ); } IF (LT_32(st->total_brate_fx, ACELP_13k20)||st->rf_mode!=0) @@ -1440,9 +2056,9 @@ void QuantizeSpectrum( /*-----------------------------------------------------------* * Apply gain * *-----------------------------------------------------------*/ - IF (EQ_16(st->tcx_cfg.coder_type, INACTIVE)) + IF (EQ_16(st->hTcxCfg->coder_type, INACTIVE)) { - gain_tcx = mult_r(gain_tcx, tcx_cfg->na_scale); + gain_tcx = mult_r(gain_tcx, hTcxCfg->na_scale); } FOR (i = 0; i < L_spec; i++) @@ -1453,7 +2069,7 @@ void QuantizeSpectrum( *spectrum_e = add(*spectrum_e, gain_tcx_e); move16(); - stop = tcx_cfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); + stop = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); test(); IF ((EQ_16(L_frame, shr(st->L_frame_fx, 1)))&&(tcxonly!=0)) @@ -1463,13 +2079,13 @@ void QuantizeSpectrum( test(); test(); - if (((tcx_cfg->fIsTNSAllowed != 0) && (fUseTns != 0)) || (GT_16(L_spec, L_frame))) + if (((hTcxCfg->fIsTNSAllowed != 0) && (fUseTns != 0)) || (GT_16(L_spec, L_frame))) { L = L_spec; move16(); } - tcxInvertWindowGrouping(tcx_cfg, + tcxInvertWindowGrouping(hTcxCfg, xn_buf32, spectrum, L, @@ -1484,17 +2100,17 @@ void QuantizeSpectrum( * Temporal Noise Shaping Synthesis * *-----------------------------------------------------------*/ - IF (tcx_cfg->fIsTNSAllowed != 0) + IF (hTcxCfg->fIsTNSAllowed != 0) { test(); test(); test(); - SetTnsConfig(tcx_cfg, sub(L_frame_glob, st->L_frame_fx) == 0, (st->last_core_fx == ACELP_CORE) && (frame_cnt == 0)); + SetTnsConfig(hTcxCfg, sub(L_frame_glob, st->L_frame_fx) == 0, (st->last_core_fx == ACELP_CORE) && (frame_cnt == 0)); /* Apply TNS to get the reconstructed signal */ IF (fUseTns != 0) { - ApplyTnsFilter(tcx_cfg->pCurrentTnsConfig, pTnsData, spectrum, 0); + ApplyTnsFilter(hTcxCfg->pCurrentTnsConfig, pTnsData, spectrum, 0); test(); IF ((EQ_16(L_frame, shr(st->L_frame_fx, 1)))&&(tcxonly!=0)) @@ -1502,8 +2118,8 @@ void QuantizeSpectrum( test(); test(); test(); - IF ( (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (stop == 0)) ) + IF ( (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) || + ((hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (stop == 0)) ) { tmp1 = shr(L_spec, 1); /* undo rearrangement of LF sub-window lines for TNS synthesis filter */ @@ -1532,7 +2148,7 @@ void QuantizeSpectrum( test(); IF ((EQ_16(L_frame, shr(st->L_frame_fx, 1)))&&(tcxonly!=0)) { - IF (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) + IF (hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP) { Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; Word16 L_win, L_spec_TCX5, L_ola, w; @@ -1540,11 +2156,11 @@ void QuantizeSpectrum( /* minimum or half overlap, two transforms, grouping into one window */ L_win = shr(L_frame, 1); L_spec_TCX5 = shr(s_max(L_frame, L_spec), 1); - L_ola = tcx_cfg->tcx_mdct_window_half_length; + L_ola = hTcxCfg->tcx_mdct_window_half_length; move16(); - if ( EQ_16(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP)) + if ( EQ_16(hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP)) { - L_ola = tcx_cfg->tcx_mdct_window_min_length; + L_ola = hTcxCfg->tcx_mdct_window_min_length; move16(); } @@ -1554,20 +2170,18 @@ void QuantizeSpectrum( FOR (w = 0; w < 2; w++) { - IF (EQ_16(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP)) + IF (EQ_16(hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP)) { TCX_MDCT_Inverse(spectrum + L_mult0(w, L_spec_TCX5), sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola); + win, L_ola, sub(L_win, L_ola), L_ola, st->element_mode); } ELSE { - TCX_MDCT_Inverse(spectrum + L_mult0(w, L_spec_TCX5), sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola); + TCX_MDCT_Inverse(spectrum + L_mult0(w, L_spec_TCX5), sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), win, + L_ola, sub(L_win, L_ola), L_ola, st->element_mode); } - tmp1 = tcx_cfg->tcx_last_overlap_mode; + tmp1 = hTcxCfg->tcx_last_overlap_mode; move16(); test(); test(); @@ -1602,19 +2216,19 @@ void QuantizeSpectrum( } tcx_windowing_synthesis_current_frame(win, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, tmp2, tmp1, - LPDmem->acelp_zir, - st->LPDmem.Txnq, + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, NULL, Aq_old, - tcx_cfg->tcx_mdct_window_trans, + hTcxCfg->tcx_mdct_window_trans, L_win, tmp4, tmp3, @@ -1629,12 +2243,12 @@ void QuantizeSpectrum( IF (w > 0) { tcx_windowing_synthesis_past_frame(tmpP16, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, + hTcxCfg->tcx_aldo_window_1_trunc, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, 2 ); } @@ -1647,13 +2261,13 @@ void QuantizeSpectrum( /* copy new sub-window region not overlapping with previous window */ Copy(win + L_ola, xn_buf16 + add(tmp1, shr(L_ola, 1)), L_win); } - /* To assure that no garbage values are copied to LPDmem->Txnq */ + /* To assure that no garbage values are copied to hLPDmem->Txnq */ set16_fx(xn_buf16 + add(add(L_frame, tcx_offset), shr(L_ola, 1)), 0, sub(sub(overlap, tcx_offset), shr(L_ola, 1))); } - ELSE IF ( s_and(frame_cnt == 0, (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)) ) + ELSE IF ( s_and(frame_cnt == 0, (hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP)) ) { /* special overlap attempt, two transforms, grouping into one window */ Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; @@ -1661,17 +2275,16 @@ void QuantizeSpectrum( L_win = shr(L_frame, 1); L_spec_TCX5 = shr(s_max(L_frame, L_spec), 1); - L_ola = tcx_cfg->tcx_mdct_window_min_length; + L_ola = hTcxCfg->tcx_mdct_window_min_length; move16(); set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); /* Resize overlap (affect only asymmetric window)*/ - overlap = st->tcx_cfg.tcx_mdct_window_delay; + overlap = st->hTcxCfg->tcx_mdct_window_delay; /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win + L_win, - 0, sub(L_win, shr(L_ola, 1)), L_ola); + win + L_win, 0, sub(L_win, shr(L_ola, 1)), L_ola, st->element_mode); /* copy new sub-window region not overlapping with previous window */ Copy(win+L_win, xn_buf16+shr(overlap, 1), add(L_win, shr(L_ola, 1))); @@ -1679,8 +2292,7 @@ void QuantizeSpectrum( /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ TCX_MDCT_Inverse(spectrum + L_spec_TCX5, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola); + win, L_ola, sub(L_win, L_ola), L_ola, st->element_mode); tmp4 = 0; move16(); @@ -1689,19 +2301,19 @@ void QuantizeSpectrum( tmp4 = negate(tcx_offset); } tcx_windowing_synthesis_current_frame(win, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, 0, /* left_rect */ 2, /* left_mode */ - LPDmem->acelp_zir, - st->LPDmem.Txnq, + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, NULL, Aq_old, - tcx_cfg->tcx_mdct_window_trans, + hTcxCfg->tcx_mdct_window_trans, L_win, tmp4, 1, /* not LPDmem->mode */ @@ -1714,12 +2326,12 @@ void QuantizeSpectrum( tmpP16 = xn_buf16 + add(sub(L_win, shr(L_ola, 1)), shr(overlap,1)); tcx_windowing_synthesis_past_frame(tmpP16, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, + hTcxCfg->tcx_aldo_window_1_trunc, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, 2 ); @@ -1749,19 +2361,19 @@ void QuantizeSpectrum( tmp4 = negate(tcx_offset); } tcx_windowing_synthesis_current_frame(xn_buf16, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, overlap, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, st->last_core_fx==ACELP_CORE, 0, - LPDmem->acelp_zir, - st->LPDmem.Txnq, + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, NULL, Aq_old, - tcx_cfg->tcx_mdct_window_trans, + hTcxCfg->tcx_mdct_window_trans, L_win, tmp4, st->last_core_fx, @@ -1773,8 +2385,7 @@ void QuantizeSpectrum( { TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf16, - overlap, sub(L_frame, overlap), overlap); + xn_buf16,overlap, sub(L_frame, overlap), overlap, st->element_mode); tmp1 = stop; move16(); @@ -1793,19 +2404,19 @@ void QuantizeSpectrum( tmp4 = negate(tcx_offset); } tcx_windowing_synthesis_current_frame(xn_buf16, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, /*tcx_cfg->tcx_mdct_window_length*/ - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + overlap, /*hTcxCfg->tcx_mdct_window_length*/ + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, st->last_core_fx==ACELP_CORE, tmp1, - LPDmem->acelp_zir, - st->LPDmem.Txnq, + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, NULL, Aq_old, - tcx_cfg->tcx_mdct_window_trans, + hTcxCfg->tcx_mdct_window_trans, shr(L_frame_glob, 1), tmp4, st->last_core_fx, @@ -1818,7 +2429,7 @@ void QuantizeSpectrum( } ELSE /* frame is TCX-20 or not TCX-only */ { - IF (NE_16(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP)) + IF (NE_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) { Word32 tmp_buf[L_FRAME_PLUS]; Word16 Q; @@ -1844,11 +2455,11 @@ void QuantizeSpectrum( window_ola_fx(tmp_buf, xn_buf16, &Q, - st->old_out_fx, - &st->Q_old_out, + hTcxEnc->old_out_fx, + &hTcxEnc->Q_old_out, L_frame, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, + hTcxCfg->tcx_last_overlap_mode, + hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL); @@ -1867,8 +2478,7 @@ void QuantizeSpectrum( { TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf16, - overlap, sub(L_frame, overlap), overlap); + xn_buf16, overlap, sub(L_frame, overlap), overlap, st->element_mode); /*-----------------------------------------------------------* * Windowing, overlap and add * @@ -1882,19 +2492,19 @@ void QuantizeSpectrum( tmp4 = negate(tcx_offset); } tcx_windowing_synthesis_current_frame(xn_buf16, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, /*tcx_cfg->tcx_mdct_window_length*/ - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_aldo_window_2, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, + overlap, /*hTcxCfg->tcx_mdct_window_length*/ + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, st->last_core_fx==ACELP_CORE, - tcx_cfg->tcx_last_overlap_mode, /*left mode*/ - LPDmem->acelp_zir, - st->LPDmem.Txnq, + hTcxCfg->tcx_last_overlap_mode, /*left mode*/ + hTcxEnc->acelp_zir, + hTcxEnc->Txnq, NULL, Aq_old, - tcx_cfg->tcx_mdct_window_trans, + hTcxCfg->tcx_mdct_window_trans, shr(L_frame_glob, 1), tmp4, st->last_core_fx, @@ -1908,31 +2518,31 @@ void QuantizeSpectrum( test(); test(); test(); - IF ((st->last_core_fx > ACELP_CORE) && (((EQ_16(L_frameTCX, shr(st->L_frameTCX, 1)))&&(st->tcxonly!=0))||(EQ_16(st->tcx_cfg.tcx_last_overlap_mode,TRANSITION_OVERLAP)))) + IF ((st->last_core_fx > ACELP_CORE) && (((EQ_16(L_frameTCX, shr(hTcxEnc->L_frameTCX, 1)))&&(st->tcxonly!=0))||(EQ_16(st->hTcxCfg->tcx_last_overlap_mode,TRANSITION_OVERLAP)))) { - IF (tcx_cfg->last_aldo != 0) + IF (hTcxCfg->last_aldo != 0) { - tmp2 = add(st->Q_old_out, TCX_IMDCT_HEADROOM); + tmp2 = add(hTcxEnc->Q_old_out, TCX_IMDCT_HEADROOM); - tmp1 = sub(overlap, tcx_cfg->tcx_mdct_window_min_length); + tmp1 = sub(overlap, hTcxCfg->tcx_mdct_window_min_length); FOR (i=0; i < tmp1; i++) { - xn_buf16[i] = shl(add(xn_buf16[i], shr(st->old_out_fx[i+nz], tmp2)), TCX_IMDCT_HEADROOM); + xn_buf16[i] = shl(add(xn_buf16[i], shr(hTcxEnc->old_out_fx[i+nz], tmp2)), TCX_IMDCT_HEADROOM); move16(); } /* fade truncated ALDO window */ - tmp1 = sub(overlap, shr(tcx_cfg->tcx_mdct_window_min_length, 1)); + tmp1 = sub(overlap, shr(hTcxCfg->tcx_mdct_window_min_length, 1)); FOR ( ; i < tmp1; i++) { - tmp3 = mult_r(shr(st->old_out_fx[i+nz], tmp2), tcx_cfg->tcx_mdct_window_minimum[i-overlap+tcx_cfg->tcx_mdct_window_min_length].v.re); + tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[i-overlap+hTcxCfg->tcx_mdct_window_min_length].v.re); xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); move16(); } FOR ( ; i < overlap; i++) { - tmp3 = mult_r(shr(st->old_out_fx[i+nz], tmp2), tcx_cfg->tcx_mdct_window_minimum[overlap-1-i].v.im); + tmp3 = mult_r(shr(hTcxEnc->old_out_fx[i+nz], tmp2), hTcxCfg->tcx_mdct_window_minimum[overlap-1-i].v.im); xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); move16(); } @@ -1948,7 +2558,7 @@ void QuantizeSpectrum( test(); test(); test(); - if ((frame_cnt > 0) && (stop == 0) && (tcx_cfg->tcx_curr_overlap_mode == 0) && (st->last_core_fx != ACELP_CORE)) + if ((frame_cnt > 0) && (stop == 0) && (hTcxCfg->tcx_curr_overlap_mode == 0) && (st->last_core_fx != ACELP_CORE)) { stop = 2; /* use minimum overlap between the two TCX-10 windows */ move16(); } @@ -1956,27 +2566,19 @@ void QuantizeSpectrum( tmp1 = stop; move16(); test(); - if ((stop == 0) || (EQ_16(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP))) + if ((stop == 0) || (EQ_16(hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP))) { - tmp1 = tcx_cfg->tcx_last_overlap_mode; + tmp1 = hTcxCfg->tcx_last_overlap_mode; move16(); } - tcx_windowing_synthesis_past_frame( LPDmem->Txnq - , - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - tmp1 - ); + tcx_windowing_synthesis_past_frame(hTcxEnc->Txnq,hTcxCfg->tcx_aldo_window_1_trunc,hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum,overlap,hTcxCfg->tcx_mdct_window_half_length,hTcxCfg->tcx_mdct_window_min_length,tmp1); BASOP_SATURATE_WARNING_OFF; FOR (i=0; iTxnq[i]), TCX_IMDCT_HEADROOM); + xn_buf16[i] = shl(add(xn_buf16[i], hTcxEnc->Txnq[i]), TCX_IMDCT_HEADROOM); move16(); } @@ -2009,50 +2611,50 @@ void QuantizeSpectrum( test(); test(); IF ( (aldo == 0) && - ((EQ_16(L_frameTCX, shr(st->L_frameTCX, 1)) && frame_cnt > 0) || - NE_16(L_frameTCX, shr(st->L_frameTCX, 1)) ) ) + ((EQ_16(L_frameTCX, shr(hTcxEnc->L_frameTCX, 1)) && frame_cnt > 0) || + NE_16(L_frameTCX, shr(hTcxEnc->L_frameTCX, 1)) ) ) { /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ FOR (i = 0; i < nz; i++) { - st->old_out_fx[i] = shr(xn_buf16[L_frame-nz+i], TCX_IMDCT_HEADROOM); + hTcxEnc->old_out_fx[i] = shr(xn_buf16[L_frame-nz+i], TCX_IMDCT_HEADROOM); move16(); } - Copy(xn_buf16+L_frame, st->old_out_fx+nz, overlap); - set16_fx(st->old_out_fx+nz+overlap, 0, nz); + Copy(xn_buf16+L_frame, hTcxEnc->old_out_fx+nz, overlap); + set16_fx(hTcxEnc->old_out_fx+nz+overlap, 0, nz); - tcx_windowing_synthesis_past_frame( st->old_out_fx+nz, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, + tcx_windowing_synthesis_past_frame(hTcxEnc->old_out_fx+nz, + hTcxCfg->tcx_aldo_window_1_trunc, + hTcxCfg->tcx_mdct_window_half, + hTcxCfg->tcx_mdct_window_minimum, overlap, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - tcx_cfg->tcx_curr_overlap_mode + hTcxCfg->tcx_mdct_window_half_length, + hTcxCfg->tcx_mdct_window_min_length, + hTcxCfg->tcx_curr_overlap_mode ); /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ - IF (EQ_16(tcx_cfg->tcx_curr_overlap_mode, FULL_OVERLAP)) + IF (EQ_16(hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP)) { FOR (i=0; iold_out_fx[nz+overlap+i] = shr(mult_r(xn_buf16[L_frame-1-i], tcx_cfg->tcx_aldo_window_1[nz-1-i]), TCX_IMDCT_HEADROOM); + hTcxEnc->old_out_fx[nz+overlap+i] = shr(mult_r(xn_buf16[L_frame-1-i], hTcxCfg->tcx_aldo_window_1[nz-1-i]), TCX_IMDCT_HEADROOM); move16(); } - tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; + hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); } - st->Q_old_out = -TCX_IMDCT_HEADROOM; + hTcxEnc->Q_old_out = -TCX_IMDCT_HEADROOM; move16(); } - tcx_cfg->last_aldo = aldo; + hTcxCfg->last_aldo = aldo; move16(); /* Update Txnq */ - IF (tcx_cfg->last_aldo == 0) + IF (hTcxCfg->last_aldo == 0) { - Copy(xn_buf16 + L_frame, LPDmem->Txnq, overlap); + Copy(xn_buf16 + L_frame, hTcxEnc->Txnq, overlap); } @@ -2073,7 +2675,7 @@ void QuantizeSpectrum( void coder_tcx( Word16 n, - TCX_config *tcx_cfg, /*input: configuration of TCX*/ + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ Word16 synth[], @@ -2084,7 +2686,6 @@ void coder_tcx( Word8 tcxonly, /*input: only TCX flag*/ Word32 spectrum[], /* i/o: MDCT spectrum */ Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - LPD_state *LPDmem, /*i/o: memories*/ Word16 prm[], /* output: tcx parameters */ Encoder_State_fx *st, CONTEXT_HM_CONFIG *hm_cfg @@ -2102,7 +2703,8 @@ void coder_tcx( Word16 winMDST[N_MAX+L_MDCT_OVLP_MAX]; Word16 *pWinMDST; Word16 left_overlap_mode, right_overlap_mode; - + LPD_state_HANDLE hLPDmem = st->hLPDmem; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; left_overlap = right_overlap = -1; move16(); @@ -2120,19 +2722,11 @@ void coder_tcx( /*-----------------------------------------------------------* * Windowing * *-----------------------------------------------------------*/ - IF (EQ_16(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP)) + IF (EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) { - WindowSignal(tcx_cfg, - tcx_cfg->tcx_offsetFB, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, - &left_overlap, &right_overlap, - st->speech_TCX, - &L_frame, - win - ,1 - ); + WindowSignal(hTcxCfg, hTcxCfg->tcx_offsetFB, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, &left_overlap, &right_overlap, + hTcxEnc->speech_TCX, &L_frame, win ,1, 1); /*-----------------------------------------------------------* * Compute MDCT * @@ -2140,7 +2734,7 @@ void coder_tcx( *spectrum_e = 16; move16(); - TCX_MDCT(win, spectrum, spectrum_e, left_overlap, sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap); + TCX_MDCT(win, spectrum, spectrum_e, left_overlap, sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap, st->element_mode); } ELSE { @@ -2150,23 +2744,16 @@ void coder_tcx( Q = 0; move16(); - wtda_fx(st->new_speech_TCX, - &Q, - tmp_buf, - NULL, - NULL, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, - L_frame); + wtda_fx(hTcxEnc->new_speech_TCX,&Q,tmp_buf,NULL,NULL,hTcxCfg->tcx_last_overlap_mode,hTcxCfg->tcx_curr_overlap_mode,L_frame); - left_overlap_mode = tcx_cfg->tcx_last_overlap_mode; + left_overlap_mode = hTcxCfg->tcx_last_overlap_mode; move16(); if (EQ_16(left_overlap_mode, ALDO_WINDOW)) { left_overlap_mode = FULL_OVERLAP; move16(); } - right_overlap_mode = tcx_cfg->tcx_curr_overlap_mode; + right_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); if (EQ_16(right_overlap_mode, ALDO_WINDOW)) { @@ -2174,9 +2761,7 @@ void coder_tcx( move16(); } - WindowSignal( tcx_cfg, tcx_cfg->tcx_offsetFB, - left_overlap_mode, right_overlap_mode, - &left_overlap, &right_overlap, st->speech_TCX, &L_frame, winMDST, 1 ); + WindowSignal( hTcxCfg, hTcxCfg->tcx_offsetFB, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, hTcxEnc->speech_TCX, &L_frame, winMDST, 1, 1 ); /* scale by NORM_MDCT_FACTOR / L */ tmp1 = mult_r(shl(L_frame, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ @@ -2215,7 +2800,7 @@ void coder_tcx( pWinMDST = winMDST; move16(); - if (EQ_16(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP)) + if (EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)) { pWinMDST = win; move16(); @@ -2223,52 +2808,52 @@ void coder_tcx( AnalyzePowerSpectrum(st, round_fx(L_shl(Mpy_32_16_1(L_mult0(L_frame,st->L_frame_fx)/*Q0*/, - getInvFrameLen(st->L_frameTCX)/*Q21*/)/*Q6*/,16-6)), + getInvFrameLen(hTcxEnc->L_frameTCX)/*Q21*/)/*Q6*/,16-6)), L_frame, left_overlap, right_overlap, spectrum, *spectrum_e, pWinMDST, powerSpec, &powerSpec_e); - IF (tcx_cfg->fIsTNSAllowed != 0) + IF (hTcxCfg->fIsTNSAllowed != 0) { test(); test(); - SetTnsConfig(tcx_cfg, sub(L_frame_glob, st->L_frame_fx) == 0, st->last_core_fx == 0); + SetTnsConfig(hTcxCfg, sub(L_frame_glob, st->L_frame_fx) == 0, st->last_core_fx == 0); - TNSAnalysis(tcx_cfg, L_frame, L_spec, TCX_20, st->last_core_fx == 0, spectrum, st->tnsData, st->fUseTns - , &st->hIGFEnc.tns_predictionGain + TNSAnalysis(hTcxCfg, L_frame, L_spec, TCX_20, st->last_core_fx == 0, spectrum, hTcxEnc->tnsData, hTcxEnc->fUseTns + , &st->hIGFEnc->tns_predictionGain ); } ELSE { - st->fUseTns[0] = st->fUseTns[1] = 0; + hTcxEnc->fUseTns[0] = hTcxEnc->fUseTns[1] = 0; move16(); move16(); } IF(st->igf) { - ProcessIGF(&st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, st->fUseTns[0], (st->last_core_fx == ACELP_CORE), 0); + ProcessIGF(st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, hTcxEnc->fUseTns[0], (st->last_core_fx == ACELP_CORE), 0); } - ShapeSpectrum(tcx_cfg, A, gainlpc, gainlpc_e, + ShapeSpectrum(hTcxCfg, A, gainlpc, gainlpc_e, L_frame_glob, L_spec, spectrum, - st->fUseTns[0], + hTcxEnc->fUseTns[0], st ); if(st->igf) { - nb_bits = sub(nb_bits, st->hIGFEnc.infoTotalBitsPerFrameWritten); + nb_bits = sub(nb_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten); } - IF (tcx_cfg->fIsTNSAllowed != 0) + IF (hTcxCfg->fIsTNSAllowed != 0) { - EncodeTnsData(tcx_cfg->pCurrentTnsConfig, st->tnsData, prm+1+NOISE_FILL_RANGES+LTPSIZE, &tnsSize, &tnsBits); + EncodeTnsData(hTcxCfg->pCurrentTnsConfig, hTcxEnc->tnsData, prm+1+NOISE_FILL_RANGES+LTPSIZE, &tnsSize, &tnsBits); } - QuantizeSpectrum(tcx_cfg, + QuantizeSpectrum(hTcxCfg, A, Aqind, gainlpc, gainlpc_e, @@ -2279,17 +2864,16 @@ void coder_tcx( sub(sub(nb_bits, tnsBits), ltpBits), tcxonly, spectrum, spectrum_e, - st->tnsData, - st->fUseTns[0], + hTcxEnc->tnsData, + hTcxEnc->fUseTns[0], tnsSize, - LPDmem, prm, n, st, hm_cfg ); - LPDmem->nbits = add(LPDmem->nbits, add(tnsBits, ltpBits)); + hLPDmem->nbits = add(hLPDmem->nbits, add(tnsBits, ltpBits)); } @@ -2300,16 +2884,16 @@ void coder_tcx( * *-------------------------------------------------------------------*/ -void coder_tcx_post(Encoder_State_fx *st, - LPD_state *LPDmem, - TCX_config *tcx_cfg, - Word16 *synth, - const Word16 *A, - const Word16 *Ai, - Word16 *wsig, - Word16 Q_new, - Word16 shift - ) +void coder_tcx_post( + Encoder_State_fx *st, + LPD_state *LPDmem, + TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 *synth, + const Word16 *A, + const Word16 *Ai, + Word16 *wsig, + Word16 Q_new, + Word16 shift +) { Word16 xn_buf[L_FRAME_MAX]; @@ -2322,7 +2906,7 @@ void coder_tcx_post(Encoder_State_fx *st, *-----------------------------------------------------------*/ /* Update LPDmem (Txnq,syn,syn_pe,old_exc,wsyn,Ai,Aq) */ - tcx_encoder_memory_update( wsig, xn_buf, st->L_frame_fx, Ai, A, tcx_cfg->preemph_fac, LPDmem, st, synth, Q_new, shift ); + tcx_encoder_memory_update( wsig, xn_buf, st->L_frame_fx, Ai, A, hTcxCfg->preemph_fac, LPDmem, st, synth, Q_new, shift ); return; } diff --git a/lib_enc/cod_uv.c b/lib_enc/cod_uv.c index bff71e0..bbf8411 100644 --- a/lib_enc/cod_uv.c +++ b/lib_enc/cod_uv.c @@ -2,12 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include -#include +#include +#include "options.h" #include #include "prot_fx.h" -#include "stl.h" /*-------------------------------------------------------------------* * gauss_L2: @@ -57,7 +55,7 @@ void gauss_L2( } /*Shape the gaussian excitation*/ - cb_shape_fx( 1, 0, 0, 1, 0, formant_enh_num, FORMANT_SHARPENING_G2, Aq, code, tilt_code, 0, 1 ); + cb_shape_fx( 1, 0, 0, 1, 0, formant_enh_num, FORMANT_SHARPENING_G2, Aq, code, tilt_code, 0, 1 , L_SUBFR); /*compute 0s memory weighted synthesis contribution and find gain*/ E_UTIL_f_convolve(code, h, y11, L_SUBFR); /* y11: Q8+shift */ diff --git a/lib_enc/comvad_decision.c b/lib_enc/comvad_decision.c index 4ea3bd9..8691603 100644 --- a/lib_enc/comvad_decision.c +++ b/lib_enc/comvad_decision.c @@ -3,34 +3,33 @@ ====================================================================================*/ -#include -#include - - +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" #include "rom_enc_fx.h" +/*-------------------------------------------------------------------* + * local function prototypes + *-------------------------------------------------------------------*/ /* only one is activated in below preprocessing*/ /*#define CLDFB_VAD*/ /* test on the CLDFB-VAD */ -static -Word16 comvad_hangover( Word32 lt_snr_org, /*(i)original long time SNR*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 l_snr, /*(i) long time frequency domain - SNR calculated by l_speech_snr and l_silence_snr*/ - Word32 snr_flux, /*(i) average tsnr*/ - Word16 bw_index, /*(i) band width index*/ - Word16 vad_flag, - Word16 pre_res_hang_num, /*(i) residual amount of previous hangover */ - Word16 continuous_speech_num2, /*(i) amount of continuous speech frames*/ - Word16 noisy_type /*(i) noisy type*/ - ) +static Word16 comvad_hangover( + const Word32 lt_snr_org, /* i : original long time SNR*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 l_snr, /* i : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ + const Word32 snr_flux, /* i : average tsnr*/ + const Word16 bw_index, /* i : band width index*/ + const Word16 vad_flag, + const Word16 pre_res_hang_num, /* i : residual amount of previous hangover */ + const Word16 continuous_speech_num2, /* i : amount of continuous speech frames*/ + const Word16 noisy_type /* i : noisy type*/ +) { Word32 l_snr_add; Word16 speech_flag; @@ -390,19 +389,20 @@ Word16 comvad_hangover( Word32 lt_snr_org, /*(i)original long time -Word16 comvad_decision( T_CldfbVadState *st, - Word32 l_snr, /*(i) long time frequency domain*/ - Word32 lt_snr_org, /*(i) original long time SNR*/ - Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ - Word32 snr_flux, /*(i) average tsnr of several frames*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word16 music_backgound_f, /*(i) background music flag*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 *cldfb_addition, /*o: adjust the harmonized hangover */ - Word16 vada_flag - ) +Word16 comvad_decision( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word32 l_snr, /* i : long time frequency domain*/ + const Word32 lt_snr_org, /* i : original long time SNR*/ + const Word32 lt_snr, /* i : long time SNR calculated by fg_energy and bg_energy*/ + const Word32 snr_flux, /* i : average tsnr of several frames*/ + const Word32 snr, /* i : frequency domain SNR */ + Word32 tsnr, /* i : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word16 music_backgound_f, /* i : background music flag*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + Word16 *cldfb_addition, /* o : adjust the harmonized hangover */ + const Word16 vada_flag +) { Word16 speech_flag; Word32 fg_energy; @@ -428,11 +428,11 @@ Word16 comvad_decision( T_CldfbVadState *st, noisy_type = UNKNOWN_NOISE; move16(); - speech_flag = st->speech_flag; + speech_flag = hVAD_CLDFB ->speech_flag; move16(); - fg_energy = st->fg_energy; + fg_energy = hVAD_CLDFB ->fg_energy; move32(); - bg_energy = st->bg_energy; + bg_energy = hVAD_CLDFB ->bg_energy; move32(); Qnorm_silence = 0; @@ -441,57 +441,50 @@ Word16 comvad_decision( T_CldfbVadState *st, move16(); test(); - IF(GT_32(st->lf_snr_smooth, LS_MIN_SILENCE_SNR[st->bw_index - CLDFBVAD_NB_ID] )&>_32(lt_snr_org,LT_MIN_SILENCE_SNR[st->bw_index-CLDFBVAD_NB_ID])) + IF(GT_32(hVAD_CLDFB ->lf_snr_smooth, LS_MIN_SILENCE_SNR[hVAD_CLDFB ->bw_index - CLDFBVAD_NB_ID] )&>_32(lt_snr_org,LT_MIN_SILENCE_SNR[hVAD_CLDFB ->bw_index-CLDFBVAD_NB_ID])) { noisy_type = SILENCE; move16(); } - tmp_snr = construct_snr_thresh( st->sp_center, - snr_flux, - lt_snr, - l_snr, - st->continuous_speech_num, - st->continuous_noise_num, - st->fg_energy_est_start, - st->bw_index); + tmp_snr = construct_snr_thresh( hVAD_CLDFB ->sp_center, snr_flux, lt_snr, l_snr, hVAD_CLDFB ->continuous_speech_num, + hVAD_CLDFB ->continuous_noise_num, hVAD_CLDFB ->fg_energy_est_start, hVAD_CLDFB ->bw_index); + + vad_flag = 0; + move16(); + if(GT_32(snr, tmp_snr)) { - vad_flag = 0; + vad_flag = 1; move16(); - if(GT_32(snr, tmp_snr)) - { - vad_flag = 1; - move16(); - } - - if(GT_32(tsnr, 67108862/* 4.0/2.0 Q25 */)) - { - vad_flag = 1; - move16(); - } } - IF(GT_16(st->frameloop, 25)) + if(GT_32(tsnr, 67108862/* 4.0/2.0 Q25 */)) + { + vad_flag = 1; + move16(); + } + + IF(GT_16(hVAD_CLDFB ->frameloop, 25)) { test(); - IF(EQ_16(vad_flag, 1)&&EQ_32(st->fg_energy_est_start,1)) + IF(EQ_16(vad_flag, 1)&&EQ_32(hVAD_CLDFB ->fg_energy_est_start,1)) { Word32 frame_energy_mult_fix32,bg_energy_mult_fix32; Word16 frame_energy_mult_Q,bg_energy_mult_Q; - IF(EQ_16(st->fg_energy_count, 512)) + IF(EQ_16(hVAD_CLDFB ->fg_energy_count, 512)) { fg_energy = MUL_F(fg_energy, 0x6000); - st->fg_energy_count = 384; + hVAD_CLDFB ->fg_energy_count = 384; move16(); } - frame_energy_mult_fix32 = MUL_F(frame_energy, st->bg_energy_count); + frame_energy_mult_fix32 = MUL_F(frame_energy, hVAD_CLDFB ->bg_energy_count); frame_energy_mult_Q = sub(frame_energy_Q, 15); bg_energy_mult_fix32 = MUL_F(bg_energy, 6); - bg_energy_mult_Q = sub(st->bg_energy_scale, 15); + bg_energy_mult_Q = sub(hVAD_CLDFB ->bg_energy_scale, 15); IF(GT_16(frame_energy_mult_Q, bg_energy_mult_Q)) { @@ -504,8 +497,8 @@ Word16 comvad_decision( T_CldfbVadState *st, IF(GT_32(frame_energy_mult_fix32, bg_energy_mult_fix32)) { - fg_energy = VAD_L_ADD(fg_energy, st->fg_energy_scale, frame_energy, frame_energy_Q, &st->fg_energy_scale); - st->fg_energy_count = add(st->fg_energy_count, 1); + fg_energy = VAD_L_ADD(fg_energy, hVAD_CLDFB ->fg_energy_scale, frame_energy, frame_energy_Q, &hVAD_CLDFB ->fg_energy_scale); + hVAD_CLDFB ->fg_energy_count = add(hVAD_CLDFB ->fg_energy_count, 1); move16(); } } @@ -519,17 +512,17 @@ Word16 comvad_decision( T_CldfbVadState *st, IF(EQ_16(vad_flag, 1)) { - IF (st->l_silence_snr == 0) + IF (hVAD_CLDFB ->l_silence_snr == 0) { snr_div_fix = 0; move16(); } ELSE { - Qnorm_silence=sub(norm_l(st->l_silence_snr), 1); - Qnorm_silence_count=norm_l(st->l_silence_snr_count); - l_silence_snr = L_shl(st->l_silence_snr,Qnorm_silence); - l_silence_snr_count = L_shl(st->l_silence_snr_count,Qnorm_silence_count); + Qnorm_silence=sub(norm_l(hVAD_CLDFB ->l_silence_snr), 1); + Qnorm_silence_count=norm_l(hVAD_CLDFB ->l_silence_snr_count); + l_silence_snr = L_shl(hVAD_CLDFB ->l_silence_snr,Qnorm_silence); + l_silence_snr_count = L_shl(hVAD_CLDFB ->l_silence_snr_count,Qnorm_silence_count); snr_div_fix = div_l(l_silence_snr,extract_h(l_silence_snr_count)); } snr_sub = L_sub(snr, 0x3000000); @@ -539,18 +532,18 @@ Word16 comvad_decision( T_CldfbVadState *st, IF(GT_32(snr_sub, snr_div_fix32)) { - IF(EQ_32(st->l_speech_snr_count, 512)) + IF(EQ_32(hVAD_CLDFB ->l_speech_snr_count, 512)) { - st->l_speech_snr = L_add(MUL_F(st->l_speech_snr, 0x6000), L_shr(snr, 9)); + hVAD_CLDFB ->l_speech_snr = L_add(MUL_F(hVAD_CLDFB ->l_speech_snr, 0x6000), L_shr(snr, 9)); move32(); - st->l_speech_snr_count = L_deposit_l(384+1); + hVAD_CLDFB ->l_speech_snr_count = L_deposit_l(384+1); move32(); } ELSE { - st->l_speech_snr = L_add(st->l_speech_snr, L_shr(snr, 9)); + hVAD_CLDFB ->l_speech_snr = L_add(hVAD_CLDFB ->l_speech_snr, L_shr(snr, 9)); move32(); - st->l_speech_snr_count = L_add(st->l_speech_snr_count, 1); + hVAD_CLDFB ->l_speech_snr_count = L_add(hVAD_CLDFB ->l_speech_snr_count, 1); move32(); } } @@ -558,7 +551,7 @@ Word16 comvad_decision( T_CldfbVadState *st, lt_snr_org_cmp = L_sub(lt_snr_org, 117440509/* 3.5 Q25 */); - IF(EQ_16(st->bw_index, CLDFBVAD_NB_ID)) + IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_NB_ID)) { Word32 lt_snr_add; @@ -572,7 +565,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if( (GT_32(snr_flux, 50331647/* 1.5 Q25 */))&&(GT_16(st->sp_center[3],1637/* 1.6 Q10 */))&&(lt_snr_org_cmp<0)) + if( (GT_32(snr_flux, 50331647/* 1.5 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],1637/* 1.6 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -580,7 +573,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if( (GT_32(snr_flux, 40265317/* 1.2 Q25 */))&&(GT_16(st->sp_center[3],1944/* 1.9 Q10 */))&&(lt_snr_org_cmp<0)) + if( (GT_32(snr_flux, 40265317/* 1.2 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],1944/* 1.9 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -588,13 +581,13 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if((GT_32(snr_flux, 33554431/* 1.0 Q25 */))&&(GT_16(st->sp_center[3],3274/* 3.2 Q10 */))&&(lt_snr_org_cmp<0)) + if((GT_32(snr_flux, 33554431/* 1.0 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],3274/* 3.2 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); } } - ELSE IF(EQ_16(st->bw_index, CLDFBVAD_WB_ID)) + ELSE IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_WB_ID)) { Word32 lt_snr_add; @@ -608,7 +601,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if((GT_32(snr_flux, 53687090/* 1.6 Q25 */))&&(GT_16(st->sp_center[3],2558/* 2.5 Q10 */))&&(lt_snr_org_cmp<0)) + if((GT_32(snr_flux, 53687090/* 1.6 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2558/* 2.5 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -616,7 +609,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if((GT_32(snr_flux, 40265317/* 1.2 Q25 */))&&(GT_16(st->sp_center[3],2864/* 2.8 Q10 */))&&(lt_snr_org_cmp<0)) + if((GT_32(snr_flux, 40265317/* 1.2 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2864/* 2.8 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -624,7 +617,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if((GT_32(snr_flux, 33554431/* 1.0 Q25 */))&&(GT_16(st->sp_center[3],4604/* 4.5 Q10 */))&&(lt_snr_org_cmp<0)) + if((GT_32(snr_flux, 33554431/* 1.0 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],4604/* 4.5 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -644,7 +637,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if((GT_32(snr_flux, 56371444/* 1.68 Q25 */))&&(GT_16(st->sp_center[3],2823/* 2.76 Q10 */))&&(lt_snr_org_cmp<0)) + if((GT_32(snr_flux, 56371444/* 1.68 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2823/* 2.76 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -652,7 +645,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if((GT_32(snr_flux, 41607494/* 1.24 Q25 */))&&(GT_16(st->sp_center[3],2987/* 2.92 Q10 */))&&(lt_snr_org_cmp<0)) + if((GT_32(snr_flux, 41607494/* 1.24 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],2987/* 2.92 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -660,7 +653,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); - if((GT_32(snr_flux, 36909874/* 1.10 Q25 */))&&(GT_16(st->sp_center[3],4706/* 4.6 Q10 */))&&(lt_snr_org_cmp<0)) + if((GT_32(snr_flux, 36909874/* 1.10 Q25 */))&&(GT_16(hVAD_CLDFB ->sp_center[3],4706/* 4.6 Q10 */))&&(lt_snr_org_cmp<0)) { vad_flag = 1; move16(); @@ -668,15 +661,15 @@ Word16 comvad_decision( T_CldfbVadState *st, } - IF(st->fg_energy_est_start==0) + IF(hVAD_CLDFB ->fg_energy_est_start==0) { tmpout = VAD_L_CMP(frame_energy, frame_energy_Q, 50, 0); test(); test(); - if(GT_16(st->ltd_stable_rate[0], 2621/* 0.08 Q15 */)&&EQ_16(vad_flag,1)&&(tmpout>0)) + if(GT_16(hVAD_CLDFB ->ltd_stable_rate[0], 2621/* 0.08 Q15 */)&&EQ_16(vad_flag,1)&&(tmpout>0)) { - st->fg_energy_est_start = L_deposit_l(1); + hVAD_CLDFB ->fg_energy_est_start = L_deposit_l(1); } } @@ -684,10 +677,10 @@ Word16 comvad_decision( T_CldfbVadState *st, snr, l_snr, snr_flux, - st->bw_index, + hVAD_CLDFB ->bw_index, vad_flag, speech_flag, - st->continuous_speech_num2, + hVAD_CLDFB ->continuous_speech_num2, noisy_type); @@ -701,7 +694,7 @@ Word16 comvad_decision( T_CldfbVadState *st, } vadb_flag = vad_flag; - IF(EQ_16(st->bw_index, CLDFBVAD_SWB_ID)) + IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_SWB_ID)) { test(); test(); @@ -713,13 +706,13 @@ Word16 comvad_decision( T_CldfbVadState *st, vad_flag = vada_flag; move16(); } - ELSE IF(LT_32(st->lf_snr_smooth,352321526/* 10.5 Q25 */)||NE_16(SILENCE,noisy_type)) + ELSE IF(LT_32(hVAD_CLDFB ->lf_snr_smooth,352321526/* 10.5 Q25 */)||NE_16(SILENCE,noisy_type)) { test(); test(); test(); IF(GT_32(snr_flux, 83886078/* 2.5 Q25 */) - || ( st->continuous_speech_num2 > 40 && GT_32(snr_flux, 67108862/* 2.0 Q25 */) ) + || ( hVAD_CLDFB ->continuous_speech_num2 > 40 && GT_32(snr_flux, 67108862/* 2.0 Q25 */) ) || music_backgound_f == 1) { vad_flag = s_or(vad_flag, vada_flag); @@ -731,7 +724,7 @@ Word16 comvad_decision( T_CldfbVadState *st, } } - ELSE IF(EQ_16(st->bw_index, CLDFBVAD_WB_ID)) + ELSE IF(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_WB_ID)) { test(); test(); @@ -743,13 +736,13 @@ Word16 comvad_decision( T_CldfbVadState *st, vad_flag = vada_flag; move16(); } - ELSE IF(LT_32(st->lf_snr_smooth,352321526/* 10.5 Q25 */)||NE_16(SILENCE,noisy_type)) + ELSE IF(LT_32(hVAD_CLDFB ->lf_snr_smooth,352321526/* 10.5 Q25 */)||NE_16(SILENCE,noisy_type)) { test(); test(); test(); IF(GT_32(snr_flux, 73819748/* 2.2 Q25 */) - || (st->continuous_speech_num2 > 40 && GT_32(snr_flux, 57042532/* 1.7 Q25 */) ) + || (hVAD_CLDFB ->continuous_speech_num2 > 40 && GT_32(snr_flux, 57042532/* 1.7 Q25 */) ) || music_backgound_f == 1) { vad_flag = s_or(vad_flag, vada_flag); @@ -767,7 +760,7 @@ Word16 comvad_decision( T_CldfbVadState *st, IF(EQ_16(SILENCE, noisy_type)) { test(); - IF(GT_32(st->lf_snr_smooth , 419430388/* 12.5 Q25 */) + IF(GT_32(hVAD_CLDFB ->lf_snr_smooth , 419430388/* 12.5 Q25 */) && music_backgound_f == 0) { vad_flag = vada_flag; @@ -779,7 +772,7 @@ Word16 comvad_decision( T_CldfbVadState *st, test(); test(); IF(GT_32(snr_flux, 67108862/* 2.0 Q25 */) - || (st->continuous_speech_num2 > 30 && GT_32(snr_flux, 50331647/* 1.5 Q25 */) ) + || (hVAD_CLDFB ->continuous_speech_num2 > 30 && GT_32(snr_flux, 50331647/* 1.5 Q25 */) ) || music_backgound_f == 1) { vad_flag = s_or(vad_flag, vada_flag); @@ -789,49 +782,49 @@ Word16 comvad_decision( T_CldfbVadState *st, IF(vad_flag == 0) { - IF(EQ_32(st->l_silence_snr_count, 512)) + IF(EQ_32(hVAD_CLDFB ->l_silence_snr_count, 512)) { - st->l_silence_snr = L_add(MUL_F(st->l_silence_snr, 0x6000),L_shr(snr, 9)); + hVAD_CLDFB ->l_silence_snr = L_add(MUL_F(hVAD_CLDFB ->l_silence_snr, 0x6000),L_shr(snr, 9)); move32(); - st->l_silence_snr_count = L_deposit_l(384+1); + hVAD_CLDFB ->l_silence_snr_count = L_deposit_l(384+1); move32(); } ELSE IF(LT_32(snr, 26843545/* 0.8 Q25 */)) { - st->l_silence_snr = L_add(st->l_silence_snr, L_shr(snr,9)); + hVAD_CLDFB ->l_silence_snr = L_add(hVAD_CLDFB ->l_silence_snr, L_shr(snr,9)); move32(); - st->l_silence_snr_count = L_add(st->l_silence_snr_count, 1); + hVAD_CLDFB ->l_silence_snr_count = L_add(hVAD_CLDFB ->l_silence_snr_count, 1); move32(); } } IF(vad_flag == 0) { - IF(EQ_16(st->bg_energy_count, 512)) + IF(EQ_16(hVAD_CLDFB ->bg_energy_count, 512)) { bg_energy = MUL_F(bg_energy, 0x6000); - st->bg_energy_count = 384; + hVAD_CLDFB ->bg_energy_count = 384; move16(); } IF(LT_32(tsnr, 16777216/* 1.0/2.0 Q25 */)) { - bg_energy = VAD_L_ADD(bg_energy, st->bg_energy_scale, frame_energy, frame_energy_Q, &st->bg_energy_scale); - st->bg_energy_count = add(st->bg_energy_count, 1); + bg_energy = VAD_L_ADD(bg_energy, hVAD_CLDFB ->bg_energy_scale, frame_energy, frame_energy_Q, &hVAD_CLDFB ->bg_energy_scale); + hVAD_CLDFB ->bg_energy_count = add(hVAD_CLDFB ->bg_energy_count, 1); move16(); } } test(); - st->vad_flag_for_bk_update = vad_flag; - IF(LT_16(st->update_count, 12)&&EQ_16(vadb_flag,1)) + hVAD_CLDFB ->vad_flag_for_bk_update = vad_flag; + IF(LT_16(hVAD_CLDFB ->update_count, 12)&&EQ_16(vadb_flag,1)) { - st->warm_hang_num = s_max(20, speech_flag); + hVAD_CLDFB ->warm_hang_num = s_max(20, speech_flag); } test(); - IF(vad_flag == 0 && st->warm_hang_num > 0) + IF(vad_flag == 0 && hVAD_CLDFB ->warm_hang_num > 0) { - st->warm_hang_num = sub(st->warm_hang_num, 1); + hVAD_CLDFB ->warm_hang_num = sub(hVAD_CLDFB ->warm_hang_num, 1); vad_flag = 1; move16(); } @@ -839,20 +832,20 @@ Word16 comvad_decision( T_CldfbVadState *st, - st->lt_snr_org = lt_snr_org; + hVAD_CLDFB ->lt_snr_org = lt_snr_org; move32(); - st->fg_energy = fg_energy; + hVAD_CLDFB ->fg_energy = fg_energy; move32(); - st->bg_energy = bg_energy; + hVAD_CLDFB ->bg_energy = bg_energy; move32(); - st->speech_flag = speech_flag; + hVAD_CLDFB ->speech_flag = speech_flag; move16(); move16(); test(); IF(EQ_16(noisy_type, SILENCE) - && NE_16(st->bw_index, CLDFBVAD_NB_ID)) + && NE_16(hVAD_CLDFB ->bw_index, CLDFBVAD_NB_ID)) { *cldfb_addition = 2; } @@ -860,17 +853,17 @@ Word16 comvad_decision( T_CldfbVadState *st, { *cldfb_addition = 0; - if(EQ_16(st->bw_index, CLDFBVAD_WB_ID)) + if(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_WB_ID)) { *cldfb_addition = 3; move16(); } - if(EQ_16(st->bw_index, CLDFBVAD_SWB_ID)) + if(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_SWB_ID)) { *cldfb_addition = 1; move16(); } - if(EQ_16(st->bw_index, CLDFBVAD_NB_ID)) + if(EQ_16(hVAD_CLDFB ->bw_index, CLDFBVAD_NB_ID)) { *cldfb_addition = 1; move16(); diff --git a/lib_enc/cor_shif_fx.c b/lib_enc/cor_shif_fx.c index 71a455b..be74339 100644 --- a/lib_enc/cor_shif_fx.c +++ b/lib_enc/cor_shif_fx.c @@ -5,7 +5,6 @@ #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* @@ -17,8 +16,8 @@ * it can be assumed about 0 *-------------------------------------------------------------------*/ -Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ +Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ + const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ ) { Word16 corr_shift_fx, e_Noise, f_Noise, wtmp; diff --git a/lib_enc/core_enc_2div.c b/lib_enc/core_enc_2div.c index 799a255..5a89edf 100644 --- a/lib_enc/core_enc_2div.c +++ b/lib_enc/core_enc_2div.c @@ -3,22 +3,25 @@ ====================================================================================*/ -#include -#include +#include #include +#include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "options.h" #include "cnst_fx.h" -#include "stl.h" + + /*-------------------------------------------------------------------* + * core_encode_twodiv() + * + * Two-div core encoder + *-------------------------------------------------------------------*/ void core_encode_twodiv( - const Word16 new_samples[], - Encoder_State_fx *st, /* i/o : coder memory state */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const Word16 new_samples[], /* i : new samples */ + Encoder_State_fx *st, /* i/o: coder memory state */ + const Word16 coder_type, /* i : coding type */ + Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ Word16 *Q_new, Word16 *shift ) @@ -44,7 +47,10 @@ void core_encode_twodiv( CONTEXT_HM_CONFIG hm_cfg[2]; Word16 i, T_op[3]; Word16 bits_param_lpc[10], no_param_lpc; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ + hLPDmem = st->hLPDmem; spectrum[0] = spectrum_buf; spectrum[1] = spectrum_buf + N_TCX10_MAX; @@ -68,7 +74,7 @@ void core_encode_twodiv( FOR( i = 0; i < 3; i++ ) { move16(); - T_op[i] = pitch[i]; + T_op[i] = st->pitch_fx[i]; /* check minimum pitch for quantization */ IF ( LT_16(T_op[i], PIT_MIN_SHORTER)) @@ -92,12 +98,12 @@ void core_encode_twodiv( move16(); st->core_fx = TCX_10_CORE; - if ( EQ_16(st->tcxMode,TCX_20)) + if ( EQ_16(hTcxEnc->tcxMode,TCX_20)) { move16(); st->core_fx = TCX_20_CORE; } - assert(st->tcxMode == TCX_20 || st->tcxMode == TCX_10); + assert(hTcxEnc->tcxMode == TCX_20 || hTcxEnc->tcxMode == TCX_10); /*--------------------------------------------------------------* * Core Signal Analysis: MDCT, TNS, LPC analysis @@ -105,9 +111,6 @@ void core_encode_twodiv( core_signal_analysis_high_bitrate( new_samples, T_op, - voicing, - pitch, - Aw, lsp_new, lsp_mid, st, @@ -116,20 +119,19 @@ void core_encode_twodiv( param_core, <pBits, st->L_frame_fx, - st->L_frameTCX, + hTcxEnc->L_frameTCX, + EVS_MONO, + vad_hover_flag, spectrum, spectrum_e, - Q_new, - shift + Q_new ); /*--------------------------------------------------------------* * LPC Quantization *---------------------------------------------------------------*/ - lpc_quantization( st, st->core_fx, st->lpcQuantization, st->lsf_old_fx , lsp_new, lsp_mid, lsp_q, lsf_q, - lspmid_q, NULL, st->clip_var_fx, st->mem_MA_fx, st->mem_AR_fx, - st->narrowBand, coder_type, 0, param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, &(st->seed_acelp), - st->Bin_E_fx, st->Bin_E_old_fx, add(*Q_new, Q_SCALE - 2) ); + lpc_quantization( st, lsp_new, lsp_mid, lsp_q, lsf_q, lspmid_q, NULL, st->clip_var_fx, coder_type, + 0, param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, add(*Q_new, Q_SCALE - 2) ); /*--------------------------------------------------------------* * Rate switching @@ -167,14 +169,14 @@ void core_encode_twodiv( } /* Shape spectrum */ - ShapeSpectrum(&(st->tcx_cfg), + ShapeSpectrum(st->hTcxCfg, A_q, gainlpc[n], gainlpc_e[n], shr(st->L_frame_fx, 1), - shr(st->tcx_cfg.tcx_coded_lines, 1), + shr(st->hTcxCfg->tcx_coded_lines, 1), spectrum[n], - st->fUseTns[n], + hTcxEnc->fUseTns[n], st ); @@ -191,16 +193,16 @@ void core_encode_twodiv( /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ bitsAvailable = sub(bitsAvailable,1); test(); - if (EQ_16(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->tcx_cfg.tcx_curr_overlap_mode,MIN_OVERLAP)) + if (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,MIN_OVERLAP)) { bitsAvailable = sub(bitsAvailable,1); } - bitsAvailable = sub(bitsAvailable, st->hIGFEnc.infoTotalBitsWritten); + bitsAvailable = sub(bitsAvailable, st->hIGFEnc->infoTotalBitsWritten); /* calculate noise-filling over whole spectrum for TCX10 frames */ move16(); - st->measuredBwRatio = 0x4000; + hTcxEnc->measuredBwRatio = 0x4000; FOR (n = 0; n < 2; n++) { @@ -221,23 +223,22 @@ void core_encode_twodiv( /* Run TCX10 encoder */ QuantizeSpectrum( - &(st->tcx_cfg), + st->hTcxCfg, A_q, NULL, gainlpc[n], gainlpc_e[n], st->synth+n*st->L_frame_fx/2, shr(st->L_frame_fx, 1), - shr(st->L_frameTCX, 1), - shr(st->tcx_cfg.tcx_coded_lines, 1), + shr(hTcxEnc->L_frameTCX, 1), + shr(st->hTcxCfg->tcx_coded_lines, 1), target_bits, st->tcxonly, spectrum[n], &spectrum_e[n], - st->tnsData+n, - st->fUseTns[n], + hTcxEnc->tnsData+n, + hTcxEnc->fUseTns[n], tnsSize[n], - &(st->LPDmem), param_core+n*NPRM_DIV, n, st, @@ -249,12 +250,12 @@ void core_encode_twodiv( if ((n > 0) || (st->tcxonly==0)) { move16(); - st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; + st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; } } - coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); + coder_tcx_post( st, hLPDmem, st->hTcxCfg, st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); } /*--------------------------------------------------------------* @@ -267,29 +268,31 @@ void core_encode_twodiv( E_LPC_f_lsp_a_conversion(lsp_q, A_q, M); - ShapeSpectrum(&(st->tcx_cfg), + ShapeSpectrum(st->hTcxCfg, A_q, gainlpc[0], gainlpc_e[0], st->L_frame_fx, - st->tcx_cfg.tcx_coded_lines, + st->hTcxCfg->tcx_coded_lines, spectrum[0], - st->fUseTns[0], + hTcxEnc->fUseTns[0], st ); + /*_DIFF_FLOAT_FIX_ -> The line below is present in float */ + //hTcxEnc->measuredBwRatio = 0x4000; /* Calculate target bits */ target_bits = sub(sub(sub(sub(st->bits_frame_core, tnsBits[0]), nbits_lpc[0]), st->nb_bits_header_tcx), ltpBits); /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ target_bits = sub(target_bits,1); test(); - if (EQ_16(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->tcx_cfg.tcx_curr_overlap_mode,MIN_OVERLAP)) + if (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,MIN_OVERLAP)) { target_bits = sub(target_bits,1); } - target_bits = sub(target_bits, st->hIGFEnc.infoTotalBitsPerFrameWritten); + target_bits = sub(target_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten); if(st->enablePlcWaveadjust) @@ -299,30 +302,29 @@ void core_encode_twodiv( QuantizeSpectrum( - &(st->tcx_cfg), + st->hTcxCfg, A_q, NULL, gainlpc[0], gainlpc_e[0], st->synth, st->L_frame_fx, - st->L_frameTCX, - st->tcx_cfg.tcx_coded_lines, + hTcxEnc->L_frameTCX, + st->hTcxCfg->tcx_coded_lines, target_bits, st->tcxonly, spectrum[0], &spectrum_e[0], - &st->tnsData[0], - st->fUseTns[0], + &hTcxEnc->tnsData[0], + hTcxEnc->fUseTns[0], tnsSize[0], - &(st->LPDmem), param_core, 0, st, &hm_cfg[0] ); - coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); + coder_tcx_post( st, hLPDmem, st->hTcxCfg, st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 5c9baa7..d8c45bc 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -11,6 +11,7 @@ #include "count.h" #include "basop_util.h" #include "rom_com_fx.h" +#include "ivas_cnst.h" #include @@ -18,10 +19,10 @@ * Local functions *-----------------------------------------------------------------------*/ -static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old ); +static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag); static void init_core_sig_ana( Encoder_State_fx *st ); static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old, const Word16 shift); -static void init_modes( Encoder_State_fx *st ); +static void init_modes( Encoder_State_fx *st, const Word32 Last_total_brate ); /*-----------------------------------------------------------------------* * init_coder_ace_plus() @@ -29,18 +30,32 @@ static void init_modes( Encoder_State_fx *st ); * Initialization of state variables *-----------------------------------------------------------------------*/ -void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) +void init_coder_ace_plus( + Encoder_State_fx *st, + const Word32 last_total_brate, /* i : last total bitrate */ + const Word16 shift, + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +) { Word16 L_frame_old; /*keep old frame size for switching */ Word16 L_subfr; - + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Bitrate */ - st->tcxonly = getTcxonly(st->total_brate_fx); + st->tcxonly = (Word8)getTcxonly( +#ifdef IVAS_CODE_SWITCHING + st->element_mode, +#endif + st->total_brate_fx +#ifdef IVAS_CODE_SWITCHING + , MCT_flag, st->is_ism_format +#endif + ); move16(); /* Core Sampling Rate */ - st->sr_core = getCoreSamplerateMode2(st->total_brate_fx, st->bwidth_fx, st->rf_mode ); + st->sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate_fx, st->bwidth_fx, st->flag_ACELP16k, st->rf_mode, st->is_ism_format); st->fscale = sr2fscale(st->sr_core); move16(); @@ -60,7 +75,7 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) st->L_frame_past = -1; move16(); - st->L_frameTCX = extract_l(Mult_32_16(st->input_Fs_fx , 0x0290)); + hTcxEnc->L_frameTCX = extract_l(Mult_32_16(st->input_Fs_fx , 0x0290)); st->nb_subfr = NB_SUBFR; move16(); @@ -88,12 +103,12 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) } /* Initialize TBE */ - st->prev_coder_type_fx = GENERIC; + hBWE_TD->prev_coder_type_fx = GENERIC; move16(); - set16_fx( st->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); - st->prev_tilt_para_fx = 0; + set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); + hBWE_TD->prev_tilt_para_fx = 0; move16(); - set16_fx( st->cur_sub_Aq_fx, 0, M+1 ); + set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M+1 ); st->currEnergyHF_fx = 0; move16(); @@ -124,16 +139,29 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) } /* Initialize IGF */ - st->hIGFEnc.infoStopFrequency = -1; + if (st->hIGFEnc != NULL) + { + st->hIGFEnc->infoStopFrequency = -1; + } move16(); IF( st->igf ) { - IGFEncSetMode(&st->hIGFEnc, st->total_brate_fx, st->bwidth_fx, st->rf_mode); + IGFEncSetMode(st->hIGFEnc, st->total_brate_fx, st->bwidth_fx, st->element_mode, st->rf_mode); + } + ELSE IF (st->hIGFEnc != NULL) + { + st->hIGFEnc->infoTotalBitsWritten = 0; +#ifdef AFFECT_TEST_VECTOR_BE_1 + st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; + /* the line above is needed for some transition, but when going from low rate to high rate, ex 7k2 to 96k, EVS fix point doesn't do the reset (or it does somewhere else */ +#endif } /* Initialize TCX */ - init_tcx( st, L_frame_old ); - + if (hTcxEnc != NULL) + { + init_tcx(st, L_frame_old, st->total_brate_fx, last_total_brate, MCT_flag); + } /* Initialize Core Signal Analysis Module */ init_core_sig_ana( st ); @@ -150,11 +178,11 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) } IF(st->tec_tfa == 0) { - resetTecEnc_Fx(&st->tecEnc, 0); + resetTecEnc_Fx(st->hTECEnc, 0); } ELSE { - resetTecEnc_Fx(&st->tecEnc, 1); + resetTecEnc_Fx(st->hTECEnc, 1); } st->tec_tfa = 0; move16(); @@ -194,7 +222,7 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) move16(); /* Initialize ACELP/TCX Modes */ - init_modes( st ); + init_modes( st, last_total_brate); /* Init I/O */ @@ -225,7 +253,7 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) move16(); } - open_PLC_ENC_EVS( &st->plcExt, st->sr_core ); + init_PLC_enc( st->hPlcExt, st->sr_core ); st->glr_idx[0] = 0; move16(); @@ -245,88 +273,93 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) return; } -static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old ) +static void init_tcx( + Encoder_State_fx *st, + Word16 L_frame_old, + const Word32 total_brate, + const Word32 last_total_brate, + const Word16 MCT_flag +) { Word16 i; Word16 fscaleFB; - - + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; +PMT("init_tcx needs an entire review to adapt to IVAS") fscaleFB = div_l(L_shl(st->input_Fs_fx, LD_FSCALE_DENOM+1), 12800); - init_TCX_config(&st->tcx_cfg, st->L_frame_fx, st->fscale, st->L_frameTCX, fscaleFB ); + init_TCX_config(st->hTcxCfg, st->L_frame_fx, st->fscale, hTcxEnc->L_frameTCX, fscaleFB ); - st->tcx_cfg.tcx_mdct_window_length_old = st->tcx_cfg.tcx_mdct_window_length; + st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length; move16(); /* TCX Offset */ - st->tcx_cfg.tcx_offset = shr(st->tcx_cfg.tcx_mdct_window_delay, 1); + st->hTcxCfg->tcx_offset = shr(st->hTcxCfg->tcx_mdct_window_delay, 1); move16(); - st->tcx_cfg.tcx_offsetFB = shr(st->tcx_cfg.tcx_mdct_window_delayFB, 1); + st->hTcxCfg->tcx_offsetFB = shr(st->hTcxCfg->tcx_mdct_window_delayFB, 1); move16(); /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ - st->tcx_cfg.lfacNext = sub(st->tcx_cfg.tcx_offset, shr(st->L_frame_fx, 2)); + st->hTcxCfg->lfacNext = sub(st->hTcxCfg->tcx_offset, shr(st->L_frame_fx, 2)); move16(); - st->tcx_cfg.lfacNextFB = sub(st->tcx_cfg.tcx_offsetFB, shr(st->L_frameTCX, 2)); + st->hTcxCfg->lfacNextFB = sub(st->hTcxCfg->tcx_offsetFB, shr(hTcxEnc->L_frameTCX, 2)); IF ( st->ini_frame_fx == 0 ) { - st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); move16(); } /* Init TCX target bits correction factor */ - st->LPDmem.tcx_target_bits_fac = 0x4000; /*1.0f in 1Q14*/ move16(); - st->measuredBwRatio = 0x4000; /*1.0f in 1Q14*/ move16(); - st->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ move16(); - st->noiseLevelMemory = 0; + hTcxEnc->tcx_target_bits_fac = 0x4000; /*1.0f in 1Q14*/ move16(); + hTcxEnc->measuredBwRatio = 0x4000; /*1.0f in 1Q14*/ move16(); + hTcxEnc->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ move16(); + hTcxEnc->noiseLevelMemory = 0; move16(); /*SQ deadzone & memory quantization*/ /*0.375f: deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - st->tcx_cfg.sq_rounding = 12288/*0.375f Q15*/; + st->hTcxCfg->sq_rounding = 12288/*0.375f Q15*/; move16(); FOR (i = 0; i < L_FRAME_PLUS; i++) { - st->memQuantZeros[i] = 0; + hTcxEnc->memQuantZeros[i] = 0; move16(); } /* TCX rate loop */ - st->tcx_cfg.tcxRateLoopOpt = 0; + st->hTcxCfg->tcxRateLoopOpt = 0; move16(); if ( st->tcxonly != 0 ) { - st->tcx_cfg.tcxRateLoopOpt = 2; + st->hTcxCfg->tcxRateLoopOpt = 2; move16(); } /* TCX bandwidth */ move16(); - st->tcx_cfg.bandwidth = getTcxBandwidth(st->bwidth_fx); + st->hTcxCfg->bandwidth = getTcxBandwidth(st->bwidth_fx); /* set number of coded lines */ - st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(st->bwidth_fx); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(st->bwidth_fx); /* TNS in TCX */ move16(); move16(); - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate_fx - ,st->igf - ); - st->tcx_cfg.pCurrentTnsConfig = NULL; + st->hTcxCfg->fIsTNSAllowed = (Word8)getTnsAllowed(st->total_brate_fx ,st->igf, st->element_mode); + + st->hTcxCfg->pCurrentTnsConfig = NULL; - IF ( st->tcx_cfg.fIsTNSAllowed != 0 ) + IF ( st->hTcxCfg->fIsTNSAllowed != 0 ) { - InitTnsConfigs(bwMode2fs[st->bwidth_fx], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFEnc.infoStopFrequency, st->total_brate_fx); + InitTnsConfigs(st->bwidth_fx, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate_fx, st->element_mode, 0/*is_mct*/); } /* TCX-LTP */ - st->tcxltp = getTcxLtp(st->sr_core); + hTcxEnc->tcxltp = getTcxLtp(st->sr_core); test(); test(); @@ -335,13 +368,13 @@ static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old ) IF( st->ini_frame_fx == 0 ) { - st->tcxltp_pitch_int_past = st->L_frame_fx; + hTcxEnc->tcxltp_pitch_int_past = st->L_frame_fx; move16(); - st->tcxltp_pitch_fr_past = 0; + hTcxEnc->tcxltp_pitch_fr_past = 0; move16(); - st->tcxltp_gain_past = 0; + hTcxEnc->tcxltp_gain_past = 0; move16(); - st->tcxltp_norm_corr_past = 0; + hTcxEnc->tcxltp_norm_corr_past = 0; move16(); } ELSE IF ( NE_16(st->L_frame_fx,L_frame_old)&&!((st->total_brate_fx==16400||st->total_brate_fx==24400)&&(st->total_brate_fx==st->last_total_brate_fx)&&(st->last_bwidth_fx==st->bwidth_fx))) @@ -358,7 +391,7 @@ static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old ) } /*pit_old = (float)st->tcxltp_pitch_int_past + (float)st->tcxltp_pitch_fr_past/(float)pitres_old;*/ - pit_old = add(st->tcxltp_pitch_int_past, mult_r(st->tcxltp_pitch_fr_past, div_s(1,pitres_old))); + pit_old = add(hTcxEnc->tcxltp_pitch_int_past, mult_r(hTcxEnc->tcxltp_pitch_fr_past, div_s(1,pitres_old))); pitres = 4; move16(); @@ -372,37 +405,36 @@ static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old ) pit = shl(mult_r(pit_old, div_s(st->L_frame_fx, shl(L_frame_old, 2))), 2); /* assert(pit <= st->L_frame_fx);*/ - st->tcxltp_pitch_int_past = pit; + hTcxEnc->tcxltp_pitch_int_past = pit; move16(); move16(); - st->tcxltp_pitch_fr_past = i_mult2(sub(pit,st->tcxltp_pitch_int_past),pitres); + hTcxEnc->tcxltp_pitch_fr_past = i_mult2(sub(pit, hTcxEnc->tcxltp_pitch_int_past),pitres); move16(); } /* Residual Coding*/ - st->tcx_cfg.resq = getResq(st->total_brate_fx); + st->hTcxCfg->resq = getResq(st->total_brate_fx); move16(); test(); - if ( st->tcx_cfg.resq != 0 && st->tcxonly == 0) + if ( st->hTcxCfg->resq != 0 && st->tcxonly == 0) { - st->tcx_cfg.tcxRateLoopOpt = 1; + st->hTcxCfg->tcxRateLoopOpt = 1; move16(); } - st->tcx_cfg.ctx_hm = getCtxHm( st->total_brate_fx, st->rf_mode ); + st->hTcxCfg->ctx_hm = getCtxHm(st->element_mode, st->total_brate_fx, st->rf_mode ); - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - st->total_brate_fx, - st->bwidth_fx - ,st->rf_mode - ); + hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri(st->total_brate_fx,st->rf_mode, st->element_mode); } void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Word16 L_subfr ) { + LPD_state_HANDLE hLPDmem = st->hLPDmem; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + /* Encoder Past Samples at encoder-sampling-rate */ st->encoderPastSamples_enc = shr(imult1616(st->L_frame_fx, 9), 4); @@ -411,7 +443,7 @@ void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Wor { set16_fx(st->buf_speech_enc, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); set16_fx(st->buf_speech_enc_pe, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); - set16_fx(st->buf_speech_ltp, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); + set16_fx(hTcxEnc->buf_speech_ltp, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); set16_fx(st->buf_wspeech_enc, 0, L_FRAME16k+L_SUBFR+L_FRAME16k+L_NEXT_MAX_16k); } ELSE @@ -427,7 +459,7 @@ void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Wor test(); IF( NE_16(st->last_core_fx,TCX_20_CORE)&&NE_16(st->last_core_fx,TCX_10_CORE)) /* condition should be checked again */ { - Copy( st->buf_speech_enc, st->buf_speech_ltp, st->L_frame_fx ); + Copy( st->buf_speech_enc, hTcxEnc->buf_speech_ltp, st->L_frame_fx ); } Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-L_WSP_MEM,L_WSP_MEM, sub(st->prev_Q_new, st->prev_Q_old)); @@ -463,7 +495,7 @@ void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Wor { lerp( st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-L_WSP_MEM, st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-310, 310, L_WSP_MEM ); } - st->LPDmem.mem_w0 = 0; + hLPDmem->mem_w0 = 0; move16(); st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame_fx+L_SUBFR-1]; move16(); @@ -472,13 +504,13 @@ void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Wor st->new_speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc + st->encoderLookahead_enc; st->new_speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc + st->encoderLookahead_enc; - st->new_speech_ltp = st->buf_speech_ltp + st->encoderPastSamples_enc + st->encoderLookahead_enc; - st->new_speech_TCX = st->input_buff + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS) - NS2SA(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); + hTcxEnc->new_speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc + st->encoderLookahead_enc; + hTcxEnc->new_speech_TCX = st->input_buff + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS) - NS2SA(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); st->speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc; st->speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc; - st->speech_ltp = st->buf_speech_ltp + st->encoderPastSamples_enc; - st->speech_TCX = st->new_speech_TCX - st->encoderLookahead_FB; + hTcxEnc->speech_ltp = hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc; + hTcxEnc->speech_TCX = hTcxEnc->new_speech_TCX - st->encoderLookahead_FB; st->wspeech_enc = st->buf_wspeech_enc + st->L_frame_fx + L_subfr; @@ -498,7 +530,6 @@ void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Wor static void init_core_sig_ana( Encoder_State_fx *st ) { - /* Pre-emphasis factor and memory */ st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); @@ -511,7 +542,7 @@ static void init_core_sig_ana( Encoder_State_fx *st ) st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); } - st->tcx_cfg.preemph_fac=st->preemph_fac; + st->hTcxCfg->preemph_fac=st->preemph_fac; move16(); st->gamma = GAMMA1; @@ -548,7 +579,8 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 { Word16 mem_syn_r_size_old; Word16 mem_syn_r_size_new; - + LPD_state_HANDLE hLPDmem = st->hLPDmem; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Init pitch lag */ st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); @@ -557,30 +589,30 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 /* Init LPDmem */ IF( st->ini_frame_fx == 0 ) { - set16_fx( st->LPDmem.syn, 0, 1+M ); + set16_fx( hLPDmem->syn, 0, 1+M ); - set16_fx( st->LPDmem.Txnq, 0, L_FRAME32k/2+64); - st->LPDmem.acelp_zir = st->LPDmem.Txnq + shr(st->L_frame_fx,1); - set16_fx( st->LPDmem.mem_syn_r, 0, L_SYN_MEM ); + set16_fx(hTcxEnc->Txnq, 0, L_FRAME32k/2+64); + hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr(st->L_frame_fx,1); + set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); } ELSE /*Rate switching*/ { IF( EQ_16(st->last_core_fx,ACELP_CORE)) { - lerp( st->LPDmem.Txnq,st->LPDmem.Txnq, shr(st->L_frame_fx,1), shr(L_frame_old,1) ); + lerp(hTcxEnc->Txnq,hTcxEnc->Txnq, shr(st->L_frame_fx,1), shr(L_frame_old,1) ); } ELSE { - lerp( st->LPDmem.Txnq,st->LPDmem.Txnq, st->tcx_cfg.tcx_mdct_window_length, st->tcx_cfg.tcx_mdct_window_length_old ); + lerp(hTcxEnc->Txnq,hTcxEnc->Txnq, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old ); } - st->LPDmem.acelp_zir = st->LPDmem.Txnq + shr(st->L_frame_fx,1); + hTcxEnc->acelp_zir = hTcxEnc->Txnq + shr(st->L_frame_fx,1); /* Rate switching */ IF( EQ_16(st->last_codec_mode,MODE1)) { - Copy( st->mem_syn1_fx, st->LPDmem.mem_syn2, M ); - set16_fx( st->LPDmem.Txnq, 0, L_FRAME32k/2+64); - set16_fx( st->LPDmem.syn, 0, M ); + Copy(hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); + set16_fx(hTcxEnc->Txnq, 0, L_FRAME32k/2+64); + set16_fx( hLPDmem->syn, 0, M ); } /*AMR-WBIO->MODE2*/ @@ -600,14 +632,14 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 move16(); st->rate_switching_reset = 1; move16(); - st->LPDmem.tilt_code = TILT_CODE; + hLPDmem->tilt_code = TILT_CODE; move16(); - set16_fx( st->LPDmem.old_exc, 0, L_EXC_MEM ); - set16_fx( st->LPDmem.syn, 0, 1+M ); - st->LPDmem.mem_w0 = 0; + set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); + set16_fx( hLPDmem->syn, 0, 1+M ); + hLPDmem->mem_w0 = 0; move16(); - set16_fx( st->LPDmem.mem_syn, 0, M ); - set16_fx( st->LPDmem.mem_syn2, 0, M ); + set16_fx( hLPDmem->mem_syn, 0, M ); + set16_fx( hLPDmem->mem_syn2, 0, M ); /* unquantized LPC*/ test(); @@ -631,10 +663,10 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 st->last_core_fx = TCX_20_CORE; move16(); - st->tcx_cfg.last_aldo=1; /*It was previously ALDO*/ - st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->last_aldo=1; /*It was previously ALDO*/ + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /*ALDO overlap windowed past: also used in MODE1 but for other MDCT-FB*/ - set16_fx( st->old_out_fx, 0, st->L_frame_fx ); + set16_fx(hTcxEnc->old_out_fx, 0, st->L_frame_fx ); } ELSE { @@ -661,9 +693,9 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } - synth_mem_updt2( st->L_frame_fx, st->last_L_frame_fx, st->LPDmem.old_exc, st->LPDmem.mem_syn_r, st->LPDmem.mem_syn2, st->LPDmem.mem_syn, ENC ); + synth_mem_updt2( st->L_frame_fx, st->last_L_frame_fx, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); - /*Mem of deemphasis stay unchanged : st->LPDmem.syn*/ + /*Mem of deemphasis stay unchanged : hLPDmem->syn*/ { Word16 tmp, A[M+1], Ap[M+1],tmp_buf[M+1]; /* Update wsyn */ @@ -674,10 +706,10 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 move16(); tmp_buf[0]=0; move16(); - Copy( st->LPDmem.mem_syn2, tmp_buf+1, M ); + Copy( hLPDmem->mem_syn2, tmp_buf+1, M ); deemph_fx( tmp_buf+1, st->preemph_fac, M, &tmp ); Residu3_fx( Ap, tmp_buf+M, &tmp, 1, 1 ); - st->LPDmem.mem_w0 = sub(shr(st->wspeech_enc[-1],shift), tmp); + hLPDmem->mem_w0 = sub(shr(st->wspeech_enc[-1],shift), tmp); } } ELSE IF((NE_16(st->L_frame_fx,L_frame_old))) @@ -689,9 +721,9 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 move16(); /*reset partly some memories*/ - st->LPDmem.tilt_code = TILT_CODE; + hLPDmem->tilt_code = TILT_CODE; move16(); - set16_fx( st->LPDmem.old_exc, 0, L_EXC_MEM ); + set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); move16(); /*Resamp others memories*/ @@ -700,12 +732,12 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 mem_syn_r_size_old = shr(L_frame_old, 4); mem_syn_r_size_new = shr(st->L_frame_fx, 4); - lerp( st->LPDmem.mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->LPDmem.mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->LPDmem.mem_syn_r+L_SYN_MEM-M, st->LPDmem.mem_syn, M); - Copy( st->LPDmem.mem_syn, st->LPDmem.mem_syn2, M ); + lerp( hLPDmem->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, hLPDmem->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( hLPDmem->mem_syn_r+L_SYN_MEM-M, hLPDmem->mem_syn, M); + Copy( hLPDmem->mem_syn, hLPDmem->mem_syn2, M ); - /*Untouched memories : st->LPDmem.syn & st->LPDmem.mem_w0*/ - st->LPDmem.mem_w0 = 0; + /*Untouched memories : hLPDmem->syn & hLPDmem->mem_w0*/ + hLPDmem->mem_w0 = 0; move16(); /* unquantized LPC*/ @@ -740,11 +772,12 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 } /* Post-processing */ - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); - st->dm_fx.prev_state = 0; + hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + hLPDmem->dm_fx.prev_state = 0; + move16(); - st->LPDmem.gc_threshold = 0; + hLPDmem->gc_threshold = 0; move16(); /* Pulse Search configuration */ @@ -773,17 +806,19 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 return; } -static void init_modes( Encoder_State_fx *st ) +static void init_modes( + Encoder_State_fx *st, + const Word32 last_total_brate +) { Word8 n; Word32 tmp32; - - + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Restrict ACE/TCX20/TCX10 mode */ move16(); - st->restrictedMode = getRestrictedMode(st->total_brate_fx, st->Opt_AMR_WB_fx); + st->restrictedMode = getRestrictedMode(st->element_mode, st->total_brate_fx, st->Opt_AMR_WB_fx); move16(); st->acelpEnabled = 0; move16(); @@ -809,7 +844,7 @@ static void init_modes( Encoder_State_fx *st ) /* TCX mode (TCX20 TCX10_10 or NO_TCX) */ - st->tcxMode = NO_TCX; + hTcxEnc->tcxMode = NO_TCX; move16(); /* Bits Budget */ @@ -854,7 +889,7 @@ static void init_modes( Encoder_State_fx *st ) } /* Reconfigure core */ - core_coder_reconfig( st ); + core_coder_reconfig( st, last_total_brate); return; diff --git a/lib_enc/core_enc_ol.c b/lib_enc/core_enc_ol.c index 3a16ba9..d637b2f 100644 --- a/lib_enc/core_enc_ol.c +++ b/lib_enc/core_enc_ol.c @@ -2,25 +2,23 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include #include +#include +#include "options.h" #include "prot_fx.h" #include "basop_util.h" -#include "options.h" #include "cnst_fx.h" -#include "stl.h" -#include "stl.h" #include "rom_com_fx.h" +/*-------------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------------*/ + +static void closest_centroid_rf(const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length, Word16 *ind_vec); +static void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, Word16* tilt_code, Word16* rf_frame_type, Word16* rf_target_bits, Word16 nb_subfr, Word16 rf_fec_indicator, Word16* pitch_buf); +static void BITS_ALLOC_TCX_config_rf(Word16* rf_frame_type, Word16* rf_target_bits, Word16 PLC_Mode, Word16 coder_type, Word16 last_core, Word16 TD_mode); -void closest_centroid_rf(const Word16 *data, /* i : input data */ - const Word16 *weights, /* i : weights */ - const Word16 *quantizer, /* i : quantizer table */ - const Word16 centroids, /* i : number of centroids */ - const Word16 length, /* i : dimension of quantiser */ - Word16 *ind_vec); /* o : list of best match indice vectors */ /*-------------------------------------------------------------------* @@ -30,16 +28,14 @@ void closest_centroid_rf(const Word16 *data, /* i : input data */ *-------------------------------------------------------------------*/ void core_encode_openloop( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - const Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 *lsp_new, /* i : LSPs at the end of the frame */ - const Word16 *lsp_mid, /* i : LSPs at the middle of the frame */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *ptr_bwe_exc, /* o : excitation for SWB TBE */ + Encoder_State_fx *st, /* i/o: encoder state structure */ + const Word16 coder_type, /* i : coding type */ + const Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const Word16 *lsp_new, /* i : LSPs at the end of the frame */ + const Word16 *lsp_mid, /* i : LSPs at the middle of the frame */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *ptr_bwe_exc, /* o : excitation for SWB TBE */ const Word16 vad_hover_flag, const Word16 vad_flag_dtx, Word16 Q_new, @@ -82,7 +78,13 @@ void core_encode_openloop( Word16 w_rf[M+1], lsf_uq_rf[M+1]; Word16 lsf_q_1st_rf[M+1], lsf_q_d_rf[M+1], lsf_q_rf[M+1]; Word16 lsp_old_q_rf[M+1], lsf_old_q_rf[M+1]; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + RF_ENC_HANDLE hRF = st->hRF; + LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ + hLPDmem = st->hLPDmem; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; /* copy primary memories to use later during partial copy assembly */ @@ -100,35 +102,34 @@ void core_encode_openloop( /* back up old exc before primary encoding */ set16_fx( exc_buf_rf, 0, (L_EXC_MEM+L_FRAME+1) ); exc_rf = exc_buf_rf + L_EXC_MEM; - Copy(st->LPDmem.old_exc, exc_buf_rf, L_EXC_MEM); + Copy(hLPDmem->old_exc, exc_buf_rf, L_EXC_MEM); /* back up old synthesis before primary encoding */ set16_fx( syn_buf_rf, 0, (M+L_FRAME16k+L_FRAME16k/2) ); syn_rf = syn_buf_rf + M; - Copy(st->LPDmem.mem_syn, syn_buf_rf, M); + Copy(hLPDmem->mem_syn, syn_buf_rf, M); /* back up syn2 mem */ - Copy(st->LPDmem.mem_syn2, st->rf_mem_syn2, M); + Copy(hLPDmem->mem_syn2, hRF->rf_mem_syn2, M); /* back up LPD mem_w0 target generation memory */ - st->rf_mem_w0 = st->LPDmem.mem_w0; + hRF->rf_mem_w0 = hLPDmem->mem_w0; /* back up clip gain memory */ - Copy( st->clip_var_fx, st->rf_clip_var, 6 ); + Copy( st->clip_var_fx, hRF->rf_clip_var, 6 ); /* back up tilt code */ - st->rf_tilt_code = st->LPDmem.tilt_code; + hRF->rf_tilt_code = hLPDmem->tilt_code; /* back up dispMem */ - st->rf_dm_fx.prev_state = st->dm_fx.prev_state; - st->rf_dm_fx.prev_gain_code = st->dm_fx.prev_gain_code; + hRF->rf_dm_fx.prev_state = hLPDmem->dm_fx.prev_state; + hRF->rf_dm_fx.prev_gain_code = hLPDmem->dm_fx.prev_gain_code; FOR(i=0; i<6; i++) { - st->rf_dm_fx.prev_gain_pit[i] = st->dm_fx.prev_gain_pit[i]; + hRF->rf_dm_fx.prev_gain_pit[i] = hLPDmem->dm_fx.prev_gain_pit[i]; } - /* back up gc_threshold for noise addition */ - st->rf_gc_threshold = st->LPDmem.gc_threshold; + hRF->rf_gc_threshold = hLPDmem->gc_threshold; /* initialization */ @@ -136,7 +137,7 @@ void core_encode_openloop( move16(); set16_fx( param_lpc, 0, NPRM_LPC_NEW ); set16_fx( param_core, 0, 2*NPRM_DIV ); - Copy( st->tcxltp_param, ¶m_core[1+NOISE_FILL_RANGES], LTPSIZE ); + Copy(hTcxEnc->tcxltp_param, ¶m_core[1+NOISE_FILL_RANGES], LTPSIZE ); no_param_lpc = 0; move16(); /* avoid MSVC warnings */ @@ -157,7 +158,7 @@ void core_encode_openloop( st->acelp_cfg.midLpc = st->acelp_cfg.midLpc_enable; move16(); test(); - if ( (EQ_16(st->lpcQuantization, 1))&&(EQ_16(coder_type,VOICED))) + if ( EQ_16(st->lpcQuantization, 1) && EQ_16(coder_type,VOICED)) { st->acelp_cfg.midLpc = 0; move16(); @@ -176,19 +177,15 @@ void core_encode_openloop( IF(EQ_16(st->core_fx,TCX_20_CORE)) { - lpc_quantization( st, st->core_fx, st->lpcQuantization, st->lsf_old_fx, lsp_new, lsp_mid, - lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, st-> mem_MA_fx, st->mem_AR_fx, - st->narrowBand, AUDIO, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, - &(st->seed_acelp), st->Bin_E_fx, st->Bin_E_old_fx, add(Q_new, Q_SCALE - 2) ); + lpc_quantization( st, lsp_new, lsp_mid, lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, + AUDIO, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, add(Q_new, Q_SCALE - 2) ); } ELSE { - lpc_quantization( st, st->core_fx, st->lpcQuantization, st->lsf_old_fx, lsp_new, lsp_mid, - lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, st-> mem_MA_fx, st->mem_AR_fx, - st->narrowBand, coder_type, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, - &(st->seed_acelp), st->Bin_E_fx, st->Bin_E_old_fx, add(Q_new, Q_SCALE - 2) ); + lpc_quantization( st, lsp_new, lsp_mid, lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, coder_type, + st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, add(Q_new, Q_SCALE - 2) ); } /*-------------------------------------------------------------* @@ -241,9 +238,9 @@ void core_encode_openloop( target_bits = sub(target_bits, MIDLSF_NBITS ); } - if( st->plcExt.enableGplc ) + if( st->hPlcExt->enableGplc ) { - target_bits = sub(target_bits, st->plcExt.nBits); + target_bits = sub(target_bits, st->hPlcExt->nBits); } /* reset TBE buffers previous frame frame wasn't ACELP*/ @@ -254,51 +251,33 @@ void core_encode_openloop( /* Run ACELP encoder */ - coder_acelp( - &(st->acelp_cfg), - coder_type, - Aw, - A_q, - st->speech_enc_pe, - st->synth, - &(st->LPDmem), - voicing, - pitch, - param_core, - stab_fac, - st, - &st->plcExt, - target_bits, - Q_new, - shift, - pitch_buf, - voice_factors, - ptr_bwe_exc - ); - - - st->glr_idx[0] = encSideSpecPowDiffuseDetector( st->plcExt.last_lsf_ref, st->plcExt.last_lsf_con, st->last_sr_core, &(st->prev_lsf4_mean), st->glr, coder_type ); - Copy(lsf_q, st->plcExt.last_lsf_ref, M); - Copy(st->plcExt.lsf_con, st->plcExt.last_lsf_con, M); + coder_acelp( Aw, A_q, st->speech_enc_pe, param_core, stab_fac, st, st->hPlcExt, target_bits, + Q_new, shift, pitch_buf, voice_factors, ptr_bwe_exc); + IF (st->hPlcExt) + { + st->glr_idx[0] = encSideSpecPowDiffuseDetector(st->hPlcExt->last_lsf_ref, st->hPlcExt->last_lsf_con, st->last_sr_core, &(st->prev_lsf4_mean), st->glr, coder_type); + Copy(lsf_q, st->hPlcExt->last_lsf_ref, M); + Copy(st->hPlcExt->lsf_con, st->hPlcExt->last_lsf_con, M); - updateSpecPowDiffuseIdx(st); + updateSpecPowDiffuseIdx(st); - if(GT_16(st->last_stab_fac, 655/*0.02f Q15*/)) - { + if (GT_16(st->last_stab_fac, 655/*0.02f Q15*/)) + { + move16(); + st->glr_idx[0] = 0; + } + move16(); move16(); - st->glr_idx[0] = 0; + st->hPlcExt->LPDmem = hLPDmem; + encoderSideLossSimulation( st,st->hPlcExt, lsf_q, stab_fac, st->hPlcExt->calcOnlylsf, st->L_frame_fx); } - move16(); st->last_stab_fac = stab_fac; - move16(); - st->plcExt.LPDmem = &st->LPDmem; - encoderSideLossSimulation( st, &st->plcExt, lsf_q, stab_fac, st->plcExt.calcOnlylsf, st->L_frame_fx); - st->tcxltp_norm_corr_past = voicing[1]; + hTcxEnc->tcxltp_norm_corr_past = st->voicing_fx[1]; move16(); - st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); } @@ -318,7 +297,7 @@ void core_encode_openloop( Copy(st->mem_MA_fx, rf_mem_MA, M); } - tcx_lpc_cdk = tcxlpc_get_cdk(st->tcx_cfg.coder_type); + tcx_lpc_cdk = tcxlpc_get_cdk(st->hTcxCfg->coder_type); /* Get the envelope corresponding to the current frame */ E_LPC_int_lpc_tcx( st->lspold_enc_fx, lsp_new, A_q ); @@ -335,7 +314,7 @@ void core_encode_openloop( /* Quantize */ Q_lsf_tcxlpc( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st-> mem_MA_fx, - st->tcx_cfg.coder_type, st->Bin_E_fx, add(Q_new, Q_SCALE-2) ); + st->hTcxCfg->coder_type, st->Bin_E_fx, add(Q_new, Q_SCALE-2) ); /* Account for consumed bits */ nbits_lpc = TCXLPC_NUMBITS; @@ -354,7 +333,7 @@ void core_encode_openloop( E_LPC_int_lpc_tcx( st->lsp_old_fx, lsp_q, A_q ); } - IF (st->tcx_lpc_shaped_ari != 0) + IF (hTcxEnc->tcx_lpc_shaped_ari != 0) { E_LPC_f_lsp_a_conversion(lspq_ind, A_q_ind, M); } @@ -370,7 +349,7 @@ void core_encode_openloop( IF (EQ_16(st->mdct_sw, MODE1)) { - /* Account for core mode signaling bits difference: bandwidth and ACELP/TCX signaling bit are replaced */ + /* Account for core signaling bits difference: bandwidth and ACELP/TCX signaling bit are replaced */ target_bits = add(target_bits, sub(add(FrameSizeConfig[st->frame_size_index].bandwidth_bits, 1), signalling_mode1_tcx20_enc(st, 0))); } ELSE if ( EQ_16(st->mdct_sw_enable, MODE2)) @@ -378,55 +357,58 @@ void core_encode_openloop( target_bits = sub(target_bits, 1); } - if( st->plcExt.enableGplc ) + if( st->hPlcExt->enableGplc ) { - target_bits = sub(target_bits, st->plcExt.nBits); + target_bits = sub(target_bits, st->hPlcExt->nBits); } /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ target_bits = sub(target_bits,1); test(); - if (EQ_16(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->tcx_cfg.tcx_curr_overlap_mode,MIN_OVERLAP)) + if (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)||EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,MIN_OVERLAP)) { target_bits = sub(target_bits,1); } - target_bits = sub(target_bits, st->tcxltp_bits); + target_bits = sub(target_bits, hTcxEnc->tcxltp_bits); coder_tcx( 0, - &(st->tcx_cfg), + st->hTcxCfg, A_q, A_q_ind, st->synth, st->L_frame_fx, - st->L_frameTCX, - st->tcx_cfg.tcx_coded_lines, + hTcxEnc->L_frameTCX, + st->hTcxCfg->tcx_coded_lines, target_bits, st->tcxonly, spectrum_long, &spectrum_long_e, - &(st->LPDmem), param_core, st, &hm_cfg ); - coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc, Q_new, shift ); + coder_tcx_post( st, hLPDmem, st->hTcxCfg, st->synth, A_q, Aw, st->wspeech_enc, Q_new, shift ); move16(); - st->plcExt.LPDmem = &(st->LPDmem); - - GplcTcxEncSetup(st, &st->plcExt, Q_new); + IF(st->hPlcExt) + { + st->hPlcExt->LPDmem = hLPDmem; + GplcTcxEncSetup(st,st->hPlcExt, Q_new); + } IF (st->enableTcxLpc) { E_LPC_lsp_unweight( lsp_tcx_q, lsp_q, lsf_q, st->inv_gamma, M ); } - - encoderSideLossSimulation( st, &st->plcExt, lsf_q, stab_fac, 1, st->L_frame_fx ); + IF(st->hPlcExt) + { + encoderSideLossSimulation(st,st->hPlcExt, lsf_q, stab_fac, 1, st->L_frame_fx); + } } @@ -450,7 +432,7 @@ void core_encode_openloop( st->pstreaklen_fx = 0; st->streaklimit_fx = 32767; /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx( st->lsf_old_fx, st->clip_var_fx, 0 ); + gp_clip_test_lsf_fx(st->element_mode, st->lsf_old_fx, st->clip_var_fx, 0 ); Copy(st->lsf_old_fx, st->mem_AR_fx, M); } ELSE @@ -463,26 +445,6 @@ void core_encode_openloop( /*--------------------------------------------------------------* * Update LP_CNG parameters *--------------------------------------------------------------*/ - - test(); - IF( st->Opt_DTX_ON_fx != 0 && vad_hover_flag != 0 ) - { - st->burst_ho_cnt_fx = add(st->burst_ho_cnt_fx,1); - if( GT_16(st->burst_ho_cnt_fx,HO_HIST_SIZE)) - { - st->burst_ho_cnt_fx = HO_HIST_SIZE; - move16(); - } - } - ELSE - { - IF( st->Opt_DTX_ON_fx != 0 && vad_flag_dtx != 0 ) - { - st->burst_ho_cnt_fx = 0; - move16(); - } - } - IF( st->Opt_DTX_ON_fx != 0 ) { /* update CNG parameters in active frames */ @@ -498,38 +460,37 @@ void core_encode_openloop( E_LPC_lev_dur(r_h, r_l, A, NULL, M, NULL); E_LPC_a_lsp_conversion(A, lsptmp, lsp_new, M); Residu3_fx(A, buf+L_LP-L_FRAME, res, L_FRAME, 1); - cng_params_upd_fx( lsptmp, res, st->L_frame_fx, &st->ho_circ_ptr_fx, - st->ho_ener_circ_fx, &st->ho_circ_size_fx, st->ho_lsp_circ_fx, - Q_new, ENC, NULL, &st->cng_buf_cnt, st->cng_exc2_buf, - st->cng_Qexc_buf, st->cng_brate_buf, st->last_active_brate_fx ); + cng_params_upd_fx( lsptmp, res, st->L_frame_fx, &hTdCngEnc->ho_circ_ptr_fx, + hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size_fx, hTdCngEnc->ho_lsp_circ_fx, + Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, + hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate_fx ); } ELSE { - cng_params_upd_fx( lsp_new, st->LPDmem.old_exc+L_EXC_MEM-st->L_frame_fx, - st->L_frame_fx, &st->ho_circ_ptr_fx, st->ho_ener_circ_fx, - &st->ho_circ_size_fx, st->ho_lsp_circ_fx, Q_new, ENC, NULL, - &st->cng_buf_cnt, st->cng_exc2_buf, - st->cng_Qexc_buf, st->cng_brate_buf, - st->last_active_brate_fx ); + cng_params_upd_fx( lsp_new, hLPDmem->old_exc+L_EXC_MEM-st->L_frame_fx, + st->L_frame_fx, &hTdCngEnc->ho_circ_ptr_fx, hTdCngEnc->ho_ener_circ_fx, + &hTdCngEnc->ho_circ_size_fx, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, + &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, + hDtxEnc->last_active_brate_fx ); } IF( EQ_16(st->L_frame_fx,L_FRAME)) { /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st->lsp_old16k_fx, &(st->ho_lsp_circ2_fx[(st->ho_circ_ptr_fx)*M]), M ); + Copy( st->lsp_old16k_fx, &(hTdCngEnc->ho_lsp_circ2_fx[(hTdCngEnc->ho_circ_ptr_fx)*M]), M ); } /* Set 16k LSP flag for CNG buffer */ - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 1; + hTdCngEnc->ho_16k_lsp_fx[hTdCngEnc->ho_circ_ptr_fx] = 1; move16(); if ( EQ_16(st->L_frame_fx,L_FRAME)) { - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 0; + hTdCngEnc->ho_16k_lsp_fx[hTdCngEnc->ho_circ_ptr_fx] = 0; move16(); } /* efficient DTX hangover control */ - IF ( GT_16(st->burst_ho_cnt_fx, 1)) + IF ( GT_16(hTdCngEnc->burst_ho_cnt_fx, 1)) { dtx_hangover_control_fx( st, lsp_new ); } @@ -581,7 +542,7 @@ void core_encode_openloop( /*o: lsf_uq_rf Qx2.56*/ /* first stage VQ, 8 bits; reuse TCX high rate codebook */ - st->rf_indx_lsf[0][0] = vlpc_1st_cod(lsf_uq_rf, lsf_q_1st_rf, w_rf, st->rf_mode); + hRF->rf_indx_lsf[0][0] = vlpc_1st_cod(lsf_uq_rf, lsf_q_1st_rf, w_rf, st->rf_mode); /*v_sub(lsf_uq_rf, lsf_q_1st_rf, lsf_q_d_rf, M);*/ FOR (i=0; irf_indx_lsf[0][1]); + closest_centroid_rf(lsf_q_d_rf, w_rf, lsf_q_diff_cb_8b_rf, (1<<8), M, &hRF->rf_indx_lsf[0][1]); /*i: lsf_q_d_rf in Q6 */ /*o: quantization index Q0 */ @@ -601,7 +562,7 @@ void core_encode_openloop( /*v_add(lsf_q_1st_rf, lsf_q_diff_cb_8b_rf + M * st->rf_indx_lsf[0][1], lsf_q_rf, M);*/ FOR (i=0; irf_indx_lsf[0][1]]; /*tmp = quantized lsf_q_d_rf in Q6*/ + tmp = lsf_q_diff_cb_8b_rf[i+ M* hRF->rf_indx_lsf[0][1]]; /*tmp = quantized lsf_q_d_rf in Q6*/ tmp = shr(mult_r(tmp,20972),4); /* bring lsf_q_d_rf to Qx2.56 for addition */ lsf_q_rf[i] = add(lsf_q_1st_rf[i], tmp); } @@ -618,9 +579,9 @@ void core_encode_openloop( Q_lsf_tcxlpc( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, rf_tcx_lpc_cdk, rf_mem_MA, GENERIC, st->Bin_E_fx, add(Q_new, Q_SCALE-2) ); /* VQ, 5+4+4 bits; reuse TCX low rate codebook */ - st->rf_indx_lsf[0][0] = param_lpc[1]; - st->rf_indx_lsf[0][1] = param_lpc[2]; - st->rf_indx_lsf[0][2] = param_lpc[3]; + hRF->rf_indx_lsf[0][0] = param_lpc[1]; + hRF->rf_indx_lsf[0][1] = param_lpc[2]; + hRF->rf_indx_lsf[0][2] = param_lpc[3]; } IF (EQ_16(st->core_fx, ACELP_CORE)) @@ -640,39 +601,39 @@ void core_encode_openloop( /* Configure partial copy estimation of the current n-th frame to be packed in future with n+fec_offset frame */ /* o: rf_frame_type, o: rf_target_bits */ - BITS_ALLOC_ACELP_config_rf( coder_type, st->rf_tilt_buf, &st->rf_frame_type, &st->rf_target_bits, st->nb_subfr, st->rf_fec_indicator, pitch_buf ); + BITS_ALLOC_ACELP_config_rf( coder_type, hRF->rf_tilt_buf, &hRF->rf_frame_type, &hRF->rf_target_bits, st->nb_subfr, st->rf_fec_indicator, pitch_buf ); /* RF frame type in the buffer */ - st->rf_indx_frametype[0] = st->rf_frame_type; - st->rf_targetbits_buff[0] = st->rf_target_bits; + hRF->rf_indx_frametype[0] = hRF->rf_frame_type; + hRF->rf_targetbits_buff[0] = hRF->rf_target_bits; - IF( NE_16(st->rf_frame_type,RF_NO_DATA)) + IF( NE_16(hRF->rf_frame_type,RF_NO_DATA)) { /* coder_acelp_rf does the partial copy encoding based on the rf frame type chosen for the RF encoding */ - coder_acelp_rf(&(st->acelp_cfg_rf), coder_type, Aw, Aq_rf, st->speech_enc_pe, voicing, pitch, - stab_fac_rf, st, st->rf_target_bits, st->rf_frame_type, exc_rf, syn_rf, Q_new, shift); + coder_acelp_rf(&(st->acelp_cfg_rf), coder_type, Aw, Aq_rf, st->speech_enc_pe, st->voicing_fx, st->pitch_fx, + stab_fac_rf, st, hRF->rf_target_bits, hRF->rf_frame_type, exc_rf, syn_rf, Q_new, shift); } } ELSE { - st->rf_clas[0] = st->clas_fx; + hRF->rf_clas[0] = st->clas_fx; move16(); - st->rf_gain_tcx[0] = param_core[0]; + hRF->rf_gain_tcx[0] = param_core[0]; move16(); /* attenuate somewhat the gain for onset when the correlation with previous frame is too low: avoid preecho */ - tmp = mult_r(shl(st->rf_gain_tcx[1], 1), 26214/*0.8f Q15*/); + tmp = mult_r(shl(hRF->rf_gain_tcx[1], 1), 26214/*0.8f Q15*/); test(); test(); - IF( (st->rf_gain_tcx[1] != 0) && (GT_16(st->rf_gain_tcx[0], tmp))&&(LE_16(st->tcxltp_gain,6554/*0.2 Q15*/))) + IF( (hRF->rf_gain_tcx[1] != 0) && (GT_16(hRF->rf_gain_tcx[0], tmp))&&(LE_16(hTcxEnc->tcxltp_gain,6554/*0.2 Q15*/))) { - st->rf_gain_tcx[0] = tmp; + hRF->rf_gain_tcx[0] = tmp; move16(); if( GT_16(tmp, 127)) { - st->rf_gain_tcx[0] = 127; + hRF->rf_gain_tcx[0] = 127; move16(); } } @@ -691,12 +652,12 @@ void core_encode_openloop( IF( (EQ_16(st->core_fx, TCX_20_CORE) )/*(st->core == TCX_20_CORE)*/ && (EQ_16(st->last_core_fx,TCX_20_CORE) )/*&&(st->last_core == TCX_20_CORE)*/ - && (EQ_16(st->rf_second_last_core, TCX_20_CORE) )/*&& (st->rf_second_last_core == TCX_20_CORE)*/ - && ( (LE_16(st->tcxltp_pitch_int, shr(st->L_frame_fx, 1)) ) || ( LE_16(st->tcxltp_gain, 13107/*0.4f Q15*/) ) )/*&& ((st->tcxltp_pitch_int <= 0.5f*st->L_frame) || ( st->tcxltp_gain <= 0.4f))*/ - && (EQ_16(st->tcxltp_pitch_int, st->rf_tcxltp_pitch_int_past) )/*&& (st->tcxltp_pitch_int == st->rf_tcxltp_pitch_int_past)*/ - && (st->rf_last_tns_active == 0)/*!st->rf_last_tns_active*/ - && (st->rf_second_last_tns_active == 0)/*!st->rf_second_last_tns_active*/ - && ( (st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0]) == 0)/*!(st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0])*/ + && (EQ_16(hRF->rf_second_last_core, TCX_20_CORE) )/*&& (st->rf_second_last_core == TCX_20_CORE)*/ + && ( (LE_16(hTcxEnc->tcxltp_pitch_int, shr(st->L_frame_fx, 1)) ) || ( LE_16(hTcxEnc->tcxltp_gain, 13107/*0.4f Q15*/) ) )/*&& ((st->tcxltp_pitch_int <= 0.5f*st->L_frame) || ( st->tcxltp_gain <= 0.4f))*/ + && (EQ_16(hTcxEnc->tcxltp_pitch_int, hRF->rf_tcxltp_pitch_int_past) )/*&& (st->tcxltp_pitch_int == st->rf_tcxltp_pitch_int_past)*/ + && (hRF->rf_last_tns_active == 0)/*!st->rf_last_tns_active*/ + && (hRF->rf_second_last_tns_active == 0)/*!st->rf_second_last_tns_active*/ + && ( (st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns[0]) == 0)/*!(st->hTcxCfg->fIsTNSAllowed & st->fUseTns[0])*/ ) { rf_PLC_Mode = 1; @@ -707,7 +668,7 @@ void core_encode_openloop( test(); test(); test(); - IF ( ((LE_16(st->clas_fx, UNVOICED_TRANSITION))||(LE_16(st->last_clas_fx,UNVOICED_TRANSITION))||(LE_16(st->tcxltp_gain,13107/*0.4f Q15*/))) + IF ( ((LE_16(st->clas_fx, UNVOICED_TRANSITION))||(LE_16(st->last_clas_fx,UNVOICED_TRANSITION))||(LE_16(hTcxEnc->tcxltp_gain,13107/*0.4f Q15*/))) && NE_16(st->last_core_fx, -1) ) { rf_PLC_Mode = st->last_core_fx; @@ -720,9 +681,9 @@ void core_encode_openloop( test(); test(); test(); - IF( rf_PLC_Mode == 0 && st->rf_gain_tcx[1] != 0 && - ( (st->transientDetection.transientDetector.bIsAttackPresent != 0 && LT_16(st->rf_gain_tcx[0], mult_r(st->rf_gain_tcx[1], 31785/*0.97f Q15*/)) ) || - LT_16(st->rf_gain_tcx[0], mult_r(st->rf_gain_tcx[1], 29491/*0.90f Q15*/)) ) + IF( rf_PLC_Mode == 0 && hRF->rf_gain_tcx[1] != 0 && + ( (st->transientDetection.transientDetector.bIsAttackPresent != 0 && LT_16(hRF->rf_gain_tcx[0], mult_r(hRF->rf_gain_tcx[1], 31785/*0.97f Q15*/)) ) || + LT_16(hRF->rf_gain_tcx[0], mult_r(hRF->rf_gain_tcx[1], 29491/*0.90f Q15*/)) ) ) { TD_mode = 0; @@ -733,26 +694,26 @@ void core_encode_openloop( } /* updates */ - st->rf_tcxltp_pitch_int_past = st->tcxltp_pitch_int; + hRF->rf_tcxltp_pitch_int_past = hTcxEnc->tcxltp_pitch_int; move16(); - st->rf_second_last_tns_active = st->rf_last_tns_active; + hRF->rf_second_last_tns_active = hRF->rf_last_tns_active; move16(); - st->rf_last_tns_active = (st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0]); + hRF->rf_last_tns_active = (st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns[0]); move16(); - st->rf_second_last_core = st->last_core_fx; + hRF->rf_second_last_core = st->last_core_fx; move16(); - st->rf_tcxltp_param[0] = st->tcxltp_param[1]; + hRF->rf_tcxltp_param[0] = hTcxEnc->tcxltp_param[1]; move16(); /* Configure partial copy estimation of the current n-th frame to be packed in future with n+fec_offset frame */ /* o: rf_frame_type, o: rf_target_bits */ - BITS_ALLOC_TCX_config_rf( &st->rf_frame_type, &st->rf_target_bits, rf_PLC_Mode, coder_type, st->last_core_fx, TD_mode); + BITS_ALLOC_TCX_config_rf( &hRF->rf_frame_type, &hRF->rf_target_bits, rf_PLC_Mode, coder_type, st->last_core_fx, TD_mode); /* RF frame type in the buffer */ - st->rf_indx_frametype[0] = st->rf_frame_type; + hRF->rf_indx_frametype[0] = hRF->rf_frame_type; move16(); - st->rf_targetbits_buff[0] = st->rf_target_bits; + hRF->rf_targetbits_buff[0] = hRF->rf_target_bits; move16(); } @@ -769,7 +730,7 @@ void core_encode_openloop( * * Determine a set of closest VQ centroids for a given input *-------------------------------------------------------------------*/ -void closest_centroid_rf( +static void closest_centroid_rf( const Word16 *data, /* i : input data Qx */ const Word16 *weights, /* i : weights */ const Word16 *quantizer, /* i : quantizer table Qx */ @@ -816,15 +777,12 @@ void closest_centroid_rf( void core_acelp_tcx20_switching( Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 vad_flag, - Word16 sp_aud_decision0, - Word16 non_staX, - Word16 *pitch, /* i : open-loop pitch values for quantiz. */ - Word16 *pitch_fr, /* i/o: fraction pitch values */ - Word16 *voicing_fr, /* i/o: fractional voicing values */ - const Word16 currFlatness, /* i : flatness */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - const Word16 stab_fac, /* i : LP filter stability */ + Word16 non_staX, /* i : unbound non-stationarity for sp/mu clas */ + Word16 *pitch_fr, /* i/o: fraction pitch values */ + Word16 *voicing_fr, /* i/o: fractional voicing values */ + const Word16 currFlatness, /* i : flatness */ + const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ + const Word16 stab_fac, /* i : LP filter stability */ Word16 Q_new, Word16 shift ) @@ -852,11 +810,13 @@ void core_acelp_tcx20_switching( Word32 gain, signal, noise; Word16 A_q_tcx[(NB_SUBFR16k+1)*(M+1)]; Word16 snr_tcx, snr_acelp, dsnr; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; /* Check minimum pitch for quantization */ FOR( i = 0; i < 3; i++ ) { - tmp16 = pitch[i]; + tmp16 = st->pitch_fx[i]; move16(); /* check minimum pitch for quantization */ if (LT_16(tmp16, PIT_MIN_SHORTER)) @@ -871,12 +831,12 @@ void core_acelp_tcx20_switching( /*pitch[i] = (short)(pitch[i] * 1.25f + 0.5f);*/ tmp16 = add(tmp16, s); } - pitch[i] = tmp16; + st->pitch_fx[i] = tmp16; move16(); } IF (st->narrowBand != 0) { - pitchDoubling_det( st->wspeech_enc, pitch, pitch_fr, voicing_fr ); + pitchDoubling_det( st->wspeech_enc, st->pitch_fx, pitch_fr, voicing_fr ); } E_LPC_f_lsp_a_conversion(lsp_mid, A_q_tcx, M); @@ -884,24 +844,24 @@ void core_acelp_tcx20_switching( /* LTP */ - tcx_ltp_encode( st->tcxltp, + tcx_ltp_encode(hTcxEnc->tcxltp, st->tcxonly, TCX_20, st->L_frame_fx, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, - st->speech_ltp + st->encoderLookahead_enc, + hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->wspeech_enc + st->encoderLookahead_enc, - pitch[1], - st->tcxltp_param, - &st->tcxltp_bits, - &st->tcxltp_pitch_int, - &st->tcxltp_pitch_fr, - &st->tcxltp_gain, - &st->tcxltp_pitch_int_past, - &st->tcxltp_pitch_fr_past, - &st->tcxltp_gain_past, - &st->tcxltp_norm_corr_past, + st->pitch_fx[1], + hTcxEnc->tcxltp_param, + &hTcxEnc->tcxltp_bits, + &hTcxEnc->tcxltp_pitch_int, + &hTcxEnc->tcxltp_pitch_fr, + &hTcxEnc->tcxltp_gain, + &hTcxEnc->tcxltp_pitch_int_past, + &hTcxEnc->tcxltp_pitch_fr_past, + &hTcxEnc->tcxltp_gain_past, + &hTcxEnc->tcxltp_norm_corr_past, st->last_core_fx, st->pit_min, st->pit_fr1, @@ -928,12 +888,12 @@ void core_acelp_tcx20_switching( L_frame = st->L_frame_fx; move16(); - tcx_offset = st->tcx_cfg.tcx_offset; + tcx_offset = st->hTcxCfg->tcx_offset; move16(); target = L_add(0x14C315C, 0); /* 1000.f * log2(10)/10 (15Q16) */ test(); - if (EQ_32(st->sr_core, 16000)||EQ_32(st->sr_core,12800)) + if (EQ_32(st->sr_core, INT_FS_16k)||EQ_32(st->sr_core, INT_FS_12k8)) { target = L_add(0x11A5D28, 0); /* 850.f * log2(10)/10 (15Q16) */ } @@ -945,13 +905,13 @@ void core_acelp_tcx20_switching( IF (st->last_core_fx == ACELP_CORE) { L_frame = add(L_frame, tcx_offset); - tcx_offset = s_min(st->tcx_cfg.lfacNext, 0); + tcx_offset = s_min(st->hTcxCfg->lfacNext, 0); L_frame = sub(L_frame, tcx_offset); } L_frame_4 = shr(L_frame, 2); - overlap = st->tcx_cfg.tcx_mdct_window_delay; + overlap = st->hTcxCfg->tcx_mdct_window_delay; move16(); - Copy(st->speech_ltp + sub(tcx_offset, shr(overlap, 1)), xn_buf, add(L_frame, overlap)); + Copy(hTcxEnc->speech_ltp + sub(tcx_offset, shr(overlap, 1)), xn_buf, add(L_frame, overlap)); tmp16 = shr(overlap, 1); IF (EQ_16(st->last_core_fx,ACELP_CORE)) @@ -965,30 +925,30 @@ void core_acelp_tcx20_switching( { FOR (i = 0; i < tmp16; i++) { - xn_buf[i] = mult_r(xn_buf[i], st->tcx_cfg.tcx_mdct_window[i].v.im); + xn_buf[i] = mult_r(xn_buf[i], st->hTcxCfg->tcx_mdct_window[i].v.im); move16(); } FOR ( ; i < overlap; i++) { - xn_buf[i] = mult_r(xn_buf[i], st->tcx_cfg.tcx_mdct_window[overlap-1-i].v.re); + xn_buf[i] = mult_r(xn_buf[i], st->hTcxCfg->tcx_mdct_window[overlap-1-i].v.re); move16(); } } FOR (i = 0; i < tmp16; i++) { - xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->tcx_cfg.tcx_mdct_window[i].v.re); + xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->hTcxCfg->tcx_mdct_window[i].v.re); move16(); } FOR ( ; i < overlap; i++) { - xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->tcx_cfg.tcx_mdct_window[overlap-1-i].v.im); + xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->hTcxCfg->tcx_mdct_window[overlap-1-i].v.im); move16(); } x_e = 16; move16(); - TCX_MDCT(xn_buf, x, &x_e, overlap, sub(L_frame, overlap), overlap); + TCX_MDCT(xn_buf, x, &x_e, overlap, sub(L_frame, overlap), overlap, st->element_mode); tmp16 = mult_r(shl(L_frame, 5), 29309/*16*0.0559017 Q15*/); /* L_frame / sqrt(2*NORM_MDCT_FACTOR); Q9 */ FOR (i = 0; i < L_frame; i++) { @@ -999,7 +959,7 @@ void core_acelp_tcx20_switching( weight_a_fx(A_q_tcx, Ap, st->gamma, M); - lpc2mdct(Ap, M, gainlpc, gainlpc_e, NULL, NULL); + lpc2mdct(Ap, M, gainlpc, gainlpc_e, NULL, NULL, FDNS_NPTS, 0); mdct_shaping(x, L_frame, gainlpc, gainlpc_e); @@ -1159,7 +1119,7 @@ void core_acelp_tcx20_switching( move16(); FOR (i = 0; i < st->L_frame_fx; i += L_SUBFR) { - IF ( EQ_32( st->sr_core, 16000 )) + IF ( EQ_32( st->sr_core, INT_FS_16k)) { T0 = shr(add( add(pitch_fr[mult_r(i2,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/)], shr(pitch_fr[mult_r(i2,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/)], 2)) , (1 << 5) ), 6); } @@ -1194,12 +1154,12 @@ void core_acelp_tcx20_switching( offset = -211332072l/*-12.5963731051575616 Q24*/; /* 10*log10(0.055f) */ move32(); - if (EQ_32(st->sr_core, 16000)) + if (EQ_32(st->sr_core, INT_FS_16k)) { offset = -173847554l/*-10.362121726544446 Q24*/; /* 10*log10(0.092f) */ move32(); } - if (EQ_32(st->sr_core, 12800)) + if (EQ_32(st->sr_core, INT_FS_12k8)) { offset = -206216813l/*-12.291479883578557 Q24*/; /* 10*log10(0.059f) */ move32(); @@ -1223,26 +1183,19 @@ void core_acelp_tcx20_switching( /* hysteresis for very small SNR differences between ACELP and TCX */ /* try to use TCX instead of ACELP on temporally stationary frames */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test();test();test(); if ((GT_16(snr_acelp, snr_tcx))&& (LT_16(snr_acelp, add(snr_tcx, 512/*2.0f Q8*/)) ) && - (LT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) || EQ_16(stab_fac, 0x7fff) || (EQ_32(st->sr_core, 12800) && EQ_16(sp_aud_decision0,1) && LT_16(add(st->prevTempFlatness_fx, currFlatness), 2560/*20.f Q7*/) )) && - (LE_16(st->acelpFramesCount, 6) )) + (LT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) || EQ_16(stab_fac, 0x7fff) || + (EQ_32(st->sr_core, INT_FS_12k8) && EQ_16(st->sp_aud_decision0,1) && LT_16(add(st->prevTempFlatness_fx, currFlatness), 2560/*20.f Q7*/) )) && + (LE_16(st->acelpFramesCount, 6) )) { dsnr = -512/*-2.0f Q8*/; move16(); } /* try to use ACELP instead of TCX on transient and "buzzy" frames */ - test(); - test(); - test(); + test();test();test(); if ((LT_16(snr_acelp, snr_tcx))&& (GT_16(snr_acelp, sub(snr_tcx, 512/*2.0f Q8*/)) ) && (GT_16(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) ) && @@ -1259,17 +1212,10 @@ void core_acelp_tcx20_switching( tmp16 = add(tmp16, shr(voicing_fr[i],2)); /*mean of voicing_fr in Q15*/ } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if( EQ_32(st->sr_core, 12800)&&(offset_tcx<0x18950F)&>_16(non_staX,1280 /*5.0f Q8*/ )&&(snr_acelp>=snr_tcx-1024 /*4.0f in Q8*/)&&GE_16(st->acelpFramesCount,1)&&((GT_16(st->lps_fx,st->lpm_fx)&&GE_16(tmp16,9830))||(GE_16(st->acelpFramesCount,6)&&(st->lps_fx>st->lpm_fx-768)))&&(sp_aud_decision0==0)&&vad_flag!=0) + test();test();test();test(); + test();test();test();test();test();test(); + if( EQ_32(st->sr_core, INT_FS_12k8) && (offset_tcx<0x18950F) && GT_16(non_staX,1280 /*5.0f Q8*/ ) && (snr_acelp>=snr_tcx-1024 /*4.0f in Q8*/) && GE_16(st->acelpFramesCount,1) && ((GT_16(hSpMusClas->lps_fx, hSpMusClas->lpm_fx) && GE_16(tmp16,9830)) + || (GE_16(st->acelpFramesCount,6) && (hSpMusClas->lps_fx> hSpMusClas->lpm_fx-768))) && (st->sp_aud_decision0==0) && st->vad_flag!=0) { /* Fine tuned across various databases based on various metrics to detect TCX frames in speech.*/ dsnr = 1024; @@ -1279,7 +1225,7 @@ void core_acelp_tcx20_switching( IF ( st->flag_noisy_speech_snr ) { test(); - IF ( vad_flag || st->Opt_DTX_ON_fx ) + IF ( st->vad_flag || st->Opt_DTX_ON_fx ) { dsnr = add(dsnr, 512/*2.0f Q8*/); } @@ -1289,13 +1235,11 @@ void core_acelp_tcx20_switching( } } - test(); - test(); - test(); - test(); - test(); - test(); - if (EQ_32(st->sr_core, 12800)&&(LT_16(non_staX,512/*2.0f Q8*/)||(st->flag_noisy_speech_snr==0&&EQ_16(vad_flag,1)&&(offset_tcx==L_add(0xFFD57AB5,0))&&GE_16(st->acelpFramesCount,6)))&&(st->last_core_fx==ACELP_CORE||st->last_core_fx==TCX_20_CORE)) + test();test();test(); + test();test();test(); + if (EQ_32(st->sr_core, INT_FS_12k8) && (LT_16(non_staX,512/*2.0f Q8*/) || + (st->flag_noisy_speech_snr==0 && EQ_16(st->vad_flag,1) && (offset_tcx==L_add(0xFFD57AB5,0)) && GE_16(st->acelpFramesCount,6))) && + (st->last_core_fx==ACELP_CORE || st->last_core_fx==TCX_20_CORE)) { st->core_fx = st->last_core_fx; } @@ -1332,6 +1276,7 @@ void core_acelp_tcx20_switching( st->prevTempFlatness_fx = currFlatness; move16(); + return; } @@ -1342,14 +1287,15 @@ void core_acelp_tcx20_switching( * * configure channel aware mode *-------------------------------------------------------------------*/ -void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, - Word16 *tilt_code, - Word16 *rf_frame_type, - Word16 *rf_target_bits, - Word16 nb_subfr - , Word16 rf_fec_indicator - , Word16 *pitch_buf - ) +static void BITS_ALLOC_ACELP_config_rf( + const Word16 coder_type, + Word16 *tilt_code, + Word16 *rf_frame_type, + Word16 *rf_target_bits, + Word16 nb_subfr, + Word16 rf_fec_indicator, + Word16 *pitch_buf +) { Word16 mean_tc, min_tilt_code, max_tilt_code; Word16 nrgMode, ltfMode, ltpMode, gainsMode; @@ -1540,7 +1486,7 @@ void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, * * configure channel aware mode *-------------------------------------------------------------------*/ -void BITS_ALLOC_TCX_config_rf( +static void BITS_ALLOC_TCX_config_rf( Word16 *rf_frame_type, Word16 *rf_target_bits, Word16 PLC_Mode, diff --git a/lib_enc/core_enc_reconf.c b/lib_enc/core_enc_reconf.c index f616d3d..9c255e5 100644 --- a/lib_enc/core_enc_reconf.c +++ b/lib_enc/core_enc_reconf.c @@ -2,13 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include -#include "prot_fx.h" +#include #include "options.h" +#include "prot_fx.h" #include "cnst_fx.h" -#include "stl.h" #include "rom_com_fx.h" #include "rom_enc_fx.h" @@ -17,53 +14,68 @@ * ~~~~~~~~~~~~~~~~~~~ * * - reconfig core coder when switching to another frame type * *-----------------------------------------------------------------*/ -void core_coder_reconfig(Encoder_State_fx *st) +void core_coder_reconfig( + Encoder_State_fx* st, + const Word32 last_total_brate +) { - Word16 i; - - + Word16 i, bwidth, index; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /*Configuration of ACELP*/ BITS_ALLOC_init_config_acelp(st->total_brate_fx, st->narrowBand, st->nb_subfr, &(st->acelp_cfg)); /*Configuration of partial copy*/ - st->acelp_cfg_rf.mode_index = 1; - st->acelp_cfg_rf.midLpc = 0; - st->acelp_cfg_rf.midLpc_enable = 0; - st->acelp_cfg_rf.pre_emphasis = 0; - st->acelp_cfg_rf.formant_enh = 1; - st->acelp_cfg_rf.formant_tilt = 1; - st->acelp_cfg_rf.voice_tilt = 1; - st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; - st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; + if (st->Opt_RF_ON) + { + st->hRF->acelp_cfg_rf.mode_index = 1; + st->hRF->acelp_cfg_rf.midLpc = 0; + st->hRF->acelp_cfg_rf.midLpc_enable = 0; + st->hRF->acelp_cfg_rf.pre_emphasis = 0; + st->hRF->acelp_cfg_rf.formant_enh = 1; + st->hRF->acelp_cfg_rf.formant_tilt = 1; + st->hRF->acelp_cfg_rf.voice_tilt = 1; + st->hRF->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; + st->hRF->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; + move16(); move16(); move16(); move16(); + move16(); move16(); move16(); move16(); + } st->nb_bits_header_tcx = 2; /*Mode(1) + Last_mode(1)*/ move16(); - IF (st->tcxonly == 0) + + IF(EQ_16(st->element_mode, IVAS_CPE_MDCT)) + { + st->nb_bits_header_tcx = 2; /* signal class */ + } + ELSE IF(st->tcxonly == 0) { move16(); st->nb_bits_header_ace = 4; st->nb_bits_header_tcx = st->nb_bits_header_ace; move16(); - if ( st->tcx_cfg.lfacNext<=0 ) + IF (st->hTcxCfg != NULL) { - /*st->nb_bits_header_ace--;*/ /*No Last_mode*/ - st->nb_bits_header_ace = sub(st->nb_bits_header_ace,1); + if (st->hTcxCfg->lfacNext <= 0) + { + /*st->nb_bits_header_ace--;*/ /*No Last_mode*/ + st->nb_bits_header_ace = sub(st->nb_bits_header_ace, 1); + } } } - if ( st->tcxonly) + if (st->tcxonly) { - st->nb_bits_header_tcx = add(st->nb_bits_header_tcx,2); + st->nb_bits_header_tcx = add(st->nb_bits_header_tcx, 2); } /*Switch off TCX or ACELP?*/ - IF( EQ_32(st->sr_core,12800)) + IF(EQ_32(st->sr_core, INT_FS_12k8)) { st->acelpEnabled = 0; move16(); - if( s_and(st->restrictedMode,1) != 0) + if (s_and(st->restrictedMode, 1) != 0) { st->acelpEnabled = 1; move16(); @@ -71,7 +83,7 @@ void core_coder_reconfig(Encoder_State_fx *st) st->tcx20Enabled = 0; move16(); - if( s_and(st->restrictedMode,2) != 0) + if (s_and(st->restrictedMode, 2) != 0) { st->tcx20Enabled = 1; @@ -85,17 +97,20 @@ void core_coder_reconfig(Encoder_State_fx *st) st->currEnergyHF_e_fx = 17; /*Sanity check : don't need to be instrumented*/ - if(st->tcxonly==0) + if (st->tcxonly == 0) { - assert(st->acelpEnabled || st->tcx20Enabled || st->frame_size_index==0); + assert(st->acelpEnabled || st->tcx20Enabled || st->frame_size_index == 0); } else { - assert(st->tcx10Enabled || st->tcx20Enabled || st->frame_size_index==0); + assert(st->tcx10Enabled || st->tcx20Enabled || st->frame_size_index == 0); } /* TCX-LTP */ - st->tcxltp = getTcxLtp(st->sr_core); + IF(st->hTcxEnc != NULL) + { + hTcxEnc->tcxltp = getTcxLtp(st->sr_core); + } /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ @@ -103,70 +118,77 @@ void core_coder_reconfig(Encoder_State_fx *st) move16(); test(); - if( (LE_32(st->total_brate_fx, 9600))&&(EQ_32(st->sr_core,12800))) + if ((LE_32(st->total_brate_fx, ACELP_9k60)) && (EQ_32(st->sr_core, INT_FS_12k8))) { st->acelp_autocorr = 0; move16(); } + /*Get bandwidth mode*/ + IF(st->narrowBand) { - Word16 bandwidth_mode; - - /*Get bandwidth mode*/ - IF(st->narrowBand) - { - bandwidth_mode=0; - } - ELSE IF( LE_32(st->sr_core, 16000)) - { - move16(); - bandwidth_mode=1; - } - ELSE - { - move16(); - bandwidth_mode=2; - } + move16(); + bwidth = 0; + } + ELSE IF(LE_32(st->sr_core, INT_FS_16k)) + { + move16(); + bwidth = 1; + } + ELSE + { + move16(); + bwidth = 2; + } /*Scale TCX for non-active frames to adjust loudness with ACELP*/ - st->tcx_cfg.na_scale=32767/*1.0f Q15*/; + IF (st->hTcxCfg != NULL) + { + st->hTcxCfg->na_scale = 32767/*1.0f Q15*/; test(); - IF( LT_16(bandwidth_mode,2)&&(st->tcxonly==0)) + IF(LT_16(bwidth, 2) && (st->tcxonly == 0)) { - const Word16 scaleTableSize = sizeof (scaleTcxTable) / sizeof (scaleTcxTable[0]); + /*const Word16 scaleTableSize = sizeof(scaleTcxTable) / sizeof(scaleTcxTable[0]);*/ - FOR (i = 0 ; i < scaleTableSize ; i++) + FOR(i = 0; i < SIZE_SCALE_TABLE_TCX; i++) { test(); test(); - IF ( EQ_16(bandwidth_mode, scaleTcxTable[i].bwmode)&& - GE_32(st->total_brate_fx, scaleTcxTable[i].bitrateFrom) && - LT_32(st->total_brate_fx, scaleTcxTable[i].bitrateTo) ) + IF(EQ_16(bwidth, scaleTcxTable[i].bwmode) && + GE_32(st->total_brate_fx, scaleTcxTable[i].bitrateFrom) && + LT_32(st->total_brate_fx, scaleTcxTable[i].bitrateTo)) { - if( st->rf_mode ) + if (st->rf_mode) { i--; } move16(); - st->tcx_cfg.na_scale = scaleTcxTable[i].scale; + st->hTcxCfg->na_scale = scaleTcxTable[i].scale; BREAK; } } } } - st->enableTcxLpc = 0; move16(); - - test(); - if ( EQ_16(st->lpcQuantization, 1)&&(LE_32(st->total_brate_fx,LOWRATE_TCXLPC_MAX_BR)||st->rf_mode!=0)) + IF (GT_16(st->element_mode, IVAS_SCE)) { - st->enableTcxLpc = 1; + test();test(); + st->enableTcxLpc = (EQ_16(st->lpcQuantization, 1) && (LE_32(st->total_brate_fx, LOWRATE_TCXLPC_MAX_BR_CPE) || st->rf_mode)); move16(); } - + ELSE + { + test();test(); + if (EQ_16(st->lpcQuantization, 1) && (LE_32(st->total_brate_fx, LOWRATE_TCXLPC_MAX_BR) || st->rf_mode != 0)) + { + st->enableTcxLpc = 1; + move16(); + } + } + test(); IF ( st->ini_frame_fx == 0 || EQ_16(st->last_codec_mode, MODE1)) { st->envWeighted = 0; @@ -182,7 +204,7 @@ void core_coder_reconfig(Encoder_State_fx *st) { FOR (i = 0; i < MAX_TEC_SMOOTHING_DEG; i++) { - st->tecEnc.loBuffer[i] = 0; + st->hTECEnc->loBuffer[i] = 0; move16(); } } @@ -209,8 +231,8 @@ void core_coder_reconfig(Encoder_State_fx *st) test(); test(); test(); - if( (EQ_32(st->total_brate_fx, 9600))||(EQ_32(st->total_brate_fx,16400))|| - (EQ_32(st->total_brate_fx, 24400))) + test(); + if( (EQ_32(st->total_brate_fx, ACELP_9k60) || EQ_32(st->total_brate_fx, ACELP_16k40) || EQ_32(st->total_brate_fx, ACELP_24k40)) && EQ_16(st->element_mode, EVS_MONO) ) { move16(); st->glr = 1; @@ -221,57 +243,68 @@ void core_coder_reconfig(Encoder_State_fx *st) st->nb_bits_header_ace = add(st->nb_bits_header_ace, G_LPC_RECOVERY_BITS); } - - test(); - IF (EQ_16(st->bwidth_fx, NB)||EQ_16(st->bwidth_fx,WB)) + IF (hTcxEnc != NULL) { test(); - IF (st->rf_mode==0) + IF(EQ_16(st->bwidth_fx, NB) || EQ_16(st->bwidth_fx, WB)) { - st->nmStartLine = startLineWB[s_min((sizeof(startLineWB)/sizeof(startLineWB[0])-1), s_max(3, st->frame_size_index))]; - move16(); - } - ELSE - { - st->nmStartLine = startLineWB[s_min((sizeof(startLineWB)/sizeof(startLineWB[0])-1), s_max(3, st->frame_size_index-1))]; + test(); + IF(st->rf_mode == 0) + { + index = s_min(N_TCX_STARTLINE_NOISE_WB - 1, s_max(3, st->frame_size_index)); + } + ELSE + { + index = s_min(N_TCX_STARTLINE_NOISE_WB - 1, s_max(3, st->frame_size_index - 1)); + } + hTcxEnc->nmStartLine = startLineWB[index]; move16(); } - } - ELSE /* (st->bwidth_fx == SWB || st->bwidth_fx == FB) */ - { - IF (st->rf_mode==0) + ELSE /* (st->bwidth_fx == SWB || st->bwidth_fx == FB) */ { - st->nmStartLine = startLineSWB[s_min((sizeof(startLineSWB)/sizeof(startLineSWB[0])-1), sub(s_max(3, st->frame_size_index), 3))]; - move16(); - } - ELSE { - st->nmStartLine = startLineSWB[s_min((sizeof(startLineSWB)/sizeof(startLineSWB[0])-1), sub(s_max(3, st->frame_size_index-1), 3))]; + IF(st->rf_mode == 0) + { + index = s_min(N_TCX_STARTLINE_NOISE_SWB - 1, sub(s_max(3, st->frame_size_index), 3)); + } + ELSE + { + index = s_min(N_TCX_STARTLINE_NOISE_SWB - 1, sub(s_max(3, st->frame_size_index - 1), 3)); + } + test();test(); + if (GE_32(st->total_brate_fx, IVAS_96k) && LE_32(st->total_brate_fx, IVAS_192k) && GT_16(st->element_mode, IVAS_SCE)) + { + index = sub(index, 1); + } + hTcxEnc->nmStartLine = startLineSWB[index]; move16(); + if (EQ_32(st->total_brate_fx, IVAS_48k) && EQ_16(st->element_mode, IVAS_CPE_MDCT) && LT_16(add(hTcxEnc->nmStartLine, shl(hTcxEnc->nmStartLine,2)) , shl(st->L_frame_fx, 2)) ) + { + hTcxEnc->nmStartLine = shr(add(hTcxEnc->nmStartLine, shl(hTcxEnc->nmStartLine, 2)), 2); /* low-rate stereo is more efficient than dual-mono due to stereo processing */ + } } } - test(); - test(); - test(); - test(); - test(); - IF ( (LT_32(st->total_brate_fx, ACELP_24k40))&&((GT_32(st->total_brate_fx,st->last_total_brate_fx))||(EQ_16(st->last_codec_mode,MODE1)))) + IF(hTcxEnc != NULL) { - /* low-freq memQuantZeros must be reset partially if bitrate increased */ - FOR (i = 0; i < st->nmStartLine; i++) + test(); test(); + test(); test(); test(); + IF((LT_32(st->total_brate_fx, ACELP_24k40)) && ((GT_32(st->total_brate_fx, st->last_total_brate_fx)) || (EQ_16(st->last_codec_mode, MODE1)))) { - st->memQuantZeros[i] = 0; - move16(); + /* low-freq memQuantZeros must be reset partially if bitrate increased */ + FOR(i = 0; i < hTcxEnc->nmStartLine; i++) + { + hTcxEnc->memQuantZeros[i] = 0; + move16(); + } } - } - ELSE IF ( (GE_32(st->total_brate_fx, ACELP_24k40))&&(LE_32(st->total_brate_fx,ACELP_32k))&&(GE_32(st->last_total_brate_fx,ACELP_13k20))&&(LT_32(st->last_total_brate_fx,ACELP_24k40))) - { - FOR (i = 0; i < st->L_frame_fx; i++) /* memQuantZeros won't be updated */ + ELSE IF((GE_32(st->total_brate_fx, ACELP_24k40)) && (LE_32(st->total_brate_fx, ACELP_32k)) && (GE_32(st->last_total_brate_fx, ACELP_13k20)) && (LT_32(st->last_total_brate_fx, ACELP_24k40))) { - st->memQuantZeros[i] = 0; - move16(); + FOR(i = 0; i < st->L_frame_fx; i++) /* memQuantZeros won't be updated */ + { + hTcxEnc->memQuantZeros[i] = 0; + move16(); + } } } - } diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 315f908..68703c2 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -1,35 +1,32 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include -#include +#include #include +#include "options.h" #include "prot_fx.h" #include "basop_mpy.h" -#include "options.h" #include "cnst_fx.h" +#include "ivas_cnst.h" #include "rom_com_fx.h" -#include "stl.h" -void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, - const Word32 bitrate, - const Word16 shift) +void core_coder_mode_switch( + Encoder_State_fx *st, + const Word32 last_total_bitrate, + const Word16 MCT_flag, + const Word16 shift +) { Word16 i, fscale, switchWB; - Word16 bSwitchFromAmrwbIO; - Word16 bandwidth; + Word16 bSwitchFromAmrwbIO, tcxonly_tmp; Word32 tmp32; Word32 sr_core; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - - move16(); - move16(); - move16(); - move16(); - - bandwidth = bandwidth_in; + move16();move16(); + move16();move16(); switchWB = 0; bSwitchFromAmrwbIO = 0; @@ -39,26 +36,25 @@ void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, bSwitchFromAmrwbIO = 1; } - sr_core = getCoreSamplerateMode2(bitrate, bandwidth, st->rf_mode); + sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate_fx, st->bwidth_fx, st->flag_ACELP16k, st->rf_mode, st->is_ism_format); move16(); fscale = sr2fscale(sr_core); move16(); - IF ( s_and(s_and((Word16)GE_16(bandwidth,WB),(Word16)EQ_16(fscale,(FSCALE_DENOM*16000)/12800)),(Word16)EQ_16(fscale,st->fscale))) - { - IF ( s_or(s_and((Word16)GT_32(bitrate, 32000),(st->tcxonly==0)),s_and((Word16)LE_32(bitrate,32000),st->tcxonly!=0))) - { - move16(); - switchWB = 1; - } - } if( EQ_16(st->last_codec_mode,MODE1)) { move16(); switchWB = 1; /*force init when coming from MODE1*/ } + +#ifdef IVAS_CODE_SWITCHING + tcxonly_tmp = getTcxonly(st->element_mode, st->total_brate_fx, MCT_flag, st->is_ism_format); +#else + tcxonly_tmp = getTcxonly(st->total_brate_fx); +#endif + test(); - if( GT_32(st->last_total_brate_fx,ACELP_32k)&&LE_32(st->total_brate_fx,ACELP_32k)) + if( NE_16(tcxonly_tmp, st->tcxonly)) { move16(); switchWB = 1; /*force init when coming from MODE1*/ @@ -66,62 +62,64 @@ void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, test(); test(); - IF ( (EQ_16(fscale, st->fscale))&&(bSwitchFromAmrwbIO==0)&&(switchWB==0)) + IF ( (EQ_16(fscale, st->fscale)) && (bSwitchFromAmrwbIO==0) && (switchWB==0)) { - st->total_brate_fx = bitrate; + /*st->total_brate_fx = bitrate; */ move32(); st->sr_core = sr_core; move32(); st->L_frame_fx = extract_l(Mult_32_16(st->sr_core , 0x0290)); assert(st->L_frame_fx == st->sr_core / 50); +#ifdef IVAS_CODE_SWITCHING + st->tcxonly = getTcxonly(st->element_mode, st->total_brate_fx, MCT_flag, st->is_ism_format); +#else st->tcxonly = getTcxonly(st->total_brate_fx); - +#endif /* st->bits_frame_nominal = (int)( (float)st->L_frame_fx/(float)st->fscale ) * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f ; */ /* st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1( L_shl(st->bitrate,8), mult_r(div_s(st->fscale, shl(st->L_frame_fx,4)), FL2WORD16(FSCALE_DENOM/12800.f))), 6)); */ tmp32 = L_shl(st->total_brate_fx, 1); /* (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1(tmp32, 20972), 6)); /* 20972 = 0.01 * 64 * 32768 */ assert(st->bits_frame_nominal == (int)( (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate_fx/100.0f + 0.49f )); - st->igf = getIgfPresent(bitrate, bandwidth, st->rf_mode); + st->igf = getIgfPresent(st->element_mode, st->total_brate_fx, st->bwidth_fx, st->rf_mode); /* switch IGF configuration */ IF (st->igf) { - IGFEncSetMode( &st->hIGFEnc, st->total_brate_fx, bandwidth, st->rf_mode ); + IGFEncSetMode(st->hIGFEnc, st->total_brate_fx, st->bwidth_fx, st->element_mode, st->rf_mode); } - st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(bandwidth); + st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines(st->bwidth_fx); move16(); - st->tcx_cfg.bandwidth = getTcxBandwidth(st->bwidth_fx); + st->hTcxCfg->bandwidth = getTcxBandwidth(st->bwidth_fx); move16(); move16(); - st->tcx_cfg.tcxRateLoopOpt = 0; + st->hTcxCfg->tcxRateLoopOpt = 0; if (st->tcxonly) { move16(); - st->tcx_cfg.tcxRateLoopOpt = 2; + st->hTcxCfg->tcxRateLoopOpt = 2; } - st->tcx_cfg.ctx_hm = getCtxHm(st->total_brate_fx, st->rf_mode ); + st->hTcxCfg->ctx_hm = getCtxHm(st->element_mode, st->total_brate_fx, st->rf_mode ); move16(); - st->tcx_cfg.resq = getResq(st->total_brate_fx); + st->hTcxCfg->resq = getResq(st->total_brate_fx); move16(); - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - st->total_brate_fx, - bandwidth - ,st->rf_mode - ); + hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri(st->total_brate_fx, st->rf_mode, st->element_mode); test(); - if (st->tcx_cfg.resq != 0 && st->tcxonly == 0) + if (st->hTcxCfg->resq != 0 && st->tcxonly == 0) { - st->tcx_cfg.tcxRateLoopOpt = 1; + st->hTcxCfg->tcxRateLoopOpt = 1; move16(); } - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate_fx, st->igf); - IF (st->tcx_cfg.fIsTNSAllowed != 0) + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(st->total_brate_fx, st->igf, st->element_mode); + IF (st->hTcxCfg->fIsTNSAllowed != 0) { - InitTnsConfigs(bwMode2fs[bandwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFEnc.infoStopFrequency, st->total_brate_fx); + InitTnsConfigs(st->bwidth_fx, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate_fx, st->element_mode, MCT_flag); +#ifdef IVAS_CODE + SetAllowTnsOnWhite(st->hTcxCfg->tnsConfig, EQ_16(st->element_mode, IVAS_CPE_MDCT)); +#endif } move16(); @@ -162,17 +160,18 @@ void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, } } - st->restrictedMode = getRestrictedMode(st->total_brate_fx, 0); + st->restrictedMode = getRestrictedMode(st->element_mode, st->total_brate_fx, 0); - core_coder_reconfig( st ); + core_coder_reconfig( st, last_total_bitrate); } ELSE { - st->igf = getIgfPresent(bitrate, bandwidth, st->rf_mode); - init_coder_ace_plus(st, shift); + st->igf = getIgfPresent(st->element_mode, st->total_brate_fx, st->bwidth_fx, st->rf_mode); + init_coder_ace_plus(st, last_total_bitrate, shift, MCT_flag); } - IF( st->igf != 0 ) + test(); + IF( st->igf != 0 && st->hBWE_TD != NULL) { test(); test(); @@ -188,11 +187,11 @@ void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, } ELSE { - set16_fx( st->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st->gain_prec_swb_fx = 16384; + set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } } @@ -200,28 +199,21 @@ void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, IF ( s_and(st->envWeighted!=0, st->enableTcxLpc==0) ) { /* Unweight the envelope */ - E_LPC_lsp_unweight( - st->lsp_old_fx, - st->lsp_old_fx, - st->lsf_old_fx, - st->inv_gamma, - M - ); + E_LPC_lsp_unweight(st->lsp_old_fx, st->lsp_old_fx, st->lsf_old_fx, st->inv_gamma, M ); move16(); st->envWeighted = 0; } st->enablePlcWaveadjust = 0; move16(); - if (GE_32(bitrate, 48000)) + if (GE_32(st->total_brate_fx, HQ_48k)) { st->enablePlcWaveadjust = 1; move16(); } test(); - IF(GT_32(st->last_total_brate_fx, 32000) - || EQ_32(st->last_codec_mode,MODE1)) + IF( (GT_32(last_total_bitrate, HQ_32k) || EQ_32(st->last_codec_mode,MODE1)) && EQ_16(st->element_mode, EVS_MONO)) { move16(); st->glr_reset = 1; diff --git a/lib_enc/core_enc_updt.c b/lib_enc/core_enc_updt.c index a84a99e..f828446 100644 --- a/lib_enc/core_enc_updt.c +++ b/lib_enc/core_enc_updt.c @@ -2,21 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include #include "prot_fx.h" -#include "basop_util.h" #include "options.h" +#include "basop_util.h" #include "cnst_fx.h" -#include "stl.h" void core_encode_update(Encoder_State_fx *st ) { Word16 n; - - + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /*--------------------------------------------------------------* * Update Buffers @@ -37,27 +33,40 @@ void core_encode_update(Encoder_State_fx *st } - IF ( s_or( s_or(st->core_fx == ACELP_CORE, s_or( (Word16)EQ_32(st->core_brate_fx, SID_2k40),(Word16)EQ_32(st->core_brate_fx,FRAME_NO_DATA))),(Word16)EQ_32(st->core_fx,AMR_WB_CORE))) + IF (hTcxEnc != NULL) { - Copy(st->buf_speech_enc + st->L_frame_fx, st->buf_speech_ltp + st->L_frame_fx, st->L_frame_fx); + IF(EQ_16(st->core_fx, ACELP_CORE) || EQ_32(st->core_brate_fx, SID_2k40) || EQ_32(st->core_brate_fx, FRAME_NO_DATA) || EQ_32(st->core_fx, AMR_WB_CORE)) + { + Copy(st->buf_speech_enc + st->L_frame_fx, hTcxEnc->buf_speech_ltp + st->L_frame_fx, st->L_frame_fx); + } } - n = add(st->encoderPastSamples_enc, st->encoderLookahead_enc); - Copy(st->buf_speech_ltp+st->L_frame_fx, st->buf_speech_ltp, n); Copy(st->buf_synth+st->L_frame_fx, st->buf_synth, add(st->L_frame_fx,L_SUBFR)); + if (hTcxEnc != NULL) + { + Copy(hTcxEnc->buf_speech_ltp+st->L_frame_fx, hTcxEnc->buf_speech_ltp, n); +#ifdef IVAS_CODE + IF (NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + st->hTcxEnc->kernel_switch_corr_past = 0.f; + st->hTcxEnc->kernel_type[0] = MDCT_IV; + st->hTcxEnc->kernel_symmetry_past = 0; + st->hTcxEnc->enc_ste_pre_corr_past = 0; + move16();move16();move16();move16(); + } +#endif + } /* Update previous mode */ - move16(); - st->last_core_fx = st->core_fx; /* not in float -> remove? */ + //move16(); + //st->last_core_fx = st->core_fx; /* _DIFF_FLOAT_FIX_ not in float -> remove? */ test(); + test(); test(); - test(); - IF( ((LE_32(st->core_brate_fx,SID_2k40))&&EQ_16(st->cng_type_fx,FD_CNG)) - || (st->tcxonly && EQ_16(st->codec_mode,MODE2)) - ) + IF( ( st->Opt_DTX_ON_fx && LE_32(st->core_brate_fx,SID_2k40) && EQ_16(st->cng_type_fx,FD_CNG)) || (st->tcxonly && EQ_16(st->codec_mode,MODE2))) { /* reset LP memories */ set16_fx( st->mem_MA_fx,0, M ); @@ -65,15 +74,19 @@ void core_encode_update(Encoder_State_fx *st } } - - -void core_encode_update_cng( Encoder_State_fx *st, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *Aw, - Word16 Q_new, - Word16 shift - ) +/*-------------------------------------------------------------------* + * core_encode_update_cng() + * + * Common updates in case of CNG + *-------------------------------------------------------------------*/ +void core_encode_update_cng( + Encoder_State_fx *st, + Word16 *timeDomainBuffer, + Word16 *A, + Word16 *Aw, + Word16 Q_new, + Word16 shift +) { Word16 i; Word16 lsp[M]; @@ -81,11 +94,11 @@ void core_encode_update_cng( Encoder_State_fx *st, Word16 *synth, synth_buf[M+1+L_FRAME_PLUS+L_FRAME_PLUS/2], wsyn[L_FRAME_PLUS]; Word16 *p_A, tmp; Word16 enr_index; - Word16 enr, tmpv, maxv, scale, att; - Word16 hi, lo; - Word16 *pt_res; - Word32 L_tmp, L_ener; - + Word16 enr; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + LPD_state_HANDLE hLPDmem = st->hLPDmem; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* LPC -> LSP/lsp */ /* LSP/lsp -> LSF/lsf */ @@ -102,95 +115,34 @@ void core_encode_update_cng( Encoder_State_fx *st, /* Update synth memory */ move16(); synth = synth_buf + (1+M); - Copy( st->LPDmem.syn, synth_buf, 1+M ); + Copy( hLPDmem->syn, synth_buf, 1+M ); Copy( timeDomainBuffer, synth, st->L_frame_fx ); - Copy( synth+st->L_frame_fx-(1+M), st->LPDmem.syn, 1+M ); + Copy( synth+st->L_frame_fx-(1+M), hLPDmem->syn, 1+M ); Copy( synth, st->synth, st->L_frame_fx ); /* Update ZIR */ set16_fx( synth+st->L_frame_fx, 0, shr(st->L_frame_fx,1) ); E_UTIL_synthesis(1, A, synth+st->L_frame_fx, synth+st->L_frame_fx, shr(st->L_frame_fx,1), &synth[st->L_frame_fx-M], 0, M ); - Copy( synth+st->L_frame_fx-(st->L_frame_fx/2), st->LPDmem.Txnq, shr(st->L_frame_fx,1) ); - + IF (hTcxEnc != NULL) + { + Copy(synth + st->L_frame_fx - (st->L_frame_fx / 2), hTcxEnc->Txnq, shr(st->L_frame_fx, 1)); + } /* Update pe-synth memory */ move16(); tmp = synth[-(1+M)]; E_UTIL_f_preemph2( Q_new-1, synth-M, st->preemph_fac, M+st->L_frame_fx, &tmp ); - Copy( synth+st->L_frame_fx-M, st->LPDmem.mem_syn, M ); - Copy( synth+st->L_frame_fx-M, st->LPDmem.mem_syn2, M ); + Copy( synth+st->L_frame_fx-M, hLPDmem->mem_syn, M ); + Copy( synth+st->L_frame_fx-M, hLPDmem->mem_syn2, M ); /* Update excitation memory */ - Copy( st->LPDmem.old_exc+st->L_frame_fx, st->LPDmem.old_exc, s_max(L_EXC_MEM-st->L_frame_fx, 0 )); - Residu3_fx( A, synth, st->LPDmem.old_exc+s_max(L_EXC_MEM-st->L_frame_fx, 0), st->L_frame_fx, 1 ); + Copy( hLPDmem->old_exc+st->L_frame_fx, hLPDmem->old_exc, s_max(L_EXC_MEM-st->L_frame_fx, 0 )); + Residu3_fx( A, synth, hLPDmem->old_exc+s_max(L_EXC_MEM-st->L_frame_fx, 0), st->L_frame_fx, 1 ); /* Update LP_CNG memory */ IF( EQ_32(st->core_brate_fx, SID_2k40)) { - pt_res = st->LPDmem.old_exc + L_EXC_MEM - st->L_frame_fx; - maxv = 0; - move16(); - FOR(i = 0; i < st->L_frame_fx; i++) - { - maxv = s_max(maxv, abs_s(pt_res[i])); - } - scale = norm_s(maxv); - L_ener = L_deposit_l(1); - IF( EQ_16(st->L_frame_fx, L_FRAME)) - { - FOR (i=0; i<128; i++) - { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); - pt_res++; - tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ - { - FOR (i=0; i<160; i++) - { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); - pt_res++; - tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ - } - } - - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(30, add(hi, shl(add(Q_new, scale), 1))); /* log2 exp in Q2*(Q_new+scale) */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ - - /* decrease the energy in case of WB input */ - IF( NE_16(st->bwidth_fx, NB)) - { - IF( EQ_16(st->bwidth_fx,WB)) - { - IF( st->CNG_mode_fx >= 0 ) - { - /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[st->CNG_mode_fx]; - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = ENR_ATT_fx[4]; - } - } - ELSE - { - att = 384; - move16();/*Q8*/ - } - enr = sub(enr, att ); - } + /*IVAS_CODE CNG_att is missing */ + enr = cng_energy(st->element_mode, st->bwidth_fx, hDtxEnc->CNG_mode_fx, /*st->hTdCngEnc->CNG_att*/0, hLPDmem->old_exc + s_max(L_EXC_MEM - st->L_frame_fx, 0), st->L_frame_fx, Q_new); /* calculate the energy quantization index */ enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ @@ -200,7 +152,7 @@ void core_encode_update_cng( Encoder_State_fx *st, enr_index = s_min(enr_index, 127); enr_index = s_max(enr_index, 0); - st->old_enr_index_fx = enr_index; + hTdCngEnc->old_enr_index_fx = enr_index; } /* Update weighted synthesis memory */ @@ -214,11 +166,10 @@ void core_encode_update_cng( Encoder_State_fx *st, move16(); - - tmp = sub(st->wspeech_enc[-1],shl(st->LPDmem.mem_w0,shift)); + tmp = sub(st->wspeech_enc[-1],shl(hLPDmem->mem_w0,shift)); E_UTIL_deemph2( -shift, wsyn, st->preemph_fac, st->L_frame_fx, &tmp ); - st->LPDmem.mem_w0 = sub(st->wspeech_enc[st->L_frame_fx-1], tmp); - st->LPDmem.mem_w0 =shr(st->LPDmem.mem_w0, shift); + hLPDmem->mem_w0 = sub(st->wspeech_enc[st->L_frame_fx-1], tmp); + hLPDmem->mem_w0 =shr(hLPDmem->mem_w0, shift); /* Update LPC-related memories */ @@ -233,23 +184,23 @@ void core_encode_update_cng( Encoder_State_fx *st, /* Reset acelp memories */ move16(); move16(); - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit,0,6); - st->dm_fx.prev_state = 0; - st->LPDmem.tilt_code = TILT_CODE; - st->LPDmem.gc_threshold = L_deposit_l(0); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + set16_fx(hLPDmem->dm_fx.prev_gain_pit,0,6); + hLPDmem->dm_fx.prev_state = 0; + hLPDmem->tilt_code = TILT_CODE; + hLPDmem->gc_threshold = L_deposit_l(0); /* Update ace/tcx mode */ move16(); st->core_fx = ACELP_CORE; /* Reset TCX overlap */ - st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); - IF( st->first_CNG_fx == 0 ) + IF(hDtxEnc->first_CNG_fx == 0 ) { - Copy( st->lsp_old_fx, st->lspCNG_fx, M ); + Copy( st->lsp_old_fx, hDtxEnc->lspCNG_fx, M ); } return; diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index d71e607..2cbdb42 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*---------------------------------------------------------------------* @@ -18,59 +17,82 @@ void core_switching_pre_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: encoder state structure */ const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */ - const Word16 *old_inp_16k /* i : old input signal @16kHz */ + const Word16 *old_inp_16k, /* i : old input signal @16kHz */ + const Word16 active_cnt, /* i : active frame counter */ + const Word16 last_element_mode /* i : last_element_mode */ ) { Word16 Sample_Delay_HP, Sample_Delay_LP; Word16 tmp16; Word16 tmp; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; /* Mode switching */ - IF( EQ_16(st_fx->last_codec_mode,MODE2)) + test();test();test(); + IF( EQ_16(st_fx->last_codec_mode,MODE2) || (((EQ_16(st_fx->last_core_fx, TCX_20_CORE) + || EQ_16(st_fx->last_core_fx, TCX_10_CORE)) && GT_16(st_fx->element_mode, EVS_MONO)))) { - st_fx->mem_deemph_fx = st_fx->LPDmem.syn[M]; - move16(); - - Copy( mem->mem_syn2, st_fx->mem_syn1_fx, M ); - - st_fx->igf = 0; - move16(); + IF (hLPDmem != NULL) + { + st_fx->mem_deemph_fx = hLPDmem->syn[M]; + move16(); + Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); + } - IF( NE_16(st_fx->last_core_fx,ACELP_CORE)) + if (NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) { - /* reset BWE memories */ - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + st_fx->igf = 0; + move16(); } - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + IF (hBWE_TD != NULL) + { + IF(NE_16(st_fx->last_core_fx, ACELP_CORE)) + { + /* reset BWE memories */ + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + } + set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + } test(); IF( EQ_16(st_fx->last_core_fx,TCX_20_CORE)||EQ_16(st_fx->last_core_fx,TCX_10_CORE)) { - st_fx->last_core_fx = HQ_CORE; - move16(); - - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - - st_fx->mode_count_fx = 0; - move16(); - st_fx->mode_count1_fx = 0; - move16(); - - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - + if (EQ_16(st_fx->element_mode, EVS_MONO)) + { + st_fx->last_core_fx = HQ_CORE; + move16(); + } + IF (hHQ_core != NULL) + { + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + hHQ_core->last_max_pos_pulse_fx = 0; + move16(); + + hHQ_core->mode_count_fx = 0; + move16(); + hHQ_core->mode_count1_fx = 0; + move16(); + + set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); + hHQ_core->prev_frm_hfe2_fx = 0; + move16(); + hHQ_core->prev_stab_hfe2_fx = 0; + move16(); + } /*ALDO overlap windowed past: also used in MODE2 but for other MDCT-LB*/ - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); + IF (EQ_16(st_fx->element_mode, EVS_MONO) && hTcxEnc != NULL) + { + set16_fx(hTcxEnc->old_out_fx, 0, L_FRAME32k); + } } test(); @@ -86,8 +108,8 @@ void core_switching_pre_enc_fx( } - test(); - IF( EQ_16(st_fx->last_core_fx, -1) && EQ_16(st_fx->core_fx, HQ_CORE)) + test();test();test(); + IF( EQ_16(st_fx->last_core_fx, -1) && ( EQ_16(st_fx->core_fx, HQ_CORE) || EQ_16(st_fx->core_fx, TCX_20_CORE) || EQ_16(st_fx->core_fx, TCX_10_CORE))) { /* very first frame is HQ_CORE */ st_fx->last_core_fx = HQ_CORE; @@ -98,23 +120,26 @@ void core_switching_pre_enc_fx( test(); IF( EQ_16(st_fx->core_fx, HQ_CORE)&&(EQ_16(st_fx->last_core_fx,ACELP_CORE)||EQ_16(st_fx->last_core_fx,AMR_WB_CORE))) /* HQ init */ { - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse_fx = 0; move16(); - st_fx->mode_count_fx = 0; + hHQ_core->mode_count_fx = 0; move16(); - st_fx->mode_count1_fx = 0; + hHQ_core->mode_count1_fx = 0; move16(); - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; + set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2_fx = 0; move16(); - st_fx->prev_stab_hfe2_fx = 0; + hHQ_core->prev_stab_hfe2_fx = 0; move16(); - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); + if (hTcxEnc != NULL) + { + set16_fx(hTcxEnc->old_out_fx, 0, L_FRAME32k); + } } /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores @@ -123,12 +148,15 @@ void core_switching_pre_enc_fx( test(); IF( EQ_16(st_fx->core_fx, ACELP_CORE)&&(NE_16(st_fx->last_core_fx,ACELP_CORE)||EQ_16(st_fx->last_codec_mode,MODE2))) { - st_fx->last_last_ppp_mode_fx = 0; - move16(); - st_fx->last_ppp_mode_fx = 0; - move16(); - st_fx->last_nelp_mode_fx =0; - move16(); + IF (hSC_VBR != NULL) + { + hSC_VBR->last_last_ppp_mode_fx = 0; + move16(); + hSC_VBR->last_ppp_mode_fx = 0; + move16(); + hSC_VBR->last_nelp_mode_fx = 0; + move16(); + } } test(); @@ -144,7 +172,9 @@ void core_switching_pre_enc_fx( test(); test(); - IF( ( EQ_16(st_fx->core_fx, ACELP_CORE)||EQ_16(st_fx->core_fx,AMR_WB_CORE))&&EQ_16(st_fx->last_core_fx,HQ_CORE)) + IF( ( ( EQ_16(st_fx->core_fx, ACELP_CORE)||EQ_16(st_fx->core_fx,AMR_WB_CORE))&&EQ_16(st_fx->last_core_fx,HQ_CORE)) || + ((EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) + && EQ_16(last_element_mode, IVAS_CPE_DFT))) && EQ_16(active_cnt, 1))) { IF(EQ_16(st_fx->L_frame_fx, L_FRAME16k)) { @@ -158,32 +188,33 @@ void core_switching_pre_enc_fx( } st_fx->mem_deemph_fx = 0; - move16(); - st_fx->LPDmem.syn[M] = 0; - move16(); - set16_fx(mem->mem_syn2, 0, M ); - set16_fx( mem->mem_syn, 0, M ); - set16_fx( st_fx->mem_syn1_fx, 0, M ); + /* Reset ACELP parameters */ + IF (hLPDmem != NULL) + { + move16(); + hLPDmem->syn[M] = 0; + move16(); + set16_fx(hLPDmem->mem_syn2, 0, M); + set16_fx(hLPDmem->mem_syn, 0, M); + set16_fx(hLPDmem->mem_syn1_fx, 0, M); + hLPDmem->mem_w0 = 0; + move16(); + hLPDmem->tilt_code = 0; + move16(); + hLPDmem->gc_threshold = 0; + move32(); + /* set16_fx( st_fx->dispMem, 0, 8 ); */ + set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + hLPDmem->dm_fx.prev_state = 0; + move16(); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + } st_fx->Nb_ACELP_frames_fx = 0; move16(); - /* Reset ACELP parameters */ set16_fx( st_fx->mem_MA_fx,0, M ); Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - mem->mem_w0 = 0; - move16(); - mem->tilt_code = 0; - move16(); init_gp_clip_fx( st_fx->clip_var_fx ); - mem->gc_threshold = 0; - move16(); - - /* set16_fx( st_fx->dispMem, 0, 8 ); */ - set16_fx( st_fx->dm_fx.prev_gain_pit, 0, 6 ); - st_fx->dm_fx.prev_state = 0; - move16(); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - st_fx->last_coder_type_fx = GENERIC; move16(); @@ -200,36 +231,80 @@ void core_switching_pre_enc_fx( set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR,tmp16); /* Reset old ACELP buffers */ - set16_fx( mem->old_exc, 0, L_EXC_MEM ); - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); + test(); + IF (EQ_16(st_fx->element_mode, EVS_MONO) && hLPDmem != NULL) + { + set16_fx(hLPDmem->old_exc, 0, L_EXC_MEM); + } + IF (hBWE_TD != NULL) + { + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); - /* reset BWE memories */ - st_fx->bwe_non_lin_prev_scale_fx = 0; - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + /* reset BWE memories */ + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + } + IF(hBWE_FD != NULL) + { + set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + } } + test();test();test(); + IF ((EQ_16(st_fx->core_fx, ACELP_CORE) || EQ_16(st_fx->core_fx, AMR_WB_CORE)) && (EQ_16(st_fx->last_core_fx, TCX_20_CORE) || EQ_16(st_fx->last_core_fx, TCX_10_CORE))) + { + /* Reset the ACELP core in case of TCX->ACELP core switching */ + st_fx->Nb_ACELP_frames_fx = 0; move16(); - test(); - test(); - IF( GE_32(st_fx->input_Fs_fx, 16000)&&NE_16(st_fx->last_extl_fx,WB_BWE)&&EQ_16(st_fx->extl_fx,WB_BWE)) + IF (hLPDmem != NULL) + { + hLPDmem->mem_w0 = 0; + move16(); + hLPDmem->tilt_code = 0; + move16(); + hLPDmem->gc_threshold = 0; + move32(); + init_gp_clip_fx(st_fx->clip_var_fx); + set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + hLPDmem->dm_fx.prev_state = 0; + move16(); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + } + + st_fx->last_coder_type_fx = GENERIC; move16(); + + tmp16 = shr(st_fx->L_frame_fx, 6); + Copy(st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16); + set16_fx(st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16); + + /* Reset old TD BWE buffers */ + IF (hBWE_TD != NULL) + { + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2); + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); + } + + /* reset BWE memories */ + IF (hBWE_FD != NULL) + { + set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS));/* TODO : this might not be needed */ + } + } + test();test();test(); + IF( GE_32(st_fx->input_Fs_fx, 16000)&&NE_16(st_fx->last_extl_fx,WB_BWE)&&EQ_16(st_fx->extl_fx,WB_BWE) && hBWE_FD != NULL) { test(); IF( NE_16(st_fx->last_extl_fx, SWB_BWE)&&NE_16(st_fx->last_extl_fx,FB_BWE)) { - st_fx->prev_mode_fx = NORMAL; + hBWE_FD->prev_mode_fx = NORMAL; move16(); - st_fx->modeCount_fx = 0; + hBWE_FD->modeCount_fx = 0; move16(); } - st_fx->prev_L_swb_norm1_fx = 8; + hBWE_FD->prev_L_swb_norm1_fx = 8; move16(); } - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test(); IF( ( GE_32(st_fx->input_Fs_fx, 32000)&&NE_16(st_fx->last_extl_fx,SWB_BWE)&&EQ_16(st_fx->extl_fx,SWB_BWE))|| ( GE_32(st_fx->input_Fs_fx, 48000) && NE_16(st_fx->last_extl_fx, FB_BWE) && EQ_16(st_fx->extl_fx, FB_BWE) ) ) { @@ -239,33 +314,75 @@ void core_switching_pre_enc_fx( { Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); - - Copy( old_inp_12k8 + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), st_fx->old_input_lp_fx, Sample_Delay_LP ); + IF (GT_16(st_fx->element_mode, EVS_MONO)) + { + IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS); + } + Sample_Delay_HP = sub(Sample_Delay_HP , NS2SA(16000, DELAY_FIR_RESAMPL_NS)); + } + Copy( old_inp_12k8 + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); } ELSE { Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); - Copy( old_inp_16k + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), st_fx->old_input_lp_fx, Sample_Delay_LP ); + IF(GT_16(st_fx->element_mode, EVS_MONO)) + { + IF(EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS); + } + Sample_Delay_HP = sub(Sample_Delay_HP,NS2SA(16000, DELAY_FIR_RESAMPL_NS)); + } + + Copy( old_inp_16k + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); } tmp = sub(L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP); - Copy( &st_fx->old_speech_shb_fx[tmp], st_fx->new_input_hp_fx, Sample_Delay_HP ); + Copy( &hBWE_TD->old_speech_shb_fx[tmp], hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); add(0,0); IF (NE_16(st_fx->last_extl_fx,WB_BWE)) { - st_fx->prev_mode_fx = NORMAL; + hBWE_FD->prev_mode_fx = NORMAL; move16(); - st_fx->modeCount_fx = 0; + hBWE_FD->modeCount_fx = 0; move16(); } - st_fx->EnergyLF_fx = L_deposit_l(0); - st_fx->prev_L_swb_norm1_fx = 8; + hBWE_FD->EnergyLF_fx = L_deposit_l(0); + hBWE_FD->prev_L_swb_norm1_fx = 8; move16();/*8.0 in Q0 */ st_fx->EnergyLT_fx_exp = 30; move16(); /* Set to a High Exponent so it is 1^-30 */ + } + /*---------------------------------------------------------------------* + * band-width switching from WB -> SWB/FB + *---------------------------------------------------------------------*/ +#ifdef IVAS_CODE + IF (GT_16(st_fx->element_mode, EVS_MONO)) + { + IF (st_fx->bwidth_sw_cnt_fx == 0) + { + IF (GE_16(st_fx->bwidth_fx, SWB) && EQ_16(st_fx->last_bwidth_fx,WB)) + { + st_fx->bwidth_sw_cnt_fx = add(st_fx->bwidth_sw_cnt_fx, 1); + } + } + ELSE + { + st_fx->bwidth_sw_cnt_fx = add(st_fx->bwidth_sw_cnt_fx, 1); + + IF (EQ_16(st_fx->bwidth_sw_cnt_fx, BWS_TRAN_PERIOD)) + { + st_fx->bwidth_sw_cnt_fx = 0; + move16(); + } + } + } +#endif return; } @@ -278,105 +395,120 @@ void core_switching_pre_enc_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ void core_switching_post_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ const Word16 old_inp_12k8[], /* i : input signal @12.8 kHz Qinp */ const Word16 old_inp_16k[], /* i : input signal @16 kHz Qinp */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : Open-loop pitch gains */ const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ Word16 Qshift, Word16 Q_new, const Word16 Qsp, /* i/o : Q from acelp synthsis */ - Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ + Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ) { - Word16 T_op[3]; - - Copy( pitch, T_op, 3 ); + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; IF( EQ_16(st_fx->core_fx, HQ_CORE)) { st_fx->use_acelp_preq = 0; move16(); - test(); - IF( ( EQ_16(st_fx->last_core_fx, ACELP_CORE)||EQ_16(st_fx->last_core_fx,AMR_WB_CORE))) /* core switching ==> CELP subframe encoding */ + test();test(); + IF( ( EQ_16(st_fx->last_core_fx, ACELP_CORE)||EQ_16(st_fx->last_core_fx,AMR_WB_CORE)) && EQ_16(st_fx->element_mode, EVS_MONO) ) /* core switching ==> CELP subframe encoding */ { - acelp_core_switch_enc_fx( st_fx, &(st_fx->LPDmem),old_inp_12k8 + L_INP_MEM - NS2SA_fx2(INT_FS_FX, ACELP_LOOK_NS), - old_inp_16k + L_INP_MEM - NS2SA_fx2(INT_FS_16k, ACELP_LOOK_NS), T_op, voicing, A, Qshift, Q_new ); + acelp_core_switch_enc_fx( st_fx, old_inp_12k8 + L_INP_MEM - NS2SA_fx2(INT_FS_FX, ACELP_LOOK_NS), + old_inp_16k + L_INP_MEM - NS2SA_fx2(INT_FS_16k, ACELP_LOOK_NS), A, Qshift, Q_new ); } - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - st_fx->mem_deemph_old_syn_fx = 0; + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); } ELSE { *Qmus=Qsp; /* Write Qout */ + move16(); + IF (hBWE_TD == NULL) + { + return; + } /* reset SWB TBE buffers */ test(); IF( EQ_16(st_fx->extl_fx, WB_TBE)&&NE_16(st_fx->last_extl_fx,WB_TBE)) { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); IF ( NE_16(st_fx->last_extl_fx, WB_BWE)) { - set16_fx( st_fx->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx(hBWE_TD->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx(hBWE_TD->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); } - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); + set16_fx(hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx(hBWE_TD->mem_csfilt_fx, 0, 2 ); } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (EQ_16(st_fx->extl_fx, SWB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE))&& + test();test();test();test(); + test();test();test();test();test();test(); + test();IF( (EQ_16(st_fx->extl_fx, SWB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE))&& ( EQ_16(st_fx->last_core_fx,HQ_CORE) || NE_16(st_fx->L_frame_fx, st_fx->last_L_frame_fx) || - ( NE_16(st_fx->last_extl_fx, SWB_TBE) && NE_16(st_fx->last_extl_fx, FB_TBE) ) ) + ( NE_16(st_fx->last_extl_fx, SWB_TBE) && NE_16(st_fx->last_extl_fx, FB_TBE) && NE_16(st_fx->last_core_fx, TCX_20_CORE) && NE_16(st_fx->last_core_fx, TCX_10_CORE)) ) ) { - set16_fx( st_fx->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx), - st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx)); - - set16_fx( st_fx->dec_2_over_3_mem_fx,0, 12 ); - set16_fx( st_fx->dec_2_over_3_mem_lp_fx,0, 6 ); + set16_fx(hBWE_TD->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + +#ifdef IVAS_CODE + set16_fx(hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER); + set16_fx(hBWE_TD->old_EnvSHBres_fx, 0, L_FRAME4k); + hBWE_TD->old_mean_EnvSHBres_fx = 0; + hBWE_TD->prev_enr_EnvSHBres_fx = 32767; /*Q15 ??? */ + hBWE_TD->prev_shb_env_tilt_fx = 0; + hBWE_TD->prev_pow_exc16kWhtnd_fx = 32767; /*Q15 ??? */ + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 ??? */ + hBWE_TD->prev_Env_error_fx = 0; + move16();move16();move16();move16();move16();move16(); +#endif + swb_tbe_reset_fx(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx), + hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx)); + + set16_fx(hBWE_TD->dec_2_over_3_mem_fx,0, 12 ); + set16_fx(hBWE_TD->dec_2_over_3_mem_lp_fx,0, 6 ); } ELSE IF( ( EQ_16(st_fx->extl_fx, SWB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE))&& ( NE_32(st_fx->last_total_brate_fx, st_fx->total_brate_fx) || NE_16(st_fx->last_bwidth_fx, st_fx->bwidth_fx) || NE_16(st_fx->last_codec_mode, MODE1) || NE_16(st_fx->rf_mode, st_fx->rf_mode_last) ) ) { - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st_fx->gain_prec_swb_fx = 16384; + set16_fx(hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = 16384; move16(); /*Q14 = 1 */ } - + ELSE IF (EQ_16(st_fx->last_core_fx, TCX_20_CORE) || EQ_16(st_fx->last_core_fx, TCX_10_CORE)) + { + TBEreset_enc_fx( st_fx, st_fx->bwidth_fx); + } test(); test(); - IF( EQ_16(st_fx->extl_fx, FB_TBE)&&(NE_16(st_fx->last_extl_fx,FB_TBE)||NE_16(st_fx->L_frame_fx,st_fx->last_L_frame_fx))) + IF( EQ_16(st_fx->extl_fx, FB_TBE) && ((NE_16(st_fx->last_extl_fx, FB_TBE) && NE_16(st_fx->last_core_fx, TCX_20_CORE) && NE_16(st_fx->last_core_fx, TCX_10_CORE)) || NE_16(st_fx->L_frame_fx, st_fx->last_L_frame_fx))) + { + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + fb_tbe_reset_enc_fx(hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,&hBWE_TD->prev_fb_energy_fx_Q); + } + /* Fade towards init value for non HQ_CORE */ + IF (st_fx->hHQ_core != NULL) { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_enc_fx( st_fx->elliptic_bpf_2_48k_mem_fx, &st_fx->prev_fb_energy_fx,st_fx->elliptic_bpf_2_48k_mem_fx_Q,&st_fx->prev_fb_energy_fx_Q); +#ifdef IVAS_CODE + st_fx->hHQ_core->crest_lp = HQ_CREST_FAC_SM * (st_fx->hHQ_core->crest_lp) + (1.0f - HQ_CREST_FAC_SM) * HQ_CREST_THRESHOLD; + st_fx->hHQ_core->crest_mod_lp = HQ_CREST_FAC_SM * (st_fx->hHQ_core->crest_mod_lp) + (1.0f - HQ_CREST_FAC_SM) * HQ_CREST_MOD_THRESHOLD; +#endif } } @@ -404,6 +536,7 @@ void core_switching_hq_prepare_enc_fx( Word32 cbrate, *pt_32; const Word16 *pt_cos, *pt_16; Word16 n; + TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; SWITCH (input_frame) { @@ -429,7 +562,7 @@ void core_switching_hq_prepare_enc_fx( BREAK; } - /* set switching frame bit-rate */ + /* set switching frame bitrate */ IF( EQ_16(st_fx->last_L_frame_fx, L_FRAME)) { IF( GT_32(st_fx->core_brate_fx, ACELP_24k40)) @@ -505,8 +638,10 @@ void core_switching_hq_prepare_enc_fx( *pt_32++=L_negate(L_mult0(*pt_16--,*pt_cos--)); } - /* reset state of old_out if switching */ - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); - + IF(hTcxEnc != NULL) + { + /* reset state of old_out if switching */ + set16_fx(hTcxEnc->old_out_fx, 0, L_FRAME32k); + } return; } diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 862c955..3d294ad 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -1,12 +1,14 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" #include "prot_fx.h" #include "cnst_fx.h" -#include "stl.h" +/*-------------------------------------------------------------------* + * local constants + * -----------------------------------------------------------------*/ #define NB_TRACK 4 #define STEP NB_TRACK @@ -20,9 +22,9 @@ * y[i]=sum(j=i,l-1) x[j]*h[j-i], i=0,l-1 *-------------------------------------------------------------------*/ void corr_xh_fx( - const Word16 x[], /* i : target signal */ - Word16 dn[], /* o : correlation between x[] and h[] */ - const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ + const Word16 x[], /* i : target signal */ + Word16 dn[], /* o : correlation between x[] and h[] */ + const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ ) { Word16 i, j, k; @@ -62,4 +64,5 @@ void corr_xh_fx( { dn[i] = round_fx(L_shl(y32[i], j)); } + return; } diff --git a/lib_enc/decision_matrix_enc_fx.c b/lib_enc/decision_matrix_enc_fx.c index fc844ca..990b8a7 100644 --- a/lib_enc/decision_matrix_enc_fx.c +++ b/lib_enc/decision_matrix_enc_fx.c @@ -2,13 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include #include +#include #include "options.h" #include "prot_fx.h" #include "stat_enc_fx.h" #include "rom_com_fx.h" -#include "stl.h" /*-----------------------------------------------------------------* @@ -49,7 +48,7 @@ * +IGF +IGF +FD FB BWE +IGF +HR FB BWE * --------------------------------------------------------------------------------------------------------------------------------------------------------------- * - * Note: the GSC technology is part of the ACELP core as AUDIO coder_type (it is used also at 13.2 and 16.4 kbps for SWB unvoiced noisy speech) + * Note: the GSC technology is part of the ACELP core as AUDIO st_fx->coder_type (it is used also at 13.2 and 16.4 kbps for SWB unvoiced noisy speech) * Note2: FB processing is optional and is activated via "-band FB" option on the encoder command line * Note3: NB (0-4kHz), WB (0-8kHz), SWB (0-16kHz), FB (0-20kHz) * @@ -78,13 +77,11 @@ void decision_matrix_enc_fx( Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 sp_aud_decision1, /* i : 1st stage speech/music classification */ - const Word16 sp_aud_decision2, /* i : 2nd stage speech/music classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 vad_flag, Word16 *hq_core_type /* o : HQ core type */ ) { + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + /* initialization */ st_fx->core_fx = -1; move16(); @@ -133,13 +130,13 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( EQ_16(st_fx->ppp_mode_fx,1)) + IF ( EQ_16(hSC_VBR->ppp_mode_fx,1)) { /* PPP mode */ st_fx->core_brate_fx = PPP_NELP_2k80; move16(); } - ELSE IF ( ( ( EQ_16(coder_type,UNVOICED)||EQ_16(coder_type,TRANSITION))&&sp_aud_decision1==0)||NE_16(st_fx->bwidth_fx,NB)) + ELSE IF ( ( ( EQ_16(st_fx->coder_type,UNVOICED)||EQ_16(st_fx->coder_type,TRANSITION))&&st_fx->sp_aud_decision1==0)||NE_16(st_fx->bwidth_fx,NB)) { test(); test(); @@ -152,18 +149,18 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( EQ_16(coder_type,UNVOICED)&&EQ_16(vad_flag,1)&& + IF ( EQ_16(st_fx->coder_type,UNVOICED)&&EQ_16(st_fx->vad_flag,1)&& ( ( GE_16(st_fx->last_bwidth_fx,SWB) && st_fx->last_Opt_SC_VBR_fx == 1 ) || LT_16(st_fx->last_bwidth_fx, SWB) ) && ( NE_16(st_fx->last_core_fx,HQ_CORE) || NE_16(st_fx->bwidth_fx, NB) ) ) { /* NELP mode */ - st_fx->nelp_mode_fx = 1; + hSC_VBR->nelp_mode_fx = 1; move16(); st_fx->core_brate_fx = PPP_NELP_2k80; move32(); } - ELSE IF ( EQ_16(coder_type,TRANSITION)||(EQ_16(coder_type,UNVOICED)&&NE_16(st_fx->nelp_mode_fx,1))|| - ( ( EQ_16(coder_type,AUDIO) || EQ_16(coder_type,INACTIVE) ) && NE_16(st_fx->bwidth_fx, NB) ) ) + ELSE IF ( EQ_16(st_fx->coder_type,TRANSITION)||(EQ_16(st_fx->coder_type,UNVOICED)&&NE_16(hSC_VBR->nelp_mode_fx,1))|| + ( ( EQ_16(st_fx->coder_type,AUDIO) || EQ_16(st_fx->coder_type,INACTIVE) ) && NE_16(st_fx->bwidth_fx, NB) ) ) { /* silence portions */ @@ -187,7 +184,7 @@ void decision_matrix_enc_fx( move16(); test(); - if ( GE_32(st_fx->total_brate_fx,HQCORE_NB_MIN_RATE)&&EQ_16(sp_aud_decision1,1)) + if ( GE_32(st_fx->total_brate_fx,HQCORE_NB_MIN_RATE)&&EQ_16(st_fx->sp_aud_decision1,1)) { st_fx->core_fx = HQ_CORE; move16(); @@ -205,7 +202,7 @@ void decision_matrix_enc_fx( test(); test(); - IF ( ( GE_32(st_fx->total_brate_fx,HQCORE_WB_MIN_RATE)&&EQ_16(sp_aud_decision1,1))|| + IF ( ( GE_32(st_fx->total_brate_fx,HQCORE_WB_MIN_RATE)&&EQ_16(st_fx->sp_aud_decision1,1))|| GE_32(st_fx->total_brate_fx,HQ_96k) ) { st_fx->core_fx = HQ_CORE; @@ -228,7 +225,7 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( EQ_16(sp_aud_decision1,1)||EQ_16(coder_type,INACTIVE)||(sp_aud_decision1==0&&EQ_16(sp_aud_decision2,1))) + IF ( EQ_16(st_fx->sp_aud_decision1,1)||EQ_16(st_fx->coder_type,INACTIVE)||(st_fx->sp_aud_decision1==0&&EQ_16(st_fx->sp_aud_decision2,1))) { st_fx->extl_fx = WB_BWE; move16(); @@ -254,7 +251,7 @@ void decision_matrix_enc_fx( { test(); test(); - IF ( ( GE_32(st_fx->total_brate_fx,HQCORE_SWB_MIN_RATE)&&EQ_16(sp_aud_decision1,1))|| + IF ( ( GE_32(st_fx->total_brate_fx,HQCORE_SWB_MIN_RATE)&&EQ_16(st_fx->sp_aud_decision1,1))|| GE_32(st_fx->total_brate_fx,HQ_96k) ) { st_fx->core_fx = HQ_CORE; @@ -275,7 +272,7 @@ void decision_matrix_enc_fx( test(); test(); test(); - IF ( (EQ_16(sp_aud_decision1,1)||EQ_16(coder_type,INACTIVE)||(sp_aud_decision1==0&&EQ_16(sp_aud_decision2,1)))&&st_fx->GSC_noisy_speech_fx==0) + IF ( (EQ_16(st_fx->sp_aud_decision1,1)||EQ_16(st_fx->coder_type,INACTIVE)||(st_fx->sp_aud_decision1==0&&EQ_16(st_fx->sp_aud_decision2,1)))&&st_fx->GSC_noisy_speech_fx==0) { st_fx->extl_fx = SWB_BWE; move16(); @@ -344,7 +341,7 @@ void decision_matrix_enc_fx( test(); IF( (EQ_16(st_fx->bwidth_fx,SWB)||EQ_16(st_fx->bwidth_fx,WB))&&LE_32(st_fx->total_brate_fx,LRMDCT_CROSSOVER_POINT)) { - /* note that FB is always coded with NORMAL_HQ_CORE */ + /* note that FB (bitrate >= 24400 bps) is always coded with NORMAL_HQ_CORE */ *hq_core_type = LOW_RATE_HQ_CORE; move16(); } @@ -375,7 +372,7 @@ void decision_matrix_enc_fx( /*---------------------------------------------------------------------* * signalling_mode1_tcx20_enc() * - * write MODE1 TCX20 signalling information into the bit-stream + * write MODE1 TCX20 signalling information into the bitstream *---------------------------------------------------------------------*/ Word16 signalling_mode1_tcx20_enc( @@ -385,7 +382,9 @@ Word16 signalling_mode1_tcx20_enc( { Word16 num_bits; Word16 nBits, idx, start_idx; + BSTR_ENC_HANDLE hBstr; + hBstr = st->hBstr; assert(st->core_fx == TCX_20_CORE); num_bits = 0; @@ -418,14 +417,14 @@ Word16 signalling_mode1_tcx20_enc( num_bits = add(num_bits, nBits); IF (push != 0) { - push_indice_fx( st, IND_ACELP_SIGNALLING, sub(idx, start_idx), nBits ); + push_indice_fx(hBstr, IND_ACELP_SIGNALLING, sub(idx, start_idx), nBits ); } /* HQ/TCX core switching flag */ num_bits = add(num_bits, 1); IF (push != 0) { - push_indice_fx( st, IND_MDCT_CORE, 1, 1 ); + push_indice_fx(hBstr, IND_MDCT_CORE, 1, 1 ); } } ELSE @@ -436,7 +435,7 @@ Word16 signalling_mode1_tcx20_enc( num_bits = add(num_bits, 1); IF (push != 0) { - push_indice_fx( st, IND_CORE, 1, 1 ); + push_indice_fx(hBstr, IND_CORE, 1, 1 ); } } @@ -444,7 +443,7 @@ Word16 signalling_mode1_tcx20_enc( num_bits = add(num_bits, 1); IF (push != 0) { - push_indice_fx( st, IND_MDCT_CORE, 1, 1 ); + push_indice_fx(hBstr, IND_MDCT_CORE, 1, 1 ); } num_bits = add(num_bits, 2); @@ -453,19 +452,19 @@ Word16 signalling_mode1_tcx20_enc( /* write band-width (needed for different I/O sampling rate support) */ IF ( EQ_16(st->bwidth_fx, NB)) { - push_indice_fx( st, IND_HQ_BWIDTH, 0, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 0, 2 ); } ELSE IF ( EQ_16(st->bwidth_fx, WB)) { - push_indice_fx( st, IND_HQ_BWIDTH, 1, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 1, 2 ); } ELSE IF ( EQ_16(st->bwidth_fx, SWB)) { - push_indice_fx( st, IND_HQ_BWIDTH, 2, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 2, 2 ); } ELSE /* st->bwidth == FB */ { - push_indice_fx( st, IND_HQ_BWIDTH, 3, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 3, 2 ); } } } @@ -480,13 +479,15 @@ Word16 signalling_mode1_tcx20_enc( *---------------------------------------------------------------------*/ void signalling_enc_fx( - Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 sharpFlag /* i : formant sharpening flag */ + Encoder_State_fx *st_fx /* i : encoder state structure */ ) { Word16 nBits, idx, start_idx; - Word32 k; + Word32 k, total_brate_temp; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + BSTR_ENC_HANDLE hBstr; + + hBstr = st_fx->hBstr; IF (EQ_16(st_fx->mdct_sw, MODE2)) { @@ -494,66 +495,69 @@ void signalling_enc_fx( assert(!st_fx->tcxonly); assert(st_fx->core_fx == HQ_CORE); - push_next_indice_fx(st_fx, 1, 1); /* TCX */ - push_next_indice_fx(st_fx, 1, 1); /* HQ_CORE */ + push_next_indice_fx(hBstr, 1, 1); /* TCX */ + push_next_indice_fx(hBstr, 1, 1); /* HQ_CORE */ /* write ACELP->HQ core switching flag */ test(); IF ( EQ_16(st_fx->last_core_fx, ACELP_CORE)||EQ_16(st_fx->last_core_fx,AMR_WB_CORE)) { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 1, 1 ); + push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 1, 1 ); /* write ACELP L_frame info */ IF( EQ_16(st_fx->last_L_frame_fx, L_FRAME)) { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 0, 1 ); + push_indice_fx(hBstr, IND_LAST_L_FRAME, 0, 1 ); } ELSE { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 1, 1 ); + push_indice_fx(hBstr, IND_LAST_L_FRAME, 1, 1 ); } } ELSE { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 0, 1 ); + push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 0, 1 ); } return; } IF( EQ_16(st_fx->core_fx,ACELP_CORE )) { + Word16 ppp_mode, nelp_mode, sig; + + ppp_mode = 0; + nelp_mode = 0; + move16(); move16(); + IF(st_fx->Opt_SC_VBR_fx) + { + ppp_mode = hSC_VBR->ppp_mode_fx; + nelp_mode = hSC_VBR->nelp_mode_fx; + move16(); move16(); + } test(); test(); - IF( EQ_16(st_fx->ppp_mode_fx,1)||EQ_16(st_fx->nelp_mode_fx,1)) + IF( EQ_16(ppp_mode,1) || EQ_16(nelp_mode,1)) { - /* 1 bit to distinguish between 2.8kbps PPP/NELP frame and SID frame */ - push_indice_fx( st_fx, IND_CORE, 0, 1 ); + push_indice_fx(hBstr, IND_CORE, 0, 1 ); /* SC-VBR: 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( EQ_16(coder_type,VOICED)&&EQ_16(st_fx->bwidth_fx,NB)&&EQ_16(st_fx->ppp_mode_fx,1)) + test();test();test();test();test();test();test();test(); + IF ( EQ_16(st_fx->coder_type,VOICED)&&EQ_16(st_fx->bwidth_fx,NB)&&EQ_16(ppp_mode,1)) { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 0, 2 ); + push_indice_fx(hBstr, IND_PPP_NELP_MODE, 0, 2 ); } - ELSE IF ( EQ_16(coder_type,VOICED)&&NE_16(st_fx->bwidth_fx,NB)&&EQ_16(st_fx->ppp_mode_fx,1)) + ELSE IF ( EQ_16(st_fx->coder_type,VOICED)&&NE_16(st_fx->bwidth_fx,NB)&&EQ_16(ppp_mode,1)) { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 1, 2 ); + push_indice_fx(hBstr, IND_PPP_NELP_MODE, 1, 2 ); } - ELSE IF ( EQ_16(coder_type,UNVOICED)&&EQ_16(st_fx->bwidth_fx,NB)&&EQ_16(st_fx->nelp_mode_fx,1)) + ELSE IF ( EQ_16(st_fx->coder_type,UNVOICED)&&EQ_16(st_fx->bwidth_fx,NB)&&EQ_16(nelp_mode,1)) { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 2, 2); + push_indice_fx(hBstr, IND_PPP_NELP_MODE, 2, 2); } - ELSE IF ( EQ_16(coder_type,UNVOICED)&&NE_16(st_fx->bwidth_fx,NB)&&EQ_16(st_fx->nelp_mode_fx,1)) + ELSE IF ( EQ_16(st_fx->coder_type,UNVOICED)&&NE_16(st_fx->bwidth_fx,NB)&&EQ_16(nelp_mode,1)) { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 3, 2 ); + push_indice_fx(hBstr, IND_PPP_NELP_MODE, 3, 2 ); } } ELSE IF( NE_32(st_fx->core_brate_fx,SID_2k40)&&NE_32(st_fx->core_brate_fx,FRAME_NO_DATA)) @@ -561,28 +565,59 @@ void signalling_enc_fx( /* write the ACELP/HQ core selection bit */ IF (GE_32(st_fx->total_brate_fx,ACELP_24k40)) { - push_indice_fx( st_fx, IND_CORE, 0, 1 ); + push_indice_fx(hBstr, IND_CORE, 0, 1 ); } /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; - WHILE ( NE_32(acelp_sig_tbl[idx],st_fx->total_brate_fx)) + move16(); + WHILE (LT_16(idx, MAX_ACELP_SIG)) + { + IF (LE_32(st_fx->total_brate_fx, brate_tbl[idx])) + { + BREAK; + } + idx++; + } + total_brate_temp = brate_tbl[idx]; + move32(); + + idx = 0; + move16(); + WHILE ( NE_32(acelp_sig_tbl[idx], total_brate_temp)) { idx++; } /* retrieve the number of bits for signalling */ - nBits = (short) acelp_sig_tbl[++idx]; + nBits = (Word16)acelp_sig_tbl[++idx]; + move16(); /* retrieve the signalling index */ +#if 0 start_idx = ++idx; - k = SIG2IND_fx(coder_type, st_fx->bwidth_fx, sharpFlag, st_fx->rf_mode); + k = SIG2IND_fx(st_fx->coder_type, st_fx->bwidth_fx, st_fx->sharpFlag, st_fx->rf_mode); WHILE( NE_32(acelp_sig_tbl[idx], k)) +#else + start_idx = ++idx; + move16(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->bwidth_fx, SWB) && LE_32(st_fx->total_brate_fx, ACELP_9k60)) + { + /* patch to signal SWB as NB in Stereo */ + sig = (Word16)SIG2IND(st_fx->coder_type, NB, st_fx->sharpFlag, st_fx->rf_mode); + } + ELSE + { + sig = (Word16)SIG2IND(st_fx->coder_type, st_fx->bwidth_fx, st_fx->sharpFlag, st_fx->rf_mode); + } + + WHILE (NE_16((Word16)acelp_sig_tbl[idx] , sig)) +#endif { idx++; } - push_indice_fx( st_fx, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); + push_indice_fx(hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); } /* write extension layer flag to distinguish between TBE (0) and BWE (1) */ @@ -594,11 +629,11 @@ void signalling_enc_fx( test(); IF( EQ_16(st_fx->extl_fx,WB_TBE)||EQ_16(st_fx->extl_fx,SWB_TBE)||EQ_16(st_fx->extl_fx,FB_TBE)) { - push_indice_fx( st_fx, IND_BWE_FLAG, 0, 1 ); + push_indice_fx(hBstr, IND_BWE_FLAG, 0, 1 ); } ELSE IF( EQ_16(st_fx->extl_fx,WB_BWE)||EQ_16(st_fx->extl_fx,SWB_BWE)||EQ_16(st_fx->extl_fx,FB_BWE)) { - push_indice_fx( st_fx, IND_BWE_FLAG, 1, 1 ); + push_indice_fx(hBstr, IND_BWE_FLAG, 1, 1 ); } } } @@ -608,24 +643,24 @@ void signalling_enc_fx( test(); IF( EQ_16(st_fx->last_core_fx,ACELP_CORE)||EQ_16(st_fx->last_core_fx,AMR_WB_CORE)) { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 1, 1 ); + push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 1, 1 ); /* write ACELP L_frame info */ IF( EQ_16(st_fx->last_L_frame_fx, L_FRAME)) { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 0, 1 ); + push_indice_fx(hBstr, IND_LAST_L_FRAME, 0, 1 ); } ELSE { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 1, 1 ); + push_indice_fx(hBstr, IND_LAST_L_FRAME, 1, 1 ); } } ELSE { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 0, 1 ); + push_indice_fx(hBstr, IND_HQ_SWITCHING_FLG, 0, 1 ); } /* HQ/TCX core switching flag */ - push_indice_fx( st_fx, IND_MDCT_CORE, 0, 1 ); + push_indice_fx(hBstr, IND_MDCT_CORE, 0, 1 ); /* Use ACELP signaling for LR MDCT */ IF ( LE_32(st_fx->total_brate_fx,ACELP_16k40)) @@ -649,7 +684,7 @@ void signalling_enc_fx( idx++; } - push_indice_fx( st_fx, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); + push_indice_fx(hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); } ELSE { @@ -657,25 +692,25 @@ void signalling_enc_fx( IF( LE_32(st_fx->core_brate_fx,ACELP_64k)) { /* write ACELP/HQ core indication flag */ - push_indice_fx( st_fx, IND_CORE, 1, 1 ); + push_indice_fx(hBstr, IND_CORE, 1, 1 ); } /* write band-width (needed for different I/O sampling rate support) */ IF( EQ_16(st_fx->bwidth_fx,NB)) { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 0, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 0, 2 ); } ELSE IF( EQ_16(st_fx->bwidth_fx,WB)) { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 1, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 1, 2 ); } ELSE IF( EQ_16(st_fx->bwidth_fx,SWB)) { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 2, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 2, 2 ); } ELSE /* st_fx->bwidth_fx == FB */ { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 3, 2 ); + push_indice_fx(hBstr, IND_HQ_BWIDTH, 3, 2 ); } } } @@ -686,63 +721,62 @@ void signalling_enc_fx( /*---------------------------------------------------------------------* * signalling_enc_rf() * - * write channel-aware signalling information into the bit-stream + * write channel-aware signalling information into the bitstream *---------------------------------------------------------------------*/ void signalling_enc_rf( Encoder_State_fx *st /* i : encoder state structure */ ) { - Word16 i, tmp_rf; + Word16 i; Word16 sfr; - + RF_ENC_HANDLE hRF = st->hRF; /* write partial copy into bitstream */ IF(EQ_16(st->rf_mode,1)) { - enc_prm_rf(st, st->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset); - st->rf_indx_tbeGainFr[0] = st->rf_bwe_gainFr_ind; + enc_prm_rf(st, hRF->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset); + hRF->rf_indx_tbeGainFr[0] = hRF->rf_bwe_gainFr_ind; } /* Shift the RF indices such that the partial copy associated with (n-fec_offset)th frame is included in the bitstream in nth frame. */ - tmp_rf = st->rf_fec_offset; - FOR(i = tmp_rf; i >= 0 ; i--) + FOR(i = st->rf_fec_offset; i >= 0 ; i--) { /* rf frame type */ - st->rf_indx_frametype[i+1] = st->rf_indx_frametype[i]; + hRF->rf_indx_frametype[i+1] = hRF->rf_indx_frametype[i]; /* rf target bits buffer */ - st->rf_targetbits_buff[i+1] = st->rf_targetbits_buff[i]; + hRF->rf_targetbits_buff[i+1] = hRF->rf_targetbits_buff[i]; /* lsf indx */ - st->rf_indx_lsf[i+1][0] = st->rf_indx_lsf[i][0]; - st->rf_indx_lsf[i+1][1] = st->rf_indx_lsf[i][1]; - st->rf_indx_lsf[i+1][2] = st->rf_indx_lsf[i][2]; + hRF->rf_indx_lsf[i+1][0] = hRF->rf_indx_lsf[i][0]; + hRF->rf_indx_lsf[i+1][1] = hRF->rf_indx_lsf[i][1]; + hRF->rf_indx_lsf[i+1][2] = hRF->rf_indx_lsf[i][2]; /* ES pred energy */ - st->rf_indx_EsPred[i+1] = st->rf_indx_EsPred[i]; + hRF->rf_indx_EsPred[i+1] = hRF->rf_indx_EsPred[i]; /* LTF mode, sfr params: pitch, fcb and gain */ FOR(sfr = 0; sfr < st->nb_subfr; sfr++) { - st->rf_indx_ltfMode[i+1][sfr] = st->rf_indx_ltfMode[i][sfr]; - st->rf_indx_pitch[i+1][sfr] = st->rf_indx_pitch[i][sfr]; - st->rf_indx_fcb[i+1][sfr] = st->rf_indx_fcb[i][sfr]; - st->rf_indx_gain[i+1][sfr] = st->rf_indx_gain[i][sfr]; + hRF->rf_indx_ltfMode[i+1][sfr] = hRF->rf_indx_ltfMode[i][sfr]; + hRF->rf_indx_pitch[i+1][sfr] = hRF->rf_indx_pitch[i][sfr]; + hRF->rf_indx_fcb[i+1][sfr] = hRF->rf_indx_fcb[i][sfr]; + hRF->rf_indx_gain[i+1][sfr] = hRF->rf_indx_gain[i][sfr]; } /* shift the nelp indices */ - st->rf_indx_nelp_iG1[i+1] = st->rf_indx_nelp_iG1[i]; - st->rf_indx_nelp_iG2[i+1][0] = st->rf_indx_nelp_iG2[i][0]; - st->rf_indx_nelp_iG2[i+1][1] = st->rf_indx_nelp_iG2[i][1]; - st->rf_indx_nelp_fid[i+1] = st->rf_indx_nelp_fid[i]; + hRF->rf_indx_nelp_iG1[i+1] = hRF->rf_indx_nelp_iG1[i]; + hRF->rf_indx_nelp_iG2[i+1][0] = hRF->rf_indx_nelp_iG2[i][0]; + hRF->rf_indx_nelp_iG2[i+1][1] = hRF->rf_indx_nelp_iG2[i][1]; + hRF->rf_indx_nelp_fid[i+1] = hRF->rf_indx_nelp_fid[i]; /* tbe gain Fr shift */ - st->rf_indx_tbeGainFr[i+1] = st->rf_indx_tbeGainFr[i]; - st->rf_clas[i+1] = st->rf_clas[i]; - st->rf_gain_tcx[i+1] = st->rf_gain_tcx[i]; - st->rf_tcxltp_param[i+1] = st->rf_tcxltp_param[i]; + hRF->rf_indx_tbeGainFr[i+1] = hRF->rf_indx_tbeGainFr[i]; + hRF->rf_clas[i+1] = hRF->rf_clas[i]; + hRF->rf_gain_tcx[i+1] = hRF->rf_gain_tcx[i]; + hRF->rf_tcxltp_param[i+1] = hRF->rf_tcxltp_param[i]; } return; diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 8fc3db5..645b5a6 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------*/ /* Function hp_filter */ @@ -67,9 +66,7 @@ static void hp_filter_fx( Word16 detect_transient_fx( const Word16 *in_fx, /*Q_new */ - /*Encoder_State *st, */ const Word16 L, - const Word16 coder_type , /* i : coder type */ Word16 Q_new, Encoder_State_fx *st_fx ) @@ -110,7 +107,7 @@ Word16 detect_transient_fx( test(); test(); test(); - IF (NE_16(st_fx->last_extl_fx, st_fx->extl_fx)||(EQ_16(st_fx->last_extl_fx,st_fx->extl_fx)&&NE_16(st_fx->last_core_fx,st_fx->core_fx))||EQ_16(st_fx->last_codec_mode,MODE2)) + IF (NE_16(st_fx->last_extl_fx, st_fx->extl_fx) || (EQ_16(st_fx->last_extl_fx,st_fx->extl_fx) && NE_16(st_fx->last_core_fx,st_fx->core_fx)) || EQ_16(st_fx->last_codec_mode,MODE2)) { /*EnergyLT = EPSILON_FX; */ EnergyLT = L_deposit_l(0); @@ -195,7 +192,8 @@ Word16 detect_transient_fx( /*Calculate shift to get to Q0*/ test(); test(); - IF((GT_32(Mult_32_16(Energy, shl(2427, shift)), EnergyLT))||(GT_32(Mult_32_16(Energy,shl(3277,shift)),EnergyLT)&&EQ_16(coder_type,INACTIVE))) + IF((GT_32(Mult_32_16(Energy, shl(2427, shift)), EnergyLT)) || (GT_32(Mult_32_16(Energy,shl(3277,shift)),EnergyLT) + && EQ_16(st_fx->core_fx,ACELP_CORE) && EQ_16(st_fx->coder_type,INACTIVE))) { IsTransient = 1; move16(); @@ -240,7 +238,7 @@ Word16 detect_transient_fx( test(); test(); test(); - if( ( NE_16(st_fx->last_extl_fx,SWB_BWE)&&NE_16(st_fx->last_extl_fx,SWB_TBE)&&EQ_16(st_fx->extl_fx,SWB_BWE))|| + if( ( NE_16(st_fx->last_extl_fx,SWB_BWE) && NE_16(st_fx->last_extl_fx,SWB_TBE) && EQ_16(st_fx->extl_fx,SWB_BWE)) || ( NE_16(st_fx->last_extl_fx,FB_BWE) && NE_16(st_fx->last_extl_fx,FB_TBE) && EQ_16(st_fx->extl_fx,FB_BWE) ) ) { IsTransient = 0; @@ -284,7 +282,7 @@ Word16 detect_transient_fx( test(); test(); - IF (LT_32(L_shr(E_high_fx, 1), E_low_fx)&>_32(E_high_fx,Mult_32_16(E_low_fx,22938))&>_32(Mult_32_16(E_in_fx,Thres_fx),E_out_fx)) + IF (LT_32(L_shr(E_high_fx, 1), E_low_fx) && GT_32(E_high_fx,Mult_32_16(E_low_fx,22938)) && GT_32(Mult_32_16(E_in_fx,Thres_fx),E_out_fx)) { IsTransient = 0; move16(); @@ -293,7 +291,7 @@ Word16 detect_transient_fx( IF ( EQ_32(st_fx->core_brate_fx,ACELP_24k40)) { test(); - IF ( NE_16(st_fx->last_core_fx,HQ_CORE)||NE_32(st_fx->last_core_brate_fx,ACELP_24k40)) + IF ( NE_16(st_fx->last_core_fx,HQ_CORE) || NE_32(st_fx->last_core_brate_fx,ACELP_24k40)) { st_fx->TransientHangOver_fx = 0; move16(); diff --git a/lib_enc/diffcod_fx.c b/lib_enc/diffcod_fx.c index 79869f2..83840bb 100644 --- a/lib_enc/diffcod_fx.c +++ b/lib_enc/diffcod_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function Prototypes */ -#include "stl.h" /*--------------------------------------------------------------------------*/ /* Function diffcod */ @@ -13,15 +12,11 @@ /* */ /* Differential coding for indices of quantized norms */ /*--------------------------------------------------------------------------*/ -/* Word16 N (i) number of sub-vectors */ -/* Word16 *y (i/o) indices of quantized norms */ -/* Word16 *difidx (o) differential code */ -/*--------------------------------------------------------------------------*/ void diffcod_fx( - const Word16 N, /* (i) number of sub-vectors */ - Word16 *y, /* (i/o) indices of quantized norms */ - Word16 *difidx /* (o) differential code */ + const Word16 N, /* i : number of sub-vectors */ + Word16 *y, /* i/o: indices of quantized norms */ + Word16 *difidx /* o : differential code */ ) { Word16 i, k, r; @@ -65,11 +60,11 @@ void diffcod_fx( *--------------------------------------------------------------------------*/ void diffcod_lrmdct_fx( - const Word16 N, /* i : number of sub-vectors */ - const Word16 be_ref, /* i : band energy reference */ - Word16 *y, /* i/o: indices of quantized norms */ - Word16 *difidx, /* o : differential code */ - const Word16 is_transient /* i : transient flag */ + const Word16 N, /* i : number of sub-vectors */ + const Word16 be_ref, /* i : band energy reference */ + Word16 *y, /* i/o: indices of quantized norms */ + Word16 *difidx, /* o : differential code */ + const Word16 is_transient /* i : transient flag */ ) { Word16 i, m, r; diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index c472ec6..e3ad5cf 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" -#include "stl.h" #include "basop_mpy.h" #include "assert.h" @@ -28,11 +27,17 @@ #define CNG_TYPE_HO 20 /* hangover for switching between CNG types */ + /* _DIFF_FLOAT_FIX_ : lp_noise_fx threshold is different between float (15) and fix (5*256) */ +#define LP_NOISE_LV 5 /* LP_NOISE level */ + +#define MAX_BRATE_DTX_EVS ACELP_24k40 /* maximum bitrate to which the default DTX is applied in EVS; otherwise DTX is applied only in silence */ +#define MAX_BRATE_DTX_IVAS IVAS_64k /* maximum bitrate to which the default DTX is applied in IVAS; otherwise DTX is applied only in silence */ + /*-------------------------------------------------------------------* - * Local functions + * Local function prototypes *-------------------------------------------------------------------*/ -static void update_SID_cnt( Encoder_State_fx *st_fx ); +static void update_SID_cnt(DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, const Word16 Opt_AMR_WB); /*==================================================================================*/ @@ -58,7 +63,7 @@ static void update_SID_cnt( Encoder_State_fx *st_fx ); /*==================================================================================*/ void dtx_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 vad, /* i : vad flag */ + const Word16 vad, /* i : vad flag for DTX */ const Word16 speech[], /* i : Pointer to the speech frame */ Word16 Q_speech /* i : Q factor for speech */ @@ -66,7 +71,31 @@ void dtx_fx( { Word16 alpha,j,i,Q_speech2; Word32 L_tmp; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + + Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; + +#ifdef IVAS_CODE + IF (st_fx->dtx_sce_sba != 0) +#else + if (0) +#endif + { + last_br_cng_flag = 1; + last_br_flag = 1; + br_dtx_flag = 1; + move16();move16();move16(); + } + ELSE + { + /* _DIFF_FLOAT_FIX_ : lp_noise_fx threshold is different between float (15) and fix (5*256) */ + last_br_cng_flag = LE_32(st_fx->last_total_brate_cng_fx, ACELP_24k40) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV *256) || (EQ_16(st_fx->element_mode, IVAS_SCE) && LE_32(st_fx->last_total_brate_cng_fx, ACELP_32k)); + last_br_flag = LE_32(st_fx->last_total_brate_fx, ACELP_24k40) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV * 256) || (EQ_16(st_fx->element_mode, IVAS_SCE) && LE_32(st_fx->last_total_brate_fx, ACELP_32k)); + br_dtx_flag = 0; + move16(); + } /* Initialization */ IF( st_fx->ini_frame_fx == 0 ) { @@ -76,7 +105,7 @@ void dtx_fx( st_fx->cng_type_fx = FD_CNG; move16(); test(); - if( EQ_16( st_fx->codec_mode, MODE1 )||st_fx->Opt_AMR_WB_fx) + if( (EQ_16( st_fx->codec_mode, MODE1 )||st_fx->Opt_AMR_WB_fx) && EQ_16(st_fx->element_mode, IVAS_SCE) && EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) { st_fx->cng_type_fx = LP_CNG; move16(); @@ -93,12 +122,8 @@ void dtx_fx( test(); test(); test(); - test(); - test(); - IF ( GT_32(st_fx->last_core_brate_fx,SID_2k40)&& - NE_32(st_fx->last_total_brate_cng_fx,-1) && - NE_32(st_fx->last_total_brate_cng_fx,st_fx->total_brate_fx) && - ( (LE_32(st_fx->last_total_brate_cng_fx, ACELP_24k40) ) || (LT_16(st_fx->lp_noise_fx, 1280) ) ) ) + IF ( GT_32(st_fx->last_core_brate_fx,SID_2k40) && NE_32(st_fx->last_total_brate_cng_fx,-1) && + NE_32(st_fx->last_total_brate_cng_fx,st_fx->total_brate_fx) && last_br_cng_flag) { st_fx->total_brate_fx = st_fx->last_total_brate_cng_fx; move32(); @@ -108,7 +133,7 @@ void dtx_fx( st_fx->Opt_SC_VBR_fx = 0; move16(); } - st_fx->rf_mode = st_fx->last_rf_mode_cng; + st_fx->rf_mode = st_fx->last_rf_mode_cng; move16(); st_fx->bwidth_fx = st_fx->last_bwidth_cng_fx; move16(); @@ -117,12 +142,7 @@ void dtx_fx( } test(); test(); - test(); - test(); - test(); - IF ( LE_32(st_fx->last_core_brate_fx,SID_2k40)&& - NE_32(st_fx->last_total_brate_fx,st_fx->total_brate_fx)&& - ( LE_32(st_fx->last_total_brate_fx,ACELP_24k40) || LT_16(st_fx->lp_noise_fx, 1280) ) ) + IF ( LE_32(st_fx->last_core_brate_fx,SID_2k40) && NE_32(st_fx->last_total_brate_fx,st_fx->total_brate_fx) && last_br_flag) { st_fx->total_brate_fx = st_fx->last_total_brate_fx; @@ -148,56 +168,14 @@ void dtx_fx( move16(); st_fx->bwidth_fx = st_fx->last_bwidth_fx; move32(); - SWITCH ( st_fx->total_brate_fx ) + IF (GT_16(st_fx->element_mode, EVS_MONO)) { - case 5900: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 7200: st_fx->codec_mode = MODE1; move16(); - BREAK; - case 8000: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 9600: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 13200: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 16400: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 24400: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 32000: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 48000: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 64000: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 96000: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 128000: - st_fx->codec_mode = MODE2; - move16(); - BREAK; + } + ELSE + { + st_fx->codec_mode = get_codec_mode(st_fx->total_brate_fx); } } } @@ -205,15 +183,20 @@ void dtx_fx( /*------------------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX is enabled *------------------------------------------------------------------------*/ - - test(); +#ifdef IVAS_CODE + if (st_fx->dtx_sce_sba == 0) +#endif + { + br_dtx_flag = LE_32(st_fx->total_brate_fx, ACELP_24k40) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV * 256) || (EQ_16(st_fx->element_mode, IVAS_SCE) && LE_32(st_fx->total_brate_fx, ACELP_32k)) || + EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && (LE_32(st_fx->element_brate, IVAS_64k) || LT_16(st_fx->lp_noise_fx, LP_NOISE_LV * 256))); + } test(); test(); test(); test(); IF( st_fx->Opt_DTX_ON_fx && vad == 0 && GT_16(st_fx->ini_frame_fx,2) && /* CNG coding starts after 2 frames */ - ( LE_32(st_fx->total_brate_fx,ACELP_24k40) || LT_16(st_fx->lp_noise_fx, 1280)) && + br_dtx_flag && st_fx->fd_cng_reset_flag == 0 ) { /* reset counter */ @@ -233,7 +216,7 @@ void dtx_fx( st_fx->last_codec_mode_cng = st_fx->codec_mode; } - IF( st_fx->cnt_SID_fx == 0 ) + IF(hDtxEnc->cnt_SID_fx == 0 ) { /* this will be a SID frame */ IF ( st_fx->Opt_AMR_WB_fx ) @@ -262,32 +245,54 @@ void dtx_fx( st_fx->core_brate_fx = SID_2k40; move32(); } - - test(); - IF( EQ_16(st_fx->cng_type_fx,FD_CNG)&&LE_32(st_fx->total_brate_fx,ACELP_24k40)) /* at highest bit-rates, use exclusively LP_CNG */ + PMT("dtx_sce_sba code is missing") +#ifdef IVAS_CODE + IF ((NE_16(st_fx->last_core_fx, ACELP_CORE) || EQ_16(st_fx->cng_type_fx, FD_CNG)) && EQ_16(st_fx->dtx_sce_sba, 1)) { - test(); - test(); - IF ( EQ_32(st_fx->total_brate_fx,ACELP_9k60)||EQ_32(st_fx->total_brate_fx,ACELP_16k40)||EQ_32(st_fx->total_brate_fx,ACELP_24k40)) + st_fx->cng_type_fx = FD_CNG; move16(); + if (EQ_16(st_fx->element_mode, EVS_MONO) && (EQ_32(st_fx->total_brate_fx, ACELP_9k60) || EQ_32(st_fx->total_brate_fx, ACELP_16k40) || EQ_32(st_fx->total_brate_fx, ACELP_24k40) || EQ_32(st_fx->total_brate_fx, ACELP_48k) || EQ_32(st_fx->total_brate_fx, HQ_96k) || EQ_32(st_fx->total_brate_fx, HQ_128k))) { - st_fx->codec_mode = MODE2; - move16(); + st_fx->codec_mode = MODE2; move16(); } } - ELSE + ELSE +#endif { - st_fx->cng_type_fx = LP_CNG; - move16(); - IF ( st_fx->codec_mode == MODE2 ) + test(); test(); test(); test(); + IF((EQ_16(st_fx->cng_type_fx,FD_CNG) && (LE_32(st_fx->total_brate_fx,ACELP_24k40) || (NE_16(st_fx->element_mode, EVS_MONO) && LE_32(st_fx->total_brate_fx, ACELP_32k)))) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT))) /* at highest bitrates, use exclusively LP_CNG */ { - st_fx->lp_cng_mode2 = 1; + test(); test(); + IF(EQ_16(st_fx->element_mode, EVS_MONO) && (EQ_32(st_fx->total_brate_fx,ACELP_9k60) || EQ_32(st_fx->total_brate_fx,ACELP_16k40) || EQ_32(st_fx->total_brate_fx,ACELP_24k40))) + { + st_fx->codec_mode = MODE2; + move16(); + } + } + ELSE + { + st_fx->cng_type_fx = LP_CNG; + move16(); + IF(st_fx->codec_mode == MODE2) + { + hTdCngEnc->lp_cng_mode2 = 1; + move16(); + } + st_fx->codec_mode = MODE1; move16(); } - st_fx->codec_mode = MODE1; - move16(); } - +#if 1//def IVAS_CODE + /* reset the bitstream (IVAS format signalling was already written) */ + IF (NE_16(st_fx->element_mode, IVAS_CPE_MDCT) && st_fx->hBstr != NULL) + { +#ifndef IVAS_CODE_BITSTREAM + reset_indices_enc_fx(st_fx->hBstr); +#else + reset_indices_enc(st_fx->hBstr, st_fx->hBstr->nb_ind_tot); +#endif + } +#endif } /*------------------------------------------------------------------------* @@ -296,53 +301,80 @@ void dtx_fx( /* NB core bit rate can be "-1" at startup , so one can not use core_brate_fx <=2400 */ test(); test(); - IF ( (NE_32(st_fx->core_brate_fx ,SID_2k40))&&(NE_32(st_fx->core_brate_fx,SID_1k75))&&(st_fx->core_brate_fx!=0)) + IF ( (NE_32(st_fx->core_brate_fx ,SID_2k40)) && (NE_32(st_fx->core_brate_fx,SID_1k75)) && (NE_32(st_fx->core_brate_fx, FRAME_NO_DATA))) { - st_fx->cnt_SID_fx = 0; - move16(); - - /* change SID update rate */ - /* first SID update is only 8 (3) frames after the active speech end */ - IF( !st_fx->Opt_AMR_WB_fx ) + IF(hDtxEnc != NULL) { - st_fx->max_SID_fx = FIXED_SID_RATE; + hDtxEnc->cnt_SID_fx = 0; move16(); - } - ELSE - { - st_fx->max_SID_fx = 3; - move16(); /* first SID update is only 3 frames after the active speech end */ - } - IF ( LT_16(st_fx->interval_SID_fx,st_fx->max_SID_fx)) - { - st_fx->max_SID_fx = st_fx->interval_SID_fx; - move16();/* change SID update rate */ - } + /* change SID update rate */ + /* first SID update is only 8 (3) frames after the active speech end */ + IF(!st_fx->Opt_AMR_WB_fx) + { + hDtxEnc->max_SID_fx = FIXED_SID_RATE; + move16(); + } + ELSE + { + hDtxEnc->max_SID_fx = 3; + move16(); /* first SID update is only 3 frames after the active speech end */ + } - st_fx->cng_cnt_fx = 0; - move16(); /* reset the counter of CNG frames for averaging */ + IF(LT_16(hDtxEnc->interval_SID_fx, hDtxEnc->max_SID_fx)) + { + hDtxEnc->max_SID_fx = hDtxEnc->interval_SID_fx; + move16();/* change SID update rate */ + } + hDtxEnc->cng_cnt_fx = 0; + move16(); /* reset the counter of CNG frames for averaging */ + } test(); - IF( GE_16(st_fx->active_fr_cnt_fx,CNG_TYPE_HO)&&st_fx->Opt_AMR_WB_fx==0) + IF( GE_16(st_fx->active_fr_cnt_fx,CNG_TYPE_HO) && st_fx->Opt_AMR_WB_fx==0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16(st_fx->cng_type_fx,LP_CNG)&&((EQ_16(st_fx->input_bwidth_fx,NB)&>_32(st_fx->bckr_tilt_lt,589824l/*9.f Q16*/))||(GT_16(st_fx->input_bwidth_fx,NB)&>_32(st_fx->bckr_tilt_lt,2949120l/*45.f Q16*/)))) + IF (EQ_16(st_fx->element_mode, IVAS_SCE)) { - st_fx->cng_type_fx = FD_CNG; - move16(); +#ifdef IVAS_CODE + Word16 lp_thresh, fd_thresh; + PMT("lp_thresh scaling is to be found") + test(); + IF (st_fx->Opt_DTX_ON_fx && EQ_16(st_fx->dtx_sce_sba, 1) ) + { + lp_thresh = 5.f; + fd_thresh = 2.f; + } + ELSE + + { + lp_thresh = 10.f; + fd_thresh = 5.f; + } + + /*More conservative selection of LP-CNG for SCE*/ + if (st->cng_type == LP_CNG && (st->bckr_tilt_lt > lp_thresh)) + { + st->cng_type = FD_CNG; + } + else if (st->cng_type == FD_CNG && (st->bckr_tilt_lt < fd_thresh) && (st->lp_noise > 2.f)) + { + st->cng_type = LP_CNG; + } +#endif } - ELSE IF( EQ_16(st_fx->cng_type_fx,FD_CNG)&&((EQ_16(st_fx->input_bwidth_fx,NB)&<_32(st_fx->bckr_tilt_lt,131072l/*2.f Q16*/))||(GT_16(st_fx->input_bwidth_fx,NB)&<_32(st_fx->bckr_tilt_lt,655360l/*10.f Q16*/)))) + ELSE { - st_fx->cng_type_fx = LP_CNG; - move16(); + test(); test(); test(); test(); test(); test(); test(); test(); + IF(EQ_16(st_fx->cng_type_fx, LP_CNG) && ((EQ_16(st_fx->input_bwidth_fx, NB) && GT_32(st_fx->bckr_tilt_lt, 589824l/*9.f Q16*/)) || (GT_16(st_fx->input_bwidth_fx, NB) && GT_32(st_fx->bckr_tilt_lt, 2949120l/*45.f Q16*/)))) + { + st_fx->cng_type_fx = FD_CNG; + move16(); + } + ELSE IF(EQ_16(st_fx->cng_type_fx, FD_CNG) && ((EQ_16(st_fx->input_bwidth_fx, NB) && LT_32(st_fx->bckr_tilt_lt, 131072l/*2.f Q16*/)) || (GT_16(st_fx->input_bwidth_fx, NB) && LT_32(st_fx->bckr_tilt_lt, 655360l/*10.f Q16*/)))) + { + st_fx->cng_type_fx = LP_CNG; + move16(); + } } st_fx->last_total_brate_cng_fx = -1; } @@ -358,70 +390,72 @@ void dtx_fx( /*------------------------------------------------------------------------* * Update speech and background noise long-term energy *------------------------------------------------------------------------*/ - - st_fx->frame_ener_fx = L_deposit_l(0); - - IF ( st_fx->Opt_DTX_ON_fx ) + IF (hDtxEnc != NULL) { - Q_speech2 = add(shl(Q_speech, 1), 7); - FOR (j=0; j<16; j++) + hDtxEnc->frame_ener_fx = L_deposit_l(0); + + IF(st_fx->Opt_DTX_ON_fx) { - L_tmp = L_mult0(*speech, *speech); - speech++; - FOR (i = 1; i< L_FRAME/16; i++) + Q_speech2 = add(shl(Q_speech, 1), 7); + FOR(j = 0; j < 16; j++) { - L_tmp = L_mac0(L_tmp, *speech, *speech); + L_tmp = L_mult0(*speech, *speech); speech++; + FOR(i = 1; i < L_FRAME / 16; i++) + { + L_tmp = L_mac0(L_tmp, *speech, *speech); + speech++; + } + hDtxEnc->frame_ener_fx = L_add(hDtxEnc->frame_ener_fx, L_shr(L_tmp, Q_speech2));/*Q(-7) */ } - st_fx->frame_ener_fx = L_add(st_fx->frame_ener_fx, L_shr(L_tmp, Q_speech2));/*Q(-7) */ - } - /* Active speech (voiced) */ + /* Active speech (voiced) */ - IF ( EQ_16(st_fx->clas_fx,VOICED_CLAS)) - { - alpha = ALPHA_ENER_SLOW_FX; - move16(); - if ( GT_32(st_fx->frame_ener_fx,st_fx->lt_ener_voiced_fx)) + IF(EQ_16(st_fx->clas_fx, VOICED_CLAS)) { - alpha = ALPHA_ENER_FAST_FX; - move16();/*Q15 */ - } + alpha = ALPHA_ENER_SLOW_FX; + move16(); + if (GT_32(hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx)) + { + alpha = ALPHA_ENER_FAST_FX; + move16();/*Q15 */ + } - /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub(st_fx->lt_ener_voiced_fx, st_fx->frame_ener_fx); - L_tmp = Mult_32_16(L_tmp, alpha); - st_fx->lt_ener_voiced_fx = L_add(L_tmp, st_fx->frame_ener_fx); /*Q(-7) */ + /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ + L_tmp = L_sub(hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx); + L_tmp = Mult_32_16(L_tmp, alpha); + hDtxEnc->lt_ener_voiced_fx = L_add(L_tmp, hDtxEnc->frame_ener_fx); /*Q(-7) */ - st_fx->VarDTX_cnt_voiced_fx = add(st_fx->VarDTX_cnt_voiced_fx,1); + hDtxEnc->VarDTX_cnt_voiced_fx = add(hDtxEnc->VarDTX_cnt_voiced_fx, 1); - st_fx->VarDTX_cnt_voiced_fx = s_min(st_fx->VarDTX_cnt_voiced_fx, MIN_CNT); - } - /* Background noise */ - ELSE IF( !st_fx->Opt_AMR_WB_fx ) - { - alpha = ALPHA_ENER_SLOW_FX; - move16(); - if (LT_32(st_fx->frame_ener_fx,st_fx->lt_ener_noise_fx)) + hDtxEnc->VarDTX_cnt_voiced_fx = s_min(hDtxEnc->VarDTX_cnt_voiced_fx, MIN_CNT); + } + /* Background noise */ + ELSE IF(!st_fx->Opt_AMR_WB_fx) { - alpha = ALPHA_ENER_FAST_FX; + alpha = ALPHA_ENER_SLOW_FX; move16(); - } + if (LT_32(hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx)) + { + alpha = ALPHA_ENER_FAST_FX; + move16(); + } - /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub(st_fx->lt_ener_noise_fx, st_fx->frame_ener_fx); - L_tmp = Mult_32_16(L_tmp, alpha); - st_fx->lt_ener_noise_fx = L_add(L_tmp, st_fx->frame_ener_fx); - move32();/*Q(-7) */ + /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ + L_tmp = L_sub(hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx); + L_tmp = Mult_32_16(L_tmp, alpha); + hDtxEnc->lt_ener_noise_fx = L_add(L_tmp, hDtxEnc->frame_ener_fx); + move32();/*Q(-7) */ - st_fx->VarDTX_cnt_noise_fx = add(st_fx->VarDTX_cnt_noise_fx,1); + hDtxEnc->VarDTX_cnt_noise_fx = add(hDtxEnc->VarDTX_cnt_noise_fx, 1); - st_fx->VarDTX_cnt_noise_fx = s_min(st_fx->VarDTX_cnt_noise_fx, MIN_CNT); + hDtxEnc->VarDTX_cnt_noise_fx = s_min(hDtxEnc->VarDTX_cnt_noise_fx, MIN_CNT); + } } } /* Update of the SID counter */ - update_SID_cnt( st_fx ); + update_SID_cnt(hDtxEnc, st_fx->core_brate_fx, st_fx->Opt_AMR_WB_fx); /* Update encoded bandwidth */ test(); @@ -504,7 +538,9 @@ void dtx_fx( *---------------------------------------------------------------------*/ static void update_SID_cnt( - Encoder_State_fx *st_fx /* i/o: State structure */ + DTX_ENC_HANDLE hDtxEnc, /* i/o: common DTX handle */ + const Word32 core_brate, /* i : core coder core bitrate */ + const Word16 Opt_AMR_WB /* i : AMR BW IO mode? */ ) { Word16 EstimatedSNR, delta, frac, exp; @@ -512,21 +548,21 @@ static void update_SID_cnt( test(); test(); - IF( EQ_32(st_fx->core_brate_fx, SID_2k40)||EQ_32(st_fx->core_brate_fx,SID_1k75)||st_fx->core_brate_fx==FRAME_NO_DATA) + IF( EQ_32(core_brate, SID_2k40)||EQ_32(core_brate,SID_1k75)||core_brate==FRAME_NO_DATA) { /* Adapt the SID interval */ test(); test(); - IF ( st_fx->var_SID_rate_flag_fx != 0 && EQ_16(st_fx->VarDTX_cnt_voiced_fx, MIN_CNT)&&EQ_16(st_fx->VarDTX_cnt_noise_fx,MIN_CNT)) + IF (hDtxEnc->var_SID_rate_flag_fx != 0 && EQ_16(hDtxEnc->VarDTX_cnt_voiced_fx, MIN_CNT)&&EQ_16(hDtxEnc->VarDTX_cnt_noise_fx,MIN_CNT)) { /* EstimatedSNR = 10.0f * (float)log10( (0.01f + st_fx->lt_ener_voiced) / (0.01f + st_fx->lt_ener_noise) ); */ - L_tmp1 = L_max(st_fx->lt_ener_voiced_fx, 1); + L_tmp1 = L_max(hDtxEnc->lt_ener_voiced_fx, 1); exp = norm_l(L_tmp1); frac = Log2_norm_lc(L_shl(L_tmp1, exp)); exp = sub(30, exp); L_tmp1 = L_Comp(exp, frac); - L_tmp2 = L_max(st_fx->lt_ener_noise_fx, 1); + L_tmp2 = L_max(hDtxEnc->lt_ener_noise_fx, 1); exp = norm_l(L_tmp2); frac = Log2_norm_lc(L_shl(L_tmp2, exp)); exp = sub(30, exp); @@ -538,37 +574,37 @@ static void update_SID_cnt( EstimatedSNR = round_fx(L_tmp1); /* now in Q8 */ IF ( GT_16(EstimatedSNR,SNR_H_FX)) { - st_fx->interval_SID_fx = INT_H; + hDtxEnc->interval_SID_fx = INT_H; move16(); } ELSE IF ( LT_16(EstimatedSNR,SNR_L_FX)) { - st_fx->interval_SID_fx = INT_L; + hDtxEnc->interval_SID_fx = INT_L; move16(); } ELSE { - st_fx->interval_SID_fx = extract_h(L_mac(INT_L*65536L-SNR_L_FX/256*65536L*RATIO,(32768/256)*RATIO, EstimatedSNR)); + hDtxEnc->interval_SID_fx = extract_h(L_mac(INT_L*65536L-SNR_L_FX/256*65536L*RATIO,(32768/256)*RATIO, EstimatedSNR)); } - st_fx->interval_SID_fx = s_min(s_max(st_fx->interval_SID_fx, INT_L), INT_H); + hDtxEnc->interval_SID_fx = s_min(s_max(hDtxEnc->interval_SID_fx, INT_L), INT_H); test(); - if( st_fx->Opt_AMR_WB_fx == 0 || NE_16(st_fx->max_SID_fx,3)) + if( Opt_AMR_WB== 0 || NE_16(hDtxEnc->max_SID_fx,3)) { - st_fx->max_SID_fx = st_fx->interval_SID_fx; + hDtxEnc->max_SID_fx = hDtxEnc->interval_SID_fx; move16(); /* change SID update rate */ } } test(); - IF( st_fx->Opt_DTX_ON_fx != 0 && st_fx->cnt_SID_fx != 0 ) + IF( hDtxEnc->cnt_SID_fx != 0 ) { - L_tmp1 = L_max(st_fx->lt_ener_noise_fx, 1); + L_tmp1 = L_max(hDtxEnc->lt_ener_noise_fx, 1); exp = norm_l(L_tmp1); frac = Log2_norm_lc(L_shl(L_tmp1, exp)); exp = sub(30, exp); L_tmp1 = L_Comp(exp, frac); - L_tmp2 = L_max(st_fx->lt_ener_last_SID_fx, 1); + L_tmp2 = L_max(hDtxEnc->lt_ener_last_SID_fx, 1); exp = norm_l(L_tmp2); frac = Log2_norm_lc(L_shl(L_tmp2, exp)); exp = sub(30, exp); @@ -580,61 +616,61 @@ static void update_SID_cnt( delta = round_fx(L_tmp1); /* now in Q8 */ test(); test(); - if ( LT_16(delta,LTE_VAR_FX)&&EQ_16(st_fx->VarDTX_cnt_voiced_fx,MIN_CNT)&&EQ_16(st_fx->VarDTX_cnt_noise_fx,MIN_CNT)) + if ( LT_16(delta,LTE_VAR_FX)&&EQ_16(hDtxEnc->VarDTX_cnt_voiced_fx,MIN_CNT)&&EQ_16(hDtxEnc->VarDTX_cnt_noise_fx,MIN_CNT)) { /* Send SID frame, and reset lt_ener_noise */ - st_fx->lt_ener_noise_fx = st_fx->frame_ener_fx; + hDtxEnc->lt_ener_noise_fx = hDtxEnc->frame_ener_fx; move32(); } } ELSE { /* If SID frame was sent, update long-term energy */ - st_fx->lt_ener_last_SID_fx = st_fx->lt_ener_noise_fx; + hDtxEnc->lt_ener_last_SID_fx = hDtxEnc->lt_ener_noise_fx; move32(); } - st_fx->cnt_SID_fx = add(st_fx->cnt_SID_fx,1); + hDtxEnc->cnt_SID_fx = add(hDtxEnc->cnt_SID_fx,1); - IF( st_fx->var_SID_rate_flag_fx ) + IF(hDtxEnc->var_SID_rate_flag_fx ) { test(); test(); test(); - if( st_fx->Opt_AMR_WB_fx != 0 && EQ_16(st_fx->max_SID_fx,3)&&EQ_16(st_fx->cnt_SID_fx,3)) + if( Opt_AMR_WB!= 0 && EQ_16(hDtxEnc->max_SID_fx,3)&&EQ_16(hDtxEnc->cnt_SID_fx,3)) { /* set the size of CNG history buffer for averaging to DTX_HIST_SIZE frames */ /* be sure that DTX_HIST_SIZE >= INT_L */ - st_fx->cng_hist_size_fx = 3; + hDtxEnc->cng_hist_size_fx = 3; move16(); } test(); /*else if ( st_fx->max_SID_fx != 3 && st_fx->cnt_SID_fx == DTX_HIST_SIZE )//compile error */ - if( NE_16(st_fx->max_SID_fx,3)&&EQ_16(st_fx->cnt_SID_fx,DTX_HIST_SIZE)) + if( NE_16(hDtxEnc->max_SID_fx,3)&&EQ_16(hDtxEnc->cnt_SID_fx,DTX_HIST_SIZE)) { /* set the size of CNG history buffer for averaging to 3 frames */ - st_fx->cng_hist_size_fx = DTX_HIST_SIZE; + hDtxEnc->cng_hist_size_fx = DTX_HIST_SIZE; move16(); } } test(); - IF( st_fx->var_SID_rate_flag_fx == 0 && GT_16(st_fx->interval_SID_fx,1)) + IF(hDtxEnc->var_SID_rate_flag_fx == 0 && GT_16(hDtxEnc->interval_SID_fx,1)) { /* set the size of CNG history buffer for averaging to interval_SID frames */ - st_fx->cng_hist_size_fx = st_fx->interval_SID_fx; + hDtxEnc->cng_hist_size_fx = hDtxEnc->interval_SID_fx; move16(); - if ( GT_16(st_fx->cng_hist_size_fx, DTX_HIST_SIZE)) + if ( GT_16(hDtxEnc->cng_hist_size_fx, DTX_HIST_SIZE)) { - st_fx->cng_hist_size_fx = DTX_HIST_SIZE; + hDtxEnc->cng_hist_size_fx = DTX_HIST_SIZE; move16(); } } - IF( GE_16(st_fx->cnt_SID_fx,st_fx->max_SID_fx)) + IF( GE_16(hDtxEnc->cnt_SID_fx, hDtxEnc->max_SID_fx)) { /* adaptive SID update interval */ - st_fx->max_SID_fx = st_fx->interval_SID_fx; + hDtxEnc->max_SID_fx = hDtxEnc->interval_SID_fx; move16(); - st_fx->cnt_SID_fx = 0; + hDtxEnc->cnt_SID_fx = 0; move16(); } } @@ -661,7 +697,7 @@ void dtx_hangover_control_fx( Word16 Dlsp,Denr; Word16 lsf_tmp[M]; Word32 C[M]; - Word32 max[2]; + Word32 max_val[2]; Word16 max_idx[2]; Word16 ftmp_fx; Word16 Dlsp_n2e,Denr_n2e; @@ -669,11 +705,13 @@ void dtx_hangover_control_fx( Word16 S_max; Word16 S_tmp; Word32 L_tmp; - + VAD_HANDLE hVAD = st_fx->hVAD; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; /* get current frame exc energy in log2 */ - exp = norm_l(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx]); - fra = Log2_norm_lc(L_shl(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx],exp)); + exp = norm_l(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr_fx]); + fra = Log2_norm_lc(L_shl(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr_fx],exp)); exp = sub(sub(30,exp),6); L_tmp = L_Comp(exp,fra); enr_new = round_fx(L_shl(L_tmp,8)); /*Q8 */ @@ -685,20 +723,20 @@ void dtx_hangover_control_fx( } /* get energies and lsps of hangover frames */ - ptr = sub(st_fx->ho_circ_ptr_fx,sub(st_fx->burst_ho_cnt_fx,1)); + ptr = sub(hTdCngEnc->ho_circ_ptr_fx,sub(hTdCngEnc->burst_ho_cnt_fx,1)); IF ( ptr < 0 ) { - ptr = add(st_fx->ho_circ_size_fx,ptr); + ptr = add(hTdCngEnc->ho_circ_size_fx,ptr); } - FOR ( i=0; iburst_ho_cnt_fx-1; i++ ) + FOR ( i=0; i< hTdCngEnc->burst_ho_cnt_fx-1; i++ ) { - Copy( &(st_fx->ho_lsp_circ_fx[ptr*M]), &(tmp_lsp[i*M]), M ); - tmp_enr[i] = st_fx->ho_ener_circ_fx[ptr]; + Copy( &(hTdCngEnc->ho_lsp_circ_fx[ptr*M]), &(tmp_lsp[i*M]), M ); + tmp_enr[i] = hTdCngEnc->ho_ener_circ_fx[ptr]; move32();/*Q6 */ ptr = add(ptr,1); - if ( EQ_16(ptr,st_fx->ho_circ_size_fx)) + if ( EQ_16(ptr, hTdCngEnc->ho_circ_size_fx)) { ptr = 0; move16(); @@ -706,7 +744,7 @@ void dtx_hangover_control_fx( } /* get estimated CNG energy and lsps assuming terminate hangover at current frame */ - ptr = sub(st_fx->burst_ho_cnt_fx,2); + ptr = sub(hTdCngEnc->burst_ho_cnt_fx,2); enr_est = Mpy_32_16_1(tmp_enr[ptr],W_DTX_HO_FX[0]); /*Q6 */ weights = W_DTX_HO_FX[0]; move16();/*Q15 */ @@ -714,7 +752,7 @@ void dtx_hangover_control_fx( m = 1; move16(); - FOR ( i=1; iburst_ho_cnt_fx-2; i++ ) + FOR ( i=1; i< hTdCngEnc->burst_ho_cnt_fx-2; i++ ) { test(); IF ( LT_32(Mpy_32_16_1(tmp_enr[ptr-i],ONE_OVER_BUF_H_NRG_FX),tmp_enr[ptr])&& @@ -755,11 +793,11 @@ void dtx_hangover_control_fx( IF ( LT_16(m,3)) { - enr_est = L_add(Mpy_32_16_1(enr_est,26214),Mpy_32_16_1(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx],6554)); /*Q6 */ + enr_est = L_add(Mpy_32_16_1(enr_est,26214),Mpy_32_16_1(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr_fx],6554)); /*Q6 */ } ELSE { - enr_est = L_add(Mpy_32_16_1(enr_est,31130),Mpy_32_16_1(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx],1638)); /*Q6 */ + enr_est = L_add(Mpy_32_16_1(enr_est,31130),Mpy_32_16_1(hTdCngEnc->ho_ener_circ_fx[hTdCngEnc->ho_circ_ptr_fx],1638)); /*Q6 */ } exp = norm_l(enr_est); @@ -774,7 +812,7 @@ void dtx_hangover_control_fx( move16(); } - set32_fx( max, 0, 2 ); + set32_fx( max_val, 0, 2 ); set16_fx( max_idx, 0, 2 ); FOR( i=0; ilspCNG_fx[i],lsp_est[i])); /*Q15 */ + S_tmp = abs_s(sub(hDtxEnc->lspCNG_fx[i],lsp_est[i])); /*Q15 */ Dlsp = add(Dlsp,S_tmp); /*Q15 */ IF ( GT_16(S_tmp,S_max)) { @@ -887,37 +925,169 @@ void dtx_hangover_control_fx( } } - exp = norm_l(st_fx->lp_ener_fx); - fra = Log2_norm_lc(L_shl(st_fx->lp_ener_fx,exp)); + exp = norm_l(hTdCngEnc->lp_ener_fx); + fra = Log2_norm_lc(L_shl(hTdCngEnc->lp_ener_fx,exp)); exp = sub(sub(30,exp),6); L_tmp = L_Comp(exp,fra); S_tmp = round_fx(L_shl(L_tmp,8)); /*Q8 */ Denr = abs_s(sub(S_tmp,enr_est_log)); /*Q8 */ /* make decision if DTX hangover can be terminated */ - st_fx->hangover_terminate_flag_fx = 0; + hVAD->hangover_terminate_flag_fx = 0; move16(); /*Q0 */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test();test();test();test();test();test();test(); IF ( ( LT_16(Dlsp,13107)&<_16(Denr,359)&<_16(S_max,3277) && LT_16(Dlsp_n2e,13107) && LT_16(Denr_n2e,308) && st_fx->Opt_SC_VBR_fx == 1 ) || ( LT_16(Dlsp,13107) && LT_16(Denr,205) && LT_16(S_max,3277) && LT_16(Dlsp_n2e,13107) && LT_16(Denr_n2e,205) && st_fx->Opt_SC_VBR_fx == 0 ) ) { - st_fx->hangover_terminate_flag_fx = 1; + hVAD->hangover_terminate_flag_fx = 1; move16(); /*Q0 */ } return; } + +/*-------------------------------------------------------------------* + * td_cng_enc_init() + * + * + *-------------------------------------------------------------------*/ + +void td_cng_enc_init( + TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ + const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +) +{ + + hTdCngEnc->cng_seed_fx = RANDOM_INITSEED; + hTdCngEnc->cng_ener_seed_fx = RANDOM_INITSEED; + hTdCngEnc->cng_ener_seed1_fx = RANDOM_INITSEED; + hTdCngEnc->lp_ener_fx = 0; + hTdCngEnc->old_enr_index_fx = -1; + hTdCngEnc->Enew_fx = 0; + + hTdCngEnc->lp_sp_enr_fx = 0; + hTdCngEnc->last_allow_cn_step_fx = 0; + move16();move32();move16();move16();move32();move16();move16(); + + IF (Opt_DTX_ON) + { + hTdCngEnc->cng_hist_ptr_fx = -1; + move16(); + set16_fx(hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M); + set16_fx(hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE); + + hTdCngEnc->ho_hist_ptr_fx = -1; + move16(); + hTdCngEnc->ho_sid_bw_fx = L_deposit_l(0); + set16_fx(hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M); + set32_fx(hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE); + set32_fx(hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG); + hTdCngEnc->ho_hist_size_fx = 0; + move16(); + hTdCngEnc->act_cnt_fx = 0; + move16(); + + } + + set16_fx(hTdCngEnc->ho_16k_lsp_fx, 0, HO_HIST_SIZE); + hTdCngEnc->act_cnt2_fx = 0; + hTdCngEnc->num_ho_fx = 0; + move16(); + move16(); + + hTdCngEnc->ho_circ_ptr_fx = -1; + move16(); + set16_fx(hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M); + set32_fx(hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE); + set32_fx(hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG); + hTdCngEnc->ho_circ_size_fx = 0; + hTdCngEnc->burst_ho_cnt_fx = 0; + move16(); + move16(); + +#ifdef IVAS_CODE + hTdCngEnc->CNG_att_fx = 0; + hTdCngEnc->last_idx_ener_fx = 0; +#endif + + hTdCngEnc->cng_buf_cnt = 0; + + + set32_fx(hTdCngEnc->lp_env_fx, 0, 20); + set32_fx(hTdCngEnc->cng_res_env_fx, 0, 20 * 8); + set16_fx(hTdCngEnc->exc_mem_fx, 0, 24); + set16_fx(hTdCngEnc->exc_mem1_fx, 0, 30); + set16_fx(hTdCngEnc->exc_mem2_fx, 0, 30); + set32_fx(hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG); + + /* SWB CNG/DTX */ + hTdCngEnc->last_wb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->last_shb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->mov_wb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->mov_shb_cng_ener_fx = -1541; + move16(); /* Q8 */ + hTdCngEnc->shb_cng_ini_cnt_fx = 1; + move16(); + hTdCngEnc->shb_NO_DATA_cnt_fx = 0; + move16(); + hTdCngEnc->last_SID_bwidth_fx = s_min(max_bwidth, SWB); + hTdCngEnc->last_vad_fx = 0; + move16(); + + return; +} + +/*-------------------------------------------------------------------* + * dtx_enc_init() + * + * Initialize DTX parameters + *-------------------------------------------------------------------*/ + +void dtx_enc_init( + Encoder_State_fx* st, /* i : Encoder state handle */ + const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ + const Word16 interval_SID /* i : interval for SID update */ +) +{ + DTX_ENC_HANDLE hDtxEnc; + hDtxEnc = st->hDtxEnc; + + hDtxEnc->first_CNG_fx = 0; move16(); + hDtxEnc->cnt_SID_fx = 0; move16(); + hDtxEnc->max_SID_fx = 2; move16(); + hDtxEnc->CNG_mode_fx = -1; move16(); + Copy(st->lsp_old1_fx, hDtxEnc->lspCNG_fx, M); + hDtxEnc->VarDTX_cnt_voiced_fx = 0; move16(); + hDtxEnc->VarDTX_cnt_noise_fx = 0; move16(); + hDtxEnc->lt_ener_voiced_fx = 0; move16(); + hDtxEnc->lt_ener_noise_fx = 0; move16(); + hDtxEnc->frame_ener_fx = 0; move16(); + hDtxEnc->lt_ener_last_SID_fx = 0; move16(); + hDtxEnc->last_CNG_L_frame_fx = L_FRAME; move16(); + hDtxEnc->var_SID_rate_flag_fx = var_SID_rate_flag; move16(); + hDtxEnc->last_active_brate_fx = ACELP_7k20; move16(); + hDtxEnc->cng_cnt_fx = 0; move16(); + + IF (hDtxEnc->var_SID_rate_flag_fx) + { + hDtxEnc->interval_SID_fx = 12; move16(); move16(); + hDtxEnc->cng_hist_size_fx = DTX_HIST_SIZE; + } + ELSE + { + hDtxEnc->interval_SID_fx = interval_SID; move16(); + if (GE_16(hDtxEnc->interval_SID_fx, DTX_HIST_SIZE)) + { + hDtxEnc->cng_hist_size_fx = hDtxEnc->interval_SID_fx; move16(); + } + } + return; +} \ No newline at end of file diff --git a/lib_enc/enc_acelp.c b/lib_enc/enc_acelp.c index 6719b1e..6adb6b1 100644 --- a/lib_enc/enc_acelp.c +++ b/lib_enc/enc_acelp.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include #include -#include "stl.h" -#include "prot_fx.h" +#include "typedef.h" +#include #include "options.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" #include "rom_enc_fx.h" @@ -72,6 +71,7 @@ void E_ACELP_h_vec_corr1(Word16 h[], Word16 vec[], UWord8 track, cor[j] = corr; move16(); } + return; } void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, @@ -111,6 +111,7 @@ void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, pos = add(pos,4); } + return; } @@ -237,6 +238,7 @@ static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, *alp = alpk[ik]; move16(); + return; } @@ -345,8 +347,10 @@ static void E_ACELP_1pulse_search(UWord8 tracks[2], move16(); *ix = x_save; move16(); + return; } + /* * E_ACELP_xh_corr * @@ -407,6 +411,7 @@ static void E_ACELP_xh_corr(Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr) j = sub(norm_l(L_tot), 4+16); /* 4 -> 16 x tot */ Copy_Scale_sig_32_16(y32, y, L_subfr, j); + return; } /** @@ -624,6 +629,7 @@ void E_ACELP_xy2_corr(Word16 xn[], Word16 y1[], Word16 y2[], BASOP_SATURATE_ERROR_OFF; + return; } @@ -1005,6 +1011,7 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 E_ACELP_apply_sign(p3, psign3); p3 += 16; } + return; } void E_ACELP_4tsearch(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], @@ -1320,6 +1327,7 @@ void E_ACELP_4tsearch(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 c move16(); } } + return; } @@ -1359,7 +1367,6 @@ void E_ACELP_4tsearch(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 c * Returns: * void */ -static void E_ACELP_4t( Word16 dn[], Word16 cn[] /* Q_xn */, Word16 H[], Word16 R[], Word8 acelpautoc, @@ -1368,7 +1375,8 @@ void E_ACELP_4t( ,const Word16 L_frame, const Word16 last_L_frame, const Word32 total_brate, - const Word16 i_subfr + const Word16 i_subfr, + const int16_t cmpl_flag ) { PulseConfig config; @@ -1393,6 +1401,12 @@ void E_ACELP_4t( move16(); memcpy(&config, &PulseConfTable[cdk_index], sizeof(PulseConfTable[cdk_index])); + + if (cmpl_flag > 0) + { + config.nbiter = cmpl_flag; + move16(); + } test(); test(); IF( NE_16(L_frame,last_L_frame)&&EQ_32(total_brate,ACELP_24k40)&<_32(i_subfr,5*L_SUBFR)) @@ -1410,6 +1424,7 @@ void E_ACELP_4t( E_ACELP_4tsearch(dn, cn, H, code, &config, ind, y); } E_ACELP_indexing(code, &config, NB_TRACK_FCB_4T, _index); + return; } static void E_ACELP_indexing_shift( @@ -1433,6 +1448,7 @@ static void E_ACELP_indexing_shift( } dst[i] = s_or(lshl(src[i], shift_bits), lsb_bits); move16(); + return; } #define MAX_IDX_LEN 9 @@ -1751,43 +1767,37 @@ void E_ACELP_adaptive_codebook( * Find innovative codebook. *--------------------------------------------------------------------------*/ void E_ACELP_innovative_codebook( - Word16 *exc, /* i : pointer to the excitation frame Q_new */ - Word16 T0, /* i : integer pitch lag Q0 */ - Word16 T0_frac, /* i : fraction of lag Q0 */ - Word16 T0_res, /* i : pitch resolution Q0 */ - Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ - Word16 tilt_code, /* i : tilt factor Q15 */ - Word16 mode, /* i : innovative codebook mode Q0 */ - Word16 formant_enh, /* i : use formant enhancement Q0 */ - Word16 formant_tilt, /* i : use tilt of formant enhancement Q0 */ - const Word16 formant_enh_num, /* i : formant sharpening numerator weighting */ - const Word16 formant_enh_den, /* i : formant sharpening denominator weighting */ - Word16 pitch_sharpening, /* i : use pitch sharpening Q0 */ - Word16 pre_emphasis, - Word16 phase_scrambling, - Word16 i_subfr, /* i : subframe index */ - const Word16 *Aq, /* i : quantized LPC coefficients 3Q12 */ - Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ - Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ - Word16 *cn, /* i : Innovative codebook search target vector Q_new */ - Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn */ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9 */ - Word8 acelpautoc, /* i : autocorrelation mode enabled */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *code, /* o : innovative codebook Q9 Q9 */ - Word16 shift /* i : Scaling to get 12 bits */ - ,const Word16 L_frame, /* i : length of the frame */ + Word16 *exc, /* i : pointer to the excitation frame Q_new */ + Word16 T0, /* i : integer pitch lag Q0 */ + Word16 T0_frac, /* i : fraction of lag Q0 */ + Word16 T0_res, /* i : pitch resolution Q0 */ + Word16 pitch_gain, /* i : adaptive codebook gain 1Q14 */ + Word16 tilt_code, /* i : tilt factor Q15 */ + ACELP_config* acelp_cfg,/* i/o: configuration of the ACELP */ + Word16 i_subfr, /* i : subframe index */ + const Word16 *Aq, /* i : quantized LPC coefficients 3Q12 */ + Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ + Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ + Word16 *cn, /* i : Innovative codebook search target vector Q_new */ + Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn */ + Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9 */ + Word8 acelpautoc, /* i : autocorrelation mode enabled */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *code, /* o : innovative codebook Q9 Q9 */ + Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 L_frame, /* i : length of the frame */ const Word16 last_L_frame,/* i : length of the last frame */ const Word32 total_brate /* i : ttoal bit-rate */ ) { Word16 xn2[L_SUBFR] /* Q_xn */, cn2[L_SUBFR] /* Q_xn */, dn[L_SUBFR] /* Rw2*cn2 */, h2[L_SUBFR] /* 4Q11 */; Word16 Rw2[L_SUBFR]; - Word16 pitch; + Word16 pitch, idx; pitch = T0; move16(); + idx = shr(i_subfr, 6); if (GT_16(T0_frac, shr(T0_res, 1))) { pitch = add(pitch,1); @@ -1796,13 +1806,13 @@ void E_ACELP_innovative_codebook( BASOP_SATURATE_ERROR_ON; /* Update target vector for ACELP codebook search */ - E_ACELP_codebook_target_update(xn, xn2, y1, gain_pit, L_SUBFR); + E_ACELP_codebook_target_update(xn, xn2, y1, pitch_gain, L_SUBFR); /* Include fixed-gain pitch contribution into impulse resp. h1[] */ Copy_Scale_sig(h1, h2, L_SUBFR, sub(-3, shift)); /*h2 1Q14+shift -> 4Q11, 1bit of headroom for Residu and xh_corr*/ - cb_shape_fx(pre_emphasis, pitch_sharpening, phase_scrambling, formant_enh, formant_tilt, - formant_enh_num, formant_enh_den, Aq, h2, tilt_code, pitch, 1); + cb_shape_fx(acelp_cfg->pre_emphasis, acelp_cfg->pitch_sharpening, acelp_cfg->phase_scrambling, acelp_cfg->formant_enh, acelp_cfg->formant_tilt, + acelp_cfg->formant_enh_num, acelp_cfg->formant_enh_den, Aq, h2, tilt_code, pitch, 1, L_SUBFR); /* Correlation between target xn2[] and impulse response h1[] */ IF (acelpautoc) @@ -1813,22 +1823,22 @@ void E_ACELP_innovative_codebook( E_ACELP_conv(xn2, h2, cn2); /* dn_e -> Rw2_e*Q_xn */ - /*dn_e = */ E_ACELP_toeplitz_mul(Rw2,cn2,dn,L_SUBFR,sub((Word16)PulseConfTable[mode].nb_pulse, 24) > 0); + /*dn_e = */ E_ACELP_toeplitz_mul(Rw2,cn2,dn,L_SUBFR,sub((Word16)PulseConfTable[acelp_cfg->fixed_cdk_index[idx]].nb_pulse, 24) > 0); } ELSE { BASOP_SATURATE_WARNING_OFF; - E_ACELP_codebook_target_update(cn, cn2, &exc[i_subfr], gain_pit, L_SUBFR); + E_ACELP_codebook_target_update(cn, cn2, &exc[i_subfr], pitch_gain, L_SUBFR); BASOP_SATURATE_WARNING_ON; Scale_sig(cn2, L_SUBFR, shift); E_ACELP_xh_corr(xn2, dn, h2, L_SUBFR); } /* Innovative codebook search */ - assert(mode < ACELP_FIXED_CDK_NB); + assert(acelp_cfg->fixed_cdk_index[idx] < ACELP_FIXED_CDK_NB); - E_ACELP_4t( dn, cn2, h2, Rw2, acelpautoc, code, mode, *pt_indice, L_frame, last_L_frame, total_brate, i_subfr ); + E_ACELP_4t( dn, cn2, h2, Rw2, acelpautoc, code, acelp_cfg->fixed_cdk_index[idx], *pt_indice, L_frame, last_L_frame, total_brate, i_subfr, 0 ); *pt_indice += 8; @@ -1839,10 +1849,11 @@ void E_ACELP_innovative_codebook( * - Add the fixed-gain pitch contribution to code[]. * *-------------------------------------------------------*/ - cb_shape_fx(pre_emphasis, pitch_sharpening, phase_scrambling, formant_enh, formant_tilt, - formant_enh_num, formant_enh_den, Aq, code, tilt_code, pitch, 1); + cb_shape_fx(acelp_cfg->pre_emphasis, acelp_cfg->pitch_sharpening, acelp_cfg->phase_scrambling, acelp_cfg->formant_enh, acelp_cfg->formant_tilt, + acelp_cfg->formant_enh_num, acelp_cfg->formant_enh_den, Aq, code, tilt_code, pitch, 1, L_SUBFR); BASOP_SATURATE_ERROR_OFF; + return; } @@ -1898,7 +1909,7 @@ void E_ACELP_codearithp(const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p) Carry = 0; s = L_add_c(s, pulsestostates[pos[k]][t]); t = add(t, 1); - if( sub(t, NPMAXPT) >= 0 ) + if( sub(t, NPMAXPT) > 0 ) { BREAK; } @@ -1931,6 +1942,7 @@ void E_ACELP_codearithp(const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p) *p = nb_pulse; move16(); + return; } void fcb_pulse_track_joint(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num) @@ -2046,4 +2058,5 @@ void fcb_pulse_track_joint(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word idxs[track] = extract_l(index); index = L_lshr(index, 16); } + return; } diff --git a/lib_enc/enc_acelp_tcx_main.c b/lib_enc/enc_acelp_tcx_main.c index 7a3d82d..35da5fd 100644 --- a/lib_enc/enc_acelp_tcx_main.c +++ b/lib_enc/enc_acelp_tcx_main.c @@ -2,72 +2,62 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include -#include "prot_fx.h" +#include #include "options.h" +#include "prot_fx.h" #include "cnst_fx.h" -#include "stl.h" - +/*-------------------------------------------------------------------* + * enc_acelp_tcx_main() + * + * encoder function for coding ACELP/TCX + *--------------------------------------------------------------------*/ void enc_acelp_tcx_main( - const Word16 new_samples[], /* i : new samples */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: FD CNG handle */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[], /* o : floating pitch for each subframe */ - Word16 vad_hover_flag, - const Word16 vad_flag_dtx, + const Word16 new_samples[], /* i : new samples */ + Encoder_State_fx *st, /* i/o: encoder state structure */ + Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ + const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 pitch_buf[], /* o : floating pitch for each subframe */ + Word16 vad_hover_flag, /* i : VAD hangover flag */ Word16 *Q_new, Word16 *shift ) { Word16 old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ Word16 *ptr_bwe_exc; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2; IF( EQ_16( st->last_core_fx, ACELP_CORE)) { set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); - Copy( st->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + Copy(hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); } ELSE { set16_fx( old_bwe_exc, 0, ((L_FRAME16k + 1) + L_SUBFR16k + PIT16k_MAX) * 2 ); } - /* PLC: [Guided ACELP PLC] */ - gPLC_encInfo(&st->plcExt, - st->total_brate_fx, - st->bwidth_fx, - st->clas_fx, - coder_type - ); - + if (st->hPlcExt) + {/* PLC: [Guided ACELP PLC] */ + gPLC_encInfo(st->hPlcExt ,st->total_brate_fx, st->bwidth_fx, st->clas_fx, st->coder_type); + } IF ( s_and(st->core_brate_fx!=FRAME_NO_DATA, st->core_brate_fx!=SID_2k40) ) { /* Run Core Coder */ IF (st->tcxonly == 0) { - core_encode_openloop( st, coder_type, - pitch, - voicing, Aw, lsp_new, lsp_mid, - pitch_buf, voice_factors, ptr_bwe_exc, - vad_hover_flag, vad_flag_dtx, *Q_new, *shift ); + core_encode_openloop( st, st->coder_type, Aw, lsp_new, lsp_mid, pitch_buf, voice_factors, ptr_bwe_exc, + vad_hover_flag, st->vad_flag, *Q_new, *shift ); } ELSE { - core_encode_twodiv( new_samples, - st, coder_type, pitch, voicing, Aw, Q_new, shift ); + core_encode_twodiv( new_samples, st,st->coder_type, Aw, vad_hover_flag, Q_new, shift ); } /*-----------------------------------------------------------------* * Apply non linearity to the SHB excitation @@ -77,18 +67,17 @@ void enc_acelp_tcx_main( test(); IF( EQ_16( st->core_fx, ACELP_CORE )&&st->igf!=0) { - non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale_fx, *Q_new - , coder_type, voice_factors, st->L_frame_fx - ); + non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new + , st->coder_type, voice_factors, st->L_frame_fx); /* update the old BWE exe memory */ - Copy( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } ELSE { - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - set16_fx( st->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st->bwe_non_lin_prev_scale_fx = 0; + set16_fx(hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + set16_fx(hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; } } ELSE @@ -96,18 +85,19 @@ void enc_acelp_tcx_main( /* Run SID Coder */ IF ( st->core_brate_fx == SID_2k40 ) { - FdCng_encodeSID( hFdCngEnc, st, st->preemph_fac ); + FdCng_encodeSID( st->hFdCngEnc_fx, st, st->preemph_fac ); } /* Generate Comfort Noise */ generate_comfort_noise_enc( st, *Q_new, 1 ); /* Update Core Encoder */ - core_encode_update_cng( st, hFdCngEnc->hFdCngCom->timeDomainBuffer, hFdCngEnc->hFdCngCom->A_cng, Aw, *Q_new, *shift ); + core_encode_update_cng( st, st->hFdCngEnc_fx->hFdCngCom->timeDomainBuffer, st->hFdCngEnc_fx->hFdCngCom->A_cng, Aw, *Q_new, *shift ); } /* coreSwitching update of MODE1 parameters in the last frame */ - st->last_coder_type_fx = coder_type; + st->last_coder_type_fx = st->coder_type; + move16(); return; diff --git a/lib_enc/enc_acelpx.c b/lib_enc/enc_acelpx.c index 7d66440..da522e6 100644 --- a/lib_enc/enc_acelpx.c +++ b/lib_enc/enc_acelpx.c @@ -2,17 +2,21 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include -#include -#include "stl.h" +#include +#include "options.h" #include "prot_fx.h" #include "basop_util.h" #include "options.h" #include "rom_enc_fx.h" -#define _1_Q11 (2048/*1.0f Q11*/) /* 1.0f in 4Q11 */ +/*--------------------------------------------------------------------------------------* + * Local constant + *--------------------------------------------------------------------------------------*/ +#define _1_Q11 (2048/*1.0f Q11*/) /* 1.0f in 4Q11 */ +/*--------------------------------------------------------------------------------------* + * E_ACELP_update_cor + *--------------------------------------------------------------------------------------*/ static void E_ACELP_update_cor( const Word16 pos[], /* i */ Word16 nb_pulse, /* i */ @@ -106,13 +110,25 @@ static void E_ACELP_update_cor( assert(!"Number of pulses not supported"); } } - - -/* Iterations: nb_pos_ix*16 */ -static void E_ACELP_2pulse_searchx(Word16 nb_pos_ix, Word16 track_x, - Word16 track_y, Word16 *R, Word16 *ps, Word16 *alp, - Word16 *ix, Word16 *iy, Word16 dn[], - Word16 *dn2, Word16 cor[], Word16 sign[], Word16 sign_val_2) +/*--------------------------------------------------------------------------------------* + * E_ACELP_2pulse_searchx + * Iterations: nb_pos_ix*16 + *--------------------------------------------------------------------------------------*/ +static void E_ACELP_2pulse_searchx( + const Word16 nb_pos_ix, + const Word16 track_x, + const Word16 track_y, + Word16 *R, + Word16 *ps, + Word16 *alp, + Word16 *ix, + Word16 *iy, + Word16 dn[], + Word16 *dn2, + Word16 cor[], + Word16 sign[], + Word16 sign_val_2 +) { Word16 i,x; Word32 y; @@ -239,12 +255,20 @@ static void E_ACELP_2pulse_searchx(Word16 nb_pos_ix, Word16 track_x, assert(((pos[0] & 3) == track_x) && ((pos[1] & 3) == track_y)); /* sanity check */ } - -/* static */ -static void E_ACELP_1pulse_searchx(UWord8 tracks[2], - Word16 *R, Word16 *ps, Word16 *alp, - Word16 *ix, Word16 dn[], - Word16 cor[], Word16 sign[], Word16 sign_val_1) +/*--------------------------------------------------------------------------------------* + * E_ACELP_1pulse_searchx + *--------------------------------------------------------------------------------------*/ +static void E_ACELP_1pulse_searchx( + UWord8 tracks[2], + Word16 *R, + Word16 *ps, + Word16 *alp, + Word16 *ix, + Word16 dn[], + Word16 cor[], + Word16 sign[], + Word16 sign_val_1 +) { Word16 x, x_save = 0; Word16 ps0; @@ -326,10 +350,19 @@ static void E_ACELP_1pulse_searchx(UWord8 tracks[2], move16(); } - -/* Autocorrelation method for searching pulse positions effectively - * Algorithm is identical to traditional covariance method. */ -void E_ACELP_4tsearchx(Word16 dn[], const Word16 cn[], Word16 Rw[], Word16 code[], const PulseConfig *config, Word16 ind[]) +/*--------------------------------------------------------------------------------------* + * E_ACELP_4tsearchx + * Autocorrelation method for searching pulse positions effectively + * Algorithm is identical to traditional covariance method + *--------------------------------------------------------------------------------------*/ +void E_ACELP_4tsearchx( + Word16 dn[], + const Word16 cn[], + Word16 Rw[], + Word16 code[], + const PulseConfig *config, + Word16 ind[] +) { Word16 sign[L_SUBFR], vec[L_SUBFR]; Word16 cor[L_SUBFR]; @@ -353,6 +386,7 @@ void E_ACELP_4tsearchx(Word16 dn[], const Word16 cn[], Word16 Rw[], Word16 code[ alp = config->alp; /* Q13 */ move16(); nb_pulse = config->nb_pulse; move16(); + move16(); nb_pulse_m2 = sub(nb_pulse, 2); /* Init to avoid crash when the search does not find a solution */ diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index 45b8af1..94db9d5 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required by wmc_tool */ /*-------------------------------------------------------------------* * encod_amr_wb() @@ -14,20 +13,17 @@ * Encode excitation signal in AMR-WB IO mode *-------------------------------------------------------------------*/ void encod_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[], /* i : voicing */ - const Word16 *res, /* i : residual signal */ - Word16 *syn, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *exc2, /* i/o: current enhanced excitation */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - const Word16 *speech16k_fx, + Encoder_State_fx *st, /* i/o: state structure */ + const Word16 speech[], /* i : input speech */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, /* i : residual signal */ + Word16 *syn, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *exc2, /* i/o: current enhanced excitation */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ + Word16 hf_gain_fx[NB_SUBFR],/* o : decoded HF gain */ + const Word16 *speech16k_fx, /* i : input speech @16kHz */ Word16 shift, Word16 Q_new ) @@ -61,6 +57,10 @@ void encod_amr_wb_fx( Word32 Lgcode; Word16 T_op[3]; /* pitch period for quantization */ Word16 lp_select, lp_flag; + VAD_HANDLE hVAD = st->hVAD; + AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; + BSTR_ENC_HANDLE hBstr = st->hBstr; + LPD_state_HANDLE hLPDmem = st->hLPDmem; /*------------------------------------------------------------------* * Initializations @@ -83,7 +83,7 @@ void encod_amr_wb_fx( pt_pitch = pitch_buf; shift_wsp = add(Q_new,shift); - Copy( pitch, T_op, 2 ); + Copy(st->pitch_fx, T_op, 2 ); if (LE_16(T_op[0],PIT_MIN)) { T_op[0] = shl(T_op[0],1); @@ -96,7 +96,19 @@ void encod_amr_wb_fx( T_op[1] = shl(T_op[1],1); move16(); } + st->acelp_cfg.fcb_mode = 0; /* flag used in inov_encode() */ + + /*-----------------------------------------------------------------* + * Select LP filtering flag + *-----------------------------------------------------------------*/ + lp_flag = NORMAL_OPERATION; + if (LT_32(st->core_brate_fx, ACELP_11k60)) + { + lp_flag = LOW_PASS; + move16(); + } + /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ @@ -110,7 +122,7 @@ void encod_amr_wb_fx( *----------------------------------------------------------------*/ Copy( &res[i_subfr], &exc[i_subfr], L_SUBFR ); - find_targets_fx( speech, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq, + find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, L_SUBFR, p_Aw, TILT_FAC_FX, xn, cn, h1 ); Copy_Scale_sig(h1, h2, L_SUBFR, -2); @@ -124,8 +136,9 @@ void encod_amr_wb_fx( * Adaptive exc. construction *----------------------------------------------------------------*/ - *pt_pitch = pit_encode_fx(st, st->core_brate_fx, 1, L_FRAME, -1, &pitch_limit_flag, i_subfr, exc, - L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn ); + *pt_pitch = pit_encode_fx(hBstr, st->acelp_cfg.pitch_bits, st->core_brate_fx, 1, L_FRAME, -1, &pitch_limit_flag, i_subfr, exc, + L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn + , 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, NULL /*hStereoTD->tdm_Pri_pitch_buf*/); /*-----------------------------------------------------------------* * Find adaptive exitation @@ -138,38 +151,38 @@ void encod_amr_wb_fx( * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = gp_clip_fx( st->core_brate_fx, voicing, i_subfr, 0, xn, st->clip_var_fx, sub(shift_wsp,1)); + clip_gain = gp_clip_fx(st->element_mode, st->core_brate_fx, st->voicing_fx, i_subfr, 0, xn, st->clip_var_fx, sub(shift_wsp,1)); /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ - lp_select = lp_filt_exc_enc_fx( MODE1, st->core_brate_fx, 1, -1, i_subfr, exc, h1, + lp_select = lp_filt_exc_enc_fx( MODE1, -1, i_subfr, exc, h1, xn, y1, xn2, L_SUBFR, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); IF( EQ_16(lp_flag,NORMAL_OPERATION)) { - push_indice_fx( st, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ inov_encode_fx( st, st->core_brate_fx, 1, L_FRAME, st->last_L_frame_fx, -1, -1, 0, i_subfr, -1, p_Aq, gain_pit, cn, - exc, h2, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, shift ); + exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, L_SUBFR, shift ); /*-----------------------------------------------------------------* * Gain encoding * Pitch gain clipping test * Estimate spectrum tilt and voicing *-----------------------------------------------------------------*/ - gain_enc_amr_wb_fx( st, xn, shift_wsp, y1, y2, code, st->core_brate_fx, &gain_pit, &gain_code, - &gain_inov, &norm_gain_code, g_corr, clip_gain, st->past_qua_en_fx ); + gain_enc_amr_wb_fx(hBstr, xn, shift_wsp, y1, y2, code, st->core_brate_fx, &gain_pit, &gain_code, + &gain_inov, &norm_gain_code, g_corr, clip_gain, hAmrwb_IO->past_qua_en_fx ); - gp_clip_test_gain_pit_fx( st->core_brate_fx, gain_pit, st->clip_var_fx ); + gp_clip_test_gain_pit_fx(st->element_mode, st->core_brate_fx, gain_pit, st->clip_var_fx ); Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx(Lgcode); - mem->tilt_code = Est_tilt2( exc+i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); + hLPDmem->tilt_code = Est_tilt2( exc+i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); FOR (i = 0; i < L_SUBFR; i++) { @@ -187,7 +200,7 @@ void encod_amr_wb_fx( Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); Ltmp = L_msu(Ltmp, y1[L_SUBFR - 1], gain_pit); Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ /*-----------------------------------------------------------------* * Find the total excitation @@ -205,7 +218,7 @@ void encod_amr_wb_fx( * Synthesize speech to update mem_syn[] * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + Syn_filt_s(1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); /*-----------------------------------------------------------------* * HF gain modification factors at 23.85 kbps @@ -216,11 +229,11 @@ void encod_amr_wb_fx( IF( GE_32(st->input_Fs_fx,16000)) { hf_cod_fx( st->core_brate_fx, &speech16k_fx[i_subfr * L_SUBFR16k/L_SUBFR], Aq, &exc[i_subfr], &syn[i_subfr], - &st->seed2_enc_fx, st->mem_hp400_enc_fx, st->mem_syn_hf_enc_fx, st->mem_hf_enc_fx, st->mem_hf2_enc_fx, - st->hangover_cnt_fx, &st->gain_alpha_fx, &hf_gain_fx[i_subfr/L_SUBFR], add(Q_new,1), st->Q_syn); + &hAmrwb_IO->seed2_enc_fx, hAmrwb_IO->mem_hp400_enc_fx, hAmrwb_IO->mem_syn_hf_enc_fx, hAmrwb_IO->mem_hf_enc_fx, hAmrwb_IO->mem_hf2_enc_fx, + hVAD->hangover_cnt_fx, &hAmrwb_IO->gain_alpha_fx, &hf_gain_fx[i_subfr/L_SUBFR], add(Q_new,1), st->Q_syn); } - push_indice_fx(st, IND_HF_GAIN_MODIFICATION, hf_gain_fx[i_subfr/L_SUBFR], 4 ); + push_indice_fx(hBstr, IND_HF_GAIN_MODIFICATION, hf_gain_fx[i_subfr/L_SUBFR], 4 ); } p_Aw += (M+1); diff --git a/lib_enc/enc_gain.c b/lib_enc/enc_gain.c index 23c64cb..72ce4b8 100644 --- a/lib_enc/enc_gain.c +++ b/lib_enc/enc_gain.c @@ -2,16 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include #include -#include -#include "stl.h" +#include +#include "options.h" #include "prot_fx.h" #include "rom_com_fx.h" #include "basop_util.h" - /* * E_GAIN_norm_corr * diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index f34d500..bf2a3a5 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -1,14 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - /*======================================================================*/ /* FUNCTION : encod_gen_voic_fx() */ @@ -51,24 +49,20 @@ void encod_gen_voic_fx( Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* o : formant sharpening flag */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ + const Word16 speech_fx[], /* i : input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *res_fx, /* i : residual signal */ + Word16 *syn_fx, /* i/o: core synthesis */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits_fx, /* i/o: number of unused bits */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 shift, Word16 Q_new ) @@ -107,7 +101,11 @@ void encod_gen_voic_fx( Word16 tmp1_fx; Word16 shift_wsp; Word16 harm_flag_acelp; - Word16 lp_select, lp_flag; + Word16 lp_select, lp_flag, L_frame; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; /*------------------------------------------------------------------* * Initializations @@ -122,8 +120,11 @@ void encod_gen_voic_fx( move16(); error_fx = 0; move16(); + L_frame = st_fx->L_frame_fx; + move16(); - IF( EQ_16(L_frame_fx,L_FRAME)) + + IF( EQ_16(L_frame,L_FRAME)) { T0_max_fx = PIT_MAX; move16(); @@ -137,6 +138,11 @@ void encod_gen_voic_fx( T0_min_fx = PIT16k_MIN; move16(); } + lp_flag = st_fx->acelp_cfg.ltf_mode; + move16(); + + *unbits_fx = 0; + move16(); p_Aw_fx = Aw_fx; p_Aq_fx = Aq_fx; @@ -152,7 +158,7 @@ void encod_gen_voic_fx( move16(); test(); test(); - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)&&LE_32(st_fx->core_brate_fx,ACELP_32k)&&EQ_16(coder_type_fx,GENERIC)) + IF( GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate_fx, MAX_BRATE_AVQ_EXC_TD) && EQ_16(st_fx->coder_type,GENERIC)) { if( GT_16(st_fx->last_harm_flag_acelp_fx,2)) { @@ -160,14 +166,14 @@ void encod_gen_voic_fx( move16(); } - push_indice_fx( st_fx, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); + push_indice_fx(hBstr, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); } /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - FOR( i_subfr_fx=0; i_subfr_fxmem_syn, i_subfr_fx, &mem->mem_w0, p_Aq_fx, + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); @@ -187,10 +193,10 @@ void encod_gen_voic_fx( /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); - *pt_pitch_fx = pit_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, coder_type_fx, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, T_op_fx, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx ); + *pt_pitch_fx = pit_encode_fx(hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate_fx, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, + L_SUBFR, st_fx->pitch_fx, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx , tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); - tbe_celp_exc(L_frame_fx,i_subfr_fx,T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); + tbe_celp_exc(L_frame,i_subfr_fx,T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); /*-----------------------------------------------------------------* * Find adaptive exitation @@ -202,9 +208,9 @@ void encod_gen_voic_fx( * Gain clipping test to avoid unstable synthesis on frame erasure *-----------------------------------------------------------------*/ - clip_gain_fx = gp_clip_fx(st_fx->core_brate_fx,voicing_fx,i_subfr_fx,coder_type_fx,xn_fx,st_fx->clip_var_fx,sub(shift_wsp, 1)); + clip_gain_fx = gp_clip_fx(st_fx->element_mode, st_fx->core_brate_fx, st_fx->voicing_fx,i_subfr_fx,st_fx->coder_type,xn_fx,st_fx->clip_var_fx,sub(shift_wsp, 1)); - if( EQ_16(coder_type_fx,INACTIVE)) + if( EQ_16(st_fx->coder_type,INACTIVE)) { /* in case of AVQ inactive, limit the gain to 0.65 */ clip_gain_fx = 2; @@ -215,36 +221,35 @@ void encod_gen_voic_fx( * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ - lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->core_brate_fx, 0, coder_type_fx, i_subfr_fx, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame_fx, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag ); + lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->coder_type, i_subfr_fx, exc_fx, h1_fx, + xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag ); IF( EQ_16(lp_flag,NORMAL_OPERATION)) { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ - st_fx->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, st_fx->lowrate_pitchGain), 6554, gain_pit_fx)); /*Q14*Q16(0.1) + Q15 -> Q15*/ + hSpMusClas->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, hSpMusClas->lowrate_pitchGain), 6554, gain_pit_fx)); /*Q14*Q16(0.1) + Q15 -> Q15*/ /*-----------------------------------------------------------------* * Transform domain contribution encoding - active frames *-----------------------------------------------------------------*/ test(); - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)&&NE_16(coder_type_fx,INACTIVE)) + IF( GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC )&& NE_16(st_fx->coder_type,INACTIVE)) { - transf_cdbk_enc_fx( st_fx, st_fx->core_brate_fx, st_fx->extl_fx, coder_type_fx, harm_flag_acelp, i_subfr_fx, -1, cn_fx, exc_fx, - p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, - &(st_fx->mem_deemp_preQ_fx), &(st_fx->mem_preemp_preQ_fx), &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); + transf_cdbk_enc_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, + xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); } /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ - inov_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, st_fx->last_L_frame_fx, - coder_type_fx, st_fx->bwidth_fx, sharpFlag_fx, i_subfr_fx, -1, p_Aq_fx, - gain_pit_fx, cn_fx, exc_fx, h2_fx, mem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, shift ); + inov_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame, st_fx->last_L_frame_fx, + st_fx->coder_type, st_fx->bwidth_fx, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx, + gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift ); /*-----------------------------------------------------------------* * Gain encoding @@ -252,43 +257,44 @@ void encod_gen_voic_fx( IF ( LE_32(st_fx->core_brate_fx,ACELP_8k00)) { - gain_enc_lbr_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx ); + gain_enc_lbr_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, + &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx, L_SUBFR ); } ELSE IF ( GT_32(st_fx->core_brate_fx,ACELP_32k)) { - gain_enc_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, -1, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx, + gain_enc_SQ_fx(hBstr, st_fx->acelp_cfg.gains_mode, i_subfr_fx, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx, shift_wsp ); } ELSE { - gain_enc_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type_fx, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx ); + gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx, + &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx ); } - - if ( EQ_16(st_fx->last_ppp_mode_fx,1)) + IF (st_fx->Opt_SC_VBR_fx) { - /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ - st_fx->clip_var_fx[1] = gain_pit_fx; - move16(); + if (EQ_16(hSC_VBR->last_ppp_mode_fx, 1)) + { + /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ + st_fx->clip_var_fx[1] = gain_pit_fx; + move16(); + } } - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, gain_pit_fx, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate_fx, gain_pit_fx, st_fx->clip_var_fx ); Lgcode = L_shl(gain_code_fx, Q_new); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx(Lgcode); - mem->tilt_code = Est_tilt2(&exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift); + hLPDmem->tilt_code = Est_tilt2(&exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift); /*-----------------------------------------------------------------* * Transform domain contribution encoding - inactive frames *-----------------------------------------------------------------*/ test(); - IF ( GT_32(st_fx->core_brate_fx,ACELP_24k40)&&EQ_16(coder_type_fx,INACTIVE)) + IF ( GE_32(st_fx->core_brate_fx, MAX_GSC_INACTIVE_BRATE) && EQ_16(st_fx->coder_type,INACTIVE)) { - transf_cdbk_enc_fx( st_fx, st_fx->core_brate_fx, st_fx->extl_fx, coder_type_fx, 0, i_subfr_fx, -1, cn_fx, exc_fx, - p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, - &(st_fx->mem_deemp_preQ_fx), &(st_fx->mem_preemp_preQ_fx), &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); + transf_cdbk_enc_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, + Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); } /*-----------------------------------------------------------------* @@ -302,9 +308,9 @@ void encod_gen_voic_fx( Ltmp = L_mac(Ltmp, xn_fx[L_SUBFR - 1], 16384); Ltmp = L_msu(Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx); Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)) + IF(gain_preQ_fx != 0 ) { tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); @@ -348,16 +354,16 @@ void encod_gen_voic_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_fx( L_frame_fx, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[i_subfr_fx/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, coder_type_fx, st_fx->core_brate_fx ); + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate_fx ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, mem->mem_syn, 1 ); + Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); p_Aw_fx += (M+1); p_Aq_fx += (M+1); @@ -368,15 +374,17 @@ void encod_gen_voic_fx( WHILE( unbits_PI_fx > 0 ) { i = s_min(unbits_PI_fx, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); + push_indice_fx(hBstr, IND_UNUSED, 0, i ); unbits_PI_fx -= i; } - /* SC-VBR */ - st_fx->prev_ppp_gain_pit_fx = gain_pit_fx; - move16(); - st_fx->prev_tilt_code_fx = mem->tilt_code; - move16(); - + IF (st_fx->Opt_SC_VBR_fx) + { + /* SC-VBR */ + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; + move16(); + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + move16(); + } return; } diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index 975d6b5..d7d0ef9 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -2,6 +2,7 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" @@ -16,88 +17,88 @@ void reset_rf_indices( Encoder_State_fx *st /* i: state structure - contains partial RF indices */ ) { - st->rf_frame_type = 0; /* since this function is called every frame this will happen even for a SID frame, hence treating it as GSC frame, i.e no RF encoding */ - + RF_ENC_HANDLE hRF = st->hRF; + Word16 i, j; + if (hRF != NULL) { - Word16 i, j; - - st->rf_mem_w0 = 0; + hRF->rf_frame_type = 0; /* since this function is called every frame this will happen even for a SID frame, hence treating it as GSC frame, i.e no RF encoding */ + hRF->rf_mem_w0 = 0; + move16(); + st->rf_target_bits_write = 0; move16(); - set16_fx(st->rf_clip_var, 0 ,6); - st->rf_tilt_code = 0; + set16_fx(hRF->rf_clip_var, 0 ,6); + hRF->rf_tilt_code = 0; move16(); - set16_fx(st->rf_mem_syn2, 0, M); - st->rf_dm_fx.prev_state = 0; + set16_fx(hRF->rf_mem_syn2, 0, M); + hRF->rf_dm_fx.prev_state = 0; move16(); - st->rf_dm_fx.prev_gain_code = 0; + hRF->rf_dm_fx.prev_gain_code = 0; move32(); FOR(i=0; i<6; i++) { - st->rf_dm_fx.prev_gain_pit[i] = 0; + hRF->rf_dm_fx.prev_gain_pit[i] = 0; move16(); } - st->rf_gc_threshold = 0; + hRF->rf_gc_threshold = 0; move32(); - set16_fx(st->rf_tilt_buf, 0, NB_SUBFR16k); + set16_fx(hRF->rf_tilt_buf, 0, NB_SUBFR16k); - st->rf_target_bits = 0; - move16(); - st->rf_target_bits_write = 0; + hRF->rf_target_bits = 0; move16(); - st->rf_tcxltp_pitch_int_past = st->L_frame_fx; + hRF->rf_tcxltp_pitch_int_past = st->L_frame_fx; move16(); - st->rf_last_tns_active = 0; + hRF->rf_last_tns_active = 0; move16(); - st->rf_second_last_tns_active = 0; + hRF->rf_second_last_tns_active = 0; move16(); - st->rf_second_last_core= 0; + hRF->rf_second_last_core= 0; move16(); FOR( i = 0; i < MAX_RF_FEC_OFFSET; i++) { - st->rf_indx_frametype[i] = RF_NO_DATA; + hRF->rf_indx_frametype[i] = RF_NO_DATA; move16(); /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ - st->rf_targetbits_buff[i] = 6; + hRF->rf_targetbits_buff[i] = 6; move16(); - st->rf_indx_lsf[i][0] = 0; + hRF->rf_indx_lsf[i][0] = 0; move16(); - st->rf_indx_lsf[i][1] = 0; + hRF->rf_indx_lsf[i][1] = 0; move16(); - st->rf_indx_lsf[i][2] = 0; + hRF->rf_indx_lsf[i][2] = 0; move16(); - st->rf_indx_EsPred[i] = 0; + hRF->rf_indx_EsPred[i] = 0; move16(); - st->rf_indx_nelp_fid[i] = 0; + hRF->rf_indx_nelp_fid[i] = 0; move16(); - st->rf_indx_nelp_iG1[i] = 0; + hRF->rf_indx_nelp_iG1[i] = 0; move16(); - st->rf_indx_nelp_iG2[i][0] = 0; + hRF->rf_indx_nelp_iG2[i][0] = 0; move16(); - st->rf_indx_nelp_iG2[i][1] = 0; + hRF->rf_indx_nelp_iG2[i][1] = 0; move16(); FOR( j = 0; j < NB_SUBFR16k; j++) { - st->rf_indx_ltfMode[i][j] = 0; + hRF->rf_indx_ltfMode[i][j] = 0; move16(); - st->rf_indx_pitch[i][j] = 0; + hRF->rf_indx_pitch[i][j] = 0; move16(); - st->rf_indx_fcb[i][j] = 0; + hRF->rf_indx_fcb[i][j] = 0; move16(); - st->rf_indx_gain[i][j] = 0; + hRF->rf_indx_gain[i][j] = 0; move16(); } - st->rf_clas[i] = UNVOICED_CLAS; + hRF->rf_clas[i] = UNVOICED_CLAS; move16(); - st->rf_gain_tcx[i] = 0; + hRF->rf_gain_tcx[i] = 0; move16(); - st->rf_tcxltp_param[i] = 0; + hRF->rf_tcxltp_param[i] = 0; move16(); - st->rf_indx_tbeGainFr[i] = 0; + hRF->rf_indx_tbeGainFr[i] = 0; move16(); } } @@ -112,19 +113,19 @@ void reset_rf_indices( * Encode excitation signal (partial redundancy) *-------------------------------------------------------------------*/ void coder_acelp_rf( - ACELP_config *acelp_cfg_rf, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ + ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ + const Word16 coder_type, /* input: coding type */ + const Word16 A[], /* input: coefficients 4xAz[M+1] */ + const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ + Word16 speech[], /* input: speech[-M..lg] */ + const Word16 voicing[], /* input: open-loop LTP gain */ + const Word16 T_op[], /* input: open-loop LTP lag */ Word16 stab_fac, Encoder_State_fx *st, - Word16 target_bits, /* i/o : coder memory state */ - const Word16 rf_frame_type, /* i : rf_frame_type */ - Word16 *exc_rf, /* i/o: pointer to RF excitation */ - Word16 *syn_rf, /* i/o: pointer to RF synthesis */ + Word16 target_bits, /* i/o : coder memory state */ + const Word16 rf_frame_type, /* i : rf_frame_type */ + Word16 *exc_rf, /* i/o: pointer to RF excitation */ + Word16 *syn_rf, /* i/o: pointer to RF synthesis */ Word16 Q_new, Word16 shift ) @@ -164,6 +165,7 @@ void coder_acelp_rf( Word16 prev_gain_pit; Word16 rf_coder_type; Word16 lp_select; + RF_ENC_HANDLE hRF = st->hRF; /* to avoid compilation warnings */ past_gcode = 0; @@ -181,7 +183,7 @@ void coder_acelp_rf( /*-----------------------------------------------------------------------* * Configure ACELP partial copy * *------------------------------------------------------------------------*/ - tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, acelp_cfg_rf, 0, st->nb_subfr ); + tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, &(hRF->acelp_cfg_rf), 0, st->nb_subfr ); /* Init Framing parameters */ L_frame = st->L_frame_fx; @@ -196,31 +198,25 @@ void coder_acelp_rf( Q_new_p5 = add(Q_new, 5); /* Reset phase dispersion */ - IF (st->last_core_fx > ACELP_CORE) + IF (GT_16(st->last_core_fx, ACELP_CORE)) { - st->rf_dm_fx.prev_gain_code = 0; - set16_fx(st->rf_dm_fx.prev_gain_pit, 0, 6); - st->rf_dm_fx.prev_state = 0; + hRF->rf_dm_fx.prev_gain_code = 0; + set16_fx(hRF->rf_dm_fx.prev_gain_pit, 0, 6); + hRF->rf_dm_fx.prev_state = 0; } /* calculate residual */ - p_Aq = Aq; - FOR (i_subfr=0; i_subfrnrg_mode > 0 && NE_16(rf_frame_type,RF_NELP)) + IF( acelp_cfg->nrg_mode > 0 && NE_16(rf_frame_type,RF_NELP)) { - Es_pred_enc_fx(&Es_pred_rf, &st->rf_indx_EsPred[0], L_frame, exc_rf, voicing, - acelp_cfg_rf->nrg_bits, acelp_cfg_rf->nrg_mode>1, Q_new); + Es_pred_enc_fx(&Es_pred_rf, &hRF->rf_indx_EsPred[0], L_frame, exc_rf, voicing, + acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1, Q_new); } /*------------------------------------------------------------------------* @@ -264,20 +260,8 @@ void coder_acelp_rf( * Find target for pitch search (xn[]), target for innovation search (cn[]) * * and impulse response of the weighted synthesis filter (h1[]). * *--------------------------------------------------------------------------*/ - find_targets_fx( - speech, - &syn_rf[i_subfr-M], - i_subfr, - &(st->rf_mem_w0), - p_Aq, - exc_rf, - L_SUBFR, - p_A, - st->preemph_fac, - xn, - cn - ,h1 - ); + find_targets_fx( speech, &syn_rf[i_subfr-M], i_subfr, &(hRF->rf_mem_w0), p_Aq, + exc_rf, L_SUBFR, p_A, st->preemph_fac, xn, cn ,h1 ); /*---------------------------------------------------------------* * Compute impulse response, h1[], of weighted synthesis filter * @@ -307,7 +291,7 @@ void coder_acelp_rf( } ELSE { - clip_gain = Mode2_gp_clip( voicing, i_subfr, coder_type, xn, st->rf_clip_var, L_SUBFR, Q_xn ); + clip_gain = Mode2_gp_clip( voicing, i_subfr, coder_type, xn, hRF->rf_clip_var, L_SUBFR, Q_xn ); /*-----------------------------------------------------------------* * - find unity gain pitch excitation (adaptive codebook entry) * @@ -315,77 +299,44 @@ void coder_acelp_rf( * - find filtered pitch exc. y1[]=exc[] convolved with h1[]) * * - compute pitch gain1 * *-----------------------------------------------------------------*/ - if( acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR] == 0 ) + if( acelp_cfg->gains_mode[i_subfr/L_SUBFR] == 0 ) { gain_pit = prev_gain_pit; move16(); } - IF ( acelp_cfg_rf->ltp_bits!=0 ) + IF ( acelp_cfg->ltp_bits!=0 ) { - prm_rf = &st->rf_indx_pitch[0][nSubfr]; + prm_rf = &hRF->rf_indx_pitch[0][nSubfr]; /* Adaptive Codebook (GC and VC) */ - Mode2_pit_encode( acelp_cfg_rf->ltp_mode, - i_subfr, - &prm_rf, - &exc_rf[i_subfr], - T_op, - &T0_min, - &T0_min_frac, - &T0_max, - &T0_max_frac, - &T0, - &T0_frac, - &T0_res, - h1, - xn, - st->pit_min, - st->pit_fr1, - st->pit_fr1b, - st->pit_fr2, - st->pit_max, - st->pit_res_max); + Mode2_pit_encode( acelp_cfg->ltp_mode, i_subfr, &prm_rf, &exc_rf[i_subfr], + T_op, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, &T0, + &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, + st->pit_fr2, st->pit_max,st->pit_res_max); /* find ACB excitation */ rf_coder_type = 100; move16(); - if( acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR] > 0 ) + if( acelp_cfg->gains_mode[i_subfr/L_SUBFR] > 0 ) { - rf_coder_type = acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR]; + rf_coder_type = acelp_cfg->gains_mode[i_subfr/L_SUBFR]; move16(); } - E_ACELP_adaptive_codebook( exc_rf, - T0, - T0_frac, - T0_res, - st->pit_res_max, - acelp_cfg_rf->ltf_mode, - i_subfr, - L_SUBFR, - L_frame, - h1, - clip_gain, - xn, - y1, - &g_corr, - &prm_rf, - &gain_pit, - xn_exp - ,st->rf_mode - ,rf_coder_type - ,&lp_select - ); - - - - if( acelp_cfg_rf->ltf_mode == NORMAL_OPERATION ) + E_ACELP_adaptive_codebook( exc_rf, T0, T0_frac, T0_res, st->pit_res_max, acelp_cfg->ltf_mode, + i_subfr, L_SUBFR, L_frame, h1,clip_gain, xn, y1, &g_corr, &prm_rf, + &gain_pit, xn_exp, st->rf_mode, rf_coder_type, &lp_select); + + + + if( EQ_16(acelp_cfg->ltf_mode, NORMAL_OPERATION) ) { - st->rf_indx_ltfMode[0][nSubfr] = lp_select; + hRF->rf_indx_ltfMode[0][nSubfr] = lp_select; + move16(); } } - ELSE IF ( acelp_cfg_rf->ltp_bits==0 ) + ELSE IF ( acelp_cfg->ltp_bits==0 ) { /* No adaptive codebook (UC) */ gain_pit=0; @@ -398,45 +349,20 @@ void coder_acelp_rf( T0 = L_SUBFR; T0_frac = 0; T0_res = 1; + move16();move16();move16();move16();move16();move16();move16();move16(); } /*----------------------------------------------------------------------* * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - IF( acelp_cfg_rf->fixed_cdk_index[i_subfr/L_SUBFR] >= 0 ) + IF( acelp_cfg->fixed_cdk_index[i_subfr/L_SUBFR] >= 0 ) { - prm_rf = &st->rf_indx_fcb[0][nSubfr]; - - E_ACELP_innovative_codebook( exc_rf, - T0, - T0_frac, - T0_res, - gain_pit, - st->rf_tilt_code, - acelp_cfg_rf->fixed_cdk_index[j_subfr], - acelp_cfg_rf->formant_enh, - acelp_cfg_rf->formant_tilt, - acelp_cfg_rf->formant_enh_num, - acelp_cfg_rf->formant_enh_den, - acelp_cfg_rf->pitch_sharpening, - acelp_cfg_rf->pre_emphasis, - acelp_cfg_rf->phase_scrambling, - i_subfr, - p_Aq, - h1, - xn, - cn, - y1, - y2, - st->acelp_autocorr, - &prm_rf, - code, - shift - ,st->L_frame_fx, - st->last_L_frame_fx, - st->total_brate_fx - ); + prm_rf = &hRF->rf_indx_fcb[0][nSubfr]; + + E_ACELP_innovative_codebook( exc_rf,T0,T0_frac,T0_res, gain_pit, hRF->rf_tilt_code, + acelp_cfg, i_subfr,p_Aq,h1,xn,cn,y1,y2,st->acelp_autocorr, + &prm_rf,code,shift,st->L_frame_fx, st->last_L_frame_fx,st->total_brate_fx); } ELSE { @@ -444,7 +370,7 @@ void coder_acelp_rf( set16_fx(y2, 0, L_SUBFR); } - IF( i_subfr < sub(L_frame,L_SUBFR) ) + IF( LT_16(i_subfr, sub(L_frame,L_SUBFR)) ) { E_ACELP_xy2_corr(xn, y1, y2, &g_corr, L_SUBFR, Q_xn); @@ -453,7 +379,6 @@ void coder_acelp_rf( g_corr.y1y2_e = sub(g_corr.y1y2_e, add(Q_xn,9)); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ g_corr.xx_e = sub(g_corr.xx_e, add(Q_xn,Q_xn)); /* -(Q_xn+Q_xn) (xn: Q_xn) */ - /*----------------------------------------------------------------------* * Add Gaussian excitation * *----------------------------------------------------------------------*/ @@ -461,37 +386,22 @@ void coder_acelp_rf( set16_fx(code2, 0, L_SUBFR); set16_fx(y22, 0, L_SUBFR); - - - /*----------------------------------------------------------* * - Compute the fixed codebook gain * * - quantize fixed codebook gain * *----------------------------------------------------------*/ - IF( acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR] != 0 ) + IF( acelp_cfg->gains_mode[i_subfr/L_SUBFR] != 0 ) { - prm_rf = &st->rf_indx_gain[0][nSubfr]; - - encode_acelp_gains( code, - acelp_cfg_rf->gains_mode[j_subfr], - Es_pred_rf, - clip_gain, - &g_corr, - &gain_pit, - &gain_code, - &prm_rf, - &past_gcode, - &gain_inov, - L_SUBFR, - code2, - &gain_code2, - st->flag_noisy_speech_snr - ); + prm_rf = &hRF->rf_indx_gain[0][nSubfr]; + + encode_acelp_gains( code, acelp_cfg->gains_mode[j_subfr], Es_pred_rf, + clip_gain, &g_corr, &gain_pit, &gain_code, &prm_rf, &past_gcode, + &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr ); } - gp_clip_test_gain_pit_fx( st->core_brate_fx, gain_pit, st->rf_clip_var ); + gp_clip_test_gain_pit_fx(st->element_mode, st->core_brate_fx, gain_pit, hRF->rf_clip_var ); gain_code_vect[0] = gain_code; move32(); @@ -501,18 +411,8 @@ void coder_acelp_rf( /*----------------------------------------------------------* * - voice factor (for pitch enhancement) * *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc_rf, - i_subfr, - code, - gain_pit, - gain_code, - &voice_fac, - &(st->rf_tilt_code), - L_SUBFR, - acelp_cfg_rf->voice_tilt, - Q_new, - shift - ); + E_UTIL_voice_factor( exc_rf, i_subfr, code, gain_pit, gain_code, + &voice_fac, &(hRF->rf_tilt_code), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift); /*-----------------------------------------------------------------* @@ -526,10 +426,10 @@ void coder_acelp_rf( Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR-1]); Ltmp2 = L_shl(Ltmp2, add(5,Q_xn)); Ltmp = L_add(Ltmp, Ltmp2); - st->rf_mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); + hRF->rf_mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); move16(); BASOP_SATURATE_WARNING_OFF; - st->rf_mem_w0 =shr(st->rf_mem_w0, shift); /*Qnew-1*/ + hRF->rf_mem_w0 =shr(hRF->rf_mem_w0, shift); /*Qnew-1*/ BASOP_SATURATE_WARNING_ON; @@ -567,23 +467,10 @@ void coder_acelp_rf( /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ - E_UTIL_enhancer( voice_fac, - stab_fac, - past_gcode, - gain_inov, - &st->rf_gc_threshold, - code, - exc2, - gain_pit, - &st->rf_dm_fx.prev_gain_code, - st->rf_dm_fx.prev_gain_pit, - &st->rf_dm_fx.prev_state, - coder_type, - acelp_cfg_rf->fixed_cdk_index[j_subfr], - L_SUBFR, - L_frame, - Q_new - ); + E_UTIL_enhancer( voice_fac, stab_fac, past_gcode, gain_inov, + &hRF->rf_gc_threshold, code, exc2, gain_pit, &hRF->rf_dm_fx.prev_gain_code, + hRF->rf_dm_fx.prev_gain_pit, &hRF->rf_dm_fx.prev_state, coder_type, + acelp_cfg->fixed_cdk_index[j_subfr], L_SUBFR, L_frame, Q_new ); } } @@ -594,7 +481,7 @@ void coder_acelp_rf( * - compute the synthesis speech * *----------------------------------------------------------*/ - E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, st->rf_mem_syn2, 1, M); + E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, hRF->rf_mem_syn2, 1, M); E_UTIL_synthesis(1, p_Aq, &exc_rf[i_subfr], &syn_rf[i_subfr], L_SUBFR, &syn_rf[i_subfr-M], 0, M); diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 37a3c38..74d346c 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -1,15 +1,14 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*---------------------------------------------------------------------* - * Local functions + * Local function prototype *---------------------------------------------------------------------*/ static void find_cn_fx( const Word16 xn[], const Word16 Ap[], const Word16 *p_Aq, Word16 cn[] ); @@ -18,34 +17,28 @@ static void find_cn_fx( const Word16 xn[], const Word16 Ap[], const Word16 *p_Aq *-----------------------------------------------------------------*/ #define Q_MINUS 4 void transf_cdbk_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *mem_deemp, /* i/o: prequantizer deemhasis memory */ - Word16 *mem_preemp, /* i/o: prequantizer preemhasis memory */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ + const Word16 i_subfr, /* i : subframe index */ + Word16 cn[], /* i/o: target vector in residual domain */ + Word16 exc[], /* i/o: pointer to excitation signal frame */ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 h1[], /* i : weighted filter input response */ + Word16 xn[], /* i/o: target vector */ + Word16 xn2[], /* i/o: target vector for innovation search */ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ + const Word16 y2[], /* i : zero-memory filtered innovative excitation */ + const Word16 Es_pred, /* i : predicited scaled innovation energy */ + Word16 *gain_pit, /* i/o: adaptive excitation gain */ + const Word32 gain_code, /* i : innovative excitation gain */ + Word16 g_corr[], /* o : ACELP correlation values */ + const Word16 clip_gain, /* i : adaptive gain clipping flag */ + Word16 *gain_preQ, /* o : prequantizer excitation gain */ + Word16 code_preQ[], /* o : prequantizer excitation */ + Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 Q_new, /* i : Current frame scaling */ + const Word16 shift /* i : shifting applied to y1, xn,... */ ) { Word16 i, index, nBits, Nsv, Es_pred_loc; @@ -56,6 +49,16 @@ void transf_cdbk_enc_fx( Word16 nq[L_SUBFR/WIDTH_BAND]; Word32 out32[L_SUBFR]; Word16 Qdct; + Word16 avq_bit_sFlag; + Word16 trgtSvPos; + + avq_bit_sFlag = 0; + move16(); + if (GT_16(st_fx->element_mode, EVS_MONO)) + { + avq_bit_sFlag = 1; + move16(); + } /*--------------------------------------------------------------* * Set bit-allocation @@ -63,7 +66,7 @@ void transf_cdbk_enc_fx( Nsv = 8; move16(); - nBits = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr(i_subfr, 6)]; move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -74,7 +77,7 @@ void transf_cdbk_enc_fx( * For inactive frame, find target in residual domain * Deemphasis *--------------------------------------------------------------*/ - IF (EQ_16(coder_type,INACTIVE)) + IF (EQ_16(st_fx->coder_type,INACTIVE)) { gcode16 = round_fx(L_shl(gain_code, Q_new)); FOR( i=0; imem_deemp_preQ_fx) ); /*--------------------------------------------------------------* * DCT-II @@ -103,7 +106,7 @@ void transf_cdbk_enc_fx( test(); test(); test(); - IF( NE_16(coder_type,INACTIVE)&&LE_32(core_brate,ACELP_32k)&>_32(core_brate,ACELP_24k40)&&!harm_flag_acelp) + IF( NE_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate_fx, MAX_BRATE_AVQ_EXC_TD) && GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC) && !harm_flag_acelp) { Copy_Scale_sig( x_in, x_tran, L_SUBFR,-Q_MINUS+1 ); /*Q_new-1 -> Q_new-4*/ /*Copy( x_in, x_tran, L_SUBFR );*/ @@ -158,7 +161,7 @@ void transf_cdbk_enc_fx( m_corr = div_s(m_corr, m_ener); e_corr = sub(e_corr, e_ener); Ltmp = L_shl(m_corr, s_min(add(e_corr,1),31)); /* Lgain in Q16 */ - IF ( EQ_16(coder_type,INACTIVE)) + IF ( EQ_16(st_fx->coder_type,INACTIVE)) { Ltmp1 = L_max(gain_code,1); e_den = norm_l(Ltmp1); @@ -177,11 +180,11 @@ void transf_cdbk_enc_fx( stmp = 0; move16(); } - IF( EQ_32(core_brate,ACELP_64k)) + IF( GT_32(st_fx->core_brate_fx,56000)) { index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12>>1, (1 << G_AVQ_BITS) ); } - ELSE IF( EQ_32(core_brate,ACELP_48k)) + ELSE IF( GT_32(st_fx->core_brate_fx,42000)) { index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12>>1, (1 << G_AVQ_BITS) ); } @@ -220,7 +223,7 @@ void transf_cdbk_enc_fx( Ltmp = L_deposit_l(0); } test(); - IF( LE_32(core_brate,ACELP_32k)&>_32(core_brate,ACELP_24k40)) + IF( LE_32(st_fx->core_brate_fx,42000) && GT_32(st_fx->core_brate_fx ,ACELP_24k40)) { index = gain_quant_fx(&Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); } @@ -232,13 +235,23 @@ void transf_cdbk_enc_fx( Ltmp = L_shl(Ltmp,add(e_den,9)); /* Q18*/ *gain_preQ = round_fx(Ltmp); /* Q2*/ } - push_indice_fx( st_fx, IND_AVQ_GAIN, index, G_AVQ_BITS ); + push_indice_fx( st_fx->hBstr, IND_AVQ_GAIN, index, G_AVQ_BITS ); /*--------------------------------------------------------------* * Encode and multiplex subvectors into bit-stream *--------------------------------------------------------------*/ + trgtSvPos = Nsv - 1; + move16(); + test();test();test();test();test(); + IF (avq_bit_sFlag && GT_16(nBits, 85) && !harm_flag_acelp && (EQ_16(st_fx->coder_type, GENERIC) || + EQ_16(st_fx->coder_type, TRANSITION) || EQ_16(st_fx->coder_type, INACTIVE) )) + { + trgtSvPos = 2; + avq_bit_sFlag = 2; + move16();move16(); + } - AVQ_encmux_fx( st_fx, -1, x_norm, &nBits, Nsv, nq ); + AVQ_encmux_fx( st_fx->hBstr, -1, x_norm, &nBits, Nsv, nq, avq_bit_sFlag, trgtSvPos); /* save # of AVQ unused bits for next subframe */ *unbits = nBits; @@ -247,12 +260,12 @@ void transf_cdbk_enc_fx( /* at the last subframe, write AVQ unused bits */ test(); test(); - IF( EQ_16(i_subfr,4*L_SUBFR)&&NE_16(extl,SWB_BWE_HIGHRATE)&&NE_16(extl,FB_BWE_HIGHRATE)) + IF( EQ_16(i_subfr,4*L_SUBFR) && NE_16(st_fx->extl_fx,SWB_BWE_HIGHRATE) && NE_16(st_fx->extl_fx,FB_BWE_HIGHRATE)) { WHILE( *unbits > 0 ) { i = s_min(*unbits, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); + push_indice_fx( st_fx->hBstr, IND_UNUSED, 0, i ); *unbits -= i; } } @@ -271,8 +284,7 @@ void transf_cdbk_enc_fx( test(); test(); test(); - - IF(NE_16(coder_type,INACTIVE)&&LE_32(core_brate,ACELP_32k)&>_32(core_brate,ACELP_24k40)&&!harm_flag_acelp) + IF(NE_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate_fx, MAX_BRATE_AVQ_EXC_TD) && GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC) && !harm_flag_acelp) { Copy( x_tran, code_preQ, L_SUBFR ); } @@ -295,12 +307,28 @@ void transf_cdbk_enc_fx( if( (nq[7] != 0) && (GT_16( sub(st_fx->last_nq_preQ_fx, nq[0]), 7))) { /* *mem_preemp /= 16; */ - *mem_preemp = shr(*mem_preemp,4); + st_fx->mem_preemp_preQ_fx = shr(st_fx->mem_preemp_preQ_fx,4); move16(); } st_fx->last_nq_preQ_fx = nq[7]; move16(); - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, mem_preemp ); +#ifdef IVAS_CODE + /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + if (st->element_mode > EVS_MONO && st->coder_type != INACTIVE && st->core_brate >= MIN_BRATE_AVQ_EXC && st->core_brate <= MAX_BRATE_AVQ_EXC_TD && !harm_flag_acelp && code_preQ[0] != 0) + { + if ((float)abs(st->last_code_preq) > 16.0f * (float)fabs(code_preQ[0])) + { + st->mem_preemp_preQ /= 16; + } + else if ((float)abs(st->last_code_preq) > 8.0f * (float)fabs(code_preQ[0])) + { + st->mem_preemp_preQ /= 8; + } + } + + st->last_code_preq = (int16_t)code_preQ[L_SUBFR - 1]; +#endif + preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &(st_fx->mem_preemp_preQ_fx)); /*--------------------------------------------------------------* * For inactive segments @@ -310,7 +338,7 @@ void transf_cdbk_enc_fx( * - Update xn[L_subfr-1] for updating the memory of the weighting filter *--------------------------------------------------------------*/ - IF ( EQ_16(coder_type,INACTIVE)) + IF ( EQ_16(st_fx->coder_type,INACTIVE)) { /*ftemp = fcode_preQ[0] *fh1[L_SUBFR-1];*/ Ltmp = L_mult(code_preQ[0], h1[L_SUBFR-1]); /*1+14+shift + Q_AVQ_OUT */ @@ -352,10 +380,10 @@ void transf_cdbk_enc_fx( *-------------------------------------------------------------------*/ static void find_cn_fx( - const Word16 xn[], /* i : target signal */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 *p_Aq, /* i : 12k8 LP coefficients */ - Word16 cn[] /* o : target signal in residual domain */ + const Word16 xn[], /* i : target signal */ + const Word16 Ap[], /* i : weighted LP filter coefficients */ + const Word16 *p_Aq, /* i : 12k8 LP coefficients */ + Word16 cn[] /* o : target signal in residual domain */ ) { Word16 tmp, tmp_fl[L_SUBFR+M]; @@ -375,13 +403,13 @@ static void find_cn_fx( /*-----------------------------------------------------------------* * Transform domain contribution encoding *-----------------------------------------------------------------*/ -Word16 gain_quant_fx( /* o: quantization index */ - Word32 *gain, /* i: quantized gain (Q16) */ - Word16 *gain16, /* o: quantized gain (expg) */ - const Word16 c_min, /* i: log10 of lower limit in Q14 */ - const Word16 c_max, /* i: log10 of upper limit in Q13 */ - const Word16 bits, /* i: number of bits to quantize */ - Word16 *expg /* o: output exponent of gain16 */ +Word16 gain_quant_fx( /* o: quantization index */ + Word32 *gain, /* i: quantized gain (Q16) */ + Word16 *gain16, /* o: quantized gain (expg) */ + const Word16 c_min, /* i: log10 of lower limit in Q14 */ + const Word16 c_max, /* i: log10 of upper limit in Q13 */ + const Word16 bits, /* i: number of bits to quantize */ + Word16 *expg /* o: output exponent of gain16 */ ) { Word16 index, levels; diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index 6cb5dc4..655a24c 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*==============================================================================*/ /* FUNCTION : encod_nelp_fx() */ @@ -39,7 +39,6 @@ /*==============================================================================*/ void encod_nelp_fx( Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ const Word16 *speech_fx, /* i : input speech */ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ @@ -66,16 +65,18 @@ void encod_nelp_fx( Word16 saved_Q_new = Q_new; Word16 reduce_gains = 0; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; IF ( EQ_16(st_fx->bwidth_fx, NB)&&GE_32(st_fx->input_Fs_fx,16000)) { - IF (st_fx->last_nelp_mode_fx == 0) + IF (hSC_VBR->last_nelp_mode_fx == 0) { - set16_fx( st_fx->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); + set16_fx(hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); } - Scale_sig(st_fx->nelp_lp_fit_mem, NELP_LP_ORDER*2, sub(Q_new, st_fx->prev_Q_new)); + Scale_sig(hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER*2, sub(Q_new, st_fx->prev_Q_new)); - pz_filter_sp_fx( num_nelp_lp_fx, den_nelp_lp_fx, res_fx, res_fx, st_fx->nelp_lp_fit_mem, NELP_LP_ORDER, NELP_LP_ORDER, L_FRAME, 3); /*16-Q of filter coeff*/ + pz_filter_sp_fx( num_nelp_lp_fx, den_nelp_lp_fx, res_fx, res_fx, hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER, NELP_LP_ORDER, L_FRAME, 3); /*16-Q of filter coeff*/ } @@ -93,24 +94,21 @@ void encod_nelp_fx( *----------------------------------------------------------------*/ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); - find_targets_fx( speech_fx, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL - ,h1_fx - ); + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx); + /* scale xn[] and h1[] to avoid overflow in dot_product12() */ Scale_sig(xn_fx, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */ IF (i_subfr == 0) { test(); - IF ( EQ_16(st_fx->Local_VAD, 1 )&&EQ_16(st_fx->bwidth_fx,NB)) + IF ( EQ_16(hSC_VBR->Local_VAD, 1 ) && EQ_16(st_fx->bwidth_fx,NB)) { reduce_gains = 1; } - nelp_encoder_fx( st_fx, res_fx, exc_nelp_fx, &Q_new - ,reduce_gains - ); + nelp_encoder_fx( st_fx, res_fx, exc_nelp_fx, &Q_new, reduce_gains); Scale_sig(exc_nelp_fx, L_FRAME, (saved_Q_new - Q_new)); } @@ -123,7 +121,7 @@ void encod_nelp_fx( * Synthesize speech to update mem_syn[]. * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq_fx, M, &exc_nelp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, mem->mem_syn, 1); + Syn_filt_s(1, p_Aq_fx, M, &exc_nelp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1); p_Aw_fx += (M+1); move16(); @@ -142,29 +140,28 @@ void encod_nelp_fx( * Updates: last value of new target is stored in mem_w0 *-----------------------------------------------------------------*/ - mem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); + hLPDmem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); move16();/*Q_new-1 */ - mem->tilt_code = 0; + hLPDmem->tilt_code = 0; move16();/* purely unvoiced */ - st_fx->prev_tilt_code_fx = mem->tilt_code; + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; move16(); Copy(exc_fx, exc2_fx, L_FRAME); - st_fx->prev_ppp_gain_pit_fx = 0; + hSC_VBR->prev_ppp_gain_pit_fx = 0; move16(); - st_fx->dm_fx.prev_state = 0; + hLPDmem->dm_fx.prev_state = 0; move16(); - st_fx->dm_fx.prev_gain_pit[0] = st_fx->prev_ppp_gain_pit_fx; + hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; move16(); FOR(j=1; j<5; j++) { - st_fx->dm_fx.prev_gain_pit[j] = st_fx->dm_fx.prev_gain_pit[j-1]; + hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j-1]; move16(); } - interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); set16_fx( voice_factors_fx, 0, NB_SUBFR16k ); diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 4858117..60724f8 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -1,15 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ - -#include "stl.h" - /*======================================================================*/ /* FUNCTION : enc_pit_exc_fx() */ /*----------------------------------------------------------------------*/ @@ -47,23 +44,22 @@ /* _ None */ /*=======================================================================*/ void enc_pit_exc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ + Encoder_State_fx *st_fx, /* i/o: State structure */ const Word16 *speech, /* i : Input speech */ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ const Word16 Aq[], /* i : 12k8 Lp coefficient */ const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 *T_op, /* i : open loop pitch */ - const Word16 *voicing, /* i : voicing */ const Word16 *res, /* i : residual signal */ - Word16 *synth, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + Word16 *synth, /* i/o: core synthesis */ + Word16 *exc, /* i/o: current non-enhanced excitation */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ + Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *gpit, /* o : pitch mean gpit */ - Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + Word16 *gpit, /* o : pitch mean gpit */ + Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, Word16 shift ) @@ -72,8 +68,8 @@ void enc_pit_exc_fx( Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ Word16 h1[PIT_EXC_L_SUBFR+(M+1)]; /* Impulse response vector */ Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ - Word16 code[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 code[2*L_SUBFR]; /* Fixed codebook excitation */ + Word16 y2[2*L_SUBFR]; /* Filtered algebraic excitation */ Word16 voice_fac; /* Voicing factor */ Word32 gain_code; /* Gain of code */ Word16 gain_inov; /* inovation gain */ @@ -87,8 +83,8 @@ void enc_pit_exc_fx( Word16 *pt_pitch; /* pointer to floating pitch */ Word16 L_subfr; Word16 cum_gpit, gpit_tmp; - Word16 Local_BR, Pitch_BR, Pitch_CT; - Word16 unbits_PI = 0; /* saved bits for PI */ + Word32 Local_BR, Pitch_BR; + Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */ Word32 norm_gain_code; Word16 pitch_limit_flag; Word16 h2[PIT_EXC_L_SUBFR+(M+1)]; /* Impulse response vector */ @@ -97,42 +93,115 @@ void enc_pit_exc_fx( Word16 gcode16; Word16 shift_wsp; Word16 lp_select, lp_flag; + Word16 use_fcb; + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ pitch_limit_flag = 1; move16(); /* always extended pitch Q range */ + use_fcb = 0; + unbits_PI = 0; + test();test(); + Pitch_CT = GENERIC; + move16(); - IF( st_fx->GSC_noisy_speech_fx ) + IF (st_fx->GSC_IVAS_mode > 0 && (st_fx->GSC_noisy_speech_fx || GT_32(st_fx->core_brate_fx, GSC_H_RATE_STG))) + { + Local_BR = ACELP_8k00; + Pitch_BR = ACELP_8k00; + move32();move32(); + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + Local_BR = ACELP_14k80; + move32(); + if (st_fx->GSC_IVAS_mode > 0) + { + Local_BR = ACELP_9k60; + move32(); + } + Pitch_BR = st_fx->core_brate_fx; + move32(); + } + } + ELSE IF( st_fx->GSC_noisy_speech_fx ) { Local_BR = ACELP_7k20; - move16(); - Pitch_CT = GENERIC; - move16(); + move32(); Pitch_BR = ACELP_7k20; + move32(); + Pitch_CT = GENERIC; move16(); + if (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + Pitch_BR = st_fx->core_brate_fx; + move32(); + } } ELSE { Local_BR = ACELP_7k20; - move16(); + move32(); + Pitch_BR = st_fx->core_brate_fx; + move32(); Pitch_CT = AUDIO; move16(); - Pitch_BR = extract_l(st_fx->core_brate_fx); + + if (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + Local_BR = ACELP_13k20; + move32(); + Pitch_CT = GENERIC; + move16(); + } } gain_code = 0; move16(); - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + T0_max = PIT16k_MAX; + T0_min = PIT16k_MIN; + } + ELSE + { + T0_max = PIT_MAX; + move16(); + T0_min = PIT_MIN; + move16(); + } cum_gpit = 0; move16(); - L_subfr = mult_r(L_FRAME,div_s(1,nb_subfr)); + L_subfr = mult_r(st_fx->L_frame_fx,div_s(1,nb_subfr)); + + lp_flag = st_fx->acelp_cfg.ltf_mode; + + test();test();test();test();test();test();test();test(); + IF (((GE_32(st_fx->core_brate_fx, MIN_RATE_FCB) || (EQ_16(st_fx->GSC_noisy_speech_fx, 1) && + ((EQ_16(st_fx->L_frame_fx, L_FRAME) && GE_32(st_fx->core_brate_fx, ACELP_13k20)) || + (EQ_16(st_fx->L_frame_fx, L_FRAME16k) && GE_32(st_fx->core_brate_fx, GSC_H_RATE_STG)) || st_fx->GSC_IVAS_mode == 0))) && EQ_16(L_subfr, L_SUBFR))) + { + use_fcb = 1; + move16(); + } + ELSE IF (st_fx->GSC_IVAS_mode > 0 && EQ_16(L_subfr, 2 * L_SUBFR) && LT_16(st_fx->GSC_IVAS_mode, 3)) + { + use_fcb = 2; + st_fx->acelp_cfg.fcb_mode = 1; + move16();move16(); + set16_fx(st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR); + set16_fx(st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR); + set16_fx(st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k); + } *saved_bit_pos = st_fx->next_bit_pos_fx; move16(); @@ -151,7 +220,7 @@ void enc_pit_exc_fx( p_Aq = Aq; pt_pitch = pitch_buf; /* pointer to the pitch buffer */ shift_wsp = add(Q_new,shift); - FOR ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_subfr ) + FOR ( i_subfr = 0; i_subfr < st_fx->L_frame_fx; i_subfr += L_subfr ) { /*----------------------------------------------------------------* @@ -162,8 +231,13 @@ void enc_pit_exc_fx( *----------------------------------------------------------------*/ Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* condition on target (compared to float) has been put outside the loop */ - find_targets_fx( speech, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq, - res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn,h1); +#if 1//ndef BUG_FIX + find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn,h1); +#else + find_targets_fx(speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hLPDmem->mem_w0, p_Aq, /*_DIFF_FLOAT_FIX_ --> Here I think mem_syn_tmp_fx should be used */ + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1); +#endif Copy_Scale_sig(h1, h2, L_subfr, -2); Scale_sig(h1, L_subfr, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ @@ -174,8 +248,8 @@ void enc_pit_exc_fx( * Close-loop pitch search and quantization * Adaptive exc. construction *----------------------------------------------------------------*/ - *pt_pitch = pit_encode_fx( st_fx, Pitch_BR, 0, L_FRAME, Pitch_CT, &pitch_limit_flag, i_subfr, exc, - L_subfr, T_op, &T0_min, &T0_max, T0, T0_frac, h1, xn ); + *pt_pitch = pit_encode_fx(hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame_fx, Pitch_CT, &pitch_limit_flag, i_subfr, exc, + L_subfr, st_fx->pitch_fx, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf); /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ @@ -186,70 +260,95 @@ void enc_pit_exc_fx( * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = gp_clip_fx(st_fx->core_brate_fx, voicing, i_subfr, AUDIO, xn, st_fx->clip_var_fx,sub(shift_wsp, 1)); + clip_gain = gp_clip_fx(st_fx->element_mode, st_fx->core_brate_fx, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx,sub(shift_wsp, 1)); /*-----------------------------------------------------------------* * Codebook target computation * (No LP filtering of the adaptive excitation) *-----------------------------------------------------------------*/ - lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->core_brate_fx, 0, AUDIO, i_subfr, exc, h1, - xn, y1, xn2, L_subfr, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); + lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, + xn, y1, xn2, L_subfr, st_fx->L_frame_fx, g_corr, clip_gain, &gain_pit, &lp_flag ); IF( EQ_16(lp_flag,NORMAL_OPERATION)) { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx(hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ - st_fx->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, st_fx->lowrate_pitchGain), 6554, gain_pit)); /*Q14*Q16(0.1) + Q15 -> Q15*/ + hSpMusClas->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, hSpMusClas->lowrate_pitchGain), 6554, gain_pit)); /*Q14*Q16(0.1) + Q15 -> Q15*/ gpit_tmp = gain_pit; move16(); /*Q14*/ test(); - IF( st_fx->GSC_noisy_speech_fx == 0 || NE_16(L_subfr,L_SUBFR )) + IF(use_fcb > 0) { - pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); - push_indice_fx( st_fx, IND_PIT_IDX, pit_idx, 4 ); + /* h2 in Q12 for codebook search */ + /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ + Copy_Scale_sig(h1, h2, L_subfr, sub(-2 - 1, shift)); } - ELSE + + IF(use_fcb == 0) + { + IF (GE_32(st_fx->core_brate_fx, MIN_RATE_FCB)) + { + pit_idx = vquant_fx(&gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32); + push_indice_fx(hBstr, IND_PIT_IDX, pit_idx, 5); + } + ELSE + { + pit_idx = vquant_fx(&gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16); + push_indice_fx(hBstr, IND_PIT_IDX, pit_idx, 4); + } + } + else if (use_fcb == 2) { /*-----------------------------------------------------------------* - * Innovation & gain encoding + * Innovation encoding *-----------------------------------------------------------------*/ - /* h2 in Q12 for codebook search */ - /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ - Copy_Scale_sig( h1, h2, L_subfr, sub(-2-1,shift) ); - inov_encode_fx( st_fx, Local_BR, 0, L_FRAME, st_fx->last_L_frame_fx, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI,shift - ); + inov_encode_fx(st_fx, st_fx->core_brate_fx, 0, st_fx->L_frame_fx, st_fx->last_L_frame_fx, GENERIC, st_fx->bwidth_fx, 0, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift); +PMT("code to be validated") /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - gain_enc_mless_fx( st_fx, Local_BR, L_FRAME, LOCAL_CT, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + + gain_enc_lbr_fx(st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR); } + ELSE + { + /*-----------------------------------------------------------------* + * Innovation & gain encoding + *-----------------------------------------------------------------*/ - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, gain_pit, st_fx->clip_var_fx ); + inov_encode_fx(st_fx, Local_BR, 0, st_fx->L_frame_fx, st_fx->last_L_frame_fx, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift); + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain); + } + gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate_fx, gain_pit, st_fx->clip_var_fx ); Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx(Lgcode); - IF( st_fx->GSC_noisy_speech_fx) + IF( use_fcb != 0) { - mem->tilt_code = Est_tilt2(&exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); + hLPDmem->tilt_code = Est_tilt2(&exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); move16(); } ELSE { - mem->tilt_code = 0; + hLPDmem->tilt_code = 0; move16(); } /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ - IF( st_fx->GSC_noisy_speech_fx) + IF(use_fcb != 0) { Ltmp = L_mult(gcode16, y2[L_subfr - 1]); Ltmp = L_shl(Ltmp, add(5, shift)); @@ -257,21 +356,21 @@ void enc_pit_exc_fx( Ltmp = L_mac(Ltmp, xn[L_subfr - 1], 16384); Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ } ELSE { Ltmp = L_mult(xn[L_subfr - 1], 16384); Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ + hLPDmem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ } /*-----------------------------------------------------------------* * Construct adaptive part of the excitation * Save the non-enhanced excitation for FEC_exc *-----------------------------------------------------------------*/ - IF( st_fx->GSC_noisy_speech_fx) + IF(use_fcb != 0) { FOR ( i = 0; i < L_subfr; i++ ) { @@ -299,8 +398,56 @@ void enc_pit_exc_fx( * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, st_fx->mem_syn_tmp_fx, 1 ); - IF( EQ_16(L_subfr,2*L_SUBFR)) + Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 ); + + IF (EQ_16(L_subfr, 5 * L_SUBFR)) + { + cum_gpit = gpit_tmp; + move16(); + pt_pitch++; + *pt_pitch = *(pt_pitch - 1); + move16(); + pt_pitch++; + *pt_pitch = *(pt_pitch - 1); + move16(); + pt_pitch++; + *pt_pitch = *(pt_pitch - 1); + move16(); + pt_pitch++; + *pt_pitch = *(pt_pitch - 1); + move16(); + pt_pitch++; + + p_Aw += 5 * (M + 1); + p_Aq += 5 * (M + 1); + } + ELSE IF (EQ_16(L_subfr, 5 * L_SUBFR / 2)) + { + IF (i_subfr == 0) + { + cum_gpit = mult_r(gpit_tmp, 13107); /* .4f*/ + pt_pitch++; + *pt_pitch = *(pt_pitch - 1); + move16(); + pt_pitch++; + p_Aw += 2 * (M + 1); + p_Aq += 2 * (M + 1); + } + ELSE + { + cum_gpit = add(cum_gpit, mult_r(gpit_tmp, 19660)); /*0.6*/ + pt_pitch++; + *pt_pitch = *(pt_pitch - 1); + move16(); + pt_pitch++; + *pt_pitch = *(pt_pitch - 1); + move16(); + pt_pitch++; + p_Aw += 3 * (M + 1); + p_Aq += 3 * (M + 1); + } + } + ELSE IF( EQ_16(L_subfr,2*L_SUBFR)) { IF( i_subfr == 0 ) { diff --git a/lib_enc/enc_ppp_fx.c b/lib_enc/enc_ppp_fx.c index d33416a..41717e3 100644 --- a/lib_enc/enc_ppp_fx.c +++ b/lib_enc/enc_ppp_fx.c @@ -1,11 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" + /*Temporary location to be move in prot* when merge is done */ void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); @@ -47,23 +47,18 @@ void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); /*---------------------------------------------------------------------------------------*/ /* CALLED FROM : TX */ /*=======================================================================================*/ -void encod_ppp_fx( - Encoder_State_fx* st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech_fx[], /* i : input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *coder_type_fx, /* i : coding type */ - Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing Q15*/ - Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *synth_fx, /* o : core synthesis Q-1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* o: current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ +ivas_error encod_ppp_fx( + Encoder_State_fx* st_fx, /* i/o: state structure */ + const Word16 speech_fx[], /* i : input speech Q_new*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *synth_fx, /* o : core synthesis Q-1*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *exc2_fx, /* o : current enhanced excitation Q0*/ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors */ + Word16 *bwe_exc, /* o : excitation for SWB TBE */ Word16 Q_new, Word16 shift ) @@ -79,8 +74,14 @@ void encod_ppp_fx( Word16 shift_wsp = add(Q_new,shift); Word16 rate_ctrl_fx; Word16 saved_Q_new = Q_new; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + ivas_error error; - rate_ctrl_fx = st_fx->rate_control_fx; + error = IVAS_ERR_OK; + move16(); + rate_ctrl_fx = hSC_VBR->rate_control_fx; move16(); /*------------------------------------------------------------------* @@ -99,10 +100,8 @@ void encod_ppp_fx( Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); - find_targets_fx( speech_fx, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL - ,h1_fx - ); + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx); /* scale xn[] and h1[] to avoid overflow in dot_product12() */ Scale_sig(xn_fx, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */ @@ -122,28 +121,31 @@ void encod_ppp_fx( /* last frame-end lpc and curr frame-end lpc */ - ppp_voiced_encoder_fx( st_fx, res_fx, excQ_ppp_fx, T_op_fx[1], LPC_de_old_fx, - LPC_de_curr_fx, exc_fx, pitch_fx, st_fx->vadsnr_fx, Q_new ); + IF((error = ppp_voiced_encoder_fx(hBstr, hSC_VBR, st_fx->bwidth_fx, st_fx->last_coder_type_raw_fx, st_fx->old_pitch_buf_fx, res_fx, + excQ_ppp_fx, st_fx->pitch_fx[1], LPC_de_old_fx, LPC_de_curr_fx, exc_fx, pitch_fx, Q_new)) != IVAS_ERR_OK) + { + return error; + } Scale_sig(exc_fx, L_FRAME, (saved_Q_new - Q_new)); - if (EQ_16(st_fx->bump_up_fx,1)) + if (EQ_16(hSC_VBR->bump_up_fx,1)) { i_subfr = L_FRAME; move16(); } } - IF( NE_16(st_fx->bump_up_fx,1)) + IF( NE_16(hSC_VBR->bump_up_fx,1)) { /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - gp_clip_fx(st_fx->core_brate_fx, voicing_fx, i_subfr, *coder_type_fx, xn_fx, st_fx->clip_var_fx, sub(shift_wsp,1)); + gp_clip_fx(st_fx->element_mode, st_fx->core_brate_fx, st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub(shift_wsp,1)); /* run the above to maintain gain clipping memories */ - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, st_fx->prev_ppp_gain_pit_fx, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate_fx, hSC_VBR->prev_ppp_gain_pit_fx, st_fx->clip_var_fx ); /*-----------------------------------------------------------------* @@ -151,7 +153,7 @@ void encod_ppp_fx( * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s( 1, p_Aq_fx, M, &excQ_ppp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + Syn_filt_s( 1, p_Aq_fx, M, &excQ_ppp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); p_Aw_fx += (M+1); @@ -160,33 +162,37 @@ void encod_ppp_fx( } /* end of subframe loop */ - IF( st_fx->bump_up_fx ) + IF(hSC_VBR->bump_up_fx ) { /* PPP failed, bump up */ - st_fx->ppp_mode_fx = 0; + hSC_VBR->ppp_mode_fx = 0; move16(); st_fx->core_brate_fx = ACELP_7k20; move16(); - st_fx->pppcountE_fx = 0; + hSC_VBR->pppcountE_fx = 0; move16(); - IF ( st_fx->set_ppp_generic_fx ) + IF (hSC_VBR->set_ppp_generic_fx ) { - *coder_type_fx = GENERIC; + st_fx->coder_type = GENERIC; move16(); } ELSE { - *coder_type_fx = VOICED; + st_fx->coder_type = VOICED; move16(); } /* We write signalling indices again only in case of bump_up */ /* delete previous indices */ - reset_indices_enc_fx( st_fx ); +#ifndef IVAS_CODE_BITSTREAM + reset_indices_enc_fx(hBstr); +#else + reset_indices_enc_fx(hBstr, hBstr->nb_ind_tot ); +#endif /* signalling matrix (writing of signalling bits) */ - signalling_enc_fx( st_fx, *coder_type_fx, sharpFlag_fx ); + signalling_enc_fx( st_fx); } ELSE { @@ -196,22 +202,22 @@ void encod_ppp_fx( * Updates: last value of new target is stored in mem_w0 *-----------------------------------------------------------------*/ - mem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); /*Q_new-1 */ + hLPDmem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); /*Q_new-1 */ Copy(exc_fx, exc2_fx, L_FRAME); - st_fx->dm_fx.prev_state = 2; + hLPDmem->dm_fx.prev_state = 2; move16();/*Q0 dispMem index 0 */ - st_fx->dm_fx.prev_gain_pit[0] = st_fx->prev_ppp_gain_pit_fx; + hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; move16();/*Q14 dispMem index 2 */ FOR( k=1; k<5; k++ ) { - st_fx->dm_fx.prev_gain_pit[k] = st_fx->dm_fx.prev_gain_pit[k-1]; + hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k-1]; move16(); } - mem->tilt_code = st_fx->prev_tilt_code_fx; + hLPDmem->tilt_code = hSC_VBR->prev_tilt_code_fx; move16(); Copy(pitch_fx, pitch_buf_fx, NB_SUBFR); pitch_buf_fx[ NB_SUBFR16k -1 ] = pitch_fx[ NB_SUBFR - 1 ]; @@ -220,8 +226,10 @@ void encod_ppp_fx( set16_fx( voice_factors, 0, NB_SUBFR16k ); } - st_fx->rate_control_fx = rate_ctrl_fx; + hSC_VBR->rate_control_fx = rate_ctrl_fx; move16(); - return; + set16_fx(hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2); + + return error; } diff --git a/lib_enc/enc_prm.c b/lib_enc/enc_prm.c index 4ee6a97..25de7b7 100644 --- a/lib_enc/enc_prm.c +++ b/lib_enc/enc_prm.c @@ -19,16 +19,18 @@ static void enc_prm_hm( ) { Word8 flag; + BSTR_ENC_HANDLE hBstr = st->hBstr; + /* Disable HM for non-GC,VC modes */ test(); - IF (NE_16(st->tcx_cfg.coder_type, VOICED)&&NE_16(st->tcx_cfg.coder_type,GENERIC)) + IF (NE_16(st->hTcxCfg->coder_type, VOICED)&&NE_16(st->hTcxCfg->coder_type,GENERIC)) { return; } /* Flag */ - push_next_indice_fx(st, prm_hm[0], 1); + push_next_indice_fx(hBstr, prm_hm[0], 1); IF (prm_hm[0]) { @@ -40,12 +42,12 @@ static void enc_prm_hm( flag = 1; move16(); } - EncodeIndex(flag, prm_hm[1], st); + EncodeIndex(flag, prm_hm[1], hBstr); - IF (EQ_16(st->tcx_cfg.coder_type, VOICED)) + IF (EQ_16(st->hTcxCfg->coder_type, VOICED)) { /* Gain index */ - push_next_indice_fx(st, prm_hm[2], kTcxHmNumGainBits); + push_next_indice_fx(hBstr, prm_hm[2], kTcxHmNumGainBits); } } } @@ -64,6 +66,10 @@ void enc_prm_rf( Encoder_State_fx *st, { Word16 sfr, nb_subfr, n, index; Word16 ltp_mode, ltf_mode, gains_mode; + RF_ENC_HANDLE hRF = st->hRF; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + BSTR_ENC_HANDLE hBstr = st->hBstr; + nb_subfr = st->nb_subfr; @@ -76,25 +82,25 @@ void enc_prm_rf( Encoder_State_fx *st, /* LSF indices */ IF( EQ_16(rf_frame_type, RF_TCXFD)) { - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][0], lsf_numbits[0]); /* VQ 1 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][1], lsf_numbits[1]); /* VQ 2 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][2], lsf_numbits[2]); /* VQ 3 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], lsf_numbits[0]); /* VQ 1 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], lsf_numbits[1]); /* VQ 2 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][2], lsf_numbits[2]); /* VQ 3 */ } /* classification */ test(); test(); - IF( EQ_16(st->rf_clas[fec_offset], UNVOICED_CLAS)) + IF( EQ_16(hRF->rf_clas[fec_offset], UNVOICED_CLAS)) { index = 0; move16(); } - ELSE IF( (EQ_16(st->rf_clas[fec_offset], VOICED_TRANSITION))||(EQ_16(st->rf_clas[fec_offset],UNVOICED_TRANSITION))) + ELSE IF( (EQ_16(hRF->rf_clas[fec_offset], VOICED_TRANSITION))||(EQ_16(hRF->rf_clas[fec_offset],UNVOICED_TRANSITION))) { index = 1; move16(); } - ELSE IF( EQ_16(st->rf_clas[fec_offset], VOICED_CLAS)) + ELSE IF( EQ_16(hRF->rf_clas[fec_offset], VOICED_CLAS)) { index = 2; move16(); @@ -104,12 +110,12 @@ void enc_prm_rf( Encoder_State_fx *st, index = 3; move16(); } - push_next_indice_fx(st, index, 2); + push_next_indice_fx( hBstr, index, 2); IF( EQ_16(rf_frame_type, RF_TCXFD)) { /* TCX global gain = 7 bits */ - push_next_indice_fx(st, st->rf_gain_tcx[fec_offset], 7); + push_next_indice_fx( hBstr, hRF->rf_gain_tcx[fec_offset], 7); /*window info 1 bit for long overlap 2 if minimum or half overlap*/ @@ -123,37 +129,37 @@ void enc_prm_rf( Encoder_State_fx *st, /* pitch and gain */ /* LTP data */ test(); - IF ( (EQ_16(rf_frame_type, RF_TCXTD1)||EQ_16(rf_frame_type,RF_TCXTD2))&&st->tcxltp!=0) + IF ( (EQ_16(rf_frame_type, RF_TCXTD1)||EQ_16(rf_frame_type,RF_TCXTD2))&& hTcxEnc->tcxltp!=0) { - push_next_indice_fx(st, st->rf_tcxltp_param[fec_offset], 9); + push_next_indice_fx( hBstr, hRF->rf_tcxltp_param[fec_offset], 9); } } } ELSE IF( EQ_16(rf_frame_type,7)) /* NELP bitstream writing */ { /* LSF indices */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ /* NELP gain indices */ - push_next_indice_fx( st, st->rf_indx_nelp_iG1[fec_offset], 5 ); - push_next_indice_fx( st, st->rf_indx_nelp_iG2[fec_offset][0], 6 ); - push_next_indice_fx( st, st->rf_indx_nelp_iG2[fec_offset][1], 6 ); + push_next_indice_fx( hBstr, hRF->rf_indx_nelp_iG1[fec_offset], 5 ); + push_next_indice_fx( hBstr, hRF->rf_indx_nelp_iG2[fec_offset][0], 6 ); + push_next_indice_fx( hBstr, hRF->rf_indx_nelp_iG2[fec_offset][1], 6 ); /* NELP filter selection index */ - push_next_indice_fx( st, st->rf_indx_nelp_fid[fec_offset], 2 ); + push_next_indice_fx( hBstr, hRF->rf_indx_nelp_fid[fec_offset], 2 ); /* tbe gainFr */ - push_next_indice_fx( st, st->rf_indx_tbeGainFr[fec_offset], 5 ); + push_next_indice_fx( hBstr, hRF->rf_indx_tbeGainFr[fec_offset], 5 ); } ELSE IF ( GE_16(rf_frame_type,4)) /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6 */ { /* LSF indices */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ + push_next_indice_fx( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ /* ES pred */ - push_next_indice_fx(st, st->rf_indx_EsPred[fec_offset], 3); + push_next_indice_fx( hBstr, hRF->rf_indx_EsPred[fec_offset], 3); ltp_mode = ACELP_LTP_MODE[1][1][rf_frame_type]; ltf_mode = ACELP_LTF_MODE[1][1][rf_frame_type]; @@ -166,13 +172,13 @@ void enc_prm_rf( Encoder_State_fx *st, n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; IF (n != 0) { - push_next_indice_fx(st, st->rf_indx_pitch[fec_offset][sfr], n); + push_next_indice_fx( hBstr, hRF->rf_indx_pitch[fec_offset][sfr], n); } /* Adaptive codebook filtering (1 bit) */ IF( EQ_16(ltf_mode,2)) { - push_next_indice_fx(st, st->rf_indx_ltfMode[fec_offset][sfr], 1); + push_next_indice_fx( hBstr, hRF->rf_indx_ltfMode[fec_offset][sfr], 1); } /*Innovative codebook*/ @@ -183,7 +189,7 @@ void enc_prm_rf( Encoder_State_fx *st, (EQ_16(rf_frame_type,RF_GENPRED) && (sfr == 0 || EQ_16(sfr,2))) ) { - push_next_indice_fx(st, st->rf_indx_fcb[fec_offset][sfr], 7); + push_next_indice_fx( hBstr, hRF->rf_indx_fcb[fec_offset][sfr], 7); } /* Gains (5b, 6b or 7b / subfr) */ @@ -191,11 +197,11 @@ void enc_prm_rf( Encoder_State_fx *st, IF( sfr == 0 || EQ_16(sfr,2)) { n = ACELP_GAINS_BITS[gains_mode]; - push_next_indice_fx(st, st->rf_indx_gain[fec_offset][sfr], n); + push_next_indice_fx( hBstr, hRF->rf_indx_gain[fec_offset][sfr], n); } } /* tbe gainFr */ - push_next_indice_fx( st, st->rf_indx_tbeGainFr[fec_offset], 2 ); + push_next_indice_fx( hBstr, hRF->rf_indx_tbeGainFr[fec_offset], 2 ); } /***************/ @@ -209,15 +215,15 @@ void enc_prm_rf( Encoder_State_fx *st, test(); IF(EQ_16(fec_offset,2)) { - push_next_indice_fx(st, 0, 2); + push_next_indice_fx( hBstr, 0, 2); } ELSE IF(EQ_16(fec_offset,3)||EQ_16(fec_offset,5)||EQ_16(fec_offset,7)) { - push_next_indice_fx(st, (fec_offset - 1)/2, 2); + push_next_indice_fx( hBstr, (fec_offset - 1)/2, 2); } /* write RF frame type last in the bitstream */ - push_next_indice_fx(st, rf_frame_type, 3); + push_next_indice_fx( hBstr, rf_frame_type, 3); } @@ -262,6 +268,8 @@ void enc_prm( Word16 idx; Word16 start_idx; Word16 nBits; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + BSTR_ENC_HANDLE hBstr = st->hBstr; /*--------------------------------------------------------------------------------* * INIT @@ -294,7 +302,7 @@ void enc_prm( move16(); move16(); j = 0; - nbits_start = st->nb_bits_tot_fx; + nbits_start = hBstr->nb_bits_tot_fx; /*--------------------------------------------------------------------------------* @@ -314,7 +322,7 @@ void enc_prm( IF ( st->tcxonly ) { - push_next_indice_fx(st, core==TCX_10_CORE, 1); + push_next_indice_fx( hBstr, core==TCX_10_CORE, 1); { index = 3; move16(); @@ -334,7 +342,7 @@ void enc_prm( index = 2; move16(); } - push_next_indice_fx(st, index, 2); + push_next_indice_fx( hBstr, index, 2); } } ELSE @@ -362,13 +370,13 @@ void enc_prm( { idx = add(idx,1); } - push_next_indice_fx( st, idx - start_idx, nBits); - push_next_indice_fx( st, 0, 1); /* Indicate to the decoder that the core is ACELP*/ + push_next_indice_fx( hBstr, idx - start_idx, nBits); + push_next_indice_fx( hBstr, 0, 1); /* Indicate to the decoder that the core is ACELP*/ nbits_start = 3; } ELSE { - push_next_indice_fx(st, coder_type, 3); + push_next_indice_fx( hBstr, coder_type, 3); } } ELSE @@ -376,15 +384,15 @@ void enc_prm( IF (EQ_16(st->mdct_sw, MODE1)) { /* 2 bits instead of 3 as TCX is already signaled */ - push_next_indice_fx(st, st->tcx_cfg.coder_type, 2 ); + push_next_indice_fx( hBstr, st->hTcxCfg->coder_type, 2 ); } ELSE { IF (EQ_16(st->mdct_sw_enable, MODE2)) { - push_next_indice_fx(st, 1, 1); /* TCX */ - push_next_indice_fx(st, 0, 1); /* not HQ_CORE */ - push_next_indice_fx(st, st->tcx_cfg.coder_type, 2); + push_next_indice_fx( hBstr, 1, 1); /* TCX */ + push_next_indice_fx( hBstr, 0, 1); /* not HQ_CORE */ + push_next_indice_fx( hBstr, st->hTcxCfg->coder_type, 2); } ELSE { @@ -403,9 +411,9 @@ void enc_prm( test(); test(); - IF(EQ_16(st->tcx_cfg.coder_type,VOICED)|| - EQ_16(st->tcx_cfg.coder_type,GENERIC)|| - EQ_16(st->tcx_cfg.coder_type,TRANSITION)) + IF(EQ_16(st->hTcxCfg->coder_type,VOICED)|| + EQ_16(st->hTcxCfg->coder_type,GENERIC)|| + EQ_16(st->hTcxCfg->coder_type,TRANSITION)) { st->sharpFlag=1; } @@ -417,18 +425,18 @@ void enc_prm( /* retrieve the signalling index */ idx = add(idx,1); start_idx = idx; - tmp32 = SIG2IND_fx(st->tcx_cfg.coder_type, st->bwidth_fx, st->sharpFlag, st->rf_mode); + tmp32 = SIG2IND_fx(st->hTcxCfg->coder_type, st->bwidth_fx, st->sharpFlag, st->rf_mode); WHILE( NE_32(acelp_sig_tbl[idx], tmp32)) { idx = add(idx,1); } - push_next_indice_fx( st, idx - start_idx, nBits); - push_next_indice_fx( st, 1, 1); /* Indicate to the decoder that the core is TCX*/ + push_next_indice_fx( hBstr, idx - start_idx, nBits); + push_next_indice_fx( hBstr, 1, 1); /* Indicate to the decoder that the core is TCX*/ nbits_start = 3; } ELSE { - push_next_indice_fx(st, 4+st->tcx_cfg.coder_type, 3 ); + push_next_indice_fx( hBstr, 4+st->hTcxCfg->coder_type, 3 ); } } } @@ -437,7 +445,7 @@ void enc_prm( /* Encode previous mode for error concealment */ test(); - IF (!(core==ACELP_CORE&&st->tcx_cfg.lfacNext<=0)) + IF (!(core==ACELP_CORE&&st->hTcxCfg->lfacNext<=0)) { tmp = 0; move16(); @@ -448,22 +456,22 @@ void enc_prm( tmp = TCX_20_CORE; move16(); } - push_next_indice_fx(st, tmp, 1); + push_next_indice_fx( hBstr, tmp, 1); } /* write TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ IF ( core!=ACELP_CORE ) { Word16 overlap_code; - assert(st->tcx_cfg.tcx_curr_overlap_mode != NOT_SUPPORTED && st->tcx_cfg.tcx_curr_overlap_mode <= ALDO_WINDOW && st->tcx_cfg.tcx_curr_overlap_mode >= FULL_OVERLAP); /*1 is not allowed!*/ - IF (EQ_16(st->tcx_cfg.tcx_curr_overlap_mode, MIN_OVERLAP)) + assert(st->hTcxCfg->tcx_curr_overlap_mode != NOT_SUPPORTED && st->hTcxCfg->tcx_curr_overlap_mode <= ALDO_WINDOW && st->hTcxCfg->tcx_curr_overlap_mode >= FULL_OVERLAP); /*1 is not allowed!*/ + IF (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, MIN_OVERLAP)) { nbits_tcx = 2; move16(); overlap_code = 2; move16(); } - ELSE IF (EQ_16(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP)) + ELSE IF (EQ_16(st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP)) { nbits_tcx = 2; move16(); @@ -477,13 +485,13 @@ void enc_prm( overlap_code = 0; move16(); } - push_next_indice_fx(st, overlap_code, nbits_tcx); + push_next_indice_fx( hBstr, overlap_code, nbits_tcx); } - IF( st->plcExt.enableGplc ) + IF( st->hPlcExt->enableGplc ) { /* encode side information. */ - enc_prm_side_Info( &st->plcExt, st ); + enc_prm_side_Info( st->hPlcExt, st ); } IF( st->glr != 0) @@ -500,14 +508,14 @@ void enc_prm( IF( EQ_16(core,ACELP_CORE)) { - push_next_indice_fx(st, st->glr_idx[0], G_LPC_RECOVERY_BITS); + push_next_indice_fx( hBstr, st->glr_idx[0], G_LPC_RECOVERY_BITS); } } st->glr_reset = 0; move16(); - nbits_header = sub(st->nb_bits_tot_fx, nbits_start); + nbits_header = sub(hBstr->nb_bits_tot_fx, nbits_start); /*--------------------------------------------------------------------------------* @@ -517,7 +525,7 @@ void enc_prm( IF ( s_and(st->enableTcxLpc!=0, core != ACELP_CORE) ) { /* Encode the indices */ - nbits_lpc = enc_lsf_tcxlpc(¶m_lpc, st); + nbits_lpc = enc_lsf_tcxlpc(¶m_lpc, hBstr); } ELSE { @@ -532,7 +540,7 @@ void enc_prm( move16(); } - nbits_lpc = encode_lpc_avq(st, numlpc, param_lpc, core); + nbits_lpc = encode_lpc_avq(hBstr, numlpc, param_lpc, st->core_fx, st->element_mode); } ELSE IF (EQ_16(st->lpcQuantization, 1)) { @@ -540,11 +548,11 @@ void enc_prm( test(); IF(EQ_32(st->sr_core, 16000)&&EQ_16(coder_type,VOICED)&&EQ_16(core,ACELP_CORE)) { - nbits_lpc = lsf_bctcvq_encprm(st, param_lpc, bits_param_lpc, no_param_lpc); + nbits_lpc = lsf_bctcvq_encprm(hBstr, param_lpc, bits_param_lpc, no_param_lpc); } ELSE { - nbits_lpc = lsf_msvq_ma_encprm(st, param_lpc, core, coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); + nbits_lpc = lsf_msvq_ma_encprm(hBstr, param_lpc, core, coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); } } ELSE @@ -571,7 +579,7 @@ void enc_prm( IF(n!=0) { - push_next_indice_fx(st, st->bpf_gain_param, n); + push_next_indice_fx( hBstr, st->bpf_gain_param, n); } /* Mean energy (2 or 3 bits) */ @@ -579,7 +587,7 @@ void enc_prm( IF(n!=0) { - push_next_indice_fx(st, prm[j++], n); + push_next_indice_fx( hBstr, prm[j++], n); } /* Subframe parameters */ @@ -592,14 +600,14 @@ void enc_prm( IF (n!=0) { - push_next_indice_fx(st, prm[j++], n); + push_next_indice_fx( hBstr, prm[j++], n); } /* Adaptive codebook filtering (1 bit) */ IF(EQ_16(st->acelp_cfg.ltf_mode,2)) { - push_next_indice_fx(st, prm[j++], 1); + push_next_indice_fx( hBstr, prm[j++], 1); } /*Innovative codebook*/ @@ -621,12 +629,12 @@ void enc_prm( FOR (ix = 0; ix < wordcnt; ix++) { - push_next_indice_fx(st, prm[j++], 16); + push_next_indice_fx( hBstr, prm[j++], 16); } IF (bitcnt) { - push_next_indice_fx(st, prm[j++], bitcnt); + push_next_indice_fx( hBstr, prm[j++], bitcnt); } j = add(j_old, 8); @@ -634,7 +642,7 @@ void enc_prm( /* Gains (5b, 6b or 7b / subfr) */ n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; - push_next_indice_fx(st, prm[j++], n); + push_next_indice_fx( hBstr, prm[j++], n); }/*end of for(sfr)*/ }/*end of mode[0]==0*/ @@ -648,28 +656,28 @@ void enc_prm( move16(); IF(st->enablePlcWaveadjust) { - push_next_indice_fx(st, st->Tonal_SideInfo, 1); + push_next_indice_fx( hBstr, st->Tonal_SideInfo, 1); } /* TCX Gain = 7 bits */ - push_next_indice_fx(st, prm[j++], 7); + push_next_indice_fx( hBstr, prm[j++], 7); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - push_next_indice_fx(st, prm[j++], NBITS_NOISE_FILL_LEVEL); + push_next_indice_fx( hBstr, prm[j++], NBITS_NOISE_FILL_LEVEL); /* LTP data */ test(); - IF ( st->tcxltp || GT_32(st->sr_core, 25600)) + IF (hTcxEnc->tcxltp || GT_32(st->sr_core, 25600)) { IF ( prm[j] ) { - push_next_indice_fx(st, 1 , 1); - push_next_indice_fx(st, prm[j+1], 9); - push_next_indice_fx(st, prm[j+2], 2); + push_next_indice_fx( hBstr, 1 , 1); + push_next_indice_fx( hBstr, prm[j+1], 9); + push_next_indice_fx( hBstr, prm[j+2], 2); } ELSE { - push_next_indice_fx(st, 0 , 1); + push_next_indice_fx( hBstr, 0 , 1); } } j = add(j, 3); @@ -677,17 +685,17 @@ void enc_prm( /* TCX spectral data */ lg = L_frame; move16(); - lgFB = st->tcx_cfg.tcx_coded_lines; + lgFB = st->hTcxCfg->tcx_coded_lines; move16(); IF ( last_core==ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); + lg = add(lg, st->hTcxCfg->tcx_offset); lgFB = add(lgFB, shr(lgFB, 2)); - if(st->tcx_cfg.lfacNext<0) + if(st->hTcxCfg->lfacNext<0) { - lg = sub(lg,st->tcx_cfg.lfacNext); + lg = sub(lg,st->hTcxCfg->lfacNext); } } @@ -697,28 +705,28 @@ void enc_prm( nTnsBits = 0; move16(); - IF (st->tcx_cfg.fIsTNSAllowed) + IF (st->hTcxCfg->fIsTNSAllowed) { - WriteTnsData(st->tcx_cfg.pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); + WriteTnsData(st->hTcxCfg->pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); j = add(j, nTnsParams); } - hm_size = shl(mult(st->tcx_cfg.bandwidth, lg), 1); + hm_size = shl(mult(st->hTcxCfg->bandwidth, lg), 1); test(); - IF ( st->tcx_lpc_shaped_ari && NE_16(last_core, ACELP_CORE)) + IF (hTcxEnc->tcx_lpc_shaped_ari && NE_16(last_core, ACELP_CORE)) { enc_prm_hm(&prm[j], st, hm_size); } /*Context HM flag*/ test(); - IF ( st->tcx_cfg.ctx_hm && NE_16(last_core, ACELP_CORE)) + IF ( st->hTcxCfg->ctx_hm && NE_16(last_core, ACELP_CORE)) { - push_next_indice_fx(st, prm[j], 1); + push_next_indice_fx( hBstr, prm[j], 1); IF (prm[j]) { - EncodeIndex(sub(hm_size,256) >= 0, prm[j+1], st); + EncodeIndex(sub(hm_size,256) >= 0, prm[j+1], hBstr); flag_ctx_hm = 1; move16(); } @@ -727,29 +735,27 @@ void enc_prm( IF (st->igf) { - st->hIGFEnc.infoTotalBitsPerFrameWritten = 0; + st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); IF (EQ_16(st->last_core_fx, ACELP_CORE)) { - IGFEncWriteBitstream( &st->hIGFEnc, st, &st->hIGFEnc.infoTotalBitsPerFrameWritten, - IGF_GRID_LB_TRAN, 1 ); + IGFEncWriteBitstream( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_TRAN, 1 ); } ELSE { - IGFEncWriteBitstream( &st->hIGFEnc, st, &st->hIGFEnc.infoTotalBitsPerFrameWritten, - IGF_GRID_LB_NORM, 1 ); + IGFEncWriteBitstream( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1 ); } } - total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); + total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); if(EQ_16(st->rf_mode,1)) { total_nbbits = add(total_nbbits,st->rf_target_bits_write); } nbits_tcx = sub(st->bits_frame_core, total_nbbits); - IF (st->tcx_lpc_shaped_ari != 0) + IF (hTcxEnc->tcx_lpc_shaped_ari != 0) { - push_next_bits_fx(st, &prm[++j], nbits_tcx); + push_next_bits_fx(hBstr, &prm[++j], nbits_tcx); j = add(j, nbits_tcx); } ELSE @@ -761,10 +767,10 @@ void enc_prm( phm_cfg = hm_cfg; move16(); } - ACcontextMapping_encode2_no_mem_s17_LC(st, prm+j, + ACcontextMapping_encode2_no_mem_s17_LC(hBstr, prm+j, lgFB, prm[j-1], /* lastnz */ - nbits_tcx, NPRM_RESQ * st->tcx_cfg.resq, phm_cfg); + nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg); } } @@ -781,7 +787,7 @@ void enc_prm( move16(); IF (st->igf) { - nbits_igf = IGFEncWriteConcatenatedBitstream( &st->hIGFEnc, st ); + nbits_igf = IGFEncWriteConcatenatedBitstream( st->hIGFEnc, hBstr ); } FOR (k = 0; k < 2; k++) { @@ -795,50 +801,50 @@ void enc_prm( j = 0; move16(); - nbits_tcx = total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); + nbits_tcx = total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); test(); IF(st->enablePlcWaveadjust && k) { - push_next_indice_fx(st, st->Tonal_SideInfo, 1); + push_next_indice_fx( hBstr, st->Tonal_SideInfo, 1); } /* TCX Gain = 7 bits */ - push_next_indice_fx(st, prm[j++], 7); + push_next_indice_fx( hBstr, prm[j++], 7); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - push_next_indice_fx(st, prm[j++], NBITS_NOISE_FILL_LEVEL); + push_next_indice_fx( hBstr, prm[j++], NBITS_NOISE_FILL_LEVEL); /* LTP data */ test(); test(); - IF ( (k == 0) && (st->tcxltp!=0 || GT_32(st->sr_core, 25600)))/* PLC pitch info for HB */ + IF ( (k == 0) && (hTcxEnc->tcxltp!=0 || GT_32(st->sr_core, 25600)))/* PLC pitch info for HB */ { IF ( prm[j] ) { - push_next_indice_fx(st, 1 , 1); - push_next_indice_fx(st, prm[j+1], 9); - push_next_indice_fx(st, prm[j+2], 2); + push_next_indice_fx( hBstr, 1 , 1); + push_next_indice_fx( hBstr, prm[j+1], 9); + push_next_indice_fx( hBstr, prm[j+2], 2); } ELSE { - push_next_indice_fx(st, 0 , 1); + push_next_indice_fx( hBstr, 0 , 1); } } j = add(j, 3); /* TCX spectral data */ lg = shr(L_frame, 1); - lgFB = shr(st->tcx_cfg.tcx_coded_lines, 1); + lgFB = shr(st->hTcxCfg->tcx_coded_lines, 1); IF ( s_and(k==0, last_core==ACELP_CORE) ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); + lg = add(lg, st->hTcxCfg->tcx_offset); lgFB = add(lgFB, shr(lgFB, 1)); - if(st->tcx_cfg.lfacNext<0) + if(st->hTcxCfg->lfacNext<0) { - lg = sub(lg,st->tcx_cfg.lfacNext); + lg = sub(lg,st->hTcxCfg->lfacNext); } } @@ -848,34 +854,34 @@ void enc_prm( nTnsParams = 0; nTnsBits = 0; - IF (st->tcx_cfg.fIsTNSAllowed) + IF (st->hTcxCfg->fIsTNSAllowed) { - SetTnsConfig(&st->tcx_cfg, 0, (last_core == ACELP_CORE) && (k == 0)); + SetTnsConfig(st->hTcxCfg, 0, (last_core == ACELP_CORE) && (k == 0)); - WriteTnsData(st->tcx_cfg.pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); + WriteTnsData(st->hTcxCfg->pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); j = add(j, nTnsParams); } - hm_size = shl(mult(st->tcx_cfg.bandwidth, lgFB), 1); + hm_size = shl(mult(st->hTcxCfg->bandwidth, lgFB), 1); /*Context HM flag*/ test(); test(); - IF ( st->tcx_cfg.ctx_hm && !(last_core == ACELP_CORE && k == 0) ) + IF ( st->hTcxCfg->ctx_hm && !(last_core == ACELP_CORE && k == 0) ) { - push_next_indice_fx(st, prm[j], 1); + push_next_indice_fx( hBstr, prm[j], 1); IF (prm[j]) { - EncodeIndex(sub(hm_size,256) >= 0, prm[j+1], st); + EncodeIndex(sub(hm_size,256) >= 0, prm[j+1], hBstr); flag_ctx_hm = 1; move16(); } } j = add(j, NPRM_CTX_HM); - total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); + total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); nbits_tcx = sub(shr(sub(add(sub(sub(sub(st->bits_frame_core, nbits_header), nbits_lpc), nbits_igf), 1), k), 1), sub(total_nbbits, nbits_tcx)); @@ -886,10 +892,10 @@ void enc_prm( phm_cfg = &hm_cfg[k]; move16(); } - ACcontextMapping_encode2_no_mem_s17_LC(st, prm+j, + ACcontextMapping_encode2_no_mem_s17_LC(hBstr, prm+j, lgFB, prm[j-1], /* lastnz */ - nbits_tcx, NPRM_RESQ * st->tcx_cfg.resq, phm_cfg); + nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, phm_cfg); } /* k, window index */ } @@ -900,7 +906,7 @@ void enc_prm( *--------------------------------------------------------------------------------*/ - total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); + total_nbbits = sub(hBstr->nb_bits_tot_fx, nbits_start); /* Check if total encoded bits does not exceed CBR target bits (->this must never happen) */ diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index ee87cd6..a00c1d2 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -1,14 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ - -#include "stl.h" - /*=================================================================================*/ /* FUNCTION : void encod_tran_fx () */ /*---------------------------------------------------------------------------------*/ @@ -45,15 +42,10 @@ Word16 encod_tran_fx( Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ const Word16 speech_fx[], /* i : input speech */ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 coder_type, /* i : coding type */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ const Word16 *res_fx, /* i : residual signal */ Word16 *syn_fx, /* i/o: core synthesis */ Word16 *exc_fx, /* i/o: current non-enhanced excitation */ @@ -61,9 +53,9 @@ Word16 encod_tran_fx( Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ Word16 *voice_factors, /* o : voicing factors */ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - const Word16 gsc_attack_flag, /* i : Flag to indicate when an audio attack is deal with TM */ + Word16 tc_subfr, /* i/o: TC subframe classification */ + Word16 position, /* i : maximum of residual signal index */ Word16 *unbits, /* i/o: number of unused bits */ - Word16 sharpFlag, /* o : formant sharpening flag */ const Word16 shift, /* i : Scaling to get 12 bits */ const Word16 Q_new /* i : Input scaling */ ) @@ -81,8 +73,9 @@ Word16 encod_tran_fx( Word32 gain_code = 0; /* Gain of code */ Word32 Lgcode; Word16 gain_inov=0; /* inovation gain */ - Word16 i, i_subfr, tc_subfr,tmp1_fx,tmp_fx; /* tmp variables */ - Word16 position, T0_min, T0_max; /* pitch and TC variables */ + Word16 i, i_subfr,tmp1_fx,tmp_fx; /* tmp variables */ + Word16 unbits_ACELP; + Word16 T0_min, T0_max; /* pitch and TC variables */ Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ Word16 *pt_pitch; /* pointer to floating pitch buffer */ Word16 g_corr[10]; /* ACELP correlation values and gain pitch */ @@ -93,10 +86,15 @@ Word16 encod_tran_fx( Word16 Jopt_flag; /* joint optimization flag */ Word16 unbits_PI = 0; /* saved bits for PI */ Word32 norm_gain_code=0; - + Word16 L_frame_fx; Word16 shift_wsp; Word32 L_tmp; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + L_frame_fx = st_fx->L_frame_fx; + move16(); /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ @@ -125,13 +123,10 @@ Word16 encod_tran_fx( /**unbits = 0;move16();*/ Jopt_flag = 0; move16(); - tc_subfr = -1; + unbits_ACELP = *unbits; + move16(); + *unbits = 0; move16(); - if( gsc_attack_flag ) - { - tc_subfr = 3*L_SUBFR; - move16(); - } p_Aw = Aw_fx; p_Aq = Aq_fx; @@ -155,7 +150,7 @@ Word16 encod_tran_fx( Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); - find_targets_fx( speech_fx, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq, + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); Copy_Scale_sig(h1, h2_fx, L_SUBFR, -2); @@ -169,26 +164,25 @@ Word16 encod_tran_fx( * adaptive/glottal part of excitation construction *-----------------------------------------------------------------*/ - transition_enc_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type, i_subfr, &tc_subfr, &Jopt_flag, &position, voicing_fx, T_op_fx, &T0, - &T0_frac, &T0_min, &T0_max, exc_fx, y1, res_fx, h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx ,Q_new,shift); + transition_enc_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1, + h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx ,&unbits_ACELP, Q_new,shift); /*-----------------------------------------------------------------* * Transform domain contribution encoding - active frames *-----------------------------------------------------------------*/ - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)) + IF( GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC)) { - transf_cdbk_enc_fx( st_fx, st_fx->core_brate_fx, st_fx->extl_fx, coder_type, 0, i_subfr, tc_subfr, cn, exc_fx, - p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, &gain_pit, gain_code, g_corr, clip_gain, - &(st_fx->mem_deemp_preQ_fx), &(st_fx->mem_preemp_preQ_fx), &gain_preQ, code_preQ, unbits, Q_new, shift); + transf_cdbk_enc_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, + &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift); } /*-----------------------------------------------------------------* * ACELP codebook search + pitch sharpening *-----------------------------------------------------------------*/ - inov_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, st_fx->last_L_frame_fx, coder_type, st_fx->bwidth_fx, sharpFlag, - i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, shift ); + inov_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, st_fx->last_L_frame_fx, st_fx->coder_type, st_fx->bwidth_fx, st_fx->sharpFlag, + i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift ); test(); test(); @@ -206,7 +200,7 @@ Word16 encod_tran_fx( IF( Jopt_flag == 0 ) { /* SQ gain_code */ - gain_enc_tc_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, i_subfr, tc_subfr, xn, y2, code, Es_pred_fx, + gain_enc_tc_fx(hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp ); } ELSE @@ -214,21 +208,21 @@ Word16 encod_tran_fx( IF ( GT_32(st_fx->core_brate_fx,ACELP_32k)) { /* SQ gain_pit and gain_code */ - gain_enc_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type, i_subfr, tc_subfr, xn, y1, y2, code, Es_pred_fx, + gain_enc_SQ_fx(hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp ); } ELSE { /* VQ gain_pit and gain_code */ - gain_enc_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx, + gain_enc_mless_fx(hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); } } - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, gain_pit, st_fx->clip_var_fx ); + gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate_fx, gain_pit, st_fx->clip_var_fx ); Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx(Lgcode); - mem->tilt_code = Est_tilt2(&exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); + hLPDmem->tilt_code = Est_tilt2(&exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ @@ -240,7 +234,7 @@ Word16 encod_tran_fx( L_tmp = L_mac(L_tmp, xn[L_SUBFR - 1], 16384); L_tmp = L_msu(L_tmp, y1[L_SUBFR - 1], gain_pit); L_tmp = L_shl(L_tmp, sub(1, shift)); - mem->mem_w0 = round_fx(L_tmp); /*Q_new-1*/ + hLPDmem->mem_w0 = round_fx(L_tmp); /*Q_new-1*/ /*-----------------------------------------------------------------* * Construct adaptive part of the excitation @@ -287,7 +281,7 @@ Word16 encod_tran_fx( * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - IF( GT_32(st_fx->core_brate_fx,ACELP_24k40)) + IF( GE_32(st_fx->core_brate_fx, MIN_BRATE_AVQ_EXC)) { tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); FOR( i = 0; i < L_SUBFR; i++ ) @@ -308,14 +302,14 @@ Word16 encod_tran_fx( *-----------------------------------------------------------------*/ prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, coder_type, st_fx->core_brate_fx ); + bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate_fx ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); p_Aw += (M+1); p_Aq += (M+1); @@ -326,7 +320,7 @@ Word16 encod_tran_fx( WHILE( unbits_PI > 0 ) { i = s_min(unbits_PI, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); + push_indice_fx( hBstr, IND_UNUSED, 0, i ); unbits_PI -= i; } @@ -335,47 +329,47 @@ Word16 encod_tran_fx( { IF( EQ_16(tc_subfr,TC_0_0)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } ELSE IF( EQ_16(tc_subfr,TC_0_64)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } ELSE IF( EQ_16(tc_subfr,TC_0_128)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); } ELSE IF( EQ_16(tc_subfr,TC_0_192)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } ELSE IF( EQ_16(tc_subfr,L_SUBFR)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } ELSE IF( EQ_16(tc_subfr,2*L_SUBFR)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } ELSE IF( EQ_16(tc_subfr,3*L_SUBFR)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); } } @@ -383,34 +377,37 @@ Word16 encod_tran_fx( { IF( tc_subfr == 0 ) { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 2 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 2 ); } ELSE IF( EQ_16(tc_subfr,L_SUBFR)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 2 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 2 ); } ELSE IF( EQ_16(tc_subfr,2*L_SUBFR)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 2, 2 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 2, 2 ); } ELSE IF( EQ_16(tc_subfr,3*L_SUBFR)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 3, 2 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 3, 2 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 0, 1 ); } ELSE IF( EQ_16(tc_subfr,4*L_SUBFR)) { - push_indice_fx( st_fx, IND_TC_SUBFR, 3, 2 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 3, 2 ); + push_indice_fx( hBstr, IND_TC_SUBFR, 1, 1 ); } } - /* SC-VBR */ - st_fx->prev_ppp_gain_pit_fx = gain_pit; - move16(); - st_fx->prev_tilt_code_fx = mem->tilt_code; - move16(); + IF(st_fx->Opt_SC_VBR_fx) + { + /* SC-VBR */ + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; + move16(); + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + move16(); + } return tc_subfr; } diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 798af31..25b92ae 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -1,11 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * encod_unvoiced() @@ -14,35 +14,48 @@ *-------------------------------------------------------------------*/ /*fixed point implementation of unvoiced_encoder*/ void encod_unvoiced_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 vad_flag_fx, - const Word16 *res_fx, /* i : residual signal */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 *speech_fx, /* i : Input speech */ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ + const Word16 Es_pred, /* i : predicted scaled innov. energy */ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ + const Word16 *res_fx, /* i : residual signal */ Word16 *syn_fx, /* o : core synthesis */ Word16 *tmp_noise_fx, /* o : long-term noise energy */ Word16 *exc_fx, /* i/o: current non-enhanced excitation */ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ const Word16 Q_new, const Word16 shift ) { - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ - Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 gain_pit_fx; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 L_gain_code_fx; /* gain of code */ - Word16 gain_inov_fx; /* inovative gain */ + Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ + Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ + Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ + Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ + Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ + Word16 gain_pit_fx; /* Pitch gain */ + Word16 voice_fac_fx; /* Voicing factor */ + Word32 L_gain_code_fx; /* gain of code */ + Word16 gain_inov_fx; /* inovative gain */ + Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ + Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ + Word16 code2[L_SUBFR]; /* Gaussian excitation */ + Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */ + Word16 prm_t[2 * NPRM_DIV], *prm = prm_t; const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ - Word16 i_subfr; + Word16 i_subfr, clip_gain, Q_xn, Q_new_p5, tmp2, j, i; Word32 norm_gain_code_fx; + ACELP_config* acelp_cfg; + ACELP_CbkCorr g_corr; + Word32 gain_code2; + Word32 gain_code_vect[2], Ltmp, Ltmp2; + Word16 exc2[L_SUBFR], index, i_subfr_idx; + acelp_cfg = &(st_fx->acelp_cfg); + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; /*------------------------------------------------------------------* * Initializations @@ -53,17 +66,20 @@ void encod_unvoiced_fx( test(); test(); test(); - IF( st_fx->Opt_SC_VBR_fx && vad_flag_fx == 0 && (EQ_16(st_fx->last_ppp_mode_fx,1)||EQ_16(st_fx->last_nelp_mode_fx,1))) + IF( st_fx->Opt_SC_VBR_fx && st_fx->vad_flag == 0 && (EQ_16(hSC_VBR->last_ppp_mode_fx,1) || EQ_16(hSC_VBR->last_nelp_mode_fx,1))) { /* SC_VBR - reset the encoder, to avoid memory not updated issue for the case when UNVOICED mode is used to code inactive speech */ - CNG_reset_enc_fx( st_fx, mem, pitch_buf_fx, voice_factors_fx, 1 ); + CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 1 ); } p_Aw_fx = Aw_fx; p_Aq_fx = Aq_fx; pt_pitch_fx = pitch_buf_fx; move16(); + Q_xn = add(sub(Q_new, 1), shift); + Q_new_p5 = add(Q_new, 5); + FOR (i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, NULL - ,h1_fx - ); + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx); + /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ Scale_sig(h1_fx, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ @@ -86,13 +102,121 @@ void encod_unvoiced_fx( /*----------------------------------------------------------------* * Unvoiced subframe processing *----------------------------------------------------------------*/ - - *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &mem->mem_w0, st_fx->clip_var_fx, - &mem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, - &voice_fac_fx, &gain_pit_fx, Q_new,shift,&norm_gain_code_fx, st_fx->core_brate_fx ); + IF (!uc_two_stage_flag) + { + *pt_pitch_fx = gaus_encode_fx(st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, + &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, + &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx); + } + ELSE + { + /*----------------------------------------------------------------* + * Unvoiced subframe processing in two stages + *----------------------------------------------------------------*/ + PMT("The code below needs validation, never been tested") + /* No adaptive codebook (UC) */ + set16_fx(y1, 0, L_SUBFR); + set16_fx(exc_fx + i_subfr, 0, L_SUBFR); + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ + clip_gain = Mode2_gp_clip(st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn); + *pt_pitch_fx = L_SUBFR; + move16(); + /*----------------------------------------------------------------------* + * Encode the algebraic innovation * + *----------------------------------------------------------------------*/ + + E_ACELP_innovative_codebook(exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame_fx, st_fx->last_L_frame_fx, st_fx->total_brate_fx); + + E_ACELP_xy2_corr(xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn); + + g_corr.y2y2_e = sub(g_corr.y2y2_e, 18); /* -18 (y2*y2: Q9*Q9) */ + g_corr.xy2_e = sub(g_corr.xy2_e, add(Q_xn, 9)); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ + g_corr.y1y2_e = sub(g_corr.y1y2_e, add(Q_xn, 9)); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ + g_corr.xx_e = sub(g_corr.xx_e, add(Q_xn, Q_xn)); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + + assert(gain_pit_fx == 0); + gauss_L2(h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &(st_fx->seed_acelp), shift); + + /*----------------------------------------------------------* + * - Compute the fixed codebook gain * + * - quantize fixed codebook gain * + *----------------------------------------------------------*/ + + index = gain_enc_uv(code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, + st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV); + +#ifdef DEBUGGING + assert(st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported"); +#endif + push_indice_fx(st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx]); + + gp_clip_test_gain_pit_fx(st_fx->element_mode, st_fx->core_brate_fx, gain_pit_fx, st_fx->clip_var_fx); + + gain_code_vect[0] = L_gain_code_fx; + move32(); + gain_code_vect[1] = L_gain_code_fx; + move32(); + + /*----------------------------------------------------------* + * - voice factor (for pitch enhancement) * + *----------------------------------------------------------*/ + E_UTIL_voice_factor(exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &(hLPDmem->tilt_code), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift); + + IF(st_fx->Opt_RF_ON) + { + st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code; + } + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = Mpy_32_16_1(L_gain_code_fx, y2_fx[L_SUBFR - 1]); + Ltmp = L_shl(Ltmp, add(5, Q_xn)); + Ltmp = L_mac(Ltmp, y1[L_SUBFR - 1], gain_pit_fx); + /* Add Gaussian contribution*/ + Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR - 1]); + Ltmp2 = L_shl(Ltmp2, add(5, Q_xn)); + Ltmp = L_add(Ltmp, Ltmp2); + hLPDmem->mem_w0 = sub(xn_fx[L_SUBFR - 1], round_fx(L_shl(Ltmp, 1))); + move16(); + BASOP_SATURATE_WARNING_OFF; + hLPDmem->mem_w0 = shr(hLPDmem->mem_w0, shift); /*Qnew-1*/ + BASOP_SATURATE_WARNING_ON; + + /*-------------------------------------------------------* + * - Find the total excitation. * + *-------------------------------------------------------*/ + + tmp2 = shr(L_SUBFR, 1); + FOR(j = 0; j < 2; j++) + { + FOR(i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) + { + /* code in Q9, gain_pit in Q14; exc Q_new */ + Ltmp = Mpy_32_16_1(gain_code2, code2[i]); + Ltmp = L_shl(Ltmp, Q_new_p5); + Ltmp = L_mac(Ltmp, gain_pit_fx, exc_fx[i + i_subfr]); + BASOP_SATURATE_WARNING_OFF + exc2[i] = round_fx(L_shl(Ltmp, 1)); + BASOP_SATURATE_WARNING_ON + + Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code_fx[i]); + Ltmp2 = L_shl(Ltmp2, Q_new_p5); + Ltmp = L_add(Ltmp, Ltmp2); + BASOP_SATURATE_WARNING_OFF + Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ + BASOP_SATURATE_WARNING_ON + exc_fx[i + i_subfr] = round_fx(Ltmp); + } + tmp2 = L_SUBFR; + move16(); + } + } *tmp_noise_fx = extract_h(norm_gain_code_fx); - voice_factors_fx[i_subfr/L_SUBFR] = 0; move16(); @@ -102,7 +226,7 @@ void encod_unvoiced_fx( * Synthesize speech to update mem_syn[]. * Update A(z) filters *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + Syn_filt_s(1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); p_Aw_fx += (M+1); p_Aq_fx += (M+1); @@ -110,9 +234,9 @@ void encod_unvoiced_fx( } /* SC-VBR */ - st_fx->prev_ppp_gain_pit_fx = gain_pit_fx; + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; move16(); - st_fx->prev_tilt_code_fx = mem->tilt_code; + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; move16(); return; diff --git a/lib_enc/encoder.c b/lib_enc/encoder.c index 5b47e3b..dbd714a 100644 --- a/lib_enc/encoder.c +++ b/lib_enc/encoder.c @@ -83,15 +83,19 @@ int main( int argc, char** argv ) Opt_RF_ON_loc = st_fx->Opt_RF_ON; rf_fec_offset_loc = st_fx->rf_fec_offset; - st_fx->ind_list_fx = ind_list; init_encoder_fx( st_fx ); - + st_fx->hBstr->ind_list_fx = ind_list; + reset_indices_enc_fx(st_fx->hBstr); + /*------------------------------------------------------------------------------------------* * Compensate for encoder delay (bitstream aligned with input signal) * Compensate for the rest of codec delay (local synthesis aligned with decoded signal and original signal) *------------------------------------------------------------------------------------------*/ - - enc_delay = NS2SA(st_fx->input_Fs_fx, get_delay_fx(ENC, st_fx->input_Fs_fx)); +#ifdef SPLIT_REND_WITH_HEAD_ROT + enc_delay = NS2SA(st_fx->input_Fs_fx, get_delay_fx(ENC, st_fx->input_Fs_fx, MONO_FORMAT, NULL, AUDIO_CONFIG_MONO)); +#else + enc_delay = NS2SA(st_fx->input_Fs_fx, get_delay_fx(ENC, st_fx->input_Fs_fx, MONO_FORMAT, NULL)); +#endif if ( noDelayCmp == 0 ) { @@ -203,17 +207,17 @@ int main( int argc, char** argv ) { SUB_WMOPS_INIT("evs_enc"); /* EVS encoder*/ - evs_enc_fx( st_fx, data, n_samples); + evs_enc_fx( st_fx, data, st_fx->mem_hp20_in_fx, n_samples); END_SUB_WMOPS; } /* pack indices into serialized payload format */ if( st_fx->bitstreamformat == MIME ) { - indices_to_serial(st_fx, pFrame, &pFrame_size); + indices_to_serial(st_fx, st_fx->hBstr, pFrame, &pFrame_size); } /* write indices into bitstream file */ - write_indices_fx( st_fx, f_stream, pFrame, pFrame_size ); + write_indices_fx(st_fx, st_fx->hBstr, f_stream, pFrame, pFrame_size ); END_SUB_WMOPS; /* update WMPOS counting (end of frame) */ diff --git a/lib_enc/energy.c b/lib_enc/energy.c index c710e77..23f23bd 100644 --- a/lib_enc/energy.c +++ b/lib_enc/energy.c @@ -3,30 +3,30 @@ ====================================================================================*/ -#include -#include -#include - - +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "rom_enc_fx.h" #include "vad_basop.h" #include "prot_fx.h" - +/*-------------------------------------------------------------------* + * est_energy() + * + * + *-------------------------------------------------------------------*/ void est_energy( - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word32 *frame_sb_energy, /*(o) energy of sub-band divided non-uniformly*/ - Word32 *frame_energy2_p, /*(o) frame energy 2*/ - Word32 *HB_Power_p, /*(o) high frequency energy*/ - Word32 *frame_energy_p, /*(o) frame energy 1*/ - Word16 *sb_power_Q, /*(o) the scaling of sb_power*/ - Word16 *frame_energy2_Q, /*(o) the scaling of frame_energy*/ - Word16 *HB_Power_Q, /*(o) the scaling of HB_Power*/ - Word16 *frame_energy_Q, /*(o) the Scaling of frame_energy*/ - Word16 *frame_sb_energy_scale, /*(o) the Scaling of frame_sb_energy[]*/ - Word32 bandwidth /*(i) band width*/ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ + Word32 *frame_energy2_p, /* o : frame energy 2*/ + Word32 *HB_Power_p, /* o : high frequency energy*/ + Word32 *frame_energy_p, /* o : frame energy 1*/ + Word16 *sb_power_Q, /* o : the scaling of sb_power*/ + Word16 *frame_energy2_Q, /* o : the scaling of frame_energy*/ + Word16 *HB_Power_Q, /* o : the scaling of HB_Power*/ + Word16 *frame_energy_Q, /* o : the Scaling of frame_energy*/ + Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ + const Word32 bandwidth /* i : band width*/ ) { Word32 i,j; @@ -40,7 +40,7 @@ void est_energy( const Word16 *Nregion_index; Word32 *sb_power = enerBuffer; Word32 Ltmp32 = 0; - + move32(); SNR_sb_num = SNR_SUB_BAND_NUM[bandwidth-CLDFBVAD_NB_ID]; move16(); Nregion_index = REGION_INDEX[bandwidth-CLDFBVAD_NB_ID]; @@ -125,10 +125,19 @@ void est_energy( *frame_sb_energy_scale = *sb_power_Q; move16(); + return; } - -static -void NormEnergyWord32(Word32 *vector, Word32 len, Word16 *pi_scale, Word16* normscale) +/*-------------------------------------------------------------------* + * NormEnergyWord32() + * + * + *-------------------------------------------------------------------*/ +static void NormEnergyWord32( + Word32 *vector, + const Word32 len, + const Word16 *pi_scale, + Word16 *normscale +) { Word16 minVal; Word16 i; @@ -151,6 +160,11 @@ void NormEnergyWord32(Word32 *vector, Word32 len, Word16 *pi_scale, Word16* norm move16(); } +/*-------------------------------------------------------------------* + * update_sb_bg_energy() + * + * + *-------------------------------------------------------------------*/ static void update_sb_bg_energy( Word32 *sb_bg_energy, Word16 *tbg_energy_count, @@ -179,14 +193,19 @@ static void update_sb_bg_energy( } } - -void background_update(T_CldfbVadState *st, /*(io) vad state*/ - Word16 scale, /*(i) the scaling of frame energy*/ - Word32 frame_energy, /*(i) current frame energy*/ - Word32 update_flag, /*(i) update flag*/ - Word16 music_backgound_f /*(i) background music flag*/ - ,Word32 snr - ) +/*-------------------------------------------------------------------* + * update_sb_bg_energy() + * + * + *-------------------------------------------------------------------*/ +void background_update( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy*/ + Word32 frame_energy, /* i : current frame energy*/ + Word32 update_flag, /* i : update flag*/ + Word16 music_backgound_f, /* i : background music flag*/ + Word32 snr +) { Word32 tmp; Word16 i, tmpQ, cmp_lt_frame, cmp_pre_frame; @@ -200,9 +219,9 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ T_VAD_EXP exp_frame_energy,CONST32fix; T_VAD_EXP t_bg_energy_sum; Word16 p_scale_sb_energy[12] ; - Word16 *f_tonality_rate = st->f_tonality_rate; - Word16 *ltd_stable_rate = st->ltd_stable_rate; - Word32 bandwith = st->bw_index; + Word16 *f_tonality_rate = hVAD_CLDFB->f_tonality_rate; + Word16 *ltd_stable_rate = hVAD_CLDFB->ltd_stable_rate; + Word32 bandwith = hVAD_CLDFB->bw_index; Word16 cmp_tmp; T_VAD_EXP exp_frame_energy_amendment; @@ -219,17 +238,17 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ move32(); SNR_sb_num = SNR_SUB_BAND_NUM[bandwith - CLDFBVAD_NB_ID]; move16(); - scale_sb_energy = st->sb_bg_energy_scale; + scale_sb_energy = hVAD_CLDFB->sb_bg_energy_scale; move16(); - sb_bg_energy = st->sb_bg_energy; + sb_bg_energy = hVAD_CLDFB->sb_bg_energy; move32(); - frame_sb_energy = st->frame_sb_energy; + frame_sb_energy = hVAD_CLDFB->frame_sb_energy; move32(); - t_bg_energy = st->t_bg_energy; + t_bg_energy = hVAD_CLDFB->t_bg_energy; move32(); - t_bg_energy_sum = st->t_bg_energy_sum; + t_bg_energy_sum = hVAD_CLDFB->t_bg_energy_sum; move32(); normscal = norm_l(frame_energy); exp_frame_energy.s16Exp = add(scale,normscal); @@ -248,11 +267,11 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ test(); test(); test(); - IF( (LT_16(st->frameloop, 60))&&(GT_16(st->frameloop,5))&&(LT_16(f_tonality_rate[0],9174/* 0.56 Q14 */)) + IF( (LT_16(hVAD_CLDFB->frameloop, 60)) && (GT_16(hVAD_CLDFB->frameloop,5)) && (LT_16(f_tonality_rate[0],9174/* 0.56 Q14 */)) && (LT_16(f_tonality_rate[1],8192/* 0.5 Q14 */)) && (LT_16(ltd_stable_rate[1],1966/* 0.06 Q15 */)) && LT_32(snr, 83886080) ) { - IF( LT_16(st->frameloop, 50) ) + IF( LT_16(hVAD_CLDFB->frameloop, 50) ) { exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); exp_frame_energy_amendment.s16Exp = q_divout; @@ -262,42 +281,42 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ { t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); } - update_sb_bg_energy(sb_bg_energy, &st->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, + update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, 29490/* 0.90 Q15 */, 3, 5242/* 0.01 Q19 */);//5243 } test(); test(); - IF((EQ_32(update_flag,1))&&(GT_16(st->frameloop,2))&&music_backgound_f==0) + IF((EQ_32(update_flag,1)) && (GT_16(hVAD_CLDFB->frameloop,2)) && music_backgound_f==0) { - IF(LT_16(st->bg_update_count, 16)) + IF(LT_16(hVAD_CLDFB->bg_update_count, 16)) { - IF( LT_16(st->frameloop, 50) ) + IF( LT_16(hVAD_CLDFB->frameloop, 50) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); - exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + exp_frame_energy_amendment.s16Exp = q_divout; + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); } ELSE { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); } - update_sb_bg_energy(sb_bg_energy, &st->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, + update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); - st->bg_update_count = add(st->bg_update_count, 1); + hVAD_CLDFB->bg_update_count = add(hVAD_CLDFB->bg_update_count, 1); } ELSE { - cmp_lt_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - cmp_pre_frame = VAD_L_CMP(MUL_F(st->frame_energy_smooth, 24576), sub(st->frame_energy_smooth_scale, 5), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - cmp_tmp = VAD_L_CMP(MUL_F(t_bg_energy, 24576), sub(st->scale_t_bg_energy, 4), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); + cmp_lt_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); + cmp_pre_frame = VAD_L_CMP(MUL_F(hVAD_CLDFB->frame_energy_smooth, 24576), sub(hVAD_CLDFB->frame_energy_smooth_scale, 5), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); + cmp_tmp = VAD_L_CMP(MUL_F(t_bg_energy, 24576), sub(hVAD_CLDFB->scale_t_bg_energy, 4), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); test(); IF( (cmp_lt_frame < 0) && (cmp_pre_frame < 0) ) { - tmpQ = add(9, st->frame_sb_energy_scale); + tmpQ = add(9, hVAD_CLDFB->frame_sb_energy_scale); FOR(i=0; iframeloop, 50) ) - { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); - exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); - } - ELSE - { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); - } - update_sb_bg_energy(sb_bg_energy, &st->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, + IF( LT_16(hVAD_CLDFB->frameloop, 50) ) + { + exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + exp_frame_energy_amendment.s16Exp = q_divout; + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + } + ELSE + { + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + } + update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); } ELSE { - cmp_pre_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); + cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); IF(cmp_pre_frame>0) { - IF( LT_16(st->frameloop, 50) ) + IF( LT_16(hVAD_CLDFB->frameloop, 50) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); - exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + exp_frame_energy_amendment.s16Exp = q_divout; + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); } ELSE { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); } - update_sb_bg_energy(sb_bg_energy, &st->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, - 31129/* 0.95 Q15 */, 4, 26214/* 0.05 Q19 */); + update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, + 31129/* 0.95 Q15 */, 4, 26214/* 0.05 Q19 */); } ELSE { - IF( LT_16(st->frameloop, 50) ) + IF( LT_16(hVAD_CLDFB->frameloop, 50) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); - exp_frame_energy_amendment.s16Exp = q_divout; - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div(exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout); + exp_frame_energy_amendment.s16Exp = q_divout; + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy_amendment); } ELSE { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); } - update_sb_bg_energy(sb_bg_energy, &st->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, + update_sb_bg_energy(sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); } @@ -363,13 +382,13 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ } ELSE { - cmp_pre_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 32000), sub(exp_frame_energy.s16Exp, 9)); - cmp_lt_frame = VAD_L_CMP(sb_bg_energy[0], scale_sb_energy, MUL_F(frame_sb_energy[0], 20480), sub(st->frame_sb_energy_scale, 4)); + cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 32000), sub(exp_frame_energy.s16Exp, 9)); + cmp_lt_frame = VAD_L_CMP(sb_bg_energy[0], scale_sb_energy, MUL_F(frame_sb_energy[0], 20480), sub(hVAD_CLDFB->frame_sb_energy_scale, 4)); test(); IF( (cmp_pre_frame > 0) && (cmp_lt_frame > 0) ) { - tmpQ = add(3, st->frame_sb_energy_scale); + tmpQ = add(3, hVAD_CLDFB->frame_sb_energy_scale); FOR(i=0; iscale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 20480), sub(exp_frame_energy.s16Exp, 4)); + cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 20480), sub(exp_frame_energy.s16Exp, 4)); IF( cmp_pre_frame > 0 ) { - tmpQ = add(9, st->frame_sb_energy_scale); + tmpQ = add(9, hVAD_CLDFB->frame_sb_energy_scale); FOR(i=0; itbg_energy_count); + tmp = L_mult0(160, (Word16)hVAD_CLDFB->tbg_energy_count); cmp_pre_frame = VAD_L_CMP(t_bg_energy_sum.s32Mantissa, t_bg_energy_sum.s16Exp, tmp, 0); IF(cmp_pre_frame > 0) { @@ -405,12 +424,12 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ move16(); } NormEnergyWord32(sb_bg_energy, SNR_sb_num, p_scale_sb_energy, &scale_sb_energy); - cmp_pre_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, 1, 0); + cmp_pre_frame = VAD_L_CMP(t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, 1, 0); test(); test(); test(); - IF( (EQ_16(music_backgound_f, 1))&&(LT_32(st->lt_snr_org,107374179/* 3.2 Q25 */)) + IF( (EQ_16(music_backgound_f, 1))&&(LT_32(hVAD_CLDFB->lt_snr_org,107374179/* 3.2 Q25 */)) && (cmp_pre_frame > 0) && update_flag == 0) { tmp = L_shr(2147/* 0.000001 Q31 */, sub(31, scale_sb_energy)); @@ -423,7 +442,7 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ IF(EQ_16(music_backgound_f,1)) { - cmp_pre_frame = VAD_L_CMP(exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp, MUL_F(t_bg_energy, 5000), sub(st->scale_t_bg_energy, 15)); + cmp_pre_frame = VAD_L_CMP(exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp, MUL_F(t_bg_energy, 5000), sub(hVAD_CLDFB->scale_t_bg_energy, 15)); IF(cmp_pre_frame < 0) { tmp = L_shr(2147/* 0.000001 Q31 */, sub(31, scale_sb_energy)); @@ -435,23 +454,24 @@ void background_update(T_CldfbVadState *st, /*(io) vad state*/ } } - IF( (EQ_32(st->tbg_energy_count, 64))) + IF( (EQ_32(hVAD_CLDFB->tbg_energy_count, 64))) { - st->tbg_energy_count = 48; + hVAD_CLDFB->tbg_energy_count = 48; move16(); t_bg_energy_sum.s32Mantissa = MUL_F(t_bg_energy_sum.s32Mantissa, 24575/* 0.75 Q15 */); } - t_bg_energy = VAD_L_div(t_bg_energy_sum.s32Mantissa, st->tbg_energy_count, t_bg_energy_sum.s16Exp, 0, &q_divout); - st->scale_t_bg_energy = q_divout; + t_bg_energy = VAD_L_div(t_bg_energy_sum.s32Mantissa, hVAD_CLDFB->tbg_energy_count, t_bg_energy_sum.s16Exp, 0, &q_divout); + hVAD_CLDFB->scale_t_bg_energy = q_divout; move16(); - st->t_bg_energy = t_bg_energy; + hVAD_CLDFB->t_bg_energy = t_bg_energy; move32(); - st->sb_bg_energy_scale = scale_sb_energy; + hVAD_CLDFB->sb_bg_energy_scale = scale_sb_energy; move16(); - st->t_bg_energy_sum = t_bg_energy_sum; + hVAD_CLDFB->t_bg_energy_sum = t_bg_energy_sum; move16(); move32(); + return; } diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index 48c9048..43c5189 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Local constantes @@ -47,14 +46,13 @@ /* _ None */ /*=======================================================================*/ -Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ - const Word16 coder_type, /* i : coding type */ +Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 *dct_res, /* i : DCT of residual */ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ + Word16 *pitch_buf, /* i/o: Pitch per subframe */ + const Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *hangover, /* i : hangover for the time contribution switching */ Word16 Qnew ) { @@ -77,6 +75,9 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si Word16 exp_norm; Word16 norm; Word16 val_thrs; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; if( EQ_16(st_fx->L_frame_fx,L_FRAME16k)) { @@ -87,11 +88,14 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si minimum_fx( pitch_buf, nb_subfr, &low_pit); exp1 = norm_s(low_pit); tmp = shl(low_pit,exp1); + tmp_dec = 12800; move16(); + if (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) { - /*F1st_harm = 12800.0f/low_pit;*/ - tmp = div_s(12800,tmp); /*15-6-exp1(->9-exp1)*/ - F1st_harm = shr_r(tmp,sub(5,exp1)); /*Q4*/ + tmp_dec = 16000; move16(); } + /*F1st_harm = (12800.0f|160000.f)/low_pit;*/ + tmp = div_s(tmp_dec,tmp); /*15-6-exp1(->9-exp1)*/ + F1st_harm = shr_r(tmp,sub(5,exp1)); /*Q4*/ /*F8th_harm = 8.0f*F1st_harm;*/ F8th_harm = extract_l(L_shr_r(L_mult0(F1st_harm,8),2)); /*Q2*/ @@ -165,7 +169,13 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si move16(); av_corr = round_fx(L_shl(L_mult0(av_corr,6400),16-12)); /*Q14*Q0-12=Q2*/ - if( LT_32(st_fx->core_brate_fx,ACELP_9k60)) + if (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + /*av_corr *= 1.25f;*/ + av_corr = add(av_corr, shr(av_corr, 2)); + } + test(); + if (GE_16(st_fx->GSC_IVAS_mode, 1)|| LT_32(st_fx->core_brate_fx, ACELP_9k60)) { av_corr = shl(av_corr,1); /*Q2 Correlation really poor at low rate, time domain still valide*/ } @@ -192,6 +202,10 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si } WHILE( GE_16(F8th_harm,mfreq_loc_Q2fx[last_pit_band])); } + if (GE_16(st_fx->GSC_IVAS_mode, 1)) + { + last_pit_band = s_max(last_pit_band, 7); + } test(); test(); test(); @@ -217,10 +231,10 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si test(); test(); test(); - IF( (st_fx->mem_last_pit_band_fx > 0 && GT_16(st_fx->old_corr_fx,16384)&>_16(st_fx->mold_corr_fx,16384)&&GE_16(st_fx->lt_gpitch_fx,19661)/*1.5f*GPIT_THR*/) + IF( (hGSCEnc->mem_last_pit_band_fx > 0 && GT_16(st_fx->old_corr_fx,16384)&>_16(hSpMusClas->mold_corr_fx,16384)&&GE_16(hGSCEnc->lt_gpitch_fx,19661)/*1.5f*GPIT_THR*/) || (GT_16(last_pit_band,6) ) - || (GE_16(last_pit_band,4) && GE_16(st_fx->lt_gpitch_fx,19661) /*1.5f*GPIT_THR*/ && GT_16(st_fx->old_corr_fx,22938) ) - || (GT_16(last_pit_band,BAND1k2) && GT_16(st_fx->mold_corr_fx,26214) && GE_16(st_fx->lt_gpitch_fx,13107) /*GPIT_THR*/) + || (GE_16(last_pit_band,4) && GE_16(hGSCEnc->lt_gpitch_fx,19661) /*1.5f*GPIT_THR*/ && GT_16(st_fx->old_corr_fx,22938) ) + || (GT_16(last_pit_band,BAND1k2) && GT_16(hSpMusClas->mold_corr_fx,26214) && GE_16(hGSCEnc->lt_gpitch_fx,13107) /*GPIT_THR*/) ) { tmp_dec = 1; @@ -236,7 +250,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si test(); test(); test(); - IF ( (st_fx->mem_last_pit_band_fx == 0 && EQ_16(tmp_dec,1))||(st_fx->mem_last_pit_band_fx>0&&tmp_dec==0)) + IF ( (hGSCEnc->mem_last_pit_band_fx == 0 && EQ_16(tmp_dec,1))||(hGSCEnc->mem_last_pit_band_fx>0&&tmp_dec==0)) { IF( *hangover == 0 ) { @@ -249,7 +263,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si { time_flg = 0; move16(); - if( st_fx->mem_last_pit_band_fx > 0 ) + if(hGSCEnc->mem_last_pit_band_fx > 0 ) { time_flg = 1; move16(); @@ -271,17 +285,17 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si move16(); } - /* Decicison on final lenght of time contribution */ + /* Decicison on final length of time contribution */ pit_contr_idx = 0; move16(); test(); test(); - IF( EQ_16(time_flg,1)||NE_16(coder_type,INACTIVE)||st_fx->GSC_noisy_speech_fx) + IF( EQ_16(time_flg,1) || NE_16(st_fx->coder_type,INACTIVE) || st_fx->GSC_noisy_speech_fx) { test(); test(); /*if(st_fx->core_brate_fx core_brate_fx,ACELP_9k60)&<_16(low_pit,4096)) + IF(LT_32(st_fx->core_brate_fx,ACELP_9k60) && LT_16(low_pit,4096)) { last_pit_band = add(9 , BAND1k2); if(EQ_16(st_fx->bwidth_fx,NB)) @@ -289,7 +303,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si last_pit_band = add(7,BAND1k2); } } - ELSE IF(LT_32(st_fx->core_brate_fx,ACELP_9k60)&<_16(low_pit,8192)) + ELSE IF(LT_32(st_fx->core_brate_fx,ACELP_9k60) && LT_16(low_pit,8192)) { last_pit_band = add(5 , BAND1k2); } @@ -322,7 +336,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si move16(); } test(); - IF((EQ_32(st_fx->core_brate_fx,ACELP_8k00))&&(NE_16(st_fx->bwidth_fx,NB))) + IF((EQ_32(st_fx->core_brate_fx,ACELP_8k00)) && (NE_16(st_fx->bwidth_fx,NB))) { move16(); /*ptr init*/ FOR (i=0; i < max_len; i++) @@ -344,7 +358,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si move16(); } } - st_fx->mem_last_pit_band_fx = last_pit_band; + hGSCEnc->mem_last_pit_band_fx = last_pit_band; move16(); pit_contr_idx = sub(last_pit_band,BAND1k2); } @@ -359,29 +373,35 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si move16(); pit_contr_idx = 0; move16(); - st_fx->mem_last_pit_band_fx = 0; + hGSCEnc->mem_last_pit_band_fx = 0; move16(); - { - set16_fx( pitch_buf, shl(L_SUBFR,6), NB_SUBFR ); - } + set16_fx( pitch_buf, shl(L_SUBFR,6), NB_SUBFR16k ); /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ FOR ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) { - IF ( st_fx->ind_list_fx[i].nb_bits != -1 ) +#ifndef IVAS_CODE_BITSTREAM + IF (hBstr->ind_list_fx[i].nb_bits != -1 ) { - st_fx->nb_bits_tot_fx = sub(st_fx->nb_bits_tot_fx,st_fx->ind_list_fx[i].nb_bits); - st_fx->ind_list_fx[i].nb_bits = -1; + hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[i].nb_bits); + hBstr->ind_list_fx[i].nb_bits = -1; move16(); } +#else + delete_indice(hBstr, i); +#endif } - IF ( st_fx->ind_list_fx[IND_ES_PRED].nb_bits != -1 ) +#ifndef IVAS_CODE_BITSTREAM + IF (hBstr->ind_list_fx[IND_ES_PRED].nb_bits != -1 ) { - st_fx->nb_bits_tot_fx = sub(st_fx->nb_bits_tot_fx,st_fx->ind_list_fx[IND_ES_PRED].nb_bits); - st_fx->ind_list_fx[IND_ES_PRED].nb_bits = -1; + hBstr->nb_bits_tot_fx = sub(hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_ES_PRED].nb_bits); + hBstr->ind_list_fx[IND_ES_PRED].nb_bits = -1; move16(); } +#else + delete_indice(hBstr, i); +#endif } IF( LT_32(st_fx->core_brate_fx,CFREQ_BITRATE)) { @@ -393,19 +413,19 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is si move16(); } - IF( EQ_16(coder_type,INACTIVE)) + IF( EQ_16(st_fx->coder_type,INACTIVE)) { - push_indice_fx( st_fx, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); + push_indice_fx(hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); } } ELSE { - push_indice_fx( st_fx, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); + push_indice_fx(hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); } } ELSE { - push_indice_fx( st_fx, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); + push_indice_fx(hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); } return last_pit_bin; diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index a6b7016..7f15788 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -2,42 +2,72 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include #include "options.h" /* Compilation switches */ #include "prot_fx.h" #include "cnst_fx.h" /* Common constants */ -#include "stl.h" /* Debug prototypes */ #include "rom_com_fx.h" /* Common constants */ +/*-------------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------------*/ + static void initFrameHeader_loc( Encoder_State_fx *st ); static void writeFrameHeader_loc( Encoder_State_fx *st ); -static void configure_core_coder_loc( Encoder_State_fx *st, Word16 *coder_type,const Word16 localVAD); +static void configure_core_coder_loc( Encoder_State_fx *st); +#ifdef MY_DEBUG +static void dbgwrite_indices(Encoder_State_fx* st) +{ + Word16 i; + FILE* outputFile = NULL; + static Word32 loc_frame = 1; + if (outputFile == NULL) { + if (loc_frame == 1) + { + outputFile = fopen("indice_test.txt", "w+"); + fprintf(outputFile, "Number\tvalue\tbits\n"); + printf("creating debugging file for writing indices.\n"); + } + else + { + outputFile = fopen("indice_test.txt", "a+"); + } + } + if (outputFile != NULL) { + fprintf(outputFile, "~~~~~~~~~~~frame: %d @ %d kbps\n", loc_frame, st->last_total_brate_fx); + for (i = 0; i < MAX_NUM_INDICES - 1; i++) + { + if (st->hBstr->ind_list_fx[i].nb_bits > -1) + { + fprintf(outputFile, "%d\t%d\t%d\n", i, st->hBstr->ind_list_fx[i].value, st->hBstr->ind_list_fx[i].nb_bits); + } + } + loc_frame++; + fclose(outputFile); + } +} +#endif /*-------------------------------------------------------------------* * evs_enc() * * Principal encoder routine *-------------------------------------------------------------------*/ -void evs_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ +ivas_error evs_enc_fx( + Encoder_State_fx *st, /* i/o: encoder state structure */ const Word16 *data, /* i : input signal */ + Word32 * mem_hp20_in_fx, /* i/o: hp20 filter memory */ const Word16 n_samples /* i : number of input samples */ ) { Word16 i, input_frame, delay; Word16 old_inp_12k8[L_INP_12k8], *inp = 0; /* buffer of input signal @ 12k8 */ Word16 old_inp_16k[L_INP]; /* buffer of input signal @ 16kHz */ - Word16 sp_aud_decision1; /* 1st stage speech/music classification */ - Word16 sp_aud_decision2; /* 2nd stage speech/music classification */ Word32 fr_bands[2*NB_BANDS]; /* energy in frequency bands */ - Word16 vad_flag; - Word16 localVAD; Word16 Etot; /* total energy; correlation shift */ Word32 ener; /* residual energy from Levinson-Durbin */ - Word16 pitch[3]; /* open-loop pitch values for quantization */ - Word16 voicing[3]; /* OL maximum normalized correlation */ Word16 A[NB_SUBFR16k*(M+1)]; /* A(z) unquantized for subframes */ Word16 Aw[NB_SUBFR16k*(M+1)]; /* weighted A(z) unquantized for subframes */ Word16 epsP_h[M+1]; /* LP prediction errors */ @@ -45,12 +75,10 @@ void evs_enc_fx( Word32 epsP[M+1]; /* LP prediction errors */ Word16 lsp_new[M]; /* LSPs at the end of the frame */ Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ - Word16 coder_type; /* coder type */ - Word16 sharpFlag; /* formant sharpening flag */ Word16 vad_hover_flag; Word16 hq_core_type; /* HQ core type (HQ, or LR-MDCT) */ - Word16 attack_flag; /* flag signalling attack encoded by the AC mode (GSC) */ + Word16 attack_flag; /* attack flag (GSC or TC) */ Word16 new_inp_resamp16k[L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ Word16 old_syn_12k8_16k[L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ Word16 shb_speech[L_FRAME16k]; @@ -60,7 +88,7 @@ void evs_enc_fx( Word16 voice_factors[NB_SUBFR16k]; Word16 fb_exc[L_FRAME16k]; Word16 Voicing_flag; - Word16 pitch_buf[NB_SUBFR16k]; + Word16 pitch_buf[NB_SUBFR16k] = { 0 }; Word16 unbits; Word16 padBits; @@ -73,6 +101,22 @@ void evs_enc_fx( Word32 L_tmp; UWord16 lsb; Word16 tmp; +#ifndef FIX_I4_OL_PITCH + Word16 pitch_orig[3]; /* original open-loop pitch values that might be altered in core_acelp_tcx20_switching() within MODE2 */ +#endif + ivas_error error; + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + //NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; + //VAD_HANDLE hVAD = st->hVAD; + //DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + LPD_state_HANDLE hLPDmem = st->hLPDmem; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + BSTR_ENC_HANDLE hBstr = st->hBstr; + RF_ENC_HANDLE hRF = st->hRF; + + error = IVAS_ERR_OK; + Q_shb_spch = 0; move16(); /* to avoid compiler warnings */ @@ -103,7 +147,7 @@ void evs_enc_fx( st->bits_frame_core = 0; move16(); /* For getting bit consumption in core coder */ - st->lp_cng_mode2 = 0; + hTdCngEnc->lp_cng_mode2 = 0; move16(); st->mdct_sw_enable = 0; move16(); @@ -114,6 +158,12 @@ void evs_enc_fx( st->rate_switching_reset = 0; move16(); + st->idchan = 0; + move16(); + st->flag_ACELP16k = set_ACELP_flag(EVS_MONO, -1, st->total_brate_fx, 0, 0, -1, -1); + move16(); + + /*----------------------------------------------------------------* * set input samples buffer *----------------------------------------------------------------*/ @@ -137,7 +187,7 @@ void evs_enc_fx( * HP filtering *----------------------------------------------------------------*/ - hp20( st->input, 1, input_frame, st->mem_hp20_in_fx, st->input_Fs_fx ); + hp20( st->input, 1, input_frame, mem_hp20_in_fx, st->input_Fs_fx ); /*----------------------------------------------------------------* * Updates in case of AMR-WB IO mode -> EVS primary mode switching @@ -146,7 +196,19 @@ void evs_enc_fx( IF( EQ_16(st->last_core_fx, AMR_WB_CORE)) { updt_IO_switch_enc_fx( st, input_frame ); - set16_fx(st->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k); + set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k); +#if defined IVAS_CODE +PMT("find scaling factor for prev_enr_EnvSHBres, prev_pow_exc16kWhtnd and prev_mix_factor ") + set16_fx(st->hBWE_TD->old_speech_shb, 0, L_LOOK_16k + L_SUBFR16k); + set16_fx(st->hBWE_TD->mem_shb_res, 0, MAX_LEN_MA_FILTER); + set16_fx(st->hBWE_TD->old_EnvSHBres, 0, L_FRAME4k); + st->hBWE_TD->old_mean_EnvSHBres = 0; + st->hBWE_TD->prev_enr_EnvSHBres = 1.0f; + st->hBWE_TD->prev_shb_env_tilt = 0; + st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; + st->hBWE_TD->prev_mix_factor = 1.0f; + st->hBWE_TD->prev_Env_error = 0; +#endif cldfb_reset_memory( st->cldfbAna_Fx ); cldfb_reset_memory( st->cldfbSyn_Fx ); } @@ -154,15 +216,15 @@ void evs_enc_fx( /*---------------------------------------------------------------------* * Pre-processing *---------------------------------------------------------------------*/ - - pre_proc_fx( st, input_frame, st->input, old_inp_12k8, old_inp_16k, &inp, &sp_aud_decision1, - &sp_aud_decision2, fr_bands, &vad_flag, &localVAD, &Etot, &ener, pitch, voicing, - A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &coder_type, &sharpFlag, &vad_hover_flag, - &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, st->LPDmem.old_exc, - &hq_core_type, - &Q_new, &shift, Q_r ); - - st->sharpFlag = sharpFlag; +#ifdef FIX_I4_OL_PITCH + pre_proc(st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &hq_core_type); +#else + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, + pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, + &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, + &hq_core_type, &Q_new, &shift, Q_r ); +#endif + //st->sharpFlag = sharpFlag; IF (EQ_16(st->mdct_sw,MODE2)) { @@ -203,7 +265,7 @@ void evs_enc_fx( move16(); } - st->sr_core = L_mult0(50,st->L_frame_fx); + st->sr_core = L_mult0(FRAMES_PER_SEC,st->L_frame_fx); st->core_brate_fx = st->total_brate_fx; move32(); @@ -215,7 +277,7 @@ void evs_enc_fx( test(); IF( (EQ_16(st->bwidth_fx,SWB)||EQ_16(st->bwidth_fx,WB))&&LE_32(st->total_brate_fx,LRMDCT_CROSSOVER_POINT)) { - /* note that FB (bit-rate >= 24400bps) is always coded with NORMAL_HQ_CORE */ + /* note that FB (bitrate >= 24400bps) is always coded with NORMAL_HQ_CORE */ hq_core_type = LOW_RATE_HQ_CORE; move16(); } @@ -232,13 +294,13 @@ void evs_enc_fx( * Write signalling info into the bitstream *---------------------------------------------------------------------*/ - signalling_enc_fx( st, coder_type, sharpFlag ); + signalling_enc_fx( st); /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - core_switching_pre_enc_fx( st,&(st->LPDmem), old_inp_12k8, old_inp_16k); + core_switching_pre_enc_fx( st, old_inp_12k8, old_inp_16k, 0, 0); /*---------------------------------------------------------------------* * ACELP core encoding @@ -246,25 +308,32 @@ void evs_enc_fx( IF( EQ_16(st->core_fx,ACELP_CORE)) { - acelp_core_enc_fx( st, &(st->LPDmem), inp, vad_flag, ener, - pitch, voicing, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, coder_type, sharpFlag, vad_hover_flag, - attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, Q_new, shift ); + acelp_core_enc_fx( st, inp, ener, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, vad_hover_flag, + attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, Q_new, shift +#ifdef ADD_LRTD + ,NULL, NULL +#endif + ); } - /*---------------------------------------------------------------------* * HQ core encoding *---------------------------------------------------------------------*/ IF( EQ_16(st->core_fx,HQ_CORE)) { - hq_core_enc_fx( st, st->input - delay, input_frame, hq_core_type, Voicing_flag); + hq_core_enc_fx( st, st->input - delay, input_frame, hq_core_type, Voicing_flag, vad_hover_flag); } /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - core_switching_post_enc_fx( st, old_inp_12k8, old_inp_16k, pitch, voicing, - A, shift, Q_new, st->Q_syn2, &Q_synth ); + core_switching_post_enc_fx( st, old_inp_12k8, old_inp_16k, A, shift, Q_new, st->Q_syn2, &Q_synth ); +#ifndef FIX_I4_OL_PITCH + IF (EQ_16(st->core_fx, HQ_CORE)) + { + Copy(pitch_orig, st->pitch_fx, 3); /* original open-loop pitch values might be altered in core_acelp_tcx20_switching() */ + } +#endif } ELSE /* MODE2 */ { @@ -273,7 +342,7 @@ void evs_enc_fx( * Write Frame Header *----------------------------------------------------------------*/ - configure_core_coder_loc( st, &coder_type, localVAD ); + configure_core_coder_loc( st); IF (st->mdct_sw != MODE1) { @@ -285,9 +354,12 @@ void evs_enc_fx( *----------------------------------------------------------------*/ /* Call main encoding function */ - enc_acelp_tcx_main( old_inp_16k + L_INP_MEM, st, coder_type, pitch, voicing, Aw, lsp_new, lsp_mid, - st->hFdCngEnc_fx, bwe_exc_extended, voice_factors, pitch_buf, - vad_hover_flag, vad_flag, &Q_new, &shift ); + enc_acelp_tcx_main( old_inp_16k + L_INP_MEM, st, Aw, lsp_new, lsp_mid, + bwe_exc_extended, voice_factors, pitch_buf, + vad_hover_flag, &Q_new, &shift ); +#ifndef FIX_I4_OL_PITCH + Copy(pitch_orig, st->pitch_fx, 3); /* populate the original OL pitch values back */ +#endif /*---------------------------------------------------------------------* * Postprocessing for codec switching @@ -312,19 +384,34 @@ void evs_enc_fx( move16(); st->extl_brate_fx = SWB_TBE_1k6; move32(); + IF (LT_32(st->total_brate_fx, ACELP_13k20)) + { + st->extl_brate_fx = SWB_TBE_0k95; + move32(); + } + ELSE IF (GE_32(st->total_brate_fx, ACELP_24k40)) + { + st->extl_brate_fx = SWB_TBE_2k8; + move32(); + } BREAK; - case FB: st->extl_fx = FB_TBE; move16(); st->extl_brate_fx = FB_TBE_1k8; move32(); + + if (GE_32(st->total_brate_fx, ACELP_24k40)) + { + st->extl_brate_fx = FB_TBE_3k0; + move32(); + } BREAK; } } ELSE { - coder_type = -1; + st->coder_type = -1; move16(); st->extl_fx = IGF_BWE; move16(); @@ -353,18 +440,18 @@ void evs_enc_fx( { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) ) + get_tbe_bits(st->total_brate, st->bwidth, st->rf_mode )); */ tmp = add(get_tbe_bits_fx(st->total_brate_fx, st->bwidth_fx, st->rf_mode), sub(st->rf_target_bits_write, st->rf_mode)); - padBits = sub(sub(shl(shr(add(st->bits_frame,7),3),3), st->nb_bits_tot_fx), tmp); + padBits = sub(sub(shl(shr(add(st->bits_frame,7),3),3), hBstr->nb_bits_tot_fx), tmp); } ELSE { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) )); */ tmp = sub(st->rf_target_bits_write, st->rf_mode); - padBits = sub(shl(shr(add(st->bits_frame,7),3),3), add(st->nb_bits_tot_fx, tmp)); + padBits = sub(shl(shr(add(st->bits_frame,7),3),3), add(hBstr->nb_bits_tot_fx, tmp)); } FOR( i = 0; iextl_fx,WB_TBE)) { /* WB TBE encoder */ - wb_tbe_enc_fx( st, coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, voicing); + wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx); IF( EQ_16(st->codec_mode,MODE2)) { @@ -395,7 +482,7 @@ void evs_enc_fx( ELSE IF ( EQ_16(st->extl_fx, WB_BWE)) { /* WB BWE encoder */ - wb_bwe_enc_fx( st, new_inp_resamp16k, coder_type ); + wb_bwe_enc_fx( st, new_inp_resamp16k, st->coder_type ); } @@ -411,8 +498,18 @@ void evs_enc_fx( } ELSE IF( GE_32(st->input_Fs_fx,32000)) { - set16_fx( st->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); set16_fx( shb_speech, 0, L_FRAME16k ); +#if defined IVAS_CODE + set_f(st->hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); + set_f(st->hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); + st->hBWE_TD->old_mean_EnvSHBres = 0.0f; + st->hBWE_TD->prev_enr_EnvSHBres = 1.0f; + st->hBWE_TD->prev_shb_env_tilt = 0.0f; + st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; + st->hBWE_TD->prev_mix_factor = 1.0f; + st->hBWE_TD->prev_Env_error = 0.0f; +#endif } /* SWB TBE encoder */ @@ -427,7 +524,7 @@ void evs_enc_fx( test(); IF( NE_32(st->core_brate_fx,FRAME_NO_DATA)&&NE_32(st->core_brate_fx,SID_2k40)) { - swb_tbe_enc_fx( st, coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, voicing, pitch_buf ); + swb_tbe_enc_fx( st, st->coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); IF ( EQ_16(st->extl_fx,FB_TBE)) { @@ -439,23 +536,23 @@ void evs_enc_fx( { IF( EQ_16(st->tec_tfa, 1)) { - tecEnc_TBE_fx(&st->tecEnc.corrFlag, voicing, coder_type); + tecEnc_TBE_fx(&(st->hTECEnc->corrFlag), st->voicing_fx, st->coder_type); - IF( EQ_16(coder_type, INACTIVE)) + IF( EQ_16(st->coder_type, INACTIVE)) { st->tec_flag = 0; move16(); - st->tecEnc.corrFlag = 0; + st->hTECEnc->corrFlag = 0; move16(); } - st->tfa_flag = tfaEnc_TBE_fx( st->tfa_enr, st->last_core_fx, voicing, pitch_buf, shl(Q_shb_spch, 1)); - set_TEC_TFA_code_fx( st->tecEnc.corrFlag, &st->tec_flag, &st->tfa_flag ); + st->tfa_flag = tfaEnc_TBE_fx( st->tfa_enr, st->last_core_fx, st->voicing_fx, pitch_buf, shl(Q_shb_spch, 1)); + set_TEC_TFA_code_fx( st->hTECEnc->corrFlag, &st->tec_flag, &st->tfa_flag ); } ELSE { st->tec_flag = 0; move16(); - st->tecEnc.corrFlag = 0; + st->hTECEnc->corrFlag = 0; move16(); st->tfa_flag = 0; move16(); @@ -468,12 +565,12 @@ void evs_enc_fx( ELSE IF ( EQ_16(st->extl_fx,SWB_BWE)||EQ_16(st->extl_fx,FB_BWE)) { /* SWB BWE encoder */ - swb_bwe_enc_fx( st, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, shb_speech, coder_type, Q_shb_spch, sub(Q_new, 1) ); + swb_bwe_enc_fx( st, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, shb_speech, st->coder_type, Q_shb_spch, sub(Q_new, 1) ); } ELSE IF( EQ_16(st->extl_fx,SWB_BWE_HIGHRATE)||EQ_16(st->extl_fx,FB_BWE_HIGHRATE)) { /* SWB HR BWE encoder */ - swb_bwe_enc_hr_fx(st, st->input - delay, st->Q_syn2, input_frame, coder_type, unbits ); + swb_bwe_enc_hr_fx(st, st->input - delay, st->Q_syn2, input_frame, unbits ); } /*---------------------------------------------------------------------* @@ -487,146 +584,19 @@ void evs_enc_fx( } /*---------------------------------------------------------------------* - * Channel-aware mode - write signaling information into the bit-stream + * Channel-aware mode - write signaling information into the bitstream *---------------------------------------------------------------------*/ signalling_enc_rf( st ); - /*---------------------------------------------------------------------* - * Updates - MODE1 - *---------------------------------------------------------------------*/ - - st->last_sr_core = st->sr_core; - move16(); - st->last_codec_mode = st->codec_mode; - move16(); - st->last_L_frame_fx = st->L_frame_fx; - move16(); - st->last_core_fx = st->core_fx; - move16(); - - st->last_total_brate_fx = st->total_brate_fx; - move32(); - st->last_core_brate_fx = st->core_brate_fx; - move32(); - st->last_extl_fx = st->extl_fx; - move16(); - st->last_input_bwidth_fx = st->input_bwidth_fx; - move16(); - st->last_bwidth_fx = st->bwidth_fx; - move16(); - st->Etot_last_fx = Etot; - move16(); - st->last_coder_type_raw_fx = st->coder_type_raw_fx; - move16(); - - st->prev_Q_new = Q_new; - - if( GT_32(st->core_brate_fx,SID_2k40)) - { - st->last_active_brate_fx = st->total_brate_fx; - move32(); - } - IF ( EQ_16(st->core_fx,HQ_CORE)) - { - /* in the HQ core, coder_type is not used so it could have been set to anything */ - st->prev_coder_type_fx = GENERIC; - } - ELSE - { - st->prev_coder_type_fx = coder_type; - } - - test(); - IF( GT_32(st->core_brate_fx,SID_2k40)&&EQ_16(st->first_CNG_fx,1)) - { - if( GE_16(st->act_cnt_fx,BUF_DEC_RATE)) - { - st->act_cnt_fx = 0; - move16(); - } - - st->act_cnt_fx = add(st->act_cnt_fx,1); - - test(); - if( EQ_16(st->act_cnt_fx,BUF_DEC_RATE)&&st->ho_hist_size_fx>0) - { - st->ho_hist_size_fx = sub(st->ho_hist_size_fx,1); - } - - st->act_cnt2_fx = add(st->act_cnt2_fx,1); - if( GE_16(st->act_cnt2_fx,MIN_ACT_CNG_UPD)) - { - st->act_cnt2_fx = MIN_ACT_CNG_UPD; - move16(); - } - } - - test(); - test(); - if ( LE_32(st->core_brate_fx,SID_2k40)&&st->first_CNG_fx==0&&EQ_16(st->cng_type_fx,LP_CNG)) - { - st->first_CNG_fx = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * Increase the counter of initialization frames - * Limit the max number of init. frames - *-----------------------------------------------------------------*/ - - if( LT_16(st->ini_frame_fx,MAX_FRAME_COUNTER)) - { - st->ini_frame_fx = add(st->ini_frame_fx, 1); - } - - /* synchronisation of CNG seeds */ - test(); - IF( NE_32(st->core_brate_fx,FRAME_NO_DATA)&&NE_32(st->core_brate_fx,SID_2k40)) - { - Random( &(st->cng_seed_fx) ); - Random( &(st->cng_ener_seed_fx) ); - } - + updt_enc_common(st, Etot, Q_new); - /*---------------------------------------------------------------------* - * Updates - MODE2 - *---------------------------------------------------------------------*/ - IF( EQ_16(st->mdct_sw,MODE2)) - { - st->codec_mode = MODE2; - move16(); - st->sr_core = getCoreSamplerateMode2( st->total_brate_fx, st->bwidth_fx, st->rf_mode); - Mpy_32_16_ss(st->sr_core, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->L_frame_fx = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - assert(st->L_frame_fx == st->sr_core / 50); - IF ( EQ_32(st->sr_core,12800)) - { - st->preemph_fac = PREEMPH_FAC; - move16(); - st->gamma = GAMMA1; - move16(); - } - ELSE - { - st->preemph_fac = PREEMPH_FAC_16k; - move16(); - st->gamma = GAMMA16k; - move16(); - } - st->igf = getIgfPresent(st->total_brate_fx, st->bwidth_fx, st->rf_mode); - } - - /* update FER clas */ - st->last_clas_fx = st->clas_fx; - - core_encode_update( st ); if( EQ_16(st->mdct_sw,MODE1)) { st->codec_mode = MODE1; move16(); } - if( st->lp_cng_mode2 ) + if(hTdCngEnc->lp_cng_mode2 ) { st->codec_mode = MODE2; move16(); @@ -634,13 +604,13 @@ void evs_enc_fx( IF (EQ_16(st->rf_mode,1)) { - IF (EQ_16(st->rf_frame_type,RF_NELP)) + IF (EQ_16(hRF->rf_frame_type,RF_NELP)) { - st->last_nelp_mode_fx = 1; + hSC_VBR->last_nelp_mode_fx = 1; } ELSE { - st->last_nelp_mode_fx = 0; + hSC_VBR->last_nelp_mode_fx = 0; } } @@ -651,10 +621,10 @@ void evs_enc_fx( st->L_frame_fx = L_FRAME; st->rf_mode = 1; } - - - - return; +#ifdef MY_DEBUG + dbgwrite_indices(st); +#endif + return error; } @@ -687,6 +657,7 @@ static void initFrameHeader_loc( Encoder_State_fx *st ) } ELSE { + PMT("Frame header needs review") FOR( n=0; nbits_frame_nominal)) @@ -713,6 +684,8 @@ static void initFrameHeader_loc( Encoder_State_fx *st ) static void writeFrameHeader_loc( Encoder_State_fx *st ) { + BSTR_ENC_HANDLE hBstr = st->hBstr; + IF( NE_32(st->core_brate_fx,FRAME_NO_DATA)) { /* SID flag at 2.4kbps */ @@ -721,19 +694,19 @@ static void writeFrameHeader_loc( Encoder_State_fx *st ) IF ( EQ_16(st->cng_type_fx,FD_CNG)) { /* write SID/CNG type flag */ - push_next_indice_fx( st, 1, 1 ); + push_next_indice_fx(hBstr, 1, 1 ); /* write bandwidth mode */ - push_next_indice_fx( st, st->bwidth_fx, 2 ); + push_next_indice_fx(hBstr, st->bwidth_fx, 2 ); /* write L_frame */ IF( EQ_16(st->L_frame_fx,L_FRAME)) { - push_next_indice_fx( st, 0, 1 ); + push_next_indice_fx(hBstr, 0, 1 ); } ELSE { - push_next_indice_fx( st, 1, 1 ); + push_next_indice_fx(hBstr, 1, 1 ); } } } @@ -741,7 +714,7 @@ static void writeFrameHeader_loc( Encoder_State_fx *st ) { IF(st->rf_mode == 0) { - push_next_indice_fx( st, sub(st->bwidth_fx,FrameSizeConfig[st->frame_size_index].bandwidth_min), FrameSizeConfig[st->frame_size_index].bandwidth_bits); + push_next_indice_fx(hBstr, sub(st->bwidth_fx,FrameSizeConfig[st->frame_size_index].bandwidth_min), FrameSizeConfig[st->frame_size_index].bandwidth_bits); } } @@ -749,7 +722,7 @@ static void writeFrameHeader_loc( Encoder_State_fx *st ) test(); IF( FrameSizeConfig[st->frame_size_index].reserved_bits && st->rf_mode == 0) { - push_next_indice_fx( st, 0, FrameSizeConfig[st->frame_size_index].reserved_bits ); + push_next_indice_fx(hBstr, 0, FrameSizeConfig[st->frame_size_index].reserved_bits ); } } @@ -761,9 +734,7 @@ static void writeFrameHeader_loc( Encoder_State_fx *st ) *------------------------------------------------------------------------*/ static void configure_core_coder_loc( - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *coder_type, /* i : coder type */ - const Word16 localVAD + Encoder_State_fx *st /* i/o: encoder state structure */ ) { @@ -774,24 +745,24 @@ static void configure_core_coder_loc( { if( st->tcxonly ) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } - st->tcx_cfg.coder_type = *coder_type; + st->hTcxCfg->coder_type = st->coder_type; move16(); test(); test(); - if( !st->tcxonly && !localVAD && EQ_16(st->tcx_cfg.coder_type,GENERIC)) + if( !st->tcxonly && !st->localVAD && EQ_16(st->hTcxCfg->coder_type,GENERIC)) { - st->tcx_cfg.coder_type = UNVOICED; + st->hTcxCfg->coder_type = UNVOICED; move16(); } } - st->igf = getIgfPresent(st->total_brate_fx, st->bwidth_fx, st->rf_mode); + st->igf = getIgfPresent(st->element_mode, st->total_brate_fx, st->bwidth_fx, st->rf_mode); test(); if( NE_32(st->core_brate_fx,SID_2k40)&&NE_32(st->core_brate_fx,FRAME_NO_DATA)) diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index 86f252d..0e5bcb1 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -2,40 +2,41 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include #include +#include +#include "options.h" #include "prot_fx.h" -#include "stl.h" #include "basop_util.h" -/*-------------------------------------------------------------- - * Main Functions - *--------------------------------------------------------------*/ - -void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ - const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - const Word16 pitch[2], - Word16 Aw[NB_SUBFR16k*(M+1)],/* i : weighted A(z) unquant. for subframes*/ - Word16 lsp_new[], - Word16 lsp_mid[], - Encoder_State_fx *st, - Word16 pTnsSize[], - Word16 pTnsBits[], - Word16 param_core[], - Word16 *ltpBits, - Word16 L_frame, - Word16 L_frameTCX, - Word32 **spectrum, - Word16 *spectrum_e, - Word16 *Q_new, - Word16 *shift - ) +/*-------------------------------------------------------------------* + * core_signal_analysis_high_bitrate() + * + * + *-------------------------------------------------------------------*/ + +void core_signal_analysis_high_bitrate( + const Word16 *new_samples, /*i: 0Q15*/ + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ + Word16 lsp_new[], + Word16 lsp_mid[], + Encoder_State_fx *st, + Word16 pTnsSize[], + Word16 pTnsBits[], + Word16 param_core[], + Word16 *ltpBits, + const Word16 L_frame, + const Word16 L_frameTCX, + const Word16 last_element_mode, + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + Word32 **spectrum, + Word16 *spectrum_e, + Word16 *Q_new +) { - const Word16 last_overlap = st->tcx_cfg.tcx_last_overlap_mode; - const Word16 curr_overlap = st->tcx_cfg.tcx_curr_overlap_mode; + const Word16 last_overlap = st->hTcxCfg->tcx_last_overlap_mode; + const Word16 curr_overlap = st->hTcxCfg->tcx_curr_overlap_mode; Word16 i, frameno; Word16 L_subframe; Word16 left_overlap, right_overlap, folding_offset; @@ -53,8 +54,8 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ Word32 r[M+1], epsP[M+1]; Word16 *lsp[2]; Word8 tmp8; - Word16 alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc; - Word16 alw_voicing[2], alw_voicing_wc; + Word16 alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc = -1; + Word16 alw_voicing[2] , alw_voicing_wc = -1; Word16 nSubframes; Word16 overlap_mode[3]; Word16 transform_type[2]; @@ -65,27 +66,38 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ Word32 *tmpP32; Word16 Q_exp; + int16_t disable_ltp = 0; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - (void)Aw; - (void)shift; +#ifndef IVAS_CODE + MY_UNUSED_Word(vad_hover_flag) +#endif + if (NE_16(last_element_mode, st->element_mode) ) + { + disable_ltp = 1; /* disable TCX-LTP in stereo switching to avoid discontinuities in synthesis */ + move16(); + } left_overlap = -1; move16(); right_overlap = -1; move16(); - tcx10SizeFB = shl(st->tcx_cfg.tcx5SizeFB, 1); - tcx5SizeFB = st->tcx_cfg.tcx5SizeFB; + tcx10SizeFB = shl(st->hTcxCfg->tcx5SizeFB, 1); + tcx5SizeFB = st->hTcxCfg->tcx5SizeFB; move16(); - tcx10Size = shl(st->tcx_cfg.tcx5Size, 1); + tcx10Size = shl(st->hTcxCfg->tcx5Size, 1); /*--------------------------------------------------------------* * Input Signal Processing: copy, HP filter, pre-emphasis *---------------------------------------------------------------*/ /* Copy Samples */ - Copy(new_samples, st->new_speech_enc, L_frame ); - Scale_sig( st->new_speech_enc, L_frame, 1 ); + IF (st->tcxonly && NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + Copy(new_samples, st->new_speech_enc, L_frame); + Scale_sig(st->new_speech_enc, L_frame, 1); + } /*--------------------------------------------------------------* * TCX-LTP @@ -98,52 +110,40 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ tmp8 = 1; move16(); } + IF (EQ_16(st->element_mode, IVAS_CPE_DFT)) + { + PMT("tcx_ltp_encode should be verified for IVAS") + tcx_ltp_encode(hTcxEnc->tcxltp, st->tcxonly, hTcxEnc->tcxMode, + L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, + hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc, + T_op[1], ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, + &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, + &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, + &hTcxEnc->tcxltp_norm_corr_past, st->last_core_fx, st->pit_min, st->pit_fr1, + st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, + tmp8, NULL, M); + } + ELSE + { + tcx_ltp_encode(hTcxEnc->tcxltp, st->tcxonly, hTcxEnc->tcxMode, + L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, + hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc, + T_op[1], ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, + &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, + &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, + &hTcxEnc->tcxltp_norm_corr_past, st->last_core_fx, st->pit_min, st->pit_fr1, + st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, + tmp8, NULL, M); + } - tcx_ltp_encode( st->tcxltp, - st->tcxonly, - st->tcxMode, - L_frame, - L_SUBFR, - st->speech_enc+st->encoderLookahead_enc, - st->speech_ltp+st->encoderLookahead_enc, - st->speech_enc+st->encoderLookahead_enc, - T_op[1], - ¶m_core[1+NOISE_FILL_RANGES], - ltpBits, - &st->tcxltp_pitch_int, - &st->tcxltp_pitch_fr, - &st->tcxltp_gain, - &st->tcxltp_pitch_int_past, - &st->tcxltp_pitch_fr_past, - &st->tcxltp_gain_past, - &st->tcxltp_norm_corr_past, - st->last_core_fx, - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max, - &st->transientDetection, - tmp8, - NULL, - M - ); - - - Copy(st->speech_enc+st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame); - - Preemph_scaled(st->new_speech_enc_pe, /* input: Q0, output: Q_new - 1 */ - Q_new, - &(st->mem_preemph_enc), - st->Q_max_enc, - st->preemph_fac, - 1, /* preemph_bits = output scaling */ - 0, - 2, - L_frame, - st->coder_type_raw_fx,1 - ); + test(); + IF(st->tcxonly&& NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + Copy(st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame); + Preemph_scaled(st->new_speech_enc_pe, Q_new, &(st->mem_preemph_enc), + st->Q_max_enc, st->preemph_fac, 1, 0, 2, L_frame, st->coder_type_raw_fx, 1); + } Q_exp = sub(*Q_new, st->prev_Q_new); move16(); @@ -155,41 +155,49 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ Scale_sig(&(st->mem_wsp_enc), 1, Q_exp); } - IF (EQ_16(st->tcxMode,TCX_10)) + IF (EQ_16(hTcxEnc->tcxMode,TCX_10)) { Copy( ¶m_core[1+NOISE_FILL_RANGES], ¶m_core[NPRM_DIV+1+NOISE_FILL_RANGES], LTPSIZE ); } - lsp[0] = lsp_new; - lsp[1] = lsp_mid; /*-------------------------------------------------------------------------* * Decision matrix for the transform and overlap length *--------------------------------------------------------------------------*/ + IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + lsp[0] = lsp_new; + lsp[1] = lsp_mid; + alw_pitch_lag_12k8[0] = st->pitch_fx[0]; + move16(); + alw_pitch_lag_12k8[1] = st->pitch_fx[1]; + move16(); + alw_voicing[0] = st->voicing_fx[0]; + move16(); + alw_voicing[1] = st->voicing_fx[1]; + move16(); - alw_pitch_lag_12k8[0] = pitch[0]; - move16(); - alw_pitch_lag_12k8[1] = pitch[1]; - move16(); - alw_voicing[0] = voicing[0]; - move16(); - alw_voicing[1] = voicing[1]; - move16(); - alw_pitch_lag_12k8_wc = s_min(alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1]); - alw_voicing_wc = s_max(alw_voicing[0], alw_voicing[1]); + alw_pitch_lag_12k8_wc = s_min(alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1]); + alw_voicing_wc = s_max(alw_voicing[0], alw_voicing[1]); + } overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ move16(); - IF (EQ_16(st->tcxMode, TCX_20)) + IF (EQ_16(hTcxEnc->tcxMode, TCX_20)) { nSubframes = 1; move16(); transform_type[0] = TCX_20; + transform_type[1] = TCX_20; move16(); overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ move16(); - alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; - move16(); - alw_voicing[0] = alw_voicing_wc; - move16(); + + IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; + move16(); + alw_voicing[0] = alw_voicing_wc; + move16(); + } } ELSE { @@ -241,21 +249,21 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ } IF (NE_16(transform_type[0], TCX_20)) { - IGFEncResetTCX10BitCounter(&st->hIGFEnc); + IGFEncResetTCX10BitCounter(st->hIGFEnc); } /*-------------------------------------------------------------------------* * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed *--------------------------------------------------------------------------*/ - FOR (frameno = 0; frameno < nSubframes; frameno++) + FOR(frameno = 0; frameno < nSubframes; frameno++) { L_subframe = L_frameTCX; move16(); - if (NE_16(nSubframes, 1))L_subframe=shr(L_frameTCX,1); + if (NE_16(nSubframes, 1))L_subframe = shr(L_frameTCX, 1); lpc_left_overlap_mode = overlap_mode[frameno]; move16(); - lpc_right_overlap_mode = overlap_mode[frameno+1]; + lpc_right_overlap_mode = overlap_mode[frameno + 1]; move16(); if (EQ_16(lpc_left_overlap_mode, ALDO_WINDOW)) { @@ -269,36 +277,47 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ } test(); - IF ((NE_16(transform_type[frameno], TCX_20))||(EQ_16(st->tcx_cfg.tcx_last_overlap_mode,TRANSITION_OVERLAP))) + IF((NE_16(transform_type[frameno], TCX_20)) || (EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP))) { /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ - WindowSignal(&st->tcx_cfg, - st->tcx_cfg.tcx_offsetFB, - overlap_mode[frameno], - overlap_mode[frameno+1], - &left_overlap, &right_overlap, - &st->speech_TCX[frameno*tcx10SizeFB], - &L_subframe, - tcx20Win - ,1 - ); + WindowSignal(st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno], + overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], + &L_subframe, tcx20Win, st->element_mode != IVAS_CPE_MDCT /* truncate_aldo */, 1); +#ifdef IVAS_CODE + if (windowed_samples != NULL) /* save windowed speech_TCX samples */ + { + assert(L_subframe + (left_overlap + right_overlap) / 2 < 2 * L_FRAME_MAX / nSubframes - L_FRAME_MAX / 8); + windowed_samples[frameno * L_FRAME_MAX + 0] = (float)overlap_mode[frameno]; + windowed_samples[frameno * L_FRAME_MAX + 1] = (float)overlap_mode[frameno + 1]; + mvr2r(tcx20Win, windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + (left_overlap + right_overlap) / 2); + } +#endif } - IF (EQ_16(transform_type[frameno], TCX_5)) + IF(EQ_16(transform_type[frameno], TCX_5)) { folding_offset = shr(left_overlap, 1); /* Outter left folding */ - FOR (i = 0; i < folding_offset; i++) + FOR(i = 0; i < folding_offset; i++) { - tcx20Win[folding_offset+i] = sub(tcx20Win[folding_offset+i], tcx20Win[folding_offset-1-i]); + tcx20Win[folding_offset + i] = sub(tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i]); move16(); } +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_MDCT && frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) + { + for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + { + tcx20Win[left_overlap + i] -= hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; + } + } +#endif /* Outter right folding */ tmp = shr(right_overlap, 1); - FOR (i = 0; i < tmp; i++) + FOR(i = 0; i < tmp; i++) { - tcx20Win[L_subframe+folding_offset-1-i] = add(tcx20Win[L_subframe+folding_offset-1-i], tcx20Win[L_subframe+folding_offset+i]); + tcx20Win[L_subframe + folding_offset - 1 - i] = add(tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i]); move16(); } /* 2xTCX5 */ @@ -307,179 +326,273 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ tmpP16 = tcx20Win; tmpP32 = spectrum[frameno]; - FOR (i = 0; i < 2; i++) + assert(st->mct_chan_mode != MCT_CHAN_MODE_LFE); + FOR(i = 0; i < 2; i++) { test(); test(); - WindowSignal(&st->tcx_cfg, - folding_offset, - mac_r(-(1<<16), 3<<8, shl(i,7)), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ - mac_r(2<<16, -(3<<8), shl(i,7)), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ - &left_overlap, &right_overlap, - tmpP16, - &L_subframe, - tcx5Win - ,1 - ); + WindowSignal(st->hTcxCfg, + folding_offset, + mac_r(-(1 << 16), 3 << 8, shl(i, 7)), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ + mac_r(2 << 16, -(3 << 8), shl(i, 7)), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ + &left_overlap, &right_overlap, tmpP16, &L_subframe, tcx5Win, st->element_mode != IVAS_CPE_MDCT, 1); + spectrum_e[frameno] = 16; move16(); TCX_MDCT(tcx5Win, - tmpP32, - &spectrum_e[frameno], - left_overlap, - sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + tmpP32, + &spectrum_e[frameno], + left_overlap, + sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), + right_overlap, st->element_mode); tmpP16 += tcx5SizeFB; tmpP32 += tcx5SizeFB; +#ifdef IVAS_CODE + /* high-band gain control in case of BWS */ + if (st->bwidth_sw_cnt > 0) + { + v_multc(hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), L_subframe - L_FRAME16k / (2 * nSubframes)); + } +#endif } + } ELSE /* transform_type[frameno] != TCX_5 */ { assert(transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20); - /* TCX20/TCX10 */ - spectrum_e[frameno] = 16; + /* TCX20/TCX10 */ + spectrum_e[frameno] = 16; + move16(); + test(); test(); + IF((EQ_16(transform_type[frameno], TCX_20)) && (NE_16(st->hTcxCfg->tcx_last_overlap_mode,TRANSITION_OVERLAP)) && NE_16(st->mct_chan_mode, MCT_CHAN_MODE_LFE)) + { + Word32 tmp_buf[L_FRAME_PLUS]; + Word16 Q, tmp1, tmp2; + + Q = 0; move16(); - test(); - IF ((EQ_16(transform_type[frameno], TCX_20))&&(NE_16(st->tcx_cfg.tcx_last_overlap_mode,TRANSITION_OVERLAP))) - { - Word32 tmp_buf[L_FRAME_PLUS]; - Word16 Q, tmp1, tmp2; - Q = 0; - move16(); + wtda_fx(hTcxEnc->new_speech_TCX,&Q, tmp_buf, NULL, NULL, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX); - wtda_fx(st->new_speech_TCX, - &Q, - tmp_buf, - NULL, - NULL, - overlap_mode[frameno], - overlap_mode[frameno+1], - L_frameTCX); - - WindowSignal(&st->tcx_cfg, - st->tcx_cfg.tcx_offsetFB, - lpc_left_overlap_mode, - lpc_right_overlap_mode, - &left_overlap, &right_overlap, - &st->speech_TCX[frameno*tcx10SizeFB], - &L_subframe, - mdstWin - ,1 - ); - - /* scale by NORM_MDCT_FACTOR / L */ - tmp1 = mult_r(shl(L_subframe, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ - tmp2 = 4; - move16(); - tmp1 = ISqrt16(tmp1, &tmp2); + WindowSignal(st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, lpc_left_overlap_mode, lpc_right_overlap_mode, &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, st->element_mode != IVAS_CPE_MDCT, 1); - FOR (i = 0; i < L_subframe; i++) - { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); - move32(); - } - Q = sub(Q, tmp2); + /* scale by NORM_MDCT_FACTOR / L */ + tmp1 = mult_r(shl(L_subframe, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ + tmp2 = 4; + move16(); + tmp1 = ISqrt16(tmp1, &tmp2); - /* DCT */ - edct_fx(tmp_buf, spectrum[frameno], L_subframe, &Q); - *spectrum_e = sub(31, Q); - } - ELSE + FOR(i = 0; i < L_subframe; i++) { - TCX_MDCT(tcx20Win, - spectrum[frameno], - &spectrum_e[frameno], - left_overlap, - sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); + move32(); + } + Q = sub(Q, tmp2); + + /* DCT */ + edct_fx(tmp_buf, spectrum[frameno], L_subframe, &Q); + *spectrum_e = sub(31, Q); + } + ELSE + { +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_MDCT && frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) + { + for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + { + tcx20Win[left_overlap + i] -= hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; + } + } +#endif + TCX_MDCT(tcx20Win,spectrum[frameno], &spectrum_e[frameno], left_overlap, sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), right_overlap, st->element_mode); } /* For TCX20 at bitrates up to 64 kbps we need the power spectrum */ - test(); - test(); - IF (EQ_16(st->tcxMode, TCX_20)&&((LT_32(st->total_brate_fx,HQ_96k))||st->igf)) + + /* high-band gain control in case of BWS */ +#ifdef IVAS_CODE + if (st->bwidth_sw_cnt > 0) { + v_multc(hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes); + } - pMdstWin = tcx20Win; - test(); - if (((EQ_16(st->tcxMode, TCX_20))&&(NE_16(st->tcx_cfg.tcx_last_overlap_mode,TRANSITION_OVERLAP)))) + if (st->mct_chan_mode == MCT_CHAN_MODE_LFE) + { + set_f(&hTcxEnc->spectrum[frameno][MCT_LFE_MAX_LINE], 0.f, L_subframe - MCT_LFE_MAX_LINE); + st->hTcxCfg->tcx_coded_lines = MCT_LFE_MAX_LINE; + } +#endif + IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + test(); test(); + IF(EQ_16(hTcxEnc->tcxMode, TCX_20) && ((LT_32(st->total_brate_fx, HQ_96k)) || st->igf)) { - pMdstWin = mdstWin; - } - /* Compute noise-measure flags for spectrum filling and quantization */ - AnalyzePowerSpectrum(st, - div_l(L_mult(L_subframe, st->L_frame_fx), st->L_frameTCX), - L_subframe, - left_overlap, right_overlap, - spectrum[frameno], spectrum_e[frameno], - pMdstWin, - powerSpec, &powerSpec_e); + pMdstWin = tcx20Win; + test(); + if (((EQ_16(hTcxEnc->tcxMode, TCX_20)) && (NE_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP)))) + { + pMdstWin = mdstWin; + } + + /* Compute noise-measure flags for spectrum filling and quantization */ + AnalyzePowerSpectrum(st, div_l(L_mult(L_subframe, st->L_frame_fx), hTcxEnc->L_frameTCX), + L_subframe, left_overlap, right_overlap, spectrum[frameno], spectrum_e[frameno], + pMdstWin, powerSpec, &powerSpec_e); + } } - } +#ifdef IVAS_CODE + if (st->element_mode == IVAS_CPE_MDCT) + { + L_subframe = L_frameTCX / nSubframes; - test(); - test(); - TNSAnalysis(&st->tcx_cfg, L_frameTCX, - st->tcx_cfg.tcx_coded_lines, - transform_type[frameno], (frameno == 0) && (st->last_core_fx == ACELP_CORE), - spectrum[frameno], &st->tnsData[frameno], &st->fUseTns[frameno], NULL - ); + if (transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP && st->mct_chan_mode != MCT_CHAN_MODE_LFE) + { + wtda_ext(hTcxEnc->new_speech_TCX, mdstWin, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX, 3); + } + else + { + /* Windowing for the MDST */ + WindowSignal(st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 0, 1); + } - EncodeTnsData(st->tcx_cfg.pCurrentTnsConfig, &st->tnsData[frameno], - param_core+frameno*NPRM_DIV+1+NOISE_FILL_RANGES+LTPSIZE, pTnsSize+frameno, pTnsBits+frameno); + if (transform_type[frameno] == TCX_5) + { + /* Outer left folding */ + for (i = 0; i < left_overlap / 2; i++) + { + mdstWin[left_overlap / 2 + i] += mdstWin[left_overlap / 2 - 1 - i]; + } + + if (frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) + { + for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + { + mdstWin[left_overlap + i] += hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; + } + } + + /* Outer right folding */ + for (i = 0; i < right_overlap / 2; i++) + { + mdstWin[L_subframe + left_overlap / 2 - 1 - i] -= mdstWin[L_subframe + left_overlap / 2 + i]; + } + + /* 2xTCX5 */ + L_subframe = tcx5SizeFB; + folding_offset = left_overlap / 2; + + for (i = 0; i < 2; i++) + { + assert(st->mct_chan_mode != MCT_CHAN_MODE_LFE); + WindowSignal(st->hTcxCfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, &left_overlap, &right_overlap, mdstWin + i * tcx5SizeFB, &L_subframe, tcx5Win, 0, 1); + + TCX_MDST(tcx5Win, mdst_spectrum[frameno] + i * tcx5SizeFB, left_overlap, L_subframe - (left_overlap + right_overlap) / 2, right_overlap, st->element_mode); + /* high-band gain control in case of BWS */ + if (st->bwidth_sw_cnt > 0) + { + v_multc(mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / (2 * nSubframes), L_subframe - L_FRAME16k / (2 * nSubframes)); + } + } + } + else /* transform_type[frameno] != TCX_5 */ + { + if (transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP && st->mct_chan_mode != MCT_CHAN_MODE_LFE) + { + edst(mdstWin, mdst_spectrum[frameno], L_subframe, st->element_mode); + + v_multc(mdst_spectrum[frameno], (float)sqrt((float)NORM_MDCT_FACTOR / L_subframe), mdst_spectrum[frameno], L_subframe); + } + else + { + if (frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen) + { + for (i = minWindowLen; i >= 0; i--) /* outer left folding of shortened long ALDO slope */ + { + mdstWin[left_overlap + i] += hTcxEnc->speech_TCX[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i]; + } + } + + TCX_MDST(mdstWin, mdst_spectrum[frameno], left_overlap, L_subframe - (left_overlap + right_overlap) / 2, right_overlap, st->element_mode); + } + + /* high-band gain control in case of BWS */ + if (st->bwidth_sw_cnt > 0) + { + v_multc(mdst_spectrum[frameno] + L_FRAME16k / nSubframes, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, mdst_spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes); + } + } - IF (EQ_16(transform_type[frameno], TCX_5)) + if (st->mct_chan_mode == MCT_CHAN_MODE_LFE) + { + set_f(&mdst_spectrum[frameno][MCT_LFE_MAX_LINE], 0.f, L_subframe - MCT_LFE_MAX_LINE); + } +#endif + } + IF(NE_16(st->element_mode, IVAS_CPE_MDCT)) { - /* group sub-windows: interleave bins according to their frequencies */ - FOR (i = 0; i < tcx5SizeFB; i++) + test(); + test(); + TNSAnalysis(st->hTcxCfg, L_frameTCX, + st->hTcxCfg->tcx_coded_lines, + transform_type[frameno], (frameno == 0) && (st->last_core_fx == ACELP_CORE), + spectrum[frameno], &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL + ); +#ifdef IVAS_CODE + IF (st->hTcxCfg->fIsTNSAllowed) +#endif { - interleaveBuf[2*i] = spectrum[frameno][i]; - move32(); - interleaveBuf[2*i+1] = spectrum[frameno][tcx5SizeFB+i]; - move32(); + EncodeTnsData(st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], + param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno); + } + IF(EQ_16(transform_type[frameno], TCX_5)) + { + /* group sub-windows: interleave bins according to their frequencies */ + FOR(i = 0; i < tcx5SizeFB; i++) + { + interleaveBuf[2 * i] = spectrum[frameno][i]; + move32(); + interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; + move32(); + } + Copy32(interleaveBuf, spectrum[frameno], tcx10SizeFB); } - Copy32(interleaveBuf, spectrum[frameno], tcx10SizeFB); - } - - /*--------------------------------------------------------------* - * LPC analysis - *---------------------------------------------------------------*/ + /*--------------------------------------------------------------* + * LPC analysis + *---------------------------------------------------------------*/ - HBAutocorrelation(&st->tcx_cfg, - lpc_left_overlap_mode, - lpc_right_overlap_mode, - &st->speech_enc_pe[frameno*tcx10Size], - shr(L_frame, sub(nSubframes, 1)), - r, - M); +#ifdef IVAS_CODE + IF(st->tcxonly) +#endif + { + HBAutocorrelation(st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size], + shr(L_frame, sub(nSubframes, 1)), r, M); - FOR (i=0; i <= M; i++) - { - move16(); - move16(); - r_l[frameno][i] = L_Extract_lc(r[i], &r_h[frameno][i]); - } + FOR(i = 0; i <= M; i++) + { + move16(); + move16(); + r_l[frameno][i] = L_Extract_lc(r[i], &r_h[frameno][i]); + } - adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); + adapt_lag_wind(r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core); - E_LPC_lev_dur(r_h[frameno], r_l[frameno], A, epsP, M, NULL); + E_LPC_lev_dur(r_h[frameno], r_l[frameno], A, epsP, M, NULL); - E_LPC_a_lsp_conversion(A, lsp[nSubframes-1-frameno], st->lspold_enc_fx, M ); + E_LPC_a_lsp_conversion(A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M); + } + IF(st->igf) + { + ProcessIGF(st->hIGFEnc, st, spectrum[frameno], &(spectrum_e[frameno]), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, hTcxEnc->fUseTns[frameno], (st->last_core_fx == ACELP_CORE), frameno); + } - IF (st->igf) - { - ProcessIGF(&st->hIGFEnc, st, spectrum[frameno], &(spectrum_e[frameno]), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, st->fUseTns[frameno], (st->last_core_fx == ACELP_CORE), frameno); + /* Copy memory */ + mvr2r_Word16(lsp_new, st->lspold_enc_fx, M); } } - /* Copy memory */ - mvr2r_Word16(lsp_new, st->lspold_enc_fx, M); - - } diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 6264bef..695be11 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -16,9 +16,9 @@ /******************************** * External functions * ********************************/ - -#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - +#ifndef swap + #define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} +#endif /************************************* * Create an instance of type FD_CNG * @@ -283,12 +283,13 @@ void resetFdCngEnc( Word16 n; Word16 totalNoiseIncrease; Word16 thresh = 5 * 256; /* 5.0 in Q8 */ + NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; /* st->totalNoise_fx; Q8 Noise estimator - total noise energy */ /* Detect fast increase of totalNoise */ - totalNoiseIncrease = sub(st->totalNoise_fx, st->last_totalNoise_fx); - st->last_totalNoise_fx = st->totalNoise_fx; + totalNoiseIncrease = sub(hNoiseEst->totalNoise_fx, st->last_totalNoise_fx); + st->last_totalNoise_fx = hNoiseEst->totalNoise_fx; move16(); IF ( totalNoiseIncrease > 0 ) { @@ -534,25 +535,26 @@ void perform_noise_estimation_enc (Word32 *band_energies, /* i: energy in void */ Word16 -AdjustFirstSID (Word16 npart, /* i : number of parts */ - Word32 *msPeriodog, /* i : pointer to periodog vector */ - Word16 msPeriodog_exp, /* i : exponent of periodog vector */ - Word32 *energy_ho, /* i/o : pointer to energy */ - Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ - Word32 *msNoiseEst, /* i/o : pointer to estimated noise */ - Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ - Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise */ - Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ - Word16 *active_frame_counter, /* i/o : pointer to active frame counter */ - Encoder_State_fx *stcod /* i : pointer to Coder_State_Plus structure */ - ) +AdjustFirstSID ( + Word16 npart, /* i : number of parts */ + Word32 *msPeriodog, /* i : pointer to periodog vector */ + Word16 msPeriodog_exp, /* i : exponent of periodog vector */ + Word32 *energy_ho, /* i/o : pointer to energy */ + Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ + Word32 *msNoiseEst, /* i/o : pointer to estimated noise */ + Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ + Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise */ + Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ + Word16 *active_frame_counter, /* i/o : pointer to active frame counter */ + Encoder_State_fx *stcod /* i : pointer to Coder_State_Plus structure */ +) { Word16 i, sc, s1, s2, lambda, lambdaM1, invFac; Word32 tmp32, energy_ho_local, msNoiseEst_local; - + DTX_ENC_HANDLE hDtxEnc = stcod->hDtxEnc; test(); - IF ( EQ_16(stcod->cnt_SID_fx,1)&>_32(stcod->last_core_brate_fx,SID_2k40)) + IF ( EQ_16(hDtxEnc->cnt_SID_fx,1)&>_32(stcod->last_core_brate_fx,SID_2k40)) { /* Detect the hangover period and the first SID frame at the beginning of each CNG phase */ @@ -905,10 +907,21 @@ void FdCng_encodeSID (HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG struct Word16 indices[32]; Word16 v16[32]; - + BSTR_ENC_HANDLE hBstr = corest->hBstr; HANDLE_FD_CNG_COM st; +#ifdef IVAS_CODE_CNG + float* invTrfMatrix; + float tmpRAM[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; + float dct_target[FDCNG_VQ_DCT_MAXTRUNC]; + float tot_sig_ext[FDCNG_VQ_MAX_LEN]; + const float gain_q_offset = (st->element_mode == EVS_MONO) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS; + /* Init */ + N = hFdCngEnc->npartDec; + invTrfMatrix = (float*)tmpRAM; /* dynamically filled */ + set_zero(v, FDCNG_VQ_MAX_LEN); +#endif /* Init */ @@ -959,27 +972,36 @@ void FdCng_encodeSID (HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG struct v16[i] = extract_h(L_sub(v[i], gain)); } +#ifdef IVAS_CODE_CNG + IF (st->element_mode != EVS_MONO) + { + /* DCT domain compressed/truncated indices used for first stage */ + /* quantization with stage1 stored in DCT24 domain, stages 2 through 6 directly dearched + in FDCNG band domain + */ + if (N == FDCNG_VQ_MAX_LEN_WB) + { + create_IDCT_N_Matrix(invTrfMatrix, N, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM) / (sizeof(float))); + /* truncated DCT21 analysis */ + dctT2_N_apply_matrix((const float*)v, dct_target, FDCNG_VQ_DCT_MAXTRUNC, N, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, DCT_T2_21_XX); + /* truncated IDCT21 extension to 24 bands */ + extend_dctN_input(v, dct_target, N, tot_sig_ext, FDCNG_VQ_MAX_LEN, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21); - /* MSVQ encoder */ - msvq_encoder (cdk_37bits, - v16, - levels_37bits, - maxC_37bits, - stages_37bits, - N, - maxN_37bits, - indices - ); - - /* MSVQ decoder */ - msvq_decoder (cdk_37bits, - stages_37bits, - N, - maxN_37bits, - indices, - v16 - ); + mvr2r(tot_sig_ext, v, FDCNG_VQ_MAX_LEN); /* write extended result as input to VQ stage #1 */ + } + create_IDCT_N_Matrix(invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM) / (sizeof(float))); + msvq_enc(cdk_37bits_ivas, NULL, NULL, v, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w, N, FD_CNG_maxN_37bits, 1, invTrfMatrix, indices); + msvq_dec(cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix, v, NULL); + } + ELSE +#endif + { + /* MSVQ encoder */ + msvq_encoder(cdk_37bits, v16, levels_37bits, maxC_37bits, stages_37bits, N, maxN_37bits, indices ); + /* MSVQ decoder */ + msvq_decoder(cdk_37bits, stages_37bits, N, maxN_37bits, indices, v16); + } FOR (i=0; iCngBandwidth, st->CngBitrate ); - +#ifdef IVAS_CODE_CNG + if (st->element_mode > EVS_MONO) + { + apply_scale(&gain, hFdCngCom->CngBandwidth, hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); + } + else +#endif + { + apply_scale(&gain, st->CngBandwidth, st->CngBitrate, scaleTableMono, SIZE_SCALE_TABLE_MONO); + } +#ifdef IVAS_CODE_CNG + /* Quantize gain, Q14.23 format */ + gain = L_add(gain, L_shr(gain, 1)); + gain = L_add(gain, gain_q_offset/*gain_q_offset+.5 Q23*/); + index = extract_l(L_shr(gain, WORD32_BITS - 1 - 8)); +#else /* Quantize gain, Q14.23 format */ gain = L_add(gain, L_shr(gain,1)); gain = L_add(gain, 507510784l/*60.5 Q23*/); index = extract_l(L_shr(gain,WORD32_BITS-1-8)); - +#endif if ( index < 0 ) { @@ -1016,12 +1052,17 @@ void FdCng_encodeSID (HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG struct index = 127; move16(); } - +#ifndef IVAS_CODE_CNG /* gain Q14.23 format */ - gain = L_shl(L_deposit_l(index), WORD32_BITS-1-8); + gain = L_shl(L_deposit_l(index), WORD32_BITS - 1 - 8); gain = L_sub(gain, 503316480l/*60.0 Q23*/); gain = Mpy_32_16_1(gain, 21845/*2.0f/3.0f Q15*/); - +#else + /* gain Q14.23 format */ + gain = L_shl(L_deposit_l(index), WORD32_BITS-1-8); + gain = L_sub(gain, gain_q_offset/*60.0 Q23*/); + gain = Mpy_32_16_1(gain, 21845/*2.0f/3.0f Q15*/); +#endif /* Apply gain and undo log */ @@ -1037,7 +1078,7 @@ void FdCng_encodeSID (HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG struct maxVal = L_add(maxVal, gain); maxVal = L_shl(Mpy_32_16_1(maxVal, 21771/*0.66438561897 Q15*/), 1); - +PMT("st must be replaced by hFdCngCom") sidNoiseEst_Exp = 0; move16(); WHILE (maxVal >= 0) @@ -1079,27 +1120,27 @@ void FdCng_encodeSID (HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG struct { FOR (i=0; ibwidth_fx, 2 ); + push_indice_fx( hBstr, IND_SID_TYPE, 1, 1 ); + push_indice_fx( hBstr, IND_ACELP_16KHZ, corest->bwidth_fx, 2 ); IF (EQ_16(corest->L_frame_fx, L_FRAME16k)) { - push_indice_fx( corest, IND_ACELP_16KHZ, 1, 1 ); + push_indice_fx( hBstr, IND_ACELP_16KHZ, 1, 1 ); } ELSE { - push_indice_fx( corest, IND_ACELP_16KHZ, 0, 1 ); + push_indice_fx( hBstr, IND_ACELP_16KHZ, 0, 1 ); } FOR (i=0; icngNoiseLevel, st->cngNoiseLevelExp, stenc->startBandDec, stenc->stopFFTbinDec, st->fftlen, st->A_cng, M, preemph_fac ); + lpc_from_spectrum(st, stenc->startBandDec, stenc->stopFFTbinDec, preemph_fac ); } @@ -1138,8 +1179,11 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, Word16 tcx_transition = 0; HANDLE_FD_CNG_ENC stenc = stcod->hFdCngEnc_fx; HANDLE_FD_CNG_COM st = stenc->hFdCngCom; + DTX_ENC_HANDLE hDtxEnc = stcod->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = stcod->hTdCngEnc; - + LPD_state_HANDLE hLPDmem = stcod->hLPDmem; + TCX_ENC_HANDLE hTcxEnc = stcod->hTcxEnc; /* Warning fix */ s = 0; @@ -1236,8 +1280,7 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, /* Perform STFT synthesis */ SynthesisSTFT (fftBuffer, fftBufferExp, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, - tcx_transition, - st, gen_exc, &Q_new); + tcx_transition,st, gen_exc, &Q_new, -1, -1); { Word32 Lener, att; Word16 exp; @@ -1261,10 +1304,10 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, { IF( EQ_16(stcod->bwidth_fx,WB)) { - IF( stcod->CNG_mode_fx >= 0 ) + IF(hDtxEnc->CNG_mode_fx >= 0 ) { /* Bitrate adapted attenuation */ - att = L_shl(L_deposit_l(ENR_ATT_fx[stcod->CNG_mode_fx]),17); + att = L_shl(L_deposit_l(ENR_ATT_fx[hDtxEnc->CNG_mode_fx]),17); } ELSE { @@ -1284,7 +1327,7 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, Lener = Mult_32_16(Lener, 6554/*0.2f Q15*/); exp = sub(25,exp); Lener = L_shr(Lener, exp); /*Q6*/ - stcod->lp_ener_fx = L_add(Mult_32_16(stcod->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ + hTdCngEnc->lp_ener_fx = L_add(Mult_32_16(hTdCngEnc->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ } /* Overlap-add when previous frame is active */ @@ -1312,7 +1355,7 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, IF ( GT_16(stcod->last_core_fx,ACELP_CORE)) { Word16 left_overlap_mode; - left_overlap_mode = stcod->tcx_cfg.tcx_last_overlap_mode; + left_overlap_mode = stcod->hTcxCfg->tcx_last_overlap_mode; move16(); if (EQ_16(left_overlap_mode, ALDO_WINDOW)) { @@ -1321,12 +1364,12 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, } tcx_windowing_synthesis_current_frame( timeDomainOutput, - stcod->tcx_cfg.tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ - stcod->tcx_cfg.tcx_mdct_window_half, - stcod->tcx_cfg.tcx_mdct_window_minimum, - stcod->tcx_cfg.tcx_mdct_window_length, - stcod->tcx_cfg.tcx_mdct_window_half_length, - stcod->tcx_cfg.tcx_mdct_window_min_length, + stcod->hTcxCfg->tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ + stcod->hTcxCfg->tcx_mdct_window_half, + stcod->hTcxCfg->tcx_mdct_window_minimum, + stcod->hTcxCfg->tcx_mdct_window_length, + stcod->hTcxCfg->tcx_mdct_window_half_length, + stcod->hTcxCfg->tcx_mdct_window_min_length, 0, left_overlap_mode, NULL, @@ -1335,35 +1378,35 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, NULL, NULL, N/2, - shr(sub(abs_s(stcod->tcx_cfg.tcx_offset), stcod->tcx_cfg.tcx_offset), 1), /* equivalent to: stdec->tcx_cfg.tcx_offset<0?-stdec->tcx_cfg.tcx_offset:0 */ + shr(sub(abs_s(stcod->hTcxCfg->tcx_offset), stcod->hTcxCfg->tcx_offset), 1), /* equivalent to: stdec->hTcxCfg->tcx_offset<0?-stdec->hTcxCfg->tcx_offset:0 */ 1, 0, 0 ); - IF (stcod->tcx_cfg.last_aldo != 0) + IF (stcod->hTcxCfg->last_aldo != 0) { FOR (i=0; iframeSize; i++) { - timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(stcod->old_out_fx[i+NS2SA(stcod->sr_core, N_ZERO_MDCT_NS)],stcod->Q_old_out)); + timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(hTcxEnc->old_out_fx[i+NS2SA(stcod->sr_core, N_ZERO_MDCT_NS)], hTcxEnc->Q_old_out)); move16(); } } ELSE { - tcx_windowing_synthesis_past_frame( stcod->LPDmem.Txnq, - stcod->tcx_cfg.tcx_aldo_window_1_trunc, - stcod->tcx_cfg.tcx_mdct_window_half, - stcod->tcx_cfg.tcx_mdct_window_minimum, - stcod->tcx_cfg.tcx_mdct_window_length, - stcod->tcx_cfg.tcx_mdct_window_half_length, - stcod->tcx_cfg.tcx_mdct_window_min_length, - stcod->tcx_cfg.tcx_last_overlap_mode + tcx_windowing_synthesis_past_frame(hTcxEnc->Txnq, + stcod->hTcxCfg->tcx_aldo_window_1_trunc, + stcod->hTcxCfg->tcx_mdct_window_half, + stcod->hTcxCfg->tcx_mdct_window_minimum, + stcod->hTcxCfg->tcx_mdct_window_length, + stcod->hTcxCfg->tcx_mdct_window_half_length, + stcod->hTcxCfg->tcx_mdct_window_min_length, + stcod->hTcxCfg->tcx_last_overlap_mode ); FOR (i=0; iLPDmem.Txnq[i],TCX_IMDCT_HEADROOM)); + timeDomainOutput[i] = add(timeDomainOutput[i],shl(hTcxEnc->Txnq[i],TCX_IMDCT_HEADROOM)); move16(); } } @@ -1386,9 +1429,9 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, lpcorder = M; move16(); E_LPC_f_lsp_a_conversion(stcod->lsp_old_fx, old_Aq, M); - old_exc = stcod->LPDmem.old_exc+sub(L_EXC_MEM,N2); - old_syn_pe = stcod->LPDmem.mem_syn2; - old_syn = stcod->LPDmem.syn[lpcorder]; + old_exc = hLPDmem->old_exc+sub(L_EXC_MEM,N2); + old_syn_pe = hLPDmem->mem_syn2; + old_syn = hLPDmem->syn[lpcorder]; move16(); preemph_fac = stcod->preemph_fac; move16(); @@ -1498,3 +1541,102 @@ void generate_comfort_noise_enc (Encoder_State_fx *stcod, } +/*-------------------------------------------------------------------* + * cng_energy() + * + * + *-------------------------------------------------------------------*/ + + /*! r: CNG energy */ +Word16 cng_energy( + const Word16 element_mode, /* i : element mode */ + const Word16 bwidth, /* i : audio bandwidh */ + const Word16 CNG_mode, /* i : mode for DTX configuration */ + const Word16 CNG_att, /* i : attenuation factor for CNG */ + const Word16* exc, /* i : input signal */ + const Word16 len, /* i : vector length */ + const Word16 Q_new /* i : Input scaling */ +) +{ + Word16 i, maxv, scale; + Word16 hi, lo, enr, tmp16, att; + const Word16* pt_res; + Word32 L_ener, L_tmp; + + maxv = 0; + move16(); + FOR(i = 0; i < len; i++) + { + maxv = s_max(maxv, abs_s(exc[i])); + } + scale = norm_s(maxv); + pt_res = exc; + L_ener = L_deposit_l(1); + IF(EQ_16(len, L_FRAME)) + { + FOR(i = 0; i < 128; i++) + { + tmp16 = shl(*pt_res, scale); + L_tmp = L_mult0(tmp16, tmp16); + pt_res++; + tmp16 = shl(*pt_res, scale); + L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ + } + } + ELSE /* L_FRAME16k */ + { + FOR(i = 0; i < 160; i++) + { + tmp16 = shl(*pt_res,scale); + L_tmp = L_mult0(tmp16, tmp16); + pt_res++; + tmp16 = shl(*pt_res,scale); + L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ + } + } + + hi = norm_l(L_ener); + lo = Log2_norm_lc(L_shl(L_ener, hi)); + hi = sub(30, add(hi, shl(add(Q_new, scale), 1))); /* log2 exp in Q2*(Q_new+scale) */ + L_tmp = L_Comp(hi, lo); /* Q16 */ + enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ + + /* decrease the energy in case of WB input */ + test(); + IF (EQ_16(element_mode, IVAS_CPE_DFT) || EQ_16(element_mode, IVAS_CPE_TD)) + { + PMT(" IVAS CNG ener computing is missing") +#ifdef IVAS_CODE + enr += CNG_att * FAC_LOG2 / 10.0f; +#else + MY_UNUSED_Word(CNG_att) +#endif + } + ELSE IF(NE_16(bwidth, NB)) + { + IF(EQ_16(bwidth, WB)) + { + IF(CNG_mode >= 0) + { + /* Bitrate adapted attenuation */ + att = ENR_ATT_fx[CNG_mode]; + } + ELSE + { + /* Use least attenuation for higher bitrates */ + att = ENR_ATT_fx[4]; + } + } + ELSE + { + att = 384; + move16();/*Q8*/ + } + enr = sub(enr, att); + } + return enr; +} diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index cb1099b..93745ee 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -1,7 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ #include "cnst_fx.h" /* Common constants */ @@ -11,22 +11,22 @@ void find_targets_fx( - const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ - const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ - Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ - const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ - const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ - const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ - Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ - Word16 *cn /* o : target vector in residual domain Q_new*/ - ,Word16 *h1 + const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ + const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ + const Word16 i_subfr, /* i : subframe index */ + Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ + const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ + const Word16 *res, /* i : residual signal Q_new*/ + const Word16 L_subfr, /* i : length of vectors for gain quantization */ + const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ + Word16 tilt_fac, /* i : tilt factor Q15 */ + Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ + Word16 *cn, /* o : target vector in residual domain Q_new*/ + Word16 *h1 /* o : impulse response of weighted synthesis filter */ ) { Word16 i; - Word16 temp[M+5*L_SUBFR]; /* error of quantization */ + Word16 temp[M+6*L_SUBFR]; /* error of quantization */ Word16 scale,scaleq,j,d,s,s2,tmp; Word16 Aqs[M+1]; Word32 Ltmp; @@ -109,6 +109,8 @@ void find_targets_fx( Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); } h1[M] = round_fx(L_shl(Ltmp, s)); + +PMT("should we used extended basop here for when the L_subfr > L_SUBFR, to prevent saturation/overflow and the subsequent loop\n") FOR (i=M+1; i < L_subfr; i++) { Ltmp = L_msu(0, Aqs[1], h1[i-1]); diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index 800e056..897117c 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_util.h" /*-------------------------------------------------------------------* @@ -17,7 +16,7 @@ void find_tilt_fx( const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ @@ -27,7 +26,7 @@ void find_tilt_fx( Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ const Word16 codec_mode, /* i : MODE1 or MODE2 */ const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ ,Word16 Opt_vbr_mode ) { diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c index f1204a1..eaa3209 100644 --- a/lib_enc/find_uv.c +++ b/lib_enc/find_uv.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Local constants @@ -83,23 +82,26 @@ static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10 * Decision about coder type *-------------------------------------------------------------------*/ -Word16 find_uv_fx( /* o : coding type */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ - const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ - const Word16 *voicing, /* i : correlation for 3 half-frames Q15*/ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ - const Word16 localVAD, /* i : vad without hangover */ - const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/ - const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ - const Word16 relE, /* i : relative frame energy Q8*/ - const Word16 Etot, /* i : total energy Q8*/ - const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/ +Word16 find_uv_fx( /* o : coding type */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ + const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ + const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ + const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/ +#ifdef IVAS_CODE + Word32* dE1X, /* o : sudden energy increase for S/M classifier */ +#endif + const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ + const Word16 relE, /* i : relative frame energy Q8*/ + const Word16 Etot, /* i : total energy Q8*/ + const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/ const Word16 Q_new, - Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ - const Word16 voicing_sm /* i : smoothed open-loop pitch gains */ - , const Word16 shift - , const Word16 last_core_orig /* i : original last core */ + Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ + const Word16 shift, + const Word16 last_core_orig /* i : original last core */ +#ifdef IVAS_CODE + ,STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ +#endif ) { Word16 coder_type, i; @@ -116,6 +118,22 @@ Word16 find_uv_fx( /* o : coding type Word16 mean_voi3_offset; Word16 voicing_m, dpit1, dpit2, dpit3; Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE; + NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + + Word16 Last_Resort; + Word16 vadnoise; + + IF (hSC_VBR != NULL) + { + Last_Resort = hSC_VBR->Last_Resort_fx; + vadnoise = hSC_VBR->vadnoise_fx; + } + ELSE + { + Last_Resort = 0; + vadnoise = 0; + } Q_in = sub(Q_new,1); @@ -170,7 +188,25 @@ Word16 find_uv_fx( /* o : coding type pt_enr_ssf++; pt_enr_ssf1++; } +#ifdef IVAS_CODE + IF (hStereoClassif != NULL) + { + IF (st_fx->idchan == 0) + { + hStereoClassif->dE1_ch1 = dE1; + } + ELSE + { + hStereoClassif->dE1_ch2 = dE1; + } + } + if (dE1X != NULL) + { + *dE1X = dE1; + move32(); + } +#endif /*-----------------------------------------------------------------* * Average spectral tilt * Average voicing (normalized correlation) @@ -181,15 +217,15 @@ Word16 find_uv_fx( /* o : coding type mean_ee = Mult_32_16(mean_ee, 10923); /*Q6*/ /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ - Ltmp0 = L_mult( voicing[0], 10923); - Ltmp0 = L_mac(Ltmp0, voicing[1], 10923); - mean_voi3 = mac_r(Ltmp0, voicing[2], 10923); /*Q15*/ + Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923); + Ltmp0 = L_mac(Ltmp0, st_fx->voicing_fx[1], 10923); + mean_voi3 = mac_r(Ltmp0, st_fx->voicing_fx[2], 10923); /*Q15*/ /*-----------------------------------------------------------------* * Total frame energy difference (dE3) *-----------------------------------------------------------------*/ - dE3 = sub(Etot, st_fx->Etot_last_fx); /*Q8*/ + dE3 = sub(Etot, hNoiseEst->Etot_last_fx); /*Q8*/ /*-----------------------------------------------------------------* * Energy decrease after spike (dE2) @@ -279,7 +315,7 @@ Word16 find_uv_fx( /* o : coding type test(); if( ( EQ_16(st_fx->last_coder_type_raw_fx,UNVOICED))|| /* previous frame was unvoiced */ ( ( LT_32(ee[0],ee0_th) ) && ( GT_32(hp_E[0],L_shl(E_MIN_FX,Q_new)) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ - ( LT_16(add(voicing[0],corr_shift),voi_th)))) /* normalized correlation is low */ + ( LT_16(add(st_fx->voicing_fx[0],corr_shift),voi_th)))) /* normalized correlation is low */ { tmp_offset_flag = 0; move16(); @@ -295,7 +331,7 @@ Word16 find_uv_fx( /* o : coding type flag_low_relE = 0; move16(); ee1_th = 608; /*9.5 Q6*/ move16(); - IF ( st_fx->Opt_SC_VBR_fx ) + IF ( st_fx->Opt_SC_VBR_fx || (EQ_16(st_fx->idchan, 1) && EQ_16(st_fx->element_mode, IVAS_CPE_TD))) /* Allow the low energy flag for the secondary channel */ { ee1_th = 544; /*8.5f Q6*/ move16(); @@ -304,7 +340,7 @@ Word16 find_uv_fx( /* o : coding type { /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */ L_tmp = L_mac(-562036736, 22938, st_fx->lp_noise_fx); - if ( st_fx->Last_Resort_fx == 0 ) + if ( Last_Resort == 0 ) { /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/ L_tmp = L_mac(-562036736, 21299, st_fx->lp_noise_fx); @@ -329,7 +365,7 @@ Word16 find_uv_fx( /* o : coding type /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */ test(); - if ( EQ_16(st_fx->input_bwidth_fx,NB)&<_16(st_fx->vadnoise_fx,20<<8)) /* vadnoise in Q8, constant Q0<<8 */ + if ( EQ_16(st_fx->input_bwidth_fx,NB)&<_16( vadnoise ,20<<8)) /* vadnoise in Q8, constant Q0<<8 */ { mean_voi3_offset = 1638; /*0.05f Q15*/ move16(); } @@ -353,11 +389,11 @@ Word16 find_uv_fx( /* o : coding type test(); test(); if( ( ( LT_16(add(mean_voi3, corr_shift),add(22282,mean_voi3_offset)))&& /* normalized correlation low */ - ( LT_16(add(voicing[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_16(add(st_fx->voicing_fx[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ ( LT_32(ee[0], 640) ) && ( GT_32(hp_E[0], E_min_th) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32(ee[1], ee1_th) ) && ( GT_32(hp_E[1], E_min_th) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - ( st_fx->music_hysteresis_fx == 0 ) && /* ... and in segment after AUDIO frames */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ ( LE_32(dE1, 237568) ) && /* Avoid on sharp energy spikes */ ( LE_32(st_fx->old_dE1_fx,237568) ) && /* + one frame hysteresis */ ( st_fx->spike_hyst_fx < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ @@ -382,11 +418,11 @@ Word16 find_uv_fx( /* o : coding type test(); test(); if( ( ( LT_16(add(mean_voi3, corr_shift),add(22774,mean_voi3_offset)))&& /* normalized correlation low */ - ( LT_16(add(voicing[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_16(add(st_fx->voicing_fx[2], corr_shift),25887) ) && /* normalized correlation low on look-ahead - onset detection */ ( LT_32(ee[0], 397) ) && ( GT_32(hp_E[0], E_min_th) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32(ee[1], 397) ) && ( GT_32(hp_E[1], E_min_th) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - ( st_fx->music_hysteresis_fx == 0 ) && /* ... and in segment after AUDIO frames */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ ( LE_32(dE1, 245760) ) && /* Avoid on sharp energy spikes */ ( LE_32(st_fx->old_dE1_fx,245760) ) && /* + one frame hysteresis */ ( st_fx->spike_hyst_fx < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ @@ -403,13 +439,15 @@ Word16 find_uv_fx( /* o : coding type /*-----------------------------------------------------------------* * Decision about VC *-----------------------------------------------------------------*/ - - st_fx->set_ppp_generic_fx = 0; + if (st_fx->Opt_SC_VBR_fx) + { + hSC_VBR->set_ppp_generic_fx = 0; + } move16(); test(); test(); - IF( EQ_16(localVAD,1)&&EQ_16(coder_type,GENERIC)&&NE_16(last_core_orig,AMR_WB_CORE)) + IF( EQ_16(st_fx->localVAD,1)&&EQ_16(coder_type,GENERIC)&&NE_16(last_core_orig,AMR_WB_CORE)) { dpit1 = abs_s( sub(T_op_fr[1], T_op_fr[0])); dpit2 = abs_s( sub(T_op_fr[2], T_op_fr[1])); @@ -436,7 +474,7 @@ Word16 find_uv_fx( /* o : coding type coder_type = VOICED; move16(); } - ELSE IF ( st_fx->Opt_SC_VBR_fx && EQ_16(st_fx->input_bwidth_fx,NB)&<_16(st_fx->vadnoise_fx,20<<8)) + ELSE IF ( st_fx->Opt_SC_VBR_fx && EQ_16(st_fx->input_bwidth_fx,NB) && LT_16(vadnoise,20<<8)) { test(); test(); @@ -454,7 +492,7 @@ Word16 find_uv_fx( /* o : coding type ( LT_16(dpit2,5<<6) ) && ( LT_16(dpit3,5<<6) ) ) { - st_fx->set_ppp_generic_fx = 1; + hSC_VBR->set_ppp_generic_fx = 1; move16(); coder_type = VOICED; move16(); @@ -470,7 +508,7 @@ Word16 find_uv_fx( /* o : coding type test(); test(); IF ( *flag_spitch || ( LE_16(dpit1,3<<6)&&LE_16(dpit2,3<<6)&&LE_16(dpit3,3<<6)&& - GT_16(voicing_m, 31130) && GT_16(voicing_sm, 31785) ) ) + GT_16(voicing_m, 31130) && GT_16(st_fx->voicing_sm_fx, 31785) ) ) { coder_type = VOICED; move16(); @@ -496,7 +534,7 @@ Word16 find_uv_fx( /* o : coding type ( LT_16(voicing_fr[1],6554) ) && /* normalized correlation high in 2st sf. */ ( LT_16(voicing_fr[2],6554) ) && /* normalized correlation high in 3rd sf. */ ( LT_16(voicing_fr[3],6554) ) && /* normalized correlation high in 4th sf. */ - ( GT_16(st_fx->vadnoise_fx, 25 << 8 ) )) /* when speech is clean */ + ( GT_16(vadnoise, 25 << 8 ) )) /* when speech is clean */ { st_fx->rf_mode = 0; @@ -505,13 +543,27 @@ Word16 find_uv_fx( /* o : coding type if( st_fx->rf_mode != st_fx->Opt_RF_ON ) { - core_coder_mode_switch( st_fx, st_fx->bwidth_fx, st_fx->total_brate_fx, shift ); + core_coder_mode_switch( st_fx, st_fx->last_total_brate_fx, 0, shift ); } } } +#ifdef IVAS_CODE + /*-----------------------------------------------------------------* + * UNCLR classifier + *-----------------------------------------------------------------*/ - - + if (hStereoClassif != NULL) + { + if (st->element_mode > EVS_MONO && (coder_type == GENERIC || coder_type == UNVOICED || coder_type == INACTIVE || st->localVAD == 0) && hStereoClassif->unclr_sw_enable_cnt[st->idchan] < MAX_UV_CNT) + { + hStereoClassif->unclr_sw_enable_cnt[st->idchan]++; + } + else + { + hStereoClassif->unclr_sw_enable_cnt[st->idchan] = 0; + } + } +#endif /*-----------------------------------------------------------------* diff --git a/lib_enc/find_wsp_fx.c b/lib_enc/find_wsp_fx.c index acbc503..7058992 100644 --- a/lib_enc/find_wsp_fx.c +++ b/lib_enc/find_wsp_fx.c @@ -3,13 +3,10 @@ ====================================================================================*/ -#include -#include -#include "stl.h" -#include "prot_fx.h" +#include #include "options.h" +#include "prot_fx.h" #include "cnst_fx.h" -#include "stl.h" @@ -33,17 +30,17 @@ * void */ void find_wsp( - const Word16 Az[], - const Word16 speech[], - Word16 wsp[], - Word16 *mem_wsp, - const Word16 preemph_fac, - const Word16 L_frame, - const Word16 lookahead, - const Word16 L_subfr, - Word16 *Aw, /* o : weighted A(z) filter coefficients */ - const Word16 gamma, /* i : weighting factor */ - const Word16 nb_subfr /* i : number of subframes */ + const Word16 Az[], /* i : A(z) filter coefficients */ + const Word16 speech[], /* i : pointer to the denoised speech frame */ + Word16 wsp[], /* o : poitnter to the weighted speech frame */ + Word16 *mem_wsp, /* i/o: W(Z) denominator memory */ + const Word16 preemph_fac, /* i : pre - emphasis factor Q15 */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 lookahead, /* i : look-ahead */ + const Word16 L_subfr, /* i : length of subframe */ + Word16 *Aw, /* o : weighted A(z) filter coefficients */ + const Word16 gamma, /* i : weighting factor */ + const Word16 nb_subfr /* i : number of subframes */ ) { Word16 i_subfr, wtmp; diff --git a/lib_enc/frame_spec_dif_cor_rate.c b/lib_enc/frame_spec_dif_cor_rate.c index a87186f..2327f51 100644 --- a/lib_enc/frame_spec_dif_cor_rate.c +++ b/lib_enc/frame_spec_dif_cor_rate.c @@ -3,20 +3,23 @@ ====================================================================================*/ -#include - +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" - - -void frame_spec_dif_cor_rate(T_CldfbVadState *st, /*(io) vad state*/ - Word32 *spec_amp, /*(i) spectral amplitude*/ - Word16 sacle, /*(i) the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /*(o) tonality rate*/ - ) +/*-------------------------------------------------------------------* + * frame_spec_dif_cor_rate() + * + * + *-------------------------------------------------------------------*/ +void frame_spec_dif_cor_rate( + VAD_CLDFB_HANDLE hVAD_CLDFB , /* i/o: CLDFB VAD state */ + Word32 *spec_amp, /* i : spectral amplitude*/ + Word16 sacle, /* i : the scaling of spec_amp*/ + Word16 f_tonality_rate[3] /* o : tonality rate*/ +) { Word32 i,tmp; @@ -26,7 +29,7 @@ void frame_spec_dif_cor_rate(T_CldfbVadState *st, /*(io) vad state*/ Word16 resu; Word16 scalefactor,spec_dif_cor_rate; Word32 m,dx,dy; - Word16 *pre_spec_low_dif = st->pre_spec_low_dif; + Word16 *pre_spec_low_dif = hVAD_CLDFB->pre_spec_low_dif; const Word32 FIX_cost1 = 2147484/* 0.001f Q31 */; @@ -70,7 +73,7 @@ void frame_spec_dif_cor_rate(T_CldfbVadState *st, /*(io) vad state*/ dx = L_mult0(round_fx(dx),round_fx(dy)); tmpq = add(sacle,scalefactor); tmpq = sub(tmpq,16); - tmpq2 = add(tmpq,st->scale_spec_low_dif); + tmpq2 = add(tmpq,hVAD_CLDFB->scale_spec_low_dif); *p_dx_Q = shl(tmpq2,1); move16(); *p_dx_Q = sub(*p_dx_Q ,32); @@ -105,7 +108,7 @@ void frame_spec_dif_cor_rate(T_CldfbVadState *st, /*(io) vad state*/ tmp = L_mac0(L_mult0(f_tonality_rate[2],29490/* 0.90 Q15 */), spec_dif_cor_rate,3277/* 0.1 Q15 */); f_tonality_rate[2] = shl(round_fx(tmp),1); move16(); - st->scale_spec_low_dif = tmpq; + hVAD_CLDFB->scale_spec_low_dif = tmpq; move16(); } diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index d287b53..b4bf1cc 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Local constants @@ -16,7 +15,7 @@ #define NB_QUA_GAIN7B 128 /* Number of quantization levels */ /*-------------------------------------------------------------------* - * Local functions + * Local function prototype *-------------------------------------------------------------------*/ static Word16 Find_Opt_gainQ_fx(Word16 *coeff, Word16 *exp_coeff, Word16 *gain_pit, Word32 *gain_code, @@ -48,14 +47,14 @@ static Word16 Find_Opt_gainQ_fx(Word16 *coeff, Word16 *exp_coeff, Word16 *gain_p /*==========================================================================*/ void Es_pred_enc_fx( - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8 */ - Word16 *indice, /* o : indice of quantization */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 *res, /* i : residual signal */ - const Word16 *voicing, /* i : normalized correlation in three 1/2frames */ - const Word16 nb_bits, /* i : allocated number of bits */ - const Word16 no_ltp, /* i : no_ltp flag */ - Word16 Q_new /* i : Scaling in speech Q0 */ + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8 */ + Word16 *indice, /* o : indice of quantization */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 *res, /* i : residual signal */ + const Word16 *voicing, /* i : normalized correlation in three 1/2frames */ + const Word16 nb_bits, /* i : allocated number of bits */ + const Word16 no_ltp, /* i : no_ltp flag */ + Word16 Q_new /* i : Scaling in speech Q0 */ ) { Word16 i, i_subfr,size, tmp16, tmp16_2, Q_res; @@ -159,7 +158,8 @@ void Es_pred_enc_fx( qua_table = Es_pred_qua_4b_no_ltp_fx; } - size = extract_l(pow2_fx[nb_bits]); /*maximum number of bit is 6 */ + /*size = extract_l(pow2_fx[nb_bits]); *//*maximum number of bit is 6 */ + size = shl(1,nb_bits); /*maximum number of bit is 6 */ /* find the nearest neighbour (codevector) */ *Es_pred = qua_table[0]; @@ -195,26 +195,25 @@ void Es_pred_enc_fx( * - the mean-squared weighted error criterion is used for codebook search *---------------------------------------------------------------------*/ void gain_enc_mless_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *xn, /* i : target vector */ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation */ - const Word16 Q_xn, /* i : xn and y1 scaling */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word16 Es_pred, /* i : predicted scaled innovation energy */ - Word16 *gain_pit, /* o : quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ - -) + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 element_mode, /* i : element mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 *xn, /* i : target vector */ + const Word16 *y1, /* i : zero-memory filtered adaptive excitation */ + const Word16 Q_xn, /* i : xn and y1 scaling */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 *code, /* i : algebraic excitation */ + const Word16 Es_pred, /* i : predicted scaled innovation energy */ + Word16 *gain_pit, /* o : quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ + Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ + ) { Word16 index, size, nBits, nBits2; @@ -309,21 +308,10 @@ void gain_enc_mless_fx( * select the codebook, size and number of bits * set the gains searching range *-----------------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) - { - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr)) ]; - move16(); - } - test(); - test(); - test(); - test(); - test(); + nBits = gains_mode[shr(i_subfr, 6)]; + move16(); + + test();test();test();test();test(); IF( (EQ_16(tc_subfr,3*L_SUBFR)&&EQ_16(i_subfr,3*L_SUBFR)&&EQ_16(L_frame,L_FRAME))|| (EQ_16(tc_subfr,4*L_SUBFR) && EQ_16(i_subfr,4*L_SUBFR) && EQ_16(L_frame,L_FRAME16k) ) ) { @@ -421,7 +409,7 @@ void gain_enc_mless_fx( tmp1 = mult_r(G_PITCH_MAX_MINUS_MIN_TC192_Q13,div_s(1,sub(shl(1, nBits), 1))); /*Q13*/ /* set quantization step */ index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_TC192_Q14, tmp1, shl(1, nBits) ); move16(); - push_indice_fx( st_fx, IND_GAIN_PIT, index, nBits ); + push_indice_fx( hBstr, IND_GAIN_PIT, index, nBits ); /* gain_code Q */ /**gain_code /= gcode0;*/ @@ -433,13 +421,13 @@ void gain_enc_mless_fx( } index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_TC192_Q14, LG10_G_CODE_MAX_TC192_Q13, nBits2, &expg ); - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits2 ); + push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits2 ); L_tmp = L_mult(gain_code16,gcode0); /*Q0*Q0 -> Q1*/ *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); /*Q16*/ } ELSE { - size = extract_l(pow2[nBits]); + size = shl(1,nBits); SWITCH ( nBits ) { @@ -447,28 +435,48 @@ void gain_enc_mless_fx( { qua_table = gain_qua_mless_7b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,30); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 30); + } BREAK; } case 6: { qua_table = gain_qua_mless_6b_fx; + if (GT_16(element_mode, EVS_MONO)) + { +#ifdef IVAS_CODE + qua_table = gain_qua_mless_6b_stereo; +#else + PMTE() +#endif + } move16(); - if ( EQ_16(clip_gain,1))size=sub(size,14); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 14); + } BREAK; } case 5: { qua_table = gain_qua_mless_5b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,6); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 6); + } BREAK; } default: { qua_table = gain_qua_mless_6b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,14); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 14); + } BREAK; } } @@ -485,7 +493,7 @@ void gain_enc_mless_fx( * search for the best quantizer *-----------------------------------------------------------------*/ index = Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, qua_table, size); - push_indice_fx( st_fx, IND_GAIN, index, nBits ); + push_indice_fx( hBstr, IND_GAIN, index, nBits ); } /* *norm_gain_code = *gain_code / *gain_inov; */ @@ -512,21 +520,19 @@ void gain_enc_mless_fx( *---------------------------------------------------------------------*/ void gain_enc_SQ_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ const Word16 *xn, /* i : target vector Q_xn */ const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ const Word16 *code, /* i : algebraic excitation Q9 */ const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ - Word16 *gain_pit, /* o : quantized pitch gain Q14 */ - Word32 *gain_code, /* o : quantized codebook gain Q16 */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ - Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ + Word16 *gain_pit, /* o : quantized pitch gain Q14 */ + Word32 *gain_code, /* o : quantized codebook gain Q16 */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ + Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ const Word16 Q_xn /* i : xn and y1 scaling */ ) @@ -738,7 +744,7 @@ void gain_enc_SQ_fx( * search for the best quantized values *-----------------------------------------------------------------*/ - nBits_pitch = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr)) ]; + nBits_pitch = gains_mode[shr(i_subfr,6)]; /* set number of bits for two SQs */ nBits_code = shr(add(nBits_pitch,1),1); @@ -750,7 +756,7 @@ void gain_enc_SQ_fx( index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_Q14, tmp1, shl(1, nBits_pitch) ); move16(); - push_indice_fx( st_fx, IND_GAIN_PIT, index, nBits_pitch ); + push_indice_fx( hBstr, IND_GAIN_PIT, index, nBits_pitch ); /* gain_code Q */ /* *gain_code /= gcode0; */ @@ -762,7 +768,7 @@ void gain_enc_SQ_fx( } index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_Q14, LG10_G_CODE_MAX_Q13, nBits_code, &expg ); - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits_code ); + push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits_code ); L_tmp = L_mult(gain_code16,gcode0); /*Q0*Q0 -> Q1*/ *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); move32(); /*Q16*/ @@ -840,20 +846,18 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ * - gain_code - scalar quantization (no prediciton history used) *-----------------------------------------------------------------*/ void gain_enc_tc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 xn_fx[], /* i : target vector */ - const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 code_fx[], /* i : algebraic excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ - Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ - Word32 *gain_code_fx, /* o : quantized codebook gain */ - Word16 *gain_inov_fx, /* o : innovation gain */ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ - const Word16 Q_xn /* i : xn and y1 scaling Q0 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 xn_fx[], /* i : target vector */ + const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 code_fx[], /* i : algebraic excitation */ + const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ + Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ + Word32 *gain_code_fx, /* o : quantized codebook gain */ + Word16 *gain_inov_fx, /* o : innovation gain */ + Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ + const Word16 Q_xn /* i : xn and y1 scaling Q0 */ ) { Word16 i, index=0, nBits, num, den, exp_num, exp_den; @@ -866,16 +870,7 @@ void gain_enc_tc_fx( /*----------------------------------------------------------------* * get number of bits for gain quantization *----------------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) - { - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - } + nBits = gains_mode[shr(i_subfr,6)]; /*----------------------------------------------------------------* * find the code pitch (for current subframe) @@ -969,7 +964,7 @@ void gain_enc_tc_fx( L_tmp = L_mult(gain_code16,gcode0_fx); /*Q0*Q0 -> Q1*/ *gain_code_fx = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); /*Q16*/ move32(); - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits ); + push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); } ELSE { @@ -1000,7 +995,7 @@ void gain_enc_tc_fx( L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); move32(); /* Q14 -> Q16 */ - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits ); + push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); } ELSE /* nBits == 3 */ { @@ -1010,7 +1005,7 @@ void gain_enc_tc_fx( L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); move32(); /* Q14 -> Q16 */ - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits ); + push_indice_fx( hBstr, IND_GAIN_CODE, index, nBits ); } } @@ -1178,23 +1173,24 @@ static Word16 Find_Opt_gainQ_fx( *---------------------------------------------------------------------*/ void gain_enc_lbr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *xn, /* i : target vector Q_xn*/ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 Q_xn, /* i : xn and y1 format */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - Word16 *gain_pit, /* o : quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits */ + const Word16 coder_type, /* i : coding type */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *xn, /* i : target vector Q_xn*/ + const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ + const Word16 Q_xn, /* i : xn and y1 format */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ + const Word16 *code, /* i : algebraic excitation Q9*/ + Word16 *gain_pit, /* o : quantized pitch gain Q14*/ + Word32 *gain_code, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ + Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ + Word32 gc_mem[], /* i/o: gain_code from previous subframes */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + const int16_t L_subfr /* i : subframe length */ ) { @@ -1202,9 +1198,16 @@ void gain_enc_lbr_fx( const Word16 *b, *cdbk = 0; Word16 gcode0, aux[10]; Word16 coeff[5], exp_coeff[5]; - Word16 exp, exp_code, exp_inov, exp_gcode0, frac, tmp; + Word16 exp, exp_code, exp_inov, exp_gcode0, frac, tmp, L_subfr_sf; Word32 L_tmp, L_tmp1, L_inov; + L_subfr_sf = 6; + move16(); + if (GT_16(L_subfr, L_SUBFR)) + { + L_subfr_sf = 7; + move16(); + } /*-----------------------------------------------------------------* * calculate the rest of the correlation coefficients * c2 = , c3 = -2, c4 = 2, c5* = @@ -1221,30 +1224,35 @@ void gain_enc_lbr_fx( move16(); /* Compute scalar product */ - - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); +#ifdef DEBUG + if (L_subfr != L_SUBFR) + { + PMT("Entire function needs review to accommode for L_subfr > L_SUBFR"); + } +#endif + coeff[2] = extract_h(Dot_product12(y2, y2, L_subfr, &exp)); exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); /* -18 (y2 Q9) */ move16(); /* Compute scalar product -2* */ - coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_SUBFR, &exp))); + coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_subfr, &exp))); exp_coeff[3] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 xn y2) */ move16(); /* Compute scalar product 2* */ - coeff[4] = extract_h(Dot_product12(y1, y2, L_SUBFR, &exp)); + coeff[4] = extract_h(Dot_product12(y1, y2, L_subfr, &exp)); exp_coeff[4] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 yy1 y2) */ move16(); /*g_corr[2] += 0.01F; g_corr[3] -= 0.02F; g_corr[4] += 0.02F;*/ /*Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; *gain_inov = 1.0f / (float)sqrt(Ecode);*/ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); + L_tmp = Dot_product12(code, code, L_subfr, &exp_code); L_inov = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); /* exp_code: -18 (code in Q9), -6 (/L_SUBFR), -31 (L_tmp Q31->Q0) */ /* output gain_inov*/ - exp_inov = sub(exp_code, 18 + 6); + exp_inov = sub(exp_code, add(18, L_subfr_sf)); L_inov = Isqrt_lc(L_inov, &exp_inov); *gain_inov = extract_h(L_shl(L_inov, sub(exp_inov, 3))); /* gain_inov in Q12 */ @@ -1254,9 +1262,9 @@ void gain_enc_lbr_fx( * set the gains searching range *-----------------------------------------------------------------*/ - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; + nBits = gains_mode[shr(i_subfr, L_subfr_sf)]; move16(); - size = extract_l(pow2[nBits]); + size = shl(1, nBits); ctype = shl(sub(coder_type, 1), 1); @@ -1277,7 +1285,10 @@ void gain_enc_lbr_fx( { cdbk = gp_gamma_1sfr_8b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,60); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 60); + } move16(); BREAK; } @@ -1285,7 +1296,10 @@ void gain_enc_lbr_fx( { cdbk = gp_gamma_1sfr_7b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,27); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 27); + } move16(); BREAK; } @@ -1293,7 +1307,10 @@ void gain_enc_lbr_fx( { cdbk = gp_gamma_1sfr_6b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,10); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 10); + } move16(); BREAK; } @@ -1341,7 +1358,7 @@ void gain_enc_lbr_fx( gp_mem[0] = *gain_pit; move16();/*Q14*/ } - ELSE IF (EQ_16(i_subfr,L_SUBFR)) + ELSE IF (EQ_16(i_subfr,L_SUBFR) || EQ_16(L_subfr, 2 * L_SUBFR)) { b = b_2sfr_fx; move16(); @@ -1354,7 +1371,10 @@ void gain_enc_lbr_fx( { cdbk = gp_gamma_2sfr_7b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,30); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 30); + } move16(); BREAK; } @@ -1362,7 +1382,10 @@ void gain_enc_lbr_fx( { cdbk = gp_gamma_2sfr_6b_fx; move16(); - if ( EQ_16(clip_gain,1))size=sub(size,12); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 12); + } move16(); BREAK; } @@ -1412,13 +1435,27 @@ void gain_enc_lbr_fx( move16(); n_pred = 6; move16(); - cdbk = gp_gamma_3sfr_6b_fx; - move16(); - if ( EQ_16(clip_gain,1)) + IF(EQ_16(nBits, 7)) { - size = sub(size,11); +#ifdef IVAS_CODE + cdbk = gp_gamma_3sfr_7b_fx; + if (clip_gain == 1) + { + size -= 28; + } +#else + PMT("gp_gamma_3sfr_7b_fx is missing") +#endif + } + ELSE + { + cdbk = gp_gamma_3sfr_6b_fx; + move16(); + if (EQ_16(clip_gain, 1)) + { + size = sub(size, 11); + } } - /* calculate predicted gain */ aux[0] = 4096; move16(); @@ -1500,15 +1537,28 @@ void gain_enc_lbr_fx( move16(); n_pred = 8; move16(); - - cdbk = gp_gamma_4sfr_6b_fx; - move16(); - if ( EQ_16(clip_gain,1)) + IF(EQ_16(nBits, 7)) + { +#ifdef IVAS_CODE + cdbk = gp_gamma_4sfr_7b_fx; + if (clip_gain == 1) + { + size -= 25; + } +#else + PMT("gp_gamma_4sfr_7b_fx is missing") +#endif + } + ELSE { - size = sub(size,11); + cdbk = gp_gamma_4sfr_6b_fx; move16(); + if (EQ_16(clip_gain,1)) + { + size = sub(size,11); + move16(); + } } - /* calculate predicted gain */ aux[0] = 4096; move16(); @@ -1571,7 +1621,7 @@ void gain_enc_lbr_fx( *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); move32(); { - push_indice_fx( st_fx, IND_GAIN, index, nBits ); + push_indice_fx( hBstr, IND_GAIN, index, nBits ); } return; } @@ -1589,20 +1639,20 @@ void gain_enc_lbr_fx( void gain_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 *xn, /* i : target vector */ - const Word16 Q_xn, /* i : xn and yy1 format Q0 */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *xn, /* i : target vector */ + const Word16 Q_xn, /* i : xn and yy1 format Q0 */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const Word16 *code, /* i : algebraic excitation */ + const Word32 core_brate, /* i : core bitrate */ + Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ + Word32 *gain_code, /* o : quantized codebook gain */ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ + Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ ) { @@ -1895,7 +1945,7 @@ void gain_enc_amr_wb_fx( *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); move32(); - push_indice_fx( st, IND_GAIN, index, nBits ); + push_indice_fx(hBstr, IND_GAIN, index, nBits ); return; } diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index a43f011..34e3e6d 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_enc_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_mpy.h" /*-------------------------------------------------------------------* @@ -24,7 +23,7 @@ static Word16 cod_2pos_fx( const Word16 ind1, const Word16 ind2, const Word16 sign1, const Word16 sign2, const Word16 n ); -static void gauss2v_fx( Encoder_State_fx *st_fx, const Word16 h[], const Word16 xn[], const Word16 dn[], Word16 code[], +static void gauss2v_fx(BSTR_ENC_HANDLE hBstr, const Word16 h[], const Word16 xn[], const Word16 dn[], Word16 code[], Word16 y1[], Word32 *gain, const Word16 lg, const Word16 shift, const Word16 Q_new, const Word16 nb_bits ); /*-------------------------------------------------------------------* @@ -37,31 +36,30 @@ static void gauss2v_fx( Encoder_State_fx *st_fx, const Word16 h[], const Word16 * - Updates *-------------------------------------------------------------------*/ Word16 gaus_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code, /* o : normalized innovative cb. gain Q16 */ - const Word32 core_brate /* i : core bitrate */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 *h1, /* i : weighted filter input response */ + const Word16 *xn, /* i : target vector */ + Word16 *exc, /* o : pointer to excitation signal frame */ + Word16 *mem_w0, /* o : weighting filter denominator memory */ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ + Word16 *code, /* o : algebraic excitation Q9 */ + Word32 *gain_code, /* o : Code gain. Q16 */ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ + Word16 *gain_inov, /* o : innovation gain Q12 */ + Word16 *voice_fac, /* o : voicing factor Q15 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ ) { Word16 nb_bits, idx; Word16 i=0; Word32 Ltmp; Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ - Word16 exp,tmp; + Word16 exp,tmp,tmp_idx; /*----------------------------------------------------------------* * Encode gaussian excitation @@ -70,9 +68,10 @@ Word16 gaus_encode_fx( /* Correlation between target xn2[] and impulse response h1[] */ corr_xh_fx(xn, dn, h1); - nb_bits = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX_fx(-1))]; + tmp_idx = shr(i_subfr, 6); + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; move16(); - gauss2v_fx(st_fx, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr(nb_bits,1)); + gauss2v_fx(st_fx->hBstr, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr(nb_bits,1)); /*----------------------------------------------------------------* * Encode gaussian gain @@ -85,10 +84,10 @@ Word16 gaus_encode_fx( Ltmp = Isqrt_lc(Ltmp, &exp_code); *gain_inov = extract_h(L_shl(Ltmp, sub(exp_code, 3))); /* g_code_inov in Q12 */ - nb_bits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX_fx(-1))]; + nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; move16(); /* low bound = -30; stepSize = 1.71875; inv_stepSize = 0.5818181 */ idx = gain_enc_gaus_fx(gain_code, nb_bits, -7680, 28160, 19065); - push_indice_fx( st_fx, IND_GAIN, idx, nb_bits ); + push_indice_fx( st_fx->hBstr, IND_GAIN, idx, nb_bits ); /*----------------------------------------------------------------* * Total excitation for Unvoiced coders @@ -135,17 +134,17 @@ Word16 gaus_encode_fx( * One Gaussian vector of 192 values vectors delayed by 2 *-------------------------------------------------------------------*/ void gauss2v_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 h[], /* i : weighted LP filter impulse response Q15 */ - const Word16 xn[], /* i : target signal Q12 */ - const Word16 dn[], /* i : backward filtered target Q12 */ - Word16 code[], /* o : gaussian excitation Q9 */ - Word16 y1[], /* o : zero-memory filtered gauss. excitation Q8 */ - Word32 *gain, /* o : excitation gain. 32-bit number in Q16 */ - const Word16 lg, /* i : subframe size Q0 */ - const Word16 shift, /* i : Scaling factor Q0 */ - const Word16 Q_new, /* i : Scaling factor Q0 */ - const Word16 nb_bits /* i : nb ob bits per track (max 6) */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + const Word16 h[], /* i : weighted LP filter impulse response Q15 */ + const Word16 xn[], /* i : target signal Q12 */ + const Word16 dn[], /* i : backward filtered target Q12 */ + Word16 code[], /* o : gaussian excitation Q9 */ + Word16 y1[], /* o : zero-memory filtered gauss. excitation Q8 */ + Word32 *gain, /* o : excitation gain. 32-bit number in Q16 */ + const Word16 lg, /* i : subframe size Q0 */ + const Word16 shift, /* i : Scaling factor Q0 */ + const Word16 Q_new, /* i : Scaling factor Q0 */ + const Word16 nb_bits /* i : nb ob bits per track (max 6) */ ) { Word16 i, j, ind1, ind2; @@ -156,7 +155,7 @@ void gauss2v_fx( Word32 enerw32,cor2w32; Word16 *cpt1; Word16 *pt1, *pt2; - Word32 max[NMAX+1]; + Word32 max_val[NMAX+1]; Word16 *pos[NMAX+1]; Word32 sign[NMAX+1]; Word32 ener[NMAX+1], corr[NMAX+1], ener1; @@ -306,7 +305,7 @@ void gauss2v_fx( * keep NMAX best vectors *----------------------------------------------------------------*/ - set32_fx(max, 0, NMAX+1); + set32_fx(max_val, 0, NMAX+1); set32_fx(sign, 0, NMAX+1); FOR (i = 0; i < NMAX+1; i++) @@ -327,15 +326,15 @@ void gauss2v_fx( DO { - IF (GE_32(cora, max[j])) + IF (GE_32(cora, max_val[j])) { - max[j+1] = max[j]; + max_val[j+1] = max_val[j]; move32(); /*Q31*/ pos[j+1] = pos[j]; move16(); /*Pointer*/ sign[j+1] = sign[j]; move32(); /*Q31*/ - max[j] = cora; + max_val[j] = cora; move32(); /*Q31*/ pos[j] = cpt1; move16(); /*Pointer*/ @@ -528,8 +527,8 @@ void gauss2v_fx( idx = cod_2pos_fx(i, j, sign1, sign2, nvec); move16(); - push_indice_fx( st_fx, IND_GAUS_CDBK_INDEX, idx, 2*nb_bits+1 ); - push_indice_fx( st_fx, IND_TILT_FACTOR, index_delta, 3 ); + push_indice_fx( hBstr, IND_GAUS_CDBK_INDEX, idx, 2*nb_bits+1 ); + push_indice_fx( hBstr, IND_TILT_FACTOR, index_delta, 3 ); /*----------------------------------------------------------------* * Find quantized gain @@ -596,12 +595,12 @@ void gauss2v_fx( /*---------------------------------------------------------------------* * Put selected codevector positions and signs into quantization index *---------------------------------------------------------------------*/ -static Word16 cod_2pos_fx( /* o : codebook quantization index */ - const Word16 ind1, /* i : index of 1st gaussian vector */ - const Word16 ind2, /* i : index of 2nd gaussian vector */ - const Word16 sign1, /* i : sign of 1st gaussian vector */ - const Word16 sign2, /* i : sign of 2nd gaussian vector */ - const Word16 n /* i : nb. of codebook vectors */ +static Word16 cod_2pos_fx(/* o : codebook quantization index */ + const Word16 ind1, /* i : index of 1st gaussian vector */ + const Word16 ind2, /* i : index of 2nd gaussian vector */ + const Word16 sign1, /* i : sign of 1st gaussian vector */ + const Word16 sign2, /* i : sign of 2nd gaussian vector */ + const Word16 n /* i : nb. of codebook vectors */ ) { Word16 i1, i2, index, s1, s2; diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index 8b7ec88..6ab0f67 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" -#include "stl.h" /*-------------------------------------------------------------------* * Local constants @@ -64,13 +64,14 @@ void init_gp_clip_fx( *-------------------------------------------------------------------*/ Word16 gp_clip_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Q_new /* i : scaling factor */ + const Word16 element_mode, /* i : element mode */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : type of coder */ + const Word16 xn[], /* i : target vector */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 Q_new /* i : scaling factor */ ) { Word16 clip; @@ -83,7 +84,8 @@ Word16 gp_clip_fx( clip = 0; move16(); test(); - IF( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) + test(); + IF( EQ_32(core_brate, ACELP_6k60) || EQ_32(core_brate, ACELP_8k85) || GT_16(element_mode, EVS_MONO) ) { thres = add(14746, mult(1638, extract_l(L_mult(mem[0], (Word16)(16384/DIST_ISF_MAX_IO))))); /* clipping is activated when filtered pitch gain > threshold (0.94 to 1 in Q14) */ test(); @@ -179,9 +181,10 @@ Word16 gp_clip_fx( *-------------------------------------------------------------------*/ void gp_clip_test_isf_fx( + const Word16 element_mode, /* i : element mode */ const Word32 core_brate, /* i : core bitrate */ const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ) { @@ -207,7 +210,8 @@ void gp_clip_test_isf_fx( dist = extract_h(L_mac(L_mult(26214, mem[0]), 6554, dist_min)); test(); - IF( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) + test(); + IF(EQ_32(core_brate, ACELP_6k60) || EQ_32(core_brate, ACELP_8k85) || GT_16(element_mode, EVS_MONO)) { dist = s_min(dist, DIST_ISF_MAX_IO); } @@ -228,16 +232,18 @@ void gp_clip_test_isf_fx( *-------------------------------------------------------------------*/ void gp_clip_test_gain_pit_fx( + const Word16 element_mode, /* i : element mode */ const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ + const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ ) { Word16 gain; Word32 L_tmp; test(); - IF( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) + test(); + IF(EQ_32(core_brate, ACELP_6k60) || EQ_32(core_brate, ACELP_8k85) || GT_16(element_mode, EVS_MONO)) { L_tmp = L_mult(32113, mem[1]); /* long term LTP gain average (>250ms) */ L_tmp = L_mac(L_tmp, 655, gain_pit); @@ -370,14 +376,22 @@ Word16 Mode2_gp_clip( * check the minimum distance of LSFs for pitch gain clipping flag *-------------------------------------------------------------------*/ void gp_clip_test_lsf_fx( - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 m /* i : dimension of lsf */ + const Word16 element_mode, /* i : element mode */ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 m /* i : dimension of lsf */ ) { Word16 i; - Word16 dist, dist_min; + Word16 dist, dist_min, dist_max; + dist_max = DIST_ISF_MAX; + move16(); + if (GT_16(element_mode, EVS_MONO)) + { + dist_max = DIST_ISF_MAX_IO; + move16(); + } dist_min = sub(lsf[1],lsf[0]); FOR (i=2; i #include "options.h" #include "cnst_fx.h" #include "rom_com_fx.h" #include "prot_fx.h" -#include "stl.h" /*-------------------------------------------------------------------* - * Local functions + * Local function prototypes *-------------------------------------------------------------------*/ static Word16 edyn_fx(const Word16 *vec, const Word16 lvec, Word16 Qnew); -static void gsc_enc_fx( Encoder_State_fx *st_fx, Word16 res_dct_in[],Word16 exc_dct_in[], - const Word16 Diff_len,const Word16 bits_used, const Word16 nb_subfr,const Word16 coder_type, - Word16 *lsf_new,Word16 *exc_wo_nf, Word16 *tmp_noise, Word16 Q_exc ); - /*-------------------------------------------------------------------* * encod_audio() * * Encode audio (AC) frames *-------------------------------------------------------------------*/ void encod_audio_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 T_op[], /* i : open loop pitch */ - const Word16 voicing[], /* i : voicing Q15 */ - const Word16 *res, /* i : residual signal Q_new */ - Word16 *synth, /* i/o: core synthesis Q-1 */ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ - const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* i : current frame ISF vector */ + Encoder_State_fx *st_fx, /* i/o: State structure */ + const Word16 speech[], /* i : input speech Q_new */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, /* i : residual signal Q_new */ + Word16 *synth, /* i/o: core synthesis Q-1 */ + Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ + const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ + Word16 *lsf_new, /* i : current frame ISF vector */ Word16 *tmp_noise, /* o : noise energy */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, Word16 shift ) @@ -50,13 +43,17 @@ void encod_audio_fx( Word16 T0_tmp, T0_frac_tmp, nb_subfr_flag; Word16 tmp_nb_bits_tot = 0; Word16 Es_pred; - Word16 dct_res[L_FRAME], dct_epit[L_FRAME]; + Word16 dct_res[L_FRAME16k], dct_epit[L_FRAME16k]; Word16 m_mean = 0; Word16 saved_bit_pos; - Word16 exc_wo_nf[L_FRAME]; + Word16 exc_wo_nf[L_FRAME16k]; Word32 Lm_mean; Word16 nb_bits; Word16 indice; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; m_mean = 0; move16(); @@ -67,59 +64,92 @@ void encod_audio_fx( move16(); T0_frac_tmp = 0; move16(); - Copy(mem->mem_syn, st_fx->mem_syn_tmp_fx, M); - st_fx->mem_w0_tmp_fx = mem->mem_w0; + Copy(hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M); + hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; move16(); Es_pred = 0; move16(); /*---------------------------------------------------------------* + * Encode GSC IVAS mode * Encode GSC attack flag (used to reduce possible pre-echo) * Encode GSC SWB speech flag *---------------------------------------------------------------*/ - push_indice_fx( st_fx, IND_GSC_ATTACK, attack_flag, 1 ); - +#ifdef GSC_IVAS // TVB -->>>>>> test(); - IF( NE_16(coder_type,INACTIVE )&&GE_32(st_fx->total_brate_fx,ACELP_13k20)) + if (GT_16( st_fx->element_mode, EVS_MONO) && st_fx->idchan == 0) + { + push_indice_fx(hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2); + } +#endif + IF (attack_flag > 0) + { + push_indice_fx(hBstr, IND_GSC_ATTACK, 1, 1); + } + ELSE + { + push_indice_fx(hBstr, IND_GSC_ATTACK, 0, 1); + } + + + test(); test(); test(); + test();test();test(); + IF (GE_16(st_fx->GSC_IVAS_mode, 1) || (NE_16(st_fx->coder_type, INACTIVE) && ((EQ_16(st_fx->element_mode, EVS_MONO) && GE_32(st_fx->total_brate_fx, ACELP_13k20)) || + (GT_16(st_fx->element_mode, EVS_MONO) && GT_32(st_fx->total_brate_fx, MIN_BRATE_GSC_NOISY_FLAG) && GE_16(st_fx->bwidth_fx, SWB) && !st_fx->flag_ACELP16k)))) { - push_indice_fx( st_fx,IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech_fx, 1); + push_indice_fx(hBstr,IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech_fx, 1); } /*---------------------------------------------------------------* * Find and encode the number of subframes *---------------------------------------------------------------*/ test(); - IF ( GE_32(st_fx->core_brate_fx,ACELP_9k60)&&LE_32(st_fx->core_brate_fx,ACELP_13k20)) + IF ( GE_32(st_fx->core_brate_fx,ACELP_9k60) && LE_32(st_fx->core_brate_fx,ACELP_13k20)) { FOR( i = 0; i < 5; i++) { test(); - if( GT_16(abs_s(st_fx->gsc_lt_diff_etot_fx[MAX_LT-i-1]),1536)&&EQ_16(st_fx->cor_strong_limit_fx,1)) + if( GT_16(abs_s(hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-i-1]),1536)&&EQ_16(hGSCEnc->cor_strong_limit_fx,1)) { - st_fx->cor_strong_limit_fx = 0; + hGSCEnc->cor_strong_limit_fx = 0; move16(); } } } - IF( st_fx->GSC_noisy_speech_fx ) + test(); + IF(GE_16(st_fx->GSC_IVAS_mode, 1) || (st_fx->GSC_noisy_speech_fx && st_fx->GSC_IVAS_mode == 0)) { nb_subfr = NB_SUBFR; move16(); - st_fx->cor_strong_limit_fx = 0; + test();test(); + if (st_fx->GSC_IVAS_mode > 0 && LT_16(st_fx->GSC_IVAS_mode, 3) && LT_32(st_fx->core_brate_fx, GSC_L_RATE_STG)) + { + nb_subfr = 2; + move16(); + } + hGSCEnc->cor_strong_limit_fx = 0; move16(); nb_subfr_flag = 1; move16(); } + ELSE IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k) && (LE_32(st_fx->core_brate_fx, ACELP_13k20) || EQ_16(st_fx->coder_type, INACTIVE))) + { + hGSCEnc->cor_strong_limit_fx = 0; + nb_subfr = SWNB_SUBFR; + nb_subfr_flag = 1; + move16();move16();move16(); + + } ELSE { test(); test(); - IF( (st_fx->cor_strong_limit_fx == 0 || EQ_16(coder_type,INACTIVE))&&GE_32(st_fx->core_brate_fx,ACELP_9k60)) + IF( (hGSCEnc->cor_strong_limit_fx == 0 || EQ_16(st_fx->coder_type,INACTIVE)) && GE_32(st_fx->core_brate_fx,ACELP_9k60)) { nb_subfr = 2; move16(); nb_subfr_flag = 0; move16(); - st_fx->cor_strong_limit_fx = 0; + hGSCEnc->cor_strong_limit_fx = 0; move16(); } ELSE @@ -129,35 +159,59 @@ void encod_audio_fx( nb_subfr_flag = 1; move16(); } - IF( GE_32(st_fx->core_brate_fx,ACELP_9k60)) + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k) && (GT_16(hSpMusClas->mold_corr_fx, 26214) && GE_32(st_fx->core_brate_fx, MIN_RATE_4SBFR) && NE_16(st_fx->coder_type, INACTIVE))) + { + nb_subfr = shl(nb_subfr, 1); + nb_subfr_flag |= 0x2; logic16(); + } + + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k) && GE_32(st_fx->core_brate_fx, MIN_RATE_4SBFR)) + { + push_indice_fx(hBstr, IND_HF_NOISE, nb_subfr_flag, 2); + } + ELSE IF( GE_32(st_fx->core_brate_fx,ACELP_9k60)) { /* nb_subfr_flag can only have the value 0 or 1 */ - push_indice_fx( st_fx, IND_HF_NOISE, nb_subfr_flag, 1); + push_indice_fx(hBstr, IND_HF_NOISE, nb_subfr_flag, 1); } } + test(); + if (EQ_16(st_fx->L_frame_fx, L_FRAME16k) && EQ_16(nb_subfr, NB_SUBFR)) + { + nb_subfr = NB_SUBFR16k; + move16(); + } /*---------------------------------------------------------------* * Compute adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ test(); - IF( st_fx->GSC_noisy_speech_fx && EQ_16(nb_subfr,NB_SUBFR )) + IF (!(st_fx->GSC_IVAS_mode > 0 && EQ_16(st_fx->L_frame_fx, i_mult(nb_subfr, 2 * L_SUBFR)) && LT_16(st_fx->GSC_IVAS_mode, 3)) && + ((GE_32(st_fx->core_brate_fx, MIN_RATE_FCB) || st_fx->GSC_noisy_speech_fx) && + ((EQ_16(nb_subfr, NB_SUBFR) && EQ_16(st_fx->L_frame_fx, L_FRAME)) || (EQ_16(nb_subfr, NB_SUBFR16k) && EQ_16(st_fx->L_frame_fx, L_FRAME16k))))) { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, GENERIC, -1, -1)]; - move16(); - Es_pred_enc_fx( &Es_pred, &indice, L_FRAME, res, voicing, nb_bits,0, Q_new - ); - push_indice_fx( st_fx, IND_ES_PRED, indice, nb_bits ); + IF (GT_16(st_fx->element_mode, EVS_MONO)) + { + nb_bits = 5; + } + ELSE + { + nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, GENERIC, -1, -1)]; + move16(); + } + Es_pred_enc_fx(&Es_pred, &indice, st_fx->L_frame_fx, res, st_fx->voicing_fx, nb_bits, 0, Q_new); + push_indice_fx(hBstr, IND_ES_PRED, indice, nb_bits ); } - enc_pit_exc_fx( st_fx, mem, speech, Aw, Aq,Es_pred, T_op, voicing, res, synth, exc, &T0_tmp, - &T0_frac_tmp, pitch_buf, nb_subfr, &st_fx->lt_gpitch_fx, &saved_bit_pos, Q_new, shift ); + enc_pit_exc_fx( st_fx, speech, Aw, Aq,Es_pred, res, synth, exc, &T0_tmp, + &T0_frac_tmp, pitch_buf, nb_subfr, &hGSCEnc->lt_gpitch_fx, &saved_bit_pos, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, L_FRAME, 7 ); - edct_16fx( res, dct_res, L_FRAME, 7 ); + edct_16fx( exc, dct_epit, st_fx->L_frame_fx, 7, st_fx->element_mode); + edct_16fx( res, dct_res, st_fx->L_frame_fx, 7, st_fx->element_mode); /*---------------------------------------------------------------* * Calculate energy dynamics *---------------------------------------------------------------*/ @@ -169,49 +223,63 @@ void encod_audio_fx( } m_mean = round_fx(Lm_mean);/*Q7*/ - IF( GT_16(m_mean,st_fx->mid_dyn_fx)) + IF( GT_16(m_mean, hGSCEnc->mid_dyn_fx)) { /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ - st_fx->mid_dyn_fx = round_fx(L_mac(L_mult(26214,m_mean),6554,st_fx->mid_dyn_fx));/*Q7*/ + hGSCEnc->mid_dyn_fx = round_fx(L_mac(L_mult(26214,m_mean),6554, hGSCEnc->mid_dyn_fx));/*Q7*/ } ELSE { /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ - st_fx->mid_dyn_fx = round_fx(L_mac(L_mult(13107,m_mean),19661,st_fx->mid_dyn_fx));/*Q7*/ + hGSCEnc->mid_dyn_fx = round_fx(L_mac(L_mult(13107,m_mean),19661,hGSCEnc->mid_dyn_fx));/*Q7*/ } - IF( NE_16(coder_type,INACTIVE)) + IF( NE_16(st_fx->coder_type,INACTIVE)) { - st_fx->noise_lev_fx = sub((NOISE_LEVEL_SP3+1), usquant_fx(st_fx->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr(GSF_NF_DELTA_FX,1), GSC_NF_STEPS)); + hGSCEnc->noise_lev_fx = sub((NOISE_LEVEL_SP3+1), usquant_fx(hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr(GSF_NF_DELTA_FX,1), GSC_NF_STEPS)); - st_fx->noise_lev_fx = s_min(st_fx->noise_lev_fx, NOISE_LEVEL_SP3); + hGSCEnc->noise_lev_fx = s_min(hGSCEnc->noise_lev_fx, NOISE_LEVEL_SP3); } - st_fx->past_dyn_dec_fx = st_fx->noise_lev_fx; + hGSCEnc->past_dyn_dec_fx = hGSCEnc->noise_lev_fx; move16(); - IF( LE_32(st_fx->core_brate_fx,ACELP_8k00)) + IF (GE_16(st_fx->GSC_IVAS_mode, 1)) + { + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP2; + IF (EQ_16(st_fx->GSC_IVAS_mode, 3) ) /* Music like */ + { + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP0; + move16(); + } + ELSE IF (st_fx->GSC_noisy_speech_fx == 0) + { + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP3; + move16(); + } + } + ELSE IF( LE_32(st_fx->core_brate_fx,ACELP_8k00)) { - st_fx->noise_lev_fx = s_max(st_fx->noise_lev_fx, NOISE_LEVEL_SP2); - push_indice_fx( st_fx, IND_NOISE_LEVEL, sub(st_fx->noise_lev_fx, NOISE_LEVEL_SP2), 2 ); + hGSCEnc->noise_lev_fx = s_max(hGSCEnc->noise_lev_fx, NOISE_LEVEL_SP2); + push_indice_fx(hBstr, IND_NOISE_LEVEL, sub(hGSCEnc->noise_lev_fx, NOISE_LEVEL_SP2), 2 ); } ELSE IF( st_fx->GSC_noisy_speech_fx ) { - st_fx->noise_lev_fx = NOISE_LEVEL_SP3; + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP3; move16(); } ELSE { - push_indice_fx( st_fx, IND_NOISE_LEVEL, sub(st_fx->noise_lev_fx, NOISE_LEVEL_SP0), 3 ); + push_indice_fx(hBstr, IND_NOISE_LEVEL, sub(hGSCEnc->noise_lev_fx, NOISE_LEVEL_SP0), 3 ); } /*---------------------------------------------------------------* * Find and encode the last band where the adaptive (pitch) contribution is significant *---------------------------------------------------------------*/ - last_pit_bin = Pit_exc_contribution_len_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &st_fx->pit_exc_hangover, coder_type, Q_new ); + last_pit_bin = Pit_exc_contribution_len_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &hGSCEnc->pit_exc_hangover, Q_new ); IF( last_pit_bin == 0 ) { - mem->tilt_code = 0; + hLPDmem->tilt_code = 0; move16(); } ELSE @@ -225,7 +293,7 @@ void encod_audio_fx( *--------------------------------------------------------------------------------------*/ /* Find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->nb_bits_tot_fx; + tmp_nb_bits_tot = hBstr->nb_bits_tot_fx; move16(); @@ -234,44 +302,51 @@ void encod_audio_fx( /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ tmp_nb_bits_tot = sub(tmp_nb_bits_tot,1); } - test(); - if( EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_9k60)) + test(); test(); + if( EQ_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate_fx,ACELP_9k60) && st_fx->idchan == 0) { /* add 5 bits for noisiness */ tmp_nb_bits_tot = add(tmp_nb_bits_tot,5); } - gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, coder_type, lsf_new, exc_wo_nf, tmp_noise, Q_new ); + gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, Q_new ); /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ - edct_16fx( dct_epit, exc, L_FRAME, 7 ); - edct_16fx( exc_wo_nf, exc_wo_nf, L_FRAME, 7 ); + edct_16fx( dct_epit, exc, st_fx->L_frame_fx , 7, st_fx->element_mode); + edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame_fx , 7, st_fx->element_mode); /*--------------------------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ - pre_echo_att_fx( &st_fx->Last_frame_ener_fx, exc, attack_flag, Q_new - ,st_fx->last_coder_type_fx - ); + pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type_fx, st_fx->L_frame_fx); /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ - - set16_fx( voice_factors, 0, NB_SUBFR ); - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - + IF (st_fx->hBWE_TD != NULL) + { + IF (EQ_16(st_fx->L_frame_fx, L_FRAME16k)) + { + set16_fx(voice_factors, 0, NB_SUBFR16k); + interp_code_4over2_fx(exc, bwe_exc, L_FRAME16k); + } + ELSE + { + set16_fx(voice_factors, 0, NB_SUBFR); + interp_code_5over2_fx(exc, bwe_exc, L_FRAME); + } + } /*--------------------------------------------------------------------------------------* * Synthesis *--------------------------------------------------------------------------------------*/ p_Aq = Aq; - FOR (i_subfr=0; i_subfrL_frame_fx; i_subfr+=L_SUBFR) { - Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); p_Aq += (M+1); } @@ -279,9 +354,9 @@ void encod_audio_fx( * Updates *--------------------------------------------------------------------------------------*/ - mem->mem_w0 = st_fx->mem_w0_tmp_fx; + hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; /*_DIFF_FLOAT_FIX_ The way it is written in the original fix point is that at this point mem_w0 falls back to its original value (before enc_pit_exc, seems not the case in float */ move16(); - Copy( exc_wo_nf, exc, L_FRAME ); + Copy( exc_wo_nf, exc, st_fx->L_frame_fx); return; } @@ -311,40 +386,45 @@ void encod_audio_fx( /*================================================================================*/ -static void gsc_enc_fx( +void gsc_enc_fx( Encoder_State_fx *st_fx, /* i/o: State structure */ Word16 res_dct_in[], /* i : dct of residual signal */ Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - const Word16 coder_type, Word16 *lsf_new, /* i : ISFs at the end of the frame */ Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ Word16 *tmp_noise, /* o : noise energy */ Word16 Q_exc ) { - Word16 y2_filt[L_FRAME]; - Word16 exc_diffQ[L_FRAME]; - Word16 exc_diff[L_FRAME]; + Word16 y2_filt[L_FRAME16k]; + Word16 exc_diffQ[L_FRAME16k]; + Word16 exc_diff[L_FRAME16k]; Word16 bit,tmp; Word16 nb_subbands; Word16 pvq_len, i; - Word16 bits_per_bands[MBANDS_GN]; + Word16 bits_per_bands[MBANDS_GN_BITALLOC16k]; Word16 tmp_band; - Word16 concat_in[L_FRAME]; - Word16 concat_out[L_FRAME]; - Word16 max_ener_band[MBANDS_GN], j; - Word16 Ener_per_bd_iQ[MBANDS_GN]; + Word16 concat_in[L_FRAME16k]; + Word16 concat_out[L_FRAME16k]; + Word16 max_ener_band[MBANDS_GN_BITALLOC16k], j; + Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; Word16 last_bin, mean_gain; - Word16 bitallocation_band[MBANDS_GN]; + Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; Word16 bitallocation_exc[2]; Word16 inpulses_fx[NB_SFM]; Word16 imaxpulse_fx[NB_SFM]; Word16 Q_tmp; Word16 seed_init; +#ifdef ADD_LRTD + Word16 max_eq_val; + Word32 max_eq; +#endif + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; set16_fx( inpulses_fx, 0, NB_SFM ); set16_fx( imaxpulse_fx, 0, NB_SFM ); @@ -354,16 +434,21 @@ static void gsc_enc_fx( *--------------------------------------------------------------------------------------*/ bit = bits_used; + test();test();test(); + if (EQ_16(st_fx->coder_type, INACTIVE) && (EQ_16(st_fx->tdm_LRTD_flag, 1) || EQ_16(st_fx->element_mode, IVAS_SCE)) && LE_32(st_fx->core_brate_fx, GSC_LRES_GAINQ_LIMIT)) + { + bit = add(bit, GSC_LRES_NB_NITS); + } move16(); - set16_fx( exc_diffQ, 0, L_FRAME ); - set16_fx( y2_filt, 0, L_FRAME ); + set16_fx( exc_diffQ, 0, st_fx->L_frame_fx ); + set16_fx( y2_filt, 0, st_fx->L_frame_fx ); /*--------------------------------------------------------------------------------------* * Calculate the difference between the residual spectrum and the spectrum of adaptive excitation * (non valuable temporal content present in exc_dct_in is already zeroed) *--------------------------------------------------------------------------------------*/ - Vr_subt( res_dct_in, exc_dct_in, exc_diff, L_FRAME ); + Vr_subt( res_dct_in, exc_dct_in, exc_diff, st_fx->L_frame_fx ); exc_diff[0] = 0; move16(); @@ -379,39 +464,64 @@ static void gsc_enc_fx( } ELSE { - tmp_band = st_fx->mem_last_pit_band_fx; + tmp_band = hGSCEnc->mem_last_pit_band_fx; move16(); } - Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1 ); + Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1/*, st_fx->L_frame_fx IVAS_CODE*/ ); /*--------------------------------------------------------------------------------------* * Gain quantizaion *--------------------------------------------------------------------------------------*/ +#if 0 + mean_gain = gsc_gainQ_fx(hBstr, Ener_per_bd_iQ, Ener_per_bd_iQ, st_fx->core_brate_fx, st_fx->coder_type, st_fx->bwidth_fx ); +#else + i = 0; move16(); + WHILE (LT_16(i, SIZE_BRATE_INTERMED_TBL)) + { + IF (LE_32(st_fx->core_brate_fx, brate_intermed_tbl[i])) + { + break; + } + i++; + } + if (GT_16(st_fx->element_mode, EVS_MONO) && EQ_16(st_fx->coder_type, AUDIO) && + LE_32(st_fx->core_brate_fx, STEREO_GSC_BIT_RATE_ALLOC) && EQ_32(brate_intermed_tbl[i], ACELP_9k60)) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + { + i--; + } + + mean_gain = gsc_gainQ_fx(hBstr, /*st_fX->element_mode, st_fx->idchan,IVAS_CODE*/ Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth_fx/*, st_fx->L_frame_fx, st_fx->tdm_LRTD_flag, st_fx->core_brate_fx*/); - mean_gain = gsc_gainQ_fx( st_fx, Ener_per_bd_iQ, Ener_per_bd_iQ, st_fx->core_brate_fx, coder_type, st_fx->bwidth_fx ); +#endif *tmp_noise = mult_r(320,mean_gain); /*10 in Q5 lp_gainc in Q3 */ /*--------------------------------------------------------------------------------------* * Frequency encoder *--------------------------------------------------------------------------------------*/ - bands_and_bit_alloc_fx( st_fx->cor_strong_limit_fx, st_fx->noise_lev_fx, st_fx->core_brate_fx, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, coder_type, st_fx->bwidth_fx, st_fx->GSC_noisy_speech_fx ); + bands_and_bit_alloc_fx(hGSCEnc->cor_strong_limit_fx, hGSCEnc->noise_lev_fx, st_fx->core_brate_fx, Diff_len, bit, &bit, Ener_per_bd_iQ, + max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, st_fx->coder_type, st_fx->bwidth_fx, + st_fx->GSC_noisy_speech_fx, st_fx->L_frame_fx, st_fx->element_mode, st_fx->GSC_IVAS_mode); Q_tmp = Q_exc; move16(); - - tmp = pvq_core_enc_fx( st_fx, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, - gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands-1], sub(Q_PVQ_OUT, Q_tmp) ); - - bit = sub(bit,tmp); + IF (bit == 0) + { + set16_fx(concat_out, 0, L_FRAME16k); + } + ELSE + { + tmp = pvq_core_enc_fx(hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, + gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE); + Scale_sig(concat_out, gsc_sfm_end[nb_subbands - 1], sub(Q_PVQ_OUT, Q_tmp)); + bit = sub(bit, tmp); + } /* write unused bits */ WHILE( bit > 0 ) { i = s_min( bit, 16 ); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); + push_indice_fx(hBstr, IND_UNUSED, 0, i ); bit = sub(bit,i); } /* Reorder Q bands */ @@ -419,7 +529,19 @@ static void gsc_enc_fx( move16(); last_bin = 0; move16(); - set16_fx( bitallocation_band, 0, MBANDS_GN ); + set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k); + +#ifdef ADD_LRTD + max_eq = 0; + max_eq_val = 1.0f; + + IF ((((LT_32(st_fx->core_brate_fx, ACELP_7k20) && EQ_16(st_fx->GSC_noisy_speech_fx, 1)) || LT_32(st_fx->core_brate_fx, 6000)) && LE_16(st_fx->coder_type, UNVOICED)) || GE_16(st_fx->GSC_IVAS_mode, 1)) + { + j = emaximum(concat_out, nb_subbands * 16, &max_eq); + max_eq = max_eq_val / (fabsf(concat_out[j]) + 0.01f); + max_eq = min(max_eq_val, max_eq); + } +#endif FOR(j = 0; j < nb_subbands; j++) { @@ -449,7 +571,7 @@ static void gsc_enc_fx( move16(); } } - st_fx->seed_tcx_fx = seed_init; + hGSCEnc->seed_tcx_fx = seed_init; move16(); } test(); @@ -476,17 +598,35 @@ static void gsc_enc_fx( * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ - - freq_dnw_scaling_fx( st_fx->cor_strong_limit_fx, coder_type, st_fx->noise_lev_fx, st_fx->core_brate_fx, exc_diffQ, Q_PVQ_OUT ); - +#ifdef ADD_LRTD + test();test();test(); + IF (GE_16(st_fx->GSC_IVAS_mode, 1) && EQ_16(st_fx->GSC_noisy_speech_fx, 1)) + { + FOR (i = 64; i < st->L_frame; i++) + { + exc_diffQ[i] *= max_eq; + } + } + ELSE IF (LT_32(st_fx->core_brate_fx, ACELP_7k20) && EQ_16(st_fx->GSC_noisy_speech_fx, 1) && LE_16(st_fx->coder_type, UNVOICED)) + { + FOR (i = 0; i < L_FRAME; i++) + { + exc_diffQ[i] *= max_eq; + } + } + else +#endif + { + freq_dnw_scaling_fx(hGSCEnc->cor_strong_limit_fx, st_fx->coder_type, hGSCEnc->noise_lev_fx, st_fx->core_brate_fx, exc_diffQ, Q_PVQ_OUT, st_fx->L_frame_fx); + } /*--------------------------------------------------------------------------------------* * Estimate noise level *--------------------------------------------------------------------------------------*/ - highband_exc_dct_in_fx( st_fx->core_brate_fx, mfreq_bindiv_loc_fx, last_bin, Diff_len, st_fx->noise_lev_fx, tmp_band, exc_diffQ, - &st_fx->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type_fx, bitallocation_band, lsf_new, - st_fx->last_exc_dct_in_fx, &st_fx->last_ener_fx, st_fx->last_bitallocation_band_fx, bitallocation_exc, 0, coder_type, - st_fx->bwidth_fx, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech_fx, NULL ); + highband_exc_dct_in_fx( st_fx->core_brate_fx, mfreq_bindiv_loc_fx, last_bin, Diff_len, hGSCEnc->noise_lev_fx, tmp_band, exc_diffQ, + &hGSCEnc->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type_fx, bitallocation_band, lsf_new, + hGSCEnc->last_exc_dct_in_fx, &st_fx->last_ener_fx, hGSCEnc->last_bitallocation_band_fx, bitallocation_exc, 0, st_fx->coder_type, + st_fx->bwidth_fx, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech_fx, NULL, st_fx->L_frame_fx, st_fx->element_mode, st_fx->GSC_IVAS_mode); exc_dct_in[0] = 0; move16(); @@ -568,3 +708,47 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ return dyn; } + + +/*-------------------------------------------------------------------* + * GSC_enc_init() + * + * Initialize GSC encoder state structure + *-------------------------------------------------------------------*/ + +void GSC_enc_init( + GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */ +) +{ + /* AC mode */ + hGSCEnc->seed_tcx_fx = 15687; + move16(); + hGSCEnc->cor_strong_limit_fx = 1; + move16(); + set16_fx(hGSCEnc->last_exc_dct_in_fx, 0, L_FRAME16k); + //hGSCEnc->last_ener = 0.0f; IVAS_CODE + set16_fx(hGSCEnc->last_bitallocation_band_fx, 0, 6); + + hGSCEnc->mem_last_pit_band_fx = BAND1k2 + 1; + hGSCEnc->Last_frame_ener_fx = MAX_32; + move32(); + hGSCEnc->lt_gpitch_fx = 0; + move16(); + move16(); + hGSCEnc->pit_exc_hangover = 0; + move16(); + + hGSCEnc->mem_w0_tmp_fx = 0; + move16(); + + set16_fx(hGSCEnc->mem_syn_tmp_fx, 0, M); + hGSCEnc->mid_dyn_fx = 5120; + move16(); /*40 -> Q7 */ + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP0; + move16(); + hGSCEnc->past_dyn_dec_fx = 0; + move16(); + + + return; +} diff --git a/lib_enc/gs_enc_fx.test.c b/lib_enc/gs_enc_fx.test.c new file mode 100644 index 0000000..e69de29 diff --git a/lib_enc/guided_plc_enc.c b/lib_enc/guided_plc_enc.c index d085715..d9ffba4 100644 --- a/lib_enc/guided_plc_enc.c +++ b/lib_enc/guided_plc_enc.c @@ -3,20 +3,22 @@ ====================================================================================*/ -#include "stl.h" +#include +#include "options.h" #include "prot_fx.h" -#include "stat_dec_fx.h" +#include "stat_enc_fx.h" #include "basop_util.h" -/************************************************************/ -/* Macro for the functions to be implemented. */ -/************************************************************/ - +/*-------------------------------------------------------------------* + * coderLookAheadInnovation() + * + * + *-------------------------------------------------------------------*/ void coderLookAheadInnovation( Word16 A_3Q12[], /* input: coefficients NxAz[M+1] */ Word16 *pT, /* out: pitch */ - HANDLE_PLC_ENC_EVS st, /* i/o: coder memory state */ + PLC_ENC_EVS_HANDLE st, /* i/o: coder memory state */ Word16 *speechLookAhead_Qx, /* i: input speech in Q(st->Qold) */ Word16 *old_exc, /* i: input excitation in Q(st->Qold) */ Word16 L_frame @@ -38,6 +40,7 @@ void coderLookAheadInnovation( Word16 max_ps_e; Word16 tmp_loop; + /* Debug init (not instrumented) */ T0_fx = -3000; subfr_len = shl(L_SUBFR,1); /* 2*L_SUBFR */ @@ -45,6 +48,7 @@ void coderLookAheadInnovation( { subfr_len = add(L_SUBFR,48); /* 1.75*L_SUBFR */ } + set16_fx(exc_buf_Qx, 0, L_EXC_MEM + 2 * L_SUBFR + 8); /*------------------------------------------------------------------------* * - BASOP specific initialization. * @@ -108,10 +112,6 @@ void coderLookAheadInnovation( move16(); } - - - - /*Calculate "big" dotproduct from buffer, including search range*/ alp_ini = L_deposit_l(0); move16(); @@ -120,7 +120,6 @@ void coderLookAheadInnovation( alp_ini = L_mac(alp_ini,exc_Qx[i],exc_Qx[i]); } - FOR( i=-search_range; inBits,1)) { - push_next_indice_fx(st, 1, 1); + push_next_indice_fx(st->hBstr, 1, 1); diff_pitch = sub(hPlc_Ext->T0, hPlc_Ext->T0_4th); test(); @@ -211,25 +218,27 @@ void enc_prm_side_Info( HANDLE_PLC_ENC_EVS hPlc_Ext, Encoder_State_fx *st ) move16(); } - push_next_indice_fx(st, add(diff_pitch, search_range), bits_per_subfr); + push_next_indice_fx(st->hBstr, add(diff_pitch, search_range), bits_per_subfr); } ELSE { - push_next_indice_fx(st, 0, 1); + push_next_indice_fx(st->hBstr, 0, 1); } return; } -/************************************************************/ -/* Functions for encoder side loss simulation */ -/************************************************************/ +/*-------------------------------------------------------------------* + * encoderSideLossSimulation() + * + * Encoder side loss simulation + *-------------------------------------------------------------------*/ void encoderSideLossSimulation( Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, + PLC_ENC_EVS_HANDLE hPlc_Ext, Word16 *lsf_q, /* Q1*1.28 */ - Word16 stab_fac, /* Q15 */ - Word8 calcOnlyISF, + const Word16 stab_fac, /* Q15 */ + const Word8 calcOnlyISF, const Word16 L_frame ) { @@ -237,11 +246,6 @@ void encoderSideLossSimulation( Word16 const* xsfBase; /* base for differential XSF coding */ - /************************************************************* - * Decoder state could be stored with memcpy, - * since Decoder_State does not contain pointer member. - *************************************************************/ - /* Decoder State Update */ IF( EQ_16(L_frame,L_FRAME_16k)) { @@ -262,7 +266,7 @@ void encoderSideLossSimulation( /* ISF parameter processing for concealment */ - updateLSFForConcealment( hPlc_Ext, lsf_q, M ); + updateLSFForConcealment( hPlc_Ext, lsf_q); hPlc_Ext->stab_fac_Q15 = stab_fac; move16(); @@ -303,10 +307,21 @@ void encoderSideLossSimulation( return; } +/*-------------------------------------------------------------------* + * GplcTcxEncSetup() + * + * + *-------------------------------------------------------------------*/ -void GplcTcxEncSetup( Encoder_State_fx *st, HANDLE_PLC_ENC_EVS hPlc_Ext, Word16 Q_new ) +void GplcTcxEncSetup( + Encoder_State_fx *st, + PLC_ENC_EVS_HANDLE hPlc_Ext, + Word16 Q_new +) { - hPlc_Ext->T0_4th = st->tcxltp_pitch_int; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + + hPlc_Ext->T0_4th = hTcxEnc->tcxltp_pitch_int; move16(); hPlc_Ext->Q_exp = sub( Q_new, hPlc_Ext->Q_new); move16(); @@ -314,14 +329,18 @@ void GplcTcxEncSetup( Encoder_State_fx *st, HANDLE_PLC_ENC_EVS hPlc_Ext, Word16 move16(); set16_fx( hPlc_Ext->old_exc_Qold, 0, 8); } - +/*-------------------------------------------------------------------* + * encSideSpecPowDiffuseDetector() + * + * + *-------------------------------------------------------------------*/ Word16 encSideSpecPowDiffuseDetector( Word16 *lsf_ref, Word16 *lsf_con, - Word32 sr_core, + const Word32 sr_core, Word16 *prev_lsf4_mean, - Word8 sw - , Word16 coder_type + const Word8 sw, + const Word16 coder_type ) { Word16 tmp; @@ -354,7 +373,7 @@ Word16 encSideSpecPowDiffuseDetector( cnt_imprv = 0; - IF( EQ_32( sr_core, 16000 )) + IF( EQ_32( sr_core, INT_FS_16k)) { th = 2560; move16(); /* LSF */ @@ -412,8 +431,14 @@ Word16 encSideSpecPowDiffuseDetector( return idx; } - -void updateSpecPowDiffuseIdx( Encoder_State_fx *st) +/*-------------------------------------------------------------------* + * updateSpecPowDiffuseIdx() + * + * + *-------------------------------------------------------------------*/ +void updateSpecPowDiffuseIdx( + Encoder_State_fx *st +) { Word16 min_gp; Word16 k; @@ -440,6 +465,5 @@ void updateSpecPowDiffuseIdx( Encoder_State_fx *st) } move16(); st->mean_gc[0] = st->mean_gc[1]; - + } - diff --git a/lib_enc/hf_cod_amrwb_fx.c b/lib_enc/hf_cod_amrwb_fx.c index 11a1299..495d4fb 100644 --- a/lib_enc/hf_cod_amrwb_fx.c +++ b/lib_enc/hf_cod_amrwb_fx.c @@ -1,17 +1,17 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" #include "cnst_fx.h" -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ - + /*---------------------------------------------------------------------* + * hf_cod_init() + * + * + *---------------------------------------------------------------------*/ void hf_cod_init_fx( Word16 *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ Word16 *mem_hf1_enc, /* o: HF band-pass filter memory */ @@ -31,20 +31,26 @@ void hf_cod_init_fx( return; } +/*---------------------------------------------------------------------* + * hf_cod() + * + * + *---------------------------------------------------------------------*/ + void hf_cod_fx( - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 *speech16k_fx, /* i : original speech at 16 kHz */ - const Word16 Aq_fx[], /* i : quantized Aq */ - const Word16 exc_fx[], /* i : excitation at 12.8 kHz */ - Word16 synth_fx[], /* i : 12.8kHz synthesis signal */ - Word16 *seed2_enc_fx, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400_enc_fx, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf_enc_fx, /* i/o: HF synthesis memory */ - Word16 *mem_hf1_enc_fx, /* i/o: HF band-pass filter memory */ - Word16 *mem_hf2_enc_fx, /* i/o: HF band-pass filter memory */ + const Word32 core_brate_fx, /* i : core bitrate */ + const Word16 *speech16k_fx, /* i : original speech at 16 kHz */ + const Word16 Aq_fx[], /* i : quantized Aq */ + const Word16 exc_fx[], /* i : excitation at 12.8 kHz */ + Word16 synth_fx[], /* i : 12.8kHz synthesis signal */ + Word16 *seed2_enc_fx, /* i/o: random seed for HF noise gen */ + Word16 *mem_hp400_enc_fx, /* i/o: memory of hp 400 Hz filter */ + Word16 *mem_syn_hf_enc_fx, /* i/o: HF synthesis memory */ + Word16 *mem_hf1_enc_fx, /* i/o: HF band-pass filter memory */ + Word16 *mem_hf2_enc_fx, /* i/o: HF band-pass filter memory */ const Word16 dtxHangoverCount_fx, - Word16 *gain_alpha_fx, /* i/o: smoothing gain for transitions between active and inactive frames */ - Word16 *hf_gain_fx, /* o : HF gain to be transmitted to decoder */ + Word16 *gain_alpha_fx, /* i/o: smoothing gain for transitions between active and inactive frames */ + Word16 *hf_gain_fx, /* o : HF gain to be transmitted to decoder */ Word16 Q_exc, Word16 Q_syn ) diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index 602c334..bf82375 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -1,20 +1,24 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* Debug prototypes */ /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -#define SHARP_DIST_THRES 22.2f #define SHARP_DIST_THRES_FX 1420 /* Q6, 22.2 */ +#define HALF_WIN_LENGTH 10 +#define L_SPEC_HB 320 +#define PEAK_THRESHOLD 3277 /*Q15 0.1f*/ +#define LOW_COUNT_THRESHOLD 220 + + /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ @@ -29,22 +33,24 @@ void hvq_classifier_fx( const Word32 *input, Word16 *prev_Npeaks, Word16 *prev_p * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ -Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 length, /* i : Frame length Q0 */ - const Word32 *coefs, /* i : Spectral coefficients Q12 */ - const Word16 is_transient, /* i : Transient flag Q0 */ - Word16 *Npeaks, /* o : Number of identified peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - Word32 *pe_gains, /* o : Peak gains Q12 */ - Word32 *nf_gains, /* o : Noise-fill gains Q12 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ +Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + const Word16 length, /* i : Frame length Q0 */ + const Word32 *coefs, /* i : Spectral coefficients Q12 */ + const Word16 is_transient, /* i : Transient flag Q0 */ + Word16 *Npeaks, /* o : Number of identified peaks Q0 */ + Word16 *peaks, /* o : Peak indices Q0 */ + Word32 *pe_gains, /* o : Peak gains Q12 */ + Word32 *nf_gains, /* o : Noise-fill gains Q12 */ + Word16 *hqswb_clas /* o : HQ class Q0 */ ) { +#ifndef SOLVED_COMP_ENC_DEC Word16 bits; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; *hqswb_clas = HQ_NORMAL; - IF( EQ_16( is_transient, 1)) + IF(EQ_16(is_transient, 1)) { *hqswb_clas = HQ_TRANSIENT; move16(); @@ -54,38 +60,38 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 test(); test(); test(); - IF( EQ_16(length, L_FRAME32k)&&NE_16(is_transient,1)&&LE_32(st_fx->core_brate_fx,HQ_32k)&&EQ_16(st_fx->bwidth_fx,st_fx->last_bwidth_fx)) + IF(EQ_16(length, L_FRAME32k) && NE_16(is_transient, 1) && LE_32(st_fx->core_brate_fx, HQ_32k) && EQ_16(st_fx->bwidth_fx, st_fx->last_bwidth_fx)) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate_fx, coefs, NUMC_N+96, &st_fx->mode_count_fx, &st_fx->mode_count1_fx, 12 ); + *hqswb_clas = peak_avrg_ratio_fx(st_fx->total_brate_fx, coefs, NUMC_N + 96, &hHQ_core->mode_count_fx, &hHQ_core->mode_count1_fx, 12); /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx( coefs, &st_fx->prev_Npeaks_fx, st_fx->prev_peaks_fx, hqswb_clas, Npeaks, peaks, st_fx->core_brate_fx, st_fx->last_core_fx, - nf_gains, &st_fx->hvq_hangover_fx, pe_gains ); + hvq_classifier_fx(coefs, &hHQ_core->prev_Npeaks_fx, hHQ_core->prev_peaks_fx, hqswb_clas, Npeaks, peaks, st_fx->core_brate_fx, st_fx->last_core_fx, + nf_gains, &hHQ_core->hvq_hangover_fx, pe_gains); } test(); test(); test(); - IF ( EQ_16(length, L_FRAME48k)&&NE_16(is_transient,1)&&LE_32(st_fx->core_brate_fx,HQ_32k)&&EQ_16(st_fx->bwidth_fx,st_fx->last_bwidth_fx)) + IF(EQ_16(length, L_FRAME48k) && NE_16(is_transient, 1) && LE_32(st_fx->core_brate_fx, HQ_32k) && EQ_16(st_fx->bwidth_fx, st_fx->last_bwidth_fx)) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate_fx, coefs, NUMC_N+96, &st_fx->mode_count_fx, &st_fx->mode_count1_fx, 12); + *hqswb_clas = peak_avrg_ratio_fx(st_fx->total_brate_fx, coefs, NUMC_N + 96, &hHQ_core->mode_count_fx, &hHQ_core->mode_count1_fx, 12); /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx( coefs, &st_fx->prev_Npeaks_fx, st_fx->prev_peaks_fx, hqswb_clas, Npeaks, peaks, - st_fx->core_brate_fx, st_fx->last_core_fx, nf_gains, &st_fx->hvq_hangover_fx, pe_gains ); + hvq_classifier_fx(coefs, &hHQ_core->prev_Npeaks_fx, hHQ_core->prev_peaks_fx, hqswb_clas, Npeaks, peaks, + st_fx->core_brate_fx, st_fx->last_core_fx, nf_gains, &hHQ_core->hvq_hangover_fx, pe_gains); } test(); test(); - IF( EQ_16(length, L_FRAME48k)&&LE_32(st_fx->core_brate_fx,HQ_32k)&&EQ_16(*hqswb_clas,HQ_NORMAL)) + IF(EQ_16(length, L_FRAME48k) && LE_32(st_fx->core_brate_fx, HQ_32k) && EQ_16(*hqswb_clas, HQ_NORMAL)) { *hqswb_clas = HQ_GEN_FB; move16(); } test(); - IF( GE_16( length, L_FRAME32k)&&LE_32(st_fx->core_brate_fx,HQ_32k)) + IF(GE_16(length, L_FRAME32k) && LE_32(st_fx->core_brate_fx, HQ_32k)) { bits = 2; move16(); @@ -97,30 +103,105 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 } test(); - IF ( EQ_16( length, L_FRAME48k)&&LE_32(st_fx->core_brate_fx,HQ_32k)) + IF(EQ_16(length, L_FRAME48k) && LE_32(st_fx->core_brate_fx, HQ_32k)) { - IF ( GE_16( *hqswb_clas, HQ_GEN_SWB)) + IF(GE_16(*hqswb_clas, HQ_GEN_SWB)) { - push_indice_fx( st_fx, IND_HQ_SWB_CLAS, *hqswb_clas - 5, bits ); + push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas - 5, bits); } ELSE { - push_indice_fx( st_fx, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); + push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits); } } ELSE { - push_indice_fx( st_fx, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); + push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits); } test(); test(); - IF ( EQ_16( *hqswb_clas, HQ_NORMAL)&&EQ_16(length,L_FRAME32k)&&LE_32(st_fx->core_brate_fx,HQ_32k)) + IF(EQ_16(*hqswb_clas, HQ_NORMAL) && EQ_16(length, L_FRAME32k) && LE_32(st_fx->core_brate_fx, HQ_32k)) { *hqswb_clas = HQ_GEN_SWB; move16(); } +#else + + Word16 bits; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; + Word32 max_brate; + Word16 harmonic_decision; + + + max_brate = HQ_32k; move32(); + if (GT_16(st_fx->element_mode, EVS_MONO)) + { + max_brate = HQ_48k; + move32(); + } + + *hqswb_clas = HQ_NORMAL; + bits = 1; move16(); + IF( EQ_16( is_transient, 1)) + { + *hqswb_clas = HQ_TRANSIENT; + move16(); + } + + /* classification and limit bandwidth for bit allocation */ + test(); + IF (EQ_16(length, L_SPEC32k) || EQ_16(length, L_SPEC48k)) + { + IF(LE_32(st_fx->core_brate_fx, max_brate)) + { + test(); + IF(!is_transient && EQ_16(st_fx->bwidth_fx, st_fx->last_bwidth_fx)) + { + /* Detect HQ_HARMONIC mode */ + *hqswb_clas = peak_avrg_ratio_fx(st_fx->total_brate_fx, coefs, NUMC_N + 96, &hHQ_core->mode_count_fx, &hHQ_core->mode_count1_fx, 12); + +#ifdef ADD_IVAS_HQ_CODE + harmonic_decision = hf_spectrum_sparseness(st, coefs); +#else + harmonic_decision = 0; +#endif + test(); + IF(EQ_16(*hqswb_clas, HQ_HARMONIC) && !harmonic_decision) + { + *hqswb_clas = HQ_NORMAL; + move16(); + } + ELSE + { + /* Detect harmonic VQ mode HQ_HVQ */ + hvq_classifier_fx(coefs, &hHQ_core->prev_Npeaks_fx, hHQ_core->prev_peaks_fx, hqswb_clas, Npeaks, peaks, st_fx->core_brate_fx, st_fx->last_core_fx, + nf_gains, &hHQ_core->hvq_hangover_fx, pe_gains); + } + } + bits = 2; move16(); + } + } + ELSE IF(EQ_16(length, L_SPEC16k_EXT) || EQ_16(length, L_SPEC48k_EXT)) + { + bits = 0; /* HQ_NORMAL only -- no signalling needed */ + move16(); + } + /* write signalling info to the bitstream */ + push_indice_fx(st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits); + IF (LE_32(st_fx->core_brate_fx, HQ_32k) && EQ_16(*hqswb_clas, HQ_NORMAL)) + { + IF (EQ_16(length, L_SPEC32k)) + { + *hqswb_clas = HQ_GEN_SWB; move16(); + } + ELSE IF (EQ_16(length, L_SPEC48k)) + { + *hqswb_clas = HQ_GEN_FB; move16(); + } + } +#endif return bits; } @@ -130,11 +211,11 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 * Classify the input signal and decide if it has a harmonic structure *--------------------------------------------------------------------------*/ Word16 peak_avrg_ratio_fx( - const Word32 total_brate, - const Word32 *input_hi_fx, /* i : input signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ + const Word32 total_brate, /* i : total bitrate */ + const Word32 *input_hi_fx, /* i : input signal */ + const Word16 length, /* i : number of coefficients */ + Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ + Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ Word16 Q_coeff ) { @@ -225,8 +306,13 @@ Word16 peak_avrg_ratio_fx( test(); test(); test(); - if ((GE_16(add(k, k1), 5)&>_16(k1,2)&&EQ_32(total_brate,HQ_24k40)) +#ifndef SOLVED_COMP_ENC_DEC /*This affect BE even if it shouldn't*/ + if ((GE_16(add(k, k1), 5) && GT_16(k1, 2) && EQ_32(total_brate, HQ_24k40)) + || (((GE_16(add(k, k1), 10) && GT_16(k1, 5)) || GE_16(*mode_count, 5)) && LT_16(*mode_count1, 5))) +#else + if ((GE_16(add(k, k1), 5) && GT_16(k1,2) && LT_32(total_brate, HQ_BWE_CROSSOVER_BRATE)) || (((GE_16(add(k, k1), 10) && GT_16(k1, 5) ) || GE_16(*mode_count, 5) ) && LT_16(*mode_count1, 5) )) +#endif { hqswb_clas = HQ_HARMONIC; move16(); @@ -242,14 +328,14 @@ Word16 peak_avrg_ratio_fx( *--------------------------------------------------------------------------*/ void hvq_classifier_fx( - const Word32 *input, /* i : input signal Q12 */ + const Word32 *input, /* i : input signal Q12 */ Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ Word16 *prev_peaks, /* i/o: Peak indices memory Q0 */ Word16 *hqswb_clas, /* i/o: HQ class Q0 */ Word16 *Npeaks, /* o : Number of peaks Q0 */ Word16 *peaks, /* o : Peak indices Q0 */ - const Word32 L_core_brate, /* i : Core bit-rate Q0 */ - const Word16 last_core, /* i : Last core used Q0 */ + const Word32 L_core_brate, /* i : Core bit-rate Q0 */ + const Word16 last_core, /* i : Last core used Q0 */ Word32 *L_nf_gains, /* o : Noisefloor gains Q12 */ Word16 *hvq_hangover, /* i/o: Mode-switch hangover Q0 */ Word32 *L_pe_gains /* o : peak gains Q12 */ @@ -287,7 +373,11 @@ void hvq_classifier_fx( L_input_max = L_deposit_l(0); set32_fx(L_thr, 0, L_FRAME16k); - IF ( EQ_32(L_core_brate, HQ_24k40)) +#ifndef SOLVED_COMP_ENC_DEC + IF(EQ_32(L_core_brate, HQ_24k40)) +#else + IF ( LT_32(L_core_brate, HQ_BWE_CROSSOVER_BRATE)) +#endif { nsub = HVQ_NSUB_24k; move16(); @@ -512,7 +602,7 @@ void hvq_classifier_fx( num_peak_cands = add(num_peak_cands, 1); } } - +#ifndef ADD_IVAS_HQ_CODE IF ( EQ_32(L_core_brate, HQ_24k40)) { peak_th = HVQ_MAX_PEAKS_24k_CLAS; @@ -523,7 +613,9 @@ void hvq_classifier_fx( peak_th = HVQ_MAX_PEAKS_32k; move16(); } - +#else + peak_th = (int16_t)((core_brate * HVQ_PEAKS_PER_DELTA_THR + HVQ_PEAKS_PER_DELTA_THR_OFFS) / HVQ_PEAKS_BPS_DELTA); +#endif /* Find peaks */ pindx = maximum_32_fx(L_input_abs, num_peak_cands, &L_m); i = 0; @@ -644,7 +736,7 @@ void hvq_classifier_fx( move16(); } - +#ifndef ADD_IVAS_HQ_CODE IF ( EQ_32(L_core_brate, HQ_24k40)) { *Npeaks = s_min( HVQ_MAX_PEAKS_24k, *Npeaks ); @@ -655,6 +747,9 @@ void hvq_classifier_fx( *Npeaks = s_min( HVQ_MAX_PEAKS_32k, *Npeaks ); move16(); } +#else + *Npeaks = (int16_t)(min((core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS) / HVQ_PEAKS_BPS_DELTA, *Npeaks)); +#endif } ELSE { @@ -668,4 +763,98 @@ void hvq_classifier_fx( return; } +#ifdef ADD_IVAS_HQ_CODE +/*--------------------------------------------------------------------------* +* hf_spectrum_sparseness() +* +* Detection of sparse spectrum in high band for activation of harmonic +* modes HQ_HARMONIC and HQ_HVQ +*--------------------------------------------------------------------------*/ +/*! r: Harmonic decision for high band */ +static int16_t hf_spectrum_sparseness( + Encoder_State_fx* st, /* i/o: encoder state structure */ + const float* coefs /* i : MDCT spectrum */ +) +{ + int16_t i; + float thr; + int16_t low_count; + float A[L_SPEC_HB]; + float Amax; + float movmean; + float inv_rms; + float crest; + float crest_mod; + const float* p_num; + float* crest_lp; + float* crest_mod_lp; + int16_t result; + + crest_lp = &st->hHQ_core->crest_lp; + crest_mod_lp = &st->hHQ_core->crest_mod_lp; + + result = TRUE; + if (st->element_mode != EVS_MONO) + { + for (i = 0; i < L_SPEC_HB; i++) + { + A[i] = (float)fabsf(coefs[i + L_SPEC_HB]); + } + low_count = 0; + inv_rms = 0.0f; + crest_mod = 0.0f; + maximum(A, L_SPEC_HB, &Amax); + thr = Amax * PEAK_THRESHOLD; + movmean = 0.0f; /* avoid uninitialized warning */ + p_num = &inv_tbl[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) */ + for (i = 0; i < L_SPEC_HB; i++) + { + inv_rms += A[i] * A[i]; + if (A[i] < thr) + { + low_count += 1; + } + if (i <= HALF_WIN_LENGTH) + { + if (i == 0) + { + movmean = sum_f(&A[0], i + HALF_WIN_LENGTH + 1) * (*p_num); + } + else + { + p_num++; + movmean = movmean + (A[i + HALF_WIN_LENGTH] - movmean) * (*p_num); + } + } + else + { + if (L_SPEC_HB <= i + HALF_WIN_LENGTH) + { + p_num--; + movmean = movmean + (movmean - A[i - HALF_WIN_LENGTH - 1]) * (*p_num); + } + else + { + movmean = movmean + (A[i + HALF_WIN_LENGTH] - A[i - HALF_WIN_LENGTH - 1]) * (*p_num); + } + } + if (crest_mod < movmean) + { + crest_mod = movmean; + } + } + inv_rms = 1.0f / (float)sqrtf(inv_rms / L_SPEC_HB); + crest = Amax * inv_rms; + crest_mod = crest_mod * inv_rms; + *crest_lp = HQ_CREST_FAC_SM * (*crest_lp) + (1.0f - HQ_CREST_FAC_SM) * crest; + *crest_mod_lp = HQ_CREST_FAC_SM * (*crest_mod_lp) + (1.0f - HQ_CREST_FAC_SM) * crest_mod; + if (((*crest_lp) > HQ_CREST_THRESHOLD) && ((*crest_mod_lp) > HQ_CREST_MOD_THRESHOLD) && (low_count > LOW_COUNT_THRESHOLD)) + { + result = FALSE; + } + } + + return result; +} +#endif diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 7546f02..3e77fae 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "rom_com_fx.h" /* Static table prototypes */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------------- * hq_core_enc() @@ -19,12 +18,13 @@ void hq_core_enc_fx( const Word16 *audio, /* i : input audio signal Q0 */ const Word16 input_frame_orig, /* i : frame length */ const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag + const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { Word16 i, is_transient, num_bits, extra_unused; Word32 wtda_audio[2 * L_FRAME48k]; - Word32 t_audio[L_FRAME48k]; /* Q12 */ + Word32 t_audio[L_FRAME48k_EXT]; /* Q12 */ Word16 Q_audio = 0; Word16 inner_frame, input_frame; Word16 ener_match; /* Q13/Q15 */ @@ -32,8 +32,17 @@ void hq_core_enc_fx( Word16 tmp; Word32 L_tmp; UWord16 lsb; - +#ifdef ADD_IVAS_HQ_CODE_L_SPEC + Word16 L_spec; +#endif +#ifdef ADD_IVAS_HQ_CODE + Word16 left_overlap, right_overlap; + Word16 overlap, nz, tcx_offset, L_frame; + Word16 Aq_old[M + 1]; + Word16 output[L_FRAME16k]; +#endif Word16 two_frames_buffer[2*L_FRAME48k]; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; set32_fx( t_audio, 0, L_FRAME48k ); st_fx->Nb_ACELP_frames_fx = 0; @@ -42,10 +51,18 @@ void hq_core_enc_fx( /* set input_frame length */ input_frame = input_frame_orig; move16(); - - st_fx->tcx_cfg.tcx_last_overlap_mode = st_fx->tcx_cfg.tcx_curr_overlap_mode; - move16(); - st_fx->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + /* Sanity check, it should never happen at the encoder side (no BFI) */ + IF (EQ_16(st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP)) + { + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;; + move16(); + } + ELSE + { + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + move16(); + } + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); /*-------------------------------------------------------------------------- @@ -64,94 +81,147 @@ void hq_core_enc_fx( * Detect signal transition *--------------------------------------------------------------------------*/ - is_transient = detect_transient_fx( audio, input_frame, HQ_CORE, 0, st_fx); - - /*-------------------------------------------------------------------------- - * Windowing and time-domain aliasing - * DCT transform - *--------------------------------------------------------------------------*/ - - Copy( st_fx->old_input_signal_fx, two_frames_buffer, input_frame ); - Copy( audio, two_frames_buffer+input_frame, input_frame ); + is_transient = detect_transient_fx( audio, input_frame, 0, st_fx); - wtda_fx( two_frames_buffer+input_frame, &Q_audio, wtda_audio, NULL, 0, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, input_frame ); - - test(); - IF ( st_fx->last_core_fx == ACELP_CORE || EQ_16(st_fx->last_core_fx, AMR_WB_CORE)) +#ifdef ADD_IVAS_HQ_CODE + test();test();test(); + IF (GT_16(st_fx->element_mode, EVS_MONO) && (EQ_16(st_fx->last_core_fx, ACELP_CORE) || EQ_16(st_fx->last_core_fx, AMR_WB_CORE))) { - /* Preprocessing in the first HQ frame after ACELP frame */ - core_switching_hq_prepare_enc_fx( st_fx, &num_bits, input_frame, wtda_audio, two_frames_buffer+input_frame ); - - /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - IF ( GT_16(num_bits, ACELP_48k_BITS)) - { - extra_unused = sub(num_bits, ACELP_48k_BITS); - num_bits = ACELP_48k_BITS; - move16(); - } + /*-------------------------------------------------------------------------- + * IVAS switching frame + *--------------------------------------------------------------------------*/ + + L_spec = input_frame; + left_overlap = -1; + right_overlap = -1; + move16();move16();move16(); + + WindowSignal(&(st_fx->tcx_cfg), st_fx->hTcxCfg->tcx_offsetFB, TRANSITION_OVERLAP, FULL_OVERLAP, &left_overlap, &right_overlap, st_fx->hTcxEnc->speech_TCX, &L_spec, wtda_audio, 1, 1); + Q_audio = 16; move16(); /*tbv inspired from core_enc_ol*/ + TCX_MDCT(wtda_audio, t_audio, &Q_audio, left_overlap, sub(L_spec, shr( add(left_overlap, right_overlap), 1)), right_overlap, st_fx->element_mode); + + inner_frame = inner_frame_tbl[st_fx->bwidth_fx]; + L_spec = l_spec_ext_tbl[st_fx->bwidth_fx]; + is_transient = 0; + move16();move16();move16(); } + ELSE +#endif + { + /*-------------------------------------------------------------------------- + * Windowing and time-domain aliasing + * DCT transform + *--------------------------------------------------------------------------*/ - /* subtract signalling bits */ - num_bits = sub(num_bits, st_fx->nb_bits_tot_fx); + Copy(st_fx->old_input_signal_fx, two_frames_buffer, input_frame); + Copy(audio, two_frames_buffer + input_frame, input_frame); - direct_transform_fx( wtda_audio, t_audio, is_transient, input_frame, &Q_audio ); + wtda_fx(two_frames_buffer + input_frame, &Q_audio, wtda_audio, NULL, 0, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, input_frame); - /* scale coefficients to their nominal level (8kHz) */ - IF ( NE_16(input_frame, NORM_MDCT_FACTOR)) - { - IF (EQ_16(input_frame, L_FRAME32k)) + test(); + IF(st_fx->last_core_fx == ACELP_CORE || EQ_16(st_fx->last_core_fx, AMR_WB_CORE)) { - Q_audio = add(Q_audio, 1); /* Divide by 2 */ + /* Preprocessing in the first HQ frame after ACELP frame */ + core_switching_hq_prepare_enc_fx(st_fx, &num_bits, input_frame, wtda_audio, two_frames_buffer + input_frame); + + /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ + IF(GT_16(num_bits, ACELP_48k_BITS)) + { + extra_unused = sub(num_bits, ACELP_48k_BITS); + num_bits = ACELP_48k_BITS; + move16(); + } } - ELSE +#ifndef ADD_IVAS_HQ_CODE + /* subtract signalling bits */ + num_bits = sub(num_bits, hBstr->nb_bits_tot_fx); +#endif + direct_transform_fx(wtda_audio, t_audio, is_transient, input_frame, &Q_audio, st_fx->element_mode); + + /* scale coefficients to their nominal level (8kHz) */ + IF(NE_16(input_frame, NORM_MDCT_FACTOR)) { - tmp = mult_r(input_frame, 410/2); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling[tmp]; - FOR( i=0; i < input_frame; i++ ) + IF(EQ_16(input_frame, L_FRAME32k)) { - /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss(t_audio[i], ener_match, &t_audio[i], &lsb); - move16(); /* Q12 */ + Q_audio = add(Q_audio, 1); /* Divide by 2 */ + } + ELSE + { + tmp = mult_r(input_frame, 410 / 2); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling[tmp]; + FOR(i = 0; i < input_frame; i++) + { + /*t_audio_q[i] *= ener_match; */ + Mpy_32_16_ss(t_audio[i], ener_match, &t_audio[i], &lsb); + move16(); /* Q12 */ + } } } + + /* limit encoded band-width according to the command-line OR BWD limitation */ + inner_frame = inner_frame_tbl[st_fx->bwidth_fx]; + move16(); +#ifdef ADD_IVAS_HQ_CODE_L_SPEC + L_spec = l_spec_tbl[st_fx->bwidth_fx]; + move16(); +#endif + IF(GT_16(input_frame, inner_frame)) + { + IF(EQ_16(is_transient, 1)) + { + FOR(i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++) + { + tmp = i_mult2(i, shr(input_frame, 2)); + tmp = shr(inner_frame, 2); + Copy32(t_audio + i_mult2(i, shr(input_frame, 2)), t_audio + i_mult2(i, tmp), tmp); + } + } + + set32_fx(t_audio + inner_frame, 0, sub(input_frame, inner_frame)); + } } +#ifdef ADD_IVAS_HQ_CODE_L_SPEC + /* subtract signalling bits */ + num_bits = sub(num_bits, hBstr->nb_bits_tot_fx); +#endif - /* limit encoded band-width according to the command-line OR BWD limitation */ - inner_frame = inner_frame_tbl[st_fx->bwidth_fx]; - move16(); + /*-------------------------------------------------------------------------- + * High-band gain control in case of BWS + *--------------------------------------------------------------------------*/ +#ifdef ADD_IVAS_HQ_CODE - IF( GT_16(input_frame, inner_frame)) + IF (st_fx->bwidth_sw_cnt > 0) { - IF( EQ_16(is_transient, 1)) + IF (is_transient) { - FOR ( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) + FOR (i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++) { - tmp = i_mult2(i, shr(input_frame, 2)); - tmp = shr(inner_frame, 2); - Copy32( t_audio + i_mult2(i, shr(input_frame, 2)), t_audio + i_mult2(i, tmp), tmp ); + v_multc(t_audio + i * inner_frame / NUM_TIME_SWITCHING_BLOCKS + L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, t_audio + i * inner_frame / NUM_TIME_SWITCHING_BLOCKS + L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, inner_frame / NUM_TIME_SWITCHING_BLOCKS - L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS); } } - - set32_fx( t_audio + inner_frame, 0, sub(input_frame, inner_frame) ); + ELSE + { + v_multc(t_audio + L_FRAME16k, (float)(st->bwidth_sw_cnt) / (float)BWS_TRAN_PERIOD, t_audio + L_FRAME16k, L_spec - L_FRAME16k); + } } - +#endif /*-------------------------------------------------------------------------- * Classify whether to put extra bits for FER mitigation *--------------------------------------------------------------------------*/ test(); - IF ( EQ_16(st_fx->last_core_fx, HQ_CORE)&>_32(st_fx->core_brate_fx,MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) + IF ((EQ_16(st_fx->last_core_fx, TCX_20_CORE) || EQ_16(st_fx->last_core_fx, TCX_10_CORE) || EQ_16(st_fx->last_core_fx, HQ_CORE)) && GT_32(st_fx->core_brate_fx, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) { IF ( Voicing_flag > 0 ) { - push_indice_fx( st_fx, IND_HQ_VOICING_FLAG, 1, 1 ); + push_indice_fx(hBstr, IND_HQ_VOICING_FLAG, 1, 1 ); num_bits = sub(num_bits, 1); } ELSE { - push_indice_fx( st_fx, IND_HQ_VOICING_FLAG, 0, 1 ); + push_indice_fx(hBstr, IND_HQ_VOICING_FLAG, 0, 1 ); num_bits = sub(num_bits, 1); } } @@ -179,7 +249,11 @@ void hq_core_enc_fx( t_audio[i] = L_shr(t_audio[i], sub(Q_audio, 12)); /* Q12 */ } - hq_hr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient ); +#ifdef ADD_IVAS_HQ_CODE_L_SPEC + hq_hr_enc_fx( st_fx, t_audio, L_spec, &num_bits, is_transient, vad_hover_flag); +#else + hq_hr_enc_fx(st_fx, t_audio, inner_frame, &num_bits, is_transient, vad_hover_flag); +#endif Q_audio = 12; move16(); } @@ -189,14 +263,101 @@ void hq_core_enc_fx( WHILE( num_bits >= 16 ) { - push_indice_fx( st_fx, IND_UNUSED, 0, 16 ); + push_indice_fx(hBstr, IND_UNUSED, 0, 16 ); num_bits = sub(num_bits, 16); } IF ( num_bits != 0 ) { - push_indice_fx( st_fx, IND_UNUSED, 0, num_bits ); + push_indice_fx(hBstr, IND_UNUSED, 0, num_bits ); + } +#ifdef ADD_IVAS_HQ_CODE + if (st->element_mode > EVS_MONO && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE)) + { + overlap = st->hTcxCfg->tcx_mdct_window_length; + nz = NS2SA(st->sr_core, N_ZERO_MDCT_NS); + L_frame = (int16_t)(st->L_frame + st->hTcxCfg->tcx_offset - st->hTcxCfg->lfacNext); + tcx_offset = st->hTcxCfg->lfacNext; + set_f(Aq_old, 0, M + 1); /* Dummy filter */ + Aq_old[0] = 1; + + /* Code taken from InternalTCXDecoder() */ + TCX_MDCT_Inverse(t_audio, wtda_audio, overlap, L_frame - overlap, overlap, st->element_mode); + + /* Window current frame */ + tcx_windowing_synthesis_current_frame(wtda_audio, st->hTcxCfg->tcx_aldo_window_2, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, /*st->hTcxCfg->tcx_mdct_window_length*/ st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->last_core == ACELP_CORE, st->hTcxCfg->tcx_last_overlap_mode, /*left mode*/ st->hTcxEnc->acelp_zir, st->hTcxEnc->Txnq, NULL, Aq_old, st->hTcxCfg->tcx_mdct_window_trans, st->L_frame >> 1, tcx_offset < 0 ? -tcx_offset : 0, st->last_core, 0, 0); + + /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ + mvr2r(wtda_audio + L_frame - nz, st->hTcxEnc->old_out, nz + overlap); + set_zero(st->hTcxEnc->old_out + nz + overlap, nz); + + tcx_windowing_synthesis_past_frame(st->hTcxEnc->old_out + nz, st->hTcxCfg->tcx_aldo_window_1_trunc, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, FULL_OVERLAP); + + for (i = 0; i < nz; i++) + { + st->hTcxEnc->old_out[nz + overlap + i] = wtda_audio[L_frame - 1 - i] * st->hTcxCfg->tcx_aldo_window_1_trunc[-1 - i]; + } + mvr2r(wtda_audio + (overlap >> 1) - tcx_offset, output, st->L_frame); + } + else + { + ener_match = (float)sqrt((float)L_FRAME16k / (float)NORM_MDCT_FACTOR); + v_multc(t_audio, ener_match, t_audio, inner_frame); + + inverse_transform(t_audio, wtda_audio, is_transient, L_FRAME16k, inner_frame, st->element_mode); + + window_ola(wtda_audio, output, st->hTcxEnc->old_out, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL); + } + + if (st->element_mode > EVS_MONO) + { + /* Store LB synthesis in case of switch to ACELP */ + mvr2r(output, st->hLPDmem->old_exc, L_FRAME16k); } +#endif + + return; +} + +/*-------------------------------------------------------------------* + * hq_core_enc_init() + * + * Initialize HQ core state structure + *-------------------------------------------------------------------*/ + +void HQ_core_enc_init( + HQ_ENC_HANDLE hHQ_core /* i/o: HQ core data handle */ +) +{ + hHQ_core->mode_count_fx = 0; + move16(); + hHQ_core->mode_count1_fx = 0; + move16(); + + hHQ_core->hq_generic_speech_class_fx = 0; + move16(); + hHQ_core->prev_Npeaks_fx = 0; + set16_fx(hHQ_core->prev_peaks_fx, 0, HVQ_MAX_PEAKS); + hHQ_core->hvq_hangover_fx = 0; + hHQ_core->prev_hqswb_clas_fx = HQ_NORMAL; + + set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); + set16_fx(hHQ_core->prev_frm_index_fx, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB); + hHQ_core->prev_frm_hfe2_fx = 0; + move16(); + hHQ_core->prev_stab_hfe2_fx = 0; + move16(); + hHQ_core->prev_ni_ratio_fx = 16384; + move16(); /* 0.5 */ + set16_fx(hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS); + set16_fx(hHQ_core->last_bitalloc_max_band_fx, 0, 2); + set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); + set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); + hHQ_core->last_max_pos_pulse_fx = 0; + move16(); + + //hHQ_core->crest_lp = HQ_CREST_THRESHOLD; IVAS_CODE + //hHQ_core->crest_mod_lp = HQ_CREST_MOD_THRESHOLD;IVAS_CODE return; } diff --git a/lib_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index 1941931..c49d097 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -14,15 +14,15 @@ * Encode envelope indices *--------------------------------------------------------------------------------------*/ -Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0 */ - ,const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ +Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 num_sfm, /* i : Number of subbands Q0 */ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ + Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ + Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ + const Word16 flag_HQ2, /* i : indicator of HQ2 core Q0 */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ ) { Word16 bits; @@ -31,10 +31,11 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if Word16 i,j; Word16 difidx_flag; Word16 index_max, index_min, index_rad; - Word16 difidx_org[NB_SFM]; /* lenght of this buffer is max(BANDS_MAX,NB_SFM) */ + Word16 difidx_org[NB_SFM]; /* length of this buffer is max(BANDS_MAX,NB_SFM) */ Word16 m, r; Word16 v, k; + set16_fx( difidx_org, 0, NB_SFM ); difidx_flag = 0; move16(); @@ -292,13 +293,13 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if test(); IF( EQ_16(flag_HQ2, LOW_RATE_HQ_CORE_TRAN)||EQ_16(flag_HQ2,LOW_RATE_HQ_CORE)) { - push_indice_fx( st_fx, IND_HQ2_DENG_HMODE, *LCmode, BITS_DE_HMODE); - push_indice_fx( st_fx, IND_HQ2_DIFF_ENERGY, difidx[0], BITS_DE_FCOMP); + push_indice_fx( hBstr, IND_HQ2_DENG_HMODE, *LCmode, BITS_DE_HMODE); + push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, difidx[0], BITS_DE_FCOMP); } ELSE { - push_indice_fx( st_fx, IND_LC_MODE, *LCmode, 2 ); - push_indice_fx( st_fx, IND_YNRM, difidx[0], NORM0_BITS ); + push_indice_fx( hBstr, IND_LC_MODE, *LCmode, 2 ); + push_indice_fx( hBstr, IND_YNRM, difidx[0], NORM0_BITS ); } test(); @@ -328,7 +329,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if m = lshr(m, 1); } - push_indice_fx(st_fx, IND_HQ2_DIFF_ENERGY, v, r); + push_indice_fx(hBstr, IND_HQ2_DIFF_ENERGY, v, r); } } ELSE @@ -367,7 +368,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if move16(); } } - push_indice_fx(st_fx, IND_HQ2_DIFF_ENERGY, m, r); + push_indice_fx(hBstr, IND_HQ2_DIFF_ENERGY, m, r); prevj = j; move16(); } @@ -416,11 +417,11 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if IF( EQ_16(flag_HQ2, LOW_RATE_HQ_CORE)) { - push_indice_fx(st_fx, IND_HQ2_DIFF_ENERGY, m, r); + push_indice_fx(hBstr, IND_HQ2_DIFF_ENERGY, m, r); } ELSE { - push_indice_fx( st_fx, IND_YNRM, m, r ); + push_indice_fx( hBstr, IND_YNRM, m, r ); } prevj = j; @@ -512,11 +513,11 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if IF ( flag_HQ2 == 0 ) { - push_indice_fx( st_fx, IND_YNRM, v, r ); + push_indice_fx( hBstr, IND_YNRM, v, r ); } ELSE { - push_indice_fx( st_fx, IND_HQ2_DIFF_ENERGY, v, r); + push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, v, r); } } } @@ -533,14 +534,14 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if r = huffsizn[j]; move16(); - push_indice_fx( st_fx, IND_YNRM, m, r ); + push_indice_fx( hBstr, IND_YNRM, m, r ); } } ELSE { FOR( i = 1; i < num_sfm; i++ ) { - push_indice_fx( st_fx, IND_YNRM, difidx[i], NORMI_BITS ); + push_indice_fx( hBstr, IND_YNRM, difidx[i], NORMI_BITS ); } } } @@ -556,12 +557,12 @@ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if *--------------------------------------------------------------------------*/ void diff_envelope_coding_fx( - const Word16 is_transient, /* i : transient indicator Q0 */ - const Word16 num_env_bands, /* i : number of envelope bands to code Q0 */ - const Word16 start_norm, /* i : start of envelope coding Q0 */ - Word16 *ynrm, /* i/o: quantization indices for norms Q0 */ - Word16 *normqlg2, /* i/o: quantized norms Q0 */ - Word16 *difidx /* o : differential code Q0 */ + const Word16 is_transient, /* i : transient indicator Q0 */ + const Word16 num_env_bands, /* i : number of envelope bands to code Q0 */ + const Word16 start_norm, /* i : start of envelope coding Q0 */ + Word16 *ynrm, /* i/o: quantization indices for norms Q0 */ + Word16 *normqlg2, /* i/o: quantized norms Q0 */ + Word16 *difidx /* o : differential code Q0 */ ) { Word16 i, tmp; diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index bccba4a..4e3a513 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*--------------------------------------------------------------------------* * hq_hr_enc_fx() @@ -14,11 +13,12 @@ * HQ High rate encoding routine *--------------------------------------------------------------------------*/ void hq_hr_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure fx */ - Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16 *num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient /* i : transient flag Q0 */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure fx */ + Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ + const Word16 length, /* i : length of spectrum Q0 */ + Word16 *num_bits, /* i : number of available bits Q0 */ + const Word16 is_transient, /* i : transient flag Q0 */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ ) { Word16 nb_sfm; /* Q0 */ @@ -35,10 +35,10 @@ void hq_hr_enc_fx( Word16 difidx_org[NB_SFM]; /* Q0 */ Word16 R[NB_SFM]; /* Q0 */ Word16 peaks[HVQ_MAX_PEAKS]; /* Q0 */ - const Word16 *sfmsize, *sfm_start, *sfm_end; /* Q0 */ + Word16 sfmsize[NB_SFM], sfm_start[NB_SFM], sfm_end[NB_SFM]; /* Q0 */ Word16 npulses[NB_SFM], maxpulse[NB_SFM]; /* Q0 */ Word16 Rsubband[NB_SFM]; /* Q3 */ - Word32 t_audio_q[L_FRAME48k]; /* Q12 */ + Word32 t_audio_q[L_SPEC48k_EXT]; /* Q12 */ Word32 nf_gains[HVQ_NF_GROUPS]; /* Q12 */ Word32 pe_gains[HVQ_NF_GROUPS]; /* Q12 */ Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /* Q15 */ @@ -57,6 +57,8 @@ void hq_hr_enc_fx( Word16 i; Word16 b_delta_env; Word16 Q_shift; + Word16 att; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; /*------------------------------------------------------------------* * Initializations @@ -91,7 +93,7 @@ void hq_hr_enc_fx( *------------------------------------------------------------------*/ hq_configure_fx( length, hqswb_clas, st_fx->core_brate_fx, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, - &sfmsize, &sfm_start, &sfm_end ); + sfmsize, sfm_start, sfm_end ); /*------------------------------------------------------------------* * Transient frame handling @@ -103,6 +105,12 @@ void hq_hr_enc_fx( interleave_spectrum_fx( t_audio, length ); } + test(); + IF (EQ_16(st_fx->element_mode, IVAS_CPE_DFT) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + calculate_hangover_attenuation_gain(st_fx, &att, vad_hover_flag); + v_multc_att32(t_audio, att, t_audio, sfm_end[sub(num_sfm, 1)]); + } /*------------------------------------------------------------------* * Scalar quantization of norms * Encode norm indices @@ -115,11 +123,11 @@ void hq_hr_enc_fx( diff_envelope_coding_fx(is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx); /* Find coding mode and calculate bit rate */ - hcode_l = encode_envelope_indices_fx( st_fx, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); + hcode_l = encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); *num_bits = sub(*num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Encode norm indices */ - encode_envelope_indices_fx( st_fx, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); + encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); /*------------------------------------------------------------------* * HQ Generic HF encoding @@ -128,7 +136,7 @@ void hq_hr_enc_fx( test(); IF ( EQ_16( hqswb_clas, HQ_GEN_SWB )||EQ_16(hqswb_clas,HQ_GEN_FB)) { - hq_generic_encoding_fx(t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas); + hq_generic_encoding_fx(t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas/*, length*/); IF (EQ_16(hq_generic_exc_clas , HQ_GENERIC_SP_EXC)) { *num_bits = add(*num_bits,1); /* conditional 1 bit saving for representing FD3 BWE excitation class */ @@ -151,7 +159,7 @@ void hq_hr_enc_fx( test(); IF (hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB) { - b_delta_env = calc_nor_delta_hf_fx( st_fx, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); + b_delta_env = calc_nor_delta_hf_fx( st_fx->hBstr, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); sum -= b_delta_env; } normalizecoefs_fx( t_audio, ynrm, nb_sfm, sfm_start, sfm_end, t_audio_norm ); @@ -163,13 +171,12 @@ void hq_hr_enc_fx( *------------------------------------------------------------------*/ IF( EQ_16( hqswb_clas, HQ_HVQ)) { - sum = hvq_enc_fx( st_fx, st_fx->core_brate_fx, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, - noise_level, pe_gains, t_audio, t_audio_q ); + sum = hvq_enc_fx( st_fx, st_fx->core_brate_fx, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, noise_level, pe_gains, t_audio, t_audio_q ); *num_bits = sub(*num_bits, sum); } ELSE { - shape_bits = pvq_core_enc_fx( st_fx, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, + shape_bits = pvq_core_enc_fx( st_fx->hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, npulses, maxpulse, HQ_CORE ); *num_bits = add( *num_bits, sub( sum, shape_bits) ); } @@ -192,43 +199,54 @@ void hq_hr_enc_fx( } } - har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &st_fx->prev_frm_hfe2_fx, subband_search_offset, wBands, &st_fx->prev_stab_hfe2_fx ); + har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2_fx, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2_fx ); - st_fx->prev_frm_hfe2_fx = har_freq_est2; + hHQ_core->prev_frm_hfe2_fx = har_freq_est2; move16(); } test(); test(); - IF ( NE_16(hqswb_clas, HQ_HARMONIC)||NE_16(hqswb_clas,HQ_HVQ)||flag_dis==0) - { - st_fx->prev_frm_hfe2_fx = 0; /*reset*/ move16(); - st_fx->prev_stab_hfe2_fx = 0; /*reset*/ move16(); - } + hHQ_core->prev_frm_hfe2_fx = 0; /*reset*/ move16(); + hHQ_core->prev_stab_hfe2_fx = 0; /*reset*/ move16(); nf_idx = 0; move16(); test(); test(); test(); - IF ( NE_16(is_transient,1 )&&NE_16(hqswb_clas,HQ_HVQ)&&!(EQ_16(length,L_FRAME16k)&&EQ_32(st_fx->core_brate_fx,HQ_32k))) + IF ( NE_16(is_transient,1 ) && NE_16(hqswb_clas,HQ_HVQ) && !(EQ_16(length,L_FRAME16k) && LE_32(st_fx->core_brate_fx,HQ_32k))) { test(); IF (EQ_16(hqswb_clas, HQ_GEN_SWB)||EQ_16(hqswb_clas,HQ_GEN_FB)) { nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max(core_sfm,sub(num_env_bands,1))); - push_indice_fx( st_fx, IND_NF_IDX, nf_idx, 2 ); + push_indice_fx( st_fx->hBstr, IND_NF_IDX, nf_idx, 2 ); } ELSE { nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, core_sfm ); - push_indice_fx( st_fx, IND_NF_IDX, nf_idx, 2 ); + push_indice_fx( st_fx->hBstr, IND_NF_IDX, nf_idx, 2 ); } } /* updates */ - st_fx->prev_hqswb_clas_fx = hqswb_clas; + hHQ_core->prev_hqswb_clas_fx = hqswb_clas; move16(); + /* Prepare synthesis for LB generation in case of switch to ACELP */ +#ifdef ADD_IVAS_HQ_CODE + IF (NE_16(hqswb_clas, HQ_HVQ)) + { + apply_envelope_enc(t_audio_q, ynrm, num_sfm, sfm_start, sfm_end); + } + + IF (is_transient) + { + de_interleave_spectrum(t_audio_q, length); + } + Copy32(t_audio_q, t_audio, length); +#endif + return; } diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 297948f..c0d20e4 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -1,29 +1,26 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "rom_com_fx.h" #include "rom_enc_fx.h" -#include "stl.h" #include "basop_mpy.h" /*--------------------------------------------------------------------------* - * Local functions + * Local function prototypes *--------------------------------------------------------------------------*/ -static Word16 band_energy_quant_fx( Encoder_State_fx *st_fx, const Word32 *L_t_audio, const Word16 band_start_fx[], const Word16 band_end_fx[], Word32 L_band_energy[], - const Word16 bands_fx, const Word32 L_qint, const Word16 eref_fx, const Word16 is_transient_fx ); +static Word16 band_energy_quant_fx(BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start_fx[], const Word16 band_end_fx[], Word32 L_band_energy[], + const Word16 bands_fx, const Word32 L_qint, const Word16 eref_fx, const Word16 is_transient_fx ); -static Word16 p2a_threshold_quant_fx( Encoder_State_fx *st_fx, const Word32 *L_t_audio, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], - const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th, Word16 *p2a_flags ); +static Word16 p2a_threshold_quant_fx(BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], + const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th, Word16 *p2a_flags ); static void mdct_spectrum_fine_gain_enc_fx( Encoder_State_fx *st_fx, const Word32 L_ybuf[], Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], - const Word16 k_sort[], const Word16 bands, - const Word32 L_qint, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); + const Word16 k_sort[], const Word16 bands, const Word32 L_qint, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); /*--------------------------------------------------------------------------* * spt_shorten_domain_set() @@ -32,17 +29,17 @@ static void mdct_spectrum_fine_gain_enc_fx( Encoder_State_fx *st_fx, const Word *--------------------------------------------------------------------------*/ static void spt_shorten_domain_set_fx( - Encoder_State_fx *st_fx, /* i: encoder state structure */ - const Word32 L_t_audio[], /* i: input spectrum */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* i/o: band start position */ - Word16 band_end[], /* i/o: band end position */ - Word16 band_width[], /* i: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ + Encoder_State_fx *st_fx, /* i: encoder state structure */ + const Word32 L_t_audio[], /* i: input spectrum */ + const Word16 p2a_flags[], /* i: p2a anlysis information */ + const Word16 new_band_start[], /* i: new band start position */ + const Word16 new_band_end[], /* i: new band end position */ + const Word16 new_band_width[], /* i: new subband band width */ + const Word16 bands, /* i: total number of subbands */ + Word16 band_start[], /* i/o: band start position */ + Word16 band_end[], /* i/o: band end position */ + Word16 band_width[], /* i: sub band band width */ + Word16 *bit_budget /* i/o: bit budget */ ) { Word16 i, j, k; @@ -50,6 +47,7 @@ static void spt_shorten_domain_set_fx( Word32 L_max_y2; Word16 max_y2_pos; Word16 spt_shorten_flag[SPT_SHORTEN_SBNUM]; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; kpos = 0; j = 0; @@ -60,7 +58,7 @@ static void spt_shorten_domain_set_fx( { spt_shorten_flag[j] = 0; move16(); - IF ( st_fx->prev_SWB_peak_pos_fx[kpos] != 0) + IF (hHQ_core->prev_SWB_peak_pos_fx[kpos] != 0) { L_max_y2 = L_deposit_l(0); max_y2_pos = 0; @@ -87,7 +85,7 @@ static void spt_shorten_domain_set_fx( move16(); } } - push_indice_fx(st_fx, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1); + push_indice_fx(st_fx->hBstr, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1); *bit_budget = sub(*bit_budget, 1); } @@ -105,11 +103,11 @@ static void spt_shorten_domain_set_fx( *--------------------------------------------------------------------------*/ void hq_lr_enc_fx( - Encoder_State_fx *st_fx, /* i/o: : encoder state structure */ - Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ - const Word16 inner_frame_fx, /* i : Q0 : inner frame length */ - Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ - const Word16 is_transient_fx /* i : Q0 : transient flag */ + Encoder_State_fx *st_fx, /* i/o: : encoder state structure */ + Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ + const Word16 inner_frame_fx,/* i : Q0 : inner frame length */ + Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ + const Word16 is_transient_fx/* i : Q0 : transient flag */ ) { Word16 i, k1_fx, k2_fx; @@ -169,6 +167,9 @@ void hq_lr_enc_fx( Word32 Ep_tmp_fx[BANDS_MAX]; Word16 gama_fx;/*Q15 0.85f;// */ Word16 beta_fx;/*Q14 1.05f; */ + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + set32_fx( L_y2, 0x0L, L_FRAME48k ); set16_fx( inp_vector_fx, 0, inner_frame_fx ); @@ -200,11 +201,11 @@ void hq_lr_enc_fx( } ELSE { - hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate_fx, L_t_audio, NUMC_N, &st_fx->mode_count_fx, &st_fx->mode_count1_fx, SWB_BWE_LR_Qs ); + hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate_fx, L_t_audio, NUMC_N, &hHQ_core->mode_count_fx, &hHQ_core->mode_count1_fx, SWB_BWE_LR_Qs ); } /* write the classification information into the bitstream */ - push_indice_fx( st_fx, IND_HQ2_SWB_CLAS, hqswb_clas_fx, 2 ); + push_indice_fx( hBstr, IND_HQ2_SWB_CLAS, hqswb_clas_fx, 2 ); (*num_bits_fx) = sub(*num_bits_fx, 2); if( EQ_16(hqswb_clas_fx, HQ_NORMAL)) { @@ -215,7 +216,7 @@ void hq_lr_enc_fx( ELSE { /* write the transient bit into the bitstream */ - push_indice_fx( st_fx, IND_HQ2_SWB_CLAS, is_transient_fx, 1 ); + push_indice_fx( st_fx->hBstr, IND_HQ2_SWB_CLAS, is_transient_fx, 1 ); /* subtract one bit for the transient flag */ (*num_bits_fx)--; @@ -247,13 +248,13 @@ void hq_lr_enc_fx( test(); IF(( EQ_32(L_bwe_br, HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))&&EQ_16(st_fx->bwidth_fx,SWB)) { - IF( NE_16(st_fx->prev_hqswb_clas_fx, HQ_NORMAL)) + IF( NE_16(hHQ_core->prev_hqswb_clas_fx, HQ_NORMAL)) { j = 0; move16(); FOR(k=sub(bands_fx,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos_fx[j] = 0; + hHQ_core->prev_SWB_peak_pos_fx[j] = 0; move16(); j = add(j, 1); } @@ -283,7 +284,7 @@ void hq_lr_enc_fx( } /* Spectral energy calculation/quantization */ - ebits_fx = band_energy_quant_fx( st_fx, L_t_audio, band_start, band_end, L_band_energy, bands_fx, + ebits_fx = band_energy_quant_fx( hBstr, L_t_audio, band_start, band_end, L_band_energy, bands_fx, L_qint, eref_fx, is_transient_fx ); /* First pass bit budget for TCQ of spectral band information */ @@ -307,7 +308,7 @@ void hq_lr_enc_fx( ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx( st_fx, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); + pbits_fx = p2a_threshold_quant_fx(hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); bit_budget_fx = sub(bit_budget_fx, pbits_fx); IF( EQ_16(hqswb_clas_fx, HQ_NORMAL)) @@ -319,14 +320,14 @@ void hq_lr_enc_fx( ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx( st_fx, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); + pbits_fx = p2a_threshold_quant_fx(hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); bit_budget_fx = sub(bit_budget_fx, pbits_fx); } IF(EQ_16(flag_spt_fx, 1)) { spt_shorten_domain_band_save_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - spt_shorten_domain_pre_fx(band_start, band_end, st_fx->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); + spt_shorten_domain_pre_fx(band_start, band_end, hHQ_core->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); spt_shorten_domain_set_fx(st_fx, L_t_audio, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx); } @@ -513,7 +514,7 @@ void hq_lr_enc_fx( alpha_fx =add(16384,tmp); } - IF(EQ_16(st_fx->last_bitalloc_max_band_fx[j++], 1)) + IF(EQ_16(hHQ_core->last_bitalloc_max_band_fx[j++], 1)) { L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ tmp = extract_h(L_shl(L_tmp,14));/*Q-2 */ @@ -624,7 +625,7 @@ void hq_lr_enc_fx( /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ FOR(i = 0; i < 2; i++) { - push_indice_fx ( st_fx, IND_HQ2_LAST_BA_MAX_BAND, st_fx->last_bitalloc_max_band_fx[i], 1 ); + push_indice_fx ( st_fx->hBstr, IND_HQ2_LAST_BA_MAX_BAND, hHQ_core->last_bitalloc_max_band_fx[i], 1 ); } } ELSE IF( is_transient_fx == 0 && EQ_16(inner_frame_fx, L_FRAME16k)) @@ -728,7 +729,7 @@ void hq_lr_enc_fx( IF(add(sub(i,bands_fx),p2a_bands_fx) > 0) { tmp = sub(bands_fx,p2a_bands_fx); - IF(EQ_16(st_fx->last_bitalloc_max_band_fx[sub(i, add(tmp, 1))], 1)) + IF(EQ_16(hHQ_core->last_bitalloc_max_band_fx[sub(i, add(tmp, 1))], 1)) { tmp = sub(tmp,lowband); L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp);/*Q(15+0-15 = 0) */ @@ -850,7 +851,7 @@ void hq_lr_enc_fx( /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ FOR(i = 0; i < 2; i++) { - push_indice_fx( st_fx, IND_HQ2_LAST_BA_MAX_BAND, st_fx->last_bitalloc_max_band_fx[i], 1 ); + push_indice_fx( st_fx->hBstr, IND_HQ2_LAST_BA_MAX_BAND, hHQ_core->last_bitalloc_max_band_fx[i], 1 ); } } ELSE IF( EQ_16(st_fx->bwidth_fx, SWB)&&EQ_16(hqswb_clas_fx,HQ_HARMONIC)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))) @@ -867,8 +868,8 @@ void hq_lr_enc_fx( *num_bits_fx, hqswb_clas_fx, st_fx->bwidth_fx, is_transient_fx ); } - tcq_core_LR_enc_fx( st_fx, inp_vector_fx, /*t_audio, */L_t_audio, /*y2, */L_y2, bit_budget_fx, bands_fx, band_start, band_end, band_width, /*Rk*/L_Rk, npulses_fx, k_sort_fx, - p2a_flags_fx, p2a_bands_fx, st_fx->last_bitalloc_max_band_fx, inner_frame_fx, adjustFlag, is_transient_fx ); + tcq_core_LR_enc_fx( hBstr, /*st_fx->idchan, */inp_vector_fx, /*t_audio, */L_t_audio, /*y2, */L_y2, bit_budget_fx, bands_fx, band_start, band_end, band_width, /*Rk*/L_Rk, npulses_fx, k_sort_fx, + p2a_flags_fx, p2a_bands_fx, hHQ_core->last_bitalloc_max_band_fx, inner_frame_fx, adjustFlag, is_transient_fx ); IF((EQ_16(inner_frame_fx, L_FRAME8k)&&LE_32(st_fx->core_brate_fx,ACELP_13k20))||EQ_16(inner_frame_fx,L_FRAME16k)) { @@ -877,11 +878,11 @@ void hq_lr_enc_fx( { IF(npulses_fx[bands_fx-i] > 0) { - st_fx->last_bitalloc_max_band_fx[j] = 1; + hHQ_core->last_bitalloc_max_band_fx[j] = 1; } ELSE { - st_fx->last_bitalloc_max_band_fx[j] = 0; + hHQ_core->last_bitalloc_max_band_fx[j] = 0; } j++; } @@ -906,7 +907,7 @@ void hq_lr_enc_fx( Copy32(L_y2, L_y2_ni, band_end[bands_fx-1]+1); hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, - st_fx->last_ni_gain_fx, st_fx->last_env_fx, &st_fx->last_max_pos_pulse_fx, p2a_flags_fx, p2a_bands_fx, + hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse_fx, p2a_flags_fx, p2a_bands_fx, hqswb_clas_fx, st_fx->bwidth_fx, L_bwe_br ); test(); @@ -918,19 +919,9 @@ void hq_lr_enc_fx( { preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx,length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); - swb_bwe_enc_lr_fx( - st_fx, - L_y2, SWB_BWE_LR_Qs, L_t_audio, L_m, - L_bwe_br, - bands_fx, band_start, band_end, - L_band_energy, SWB_BWE_LR_Qbe, - p2a_flags_fx, - hqswb_clas_fx, lowlength_fx, highlength_fx, - st_fx->prev_frm_index_fx, - har_bands_fx, - &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx, - band_width, L_y2_ni, &ni_seed_fx - ); + swb_bwe_enc_lr_fx( st_fx, L_y2, SWB_BWE_LR_Qs, L_t_audio, L_m, L_bwe_br, + bands_fx, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, + hHQ_core->prev_frm_index_fx, har_bands_fx, &hHQ_core->prev_frm_hfe2_fx, &hHQ_core->prev_stab_hfe2_fx, band_width, L_y2_ni, &ni_seed_fx); post_hq2_swb_fx( L_m, lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx, p2a_flags_fx, band_start, band_end, L_y2, npulses_fx ); @@ -955,15 +946,15 @@ void hq_lr_enc_fx( } } - updat_prev_frm_fx( L_y2, L_t_audio, L_bwe_br, length_fx, inner_frame_fx, bands_fx, st_fx->bwidth_fx, is_transient_fx, hqswb_clas_fx, &st_fx->prev_hqswb_clas_fx, - st_fx->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx, 0 ); + updat_prev_frm_fx( L_y2, L_t_audio, L_bwe_br, length_fx, inner_frame_fx, bands_fx, st_fx->bwidth_fx, is_transient_fx, hqswb_clas_fx, &hHQ_core->prev_hqswb_clas_fx, + hHQ_core->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &hHQ_core->prev_frm_hfe2_fx, &hHQ_core->prev_stab_hfe2_fx, 0 ); IF( NE_16(st_fx->bwidth_fx, SWB)) { /* reset HQ classifier memories */ - st_fx->mode_count_fx = 0; + hHQ_core->mode_count_fx = 0; move16(); - st_fx->mode_count1_fx = 0; + hHQ_core->mode_count1_fx = 0; move16(); } @@ -972,9 +963,9 @@ void hq_lr_enc_fx( test(); IF( NE_16(hqswb_clas_fx, HQ_HARMONIC)&&(EQ_32(L_bwe_br,HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))&&EQ_16(st_fx->bwidth_fx,SWB)) { - st_fx->prev_frm_index_fx[0] = -1; + hHQ_core->prev_frm_index_fx[0] = -1; move16(); - st_fx->prev_frm_index_fx[1] = -1; + hHQ_core->prev_frm_index_fx[1] = -1; move16(); } @@ -982,7 +973,7 @@ void hq_lr_enc_fx( *num_bits_fx = 0; move16(); - st_fx->hvq_hangover_fx = 0; + hHQ_core->hvq_hangover_fx = 0; move16(); return; @@ -996,12 +987,12 @@ void hq_lr_enc_fx( * if flag_pack = 0, estimatng else packing bits *--------------------------------------------------------------------------*/ -static Word16 small_symbol_enc_tran_fx( /* o : bits */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits */ +static Word16 small_symbol_enc_tran_fx( /* o : bits */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 *qbidx, /* i : input of dequantized differential energy */ + const Word16 BANDS, /* i : number of bands */ + Word16 *hLCmode, /* i/o: LC mode info */ + const Word16 flag_pack, /* i : indicator of packing or estimating bits */ const Word16 is_transient ) { @@ -1028,14 +1019,14 @@ static Word16 small_symbol_enc_tran_fx( /* o : bits IF ( flag_pack == 0 ) { /* estimating # of bits */ - bits = encode_envelope_indices_fx(st_fx, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN , is_transient ); + bits = encode_envelope_indices_fx(hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN , is_transient ); bits = add(bits, BITS_DE_FCOMP); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ } ELSE { bits = 0; move16(); - encode_envelope_indices_fx(st_fx, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN ,is_transient ); + encode_envelope_indices_fx(hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN ,is_transient ); } return add(bits, BITS_DE_HMODE); /* xx bits for diff. energies + 1 bit for LC coding mode */ @@ -1051,10 +1042,10 @@ static Word16 small_symbol_enc_tran_fx( /* o : bits *--------------------------------------------------------------------------*/ static Word16 small_symbol_enc_fx( /* o : bits */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ const Word16 *qbidx, /* i : input of dequantized differential energy */ const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ + Word16 *hLCmode, /* i/o: LC mode info */ const Word16 flag_pack /* i : indicator of packing or estimating bits */ ,const Word16 is_transient ) @@ -1096,7 +1087,7 @@ static Word16 small_symbol_enc_fx( /* o : bits { /* estimating # of bits */ /* Encoding MSB bits */ - bits = encode_envelope_indices_fx( st_fx, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); + bits = encode_envelope_indices_fx(hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); bits = add(bits, BITS_DE_FCOMP); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ /* Encoding LSB bit packing */ @@ -1107,24 +1098,24 @@ static Word16 small_symbol_enc_fx( /* o : bits /* Encoding MSB bits */ bits = 0; move16(); - encode_envelope_indices_fx( st_fx, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); + encode_envelope_indices_fx(hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); /* Encoding LSB bit packing */ FOR( i=0; ihBstr, IND_HQ2_SUBBAND_GAIN, imin_fx, gqbits ); } return; diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 9db2687..1fb7f29 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -2,10 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" #include "cnst_fx.h" -#include "stl.h" #define HVQ_ENC_NOISE_DELTA ((Word16)3277) /* 0.1 in Q15 */ @@ -18,19 +18,19 @@ static Word16 quant_lc(const Word16, Word16 *); * Harmonic VQ encoder *--------------------------------------------------------------------------*/ -Word16 hvq_enc_fx( /*o : Consumed bits */ - Encoder_State_fx *st_fx, /*i/o: encoder state structure */ - const Word32 brate, /*i : Total bit rate */ - const Word16 hvq_bits, /*i : HVQ bit budget */ - const Word16 Npeaks, /*i : Number of peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ - Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ - Word16 *noise_level, /* o : Quantized noise level */ - const Word32 *pe_gains, /* i : Peak gains */ - const Word32 *coefs, /* i : spectrum coefficients in Q12 */ - Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ +Word16 hvq_enc_fx( /*o : Consumed bits */ + Encoder_State_fx *st_fx, /*i/o: encoder state structure */ + const Word32 core_brate, /*i : Total bit rate */ + const Word16 hvq_bits, /*i : HVQ bit budget */ + const Word16 Npeaks, /*i : Number of peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ + Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ + Word16 *noise_level, /* o : Quantized noise level */ + const Word32 *pe_gains, /* i : Peak gains */ + const Word32 *coefs, /* i : spectrum coefficients in Q12 */ + Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ ) { const Word32 *pCoefs; @@ -51,7 +51,7 @@ Word16 hvq_enc_fx( /*o : Consumed bits */ bits_used = 0; move16(); - IF ( brate == HQ_24k40 ) + IF ( LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { bin_th = HVQ_THRES_BIN_24k; move16(); @@ -150,7 +150,7 @@ Word16 hvq_enc_fx( /*o : Consumed bits */ q_noise_level[i] = 0; move16(); } - push_indice_fx(st_fx, IND_HVQ_BWE_NL, q_noise_level_idx[i], 2 ); + push_indice_fx(st_fx->hBstr, IND_HVQ_BWE_NL, q_noise_level_idx[i], 2 ); bits_used = add(bits_used, 2); noise_level[i] = q_noise_level[i]; /* in Q15 */ @@ -183,7 +183,7 @@ Word16 hvq_enc_fx( /*o : Consumed bits */ move16(); } } - nBits = peak_vq_enc_fx( st_fx, coefs, coefs_out, brate, sub(hvq_bits, bits_used), + nBits = peak_vq_enc_fx( st_fx->hBstr, st_fx->bwidth_fx, coefs, coefs_out, core_brate, sub(hvq_bits, bits_used), Npeaks, ynrm, R, peaks, &nf_gains[0] ); bits_used = add(bits_used, nBits); return bits_used; diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index fcf2f37..8500f3a 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -15,23 +15,25 @@ /**********************************************************************/ /* write single bit to stream **************************************************************************/ -static void IGF_write_bit(Encoder_State_fx *st, /**< in: | encoder state structure */ - Word16 *bitCount, /**< in/out: | bit counter */ - Word16 bit /**< in: | value of bit */ - ) +static void IGF_write_bit( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *bitCount, /**< in/out: | bit counter */ + Word16 bit /**< in: | value of bit */ +) { - IGFCommonFuncsWriteSerialBit(st, bitCount, bit); + IGFCommonFuncsWriteSerialBit(hBstr, bitCount, bit); } /**********************************************************************/ /* write bits to stream **************************************************************************/ -static void IGF_write_bits(Encoder_State_fx *st, /**< in: | encoder state structure */ - Word16 *bitCount, /**< in/out: | bit counter */ - Word16 value, /**< in: | value to be written */ - Word16 bits /**< in: Q0 | number of bits */ - ) +static void IGF_write_bits( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *bitCount, /**< in/out: | bit counter */ + Word16 value, /**< in: | value to be written */ + Word16 bits /**< in: Q0 | number of bits */ +) { Word16 tmp; @@ -41,11 +43,11 @@ static void IGF_write_bits(Encoder_State_fx *st, tmp = s_and(value, shl(1, bits)); IF (tmp == 0) { - IGF_write_bit(st, bitCount, 0); + IGF_write_bit(hBstr, bitCount, 0); } ELSE { - IGF_write_bit(st, bitCount, 1); + IGF_write_bit(hBstr, bitCount, 1); } } @@ -290,12 +292,12 @@ static void IGF_CalculateEnvelope(const IGF_ENC_INSTANCE_HANDLE hInstanc writes IGF SCF values **************************************************************************/ static void IGF_WriteEnvelope( /**< out: Q0 | number of bits writen */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ - Word16 *igfAllZero /**< in: Q0 | returns 1 if all IGF scfs are zero, else 0 */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + Word16 *igfAllZero /**< in: Q0 | returns 1 if all IGF scfs are zero, else 0 */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; @@ -319,36 +321,31 @@ static void IGF_WriteEnvelope( IF (*igfAllZero != 0) { - IGF_write_bit(st, pBitOffset, 1); - IF (NULL == st) + IGF_write_bit(hBstr, pBitOffset, 1); + IF (NULL == hBstr) { - IGFSCFEncoderSaveContextState(&hPrivateData->hIGFSCFArithEnc); + IGFSCFEncoderSaveContextState(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); } IGFSCFEncoderReset(&hPrivateData->hIGFSCFArithEnc); - IF (NULL == st) + IF (NULL == hBstr) { - IGFSCFEncoderRestoreContextState(&hPrivateData->hIGFSCFArithEnc); + IGFSCFEncoderRestoreContextState(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); } } ELSE { - IGF_write_bit(st, pBitOffset, 0); - IF (NULL == st) + IGF_write_bit(hBstr, pBitOffset, 0); + IF (NULL == hBstr) { - IGFSCFEncoderSaveContextState(&hPrivateData->hIGFSCFArithEnc); + IGFSCFEncoderSaveContextState(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); } - *pBitOffset = IGFSCFEncoderEncode(&hPrivateData->hIGFSCFArithEnc, - st, - *pBitOffset, - &hPrivateData->igfScfQuantized[hGrid->startSfb], - isIndepFlag, - (NULL != st)); + *pBitOffset = IGFSCFEncoderEncode(&hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag); move16(); - IF (NULL == st) + IF (NULL == hBstr) { - IGFSCFEncoderRestoreContextState(&hPrivateData->hIGFSCFArithEnc); + IGFSCFEncoderRestoreContextState(&hPrivateData->hIGFSCFArithEnc, igfGridIdx); } } @@ -876,25 +873,25 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc write whitening levels into bitstream **************************************************************************/ static void IGF_WriteWhiteningTile( /**< out: Q0 | number of bits written */ - Encoder_State_fx *st, /**< in: | encoder state handle */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - Word16 whiteningLevel /**< in: Q0 | whitening levels to write */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + Word16 whiteningLevel /**< in: Q0 | whitening levels to write */ ) { IF (EQ_32(whiteningLevel, IGF_WHITENING_MID)) { - IGF_write_bits(st, pBitOffset, 0, 1); + IGF_write_bits(hBstr, pBitOffset, 0, 1); } ELSE { - IGF_write_bits(st, pBitOffset, 1, 1); + IGF_write_bits(hBstr, pBitOffset, 1, 1); IF (EQ_32(whiteningLevel , IGF_WHITENING_OFF)) { - IGF_write_bits(st, pBitOffset, 0, 1); + IGF_write_bits(hBstr, pBitOffset, 0, 1); } ELSE { - IGF_write_bits(st, pBitOffset, 1, 1); + IGF_write_bits(hBstr, pBitOffset, 1, 1); } } } @@ -904,7 +901,7 @@ writes the whitening levels **************************************************************************/ static void IGF_WriteWhiteningLevels( /**< out: Q0 | total number of bits written */ const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ @@ -951,15 +948,15 @@ static void IGF_WriteWhiteningLevels( } IF (isSame) { - IGF_write_bits(st, pBitOffset, 1, 1); + IGF_write_bits(hBstr, pBitOffset, 1, 1); } ELSE { IF (!isIndepFlag) { - IGF_write_bits(st, pBitOffset, 0, 1); + IGF_write_bits(hBstr, pBitOffset, 0, 1); } - IGF_WriteWhiteningTile(st, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0]); + IGF_WriteWhiteningTile(hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0]); p = 1; move16(); tmp32 = 0; @@ -984,15 +981,15 @@ static void IGF_WriteWhiteningLevels( IF (!isSame) { - IGF_write_bits(st, pBitOffset, 1, 1); + IGF_write_bits(hBstr, pBitOffset, 1, 1); FOR (p = 1; p < nTiles; p++) { - IGF_WriteWhiteningTile(st, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p]); + IGF_WriteWhiteningTile(hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p]); } } ELSE { - IGF_write_bits(st, pBitOffset, 0, 1); + IGF_write_bits(hBstr, pBitOffset, 0, 1); } } @@ -1003,7 +1000,7 @@ write flattening trigger **************************************************************************/ static void IGF_WriteFlatteningTrigger( /**< out: | number of bits written */ const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ ) { @@ -1013,7 +1010,7 @@ static void IGF_WriteFlatteningTrigger( flatteningTrigger = hInstance->flatteningTrigger; move16(); - IGF_write_bits(st, pBitOffset, flatteningTrigger, 1); + IGF_write_bits(hBstr, pBitOffset, flatteningTrigger, 1); } @@ -1047,7 +1044,7 @@ IGF bitsream writer **************************************************************************/ Word16 IGFEncWriteBitstream( /**< out: | number of bits written per frame */ const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ @@ -1069,20 +1066,20 @@ Word16 IGFEncWriteBitstream( } IGF_WriteEnvelope(hInstance, /* i: instance handle of IGF Encoder */ - st, /* i: encoder state */ + hBstr, /* i: encoder state */ pBitOffset, /* i: ptr to bitOffset counter */ igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ &igfAllZero); /* o: *igfAllZero */ IGF_WriteWhiteningLevels(hInstance, /* i: instance handle of IGF Encoder */ - st, /* i: encoder state */ + hBstr, /* i: encoder state */ pBitOffset, /* i: ptr to bitOffset counter */ igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ IGF_WriteFlatteningTrigger(hInstance, /* i: instance handle of IGF Encoder */ - st, /* i: encoder state */ + hBstr, /* i: encoder state */ pBitOffset); /* i: ptr to bitOffset counter */ hInstance->infoTotalBitsPerFrameWritten = sub(*pBitOffset, startBitCount); @@ -1094,22 +1091,24 @@ Word16 IGFEncWriteBitstream( /**********************************************************************/ /* sets the IGF mode according to given bitrate **************************************************************************/ -void IGFEncSetMode(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word32 bitRate, /**< in: Q0 | encoder bitrate */ - const Word16 mode /**< in: Q0 | encoder bandwidth mode */ - ,const Word16 rf_mode /**< in: Q0 | flag to signal the RF mode */ - ) +void IGFEncSetMode( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ + const Word32 total_brate, /* i : encoder total bitrate */ + const Word16 bwidth, /* i : encoder audio bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; Word16 i; - hPrivateData = &hInstance->igfData; + hPrivateData = &hIGFEnc->igfData; hPrivateData->igfBitstreamBits = 0; move16(); set16_fx(hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB); set16_fx(hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES); set16_fx(hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES); - FOR( i = 0; i < BITBUFSIZE/8; i++) + FOR( i = 0; i < IGF_BITBUFSIZE /8; i++) { hPrivateData->igfBitstream[i] = 0; move16(); @@ -1119,58 +1118,145 @@ void IGFEncSetMode(const IGF_ENC_INSTANCE_HANDLE hInstance, set32_fx(hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES); set16_fx(hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES); - IF (IGFCommonFuncsIGFConfiguration(bitRate, mode, &hPrivateData->igfInfo,rf_mode) != 0) + IF (IGFCommonFuncsIGFConfiguration(total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode) != 0) { - IGFSCFEncoderOpen(&hPrivateData->hIGFSCFArithEnc, - sub(hPrivateData->igfInfo.grid[0].stopSfb, hPrivateData->igfInfo.grid[0].startSfb), - bitRate, - mode - ,rf_mode + IGFSCFEncoderOpen(&hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode); - ); - - hInstance->infoSamplingRate = hPrivateData->igfInfo.sampleRate; + hIGFEnc->infoSamplingRate = hPrivateData->igfInfo.sampleRate; move32(); - hInstance->infoStartFrequency = hPrivateData->igfInfo.grid[0].startFrequency; + hIGFEnc->infoStartFrequency = hPrivateData->igfInfo.grid[0].startFrequency; move16(); - hInstance->infoStopFrequency = hPrivateData->igfInfo.grid[0].stopFrequency; + hIGFEnc->infoStopFrequency = hPrivateData->igfInfo.grid[0].stopFrequency; move16(); - hInstance->infoStartLine = hPrivateData->igfInfo.grid[0].startLine; + hIGFEnc->infoStartLine = hPrivateData->igfInfo.grid[0].startLine; move16(); - hInstance->infoStopLine = hPrivateData->igfInfo.grid[0].stopLine; + hIGFEnc->infoStopLine = hPrivateData->igfInfo.grid[0].stopLine; move16(); } ELSE { /* IGF configuration failed -> error! */ - hInstance->infoSamplingRate = 0; + hIGFEnc->infoSamplingRate = 0; move32(); - hInstance->infoStartFrequency = -1; + hIGFEnc->infoStartFrequency = -1; move16(); - hInstance->infoStopFrequency = -1; + hIGFEnc->infoStopFrequency = -1; move16(); - hInstance->infoStartLine = -1; + hIGFEnc->infoStartLine = -1; move16(); - hInstance->infoStopLine = -1; + hIGFEnc->infoStopLine = -1; move16(); fprintf(stderr,"IGFEncSetMode: initialization error!\n"); } /* reset remaining variables */ - hInstance->infoTotalBitsWritten = 0; + hIGFEnc->infoTotalBitsWritten = 0; move16(); - hInstance->infoTotalBitsPerFrameWritten = 0; + hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); - hInstance->flatteningTrigger = 0; + hIGFEnc->flatteningTrigger = 0; move16(); - hInstance->spec_be_igf_e = 0; + hIGFEnc->spec_be_igf_e = 0; move16(); - hInstance->tns_predictionGain = 0; + hIGFEnc->tns_predictionGain = 0; move16(); - set32_fx(hInstance->spec_be_igf, 0, N_MAX_TCX-IGF_START_MN); + set32_fx(hIGFEnc->spec_be_igf, 0, N_MAX_TCX-IGF_START_MN); + return; +} +#ifdef IVAS_CODE_BITSTREAM + +/*-------------------------------------------------------------------* + * pack_bit() + * + * insert a bit into packed octet + *-------------------------------------------------------------------*/ + +static void pack_bit( + const int16_t bit, /* i : bit to be packed */ + uint8_t** pt, /* i/o: pointer to octet array into which bit will be placed */ + uint8_t* omask /* i/o: output mask to indicate where in the octet the bit is to be written */ +) +{ + if (*omask == 0x80) + { + **pt = 0; + } + + if (bit != 0) + { + **pt = **pt | *omask; + } + + *omask >>= 1; + if (*omask == 0) + { + *omask = 0x80; + (*pt)++; + } + return; } +/*-------------------------------------------------------------------* + * IGFEncConcatenateBitstream() + * + * IGF bitstream concatenation for TCX10 modes + *-------------------------------------------------------------------*/ + +void IGFEncConcatenateBitstream( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + const int16_t bsBits, /* i : number of IGF bits written to list of indices */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +) +{ + int16_t i; + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + Indice* ind_list; + uint8_t* pFrame; /* byte array with bit packet and byte aligned coded speech data */ + int16_t* pFrame_size; /* number of bits in the binary encoded access unit [bits] */ + int16_t k, nb_bits_written; + int32_t imask; + uint8_t omask; + + hPrivateData = &hIGFEnc->igfData; + + ind_list = &hBstr->ind_list[hBstr->nb_ind_tot - bsBits]; /* here, we assume that each bit has been written as a single indice */ + pFrame = hPrivateData->igfBitstream; + pFrame_size = &hPrivateData->igfBitstreamBits; + nb_bits_written = 0; + + omask = (0x80 >> (*pFrame_size & 0x7)); + pFrame += *pFrame_size >> 3; + + /* bitstream packing (conversion of individual indices into a serial stream) */ + for (i = 0; i < bsBits; i++) + { + if (ind_list[i].nb_bits > 0) + { + /* mask from MSB to LSB */ + imask = 1 << (ind_list[i].nb_bits - 1); + + /* write bit by bit */ + for (k = 0; k < ind_list[i].nb_bits; k++) + { + pack_bit(ind_list[i].value & imask, &pFrame, &omask); + imask >>= 1; + } + nb_bits_written += ind_list[i].nb_bits; + + /* delete the indice */ + ind_list[i].nb_bits = -1; + } + } + + *pFrame_size += nb_bits_written; + + /* update list of indices */ + hBstr->nb_ind_tot -= bsBits; + hBstr->nb_bits_tot -= nb_bits_written; + return; +} +#else /**********************************************************************/ /* IGF bitsream concatenation for TCX10 modes **************************************************************************/ @@ -1197,7 +1283,7 @@ void IGFEncConcatenateBitstream(const IGF_ENC_INSTANCE_HANDLE hInstance, return; } - +#endif /**********************************************************************/ /* IGF reset bitsream bit counter for TCX10 modes **************************************************************************/ @@ -1220,8 +1306,8 @@ IGF write concatenated bitsream for TCX10 modes **************************************************************************/ Word16 IGFEncWriteConcatenatedBitstream( /**< out: Q0 | total number of bits written */ const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - void *st /**< in: | encoder state */ -) + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ + ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; Word16 i; @@ -1235,13 +1321,13 @@ Word16 IGFEncWriteConcatenatedBitstream( tmp = shr(hPrivateData->igfBitstreamBits, 3); FOR (i = 0; i < tmp; i++) { - push_next_indice_fx(st, pBitstream[i], 8); + push_next_indice_fx(hBstr, pBitstream[i], 8); } bitsLeft = s_and(hPrivateData->igfBitstreamBits, 0x7); IF(bitsLeft > 0) { - push_next_indice_fx(st, shr(pBitstream[i], sub(8, bitsLeft)), bitsLeft); + push_next_indice_fx(hBstr, shr(pBitstream[i], sub(8, bitsLeft)), bitsLeft); } return hInstance->infoTotalBitsWritten; @@ -1314,3 +1400,4 @@ void IGFEncApplyMono(const IGF_ENC_INSTANCE_HANDLE hInstance, } + diff --git a/lib_enc/igf_scf_enc.c b/lib_enc/igf_scf_enc.c index bce80fe..cfce82e 100644 --- a/lib_enc/igf_scf_enc.c +++ b/lib_enc/igf_scf_enc.c @@ -2,11 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include +#include "options.h" #include "options.h" -#include "stl.h" #include "prot_fx.h" #include "stat_enc_fx.h" #include "stat_com.h" @@ -18,11 +16,12 @@ initialization of an instance of this module **************************************************************************/ void IGFSCFEncoderOpen( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - , Word16 rf_mode /**< in: flag to signal the RF mode */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + H_IGF_INFO hIgfInfo, /* i : IGF info handle */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t element_mode, /* i : IVAS element mode */ + const int16_t rf_mode /* i : flag to signal the RF mode */ ) { @@ -39,30 +38,20 @@ void IGFSCFEncoderOpen( move32(); hPublicData->acState.high = 0; move32(); - hPublicData->acState.vobf = 0; + hPublicData->acState.value = 0; move16(); set16_fx(hPublicData->prev, 0, 64); set16_fx(hPublicData->prevSave, 0, 64); - hPublicData->scfCountLongBlock = scfCountLongBlock; - move16(); + hPublicData->scfCountLongBlock[0] = hIgfInfo->grid[0].swb_offset_len - 1; + hPublicData->scfCountLongBlock[1] = hIgfInfo->grid[1].swb_offset_len - 1; + hPublicData->scfCountLongBlock[2] = hIgfInfo->grid[2].swb_offset_len - 1; + move16();move16();move16(); + hPublicData->t = 0; move16(); /* protect against the invalid request of starting encoding with a dependent block */ - IGFCommonFuncsIGFGetCFTables( - bitRate, - mode, - rf_mode, - &hPublicData->cf_se00, - &hPublicData->cf_se01, - &hPublicData->cf_off_se01, - &hPublicData->cf_se02, - &hPublicData->cf_off_se02, - &hPublicData->cf_se10, - &hPublicData->cf_off_se10, - &hPublicData->cf_se11, - &hPublicData->cf_off_se11 - ); + IGFCommonFuncsIGFGetCFTables(total_brate, bwidth, element_mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11); } @@ -194,12 +183,12 @@ static void arith_encode_residual( static void encode_sfe_vector( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ - Word16 t, /* i: counter reset to 0 at each independent block */ - Word16 *prev_x, /* i: previous vector */ - Word16 *x, /* i: current vector to encode */ - Word16 length /* i: number of elements to encode */ + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Word16 * ptr, /* i : pointer to expanded bit buffer, one bit in each short */ + const Word16 t, /* i : frame counter reset to 0 at each independent frame */ + Word16* prev_x, /* i : previous vector */ + Word16* x, /* i : current vector to encode */ + const Word16 length /* i : number of elements to encode */ ) { /* @@ -329,15 +318,15 @@ void IGFSCFEncoderReset( main encoder function **************************************************************************/ Word16 IGFSCFEncoderEncode( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Encoder_State_fx *st, /* i/o: pointer to encoder state */ - Word16 bitCount, /* i: offset to the first bit in bitbuffer which should be written by the raw AC functions */ - Word16 *sfe, /* i: pointer to an array which contains the quantized SCF energies to be encoded */ - Word16 indepFlag, /* i: 1 if the block is an independent block, 0 otherwise */ - Word16 doRealEncoding /* i: whether the real encoding is needed, otherwise only the number of bits is used */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + Word16* sfe, /* i : ptr to an array which contain quantized scalefactor energies */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { - Word16 ptr[BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each Word16 */ + Word16 ptr[IGF_BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each Word16 */ Word16 i; @@ -356,13 +345,7 @@ Word16 IGFSCFEncoderEncode( IGFSCFEncoderReset(hPublicData); } - encode_sfe_vector(hPublicData, - ptr, - hPublicData->t, - hPublicData->prev, - sfe, - hPublicData->scfCountLongBlock - ); + encode_sfe_vector(hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx]); hPublicData->ptrBitIndex = ari_done_encoding_14bits(ptr, hPublicData->ptrBitIndex, @@ -372,16 +355,16 @@ Word16 IGFSCFEncoderEncode( /* advance history */ - Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock); + Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx]); hPublicData->t = add(hPublicData->t, 1); /* copy the bits from the temporary bit buffer, if doRealEncoding is enabled */ - IF (doRealEncoding != 0) + IF (hBstr) { FOR (i = 0; i < hPublicData->ptrBitIndex; ++i) { - push_next_indice_fx(st, ptr[i], 1); + push_next_indice_fx(hBstr, ptr[i], 1); } } @@ -393,27 +376,21 @@ Word16 IGFSCFEncoderEncode( for a closed loop encoder, the SCF encoder needs to memorize the context **************************************************************************/ void IGFSCFEncoderSaveContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ) { - - hPublicData->tSave = hPublicData->t; move16(); - - Copy(hPublicData->prev, - hPublicData->prevSave, - hPublicData->scfCountLongBlock - ); - - + Copy(hPublicData->prev, hPublicData->prevSave, hPublicData->scfCountLongBlock[igfGridIdx]); } /**********************************************************************/ /** for a closed loop encoder, the SCF encoder needs to memorize the context **************************************************************************/ void IGFSCFEncoderRestoreContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ + const Word16 igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ) { @@ -421,10 +398,7 @@ void IGFSCFEncoderRestoreContextState( hPublicData->t = hPublicData->tSave; move16(); - Copy(hPublicData->prevSave, - hPublicData->prev, - hPublicData->scfCountLongBlock - ); + Copy(hPublicData->prevSave, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx]); } diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index a3f071e..c3604f5 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -7,6 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "stl.h" +#include "ivas_cnst.h" /*-----------------------------------------------------------------------* @@ -14,15 +15,77 @@ * * Initialization of state variables *-----------------------------------------------------------------------*/ -void init_encoder_fx( +ivas_error init_encoder_fx( Encoder_State_fx *st_fx /* i/o: Encoder static variables structure */ ) { Word16 i; Word32 L_tmp; - st_fx->nb_bits_tot_fx = 0; - move16(); + +Word16 idchan = 0; /* i : channel ID */ +Word16 vad_only_flag = 0; /* i : channel ID */ +ISM_MODE ism_mode = ISM_MODE_NONE; + ivas_error error; +PMT("ism_mode, idchan, vad_only_flag to be move to function header") + error = IVAS_ERR_OK; + + + /*-----------------------------------------------------------------* + * General signal buffers + *-----------------------------------------------------------------*/ + if (!vad_only_flag) + { + if ((st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE)count_malloc(sizeof(SIGNAL_BUFFERS_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n")); + } + + st_fx->Bin_E_old_fx = st_fx->hSignalBuf->Bin_E_old_fx; + st_fx->mem_decim_fx = st_fx->hSignalBuf->mem_decim_fx; + st_fx->mem_decim16k_fx = st_fx->hSignalBuf->mem_decim16k_fx; + st_fx->old_inp_12k8_fx = st_fx->hSignalBuf->old_inp_12k8_fx; + st_fx->old_inp_16k_fx = st_fx->hSignalBuf->old_inp_16k_fx; + st_fx->buf_speech_enc_pe = st_fx->hSignalBuf->buf_speech_enc_pe; + st_fx->buf_synth = st_fx->hSignalBuf->buf_synth; + st_fx->buf_speech_enc = st_fx->hSignalBuf->buf_speech_enc; + st_fx->buf_wspeech_enc = st_fx->hSignalBuf->buf_wspeech_enc; + + /* initializations */ + set16_fx(st_fx->old_inp_12k8_fx, 0, L_INP_MEM); /* memory of input signal at 12.8kHz */ + set16_fx(st_fx->old_inp_16k_fx, 0, L_INP_MEM); + set16_fx(st_fx->mem_decim16k_fx, 0, 2 * L_FILT_MAX); + set16_fx(st_fx->mem_decim_fx, 0, 2 * L_FILT_MAX); + set32_fx(st_fx->Bin_E_old_fx, 0, L_FFT/2); + + + st_fx->input_buff = st_fx->hSignalBuf->input_buff; + set16_fx(st_fx->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS)); + st_fx->old_input_signal_fx = st_fx->input_buff; + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + st_fx->input = st_fx->input_buff + st_fx->input_Fs_fx / FRAMES_PER_SEC + NS2SA(st_fx->input_Fs_fx, DELAY_FIR_RESAMPL_NS); + } + ELSE + { + st_fx->input = st_fx->input_buff + st_fx->input_Fs_fx / FRAMES_PER_SEC; + } + } + else + { + st_fx->hSignalBuf = NULL; + st_fx->Bin_E_old_fx = NULL; + st_fx->mem_decim_fx = NULL; + st_fx->mem_decim16k_fx = NULL; + st_fx->old_inp_12k8_fx = NULL; + st_fx->old_inp_16k_fx = NULL; + st_fx->buf_speech_enc_pe = NULL; + st_fx->buf_synth = NULL; + st_fx->buf_speech_enc = NULL; + st_fx->buf_wspeech_enc = NULL; + st_fx->input_buff = NULL; + } + /*-----------------------------------------------------------------* * ACELP core parameters *-----------------------------------------------------------------*/ @@ -38,8 +101,6 @@ void init_encoder_fx( move16(); st_fx->last_coder_type_fx = GENERIC; move16(); - st_fx->last_7k2_coder_type_fx = GENERIC; - move16(); st_fx->last_total_brate_fx = st_fx->total_brate_fx; move32(); st_fx->last_total_brate_cng_fx = -1; @@ -56,6 +117,36 @@ void init_encoder_fx( move16(); st_fx->rate_switching_reset_16kHz = 0; move16(); + + /*-----------------------------------------------------------------* + * Bitstream + *-----------------------------------------------------------------*/ + + IF (!vad_only_flag) + { + IF ((st_fx->hBstr = (BSTR_ENC_HANDLE)count_malloc(sizeof(BSTR_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n")); + } +#ifdef IVAS_CODE_BITSTREAM + + /* set pointer to the buffer of indices */ + st->hBstr->ind_list = st_ivas->ind_list; + st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; + st->hBstr->nb_ind_tot = 0; + st->hBstr->nb_bits_tot = 0; + st->hBstr->st_ivas = st_ivas; +#endif + } + ELSE + { + st_fx->hBstr = NULL; + } + st_fx->hBstr->nb_bits_tot_fx = 0; + move16(); + + Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); @@ -72,21 +163,27 @@ void init_encoder_fx( init_gp_clip_fx( st_fx->clip_var_fx ); pitch_ol_init_fx( &st_fx->old_thres_fx, &st_fx->old_pitch, &st_fx->delta_pit_fx, &st_fx->old_corr_fx ) ; - hf_cod_init_fx( st_fx->mem_hp400_enc_fx, st_fx->mem_hf_enc_fx, st_fx->mem_syn_hf_enc_fx, st_fx->mem_hf2_enc_fx, &st_fx->gain_alpha_fx ); - - st_fx->LPDmem.tilt_code = 0; - move16(); - st_fx->LPDmem.gc_threshold = 0; - move16(); + /*-----------------------------------------------------------------* + * AMR-WB IO initialization + *-----------------------------------------------------------------*/ + test(); + IF (st_fx->Opt_AMR_WB_fx || EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF ((st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE)count_malloc(sizeof(AMRWB_IO_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n")); + } + amr_wb_enc_init(st_fx->hAmrwb_IO); + } + ELSE + { + st_fx->hAmrwb_IO = NULL; + } st_fx->clas_fx = UNVOICED_CLAS; move16(); - set16_fx( st_fx->old_inp_12k8_fx, 0, L_INP_MEM); /* memory of input signal at 12.8kHz */ - set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); - set16_fx( st_fx->LPDmem.old_exc, 0, L_EXC_MEM ); set16_fx( st_fx->old_wsp2_fx, 0, (L_WSP_MEM - L_INTERPOL)/OPL_DECIM ); - set16_fx( st_fx->old_inp_16k_fx, 0, L_INP_MEM ); - + set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); st_fx->mem_deemph_fx = 0; move16(); st_fx->mem_preemph_fx = 0; @@ -110,22 +207,11 @@ void init_encoder_fx( st_fx->mem_wsp_enc = 0; move16(); - set16_fx( st_fx->mem_decim16k_fx, 0, 2*L_FILT_MAX ); st_fx->mem_wsp_fx = 0; move16(); - st_fx->LPDmem.mem_w0 = 0; - move16(); - set16_fx( st_fx->LPDmem.mem_syn, 0, M ); - set16_fx( st_fx->mem_syn1_fx, 0, M ); - st_fx->mem_deemph_old_syn_fx = 0; - move16(); - set16_fx( st_fx->LPDmem.mem_syn2, 0, M ); - set16_fx( st_fx->mem_decim_fx, 0, 2*L_FILT_MAX ); - set16_fx( st_fx->mem_decim2_fx, 0, 3 ); set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); + set16_fx( st_fx->mem_decim2_fx, 0, 3 ); set16_fx( st_fx->lgBin_E_fx, 0, L_FFT/2 ); - set32_fx( st_fx->Bin_E_old_fx, 0, L_FFT/2 ); - set16_fx( st_fx->LPDmem.mem_syn3, 0, M ); st_fx->ini_frame_fx = 0; move16(); @@ -143,24 +229,6 @@ void init_encoder_fx( move16(); set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); - st_fx->Last_Resort_fx = 0; - st_fx->set_ppp_generic_fx = 0; - - st_fx->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = 0; - move32(); - - FOR(i=2; i<8; i++) - { - st_fx->dm_fx.prev_gain_pit[i-2] = 0; - move16(); - } - - st_fx->seed2_enc_fx = RANDOM_INITSEED; - move16(); - - st_fx->old_hpfilt_in_fx = 0; move16(); st_fx->old_hpfilt_out_fx = 0; @@ -171,11 +239,6 @@ void init_encoder_fx( move16(); - FOR (i=0; ipast_qua_en_fx[i] = -14336; /* Q10gain quantization memory (used also in AMR-WB IO mode) */ - } - IF( EQ_32(st_fx->input_Fs_fx,8000)) { st_fx->min_band_fx = 1; @@ -190,16 +253,6 @@ void init_encoder_fx( st_fx->max_band_fx = 19; move16(); } - - FOR( i=0; ifr_bands1_fx[i] = 1; - move32();/*1e-5f; */ - st_fx->fr_bands2_fx[i] = 1; - move32();/*1e-5f; */ - st_fx->ave_enr2_fx[i] = E_MIN_FX; - move32(); /*Q7//E_MIN; */ - } IF ( st_fx->Opt_AMR_WB_fx ) { Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); @@ -218,9 +271,6 @@ void init_encoder_fx( st_fx->stab_fac_fx = 0; move16(); - - MDCT_selector_reset(st_fx); - /* Bass post-filter memories - encoder side of MODE2 */ st_fx->bpf_off_fx = 0; move16(); @@ -232,15 +282,30 @@ void init_encoder_fx( move16(); /* AC mode */ - st_fx->seed_tcx_fx = 15687; - move16(); - st_fx->cor_strong_limit_fx = 1; - move16(); - set16_fx( st_fx->last_exc_dct_in_fx, 0, L_FRAME ); - st_fx->last_ener_fx = 0; - set16_fx( st_fx->last_bitallocation_band_fx, 0, 6 ); - st_fx->mem_last_pit_band_fx = BAND1k2+1; + /*-----------------------------------------------------------------* + * parameters for AC coder type (GSC) + *-----------------------------------------------------------------*/ + + //st_fx->GSC_noisy_speech = 0; + st_fx->GSC_IVAS_mode = 0; + + test();test(); + IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF ((st_fx->hGSCEnc = (GSC_ENC_HANDLE)count_malloc(sizeof(GSC_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); + } + + GSC_enc_init(st_fx->hGSCEnc); + } + ELSE + { + st_fx->hGSCEnc = NULL; + } + + st_fx->last_ener_fx = 0; move16(); st_fx->old_dE1_fx = 0; @@ -258,183 +323,107 @@ void init_encoder_fx( move16(); /* speech/music classifier */ - st_fx->inact_cnt_fx = 0; + st_fx->Last_pulse_pos_fx = 0; move16(); - set16_fx(st_fx->past_dec_fx, 0, HANG_LEN-1 ); - set16_fx(st_fx->past_dlp_fx, 0, HANG_LEN-1 ); - set16_fx(st_fx->past_log_enr_fx, -1448, NB_BANDS_SPMUS); /* log(E_MIN) in Q8 */ - st_fx->sp_mus_state_fx = -8; - move16(); - st_fx->wdrop_fx = 0; - move16(); - st_fx->wdlp_0_95_sp_fx = 0; - move16(); - set16_fx( st_fx->last_lsp_fx, 0, M_LSP_SPMUS ); - st_fx->last_cor_map_sum_fx = 0; - move16(); - st_fx->last_non_sta_fx = 0; - move16(); - set32_fx( st_fx->past_PS_fx, 0, HIGHEST_FBIN-LOWEST_FBIN ); - st_fx->past_ps_diff_fx = 0; - move16(); - st_fx->past_epsP2_fx = 1024; + st_fx->last_vad_spa_fx = 0; move16(); + /*-----------------------------------------------------------------* + * VAD + *-----------------------------------------------------------------*/ - st_fx->gsc_thres_fx[0] = TH_0_MIN_FX; - move16(); - st_fx->gsc_thres_fx[1] = TH_1_MIN_FX; - move16(); - st_fx->gsc_thres_fx[2] = TH_2_MIN_FX; - move16(); - st_fx->gsc_thres_fx[3] = TH_3_MIN_FX; - move16(); - set16_fx(st_fx->gsc_lt_diff_etot_fx, 0, 40); - st_fx->gsc_mem_etot_fx = 0; - move16(); - st_fx->gsc_last_music_flag_fx = 0; - move16(); - st_fx->gsc_nb_thr_1_fx = 0; - move16(); - st_fx->gsc_nb_thr_3_fx = 0; - move16(); - st_fx->mold_corr_fx = 29491; - move16(); - st_fx->lt_gpitch_fx = 0; - move16(); - st_fx->mean_avr_dyn_fx = 64; - move16();/*Q7 */ - st_fx->last_sw_dyn_fx = 2560; - move16(); - st_fx->pit_exc_hangover = 0; - move16(); - st_fx->Last_pulse_pos_fx = 0; - move16(); - - /* speech/music classifier improvement */ - FOR ( i=0; ivad_flag = 1; + st_fx->localVAD = 0; + move16();move16(); + test();test();test();test(); + IF ((idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, EVS_MONO)) && (!vad_only_flag)) { - st_fx->buf_flux_fx[i] = -12800; - move16(); /*-100.0 in Q7 */ - st_fx->buf_pkh_fx[i] = 0; + if ((st_fx->hVAD = (VAD_HANDLE)count_malloc(sizeof(VAD_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n")); + } + + wb_vad_init_fx(st_fx->hVAD); + st_fx->hVAD->prim_act_quick_fx = 0; move16(); - st_fx->buf_epsP_tilt_fx[i] = 0; + st_fx->hVAD->prim_act_slow_fx = 0; move16(); - st_fx->buf_cor_map_sum_fx[i] = 0; + st_fx->hVAD->prim_act_fx = 0; move16(); - st_fx->buf_Ntonal_fx[i] = 0; + st_fx->hVAD->prim_act_quick_he_fx = 0; move16(); - st_fx->buf_Ntonal2_fx[i] = 0; + st_fx->hVAD->prim_act_slow_he_fx = 0; move16(); - st_fx->buf_Ntonal_lf_fx[i] = 0; + st_fx->hVAD->prim_act_he_fx = 0; + move16(); + st_fx->hVAD->hangover_terminate_flag_fx = 0; move16(); - } - - set16_fx(st_fx->lpe_buf_fx, 0, HANG_LEN_INIT); - set16_fx(st_fx->voicing_buf_fx, 0, HANG_LEN_INIT); - st_fx->gsc_hangover_fx = 0; - move16(); - set16_fx(st_fx->sparse_buf_fx, 0, HANG_LEN_INIT); - set16_fx(st_fx->hf_spar_buf_fx, 0, HANG_LEN_INIT); - st_fx->LT_sparse_fx = 0; - move16(); - st_fx->gsc_cnt_fx = 0; - move16(); - st_fx->last_vad_spa_fx = 0; - move16(); - - set16_fx( st_fx->old_Bin_E_fx, 0, 3*N_OLD_BIN_E ); - set16_fx( st_fx->buf_etot_fx, 0, 4 ); - set16_fx( st_fx->buf_dlp_fx, 0, 10 ); - - st_fx->UV_cnt1_fx = 300; - move16(); - st_fx->LT_UV_cnt1_fx = 16000; - move16(); /*250.0f in Q6 */ - st_fx->onset_cnt_fx = 0; - move16(); - st_fx->attack_hangover_fx = 0; - move16(); - st_fx->dec_mov_fx = 0; - move16(); - st_fx->dec_mov1_fx = 0; - move16(); - st_fx->mov_log_max_spl_fx = 25600; - move16(); /*200.0 in Q7 */ - st_fx->old_lt_diff_fx[0] = 0; - move16(); - st_fx->old_lt_diff_fx[1] = 0; - move16(); - - /* GSC - pitch excitation parameters */ - st_fx->mem_w0_tmp_fx = 0; - move16(); - set16_fx(st_fx->mem_syn_tmp_fx, 0, M); - st_fx->high_stable_cor_fx = 0; - move16(); - set16_fx(st_fx->var_cor_t_fx, 0, VAR_COR_LEN); - st_fx->lps_fx = 0; - move16(); - st_fx->lpm_fx = 0; - move16(); - st_fx->Last_frame_ener_fx = MAX_32; - move32(); - st_fx->lt_dec_thres_fx = 5120; - move16(); /*10 in Q9 */ - st_fx->ener_RAT_fx = 0; - move16(); - st_fx->mid_dyn_fx = 5120; - move16(); /*40 -> Q7 */ - st_fx->noise_lev_fx = NOISE_LEVEL_SP0; - move16(); - st_fx->past_dyn_dec_fx = 0; - move16(); + st_fx->hVAD->consec_inactive_fx = 0; + move16(); + st_fx->hVAD->spectral_tilt_reset_fx = 1; + move16(); + st_fx->hVAD->running_avg_fx = 0; + move16(); + st_fx->hVAD->ra_deltasum_fx = 0; + move16(); + st_fx->hVAD->trigger_SID_fx = 0; + move16(); + st_fx->hVAD->L_snr_sum_vad_fx = 0; + move32(); + } + else + { + st_fx->hVAD = NULL; + } - wb_vad_init_fx( &st_fx->nb_active_frames_fx, &st_fx->hangover_cnt_fx, &st_fx->lp_speech_fx, &st_fx->nb_active_frames_he_fx, - &st_fx->hangover_cnt_he_fx, &st_fx->bcg_flux_fx, &st_fx->soft_hangover_fx, &st_fx->voiced_burst_fx, - &st_fx->bcg_flux_init_fx, &st_fx->nb_active_frames_he1_fx, &st_fx->hangover_cnt_he1_fx, - &st_fx->L_vad_flag_reg_H_fx, &st_fx->L_vad_flag_reg_L_fx, &st_fx->L_vad_prim_reg_fx, &st_fx->vad_flag_cnt_50_fx, - &st_fx->vad_prim_cnt_16_fx, &st_fx->hangover_cnt_dtx_fx, &st_fx->hangover_cnt_music_fx ); st_fx->Pos_relE_cnt = 5120; move16(); /*20.0f*/ - st_fx->nb_active_frames_HE_SAD_fx = 0; - move16(); + st_fx->nb_active_frames_HE_SAD_fx = 0;move16(); + st_fx->lp_speech_fx = 11520;move16(); /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + /* avoid uninitialized memory access */ - noise_est_init_fx( &st_fx->totalNoise_fx, &st_fx->first_noise_updt_fx, st_fx->bckr_fx, st_fx->enrO_fx, - st_fx->ave_enr_fx, &st_fx->pitO_fx, &st_fx->aEn_fx, &st_fx->harm_cor_cnt_fx,&st_fx->bg_cnt_fx, - &st_fx->lt_tn_track_fx, &st_fx->lt_tn_dist_fx, &st_fx->lt_Ellp_dist_fx, - &st_fx->lt_haco_ev_fx, &st_fx->low_tn_track_cnt_fx - ,&st_fx->Etot_st_est_fx,&st_fx->Etot_sq_st_est_fx - ); - st_fx->epsP_0_2_lp_fx = 4096; /*1.0 Q12*/ move16(); - st_fx->epsP_0_2_ad_lp_fx = 0; - move16(); - st_fx->epsP_2_16_lp_fx = 4096; - move16(); - st_fx->epsP_2_16_lp2_fx = 4096; - move16(); - st_fx->epsP_2_16_dlp_lp2_fx = 0; - move16(); - st_fx->lt_aEn_zero_fx = 0; - move16(); + /*-----------------------------------------------------------------* + * Noise estimator + *-----------------------------------------------------------------*/ + PMT("deal with idchan ") + IF (/*idchan == 0 ||*/ EQ_16(st_fx->element_mode, IVAS_CPE_TD) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, EVS_MONO) ) + { + if ((st_fx->hNoiseEst = (NOISE_EST_HANDLE)count_malloc(sizeof(NOISE_EST_DATA))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n"); + } + noise_est_init_fx(st_fx->hNoiseEst); + } + ELSE + { + st_fx->hNoiseEst = NULL; + } + /*-----------------------------------------------------------------* + * Speech/music classifier + *-----------------------------------------------------------------*/ + test();test(); + IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_TD) || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) || EQ_16(st_fx->element_mode, EVS_MONO) ) + { + IF ((st_fx->hSpMusClas = (SP_MUS_CLAS_HANDLE)count_malloc(sizeof(SP_MUS_CLAS_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n")); + } + speech_music_clas_init(st_fx->hSpMusClas); + st_fx->sp_aud_decision0 = 0; + st_fx->sp_aud_decision1 = 0; + st_fx->sp_aud_decision2 = 0; + move16();move16();move16(); + } + ELSE + { + st_fx->hSpMusClas = NULL; + } - st_fx->prim_act_quick_fx=0; - move16(); - st_fx->prim_act_slow_fx=0; - move16(); - st_fx->prim_act_fx=0; - move16(); - st_fx->prim_act_quick_he_fx=0; - move16(); - st_fx->prim_act_slow_he_fx=0; - move16(); - st_fx->prim_act_he_fx=0; - move16(); st_fx->bckr_tilt_lt=0; move32(); @@ -460,22 +449,16 @@ void init_encoder_fx( st_fx->last_bwidth_cng_fx = st_fx->bwidth_fx; move16(); - /* Tonal detector */ - FOR ( i=0; iold_S_fx[i] = 1; - move16(); - } - set16_fx( st_fx->cor_map_fx, 0, L_FFT/2 ); - st_fx->act_pred_fx = 32767; - move16(); - st_fx->noise_char_fx = 0; - move16(); - st_fx->multi_harm_limit_fx = THR_CORR_INIT_FX; + move16(); st_fx->coder_type_raw_fx = VOICED; st_fx->last_coder_type_raw_fx = st_fx->coder_type_raw_fx; - + + st_fx->is_ism_format = 0; move16(); + if (NE_16(ism_mode, ISM_MODE_NONE) ) + { + st_fx->is_ism_format = 1; move16(); + } /* Stationary noise UV modification */ st_fx->ge_sm_fx = 640; move32();/*Q(GE_SHIFT) */ @@ -494,65 +477,27 @@ void init_encoder_fx( /* CNG and DTX */ st_fx->lp_noise_fx = 0; move16(); - Copy( st_fx->lsp_old1_fx, st_fx->lspCNG_fx, M ); - st_fx->cng_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->cng_ener_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->cng_ener_seed1_fx = RANDOM_INITSEED; - st_fx->lp_ener_fx = 0; - move32(); - st_fx->first_CNG_fx = 0; - move16(); - st_fx->cnt_SID_fx = 0; - move16(); - st_fx->max_SID_fx = 2; - move16(); - st_fx->old_enr_index_fx = -1; - move16(); - st_fx->Enew_fx = 0; - move32(); - st_fx->VarDTX_cnt_voiced_fx = 0; - move16(); - st_fx->lt_ener_voiced_fx = 0; - move32(); - st_fx->VarDTX_cnt_noise_fx = 0; - move16(); - st_fx->lt_ener_noise_fx = 0; - move32(); - st_fx->lt_ener_last_SID_fx = 0; - move32(); - if( st_fx->var_SID_rate_flag_fx ) + + test();test(); + IF (((idchan == 0 && st_fx->Opt_DTX_ON_fx) || EQ_16(st_fx->element_mode, EVS_MONO)) || (EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && st_fx->Opt_DTX_ON_fx)) { - st_fx->interval_SID_fx = 12; - move16(); + if ((st_fx->hDtxEnc = (DTX_ENC_HANDLE)count_malloc(sizeof(DTX_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n")); + } + dtx_enc_init(st_fx, st_fx->var_SID_rate_flag_fx, st_fx->interval_SID_fx); + + } + ELSE + { + st_fx->hDtxEnc = NULL; } - st_fx->lp_sp_enr_fx = 0; - move16(); - st_fx->last_allow_cn_step_fx = 0; - move16(); st_fx->fd_cng_reset_flag = 0; move16(); IF( st_fx->Opt_DTX_ON_fx ) { - st_fx->cng_hist_ptr_fx = -1; - move16(); - set16_fx( st_fx->cng_lsp_hist_fx, 0, DTX_HIST_SIZE*M ); - set16_fx( st_fx->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); - st_fx->cng_cnt_fx = 0; - move16(); - - st_fx->ho_hist_ptr_fx = -1; - move16(); - st_fx->ho_sid_bw_fx = L_deposit_l(0); - set16_fx( st_fx->ho_lsp_hist_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_hist_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_hist_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_hist_size_fx = 0; - move16(); - st_fx->act_cnt_fx = 0; move16(); } st_fx->active_fr_cnt_fx = 0; @@ -560,69 +505,47 @@ void init_encoder_fx( st_fx->cng_type_fx = -1; move16(); - st_fx->CNG_mode_fx = -1; - move16(); - st_fx->last_active_brate_fx = ACELP_7k20; - move32(); - st_fx->last_CNG_L_frame_fx = L_FRAME; - move16(); - set16_fx( st_fx->ho_16k_lsp_fx, 0, HO_HIST_SIZE ); - st_fx->act_cnt2_fx = 0; - move16(); - st_fx->num_ho_fx = 0; - move16(); - st_fx->hangover_terminate_flag_fx = 0; - move16(); - st_fx->ho_circ_ptr_fx = -1; - move16(); - set16_fx( st_fx->ho_lsp_circ_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_circ_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_circ_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_circ_size_fx = 0; - move16(); - st_fx->burst_ho_cnt_fx = 0; - move16(); - st_fx->cng_buf_cnt = 0; - move16(); + /*-----------------------------------------------------------------* + * LP-CNG + *-----------------------------------------------------------------*/ - test(); - test(); - IF( st_fx->var_SID_rate_flag_fx || ((!st_fx->var_SID_rate_flag_fx) && (st_fx->interval_SID_fx >= DTX_HIST_SIZE)) ) + test();test();test(); + IF (((idchan == 0 && st_fx->Opt_DTX_ON_fx && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, EVS_MONO)) && !(EQ_16(ism_mode, ISM_MODE_PARAM) || EQ_16(ism_mode, ISM_MODE_DISC))) { - st_fx->cng_hist_size_fx = DTX_HIST_SIZE; - move16(); + IF ((st_fx->hTdCngEnc = (TD_CNG_ENC_HANDLE)count_malloc(sizeof(TD_CNG_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n")); + } + + td_cng_enc_init(st_fx->hTdCngEnc, st_fx->Opt_DTX_ON_fx, st_fx->max_bwidth_fx); } ELSE { - st_fx->cng_hist_size_fx = st_fx->interval_SID_fx; - move16(); + st_fx->hTdCngEnc = NULL; } - set32_fx(st_fx->lp_env_fx, 0, 20); - set32_fx(st_fx->cng_res_env_fx, 0, 20*8); - set16_fx(st_fx->exc_mem_fx, 0, 24); - set16_fx(st_fx->exc_mem1_fx, 0, 30); - set16_fx(st_fx->exc_mem2_fx, 0, 30); - set32_fx(st_fx->old_env_fx, 0, NUM_ENV_CNG); - /* SWB CNG/DTX */ - st_fx->last_wb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->last_shb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->mov_wb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->mov_shb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->shb_cng_ini_cnt_fx = 1; - move16(); - st_fx->shb_NO_DATA_cnt_fx = 0; - move16(); - st_fx->last_SID_bwidth_fx = s_min(st_fx->max_bwidth_fx, SWB); - st_fx->last_vad_fx = 0; - move16(); - /* FEC */ + /*-----------------------------------------------------------------* + * ACELP LPDmem + *-----------------------------------------------------------------*/ + + test();test(); + IF ((idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) || EQ_16(st_fx->element_mode, IVAS_CPE_TD)) + { + IF ((st_fx->hLPDmem = (LPD_state_HANDLE)count_malloc(sizeof(LPD_state))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n")); + } + + LPDmem_enc_init(st_fx->hLPDmem); + } + ELSE + { + st_fx->hLPDmem = NULL; + } + + /* FEC */ st_fx->last_clas_fx = UNVOICED_CLAS; move16(); @@ -642,41 +565,21 @@ void init_encoder_fx( *-----------------------------------------------------------------*/ /* open analysis for input SR */ - openCldfb ( &st_fx->cldfbAna_Fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(st_fx->input_Fs_fx), st_fx->input_frame_fx ); + if ((error = openCldfb ( &st_fx->cldfbAna_Fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(st_fx->input_Fs_fx), st_fx->input_frame_fx )) != IVAS_ERR_OK) + { + return error; + } - openCldfb ( &st_fx->cldfbSyn_Fx, CLDFB_SYNTHESIS, CLDFB_getNumChannels(16000), L_FRAME16k); + if ((error = openCldfb ( &st_fx->cldfbSyn_Fx, CLDFB_SYNTHESIS, CLDFB_getNumChannels(16000), L_FRAME16k)) != IVAS_ERR_OK) + { + return error; + } st_fx->energyCoreLookahead_Fx = 0; move32(); st_fx->sf_energyCoreLookahead_Fx = 0; move16(); - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ - - st_fx->nelp_enc_seed_fx = 0; - move16(); - st_fx->last_nelp_mode_fx = 0; - move16(); - st_fx->pppcountE_fx = 0; - move16(); - st_fx->last_ppp_mode_fx = 0; - move16(); - st_fx->last_last_ppp_mode_fx = 0; - move16(); - st_fx->firstTime_voicedenc_fx = 1; - move16(); - st_fx->prev_ppp_gain_pit_fx = 0; - move16(); - st_fx->prev_tilt_code_fx = 0; - move16(); - - st_fx->ppp_mode_fx = 0; - move16(); - st_fx->nelp_mode_fx = 0; - move16(); - /* stable short pitch detection */ st_fx->voicing0_sm_fx = 0; move16(); @@ -691,53 +594,86 @@ void init_encoder_fx( st_fx->energy_sm_fx = 0; move32(); - st_fx->pattern_m_fx = 0; - move16(); - st_fx->Last_Resort_fx = 0; - move16(); - st_fx->Q_to_F_fx = 0; - move16(); + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ + test(); + IF (st_fx->Opt_SC_VBR_fx || EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF ((st_fx->hSC_VBR = (SC_VBR_ENC_HANDLE)count_malloc(sizeof(SC_VBR_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); + } - st_fx->numactive_fx = 0; /* keep the count of the frames inside current 600 frame bloack.*/ - st_fx->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ - st_fx->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - st_fx->frame_cnt_ratewin_fx = 0; /* 600 active frame block count. Used to update the global rate*/ - st_fx->rate_control_fx = 0; - move16(); - st_fx->SNR_THLD_fx = SNR_THLD_FX_Q8; - move16(); - st_fx->mode_QQF_fx = 1; - move16(); + sc_vbr_enc_init(st_fx->hSC_VBR); + } + ELSE + { + st_fx->hSC_VBR = NULL; + } + /* PLC encoder */ + IF (EQ_16(st_fx->element_mode, EVS_MONO)) + { + IF ((st_fx->hPlcExt = (PLC_ENC_EVS_HANDLE)count_malloc(sizeof(PLC_ENC_EVS))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n")); + } + } + ELSE + { + st_fx->hPlcExt = NULL; + } + /*-----------------------------------------------------------------* + * Temporal Envelope Coding + *-----------------------------------------------------------------*/ + IF (st_fx->element_mode == EVS_MONO) + { + IF ((st_fx->hTECEnc = (TEC_ENC_HANDLE_FX)count_malloc(sizeof(TEC_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); + } + } + ELSE + { + st_fx->hTECEnc = NULL; + } /*-----------------------------------------------------------------* - * SWB BWE parameters + * Bitstream *-----------------------------------------------------------------*/ - set16_fx( st_fx->new_input_hp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)); - set16_fx( st_fx->old_input_fx, 0, NS2SA(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) ); - set16_fx( st_fx->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS) ); - set16_fx( st_fx->old_input_lp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS) ); - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - - st_fx->prev_mode_fx = NORMAL; - move16(); - st_fx->modeCount_fx = 0; - move16(); - st_fx->EnergyLF_fx = 0; - move32(); + IF (!vad_only_flag) + { + IF ((st_fx->hBstr = (BSTR_ENC_HANDLE)count_malloc(sizeof(BSTR_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n")); + } + } + ELSE + { + st_fx->hBstr = NULL; + } - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF ((st_fx->hBWE_FD = (FD_BWE_ENC_HANDLE)count_malloc(sizeof(FD_BWE_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n")); + } - st_fx->prev_Q_input_lp = 0; - move16(); + fd_bwe_enc_init(st_fx->hBWE_FD); + } + ELSE + { + st_fx->hBWE_FD = NULL; + } - st_fx->prev_global_gain_fx = 0; - move32(); st_fx->prev_Q_shb = 0; move16(); - st_fx->prev_L_swb_norm1_fx = 8; - move16(); st_fx->last_Opt_SC_VBR_fx = 0; move16(); @@ -745,52 +681,43 @@ void init_encoder_fx( * TBE parameters *-----------------------------------------------------------------*/ - InitSWBencBuffer_fx(st_fx); - ResetSHBbuffer_Enc_fx(st_fx); - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( st_fx->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16); - set16_fx( st_fx->old_input_fhb_fx, 0, NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2); - st_fx->old_input_fhb_fx_Q = 0; - move16(); - st_fx->cldfbHBLT = 8192/*1.0f Q13*/; + IF (idchan == 0 && NE_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF ((st_fx->hBWE_TD = (TD_BWE_ENC_HANDLE)count_malloc(sizeof(TD_BWE_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n")); + } - st_fx->prev_gainFr_SHB_fx = 0; - set16_fx(st_fx->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER); - set16_fx(st_fx->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER); - set16_fx( st_fx->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->lsp_shb_spacing_fx, 3277, 3); - st_fx->prev_swb_GainShape_fx= 0; - move16(); - st_fx->prev_frGainAtten_fx = 0; - move16(); - st_fx->prev_wb_GainShape = 0; - move16(); - st_fx->prev_Q_bwe_exc_fb = 51; - move16(); - set16_fx(st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); - st_fx->fb_tbe_demph_fx = 0; - move16(); - st_fx->tilt_mem_fx = 0; - move16(); - st_fx->prev_coder_type_fx = GENERIC; - move16(); - set16_fx( st_fx->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = 0; - move16(); - set16_fx( st_fx->cur_sub_Aq_fx, 0, M+1 ); + //IF ((error = openCldfb(&st_fx->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + //{ + // return error; + //} + + InitSWBencBuffer_fx(st_fx/*st_fx->hBWE_TD*/); + ResetSHBbuffer_Enc_fx(st_fx/*st_fx->hBWE_TD*/); + } + ELSE + { + st_fx->hBWE_TD = NULL; + //st_fx->cldfbSynTd = NULL; + } - /* TD BWE post-processing */ - st_fx->ptr_mem_stp_swb_fx = st_fx->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx(st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER); - FOR ( i=0; iOpt_RF_ON || EQ_16(st_fx->element_mode, EVS_MONO)) { - st_fx->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + IF ((st_fx->hRF = (RF_ENC_HANDLE)count_malloc(sizeof(RF_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n")); + } + + /* initialize RF indice buffers */ + reset_rf_indices(st_fx/*->hRF, st_fx->L_frame_fx, &st->rf_target_bits_write*/); + } + ELSE + { + st_fx->hRF = NULL; } - set16_fx( st_fx->dec_2_over_3_mem_fx, 0, 12 ); - set16_fx( st_fx->dec_2_over_3_mem_lp_fx, 0, 6 ); - set16_fx( st_fx->old_fdbwe_speech_fx, 0, L_FRAME48k ); /*-----------------------------------------------------------------* * HQ core parameters @@ -800,8 +727,6 @@ void init_encoder_fx( set16_fx( st_fx->input_buff+L_FRAME48k, 0, L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS) ); st_fx->old_input_signal_fx = st_fx->input - add(NS2SA_fx2(st_fx->input_Fs_fx, DELAY_FIR_RESAMPL_NS), st_fx->input_frame_fx); - st_fx->Q_old_out = 0; - move16(); st_fx->Energy_Old_fx = 0; move16(); @@ -814,77 +739,62 @@ void init_encoder_fx( st_fx->TransientHangOver_fx = 0; move16(); - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); - st_fx->mode_count_fx = 0; - move16(); - st_fx->mode_count1_fx = 0; - move16(); + /*-----------------------------------------------------------------* + * TCX core + *-----------------------------------------------------------------*/ - st_fx->hq_generic_speech_class_fx = 0; - move16(); - st_fx->prev_Npeaks_fx = 0; - set16_fx(st_fx->prev_peaks_fx, 0, HVQ_MAX_PEAKS); - st_fx->hvq_hangover_fx = 0; - st_fx->prev_hqswb_clas_fx = HQ_NORMAL; + // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 + IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF ((st_fx->hTcxEnc = (TCX_ENC_HANDLE)count_malloc(sizeof(TCX_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n")); + } - set16_fx(st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - st_fx->clas_sec_old_fx = 8192; /* 1.0f in Q13 */; - st_fx->clas_final_old_fx = 1; /* Q0 */ - st_fx->last_gain1 = 0; - move32(); - st_fx->last_gain2 = 0; - move32(); - st_fx->last_enerBuffer_exp = 0; - move16(); - /* speech/music classification */ - set16_fx(st_fx->lt_old_mode, 1, 3); - st_fx->lt_voicing = 16384/*0.5f Q15*/; - st_fx->lt_corr = 16384/*0.5f Q15*/; - st_fx->lt_tonality = 0; - move32(); - set16_fx(st_fx->lt_corr_pitch, 0, 3); - st_fx->lt_hangover = 0; - move16(); - st_fx->lowrate_pitchGain = 0; - move16(); + /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ + /*st_fx->hTcxEnc->spectrum[0] = st_fx->hTcxEnc->spectrum_long; + st_fx->hTcxEnc->spectrum[1] = st_fx->hTcxEnc->spectrum_long + N_TCX10_MAX;*/ + set16_fx(st_fx->hTcxEnc->old_out_fx, 0, L_FRAME32k); - st_fx->lt_music_hangover_fx = 0; - move16(); - set16_fx(st_fx->tonality2_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->tonality3_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->LPCErr_buf_fx,0,HANG_LEN_INIT); - st_fx->lt_music_state_fx = 0; - move16(); - st_fx->lt_speech_state_fx = 0; - move16(); - st_fx->lt_speech_hangover_fx = 0; - move16(); - st_fx->consec_inactive_fx = 0; - move16(); - st_fx->spectral_tilt_reset_fx = 1; - move16(); - st_fx->running_avg_fx = 0; - move16(); - st_fx->ra_deltasum_fx = 0; - move16(); - st_fx->trigger_SID_fx = 0; - move16(); - st_fx->L_snr_sum_vad_fx = 0; - move32(); + /* MDCT selector */ + MDCT_selector_reset(st_fx->hTcxEnc); + st_fx->hTcxEnc->Q_old_out = 0; + move16(); - set16_fx( st_fx->prev_frm_index_fx, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB ); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - st_fx->prev_ni_ratio_fx = 16384; - move16(); /* 0.5 */ - set16_fx(st_fx->prev_En_sb_fx, 0, NB_SWB_SUBBANDS); - set16_fx(st_fx->last_bitalloc_max_band_fx, 0, 2); - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; + /* MDCT classifier */ + MDCT_classifier_reset(st_fx->hTcxEnc); + + IF ((st_fx->hTcxCfg = (TCX_CONFIG_HANDLE)count_malloc(sizeof(TCX_config))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n")); + } + } + else + { + st_fx->hTcxEnc = NULL; + //st_fx->hTcxCfg = NULL; + } + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ + + test();test(); + IF (NE_16(st_fx->element_mode, IVAS_CPE_TD) && NE_16(st_fx->element_mode, IVAS_CPE_MDCT) && idchan == 0) + { + IF ((st_fx->hHQ_core = (HQ_ENC_HANDLE)count_malloc(sizeof(HQ_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n")); + } + + HQ_core_enc_init(st_fx->hHQ_core); + } + ELSE + { + st_fx->hHQ_core = NULL; + } + + st_fx->last_enerBuffer_exp = 0; move16(); /*-----------------------------------------------------------------* @@ -925,10 +835,27 @@ void init_encoder_fx( st_fx->last_sr_core = i_mult2 (st_fx->last_L_frame_fx, 50); + /*-----------------------------------------------------------------* + * IGF + *-----------------------------------------------------------------*/ + + test();test(); + IF (idchan == 0 || EQ_16(st_fx->element_mode, IVAS_CPE_MDCT)) + { + IF ((st_fx->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE)count_malloc(sizeof(IGF_ENC_INSTANCE))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n")); + } + } + ELSE + { + st_fx->hIGFEnc = NULL; + move16(); + } IF( EQ_16(st_fx->codec_mode, MODE2)) { - st_fx->igf = getIgfPresent( st_fx->total_brate_fx, st_fx->bwidth_fx, st_fx->rf_mode); + st_fx->igf = getIgfPresent(st_fx->element_mode, st_fx->total_brate_fx, st_fx->bwidth_fx, st_fx->rf_mode); } ELSE { @@ -954,13 +881,13 @@ void init_encoder_fx( set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st_fx->totalNoise_increase_len_fx = 0; move16(); - init_coder_ace_plus( st_fx, 0); - + init_coder_ace_plus( st_fx, st_fx->last_total_brate_fx, 0, 0); +PMT("Transient detector init needs review, handle hTranDet is missing") InitTransientDetection( extract_l(Mult_32_16(st_fx->input_Fs_fx, 0x0290)), NS2SA_fx2(st_fx->input_Fs_fx, DELAY_FIR_RESAMPL_NS), &st_fx->transientDetection ); - reset_indices_enc_fx( st_fx ); + //reset_indices_enc_fx( st_fx->hBstr); st_fx->Q_syn2 = 0; @@ -975,20 +902,71 @@ void init_encoder_fx( move16(); st_fx->old_wsp_shift = 0; move16(); - - st_fx->vbr_generic_ho_fx = 0; - move16(); - st_fx->sharpFlag = 0; move16(); - st_fx->Local_VAD = 0; + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + st_fx->GSC_IVAS_mode = 0; /* CNG in SBA flag */ + st_fx->element_mode = EVS_MONO; /* element mode */ + st_fx->last_element_mode = st_fx->element_mode; /* element mode */ + st_fx->element_brate = -1; /* element bitrate */ + PMT("element_mode and element_brate should be initialized at a proper place in ivas_dec_init eventually") + st_fx->low_rate_mode = 0; /* low-rate mode flag */ + //st_fx->coder_type_fx = GENERIC; /* low-rate mode flag */ - set16_fx( st_fx->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); + set16_fx(st_fx->pitch_fx, L_SUBFR, 3); + set16_fx(st_fx->voicing_fx, 0, 3); - return; + +#ifdef DEBUGGING + st_fx->id_element = -1; /* element ID */ +#endif + st_fx->extl_orig = -1; /* extension layer */ + st_fx->extl_brate_orig = 0; /* extension layer bitrate */ + + return error; } +/*-----------------------------------------------------------------------* + * LPDmem_enc_init() + * + * Initialization of ACELP LPDmem state variables + *-----------------------------------------------------------------------*/ +void LPDmem_enc_init( + LPD_state_HANDLE hLPDmem /* i/o: LP memories */ +) +{ + Word16 i; + + set16_fx(hLPDmem->syn, 0, 1 + M); + set16_fx(hLPDmem->old_exc, 0, L_EXC_MEM); + set16_fx(hLPDmem->mem_syn, 0, M); + set16_fx(hLPDmem->mem_syn1_fx, 0, M); + set16_fx(hLPDmem->mem_syn2, 0, M); + set16_fx(hLPDmem->mem_syn_r, 0, L_SYN_MEM); + set16_fx(hLPDmem->mem_syn3, 0, M); + + hLPDmem->mem_w0 = 0; move16(); + hLPDmem->tilt_code = 0; move16(); + hLPDmem->gc_threshold = 0; move32(); +#if 0 + //set16_fx(hLPDmem->dispMem, 0, 8); +#else + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR(i = 2; i < 8; i++) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } +#endif + return; +} /*-----------------------------------------------------------------------* * destroy_encoder() * diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index dc89b04..8462a9e 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /*==============================================================================*/ @@ -55,36 +54,38 @@ /*==============================================================================*/ Word16 inov_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16 *cn, /* i/o: target vector in residual domain Q_new*/ - const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ - Word16 *h2, /* i/o: weighted filter input response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16 *unbits, /* o : number of unused bits for PI */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 last_L_frame, /* i : length of the last frame */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 sharpFlag, /* i : formant sharpening flag */ + const Word16 i_subfr, /* i : subframe index */ + const Word16 tc_subfr, /* i : TC subframe index */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ + const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ + Word16 *cn, /* i/o: target vector in residual domain Q_new*/ + const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ + Word16 *h2, /* i/o: weighted filter input response Q12*/ + const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ + const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ + Word16 *code, /* o : algebraic excitation Q9*/ + Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ + Word16 *unbits, /* o : number of unused bits for PI */ + const Word16 L_subfr, /* i : subframe length */ Word16 shift ) { - Word16 dn[L_SUBFR]; + Word16 dn[2*L_SUBFR]; Word16 nBits, cmpl_flag; Word16 stack_pulses; Word16 g1, g2; Word16 Rw[L_SUBFR]; Word16 acelpautoc; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; stack_pulses = 0; move16(); @@ -111,12 +112,13 @@ Word16 inov_encode_fx( *----------------------------------------------------------------*/ test(); - IF (GT_32(core_brate, ACELP_13k20)&&!Opt_AMR_WB) + test(); + IF (GT_32(core_brate, ACELP_13k20) && !Opt_AMR_WB && EQ_16(L_subfr, L_SUBFR)) { acelpautoc = 1; move16(); - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 ); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 , L_SUBFR); /* h2: Q11, Rw: (Rw_e)Q */ /* Rw_e = */ E_ACELP_hh_corr(h2, Rw, L_SUBFR, 3); @@ -129,11 +131,11 @@ Word16 inov_encode_fx( { acelpautoc = 0; move16(); - updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_SUBFR ); + updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr ); /* scaling of cn[] to limit dynamic at 12 bits */ - Scale_sig(cn, L_SUBFR, shift); + Scale_sig(cn, L_subfr, shift); - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 ); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 , L_subfr); corr_xh_fx( xn2, dn, h2 ); } @@ -144,30 +146,31 @@ Word16 inov_encode_fx( cmpl_flag = 0; move16(); test(); - IF( EQ_16(L_frame,L_FRAME)&&EQ_16(coder_type,TRANSITION)) + IF (st_fx->acelp_cfg.fcb_mode) + { + /* set number of iterations in TD stereo, secondary channel */ + if (EQ_16(st_fx->element_mode, IVAS_CPE_TD) && EQ_16(st_fx->idchan, 1)) + { + cmpl_flag = 1; + move16(); + } + } + ELSE IF( EQ_16(L_frame,L_FRAME) && EQ_16(coder_type,TRANSITION)) { - test(); - test(); - if( EQ_32(core_brate,ACELP_8k00)&&i_subfr==0&<_16(tc_subfr,L_SUBFR)) + test();test(); + if( EQ_32(core_brate,ACELP_8k00) && i_subfr==0 && LT_16(tc_subfr,L_SUBFR)) { cmpl_flag = 3; move16(); } - test(); - test(); - test(); - test(); - test(); - if( EQ_32(core_brate,ACELP_11k60)&&((i_subfr==0&<_16(tc_subfr,L_SUBFR))||EQ_16(tc_subfr,TC_0_0)||(EQ_16(i_subfr,3*L_SUBFR)&&EQ_16(tc_subfr,TC_0_64)))) + test();test();test();test();test(); + if( EQ_32(core_brate,ACELP_11k60) && ((i_subfr==0 && LT_16(tc_subfr,L_SUBFR)) || EQ_16(tc_subfr,TC_0_0) || (EQ_16(i_subfr,3*L_SUBFR) && EQ_16(tc_subfr,TC_0_64)))) { cmpl_flag = 3; move16(); } - test(); - test(); - test(); - test(); - if( (EQ_32(core_brate,ACELP_13k20)||EQ_32(core_brate,ACELP_12k15))&&((i_subfr==0&<_16(tc_subfr,L_SUBFR))||LE_16(tc_subfr,TC_0_64))) + test();test();test();test(); + if( (EQ_32(core_brate,ACELP_13k20) || EQ_32(core_brate,ACELP_12k15)) && ((i_subfr==0 && LT_16(tc_subfr,L_SUBFR)) || LE_16(tc_subfr,TC_0_64))) { cmpl_flag = 3; move16(); @@ -239,7 +242,7 @@ Word16 inov_encode_fx( test(); test(); test(); - IF( NE_16(L_frame,last_L_frame)&>_32(core_brate,ACELP_13k20)&&(LT_32(core_brate,ACELP_32k)||EQ_16(bwidth,WB))) + IF( NE_16(L_frame,st_fx->last_L_frame_fx)&>_32(core_brate,ACELP_13k20)&&(LT_32(core_brate,ACELP_32k)||EQ_16(bwidth,WB))) { if( GT_16(cmpl_flag,1)) { @@ -255,68 +258,143 @@ Word16 inov_encode_fx( IF ( !Opt_AMR_WB ) { - IF( EQ_16(L_frame,L_FRAME)) - { - nBits = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - } + IF (st_fx->acelp_cfg.fcb_mode) + { PMTE() +#ifdef IVAS_CODE + if (st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] < ACELP_FIXED_CDK_NB) + { + int16_t wordcnt, bitcnt; + int16_t prm[8]; - IF( EQ_16(nBits,7)) - { - acelp_1t64_fx( st_fx, dn, h2, code, y2 ); - } - ELSE IF( EQ_16(nBits,12)) - { - acelp_2t32_fx(st_fx, dn, h2, code, y2 ); + if (st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0) + { + if (L_subfr == 2 * L_SUBFR) + { + nBits = st->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + + if (nBits == 8) + { + acelp_1t64(hBstr, dn, h1, code, y2, L_subfr); + } + else + { + acelp_fast(hBstr, nBits, dn, cn, h1, code, y2, L_subfr); + } + } + else if ((st->idchan == 1 && st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7) || (st->idchan == 0 && st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3)) + { + if (st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0) + { + acelp_1t64(hBstr, dn, h1, code, y2, L_subfr); + } + else + { + acelp_fast(hBstr, st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], dn, cn, h1, code, y2, L_SUBFR); + } + } + else + { + E_ACELP_4t(dn, cn, h1, Rw, acelpautoc, code, st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], prm, L_frame, last_L_frame, st->total_brate, i_subfr, cmpl_flag); + + wordcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) >> 4; + bitcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) & 15; + + for (i = 0; i < wordcnt; i++) + { + push_indice(hBstr, IND_ALG_CDBK_4T64, prm[i], 16); + } + if (bitcnt) + { + push_indice(hBstr, IND_ALG_CDBK_4T64, prm[i], bitcnt); + } + + /* Generate weighted code */ + set_f(y2, 0.0f, L_SUBFR); + for (i = 0; i < L_SUBFR; i++) + { + /* Code is sparse, so check which samples are non-zero */ + if (code[i] != 0) + { + for (k = 0; k < L_SUBFR - i; k++) + { + y2[i + k] += code[i] * h1[k]; + } + } + } + } + } + else + { + set_f(code, 0.0f, L_SUBFR); + set_f(y2, 0.0f, L_SUBFR); + } + } +#ifdef DEBUGGING + else + { + IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "invalid mode for acelp frame!\n"); + } +#endif +#endif } ELSE { - *unbits = add(*unbits, acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB)); + nBits = st_fx->acelp_cfg.fixed_cdk_index[shr(i_subfr, 6)]; move16(); + + + IF(EQ_16(nBits, 7)) + { + acelp_1t64_fx(hBstr, dn, h2, code, y2, L_SUBFR); + } + ELSE IF(EQ_16(nBits, 12)) + { + acelp_2t32_fx(hBstr, dn, h2, code, y2); + } + ELSE + { + *unbits = add(*unbits, acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB)); + move16(); + } } } ELSE { IF (EQ_32(core_brate,ACELP_6k60)) { - acelp_2t32_fx( st_fx, dn, h2, code, y2 ); + acelp_2t32_fx(hBstr, dn, h2, code, y2 ); } ELSE IF( (EQ_32(core_brate,ACELP_8k85))) { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB ); } ELSE IF( EQ_32(core_brate,ACELP_12k65)) { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB ); } ELSE IF( EQ_32(core_brate,ACELP_14k25)) { - acelp_4t64_fx( st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB ); } ELSE IF( EQ_32(core_brate,ACELP_15k85)) { - acelp_4t64_fx( st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB ); } ELSE IF( EQ_32(core_brate,ACELP_18k25)) { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB ); } ELSE IF( EQ_32(core_brate,ACELP_19k85)) { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB ); } ELSE IF( EQ_32(core_brate,ACELP_23k05)) { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); } ELSE IF( EQ_32(core_brate,ACELP_23k85)) { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB); + acelp_4t64_fx(hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB); } } @@ -325,7 +403,7 @@ Word16 inov_encode_fx( * Pitch sharpening *----------------------------------------------------------------*/ - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0 ); + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0 , L_subfr); return stack_pulses; diff --git a/lib_enc/isf_enc_amr_wb_fx.c b/lib_enc/isf_enc_amr_wb_fx.c index 26da8d5..84096c8 100644 --- a/lib_enc/isf_enc_amr_wb_fx.c +++ b/lib_enc/isf_enc_amr_wb_fx.c @@ -1,13 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required by wmc_tool */ /*-----------------------------------------------------------------* @@ -29,12 +28,12 @@ #define N_SURV_MAX 4 /* maximum number of survivors */ /*---------------------------------------------------------------------* - * Local functions + * Local function prototypes *---------------------------------------------------------------------*/ -static void qisf_ns_28b_fx( Encoder_State_fx *st, Word16 *isf ); -static void qisf_2s_46b_fx( Encoder_State_fx *st, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); -static void qisf_2s_36b_fx( Encoder_State_fx *st, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); +static void qisf_ns_28b_fx(BSTR_ENC_HANDLE hBstr, Word16 *isf ); +static void qisf_2s_46b_fx(BSTR_ENC_HANDLE hBstr, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); +static void qisf_2s_36b_fx(BSTR_ENC_HANDLE hBstr, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); static void VQ_stage1_fx(const Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word16 *index, const Word16 surv); static Word16 sub_VQ_fx(Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word32 *distance); @@ -45,14 +44,13 @@ static Word16 sub_VQ_fx(Word16 *x, const Word16 *dico, const Word16 dim, const W *-------------------------------------------------------------------*/ void isf_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - Word16 *isf_new, /* i/o: quantized ISF vector */ - Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac /* o : ISF stability factor */ + Encoder_State_fx *st, /* i/o: state structure */ + Word16 *isf_new, /* i/o: quantized ISF vector */ + Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ + Word16 *Aq /* o : quantized A(z) for 4 subframes */ ) { - + BSTR_ENC_HANDLE hBstr = st->hBstr; /*---------------------------------* * ISF quantization of SID frames @@ -60,7 +58,7 @@ void isf_enc_amr_wb_fx( IF ( EQ_32(st->core_brate_fx,SID_1k75)) { - qisf_ns_28b_fx( st, isf_new ); + qisf_ns_28b_fx( hBstr, isf_new ); reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2); @@ -71,7 +69,7 @@ void isf_enc_amr_wb_fx( } /* check resonance for pitch clipping algorithm */ - gp_clip_test_isf_fx( st->core_brate_fx, isf_new, st->clip_var_fx, 1 ); + gp_clip_test_isf_fx(st->element_mode, st->core_brate_fx, isf_new, st->clip_var_fx, 1 ); /*---------------------------------------* * ISF quantization of all other frames @@ -79,11 +77,11 @@ void isf_enc_amr_wb_fx( IF ( EQ_32(st->core_brate_fx,ACELP_6k60)) { - qisf_2s_36b_fx( st, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); + qisf_2s_36b_fx( hBstr, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); } ELSE IF( GE_32(st->core_brate_fx,ACELP_8k85)) { - qisf_2s_46b_fx( st, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); + qisf_2s_46b_fx( hBstr, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); } reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 ); @@ -106,9 +104,10 @@ void isf_enc_amr_wb_fx( /*------------------------------------------------------------------* * Calculate ISF stability (distance between old ISF and current ISF) *------------------------------------------------------------------*/ - - *stab_fac = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, L_FRAME ); - + IF (NE_32(st->last_core_brate_fx, SID_1k75) ) + { + st->stab_fac_fx = lsf_stab_fx(isf_new, st->lsf_old_fx, 1, L_FRAME); + } return; } @@ -120,7 +119,7 @@ void isf_enc_amr_wb_fx( *-------------------------------------------------------------------*/ static void qisf_ns_28b_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ Word16 *isf /* i/o: unquantized/quantized ISF vector */ ) { @@ -145,11 +144,11 @@ static void qisf_ns_28b_fx( indice[4] = add(sub_VQ_fx(&isf[12],dico5_ns_28b_fx+4, 4, DICO5_NS_28b-1, &tmp), 1); /* First vector has a problem -> do not allow */ /* write indices to array */ - push_indice_fx( st, IND_ISF_0_0, indice[0], 6 ); - push_indice_fx( st, IND_ISF_0_1, indice[1], 6 ); - push_indice_fx( st, IND_ISF_0_2, indice[2], 6 ); - push_indice_fx( st, IND_ISF_0_3, indice[3], 5 ); - push_indice_fx( st, IND_ISF_0_4, indice[4], 5 ); + push_indice_fx(hBstr, IND_ISF_0_0, indice[0], 6 ); + push_indice_fx(hBstr, IND_ISF_0_1, indice[1], 6 ); + push_indice_fx(hBstr, IND_ISF_0_2, indice[2], 6 ); + push_indice_fx(hBstr, IND_ISF_0_3, indice[3], 5 ); + push_indice_fx(hBstr, IND_ISF_0_4, indice[4], 5 ); /* decoding the ISFs */ disf_ns_28b_fx( indice, isf); @@ -168,7 +167,7 @@ static void qisf_ns_28b_fx( *---------------------------------------------------------------------*/ static void qisf_2s_36b_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ Word16 *isf, /* i/o: unquantized/quantized ISF vector */ Word16 nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ Word16 *mem_AR, /* o : quantizer memory for AR model */ @@ -276,11 +275,11 @@ static void qisf_2s_36b_fx( indice[0] = Indirect_dico1[indice[0]]; move16(); /* Make interoperable with G722.2 */ - push_indice_fx( st, IND_ISF_0_0, indice[0], 8 ); - push_indice_fx( st, IND_ISF_0_1, indice[1], 8 ); - push_indice_fx( st, IND_ISF_1_0, indice[2], 7 ); - push_indice_fx( st, IND_ISF_1_1, indice[3], 7 ); - push_indice_fx( st, IND_ISF_1_2, indice[4], 6 ); + push_indice_fx(hBstr, IND_ISF_0_0, indice[0], 8 ); + push_indice_fx(hBstr, IND_ISF_0_1, indice[1], 8 ); + push_indice_fx(hBstr, IND_ISF_1_0, indice[2], 7 ); + push_indice_fx(hBstr, IND_ISF_1_1, indice[3], 7 ); + push_indice_fx(hBstr, IND_ISF_1_2, indice[4], 6 ); return; } @@ -296,7 +295,7 @@ static void qisf_2s_36b_fx( *-------------------------------------------------------------------*/ static void qisf_2s_46b_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ Word16 *isf, /* i/o: unquantized/quantized ISF vector */ Word16 nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ Word16 *mem_AR, /* o : quantizer memory for AR model */ @@ -410,13 +409,13 @@ static void qisf_2s_46b_fx( indice[0] = Indirect_dico1[indice[0]]; move16(); /* Make interoperable with G722.2 */ - push_indice_fx( st, IND_ISF_0_0, indice[0], 8 ); - push_indice_fx( st, IND_ISF_0_1, indice[1], 8 ); - push_indice_fx( st, IND_ISF_1_0, indice[2], 6 ); - push_indice_fx( st, IND_ISF_1_1, indice[3], 7 ); - push_indice_fx( st, IND_ISF_1_2, indice[4], 7 ); - push_indice_fx( st, IND_ISF_1_3, indice[5], 5 ); - push_indice_fx( st, IND_ISF_1_4, indice[6], 5 ); + push_indice_fx(hBstr, IND_ISF_0_0, indice[0], 8 ); + push_indice_fx(hBstr, IND_ISF_0_1, indice[1], 8 ); + push_indice_fx(hBstr, IND_ISF_1_0, indice[2], 6 ); + push_indice_fx(hBstr, IND_ISF_1_1, indice[3], 7 ); + push_indice_fx(hBstr, IND_ISF_1_2, indice[4], 7 ); + push_indice_fx(hBstr, IND_ISF_1_3, indice[5], 5 ); + push_indice_fx(hBstr, IND_ISF_1_4, indice[6], 5 ); return; } @@ -432,7 +431,7 @@ static void VQ_stage1_fx( const Word16 *dico, /* i : ISF codebook */ const Word16 dim, /* i : codebook dimension */ const Word16 dico_size, /* i : codebook size */ - Word16 *index, /* o : indices of best vector candidates */ + Word16 *index, /* o : indices of best vector candidates */ const Word16 surv /* i : nb of surviving best candidates */ ) { @@ -491,12 +490,12 @@ static void VQ_stage1_fx( * Quantization of a subvector in Split-VQ of ISFs *-------------------------------------------------------------------*/ -static Word16 sub_VQ_fx( /* o : selected codebook vector index */ - Word16 *x, /* i/o: ISF vector */ - const Word16 *dico, /* i : ISF codebook */ - const Word16 dim, /* i : codebook dimension */ - const Word16 dico_size, /* i : codebook size */ - Word32 *distance /* o : quantization error (min. distance) */ +static Word16 sub_VQ_fx( /* o : selected codebook vector index */ + Word16 *x, /* i/o: ISF vector */ + const Word16 *dico, /* i : ISF codebook */ + const Word16 dim, /* i : codebook dimension */ + const Word16 dico_size, /* i : codebook size */ + Word32 *distance /* o : quantization error (min. distance) */ ) { Word32 dist_min, dist; diff --git a/lib_enc/ivas_rom_enc.h b/lib_enc/ivas_rom_enc.h new file mode 100644 index 0000000..7194264 --- /dev/null +++ b/lib_enc/ivas_rom_enc.h @@ -0,0 +1,133 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_ROM_ENC_H +#define IVAS_ROM_ENC_H + +#include +#include "options.h" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "cnst.h" +#include "ivas_cnst.h" + + +/*----------------------------------------------------------------------------------* + * Stereo classifiers + *----------------------------------------------------------------------------------*/ + +extern const int16_t unclr_isel_td[]; +extern const float unclr_mean_td[]; +extern const float unclr_scale_td[]; +extern const float unclr_coef_td[]; + +extern const int16_t xtalk_isel_td[]; +extern const float xtalk_mean_td[]; +extern const float xtalk_scale_td[]; +extern const float xtalk_coef_td[]; + +extern const int16_t xtalk_isel_dft[]; +extern const float xtalk_mean_dft[]; +extern const float xtalk_scale_dft[]; +extern const float xtalk_coef_dft[]; + +extern const int16_t unclr_isel_dft[]; +extern const float unclr_mean_dft[]; +extern const float unclr_scale_dft[]; +extern const float unclr_coef_dft[]; + +/*----------------------------------------------------------------------------------* + * Stereo IC-BWE ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float icbwe_thr_TDM[]; +extern const float icbwe_thr_DFT[]; +extern const float icbwe_regressionValuesTDM[]; +extern const float icbwe_regressionValuesDFT[]; + +/*----------------------------------------------------------------------------------* + * DFT stereo ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int16_t itd_vad_band_tbl[]; +extern const int16_t ild_q[]; + +extern const float Wn_table[]; + +extern const float win_ana_8k[STEREO_DFT_OVL_8k]; +extern const float win_ana_12k8[STEREO_DFT_OVL_12k8]; +extern const float win_ana_16k[STEREO_DFT_OVL_16k]; +extern const float win_ana_32k[STEREO_DFT_OVL_32k]; +extern const float win_ana_48k[STEREO_DFT_OVL_MAX]; + +extern const float win_syn_8k[STEREO_DFT_OVL_8k]; +extern const float win_syn_12k8[STEREO_DFT_OVL_12k8]; +extern const float win_syn_16k[STEREO_DFT_OVL_16k]; +extern const float win_syn_32k[STEREO_DFT_OVL_32k]; +extern const float win_syn_48k[STEREO_DFT_OVL_MAX]; + +extern const float win_mdct_8k[STEREO_DFT_OVL_8k]; + +/*----------------------------------------------------------------------------------* + * Range Coder ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float ari_bit_estimate_s17_LC[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; + +/*----------------------------------------------------------------------------------* + * ECLVQ Stereo ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int16_t log2_1px_table[65]; +extern const float log2TB[ECSQ_log2TB_SIZE]; +extern const float ECSQ_log2_fact[1 + ECSQ_SEGMENT_SIZE]; +extern const uint16_t ECSQ_tab_param[ECSQ_CONFIG_COUNT][1 + ECSQ_PARAM_COUNT]; +extern const uint16_t *const ECSQ_tab_abs_lsbs[1 + 4]; +extern const uint16_t ECSQ_tab_vals[ECSQ_PARAM_COUNT - 1][1 + ECSQ_TAB_VALS_SIZE]; + + +/*----------------------------------------------------------------------------------* + * Stereo downmix to EVS ROM tables + *----------------------------------------------------------------------------------*/ + +extern const float Stereo_dmx_s_wnd_coef_eps_16k[L_FRAME16k * 3 / 4]; +extern const float Stereo_dmx_s_wnd_coef_eps_32k[L_FRAME32k * 3 / 4]; +extern const float Stereo_dmx_s_wnd_coef_eps_48k[L_FRAME48k * 3 / 4]; +extern const float Stereo_dmx_s_wnd_coef_16k[L_FRAME16k >> 4]; +extern const float Stereo_dmx_s_wnd_coef_32k[L_FRAME32k >> 4]; +extern const float Stereo_dmx_s_wnd_coef_48k[L_FRAME48k >> 4]; +extern const float Stereo_dmx_wnd_coef_32k[L_FRAME32k]; +extern const float Stereo_dmx_wnd_coef_48k[L_FRAME48k]; + + +#endif diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h new file mode 100644 index 0000000..f5cff65 --- /dev/null +++ b/lib_enc/ivas_stat_enc.h @@ -0,0 +1,1141 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_STAT_ENC_H +#define IVAS_STAT_ENC_H + +#include +#include "options.h" +#include "ivas_cnst.h" +#include "cnst_fx.h" +#include "stat_enc_fx.h" +#include "ivas_cnst.h" +#include "ivas_stat_com.h" + + +/*----------------------------------------------------------------------------------* + * DFT Stereo encoder structures + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_itd_data_struct +{ + int16_t prev_itd; + float itd[STEREO_DFT_ENC_DFT_NB]; + float deltaItd[STEREO_DFT_ENC_DFT_NB]; + int16_t td_itd[STEREO_DFT_ENC_DFT_NB]; + int16_t td_itd_32k[STEREO_DFT_ENC_DFT_NB]; + int16_t itd_index[STEREO_DFT_ENC_DFT_NB]; + float xcorr_smooth[STEREO_DFT_N_32k_ENC]; + float lp_phat_peak; /* low-pass GCC PHAT peak value */ + int16_t itd_hangover; /* ITD hangover counter */ + int16_t itd_cnt; /* Consecutive valid ITD counter */ + float prev_sum_nrg_L_lb; + float prev_xcorr_lb[STEREO_DFT_XCORR_LB_MAX]; + float E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM]; + int16_t vad_frm_cnt; + int16_t pre_vad; + int16_t itd_nonzero_cnt; + float acorr_L[STEREO_DFT_BAND_MAX]; + float acorr_R[STEREO_DFT_BAND_MAX]; + float cohSNR; + float itd_thres; + int16_t valid_itd_cnt; /* Extra variable to store value of itd_cnt for fine-control decision making */ + + int16_t detected_itd_flag; + int16_t itd_tracking; + float prev_max; + int16_t prev_index; + float prev_avg_max; + float currFlatness; + + /* Xtalk classifier */ + float prev_m1; + float prev_m2; + int16_t prev_itd1; + int16_t prev_itd2; + +} ITD_DATA, *ITD_DATA_HANDLE; + +typedef struct dft_ana_struct +{ + /*Sizes*/ + int16_t N; /* Size of the frame and hop */ + int16_t NFFT; /* Size of the FFT=frame size+overlap */ + + /*FFT*/ + int16_t dft_ovl; /* Overlap size */ + int16_t dft_zp; /* Zero padding */ + + const float *win_ana; /* DFT analysis window */ + const float *dft_trigo; + const float *dft_trigo_32k; + int16_t dft_trigo_step; + +} DFT_ANA, *DFT_ANA_HANDLE; + +/* State of the range encoder */ +typedef struct +{ + uint32_t rc_low; + uint32_t rc_range; + int16_t rc_cache; + int16_t rc_carry; + int16_t rc_carry_count; + + uint8_t byte_buffer[RANGE_UNI_BUFFER_BYTES_MAX]; + int16_t byte_count; + int16_t last_byte_bit_count; + +} RangeUniEncState; + + +typedef struct stereo_dft_enc_data_struct +{ + STEREO_DFT_CONFIG_DATA_HANDLE hConfig; + + /*Sizes*/ + int16_t N; /* Size of the frame and hop */ + int16_t NFFT; /* Size of the FFT=frame size+overlap */ + + /*FFT*/ + float DFT[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC]; + int16_t dft_ovl; /* Overlap size */ + int16_t dft_zp; /* Zero padding */ + + const float *win; /* DFT window */ + const float *win_8k; /* DFT window */ + const float *win_12k8; /* DFT window */ + const float *win_16k; /* DFT window */ + const float *win_32k; /* DFT window */ + + const float *win_ana; /* DFT analysis window */ + const float *win_ana_8k; /* DFT analysis window */ + const float *win_ana_12k8; /* DFT analysis window */ + const float *win_ana_16k; /* DFT analysis window */ + const float *win_ana_32k; /* DFT analysis window */ + + const float *win_mdct_8k; /* DFT analysis window */ + + const float *dft_trigo; + const float *dft_trigo_8k; + const float *dft_trigo_12k8; + const float *dft_trigo_16k; + const float *dft_trigo_32k; + int16_t dft_trigo_step; + + float output_mem_res_8k[STEREO_DFT_OVL_8k]; + + /*I/O channel buffers */ + float output_mem_dmx[STEREO_DFT_OVL_MAX]; + float output_mem_dmx_12k8[STEREO_DFT_OVL_12k8]; + float output_mem_dmx_16k[STEREO_DFT_OVL_16k]; /*can hold 16, 12.8 or 32kHz signals*/ + float output_mem_dmx_32k[STEREO_DFT_OVL_32k]; /*can hold 16, 12.8 or 32kHz signals*/ + float output_mem_dmx_16k_shb[STEREO_DFT_OVL_16k]; + float input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX]; + + /*Bands*/ + int16_t band_res[STEREO_DFT_ENC_DFT_NB]; + int16_t band_limits[STEREO_DFT_BAND_MAX + 1]; + int16_t nbands; + int16_t band_limits_dmx[STEREO_DFT_BAND_MAX + 1]; + int16_t nbands_dmx; + + /*Stereo parameters*/ + float past_nrgL[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + float past_nrgR[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + float past_dot_prod_real[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + float past_dot_prod_imag[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + int16_t nrg_past_pos; + + /*Side Gain*/ + float side_gain[STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX]; + int16_t side_gain_flag_1; + int16_t side_gain_flag_2; + int16_t side_gain_index_ECDiff[STEREO_DFT_BAND_MAX]; + int16_t side_gain_index_ECprevious[STEREO_DFT_BAND_MAX]; + int16_t side_gain_index_EC[STEREO_DFT_BAND_MAX]; + int16_t side_gain_counter; + float side_gain_bitdiff_lp; + + /* Stereo CNG */ + float sidSideGain[STEREO_DFT_ERB4_BANDS]; + float win_ana_energy; + float xspec_smooth[STEREO_DFT_N_32k_ENC]; + float Spd_L_smooth[STEREO_DFT_N_32k_ENC / 2]; + float Spd_R_smooth[STEREO_DFT_N_32k_ENC / 2]; + float sid_gipd; + int16_t coh_fade_counter; + + /*IPD*/ + float gipd[STEREO_DFT_ENC_DFT_NB]; + int16_t gipd_band_max; + int16_t gipd_index; + int16_t no_ipd_flag; /* flag to indicate when group IPD gets used */ + int16_t prev_no_ipd_flag; /* flag from previous frame */ + int16_t no_ipd_cnt; /* counter */ + int16_t no_ipd_cnt1; /* counter */ + int16_t attackPresent; + int16_t wasTransient; + float gainIPD_sm; /* long-term gain IPD for NIPD detection */ + float sfm; + float sum_dot_prod_real; + float sum_dot_prod_img; + + /*ITD*/ + ITD_DATA_HANDLE hItd; + + float voicing_lt; + +#ifdef ITD_WINNER_GAIN_MODIFY + float noise_coherence; + int16_t local_vad; + int16_t mus_flag; + float spd_L_noise[STEREO_DFT_N_32k_ENC / 2]; /*The estimation of spectral power density of noise in the left channel*/ + float spd_R_noise[STEREO_DFT_N_32k_ENC / 2]; /*The estimation of spectral power density of noise in the right channel*/ + float spd_L_noise_min[STEREO_DFT_N_32k_ENC / 2]; + float spd_R_noise_min[STEREO_DFT_N_32k_ENC / 2]; + float spd_L_noise_max[STEREO_DFT_N_32k_ENC / 2]; + float spd_R_noise_max[STEREO_DFT_N_32k_ENC / 2]; + float winner_gain_L[STEREO_DFT_N_32k_ENC / 2]; /*The estimation of the Winner gain of the left channel*/ + float winner_gain_R[STEREO_DFT_N_32k_ENC / 2]; /*The estimation of the Winner gain of the right channel*/ + float spd_L_smooth_new[STEREO_DFT_N_32k_ENC / 2]; + float spd_R_smooth_new[STEREO_DFT_N_32k_ENC / 2]; + +#endif + + /* energy buffers for ICBWE */ + float nrg_L[2]; + float nrg_R[2]; + float nrg_DMX[2]; + + /*Residual prediction*/ + int16_t res_pred_mode[STEREO_DFT_ENC_DFT_NB]; /* mode from 0 (off) to 1 (on) */ + float res_pred_gain[STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX]; /*prediction gain for the residual HFs */ + int16_t res_pred_band_min; /* Band min for prediction of residual */ + int16_t res_pred_flag_1; + int16_t res_pred_flag_2; + int16_t res_pred_counter; + float res_pred_gain_f[STEREO_DFT_BAND_MAX]; + int16_t res_pred_index_EC[STEREO_DFT_BAND_MAX]; + int16_t res_pred_index_ECDiff[STEREO_DFT_BAND_MAX]; + int16_t res_pred_index_ECprevious[STEREO_DFT_BAND_MAX]; + int16_t reverb_flag; + float pre_sub_nrg_DMX[STEREO_DFT_BAND_MAX]; + float diff_l_h_sm; + float diff_r_h_sm; + float prev_fac2; + + /*Residual coding*/ + int16_t res_cod_mode[STEREO_DFT_ENC_DFT_NB]; /* mode from 0 (off) to 3 */ + int16_t res_cod_band_max; /* Band max for coding of residual */ + int16_t res_cod_line_max; /* Maximum number of MDCT lines to code for the residual coding */ + float res_cod_NRG_M[STEREO_DFT_BAND_MAX]; + float res_cod_NRG_S[STEREO_DFT_BAND_MAX]; + float res_cod_SNR_M[STEREO_DFT_BAND_MAX]; + float old_snr; + + /* flags and data for adaptive wideband residual coding */ + float res_dmx_ratio_lt; /* long term energy ratio between RES and DMX */ + int16_t hangover_cnt0; /* counter 0 for hangover */ + int16_t hangover_cnt1; /* counter 1 for hangover */ + float dmx_res_all_prev; /* energy of the previous frame */ + int16_t last_res_cod_mode_modify_flag; /* a flag to indicate whether the res_cod_mode_flag has been modified for the switching frame in which res_cod_mode_flag should be swithced from 1 to 0 */ + int16_t res_cod_sw_flag; /* a flag to indicate whether it is a switching frame */ + float switch_fade_factor; /* Adaptive fade factor for switch frame */ + + /*misc*/ + float icbweRefEner; + float lbEner; + int16_t flip_sign; +#ifdef DEBUG_MODE_DFT + int16_t verbose; +#endif + +} STEREO_DFT_ENC_DATA, *STEREO_DFT_ENC_DATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * MDCT Stereo encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_mdct_enc_data_structure +{ + /* static members */ + STEREO_MDCT_BAND_PARAMETERS stbParamsTCX20; /* stereo frequency band parameters for TCX20 */ + STEREO_MDCT_BAND_PARAMETERS stbParamsTCX10; /* stereo frequency band parameters for TCX10 */ + STEREO_MDCT_BAND_PARAMETERS stbParamsTCX20afterACELP; /* stereo frequency band parameters for transition frames */ + + /* only intraframe */ + int16_t mdct_stereo_mode[2]; /* mdct stereo mode: LR, MS, band-wise MS */ +#ifdef DEBUGGING + int16_t mdct_stereo_mode_cmdl; /* MDCT stereo mode from command-line */ + int16_t fDualMono; /* force dual mono in MDCT stereo mode */ + int16_t fMSstereo; /* force full-band MS in MDCT stereo mode */ +#endif + int16_t global_ild[2]; /* Quantized ILD for the whole spectrum */ + int16_t split_ratio; /* Ratio of bitrate (1 to 7), split_ratio = 8 * 1st chn bitrate / (1st + 2nd chn bitrate) */ + + int16_t IGFStereoMode[2]; /* MDCT stereo mode for IGF */ + + ITD_DATA_HANDLE hItd; + DFT_ANA_HANDLE hDft_ana; + + int16_t sw_uncorr; + +} STEREO_MDCT_ENC_DATA, *STEREO_MDCT_ENC_DATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * TD Stereo encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_td_enc_data_structure +{ + int16_t tdm_lp_reuse_flag; /* Flag that indicate if it is possible to reuse the LP coefficient from the primary channel or not */ + int16_t tdm_low_rate_mode; /* secondary channel low rate mode flag */ + float tdm_Pri_pitch_buf[NB_SUBFR]; + int16_t tdm_Pitch_reuse_flag; + + float tdm_lt_corr_RM; /* Long term right-mono correlation */ + float tdm_lt_corr_LM; /* Long term left-mono correlation */ + float tdm_last_diff_lt_corr; /* long term correlation difference mem */ + float tdm_last_ratio; /* Last TDM ratio */ + + float tdm_lt_rms_L; /* Left channel long term rms */ + float tdm_lt_rms_R; /* Right channel long term rms */ + float tdm_last_ener_lt_R; /* Right channel long term energy */ + float tdm_last_ener_lt_L; /* Left channel long term energy */ + + int16_t tdm_last_ratio_idx; /* last TDM ratio index */ + int16_t tdm_last_SM_flag; /* Flag to signal a SM encoding scheme -> better for some music item */ + int16_t tdm_ratio_transition_mov_flag; /* Flag that indicates that L-R energy is changing */ + int16_t tdm_ratio_transition_cnt; /* Counter */ + int16_t tdm_hyst_cnt; /* Counter */ + int16_t tdm_prev_stable_idx; /* Previous Transmitted ratio index*/ + int16_t tdm_prev_desired_idx; /* Previous Transmitted ratio index*/ + float tdm_LT_es_em; /* Long term evoluation of the side to mono energy ratio */ + int16_t tdm_use_IAWB_Ave_lpc; /* Flag to indicate the usage of mean inactive LP coefficients */ + + /* NOOP parameters */ + float tdm_lt_corr_RM_SM; /* Long term right-mono correlation in SM mode*/ + float tdm_lt_corr_LM_SM; /* Long term left-mono correlation in SM mode*/ + float tdm_last_diff_lt_corr_SM; /* long term correlation difference mem in SM mode*/ + float tdm_last_ratio_SM; /* Last TDM ratio in SM mode*/ + + float tdm_lt_rms_L_SM; /* Left channel long term rms in SM mode*/ + float tdm_lt_rms_R_SM; /* Right channel long term rms in SM mode*/ + float tdm_last_ener_lt_R_SM; /* Right channel long term energy in SM mode*/ + float tdm_last_ener_lt_L_SM; /* Left channel long term energy in SM mode*/ + + int16_t tdm_last_ratio_idx_SM; /* last TDM ratio index in SM mode*/ + int16_t tdm_last_SM_flag_noop; /* Flag to signal a SM encoding scheme -> better for some music item in SM mode*/ + int16_t tdm_noop_mov_flag; /* Flag that indicates that L-R energy is changing in SM mode*/ + int16_t tdm_noop_cnt; /* Counter in SM mode*/ + int16_t tdm_hyst_cnt_SM; /* Counter in SM mode*/ + int16_t tdm_prev_stable_idx_SM; /* Previous Transmitted ratio index in SM mode*/ + int16_t tdm_prev_desired_idx_SM; /* Previous Transmitted ratio index in SM mode*/ + float tdm_LT_es_em_SM; /* Long term evoluation of the side to mono energy ratio in SM mode*/ + int16_t tdm_NOOP_cnt; /* Counter for channel combination scheme */ + int16_t tdm_SM_flag; /* Flag for channel combination scheme */ + int16_t tdm_SM_last2_clas[2]; /* Class of the frame immediately prior to the previous frame */ + int16_t tdm_SM_last_clas[2]; /* Class of the previous frame */ + int16_t tdm_SM_modi_flag; /* Flag that indicates to modify ratio */ + int16_t tdm_SM_reset_flag; /* Flag that indicates to reset the parameters for SM mode */ + + int16_t tdm_FD2LRTD_SW_cnt; /* Count the number of frames following a FD to LRTD switching */ + int16_t tdm_LRTD_flag; /* LRTD stereo mode flag */ + int16_t prev_fr_LRTD_TD_dec; /* At the beginning of a frame, contains the previous LRTD decision that might have been modified during last frame */ + int16_t tdm_inst_ratio_idx; /* Instantaneous correlation ratio index */ + int16_t tdm_last_inst_ratio_idx; /* previous frame instantaneous correlation ratio index */ + int16_t tdm_vad_hangover_cnt; /* Count the number of frames where hangover_cnt >= 5 in both primary and secondary channel */ + int16_t tdm_ini_frame_cnt; /* Count the number of frame to decide how to evaluate the local VAD of primary and secondary channel */ + int16_t tdm_last_LRTD_frame_cnt; /* Count the number of frame since the last LRTD frame */ + int16_t tdm_last_LRTD_PriCh_cnt; /* Count the number of frame since the primary channel changed */ + int16_t flag_skip_DMX; /* flag that indicates whether the TD downmixing is skipped */ + +} STEREO_TD_ENC_DATA, *STEREO_TD_ENC_DATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * ICA Stereo encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_tca_enc_data_structure +{ + int16_t refChanIndx; /* reference channel index in current frame */ + int16_t prevRefChanIndx; /* reference channel index in previous frame */ + int16_t indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ + int16_t indx_ica_gD; /* ICA target gain */ + float targetGain; /* gain norm applied on target (or right) channel in current frame */ + float instTargetGain; /* instantaneous gain norm applied on target (or right) channel in current frame */ + float prevTargetGain; /* gain norm applied on target (or right) channel in previous frame */ + float corrStatsSmoothFac; /* gD/corrStats smoothing based on corrStats */ + + int16_t lMemRecalc; + int16_t lMemRecalc_12k8; + int16_t lMemRecalc_16k; + + int16_t corrLagStats[3]; /* corr lag stats in current frame */ + int16_t prevCorrLagStats[3]; /* corr lag stats in previous frame */ + + float memChanL[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* left channel input to correct at the cross-over */ + float memChanR[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* right channel input to correct at the cross-over */ + + float memChanL_DS[ADDED_MEM_DS]; /* left channel input speech memory for downmix */ + float memChanR_DS[ADDED_MEM_DS]; /* right channel input speech memory for downmix */ + float mem_tempF; + float memdecim[12]; /* memory for pre-rmphasis filter for resampling */ + float corrEstPrev[3][2 * L_NCSHIFT_DS + 1]; /* Prev correlation vector */ + float corrEstLT[2 * L_NCSHIFT_DS + 1]; /* Long term correlation vector smoothed */ + + float ica_envVarLT; + float C_mem[2 * L_NCSHIFT_DS + 1]; + float E1_mem, E2_mem; + float delay_0_mem[MAX_DELAYREGLEN]; + float smooth_dist_reg_prv_corr; + int16_t LRTD_G_ATT_cnt; + +} STEREO_TCA_ENC_DATA, *STEREO_TCA_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Stereo IC_BWE encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_icbwe_enc_data_structure +{ + int16_t prev_refChanIndx_bwe; + int16_t refChanIndx_bwe; + /* SHB speech resampler memory */ + float memHPF[8]; + float mem_decim_shb_ch0[2 * L_FILT_MAX]; + + /* SHB speech non-ref channel */ + float mem_shb_speech_ref[L_LOOK_16k]; + float mem_shb_speech_nonref[L_LOOK_16k]; + + /* unscaled & scaled SHB synthesis memory */ + float mem_lpc_shbsynth_nonref[LPC_SHB_ORDER]; + + /* inter-channel BWE spectral shape adj. */ + float prevSpecMapping; + float memShbSpecMapping; + float memShbSpecXcorr[6]; + float prevgsMapping; + + float prevRefEner; + float prevNonRefEner; + + float memGsEnerMap[2]; + + float dec_2over3_mem[L_FILT_2OVER3]; + float dec_2over3_mem_lp[L_FILT_2OVER3_LP]; + float icbwe_inp_mem[CPE_CHANNELS][NS2SA( 48000, L_MEM_RECALC_TBE_NS )]; + float *dataChan[CPE_CHANNELS]; + float memModifyFs_icbwe[CPE_CHANNELS][2 * L_FILT32k]; + + float mem_nrg_L[CPE_CHANNELS]; + float mem_nrg_R[CPE_CHANNELS]; + float mem_nrg_DMX[CPE_CHANNELS]; + float gDes_pastFrame; + float icbweRefEner; + + float shbSynthRef[L_FRAME16k]; + float nlExc16k[L_FRAME16k]; + float mixExc16k[L_FRAME16k]; + float lpSHBRef[LPC_SHB_ORDER + 1]; + + int16_t MSFlag; + +} STEREO_ICBWE_ENC_DATA, *STEREO_ICBWE_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * stereo classifiers structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_stereo_classifier_data_structure +{ + /* features for xtalk classifier and UNCLR classifier */ + int16_t clas_ch1; + int16_t pitch_ch1[3]; + float voicing_ch1[3]; + float cor_map_sum_ch1; + float lsf_ch1[M]; + float lepsP_ch1; + float dE1_ch1, dE1_ch2; + float nchar_ch1, nchar_ch2; + float non_sta_ch1; + float sp_div_ch1; + float ps_diff_ch1, ps_diff_ch2; + float ps_sta_ch1, ps_sta_ch2; + float prev_g_IPD; + float prev_IPD; + float prev_ratio_m1_m2; + float ratio_L; + int16_t vad_flag_glob; + int16_t vad_relE; + + int16_t aEn_raw[CPE_CHANNELS]; /* raw aEn for local relative energy estimation */ + float ave_ener_L; /* average energy of the L channel */ + float ave_ener_R; /* average energy of the R channel */ + float Etot_dn; /* average energy in dB - lower bound */ + float Etot_up; /* average energy in dB - upper bound */ + float relE_buf[UNCLR_L_RELE]; /* running buffer for relative energy */ + float Etot_buf[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ + float relE_0_1; /* relative energy in the current frame normalized to (0,1) */ + float relE_0_1_LT; + + int16_t unclr_sw_enable_cnt[CPE_CHANNELS]; /* UNCLR classifier - counter of frames suitable for UNCLR switching */ + + float unclr_relE_0_1_LT[UNCLR_RC_ORDER]; + float unclr_wscore; + int16_t unclr_decision; /* UNCLR stereo classifier decision (0/1) */ + float unclr_fv[SSC_MAX_NFEA]; /* UNCLR - feature vector */ + int16_t unclr_corrLagMax_prev; + + float xtalk_score_buf[XTALK_SCORE_BUF_LEN]; + int16_t xtalk_decision; /* xtalk stereo classifier decision (0/1) */ + float xtalk_fv[SSC_MAX_NFEA]; /* xtalk - feature vector */ + float xtalk_wscore; + float xtalk_score; + float xtalk_score_wrelE; + + int16_t lrtd_mode; + int16_t prev_lrtd_mode; + + float is_speech; + int16_t silence_flag; + +} STEREO_CLASSIF_DATA, *STEREO_CLASSIF_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Front-VAD structure + *----------------------------------------------------------------------------------*/ + +typedef struct front_vad_enc +{ + int16_t ini_frame; /* initialization frames counter */ + float lp_speech; /* long term speech average */ + float lp_noise; /* long term noise average */ + float mem_decim[2 * L_FILT_MAX]; /* decimation filter memory */ + float buffer_12k8[3 * L_FRAME / 2]; /* 12k8 signal buffer */ + float mem_preemph; /* preemph filter memory */ + NOISE_EST_HANDLE hNoiseEst; /* Noise estimation handle */ + VAD_HANDLE hVAD; /* VAD handle */ + float *delay_buf; + int16_t delay_samples; + +} FRONT_VAD_ENC, *FRONT_VAD_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * DirAC encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_dirac_enc_data_structure +{ + DIRAC_CONFIG_DATA_HANDLE hConfig; + PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */ + + IVAS_FB_MIXER_HANDLE hFbMixer; + float *sba_synchro_buffer[IVAS_MAX_NUM_CH]; // VE: all 16 buffers not needed ? + int16_t num_samples_synchro_delay; + + /* DirAC parameter estimation */ + float **direction_vector[DIRAC_NUM_DIMS]; + float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ + float diffuseness_m[DIRAC_MAX_NBANDS]; + int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; + int16_t block_grouping[5]; + + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + + /* diffuseness */ + int16_t index_buffer_intensity; + int16_t no_col_avg_diff; + float **buffer_intensity_real[DIRAC_NUM_DIMS]; + float *buffer_energy; + +} DIRAC_ENC_DATA, *DIRAC_ENC_HANDLE; + +/*----------------------------------------------------------------------------------* + * SPAR encoder structures + *----------------------------------------------------------------------------------*/ + +/* SPAR AGC structures */ +typedef struct ivas_agc_enc_chan_state_t +{ + int16_t lastExp; + int16_t prevExp; + float lastGain; + float lastMaxAbs; + int16_t gainExpVal; + float MaxAbsVal_del; + int16_t MaxAbsValIdx_del; + +} ivas_agc_enc_chan_state_t; + +typedef struct ivas_agc_enc_state_t +{ + ivas_agc_com_state_t agc_com; + float minDelta; + float smFact; + ivas_agc_enc_chan_state_t *gain_state; + ivas_agc_chan_data_t *gain_data; + +} ivas_agc_enc_state_t; + +/* SPAR covariance structures */ +typedef struct ivas_enc_cov_handler_state_t +{ + ivas_cov_smooth_state_t *pCov_state; + ivas_cov_smooth_state_t *pCov_dtx_state; + int16_t num_bins; + int16_t prior_dtx_present; + +} ivas_enc_cov_handler_state_t; + +typedef struct ivas_enc_cov_handler_in_buf_t +{ + float *ppIn_FR_real[IVAS_SPAR_MAX_CH]; + float *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; + int16_t num_ch; + int16_t transient_det; + int16_t dtx_cov_flag; + +} ivas_enc_cov_handler_in_buf_t; + +#ifndef FIX_SBA_CLEAN_UP_OPT +/* SPAR FOA MD structures */ +typedef struct ivas_spar_foa_md_enc_state_t +{ + ivas_spar_md_t spar_md; + ivas_spar_md_prev_t spar_md_prior; + int16_t num_umx_ch; + int16_t num_decorr; + + float ***mixer_mat; + float ***cov_real; + float ***cov_dtx_real; + float ***mixer_mat_local; + ivas_spar_foa_md_com_cfg spar_md_cfg; + ivas_arith_coeffs_t arith_coeffs; + ivas_huff_coeffs_t huff_coeffs; + int16_t table_idx; + +} ivas_spar_foa_md_enc_state_t; + +typedef struct ivas_spar_foa_md_enc_in_buf_t +{ + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + int16_t num_bands; + int16_t dtx_vad; + +} ivas_spar_foa_md_enc_in_buf_t; +#else +/* SPAR MD structures */ +typedef struct ivas_spar_md_enc_state_t +{ + ivas_spar_md_t spar_md; + ivas_spar_md_prev_t spar_md_prior; + int16_t num_umx_ch; + int16_t num_decorr; + + float ***mixer_mat; + float ***cov_real; + float ***cov_dtx_real; + float ***mixer_mat_local; + ivas_spar_md_com_cfg spar_md_cfg; + ivas_arith_coeffs_t arith_coeffs; + ivas_huff_coeffs_t huff_coeffs; + int16_t table_idx; + +} ivas_spar_md_enc_state_t; + + +typedef struct ivas_spar_md_enc_in_buf_t +{ + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + int16_t num_bands; + int16_t dtx_vad; + +} ivas_spar_md_enc_in_buf_t; +#endif + + +/* PCA structure */ +typedef struct +{ + int16_t prev_bypass_decision; + float prev_eigVec[FOA_CHANNELS * FOA_CHANNELS]; + float prev_ql[IVAS_PCA_INTERP]; + float prev_qr[IVAS_PCA_INTERP]; + float prev_D[IVAS_PCA_INTERP]; + float mem_eigVec_interp[FOA_CHANNELS * FOA_CHANNELS]; + float old_r_sm[FOA_CHANNELS * FOA_CHANNELS]; + +} PCA_ENC_STATE; + + +/* SPAR FOA structures */ +#ifndef FIX_SBA_CLEAN_UP_OPT +typedef struct ivas_spar_foa_enc_state_t +{ + ivas_spar_foa_md_enc_state_t *hMdEnc; + IVAS_FB_MIXER_HANDLE hFbMixer; + ivas_enc_cov_handler_state_t *hCovEnc; + ivas_trans_det_state_t *hTranDet; + ivas_agc_enc_state_t *hAgcEnc; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t enc_param_start_band; + PCA_ENC_STATE *hPCA; + int32_t core_nominal_brate; /* Nominal bitrate for core coding */ + +} ivas_spar_foa_enc_state_t; +#endif + + +/* SPAR main structure */ +#ifndef FIX_SBA_CLEAN_UP_OPT +typedef struct ivas_spar_enc_lib_t +{ + ivas_spar_foa_enc_state_t *hSparFoa; + + FRONT_VAD_ENC_HANDLE hFrontVad; /* front-VAD handle */ + //ENC_CORE_HANDLE hCoreCoderVAD; /* core-coder handle for front-VAD module */ + + int16_t front_vad_flag; + int16_t front_vad_dtx_flag; + int16_t force_front_vad; + +} SPAR_ENC_DATA, *SPAR_ENC_HANDLE; +#else +typedef struct ivas_spar_enc_lib_t +{ + ivas_spar_md_enc_state_t *hMdEnc; + IVAS_FB_MIXER_HANDLE hFbMixer; + ivas_enc_cov_handler_state_t *hCovEnc; + ivas_trans_det_state_t *hTranDet; + ivas_agc_enc_state_t *hAgcEnc; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t enc_param_start_band; + PCA_ENC_STATE *hPCA; + int32_t core_nominal_brate; /* Nominal bitrate for core coding */ + FRONT_VAD_ENC_HANDLE hFrontVad; /* front-VAD handle */ + ENC_CORE_HANDLE hCoreCoderVAD; /* core-coder handle for front-VAD module */ + + int16_t front_vad_flag; + int16_t front_vad_dtx_flag; + int16_t force_front_vad; + +} SPAR_ENC_DATA, *SPAR_ENC_HANDLE; +#endif + + +/*----------------------------------------------------------------------------------* + * Parametric MC encoder structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_param_mc_enc_data_structure +{ + + IVAS_FB_MIXER_HANDLE hFbMixer; + int16_t transient_detector_delay; + const float *dmx_factors; + + /* Multichannel Specific Parameters */ + IVAS_PARAM_MC_METADATA hMetadataPMC; + int16_t band_grouping[PARAM_MC_MAX_PARAMETER_BANDS + 1]; + int16_t lfe_index; + int16_t icc_map_index[PARAM_MC_PARAMETER_FRAMES][PARAM_MC_SZ_ICC_MAP]; + int16_t max_param_band_abs_cov; + + float ener_fac[PARAM_MC_MAX_PARAMETER_BANDS]; + +} PARAM_MC_ENC_DATA, *PARAM_MC_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * MASA encoder structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_masa_encoder_data_struct +{ + float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + int16_t num_Cldfb_instances; + HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; + float *delay_buffer[MASA_MAX_TRANSPORT_CHANNELS]; + int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; + uint8_t twoDirBands[MASA_FREQUENCY_BANDS]; + float importanceWeight[MASA_FREQUENCY_BANDS]; + SPHERICAL_GRID_DATA Sph_Grid16; + float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; + float prevq_lfeToTotalEnergyRatio; + int16_t prevq_lfeIndex; + + float onset_detector_1; + float onset_detector_2; + +} MASA_ENCODER_DATA; + +typedef struct ivas_masa_encoder_struct +{ + MASA_METADATA_FRAME masaMetadata; /* MASA metadata frame storage during processing before unified metadata coding */ + MASA_CODEC_CONFIG config; /* Configuration of MASA encoding */ + MASA_ENCODER_DATA data; /* Data storage for MASA encoding */ + +} MASA_ENCODER, *MASA_ENCODER_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Multichannel MASA (McMASA) encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_mcmasa_enc_data_structure +{ + int16_t nbands; + int16_t nCodingBands; + + /* delay compensation */ + float *delay_buffer_lfe[2]; /* Delay buffer for LFE estimation */ + + int16_t num_samples_delay_comp; + int16_t num_slots_delay_comp; + int16_t offset_comp; + + IVAS_FB_MIXER_HANDLE hFbMixer; + IVAS_FB_MIXER_HANDLE hFbMixerLfe; + + /* DirAC parameter estimation */ + float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ + int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; + int16_t block_grouping[5]; + + /* diffuseness */ + int16_t index_buffer_intensity; + int8_t no_col_avg_diff; + float **buffer_intensity_real[DIRAC_NUM_DIMS]; + float **buffer_intensity_real_vert; + float *buffer_energy; + + float chnlToFoaMtx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; + float chnlToFoaEvenMtx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; + float ls_azimuth[MCMASA_MAX_ANA_CHANS]; + int16_t leftNearest[MCMASA_MAX_ANA_CHANS]; + int16_t rightNearest[MCMASA_MAX_ANA_CHANS]; + int16_t numHorizontalChannels; + uint8_t isHorizontalSetup; + uint8_t combineRatios; + + float prevMultiChEne; + float prevDownmixEne; + float prevEQ; + float interpolator[L_FRAME48k]; + + uint8_t separateChannelEnabled; + int16_t separateChannelIndex; + + /* LFE coding */ + float lfeLfEne[MAX_PARAM_SPATIAL_SUBFRAMES]; + float totalLfEne[MAX_PARAM_SPATIAL_SUBFRAMES]; + float *lfeAnaRingBuffer[2]; + int16_t ringBufferPointer; + float lowpassSum[2]; + int16_t ringBufferSize; + +} MCMASA_ENC_DATA, *MCMASA_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Stereo CNG handle + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_cng_enc +{ + int16_t prev_sg_average_counter; /* Counter for sidegain averaging */ + int16_t sg_active_cnt; /* Counter for sidegain averaging */ + int16_t sg_average_counter; /* Counter for sidegain averaging */ + float sg_average[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ + float prev_sg_average[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ + float mem_cohBand[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ + float coh_crossfade[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ + int16_t td_active; /* TD-stereo indication */ + int16_t first_SID_after_TD; /* Set if first SID frame after TD stereo */ + int16_t first_SID; /* Set if first SID frame since codec start */ + +} STEREO_CNG_ENC, *STEREO_CNG_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * SCE encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct sce_enc_data_structure +{ + int16_t sce_id; /* SCE # identifier */ + int32_t element_brate; /* SCE element total bitrate in bps */ + + BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */ + + //ENC_CORE_HANDLE hCoreCoder[1]; /* core coder handle */ + +} SCE_ENC_DATA, *SCE_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * CPE encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct cpe_enc_data_structure +{ + int16_t cpe_id; /* CPE # identifier */ + + int32_t element_brate; /* CPE element total bitrate in bps */ + int32_t last_element_brate; /* last CPE element total bitrate in bps */ + int16_t element_mode; /* element mode, in CPE it can be IVAS_CPE_DFT, IVAS_CPE_TD or IVAS_CPE_MDCT */ + int16_t last_element_mode; /* last element mode */ + + BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */ + + //ENC_CORE_HANDLE hCoreCoder[CPE_CHANNELS]; /* core coder handle */ + + /* stereo data handles */ + STEREO_CLASSIF_HANDLE hStereoClassif; /* stereo classifiers handle */ + STEREO_DFT_ENC_DATA_HANDLE hStereoDft; /* DFT stereo data handle */ + STEREO_TD_ENC_DATA_HANDLE hStereoTD; /* TD stereo data handle */ + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct; /* MDCT stereo data handle */ + STEREO_TCA_ENC_HANDLE hStereoTCA; /* Stereo TCA Encoder handle */ + STEREO_ICBWE_ENC_HANDLE hStereoICBWE; /* Stereo inter-channel BWE handle */ + STEREO_CNG_ENC_HANDLE hStereoCng; /* Stereo CNG data structure */ + FRONT_VAD_ENC_HANDLE hFrontVad[CPE_CHANNELS]; + + float *input_mem[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ + +#ifdef DEBUGGING + int16_t stereo_mode_cmdl; /* stereo mode forced from the commaand-line */ +#endif + +} CPE_ENC_DATA, *CPE_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * MCT structure + *----------------------------------------------------------------------------------*/ + +typedef struct mct_block_data_struct +{ + int16_t isActive; + int16_t ch1, ch2; + int16_t mask[2][MAX_SFB]; + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct; /* MDCT stereo data handle */ + +} MCT_BLOCK_DATA, *MCT_BLOCK_DATA_HANDLE; + +typedef struct mct_enc_data_structure +{ + BSTR_ENC_HANDLE hBstr; /* bitstream handle for side bits - in MCT, side bits are written at the beginning of the bitstream */ + + int16_t nchan_out_woLFE; /* number of active channels within multi-channel configuration */ + int16_t currBlockDataCnt; + int16_t bitsChannelPairIndex; /* bits needed to code channel pair index, depends on number of active channels */ + MCT_BLOCK_DATA_HANDLE hBlockData[MCT_MAX_BLOCKS]; + + float lastxCorrMatrix[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS]; + int16_t lowE_ch[MCT_MAX_CHANNELS]; + int16_t LFE_off; + uint16_t mc_global_ild[MCT_MAX_CHANNELS]; + int16_t nBitsMCT; /* number of bits spent on mct side info */ + int16_t num_lfe; + + /* pointers to local buffers */ + float *p_mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS]; + float *p_orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS]; + int16_t tnsBits[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; /* number of tns bits in the frame */ + int16_t tnsSize[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; /* number of tns parameters put into prm */ + int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + + int16_t hbr_mct; + +} MCT_ENC_DATA, *MCT_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * Stereo downmix for EVS encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct stereo_dmx_evs_phase_only_correlation_structure +{ + float P[L_FRAME48k]; + float peakQ[CPE_CHANNELS]; + float peak_width[CPE_CHANNELS]; + float confidence; + + int16_t ispeak[CPE_CHANNELS]; + int16_t itdLR[CPE_CHANNELS]; + int16_t shift_limit; + + const float *wnd; + float eps; + const float *sin; + +} STEREO_DMX_EVS_POC_DATA, *STEREO_DMX_EVS_POC_HANDLE; + +typedef struct stereo_dmx_evs_enc_data_structure +{ + STEREO_DMX_EVS_POC_HANDLE hPOC; + + float itd; + + float pre_dmx_energy[1]; + float aux_dmx_energy[CPE_CHANNELS]; + + float dmx_weight[1 + CPE_CHANNELS]; + + const float *s_wnd; + +} STEREO_DMX_EVS_ENC_DATA, *STEREO_DMX_EVS_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * LFE encoder structures + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_lfe_enc_data_structure +{ + ivas_filters_process_state_t filter_state; + LFE_WINDOW_HANDLE pWindow_state; + BSTR_ENC_HANDLE hBstr; /* pointer to encoder bitstream handle */ + const uint16_t *cum_freq_models[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; + int16_t lfe_bits; + float *old_wtda_audio; + +} LFE_ENC_DATA, *LFE_ENC_HANDLE; + + +/* clang-format off */ +/*----------------------------------------------------------------------------------* + * Encoder configuration structure (includes commandline-related parameters) + *----------------------------------------------------------------------------------*/ + +typedef struct encoder_config_structure +{ + int32_t ivas_total_brate; /* IVAS total bitrate in bps */ + int32_t last_ivas_total_brate; /* IVAS last total bitrate in bps */ + int32_t input_Fs; /* input signal sampling frequency in Hz */ + int16_t nchan_inp; /* number of input audio channels */ + int16_t max_bwidth; /* maximum encoded bandwidth */ + IVAS_FORMAT ivas_format; /* IVAS format */ + + int16_t element_mode_init; /* element mode used at initialization */ + int16_t stereo_dmx_evs; /* flag to indicate that stereo downmix for EVS encoder */ + + int16_t sba_order; /* Ambisonic (SBA) order */ + int16_t sba_planar; /* Ambisonic (SBA) planar flag */ + MC_LS_SETUP mc_input_setup; /* multichannel input ls setup */ + + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + + int16_t Opt_DTX_ON; /* flag indicating DTX operation */ + int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ + int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ + + int16_t Opt_RF_ON; /* flag indicating RF (channel-aware) mode */ + int16_t rf_fec_offset; /* RF FEC offset */ + int16_t rf_fec_indicator; /* RF FEC indicator */ + + int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ + int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ + + /* temp. development parameters */ + int16_t Opt_AGC_ON; /* flag indicating AGC operation in SBA */ + int16_t Opt_PCA_ON; /* flag indicating PCA operation in SBA */ + +#ifdef DEBUGGING + /* debugging options */ + int16_t stereo_mode_cmdl; /* stereo mode forced from the command-line */ + int16_t force; /* parameter to force specific "core" of the Core-Coder*/ + int16_t mdct_stereo_mode_cmdl; /* mdct stereo mode forced from command-line, employed only when DEBUG_FORCE_MDCT_STEREO_MODE is activated */ +#endif + + +} ENCODER_CONFIG, *ENCODER_CONFIG_HANDLE; + + +/*----------------------------------------------------------------------------------* + * + * Main IVAS encoder structure + * =========================== + *----------------------------------------------------------------------------------*/ + +typedef struct +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; /* Encoder configuration structure */ + + /* high-level encoder parameters */ + int16_t nchan_transport; /* number of transport channels */ + + int16_t codec_mode; /* Mode1 or Mode2 of core codec */ + int16_t last_codec_mode; /* previous frame Mode 1 or 2 */ + + float **mem_hp20_in; /* input signals HP filter memories */ + + /* core-encoder modules */ + int16_t nSCE; /* number of total SCEs */ + int16_t nCPE; /* number of total CPEs */ + SCE_ENC_HANDLE hSCE[MAX_SCE]; /* SCE handles */ + CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS]; /* CPE handles */ + + /* multichannel modules */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS]; /* ISM metadata handles (storage for one frame of read ISM metadata) */ + DIRAC_ENC_HANDLE hDirAC; /* DirAC data handle */ + SPAR_ENC_HANDLE hSpar; /* SPAR encoder handle */ + MASA_ENCODER_HANDLE hMasa; /* MASA encoder data and configuration */ + IVAS_QMETADATA_HANDLE hQMetaData; /* Metadata handle for q_metadata parametric spatial coding DirAC/MASA*/ + MCT_ENC_HANDLE hMCT; /* MCT handle */ + PARAM_MC_ENC_HANDLE hParamMC; /* Parametric MC handle */ + MCMASA_ENC_HANDLE hMcMasa; /* Multi-channel MASA data handle */ + LFE_ENC_HANDLE hLFE; /* LFE data handle */ + + ISM_MODE ism_mode; /* ISM format mode */ + SBA_MODE sba_mode; /* SBA format mode */ + MC_MODE mc_mode; /* MC format mode */ + + /* Stereo downmix for EVS module */ + STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS; /* Stereo downmix for EVS encoder handle */ + +} Encoder_Struct; + +/* clang-format on */ + +#endif /* IVAS_STAT_ENC_H */ diff --git a/lib_enc/lead_indexing_fx.c b/lib_enc/lead_indexing_fx.c index fff763a..1645238 100644 --- a/lib_enc/lead_indexing_fx.c +++ b/lib_enc/lead_indexing_fx.c @@ -1,13 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" /* Compilation switches */ - #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ /*-------------------------------------------------------------------* * Local function prototypes @@ -23,7 +20,7 @@ static Word16 fcb_encode_pos_fx(const Word16 pos_vector[], const Word16 pulse_nu void re8_compute_base_index_fx( const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ const Word16 ka, /* i : Identifier of the absolute leader related to x */ - UWord16 *I /* o : index */ + UWord16 *I /* o : index */ ) { Word16 i, j, k1 ,m; diff --git a/lib_enc/long_enr.c b/lib_enc/long_enr.c index 439bb37..9a4fa8f 100644 --- a/lib_enc/long_enr.c +++ b/lib_enc/long_enr.c @@ -14,63 +14,120 @@ * Compute relative energy, long-term average total noise energy and total active speech energy *-------------------------------------------------------------------*/ void long_enr_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 high_lpn_flag + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + Word16 high_lpn_flag /* i : sp/mus LPN flag */ +#ifdef IVAS_CODE + ,FRONT_VAD_ENC_HANDLE hFrontVad[CPE_CHANNELS], /* i/o: front-VAD handles */ + const int16_t n_chan, /* i : number of channels */ + const int16_t localVAD_HE_SAD_LR[CPE_CHANNELS], /* i : HE-SAD flag without hangover LR channels */ + const float Etot_LR[CPE_CHANNELS] /* i : total channel energy LR channels */ +#endif ) { Word16 tmp; Word16 alpha; + NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; /*-----------------------------------------------------------------* * Compute long term estimate of total noise energy * and total active speech energy *-----------------------------------------------------------------*/ +#ifdef IVAS_CODE + Word16 n; + if (hFrontVad != NULL) + { + if (hFrontVad[0]->ini_frame < 4) + { + for (n = 0; n < n_chan; n++) + { + hFrontVad[n]->lp_noise = hFrontVad[n]->hNoiseEst->totalNoise; + tmp = hFrontVad[n]->lp_noise + 10.0f; - IF( LT_16(st_fx->ini_frame_fx, 4 )) + if (hFrontVad[n]->lp_speech < tmp) + { + hFrontVad[n]->lp_speech = tmp; + } + } + } + else + { + float smooth_prev, smooth_curr; - { + if (hFrontVad[0]->ini_frame < 150) + { + smooth_prev = 0.95f; + smooth_curr = 0.05f; + } + else + { + smooth_prev = 0.98f; + smooth_curr = 0.02f; + } + + for (n = 0; n < n_chan; n++) + { + hFrontVad[n]->lp_noise = smooth_prev * hFrontVad[n]->lp_noise + smooth_curr * hFrontVad[n]->hNoiseEst->totalNoise; - st_fx->lp_noise_fx = st_fx->totalNoise_fx; - move16(); - tmp = add(st_fx->lp_noise_fx, 2560); /*10.0 in Q8*/ - st_fx->lp_speech_fx = s_max(st_fx->lp_speech_fx, tmp); + if (localVAD_HE_SAD_LR[n] && !high_lpn_flag) + { + if ((hFrontVad[n]->lp_speech - Etot_LR[n]) < 10.0f) + { + hFrontVad[n]->lp_speech = 0.98f * hFrontVad[n]->lp_speech + 0.02f * Etot_LR[n]; + } + else + { + hFrontVad[n]->lp_speech = hFrontVad[n]->lp_speech - 0.05f; + } + } + } + } } - ELSE + else +#endif { - /* if ( st->ini_frame < 150 ) { - st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->totalNoise; - } else { - st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; - } */ - alpha = 655; - move16();/* 0.02 Q15 */ - if ( LT_16(st_fx->ini_frame_fx, 150)) /* should match HE_LT_CNT_INIT_FX */ + IF(LT_16(st_fx->ini_frame_fx, 4)) { - alpha = 1638 ; - move16(); /* 0.05 Q15 */ + st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; + move16(); + tmp = add(st_fx->lp_noise_fx, 2560); /*10.0 in Q8*/ + st_fx->lp_speech_fx = s_max(st_fx->lp_speech_fx, tmp); } - st_fx->lp_noise_fx = noise_est_AR1_Qx( st_fx->totalNoise_fx, st_fx->lp_noise_fx , alpha); /* Q8 state, alpha in Q15 */ - - test(); - IF ( (localVAD_HE_SAD != 0) - && ( high_lpn_flag == 0) ) + ELSE { - IF( LT_16(sub(st_fx->lp_speech_fx, Etot ), 10*256 )) /* 10.0 in Q8 */ + /* if ( st->ini_frame < 150 ) { + st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->totalNoise; + } else { + st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; + } */ + alpha = 655; + move16();/* 0.02 Q15 */ + if (LT_16(st_fx->ini_frame_fx, 150)) /* should match HE_LT_CNT_INIT_FX */ { - /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ - st_fx->lp_speech_fx = noise_est_AR1_Qx(Etot, st_fx->lp_speech_fx, 655); /* Q8 state, 0.02 in Q15 */ + alpha = 1638; + move16(); /* 0.05 Q15 */ } - ELSE + st_fx->lp_noise_fx = noise_est_AR1_Qx(hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx , alpha); /* Q8 state, alpha in Q15 */ + + test(); + IF((localVAD_HE_SAD != 0) + && (high_lpn_flag == 0)) { - st_fx->lp_speech_fx = sub(st_fx->lp_speech_fx, 13); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ + IF(LT_16(sub(st_fx->lp_speech_fx, Etot), 10 * 256)) /* 10.0 in Q8 */ + { + /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ + st_fx->lp_speech_fx = noise_est_AR1_Qx(Etot, st_fx->lp_speech_fx, 655); /* Q8 state, 0.02 in Q15 */ + } + ELSE + { + st_fx->lp_speech_fx = sub(st_fx->lp_speech_fx, 13); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ + } } - } + } } - /*-----------------------------------------------------------------* * Initialize parameters for energy tracking and signal dynamics *-----------------------------------------------------------------*/ diff --git a/lib_enc/lp_exc_e_fx.c b/lib_enc/lp_exc_e_fx.c index c763242..2083591 100644 --- a/lib_enc/lp_exc_e_fx.c +++ b/lib_enc/lp_exc_e_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "basop_util.h" /*-------------------------------------------------------------------* @@ -17,13 +16,12 @@ #define LOW_LTP_LIMIT 0.55f /*-------------------------------------------------------------------* - * Local functions + * Local function prototypes *-------------------------------------------------------------------*/ static Word16 adpt_enr_fx(const Word16 codec_mode, const Word16 *exc, const Word16 *h1, Word16 *y1, const Word16 L_subfr, Word16 *gain, Word16 *g_corr, const Word16 clip_gain, const Word16 *xn, Word16 *xn2, Word16 *exp_ener - ,Word16 use_prev_sf_pit_gain - ); + ,Word16 use_prev_sf_pit_gain); /*-------------------------------------------------------------------* * function lp_filt_exc_enc_fx() @@ -34,22 +32,20 @@ static Word16 adpt_enr_fx(const Word16 codec_mode, const Word16 *exc, const Word *-------------------------------------------------------------------*/ Word16 lp_filt_exc_enc_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ - const Word16 coder_type, /* i : coding type Q0 */ - const Word16 i_subfr, /* i : subframe index Q0 */ - Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ - const Word16 *h1, /* i : weighted filter input response Q(14+shift) */ - const Word16 *xn, /* i : target vector Q_new-1+shift */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ - Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ - const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ - const Word16 L_frame, /* i : frame size Q0 */ - Word16 *g_corr, /* o : ACELP correlation values mant/exp */ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - Word16 *lp_flag /* i/o: mode selection Q0 */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + const Word16 coder_type, /* i : coding type Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ + Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ + const Word16 *h1, /* i : weighted filter input response Q(14+shift) */ + const Word16 *xn, /* i : target vector Q_new-1+shift */ + Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ + Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ + const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ + const Word16 L_frame, /* i : frame size Q0 */ + Word16 *g_corr, /* o : ACELP correlation values mant/exp */ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ + Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ + Word16 *lp_flag /* i/o: mode selection Q0 */ ) { Word16 gain1, gain2, g_corr2[4], exc_tmp[5*L_SUBFR], xn2_tmp[5*L_SUBFR]; @@ -65,34 +61,6 @@ Word16 lp_filt_exc_enc_fx( gain2 = 0; move16(); - /*-----------------------------------------------------------------* - * Select LP filtering flag - *-----------------------------------------------------------------*/ - - IF ( EQ_16(codec_mode,MODE1)) - { - test(); - test(); - test(); - test(); - IF ( ( Opt_AMR_WB || EQ_16(coder_type,GENERIC)||EQ_16(coder_type,TRANSITION))&<_32(core_brate,ACELP_11k60)) - { - *lp_flag = LOW_PASS; - move16(); - } - ELSE IF ( GE_32(core_brate,ACELP_11k60)&&NE_16(coder_type,AUDIO)) - { - *lp_flag = NORMAL_OPERATION; - move16(); - } - ELSE - { - *lp_flag = FULL_BAND; - move16(); - } - - } - /*----------------------------------------------------------------* * Find the target energy if the adaptive exc. is not filtered *----------------------------------------------------------------*/ @@ -212,18 +180,18 @@ Word16 lp_filt_exc_enc_fx( * This serves to decide about the filtering of the adaptive excitation *-------------------------------------------------------------------*/ -static Word16 adpt_enr_fx( /* o : adaptive excitation energy mant */ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 *exc, /* i : excitation vector Q_new */ - const Word16 *h1, /* i : impuls response Q15 */ - Word16 *y1, /* o : zero-memory filtered adpt. excitation 12 bits */ - const Word16 L_subfr, /* i : vector length */ - Word16 *gain, /* o : subframe adaptive gain Q14 */ - Word16 *g_corr, /* o : correlations for adptive gain mant/exp*/ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - const Word16 *xn, /* i : adaptive codebook target 12 bits Q_new-1+shift*/ - Word16 *xn2, /* o : algebraic codebook target 12 bits Q_new-1+shift*/ - Word16 *exp_ener /* o : adaptive excitation energy exp */ +static Word16 adpt_enr_fx( /* o : adaptive excitation energy mant */ + const Word16 codec_mode,/* i : MODE1 or MODE2 */ + const Word16 *exc, /* i : excitation vector Q_new */ + const Word16 *h1, /* i : impuls response Q15 */ + Word16 *y1, /* o : zero-memory filtered adpt. excitation 12 bits */ + const Word16 L_subfr, /* i : vector length */ + Word16 *gain, /* o : subframe adaptive gain Q14 */ + Word16 *g_corr, /* o : correlations for adptive gain mant/exp*/ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ + const Word16 *xn, /* i : adaptive codebook target 12 bits Q_new-1+shift*/ + Word16 *xn2, /* o : algebraic codebook target 12 bits Q_new-1+shift*/ + Word16 *exp_ener /* o : adaptive excitation energy exp */ , Word16 use_prev_sf_pit_gain /* i : flag to use prev sf pitch gain or not */ ) { @@ -300,12 +268,12 @@ static Word16 adpt_enr_fx( /* o : adaptive excitation energy mant * codebook excitation y1[]. ( and -2 ) *-------------------------------------------------------------------*/ -Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ - const Word16 xn_1[], /* i : target signal */ - const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ - Word16 g_corr[], /* o : correlations and -2 */ - const Word16 L_subfr, /* i : vector length */ - const Word16 norm_flag /* i : flag for constraining pitch contribution */ +Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ + const Word16 xn_1[], /* i : target signal */ + const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ + Word16 g_corr[], /* o : correlations and -2 */ + const Word16 L_subfr, /* i : vector length */ + const Word16 norm_flag /* i : flag for constraining pitch contribution */ ) { Word16 i; diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index ca2de53..93a97cb 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "rom_enc_fx.h" #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "prot_fx.h" @@ -21,19 +20,18 @@ #define MAXINT32 MAX_32 /*---------------------------------------------------------------------* -* Local functions +* Local function prototypes *---------------------------------------------------------------------*/ -static void lsfq_CNG_fx( Encoder_State_fx *st_fx, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 * p_offset_scale2, +static void lsfq_CNG_fx(BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 * p_offset_scale2, Word16 * p_no_scales ); static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 * levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 * lsf, const Word16 * pred, Word32 p_offset_scale1[][MAX_NO_SCALES+1], Word32 p_offset_scale2[][MAX_NO_SCALES+1], Word16 p_no_scales[][2], Word16 *resq, Word16 * lsfq ); -static void lsf_mid_enc_fx( Encoder_State_fx *st_fx,const Word16 int_fs, const Word16 qisp0[], const Word16 qisp1[], Word16 isp[], const Word16 coder_type, - const Word16 bwidth, const Word32 core_brate, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); - +static void lsf_mid_enc_fx(BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], + const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode); /*===========================================================================*/ /* FUNCTION : lsf_enc_fx() */ @@ -63,15 +61,17 @@ static void lsf_mid_enc_fx( Encoder_State_fx *st_fx,const Word16 int_fs, const W /* _ None */ /*===========================================================================*/ void lsf_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* o : quantized LSF vector */ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac, /* o : LSF stability factor */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + Word16 *lsf_new, /* o : quantized LSF vector */ + Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ const Word16 Nb_ACELP_frames, + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ +#endif const Word16 Q_new ) { @@ -79,10 +79,51 @@ void lsf_enc_fx( Word16 int_fs; Word16 force_sf = 0; Word16 fec_lsf[M], stab; - Word16 i; + Word16 no_param_lpc, i; +#ifdef IVAS_CODE + Word16 param_lpc[NPRM_LPC_NEW]; +#endif Word32 L_tmp; + Word16 coder_type, ppp_mode, nelp_mode; + + test(); + IF (EQ_32(st_fx->core_brate_fx, SID_2k40) || EQ_32(st_fx->core_brate_fx, SID_1k75)) + { + coder_type = INACTIVE; + move16(); + } + ELSE + { + coder_type = st_fx->coder_type; + move16(); + + } + + test(); + if (EQ_16(coder_type, AUDIO) && GSC_IVAS_mode > 0) + { + coder_type = GENERIC; + move16(); + } + + no_param_lpc = 0; + move16(); + + IF (st_fx->Opt_SC_VBR_fx) + { + ppp_mode = st_fx->hSC_VBR->ppp_mode_fx; + nelp_mode = st_fx->hSC_VBR->nelp_mode_fx; + move16();move16(); + } + ELSE + { + ppp_mode = 0; + nelp_mode = 0; + move16(); move16(); + } /* initialize */ +#if 0 int_fs = INT_FS_16k_FX; move16(); if( EQ_16(L_frame, L_FRAME)) @@ -90,14 +131,19 @@ void lsf_enc_fx( int_fs = INT_FS_FX; move16(); } - +#else + assert(st_fx->sr_core <= 32000); + int_fs = extract_l(st_fx->sr_core); + move32(); +#endif /* convert LSPs to LSFs */ lsp2lsf_fx( lsp_new, lsf_new, M, int_fs); /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx( lsf_new, st_fx->clip_var_fx, 0 ); + gp_clip_test_lsf_fx(st_fx->element_mode, lsf_new, st_fx->clip_var_fx, 0 ); /* Find the number of bits for LSF quantization */ + nBits = 0; move16(); IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) { nBits = LSF_BITS_CNG; @@ -106,12 +152,12 @@ void lsf_enc_fx( ELSE { test(); - IF ( (st_fx->nelp_mode_fx == 0) && (st_fx->ppp_mode_fx == 0) ) + IF ( (nelp_mode == 0) && (ppp_mode == 0) ) { - nBits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type)]; + nBits = st_fx->acelp_cfg.lsf_bits; move16(); } - ELSE IF ( EQ_16(st_fx->nelp_mode_fx, 1)) + ELSE IF ( EQ_16(nelp_mode, 1)) { nBits = 30; move16(); @@ -122,15 +168,16 @@ void lsf_enc_fx( move16(); } } - ELSE IF ( EQ_16(st_fx->ppp_mode_fx, 1)) + ELSE IF ( EQ_16(ppp_mode, 1)) { nBits = 26; move16(); } } - + force_sf = 0; move16(); /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ - if( (LT_16(Nb_ACELP_frames, 3))) + test(); + if( LT_16(Nb_ACELP_frames, 3) && NE_32(st_fx->core_brate_fx, SID_2k40) ) { force_sf = 1; move16(); @@ -148,11 +195,13 @@ void lsf_enc_fx( /*-------------------------------------------------------------------------------------* * Frame end LSF quantization *-------------------------------------------------------------------------------------*/ - - lsf_end_enc_fx( st_fx, lsf_new, lsf_new, st_fx->mem_AR_fx, st_fx->mem_MA_fx, nBits, coder_type, st_fx->bwidth_fx, - st_fx->Bin_E_fx, Q_new+QSCALE-2, int_fs, st_fx->core_brate_fx, &st_fx->streaklimit_fx, &st_fx->pstreaklen_fx, - force_sf, 0, 0, NULL, NULL, NULL, st_fx->coder_type_raw_fx ); - +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + lsf_end_enc_fx(st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, + force_sf, NULL, NULL, NULL, st_fx->coder_type_raw_fxtdm_lsfQ_PCh); +#else + lsf_end_enc_fx( st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new+QSCALE-2, + force_sf, NULL, NULL, NULL, st_fx->coder_type_raw_fx); +#endif /* convert quantized LSFs back to LSPs */ lsf2lsp_fx( lsf_new, lsp_new, M, int_fs); @@ -162,6 +211,19 @@ void lsf_enc_fx( /* don't use old LSF values if this is the first ACELP frame after HQ frames */ Copy( lsf_new, st_fx->lsf_old_fx, M ); } + /* set seed_acelp used in UC mode */ +#ifdef IVAS_CODE + test(); + IF (EQ_16(coder_type, UNVOICED) && GT_16(st_fx->element_mode, EVS_MONO)) + { + st_fx->seed_acelp = 0; move16(); + FOR (i = no_param_lpc - 1; i >= 0; i--) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st->seed_acelp = (int16_t)((((st->seed_acelp) >> 1) + param_lpc[i]) * 31821L + 13849L); + } + } +#endif IF ( EQ_32(st_fx->core_brate_fx, SID_2k40)) { /* return if SID frame (conversion to A(z) done in the calling function) */ @@ -180,7 +242,7 @@ void lsf_enc_fx( Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); } - FEC_lsf_estim_enc_fx( st_fx, st_fx->L_frame_fx, fec_lsf ); + FEC_lsf_estim_enc_fx( st_fx, fec_lsf ); /* in case of FEC in decoder - calculate LSF stability */ stab = lsf_stab_fx( lsf_new, fec_lsf, 0, st_fx->L_frame_fx ); @@ -226,7 +288,7 @@ void lsf_enc_fx( Copy( lsf_new, st_fx->lsf_old_fx, M ); } /* Mid-frame LSF encoding */ - lsf_mid_enc_fx( st_fx, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth_fx, st_fx->core_brate_fx, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new+QSCALE-2, st_fx->ppp_mode_fx, st_fx->nelp_mode_fx); + lsf_mid_enc_fx(st_fx->hBstr, st_fx->acelp_cfg.mid_lsf_bits, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth_fx, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new+QSCALE-2, ppp_mode, nelp_mode); test(); IF ( EQ_16(st_fx->last_core_fx,HQ_CORE)&&EQ_16(st_fx->core_fx,ACELP_CORE)) @@ -237,13 +299,32 @@ void lsf_enc_fx( } /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_fx( L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); +#ifdef ADD_LRTD + test(); + IF (EQ_16(tdm_low_rate_mode, 1) && GT_16(coder_type, UNVOICED)) + { + IF (EQ_16(st_fx->active_cnt_fx, 1)) + { + Copy(lsp_mid, st_fx->lsp_old_fx, M); + lsp2lsf_fx(lsp_mid, st_fx->lsf_old_fx, M, int_fs); + Copy(lsp_new, lsp_mid, M); + } + /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ + int_lsp4_fx(st_fx->L_frame_fx, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2); + } + ELSE +#endif + { + int_lsp4_fx(st_fx->L_frame_fx, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0); + } /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ - *stab_fac = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame_fx ); - + IF (NE_32(st_fx->core_brate_fx, SID_2k40)) + { + st_fx->stab_fac_fx = lsf_stab_fx(lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame_fx); + } return; } @@ -260,7 +341,7 @@ void lsf_enc_fx( *-------------------------------------------------------------------*/ static void lsfq_CNG_fx( - Encoder_State_fx *st_fx, + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *lsf, /*x2.56 unquantized LSF vector */ const Word16 *wghts, /*Q10 LSF weights */ Word16 *qlsf, /*x2.56 quantized LSF vecotor */ @@ -335,6 +416,7 @@ static void lsfq_CNG_fx( } /* quantize the difference with LVQ */ + /* MSVQ_ROM to be updated */ mslvq_cng_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts, p_no_scales ); index_lvq_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, @@ -342,11 +424,11 @@ static void lsfq_CNG_fx( Vr_add( qlsf, &CNG_SN1_fx[idx_cv*M], qlsf, M ); /* write the VQ index to the bitstream */ - push_indice_fx( st_fx, IND_ISF_0_0, idx_cv, 4 ); + push_indice_fx( hBstr, IND_ISF_0_0, idx_cv, 4 ); /* write the LVQ index to the bitstream */ - push_indice_fx( st_fx, IND_ISF_0_1, idx_lvq[0], LEN_INDICE ); - push_indice_fx( st_fx, IND_ISF_0_1, idx_lvq[1], LSF_BITS_CNG - 4 - LEN_INDICE ); + push_indice_fx( hBstr, IND_ISF_0_1, idx_lvq[0], LEN_INDICE ); + push_indice_fx( hBstr, IND_ISF_0_1, idx_lvq[1], LSF_BITS_CNG - 4 - LEN_INDICE ); return; } @@ -359,10 +441,10 @@ static void lsfq_CNG_fx( static Word16 qlsf_Mode_Select_fx( - Word16 *w, /* i : weighting vector Q8 */ - Word16 *pred1, /* i : prediction vector x2.56 */ - Word16 streaklimit, /* i : predictive streak limit Q15 */ - Word32 op_loop_thr /* i : Open-loop Threshold */ + const Word16 *w, /* i : weighting vector Q8 */ + const Word16 *pred1, /* i : prediction vector x2.56 */ + const Word16 streaklimit, /* i : predictive streak limit Q15 */ + const Word32 op_loop_thr /* i : Open-loop Threshold */ ) { Word16 pred_pow2[M]; @@ -451,27 +533,20 @@ static Word16 qlsf_Mode_Select_fx( /* _ None */ /*========================================================================*/ void lsf_end_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ - Word16 *qlsf, /* o : quantized LSF */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ - const Word16 coder_type_org,/* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word32 *Bin_Ener, /* i : FFT Bin energy 128 *2 sets */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - const Word32 int_fs, /* i : sampling frequency */ - Word32 core_brate, /* i : ACELP core bitrate */ - Word16 *streaklimit, /* i/o: Multiplier to limit consecutive predictive usage */ - Word16 *pstreaklen, /* i/o: Lentght of the current predictive mode streak */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ - Word16 rf_flag, /* i : Channel aware mode has some special cases */ - Word16 mode2_flag, /* i : MODE2 mode has some special cases */ - Word16 * lpc_param, - Word16 * no_indices, - Word16 * bits_param_lpc, - Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ + Encoder_State_fx *st, /* i/o: encoder state structure */ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ + Word16 *qlsf, /* o : quantized LSF */ + const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ + const Word16 coder_type_org, /* i : coding type */ + Word16 Q_ener, /* i : Q valuen for Bin_Ener */ + Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + Word16* lpc_param, + Word16* no_indices, + Word16* bits_param_lpc, + Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + ,const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif ) { Word16 i; @@ -503,6 +578,14 @@ void lsf_end_enc_fx( Word16 TCQIdx0[M+2]; /* Optimal codebook indices for VQ-TCQ quantizer */ Word16 *TCQIdx; Word16 tmp; + Word16 flag_1bit_gran; + BSTR_ENC_HANDLE hBstr = st->hBstr; +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + Word16 pred3[M]; + Word16 dummy, dummy_v[5]; +#endif + + flag_1bit_gran = (Word16)GT_16(st->element_mode, EVS_MONO); nBits = nBits_in; move16(); @@ -510,12 +593,20 @@ void lsf_end_enc_fx( test(); test(); test(); - IF(EQ_16(coder_type_org, GENERIC)&&EQ_32(int_fs,INT_FS_16k)&&(rf_flag==0)&&(mode2_flag==0)) +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF(EQ_16(coder_type_org, GENERIC) && EQ_32(st->sr_core,INT_FS_16k) && EQ_16(st->codec_mode, MODE1) && (st->idchan == 0)) /* this bit is used only for primary channel or mono */ +#else + IF(EQ_16(coder_type_org, GENERIC) && EQ_32(st->sr_core, INT_FS_16k) && EQ_16(st->codec_mode, MODE1)) +#endif { IF (EQ_16(coder_type_raw, VOICED)) { coder_type = VOICED; move16(); /* Reflect Inactive mode */ + if (EQ_16(flag_1bit_gran, 1)) + { + nBits = sub(nBits, 1); /* This is for real Generic*/ + } } ELSE { @@ -534,7 +625,7 @@ void lsf_end_enc_fx( * Calculate the number of stages and levels for each stage based on allowed bit budget * Set absolute threshold for codebook-type decision logic depending on signal bandwidth *------------------------------------------------------------------------------------ -*/ - IF ( EQ_16(bwidth, NB)) + IF ( EQ_16(st->bwidth_fx, NB)) { abs_threshold = L_add(SFNETLOWLIMIT_NB, 0); } @@ -543,21 +634,21 @@ void lsf_end_enc_fx( abs_threshold = L_add(SFNETLOWLIMIT_WB, 0); } /* Calculate LSF weighting coefficients */ - Unified_weighting_fx(&Bin_Ener[L_FFT/2], Q_ener, lsf, wghts, (Word16)EQ_16(bwidth, NB),(Word16)EQ_16(coder_type,UNVOICED),int_fs,M); + Unified_weighting_fx(&st->Bin_E_fx[L_FFT/2], Q_ener, lsf, wghts, (Word16)EQ_16(st->bwidth_fx, NB), (Word16)EQ_16(coder_type,UNVOICED),st->sr_core,M); /*--------------------------------------------------------------------------------* * LSF quantization of SID frames *--------------------------------------------------------------------------------*/ - IF ( EQ_32(core_brate, SID_2k40)) + IF ( EQ_32(st->core_brate_fx, SID_2k40)) { - lsfq_CNG_fx( st, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); + lsfq_CNG_fx(hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); sort_fx( qlsf, 0, M-1 ); - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, int_fs ); + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); return; } /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ - predmode = find_pred_mode(coder_type, bwidth, int_fs, &mode_lvq, &mode_lvq_p,st->total_brate_fx); + find_pred_mode(&predmode, coder_type, st->bwidth_fx, st->sr_core, &mode_lvq, &mode_lvq_p,st->total_brate_fx); /*----------------------------------------------------------------* * Calculate number of stages and levels for each stage based on the allowed bit allocation @@ -578,9 +669,19 @@ void lsf_end_enc_fx( /* for mem_MA update */ FOR (i=0; imem_MA_fx[i])); move16(); } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ + if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + { + /* if secondary channel predmode is set to be > 2 */ + predmode += 3; + + tdm_SCh_LSF_intra_pred(st->element_brate, tdm_lsfQ_PCh, pred3); + } +#endif IF ( predmode == 0 ) { /* Subtract only mean */ @@ -592,7 +693,7 @@ void lsf_end_enc_fx( st->offset_scale1_fx,st->offset_scale2_fx, st->no_scales_fx, resq, lsfq); safety_net = 1; move16(); - *pstreaklen = 0; + st->pstreaklen_fx = 0; move16();/* predictive LSF quantizer streak is ended with safety-net */ } ELSE IF (EQ_16(predmode, 1)) /* only MA prediction */ @@ -605,147 +706,230 @@ void lsf_end_enc_fx( move16(); } ELSE - { - /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in - case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ - test(); - test(); - test(); - IF ( ((GT_16(*pstreaklen, (STREAKLEN+3)))&&(EQ_16(coder_type,VOICED)))||((GT_16(*pstreaklen,(STREAKLEN)))&&(NE_16(coder_type,VOICED)))) +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + PMT("LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING ") { - /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ - *streaklimit = mult(*streaklimit,STREAKMULT_FX); - move16(); - } - - IF ( *pstreaklen == 0 ) + if (predmode == 2) +#endif { - /* reset the consecutive AR-predictor multiplier */ - *streaklimit = 32767; /*1.0 in Q15 */ move16(); - } - - /* VOICED_WB@16kHz */ - test(); - IF ( EQ_32(int_fs, INT_FS_16k)&&EQ_16(coder_type,VOICED)) - { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt(lsf, pred0, Tmp, M); - - FOR (i = 0; i < M; i++) + /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + test(); + test(); + test(); + IF ( ((GT_16(st->pstreaklen_fx, (STREAKLEN+3))) && (EQ_16(coder_type,VOICED))) || ((GT_16(st->pstreaklen_fx,(STREAKLEN))) && (NE_16(coder_type,VOICED)))) { - /* subtract mean and AR prediction */ - pred2[i] = mult(Predictors_fx[mode_lvq_p][i],sub(mem_AR[i],pred0[i])); - Tmp2[i] = sub(Tmp[i], pred2[i]); - pred2[i] = add(pred2[i], pred0[i]); + /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ + st->streaklimit_fx = mult(st->streaklimit_fx,STREAKMULT_FX); + move16(); } - /* select safety_net or predictive */ - safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, *streaklimit, OP_LOOP_THR_HVO ); - IF ( EQ_16(force_sf, 1)) + IF (st->pstreaklen_fx == 0 ) { - safety_net = 1; - move16(); + /* reset the consecutive AR-predictor multiplier */ + st->streaklimit_fx = 32767; /*1.0 in Q15 */ move16(); } - IF ( safety_net ) + /* VOICED_WB@16kHz */ + test(); + IF ( EQ_32(st->sr_core, INT_FS_16k)&&EQ_16(coder_type,VOICED) && flag_1bit_gran == 0) { - /* Safety-net - BC-TCQ quantization : SN */ - Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); - *pstreaklen = 0; - move16(); + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + /* subtract only mean */ + Vr_subt(lsf, pred0, Tmp, M); + + FOR (i = 0; i < M; i++) + { + /* subtract mean and AR prediction */ + pred2[i] = mult(Predictors_fx[mode_lvq_p][i],sub(st->mem_AR_fx[i],pred0[i])); + Tmp2[i] = sub(Tmp[i], pred2[i]); + pred2[i] = add(pred2[i], pred0[i]); + } + + /* select safety_net or predictive */ + safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, st->streaklimit_fx, OP_LOOP_THR_HVO ); + IF ( EQ_16(force_sf, 1)) + { + safety_net = 1; + move16(); + } + + IF ( safety_net ) + { + /* Safety-net - BC-TCQ quantization : SN */ + Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); + st->pstreaklen_fx = 0; + move16(); + } + ELSE + { + /* predictive - BC-TCQ quantization : AR */ + Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); + st->pstreaklen_fx =add(st->pstreaklen_fx,1); + } } + /* all other frames (not VOICED@16kHz) */ ELSE { - /* predictive - BC-TCQ quantization : AR */ - Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); - *pstreaklen=add(*pstreaklen,1); + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + /* subtract only mean */ + Vr_subt(lsf, pred0, Tmp, M); + + FOR (i = 0; i < M; i++) + { + /* subtract mean and AR prediction */ + pred2[i] = add(pred0[i],mult(Predictors_fx[mode_lvq_p][i],sub(st->mem_AR_fx[i],pred0[i]))); + Tmp2[i] = sub(lsf[i], pred2[i]); + } + + /* safety-net */ + Err[0] = vq_lvq_lsf_enc(0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx,st->offset_scale2_fx,st->no_scales_fx, resq, lsfq); + /* Predictive quantizer is calculated only if it can be selected */ + test(); + IF (!force_sf || GT_32(Err[0],abs_threshold)) + { + Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M]); + + } + test(); + test(); + /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: + if the non-predictive (safety-net) quantization error (Err[0]) is low enough (spectral distortion is low) it is selected + or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. + or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ + IF ( force_sf || LT_32(Mult_32_16(Err[0],(st->streaklimit_fx)),L_add(Err[1],Mult_32_16(Err[1],PREFERSFNET_FX))) || LT_32(Err[0],abs_threshold)) + { + safety_net = 1; + move16(); + st->pstreaklen_fx = 0; + move16(); /* Reset the consecutive predictive frame counter */ + } + ELSE + { + safety_net = 0; + move16(); /* Increase the consecutive predictive frame counter by one */ + st->pstreaklen_fx = add(st->pstreaklen_fx,1); + } } } - /* all other frames (not VOICED@16kHz) */ - ELSE +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + PMT("LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING ") + else /* of "if (predmode==2)" */ { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt(lsf, pred0, Tmp, M); + mvr2r(ModeMeans[mode_lvq], pred0, M); - FOR (i = 0; i < M; i++) + if (predmode == 4) { - /* subtract mean and AR prediction */ - pred2[i] = add(pred0[i],mult(Predictors_fx[mode_lvq_p][i],sub(mem_AR[i],pred0[i]))); - Tmp2[i] = sub(lsf[i], pred2[i]); + mode_lvq_p = 9; /* force to Generic WB with AR*/ } - /* safety-net */ - Err[0] = vq_lvq_lsf_enc(0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, - st->offset_scale1_fx,st->offset_scale2_fx,st->no_scales_fx, resq, lsfq); - /* Predictive quantizer is calculated only if it can be selected */ - test(); - IF (!force_sf || GT_32(Err[0],abs_threshold)) + for (i = 0; i < M; i++) { - Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M]); + /* subtract mean and AR prediction */ + pred2[i] = pred0[i] + Predictors[mode_lvq_p][i] * (st->mem_AR[i] - pred0[i]); + Tmp[i] = lsf[i] - pred2[i]; + Tmp2[i] = lsf[i] - pred3[i]; + } + /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + if (st->pstreaklen > (STREAKLEN)) + { + /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ + st->streaklimit *= STREAKMULT; } - test(); - test(); - /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: - if the non-predictive (safety-net) quantization error (Err[0]) is low enough (spectral distortion is low) it is selected - or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. - or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ - IF ( force_sf || LT_32(Mult_32_16(Err[0],(*streaklimit)),L_add(Err[1],Mult_32_16(Err[1],PREFERSFNET_FX)))||LT_32(Err[0],abs_threshold)) + + if (st->pstreaklen == 0) { - safety_net = 1; - move16(); - *pstreaklen = 0; - move16(); /* Reset the consecutive predictive frame counter */ + /* reset the adaptive scaling factor */ + st->streaklimit = 1.0f; } - ELSE + + /* intra pred */ + /* use G AR pred for the intra mode (as a safety mode, this is why the indexes 0/1 are interchanged)*/ + + lsf_allocate(nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0); + + Err[0] = vq_lvq_lsf_enc(2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M]); + + if (force_sf) { - safety_net = 0; - move16(); /* Increase the consecutive predictive frame counter by one */ - *pstreaklen=add(*pstreaklen,1); + safety_net = 1; /* intra-frame prediction */ + st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + } + else + { /* try also the inter frame prediction */ + + /* AR inter-frame prediction */ + lsf_allocate(nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1); + + + Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq); + + if (Err[0] * (st->streaklimit) < PREFERSFNET * Err[1]) + { + safety_net = 1; + st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + } + else + { + safety_net = 0; + (st->pstreaklen)++; /* Increase the consecutive predictive frame counter by one */ + } } } } - /*--------------------------------------------------------------------------* +#endif /*--------------------------------------------------------------------------* * Write indices to array *--------------------------------------------------------------------------*/ - IF (mode2_flag == 0) + IF (EQ_16(st->codec_mode, MODE1) && EQ_16(st->core_fx, ACELP_CORE)) { /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ test(); - IF(EQ_16(coder_type_org, GENERIC)&&EQ_32(int_fs,INT_FS_16k)) +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF(EQ_16(coder_type_org, GENERIC)&&EQ_32(st->sr_core,INT_FS_16k) && (st->idchan == 0)) +#else + IF(EQ_16(coder_type_org, GENERIC) && EQ_32(st->sr_core, INT_FS_16k) ) +#endif { /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ - push_indice_fx( st, IND_LSF_PREDICTOR_SELECT_BIT, sub(coder_type,2), 1 ); + push_indice_fx( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub(coder_type,2), 1 ); } /* write predictor selection bit */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF(GE(predmode, 2)) +#else IF ( EQ_16(predmode, 2)) +#endif { - push_indice_fx( st, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); + push_indice_fx( st->hBstr, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); } test(); - IF ( EQ_16(coder_type, VOICED)&&EQ_32(int_fs,INT_FS_16k)) + IF ( EQ_16(coder_type, VOICED) && EQ_32(st->sr_core,INT_FS_16k) && flag_1bit_gran == 0) { /* BC-TCVQ (only for VOICED@16kHz) */ TCQIdx = &TCQIdx0[1]; Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; FOR( i=0; i<(M/2)+3; i++ ) { - push_indice_fx( st, IND_LSF, TCQIdx[i], Bit_alloc1[i]); + push_indice_fx( hBstr, IND_LSF, TCQIdx[i], Bit_alloc1[i]); } } ELSE { cumleft = nBits; move16(); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF(GE(predmode, 2)) +#else IF (EQ_16( predmode, 2 )) +#endif { /* subtract predictor selection bit */ cumleft = sub(nBits, 1); @@ -779,7 +963,7 @@ void lsf_end_enc_fx( move16(); cumleft -= num_bits; move16(); - push_indice_fx( st, IND_LSF, indice[i], num_bits ); + push_indice_fx( hBstr, IND_LSF, indice[i], num_bits ); } WHILE ( cumleft > 0 ) @@ -799,7 +983,7 @@ void lsf_end_enc_fx( } cumleft = sub(cumleft, num_bits); - push_indice_fx( st, IND_LSF, indice[i], num_bits ); + push_indice_fx( hBstr, IND_LSF, indice[i], num_bits ); i=add(i,1); } } @@ -807,7 +991,7 @@ void lsf_end_enc_fx( ELSE { test(); - IF ( EQ_16(coder_type, VOICED)&&EQ_32(int_fs,INT_FS_16k)) + IF ( EQ_16(coder_type, VOICED)&&EQ_32(st->sr_core,INT_FS_16k)) { /* BC-TCVQ (only for VOICED@16kHz) */ /* Number of quantization indices */ @@ -901,46 +1085,57 @@ void lsf_end_enc_fx( { /* Safety-net */ test(); - IF ( EQ_16(coder_type, VOICED)&&EQ_32(int_fs,INT_FS_16k)) + IF ( EQ_16(coder_type, VOICED) && EQ_32(st->sr_core,INT_FS_16k) && flag_1bit_gran == 0) { /* BC-TCQ */ - Copy( lsfq, mem_MA, M ); + Copy( lsfq, st->mem_MA_fx, M ); Vr_add( lsfq, pred0, qlsf, M ); } ELSE { - vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0-1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); - - Vr_add( qlsf, pred0, qlsf, M ); - Vr_subt(qlsf, pred1,mem_MA, M); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if (st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL) + { + /* intra mode*/ + vq_dec_lvq(0, qlsf, &indice[0], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1]); + v_add(qlsf, pred3, qlsf, M); + v_sub(qlsf, pred1, st->mem_MA, M); + } + else +#endif + { + vq_dec_lvq_fx(1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0]); + Vr_add(qlsf, pred0, qlsf, M); + Vr_subt(qlsf, pred1, st->mem_MA_fx, M); + } } } ELSE { test(); - IF ( EQ_16(coder_type, VOICED)&&EQ_32(int_fs,INT_FS_16k)) + IF ( EQ_16(coder_type, VOICED) && EQ_32(st->sr_core,INT_FS_16k) && flag_1bit_gran == 0) { /* BC-TCVQ */ - Copy( lsfq, mem_MA, M ); + Copy( lsfq, st->mem_MA_fx, M ); Vr_add( lsfq, pred2, qlsf, M ); } ELSE { /* LVQ */ vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1-1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], - &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], + &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); IF (EQ_16(predmode,1)) { - Copy(qlsf, mem_MA, M); + Copy(qlsf, st->mem_MA_fx, M); Vr_add( qlsf, pred1, qlsf, M ); } ELSE { Vr_add( qlsf, pred2, qlsf, M ); - Vr_subt(qlsf, pred1, mem_MA, M); + Vr_subt(qlsf, pred1, st->mem_MA_fx, M); } } } @@ -949,10 +1144,10 @@ void lsf_end_enc_fx( sort_fx( qlsf, 0, M-1 ); /* Verify stability by adding minimum separation */ - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, int_fs ); + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); /* Update AR-predictor memories */ - Copy( qlsf, mem_AR, M ); + Copy( qlsf, st->mem_AR_fx, M ); return; } @@ -1200,14 +1395,14 @@ static Word32 vq_lvq_lsf_enc( { cb = &Quantizers_fx[CB_lsf_fx[mode]]; move16(); - mode_glb = add(offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub(levels[stagesVQ] , min_lat_bits_SN_fx[mode])]); - } + mode_glb = add(offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub(levels[stagesVQ], min_lat_bits_SN_fx[mode])]); + } ELSE /* predictive */ { cb = &Quantizers_p_fx[CB_p_lsf_fx[mode]]; move16(); - mode_glb = add(offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub(levels[stagesVQ], min_lat_bits_pred_fx[mode])]); - } + mode_glb = add(offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub(levels[stagesVQ], min_lat_bits_pred_fx[mode])]); + } IF (stagesVQ>0) { /* first VQ stages */ @@ -2169,14 +2364,14 @@ static void FFT_Mid_Interpol_16k_fx( static void lsf_mid_enc_fx( - Encoder_State_fx *st_fx, + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 nb_bits, /* i : number of bits */ const Word16 int_fs, /* i : internal (ACELP) sampling frequency*/ const Word16 qlsp0[], /* i : quantized LSPs from frame beginning*/ const Word16 qlsp1[], /* i : quantized LSPs from frame end */ Word16 lsp[], /* i/o: mid-frame LSP */ const Word16 coder_type, /* i : coding type */ const Word16 bwidth, /* i : input signal bandwidth */ - const Word32 core_brate, /* i : core bitrate */ Word32 Bin_Ener_old[], /* i/o: per bin old log energy spectrum */ Word32 Bin_Ener[], /* i : per bin log energy spectrum */ Word16 Q_ener, /* i : Q value of Bin_ener */ @@ -2186,7 +2381,7 @@ static void lsf_mid_enc_fx( { Word16 lsf[M], qlsf[M], qlsf1[M], qlsf0[M], wghts[M]; Word32 err, err_min; - Word16 j, k, idx, nb_bits = 0, size = 0; + Word16 j, k, idx, size = 0; Word32 Bin_Ener_mid[L_FFT/2]; Word32 L_tmp; Word16 tmp, k1; @@ -2207,9 +2402,6 @@ static void lsf_mid_enc_fx( test(); IF ( ppp_mode == 0 && nelp_mode == 0 ) { - nb_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; - move16(); - /* codebook selection */ IF ( EQ_16(coder_type, VOICED)) { @@ -2227,6 +2419,14 @@ static void lsf_mid_enc_fx( move16(); BREAK; } +#ifdef IVAS_CODE + case 1: + { + ratio = tbl_mid_voi_wb_1b_fx; + move16(); + BREAK; + } +#endif } } ELSE IF ( EQ_16(coder_type, UNVOICED)) @@ -2244,6 +2444,14 @@ static void lsf_mid_enc_fx( move16(); BREAK; } +#ifdef IVAS_CODE + case 4: + { + ratio = tbl_mid_gen_wb_4b_fx; + move16(); + BREAK; + } +#endif case 2: { ratio = tbl_mid_gen_wb_2b_fx; @@ -2343,7 +2551,7 @@ static void lsf_mid_enc_fx( /* convert LSFs back to LSPs */ lsf2lsp_fx( qlsf, lsp, M, int_fs); - push_indice_fx( st_fx, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); + push_indice_fx( hBstr, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); return; } diff --git a/lib_enc/lsf_msvq_ma_enc.c b/lib_enc/lsf_msvq_ma_enc.c index e4124f6..d13bdf6 100644 --- a/lib_enc/lsf_msvq_ma_enc.c +++ b/lib_enc/lsf_msvq_ma_enc.c @@ -2,28 +2,35 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include +#include "options.h" +#include "prot_fx.h" #include "cnst_fx.h" #include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" #include "rom_enc_fx.h" +#include "basop_util.h" -#define MAXINT32 2147483647 -#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ +#define MAXINT32 2147483647 +#ifndef swap + #define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} +#endif #define depack_4_values(cbp, val0, val1, val2, val3) \ val0 = shr((cbp)[0], 4); \ val1 = shr((cbp)[1], 4); \ val2 = shr((cbp)[2], 4); \ val3 = add(add(shr(lshl((cbp)[2],12),4),lshr(lshl((cbp)[1],12),8)),s_and((cbp)[0],0xF)); - -static Word32 depack_mul_values(Word16 *Tmp, const Word16 *w, const Word16 *cbp, const Word16 N) +/*--------------------------------------------------------------------------* + * depack_mul_values() + * + *--------------------------------------------------------------------------*/ + static Word32 depack_mul_values(Word16 *Tmp, const Word16 *w, const Word16 *cbp, const Word16 N) { Word16 i, val0, val1, val2, val3; Word32 en; @@ -49,7 +56,10 @@ static Word32 depack_mul_values(Word16 *Tmp, const Word16 *w, const Word16 *cbp, return en; } - +/*--------------------------------------------------------------------------* + * depack_sub_values() + * + *--------------------------------------------------------------------------*/ static void depack_sub_values(Word16 *pTmp, const Word16 *p1, const Word16 *cbp, const Word16 N) { Word16 j, val0, val1, val2, val3; @@ -70,8 +80,11 @@ static void depack_sub_values(Word16 *pTmp, const Word16 *p1, const Word16 *cbp, } } - -/* Unroll of inner search loop for maxC == 8 */ +/*--------------------------------------------------------------------------* + * msvq_enc_find_p_max_8() + * + * Unroll of inner search loop for maxC == 8 + *--------------------------------------------------------------------------*/ static Word16 msvq_enc_find_p_max_8(Word32 dist[]) { Word16 p_max; @@ -118,8 +131,11 @@ static Word16 msvq_enc_find_p_max_8(Word32 dist[]) BASOP_SATURATE_WARNING_ON return p_max; } - -/* Unroll of inner search loop for maxC == 8 */ +/*--------------------------------------------------------------------------* + * msvq_enc_find_p_max_6() + * + * Unroll of inner search loop for maxC == 6 + *--------------------------------------------------------------------------*/ static Word16 msvq_enc_find_p_max_6(Word32 dist[]) { Word16 p_max; @@ -156,22 +172,25 @@ static Word16 msvq_enc_find_p_max_6(Word32 dist[]) BASOP_SATURATE_WARNING_ON return p_max; } - - +/*--------------------------------------------------------------------------* + * msvq_enc() + * + * MSVQ encoder + *--------------------------------------------------------------------------*/ void msvq_enc ( - const Word16 *const*cb,/* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 u[], /* i : Vector to be encoded (prediction and mean removed)(3Q12) */ + const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ + const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + const Word16 u[], /* i : Vector to be encoded (prediction and mean removed)(3Q12) */ const Word16 *levels, /* i : Number of levels in each stage */ - const Word16 maxC, /* i : Tree search size (number of candidates kept from */ + const Word16 maxC, /* i : Tree search size (number of candidates kept from */ /* one stage to the next == M-best) */ const Word16 stages, /* i : Number of stages */ - const Word16 w[], /* i : Weights */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - Word16 Idx[] /* o : Indices */ + const Word16 w[], /* i : Weights */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook dimension */ + Word16 Idx[] /* o : Indices */ ) { Word16 j; @@ -186,9 +205,6 @@ void msvq_enc Word16 N34; Word16 n, maxn, start; - - - /*----------------------------------------------------------------* * Allocate memory for previous (parent) and current nodes. * Parent node is indexed [0], current node is indexed [1]. @@ -376,30 +392,29 @@ void msvq_enc return; } - -extern const Word16 tbl_mid_gen_wb_5b_fx[]; -extern const Word16 tbl_mid_unv_wb_5b_fx[]; - +/*--------------------------------------------------------------------------* + * midlsf_enc() + * + * + *--------------------------------------------------------------------------*/ void midlsf_enc( const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ const Word16 lsf[], /* i: lsf coefficients (3Q12) */ - Word16 *idx, /* o: codebook index */ - const Word16 lpcorder /* i: order of the lpc */ - , Word32 * Bin_Ener_128_fx - ,const Word16 Q_ener - ,Word8 narrowBand - ,Word32 sr_core - ,Word16 coder_type + Word16 *idx, /* o: codebook index */ + const Word16 lpcorder, /* i: order of the lpc */ + const Word32 * Bin_Ener_128_fx, + const Word16 Q_ener, + const Word8 narrowBand, + const Word32 sr_core, + const Word16 coder_type ) { Word32 err, err_min, L_tmp; Word16 k, k1, j, tmp, size, qlsf[M], wghts[M]; const Word16 *ratio; - - IF ( EQ_16(coder_type, UNVOICED)) { ratio = tbl_mid_unv_wb_5b_fx; @@ -471,23 +486,26 @@ void midlsf_enc( return; } - -/* Returns: number of indices */ +/*--------------------------------------------------------------------------* + * Q_lsf_tcxlpc() + * + * Returns: number of indices + *--------------------------------------------------------------------------*/ Word16 Q_lsf_tcxlpc( - /* const */ Word16 lsf[], /* (I) original lsf */ - Word16 lsf_q[], /* (O) quantized lsf */ - Word16 lsp_q_ind[], /* (O) quantized lsp (w/o MA prediction) */ - Word16 indices[], /* (O) VQ indices */ - Word16 lpcorder, /* (I) LPC order */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ - , Word16 coder_type - , Word32 * Bin_Ener - ,const Word16 Q_ener + /* const */ Word16 lsf[], /* i : original lsf */ + Word16 lsf_q[], /* o : quantized lsf */ + Word16 lsp_q_ind[], /* o : quantized lsp (w/o MA prediction) */ + Word16 indices[], /* o : VQ indices */ + const Word16 lpcorder, /* i : LPC order */ + const Word16 narrowband, /* i : narrowband flag */ + const Word16 cdk, /* i : codebook selector */ + const Word16 mem_MA[], /* i : MA memory */ + const Word16 coder_type, + const Word32 * Bin_Ener, + const Word16 Q_ener ) { - Word16 weights[17]; + Word16 weights[M+1]; Word16 pred[M16k]; Word16 i; Word16 NumIndices; @@ -544,6 +562,9 @@ Word16 Q_lsf_tcxlpc( lpcorder, lpcorder, indices + NumIndices, +#ifdef IVAS_MSVQ + 0, NULL, +#endif lsf_q ); NumIndices = add(NumIndices, TCXLPC_NUMSTAGES); @@ -590,6 +611,9 @@ Word16 Q_lsf_tcxlpc( lpcorder, lpcorder, indices + NumIndices, +#ifdef IVAS_MSVQ + 0, NULL, +#endif lsf_rem_q_ind ); NumIndices = add(NumIndices, TCXLPC_IND_NUMSTAGES); @@ -623,11 +647,14 @@ Word16 Q_lsf_tcxlpc( return NumIndices; } - -/* Returns: number of bits written */ +/*--------------------------------------------------------------------------* + * enc_lsf_tcxlpc() + * + * Returns: number of bits written + *--------------------------------------------------------------------------*/ Word16 enc_lsf_tcxlpc( - Word16 **indices, /* (I) Ptr to VQ indices */ - Encoder_State_fx *st /* (I/O) Encoder state */ + Word16 **indices, /* i : Ptr to VQ indices */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) { Word16 i, NumBits; @@ -643,7 +670,7 @@ Word16 enc_lsf_tcxlpc( move16(); FOR (i=0; i +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" - -void ltd_stable(T_CldfbVadState *st, /*(io) vad state*/ - Word16 *ltd_stable_rate, /*(o) time-domain stable rate*/ - Word32 frame_energy, /*(i) current frame energy*/ - Word16 frameloop, /*(i) amount of frames*/ - Word16 Q_frames_power /*(i) the Scaling of frames_power*/ - ) +/*-------------------------------------------------------------------* + * ltd_stable() + * + * + *-------------------------------------------------------------------*/ + +void ltd_stable( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ + const Word32 frame_energy, /* i : current frame energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 Q_frames_power /* i : the Scaling of frames_power*/ +) { Word32 i; @@ -46,8 +53,8 @@ void ltd_stable(T_CldfbVadState *st, /*(io) vad state*/ move16(); Q_apow = 0; move16(); - frames_power_32 = st->frames_power_32; - Q_frames_power_last_32 = st->Q_frames_power_32; + frames_power_32 = hVAD_CLDFB->frames_power_32; + Q_frames_power_last_32 = hVAD_CLDFB->Q_frames_power_32; move16(); leadingzero_midamp = 31; move16(); @@ -462,7 +469,7 @@ void ltd_stable(T_CldfbVadState *st, /*(io) vad state*/ frames_power_32[i] = frames_power_32[i-1]; move32(); } - st->Q_frames_power_32 = Q_frames_power32; + hVAD_CLDFB->Q_frames_power_32 = Q_frames_power32; move16(); } diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index 52401fe..96d36c0 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -2,15 +2,13 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" #include "cnst_fx.h" #include "prot_fx.h" -#include "stl.h" /*--------------------------------------------------------------------------* - * mdct_classifier() - * - * MDCT signal classifier + * Local constants *--------------------------------------------------------------------------*/ #define MDCT_CLASSIFER_SMOOTH_FILT_COEFF 26214 /* 0.8 in Q15 */ @@ -18,7 +16,24 @@ #define MDCT_CLASSIFER_THRESH_DOWN 9011 /* 1.1 in Q13 */ #define MDCT_CLASSIFER_HQ_LOCAL (3 << 13) /* Q13, Define those local to make the filtering operation robust in case classes numbers are changed */ #define MDCT_CLASSIFER_TCX_LOCAL (1 << 13) /* Q13 */ +//IVAS_CODE +#define GAIN2_START_WB 6 +#define GAIN3_START_WB 12 +#define GAIN4_START_WB 9 +#define H1_START_WB 17 +#define H2_START_WB 14 +#define H_LENGTH_WB 3 + +#define GAIN2_START_SWB 8 +#define GAIN3_START_SWB 16 + +#define GAIN2_START_SWB_RS 3 +#define GAIN3_START_SWB_RS 4 +#define GAIN4_START_SWB 12 +#define H1_START_SWB 25 +#define H2_START_SWB 20 +#define H_LENGTH_SWB 5 /*----------------------------------------------------------------------------- * dft_mag_square_fx() @@ -26,9 +41,9 @@ * Square magnitude of fft spectrum *----------------------------------------------------------------------------*/ static void dft_mag_square_fx( - const Word16 x[], /* i : Input vector: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Word32 magSq[], /* o : Magnitude square spectrum */ - const Word16 n /* i : Input vector length */ + const Word16 x[], /* i : Input vector: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ + Word32 magSq[], /* o : Magnitude square spectrum */ + const Word16 n /* i : Input vector length */ ) { Word16 i, l; @@ -60,13 +75,18 @@ static void dft_mag_square_fx( move32(); return; } +/*-------------------------------------------------------------------* + * mdct_classifier() + * + * MDCT signal classifier for HQ_CORE/TCX_20_CORE + *-------------------------------------------------------------------*/ -Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ - const Word16 *Y, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ +Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ + const Word16 * fft_buff, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ Encoder_State_fx *st_fx, /* i/o: Encoder state variable */ - Word16 vadflag - , Word32 *cldfbBuf_Ener - ,Word16 enerBuffer_exp + Word32 *cldfbBuf_Ener, + Word16 enerBuffer_exp, + const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ) { Word16 c; @@ -92,9 +112,68 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ Word32 gain1_tmp = 0, gain2_tmp = 0; Word16 exp, exp1, exp2, exp3; Word32 L_tmp, L_tmp1; + Word16 gain2_start, gain3_start, gain4_start, H1_start, H2_start, H_length; + Word16 gain2_start_rs, gain3_start_rs; + TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; + + test(); + IF (EQ_32(st_fx->input_Fs_fx, 32000) || EQ_32(st_fx->input_Fs_fx, 48000)) + { + gain2_start = GAIN2_START_SWB; + gain2_start_rs = GAIN2_START_SWB_RS; + gain3_start = GAIN3_START_SWB; + gain3_start_rs = GAIN3_START_SWB_RS; + gain4_start = GAIN4_START_SWB; + //gain4_start_rs = GAIN4_START_SWB_RS; + H1_start = H1_START_SWB; + H2_start = H2_START_SWB; + H_length = H_LENGTH_SWB; + move16();move16();move16();move16();move16();move16(); + } + ELSE IF (EQ_32(st_fx->input_Fs_fx, 16000)) + { + gain2_start = GAIN2_START_WB; + gain2_start_rs = GAIN2_START_SWB_RS; + gain3_start = GAIN3_START_WB; + gain2_start_rs = GAIN2_START_SWB_RS; + gain4_start = GAIN4_START_WB; + H1_start = H1_START_WB; + H2_start = H2_START_WB; + H_length = H_LENGTH_WB; + move16(); move16(); move16(); move16(); move16(); move16(); + + } + ELSE + { + assert(!"Unknown sampling frequency in MDCT_classifier"); + H1_start = -1; /* to avoid compilation warning */ + H2_start = -1; /* to avoid compilation warning */ + H_length = -1; /* to avoid compilation warning */ + gain2_start = -1; /* to avoid compilation warning */ + gain3_start = -1; /* to avoid compilation warning */ + gain4_start = -1; /* to avoid compilation warning */ + move16(); move16(); move16(); move16(); move16(); move16(); + } +#ifdef IVAS_CODE + if (NE_16(st_fx->element_mode, IVAS_CPE_DFT)) +#endif + { - dft_mag_square_fx(Y, magSq, 256); + dft_mag_square_fx(fft_buff, magSq, 256); + } +#ifdef IVAS_CODE + ELSE + { + float norm_val; + norm_val = (L_FFT * L_FFT) / 4.f; + for (k = 0; k < 128; k++) + { + X[k + 1] = st->Bin_E_old[k] * norm_val; + } + X[0] = X[1]; + } +#endif nf = L_add(magSq[0], 0); pe = L_add(magSq[0], 0); np = 0; @@ -191,6 +270,10 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ gain1 = L_deposit_l(0); gain2 = L_deposit_l(0); gain3 = L_deposit_l(0); +#ifdef IVAS_CODE + PMT("MDCT_classifier needs review for different sampling rate") +#endif +//IVAS_CODE to adapt FOR (k = 0; k < 8; k++) { gain1 = L_add(gain1, L_shr(cldfbBuf_Ener[k], 3)); @@ -231,7 +314,7 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ } avrg_H2 = L_add(avrg_H2, Mult_32_16(cldfbBuf_Ener[k + 20], 6554)); } - +//End peak_l = L_deposit_l(0); avrg_l = L_deposit_l(0); peak_h = L_deposit_l(0); @@ -380,8 +463,8 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ test(); test(); test(); - IF ((EQ_32(st_fx->total_brate_fx, HQ_32k)&&(s_xor(condition1,condition2)!=0||condition3)) - || (EQ_32(st_fx->total_brate_fx, HQ_24k40)&& condition4)) + IF ((GE_32(brate, HQ_MDCTCLASS_CROSSOVER_BRATE) && GT_32(st_fx->input_Fs_fx, 16000) && (s_xor(condition1,condition2)!=0||condition3)) + || ((LT_32(brate, HQ_MDCTCLASS_CROSSOVER_BRATE) || EQ_32(st_fx->input_Fs_fx,16000) ) && condition4)) { c = MDCT_CLASSIFER_HQ_LOCAL; /* Q13 */ move16(); } @@ -391,7 +474,7 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ } /* Smooth decision from instantaneous decision*/ - acc = L_mult(st_fx->clas_sec_old_fx, MDCT_CLASSIFER_SMOOTH_FILT_COEFF); /* st_fx->clas_sec_old_fx in Q13 */ + acc = L_mult(hTcxEnc->clas_sec_old_fx, MDCT_CLASSIFER_SMOOTH_FILT_COEFF); /* st_fx->clas_sec_old_fx in Q13 */ clas_sec = mac_r(acc, c, 0x7fff - MDCT_CLASSIFER_SMOOTH_FILT_COEFF); /* clas_sec and c are in Q13 */ /* Do thresholding with hysteresis */ IF(GT_16(st_fx->last_enerBuffer_exp, enerBuffer_exp)) @@ -403,9 +486,9 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ } ELSE { - st_fx->last_gain1 = L_shr(st_fx->last_gain1, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); + hTcxEnc->last_gain1 = L_shr(hTcxEnc->last_gain1, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); move32(); - st_fx->last_gain2 = L_shr(st_fx->last_gain2, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); + hTcxEnc->last_gain2 = L_shr(hTcxEnc->last_gain2, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); move32(); gain1_tmp = gain1; move32(); @@ -419,14 +502,14 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ test(); test(); test(); - IF ((EQ_16(st_fx->clas_final_old_fx, HQ_CORE)||EQ_16(st_fx->clas_final_old_fx,TCX_20_CORE)) - && ((GT_32(st_fx->last_gain1, L_shr(gain1_tmp, 1)) && LT_32(st_fx->last_gain1, L_shl(gain1_tmp, 1))) - && (GT_32(st_fx->last_gain2, L_shr(gain2_tmp, 1)) && LT_32(st_fx->last_gain2, L_shl(gain2_tmp, 1))))) + IF ((EQ_16(hTcxEnc->clas_final_old_fx, HQ_CORE) || EQ_16(hTcxEnc->clas_final_old_fx,TCX_20_CORE)) + && ((GT_32(hTcxEnc->last_gain1, L_shr(gain1_tmp, 1)) && LT_32(hTcxEnc->last_gain1, L_shl(gain1_tmp, 1))) + && (GT_32(hTcxEnc->last_gain2, L_shr(gain2_tmp, 1)) && LT_32(hTcxEnc->last_gain2, L_shl(gain2_tmp, 1))))) { - clas_final = st_fx->clas_final_old_fx; + clas_final = hTcxEnc->clas_final_old_fx; move16(); } - ELSE IF (GT_16(clas_sec, st_fx->clas_sec_old_fx)&>_16(clas_sec,MDCT_CLASSIFER_THRESH_UP)) /* Going up? */ + ELSE IF (GT_16(clas_sec, hTcxEnc->clas_sec_old_fx) && GT_16(clas_sec,MDCT_CLASSIFER_THRESH_UP)) /* Going up? */ { clas_final = HQ_CORE; /* Q0 */ move16(); } @@ -437,7 +520,7 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ } ELSE { - clas_final = st_fx->clas_final_old_fx; + clas_final = hTcxEnc->clas_final_old_fx; move16(); } @@ -445,21 +528,29 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ test(); test(); /* Prevent the usage of MDCTA on noisy-speech or inactive */ - if ( EQ_16(st_fx->mdct_sw_enable, MODE2)&&(EQ_16(st_fx->flag_noisy_speech_snr,1)||vadflag==0)&&EQ_16(clas_final,HQ_CORE)) + if ( EQ_16(st_fx->mdct_sw_enable, MODE2) && (EQ_16(st_fx->flag_noisy_speech_snr,1) || st_fx->vad_flag==0) && EQ_16(clas_final,HQ_CORE)) + { + clas_final = TCX_20_CORE; + move16(); + } + /* Restrict usage of HQ_core to supported operating range */ + /* EVS: brate == st->total_brate */ + /* IVAS: brate is the nominal bitrate while st->total_brate may fluctuate. This sets a hard limit for HQ at HQ_16k40 */ + test();test();test(); + if (LE_32(st_fx->total_brate_fx, HQ_16k40) || LT_32(brate, HQ_16k40) || EQ_16(st_fx->bwidth_fx, NB) || GT_32(brate, IVAS_48k)) { clas_final = TCX_20_CORE; move16(); } - /* Memory update */ - st_fx->clas_sec_old_fx = clas_sec; + hTcxEnc->clas_sec_old_fx = clas_sec; move16(); /* Q13 */ - st_fx->clas_final_old_fx = clas_final; + hTcxEnc->clas_final_old_fx = clas_final; move16(); /* Q0 */ - st_fx->last_gain1 = gain1; + hTcxEnc->last_gain1 = gain1; move32(); - st_fx->last_gain2 = gain2; + hTcxEnc->last_gain2 = gain2; move32(); st_fx->last_enerBuffer_exp = enerBuffer_exp; move16(); diff --git a/lib_enc/mdct_selector.c b/lib_enc/mdct_selector.c index 9b3045c..03bea5f 100644 --- a/lib_enc/mdct_selector.c +++ b/lib_enc/mdct_selector.c @@ -2,13 +2,14 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" -#include "stl.h" #include "cnst_fx.h" #include "prot_fx.h" -#include +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ # define MDCT_SW_SIG_LINE_THR 840 /* 2.85f*LOG_10 in Q7 */ /* Significant spectral line threshold above Etot (dB) */ # define MDCT_SW_SIG_PEAK_THR 9216 /* 36.0f in Q8 */ /* Significant peak threshold below Etot (dB) */ @@ -35,6 +36,12 @@ # define MDCT_SW_2_SPARSENESS_THR 13107 /* 0.4f in Q15*/ /* Threshold on spectrum sparseness */ # define MDCT_SW_2_SPARSENESS_THR2 10486 /* 0.4f*0.8f in Q15*/ +/*--------------------------------------------------------------------------* + * get_sparseness() + * + * + *--------------------------------------------------------------------------*/ + static Word16 get_sparseness( /* Returns sparseness measure (Q15) */ const Word16 Bin_E[], /* i : per bin energy dB Q7 */ Word16 n, /* i : number of bins Q0 */ @@ -61,6 +68,11 @@ static Word16 get_sparseness( /* Returns sparseness measure (Q15) */ n = shr(sub(n, 2), 1); return div_s(sub(n, num_max), n); } +/*--------------------------------------------------------------------------* + * get_mean_ener() + * + * + *--------------------------------------------------------------------------*/ static Word16 get_mean_ener( /* Returns mean energy in dB (Q8) */ const Word32 enerBuffer[], /* i : CLDFB buffers */ @@ -90,18 +102,22 @@ static Word16 get_mean_ener( /* Returns mean energy in dB (Q8) */ return round_fx(L_shl(L_tmp, 8)); } +/*--------------------------------------------------------------------------* + * MDCT_selector() + * + * + *--------------------------------------------------------------------------*/ void MDCT_selector( - Encoder_State_fx *st, /* i/o: Encoder State */ - Word16 sp_floor, /* i : Noise floor estimate Q7 */ - Word16 Etot, /* i : Total energy Q8 */ - Word16 cor_map_sum, /* i : harmonicity factor Q8 */ - const Word16 voicing[], /* i : voicing factors Q15*/ - const Word32 enerBuffer[], /* i : CLDFB buffers */ - Word16 enerBuffer_exp, /* i : exponent of enerBuffer */ - Word16 vadflag + Encoder_State_fx *st, /* i/o: Encoder State */ + Word16 sp_floor, /* i : Noise floor estimate Q7 */ + const Word16 Etot, /* i : Total energy Q8 */ + const Word16 cor_map_sum, /* i : harmonicity factor Q8 */ + const Word32 enerBuffer[], /* i : CLDFB buffers */ + const Word16 enerBuffer_exp /* i : exponent of enerBuffer */ ) { + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; test(); IF (EQ_16(st->mdct_sw_enable, MODE1)||EQ_16(st->mdct_sw_enable,MODE2)) { @@ -159,7 +175,7 @@ void MDCT_selector( } /* Voicing */ - frame_voicing = add(shr(voicing[0], 1), shr(voicing[1], 1)); + frame_voicing = add(shr(st->voicing_fx[0], 1), shr(st->voicing_fx[1], 1)); /* Spectral sparseness */ sparseness = get_sparseness(st->lgBin_E_fx, lob_fft, sub(Etot, MDCT_SW_SIG_PEAK_THR)); @@ -203,7 +219,7 @@ void MDCT_selector( /* Hysteresis */ test(); test(); - if (st->prev_hi_sparse > 0 && sparse > 0 && GE_16(s_min(s_min(voicing[0], voicing[1]), voicing[2]), MDCT_SW_1_VOICING_THR)) + if (hTcxEnc->prev_hi_sparse > 0 && sparse > 0 && GE_16(s_min(s_min(st->voicing_fx[0], st->voicing_fx[1]), st->voicing_fx[2]), MDCT_SW_1_VOICING_THR)) { hi_sparse = 1; move16(); @@ -222,9 +238,9 @@ void MDCT_selector( test(); test(); switching_point = (NE_16(last_core, HQ_CORE) && NE_16(last_core, TCX_20_CORE) ) || /* previous core was non-MDCT */ - (LE_16(st->prev_hi_ener, MDCT_SW_HI_ENER_LO_THR) || LE_16(hi_ener, MDCT_SW_HI_ENER_LO_THR) ) || /* hi band is close to silent */ - (EQ_16(last_core, HQ_CORE) && (EQ_16(st->mdct_sw_enable, MODE1) || (hi_sparse > 0 && st->prev_hi_sparse >= 0 && LE_16(st->prev_hi_sparse, 1) ))) || /* HQ_CORE and hi band became sparse */ - (EQ_16(last_core, TCX_20_CORE) && (hi_sparse == 0 && st->prev_hi_sparse > 0)); /* TCX and hi band became dense */ + (LE_16(hTcxEnc->prev_hi_ener, MDCT_SW_HI_ENER_LO_THR) || LE_16(hi_ener, MDCT_SW_HI_ENER_LO_THR) ) || /* hi band is close to silent */ + (EQ_16(last_core, HQ_CORE) && (EQ_16(st->mdct_sw_enable, MODE1) || (hi_sparse > 0 && hTcxEnc->prev_hi_sparse >= 0 && LE_16(hTcxEnc->prev_hi_sparse, 1) ))) || /* HQ_CORE and hi band became sparse */ + (EQ_16(last_core, TCX_20_CORE) && (hi_sparse == 0 && hTcxEnc->prev_hi_sparse > 0)); /* TCX and hi band became dense */ IF (EQ_16(st->mdct_sw_enable, MODE1)) { @@ -324,32 +340,54 @@ void MDCT_selector( test(); test(); /* Prevent the usage of HQ_CORE on noisy-speech or inactive */ - IF (EQ_16(st->mdct_sw_enable, MODE2)&&EQ_16(st->core_fx,HQ_CORE)&&(EQ_16(st->flag_noisy_speech_snr,1)||vadflag==0)) + IF (EQ_16(st->mdct_sw_enable, MODE2)&&EQ_16(st->core_fx,HQ_CORE)&&(EQ_16(st->flag_noisy_speech_snr,1)||st->vad_flag==0)) { st->core_fx = TCX_20_CORE; move16(); } /* Update memories */ - st->prev_hi_sparse = add(st->prev_hi_sparse, hi_sparse); + hTcxEnc->prev_hi_sparse = add(hTcxEnc->prev_hi_sparse, hi_sparse); move16(); if (hi_sparse <= 0) { - st->prev_hi_sparse = hi_sparse; + hTcxEnc->prev_hi_sparse = hi_sparse; move16(); } - st->prev_hi_sparse = s_min(st->prev_hi_sparse, 2); - st->prev_hi_ener = hi_ener; + hTcxEnc->prev_hi_sparse = s_min(hTcxEnc->prev_hi_sparse, 2); + hTcxEnc->prev_hi_ener = hi_ener; move16(); } } - +/*--------------------------------------------------------------------------* + * MDCT_selector_reset() + * + * reset MDCT selector memories + *--------------------------------------------------------------------------*/ void MDCT_selector_reset( - Encoder_State_fx *st /* i/o: Encoder State */ + TCX_ENC_HANDLE hTcxEnc ) { - st->prev_hi_ener = 0; + hTcxEnc->prev_hi_ener = 0; move16(); - st->prev_hi_sparse = -1; + hTcxEnc->prev_hi_sparse = -1; move16(); } +/*--------------------------------------------------------------------------* + * MDCT_classifier_reset() + * + * reset MDCT classifier memories + *--------------------------------------------------------------------------*/ +void MDCT_classifier_reset( + TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ +) +{ + hTcxEnc->clas_sec_old_fx = 8192; /* 1.0f in Q13 */; + hTcxEnc->clas_final_old_fx = 1; /* Q0 */ + hTcxEnc->last_gain1 = 0; + move32(); + hTcxEnc->last_gain2 = 0; + move32(); + + return; +} diff --git a/lib_enc/mslvq_enc_fx.c b/lib_enc/mslvq_enc_fx.c index 1a6e073..cbbc74d 100644 --- a/lib_enc/mslvq_enc_fx.c +++ b/lib_enc/mslvq_enc_fx.c @@ -68,10 +68,10 @@ Word32 mslvq_fx ( } ELSE { - p_sigma = sigma_p_fx[mode]; - /* inverse sigma is precomputed to save complexity */ - p_inv_sigma = inv_sigma_p_fx[mode]; - p_scales = scales_p_fx[mode_glb]; + p_sigma = sigma_p_fx[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_p_fx[mode]; + p_scales = scales_p_fx[mode_glb]; p_no_lead = no_lead_p_fx[mode_glb]; } @@ -79,12 +79,12 @@ Word32 mslvq_fx ( dist = quantize_data_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_scales[0], p_no_lead ); /* second subvector */ - L_tmp = quantize_data_fx( pTmp+LATTICE_DIM, w+LATTICE_DIM, quant+LATTICE_DIM, - cv_out+LATTICE_DIM, &idx_lead[1], &idx_scale[1], - p_sigma+LATTICE_DIM, p_inv_sigma+LATTICE_DIM, p_scales+MAX_NO_SCALES, + L_tmp = quantize_data_fx(pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, + cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, p_no_scales[1], p_no_lead+MAX_NO_SCALES ); - dist = L_add(dist,L_tmp); + dist = L_add(dist, L_tmp); return dist; } diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 8b8e871..a79ca46 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -1,11 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #define THR_CORR_FX (56<<15) /* 56 in Q15 starting threshold of multi-harm. correlation */ #define THR_CORR_MAX_FX 30720 /* 60 in Q9 upper threshold of multi-harm. correlation */ @@ -18,18 +17,19 @@ * Perform multi-harmonic analysis, information used for UV and VAD decision *---------------------------------------------------------------------*/ -Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ +Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ + const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : input signal bandwidth Q0 */ + const Word32 total_brate, /* i : total bitrate Q0 */ + const Word16 bwidth, /* i : input signal bandwidth Q0 */ Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum /* Q8 */ - , Word16 *sp_floor /* o: noise floor estimate Q7 */ + Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ + Word16 *sp_floor, /* o: noise floor estimate Q7 */ + Word16 S_map[] /* o : short-term correlation map Q7 */ ) { Word16 i, j, k, L, stemp, N_mins, ind_mins[L_FFT/4], *pt_mins, harm; @@ -350,6 +350,9 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) { set16_fx(old_S, 0, L); } - + IF (S_map != NULL) + { + Copy(S, S_map, L); + } return harm; } diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index c0165d4..b2f8ce7 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -1,16 +1,13 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "control.h" #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" - -#include "stl.h" - /*===================================================================*/ /* FUNCTION : quantize_uvg_fx() */ /*-------------------------------------------------------------------*/ @@ -267,11 +264,11 @@ static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) /*===================================================================*/ void nelp_encoder_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state */ - Word16 *in_fx, /* i : residual signal */ + Encoder_State_fx *st_fx,/* i/o: encoder state */ + Word16 *in_fx, /* i : residual signal */ Word16 *exc_fx, /* o : NELP quantized excitation signal */ - Word16 *qIn1 - ,Word16 reduce_gains + Word16 *qIn1, + Word16 reduce_gains ) { Word16 i,j; @@ -299,12 +296,15 @@ void nelp_encoder_fx( Word32 Ltemp = 0, Ltemp1 = 0, L_tmp = 0, L_const_1; Word16 BP1_ORDER; Word16 rf_flag; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + RF_ENC_HANDLE hRF = st_fx->hRF; rf_flag = st_fx->rf_mode; - if (EQ_16(st_fx->last_nelp_mode_fx,1)&&NE_16(st_fx->bwidth_fx,st_fx->last_bwidth_fx)) + if (EQ_16(hSC_VBR->last_nelp_mode_fx,1)&&NE_16(st_fx->bwidth_fx,st_fx->last_bwidth_fx)) { - st_fx->last_nelp_mode_fx = 0; + hSC_VBR->last_nelp_mode_fx = 0; } qIn = *qIn1; @@ -312,40 +312,40 @@ void nelp_encoder_fx( test(); IF (EQ_16(st_fx->bwidth_fx,NB)) { - IF (st_fx->last_nelp_mode_fx != 1) + IF (hSC_VBR->last_nelp_mode_fx != 1) { BP1_ORDER = 7; move16(); - set32_fx(st_fx->bp1_filt_mem_nb_fx, 0, BP1_ORDER*2); - st_fx->qprevGain_fx = 0; + set32_fx(hSC_VBR->bp1_filt_mem_nb_fx, 0, BP1_ORDER*2); + hSC_VBR->qprevGain_fx = 0; move16(); } } ELSE IF (EQ_16(st_fx->bwidth_fx,WB)||EQ_16(st_fx->bwidth_fx,SWB)) { - IF (st_fx->last_nelp_mode_fx != 1) + IF (hSC_VBR->last_nelp_mode_fx != 1) { BP1_ORDER =4; move16(); - set16_fx(st_fx->bp1_filt_mem_wb_fx, 0, BP1_ORDER*2); + set16_fx(hSC_VBR->bp1_filt_mem_wb_fx, 0, BP1_ORDER*2); } } - IF (st_fx->last_nelp_mode_fx != 1) + IF (hSC_VBR->last_nelp_mode_fx != 1) { test(); IF (st_fx->bwidth_fx == WB || EQ_16(st_fx->bwidth_fx,SWB)) { - set16_fx(st_fx->shape1_filt_mem_fx, 0, 10); - set16_fx(st_fx->shape2_filt_mem_fx, 0, 10); - set16_fx(st_fx->shape3_filt_mem_fx, 0, 10); - set16_fx(st_fx->txlpf1_filt1_mem_fx, 0, 10); - set16_fx(st_fx->txlpf1_filt2_mem_fx, 0, 10); - set16_fx(st_fx->txhpf1_filt1_mem_fx, 0, 10); - set16_fx(st_fx->txhpf1_filt2_mem_fx, 0, 10); - st_fx->qprevIn_fx = 0; + set16_fx(hSC_VBR->shape1_filt_mem_fx, 0, 10); + set16_fx(hSC_VBR->shape2_filt_mem_fx, 0, 10); + set16_fx(hSC_VBR->shape3_filt_mem_fx, 0, 10); + set16_fx(hSC_VBR->txlpf1_filt1_mem_fx, 0, 10); + set16_fx(hSC_VBR->txlpf1_filt2_mem_fx, 0, 10); + set16_fx(hSC_VBR->txhpf1_filt1_mem_fx, 0, 10); + set16_fx(hSC_VBR->txhpf1_filt2_mem_fx, 0, 10); + hSC_VBR->qprevIn_fx = 0; move16(); - st_fx->qprevGain_fx = 0; + hSC_VBR->qprevGain_fx = 0; move16(); } } @@ -366,8 +366,8 @@ void nelp_encoder_fx( qf = qIn; move16(); - Scale_sig(st_fx->txlpf1_filt1_mem_fx, 10, (qf-st_fx->qprevIn_fx)); - pz_filter_sp_fx(txlpf1_num_coef_fx,txlpf1_den_coef_fx, in_fx, filtRes_fx, st_fx->txlpf1_filt1_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->txlpf1_filt1_mem_fx, 10, (qf-hSC_VBR->qprevIn_fx)); + pz_filter_sp_fx(txlpf1_num_coef_fx,txlpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txlpf1_filt1_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ qEL1 = qf; move16(); @@ -380,9 +380,9 @@ void nelp_encoder_fx( qf = qIn; move16(); - Scale_sig(st_fx->txhpf1_filt1_mem_fx, 10, qf-st_fx->qprevIn_fx); - pz_filter_sp_fx(txhpf1_num_coef_fx,txhpf1_den_coef_fx, in_fx, filtRes_fx, st_fx->txhpf1_filt1_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ - st_fx->qprevIn_fx = qf; + Scale_sig(hSC_VBR->txhpf1_filt1_mem_fx, 10, qf-hSC_VBR->qprevIn_fx); + pz_filter_sp_fx(txhpf1_num_coef_fx,txhpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txhpf1_filt1_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ + hSC_VBR->qprevIn_fx = qf; move16(); qEH1 = qf; @@ -461,9 +461,9 @@ void nelp_encoder_fx( qGain = 3; move16(); - IF (st_fx->last_nelp_mode_fx != 1) /* if prev frame was not NELP then init mem*/ + IF (hSC_VBR->last_nelp_mode_fx != 1) /* if prev frame was not NELP then init mem*/ { - st_fx->nelp_gain_mem_fx = Gains_fx[0]; + hSC_VBR->nelp_gain_mem_fx = Gains_fx[0]; move16(); qNelpGain = qGain; move16(); @@ -481,7 +481,7 @@ void nelp_encoder_fx( Ltemp = Mpy_32_16(exp2, tmp1,9864); /*log(2) in Q13 format = Q0 format */ /*tmp1 = round_fx(L_shl(Ltemp,12)); Q12 */ - L_tmp = L_deposit_l(st_fx->nelp_gain_mem_fx); /*Q0 */ + L_tmp = L_deposit_l(hSC_VBR->nelp_gain_mem_fx); /*Q0 */ L_tmp = L_max(L_tmp,1); exp2 = norm_l(L_tmp); L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ @@ -520,7 +520,7 @@ void nelp_encoder_fx( var_dB_fx = L_add(L_tmp, var_dB_fx);/*Q15 */ } - IF (st_fx->last_nelp_mode_fx!=1) + IF (hSC_VBR->last_nelp_mode_fx!=1) { /*var_dB *= 0.111f; */ var_dB_fx = Mult_32_16(var_dB_fx, 3637); /*0.111 in Q15 */ @@ -596,7 +596,7 @@ void nelp_encoder_fx( L_const_1 = L_shl(1, exp1); } - l_nelp_gain_mem = L_deposit_l(st_fx->nelp_gain_mem_fx); + l_nelp_gain_mem = L_deposit_l(hSC_VBR->nelp_gain_mem_fx); IF(NE_16(qNelpGain,qGain)) { l_nelp_gain_mem = L_shl(l_nelp_gain_mem, sub(qGain, qNelpGain)); @@ -615,9 +615,9 @@ void nelp_encoder_fx( l_nelp_gain_mem = L_tmp; } - st_fx->nelp_gain_mem_fx = round_fx(L_shl(l_nelp_gain_mem,16)); + hSC_VBR->nelp_gain_mem_fx = round_fx(L_shl(l_nelp_gain_mem,16)); - Scale_sig(&st_fx->nelp_gain_mem_fx, 1, -qGain); + Scale_sig(&hSC_VBR->nelp_gain_mem_fx, 1, -qGain); Scale_sig(Gains_fx, 10, -qGain); qGain =0; move16(); @@ -626,15 +626,15 @@ void nelp_encoder_fx( IF( EQ_16(rf_flag,1)) { - st_fx->rf_indx_nelp_iG1[0] = iG1_fx; - st_fx->rf_indx_nelp_iG2[0][0] = iG2_fx[0]; - st_fx->rf_indx_nelp_iG2[0][1] = iG2_fx[1]; + hRF->rf_indx_nelp_iG1[0] = iG1_fx; + hRF->rf_indx_nelp_iG2[0][0] = iG2_fx[0]; + hRF->rf_indx_nelp_iG2[0][1] = iG2_fx[1]; } ELSE { - push_indice_fx( st_fx, IND_IG1, iG1_fx, 5); - push_indice_fx( st_fx, IND_IG2A, iG2_fx[0], 6 ); - push_indice_fx( st_fx, IND_IG2B, iG2_fx[1], 6 ); + push_indice_fx(hBstr, IND_IG1, iG1_fx, 5); + push_indice_fx(hBstr, IND_IG2A, iG2_fx[0], 6 ); + push_indice_fx(hBstr, IND_IG2B, iG2_fx[1], 6 ); } test(); @@ -653,21 +653,21 @@ void nelp_encoder_fx( /* This fills up qGain with some new value */ normalize_arr(Gains_fx, &qGain, 10, 4); - generate_nelp_excitation_fx(&(st_fx->nelp_enc_seed_fx), Gains_fx, ptr_fx, gain_fac_fx); + generate_nelp_excitation_fx(&(hSC_VBR->nelp_enc_seed_fx), Gains_fx, ptr_fx, gain_fac_fx); test(); IF (EQ_16(st_fx->bwidth_fx,WB)||EQ_16(st_fx->bwidth_fx,SWB)) { BP1_ORDER = 4; - Scale_sig(st_fx->bp1_filt_mem_wb_fx, BP1_ORDER*2, qGain-st_fx->qprevGain_fx);/*qf-qAdj */ - pz_filter_sp_fx(bp1_num_coef_wb_fx,bp1_den_coef_wb_fx, ptr_fx, ptr_tmp_fx, st_fx->bp1_filt_mem_wb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, 2); + Scale_sig(hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER*2, qGain-hSC_VBR->qprevGain_fx);/*qf-qAdj */ + pz_filter_sp_fx(bp1_num_coef_wb_fx,bp1_den_coef_wb_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, 2); Copy(ptr_tmp_fx,ptr_fx,L_FRAME); } ELSE IF (EQ_16(st_fx->bwidth_fx,NB)) { BP1_ORDER = 7; move16(); - Scale_sig32(st_fx->bp1_filt_mem_nb_fx, BP1_ORDER*2, (qGain - st_fx->qprevGain_fx)); - pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr_fx, ptr_tmp_fx, st_fx->bp1_filt_mem_nb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_NB_QF_ORDER7))); + Scale_sig32(hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER*2, (qGain - hSC_VBR->qprevGain_fx)); + pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_NB_QF_ORDER7))); Copy(ptr_tmp_fx,ptr_fx,L_FRAME); Scale_sig(ptr_fx, L_FRAME, -1); /* bring exc to qgain-1 */ @@ -684,8 +684,8 @@ void nelp_encoder_fx( test(); IF (st_fx->bwidth_fx == WB|| EQ_16(st_fx->bwidth_fx,SWB)) { - Scale_sig(st_fx->shape1_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape1_num_coef_fx,shape1_den_coef_fx, ptr_fx, ptr_tmp_fx, st_fx->shape1_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->shape1_filt_mem_fx, 10, (qGain-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(shape1_num_coef_fx,shape1_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape1_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ Copy(ptr_tmp_fx,ptr_fx,L_FRAME); qf = qGain; @@ -744,9 +744,9 @@ void nelp_encoder_fx( qf1 = qGain; move16(); - Scale_sig(st_fx->txlpf1_filt2_mem_fx, 10, (qf1-st_fx->qprevGain_fx)); + Scale_sig(hSC_VBR->txlpf1_filt2_mem_fx, 10, (qf1-hSC_VBR->qprevGain_fx)); - pz_filter_sp_fx(txlpf1_num_coef_fx,txlpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, st_fx->txlpf1_filt2_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ + pz_filter_sp_fx(txlpf1_num_coef_fx,txlpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txlpf1_filt2_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ Copy(ptr_tmp_fx,filtRes_fx,L_FRAME); qEL2 = qf1; @@ -768,8 +768,8 @@ void nelp_encoder_fx( qf = qGain; move16(); - Scale_sig(st_fx->txhpf1_filt2_mem_fx, 10, (qf-st_fx->qprevGain_fx)); - pz_filter_sp_fx(txhpf1_num_coef_fx,txhpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, st_fx->txhpf1_filt2_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->txhpf1_filt2_mem_fx, 10, (qf-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(txhpf1_num_coef_fx,txhpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txhpf1_filt2_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ Copy(ptr_tmp_fx,filtRes_fx,L_FRAME); @@ -858,33 +858,33 @@ void nelp_encoder_fx( { case 1: /* Update other filter memory */ - Scale_sig(st_fx->shape3_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->shape3_filt_mem_fx, 10, (qGain-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ /* filter the residual to desired shape */ - Scale_sig(st_fx->shape2_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, ptr_tmp_fx, st_fx->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->shape2_filt_mem_fx, 10, (qGain-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ Copy(ptr_tmp_fx,ptr_fx,L_FRAME); BREAK; case 2: /* Update other filter memory */ - Scale_sig(st_fx->shape2_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->shape2_filt_mem_fx, 10, (qGain-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ /* filter the residual to desired shape */ - Scale_sig(st_fx->shape3_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, ptr_tmp_fx, st_fx->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->shape3_filt_mem_fx, 10, (qGain-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ Copy(ptr_tmp_fx,ptr_fx,L_FRAME); BREAK; default: - Scale_sig(st_fx->shape2_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->shape2_filt_mem_fx, 10, (qGain-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - Scale_sig(st_fx->shape3_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ + Scale_sig(hSC_VBR->shape3_filt_mem_fx, 10, (qGain-hSC_VBR->qprevGain_fx)); + pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ BREAK; } @@ -948,16 +948,16 @@ void nelp_encoder_fx( IF( EQ_16(rf_flag,1)) { - st_fx->rf_indx_nelp_fid[0] = fid; + hRF->rf_indx_nelp_fid[0] = fid; move16(); } ELSE { - push_indice_fx( st_fx, IND_NELP_FID, fid, 2 ); + push_indice_fx(hBstr, IND_NELP_FID, fid, 2 ); } } - st_fx->qprevGain_fx = qGain; + hSC_VBR->qprevGain_fx = qGain; move16(); IF( rf_flag == 0 ) diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index a66fd17..8a85670 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2,11 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include +#include "options.h" #include "cnst_fx.h" #include "prot_fx.h" -#include "stl.h" #include "basop_util.h" /*-----------------------------------------------------------------* @@ -150,70 +150,94 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */ * * Initialization of Noise estimator *-----------------------------------------------------------------*/ - void noise_est_init_fx( - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 *first_noise_updt, /* o : noise update initialization flag */ - Word32 bckr[], /* o : per band background noise energy estimate */ - Word32 enrO[], /* o : per band old input energy */ - Word32 ave_enr[], /* o : per band long-term average energies */ - Word16 *pitO, /* o : open-loop pitch values from preceed. frame */ - Word16 *aEn, /* o : noise adaptation hangover counter */ - Word16 *st_harm_cor_cnt, /* i/o: 1st harm correlation timer */ - Word16 *bg_cnt, /* i/o: pause burst length counter */ - Word16 *lt_tn_track, /* Q15 */ - Word16 *lt_tn_dist, /* Q8 */ - Word16 *lt_Ellp_dist, /* Etot low lp same domain as *Etot_l_lp, Q8 */ - Word16 *lt_haco_ev, /* Q15 */ - Word16 *low_tn_track_cnt /* Q0 */ - ,Word16 *Etot_st_est, /* Q8 */ - Word16 *Etot_sq_st_est /* Q2 */ - + NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */ ) { Word16 i; - FOR( i=0; ifr_bands1_fx[i] = 1; + move32();/*1e-5f; */ + hNoiseEst->fr_bands2_fx[i] = 1; + move32();/*1e-5f; */ + hNoiseEst->ave_enr2_fx[i] = E_MIN_FX; + move32(); /*Q7//E_MIN; */ + hNoiseEst->enrO_fx[i] = E_MIN_FX; move32(); - bckr[i] = E_MIN_FX; + hNoiseEst->bckr_fx[i] = E_MIN_FX; move32(); - ave_enr[i] = E_MIN_FX; + hNoiseEst->ave_enr_fx[i] = E_MIN_FX; move32(); } - - pitO[0] = 0; move16(); - *totalNoise = 0; + hNoiseEst->totalNoise_fx = 0; move16(); - *first_noise_updt = 0; + hNoiseEst->first_noise_updt_fx = 0; + //hNoiseEst->first_noise_updt_cnt_fx = 0; IVAS_CODE ?? move16(); - *aEn = 6; + hNoiseEst->aEn_fx = 6; + //hNoiseEst->aEn_inac_cnt = 0; IVAS_CODE move16(); - *st_harm_cor_cnt = 0; + hNoiseEst->harm_cor_cnt_fx = 0; move16(); - *bg_cnt = 0; + hNoiseEst->bg_cnt_fx = 0; move16(); - *lt_tn_track = 6554; /*.20 in Q15*/ move16(); - *lt_tn_dist = 0; + hNoiseEst->lt_tn_track_fx = 6554; /*.20 in Q15*/ move16(); + hNoiseEst->lt_tn_dist_fx = 0; move16(); - *lt_Ellp_dist = 0 ; + hNoiseEst->lt_Ellp_dist_fx = 0; move16(); - *lt_haco_ev = 13107; /*.40 in Q15*/ move16(); - *low_tn_track_cnt = 0; + hNoiseEst->lt_haco_ev_fx = 13107; /*.40 in Q15*/ move16(); + hNoiseEst->low_tn_track_cnt_fx = 0; move16(); - *Etot_st_est=5120; /* 20.0f in Q8 */ - *Etot_sq_st_est=1600; /* 400 in Q2 */ + hNoiseEst->Etot_st_est_fx = 5120; /* 20.0f in Q8 */ + hNoiseEst->Etot_sq_st_est_fx = 1600; /* 400 in Q2 */ +//### - return; -} + hNoiseEst->epsP_0_2_lp_fx = 4096; /*1.0 Q12*/ move16(); + hNoiseEst->epsP_0_2_ad_lp_fx = 0; + move16(); + hNoiseEst->epsP_2_16_lp_fx = 4096; + move16(); + hNoiseEst->epsP_2_16_lp2_fx = 4096; + move16(); + hNoiseEst->epsP_2_16_dlp_lp2_fx = 0; + move16(); + hNoiseEst->lt_aEn_zero_fx = 0; + move16(); + /* Tonal detector */ + FOR(i = 0; i < L_FFT / 2; i++) + { + hNoiseEst->old_S_fx[i] = 1; + move16(); + } + set16_fx(hNoiseEst->cor_map_fx, 0, L_FFT / 2); + hNoiseEst->act_pred_fx = 32767; + move16(); + hNoiseEst->noise_char_fx = 0; + move16(); + hNoiseEst->multi_harm_limit_fx = THR_CORR_INIT_FX; + + hNoiseEst->Etot_lp_fx = 0; + hNoiseEst->Etot_h_fx = 0; + hNoiseEst->Etot_l_fx = 0; + hNoiseEst->Etot_l_lp_fx = 0; + hNoiseEst->Etot_last_fx = 0; + hNoiseEst->Etot_v_h2_fx = 0; + hNoiseEst->sign_dyn_lp_fx = 0; + move16(); move16(); move16();move16(); + move16();move16();move16(); + return; + +} /*-----------------------------------------------------------------* * noise_est_pre_fx() * @@ -221,90 +245,86 @@ void noise_est_init_fx( *-----------------------------------------------------------------*/ void noise_est_pre_fx( - const Word16 Etot, /* i : Energy of current frame */ - const Word16 ini_frame_fx, /* i : Frame number (init) */ - Word16 *Etot_l, /* i/o: Track energy from below */ /*Q8*/ - Word16 *Etot_h, /* i/o: Track energy from above */ /*Q8*/ - Word16 *Etot_l_lp, /* i/o: Smoothed low energy */ /*Q8*/ - Word16 *Etot_last, /* i/o: Energy of last frame */ /*Q8*/ - Word16 *Etot_v_h2, /* i/o: Energy variations */ /*Q8*/ - Word16 *sign_dyn_lp, /* i/o: Smoother signal dynamics */ /*Q8*/ - Word16 harm_cor_cnt, /* i : */ - Word16 *Etot_lp /* i/o: Smoothed energy */ + const Word16 Etot, /* i : Energy of current frame */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const int16_t idchan, /* i : channel ID */ + const int16_t element_mode, /* i : element mode */ + const int16_t last_element_mode /* i : last element mode */ ) { Word16 tmp; - IF (LE_16(ini_frame_fx, 1)) + IF(LE_16(ini_frame_fx, 1) || (EQ_16(idchan, 1) && EQ_16(element_mode, IVAS_CPE_TD) && EQ_16(last_element_mode, IVAS_CPE_DFT))) { - *Etot_h = Etot; + hNoiseEst->Etot_h_fx = Etot; move16(); - *Etot_l = Etot; + hNoiseEst->Etot_l_fx = Etot; move16(); - *Etot_l_lp = Etot; + hNoiseEst->Etot_l_lp_fx = Etot; move16(); - *Etot_last = Etot; + hNoiseEst->Etot_last_fx = Etot; move16(); - *Etot_v_h2 = 0; + hNoiseEst->Etot_v_h2_fx = 0; move16(); - *Etot_lp = Etot; + hNoiseEst->Etot_lp_fx = Etot; move16(); - *sign_dyn_lp = 0; + hNoiseEst->sign_dyn_lp_fx = 0; move16(); } ELSE { /* *Etot_lp = 0.20f*Etot + 0.80f* *Etot_lp; */ - *Etot_lp = mac_r(L_mult(6554, Etot), 26214, *Etot_lp); + hNoiseEst->Etot_lp_fx = mac_r(L_mult(6554, Etot), 26214, hNoiseEst->Etot_lp_fx); move16(); - *Etot_h = sub(*Etot_h, 10); + hNoiseEst->Etot_h_fx = sub(hNoiseEst->Etot_h_fx, 10); move16(); /* 10=0.04 in Q8 */ - *Etot_h = s_max(*Etot_h, Etot); + hNoiseEst->Etot_h_fx = s_max(hNoiseEst->Etot_h_fx, Etot); move16(); - *Etot_l = add(*Etot_l, 20); + hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, 20); move16(); /* 20 = .08 in Q8 */ /* Could even be higher but it also delays first entry to DTX */ - IF ( GT_16(harm_cor_cnt,HE_LT_CNT_PRE_FX)) + IF(GT_16(hNoiseEst->harm_cor_cnt_fx,HE_LT_CNT_PRE_FX)) { test(); - IF( ( LT_16( ini_frame_fx , s_min(HE_LT_CNT_INIT_FX ,MAX_FRAME_COUNTER-1) )) - && (LT_16(sub(*Etot_h, *Etot_lp),(Word16)3*256) ) /* 3.0 Q8 */ + IF((LT_16(ini_frame_fx , s_min(HE_LT_CNT_INIT_FX ,MAX_FRAME_COUNTER - 1))) + && (LT_16(sub(hNoiseEst->Etot_h_fx, hNoiseEst->Etot_lp_fx),(Word16)3 * 256)) /* 3.0 Q8 */ ) { /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */ - tmp = mult_r(sub(*Etot_last, *Etot_l), 3277); /* factor in Q15 3277 .1*32768 */ - tmp = s_min(512, tmp); /* 2.0 in Q8 is 512*/ - *Etot_l = add(*Etot_l, tmp); + tmp = mult_r(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), 3277); /* factor in Q15 3277 .1*32768 */ + tmp = s_min(512, tmp); /* 2.0 in Q8 is 512*/ + hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, tmp); move16();/* Q8 */ } /* Avoids large steps in short active segments */ test(); - IF ( ( GT_16(sub(*Etot_last, *Etot_l), HE_LT_THR2_FX )) /* 30.0f*Q8 */ - && (GT_16(harm_cor_cnt,HE_LT_CNT_PRE_SHORT_FX)) + IF((GT_16(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), HE_LT_THR2_FX)) /* 30.0f*Q8 */ + && (GT_16(hNoiseEst->harm_cor_cnt_fx,HE_LT_CNT_PRE_SHORT_FX)) ) { /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */ - *Etot_l = add(*Etot_l, mult_r(sub(*Etot_last, *Etot_l), 655)); + hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, mult_r(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), 655)); move16();/* 0.02 = 655 Q8*/ } - ELSE IF (GT_16(sub(*Etot_last, *Etot_l), HE_LT_THR1_FX )) /* 10.0 in Q8*/ + ELSE IF(GT_16(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), HE_LT_THR1_FX)) /* 10.0 in Q8*/ { - *Etot_l = add(*Etot_l, 20); + hNoiseEst->Etot_l_fx = add(hNoiseEst->Etot_l_fx, 20); move16();/* 0.08 is 20 in Q8*/ } } - *Etot_l = s_min(*Etot_l, Etot); + hNoiseEst->Etot_l_fx = s_min(hNoiseEst->Etot_l_fx, Etot); - IF ( LT_16(ini_frame_fx,100)&<_16(*Etot_l,*Etot_l_lp)) + IF(LT_16(ini_frame_fx,100) && LT_16(hNoiseEst->Etot_l_fx,hNoiseEst->Etot_l_lp_fx)) { /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */ - *Etot_l_lp = mac_r(L_mult(3277, *Etot_l), 29491, *Etot_l_lp); + hNoiseEst->Etot_l_lp_fx = mac_r(L_mult(3277, hNoiseEst->Etot_l_fx), 29491, hNoiseEst->Etot_l_lp_fx); move16(); } ELSE @@ -313,31 +333,32 @@ void noise_est_pre_fx( test(); test(); test(); - IF ( ( (GT_16(harm_cor_cnt, HE_LT_CNT_FX)) - && (GT_16(sub(*Etot_last, *Etot_l), HE_LT_THR2_FX ) ) + IF(((GT_16(hNoiseEst->harm_cor_cnt_fx, HE_LT_CNT_FX)) + && (GT_16(sub(hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx), HE_LT_THR2_FX)) ) - || ( (sub(harm_cor_cnt, HE_LT_CNT_FX) > 0 ) && (LT_16(ini_frame_fx, HE_LT_CNT_INIT_FX) ) ) - || (GT_16(sub(*Etot_l_lp, *Etot_l), HE_LT_THR2_FX ) ) + || ((sub(hNoiseEst->harm_cor_cnt_fx, HE_LT_CNT_FX) > 0) && (LT_16(ini_frame_fx, HE_LT_CNT_INIT_FX))) + || (GT_16(sub(hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx), HE_LT_THR2_FX)) ) { /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ - *Etot_l_lp = mac_r(L_mult(983, *Etot_l), 31785, *Etot_l_lp); + hNoiseEst->Etot_l_lp_fx = mac_r(L_mult(983, hNoiseEst->Etot_l_fx), 31785, hNoiseEst->Etot_l_lp_fx); move16(); } ELSE { /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */ - *Etot_l_lp = round_fx(L_mac(L_mult(655 , *Etot_l), 32113 , *Etot_l_lp )); + hNoiseEst->Etot_l_lp_fx = round_fx(L_mac(L_mult(655 , hNoiseEst->Etot_l_fx), 32113 , hNoiseEst->Etot_l_lp_fx)); } } - /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ - *sign_dyn_lp = round_fx(L_mac(L_mult(3277, sub(*Etot_h, *Etot_l)), 29491, *sign_dyn_lp)); + /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ + hNoiseEst->sign_dyn_lp_fx = round_fx(L_mac(L_mult(3277, sub(hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx)), 29491, hNoiseEst->sign_dyn_lp_fx)); } return; } + /*==================================================================================*/ /* FUNCTION : noise_est_down_fx() */ /*----------------------------------------------------------------------------------*/ @@ -367,18 +388,18 @@ void noise_est_pre_fx( void noise_est_down_fx( - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ - Word32 bckr[], /* i/o: per band background noise energy estimate */ - Word32 tmpN[], /* o : temporary noise update */ - Word32 enr[], /* o : averaged energy over both subframes */ - const Word16 min_band, /* i : minimum critical band */ - const Word16 max_band, /* i : maximum critical band */ - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 Etot, /* i : Energy of current frame */ - Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ - Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ + Word32 bckr[], /* i/o: per band background noise energy estimate */ + Word32 tmpN[], /* o : temporary noise update */ + Word32 enr[], /* o : averaged energy over both subframes */ + const Word16 min_band, /* i : minimum critical band */ + const Word16 max_band, /* i : maximum critical band */ + Word16 *totalNoise, /* o : noise estimate over all critical bands */ + Word16 Etot, /* i : Energy of current frame */ + Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ + Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ Word16 Q_new, - const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ + const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ ) { @@ -478,31 +499,37 @@ void noise_est_down_fx( * Noise energy estimation (noise energy is updated in case of noise-only frame) *-----------------------------------------------------------------*/ void noise_est_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ - const Word16 *pit, /* i : open-loop pitch values for each half-frame Q0 */ - const Word16 cor[], /* i : normalized correlation for all half-frames Q15 */ - const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ - const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ - const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ - const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ - Word16 *cor_map_sum, /* o : Q8 */ - Word16 *sp_div, /* o : Q_sp_div */ - Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ - Word16 *loc_harm , /* o : multi-harmonicity flag for UV classifier */ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ - Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ - const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ - const Word16 Etot_v_h2, /* i : Energy variations Q8 */ - Word16 *bg_cnt, /* i : Background burst length timer Q0 */ - Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ - Word16 Q_new, /* i : SCaling of current frame */ - const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ - Word16 *sp_floor /* o : noise floor estimate Q7 */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ + const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ + const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ + const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + Word16 *cor_map_sum, /* o : Q8 */ + Word16* ncharX, /* o : IVAS_CODE -> size of ncharX needs validation noise character for sp/mus classifier Qx? */ + Word16 *sp_div, /* o : Q_sp_div */ + Word16 *Q_sp_div, /* o : Q factor for sp_div */ + Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16 *loc_harm , /* o : multi-harmonicity flag for UV classifier */ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ + Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ + const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ + const Word16 Etot_v_h2, /* i : Energy variations Q8 */ + Word16 *bg_cnt, /* i : Background burst length timer Q0 */ + Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ + Word16 Q_new, /* i : SCaling of current frame */ + const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ + Word16 *sp_floor, /* o : noise floor estimate Q7 */ + Word16 S_map[], /* o : short-term correlation map Q7 */ +#ifdef IVAS_CODE + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */ +#endif + const Word16 ini_frame /* i : Frame number (init) */ ) { Word16 alpha, alpha2, alpha2m1, alpham1; @@ -541,43 +568,74 @@ void noise_est_fx( Word16 lim_Etot_fx; /* Q8 */ Word16 lim_Etot_sq_fx; /* Q2 */ Word16 st_E_var_est_fx; /* Q2 */ + NOISE_EST_HANDLE hNoiseEst; + SP_MUS_CLAS_HANDLE hSpMusClas; + hSpMusClas = st_fx->hSpMusClas; + + /* Check if LR-VAD */ +#ifdef IVAS_CODE + IF (hFrontVad != NULL) + { + hNoiseEst = hFrontVad->hNoiseEst; + } + ELSE +#endif + { + hNoiseEst = st_fx->hNoiseEst; + } + + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ - vad_bwidth_fx = st_fx->input_bwidth_fx; move16(); /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ - Ltmp = L_shr(lf_E[0],3); - FOR(i = 1; i < 8; i++) - { - Ltmp = L_add(Ltmp, L_shr(lf_E[i],3)); - } - Ltmp = L_max(Ltmp,(Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ - e_ener = norm_l(Ltmp); - f_ener = Log2_norm_lc(L_shl(Ltmp, e_ener)); - e_ener = sub(30, e_ener); - e_ener = sub(e_ener, sub(add(Q_new,QSCALE),2)); - Ltmp = Mpy_32_16(e_ener, f_ener, LG10); - wtmp = round_fx(L_shl(Ltmp, 10));/*Q8*/ - - /* st_fx->ener_RAT /= (Etot + 0.01f); */ - wtmp1 = add(Etot,3);/*3 is 0.01 in Q8 */ - /* st_fx->ener_RAT_fx = wtmp/wtmp1 */ - st_fx->ener_RAT_fx = 0; - move16(); - IF( wtmp > 0 ) +#ifdef IVAS_CODE + IF(hFrontVad == NULL) +#endif { - st_fx->ener_RAT_fx = 32767; - move16(); /*Q15*/ - if(GE_16(wtmp1, wtmp )) + if (hSpMusClas != NULL) { - st_fx->ener_RAT_fx = div_s(wtmp, wtmp1); /*Q15*//* wtmp1 gte than wtmp */ + Ltmp = L_shr(lf_E[0], 3); + FOR(i = 1; i < 8; i++) + { + Ltmp = L_add(Ltmp, L_shr(lf_E[i], 3)); + } + IF (LT_32(Ltmp, L_shl(1, add(Q_new, Q_SCALE - 2)))) + { + hSpMusClas->ener_RAT_fx = 0; + PMT("hSpMusClas->ener_RAT_fx = 0, that should be validated") + } + ELSE + { + Ltmp = L_max(Ltmp, (Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ + e_ener = norm_l(Ltmp); + f_ener = Log2_norm_lc(L_shl(Ltmp, e_ener)); + e_ener = sub(30, e_ener); + e_ener = sub(e_ener, sub(add(Q_new, QSCALE), 2)); + Ltmp = Mpy_32_16(e_ener, f_ener, LG10); + wtmp = round_fx(L_shl(Ltmp, 10));/*Q8*/ + + /* st_fx->ener_RAT /= (Etot + 0.01f); */ + wtmp1 = add(Etot, 3);/*3 is 0.01 in Q8 */ + /* st_fx->ener_RAT_fx = wtmp/wtmp1 */ + hSpMusClas->ener_RAT_fx = 0; + move16(); + IF(wtmp > 0) + { + hSpMusClas->ener_RAT_fx = 32767; + move16(); /*Q15*/ + if (GE_16(wtmp1, wtmp)) + { + hSpMusClas->ener_RAT_fx = div_s(wtmp, wtmp1); /*Q15*//* wtmp1 gte than wtmp */ + } + } + } } } - /*-----------------------------------------------------------------* * Set the threshold for eps & non_sta based on input sampling rate * The reason is that in case of 8kHz sampling input, there is nothing @@ -615,15 +673,15 @@ void noise_est_fx( *-----------------------------------------------------------------*/ /* pc = abs(pit[0] - pitO) + abs(pit[1] - pit[0]) */ /* needed in signal_clas() */ - wtmp = abs_s(sub(pit[0], st_fx->pitO_fx)); - wtmp1 = abs_s(sub(pit[1], pit[0])); + wtmp = abs_s(sub(st_fx->pitch_fx[0], old_pitch1)); + wtmp1 = abs_s(sub(st_fx->pitch_fx[1], st_fx->pitch_fx[0])); pc = add(wtmp, wtmp1); Ltmp = L_deposit_h(corr_shift); - Ltmp = L_mac(Ltmp, cor[0], 10923); - Ltmp = L_mac(Ltmp, cor[1], 10923); - wtmp = mac_r(Ltmp, cor[2], 10923); + Ltmp = L_mac(Ltmp, st_fx->voicing_fx[0], 10923); + Ltmp = L_mac(Ltmp, st_fx->voicing_fx[1], 10923); + wtmp = mac_r(Ltmp, st_fx->voicing_fx[2], 10923); tmp_pc = pc; move16(); @@ -633,16 +691,22 @@ void noise_est_fx( move16(); /* low correlation -> probably inactive signal */ } - st_fx->pitO_fx = pit[1]; move16(); /* Update */ /*-----------------------------------------------------------------* * Multi-harmonic analysis *-----------------------------------------------------------------*/ - - *loc_harm = multi_harm_fx( EspecdB, st_fx->old_S_fx, st_fx->cor_map_fx, &st_fx->multi_harm_limit_fx, st_fx->total_brate_fx, - st_fx->bwidth_fx, &st_fx->cor_strong_limit_fx, &st_fx->mean_avr_dyn_fx, &st_fx->last_sw_dyn_fx, cor_map_sum, sp_floor ); - +#ifdef IVAS_CODE + IF (hFrontVad == NULL) +#endif + { + IF (st_fx->hSpMusClas != NULL) + { + i = 0; move16(); + *loc_harm = multi_harm_fx(EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate_fx, + st_fx->bwidth_fx, (st_fx->hGSCEnc != NULL) ? &hGSCEnc->cor_strong_limit_fx : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map); + } + } /*-----------------------------------------------------------------* * Detection of frames with non-stationary spectral content *-----------------------------------------------------------------*/ @@ -655,18 +719,18 @@ void noise_est_fx( tmpExp = 0; move16(); ExpLmax = sub(30, norm_l(fr_bands[10])); - ExpLmax2 = sub(30, norm_l(st_fx->fr_bands2_fx[10])); + ExpLmax2 = sub(30, norm_l(hNoiseEst->fr_bands2_fx[10])); tmpExp = s_max(tmpExp, sub(shl(s_max(ExpLmax,ExpLmax2), 1), s_min(ExpLmax, ExpLmax2))); FOR (i = 11; i<= st_fx->max_band_fx; i++) { ExpLmax = sub(30, norm_l(fr_bands[i])); - ExpLmax2 = sub(30, norm_l(st_fx->fr_bands2_fx[i])); + ExpLmax2 = sub(30, norm_l(hNoiseEst->fr_bands2_fx[i])); tmpExp = s_max(tmpExp, sub(shl(s_max(ExpLmax,ExpLmax2), 1), s_min(ExpLmax, ExpLmax2))); } tmpExp = sub(tmpExp, 30-4-4); /* 4bits for internal summation and 4 bits for comparaison */ pt1 = fr_bands + 10; - pt2 = st_fx->fr_bands2_fx + 10; + pt2 = hNoiseEst->fr_bands2_fx + 10; FOR (i=10; i<=st_fx->max_band_fx; i++) { Lnum = L_max(*pt1, *pt2); /* Don't need if anymore */ @@ -727,7 +791,12 @@ void noise_est_fx( Ltmp2 = sum32_fx( &fr_bands[10], sub(st_fx->max_band_fx,9) ); wtmp = shl(1, sub(add(Q_new, QSCALE), 1)); - +#ifdef IVAS_CODE + IF (ncharX != NULL) + { + *ncharX = ftemp2 / (ftemp + 1e-5f); + } +#endif test(); IF (L_msu(Ltmp, 100, wtmp) < 0 || L_msu(Ltmp2, 100, wtmp) < 0) { @@ -750,7 +819,7 @@ void noise_est_fx( /* update LT value of the final parameter */ /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */ - st_fx->noise_char_fx = mac_r(L_mult(M_ALPHA_FX, st_fx->noise_char_fx), ONE_MINUS_M_ALPHA, noise_chartmp); + hNoiseEst->noise_char_fx = mac_r(L_mult(M_ALPHA_FX, hNoiseEst->noise_char_fx), ONE_MINUS_M_ALPHA, noise_chartmp); nchar_thr = THR_NCHAR_WB_FX; @@ -763,15 +832,15 @@ void noise_est_fx( noise_char = 0; move16(); - if (GT_16(st_fx->noise_char_fx, nchar_thr)) + if (GT_16(hNoiseEst->noise_char_fx, nchar_thr)) { noise_char = 1; move16(); } /* save the 2 last spectra per crit. bands for the future */ - Copy32(st_fx->fr_bands1_fx, st_fx->fr_bands2_fx, NB_BANDS); - Copy32(fr_bands+NB_BANDS, st_fx->fr_bands1_fx, NB_BANDS); + Copy32(hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS); + Copy32(fr_bands+NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS); /*-----------------------------------------------------------------* * Non-stationarity estimation for each band @@ -823,7 +892,7 @@ void noise_est_fx( tmp_Q = add(Q_new, Q_SCALE); Ltmp = L_shl((Word32)1L, tmp_Q); /* 1.0 added in the right dynamic domain */ L_tmp_enr = L_add(enr[i] , Ltmp ); /* enr scale dynamic */ - L_tmp_ave_enr = L_add(st_fx->ave_enr_fx[i], Ltmp); /* ave__enr scale dynamic */ + L_tmp_ave_enr = L_add(hNoiseEst->ave_enr_fx[i], Ltmp); /* ave__enr scale dynamic */ IF (LE_32(non_sta, th_sta)) /* Just to limit the saturation */ { @@ -846,9 +915,9 @@ void noise_est_fx( } /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */ - Ltmp = Mult_32_16(st_fx->ave_enr_fx[i], alpha); + Ltmp = Mult_32_16(hNoiseEst->ave_enr_fx[i], alpha); Ltmp = L_add(Ltmp, Mult_32_16(enr[i], alpham1)); - st_fx->ave_enr_fx[i] = L_max(Le_min_scaled, Ltmp); + hNoiseEst->ave_enr_fx[i] = L_max(Le_min_scaled, Ltmp); move32(); /* calculation of another non-stationarity measure (following attacks) */ @@ -864,7 +933,7 @@ void noise_est_fx( /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */ Ltmp = L_shl((Word32)1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ - L_tmp_ave_enr2 = L_add(st_fx->ave_enr2_fx[i], Ltmp); /* ave__enr scale dynamic */ + L_tmp_ave_enr2 = L_add(hNoiseEst->ave_enr2_fx[i], Ltmp); /* ave__enr scale dynamic */ IF (LE_32(Lnon_sta2, th_sta )) /* Just to limit the saturation */ { @@ -883,32 +952,48 @@ void noise_est_fx( /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i] + (1.0f - alpha2) * (enr[i]) */ - Ltmp1 = Mult_32_16(st_fx->ave_enr2_fx[i], alpha2); + Ltmp1 = Mult_32_16(hNoiseEst->ave_enr2_fx[i], alpha2); Ltmp1 = L_add(Ltmp1, Mult_32_16(enr[i], alpha2m1)); - st_fx->ave_enr2_fx[i] = L_max(Le_min_scaled, Ltmp1); + hNoiseEst->ave_enr2_fx[i] = L_max(Le_min_scaled, Ltmp1); move32(); /* calculation of non-stationarity measure for speech/music classification */ - test(); - IF ( GE_16(i,START_BAND_SPMUS)&<_16(i,NB_BANDS_SPMUS+START_BAND_SPMUS)) +#ifdef IVAS_CODE + IF(hFrontVad == NULL) +#endif { - /* log_enr = (float)ln_fx(enr[i]); */ - log_enr16 = noise_est_ln_q8_fx( enr[i], 0 ,tmp_Q); - wtmp = abs_s(sub(log_enr16, st_fx->past_log_enr_fx[i-START_BAND_SPMUS])); - *non_staX = add(*non_staX, wtmp); - move16(); /* Q8 */ - st_fx->past_log_enr_fx[i-START_BAND_SPMUS] = log_enr16; - move16(); - - /* calculate non-stationarity feature relative background */ - tmp_enr = noise_est_ln_q8_fx( enr[i], 1 , tmp_Q); /* 1.0f added */ - tmp_floor = LN_E_MIN_PLUS_ONE_FX ; - move16(); /* non dynamic init constant in Q8 */ - IF ( GE_16(st_fx->ini_frame_fx, 100 )) + test();test(); + IF(GE_16(i, START_BAND_SPMUS) && LT_16(i, NB_BANDS_SPMUS + START_BAND_SPMUS) && st_fx->hSpMusClas != NULL) { - tmp_floor = noise_est_ln_q8_fx( st_fx->bckr_fx[i], 1, tmp_Q ); + /* log_enr = (float)ln_fx(enr[i]); */ + log_enr16 = noise_est_ln_q8_fx(enr[i], 0, tmp_Q); + wtmp = abs_s(sub(log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS])); + *non_staX = add(*non_staX, wtmp); + move16(); /* Q8 */ + hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16; + move16(); + } + } + IF(GE_16(i, 2) && LE_16(i, 16)) + { + IF(GE_16(ini_frame , 100)) + { + /* calculate non-stationarity feature relative background */ + tmp_enr = noise_est_ln_q8_fx(enr[i], 1, tmp_Q); /* 1.0f added */ + tmp_floor = LN_E_MIN_PLUS_ONE_FX; + move16(); /* non dynamic init constant in Q8 */ + tmp_floor = noise_est_ln_q8_fx(hNoiseEst->bckr_fx[i], 1, tmp_Q); + non_staB = add(non_staB, abs_s(sub(tmp_enr, tmp_floor))); /* Q8 */ + } + ELSE /*ini_frame < 100*/ + { + /* calculate non-stationarity feature relative background */ + tmp_enr = noise_est_ln_q8_fx(enr[i], 1, tmp_Q); /* 1.0f added */ + tmp_floor = LN_E_MIN_PLUS_ONE_FX; + move16(); /* non dynamic init constant in Q8 */ + tmp_floor = noise_est_ln_q8_fx(E_MIN_FX, 1, tmp_Q); + non_staB = add(non_staB, abs_s(sub(tmp_enr, tmp_floor))); /* Q8 */ } - non_staB = add(non_staB, abs_s(sub(tmp_enr, tmp_floor))); /* Q8 */ } } /* end of band loop FOR( i = st_fx->min_band_fx; i <= st_fx->max_band_fx; i++ ) */ @@ -926,23 +1011,23 @@ void noise_est_fx( { /* Allow use of quicker filter during init - if needed */ /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - st_fx->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, st_fx->Etot_st_est_fx); + hNoiseEst->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, hNoiseEst->Etot_st_est_fx); move16(); /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - st_fx->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, st_fx->Etot_sq_st_est_fx); + hNoiseEst->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, hNoiseEst->Etot_sq_st_est_fx); move16(); } else { /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - st_fx->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, st_fx->Etot_st_est_fx); + hNoiseEst->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, hNoiseEst->Etot_st_est_fx); move16(); /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - st_fx->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, st_fx->Etot_sq_st_est_fx); + hNoiseEst->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, hNoiseEst->Etot_sq_st_est_fx); move16(); } - st_E_var_est_fx = sub(st_fx->Etot_sq_st_est_fx,extract_h(L_shl_r(L_mult(st_fx->Etot_st_est_fx,st_fx->Etot_st_est_fx),1))); + st_E_var_est_fx = sub(hNoiseEst->Etot_sq_st_est_fx,extract_h(L_shl_r(L_mult(hNoiseEst->Etot_st_est_fx,hNoiseEst->Etot_st_est_fx),1))); @@ -950,8 +1035,8 @@ void noise_est_fx( * Count frames since last correlation or harmonic event *-----------------------------------------------------------------*/ - Ltmp = L_mult(cor[0], 16384); - Ltmp = L_mac(Ltmp, cor[1], 16384); + Ltmp = L_mult(st_fx->voicing_fx[0], 16384); + Ltmp = L_mac(Ltmp, st_fx->voicing_fx[1], 16384); test(); test(); @@ -964,7 +1049,7 @@ void noise_est_fx( IF( (GT_16(*st_harm_cor_cnt,1))&&((LT_16(Etot,3840))||/* 15 in Q8 */ ( GT_16(st_fx->ini_frame_fx,10) && - GT_16(sub(Etot,st_fx->Etot_lp_fx),1792) )) /* 7 in Q8 */ + GT_16(sub(Etot, hNoiseEst->Etot_lp_fx),1792) )) /* 7 in Q8 */ ) { *st_harm_cor_cnt = 1; @@ -1024,10 +1109,10 @@ void noise_est_fx( /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */ alpha = 4915; move16(); /*0.15 in Q15 */ - st_fx->epsP_0_2_lp_fx = noise_est_AR1_Qx(epsP_0_2, st_fx->epsP_0_2_lp_fx ,alpha); + hNoiseEst->epsP_0_2_lp_fx = noise_est_AR1_Qx(epsP_0_2, hNoiseEst->epsP_0_2_lp_fx ,alpha); /* epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); */ - epsP_0_2_ad = abs_s(sub(epsP_0_2, st_fx->epsP_0_2_lp_fx)); /* Q12 */ + epsP_0_2_ad = abs_s(sub(epsP_0_2, hNoiseEst->epsP_0_2_lp_fx)); /* Q12 */ /*if (epsP_0_2_ad < st->epsP_0_2_ad_lp) { st->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + (1.0f - 0.1f) * st->epsP_0_2_ad_lp; @@ -1036,14 +1121,14 @@ void noise_est_fx( } */ alpha = 6554; move16();/* 0.2 Q15 */ - if (LT_16(epsP_0_2_ad, st_fx->epsP_0_2_ad_lp_fx)) + if (LT_16(epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx)) { alpha = shr(alpha,1); /* 0.1 Q15 */ } - st_fx->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx(epsP_0_2_ad, st_fx->epsP_0_2_ad_lp_fx ,alpha); + hNoiseEst->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx(epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ,alpha); /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/ - epsP_0_2_ad_lp_max = s_max(epsP_0_2_ad, st_fx->epsP_0_2_ad_lp_fx); /* Q12 */ + epsP_0_2_ad_lp_max = s_max(epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx); /* Q12 */ /*-----------------------------------------------------------------* @@ -1071,16 +1156,16 @@ void noise_est_fx( alpha = 983 ; move16();/* 0.03 Q15 */ - if (GT_16(epsP_2_16 , st_fx->epsP_2_16_lp_fx)) + if (GT_16(epsP_2_16 , hNoiseEst->epsP_2_16_lp_fx)) { alpha = 6554; move16();/* 0.2 Q15 */ } - st_fx->epsP_2_16_lp_fx = noise_est_AR1_Qx(epsP_2_16, st_fx->epsP_2_16_lp_fx , alpha); + hNoiseEst->epsP_2_16_lp_fx = noise_est_AR1_Qx(epsP_2_16, hNoiseEst->epsP_2_16_lp_fx , alpha); - st_fx->epsP_2_16_lp2_fx = noise_est_AR1_Qx(epsP_2_16, st_fx->epsP_2_16_lp2_fx , 655); /* 0.02 */ + hNoiseEst->epsP_2_16_lp2_fx = noise_est_AR1_Qx(epsP_2_16, hNoiseEst->epsP_2_16_lp2_fx , 655); /* 0.02 */ - epsP_2_16_dlp = sub(st_fx->epsP_2_16_lp_fx, st_fx->epsP_2_16_lp2_fx); + epsP_2_16_dlp = sub(hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx); /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) { @@ -1090,21 +1175,21 @@ void noise_est_fx( }*/ alpha = 1638; move16();/* 0.05 Q15 */ - if (LT_16(epsP_2_16_dlp , st_fx->epsP_2_16_dlp_lp2_fx)) + if (LT_16(epsP_2_16_dlp , hNoiseEst->epsP_2_16_dlp_lp2_fx)) { alpha = 655; move16();/* 0.02 Q15 */ } - st_fx->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx(epsP_2_16_dlp, st_fx->epsP_2_16_dlp_lp2_fx , alpha); + hNoiseEst->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx(epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx , alpha); /* epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); */ - epsP_2_16_dlp_max = s_max(epsP_2_16_dlp, st_fx->epsP_2_16_dlp_lp2_fx); + epsP_2_16_dlp_max = s_max(epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx); /*-----------------------------------------------------------------* * long term extensions of frame features *-----------------------------------------------------------------*/ - tmp = sub(Etot, st_fx->totalNoise_fx ); /* Q8 */ + tmp = sub(Etot, hNoiseEst->totalNoise_fx ); /* Q8 */ /* st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; */ tmp2 = 0; move16(); @@ -1113,14 +1198,14 @@ void noise_est_fx( tmp2=32767; move16(); } - st_fx->lt_tn_track_fx = noise_est_AR1_Qx(tmp2, st_fx->lt_tn_track_fx , 983); /*0.03 in Q15 ,Q15 state*/ + hNoiseEst->lt_tn_track_fx = noise_est_AR1_Qx(tmp2, hNoiseEst->lt_tn_track_fx , 983); /*0.03 in Q15 ,Q15 state*/ /* st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; */ - st_fx->lt_tn_dist_fx = noise_est_AR1_Qx(tmp, st_fx->lt_tn_dist_fx , 983); /*0.03 in Q15 ,Q8 state*/ + hNoiseEst->lt_tn_dist_fx = noise_est_AR1_Qx(tmp, hNoiseEst->lt_tn_dist_fx , 983); /*0.03 in Q15 ,Q8 state*/ /* st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist;*/ - tmp = sub(Etot,st_fx->Etot_l_lp_fx); /* Q8 */ - st_fx->lt_Ellp_dist_fx = noise_est_AR1_Qx(tmp, st_fx->lt_Ellp_dist_fx, 983); /*0.03 in Q15 ,Q8 state*/ + tmp = sub(Etot, hNoiseEst->Etot_l_lp_fx); /* Q8 */ + hNoiseEst->lt_Ellp_dist_fx = noise_est_AR1_Qx(tmp, hNoiseEst->lt_Ellp_dist_fx, 983); /*0.03 in Q15 ,Q8 state*/ @@ -1131,11 +1216,11 @@ void noise_est_fx( } */ IF ( *st_harm_cor_cnt == 0) { - st_fx->lt_haco_ev_fx = noise_est_AR1_Qx((Word16)32767, st_fx->lt_haco_ev_fx, 983); /*.03 in Q15 , Q15 state */ + hNoiseEst->lt_haco_ev_fx = noise_est_AR1_Qx((Word16)32767, hNoiseEst->lt_haco_ev_fx, 983); /*.03 in Q15 , Q15 state */ } ELSE { - st_fx->lt_haco_ev_fx = mult_r(32440, st_fx->lt_haco_ev_fx); /*.99 in Q15 , Q15 state */ + hNoiseEst->lt_haco_ev_fx = mult_r(32440, hNoiseEst->lt_haco_ev_fx); /*.99 in Q15 , Q15 state */ } @@ -1147,11 +1232,11 @@ void noise_est_fx( tmp = 0; move16(); move16(); - if( LT_16( st_fx->lt_tn_track_fx , 1638 )) /* 0.05 in Q15*/ + if( LT_16(hNoiseEst->lt_tn_track_fx , 1638 )) /* 0.05 in Q15*/ { - tmp = add(st_fx->low_tn_track_cnt_fx, 1); + tmp = add(hNoiseEst->low_tn_track_cnt_fx, 1); } - st_fx->low_tn_track_cnt_fx = tmp; + hNoiseEst->low_tn_track_cnt_fx = tmp; move16(); @@ -1161,7 +1246,7 @@ void noise_est_fx( } else { st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0; }*/ - Ltmp = L_mult(M_GAMMA_FX, st_fx->act_pred_fx); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ + Ltmp = L_mult(M_GAMMA_FX, hNoiseEst->act_pred_fx); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ tmp = round_fx(Ltmp); /* Q15 */ test(); if ( ( GT_32(non_sta, th_sta)) /* float th_sta NB 5e10 , WB 3.5e10*/ @@ -1170,7 +1255,7 @@ void noise_est_fx( { tmp = mac_r(Ltmp, (-32768+M_GAMMA_FX), -32768); /* (-0.01)*(-1.0) */ } - st_fx->act_pred_fx = tmp ; + hNoiseEst->act_pred_fx = tmp ; move16(); @@ -1178,8 +1263,8 @@ void noise_est_fx( /*-----------------------------------------------------------------* * Background noise adaptation enable flag *-----------------------------------------------------------------*/ - Ltmp = L_mult(cor[0], 16384); - Ltmp = L_mac(Ltmp, cor[1], 16384); + Ltmp = L_mult(st_fx->voicing_fx[0], 16384); + Ltmp = L_mac(Ltmp, st_fx->voicing_fx[1], 16384); cor_tmp = mac_r(Ltmp, corr_shift,MAX_16); LepsP = eps_quota_fx(epsP_h[2] , epsP_l[2], @@ -1202,8 +1287,8 @@ void noise_est_fx( ((st->act_pred > 0.8f) && (non_sta2 > th_sta)) ) */ - Ltmp = L_mult(cor[0], 16384); /* Q15 + Q15(.5)) + 1 -> Q31 */ - cor_tmp = mac_r(Ltmp, cor[1], 16384 ); /* Q31 -16 -> Q15 */ + Ltmp = L_mult(st_fx->voicing_fx[0], 16384); /* Q15 + Q15(.5)) + 1 -> Q31 */ + cor_tmp = mac_r(Ltmp, st_fx->voicing_fx[1], 16384 ); /* Q31 -16 -> Q15 */ if ( Etot < 0 ) { cor_tmp = 0; @@ -1228,7 +1313,7 @@ void noise_est_fx( ( GT_16(cor_tmp, cor_max) ) || /* Q15 */ ( GT_32(LepsP, th_eps) ) || /* Q11 */ ( GT_16(*loc_harm,0)) || - ((GT_16(st_fx->act_pred_fx, 26214) ) && (GT_32(Lnon_sta2, th_sta) ) ) /*act_pred in Q15 , th_sta in Q10 */ + ((GT_16(hNoiseEst->act_pred_fx, 26214) ) && (GT_32(Lnon_sta2, th_sta) ) ) /*act_pred in Q15 , th_sta in Q10 */ ) { vad_2nd_stage_fx = 1; @@ -1242,25 +1327,55 @@ void noise_est_fx( tmp = -1; move16(); /* Background present */ } - st_fx->aEn_fx = add(st_fx->aEn_fx, tmp); + hNoiseEst->aEn_fx = add(hNoiseEst->aEn_fx, tmp); - st_fx->aEn_fx = s_min(st_fx->aEn_fx,6); - st_fx->aEn_fx = s_max(st_fx->aEn_fx,0); + hNoiseEst->aEn_fx = s_min(hNoiseEst->aEn_fx,6); + hNoiseEst->aEn_fx = s_max(hNoiseEst->aEn_fx,0); +#ifdef IVAS_CODE + /*-----------------------------------------------------------------* + * Stereo classifier - save raw aEn + *-----------------------------------------------------------------*/ + if (hStereoClassif != NULL) + { + if ((non_sta > th_sta) || + (tmp_pc < TH_PC) || + (0.5f * (st->voicing[0] + st->voicing[1]) > cor_max) || + (epsP[2] / epsP[16] > th_eps) || + ((hNoiseEst->act_pred > 0.8f) && (non_sta2 > th_sta))) + { + /* active signal present - increment counter */ + hStereoClassif->aEn_raw[st->idchan] = hStereoClassif->aEn_raw[st->idchan] + 2; + } + else + { + /* background noise present - decrement counter */ + hStereoClassif->aEn_raw[st->idchan] = hStereoClassif->aEn_raw[st->idchan] - 1; + } + if (hStereoClassif->aEn_raw[st->idchan] > 6) + { + hStereoClassif->aEn_raw[st->idchan] = 6; + } + else if (hStereoClassif->aEn_raw[st->idchan] < 0) + { + hStereoClassif->aEn_raw[st->idchan] = 0; + } + } +#endif /* Additional NNE detectors */ /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ /* Q15 Q15 Q12 */ - comb_ahc_epsP = s_max(s_max(shr(st_fx->act_pred_fx,15-12), shr(st_fx->lt_haco_ev_fx, 15-12)), epsP_2_16_dlp); /* Q12 */ + comb_ahc_epsP = s_max(s_max(shr(hNoiseEst->act_pred_fx,15-12), shr(hNoiseEst->lt_haco_ev_fx, 15-12)), epsP_2_16_dlp); /* Q12 */ /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ /* Q15 Q12 Q12 */ - comb_hcm_epsP = s_max(s_max(shr(st_fx->lt_haco_ev_fx,15-12), epsP_2_16_dlp_max), epsP_0_2_ad_lp_max); /* Q12 */ + comb_hcm_epsP = s_max(s_max(shr(hNoiseEst->lt_haco_ev_fx,15-12), epsP_2_16_dlp_max), epsP_0_2_ad_lp_max); /* Q12 */ /*haco_ev_max = max(*st_harm_cor_cnt==0,st->lt_haco_ev); */ tmp = 0; @@ -1270,16 +1385,16 @@ void noise_est_fx( tmp = (Word16)32767; move16(); } - haco_ev_max = s_max(tmp, st_fx->lt_haco_ev_fx); /* Q15 */ + haco_ev_max = s_max(tmp, hNoiseEst->lt_haco_ev_fx); /* Q15 */ /* Etot_l_lp_thr = st->Etot_l_lp + (1.5f + 1.5f * (st->Etot_lp<50.0f))*st->Etot_v_h2; */ tmp = 12288; move16();/* 1.5 Q13 */ - if( LT_16(st_fx->Etot_lp_fx, 12800 )) /* 50.0 in Q8 */ + if( LT_16(hNoiseEst->Etot_lp_fx, 12800 )) /* 50.0 in Q8 */ { tmp =shl(tmp,1); /*1.5 + 1.5 Q13 */ } - Ltmp = L_deposit_h(st_fx->Etot_l_lp_fx); + Ltmp = L_deposit_h(hNoiseEst->Etot_l_lp_fx); Etot_l_lp_thr = round_fx(L_add(Ltmp, L_shl(L_mult(tmp, Etot_v_h2),2))); /* Q13+Q8+1 +2 = Q24 -> Q8*/ /* enr_bgd = Etot < Etot_l_lp_thr; */ @@ -1325,7 +1440,7 @@ void noise_est_fx( /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); - if( LT_16(st_fx->lt_haco_ev_fx, 16384 )) /* ( .5 in Q15)*/ + if( LT_16(hNoiseEst->lt_haco_ev_fx, 16384 )) /* ( .5 in Q15)*/ { lt_haco_mask = 1; move16(); /* Q0 */ @@ -1414,8 +1529,8 @@ void noise_est_fx( test(); test(); if( ( (SD_1 == 0) || (LT_16(Etot, Etot_l_lp_thr))) - && (bg_haco_mask != 0) && ( LT_16(st_fx->act_pred_fx, 27853 ) ) /* 0.85f in Q15 */ - && (LT_16(st_fx->Etot_lp_fx, 50*256) )) /* 50.0 in Q8 */ + && (bg_haco_mask != 0) && ( LT_16(hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85f in Q15 */ + && (LT_16(hNoiseEst->Etot_lp_fx, 50*256) )) /* 50.0 in Q8 */ { BG_1 = 1; move16(); @@ -1426,7 +1541,7 @@ void noise_est_fx( && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); */ PAU=0; move16();/*Q0*/ - if(st_fx->aEn_fx == 0) + if(hNoiseEst->aEn_fx == 0) { PAU = 1; move16();/*Q0*/ @@ -1449,7 +1564,7 @@ void noise_est_fx( /* aE_bgd = (st->aEn == 0);*/ aE_bgd = 0; move16(); - if(st_fx->aEn_fx == 0) + if(hNoiseEst->aEn_fx == 0) { aE_bgd = 1; move16(); @@ -1465,8 +1580,8 @@ void noise_est_fx( move16(); test(); test(); - if ( ( GT_16(st_fx->sign_dyn_lp_fx, 15*256)) /* 15 in Q8 */ - && ( LT_16(sub(Etot, st_fx->Etot_l_lp_fx ), shl(Etot_v_h2, 1) ) ) /* Q8 , Etot_v_h2 has limited dynmics can be upscaled*/ + if ( ( GT_16(hNoiseEst->sign_dyn_lp_fx, 15*256)) /* 15 in Q8 */ + && ( LT_16(sub(Etot, hNoiseEst->Etot_l_lp_fx ), shl(Etot_v_h2, 1) ) ) /* Q8 , Etot_v_h2 has limited dynmics can be upscaled*/ && (GT_16(*st_harm_cor_cnt, 20) ) ) { sd1_bgd = 1; @@ -1487,15 +1602,15 @@ void noise_est_fx( test(); test(); test(); - if ( ( (LT_16(st_fx->act_pred_fx, 19333))&&(LT_16(st_fx->lt_haco_ev_fx,7537))) /* .59 in Q15 .23 in Q15 */ - || (LT_16(st_fx->act_pred_fx, 12452) ) /* .38 in Q15 */ - || (LT_16(st_fx->lt_haco_ev_fx, 4915) ) /* .15 in Q15 */ + if ( ( (LT_16(hNoiseEst->act_pred_fx, 19333))&&(LT_16(hNoiseEst->lt_haco_ev_fx,7537))) /* .59 in Q15 .23 in Q15 */ + || (LT_16(hNoiseEst->act_pred_fx, 12452) ) /* .38 in Q15 */ + || ((EQ_16(st_fx->element_mode, EVS_MONO) && LT_16(hNoiseEst->lt_haco_ev_fx, 4915)) || (GT_16(st_fx->element_mode, EVS_MONO) && LT_16(hNoiseEst->lt_haco_ev_fx, 2621)) ) /* .15 in Q15 || 0.08 */ || (LT_16(non_staB, 50*256 ) ) /* 50.0 in Q8 */ || aE_bgd != 0 || ( (LT_16(Etot,10752)) /* 42 in Q8 */ - && (GT_16(st_fx->harm_cor_cnt_fx, 10) ) - && ( LT_16(st_fx->lt_haco_ev_fx, 11469) ) /* 0.35 in Q15 */ - && ( LT_16(st_fx->act_pred_fx, 26214) ) /* 0.80 in Q15 */ + && (GT_16(hNoiseEst->harm_cor_cnt_fx, 10) ) + && ( LT_16(hNoiseEst->lt_haco_ev_fx, 11469) ) /* 0.35 in Q15 */ + && ( LT_16(hNoiseEst->act_pred_fx, 26214) ) /* 0.80 in Q15 */ ) ) { @@ -1508,8 +1623,8 @@ void noise_est_fx( test(); test(); if ( ( LT_16(st_fx->ini_frame_fx, HE_LT_CNT_INIT_FX )) - && ( GT_16(st_fx->harm_cor_cnt_fx,5)) /* > 5 Q0 */ - && ( LT_16(sub(Etot,st_fx->Etot_lp_fx),1792 )) /* 7 in Q8 */ + && ( GT_16(hNoiseEst->harm_cor_cnt_fx,5)) /* > 5 Q0 */ + && ( LT_16(sub(Etot, hNoiseEst->Etot_lp_fx),1792 )) /* 7 in Q8 */ && ( NE_16(tmp, 0)) ) { tn_ini = 1; @@ -1534,7 +1649,7 @@ void noise_est_fx( || tn_ini ) */ tmp = 0; move16(); - if( GT_16(st_fx->lt_tn_track_fx, 29491 )) /* .90 in Q15 */ + if( GT_16(hNoiseEst->lt_tn_track_fx, 29491 )) /* .90 in Q15 */ { tmp = 1; move16(); @@ -1583,26 +1698,26 @@ void noise_est_fx( test(); test(); test(); - IF( ( ( LT_16(st_fx->act_pred_fx, 27853)) /* 0.85 in Q15 */ + IF( ( ( LT_16(hNoiseEst->act_pred_fx, 27853)) /* 0.85 in Q15 */ && ( NE_16(aE_bgd ,0) ) - && ( (LT_16(st_fx->lt_Ellp_dist_fx, 10*256) ) || ( NE_16(sd1_bgd, 0) ) ) /* 10.0 in Q8*/ - && ( LT_16(st_fx->lt_tn_dist_fx, 40*256 ) ) /* 40.0 in Q8*/ - && ( LT_16(sub(Etot, st_fx->totalNoise_fx), 10*256) ) /* 10.0 in Q8*/ + && ( (LT_16(hNoiseEst->lt_Ellp_dist_fx, 10*256) ) || ( NE_16(sd1_bgd, 0) ) ) /* 10.0 in Q8*/ + && ( LT_16(hNoiseEst->lt_tn_dist_fx, 40*256 ) ) /* 40.0 in Q8*/ + && ( LT_16(sub(Etot, hNoiseEst->totalNoise_fx), 10*256) ) /* 10.0 in Q8*/ ) - || ( (st_fx->first_noise_updt_fx == 0) && (GT_16(st_fx->harm_cor_cnt_fx,80) ) - && ( aE_bgd != 0 ) && (GT_16(st_fx->lt_aEn_zero_fx, 16384) ) /*.5 in Q15*/ + || ( (hNoiseEst->first_noise_updt_fx == 0) && (GT_16(hNoiseEst->harm_cor_cnt_fx,80) ) + && ( aE_bgd != 0 ) && (GT_16(hNoiseEst->lt_aEn_zero_fx, 16384) ) /*.5 in Q15*/ ) - || ( (tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( LT_16(non_staB, 10*256) ) || (GT_16(st_fx->harm_cor_cnt_fx, 80) ) ) /* 10.0 in Q8*/ + || ( (tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( LT_16(non_staB, 10*256) ) || (GT_16(hNoiseEst->harm_cor_cnt_fx, 80) ) ) /* 10.0 in Q8*/ ) ) { updt_step = 32767; move16(); - st_fx->first_noise_updt_fx = 1; + hNoiseEst->first_noise_updt_fx = 1; FOR( i=0; i< NB_BANDS; i++ ) { - st_fx->bckr_fx[i] = tmpN[i]; + hNoiseEst->bckr_fx[i] = tmpN[i]; move32(); } } @@ -1613,19 +1728,19 @@ void noise_est_fx( ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f ) || tn_ini ) */ - ELSE IF ( ( ( LT_16(st_fx->act_pred_fx, 26214)) /* .8 in Q15*/ + ELSE IF ( ( ( LT_16(hNoiseEst->act_pred_fx, 26214)) /* .8 in Q15*/ && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) - && (LT_16(st_fx->lt_haco_ev_fx, 3277) ) ) /* .10 in q15*/ - || ( ( LT_16(st_fx->act_pred_fx, 22938 ) ) /* 0.70 in Q15 */ + && (LT_16(hNoiseEst->lt_haco_ev_fx, 3277) ) ) /* .10 in q15*/ + || ( ( LT_16(hNoiseEst->act_pred_fx, 22938 ) ) /* 0.70 in Q15 */ && ( (aE_bgd!=0 ) || ( LT_16(non_staB, 17*256 ) ) )/* 17.0 in Q8 */ && ( PAU != 0 ) - && ( LT_16(st_fx->lt_haco_ev_fx,4915) ) /* 0.15 in Q15 */ + && ( LT_16(hNoiseEst->lt_haco_ev_fx,4915) ) /* 0.15 in Q15 */ ) - || ( (GT_16(st_fx->harm_cor_cnt_fx, 80) ) && (GT_16(st_fx->totalNoise_fx, 5*256) ) /* 5.0 in Q8 */ - && ( LT_16(Etot, s_max((Word16)1*256, add(Etot_l_lp, add(st_fx->Etot_v_h2_fx,shr(st_fx->Etot_v_h2_fx,1))))) ) /* 1.5= 1.0+.5 */ + || ( (GT_16(hNoiseEst->harm_cor_cnt_fx, 80) ) && (GT_16(hNoiseEst->totalNoise_fx, 5*256) ) /* 5.0 in Q8 */ + && ( LT_16(Etot, s_max((Word16)1*256, add(Etot_l_lp, add(hNoiseEst->Etot_v_h2_fx,shr(hNoiseEst->Etot_v_h2_fx,1))))) ) /* 1.5= 1.0+.5 */ ) - || ( (GT_16(st_fx->harm_cor_cnt_fx,50) ) && (GT_16(st_fx->first_noise_updt_fx, 30) ) - && (aE_bgd != 0) && (GT_16(st_fx->lt_aEn_zero_fx, 16384) ) ) /*.5 in Q15*/ + || ( (GT_16(hNoiseEst->harm_cor_cnt_fx,50) ) && (GT_16(hNoiseEst->first_noise_updt_fx, 30) ) + && (aE_bgd != 0) && (GT_16(hNoiseEst->lt_aEn_zero_fx, 16384) ) ) /*.5 in Q15*/ || ( tn_ini != 0 ) ) @@ -1644,10 +1759,10 @@ void noise_est_fx( test(); test(); IF ( ( aE_bgd==0 ) - && ( LT_16(st_fx->harm_cor_cnt_fx, 50) ) - && ( ( GT_16(st_fx->act_pred_fx, 19661) ) /* 0.6 in Q15*/ + && ( LT_16(hNoiseEst->harm_cor_cnt_fx, 50) ) + && ( ( GT_16(hNoiseEst->act_pred_fx, 19661) ) /* 0.6 in Q15*/ || ( ( tn_ini==0 ) - && (LT_16(sub(Etot_l_lp, st_fx->totalNoise_fx),10*256) ) /* 10.0 in Q8 */ + && (LT_16(sub(Etot_l_lp, hNoiseEst->totalNoise_fx),10*256) ) /* 10.0 in Q8 */ && (GT_16(non_staB, 8*256) ) /* 8.0 in in Q8*/ ) ) @@ -1660,24 +1775,24 @@ void noise_est_fx( IF (updt_step > 0 ) { */ - st_fx->first_noise_updt_fx = 1; + hNoiseEst->first_noise_updt_fx = 1; move16(); FOR( i=0; i< NB_BANDS; i++ ) { /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ /* 32 bit state update */ - Ltmp = L_sub(tmpN[i], st_fx->bckr_fx[i]); /*Q_new+Q_SCALE*/ + Ltmp = L_sub(tmpN[i], hNoiseEst->bckr_fx[i]); /*Q_new+Q_SCALE*/ Ltmp = Mult_32_16(Ltmp, updt_step ); /* Q_new+Q_SCALE+15+1 -16*/ - st_fx->bckr_fx[i] = L_add(Ltmp, st_fx->bckr_fx[i]); + hNoiseEst->bckr_fx[i] = L_add(Ltmp, hNoiseEst->bckr_fx[i]); move32(); } /* } */ } /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/ - ELSE IF ( (aE_bgd !=0) || (GT_16(st_fx->harm_cor_cnt_fx, 100))) + ELSE IF ( (aE_bgd !=0) || (GT_16(hNoiseEst->harm_cor_cnt_fx, 100))) { - st_fx->first_noise_updt_fx = add(st_fx->first_noise_updt_fx,1); + hNoiseEst->first_noise_updt_fx = add(hNoiseEst->first_noise_updt_fx,1); } } ELSE @@ -1685,18 +1800,18 @@ void noise_est_fx( /* If in music lower bckr to drop further */ test(); test(); - IF ( (GT_16(st_fx->low_tn_track_cnt_fx, 300)) - && (GT_16(st_fx->lt_haco_ev_fx, 29491 ) ) /*.9 in Q15 */ - && (st_fx->totalNoise_fx > 0 ) ) + IF ( (GT_16(hNoiseEst->low_tn_track_cnt_fx, 300)) + && (GT_16(hNoiseEst->lt_haco_ev_fx, 29491 ) ) /*.9 in Q15 */ + && (hNoiseEst->totalNoise_fx > 0 ) ) { updt_step = -655; move16(); /* for debug purposes */ FOR( i=0; i< NB_BANDS; i++ ) { - IF( GT_32(st_fx->bckr_fx[i], L_shl(Le_min_scaled, 1L) )) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */ + IF( GT_32(hNoiseEst->bckr_fx[i], L_shl(Le_min_scaled, 1L) )) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */ { /* st->bckr[i] = 0.98f*st->bckr[i]; */ - st_fx->bckr_fx[i] = Mult_32_16(st_fx->bckr_fx[i], 32113); /* .98 in Q15 */ + hNoiseEst->bckr_fx[i] = Mult_32_16(hNoiseEst->bckr_fx[i], 32113); /* .98 in Q15 */ move32(); /* move to array */ } } @@ -1705,15 +1820,25 @@ void noise_est_fx( /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */ tmp=0; move16(); - if( st_fx->aEn_fx == 0 ) + if(hNoiseEst->aEn_fx == 0 ) { tmp=32767; move16(); } - st_fx->lt_aEn_zero_fx = noise_est_AR1_Qx(tmp, st_fx->lt_aEn_zero_fx, 6554); /* alpha=0.2 , Q15 */ + hNoiseEst->lt_aEn_zero_fx = noise_est_AR1_Qx(tmp, hNoiseEst->lt_aEn_zero_fx, 6554); /* alpha=0.2 , Q15 */ } +#ifdef IVAS_CODE + IF (GT_16(st_fx->element_mode, EVS_MONO)) + { + test(); + if (hNoiseEst->first_noise_updt_cnt_fx > 0 && LT_16(hNoiseEst->first_noise_updt_cnt_fx, 100)) + { + hNoiseEst->first_noise_updt_cnt_fx = add(hNoiseEst->first_noise_updt_cnt_fx, 1); + } + } +#endif return; } diff --git a/lib_enc/noise_adjust_fx.c b/lib_enc/noise_adjust_fx.c index 74b6d52..ca8b91f 100644 --- a/lib_enc/noise_adjust_fx.c +++ b/lib_enc/noise_adjust_fx.c @@ -1,13 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ - #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------* * noise_adjust_fx() diff --git a/lib_enc/normalizecoefs_fx.c b/lib_enc/normalizecoefs_fx.c index 5b2eec9..cba8572 100644 --- a/lib_enc/normalizecoefs_fx.c +++ b/lib_enc/normalizecoefs_fx.c @@ -1,9 +1,8 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ -#include "stl.h" #include "basop_mpy.h" #include "prot_fx.h" #include "cnst_fx.h" /* Common constants */ @@ -16,12 +15,12 @@ *--------------------------------------------------------------------------*/ void normalizecoefs_fx( - Word32 *coefs, /* i : Input vector (Q12) */ - const Word16 *ynrm, /* i : quantization indices for norms */ - const Word16 num_bands, /* i : Number of bands */ - const Word16 *band_start, /* i : Start of bands */ - const Word16 *band_end, /* i : End of bands */ - Word16 *coefs_norm /* o : Normalized output vector */ + Word32 *coefs, /* i : Input vector (Q12) */ + const Word16 *ynrm, /* i : quantization indices for norms */ + const Word16 num_bands, /* i : Number of bands */ + const Word16 *band_start, /* i : Start of bands */ + const Word16 *band_end, /* i : End of bands */ + Word16 *coefs_norm /* o : Normalized output vector */ ) { Word16 band, j, k, r, v; diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 9c634d6..045d99e 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -2,21 +2,21 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" #include "rom_enc_fx.h" #include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ /*-------------------------------------------------------------------------- - * Local functions + * Local function prototypes *--------------------------------------------------------------------------*/ -static void quant_peaks_fx(Encoder_State_fx *, const Word32*, Word32*, const Word32*, +static void quant_peaks_fx(BSTR_ENC_HANDLE hBstr, const Word32*, Word32*, const Word32*, Word16*, const Word16, const Word32, const Word16); -static Word16 hvq_code_pos_fx(Encoder_State_fx *st_fx, const Word16 *inp, const Word16 length, const Word16 num_peaks); +static Word16 hvq_code_pos_fx(BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks); static Word16 sparse_code_pos_fx(const Word16 *inp, const Word16 length, Word16 *result); /*-------------------------------------------------------------------------- @@ -26,22 +26,23 @@ static Word16 sparse_code_pos_fx(const Word16 *inp, const Word16 length, Word16 *--------------------------------------------------------------------------*/ Word16 peak_vq_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 *coefs, /* i : Input coefficient vector Q12 */ - Word32 *coefs_out, /* o : Quantized output vector Q12 */ - const Word32 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 *coefs, /* i : Input coefficient vector Q12 */ + Word32 *coefs_out, /* o : Quantized output vector Q12 */ + const Word32 core_brate, /* i : Core bitrate */ + const Word16 num_bits, /* i : Number of bits for HVQ */ + const Word16 vq_peaks, /* i : Number of identified peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *vq_peak_idx, /* i : Peak index vector */ + Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ ) { Word16 pos_bits; Word32 normq; - Word32 pgain_q[HVQ_MAX_PEAKS_32k]; - Word32 peak_gains[HVQ_MAX_PEAKS_32k]; + Word32 pgain_q[HVQ_MAX_PEAKS]; + Word32 peak_gains[HVQ_MAX_PEAKS]; Word16 coefs_pvq[HVQ_PVQ_BUF_LEN], *pCoefsPvq; /* Q12 */ Word32 pvq_vector[HVQ_PVQ_BUF_LEN], *pPvqVector; Word32 *pPvqVectorBandStart; @@ -79,6 +80,13 @@ Word16 peak_vq_enc_fx( Word16 hvq_band_width[MAX_PVQ_BANDS]; Word16 n_sel_bnds; UWord32 lsb; + + assert((core_brate > HQ_16k40 && core_brate <= HQ_48k) && "HVQ rate not supported"); + + PMT("max_peaks equation needs to be converted") + max_peaks = (Word16)((core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS) / HVQ_PEAKS_BPS_DELTA); + + bits = 0; move16(); nf_seed = RANDOM_INITSEED; @@ -90,25 +98,18 @@ Word16 peak_vq_enc_fx( set16_fx(pvq_vector_norm, 0, HVQ_PVQ_BUF_LEN ); set16_fx(npulses, 0, MAX_PVQ_BANDS ); + bin_th = HVQ_THRES_BIN_32k; + move16(); + bin_th2 = HVQ_THRES_BIN_32k/HVQ_NF_GROUPS; + move16(); /* Set bit-rate dependent variables */ - IF (EQ_32(brate, HQ_24k40)) + IF (LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { - max_peaks = HVQ_MAX_PEAKS_24k; - move16(); bin_th = HVQ_THRES_BIN_24k; move16(); bin_th2 = HVQ_THRES_BIN_24k/HVQ_NF_GROUPS; move16(); } - ELSE - { - max_peaks = HVQ_MAX_PEAKS_32k; - move16(); - bin_th = HVQ_THRES_BIN_32k; - move16(); - bin_th2 = HVQ_THRES_BIN_32k/HVQ_NF_GROUPS; - move16(); - } FOR (i = 0; i < bin_th; i++) { @@ -124,13 +125,13 @@ Word16 peak_vq_enc_fx( /* De-quantization */ acc = L_add(dicn_fx[indx], 0); /* Q14 */ nf_gains[i] = L_shr(acc, 1 + 2); /* nf_gains in Q12. dicn_fx is in Q14. Need extra shift +2. */ - push_indice_fx(st_fx, IND_HVQ_NF_GAIN , (int)indx, 5); + push_indice_fx( hBstr, IND_HVQ_NF_GAIN , (int)indx, 5); bits = add(bits, 5); } /* Signal number of peaks */ i = sub(max_peaks, vq_peaks); - push_indice_fx(st_fx, IND_NUM_PEAKS, (int)i, 5); + push_indice_fx( hBstr, IND_NUM_PEAKS, (int)i, 5); bits = add(bits, 5); /* Identify position of first peak and arrange peak gains by position */ @@ -237,8 +238,8 @@ Word16 peak_vq_enc_fx( move16(); } - push_indice_fx(st_fx, IND_FLAGN, (int)FlagN, 1); - push_indice_fx(st_fx, IND_PG_IDX, (int)pgain_difidx[0], GAIN0_BITS); + push_indice_fx( hBstr, IND_FLAGN, (int)FlagN, 1); + push_indice_fx( hBstr, IND_PG_IDX, (int)pgain_difidx[0], GAIN0_BITS); IF (FlagN) { @@ -252,7 +253,7 @@ Word16 peak_vq_enc_fx( r = pgain_huffsizn[j]; move16(); - push_indice_fx(st_fx, IND_PG_IDX, (int)m, r ); + push_indice_fx( hBstr, IND_PG_IDX, (int)m, r ); } } ELSE @@ -260,7 +261,7 @@ Word16 peak_vq_enc_fx( pPgainDifIdx = &pgain_difidx[1]; FOR (i = 0; i < vqPeaksMinus1; i++) { - push_indice_fx(st_fx, IND_PG_IDX, (int)(*pPgainDifIdx++), GAINI_BITS ); + push_indice_fx( hBstr, IND_PG_IDX, (int)(*pPgainDifIdx++), GAINI_BITS ); } } @@ -284,29 +285,27 @@ Word16 peak_vq_enc_fx( { num_overlap_bins = sub(5, sub(vq_peak_idx[i+1], vq_peak_idx[i])); indx = sub(vq_peak_idx[i], 2); - quant_peaks_fx(st_fx, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, brate, vq_peaks); - push_indice_fx(st_fx, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); + quant_peaks_fx(hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks); + push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); bits = add(bits, 9); } indx = sub(vq_peak_idx[i], 2); - quant_peaks_fx(st_fx, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, brate, vq_peaks); - push_indice_fx(st_fx, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); + quant_peaks_fx(hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks); + push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); bits = add(bits, 9); /* Quantize peak positions and sign with HVQ */ - pos_bits = hvq_code_pos_fx( st_fx, pos_vec, bin_th, vq_peaks ); + pos_bits = hvq_code_pos_fx( hBstr, pos_vec, bin_th, vq_peaks ); bits = add(bits, pos_bits); bit_budget = sub(num_bits, bits); /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx(bit_budget, brate, st_fx->bwidth_fx, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, - &n_sel_bnds); + pvq_bands = hvq_pvq_bitalloc_fx(bit_budget, core_brate, bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds); /* Get band limits for concatenated PVQ target */ - hvq_concat_bands_fx(pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, - hvq_band_width, hvq_band_end); + hvq_concat_bands_fx(pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, hvq_band_width, hvq_band_end); /* Quantize PVQ bands */ pCoefsOut = coefs_out; @@ -352,7 +351,7 @@ Word16 peak_vq_enc_fx( move16(); set16_fx( npulses, 0, MAX_PVQ_BANDS ); - pvq_encode_frame_fx(st_fx, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, + pvq_encode_frame_fx(hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, HQ_CORE ); FOR (i = 0; i < pvq_bands; i++) @@ -383,7 +382,7 @@ Word16 peak_vq_enc_fx( move16(); } - push_indice_fx(st_fx, IND_HVQ_PVQ_GAIN, pvq_norm[k], HVQ_PVQ_GAIN_BITS); + push_indice_fx( hBstr, IND_HVQ_PVQ_GAIN, pvq_norm[k], HVQ_PVQ_GAIN_BITS); pvq_bits = add(pvq_bits, HVQ_PVQ_GAIN_BITS); pvq_norm[k] = add(pvq_norm[k], 8); @@ -438,14 +437,14 @@ Word16 peak_vq_enc_fx( *--------------------------------------------------------------------------*/ static void quant_peaks_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 *vect_in, /* i : Target vector in Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32 *vect_in, /* i : Target vector in Q12 */ Word32 *vect_out, /* i/o: Quantized vector in Q12 */ - const Word32 *peak_gain, /* i : Peak gain vector in Q12 */ + const Word32 *peak_gain,/* i : Peak gain vector in Q12 */ Word16 *vq_idx, /* o : Codebook index */ - const Word16 overlap, /* i : Overlap indicator */ - const Word32 brate, /* i : Core bitrate */ - const Word16 Npeaks /* i : Number of peaks */ + const Word16 overlap, /* i : Overlap indicator */ + const Word32 core_brate,/* i : Core bitrate */ + const Word16 Npeaks /* i : Number of peaks */ ) { Word16 x[4]; /* Qx */ @@ -529,7 +528,7 @@ static void quant_peaks_fx( #error w_vquant_fx() is hard-wired to dim = 4 = (HVQ_VQ_DIM - 1). #endif cb_class = w_vquant_fx(x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0); - IF (brate == HQ_24k40) + IF (LT_32(core_brate, HQ_BWE_CROSSOVER_BRATE)) { indx = sub(HVQ_MAX_PEAKS_24k, Npeaks); search_overlap = hvq_cb_search_overlap24k[indx]; @@ -547,26 +546,26 @@ static void quant_peaks_fx( IF ( cb_class == 0 ) { *vq_idx = w_vquant_fx(x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 0, 1 ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, 0, 1 ); } ELSE IF( EQ_16(cb_class, 1)) { indx = sub(HVQ_CB_SIZE*2, shl(search_overlap,2)); *vq_idx = w_vquant_fx(x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 0); *vq_idx = add(*vq_idx, sub(HVQ_CB_SIZE/2, search_overlap)); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 0, 1 ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, 0, 1 ); } ELSE IF( EQ_16(cb_class, 2)) { indx = sub(HVQ_CB_SIZE*2, shl(search_overlap,2)); *vq_idx = w_vquant_fx(x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 1); *vq_idx = add(*vq_idx, sub(HVQ_CB_SIZE/2, search_overlap)); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 1, 1 ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, 1, 1 ); } ELSE { *vq_idx = w_vquant_fx(x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 1); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 1, 1 ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, 1, 1 ); } FOR (i = 0; i < 4; i++) @@ -670,17 +669,17 @@ static Word16 sparse_code_pos_fx( *--------------------------------------------------------------------------*/ static Word16 hvq_code_pos_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *inp, const Word16 length, const Word16 num_peaks ) { Word16 sparse_result[4*HVQ_THRES_BIN_32k/HVQ_CP_L1_LEN]; - Word16 delta[HVQ_MAX_PEAKS_32k]; - Word16 peak_idx[HVQ_MAX_PEAKS_32k]; + Word16 delta[HVQ_MAX_PEAKS]; + Word16 peak_idx[HVQ_MAX_PEAKS]; Word16 inp_abs[HVQ_THRES_BIN_32k]; - Word16 inp_sign[HVQ_MAX_PEAKS_32k]; + Word16 inp_sign[HVQ_MAX_PEAKS]; Word16 i, j; Word16 bits; @@ -742,23 +741,23 @@ static Word16 hvq_code_pos_fx( test(); IF (GT_16(delta_bits, sparse_bits)||delta_bits<0) { - push_indice_fx(st_fx, IND_POS_IDX, HVQ_CP_SPARSE, 1); + push_indice_fx( hBstr, IND_POS_IDX, HVQ_CP_SPARSE, 1); FOR (i = 0; i < sparse_bits; i++) { - push_indice_fx(st_fx, IND_POS_IDX, sparse_result[i], 1); + push_indice_fx( hBstr, IND_POS_IDX, sparse_result[i], 1); } bits = add(add(bits, sparse_bits), 1); } ELSE { - push_indice_fx(st_fx, IND_POS_IDX, HVQ_CP_DELTA, 1); + push_indice_fx( hBstr, IND_POS_IDX, HVQ_CP_DELTA, 1); FOR (i = 0; i < num_peaks; i++) { j = delta[i]; move16(); - push_indice_fx(st_fx, IND_POS_IDX, hvq_cp_huff_val[j], hvq_cp_huff_len[j]); + push_indice_fx( hBstr, IND_POS_IDX, hvq_cp_huff_val[j], hvq_cp_huff_len[j]); } bits = add(add(bits, delta_bits), 1); } @@ -773,7 +772,7 @@ static Word16 hvq_code_pos_fx( tmp = 0; move16(); } - push_indice_fx(st_fx, IND_POS_IDX, tmp, 1); + push_indice_fx( hBstr, IND_POS_IDX, tmp, 1); } bits = add(bits, num_peaks); diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index a4ac085..3fe63c0 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -1,14 +1,13 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" #include "rom_basop_util.h" #define inv_T0_res InvIntTable @@ -52,28 +51,56 @@ static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Wo /* _ None */ /*==============================================================================*/ -Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 *T_op, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn /* i : target vector */ +Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 pitch_bits[], /* i : pitch bits */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *exc, /* i/o: pointer to excitation signal frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 * pitch, /* i : open loop pitch estimates in current frame */ + Word16 *T0_min, /* i/o: lower limit for close-loop search */ + Word16 *T0_max, /* i/o: higher limit for close-loop search */ + Word16 *T0, /* i/o: close loop integer pitch */ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ + const Word16 *h1, /* i : weighted filter input response */ + const Word16 *xn, /* i : target vector */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ) { - Word16 pitch; + Word16 pitch_cl; Word16 pit_flag, delta, mult_Top, nBits; + Word16 L_sufr_sft; + + + Word16 T_op[2]; /* values for two half-frames */ + L_sufr_sft = 6; + move16(); + if (EQ_16(L_subfr, 2*L_SUBFR)) + { + L_sufr_sft = 7; + } + + /*----------------------------------------------------------------* + * convert pitch values to 16kHz domain + *----------------------------------------------------------------*/ + IF (EQ_16(L_frame, L_FRAME) || (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)) + { + Copy(pitch, T_op, 2); + } + ELSE /* L_frame == L_FRAME16k */ + { + /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); + T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ + T_op[0] = shr(add(round_fx(L_shl(L_mult(20480, pitch[0]), 2)), 1), 1); move16(); + T_op[1] = shr(add(round_fx(L_shl(L_mult(20480, pitch[1]), 2)), 1), 1); move16(); + } /*----------------------------------------------------------------* * Set pit_flag to 0 for every subframe with absolute pitch search @@ -149,24 +176,12 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe move16(); IF( NE_16(coder_type,AUDIO)) { - /* find the number of bits */ - IF( EQ_16(L_frame,L_FRAME)) - { - { - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } + nBits = pitch_bits[shr(i_subfr, L_sufr_sft)]; } IF( EQ_16(coder_type,AUDIO)) { /*-------------------------------------------------------* - * Pitch encoding in AUDIO mode + * Pitch encoding in AUDIO coder type * (both ACELP@12k8 and ACELP@16k cores) *-------------------------------------------------------*/ @@ -204,12 +219,12 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr ); - pit_Q_enc_fx( st_fx, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16(coder_type,VOICED)) { /*-------------------------------------------------------* - * Pitch encoding in VOICED mode (ACELP@12k8 core only) + * Pitch encoding in VOICED code type (ACELP@12k8 core only) *-------------------------------------------------------*/ delta = 4; @@ -240,12 +255,54 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe move16(); } - pit_Q_enc_fx( st_fx, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } +#ifdef ADD_LRTD + else if (tdm_Pitch_reuse_flag == 1 || nBits == 4) + { + /*-------------------------------------------------------* + * Pitch encoding with reusing primary channel information + *-------------------------------------------------------*/ + int16_t loc_T0, loc_frac; + + delta = 4; + + pit_flag = L_SUBFR; + + if (L_subfr == 2 * L_SUBFR) + { + loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]); + loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f); + } + else + { + loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR]; + loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f); + } + + /* pitch lag search limitation */ + limit_T0(L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max); + if (nBits > 0) + { + /* search and encode the closed loop pitch period */ + *T0 = pitch_fr4(&exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR); + if (delta == 8) + { + *T0_frac = 0; + } + pit_Q_enc(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max); + } + else + { + *T0 = loc_T0; + *T0_frac = loc_frac; + } } +#endif ELSE { /*-------------------------------------------------------* - * Pitch encoding in GENERIC mode + * Pitch encoding in GENERIC coder type * (both ACELP@12k8 and ACELP@16k cores) *-------------------------------------------------------*/ @@ -294,7 +351,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); } - pit_Q_enc_fx( st_fx, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx(hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE /* L_frame == L_FRAME16k */ { @@ -308,7 +365,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); } - pit16k_Q_enc_fx( st_fx, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit16k_Q_enc_fx(hBstr, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } } } @@ -396,7 +453,7 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); } - pit_Q_enc_fx( st_fx, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + pit_Q_enc_fx(hBstr, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } /*-------------------------------------------------------* @@ -404,9 +461,9 @@ Word16 pit_encode_fx( /* o : Fractional pitch for each subframe *-------------------------------------------------------*/ /*pitch = (float)(*T0) + (float)(*T0_frac)/4.0f;*/ /* save subframe pitch values */ - pitch = shl(add(shl(*T0,2),*T0_frac),4); /* save subframe pitch values Q6 */ + pitch_cl = shl(add(shl(*T0,2),*T0_frac),4); /* save subframe pitch values Q6 */ - return pitch; + return pitch_cl; } @@ -659,7 +716,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ { Word16 i; Word16 t_min, t_max; - Word16 max, t0, t1, fraction, step, temp; + Word16 max_val, t0, t1, fraction, step, temp; Word16 *corr; Word16 corr_v[15+2*L_INTERPOL1+1]; /* Total length = t0_max-t0_min+1+2*L_inter */ Word16 pit_min; @@ -717,19 +774,19 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ * Find integer pitch *-----------------------------------------------------------------*/ - max = corr[t0_min]; + max_val = corr[t0_min]; move16(); t0 = t0_min; move16(); FOR (i = add(t0_min, 1); i <= t0_max; i++) { - if (corr[i] >= max) + if (corr[i] >= max_val) { t0 = i; move16(); } - max = s_max(corr[i], max); + max_val = s_max(corr[i], max_val); } IF( EQ_16(t0_fr1,pit_min)) @@ -941,7 +998,7 @@ void norm_corr_fx( *-------------------------------------------------------------------*/ void pit_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 nBits, /* i : # of Q bits */ const Word16 delta, /* i : Half the CL searched interval */ @@ -950,7 +1007,7 @@ void pit_Q_enc_fx( const Word16 T0, /* i : integer pitch lag */ const Word16 T0_frac, /* i : pitch fraction */ Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ + Word16 *T0_max /* o : delta search max_val */ ) { Word16 pitch_index; @@ -1027,7 +1084,7 @@ void pit_Q_enc_fx( } { - push_indice_fx( st_fx, IND_PITCH, pitch_index, nBits ); + push_indice_fx(hBstr, IND_PITCH, pitch_index, nBits ); } return; @@ -1040,13 +1097,13 @@ void pit_Q_enc_fx( *-------------------------------------------------------------------*/ void pit16k_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 nBits, /* i : # of Q bits */ const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ const Word16 T0, /* i : integer pitch lag */ const Word16 T0_frac, /* i : pitch fraction */ Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ + Word16 *T0_max /* o : delta search max_val */ ) { Word16 pitch_index; @@ -1066,7 +1123,7 @@ void pit16k_Q_enc_fx( } } - push_indice_fx( st_fx, IND_PITCH, pitch_index, nBits ); + push_indice_fx(hBstr, IND_PITCH, pitch_index, nBits ); } ELSE IF( EQ_16(nBits,9)) /* absolute encoding with 9 bits */ { @@ -1096,14 +1153,14 @@ void pit16k_Q_enc_fx( } } - push_indice_fx( st_fx, IND_PITCH, pitch_index, 9 ); + push_indice_fx(hBstr, IND_PITCH, pitch_index, 9 ); } ELSE /* nBits == 6 */ /* relative encoding with 6 bits */ { /*pitch_index = (T0 - *T0_min) * 4 + T0_frac;*/ pitch_index = add(shl(sub(T0,*T0_min),2),T0_frac); - push_indice_fx( st_fx, IND_PITCH, pitch_index, nBits ); + push_indice_fx(hBstr, IND_PITCH, pitch_index, nBits ); } limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, T0, T0_frac, T0_min, T0_max ); diff --git a/lib_enc/pitch_ol.c b/lib_enc/pitch_ol.c index 633f5bb..e2b121b 100644 --- a/lib_enc/pitch_ol.c +++ b/lib_enc/pitch_ol.c @@ -2,13 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include -#include +#include +#include "options.h" #include "prot_fx.h" #include "cnst_fx.h" #include "basop_util.h" -#include "stl.h" #include "rom_com_fx.h" #include "rom_enc_fx.h" @@ -45,61 +43,17 @@ /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ -static void LP_Decim2_Copy( - const Word16 x[], - Word16 y[], - Word16 l, - Word16 mem[] -); +static void LP_Decim2_Copy(const Word16 x[], Word16 y[], Word16 l, Word16 mem[] ); -static void pitch_neighbour_fx( - Word16 sect0, - Word16 pitch_tmp[], - Word16 pitch[3][2*NSECT], - Word16 corr_tmp[], - Word16 corr[3][2*NSECT], - Word16 thres1[2*NHFR], - Word16 ind_tmp[2*NHFR] -); +static void pitch_neighbour_fx(Word16 sect0, Word16 pitch_tmp[],Word16 pitch[3][2*NSECT],Word16 corr_tmp[],Word16 corr[3][2*NSECT],Word16 thres1[2*NHFR],Word16 ind_tmp[2*NHFR]); -static void find_mult_fx( - Word16 *fac, - Word16 pitch0, - Word16 pitch1, - Word16 pit_max0, - Word16 *corr, - Word16 *old_pitch, - Word16 *old_corr, - Word16 delta, - Word16 step -); +static void find_mult_fx(Word16 *fac,Word16 pitch0,Word16 pitch1,Word16 pit_max0,Word16 *corr,Word16 *old_pitch,Word16 *old_corr,Word16 delta,Word16 step); -static Word16 pitch_coherence_fx( - Word16 pitch0, - Word16 pitch1, - Word16 fac_max, - Word16 diff_max -); - -static Word32 Dot_product12_OL( - Word16 *sum1, - const Word16 x[], - const Word16 y[], - const Word16 lg, - const Word16 lg2, - Word16 *exp, - Word16 *exp2 -); - -static Word32 Dot_product12_OL_back( - Word16 *sum1, - const Word16 x[], - const Word16 y[], - const Word16 lg, - const Word16 lg2, - Word16 *exp, - Word16 *exp2 -); +static Word16 pitch_coherence_fx(Word16 pitch0,Word16 pitch1,Word16 fac_max,Word16 diff_max); + +static Word32 Dot_product12_OL(Word16 *sum1,const Word16 x[],const Word16 y[],const Word16 lg,const Word16 lg2,Word16 *exp,Word16 *exp2); + +static Word32 Dot_product12_OL_back(Word16 *sum1,const Word16 x[],const Word16 y[],const Word16 lg,const Word16 lg2,Word16 *exp,Word16 *exp2); /*-----------------------------------------------------------------* @@ -192,12 +146,12 @@ void pitch_ol_fx( Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ - const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ + const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 last_class, /* i : frame classification of last frame */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 Opt_SC_VBR /* i : SC-VBR flag */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 last_class,/* i : frame classification of last frame */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 Opt_SC_VBR /* i : SC-VBR flag */ ) { Word16 ftmp, old_wsp2[(L_WSP-L_INTERPOL)/OPL_DECIM], *wsp2; @@ -1355,10 +1309,10 @@ static void LP_Decim2_Copy( *---------------------------------------------------------------------*/ static Word32 Dot_product12_OL( /* o : Q31: normalized result (1 < val <= -1) */ Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ Word16 *exp, /* o : exponent of result (0..+30) */ Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) @@ -1416,13 +1370,13 @@ static Word32 Dot_product12_OL( /* o : Q31: normalized result (1 < val <= -1) * * two different length dot products of x and y, computed backward *---------------------------------------------------------------------*/ static Word32 Dot_product12_OL_back(/* o : Q31: normalized result (1 < val <= -1) */ - Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ - Word16 *exp, /* o : exponent of result (0..+30) */ - Word16 *exp2 /* o : exponent of result 2 (0..+30) */ + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) { Word16 i, sft; diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index 007de95..4d57cd0 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -1,14 +1,13 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Encoder static table prototypes */ #include "rom_dec_fx.h" #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * Local constants @@ -25,13 +24,13 @@ * i.e. the value pitch_ol + delta is not a part of the interval *-------------------------------------------------------------------*/ void pitch_ol2_fx( - const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ - const Word16 pitch_ol, /* i : pitch to be improved */ - Word16 *pitch_fr_fx, /* o : adjusted 1/4 fractional pitch */ /*Q7*/ + const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ + const Word16 pitch_ol, /* i : pitch to be improved */ + Word16 *pitch_fr_fx, /* o : adjusted 1/4 fractional pitch */ /*Q7*/ Word16 *voicing_fr_fx, /* o : adjusted 1/4 fractional voicing */ /*Q15*/ - const Word16 pos, /* i : position in frame where to calculate the improv. */ - const Word16 *wsp_fx, /* i : weighted speech for current frame and look-ahead */ /*Q_new-1+shift*/ - const Word16 delta /* i : delta for pitch search (2 or 7) */ + const Word16 pos, /* i : position in frame where to calculate the improv. */ + const Word16 *wsp_fx, /* i : weighted speech for current frame and look-ahead */ /*Q_new-1+shift*/ + const Word16 delta /* i : delta for pitch search (2 or 7) */ ) { Word16 i, t, step, fraction, t0_min, t0_max, t_min, t_max; @@ -206,15 +205,15 @@ void pitch_ol2_fx( void StableHighPitchDetect_fx( Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ Word16 pitch[], /* i/o: OL pitch buffer */ - const Word16 voicing[], /* i : OL pitch gains */ - const Word16 wsp[], /* i : weighted speech */ - const Word16 localVAD, + const Word16 voicing[], /* i : OL pitch gains */ + const Word16 wsp[], /* i : weighted speech */ + const Word16 localVAD, /* i : local VAD flag */ Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains */ Word16 *voicing0_sm, /* i/o: smoothed high pitch gains */ Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy*/ Word16 *predecision_flag, /* i/o: predecision flag */ Word32 *diff_sm, /* i/o: smoothed pitch frequency difference */ - Word32 *energy_sm , /* i/o: smoothed energy around pitch frequency */ + Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency */ Word16 Q_new, Word16 EspecdB[] ) diff --git a/lib_enc/plc_enc_ext.c b/lib_enc/plc_enc_ext.c index 1d51f13..c8f77cb 100644 --- a/lib_enc/plc_enc_ext.c +++ b/lib_enc/plc_enc_ext.c @@ -3,9 +3,8 @@ ====================================================================================*/ -#include - -#include "stl.h" +#include +#include "options.h" #include "cnst_fx.h" #include "stat_enc_fx.h" #include "prot_fx.h" @@ -14,9 +13,14 @@ extern const Word16 lsf_init[16]; +/*-------------------------------------------------------------------* + * init_PLC_enc() + * + * + *-------------------------------------------------------------------*/ -void open_PLC_ENC_EVS( - HANDLE_PLC_ENC_EVS hPlcExt, +void init_PLC_enc( + PLC_ENC_EVS_HANDLE hPlcExt, Word32 sampleRate /* core coder SR */ ) { @@ -47,7 +51,7 @@ void open_PLC_ENC_EVS( set16_fx(hPlcExt->lsf_adaptive_mean_14Q1,0,M); hPlcExt->stab_fac_Q15 = 0; move16(); - IF( EQ_32(sampleRate,12800)) + IF( EQ_32(sampleRate, INT_FS_12k8)) { hPlcExt->T0_4th = L_SUBFR; move16(); @@ -80,53 +84,49 @@ void open_PLC_ENC_EVS( return; } - -/* - function to extract and write guided information -*/ -void gPLC_encInfo (HANDLE_PLC_ENC_EVS self, - Word32 modeBitrate, - Word16 modeBandwidth, - Word16 old_clas, - Word16 coder_type - ) +/*-------------------------------------------------------------------* + * gPLC_encInfo() + * + * Function to extract and write guided information + *-------------------------------------------------------------------*/ +void gPLC_encInfo ( + PLC_ENC_EVS_HANDLE hPlcExt, + const Word32 total_brate, + const Word16 bwidth, + const Word16 last_clas, + const Word16 coder_type +) { - IF (self) + IF (hPlcExt) { - self->calcOnlylsf = 1; + hPlcExt->calcOnlylsf = 1; move16(); test(); - test(); - test(); - test(); - test(); - IF ( ( EQ_16(modeBandwidth, WB)&&EQ_32(modeBitrate,24400))|| - ( EQ_16(modeBandwidth, SWB) && EQ_32(modeBitrate, 24400) ) || - ( EQ_16(modeBandwidth, FB) && EQ_32(modeBitrate, 24400) ) ) + IF ( ( GE_16(bwidth, WB) && EQ_32(total_brate, ACELP_24k40))) { - self->enableGplc = 1; + hPlcExt->enableGplc = 1; move16(); - self->nBits = 1; + hPlcExt->nBits = 1; move16(); test(); test(); test(); - IF ( (EQ_16(old_clas, VOICED_CLAS)||EQ_16(old_clas,ONSET))&& + IF ( (EQ_16(last_clas, VOICED_CLAS)||EQ_16(last_clas,ONSET))&& (EQ_16(coder_type, VOICED) || EQ_16(coder_type, GENERIC) ) ) { - self->nBits = NBITS_GACELP; + hPlcExt->nBits = NBITS_GACELP; move16(); - self->calcOnlylsf = 0; + hPlcExt->calcOnlylsf = 0; move16(); } } ELSE { - self->enableGplc = 0; + hPlcExt->enableGplc = 0; move16(); - self->nBits = NBITS_GACELP; + hPlcExt->nBits = NBITS_GACELP; move16(); } diff --git a/lib_enc/ppp_enc_fx.c b/lib_enc/ppp_enc_fx.c index 0c9fc74..6b02984 100644 --- a/lib_enc/ppp_enc_fx.c +++ b/lib_enc/ppp_enc_fx.c @@ -2,11 +2,28 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include +#include "options.h" #include "cnst_fx.h" #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ +#define ERB_CBSIZE1 64 +#define ERB_CBSIZE2 64 +#define P_CBSIZE 64 + +/*-------------------------------------------------------------------* + * Local functions + *--------------------------------------------------------------------*/ +static Word16 DTFS_quant_cw_fx(DTFS_STRUCTURE_FX* X_fx, Word16 pl, const Word16* curr_lpc_fx, Word16* POWER_IDX, + Word16* AMP_IDX, Word16* lastLgainE_fx, Word16* lastHgainE_fx, Word16* lasterbE_fx, Word16* sin_tab, Word16* cos_tab); +static Word16 DTFS_alignment_fine_new_fx(DTFS_STRUCTURE_FX X1_fx, DTFS_STRUCTURE_FX X2_fx, Word16* S_fx, Word16* C_fx); +static void erb_diff_fx(const Word16* prev_erb, Word16 pl, const Word16* curr_erb, Word16 l, const Word16* curr_lsp, Word16* index, Word16 num_erb); + + /*=======================================================================================*/ /* FUNCTION : ppp_quarter_encoder_fx() */ @@ -55,26 +72,26 @@ /* CALLED FROM : TX */ /*=======================================================================================*/ -Word16 ppp_quarter_encoder_fx( - DTFS_STRUCTURE_FX *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ - DTFS_STRUCTURE_FX *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ +ivas_error ppp_quarter_encoder_fx( + Word16* returnFlag, /* o : return value */ + DTFS_STRUCTURE_FX *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ + DTFS_STRUCTURE_FX *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ Word16 prevCW_lag, /* i : previous lag */ - DTFS_STRUCTURE_FX vCURRCW_NQ_FX, /* i : Unquantized DTFS */ - const Word16 *curr_lpc_fx, /* i : LPCS */ + DTFS_STRUCTURE_FX vCURRCW_NQ_FX, /* i : Unquantized DTFS */ + const Word16 *curr_lpc_fx, /* i : LPCS */ Word16 *lastLgainE_fx, /* i/o: last low band gain */ Word16 *lastHgainE_fx, /* i/o: last high band gain */ Word16 *lasterbE_fx, /* i/o: last ERB vector */ - DTFS_STRUCTURE_FX PREV_CW_E_FX, /* i : past DTFS */ + DTFS_STRUCTURE_FX PREV_CW_E_FX, /* i : past DTFS */ Word16 *S_fx, /* i : sin table, Q15 */ Word16 *C_fx, /* i : cos table, Q15 */ - Encoder_State_fx *st_fx + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) { - DTFS_STRUCTURE_FX *PREVDTFS_FX = DTFS_new_fx(); + DTFS_STRUCTURE_FX *PREVDTFS_FX; Word16 tmp_fx, temp_pl_fx, temp_l_fx; Word16 temp; Word16 l; - Word16 returnFlag = 1; Word16 POWER_IDX_FX; /* Codebook index for the power quantization for PPP */ Word16 AMP_IDX_fx[2]; /* Codebook index for the Amplitude quantization for PPP */ Word16 Erot_fx = 0; @@ -82,6 +99,15 @@ Word16 ppp_quarter_encoder_fx( Word32 Ltempd,Ltempn; Word32 L_tmp, L_tmp1; Word16 tmp, exp; + ivas_error error; + + error = IVAS_ERR_OK; + *returnFlag = 1; + move16();move16(); + IF((error = DTFS_new_fx(&PREVDTFS_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } DTFS_copy_fx( CURRCW_Q_FX, vCURRCW_NQ_FX ); DTFS_copy_fx( PREVDTFS_FX, PREV_CW_E_FX ); @@ -129,7 +155,7 @@ Word16 ppp_quarter_encoder_fx( Ltempn = L_mult(CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx,10486);/* Q0+Q27 = Q28 */ CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16)L_shr(Ltempn,13);/*Q15 */ - returnFlag = DTFS_quant_cw_fx(CURRCW_Q_FX,prevCW_lag,curr_lpc_fx,&POWER_IDX_FX, + *returnFlag = DTFS_quant_cw_fx(CURRCW_Q_FX,prevCW_lag,curr_lpc_fx,&POWER_IDX_FX, AMP_IDX_fx,lastLgainE_fx,lastHgainE_fx,lasterbE_fx,S_fx,C_fx); move16(); @@ -140,9 +166,9 @@ Word16 ppp_quarter_encoder_fx( Ltempn = L_shl((Word32)CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx,13);/*Q28 */ CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16)find_remd(Ltempn, 20971,&Ltempd); - push_indice_fx( st_fx, IND_AMP0, AMP_IDX_fx[0], 6 ); - push_indice_fx( st_fx, IND_AMP1, AMP_IDX_fx[1], 6 ); - push_indice_fx( st_fx, IND_POWER, POWER_IDX_FX, 6); + push_indice_fx(hBstr, IND_AMP0, AMP_IDX_fx[0], 6 ); + push_indice_fx( hBstr, IND_AMP1, AMP_IDX_fx[1], 6 ); + push_indice_fx( hBstr, IND_POWER, POWER_IDX_FX, 6); /*Phase copying is done through copy_phase instead of car2pol and pol2car */ copy_phase_fx(TARGETCW_FX,*CURRCW_Q_FX,TARGETCW_FX); @@ -162,17 +188,17 @@ Word16 ppp_quarter_encoder_fx( { tmp_fx = 0; move16(); - returnFlag = 0; + *returnFlag = 0; move16(); } /*DTFS_phaseShift( CURRCW_Q,(float)(PI2*tmp/CURRCW_Q->lag) ); */ Q2phaseShift_fx(CURRCW_Q_FX,tmp_fx,CURRCW_Q_FX->lag_fx,S_fx,C_fx); - push_indice_fx( st_fx, IND_GLOBAL_ALIGNMENT, shr(add(tmp_fx,12),2), 3 ); + push_indice_fx( hBstr, IND_GLOBAL_ALIGNMENT, shr(add(tmp_fx,12),2), 3 ); - free(PREVDTFS_FX); - return returnFlag; + count_free(PREVDTFS_FX); + return error; } /*-------------------------------------------------------------------* @@ -183,38 +209,35 @@ Word16 ppp_quarter_encoder_fx( *-------------------------------------------------------------------*/ void set_ppp_mode_fx( Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *coder_type /* i : coding type */ - ,const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ + const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ - const Word16 localVAD, - const Word16 localVAD_he, /* i : HE-SAD flag without hangover */ - Word16 *vad_flag - ,Word16 T_op_fx[] /* i : open loop pitch lag */ - ,Word16 sp_aud_decision1 /* i : Speech Audio Decision */ + const Word16 localVAD_he /* i : HE-SAD flag without hangover */ ) { + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + test(); test(); test(); test(); test(); - IF ( EQ_16( *vad_flag, 1)&& + IF ( EQ_16( st_fx->vad_flag, 1)&& ( EQ_16( noisy_speech_HO , 1 ) || EQ_16( clean_speech_HO, 1 ) || EQ_16( NB_speech_HO, 1) ) && - ( localVAD == 0 || localVAD_he == 0 ) ) + ( st_fx->localVAD == 0 || localVAD_he == 0 ) ) { - *coder_type = UNVOICED; + st_fx->coder_type = UNVOICED; move16(); } test(); test(); - IF ( EQ_16( *coder_type , INACTIVE )&&(*vad_flag==0)&&EQ_16(st_fx->last_nelp_mode_fx,1)) /* avoid HO frame go to GSC */ + IF ( EQ_16( st_fx->coder_type , INACTIVE ) && (st_fx->vad_flag==0) && EQ_16(hSC_VBR->last_nelp_mode_fx,1)) /* avoid HO frame go to GSC */ { - *coder_type = UNVOICED; + st_fx->coder_type = UNVOICED; move16(); } @@ -223,48 +246,48 @@ void set_ppp_mode_fx( /* this will indicate the decoder that the coder is operating in the VBR mode */ IF ( LT_16( st_fx->ini_frame_fx, 5)) { - *coder_type = UNVOICED; + st_fx->coder_type = UNVOICED; move16(); - *vad_flag = 1; + st_fx->vad_flag = 1; move16(); } /* Pattern PPP-CELP-CELP (pppcountE holds number of consecutive PPP frames) */ test(); - IF ( NE_16( *coder_type, VOICED )||EQ_16(st_fx->last_coder_type_fx,TRANSITION)) + IF ( NE_16( st_fx->coder_type, VOICED )||EQ_16(st_fx->last_coder_type_fx,TRANSITION)) { /* ensure no transient to PPP transition */ - st_fx->pppcountE_fx = 0; + hSC_VBR->pppcountE_fx = 0; move16(); } ELSE { /* current mode is voiced */ - st_fx->pppcountE_fx = add( st_fx->pppcountE_fx, 1); + hSC_VBR->pppcountE_fx = add( hSC_VBR->pppcountE_fx, 1); test(); test(); test(); test(); - IF ( ( EQ_16( st_fx->pppcountE_fx, 1 )&&NE_16(st_fx->last_last_ppp_mode_fx,1)&&st_fx->rate_control_fx==0)|| - ( EQ_16( st_fx->pppcountE_fx, 1 ) && st_fx->mode_QQF_fx != 0) ) + IF ( ( EQ_16( hSC_VBR->pppcountE_fx, 1 )&&NE_16(hSC_VBR->last_last_ppp_mode_fx,1)&& hSC_VBR->rate_control_fx==0)|| + ( EQ_16( hSC_VBR->pppcountE_fx, 1 ) && hSC_VBR->mode_QQF_fx != 0) ) { - st_fx->ppp_mode_fx = 1; + hSC_VBR->ppp_mode_fx = 1; move16(); st_fx->core_brate_fx = PPP_NELP_2k80; move32(); } - ELSE IF ( EQ_16(st_fx->pppcountE_fx, 2 )) + ELSE IF ( EQ_16(hSC_VBR->pppcountE_fx, 2 )) { test(); - IF ( st_fx->last_ppp_mode_fx != 0 && st_fx->mode_QQF_fx == 0 ) + IF (hSC_VBR->last_ppp_mode_fx != 0 && hSC_VBR->mode_QQF_fx == 0 ) { /* QFF mode */ - st_fx->ppp_mode_fx = 0; + hSC_VBR->ppp_mode_fx = 0; move16(); } ELSE { /* QQF Mode */ - st_fx->ppp_mode_fx = 1; + hSC_VBR->ppp_mode_fx = 1; move16(); st_fx->core_brate_fx = PPP_NELP_2k80; move32(); @@ -272,30 +295,30 @@ void set_ppp_mode_fx( } ELSE { - st_fx->ppp_mode_fx = 0; + hSC_VBR->ppp_mode_fx = 0; move16(); - st_fx->pppcountE_fx = 0; + hSC_VBR->pppcountE_fx = 0; move16(); } } test(); - IF ( st_fx->ppp_mode_fx == 0 && EQ_16( st_fx->set_ppp_generic_fx, 1)) + IF (hSC_VBR->ppp_mode_fx == 0 && EQ_16(hSC_VBR->set_ppp_generic_fx, 1)) { - st_fx->set_ppp_generic_fx = 0; + hSC_VBR->set_ppp_generic_fx = 0; move16(); - *coder_type = GENERIC; + st_fx->coder_type = GENERIC; move16(); } IF ( st_fx->last_core_fx == HQ_CORE ) { - st_fx->ppp_mode_fx = 0; + hSC_VBR->ppp_mode_fx = 0; move16(); - st_fx->set_ppp_generic_fx = 0; + hSC_VBR->set_ppp_generic_fx = 0; move16(); - *coder_type = TRANSITION; + st_fx->coder_type = TRANSITION; move16(); } @@ -303,23 +326,23 @@ void set_ppp_mode_fx( test(); test(); test(); - IF ( (st_fx->last_ppp_mode_fx != 0 ) && ( st_fx->ppp_mode_fx == 0 ) && ( sp_aud_decision1 != 0) + IF ( (hSC_VBR->last_ppp_mode_fx != 0 ) && (hSC_VBR->ppp_mode_fx == 0 ) && ( st_fx->sp_aud_decision1 != 0) && EQ_16(st_fx->bwidth_fx, NB)&&st_fx->Opt_SC_VBR_fx!=0) /*if it were about to go from ppp->HQ*/ { - st_fx->avoid_HQ_VBR_NB = 1; + hSC_VBR->avoid_HQ_VBR_NB = 1; move16(); - *coder_type = GENERIC; + st_fx->coder_type = GENERIC; move16(); } test(); test(); test(); - IF ( (st_fx->last_nelp_mode_fx != 0) && ( sp_aud_decision1 != 0) && EQ_16( st_fx->bwidth_fx, NB)&&(st_fx->Opt_SC_VBR_fx!=0)) /*if it were about to go from nelp->HQ*/ + IF ( (hSC_VBR->last_nelp_mode_fx != 0) && ( st_fx->sp_aud_decision1 != 0) && EQ_16( st_fx->bwidth_fx, NB)&&(st_fx->Opt_SC_VBR_fx!=0)) /*if it were about to go from nelp->HQ*/ { - st_fx->avoid_HQ_VBR_NB = 1; + hSC_VBR->avoid_HQ_VBR_NB = 1; move16(); - *coder_type = GENERIC; + st_fx->coder_type = GENERIC; move16(); } @@ -328,10 +351,10 @@ void set_ppp_mode_fx( test(); test(); IF( ( GT_16(st_fx->old_pitch_buf_fx[(2*NB_SUBFR)-1], PPP_LAG_THRLD_Q6)|| - GT_16(T_op_fx[1], PPP_LAG_THRLD) || !st_fx->last_Opt_SC_VBR_fx ) && - EQ_16(st_fx->ppp_mode_fx,1) ) + GT_16(st_fx->pitch_fx[1], PPP_LAG_THRLD) || !st_fx->last_Opt_SC_VBR_fx ) && + EQ_16(hSC_VBR->ppp_mode_fx,1) ) { - st_fx->ppp_mode_fx=0; + hSC_VBR->ppp_mode_fx=0; move16(); st_fx->core_brate_fx = ACELP_7k20; move32(); @@ -340,3 +363,618 @@ void set_ppp_mode_fx( return; } + +/*===================================================================*/ +/* FUNCTION : Word16 DTFS_quant_cw_fx () */ +/*-------------------------------------------------------------------*/ +/* PURPOSE : Quantize QPPP prototype */ +/*-------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16) pl: previous lag */ +/* _ (Word16 []) curr_lpc_fx: LPC coefficients, Q12 */ +/* _ (Word16 []) sin_tab: sine table based on lag, Q15 */ +/* _ (Word16 []) cos_tab: cosine table based on lag, Q15 */ +/*-------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) POWER_IDX: Power index */ +/* _ (Word16[]) AMP_IDX: Amplitude indices */ +/*-------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (struct DTFS_fx) X_fx : prototype in polar domain */ +/* (Word16) lag_fx: length of prototype in time domain*/ +/* (Word16 []) a: amplitude of harmonics, normalized */ +/* (Word16) Q: norm factor of a */ +/* _ (Word16[]) lasterb_fx: ERB history for differential */ +/* quantization, Q13 */ +/* _ (Word16) Lgain_fx: low band power history, log domain, Q11 */ +/* _ (Word16) Hgain_fx: high band power history, log domain, Q11 */ +/*-------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ (Word16) flag: flag indicating success/failure (TRUE/FALSE) */ +/*-------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*===================================================================*/ +/* NOTE: Frequencies is normalized by 12800, i.e. 1=12800Hz */ +/*===================================================================*/ +static Word16 DTFS_quant_cw_fx( + DTFS_STRUCTURE_FX* X_fx, /* i/o: DTFS unquant inp, quant out */ + Word16 pl, /* i : Previous lag */ + const Word16* curr_lpc_fx, /* i : LPC */ + Word16* POWER_IDX, /* o : Power index */ + Word16* AMP_IDX, /* o : Amplitude index */ + Word16* lastLgainE_fx, /* i/o: last frame lowband gain */ + Word16* lastHgainE_fx, /* i/o: last frame highband gain */ + Word16* lasterbE_fx, /* i/o: last frame ERB vector */ + Word16* sin_tab, + Word16* cos_tab +) + +{ + Word16 num_erb = 0; + const Word16* PowerCB_fx = NULL; + Word16 tmp, w[2], target[2], j, slot[NUM_ERB_WB], flag; + Word16 n, d1, d2, exp; + Word32 minerror, Ltemp, logLag_fx, L_tmp; + Word16 erb_uq[NUM_ERB_WB], Qh, Ql; + /* Word40 Lacc_40; */ + Word32 Lacc; + Word16 mfreq[NUM_ERB_WB]; + Word16 Q; + + Word16 curr_erb_fx[NUM_ERB_WB]; + + + /* upper_cute_off_freq are normalized to 12800 */ + + IF(EQ_16(X_fx->upper_cut_off_freq_fx, 0x2800))/* 4000 hz normalized to 12800 in Q15 */ + { + num_erb = NUM_ERB_NB; + move16(); + PowerCB_fx = PowerCB_NB_fx; + move16(); + } + ELSE IF(EQ_16(X_fx->upper_cut_off_freq_fx, 0x4000))/* 6400 hz normalized to 12800 in Q15 */ + { + num_erb = NUM_ERB_WB; + move16(); + PowerCB_fx = PowerCB_WB_fx; + move16(); + } + + /* Get weighting and target */ + quant_target_fx(X_fx, curr_lpc_fx, w, target, sin_tab, cos_tab); + + /* Power Quantization in log domain */ + target[0] = sub(target[0], *lastLgainE_fx); + move16(); + target[1] = sub(target[1], *lastHgainE_fx); + move16(); + + minerror = L_add(EVS_LW_MAX, 0); + *POWER_IDX = 0; + move16(); + + j = 0; + move16(); + FOR(n = 0; n < P_CBSIZE * 2; n += 2) + { + /* n=shl(j,1); n=offset to current codebook entry */ + d1 = sub(target[0], PowerCB_fx[n]); + d2 = sub(target[1], PowerCB_fx[n + 1]); + Ltemp = L_mult(w[0], abs_s(d1)); + Ltemp = L_mac(Ltemp, w[1], abs_s(d2)); /* Ltemp=error */ + + test(); + IF(d1 >= 0 && d2 >= 0) + { + Ltemp = Mult_32_16(Ltemp, 0x6666); /* *=0.8 */ + } + IF(LT_32(Ltemp, minerror)) + { + minerror = L_add(Ltemp, 0); + *POWER_IDX = j; + move16(); + } + j = add(j, 1); + } + DTFS_to_erb_fx(*X_fx, curr_erb_fx); + + FOR(j = 0; j < num_erb; j++) + { + erb_uq[j] = curr_erb_fx[j]; + move16(); + } + erb_slot_fx(X_fx->lag_fx, slot, mfreq, num_erb); + /* Amplitude Quantization */ + + + erb_diff_fx(lasterbE_fx, pl, curr_erb_fx, X_fx->lag_fx, curr_lpc_fx, AMP_IDX, num_erb); + + + /* Dequantization of prototype */ + /* PORTING: Removing the references */ + /* DTFS_dequant_cw_fx(pl, *POWER_IDX, AMP_IDX,lastLgainE_fx,lastHgainE_fx, lasterbE_fx,X_fx,num_erb,curr_erb_fx); */ + + /* Determine IF the amplitude quantization is good enough */ + erb_add_fx(curr_erb_fx, X_fx->lag_fx, lasterbE_fx, pl, AMP_IDX, num_erb); + + curr_erb_fx[0] = mult_r(curr_erb_fx[1], 9830); + move16(); /* 0.3 inQ15 leaves curr_erb in Q13 */ + curr_erb_fx[sub(num_erb, 2)] = mult_r(curr_erb_fx[sub(num_erb, 3)], 9830);/* Q13 */ + + curr_erb_fx[sub(num_erb, 1)] = 0; + move16(); + flag = 1; + move16(); + + Ltemp = L_deposit_l(0); + n = 0; + move16(); + FOR(j = 1; j < 10; j++) + { + IF(slot[j] != 0) + { + Ltemp = L_add(Ltemp, abs_s(sub(erb_uq[j], curr_erb_fx[j]))); /* Q13 */ + n = add(n, 1); /* n++ */ + } + } + + exp = norm_s(n); + tmp = div_s(shl(1, sub(14, exp)), n);/* 29 - exp */ + Lacc = L_shl(Mult_32_16(Ltemp, tmp), exp + 4); + + tmp = round_fx(Lacc); /* tmp in Q15 */ + + test(); + if (GT_16(tmp, 0x3C29) && GT_16(target[0], -819)) + { + flag = 0; /* Bumping up */ move16(); + } + + /* mfreq normalized (2.56) in Q15 */ + DTFS_erb_inv_fx(curr_erb_fx, slot, mfreq, X_fx, num_erb); + + + /* Back up the lasterbD memory after power normalization */ + DTFS_setEngyHarm_fx(236, 2828, 0, 2828, 1, 0, &Ql, X_fx); + DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx); + + /* Need to unify the Q factors of both bands */ + X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ + n = sub(Ql, Qh); /* compare band Q factors */ + + + /* This logic adjusts difference between Q formats of both bands */ + + IF(n < 0) + rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); + ELSE IF(n > 0) + rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); + + tmp = shl(*POWER_IDX, 1); /* tmp=2*POWER_IDX */ + *lastLgainE_fx = add(*lastLgainE_fx, PowerCB_fx[tmp]); /* Q11 */ + *lastHgainE_fx = add(*lastHgainE_fx, PowerCB_fx[tmp + 1]); /* Q11 */ + + Ltemp = log10_fx(X_fx->lag_fx); /* Ltemp=10*log10(lag), Q23 */ + logLag_fx = Mult_32_16(Ltemp, 0x6666); /* logLag=log10(lag), Q26 */ + + Ltemp = L_sub(L_shr(L_deposit_h(*lastLgainE_fx), 1), logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ + + L_tmp = pow_10(Ltemp, &Q); /* Lacc=10^Lgain/lag, Q15 */ + n = norm_l(L_tmp); + Ltemp = (Word32)L_shl(L_tmp, n); /* Ltemp in Q(15+n) */ + + + DTFS_setEngyHarm_fx(236, 2828, 0, 2828, Ltemp, add(Q, n), &Ql, X_fx); + + Ltemp = L_sub(L_shr(L_deposit_h(*lastHgainE_fx), 1), logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ + + /* Ltemp = L_shr(Ltemp,1); */ + L_tmp = pow_10(Ltemp, &Q); /* Lacc=10^Lgain/lag, Q15 */ + n = norm_l(L_tmp); + Ltemp = (Word32)L_shl(L_tmp, n); /* Ltemp in Q(15+n) */ + + DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, Ltemp, add(Q, n), &Qh, X_fx); + /* Need to unify the Q factors of both bands */ + X_fx->Q = s_min(Ql, Qh); /* set Q factor to be the smaller one */ + n = sub(Ql, Qh); /* compare band Q factors */ + + IF(n < 0) + { + rshiftHarmBand_fx(X_fx, 2828, X_fx->upper_cut_off_freq_fx, n); + } + ELSE IF(n > 0) + { + rshiftHarmBand_fx(X_fx, 0, 2828, sub(Qh, Ql)); + } + return flag; +} +/*===================================================================*/ +/* FUNCTION : DTFS_alignment_fine_new_fx () */ +/*-------------------------------------------------------------------*/ +/* PURPOSE : search for alignment */ +/*-------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (struct DTFS_fx) X1_fx : a/b in X1_fx.Q */ +/* _ (struct DTFS_fx) X2_fx : a/b in X2_fx.Q */ +/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ +/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ +/*-------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) fshift_fx : Q2 */ +/*-------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ +/*-------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : _ None. */ +/*-------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*===================================================================*/ + +static Word16 DTFS_alignment_fine_new_fx(DTFS_STRUCTURE_FX X1_fx, DTFS_STRUCTURE_FX X2_fx, Word16* S_fx, Word16* C_fx) +{ + Word16 temp, temp1, k, Qcorr, Qmaxcorr; + Word16 n, fshift_fx, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI]; + Word32 corr_fx; + Word32 maxcorr_fx, wcorr_fx, diff_corr; + + IF(LT_16(X1_fx.lag_fx, X2_fx.lag_fx)) + { + DTFS_zeroPadd_fx(X2_fx.lag_fx, &X1_fx); + } + + maxcorr_fx = L_add(MIN_32, 0); + Qmaxcorr = 0; + move16(); + HalfLag = s_min(shr(X2_fx.lag_fx, 1), X2_fx.nH_fx); + + FOR(k = 0; k <= HalfLag; k++) + { + ab1[k] = round_fx(L_mac(L_mult(X1_fx.a_fx[k], X2_fx.a_fx[k]), X1_fx.b_fx[k], X2_fx.b_fx[k])); + ab2[k] = round_fx(L_msu(L_mult(X1_fx.b_fx[k], X2_fx.a_fx[k]), X1_fx.a_fx[k], X2_fx.b_fx[k])); + } + + + fshift_fx = 0; + move16(); + FOR(n = -76; n <= 80; n += 4) + { + /* n is Q2 */ + corr_fx = L_deposit_l(0); + temp = 0; + move16(); + temp1 = n; + move16(); + + IF(n < 0) + { + temp1 = add(temp1, shl(X2_fx.lag_fx, 2)); /* avoid negative */ + } + + FOR(k = 0; k <= HalfLag; k++) + { + corr_fx = L_mac(corr_fx, ab1[k], C_fx[temp % (4 * X2_fx.lag_fx)]); + corr_fx = L_mac(corr_fx, ab2[k], S_fx[temp % (4 * X2_fx.lag_fx)]); + temp = add(temp, temp1); + } + temp = sub(32767, extract_l(L_shr(L_mult(82, abs_s(n)), 1))); /* Q15 */ + Qcorr = norm_l(corr_fx); + if (corr_fx == 0) + { + Qcorr = 31; + move16(); + } + + temp1 = round_fx((Word32)L_shl(corr_fx, Qcorr)); /* Q(Qcorr-16) */ + wcorr_fx = L_mult(temp1, temp); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ + + IF(GE_16(Qmaxcorr, Qcorr)) + { + diff_corr = L_sub(wcorr_fx, L_shl(maxcorr_fx, sub(Qcorr, Qmaxcorr))); /* Qcorr */ + } + ELSE + { + diff_corr = L_sub(L_shl(wcorr_fx, sub(Qmaxcorr, Qcorr)), maxcorr_fx); /* Qmaxcorr */ + } + + if (diff_corr > 0) + { + fshift_fx = n; + move16(); + maxcorr_fx = (Word32)L_shl(corr_fx, Qcorr); /* Qcorr */ + Qmaxcorr = Qcorr; + move16(); + } + } + + return fshift_fx; +} +/*===================================================================*/ +/* FUNCTION : LPCPowSpect_fx () */ +/*-------------------------------------------------------------------*/ +/* PURPOSE : Compute LPC power spectrum */ +/*-------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16 []) freq : ERB frequency bounds, Q15 */ +/* _ (Word16 []) LPC : LPC coefficients, Q12 */ +/* _ (Word16) Nf: number of ERB bins, Q0 */ +/* _ (Word16) Np : order of LPC, Q0 */ +/*-------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16 []) out : LPC power spectrum, Q7 */ +/*-------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ +/*-------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : _ None. */ +/*-------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*===================================================================*/ +/* NOTE: Frequency is normalized by 12800, i.e. 1=12800Hz */ +/*===================================================================*/ +static void LPCPowSpect_fx( + const Word16* freq, /* i : ERB frequencies */ + const Word16 Nf, /* i : Number of ERBs */ + const Word16* LPC, /* i : LPC coefficients */ + const Word16 Np, /* i : Number of LPCs */ + Word16* out /* o : LPC power spectrum */ +) +{ + Word16 i, k; + Word16 w; /* Q9 */ + Word16 t1, dt; + /*Word16 t2; */ + Word16 dh, dl; + Word32 Re, Im; /* Q27 */ + Word32 Ltemp, Lw; + Word32 Lacc; + Word16 tmp, exp; + + FOR(k = 0; k < Nf; k++) + { + + Re = L_add(0x8000000, 0); /* Re=1.0, Q27 */ + Im = L_deposit_l(0); + Lw = L_deposit_l(freq[k]);/* Q15 */ + FOR(i = 0; i < Np; i++) + { + Ltemp = L_shl(Lw, 10); /* Ltemp in Q25 */ + w = extract_h(Ltemp); /* w in Q9 */ + dl = extract_l(Ltemp); /* dl has 6 bits left-over */ + w = s_and(w, 511); + t1 = cos_table[w]; + /* t2=cos_table[s_and(add(w,1),511)]; */ + /*dt=sub(t2,t1); */ /* dt=t2-t1, Q15 */ + dt = cos_diff_table[w]; + + IF(dl < 0) + { + Ltemp = L_shl(L_add(65536, dl), 14);/* */ + Ltemp = Mult_32_16(Ltemp, dt); + Ltemp = L_shl(Ltemp, 1); + } + ELSE + { + Ltemp = (Word32)L_mult0(dt,dl); /* Ltemp in Q31 */ + } + + t1 = add(t1, (Word16)L_shr(Ltemp, 16)); /* t1 is interpolated cos(w) */ + Ltemp = L_shr(L_mult(LPC[i], t1), 1); /* Ltemp in Q27 */ + Re = L_add(Re, Ltemp); /* Re=1-sum(LPC[i]*cos(Lw)); */ + Ltemp = L_add(Lw, 0x6000); /* add 0.75, which is 3pi/2 to convert sin to cos */ + Ltemp = L_shl(Ltemp, 10); /* Q25 */ + w = extract_h(Ltemp); /* w is equivalent cos index */ + dl = extract_l(Ltemp); /* dl is 6 bit left-over for interpolation */ + w = s_and(w, 511); + t1 = cos_table[w]; + /*t2=cos_table[s_and(add(w,1),511)]; */ + /*dt=sub(t2,t1); */ /* dt=t2-t1, Q15 */ + dt = cos_diff_table[w]; + + IF(dl < 0) + { + Ltemp = L_shl(L_add(65536, dl), 14);/* */ + Ltemp = Mult_32_16(Ltemp, dt); + Ltemp = L_shl(Ltemp, 1); + } + ELSE + { + Ltemp = (Word32)L_mult0(dt,dl); /* Ltemp in Q31 */ + } + + t1 = add(t1, (Word16)L_shr(Ltemp, 16)); /* t1 is interpolated cos(w) */ + Ltemp = L_shr(L_mult(LPC[i], t1), 1); /* Ltemp in Q27 */ + Im = L_sub(Im, Ltemp); /* Im=sum(LPC[i]*sin(Lw)) */ + Lw = L_add(Lw, freq[k]); /* Lw=(i+1)*freq[k] */ + } + /* If necessary, we can block-normalize Re and Im to improve precision */ + dh = extract_h(Re); + dl = extract_l(Re); + + IF(dl < 0) + { + Ltemp = L_shl(L_add(65536, dl), 14);/* */ + Ltemp = Mult_32_16(Ltemp, dh); + Lacc = L_shl(Ltemp, 1); + } + ELSE + Lacc = L_mult0(dh, dl); + + Lacc = L_add(L_shr(Lacc, 15), L_shr(L_mult(dh, dh), 1)); /* Lacc=Re*Re */ + dh = extract_h(Im); + dl = extract_l(Im); + + IF(dl < 0) + { + Ltemp = L_shl(L_add(65536, dl), 14);/* */ + Ltemp = Mult_32_16(Ltemp, dh); + Ltemp = L_shl(Ltemp, 1); + } + ELSE + Ltemp = (Word32)L_mult0(dh, dl); + + Lacc = L_add(Lacc, L_shr(Ltemp, 15)); + Lacc = L_add(Lacc, L_shr(L_mult(dh, dh), 1)); /* Lacc=Re^2+Im^2, Q22 */ + + exp = norm_l(Lacc); + tmp = round_fx(L_shl(Lacc, exp)); + exp = sub(sub(30, exp), 22); + + /* tmp may potentially become negative, when Lacc is a very large value */ + IF(tmp > 0) + { + tmp = div_s(16384, tmp); /* 15+exp1 */ + } + ELSE + { + tmp = 0; + move16(); + } + Ltemp = L_deposit_h(tmp); + out[k] = round_fx(L_shl(Ltemp, negate(add(exp, 8)))); + + /* out[k] = shl(tmp,-exp-8); in Q7 */ + + } + return; +} + +/*===================================================================*/ +/* FUNCTION : erb_diff_fx () */ +/*-------------------------------------------------------------------*/ +/* PURPOSE : Quantize erb amplitude for QPPP */ +/*-------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16) pl : previous pitch lag, Q0 */ +/* _ (Word16) l : current pitch lag, Q0 */ +/* _ (Word16 []) prev_erb : Previous erb amplitude, Q13 */ +/* _ (Word16 []) curr_erb : Current erb amplitude, Q13 */ +/* _ (Word16 []) curr_lsp : LSP coefficients, Q12 */ +/* _ (Word16 []) num_erb : Number of ERBs , Q0 */ +/*-------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16 []) index: quantized differential erb index */ +/*-------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ +/*-------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : _ None. */ +/*-------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*===================================================================*/ +static void erb_diff_fx( + const Word16* prev_erb, /* i : previous ERB */ + Word16 pl, /* i : previous lag */ + const Word16* curr_erb, /* i : current ERB */ + Word16 l, /* i : current lag */ + const Word16* curr_lsp, /* i : current LSP coefficients */ + Word16* index, /* 0 : ERB index */ + Word16 num_erb /* i : Number of ERBs */ +) +{ + Word16 i; + Word16 pslot[NUM_ERB_WB], cslot[NUM_ERB_WB]; + Word16 tmp, t_prev_erb[NUM_ERB_WB], LPC[M + 1], mfreq[NUM_ERB_WB], PowSpect[NUM_ERB_WB], dif_erb[NUM_ERB_WB]; + const Word16* AmpCB1_fx = NULL; + + IF(EQ_16(num_erb, NUM_ERB_NB)) + { + AmpCB1_fx = AmpCB1_NB_fx; + move16(); + } + ELSE IF(EQ_16(num_erb, NUM_ERB_WB)) + { + AmpCB1_fx = AmpCB1_WB_fx; + move16(); + + } + erb_slot_fx(l, cslot, mfreq, num_erb);/* cslot in Qo and mfreq in Q15 */ + erb_slot_fx(pl, pslot, t_prev_erb, num_erb); + + FOR(i = 0; i < M + 1; i++) + { + LPC[i] = mult_r(curr_lsp[i], pwf78_fx[i]); + move16(); + } + + LPCPowSpect_fx(mfreq, num_erb, LPC, M + 1, PowSpect);/* Powspect in Q7 */ + + FOR(i = 0; i < num_erb; i++) + { + if (cslot[i] == 0) + { + PowSpect[i] = 0; + move16(); + } + } + FOR(i = 0; i < num_erb; i++) + { + t_prev_erb[i] = prev_erb[i]; + move16(); + } + IF(GT_16(pl, l)) + { + tmp = t_prev_erb[0]; + move16(); + FOR(i = 0; i < num_erb; i++) + { + IF(pslot[i] != 0) + { + tmp = t_prev_erb[i]; + move16(); + } + ELSE + { + t_prev_erb[i] = tmp; + move16(); + } + } + } + ELSE IF(GT_16(l, pl)) + { + tmp = t_prev_erb[num_erb - 1]; + move16(); + + FOR(i = sub(num_erb, 1); i >= 0; i--) + { + IF(pslot[i] != 0) + { + tmp = t_prev_erb[i]; + move16(); + } + ELSE + { + t_prev_erb[i] = tmp; + move16(); + } + } + } + FOR(i = 0; i < num_erb; i++) + { + dif_erb[i] = sub(curr_erb[i], t_prev_erb[i]); + move16(); + } + + /* First Band Amplitude Search */ + index[0] = erb_diff_search_fx(t_prev_erb, curr_erb, dif_erb, + PowSpect, AmpCB1_fx, + ERB_CBSIZE1, 10, 1); + move16(); + IF(EQ_16(num_erb, NUM_ERB_NB)) + { + /* Second Band Amplitude Search */ + index[1] = erb_diff_search_fx(t_prev_erb, curr_erb, dif_erb, + PowSpect, AmpCB2_NB_fx, + ERB_CBSIZE2, 9, 11); + move16(); + } + ELSE IF(EQ_16(num_erb, NUM_ERB_WB)) + { + /* Second Band Amplitude Search */ + index[1] = erb_diff_search_fx(t_prev_erb, curr_erb, dif_erb, + PowSpect, AmpCB2_WB_fx, + ERB_CBSIZE2, 11, 11); + move16(); + } + +} diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 23802e5..45bb603 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -2,13 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include #include "options.h" #include "cnst_fx.h" #include "rom_com_fx.h" #include "prot_fx.h" -#include "stl.h" /*-------------------------------------------------------------------* * pre_proc() @@ -18,46 +16,42 @@ *--------------------------------------------------------------------*/ void pre_proc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ + Encoder_State_fx* st, /* i/o: encoder state structure */ const Word16 input_frame, /* i : frame length */ - const Word16 signal_in[], /* i : new samples */ Word16 old_inp_12k8[], /* i/o: buffer of old input signal */ Word16 old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ - Word16 **inp, /* o : ptr. to inp. signal in the current frame */ - Word16 *sp_aud_decision1, /* o : 1st stage speech/music classification */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music classification */ - Word32 fr_bands[2*NB_BANDS], /* o : energy in frequency bands */ - Word16 *vad_flag, - Word16 *localVAD, - Word16 *Etot, /* o : total energy */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 pitch[3], /* o : open-loop pitch values for quantiz. */ - Word16 voicing[3], /* o : OL maximum normalized correlation */ - Word16 A[NB_SUBFR16k*(M+1)], /* o : A(z) unquantized for the 4 subframes */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* o : weighted A(z) unquantized for subframes */ - Word16 epsP_h[M+1], /* o : LP prediction errors */ - Word16 epsP_l[M+1], /* o : LP prediction errors */ - Word32 epsP[M+1], /* o : LP prediction errors */ + Word16** inp, /* o : ptr. to inp. signal in the current frame */ + Word32 fr_bands[2 * NB_BANDS], /* o : energy in frequency bands */ + Word16* Etot, /* o : total energy */ + Word32* ener, /* o : residual energy from Levinson-Durbin */ +#ifndef FIX_I4_OL_PITCH + Word16 pitch_orig[3], /* o : open-loop pitch values for quantization */ +#endif + Word16 A[NB_SUBFR16k * (M + 1)], /* o : A(z) unquantized for the 4 subframes */ + Word16 Aw[NB_SUBFR16k * (M + 1)], /* o : weighted A(z) unquantized for subframes */ + Word16 epsP_h[M + 1], /* o : LP prediction errors */ + Word16 epsP_l[M + 1], /* o : LP prediction errors */ + Word32 epsP[M + 1], /* o : LP prediction errors */ Word16 lsp_new[M], /* o : LSPs at the end of the frame */ Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ - Word16 *coder_type, /* o : coder type */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *vad_hover_flag, - Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* o : cldfb real buffer */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* o : cldfb imag buffer */ - CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale*/ - Word16 *old_exc, - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *Q_new, - Word16 *shift, - Word16 *Q_r + Word16* vad_hover_flag, + Word16* attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ + Word16* new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16* Voicing_flag, /* o : voicing flag for HQ FEC */ + + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb real buffer */ + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb imag buffer */ + CLDFB_SCALE_FACTOR* cldfbScale, /* o : cldfb scale */ + Word16* old_exc, /* i/o: static excitation memory */ + Word16* hq_core_type, /* o : HQ core type */ + Word16* Q_new, + Word16* shift, + Word16* Q_r ) { Word16 delay; + const Word16* signal_in; + Word16 i; Word16 *inp_12k8, *new_inp_12k8, *inp_16k, *new_inp_16k; /* pointers to current frame and new data */ Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ @@ -82,7 +76,6 @@ void pre_proc_fx( Word16 vad_flag_dtx; Word16 old_cor; - Word16 uc_clas; Word32 hp_E[2]; /* Energy in HF */ Word16 noisy_speech_HO, clean_speech_HO, NB_speech_HO; /* SC-VBR HO flags */ Word16 non_staX; /* unbound non-stationarity for sp/mus clas. */ @@ -110,16 +103,29 @@ void pre_proc_fx( Word16 fft_buff[2*L_FFT]; Word16 sp_floor; Word16 freqTable[2] = {20, 40}; - Word16 sp_aud_decision0; Word16 last_core_orig; Word16 headroom; Word16 cldfb_addition = 0; move16(); Word16 old_pitch1; + Word16 clas_mod; + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; + NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; + VAD_HANDLE hVAD = st->hVAD; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + RF_ENC_HANDLE hRF = st->hRF; + LPD_state_HANDLE hLPDmem = st->hLPDmem; + FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD; /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ + signal_in = st->input; vad_flag_dtx = 0; move16(); @@ -141,28 +147,28 @@ void pre_proc_fx( *vad_hover_flag = 0; move16(); - uc_clas = VOICED_CLAS; - move16(); - *sp_aud_decision1 = 0; + st->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 0; + st->sp_aud_decision2 = 0; move16(); - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); - st->noise_lev_fx = NOISE_LEVEL_SP0; + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP0; move16(); *attack_flag = 0; move16(); - st->bump_up_fx = 0; - move16(); - st->ppp_mode_fx = 0; - move16(); - st->nelp_mode_fx = 0; - move16(); - st->avoid_HQ_VBR_NB = 0; - move16(); - + IF (hSC_VBR != NULL) + { + hSC_VBR->bump_up_fx = 0; + move16(); + hSC_VBR->ppp_mode_fx = 0; + move16(); + hSC_VBR->nelp_mode_fx = 0; + move16(); + hSC_VBR->avoid_HQ_VBR_NB = 0; + move16(); + } L_look = L_LOOK_12k8; move16(); /* lookahead at 12.8kHz */ @@ -198,7 +204,7 @@ void pre_proc_fx( * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs_fx, new_inp_12k8, 12800, st->mem_decim_fx, (const Word16)(EQ_16(st->max_bwidth_fx,NB))); + modify_Fs_fx( signal_in, input_frame, st->input_Fs_fx, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16)(EQ_16(st->max_bwidth_fx,NB))); Copy( new_inp_12k8, st->buf_speech_enc+L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc+L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* @@ -231,15 +237,19 @@ void pre_proc_fx( * Scaling of memories *-----------------------------------------------------------------*/ - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, Q_new, old_inp_12k8, &(st->mem_wsp_fx), st->enrO_fx, st->bckr_fx, - st->ave_enr_fx, st->ave_enr2_fx, st->fr_bands1_fx, st->fr_bands2_fx, st->Bin_E_old_fx ); + Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, Q_new, old_inp_12k8, &(st->mem_wsp_fx), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, + hNoiseEst->ave_enr_fx, hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); /*-------------------------------------------------------------------------* * Spectral analysis *--------------------------------------------------------------------------*/ - analy_sp( inp_12k8, *Q_new, fr_bands, lf_E, Etot, st->min_band_fx, st->max_band_fx, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, - PS, st->lgBin_E_fx, st->band_energies, fft_buff ); + analy_sp(-1, +#ifdef IVAS_CODE_CPE + NULL, +#endif + st->input_Fs_fx, inp_12k8, *Q_new, fr_bands, lf_E, Etot, st->min_band_fx, st->max_band_fx, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, + PS, st->lgBin_E_fx, st->band_energies, fft_buff ); st->band_energies_exp = sub(sub(WORD32_BITS-1,*Q_new),QSCALE); move16(); @@ -248,32 +258,31 @@ void pre_proc_fx( * SAD (1-signal, 0-noise) *----------------------------------------------------------------*/ - noise_est_pre_fx( *Etot, st->ini_frame_fx, &st->Etot_l_fx, &st->Etot_h_fx, &st->Etot_l_lp_fx, &st->Etot_last_fx, - &st->Etot_v_h2_fx, &st->sign_dyn_lp_fx, st->harm_cor_cnt_fx, &st->Etot_lp_fx ); + noise_est_pre_fx( *Etot, st->ini_frame_fx, hNoiseEst, 0, EVS_MONO, EVS_MONO); - *vad_flag = wb_vad_fx( st, fr_bands, localVAD, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr), *Q_new ); - - vad_flag_cldfb = vad_proc( &(st->vad_st),realBuffer, imagBuffer, cldfbScale->lb_scale, &cldfb_addition, - enerBuffer, enerBuffer_exp,st->cldfbAna_Fx->no_channels, *vad_flag ); + st->vad_flag = wb_vad_fx( st, fr_bands, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, + &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr), *Q_new + , hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx); + vad_flag_cldfb = vad_proc(&(st->vad_st), realBuffer, imagBuffer, cldfbScale->lb_scale, &cldfb_addition, + enerBuffer, enerBuffer_exp, st->cldfbAna_Fx->no_channels, st->vad_flag); IF ( LT_16( st->Pos_relE_cnt, 20) ) /* Ensure the level is high enough and cldfb decision is reliable */ { /* Combine decisions from SADS */ test(); - IF (*vad_flag != 0 && vad_flag_cldfb == 0) + IF (EQ_16(st->vad_flag, 1) && vad_flag_cldfb == 0) { - *localVAD = 0; + st->localVAD = 0; move16(); } - *vad_flag = vad_flag_cldfb; + st->vad_flag = vad_flag_cldfb; move16(); } /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, *localVAD, *vad_flag, sub(st->lp_speech_fx,st->lp_noise_fx), cldfb_addition, vad_hover_flag ); + vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub(st->lp_speech_fx,st->lp_noise_fx), cldfb_addition, vad_hover_flag, hVAD, hNoiseEst ); /*----------------------------------------------------------------* * NB/WB/SWB/FB bandwidth detector @@ -285,7 +294,7 @@ void pre_proc_fx( move16(); } - bw_detect_fx( st, signal_in, *localVAD, enerBuffer, sf_energySum ); + bw_detect_fx( st, signal_in, NULL, enerBuffer, sf_energySum, MONO_FORMAT, 0); /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation @@ -293,8 +302,8 @@ void pre_proc_fx( * Correlation correction as a function of total noise level *----------------------------------------------------------------*/ - noise_est_down_fx( fr_bands, st->bckr_fx, tmpN, tmpE, st->min_band_fx, st->max_band_fx, &st->totalNoise_fx, - *Etot, &st->Etot_last_fx, &st->Etot_v_h2_fx, *Q_new , Le_min_scaled ); + noise_est_down_fx( fr_bands, hNoiseEst->bckr_fx, tmpN, tmpE, st->min_band_fx, st->max_band_fx, &hNoiseEst->totalNoise_fx, + *Etot, &hNoiseEst->Etot_last_fx, &hNoiseEst->Etot_v_h2_fx, *Q_new , Le_min_scaled ); relE = sub(*Etot, st->lp_speech_fx); /* Q8 */ /* relE = *Etot - st->lp_speech;*/ @@ -304,12 +313,12 @@ void pre_proc_fx( st->Pos_relE_cnt = 0; move16(); } - ELSE IF (relE < 0 && *vad_flag == 1) + ELSE IF (relE < 0 && EQ_16(st->vad_flag, 1)) { st->Pos_relE_cnt = add(st->Pos_relE_cnt, 1); } - corr_shift = correlation_shift_fx( st->totalNoise_fx ); + corr_shift = correlation_shift_fx(hNoiseEst->totalNoise_fx ); /*----------------------------------------------------------------* * FD-CNG Noise Estimator @@ -354,11 +363,11 @@ void pre_proc_fx( IF ( EQ_16(st->codec_mode,MODE2)) { - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift); + SetModeIndex( st, st->last_total_brate_fx, EVS_MONO, 0, *shift); } - calcLoEnvCheckCorrHiLo_Fix( st->cldfbAna_Fx->no_col, freqTable, (st->tecEnc).loBuffer, (st->tecEnc).loTempEnv, - (st->tecEnc).loTempEnv_ns, (st->tecEnc).hiTempEnv, &((st->tecEnc).corrFlag) ); + calcLoEnvCheckCorrHiLo_Fix( st->cldfbAna_Fx->no_col, freqTable, st->hTECEnc->loBuffer, st->hTECEnc->loTempEnv, + st->hTECEnc->loTempEnv_ns, st->hTECEnc->hiTempEnv, &(st->hTECEnc->corrFlag) ); /*---------------------------------------------------------------* * Time-domain transient detector @@ -396,14 +405,14 @@ void pre_proc_fx( move16(); alw_pitch_lag_12k8[1] = st->old_pitch_la; move16(); - alw_voicing[0] = st->old_voicing_la; + alw_voicing[0] = st->voicing_fx[2]; move16(); - alw_voicing[1] = st->old_voicing_la; + alw_voicing[1] = st->voicing_fx[2]; move16(); - analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, 12800, *Q_new, Q_r ); + analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, -1/*IVAS_CODE !! LowRateFlag*/,*Q_new, Q_r ); - lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_FX ); + lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_12k8); stab_fac = lsf_stab_fx( lsf_new, st->lsf_old1_fx, 0, L_FRAME ); Copy( lsf_new, st->lsf_old1_fx, M ); @@ -421,82 +430,92 @@ void pre_proc_fx( st->mem_decim2_fx, old_wsp, add(L_FRAME, L_look) ); shift_exp=sub(Q_wsp_exp, Q_exp); - IF( *vad_flag == 0 ) + IF( st->vad_flag == 0 ) { /* reset the OL pitch tracker memories during inactive frames */ pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit_fx, &st->old_corr_fx) ; } + old_pitch1 = st->pitch_fx[1]; - pitch_ol_fx( pitch, voicing, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, + pitch_ol_fx( st->pitch_fx, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit_fx, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, st->clas_fx, st->bwidth_fx, st->Opt_SC_VBR_fx ); /* Updates for adaptive lag window memory */ - st->old_pitch_la = pitch[2]; + st->old_pitch_la = st->pitch_fx[2]; move16(); - st->old_voicing_la = voicing[2]; + st->old_voicing_la = st->voicing_fx[2]; move16(); - /* Detection of very short stable pitch period (MODE1 bit-rates) */ - StableHighPitchDetect_fx( &flag_spitch, pitch, voicing, wsp, *localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, + /* Detection of very short stable st->pitch_fx period (MODE1 bit-rates) */ + StableHighPitchDetect_fx( &flag_spitch, st->pitch_fx, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag_fx, &st->diff_sm_fx, &st->energy_sm_fx,*Q_new,st->lgBin_E_fx); /* 1/4 pitch precision improvement */ IF( LE_32(st->total_brate_fx,ACELP_24k40)) { /* 1/4 pitch precision improvement */ - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[1], &pitch_fr[2], &voicing_fr[2], 2*L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[1], &pitch_fr[3], &voicing_fr[3], 3*L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[2], &voicing_fr[2], 2*L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[3], &voicing_fr[3], 3*L_SUBFR, wsp, 7 ); } ELSE { - pitch_fr[0] = pitch[0]; + pitch_fr[0] = st->pitch_fx[0]; move16(); - pitch_fr[1] = pitch[0]; + pitch_fr[1] = st->pitch_fx[0]; move16(); - pitch_fr[2] = pitch[1]; + pitch_fr[2] = st->pitch_fx[1]; move16(); - pitch_fr[3] = pitch[1]; + pitch_fr[3] = st->pitch_fx[1]; move16(); - voicing_fr[0] = voicing[0]; + voicing_fr[0] = st->voicing_fx[0]; move16(); - voicing_fr[1] = voicing[0]; + voicing_fr[1] = st->voicing_fx[0]; move16(); - voicing_fr[2] = voicing[1]; + voicing_fr[2] = st->voicing_fx[1]; move16(); - voicing_fr[3] = voicing[1]; + voicing_fr[3] = st->voicing_fx[1]; move16(); } - old_pitch1 = st->pitO_fx; move16(); /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - noise_est_fx( st, tmpN, pitch, voicing, epsP_h,epsP_l, *Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, - &sp_div, &Q_sp_div, &non_staX , &loc_harm, lf_E, &st->harm_cor_cnt_fx ,st->Etot_l_lp_fx, - st->Etot_v_h2_fx ,&st->bg_cnt_fx, st->lgBin_E_fx,*Q_new, Le_min_scaled, &sp_floor ); + noise_est_fx( st, old_pitch1, tmpN, epsP_h,epsP_l, *Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, + NULL, &sp_div, &Q_sp_div, &non_staX , &loc_harm, lf_E, &hNoiseEst->harm_cor_cnt_fx , hNoiseEst->Etot_l_lp_fx, + hNoiseEst->Etot_v_h2_fx ,&hNoiseEst->bg_cnt_fx, st->lgBin_E_fx,*Q_new, Le_min_scaled, &sp_floor, NULL, +#ifdef IVAS_CODE + NULL, NULL, +#endif + st->ini_frame_fx); /*------------------------------------------------------------------* * Update parameters used in the VAD and DTX *-----------------------------------------------------------------*/ - - vad_param_updt_fx( st, pitch, voicing, old_pitch1, corr_shift, *vad_flag, A ); + vad_param_updt_fx( st, old_pitch1, corr_shift, corr_shift, A, NULL, 1); /*-----------------------------------------------------------------* * Find spectral tilt * UC and VC frame selection *-----------------------------------------------------------------*/ - find_tilt_fx( fr_bands, st->bckr_fx, ee, pitch, voicing, lf_E, corr_shift, st->input_bwidth_fx, + find_tilt_fx( fr_bands, hNoiseEst->bckr_fx, ee, st->pitch_fx, st->voicing_fx, lf_E, corr_shift, st->input_bwidth_fx, st->max_band_fx, hp_E, st->codec_mode, *Q_new, &(st->bckr_tilt_lt), st->Opt_SC_VBR_fx ); - *coder_type = find_uv_fx( st, pitch_fr, voicing_fr, voicing, inp_12k8, *localVAD, ee, corr_shift, - relE, *Etot, hp_E, *Q_new, &flag_spitch, st->voicing_sm_fx, *shift, last_core_orig ); + st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, +#ifdef IVAS_CODE + NULL, +#endif + corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig +#ifdef IVAS_CODE + , NULL +#endif + ); /*----------------------------------------------------------------* * channel aware mode configuration * @@ -511,18 +530,21 @@ void pre_proc_fx( } ELSE IF( st->rf_mode && NE_32(st->core_brate_fx,FRAME_NO_DATA)&&NE_32(st->core_brate_fx,SID_2k40)) { - /* the RF config is for (n- fec_offset)th frame that will be packed along with the n-th frame bistream */ + /* the RF config is for (n- fec_offset)th frame that will be packed along with the n-th frame bitstream */ st->rf_mode = 1; st->codec_mode = MODE2; - st->rf_target_bits_write = st->rf_targetbits_buff[st->rf_fec_offset]; + st->rf_target_bits_write = hRF->rf_targetbits_buff[st->rf_fec_offset]; } ELSE { st->rf_mode = 0; st->codec_mode = MODE1; - st->rf_indx_frametype[0] = RF_NO_DATA; - st->rf_targetbits_buff[0] = 6; /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ + IF (st->Opt_RF_ON) + { + hRF->rf_indx_frametype[0] = RF_NO_DATA; + hRF->rf_targetbits_buff[0] = 6; /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ + } } /*-----------------------------------------------------------------* @@ -530,10 +552,19 @@ void pre_proc_fx( * TC frame selection *-----------------------------------------------------------------*/ - st->clas_fx = signal_clas_fx( st, coder_type, voicing, inp_12k8, *localVAD, pitch, ee, relE, L_look, &uc_clas); + st->clas_fx = signal_clas_fx( st, inp_12k8, ee, relE, L_look, &clas_mod); + + select_TC(st->codec_mode, st->tc_cnt_fx, &st->coder_type, st->localVAD); + + /* limit coder_type depending on the bitrate */ + coder_type_modif(st, relE); - st->Local_VAD = *localVAD; + if (st->Opt_SC_VBR_fx) + { + hSC_VBR->Local_VAD = st->localVAD; + move16(); + } /*----------------------------------------------------------------* * Speech/music classification * AC frame selection @@ -547,13 +578,14 @@ void pre_proc_fx( Q_esp = add(2*(*Q_new),add(Q_r[0],1)); - speech_music_classif_fx( st, - &sp_aud_decision0, - sp_aud_decision1, sp_aud_decision2, new_inp_12k8, inp_12k8, *vad_flag, - *localVAD, localVAD_HE_SAD, pitch, voicing, lsp_new, cor_map_sum, epsP, PS, - *Etot, old_cor, coder_type, attack_flag, non_staX, relE, Q_esp, *Q_new, &high_lpn_flag, flag_spitch); + speech_music_classif_fx( st, new_inp_12k8, inp_12k8, localVAD_HE_SAD, lsp_new, cor_map_sum, epsP, PS, + *Etot, old_cor, attack_flag, non_staX, relE, Q_esp, *Q_new, &high_lpn_flag, flag_spitch); - long_enr_fx( st, *Etot, localVAD_HE_SAD , high_lpn_flag ); /* has to be after after sp_music classfier */ + long_enr_fx( st, *Etot, localVAD_HE_SAD , high_lpn_flag +#ifdef IVAS_CODE + , NULL, 1, NULL, NULL +#endif + ); /* has to be after after sp_music classfier */ /*----------------------------------------------------------------* * Rewrite the VAD flag by VAD flag with DTX hangover for further processing) @@ -561,7 +593,7 @@ void pre_proc_fx( if( st->Opt_DTX_ON_fx ) { - *vad_flag = vad_flag_dtx; + st->vad_flag = vad_flag_dtx; move16(); /* flag now with the DTX-HO for use in further high rate encoding below */ } @@ -571,30 +603,18 @@ void pre_proc_fx( IF( EQ_16(st->codec_mode,MODE1)) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); + test();test();test();test(); + test();test();test();test();test();test();test();test();test();test(); IF( EQ_32(st->core_brate_fx,FRAME_NO_DATA)) { /* prevent "L_frame" changes in CNG segments */ st->L_frame_fx = st->last_L_frame_fx; move16(); } - ELSE IF ( EQ_32(st->core_brate_fx,SID_2k40)&&GE_16(st->bwidth_fx,WB)&&st->first_CNG_fx&<_16(st->act_cnt2_fx,MIN_ACT_CNG_UPD)) + ELSE IF ( EQ_32(st->core_brate_fx,SID_2k40) && GE_16(st->bwidth_fx,WB) && hDtxEnc->first_CNG_fx && (hTdCngEnc != NULL && LT_16(hTdCngEnc->act_cnt2_fx,MIN_ACT_CNG_UPD))) { /* prevent "L_frame" changes in SID frame after short segment of active frames */ - st->L_frame_fx = st->last_CNG_L_frame_fx; + st->L_frame_fx = hDtxEnc->last_CNG_L_frame_fx; move16(); } ELSE IF ( ( EQ_32(st->core_brate_fx,SID_2k40)&&GE_32(st->total_brate_fx,ACELP_9k60)&&((EQ_16(st->bwidth_fx,WB)&&!(EQ_32(st->total_brate_fx,ACELP_13k20)&&EQ_16(st->cng_type_fx,FD_CNG)))||(EQ_16(st->cng_type_fx,LP_CNG)&>_16(st->bwidth_fx,WB)&&GE_32(st->total_brate_fx,ACELP_16k40))))|| @@ -631,7 +651,7 @@ void pre_proc_fx( move16(); } - st->sr_core = L_mult0(50,st->L_frame_fx); + st->sr_core = L_mult0(FRAMES_PER_SEC,st->L_frame_fx); st->encoderLookahead_enc = NS2SA_fx2(st->sr_core, ACELP_LOOK_NS); move16(); st->encoderPastSamples_enc = shr(imult1616(st->L_frame_fx, 9), 4); @@ -646,71 +666,60 @@ void pre_proc_fx( IF( EQ_16(st->codec_mode,MODE1)) { /* enforce TRANSITION frames */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( NE_16(st->last_L_frame_fx,st->L_frame_fx)&&NE_32(st->core_brate_fx,FRAME_NO_DATA)&&NE_32(st->core_brate_fx,SID_2k40)&&(NE_16(st->coder_type_raw_fx,VOICED))) + test();test();test();test();test();test();test();test(); + test();test();test();test();test(); + IF( NE_16(st->last_L_frame_fx,st->L_frame_fx) && NE_32(st->core_brate_fx,FRAME_NO_DATA) && NE_32(st->core_brate_fx,SID_2k40) && (NE_16(st->coder_type_raw_fx,VOICED))) { /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ - *coder_type = TRANSITION; + st->coder_type = TRANSITION; move16(); } - ELSE IF( EQ_16(st->last_core_fx,HQ_CORE)||EQ_16(st->last_core_fx,TCX_10_CORE)||EQ_16(st->last_core_fx,TCX_20_CORE)) + ELSE IF( EQ_16(st->last_core_fx,HQ_CORE) || EQ_16(st->last_core_fx,TCX_10_CORE) || EQ_16(st->last_core_fx,TCX_20_CORE)) { /* enforce TC frame in case of HQ/TCX -> ACELP core switching */ - *coder_type = TRANSITION; + st->coder_type = TRANSITION; move16(); } - ELSE IF( LE_32(st->last_core_brate_fx,SID_2k40)&&EQ_16(st->cng_type_fx,FD_CNG)) + ELSE IF( LE_32(st->last_core_brate_fx,SID_2k40) && EQ_16(st->cng_type_fx,FD_CNG)) { /* enforce TC frame in case of FD_CNG -> ACELP switching (past excitation not available) */ - *coder_type = TRANSITION; + st->coder_type = TRANSITION; move16(); } /* select INACTIVE frames */ - ELSE IF( LE_32(st->total_brate_fx,ACELP_24k40)&&*vad_flag==0) + ELSE IF( LE_32(st->total_brate_fx,ACELP_24k40) && st->vad_flag==0) { /* inactive frames will be coded by GSC technology */ /* except for the VBR mode. VBR mode uses NELP for that */ test(); - IF ( !( EQ_16(st->Opt_SC_VBR_fx, 1)&&EQ_16(vad_flag_dtx,1))) + IF ( !( EQ_16(st->Opt_SC_VBR_fx, 1) && EQ_16(vad_flag_dtx,1))) { - *coder_type = INACTIVE; + st->coder_type = INACTIVE; move16(); - st->noise_lev_fx = NOISE_LEVEL_SP3; + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP3; move16(); } } ELSE IF( GT_32(st->total_brate_fx,ACELP_24k40)&& - ( (*vad_flag == 0 && GE_16(st->bwidth_fx,SWB) && GE_16(st->max_bwidth_fx,SWB) ) || (*localVAD == 0 && (LE_16(st->bwidth_fx,WB) || LE_16(st->max_bwidth_fx,WB))) ) + ( (st->vad_flag == 0 && GE_16(st->bwidth_fx,SWB) && GE_16(st->max_bwidth_fx,SWB) ) || (st->localVAD == 0 && (LE_16(st->bwidth_fx,WB) || LE_16(st->max_bwidth_fx,WB))) ) ) { /* inactive frames will be coded by AVQ technology */ - *coder_type = INACTIVE; + st->coder_type = INACTIVE; move16(); } } ELSE { - IF( !(*vad_flag) ) + IF( !(st->vad_flag) ) { - *coder_type = INACTIVE; + st->coder_type = INACTIVE; move16(); } - ELSE IF( GT_16(*coder_type,GENERIC)) + ELSE IF( GT_16(st->coder_type,GENERIC)) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } } @@ -721,7 +730,7 @@ void pre_proc_fx( IF( st->Opt_SC_VBR_fx ) { - set_ppp_mode_fx( st, coder_type, noisy_speech_HO, clean_speech_HO, NB_speech_HO, *localVAD, localVAD_HE_SAD, vad_flag, pitch, *sp_aud_decision1 ); + set_ppp_mode_fx( st, noisy_speech_HO, clean_speech_HO, NB_speech_HO, localVAD_HE_SAD); } test(); IF ( !st->Opt_AMR_WB_fx && !st->rf_mode ) @@ -740,35 +749,33 @@ void pre_proc_fx( } } + /*---------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *---------------------------------------------------------------------*/ IF( EQ_16(st->codec_mode,MODE1)) { - /*---------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *---------------------------------------------------------------------*/ - decision_matrix_enc_fx( st, *sp_aud_decision1, *sp_aud_decision2, *coder_type, *vad_flag, hq_core_type ); + decision_matrix_enc_fx( st, hq_core_type ); /* HQ_CORE/TCX_20_CORE decision */ IF ( EQ_16(st->core_fx,HQ_CORE)) /* Decision matrix decided for MDCT coding */ { test(); test(); - IF( (EQ_16(st->bwidth_fx,SWB)||EQ_16(st->bwidth_fx,FB))&&EQ_32(st->total_brate_fx,32000)) + IF( (EQ_16(st->bwidth_fx,SWB) || EQ_16(st->bwidth_fx,FB)) && EQ_32(st->total_brate_fx, ACELP_32k)) { /* Select MDCT Core */ - st->core_fx = mdct_classifier_fx(fft_buff,st,*vad_flag, enerBuffer - ,sub(enerBuffer_exp, 31) - ); + st->core_fx = mdct_classifier_fx(fft_buff,st, enerBuffer,sub(enerBuffer_exp, 31), st->total_brate_fx); } test(); - IF( (EQ_32(st->total_brate_fx,13200))&&(NE_16(st->bwidth_fx,FB))) + IF( (EQ_32(st->total_brate_fx, ACELP_13k20)) && (NE_16(st->bwidth_fx,FB))) { - MDCT_selector( st, sp_floor, *Etot, cor_map_sum, voicing, enerBuffer, enerBuffer_exp, *vad_flag ); + MDCT_selector( st, sp_floor, *Etot, cor_map_sum, enerBuffer, enerBuffer_exp); } } ELSE { - MDCT_selector_reset( st ); + MDCT_selector_reset(hTcxEnc); } /* Switch to MODE2 if TCX_20_CORE */ @@ -781,14 +788,14 @@ void pre_proc_fx( Word32 last_total_brate = L_add(st->last_total_brate_fx, 0); st->last_total_brate_fx = -1; move32(); - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift ); + SetModeIndex( st, st->last_total_brate_fx, EVS_MONO, 0, *shift ); st->last_total_brate_fx = last_total_brate; move32(); } ELSE { - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift); - st->sr_core = getCoreSamplerateMode2( st->total_brate_fx, st->bwidth_fx, st->rf_mode); + SetModeIndex( st, st->last_total_brate_fx, EVS_MONO, 0, *shift); + st->sr_core = getCoreSamplerateMode2(st->element_mode, st->total_brate_fx, st->bwidth_fx, st->flag_ACELP16k, st->rf_mode, 0 ); Mpy_32_16_ss(st->sr_core, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ st->L_frame_fx = extract_l(L_shr(L_tmp, 3)); /* Q0 */ @@ -797,7 +804,7 @@ void pre_proc_fx( st->encoderPastSamples_enc = shr(imult1616(st->L_frame_fx, 9), 4); assert(st->L_frame_fx == st->sr_core / 50); - IF ( EQ_32(st->sr_core,12800)) + IF ( EQ_32(st->sr_core, INT_FS_12k8)) { st->preemph_fac = PREEMPH_FAC; move16(); @@ -812,20 +819,20 @@ void pre_proc_fx( move16(); } - st->igf = getIgfPresent(st->total_brate_fx, st->bwidth_fx, st->rf_mode); + st->igf = getIgfPresent(st->element_mode, st->total_brate_fx, st->bwidth_fx, st->rf_mode); } - *coder_type = st->coder_type_raw_fx; + st->coder_type = st->coder_type_raw_fx; move16(); - IF( *vad_flag == 0 ) + IF( st->vad_flag == 0 ) { - *coder_type = INACTIVE; + st->coder_type = INACTIVE; move16(); } - ELSE IF( GT_16((*coder_type),GENERIC)) + ELSE IF( GT_16((st->coder_type),GENERIC)) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } @@ -838,12 +845,10 @@ void pre_proc_fx( * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); + test();test(); + test();test(); IF( EQ_32(st->total_brate_fx, ACELP_32k)&&EQ_16(loc_harm,1)&>_16(cor_map_sum,50<<8) - && EQ_16(st->clas_fx, VOICED_CLAS) && EQ_16(*coder_type,GENERIC) ) + && EQ_16(st->clas_fx, VOICED_CLAS) && EQ_16(st->coder_type,GENERIC) ) { st->last_harm_flag_acelp_fx = add(st->last_harm_flag_acelp_fx,1); st->last_harm_flag_acelp_fx = s_min(st->last_harm_flag_acelp_fx,10); @@ -858,11 +863,11 @@ void pre_proc_fx( * Update audio frames counter (used for UV decision) *-----------------------------------------------------------------*/ - IF( EQ_16(*coder_type,AUDIO)) + IF( EQ_16(st->coder_type,AUDIO)) { st->audio_frame_cnt_fx = add(st->audio_frame_cnt_fx,AUDIO_COUNTER_STEP); } - ELSE IF (NE_16(*coder_type,INACTIVE)) + ELSE IF (NE_16(st->coder_type,INACTIVE)) { st->audio_frame_cnt_fx = sub(st->audio_frame_cnt_fx,1); } @@ -874,48 +879,40 @@ void pre_proc_fx( * Set formant sharpening flag *-----------------------------------------------------------------*/ - *sharpFlag = 0; + st->sharpFlag = 0; move16(); - IF( EQ_16(*coder_type,TRANSITION)) + IF( EQ_16(st->coder_type,TRANSITION)) { - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test(); IF( ( GT_32(st->total_brate_fx,ACELP_48k)&<_16(st->bwidth_fx,SWB))|| /* Deactivate for core bitrates higher than 48.0 kb/s */ ( GE_32(st->total_brate_fx,ACELP_13k20) && LE_32(st->total_brate_fx,ACELP_16k40) ) || /* Deactivate for bitrates <13.2, 16.4> kb/s (this is basically due to lack of signaling configurations */ ( GT_32(st->total_brate_fx,ACELP_16k40)&>_16(st->lp_noise_fx,FORMANT_SHARPENING_NOISE_THRESHOLD_FX))) /* Deactivate for bitrates >= 24.4 kb/s if the long-term noise level exceeds 34 dB */ { - *sharpFlag= 0; + st->sharpFlag= 0; move16(); } ELSE { - *sharpFlag= 1; + st->sharpFlag= 1; move16(); } } test(); - IF( EQ_16(*coder_type,GENERIC)||EQ_16(*coder_type,VOICED)) + IF( EQ_16(st->coder_type,GENERIC)||EQ_16(st->coder_type,VOICED)) { - test(); - test(); - test(); - test(); - test(); + test();test();test();test();test(); IF( *vad_hover_flag || ( GT_32(st->total_brate_fx,ACELP_48k) && LT_16(st->bwidth_fx,SWB) ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ ( GE_32(st->total_brate_fx,ACELP_13k20)&>_16(st->lp_noise_fx,FORMANT_SHARPENING_NOISE_THRESHOLD_FX) /* Deactivate for bitrates >= 13.2 kb/s if the long-term noise level exceeds 34 dB */ && GT_32(st->total_brate_fx,CNA_MAX_BRATE) ) ) { - *sharpFlag = 0; + st->sharpFlag = 0; move16(); } ELSE { - *sharpFlag = 1; + st->sharpFlag = 1; move16(); } } @@ -923,9 +920,9 @@ void pre_proc_fx( /* channel-aware mode - due to lack of signalling bit, sharpFlag is 1 always in RF mode */ test(); test(); - IF( EQ_16(st->rf_mode,1)&&(EQ_16(*coder_type,VOICED)||EQ_16(*coder_type,GENERIC))) + IF( EQ_16(st->rf_mode,1)&&(EQ_16(st->coder_type,VOICED)||EQ_16(st->coder_type,GENERIC))) { - *sharpFlag = 1; + st->sharpFlag = 1; } /*-----------------------------------------------------------------* @@ -936,7 +933,7 @@ void pre_proc_fx( move16(); test(); test(); - if ( *sp_aud_decision1 == 0 && ( EQ_16(*coder_type,VOICED)||EQ_16(*coder_type,GENERIC))) + if ( st->sp_aud_decision1 == 0 && ( EQ_16(st->coder_type,VOICED)||EQ_16(st->coder_type,GENERIC))) { *Voicing_flag = 1; move16(); @@ -983,7 +980,7 @@ void pre_proc_fx( { modify_Fs_fx( signal_in, input_frame, st->input_Fs_fx, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0 ); } - ELSE /* keep memories up-to-date in case of bit-rate switching */ + ELSE /* keep memories up-to-date in case of bitrate switching */ { /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ delay = NS2SA_fx2(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); @@ -992,12 +989,12 @@ void pre_proc_fx( Copy( signal_in + sub(input_frame, shl(delay,1)), st->mem_decim16k_fx, shl(delay,1) ); } - IF( EQ_32(sr_core_tmp,16000)) + IF( EQ_32(sr_core_tmp, INT_FS_16k)) { /* save input resampled at 16kHz, non-preemhasised */ Copy( new_inp_16k, new_inp_resamp16k, L_FRAME16k ); } - ELSE IF( GT_32(sr_core_tmp,16000)) + ELSE IF( GT_32(sr_core_tmp, INT_FS_16k)) { /* reset the buffer, the signal is needed for WB BWEs */ set16_fx( new_inp_resamp16k, 0, L_FRAME16k ); @@ -1015,7 +1012,7 @@ void pre_proc_fx( } test(); - IF( GT_32(st->input_Fs_fx,8000)&&EQ_32(sr_core_tmp,16000)) + IF( GT_32(st->input_Fs_fx,8000)&&EQ_32(sr_core_tmp, INT_FS_16k)) { Preemph_scaled( new_inp_16k, &Q_new_16k, &(st->mem_preemph16k_fx), st->Q_max_16k, PREEMPH_FAC_16k, 0, 1, L_Q_MEM, L_FRAME16k, st->last_coder_type_fx, 1); } @@ -1029,13 +1026,8 @@ void pre_proc_fx( * Core-encoder memories scaling *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ((st->tcxonly == 0) || !(NE_32(st->core_brate_fx,FRAME_NO_DATA)||NE_32(st->core_brate_fx,SID_2k40)))&&EQ_16(st->L_frame_fx,L_FRAME16k)&&EQ_16(st->codec_mode,MODE2))|| + test();test();test();test();test();test(); + IF( ( ((st->tcxonly == 0) || !(NE_32(st->core_brate_fx,FRAME_NO_DATA) || NE_32(st->core_brate_fx,SID_2k40))) && EQ_16(st->L_frame_fx,L_FRAME16k) && EQ_16(st->codec_mode,MODE2)) || ( EQ_16(st->L_frame_fx,L_FRAME16k) && EQ_16(st->codec_mode,MODE1) ) ) { *Q_new = Q_new_16k; @@ -1055,8 +1047,8 @@ void pre_proc_fx( move16(); Q_wsp_exp = add(Q_exp,shift_exp); - Scale_mem_enc( Q_exp, old_inp_16k, old_exc, st->old_bwe_exc_fx, &(st->LPDmem.mem_w0), st->LPDmem.mem_syn, - st->LPDmem.mem_syn2, &st->mem_deemp_preQ_fx, st->last_exc_dct_in_fx, st->old_input_lp_fx ); + Scale_mem_enc( Q_exp, old_inp_16k, old_exc, hBWE_TD->old_bwe_exc_fx, &(hLPDmem->mem_w0), hLPDmem->mem_syn, + hLPDmem->mem_syn2, &st->mem_deemp_preQ_fx, hGSCEnc->last_exc_dct_in_fx, hBWE_FD->old_input_lp_fx ); /*-----------------------------------------------------------------* * Redo LP analysis at 16kHz if ACELP@16k core was selected @@ -1069,7 +1061,7 @@ void pre_proc_fx( test(); test(); test(); - IF( ( ((st->tcxonly == 0) || !(NE_32(st->core_brate_fx,FRAME_NO_DATA)||NE_32(st->core_brate_fx,SID_2k40)))&&EQ_16(st->L_frame_fx,L_FRAME16k)&&EQ_16(st->codec_mode,MODE2))|| + IF( ( ((st->tcxonly == 0) || !(NE_32(st->core_brate_fx,FRAME_NO_DATA)&&NE_32(st->core_brate_fx,SID_2k40)))&&EQ_16(st->L_frame_fx,L_FRAME16k)&&EQ_16(st->codec_mode,MODE2))|| ( EQ_16(st->L_frame_fx,L_FRAME16k) && EQ_16(st->codec_mode,MODE1) ) ) { /* update signal buffers */ @@ -1093,7 +1085,7 @@ void pre_proc_fx( Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } - analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, pitch, voicing, 16000, *Q_new, Q_r ); + analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch_fx, st->voicing_fx, 16000, -1/*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); /*--------------------------------------------------------------* * Compute Weighted Input @@ -1172,15 +1164,16 @@ void pre_proc_fx( * ACELP/TCX20/HQ Switching Decision *-----------------------------------------------------------------*/ +#ifndef FIX_I4_OL_PITCH + Copy(st->pitch_fx, pitch_orig, 3); +#endif IF ( EQ_16(st->codec_mode,MODE2)) { test(); test(); IF((NE_32(st->core_brate_fx,FRAME_NO_DATA)&&NE_32(st->core_brate_fx,SID_2k40)&&st->tcxonly==0)) { - core_acelp_tcx20_switching( st,*vad_flag, - sp_aud_decision0, non_staX, - pitch, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, *Q_new, *shift ); + core_acelp_tcx20_switching( st, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, *Q_new, *shift ); } test(); @@ -1191,21 +1184,19 @@ void pre_proc_fx( /* Select MDCT Core */ test(); test(); - IF ((EQ_16(st->bwidth_fx,SWB)||EQ_16(st->bwidth_fx,FB))&&EQ_32(st->total_brate_fx,24400)) + IF ((EQ_16(st->bwidth_fx,SWB) || EQ_16(st->bwidth_fx,FB)) && EQ_32(st->total_brate_fx, ACELP_24k40)) { - st->core_fx = mdct_classifier_fx(fft_buff,st,*vad_flag, enerBuffer - ,sub(enerBuffer_exp, 31) - ); + st->core_fx = mdct_classifier_fx(fft_buff,st, enerBuffer, sub(enerBuffer_exp, 31), st->total_brate_fx); } test(); - IF ((EQ_32(st->total_brate_fx,16400))&&(NE_16(st->bwidth_fx,FB))) + IF ((EQ_32(st->total_brate_fx, ACELP_16k40)) && (NE_16(st->bwidth_fx,FB))) { - MDCT_selector( st, sp_floor, *Etot, cor_map_sum, voicing, enerBuffer, enerBuffer_exp, *vad_flag ); + MDCT_selector( st, sp_floor, *Etot, cor_map_sum, enerBuffer, enerBuffer_exp ); } } ELSE { - MDCT_selector_reset( st ); + MDCT_selector_reset(hTcxEnc); } /* Do the switching that was decided in the MDCT selector */ @@ -1223,7 +1214,7 @@ void pre_proc_fx( move16(); st->last_L_frame_fx = st->L_frame_fx; move16(); - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift ); + SetModeIndex( st, st->last_total_brate_fx, EVS_MONO, 0, *shift); st->last_L_frame_fx = L_frame_old; move16(); } @@ -1233,7 +1224,7 @@ void pre_proc_fx( * TCX mode decision *---------------------------------------------------------------*/ - SetTCXModeInfo( st, &st->transientDetection, &st->tcx_cfg.tcx_curr_overlap_mode ); + SetTCXModeInfo( st, &st->transientDetection, &st->hTcxCfg->tcx_curr_overlap_mode ); } /*-----------------------------------------------------------------* @@ -1248,7 +1239,7 @@ void pre_proc_fx( /* update old input signal @16kHz buffer */ test(); - IF( GT_32(st->input_Fs_fx,8000)&&EQ_32(sr_core_tmp,16000)) + IF( GT_32(st->input_Fs_fx,8000)&&EQ_32(sr_core_tmp, INT_FS_16k)) { Copy( &old_inp_16k[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM ); } @@ -1260,14 +1251,14 @@ void pre_proc_fx( test(); test(); - IF( (EQ_32(sr_core_tmp,16000))&&st->tcxonly&&EQ_16(st->codec_mode,MODE2)) + IF( (EQ_32(sr_core_tmp, INT_FS_16k))&&st->tcxonly&&EQ_16(st->codec_mode,MODE2)) { /* copy input resampled at 16kHz, non-preemhasised */ Copy( new_inp_resamp16k, new_inp_16k, L_FRAME16k ); } /* update of old per-band energy spectrum */ - Copy32( fr_bands + NB_BANDS, st->enrO_fx, NB_BANDS ); + Copy32( fr_bands + NB_BANDS, hNoiseEst->enrO_fx, NB_BANDS ); /* set the pointer of the current frame for the ACELP core */ *inp = inp_16k; @@ -1276,6 +1267,29 @@ void pre_proc_fx( *inp = inp_12k8; } + /* Update vAD hangover frame counter in active frames */ + if ((NE_16(st->core_fx, HQ_CORE) && st->tcxonly == 0) || EQ_16(st->core_fx, ACELP_CORE)) + { + + IF(!(EQ_32(st->core_brate_fx, SID_2k40) || EQ_32(st->core_brate_fx, FRAME_NO_DATA))) + { + test(); + IF(st->Opt_DTX_ON_fx != 0 && *vad_hover_flag != 0) + { + hTdCngEnc->burst_ho_cnt_fx = add(hTdCngEnc->burst_ho_cnt_fx, 1); + hTdCngEnc->burst_ho_cnt_fx = s_min(hTdCngEnc->burst_ho_cnt_fx, HO_HIST_SIZE); + } + ELSE + { + IF(hTdCngEnc != NULL && vad_flag_dtx != 0) + { + hTdCngEnc->burst_ho_cnt_fx = 0; + move16(); + } + } + + } + } return; } diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 7450792..ffdf8a2 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -1,32 +1,37 @@ -#include "options.h" /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -static Word16 calc_pvq_splits_fx(Encoder_State_fx *st_fx, const Word16 band_bits, const Word16 sfmsize, const Word16 *y, const Word16 Q_y, + /*-------------------------------------------------------------------* + * Local function prototypes + *--------------------------------------------------------------------*/ + +static Word16 calc_pvq_splits_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, const Word16 *y, const Word16 Q_y, Word16 *bits); -static void densityIndexSymbolEncode_fx( Encoder_State_fx *st_fx, const Word16 density , const Word16 r_dim, const Word16 l_dim , const Word16 index_phi ); +static void densityIndexSymbolEncode_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 density , const Word16 r_dim, const Word16 l_dim , const Word16 index_phi ); +static void encode_energies_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16* coefs, const Word16 Q_coefs, Word16 Np, + Word16* dim_part, Word32* E_part, Word16* bits_part, Word16* g_part, Word16 qband, Word16* bits_left, Word32 enr, Word16 dim, const Word16 strict_bits); /* Encode band with PVQ */ static void pvq_encode_band_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs_norm, + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16* coefs_norm, /* i : normalized vector to encode */ const Word16 Q_coefs, - Word16 *pulse_vector, - Word16 *npulses, - Word16 *coefs_quant, - const Word16 sfmsize, - const Word16 band_bits, - Word16 *bits_left, - const Word16 strict_bits + Word16 *pulse_vector, /* o : quantized vector, integer */ + Word16* npulses, /* o : number of pulses */ + Word16* coefs_quant, /* o : quantized vector */ + const Word16 sfmsize, /* i : length of vector */ + const Word16 band_bits, /* i : assigned bits */ + Word16* bits_left, /* o : bits remaining */ + const Word16 strict_bits /* i : conservative rounding flag */ ) { @@ -43,7 +48,7 @@ static void pvq_encode_band_fx( Word16 tmp; Word32 L_coefs_quant_fx[PVQ_MAX_BAND_SIZE]; - Np = calc_pvq_splits_fx(st_fx, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit); + Np = calc_pvq_splits_fx(hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit); band_bits_tot = sub(band_bits, split_bit); enr = L_deposit_l(0); @@ -75,7 +80,7 @@ static void pvq_encode_band_fx( set16_fx(g_part_neg, -32768, Np); /* -1.0 in Q15 */ IF (GT_16(Np, 1)) { - encode_energies_fx( st_fx, coefs_norm, Q_coefs, Np, dim_part, E_part, bits_part, g_part_neg, band_bits_tot, bits_left, enr, sfmsize, strict_bits ); + encode_energies_fx(hBstr, hPVQ, coefs_norm, Q_coefs, Np, dim_part, E_part, bits_part, g_part_neg, band_bits_tot, bits_left, enr, sfmsize, strict_bits ); } ELSE { @@ -102,7 +107,7 @@ static void pvq_encode_band_fx( IF( K_val > 0 ) { - pvq_encode_fx(st_fx,coefs_norm + part_start[js], pulse_vector + part_start[js], + pvq_encode_fx(hBstr, hPVQ, coefs_norm + part_start[js], pulse_vector + part_start[js], coefs_quant + part_start[js], L_coefs_quant_fx, K_val, dim_part[js], g_part_neg[js]); } ELSE @@ -116,20 +121,20 @@ static void pvq_encode_band_fx( } void pvq_encode_frame_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *gopt, /* o : optimal shape gains */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band Q3 */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *coefs_norm, /* i : normalized coefficients to encode */ + Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ + Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *gopt, /* o : optimal shape gains */ + Word16 *npulses, /* o : number of pulses per band */ + Word16 *pulse_vector, /* o : non-normalized pulse shapes */ + const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ + const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ + const Word16 *sfmsize, /* i : band sizes */ + const Word16 nb_sfm, /* i : total number of bands */ + const Word16 *R, /* i : bitallocation per band Q3 */ + const Word16 pvq_bits, /* i : number of bits avaiable */ + const Word16 core /* i : core */ ) { Word16 i, j; @@ -143,7 +148,10 @@ void pvq_encode_frame_fx( Word16 strict_bits; Word16 exp, tmp, shift; Word32 xy_corr, yy_corr; - rc_enc_init_fx(st_fx, pvq_bits); + PVQ_ENC_DATA pvq_enc; + PVQ_ENC_HANDLE hPVQ = &pvq_enc; + + rc_enc_init_fx(hPVQ, pvq_bits); bits = shl(sub(pvq_bits, RC_BITS_RESERVED), 3); @@ -184,9 +192,9 @@ void pvq_encode_frame_fx( move16(); IF (R[is] > 0) { - bandBitsAdjustment_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ + bandBitsAdjustment_fx(hPVQ->rc_num_bits_fx, hPVQ->rc_range_fx, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ &band_bits, &bits_left, &bit_pool); /* outputs */ - pvq_encode_band_fx( st_fx, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], + pvq_encode_band_fx(hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, &bits_left, strict_bits); @@ -225,7 +233,7 @@ void pvq_encode_frame_fx( } } - rc_enc_finish_fx(st_fx); + rc_enc_finish_fx(hBstr, hPVQ); return; } @@ -237,20 +245,20 @@ void pvq_encode_frame_fx( *---------------------------------------------------------------------*/ Word16 pvq_core_enc_fx( - Encoder_State_fx *st_fx, - Word16 coefs_norm[], - Word16 coefs_quant[], + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ + Word16 coefs_quant[], /* o : quantized coefficients */ Word16 *Q_coefs, - Word16 bits_tot, /* total number of bits */ - Word16 nb_sfm, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core + const Word16 bits_tot, /* i : total number of bits */ + const Word16 nb_sfm, /* i : number of bands */ + const Word16* sfm_start, /* i : Subband start coefficient */ + const Word16* sfm_end, /* i : Subband end coefficient */ + const Word16* sfmsize, /* i : subband width */ + Word16* R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16* Rs, /* i/o: Integer bit allocation */ + Word16* npulses, /* o : number of pulses */ + Word16* maxpulse, /* i : maximum pulse per band */ + const Word16 core /* i : number of bands */ ) { Word16 i; @@ -259,7 +267,7 @@ Word16 pvq_core_enc_fx( Word16 fg_pred[NB_SFM_MAX]; Word16 pvq_bits; - Word16 pulse_vector[L_FRAME48k]; + Word16 pulse_vector[L_SPEC48k_EXT]; Word16 gopt[NB_SFM]; Word16 gain_bits_array[NB_SFM]; Word16 gain_bits_tot; @@ -269,11 +277,9 @@ Word16 pvq_core_enc_fx( gain_bits_tot = assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); pvq_bits = shr(R_upd, 3); - pvq_encode_frame_fx( st_fx, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - - bits_tot = add(pvq_bits, gain_bits_tot); - + pvq_encode_frame_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); + IF( Rs != NULL ) { FOR (i=0; i < nb_sfm; i++) @@ -303,30 +309,31 @@ Word16 pvq_core_enc_fx( fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, coefs_quant, pulse_vector, fg_pred, core); - fine_gain_quant_fx(st_fx, ord, nb_sfm, gain_bits_array, fg_pred, gopt); + fine_gain_quant_fx(hBstr, ord, nb_sfm, gain_bits_array, fg_pred, gopt); apply_gain_fx(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); *Q_coefs = 12; - return bits_tot; + return add(pvq_bits, gain_bits_tot);; } -void encode_energies_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs, /* In block-floating point format with a common block-exponent - not used in this function. Hence, the block-exponent is - not in the parameter list. */ +static void encode_energies_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 *coefs, /* In block-floating point format with a common block-exponent + not used in this function. Hence, the block-exponent is + not in the parameter list. */ const Word16 Q_coefs, - Word16 Np, - Word16 *dim_part, - Word32 *E_part, /* 32-bit Q15 */ - Word16 *bits_part, - Word16 *g_part, /* Q15 */ - Word16 qband, - Word16 *bits_left, - Word32 enr, - Word16 dim, - const Word16 strict_bits + Word16 Np, /* i : number of parts */ + Word16 *dim_part, /* o : sizes of parts */ + Word32 *E_part, /* o : energies of parts 32-bit Q15 */ + Word16 *bits_part, /* o : assigned bits per part */ + Word16 *g_part, /* o : gains Q15 */ + Word16 qband, /* i : assigned quanta per band */ + Word16 *bits_left, /* o : remaining bits */ + Word32 enr, /* i : energy of vector */ + Word16 dim, /* i : size of vector */ + const Word16 strict_bits /* i : conservative rounding flag */ ) { Word16 i, j, l_Np, r_Np; @@ -399,9 +406,9 @@ void encode_energies_fx( phi = mult_r(angle, 20861); - rangeCoderFinalizationFBits_fx((Word16)st_fx->rc_num_bits_fx, (UWord32)st_fx->rc_range_fx, &qzero); + rangeCoderFinalizationFBits_fx(hPVQ->rc_num_bits_fx, (UWord32)hPVQ->rc_range_fx, &qzero); densityAngle2RmsProjEnc_fx(density, phi , &index_phi, &ir, &il, &oppRQ3); - densityIndexSymbolEncode_fx( st_fx, density , r_dim, l_dim , index_phi ); + densityIndexSymbolEncode_fx( hBstr, hPVQ, density , r_dim, l_dim , index_phi ); @@ -418,14 +425,14 @@ void encode_energies_fx( g_part[i] = mult_r(r_gain, g_part[i]); } - NearOppSplitAdjustment_fx( qband, qzero, st_fx->rc_num_bits_fx, st_fx->rc_range_fx, *bits_left, + NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits_fx, hPVQ->rc_range_fx, *bits_left, strict_bits, Np, dim_part[0], dim_part[Np-1], l_dim, r_dim, oppRQ3, &l_bits, &r_bits, bits_left); IF (GT_16(l_Np, 1)) { - encode_energies_fx( st_fx, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); + encode_energies_fx(hBstr, hPVQ, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); } ELSE { @@ -436,7 +443,7 @@ void encode_energies_fx( } IF (GT_16(r_Np, 1)) { - encode_energies_fx( st_fx, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); + encode_energies_fx(hBstr, hPVQ, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); } ELSE { @@ -450,12 +457,13 @@ void encode_energies_fx( } -void densityIndexSymbolEncode_fx( - Encoder_State_fx *st_fx, - const Word16 density , - const Word16 r_dim, - const Word16 l_dim, - const Word16 index_phi +static void densityIndexSymbolEncode_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 density, /* i : Current density */ + const Word16 r_dim, /* i : Opposite size */ + const Word16 l_dim, /* i : Near size */ + const Word16 index_phi /* i : Index */ ) { Word16 angle, c, densitySubIndex, densitySubC; @@ -516,7 +524,7 @@ void densityIndexSymbolEncode_fx( } } - rc_encode_fx(st_fx, cum_freq, sym_freq, tot); + rc_encode_fx(hBstr, hPVQ, cum_freq, sym_freq, tot); } return; @@ -528,13 +536,14 @@ void densityIndexSymbolEncode_fx( * Calculate the number of segments needed *--------------------------------------------------------------------------*/ -static Word16 calc_pvq_splits_fx( /* o : Number of segments */ - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - const Word16 band_bits, /* i : Band bit rate */ - const Word16 sfmsize, /* i : Band width */ - const Word16 *y, /* i : Target vector */ - const Word16 Q_y, /* i : Q point of y */ - Word16 *bits /* o : Consumed bits */ +static Word16 calc_pvq_splits_fx( /* o : Number of segments */ + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 band_bits, /* i : Band bit rate */ + const Word16 sfmsize, /* i : Band width */ + const Word16 *y, /* i : Target vector */ + const Word16 Q_y, /* i : Q point of y */ + Word16 *bits /* o : Consumed bits */ ) { Word16 Np; @@ -611,7 +620,7 @@ static Word16 calc_pvq_splits_fx( /* o : Number of segments */ tmp = 1; move16(); } - rc_enc_bits_fx(st_fx, tmp, 1); + rc_enc_bits_fx(hBstr, hPVQ, tmp, 1); Np = add(Np, tmp); } } diff --git a/lib_enc/pvq_encode_fx.c b/lib_enc/pvq_encode_fx.c index b850930..af6a399 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -1,22 +1,19 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" -#include "stl.h" #include "prot_fx.h" #include "rom_com_fx.h" -#include /* PVQ MIXED_SEARCH_LOOP: low precision 16/32 + energy selective high precision 32/64, mixed perf , 10 dB SEGSNR better than the low precision loop only, active if k>=128 and accumulated energy is high enough, comes at a controlled complexity cost, as dimensions decrease for high k's*/ -static -Word16 max_val_fx( /* o : maximum value in the input vector */ +static Word16 max_val_fx( /* o : maximum value in the input vector */ const Word16 *vec, /* i : input vector */ const Word16 lvec /* i : length of input vector */ ) @@ -32,9 +29,7 @@ Word16 max_val_fx( /* o : maximum value in the input vector return tmp; } -static Word16 pyramidSearchProjInit_fx( - Word16 L, - Word16 Ptot) +static Word16 pyramidSearchProjInit_fx(Word16 L, Word16 Ptot) { return (sub(Ptot, extract_l(L_shr(L_mult0(8223, (Word32)L), 14))) > 0 ); } @@ -45,16 +40,16 @@ static Word16 pyramidSearchProjInit_fx( and the current max_xabs absolute value to be used for an near optimal correlation upscaling. returns the index of the best positioned unit pulse in imax */ -static -Word16 one_pulse_search(const Word16 dim, /* vector dimension */ - const Word16* x_abs, /* absolute vector values */ - Word16* y, /* output vector */ - Word16 *pulse_tot_ptr, - Word32* L_xy_ptr, /* accumulated correlation */ - Word32* L_yy_ptr, /* accumulated energy */ - Word16 high_prec_active, - Word16 en_dn_shift, - Word16 max_xabs) /* current accumulated max amplitude for pulses */ +static Word16 one_pulse_search( + const Word16 dim, /* vector dimension */ + const Word16* x_abs, /* absolute vector values */ + Word16* y, /* output vector */ + Word16 *pulse_tot_ptr, + Word32* L_xy_ptr, /* accumulated correlation */ + Word32* L_yy_ptr, /* accumulated energy */ + Word16 high_prec_active, + Word16 en_dn_shift, + Word16 max_xabs) /* current accumulated max amplitude for pulses */ { Word16 i, corr_up_shift, corr_tmp, imax, corr_sq_tmp, en_max_den, cmax_num, en_tmp; Word32 L_tmp_en_lc, L_tmp_corr ; @@ -170,14 +165,15 @@ Word16 one_pulse_search(const Word16 dim, /* vector dimension */ * * *-----------------------------------------------------------------------*/ void pvq_encode_fx( - Encoder_State_fx *st_fx, - const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ - Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ - Word16 *xq, /* o: quantized vector Q15 */ - Word32 *L_xq, /* o: quantized vector Q31 fot eval */ - const Word16 pulses, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0..1 */ + BSTR_ENC_HANDLE hBstr, + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ + Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ + Word16 *xq, /* o: quantized vector Q15 */ + Word32 *L_xq, /* o: quantized vector Q31 fot eval */ + const Word16 pulses, /* i: number of allocated pulses */ + const Word16 dim, /* i: Length of vector */ + const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0..1 */ ) { Word16 i; @@ -360,10 +356,10 @@ void pvq_encode_fx( entry = mpvq_encode_vec_fx(y, dim, pulses); /* send the short codeword(s) to the range encoder */ - rc_enc_bits_fx(st_fx, UL_deposit_l(entry.lead_sign_ind) , 1); /* 0 or 1 */ + rc_enc_bits_fx(hBstr, hPVQ, UL_deposit_l(entry.lead_sign_ind) , 1); /* 0 or 1 */ IF( NE_16( dim, 1)) { - rc_enc_uniform_fx(st_fx, entry.index, entry.size); + rc_enc_uniform_fx(hBstr, hPVQ, entry.index, entry.size); } return; diff --git a/lib_enc/q_gain2p.c b/lib_enc/q_gain2p.c index a14a407..55a8fa7 100644 --- a/lib_enc/q_gain2p.c +++ b/lib_enc/q_gain2p.c @@ -2,6 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include +#include +#include "options.h" +#include "prot_fx.h" +#include "basop_util.h" +#include "rom_com_fx.h" + + + + /*-------------------------------------------------------------------------* * procedure q_gain2_plus * * ~~~~~~~~~~~~~~~~~~~~~~ * @@ -12,22 +22,6 @@ * The pitch gain and the code gain are vector quantized and the * * mean-squared weighted error criterion is used in the quantizer search. * *-------------------------------------------------------------------------*/ -#include -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" -#include "rom_com_fx.h" - -enum FUNC_GAIN_ENC -{ - FUNC_GAIN_ENC_MLESS = 0, /* Memory-less gain coding */ - FUNC_GAIN_ENC_2 = 1, /* AMR-WB gains quantizer (6bits/subfr (mode 4) or 7bits/subfr (mode 5)) */ /* !!! to be removed !!! */ - FUNC_GAIN_ENC_UV, /* UV gains quantizer (5bits/subfr) */ - FUNC_GAIN_ENC_GACELP_UV /* UV GACELP gain quantizer ((7=5-2bits/subfr) */ -}; - - - void encode_acelp_gains( Word16 *code, Word16 gains_mode, @@ -39,10 +33,10 @@ void encode_acelp_gains( Word16 **pt_indice, Word32 *past_gcode, Word16 *gain_inov, - Word16 L_subfr - , Word16 *code2, - Word32 *gain_code2 - ,Word8 noisy_speech_flag /* (i) : noisy speech flag */ + Word16 L_subfr, + Word16 *code2, + Word32 *gain_code2, + Word8 noisy_speech_flag /* i : noisy speech flag */ ) { Word16 index = 0, func_type = 0; @@ -75,8 +69,7 @@ void encode_acelp_gains( move16(); BREAK; default: - fprintf(stderr, "invalid gains coding for acelp!\n"); - assert(0); + IVAS_ERROR(IVAS_ERR_INTERNAL, "invalid gains coding for acelp!"); func_type = 0; move16(); /*To avoid compiler warning*/ BREAK; @@ -84,20 +77,13 @@ void encode_acelp_gains( IF( func_type == FUNC_GAIN_ENC_MLESS ) { - index = gain_enc(code, - L_subfr, gain_pit, gain_code, g_corr, mean_ener_code, + index = gain_enc(code, L_subfr, gain_pit, gain_code, g_corr, mean_ener_code, clip_gain, past_gcode, gain_inov, gains_mode, func_type); } ELSE { - index = gain_enc_uv(code, - code2, - L_subfr, gain_pit, gain_code, - gain_code2, - noisy_speech_flag, - g_corr, mean_ener_code, - past_gcode, gain_inov, - func_type); + index = gain_enc_uv(code, code2, L_subfr, gain_pit, gain_code, gain_code2, + noisy_speech_flag, g_corr, mean_ener_code, past_gcode, gain_inov, func_type); } move16(); @@ -117,19 +103,19 @@ void encode_acelp_gains( * - the mean-squared weighted error criterion is used for the quantizer search *---------------------------------------------------------------------*/ -Word16 gain_enc( /* o : quantization pitch index */ +Word16 gain_enc( /* o : quantization pitch index */ const Word16 *code, /* i : algebraic excitation */ - Word16 lcode, /* (i) : Subframe size in range: 40,64,80 */ + Word16 lcode, /* i : Subframe size in range: 40,64,80 */ Word16 *gain_pit, /* o : quantized pitch gain */ /* i/o : only func=1,coder_type=1 quantized pitch gain */ Word32 *gain_code, /* o : quantized codebook gain */ ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* (i) : only func=0: mean_ener defined in open-loop (3 bits) */ + Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ const Word16 clip_gain, /* i : only func=0,1: gain pitch clipping flag (1 = clipping) */ Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* (o) : Q12 innovation gain */ - const Word16 coder_type, /* (i) : only func=0,1: coder type */ - const Word16 func_type /* (i) : algorithm: 0=gain_enc_mless, 1=gain_enc_2 */ + Word16 *gain_inov, /* o : Q12 innovation gain */ + const Word16 coder_type, /* i : only func=0,1: coder type */ + const Word16 func_type /* i : algorithm: 0=gain_enc_mless, 1=gain_enc_2 */ ) { Word16 i, j, index, size, min_index, exp_L_tmp1; @@ -404,19 +390,19 @@ Word16 gain_enc( /* o : quantization pitch index return index; } -Word16 gain_enc_uv( /* o : quantization pitch index */ +Word16 gain_enc_uv( /* o : quantization pitch index */ const Word16 *code, /* i : algebraic excitation */ const Word16 *code2, /* i : gaussian excitation */ - Word16 lcode, /* (i) : Subframe size in range: 40,64,80 */ + Word16 lcode, /* i : Subframe size in range: 40,64,80 */ Word16 *gain_pit, /* o : quantized pitch gain */ Word32 *gain_code, /* o : quantized codebook gain */ Word32 *gain_code2, /* o : quantized codebook gain */ - Word8 noisy_speech_flag, /* (i) : noisy speech flag */ + Word8 noisy_speech_flag, /* i : noisy speech flag */ ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* (i) : only func=0: mean_ener defined in open-loop (3 bits) */ + Word16 mean_ener, /* i : only func=0: mean_ener defined in open-loop (3 bits) */ Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* (o) : Q12 innovation gain */ - const Word16 func_type /* (i) : algorithm: 2=gain_enc_uv, 3=gain_enc_gacelp_uv */ + Word16 *gain_inov, /* o : Q12 innovation gain */ + const Word16 func_type /* i : algorithm: 2=gain_enc_uv, 3=gain_enc_gacelp_uv */ ) { Word16 i, index, exp_L_tmp1, tmp; diff --git a/lib_enc/qlpc_avq.c b/lib_enc/qlpc_avq.c index afc09f7..162783d 100644 --- a/lib_enc/qlpc_avq.c +++ b/lib_enc/qlpc_avq.c @@ -3,26 +3,27 @@ ====================================================================================*/ -#include -#include +#include #include -#include "stl.h" -#include "control.h" +#include "options.h" #include "prot_fx.h" -/* Prototypes */ - -void qlpc_avq( - const Word16 *lsf, /* (i) Input LSF vectors (14Q1*1.28) */ - const Word16 *lsfmid, /* (i) Input LSF vectors (14Q1*1.28) */ - Word16 *lsf_q, /* (o) Quantized LFS vectors (14Q1*1.28) */ - Word16 *lsfmid_q, /* (o) Quantized LFS vectors (14Q1*1.28) */ - Word16 *index, /* (o) Quantization indices */ - Word16 *nb_indices, /* (o) Number of quantization indices */ - Word16 *nbbits, /* (o) Number of quantization bits */ - const Word16 core, /* (i) TCX10 or TCX20 */ - Word32 sr_core +/*-------------------------------------------------------------------* + * qlpc_avq() + * + * + * --------------------------------------------------------------------*/ + void qlpc_avq( + const Word16 *lsf, /* i : Input LSF vectors (14Q1*1.28) */ + const Word16 *lsfmid, /* i : Input LSF vectors (14Q1*1.28) */ + Word16 *lsf_q, /* o : Quantized LFS vectors (14Q1*1.28) */ + Word16 *lsfmid_q, /* o : Quantized LFS vectors (14Q1*1.28) */ + Word16 *index, /* o : Quantization indices */ + Word16 *nb_indices, /* o : Number of quantization indices */ + Word16 *nbbits, /* o : Number of quantization bits */ + const Word16 core, /* i : TCX10 or TCX20 */ + const Word32 sr_core /* i : internal sampling rate */ ) { Word16 i; @@ -118,8 +119,13 @@ void qlpc_avq( return; } +/*-------------------------------------------------------------------* + * unary_code() + * + * + *--------------------------------------------------------------------*/ -static Word16 unary_code(Word16 ind, Encoder_State_fx *st) +static Word16 unary_code(Word16 ind, BSTR_ENC_HANDLE hBstr) { Word16 nb_bits; @@ -131,23 +137,27 @@ static Word16 unary_code(Word16 ind, Encoder_State_fx *st) FOR ( ; ind > 0; ind--) { - push_next_indice_fx(st, 1, 1); + push_next_indice_fx(hBstr, 1, 1); nb_bits = add(nb_bits, 1); } /* Stop bit */ - push_next_indice_fx(st, 0, 1); + push_next_indice_fx(hBstr, 0, 1); return(nb_bits); } - -static Word16 unpack4bits(Word16 nbits, const Word16 *prm, Encoder_State_fx *st) +/*-------------------------------------------------------------------* + * unpack4bits() + * + * + *--------------------------------------------------------------------*/ +static Word16 unpack4bits(Word16 nbits, const Word16 *prm, BSTR_ENC_HANDLE hBstr) { Word16 i; IF (nbits == 0) { - push_next_indice_fx(st, 0, 0); + push_next_indice_fx(hBstr, 0, 0); i = 1; move16(); } @@ -158,22 +168,45 @@ static Word16 unpack4bits(Word16 nbits, const Word16 *prm, Encoder_State_fx *st) FOR ( ; nbits > 4; nbits -= 4) { - push_next_indice_fx(st, prm[i], 4); + push_next_indice_fx(hBstr, prm[i], 4); i = add(i, 1); } - push_next_indice_fx(st, prm[i], nbits); + push_next_indice_fx(hBstr, prm[i], nbits); i = add(i, 1); } return(i); } -Word16 encode_lpc_avq( Encoder_State_fx *st, Word16 numlpc, Word16 *param_lpc, Word16 mode ) +/*-------------------------------------------------------------------* + * encode_lpc_avq() + * + * + *--------------------------------------------------------------------*/ + +Word16 encode_lpc_avq( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 numlpc, /* i : Number of sets of lpc */ + const Word16* param_lpc, /* i : lpc parameters */ + const Word16 core, /* i : core */ + const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ +) { Word16 k,j; Word16 q_type, nb_ind; Word16 i,qn1,qn2,nb,avqBits,st1; Word16 nb_bits; + Word16 stereo_mode, bits_for_abs_quant; + stereo_mode = 0; + move16(); + bits_for_abs_quant = LPC_ABS_QUANT_BITS; + move16(); + if (EQ_16(element_mode, IVAS_CPE_MDCT)) + { + bits_for_abs_quant = SNS_ABS_QUANT_BITS; + move16(); + } + move16(); move16(); move16(); @@ -188,13 +221,19 @@ Word16 encode_lpc_avq( Encoder_State_fx *st, Word16 numlpc, Word16 *param_lpc, W move16(); q_type = 0; - IF (k!=0) + if (k!=0) { move16(); q_type = param_lpc[j]; j = add(j,1); } - + test(); + if (EQ_16(element_mode, IVAS_CPE_MDCT) && k == 0) + { + stereo_mode = param_lpc[j]; + move16(); + j = add(j, 1); + } /* Determine number of AVQ indices */ move16(); nb_ind = 0; @@ -208,118 +247,138 @@ Word16 encode_lpc_avq( Encoder_State_fx *st, Word16 numlpc, Word16 *param_lpc, W move16(); qn1 = param_lpc[j++]; qn2 = param_lpc[j++]; - nb_ind = add(qn1, qn2); + IF (EQ_16(qn1, SNS_LOW_BR_MODE)) + { + nb_ind = add(qn1, qn2); + } - IF ( s_or(k==0, s_and(k==1, mode!=1)) ) + IF( k == 0 || ( EQ_16(k, 1) && NE_16(core, TCX_20_CORE) ) ) { /* Encode quantizer type */ - - move16(); nb = 0; - IF (k!=0) + IF(k != 0) { nb = 1; - push_next_indice_fx(st, q_type, nb); + push_next_indice_fx(hBstr, q_type, nb); } nb_bits = add(nb_bits, nb); /* Encode quantizer data */ - - IF (q_type==0) +#if 1 //IVAS_CODE + test(); test(); test(); + IF(((q_type == 0) && NE_16(element_mode, IVAS_CPE_MDCT)) || ((q_type == 0) && (GE_16(st1, 0)) && EQ_16(element_mode, IVAS_CPE_MDCT))) { /* Absolute quantizer with 1st stage stochastic codebook */ - push_next_indice_fx(st, st1, 8); - nb_bits = add(nb_bits, 8); + push_next_indice_fx(hBstr, st1, bits_for_abs_quant); + nb_bits = add(nb_bits, bits_for_abs_quant); } - /* 2 bits to specify Q2,Q3,Q4,ext */ - nb_bits = add(nb_bits, 4); - i = sub(qn1, 2); - - if ( s_or(i<0, (Word16)GT_16(i,3))) + test(); test(); + IF(EQ_16(element_mode, IVAS_CPE_MDCT) && EQ_16(stereo_mode, 3) && st1 < 0) { - move16(); - i = 3; + push_next_indice_fx(hBstr, add(st1, 2), 1); + nb_bits = add(nb_bits, 1); } - push_next_indice_fx(st, i, 2); - - i = sub(qn2, 2); - - if ( s_or(i<0, (Word16)GT_16(i,3))) +#else + IF(q_type == 0) { - move16(); - i = 3; + /* Absolute quantizer with 1st stage stochastic codebook */ + push_next_indice_fx(hBstr, st1, 8); + nb_bits = add(nb_bits, 8); } - push_next_indice_fx(st, i, 2); +#endif + IF(NE_16(element_mode, IVAS_CPE_MDCT) || (NE_16(st1, -2) && NE_16(qn1, SNS_LOW_BR_MODE))) + { - /* Unary code for abs and rel LPC0/LPC2 */ - /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ - move16(); - nb = qn1; + /* 2 bits to specify Q2,Q3,Q4,ext */ + nb_bits = add(nb_bits, 4); + i = sub(qn1, 2); - IF ( GT_16(nb,6)) - { - nb = sub(nb, 3); - } - ELSE IF ( GT_16(nb,4)) - { - nb = sub(nb, 4); - } - ELSE IF (nb == 0) - { - move16(); - nb = 3; - } - ELSE - { - move16(); - nb = 0; - } + if (s_or(i < 0, (Word16)GT_16(i, 3))) + { + move16(); + i = 3; + } + push_next_indice_fx(hBstr, i, 2); - IF (nb > 0) - { - unary_code(nb, st); - } - nb_bits = add(nb_bits, nb); + i = sub(qn2, 2); - move16(); - nb = qn2; + if (s_or(i < 0, (Word16)GT_16(i, 3))) + { + move16(); + i = 3; + } + push_next_indice_fx(hBstr, i, 2); - IF ( GT_16(nb,6)) - { - nb = sub(nb, 3); - } - ELSE IF ( GT_16(nb,4)) - { - nb = sub(nb, 4); - } - ELSE IF (nb == 0) - { - move16(); - nb = 3; - } - ELSE - { + /* Unary code for abs and rel LPC0/LPC2 */ + /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ move16(); - nb = 0; - } + nb = qn1; + + IF(GT_16(nb, 6)) + { + nb = sub(nb, 3); + } + ELSE IF(GT_16(nb, 4)) + { + nb = sub(nb, 4); + } + ELSE IF(nb == 0) + { + move16(); + nb = 3; + } + ELSE + { + move16(); + nb = 0; + } + + IF(nb > 0) + { + unary_code(nb, hBstr); + } + nb_bits = add(nb_bits, nb); - IF (nb > 0) - { - unary_code(nb, st); + move16(); + nb = qn2; + + IF(GT_16(nb, 6)) + { + nb = sub(nb, 3); + } + ELSE IF(GT_16(nb, 4)) + { + nb = sub(nb, 4); + } + ELSE IF(nb == 0) + { + move16(); + nb = 3; + } + ELSE + { + move16(); + nb = 0; + } + + IF(nb > 0) + { + unary_code(nb, hBstr); + } + nb_bits = add(nb_bits, nb); + + avqBits = shl(qn1, 2); + unpack4bits(avqBits, ¶m_lpc[j], hBstr); + j = add(j, qn1); + nb_bits = add(nb_bits, avqBits); + + avqBits = shl(qn2, 2); + unpack4bits(avqBits, ¶m_lpc[j], hBstr); + j = add(j, qn2); + nb_bits = add(nb_bits, avqBits); } - nb_bits = add(nb_bits, nb); - - avqBits = shl(qn1,2); - unpack4bits(avqBits, ¶m_lpc[j], st); - j = add(j, qn1); - nb_bits = add(nb_bits, avqBits); - - avqBits = shl(qn2, 2); - unpack4bits(avqBits, ¶m_lpc[j], st); - j = add(j, qn2); - nb_bits = add(nb_bits, avqBits); } ELSE { diff --git a/lib_enc/qlpc_stoch.c b/lib_enc/qlpc_stoch.c index 5efa7fd..cdaa1d6 100644 --- a/lib_enc/qlpc_stoch.c +++ b/lib_enc/qlpc_stoch.c @@ -3,25 +3,30 @@ ====================================================================================*/ -#include -#include +#include #include - +#include "options.h" #include "cnst_fx.h" #include "rom_enc_fx.h" #include "rom_com_fx.h" -#include "stl.h" #include "prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" +/*-------------------------------------------------------------------* + * local constants + *--------------------------------------------------------------------*/ +#define MIN_LOG_FX 0 +#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ +/*-------------------------------------------------------------------* + * lpc_quantization() + * + * + *--------------------------------------------------------------------*/ void lpc_quantization( Encoder_State_fx * st, - const Word16 core, - const Word16 lpcQuantization, - const Word16 lsfold_q[], const Word16 lsp[], const Word16 lspmid[], Word16 lsp_q[], @@ -29,28 +34,20 @@ void lpc_quantization( Word16 lspmid_q[], Word16 lspq_ind[], Word16 clip_var[], - Word16 mem_MA[], - Word16 mem_AR[], - const Word8 narrowBand, const Word16 coder_type, const Word8 acelp_midLpc, Word16 param_lpc[], Word16 nbits_lpc[], Word16 * bits_param_lpc, Word16 *no_param_lpc, - Word16 *seed_acelp, - Word32 * Bin_Ener, - Word32 * Bin_Ener_old, const Word16 Q_ener ) { - Word16 nb_indices; Word16 lsfmid_q[M]; /* 14Q1*1.28 */ Word16 lsfmid_idx; Word16 i, force_sf; Word16 lsf[M], lsfmid[M]; - Word16 fec_lsf[M], stab; nb_indices = 0; @@ -58,24 +55,30 @@ void lpc_quantization( /****** High-rate LPC quantizer *******/ - IF (lpcQuantization==0) + IF (st->lpcQuantization==0) { + if (st->sr_core != 12800) + { + PMT("from the comment in E_LPC_isp_isf_conversion, it seems built for 12.8kHz, current sampling rate is NOT 12800, is it ok?") + /*_DIFF_FLOAT_FIX_ E_LPC_lsp_lsf_conversion, does it work for 16kHz as well ?*/ + + } E_LPC_lsp_lsf_conversion(lsp, lsf, M); /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx( lsf, clip_var, M ); + gp_clip_test_lsf_fx(st->element_mode, lsf, clip_var, M ); - IF ( (EQ_16(core, TCX_10_CORE))) + IF ( (EQ_16(st->core_fx, TCX_10_CORE))) { E_LPC_lsp_lsf_conversion(lspmid, lsfmid, M); } /* LPC quantizer */ - qlpc_avq(lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, core, st->sr_core); + qlpc_avq(lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core_fx, st->sr_core); E_LPC_lsf_lsp_conversion(lsf_q, lsp_q, M); - IF( EQ_16(core, TCX_10_CORE)) + IF( EQ_16(st->core_fx, TCX_10_CORE)) { E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M ); } @@ -85,18 +88,20 @@ void lpc_quantization( /****** Low-rate LPC quantizer *******/ - ELSE IF ( EQ_16(lpcQuantization, 1)) + ELSE IF ( EQ_16(st->lpcQuantization, 1)) { + assert(st->sr_core <= 32000); + lsp2lsf_fx(lsp, lsf, M, extract_l(st->sr_core)); - gp_clip_test_lsf_fx( lsf, clip_var, M ); + gp_clip_test_lsf_fx(st->element_mode, lsf, clip_var, M ); force_sf = 0; move16(); /*Force safety net when possible in case of transitions*/ test(); test(); - IF( st->tc_cnt_fx >= 1 || LE_32(st->last_core_brate_fx,SID_2k40)||(EQ_16(st->next_force_safety_net_fx,1))) + IF( st->tc_cnt_fx >= 1 || LE_32(st->last_core_brate_fx,SID_2k40) || (EQ_16(st->next_force_safety_net_fx,1))) { force_sf = 1; move16(); @@ -105,32 +110,30 @@ void lpc_quantization( } test(); - IF ( EQ_16(st->next_force_safety_net_fx,1)&&EQ_16(st->Opt_RF_ON,1)) + IF ( EQ_16(st->next_force_safety_net_fx,1) && EQ_16(st->Opt_RF_ON,1)) { force_sf = 1; st->next_force_safety_net_fx = 0; } test(); - IF ( EQ_32(st->sr_core, INT_FS_16k)&&EQ_16(coder_type,UNVOICED)) + IF ( EQ_32(st->sr_core, INT_FS_16k) && EQ_16(coder_type,UNVOICED)) { - lsf_end_enc_fx( st, lsf, lsf_q, mem_AR, mem_MA, ENDLSF_NBITS, GENERIC, st->bwidth_fx, Bin_Ener, Q_ener, st->sr_core, st->core_brate_fx, - &st->streaklimit_fx, &st->pstreaklen_fx, force_sf, 0, - 1, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); nb_indices = *no_param_lpc; } ELSE { - lsf_end_enc_fx( st, lsf, lsf_q, mem_AR, mem_MA, ENDLSF_NBITS, coder_type, st->bwidth_fx, Bin_Ener, Q_ener, st->sr_core, st->core_brate_fx, - &st->streaklimit_fx, &st->pstreaklen_fx, force_sf, 0, - 1, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); + lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, + force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); nb_indices = *no_param_lpc; } - FEC_lsf_estim_enc_fx( st, st->L_frame_fx, fec_lsf ); + FEC_lsf_estim_enc_fx( st, fec_lsf ); /* FEC - calculate LSF stability */ stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame_fx); /*Q15*/ @@ -161,30 +164,28 @@ void lpc_quantization( E_LPC_lsf_lsp_conversion( lsf_q, lspq_ind, M ); } - *seed_acelp=0; + st->seed_acelp=0; move16(); FOR(i=nb_indices-1; i>=0; i--) { - *seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(*seed_acelp, 1), 31821), param_lpc[i], 31821)); + st->seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(st->seed_acelp, 1), 31821), param_lpc[i], 31821)); move16(); } /* Mid-frame LPC quantization */ test(); - IF(lpcQuantization && acelp_midLpc) + IF(st->lpcQuantization && acelp_midLpc) { IF(st->rate_switching_reset==0) { lsp2lsf_fx(lspmid, lsfmid, M, extract_l(st->sr_core)); - midlsf_enc ( lsfold_q, lsf_q, lsfmid, &lsfmid_idx, M, Bin_Ener_old, Q_ener, narrowBand, st->sr_core, coder_type ); + midlsf_enc (st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, st->narrowBand, st->sr_core, coder_type ); param_lpc[nb_indices++] = lsfmid_idx; move16(); - midlsf_dec (lsfold_q, lsf_q, lsfmid_idx, lsfmid_q, coder_type - ,NULL,0,1 - ); + midlsf_dec (st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type ,NULL,0,1 ); reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core ); lsf2lsp_fx(lsfmid_q, lspmid_q, M, st->sr_core); @@ -203,18 +204,21 @@ void lpc_quantization( -#define MIN_LOG_FX 0 -#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ +/*-------------------------------------------------------------------* + * Unified_weighting() + * + * LSF weighting + *-------------------------------------------------------------------*/ void Unified_weighting_fx( - Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ + const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband */ - const Word16 unvoiced, /* i : flag for Unvoiced frame */ - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 order /* i : LP order */ + const Word16 lsf_fx[], /* i : LSF vector x2.56 */ + Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ + const Word16 narrowBand, /* i : flag for Narrowband */ + const Word16 unvoiced, /* i : flag for Unvoiced frame */ + const Word32 sr_core, /* i : sampling rate of core-coder */ + const Word16 order /* i : LP order */ ) { Word16 i; @@ -229,8 +233,7 @@ void Unified_weighting_fx( Word32 L_tmp; Word16 nf_fx; Word32 Bin_Ener_160_fx[160]; - Word32 *Bin_Ener_fx; - const Word32 *Freq_w_Table_fx; + const Word32 *Freq_w_Table_fx, *Bin_Ener_fx; /*Config. weighting*/ @@ -244,7 +247,7 @@ void Unified_weighting_fx( move16(); Bin_Ener_fx = Bin_Ener_128_fx; } - ELSE IF( EQ_32(sr_core, 12800)) + ELSE IF( EQ_32(sr_core, INT_FS_12k8)) { ptr_lsf_fit_model = lsf_unified_fit_model_wb; nf_fx = 16384; diff --git a/lib_enc/range_enc_fx.c b/lib_enc/range_enc_fx.c index 95a4fa8..c26873a 100644 --- a/lib_enc/range_enc_fx.c +++ b/lib_enc/range_enc_fx.c @@ -2,17 +2,16 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -static void rc_enc_shift_fx(Encoder_State_fx *st_fx); -static void rc_enc_write_fx(Encoder_State_fx *st_fx, Word16 byte, Word16 bits); +static void rc_enc_shift_fx(BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ); +static void rc_enc_write_fx(BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits); /*-------------------------------------------------------------------* * rc_enc_init() @@ -21,24 +20,24 @@ static void rc_enc_write_fx(Encoder_State_fx *st_fx, Word16 byte, Word16 bits); *-------------------------------------------------------------------*/ void rc_enc_init_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ Word16 tot_bits /* i : Total bit budget */ ) { - st_fx->rc_low_fx = L_deposit_l(0); - st_fx->rc_range_fx = 0xffffffff; + hPVQ->rc_low_fx = L_deposit_l(0); + hPVQ->rc_range_fx = 0xffffffff; move32(); - st_fx->rc_cache_fx = -1; + hPVQ->rc_cache_fx = -1; move16(); - st_fx->rc_carry_fx = 0; + hPVQ->rc_carry_fx = 0; move16(); - st_fx->rc_carry_count_fx = 0; + hPVQ->rc_carry_count_fx = 0; move16(); - st_fx->rc_num_bits_fx = 0; + hPVQ->rc_num_bits_fx = 0; move16(); - st_fx->rc_tot_bits_fx = tot_bits; + hPVQ->rc_tot_bits_fx = tot_bits; move16(); - st_fx->rc_offset_fx = 0; + hPVQ->rc_offset_fx = 0; move16(); return; @@ -51,7 +50,8 @@ void rc_enc_init_fx( *-------------------------------------------------------------------*/ void rc_encode_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ UWord32 sym_freq, /* i : Symbol probability */ UWord32 tot /* i : Total cumulative frequency */ @@ -62,25 +62,25 @@ void rc_encode_fx( UWord16 carry; inv_tot = UL_inverse(tot, &exp); - Mpy_32_32_uu(st_fx->rc_range_fx, inv_tot, &tmp, &lsb); /*0+exp-32 */ + Mpy_32_32_uu(hPVQ->rc_range_fx, inv_tot, &tmp, &lsb); /*0+exp-32 */ r = UL_lshr(tmp, sub(exp, 32)); /* exp-32-exp3+32 = 0 */ tmp = UL_Mpy_32_32(r, cum_freq); - st_fx->rc_low_fx = UL_addNs(st_fx->rc_low_fx, tmp, &carry); + hPVQ->rc_low_fx = UL_addNs(hPVQ->rc_low_fx, tmp, &carry); if (carry != 0) { - st_fx->rc_carry_fx = carry; + hPVQ->rc_carry_fx = carry; move16(); } - st_fx->rc_range_fx = UL_Mpy_32_32(r, sym_freq); + hPVQ->rc_range_fx = UL_Mpy_32_32(r, sym_freq); - WHILE (st_fx->rc_range_fx < 1<<24) + WHILE (hPVQ->rc_range_fx < 1<<24) { L_sub(0, 0); /* Comparison in while */ - st_fx->rc_range_fx = UL_lshl(st_fx->rc_range_fx, 8); - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, 8); - rc_enc_shift_fx(st_fx); + hPVQ->rc_range_fx = UL_lshl(hPVQ->rc_range_fx, 8); + hPVQ->rc_num_bits_fx = add(hPVQ->rc_num_bits_fx, 8); + rc_enc_shift_fx(hBstr, hPVQ); } return; @@ -93,18 +93,20 @@ void rc_encode_fx( *-------------------------------------------------------------------*/ void rc_enc_finish_fx( - Encoder_State_fx *st_fx /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, + PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ + ) { UWord32 val, mask, high; Word16 bits; UWord16 over1, over2; - bits = add(norm_ul(st_fx->rc_range_fx), 1); + bits = add(norm_ul(hPVQ->rc_range_fx), 1); mask = UL_lshr(0xffffffff, bits); - val = UL_addNs(st_fx->rc_low_fx, mask, &over1); - high = UL_addNs(st_fx->rc_low_fx, st_fx->rc_range_fx, &over2); + val = UL_addNs(hPVQ->rc_low_fx, mask, &over1); + high = UL_addNs(hPVQ->rc_low_fx, hPVQ->rc_range_fx, &over2); val = L_and(val, ~mask); L_xor(0,0); /* For bit not */ @@ -116,60 +118,60 @@ void rc_enc_finish_fx( { bits = add(bits, 1); mask = UL_lshr(mask, 1); - val = UL_and(UL_addNsD(st_fx->rc_low_fx, mask), ~mask); + val = UL_and(UL_addNsD(hPVQ->rc_low_fx, mask), ~mask); L_xor(0,0); /* For bit not */ } - if (val < st_fx->rc_low_fx) + if (val < hPVQ->rc_low_fx) { - st_fx->rc_carry_fx = 1; + hPVQ->rc_carry_fx = 1; move16(); } } - st_fx->rc_low_fx = val; + hPVQ->rc_low_fx = val; move32(); - IF ( GT_16(bits, sub(st_fx->rc_tot_bits_fx, st_fx->rc_num_bits_fx))) + IF ( GT_16(bits, sub(hPVQ->rc_tot_bits_fx, hPVQ->rc_num_bits_fx))) { - bits = sub(st_fx->rc_tot_bits_fx, st_fx->rc_num_bits_fx); + bits = sub(hPVQ->rc_tot_bits_fx, hPVQ->rc_num_bits_fx); } - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, bits); + hPVQ->rc_num_bits_fx = add(hPVQ->rc_num_bits_fx, bits); FOR ( ; bits > 0; bits -= 8) { - rc_enc_shift_fx(st_fx); + rc_enc_shift_fx(hBstr, hPVQ); } bits = add(bits, 8); - IF ( st_fx->rc_carry_count_fx > 0 ) + IF (hPVQ->rc_carry_count_fx > 0 ) { - rc_enc_write_fx(st_fx, add(st_fx->rc_cache_fx, st_fx->rc_carry_fx), 8); + rc_enc_write_fx(hBstr, add(hPVQ->rc_cache_fx, hPVQ->rc_carry_fx), 8); - FOR ( ; st_fx->rc_carry_count_fx > 1; st_fx->rc_carry_count_fx--) + FOR ( ; hPVQ->rc_carry_count_fx > 1; hPVQ->rc_carry_count_fx--) { - rc_enc_write_fx(st_fx, (st_fx->rc_carry_fx + 0xff), 8); + rc_enc_write_fx(hBstr, (hPVQ->rc_carry_fx + 0xff), 8); } - rc_enc_write_fx(st_fx, s_and(add(st_fx->rc_carry_fx, 0xff), sub(lshl(1, bits), 1)), bits); + rc_enc_write_fx(hBstr, s_and(add(hPVQ->rc_carry_fx, 0xff), sub(lshl(1, bits), 1)), bits); } ELSE { - rc_enc_write_fx(st_fx, lshr(add(st_fx->rc_cache_fx, st_fx->rc_carry_fx), sub(8, bits)), bits); + rc_enc_write_fx(hBstr, lshr(add(hPVQ->rc_cache_fx, hPVQ->rc_carry_fx), sub(8, bits)), bits); } - bits = st_fx->rc_num_bits_fx; + bits = hPVQ->rc_num_bits_fx; move16(); - WHILE (LT_16(bits, sub(st_fx->rc_tot_bits_fx, 16))) + WHILE (LT_16(bits, sub(hPVQ->rc_tot_bits_fx, 16))) { - rc_enc_write_fx(st_fx, 0, 16); + rc_enc_write_fx(hBstr, 0, 16); bits = add(bits, 16); } - bits = sub(st_fx->rc_tot_bits_fx, bits); + bits = sub(hPVQ->rc_tot_bits_fx, bits); IF (bits > 0) { - rc_enc_write_fx(st_fx, 0, bits); + rc_enc_write_fx(hBstr, 0, bits); } return; @@ -182,33 +184,34 @@ void rc_enc_finish_fx( *-------------------------------------------------------------------*/ static void rc_enc_shift_fx( - Encoder_State_fx *st_fx /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ) { test(); L_sub(0, 0); /* For comparision in if */ - IF (st_fx->rc_low_fx < (0xff000000UL) || EQ_16(st_fx->rc_carry_fx, 1)) + IF (hPVQ->rc_low_fx < (0xff000000UL) || EQ_16(hPVQ->rc_carry_fx, 1)) { - IF (st_fx->rc_cache_fx >= 0) + IF (hPVQ->rc_cache_fx >= 0) { - rc_enc_write_fx(st_fx, add(st_fx->rc_cache_fx, st_fx->rc_carry_fx), 8); + rc_enc_write_fx(hBstr, add(hPVQ->rc_cache_fx, hPVQ->rc_carry_fx), 8); } - WHILE (st_fx->rc_carry_count_fx > 0) + WHILE (hPVQ->rc_carry_count_fx > 0) { - rc_enc_write_fx(st_fx, s_and(add(st_fx->rc_carry_fx, 0xff), 255), 8); - st_fx->rc_carry_count_fx = sub(st_fx->rc_carry_count_fx, 1); + rc_enc_write_fx(hBstr, s_and(add(hPVQ->rc_carry_fx, 0xff), 255), 8); + hPVQ->rc_carry_count_fx = sub(hPVQ->rc_carry_count_fx, 1); } - st_fx->rc_cache_fx = u_extract_l(UL_lshr(st_fx->rc_low_fx, 24)); - st_fx->rc_carry_fx = 0; + hPVQ->rc_cache_fx = u_extract_l(UL_lshr(hPVQ->rc_low_fx, 24)); + hPVQ->rc_carry_fx = 0; move16(); } ELSE { - st_fx->rc_carry_count_fx = add(st_fx->rc_carry_count_fx, 1); + hPVQ->rc_carry_count_fx = add(hPVQ->rc_carry_count_fx, 1); } - st_fx->rc_low_fx = UL_lshl(st_fx->rc_low_fx, 8); + hPVQ->rc_low_fx = UL_lshl(hPVQ->rc_low_fx, 8); return; } @@ -220,26 +223,27 @@ static void rc_enc_shift_fx( *-------------------------------------------------------------------*/ void rc_enc_bits_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ UWord32 value, /* i : Value to encode */ Word16 bits /* i : Number of bits used */ ) { - IF ( LE_16(add(rc_get_bits2_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx), bits), st_fx->rc_tot_bits_fx)) + IF ( LE_16(add(rc_get_bits2_fx(hPVQ->rc_num_bits_fx, hPVQ->rc_range_fx), bits), hPVQ->rc_tot_bits_fx)) { - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, bits); + hPVQ->rc_num_bits_fx = add(hPVQ->rc_num_bits_fx, bits); IF ( GT_16(bits, 16)) { - push_indice_fx(st_fx, sub(IND_RC_END, st_fx->rc_offset_fx), u_extract_l(UL_lshr(value, 16)), sub(bits, 16)); - st_fx->rc_offset_fx = add(st_fx->rc_offset_fx, 1); - push_indice_fx(st_fx, sub(IND_RC_END, st_fx->rc_offset_fx), u_extract_l(UL_and(value, 0x0000ffff)), 16); - st_fx->rc_offset_fx = add(st_fx->rc_offset_fx, 1); + push_indice_fx(hBstr, sub(IND_RC_END, hPVQ->rc_offset_fx), u_extract_l(UL_lshr(value, 16)), sub(bits, 16)); + hPVQ->rc_offset_fx = add(hPVQ->rc_offset_fx, 1); + push_indice_fx(hBstr, sub(IND_RC_END, hPVQ->rc_offset_fx), u_extract_l(UL_and(value, 0x0000ffff)), 16); + hPVQ->rc_offset_fx = add(hPVQ->rc_offset_fx, 1); } ELSE { - push_indice_fx(st_fx, sub(IND_RC_END, st_fx->rc_offset_fx), u_extract_l(value), bits); - st_fx->rc_offset_fx = add(st_fx->rc_offset_fx, 1); + push_indice_fx(hBstr, sub(IND_RC_END, hPVQ->rc_offset_fx), u_extract_l(value), bits); + hPVQ->rc_offset_fx = add(hPVQ->rc_offset_fx, 1); } } ELSE @@ -256,7 +260,8 @@ void rc_enc_bits_fx( *-------------------------------------------------------------------*/ void rc_enc_uniform_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ UWord32 value, /* i : Value to encode */ UWord32 tot /* i : Maximum value */ ) @@ -267,13 +272,13 @@ void rc_enc_uniform_fx( IF (LE_16(n, 8)) { - rc_encode_fx(st_fx, value, 1, tot); + rc_encode_fx(hBstr, hPVQ, value, 1, tot); } ELSE { n = sub(n, 8); - rc_encode_fx(st_fx, UL_lshr(value, n), 1, UL_addNsD(UL_lshr(tot, n), 1)); - rc_enc_bits_fx(st_fx, UL_and(value, UL_subNsD(UL_lshl(1, n), 1)), n); + rc_encode_fx(hBstr, hPVQ, UL_lshr(value, n), 1, UL_addNsD(UL_lshr(tot, n), 1)); + rc_enc_bits_fx(hBstr, hPVQ, UL_and(value, UL_subNsD(UL_lshl(1, n), 1)), n); } return; @@ -286,12 +291,12 @@ void rc_enc_uniform_fx( *-------------------------------------------------------------------*/ static void rc_enc_write_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 byte, /* i : Byte to write */ Word16 bits /* i : Number of bits */ ) { - push_indice_fx(st_fx, IND_RC_START, byte, bits); + push_indice_fx(hBstr, IND_RC_START, byte, bits); return; } diff --git a/lib_enc/re8_cod_fx.c b/lib_enc/re8_cod_fx.c index 59f98c2..f77401f 100644 --- a/lib_enc/re8_cod_fx.c +++ b/lib_enc/re8_cod_fx.c @@ -1,10 +1,9 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" -#include "stl.h" /*------------------------------------------------------------------------ * RE8_cod: diff --git a/lib_enc/reordernorm_fx.c b/lib_enc/reordernorm_fx.c index 187b08e..71609c0 100644 --- a/lib_enc/reordernorm_fx.c +++ b/lib_enc/reordernorm_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" - #include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ /*--------------------------------------------------------------------------*/ /* Function reordernorm_fx */ @@ -17,11 +16,11 @@ /*--------------------------------------------------------------------------*/ void reordernorm_fx( - const Word16 *ynrm, /* i : quantization indices for norms Q0 */ - const Word16 *normqlg2, /* i : quantized norms Q0 */ - Word16 *idxbuf, /* o : reordered quantization indices Q0 */ - Word16 *normbuf, /* o : reordered quantized norms Q0 */ - const Word16 nb_sfm /* i : number of bands Q0 */ + const Word16 *ynrm, /* i : quantization indices for norms Q0 */ + const Word16 *normqlg2, /* i : quantized norms Q0 */ + Word16 *idxbuf, /* o : reordered quantization indices Q0 */ + Word16 *normbuf, /* o : reordered quantized norms Q0 */ + const Word16 nb_sfm /* i : number of bands Q0 */ ) { Word16 i; diff --git a/lib_enc/rst_enc_fx.c b/lib_enc/rst_enc_fx.c index ed721e3..c0ca875 100644 --- a/lib_enc/rst_enc_fx.c +++ b/lib_enc/rst_enc_fx.c @@ -16,29 +16,31 @@ void CNG_reset_enc_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ + LPD_state_HANDLE hLPDmem, /* i/o: acelp memories */ Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ - ,Word16 VBR_cng_reset_flag + Word16 *voice_factors, /* o : voicing factors */ + Word16 VBR_cng_reset_flag ) { + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + init_gp_clip_fx( st_fx->clip_var_fx ); Copy( UVWB_Ave_fx, st_fx->mem_AR_fx, M ); set16_fx( st_fx->mem_MA_fx, 0, M ); - mem->mem_w0 = 0; + hLPDmem->mem_w0 = 0; move16(); - mem->tilt_code = 0; + hLPDmem->tilt_code = 0; move16(); - mem->gc_threshold = 0; + hLPDmem->gc_threshold = 0; move16(); IF( EQ_16(VBR_cng_reset_flag,1)) { - set16_fx( mem->mem_syn, 0, M ); + set16_fx( hLPDmem->mem_syn, 0, M ); } - /*set16_fx( st_fx->dispMem_fx , 0, 8 ); */ - set16_fx( st_fx->dm_fx.prev_gain_pit , 0, 6 ); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - st_fx->dm_fx.prev_state = 0; + set16_fx(hLPDmem->dm_fx.prev_gain_pit, 0, 6); + hLPDmem->dm_fx.prev_gain_code = L_deposit_l(0); + hLPDmem->dm_fx.prev_state = 0; + PMTE() move16(); /* last good received frame for FEC in ACELP */ @@ -62,8 +64,11 @@ void CNG_reset_enc_fx( move16(); /* Reset active frame counter */ - st_fx->act_cnt2_fx = 0; - move16(); + if (hTdCngEnc != NULL) + { + hTdCngEnc->act_cnt2_fx = 0; + move16(); + } return; } diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index 76f0a25..31a59ac 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -1,11 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include +#include "options.h" #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-----------------------------------------------------------------* * Local constant @@ -13,7 +13,7 @@ #define INPOL 4 /* +- range in samples for impulse position searching */ /*-----------------------------------------------------------------* - * Local function prototype + * Local function prototypes *-----------------------------------------------------------------*/ static void convolve_tc_fx(const Word16 g[],const Word16 h[],Word16 y[],const Word16 L_1,const Word16 L_2); static void correlate_tc_fx(const Word16 *x, Word16 *y, const Word16 *h, const Word16 start, const Word16 L_1,const Word16 L_2); @@ -49,15 +49,15 @@ void set_impulse_fx( Word16 exc_fx[], /* o : adaptive codebook excitation */ Word16 yy1_fx[], /* o : filtered adaptive codebook excitation */ Word16 *imp_shape, /* o : adaptive codebook index */ - Word16 *imp_pos, /* o : position of the glotal impulse center index */ + Word16 *imp_pos, /* o : position of the glottal impulse center index */ Word32 *gain_trans_fx, /* o : transition gain Q7 */ Word16 Q_new /* i : Current scaling */ ) { Word16 i, j, m; Word16 start1, start2, end1; - Word32 rr_fx[L_SUBFR]; /* criterion: nominator coeficients */ - Word16 dd_fx[L_SUBFR],tmp16; /* criterion: denominator coeficients */ + Word32 rr_fx[L_SUBFR]; /* criterion: nominator coefficients */ + Word16 dd_fx[L_SUBFR],tmp16; /* criterion: denominator coefficients */ Word16 gh_fx[L_SUBFR], num, den, exp_num, exp_den; /* convolution of 'g' and 'h' filters */ Word16 krit_fx, krit_max_fx, gain16; Word32 Lrr, Ldd, Ltmp,Ltmp1; @@ -265,7 +265,7 @@ void set_impulse_fx( static void convolve_tc_fx( const Word16 g[], /* i : input vector Qx */ const Word16 h[], /* i : impulse response (or second input vector) Q15 */ - Word16 y[], /* o : output vetor (result of convolution) 12 bits */ + Word16 y[], /* o : output vector (result of convolution) 12 bits */ const Word16 L_1, /* i : vector h size */ const Word16 L_2 /* i : vector g size */ ) @@ -293,7 +293,7 @@ static void convolve_tc_fx( static void convolve_tc2_fx( const Word16 g[], /* i : input vector Qx */ const Word16 h[], /* i : impulse response (or second input vector) Q15 */ - Word16 y[], /* o : output vetor (result of convolution) 12 bits */ + Word16 y[], /* o : output vector (result of convolution) 12 bits */ const Word16 pos_max /* o : artificial impulse position */ ) { diff --git a/lib_enc/setmodeindex.c b/lib_enc/setmodeindex.c index e9c3702..0f9fc30 100644 --- a/lib_enc/setmodeindex.c +++ b/lib_enc/setmodeindex.c @@ -2,13 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include -#include - +#include #include "options.h" -#include "stl.h" #include "prot_fx.h" #include "cnst_fx.h" #include "rom_com_fx.h" @@ -26,25 +21,36 @@ void SetModeIndex( Encoder_State_fx *st, - Word32 total_brate, - Word16 bwidth, - const Word16 shift) + Word32 last_total_brate, + const Word16 last_element_mode, + const Word16 is_mct, + const Word16 shift +) { + Word16 ini_frame_loc = st->ini_frame_fx; + + test();test(); + if (EQ_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(last_element_mode, IVAS_CPE_MDCT) && EQ_16(st->idchan, 1)) + { + st->ini_frame_fx = 0; + move16(); + } /* Reconfigure the core coder */ - test(); - test(); - test(); + test();test();test(); IF( - (NE_32(st->last_total_brate_fx,total_brate) ) || - (NE_16(st->last_bwidth_fx,bwidth) ) || - (EQ_16(st->last_codec_mode,MODE1) ) - || (NE_16(st->rf_mode_last,st->rf_mode) ) + (NE_32(last_total_brate,st->total_brate_fx) ) || + (NE_16(st->last_bwidth_fx,st->bwidth_fx) ) || + (EQ_16(st->last_codec_mode,MODE1) && EQ_16(st->element_mode, EVS_MONO) ) || + ( (NE_16(st->last_core_fx, TCX_20_CORE) && NE_16(st->last_core_fx, TCX_10_CORE)) && GT_16(st->element_mode, EVS_MONO)) || + (NE_16(st->rf_mode_last,st->rf_mode) ) || + (GT_16(st->element_mode, EVS_MONO) && st->ini_frame_fx == 0) ) { - core_coder_mode_switch( st, st->bwidth_fx, total_brate, shift); + core_coder_mode_switch( st, last_total_brate, is_mct, shift); } - + st->ini_frame_fx = ini_frame_loc; return; } + \ No newline at end of file diff --git a/lib_enc/sig_clas.c b/lib_enc/sig_clas.c index 548c1f7..ca0595e 100644 --- a/lib_enc/sig_clas.c +++ b/lib_enc/sig_clas.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*---------------------------------------------------------------------* * Local constants @@ -41,24 +40,19 @@ *-------------------------------------------------------------------*/ Word16 signal_clas_fx( /* o : classification for current frames */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *coder_type, /* i/o: coder type */ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames */ - const Word16 *speech, /* i : pointer to speech signal for E computation */ - const Word16 localVAD, /* i : vad without hangover */ - const Word16 pit[3], /* i : open loop pitch values for 3 half-frames */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16* speech, /* i : pointer to speech signal for E computation */ + const Word32* ee, /* i : lf/hf E ration for 2 half-frames */ const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look , /* i : look-ahead */ - Word16 *uc_clas /* o : temporary classification used in music/speech class*/ + const Word16 L_look, /* i : look-ahead */ + Word16* clas_mod /* o : class flag for NOOP detection */ ) { Word32 Ltmp; Word16 mean_voi2, een, corn, zcn, relEn, pcn, fmerit1; Word16 i, clas, pc, zc, lo, lo2, hi, hi2, exp_ee, frac_ee; Word16 tmp16, tmpS; - const Word16 *pt1; - Word16 unmod_coder_type; + const Word16* pt1; /*----------------------------------------------------------------* * Calculate average voicing @@ -67,9 +61,9 @@ Word16 signal_clas_fx( /* o : classification for current frames * Calculate pitch stability *----------------------------------------------------------------*/ - /* average voicing on second half-frame and look-ahead */ - Ltmp = L_mult(voicing[1], 16384); - mean_voi2 = mac_r(Ltmp, voicing[2], 16384); + /* average voicing on second half-frame and look-ahead */ + Ltmp = L_mult(st->voicing_fx[1], 16384); + mean_voi2 = mac_r(Ltmp, st->voicing_fx[2], 16384); /* average spectral tilt in dB */ lo = L_Extract_lc(ee[0], &hi); @@ -78,12 +72,12 @@ Word16 signal_clas_fx( /* o : classification for current frames test(); test(); - IF (LT_32(Ltmp, 2048)) + IF(LT_32(Ltmp, 2048)) { een = 0; move16(); } - ELSE IF (GT_32(Ltmp, THRES_EEN)||hi>0||hi2>0) + ELSE IF(GT_32(Ltmp, THRES_EEN) || hi > 0 || hi2 > 0) { een = 512; move16(); @@ -94,17 +88,17 @@ Word16 signal_clas_fx( /* o : classification for current frames /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */ exp_ee = norm_l(Ltmp); frac_ee = Log2_norm_lc(L_shl(Ltmp, exp_ee)); - exp_ee = sub(30-11, exp_ee); + exp_ee = sub(30 - 11, exp_ee); Ltmp = Mpy_32_16(exp_ee, frac_ee, LG10); /* Ltmp Q14 */ - een = round_fx(L_shl(Ltmp, 16-5)); /* Q14 -> Q9 */ + een = round_fx(L_shl(Ltmp, 16 - 5)); /* Q14 -> Q9 */ een = mac_r(C_EE_FX, een, K_EE_FX); } - /* compute zero crossing rate */ + /* compute zero crossing rate */ pt1 = speech + L_look - 1; tmpS = shr(*pt1, 15); /* sets 'tmpS to -1 if *pt1 < 0 */ Ltmp = L_deposit_l(0); - FOR (i = 0; i < L_FRAME; i++) + FOR(i = 0; i < L_FRAME; i++) { tmp16 = add(1, tmpS); pt1++; @@ -114,22 +108,23 @@ Word16 signal_clas_fx( /* o : classification for current frames zc = extract_l(Ltmp); /* compute pitch stability */ - pc = add( abs_s(sub(pit[1], pit[0])), abs_s(sub(pit[2], pit[1]))); + pc = add(abs_s(sub(st->pitch_fx[1], st->pitch_fx[0])), abs_s(sub(st->pitch_fx[2], st->pitch_fx[1]))); + st->tdm_pc = pc; /*-----------------------------------------------------------------* * Transform parameters to the range <0:1> * Compute the merit function *-----------------------------------------------------------------*/ - /* corn = K_COR * mean_voi2 + C_COR */ + /* corn = K_COR * mean_voi2 + C_COR */ Ltmp = L_mult(C_COR_FX, 32767); - corn = round_fx(L_shl(L_mac(Ltmp, mean_voi2, K_COR_FX),-4)); /*Q13+Q13*Q15 =>Q13->Q9*/ + corn = round_fx(L_shl(L_mac(Ltmp, mean_voi2, K_COR_FX), -4)); /*Q13+Q13*Q15 =>Q13->Q9*/ /* Limit [0, 1] */ corn = s_max(corn, 0); corn = s_min(corn, 512); Ltmp = L_mult(C_ZC_FX, 4); /*Q13*Q2 -> Q16*/ - zcn = round_fx(L_shl(L_mac(Ltmp, zc, K_ZC_FX),16-7)); /*Q0*Q15 + Q16*/ + zcn = round_fx(L_shl(L_mac(Ltmp, zc, K_ZC_FX), 16 - 7)); /*Q0*Q15 + Q16*/ /* Limit [0, 1] */ zcn = s_max(zcn, 0); zcn = s_min(zcn, 512); @@ -141,7 +136,7 @@ Word16 signal_clas_fx( /* o : classification for current frames relEn = s_min(relEn, 512); Ltmp = L_mult(C_PC_FX, 2); /*Q14*Q1 -> Q16*/ - pcn = round_fx(L_shl(L_mac(Ltmp, pc, K_PC_FX),16-7)); /*Q16 + Q0*Q15*/ + pcn = round_fx(L_shl(L_mac(Ltmp, pc, K_PC_FX), 16 - 7)); /*Q16 + Q0*Q15*/ /* Limit [0, 1] */ pcn = s_max(pcn, 0); pcn = s_min(pcn, 512); @@ -152,36 +147,40 @@ Word16 signal_clas_fx( /* o : classification for current frames Ltmp = L_mac(Ltmp, relEn, 10923); Ltmp = L_mac(Ltmp, pcn, 10923); - fmerit1 = round_fx(L_shl(Ltmp, 16-10-1)); /* fmerit1 ->Q15 */ + fmerit1 = round_fx(L_shl(Ltmp, 16 - 10 - 1)); /* fmerit1 ->Q15 */ /*-----------------------------------------------------------------* * FEC classification - * Onset classification *-----------------------------------------------------------------*/ + st->fmerit_dt = sub(st->prev_fmerit, fmerit1); + st->prev_fmerit = fmerit1; + move16(); /* FEC classification */ test(); test(); - IF (localVAD == 0 || EQ_16(*coder_type,UNVOICED)||LT_16(relE,-1536)) + IF(st->localVAD == 0 || EQ_16(st->coder_type, UNVOICED) || LT_16(relE, -1536)) { clas = UNVOICED_CLAS; + *clas_mod = clas; + move16(); move16(); } ELSE { - SWITCH (st->last_clas_fx) + SWITCH(st->last_clas_fx) { case VOICED_CLAS: case ONSET: case VOICED_TRANSITION: - IF (LT_16(fmerit1, 16056)) /*0.49f*/ + IF(LT_16(fmerit1, 16056)) /*0.49f*/ { clas = UNVOICED_CLAS; move16(); } - ELSE IF (LT_16(fmerit1, 21626)) /*0.66*/ + ELSE IF(LT_16(fmerit1, 21626)) /*0.66*/ { clas = VOICED_TRANSITION; move16(); @@ -191,16 +190,31 @@ Word16 signal_clas_fx( /* o : classification for current frames clas = VOICED_CLAS; move16(); } + IF(LT_16(fmerit1, 14745 /* 0.45f*/)) + { + *clas_mod = UNVOICED_CLAS; + move16(); + } + ELSE IF(LT_16(fmerit1, 21626 /* 0.66f*/)) + { + *clas_mod = VOICED_TRANSITION; + move16(); + } + ELSE + { + *clas_mod = VOICED_CLAS; + move16(); + } BREAK; case UNVOICED_CLAS: case UNVOICED_TRANSITION: - IF (GT_16(fmerit1, 20643)) /*0.63*/ + IF(GT_16(fmerit1, 20643)) /*0.63*/ { clas = ONSET; move16(); } - ELSE IF (GT_16(fmerit1, 19169)) /*0.585*/ + ELSE IF(GT_16(fmerit1, 19169)) /*0.585*/ { clas = UNVOICED_TRANSITION; move16(); @@ -210,17 +224,22 @@ Word16 signal_clas_fx( /* o : classification for current frames clas = UNVOICED_CLAS; move16(); } + *clas_mod = clas; + move16(); + BREAK; default: clas = UNVOICED_CLAS; + *clas_mod = clas; + move16(); move16(); BREAK; } } - - /* set flag for unvoiced class, it will be used in sp/mus classifier */ - *uc_clas = clas; +#if 0 + /* set flag for unvoiced class, it will be used in sp/mus classifier */ + * uc_clas = clas; move16(); test(); test(); @@ -230,149 +249,215 @@ Word16 signal_clas_fx( /* o : classification for current frames test(); test(); test(); - if( ( (EQ_16(*coder_type,UNVOICED))|| - (NE_16(st->input_bwidth_fx,NB) && LT_16(fmerit1,13435) && GT_16(st->mold_corr_fx,21299) ) || /* WB case */ - (EQ_16(st->input_bwidth_fx,NB) && LT_16(mult_r(fmerit1,28836),13435) && GT_16(st->mold_corr_fx,18022) ) ) && /* NB case */ - GT_16(relE,-3840) && LT_16(st->lt_dec_thres_fx,768) ) /* to compute unvoiced on frame that tends to speech */ + if (((EQ_16(*coder_type, UNVOICED)) || + (NE_16(st->input_bwidth_fx, NB) && LT_16(fmerit1, 13435) && GT_16(st->mold_corr_fx, 21299)) || /* WB case */ + (EQ_16(st->input_bwidth_fx, NB) && LT_16(mult_r(fmerit1, 28836), 13435) && GT_16(st->mold_corr_fx, 18022))) && /* NB case */ + GT_16(relE, -3840) && LT_16(st->lt_dec_thres_fx, 768)) /* to compute unvoiced on frame that tends to speech */ { - *uc_clas = UNVOICED_CLAS; + *uc_clas = UNVOICED_CLAS; move16(); } - +#endif /* Onset classification */ /* tc_cnt == -1: frame after TC frame in continuous block of GC/VC frames */ /* tc_cnt == 0: UC frame */ - /* tc_cnt == 1: onset/transition frame, coded by GC mode */ - /* tc_cnt == 2: frame after onset/transition frame, coded by TC mode */ + /* tc_cnt == 1: onset/transition frame, coded by GC coder type */ + /* tc_cnt == 2: frame after onset/transition frame, coded by TC coder type */ - if( EQ_16(clas,UNVOICED_CLAS )) + if (EQ_16(clas, UNVOICED_CLAS)) { st->tc_cnt_fx = 0; move16(); } test(); - if( GE_16(clas,VOICED_TRANSITION)&&st->tc_cnt_fx>=0) + if (GE_16(clas, VOICED_TRANSITION) && st->tc_cnt_fx >= 0) { - st->tc_cnt_fx = add(st->tc_cnt_fx,1); + st->tc_cnt_fx = add(st->tc_cnt_fx, 1); move16(); } - if( GT_16(st->tc_cnt_fx,2)) + if (GT_16(st->tc_cnt_fx, 2)) { st->tc_cnt_fx = -1; move16(); } + return clas; +} +/*-------------------------------------------------------------------* + * select_TC() + * + * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION, + * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames + *-------------------------------------------------------------------*/ + +void select_TC( + const Word16 codec_mode, /* i : codec mode */ + const Word16 tc_cnt, /* i : TC frame counter */ + Word16* coder_type, /* i/o: coder type */ + const Word16 localVAD /* i : VAD without hangover */ +) +{ + IF (EQ_16(codec_mode, MODE1)) + { + /*---------------------------------------------------------------------* + * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION, + * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames + *---------------------------------------------------------------------*/ + + IF (localVAD != 0 && GE_16(tc_cnt, 1)) + { + IF (EQ_16(tc_cnt, 1)) + { + /* onset/transition frame is always coded using GC coder type */ + *coder_type = GENERIC; + move16(); + } + ELSE + { + /* frame after onset/transition frame is coded by TC coder type */ + *coder_type = TRANSITION; + move16(); + } + } + } + + return; +} + +/*-------------------------------------------------------------------* + * coder_type_modif() + * + * Coder type modification + *-------------------------------------------------------------------*/ + +void coder_type_modif( + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16 relE /* i : frame relative E to the long term average */ +) +{ + Word16 unmod_coder_type, vbr_generic_ho; + + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + + + IF (st->Opt_SC_VBR_fx) + { + vbr_generic_ho = hSC_VBR->vbr_generic_ho_fx; + move16(); + } + ELSE + { + vbr_generic_ho = -1; + move16(); + } - IF ( EQ_16(st->codec_mode,MODE1)) + IF(EQ_16(st->codec_mode, MODE1)) { /*---------------------------------------------------------------------* * Coder type modification * - * Prevent UC mode in certain conditions - * Prevent VC mode in certain conditions - * Select TC mode in appropriate frames + * Prevent UC coder type in certain conditions + * Prevent VC coder type in certain conditions + * Select TC coder type in appropriate frames *---------------------------------------------------------------------*/ /* At higher rates, use GC coding instead of UC coding to improve quality */ test(); - if( GT_32(st->total_brate_fx,ACELP_9k60)&&EQ_16(*coder_type,UNVOICED)) + if( (EQ_16(st->element_mode, EVS_MONO) && GT_32(st->total_brate_fx,ACELP_9k60) && EQ_16(st->coder_type,UNVOICED)) || + (GT_16(st->element_mode, EVS_MONO) && GT_32(st->total_brate_fx, MAX_UNVOICED_BRATE) && EQ_16(st->coder_type, UNVOICED)) ) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } /* Prevent UC coding on mixed content at 9.6 kb/s */ test(); test(); - if( EQ_32(st->total_brate_fx,ACELP_9k60)&&EQ_16(*coder_type,UNVOICED)&&st->audio_frame_cnt_fx!=0) + if( GE_32(st->total_brate_fx,ACELP_9k60) && EQ_16(st->coder_type,UNVOICED) && st->audio_frame_cnt_fx!=0) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } - unmod_coder_type = *coder_type; + unmod_coder_type = st->coder_type; move16(); - /* Enforce GC mode on inactive signal (this can be later overwritten to INACTIVE) */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if( localVAD == 0 && ( + /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */ + test();test();test();test(); + test();test();test(); + if( st->localVAD == 0 && ( ( - EQ_16(*coder_type,UNVOICED) - && ( ( st->Opt_SC_VBR_fx == 0) || ( ( st->Opt_SC_VBR_fx == 1 ) && st->vbr_generic_ho_fx == 0 && GT_16(st->last_coder_type_fx,UNVOICED) )) ) - || EQ_16(*coder_type,TRANSITION) || EQ_16(*coder_type,VOICED) ) + EQ_16(st->coder_type,UNVOICED) + && ( ( st->Opt_SC_VBR_fx == 0) || ( ( EQ_16(st->Opt_SC_VBR_fx, 1) ) && vbr_generic_ho == 0 && GT_16(st->last_coder_type_fx,UNVOICED) )) ) + || EQ_16(st->coder_type,TRANSITION) || EQ_16(st->coder_type,VOICED) ) ) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } test(); test(); - if( EQ_16(*coder_type,GENERIC)&&EQ_16(unmod_coder_type,UNVOICED)&&(st->Opt_SC_VBR_fx==1)) - { - st->vbr_generic_ho_fx = 1; - move16(); - } - - test(); - if ( GT_16(*coder_type,UNVOICED)&&(st->Opt_SC_VBR_fx==1)) + IF(EQ_16(st->Opt_SC_VBR_fx, 1)) { - st->vbr_generic_ho_fx = 0; - move16(); - } + if (EQ_16(st->coder_type, GENERIC) && EQ_16(unmod_coder_type, UNVOICED) ) + { + hSC_VBR->vbr_generic_ho_fx = 1; + move16(); + } - st->last_7k2_coder_type_fx = *coder_type; + test(); + if (GT_16(st->coder_type, UNVOICED) ) + { + hSC_VBR->vbr_generic_ho_fx = 0; + move16(); + } + }//_DIFF_FLOAT_FIX_ see below +PMT("Verify if EVS or IVAS is right about last_7k2_coder_type update") + hSC_VBR->last_7k2_coder_type_fx = st->coder_type; move16(); test(); - if( localVAD == 0 && EQ_16( *coder_type, UNVOICED )) + if (st->localVAD == 0 && EQ_16(st->coder_type, UNVOICED)) { - st->last_7k2_coder_type_fx = GENERIC; + hSC_VBR->last_7k2_coder_type_fx = GENERIC; move16(); } + //} closing bracket here in IVAS float, but not in EVS float. currently affects BE for switching bitrate on Linux 20220929 _DIFF_FLOAT_FIX_ !! - /* Select TC mode for appropriate frames which is in general VOICED_TRANSITION, VOICED_CLAS or MODE1_ONSET frames following UNVOICED_CLAS frames */ - test(); - IF( localVAD != 0 && GE_16(st->tc_cnt_fx,1)) /* TC mode is allowed only in active signal */ + IF (EQ_16(st->element_mode, EVS_MONO)) { - /* frame after onset/transition frame is coded by TC mode */ - *coder_type = TRANSITION; - move16(); - if ( EQ_16(st->tc_cnt_fx,1)) + /* At higher rates and with 16kHz core, allow only GC and TC coder type */ + test(); test(); test(); + if (GT_32(st->total_brate_fx, ACELP_16k40) && NE_16(st->coder_type, GENERIC) && NE_16(st->coder_type, TRANSITION)) { /* onset/transition frame is always coded using GC mode */ - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } } - - /* At higher rates and with 16kHz core, allow only GC and TC mode */ - test(); - test(); - if( (GE_32(st->total_brate_fx,ACELP_24k40))&&NE_16(*coder_type,GENERIC)&&NE_16(*coder_type,TRANSITION)) + ELSE /*IVAS*/ { - *coder_type = GENERIC; - move16(); + /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */ + if ((GT_32(st->total_brate_fx, MAX_VOICED_BRATE) && EQ_16(st->coder_type, VOICED)) || + (GT_32(st->total_brate_fx, MAX_UNVOICED_BRATE) && EQ_16(st->coder_type, UNVOICED))) + { + st->coder_type = GENERIC; + move16(); + } + } /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */ - test(); - test(); - test(); - if( EQ_16(*coder_type,VOICED)&&EQ_16(st->input_bwidth_fx,NB)&<_16(relE,-2560)&&LE_32(st->total_brate_fx,ACELP_8k00)) + test();test();test(); + if( EQ_16(st->coder_type,VOICED) && EQ_16(st->input_bwidth_fx,NB) && LT_16(relE,-2560) && LE_32(st->total_brate_fx,ACELP_8k00)) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } } - return clas; + return ; } diff --git a/lib_enc/spec_center.c b/lib_enc/spec_center.c index 428a107..484291e 100644 --- a/lib_enc/spec_center.c +++ b/lib_enc/spec_center.c @@ -2,19 +2,25 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" #include "rom_enc_fx.h" - - -void spec_center(Word32* sb_power, /*(i) energy of sub-band divided uniformly*/ - Word16* sp_center, /*(o) spectral center*/ - Word32 bandwith, /*(i) band width*/ - Word16 Q_sb_p /*(i) the Scaling of sb_power*/ - ) +/*-------------------------------------------------------------------* + * spec_center() + * + * + *-------------------------------------------------------------------*/ + +void spec_center( + Word32* sb_power, /* i : energy of sub-band divided uniformly*/ + Word16* sp_center, /* o : spectral center*/ + const Word32 bw_index, /* i : band width*/ + const Word16 Q_sb_p /* i : the Scaling of sb_power*/ +) { Word16 i; @@ -112,7 +118,7 @@ void spec_center(Word32* sb_power, /*(i) energy of sub-band divided uniformly*/ t_sp_center = 0; move32(); frame_power = 0; move32(); - IF(EQ_32(bandwith,CLDFBVAD_WB_ID)) + IF(EQ_32(bw_index,CLDFBVAD_WB_ID)) { FOR (i=10; i<20; i++) { @@ -183,7 +189,7 @@ void spec_center(Word32* sb_power, /*(i) energy of sub-band divided uniformly*/ sp_center[3]= shr(d_t_sp_center,d_t_sp_center_Qtmp); move16(); } - ELSE IF(EQ_32(bandwith, CLDFBVAD_SWB_ID)) + ELSE IF(EQ_32(bw_index, CLDFBVAD_SWB_ID)) { FOR (i=10; i<24; i++) { diff --git a/lib_enc/spec_flatness.c b/lib_enc/spec_flatness.c index 1a595a0..dd3aeb4 100644 --- a/lib_enc/spec_flatness.c +++ b/lib_enc/spec_flatness.c @@ -3,15 +3,23 @@ ====================================================================================*/ +#include +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" -void spec_flatness(Word32 *spec_amp, /*(i) spectral amplitude*/ - Word32 smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ - Word16 sSFM[5] /*(o) spectral flatness rate*/ - ) +/*-------------------------------------------------------------------* + * spec_flatness() + * + * + *-------------------------------------------------------------------*/ + void spec_flatness( + Word32 *spec_amp, /* i : spectral amplitude*/ + Word32 smooth_spec_amp[], /* i : smoothed spectral amplitude*/ + Word16 sSFM[ ] /* o : spectral flatness rate*/ +) { Word32 i; Word32 *smooth_spec_amp32; diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index bc1c2f8..3a34463 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -25,36 +25,218 @@ * Local functions *---------------------------------------------------------------------*/ -static Word16 sp_mus_classif_gmm_fx( Encoder_State_fx *st_fx, const Word16 localVAD, const Word16 pitch[3], const Word16 voicing[3], - const Word16 lsp_new[M], const Word16 cor_map_sum, const Word32 epsP[M+1], const Word32 PS[], +static Word16 sp_mus_classif_gmm_fx( Encoder_State_fx *st_fx, const Word16 localVAD_HE_SAD, const Word16 lsp_new[M], const Word16 cor_map_sum, const Word32 epsP[M+1], const Word32 PS[], Word16 non_sta, Word16 relE, Word16 *voi_fv, Word16 *cor_map_sum_fv, Word16 *LPCErr, Word16 Q_esp , Word16 *high_lpn_flag_ptr); -static void sp_mus_classif_2nd_fx( Encoder_State_fx *st, const Word16 sp_aud_decision1, Word16 *sp_aud_decision2, - const Word16 pitch[3], const Word16 Etot, Word16 *coder_type, Word16 *attack_flag, - const Word16 *inp, const Word16 Qx, const Word16 localVAD, const Word16 vad_flag ); -static void music_mixed_classif_improv_fx( Encoder_State_fx *st, const Word16 *new_inp, Word16 *sp_aud_decision1, Word16 vad_flag, - const Word16 *voicing, const Word32 *epsP, Word16 Q_epsP, Word16 etot, Word16 old_cor, - Word16 cor_map_sum ); +static void sp_mus_classif_2nd_fx(Encoder_State_fx* st, const Word16 Etot, Word16* attack_flag, const Word16* inp, const Word16 Qx); -static void tonal_context_improv_fx( Encoder_State_fx *st_fx, const Word32 PS[], Word16 *sp_aud_decision1, Word16 *sp_aud_decision2, - const Word16 vad_flag, const Word16 pitch[3], const Word16 voicing[3], const Word16 voi_fv, - const Word16 cor_map_sum_fv, const Word16 LPCErr, const Word16 Qx ); +static void music_mixed_classif_improv_fx( Encoder_State_fx *st, const Word16 *new_inp, const Word32 *epsP, Word16 Q_epsP, Word16 etot, Word16 old_cor,Word16 cor_map_sum ); -static void var_cor_calc_fx( const Word16 old_corr, Word16 *mold_corr, Word16 var_cor_t[], Word16 *high_stable_cor ); +static void tonal_context_improv_fx( Encoder_State_fx *st_fx, const Word32 PS[], const Word16 voi_fv, const Word16 cor_map_sum_fv, const Word16 LPCErr, const Word16 Qx ); -static Word16 attack_det_fx( const Word16 *inp, const Word16 Qx, const Word16 last_clas, const Word16 localVAD, const Word16 coder_type - ,const Word32 total_brate +static void var_cor_calc_fx( const Word16 old_corr, Word16 *mold_corr, Word16 var_cor_t[], Word16 *high_stable_cor ); - ); +static Word16 attack_det_fx(const Word16* inp, const Word16 Qx, const Word16 last_clas, const Word16 localVAD, const Word16 coder_type, + const Word32 total_brate +#ifdef IVAS_CODE + , const Word16 element_mode, const Word16 clas, Word32 finc_prev[], Word32* lt_finc, Word16* last_strong_attack +#endif + ); static void order_spectrum_fx( Word16 *vec, Word16 len ); -static void detect_sparseness_fx( Encoder_State_fx *st_fx, const Word16 localVAD_HE_SAD, Word16 *sp_aud_decision1, - Word16 *sp_aud_decision2, const Word16 voi_fv ); +static void detect_sparseness_fx( Encoder_State_fx *st_fx, const Word16 localVAD_HE_SAD, const Word16 voi_fv ); +/*---------------------------------------------------------------------* + * speech_music_clas_init() + * + * Initialization of speech/music classifier + *---------------------------------------------------------------------*/ + +void speech_music_clas_init( + SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ +) +{ + int16_t i; + + + hSpMusClas->inact_cnt_fx = 0; + move16(); + set16_fx(hSpMusClas->past_dec_fx, 0, HANG_LEN - 1); + set16_fx(hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1); + set16_fx(hSpMusClas->past_log_enr_fx, -1448, NB_BANDS_SPMUS); /* log(E_MIN) in Q8 */ + + hSpMusClas->sp_mus_state_fx = -8; + move16(); + hSpMusClas->wdrop_fx = 0; + move16(); + hSpMusClas->wdlp_0_95_sp_fx = 0; + move16(); + set16_fx(hSpMusClas->last_lsp_fx, 0, M_LSP_SPMUS); + hSpMusClas->last_cor_map_sum_fx = 0; + move16(); + hSpMusClas->last_non_sta_fx = 0; + move16(); + set32_fx(hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN); + hSpMusClas->past_ps_diff_fx = 0; + move16(); + hSpMusClas->past_epsP2_fx = 1024; + move16(); + + + hSpMusClas->gsc_thres_fx[0] = TH_0_MIN_FX; + move16(); + hSpMusClas->gsc_thres_fx[1] = TH_1_MIN_FX; + move16(); + hSpMusClas->gsc_thres_fx[2] = TH_2_MIN_FX; + move16(); + hSpMusClas->gsc_thres_fx[3] = TH_3_MIN_FX; + move16(); + set16_fx(hSpMusClas->gsc_lt_diff_etot_fx, 0, 40); + hSpMusClas->gsc_mem_etot_fx = 0; + move16(); + hSpMusClas->gsc_last_music_flag_fx = 0; + move16(); + hSpMusClas->gsc_nb_thr_1_fx = 0; + move16(); + hSpMusClas->gsc_nb_thr_3_fx = 0; + move16(); + hSpMusClas->mold_corr_fx = 29491; + move16(); + hSpMusClas->mean_avr_dyn_fx = 64; + move16();/*Q7 */ + hSpMusClas->last_sw_dyn_fx = 2560; + move16(); + /* speech/music classifier improvement */ + FOR(i = 0; i < BUF_LEN; i++) + { + hSpMusClas->buf_flux_fx[i] = -12800; + move16(); /*-100.0 in Q7 */ + hSpMusClas->buf_pkh_fx[i] = 0; + move16(); + hSpMusClas->buf_epsP_tilt_fx[i] = 0; + move16(); + hSpMusClas->buf_cor_map_sum_fx[i] = 0; + move16(); + hSpMusClas->buf_Ntonal_fx[i] = 0; + move16(); + hSpMusClas->buf_Ntonal2_fx[i] = 0; + move16(); + hSpMusClas->buf_Ntonal_lf_fx[i] = 0; + move16(); + } + + set16_fx(hSpMusClas->lpe_buf_fx, 0, HANG_LEN_INIT); + set16_fx(hSpMusClas->voicing_buf_fx, 0, HANG_LEN_INIT); + hSpMusClas->gsc_hangover_fx = 0; + move16(); + set16_fx(hSpMusClas->sparse_buf_fx, 0, HANG_LEN_INIT); + set16_fx(hSpMusClas->hf_spar_buf_fx, 0, HANG_LEN_INIT); + hSpMusClas->LT_sparse_fx = 0; + move16(); + hSpMusClas->gsc_cnt_fx = 0; + move16(); + set16_fx(hSpMusClas->old_Bin_E_fx, 0, 3 * N_OLD_BIN_E); + set16_fx(hSpMusClas->buf_etot_fx, 0, 4); + set16_fx(hSpMusClas->buf_dlp_fx, 0, 10); + + hSpMusClas->UV_cnt1_fx = 300; + move16(); + hSpMusClas->LT_UV_cnt1_fx = 16000; + move16(); /*250.0f in Q6 */ + hSpMusClas->onset_cnt_fx = 0; + move16(); + hSpMusClas->attack_hangover_fx = 0; + move16(); + hSpMusClas->dec_mov_fx = 0; + move16(); + hSpMusClas->dec_mov1_fx = 0; + move16(); + hSpMusClas->mov_log_max_spl_fx = 25600; + move16(); /*200.0 in Q7 */ + hSpMusClas->old_lt_diff_fx[0] = 0; + move16(); + hSpMusClas->old_lt_diff_fx[1] = 0; + move16(); + + /* GSC - pitch excitation parameters */ + hSpMusClas->high_stable_cor_fx = 0; + move16(); + set16_fx(hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN); + + hSpMusClas->lps_fx = 0; + move16(); + hSpMusClas->lpm_fx = 0; + move16(); + hSpMusClas->lt_dec_thres_fx = 5120; + move16(); /*10 in Q9 */ + hSpMusClas->ener_RAT_fx = 0; + + /* speech/music classification */ + set16_fx(hSpMusClas->lt_old_mode, 1, 3); + hSpMusClas->lt_voicing = 16384/*0.5f Q15*/; + hSpMusClas->lt_corr = 16384/*0.5f Q15*/; + hSpMusClas->lt_tonality = 0; + move32(); + set16_fx(hSpMusClas->lt_corr_pitch, 0, 3); + hSpMusClas->lt_hangover = 0; + move16(); + hSpMusClas->lowrate_pitchGain = 0; + move16(); + + + hSpMusClas->lt_music_hangover_fx = 0; + move16(); + set16_fx(hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT); + set16_fx(hSpMusClas->tonality3_buf_fx, 0, HANG_LEN_INIT); + set16_fx(hSpMusClas->LPCErr_buf_fx, 0, HANG_LEN_INIT); + hSpMusClas->lt_music_state_fx = 0; + move16(); + hSpMusClas->lt_speech_state_fx = 0; + move16(); + hSpMusClas->lt_speech_hangover_fx = 0; + move16(); + + +#if 0 /*IVAS_CODE*/ + set_f(hSpMusClas->FV_st, 0.0f, N_SMC_FEATURES); //?? + for (i = 0; i < N_SMC_FEATURES; i++) + { + hSpMusClas->prev_FV[i] = 0.5f * hout_intervals[2 * i] + 0.5f * hout_intervals[2 * i + 1]; + } + hSpMusClas->past_epsP = 0; + hSpMusClas->wrise = 0.0f; + hSpMusClas->wdlp_xtalk = 0.0f; + //float past_dlp_mean_ST[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ + hSpMusClas->dlp_mean_ST = 0.0f; + hSpMusClas->flag_spitch_cnt = 0; + hSpMusClas->dlp_mean_LT = 0.0f; + hSpMusClas->dlp_var_LT = 0.0f; + hSpMusClas->relE_attack_cnt = 0; + hSpMusClas->prev_relE = 0.0f; + hSpMusClas->prev_Etot = 0.0f; + hSpMusClas->prev_vad = 0; + hSpMusClas->vad_0_1_cnt = 0; + hSpMusClas->relE_attack_sum = 0; + + set_f(hSpMusClas->finc_prev, 0.0f, ATT_NSEG); + hSpMusClas->lt_finc = 0.0f; + hSpMusClas->last_strong_attack = 0; + set_f(hSpMusClas->tod_lt_Bin_E, 0.0f, TOD_NSPEC); + set_f(hSpMusClas->tod_S_map_lt, 0.0f, TOD_NSPEC); + hSpMusClas->tod_thr_lt = TOD_THR_MASS; + hSpMusClas->tod_weight = 0.0f; + hSpMusClas->tod_S_mass_prev = 0.0f; + hSpMusClas->tod_S_mass_lt = 0.0f; + hSpMusClas->tdm_lt_Etot = 0.01f; + hSpMusClas->lpn = 0.0f; +#endif + + return; +} /*---------------------------------------------------------------------* * speech_music_classif() @@ -72,23 +254,15 @@ static void detect_sparseness_fx( Encoder_State_fx *st_fx, const Word16 localVAD void speech_music_classif_fx( Encoder_State_fx *st, /* i/o: state structure */ - Word16 *sp_aud_decision0, - Word16 *sp_aud_decision1, /* o : 1st stage speech/music decision for GSC */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music decision for GSC */ const Word16 *new_inp, /* i : new input signal */ const Word16 *inp, /* i : input signal to locate attach position */ - const Word16 vad_flag, - const Word16 localVAD, const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ - const Word16 voicing[3], /* i : voicing estimate in three subframes Q15 */ const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ const Word32 epsP[M+1], /* i : LP prediciton error Q_esp*/ const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ const Word16 Etot, /* i : total frame energy Q8 */ const Word16 old_cor, /* i : max correlation from previous frame Q15 */ - Word16 *coder_type, /* i/o: coding type */ Word16 *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ Word16 relE, /* i : relative frame energy */ @@ -99,51 +273,42 @@ void speech_music_classif_fx( ) { Word16 voi_fv, cor_map_sum_fv, LPCErr; - + GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; /* 1st stage speech/music classifier based on the GMM model */ - *sp_aud_decision1 = sp_mus_classif_gmm_fx( st, localVAD_HE_SAD, pitch, voicing, lsp_new, cor_map_sum, - epsP, PS, non_sta, relE, &voi_fv, &cor_map_sum_fv, &LPCErr, - - - Q_esp, high_lpn_flag_ptr ); + st->sp_aud_decision1 = sp_mus_classif_gmm_fx( st, localVAD_HE_SAD, lsp_new, cor_map_sum, + epsP, PS, non_sta, relE, &voi_fv, &cor_map_sum_fv, &LPCErr, Q_esp, high_lpn_flag_ptr ); test(); - IF ( EQ_16( st->codec_mode, MODE1)||EQ_32(st->sr_core,12800)) + IF ( EQ_16( st->codec_mode, MODE1) || EQ_32(st->sr_core, INT_FS_12k8)) { /* Improvement of the 1st stage decision on mixed/music content */ test(); - IF ( st->Opt_SC_VBR_fx == 0 && ( NE_32(st->total_brate_fx, ACELP_24k40))) + IF ( st->Opt_SC_VBR_fx == 0 && NE_32(st->total_brate_fx, ACELP_24k40)) { - - - music_mixed_classif_improv_fx( st, new_inp, sp_aud_decision1, vad_flag, voicing, epsP, Q_esp, Etot, - old_cor, cor_map_sum ); - - + music_mixed_classif_improv_fx( st, new_inp, epsP, Q_esp, Etot, old_cor, cor_map_sum ); } - *sp_aud_decision0 = *sp_aud_decision1; + st->sp_aud_decision0 = st->sp_aud_decision1; /* 2nd stage speech/music classifier (rewrite music to speech in onsets) */ - *sp_aud_decision2 = *sp_aud_decision1; + st->sp_aud_decision2 = st->sp_aud_decision1; move16(); IF ( GT_16(st->bwidth_fx,NB)) { - sp_mus_classif_2nd_fx( st, *sp_aud_decision1, sp_aud_decision2, pitch, Etot, coder_type, - attack_flag, inp, Q_inp-1, localVAD, vad_flag ); + sp_mus_classif_2nd_fx( st, Etot, attack_flag, inp, Q_inp-1); - /* avoid switch to AUDIO/MUSIC class for very short stable high pitch + /* avoid switch to AUDIO/MUSIC class for very short stable high st->pitch_fx and/or stable pitch with high correlation at low bitrates*/ test(); test(); - IF ( flag_spitch && EQ_16(st->bwidth_fx,WB)&<_32(st->total_brate_fx,ACELP_13k20)) + IF ( flag_spitch && EQ_16(st->bwidth_fx,WB) && LT_32(st->total_brate_fx,ACELP_13k20)) { - *sp_aud_decision2 = 0; + st->sp_aud_decision2 = 0; move16(); } } @@ -152,10 +317,9 @@ void speech_music_classif_fx( /* Context-based improvement of 1st and 2nd stage decision on stable tonal signals */ test(); - IF ( st->Opt_SC_VBR_fx == 0 && ( NE_32(st->total_brate_fx, ACELP_24k40))) + IF ( st->Opt_SC_VBR_fx == 0 && NE_32(st->total_brate_fx, ACELP_24k40)) { - tonal_context_improv_fx( st, PS, sp_aud_decision1, sp_aud_decision2, vad_flag, pitch, voicing, - voi_fv, cor_map_sum_fv, LPCErr, Q_inp + QSCALE -2 ); + tonal_context_improv_fx( st, PS, voi_fv, cor_map_sum_fv, LPCErr, Q_inp + QSCALE -2 ); } /* Avoid using LR-MDCT on sparse spectra, use GSC instead at 13.2 kbps (WB/SWB) */ @@ -163,19 +327,19 @@ void speech_music_classif_fx( test(); test(); test(); - IF ( !st->Opt_SC_VBR_fx && EQ_32(st->total_brate_fx, ACELP_13k20)&&EQ_16(vad_flag,1)&& + IF ( !st->Opt_SC_VBR_fx && EQ_32(st->total_brate_fx, ACELP_13k20) && EQ_16(st->vad_flag,1)&& ( EQ_16(st->bwidth_fx, WB) || EQ_16(st->bwidth_fx, SWB)) ) { - detect_sparseness_fx( st, localVAD_HE_SAD, sp_aud_decision1, sp_aud_decision2, voi_fv ); + detect_sparseness_fx( st, localVAD_HE_SAD, voi_fv ); } /* override speech/music classification to ACELP when background noise level reaches certain level */ /* this is a patch against mis-classifications during active noisy speech segments */ IF ( GT_16(st->lp_noise_fx, 3072)) { - *sp_aud_decision1 = 0; + st->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 0; + st->sp_aud_decision2 = 0; move16(); } @@ -183,14 +347,10 @@ void speech_music_classif_fx( /* select GSC on SWB noisy speech (only on active unvoiced SWB noisy speech segments) */ st->GSC_noisy_speech_fx = 0; move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( EQ_16(vad_flag,1)&&GE_32(st->total_brate_fx,ACELP_13k20)&<_32(st->total_brate_fx,ACELP_24k40)&& - GT_16(st->lp_noise_fx,3072) && *sp_aud_decision1 == 0 && GE_16(st->bwidth_fx,SWB) && + + test();test();test();test();test();test(); + IF ( EQ_16(st->vad_flag,1)&&GE_32(st->total_brate_fx,ACELP_13k20)&<_32(st->total_brate_fx,ACELP_24k40)&& + GT_16(st->lp_noise_fx,3072) && st->sp_aud_decision1 == 0 && GE_16(st->bwidth_fx,SWB) && EQ_16(st->coder_type_raw_fx,UNVOICED)) { st->GSC_noisy_speech_fx = 1; @@ -198,22 +358,20 @@ void speech_music_classif_fx( } /* Select AUDIO frames */ - test(); - test(); - test(); - test(); - IF ( EQ_16(st->codec_mode,MODE1)&&(*sp_aud_decision2||st->GSC_noisy_speech_fx)) + test();test(); + test();test(); + IF ( EQ_16(st->codec_mode,MODE1) && (st->sp_aud_decision2 || st->GSC_noisy_speech_fx)) { - *coder_type = AUDIO; + st->coder_type = AUDIO; move16(); - st->noise_lev_fx = NOISE_LEVEL_SP0; + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP0; move16(); } } ELSE { - *sp_aud_decision0 = *sp_aud_decision1; + st->sp_aud_decision0 = st->sp_aud_decision1; } @@ -226,22 +384,20 @@ void speech_music_classif_fx( * Speech/music classification based on GMM model *---------------------------------------------------------------------*/ -static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech or noise) */ - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 localVAD, - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes Q0 */ - const Word16 voicing[3], /* i : voicing estimate in three subframes Q15 */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8 */ - const Word32 epsP[M+1], /* i : LP prediciton error Q_esp */ - const Word32 PS[], /* i : energy spectrum Q_new+Qscale-2 */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 *voi_fv, /* o : scaled voicing feature */ - Word16 *cor_map_sum_fv, /* o : scaled correlation map feature */ - Word16 *LPCErr, /* o : scaled LP prediction error feature */ - Word16 Q_esp /* i : scaling of epsP */ - ,Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ +static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech or noise) */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 localVAD_HE_SAD, /* i : local VAD HE flag */ + const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8 */ + const Word32 epsP[M+1], /* i : LP prediciton error Q_esp */ + const Word32 PS[], /* i : energy spectrum Q_new+Qscale-2 */ + Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ + Word16 relE, /* i : relative frame energy */ + Word16 *voi_fv, /* o : scaled voicing feature */ + Word16 *cor_map_sum_fv, /* o : scaled correlation map feature */ + Word16 *LPCErr, /* o : scaled LP prediction error feature */ + Word16 Q_esp, /* i : scaling of epsP */ + Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ ) { Word16 i, k, p, dec, vad; @@ -270,12 +426,14 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech Word16 ishift[12] = {8,0,2,2,2,2,2,1,0,2,2,1}; Word16 tmp; Word16 tmp1,tmp2,exp2,scale,exp3; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ - vad = localVAD; + vad = localVAD_HE_SAD; move16(); /*------------------------------------------------------------------* @@ -284,14 +442,14 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech /* [0] OL pitch Q0 */ /*(float)(pitch[0] + pitch[1] + pitch[2]) / 3.0f;*/ - L_tmp = L_mult(pitch[0], 10923); - L_tmp = L_mac(L_tmp, pitch[1], 10923); - L_tmp = L_mac(L_tmp, pitch[2], 10923); + L_tmp = L_mult(st_fx->pitch_fx[0], 10923); + L_tmp = L_mac(L_tmp, st_fx->pitch_fx[1], 10923); + L_tmp = L_mac(L_tmp, st_fx->pitch_fx[2], 10923); test(); IF ( EQ_16(st_fx->tc_cnt_fx,1)||EQ_16(st_fx->tc_cnt_fx,2)) { - *pFV++ = pitch[2]; + *pFV++ = st_fx->pitch_fx[2]; move16(); } ELSE @@ -304,14 +462,14 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech test(); IF ( EQ_16(st_fx->tc_cnt_fx,1)||EQ_16(st_fx->tc_cnt_fx,2)) { - *pFV++ = voicing[2]; + *pFV++ = st_fx->voicing_fx[2]; move16(); } ELSE { - L_tmp = L_mult(voicing[0], 10923); - L_tmp = L_mac(L_tmp, voicing[1], 10923); - L_tmp = L_mac(L_tmp, voicing[2], 10923); + L_tmp = L_mult(st_fx->voicing_fx[0], 10923); + L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); + L_tmp = L_mac(L_tmp, st_fx->voicing_fx[2], 10923); *pFV++ = round_fx(L_tmp); } @@ -327,20 +485,20 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech { L_tmp = sub_lsp2lsf_fx(lsp[i]); tmp16 = round_fx(L_shl(L_mult0(extract_l(L_tmp),lsf2acos_fact),2)); - *pFV++ = add(tmp16,st_fx->last_lsp_fx[i]); + *pFV++ = add(tmp16, hSpMusClas->last_lsp_fx[i]); move16(); /*Q13*/ - st_fx->last_lsp_fx[i] = tmp16; + hSpMusClas->last_lsp_fx[i] = tmp16; move16(); } /* [7] cor_map_sum Q8 */ - *pFV++ = round_fx(L_mac(L_mult(cor_map_sum, 16384), st_fx->last_cor_map_sum_fx, 16384)); /* Q8 ->Q7*/ - st_fx->last_cor_map_sum_fx = cor_map_sum; + *pFV++ = round_fx(L_mac(L_mult(cor_map_sum, 16384), hSpMusClas->last_cor_map_sum_fx, 16384)); /* Q8 ->Q7*/ + hSpMusClas->last_cor_map_sum_fx = cor_map_sum; move16(); /* [8] non_sta Q8*/ - *pFV++ = round_fx(L_mac(L_mult(non_sta,16384), st_fx->last_non_sta_fx, 16384)); /* Q8 -> Q7 */ - st_fx->last_non_sta_fx = non_sta; + *pFV++ = round_fx(L_mac(L_mult(non_sta,16384), hSpMusClas->last_non_sta_fx, 16384)); /* Q8 -> Q7 */ + hSpMusClas->last_non_sta_fx = non_sta; move16(); /* [9] epsP Q10 */ @@ -382,11 +540,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech ftmp = round_fx(L_shl(L_tmp,10)); /*Q10 */ /**pFV++ = ftmp + st->past_epsP2;*/ - *pFV++ = add(ftmp,st_fx->past_epsP2_fx); + *pFV++ = add(ftmp, hSpMusClas->past_epsP2_fx); move16(); /*Q10 */ /*st->past_epsP2 = ftmp;*/ - st_fx->past_epsP2_fx = ftmp; + hSpMusClas->past_epsP2_fx = ftmp; move16(); /*Q10 */ } @@ -417,7 +575,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech tmp = div_s(tmp2, tmp1); /*Q(15+exp3) */ PS_norm[i] = L_shl(tmp,sub(10,exp3)); move32(); /*Q25 */ - dPS[i] = L_abs(L_sub(PS_norm[i],st_fx->past_PS_fx[i-LOWEST_FBIN])); + dPS[i] = L_abs(L_sub(PS_norm[i], hSpMusClas->past_PS_fx[i-LOWEST_FBIN])); move32(); /*Q25 */ } @@ -445,9 +603,9 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech move16(); /*Q10 */ } - *pFV++ = add(ps_diff_16, st_fx->past_ps_diff_fx); + *pFV++ = add(ps_diff_16, hSpMusClas->past_ps_diff_fx); move16();/*Q10 */ - st_fx->past_ps_diff_fx = ps_diff_16; + hSpMusClas->past_ps_diff_fx = ps_diff_16; move16(); /*Q10 */ /* [11] ps_sta (spectral stationarity) Q11 */ @@ -456,14 +614,14 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { /*mx = PS_norm[i] > st->past_PS[i] ? PS_norm[i] : st->past_PS[i];*/ - IF (GT_32(PS_norm[i],st_fx->past_PS_fx[i-LOWEST_FBIN])) + IF (GT_32(PS_norm[i], hSpMusClas->past_PS_fx[i-LOWEST_FBIN])) { mx = PS_norm[i]; move16(); /*Q25 */ } ELSE { - mx = st_fx->past_PS_fx[i-LOWEST_FBIN]; + mx = hSpMusClas->past_PS_fx[i-LOWEST_FBIN]; move16(); /*Q25 */ } @@ -504,7 +662,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech *pFV++ = round_fx(L_shl(L_tmp,11)); /*Q11 */ /* update PS vector */ - Copy32( &PS_norm[LOWEST_FBIN], st_fx->past_PS_fx, HIGHEST_FBIN-LOWEST_FBIN ); + Copy32( &PS_norm[LOWEST_FBIN], hSpMusClas->past_PS_fx, HIGHEST_FBIN-LOWEST_FBIN ); /*------------------------------------------------------------------* * Scaling of the feature vector @@ -623,8 +781,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech *high_lpn_flag_ptr = 0; move16(); test(); - if ( (GT_16(lpn, lps)) - && (GT_16(lpn, lpm)) ) + if ( GT_16(lpn, lps) && GT_16(lpn, lpm)) { *high_lpn_flag_ptr = 1; move16(); @@ -638,21 +795,23 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech lps = add(lpn,mult_r(6554,lpn)); /* Q9 */ } - st_fx->lpm_fx = lpm; + hSpMusClas->lpm_fx = lpm; move16(); - st_fx->lps_fx = lps; + hSpMusClas->lps_fx = lps; move16(); /* determine HQ GENERIC speech class */ - st_fx->hq_generic_speech_class_fx = 0; - move16(); - if( GT_16(lps,add(lpm,256))) + IF (hHQ_core != NULL) { - st_fx->hq_generic_speech_class_fx = 1; + hHQ_core->hq_generic_speech_class_fx = 0; move16(); + if (GT_16(lps, add(lpm, 256))) + { + hHQ_core->hq_generic_speech_class_fx = 1; + move16(); + } } - /*------------------------------------------------------------------* * State machine (sp_mus_state < 0 .. inactive, > 0 .. entry, = 0 .. active ) *------------------------------------------------------------------*/ @@ -664,85 +823,85 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech test(); IF ( LT_16(relE,-20*256)||(LE_16(lps,-5*512)&&LE_16(lpm,-5*512))) { - IF ( st_fx->sp_mus_state_fx > 0 ) + IF (hSpMusClas->sp_mus_state_fx > 0 ) { - if ( LT_16(st_fx->sp_mus_state_fx,HANG_LEN)) + if ( LT_16(hSpMusClas->sp_mus_state_fx,HANG_LEN)) { /* energy is too low but we are in entry period -> reset the inactive counter to allow new entry later */ - st_fx->inact_cnt_fx = 0; + hSpMusClas->inact_cnt_fx = 0; move16(); } /* energy is too low -> we are going to instable state */ - st_fx->sp_mus_state_fx = 0; + hSpMusClas->sp_mus_state_fx = 0; move16(); } - ELSE IF ( GT_16(st_fx->sp_mus_state_fx,-HANG_LEN)) + ELSE IF ( GT_16(hSpMusClas->sp_mus_state_fx,-HANG_LEN)) { /* energy is still too low -> we are still in instable state */ - st_fx->sp_mus_state_fx = sub(st_fx->sp_mus_state_fx,1); + hSpMusClas->sp_mus_state_fx = sub(hSpMusClas->sp_mus_state_fx,1); } } - ELSE IF ( st_fx->sp_mus_state_fx <= 0 ) + ELSE IF (hSpMusClas->sp_mus_state_fx <= 0 ) { - IF ( st_fx->inact_cnt_fx == 0 ) + IF (hSpMusClas->inact_cnt_fx == 0 ) { - st_fx->sp_mus_state_fx = 1; + hSpMusClas->sp_mus_state_fx = 1; move16(); } ELSE { - st_fx->sp_mus_state_fx = HANG_LEN; + hSpMusClas->sp_mus_state_fx = HANG_LEN; move16(); } - st_fx->inact_cnt_fx = 12; + hSpMusClas->inact_cnt_fx = 12; move16(); } - ELSE IF ( st_fx->sp_mus_state_fx > 0 && LT_16(st_fx->sp_mus_state_fx,HANG_LEN)) + ELSE IF (hSpMusClas->sp_mus_state_fx > 0 && LT_16(hSpMusClas->sp_mus_state_fx,HANG_LEN)) { /* we are inside an entry period -> increment the counter of entry frames */ - st_fx->sp_mus_state_fx = add(st_fx->sp_mus_state_fx,1); + hSpMusClas->sp_mus_state_fx = add(hSpMusClas->sp_mus_state_fx,1); } test(); - if ( st_fx->sp_mus_state_fx < 0 && st_fx->inact_cnt_fx > 0 ) + if (hSpMusClas->sp_mus_state_fx < 0 && hSpMusClas->inact_cnt_fx > 0 ) { - st_fx->inact_cnt_fx = sub(st_fx->inact_cnt_fx,1); + hSpMusClas->inact_cnt_fx = sub(hSpMusClas->inact_cnt_fx,1); } } ELSE { test(); - IF ( st_fx->sp_mus_state_fx > 0 && LT_16(st_fx->sp_mus_state_fx,HANG_LEN)) + IF (hSpMusClas->sp_mus_state_fx > 0 && LT_16(hSpMusClas->sp_mus_state_fx,HANG_LEN)) { - st_fx->inact_cnt_fx = 0; + hSpMusClas->inact_cnt_fx = 0; move16(); } - ELSE IF ( st_fx->inact_cnt_fx > 0 ) + ELSE IF (hSpMusClas->inact_cnt_fx > 0 ) { - st_fx->inact_cnt_fx = sub(st_fx->inact_cnt_fx,1); + hSpMusClas->inact_cnt_fx = sub(hSpMusClas->inact_cnt_fx,1); } test(); - IF ( st_fx->sp_mus_state_fx > 0 && LT_16(st_fx->sp_mus_state_fx,HANG_LEN)) + IF (hSpMusClas->sp_mus_state_fx > 0 && LT_16(hSpMusClas->sp_mus_state_fx,HANG_LEN)) { - st_fx->sp_mus_state_fx = -HANG_LEN; + hSpMusClas->sp_mus_state_fx = -HANG_LEN; move16(); } - ELSE IF ( st_fx->sp_mus_state_fx > 0 ) + ELSE IF (hSpMusClas->sp_mus_state_fx > 0 ) { - st_fx->sp_mus_state_fx = -1; + hSpMusClas->sp_mus_state_fx = -1; move16(); } - ELSE IF ( GT_16(st_fx->sp_mus_state_fx,-HANG_LEN)) + ELSE IF ( GT_16(hSpMusClas->sp_mus_state_fx,-HANG_LEN)) { /* we are in inactive state */ - st_fx->sp_mus_state_fx = sub(st_fx->sp_mus_state_fx,1); + hSpMusClas->sp_mus_state_fx = sub(hSpMusClas->sp_mus_state_fx,1); } } @@ -775,25 +934,25 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ test(); - IF ( dlp < 0 && LT_16(dlp,st_fx->past_dlp_fx[0])) + IF ( dlp < 0 && LT_16(dlp, hSpMusClas->past_dlp_fx[0])) { - IF ( st_fx->past_dlp_fx[0] > 0 ) + IF (hSpMusClas->past_dlp_fx[0] > 0 ) { - st_fx->wdrop_fx = negate(dlp); /*Q9*/ + hSpMusClas->wdrop_fx = negate(dlp); /*Q9*/ } ELSE { - st_fx->wdrop_fx = add(st_fx->wdrop_fx, sub(st_fx->past_dlp_fx[0], dlp)); /*Q9*/ + hSpMusClas->wdrop_fx = add(hSpMusClas->wdrop_fx, sub(hSpMusClas->past_dlp_fx[0], dlp)); /*Q9*/ } } ELSE { - st_fx->wdrop_fx = 0; + hSpMusClas->wdrop_fx = 0; move16(); } /*wdrop = st->wdrop/20;*/ - wdrop = mult_r(st_fx->wdrop_fx, 26214); /*Q9*Q19->Q13*/ + wdrop = mult_r(hSpMusClas->wdrop_fx, 26214); /*Q9*Q19->Q13*/ wdrop = s_min(wdrop,8192); /* limitation [0.1,1] Q13 */ wdrop = s_max(wdrop,819); @@ -805,12 +964,12 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech /* calculate weighted decision */ /*st->wdlp_0_95_sp = wght * dlp + (1 - wght) * st->wdlp_0_95_sp;*/ /* = Q9 * Q9 + (Q9-Q9)*Q9 */ - L_tmp = L_mac(L_mult(wght, dlp), sub(512, wght), st_fx->wdlp_0_95_sp_fx); - st_fx->wdlp_0_95_sp_fx = round_fx(L_shl(L_tmp, 6)); + L_tmp = L_mac(L_mult(wght, dlp), sub(512, wght), hSpMusClas->wdlp_0_95_sp_fx); + hSpMusClas->wdlp_0_95_sp_fx = round_fx(L_shl(L_tmp, 6)); - if ( EQ_16(st_fx->sp_mus_state_fx,-HANG_LEN)) + if ( EQ_16(hSpMusClas->sp_mus_state_fx,-HANG_LEN)) { - st_fx->wdlp_0_95_sp_fx = 0; + hSpMusClas->wdlp_0_95_sp_fx = 0; move16(); } @@ -820,25 +979,25 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech test(); test(); - IF ( !vad && EQ_16(st_fx->sp_mus_state_fx,-HANG_LEN)) + IF ( !vad && EQ_16(hSpMusClas->sp_mus_state_fx,-HANG_LEN)) { /* inactive state */ dec = 0; move16(); } - ELSE IF ( st_fx->sp_mus_state_fx <= 0 ) + ELSE IF (hSpMusClas->sp_mus_state_fx <= 0 ) { /* transition from active to inactive state or instable state */ - dec = st_fx->past_dec_fx[0]; + dec = hSpMusClas->past_dec_fx[0]; move16(); } - ELSE IF ( st_fx->sp_mus_state_fx > 0 && LT_16(st_fx->sp_mus_state_fx,HANG_LEN)) + ELSE IF (hSpMusClas->sp_mus_state_fx > 0 && LT_16(hSpMusClas->sp_mus_state_fx,HANG_LEN)) { /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ - L_tmp = L_mult(w_spmus_fx[st_fx->sp_mus_state_fx-1][0], dlp); /*Q15*Q9 */ + L_tmp = L_mult(w_spmus_fx[hSpMusClas->sp_mus_state_fx-1][0], dlp); /*Q15*Q9 */ /*ftmp += dotp( &w[st_fx->sp_mus_state_fx-1][1], st_fx->past_dlp_fx, HANG_LEN-1 );*/ - L_tmp = L_add(L_tmp, Dot_product( &w_spmus_fx[st_fx->sp_mus_state_fx-1][1], st_fx->past_dlp_fx, HANG_LEN-1 )); + L_tmp = L_add(L_tmp, Dot_product( &w_spmus_fx[hSpMusClas->sp_mus_state_fx-1][1], hSpMusClas->past_dlp_fx, HANG_LEN-1 )); logic16(); move16(); @@ -852,13 +1011,13 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech test(); test(); test(); - IF ( st_fx->wdlp_0_95_sp_fx > 0 && st_fx->past_dec_fx[0] == 0 && st_fx->past_dec_fx[1] == 0 && st_fx->past_dec_fx[2] == 0 ) + IF (hSpMusClas->wdlp_0_95_sp_fx > 0 && hSpMusClas->past_dec_fx[0] == 0 && hSpMusClas->past_dec_fx[1] == 0 && hSpMusClas->past_dec_fx[2] == 0 ) { /* switching from speech to music */ dec = 1; move16(); } - ELSE IF ( st_fx->past_dec_fx[0] == 1 && st_fx->wdlp_0_95_sp_fx < 0 ) + ELSE IF (hSpMusClas->past_dec_fx[0] == 1 && hSpMusClas->wdlp_0_95_sp_fx < 0 ) { /* switching from music to speech */ dec = 0; @@ -866,7 +1025,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech } ELSE { - dec = st_fx->past_dec_fx[0]; + dec = hSpMusClas->past_dec_fx[0]; move16(); } } @@ -877,13 +1036,13 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech *------------------------------------------------------------------*/ /* update the buffer of past non-binary decisions */ - Copy( &st_fx->past_dlp_fx[0], &st_fx->past_dlp_fx[1], HANG_LEN-2 ); - st_fx->past_dlp_fx[0] = dlp; + Copy( &hSpMusClas->past_dlp_fx[0], &hSpMusClas->past_dlp_fx[1], HANG_LEN-2 ); + hSpMusClas->past_dlp_fx[0] = dlp; move16(); /* update the buffer of past binary decisions */ - Copy( &st_fx->past_dec_fx[0], &st_fx->past_dec_fx[1], HANG_LEN-2 ); - st_fx->past_dec_fx[0] = dec; + Copy( &hSpMusClas->past_dec_fx[0], &hSpMusClas->past_dec_fx[1], HANG_LEN-2 ); + hSpMusClas->past_dec_fx[0] = dec; move16(); return dec; @@ -898,34 +1057,32 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech static void sp_mus_classif_2nd_fx( Encoder_State_fx *st, /* i/o: Encoder state structure */ - const Word16 sp_aud_decision1, /* i : 1st stage decision flag */ - Word16 *sp_aud_decision2, /* i/o: 2nd stage decision flag */ - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ const Word16 Etot, /* i : total frame energy */ - Word16 *coder_type, /* i/o: coder type */ Word16 *attack_flag, /* i/o: attack flag (GSC or TC) */ const Word16 *inp, /* i : input signal */ - const Word16 Qx, - const Word16 localVAD, - const Word16 vad_flag + const Word16 Qx ) { Word16 attack; + SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; /* initialization */ *attack_flag = 0; move16(); /* signal stability estimation */ - stab_est_fx( Etot, st->gsc_lt_diff_etot_fx, &st->gsc_mem_etot_fx - , &st->gsc_nb_thr_3_fx, &st->gsc_nb_thr_1_fx, st->gsc_thres_fx, &st->gsc_last_music_flag_fx, vad_flag ); + stab_est_fx( Etot, hSpMusClas->gsc_lt_diff_etot_fx, &hSpMusClas->gsc_mem_etot_fx + , &hSpMusClas->gsc_nb_thr_3_fx, &hSpMusClas->gsc_nb_thr_1_fx, hSpMusClas->gsc_thres_fx, &hSpMusClas->gsc_last_music_flag_fx, st->vad_flag ); /* calculate variance of correlation */ - var_cor_calc_fx( st->old_corr_fx, &st->mold_corr_fx, st->var_cor_t_fx, &st->high_stable_cor_fx ); + var_cor_calc_fx( st->old_corr_fx, &hSpMusClas->mold_corr_fx, hSpMusClas->var_cor_t_fx, &hSpMusClas->high_stable_cor_fx ); /* attack detection */ - attack = attack_det_fx( inp, Qx, st->clas_fx, localVAD, *coder_type - , st->total_brate_fx); + attack = attack_det_fx( inp, Qx, st->clas_fx, st->localVAD, st->coder_type, st->total_brate_fx +#ifdef IVAS_CODE + , EVS_MONO, st->clas_fx, hSpMusClas->finc_prev, &hSpMusClas->lt_finc, &hSpMusClas->last_strong_attack +#endif + ); test(); test(); @@ -933,41 +1090,41 @@ static void sp_mus_classif_2nd_fx( test(); test(); test(); - IF( EQ_16(sp_aud_decision1,1)) + IF( EQ_16(st->sp_aud_decision1,1)) { test(); test(); test(); - IF( LT_16(st->ener_RAT_fx,5898)&>_16(st->lt_dec_thres_fx,7680)) + IF( LT_16(hSpMusClas->ener_RAT_fx,5898) && GT_16(hSpMusClas->lt_dec_thres_fx,7680)) { - *sp_aud_decision2 = 0; + st->sp_aud_decision2 = 0; move16(); } - ELSE IF( EQ_16(st->high_stable_cor_fx, 1)&&GE_16(pitch[0],130)) + ELSE IF( EQ_16(hSpMusClas->high_stable_cor_fx, 1)&&GE_16(st->pitch_fx[0],130)) { /* prevent GSC in highly correlated signal with low energy variation */ /* this is basically a patch against bassoon-type of music */ - *sp_aud_decision2 = 0; + st->sp_aud_decision2 = 0; move16(); test(); - IF( EQ_16(st->codec_mode,MODE1)&&EQ_16(*coder_type,TRANSITION)) + IF( EQ_16(st->codec_mode,MODE1)&&EQ_16(st->coder_type,TRANSITION)) { - *coder_type = GENERIC; + st->coder_type = GENERIC; move16(); } } - ELSE IF( GT_16(st->gsc_lt_diff_etot_fx[MAX_LT-1],1152)&& - GT_16(sub(st->gsc_lt_diff_etot_fx[MAX_LT-1], st->gsc_lt_diff_etot_fx[MAX_LT-2]),2560)) /* 10.0f in Q8 */ + ELSE IF( GT_16(hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-1],1152) && + GT_16(sub(hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-1], hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT-2]),2560)) /* 10.0f in Q8 */ { IF ( EQ_16(st->tc_cnt_fx,1)) { - *sp_aud_decision2 = 0; + st->sp_aud_decision2 = 0; move16(); IF( EQ_16(st->codec_mode,MODE1)) { - *coder_type = TRANSITION; + st->coder_type = TRANSITION; move16(); } } @@ -976,13 +1133,13 @@ static void sp_mus_classif_2nd_fx( IF( GE_16(attack, ATT_3LSUB_POS)) { /* do TC coding if attack is located in the last subframe */ - *sp_aud_decision2 = 0; + st->sp_aud_decision2 = 0; move16(); - *attack_flag = 1; + *attack_flag = add(attack, 1); move16(); IF( EQ_16(st->codec_mode,MODE1)) { - *coder_type = TRANSITION; + st->coder_type = TRANSITION; move16(); } } @@ -990,200 +1147,1160 @@ static void sp_mus_classif_2nd_fx( { /* do GSC coding if attack is located after the first quarter of the first subframe */ /* (pre-echo will be treated at the decoder side) */ - *attack_flag = 1; + st->sp_aud_decision2 = 1; + *attack_flag = 31; + move16(); + move16(); + } + } + } + } + ELSE IF( EQ_16(st->localVAD,1)&&EQ_16(st->coder_type,GENERIC)&& + ( (GE_16(attack,ATT_3LSUB_POS) && LT_32(st->total_brate_fx,ACELP_24k40)) || + (GE_16(attack,ATT_3LSUB_POS_16k) && GE_32(st->total_brate_fx,ACELP_24k40) && LT_32(st->total_brate_fx,ACELP_48k)) ) + ) + { + /* do TC coding if attack is located in the last subframe */ + *attack_flag = add(attack, 1); + move16(); + IF( EQ_16(st->codec_mode,MODE1)) + { + st->coder_type = TRANSITION; + move16(); + } + } + + return; +} + + +/*---------------------------------------------------------------------* + * var_cor_calc_fx() + * + * Calculate variance of correlation + *---------------------------------------------------------------------*/ + +static void var_cor_calc_fx( + const Word16 old_corr, + Word16 *mold_corr, + Word16 var_cor_t[], + Word16 *high_stable_cor +) +{ + Word16 i, var_cor; + + /* update buffer of old correlation values */ + FOR( i = VAR_COR_LEN-1; i > 0; i-- ) + { + var_cor_t[i] = var_cor_t[i-1]; /*Q11*/ move16(); + } + var_cor_t[i] = old_corr; + move16(); + + /* calculate variance of correlation */ + var_cor = var_fx( var_cor_t, 11, VAR_COR_LEN ); + + *high_stable_cor = 0; + move16(); + test(); + IF( GT_16(*mold_corr,26214)&<_16(var_cor,2)) + { + *high_stable_cor = 1; + move16(); + } + + /* update average correlation */ + /*st->mold_corr = 0.1f * st->old_corr + 0.9f * st->mold_corr;*/ + *mold_corr = mac_r(L_mult(3277,old_corr),29491,*mold_corr); /*Q15 */ + + return; +} + +/*---------------------------------------------------------------------* + * attack_det_fx() + * + * Attack detection + *---------------------------------------------------------------------*/ + +static Word16 attack_det_fx( /* o : attack flag */ + const Word16 *inp, /* i : input signal */ + const Word16 Qx, + const Word16 last_clas, /* i : last signal clas */ + const Word16 localVAD, /* i : local VAD flag */ + const Word16 coder_type, /* i : coder type */ + const Word32 total_brate /* i : total bitrate */ +#ifdef IVAS_CODE + , + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 clas, /* i : signal class */ + Word32 finc_prev[], /* i/o: previous finc */ + Word32* lt_finc, /* i/o: long-term mean finc */ + Word16* last_strong_attack /* i/o: last strong attack flag */ +#endif +) +{ + Word16 i, j, tmp, tmp1, attack, exp1; + Word32 L_tmp, etmp, etmp2, finc[ATT_NSEG]; + Word16 att_3lsub_pos; + Word16 attack1; + + att_3lsub_pos = ATT_3LSUB_POS; + move16(); + if( GE_32(total_brate,ACELP_24k40)) + { + att_3lsub_pos = ATT_3LSUB_POS_16k; + move16(); + } + + /* compute energy per section */ + FOR( i=0; i 0 ) + { + etmp2 = L_add(finc[attack], 0); + etmp = Mult_32_16(etmp2, 16384); /* etmp2 / 2.0 = (etmp2*0.5) */ + FOR( i=2; itotal_brate_fx,ACELP_24k40)) || - (GE_16(attack,ATT_3LSUB_POS_16k) && GE_32(st->total_brate_fx,ACELP_24k40) && LT_32(st->total_brate_fx,ACELP_48k)) ) - ) - { - /* do TC coding if attack is located in the last subframe */ - *attack_flag = 1; - move16(); - IF( EQ_16(st->codec_mode,MODE1)) +#ifdef IVAS_CODE + test();test();test(); + IF (attack == 0 && GT_16(element_mode, EVS_MONO) && (LT_16(clas, VOICED_TRANSITION) || EQ_16(clas, ONSET))) + { + Copy32(finc, finc_prev, attack1); + + /* compute mean energy before the attack */ + etmp = L_shr(sum32_fx(finc_prev, ATT_NSEG),5); /*ATT_NSEG == 32*/ + + etmp2 = finc[attack1]; + move32(); + test();test(); + if ( (LT_32(L_shl(etmp, 4), etmp2)) || (LT_32(L_mult0(etmp, 12), etmp2) && EQ_16(last_clas, UNVOICED_CLAS))) + { + attack = attack1; + move16(); + } + PMT("Size of lf_finc not verified yet") + test(); + if ( GT_32(L_mult0(20, *lt_finc), etmp2) || *last_strong_attack) /*lt_finc assumes same Q as etmp2, TBV!!!! */ + { + attack = 0; + move16(); + } + } + *last_strong_attack = attack; + move16(); +#endif + } + ELSE IF( attack > 0 ) + { + etmp2 = L_add(finc[attack], 0); + etmp = Mult_32_16(etmp2, 25206); /* etmp2 / 1.3 = (etmp2*0.76923) */ + FOR( i=2; i etmp2 ) -> finc[i] > (etmp2*0.76923) */ + test(); + IF( NE_16(i,attack)&>_32(finc[i],etmp)) + { + attack = 0; + move16(); + BREAK; + } + } +#ifdef IVAS_CODE + *last_strong_attack = 0; +#endif + move16(); + } + + return attack; +} +#ifdef IVAS_CODE +/* -------------------------------------------------------------------- - * + *ivas_smc_gmm() + * + *1st stage of the speech / music classification(based on the GMM model) + * -------------------------------------------------------------------- - */ + /*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ +int16_t ivas_smc_gmm( + Encoder_State * st, /* i/o: state structure */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const float Etot, /* i : total frame energy */ + const float lsp_new[M], /* i : LSPs in current frame */ + const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */ + const float epsP[M + 1], /* i : LP prediciton error */ + const float PS[], /* i : energy spectrum */ + const float non_sta, /* i : unbound non-stationarity */ + const float relE, /* i : relative frame energy */ + int16_t * high_lpn_flag, /* i/o: sp/mus LPN flag */ + const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ +) +{ + int16_t i, m, dec; + int16_t flag_odv; + float lps, lpm, lpn; + float ps[N_SMC_MIXTURES], pm[N_SMC_MIXTURES], pn[N_SMC_MIXTURES]; + float fvm[N_PCA_COEF], lprob; + float dlp, ftmp, sum_PS, ps_diff, ps_sta, wrelE, wdrop, wght; + float wrise; + float dlp_mean2var; + float FV[N_SMC_FEATURES], * pFV, PS_norm[128], dPS[128]; + const float* pODV; + float* pFV_st, smc_st_mean_fact; + int16_t relE_attack_flag; + int16_t j, len; + const float* pt_mel_fb; + float melS[NB_MEL_BANDS], mfcc[NB_MEL_BANDS]; + int16_t odv_cnt; + int16_t i_out[N_SMC_FEATURES], * p_out; + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; + + /*------------------------------------------------------------------* + * State machine (sp_mus_state: -8 = INACTIVE, -7:-1 = UNSTABLE, 0:7 = ENTRY, 8 = STABLE ) + *------------------------------------------------------------------*/ + + if (localVAD_HE_SAD) + { + if (relE < -20) + { + if (hSpMusClas->sp_mus_state > 0) + { + if (hSpMusClas->sp_mus_state < HANG_LEN) + { + /* energy is too low but we are in entry period -> reset the inactive counter to allow new entry later */ + hSpMusClas->inact_cnt = 0; + } + + /* energy is too low -> we are going to instable state */ + hSpMusClas->sp_mus_state = 0; + } + else if (hSpMusClas->sp_mus_state > -HANG_LEN) + { + /* energy is still too low -> we are still in instable state */ + hSpMusClas->sp_mus_state--; + } + } + else if (hSpMusClas->sp_mus_state <= 0) + { + if (hSpMusClas->inact_cnt == 0) + { + + hSpMusClas->sp_mus_state = 1; + } + else + { + + hSpMusClas->sp_mus_state = HANG_LEN; + } + + hSpMusClas->inact_cnt = 12; + } + else if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + { + /* we are inside an entry period -> increment the counter of entry frames */ + hSpMusClas->sp_mus_state++; + } + + if (hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0) + { + hSpMusClas->inact_cnt--; + } + } + else + { + if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + { + hSpMusClas->inact_cnt = 0; + } + else if (hSpMusClas->inact_cnt > 0) + { + hSpMusClas->inact_cnt--; + } + + if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + { + hSpMusClas->sp_mus_state = -HANG_LEN; + } + else if (hSpMusClas->sp_mus_state > 0) + { + hSpMusClas->sp_mus_state = -1; + } + else if (hSpMusClas->sp_mus_state > -HANG_LEN) + { + /* we are in inactive state */ + hSpMusClas->sp_mus_state--; + } + } + + /* detect attacks based on relE */ + if (relE > hSpMusClas->prev_relE) + { + hSpMusClas->relE_attack_sum += relE - hSpMusClas->prev_relE; + } + else + { + hSpMusClas->relE_attack_sum = 0; + } + hSpMusClas->prev_relE = relE; + + /* update counter from last VAD 0->1 change */ + if (hSpMusClas->prev_vad == 0 && localVAD_HE_SAD == 1) + { + hSpMusClas->vad_0_1_cnt = 1; + } + else if (localVAD_HE_SAD == 1 && hSpMusClas->vad_0_1_cnt > 0 && hSpMusClas->vad_0_1_cnt < 50) + { + hSpMusClas->vad_0_1_cnt++; + } + else + { + hSpMusClas->vad_0_1_cnt = 0; + } + hSpMusClas->prev_vad = localVAD_HE_SAD; + + if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && hSpMusClas->relE_attack_sum > 5.0f) + { + hSpMusClas->relE_attack_cnt++; + + /* set flag only in the first X frames in a series */ + if (hSpMusClas->relE_attack_cnt > 0 && hSpMusClas->relE_attack_cnt < 3) + { + relE_attack_flag = 1; + } + else + { + relE_attack_flag = 0; + } + } + else + { + hSpMusClas->relE_attack_cnt = 0; + relE_attack_flag = 0; + } + + hSpMusClas->prev_Etot = Etot; + + /*------------------------------------------------------------------* + * Preparation of the feature vector + *------------------------------------------------------------------*/ + + pFV = FV; + + /* [0] OL pitch */ + if (relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2) + { + *pFV++ = (float)st->pitch[2]; + } + else + { + *pFV++ = (float)(st->pitch[0] + st->pitch[1] + st->pitch[2]) / 3.0f; + } + + /* [1] voicing */ + if (relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2) + { + *pFV++ = st->voicing[2]; + } + else + { + *pFV++ = (st->voicing[0] + st->voicing[1] + st->voicing[2]) / 3.0f; + } + + /* [2,3,4,5,6] LSFs */ + *pFV++ = acosf(lsp_new[2]); + *pFV++ = acosf(lsp_new[3]); + *pFV++ = acosf(lsp_new[4]); + *pFV++ = acosf(lsp_new[5]); + *pFV++ = acosf(lsp_new[6]); + + /* [7] cor_map_sum */ + *pFV++ = cor_map_sum; + + /* [8] non_sta */ + *pFV++ = non_sta; + + /* [9] epsP */ + *pFV++ = logf(epsP[14] + 1e-5f) - logf(epsP[0] + 1e-5f); + + /* [10,11,12] MFCCs */ + set_zero(melS, NB_MEL_BANDS); + pt_mel_fb = mel_fb; + for (i = 0; i < NB_MEL_BANDS; i++) + { + j = mel_fb_start[i]; + len = mel_fb_len[i]; + melS[i] = logf(dotp(&PS[j], pt_mel_fb, len) + 1e-5f); + pt_mel_fb += len; + } + + v_mult_mat(mfcc, melS, dct_mtx, NB_MEL_BANDS, NB_MEL_COEF); + + *pFV++ = mfcc[2]; + *pFV++ = mfcc[6]; + *pFV++ = mfcc[12]; + + /* calculation of differential normalized power spectrum */ + sum_PS = 1e-5f; + for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + { + sum_PS += PS[i]; + } + + for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + { + PS_norm[i] = PS[i] / sum_PS; + dPS[i] = fabsf(PS_norm[i] - hSpMusClas->past_PS[i - LOWEST_FBIN]); + } + + /* [13] ps_diff (spectral difference) */ + ps_diff = 0; + for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + { + ps_diff += dPS[i]; + } + + *pFV++ = ps_diff; + + /* [14] ps_sta (spectral stationarity) */ + ps_sta = 0; + for (i = LOWEST_FBIN; i < HIGHEST_FBIN; i++) + { + if (PS_norm[i] > hSpMusClas->past_PS[i - LOWEST_FBIN]) + { + ps_sta += PS_norm[i] / (dPS[i] + 1e-5f); + } + else + { + ps_sta += hSpMusClas->past_PS[i - LOWEST_FBIN] / (dPS[i] + 1e-5f); + } + } + + *pFV++ = logf(ps_sta + 1e-5f); + mvr2r(&PS_norm[LOWEST_FBIN], hSpMusClas->past_PS, HIGHEST_FBIN - LOWEST_FBIN); + + /* save ps_diff and ps_sta features for XTALK and UNCLR classifier */ + if (hStereoClassif != NULL) + { + if (st->idchan == 0) + { + hStereoClassif->ps_diff_ch1 = ps_diff; + hStereoClassif->ps_sta_ch1 = logf(ps_sta + 1e-5f); + } + else + { + hStereoClassif->ps_diff_ch2 = ps_diff; + hStereoClassif->ps_sta_ch2 = logf(ps_sta + 1e-5f); + } + } + + /*------------------------------------------------------------------* + * Outlier detection based on feature histograms + *------------------------------------------------------------------*/ + + flag_odv = 0; + if (localVAD_HE_SAD) + { + pFV = FV; + pODV = hout_intervals; + p_out = i_out; + odv_cnt = 0; + for (i = 0; i < N_SMC_FEATURES; i++) + { + if (*pFV < pODV[0] || *pFV > pODV[1]) + { + *p_out++ = i; + odv_cnt++; + } + + pFV++; + pODV += 2; + } + + /* set outlier flag */ + if (odv_cnt >= 2) + { + flag_odv = 1; + + /* replace outlying features with values from the previous frame */ + for (i = 0; i < odv_cnt; i++) + { + FV[i_out[i]] = hSpMusClas->prev_FV[i_out[i]]; + } + } + } + + /*------------------------------------------------------------------* + * Adaptive short-term mean filter on feature vector + *------------------------------------------------------------------*/ + + pFV = FV; + pFV_st = hSpMusClas->FV_st; + smc_st_mean_fact = SMC_ST_MEAN_FACT; + for (i = 0; i < N_SMC_FEATURES; i++) + { + *pFV_st = smc_st_mean_fact * (*pFV_st) + (1 - smc_st_mean_fact) * (*pFV); + + if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && (relE_attack_flag || flag_odv)) + { + /* strong attack or outlier frame during entry state -> features cannot be trusted but there is also no useful past info -> */ + /* -> do whatever you want because dlp will be reset to 0 anyway */ + pFV++; + pFV_st++; + } + else if (hSpMusClas->sp_mus_state == HANG_LEN && (st->tc_cnt == 1 || st->tc_cnt == 2)) + { + /* energy attack in stable state -> use current features intead of the long-term average */ + pFV++; + pFV_st++; + } + else + { + *pFV++ = *pFV_st++; + } + } + + /* update */ + mvr2r(FV, hSpMusClas->prev_FV, N_SMC_FEATURES); + + /*------------------------------------------------------------------* + * Non-linear power transformation (boxcox) on certain features + *------------------------------------------------------------------*/ + + pFV = FV; + for (i = 0; i < N_SMC_FEATURES; i++) + { + if (bcox_lmbd[i] != 0) + { + *pFV -= bcox_add_cnst[i]; + if (*pFV < 1) + { + *pFV = 1; + } + *pFV = (powf(*pFV, bcox_lmbd[i]) - 1) / bcox_lmbd[i]; + } + + pFV++; + } + + /*------------------------------------------------------------------* + * Scaling of the feature vector + * PCA + *------------------------------------------------------------------*/ + + pFV = FV; + for (i = 0; i < N_SMC_FEATURES; i++) + { + /* Standard scaler - mean and variance normalization */ + *pFV = (*pFV - sm_means[i]) / sm_scale[i]; + pFV++; + + /* MinMax sclaer - mean and variance normalization */ + /**pFV = *pFV * sm_scale[i] + sm_min[i];*/ + /*pFV++;*/ + } + + /* PCA */ + v_sub(FV, pca_mean_, FV, N_SMC_FEATURES); + v_mult_mat(FV, FV, pca_components_, N_SMC_FEATURES, N_PCA_COEF); + + /*------------------------------------------------------------------* + * Calculation of posterior probability + * Log-probability + *------------------------------------------------------------------*/ + + /* run loop for all mixtures (for each mixture, calculate the probability of speech, music and noise) */ + lps = lpm = lpn = 0; + for (m = 0; m < N_SMC_MIXTURES; m++) + { + v_sub(FV, &means_speech[m * N_PCA_COEF], fvm, N_PCA_COEF); + lprob = dot_product_cholesky(fvm, &prec_chol_speech[m * (N_PCA_COEF * N_PCA_COEF + N_PCA_COEF) / 2], N_PCA_COEF); + ps[m] = logf(weights_speech[m]) + log_det_chol_speech[m] - 0.5f * N_PCA_COEF * logf(PI2) - 0.5f * lprob; + + v_sub(FV, &means_music[m * N_PCA_COEF], fvm, N_PCA_COEF); + lprob = dot_product_cholesky(fvm, &prec_chol_music[m * (N_PCA_COEF * N_PCA_COEF + N_PCA_COEF) / 2], N_PCA_COEF); + pm[m] = logf(weights_music[m]) + log_det_chol_music[m] - 0.5f * N_PCA_COEF * logf(PI2) - 0.5f * lprob; + + v_sub(FV, &means_noise[m * N_PCA_COEF], fvm, N_PCA_COEF); + lprob = dot_product_cholesky(fvm, &prec_chol_noise[m * (N_PCA_COEF * N_PCA_COEF + N_PCA_COEF) / 2], N_PCA_COEF); + pn[m] = logf(weights_noise[m]) + log_det_chol_noise[m] - 0.5f * N_PCA_COEF * logf(PI2) - 0.5f * lprob; + } + + lps = logsumexp(ps, N_SMC_MIXTURES); + lpm = logsumexp(pm, N_SMC_MIXTURES); + lpn = logsumexp(pn, N_SMC_MIXTURES); + + *high_lpn_flag = 0; + if (lpn > lps && lpn > lpm) + { + *high_lpn_flag = 1; + } + + hSpMusClas->lpm = lpm; + hSpMusClas->lps = lps; + hSpMusClas->lpn = lpn; + + /* determine HQ Generic speech class */ + if (st->hHQ_core != NULL) + { + if (lps > lpm + 0.5f) + { + st->hHQ_core->hq_generic_speech_class = 1; + } + else + { + st->hHQ_core->hq_generic_speech_class = 0; + } + } + + /*------------------------------------------------------------------* + * Decision without hangover + * Weighted decision + *------------------------------------------------------------------*/ + + /* decision without hangover (0 - speech/noise, 1 - music) */ + if (!localVAD_HE_SAD || Etot < 10 || (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && (relE_attack_flag || flag_odv))) + { + dlp = 0; + } + else + { + dlp = lpm - lps + DLP_BIAS; + + if (dlp > 30.0f) + { + dlp = 30.0f; + } + else if (dlp < -30.0f) + { + dlp = -30.0f; + } + } + + dec = dlp > 0; + + /* calculate weight based on relE (higher relE -> lower weight, lower relE -> higher weight) */ + wrelE = lin_interp(relE, 15.0f, 0.9f, -15.0f, 0.99f, 1); + + /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ + hSpMusClas->dlp_mean_ST = 0.8f * hSpMusClas->dlp_mean_ST + 0.2f * dlp; + hSpMusClas->lt_dec_thres = hSpMusClas->dlp_mean_ST; + + if (dlp < 0 && dlp < hSpMusClas->dlp_mean_ST) + { + if (hSpMusClas->dlp_mean_ST > 0) + { + hSpMusClas->wdrop = -dlp; + } + else if (hSpMusClas->wdrop > 0) + { + hSpMusClas->wdrop += hSpMusClas->dlp_mean_ST - dlp; + } + } + else + { + hSpMusClas->wdrop = 0; + } + + wdrop = lin_interp(hSpMusClas->wdrop, 15.0f, 0.7f, 0.0f, 1.0f, 1); + + /* calculate weight based on rises of dlp (close to 1 during sudden rise of dlp, close to 0 otherwise) */ + if (hSpMusClas->sp_mus_state == HANG_LEN && hSpMusClas->dlp_mean_ST > 0 && hSpMusClas->dlp_mean_ST > hSpMusClas->past_dlp_mean_ST[0]) + { + if (hSpMusClas->past_dlp_mean_ST[0] < 0) + { + hSpMusClas->wrise = hSpMusClas->dlp_mean_ST; + } + else if (hSpMusClas->wrise > 0) + { + hSpMusClas->wrise += hSpMusClas->dlp_mean_ST - hSpMusClas->past_dlp_mean_ST[0]; + } + } + else + { + hSpMusClas->wrise = 0; + } + + wrise = lin_interp(hSpMusClas->wrise, 5.0f, 0.95f, 0.0f, 1.0f, 1); + + /* combine weights into one */ + wght = wrelE * wdrop * wrise; + + /* ratio of delta means vs. delta variances */ + if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + { + hSpMusClas->dlp_mean_LT = dlp; + hSpMusClas->dlp_var_LT = 0; + } + + hSpMusClas->dlp_mean_LT = 0.9f * hSpMusClas->dlp_mean_LT + 0.1f * dlp; + ftmp = dlp - hSpMusClas->dlp_mean_LT; + hSpMusClas->dlp_var_LT = 0.9f * hSpMusClas->dlp_var_LT + 0.1f * (ftmp * ftmp); + + if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + { + dlp_mean2var = 0; + } + else + { + dlp_mean2var = fabsf(hSpMusClas->dlp_mean_LT) / (sqrtf(fabsf(hSpMusClas->dlp_var_LT)) + 1.0f); + } + + if (dlp_mean2var > 15.0f) + { + /* decrease the weight little bit when the classifier indicates "strong speech" or "strong music" */ + wght *= 0.9f; + } + + if (wght > 1.0f) + { + wght = 1.0f; + } + else if (wght < 0.01f) + { + wght = 0.01f; + } + + if (Etot < 10) + { + /* silence */ + wght = 0.92f; + } + + /* calculate weighted decision */ + hSpMusClas->wdlp_0_95_sp = wght * hSpMusClas->wdlp_0_95_sp + (1 - wght) * dlp; + + /* xtalk classifier: apply long hysteresis to prevent LRTD on music */ + hSpMusClas->wdlp_xtalk = 0.995f * hSpMusClas->wdlp_xtalk + 0.005f * dlp; + + /*------------------------------------------------------------------* + * Final speech/music decision + *------------------------------------------------------------------*/ + + if (flag_spitch) + { + hSpMusClas->flag_spitch_cnt = 5; + } + else if (hSpMusClas->flag_spitch_cnt > 0) + { + hSpMusClas->flag_spitch_cnt--; + } + + if (Etot < 10) + { + /* silence */ + dec = 0; + } + else if (hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN) + { + /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ + ftmp = w_spmus[hSpMusClas->sp_mus_state - 1][0] * dlp; + ftmp += dotp(&w_spmus[hSpMusClas->sp_mus_state - 1][1], hSpMusClas->past_dlp, HANG_LEN - 1); + if (ftmp > 2.0f) + { + if (dlp > 2.0f) + { + dec = 2; + } + else + { + dec = 1; + } + } + else + { + dec = 0; + } + } + else + { + /* stable active state */ + if (hSpMusClas->past_dec[0] == 0 && hSpMusClas->past_dec[1] == 0 && hSpMusClas->past_dec[2] == 0 && + ((hSpMusClas->flag_spitch_cnt > 0 && hSpMusClas->wdlp_0_95_sp > 3.4f) || (hSpMusClas->flag_spitch_cnt == 0 && hSpMusClas->wdlp_0_95_sp > 2.1f))) + { + /* switching from speech to unclear */ + dec = 1; + } + else if (hSpMusClas->past_dec[0] == 0 && hSpMusClas->vad_0_1_cnt < 50 && hSpMusClas->relE_attack_sum == 0.0f && hSpMusClas->wdlp_0_95_sp > 1.0f) + { + /* switch from speech to unclear also during slowly rising weak music onsets */ + dec = 1; + } + else if (hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp > 2.5f) + { + /* switching from unclear to music */ + dec = 2; + } + else if (hSpMusClas->past_dec[0] == 2 && hSpMusClas->past_dec[1] == 2 && hSpMusClas->past_dec[2] == 2 && hSpMusClas->wdlp_0_95_sp < -1.0f) + { + /* switching from music to unclear */ + dec = 1; + } + else if (hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp < -2.5f) + { + /* switching from unclear to speech */ + dec = 0; + } + else { - *coder_type = TRANSITION; - move16(); + dec = hSpMusClas->past_dec[0]; } } - return; -} + /*------------------------------------------------------------------* + * raw S/M decision based on smoothed GMM score + *------------------------------------------------------------------*/ + + if (dec == 0 || st->hSpMusClas->wdlp_0_95_sp <= 0) + { + st->sp_aud_decision0 = 0; + st->sp_aud_decision1 = 0; + } + else + { + st->sp_aud_decision0 = 1; + st->sp_aud_decision1 = 1; + } + + /*------------------------------------------------------------------* + * Updates + *------------------------------------------------------------------*/ + + /* update buffer of past non-binary decisions */ + mvr2r(&hSpMusClas->past_dlp[0], &hSpMusClas->past_dlp[1], HANG_LEN - 2); + hSpMusClas->past_dlp[0] = dlp; + + mvr2r(&hSpMusClas->past_dlp_mean_ST[0], &hSpMusClas->past_dlp_mean_ST[1], HANG_LEN - 2); + hSpMusClas->past_dlp_mean_ST[0] = hSpMusClas->dlp_mean_ST; + /* update buffer of past binary decisions */ + mvs2s(&hSpMusClas->past_dec[0], &hSpMusClas->past_dec[1], HANG_LEN - 2); + hSpMusClas->past_dec[0] = dec; + +#ifdef DEBUG_MODE_INFO + dbgwrite(&st->hSpMusClas->wdlp_0_95_sp, sizeof(float), 1, 1, "res/wdlp_0_95_sp.x"); +#endif + + return dec; +} /*---------------------------------------------------------------------* - * var_cor_calc_fx() + * ivas_smc_mode_selection() * - * Calculate variance of correlation + * 2nd stage speech/music classifier (select coding mode (ACELP, GSC and TCX) based on S/M classification) + * output (sp_aud_decision1 - sp_aud_decision2 -> coding mode): + * 0 - 0 -> ACELP + * 1 - 0 -> GSC + * 1 - 1 -> TCX *---------------------------------------------------------------------*/ -static void var_cor_calc_fx( - const Word16 old_corr, - Word16 *mold_corr, - Word16 var_cor_t[], - Word16 *high_stable_cor +void ivas_smc_mode_selection( + Encoder_State* st, /* i/o: encoder state structure */ + const int32_t element_brate, /* i : element bitrate */ + int16_t smc_dec, /* i : raw decision of the 1st stage classifier*/ + const float relE, /* i : relative frame energy */ + const float Etot, /* i : total frame energy */ + int16_t* attack_flag, /* i/o: attack flag (GSC or TC) */ + const float* inp, /* i : input signal */ + const float S_map[], /* i : short-term correlation map */ + const int16_t flag_spitch /* i : flag to indicate very short stable pitch*/ ) { - Word16 i, var_cor; + int16_t attack; + float ton; + int16_t i; + float S_p2a, S_max, S_ave; + float thr_sp2a; - /* update buffer of old correlation values */ - FOR( i = VAR_COR_LEN-1; i > 0; i-- ) - { - var_cor_t[i] = var_cor_t[i-1]; /*Q11*/ move16(); - } - var_cor_t[i] = old_corr; - move16(); + SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; + + /* initialization */ + *attack_flag = 0; + st->sp_aud_decision2 = 0; + + /* signal stability estimation */ + stab_est(Etot, hSpMusClas->gsc_lt_diff_etot, &hSpMusClas->gsc_mem_etot, &hSpMusClas->gsc_nb_thr_3, &hSpMusClas->gsc_nb_thr_1, hSpMusClas->gsc_thres, &hSpMusClas->gsc_last_music_flag, st->vad_flag); /* calculate variance of correlation */ - var_cor = var_fx( var_cor_t, 11, VAR_COR_LEN ); + var_cor_calc(st->old_corr, &hSpMusClas->mold_corr, hSpMusClas->var_cor_t, &hSpMusClas->high_stable_cor); - *high_stable_cor = 0; - move16(); - test(); - IF( GT_16(*mold_corr,26214)&<_16(var_cor,2)) - { - *high_stable_cor = 1; - move16(); - } + /* attack detection */ + attack = attack_det(inp, st->clas, st->localVAD, st->coder_type, 0, st->element_mode, st->clas, hSpMusClas->finc_prev, &hSpMusClas->lt_finc, &hSpMusClas->last_strong_attack); - /* update average correlation */ - /*st->mold_corr = 0.1f * st->old_corr + 0.9f * st->mold_corr;*/ - *mold_corr = mac_r(L_mult(3277,old_corr),29491,*mold_corr); /*Q15 */ + /* tonal detector */ + ton = tonal_det(S_map, st->vad_flag, hSpMusClas->tod_S_map_lt, &hSpMusClas->tod_thr_lt, &hSpMusClas->tod_weight, &hSpMusClas->tod_S_mass_prev, &hSpMusClas->tod_S_mass_lt); - return; -} -/*---------------------------------------------------------------------* - * attack_det_fx() - * - * Attack detection - *---------------------------------------------------------------------*/ + /* calculate spectral peak-to-average ratio */ + for (i = 0; i < TOD_NSPEC; i++) + { + st->hSpMusClas->tod_lt_Bin_E[i] = P2A_FACT * st->hSpMusClas->tod_lt_Bin_E[i] + (1 - P2A_FACT) * st->Bin_E[i]; + } -static Word16 attack_det_fx( /* o : attack flag */ - const Word16 *inp, /* i : input signal */ - const Word16 Qx, - const Word16 last_clas, /* i : last signal clas */ - const Word16 localVAD, - const Word16 coder_type /* i : coder type */ - ,const Word32 total_brate /* i : total bit-rate */ -) -{ - Word16 i, j, tmp, tmp1, attack, exp1; - Word32 L_tmp, etmp, etmp2, finc[ATT_NSEG]; - Word16 att_3lsub_pos; + maximum(st->hSpMusClas->tod_lt_Bin_E, TOD_NSPEC, &S_max); + S_ave = sum_f(st->hSpMusClas->tod_lt_Bin_E, TOD_NSPEC) / TOD_NSPEC; + S_p2a = S_max - S_ave; - att_3lsub_pos = ATT_3LSUB_POS; - move16(); - if( GE_32(total_brate,ACELP_24k40)) + + thr_sp2a = THR_P2A; + if (element_brate <= IVAS_16k4) { - att_3lsub_pos = ATT_3LSUB_POS_16k; - move16(); + thr_sp2a = THR_P2A_HIGH; } - /* compute energy per section */ - FOR( i=0; i -10.0f && (S_p2a > thr_sp2a || ton > hSpMusClas->tod_thr_lt)) { - L_tmp = L_mult0(inp[i*ATT_SEG_LEN],inp[i*ATT_SEG_LEN]); /*2*Qx */ + /* select TCX to encode extremely peaky signals or strongly tonal signals */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 1; + } + else if (smc_dec == SPEECH) + { + /* select ACELP to encode speech */ + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + } + else if (smc_dec == SPEECH_OR_MUSIC) + { + /* select GSC to encode "unclear" segments (classifier's score on the borderline) */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 0; + } + else + { + /* select TCX to encode music */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 1; + } - FOR(j=1; jsp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) + { + if (hSpMusClas->ener_RAT < 0.18f && hSpMusClas->lt_dec_thres > 15.0f) { - L_tmp = L_mac0(L_tmp,inp[i*ATT_SEG_LEN+j],inp[i*ATT_SEG_LEN+j]); /*2*Qx */ + /* prevent GSC on strong music with almost no content below 1kHz */ + st->sp_aud_decision2 = 1; + } + else if (flag_spitch) + { + /* prevent GSC on signals with very short and stable high pitch period */ + if (hSpMusClas->wdlp_0_95_sp < 2.5f) + { + /* select ACELP instead */ + st->sp_aud_decision1 = 0; + } + else + { + /* select TCX instead */ + st->sp_aud_decision2 = 1; + } + } + else if (hSpMusClas->high_stable_cor && st->pitch[0] >= 130) + { + /* prevent GSC in highly correlated signal with low energy variation */ + /* this is basically a patch against bassoon-type of music */ + st->sp_aud_decision2 = 1; } - - finc[i] = L_tmp; - move32(); } - attack = maximum_32_fx( finc, ATT_NSEG, &etmp ); - test(); - IF( EQ_16(localVAD,1)&&EQ_16(coder_type,GENERIC)) + /* change decision from GSC to ACELP TC during attacks/onsets */ + if (st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) { - /*----------------------------------------------------------------------* - * Detect if there is a strong onset in the last subframe - * - if detected, TC is used to better code the onset - *----------------------------------------------------------------------*/ + if ((hSpMusClas->gsc_lt_diff_etot[MAX_LT - 1] > 4.5f) && + (hSpMusClas->gsc_lt_diff_etot[MAX_LT - 1] - hSpMusClas->gsc_lt_diff_etot[MAX_LT - 2] > 10.0f)) + { + if (st->tc_cnt == 1) + { + /* do ACELP TC coding instead of GC/VC if onset has been already declared before */ + st->sp_aud_decision1 = 0; + st->coder_type = TRANSITION; + } + else + { + if (attack >= ATT_3LSUB_POS) + { + /* do ACELP TC coding also if attack is located in the last subframe */ + st->sp_aud_decision1 = 0; + *attack_flag = attack + 1; + st->coder_type = TRANSITION; + } + else if (attack >= ATT_SEG_LEN / 2) + { + /* do GSC coding if attack is located after the first quarter of the first subframe */ + /* (pre-echo will be treated at the decoder side) */ + *attack_flag = 31; + *attack_flag = attack + 1; + } + } + } + } - /* compute mean energy in the first three subframes */ - exp1 = norm_s(att_3lsub_pos); - tmp = div_s(shl(1,sub(14,exp1)),att_3lsub_pos); /*Q(29-exp1) */ + if (st->localVAD == 1 && st->coder_type == GENERIC && attack > 0 /*&& *attack_flag < 32*/ /*&& st->tc_cnt != 2*/ && !(st->sp_aud_decision2 == 1 && ton > 0.65f)) + { + /* change ACELP coder_type to TC if attack has been detected */ + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; - L_tmp = L_shr(finc[0],Qx); /*Qx */ + st->coder_type = TRANSITION; + *attack_flag = attack + 1; + } - FOR(i=1; iidchan == 0 && st->coder_type != INACTIVE) + { + if (st->force == FORCE_GSC && element_brate < IVAS_24k4) { - L_tmp = L_add(L_tmp,L_shr(finc[i],Qx)); /*Qx */ + /* enforce GSC */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 0; } - L_tmp = Mult_32_16(L_tmp,tmp); /*Q(14-exp1+Qx) */ - etmp = L_shl(L_tmp,sub(exp1,14)); /*Qx */ + else if (st->force == FORCE_SPEECH && (st->sp_aud_decision1 == 1 || st->sp_aud_decision2 == 1)) + { + if (element_brate < IVAS_24k4) + { + /* convert TCX to GSC */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 0; + } + else + { + /* convert TCX to ACELP */ + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + } + } + else if (st->force == FORCE_MUSIC) + { + /* enforce TCX */ + st->sp_aud_decision1 = 1; + st->sp_aud_decision2 = 1; + } + } +#endif - tmp1 = sub(ATT_NSEG,attack); - exp1 = norm_s(tmp1); - tmp = div_s(shl(1,sub(14,exp1)),tmp1); /*Q(29-exp1) */ + /* set GSC noisy speech flag on unvoiced SWB segments */ + st->GSC_noisy_speech = 0; + if (st->vad_flag == 1 && element_brate <= IVAS_16k4 && st->lp_noise > 30.0f && st->sp_aud_decision1 == 0 && st->bwidth >= SWB && st->coder_type_raw == UNVOICED) + { + st->GSC_noisy_speech = 1; + } - L_tmp = L_shr(finc[attack],Qx); /*Qx */ - FOR(i=1; ielement_mode > EVS_MONO && (st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) && st->total_brate > STEREO_GSC_BIT_RATE_ALLOC) /* below STEREO_GSC_BIT_RATE_ALLOC, fall back on normal GSC */ + { + st->GSC_IVAS_mode = 1; + if (st->hSpMusClas->wdlp_0_95_sp > 0.0f) { - L_tmp = L_add(L_tmp,L_shr(finc[i+attack],Qx)); /*Qx */ + /* music-like content */ + st->GSC_IVAS_mode = 3; } - L_tmp = Mult_32_16(L_tmp,tmp); /*Q(14-exp1+Qx) */ - etmp2 = L_shl(L_tmp,sub(exp1,14)); /*Qx */ - - /* and compare them */ - if( GT_32(etmp,L_shr(etmp2,3))) + else if (st->tc_cnt > 0) { - /* stop, if the attack is not sufficiently strong */ - attack = 0; - move16(); + /* likely presence of an onset, GSC bit allocation will be more focused on LF */ + st->GSC_IVAS_mode = 2; } - test(); - if( EQ_16(last_clas,VOICED_CLAS)&>_32(L_add(L_shl(etmp,4),L_shl(etmp,2)),etmp2)) + if (st->coder_type_raw == UNVOICED && st->sp_aud_decision0 == 0 /*&& st->GSC_IVAS_mode < 3*/) { - /* stop, if the signal was voiced and the attack is not sufficiently strong */ - attack = 0; - move16(); + st->GSC_noisy_speech = 1; } - - /* compare also wrt. other sections (reduces a misclassification) */ - IF( attack > 0 ) + else { - etmp2 = L_add(finc[attack], 0); - etmp = Mult_32_16(etmp2, 16384); /* etmp2 / 2.0 = (etmp2*0.5) */ - FOR( i=2; iGSC_noisy_speech = 0; } } - ELSE IF( attack > 0 ) + + /* set coder_type to AUDIO when GSC is selected (st->core will be set later in the decision matrix) */ + if ((st->sp_aud_decision1 == 1 && st->sp_aud_decision2 == 0) || st->GSC_noisy_speech) { - etmp2 = L_add(finc[attack], 0); - etmp = Mult_32_16(etmp2, 25206); /* etmp2 / 1.3 = (etmp2*0.76923) */ - FOR( i=2; icoder_type = AUDIO; + if (st->hGSCEnc != NULL && st->GSC_noisy_speech == 0) /* In case of GSC_noisy_speech, NOISE_LEVEL should remain at NOISE_LEVEL_SP3 */ { - /*if( i != attack && finc[i] * 1.3f > etmp2 ) -> finc[i] > (etmp2*0.76923) */ - test(); - IF( NE_16(i,attack)&>_32(finc[i],etmp)) - { - attack = 0; - move16(); - BREAK; - } + st->hGSCEnc->noise_lev = NOISE_LEVEL_SP0; } } - return attack; + return; } +#endif + /*---------------------------------------------------------------------* * mode_decision_fx() * @@ -1218,6 +2335,7 @@ static Word16 mode_decision_fx( Word16 inv_len; Word16 j; Word16 M_flux10; + SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; mode = *dec_mov > 16384; @@ -1274,12 +2392,12 @@ static Word16 mode_decision_fx( test(); test(); test(); - IF ( (GT_16(M_pkh,2200)||LT_32(V_epsP_tilt,171799)||GT_16(M_cor_map_sum,25600))&&voiced_cnt<4) + IF ( (GT_16(M_pkh,2200) || LT_32(V_epsP_tilt,171799) || GT_16(M_cor_map_sum,25600)) && LT_16(voiced_cnt, 4) ) { mode = 1; move16(); } - ELSE IF ( GT_16(M_Ntonal,108)&&voiced_cnt<4) /*27 in Q2 */ + ELSE IF ( GT_16(M_Ntonal,108) && LT_16(voiced_cnt, 4)) /*27 in Q2 */ { mode = 1; move16(); @@ -1339,8 +2457,8 @@ static Word16 mode_decision_fx( test(); test(); test(); - IF ( (LT_16(M_flux10,4352)||(LT_32(V_epsP_tilt,2147484)&<_16(M_flux10,6144))||GT_16(M_pkh,2100)||GT_16(M_cor_map_sum,25600))&& - LT_16(voiced_cnt,3) && LT_16(tmp,7680) ) + IF ( (LT_16(M_flux10,4352) || (LT_32(V_epsP_tilt,2147484) && LT_16(M_flux10,6144)) || GT_16(M_pkh,2100) || + GT_16(M_cor_map_sum,25600)) && LT_16(voiced_cnt,3) && LT_16(tmp,7680) ) { mode = 1; move16(); @@ -1354,7 +2472,8 @@ static Word16 mode_decision_fx( test(); test(); test(); - IF ( GT_16(M_flux10,8192)||(GT_16(M_flux10,7680)&&voiced_cnt>2)||GT_16(tmp,9728)||(GE_16(buf_flux[59],2560)&>_16(st->lps_fx,st->lpm_fx))) + IF ( GT_16(M_flux10,8192) || (GT_16(M_flux10,7680) && GT_16(voiced_cnt, 2)) || GT_16(tmp,9728) || + (GE_16(buf_flux[59],2560) && GT_16(hSpMusClas->lps_fx, hSpMusClas->lpm_fx))) { mode = 0; move16(); @@ -1743,22 +2862,20 @@ static void spec_analysis_fx( } static void music_mixed_classif_improv_fx( - Encoder_State_fx *st, /* i : encoder state structure */ - const Word16 *new_inp, /* i : new input signal */ - Word16 *sp_aud_decision1, /* i/o: 1st stage speech/music decision */ - Word16 vad_flag, - const Word16 *voicing, /* i : voicing estimate Q15*/ - const Word32 *epsP, /* i : LP prediciton error Q_epsP*/ + Encoder_State_fx *st, /* i : encoder state structure */ + const Word16 *new_inp, /* i : new input signal */ + const Word32 *epsP, /* i : LP prediciton error Q_epsP*/ Word16 Q_epsP, - Word16 etot, /* i : total frame energy Q8*/ - Word16 old_cor, /* i : normalized correlation Q15*/ - Word16 cor_map_sum /* i : correlation map sum Q8*/ + Word16 etot, /* i : total frame energy Q8*/ + Word16 old_cor, /* i : normalized correlation Q15*/ + Word16 cor_map_sum /* i : correlation map sum Q8*/ ) { Word16 i, max_spl, dec, len, percus_flag, lt_diff, log_max_spl, epsP_tilt, p2v_map[128]; Word16 exp, frac, expn, fracn, expd, fracd, scale; Word16 tmp; Word32 L_tmp, ftmp, ftmp1, epsP_max = MIN_32; + SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; /* find sample with maximum absolute amplitude */ max_spl = 0; @@ -1770,30 +2887,30 @@ static void music_mixed_classif_improv_fx( /* music is considered only appearing in high SNR condition and active signal */ test(); - IF ( vad_flag == 0 || LT_16(sub(st->lp_speech_fx,st->lp_noise_fx),6400)) /* 25 in Q8 */ + IF ( st->vad_flag == 0 || LT_16(sub(st->lp_speech_fx,st->lp_noise_fx),6400)) /* 25 in Q8 */ { /* st->dec_mov = 0.5f; */ /* st->dec_mov1 = 0.5f; */ - st->dec_mov_fx = 16384; + hSpMusClas->dec_mov_fx = 16384; move16(); - st->dec_mov1_fx = 16384; + hSpMusClas->dec_mov1_fx = 16384; move16(); - if ( vad_flag == 0 ) + if (st->vad_flag == 0 ) { - st->onset_cnt_fx = 0; + hSpMusClas->onset_cnt_fx = 0; move16(); } return; } - st->onset_cnt_fx = add(st->onset_cnt_fx,1); - st->onset_cnt_fx = s_min(st->onset_cnt_fx, 9); + hSpMusClas->onset_cnt_fx = add(hSpMusClas->onset_cnt_fx,1); + hSpMusClas->onset_cnt_fx = s_min(hSpMusClas->onset_cnt_fx, 9); - IF ( EQ_16(st->onset_cnt_fx,1)) + IF ( EQ_16(hSpMusClas->onset_cnt_fx,1)) { - set16_fx( st->buf_flux_fx, -12800, BUF_LEN ); /*-100.0 in Q7 */ + set16_fx(hSpMusClas->buf_flux_fx, -12800, BUF_LEN ); /*-100.0 in Q7 */ } /* spectral analysis */ @@ -1812,34 +2929,34 @@ static void music_mixed_classif_improv_fx( log_max_spl = round_fx(L_shl(L_tmp,11)); /*Q7 */ } - lt_diff = sub(log_max_spl,st->mov_log_max_spl_fx); /*Q7 */ + lt_diff = sub(log_max_spl, hSpMusClas->mov_log_max_spl_fx); /*Q7 */ FOR ( i=0; i<3; i++ ) { - st->buf_etot_fx[i] = st->buf_etot_fx[i+1]; + hSpMusClas->buf_etot_fx[i] = hSpMusClas->buf_etot_fx[i+1]; move16(); /*Q8 */ } - st->buf_etot_fx[i] = etot; + hSpMusClas->buf_etot_fx[i] = etot; move16();/*Q8 */ percus_flag = 0; move16(); test(); test(); - IF ( GT_16(sub(st->buf_etot_fx[1],st->buf_etot_fx[0]),1536)&& - LT_16(st->buf_etot_fx[2],st->buf_etot_fx[1]) && - GT_16(sub(st->buf_etot_fx[1],st->lp_speech_fx),768) ) /* 3 in Q8 */ + IF ( GT_16(sub(hSpMusClas->buf_etot_fx[1], hSpMusClas->buf_etot_fx[0]),1536)&& + LT_16(hSpMusClas->buf_etot_fx[2], hSpMusClas->buf_etot_fx[1]) && + GT_16(sub(hSpMusClas->buf_etot_fx[1], st->lp_speech_fx),768) ) /* 3 in Q8 */ { /*tmp = add(shr(voicing[0],2),shr(voicing[1],2)); //Q15 */ /*tmp = add(tmp,shr(old_cor,1)); //Q15 */ - tmp = mac_r(L_mac(L_mult(voicing[0],8192),voicing[1],8192),old_cor, 16384); + tmp = mac_r(L_mac(L_mult(st->voicing_fx[0],8192),st->voicing_fx[1],8192),old_cor, 16384); test(); test(); - IF ( GT_16(sub(st->buf_etot_fx[1],st->buf_etot_fx[3]),768)&& - LT_16(st->buf_etot_fx[3],st->buf_etot_fx[2]) && + IF ( GT_16(sub(hSpMusClas->buf_etot_fx[1], hSpMusClas->buf_etot_fx[3]),768)&& + LT_16(hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2]) && LT_16(tmp,24576)) /* 0.75 in Q15 */ { - IF ( GT_16(st->dec_mov_fx,26214)) /* 0.8 in Q15 */ + IF ( GT_16(hSpMusClas->dec_mov_fx,26214)) /* 0.8 in Q15 */ { percus_flag = 1; move16(); @@ -1849,7 +2966,7 @@ static void music_mixed_classif_improv_fx( test(); test(); test(); - IF ( LT_16(old_cor,24576)&<_16(voicing[0],24576)&<_16(voicing[1],24576)&>_16(st->old_lt_diff_fx[0],1280)) + IF ( LT_16(old_cor,24576)&<_16(st->voicing_fx[0],24576)&<_16(st->voicing_fx[1],24576)&>_16(hSpMusClas->old_lt_diff_fx[0],1280)) { percus_flag = 1; move16(); @@ -1862,47 +2979,47 @@ static void music_mixed_classif_improv_fx( test(); test(); test(); - IF ( GT_16(sub(st->buf_etot_fx[3],st->buf_etot_fx[2]),1536) - && GT_16(st->dec_mov_fx,29491) + IF ( GT_16(sub(hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2]),1536) + && GT_16(hSpMusClas->dec_mov_fx,29491) && GT_16(sub(etot,st->lp_speech_fx),1280) - && GT_16(st->old_lt_diff_fx[0],640)) + && GT_16(hSpMusClas->old_lt_diff_fx[0],640)) { - st->attack_hangover_fx = 3; + hSpMusClas->attack_hangover_fx = 3; move16(); } test(); - IF ( GT_16(voicing[0],29491)&>_16(voicing[1],29491)) + IF ( GT_16(st->voicing_fx[0],29491)&>_16(st->voicing_fx[1],29491)) { - IF ( GT_16(log_max_spl,st->mov_log_max_spl_fx)) + IF ( GT_16(log_max_spl, hSpMusClas->mov_log_max_spl_fx)) { /**mov_log_max_spl = add(mult_r(31130,(*mov_log_max_spl)),mult_r(1638,log_max_spl)); //Q7 */ - st->mov_log_max_spl_fx = round_fx(L_mac(L_mult(31130,st->mov_log_max_spl_fx),1638,log_max_spl)); /*Q7 */ + hSpMusClas->mov_log_max_spl_fx = round_fx(L_mac(L_mult(31130, hSpMusClas->mov_log_max_spl_fx),1638,log_max_spl)); /*Q7 */ } ELSE { /**mov_log_max_spl = add(mult_r(32604,(*mov_log_max_spl)),mult_r(164,log_max_spl)); //Q7 */ - st->mov_log_max_spl_fx = round_fx(L_mac(L_mult(32604,st->mov_log_max_spl_fx),164,log_max_spl)); /*Q7 */ + hSpMusClas->mov_log_max_spl_fx = round_fx(L_mac(L_mult(32604,hSpMusClas->mov_log_max_spl_fx),164,log_max_spl)); /*Q7 */ } } - st->old_lt_diff_fx[0] = st->old_lt_diff_fx[1]; + hSpMusClas->old_lt_diff_fx[0] = hSpMusClas->old_lt_diff_fx[1]; move16(); /*Q7 */ - st->old_lt_diff_fx[1] = lt_diff; + hSpMusClas->old_lt_diff_fx[1] = lt_diff; move16(); /*Q7 */ /* calculate and buffer spectral energy fluctuation */ - flux_fx( st->lgBin_E_fx, p2v_map, st->old_Bin_E_fx, st->buf_flux_fx, st->attack_hangover_fx, st->dec_mov_fx ); + flux_fx( st->lgBin_E_fx, p2v_map, hSpMusClas->old_Bin_E_fx, hSpMusClas->buf_flux_fx, hSpMusClas->attack_hangover_fx, hSpMusClas->dec_mov_fx ); - st->attack_hangover_fx = sub(st->attack_hangover_fx,1); - st->attack_hangover_fx = s_max(st->attack_hangover_fx,0); + hSpMusClas->attack_hangover_fx = sub(hSpMusClas->attack_hangover_fx,1); + hSpMusClas->attack_hangover_fx = s_max(hSpMusClas->attack_hangover_fx,0); /* identify flux buffer buffering status */ len = 0; move16(); FOR ( i=BUF_LEN-1; i>=0; i-- ) { - IF (st->buf_flux_fx[i] < 0) + IF (hSpMusClas->buf_flux_fx[i] < 0) { BREAK; } @@ -1913,7 +3030,7 @@ static void music_mixed_classif_improv_fx( /* reset flux buffer if percussive music is detected */ IF ( EQ_16(percus_flag,1)) { - set16_fx( &st->buf_flux_fx[BUF_LEN-len], 640, len ); /* 5 in Q7 */ + set16_fx( &hSpMusClas->buf_flux_fx[BUF_LEN-len], 640, len ); /* 5 in Q7 */ } /* calculate and buffer the tilt of residual LP energies */ @@ -2014,37 +3131,37 @@ static void music_mixed_classif_improv_fx( FOR ( i=0; ibuf_epsP_tilt_fx[i] = st->buf_epsP_tilt_fx[i+1]; + hSpMusClas->buf_epsP_tilt_fx[i] = hSpMusClas->buf_epsP_tilt_fx[i+1]; move16(); /*Q15 */ } - st->buf_epsP_tilt_fx[i] = epsP_tilt; + hSpMusClas->buf_epsP_tilt_fx[i] = epsP_tilt; move16(); /*Q15 */ /* calculate and buffer highband spectral peakness */ - tonal_dist_fx( p2v_map, st->buf_pkh_fx, st->buf_Ntonal_fx, st->buf_Ntonal2_fx, st->buf_Ntonal_lf_fx ); + tonal_dist_fx( p2v_map, hSpMusClas->buf_pkh_fx, hSpMusClas->buf_Ntonal_fx, hSpMusClas->buf_Ntonal2_fx, hSpMusClas->buf_Ntonal_lf_fx ); /* buffer sum of correlation map */ FOR ( i=0; ibuf_cor_map_sum_fx[i] = st->buf_cor_map_sum_fx[i+1]; + hSpMusClas->buf_cor_map_sum_fx[i] = hSpMusClas->buf_cor_map_sum_fx[i+1]; move16(); /*Q8 */ } - st->buf_cor_map_sum_fx[i] = cor_map_sum; + hSpMusClas->buf_cor_map_sum_fx[i] = cor_map_sum; move16(); /*Q8 */ /* buffer voicing metric */ FOR ( i=0; i<9; i++ ) { - st->buf_dlp_fx[i] = st->buf_dlp_fx[i+1]; + hSpMusClas->buf_dlp_fx[i] = hSpMusClas->buf_dlp_fx[i+1]; move16(); } - st->buf_dlp_fx[i] = sub(st->lps_fx, st->lpm_fx); + hSpMusClas->buf_dlp_fx[i] = sub(hSpMusClas->lps_fx, hSpMusClas->lpm_fx); move16();/*Q9 */ /* classification */ - dec = mode_decision_fx( st, len, &st->dec_mov_fx, st->buf_flux_fx, st->buf_epsP_tilt_fx, st->buf_pkh_fx, - st->buf_cor_map_sum_fx, st->buf_Ntonal_fx, st->buf_Ntonal2_fx, st->buf_Ntonal_lf_fx, - st->buf_dlp_fx ); + dec = mode_decision_fx( st, len, &hSpMusClas->dec_mov_fx, hSpMusClas->buf_flux_fx, hSpMusClas->buf_epsP_tilt_fx, hSpMusClas->buf_pkh_fx, + hSpMusClas->buf_cor_map_sum_fx, hSpMusClas->buf_Ntonal_fx, hSpMusClas->buf_Ntonal2_fx, hSpMusClas->buf_Ntonal_lf_fx, + hSpMusClas->buf_dlp_fx ); move16(); /* update long term moving average of the classification decisions */ @@ -2052,13 +3169,13 @@ static void music_mixed_classif_improv_fx( { IF( dec == 0 ) { - st->dec_mov_fx = mult_r(31785,st->dec_mov_fx); /*Q15 */ - st->dec_mov1_fx = mult_r(31785,st->dec_mov1_fx); /*Q15 */ + hSpMusClas->dec_mov_fx = mult_r(31785, hSpMusClas->dec_mov_fx); /*Q15 */ + hSpMusClas->dec_mov1_fx = mult_r(31785, hSpMusClas->dec_mov1_fx); /*Q15 */ } ELSE { - st->dec_mov_fx = add(mult_r(31785,st->dec_mov_fx),983); /*Q15 */ - st->dec_mov1_fx = add(mult_r(31785,st->dec_mov1_fx),983); /*Q15 */ + hSpMusClas->dec_mov_fx = add(mult_r(31785,hSpMusClas->dec_mov_fx),983); /*Q15 */ + hSpMusClas->dec_mov1_fx = add(mult_r(31785, hSpMusClas->dec_mov1_fx),983); /*Q15 */ } } @@ -2067,25 +3184,25 @@ static void music_mixed_classif_improv_fx( test(); test(); IF ( (EQ_16(st->coder_type_raw_fx,UNVOICED)||EQ_16(st->coder_type_raw_fx,INACTIVE))&& - GT_16(etot,384) && LT_16(st->buf_Ntonal2_fx[59],2) ) + GT_16(etot,384) && LT_16(hSpMusClas->buf_Ntonal2_fx[59],2) ) { - st->UV_cnt1_fx = sub(st->UV_cnt1_fx,8); + hSpMusClas->UV_cnt1_fx = sub(hSpMusClas->UV_cnt1_fx,8); } ELSE { - st->UV_cnt1_fx = add(st->UV_cnt1_fx,1); + hSpMusClas->UV_cnt1_fx = add(hSpMusClas->UV_cnt1_fx,1); } - st->UV_cnt1_fx = s_min(st->UV_cnt1_fx,300); - st->UV_cnt1_fx = s_max(st->UV_cnt1_fx,0); + hSpMusClas->UV_cnt1_fx = s_min(hSpMusClas->UV_cnt1_fx,300); + hSpMusClas->UV_cnt1_fx = s_max(hSpMusClas->UV_cnt1_fx,0); /**LT_UV_cnt1 = add(mult_r(29491,*LT_UV_cnt1),mult_r(3277,shl(*UV_cnt1,6)));*/ /* Q6 */ - st->LT_UV_cnt1_fx = round_fx(L_mac(L_mult(29491,st->LT_UV_cnt1_fx),3277,shl(st->UV_cnt1_fx,6))); /*Q6 */ + hSpMusClas->LT_UV_cnt1_fx = round_fx(L_mac(L_mult(29491, hSpMusClas->LT_UV_cnt1_fx),3277,shl(hSpMusClas->UV_cnt1_fx,6))); /*Q6 */ /* revert classification decision due to long-term unvoiced counter */ test(); test(); - IF ( EQ_16(dec,1)&<_16(st->dec_mov1_fx,6554)&<_16(st->LT_UV_cnt1_fx,12800)) + IF ( EQ_16(dec,1)&<_16(hSpMusClas->dec_mov1_fx,6554)&<_16(hSpMusClas->LT_UV_cnt1_fx,12800)) { dec = 0; move16(); @@ -2094,7 +3211,7 @@ static void music_mixed_classif_improv_fx( /* overwrite 1st stage speech/music decision to music */ IF (EQ_16(dec,1)) { - *sp_aud_decision1 = 1; + st->sp_aud_decision1 = 1; move16(); } @@ -2112,11 +3229,6 @@ static void music_mixed_classif_improv_fx( static void tonal_context_improv_fx( Encoder_State_fx *st_fx, /* i/o: Encoder state structure */ const Word32 PS[], /* i : energy spectrum */ - Word16 *sp_aud_decision1, /* i/o: 1st stage speech/music decision */ - Word16 *sp_aud_decision2, /* i/o: 2nd stage speech/music decision */ - const Word16 vad_flag, - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ - const Word16 voicing[3], /* i : voicing estimate in three subframes */ const Word16 voi_fv, /* i : scaled voicing feature */ const Word16 cor_map_sum_fv, /* i : scaled correlation map feature */ const Word16 LPCErr, /* i : scaled LP prediction error feature */ @@ -2127,19 +3239,21 @@ static void tonal_context_improv_fx( Word16 exp, expa, expb, fraca, fracb, scale, exp1, exp2, exp3, tmp; Word16 voi_mean, lt_pitch_diff; Word32 L_tmp, tonality, tonality1, tonality2, tonality3, sort_max, sort_avg, sort_val[80]; + VAD_HANDLE hVAD = st_fx->hVAD; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; IF ( EQ_16(st_fx->last_codec_mode, MODE2)) { - set16_fx(st_fx->tonality2_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->tonality3_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->LPCErr_buf_fx,0,HANG_LEN_INIT); - st_fx->lt_music_hangover_fx = 0; + set16_fx(hSpMusClas->tonality2_buf_fx,0,HANG_LEN_INIT); + set16_fx(hSpMusClas->tonality3_buf_fx,0,HANG_LEN_INIT); + set16_fx(hSpMusClas->LPCErr_buf_fx,0,HANG_LEN_INIT); + hSpMusClas->lt_music_hangover_fx = 0; move16(); - st_fx->lt_music_state_fx = 0; + hSpMusClas->lt_music_state_fx = 0; move16(); - st_fx->lt_speech_state_fx = 0; + hSpMusClas->lt_speech_state_fx = 0; move16(); - st_fx->lt_speech_hangover_fx= 0; + hSpMusClas->lt_speech_hangover_fx= 0; move16(); } @@ -2239,85 +3353,73 @@ static void tonal_context_improv_fx( tonality = L_max(L_max(tonality1, tonality2), tonality3); - /* voi_mean = 0.33f * (voicing[0] + voicing[1] + voicing[2]); */ - L_tmp = L_mult(voicing[0], 10923); - L_tmp = L_mac(L_tmp, voicing[1], 10923); - voi_mean = mac_r(L_tmp, voicing[2], 10923); /* Q15 */ + /* voi_mean = 0.33f * (st->voicing_fx[0] + voicing[1] + voicing[2]); */ + L_tmp = L_mult(st_fx->voicing_fx[0], 10923); + L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); + voi_mean = mac_r(L_tmp, st_fx->voicing_fx[2], 10923); /* Q15 */ test(); - IF( EQ_16(st_fx->hangover_cnt_fx,10)&&EQ_16(vad_flag,1)) + IF( EQ_16(hVAD->hangover_cnt_fx,10) && EQ_16(st_fx->vad_flag,1)) { /* long-term voicing parameter */ - st_fx->lt_voicing = round_fx(L_mac(L_mult(3277,st_fx->lt_voicing),29491, voi_mean)); + hSpMusClas->lt_voicing = round_fx(L_mac(L_mult(3277,hSpMusClas->lt_voicing),29491, voi_mean)); /* long-term correlation value */ - st_fx->lt_corr = round_fx(L_mac(L_mult(3277,st_fx->lt_corr),29491, st_fx->old_corr_fx)); + hSpMusClas->lt_corr = round_fx(L_mac(L_mult(3277,hSpMusClas->lt_corr),29491, st_fx->old_corr_fx)); /* long-term tonality measure */ - st_fx->lt_tonality = L_add(Mult_32_16(st_fx->lt_tonality,3277),Mult_32_16(tonality,29491)); + hSpMusClas->lt_tonality = L_add(Mult_32_16(hSpMusClas->lt_tonality,3277),Mult_32_16(tonality,29491)); } ELSE { /* long-term voicing parameter */ - st_fx->lt_voicing = round_fx(L_mac(L_mult(22938,st_fx->lt_voicing),9830, voi_mean)); + hSpMusClas->lt_voicing = round_fx(L_mac(L_mult(22938,hSpMusClas->lt_voicing),9830, voi_mean)); /* long-term correlation value */ - st_fx->lt_corr = round_fx(L_mac(L_mult(22938,st_fx->lt_corr),9830, st_fx->old_corr_fx)); + hSpMusClas->lt_corr = round_fx(L_mac(L_mult(22938,hSpMusClas->lt_corr),9830, st_fx->old_corr_fx)); /* long-term tonality measure */ - st_fx->lt_tonality = L_add(Mult_32_16(st_fx->lt_tonality,16384),Mult_32_16(tonality,16384)); + hSpMusClas->lt_tonality = L_add(Mult_32_16(hSpMusClas->lt_tonality,16384),Mult_32_16(tonality,16384)); } /* Pitch difference w.r.t to past 3 frames */ - lt_pitch_diff = abs_s(sub(st_fx->lt_corr_pitch[0], pitch[0])); - lt_pitch_diff = add(lt_pitch_diff , abs_s(sub(st_fx->lt_corr_pitch[1], pitch[0]))); - lt_pitch_diff = add(lt_pitch_diff,abs_s(sub(st_fx->lt_corr_pitch[2], pitch[0]))); + lt_pitch_diff = abs_s(sub(hSpMusClas->lt_corr_pitch[0], st_fx->pitch_fx[0])); + lt_pitch_diff = add(lt_pitch_diff , abs_s(sub(hSpMusClas->lt_corr_pitch[1], st_fx->pitch_fx[0]))); + lt_pitch_diff = add(lt_pitch_diff,abs_s(sub(hSpMusClas->lt_corr_pitch[2], st_fx->pitch_fx[0]))); - st_fx->lt_corr_pitch[0] = st_fx->lt_corr_pitch[1]; + hSpMusClas->lt_corr_pitch[0] = hSpMusClas->lt_corr_pitch[1]; move16(); - st_fx->lt_corr_pitch[1] = st_fx->lt_corr_pitch[2]; + hSpMusClas->lt_corr_pitch[1] = hSpMusClas->lt_corr_pitch[2]; move16(); - st_fx->lt_corr_pitch[2] = pitch[0]; + hSpMusClas->lt_corr_pitch[2] = st_fx->pitch_fx[0]; move16(); - st_fx->lt_old_mode[0] = st_fx->lt_old_mode[1]; + hSpMusClas->lt_old_mode[0] = hSpMusClas->lt_old_mode[1]; move16(); - st_fx->lt_old_mode[1] = st_fx->lt_old_mode[2]; + hSpMusClas->lt_old_mode[1] = hSpMusClas->lt_old_mode[2]; move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( *sp_aud_decision1 == 1 && + test();test();test();test();test();test();test();test();test();test();test();test();test(); + IF (st_fx->sp_aud_decision1 == 1 && ( GT_32(L_min(L_min(tonality1, tonality2), tonality3),1638400) ) && ( GT_32(L_add(tonality1, tonality2),6553600) && GT_32(L_add(tonality2, tonality3),6553600) && GT_32(L_add(tonality1, tonality3),6553600)) && - ( LT_32(st_fx->lt_tonality,655360000) ) && - ( ( GT_32(st_fx->lt_tonality,32768000) && GT_16(s_max(st_fx->lt_voicing, voi_mean),32440) ) || - ( GT_32(st_fx->lt_tonality,49152000) && GT_16(st_fx->lt_corr,32440) ) || - ( GT_32(st_fx->lt_tonality,98304000) && GT_16(st_fx->lowrate_pitchGain,15729) ) || - ( lt_pitch_diff == 0 && GT_16(st_fx->lowrate_pitchGain,14582)))) + ( LT_32(hSpMusClas->lt_tonality,655360000) ) && + ( ( GT_32(hSpMusClas->lt_tonality,32768000) && GT_16(s_max(hSpMusClas->lt_voicing, voi_mean),32440) ) || + ( GT_32(hSpMusClas->lt_tonality,49152000) && GT_16(hSpMusClas->lt_corr,32440) ) || + ( GT_32(hSpMusClas->lt_tonality,98304000) && GT_16(hSpMusClas->lowrate_pitchGain,15729) ) || + ( lt_pitch_diff == 0 && GT_16(hSpMusClas->lowrate_pitchGain,14582)))) { - IF( LT_16(sum16_fx(st_fx->lt_old_mode, 2),2)) + IF( LT_16(sum16_fx(hSpMusClas->lt_old_mode, 2),2)) { /* probably speech - change the decision to speech */ - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 0; + st_fx->sp_aud_decision2 = 0; move16(); - if( st_fx->lt_hangover == 0 ) + if( hSpMusClas->lt_hangover == 0 ) { - st_fx->lt_hangover = 6; + hSpMusClas->lt_hangover = 6; move16(); } } @@ -2325,160 +3427,139 @@ static void tonal_context_improv_fx( ELSE { /* not speech, but still in the hangover period - change the decision to speech */ - IF( st_fx->lt_hangover > 0 ) + IF( hSpMusClas->lt_hangover > 0 ) { - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 0; + st_fx->sp_aud_decision2 = 0; move16(); - st_fx->lt_hangover = sub(st_fx->lt_hangover,1); + hSpMusClas->lt_hangover = sub(hSpMusClas->lt_hangover,1); } } /* calculate standard deviation of log-tonality */ - Copy( st_fx->tonality2_buf_fx + 1, st_fx->tonality2_buf_fx, HANG_LEN_INIT - 1 ); + Copy( hSpMusClas->tonality2_buf_fx + 1, hSpMusClas->tonality2_buf_fx, HANG_LEN_INIT - 1 ); /* st->tonality2_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality2); */ exp = norm_l(tonality2); tmp = Log2_norm_lc(L_shl(tonality2, exp));/*15 */ exp = sub(30, add(exp, 16)); L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - st_fx->tonality2_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ + hSpMusClas->tonality2_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ /* t2 = std( st->tonality2_buf, HANG_LEN_INIT ); */ - t2_fx = std_fx( st_fx->tonality2_buf_fx, HANG_LEN_INIT ); /*14 */ + t2_fx = std_fx( hSpMusClas->tonality2_buf_fx, HANG_LEN_INIT ); /*14 */ - Copy( st_fx->tonality3_buf_fx + 1, st_fx->tonality3_buf_fx, HANG_LEN_INIT - 1 ); + Copy( hSpMusClas->tonality3_buf_fx + 1, hSpMusClas->tonality3_buf_fx, HANG_LEN_INIT - 1 ); /* st->tonality3_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality3); */ exp = norm_l(tonality3); tmp = Log2_norm_lc(L_shl(tonality3, exp));/*15 */ exp = sub(30, add(exp, 16)); L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - st_fx->tonality3_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ - t3_fx = std_fx( st_fx->tonality3_buf_fx, HANG_LEN_INIT ); /*14 */ + hSpMusClas->tonality3_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ + t3_fx = std_fx( hSpMusClas->tonality3_buf_fx, HANG_LEN_INIT ); /*14 */ /* tL = 0.2f*(float)log10(st->lt_tonality); */ - exp = norm_l(st_fx->lt_tonality); - tmp = Log2_norm_lc(L_shl(st_fx->lt_tonality, exp));/*15 */ + exp = norm_l(hSpMusClas->lt_tonality); + tmp = Log2_norm_lc(L_shl(hSpMusClas->lt_tonality, exp));/*15 */ exp = sub(30, add(exp, 16)); L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ tL_fx = round_fx(L_shl(L_tmp, 11));/*14 */ /* calculate standard deviation of residual LP energy */ - Copy( st_fx->LPCErr_buf_fx + 1, st_fx->LPCErr_buf_fx, HANG_LEN_INIT - 1 ); - st_fx->LPCErr_buf_fx[HANG_LEN_INIT - 1] = LPCErr; + Copy( hSpMusClas->LPCErr_buf_fx + 1, hSpMusClas->LPCErr_buf_fx, HANG_LEN_INIT - 1 ); + hSpMusClas->LPCErr_buf_fx[HANG_LEN_INIT - 1] = LPCErr; /* err = std( st->LPCErr_buf, HANG_LEN_INIT ); */ - err_fx = std_fx( st_fx->LPCErr_buf_fx, HANG_LEN_INIT ); + err_fx = std_fx( hSpMusClas->LPCErr_buf_fx, HANG_LEN_INIT ); cor_fx = s_max(sub(voi_fv, cor_map_sum_fv), 0);/*15 */ - dft_fx = abs_s(sub(st_fx->tonality2_buf_fx[HANG_LEN_INIT - 1], st_fx->tonality3_buf_fx[HANG_LEN_INIT - 1]));/*14 */ + dft_fx = abs_s(sub(hSpMusClas->tonality2_buf_fx[HANG_LEN_INIT - 1], hSpMusClas->tonality3_buf_fx[HANG_LEN_INIT - 1]));/*14 */ /* state machine for strong music */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (EQ_16(*sp_aud_decision1, 1))&&st_fx->lt_music_state_fx==0&&st_fx->lt_music_hangover_fx==0&& + test();test();test();test();test();test();test();test();test();test();test();test(); + IF ( (EQ_16(st_fx->sp_aud_decision1, 1)) && hSpMusClas->lt_music_state_fx==0 && hSpMusClas->lt_music_hangover_fx==0 && (LT_16(t2_fx, 8847)) && (GT_16(t2_fx, 4260)) && (GT_16(t3_fx, 3604)) && (LT_16(tL_fx, 8847)) && (GT_16(tL_fx, 4260)) && (GT_16(err_fx, 8192)) ) { - st_fx->lt_music_state_fx = 1; + hSpMusClas->lt_music_state_fx = 1; move16(); - st_fx->lt_music_hangover_fx = 6; + hSpMusClas->lt_music_hangover_fx = 6; move16(); } - ELSE IF( EQ_16(st_fx->lt_music_state_fx, 1)&&st_fx->lt_music_hangover_fx==0&& + ELSE IF( EQ_16(hSpMusClas->lt_music_state_fx, 1) && hSpMusClas->lt_music_hangover_fx==0 && (LT_16(t2_fx, 5571) ) && (LT_16(t3_fx, 4260) ) && (LT_16(tL_fx, 7373) ) ) { - st_fx->lt_music_state_fx = 0; + hSpMusClas->lt_music_state_fx = 0; move16(); - st_fx->lt_music_hangover_fx = 6; + hSpMusClas->lt_music_hangover_fx = 6; move16(); } - IF ( st_fx->lt_music_hangover_fx > 0 ) + IF ( hSpMusClas->lt_music_hangover_fx > 0 ) { - st_fx->lt_music_hangover_fx = sub(st_fx->lt_music_hangover_fx,1); + hSpMusClas->lt_music_hangover_fx = sub(hSpMusClas->lt_music_hangover_fx,1); } /* state machine for strong speech */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (EQ_16(*sp_aud_decision1, 1))&&st_fx->lt_speech_state_fx==0&&st_fx->lt_speech_hangover_fx==0&& + test();test();test();test();test();test();test();test();test();test();test();test();test(); + IF ( (EQ_16(st_fx->sp_aud_decision1, 1)) && hSpMusClas->lt_speech_state_fx==0 && hSpMusClas->lt_speech_hangover_fx==0 && (GT_16(cor_fx, 13107)) && (LT_16(dft_fx, 1638)) && GT_16(shr(voi_fv,1), add(cor_map_sum_fv, 1966)) && (LT_16(t2_fx, shr(cor_fx, 1))) && (LT_16(t3_fx, shr(cor_fx, 1))) && (LT_16(tL_fx, shr(cor_fx, 1))) && (LT_16(cor_map_sum_fv, cor_fx)) && (GT_16(voi_fv, cor_fx)) && (GT_16(voi_fv, 24903) ) ) { - st_fx->lt_speech_state_fx = 1; + hSpMusClas->lt_speech_state_fx = 1; move16(); - st_fx->lt_speech_hangover_fx = 6; + hSpMusClas->lt_speech_hangover_fx = 6; move16(); } - ELSE IF ( (EQ_16(st_fx->lt_speech_state_fx, 1))&&st_fx->lt_speech_hangover_fx==0&&(LT_16(cor_fx,13107))) + ELSE IF ( (EQ_16(hSpMusClas->lt_speech_state_fx, 1)) && hSpMusClas->lt_speech_hangover_fx==0 &&(LT_16(cor_fx,13107))) { - st_fx->lt_speech_state_fx = 0; + hSpMusClas->lt_speech_state_fx = 0; move16(); - st_fx->lt_speech_hangover_fx = 6; + hSpMusClas->lt_speech_hangover_fx = 6; move16(); } - IF ( st_fx->lt_speech_hangover_fx > 0) + IF ( hSpMusClas->lt_speech_hangover_fx > 0) { - st_fx->lt_speech_hangover_fx = sub(st_fx->lt_speech_hangover_fx,1); + hSpMusClas->lt_speech_hangover_fx = sub(hSpMusClas->lt_speech_hangover_fx,1); } /* final decision */ test(); test(); - IF ( EQ_16(*sp_aud_decision1,1)&&EQ_16(st_fx->lt_speech_state_fx,1)) + IF ( EQ_16(st_fx->sp_aud_decision1,1) && EQ_16(hSpMusClas->lt_speech_state_fx,1)) { /* strong speech - probably error in speech/music classification */ - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 0; + st_fx->sp_aud_decision2 = 0; move16(); } - ELSE IF ( *sp_aud_decision1 == 0 && EQ_16(st_fx->lt_speech_state_fx,1)) + ELSE IF (st_fx->sp_aud_decision1 == 0 && EQ_16(hSpMusClas->lt_speech_state_fx,1)) { /* strong music - probably error in speech/music classification */ - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 0; + st_fx->sp_aud_decision2 = 0; move16(); } /* update the buffer of past decisions */ - st_fx->lt_old_mode[2] = *sp_aud_decision1; + hSpMusClas->lt_old_mode[2] = st_fx->sp_aud_decision1; move16(); return; } - +/*----------------------------------------------------------------------------------* + * detect_sparseness_fx() + * + * + *----------------------------------------------------------------------------------*/ static void detect_sparseness_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 *sp_aud_decision1, /* i/o: 1st stage speech/music decision */ - Word16 *sp_aud_decision2, /* i/o: 2nd stage speech/music decision */ - const Word16 voi_fv /* i : scaled voicing feature */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 voi_fv /* i : scaled voicing feature */ ) { Word16 sum, sumh; @@ -2491,6 +3572,7 @@ static void detect_sparseness_fx( Word16 sparse; Word16 tmp_buf[4]; Word16 Mlpe=0, Mv=0, Msp; + SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; Copy(st_fx->lgBin_E_fx, S1, 128); @@ -2541,13 +3623,13 @@ static void detect_sparseness_fx( FOR (i = 0; i < HANG_LEN_INIT-1; i++) { - st_fx->sparse_buf_fx[i] = st_fx->sparse_buf_fx[i+1]; + hSpMusClas->sparse_buf_fx[i] = hSpMusClas->sparse_buf_fx[i+1]; move16(); } sparse = j; move16(); - st_fx->sparse_buf_fx[i] = sparse; + hSpMusClas->sparse_buf_fx[i] = sparse; move16(); IF (EQ_16(st_fx->bwidth_fx, WB)) @@ -2556,15 +3638,15 @@ static void detect_sparseness_fx( move16(); FOR (i = 0; i < 8; i++) { - Msp = add(Msp, st_fx->sparse_buf_fx[i]); + Msp = add(Msp, hSpMusClas->sparse_buf_fx[i]); } Msp = shl(Msp, 5); /* Q8 */ /* find long-term smoothed sparseness */ IF (st_fx->last_vad_spa_fx == 0 ) { - set16_fx( &st_fx->sparse_buf_fx[0], sparse, HANG_LEN_INIT-1 ); - st_fx->LT_sparse_fx = sparse; + set16_fx( &hSpMusClas->sparse_buf_fx[0], sparse, HANG_LEN_INIT-1 ); + hSpMusClas->LT_sparse_fx = sparse; move16(); } ELSE @@ -2575,10 +3657,10 @@ static void detect_sparseness_fx( { FOR (j = 0; j < 4; j++) { - IF (GT_16(st_fx->sparse_buf_fx[i], tmp_buf[j])) + IF (GT_16(hSpMusClas->sparse_buf_fx[i], tmp_buf[j])) { Copy(&tmp_buf[j], &tmp_buf[j+1], sub(3, j)); - tmp_buf[j] = st_fx->sparse_buf_fx[i]; + tmp_buf[j] = hSpMusClas->sparse_buf_fx[i]; move16(); BREAK; } @@ -2588,9 +3670,9 @@ static void detect_sparseness_fx( /* ftmp = 0.25f*(HANG_LEN_INIT*Msp - sum_f(tmp_buf, 4)) - st->LT_sparse; */ tmp = shl(sum16_fx(tmp_buf, 4), 5); tmp = shl(sub(Msp, tmp), 1); - tmp = sub(tmp, st_fx->LT_sparse_fx); + tmp = sub(tmp, hSpMusClas->LT_sparse_fx); - st_fx->LT_sparse_fx = add(st_fx->LT_sparse_fx, shr(tmp, 2)); /* Q8 */ + hSpMusClas->LT_sparse_fx = add(hSpMusClas->LT_sparse_fx, shr(tmp, 2)); /* Q8 */ } /* find high-band sparseness */ @@ -2600,7 +3682,7 @@ static void detect_sparseness_fx( FOR (i = 0; i < HANG_LEN_INIT-1; i++) { - st_fx->hf_spar_buf_fx[i] = st_fx->hf_spar_buf_fx[i+1]; + hSpMusClas->hf_spar_buf_fx[i] = hSpMusClas->hf_spar_buf_fx[i+1]; move16(); } @@ -2620,19 +3702,19 @@ static void detect_sparseness_fx( tmp = extract_l(L_shr(L_tmp, 7)); IF (tmp == 0) { - st_fx->hf_spar_buf_fx[HANG_LEN_INIT-1] = 0; + hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT-1] = 0; move16(); } ELSE { - st_fx->hf_spar_buf_fx[HANG_LEN_INIT-1] = div_s(tmp, sumh); + hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT-1] = div_s(tmp, sumh); } tmp = 0; move16(); FOR (i = 0; i < 8; i++) { - tmp = add(tmp, shr(st_fx->hf_spar_buf_fx[i], 3)); + tmp = add(tmp, shr(hSpMusClas->hf_spar_buf_fx[i], 3)); } IF (GT_16(tmp, 6554)) { @@ -2683,38 +3765,38 @@ static void detect_sparseness_fx( /* find smoothed linear prediction efficiency */ FOR (i = 0; i < 7; i++) { - st_fx->lpe_buf_fx[i] = st_fx->lpe_buf_fx[i+1]; + hSpMusClas->lpe_buf_fx[i] = hSpMusClas->lpe_buf_fx[i+1]; move16(); } - st_fx->lpe_buf_fx[i] = st_fx->past_epsP2_fx; + hSpMusClas->lpe_buf_fx[i] = hSpMusClas->past_epsP2_fx; move16(); Mlpe = 0; move16(); FOR (i = 0; i < 8; i++) { - Mlpe = add(Mlpe, shr(st_fx->lpe_buf_fx[i], 3)); + Mlpe = add(Mlpe, shr(hSpMusClas->lpe_buf_fx[i], 3)); } /* find smoothed voicing */ FOR (i = 0; i < HANG_LEN_INIT-1; i++) { - st_fx->voicing_buf_fx[i] = st_fx->voicing_buf_fx[i+1]; + hSpMusClas->voicing_buf_fx[i] = hSpMusClas->voicing_buf_fx[i+1]; move16(); } - st_fx->voicing_buf_fx[i] = voi_fv; + hSpMusClas->voicing_buf_fx[i] = voi_fv; move16(); Mv = 0; move16(); FOR (i = 0; i < 8; i++) { - Mv = add(Mv, shr(st_fx->voicing_buf_fx[i], 3)); + Mv = add(Mv, shr(hSpMusClas->voicing_buf_fx[i], 3)); } } /* avoid using LR-MDCT on sparse spectra */ - IF (EQ_16(*sp_aud_decision1, 1)) + IF (EQ_16(st_fx->sp_aud_decision1, 1)) { tmp = 91; move16(); @@ -2725,38 +3807,38 @@ static void detect_sparseness_fx( IF (GT_16(sparse, tmp)) { - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 1; + st_fx->sp_aud_decision2 = 1; move16(); - st_fx->gsc_hangover_fx = 1; + hSpMusClas->gsc_hangover_fx = 1; move16(); } - ELSE IF (EQ_16(st_fx->gsc_hangover_fx, 1)) + ELSE IF (EQ_16(hSpMusClas->gsc_hangover_fx, 1)) { IF (GT_16(sparse, 85)) { - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 1; + st_fx->sp_aud_decision2 = 1; move16(); } ELSE { tmp = 0; move16(); - FOR (i=0; igsc_cnt_fx; i++) + FOR (i=0; igsc_cnt_fx; i++) { - tmp = add(tmp, st_fx->sparse_buf_fx[HANG_LEN_INIT-1-st_fx->gsc_cnt_fx+i]); + tmp = add(tmp, hSpMusClas->sparse_buf_fx[HANG_LEN_INIT-1-hSpMusClas->gsc_cnt_fx+i]); } - tmp1 = div_s(1, st_fx->gsc_cnt_fx); + tmp1 = div_s(1, hSpMusClas->gsc_cnt_fx); tmp = mult(tmp, tmp1); IF (LT_16(abs_s(sub(sparse, tmp)), 7)) { - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 1; + st_fx->sp_aud_decision2 = 1; move16(); } } @@ -2764,32 +3846,24 @@ static void detect_sparseness_fx( IF (EQ_16(st_fx->bwidth_fx, WB)) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF (GT_16(st_fx->LT_sparse_fx, 15360)&>_16(sparse,50)&<_16(Mlpe,-1331)&>_16(Mv,27853)&& + test();test();test();test();test();test();test();test();test(); + IF (GT_16(hSpMusClas->LT_sparse_fx, 15360) && GT_16(sparse,50) && LT_16(Mlpe,-1331) && GT_16(Mv,27853) && lb_sp_high_flag == 0 && ((hb_sp_high_flag == 0 && GT_16(sumh, mult_r(4915, sum))) || LE_16(sumh, mult_r(4915, sum)))) { - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 1; + st_fx->sp_aud_decision2 = 1; move16(); - st_fx->gsc_hangover_fx = 1; + hSpMusClas->gsc_hangover_fx = 1; move16(); } - ELSE IF (EQ_16(st_fx->gsc_hangover_fx, 1)&&!(*sp_aud_decision1==0&&*sp_aud_decision2==1)) + ELSE IF (EQ_16(hSpMusClas->gsc_hangover_fx, 1) && !(st_fx->sp_aud_decision1==0 && st_fx->sp_aud_decision2==1)) { - IF (LT_16(abs_s(sub(sparse, mean_fx(&st_fx->sparse_buf_fx[HANG_LEN_INIT-1-st_fx->gsc_cnt_fx], st_fx->gsc_cnt_fx))), 7)) + IF (LT_16(abs_s(sub(sparse, mean_fx(&hSpMusClas->sparse_buf_fx[HANG_LEN_INIT-1-hSpMusClas->gsc_cnt_fx], hSpMusClas->gsc_cnt_fx))), 7)) { - *sp_aud_decision1 = 0; + st_fx->sp_aud_decision1 = 0; move16(); - *sp_aud_decision2 = 1; + st_fx->sp_aud_decision2 = 1; move16(); } } @@ -2798,20 +3872,20 @@ static void detect_sparseness_fx( /* update the counter of consecutive GSC frames with sparse spectrum */ test(); - IF (*sp_aud_decision1 == 0 && EQ_16(*sp_aud_decision2, 1)) + IF (st_fx->sp_aud_decision1 == 0 && EQ_16(st_fx->sp_aud_decision2, 1)) { - st_fx->gsc_cnt_fx = add(st_fx->gsc_cnt_fx, 1); - IF (GT_16(st_fx->gsc_cnt_fx, 7)) + hSpMusClas->gsc_cnt_fx = add(hSpMusClas->gsc_cnt_fx, 1); + IF (GT_16(hSpMusClas->gsc_cnt_fx, 7)) { - st_fx->gsc_cnt_fx = 7; + hSpMusClas->gsc_cnt_fx = 7; move16(); } } ELSE { - st_fx->gsc_cnt_fx = 0; + hSpMusClas->gsc_cnt_fx = 0; move16(); - st_fx->gsc_hangover_fx = 0; + hSpMusClas->gsc_hangover_fx = 0; move16(); } @@ -2821,7 +3895,11 @@ static void detect_sparseness_fx( return; } - +/*---------------------------------------------------------------------* + * order_spectrum() + * + * + *---------------------------------------------------------------------*/ static void order_spectrum_fx( Word16 *vec, Word16 len diff --git a/lib_enc/stat_enc_fx.h b/lib_enc/stat_enc_fx.h index aaea555..970bec3 100644 --- a/lib_enc/stat_enc_fx.h +++ b/lib_enc/stat_enc_fx.h @@ -17,9 +17,10 @@ typedef struct { - UWord16 value; /* value of the quantized indice */ - Word16 nb_bits; /* number of bits used for the quantization of the indice */ -} Indice_fx; + Word16 id; /* id of the indice */ + UWord16 value; /* value of the quantized indice */ + Word16 nb_bits; /* number of bits used for the quantization of the indice */ +} Indice_fx, * INDICE_HANDLE; typedef struct { @@ -37,6 +38,51 @@ typedef struct Word32 s32Mantissa; } T_VAD_EXP; +/*----------------------------------------------------------------------------------* + * Bitstream structure + *----------------------------------------------------------------------------------*/ +#ifdef IVAS_CODE_BITSTREAM +typedef struct bitstream_enc_data_structure +{ + Word16 nb_ind_tot; /* total number of indices already written */ + Word16 nb_bits_tot; /* total number of bits already written */ + Indice* ind_list; /* list of indices */ + int16_t* ivas_max_num_indices; /* maximum total number of indices in the list */ + Indice** ivas_ind_list_zero; /* beginning of the buffer of indices */ + void* st_ivas; /* IVAS encoder structure */ +} BSTR_ENC_DATA, * BSTR_ENC_HANDLE; + +#else +typedef struct bitstream_enc_data_structure +{ + Word16 nb_bits_tot_fx; /* total number of bits already written */ + Indice_fx* ind_list_fx; /* list of indices */ + Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ + Word16 last_ind_fx; /* last written indice */ + +} BSTR_ENC_DATA, * BSTR_ENC_HANDLE; +#endif +/*----------------------------------------------------------------------------------* + * General Signal buffers structure + *----------------------------------------------------------------------------------*/ + +typedef struct signal_buffers_enc_data_structure +{ + Word16 input_buff[L_FRAME48k + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS)]; + + Word32 Bin_E_old_fx[L_FFT / 2]; /* per bin energy of old 2nd frames */ + Word16 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ + Word16 mem_decim16k_fx[2 * L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ + Word16 old_inp_12k8_fx[L_INP_MEM]; /* memory of input signal at 12.8kHz */ + Word16 old_inp_16k_fx[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ + + Word16 buf_speech_enc_pe[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; + Word16 buf_synth[OLD_SYNTH_SIZE_ENC + L_FRAME32k]; + Word16 buf_speech_enc[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; + Word16 buf_wspeech_enc[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k]; /*normally there is a lookahead for 12k8 and 16k but L_FRAME_MAX=L_FRAME_16K+L_NEXT_16k*/ + +} SIGNAL_BUFFERS_ENC_DATA, * SIGNAL_BUFFERS_ENC_HANDLE; + typedef struct { Word16 bw_index; /* index of band width */ @@ -96,13 +142,13 @@ typedef struct Word16 update_count; /* the number of the background update*/ Word16 warm_hang_num; /* the number of hangover for warm up*/ Word16 vad_flag_for_bk_update; -} T_CldfbVadState; +} T_CldfbVadState, * VAD_CLDFB_HANDLE; /*ari.h*/ typedef struct { Word32 low,high; - Word16 vobf; + Word16 value; } TastatEnc; /*---------------------------------------------------------------* @@ -115,7 +161,7 @@ typedef struct Word16 bitCount; Word16 prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block, short or long */ Word16 prevSave[64]; - Word16 scfCountLongBlock; + Word16 scfCountLongBlock[IGF_NOF_GRIDS]; Word16 t; Word16 tSave; Word16 context_saved; @@ -147,7 +193,7 @@ typedef struct igf_enc_private_data_struct Word16 prevSFM_IIR[IGF_MAX_TILES]; /* 2Q13 */ Word16 wasTransient; /* 15Q0 */ - UWord8 igfBitstream[BITBUFSIZE/8]; + UWord8 igfBitstream[IGF_BITBUFSIZE /8]; Word16 igfBitstreamBits; } IGF_ENC_PRIVATE_DATA, *IGF_ENC_PRIVATE_DATA_HANDLE; @@ -155,17 +201,17 @@ typedef struct igf_enc_private_data_struct typedef struct igf_enc_instance_struct { IGF_ENC_PRIVATE_DATA igfData; - Word32 infoSamplingRate; - Word16 infoStartFrequency; - Word16 infoStopFrequency; - Word16 infoStartLine; - Word16 infoStopLine; - Word16 infoTotalBitsWritten; - Word16 infoTotalBitsPerFrameWritten; - Word16 flatteningTrigger; - Word32 spec_be_igf[N_MAX_TCX-IGF_START_MN]; /* copy of MDCT spectrum */ - Word16 spec_be_igf_e; /* exponent of copy of MDCT spectrum */ - Word16 tns_predictionGain; + Word32 infoSamplingRate; + Word16 infoStartFrequency; + Word16 infoStopFrequency; + Word16 infoStartLine; + Word16 infoStopLine; + Word16 infoTotalBitsWritten; + Word16 infoTotalBitsPerFrameWritten; + Word16 flatteningTrigger; + Word32 spec_be_igf[N_MAX_TCX-IGF_START_MN]; /* copy of MDCT spectrum */ + Word16 spec_be_igf_e; /* exponent of copy of MDCT spectrum */ + Word16 tns_predictionGain; } IGF_ENC_INSTANCE, *IGF_ENC_INSTANCE_HANDLE; @@ -183,18 +229,16 @@ typedef struct Word16 tilt_code; Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ Word16 mem_syn3[M]; + struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ /* ACELP memory */ Word16 old_exc[L_EXC_MEM]; /* ACELP exc memory (Aq) */ - /* TCX memory */ - Word16 Txnq[L_FRAME32k/2+64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ - Word16 *acelp_zir; - Word16 tcx_target_bits_fac; Word32 gc_threshold; /* exponent = 15, 15Q16 */ + Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ -} LPD_state; +} LPD_state, * LPD_state_HANDLE; typedef struct PLC_ENC_EVS @@ -230,9 +274,96 @@ typedef struct PLC_ENC_EVS Word16 lsf_con[M]; Word16 last_lsf_ref[M]; Word16 last_lsf_con[M]; -} PLC_ENC_EVS, *HANDLE_PLC_ENC_EVS; +} PLC_ENC_EVS, * PLC_ENC_EVS_HANDLE; + + +/*------------------------------------------------------------------------------------------* + * TCX encoder + *------------------------------------------------------------------------------------------*/ + +typedef struct tcx_enc_structure +{ + int16_t L_frameTCX; + + int16_t tcxMode; /* Chosen TCX mode for this frame */ + //int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ + + /* Core Signal Analysis Outputs */ + //float* spectrum[2]; /* MDCT output for a short block */ + //float spectrum_long[N_MAX]; /* MDCT output for a long block. Points to spectrum */ + + Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling */ + Word16 noiseLevelMemory; /* counter of consecutive low TCX noise levels */ + //float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ + STnsData tnsData[2]; + Word8 fUseTns[2]; + //int16_t bTnsOnWhithenedSpectra[2]; + + Word8 memQuantZeros[L_FRAME_PLUS]; + + Word16* speech_TCX; + Word16* new_speech_TCX; + + /* TCX-LTP */ + Word8 tcxltp; + Word16 tcxltp_pitch_int; + Word16 tcxltp_pitch_fr; + Word16 tcxltp_gain; + Word16 tcxltp_pitch_int_past; + Word16 tcxltp_pitch_fr_past; + Word16 tcxltp_gain_past; + Word16 tcxltp_norm_corr_past; + //float tcxltp_norm_corr_mem; + //float kernel_switch_corr_past; + + //uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ + //uint16_t kernel_symmetry_past; /* last TDA symmetry (0 for MDCT, 1 for MDST type) */ + //uint16_t enc_ste_pre_corr_past; + //float tfm_mem; /* state of IIR filtered temporal flatness measure */ + Word16 buf_speech_ltp[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; + Word16* speech_ltp; + Word16* new_speech_ltp; + //int16_t tcxltp_filt_idx; + Word16 tcxltp_bits; + Word16 tcxltp_param[LTPSIZE]; + //int16_t tcxltp_on_mem; + + Word16 measuredBwRatio; /* measured bw; used for TCX noise-filling. 1Q14 */ + Word16 nmStartLine; /* Starting line for the noise measurement. Q0 */ + + Word16 tcx_lpc_shaped_ari; + + + Word16 old_out_fx[L_FRAME32k]; /* buffer for OLA; at the encoder, the maximum length is L_FRAME32k (corresponds to maximum internal L_frame length) */ + Word16 Q_old_out; + + + /* MDCT switching */ + Word16 prev_hi_ener; + Word16 prev_hi_sparse; + Word16 clas_sec_old_fx; /* MDCT classifier secondary decision memory */ + Word16 clas_final_old_fx; /* MDCT classifier final decision memory */ + Word32 last_gain1; + Word32 last_gain2; + /* TCX memory */ + Word16 Txnq[L_FRAME32k / 2 + 64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ + Word16* acelp_zir; + Word16 tcx_target_bits_fac; + + Word16 tns_ms_flag[2]; + +} TCX_ENC_DATA, * TCX_ENC_HANDLE; +typedef struct tec_enc_structure +{ + Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC]; + Word16 loTempEnv[CLDFB_NO_COL_MAX]; + Word16 loTempEnv_ns[CLDFB_NO_COL_MAX]; + Word16 hiTempEnv[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV]; + Word16 tranFlag; + Word16 corrFlag; +} TEC_ENC_DATA, * TEC_ENC_HANDLE_FX; /*****************************************/ /* MODE2 STAT ENC */ /*****************************************/ @@ -278,6 +409,8 @@ typedef struct /** High-pass filter states (delay line) */ Word16 firState1; Word16 firState2; + + UWord16 ramp_up_flag; /* bit map flags to indicate a ramp up in beginning of TCX frame */ } SubblockEnergies; @@ -311,6 +444,8 @@ typedef struct TransientDetector TCheckSubblocksForAttack CheckSubblocksForAttack; /** Attack ratio threshold. */ Word16 attackRatioThreshold; + /* True if an attack was detected in the previous frame. */ + Word16 prev_bIsAttackPresent; /** True when an attack was detected. */ Word16 bIsAttackPresent; /** The index of an attack. */ @@ -378,346 +513,851 @@ typedef struct FD_CNG_ENC; typedef FD_CNG_ENC *HANDLE_FD_CNG_ENC; +/*------------------------------------------------------------------------------------------* +* VAD structures +*------------------------------------------------------------------------------------------*/ - -typedef struct Encoder_State_fx +typedef struct vad_structure { + Word16 nb_active_frames_fx; + Word16 hangover_cnt_fx; + Word16 nb_active_frames_he_fx; + Word16 hangover_cnt_he_fx; + /* should be L_var */ + Word32 L_vad_flag_reg_H_fx; + Word32 L_vad_flag_reg_L_fx; + Word32 L_vad_prim_reg_fx; - /*----------------------------------------------------------------------------------* - * Common parameters - *----------------------------------------------------------------------------------*/ + Word16 vad_flag_cnt_50_fx; + Word16 vad_prim_cnt_16_fx; - Word16 codec_mode; /* MODE1 or MODE2 */ - Word16 last_codec_mode; /* Previous Codec Mode*/ - Word16 last_codec_mode_cng; /* Codec Mode of the last inactive frame*/ - Word16 mdct_sw_enable; /* MDCT switching enable flag */ - Word16 mdct_sw; /* MDCT switching indicator */ - Word16 prev_hi_ener; - Word16 prev_hi_sparse; - Word16 clas_sec_old_fx; /* MDCT classifier secondary decision memory */ - Word16 clas_final_old_fx; /* MDCT classifier final decision memory */ - Word32 last_gain1; - Word32 last_gain2; - Word16 last_enerBuffer_exp; - Word16 nb_bits_tot_fx; /* total number of bits already written */ - Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ - Indice_fx *ind_list_fx; /* list of indices */ - Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ - Word16 last_ind_fx; /* last written indice */ - Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ + Word16 hangover_cnt_dtx_fx; + Word16 hangover_cnt_music_fx; - Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ - Word32 total_brate_fx; /* total bitrate in kbps of the codec */ - Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ - Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ - Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - Word32 core_brate_fx; /* core bitrate */ - Word32 last_core_brate_fx; /* previous frame core bitrate */ - Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ - Word16 extl_fx; /* extension layer */ - Word16 last_extl_fx; /* previous extension layer */ - Word32 extl_brate_fx; /* extension layer bitrate */ - Word16 input_bwidth_fx; /* input signal bandwidth */ - Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ - Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ - Word16 max_bwidth_fx; /* maximum encoded bandwidth */ - Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ - Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ - Word16 L_frame_fx; /* ACELP core internal frame length */ - Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode */ - Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ - Word16 cng_type_fx; /* flag indicating LP or CLDFB based SID/CNG */ - Word16 active_fr_cnt_fx; /* counter of active frames */ - Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ - Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ + Word16 bcg_flux_fx; + Word16 soft_hangover_fx; + Word16 voiced_burst_fx; + Word16 bcg_flux_init_fx; + Word16 nb_active_frames_he1_fx; + Word16 hangover_cnt_he1_fx; + + Word16 prim_act_quick_fx; /* Noise estimator - primary activity quick */ + Word16 prim_act_slow_fx; /* Noise estimator - primary activity slow */ + Word16 prim_act_fx; /* Noise estimator - primary activity slow rise quick fall */ + Word16 prim_act_quick_he_fx; /* Noise estimator - primary activity quick */ + Word16 prim_act_slow_he_fx; /* Noise estimator - primary activity slow */ + Word16 prim_act_he_fx; /* Q15 Noise estimator - primary activity slow rise quick fall */ + + Word16 spectral_tilt_reset_fx; + Word16 consec_inactive_fx; + Word16 ra_deltasum_fx; + Word16 trigger_SID_fx; + Word16 running_avg_fx; /*Q15 */ + Word32 L_snr_sum_vad_fx; /*Q4*/ + + Word16 hangover_terminate_flag_fx; /* CNG and DTX - flag indicating whether to early terminate DTX hangover */ + Word16 vad_flag_fx; /* VAD flag */ + +} VAD_DATA, * VAD_HANDLE; +/*------------------------------------------------------------------------------------------* +* DTX and TD CNG structure +*------------------------------------------------------------------------------------------*/ + +typedef struct td_cng_enc_structure +{ Word16 lp_cng_mode2; + Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG */ + Word16 cng_seed_fx; /* CNG and DTX - seed for white noise random generator */ + Word16 old_enr_index_fx; /* CNG and DTX - index of last encoded CNG energy */ + Word32 Enew_fx; /* CNG and DTX - CNG target residual energy */ + Word16 cng_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ + Word16 cng_lsp_hist_fx[DTX_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ + Word16 cng_ener_seed_fx; /* CNG and DTX - seed for random generator for variation of excitation energy */ + Word16 cng_ener_seed1_fx; + Word16 lp_sp_enr_fx; /*Q8*/ + Word16 last_allow_cn_step_fx; + Word16 ho_hist_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ + Word32 ho_sid_bw_fx; /* CNG and DTX - SID bandwidth flags */ + Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ + Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; + Word16 act_cnt_fx; /* CNG and DTX - counter of active frames */ + Word16 ho_circ_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_circ_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ + Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ + Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ + Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; + Word16 burst_ho_cnt_fx; /* CNG and DTX - counter of hangover frames at end of active burst */ + Word16 cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ + Word16 cng_exc2_buf[HO_HIST_SIZE * L_FFT]; /* CNG and DTX - exc2 buffer for storing */ + Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ + Word32 cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ + + //float CNG_att; IVAS only?? /* CNG and DTX - attenuation factor for CNG, in dB */ + Word16 ho_16k_lsp_fx[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ + Word16 act_cnt2_fx; /* CNG and DTX - counter of active frames for CNG_mode switching */ + Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ + Word16 num_ho_fx; /* CNG and DTX - number of selected hangover frames */ + Word32 old_env_fx[NUM_ENV_CNG]; + Word32 lp_env_fx[NUM_ENV_CNG]; + Word32 cng_res_env_fx[NUM_ENV_CNG * HO_HIST_SIZE]; + Word16 exc_mem_fx[24]; + Word16 exc_mem1_fx[30]; + Word16 exc_mem2_fx[30]; + /*----------------------------------------------------------------------------------* - * ACELP core parameters + * SWB DTX/CNG parameters *----------------------------------------------------------------------------------*/ - Word16 clas_fx; /* current frame clas */ - Word16 last_clas_fx; /* previous frame signal classification */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word32 Bin_E_old_fx[L_FFT/2]; /* per bin energy of old 2nd frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - Word16 pstreaklen_fx; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer */ - Word32 offset_scale1_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ - Word32 offset_scale2_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ - Word32 offset_scale1_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ - Word32 offset_scale2_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ - Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ - Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 stab_fac_fx; /* LSF stability factor */ - Word16 mem_decim_fx[2*L_FILT_MAX]; /* decimation filter memory */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word16 mem_preemph_fx; /* preemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 old_inp_12k8_fx[L_INP_MEM]; /* memory of input signal at 12.8kHz */ - Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ - Word16 old_wsp2_fx[(L_WSP_MEM - L_INTERPOL)/OPL_DECIM]; /* old decimated weighted signal vector qwsp */ + Word16 last_vad_fx; + Word16 last_wb_cng_ener_fx; + Word16 last_shb_cng_ener_fx; + Word16 mov_wb_cng_ener_fx; + Word16 mov_shb_cng_ener_fx; + //int16_t last_idx_ener; IVAS only? + Word16 shb_cng_ini_cnt_fx; + Word16 last_SID_bwidth_fx; + Word16 shb_NO_DATA_cnt_fx; + +} TD_CNG_ENC_DATA, * TD_CNG_ENC_HANDLE; +/*----------------------------------------------------------------------------------* + * Noise estimation structure + *----------------------------------------------------------------------------------*/ + +typedef struct noise_estimation_structure +{ Word32 fr_bands1_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands of the previous frame */ Word32 fr_bands2_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands 2 frames ago */ - Word16 mem_wsp_fx; /* weighted signal vector memory */ - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - - Word16 clip_var_fx[6]; - Word16 past_qua_en_fx[4]; - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - Word16 coder_type_raw_fx; - Word16 last_coder_type_raw_fx; /* raw last_coder_type (coming from the sigal classification) */ - Word16 last_coder_type_fx; /*Q0 previous coding type */ - Word16 ini_frame_fx; /* initialization frames counter */ - Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ - Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ - Word16 old_pitch; /* previous pitch for open-loop pitch search Q0 */ - Word16 delta_pit_fx; /* open-loop pitch extrapolation correction Q0 */ - Word32 ee_old_fx; - Word16 min_band_fx; /* Q0 minimum critical band of useful bandwidth */ - Word16 max_band_fx; /* Q0 maximum critical band of useful bandwidth */ - Word16 tc_cnt_fx; /* TC frame counter */ - Word16 audio_frame_cnt_fx; /* Counter of relative presence of audio frames */ - Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ - Word16 old_ind_deltaMax_fx; /* Index of the sub-subframe of maximum energy in previous frame */ - Word32 old_enr_ssf_fx[2*NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ - Word16 spike_hyst_fx; /* Hysteresis to prevent UC after sharp energy spike */ - Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ - Word16 last_harm_flag_acelp_fx; /* harmonicity flag for ACELP @32kbps rate */ - Word16 old_Aq_12_8_fx[M+1]; /* Q12 old Aq[] for core switching */ - Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ - Word16 high_stable_cor_fx; /* flag for stable high correlation */ - Word16 seed_tcx_fx ; /* AC mode (GSC) - seed for noise fill*/ - Word16 cor_strong_limit_fx; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ - Word16 mem_last_pit_band_fx; /* AC mode (GSC) - memory of the last band where pitch contribution was significant */ + Word16 old_S_fx[L_FFT / 2]; /* Q7 Tonal detector - prev. log-energy spectrum with subtracted floor */ + Word16 cor_map_fx[L_FFT / 2]; /* Q15 Tonal detector - LT correlation map */ + Word16 noise_char_fx; /* Q11 Tonal detector - LT noise character */ + Word32 ave_enr2_fx[NB_BANDS]; /* Q_new + Q_SCALE Tonal detector - LT average E per crit. band (for non_sta2) */ + Word16 act_pred_fx; /* Q15 Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ + Word16 multi_harm_limit_fx; /* Q9 Tonal detector - adaptive threshold */ + Word32 enrO_fx[NB_BANDS]; /* Noise estimator - previous energy per critical band */ + Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ + Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ + Word16 aEn_fx; /* Q0 Noise estimator - noise estimator adaptation flag */ + Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ + Word16 first_noise_updt_fx; /* Q0 Noise estimator - flag used to determine if the first noise update frame */ + //int16_t first_noise_updt_cnt; /* IVA?? Noise estimator - counter of frame after first noise update */ + Word16 harm_cor_cnt_fx; /* Q0 Noise estimator - 1st memory counter of harm or correlation frame */ + Word16 bg_cnt_fx; /* Q0 Noise estimator - pause length counter */ + Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ + Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ + Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ + Word16 Etot_last_fx; /*Q8*/ + Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ + Word16 lt_tn_track_fx; /* Q15 */ + Word16 lt_tn_dist_fx; /* Q8*/ + Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ + Word16 lt_haco_ev_fx; /* Q15 */ + Word16 low_tn_track_cnt_fx; /* Q0 */ + Word16 epsP_0_2_lp_fx; /* Q12, all epsP quotas , range ]8.0 ..0]*/ + Word16 epsP_0_2_ad_lp_fx; + Word16 epsP_2_16_lp_fx; + Word16 epsP_2_16_lp2_fx; + Word16 epsP_2_16_dlp_lp2_fx; /* Q12 */ + Word16 lt_aEn_zero_fx; /* Q15 */ + + Word16 Etot_v_h2_fx; + Word16 sign_dyn_lp_fx; /*Q8*/ + Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ + Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ + //int16_t aEn_inac_cnt; IVAS ?? + +} NOISE_EST_DATA, * NOISE_EST_HANDLE; +/*------------------------------------------------------------------------------------------* + * Structure for DTX-related variables used in both FD- and TD-CNG + *------------------------------------------------------------------------------------------*/ + +typedef struct dtx_enc_structure +{ + Word16 cnt_SID_fx; /* CNG and DTX - counter of SID update for the interop. mode or dtx, if enabled*/ + Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag */ + Word16 cng_cnt_fx; /* CNG and DTX - counter of CNG frames for averaging */ + Word16 max_SID_fx; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ + Word16 CNG_mode_fx; /* CNG and DTX - mode for DTX configuration */ + Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps */ + Word16 VarDTX_cnt_voiced_fx; /* CNG and DTX - counter for variable DTX activation (speech) */ + Word16 VarDTX_cnt_noise_fx; /* CNG and DTX - counter for variable DTX activation (noise) */ + Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ + Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise */ + Word32 frame_ener_fx; + Word16 cng_hist_size_fx; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ + Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame */ + Word16 last_CNG_L_frame_fx; /* CNG and DTX - last CNG frame length */ + Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ + Word16 interval_SID_fx; /* CNG and DTX - interval of SID update, default 8 */ + Word32 last_active_brate_fx; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ + +} DTX_ENC_DATA, * DTX_ENC_HANDLE; +/*----------------------------------------------------------------------------------* + * Speech/music classifier structure + *----------------------------------------------------------------------------------*/ + +typedef struct sp_mus_clas_structure +{ + //float FV_st[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector */ + Word32 past_PS_fx[HIGHEST_FBIN - LOWEST_FBIN]; + Word16 past_ps_diff_fx; + //float prev_FV[N_SMC_FEATURES]; + Word16 past_epsP2_fx; + //float past_epsP; + Word16 inact_cnt_fx; + Word16 wdrop_fx; + //float wrise; + Word16 wdlp_0_95_sp_fx; + //float wdlp_xtalk; + Word16 sp_mus_state_fx; + Word16 past_dec_fx[HANG_LEN - 1]; + Word16 past_dlp_fx[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions */ + + //float past_dlp_mean_ST[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ + //float dlp_mean_ST; + //int16_t flag_spitch_cnt; + //float dlp_mean_LT; + //float dlp_var_LT; + Word16 last_lsp_fx[M_LSP_SPMUS]; + Word16 last_cor_map_sum_fx; + Word16 last_non_sta_fx; + Word16 past_log_enr_fx[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ + Word16 gsc_thres_fx[4]; /* Speech/music classifier - classification threshold */ + Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ + Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory */ + Word16 gsc_last_music_flag_fx; /* Speech/music classifier - last music flag */ + Word16 gsc_nb_thr_1_fx; /* Speech/music classifier - number of consecutives frames of level 1 */ + Word16 gsc_nb_thr_3_fx; /* Speech/music classifier - number of consecutives frames of level 3 */ + + Word16 mold_corr_fx; + Word16 mean_avr_dyn_fx; /* Q7 Speech/music classifier - long term average dynamic */ + Word16 last_sw_dyn_fx; /* Q7 Speech/music classifier - last dynamic */ + Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values */ + Word16 ener_RAT_fx; /* Q15 Speech/music classifier - LF/to total energy ratio */ + + //int16_t relE_attack_cnt; + //float prev_relE; + //float prev_Etot; + //int16_t prev_vad; + //int16_t vad_0_1_cnt; + //float relE_attack_sum; + + /* speech/music classifier improvement parameters */ + Word16 old_Bin_E_fx[3 * N_OLD_BIN_E]; + Word16 buf_flux_fx[BUF_LEN]; + Word16 buf_pkh_fx[BUF_LEN]; + Word16 buf_epsP_tilt_fx[BUF_LEN]; + Word16 buf_cor_map_sum_fx[BUF_LEN]; + Word16 buf_Ntonal_fx[BUF_LEN]; + Word16 buf_Ntonal2_fx[BUF_LEN]; + Word16 buf_Ntonal_lf_fx[BUF_LEN]; + Word16 buf_dlp_fx[10]; + Word16 onset_cnt_fx; + Word16 buf_etot_fx[4]; + Word16 attack_hangover_fx; + Word16 dec_mov_fx; + Word16 dec_mov1_fx; + Word16 mov_log_max_spl_fx; + Word16 old_lt_diff_fx[2]; + Word16 UV_cnt1_fx; + Word16 LT_UV_cnt1_fx; + + + //float finc_prev[ATT_NSEG]; /* strong attack detection - previous finc */ + //float lt_finc; /* strong attack detection - long-term finc energy */ + //int16_t last_strong_attack; /* strong attack detection - last strong attack flag */ + //float tod_lt_Bin_E[TOD_NSPEC]; /* tonal detector - long-term energy spectrum */ + //float tod_S_map_lt[TOD_NSPEC]; /* tonal detector - long-term correlation map */ + //float tod_thr_lt; /* tonal detector - adaptive threshold */ + //float tod_weight; /* tonal detector - adaptive weight */ + //float tod_S_mass_prev; + //float tod_S_mass_lt; + + Word16 lt_music_hangover_fx; + Word16 tonality2_buf_fx[HANG_LEN_INIT]; + Word16 tonality3_buf_fx[HANG_LEN_INIT]; + Word16 LPCErr_buf_fx[HANG_LEN_INIT]; + Word16 lt_music_state_fx; + Word16 lt_speech_state_fx; + Word16 lt_speech_hangover_fx; + + Word16 lpe_buf_fx[HANG_LEN_INIT]; + Word16 voicing_buf_fx[HANG_LEN_INIT]; + Word16 gsc_hangover_fx; + Word16 sparse_buf_fx[HANG_LEN_INIT]; + Word16 hf_spar_buf_fx[HANG_LEN_INIT]; + Word16 LT_sparse_fx; + Word16 gsc_cnt_fx; + + /* speech/music classification */ + Word16 lt_old_mode[3]; + Word16 lt_voicing; + Word16 lt_corr; + Word32 lt_tonality; + Word16 lt_corr_pitch[3]; + Word16 lt_hangover; + Word16 lowrate_pitchGain; + + //float tdm_lt_Etot; + Word16 var_cor_t_fx[VAR_COR_LEN]; + Word16 high_stable_cor_fx; /* flag for stable high correlation */ + + + Word16 lps_fx; + Word16 lpm_fx; + + //float lpn; + +} SP_MUS_CLAS_DATA, * SP_MUS_CLAS_HANDLE; + +/*----------------------------------------------------------------------------------* +* GSC static variables +*----------------------------------------------------------------------------------*/ + +typedef struct gsc_enc_structure +{ + Word16 seed_tcx_fx; /* AC mode (GSC) - seed for noise fill*/ + Word16 cor_strong_limit_fx; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + Word16 mem_last_pit_band_fx; /* AC mode (GSC) - memory of the last band where pitch contribution was significant */ Word16 mem_w0_tmp_fx; Word16 mem_syn_tmp_fx[M]; - Word16 var_cor_t_fx[VAR_COR_LEN]; Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ Word16 noise_lev_fx; /* AC mode (GSC) - Q0 noise level */ Word16 past_dyn_dec_fx; /* AC mode (GSC) - Past noise level decision */ Word32 Last_frame_ener_fx; /* AC mode (GSC) - Last frame energy */ Word16 pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching*/ + Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous exciation */ + //float last_ener; /* AC mode (GSC) - previous energy */ + Word16 last_bitallocation_band_fx[6]; /* AC mode (GSC) - previous bit allocation of each band */ + Word16 lt_gpitch_fx; /*Q15 */ +} GSC_ENC_DATA, * GSC_ENC_HANDLE; + +/*----------------------------------------------------------------------------------* + * HQ core structure + *----------------------------------------------------------------------------------*/ + +typedef struct hq_enc_structure +{ + Word16 mode_count_fx; /* HQ_HARMONIC mode count */ + Word16 mode_count1_fx; /* HQ_NORMAL mode count */ + Word16 prev_Npeaks_fx; /* number of peaks in previous frame */ + Word16 prev_peaks_fx[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ + Word16 hvq_hangover_fx; + Word16 prev_hqswb_clas_fx; + Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; + + Word16 hq_generic_speech_class_fx; + //float crest_lp; IVAS_CODE /* Low-pass filtered crest of high band */ + //float crest_mod_lp; IVAS_CODE/* Low-pass filtered noise band detection */ + + /* SWB BWE LR classification */ + Word16 prev_frm_index_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + Word16 prev_frm_hfe2_fx; + Word16 prev_stab_hfe2_fx; + Word16 prev_ni_ratio_fx; /* 15 */ + Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ + + Word16 last_bitalloc_max_band_fx[2]; + Word32 last_ni_gain_fx[BANDS_MAX]; + Word16 last_env_fx[BANDS_MAX]; + Word16 last_max_pos_pulse_fx; + + +} HQ_ENC_DATA, * HQ_ENC_HANDLE; + +/* PVQ range coder state */ +typedef struct pvq_enc_structure +{ + UWord32 rc_low_fx; + UWord32 rc_range_fx; + Word16 rc_cache_fx; + Word16 rc_carry_fx; + Word16 rc_carry_count_fx; + Word16 rc_num_bits_fx; + Word16 rc_tot_bits_fx; + Word16 rc_offset_fx; + + +} PVQ_ENC_DATA, * PVQ_ENC_HANDLE; + +/*----------------------------------------------------------------------------------* + * SC-VBR structure + *----------------------------------------------------------------------------------*/ + +typedef struct sc_vbr_enc_structure +{ + Word16 vadsnr_fx; /*Q7*/ + Word16 vadnoise_fx; + + /* NELP variables */ + Word16 shape1_filt_mem_fx[10]; + Word16 shape2_filt_mem_fx[10]; + Word16 shape3_filt_mem_fx[10]; + Word16 txlpf1_filt1_mem_fx[10]; + Word16 txlpf1_filt2_mem_fx[10]; + Word16 txhpf1_filt1_mem_fx[10]; + Word16 txhpf1_filt2_mem_fx[10]; + + Word16 bp1_filt_mem_wb_fx[8]; + Word16 nelp_lp_fit_mem[NELP_LP_ORDER * 2]; + Word32 bp1_filt_mem_nb_fx[14]; + + Word16 nelp_enc_seed_fx; + Word16 nelp_gain_mem_fx; + Word16 last_nelp_mode_fx; + Word16 nelp_mode_fx; + + Word16 qprevIn_fx; + Word16 qprevGain_fx; + + /* PPP variables */ + Word16 pppcountE_fx; + Word16 bump_up_fx; /*Q0*/ + Word16 last_ppp_mode_fx; /*Q0*/ + Word16 last_last_ppp_mode_fx; + + Word16 ppp_mode_fx; + Word16 prev_ppp_gain_pit_fx; /*Q14*/ + Word16 prev_tilt_code_fx; + + /* voiced encoder variables */ + Word16 firstTime_voicedenc_fx; /*Q0*/ + + /* DTFS variables */ + Word16 dtfs_enc_a_fx[MAXLAG_WI]; /*Q0*/ + Word16 dtfs_enc_b_fx[MAXLAG_WI]; /*Q0*/ + Word16 dtfs_enc_lag_fx; + Word16 dtfs_enc_nH_fx; + Word16 dtfs_enc_nH_4kHz_fx; + Word16 dtfs_enc_upper_cut_off_freq_of_interest_fx; + Word16 dtfs_enc_upper_cut_off_freq_fx; + Word16 dtfs_enc_Q; + + Word32 prev_cw_en_fx; /*Q_prev_cw_en_fx*/ + Word16 ph_offset_E_fx; /*Q15 normalized y 2*Pi */ + Word16 lastLgainE_fx; /*Q11 Previous gain value for the low band */ + Word16 lastHgainE_fx; /*Q11 Previous gain value for the high band */ + Word16 lasterbE_fx[NUM_ERB_WB]; /*Q13 Previous Amplitude spectrum (ERB) */ + Word16 Q_prev_cw_en_fx; + + Word16 mode_QQF_fx; + Word16 rate_control_fx; + Word16 SNR_THLD_fx; + Word16 Q_to_F_fx; + Word16 pattern_m_fx; + Word16 patterncount_fx; + Word16 Last_Resort_fx; + Word16 numactive_fx; /* keep the count of the frames inside current 600 frame bloack.*/ + Word32 sum_of_rates_fx; /* sum of the rates of past 600 active frames*/ + Word32 global_avr_rate_fx; /* global rate upto current time. recorded a (rate in kbps) *6000*/ + + // int16_t global_frame_cnt; /* 600 active frame block count. Used to update the global rate */ + Word16 set_ppp_generic_fx; + Word16 avoid_HQ_VBR_NB; + + Word16 vbr_generic_ho_fx; + Word16 last_7k2_coder_type_fx; + Word16 Local_VAD; + Word16 frame_cnt_ratewin_fx; /* keep count of how many ratewin (600) windows */ + +} SC_VBR_ENC_DATA, * SC_VBR_ENC_HANDLE; + +/*----------------------------------------------------------------------------------* + * AMR-WB IO mode structure + *----------------------------------------------------------------------------------*/ + +typedef struct amrwb_io_enc_structure +{ + Word16 past_qua_en_fx[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ + + /*----------------------------------------------------------------------------------* + * HF WB BWE for AMR-WB IO mode at 23.85 kbps + *----------------------------------------------------------------------------------*/ + + Word16 gain_alpha_fx; + Word16 mem_hf2_enc_fx[L_FIR - 1]; + Word16 mem_hp400_enc_fx[6]; + Word16 mem_hf_enc_fx[L_FIR - 1]; + Word16 mem_syn_hf_enc_fx[M]; + Word16 seed2_enc_fx; + +} AMRWB_IO_ENC_DATA, * AMRWB_IO_ENC_HANDLE; + + +/*----------------------------------------------------------------------------------* + * TD BWE structure + *----------------------------------------------------------------------------------*/ + +typedef struct td_bwe_enc_structure +{ + Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ + Word16 old_speech_wb_fx[(L_LOOK_12k8 + L_SUBFR) * 5 / 16]; /* Buffer memories */ + Word16 old_input_fhb_fx[NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k / 2]; + Word16 old_input_fhb_fx_Q; + + Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; + + Word16 state_ana_filt_shb_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + Word16 cldfbHBLT; + /* states for the filters used in generating SHB excitation from WB excitation*/ + Word32 mem_csfilt_fx[2]; + + //float mem_shb_res[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ + //float old_EnvSHBres[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ + //float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ + //float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ + //float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ + //float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ + //float prev_mix_factor; /* mixing factor in the previous frame */ + //float prev_Env_error; /* error in SHB envelope modelling */ + + /* states for the filters used in generating SHB signal from SHB excitation*/ + Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; + Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; + Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ + Word16 bwe_seed_fx[2]; + Word32 bwe_non_lin_prev_scale_fx; /*Q30*/ + Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; + Word16 syn_overlap_fx[L_SHB_LAHEAD]; + Word16 decim_state1_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + Word16 decim_state2_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + Word16 mem_genSHBexc_filt_down_wb2_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + Word16 mem_genSHBexc_filt_down_wb3_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + Word16 mem_genSHBexc_filt_down_shb_fx[(2 * ALLPASSSECTIONS_STEEP + 1)]; + + Word32 elliptic_bpf_2_48k_mem_fx[4][4]; + Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; + Word32 prev_fb_energy_fx; + Word16 prev_fb_energy_fx_Q; + Word32 prev_gainFr_SHB_fx; + Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; + Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; + Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; + Word16 lsp_shb_spacing_fx[3]; + Word16 prev_swb_GainShape_fx; + Word16 prev_frGainAtten_fx; + + Word16 prev_wb_GainShape; + Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; + Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; + Word16 prev_Q_bwe_exc_fb; + Word16 fb_tbe_demph_fx; + Word16 tilt_mem_fx; + + Word16 prev_coder_type_fx; + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; + Word16 prev_tilt_para_fx; + Word16 cur_sub_Aq_fx[M + 1]; + + /* quantized data */ + Word16 lsf_idx_fx[NUM_Q_LSF]; + Word16 m_idx_fx; + Word16 grid_idx_fx; + Word16 idxSubGains_fx; + Word16 idxFrameGain_fx; + Word16 idx_shb_fr_gain_fx; + Word16 idx_res_gs_fx[NB_SUBFR16k]; + Word16 idx_mixFac_fx; + + Word16 lsf_WB_fx; + Word16 gFrame_WB_fx; + + Word16 idxGain_fx; + Word16 dec_2_over_3_mem_fx[12]; + Word16 dec_2_over_3_mem_lp_fx[6]; + + Word16 tbe_demph_fx; + Word16 tbe_premph_fx; + Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; + Word16* ptr_mem_stp_swb_fx; + Word16 gain_prec_swb_fx; + Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; + +} TD_BWE_ENC_DATA, * TD_BWE_ENC_HANDLE; + +/*----------------------------------------------------------------------------------* + * FD BWE structure + *----------------------------------------------------------------------------------*/ + +typedef struct fd_bwe_enc_structure +{ + + Word16 new_input_hp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)]; + Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS)]; + Word16 old_input_wb_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; + Word16 old_input_lp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS)]; + Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; + Word16 old_fdbwe_speech_fx[L_FRAME48k]; + Word16 mem_deemph_old_syn_fx; + Word16 prev_mode_fx; + Word16 L_old_wtda_swb_fx[L_FRAME48k]; + + Word16 prev_Q_input_lp; + Word16 prev_L_swb_norm1_fx; + Word32 prev_global_gain_fx; + Word16 modeCount_fx; + Word32 EnergyLF_fx; + //float mem_old_wtda_swb; + +} FD_BWE_ENC_DATA, * FD_BWE_ENC_HANDLE; + +/*----------------------------------------------------------------------------------* + * Channel-aware mode + *----------------------------------------------------------------------------------*/ + +typedef struct rf_enc_structure +{ + int16_t rf_frame_type; + int16_t rf_targetbits_buff[MAX_RF_FEC_OFFSET]; + int16_t rf_indx_frametype[MAX_RF_FEC_OFFSET]; + + ACELP_config acelp_cfg_rf; /* configuration for RF frame */ + + Word16 rf_mem_w0; + Word16 rf_clip_var[6]; + Word16 rf_tilt_code; + Word16 rf_mem_syn2[M]; + struct dispMem_fx rf_dm_fx; + Word32 rf_gc_threshold; + + Word16 rf_target_bits; + Word16 rf_tilt_buf[NB_SUBFR16k]; + + Word16 rf_indx_lsf[MAX_RF_FEC_OFFSET][3]; + Word16 rf_indx_pitch[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + Word16 rf_indx_fcb[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + Word16 rf_indx_gain[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + Word16 rf_indx_EsPred[MAX_RF_FEC_OFFSET]; + Word16 rf_indx_ltfMode[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + + Word16 rf_indx_nelp_fid[MAX_RF_FEC_OFFSET]; + Word16 rf_indx_nelp_iG1[MAX_RF_FEC_OFFSET]; + Word16 rf_indx_nelp_iG2[MAX_RF_FEC_OFFSET][2]; + + Word16 rf_indx_tbeGainFr[MAX_RF_FEC_OFFSET]; + + Word16 rf_tcxltp_pitch_int_past; + Word16 rf_last_tns_active; + Word16 rf_second_last_tns_active; + Word16 rf_second_last_core; + Word16 rf_clas[MAX_RF_FEC_OFFSET]; + Word16 rf_gain_tcx[MAX_RF_FEC_OFFSET]; + Word16 rf_tcxltp_param[MAX_RF_FEC_OFFSET]; + + Word16 rf_bwe_gainFr_ind; + +} RF_ENC_DATA, * RF_ENC_HANDLE; + +typedef struct Encoder_State_fx +{ + + /*----------------------------------------------------------------------------------* + * Common parameters + *----------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------* + * Stereo/IVAS parameters + *----------------------------------------------------------------------------------*/ + Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ + + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ + Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 cng_sba_flag; /* CNG in SBA flag */ + Word16 idchan; /* channel ID (audio channel number) */ + Word16 element_mode; /* element mode */ + Word16 last_element_mode; /* element mode */ + Word16 low_rate_mode; /* low-rate mode flag */ + MCT_CHAN_MODE mct_chan_mode; + Word16 GSC_IVAS_mode; + Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ + Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ + + + //#ifdef IVAS_CODE + +#ifdef DEBUGGING + Word16 id_element; /* element ID */ +#endif + Word32 element_brate; /* element bitrate */ + Word16 extl_orig; /* extension layer */ + Word32 extl_brate_orig; /* extension layer bitrate */ + /*----------------------- End of IVAS specific--------------------------------------*/ + + + Word16 codec_mode; /* MODE1 or MODE2 */ + Word16 last_codec_mode; /* Previous Codec Mode*/ + Word16 last_codec_mode_cng; /* Codec Mode of the last inactive frame*/ + Word16 mdct_sw_enable; /* MDCT switching enable flag */ + Word16 mdct_sw; /* MDCT switching indicator */ + Word16 last_enerBuffer_exp; + Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ + Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ + + BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ + + + LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ + + + Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ + Word32 total_brate_fx; /* total bitrate in kbps of the codec */ + Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ + Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ + Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + Word32 core_brate_fx; /* core bitrate */ + Word32 last_core_brate_fx; /* previous frame core bitrate */ + Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ + Word16 extl_fx; /* extension layer */ + Word16 last_extl_fx; /* previous extension layer */ + Word32 extl_brate_fx; /* extension layer bitrate */ + Word16 input_bwidth_fx; /* input signal bandwidth */ + Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ + Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ + Word16 max_bwidth_fx; /* maximum encoded bandwidth */ + Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ + Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ + Word16 L_frame_fx; /* ACELP core internal frame length */ + Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode */ + Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ + Word16 cng_type_fx; /* flag indicating LP or CLDFB based SID/CNG */ + Word16 active_fr_cnt_fx; /* counter of active frames */ + Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ + Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ + /*----------------------------------------------------------------------------------* + * ACELP core parameters + *----------------------------------------------------------------------------------*/ + + Word16 clas_fx; /* current frame clas */ + Word16 last_clas_fx; /* previous frame signal classification */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + + /*----------------------------------------------------------------------------------* + * General signal buffers + *----------------------------------------------------------------------------------*/ + Word16* input_buff; + /*Word16* input; + Word16* old_input_signal;*/ + + SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; + + Word32* Bin_E_old_fx; /* per bin energy of old 2nd frames */ + Word16* mem_decim_fx; /* decimation filter memory */ + Word16* mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz */ + Word16* old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ + Word16* old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ + + Word16* buf_speech_enc_pe; + Word16* buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ + Word16* buf_speech_enc; + Word16* buf_wspeech_enc; + + + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ + Word16 pstreaklen_fx; /* LSF quantizer */ + Word16 streaklimit_fx; /* LSF quantizer */ + Word32 offset_scale1_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ + Word32 offset_scale2_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ + Word32 offset_scale1_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ + Word32 offset_scale2_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ + Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ + Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ + Word16 stab_fac_fx; /* LSF stability factor */ + Word16 mem_deemph_fx; /* deemphasis filter memory */ + Word16 mem_preemph_fx; /* preemphasis filter memory */ + Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ + Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ + /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ + Word16 old_wsp2_fx[(L_WSP_MEM - L_INTERPOL)/OPL_DECIM]; /* old decimated weighted signal vector qwsp */ - Word16 last_exc_dct_in_fx[L_FRAME]; /* AC mode (GSC) - previous exciation */ - Word16 last_bitallocation_band_fx[6]; /* AC mode (GSC) - previous bit allocation of each band */ + /*----------------------------------------------------------------------------------* + * Noise estimation + *----------------------------------------------------------------------------------*/ - Word32 past_PS_fx[HIGHEST_FBIN-LOWEST_FBIN]; - Word16 past_ps_diff_fx; - Word16 past_epsP2_fx; - Word16 inact_cnt_fx; - Word16 wdrop_fx; - Word16 wdlp_0_95_sp_fx; - Word16 sp_mus_state_fx; - Word16 past_dec_fx[HANG_LEN-1]; - Word16 past_dlp_fx[HANG_LEN-1]; /* Speech/music classifier - buffer of past non-binary decisions */ - Word16 last_lsp_fx[M_LSP_SPMUS]; - Word16 last_cor_map_sum_fx; - Word16 last_non_sta_fx; - Word16 past_log_enr_fx[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ + NOISE_EST_HANDLE hNoiseEst; + + Word16 mem_wsp_fx; /* weighted signal vector memory */ + Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ + Word16 clip_var_fx[6]; + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + Word16 coder_type_raw_fx; + Word16 last_coder_type_raw_fx; /* raw last_coder_type (coming from the sigal classification) */ + Word16 last_coder_type_fx; /*Q0 previous coding type */ + Word16 ini_frame_fx; /* initialization frames counter */ + Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ + Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ + Word16 old_pitch; /* previous pitch for open-loop pitch search Q0 */ + Word16 delta_pit_fx; /* open-loop pitch extrapolation correction Q0 */ + Word32 ee_old_fx; + Word16 min_band_fx; /* Q0 minimum critical band of useful bandwidth */ + Word16 max_band_fx; /* Q0 maximum critical band of useful bandwidth */ + Word16 tc_cnt_fx; /* TC frame counter */ + Word16 audio_frame_cnt_fx; /* Counter of relative presence of audio frames */ + Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ + Word16 old_ind_deltaMax_fx; /* Index of the sub-subframe of maximum energy in previous frame */ + Word32 old_enr_ssf_fx[2*NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ + Word16 spike_hyst_fx; /* Hysteresis to prevent UC after sharp energy spike */ + Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ + Word16 last_harm_flag_acelp_fx; /* harmonicity flag for ACELP @32kbps rate */ + Word16 old_Aq_12_8_fx[M+1]; /* Q12 old Aq[] for core switching */ + Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ + + GSC_ENC_HANDLE hGSCEnc; + + + Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + + SP_MUS_CLAS_HANDLE hSpMusClas; - Word16 mold_corr_fx; - Word16 lt_gpitch_fx; /*Q15 */ - Word16 mean_avr_dyn_fx; /* Q7 Speech/music classifier - long term average dynamic */ - Word16 last_sw_dyn_fx; /* Q7 Speech/music classifier - last dynamic */ - Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values */ - Word16 ener_RAT_fx; /* Q15 Speech/music classifier - LF/to total energy ratio */ Word16 lgBin_E_fx[L_FFT/2]; /* Q8 per bin energy of two frames */ /* speech/music classifier improvement parameters */ - Word16 old_Bin_E_fx[3*N_OLD_BIN_E]; - Word16 buf_flux_fx[BUF_LEN]; - Word16 buf_pkh_fx[BUF_LEN]; - Word16 buf_epsP_tilt_fx[BUF_LEN]; - Word16 buf_cor_map_sum_fx[BUF_LEN]; - Word16 buf_Ntonal_fx[BUF_LEN]; - Word16 buf_Ntonal2_fx[BUF_LEN]; - Word16 buf_Ntonal_lf_fx[BUF_LEN]; - Word16 buf_dlp_fx[10]; - Word16 onset_cnt_fx; - Word16 buf_etot_fx[4]; - Word16 attack_hangover_fx; - Word16 dec_mov_fx; - Word16 dec_mov1_fx; - Word16 mov_log_max_spl_fx; - Word16 old_lt_diff_fx[2]; - Word16 UV_cnt1_fx; - Word16 LT_UV_cnt1_fx; - Word16 lpe_buf_fx[HANG_LEN_INIT]; - Word16 voicing_buf_fx[HANG_LEN_INIT]; - Word16 gsc_hangover_fx; - Word16 sparse_buf_fx[HANG_LEN_INIT]; - Word16 hf_spar_buf_fx[HANG_LEN_INIT]; - Word16 LT_sparse_fx; - Word16 gsc_cnt_fx; Word16 last_vad_spa_fx; - Word16 lt_music_hangover_fx; - Word16 tonality2_buf_fx[HANG_LEN_INIT]; - Word16 tonality3_buf_fx[HANG_LEN_INIT]; - Word16 LPCErr_buf_fx[HANG_LEN_INIT]; - Word16 lt_music_state_fx; - Word16 lt_speech_state_fx; - Word16 lt_speech_hangover_fx; Word16 Last_pulse_pos_fx; /* FEC - last position of the first glotal pulse in the frame */ Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame */ Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame */ Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC */ Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ - Word16 gsc_last_music_flag_fx; /* Speech/music classifier - last music flag */ - Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ - Word16 gsc_thres_fx[4]; /* Speech/music classifier - classification threshold */ - Word16 gsc_nb_thr_1_fx; /* Speech/music classifier - number of consecutives frames of level 1 */ - Word16 gsc_nb_thr_3_fx; /* Speech/music classifier - number of consecutives frames of level 3 */ - Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory */ - Word16 old_S_fx[L_FFT/2]; /* Q7 Tonal detector - prev. log-energy spectrum with subtracted floor */ - Word16 cor_map_fx[L_FFT/2]; /* Q15 Tonal detector - LT correlation map */ - Word16 noise_char_fx; /* Q11 Tonal detector - LT noise character */ - Word32 ave_enr2_fx[NB_BANDS]; /* Q_new + Q_SCALE Tonal detector - LT average E per crit. band (for non_sta2) */ - Word16 act_pred_fx; /* Q15 Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ - Word16 multi_harm_limit_fx; /* Q9 Tonal detector - adaptive threshold */ - Word32 enrO_fx[NB_BANDS]; /* Noise estimator - previous energy per critical band */ - Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ - Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ - Word16 pitO_fx; /* Q0 Noise estimator - previous open-loop pitch value */ - Word16 aEn_fx; /* Q0 Noise estimator - noise estimator adaptation flag */ - Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ - Word16 first_noise_updt_fx; /* Q0 Noise estimator - flag used to determine if the first noise update frame */ - Word16 harm_cor_cnt_fx; /* Q0 Noise estimator - 1st memory counter of harm or correlation frame */ - Word16 bg_cnt_fx; /* Q0 Noise estimator - pause length counter */ - Word16 prim_act_quick_fx; /* Noise estimator - primary activity quick */ - Word16 prim_act_slow_fx; /* Noise estimator - primary activity slow */ - Word16 prim_act_fx; /* Noise estimator - primary activity slow rise quick fall */ - Word16 prim_act_quick_he_fx; /* Noise estimator - primary activity quick */ - Word16 prim_act_slow_he_fx; /* Noise estimator - primary activity slow */ - Word16 prim_act_he_fx; /* Q15 Noise estimator - primary activity slow rise quick fall */ - Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ - Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ - Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ - Word16 Etot_last_fx; /*Q8*/ - Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ - Word16 lt_tn_track_fx; /* Q15 */ - Word16 lt_tn_dist_fx; /* Q8*/ - Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ - Word16 lt_haco_ev_fx; /* Q15 */ - Word16 low_tn_track_cnt_fx; /* Q0 */ - Word16 epsP_0_2_lp_fx; /* Q12, all epsP quotas , range ]8.0 ..0]*/ - Word16 epsP_0_2_ad_lp_fx; - Word16 epsP_2_16_lp_fx; - Word16 epsP_2_16_lp2_fx; - Word16 epsP_2_16_dlp_lp2_fx; /* Q12 */ - Word16 lt_aEn_zero_fx; /* Q15 */ + + /*----------------------------------------------------------------------------------* + * VAD/DTX/CNG + *----------------------------------------------------------------------------------*/ - Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ - Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ + VAD_HANDLE hVAD; - Word16 nb_active_frames_fx; - Word16 hangover_cnt_fx; + VAD_CLDFB_HANDLE hVAD_CLDFB; Word16 lp_speech_fx; - Word16 Etot_v_h2_fx; - - Word16 sign_dyn_lp_fx; /*Q8*/ Word16 Opt_HE_SAD_ON_fx; - Word16 nb_active_frames_he_fx; - Word16 hangover_cnt_he_fx; Word16 nb_active_frames_HE_SAD_fx; - /* should be L_var */ - Word32 L_vad_flag_reg_H_fx; - Word32 L_vad_flag_reg_L_fx; - Word32 L_vad_prim_reg_fx; - Word16 vad_flag_cnt_50_fx; - Word16 vad_prim_cnt_16_fx; - Word16 hangover_cnt_dtx_fx; - Word16 hangover_cnt_music_fx; - Word16 bcg_flux_fx; - Word16 soft_hangover_fx; - Word16 voiced_burst_fx; - Word16 bcg_flux_init_fx; Word16 voicing_old_fx; - Word16 nb_active_frames_he1_fx; - Word16 hangover_cnt_he1_fx; Word32 bckr_tilt_lt; - Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ - Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG */ - Word16 cng_seed_fx; /* CNG and DTX - seed for white noise random generator */ - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps */ - Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag */ - Word16 lp_noise_fx; /* CNG and DTX - LP filterend total noise estimation */ - Word16 cnt_SID_fx; /* CNG and DTX - counter of SID update for the interop. mode or dtx, if enabled*/ - Word16 max_SID_fx; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ - Word16 interval_SID_fx; /* CNG and DTX - interval of SID update, default 8 */ - Word16 old_enr_index_fx; /* CNG and DTX - index of last encoded CNG energy */ - Word32 Enew_fx; /* CNG and DTX - CNG target residual energy */ - Word16 VarDTX_cnt_voiced_fx; /* CNG and DTX - counter for variable DTX activation (speech) */ - Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ - Word16 VarDTX_cnt_noise_fx; /* CNG and DTX - counter for variable DTX activation (noise) */ - Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise */ - Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame */ - Word16 cng_hist_size_fx; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ - Word16 cng_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word16 cng_lsp_hist_fx[DTX_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ - Word16 cng_cnt_fx; /* CNG and DTX - counter of CNG frames for averaging */ - Word16 cng_ener_seed_fx; /* CNG and DTX - seed for random generator for variation of excitation energy */ - Word16 cng_ener_seed1_fx; - Word32 frame_ener_fx; - Word16 lp_sp_enr_fx; /*Q8*/ - Word16 last_allow_cn_step_fx; - Word16 ho_hist_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - Word16 ho_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word32 ho_sid_bw_fx; /* CNG and DTX - SID bandwidth flags */ - Word16 ho_lsp_hist_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ - Word32 ho_env_hist_fx[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 act_cnt_fx; /* CNG and DTX - counter of active frames */ - Word16 ho_circ_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - Word16 ho_circ_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word16 ho_lsp_circ_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ - Word32 ho_env_circ_fx[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 burst_ho_cnt_fx; /* CNG and DTX - counter of hangover frames at end of active burst */ - Word16 cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ - Word16 cng_exc2_buf[HO_HIST_SIZE*L_FFT]; /* CNG and DTX - exc2 buffer for storing */ - Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ - Word32 cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ + TD_CNG_ENC_HANDLE hTdCngEnc; - Word16 CNG_mode_fx; /* CNG and DTX - mode for DTX configuration */ - Word32 last_active_brate_fx; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ - Word16 ho_16k_lsp_fx[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ - Word16 last_CNG_L_frame_fx; /* CNG and DTX - last CNG frame length */ - Word16 act_cnt2_fx; /* CNG and DTX - counter of active frames for CNG_mode switching */ - Word16 ho_lsp_circ2_fx[HO_HIST_SIZE*M]; /* CNG and DTX - second buffer of LSPs */ - Word16 num_ho_fx; /* CNG and DTX - number of selected hangover frames */ - Word16 hangover_terminate_flag_fx; /* CNG and DTX - flag indicating whether to early terminate DTX hangover */ - Word32 old_env_fx[NUM_ENV_CNG]; - Word32 lp_env_fx[NUM_ENV_CNG]; - Word32 cng_res_env_fx[NUM_ENV_CNG*HO_HIST_SIZE]; - Word16 exc_mem_fx[24]; - Word16 exc_mem1_fx[30]; - Word16 exc_mem2_fx[30]; + DTX_ENC_HANDLE hDtxEnc; + Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ + Word16 interval_SID_fx; /* CNG and DTX - interval of SID update, default 8 */ - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ + Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation */ Word16 uv_count_fx; /*Q0*/ /* Stationary noise UV modification - unvoiced counter */ Word16 act_count_fx; /*Q0*/ /* Stationary noise UV modification - activation counter */ @@ -728,9 +1368,7 @@ typedef struct Encoder_State_fx Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ Word16 last_L_frame_fx; /* ACELP@16kHz - last L_frame value */ - Word16 mem_decim16k_fx[2*L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ - Word16 old_inp_16k_fx[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ Word16 last_nq_preQ_fx; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ @@ -739,8 +1377,6 @@ typedef struct Encoder_State_fx Word16 bpf_off_fx; Word16 old_pitch_buf_fx[2*NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ - Word16 lps_fx; - Word16 lpm_fx; /* stable short pitch detection */ Word16 voicing0_sm_fx; @@ -753,103 +1389,39 @@ typedef struct Encoder_State_fx Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ /*----------------------------------------------------------------------------------* - * HF WB BWE for AMR-WB IO mode at 23.85 kbps - *----------------------------------------------------------------------------------*/ - - Word16 gain_alpha_fx; - Word16 mem_hf2_enc_fx[L_FIR-1]; - Word16 mem_hp400_enc_fx[6]; - Word16 mem_hf_enc_fx[L_FIR-1]; - Word16 mem_syn_hf_enc_fx[M]; - Word16 seed2_enc_fx; - - /*----------------------------------------------------------------------------------* - * CLDFB analysis - *----------------------------------------------------------------------------------*/ - HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - - HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; - - /*----------------------------------------------------------------------------------* - * FD CNG handle - *----------------------------------------------------------------------------------*/ - HANDLE_FD_CNG_ENC hFdCngEnc_fx; - Word16 fd_cng_reset_flag; - Word16 last_totalNoise_fx; - Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; - Word16 totalNoise_increase_len_fx; - /*----------------------------------------------------------------------------------* - * SC-VBR parameters + * AMR-WB IO handle *----------------------------------------------------------------------------------*/ - Word16 vadsnr_fx; /*Q7*/ - Word16 vadnoise_fx; - - /* NELP variables */ - Word16 shape1_filt_mem_fx[10]; - Word16 shape2_filt_mem_fx[10]; - Word16 shape3_filt_mem_fx[10]; - Word16 txlpf1_filt1_mem_fx[10]; - Word16 txlpf1_filt2_mem_fx[10]; - Word16 txhpf1_filt1_mem_fx[10]; - Word16 txhpf1_filt2_mem_fx[10]; - Word16 bp1_filt_mem_wb_fx[8]; - Word32 bp1_filt_mem_nb_fx[14]; - Word16 nelp_lp_fit_mem[NELP_LP_ORDER*2]; - Word16 nelp_enc_seed_fx; - Word16 nelp_gain_mem_fx; - Word16 last_nelp_mode_fx; - Word16 nelp_mode_fx; - Word16 qprevIn_fx; - Word16 qprevGain_fx; - - /* PPP variables */ - Word16 pppcountE_fx; - Word16 bump_up_fx; /*Q0*/ - Word16 last_ppp_mode_fx; /*Q0*/ - Word16 ppp_mode_fx; - Word16 prev_ppp_gain_pit_fx; /*Q14*/ - Word16 prev_tilt_code_fx; + AMRWB_IO_ENC_HANDLE hAmrwb_IO; /* AMR-WB IO encoder handle */ - /* voiced encoder variables */ - Word16 firstTime_voicedenc_fx; /*Q0*/ + /*----------------------------------------------------------------------------------* + * CLDFB analysis + *----------------------------------------------------------------------------------*/ + HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - /* DTFS variables */ - Word16 dtfs_enc_a_fx[MAXLAG_WI]; /*Q0*/ - Word16 dtfs_enc_b_fx[MAXLAG_WI]; /*Q0*/ - Word16 dtfs_enc_lag_fx; - Word16 dtfs_enc_nH_fx; - Word16 dtfs_enc_nH_4kHz_fx; - Word16 dtfs_enc_upper_cut_off_freq_of_interest_fx; - Word16 dtfs_enc_upper_cut_off_freq_fx; - Word16 dtfs_enc_Q; + HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; - Word32 prev_cw_en_fx; /*Q_prev_cw_en_fx*/ - Word16 ph_offset_E_fx; /*Q15 normalized y 2*Pi */ - Word16 lastLgainE_fx; /*Q11 Previous gain value for the low band */ - Word16 lastHgainE_fx; /*Q11 Previous gain value for the high band */ - Word16 lasterbE_fx[NUM_ERB_WB]; /*Q13 Previous Amplitude spectrum (ERB) */ - Word16 Q_prev_cw_en_fx; + /*----------------------------------------------------------------------------------* + * FD CNG handle + *----------------------------------------------------------------------------------*/ + HANDLE_FD_CNG_ENC hFdCngEnc_fx; + Word16 fd_cng_reset_flag; + Word16 last_totalNoise_fx; + Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; + Word16 totalNoise_increase_len_fx; + /*----------------------------------------------------------------------------------* + * SC-VBR parameters + *----------------------------------------------------------------------------------*/ - Word16 mode_QQF_fx; - Word16 rate_control_fx; - Word16 SNR_THLD_fx; - Word16 Q_to_F_fx; - Word16 pattern_m_fx; - Word16 patterncount_fx; - Word16 Last_Resort_fx; - Word16 numactive_fx; /* keep the count of the frames inside current 600 frame bloack.*/ - Word32 sum_of_rates_fx; /* sum of the rates of past 600 active frames*/ - Word32 global_avr_rate_fx; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - Word16 frame_cnt_ratewin_fx; /* keep count of how many ratewin (600) windows */ + /*----------------------------------------------------------------------------------* + * SC-VBR parameters + *----------------------------------------------------------------------------------*/ - Word16 set_ppp_generic_fx; - Word16 avoid_HQ_VBR_NB; + SC_VBR_ENC_HANDLE hSC_VBR; /*----------------------------------------------------------------------------------* * HQ core parameters *----------------------------------------------------------------------------------*/ - Word16 input_buff[L_FRAME48k+L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS)]; Word16 * input; Word16 * old_input_signal_fx; Word16 Q_old_wtda; @@ -858,145 +1430,25 @@ typedef struct Encoder_State_fx Word32 EnergyLT_fx; Word32 Energy_Old_fx; Word16 TransientHangOver_fx; - Word16 old_out_fx[L_FRAME32k]; /* buffer for OLA; at the encoder, the maximum length is L_FRAME32k (corresponds to maximum internal L_frame length) */ - Word16 Q_old_out; Word16 last_core_fx; - Word16 hq_generic_speech_class_fx; - Word16 mode_count_fx; /* HQ_HARMONIC mode count */ - Word16 mode_count1_fx; /* HQ_NORMAL mode count */ - Word16 Nb_ACELP_frames_fx; - Word16 prev_Npeaks_fx; /* number of peaks in previous frame */ - Word16 prev_peaks_fx[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ - Word16 hvq_hangover_fx; - Word16 prev_hqswb_clas_fx; - Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; + HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ - Word16 lt_old_mode[3]; - Word16 lt_voicing; - Word16 lt_corr; - Word32 lt_tonality; - Word16 lt_corr_pitch[3]; - Word16 lt_hangover; - Word16 lowrate_pitchGain; - - Word16 prev_frm_index_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - Word16 prev_frm_hfe2_fx; - Word16 prev_stab_hfe2_fx; - Word16 prev_ni_ratio_fx; /* 15 */ - Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ - - Word16 last_bitalloc_max_band_fx[2]; - Word32 last_ni_gain_fx[BANDS_MAX]; - Word16 last_env_fx[BANDS_MAX]; - Word16 last_max_pos_pulse_fx; - - /* PVQ range coder state */ - UWord32 rc_low_fx; - UWord32 rc_range_fx; - Word16 rc_cache_fx; - Word16 rc_carry_fx; - Word16 rc_carry_count_fx; - Word16 rc_num_bits_fx; - Word16 rc_tot_bits_fx; - Word16 rc_offset_fx; - /*----------------------------------------------------------------------------------* - * TBE parameters - *----------------------------------------------------------------------------------*/ - - Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ - Word16 old_speech_wb_fx[(L_LOOK_12k8 + L_SUBFR) * 5/16]; /* Buffer memories */ - Word16 old_input_fhb_fx[NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2]; - Word16 old_input_fhb_fx_Q; - - Word16 state_ana_filt_shb_fx[ (2*ALLPASSSECTIONS_STEEP+1) ]; - Word16 cldfbHBLT; - /* states for the filters used in generating SHB excitation from WB excitation*/ - Word32 mem_csfilt_fx[2]; - - /* states for the filters used in generating SHB signal from SHB excitation*/ - Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; - Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - Word16 bwe_seed_fx[2]; - Word32 bwe_non_lin_prev_scale_fx; /*Q30*/ - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; - Word16 syn_overlap_fx[L_SHB_LAHEAD]; - Word16 decim_state1_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 decim_state2_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 mem_genSHBexc_filt_down_wb2_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 mem_genSHBexc_filt_down_wb3_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 mem_genSHBexc_filt_down_shb_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word32 elliptic_bpf_2_48k_mem_fx[4][4]; - Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; - Word32 prev_fb_energy_fx; - Word16 prev_fb_energy_fx_Q; - Word32 prev_gainFr_SHB_fx; - Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; - Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_spacing_fx[3]; - Word16 prev_swb_GainShape_fx; - Word16 prev_frGainAtten_fx; - - Word16 spectral_tilt_reset_fx; - Word16 consec_inactive_fx; - Word16 ra_deltasum_fx; - Word16 trigger_SID_fx; - Word16 running_avg_fx; /*Q15 */ - Word32 L_snr_sum_vad_fx; /*Q4*/ - Word16 prev_wb_GainShape; - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; - Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 prev_Q_bwe_exc_fb; - Word16 fb_tbe_demph_fx; - Word16 tilt_mem_fx; + Word16 Nb_ACELP_frames_fx; - Word16 prev_coder_type_fx; - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER-2]; - Word16 prev_tilt_para_fx; - Word16 cur_sub_Aq_fx[M+1]; + PVQ_ENC_HANDLE hPVQ; - /* quantized data */ - Word16 lsf_idx_fx[NUM_Q_LSF]; - Word16 m_idx_fx; - Word16 grid_idx_fx; - Word16 idxSubGains_fx; - Word16 idxFrameGain_fx; - Word16 idx_shb_fr_gain_fx; - Word16 idx_res_gs_fx[NB_SUBFR16k]; - Word16 idx_mixFac_fx; + /*----------------------------------------------------------------------------------* + * TD BWE parameters + *----------------------------------------------------------------------------------*/ - Word16 lsf_WB_fx; - Word16 gFrame_WB_fx; + TD_BWE_ENC_HANDLE hBWE_TD; - Word16 idxGain_fx; - Word16 dec_2_over_3_mem_fx[12]; - Word16 dec_2_over_3_mem_lp_fx[6]; /*----------------------------------------------------------------------------------* - * SWB BWE parameters + * FD BWE parameters *----------------------------------------------------------------------------------*/ - Word16 new_input_hp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)]; - Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS)]; - Word16 old_input_wb_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; - Word16 old_input_lp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS)]; - Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; - Word16 old_fdbwe_speech_fx[L_FRAME48k]; - Word16 mem_deemph_old_syn_fx; - Word16 prev_mode_fx; - Word16 L_old_wtda_swb_fx[L_FRAME48k]; - Word16 prev_Q_input_lp; - Word16 prev_L_swb_norm1_fx; - Word32 prev_global_gain_fx; - Word16 modeCount_fx; - Word32 EnergyLF_fx; - Word16 tbe_demph_fx; - Word16 tbe_premph_fx; - Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; - Word16 *ptr_mem_stp_swb_fx; - Word16 gain_prec_swb_fx; - Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; + FD_BWE_ENC_HANDLE hBWE_FD; /*----------------------------------------------------------------------------------* * WB, SWB and FB bandwidth detector @@ -1009,72 +1461,16 @@ typedef struct Encoder_State_fx Word16 count_SWB_fx; Word16 count_FB_fx; - /*----------------------------------------------------------------------------------* - * SWB DTX/CNG parameters - *----------------------------------------------------------------------------------*/ - - Word16 last_vad_fx; - Word16 last_wb_cng_ener_fx; - Word16 last_shb_cng_ener_fx; - Word16 mov_wb_cng_ener_fx; - Word16 mov_shb_cng_ener_fx; - Word16 shb_cng_ini_cnt_fx; - Word16 last_SID_bwidth_fx; - Word16 shb_NO_DATA_cnt_fx; - - /*----------------------------------------------------------------------------------* - * Channel-aware mode - *----------------------------------------------------------------------------------*/ - + RF_ENC_HANDLE hRF; /* RF encoder handle */ Word16 rf_mode; + Word16 rf_target_bits_write; Word16 rf_mode_last; Word16 last_rf_mode_cng; Word16 Opt_RF_ON; - Word16 rf_frame_type; - - Word16 rf_target_bits_write; Word16 rf_fec_offset; Word16 rf_fec_indicator; - Word16 rf_targetbits_buff[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_frametype[MAX_RF_FEC_OFFSET]; - - Word16 rf_mem_w0; - Word16 rf_clip_var[6]; - Word16 rf_tilt_code; - Word16 rf_mem_syn2[M]; - struct dispMem_fx rf_dm_fx; - Word32 rf_gc_threshold; - - Word16 rf_target_bits; - Word16 rf_tilt_buf[NB_SUBFR16k]; - - Word16 rf_indx_lsf[MAX_RF_FEC_OFFSET][3]; - Word16 rf_indx_pitch[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - Word16 rf_indx_fcb[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - Word16 rf_indx_gain[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - Word16 rf_indx_EsPred[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_ltfMode[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - - Word16 rf_indx_nelp_fid[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_nelp_iG1[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_nelp_iG2[MAX_RF_FEC_OFFSET][2]; - - Word16 rf_indx_tbeGainFr[MAX_RF_FEC_OFFSET]; - - Word16 rf_tcxltp_pitch_int_past; - Word16 rf_last_tns_active; - Word16 rf_second_last_tns_active; - Word16 rf_second_last_core; - Word16 rf_clas[MAX_RF_FEC_OFFSET]; - Word16 rf_gain_tcx[MAX_RF_FEC_OFFSET]; - Word16 rf_tcxltp_param[MAX_RF_FEC_OFFSET]; - - Word16 rf_bwe_gainFr_ind; - - - /*----------------------------------------------------------------------------------* * Fixed point only variables *----------------------------------------------------------------------------------*/ @@ -1099,10 +1495,8 @@ typedef struct Encoder_State_fx *----------------------------------------------------------------------------------*/ Word16 EnergyLT_fx_exp; - Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; - Word16 last_last_ppp_mode_fx; Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; Word16 frame_size_index; /* 0-FRAME_SIZE_NB-1: index determining the frame size */ @@ -1119,31 +1513,24 @@ typedef struct Encoder_State_fx Word16 mode_index; /* Mode Index for LPD core */ /*TCX config*/ - TCX_config tcx_cfg; - Word16 L_frameTCX; + TCX_CONFIG_HANDLE hTcxCfg; + /*----------------------------------------------------------------------------------* + * TCX core encoder handle + *----------------------------------------------------------------------------------*/ + + TCX_ENC_HANDLE hTcxEnc; /* cod_main.c */ Word16 mem_preemph_enc; /* speech preemph filter memory (at encoder-sampling-rate) */ - Word16 *speech_TCX; - Word16 *new_speech_TCX; Word16 *speech_enc; Word16 *speech_enc_pe; Word16 *new_speech_enc; Word16 *new_speech_enc_pe; - Word16 buf_speech_enc[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; - Word16 buf_speech_enc_pe[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; Word16 *wspeech_enc; - Word16 buf_wspeech_enc[L_FRAME16k+L_SUBFR+L_FRAME16k+L_NEXT_MAX_16k]; /*normally there is a lookahead for 12k8 and 16k but L_FRAME_MAX=L_FRAME_16K+L_NEXT_16k*/ Word16 *synth; - Word16 buf_synth[OLD_SYNTH_SIZE_ENC+L_FRAME32k]; - /* Core Signal Analysis Outputs */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling */ - Word16 noiseLevelMemory; /* counter of consecutive low TCX noise levels */ - STnsData tnsData[2]; - Word8 fUseTns[2]; Word8 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ Word16 envWeighted; /* are is{p,f}_old_q[] weighted or not? */ @@ -1152,9 +1539,6 @@ typedef struct Encoder_State_fx Word8 tcx10Enabled; /* Flag indicating if TCX 10 can be used */ Word8 tcx20Enabled; /* Flag indicating if TCX 20 can be used */ - Word16 tcxMode; /* Chosen TCX mode for this frame */ - - LPD_state LPDmem; Word16 mem_wsp_enc; /* wsp vector memory */ @@ -1228,7 +1612,6 @@ typedef struct Encoder_State_fx /* for FAC */ Word16 L_frame_past; - Word8 memQuantZeros[L_FRAME_PLUS]; /*Adaptive BPF*/ Word16 bpf_gain_param; @@ -1244,23 +1627,7 @@ typedef struct Encoder_State_fx Word16 noise_shift_old; } mem_bpf; - /* TCX-LTP */ - Word8 tcxltp; - Word16 tcxltp_pitch_int; - Word16 tcxltp_pitch_fr; - Word16 tcxltp_gain; - Word16 tcxltp_pitch_int_past; - Word16 tcxltp_pitch_fr_past; - Word16 tcxltp_gain_past; - Word16 tcxltp_norm_corr_past; - Word16 buf_speech_ltp[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; - Word16 *speech_ltp; - Word16 *new_speech_ltp; - Word16 tcxltp_bits; - Word16 tcxltp_param[LTPSIZE]; - Word16 measuredBwRatio; /* measured bw; used for TCX noise-filling. 1Q14 */ - Word16 nmStartLine; /* Starting line for the noise measurement. Q0 */ Word8 glr; Word16 glr_idx[2]; @@ -1276,17 +1643,16 @@ typedef struct Encoder_State_fx Word16 enablePlcWaveadjust; Word16 Tonal_SideInfo; - IGF_ENC_INSTANCE hIGFEnc; + + IGF_ENC_INSTANCE_HANDLE hIGFEnc; /* IGF encoder handle */ Word16 igf; Word16 seed_acelp; - Word16 tcx_lpc_shaped_ari; - - PLC_ENC_EVS plcExt; + PLC_ENC_EVS_HANDLE hPlcExt; Word16 tec_tfa; - TEMPORAL_ENVELOPE_CODING_ENCODER_FX tecEnc; + TEC_ENC_HANDLE_FX hTECEnc; /* TEC encoder handle */ Word16 tec_flag; Word16 tfa_flag; Word32 tfa_enr[N_TEC_TFA_SUBFR]; @@ -1295,13 +1661,22 @@ typedef struct Encoder_State_fx T_CldfbVadState vad_st; - Word16 vbr_generic_ho_fx; - Word16 last_7k2_coder_type_fx; - Word16 sharpFlag; + Word16 pitch_fx[3]; + Word16 voicing_fx[3]; + Word16 sp_aud_decision0; /* 1st stage speech/music classification */ + Word16 sp_aud_decision1; /* 1st stage speech/music classification */ + Word16 sp_aud_decision2; /* 2nd stage speech/music classification */ + Word16 coder_type; /* coder type */ + Word16 vad_flag; + Word16 sharpFlag; /* formant sharpening flag */ + Word16 localVAD; - Word16 Local_VAD; + Word16 tdm_pc; + Word16 prev_fmerit; + Word16 fmerit_dt; + } Encoder_State_fx; /* Structure for storing correlations between ACELP codebook components and target */ diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index b9199fa..31a84d1 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -2,12 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ +#include +#include "options.h" #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" -/*======================================================================*/ + /*======================================================================*/ /* FUNCTION : stat_noise_uv_enc_fx */ /*----------------------------------------------------------------------*/ /* PURPOSE : Modifies excitation signal in UC mode */ @@ -15,11 +15,11 @@ /*----------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (Encoder_State_fx) st_fx : Encoder state Structure */ -/* _ (Word16) coder_type : coding type */ /* _ (Word16*) epsP : LP prediction errors */ /* _ (Word16*) isp_new : immittance spectral pairs at 4th sfr Q15 */ /* _ (Word16*) isp_mid : immittance spectral pairs at 2nd sfr Q15 */ /* _ (Word16*) Aq : A(z) quantized for the 4 subframes Q12 */ +/* _ (Word16 ) uc_two_stage_flag flag undicating two-stage UC */ /*-----------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* _ (Word16*) exc2 : excitation buffer Q_exc */ @@ -33,13 +33,13 @@ /* _ None */ /*=======================================================================*/ void stat_noise_uv_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 coder_type, /* i : coding type */ - const Word32 *LepsP, /* i : LP prediction errors */ - Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ - Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word32 *LepsP, /* i : LP prediction errors */ + const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ + const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ + Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ + Word16 *exc2, /* i/o: excitation buffer */ + const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ Word16 Q_new ) { @@ -48,7 +48,7 @@ void stat_noise_uv_enc_fx( test(); test(); - IF ( EQ_16(coder_type,UNVOICED)||(EQ_16(coder_type,INACTIVE)&&LE_32(st_fx->core_brate_fx,ACELP_9k60))) + IF ( ( EQ_16(st_fx->coder_type,UNVOICED) && uc_two_stage_flag == 0) || (EQ_16(st_fx->coder_type,INACTIVE) && LE_32(st_fx->core_brate_fx,ACELP_9k60))) { /*-----------------------------------------------------------------* @@ -71,7 +71,7 @@ void stat_noise_uv_enc_fx( /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/ noisiness = shr(num,4);/*Q10 x64 -> Q0 */ } - ELSE IF ( EQ_16(coder_type,INACTIVE)&&EQ_16(st_fx->bwidth_fx,NB)) + ELSE IF ( EQ_16(st_fx->coder_type,INACTIVE)&&EQ_16(st_fx->bwidth_fx,NB)) { /* NB GSC case */ /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/ @@ -86,18 +86,18 @@ void stat_noise_uv_enc_fx( noisiness = s_max(noisiness, 0); noisiness = s_min(noisiness, 31); - push_indice_fx( st_fx, IND_NOISINESS, noisiness, 5 ); + push_indice_fx( st_fx->hBstr, IND_NOISINESS, noisiness, 5 ); } /*-----------------------------------------------------------------* * Modify the stationary noise excitation signal *-----------------------------------------------------------------*/ - stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq + stat_noise_uv_mod_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq ,exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count_fx, &st_fx->act_count_fx, st_fx->lspold_s_fx, &st_fx->noimix_seed_fx, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate_fx, st_fx->bwidth_fx, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - + return; } diff --git a/lib_enc/subband_fft.c b/lib_enc/subband_fft.c index f4aafca..7f6a697 100644 --- a/lib_enc/subband_fft.c +++ b/lib_enc/subband_fft.c @@ -3,12 +3,16 @@ ====================================================================================*/ +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" #include "rom_enc_fx.h" +/*---------------------------------------------------------------------* + * Local + *---------------------------------------------------------------------*/ #define RE(A) A.r #define IM(A) A.i @@ -17,17 +21,32 @@ typedef struct complex_16 work[32]; complex_16 const* tab; } cfft_info_16; - -static void ComplexMult_16(Word16 *y1, Word16 *y2, Word16 x1, Word16 x2, Word16 c1, Word16 c2) +/*-------------------------------------------------------------------* + * ComplexMult_16() + * + *-------------------------------------------------------------------*/ +static void ComplexMult_16( + Word16 *y1, + Word16 *y2, + const Word16 x1, + const Word16 x2, + const Word16 c1, + const Word16 c2 +) { *y1 = add(mult(x1, c1) , mult(x2, c2)); move16(); *y2 = sub(mult(x2, c1) , mult(x1, c2)); move16(); } - -Word16 ffr_getSfWord32(Word32 *vector, /*!< Pointer to input vector */ - Word16 len) /*!< Length of input vector */ +/*-------------------------------------------------------------------* + * ffr_getSfWord32() + * + *-------------------------------------------------------------------*/ +Word16 ffr_getSfWord32( + const Word32 *vector, /*!< Pointer to input vector */ + const Word16 len /*!< Length of input vector */ +) { Word32 maxVal; Word16 i; @@ -43,16 +62,25 @@ Word16 ffr_getSfWord32(Word32 *vector, /*!< Pointer to input vector */ resu = 31; move16(); - if(maxVal) + if (maxVal) + { resu = norm_l(maxVal); - + } return resu; } +/*-------------------------------------------------------------------* + * cgetpreSfWord16() + * + *-------------------------------------------------------------------*/ static -void cgetpreSfWord16( Word16 *vector, /*!< Pointer to input vector */ - Word16 len,Word16 preshr,Word16* num) +void cgetpreSfWord16( + Word16 *vector, /*!< Pointer to input vector */ + const Word16 len, + const Word16 preshr, + Word16* num +) { Word16 i; @@ -66,12 +94,18 @@ void cgetpreSfWord16( Word16 *vector, /*!< Pointer to input vector */ } } - -static void passf4_1_16( const cmplx_s *cc, - cmplx_s *ch, - const cmplx_s *wa1, - const cmplx_s *wa2, - const cmplx_s *wa3) +/*-------------------------------------------------------------------* + * passf4_1_16() + * + *-------------------------------------------------------------------*/ + +static void passf4_1_16( + const cmplx_s *cc, + cmplx_s *ch, + const cmplx_s *wa1, + const cmplx_s *wa2, + const cmplx_s *wa3 +) { UWord16 i; @@ -101,9 +135,14 @@ static void passf4_1_16( const cmplx_s *cc, } - -static void passf4_2_16(const cmplx_s *cc, - cmplx_s *ch) +/*-------------------------------------------------------------------* + * passf4_2_16() + * + *-------------------------------------------------------------------*/ +static void passf4_2_16( + const cmplx_s *cc, + cmplx_s *ch +) { Word16 k; @@ -131,9 +170,17 @@ static void passf4_2_16(const cmplx_s *cc, } - +/*-------------------------------------------------------------------* + * cfftf_16() + * + *-------------------------------------------------------------------*/ static -void cfftf_16(Word16* scale, complex_16 *c, complex_16 *ch, const complex_16 *wa) +void cfftf_16( + Word16* scale, + complex_16 *c, + complex_16 *ch, + const complex_16 *wa +) { cgetpreSfWord16((Word16*)c, 32,3,scale); @@ -142,16 +189,19 @@ void cfftf_16(Word16* scale, complex_16 *c, complex_16 *ch, const complex_16 *wa passf4_2_16((const cmplx_s*)ch, (cmplx_s*)c); } - +/*-------------------------------------------------------------------* + * fft16_fix_4_16() + * + *-------------------------------------------------------------------*/ static void fft16_fix_4_16( Word32 **Sr, Word32 **Si, - Word32 Offset, - Word16 i, + const Word32 Offset, + const Word16 i, cfft_info_16 cfft, Word16 in_specamp_Q, - Word16 tmpQ, + const Word16 tmpQ, Word32 * spec_amp ) { @@ -216,16 +266,19 @@ void fft16_fix_4_16( } } - +/*-------------------------------------------------------------------* + * fft16_fix_5_16() + * + *-------------------------------------------------------------------*/ static void fft16_fix_5_16( Word32 **Sr, Word32 **Si, - Word32 Offset, - Word16 i, + const Word32 Offset, + const Word16 i, cfft_info_16 cfft, Word16 in_specamp_Q, - Word16 tmpQ, + const Word16 tmpQ, Word32 * spec_amp ) { diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index bdefc5f..262329d 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -122,6 +122,7 @@ void wb_bwe_enc_fx( Word16 *new_input_fx; /* pointer to original input signal */ Word16 scl, new_input_fx_exp; Word16 Q_synth; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; Word16 WB_fenv_fx[SWB_FENV]; IF( EQ_32(st_fx->total_brate_fx, ACELP_13k20)) @@ -133,9 +134,9 @@ void wb_bwe_enc_fx( Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS); new_input_fx = old_input_fx + Sample_Delay_WB_BWE; - Copy( st_fx->old_input_wb_fx, old_input_fx, Sample_Delay_WB_BWE ); + Copy(hBWE_FD->old_input_wb_fx, old_input_fx, Sample_Delay_WB_BWE ); Copy( new_wb_speech_fx, new_input_fx, L_FRAME16k ); - Copy( old_input_fx + L_FRAME16k, st_fx->old_input_wb_fx, Sample_Delay_WB_BWE ); + Copy( old_input_fx + L_FRAME16k, hBWE_FD->old_input_wb_fx, Sample_Delay_WB_BWE ); /*---------------------------------------------------------------------*/ /* WB BWE encoding */ @@ -146,12 +147,13 @@ void wb_bwe_enc_fx( new_input_fx_exp = 0; move16(); - wtda_fx(old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, st_fx->L_old_wtda_swb_fx, + wtda_fx(old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, &st_fx->Q_old_wtda,ALDO_WINDOW,ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ L_FRAME16k ); /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp); + direct_transform_fx(L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp + , /*st_fx->element_mode*/EVS_MONO); /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub(16+8/*MAX_Q_NEW_INPUT*/, new_input_fx_exp); @@ -169,10 +171,10 @@ void wb_bwe_enc_fx( Q_synth = add(sub(new_input_fx_exp, 16), scl) - 1; mode = WB_BWE_encoding_fx( coder_type, yorig_fx, WB_fenv_fx, st_fx, Q_synth, Q_synth); - push_indice_fx(st_fx, IND_WB_CLASS, mode - 2, 1 ); + push_indice_fx(st_fx->hBstr, IND_WB_CLASS, mode - 2, 1 ); } - st_fx->prev_mode_fx = mode; + hBWE_FD->prev_mode_fx = mode; return; } @@ -221,6 +223,7 @@ void swb_bwe_enc_fx( Word32 energy_fbe_fb_fx = 0; Word16 fb_ener_adjust_fx; Word16 ener_adjust_quan_fx = 0; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; /*---------------------------------------------------------------------* @@ -245,7 +248,7 @@ void swb_bwe_enc_fx( Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); Sample_Delay_LP = NS2SA(12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS); - delay_input_signal_fx( st_fx->old_input_lp_fx, old_input_lp_fx, &old_input_12k8_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME, &st_fx->prev_Q_input_lp, &Q_slb_speech ); + delay_input_signal_fx(hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_12k8_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); } ELSE { @@ -253,16 +256,16 @@ void swb_bwe_enc_fx( Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); Sample_Delay_LP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS); - delay_input_signal_fx( st_fx->old_input_lp_fx, old_input_lp_fx, &old_input_16k_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME16k, &st_fx->prev_Q_input_lp, &Q_slb_speech ); + delay_input_signal_fx(hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_16k_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME16k, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); } - Copy(st_fx->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP); + Copy(hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP); Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k-Sample_Delay_HP ); - Copy( shb_speech_fx + L_FRAME16k-Sample_Delay_HP, st_fx->new_input_hp_fx, Sample_Delay_HP ); + Copy( shb_speech_fx + L_FRAME16k-Sample_Delay_HP, hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); new_input_fx = old_input_fx + Sample_Delay_SWB_BWE; - Copy( st_fx->old_input_fx, old_input_fx, Sample_Delay_SWB_BWE ); + Copy(hBWE_FD->old_input_fx, old_input_fx, Sample_Delay_SWB_BWE ); Copy( new_swb_speech_fx, new_input_fx, inner_frame ); - Copy( old_input_fx + inner_frame, st_fx->old_input_fx, Sample_Delay_SWB_BWE ); + Copy( old_input_fx + inner_frame, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); /*----------------------------------------------------------------------* * Calculate tilt of the input signal and the ACELP core synthesis *----------------------------------------------------------------------*/ @@ -275,12 +278,13 @@ void swb_bwe_enc_fx( *---------------------------------------------------------------------*/ new_input_fx_exp = 0; /* MDCT of the core synthesis signal */ - wtda_fx(old_input_fx, &new_input_fx_exp, L_old_input_fx, st_fx->L_old_wtda_swb_fx, + wtda_fx(old_input_fx, &new_input_fx_exp, L_old_input_fx, hBWE_FD->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ inner_frame ); /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp); + direct_transform_fx(L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp + , /*st_fx->element_mode*/EVS_MONO); /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub(16+8, new_input_fx_exp); @@ -406,7 +410,7 @@ void swb_bwe_enc_fx( /* write FB BWE frame gain to the bitstream */ IF( EQ_16(st_fx->extl_fx, FB_BWE)) { - push_indice_fx(st_fx, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); + push_indice_fx(st_fx->hBstr, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); } return; @@ -586,6 +590,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ Word16 sharplimit; Word16 numsharp, num, den; Word16 numharmonic, tmp, expn, expd, scale; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; mode = NORMAL; move16(); @@ -617,7 +622,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ test(); IF ( ( EQ_16(st_fx->last_extl_fx, SWB_BWE)&&EQ_16(st_fx->extl_fx,SWB_BWE))||(EQ_16(st_fx->last_extl_fx,FB_BWE)&&EQ_16(st_fx->extl_fx,FB_BWE))) { - IF(st_fx->prev_global_gain_fx == 0) + IF(hBWE_FD->prev_global_gain_fx == 0) { gain_tmp = round_fx(L_shl(fGain, 30)); /*Q14 */ } @@ -627,8 +632,8 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ num = extract_h(L_shl(fGain, expn)); expn = sub(sub(30, expn), shl(Q_shb,1)); - expd = norm_l(st_fx->prev_global_gain_fx); - den = extract_h(L_shl(st_fx->prev_global_gain_fx, expd)); + expd = norm_l(hBWE_FD->prev_global_gain_fx); + den = extract_h(L_shl(hBWE_FD->prev_global_gain_fx, expd)); expd = sub(sub(30, expd), shl(st_fx->prev_Q_shb,1)); scale = shr(sub(den, num), 15); @@ -640,11 +645,11 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ gain_tmp = shl(tmp, sub(expn,1));/*Q14 */ } test(); - IF (EQ_16(st_fx->prev_mode_fx,TRANSIENT)) + IF (EQ_16(hBWE_FD->prev_mode_fx,TRANSIENT)) { numharmonic = shl(numharmonic, 1); } - ELSE IF (EQ_16(st_fx->prev_mode_fx, NORMAL)||EQ_16(st_fx->prev_mode_fx,NOISE)) + ELSE IF (EQ_16(hBWE_FD->prev_mode_fx, NORMAL)||EQ_16(hBWE_FD->prev_mode_fx,NOISE)) { numharmonic = add(shr(numharmonic, 1), numharmonic); } @@ -653,7 +658,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ { gain_tmp = 16384; move16(); - IF (EQ_16(st_fx->prev_mode_fx, HARMONIC)) + IF (EQ_16(hBWE_FD->prev_mode_fx, HARMONIC)) { numharmonic = shr(numharmonic, 1); sharplimit = shr(sharplimit, 1); @@ -672,7 +677,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ numsharp = 3; move16(); - IF (EQ_16(st_fx->prev_mode_fx, HARMONIC)) + IF (EQ_16(hBWE_FD->prev_mode_fx, HARMONIC)) { numharmonic = shr(numharmonic, 2); } @@ -682,7 +687,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ } IF (NE_16(st_fx->last_extl_fx, WB_BWE)) { - IF (EQ_16(st_fx->prev_mode_fx, HARMONIC)) + IF (EQ_16(hBWE_FD->prev_mode_fx, HARMONIC)) { sharplimit = shr(sharplimit, 1); } @@ -797,16 +802,16 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class */ test(); test(); - IF (sharpMod && LT_16(st_fx->modeCount_fx, 12)) + IF (sharpMod && LT_16(hBWE_FD->modeCount_fx, 12)) { - st_fx->modeCount_fx = add(st_fx->modeCount_fx, 1); + hBWE_FD->modeCount_fx = add(hBWE_FD->modeCount_fx, 1); } - ELSE IF (sharpMod == 0 && st_fx->modeCount_fx > 0) + ELSE IF (sharpMod == 0 && hBWE_FD->modeCount_fx > 0) { - st_fx->modeCount_fx = sub(st_fx->modeCount_fx, 1); + hBWE_FD->modeCount_fx = sub(hBWE_FD->modeCount_fx, 1); } - IF (GE_16(st_fx->modeCount_fx, 2)) + IF (GE_16(hBWE_FD->modeCount_fx, 2)) { sharpMod = 1; move16(); @@ -1641,7 +1646,7 @@ static void energy_control_fx( Word16 n_band,max_band,band_step; Word16 gamma_fx, core_type; Word16 SWB_signal_fx[L_FRAME32k], SFM_org_fx[SWB_FENV], SFM_gen_fx[SWB_FENV]; - + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; IF ( EQ_16(core,ACELP_CORE)) { @@ -1658,7 +1663,7 @@ static void energy_control_fx( core_type = 1; move16(); } - get_normalize_spec_fx(core, st_fx->extl_fx, mode, core_type, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset, Q_new_lf); + get_normalize_spec_fx(core, st_fx->extl_fx, mode, core_type, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1_fx), offset, Q_new_lf); IF ( EQ_16(st_fx->extl_fx,WB_BWE)) { @@ -1679,7 +1684,7 @@ static void energy_control_fx( { gamma_fx = 18022; move16();/*.55 in Q15 */ - get_normalize_spec_fx(core, st_fx->extl_fx, mode, -1, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset, Q_new_lf); + get_normalize_spec_fx(core, st_fx->extl_fx, mode, -1, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1_fx), offset, Q_new_lf); band_step = 1; move16(); @@ -1784,7 +1789,7 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb signal */ index = WB_BWE_fenv_q_fx( WB_fenv_fx, F_2_5_fx, 32, 2 ); - push_indice_fx(st_fx, IND_WB_FENV, index, 5 ); + push_indice_fx(st_fx->hBstr, IND_WB_FENV, index, 5 ); return (mode); } @@ -1832,6 +1837,8 @@ static Word16 SWB_BWE_encoding_fx( Word16 SWB_tenv_tmp_fx[SWB_TENV]; Word16 max_fx; Word16 energy_factor_fx[SWB_FENV], w_env_fx[SWB_FENV]; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; IF( EQ_16(st_fx->L_frame_fx, L_FRAME )) { @@ -1845,7 +1852,7 @@ static Word16 SWB_BWE_encoding_fx( } /* HF transient detect */ - IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, coder_type, Q_shb, st_fx); + IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, Q_shb, st_fx); st_fx->EnergyLT_fx_exp = shl(Q_shb, 1); /* LF transient detect */ @@ -1860,13 +1867,13 @@ static Word16 SWB_BWE_encoding_fx( energy_fx = L_add(energy_fx, L_shr(L_mult0(insig_lp_fx[i + tmp], insig_lp_fx[i + tmp]), 7)); /*2*Q_slb_speech - 7 */ } - IF(GT_32(Mult_32_16(energy_fx, 5958), st_fx->EnergyLF_fx)) + IF(GT_32(Mult_32_16(energy_fx, 5958), hBWE_FD->EnergyLF_fx)) { IsTransient_LF = 1; move16(); } - st_fx->EnergyLF_fx = energy_fx; + hBWE_FD->EnergyLF_fx = energy_fx; move32(); } @@ -1887,7 +1894,7 @@ static Word16 SWB_BWE_encoding_fx( { mode = IsTransient; move16(); - push_indice_fx(st_fx, IND_SWB_CLASS, mode, 2 ); + push_indice_fx( hBstr, IND_SWB_CLASS, mode, 2 ); /* Energy for the different bands and global energies */ global_gain_fx = L_deposit_l(0); @@ -2142,13 +2149,13 @@ static Word16 SWB_BWE_encoding_fx( index = shr(add(SWB_tenv_tmp_fx[n_band], 1024), 11); } - push_indice_fx(st_fx, IND_SWB_TENV, index, 4 ); + push_indice_fx( hBstr, IND_SWB_TENV, index, 4 ); } MSVQ_Interpol_Tran_fx(SWB_fenv_fx, indice); - push_indice_fx(st_fx, IND_SWB_FENV, indice[0], 7 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[1], 6 ); + push_indice_fx( hBstr, IND_SWB_FENV, indice[0], 7 ); + push_indice_fx( hBstr, IND_SWB_FENV, indice[1], 6 ); } ELSE { @@ -2173,7 +2180,7 @@ static Word16 SWB_BWE_encoding_fx( global_gain_fx = L_shr(global_gain_fx, 1); /*2*Q_shb */ mode = FD_BWE_class_fx(yos_fx, global_gain_fx, tilt_nb_fx, Q_synth, Q_shb, st_fx); - push_indice_fx(st_fx, IND_SWB_CLASS, mode, 2 ); + push_indice_fx( hBstr, IND_SWB_CLASS, mode, 2 ); energy_control_fx( st_fx, ACELP_CORE, mode, -1, yos_fx, st_offset, energy_factor_fx, Q_synth_lf ); @@ -2207,16 +2214,16 @@ static Word16 SWB_BWE_encoding_fx( /* Energy VQ */ msvq_interpol_fx(SWB_fenv_fx, w_env_fx, indice); - push_indice_fx(st_fx, IND_SWB_FENV, indice[0], 5 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[1], 7 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[2], 6 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[3], 5 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[4], 6 ); + push_indice_fx( hBstr, IND_SWB_FENV, indice[0], 5 ); + push_indice_fx( hBstr, IND_SWB_FENV, indice[1], 7 ); + push_indice_fx( hBstr, IND_SWB_FENV, indice[2], 6 ); + push_indice_fx( hBstr, IND_SWB_FENV, indice[3], 5 ); + push_indice_fx( hBstr, IND_SWB_FENV, indice[4], 6 ); } - st_fx->prev_mode_fx = mode; + hBWE_FD->prev_mode_fx = mode; move16(); - st_fx->prev_global_gain_fx = global_gain_fx; + hBWE_FD->prev_global_gain_fx = global_gain_fx; move32(); st_fx->prev_Q_shb = Q_shb; move16(); @@ -2466,6 +2473,7 @@ static void energy_control_fx_32( Word32 L_temp1, L_temp2; Word16 exp1, exp2, tmp1, tmp2, tmp; Word16 gamma_fx; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; IF ( core == ACELP_CORE ) { @@ -2483,7 +2491,7 @@ static void energy_control_fx_32( move16(); } - get_normalize_spec_fx_32(core, st_fx->extl_fx, mode, core_type, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset ); + get_normalize_spec_fx_32(core, st_fx->extl_fx, mode, core_type, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1_fx), offset ); IF ( EQ_16(st_fx->extl_fx , WB_BWE)) { @@ -2497,7 +2505,7 @@ static void energy_control_fx_32( { gamma_fx = 18021; move16(); - get_normalize_spec_fx_32(core, -1, mode, -1, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset ); + get_normalize_spec_fx_32(core, -1, mode, -1, org_fx, SWB_signal_fx, &(hBWE_FD->prev_L_swb_norm1_fx), offset ); IF ( EQ_16(offset , HQ_GENERIC_FOFFSET_32K)) { @@ -2641,6 +2649,9 @@ void hq_generic_encoding_fx( Word32 energy_fx; Word32 L_tmp, max_coefs_fx; Word16 w_env_fx[SWB_FENV]; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + IF ( LE_16(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4)) { @@ -2656,17 +2667,17 @@ void hq_generic_encoding_fx( energy_control_fx_32(st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx); - IF ( EQ_16(st_fx->hq_generic_speech_class_fx , 1)) + IF ( EQ_16(hHQ_core->hq_generic_speech_class_fx , 1)) { - push_indice_fx( st_fx, IND_HQ_SWB_EXC_SP_CLAS, 1, 1 ); + push_indice_fx( hBstr, IND_HQ_SWB_EXC_SP_CLAS, 1, 1 ); *hq_generic_exc_clas = HQ_GENERIC_SP_EXC; move16(); } ELSE { *hq_generic_exc_clas = decision_hq_generic_class_fx_32(coefs_fx, hq_generic_offset); - push_indice_fx( st_fx, IND_HQ_SWB_EXC_SP_CLAS, 0, 1 ); - push_indice_fx( st_fx, IND_HQ_SWB_EXC_CLAS, *hq_generic_exc_clas, 1 ); + push_indice_fx( hBstr, IND_HQ_SWB_EXC_SP_CLAS, 0, 1 ); + push_indice_fx( hBstr, IND_HQ_SWB_EXC_CLAS, *hq_generic_exc_clas, 1 ); } FOR ( n_band = 0; n_band < nenv; n_band++ ) @@ -2782,23 +2793,23 @@ void hq_generic_encoding_fx( indice[5] = vqSimple_w_fx(hq_generic_fenv_fx+nenv, hq_generic_fenv_fx+nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0); } - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[0], 5 ); - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[1], 7 ); - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[2], 6 ); - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[3], 5 ); + push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[0], 5 ); + push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[1], 7 ); + push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[2], 6 ); + push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[3], 5 ); IF ( LE_16(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4)) { - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[4], 6 ); + push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[4], 6 ); } ELSE { - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[4], 5 ); + push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[4], 5 ); } IF ( EQ_16(st_fx->bwidth_fx , FB)) { - push_indice_fx( st_fx, IND_FB_FENV_HQ, indice[5], 5 ); + push_indice_fx( hBstr, IND_FB_FENV_HQ, indice[5], 5 ); } FOR ( n_band = 0; n_band < nenv; n_band++ ) @@ -2830,4 +2841,40 @@ void hq_generic_encoding_fx( return; } +/*-------------------------------------------------------------------* + * fd_bwe_enc_init() + * + * Initialize FD BWE state structure at the encoder + *-------------------------------------------------------------------*/ +void fd_bwe_enc_init( + FD_BWE_ENC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ +) +{ + set16_fx(hBWE_FD->new_input_hp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)); + set16_fx(hBWE_FD->old_input_fx, 0, NS2SA(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS)); + set16_fx(hBWE_FD->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS)); + set16_fx(hBWE_FD->old_input_lp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS)); + set16_fx(hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + hBWE_FD->prev_mode_fx = NORMAL; + move16(); + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k); + hBWE_FD->prev_L_swb_norm1_fx = 8; + move16(); + hBWE_FD->prev_global_gain_fx = 0; + move32(); + hBWE_FD->modeCount_fx = 0; + move16(); + hBWE_FD->EnergyLF_fx = 0; + move32(); + + hBWE_FD->prev_Q_input_lp = 0; + move16(); + set16_fx(hBWE_FD->old_fdbwe_speech_fx, 0, L_FRAME48k); + hBWE_FD->mem_deemph_old_syn_fx = 0; + move16(); + + //hBWE_FD->mem_old_wtda_swb = 0.0f; + + return; +} diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index 3caaae1..d5244db 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -1,13 +1,13 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include "options.h" /* Compilation switches */ +#include +#include +#include "options.h" #include "cnst_fx.h" /* Common constants */ #include "rom_enc_fx.h" /* Encoder static table prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* @@ -84,12 +84,11 @@ static Word16 en_band_quant_fx(/* o : quantization index */ * HR SWB BWE encoder *-------------------------------------------------------------------*/ void swb_bwe_enc_hr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *new_input_fx, /* i : input signal */ - Word16 new_input_fx_exp, /* i : Exponent of input signal */ - const Word16 input_frame, /* i : frame length */ - const Word16 coder_type, /* i : coding type */ - const Word16 unbits /* i : number of core unused bits */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + Word16 *new_input_fx, /* i : input signal */ + Word16 new_input_fx_exp, /* i : Exponent of input signal */ + const Word16 input_frame, /* i : frame length */ + const Word16 unbits /* i : number of core unused bits */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; @@ -115,6 +114,9 @@ void swb_bwe_enc_hr_fx( #else Word32 L_t_audio_tmp_fx[L_FRAME48k]; #endif + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + Word32 *ptr32; /*---------------------------------------------------------------------* @@ -142,14 +144,15 @@ void swb_bwe_enc_hr_fx( test(); IF( EQ_16(st_fx->last_core_fx, HQ_CORE)||NE_16(st_fx->last_extl_fx,st_fx->extl_fx)) { - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); st_fx->Q_old_wtda = 0; move16(); } /* calculate SWB BWE bit-budget (extension layer bit-rate + AVQ unused bits from the core layer) */ /* nBits = st->extl_brate/50 + unbits */ - nBits = add(320,unbits); /* st->extl_brate_fx is always 16kbps */ + assert(SWB_BWE_16k == st_fx->extl_brate_fx); + nBits = add(SWB_BWE_16k/50,unbits); /* st->extl_brate_fx is always 16kbps */ nBits_total = nBits; move16(); @@ -176,11 +179,11 @@ void swb_bwe_enc_hr_fx( /* Bring Energy in 2*Q'exp1' */ st_fx->EnergyLT_fx = L_shl(st_fx->EnergyLT_fx, shl(sub(exp1, st_fx->EnergyLT_fx_exp), 1)); - is_transient = detect_transient_fx( t_audio_fx, input_frame, coder_type, exp1, st_fx ); + is_transient = detect_transient_fx( t_audio_fx, input_frame, exp1, st_fx ); st_fx->EnergyLT_fx_exp = exp1; move16(); - push_indice_fx( st_fx, IND_HR_IS_TRANSIENT, is_transient, 1 ); + push_indice_fx( hBstr, IND_HR_IS_TRANSIENT, is_transient, 1 ); /*---------------------------------------------------------------------* * OLA and MDCT @@ -191,10 +194,11 @@ void swb_bwe_enc_hr_fx( st_fx->Q_old_wtda = new_input_fx_exp; move16(); new_input_fx_exp=0; - wtda_fx( new_input_fx, &new_input_fx_exp, L_t_audio_tmp_fx, st_fx->L_old_wtda_swb_fx, + wtda_fx( new_input_fx, &new_input_fx_exp, L_t_audio_tmp_fx, hBWE_FD->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, input_frame ); - direct_transform_fx(L_t_audio_tmp_fx, t_audio32, is_transient, input_frame, &new_input_fx_exp); + direct_transform_fx(L_t_audio_tmp_fx, t_audio32, is_transient, input_frame, &new_input_fx_exp + , /*st_fx->element_mode*/EVS_MONO ); /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); @@ -300,7 +304,7 @@ void swb_bwe_enc_hr_fx( ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1); - push_indice_fx( st_fx, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); + push_indice_fx( hBstr, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); /* normalization with global gain */ @@ -345,7 +349,7 @@ void swb_bwe_enc_hr_fx( { ind1 = en_band_quant_fx( en_band_fx, swb_hr_env_code3_fx, NUM_ENVLOPE_CODE_HR_TR ); - push_indice_fx( st_fx, IND_HR_ENVELOPE, ind1, NBITS_ENVELOPE_BWE_HR_TR ); + push_indice_fx( hBstr, IND_HR_ENVELOPE, ind1, NBITS_ENVELOPE_BWE_HR_TR ); nBits = sub(nBits, NBITS_ENVELOPE_BWE_HR_TR); ind2 = ind1; move16(); @@ -363,7 +367,7 @@ void swb_bwe_enc_hr_fx( move16(); } - push_indice_fx( st_fx, IND_HR_ENVELOPE, ind1, NBITS_ENVELOPE_BWE_HR_TR - 1 ); + push_indice_fx( hBstr, IND_HR_ENVELOPE, ind1, NBITS_ENVELOPE_BWE_HR_TR - 1 ); nBits = sub(nBits, NBITS_ENVELOPE_BWE_HR_TR - 1); } @@ -433,7 +437,7 @@ void swb_bwe_enc_hr_fx( L_en_noncoded_fx = L_deposit_h(en_band_fx[N_BANDS_TRANS_BWE_HR-1]); /* to Put in Q16+9 */ } - push_indice_fx( st_fx, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); + push_indice_fx( hBstr, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); } ELSE @@ -450,7 +454,7 @@ void swb_bwe_enc_hr_fx( Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; move16(); AVQ_cod_fx(t_audio_fx + add(temp, NUM_TRANS_START_FREQ_COEF), x_norm_fx, nBits, Nsv, t_audio_fx_exp); - AVQ_encmux_fx(st_fx, st_fx->extl_fx, x_norm_fx, &nBits, Nsv, nq); + AVQ_encmux_fx(hBstr, st_fx->extl_fx, x_norm_fx, &nBits, Nsv, nq, 0, sub(Nsv, 1)); } } @@ -502,7 +506,7 @@ void swb_bwe_enc_hr_fx( L_gain_fx = L_shr(L_tmp, sub(31-16, exp2)); /* 31: 'L_tmp' is already in Q31 */ ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1); - push_indice_fx( st_fx, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); + push_indice_fx( hBstr, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); /* normalization with global gain */ @@ -542,8 +546,8 @@ void swb_bwe_enc_hr_fx( ind1 = en_band_quant_fx( en_band_fx, swb_hr_env_code1_fx, NUM_ENVLOPE_CODE_HR1 ); ind2 = en_band_quant_fx( en_band_fx + 2, swb_hr_env_code2_fx, NUM_ENVLOPE_CODE_HR2 ); - push_indice_fx( st_fx, IND_HR_ENVELOPE, ind1, NBITS_ENVELOPE_BWE_HR1 ); - push_indice_fx( st_fx, IND_HR_ENVELOPE, ind2, NBITS_ENVELOPE_BWE_HR2 ); + push_indice_fx( hBstr, IND_HR_ENVELOPE, ind1, NBITS_ENVELOPE_BWE_HR1 ); + push_indice_fx( hBstr, IND_HR_ENVELOPE, ind2, NBITS_ENVELOPE_BWE_HR2 ); nBits = sub(nBits, NBITS_ENVELOPE_BWE_HR1 + NBITS_ENVELOPE_BWE_HR2); @@ -669,7 +673,7 @@ void swb_bwe_enc_hr_fx( L_en_noncoded_fx = L_mult0(min_env_fx, 16384); } - push_indice_fx( st_fx, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); + push_indice_fx( hBstr, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); } ELSE @@ -685,7 +689,7 @@ void swb_bwe_enc_hr_fx( Nsv = shr(i, WIDTH_BAND_SHIFT); AVQ_cod_fx(t_audio_tmp_fx/*same exponent as t_audio_fx*/, x_norm_fx, nBits, Nsv, t_audio_fx_exp); - AVQ_encmux_fx(st_fx, st_fx->extl_fx, x_norm_fx, &nBits, Nsv, nq); + AVQ_encmux_fx(hBstr, st_fx->extl_fx, x_norm_fx, &nBits, Nsv, nq, 0, sub(Nsv, 1)); /*---------------------------------------------------------------------* * second stage coding @@ -754,7 +758,7 @@ void swb_bwe_enc_hr_fx( /* Put in Q16 */ L_gain_fx = L_shr(L_temp, sub(31-16, temp2)); /* 31: 'L_temp' is already in Q31 */ ind1 = gain_quant_fx( &L_gain_fx, &gain2_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp2); - push_indice_fx( st_fx, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); + push_indice_fx( hBstr, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); /* normalize with global gain */ @@ -770,7 +774,7 @@ void swb_bwe_enc_hr_fx( set16_fx( nq2, 0, Nsv ); AVQ_cod_fx( t_audio_fx, x_norm1_fx, nBits, Nsv2, t_audio_fx_exp ); - AVQ_encmux_fx( st_fx, st_fx->extl_fx, x_norm1_fx, &nBits, Nsv2, nq2 ); + AVQ_encmux_fx(hBstr, st_fx->extl_fx, x_norm1_fx, &nBits, Nsv2, nq2, 0, sub(Nsv2, 1)); } } /* 'ELSE' of ' IF( is_transient )' */ @@ -779,7 +783,7 @@ void swb_bwe_enc_hr_fx( WHILE( nBits > 0 ) { i = s_min( nBits, 16 ); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); + push_indice_fx( hBstr, IND_UNUSED, 0, i ); nBits = sub(nBits, i); } return; diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 6c7dfb0..e3ab838 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -1,13 +1,10 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include +#include #include "options.h" - #include "prot_fx.h" #include "rom_com_fx.h" -#include "stl.h" #include "basop_mpy.h" /*--------------------------------------------------------------------------* @@ -22,9 +19,9 @@ Word16 GetSubbandCorrIndex2_har_fx( /* o : best correlation index const Word16 *predBuf_fx, /* i : prediction buffer (i.e., lowband) : sspectra */ const Word16 predBufLen, /* i : sspectra buffer size */ const Word16 maxLag_fx, /* i : search length */ - const GainItem_fx *G_item_fx, /* i : */ + const GainItem_fx *G_item_fx, /* i : */ const Word16 nZero_fx, /* i : number of nonzero components used in */ - Word16 *prev_frame_bstindx_fx /* i : previous frame best Indices */ + Word16 *prev_frame_bstindx_fx /* i : previous frame best Indices */ ) { Word16 i, j; @@ -207,16 +204,16 @@ Word16 GetSubbandCorrIndex2_har_fx( /* o : best correlation index *--------------------------------------------------------------------------*/ static void getswbindices_har_fx( - const Word32 *L_yos, /* i : original input spectrum */ - Word16 exp_refBuf, /* i : */ - Word16 *y2_fx, /* i : decoded spectrum */ - const Word16 nBands_search_fx, /* i : number of bands */ - Word16 *lagIndices_fx, /* o : pulse index */ - Word16 *prev_frame_bstindx_fx, /* i/o: prev frame index */ - const Word16 swb_lowband_fx, /* i : length of the LF spectrum */ - const Word16 *subband_offsets_fx, /* i : */ - const Word16 *sbWidth_fx, /* i : */ - const Word16 *subband_search_offset_fx /* i : */ + const Word32 *L_yos, /* i : original input spectrum */ + Word16 exp_refBuf, /* i : */ + Word16 *y2_fx, /* i : decoded spectrum */ + const Word16 nBands_search_fx, /* i : number of bands */ + Word16 *lagIndices_fx, /* o : pulse index */ + Word16 *prev_frame_bstindx_fx, /* i/o: prev frame index */ + const Word16 swb_lowband_fx, /* i : length of the LF spectrum */ + const Word16 *subband_offsets_fx, /* i : */ + const Word16 *sbWidth_fx, /* i : */ + const Word16 *subband_search_offset_fx /* i : */ ) { Word16 i, j, k, sb, tmp; @@ -288,6 +285,10 @@ static void getswbindices_har_fx( return; } +/*--------------------------------------------------------------------------* + * GetSubbandCorrIndex2_pulsestep_fx() + * + *--------------------------------------------------------------------------*/ static Word16 GetSubbandCorrIndex2_pulsestep_fx( const Word32 *L_inBuf, /* i: original input vector (highband) */ @@ -516,19 +517,22 @@ static Word16 GetSubbandCorrIndex2_pulsestep_fx( return bestIdx_fx; } - +/*--------------------------------------------------------------------------* + * GetSWBIndices_fx() + * + *--------------------------------------------------------------------------*/ static void GetSWBIndices_fx( - const Word16 *predBuf_fx, /* i : low-frequency band */ - /*const Word16 Qss,*/ /* i : Q value of predBuf_fx */ - const Word32 *L_targetBuf, /* i : SWB MDCT coeff. */ - const Word16 Qsh, /* i : Q value of L_targetBuf */ - const Word16 nBands_search, /* i : number of search subbands */ - const Word16 *sbWidth, /* i : subband lengths */ - Word16 *lagIndices, /* o : selected lags for subband coding */ - const Word16 predBufLen, /* i : low-frequency band length */ - GainItem_fx *gi_fx, /* o : most representative region */ - const Word16 *subband_offsets, /* o : N biggest components */ - Word16 *predBuf_ni_fx /* i : low-frequency band filled noise */ + const Word16 *predBuf_fx, /* i : low-frequency band */ + /*const Word16 Qss,*/ /* i : Q value of predBuf_fx */ + const Word32 *L_targetBuf, /* i : SWB MDCT coeff. */ + const Word16 Qsh, /* i : Q value of L_targetBuf */ + const Word16 nBands_search, /* i : number of search subbands */ + const Word16 *sbWidth, /* i : subband lengths */ + Word16 *lagIndices, /* o : selected lags for subband coding */ + const Word16 predBufLen, /* i : low-frequency band length */ + GainItem_fx *gi_fx, /* o : most representative region */ + const Word16 *subband_offsets, /* o : N biggest components */ + Word16 *predBuf_ni_fx /* i : low-frequency band filled noise */ ) { Word16 j; @@ -599,34 +603,38 @@ static void GetSWBIndices_fx( } } +/*--------------------------------------------------------------------------* + * gethar_noisegn_fx() + * + *--------------------------------------------------------------------------*/ static void gethar_noisegn_fx( - Encoder_State_fx *st_fx, - Word32 L_spectra[], /* i : Qs input MDCT */ - Word16 QsL, /* i : Q0 Q value for L_spectra, L_xSynth_har */ - Word16 noise_flr_fx[], /* i : Qss noise floor */ - Word16 Qss, /* i : Q0 Q value for noise_flr_fx, sspectra */ - Word32 L_xSynth_har[], /* o : Qs output SWB MDCT */ - const Word16 sbWidth[], /* i : Q0 band width for SWB */ - const Word16 lagIndices[], /* i : Q0 lag Indices */ - const Word16 bands, /* i : Q0 all band number */ - const Word16 har_bands, /* i : Q0 harmonic band number */ - const Word16 fLenLow, /* i : Q0 low frequency band width */ - const Word16 fLenHigh, /* i : Q0 SWB band width */ - const Word16 subband_offsets[], /* i : Q0 offset */ - const Word16 subband_search_offset[], /* i : Q0 offset */ - const Word16 band_start[], /* i : Q0 band start array */ - const Word16 band_end[], /* i : Q0 band end array */ - const Word16 band_width[], /* i : Q0 band width */ - Word32 L_band_energy[], /* i : Qbe band energy (Log scale) */ - Word16 Qbe, /* i : Q0 Q value for L_band_energy */ - Word32 L_be_tonal[], /* o : QbeL tonal energy */ - Word16 *QbeL, /* o : Q0 Q value for L_be_tonal */ - Word16 *sspectra_fx, /* i : Qss smoothed spectrum */ - Word16 har_freq_est2, /* i : Q0 for harmonic structure */ - Word16 pos_max_hfe2, /* i : Q0 for harmonic structure */ - Word16 *pul_res_fx, /* o : Q0 */ - GainItem_fx pk_sf_fx[] /* o : */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word32 L_spectra[], /* i : Qs input MDCT */ + const Word16 QsL, /* i : Q0 Q value for L_spectra, L_xSynth_har */ + const Word16 noise_flr_fx[], /* i : Qss noise floor */ + const Word16 Qss, /* i : Q0 Q value for noise_flr_fx, sspectra */ + Word32 L_xSynth_har[], /* o : Qs output SWB MDCT */ + const Word16 sbWidth[], /* i : Q0 band width for SWB */ + const Word16 lagIndices[], /* i : Q0 lag Indices */ + const Word16 bands, /* i : Q0 all band number */ + const Word16 har_bands, /* i : Q0 harmonic band number */ + const Word16 fLenLow, /* i : Q0 low frequency band width */ + const Word16 fLenHigh, /* i : Q0 SWB band width */ + const Word16 subband_offsets[], /* i : Q0 offset */ + const Word16 subband_search_offset[], /* i : Q0 offset */ + const Word16 band_start[], /* i : Q0 band start array */ + const Word16 band_end[], /* i : Q0 band end array */ + const Word16 band_width[], /* i : Q0 band width */ + Word32 L_band_energy[], /* i : Qbe band energy (Log scale) */ + const Word16 Qbe, /* i : Q0 Q value for L_band_energy */ + Word32 L_be_tonal[], /* o : QbeL tonal energy */ + Word16 *QbeL, /* o : Q0 Q value for L_be_tonal */ + const Word16 *sspectra_fx, /* i : Qss smoothed spectrum */ + const Word16 har_freq_est2, /* i : Q0 for harmonic structure */ + const Word16 pos_max_hfe2, /* i/o : Q0 for harmonic structure */ + Word16 *pul_res_fx, /* o : Q0 */ + GainItem_fx pk_sf_fx[] /* o : */ ) { Word16 i; @@ -758,7 +766,7 @@ static void gethar_noisegn_fx( } } - push_indice_fx( st_fx,IND_NOISEG, imin_fx, 2); + push_indice_fx( hBstr,IND_NOISEG, imin_fx, 2); /*g=(float) pow (10.0f,gain_table[imin]);*/ L_temp = L_mult(gain_table_SWB_BWE_fx[imin_fx], 27213); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ @@ -776,33 +784,39 @@ static void gethar_noisegn_fx( return; } - +/*--------------------------------------------------------------------------* + * EncodeSWBSubbands() + * + * Main routine for generic SWB coding. High-frequency subband + * replicated based on the lowband signal. A search is perform + * find lowband indices denoting the selected lowband subband. + *--------------------------------------------------------------------------*/ static void EncodeSWBSubbands_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value for L_spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 nBands_search_fx, /* i : number of subbands to be searched for BWE */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : Subband offset for BWE */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 BANDS_fx, /* i : noise estimate from WB part */ - const Word16 *band_start_fx, /* i : Number subbands/Frame */ - const Word16 *band_end_fx, /* i : Band Start of each SB */ - Word32 *L_band_energy, /* i : Band end of each SB, :Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - const Word16 *p2a_flags_fx, /* i : BAnd energy of each SB */ - const Word16 hqswb_clas_fx, /* i : lowband synthesis */ - Word16 *prev_frm_index_fx, /* i : clas information */ - const Word16 har_bands_fx, /* i/o: Index of the previous Frame */ - const Word16 *subband_search_offset_fx,/* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ - const Word16 band_width_fx[], /* i : band width */ - const Word32 L_spectra_ni[], /* i : Qs noise injected spectra */ - Word16 *ni_seed_fx /* i/o: random seed */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + Word32 *L_spectra, /* i/o: MDCT domain spectrum */ + Word16 QsL, /* i : Q value for L_spectra */ + const Word16 fLenLow_fx, /* i : lowband length */ + const Word16 fLenHigh_fx, /* i : highband length */ + const Word16 nBands_fx, /* i : number of subbands */ + const Word16 nBands_search_fx, /* i : number of subbands to be searched for BWE */ + const Word16 *sbWidth_fx, /* i : subband lengths */ + const Word16 *subband_offsets_fx, /* i : Subband offset for BWE */ + Word16 *lagIndices_fx, /* o : lowband index for each subband */ + const Word16 BANDS_fx, /* i : noise estimate from WB part */ + const Word16 *band_start_fx, /* i : Number subbands/Frame */ + const Word16 *band_end_fx, /* i : Band Start of each SB */ + Word32 *L_band_energy, /* i : Band end of each SB, :Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + const Word16 *p2a_flags_fx, /* i : BAnd energy of each SB */ + const Word16 hqswb_clas_fx, /* i : lowband synthesis */ + Word16 *prev_frm_index_fx, /* i : clas information */ + const Word16 har_bands_fx, /* i/o: Index of the previous Frame */ + const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ + Word16 *prev_frm_hfe2_fx, /* i/o: */ + Word16 *prev_stab_hfe2_fx, /* i/o: */ + const Word16 band_width_fx[], /* i : band width */ + const Word32 L_spectra_ni[], /* i : Qs noise injected spectra */ + Word16 *ni_seed_fx /* i/o: random seed */ ) { Word16 i, k; @@ -826,6 +840,7 @@ static void EncodeSWBSubbands_fx( Word16 har_freq_est1,har_freq_est2; Word16 flag_dis; Word16 pos_max_hfe2; + HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; har_freq_est1 = 0; move16(); @@ -845,7 +860,7 @@ static void EncodeSWBSubbands_fx( IF( EQ_16(hqswb_clas_fx, HQ_HARMONIC)) { pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2_fx, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2_fx ); - noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx , st_fx->prev_hqswb_clas_fx ,&st_fx->prev_ni_ratio_fx, &Qss); + noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx , hHQ_core->prev_hqswb_clas_fx ,&hHQ_core->prev_ni_ratio_fx, &Qss); /* Find best indices for each group */ getswbindices_har_fx( L_spectra, @@ -855,7 +870,7 @@ static void EncodeSWBSubbands_fx( /* Write the indices into the bitstream */ FOR (k = 0; k < nBands_search_fx; k++) { - push_indice_fx( st_fx, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har_fx[k]); + push_indice_fx( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har_fx[k]); } IF ( flag_dis == 0 ) @@ -868,17 +883,14 @@ static void EncodeSWBSubbands_fx( } } - gethar_noisegn_fx( - st_fx, - L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har, + gethar_noisegn_fx( st_fx->hBstr, L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har, sbWidth_fx, lagIndices_fx, BANDS_fx, har_bands_fx, fLenLow_fx, fLenHigh_fx, subband_offsets_fx, subband_search_offset_fx, band_start_fx, band_end_fx, band_width_fx, L_band_energy, Qbe, L_be_tonal, &QbeL, sspectra_fx, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx); - Gettonl_scalfact_fx( - L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, + Gettonl_scalfact_fx(L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx ,Qss, pul_res_fx); IF( flag_dis == 0 ) @@ -903,15 +915,11 @@ static void EncodeSWBSubbands_fx( } ELSE { - ss_min_fx = spectrumsmooth_noiseton_fx( - L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx); + ss_min_fx = spectrumsmooth_noiseton_fx(L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx); /* Get lag indices */ - GetSWBIndices_fx( sspectra_fx, /*Qss,*/ - L_spectra + fLenLow_fx, QsL, - nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, - Nbiggest_fx, subband_offsets_fx, sspectra_fx - ); + GetSWBIndices_fx( sspectra_fx, /*Qss,*/ L_spectra + fLenLow_fx, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, + Nbiggest_fx, subband_offsets_fx, sspectra_fx); /* Bitstream operations */ FOR(k=0; khBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_modeNormal_fx[k]); } } - convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_fx, - sspectra_fx, sbWidth_fx, fLenLow_fx ); + convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); GetlagGains_fx( sspectra_ni_fx, Qss, &L_band_energy[BANDS_fx-NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, lagGains_fx, QlagGains ); FOR(k=0; kprev_En_sb_fx, - p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx); + noiseinj_hf_fx( L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx); FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) @@ -981,30 +985,34 @@ static void EncodeSWBSubbands_fx( return; } - +/*--------------------------------------------------------------------------* + * swb_bwe_enc_lr() + * + * Main encoding routine of SWB BWE for the LR MDCT core + *--------------------------------------------------------------------------*/ void swb_bwe_enc_lr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - Word16 QsL, /* i : Q value */ - const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band_energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ - Word16 lowlength_fx, /* i : lowband length */ - Word16 highlength_fx, /* i : highband length */ - Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band_width information */ - const Word32 L_y2_ni[], /* i : band_width information */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis */ + Word16 QsL, /* i : Q value */ + const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ + Word16 *band_start_fx, /* i : band start of each SB */ + Word16 *band_end_fx, /* i : band end of each SB */ + Word32 *L_band_energy, /* i : band_energy of each SB */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator */ + const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ + Word16 lowlength_fx, /* i : lowband length */ + Word16 highlength_fx, /* i : highband length */ + Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ + const Word16 band_width_fx[],/* i : band_width information */ + const Word32 L_y2_ni[], /* i : band_width information */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ ) { Word16 k; diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 5065177..06fcacb 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -51,6 +51,9 @@ void wb_pre_proc_fx( Word16 fSwitchFromIO = 0; Word32 temp1 = 0; Word32 temp2 = 0; + SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; test(); test(); @@ -92,8 +95,8 @@ void wb_pre_proc_fx( Q_wb_sp = sub(Q_wb_sp, 3); /* leave 3 bit headroom */ } Copy_Scale_sig(new_inp_resamp16k, temp_buf, L_FRAME16k, Q_wb_sp); - Scale_sig(st_fx->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); - Scale_sig(st_fx->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); + Scale_sig(hBWE_TD->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); + Scale_sig(hBWE_TD->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); /* temp_buf, and the memory states are in Q_wb_sp */ test(); @@ -112,16 +115,16 @@ void wb_pre_proc_fx( ramp_flag = 1; } - IF ( !st_fx->ppp_mode_fx) + IF ( !hSC_VBR->ppp_mode_fx) { /* temp_buf is in Q_wb_sp hb_speech and the two decimator memories are in Q_wb_sp */ - flip_spectrum_and_decimby4_fx( temp_buf, hb_speech, L_FRAME16k, st_fx->decim_state1_fx, st_fx->decim_state2_fx, ramp_flag ); + flip_spectrum_and_decimby4_fx( temp_buf, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag ); /* rescale the hb_speech and memories back to Q-1 to keep the downstream BWE coding unaffected */ Scale_sig(hb_speech, L_FRAME16k/4, -Q_wb_sp); - Scale_sig(st_fx->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); - Scale_sig(st_fx->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); + Scale_sig(hBWE_TD->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); + Scale_sig(hBWE_TD->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); IF( NE_16(st_fx->extl_fx, WB_TBE)) { @@ -130,29 +133,29 @@ void wb_pre_proc_fx( highband_new_speech = highband_old_speech + Sample_Delay_WB_BWE; Copy( hb_speech, highband_new_speech, L_FRAME16k / 4 ); - Copy( highband_old_speech + L_FRAME16k / 4, st_fx->old_speech_wb_fx, Sample_Delay_WB_BWE ); + Copy( highband_old_speech + L_FRAME16k / 4, hBWE_TD->old_speech_wb_fx, Sample_Delay_WB_BWE ); } } } ELSE { - set16_fx( st_fx->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st_fx->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st_fx->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); + set16_fx(hBWE_TD->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set16_fx(hBWE_TD->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set16_fx(hBWE_TD->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); } /* st->old_input_wb and st->old_wtda_wb must be updated each frame, or there are often some clicks during WB TBE <-> WB BWE switching */ test(); test(); test(); - IF ( (NE_16(st_fx->extl_fx, WB_BWE)||(EQ_16(st_fx->extl_fx,WB_BWE)&&LE_32(st_fx->total_brate_fx,ACELP_8k00)))&&!st_fx->ppp_mode_fx) + IF ( (NE_16(st_fx->extl_fx, WB_BWE)||(EQ_16(st_fx->extl_fx,WB_BWE)&&LE_32(st_fx->total_brate_fx,ACELP_8k00)))&&!hSC_VBR->ppp_mode_fx) { Sample_Delay_WB_BWE = NS2SA_fx2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); Copy( new_inp_resamp16k, &old_input[Sample_Delay_WB_BWE], L_FRAME16k ); - Copy( st_fx->old_input_wb_fx, old_input, Sample_Delay_WB_BWE ); - Copy( new_inp_resamp16k + L_FRAME16k - Sample_Delay_WB_BWE, st_fx->old_input_wb_fx, Sample_Delay_WB_BWE ); - Copy( old_input, st_fx->L_old_wtda_swb_fx, L_FRAME16k ); + Copy(hBWE_FD->old_input_wb_fx, old_input, Sample_Delay_WB_BWE ); + Copy( new_inp_resamp16k + L_FRAME16k - Sample_Delay_WB_BWE, hBWE_FD->old_input_wb_fx, Sample_Delay_WB_BWE ); + Copy( old_input, hBWE_FD->L_old_wtda_swb_fx, L_FRAME16k ); } return; } @@ -212,6 +215,8 @@ void swb_pre_proc_fx( /* Highband energy computation using CLDFB */ Word32 CldfbHB_ener; Word16 realQ_neg1, imagQ_neg1, exp, Cldfbtemp1; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; FOR( j=0; j < CLDFB_NO_COL_MAX; j++ ) { @@ -231,20 +236,20 @@ void swb_pre_proc_fx( IF( NE_16(st_fx->last_extl_fx, SWB_BWE)&&NE_16(st_fx->last_extl_fx,FB_BWE)&&NE_16(st_fx->extl_fx,SWB_BWE_HIGHRATE)) { Sample_Delay_SWB_BWE = NS2SA_fx2( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); - Copy( st_fx->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); + Copy(hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); - Copy( st_fx->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, st_fx->old_input_fx, Sample_Delay_SWB_BWE ); + Copy(hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); IF( sub(st_fx->extl_fx, WB_BWE) != 0 ) { - Copy( old_input_fx, st_fx->L_old_wtda_swb_fx, L_FRAME32k ); + Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, L_FRAME32k ); } } test(); IF( NE_16(st_fx->extl_fx, SWB_BWE)&&NE_16(st_fx->extl_fx,FB_BWE)) { - Copy( input_fx, st_fx->old_fdbwe_speech_fx, L_FRAME32k ); + Copy( input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k ); } } ELSE /* 48 kHz */ @@ -257,7 +262,7 @@ void swb_pre_proc_fx( IF( NE_16(st_fx->extl_fx,SWB_BWE)&&NE_16(st_fx->extl_fx,FB_BWE)&&EQ_16(st_fx->core_fx,ACELP_CORE)) { /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */ - Copy( input_fx, st_fx->old_fdbwe_speech_fx, L_FRAME48k ); + Copy( input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k ); } ELSE { @@ -269,21 +274,21 @@ void swb_pre_proc_fx( { inner_frame = L_FRAME48k; inner_Fs = 48000; - Copy( st_fx->old_fdbwe_speech_fx, new_swb_speech_fx, L_FRAME48k ); + Copy(hBWE_FD->old_fdbwe_speech_fx, new_swb_speech_fx, L_FRAME48k ); } ELSE { inner_frame = L_FRAME32k; inner_Fs = 32000; - decimate_2_over_3_allpass_fx( st_fx->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech_fx, st_fx->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st_fx->dec_2_over_3_mem_lp_fx ); + decimate_2_over_3_allpass_fx(hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, + decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, hBWE_TD->dec_2_over_3_mem_lp_fx ); } Sample_Delay_SWB_BWE = NS2SA_fx2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); Copy( new_swb_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame ); set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); - Copy( new_swb_speech_fx + inner_frame - Sample_Delay_SWB_BWE, st_fx->old_input_fx, Sample_Delay_SWB_BWE ); - Copy( old_input_fx, st_fx->L_old_wtda_swb_fx, inner_frame ); + Copy( new_swb_speech_fx + inner_frame - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, inner_frame ); st_fx->Q_old_wtda = 0; move16(); } @@ -294,8 +299,8 @@ void swb_pre_proc_fx( } ELSE { - decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, st_fx->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st_fx->dec_2_over_3_mem_lp_fx ); + decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, + decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, hBWE_TD->dec_2_over_3_mem_lp_fx ); } } } @@ -308,8 +313,8 @@ void swb_pre_proc_fx( } ELSE { - decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, st_fx->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st_fx->dec_2_over_3_mem_lp_fx ); + decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, + decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, hBWE_TD->dec_2_over_3_mem_lp_fx ); } } } @@ -382,7 +387,7 @@ void swb_pre_proc_fx( Cldfbtemp1 = (Log2_norm_lc(CldfbHB_ener)); Cldfbtemp1 = add(shr(Cldfbtemp1, 6), shl(sub(30, sub(exp, 2)), 9));/* Log2_norm_lc(CldfbHB_ener) = 2^15*(log2(CldfbHB_ener/2^30)) = 2^15*(log2(CldfbHB_fl*(2^-2)*2^exp/2^30)) = 2^15*(log2(CldfbHB_fl) + exp-2-30) => 2^(-6)*l2nc + 2^9(20-(exp-2)) = 2^9*log2(CldfbHB_fl), Q9 */ CldfbHB_ener = L_mult(sub(Cldfbtemp1, 1741/*3.401 Q9*/), 3495); /* 3495 = Q19 log10(2)*0.1/log10(32768), Q = 19+9+1 = 29 */ - st_fx->cldfbHBLT = mac_r(CldfbHB_ener, 29491/*0.9 Q15*/, st_fx->cldfbHBLT); /* cldfbHBLT is in Q13 */ + hBWE_TD->cldfbHBLT = mac_r(CldfbHB_ener, 29491/*0.9 Q15*/, hBWE_TD->cldfbHBLT); /* cldfbHBLT is in Q13 */ } cldfbSynthesisFiltering( st_fx->cldfbSyn_Fx, realBufferFlipped, imagBufferFlipped, cldfbScale, shb_speech_fx, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer ); @@ -394,14 +399,14 @@ void swb_pre_proc_fx( { /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ delay = L_LOOK_16k + L_SUBFR16k; - Copy( shb_speech_fx + L_FRAME16k - delay, st_fx->old_speech_shb_fx, delay ); + Copy( shb_speech_fx + L_FRAME16k - delay, hBWE_TD->old_speech_shb_fx, delay ); } } ELSE { IF( EQ_16(st_fx->bwidth_fx, FB)||EQ_16(st_fx->core_fx,ACELP_CORE)) { - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx(hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); set16_fx( shb_speech_fx, 0, L_FRAME16k ); /* shb_speech for FB/SWB BWE_HIGHRATE is not used at 64kbps */ } ELSE @@ -414,8 +419,8 @@ void swb_pre_proc_fx( spchTmp_fx[i] = negate(spchTmp_fx[i]); } - Decimate_allpass_steep_fx( spchTmp_fx, st_fx->state_ana_filt_shb_fx, L_FRAME32k, shb_speech_fx ); - Copy( shb_speech_fx + L_FRAME16k - (L_LOOK_16k + L_SUBFR16k), st_fx->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); + Decimate_allpass_steep_fx( spchTmp_fx, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech_fx ); + Copy( shb_speech_fx + L_FRAME16k - (L_LOOK_16k + L_SUBFR16k), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); } /* Reset CLDFB synthesis buffer */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 0852934..22f8364 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -94,18 +94,19 @@ void find_max_mem_enc( Word16 max = 0; Word32 Lmax = 0; Word16 tempQ15, max2 = 0; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* old BWE exc max */ FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) { - tempQ15 = abs_s( st_fx->old_bwe_exc_extended_fx[i] ); + tempQ15 = abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ); max = s_max( max, tempQ15 ); } /* decimate all-pass steep memory */ FOR ( i = 0; i < (2*ALLPASSSECTIONS_STEEP+1); i++ ) { - tempQ15 = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); + tempQ15 = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); max = s_max(max, tempQ15); } @@ -114,21 +115,21 @@ void find_max_mem_enc( /* findMaxMem2() inside tbe com */ FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s( st_fx->state_lpc_syn_fx[i] ); + tempQ15 = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); max2 = s_max(max2, tempQ15); } /* findMaxMem2() inside tbe com */ FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) { - tempQ15 = abs_s( st_fx->state_syn_shbexc_fx[i] ); + tempQ15 = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); max2 = s_max(max2, tempQ15); } /* findMaxMem2() inside tbe com */ FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s( st_fx->mem_stp_swb_fx[i] ); + tempQ15 = abs_s( hBWE_TD->mem_stp_swb_fx[i] ); max2 = s_max(max2, tempQ15); } @@ -141,21 +142,21 @@ void find_max_mem_enc( } /* de-emph and pre-emph memory */ - tempQ15 = abs_s( st_fx->tbe_demph_fx ); + tempQ15 = abs_s( hBWE_TD->tbe_demph_fx ); max = s_max(max, tempQ15); - tempQ15 = abs_s( st_fx->tbe_premph_fx ); + tempQ15 = abs_s( hBWE_TD->tbe_premph_fx ); max = s_max(max, tempQ15); IF( EQ_16(st_fx->extl_fx, FB_TBE)) { FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - tempQ15 = abs_s( st_fx->fb_state_lpc_syn_fx[i] ); + tempQ15 = abs_s( hBWE_TD->fb_state_lpc_syn_fx[i] ); max = s_max(max, tempQ15); } /* FB de-emph memory */ - tempQ15 = abs_s( st_fx->fb_tbe_demph_fx); + tempQ15 = abs_s( hBWE_TD->fb_tbe_demph_fx); max = s_max(max, tempQ15); } /* estimate the norm for 16-bit memories */ @@ -166,7 +167,7 @@ void find_max_mem_enc( } /* estimate the norm for 32-bit memories */ - Lmax = L_abs( st_fx->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ + Lmax = L_abs( hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ n_mem_32 = norm_l( Lmax ); if( Lmax == 0 ) @@ -187,16 +188,17 @@ void find_max_mem_enc( void rescale_genSHB_mem_enc( Encoder_State_fx* st_fx, Word16 sf ) { Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FOR( i = 0; i old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); + hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } FOR ( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } @@ -205,23 +207,23 @@ void rescale_genSHB_mem_enc( Encoder_State_fx* st_fx, Word16 sf ) { FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); + hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); + hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); } } - st_fx->mem_csfilt_fx[0] = L_shl( st_fx->mem_csfilt_fx[0], sf ); + hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); move32(); - st_fx->tbe_demph_fx = shl_r( st_fx->tbe_demph_fx, sf ); + hBWE_TD->tbe_demph_fx = shl_r( hBWE_TD->tbe_demph_fx, sf ); move16(); - st_fx->tbe_premph_fx = shl_r( st_fx->tbe_premph_fx, sf ); + hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); } @@ -232,38 +234,39 @@ void find_max_mem_wb_enc( Encoder_State_fx* st_fx, Word16* n_mem ) Word16 n_mem_32; Word16 max =0; Word32 Lmax =0; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FOR ( i = 0; i < NL_BUFF_OFFSET; i++ ) - max = s_max( max, abs_s( st_fx->old_bwe_exc_extended_fx[i] ) ); + max = s_max( max, abs_s( hBWE_TD->old_bwe_exc_extended_fx[i] ) ); FOR ( i = 0; i < 7; i++ ) { - IF ( abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); + IF ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) + max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); } FOR ( i = 0; i < 7; i++ ) { - IF ( abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ); + IF ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) + max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ); } FOR ( i = 0; i < 7; i++ ) { - IF ( abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ); + IF ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) + max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } FOR ( i = 0; i < 10; i++ ) { - IF ( abs_s( st_fx->state_lpc_syn_fx[i] ) > max ) - max = abs_s( st_fx->state_lpc_syn_fx[i] ); + IF ( abs_s( hBWE_TD->state_lpc_syn_fx[i] ) > max ) + max = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); } FOR ( i = 0; i < 5; i++ ) { - IF ( abs_s( st_fx->state_syn_shbexc_fx[i] ) > max ) - max = abs_s( st_fx->state_syn_shbexc_fx[i] ); + IF ( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ) > max ) + max = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); } IF ( max == 0 ) @@ -279,8 +282,8 @@ void find_max_mem_wb_enc( Encoder_State_fx* st_fx, Word16* n_mem ) FOR ( i = 0; i < 2; i++ ) { - IF ( L_abs( st_fx->mem_csfilt_fx[i] ) > Lmax ) - Lmax = L_abs( st_fx->mem_csfilt_fx[i] ); + IF ( L_abs( hBWE_TD->mem_csfilt_fx[i] ) > Lmax ) + Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } @@ -302,46 +305,47 @@ void find_max_mem_wb_enc( Encoder_State_fx* st_fx, Word16* n_mem ) void rescale_genWB_mem_enc( Encoder_State_fx* st_fx, Word16 sf ) { Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FOR ( i = 0; i < NL_BUFF_OFFSET; i++ ) { - st_fx->old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); + hBWE_TD->old_bwe_exc_extended_fx[i] = shl( hBWE_TD->old_bwe_exc_extended_fx[i], sf ); move16(); } FOR ( i = 0; i < 10; i++ ) { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); + hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } FOR ( i = 0; i < 5; i++ ) { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); + hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); move16(); } FOR ( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); move16(); } FOR ( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_wb2_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb2_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i], sf ); move16(); } FOR ( i = 0; i < 7; i++ ) { - st_fx->mem_genSHBexc_filt_down_wb3_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb3_fx[i], sf ); + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i], sf ); move16(); } FOR ( i = 0; i < 2; i++ ) { - st_fx->mem_csfilt_fx[i] = L_shl( st_fx->mem_csfilt_fx[i], sf ); + hBWE_TD->mem_csfilt_fx[i] = L_shl( hBWE_TD->mem_csfilt_fx[i], sf ); move32(); } } @@ -356,35 +360,96 @@ void InitSWBencBuffer_fx( Encoder_State_fx* st_fx /* i/o: SHB encoder structure */ ) { - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( st_fx->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - st_fx->bwe_seed_fx[0] = 23; + Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); + hBWE_TD->bwe_seed_fx[0] = 23; move16(); - st_fx->bwe_seed_fx[1] = 59; + hBWE_TD->bwe_seed_fx[1] = 59; move16(); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + + set16_fx(hBWE_TD->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1)); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); + hBWE_TD->prev_fb_energy_fx = 0; + move16(); + + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx(hBWE_TD->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5 / 16); + set16_fx(hBWE_TD->old_input_fhb_fx, 0, NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k / 2); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + //IVAS_CODE + //set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); + //set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); + //hBWE_TD->old_mean_EnvSHBres = 0.0f; + //hBWE_TD->prev_enr_EnvSHBres = 1.0f; + //hBWE_TD->prev_shb_env_tilt = 0.0f; + //hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; + //hBWE_TD->prev_mix_factor = 1.0f; + //hBWE_TD->prev_Env_error = 0.0f; + set16_fx(hBWE_TD->prev_lsp_shb_fx, 0, 10 ); - set16_fx(st_fx->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1)); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); - st_fx->prev_fb_energy_fx = 0; + hBWE_TD->cldfbHBLT = 8192/*1.0f Q13*/; + move16(); + hBWE_TD->prev_gainFr_SHB_fx = 0; + set16_fx(hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER); + set16_fx(hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER); + set16_fx(hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); + set16_fx(hBWE_TD->lsp_shb_spacing_fx, 3277, 3); + set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); + + hBWE_TD->prev_swb_GainShape_fx = 0; + move16(); + hBWE_TD->prev_frGainAtten_fx = 0; + move16(); + hBWE_TD->prev_wb_GainShape = 0; + move16(); + hBWE_TD->prev_Q_bwe_exc_fb = 51; move16(); - set16_fx( st_fx->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); - st_fx->prev_fb_energy_fx_Q = 0; + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); + hBWE_TD->tilt_mem_fx = 0; + move16(); + + hBWE_TD->prev_coder_type_fx = GENERIC; + move16(); + set16_fx(hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2); + hBWE_TD->prev_tilt_para_fx = 0; + move16(); + set16_fx(hBWE_TD->cur_sub_Aq_fx, 0, M + 1); + + /* TD BWE post-processing */ + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; + set16_fx(hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER); + + FOR(i = 0; i < LPC_SHB_ORDER; i++) + { + hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + } + + set16_fx(hBWE_TD->dec_2_over_3_mem_fx, 0, 12); + set16_fx(hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6); + + + + hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - set16_fx( st_fx->prev_lsp_shb_fx, 0, 10 ); + + + // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD st_fx->prev_Q_bwe_exc = 31; move16(); st_fx->prev_Q_bwe_syn = 31; move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); + set16_fx(st_fx->prev_lsp_wb_fx, 0, 6 ); + set16_fx(st_fx->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx(st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); return; } @@ -397,32 +462,34 @@ void ResetSHBbuffer_Enc_fx( Encoder_State_fx* st_fx /* i/o: SHB encoder structure */ ) { + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + /* states for the filters used in generating SHB excitation from WB excitation*/ - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); /* states for the filters used in generating SHB signal from SHB excitation*/ - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - IF( EQ_16(st_fx->extl_fx, FB_TBE)) + //IF( EQ_16(st_fx->extl_fx, FB_TBE)) _DIFF_FLOAT_FIX_ { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; move16(); } /* states for the filters used in generating WB signal from WB excitation*/ - set16_fx( st_fx->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx( hBWE_TD->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx( hBWE_TD->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); /* overlap buffer used to Adjust SHB Frame Gain */ - set16_fx(st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER); - st_fx->gain_prec_swb_fx = 16384;/*Q14=1 */ - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - st_fx->tbe_demph_fx = 0; - st_fx->tbe_premph_fx = 0; + set16_fx(hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER); + hBWE_TD->gain_prec_swb_fx = 16384;/*Q14=1 */ + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + hBWE_TD->tbe_demph_fx = 0; + hBWE_TD->tbe_premph_fx = 0; return; @@ -507,14 +574,17 @@ void wb_tbe_enc_fx( Word16 uv_flag; Word16 dummy=0; Word16 avg_voice_fac; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + RF_ENC_HANDLE hRF = st_fx->hRF; + /*Word16 att = 32767;*/ hb_new_speech = hb_old_speech + WBTBE_LOOK_LSUFBR_5_OVER_16; hb_frame = hb_old_speech + WBTBE_LSUBFR_5_OVER_16 + WBTBE_ANA_ALIGNDELAY; - Copy( st_fx->old_speech_wb_fx, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); + Copy( hBWE_TD->old_speech_wb_fx, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); Copy( hb_speech, hb_new_speech, LFRAME16K_OVER_4 ); - Copy( hb_old_speech + LFRAME16K_OVER_4, st_fx->old_speech_wb_fx, WBTBE_LOOK_LSUFBR_5_OVER_16 ); + Copy( hb_old_speech + LFRAME16K_OVER_4, hBWE_TD->old_speech_wb_fx, WBTBE_LOOK_LSUFBR_5_OVER_16 ); test(); test(); @@ -624,12 +694,12 @@ void wb_tbe_enc_fx( i = closest_centroid_fx( lsp_wb, weights_lsp, lbr_wb_bwe_lsfvq_cbook_2bit_fx, 4, LPC_SHB_ORDER_LBR_WB ); IF( EQ_16(st_fx->codec_mode, MODE2)) { - st_fx->lsf_WB_fx = i; + hBWE_TD->lsf_WB_fx = i; move16(); } ELSE { - push_indice_fx( st_fx, IND_SHB_LSF, i, NUM_BITS_LBR_WB_LSF ); + push_indice_fx( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_LBR_WB_LSF ); } Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); @@ -686,12 +756,12 @@ void wb_tbe_enc_fx( IF( EQ_16(st_fx->codec_mode, MODE2)) { - st_fx->lsf_WB_fx = i; + hBWE_TD->lsf_WB_fx = i; move16(); } ELSE { - push_indice_fx( st_fx, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); + push_indice_fx( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); } Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); @@ -770,27 +840,27 @@ void wb_tbe_enc_fx( move16(); FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - prev_pow = L_mac0( prev_pow, st_fx->state_syn_shbexc_fx[i], st_fx->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ + prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ } rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR ( i = 0; i < L_FRAME32k; i++ ) { bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - Copy( st_fx->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, st_fx->mem_csfilt_fx, - st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx, - st_fx->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, st_fx->bwe_seed_fx, + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed_fx, vf_modified_fx, uv_flag , st_fx->igf ); @@ -807,7 +877,7 @@ void wb_tbe_enc_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub(st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); FOR ( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) @@ -821,17 +891,17 @@ void wb_tbe_enc_fx( shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ /* Update WB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape,subwin_wb_fx, NULL ); /* Gain frame adjustment factor */ test(); - IF( GainShape[0] && st_fx->prev_wb_GainShape ) + IF( GainShape[0] && hBWE_TD->prev_wb_GainShape ) { - exp = norm_s( st_fx->prev_wb_GainShape ); - tmp = div_s( shl(1,sub( 14,exp )), st_fx->prev_wb_GainShape ); + exp = norm_s( hBWE_TD->prev_wb_GainShape ); + tmp = div_s( shl(1,sub( 14,exp )), hBWE_TD->prev_wb_GainShape ); L_tmp = L_mult( GainShape[0], tmp ); /* Q(30 - exp) */ exp1 = norm_l( L_tmp ); @@ -890,7 +960,7 @@ void wb_tbe_enc_fx( } - temp_wb_fac_fx = st_fx->prev_wb_GainShape; + temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; move16(); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -900,7 +970,7 @@ void wb_tbe_enc_fx( move16(); } - st_fx->prev_wb_GainShape = GainShape[sub(shr(NUM_SHB_SUBFR,2),1)]; + hBWE_TD->prev_wb_GainShape = GainShape[sub(shr(NUM_SHB_SUBFR,2),1)]; move16(); p2m_in = pow_off_pk_fx( GainShape, shr(NUM_SHB_SUBFR,2), 1 ); move16(); @@ -916,7 +986,7 @@ void wb_tbe_enc_fx( } ELSE { - push_indice_fx( st_fx, IND_UV_FLAG, uv_flag, 1 ); + push_indice_fx( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); /* Quantization of the subframe gain parameter */ QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl_fx ); @@ -1001,11 +1071,11 @@ void wb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl_fx, st_fx->extl_brate_fx, &st_fx->rf_bwe_gainFr_ind ); + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl_fx, st_fx->extl_brate_fx, &hRF->rf_bwe_gainFr_ind ); /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ - ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, st_fx->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, + ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); st_fx->prev_Q_bwe_exc = Q_bwe_exc; @@ -1134,6 +1204,8 @@ void swb_tbe_enc_fx( Word16 tilt_para; Word16 Q_bwe_exc_fb; Word16 n_subfr_saturation; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + RF_ENC_HANDLE hRF = st_fx->hRF; /* init and buffers set up */ exp1 = 0; /* to avoid compilation warnings */ @@ -1146,9 +1218,9 @@ void swb_tbe_enc_fx( /* set up the speech buffers for TBE processing*/ shb_new_speech_fx = shb_old_speech_fx + (L_LOOK_16k + L_SUBFR16k); move16(); - Copy( st_fx->old_speech_shb_fx, shb_old_speech_fx, (L_LOOK_16k + L_SUBFR16k) ); + Copy(hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, (L_LOOK_16k + L_SUBFR16k) ); Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, st_fx->old_speech_shb_fx, (L_LOOK_16k + L_SUBFR16k) ); + Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, (L_LOOK_16k + L_SUBFR16k) ); /* autocorrelation of SHB speech for 10-th order LP analysis */ autocorr_fx( shb_old_speech_fx, @@ -1211,7 +1283,7 @@ void swb_tbe_enc_fx( /* LPC to LSP conversion */ /* LPC: Q12, LSP: Q15 */ - E_LPC_a_lsp_conversion(lpc_shb_fx, lsp_shb_fx, st_fx->prev_lsp_shb_fx, LPC_SHB_ORDER ); + E_LPC_a_lsp_conversion(lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); /* LSP to LSF conversion */ /* LSP: Q15, LSF: Q15 */ @@ -1221,7 +1293,7 @@ void swb_tbe_enc_fx( gain Frame smoothing and attenuation control */ gainFrSmooth_En_fx(st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn); - Copy( lsp_shb_fx, st_fx->prev_lsp_shb_fx, LPC_SHB_ORDER ); + Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); test(); @@ -1238,8 +1310,8 @@ void swb_tbe_enc_fx( i = closest_centroid_fx( lsf_shb_fx, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER ); Copy(swb_tbe_lsfvq_cbook_8b + i*LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER); - set16_fx(st_fx->lsf_idx_fx, 0, NUM_Q_LSF); - st_fx->lsf_idx_fx[0] = i; + set16_fx(hBWE_TD->lsf_idx_fx, 0, NUM_Q_LSF); + hBWE_TD->lsf_idx_fx[0] = i; } ELSE { @@ -1294,7 +1366,7 @@ void swb_tbe_enc_fx( IF( EQ_16(st_fx->last_extl_fx, SWB_TBE)||EQ_16(st_fx->last_extl_fx,FB_TBE)) { /* SHB LSP values from prev. frame for interpolation */ - Copy(st_fx->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER); + Copy(hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER); } ELSE { @@ -1307,7 +1379,7 @@ void swb_tbe_enc_fx( { lsf_diff[i] = sub(lsf_shb_fx[i],lsf_shb_fx[sub(i,1)]); } - a2rc_fx (st_fx->cur_sub_Aq_fx+1, refl, M); + a2rc_fx (hBWE_TD->cur_sub_Aq_fx+1, refl, M); /* LSP interpolation for 13.2 kbps and 16.4 kbps */ /* tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) @@ -1323,7 +1395,7 @@ void swb_tbe_enc_fx( { FOR( i=1; iprev_lsf_diff_fx[i-1] = mult(lsf_diff[i],16384);/*Q15*/ + hBWE_TD->prev_lsf_diff_fx[i-1] = mult(lsf_diff[i],16384);/*Q15*/ } } @@ -1334,21 +1406,21 @@ void swb_tbe_enc_fx( test(); test(); test(); - IF(!(GT_16(st_fx->prev_tilt_para_fx,5120)&&(EQ_16(coder_type_fx,TRANSITION)||LT_16(tilt_para,1024)))&& - !(((LT_16(st_fx->prev_tilt_para_fx,3072) && GE_16(st_fx->prev_coder_type_fx,VOICED) )) && GT_16(tilt_para,5120) )) + IF(!(GT_16(hBWE_TD->prev_tilt_para_fx,5120)&&(EQ_16(coder_type_fx,TRANSITION)||LT_16(tilt_para,1024)))&& + !(((LT_16(hBWE_TD->prev_tilt_para_fx,3072) && GE_16(hBWE_TD->prev_coder_type_fx,VOICED) )) && GT_16(tilt_para,5120) )) { FOR( i = 1; i < LPC_SHB_ORDER-1; i++ ) { - IF(LT_16(lsf_diff[i],st_fx->prev_lsf_diff_fx[i-1])) + IF(LT_16(lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i-1])) { tmp = mult(26214,lsf_diff[i]); - tmp = div_s(tmp,st_fx->prev_lsf_diff_fx[i-1]); + tmp = div_s(tmp, hBWE_TD->prev_lsf_diff_fx[i-1]); tmp = s_max(tmp,16384); w[i] = s_min(tmp,32767); } ELSE { - tmp = mult(26214,st_fx->prev_lsf_diff_fx[i-1]); + tmp = mult(26214,hBWE_TD->prev_lsf_diff_fx[i-1]); tmp = div_s(tmp,lsf_diff[i]); tmp = s_max(tmp,16384); w[i] = s_min(tmp,32767); @@ -1370,8 +1442,8 @@ void swb_tbe_enc_fx( } } - Copy( lsf_diff + 1, st_fx->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = tilt_para; + Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); + hBWE_TD->prev_tilt_para_fx = tilt_para; shb_ener_sf_Q31 = 0; move16(); @@ -1459,7 +1531,7 @@ void swb_tbe_enc_fx( Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_fx[0]),2) ); /* Q12 */ /* Save the SWB LSP values from current frame for interpolation */ - Copy(lsp_shb_2_fx, st_fx->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); /* lsp_shb_2_fx in Q15 */ + Copy(lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); /* lsp_shb_2_fx in Q15 */ /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ @@ -1492,17 +1564,17 @@ void swb_tbe_enc_fx( } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + Copy(hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( st_fx->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + Copy(hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); /* save the previous Q factor of the buffer */ st_fx->prev_Q_bwe_exc = Q_bwe_exc; @@ -1511,10 +1583,10 @@ void swb_tbe_enc_fx( Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = st_fx->prev_Q_bwe_exc_fb; + Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; move16(); /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &st_fx->tilt_mem_fx ); + formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ @@ -1522,22 +1594,22 @@ void swb_tbe_enc_fx( move16(); GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, - st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - coder_type_fx, bwe_exc_extended_16, st_fx->bwe_seed_fx, vf_modified_fx, st_fx->extl_fx, - &( st_fx->tbe_demph_fx ), &( st_fx->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, - shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, st_fx->fb_state_lpc_syn_fx, - &(st_fx->fb_tbe_demph_fx), &Q_bwe_exc,&Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate_fx, 0 ); + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + coder_type_fx, bwe_exc_extended_16, hBWE_TD->bwe_seed_fx, vf_modified_fx, st_fx->extl_fx, + &(hBWE_TD->tbe_demph_fx ), &(hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, + shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, + &(hBWE_TD->fb_tbe_demph_fx), &Q_bwe_exc,&Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate_fx, 0 ); *Q_white_exc = Q_bwe_exc_fb; IF( EQ_16(st_fx->extl_fx, FB_TBE)) { - st_fx->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; } ELSE { /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - st_fx->prev_Q_bwe_exc_fb = 51; + hBWE_TD->prev_Q_bwe_exc_fb = 51; move16(); } @@ -1546,24 +1618,24 @@ void swb_tbe_enc_fx( { IF( EQ_16( st_fx->codec_mode, MODE2 )) { - st_fx->idx_mixFac_fx = vf_ind_fx; + hBWE_TD->idx_mixFac_fx = vf_ind_fx; move16(); } ELSE { - push_indice_fx( st_fx, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF); + push_indice_fx( st_fx->hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF); } } FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->mem_stp_swb_fx[i] = shl(st_fx->mem_stp_swb_fx[i], sub(Q_bwe_exc, st_fx->prev_Q_bwe_syn) ); + hBWE_TD->mem_stp_swb_fx[i] = shl(hBWE_TD->mem_stp_swb_fx[i], sub(Q_bwe_exc, st_fx->prev_Q_bwe_syn) ); } FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { - PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD+i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], st_fx->mem_stp_swb_fx, - st_fx->ptr_mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx), st_fx->mem_zero_swb_fx, formant_fac_fx ); + PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD+i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); /* i: shaped_shb_excitation_fx in Q_bwe_exc */ /* i: lpc_shb_fx in Q12 */ } @@ -1612,7 +1684,7 @@ void swb_tbe_enc_fx( } /* Update SHB excitation */ - Copy( shaped_shb_excitation_fx + L_FRAME16k, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ + Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ /* Estimate the gain-shape parameter */ n_subfr_saturation = 0; @@ -1621,7 +1693,7 @@ void swb_tbe_enc_fx( Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation ); /* Gain shape BWS/high band low energy fix */ - IF( LT_16(st_fx->cldfbHBLT, 8192/*1.0f Q13*/)) /* cldfbHBLT in Q13 */ + IF( LT_16(hBWE_TD->cldfbHBLT, 8192/*1.0f Q13*/)) /* cldfbHBLT in Q13 */ { /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ FOR(i = 0; i < NUM_SHB_SUBGAINS; i++) @@ -1635,10 +1707,10 @@ void swb_tbe_enc_fx( /* Gain frame adjustment factor */ /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ test(); - IF( GainShape_fx[0] && st_fx->prev_swb_GainShape_fx ) + IF( GainShape_fx[0] && hBWE_TD->prev_swb_GainShape_fx ) { - exp = norm_s( st_fx->prev_swb_GainShape_fx ); - tmp = div_s( shl(1, sub( 14, exp )), st_fx->prev_swb_GainShape_fx ); + exp = norm_s(hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl(1, sub( 14, exp )), hBWE_TD->prev_swb_GainShape_fx ); L_tmp = L_mult( GainShape_fx[0], tmp );/*Q(30 - exp) */ exp1 = norm_l( L_tmp ); @@ -1716,7 +1788,7 @@ void swb_tbe_enc_fx( IF( EQ_16(frGainAttenuate,1)||(GT_16(tmp,19661)&>_16(tmp1,6554))) { - temp_swb_fac = st_fx->prev_swb_GainShape_fx; + temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ @@ -1725,7 +1797,7 @@ void swb_tbe_enc_fx( move16(); } } - st_fx->prev_swb_GainShape_fx = GainShape_fx[3]; + hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; move16(); /* Compute the power of gains away from the peak gain prior to quantization */ @@ -1755,9 +1827,9 @@ void swb_tbe_enc_fx( GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ } test(); - IF( EQ_16(frGainSmoothEn,1)&<_32(st_fx->prev_gainFr_SHB_fx,GainFrame_fx)) + IF( EQ_16(frGainSmoothEn,1)&<_32(hBWE_TD->prev_gainFr_SHB_fx,GainFrame_fx)) { - GainFrame_fx = L_add( L_shr(st_fx->prev_gainFr_SHB_fx, 1), L_shr(GainFrame_fx, 1) ); /* Q18 */ + GainFrame_fx = L_add( L_shr(hBWE_TD->prev_gainFr_SHB_fx, 1), L_shr(GainFrame_fx, 1) ); /* Q18 */ } test(); @@ -1772,15 +1844,15 @@ void swb_tbe_enc_fx( exp = sub( exp, 30); GainFrame_fx = L_shl( GainFrame_fx, exp + 18 ); /* Q18 */ } - ELSE IF( EQ_16(st_fx->prev_frGainAtten_fx, 1)&>_32(Mult_32_16(GainFrame_fx,10923),st_fx->prev_gainFr_SHB_fx)) + ELSE IF( EQ_16(hBWE_TD->prev_frGainAtten_fx, 1)&>_32(Mult_32_16(GainFrame_fx,10923), hBWE_TD->prev_gainFr_SHB_fx)) { /*GainFrame *= (0.8f + 0.5f*feedback); */ tmp = add( 26214, mult_r( feedback, 16384 ) ); GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ } - st_fx->prev_frGainAtten_fx = frGainAttenuate; + hBWE_TD->prev_frGainAtten_fx = frGainAttenuate; move16(); - st_fx->prev_gainFr_SHB_fx = GainFrame_fx; + hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; move16(); /* Q18 */ @@ -1847,7 +1919,7 @@ void swb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl_fx, 0, &st_fx->rf_bwe_gainFr_ind ); + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl_fx, 0, &hRF->rf_bwe_gainFr_ind ); /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation */ @@ -2530,6 +2602,8 @@ static void QuantizeSHBsubgains_fx( Word16 Unit_weights10[NUM_SHB_SUBFR]; Word16 exp, frac; Word32 L_tmp; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; IF( EQ_16(extl, WB_TBE)) { @@ -2555,7 +2629,7 @@ static void QuantizeSHBsubgains_fx( idxSubGain = closest_centroid_lc_fx( subgains + NUM_SHB_SUBFR / 4, HBCB_SubGain5bit_fx, 1 << NUM_BITS_SHB_SUBGAINS ); Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, subgains, NUM_SHB_SUBFR / 4 ); - push_indice_fx( st_fx, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); + push_indice_fx( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -2619,11 +2693,11 @@ static void QuantizeSHBsubgains_fx( move16(); } - st_fx->idxSubGains_fx = idxSubGain; + hBWE_TD->idxSubGains_fx = idxSubGain; move16(); IF( NE_16( st_fx->codec_mode, MODE2 )) { - push_indice_fx( st_fx, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); + push_indice_fx( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); } } @@ -2650,6 +2724,7 @@ static void Quant_shb_ener_sf_fx( Word32 L_tmp1, L_tmp; Word32 sum; Word16 tmp; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ @@ -2674,11 +2749,11 @@ static void Quant_shb_ener_sf_fx( L_tmp = Pow2(14, frac ); *shb_ener_sf_Q31 = L_shl(L_tmp, exp-14+Q_ener ); /* In Q_ener */ - st_fx->idx_shb_fr_gain_fx = idxSubEner_fx; + hBWE_TD->idx_shb_fr_gain_fx = idxSubEner_fx; move16(); IF( NE_16( st_fx->codec_mode, MODE2 )) { - push_indice_fx( st_fx, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF); + push_indice_fx( st_fx->hBstr, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF); } return; } @@ -2696,6 +2771,7 @@ static void Quant_shb_res_gshape_fx( ) { Word16 i, idxSubGain_fx[NB_SUBFR16k]; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FOR(i = 0; i < NB_SUBFR16k; i++) { @@ -2705,10 +2781,10 @@ static void Quant_shb_res_gshape_fx( 1024/*0.125f Q13*/, /*1024 = 0.125 in Q13 */ shl(1,NUM_BITS_SHB_RES_GS)); - st_fx->idx_res_gs_fx[i] = idxSubGain_fx[i]; + hBWE_TD->idx_res_gs_fx[i] = idxSubGain_fx[i]; IF ( NE_16( st_fx->codec_mode, MODE2 )) { - push_indice_fx( st_fx, IND_SHB_RES_GS1+i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS); + push_indice_fx( st_fx->hBstr, IND_SHB_RES_GS1+i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS); } } } @@ -2746,6 +2822,8 @@ static void QuantizeSHBframegain_fx( Word16 exp, frac, tmp; Word32 L_tmp; Word32 GainFrameLog; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + RF_ENC_HANDLE hRF = st_fx->hRF; IF( EQ_16(extl, WB_TBE)) { @@ -2761,7 +2839,7 @@ static void QuantizeSHBframegain_fx( idxFrameGain--; Q_GainFrame = L_add(SHBCB_FrameGain16_fx[idxFrameGain], 0); /* Q18 */ } - st_fx->gFrame_WB_fx = idxFrameGain; + hBWE_TD->gFrame_WB_fx = idxFrameGain; move16(); *rf_gainFrame_ind = idxFrameGain; } @@ -2771,7 +2849,7 @@ static void QuantizeSHBframegain_fx( 1 << NUM_BITS_SHB_FrameGain, &idxFrameGain, &Q_GainFrame, SHBCB_FrameGain64_fx ); - push_indice_fx( st_fx, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FrameGain ); + push_indice_fx( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FrameGain ); *rf_gainFrame_ind = idxFrameGain; move16(); /* Q18 */ } @@ -2828,11 +2906,11 @@ static void QuantizeSHBframegain_fx( exp = sub ( exp, 30) ; Q_GainFrame = L_shl( Q_GainFrame, exp + 18 ); /* Q18 */ - st_fx->idxFrameGain_fx = idxFrameGain; + hBWE_TD->idxFrameGain_fx = idxFrameGain; move16(); IF ( NE_16( st_fx->codec_mode, MODE2 )) { - push_indice_fx( st_fx, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); + push_indice_fx( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); } *rf_gainFrame_ind = idxFrameGain; } @@ -2840,20 +2918,28 @@ static void QuantizeSHBframegain_fx( IF( EQ_16(st_fx->rf_mode,1)) { /*Currently intended for SWB only. Modify for WB is needed later!*/ - IF( EQ_16(st_fx->rf_frame_type,RF_NELP)) + IF( EQ_16(hRF->rf_frame_type,RF_NELP)) { *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ } ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ { - IF( *GainFrame <= 327680 /*1.25 in Q18*/ ) /* [0 to 1.25] range --> 0.5*/ - *rf_gainFrame_ind = 0; - ELSE IF ( *GainFrame <= 786432 /*3 in Q18*/ ) /* (1.25 to 3] --> 2 */ - *rf_gainFrame_ind = 1; - ELSE IF ( *GainFrame <= 1572864 /*6 in Q18*/ ) /* (3 to 6] --> 4 */ - *rf_gainFrame_ind = 2; + IF(*GainFrame <= 327680 /*1.25 in Q18*/) /* [0 to 1.25] range --> 0.5*/ + { + *rf_gainFrame_ind = 0; + } + ELSE IF(*GainFrame <= 786432 /*3 in Q18*/) /* (1.25 to 3] --> 2 */ + { + *rf_gainFrame_ind = 1; + } + ELSE IF(*GainFrame <= 1572864 /*6 in Q18*/) /* (3 to 6] --> 4 */ + { + *rf_gainFrame_ind = 2; + } ELSE /* (6 to Inf) --> 8 */ - *rf_gainFrame_ind = 3; + { + *rf_gainFrame_ind = 3; + } } } @@ -3267,6 +3353,7 @@ static void gainFrSmooth_En_fx(Encoder_State_fx *st_fx, Word32 tempQ31; Word16 tempQ15_1, tempQ15_2; Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* inits */ *frGainAttenuate = 0; @@ -3279,17 +3366,17 @@ static void gainFrSmooth_En_fx(Encoder_State_fx *st_fx, move16(); /* estimate the mean square error in lsps from current frame to past frames */ - tempQ15_1 = sub( lsp_shb_fx[0], st_fx->lsp_shb_slow_interpl_fx[0] ); - tempQ15_2 = sub( lsp_shb_fx[0], st_fx->lsp_shb_fast_interpl_fx[0] ); + tempQ15_1 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_slow_interpl_fx[0] ); + tempQ15_2 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_fast_interpl_fx[0] ); lsp_slow_evol_rate = L_mult(tempQ15_1, tempQ15_1 ); lsp_fast_evol_rate = L_mult(tempQ15_2, tempQ15_2 ); /* update the slow and fast lsp interp for next frame */ - tempQ31 = L_mult(st_fx->lsp_shb_slow_interpl_fx[0], 22937 ); - st_fx->lsp_shb_slow_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 9830 ); + tempQ31 = L_mult(hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 ); + hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 9830 ); move16(); - tempQ31 = L_mult(st_fx->lsp_shb_fast_interpl_fx[0], 9830 ); - st_fx->lsp_shb_fast_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 22937 ); + tempQ31 = L_mult(hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 ); + hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 22937 ); move16(); FOR( i = 1; i < LPC_SHB_ORDER; i++ ) @@ -3298,17 +3385,17 @@ static void gainFrSmooth_En_fx(Encoder_State_fx *st_fx, lsp_spacing = s_min( lsp_spacing, tempQ15_1); /* estimate the mean square error in lsps from current frame to past frames */ - tempQ15_1 = sub( lsp_shb_fx[i], st_fx->lsp_shb_slow_interpl_fx[i] ); - tempQ15_2 = sub( lsp_shb_fx[i], st_fx->lsp_shb_fast_interpl_fx[i] ); + tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); + tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); lsp_slow_evol_rate = L_mac(lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); lsp_fast_evol_rate = L_mac(lsp_fast_evol_rate , tempQ15_2, tempQ15_2 ); /* update the slow and fast interpolation lsps for next frame */ - tempQ31 = L_mult(st_fx->lsp_shb_slow_interpl_fx[i], 22937 ); - st_fx->lsp_shb_slow_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 9830 ); + tempQ31 = L_mult(hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 ); + hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 9830 ); move16(); - tempQ31 = L_mult(st_fx->lsp_shb_fast_interpl_fx[i], 9830 ); - st_fx->lsp_shb_fast_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 22937 ); + tempQ31 = L_mult(hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 ); + hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 22937 ); move16(); } @@ -3318,34 +3405,34 @@ static void gainFrSmooth_En_fx(Encoder_State_fx *st_fx, && NE_16(st_fx->last_extl_fx, FB_TBE) && LT_16( lsp_spacing, 262 ) ) { - st_fx->lsp_shb_spacing_fx[0] = lsp_spacing; + hBWE_TD->lsp_shb_spacing_fx[0] = lsp_spacing; move16(); - st_fx->lsp_shb_spacing_fx[1] = lsp_spacing; + hBWE_TD->lsp_shb_spacing_fx[1] = lsp_spacing; move16(); - st_fx->lsp_shb_spacing_fx[2] = lsp_spacing; + hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; move16(); - st_fx->prev_frGainAtten_fx = 1; + hBWE_TD->prev_frGainAtten_fx = 1; move16(); - set16_fx(st_fx->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); + set16_fx(hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); } /* Estimate the moving average LSP spacing */ - tempQ31 = L_mult(st_fx->lsp_shb_spacing_fx[0], 3277); /* 0.1f */ - tempQ31 = L_mac(tempQ31, st_fx->lsp_shb_spacing_fx[1], 6553); /* 0.2f */ - tempQ31 = L_mac(tempQ31, st_fx->lsp_shb_spacing_fx[2], 9830); /* 0.3f */ + tempQ31 = L_mult(hBWE_TD->lsp_shb_spacing_fx[0], 3277); /* 0.1f */ + tempQ31 = L_mac(tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553); /* 0.2f */ + tempQ31 = L_mac(tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830); /* 0.3f */ *MA_lsp_shb_spacing = mac_r(tempQ31, lsp_spacing, 13107); /* 0.4f */ - st_fx->lsp_shb_spacing_fx[0] = st_fx->lsp_shb_spacing_fx[1]; + hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; move16(); - st_fx->lsp_shb_spacing_fx[1] = st_fx->lsp_shb_spacing_fx[2]; + hBWE_TD->lsp_shb_spacing_fx[1] = hBWE_TD->lsp_shb_spacing_fx[2]; move16(); - st_fx->lsp_shb_spacing_fx[2] = lsp_spacing; + hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; move16(); test(); test(); test(); - IF( ( LT_16( lsp_spacing, 262 )&&(LT_16(*MA_lsp_shb_spacing,164)||EQ_16(st_fx->prev_frGainAtten_fx,1))) + IF( ( LT_16( lsp_spacing, 262 )&&(LT_16(*MA_lsp_shb_spacing,164)||EQ_16(hBWE_TD->prev_frGainAtten_fx,1))) || LE_16( lsp_spacing, 105 ) ) { *frGainAttenuate = 1; @@ -3354,11 +3441,11 @@ static void gainFrSmooth_En_fx(Encoder_State_fx *st_fx, IF( NE_32(st_fx->total_brate_fx , ACELP_24k40)) { Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD ); - fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, st_fx->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1,3); + fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1,3); } ELSE { - set16_fx(st_fx->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); + set16_fx(hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); } test(); @@ -3391,6 +3478,9 @@ static void Quant_BWE_LSF_fx( Word16 m_idx; Word16 m; Word16 grid_idx; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { @@ -3404,29 +3494,29 @@ static void Quant_BWE_LSF_fx( FOR( i = 0; i < NUM_Q_LSF; i++ ) { - st_fx->lsf_idx_fx[i] = lsf_idx[i]; + hBWE_TD->lsf_idx_fx[i] = lsf_idx[i]; move16(); IF( NE_16( st_fx->codec_mode, MODE2 )) { - push_indice_fx( st_fx, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); + push_indice_fx(hBstr, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); } } m_idx = Quant_mirror_point_fx( lsf, lsf_q, &m ); - st_fx->m_idx_fx = m_idx; + hBWE_TD->m_idx_fx = m_idx; move16(); IF( NE_16( st_fx->codec_mode, MODE2 )) { - push_indice_fx( st_fx, IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS ); + push_indice_fx(hBstr, IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS ); } grid_idx = Find_LSF_grid_fx( lsf, lsf_q, m ); - st_fx->grid_idx_fx = grid_idx; + hBWE_TD->grid_idx_fx = grid_idx; IF( NE_16( st_fx->codec_mode, MODE2 )) { - push_indice_fx( st_fx, IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS ); + push_indice_fx(hBstr, IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS ); } FOR( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -3460,6 +3550,7 @@ void fb_tbe_enc_fx( Word32 L_tmp; Word16 tmp,tmp1,tmp2,exp,exp2,exp_norm; Word16 s_max_value,exp_temp,i; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; s_max_value = 0; FOR( i = 0; i < L_FRAME48k; i++ ) @@ -3475,25 +3566,25 @@ void fb_tbe_enc_fx( Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); - elliptic_bpf_48k_generic_fx( input_fhb, &exp_temp , tmp_vec, st->elliptic_bpf_2_48k_mem_fx, st->elliptic_bpf_2_48k_mem_fx_Q,full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( input_fhb, &exp_temp , tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,full_band_bpf_2_fx ); Sample_Delay_HP = NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2 ; IF( NE_16(st->last_extl_fx,FB_TBE)) { - set16_fx( st->old_input_fhb_fx, 0, Sample_Delay_HP ); - st->old_input_fhb_fx_Q = 0; + set16_fx( hBWE_TD->old_input_fhb_fx, 0, Sample_Delay_HP ); + hBWE_TD->old_input_fhb_fx_Q = 0; move16(); set16_fx( tmp_vec, 0, L_FRAME16k ); } - Copy_Scale_sig( st->old_input_fhb_fx, st->old_input_fhb_fx, Sample_Delay_HP, sub(exp_temp,st->old_input_fhb_fx_Q) ); - st->old_input_fhb_fx_Q = exp_temp; - Copy( st->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); + Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub(exp_temp,hBWE_TD->old_input_fhb_fx_Q) ); + hBWE_TD->old_input_fhb_fx_Q = exp_temp; + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k-Sample_Delay_HP ); - Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, st->old_input_fhb_fx, Sample_Delay_HP ); + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); temp2 = sum2_fx_mod( input_fhb, L_FRAME48k/2 );/* Q11 */ - temp2 = L_add(temp2,L_shl(st->prev_fb_energy_fx,sub(sub(add(exp_temp,exp_temp),6),st->prev_fb_energy_fx_Q)));/* Q11 */ - st->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k/2, L_FRAME48k/2 );/*Q11*/ - st->prev_fb_energy_fx_Q = sub(add(exp_temp,exp_temp),6); + temp2 = L_add(temp2,L_shl(hBWE_TD->prev_fb_energy_fx,sub(sub(add(exp_temp,exp_temp),6),hBWE_TD->prev_fb_energy_fx_Q)));/* Q11 */ + hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k/2, L_FRAME48k/2 );/*Q11*/ + hBWE_TD->prev_fb_energy_fx_Q = sub(add(exp_temp,exp_temp),6); fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k );/* Q(2*Q_fb_exc+1 -7) */ /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ @@ -3547,11 +3638,11 @@ void fb_tbe_enc_fx( /* ratio = (float)(1 << idxGain);*/ IF( st->codec_mode == MODE2 ) { - st->idxGain_fx = idxGain; + hBWE_TD->idxGain_fx = idxGain; } ELSE { - push_indice_fx( st, IND_FB_SLOPE, idxGain, 4 ); + push_indice_fx( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); } return; @@ -3561,6 +3652,9 @@ void tbe_write_bitstream_fx( ) { Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + test(); test(); @@ -3570,10 +3664,10 @@ void tbe_write_bitstream_fx( IF ( ( st_fx->rf_mode || EQ_32( st_fx->total_brate_fx, ACELP_9k60 ))&&(EQ_16(st_fx->bwidth_fx,WB))) { /* WB LSF */ - push_next_indice_fx( st_fx, st_fx->lsf_WB_fx, NUM_BITS_LBR_WB_LSF ); + push_next_indice_fx(hBstr, hBWE_TD->lsf_WB_fx, NUM_BITS_LBR_WB_LSF ); /* WB frame */ - push_next_indice_fx( st_fx, st_fx->gFrame_WB_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + push_next_indice_fx(hBstr, hBWE_TD->gFrame_WB_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); } ELSE IF ( ( GE_32( st_fx->total_brate_fx, ACELP_9k60 ))&&(LE_32(st_fx->total_brate_fx,ACELP_32k))&& ( ( EQ_16( st_fx->bwidth_fx, SWB ) ) || ( EQ_16( st_fx->bwidth_fx, FB ) ) ) ) @@ -3583,53 +3677,53 @@ void tbe_write_bitstream_fx( test(); IF( (EQ_16(st_fx->rf_mode,1))||EQ_32(st_fx->total_brate_fx,ACELP_9k60)) { - push_next_indice_fx( st_fx, st_fx->lsf_idx_fx[0], 8 ); + push_next_indice_fx(hBstr, hBWE_TD->lsf_idx_fx[0], 8 ); } ELSE { FOR (i = 0; i < NUM_Q_LSF; i++) { - push_next_indice_fx( st_fx, st_fx->lsf_idx_fx[i], lsf_q_num_bits[i] ); + push_next_indice_fx(hBstr, hBWE_TD->lsf_idx_fx[i], lsf_q_num_bits[i] ); } /* LSF mirror points */ - push_next_indice_fx( st_fx, st_fx->m_idx_fx, MIRROR_POINT_BITS ); + push_next_indice_fx(hBstr, hBWE_TD->m_idx_fx, MIRROR_POINT_BITS ); /* LSF grid points */ - push_next_indice_fx( st_fx, st_fx->grid_idx_fx, NUM_LSF_GRID_BITS ); + push_next_indice_fx(hBstr, hBWE_TD->grid_idx_fx, NUM_LSF_GRID_BITS ); } /* Gain shape */ - push_next_indice_fx( st_fx, st_fx->idxSubGains_fx, NUM_BITS_SHB_SUBGAINS ); + push_next_indice_fx(hBstr, hBWE_TD->idxSubGains_fx, NUM_BITS_SHB_SUBGAINS ); /* frame gain */ - push_next_indice_fx( st_fx, st_fx->idxFrameGain_fx, NUM_BITS_SHB_FRAMEGAIN ); + push_next_indice_fx(hBstr, hBWE_TD->idxFrameGain_fx, NUM_BITS_SHB_FRAMEGAIN ); IF ( GE_32( st_fx->total_brate_fx, ACELP_24k40 )) { /* sub frame energy*/ - push_next_indice_fx( st_fx, st_fx->idx_shb_fr_gain_fx, NUM_BITS_SHB_ENER_SF ); + push_next_indice_fx(hBstr, hBWE_TD->idx_shb_fr_gain_fx, NUM_BITS_SHB_ENER_SF ); /* gain shapes residual */ FOR (i = 0; i < NB_SUBFR16k; i++) { - push_next_indice_fx( st_fx, st_fx->idx_res_gs_fx[i], NUM_BITS_SHB_RES_GS ); + push_next_indice_fx(hBstr, hBWE_TD->idx_res_gs_fx[i], NUM_BITS_SHB_RES_GS ); } /* voicing factor */ - push_next_indice_fx( st_fx, st_fx->idx_mixFac_fx, NUM_BITS_SHB_VF ); + push_next_indice_fx(hBstr, hBWE_TD->idx_mixFac_fx, NUM_BITS_SHB_VF ); } IF( EQ_16(st_fx->tec_tfa, 1)) { - push_next_indice_fx( st_fx, st_fx->tec_flag, BITS_TEC ); - push_next_indice_fx( st_fx, st_fx->tfa_flag, BITS_TFA ); + push_next_indice_fx(hBstr, st_fx->tec_flag, BITS_TEC ); + push_next_indice_fx(hBstr, st_fx->tfa_flag, BITS_TFA ); } } IF ( EQ_16( st_fx->bwidth_fx, FB )) { - push_next_indice_fx( st_fx, st_fx->idxGain_fx, 4 ); + push_next_indice_fx(hBstr, hBWE_TD->idxGain_fx, 4 ); } } @@ -3639,10 +3733,12 @@ void TBEreset_enc_fx( Word16 bandwidth /* i : bandwidth mode */ ) { + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + IF( NE_16(st_fx->last_core_fx,ACELP_CORE)) { - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l(0); st_fx->prev_Q_bwe_exc = 31; move16(); } @@ -3650,27 +3746,27 @@ void TBEreset_enc_fx( test(); IF( EQ_16( bandwidth, WB )) { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); - set16_fx( st_fx->state_lpc_syn_fx, 0, 10 ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); + wb_tbe_extras_reset_fx(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, 10 ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); + set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); } ELSE IF( ( EQ_16( bandwidth, SWB ))||(EQ_16(bandwidth,FB))) { - set16_fx( st_fx->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx), - st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx), &(hBWE_TD->tbe_premph_fx), + hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); IF( EQ_16( bandwidth, FB )) { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; move16(); - fb_tbe_reset_enc_fx( st_fx->elliptic_bpf_2_48k_mem_fx, &st_fx->prev_fb_energy_fx,st_fx->elliptic_bpf_2_48k_mem_fx_Q,&st_fx->prev_fb_energy_fx_Q); + fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx,hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,&hBWE_TD->prev_fb_energy_fx_Q); } } } diff --git a/lib_enc/tcq_core_enc_fx.c b/lib_enc/tcq_core_enc_fx.c index 82354f0..ff2d86b 100644 --- a/lib_enc/tcq_core_enc_fx.c +++ b/lib_enc/tcq_core_enc_fx.c @@ -1,14 +1,13 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include "options.h" /* Compilation switches */ #include "prot_fx.h" -#include "stl.h" -void tcq_core_LR_enc_fx( - Encoder_State_fx* st_fx, +ivas_error tcq_core_LR_enc_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 inp_vector_fx[], /* x5 */ const Word32 coefs_norm_fx[], /* Q12 */ Word32 coefs_quant_fx[], /* Q12 */ @@ -60,7 +59,10 @@ void tcq_core_LR_enc_fx( Word32 leftbits = 0; Word32 sepbits = 0; Word32 divider = 0; + ivas_error error; + error = IVAS_ERR_OK; + move16(); set16_fx(dpath, 0, 280); set32_fx(abuffer_fx, 0, MAX_PULSES); set32_fx(sbuffer_fx, 0, MAX_PULSES); @@ -427,11 +429,11 @@ void tcq_core_LR_enc_fx( j = sub(bit_budget, shl(nb_bytes, 3)); FOR( i = 0; i < nb_bytes; i++ ) { - push_indice_fx(st_fx, IND_HQ2_SUBBAND_TCQ, pbs_fx->buf[i], 8); + push_indice_fx(hBstr, IND_HQ2_SUBBAND_TCQ, pbs_fx->buf[i], 8); } IF( j > 0 ) { - push_indice_fx(st_fx, IND_HQ2_SUBBAND_TCQ, shr(pbs_fx->buf[nb_bytes],(8 - j)), j); + push_indice_fx(hBstr, IND_HQ2_SUBBAND_TCQ, shr(pbs_fx->buf[nb_bytes],(8 - j)), j); } /* Clear decoding buffer */ set32_fx(coefs_quant_fx, 0, sfm_end[BANDS-1]+1); @@ -469,6 +471,6 @@ void tcq_core_LR_enc_fx( - return; + return error; } diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index 6d4f911..bf9c4f1 100644 --- a/lib_enc/tcx_utils_enc.c +++ b/lib_enc/tcx_utils_enc.c @@ -201,18 +201,14 @@ void AnalyzePowerSpectrum( Word16 tmp, s1, s2; Word32 tmp32; Word8 tmp8; + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; lowpassLine = L_frameTCX; move16(); *powerSpec_e = 16; move16(); - TCX_MDST(signal, - powerSpec, - powerSpec_e, - left_overlap, - sub(L_frameTCX, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + TCX_MDST(signal, powerSpec, powerSpec_e, left_overlap, sub(L_frameTCX, shr(add(left_overlap, right_overlap), 1)), right_overlap, st->element_mode); iStart = 0; move16(); @@ -274,25 +270,25 @@ void AnalyzePowerSpectrum( ComputeSpectrumNoiseMeasure(powerSpec, L_frameTCX, - divide3216(L_mult(st->nmStartLine, L_frame), st->L_frame_fx), + divide3216(L_mult(hTcxEnc->nmStartLine, L_frame), st->L_frame_fx), tmp8, - st->memQuantZeros, + hTcxEnc->memQuantZeros, lowpassLine); IF( LE_32(st->total_brate_fx, ACELP_24k40)) { - lowpassLine = shl(mult(st->tcx_cfg.bandwidth, L_frame), 1); + lowpassLine = shl(mult(st->hTcxCfg->bandwidth, L_frame), 1); test(); detectLowpassFac(powerSpec, *powerSpec_e, L_frame, sub(st->last_core_fx, ACELP_CORE) == 0, - &st->measuredBwRatio, + &hTcxEnc->measuredBwRatio, lowpassLine); } ELSE { - st->measuredBwRatio = 0x4000; + hTcxEnc->measuredBwRatio = 0x4000; move16(); } } @@ -1814,6 +1810,7 @@ void ProcessIGF( Word16 isIndepFlag; Word16 bsBits; Word16 bsStart; + BSTR_ENC_HANDLE hBstr = st->hBstr; isIndepFlag = 1; @@ -1856,53 +1853,58 @@ void ProcessIGF( isTNSActive, /**< in: flag indicating if the TNS is active */ (st->last_core_fx == ACELP_CORE) ); - { - const Word32 tns_predictionGain = (&st->hIGFEnc)->tns_predictionGain; - const Word16 startLine = (&st->hIGFEnc)->infoStartLine; - const Word16 endLine = (&st->hIGFEnc)->infoStopLine; - const Word16 maxOrder = 8; - const Word32 *spec_before = (&st->hIGFEnc)->spec_be_igf; - Word16 curr_order = 0; - Word16 A[ITF_MAX_FILTER_ORDER+1]; - Word16 Q_A; - Word16 predictionGain = 0; - Word16 *flatteningTrigger = &(&st->hIGFEnc)->flatteningTrigger; - ITF_Detect_fx( spec_before, startLine, endLine, maxOrder, A, &Q_A, &predictionGain, &curr_order, shl((&st->hIGFEnc)->spec_be_igf_e, 1) ); - *flatteningTrigger = 0; - test(); - IF (LT_32(tns_predictionGain, 9646899l/*1.15 Q23*/)&& - LT_16(predictionGain, 147/*1.15 Q7*/)) { - *flatteningTrigger = 1; + const Word32 tns_predictionGain = st->hIGFEnc->tns_predictionGain; + const Word16 startLine = st->hIGFEnc->infoStartLine; + const Word16 endLine = st->hIGFEnc->infoStopLine; + const Word16 maxOrder = 8; + const Word32 *spec_before = st->hIGFEnc->spec_be_igf; + Word16 curr_order = 0; + Word16 A[ITF_MAX_FILTER_ORDER+1]; + Word16 Q_A; + Word16 predictionGain = 0; + Word16 *flatteningTrigger = &(st->hIGFEnc->flatteningTrigger); + + ITF_Detect_fx( spec_before, startLine, endLine, maxOrder, A, &Q_A, &predictionGain, &curr_order, shl(st->hIGFEnc->spec_be_igf_e, 1) ); + *flatteningTrigger = 0; + test(); + IF (LT_32(tns_predictionGain, 9646899l/*1.15 Q23*/)&& + LT_16(predictionGain, 147/*1.15 Q7*/)) + { + *flatteningTrigger = 1; + } } - } - bsStart = st->next_ind_fx; +//IVAS_CODE_BITSTREAM + bsStart = hBstr->next_ind_fx; + move16(); hInstance->infoTotalBitsPerFrameWritten = 0; move16(); IF (isTCX20) { - IGFEncWriteBitstream(hInstance, - NULL, - &hInstance->infoTotalBitsPerFrameWritten, - igfGridIdx, - isIndepFlag); + IGFEncWriteBitstream(hInstance, NULL, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag); } ELSE { - IGFEncWriteBitstream(hInstance, - st, - &hInstance->infoTotalBitsPerFrameWritten, - igfGridIdx, - isIndepFlag); + IGFEncWriteBitstream(hInstance, st->hBstr, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag); } - bsBits = sub(st->next_ind_fx, bsStart); +#ifndef IVAS_CODE_BITSTREAM + bsBits = sub(hBstr->next_ind_fx, bsStart); IF (!isTCX20) { - IGFEncConcatenateBitstream(hInstance, bsBits, &st->next_ind_fx, &st->nb_bits_tot_fx, st->ind_list_fx); + IGFEncConcatenateBitstream(hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx); } +#else +PMT("New bit stream implementation to be checked") + bsBits = sub(hBstr->next_ind_fx, bsStart); + IF(!isTCX20) + { + IGFEncConcatenateBitstream(hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx); + } + +#endif } diff --git a/lib_enc/tfa_enc.c b/lib_enc/tfa_enc.c index 2c453af..ab0d25c 100644 --- a/lib_enc/tfa_enc.c +++ b/lib_enc/tfa_enc.c @@ -2,15 +2,22 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include "stl.h" +#include +#include "options.h" #include "basop_util.h" #include "cnst_fx.h" #include "prot_fx.h" +/*-------------------------------------------------------------------* + * tfaCalcEnv() + * + * + *-------------------------------------------------------------------*/ -void tfaCalcEnv_fx(const Word16* shb_speech, Word32* enr) +void tfaCalcEnv_fx( + const Word16* shb_speech, + Word32* enr +) { Word16 i, j, k; @@ -25,14 +32,16 @@ void tfaCalcEnv_fx(const Word16* shb_speech, Word32* enr) k = add(k, 1); } } + return; } -Word16 tfaEnc_TBE_fx(Word32* enr, - Word16 last_core, - Word16* voicing, /* Q15 */ - Word16* pitch_buf, /* Q6 */ - Word16 Q_enr - ) +Word16 tfaEnc_TBE_fx( + const Word32* enr, + const Word16 last_core, + const Word16* voicing, /* Q15 */ + const Word16* pitch_buf, /* Q6 */ + const Word16 Q_enr +) { Word16 i; Word32 m_g, m_a; /* m_g: geometrical mean, m_a: arithmetical mean */ @@ -86,13 +95,9 @@ Word16 tfaEnc_TBE_fx(Word32* enr, pitch_buf_sum = shr(add(shr(pitch_buf[0], 1), shr(pitch_buf[1], 1)), 1); pitch_buf_sum = add(pitch_buf_sum, shr(add(shr(pitch_buf[2], 1), shr(pitch_buf[3], 1)), 1)); - test(); - test(); - test(); - test(); - test(); - IF ((GT_32(m_g, L_tmp)&>_16(pitch_buf_sum,7040/*110 Q6*/)&>_16(voicing_sum,22938/*0.70 Q15*/))|| - (EQ_16(last_core, TCX_20_CORE) && GT_32(m_g, L_tmp1) && LT_16(voicing_sum, 22938/*0.70 Q15*/) )) + test();test();test();test();test(); + IF ((GT_32(m_g, L_tmp) && GT_16(pitch_buf_sum,7040/*110 Q6*/) && GT_16(voicing_sum,22938/*0.70 Q15*/))|| + (EQ_16(last_core, TCX_20_CORE) && GT_32(m_g, L_tmp1) && LT_16(voicing_sum, 22938/*0.70 Q15*/) )) { tfa_flag = 1; move16(); diff --git a/lib_enc/tns_base_enc.c b/lib_enc/tns_base_enc.c index 58fd8a6..3e60f7c 100644 --- a/lib_enc/tns_base_enc.c +++ b/lib_enc/tns_base_enc.c @@ -322,16 +322,16 @@ Word16 WriteTnsData(STnsConfig const * pTnsConfig, Word16 const * stream, Word16 IF ( LT_16(pTnsConfig->iFilterBorders[0],512)) { - WriteToBitstream(tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, st, pnBits); + WriteToBitstream(tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, st->hBstr, pnBits); } ELSE { - WriteToBitstream(tnsEnabledSWBTCX20BitMap, 1, &stream, pnSize, st, pnBits); + WriteToBitstream(tnsEnabledSWBTCX20BitMap, 1, &stream, pnSize, st->hBstr, pnBits); } } ELSE { - WriteToBitstream(tnsEnabledWBTCX20BitMap, 1, &stream, pnSize, st, pnBits); + WriteToBitstream(tnsEnabledWBTCX20BitMap, 1, &stream, pnSize, st->hBstr, pnBits); } diff --git a/lib_enc/transient_detection.c b/lib_enc/transient_detection.c index 3c469bb..c0f4448 100644 --- a/lib_enc/transient_detection.c +++ b/lib_enc/transient_detection.c @@ -296,12 +296,24 @@ void RunTransientDetection(Word16 const * input, Word16 nSamplesAvailable, Trans /* Update the delay buffer. */ UpdateDelayBuffer(filteredInput, nSamplesAvailable, &pTransientDetection->delayBuffer); +#ifdef IVAS_CODE + /* compute ramp up flag */ + pSubblockEnergies->ramp_up_flag = ((pSubblockEnergies->ramp_up_flag << 1) & 0x0003); + e0 = dotp(filteredInput + length / 2, filteredInput + length / 2, pSubblockEnergies->pDelayBuffer->nSubblockSize / 2) + 0.5f * MIN_BLOCK_ENERGY; + e1 = pSubblockEnergies->subblockNrg[pSubblockEnergies->nDelay + 4] - e0; + if (e1 > e0) + { + pSubblockEnergies->ramp_up_flag |= 0x0001; + } +#endif } void SetTCXModeInfo(Encoder_State_fx *st, TransientDetection const * pTransientDetection, Word16 * tcxModeOverlap) { + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + assert(pTransientDetection != NULL); IF( EQ_16(st->codec_mode,MODE2)) @@ -321,12 +333,12 @@ void SetTCXModeInfo(Encoder_State_fx *st, && ((NE_16(st->last_core_fx, ACELP_CORE) ) && (NE_16(st->last_core_fx, AMR_WB_CORE) )) ) { move16(); - st->tcxMode = TCX_10; + hTcxEnc->tcxMode = TCX_10; } ELSE { move16(); - st->tcxMode = TCX_20; + hTcxEnc->tcxMode = TCX_20; } } ELSE @@ -335,16 +347,16 @@ void SetTCXModeInfo(Encoder_State_fx *st, IF (st->tcx10Enabled) { move16(); - st->tcxMode = TCX_10; + hTcxEnc->tcxMode = TCX_10; } ELSE IF (st->tcx20Enabled) { move16(); - st->tcxMode = TCX_20; + hTcxEnc->tcxMode = TCX_20; } ELSE { move16(); - st->tcxMode = NO_TCX; + hTcxEnc->tcxMode = NO_TCX; } } test(); @@ -352,22 +364,22 @@ void SetTCXModeInfo(Encoder_State_fx *st, IF (st->last_core_fx == ACELP_CORE || st->last_core_fx == AMR_WB_CORE) { move16(); - st->tcx_cfg.tcx_last_overlap_mode = TRANSITION_OVERLAP; + st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; } - ELSE IF ( (EQ_16(st->tcxMode, TCX_10))&&(EQ_16(st->tcx_cfg.tcx_curr_overlap_mode,ALDO_WINDOW))) + ELSE IF ( (EQ_16(hTcxEnc->tcxMode, TCX_10))&&(EQ_16(st->hTcxCfg->tcx_curr_overlap_mode,ALDO_WINDOW))) { move16(); - st->tcx_cfg.tcx_last_overlap_mode = FULL_OVERLAP; + st->hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP; } ELSE { move16(); - st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; + st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; } /* determine window overlaps (0 full, 2 none, or 3 half) */ - IF ( EQ_16(st->tcxMode, TCX_10)) + IF ( EQ_16(hTcxEnc->tcxMode, TCX_10)) { IF( pTransientDetection->transientDetector.attackIndex < 0) { @@ -385,7 +397,7 @@ void SetTCXModeInfo(Encoder_State_fx *st, } } } - ELSE IF ( EQ_16(st->tcxMode, TCX_20)) + ELSE IF ( EQ_16(hTcxEnc->tcxMode, TCX_20)) { IF (EQ_16(pTransientDetection->transientDetector.attackIndex, 7)) { @@ -409,7 +421,7 @@ void SetTCXModeInfo(Encoder_State_fx *st, *tcxModeOverlap = TRANSITION_OVERLAP; } test(); - if ((EQ_16(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP))&&(EQ_16(*tcxModeOverlap,ALDO_WINDOW))) + if ((EQ_16(st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP))&&(EQ_16(*tcxModeOverlap,ALDO_WINDOW))) { move16(); *tcxModeOverlap = FULL_OVERLAP; @@ -496,6 +508,7 @@ static void InitTransientDetector(SubblockEnergies * pSubblockEnergies, Word16 n pTransientDetector->nSubblocksToCheck = nSubblocksToCheck; pTransientDetector->CheckSubblocksForAttack = pCheckSubblocksForAttack; pTransientDetector->attackRatioThreshold = attackRatioThreshold; + pTransientDetector->prev_bIsAttackPresent = FALSE; pTransientDetector->bIsAttackPresent = FALSE; pTransientDetector->attackIndex = -1; } @@ -725,5 +738,167 @@ static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvail pSubblockEnergies->firState1 = firState1; pSubblockEnergies->firState2 = firState2; } +#ifdef IVAS_CODE +/*-------------------------------------------------------------------* + * set_transient_stereo() + * + * + *-------------------------------------------------------------------*/ + +void set_transient_stereo( + CPE_ENC_HANDLE hCPE, /* i : CPE structure */ + float currFlatness[] /* i/o: current flatness */ +) +{ + int16_t n, attackIsPresent; + float currFlatnessMax; + Encoder_State** sts; + + sts = hCPE->hCoreCoder; + + /* for DFT/TD based stereo ,map avg. flatness to individual stereo channels (M/S or X/Y) */ + maximum(currFlatness, CPE_CHANNELS, &currFlatnessMax); + attackIsPresent = 0; + + for (n = 0; n < CPE_CHANNELS; n++) + { + attackIsPresent = max(attackIsPresent, sts[n]->hTranDet->transientDetector.bIsAttackPresent); + } + + set_f(currFlatness, currFlatnessMax, CPE_CHANNELS); + + for (n = 0; n < CPE_CHANNELS; n++) + { + sts[n]->hTranDet->transientDetector.bIsAttackPresent = attackIsPresent; + } + + if (hCPE->hStereoDft != NULL) + { + if (hCPE->hStereoDft->attackPresent) + { + hCPE->hStereoDft->wasTransient = 1; + } + else if (hCPE->hStereoDft->wasTransient) + { + hCPE->hStereoDft->wasTransient = 0; + } + + hCPE->hStereoDft->attackPresent = attackIsPresent; + + hCPE->hStereoDft->hItd->currFlatness = 0; + for (n = 0; n < CPE_CHANNELS; n++) + { + hCPE->hStereoDft->hItd->currFlatness = max(hCPE->hStereoDft->hItd->currFlatness, currFlatness[n]); + } + } + + if (hCPE->hStereoMdct != NULL) + { + hCPE->hStereoMdct->hItd->currFlatness = 0; + for (n = 0; n < CPE_CHANNELS; n++) + { + hCPE->hStereoMdct->hItd->currFlatness = max(hCPE->hStereoMdct->hItd->currFlatness, currFlatness[n]); + } + } + + return; +} + +/*-------------------------------------------------------------------* + * transient_analysis() + * + * + *-------------------------------------------------------------------*/ + + /*! r: preliminary flag to force ACELP */ +int16_t transient_analysis( + TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ + const float cor_map_LT[], /* i : LT correlation map */ + const float multi_harm_limit /* i : multi harminic threshold */ +) +{ + const float* pSubblockNrg; + float accSubblockNrgRev[NSUBBLOCKS]; /* store acc Nrg in reversed signal */ + float* pTmp; /* point to acc Nrg */ + int16_t offset; + int16_t i; + float thr_fwd; + float thr_rev; + const int16_t nRelativeDelay = hTranDet->subblockEnergies.nDelay - hTranDet->transientDetector.nDelay; + int16_t prel_force_td; + float cor_map_LT_sum; + + pTmp = &accSubblockNrgRev[NSUBBLOCKS - 1]; + offset = nRelativeDelay - 4; + prel_force_td = FALSE; + + /* summation of the LT correlation map */ + cor_map_LT_sum = sum_f(cor_map_LT, L_FFT / 2); /* Note maybe BE optimized by computing inside noise_est */ + + thr_fwd = THR_NORM_HIGH; + if (cor_map_LT_sum > multi_harm_limit * 0.8f) + { + thr_fwd = THR_HIGH; + } + thr_rev = THR_LOW; + if (cor_map_LT_sum > multi_harm_limit * 0.6f) + { + thr_rev = THR_NORM_LOW; + } + + /* forward attack analysis */ + for (i = -2; i < 7; i++) + { + if (hTranDet->subblockEnergies.subblockNrg[nRelativeDelay + i] > hTranDet->subblockEnergies.accSubblockNrg[nRelativeDelay + i] * thr_fwd) + { + prel_force_td |= 0x0001; + } + } + if (prel_force_td == 0 && hTranDet->transientDetector.prev_bIsAttackPresent == 1) + { + /* release analysis */ + pSubblockNrg = hTranDet->transientDetector.pSubblockEnergies->subblockNrg; + set_zero(accSubblockNrgRev, NSUBBLOCKS); + + for (i = NSUBBLOCKS - 1; i > -1; i--) + { + if (i == NSUBBLOCKS - 1) + { + accSubblockNrgRev[i] = pSubblockNrg[i + offset]; + } + else + { + accSubblockNrgRev[i] = *pTmp; + *pTmp *= hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg; + if (pSubblockNrg[i + offset] > *pTmp) + { + *pTmp = pSubblockNrg[i + offset]; + } + } + } + + /* -3 check */ + if (pSubblockNrg[1 + offset] > accSubblockNrgRev[1] * thr_rev) + { + prel_force_td |= 0x0002; + } + + /* -4 check */ + if (prel_force_td == 0 && pSubblockNrg[offset] > accSubblockNrgRev[0] * thr_rev) + { + if (pSubblockNrg[offset] > accSubblockNrgRev[0] * (thr_rev + THR_LOW_STEP)) + { + prel_force_td |= 0x0004; + } + else if ((hTranDet->subblockEnergies.ramp_up_flag & 0x0002) != 0) + { + prel_force_td |= 0x0008; + } + } + } + + return prel_force_td != 0; +} +#endif diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 85cc79c..8121843 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -2,20 +2,19 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-----------------------------------------------------------------* - * Local functions + * Local function prototypes *-----------------------------------------------------------------*/ static void gain_trans_enc_fx(Word32 gain_trans32, Word16 exc[], Word16 *quant_index, Word16 *quant_sign, Word16 Q_new); -static void tc_enc_fx(Encoder_State_fx *st_fx, const Word32 core_brate, const Word16 L_frame, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, +static void tc_enc_fx(Encoder_State_fx *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new); @@ -27,14 +26,9 @@ static void tc_enc_fx(Encoder_State_fx *st_fx, const Word32 core_brate, const W /*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* (Word32) core_brate : core bitrate Q0 */ -/* (Word16) L_frame : length of the frame Q0 */ -/* (Word16) coder_type : coding type Q0 */ /* (Word16) bwidth : input signal bandwidth Q0 */ /* (Word16) i_subfr : subrame index Q0 */ /* (Word16*) Jopt_flag : joint optimization flag Q0 */ -/* (Word16[]) voicing_fx : normalized correlations(from OL pitch)Q15 */ -/* (Word16[]) T_op_fx : open loop pitch estimates in current frameQ0*/ -/* (Word16*) res_fx : pointer to the LP residual signal frameQ_new*/ /* (Word16*) h1_fx : weighted filter input response Q14 */ /* (Word16*) xn_fx : target signal Q_new*/ /* (Word16) Q_new : input scaling */ @@ -63,42 +57,39 @@ static void tc_enc_fx(Encoder_State_fx *st_fx, const Word32 core_brate, const W /*--------------------------------------------------------------------------*/ void transition_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *position, /* i/o: maximum of residual signal index */ - const Word16 voicing_fx[], /* i : normalized correlations (from OL pitch) Q15*/ - const Word16 T_op_fx[], /* i : open loop pitch estimates in current frame Q0*/ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ - Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ - Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ - Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ - Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *res_fx, /* i : pointer to the LP residual signal frame Q_new*/ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ - Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ - Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ - Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ - Word16 *g_corr_fx, /* o : ACELP correlation values */ - Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ - Word16 **pt_pitch_fx, /* o : floating pitch values */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + Encoder_State_fx *st_fx,/* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *Jopt_flag, /* i : joint optimization flag */ + Word16 *position, /* i/o: maximum of residual signal index */ + Word16 *T0, /* i/o: close loop integer pitch Q0*/ + Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ + Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ + Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ + Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ + Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ + Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ + Word16 *g_corr_fx, /* o : ACELP correlation values */ + Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ + Word16 **pt_pitch_fx, /* o : floating pitch values */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + Word16* unbits_ACELP, /* i/o: unused bits */ Word16 Q_new, /* i : Current scaling */ Word16 shift /* i : downscaling needs for 12 bits convolutions */ ) { Word16 pit_flag, pit_start, pit_limit, index, nBits; - Word16 tmp, tmp1; - Word32 i, offset,temp; + Word16 tmp, tmp1, i; + Word32 offset; Word16 shift_wsp; Word16 limit_flag, mult_Top, lp_select, lp_flag; + Word16 T_op[2]; /* values for two half-frames */ + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; /* set limit_flag to 0 for restrained limits, and 1 for extended limits */ limit_flag = 0; @@ -106,8 +97,26 @@ void transition_enc_fx( pit_start = PIT_MIN; move16(); + + /*----------------------------------------------------------------* + * convert pitch values to 16kHz domain + *----------------------------------------------------------------*/ + + IF(EQ_16(st_fx->L_frame_fx, L_FRAME) /*|| (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)*/) + { + Copy(st_fx->pitch_fx, T_op, 2); + } + ELSE /* L_frame == L_FRAME16k */ + { + /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); + T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ + T_op[0] = add(st_fx->pitch_fx[0], mult_r(st_fx->pitch_fx[0], 8192/*0.25f Q15*/)); + T_op[1] = add(st_fx->pitch_fx[1], mult_r(st_fx->pitch_fx[1], 8192/*0.25f Q15*/)); + } shift_wsp = add(Q_new,shift); + lp_flag = st_fx->acelp_cfg.ltf_mode; + move16(); /*-----------------------------------------------------------------* * TC: subrame determination for glottal shape search * ------------------------------------------------------- @@ -120,82 +129,24 @@ void transition_enc_fx( IF( i_subfr == 0 ) { - IF( EQ_16(*tc_subfr,3*L_SUBFR)) - { - IF( EQ_16(L_frame,L_FRAME)) - { - *position = emaximum_fx( Q_new, res_fx + 3*L_SUBFR,s_min(add(T_op_fx[0],2),L_SUBFR), &temp ) + 3*L_SUBFR; - move16(); - *tc_subfr = 3*L_SUBFR; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - *position = emaximum_fx( Q_new, res_fx + 4*L_SUBFR,s_min(add(T_op_fx[0],2),L_SUBFR), &temp ) + 4*L_SUBFR; - move16(); - *tc_subfr = 4*L_SUBFR; - move16(); - } - } - ELSE - { - *position = emaximum_fx( Q_new, res_fx, add(T_op_fx[0],2), &temp ); - - /* correction in case of possibly wrong T_op (double-pitch values) */ - test(); - test(); - test(); - IF( (EQ_16(L_frame,L_FRAME)&>_16(T_op_fx[0],2*PIT_MIN))|| - (EQ_16(L_frame,L_FRAME16k) && GT_16(T_op_fx[0],2*PIT16k_MIN) ) - ) - { - Word16 position_tmp, len, exp_aver=0, exp=0, exp2=0; - Word32 aver, temp2, L_sum, L_temp1, L_temp2; - - len = add(shr(T_op_fx[0],1), 2); - position_tmp = emaximum_fx( Q_new, res_fx, len, &temp2 ); - - L_sum = L_mac(1L, res_fx[0], res_fx[0]); - FOR (i = 1; i < len; i++) - { - L_sum = L_mac0(L_sum, res_fx[i], res_fx[i]); - } - aver = L_sum; /*Q = 2*Q_new */ - aver = root_a_over_b_fx(aver, 2*Q_new, L_shl(len,15), 15, &exp_aver); /*Q = 31-exp_aver*/ - - temp = root_a_fx(temp, 0, &exp); /* Q=31-exp */ - temp2 = root_a_fx(temp2, 0, &exp2); /* Q=31-exp2 */ - - L_temp2 = Mult_32_16(temp, 26214); /* Q=31-exp */ - L_temp1 = Mult_32_16(temp, 8192); /* Q=31-exp */ - - test(); - IF( GT_32(temp2, L_shl(L_temp2,(31-exp2)-(31-exp)))&& - LT_32(aver, L_shl(L_temp1,(31-exp_aver)-(31-exp))) ) - { - *position = position_tmp; - } - } - *tc_subfr = s_and(*position, 0x7FC0); - } mult_Top = 1; IF( limit_flag == 0 ) { test(); - IF( EQ_16(L_frame,L_FRAME)&<_16(T_op_fx[1],PIT_MIN)) + IF( EQ_16(st_fx->L_frame_fx,L_FRAME) && LT_16(T_op[1],PIT_MIN) ) { mult_Top = 2; move16(); } test(); - if( EQ_16(L_frame,L_FRAME16k)&<_16(T_op_fx[1],PIT16k_MIN)) + if( EQ_16(st_fx->L_frame_fx,L_FRAME16k) && LT_16(T_op[1],PIT16k_MIN)) { mult_Top = 2; move16(); } } - limit_T0_fx( L_frame, 8, 0, limit_flag, mult_Top*T_op_fx[1], 0, T0_min, T0_max ); + limit_T0_fx( st_fx->L_frame_fx, 8, 0, limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); } /*-----------------------------------------------------------------* @@ -217,7 +168,7 @@ void transition_enc_fx( set16_fx(&exc_fx[i_subfr], 0, L_SUBFR); /* set excitation for current subrame to 0 */ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) { set16_fx(&bwe_exc_fx[i_subfr*HIBND_ACB_L_FAC], 0, (Word16)(L_SUBFR*HIBND_ACB_L_FAC)); /* set past excitation buffer to 0 */ } @@ -243,7 +194,7 @@ void transition_enc_fx( *-----------------------------------------------------------------*/ ELSE IF ( EQ_16(*tc_subfr,i_subfr)) { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) { set16_fx( bwe_exc_fx-PIT_MAX*HIBND_ACB_L_FAC, 0, PIT_MAX*HIBND_ACB_L_FAC); /* set past excitation buffer to 0 */ } @@ -252,10 +203,18 @@ void transition_enc_fx( set16_fx( bwe_exc_fx-PIT16k_MAX*2, 0, PIT16k_MAX*2); /* set past excitation buffer to 0 */ } - tc_enc_fx( st_fx, core_brate, L_frame, i_subfr, tc_subfr, position, h1_fx, xn_fx, exc_fx, + tc_enc_fx( st_fx, i_subfr, tc_subfr, position, h1_fx, xn_fx, exc_fx, y1_fx, T0_min, T0_max, T0, T0_frac, gain_pit_fx, g_corr_fx, bwe_exc_fx,Q_new); - *clip_gain = gp_clip_fx( core_brate, voicing_fx, i_subfr, coder_type, xn_fx, gp_cl_fx, sub(shift_wsp,1) ); + IF (EQ_16(*tc_subfr, TC_0_0) ) + { + /* this is called only to compute unused bits */ + config_acelp1(ENC, st_fx->total_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_fx, st_fx->extl_brate_fx, + L_FRAME, -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, + st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ + ); + } + *clip_gain = gp_clip_fx(st_fx->element_mode, st_fx->core_brate_fx, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub(shift_wsp,1) ); updt_tar_fx( xn_fx, xn2_fx, y1_fx, *gain_pit_fx, L_SUBFR ); **pt_pitch_fx = shl(add(shl(*T0,2),*T0_frac),4); @@ -273,7 +232,7 @@ void transition_enc_fx( *--------------------------------------------------------------*/ ELSE IF ( LT_16(*tc_subfr,i_subfr)) { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) { *Jopt_flag = 1; move16(); @@ -324,7 +283,7 @@ void transition_enc_fx( *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR ); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); + offset = tbe_celp_exc_offset(*T0, *T0_frac, st_fx->L_frame_fx); FOR (i=0; itotal_brate_fx, st_fx->core_brate_fx, st_fx->core_fx, st_fx->extl_fx, st_fx->extl_brate_fx, + st_fx->L_frame_fx, -1, &(st_fx->acelp_cfg), hBstr->nb_bits_tot_fx, TRANSITION, *tc_subfr, 2, NULL, + unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/); + } /*-----------------------------------------------------------------* * get number of bits for pitch encoding *-----------------------------------------------------------------*/ - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(*tc_subfr))]; + nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr, 6)]; move16(); /*-----------------------------------------------------------------* @@ -419,13 +384,13 @@ void transition_enc_fx( /* 7bit ENCODER */ /* index = (*T0-pit_start)*2 + *T0_frac/2;*/ index = add(shl(sub(*T0,pit_start),1), shr(*T0_frac,1)); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); + push_indice_fx( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ pred_lt4(&exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); + offset = tbe_celp_exc_offset(*T0, *T0_frac, st_fx->L_frame_fx); FOR (i=0; iL_frame_fx); FOR (i=0; iL_frame_fx); FOR (i=0; iL_frame_fx); FOR (i=0; iL_frame_fx); FOR (i=0; ielement_mode, st_fx->core_brate_fx, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, (Q_new+shift-1) ); - lp_select = lp_filt_exc_enc_fx( MODE1, core_brate, 0, coder_type, i_subfr, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); + lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, + xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame_fx, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); IF( EQ_16(lp_flag,NORMAL_OPERATION)) { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } } @@ -733,18 +697,18 @@ void transition_enc_fx( { mult_Top = 1; move16(); - if( LT_16(T_op_fx[0],PIT16k_MIN)) + if( LT_16(T_op[0],PIT16k_MIN)) { mult_Top = 2; move16(); } - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, mult_Top*T_op_fx[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ + limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ } ELSE { - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, T_op_fx[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ + limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, T_op[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ } } @@ -752,7 +716,7 @@ void transition_enc_fx( * get number of bits for pitch encoding *-----------------------------------------------------------------*/ - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(*tc_subfr))]; + nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr, 6)]; move16(); /*-----------------------------------------------------------------* @@ -761,8 +725,8 @@ void transition_enc_fx( IF( EQ_16(nBits,10)) { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_frame, L_SUBFR ); - pit16k_Q_enc_fx( st_fx, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame_fx, L_SUBFR ); + pit16k_Q_enc_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16(nBits,8)) /* tc_subfr==0 && i_subfr==L_SUBFR */ { @@ -771,7 +735,7 @@ void transition_enc_fx( * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) *-----------------------------------------------------------------------------*/ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2*L_SUBFR, L_frame, L_SUBFR ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2*L_SUBFR, st_fx->L_frame_fx, L_SUBFR ); IF( GT_16(*T0_max,2*L_SUBFR)) { @@ -791,15 +755,15 @@ void transition_enc_fx( /*index = (*T0)*2 + ((*T0_frac)>>1) - (PIT16k_FR2_TC0_2SUBFR*2) + ((PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4);*/ index = add(sub(add(shl(*T0,1), shr(*T0_frac,1)), (PIT16k_FR2_TC0_2SUBFR*2)), (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4); } - push_indice_fx( st_fx, IND_PITCH, index, nBits ); + push_indice_fx( hBstr, IND_PITCH, index, nBits ); } ELSE IF( EQ_16(nBits,6)) { /* delta search */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_frame, L_SUBFR ); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame_fx, L_SUBFR ); index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); + push_indice_fx( hBstr, IND_PITCH, index, nBits ); } IF( EQ_16(nBits,6)) { @@ -826,7 +790,7 @@ void transition_enc_fx( move16(); set16_fx( &exc_fx[i_subfr], 0, L_SUBFR+1 ); /* set excitation for current subrame to 0 */ - push_indice_fx( st_fx, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ + push_indice_fx( hBstr, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ @@ -852,14 +816,14 @@ void transition_enc_fx( bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - offset + 4]; } - *clip_gain = gp_clip_fx( core_brate, voicing_fx, i_subfr, coder_type, xn_fx, gp_cl_fx,Q_new ); + *clip_gain = gp_clip_fx(st_fx->element_mode, st_fx->core_brate_fx, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx,Q_new ); - lp_select = lp_filt_exc_enc_fx( MODE1, core_brate, 0, coder_type, i_subfr, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); + lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, + xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame_fx, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); IF( EQ_16(lp_flag,NORMAL_OPERATION)) { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); + push_indice_fx( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } *Jopt_flag = 1; @@ -913,29 +877,28 @@ void transition_enc_fx( *-------------------------------------------------------------------------------------------*/ static void tc_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subrame index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *position, /* i/o: index of the residual signal maximum */ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ - Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ - Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ - Word16 *T0_min, /* o : lower pitch limit Q0*/ - Word16 *T0_max, /* o : higher pitch limit Q0*/ - Word16 *T0, /* o : close loop integer pitch Q0*/ - Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ - Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ - Word16 g_corr_fx[], /* o : correlations and -2 */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ + Encoder_State_fx *st_fx,/* i/o: encoder state structure */ + const Word16 i_subfr, /* i : subrame index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *position, /* i/o: index of the residual signal maximum */ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ + Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ + Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ + Word16 *T0_min, /* o : lower pitch limit Q0*/ + Word16 *T0_max, /* o : higher pitch limit Q0*/ + Word16 *T0, /* o : close loop integer pitch Q0*/ + Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ + Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ + Word16 g_corr_fx[], /* o : correlations and -2 */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ Word16 Q_new /* i : input scaling */ ) { Word16 i,imp_shape, imp_pos, index, nBits, h1_tmp_fx[L_SUBFR]; Word16 pitch_index,pitch_sign_fx; Word32 gain_trans32; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; imp_pos = sub(*position, i_subfr); FOR (i = 0; i < L_SUBFR; i++) @@ -947,16 +910,7 @@ static void tc_enc_fx( * get number of bits for pitch encoding *-----------------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) - { - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(*tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_16KHZ_fx(*tc_subfr))]; - move16(); - } + nBits = st_fx->acelp_cfg.pitch_bits[shr(i_subfr, 6)]; /*--------------------------------------------------------------* * Closed loop pitch search @@ -965,7 +919,7 @@ static void tc_enc_fx( *T0_frac = 0; move16(); - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) { test(); IF( (LE_16(*T0_min,L_SUBFR))||(EQ_16(*tc_subfr,3*L_SUBFR))) @@ -995,7 +949,7 @@ static void tc_enc_fx( move16(); } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* st_fx->L_frame_fx == L_FRAME16k */ { IF( EQ_16(nBits,10)) { @@ -1020,7 +974,7 @@ static void tc_enc_fx( test(); test(); test(); - if( i_subfr == 0 && EQ_16(L_frame,L_FRAME)&&(LT_16(*T0,L_SUBFR)||EQ_16(*tc_subfr,3*L_SUBFR))) + if( i_subfr == 0 && EQ_16(st_fx->L_frame_fx,L_FRAME)&&(LT_16(*T0,L_SUBFR)||EQ_16(*tc_subfr,3*L_SUBFR))) { *tc_subfr = TC_0_0; move16(); @@ -1046,16 +1000,17 @@ static void tc_enc_fx( *--------------------------------------------------------------*/ pred_lt4_tc_fx( exc_fx, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); - - IF( EQ_16(L_frame,L_FRAME)) + IF (st_fx->hBWE_TD != NULL) { - interp_code_5over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); - } - ELSE - { - interp_code_4over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR); + IF(EQ_16(st_fx->L_frame_fx, L_FRAME)) + { + interp_code_5over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); + } + ELSE + { + interp_code_4over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR); + } } - /*--------------------------------------------------------------* * compute glottal-shape codebook excitation *--------------------------------------------------------------*/ @@ -1069,7 +1024,7 @@ static void tc_enc_fx( /*--------------------------------------------------------------* * Encode parameters and write indices *--------------------------------------------------------------*/ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16(st_fx->L_frame_fx,L_FRAME)) { test(); test(); @@ -1080,7 +1035,7 @@ static void tc_enc_fx( /* write pitch index */ IF( (GE_16(*T0,L_SUBFR))&&(NE_16(*tc_subfr,3*L_SUBFR))) { - push_indice_fx( st_fx, IND_PITCH, 0, nBits ); + push_indice_fx( hBstr, IND_PITCH, 0, nBits ); } ELSE IF( EQ_16(*tc_subfr,3*L_SUBFR)) { @@ -1092,7 +1047,7 @@ static void tc_enc_fx( { index = abs_pit_enc_fx( 2, 0, *T0, *T0_frac ); } - push_indice_fx( st_fx, IND_PITCH, index, nBits ); + push_indice_fx( hBstr, IND_PITCH, index, nBits ); limit_T0_fx( L_FRAME, 8, 0, 0, *T0, 0, T0_min, T0_max ); } @@ -1101,32 +1056,32 @@ static void tc_enc_fx( IF( EQ_16(nBits,6)) { index = delta_pit_enc_fx( 2, *T0, *T0_frac, PIT_MIN-1 ); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); + push_indice_fx( hBstr, IND_PITCH, index, nBits ); } ELSE { index = delta_pit_enc_fx( 0, *T0, *T0_frac, PIT_MIN-1 ); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); + push_indice_fx( hBstr, IND_PITCH, index, nBits ); } } } } - ELSE /* L_frame == L_FRAME16k */ + ELSE /* st_fx->L_frame_fx == L_FRAME16k */ { IF( EQ_16(nBits,10)) { - pit16k_Q_enc_fx( st_fx, nBits, 1, *T0, *T0_frac, T0_min, T0_max ); + pit16k_Q_enc_fx( hBstr, nBits, 1, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16(nBits,6)) { index = add(shl(sub(*T0,PIT16k_MIN),1) , shr(*T0_frac,1)); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); + push_indice_fx( hBstr, IND_PITCH, index, nBits ); } } - push_indice_fx( st_fx, IND_TC_IMP_SHAPE, imp_shape, 3 ); - push_indice_fx( st_fx, IND_TC_IMP_POS, imp_pos, 6 ); - push_indice_fx( st_fx, IND_TC_IMP_SIGN, pitch_sign_fx, 1 ); - push_indice_fx( st_fx, IND_TC_IMP_GAIN, pitch_index, 3 ); + push_indice_fx( hBstr, IND_TC_IMP_SHAPE, imp_shape, 3 ); + push_indice_fx( hBstr, IND_TC_IMP_POS, imp_pos, 6 ); + push_indice_fx( hBstr, IND_TC_IMP_SIGN, pitch_sign_fx, 1 ); + push_indice_fx( hBstr, IND_TC_IMP_GAIN, pitch_index, 3 ); *position = add(imp_pos, i_subfr); move16(); @@ -1198,3 +1153,116 @@ static void gain_trans_enc_fx( } } + +/*-----------------------------------------------------------------* + * tc_classif_enc() + * + * TC subframe determination + *-----------------------------------------------------------------*/ +void tc_classif_enc( + const Word16 Q_new, /* i : scaling factor */ + const Word16 L_frame, /* i : length of the frame */ + Word16* tc_subfr, /* o : TC subframe index */ + Word16* position, /* o : maximum of residual signal index */ + const Word16 attack_flag, /* i : attack flag */ + const Word16 pitch, /* i : open loop pitch estimates for first halfframe */ + const Word16* res /* i : pointer to the LP residual signal frame */ +) +{ + Word32 temp; + Word16 T_op, i; + + T_op = pitch; + move16(); + + IF ( EQ_16(L_frame, L_FRAME16k) ) + { + /*T_op = (int16_t)(pitch * 1.25f + 0.5f);*/ + T_op = add(pitch, mult_r(pitch, 8192)); + } + + *tc_subfr = -1; + move16(); + IF (attack_flag) + { + *tc_subfr = 3 * L_SUBFR; + move16(); + IF (attack_flag > 0) + { + IF (EQ_16(L_frame, L_FRAME)) + { + /* *tc_subfr = NB_SUBFR * (attack_flag - 1) / 32 ; ATT_NSEG == 32*/ + *tc_subfr = mult(i_mult(NB_SUBFR, sub(attack_flag, 1)), 1024) ; /* divide by 32 Q15*/ + move16(); + } + ELSE + { + /* *tc_subfr = NB_SUBFR16k * (attack_flag - 1) / 32 ; */ + *tc_subfr = mult(i_mult(NB_SUBFR16k, sub(attack_flag, 1)), 1024); /* divide by 32 Q15*/ + move16(); + } + /* *tc_subfr *= L_SUBFR; */ + *tc_subfr = i_mult(*tc_subfr, L_SUBFR); + move16(); + } + } + + IF (attack_flag) + { + /*-----------------------------------------------------------------* + * TC: subrame determination for glottal shape search + * ------------------------------------------------------- + * tc_subfr == 0 - TC in 1st subframe + * tc_subfr == TC_0_0 - TC in 1st subframe + information about T0 + * tc_subfr == L_SUBFR - TC in 2nd subframe + * tc_subfr == 2*L_SUBFR - TC in 3rd subframe + * tc_subfr == 3*L_SUBFR - TC in 4th subframe + *-----------------------------------------------------------------*/ + + /** position = emaximum(res + *tc_subfr, min(T_op + 2, L_SUBFR), &temp) + *tc_subfr;*/ + *position = add(emaximum_fx(Q_new, res + *tc_subfr, s_min(add(T_op, 2), L_SUBFR), &temp), *tc_subfr); + move16(); + } + ELSE + { + *position = emaximum_fx(Q_new, res, add(T_op,2), &temp); + + /* correction in case of possibly wrong T_op (double-pitch values) */ + test(); + test(); + test(); + IF((EQ_16(L_frame,L_FRAME) && GT_16(T_op,2 * PIT_MIN)) || (EQ_16(L_frame,L_FRAME16k) && GT_16(T_op,2 * PIT16k_MIN)) ) + { + Word16 position_tmp, len, exp_aver = 0, exp = 0, exp2 = 0; + Word32 aver, temp2, L_sum, L_temp1, L_temp2; + + len = add(shr(T_op,1), 2); + position_tmp = emaximum_fx(Q_new, res, len, &temp2); + + L_sum = L_mac(1L, res[0], res[0]); + FOR(i = 1; i < len; i++) + { + L_sum = L_mac0(L_sum, res[i], res[i]); + } + aver = L_sum; /*Q = 2*Q_new */ + aver = root_a_over_b_fx(aver, 2 * Q_new, L_shl(len,15), 15, &exp_aver); /*Q = 31-exp_aver*/ + + temp = root_a_fx(temp, 0, &exp); /* Q=31-exp */ + temp2 = root_a_fx(temp2, 0, &exp2); /* Q=31-exp2 */ + + L_temp2 = Mult_32_16(temp, 26214); /* Q=31-exp */ + L_temp1 = Mult_32_16(temp, 8192); /* Q=31-exp */ + + test(); + IF(GT_32(temp2, L_shl(L_temp2,(31 - exp2) - (31 - exp))) && + LT_32(aver, L_shl(L_temp1,(31 - exp_aver) - (31 - exp)))) + { + *position = position_tmp; + } + } + *tc_subfr = s_and(*position, 0x7FC0); + move16(); + } + + return; +} diff --git a/lib_enc/update_decision.c b/lib_enc/update_decision.c index 19bd5a6..d19da9d 100644 --- a/lib_enc/update_decision.c +++ b/lib_enc/update_decision.c @@ -3,22 +3,28 @@ ====================================================================================*/ +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" - -void bg_music_decision(T_CldfbVadState *st, - Word16 *music_backgound_f, /*(i) background music flag*/ - Word32 frame_energy, /*(i) current frame energy 1*/ - Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ - ) +/*-------------------------------------------------------------------* + * bg_music_decision() + * + * + * -------------------------------------------------------------------*/ + void bg_music_decision( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *music_backgound_f, /* i : background music flag*/ + Word32 frame_energy, /* i : current frame energy 1*/ + Word16 frame_energy_Q /* i : the Scaling of current frame energy*/ +) { - Word16 *f_tonality_rate = st->f_tonality_rate; - Word16 *ltd_stable_rate = st->ltd_stable_rate; - Word16 *sp_center = st->sp_center; - Word16 *sSFM = st->sfm; + Word16 *f_tonality_rate = hVAD_CLDFB->f_tonality_rate; + Word16 *ltd_stable_rate = hVAD_CLDFB->ltd_stable_rate; + Word16 *sp_center = hVAD_CLDFB->sp_center; + Word16 *sSFM = hVAD_CLDFB->sfm; Word16 cmp_result; Word32 music_background_frame; Word32 tmp1; @@ -30,7 +36,7 @@ void bg_music_decision(T_CldfbVadState *st, music_background_frame = 0; move32(); - tmp1 = L_mult(st->fg_energy_count,18842); + tmp1 = L_mult(hVAD_CLDFB->fg_energy_count,18842); tmp1_Q = norm_l(tmp1); tmp1 = L_shl(tmp1,tmp1_Q); tmp_norm = extract_h(tmp1); @@ -39,7 +45,7 @@ void bg_music_decision(T_CldfbVadState *st, fg_energy_Qtmp = sub(frame_energy_Q, 18); fg_energy_Qtmp = add(fg_energy_Qtmp, tmp1_Q); - cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,st->fg_energy,st->fg_energy_scale); + cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,hVAD_CLDFB->fg_energy,hVAD_CLDFB->fg_energy_scale); test(); IF((GT_16(f_tonality_rate[1],9830/* 0.6 Q14 */)) @@ -65,49 +71,55 @@ void bg_music_decision(T_CldfbVadState *st, test(); IF(music_background_frame &&(cmp_result > 0) - &&(EQ_32(st->fg_energy_est_start,1))) + &&(EQ_32(hVAD_CLDFB->fg_energy_est_start,1))) { - st->music_background_rate = add(mult(st->music_background_rate,31949), 819); + hVAD_CLDFB->music_background_rate = add(mult(hVAD_CLDFB->music_background_rate,31949), 819); move16(); } ELSE IF(music_background_frame) { - st->music_background_rate = add(mult(st->music_background_rate,32702), 66); + hVAD_CLDFB->music_background_rate = add(mult(hVAD_CLDFB->music_background_rate,32702), 66); move16(); } ELSE { - st->music_background_rate = mult(st->music_background_rate,32670); + hVAD_CLDFB->music_background_rate = mult(hVAD_CLDFB->music_background_rate,32670); move16(); } *music_backgound_f = 0; move16(); - if(GT_16(st->music_background_rate, 16384)) + if(GT_16(hVAD_CLDFB->music_background_rate, 16384)) { *music_backgound_f = 1; move16(); } } - -Word16 update_decision(T_CldfbVadState *st, - Word32 frame_energy, /*(i) current frame energy*/ - Word32 HB_Power,/*(i) current frame high frequency energy*/ - Word16 frameloop,/*(i) amount of frames*/ - Word16 bw, /*(i) band width index*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 HB_Power_Q, /*(i) the Scaling of current frame high frequency energy*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word16 vad_flag, - Word16 music_backgound_f/*(i) background music flag*/ - ) + /*-------------------------------------------------------------------* + * update_decision() + * + * + *-------------------------------------------------------------------*/ + +Word16 update_decision( + VAD_CLDFB_HANDLE hVAD_CLDFB ,/* i/o: CLDFB VAD state */ + const Word32 frame_energy, /* i : current frame energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 bw, /* i : band width index*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 tsnr, /* i : time domain SNR */ + const Word16 vad_flag, /* i : VAD flag */ + const Word16 music_backgound_f /* i : background music flag*/ +) { - Word16 *sp_center = st->sp_center; - Word16 *ltd_stable_rate = st->ltd_stable_rate; - Word16 *sSFM = st->sfm; - Word16 *f_tonality_rate = st->f_tonality_rate; + Word16 *sp_center = hVAD_CLDFB->sp_center; + Word16 *ltd_stable_rate = hVAD_CLDFB->ltd_stable_rate; + Word16 *sSFM = hVAD_CLDFB->sfm; + Word16 *f_tonality_rate = hVAD_CLDFB->f_tonality_rate; Word16 update_flag; Word16 tonality_flag; @@ -136,7 +148,7 @@ Word16 update_decision(T_CldfbVadState *st, tonality_flag = 0; move16(); - lt_bg_highf_eng_trbl = MUL_F(st->lt_bg_highf_eng,24576); + lt_bg_highf_eng_trbl = MUL_F(hVAD_CLDFB->lt_bg_highf_eng,24576); IF (GT_16(14,HB_Power_Q)) { lt_bg_highf_eng_trbl = L_shr(lt_bg_highf_eng_trbl,sub(14,HB_Power_Q)); @@ -154,7 +166,7 @@ Word16 update_decision(T_CldfbVadState *st, move16(); } - sp_center3_diff = sub(sp_center[3], st->lt_noise_sp_center3); + sp_center3_diff = sub(sp_center[3], hVAD_CLDFB->lt_noise_sp_center3); IF(sub(frameloop, 50) > 0) { @@ -165,7 +177,7 @@ Word16 update_decision(T_CldfbVadState *st, move16(); } - tmpout= VAD_L_CMP(frame_energy, sub(frame_energy_Q,2), st->frame_energy_smooth,st->frame_energy_smooth_scale); + tmpout= VAD_L_CMP(frame_energy, sub(frame_energy_Q,2), hVAD_CLDFB->frame_energy_smooth,hVAD_CLDFB->frame_energy_smooth_scale); test(); IF((NE_16(bw, CLDFBVAD_NB_ID))&&tmpout>0) { @@ -212,15 +224,15 @@ Word16 update_decision(T_CldfbVadState *st, move16(); } - /*if(frame_energy > 32*st->frame_energy_smooth)*/ - tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, st->frame_energy_smooth,sub(st->frame_energy_smooth_scale,5)); + /*if(frame_energy > 32*hVAD_CLDFB->frame_energy_smooth)*/ + tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, hVAD_CLDFB->frame_energy_smooth,sub(hVAD_CLDFB->frame_energy_smooth_scale,5)); if(tmpout>0) { update_flag = 0; move16(); } - tmp1 = L_mult(st->fg_energy_count,18842); + tmp1 = L_mult(hVAD_CLDFB->fg_energy_count,18842); tmp1_Q = norm_l(tmp1); tmp1 = L_shl(tmp1,tmp1_Q); tmp_norm = extract_h(tmp1); @@ -229,14 +241,14 @@ Word16 update_decision(T_CldfbVadState *st, fg_energy_Qtmp = sub(frame_energy_Q, 18); fg_energy_Qtmp = add(fg_energy_Qtmp, tmp1_Q); - cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,st->fg_energy,st->fg_energy_scale); + cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,hVAD_CLDFB->fg_energy,hVAD_CLDFB->fg_energy_scale); tmpout = VAD_L_CMP(frame_energy, frame_energy_Q, 3, 0); test(); test(); if((cmp_result>0) - &&(EQ_32(st->fg_energy_est_start,1)) + &&(EQ_32(hVAD_CLDFB->fg_energy_est_start,1)) &&(tmpout>0)) { update_flag = 0; @@ -253,15 +265,15 @@ Word16 update_decision(T_CldfbVadState *st, move16(); } - st->tonality_rate3 = mult(st->tonality_rate3, 32211); + hVAD_CLDFB->tonality_rate3 = mult(hVAD_CLDFB->tonality_rate3, 32211); move16(); if(tonality_flag) { - st->tonality_rate3 = add(mult(st->tonality_rate3,32211), 557); + hVAD_CLDFB->tonality_rate3 = add(mult(hVAD_CLDFB->tonality_rate3,32211), 557); move16(); } - if(GT_16(st->tonality_rate3, 16384)) + if(GT_16(hVAD_CLDFB->tonality_rate3, 16384)) { update_flag = 0; move16(); @@ -310,22 +322,22 @@ Word16 update_decision(T_CldfbVadState *st, IF(EQ_16(update_flag, 1)) { - if(LT_16(st->update_count, 1000)) + if(LT_16(hVAD_CLDFB->update_count, 1000)) { - st->update_count = add(st->update_count,1); + hVAD_CLDFB->update_count = add(hVAD_CLDFB->update_count,1); } } IF(update_flag) { - st->lt_noise_sp_center3 = add(mult(st->lt_noise_sp_center3,29491),mult(sp_center[3],3277)); + hVAD_CLDFB->lt_noise_sp_center3 = add(mult(hVAD_CLDFB->lt_noise_sp_center3,29491),mult(sp_center[3],3277)); move16(); } - tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, st->frame_energy_smooth,sub(st->frame_energy_smooth_scale,2)); + tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, hVAD_CLDFB->frame_energy_smooth,sub(hVAD_CLDFB->frame_energy_smooth_scale,2)); test(); @@ -350,9 +362,9 @@ Word16 update_decision(T_CldfbVadState *st, if((LT_32(snr,10066329/* 0.3 Q25 */))&&tmpout<0 &&(LT_32(L_shr(tsnr,1), 20132659/* 1.2/2.0 Q25 */)) &&(vad_flag==0) - &&(LT_16(st->f_tonality_rate[1],8192/* 0.5 Q14 */)) + &&(LT_16(hVAD_CLDFB->f_tonality_rate[1],8192/* 0.5 Q14 */)) &&(music_backgound_f==0) - &&(LT_16(st->ltd_stable_rate[3],3277/* 0.1 Q15 */))) + &&(LT_16(hVAD_CLDFB->ltd_stable_rate[3],3277/* 0.1 Q15 */))) { update_flag = 1; move16(); @@ -377,16 +389,16 @@ Word16 update_decision(T_CldfbVadState *st, IF(update_flag == 0) { - st->updateNumWithSnr = 0; + hVAD_CLDFB->updateNumWithSnr = 0; } ELSE { test(); test(); - IF(vad_flag && GT_32(snr, 100663293/* 3.0 Q25 */)&<_16(st->updateNumWithSnr,10)) + IF(vad_flag && GT_32(snr, 100663293/* 3.0 Q25 */)&<_16(hVAD_CLDFB->updateNumWithSnr,10)) { update_flag = 0; move16(); - st->updateNumWithSnr = add(st->updateNumWithSnr, 1); + hVAD_CLDFB->updateNumWithSnr = add(hVAD_CLDFB->updateNumWithSnr, 1); } } @@ -395,49 +407,49 @@ Word16 update_decision(T_CldfbVadState *st, IF(vad_flag==0||EQ_16(update_flag,1)) { Word16 tmp_fix; - tmp_fix = sub(st->sp_center[2],st->lt_noise_sp_center0); + tmp_fix = sub(hVAD_CLDFB->sp_center[2],hVAD_CLDFB->lt_noise_sp_center0); tmp_fix = abs_s(tmp_fix); if (GT_16(tmp_fix, 2558/* 2.5 Q10 */)) { tmp_fix = 2558/* 2.5 Q10 */; move16(); } - st->lt_noise_sp_center_diff_sum = L_add(st->lt_noise_sp_center_diff_sum ,tmp_fix); + hVAD_CLDFB->lt_noise_sp_center_diff_sum = L_add(hVAD_CLDFB->lt_noise_sp_center_diff_sum ,tmp_fix); move32(); - st->lt_noise_sp_center_diff_counter = L_add(st->lt_noise_sp_center_diff_counter,1); + hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_add(hVAD_CLDFB->lt_noise_sp_center_diff_counter,1); move32(); - IF(EQ_32(st->lt_noise_sp_center_diff_counter, 128)) + IF(EQ_32(hVAD_CLDFB->lt_noise_sp_center_diff_counter, 128)) { - st->lt_noise_sp_center_diff_sum = MUL_F(st->lt_noise_sp_center_diff_sum,24576); + hVAD_CLDFB->lt_noise_sp_center_diff_sum = MUL_F(hVAD_CLDFB->lt_noise_sp_center_diff_sum,24576); move32(); - st->lt_noise_sp_center_diff_counter = 96; + hVAD_CLDFB->lt_noise_sp_center_diff_counter = 96; move32(); } move16(); move16(); - IF(GT_16((Word16)abs_s(sub(st->sp_center[0],st->lt_noise_sp_center0)), 2455/* 2.4 Q10 */)) + IF(GT_16((Word16)abs_s(sub(hVAD_CLDFB->sp_center[0],hVAD_CLDFB->lt_noise_sp_center0)), 2455/* 2.4 Q10 */)) { - st->lt_noise_sp_center0 = add(mult(st->lt_noise_sp_center0,32637),mult(st->sp_center[0],131)); + hVAD_CLDFB->lt_noise_sp_center0 = add(mult(hVAD_CLDFB->lt_noise_sp_center0,32637),mult(hVAD_CLDFB->sp_center[0],131)); move16(); } - ELSE IF(GT_16((Word16)abs_s(sub(st->sp_center[0],st->lt_noise_sp_center0)), 1023/* 1.0 Q10 */)) + ELSE IF(GT_16((Word16)abs_s(sub(hVAD_CLDFB->sp_center[0],hVAD_CLDFB->lt_noise_sp_center0)), 1023/* 1.0 Q10 */)) { - st->lt_noise_sp_center0 = add(mult(st->lt_noise_sp_center0,32440),mult(st->sp_center[0],328)); + hVAD_CLDFB->lt_noise_sp_center0 = add(mult(hVAD_CLDFB->lt_noise_sp_center0,32440),mult(hVAD_CLDFB->sp_center[0],328)); move16(); } ELSE { - st->lt_noise_sp_center0 = add(mult(st->lt_noise_sp_center0,31457),mult(st->sp_center[0],1311)); + hVAD_CLDFB->lt_noise_sp_center0 = add(mult(hVAD_CLDFB->lt_noise_sp_center0,31457),mult(hVAD_CLDFB->sp_center[0],1311)); move16(); } } - Q_sum = sub(norm_l(st->lt_noise_sp_center_diff_sum), 1); - Q_counter = norm_l(st->lt_noise_sp_center_diff_counter); - sum_num = L_shl(st->lt_noise_sp_center_diff_sum,Q_sum); - counter_den = L_shl(st->lt_noise_sp_center_diff_counter,Q_counter); + Q_sum = sub(norm_l(hVAD_CLDFB->lt_noise_sp_center_diff_sum), 1); + Q_counter = norm_l(hVAD_CLDFB->lt_noise_sp_center_diff_counter); + sum_num = L_shl(hVAD_CLDFB->lt_noise_sp_center_diff_sum,Q_sum); + counter_den = L_shl(hVAD_CLDFB->lt_noise_sp_center_diff_counter,Q_counter); IF(extract_h(counter_den)==0) { @@ -454,7 +466,7 @@ Word16 update_decision(T_CldfbVadState *st, div_r =extract_l(L_shr(div_r_32, sub(div_r_Q, SP_CENTER_Q))); test(); - if((GT_16(abs_s(sub(st->sp_center[2],st->lt_noise_sp_center0)), div_r))&&(GT_16(frameloop,200))) + if((GT_16(abs_s(sub(hVAD_CLDFB->sp_center[2],hVAD_CLDFB->lt_noise_sp_center0)), div_r))&&(GT_16(frameloop,200))) { update_flag = 0; move16(); diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index a87801a..98ce6c9 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*-------------------------------------------------------------------* * updt_enc() @@ -15,9 +14,7 @@ *-------------------------------------------------------------------*/ void updt_enc_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : speech coder type */ + Encoder_State_fx *st, /* i/o: state structure */ const Word16 *old_exc, /* i : buffer of excitation */ const Word16 *pitch_buf, /* i : floating pitch for each subframe */ const Word16 Es_pred, /* i : predicited scaled innovation energy */ @@ -28,13 +25,17 @@ void updt_enc_fx( ) { Word16 i, tmp; - + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + LPD_state_HANDLE hLPDmem = st->hLPDmem; + GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; /* update old excitation buffer */ - Copy( &old_exc[L_frame], st->LPDmem.old_exc, L_EXC_MEM ); - IF( !st->Opt_AMR_WB_fx ) + Copy( &old_exc[st->L_frame_fx], hLPDmem->old_exc, L_EXC_MEM ); + test(); + IF( !st->Opt_AMR_WB_fx && st->hBWE_TD != NULL) { - Copy( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } /* update old LSP and LSF vector */ @@ -42,12 +43,12 @@ void updt_enc_fx( Copy( lsf_new, st->lsf_old_fx, M ); /* update last coder type */ - st->last_coder_type_fx = coder_type; + st->last_coder_type_fx = st->coder_type; move16(); test(); test(); test(); - if( EQ_16(coder_type,INACTIVE)||(EQ_16(st->bpf_off_fx,1)&&NE_16(coder_type,AUDIO)&&NE_16(coder_type,TRANSITION))) + if( EQ_16(st->coder_type,INACTIVE) || (EQ_16(st->bpf_off_fx,1) && NE_16(st->coder_type,AUDIO) && NE_16(st->coder_type,TRANSITION))) { st->last_coder_type_fx = UNVOICED; move16(); @@ -55,7 +56,7 @@ void updt_enc_fx( /* this ensures that st->last_coder_type_fx is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ test(); - if ( EQ_16(coder_type,INACTIVE)&>_32(st->total_brate_fx,ACELP_24k40)) + if ( EQ_16(st->coder_type,INACTIVE) && GT_32(st->total_brate_fx,ACELP_24k40)) { st->last_coder_type_fx = GENERIC; move16(); @@ -64,7 +65,7 @@ void updt_enc_fx( test(); test(); test(); - IF( st->Opt_AMR_WB_fx && EQ_16(coder_type,INACTIVE)&&st->core_brate_fx!=SID_1k75&&st->core_brate_fx!=FRAME_NO_DATA) + IF( st->Opt_AMR_WB_fx && EQ_16(st->coder_type,INACTIVE) && st->core_brate_fx!=SID_1k75 && st->core_brate_fx!=FRAME_NO_DATA) { /* overwrite previous coding type to help FEC */ st->last_coder_type_fx = UNVOICED; @@ -72,30 +73,30 @@ void updt_enc_fx( } /* AC mode (GSC) - in speech we can consider that the last pitch band reached the max */ - test(); - IF ( NE_16(coder_type,AUDIO)&&NE_16(coder_type,INACTIVE)) + test();test(); + IF (st->hGSCEnc != NULL && NE_16(st->coder_type,AUDIO) && NE_16(st->coder_type,INACTIVE)) { - st->mem_last_pit_band_fx = 10 + BAND1k2; + hGSCEnc->mem_last_pit_band_fx = 10 + BAND1k2; move16(); - st->past_dyn_dec_fx = NOISE_LEVEL_SP0-1; + hGSCEnc->past_dyn_dec_fx = NOISE_LEVEL_SP0-1; move16(); /* tends to speech */ - st->noise_lev_fx = NOISE_LEVEL_SP0-1; + hGSCEnc->noise_lev_fx = NOISE_LEVEL_SP0-1; move16(); /* tends to speech */ /*st->mid_dyn_fx = 40.0f * 0.5f + st->mid_dyn * 0.5f;*/ - st->mid_dyn_fx = add(20*128, mult_r(st->mid_dyn_fx, 16384)); /*Q7*/ + hGSCEnc->mid_dyn_fx = add(20*128, mult_r(hGSCEnc->mid_dyn_fx, 16384)); /*Q7*/ } /* convert old LSP vector from 12kHz domain to 16kHz domain (needed in case of ACELP@12k8 <-> ACELP@16kHz switching) */ - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16(st->L_frame_fx,L_FRAME)) { Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); st->rate_switching_reset_16kHz=lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, st->Opt_AMR_WB_fx ); } /* update buffer of old subframe pitch values */ - IF( NE_16(st->last_L_frame_fx,L_frame)) + IF( NE_16(st->last_L_frame_fx,st->L_frame_fx)) { - IF( EQ_16(L_frame,L_FRAME)) + IF( EQ_16(st->L_frame_fx,L_FRAME)) { FOR( i=0; iL_frame_fx,6); Copy( &st->old_pitch_buf_fx[tmp], st->old_pitch_buf_fx, tmp); Copy( pitch_buf, &st->old_pitch_buf_fx[tmp], tmp); /* SC-VBR */ st->last_Opt_SC_VBR_fx = st->Opt_SC_VBR_fx; move16(); - st->last_last_ppp_mode_fx = st->last_ppp_mode_fx; - move16(); - st->last_ppp_mode_fx = st->ppp_mode_fx; - move16(); - st->last_nelp_mode_fx = st->nelp_mode_fx; - move16(); - + IF(st->hSC_VBR != NULL) + { + hSC_VBR->last_last_ppp_mode_fx = hSC_VBR->last_ppp_mode_fx; + move16(); + hSC_VBR->last_ppp_mode_fx = hSC_VBR->ppp_mode_fx; + move16(); + hSC_VBR->last_nelp_mode_fx = hSC_VBR->nelp_mode_fx; + move16(); + } /* core switching updates */ Copy( &Aq[(st->L_frame_fx/L_SUBFR-1)*(M+1)], st->old_Aq_12_8_fx, M+1 ); st->old_Es_pred_fx = Es_pred; @@ -147,6 +150,13 @@ void updt_IO_switch_enc_fx( ) { Word16 xsp_tmp[M]; + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; + GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; + AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD; IF( EQ_16(st->last_core_fx,AMR_WB_CORE)) /* switching to EVS primary mode */ { @@ -165,12 +175,12 @@ void updt_IO_switch_enc_fx( isp2lsp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M); Copy( stable_LSP_fx, xsp_tmp, M ); - isp2lsp_fx( st->lspCNG_fx, st->lspCNG_fx, xsp_tmp, M); + isp2lsp_fx(hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M); /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_AMR_WB_SID * STEP_SID), 127 );*/ - IF( st->old_enr_index_fx >=0 ) + IF(hTdCngEnc->old_enr_index_fx >=0 ) { /* old index is initialized to -1, and may only be updated after it has been calculated properly at least once once */ - st->old_enr_index_fx = s_min(mult(shl(st->old_enr_index_fx,1), 32459), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ + hTdCngEnc->old_enr_index_fx = s_min(mult(shl(hTdCngEnc->old_enr_index_fx,1), 32459), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ } /* Perform preemphasis of the old input signal @16kHz */ st->mem_preemph16k_fx = 0; @@ -178,45 +188,66 @@ void updt_IO_switch_enc_fx( preemph_fx( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &(st->mem_preemph16k_fx) ); Scale_sig(st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new); /* reset TD BWE buffers */ - set16_fx( st->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( st->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); - set16_fx( st->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - - st->bwe_non_lin_prev_scale_fx = 0; + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( hBWE_TD->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); +#ifdef IVAS_CODE + set16_fx(st->hBWE_TD->mem_shb_res, 0, MAX_LEN_MA_FILTER); + set16_fx(st->hBWE_TD->old_EnvSHBres, 0, L_FRAME4k); + st->hBWE_TD->old_mean_EnvSHBres = 0; + st->hBWE_TD->prev_enr_EnvSHBres = 32767; + st->hBWE_TD->prev_pow_exc16kWhtnd = 32767; + st->hBWE_TD->prev_mix_factor = 32767; + st->hBWE_TD->prev_Env_error = 0; + move16();move16();move16();move16();move16(); +#endif + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); - set16_fx( st->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st->L_old_wtda_swb_fx, 0, L_FRAME16k ); - set16_fx( st->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + set16_fx( hBWE_TD->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set16_fx( hBWE_TD->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set16_fx(hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME16k ); + set16_fx(hBWE_FD->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - wb_tbe_extras_reset_fx( st->mem_genSHBexc_filt_down_wb2_fx, st->mem_genSHBexc_filt_down_wb3_fx ); + wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); IF( GE_16(input_frame,L_FRAME32k)) { - swb_tbe_reset_fx( st->mem_csfilt_fx, st->mem_genSHBexc_filt_down_shb_fx, st->state_lpc_syn_fx, - st->syn_overlap_fx, st->state_syn_shbexc_fx, &(st->tbe_demph_fx),&(st->tbe_premph_fx), st->mem_stp_swb_fx, &(st->gain_prec_swb_fx) ); + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &(hBWE_TD->tbe_demph_fx),&(hBWE_TD->tbe_premph_fx), hBWE_TD->mem_stp_swb_fx, &(hBWE_TD->gain_prec_swb_fx) ); } IF( EQ_16(input_frame,L_FRAME48k)) { - set16_fx(st->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); - st->fb_tbe_demph_fx = 0; + set16_fx(hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); + hBWE_TD->fb_tbe_demph_fx = 0; move16(); - fb_tbe_reset_enc_fx( st->elliptic_bpf_2_48k_mem_fx, &st->prev_fb_energy_fx,st->elliptic_bpf_2_48k_mem_fx_Q,&st->prev_fb_energy_fx_Q); + fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx,hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q,&hBWE_TD->prev_fb_energy_fx_Q); } /* reset FD BWE buffers */ - st->prev_mode_fx = NORMAL; + hBWE_FD->prev_mode_fx = NORMAL; move16(); /* reset the unvoiced/audio signal improvement memories */ - st->seed_tcx_fx = 15687; + hGSCEnc->seed_tcx_fx = 15687; move16(); st->use_acelp_preq = 0; move16(); +#ifdef IVAS_CODE + set16_fx(st->hSpMusClas->finc_prev, 0, ATT_NSEG); + set16_fx(st->hSpMusClas->tod_lt_Bin_E, 0, TOD_NSPEC); + set16_fx(st->hSpMusClas->tod_S_map_lt, 0, TOD_NSPEC); + st->hSpMusClas->lt_finc = 0; + st->hSpMusClas->last_strong_attack = 0; + st->hSpMusClas->tod_thr_lt = TOD_THR_MASS; + st->hSpMusClas->tod_weight = 0; + st->hSpMusClas->tod_S_mass_prev = TOD_THR_MASS; + st->hSpMusClas->tod_S_mass_lt = TOD_THR_MASS; + move16();move16();move16();move16();move16();move16(); +#endif } ELSE /* switching to AMR-WB IO mode */ @@ -230,35 +261,42 @@ void updt_IO_switch_enc_fx( lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M); lsp2isp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M); Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st->lspCNG_fx, st->lspCNG_fx, xsp_tmp, M); + lsp2isp_fx(hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M); - IF( st->old_enr_index_fx >= 0 ) + IF(hTdCngEnc->old_enr_index_fx >= 0 ) { /* old_enr__index is initialized to -1, and may only be updated this way after it has been calculated properly at least once once */ /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_SID * STEP_AMR_WB_SID), 63 );*/ - st->old_enr_index_fx = s_max(s_min(mult(st->old_enr_index_fx, 16384), 63 ),0); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ + hTdCngEnc->old_enr_index_fx = s_max(s_min(mult(hTdCngEnc->old_enr_index_fx, 16384), 63 ),0); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ } /* gain quantization memory */ - set16_fx(st->past_qua_en_fx, (-14*1024), GAIN_PRED_ORDER ); + set16_fx(hAmrwb_IO->past_qua_en_fx, (-14*1024), GAIN_PRED_ORDER ); /* reset VBR signalling */ - st->ppp_mode_fx = 0; - move16(); - st->nelp_mode_fx = 0; + IF (st->Opt_SC_VBR_fx) + { + hSC_VBR->ppp_mode_fx = 0; + move16(); + hSC_VBR->nelp_mode_fx = 0; + move16(); + } + st->hGSCEnc->seed_tcx_fx = 15687; /* the re-init here was present only in float _DIFF_FLOAT_FIX_*/ move16(); } /* Force SID in case of AMR-WB IO/EVS primary mode switching */ - st->cnt_SID_fx = 0; - move16(); - - /* CNG - reset */ - st->cng_cnt_fx = 0; - move16(); - st->ho_hist_size_fx = 0; - move16(); - st->burst_ho_cnt_fx = 0; - move16(); + IF (hTdCngEnc != NULL) + { + hDtxEnc->cnt_SID_fx = 0; + move16(); + /* CNG - reset */ + hDtxEnc->cng_cnt_fx = 0; + move16(); + hTdCngEnc->ho_hist_size_fx = 0; + move16(); + hTdCngEnc->burst_ho_cnt_fx = 0; + move16(); + } /* LP memories */ Copy( UVWB_Ave_fx, st->mem_AR_fx, M ); @@ -269,3 +307,218 @@ void updt_IO_switch_enc_fx( return; } + +/*-------------------------------------------------------------------* + * updt_enc_common() + * + * Common updates for MODE1 and MODE2 + *-------------------------------------------------------------------*/ +#if 1 +void updt_enc_common( + Encoder_State_fx* st, /* i/o: encoder state structure */ + const Word16 Etot, /* i : total energy */ + const Word16 Q_new /* i : CUrrent frame scaling */ +) +{ + /*---------------------------------------------------------------------* + * Updates - main main codec parameters + *---------------------------------------------------------------------*/ + + st->last_sr_core = st->sr_core; //## + move32(); + st->last_codec_mode = st->codec_mode; + move16(); + st->last_L_frame_fx = st->L_frame_fx; // + move16(); + st->last_core_fx = st->core_fx; + move16(); + + st->last_core_brate_fx = st->core_brate_fx; + move32(); +#ifdef IVAS_CODE + st->last_bits_frame_nominal_fx = st->bits_frame_nominal; +#endif + st->last_total_brate_fx = st->total_brate_fx; + move32(); + st->last_extl_fx = st->extl_fx; // + move16(); + st->last_input_bwidth_fx = st->input_bwidth_fx; //## + move16(); + st->last_bwidth_fx = st->bwidth_fx; //## + move16(); + st->hNoiseEst->Etot_last_fx = Etot; + move16(); + st->last_coder_type_raw_fx = st->coder_type_raw_fx; + move16(); + + st->prev_Q_new = Q_new; + move16(); + + test(); + if (GT_32(st->core_brate_fx, SID_2k40) && st->hDtxEnc != NULL) + { + st->hDtxEnc->last_active_brate_fx = st->total_brate_fx; + move32(); + } + + IF(st->hBWE_TD != NULL) + { + st->hBWE_TD->prev_coder_type_fx = st->coder_type; + move16(); + if (EQ_16(st->core_fx, HQ_CORE)) + { + /* in the HQ core, coder_type is not used so it could have been set to anything */ + st->hBWE_TD->prev_coder_type_fx = GENERIC; + move16(); + + } + } + + test(); + IF(st->Opt_DTX_ON_fx && st->hTdCngEnc != NULL) + { + IF(GT_32(st->core_brate_fx, SID_2k40) ) + { + IF(EQ_16(st->hDtxEnc->first_CNG_fx, 1)) + { + if (GE_16(st->hTdCngEnc->act_cnt_fx, BUF_DEC_RATE)) + { + st->hTdCngEnc->act_cnt_fx = 0; + move16(); + } + st->hTdCngEnc->act_cnt_fx = add(st->hTdCngEnc->act_cnt_fx, 1); + + test(); + if (EQ_16(st->hTdCngEnc->act_cnt_fx, BUF_DEC_RATE) && st->hTdCngEnc->ho_hist_size_fx > 0) + { + st->hTdCngEnc->ho_hist_size_fx = sub(st->hTdCngEnc->ho_hist_size_fx, 1); + } + } + + test(); test(); test(); + IF(EQ_16(st->element_mode, IVAS_SCE) || EQ_16(st->element_mode, IVAS_CPE_DFT) || EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->hDtxEnc->first_CNG_fx, 1)) + { + st->hTdCngEnc->act_cnt2_fx = add(st->hTdCngEnc->act_cnt2_fx, 1); + st->hTdCngEnc->act_cnt2_fx = s_min(st->hTdCngEnc->act_cnt2_fx, MIN_ACT_CNG_UPD); + +#ifdef IVAS_CODE + test(); test(); test(); + IF((EQ_16(st->element_mode, IVAS_SCE) || EQ_16(st->element_mode, IVAS_CPE_DFT) || EQ_16(st->element_mode, IVAS_CPE_TD)) && GE_16(st->hTdCngEnc->act_cnt2_fx, MIN_ACT_CNG_UPD)) + { + st->hTdCngEnc->CNG_att_fx = 0; move16(); + + apply_scale(&st->hTdCngEnc->CNG_att, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO); + } +#endif + } + } + + test(); test(); test(); + if ((EQ_32(st->core_brate_fx, SID_2k40) || EQ_32(st->core_brate_fx, FRAME_NO_DATA) || (GT_32(st->core_brate_fx, SID_1k75) && EQ_16(st->core_fx, AMR_WB_CORE))) && st->hDtxEnc->first_CNG_fx == 0 && EQ_16(st->cng_type_fx, LP_CNG)) + { + st->hDtxEnc->first_CNG_fx = 1; + move16(); + } + } + + /*-----------------------------------------------------------------* + * Increase the counter of initialization frames + * Limit the max number of init. frames + *-----------------------------------------------------------------*/ + + if (LT_16(st->ini_frame_fx, MAX_FRAME_COUNTER)) + { + st->ini_frame_fx = add(st->ini_frame_fx, 1); + } + + /* synchronisation of CNG seeds */ + test();test();test(); + IF (st->hTdCngEnc != NULL && NE_32(st->core_brate_fx, FRAME_NO_DATA) && NE_32(st->core_brate_fx, SID_2k40) && NE_16(st->core_fx, AMR_WB_CORE)) + { + Random(&(st->hTdCngEnc->cng_seed_fx)); + Random(&(st->hTdCngEnc->cng_ener_seed_fx)); + } + + /*---------------------------------------------------------------------* + * Updates - MODE2 + *---------------------------------------------------------------------*/ + + IF (EQ_16(st->element_mode, EVS_MONO) && EQ_16(st->mdct_sw, MODE2)) + { + st->codec_mode = MODE2; + move16(); + + st->sr_core = getCoreSamplerateMode2(EVS_MONO, st->total_brate_fx, st->bwidth_fx, st->flag_ACELP16k, st->rf_mode, 0); + + //st->L_frame_fx = extract_l(Mult_32_16(st->sr_core, 0x0290)); /*(int16_t)(st->sr_core / FRAMES_PER_SEC);*/ + + IF (EQ_32(st->sr_core, INT_FS_12k8)) + { + st->preemph_fac = PREEMPH_FAC; + st->gamma = GAMMA1; + st->L_frame_fx = L_FRAME; + move16(); move16(); move16(); + } + ELSE + { + st->preemph_fac = PREEMPH_FAC_16k; + st->gamma = GAMMA16k; + st->L_frame_fx = L_FRAME16k; + move16();move16();move16(); + } + + st->igf = getIgfPresent(EVS_MONO, st->total_brate_fx, st->bwidth_fx, st->rf_mode); + } + + /* update FER clas */ + if (NE_16(st->core_fx, AMR_WB_CORE)) + { + st->last_clas_fx = st->clas_fx; + move16(); + } + + /* Update Core */ + core_encode_update(st); + + /*---------------------------------------------------------------------* + * RF mode updates + *---------------------------------------------------------------------*/ + + IF (st->rf_mode) + { + IF (st->hSC_VBR != NULL) + { + st->hSC_VBR->last_nelp_mode_fx = 0; + move16(); + if (EQ_16(st->hRF->rf_frame_type, RF_NELP)) + { + st->hSC_VBR->last_nelp_mode_fx = 1; + move16(); + } + + } + } + + st->rf_mode_last = st->rf_mode; move16(); + + IF (st->Opt_RF_ON) + { + st->L_frame_fx = L_FRAME; + st->rf_mode = 1; + move16();move16(); + } + + /*---------------------------------------------------------------------* + * Other updates + *---------------------------------------------------------------------*/ +#ifdef IVAS_CODE + test(); + if (GT_16(st->element_mode, EVS_MONO) && st->hTcxEnc != NULL) + { + st->hTcxEnc->tcxltp_norm_corr_mem= st->hTcxEnc->tcxltp_norm_corr_past; + move16(); + } +#endif + return; +} +#endif \ No newline at end of file diff --git a/lib_enc/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index 82d78cb..1f727ab 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -1,10 +1,9 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /*----------------------------------------------------------------------------------* * procedure updt_tar: @@ -13,7 +12,7 @@ *----------------------------------------------------------------------------------*/ void updt_tar_fx( const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ + Word16 *x2, /* o : new target (for codebook search) */ const Word16 *y, /* i : filtered adaptive codebook vector */ const Word16 gain, /* i : adaptive codebook gain */ const Word16 L /* i : subframe size */ @@ -30,6 +29,7 @@ void updt_tar_fx( L_tmp = L_msu(L_tmp, y[i], gain); x2[i] = extract_h(L_shl(L_tmp, 1)); } + return; } /*----------------------------------------------------------------------------------* * procedure updt_tar: @@ -38,7 +38,7 @@ void updt_tar_fx( *----------------------------------------------------------------------------------*/ void updt_tar_HR_fx( const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ + Word16 *x2, /* o : new target (for codebook search) */ const Word16 *y, /* i : filtered adaptive codebook vector */ const Word16 gain, /* i : adaptive codebook gain Q2 */ const Word16 Qx, /* i : Scaling factor to adapt output to input */ @@ -57,4 +57,5 @@ void updt_tar_HR_fx( L_tmp = L_sub(L_tmp, L_tmp1); x2[i] = extract_h(L_tmp); } + return; } diff --git a/lib_enc/vad_basop.c b/lib_enc/vad_basop.c index ff97b38..1c0d0c4 100644 --- a/lib_enc/vad_basop.c +++ b/lib_enc/vad_basop.c @@ -2,13 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include +#include +#include "options.h" #include "prot_fx.h" #include "vad_basop.h" #include "basop_util.h" -#include "stl.h" -#include "options.h" /* Needed for Stack Counting Mechanism Macros (when Instrumented) */ Word32 vad_Sqrt_l( /* o : output value, Q31 */ Word32 i_s32Val, diff --git a/lib_enc/vad_basop.h b/lib_enc/vad_basop.h index d2acc8f..87391b6 100644 --- a/lib_enc/vad_basop.h +++ b/lib_enc/vad_basop.h @@ -49,10 +49,11 @@ Word32 VAD_L_div( Word32 L_var1, Word32 VAD_Log2( Word32 i_s32Val, Word16 i_s16Q ); - -Word16 ffr_getSfWord32( Word32 *vector, - Word16 len - ); +/*already defined in prot_fx.h +Word16 ffr_getSfWord32( + Word32 *vector, + Word16 len + );*/ Word32 VAD_Pow( Word32 i_s32Base, Word32 i_s32Exp, diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 398cab3..90b85c7 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -1,13 +1,11 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - -#include "options.h" /* Compilation switches */ +#include +#include "options.h" #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_enc_fx.h" -#include "stl.h" - /*-----------------------------------------------------------------* @@ -75,10 +73,10 @@ /* snr_sum = "scale" * (float)log10( L_snr_sum ) ;*/ -static -Word16 vad_snr_log_fx( /* o: Q8 */ - Word32 L_snr /* i: Q4 */ - , Word16 scale)/* i: scale Q13 , 10.0*log10(2) or 1.0*log10(2) */ +static Word16 vad_snr_log_fx( /* o: Q8 */ + Word32 L_snr, /* i: Q4 */ + Word16 scale/* i: scale Q13 , 10.0*log10(2) or 1.0*log10(2) */ +) { Word16 e_snr,f_snr; Word32 L_tmp; @@ -92,62 +90,43 @@ Word16 vad_snr_log_fx( /* o: Q8 */ void wb_vad_init_fx( - Word16 *nb_active_frames, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt, - Word16 *lp_speech, /* o : long-term active speech level */ - Word16 *nb_active_frames_he, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt_he, - Word16 *bcg_flux, /* o : background noise fluctuation */ - Word16 *soft_hangover, /* o : soft hangover counter */ - Word16 *voiced_burst, /* o : consecutive voiced speech counter */ - Word16 *bcg_flux_init, /* o : initialization period for noise fluctuation estimation */ - Word16 *nb_active_frames_he1, /* o : nb of consecutive active speech frames 1 */ - Word16 *hangover_cnt_he1, - Word32 *L_vad_flag_reg_H, - Word32 *L_vad_flag_reg_L, - Word32 *L_vad_prim_reg, - Word16 *vad_flag_cnt_50, - Word16 *vad_prim_cnt_16, - Word16 *hangover_cnt_dtx - , Word16 *hangover_cnt_music + VAD_HANDLE hVAD /* i/o: VAD data handle */ ) { - *hangover_cnt = 0; + hVAD->hangover_cnt_fx = 0; move16(); /* Hangover counter initialized to 0 */ - *nb_active_frames = ACTIVE_FRAMES_FX; + hVAD->nb_active_frames_fx = ACTIVE_FRAMES_FX; move16(); /* The counter of SPEECH frames necessary to trigger HO */ /* is set to max (-> start with hangover) */ - *lp_speech = 11520; - move16(); /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ - *L_vad_flag_reg_H = L_deposit_l(0); - *L_vad_flag_reg_L = L_deposit_l(0); - *L_vad_prim_reg = L_deposit_l(0); - *vad_flag_cnt_50 = 0; + hVAD->L_vad_flag_reg_H_fx = L_deposit_l(0); + hVAD->L_vad_flag_reg_L_fx = L_deposit_l(0); + hVAD->L_vad_prim_reg_fx = L_deposit_l(0); + hVAD->vad_flag_cnt_50_fx = 0; move16(); - *vad_prim_cnt_16 = 0; + hVAD->vad_prim_cnt_16_fx = 0; move16(); - *hangover_cnt_dtx = HANGOVER_LONG_FX; + hVAD->hangover_cnt_dtx_fx = HANGOVER_LONG_FX; move16(); /* hangover for DTX */ - *hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; + hVAD->hangover_cnt_music_fx = HANGOVER_LONG_MUSIC_FX; move16(); /* hangover for MUSIC DTX */ - *hangover_cnt_he = 0; + hVAD->hangover_cnt_he_fx = 0; move16(); /* Hangover counter initialized to 0 */ - *nb_active_frames_he = ACTIVE_FRAMES_FX; + hVAD->nb_active_frames_he_fx = ACTIVE_FRAMES_FX; move16(); /* The counter of SPEECH frames necessary to trigger HO */ - *bcg_flux = 1120; + hVAD->bcg_flux_fx = 1120; move16(); /*70 in Q4 */ - *soft_hangover = 0; + hVAD->soft_hangover_fx = 0; move16(); - *voiced_burst = 0; + hVAD->voiced_burst_fx = 0; move16(); - *bcg_flux_init = 50; + hVAD->bcg_flux_init_fx = 50; move16(); - *nb_active_frames_he1 = ACTIVE_FRAMES_FX; + hVAD->nb_active_frames_he1_fx = ACTIVE_FRAMES_FX; move16(); - *hangover_cnt_he1 = 0; + hVAD->hangover_cnt_he1_fx = 0; move16(); return; } @@ -158,12 +137,12 @@ void wb_vad_init_fx( * * accumulate snr_sum with significance thresholds *-----------------------------------------------------------------*/ -static -void sign_thr_snr_acc_fx( +static void sign_thr_snr_acc_fx( Word32 *L_snr_sum, /* o: Q4 */ Word32 L_snr, /* i: Q4 */ Word16 sign_thr, /* i: Q4 */ - Word16 min_snr ) /* i: Q4 */ + Word16 min_snr /* i: Q4 */ +) { /*if( snr >= sign_thr ) */ Word32 L_tmp; @@ -185,16 +164,28 @@ void sign_thr_snr_acc_fx( Word16 dtx_hangover_addition_fx( Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 localVAD, /* i Q0 */ const Word16 vad_flag, /* i Q0 */ const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ - Word16 *vad_hover_flag_ptr + const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ + Word16 *vad_hover_flag_ptr, + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ ) { Word16 hangover_short_dtx ; Word16 flag_dtx ; Word16 tmp; + if (hNoiseEst == NULL) + { + hNoiseEst = st_fx->hNoiseEst; + move16(); + } + + if (hVAD == NULL) + { + move16(); + hVAD = st_fx->hVAD; + } flag_dtx = 0; @@ -208,19 +199,19 @@ Word16 dtx_hangover_addition_fx( test(); if ( ( ( LT_16(lp_snr,(16*256))) && ( NE_16(st_fx->input_bwidth_fx, NB) )) - || ( GT_16(st_fx->prim_act_he_fx, 31130) ) ) /*.95*Q15*/ + || ( GT_16(hVAD->prim_act_he_fx, 31130) ) ) /*.95*Q15*/ { hangover_short_dtx = 3; move16(); } /* Adjust hangover according to activity history */ - if (GT_16(st_fx->vad_prim_cnt_16_fx, 12)) /* 12 requires roughly > 80% primary activity */ + if (GT_16(hVAD->vad_prim_cnt_16_fx, 12)) /* 12 requires roughly > 80% primary activity */ { hangover_short_dtx = add(hangover_short_dtx,2); } - if (GT_16(st_fx->vad_flag_cnt_50_fx, 40)) /* 40 requires roughtly > 80% flag activity */ + if (GT_16(hVAD->vad_flag_cnt_50_fx, 40)) /* 40 requires roughtly > 80% flag activity */ { hangover_short_dtx = add(hangover_short_dtx,5); } @@ -261,9 +252,9 @@ Word16 dtx_hangover_addition_fx( test(); test(); if ( (GT_16(hangover_short_dtx, tmp)) - && ( (LT_16(st_fx->vad_prim_cnt_16_fx, 7) ) + && ( (LT_16(hVAD->vad_prim_cnt_16_fx, 7) ) || ( (GT_16(lp_snr, (16*256)) ) - && (LT_16(st_fx->prim_act_he_fx, 27853) ) /*0.85f*2^15 */ + && (LT_16(hVAD->prim_act_he_fx, 27853) ) /*0.85f*2^15 */ ) ) ) @@ -288,80 +279,80 @@ Word16 dtx_hangover_addition_fx( /* Add hangover after sufficient # of active frames or sufficient activity during last second */ test(); - if ( ( GE_16(st_fx->nb_active_frames_fx, ACTIVE_FRAMES_FX)) - || (GT_16(st_fx->vad_flag_cnt_50_fx,45)) ) /* 45 requires roughly > 90% flag activity */ + if ( ( GE_16(hVAD->nb_active_frames_fx, ACTIVE_FRAMES_FX)) + || (GT_16(hVAD->vad_flag_cnt_50_fx,45)) ) /* 45 requires roughly > 90% flag activity */ { - st_fx->hangover_cnt_dtx_fx = 0; + hVAD->hangover_cnt_dtx_fx = 0; move16(); } /* inside HO period */ test(); - if( ( LT_16(st_fx->hangover_cnt_dtx_fx, HANGOVER_LONG_FX)) - && (st_fx->hangover_cnt_dtx_fx != 0) ) + if( ( LT_16(hVAD->hangover_cnt_dtx_fx, HANGOVER_LONG_FX)) + && (hVAD->hangover_cnt_dtx_fx != 0) ) { - st_fx->hangover_cnt_dtx_fx = add(st_fx->hangover_cnt_dtx_fx, 1); + hVAD->hangover_cnt_dtx_fx = add(hVAD->hangover_cnt_dtx_fx, 1); } - st_fx->hangover_terminate_flag_fx = 0; + hVAD->hangover_terminate_flag_fx = 0; move16();/* float fix FIX_HO_TERMINATE */ /* Music hangover when music detected */ test(); test(); test(); - if ( (GT_16(st_fx->prim_act_he_fx,31129)) - && (GT_16(st_fx->Etot_lp_fx,40*256) ) - && (GT_16(st_fx->vad_prim_cnt_16_fx,14) ) - && (GT_16(st_fx->vad_flag_cnt_50_fx,48) ) ) /* 45 requires roughly > 95% flag activity */ + if ( (GT_16(hVAD->prim_act_he_fx,31129)) + && (GT_16(hNoiseEst->Etot_lp_fx,40*256) ) + && (GT_16(hVAD->vad_prim_cnt_16_fx,14) ) + && (GT_16(hVAD->vad_flag_cnt_50_fx,48) ) ) /* 45 requires roughly > 95% flag activity */ { - st_fx->hangover_cnt_music_fx = 0; + hVAD->hangover_cnt_music_fx = 0; move16(); } /* inside Music HO period */ test(); - if( ( LT_16(st_fx->hangover_cnt_music_fx, HANGOVER_LONG_MUSIC_FX)) - && (st_fx->hangover_cnt_music_fx != 0) ) + if( ( LT_16(hVAD->hangover_cnt_music_fx, HANGOVER_LONG_MUSIC_FX)) + && (hVAD->hangover_cnt_music_fx != 0) ) { - st_fx->hangover_cnt_music_fx = add(st_fx->hangover_cnt_music_fx, 1); + hVAD->hangover_cnt_music_fx = add(hVAD->hangover_cnt_music_fx, 1); } } ELSE { /* Reset the counter of speech frames necessary to start hangover algorithm */ - if(LT_16(st_fx->hangover_cnt_dtx_fx,HANGOVER_LONG_FX)) /* inside HO period */ + if(LT_16(hVAD->hangover_cnt_dtx_fx,HANGOVER_LONG_FX)) /* inside HO period */ { - st_fx->hangover_cnt_dtx_fx = add(st_fx->hangover_cnt_dtx_fx,1); + hVAD->hangover_cnt_dtx_fx = add(hVAD->hangover_cnt_dtx_fx,1); } - if(LT_16(st_fx->hangover_cnt_music_fx,HANGOVER_LONG_MUSIC_FX)) /* inside HO period */ + if(LT_16(hVAD->hangover_cnt_music_fx,HANGOVER_LONG_MUSIC_FX)) /* inside HO period */ { - st_fx->hangover_cnt_music_fx = add(st_fx->hangover_cnt_music_fx,1); + hVAD->hangover_cnt_music_fx = add(hVAD->hangover_cnt_music_fx,1); } /* fast terminate DTX hangover if st->hangover_terminate_flag is set */ - IF ( st_fx->hangover_terminate_flag_fx != 0 ) + IF ( hVAD->hangover_terminate_flag_fx != 0 ) { - st_fx->hangover_cnt_fx = HANGOVER_LONG_FX; + hVAD->hangover_cnt_fx = HANGOVER_LONG_FX; move16(); - st_fx->hangover_cnt_dtx_fx = HANGOVER_LONG_FX; + hVAD->hangover_cnt_dtx_fx = HANGOVER_LONG_FX; move16(); - st_fx->hangover_terminate_flag_fx = 0; + hVAD->hangover_terminate_flag_fx = 0; move16(); /* Only shorten music hangover when low energy frames */ - if (LT_16(st_fx->Etot_lp_fx,20*256)) + if (LT_16(hNoiseEst->Etot_lp_fx,20*256)) { - st_fx->hangover_cnt_music_fx = HANGOVER_LONG_MUSIC_FX; + hVAD->hangover_cnt_music_fx = HANGOVER_LONG_MUSIC_FX; move16(); } } - if( LE_16(st_fx->hangover_cnt_dtx_fx, hangover_short_dtx)) /* "hard" hangover */ + if( LE_16(hVAD->hangover_cnt_dtx_fx, hangover_short_dtx)) /* "hard" hangover */ { flag_dtx = 1; move16(); } - if( LE_16(st_fx->hangover_cnt_music_fx, 15)) /* "hard" hangover music */ + if( LE_16(hVAD->hangover_cnt_music_fx, 15)) /* "hard" hangover music */ { flag_dtx = 1; move16(); @@ -371,7 +362,7 @@ Word16 dtx_hangover_addition_fx( test(); - if ( flag_dtx != 0 && localVAD == 0 ) + if ( flag_dtx != 0 && st_fx->localVAD == 0 ) { *vad_hover_flag_ptr = 1; move16(); @@ -380,19 +371,26 @@ Word16 dtx_hangover_addition_fx( return flag_dtx ; } - +/*-----------------------------------------------------------------* + * wb_vad() + * + * Voice Activity Detector + *-----------------------------------------------------------------*/ /* new simplified and harmonized code */ Word16 wb_vad_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ - Word16 *localVAD, + Encoder_State_fx *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ Word16 *localVAD_HE_SAD, - Word8 *flag_noisy_speech_snr , /* o : */ - const Word16 Q_new /* i : scaling factor Q0 */ + Word8 *flag_noisy_speech_snr , /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech_fx, /* i : long term active speech energy average */ + Word16 lp_noise_fx /* i : long term noise energy */ ) { Word16 i, flag=0, hangover_short; @@ -441,6 +439,30 @@ Word16 wb_vad_fx( Word32 L_accum_ener_L; Word32 L_accum_ener_H; Word16 vad_bwidth_fx; + Word16 last_7k2_coder_type_fx; + + if (hNoiseEst == NULL) + { + hNoiseEst = st_fx->hNoiseEst; + move16(); + } + + if (hVAD == NULL) + { + move16(); + hVAD = st_fx->hVAD; + } + if ( LT_16(lp_speech_fx , -100*256)) + { + lp_speech_fx = st_fx->lp_speech_fx; + move16(); + } + + if (LT_16(lp_noise_fx, -100*256)) + { + lp_noise_fx = st_fx->lp_noise_fx; + move16(); + } vad_bwidth_fx = st_fx->input_bwidth_fx; move16(); @@ -471,7 +493,25 @@ Word16 wb_vad_fx( st_fx->max_band_fx = 19; move16(); } - + /*_DIFF_FLOAT_FIX_ -> see around Ln1570, inversion in if conditions compared to float*/ + PMT("Error in EVS fixed point ?") + /*FIXED EVS */ + /* ELSE IF(((LE_16(st_fx->last_coder_type_fx, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR_fx != 0)) || + ((LE_16(last_7k2_coder_type_fx, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR_fx == 0)))*/ + + /*FLOAT both IVAS and EVS */ + /*if ((snr_outlier_index <= 4 && (st->last_coder_type > UNVOICED) && !st->Opt_SC_VBR) || + (snr_outlier_index <= 4 && (last_7k2_coder_type > UNVOICED) && st->Opt_SC_VBR))*/ + IF ( 1)//st_fx->Opt_SC_VBR_fx) + { + last_7k2_coder_type_fx = st_fx->hSC_VBR->last_7k2_coder_type_fx; + move16(); + } + ELSE + { + last_7k2_coder_type_fx = -1; + move16(); + } /*---------------------------------------------------------------------* * set SNR thresholds depending on the input bandwitdh *---------------------------------------------------------------------*/ @@ -547,7 +587,7 @@ Word16 wb_vad_fx( * compute SNR for each band & total *---------------------------------------------------------------------*/ - lp_snr = sub(st_fx->lp_speech_fx, st_fx->lp_noise_fx); /*Q8 */ + lp_snr = sub(lp_speech_fx, lp_noise_fx); /*Q8 */ snr_idx = 2; move16(); @@ -632,7 +672,7 @@ Word16 wb_vad_fx( pt1 = fr_bands; pt2 = fr_bands + NB_BANDS; - pt3 = st_fx->bckr_fx; + pt3 = hNoiseEst->bckr_fx; L_snr_sum = L_deposit_l(0); L_snr_sum_HE_SAD = L_deposit_l(0); @@ -652,7 +692,7 @@ Word16 wb_vad_fx( ftmp2 = L_add(*pt3++, 0); /*fr_enr = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 );*/ - L_tmp = Mult_32_16(st_fx->enrO_fx[i], 13107); /* L_tmp(high word) = Qenr0fx*Q16+1 -16 -> Qener0+1 */ + L_tmp = Mult_32_16(hNoiseEst->enrO_fx[i], 13107); /* L_tmp(high word) = Qenr0fx*Q16+1 -16 -> Qener0+1 */ L_tmp1 = Madd_32_16(L_tmp, ftmp, 26214); /* 26214 = .4 in Q16 */ L_tmp1 = Madd_32_16(L_tmp1, ftmp1, 26214); /* L_tmp1 re_used a bit later for final snr[i]*/ @@ -797,13 +837,13 @@ Word16 wb_vad_fx( /* recompute after he1 modifications */ /* snr[i] = fr_enr / st->bckr[i] = L_tmp1/st->bckr[i];*/ - IF (st_fx->bckr_fx[i] != 0) + IF (hNoiseEst->bckr_fx[i] != 0) { e_num = norm_l(L_tmp1); m_num = extract_h(L_shl(L_tmp1,e_num)); - e_noise = norm_l(st_fx->bckr_fx[i]); - m_noise= extract_h(L_shl(st_fx->bckr_fx[i],e_noise)); + e_noise = norm_l(hNoiseEst->bckr_fx[i]); + m_noise= extract_h(L_shl(hNoiseEst->bckr_fx[i],e_noise)); m_num = shr(m_num,1); shift_snr = add(sub(e_num, e_noise),15-4); @@ -847,11 +887,11 @@ Word16 wb_vad_fx( /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ IF(LT_16(i,3)) { - L_accum_ener_L = L_add(L_accum_ener_L , st_fx->bckr_fx[i]);/*Q_new+QSCALE */ + L_accum_ener_L = L_add(L_accum_ener_L , hNoiseEst->bckr_fx[i]);/*Q_new+QSCALE */ } ELSE { - L_accum_ener_H = L_add(L_accum_ener_H , st_fx->bckr_fx[i]);/*Q_new+QSCALE */ + L_accum_ener_H = L_add(L_accum_ener_H , hNoiseEst->bckr_fx[i]);/*Q_new+QSCALE */ } /* Identify the outlier band */ @@ -953,7 +993,7 @@ Word16 wb_vad_fx( } } /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ - st_fx->L_snr_sum_vad_fx = L_shr(L_add(st_fx->L_snr_sum_vad_fx ,L_snr_sum_ol ),1); /*Q4*/ + hVAD->L_snr_sum_vad_fx = L_shr(L_add(hVAD->L_snr_sum_vad_fx ,L_snr_sum_ol ),1); /*Q4*/ /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ snr_sum_ol = vad_snr_log_fx(L_snr_sum_ol, LG10); @@ -970,41 +1010,52 @@ Word16 wb_vad_fx( /*---------------------------------------------------------------------* * compute thr1 for SAD decision *---------------------------------------------------------------------*/ - lp_snr = sub(st_fx->lp_speech_fx,st_fx->lp_noise_fx); /*Q8*/ + lp_snr = sub(lp_speech_fx, lp_noise_fx); /*Q8*/ sub(0,0); - IF ( LT_16(lp_snr, st_fx->sign_dyn_lp_fx)) + IF ( LT_16(lp_snr, hNoiseEst->sign_dyn_lp_fx)) { lp_snr = add(lp_snr,1<<8); /* lp_snr += 1; */ - if (GT_16(lp_snr, st_fx->sign_dyn_lp_fx)) + if (GT_16(lp_snr, hNoiseEst->sign_dyn_lp_fx)) { - lp_snr = st_fx->sign_dyn_lp_fx; + lp_snr = hNoiseEst->sign_dyn_lp_fx; move16(); } } /*thr1 = nk * lp_snr + nc*1.0 + nv * ( st->Etot_v_h2 - nv_ofs); */ /* Linear function for noisy speech */ - L_tmp = L_shl(L_mult(sub(st_fx->Etot_v_h2_fx, nv_ofs), nv ),7); /* Q8+Q8+1 +7 --> Q24 */ + L_tmp = L_shl(L_mult(sub(hNoiseEst->Etot_v_h2_fx, nv_ofs), nv ),7); /* Q8+Q8+1 +7 --> Q24 */ L_tmp = L_mac(L_tmp, nc, (Word16)32767); /* Q8+Q15+1 = Q24 */ thr1 = mac_r(L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ - - +#ifdef IVAS_CODE + if (st->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100) + { + /* lower threshold during warmup time */ + thr1 -= 10.0f; + vad_thr = 0.f; + } +#endif IF (GT_16(lp_snr, (Word16)20*(1<<8))) /* if (lp_snr > 20.0f )*/ { - /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ - thr1 = add(thr1, mult(9830, sub(lp_snr,(Word16) 20*(1<<8) ))); /* Q15*Q8+1 -16 --> Q8 */ - - test(); - test(); - test(); - if( EQ_16(st_fx->max_band_fx,16) - && GT_16(lp_snr,40*256) - && GT_16(thr1,6600) - && LT_16(st_fx->lp_speech_fx,11520) ) +#ifdef IVAS_CODE + if (st->element_mode == EVS_MONO || hNoiseEst->first_noise_updt_cnt >= 100) +#endif { - thr1 = 6600; + /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ + thr1 = add(thr1, mult(9830, sub(lp_snr, (Word16)20 * (1 << 8)))); /* Q15*Q8+1 -16 --> Q8 */ + + test(); + test(); + test(); + if (EQ_16(st_fx->max_band_fx, 16) + && GT_16(lp_snr, 40 * 256) + && GT_16(thr1, 6600) + && LT_16(lp_speech_fx, 11520)) + { + thr1 = 6600; + } } } @@ -1042,20 +1093,21 @@ Word16 wb_vad_fx( test(); test(); test(); + test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float + ### st_fx->Opt_SC_VBR_fx!=0 vs !st_fx->Opt_SC_VBR #####*/ test(); - test(); - IF( ( (LE_16(snr_outlier_index, 4))&&(GT_16(st_fx->last_coder_type_fx,UNVOICED))&&(st_fx->Opt_SC_VBR_fx!=0))|| - ( (LE_16(snr_outlier_index, 4)) && (GT_16(st_fx->last_7k2_coder_type_fx, UNVOICED) ) && ( st_fx->Opt_SC_VBR_fx == 0 ) ) ) + IF( LE_16(snr_outlier_index, 4) && ( ( GT_16(st_fx->last_coder_type_fx,UNVOICED) && (st_fx->Opt_SC_VBR_fx!=0)) || + ( GT_16(last_7k2_coder_type_fx, UNVOICED) && ( st_fx->Opt_SC_VBR_fx == 0 ) ) ) ) { thr1_ol = sub(thr1_ol,(Word16)(1<<8)); /*thr1_ol = thr1 - 1.0f ; */ - /*snr_sum_ol = 10.0f * (float)log10( st_fx->L_snr_sum_vad_fx );*/ - snr_sum_ol = vad_snr_log_fx(st_fx->L_snr_sum_vad_fx, LG10); /* snr in Q8 */ + /*snr_sum_ol = 10.0f * (float)log10( hVAD->L_snr_sum_vad_fx );*/ + snr_sum_ol = vad_snr_log_fx(hVAD->L_snr_sum_vad_fx, LG10); /* snr in Q8 */ } - ELSE IF ( ((LE_16(st_fx->last_coder_type_fx, UNVOICED))&&(LT_32(L_snr_outlier,MAX_SNR_OUTLIER_2_FX))&&(st_fx->Opt_SC_VBR_fx!=0))|| - ((LE_16(st_fx->last_7k2_coder_type_fx, UNVOICED) ) && (LT_32(L_snr_outlier,MAX_SNR_OUTLIER_2_FX)) && ( st_fx->Opt_SC_VBR_fx == 0 ) ) ) + ELSE IF ( ((LE_16(st_fx->last_coder_type_fx, UNVOICED)) && (LT_32(L_snr_outlier,MAX_SNR_OUTLIER_2_FX)) && ( st_fx->Opt_SC_VBR_fx != 0)) || + ((LE_16(last_7k2_coder_type_fx, UNVOICED) ) && (LT_32(L_snr_outlier,MAX_SNR_OUTLIER_2_FX)) && ( st_fx->Opt_SC_VBR_fx == 0 ) ) ) { /* thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); */ @@ -1091,48 +1143,48 @@ Word16 wb_vad_fx( { flag_he1 = 1; move16(); /* he1 primary decision */ - st_fx->nb_active_frames_he1_fx = add(st_fx->nb_active_frames_he1_fx,1); /* Counter of consecutive active speech frames */ + hVAD->nb_active_frames_he1_fx = add(hVAD->nb_active_frames_he1_fx,1); /* Counter of consecutive active speech frames */ - IF ( GE_16(st_fx->nb_active_frames_he1_fx,ACTIVE_FRAMES_FX)) + IF ( GE_16(hVAD->nb_active_frames_he1_fx,ACTIVE_FRAMES_FX)) { - st_fx->nb_active_frames_he1_fx = ACTIVE_FRAMES_FX; + hVAD->nb_active_frames_he1_fx = ACTIVE_FRAMES_FX; move16(); - st_fx->hangover_cnt_he1_fx = 0; + hVAD->hangover_cnt_he1_fx = 0; move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ } /* inside HO period */ test(); - if ( sub(st_fx->hangover_cnt_he1_fx, HANGOVER_LONG_HE_FX) < 0 && st_fx->hangover_cnt_he1_fx != 0 ) + if ( sub(hVAD->hangover_cnt_he1_fx, HANGOVER_LONG_HE_FX) < 0 &&hVAD->hangover_cnt_he1_fx != 0 ) { - st_fx->hangover_cnt_he1_fx = add(st_fx->hangover_cnt_he1_fx ,1); + hVAD->hangover_cnt_he1_fx = add(hVAD->hangover_cnt_he1_fx ,1); } - if ( st_fx->soft_hangover_fx > 0 ) + if ( hVAD->soft_hangover_fx > 0 ) { - st_fx->soft_hangover_fx = sub(st_fx->soft_hangover_fx ,1); + hVAD->soft_hangover_fx = sub(hVAD->soft_hangover_fx ,1); } } ELSE { /* Reset the counter of speech frames necessary to start hangover algorithm */ - st_fx->nb_active_frames_he1_fx = 0; + hVAD->nb_active_frames_he1_fx = 0; move16(); } - IF ( GT_16(st_fx->voiced_burst_fx, 3)) + IF ( GT_16(hVAD->voiced_burst_fx, 3)) { - IF ( LT_16(st_fx->bcg_flux_fx, 640)) /* Q4 */ + IF ( LT_16(hVAD->bcg_flux_fx, 640)) /* Q4 */ { - st_fx->soft_hangover_fx = hangover_sf_tbl_fx[add(snr_idx,3)]; + hVAD->soft_hangover_fx = hangover_sf_tbl_fx[add(snr_idx,3)]; move16(); } ELSE { - st_fx->soft_hangover_fx = hangover_sf_tbl_fx[snr_idx]; + hVAD->soft_hangover_fx = hangover_sf_tbl_fx[snr_idx]; move16(); } } @@ -1141,7 +1193,7 @@ Word16 wb_vad_fx( hangover_hd = hangover_hd_tbl_fx[snr_idx]; move16(); - IF ( LT_16(st_fx->bcg_flux_fx, 640)) + IF ( LT_16(hVAD->bcg_flux_fx, 640)) { hangover_hd = add(shr(hangover_hd,1), 1); move16(); @@ -1149,23 +1201,23 @@ Word16 wb_vad_fx( /* VAD hangover for he1 */ test(); - IF ( flag_he1 == 0 && st_fx->soft_hangover_fx > 0 ) + IF ( flag_he1 == 0 && hVAD->soft_hangover_fx > 0 ) { IF ( GT_32(L_mssnr_hov, L_vad_thr)) { flag_he1 = 1; move16(); - st_fx->soft_hangover_fx=sub(st_fx->soft_hangover_fx,1); + hVAD->soft_hangover_fx=sub(hVAD->soft_hangover_fx,1); } ELSE { - st_fx->soft_hangover_fx=0; + hVAD->soft_hangover_fx=0; move16(); } - if( st_fx->soft_hangover_fx < 0) + if( hVAD->soft_hangover_fx < 0) { - st_fx->soft_hangover_fx=0; + hVAD->soft_hangover_fx=0; move16(); } } @@ -1173,85 +1225,85 @@ Word16 wb_vad_fx( test(); test(); IF ( (flag_he1 == 0) - && (LT_16(st_fx->hangover_cnt_he1_fx, hangover_hd) ) - && (st_fx->soft_hangover_fx == 0 ) ) + && (LT_16(hVAD->hangover_cnt_he1_fx, hangover_hd) ) + && (hVAD->soft_hangover_fx == 0 ) ) { flag_he1 = 1; move16(); - st_fx->hangover_cnt_he1_fx = add(st_fx->hangover_cnt_he1_fx,1); + hVAD->hangover_cnt_he1_fx = add(hVAD->hangover_cnt_he1_fx,1); } /* Calculate background stationarity */ test(); - IF ( flag_he1 == 0 && st_fx->first_noise_updt_fx > 0 ) + IF ( flag_he1 == 0 && hNoiseEst->first_noise_updt_fx > 0 ) { - IF ( GT_16(snr_sumt, st_fx->bcg_flux_fx)) + IF ( GT_16(snr_sumt, hVAD->bcg_flux_fx)) { - IF ( st_fx->bcg_flux_init_fx-- > 0 ) + IF (hVAD->bcg_flux_init_fx-- > 0 ) { - IF ( GT_16(snr_sumt,add(st_fx->bcg_flux_fx,800))) + IF ( GT_16(snr_sumt,add(hVAD->bcg_flux_fx,800))) { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,29491),add(st_fx->bcg_flux_fx,800),3277); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,29491),add(hVAD->bcg_flux_fx,800),3277); /*Q4 */ } ELSE { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,29491),snr_sumt,3277); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,29491),snr_sumt,3277); /*Q4 */ } } ELSE { - IF ( GT_16(snr_sumt,add(st_fx->bcg_flux_fx,160))) + IF ( GT_16(snr_sumt,add(hVAD->bcg_flux_fx,160))) { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32440),add(st_fx->bcg_flux_fx,160),328); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32440),add(hVAD->bcg_flux_fx,160),328); /*Q4 */ } ELSE { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt;*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32440),snr_sumt,328); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32440),snr_sumt,328); /*Q4 */ } } } ELSE { - IF ( st_fx->bcg_flux_init_fx-- > 0 ) + IF (hVAD->bcg_flux_init_fx-- > 0 ) { - IF ( LT_16(snr_sumt,sub(st_fx->bcg_flux_fx,480))) + IF ( LT_16(snr_sumt,sub(hVAD->bcg_flux_fx,480))) { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,31130),sub(st_fx->bcg_flux_fx,480),1638); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,31130),sub(hVAD->bcg_flux_fx,480),1638); /*Q4 */ } ELSE { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt;*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,31130),snr_sumt,1638); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,31130),snr_sumt,1638); /*Q4 */ } } ELSE { - IF ( LT_16(snr_sumt,sub(st_fx->bcg_flux_fx,160))) + IF ( LT_16(snr_sumt,sub(hVAD->bcg_flux_fx,160))) { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32742),sub(st_fx->bcg_flux_fx,160),26); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32742),sub(hVAD->bcg_flux_fx,160),26); /*Q4 */ } ELSE { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt;*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32742),snr_sumt,26); /*Q4 */ + hVAD->bcg_flux_fx = mac_r(L_mult(hVAD->bcg_flux_fx,32742),snr_sumt,26); /*Q4 */ } } } - st_fx->bcg_flux_init_fx = s_max(st_fx->bcg_flux_init_fx,0); + hVAD->bcg_flux_init_fx = s_max(hVAD->bcg_flux_init_fx,0); } flag = 0; move16(); - *localVAD = 0; + st_fx->localVAD = 0; move16(); /* if ( snr_sum > thr1 && flag_he1 == 1 ) *//* Speech present */ test(); @@ -1260,55 +1312,51 @@ Word16 wb_vad_fx( { flag = 1; move16(); - *localVAD = 1; + st_fx->localVAD = 1; move16(); - st_fx->nb_active_frames_fx = add(st_fx->nb_active_frames_fx,1); /* Counter of consecutive active speech frames */ + hVAD->nb_active_frames_fx = add(hVAD->nb_active_frames_fx,1); /* Counter of consecutive active speech frames */ - IF ( GE_16(st_fx->nb_active_frames_fx,ACTIVE_FRAMES_FX)) + IF ( GE_16(hVAD->nb_active_frames_fx,ACTIVE_FRAMES_FX)) { - st_fx->nb_active_frames_fx = ACTIVE_FRAMES_FX; + hVAD->nb_active_frames_fx = ACTIVE_FRAMES_FX; move16(); - st_fx->hangover_cnt_fx = 0; + hVAD->hangover_cnt_fx = 0; move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ } /* inside HO period */ test(); - if( LT_16(st_fx->hangover_cnt_fx,HANGOVER_LONG_FX) - && st_fx->hangover_cnt_fx != 0 ) + if( LT_16(hVAD->hangover_cnt_fx,HANGOVER_LONG_FX) + &&hVAD->hangover_cnt_fx != 0 ) { - st_fx->hangover_cnt_fx = add(st_fx->hangover_cnt_fx,1); + hVAD->hangover_cnt_fx = add(hVAD->hangover_cnt_fx,1); } } ELSE { /* Reset the counter of speech frames necessary to start hangover algorithm */ - st_fx->nb_active_frames_fx = 0; + hVAD->nb_active_frames_fx = 0; move16(); - if( LT_16(st_fx->hangover_cnt_fx,HANGOVER_LONG_FX)) /* inside HO period */ + if( LT_16(hVAD->hangover_cnt_fx,HANGOVER_LONG_FX)) /* inside HO period */ { - st_fx->hangover_cnt_fx = add(st_fx->hangover_cnt_fx,1); + hVAD->hangover_cnt_fx = add(hVAD->hangover_cnt_fx,1); } - IF( LE_16(st_fx->hangover_cnt_fx, hangover_short)) /* "hard" hangover */ + IF( LE_16(hVAD->hangover_cnt_fx, hangover_short)) /* "hard" hangover */ { test(); test(); - if ( (LT_16(lp_snr,th_clean)) - && (st_fx->Opt_SC_VBR_fx != 0 ) - && (GE_16(st_fx->hangover_cnt_fx, 2)) ) + if (EQ_16(st_fx->element_mode, EVS_MONO) && (LT_16(lp_snr,th_clean)) && (st_fx->Opt_SC_VBR_fx != 0 ) && (GE_16(hVAD->hangover_cnt_fx, 2)) ) { *noisy_speech_HO = 1; move16(); } test(); test(); - if ( (GE_16(lp_snr,th_clean)) - && (st_fx->Opt_SC_VBR_fx != 0 ) - && (GE_16(st_fx->hangover_cnt_fx, 2) ) ) + if (EQ_16(st_fx->element_mode, EVS_MONO) && (GE_16(lp_snr,th_clean)) && (st_fx->Opt_SC_VBR_fx != 0 ) && (GE_16(hVAD->hangover_cnt_fx, 2) ) ) { *clean_speech_HO = 1; move16(); @@ -1351,34 +1399,34 @@ Word16 wb_vad_fx( move16(); } - *localVAD = 0; + st_fx->localVAD = 0; move16(); /* safety inits for fx */ IF ( GT_16(snr_sum,thr1)) /* Speech present, possibly in hangover */ { - st_fx->nb_active_frames_fx = add(st_fx->nb_active_frames_fx,1); /* Counter of consecutive active speech frames */ - IF ( GE_16(st_fx->nb_active_frames_fx,ACTIVE_FRAMES_FX)) + hVAD->nb_active_frames_fx = add(hVAD->nb_active_frames_fx,1); /* Counter of consecutive active speech frames */ + IF ( GE_16(hVAD->nb_active_frames_fx,ACTIVE_FRAMES_FX)) { - st_fx->nb_active_frames_fx = ACTIVE_FRAMES_FX; + hVAD->nb_active_frames_fx = ACTIVE_FRAMES_FX; move16(); - st_fx->hangover_cnt_fx = 0; + hVAD->hangover_cnt_fx = 0; move16();/* Reset the counter of hangover frames after at least "active_frames" speech frames */ } - *localVAD = 1; + st_fx->localVAD = 1; move16(); } ELSE { - st_fx->nb_active_frames_fx = 0; + hVAD->nb_active_frames_fx = 0; move16(); /* Reset the counter of speech frames necessary to start hangover algorithm */ - /* *localVAD = 0; move16(); */ /* set above */ + /* st_fx->localVAD = 0; move16(); */ /* set above */ } thr1_nb_mod = thr1; move16(); /* thr1 may be adjusted after this point */ - IF( LT_16(st_fx->hangover_cnt_fx,HANGOVER_LONG_NB_FX)) + IF( LT_16(hVAD->hangover_cnt_fx,HANGOVER_LONG_NB_FX)) { - st_fx->hangover_cnt_fx = add(st_fx->hangover_cnt_fx,1); + hVAD->hangover_cnt_fx = add(hVAD->hangover_cnt_fx,1); IF( LT_16(lp_snr, 4864 )) /*19.0f Q8*/ /* very low SNR */ { @@ -1423,9 +1471,13 @@ Word16 wb_vad_fx( { flag = 1; move16(); - *localVAD = 0; + st_fx->localVAD = 0; move16(); - *NB_speech_HO = 1; + + if (EQ_16(st_fx->element_mode, EVS_MONO)) + { + *NB_speech_HO = 1; + } move16(); } thr1 = thr1_nb_mod ; @@ -1435,7 +1487,7 @@ Word16 wb_vad_fx( /* *flag_noisy_speech_snr is a Word8 parameter */ - *flag_noisy_speech_snr = 0; + *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_ -> this initialisation is not done here in float */ move16(); IF( vad_bwidth_fx != NB ) { @@ -1454,95 +1506,98 @@ Word16 wb_vad_fx( } } + if (st_fx->hSC_VBR != NULL) + { /* SC-VBR */ - st_fx->vadsnr_fx = snr_sum; - move16(); /* for ppp, voiced_enc */ - st_fx->vadnoise_fx = thr1; - move16(); /* used in nb for find_uv */ + st_fx->hSC_VBR->vadsnr_fx = snr_sum; + move16(); /* for ppp, voiced_enc */ + st_fx->hSC_VBR->vadnoise_fx = thr1; + move16(); /* used in nb for find_uv */ + } /* Updates */ - st_fx->prim_act_quick_fx = mult_r(26214,st_fx->prim_act_quick_fx); /*Q15 */ + hVAD->prim_act_quick_fx = mult_r(26214,hVAD->prim_act_quick_fx); /*Q15 */ - if(*localVAD != 0) + if(st_fx->localVAD != 0) { - st_fx->prim_act_quick_fx = add(6554,st_fx->prim_act_quick_fx ); /*Q15 */ + hVAD->prim_act_quick_fx = add(6554,hVAD->prim_act_quick_fx ); /*Q15 */ } - st_fx->prim_act_slow_fx = mult_r(32440,st_fx->prim_act_slow_fx); /*Q15 */ + hVAD->prim_act_slow_fx = mult_r(32440,hVAD->prim_act_slow_fx); /*Q15 */ - if(*localVAD != 0) + if(st_fx->localVAD != 0) { - st_fx->prim_act_slow_fx = add(328, st_fx->prim_act_slow_fx ); /*Q15 */ + hVAD->prim_act_slow_fx = add(328, hVAD->prim_act_slow_fx ); /*Q15 */ } - tmp = st_fx->prim_act_slow_fx; + tmp = hVAD->prim_act_slow_fx; move16(); - if (LE_16(st_fx->prim_act_quick_fx,st_fx->prim_act_slow_fx)) + if (LE_16(hVAD->prim_act_quick_fx,hVAD->prim_act_slow_fx)) { - tmp=st_fx->prim_act_quick_fx; + tmp=hVAD->prim_act_quick_fx; move16(); } /*st->prim_act = 0.1f * tmp + (1.0f-0.1f)* st->prim_act;*/ - st_fx->prim_act_fx = mac_r(L_mult(3277,tmp),29491,st_fx->prim_act_fx); + hVAD->prim_act_fx = mac_r(L_mult(3277,tmp),29491,hVAD->prim_act_fx); - st_fx->prim_act_quick_he_fx = mult_r(26214,st_fx->prim_act_quick_he_fx); /*Q15 */ + hVAD->prim_act_quick_he_fx = mult_r(26214,hVAD->prim_act_quick_he_fx); /*Q15 */ if(*localVAD_HE_SAD != 0) { - st_fx->prim_act_quick_he_fx = add(6554,st_fx->prim_act_quick_he_fx ); /*Q15 */ + hVAD->prim_act_quick_he_fx = add(6554,hVAD->prim_act_quick_he_fx ); /*Q15 */ } - st_fx->prim_act_slow_he_fx = mult_r(32440,st_fx->prim_act_slow_he_fx); /*Q15 */ + hVAD->prim_act_slow_he_fx = mult_r(32440,hVAD->prim_act_slow_he_fx); /*Q15 */ if(*localVAD_HE_SAD != 0) { - st_fx->prim_act_slow_he_fx = add(328, st_fx->prim_act_slow_he_fx ); /*Q15 */ + hVAD->prim_act_slow_he_fx = add(328, hVAD->prim_act_slow_he_fx ); /*Q15 */ } - tmp = st_fx->prim_act_slow_he_fx; + tmp = hVAD->prim_act_slow_he_fx; move16(); - if (LE_16(st_fx->prim_act_quick_he_fx,st_fx->prim_act_slow_he_fx)) + if (LE_16(hVAD->prim_act_quick_he_fx,hVAD->prim_act_slow_he_fx)) { - tmp = st_fx->prim_act_quick_he_fx; + tmp = hVAD->prim_act_quick_he_fx; move16(); } - st_fx->prim_act_he_fx = mac_r(L_mult(3277,tmp),29491,st_fx->prim_act_he_fx); + hVAD->prim_act_he_fx = mac_r(L_mult(3277,tmp),29491, hVAD->prim_act_he_fx); - if (L_and(st_fx->L_vad_flag_reg_H_fx, (Word32) 0x40000L) != 0) /* 0x4000L = 0x01L << 18 */ + if (L_and(hVAD->L_vad_flag_reg_H_fx, (Word32) 0x40000L) != 0) /* 0x4000L = 0x01L << 18 */ { - st_fx->vad_flag_cnt_50_fx = sub(st_fx->vad_flag_cnt_50_fx,1); + hVAD->vad_flag_cnt_50_fx = sub(hVAD->vad_flag_cnt_50_fx,1); } - st_fx->L_vad_flag_reg_H_fx = L_shl(L_and(st_fx->L_vad_flag_reg_H_fx, (Word32) 0x3fffffffL ), 1); + hVAD->L_vad_flag_reg_H_fx = L_shl(L_and(hVAD->L_vad_flag_reg_H_fx, (Word32) 0x3fffffffL ), 1); - if (L_and(st_fx->L_vad_flag_reg_L_fx, (Word32) 0x40000000L) != 0) + if (L_and(hVAD->L_vad_flag_reg_L_fx, (Word32) 0x40000000L) != 0) { - st_fx->L_vad_flag_reg_H_fx = L_or(st_fx->L_vad_flag_reg_H_fx, 0x01L); + hVAD->L_vad_flag_reg_H_fx = L_or(hVAD->L_vad_flag_reg_H_fx, 0x01L); } - st_fx->L_vad_flag_reg_L_fx = L_shl(L_and(st_fx->L_vad_flag_reg_L_fx, (Word32) 0x3fffffffL ), 1); + hVAD->L_vad_flag_reg_L_fx = L_shl(L_and(hVAD->L_vad_flag_reg_L_fx, (Word32) 0x3fffffffL ), 1); IF ( flag != 0 ) /* should not include the extra DTX hangover */ { - st_fx->L_vad_flag_reg_L_fx = L_or(st_fx->L_vad_flag_reg_L_fx, 0x01L); - st_fx->vad_flag_cnt_50_fx = add(st_fx->vad_flag_cnt_50_fx, 1); + hVAD->L_vad_flag_reg_L_fx = L_or(hVAD->L_vad_flag_reg_L_fx, 0x01L); + hVAD->vad_flag_cnt_50_fx = add(hVAD->vad_flag_cnt_50_fx, 1); } - if (L_and(st_fx->L_vad_prim_reg_fx, (Word32) 0x8000L) != 0) /* 0x8000L = 1L << 15 */ + if (L_and(hVAD->L_vad_prim_reg_fx, (Word32) 0x8000L) != 0) /* 0x8000L = 1L << 15 */ { - st_fx->vad_prim_cnt_16_fx = sub(st_fx->vad_prim_cnt_16_fx,1); + hVAD->vad_prim_cnt_16_fx = sub(hVAD->vad_prim_cnt_16_fx,1); } - st_fx->L_vad_prim_reg_fx = L_shl(L_and(st_fx->L_vad_prim_reg_fx, (Word32) 0x3fffffffL ), 1); + hVAD->L_vad_prim_reg_fx = L_shl(L_and(hVAD->L_vad_prim_reg_fx, (Word32) 0x3fffffffL ), 1); - IF ( *localVAD != 0 ) + IF ( st_fx->localVAD != 0 ) { - st_fx->L_vad_prim_reg_fx = L_or(st_fx->L_vad_prim_reg_fx, 0x01L); - st_fx->vad_prim_cnt_16_fx = add(st_fx->vad_prim_cnt_16_fx,1); + hVAD->L_vad_prim_reg_fx = L_or(hVAD->L_vad_prim_reg_fx, 0x01L); + hVAD->vad_prim_cnt_16_fx = add(hVAD->vad_prim_cnt_16_fx,1); } return flag; diff --git a/lib_enc/vad_param_updt_fx.c b/lib_enc/vad_param_updt_fx.c index 68caf7e..bdd6a74 100644 --- a/lib_enc/vad_param_updt_fx.c +++ b/lib_enc/vad_param_updt_fx.c @@ -1,12 +1,12 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - +#include #include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ -#include "stl.h" +#include "ivas_stat_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * vad_param_updt() @@ -15,162 +15,178 @@ *--------------------------------------------------------------------*/ void vad_param_updt_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 pitch[3], /* i : open loop pitch lag for each half-frame Q0*/ - Word16 voicing[3], /* i : maximum normalized correlation for each half-frame Q15*/ - const Word16 old_pitch1,/* i : OL pitch value from last frame */ - Word16 corr_shift, /* i : correlation shift Q15*/ - Word16 vad_flag, /* i : vad flag Q0*/ - const Word16 Az[] /* i: a coeffs Q12 */ + Encoder_State_fx *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : OL pitch value from last frame */ + const Word16 corr_shift, /* i : correlation shift Q15*/ + const Word16 corr_shiftR, /* i : correlation shift */ + const Word16 Az[], /* i: a coeffs Q12 */ + FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ + const Word16 n_channels /* i : number of channels */ ) { - Word16 voice_tmp, pitch_tmp; + Word16 voice_tmp, pitch_tmp; Word32 L_tmp; - - Word16 refl[M+1]; Word16 tmp1,tmp2; Word16 tmp_active_flag; + Word16 i, ini_frame, corr_shift_temp[2]; + VAD_HANDLE hVAD; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + + corr_shift_temp[0] = corr_shift; + corr_shift_temp[1] = corr_shiftR; + move16(); move16(); - IF( !st_fx->Opt_AMR_WB_fx ) + hVAD = st_fx->hVAD; + ini_frame = st_fx->ini_frame_fx; + move16();move16(); + + IF (hFrontVad != NULL) { - /* fix explanation - , after function dtx_fx, the "vad_flag" parameter can not be used for SID scheduling purposes any longer - as dtx_fx can schedules active frames even if the initial analyzed vad_flag is 0 ) - in the worst case without the fix an active frame could be classified as SID frame, quite/very unlikley though - */ - tmp1 = vad_flag; - move16(); /* kill MSVC warning */ - tmp_active_flag = 0; - move16(); - test(); - if( (NE_32(st_fx->core_brate_fx, (Word32)SID_2k40))&&(st_fx->core_brate_fx!=0)) /* Note, core_brate_fx can be -1 */ + hVAD = hFrontVad[0]->hVAD; + ini_frame = hFrontVad[0]->ini_frame; + move16(); move16(); + } + FOR(i = 0; i < n_channels; i++) + { + if (EQ_16(i, 1)) { - tmp_active_flag = 1; - move16(); /* reqires active coding according to dtx_fx logic */ + hVAD = hFrontVad[1]->hVAD; + move16(); } - test(); - test(); - IF( (st_fx->Opt_DTX_ON_fx != 0) && (tmp_active_flag == 0) && ( GT_16(st_fx->ini_frame_fx,3))) - - + IF(!st_fx->Opt_AMR_WB_fx) { - /* update the counter of consecutive inactive frames in DTX */ - st_fx->consec_inactive_fx = add(st_fx->consec_inactive_fx,1); - IF( GT_16(st_fx->consec_inactive_fx,5)) + /* fix explanation + , after function dtx_fx, the "vad_flag" parameter can not be used for SID scheduling purposes any longer + as dtx_fx can schedules active frames even if the initial analyzed vad_flag is 0 ) + in the worst case without the fix an active frame could be classified as SID frame, quite/very unlikley though + */ + tmp_active_flag = 0; + move16(); + test(); + if ((NE_32(st_fx->core_brate_fx, (Word32)SID_2k40)) && (st_fx->core_brate_fx != 0)) /* Note, core_brate_fx can be -1 */ { - st_fx->consec_inactive_fx = 5; - move16(); + tmp_active_flag = 1; + move16(); /* reqires active coding according to dtx_fx logic */ } + test(); + test(); + IF((st_fx->Opt_DTX_ON_fx != 0) && (tmp_active_flag == 0) && (GT_16(ini_frame, 3))) - IF( EQ_16(st_fx->consec_inactive_fx,5)) - { - /* compute spectral tilt parameter */ - a2rc_fx( &Az[1], refl, M ); /* cast to kill MSVC warning */ - /* i: Az in Q12 */ - /* o: refl in Q15 */ - IF( EQ_16(st_fx->spectral_tilt_reset_fx,1)) + { + /* update the counter of consecutive inactive frames in DTX */ + hVAD->consec_inactive_fx = add(hVAD->consec_inactive_fx, 1); + IF(GT_16(hVAD->consec_inactive_fx, 5)) { - st_fx->spectral_tilt_reset_fx = 0; + hVAD->consec_inactive_fx = 5; move16(); - st_fx->running_avg_fx = refl[0]; - move16(); /*Q15*/ - st_fx->ra_deltasum_fx = 0; - move16(); /*Q15*/ } - /* st_fx->ra_deltasum_fx += (0.80f * st_fx->running_avg_fx + 0.20f * refl[0]) - st_fx->running_avg_fx; - st_fx->running_avg_fx = 0.80f * st_fx->running_avg_fx + 0.20f * refl[0]; */ - tmp1 = mult(6553, st_fx->running_avg_fx); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/ - tmp2 = mult(6553, refl[0]); - st_fx->ra_deltasum_fx = add(st_fx->ra_deltasum_fx, sub(tmp2,tmp1)); - move16(); - - tmp1 = mult(26214, st_fx->running_avg_fx); - st_fx->running_avg_fx = add(tmp1,tmp2); - move16(); - - IF( GT_16(abs_s(st_fx->ra_deltasum_fx), 6553)) /*0.2 in Q15*/ + IF(EQ_16(hVAD->consec_inactive_fx, 5)) { - st_fx->spectral_tilt_reset_fx = 1; - move16(); - st_fx->running_avg_fx = 0; + /* compute spectral tilt parameter */ + a2rc_fx(&Az[1], refl, M); /* cast to kill MSVC warning */ + /* i: Az in Q12 */ + /* o: refl in Q15 */ + + IF(EQ_16(hVAD->spectral_tilt_reset_fx, 1)) + { + hVAD->spectral_tilt_reset_fx = 0; + move16(); + hVAD->running_avg_fx = refl[0]; + move16(); /*Q15*/ + hVAD->ra_deltasum_fx = 0; + move16(); /*Q15*/ + } + + /* st_fx->ra_deltasum_fx += (0.80f * st_fx->running_avg_fx + 0.20f * refl[0]) - st_fx->running_avg_fx; + st_fx->running_avg_fx = 0.80f * st_fx->running_avg_fx + 0.20f * refl[0]; */ + tmp1 = mult(6553, hVAD->running_avg_fx); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/ + tmp2 = mult(6553, refl[0]); + hVAD->ra_deltasum_fx = add(hVAD->ra_deltasum_fx, sub(tmp2, tmp1)); move16(); - st_fx->ra_deltasum_fx = 0; - move16(); - st_fx->trigger_SID_fx = 1; + + tmp1 = mult(26214, hVAD->running_avg_fx); + hVAD->running_avg_fx = add(tmp1, tmp2); move16(); + + IF(GT_16(abs_s(hVAD->ra_deltasum_fx), 6553)) /*0.2 in Q15*/ + { + hVAD->spectral_tilt_reset_fx = 1; + move16(); + hVAD->running_avg_fx = 0; + move16(); + hVAD->ra_deltasum_fx = 0; + move16(); + hVAD->trigger_SID_fx = 1; + move16(); + } } } - } - ELSE - { - st_fx->trigger_SID_fx = 0; - move16(); - st_fx->consec_inactive_fx = 0; - move16(); - } - - IF( st_fx->trigger_SID_fx == 1 ) - { - IF( st_fx->cng_cnt_fx >= 8 ) + ELSE { - /* Declare SID frame due to spectral tilt changes */ - st_fx->cnt_SID_fx = 1; - move16(); - st_fx->core_brate_fx = SID_2k40; + hVAD->trigger_SID_fx = 0; move16(); - st_fx->trigger_SID_fx = 0; + hVAD->consec_inactive_fx = 0; move16(); } - ELSE IF ( st_fx->core_brate_fx == SID_2k40 ) + + IF( EQ_16(hVAD->trigger_SID_fx, 1)) { - /* SID fame has already been declared before */ - st_fx->trigger_SID_fx = 0; - move16(); + IF(GE_16(hDtxEnc->cng_cnt_fx, 8)) + { + /* Declare SID frame due to spectral tilt changes */ + hDtxEnc->cnt_SID_fx = 1; + move16(); + st_fx->core_brate_fx = SID_2k40; + move16(); + hVAD->trigger_SID_fx = 0; + move16(); + } + ELSE IF(EQ_32(st_fx->core_brate_fx, SID_2k40)) + { + /* SID fame has already been declared before */ + hVAD->trigger_SID_fx = 0; + move16(); + } } } - } - /* (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift */ - L_tmp = L_mult(voicing[0], 10923); - L_tmp = L_mac(L_tmp, voicing[1], 10923); - L_tmp = L_mac(L_tmp, voicing[2], 10923); /*Q15 */ - L_tmp = L_mac(L_tmp, corr_shift, 32767); /*Q15 */ - voice_tmp = round_fx(L_tmp); /*Q15 */ + /* (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift */ + L_tmp = L_mult(st_fx->voicing_fx[0], 10923); + L_tmp = L_mac(L_tmp, st_fx->voicing_fx[1], 10923); + L_tmp = L_mac(L_tmp, st_fx->voicing_fx[2], 10923); /*Q15 */ + L_tmp = L_mac(L_tmp, corr_shift_temp[i], 32767); /*Q15 */ + voice_tmp = round_fx(L_tmp); /*Q15 */ - /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */ - pitch_tmp = abs_s( sub( pitch[0], old_pitch1 ) ); /*Q0 */ - pitch_tmp = add(pitch_tmp,abs_s(sub(pitch[1],pitch[0]))); /*Q0 */ - pitch_tmp = add(pitch_tmp,abs_s(sub(pitch[2],pitch[1]))); /*Q0 */ + /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */ + pitch_tmp = abs_s(sub(st_fx->pitch_fx[0], old_pitch1)); /*Q0 */ + pitch_tmp = add(pitch_tmp, abs_s(sub(st_fx->pitch_fx[1], st_fx->pitch_fx[0]))); /*Q0 */ + pitch_tmp = add(pitch_tmp, abs_s(sub(st_fx->pitch_fx[2], st_fx->pitch_fx[1]))); /*Q0 */ - /* if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 && - (short)(abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1])) / 3 < 14 ) - { - (st->voiced_burst)++; - } else { - st->voiced_burst = 0; - } */ - - st_fx->voiced_burst_fx = add( st_fx->voiced_burst_fx,1); - move16(); - test(); - if ( ( LE_16(voice_tmp,21299)) /* 0.65 in Q15 */ - || ( GE_16(pitch_tmp,42) ) ) /*3*14 = 42 Q0 */ - { - st_fx->voiced_burst_fx = 0; - move16(); - } + /* if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 && + (short)(abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1])) / 3 < 14 ) + { + (st->voiced_burst)++; + } else { + st->voiced_burst = 0; + } */ - /* Update previous voicing value for next frame use */ - /* st->voicing_old = (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift; */ - st_fx->voicing_old_fx = voice_tmp; - move16(); + hVAD->voiced_burst_fx = add(hVAD->voiced_burst_fx, 1); + move16(); + test(); + if ((LE_16(voice_tmp, 21299)) /* 0.65 in Q15 */ + || (GE_16(pitch_tmp, 42))) /*3*14 = 42 Q0 */ + { + hVAD->voiced_burst_fx = 0; + move16(); + } + } return; diff --git a/lib_enc/vad_proc.c b/lib_enc/vad_proc.c index b8554d3..8560603 100644 --- a/lib_enc/vad_proc.c +++ b/lib_enc/vad_proc.c @@ -3,166 +3,167 @@ ====================================================================================*/ -#include -#include -#include -#include - - +#include +#include "options.h" #include "basop_util.h" -#include "stl.h" #include "vad_basop.h" #include "prot_fx.h" #include "stat_enc_fx.h" #include "rom_enc_fx.h" - -Word16 vad_init(T_CldfbVadState *vad_state) +/*-------------------------------------------------------------------* + * vad_init() + * + * + *-------------------------------------------------------------------*/ +Word16 vad_init( + VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ +) { Word16 i = 0; - IF(vad_state == NULL) + IF(hVAD_CLDFB == NULL) { return -1; } - vad_state->frameloop=0; + hVAD_CLDFB->frameloop=0; move16(); - vad_state->continuous_noise_num = 0; + hVAD_CLDFB->continuous_noise_num = 0; move16(); - vad_state->continuous_speech_num = 0; + hVAD_CLDFB->continuous_speech_num = 0; move16(); - vad_state->continuous_speech_num2 = 0; + hVAD_CLDFB->continuous_speech_num2 = 0; move16(); - vad_state->fg_energy_est_start = L_deposit_l(0); - vad_state->speech_flag = 0; + hVAD_CLDFB->fg_energy_est_start = L_deposit_l(0); + hVAD_CLDFB->speech_flag = 0; move16(); - vad_state->frame_sb_energy_scale = 0; + hVAD_CLDFB->frame_sb_energy_scale = 0; move16(); - vad_state->updateNumWithSnr=0; + hVAD_CLDFB->updateNumWithSnr=0; move16(); - vad_state->update_count = 0; + hVAD_CLDFB->update_count = 0; move16(); - vad_state->warm_hang_num = 0; + hVAD_CLDFB->warm_hang_num = 0; move16(); FOR(i = 0; i < SPEC_AMP_NUM; i++) { - vad_state->smooth_spec_amp[i] = L_deposit_l(0); + hVAD_CLDFB->smooth_spec_amp[i] = L_deposit_l(0); } FOR(i = 0; i < PRE_SNR_NUM; i++) { - vad_state->pre_snr[i] = L_deposit_l(0); + hVAD_CLDFB->pre_snr[i] = L_deposit_l(0); } FOR(i = 0; i < BG_ENG_NUM; i++) { - vad_state->frame_sb_energy[i] = L_deposit_l(0); + hVAD_CLDFB->frame_sb_energy[i] = L_deposit_l(0); } - vad_state->sfm[0] = 28835/* 0.88 Q15 */; + hVAD_CLDFB->sfm[0] = 28835/* 0.88 Q15 */; move16(); - vad_state->sfm[1] = 30146/* 0.92 Q15 */; + hVAD_CLDFB->sfm[1] = 30146/* 0.92 Q15 */; move16(); - vad_state->sfm[2] = 30146/* 0.92 Q15 */; + hVAD_CLDFB->sfm[2] = 30146/* 0.92 Q15 */; move16(); - vad_state->l_silence_snr_count = L_deposit_l(1); - vad_state->l_speech_snr_count = L_deposit_l(1); - vad_state->lt_snr_org = 33554432; + hVAD_CLDFB->l_silence_snr_count = L_deposit_l(1); + hVAD_CLDFB->l_speech_snr_count = L_deposit_l(1); + hVAD_CLDFB->lt_snr_org = 33554432; move32(); - vad_state->lf_snr_smooth = 167772155/* 5.0 Q25 */; + hVAD_CLDFB->lf_snr_smooth = 167772155/* 5.0 Q25 */; move32(); - vad_state->fg_energy = 1073741824; + hVAD_CLDFB->fg_energy = 1073741824; move32(); - vad_state->fg_energy_scale = 41; + hVAD_CLDFB->fg_energy_scale = 41; move16(); - vad_state->bg_energy = 1073741824; + hVAD_CLDFB->bg_energy = 1073741824; move32(); - vad_state->bg_energy_scale = 57; + hVAD_CLDFB->bg_energy_scale = 57; move16(); - vad_state->lt_noise_sp_center_diff_counter = L_deposit_l(4); + hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_deposit_l(4); - vad_state->t_bg_energy = 1374389535; + hVAD_CLDFB->t_bg_energy = 1374389535; move32(); - vad_state->scale_t_bg_energy = 37; + hVAD_CLDFB->scale_t_bg_energy = 37; move16(); - vad_state->t_bg_energy_sum.s16Exp = 37; + hVAD_CLDFB->t_bg_energy_sum.s16Exp = 37; move16(); - vad_state->t_bg_energy_sum.s32Mantissa = 1374389535; + hVAD_CLDFB->t_bg_energy_sum.s32Mantissa = 1374389535; move32(); - vad_state->tbg_energy_count = 1; + hVAD_CLDFB->tbg_energy_count = 1; move16(); - vad_state->fg_energy_count = 16; + hVAD_CLDFB->fg_energy_count = 16; move16(); - vad_state->bg_energy_count = 16; + hVAD_CLDFB->bg_energy_count = 16; move16(); - vad_state->bg_update_count = 0; + hVAD_CLDFB->bg_update_count = 0; move16(); - vad_state->frame_energy_smooth = 1073741824; + hVAD_CLDFB->frame_energy_smooth = 1073741824; move32(); - vad_state->frame_energy_smooth_scale = 30; + hVAD_CLDFB->frame_energy_smooth_scale = 30; move16(); - vad_state->Q_frames_power_32 = 31; + hVAD_CLDFB->Q_frames_power_32 = 31; move16(); - vad_state->lt_bg_highf_eng = 131070/* 2.0 Q16 */; + hVAD_CLDFB->lt_bg_highf_eng = 131070/* 2.0 Q16 */; move16(); - vad_state->lt_noise_sp_center0 = 1841/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center0 = 1841/* 0.4 Q10 */; move16(); - vad_state->lt_noise_sp_center3 = 2046/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center3 = 2046/* 0.4 Q10 */; move16(); - vad_state->music_background_rate = 15073/* 0.46 Q15 */; + hVAD_CLDFB->music_background_rate = 15073/* 0.46 Q15 */; move16(); - vad_state->tonality_rate3 = 15073/* 0.46 Q15 */; + hVAD_CLDFB->tonality_rate3 = 15073/* 0.46 Q15 */; move16(); - vad_state->lt_noise_sp_center_diff_sum = 409/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center_diff_sum = 409/* 0.4 Q10 */; move32(); - vad_state->l_silence_snr = 32768/* 0.5 Q16 */; + hVAD_CLDFB->l_silence_snr = 32768/* 0.5 Q16 */; move32(); - vad_state->l_speech_snr = 327675/* 5.0 Q16 */; + hVAD_CLDFB->l_speech_snr = 327675/* 5.0 Q16 */; move32(); FOR(i = 0; i < SP_CENTER_NUM; i++) { - vad_state->sp_center[i] = 1228/* 1.2 Q10 */; + hVAD_CLDFB->sp_center[i] = 1228/* 1.2 Q10 */; move16(); } FOR(i = 0; i < STABLE_NUM; i++) { - vad_state->ltd_stable_rate[i] = 2294/* 0.07 Q15 */; + hVAD_CLDFB->ltd_stable_rate[i] = 2294/* 0.07 Q15 */; move16(); } FOR(i = 0; i < BG_ENG_NUM; i++) { - vad_state->sb_bg_energy[i] =1374389535; + hVAD_CLDFB->sb_bg_energy[i] =1374389535; move32(); } - vad_state->sb_bg_energy_scale = 37; + hVAD_CLDFB->sb_bg_energy_scale = 37; move16(); - vad_state->f_tonality_rate[0] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[0] = 7864/* 0.48 Q14 */; move16(); - vad_state->f_tonality_rate[1] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[1] = 7864/* 0.48 Q14 */; move16(); - vad_state->f_tonality_rate[2] = 7864/* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[2] = 7864/* 0.48 Q14 */; move16(); FOR(i = 0; i < PRE_SPEC_DIF_NUM; i++) { - vad_state->pre_spec_low_dif[i] = 4095; + hVAD_CLDFB->pre_spec_low_dif[i] = 4095; move16(); } - vad_state->scale_spec_low_dif = 12; + hVAD_CLDFB->scale_spec_low_dif = 12; move16(); FOR (i = 0; i < 56; i++) { - vad_state->frames_power_32[i] = L_deposit_l(0); + hVAD_CLDFB->frames_power_32[i] = L_deposit_l(0); } @@ -170,86 +171,82 @@ Word16 vad_init(T_CldfbVadState *vad_state) } -void UpdateState(T_CldfbVadState *vad_state, - Word16 vad_flag, - Word32 frame_energy, /*(i) current frame energy*/ - Word16 sacle_sbpower, /*(i) the Scaling of current frame energy*/ - Word32 update_flag, /*(i) current frame update flag*/ - Word16 music_backgound_f, /*(i) backgound music flag*/ - Word32 HB_Power, /*(i) current frame high frequency energy*/ - Word16 HB_Power_Q /*(i) the Scaling of current frame high frequency energy*/ - ,Word32 snr - ) +void UpdateState( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 vad_flag, /* i : VAD flag */ + Word32 frame_energy, /* i : current frame energy */ + Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ + Word32 update_flag, /* i : current frame update flag */ + Word16 music_backgound_f, /* i : background music flag */ + Word32 HB_Power, /* i : current frame high frequency energy */ + Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + Word32 snr +) { Word16 lt_bg_energy_scal; Word32 tmp,tmp2; - tmp = MUL_F(vad_state->frame_energy_smooth, 31129/* 0.95 Q15 */); + tmp = MUL_F(hVAD_CLDFB->frame_energy_smooth, 31129/* 0.95 Q15 */); tmp2 = MUL_F(frame_energy, 26214); - vad_state->frame_energy_smooth = VAD_L_ADD(tmp, vad_state->frame_energy_smooth_scale, tmp2, add(4, sacle_sbpower), <_bg_energy_scal); + hVAD_CLDFB->frame_energy_smooth = VAD_L_ADD(tmp, hVAD_CLDFB->frame_energy_smooth_scale, tmp2, add(4, sacle_sbpower), <_bg_energy_scal); move32(); - vad_state->frame_energy_smooth_scale = lt_bg_energy_scal; + hVAD_CLDFB->frame_energy_smooth_scale = lt_bg_energy_scal; move16(); IF( vad_flag == 0 ) { - vad_state->lt_bg_highf_eng = L_add(MUL_F(vad_state->lt_bg_highf_eng, 31130), L_shr(MUL_F(HB_Power, 1638), sub(HB_Power_Q, lt_bg_highf_eng_Q))); + hVAD_CLDFB->lt_bg_highf_eng = L_add(MUL_F(hVAD_CLDFB->lt_bg_highf_eng, 31130), L_shr(MUL_F(HB_Power, 1638), sub(HB_Power_Q, lt_bg_highf_eng_Q))); } - if(LT_16(vad_state->frameloop, 1000)) + if(LT_16(hVAD_CLDFB->frameloop, 1000)) { - vad_state->frameloop = add(vad_state->frameloop, 1); + hVAD_CLDFB->frameloop = add(hVAD_CLDFB->frameloop, 1); move16(); } - background_update(vad_state, - sacle_sbpower, - frame_energy, - update_flag, - music_backgound_f - ,snr - ); + background_update(hVAD_CLDFB, sacle_sbpower, frame_energy, update_flag, music_backgound_f, snr); + IF( vad_flag== 0) { - vad_state->continuous_speech_num2 = 0; + hVAD_CLDFB->continuous_speech_num2 = 0; move16(); - IF(GT_16(vad_state->continuous_noise_num, 10)) + IF(GT_16(hVAD_CLDFB->continuous_noise_num, 10)) { - vad_state->continuous_speech_num = 0; + hVAD_CLDFB->continuous_speech_num = 0; move16(); } - ELSE IF(GT_32(vad_state->continuous_speech_num, 9)) + ELSE IF(GT_32(hVAD_CLDFB->continuous_speech_num, 9)) { - vad_state->continuous_speech_num = 9; + hVAD_CLDFB->continuous_speech_num = 9; move16(); } - vad_state->continuous_noise_num = add(vad_state->continuous_noise_num, 1); + hVAD_CLDFB->continuous_noise_num = add(hVAD_CLDFB->continuous_noise_num, 1); move16(); - if(GT_16(vad_state->continuous_noise_num, 2048)) + if(GT_16(hVAD_CLDFB->continuous_noise_num, 2048)) { - vad_state->continuous_noise_num = 2048; + hVAD_CLDFB->continuous_noise_num = 2048; move16(); } } ELSE { - vad_state->continuous_noise_num = 0; + hVAD_CLDFB->continuous_noise_num = 0; move16(); - vad_state->continuous_speech_num2 = add(vad_state->continuous_speech_num2, 1); - vad_state->continuous_speech_num = add(vad_state->continuous_speech_num, 1); - if(GT_16(vad_state->continuous_speech_num, 2048)) + hVAD_CLDFB->continuous_speech_num2 = add(hVAD_CLDFB->continuous_speech_num2, 1); + hVAD_CLDFB->continuous_speech_num = add(hVAD_CLDFB->continuous_speech_num, 1); + if(GT_16(hVAD_CLDFB->continuous_speech_num, 2048)) { - vad_state->continuous_speech_num = 2048; + hVAD_CLDFB->continuous_speech_num = 2048; move16(); } - if(GT_16(vad_state->continuous_speech_num2, 2048)) + if(GT_16(hVAD_CLDFB->continuous_speech_num2, 2048)) { - vad_state->continuous_speech_num2 = 2048; + hVAD_CLDFB->continuous_speech_num2 = 2048; move16(); } } @@ -257,19 +254,20 @@ void UpdateState(T_CldfbVadState *vad_state, } -Word16 vad_proc(T_CldfbVadState *vad_st, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: real values */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: imag values */ - Word16 riBuffer_exp, /* i: exponent of real & imag Buffer */ - Word16 *cldfb_addition, /*o: adjust the harmonized hangover */ - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word16 numBands, /* i: band width 1: NB; 2:WB;3:SWB;4:FB*/ - Word16 vada_flag - ) +Word16 vad_proc( + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real values */ + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag values */ + Word16 riBuffer_exp, /* i : exponent of real & imag Buffer */ + Word16 *cldfb_addition, /* o : adjust the harmonized hangover */ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word16 numBands, /* i : band width 1: NB; 2:WB;3:SWB;4:FB*/ + Word16 vada_flag /* i : VAD flag */ +) { Word16 i; - Word16 bandwidth; + Word16 bw_index; Word16 music_backgound_f; Word16 Q_cldfb; Word16 frame_energy2_Q, HB_Power_Q; @@ -291,21 +289,21 @@ Word16 vad_proc(T_CldfbVadState *vad_st, IF(LT_16(numBands, 20)) { - bandwidth = 1; + bw_index = 1; move16(); } ELSE IF(LT_16(numBands, 40)) { - bandwidth = 2; + bw_index = 2; move16(); } ELSE { - bandwidth = 3; + bw_index = 3; move16(); } - vad_st->bw_index = bandwidth; + hVAD_CLDFB->bw_index = bw_index; move16(); FOR (i=0; iframe_sb_energy, - &frame_energy2, - &HB_Power, - &frame_energy, - &sb_power_Q, - &frame_energy2_Q, - &HB_Power_Q, - &frame_energy_Q, - &vad_st->frame_sb_energy_scale, - bandwidth - ); - - subband_FFT(cldfbBufferReal, - cldfbBufferImag, - spec_amp, - 0, - &Q_cldfb - ); - - frame_spec_dif_cor_rate(vad_st, spec_amp, - add(Q_cldfb, 8), - vad_st->f_tonality_rate - ); - - spec_center(enerBuffer, - vad_st->sp_center, - bandwidth, - sb_power_Q - ); - - ltd_stable(vad_st, - vad_st->ltd_stable_rate, - frame_energy, - vad_st->frameloop, - frame_energy_Q - ); - - spec_flatness(spec_amp, - vad_st->smooth_spec_amp, - vad_st->sfm - ); - - bg_music_decision(vad_st, - &music_backgound_f, - frame_energy, - frame_energy_Q - ); - - snr_calc(vad_st, - frame_energy2_Q, - &snr, - &tsnr, - frame_energy2, - bandwidth - ); - - calc_snr_flux(tsnr, - vad_st->pre_snr, - &snr_flux - ); - - calc_lt_snr(vad_st, - <_snr_org, - <_snr, - vad_st->fg_energy, - vad_st->fg_energy_count, - vad_st->bg_energy, - vad_st->bg_energy_count, - bandwidth, - vad_st->lt_noise_sp_center0 - ); - - calc_lf_snr(&vad_st->lf_snr_smooth, - &lf_snr, - vad_st->l_speech_snr, - vad_st->l_speech_snr_count, - vad_st->l_silence_snr, - vad_st->l_silence_snr_count, - vad_st->fg_energy_count, - vad_st->bg_energy_count, - bandwidth - ); - - - vad_flag = comvad_decision(vad_st, - lf_snr, - lt_snr_org, - lt_snr, - snr_flux, - snr, - tsnr, - frame_energy2, - music_backgound_f, - frame_energy2_Q, - cldfb_addition, - vada_flag - ); - - - update_flag = update_decision(vad_st, - frame_energy, - HB_Power, - vad_st->frameloop, - bandwidth, - frame_energy_Q, - HB_Power_Q, - snr, - tsnr, - vad_st->vad_flag_for_bk_update, - music_backgound_f - ); - - - UpdateState(vad_st, - vad_st->vad_flag_for_bk_update, - frame_energy2, - frame_energy2_Q, - update_flag, - music_backgound_f, - HB_Power, - HB_Power_Q - ,snr - ); + est_energy(enerBuffer, enerBuffer_exp, hVAD_CLDFB->frame_sb_energy, &frame_energy2, &HB_Power,&frame_energy, &sb_power_Q, &frame_energy2_Q, &HB_Power_Q, &frame_energy_Q, + &hVAD_CLDFB->frame_sb_energy_scale,bw_index ); + + subband_FFT(cldfbBufferReal, cldfbBufferImag, spec_amp, 0, &Q_cldfb ); + + frame_spec_dif_cor_rate(hVAD_CLDFB, spec_amp, add(Q_cldfb, 8), hVAD_CLDFB->f_tonality_rate ); + + spec_center(enerBuffer, hVAD_CLDFB->sp_center, bw_index, sb_power_Q ); + + ltd_stable(hVAD_CLDFB, hVAD_CLDFB->ltd_stable_rate, frame_energy, hVAD_CLDFB->frameloop, frame_energy_Q ); + + spec_flatness(spec_amp, hVAD_CLDFB->smooth_spec_amp, hVAD_CLDFB->sfm ); + + bg_music_decision(hVAD_CLDFB, &music_backgound_f, frame_energy, frame_energy_Q); + + snr_calc(hVAD_CLDFB, frame_energy2_Q, &snr, &tsnr, frame_energy2, bw_index ); + + calc_snr_flux(tsnr, hVAD_CLDFB->pre_snr, &snr_flux); + + calc_lt_snr(hVAD_CLDFB, <_snr_org, <_snr, hVAD_CLDFB->fg_energy, hVAD_CLDFB->fg_energy_count, hVAD_CLDFB->bg_energy, + hVAD_CLDFB->bg_energy_count, bw_index, hVAD_CLDFB->lt_noise_sp_center0); + + calc_lf_snr(&hVAD_CLDFB->lf_snr_smooth, &lf_snr, hVAD_CLDFB->l_speech_snr, hVAD_CLDFB->l_speech_snr_count, hVAD_CLDFB->l_silence_snr, + hVAD_CLDFB->l_silence_snr_count, hVAD_CLDFB->fg_energy_count, hVAD_CLDFB->bg_energy_count, bw_index ); + + + vad_flag = comvad_decision(hVAD_CLDFB, lf_snr, lt_snr_org, lt_snr,snr_flux, snr, tsnr, frame_energy2, music_backgound_f, frame_energy2_Q, + cldfb_addition, vada_flag); + + + update_flag = update_decision(hVAD_CLDFB, frame_energy, HB_Power, hVAD_CLDFB->frameloop, bw_index,frame_energy_Q, + HB_Power_Q, snr, tsnr, hVAD_CLDFB->vad_flag_for_bk_update, music_backgound_f); + + + UpdateState(hVAD_CLDFB, hVAD_CLDFB->vad_flag_for_bk_update, frame_energy2, frame_energy2_Q, update_flag, music_backgound_f, HB_Power, HB_Power_Q, snr); return vad_flag; diff --git a/lib_enc/vbr_average_rate_fx.c b/lib_enc/vbr_average_rate_fx.c index 927d890..e92be58 100644 --- a/lib_enc/vbr_average_rate_fx.c +++ b/lib_enc/vbr_average_rate_fx.c @@ -2,13 +2,12 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include #include "options.h" /* Compilation switches */ #include "cnst_fx.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "stat_enc_fx.h" /* Static table prototypes */ -#include "stl.h" #define RATEWIN 600 /* length of the rate control window. This is 600 active speech frames. This equals roughly 12s of active speech */ @@ -22,12 +21,12 @@ /* _ (struct DTFS_STRUCTURE_FX) */ /*---------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* st_fx->global_avr_rate_fx Q13 */ -/* st_fx->sum_of_rates_fx Q13 */ -/* st_fx->SNR_THLD_fx Q8 */ -/* st_fx->Q_to_F_fx Q0 */ -/* st_fx->pattern_m_fx Q0 */ -/* st_fx->rate_control_fx Q0 */ +/* hSC_VBR->global_avr_rate_fx Q13 */ +/* hSC_VBR->sum_of_rates_fx Q13 */ +/* hSC_VBR->SNR_THLD_fx Q8 */ +/* hSC_VBR->Q_to_F_fx Q0 */ +/* hSC_VBR->pattern_m_fx Q0 */ +/* hSC_VBR->rate_control_fx Q0 */ /*---------------------------------------------------------------------------------*/ /*/* OUTPUT ARGUMENTS : */ /* _ None */ @@ -37,7 +36,8 @@ /* CALLED FROM : */ /*=================================================================================*/ void update_average_rate_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ + SC_VBR_ENC_HANDLE hSC_VBR, /* i/o: SC-VBR state structure */ + const Word32 core_brate_fx /* i : core bitrate */ ) { Word32 avratetarg_fx; /* target rate for next RATEWIN active frames */ @@ -48,148 +48,148 @@ void update_average_rate_fx( Word16 exp, recip, Qrecip; - IF ( EQ_16(st_fx->numactive_fx,RATEWIN)) /* goes into rate control only the numactive ==RATEWIN. So rate control is triggered after each RATEWIN avtive frames */ + IF ( EQ_16(hSC_VBR->numactive_fx,RATEWIN)) /* goes into rate control only the numactive ==RATEWIN. So rate control is triggered after each RATEWIN avtive frames */ { /* after 1000 blocks of RATEWIN frames, we change the way we control the average rate by using st->global_avr_rate=0.99*st->global_avr_rate+0.01*st->sum_of_rates. This will avoid veriables growing indefinitely while providing a good long term average rate */ - IF ( LT_32(st_fx->frame_cnt_ratewin_fx,1000)) + IF ( LT_32(hSC_VBR->frame_cnt_ratewin_fx,1000)) { - st_fx->frame_cnt_ratewin_fx = add(st_fx->frame_cnt_ratewin_fx,1); + hSC_VBR->frame_cnt_ratewin_fx = add(hSC_VBR->frame_cnt_ratewin_fx,1); /*st->global_avr_rate = (st->global_avr_rate * (st->global_frame_cnt-1) + st->sum_of_rates) / st->global_frame_cnt; */ - exp = norm_s(st_fx->frame_cnt_ratewin_fx); - tmp = shl(st_fx->frame_cnt_ratewin_fx,exp); + exp = norm_s(hSC_VBR->frame_cnt_ratewin_fx); + tmp = shl(hSC_VBR->frame_cnt_ratewin_fx,exp); recip = div_s(16384,tmp); Qrecip = 15-(exp-14); - IF(GT_32(st_fx->frame_cnt_ratewin_fx,1)) + IF(GT_32(hSC_VBR->frame_cnt_ratewin_fx,1)) { - tmp = div_s(sub(st_fx->frame_cnt_ratewin_fx,1),st_fx->frame_cnt_ratewin_fx); /*Q15*/ - L_tmp1 = Mult_32_16(st_fx->global_avr_rate_fx, tmp); /* Q13*Q15 = Q13 */ + tmp = div_s(sub(hSC_VBR->frame_cnt_ratewin_fx,1),hSC_VBR->frame_cnt_ratewin_fx); /*Q15*/ + L_tmp1 = Mult_32_16(hSC_VBR->global_avr_rate_fx, tmp); /* Q13*Q15 = Q13 */ - L_tmp2 = Mult_32_16(st_fx->sum_of_rates_fx, recip); /*Q13*Qrecip = 13+Qrecip+1-16 = Qrecip-2 */ + L_tmp2 = Mult_32_16(hSC_VBR->sum_of_rates_fx, recip); /*Q13*Qrecip = 13+Qrecip+1-16 = Qrecip-2 */ - st_fx->global_avr_rate_fx = L_add(L_tmp1, L_shl(L_tmp2,13-(Qrecip-2))); /*Q13 */ + hSC_VBR->global_avr_rate_fx = L_add(L_tmp1, L_shl(L_tmp2,13-(Qrecip-2))); /*Q13 */ } ELSE { - st_fx->global_avr_rate_fx = st_fx->sum_of_rates_fx; /*handle the first frame*/ + hSC_VBR->global_avr_rate_fx = hSC_VBR->sum_of_rates_fx; /*handle the first frame*/ } /* Q13 */ } ELSE { /* st->global_avr_rate = 0.01f * st->sum_of_rates + 0.99f * st->global_avr_rate; */ - st_fx->global_avr_rate_fx = L_add(Mult_32_16(st_fx->sum_of_rates_fx,328),Mult_32_16(st_fx->global_avr_rate_fx,32441) ); /*Q13 */ + hSC_VBR->global_avr_rate_fx = L_add(Mult_32_16(hSC_VBR->sum_of_rates_fx,328),Mult_32_16(hSC_VBR->global_avr_rate_fx,32441) ); /*Q13 */ } - IF ( st_fx->sum_of_rates_fx == 0 ) + IF ( hSC_VBR->sum_of_rates_fx == 0 ) { /* st->sum_of_rates = (float) (RATEWIN * VBR_ADR_MAX_TARGET * 10); */ - st_fx->sum_of_rates_fx = L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),12); /*Q13 */ + hSC_VBR->sum_of_rates_fx = L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),12); /*Q13 */ } /* target = VBR_ADR_MAX_TARGET * 10 * RATEWIN; */ target_fx = L_shl(L_mult0(VBR_ADR_MAX_TARGET_x10_Q1,RATEWIN ),12); /*Q13 */ - IF ( LT_32(target_fx,st_fx->global_avr_rate_fx)) /* Action is taken to reduce the averge rate. Only initiated if the global rate > target rate */ + IF ( LT_32(target_fx,hSC_VBR->global_avr_rate_fx)) /* Action is taken to reduce the averge rate. Only initiated if the global rate > target rate */ { /* Check the vad snr values to table the noisey/not noisey decision */ test(); - IF ( LT_16(st_fx->SNR_THLD_fx , 17152)) /*Q8 */ /* Currently in QFF mode. The bumpup thresholds are slightly relaxed for noisy speech. */ + IF ( LT_16(hSC_VBR->SNR_THLD_fx , 17152)) /*Q8 */ /* Currently in QFF mode. The bumpup thresholds are slightly relaxed for noisy speech. */ { /* Increase the threshold so the the bumpup procedure is done using the noisy thresholds. Use 3.5 steps to quickly ramp up the rate control to reduce the settling time */ /* st->SNR_THLD += 3.5f; */ - st_fx->SNR_THLD_fx = add(st_fx->SNR_THLD_fx , 896 ); /*Q8 */ + hSC_VBR->SNR_THLD_fx = add(hSC_VBR->SNR_THLD_fx , 896 ); /*Q8 */ } - ELSE IF ( st_fx->mode_QQF_fx == 0 && GT_32(st_fx->sum_of_rates_fx, target_fx)) /* Now SNR_THLD is in the max allowed. Sill the global average is higher and + ELSE IF ( hSC_VBR->mode_QQF_fx == 0 && GT_32(hSC_VBR->sum_of_rates_fx, target_fx)) /* Now SNR_THLD is in the max allowed. Sill the global average is higher and last RATEWIN frames have a higher agerage than the target rate. Now slightly more aggresive rate control is used by changing the mode to QQF. Still the same strict bumpups (more bumpups,higher rate) are used. */ { /* Kick in QQF mode */ - st_fx->mode_QQF_fx = 1; + hSC_VBR->mode_QQF_fx = 1; move16(); } - ELSE IF ( GT_32(st_fx->sum_of_rates_fx , target_fx)) /* Actions (1) and (2) are not sufficient to control the rate. Still the last RATEWIN active + ELSE IF ( GT_32(hSC_VBR->sum_of_rates_fx , target_fx)) /* Actions (1) and (2) are not sufficient to control the rate. Still the last RATEWIN active frames have a higher average rate than the target rate. More aggresive rate control is needed. At this point the rate_control flag is set. This will enable the more relaxed bump up thresholds (less bump ups->reduced rate)*/ { /* Relaxed bump ups are used */ - st_fx->rate_control_fx = 1; + hSC_VBR->rate_control_fx = 1; move16(); /* This will be triggered only if the gloabl average rate is considerablly higher than the target rate. Keep a higher threshold to avoid short term rate increases over the target rate. */ - IF ( GT_32(st_fx->global_avr_rate_fx ,L_add(target_fx,3440640))) /* Last resort rate control. This is a safer rate control mechanism by increasing NELPS */ + IF ( GT_32(hSC_VBR->global_avr_rate_fx ,L_add(target_fx,3440640))) /* Last resort rate control. This is a safer rate control mechanism by increasing NELPS */ { - st_fx->Last_Resort_fx = 1; + hSC_VBR->Last_Resort_fx = 1; move16(); /* compute based on a larger window as the last resort */ } ELSE { - st_fx->Last_Resort_fx = 0; + hSC_VBR->Last_Resort_fx = 0; move16(); } } - ELSE IF ( LT_32(st_fx->sum_of_rates_fx, target_fx )) /* If the average rate of last RATEWIN frames is controlled by above actions, disable the most + ELSE IF ( LT_32(hSC_VBR->sum_of_rates_fx, target_fx )) /* If the average rate of last RATEWIN frames is controlled by above actions, disable the most aggresive rate control mechanisms. Still keep QQF mode as the global rate is not under the target rate*/ { - st_fx->Last_Resort_fx = 0; + hSC_VBR->Last_Resort_fx = 0; move16(); - st_fx->mode_QQF_fx = 1; + hSC_VBR->mode_QQF_fx = 1; move16(); - st_fx->rate_control_fx = 0; + hSC_VBR->rate_control_fx = 0; move16(); } } ELSE { /* floding back to lesser and leser aggresive rate control mechanisms gradually if global rate is under control */ - st_fx->Last_Resort_fx = 0; + hSC_VBR->Last_Resort_fx = 0; move16(); - IF ( EQ_16(st_fx->rate_control_fx,1)) + IF ( EQ_16(hSC_VBR->rate_control_fx,1)) { - st_fx->rate_control_fx = 0; + hSC_VBR->rate_control_fx = 0; move16(); } - ELSE IF ( EQ_16(st_fx->mode_QQF_fx,1)) /* now rate control is not active and still the global rate is below the target. so go to QFF mode */ + ELSE IF ( EQ_16(hSC_VBR->mode_QQF_fx,1)) /* now rate control is not active and still the global rate is below the target. so go to QFF mode */ { - st_fx->mode_QQF_fx = 0; + hSC_VBR->mode_QQF_fx = 0; move16(); } ELSE { - IF ( GE_16(st_fx->SNR_THLD_fx, 15360)) + IF ( GE_16(hSC_VBR->SNR_THLD_fx, 15360)) { - st_fx->SNR_THLD_fx =sub(st_fx->SNR_THLD_fx ,384 ); /*Q8 */ + hSC_VBR->SNR_THLD_fx =sub(hSC_VBR->SNR_THLD_fx ,384 ); /*Q8 */ } ELSE { - st_fx->SNR_THLD_fx = 15360; + hSC_VBR->SNR_THLD_fx = 15360; move16(); } } } - IF ( LT_32(st_fx->global_avr_rate_fx , L_sub(target_fx,983040))) /* In QFF mode and global rate is less than target rate-0.2kbps. We can send some Q frames + IF ( LT_32(hSC_VBR->global_avr_rate_fx , L_sub(target_fx,983040))) /* In QFF mode and global rate is less than target rate-0.2kbps. We can send some Q frames to F frames to improve the quality */ { /* kick in bouncing back from Q to F */ - st_fx->Q_to_F_fx = 1; + hSC_VBR->Q_to_F_fx = 1; move16(); /* average rate for next 600ms = global_rate * 2 - rate of the past RATEWIN active frames */ /* avratetarg = (float)((RATEWIN * 10) * 2 * VBR_ADR_MAX_TARGET - st->global_avr_rate); */ - avratetarg_fx = L_sub(L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),13), st_fx->global_avr_rate_fx ); + avratetarg_fx = L_sub(L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),13), hSC_VBR->global_avr_rate_fx ); /* Q13 */ @@ -201,43 +201,43 @@ void update_average_rate_fx( L_tmp = L_shl(L_tmp , 12); L_tmp = L_sub(avratetarg_fx , L_tmp); tmp = extract_h(L_shl(Mult_32_16(L_tmp,27307),4)); - st_fx->pattern_m_fx =tmp; + hSC_VBR->pattern_m_fx =tmp; move16(); - if ( st_fx->pattern_m_fx < 0 ) + if ( hSC_VBR->pattern_m_fx < 0 ) { - st_fx->pattern_m_fx = 0; + hSC_VBR->pattern_m_fx = 0; move16(); /* no bump up will ever happen */ } - if ( GT_16(st_fx->pattern_m_fx,1000)) + if ( GT_16(hSC_VBR->pattern_m_fx,1000)) { - st_fx->pattern_m_fx = 1000; + hSC_VBR->pattern_m_fx = 1000; move16();/* 10% of bump ups */ } - st_fx->patterncount_fx = 0; + hSC_VBR->patterncount_fx = 0; move16(); } ELSE { - st_fx->Q_to_F_fx = 0; + hSC_VBR->Q_to_F_fx = 0; move16(); } - st_fx->sum_of_rates_fx = 0; + hSC_VBR->sum_of_rates_fx = 0; move16(); - st_fx->numactive_fx = 0; + hSC_VBR->numactive_fx = 0; move16(); } - st_fx->numactive_fx = add(st_fx->numactive_fx,1); + hSC_VBR->numactive_fx = add(hSC_VBR->numactive_fx,1); /* sum the total number of bits (in kbytes) * 10 here */ - /*st->sum_of_rates += (st_fx->core_brate_fx / 1000.0f) * 10; */ - L_tmp = L_shl(Mult_32_16(st_fx->core_brate_fx ,20972),7); - st_fx->sum_of_rates_fx = L_add(st_fx->sum_of_rates_fx ,L_tmp); + /*st->sum_of_rates += (hSC_VBR->core_brate_fx / 1000.0f) * 10; */ + L_tmp = L_shl(Mult_32_16(core_brate_fx ,20972),7); + hSC_VBR->sum_of_rates_fx = L_add(hSC_VBR->sum_of_rates_fx ,L_tmp); return; } diff --git a/lib_enc/vlpc_1st_cod.c b/lib_enc/vlpc_1st_cod.c index 079f387..3d97a47 100644 --- a/lib_enc/vlpc_1st_cod.c +++ b/lib_enc/vlpc_1st_cod.c @@ -2,20 +2,24 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include "stl.h" +#include +#include "options.h" #include "control.h" #include "cnst_fx.h" #include "prot_fx.h" +#include "rom_com_fx.h" #define ISF_ONE 3/*1.0f*1.28f Q1*/ /*=1.0f in 14Q1*1.28*/ -extern const Word16 dico_lsf_abs_8b[]; - +/*------------------------------------------------------------------* + * lsf_weight() + * + * outputs only the weightings, doesn't do anything with the lsfq + *------------------------------------------------------------------*/ /*outputs only the weightings, doesn't do anything with the lsfq*/ static void lsf_weight( - const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28)*/ - Word16 *w /* output: lsf weighting vector (0Q15) */ + const Word16 *lsfq, /* i : quantized lsf coefficients (14Q1*1.28)*/ + Word16 *w /* o : lsf weighting vector (0Q15) */ ) { Word16 i; @@ -65,12 +69,16 @@ static void lsf_weight( return; } - -Word16 vlpc_1st_cod( /* output: codebook index */ - const Word16 *lsf, /* input: vector to quantize (14Q1*1.28) */ - Word16 *lsfq /* o: quantized lsf (14Q1*1.28) */ - ,Word16 *wout /* o: lsf weights */ - ,Word16 rf_mode +/*------------------------------------------------------------------* +* vlpc_1st_cod() +* +* +*------------------------------------------------------------------*/ +Word16 vlpc_1st_cod( /* o : codebook index */ + const Word16 *lsf, /* i : vector to quantize (14Q1*1.28) */ + Word16 *lsfq, /* o : quantized lsf (14Q1*1.28) */ + Word16 *wout, /* o : lsf weights */ + Word16 rf_mode ) { Word16 i, j, index, diff, wdiff; diff --git a/lib_enc/vlpc_2st_cod.c b/lib_enc/vlpc_2st_cod.c index 75f3d2e..cb8c227 100644 --- a/lib_enc/vlpc_2st_cod.c +++ b/lib_enc/vlpc_2st_cod.c @@ -2,22 +2,26 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include +#include "options.h" #include "cnst_fx.h" +#include "options.h" #include "prot_fx.h" -#include "stl.h" #include "control.h" #include "basop_util.h" +/*------------------------------------------------------------------* + * vlpc_2st_cod() + * + * + *------------------------------------------------------------------*/ Word16 vlpc_2st_cod( /* output: number of allocated bits */ - const Word16 *lsf, /* input: normalized vector to quantize (14Q1*1.28)*/ - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage (14Q1*1.28)*/ - Word16 *indx, /* output: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ - Word32 sr_core + const Word16 *lsf, /* i : normalized vector to quantize */ + Word16* lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16* indx, /* o : index[] (4 bits per words) */ + const Word16 mode, /* i : 0=abs, >0=rel */ + const Word32 sr_core/* i : internal sampling rate */ ) { Word16 i, nbits; diff --git a/lib_enc/voiced_enc_fx.c b/lib_enc/voiced_enc_fx.c index ae68517..e4491f2 100644 --- a/lib_enc/voiced_enc_fx.c +++ b/lib_enc/voiced_enc_fx.c @@ -2,18 +2,19 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include +#include +#include "options.h" #include "prot_fx.h" #include "cnst_fx.h" #include "rom_com_fx.h" -#include "stl.h" /*-------------------------------------------------------------------* * Local functions *--------------------------------------------------------------------*/ -void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], - Word16 P, Word16 N ); - +static void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], Word16 P, Word16 N ); +static Word32 DTFS_freq_corr_fx(DTFS_STRUCTURE_FX X1_DTFS_fx, DTFS_STRUCTURE_FX X2_DTFS_fx, Word16 lband, Word16 hband, Word16* Qout); +static Word16 DTFS_alignment_extract_td_fx(Word16* x1, Word16* x2, Word16 lag); +static Word32 DTFS_getEngy_band_fx(DTFS_STRUCTURE_FX X_fx,const Word16 lband,const Word16 hband); /*=======================================================================================*/ /* FUNCTION : ppp_voiced_encoder_fx() */ @@ -22,7 +23,7 @@ void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], /*---------------------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (Word16) delay_fx: open loop pitch, Q6 - WRONG, it is Q0 */ -/* _ (Word16) vadsnr_fx: SNR for current frame Q7 */ +/* _ (Word16) hSC_VBR->vadsnr_fx: SNR for current frame Q7 */ /* _ (Word16) prevCW_lag_fx: Previous lag, Q0 */ /* _ (Word16 *) in_fx : residual signal (Q_res) */ /* _ (Word16 *) lpc1_fx : prev frame de-emphasized LPC Q12 */ @@ -41,8 +42,8 @@ void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], /*---------------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* _ Encoder_State_fx *st_fx: */ -/* _ st_fx->dtfs_enc_xxxx */ -/* _ a nd b in st_fx->dtfs_enc_Q */ +/* _ hSC_VBR->dtfs_enc_xxxx */ +/* _ a nd b in hSC_VBR->dtfs_enc_Q */ /* rest all in Q0 */ /* - bump_up_fx - Q0 */ /*---------------------------------------------------------------------------------------*/ @@ -52,8 +53,12 @@ void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], /* CALLED FROM : TX */ /*=======================================================================================*/ -void ppp_voiced_encoder_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ +ivas_error ppp_voiced_encoder_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + SC_VBR_ENC_HANDLE hSC_VBR, + const Word16 bwidth_fx, /* i : audio bandwidth */ + const Word16 last_coder_type_raw, /* i : raw last_coder_type */ + const Word16 old_pitch_buf[], /* i : buffer of old subframe pitch values */ Word16 *in_fx, /* i : residual signal */ Word16 *out_fx, /* o : Quantized residual signal */ Word16 delay_fx, /* i : open loop pitch */ @@ -61,7 +66,6 @@ void ppp_voiced_encoder_fx( Word16* lpc2_fx, /* i : current frame de-emphasized LPC */ Word16 *exc_fx, /* i: previous frame quantized excitation */ Word16 *pitch_fx, /* o: floating pitch values for each subframe */ - Word16 vadsnr_fx, /* i: current frame SNR Q7, later shl by 1 for compare */ Word16 Qres ) { @@ -105,27 +109,55 @@ void ppp_voiced_encoder_fx( Word32 curr_Engy,prev_Engy; Word16 temp_Fs; + DTFS_STRUCTURE_FX* CURRP_NQ_FX; + DTFS_STRUCTURE_FX* TMPDTFS_FX; + DTFS_STRUCTURE_FX* TMPDTFS2_FX; + DTFS_STRUCTURE_FX* TMPDTFS3_FX; + DTFS_STRUCTURE_FX* CURRP_Q_E_FX; + DTFS_STRUCTURE_FX* dtfs_temp_fx; + + ivas_error error; - DTFS_STRUCTURE_FX *CURRP_NQ_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *TMPDTFS_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *TMPDTFS2_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *TMPDTFS3_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *CURRP_Q_E_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *dtfs_temp_fx = DTFS_new_fx(); + error = IVAS_ERR_OK; + + IF ((error = DTFS_new_fx(&CURRP_NQ_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } + IF ((error = DTFS_new_fx(&TMPDTFS_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } + IF ((error = DTFS_new_fx(&TMPDTFS2_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } + IF ((error = DTFS_new_fx(&TMPDTFS3_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } + IF ((error = DTFS_new_fx(&CURRP_Q_E_FX)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } + IF ((error = DTFS_new_fx(&dtfs_temp_fx)) != IVAS_ERR_OK) + { + IVAS_ERROR(error, "Error creating DTFS structure"); + } temp_Fs = 8000; move16(); - if ( EQ_16( st_fx->bwidth_fx, WB)) + if ( EQ_16( bwidth_fx, WB)) { temp_Fs = 16000; move16(); } test(); - IF (EQ_16(st_fx->bwidth_fx,WB)||EQ_16(st_fx->bwidth_fx,SWB)) + IF (EQ_16(bwidth_fx,WB)||EQ_16(bwidth_fx,SWB)) { upper_cut_off_freq_of_interest_fx = 4000; move16(); @@ -134,7 +166,7 @@ void ppp_voiced_encoder_fx( upper_cut_off_freq_norm_fx = 16384; move16();/*value normalized by 12800 */ } - ELSE IF (EQ_16(st_fx->bwidth_fx,NB)) + ELSE IF (EQ_16(bwidth_fx,NB)) { upper_cut_off_freq_of_interest_fx = 3300; move16(); @@ -145,77 +177,77 @@ void ppp_voiced_encoder_fx( } /* Initialization */ - IF (st_fx->firstTime_voicedenc_fx) + IF (hSC_VBR->firstTime_voicedenc_fx) { - st_fx->firstTime_voicedenc_fx = 0; + hSC_VBR->firstTime_voicedenc_fx = 0; move16(); - st_fx->dtfs_enc_lag_fx = 0; + hSC_VBR->dtfs_enc_lag_fx = 0; move16(); - st_fx->dtfs_enc_nH_fx = 0; + hSC_VBR->dtfs_enc_nH_fx = 0; move16(); - st_fx->dtfs_enc_nH_4kHz_fx = 0; + hSC_VBR->dtfs_enc_nH_4kHz_fx = 0; move16(); - st_fx->dtfs_enc_upper_cut_off_freq_of_interest_fx = 3300; + hSC_VBR->dtfs_enc_upper_cut_off_freq_of_interest_fx = 3300; move16(); - st_fx->dtfs_enc_upper_cut_off_freq_fx = 4000; + hSC_VBR->dtfs_enc_upper_cut_off_freq_fx = 4000; move16(); - set16_fx(st_fx->dtfs_enc_a_fx, 0, MAXLAG_WI); - set16_fx(st_fx->dtfs_enc_b_fx, 0, MAXLAG_WI); + set16_fx(hSC_VBR->dtfs_enc_a_fx, 0, MAXLAG_WI); + set16_fx(hSC_VBR->dtfs_enc_b_fx, 0, MAXLAG_WI); } test(); /* Figure out the PPP_MODE */ - IF ( EQ_16(st_fx->last_ppp_mode_fx,1)&&!st_fx->mode_QQF_fx) + IF ( EQ_16(hSC_VBR->last_ppp_mode_fx,1)&&!hSC_VBR->mode_QQF_fx) { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } /* Use the aggresive bumpups if there are two consecutive Q frames */ /* Aggresive bump upsare only used in the second Q frame */ - if ( st_fx->last_ppp_mode_fx == 1 ) + if (hSC_VBR->last_ppp_mode_fx == 1 ) { - st_fx->rate_control_fx = 0; + hSC_VBR->rate_control_fx = 0; } PPP_MODE_E = 'Q'; move16(); - pl = s_min(MAX_LAG_PIT, rint_new_fx(L_shl(st_fx->old_pitch_buf_fx[(2*NB_SUBFR)-1],10))); + pl = s_min(MAX_LAG_PIT, rint_new_fx(L_shl(old_pitch_buf[(2*NB_SUBFR)-1],10))); move16(); l = s_min(MAX_LAG_PIT, rint_new_fx(L_deposit_h(delay_fx))); move16(); - /* st_fx->old_pitch_buf_fx in Q6*/ + /* old_pitch_buf in Q6*/ /* Bump up if the lag is out_fx of range */ test(); IF (GT_16(sub(l,pl),13)||LT_16(sub(l,pl),-11)||LT_16(l,19)||LT_16(pl,19)) { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } - IF (NE_16(st_fx->last_ppp_mode_fx,1)) + IF (NE_16(hSC_VBR->last_ppp_mode_fx,1)) { /* Obtain DTFS of last pl values of past excitation */ GetSinCosTab_fx(pl,S_fx,C_fx); DTFS_to_fs_fx(exc_fx-pl, pl, dtfs_temp_fx, temp_Fs, 0,S_fx,C_fx); } - if (EQ_16(st_fx->last_coder_type_raw_fx,UNVOICED)) + if (EQ_16(last_coder_type_raw,UNVOICED)) { pl = l; move16(); /* if prev frame was sil/uv */ @@ -228,15 +260,15 @@ void ppp_voiced_encoder_fx( IF (out_of_bound == 1) { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } /* Get DTFS of current prototype */ @@ -275,10 +307,10 @@ void ppp_voiced_encoder_fx( curr_Engy=DTFS_getEngy_P2A_fx(CURRP_NQ_FX); /*2Q where Q=CURRP_NQ_FX->Q */ /* Restoring PPP memories when the last frame is non-PPP */ - IF (NE_16(st_fx->last_ppp_mode_fx,1)) + IF (NE_16(hSC_VBR->last_ppp_mode_fx,1)) { - st_fx->ph_offset_E_fx = 0 ; + hSC_VBR->ph_offset_E_fx = 0 ; move16(); /* st->prev_cw_en = DTFS_getEngy(*dtfs_temp); */ @@ -287,18 +319,18 @@ void ppp_voiced_encoder_fx( prev_Engy = L_add(Lacc, 0); - st_fx->Q_prev_cw_en_fx=norm_l(Lacc); /* = K = headroom */ + hSC_VBR->Q_prev_cw_en_fx=norm_l(Lacc); /* = K = headroom */ - /*st_fx->Q_prev_cw_en_fx = (Lacc==0)?31: st_fx->Q_prev_cw_en_fx; */ + /*hSC_VBR->Q_prev_cw_en_fx = (Lacc==0)?31: hSC_VBR->Q_prev_cw_en_fx; */ if (Lacc==0) { - st_fx->Q_prev_cw_en_fx = 31; + hSC_VBR->Q_prev_cw_en_fx = 31; move16(); } - st_fx->prev_cw_en_fx=(Word32) L_shl(Lacc,st_fx->Q_prev_cw_en_fx); /*2Q+K */ - st_fx->Q_prev_cw_en_fx = add(st_fx->Q_prev_cw_en_fx,shl(dtfs_temp_fx->Q,1)); - /* st_fx->Q_prev_cw_en_fx = 2*(dtfs_temp_fx->Q) + K */ + hSC_VBR->prev_cw_en_fx=(Word32) L_shl(Lacc, hSC_VBR->Q_prev_cw_en_fx); /*2Q+K */ + hSC_VBR->Q_prev_cw_en_fx = add(hSC_VBR->Q_prev_cw_en_fx,shl(dtfs_temp_fx->Q,1)); + /* hSC_VBR->Q_prev_cw_en_fx = 2*(dtfs_temp_fx->Q) + K */ DTFS_copy_fx(TMPDTFS_FX,*dtfs_temp_fx); /* output = TMPDTFS_FX */ @@ -312,15 +344,15 @@ void ppp_voiced_encoder_fx( /* Compensate for Q factor of energy to get log10(lag*eng) */ Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - /*st_fx->lastLgainE_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); // Q11, 0x6666 = 0.1 in Q18 */ - st_fx->lastLgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11, 0x6666 = 0.1 in Q18 */ + /*hSC_VBR->lastLgainE_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); // Q11, 0x6666 = 0.1 in Q18 */ + hSC_VBR->lastLgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11, 0x6666 = 0.1 in Q18 */ /* Process high band */ Ltemp=DTFS_setEngyHarm_fx(2828,upper_cut_off_freq_of_interest_norm_fx,2828,upper_cut_off_freq_norm_fx, 1, 0, &Qh,TMPDTFS_FX); Ltemp=log10_fx(Ltemp); Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - st_fx->lastHgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ + hSC_VBR->lastHgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ /* Need to unify the Q factors of both bands */ TMPDTFS_FX->Q=s_min(Ql,Qh); @@ -336,27 +368,27 @@ void ppp_voiced_encoder_fx( rshiftHarmBand_fx(TMPDTFS_FX,0, 2828, sub(Qh,Ql)); } - DTFS_to_erb_fx(*TMPDTFS_FX,st_fx->lasterbE_fx); /* output lasterbE_fx in Q13 */ + DTFS_to_erb_fx(*TMPDTFS_FX, hSC_VBR->lasterbE_fx); /* output lasterbE_fx in Q13 */ Lacc1 = L_max(prev_Engy, 1); } ELSE { /* Copy DTFS related parameters from 'st_fx' to 'dtfs_temp' structure */ - dtfs_temp_fx->lag_fx = st_fx->dtfs_enc_lag_fx; + dtfs_temp_fx->lag_fx = hSC_VBR->dtfs_enc_lag_fx; move16(); - dtfs_temp_fx->nH_fx = st_fx->dtfs_enc_nH_fx; + dtfs_temp_fx->nH_fx = hSC_VBR->dtfs_enc_nH_fx; move16(); - dtfs_temp_fx->nH_4kHz_fx = st_fx->dtfs_enc_nH_4kHz_fx; + dtfs_temp_fx->nH_4kHz_fx = hSC_VBR->dtfs_enc_nH_4kHz_fx; move16(); - dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = st_fx->dtfs_enc_upper_cut_off_freq_of_interest_fx; + dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = hSC_VBR->dtfs_enc_upper_cut_off_freq_of_interest_fx; move16(); - dtfs_temp_fx->upper_cut_off_freq_fx = st_fx->dtfs_enc_upper_cut_off_freq_fx; + dtfs_temp_fx->upper_cut_off_freq_fx = hSC_VBR->dtfs_enc_upper_cut_off_freq_fx; move16(); - Copy(st_fx->dtfs_enc_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); - Copy(st_fx->dtfs_enc_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); + Copy(hSC_VBR->dtfs_enc_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); + Copy(hSC_VBR->dtfs_enc_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); - dtfs_temp_fx->Q = st_fx->dtfs_enc_Q; + dtfs_temp_fx->Q = hSC_VBR->dtfs_enc_Q; move16(); Lacc1=DTFS_getEngy_P2A_fx(dtfs_temp_fx); prev_Engy = L_add(Lacc1, 0); @@ -419,9 +451,7 @@ void ppp_voiced_encoder_fx( /* Copy over dtfs_temp into TMPDTFS2 */ DTFS_copy_fx(TMPDTFS2_FX, *dtfs_temp_fx); /* output = TMPDTFS2_FX with Q = dtfs_temp_fx->Q */ - tmptmp = DTFS_alignment_full_fx(*TMPDTFS2_FX,*TMPDTFS_FX,st_fx->ph_offset_E_fx,S_fx,C_fx - , 0 - ); + tmptmp = DTFS_alignment_full_fx(*TMPDTFS2_FX,*TMPDTFS_FX, hSC_VBR->ph_offset_E_fx,S_fx,C_fx, 0); tmptmp1 = sub(shl(TMPDTFS_FX->lag_fx,1), tmptmp);/* (C_l-tmptmp) , Q1 */ @@ -502,7 +532,7 @@ void ppp_voiced_encoder_fx( } /* Bump up if big change between the previous and the current CWs */ - IF ( LT_16(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx)) /*Q8 */ + IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ { /*if ( res_enratio > 5.0 && tmp < 0.65 ) */ /* 5 in Q11, 0.65 in Q15 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q31 */ @@ -529,20 +559,20 @@ void ppp_voiced_encoder_fx( /* Rapid rampdown frame where time resolution is important */ /* Not a suitable PPP frame -> Bump to CELP */ - IF ( LT_16(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx)) /*Q8 */ + IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ { /* if (res_enratio < 0.025) */ IF (LT_32(L_shl(res_enratio_fx,4),819)) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } } ELSE @@ -550,7 +580,7 @@ void ppp_voiced_encoder_fx( /* if ( res_enratio < 0.092f) */ if ( LT_32(L_shl(res_enratio_fx,4), 3015))/*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); } } @@ -559,59 +589,59 @@ void ppp_voiced_encoder_fx( test(); if ( LT_32(L_min(L_shl(res_enratio_fx,4), sp_enratio_fx), 2458)&<_32(tmp_fx,shl(-1,sub(Qtmp,1)))) { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); } /* Rapid rampup frame where time resolution is important */ /* Not a suitable PPP frame -> Bump to CELP */ - IF ( LT_16(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx)) /*Q8 */ + IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ { IF (GT_32(res_enratio_fx,29696)) /*14.5 in Q11 */ { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } } ELSE { if (GT_32(res_enratio_fx,14336)) /* 7.0 in Q11 */ { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); } } - IF ( st_fx->bump_up_fx == 1 ) + IF ( hSC_VBR->bump_up_fx == 1 ) { - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } /* Bump up when the previous frame is an unvoiced or a silent frame */ - IF (EQ_16(st_fx->last_coder_type_raw_fx,UNVOICED)) + IF (EQ_16(last_coder_type_raw,UNVOICED)) { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } /* -----End Open-loop Bump-Up */ @@ -622,9 +652,16 @@ void ppp_voiced_encoder_fx( move16(); IF (EQ_16(PPP_MODE_E,'Q')) { - flag = ppp_quarter_encoder_fx(CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, - lpc2_fx, &st_fx->lastLgainE_fx, &st_fx->lastHgainE_fx, st_fx->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, st_fx); - move16(); + if ((error = ppp_quarter_encoder_fx(&flag, CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, lpc2_fx, &hSC_VBR->lastLgainE_fx, &hSC_VBR->lastHgainE_fx, hSC_VBR->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, hBstr)) != IVAS_ERR_OK) + { + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; + } } IF (flag) @@ -701,20 +738,20 @@ void ppp_voiced_encoder_fx( } Ltmp_32=DTFS_getEngy_fx(CURRP_NQ_FX); /*Q = 2*(CURRP_NQ_FX->Q) */ - Qadj = sub(st_fx->Q_prev_cw_en_fx, shl(CURRP_NQ_FX->Q, 1)); + Qadj = sub(hSC_VBR->Q_prev_cw_en_fx, shl(CURRP_NQ_FX->Q, 1)); Ltmp_32 = L_shl(Ltmp_32,Qadj); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ /* Ltmp1_32 = 0.8f * st->prev_cw_en */ - Ltmp1_32 = Mult_32_16(st_fx->prev_cw_en_fx,26214); /* Q = (Q_prev_cw_en_fx + Q15+1)-Q16 = Q_prev_cw_en_fx */ + Ltmp1_32 = Mult_32_16(hSC_VBR->prev_cw_en_fx,26214); /* Q = (Q_prev_cw_en_fx + Q15+1)-Q16 = Q_prev_cw_en_fx */ - IF ( LT_16(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx)) /*Q8 */ + IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /*Q8 */ { /* if ( DTFS_getEngy(*CURRP_NQ) > 0.8f * st->prev_cw_en && max(pos_nq, neg_nq) > 3.0f && st->rate_control ) */ /* pos_nq_fx and neg_nq_fx in Q28 ???? */ test(); test(); - IF ( GT_32( Ltmp_32, Ltmp1_32)&>_32(L_max(pos_nq_fx,neg_nq_fx),805306368)&&st_fx->rate_control_fx) + IF ( GT_32( Ltmp_32, Ltmp1_32)&>_32(L_max(pos_nq_fx,neg_nq_fx),805306368)&&hSC_VBR->rate_control_fx) { /*if ( pos_nq > neg_nq && pos_nq > 2.0f * pos_q ) */ test(); @@ -743,8 +780,8 @@ void ppp_voiced_encoder_fx( test(); test(); test(); - IF ((((L_sub(Ltmp_32 ,(st_fx->prev_cw_en_fx)>0))&&(GT_32(L_max(pos_nq_fx,neg_nq_fx),939524096)))&&(st_fx->rate_control_fx))|| - (((GT_32( Ltmp_32, Ltmp1_32) ) && (GT_32(L_max(pos_nq_fx,neg_nq_fx),805306368)))&&(!st_fx->rate_control_fx))) + IF ((((L_sub(Ltmp_32 ,(hSC_VBR->prev_cw_en_fx)>0))&&(GT_32(L_max(pos_nq_fx,neg_nq_fx),939524096)))&&(hSC_VBR->rate_control_fx))|| + (((GT_32( Ltmp_32, Ltmp1_32) ) && (GT_32(L_max(pos_nq_fx,neg_nq_fx),805306368)))&&(!hSC_VBR->rate_control_fx))) { /* if (((pos_nq > neg_nq) && (pos_nq > 2.5*pos_q)&&(st->rate_control))|| ((pos_nq > neg_nq) && (pos_nq > 2.0*pos_q)&&(!st->rate_control))) */ @@ -753,8 +790,8 @@ void ppp_voiced_encoder_fx( test(); test(); test(); - IF ((GT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(pos_nq_fx,13107),pos_q_fx)&&(st_fx->rate_control_fx))|| - (GT_32(pos_nq_fx , neg_nq_fx) && GT_32(Mult_32_16(pos_nq_fx,16384),pos_q_fx) && (!st_fx->rate_control_fx))) + IF ((GT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(pos_nq_fx,13107),pos_q_fx)&&(hSC_VBR->rate_control_fx))|| + (GT_32(pos_nq_fx , neg_nq_fx) && GT_32(Mult_32_16(pos_nq_fx,16384),pos_q_fx) && (!hSC_VBR->rate_control_fx))) { PPP_MODE_E='B'; move16(); @@ -767,8 +804,8 @@ void ppp_voiced_encoder_fx( test(); test(); test(); - IF ((LT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(neg_nq_fx,13107),neg_q_fx)&&(st_fx->rate_control_fx))|| - (LT_32(pos_nq_fx , neg_nq_fx) && GT_32(Mult_32_16(neg_nq_fx,16384),neg_q_fx) && (!st_fx->rate_control_fx))) + IF ((LT_32(pos_nq_fx , neg_nq_fx)&>_32(Mult_32_16(neg_nq_fx,13107),neg_q_fx)&&(hSC_VBR->rate_control_fx))|| + (LT_32(pos_nq_fx , neg_nq_fx) && GT_32(Mult_32_16(neg_nq_fx,16384),neg_q_fx) && (!hSC_VBR->rate_control_fx))) { PPP_MODE_E='B'; move16(); @@ -776,7 +813,7 @@ void ppp_voiced_encoder_fx( } - IF ( st_fx->rate_control_fx ) + IF ( hSC_VBR->rate_control_fx ) { DTFS_peaktoaverage_fx(*CURRP_NQ_FX,&pos_nq0_fx,&Qposnq,&neg_nq0_fx,&Qnegnq); @@ -821,14 +858,14 @@ void ppp_voiced_encoder_fx( /* energy_impz_fx is Q11 */ Ltmp_32 = DTFS_getEngy_fx(CURRP_Q_E_FX); /*Q = 2*(CURRP_Q_E_FX->Q) */ - Qadj = sub(st_fx->Q_prev_cw_en_fx, shl(CURRP_Q_E_FX->Q, 1)); + Qadj = sub(hSC_VBR->Q_prev_cw_en_fx, shl(CURRP_Q_E_FX->Q, 1)); Ltmp_32 = L_shl(Ltmp_32,Qadj); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ /* if ((DTFS_getEngy(*CURRP_Q_E) > st->prev_cw_en)&&(max(pos_q,neg_q)>3.5) && energy_impz>15.0 && tmpres>0.7) */ test(); test(); test(); - IF ((GT_32(Ltmp_32, st_fx->prev_cw_en_fx ))&&(GT_32(L_max(pos_q_fx,neg_q_fx),939524096))&&(GT_32(energy_impz_fx,30720)) + IF ((GT_32(Ltmp_32, hSC_VBR->prev_cw_en_fx ))&&(GT_32(L_max(pos_q_fx,neg_q_fx),939524096))&&(GT_32(energy_impz_fx,30720)) && (GT_32(Mult_32_16(tmpres_fx,23265),shl(1,sub(Qtmpres,1)))) ) { /* if ((pos_q > neg_q) && ((pos_q>3.0*pos_nq0) || ((pos_q > 1.5*pos_nq0) && (neg_q < 1.5*neg_nq0)))) */ @@ -867,7 +904,7 @@ void ppp_voiced_encoder_fx( DTFS_poleFilter_fx_9(TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); DTFS_poleFilter_fx_9(TMPDTFS2_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); - *TMPDTFS3_FX = DTFS_sub_fx(*TMPDTFS_FX,*TMPDTFS2_FX); + DTFS_sub_fx(TMPDTFS3_FX, *TMPDTFS_FX,*TMPDTFS2_FX); /* operate in ADR mode only the rate control is active. This adds some bumpups to improve the speech quality */ @@ -898,7 +935,7 @@ void ppp_voiced_encoder_fx( } test(); - IF (GT_32(Ltemp_fx , 6710886)&&(!st_fx->rate_control_fx)) /* 0.05 in Q27 = 6710886 */ + IF (GT_32(Ltemp_fx , 6710886)&&(!hSC_VBR->rate_control_fx)) /* 0.05 in Q27 = 6710886 */ { /*if (10.0*log10(DTFS_getEngy_band(*TMPDTFS,1500.0,upper_cut_off_freq_of_interest)/ */ /*DTFS_getEngy_band(*TMPDTFS3,1500.0,upper_cut_off_freq_of_interest)) < 0.1) */ @@ -1005,13 +1042,13 @@ void ppp_voiced_encoder_fx( } test(); - if ((Ltemp <= 0)&&(!st_fx->rate_control_fx)) + if ((Ltemp <= 0)&&(!hSC_VBR->rate_control_fx)) { PPP_MODE_E = 'B'; move16(); } - IF ( LT_16(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx)) /* Q8 */ + IF ( LT_16(shl(hSC_VBR->vadsnr_fx,1) ,hSC_VBR->SNR_THLD_fx)) /* Q8 */ { /* if ((( tmp < 3.05 && max(res_enratio,sp_enratio) > 0.8 ) && (st->rate_control))|| (( tmp < 2.8 && max(res_enratio,sp_enratio) > 0.65 ) && (!st->rate_control))) */ @@ -1021,8 +1058,8 @@ void ppp_voiced_encoder_fx( test(); test(); test(); - if ((( LT_32(Ltemp, 25585254 )&>_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx),6554))&&(st_fx->rate_control_fx))|| - (( LT_32(Ltemp, 23488102 ) && GT_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 5325) )&&(!st_fx->rate_control_fx))) + if ((( LT_32(Ltemp, 25585254 )&>_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx),6554))&&(hSC_VBR->rate_control_fx))|| + (( LT_32(Ltemp, 23488102 ) && GT_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 5325) )&&(!hSC_VBR->rate_control_fx))) { PPP_MODE_E = 'B'; move16(); @@ -1037,8 +1074,8 @@ void ppp_voiced_encoder_fx( test(); test(); test(); - if ((( LT_32(Ltemp ,20132659 )&>_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx),7700))&&(st_fx->rate_control_fx))|| - (( LT_32(Ltemp, 37748736 ) && GT_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 4096) )&&(!st_fx->rate_control_fx))) + if ((( LT_32(Ltemp ,20132659 )&>_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx),7700))&&(hSC_VBR->rate_control_fx))|| + (( LT_32(Ltemp, 37748736 ) && GT_32(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 4096) )&&(!hSC_VBR->rate_control_fx))) { PPP_MODE_E = 'B'; move16(); @@ -1058,35 +1095,35 @@ void ppp_voiced_encoder_fx( } if (PPP_MODE_E == 'B') { - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } - IF ( st_fx->Q_to_F_fx ) + IF ( hSC_VBR->Q_to_F_fx ) { - st_fx->patterncount_fx = add(st_fx->patterncount_fx ,st_fx->pattern_m_fx); + hSC_VBR->patterncount_fx = add(hSC_VBR->patterncount_fx ,hSC_VBR->pattern_m_fx); - IF (GE_16(st_fx->patterncount_fx , 1000)) + IF (GE_16(hSC_VBR->patterncount_fx , 1000)) { - st_fx->patterncount_fx = sub (st_fx->patterncount_fx , 1000); + hSC_VBR->patterncount_fx = sub (hSC_VBR->patterncount_fx , 1000); PPP_MODE_E = 'B'; move16(); - st_fx->bump_up_fx = 1; + hSC_VBR->bump_up_fx = 1; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); + return error; } } @@ -1096,51 +1133,51 @@ void ppp_voiced_encoder_fx( { Q_delta_lag = add(delta_lag_E,11); /* to make it positive always */ - push_indice_fx( st_fx, IND_DELTALAG, Q_delta_lag, 5 ); + push_indice_fx(hBstr, IND_DELTALAG, Q_delta_lag, 5 ); } - WIsyn_fx(*dtfs_temp_fx, CURRP_Q_E_FX, lpc2_fx, &(st_fx->ph_offset_E_fx), out_fx, L_FRAME,0,S_fx,C_fx, + WIsyn_fx(*dtfs_temp_fx, CURRP_Q_E_FX, lpc2_fx, &(hSC_VBR->ph_offset_E_fx), out_fx, L_FRAME,0,S_fx,C_fx, pf_temp1,pf_temp2,pf_temp,pf_n2); /* i/o ph_offset_fx in Q15, out_fx in Q0 */ DTFS_copy_fx(dtfs_temp_fx, *CURRP_Q_E_FX); Lacc = DTFS_getEngy_P2A_fx(CURRP_NQ_FX); - st_fx->Q_prev_cw_en_fx=norm_l(Lacc); + hSC_VBR->Q_prev_cw_en_fx=norm_l(Lacc); - /* st_fx->Q_prev_cw_en_fx = (Lacc==0)?31: st_fx->Q_prev_cw_en_fx;move16(); */ + /* hSC_VBR->Q_prev_cw_en_fx = (Lacc==0)?31: hSC_VBR->Q_prev_cw_en_fx;move16(); */ if (Lacc==0) { - st_fx->Q_prev_cw_en_fx = 31; + hSC_VBR->Q_prev_cw_en_fx = 31; move16(); } - st_fx->prev_cw_en_fx=(Word32) L_shl(Lacc,st_fx->Q_prev_cw_en_fx); /*2Q+Q_prev_cw_en_fx */ - st_fx->Q_prev_cw_en_fx=add(st_fx->Q_prev_cw_en_fx,shl(CURRP_NQ_FX->Q,1)); + hSC_VBR->prev_cw_en_fx=(Word32) L_shl(Lacc,hSC_VBR->Q_prev_cw_en_fx); /*2Q+Q_prev_cw_en_fx */ + hSC_VBR->Q_prev_cw_en_fx=add(hSC_VBR->Q_prev_cw_en_fx,shl(CURRP_NQ_FX->Q,1)); /* Copy DTFS related parameters from 'dtfs_temp' to 'st_fx' structure */ - st_fx->dtfs_enc_lag_fx = dtfs_temp_fx->lag_fx; + hSC_VBR->dtfs_enc_lag_fx = dtfs_temp_fx->lag_fx; move16(); - st_fx->dtfs_enc_nH_fx = dtfs_temp_fx->nH_fx; + hSC_VBR->dtfs_enc_nH_fx = dtfs_temp_fx->nH_fx; move16(); - st_fx->dtfs_enc_nH_4kHz_fx = dtfs_temp_fx->nH_4kHz_fx; + hSC_VBR->dtfs_enc_nH_4kHz_fx = dtfs_temp_fx->nH_4kHz_fx; move16(); - st_fx->dtfs_enc_upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; + hSC_VBR->dtfs_enc_upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; move16(); - st_fx->dtfs_enc_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; + hSC_VBR->dtfs_enc_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; move16(); - Copy(dtfs_temp_fx->a_fx, st_fx->dtfs_enc_a_fx, MAXLAG_WI); - Copy(dtfs_temp_fx->b_fx, st_fx->dtfs_enc_b_fx, MAXLAG_WI); + Copy(dtfs_temp_fx->a_fx, hSC_VBR->dtfs_enc_a_fx, MAXLAG_WI); + Copy(dtfs_temp_fx->b_fx, hSC_VBR->dtfs_enc_b_fx, MAXLAG_WI); - st_fx->dtfs_enc_Q = dtfs_temp_fx->Q; + hSC_VBR->dtfs_enc_Q = dtfs_temp_fx->Q; move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); + count_free(CURRP_NQ_FX); + count_free(TMPDTFS_FX); + count_free(TMPDTFS2_FX); + count_free(TMPDTFS3_FX); + count_free(CURRP_Q_E_FX); + count_free(dtfs_temp_fx); - return; + return error; } @@ -1172,8 +1209,7 @@ void ppp_voiced_encoder_fx( /* } */ /* +fres(n) */ /*===================================================================*/ -void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], - Word16 P, Word16 N ) +static void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], Word16 P, Word16 N ) { Word32 acc; Word16 i, j; @@ -1198,8 +1234,361 @@ void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], buf[0] = round_fx(acc); } } +/*==============================================================================*/ +/* FUNCTION : DTFS_freq_corr_fx () */ +/*------------------------------------------------------------------------------*/ +/* PURPOSE : */ +/*------------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (struct DTFS_STRUCTURE_FX) X1_DTFS_fx : a_fx/b_fx in X1_DTFS_fx.Q */ +/* _ (struct DTFS_STRUCTURE_FX) X2_DTFS_fx : a_fx/b_fx in X2_DTFS_fx.Q */ +/* _ (Word16) lband: Q0 */ +/* _ (Word16) hband: Q0 */ +/*------------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) *Qout : Q of output result */ +/*------------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ +/*------------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ (Word32) Result : Qout */ +/*------------------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*==============================================================================*/ + +static Word32 DTFS_freq_corr_fx( + DTFS_STRUCTURE_FX X1_DTFS_fx, + DTFS_STRUCTURE_FX X2_DTFS_fx, + Word16 lband, + Word16 hband, + Word16* Qout +) +{ + Word16 k, HalfLag, lk, hk; + Word32 corr_fx; + Word32 freq_fx, L_lband, L_hband; + Word32 E_fx; + Word32 Num, Den, Result; + Word16 E1_fx, E2_fx, Q1, Q2, Qr; + Word16 expa, expb, fraca, fracb, scale; + Word16 exp, tmp; + Word32 L_tmp; + Word16 Q_num, Q_den; + + IF(LT_16(X1_DTFS_fx.lag_fx, X2_DTFS_fx.lag_fx)) + { + DTFS_zeroPadd_fx(X2_DTFS_fx.lag_fx, &X1_DTFS_fx); + } + + corr_fx = L_deposit_l(0); + + L_lband = L_mult(lband, X2_DTFS_fx.lag_fx); + L_hband = L_mult(hband, X2_DTFS_fx.lag_fx); + HalfLag = s_min(shr(X2_DTFS_fx.lag_fx, 1), X2_DTFS_fx.nH_4kHz_fx); + + /* get lband and hband */ + FOR(k = 0; k <= HalfLag; k++) + { + freq_fx = L_mult(k, 12800); + IF(GE_32(freq_fx, L_lband)) + { + BREAK; + } + } + lk = k; + FOR(k = 0; k <= HalfLag; k++) + { + freq_fx = L_mult(k, 12800); + IF(GE_32(freq_fx, L_hband)) + { + BREAK; + } + } + hk = k; + move16(); + + FOR(k = lk; k < hk; k++) + { + corr_fx = L_mac0(corr_fx, X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k]); /* Q(1) */ + corr_fx = L_mac0(corr_fx, X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k]); /* Q(1) */ + } + + Qr = norm_l(corr_fx); + if (corr_fx == 0) + { + Qr = 31; + move16(); + } + + E1_fx = round_fx(L_shl(corr_fx, Qr)); /* Q(Qr-16) */ + Num = L_mult0(E1_fx, E1_fx); /* Q(2+2*Qr-32+1) */ + Q_num = sub(shl(add(add(X1_DTFS_fx.Q, X2_DTFS_fx.Q), Qr), 1), 32); + + /* PORTING: Handling the functions with variable no. of arguments */ + E_fx = DTFS_getEngy_band_fx(X1_DTFS_fx, lband, hband); /* Q(1) */ + Q1 = norm_l(E_fx); + if (E_fx == 0) + { + Q1 = 31; + move16(); + } + + E1_fx = round_fx(L_shl(E_fx, Q1)); /* Q(1+Q1-16) */ + + /* PORTING: Handling the functions with variable no. of arguments */ + E_fx = DTFS_getEngy_band_fx(X2_DTFS_fx, lband, hband); /* Q(1) */ + Q2 = norm_l(E_fx); + if (E_fx == 0) + { + Q2 = 31; + move16(); + } + + E2_fx = round_fx(L_shl(E_fx, Q2)); /* Q(1+Q2-16) */ + + Den = L_mult0(E1_fx, E2_fx); /* Q(2+Q1+Q2-32+1) */ + Q_den = sub(add(shl(add(X2_DTFS_fx.Q, X1_DTFS_fx.Q), 1), add(Q1, Q2)), 32); + + Num = L_max(Num, 1); + + IF(Num == 0) + { + Result = 0; + *Qout = 31; + } + ELSE + { + + expa = norm_l(Num); + fraca = extract_h(L_shl(Num,expa)); + expa = sub(30, add(expa,Q_num)); + + + expb = norm_l(Den); + fracb = round_fx(L_shl(Den,expb)); + expb = sub(30, add(expb,Q_den)); + scale = shr(sub(fraca,fracb),15); + fracb = shl(fracb,scale); + expb = sub(expb,scale); + + tmp = div_s(fracb,fraca); + exp = sub(expb,expa); + L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ + IF(corr_fx > 0) + { + Result = L_add(L_tmp, 0); + } + ELSE + { + Result = L_negate(L_tmp); + } + *Qout = sub(30,exp); + } + return Result; +} +/*===================================================================*/ +/* FUNCTION : DTFS_alignment_extract_td_fx () */ +/*-------------------------------------------------------------------*/ +/* PURPOSE : search for alignment in time domain */ +/*-------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16 *) x1: Q? */ +/* _ (Word16 *) x2: Q? */ +/*-------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) lag : Q0 */ +/*-------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ +/*-------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : _ (Word16 *) idx: Q0 */ +/*-------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*===================================================================*/ + +static Word16 DTFS_alignment_extract_td_fx(Word16* x1, Word16* x2, Word16 lag) +{ + Word16 j, k, idx, Adiff_fx; + Word32 maxcorr, corr; + + maxcorr = L_add(MIN_32, 0); + Adiff_fx = (Word16)(s_max(4, shr(lag, 3))); + + idx = 0; + move16(); + FOR(j = negate(Adiff_fx); j <= Adiff_fx; j++) + { + corr = L_deposit_l(0); + FOR(k = 0; k < lag; k++) + { + corr = L_mac(corr, x1[k], x2[(k - j + lag) % lag]); + } + if (GT_32(corr, maxcorr)) + { + idx = j; + move16(); + maxcorr = L_add(corr, 0); + } + } + return idx; +} +/*=================================================================================*/ +/* FUNCTION : DTFS_getEngy_band_fx (Word16 lband, Word16 hband) */ +/*---------------------------------------------------------------------------------*/ +/* PURPOSE : compute the energy of X1.a[k] and X2.b[k] */ +/*---------------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (struct DTFS_STRUCTURE_FX) X_fx : a_fx/b_fx in X_fx.Q, lag in Q0 */ +/* _ (Word16) lband: Q0 */ +/* _ (Word16) hband: Q0 */ +/*---------------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word40) en_fx : 2*X1.Q */ +/*---------------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ +/*---------------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : _ None. */ +/*---------------------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*=================================================================================*/ + +/* PORTING: Handling the functions with variable no. of arguments */ + +static Word32 DTFS_getEngy_band_fx( + DTFS_STRUCTURE_FX X_fx, + const Word16 lband, + const Word16 hband +) +{ + Word16 k, lk, hk, HalfLag; + Word32 freq_fx, L_lband, L_hband; + Word32 en_fx = 0; + + L_lband = L_mult(lband, X_fx.lag_fx); + L_hband = L_mult(hband, X_fx.lag_fx); + HalfLag = s_min(shr(sub(X_fx.lag_fx, 1), 1), X_fx.nH_4kHz_fx); + /* get lband and hband */ + FOR(k = 1; k <= HalfLag; k++) + { + freq_fx = L_mult(k, 12800); + IF(GE_32(freq_fx, L_lband)) + { + BREAK; + } + } + lk = k; + move16(); + FOR(k = 1; k <= HalfLag; k++) + { + freq_fx = L_mult(k, 12800); + IF(GE_32(freq_fx, L_hband)) + { + BREAK; + } + } + hk = k; + move16(); + + FOR(k = lk; k < hk; k++) + { + en_fx = L_mac0(en_fx, X_fx.a_fx[k], X_fx.a_fx[k]); /* 2*X1.Q+1 */ + en_fx = L_mac0(en_fx, X_fx.b_fx[k], X_fx.b_fx[k]); + } + + if (lband == 0) + { + en_fx = L_mac0(en_fx, X_fx.a_fx[0], X_fx.a_fx[0]); /* 2*X1.Q+1 */ + } + + /* IF ((X_fx.lag_fx%2 == 0) && (hband == X_fx.upper_cut_off_freq_fx)) */ + test(); + IF((s_and(X_fx.lag_fx, 1) == 0) && (hband == X_fx.upper_cut_off_freq_fx)) + { + en_fx = L_mac0(en_fx, X_fx.a_fx[k], X_fx.a_fx[k]); + en_fx = L_mac0(en_fx, X_fx.b_fx[k], X_fx.b_fx[k]); + } + + return en_fx; /* 2*X1.Q */ +} +/*---------------------------------------------------------------------* + * sc_vbr_enc_init() + * + * Initialize SC-VBR encoder + *---------------------------------------------------------------------*/ + +void sc_vbr_enc_init( + SC_VBR_ENC_HANDLE hSC_VBR /* i/o: SC-VBR encoder handle */ +) +{ + hSC_VBR->nelp_enc_seed_fx = 0; + move16(); + hSC_VBR->last_nelp_mode_fx = 0; + move16(); + hSC_VBR->pppcountE_fx = 0; + move16(); + hSC_VBR->last_ppp_mode_fx = 0; + move16(); + hSC_VBR->last_last_ppp_mode_fx = 0; + move16(); + hSC_VBR->firstTime_voicedenc_fx = 1; + move16(); + hSC_VBR->prev_ppp_gain_pit_fx = 0; + move16(); + hSC_VBR->prev_tilt_code_fx = 0; + move16(); + + hSC_VBR->ppp_mode_fx = 0; + move16(); + hSC_VBR->nelp_mode_fx = 0; + move16(); + + + hSC_VBR->pattern_m_fx = 0; + move16(); + hSC_VBR->Last_Resort_fx = 0; + move16(); + hSC_VBR->Q_to_F_fx = 0; + move16(); + + hSC_VBR->numactive_fx = 0; /* keep the count of the frames inside current 600 frame bloack.*/ + hSC_VBR->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ + hSC_VBR->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ + hSC_VBR->frame_cnt_ratewin_fx = 0; /* 600 active frame block count. Used to update the global rate*/ + hSC_VBR->rate_control_fx = 0; + move16(); + hSC_VBR->SNR_THLD_fx = SNR_THLD_FX_Q8; + move16(); + hSC_VBR->mode_QQF_fx = 1; + move16(); + + hSC_VBR->vbr_generic_ho_fx = 0; + move16(); + hSC_VBR->Local_VAD = 0; + + hSC_VBR->Last_Resort_fx = 0; + hSC_VBR->set_ppp_generic_fx = 0; + + hSC_VBR->last_7k2_coder_type_fx = GENERIC; + move16(); + + set16_fx(hSC_VBR->shape1_filt_mem_fx, 0, 10); + set16_fx(hSC_VBR->shape2_filt_mem_fx, 0, 10); + set16_fx(hSC_VBR->shape3_filt_mem_fx, 0, 10); + set16_fx(hSC_VBR->txlpf1_filt1_mem_fx, 0, 10); + set16_fx(hSC_VBR->txlpf1_filt2_mem_fx, 0, 10); + set16_fx(hSC_VBR->txhpf1_filt1_mem_fx, 0, 10); + set16_fx(hSC_VBR->txhpf1_filt2_mem_fx, 0, 10); + hSC_VBR->qprevIn_fx = 0; + move16(); + hSC_VBR->qprevGain_fx = 0; + move16(); + + return; +} diff --git a/lib_enc/waveadjust_fec_cod.c b/lib_enc/waveadjust_fec_cod.c index d8868e0..92bf271 100644 --- a/lib_enc/waveadjust_fec_cod.c +++ b/lib_enc/waveadjust_fec_cod.c @@ -2,13 +2,17 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include -#include -#include +#include +#include "options.h" /* for wmc_tool */ #include "prot_fx.h" +#include "rom_com_fx.h" #include "stat_com.h" -#include "stl.h" /* for wmc_tool */ +/*-------------------------------------------------------------------* + * SFM_Cal() + * + * + *--------------------------------------------------------------------*/ Word32 SFM_Cal(Word32 magn[], Word16 n) { -- GitLab